@tencent-ai/cloud-agent-sdk 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,10 +1,633 @@
1
- require('./MockAgentProvider-D-basTXz.cjs');
1
+ let zod = require("zod");
2
2
  let _agentclientprotocol_sdk = require("@agentclientprotocol/sdk");
3
3
  require("@connectrpc/connect");
4
4
  require("@connectrpc/connect-web");
5
5
  require("@bufbuild/protobuf");
6
6
  let e2b = require("e2b");
7
7
 
8
+ //#region ../agent-provider/src/common/_legacy/tool-schemas.ts
9
+ /**
10
+ * ACP Tool Input/Output Schema 定义
11
+ *
12
+ * 用于约束 ACP 协议中 ToolCallUpdate 的 rawInput 和 rawOutput 字段
13
+ * 基于 getCraftToolProvider 使用的工具定义
14
+ */
15
+ /**
16
+ * 工具输入 Schema 定义
17
+ * 用于验证和约束 rawInput
18
+ */
19
+ const ToolInputSchemas = {
20
+ list_dir: zod.z.object({
21
+ target_directory: zod.z.string().describe("要列出内容的目录路径"),
22
+ ignore_globs: zod.z.string().optional().describe("可选的 glob 模式数组,用于忽略特定文件")
23
+ }),
24
+ search_file: zod.z.object({
25
+ target_directory: zod.z.string().describe("搜索的目录绝对路径"),
26
+ pattern: zod.z.string().describe("文件模式(如 \"*.js\"),支持通配符"),
27
+ recursive: zod.z.boolean().describe("是否递归搜索子目录"),
28
+ caseSensitive: zod.z.boolean().describe("是否区分大小写")
29
+ }),
30
+ read_file: zod.z.object({
31
+ filePath: zod.z.string().describe("要读取的文件的绝对路径"),
32
+ offset: zod.z.number().optional().describe("开始读取的行号"),
33
+ limit: zod.z.number().optional().describe("要读取的行数")
34
+ }),
35
+ read_lints: zod.z.object({ paths: zod.z.string().optional().describe("要读取 lint 错误的文件或目录路径") }),
36
+ rag_search: zod.z.object({
37
+ queryString: zod.z.string().describe("用户的实际问题或搜索查询"),
38
+ knowledgeBaseNames: zod.z.string().describe("知识库名称,多个用逗号分隔")
39
+ }),
40
+ read_rules: zod.z.object({ ruleNames: zod.z.string().describe("要读取的规则关键词,用逗号分隔,格式:{ruleName}_{ruleId}") }),
41
+ mcp_get_tool_description: zod.z.object({ toolRequests: zod.z.string().describe("JSON 字符串,二维数组格式:[[\"server1\", \"tool1\"], [\"server2\", \"tool2\"]]") }),
42
+ mcp_call_tool: zod.z.object({
43
+ serverName: zod.z.string().describe("MCP 服务器名称"),
44
+ toolName: zod.z.string().describe("要调用的工具名称"),
45
+ arguments: zod.z.string().describe("目标 MCP 工具的参数,JSON 格式字符串"),
46
+ maxOutputLength: zod.z.number().optional().describe("控制工具输出的最大长度,默认 200000")
47
+ }),
48
+ fetch_mcp_resource: zod.z.object({
49
+ server: zod.z.string().describe("MCP 服务器标识符"),
50
+ uri: zod.z.string().describe("要读取的资源 URI"),
51
+ arguments: zod.z.record(zod.z.unknown()).optional().describe("资源模板的参数"),
52
+ downloadPath: zod.z.string().optional().describe("可选的绝对路径,用于保存资源到磁盘")
53
+ }),
54
+ create_rule: zod.z.object({
55
+ ruleScope: zod.z.string().describe("规则范围,project rule 或 user rule"),
56
+ ruleName: zod.z.string().describe("规则文件名,不带扩展名"),
57
+ ruleType: zod.z.string().describe("规则类型,always、manual 或 requested"),
58
+ ruleContent: zod.z.string().describe("规则内容,使用 Markdown 格式"),
59
+ ruleDescription: zod.z.string().optional().describe("规则描述,使用 Markdown 格式")
60
+ }),
61
+ update_memory: zod.z.object({
62
+ action: zod.z.enum([
63
+ "create",
64
+ "update",
65
+ "delete"
66
+ ]).optional().describe("执行的操作"),
67
+ existing_knowledge_id: zod.z.string().optional().describe("更新或删除时必需,现有记忆的 ID"),
68
+ knowledge_to_store: zod.z.string().optional().describe("要存储的特定记忆"),
69
+ title: zod.z.string().optional().describe("记忆的标题")
70
+ }),
71
+ search_content: zod.z.object({
72
+ pattern: zod.z.string().describe("要搜索的关键字或正则表达式模式"),
73
+ directory: zod.z.string().describe("要搜索的目录的绝对路径"),
74
+ fileTypes: zod.z.string().optional().describe("可选的逗号分隔文件扩展名"),
75
+ contextBefore: zod.z.number().optional().describe("每个匹配前显示的行数"),
76
+ contextAfter: zod.z.number().optional().describe("每个匹配后显示的行数"),
77
+ contextAround: zod.z.number().optional().describe("每个匹配前后显示的行数"),
78
+ outputMode: zod.z.string().optional().describe("输出模式:content、files_with_matches 或 count"),
79
+ caseSensitive: zod.z.boolean().optional().describe("是否区分大小写")
80
+ }),
81
+ write_to_file: zod.z.object({
82
+ filePath: zod.z.string().describe("目标文件的绝对路径"),
83
+ content: zod.z.string().describe("要写入的内容")
84
+ }),
85
+ replace_in_file: zod.z.object({
86
+ filePath: zod.z.string().describe("要修改的文件的绝对路径"),
87
+ old_str: zod.z.string().describe("要替换的文本"),
88
+ new_str: zod.z.string().describe("替换后的文本")
89
+ }),
90
+ delete_file: zod.z.object({
91
+ target_file: zod.z.string().describe("要删除的文件的绝对路径"),
92
+ explanation: zod.z.string().optional().describe("为什么使用此工具的一句话解释")
93
+ }),
94
+ execute_command: zod.z.object({
95
+ command: zod.z.string().describe("要执行的 CLI 命令"),
96
+ requires_approval: zod.z.boolean().describe("命令是否需要用户批准")
97
+ }),
98
+ preview_url: zod.z.object({ url: zod.z.string().describe("要打开的完整、有效的 HTTP/HTTPS URL") }),
99
+ ask_followup_question: zod.z.object({ questions: zod.z.array(zod.z.object({
100
+ question: zod.z.string(),
101
+ header: zod.z.string().max(12),
102
+ options: zod.z.array(zod.z.object({
103
+ label: zod.z.string().max(50),
104
+ description: zod.z.string()
105
+ })).min(2).max(4),
106
+ multiSelect: zod.z.boolean().optional()
107
+ })).min(1).max(4) }),
108
+ invoke_integration: zod.z.object({}).passthrough(),
109
+ call_integration: zod.z.object({}).passthrough(),
110
+ search_integration_tool: zod.z.object({}).passthrough(),
111
+ supabase_get_logs: zod.z.object({}).passthrough(),
112
+ supabase_execute_sql: zod.z.object({}).passthrough(),
113
+ supabase_apply_migration: zod.z.object({}).passthrough(),
114
+ supabase_list_migration: zod.z.object({}).passthrough(),
115
+ supabase_list_tables: zod.z.object({}).passthrough(),
116
+ cloud_studio_fetch_log: zod.z.object({}).passthrough(),
117
+ cloud_studio_execute_command: zod.z.object({}).passthrough(),
118
+ cloud_studio_deploy_sandbox: zod.z.object({}).passthrough(),
119
+ component_get_prompt: zod.z.object({}).passthrough(),
120
+ web_fetch: zod.z.object({
121
+ url: zod.z.string().describe("要获取内容的 URL"),
122
+ fetchInfo: zod.z.string().describe("用户想要获取的信息描述")
123
+ }),
124
+ use_skill: zod.z.object({ command: zod.z.string().describe("技能名称(不含参数),如 \"pdf\" 或 \"xlsx\"") }),
125
+ web_search: zod.z.object({
126
+ explanation: zod.z.string().describe("为什么使用此工具的一句话解释"),
127
+ searchTerm: zod.z.string().describe("要在网络上搜索的搜索词")
128
+ }),
129
+ task: zod.z.object({
130
+ subagent_name: zod.z.string().describe("要调用的子代理名称"),
131
+ description: zod.z.string().describe("任务的简短描述(3-5 个词)"),
132
+ prompt: zod.z.string().describe("子代理要执行的任务"),
133
+ subagent_path: zod.z.string().optional().describe("子代理定义文件的路径")
134
+ }),
135
+ codebase_search: zod.z.object({
136
+ query: zod.z.string().describe("关于你想理解的内容的完整问题"),
137
+ path: zod.z.string().describe("限制搜索范围的目录路径前缀"),
138
+ limit: zod.z.number().max(100).optional().describe("返回的最大结果数,默认 10")
139
+ }),
140
+ lsp: zod.z.object({}).passthrough(),
141
+ spec_create: zod.z.object({
142
+ name: zod.z.string().describe("Plan 名称,用作稳定标识符/文件名"),
143
+ overview: zod.z.string().describe("用一两句话精确概括本次 plan 的主要内容"),
144
+ relative_history: zod.z.string().describe("准备阶段的上下文,包含用户需求、代码位置、额外上下文等")
145
+ }),
146
+ spec_update: zod.z.object({ status: zod.z.enum([
147
+ "prepare",
148
+ "ready",
149
+ "building",
150
+ "finished"
151
+ ]).optional().describe("Plan 状态") })
152
+ };
153
+ /**
154
+ * 工具输出 Schema 定义
155
+ * 用于验证和约束 rawOutput
156
+ */
157
+ const ToolOutputSchemas = {
158
+ list_dir: zod.z.object({
159
+ type: zod.z.literal("list_files_result"),
160
+ files: zod.z.array(zod.z.object({
161
+ filePath: zod.z.string(),
162
+ size: zod.z.string(),
163
+ modifyTime: zod.z.string()
164
+ })),
165
+ root: zod.z.string(),
166
+ listing: zod.z.string().optional()
167
+ }),
168
+ search_file: zod.z.object({
169
+ type: zod.z.literal("search_file_result"),
170
+ path: zod.z.string(),
171
+ pattern: zod.z.string(),
172
+ recursive: zod.z.boolean().optional(),
173
+ caseSensitive: zod.z.boolean().optional(),
174
+ results: zod.z.array(zod.z.object({
175
+ filePath: zod.z.string(),
176
+ size: zod.z.string(),
177
+ modifyTime: zod.z.string()
178
+ }))
179
+ }),
180
+ read_file: zod.z.object({
181
+ type: zod.z.literal("read_file_result"),
182
+ path: zod.z.string(),
183
+ content: zod.z.string(),
184
+ totalLineCount: zod.z.number(),
185
+ hasMore: zod.z.boolean(),
186
+ diagnostic: zod.z.string().optional(),
187
+ hint: zod.z.string().optional(),
188
+ image: zod.z.object({
189
+ data: zod.z.string(),
190
+ mimeType: zod.z.string()
191
+ }).optional()
192
+ }),
193
+ read_lints: zod.z.object({
194
+ type: zod.z.literal("read_lints_result"),
195
+ diagnostics: zod.z.array(zod.z.string()),
196
+ totalCount: zod.z.number().optional(),
197
+ hint: zod.z.string().optional(),
198
+ isTruncated: zod.z.boolean().optional()
199
+ }),
200
+ rag_search: zod.z.object({
201
+ type: zod.z.literal("knowledge_base_result"),
202
+ selectedKnowledgeBases: zod.z.string(),
203
+ queryInput: zod.z.string()
204
+ }),
205
+ read_rules: zod.z.object({
206
+ type: zod.z.literal("rule_match_result"),
207
+ ruleDescription: zod.z.string(),
208
+ filePaths: zod.z.array(zod.z.string())
209
+ }),
210
+ mcp_get_tool_description: zod.z.object({}).passthrough(),
211
+ mcp_call_tool: zod.z.object({
212
+ type: zod.z.literal("mcp_call_tool_result"),
213
+ serverName: zod.z.string(),
214
+ toolName: zod.z.string(),
215
+ data: zod.z.array(zod.z.union([
216
+ zod.z.object({
217
+ type: zod.z.literal("text"),
218
+ text: zod.z.string()
219
+ }),
220
+ zod.z.object({
221
+ type: zod.z.literal("image"),
222
+ data: zod.z.string(),
223
+ mimeType: zod.z.string()
224
+ }),
225
+ zod.z.object({
226
+ type: zod.z.literal("resource"),
227
+ resource: zod.z.object({
228
+ uri: zod.z.string(),
229
+ mimeType: zod.z.string().optional(),
230
+ text: zod.z.string().optional(),
231
+ blob: zod.z.string().optional()
232
+ })
233
+ })
234
+ ])),
235
+ isError: zod.z.boolean().optional(),
236
+ error: zod.z.unknown().optional(),
237
+ hint: zod.z.string().optional()
238
+ }),
239
+ fetch_mcp_resource: zod.z.object({
240
+ type: zod.z.literal("fetch_mcp_resource_result"),
241
+ server: zod.z.string(),
242
+ uri: zod.z.string(),
243
+ content: zod.z.string(),
244
+ downloadPath: zod.z.string().optional()
245
+ }),
246
+ create_rule: zod.z.object({
247
+ type: zod.z.literal("rule_create_result"),
248
+ ruleName: zod.z.string(),
249
+ createState: zod.z.enum([
250
+ "success",
251
+ "invoke",
252
+ "cancelled"
253
+ ]),
254
+ hint: zod.z.string().optional(),
255
+ filePath: zod.z.string().optional()
256
+ }),
257
+ update_memory: zod.z.object({
258
+ type: zod.z.literal("update_memory_result"),
259
+ success: zod.z.boolean(),
260
+ message: zod.z.string(),
261
+ action: zod.z.enum([
262
+ "create",
263
+ "update",
264
+ "delete"
265
+ ]),
266
+ knowledge_id: zod.z.string().optional()
267
+ }),
268
+ search_content: zod.z.object({
269
+ type: zod.z.literal("search_content_result"),
270
+ directory: zod.z.string(),
271
+ pattern: zod.z.string(),
272
+ fileTypes: zod.z.string(),
273
+ matches: zod.z.array(zod.z.object({
274
+ filePath: zod.z.string(),
275
+ content: zod.z.string(),
276
+ startLine: zod.z.number(),
277
+ endLine: zod.z.number(),
278
+ size: zod.z.string(),
279
+ modifyTime: zod.z.string()
280
+ })),
281
+ totalCount: zod.z.number(),
282
+ hasMore: zod.z.boolean(),
283
+ offset: zod.z.number(),
284
+ limit: zod.z.number(),
285
+ contextBefore: zod.z.number(),
286
+ contextAfter: zod.z.number(),
287
+ contextAround: zod.z.number().optional(),
288
+ outputMode: zod.z.string(),
289
+ caseSensitive: zod.z.boolean(),
290
+ hint: zod.z.string().optional()
291
+ }),
292
+ write_to_file: zod.z.object({
293
+ type: zod.z.literal("write_to_file_result"),
294
+ path: zod.z.string(),
295
+ addLineCount: zod.z.number(),
296
+ removedLines: zod.z.number(),
297
+ addedChars: zod.z.number().optional(),
298
+ removedChars: zod.z.number().optional(),
299
+ bytesWritten: zod.z.number(),
300
+ isNewFile: zod.z.boolean(),
301
+ oldContent: zod.z.string().optional(),
302
+ diagnostic: zod.z.string().optional()
303
+ }),
304
+ replace_in_file: zod.z.object({
305
+ type: zod.z.literal("replace_in_file_result"),
306
+ path: zod.z.string(),
307
+ addLineCount: zod.z.number().optional(),
308
+ removedLines: zod.z.number().optional(),
309
+ addedChars: zod.z.number().optional(),
310
+ removedChars: zod.z.number().optional(),
311
+ matchCount: zod.z.number().optional(),
312
+ hint: zod.z.string().optional(),
313
+ diagnosticChange: zod.z.object({
314
+ added: zod.z.string(),
315
+ removed: zod.z.string(),
316
+ unchanged: zod.z.string()
317
+ }).optional()
318
+ }),
319
+ delete_file: zod.z.object({
320
+ type: zod.z.literal("delete_file_result"),
321
+ path: zod.z.string(),
322
+ recursive: zod.z.boolean(),
323
+ hint: zod.z.string().optional()
324
+ }),
325
+ execute_command: zod.z.object({
326
+ type: zod.z.literal("execute_command_result"),
327
+ stdout: zod.z.string(),
328
+ stderr: zod.z.string(),
329
+ exitCode: zod.z.number(),
330
+ hint: zod.z.string().optional(),
331
+ serviceInfo: zod.z.object({
332
+ isWatchCommand: zod.z.boolean(),
333
+ isServiceOutput: zod.z.boolean(),
334
+ serviceReady: zod.z.boolean(),
335
+ message: zod.z.string()
336
+ }).optional(),
337
+ use_standalone_terminal: zod.z.boolean().optional()
338
+ }),
339
+ preview_url: zod.z.object({
340
+ type: zod.z.literal("preview_tool_result"),
341
+ url: zod.z.string(),
342
+ message: zod.z.string()
343
+ }),
344
+ ask_followup_question: zod.z.object({
345
+ type: zod.z.literal("multi_question_result"),
346
+ questions: zod.z.array(zod.z.object({
347
+ id: zod.z.string(),
348
+ question: zod.z.string(),
349
+ options: zod.z.array(zod.z.string()),
350
+ multiSelect: zod.z.boolean().optional(),
351
+ title: zod.z.string().optional()
352
+ })),
353
+ answers: zod.z.record(zod.z.union([zod.z.string(), zod.z.array(zod.z.string())])),
354
+ message: zod.z.string()
355
+ }),
356
+ invoke_integration: zod.z.object({
357
+ type: zod.z.literal("invoke_integration_tool_result"),
358
+ recommend: zod.z.object({
359
+ id: zod.z.string(),
360
+ type: zod.z.string(),
361
+ status: zod.z.enum(["connected", "disconnected"])
362
+ }),
363
+ message: zod.z.string()
364
+ }),
365
+ call_integration: zod.z.object({
366
+ type: zod.z.literal("call_integration_tool_result"),
367
+ integrationId: zod.z.string(),
368
+ toolName: zod.z.string(),
369
+ data: zod.z.object({
370
+ type: zod.z.literal("text"),
371
+ text: zod.z.string()
372
+ }),
373
+ isError: zod.z.boolean().optional(),
374
+ error: zod.z.unknown().optional()
375
+ }),
376
+ search_integration_tool: zod.z.object({
377
+ type: zod.z.literal("search_integration_tool_result"),
378
+ data: zod.z.array(zod.z.object({
379
+ integrationId: zod.z.string(),
380
+ integrationName: zod.z.string(),
381
+ toolName: zod.z.string(),
382
+ description: zod.z.string(),
383
+ inputSchema: zod.z.record(zod.z.unknown())
384
+ })),
385
+ hint: zod.z.string().optional()
386
+ }),
387
+ supabase_get_logs: zod.z.object({
388
+ type: zod.z.enum([
389
+ "supabase_get_logs_result",
390
+ "supabase_execute_sql_result",
391
+ "supabase_apply_migration_result",
392
+ "supabase_list_migration_result",
393
+ "supabase_list_tables_result"
394
+ ]),
395
+ message: zod.z.string()
396
+ }),
397
+ supabase_execute_sql: zod.z.object({
398
+ type: zod.z.enum([
399
+ "supabase_get_logs_result",
400
+ "supabase_execute_sql_result",
401
+ "supabase_apply_migration_result",
402
+ "supabase_list_migration_result",
403
+ "supabase_list_tables_result"
404
+ ]),
405
+ message: zod.z.string()
406
+ }),
407
+ supabase_apply_migration: zod.z.object({
408
+ type: zod.z.enum([
409
+ "supabase_get_logs_result",
410
+ "supabase_execute_sql_result",
411
+ "supabase_apply_migration_result",
412
+ "supabase_list_migration_result",
413
+ "supabase_list_tables_result"
414
+ ]),
415
+ message: zod.z.string()
416
+ }),
417
+ supabase_list_migration: zod.z.object({
418
+ type: zod.z.enum([
419
+ "supabase_get_logs_result",
420
+ "supabase_execute_sql_result",
421
+ "supabase_apply_migration_result",
422
+ "supabase_list_migration_result",
423
+ "supabase_list_tables_result"
424
+ ]),
425
+ message: zod.z.string()
426
+ }),
427
+ supabase_list_tables: zod.z.object({
428
+ type: zod.z.enum([
429
+ "supabase_get_logs_result",
430
+ "supabase_execute_sql_result",
431
+ "supabase_apply_migration_result",
432
+ "supabase_list_migration_result",
433
+ "supabase_list_tables_result"
434
+ ]),
435
+ message: zod.z.string()
436
+ }),
437
+ cloud_studio_fetch_log: zod.z.object({
438
+ type: zod.z.literal("cloud_studio_fetch_log_result"),
439
+ success: zod.z.boolean(),
440
+ logs: zod.z.record(zod.z.string())
441
+ }),
442
+ cloud_studio_execute_command: zod.z.object({
443
+ type: zod.z.literal("cloud_studio_execute_command_result"),
444
+ success: zod.z.boolean(),
445
+ message: zod.z.string()
446
+ }),
447
+ cloud_studio_deploy_sandbox: zod.z.object({
448
+ type: zod.z.literal("cloud_studio_integration_result"),
449
+ previewUrl: zod.z.string().optional(),
450
+ steps: zod.z.array(zod.z.object({
451
+ status: zod.z.enum([
452
+ "idle",
453
+ "success",
454
+ "running",
455
+ "error"
456
+ ]),
457
+ name: zod.z.enum([
458
+ "createSandbox",
459
+ "uploadProject",
460
+ "installDependencies",
461
+ "startService",
462
+ "preview"
463
+ ]),
464
+ error: zod.z.object({
465
+ code: zod.z.number().optional(),
466
+ message: zod.z.string().optional()
467
+ }).optional()
468
+ }))
469
+ }),
470
+ component_get_prompt: zod.z.object({
471
+ type: zod.z.literal("component_get_prompt_result"),
472
+ componentType: zod.z.string(),
473
+ webFramework: zod.z.string(),
474
+ data: zod.z.object({
475
+ type: zod.z.literal("text"),
476
+ text: zod.z.string()
477
+ })
478
+ }),
479
+ web_fetch: zod.z.object({
480
+ type: zod.z.literal("web_fetch_tool_result"),
481
+ message: zod.z.string(),
482
+ data: zod.z.string(),
483
+ loading: zod.z.string().optional(),
484
+ title: zod.z.string().optional(),
485
+ favicon: zod.z.string().optional()
486
+ }),
487
+ use_skill: zod.z.object({
488
+ type: zod.z.literal("use_skill_tool_result"),
489
+ commandMessage: zod.z.string(),
490
+ message: zod.z.string()
491
+ }),
492
+ web_search: zod.z.object({
493
+ type: zod.z.literal("web_search_tool_result"),
494
+ data: zod.z.array(zod.z.object({
495
+ passage: zod.z.string(),
496
+ uri: zod.z.string(),
497
+ site: zod.z.string(),
498
+ title: zod.z.string(),
499
+ snippets: zod.z.array(zod.z.string()).optional(),
500
+ content: zod.z.string().optional()
501
+ })),
502
+ searchInput: zod.z.string().optional()
503
+ }),
504
+ task: zod.z.object({
505
+ type: zod.z.literal("task_tool_result"),
506
+ toolInfo: zod.z.array(zod.z.object({
507
+ name: zod.z.string(),
508
+ info: zod.z.string(),
509
+ needApprove: zod.z.boolean().optional(),
510
+ toolCallId: zod.z.string().optional(),
511
+ executeStatus: zod.z.enum([
512
+ "ing",
513
+ "completed",
514
+ "cancel",
515
+ "fail"
516
+ ]).optional()
517
+ })).optional(),
518
+ startCallTool: zod.z.boolean().optional(),
519
+ finalResult: zod.z.string().optional(),
520
+ toolCallBrief: zod.z.string().optional()
521
+ }),
522
+ codebase_search: zod.z.object({
523
+ type: zod.z.literal("codebase_search_result"),
524
+ query: zod.z.string(),
525
+ path: zod.z.string(),
526
+ content: zod.z.string()
527
+ }),
528
+ lsp: zod.z.object({
529
+ type: zod.z.literal("lsp_tool_result"),
530
+ operation: zod.z.string(),
531
+ result: zod.z.string(),
532
+ resultCount: zod.z.number().optional(),
533
+ fileCount: zod.z.number().optional(),
534
+ character: zod.z.number().optional()
535
+ }),
536
+ spec_create: zod.z.object({
537
+ type: zod.z.literal("plan_create_tool_result"),
538
+ message: zod.z.string(),
539
+ data: zod.z.string()
540
+ }),
541
+ spec_update: zod.z.object({
542
+ type: zod.z.literal("plan_update_tool_result"),
543
+ status: zod.z.enum([
544
+ "prepare",
545
+ "ready",
546
+ "building",
547
+ "finished"
548
+ ]),
549
+ data: zod.z.string(),
550
+ reminder: zod.z.string()
551
+ })
552
+ };
553
+
554
+ //#endregion
555
+ //#region ../agent-provider/src/common/_legacy/MockAgentProvider.ts
556
+ /**
557
+ * Mock 会话数据存储
558
+ * 每个会话都有对应的模拟历史消息
559
+ */
560
+ const mockSessionHistories = /* @__PURE__ */ new Map();
561
+ mockSessionHistories.set("1", [
562
+ {
563
+ type: "user",
564
+ content: "帮我开发一个五子棋游戏,需要包含以下功能:\n1. 双人对战模式\n2. 悔棋功能\n3. 计时器",
565
+ timestamp: Date.now() - 18e5 - 6e4
566
+ },
567
+ {
568
+ type: "assistant",
569
+ content: "好的,我来帮你开发一个五子棋游戏。我会创建以下文件结构:\n\n- `index.html` - 主页面\n- `game.js` - 游戏逻辑\n- `style.css` - 样式文件\n\n让我开始创建这些文件...",
570
+ timestamp: Date.now() - 18e5 - 5e4
571
+ },
572
+ {
573
+ type: "assistant",
574
+ content: "我已经完成了所有文件的创建和修改。游戏支持双人对战、悔棋和计时功能。你可以直接在浏览器中打开 index.html 开始游戏。",
575
+ timestamp: Date.now() - 18e5
576
+ }
577
+ ]);
578
+ mockSessionHistories.set("2", [
579
+ {
580
+ type: "user",
581
+ content: "登录页面的样式有问题,按钮颜色不对齐,帮我修复一下",
582
+ timestamp: Date.now() - 72e5 - 12e4
583
+ },
584
+ {
585
+ type: "assistant",
586
+ content: "我来检查登录页面的样式。让我先看看相关的 CSS 文件...",
587
+ timestamp: Date.now() - 72e5 - 1e5
588
+ },
589
+ {
590
+ type: "assistant",
591
+ content: "样式问题已修复,请查看效果。主要修改了按钮的 flex 布局和颜色变量。",
592
+ timestamp: Date.now() - 72e5
593
+ }
594
+ ]);
595
+ mockSessionHistories.set("3", [
596
+ {
597
+ type: "user",
598
+ content: "API 接口响应太慢了,需要添加缓存和错误重试机制",
599
+ timestamp: Date.now() - 144e5 - 18e4
600
+ },
601
+ {
602
+ type: "assistant",
603
+ content: "好的,我来优化 API 接口。我会实现:\n1. Redis 缓存层\n2. 指数退避重试策略\n3. 请求去重",
604
+ timestamp: Date.now() - 144e5 - 15e4
605
+ },
606
+ {
607
+ type: "assistant",
608
+ content: "已添加缓存和错误重试机制。性能提升了约 60%。",
609
+ timestamp: Date.now() - 144e5
610
+ }
611
+ ]);
612
+ mockSessionHistories.set("4", [
613
+ {
614
+ type: "user",
615
+ content: "帮我为核心模块添加单元测试,覆盖率要达到 80% 以上",
616
+ timestamp: Date.now() - 864e5 - 3e5
617
+ },
618
+ {
619
+ type: "assistant",
620
+ content: "好的,我会使用 Jest 来编写单元测试。让我先看看核心模块的代码结构...",
621
+ timestamp: Date.now() - 864e5 - 25e4
622
+ },
623
+ {
624
+ type: "assistant",
625
+ content: "测试覆盖率已达到 85%,超过了目标。主要测试了:\n- 用户认证逻辑\n- 数据验证\n- 错误处理",
626
+ timestamp: Date.now() - 864e5
627
+ }
628
+ ]);
629
+
630
+ //#endregion
8
631
  //#region ../agent-client-protocol/src/common/types.ts
