|
1 | 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import type { OpenClawConfig } from "../../config/config.js"; |
| 3 | +import type { SessionEntry } from "../../config/sessions/types.js"; |
3 | 4 | import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js"; |
4 | 5 | import { handleSubagentsFocusAction } from "./commands-subagents/action-focus.js"; |
5 | 6 | import { handleSubagentsUnfocusAction } from "./commands-subagents/action-unfocus.js"; |
| 7 | +import type { HandleCommandsParams } from "./commands-types.js"; |
| 8 | +import type { InlineDirectives } from "./directive-handling.js"; |
6 | 9 |
|
7 | 10 | const THREAD_CHANNEL = "thread-chat"; |
8 | 11 | const ROOM_CHANNEL = "room-chat"; |
@@ -150,45 +153,91 @@ function createSessionBindingCapabilities() { |
150 | 153 | }; |
151 | 154 | } |
152 | 155 |
|
| 156 | +function buildCommandParams(params?: { |
| 157 | + cfg?: OpenClawConfig; |
| 158 | + chatType?: string; |
| 159 | + senderId?: string; |
| 160 | + sessionEntry?: SessionEntry; |
| 161 | +}): HandleCommandsParams { |
| 162 | + const directives: InlineDirectives = { |
| 163 | + cleaned: "", |
| 164 | + hasThinkDirective: false, |
| 165 | + hasVerboseDirective: false, |
| 166 | + hasFastDirective: false, |
| 167 | + hasReasoningDirective: false, |
| 168 | + hasElevatedDirective: false, |
| 169 | + hasExecDirective: false, |
| 170 | + hasExecOptions: false, |
| 171 | + invalidExecHost: false, |
| 172 | + invalidExecSecurity: false, |
| 173 | + invalidExecAsk: false, |
| 174 | + invalidExecNode: false, |
| 175 | + hasStatusDirective: false, |
| 176 | + hasModelDirective: false, |
| 177 | + hasQueueDirective: false, |
| 178 | + queueReset: false, |
| 179 | + hasQueueOptions: false, |
| 180 | + }; |
| 181 | + return { |
| 182 | + cfg: params?.cfg ?? baseCfg, |
| 183 | + ctx: { |
| 184 | + ChatType: params?.chatType ?? "group", |
| 185 | + }, |
| 186 | + command: { |
| 187 | + surface: "whatsapp", |
| 188 | + channel: "whatsapp", |
| 189 | + ownerList: [], |
| 190 | + senderIsOwner: true, |
| 191 | + isAuthorizedSender: true, |
| 192 | + senderId: params?.senderId ?? "user-1", |
| 193 | + rawBodyNormalized: "", |
| 194 | + commandBodyNormalized: "", |
| 195 | + }, |
| 196 | + directives, |
| 197 | + elevated: { enabled: false, allowed: false, failures: [] }, |
| 198 | + sessionEntry: params?.sessionEntry, |
| 199 | + sessionKey: "agent:main:main", |
| 200 | + workspaceDir: "/tmp/openclaw-subagents-focus", |
| 201 | + defaultGroupActivation: () => "mention", |
| 202 | + resolvedVerboseLevel: "off", |
| 203 | + resolvedReasoningLevel: "off", |
| 204 | + resolveDefaultThinkingLevel: async () => undefined, |
| 205 | + provider: "whatsapp", |
| 206 | + model: "test-model", |
| 207 | + contextTokens: 0, |
| 208 | + isGroup: true, |
| 209 | + }; |
| 210 | +} |
| 211 | + |
153 | 212 | function buildFocusContext(params?: { |
154 | 213 | cfg?: OpenClawConfig; |
155 | 214 | chatType?: string; |
156 | 215 | senderId?: string; |
157 | 216 | token?: string; |
158 | 217 | }) { |
159 | 218 | return { |
160 | | - params: { |
161 | | - cfg: params?.cfg ?? baseCfg, |
162 | | - ctx: { |
163 | | - ChatType: params?.chatType ?? "group", |
164 | | - }, |
165 | | - command: { |
166 | | - senderId: params?.senderId ?? "user-1", |
167 | | - }, |
168 | | - }, |
| 219 | + params: buildCommandParams({ |
| 220 | + cfg: params?.cfg, |
| 221 | + chatType: params?.chatType, |
| 222 | + senderId: params?.senderId, |
| 223 | + }), |
169 | 224 | handledPrefix: "/focus", |
170 | 225 | requesterKey: "agent:main:main", |
171 | 226 | runs: [], |
172 | 227 | restTokens: [params?.token ?? "codex-acp"], |
173 | | - } as Parameters<typeof handleSubagentsFocusAction>[0]; |
| 228 | + } satisfies Parameters<typeof handleSubagentsFocusAction>[0]; |
174 | 229 | } |
175 | 230 |
|
176 | 231 | function buildUnfocusContext(params?: { senderId?: string }) { |
177 | 232 | return { |
178 | | - params: { |
179 | | - cfg: baseCfg, |
180 | | - ctx: { |
181 | | - ChatType: "group", |
182 | | - }, |
183 | | - command: { |
184 | | - senderId: params?.senderId ?? "user-1", |
185 | | - }, |
186 | | - }, |
| 233 | + params: buildCommandParams({ |
| 234 | + senderId: params?.senderId, |
| 235 | + }), |
187 | 236 | handledPrefix: "/unfocus", |
188 | 237 | requesterKey: "agent:main:main", |
189 | 238 | runs: [], |
190 | 239 | restTokens: [], |
191 | | - } as Parameters<typeof handleSubagentsUnfocusAction>[0]; |
| 240 | + } satisfies Parameters<typeof handleSubagentsUnfocusAction>[0]; |
192 | 241 | } |
193 | 242 |
|
194 | 243 | describe("focus actions", () => { |
|
0 commit comments