@xagent-ai/cli 1.3.0 → 1.3.2

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.
Files changed (190) hide show
  1. package/.github/release.yml +76 -0
  2. package/.github/workflows/ci.yml +3 -0
  3. package/.github/workflows/release.yml +11 -17
  4. package/README.md +2 -2
  5. package/README_CN.md +2 -2
  6. package/dist/agents.d.ts.map +1 -1
  7. package/dist/agents.js +7 -3
  8. package/dist/agents.js.map +1 -1
  9. package/dist/ai-client/factory.d.ts +0 -12
  10. package/dist/ai-client/factory.d.ts.map +1 -1
  11. package/dist/ai-client/factory.js +0 -32
  12. package/dist/ai-client/factory.js.map +1 -1
  13. package/dist/ai-client/index.js +1 -1
  14. package/dist/ai-client/index.js.map +1 -1
  15. package/dist/ai-client/providers/anthropic.d.ts.map +1 -1
  16. package/dist/ai-client/providers/anthropic.js +10 -4
  17. package/dist/ai-client/providers/anthropic.js.map +1 -1
  18. package/dist/ai-client/providers/openai.d.ts.map +1 -1
  19. package/dist/ai-client/providers/openai.js +8 -4
  20. package/dist/ai-client/providers/openai.js.map +1 -1
  21. package/dist/ai-client/providers/remote.d.ts +0 -1
  22. package/dist/ai-client/providers/remote.d.ts.map +1 -1
  23. package/dist/ai-client/providers/remote.js +11 -10
  24. package/dist/ai-client/providers/remote.js.map +1 -1
  25. package/dist/ai-client/types.d.ts +14 -0
  26. package/dist/ai-client/types.d.ts.map +1 -1
  27. package/dist/ai-client/types.js +17 -0
  28. package/dist/ai-client/types.js.map +1 -1
  29. package/dist/ai-client-factory.d.ts.map +1 -1
  30. package/dist/ai-client-factory.js +4 -4
  31. package/dist/ai-client-factory.js.map +1 -1
  32. package/dist/auth.d.ts.map +1 -1
  33. package/dist/auth.js +10 -12
  34. package/dist/auth.js.map +1 -1
  35. package/dist/cancellation.d.ts.map +1 -1
  36. package/dist/cancellation.js +3 -5
  37. package/dist/cancellation.js.map +1 -1
  38. package/dist/checkpoint.d.ts +1 -0
  39. package/dist/checkpoint.d.ts.map +1 -1
  40. package/dist/checkpoint.js +38 -4
  41. package/dist/checkpoint.js.map +1 -1
  42. package/dist/cli.js +132 -32
  43. package/dist/cli.js.map +1 -1
  44. package/dist/config.js +1 -1
  45. package/dist/config.js.map +1 -1
  46. package/dist/context-compressor.d.ts +1 -2
  47. package/dist/context-compressor.d.ts.map +1 -1
  48. package/dist/context-compressor.js +22 -17
  49. package/dist/context-compressor.js.map +1 -1
  50. package/dist/conversation.d.ts +1 -1
  51. package/dist/conversation.d.ts.map +1 -1
  52. package/dist/conversation.js +8 -7
  53. package/dist/conversation.js.map +1 -1
  54. package/dist/gui-subagent/action-parser/actionParser.js +2 -2
  55. package/dist/gui-subagent/action-parser/actionParser.js.map +1 -1
  56. package/dist/gui-subagent/agent/gui-agent.d.ts +10 -0
  57. package/dist/gui-subagent/agent/gui-agent.d.ts.map +1 -1
  58. package/dist/gui-subagent/agent/gui-agent.js +105 -32
  59. package/dist/gui-subagent/agent/gui-agent.js.map +1 -1
  60. package/dist/gui-subagent/index.d.ts +7 -0
  61. package/dist/gui-subagent/index.d.ts.map +1 -1
  62. package/dist/gui-subagent/index.js +2 -0
  63. package/dist/gui-subagent/index.js.map +1 -1
  64. package/dist/gui-subagent/operator/computer-operator.d.ts.map +1 -1
  65. package/dist/gui-subagent/operator/computer-operator.js +2 -0
  66. package/dist/gui-subagent/operator/computer-operator.js.map +1 -1
  67. package/dist/input-processor.js +2 -2
  68. package/dist/input-processor.js.map +1 -1
  69. package/dist/logger.d.ts.map +1 -1
  70. package/dist/logger.js +1 -1
  71. package/dist/logger.js.map +1 -1
  72. package/dist/mcp.d.ts +2 -1
  73. package/dist/mcp.d.ts.map +1 -1
  74. package/dist/mcp.js +84 -21
  75. package/dist/mcp.js.map +1 -1
  76. package/dist/memory.d.ts.map +1 -1
  77. package/dist/memory.js +3 -3
  78. package/dist/memory.js.map +1 -1
  79. package/dist/output-util.d.ts +27 -0
  80. package/dist/output-util.d.ts.map +1 -0
  81. package/dist/output-util.js +74 -0
  82. package/dist/output-util.js.map +1 -0
  83. package/dist/retry.js +1 -1
  84. package/dist/retry.js.map +1 -1
  85. package/dist/ripgrep.d.ts.map +1 -1
  86. package/dist/ripgrep.js +5 -3
  87. package/dist/ripgrep.js.map +1 -1
  88. package/dist/sdk-output-adapter.d.ts +265 -0
  89. package/dist/sdk-output-adapter.d.ts.map +1 -0
  90. package/dist/sdk-output-adapter.js +701 -0
  91. package/dist/sdk-output-adapter.js.map +1 -0
  92. package/dist/sdk-session.d.ts +13 -0
  93. package/dist/sdk-session.d.ts.map +1 -0
  94. package/dist/sdk-session.js +50 -0
  95. package/dist/sdk-session.js.map +1 -0
  96. package/dist/session-manager.js +3 -3
  97. package/dist/session-manager.js.map +1 -1
  98. package/dist/session.d.ts +96 -2
  99. package/dist/session.d.ts.map +1 -1
  100. package/dist/session.js +849 -262
  101. package/dist/session.js.map +1 -1
  102. package/dist/shell.d.ts.map +1 -1
  103. package/dist/shell.js +5 -4
  104. package/dist/shell.js.map +1 -1
  105. package/dist/skill-installer.js +3 -3
  106. package/dist/skill-installer.js.map +1 -1
  107. package/dist/skill-invoker.d.ts +1 -1
  108. package/dist/skill-invoker.d.ts.map +1 -1
  109. package/dist/skill-invoker.js +2 -2
  110. package/dist/skill-invoker.js.map +1 -1
  111. package/dist/skill-loader.js +6 -5
  112. package/dist/skill-loader.js.map +1 -1
  113. package/dist/skill-manager.d.ts.map +1 -1
  114. package/dist/skill-manager.js +3 -2
  115. package/dist/skill-manager.js.map +1 -1
  116. package/dist/slash-commands.d.ts +1 -1
  117. package/dist/slash-commands.d.ts.map +1 -1
  118. package/dist/slash-commands.js +24 -11
  119. package/dist/slash-commands.js.map +1 -1
  120. package/dist/smart-approval.d.ts +20 -1
  121. package/dist/smart-approval.d.ts.map +1 -1
  122. package/dist/smart-approval.js +58 -1
  123. package/dist/smart-approval.js.map +1 -1
  124. package/dist/system-prompt-generator.js +3 -3
  125. package/dist/system-prompt-generator.js.map +1 -1
  126. package/dist/theme.d.ts.map +1 -1
  127. package/dist/theme.js +9 -8
  128. package/dist/theme.js.map +1 -1
  129. package/dist/tools.d.ts +15 -0
  130. package/dist/tools.d.ts.map +1 -1
  131. package/dist/tools.js +487 -215
  132. package/dist/tools.js.map +1 -1
  133. package/dist/types.d.ts +57 -0
  134. package/dist/types.d.ts.map +1 -1
  135. package/dist/types.js +49 -0
  136. package/dist/types.js.map +1 -1
  137. package/dist/update.d.ts.map +1 -1
  138. package/dist/update.js +12 -9
  139. package/dist/update.js.map +1 -1
  140. package/dist/workflow.d.ts.map +1 -1
  141. package/dist/workflow.js +1 -2
  142. package/dist/workflow.js.map +1 -1
  143. package/docs/third-party-models.md +16 -15
  144. package/package.json +3 -1
  145. package/src/agents.ts +7 -3
  146. package/src/ai-client/factory.ts +1 -36
  147. package/src/ai-client/index.ts +1 -1
  148. package/src/ai-client/providers/anthropic.ts +12 -3
  149. package/src/ai-client/providers/openai.ts +10 -4
  150. package/src/ai-client/providers/remote.ts +13 -10
  151. package/src/ai-client/types.ts +19 -0
  152. package/src/ai-client-factory.ts +5 -5
  153. package/src/auth.ts +11 -13
  154. package/src/cancellation.ts +3 -6
  155. package/src/checkpoint.ts +41 -4
  156. package/src/cli.ts +154 -37
  157. package/src/config.ts +1 -1
  158. package/src/context-compressor.ts +27 -22
  159. package/src/conversation.ts +9 -7
  160. package/src/gui-subagent/action-parser/actionParser.ts +2 -2
  161. package/src/gui-subagent/agent/gui-agent.ts +117 -34
  162. package/src/gui-subagent/index.ts +8 -0
  163. package/src/gui-subagent/operator/computer-operator.ts +2 -1
  164. package/src/input-processor.ts +2 -2
  165. package/src/logger.ts +2 -4
  166. package/src/mcp.ts +87 -23
  167. package/src/memory.ts +3 -4
  168. package/src/output-util.ts +80 -0
  169. package/src/retry.ts +1 -1
  170. package/src/ripgrep.ts +5 -3
  171. package/src/sdk-output-adapter.ts +842 -0
  172. package/src/sdk-session.ts +62 -0
  173. package/src/session-manager.ts +3 -3
  174. package/src/session.ts +942 -302
  175. package/src/shell.ts +6 -5
  176. package/src/skill-installer.ts +3 -3
  177. package/src/skill-invoker.ts +3 -4
  178. package/src/skill-loader.ts +7 -7
  179. package/src/skill-manager.ts +4 -3
  180. package/src/slash-commands.ts +24 -16
  181. package/src/smart-approval.ts +76 -1
  182. package/src/system-prompt-generator.ts +3 -3
  183. package/src/theme.ts +10 -9
  184. package/src/tools.ts +563 -267
  185. package/src/types.ts +118 -0
  186. package/src/update.ts +12 -9
  187. package/src/workflow.ts +2 -4
  188. package/test/cli-launch.test.ts +279 -0
  189. package/vitest.config.ts +2 -0
  190. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