9
632
  /**
10
633
  * Protocol Extension Types for Agent Client Protocol
@@ -81,7 +704,7 @@ function parseSSELine(line, currentEvent) {
81
704
  function streamableHttp(options) {
82
705
  const { endpoint, authToken, headers: customHeaders = {}, reconnect = {}, signal: externalSignal, fetch: customFetch = globalThis.fetch, onConnect, onDisconnect, onError, heartbeatTimeout = 6e4, postTimeout = 3e4, backpressure = {} } = options;
83
706
  const { enabled: reconnectEnabled = true, initialDelay = 1e3, maxDelay = 3e4, maxRetries = Infinity, jitter: jitterEnabled = true } = reconnect;
84
- const { highWaterMark = 100, lowWaterMark = 50 } = backpressure;
707
+ const { highWaterMark = 100, lowWaterMark = 50, pauseTimeout = 5e3 } = backpressure;
85
708
  let connectionId;
86
709
  let lastEventId;
87
710
  let reconnectAttempts = 0;
@@ -110,6 +733,7 @@ function streamableHttp(options) {
110
733
  let streamError = null;
111
734
  let isPaused = false;
112
735
  let resumeReading = null;
736
+ let backgroundSSEProcessors = /* @__PURE__ */ new Set();
113
737
  let lastActivity = Date.now();
