refactor: polish trigger and manifest seams

This commit is contained in:
Peter Steinberger
2026-03-23 22:22:44 -07:00
parent 535b792808
commit 013385e5c2
8 changed files with 135 additions and 47 deletions

View File

@@ -305,13 +305,9 @@ async function dispatchSlashCommand(
}
const targetSessionKey = host.sessionKey;
const result = await executeSlashCommand(
host.client,
targetSessionKey,
name,
args,
host.chatModelCatalog,
);
const result = await executeSlashCommand(host.client, targetSessionKey, name, args, {
chatModelCatalog: host.chatModelCatalog,
});
if (result.content) {
injectCommandResult(host, result.content);

View File

@@ -285,7 +285,9 @@ describe("executeSlashCommand directives", () => {
"main",
"model",
"gpt-5-mini",
[{ id: "gpt-5-mini", name: "gpt-5-mini", provider: "openai" }],
{
chatModelCatalog: [{ id: "gpt-5-mini", name: "gpt-5-mini", provider: "openai" }],
},
);
expect(request).toHaveBeenCalledWith("sessions.patch", {
@@ -317,7 +319,9 @@ describe("executeSlashCommand directives", () => {
"main",
"model",
"gpt-5-mini",
[{ id: "gpt-5-mini", name: "GPT-5 Mini", provider: "openai" }],
{
chatModelCatalog: [{ id: "gpt-5-mini", name: "GPT-5 Mini", provider: "openai" }],
},
);
expect(result.sessionPatch?.modelOverride).toEqual({

View File

@@ -50,12 +50,16 @@ export type SlashCommandResult = {
};
};
export type SlashCommandContext = {
chatModelCatalog?: ModelCatalogEntry[];
};
export async function executeSlashCommand(
client: GatewayBrowserClient,
sessionKey: string,
commandName: string,
args: string,
chatModelCatalog: ModelCatalogEntry[] = [],
context: SlashCommandContext = {},
): Promise<SlashCommandResult> {
switch (commandName) {
case "help":
@@ -73,7 +77,7 @@ export async function executeSlashCommand(
case "compact":
return await executeCompact(client, sessionKey);
case "model":
return await executeModel(client, sessionKey, args, chatModelCatalog);
return await executeModel(client, sessionKey, args, context);
case "think":
return await executeThink(client, sessionKey, args);
case "fast":
@@ -130,7 +134,7 @@ async function executeModel(
client: GatewayBrowserClient,
sessionKey: string,
args: string,
chatModelCatalog: ModelCatalogEntry[],
context: SlashCommandContext,
): Promise<SlashCommandResult> {
if (!args) {
try {
@@ -163,6 +167,7 @@ async function executeModel(
});
const patchedModel = patched.resolved?.model ?? args.trim();
const rawOverride = createChatModelOverride(patchedModel.trim());
const chatModelCatalog = context.chatModelCatalog ?? [];
const resolvedValue = rawOverride
? normalizeChatModelOverrideValue(rawOverride, chatModelCatalog) ||
resolveServerChatModelValue(patchedModel, patched.resolved?.modelProvider)