mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-07 16:29:40 +00:00
Let direct chat launchers open disappearing chats (#967)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
1 parent
65a1683b95
commit
828541ce93
22 files changed
+212
-103
No files matched your search
+9
-1
@@ -1,4 +1,12 @@
|
||||
namespace AIStudio.Tools.PluginSystem.Assistants;
|
||||
|
||||
/// <param name="WorkspaceName">The workspace the chat is created in. An empty name means the launcher opens a chat without a workspace, which the app shows as a disappearing chat.</param>
|
||||
/// <param name="ToolIds">The tools preselected for the chat, or null when the launcher names none.</param>
|
||||
public sealed record AssistantChatLaunchConfiguration(string WorkspaceName, Guid? ProviderId, Guid? ProfileId, Guid? ChatTemplateId, IReadOnlyList<Guid>? DataSourceIds, IReadOnlyList<string>? ToolIds);
|
||||
public sealed record AssistantChatLaunchConfiguration(string WorkspaceName, Guid? ProviderId, Guid? ProfileId, Guid? ChatTemplateId, IReadOnlyList<Guid>? DataSourceIds, IReadOnlyList<string>? ToolIds)
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the launcher opens a chat that belongs to no workspace. The missing workspace name is
|
||||
/// the whole condition, so the launch behavior and the written plugin follow from it.
|
||||
/// </summary>
|
||||
public bool OpensTemporaryChat => string.IsNullOrWhiteSpace(this.WorkspaceName);
|
||||
}
|
||||
@@ -4,4 +4,5 @@ public enum AssistantPluginLaunchBehavior
|
||||
{
|
||||
NONE,
|
||||
OPEN_WORKSPACE_CHAT_BY_NAME,
|
||||
OPEN_TEMPORARY_CHAT,
|
||||
}
|
||||
+12
-2
@@ -165,8 +165,18 @@ public static class DirectChatLauncherLuaWriter
|
||||
builder.AppendLine("ASSISTANT = {");
|
||||
builder.AppendLine($" [\"Title\"] = \"{Escape(definition.Title)}\",");
|
||||
builder.AppendLine($" [\"Description\"] = \"{Escape(definition.Description)}\",");
|
||||
builder.AppendLine($" [\"LaunchBehavior\"] = \"{nameof(AssistantPluginLaunchBehavior.OPEN_WORKSPACE_CHAT_BY_NAME)}\",");
|
||||
builder.AppendLine($" [\"WorkspaceName\"] = \"{Escape(definition.Launch.WorkspaceName.Trim())}\",");
|
||||
//
|
||||
// The behavior follows from the workspace rather than being tracked next to it. A launcher
|
||||
// without one has no name to write, and the plugin loader rejects a WorkspaceName there, so
|
||||
// the field is left out the same way the optional IDs below are:
|
||||
//
|
||||
if (definition.Launch.OpensTemporaryChat)
|
||||
builder.AppendLine($" [\"LaunchBehavior\"] = \"{nameof(AssistantPluginLaunchBehavior.OPEN_TEMPORARY_CHAT)}\",");
|
||||
else
|
||||
{
|
||||
builder.AppendLine($" [\"LaunchBehavior\"] = \"{nameof(AssistantPluginLaunchBehavior.OPEN_WORKSPACE_CHAT_BY_NAME)}\",");
|
||||
builder.AppendLine($" [\"WorkspaceName\"] = \"{Escape(definition.Launch.WorkspaceName.Trim())}\",");
|
||||
}
|
||||
|
||||
//
|
||||
// Omitted IDs mean "use the chat defaults", while an empty GUID explicitly selects no
|
||||
|
||||
@@ -223,38 +223,61 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
if (launchBehavior is AssistantPluginLaunchBehavior.NONE)
|
||||
return true;
|
||||
|
||||
//
|
||||
// Both launch behaviors describe the same chat and differ only in where it is kept, so only
|
||||
// the workspace is read per behavior. Everything else follows below, for both of them:
|
||||
//
|
||||
var workspaceName = string.Empty;
|
||||
switch (launchBehavior)
|
||||
{
|
||||
case AssistantPluginLaunchBehavior.OPEN_WORKSPACE_CHAT_BY_NAME:
|
||||
if (!assistantTable.TryGetValue("WorkspaceName", out var workspaceNameValue) ||
|
||||
!workspaceNameValue.TryRead<string>(out var workspaceName))
|
||||
!workspaceNameValue.TryRead<string>(out var configuredWorkspaceName))
|
||||
{
|
||||
message = TB("The ASSISTANT table contains the LaunchBehavior 'OPEN_WORKSPACE_CHAT_BY_NAME' but no valid WorkspaceName.");
|
||||
return false;
|
||||
}
|
||||
|
||||
workspaceName = workspaceName.Trim();
|
||||
workspaceName = configuredWorkspaceName.Trim();
|
||||
if (string.IsNullOrWhiteSpace(workspaceName))
|
||||
{
|
||||
message = TB("The ASSISTANT table contains an empty WorkspaceName for LaunchBehavior 'OPEN_WORKSPACE_CHAT_BY_NAME'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryReadOptionalGuid(assistantTable, "ProviderId", false, out var providerId, out message) ||
|
||||
!TryReadOptionalGuid(assistantTable, "ProfileId", true, out var profileId, out message) ||
|
||||
!TryReadOptionalGuid(assistantTable, "ChatTemplateId", true, out var chatTemplateId, out message) ||
|
||||
!TryReadOptionalDataSourceIds(assistantTable, out var dataSourceIds, out message) ||
|
||||
!TryReadOptionalToolIds(assistantTable, out var toolIds, out message))
|
||||
break;
|
||||
|
||||
//
|
||||
// A chat without a workspace has no name to carry, so one written here can only be a
|
||||
// mistake. We reject it rather than dropping it silently: a misspelled LaunchBehavior
|
||||
// would otherwise turn a workspace launcher into a disappearing one, and the author
|
||||
// would only notice it by the chats going missing.
|
||||
//
|
||||
case AssistantPluginLaunchBehavior.OPEN_TEMPORARY_CHAT:
|
||||
if (assistantTable.TryGetValue("WorkspaceName", out var unexpectedWorkspaceNameValue) &&
|
||||
unexpectedWorkspaceNameValue.TryRead<string>(out var unexpectedWorkspaceName) &&
|
||||
!string.IsNullOrWhiteSpace(unexpectedWorkspaceName))
|
||||
{
|
||||
message = TB("The ASSISTANT table contains a WorkspaceName for LaunchBehavior 'OPEN_TEMPORARY_CHAT'. A chat without a workspace cannot have one.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.ChatLaunchConfiguration = new(workspaceName, providerId, profileId, chatTemplateId, dataSourceIds, toolIds);
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
message = TB("The ASSISTANT table contains an unsupported LaunchBehavior value.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryReadOptionalGuid(assistantTable, "ProviderId", false, out var providerId, out message) ||
|
||||
!TryReadOptionalGuid(assistantTable, "ProfileId", true, out var profileId, out message) ||
|
||||
!TryReadOptionalGuid(assistantTable, "ChatTemplateId", true, out var chatTemplateId, out message) ||
|
||||
!TryReadOptionalDataSourceIds(assistantTable, out var dataSourceIds, out message) ||
|
||||
!TryReadOptionalToolIds(assistantTable, out var toolIds, out message))
|
||||
return false;
|
||||
|
||||
this.ChatLaunchConfiguration = new(workspaceName, providerId, profileId, chatTemplateId, dataSourceIds, toolIds);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryReadOptionalGuid(LuaTable assistantTable, string fieldName, bool allowEmpty, out Guid? id, out string message)
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace AIStudio.Tools.Services;
|
||||
/// <summary>
|
||||
/// The chat a direct chat launcher tile opens, as chosen in the Assistant Builder.
|
||||
/// </summary>
|
||||
/// <param name="WorkspaceName">The workspace the chat is created in.</param>
|
||||
/// <param name="WorkspaceName">The workspace the chat is created in; an empty name opens a chat without a workspace instead.</param>
|
||||
/// <param name="ProviderId">The provider to preselect, or null for the chat default.</param>
|
||||
/// <param name="ProfileId">The profile to preselect; the empty GUID selects no profile.</param>
|
||||
/// <param name="ChatTemplateId">The chat template to preselect; the empty GUID selects none.</param>
|
||||
|
||||
@@ -358,6 +358,7 @@ public sealed class AssistantPluginGenerationService(ToolRegistry toolRegistry,
|
||||
- Write description as one sentence that says which chat this tile opens and what it is for. Do not describe an input form, a prompt, or a submit button, because a launcher has none.
|
||||
- Write all three texts in the language of the approved draft.
|
||||
- Do not mention workspace names, provider names, profile names, template names, data source IDs, or tool IDs in any of the three texts.
|
||||
- When the chat launch names no workspace, the tile opens a chat that belongs to no workspace and disappears again. You may say the chat is temporary, but never invent a workspace name.
|
||||
- Do not return Markdown, code fences, explanations, or text outside the JSON object.
|
||||
""";
|
||||
|
||||
@@ -512,6 +513,7 @@ public sealed class AssistantPluginGenerationService(ToolRegistry toolRegistry,
|
||||
- Explain omitted provider, profile, template, data-source, or tool values as using the normal chat defaults.
|
||||
- In the {{TB("Tools")}} section, say what the preselected tools let the chat do and that users may change the selection once the chat is open.
|
||||
- Explain the empty profile/template GUID as explicitly selecting no profile/template.
|
||||
- When the ChatLaunch names no workspace, write in the {{TB("Workspace")}} section that the tile opens a chat without a workspace: it is kept among the temporary chats and is deleted by the maintenance the user configured for them. Never invent a workspace name.
|
||||
- Do not propose UI components, submit behavior, BuildPrompt, or a plugin SystemPrompt for a chat launcher.
|
||||
""";
|
||||
|
||||
@@ -620,10 +622,11 @@ public sealed class AssistantPluginGenerationService(ToolRegistry toolRegistry,
|
||||
- Keep TYPE = "ASSISTANT".
|
||||
- Keep the assistant locally managed. DEPLOYED_USING_CONFIG_SERVER must not be true.
|
||||
{{builderMetadataRule}}
|
||||
- Set assistant.kind to "CHAT_LAUNCHER" exactly when the revised ASSISTANT table uses LaunchBehavior = "OPEN_WORKSPACE_CHAT_BY_NAME"; otherwise set it to "FORM".
|
||||
- Set assistant.kind to "CHAT_LAUNCHER" exactly when the revised ASSISTANT table uses LaunchBehavior = "OPEN_WORKSPACE_CHAT_BY_NAME" or "OPEN_TEMPORARY_CHAT"; otherwise set it to "FORM".
|
||||
- For a form assistant, include system_prompt, submit_text, and allow_ai_studio_profiles in the JSON assistant object and omit launch. Include tool_ids exactly when the revised ASSISTANT table carries ToolIds.
|
||||
- Change ASSISTANT.ToolIds only when the requested change asks for it. Use only tool IDs from the "Available tools" list in the plugin context for tools you add; never invent an ID. Drop the field entirely rather than writing an empty list.
|
||||
- For a chat launcher, include launch with the exact WorkspaceName and optional ProviderId, ProfileId, ChatTemplateId, DataSourceIds, and ToolIds values from the revised ASSISTANT table; omit system_prompt, submit_text, and allow_ai_studio_profiles.
|
||||
- For a chat launcher, include launch with the optional ProviderId, ProfileId, ChatTemplateId, DataSourceIds, and ToolIds values from the revised ASSISTANT table; omit system_prompt, submit_text, and allow_ai_studio_profiles. Include workspace_name with the exact WorkspaceName exactly when the table uses OPEN_WORKSPACE_CHAT_BY_NAME, and omit it for OPEN_TEMPORARY_CHAT.
|
||||
- Keep the LaunchBehavior a launcher already has unless the requested change asks to add or drop its workspace. OPEN_WORKSPACE_CHAT_BY_NAME requires a WorkspaceName, and OPEN_TEMPORARY_CHAT must not carry one.
|
||||
- A chat launcher must not include SystemPrompt, SubmitText, AllowProfiles, BuildPrompt, or UI in its ASSISTANT table.
|
||||
- Preserve an empty profile or template GUID when it explicitly means no profile or no template. Do not emit empty provider or data-source GUIDs.
|
||||
- Preserve existing behavior unless the requested change explicitly modifies it.
|
||||
@@ -757,8 +760,11 @@ public sealed class AssistantPluginGenerationService(ToolRegistry toolRegistry,
|
||||
if (launch is null)
|
||||
return true;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(launch.WorkspaceName) ||
|
||||
!IsOptionalGuid(launch.ProviderId, allowEmpty: false) ||
|
||||
//
|
||||
// No workspace name is a choice rather than a gap: the launcher then opens a chat that
|
||||
// belongs to no workspace. Only the remaining fields have a shape to check.
|
||||
//
|
||||
if (!IsOptionalGuid(launch.ProviderId, allowEmpty: false) ||
|
||||
!IsOptionalGuid(launch.ProfileId, allowEmpty: true) ||
|
||||
!IsOptionalGuid(launch.ChatTemplateId, allowEmpty: true))
|
||||
return false;
|
||||
|
||||
@@ -50,21 +50,29 @@ public sealed class DirectChatService(SettingsManager settingsManager, DataSourc
|
||||
if (dataSourceOptions is null)
|
||||
return new(null, dataSourceOptionsResult.ErrorMessage);
|
||||
|
||||
Guid workspaceId;
|
||||
try
|
||||
//
|
||||
// A launcher that names no workspace wants the same chat the chat page starts on its own:
|
||||
// one that belongs nowhere, is kept among the temporary chats, and disappears with them. The
|
||||
// empty workspace ID is what says so, here as everywhere else in the app.
|
||||
//
|
||||
var workspaceId = Guid.Empty;
|
||||
if (!launchConfiguration.OpensTemporaryChat)
|
||||
{
|
||||
workspaceId = await WorkspaceBehaviour.ResolveOrCreateWorkspaceIdByNameAsync(launchConfiguration.WorkspaceName);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Assistant plugin '{PluginName}' could not resolve or create workspace '{WorkspaceName}'.", assistantPlugin.Name, launchConfiguration.WorkspaceName);
|
||||
return new(null, string.Format(TB("The workspace '{0}' could not be opened or created."), launchConfiguration.WorkspaceName));
|
||||
}
|
||||
try
|
||||
{
|
||||
workspaceId = await WorkspaceBehaviour.ResolveOrCreateWorkspaceIdByNameAsync(launchConfiguration.WorkspaceName);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Assistant plugin '{PluginName}' could not resolve or create workspace '{WorkspaceName}'.", assistantPlugin.Name, launchConfiguration.WorkspaceName);
|
||||
return new(null, string.Format(TB("The workspace '{0}' could not be opened or created."), launchConfiguration.WorkspaceName));
|
||||
}
|
||||
|
||||
if (workspaceId == Guid.Empty)
|
||||
{
|
||||
logger.LogWarning("Assistant plugin '{PluginName}' could not resolve or create workspace '{WorkspaceName}'.", assistantPlugin.Name, launchConfiguration.WorkspaceName);
|
||||
return new(null, string.Format(TB("The workspace '{0}' could not be opened or created."), launchConfiguration.WorkspaceName));
|
||||
if (workspaceId == Guid.Empty)
|
||||
{
|
||||
logger.LogWarning("Assistant plugin '{PluginName}' could not resolve or create workspace '{WorkspaceName}'.", assistantPlugin.Name, launchConfiguration.WorkspaceName);
|
||||
return new(null, string.Format(TB("The workspace '{0}' could not be opened or created."), launchConfiguration.WorkspaceName));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user