@@ -0,0 +1,701 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * SDK Output Adapter
4
+ *
5
+ * This module provides output formatting for SDK mode.
6
+ * It converts CLI-style output into JSON format for programmatic consumption.
7
+ */
8
+ export class SdkOutputAdapter {
9
+ outputHandler;
10
+ indentLevel;
11
+ constructor(outputHandler) {
12
+ this.outputHandler = outputHandler || ((msg) => {
13
+ process.stdout.write(JSON.stringify(msg) + '\n');
14
+ });
15
+ this.indentLevel = 0;
16
+ }
17
+ /**
18
+ * Set indent level for output formatting.
19
+ */
20
+ setIndentLevel(level) {
21
+ this.indentLevel = level;
22
+ }
23
+ /**
24
+ * Get current indent string.
25
+ */
26
+ getIndent() {
27
+ return ' '.repeat(this.indentLevel);
28
+ }
29
+ /**
30
+ * Format and output a welcome message.
31
+ */
32
+ outputWelcome(language, executionMode) {
33
+ const messages = {
34
+ zh: {
35
+ title: '🤖 XAGENT CLI',
36
+ version: 'v1.0.0',
37
+ subtitle: 'AI-powered command-line assistant',
38
+ modeLabel: '当前模式',
39
+ modeDescription: '智能审批与安全检查',
40
+ help: '输入 /help 查看可用命令'
41
+ },
42
+ en: {
43
+ title: '🤖 XAGENT CLI',
44
+ version: 'v1.0.0',
45
+ subtitle: 'AI-powered command-line assistant',
46
+ modeLabel: 'Current Mode',
47
+ modeDescription: 'Smart approval with intelligent security checks',
48
+ help: 'Type /help to see available commands'
49
+ }
50
+ };
51
+ const msg = messages[language];
52
+ const config = this.getModeConfig(executionMode);
53
+ this.output({
54
+ type: 'system',
55
+ subtype: 'welcome',
56
+ timestamp: Date.now(),
57
+ data: {
58
+ title: msg.title,
59
+ version: msg.version,
60
+ subtitle: msg.subtitle,
61
+ mode: {
62
+ name: executionMode,
63
+ icon: config.icon,
64
+ description: msg.modeDescription
65
+ },
66
+ help: msg.help
67
+ }
68
+ });
69
+ }
70
+ /**
71
+ * Format and output ready signal.
72
+ * This is sent when the CLI is fully initialized and ready to accept requests.
73
+ */
74
+ outputReady() {
75
+ this.output({
76
+ type: 'system',
77
+ subtype: 'ready',
78
+ timestamp: Date.now(),
79
+ data: {
80
+ status: 'initialized',
81
+ message: 'CLI is ready to accept requests'
82
+ }
83
+ });
84
+ }
85
+ /**
86
+ * Format and output request done signal.
87
+ * This is sent when a user request has been fully processed.
88
+ */
89
+ outputRequestDone(requestId, status = 'success') {
90
+ this.output({
91
+ type: 'result',
92
+ subtype: 'request_done',
93
+ timestamp: Date.now(),
94
+ data: {
95
+ requestId,
96
+ status,
97
+ message: status === 'success' ? 'Request completed successfully' : `Request ${status}`
98
+ }
99
+ });
100
+ }
101
+ /**
102
+ * Format and output AI response.
103
+ */
104
+ outputAssistant(content, reasoningContent) {
105
+ this.output({
106
+ type: 'output',
107
+ subtype: 'assistant',
108
+ timestamp: Date.now(),
109
+ data: {
110
+ content,
111
+ reasoningContent
112
+ }
113
+ });
114
+ }
115
+ /**
116
+ * Format and output tool execution.
117
+ */
118
+ outputToolStart(toolName, params) {
119
+ this.output({
120
+ type: 'tool',
121
+ subtype: 'start',
122
+ timestamp: Date.now(),
123
+ data: {
124
+ tool: toolName,
125
+ params,
126
+ status: 'running'
127
+ }
128
+ });
129
+ }
130
+ /**
131
+ * Format and output tool result.
132
+ */
133
+ outputToolResult(toolName, result, duration) {
134
+ this.output({
135
+ type: 'tool',
136
+ subtype: 'result',
137
+ timestamp: Date.now(),
138
+ data: {
139
+ tool: toolName,
140
+ result,
141
+ duration,
142
+ status: 'completed'
143
+ }
144
+ });
145
+ }
146
+ /**
147
+ * Format and output tool error.
148
+ */
149
+ outputToolError(toolName, error) {
150
+ this.output({
151
+ type: 'tool',
152
+ subtype: 'error',
153
+ timestamp: Date.now(),
154
+ data: {
155
+ tool: toolName,
156
+ error,
157
+ status: 'error'
158
+ }
159
+ });
160
+ }
161
+ /**
162
+ * Format and output thinking content.
163
+ */
164
+ outputThinking(reasoningContent, displayMode = 'compact') {
165
+ const maxLength = displayMode === 'full' ? undefined : 500;
166
+ const truncated = maxLength && reasoningContent.length > maxLength;
167
+ const displayContent = truncated ? reasoningContent.substring(0, maxLength) + '... (truncated)' : reasoningContent;
168
+ this.output({
169
+ type: 'thinking',
170
+ subtype: displayMode,
171
+ timestamp: Date.now(),
172
+ data: {
173
+ content: displayContent,
174
+ originalLength: reasoningContent.length,
175
+ truncated,
176
+ displayMode
177
+ }
178
+ });
179
+ }
180
+ /**
181
+ * Format and output system message.
182
+ */
183
+ outputSystem(subtype, data) {
184
+ this.output({
185
+ type: 'system',
186
+ subtype,
187
+ timestamp: Date.now(),
188
+ data
189
+ });
190
+ }
191
+ /**
192
+ * Format and output MCP loading status.
193
+ */
194
+ outputMCPLoading(count) {
195
+ this.output({
196
+ type: 'system',
197
+ subtype: 'mcp_loading',
198
+ timestamp: Date.now(),
199
+ data: { count }
200
+ });
201
+ }
202
+ /**
203
+ * Format and output MCP server registering status.
204
+ */
205
+ outputMCPRegistering(name, transport) {
206
+ this.output({
207
+ type: 'system',
208
+ subtype: 'mcp_registering',
209
+ timestamp: Date.now(),
210
+ data: { name, transport }
211
+ });
212
+ }
213
+ /**
214
+ * Format and output MCP connecting status.
215
+ */
216
+ outputMCPConnecting(count) {
217
+ this.output({
218
+ type: 'system',
219
+ subtype: 'mcp_connecting',
220
+ timestamp: Date.now(),
221
+ data: { count }
222
+ });
223
+ }
224
+ /**
225
+ * Format and output MCP connected result.
226
+ */
227
+ outputMCPConnected(total, connected, toolsAvailable) {
228
+ this.output({
229
+ type: 'system',
230
+ subtype: 'mcp_connected',
231
+ timestamp: Date.now(),
232
+ data: { total, connected, toolsAvailable }
233
+ });
234
+ }
235
+ /**
236
+ * Format and output MCP connection failed warning.
237
+ */
238
+ outputMCPConnectionFailed(message) {
239
+ this.output({
240
+ type: 'system',
241
+ subtype: 'mcp_connection_failed',
242
+ timestamp: Date.now(),
243
+ data: { message }
244
+ });
245
+ }
246
+ /**
247
+ * Format and output error message.
248
+ */
249
+ outputError(message, context) {
250
+ this.output({
251
+ type: 'error',
252
+ subtype: 'general',
253
+ timestamp: Date.now(),
254
+ data: {
255
+ message,
256
+ ...context
257
+ }
258
+ });
259
+ }
260
+ /**
261
+ * Format and output warning message.
262
+ */
263
+ outputWarning(message) {
264
+ this.output({
265
+ type: 'system',
266
+ subtype: 'warning',
267
+ timestamp: Date.now(),
268
+ data: { message }
269
+ });
270
+ }
271
+ /**
272
+ * Format and output success message.
273
+ */
274
+ outputSuccess(message) {
275
+ this.output({
276
+ type: 'system',
277
+ subtype: 'success',
278
+ timestamp: Date.now(),
279
+ data: { message }
280
+ });
281
+ }
282
+ /**
283
+ * Format and output info message.
284
+ */
285
+ outputInfo(message) {
286
+ this.output({
287
+ type: 'system',
288
+ subtype: 'info',
289
+ timestamp: Date.now(),
290
+ data: { message }
291
+ });
292
+ }
293
+ /**
294
+ * Format and output context compression notification.
295
+ */
296
+ outputContextCompression(reason, originalSize, compressedSize, reductionPercent) {
297
+ this.output({
298
+ type: 'system',
299
+ subtype: 'context_compression',
300
+ timestamp: Date.now(),
301
+ data: {
302
+ reason,
303
+ originalSize,
304
+ compressedSize,
305
+ reductionPercent
306
+ }
307
+ });
308
+ }
309
+ /**
310
+ * Format and output context compression triggered.
311
+ */
312
+ outputContextCompressionTriggered(reason) {
313
+ this.output({
314
+ type: 'system',
315
+ subtype: 'context_compression_triggered',
316
+ timestamp: Date.now(),
317
+ data: { reason }
318
+ });
319
+ }
320
+ /**
321
+ * Format and output context compression result.
322
+ */
323
+ outputContextCompressionResult(originalSize, compressedSize, reductionPercent, originalMessageCount, compressedMessageCount) {
324
+ this.output({
325
+ type: 'system',
326
+ subtype: 'context_compression_result',
327
+ timestamp: Date.now(),
328
+ data: {
329
+ originalSize,
330
+ compressedSize,
331
+ reductionPercent,
332
+ originalMessageCount,
333
+ compressedMessageCount
334
+ }
335
+ });
336
+ }
337
+ /**
338
+ * Format and output context compression summary.
339
+ */
340
+ outputContextCompressionSummary(summary, preview, isTruncated, totalLength) {
341
+ this.output({
342
+ type: 'system',
343
+ subtype: 'context_compression_summary',
344
+ timestamp: Date.now(),
345
+ data: {
346
+ summary,
347
+ preview,
348
+ isTruncated,
349
+ totalLength
350
+ }
351
+ });
352
+ }
353
+ /**
354
+ * Format and output session result.
355
+ */
356
+ outputResult(duration, numTurns, status) {
357
+ this.output({
358
+ type: 'result',
359
+ timestamp: Date.now(),
360
+ data: {
361
+ duration_ms: duration,
362
+ num_turns: numTurns,
363
+ status
364
+ }
365
+ });
366
+ }
367
+ /**
368
+ * Format and output progress/spinner.
369
+ */
370
+ outputProgress(text, status) {
371
+ this.output({
372
+ type: 'system',
373
+ subtype: 'progress',
374
+ timestamp: Date.now(),
375
+ data: {
376
+ text,
377
+ status
378
+ }
379
+ });
380
+ }
381
+ /**
382
+ * Format and output agent switch.
383
+ */
384
+ outputAgentSwitch(agentName, agentDescription) {
385
+ this.output({
386
+ type: 'system',
387
+ subtype: 'agent_switch',
388
+ timestamp: Date.now(),
389
+ data: {
390
+ agent: agentName,
391
+ description: agentDescription
392
+ }
393
+ });
394
+ }
395
+ /**
396
+ * Format and output command execution.
397
+ */
398
+ outputCommand(command, status) {
399
+ this.output({
400
+ type: 'tool',
401
+ subtype: 'command',
402
+ timestamp: Date.now(),
403
+ data: {
404
+ command,
405
+ status
406
+ }
407
+ });
408
+ }
409
+ // ==================== SDK Approval Request ====================
410
+ /**
411
+ * Format and output approval request (for SDK mode).
412
+ * This is sent when a potentially risky operation needs user confirmation.
413
+ */
414
+ outputApprovalRequest(params) {
415
+ this.output({
416
+ type: 'system',
417
+ subtype: 'approval_request',
418
+ timestamp: Date.now(),
419
+ data: {
420
+ requestId: params.requestId,
421
+ toolName: params.toolName,
422
+ params: params.params,
423
+ riskLevel: params.riskLevel,
424
+ description: params.description,
425
+ aiAnalysis: params.aiAnalysis,
426
+ approved: false // Default to not approved, client must respond
427
+ }
428
+ });
429
+ }
430
+ /**
431
+ * Format and output approval response received (for SDK mode logging).
432
+ */
433
+ outputApprovalResponse(requestId, approved) {
434
+ this.output({
435
+ type: 'system',
436
+ subtype: 'approval_response',
437
+ timestamp: Date.now(),
438
+ data: {
439
+ requestId,
440
+ approved
441
+ }
442
+ });
443
+ }
444
+ // ==================== SDK Question Request ====================
445
+ /**
446
+ * Format and output question request (for SDK mode).
447
+ * This is sent when the agent needs to ask the user questions.
448
+ */
449
+ outputQuestionRequest(params) {
450
+ this.output({
451
+ type: 'system',
452
+ subtype: 'question_request',
453
+ timestamp: Date.now(),
454
+ data: {
455
+ requestId: params.requestId,
456
+ questions: params.questions
457
+ }
458
+ });
459
+ }
460
+ /**
461
+ * Format and output question response received (for SDK mode logging).
462
+ */
463
+ outputQuestionResponse(requestId, answers) {
464
+ this.output({
465
+ type: 'system',
466
+ subtype: 'question_response',
467
+ timestamp: Date.now(),
468
+ data: {
469
+ requestId,
470
+ answers
471
+ }
472
+ });
473
+ }
474
+ // ==================== GUI Agent Output Methods ====================
475
+ /**
476
+ * Format and output GUI agent start.
477
+ */
478
+ outputGUIAgentStart(description, mode) {
479
+ this.output({
480
+ type: 'system',
481
+ subtype: 'gui_agent_start',
482
+ timestamp: Date.now(),
483
+ data: {
484
+ description,
485
+ mode
486
+ }
487
+ });
488
+ }
489
+ /**
490
+ * Format and output GUI agent status update.
491
+ */
492
+ outputGUIAgentStatus(status, iteration, error) {
493
+ this.output({
494
+ type: 'system',
495
+ subtype: `gui_status_${status}`,
496
+ timestamp: Date.now(),
497
+ data: {
498
+ status,
499
+ iteration,
500
+ error
501
+ }
502
+ });
503
+ }
504
+ /**
505
+ * Format and output GUI agent action/step.
506
+ */
507
+ outputGUIAgentAction(iteration, actionType, cost) {
508
+ this.output({
509
+ type: 'output',
510
+ subtype: 'gui_action',
511
+ timestamp: Date.now(),
512
+ data: {
513
+ iteration,
514
+ actionType,
515
+ cost
516
+ }
517
+ });
518
+ }
519
+ /**
520
+ * Format and output GUI agent conversation (screenshot).
521
+ */
522
+ outputGUIConversation(data) {
523
+ this.output({
524
+ type: 'output',
525
+ subtype: 'gui_conversation',
526
+ timestamp: Date.now(),
527
+ data
528
+ });
529
+ }
530
+ /**
531
+ * Format and output GUI agent completion.
532
+ */
533
+ outputGUIAgentComplete(description, iterations) {
534
+ this.output({
535
+ type: 'system',
536
+ subtype: 'gui_complete',
537
+ timestamp: Date.now(),
538
+ data: {
539
+ description,
540
+ iterations,
541
+ message: `GUI task completed in ${iterations} iterations`
542
+ }
543
+ });
544
+ }
545
+ /**
546
+ * Format and output GUI agent cancellation.
547
+ */
548
+ outputGUIAgentCancelled(description) {
549
+ this.output({
550
+ type: 'system',
551
+ subtype: 'gui_cancelled',
552
+ timestamp: Date.now(),
553
+ data: {
554
+ description,
555
+ message: 'GUI task cancelled by user'
556
+ }
557
+ });
558
+ }
559
+ /**
560
+ * Format and output GUI agent error.
561
+ */
562
+ outputGUIAgentError(description, error) {
563
+ this.output({
564
+ type: 'error',
565
+ subtype: 'gui_error',
566
+ timestamp: Date.now(),
567
+ data: {
568
+ description,
569
+ error
570
+ }
571
+ });
572
+ }
573
+ /**
574
+ * Create a GUI Agent output handler that maps GUIAgentOutput to SDK format.
575
+ * This handler can be passed directly to GUIAgent.
576
+ */
577
+ createGUIAgentHandler() {
578
+ return (output) => {
579
+ switch (output.type) {
580
+ case 'action':
581
+ this.output({
582
+ type: 'system',
583
+ subtype: 'gui_action',
584
+ timestamp: output.timestamp,
585
+ data: output.data
586
+ });
587
+ break;
588
+ case 'status':
589
+ this.outputGUIAgentStatus(output.data.status, output.data.iteration, output.data.error);
590
+ break;
591
+ case 'conversation':
592
+ this.outputGUIConversation({
593
+ iteration: output.data.iteration,
594
+ from: output.data.from,
595
+ actionType: output.data.actionType,
596
+ indentLevel: output.data.indentLevel,
597
+ timing: output.data.timing
598
+ });
599
+ break;
600
+ case 'complete':
601
+ this.output({
602
+ type: 'system',
603
+ subtype: 'gui_complete',
604
+ timestamp: output.timestamp,
605
+ data: output.data
606
+ });
607
+ break;
608
+ case 'error':
609
+ this.output({
610
+ type: 'error',
611
+ subtype: 'gui_error',
612
+ timestamp: output.timestamp,
613
+ data: output.data
614
+ });
615
+ break;
616
+ case 'screenshot':
617
+ this.output({
618
+ type: 'output',
619
+ subtype: 'gui_screenshot',
620
+ timestamp: output.timestamp,
621
+ data: output.data
622
+ });
623
+ break;
624
+ }
625
+ };
626
+ }
627
+ /**
628
+ * Output a raw message.
629
+ */
630
+ output(message) {
631
+ this.outputHandler(message);
632
+ }
633
+ /**
634
+ * Get mode configuration.
635
+ */
636
+ getModeConfig(mode) {
637
+ const modeConfigs = {
638
+ yolo: {
639
+ color: 'red',
640
+ icon: '🔥',
641
+ description: 'Execute commands without confirmation'
642
+ },
643
+ accept_edits: {
644
+ color: 'yellow',
645
+ icon: '✅',
646
+ description: 'Accept all edits automatically'
647
+ },
648
+ plan: {
649
+ color: 'blue',
650
+ icon: '🧠',
651
+ description: 'Plan before executing'
652
+ },
653
+ default: {
654
+ color: 'green',
655
+ icon: '⚡',
656
+ description: 'Safe execution with confirmations'
657
+ },
658
+ smart: {
659
+ color: 'cyan',
660
+ icon: '✨',
661
+ description: 'Smart approval with intelligent security checks'
662
+ }
663
+ };
664
+ return modeConfigs[mode.toLowerCase()] || modeConfigs.default;
665
+ }
666
+ /**
667
+ * Convert a SessionInput to SDK format.
668
+ */
669
+ static formatSessionInput(input) {
670
+ return {
671
+ type: 'input',
672
+ timestamp: input.timestamp,
673
+ data: {
674
+ inputType: input.type,
675
+ content: input.content,
676
+ rawInput: input.rawInput,
677
+ filePath: input.filePath
678
+ }
679
+ };
680
+ }
681
+ /**
682
+ * Convert a SessionOutput to SDK format.
683
+ */
684
+ static formatSessionOutput(output) {
685
+ return {
686
+ type: 'output',
687
+ timestamp: output.timestamp,
688
+ data: {
689
+ role: output.role,
690
+ content: output.content,
691
+ toolName: output.toolName,
692
+ toolParams: output.toolParams,
693
+ toolResult: output.toolResult,
694
+ duration: output.duration,
695
+ reasoning_content: output.reasoning_content,
696
+ tool_calls: output.tool_calls
697
+ }
698
+ };
699
+ }
700
+ }
701
+ //# sourceMappingURL=sdk-output-adapter.js.map