114
738
  let heartbeatCheckTimer;
115
739
  function enqueueMessage(message) {
@@ -132,7 +756,8 @@ function streamableHttp(options) {
132
756
  const message = messageQueue.shift();
133
757
  if (isPaused && messageQueue.length <= lowWaterMark) {
134
758
  isPaused = false;
135
- resumeReading?.();
759
+ const resume = resumeReading;
760
+ if (resume) queueMicrotask(() => resume());
136
761
  }
137
762
  return Promise.resolve(message);
138
763
  }
@@ -186,6 +811,7 @@ function streamableHttp(options) {
186
811
  resumeReading();
187
812
  resumeReading = null;
188
813
  }
814
+ backgroundSSEProcessors.clear();
189
815
  while (messageResolvers.length > 0) messageResolvers.shift()(null);
190
816
  }
191
817
  async function sendDelete() {
@@ -218,7 +844,21 @@ function streamableHttp(options) {
218
844
  while (true) {
219
845
  if (isPaused) {
220
846
  await new Promise((resolve) => {
221
- resumeReading = resolve;
847
+ let resolved = false;
848
+ const timeoutId = setTimeout(() => {
849
+ if (!resolved) {
850
+ resolved = true;
851
+ console.warn("[StreamableHTTP] Backpressure pause timeout, forcing resume");
852
+ resolve();
853
+ }
854
+ }, pauseTimeout);
855
+ resumeReading = () => {
856
+ if (!resolved) {
857
+ resolved = true;
858
+ clearTimeout(timeoutId);
859
+ resolve();
860
+ }
861
+ };
222
862
  });
223
863
  resumeReading = null;
224
864
  }
@@ -251,6 +891,19 @@ function streamableHttp(options) {
251
891
  reader.releaseLock();
252
892
  }
253
893
  }
894
+ /**
895
+ * Process SSE stream in background without blocking the caller.
896
+ * This prevents deadlock when POST responses return SSE streams.
897
+ */
898
+ function processSSEStreamBackground(reader) {
899
+ const promise = processSSEStream(reader).catch((error) => {
900
+ console.error("[StreamableHTTP] Background SSE processing error:", error);
901
+ onError?.(error instanceof Error ? error : new Error(String(error)));
902
+ }).finally(() => {
903
+ backgroundSSEProcessors.delete(promise);
904
+ });
905
+ backgroundSSEProcessors.add(promise);
906
+ }
254
907
  async function startSSEConnection() {
255
908
  let currentReader = null;
256
909
  const triggerReconnect = () => {
@@ -340,7 +993,7 @@ function streamableHttp(options) {
340
993
  const contentType = response.headers.get("Content-Type") || "";
341
994
  if (contentType.includes("text/event-stream")) {
342
995
  const reader = response.body?.getReader();
343
- if (reader) await processSSEStream(reader);
996
+ if (reader) processSSEStreamBackground(reader);
344
997
  } else if (contentType.includes("application/json")) {
345
998
  const data = await response.json();
346
999
  if (data && typeof data === "object" && "jsonrpc" in data) enqueueMessage(data);
@@ -3858,9 +4511,11 @@ const SELECTED_ACCOUNT_KEY = "CODEBUDDY_IDE_SELECTED_ACCOUNT_ID";
3858
4511
  * Backend Provider 实现类
3859
4512
  *
3860
4513
  * 职责:
3861
- * - 与后端 API 通信(getAgents, getModels, getAccount 等)
3862
4514
  * - 触发登录/登出流程
3863
4515
  * - 获取 account 后自动同步到 accountService
4516
+ *
4517
+ * 注意:getAgents 和 getModels 方法已废弃并移除,
4518
+ * 请使用 IAgentAdapter 中的对应方法
3864
4519
  */
3865
4520
  var BackendProvider = class {
3866
4521
  constructor(config) {
@@ -3868,98 +4523,6 @@ var BackendProvider = class {
3868
4523
  this.authToken = config.authToken;
3869
4524
  }
3870
4525
  /**
3871
- * 获取 Agent 列表
3872
- * API 端点: GET /v2/cloudagent/agentmgmt/agents
3873
- */
3874
- async getAgents(request = {}) {
3875
- const { MockAgentProvider } = await Promise.resolve().then(() => require("./MockAgentProvider-4e4oOusg.cjs"));
3876
- const sessions = new MockAgentProvider().getAllSessions();
3877
- const mockTitles = {
3878
- "1": "开发五子棋游戏",
3879
- "2": "修复登录页面样式",
3880
- "3": "API 接口优化"
3881
- };
3882
- const agents = sessions.map((session, index) => ({
3883
- id: session.sessionId,
3884
- name: mockTitles[session.sessionId] || `Agent ${session.sessionId}`,
3885
- status: "RUNNING",
3886
- visibility: "PRIVATE",
3887
- createdAt: new Date(session.createdAt).toISOString(),
3888
- summary: `Session created at ${new Date(session.createdAt).toLocaleString()}`,
3889
- source: {
3890
- provider: "github",
3891
- ref: "refs/heads/main",
3892
- repository: session.cwd
3893
- },
3894
- target: {
3895
- autoCreatePr: false,
3896
- branchName: "feature/mock",
3897
- prUrl: void 0,
3898
- url: void 0
3899
- }
3900
- }));
3901
- return {
3902
- agents,
3903
- pagination: {
3904
- hasNext: false,
3905
- hasPrev: false,
3906
- page: 1,
3907
- size: agents.length,
3908
- total: agents.length,
3909
- totalPages: 1
3910
- }
3911
- };
3912
- }
3913
- /**
3914
- * 获取可用模型列表
3915
- * API 端点: GET /v2/cloudagent/models (假设)
3916
- *
3917
- * 当前实现: 返回 Mock 数据
3918
- */
3919
- async getModels(request) {
3920
- const mockModels = [{
3921
- id: "glm-4.7",
3922
- name: "GLM-4.7",
3923
- vendor: "f",
3924
- maxOutputTokens: 48e3,
3925
- maxInputTokens: 2e5,
3926
- supportsToolCall: true,
3927
- supportsImages: false,
3928
- disabledMultimodal: true,
3929
- maxAllowedSize: 2e5,
3930
- supportsReasoning: true,
3931
- onlyReasoning: true,
3932
- temperature: 1,
3933
- reasoning: {
3934
- effort: "medium",
3935
- summary: "auto"
3936
- },
3937
- descriptionEn: "GLM-4.7 model, Well-rounded model for everyday use",
3938
- descriptionZh: "GLM-4.7 大模型,能力均衡,适合日常使用"
3939
- }, {
3940
- id: "glm-4.7-flash",
3941
- name: "GLM-4.7 Flash",
3942
- vendor: "f",
3943
- maxOutputTokens: 4e4,
3944
- maxInputTokens: 128e3,
3945
- supportsToolCall: true,
3946
- supportsImages: false,
3947
- disabledMultimodal: false,
3948
- maxAllowedSize: 128e3,
3949
- supportsReasoning: false,
3950
- onlyReasoning: false,
3951
- temperature: .7,
3952
- reasoning: {
3953
- effort: "low",
3954
- summary: "never"
3955
- },
3956
- descriptionEn: "GLM-4.7 Flash, Fast and efficient model",
3957
- descriptionZh: "GLM-4.7 Flash,快速高效的模型"
3958
- }];
3959
- console.log("[BackendProvider] getModels called for repository:", request.repository);
3960
- return { models: mockModels };
3961
- }
3962
- /**
3963
4526
  * 获取当前账号信息
3964
4527
  * API 端点: GET /console/accounts (返回账号列表)
3965
4528
  *
@@ -4184,8 +4747,6 @@ function createBackendProvider(config) {
4184
4747
  * Backend 请求类型常量
4185
4748
  */
4186
4749
  const BACKEND_REQUEST_TYPES = {
4187
- GET_AGENTS: "backend:get-agents-request",
4188
- GET_MODELS: "backend:get-models",
4189
4750
  LOGIN: "backend:login",
4190
4751
  LOGOUT: "backend:logout",
4191
4752
  GET_ACCOUNT: "backend:get-account"
@@ -4199,7 +4760,7 @@ function generateRequestId() {
4199
4760
  /**
4200
4761
  * IPC Backend Provider 实现类
4201
4762
  *
4202
- * 通过 IWidgetChannel 与后端通信获取 Agent 列表
4763
+ * 通过 IWidgetChannel 与后端通信
4203
4764
  */
4204
4765
  var IPCBackendProvider = class {
4205
4766
  constructor(config) {
@@ -4230,32 +4791,6 @@ var IPCBackendProvider = class {
4230
4791
  return response?.data !== void 0 ? response.data : response;
4231
4792
  }
4232
4793
  /**
4233
- * 获取 Agent 列表
4234
- * 通过 IWidgetChannel 发送请求到后端
4235
- */
4236
- async getAgents(request = {}) {
4237
- this.log("Getting agents with request:", request);
4238
- try {
4239
- return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_AGENTS, request);
4240
- } catch (error) {
4241
- this.log("Get agents failed:", error);
4242
- throw error;
4243
- }
4244
- }
4245
- /**
4246
- * 获取可用模型列表
4247
- * 通过 IWidgetChannel 发送请求到后端
4248
- */
4249
- async getModels(request) {
4250
- this.log("Getting models with request:", request);
4251
- try {
4252
- return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_MODELS, request);
4253
- } catch (error) {
4254
- this.log("Get models failed:", error);
4255
- throw error;
4256
- }
4257
- }
4258
- /**
4259
4794
  * 获取当前账号信息
4260
4795
  * IDE 环境: 通过 IPC 获取账号信息,并同步到 accountService
4261
4796
  */