mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
refactor: polish trigger and manifest seams
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user