mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 03:17:59 +00:00
Let assistant plugins launch a chat without a workspace
This commit is contained in:
4 files changed
+55
-13
No files matched your search
+9
-1
@@ -1,4 +1,12 @@
|
|||||||
namespace AIStudio.Tools.PluginSystem.Assistants;
|
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>
|
/// <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,
|
NONE,
|
||||||
OPEN_WORKSPACE_CHAT_BY_NAME,
|
OPEN_WORKSPACE_CHAT_BY_NAME,
|
||||||
|
OPEN_TEMPORARY_CHAT,
|
||||||
}
|
}
|
||||||
+12
-2
@@ -165,8 +165,18 @@ public static class DirectChatLauncherLuaWriter
|
|||||||
builder.AppendLine("ASSISTANT = {");
|
builder.AppendLine("ASSISTANT = {");
|
||||||
builder.AppendLine($" [\"Title\"] = \"{Escape(definition.Title)}\",");
|
builder.AppendLine($" [\"Title\"] = \"{Escape(definition.Title)}\",");
|
||||||
builder.AppendLine($" [\"Description\"] = \"{Escape(definition.Description)}\",");
|
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
|
// 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)
|
if (launchBehavior is AssistantPluginLaunchBehavior.NONE)
|
||||||
return true;
|
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)
|
switch (launchBehavior)
|
||||||
{
|
{
|
||||||
case AssistantPluginLaunchBehavior.OPEN_WORKSPACE_CHAT_BY_NAME:
|
case AssistantPluginLaunchBehavior.OPEN_WORKSPACE_CHAT_BY_NAME:
|
||||||
if (!assistantTable.TryGetValue("WorkspaceName", out var workspaceNameValue) ||
|
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.");
|
message = TB("The ASSISTANT table contains the LaunchBehavior 'OPEN_WORKSPACE_CHAT_BY_NAME' but no valid WorkspaceName.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceName = workspaceName.Trim();
|
workspaceName = configuredWorkspaceName.Trim();
|
||||||
if (string.IsNullOrWhiteSpace(workspaceName))
|
if (string.IsNullOrWhiteSpace(workspaceName))
|
||||||
{
|
{
|
||||||
message = TB("The ASSISTANT table contains an empty WorkspaceName for LaunchBehavior 'OPEN_WORKSPACE_CHAT_BY_NAME'.");
|
message = TB("The ASSISTANT table contains an empty WorkspaceName for LaunchBehavior 'OPEN_WORKSPACE_CHAT_BY_NAME'.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TryReadOptionalGuid(assistantTable, "ProviderId", false, out var providerId, out message) ||
|
break;
|
||||||
!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) ||
|
// A chat without a workspace has no name to carry, so one written here can only be a
|
||||||
!TryReadOptionalToolIds(assistantTable, out var toolIds, out message))
|
// 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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.ChatLaunchConfiguration = new(workspaceName, providerId, profileId, chatTemplateId, dataSourceIds, toolIds);
|
break;
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
message = TB("The ASSISTANT table contains an unsupported LaunchBehavior value.");
|
message = TB("The ASSISTANT table contains an unsupported LaunchBehavior value.");
|
||||||
return false;
|
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)
|
private static bool TryReadOptionalGuid(LuaTable assistantTable, string fieldName, bool allowEmpty, out Guid? id, out string message)
|
||||||
|
|||||||
Reference in new issue
Block a user