From 48fd9d7dc71e995e1ca830cb734e6ad6939a4d7c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 05:25:48 +0000 Subject: [PATCH] refactor(auto-reply): share directive handling params --- .../reply/directive-handling.fast-lane.ts | 46 ++-------------- .../reply/directive-handling.impl.ts | 37 ++----------- .../reply/directive-handling.params.ts | 55 +++++++++++++++++++ 3 files changed, 64 insertions(+), 74 deletions(-) create mode 100644 src/auto-reply/reply/directive-handling.params.ts diff --git a/src/auto-reply/reply/directive-handling.fast-lane.ts b/src/auto-reply/reply/directive-handling.fast-lane.ts index df183b16b..e83aa889d 100644 --- a/src/auto-reply/reply/directive-handling.fast-lane.ts +++ b/src/auto-reply/reply/directive-handling.fast-lane.ts @@ -1,50 +1,12 @@ -import type { ModelAliasIndex } from "../../agents/model-selection.js"; -import type { OpenClawConfig } from "../../config/config.js"; -import type { SessionEntry } from "../../config/sessions.js"; -import type { MsgContext } from "../templating.js"; import type { ReplyPayload } from "../types.js"; -import type { InlineDirectives } from "./directive-handling.parse.js"; +import type { ApplyInlineDirectivesFastLaneParams } from "./directive-handling.params.js"; import type { ElevatedLevel, ReasoningLevel, ThinkLevel, VerboseLevel } from "./directives.js"; import { handleDirectiveOnly } from "./directive-handling.impl.js"; import { isDirectiveOnly } from "./directive-handling.parse.js"; -export async function applyInlineDirectivesFastLane(params: { - directives: InlineDirectives; - commandAuthorized: boolean; - ctx: MsgContext; - cfg: OpenClawConfig; - agentId?: string; - isGroup: boolean; - sessionEntry: SessionEntry; - sessionStore: Record; - sessionKey: string; - storePath?: string; - elevatedEnabled: boolean; - elevatedAllowed: boolean; - elevatedFailures?: Array<{ gate: string; key: string }>; - messageProviderKey?: string; - defaultProvider: string; - defaultModel: string; - aliasIndex: ModelAliasIndex; - allowedModelKeys: Set; - allowedModelCatalog: Awaited< - ReturnType - >; - resetModelOverride: boolean; - provider: string; - model: string; - initialModelLabel: string; - formatModelSwitchEvent: (label: string, alias?: string) => string; - agentCfg?: NonNullable["defaults"]; - modelState: { - resolveDefaultThinkingLevel: () => Promise; - allowedModelKeys: Set; - allowedModelCatalog: Awaited< - ReturnType - >; - resetModelOverride: boolean; - }; -}): Promise<{ directiveAck?: ReplyPayload; provider: string; model: string }> { +export async function applyInlineDirectivesFastLane( + params: ApplyInlineDirectivesFastLaneParams, +): Promise<{ directiveAck?: ReplyPayload; provider: string; model: string }> { const { directives, commandAuthorized, diff --git a/src/auto-reply/reply/directive-handling.impl.ts b/src/auto-reply/reply/directive-handling.impl.ts index 4b0707327..cc8b5aef6 100644 --- a/src/auto-reply/reply/directive-handling.impl.ts +++ b/src/auto-reply/reply/directive-handling.impl.ts @@ -1,9 +1,8 @@ -import type { ModelAliasIndex } from "../../agents/model-selection.js"; import type { OpenClawConfig } from "../../config/config.js"; import type { ExecAsk, ExecHost, ExecSecurity } from "../../infra/exec-approvals.js"; import type { ReplyPayload } from "../types.js"; -import type { InlineDirectives } from "./directive-handling.parse.js"; -import type { ElevatedLevel, ReasoningLevel, ThinkLevel, VerboseLevel } from "./directives.js"; +import type { HandleDirectiveOnlyParams } from "./directive-handling.params.js"; +import type { ElevatedLevel, ReasoningLevel, ThinkLevel } from "./directives.js"; import { resolveAgentConfig, resolveAgentDir, @@ -58,35 +57,9 @@ function resolveExecDefaults(params: { }; } -export async function handleDirectiveOnly(params: { - cfg: OpenClawConfig; - directives: InlineDirectives; - sessionEntry: SessionEntry; - sessionStore: Record; - sessionKey: string; - storePath?: string; - elevatedEnabled: boolean; - elevatedAllowed: boolean; - elevatedFailures?: Array<{ gate: string; key: string }>; - messageProviderKey?: string; - defaultProvider: string; - defaultModel: string; - aliasIndex: ModelAliasIndex; - allowedModelKeys: Set; - allowedModelCatalog: Awaited< - ReturnType - >; - resetModelOverride: boolean; - provider: string; - model: string; - initialModelLabel: string; - formatModelSwitchEvent: (label: string, alias?: string) => string; - currentThinkLevel?: ThinkLevel; - currentVerboseLevel?: VerboseLevel; - currentReasoningLevel?: ReasoningLevel; - currentElevatedLevel?: ElevatedLevel; - surface?: string; -}): Promise { +export async function handleDirectiveOnly( + params: HandleDirectiveOnlyParams, +): Promise { const { directives, sessionEntry, diff --git a/src/auto-reply/reply/directive-handling.params.ts b/src/auto-reply/reply/directive-handling.params.ts new file mode 100644 index 000000000..af6f0ff0d --- /dev/null +++ b/src/auto-reply/reply/directive-handling.params.ts @@ -0,0 +1,55 @@ +import type { ModelAliasIndex } from "../../agents/model-selection.js"; +import type { OpenClawConfig } from "../../config/config.js"; +import type { SessionEntry } from "../../config/sessions.js"; +import type { MsgContext } from "../templating.js"; +import type { InlineDirectives } from "./directive-handling.parse.js"; +import type { ElevatedLevel, ReasoningLevel, ThinkLevel, VerboseLevel } from "./directives.js"; + +export type HandleDirectiveOnlyCoreParams = { + cfg: OpenClawConfig; + directives: InlineDirectives; + sessionEntry: SessionEntry; + sessionStore: Record; + sessionKey: string; + storePath?: string; + elevatedEnabled: boolean; + elevatedAllowed: boolean; + elevatedFailures?: Array<{ gate: string; key: string }>; + messageProviderKey?: string; + defaultProvider: string; + defaultModel: string; + aliasIndex: ModelAliasIndex; + allowedModelKeys: Set; + allowedModelCatalog: Awaited< + ReturnType + >; + resetModelOverride: boolean; + provider: string; + model: string; + initialModelLabel: string; + formatModelSwitchEvent: (label: string, alias?: string) => string; +}; + +export type HandleDirectiveOnlyParams = HandleDirectiveOnlyCoreParams & { + currentThinkLevel?: ThinkLevel; + currentVerboseLevel?: VerboseLevel; + currentReasoningLevel?: ReasoningLevel; + currentElevatedLevel?: ElevatedLevel; + surface?: string; +}; + +export type ApplyInlineDirectivesFastLaneParams = HandleDirectiveOnlyCoreParams & { + commandAuthorized: boolean; + ctx: MsgContext; + agentId?: string; + isGroup: boolean; + agentCfg?: NonNullable["defaults"]; + modelState: { + resolveDefaultThinkingLevel: () => Promise; + allowedModelKeys: Set; + allowedModelCatalog: Awaited< + ReturnType + >; + resetModelOverride: boolean; + }; +};