@umsai/ums-code 0.1.4-v2 → 0.3.0-v2

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 (382) hide show
  1. package/dist/package.json +11 -3
  2. package/dist/src/config/config.d.ts +6 -0
  3. package/dist/src/config/config.js +102 -11
  4. package/dist/src/config/config.js.map +1 -1
  5. package/dist/src/config/settings.d.ts +5 -0
  6. package/dist/src/config/settings.js +15 -1
  7. package/dist/src/config/settings.js.map +1 -1
  8. package/dist/src/config/settingsSchema.d.ts +75 -17
  9. package/dist/src/config/settingsSchema.js +57 -17
  10. package/dist/src/config/settingsSchema.js.map +1 -1
  11. package/dist/src/config/webSearch.d.ts +35 -0
  12. package/dist/src/config/webSearch.js +87 -0
  13. package/dist/src/config/webSearch.js.map +1 -0
  14. package/dist/src/core/auth.d.ts +1 -1
  15. package/dist/src/core/auth.js +19 -3
  16. package/dist/src/core/auth.js.map +1 -1
  17. package/dist/src/core/initializer.js +13 -2
  18. package/dist/src/core/initializer.js.map +1 -1
  19. package/dist/src/core/theme.js +4 -1
  20. package/dist/src/core/theme.js.map +1 -1
  21. package/dist/src/gemini.d.ts +1 -1
  22. package/dist/src/gemini.js +53 -44
  23. package/dist/src/gemini.js.map +1 -1
  24. package/dist/src/gemini.test.js +117 -0
  25. package/dist/src/gemini.test.js.map +1 -1
  26. package/dist/src/generated/git-commit.d.ts +2 -2
  27. package/dist/src/generated/git-commit.js +2 -2
  28. package/dist/src/i18n/index.d.ts +18 -0
  29. package/dist/src/i18n/index.js +184 -0
  30. package/dist/src/i18n/index.js.map +1 -0
  31. package/dist/src/i18n/locales/en.js +1129 -0
  32. package/dist/src/i18n/locales/zh.js +1052 -0
  33. package/dist/src/nonInteractive/control/ControlContext.d.ts +63 -0
  34. package/dist/src/nonInteractive/control/ControlContext.js +31 -0
  35. package/dist/src/nonInteractive/control/ControlContext.js.map +1 -0
  36. package/dist/src/nonInteractive/control/ControlDispatcher.d.ts +86 -0
  37. package/dist/src/nonInteractive/control/ControlDispatcher.js +238 -0
  38. package/dist/src/nonInteractive/control/ControlDispatcher.js.map +1 -0
  39. package/dist/src/nonInteractive/control/ControlDispatcher.test.d.ts +6 -0
  40. package/dist/src/nonInteractive/control/ControlDispatcher.test.js +549 -0
  41. package/dist/src/nonInteractive/control/ControlDispatcher.test.js.map +1 -0
  42. package/dist/src/nonInteractive/control/ControlService.d.ts +78 -0
  43. package/dist/src/nonInteractive/control/ControlService.js +154 -0
  44. package/dist/src/nonInteractive/control/ControlService.js.map +1 -0
  45. package/dist/src/nonInteractive/control/controllers/baseController.d.ts +50 -0
  46. package/dist/src/nonInteractive/control/controllers/baseController.js +102 -0
  47. package/dist/src/nonInteractive/control/controllers/baseController.js.map +1 -0
  48. package/dist/src/nonInteractive/control/controllers/hookController.d.ts +25 -0
  49. package/dist/src/nonInteractive/control/controllers/hookController.js +42 -0
  50. package/dist/src/nonInteractive/control/controllers/hookController.js.map +1 -0
  51. package/dist/src/nonInteractive/control/controllers/mcpController.d.ts +42 -0
  52. package/dist/src/nonInteractive/control/controllers/mcpController.js +205 -0
  53. package/dist/src/nonInteractive/control/controllers/mcpController.js.map +1 -0
  54. package/dist/src/nonInteractive/control/controllers/permissionController.d.ts +78 -0
  55. package/dist/src/nonInteractive/control/controllers/permissionController.js +358 -0
  56. package/dist/src/nonInteractive/control/controllers/permissionController.js.map +1 -0
  57. package/dist/src/nonInteractive/control/controllers/systemController.d.ts +56 -0
  58. package/dist/src/nonInteractive/control/controllers/systemController.js +166 -0
  59. package/dist/src/nonInteractive/control/controllers/systemController.js.map +1 -0
  60. package/dist/src/nonInteractive/control/types/serviceAPIs.d.ts +120 -0
  61. package/dist/src/nonInteractive/control/types/serviceAPIs.js +7 -0
  62. package/dist/src/nonInteractive/control/types/serviceAPIs.js.map +1 -0
  63. package/dist/src/nonInteractive/io/BaseJsonOutputAdapter.d.ts +446 -0
  64. package/dist/src/nonInteractive/io/BaseJsonOutputAdapter.js +891 -0
  65. package/dist/src/nonInteractive/io/BaseJsonOutputAdapter.js.map +1 -0
  66. package/dist/src/nonInteractive/io/BaseJsonOutputAdapter.test.d.ts +6 -0
  67. package/dist/src/nonInteractive/io/BaseJsonOutputAdapter.test.js +1197 -0
  68. package/dist/src/nonInteractive/io/BaseJsonOutputAdapter.test.js.map +1 -0
  69. package/dist/src/nonInteractive/io/JsonOutputAdapter.d.ts +29 -0
  70. package/dist/src/nonInteractive/io/JsonOutputAdapter.js +56 -0
  71. package/dist/src/nonInteractive/io/JsonOutputAdapter.js.map +1 -0
  72. package/dist/src/nonInteractive/io/JsonOutputAdapter.test.d.ts +6 -0
  73. package/dist/src/nonInteractive/io/JsonOutputAdapter.test.js +624 -0
  74. package/dist/src/nonInteractive/io/JsonOutputAdapter.test.js.map +1 -0
  75. package/dist/src/nonInteractive/io/StreamJsonInputReader.d.ts +16 -0
  76. package/dist/src/nonInteractive/io/StreamJsonInputReader.js +54 -0
  77. package/dist/src/nonInteractive/io/StreamJsonInputReader.js.map +1 -0
  78. package/dist/src/nonInteractive/io/StreamJsonInputReader.test.d.ts +6 -0
  79. package/dist/src/nonInteractive/io/StreamJsonInputReader.test.js +178 -0
  80. package/dist/src/nonInteractive/io/StreamJsonInputReader.test.js.map +1 -0
  81. package/dist/src/nonInteractive/io/StreamJsonOutputAdapter.d.ts +69 -0
  82. package/dist/src/nonInteractive/io/StreamJsonOutputAdapter.js +185 -0
  83. package/dist/src/nonInteractive/io/StreamJsonOutputAdapter.js.map +1 -0
  84. package/dist/src/nonInteractive/io/StreamJsonOutputAdapter.test.d.ts +6 -0
  85. package/dist/src/nonInteractive/io/StreamJsonOutputAdapter.test.js +808 -0
  86. package/dist/src/nonInteractive/io/StreamJsonOutputAdapter.test.js.map +1 -0
  87. package/dist/src/nonInteractive/session.d.ts +23 -0
  88. package/dist/src/nonInteractive/session.js +549 -0
  89. package/dist/src/nonInteractive/session.js.map +1 -0
  90. package/dist/src/nonInteractive/session.test.d.ts +6 -0
  91. package/dist/src/nonInteractive/session.test.js +407 -0
  92. package/dist/src/nonInteractive/session.test.js.map +1 -0
  93. package/dist/src/nonInteractive/types.d.ts +344 -0
  94. package/dist/src/nonInteractive/types.js +78 -0
  95. package/dist/src/nonInteractive/types.js.map +1 -0
  96. package/dist/src/nonInteractiveCli.d.ts +21 -1
  97. package/dist/src/nonInteractiveCli.js +204 -57
  98. package/dist/src/nonInteractiveCli.js.map +1 -1
  99. package/dist/src/nonInteractiveCliCommands.d.ts +19 -1
  100. package/dist/src/nonInteractiveCliCommands.js +69 -4
  101. package/dist/src/nonInteractiveCliCommands.js.map +1 -1
  102. package/dist/src/services/BuiltinCommandLoader.js +2 -0
  103. package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
  104. package/dist/src/services/FileCommandLoader.js +4 -1
  105. package/dist/src/services/FileCommandLoader.js.map +1 -1
  106. package/dist/src/ui/AppContainer.js +41 -38
  107. package/dist/src/ui/AppContainer.js.map +1 -1
  108. package/dist/src/ui/auth/AuthDialog.d.ts +1 -13
  109. package/dist/src/ui/auth/AuthDialog.js +41 -111
  110. package/dist/src/ui/auth/AuthDialog.js.map +1 -1
  111. package/dist/src/ui/auth/AuthDialog.test.js +49 -19
  112. package/dist/src/ui/auth/AuthDialog.test.js.map +1 -1
  113. package/dist/src/ui/auth/AuthInProgress.js +2 -1
  114. package/dist/src/ui/auth/AuthInProgress.js.map +1 -1
  115. package/dist/src/ui/auth/useAuth.d.ts +9 -8
  116. package/dist/src/ui/auth/useAuth.js +135 -63
  117. package/dist/src/ui/auth/useAuth.js.map +1 -1
  118. package/dist/src/ui/commands/aboutCommand.js +7 -31
  119. package/dist/src/ui/commands/aboutCommand.js.map +1 -1
  120. package/dist/src/ui/commands/agentsCommand.js +10 -3
  121. package/dist/src/ui/commands/agentsCommand.js.map +1 -1
  122. package/dist/src/ui/commands/approvalModeCommand.js +8 -329
  123. package/dist/src/ui/commands/approvalModeCommand.js.map +1 -1
  124. package/dist/src/ui/commands/approvalModeCommand.test.js +19 -263
  125. package/dist/src/ui/commands/approvalModeCommand.test.js.map +1 -1
  126. package/dist/src/ui/commands/authCommand.js +4 -1
  127. package/dist/src/ui/commands/authCommand.js.map +1 -1
  128. package/dist/src/ui/commands/bugCommand.js +13 -47
  129. package/dist/src/ui/commands/bugCommand.js.map +1 -1
  130. package/dist/src/ui/commands/chatCommand.js +51 -25
  131. package/dist/src/ui/commands/chatCommand.js.map +1 -1
  132. package/dist/src/ui/commands/clearCommand.js +6 -3
  133. package/dist/src/ui/commands/clearCommand.js.map +1 -1
  134. package/dist/src/ui/commands/compressCommand.js +9 -4
  135. package/dist/src/ui/commands/compressCommand.js.map +1 -1
  136. package/dist/src/ui/commands/copyCommand.js +4 -1
  137. package/dist/src/ui/commands/copyCommand.js.map +1 -1
  138. package/dist/src/ui/commands/directoryCommand.js +30 -12
  139. package/dist/src/ui/commands/directoryCommand.js.map +1 -1
  140. package/dist/src/ui/commands/docsCommand.js +9 -3
  141. package/dist/src/ui/commands/docsCommand.js.map +1 -1
  142. package/dist/src/ui/commands/editorCommand.js +4 -1
  143. package/dist/src/ui/commands/editorCommand.js.map +1 -1
  144. package/dist/src/ui/commands/extensionsCommand.js +10 -3
  145. package/dist/src/ui/commands/extensionsCommand.js.map +1 -1
  146. package/dist/src/ui/commands/helpCommand.js +4 -1
  147. package/dist/src/ui/commands/helpCommand.js.map +1 -1
  148. package/dist/src/ui/commands/ideCommand.js +23 -7
  149. package/dist/src/ui/commands/ideCommand.js.map +1 -1
  150. package/dist/src/ui/commands/initCommand.js +5 -3
  151. package/dist/src/ui/commands/initCommand.js.map +1 -1
  152. package/dist/src/ui/commands/languageCommand.d.ts +7 -0
  153. package/dist/src/ui/commands/languageCommand.js +386 -0
  154. package/dist/src/ui/commands/languageCommand.js.map +1 -0
  155. package/dist/src/ui/commands/mcpCommand.js +38 -18
  156. package/dist/src/ui/commands/mcpCommand.js.map +1 -1
  157. package/dist/src/ui/commands/memoryCommand.js +54 -25
  158. package/dist/src/ui/commands/memoryCommand.js.map +1 -1
  159. package/dist/src/ui/commands/modelCommand.js +9 -4
  160. package/dist/src/ui/commands/modelCommand.js.map +1 -1
  161. package/dist/src/ui/commands/permissionsCommand.js +4 -1
  162. package/dist/src/ui/commands/permissionsCommand.js.map +1 -1
  163. package/dist/src/ui/commands/quitCommand.js +7 -2
  164. package/dist/src/ui/commands/quitCommand.js.map +1 -1
  165. package/dist/src/ui/commands/settingsCommand.js +4 -1
  166. package/dist/src/ui/commands/settingsCommand.js.map +1 -1
  167. package/dist/src/ui/commands/setupGithubCommand.js +4 -1
  168. package/dist/src/ui/commands/setupGithubCommand.js.map +1 -1
  169. package/dist/src/ui/commands/statsCommand.js +11 -4
  170. package/dist/src/ui/commands/statsCommand.js.map +1 -1
  171. package/dist/src/ui/commands/summaryCommand.js +15 -8
  172. package/dist/src/ui/commands/summaryCommand.js.map +1 -1
  173. package/dist/src/ui/commands/terminalSetupCommand.js +9 -3
  174. package/dist/src/ui/commands/terminalSetupCommand.js.map +1 -1
  175. package/dist/src/ui/commands/themeCommand.js +4 -1
  176. package/dist/src/ui/commands/themeCommand.js.map +1 -1
  177. package/dist/src/ui/commands/toolsCommand.js +5 -2
  178. package/dist/src/ui/commands/toolsCommand.js.map +1 -1
  179. package/dist/src/ui/commands/types.d.ts +1 -1
  180. package/dist/src/ui/commands/types.js.map +1 -1
  181. package/dist/src/ui/commands/vimCommand.js +4 -1
  182. package/dist/src/ui/commands/vimCommand.js.map +1 -1
  183. package/dist/src/ui/components/AboutBox.d.ts +2 -9
  184. package/dist/src/ui/components/AboutBox.js +6 -2
  185. package/dist/src/ui/components/AboutBox.js.map +1 -1
  186. package/dist/src/ui/components/ApprovalModeDialog.d.ts +21 -0
  187. package/dist/src/ui/components/ApprovalModeDialog.js +68 -0
  188. package/dist/src/ui/components/ApprovalModeDialog.js.map +1 -0
  189. package/dist/src/ui/components/AutoAcceptIndicator.js +7 -6
  190. package/dist/src/ui/components/AutoAcceptIndicator.js.map +1 -1
  191. package/dist/src/ui/components/Composer.js +4 -3
  192. package/dist/src/ui/components/Composer.js.map +1 -1
  193. package/dist/src/ui/components/ConfigInitDisplay.js +7 -3
  194. package/dist/src/ui/components/ConfigInitDisplay.js.map +1 -1
  195. package/dist/src/ui/components/ContextSummaryDisplay.js +33 -9
  196. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
  197. package/dist/src/ui/components/DialogManager.js +60 -13
  198. package/dist/src/ui/components/DialogManager.js.map +1 -1
  199. package/dist/src/ui/components/EditorSettingsDialog.js +8 -3
  200. package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -1
  201. package/dist/src/ui/components/Help.js +14 -4
  202. package/dist/src/ui/components/Help.js.map +1 -1
  203. package/dist/src/ui/components/HistoryItemDisplay.js +1 -1
  204. package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -1
  205. package/dist/src/ui/components/HistoryItemDisplay.test.js +17 -8
  206. package/dist/src/ui/components/HistoryItemDisplay.test.js.map +1 -1
  207. package/dist/src/ui/components/InputPrompt.js +10 -136
  208. package/dist/src/ui/components/InputPrompt.js.map +1 -1
  209. package/dist/src/ui/components/LoadingIndicator.js +6 -1
  210. package/dist/src/ui/components/LoadingIndicator.js.map +1 -1
  211. package/dist/src/ui/components/ModelDialog.js +2 -1
  212. package/dist/src/ui/components/ModelDialog.js.map +1 -1
  213. package/dist/src/ui/components/ModelStatsDisplay.js +6 -5
  214. package/dist/src/ui/components/ModelStatsDisplay.js.map +1 -1
  215. package/dist/src/ui/components/OpenAIKeyPrompt.d.ts +19 -1
  216. package/dist/src/ui/components/OpenAIKeyPrompt.js +38 -6
  217. package/dist/src/ui/components/OpenAIKeyPrompt.js.map +1 -1
  218. package/dist/src/ui/components/ProQuotaDialog.js +5 -4
  219. package/dist/src/ui/components/ProQuotaDialog.js.map +1 -1
  220. package/dist/src/ui/components/QuitConfirmationDialog.js +6 -5
  221. package/dist/src/ui/components/QuitConfirmationDialog.js.map +1 -1
  222. package/dist/src/ui/components/QwenOAuthProgress.d.ts +2 -2
  223. package/dist/src/ui/components/QwenOAuthProgress.js +14 -7
  224. package/dist/src/ui/components/QwenOAuthProgress.js.map +1 -1
  225. package/dist/src/ui/components/QwenOAuthProgress.test.js +1 -0
  226. package/dist/src/ui/components/QwenOAuthProgress.test.js.map +1 -1
  227. package/dist/src/ui/components/SessionSummaryDisplay.js +2 -1
  228. package/dist/src/ui/components/SessionSummaryDisplay.js.map +1 -1
  229. package/dist/src/ui/components/SettingsDialog.d.ts +3 -1
  230. package/dist/src/ui/components/SettingsDialog.js +35 -12
  231. package/dist/src/ui/components/SettingsDialog.js.map +1 -1
  232. package/dist/src/ui/components/SettingsDialog.test.js +5 -4
  233. package/dist/src/ui/components/SettingsDialog.test.js.map +1 -1
  234. package/dist/src/ui/components/ShellConfirmationDialog.js +5 -4
  235. package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -1
  236. package/dist/src/ui/components/StatsDisplay.js +5 -4
  237. package/dist/src/ui/components/StatsDisplay.js.map +1 -1
  238. package/dist/src/ui/components/ThemeDialog.js +5 -2
  239. package/dist/src/ui/components/ThemeDialog.js.map +1 -1
  240. package/dist/src/ui/components/ToolStatsDisplay.js +3 -2
  241. package/dist/src/ui/components/ToolStatsDisplay.js.map +1 -1
  242. package/dist/src/ui/components/WelcomeBackDialog.js +13 -4
  243. package/dist/src/ui/components/WelcomeBackDialog.js.map +1 -1
  244. package/dist/src/ui/components/messages/CompressionMessage.js +10 -6
  245. package/dist/src/ui/components/messages/CompressionMessage.js.map +1 -1
  246. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +40 -29
  247. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
  248. package/dist/src/ui/components/shared/BaseSelectionList.test.js +1 -1
  249. package/dist/src/ui/components/shared/BaseSelectionList.test.js.map +1 -1
  250. package/dist/src/ui/components/shared/ScopeSelector.js +3 -1
  251. package/dist/src/ui/components/shared/ScopeSelector.js.map +1 -1
  252. package/dist/src/ui/components/subagents/create/AgentCreationWizard.js +39 -26
  253. package/dist/src/ui/components/subagents/create/AgentCreationWizard.js.map +1 -1
  254. package/dist/src/ui/components/subagents/create/CreationSummary.js +20 -10
  255. package/dist/src/ui/components/subagents/create/CreationSummary.js.map +1 -1
  256. package/dist/src/ui/components/subagents/create/DescriptionInput.js +6 -3
  257. package/dist/src/ui/components/subagents/create/DescriptionInput.js.map +1 -1
  258. package/dist/src/ui/components/subagents/create/GenerationMethodSelector.js +7 -2
  259. package/dist/src/ui/components/subagents/create/GenerationMethodSelector.js.map +1 -1
  260. package/dist/src/ui/components/subagents/create/LocationSelector.js +7 -2
  261. package/dist/src/ui/components/subagents/create/LocationSelector.js.map +1 -1
  262. package/dist/src/ui/components/subagents/create/ToolSelector.js +8 -7
  263. package/dist/src/ui/components/subagents/create/ToolSelector.js.map +1 -1
  264. package/dist/src/ui/components/subagents/manage/ActionSelectionStep.js +29 -4
  265. package/dist/src/ui/components/subagents/manage/ActionSelectionStep.js.map +1 -1
  266. package/dist/src/ui/components/subagents/manage/AgentDeleteStep.js +6 -3
  267. package/dist/src/ui/components/subagents/manage/AgentDeleteStep.js.map +1 -1
  268. package/dist/src/ui/components/subagents/manage/AgentEditStep.js +14 -5
  269. package/dist/src/ui/components/subagents/manage/AgentEditStep.js.map +1 -1
  270. package/dist/src/ui/components/subagents/manage/AgentSelectionStep.js +13 -6
  271. package/dist/src/ui/components/subagents/manage/AgentSelectionStep.js.map +1 -1
  272. package/dist/src/ui/components/subagents/manage/AgentViewerStep.js +3 -2
  273. package/dist/src/ui/components/subagents/manage/AgentViewerStep.js.map +1 -1
  274. package/dist/src/ui/components/subagents/manage/AgentsManagerDialog.js +14 -13
  275. package/dist/src/ui/components/subagents/manage/AgentsManagerDialog.js.map +1 -1
  276. package/dist/src/ui/components/subagents/runtime/AgentExecutionDisplay.js +8 -8
  277. package/dist/src/ui/components/views/McpStatus.js +28 -15
  278. package/dist/src/ui/components/views/McpStatus.js.map +1 -1
  279. package/dist/src/ui/components/views/ToolsList.js +2 -1
  280. package/dist/src/ui/components/views/ToolsList.js.map +1 -1
  281. package/dist/src/ui/contexts/UIActionsContext.d.ts +5 -4
  282. package/dist/src/ui/contexts/UIActionsContext.js +1 -0
  283. package/dist/src/ui/contexts/UIActionsContext.js.map +1 -1
  284. package/dist/src/ui/contexts/UIStateContext.d.ts +5 -7
  285. package/dist/src/ui/contexts/UIStateContext.js.map +1 -1
  286. package/dist/src/ui/editors/editorSettingsManager.js +1 -0
  287. package/dist/src/ui/editors/editorSettingsManager.js.map +1 -1
  288. package/dist/src/ui/hooks/atCommandProcessor.test.js +2 -0
  289. package/dist/src/ui/hooks/atCommandProcessor.test.js.map +1 -1
  290. package/dist/src/ui/hooks/slashCommandProcessor.d.ts +1 -0
  291. package/dist/src/ui/hooks/slashCommandProcessor.js +4 -7
  292. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
  293. package/dist/src/ui/hooks/useApprovalModeCommand.d.ts +14 -0
  294. package/dist/src/ui/hooks/useApprovalModeCommand.js +33 -0
  295. package/dist/src/ui/hooks/useApprovalModeCommand.js.map +1 -0
  296. package/dist/src/ui/hooks/useAttentionNotifications.d.ts +14 -0
  297. package/dist/src/ui/hooks/useAttentionNotifications.js +41 -0
  298. package/dist/src/ui/hooks/useAttentionNotifications.js.map +1 -0
  299. package/dist/src/ui/hooks/useAttentionNotifications.test.d.ts +6 -0
  300. package/dist/src/ui/hooks/useAttentionNotifications.test.js +113 -0
  301. package/dist/src/ui/hooks/useAttentionNotifications.test.js.map +1 -0
  302. package/dist/src/ui/hooks/useCommandCompletion.d.ts +1 -4
  303. package/dist/src/ui/hooks/useCommandCompletion.js +1 -23
  304. package/dist/src/ui/hooks/useCommandCompletion.js.map +1 -1
  305. package/dist/src/ui/hooks/useDialogClose.d.ts +6 -3
  306. package/dist/src/ui/hooks/useDialogClose.js +5 -0
  307. package/dist/src/ui/hooks/useDialogClose.js.map +1 -1
  308. package/dist/src/ui/hooks/useGitBranchName.js +6 -3
  309. package/dist/src/ui/hooks/useGitBranchName.js.map +1 -1
  310. package/dist/src/ui/hooks/useGitBranchName.test.js +39 -21
  311. package/dist/src/ui/hooks/useGitBranchName.test.js.map +1 -1
  312. package/dist/src/ui/hooks/useInitializationAuthError.d.ts +22 -0
  313. package/dist/src/ui/hooks/useInitializationAuthError.js +40 -0
  314. package/dist/src/ui/hooks/useInitializationAuthError.js.map +1 -0
  315. package/dist/src/ui/hooks/usePhraseCycler.js +6 -4
  316. package/dist/src/ui/hooks/usePhraseCycler.js.map +1 -1
  317. package/dist/src/ui/hooks/useQwenAuth.d.ts +7 -12
  318. package/dist/src/ui/hooks/useQwenAuth.js +4 -8
  319. package/dist/src/ui/hooks/useQwenAuth.js.map +1 -1
  320. package/dist/src/ui/hooks/useQwenAuth.test.js +72 -98
  321. package/dist/src/ui/hooks/useQwenAuth.test.js.map +1 -1
  322. package/dist/src/ui/hooks/useThemeCommand.js +8 -3
  323. package/dist/src/ui/hooks/useThemeCommand.js.map +1 -1
  324. package/dist/src/ui/models/availableModels.js +7 -2
  325. package/dist/src/ui/models/availableModels.js.map +1 -1
  326. package/dist/src/ui/types.d.ts +32 -14
  327. package/dist/src/ui/types.js.map +1 -1
  328. package/dist/src/ui/utils/clipboardUtils.js +3 -3
  329. package/dist/src/ui/utils/clipboardUtils.js.map +1 -1
  330. package/dist/src/ui/utils/commandUtils.d.ts +16 -0
  331. package/dist/src/ui/utils/commandUtils.js +16 -1
  332. package/dist/src/ui/utils/commandUtils.js.map +1 -1
  333. package/dist/src/ui/utils/commandUtils.test.js +5 -2
  334. package/dist/src/ui/utils/commandUtils.test.js.map +1 -1
  335. package/dist/src/ui/utils/terminalSetup.js +45 -18
  336. package/dist/src/ui/utils/terminalSetup.js.map +1 -1
  337. package/dist/src/utils/attentionNotification.d.ts +20 -0
  338. package/dist/src/utils/attentionNotification.js +34 -0
  339. package/dist/src/utils/attentionNotification.js.map +1 -0
  340. package/dist/src/utils/attentionNotification.test.d.ts +6 -0
  341. package/dist/src/utils/attentionNotification.test.js +46 -0
  342. package/dist/src/utils/attentionNotification.test.js.map +1 -0
  343. package/dist/src/utils/dialogScopeUtils.d.ts +0 -4
  344. package/dist/src/utils/dialogScopeUtils.js +5 -2
  345. package/dist/src/utils/dialogScopeUtils.js.map +1 -1
  346. package/dist/src/utils/errors.d.ts +10 -2
  347. package/dist/src/utils/errors.js +14 -13
  348. package/dist/src/utils/errors.js.map +1 -1
  349. package/dist/src/utils/errors.test.js +91 -54
  350. package/dist/src/utils/errors.test.js.map +1 -1
  351. package/dist/src/utils/nonInteractiveHelpers.d.ts +88 -0
  352. package/dist/src/utils/nonInteractiveHelpers.js +470 -0
  353. package/dist/src/utils/nonInteractiveHelpers.js.map +1 -0
  354. package/dist/src/utils/nonInteractiveHelpers.test.d.ts +6 -0
  355. package/dist/src/utils/nonInteractiveHelpers.test.js +945 -0
  356. package/dist/src/utils/nonInteractiveHelpers.test.js.map +1 -0
  357. package/dist/src/utils/sandbox.js +1 -1
  358. package/dist/src/utils/sandbox.js.map +1 -1
  359. package/dist/src/utils/settingsUtils.js +7 -1
  360. package/dist/src/utils/settingsUtils.js.map +1 -1
  361. package/dist/src/utils/systemInfo.d.ts +66 -0
  362. package/dist/src/utils/systemInfo.js +125 -0
  363. package/dist/src/utils/systemInfo.js.map +1 -0
  364. package/dist/src/utils/systemInfo.test.d.ts +6 -0
  365. package/dist/src/utils/systemInfo.test.js +259 -0
  366. package/dist/src/utils/systemInfo.test.js.map +1 -0
  367. package/dist/src/utils/systemInfoFields.d.ts +22 -0
  368. package/dist/src/utils/systemInfoFields.js +96 -0
  369. package/dist/src/utils/systemInfoFields.js.map +1 -0
  370. package/dist/src/utils/userStartupWarnings.js +9 -4
  371. package/dist/src/utils/userStartupWarnings.js.map +1 -1
  372. package/dist/src/validateNonInterActiveAuth.js +27 -6
  373. package/dist/src/validateNonInterActiveAuth.js.map +1 -1
  374. package/dist/src/zed-integration/acp.js +1 -2
  375. package/dist/src/zed-integration/acp.js.map +1 -1
  376. package/dist/src/zed-integration/schema.d.ts +506 -264
  377. package/dist/src/zed-integration/schema.js +13 -0
  378. package/dist/src/zed-integration/schema.js.map +1 -1
  379. package/dist/src/zed-integration/zedIntegration.js +376 -32
  380. package/dist/src/zed-integration/zedIntegration.js.map +1 -1
  381. package/dist/tsconfig.tsbuildinfo +1 -1
  382. package/package.json +12 -4
@@ -0,0 +1,891 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Qwen Team
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { randomUUID } from 'node:crypto';
7
+ import { GeminiEventType, ToolErrorType } from '@umsai/ums-code-core';
8
+ import { functionResponsePartsToString } from '../../utils/nonInteractiveHelpers.js';
9
+ /**
10
+ * Abstract base class for JSON output adapters.
11
+ * Contains shared logic for message building, state management, and content block handling.
12
+ */
13
+ export class BaseJsonOutputAdapter {
14
+ config;
15
+ // Main agent message state
16
+ mainAgentMessageState;
17
+ // Subagent message states keyed by parentToolUseId
18
+ subagentMessageStates = new Map();
19
+ // Last assistant message for result generation
20
+ lastAssistantMessage = null;
21
+ // Track permission denials (execution denied tool calls)
22
+ permissionDenials = [];
23
+ constructor(config) {
24
+ this.config = config;
25
+ this.mainAgentMessageState = this.createMessageState();
26
+ }
27
+ /**
28
+ * Creates a new message state with default values.
29
+ */
30
+ createMessageState() {
31
+ return {
32
+ messageId: null,
33
+ blocks: [],
34
+ openBlocks: new Set(),
35
+ usage: this.createUsage(),
36
+ messageStarted: false,
37
+ finalized: false,
38
+ currentBlockType: null,
39
+ };
40
+ }
41
+ /**
42
+ * Gets or creates message state for a given context.
43
+ *
44
+ * @param parentToolUseId - null for main agent, string for subagent
45
+ * @returns MessageState for the context
46
+ */
47
+ getMessageState(parentToolUseId) {
48
+ if (parentToolUseId === null) {
49
+ return this.mainAgentMessageState;
50
+ }
51
+ let state = this.subagentMessageStates.get(parentToolUseId);
52
+ if (!state) {
53
+ state = this.createMessageState();
54
+ this.subagentMessageStates.set(parentToolUseId, state);
55
+ }
56
+ return state;
57
+ }
58
+ /**
59
+ * Creates a Usage object from metadata.
60
+ *
61
+ * @param metadata - Optional usage metadata from Gemini API
62
+ * @returns Usage object
63
+ */
64
+ createUsage(metadata) {
65
+ const usage = {
66
+ input_tokens: 0,
67
+ output_tokens: 0,
68
+ };
69
+ if (!metadata) {
70
+ return usage;
71
+ }
72
+ if (typeof metadata.promptTokenCount === 'number') {
73
+ usage.input_tokens = metadata.promptTokenCount;
74
+ }
75
+ if (typeof metadata.candidatesTokenCount === 'number') {
76
+ usage.output_tokens = metadata.candidatesTokenCount;
77
+ }
78
+ if (typeof metadata.cachedContentTokenCount === 'number') {
79
+ usage.cache_read_input_tokens = metadata.cachedContentTokenCount;
80
+ }
81
+ if (typeof metadata.totalTokenCount === 'number') {
82
+ usage.total_tokens = metadata.totalTokenCount;
83
+ }
84
+ return usage;
85
+ }
86
+ /**
87
+ * Builds a CLIAssistantMessage from the current message state.
88
+ *
89
+ * @param parentToolUseId - null for main agent, string for subagent
90
+ * @returns CLIAssistantMessage
91
+ */
92
+ buildMessage(parentToolUseId) {
93
+ const state = this.getMessageState(parentToolUseId);
94
+ if (!state.messageId) {
95
+ throw new Error('Message not started');
96
+ }
97
+ // Enforce constraint: assistant message must contain only a single type of ContentBlock
98
+ if (state.blocks.length > 0) {
99
+ const blockTypes = new Set(state.blocks.map((block) => block.type));
100
+ if (blockTypes.size > 1) {
101
+ throw new Error(`Assistant message must contain only one type of ContentBlock, found: ${Array.from(blockTypes).join(', ')}`);
102
+ }
103
+ }
104
+ // Determine stop_reason based on content block types
105
+ // If the message contains only tool_use blocks, set stop_reason to 'tool_use'
106
+ const stopReason = state.blocks.length > 0 &&
107
+ state.blocks.every((block) => block.type === 'tool_use')
108
+ ? 'tool_use'
109
+ : null;
110
+ return {
111
+ type: 'assistant',
112
+ uuid: state.messageId,
113
+ session_id: this.config.getSessionId(),
114
+ parent_tool_use_id: parentToolUseId,
115
+ message: {
116
+ id: state.messageId,
117
+ type: 'message',
118
+ role: 'assistant',
119
+ model: this.config.getModel(),
120
+ content: state.blocks,
121
+ stop_reason: stopReason,
122
+ usage: state.usage,
123
+ },
124
+ };
125
+ }
126
+ /**
127
+ * Finalizes pending blocks (text or thinking) by closing them.
128
+ *
129
+ * @param state - Message state to finalize blocks for
130
+ * @param parentToolUseId - null for main agent, string for subagent (optional, defaults to null)
131
+ */
132
+ finalizePendingBlocks(state, parentToolUseId) {
133
+ const actualParentToolUseId = parentToolUseId ?? null;
134
+ const lastBlock = state.blocks[state.blocks.length - 1];
135
+ if (!lastBlock) {
136
+ return;
137
+ }
138
+ if (lastBlock.type === 'text') {
139
+ const index = state.blocks.length - 1;
140
+ this.onBlockClosed(state, index, actualParentToolUseId);
141
+ this.closeBlock(state, index);
142
+ }
143
+ else if (lastBlock.type === 'thinking') {
144
+ const index = state.blocks.length - 1;
145
+ this.onBlockClosed(state, index, actualParentToolUseId);
146
+ this.closeBlock(state, index);
147
+ }
148
+ }
149
+ /**
150
+ * Opens a block (adds to openBlocks set).
151
+ *
152
+ * @param state - Message state
153
+ * @param index - Block index
154
+ * @param _block - Content block
155
+ */
156
+ openBlock(state, index, _block) {
157
+ state.openBlocks.add(index);
158
+ }
159
+ /**
160
+ * Closes a block (removes from openBlocks set).
161
+ *
162
+ * @param state - Message state
163
+ * @param index - Block index
164
+ */
165
+ closeBlock(state, index) {
166
+ if (!state.openBlocks.has(index)) {
167
+ return;
168
+ }
169
+ state.openBlocks.delete(index);
170
+ }
171
+ /**
172
+ * Guarantees that a single assistant message aggregates only one
173
+ * content block category (text, thinking, or tool use). When a new
174
+ * block type is requested, the current message is finalized and a fresh
175
+ * assistant message is started to honour the single-type constraint.
176
+ *
177
+ * @param state - Message state
178
+ * @param targetType - Target block type
179
+ * @param parentToolUseId - null for main agent, string for subagent
180
+ */
181
+ ensureBlockTypeConsistency(state, targetType, parentToolUseId) {
182
+ if (state.currentBlockType === targetType) {
183
+ return;
184
+ }
185
+ if (state.currentBlockType === null) {
186
+ state.currentBlockType = targetType;
187
+ return;
188
+ }
189
+ // Finalize current message and start new one
190
+ this.finalizeAssistantMessageInternal(state, parentToolUseId);
191
+ this.startAssistantMessageInternal(state);
192
+ state.currentBlockType = targetType;
193
+ }
194
+ /**
195
+ * Starts a new assistant message, resetting state.
196
+ *
197
+ * @param state - Message state to reset
198
+ */
199
+ startAssistantMessageInternal(state) {
200
+ state.messageId = randomUUID();
201
+ state.blocks = [];
202
+ state.openBlocks = new Set();
203
+ state.usage = this.createUsage();
204
+ state.messageStarted = false;
205
+ state.finalized = false;
206
+ state.currentBlockType = null;
207
+ }
208
+ /**
209
+ * Finalizes an assistant message.
210
+ *
211
+ * @param state - Message state to finalize
212
+ * @param parentToolUseId - null for main agent, string for subagent
213
+ * @returns CLIAssistantMessage
214
+ */
215
+ finalizeAssistantMessageInternal(state, parentToolUseId) {
216
+ if (state.finalized) {
217
+ return this.buildMessage(parentToolUseId);
218
+ }
219
+ state.finalized = true;
220
+ this.finalizePendingBlocks(state, parentToolUseId);
221
+ const orderedOpenBlocks = Array.from(state.openBlocks).sort((a, b) => a - b);
222
+ for (const index of orderedOpenBlocks) {
223
+ this.onBlockClosed(state, index, parentToolUseId);
224
+ this.closeBlock(state, index);
225
+ }
226
+ const message = this.buildMessage(parentToolUseId);
227
+ this.emitMessageImpl(message);
228
+ return message;
229
+ }
230
+ /**
231
+ * Hook method called when a text block is created.
232
+ * Subclasses can override this to emit stream events.
233
+ *
234
+ * @param state - Message state
235
+ * @param index - Block index
236
+ * @param block - Text block that was created
237
+ * @param parentToolUseId - null for main agent, string for subagent
238
+ */
239
+ onTextBlockCreated(_state, _index, _block, _parentToolUseId) {
240
+ // Default implementation does nothing
241
+ }
242
+ /**
243
+ * Hook method called when text content is appended.
244
+ * Subclasses can override this to emit stream events.
245
+ *
246
+ * @param state - Message state
247
+ * @param index - Block index
248
+ * @param fragment - Text fragment that was appended
249
+ * @param parentToolUseId - null for main agent, string for subagent
250
+ */
251
+ onTextAppended(_state, _index, _fragment, _parentToolUseId) {
252
+ // Default implementation does nothing
253
+ }
254
+ /**
255
+ * Hook method called when a thinking block is created.
256
+ * Subclasses can override this to emit stream events.
257
+ *
258
+ * @param state - Message state
259
+ * @param index - Block index
260
+ * @param block - Thinking block that was created
261
+ * @param parentToolUseId - null for main agent, string for subagent
262
+ */
263
+ onThinkingBlockCreated(_state, _index, _block, _parentToolUseId) {
264
+ // Default implementation does nothing
265
+ }
266
+ /**
267
+ * Hook method called when thinking content is appended.
268
+ * Subclasses can override this to emit stream events.
269
+ *
270
+ * @param state - Message state
271
+ * @param index - Block index
272
+ * @param fragment - Thinking fragment that was appended
273
+ * @param parentToolUseId - null for main agent, string for subagent
274
+ */
275
+ onThinkingAppended(_state, _index, _fragment, _parentToolUseId) {
276
+ // Default implementation does nothing
277
+ }
278
+ /**
279
+ * Hook method called when a tool_use block is created.
280
+ * Subclasses can override this to emit stream events.
281
+ *
282
+ * @param state - Message state
283
+ * @param index - Block index
284
+ * @param block - Tool use block that was created
285
+ * @param parentToolUseId - null for main agent, string for subagent
286
+ */
287
+ onToolUseBlockCreated(_state, _index, _block, _parentToolUseId) {
288
+ // Default implementation does nothing
289
+ }
290
+ /**
291
+ * Hook method called when tool_use input is set.
292
+ * Subclasses can override this to emit stream events.
293
+ *
294
+ * @param state - Message state
295
+ * @param index - Block index
296
+ * @param input - Tool use input that was set
297
+ * @param parentToolUseId - null for main agent, string for subagent
298
+ */
299
+ onToolUseInputSet(_state, _index, _input, _parentToolUseId) {
300
+ // Default implementation does nothing
301
+ }
302
+ /**
303
+ * Hook method called when a block is closed.
304
+ * Subclasses can override this to emit stream events.
305
+ *
306
+ * @param state - Message state
307
+ * @param index - Block index
308
+ * @param parentToolUseId - null for main agent, string for subagent
309
+ */
310
+ onBlockClosed(_state, _index, _parentToolUseId) {
311
+ // Default implementation does nothing
312
+ }
313
+ /**
314
+ * Hook method called to ensure message is started.
315
+ * Subclasses can override this to emit message_start events.
316
+ *
317
+ * @param state - Message state
318
+ * @param parentToolUseId - null for main agent, string for subagent
319
+ */
320
+ onEnsureMessageStarted(_state, _parentToolUseId) {
321
+ // Default implementation does nothing
322
+ }
323
+ /**
324
+ * Gets the session ID from config.
325
+ *
326
+ * @returns Session ID
327
+ */
328
+ getSessionId() {
329
+ return this.config.getSessionId();
330
+ }
331
+ /**
332
+ * Gets the model name from config.
333
+ *
334
+ * @returns Model name
335
+ */
336
+ getModel() {
337
+ return this.config.getModel();
338
+ }
339
+ // ========== Main Agent APIs ==========
340
+ /**
341
+ * Starts a new assistant message for the main agent.
342
+ * This is a shared implementation used by both streaming and non-streaming adapters.
343
+ */
344
+ startAssistantMessage() {
345
+ this.startAssistantMessageInternal(this.mainAgentMessageState);
346
+ }
347
+ /**
348
+ * Processes a stream event from the Gemini API.
349
+ * This is a shared implementation used by both streaming and non-streaming adapters.
350
+ *
351
+ * @param event - Stream event from Gemini API
352
+ */
353
+ processEvent(event) {
354
+ const state = this.mainAgentMessageState;
355
+ if (state.finalized) {
356
+ return;
357
+ }
358
+ switch (event.type) {
359
+ case GeminiEventType.Content:
360
+ this.appendText(state, event.value, null);
361
+ break;
362
+ case GeminiEventType.Citation:
363
+ if (typeof event.value === 'string') {
364
+ this.appendText(state, `\n${event.value}`, null);
365
+ }
366
+ break;
367
+ case GeminiEventType.Thought:
368
+ this.appendThinking(state, event.value.subject, event.value.description, null);
369
+ break;
370
+ case GeminiEventType.ToolCallRequest:
371
+ this.appendToolUse(state, event.value, null);
372
+ break;
373
+ case GeminiEventType.Finished:
374
+ if (event.value?.usageMetadata) {
375
+ state.usage = this.createUsage(event.value.usageMetadata);
376
+ }
377
+ this.finalizePendingBlocks(state, null);
378
+ break;
379
+ default:
380
+ break;
381
+ }
382
+ }
383
+ // ========== Subagent APIs ==========
384
+ /**
385
+ * Starts a new assistant message for a subagent.
386
+ * This is a shared implementation used by both streaming and non-streaming adapters.
387
+ *
388
+ * @param parentToolUseId - Parent tool use ID
389
+ */
390
+ startSubagentAssistantMessage(parentToolUseId) {
391
+ const state = this.getMessageState(parentToolUseId);
392
+ this.startAssistantMessageInternal(state);
393
+ }
394
+ /**
395
+ * Finalizes a subagent assistant message.
396
+ * This is a shared implementation used by both streaming and non-streaming adapters.
397
+ *
398
+ * @param parentToolUseId - Parent tool use ID
399
+ * @returns CLIAssistantMessage
400
+ */
401
+ finalizeSubagentAssistantMessage(parentToolUseId) {
402
+ const state = this.getMessageState(parentToolUseId);
403
+ const message = this.finalizeAssistantMessageInternal(state, parentToolUseId);
404
+ this.updateLastAssistantMessage(message);
405
+ return message;
406
+ }
407
+ /**
408
+ * Emits a subagent error result message.
409
+ * This is a shared implementation used by both streaming and non-streaming adapters.
410
+ *
411
+ * @param errorMessage - Error message
412
+ * @param numTurns - Number of turns
413
+ * @param parentToolUseId - Parent tool use ID
414
+ */
415
+ emitSubagentErrorResult(errorMessage, numTurns, parentToolUseId) {
416
+ const state = this.getMessageState(parentToolUseId);
417
+ // Finalize any pending assistant message
418
+ if (state.messageStarted && !state.finalized) {
419
+ this.finalizeSubagentAssistantMessage(parentToolUseId);
420
+ }
421
+ const errorResult = this.buildSubagentErrorResult(errorMessage, numTurns);
422
+ this.emitMessageImpl(errorResult);
423
+ }
424
+ /**
425
+ * Processes a subagent tool call.
426
+ * This is a shared implementation used by both streaming and non-streaming adapters.
427
+ * Uses template method pattern with hooks for stream events.
428
+ *
429
+ * @param toolCall - Tool call information
430
+ * @param parentToolUseId - Parent tool use ID
431
+ */
432
+ processSubagentToolCall(toolCall, parentToolUseId) {
433
+ const state = this.getMessageState(parentToolUseId);
434
+ // Finalize any pending text message before starting tool_use
435
+ const hasText = state.blocks.some((b) => b.type === 'text') ||
436
+ (state.currentBlockType === 'text' && state.blocks.length > 0);
437
+ if (hasText) {
438
+ this.finalizeSubagentAssistantMessage(parentToolUseId);
439
+ this.startSubagentAssistantMessage(parentToolUseId);
440
+ }
441
+ // Ensure message is started before appending tool_use
442
+ if (!state.messageId || !state.messageStarted) {
443
+ this.startAssistantMessageInternal(state);
444
+ }
445
+ this.ensureBlockTypeConsistency(state, 'tool_use', parentToolUseId);
446
+ this.ensureMessageStarted(state, parentToolUseId);
447
+ this.finalizePendingBlocks(state, parentToolUseId);
448
+ const { index } = this.createSubagentToolUseBlock(state, toolCall, parentToolUseId);
449
+ // Process tool use block creation and closure
450
+ // Subclasses can override hook methods to emit stream events
451
+ this.processSubagentToolUseBlock(state, index, toolCall, parentToolUseId);
452
+ // Finalize tool_use message immediately
453
+ this.finalizeSubagentAssistantMessage(parentToolUseId);
454
+ this.startSubagentAssistantMessage(parentToolUseId);
455
+ }
456
+ /**
457
+ * Processes a tool use block for subagent.
458
+ * This method is called by processSubagentToolCall to handle tool use block creation,
459
+ * input setting, and closure. Subclasses can override this to customize behavior.
460
+ *
461
+ * @param state - Message state
462
+ * @param index - Block index
463
+ * @param toolCall - Tool call information
464
+ * @param parentToolUseId - Parent tool use ID
465
+ */
466
+ processSubagentToolUseBlock(state, index, toolCall, parentToolUseId) {
467
+ // Emit tool_use block creation event (with empty input)
468
+ const startBlock = {
469
+ type: 'tool_use',
470
+ id: toolCall.callId,
471
+ name: toolCall.name,
472
+ input: {},
473
+ };
474
+ this.onToolUseBlockCreated(state, index, startBlock, parentToolUseId);
475
+ this.onToolUseInputSet(state, index, toolCall.args ?? {}, parentToolUseId);
476
+ this.onBlockClosed(state, index, parentToolUseId);
477
+ this.closeBlock(state, index);
478
+ }
479
+ /**
480
+ * Updates the last assistant message.
481
+ * Subclasses can override this to customize tracking behavior.
482
+ *
483
+ * @param message - Assistant message to track
484
+ */
485
+ updateLastAssistantMessage(message) {
486
+ this.lastAssistantMessage = message;
487
+ }
488
+ // ========== Shared Content Block Methods ==========
489
+ /**
490
+ * Appends text content to the current message.
491
+ * Uses template method pattern with hooks for stream events.
492
+ *
493
+ * @param state - Message state
494
+ * @param fragment - Text fragment to append
495
+ * @param parentToolUseId - null for main agent, string for subagent
496
+ */
497
+ appendText(state, fragment, parentToolUseId) {
498
+ if (fragment.length === 0) {
499
+ return;
500
+ }
501
+ this.ensureBlockTypeConsistency(state, 'text', parentToolUseId);
502
+ this.ensureMessageStarted(state, parentToolUseId);
503
+ let current = state.blocks[state.blocks.length - 1];
504
+ const isNewBlock = !current || current.type !== 'text';
505
+ if (isNewBlock) {
506
+ current = { type: 'text', text: '' };
507
+ const index = state.blocks.length;
508
+ state.blocks.push(current);
509
+ this.openBlock(state, index, current);
510
+ this.onTextBlockCreated(state, index, current, parentToolUseId);
511
+ }
512
+ // current is guaranteed to be defined here (either existing or newly created)
513
+ current.text += fragment;
514
+ const index = state.blocks.length - 1;
515
+ this.onTextAppended(state, index, fragment, parentToolUseId);
516
+ }
517
+ /**
518
+ * Appends thinking content to the current message.
519
+ * Uses template method pattern with hooks for stream events.
520
+ *
521
+ * @param state - Message state
522
+ * @param subject - Thinking subject
523
+ * @param description - Thinking description
524
+ * @param parentToolUseId - null for main agent, string for subagent
525
+ */
526
+ appendThinking(state, subject, description, parentToolUseId) {
527
+ const actualParentToolUseId = parentToolUseId ?? null;
528
+ const fragment = [subject?.trim(), description?.trim()]
529
+ .filter((value) => value && value.length > 0)
530
+ .join(': ');
531
+ if (!fragment) {
532
+ return;
533
+ }
534
+ this.ensureBlockTypeConsistency(state, 'thinking', actualParentToolUseId);
535
+ this.ensureMessageStarted(state, actualParentToolUseId);
536
+ let current = state.blocks[state.blocks.length - 1];
537
+ const isNewBlock = !current || current.type !== 'thinking';
538
+ if (isNewBlock) {
539
+ current = {
540
+ type: 'thinking',
541
+ thinking: '',
542
+ signature: subject,
543
+ };
544
+ const index = state.blocks.length;
545
+ state.blocks.push(current);
546
+ this.openBlock(state, index, current);
547
+ this.onThinkingBlockCreated(state, index, current, actualParentToolUseId);
548
+ }
549
+ // current is guaranteed to be defined here (either existing or newly created)
550
+ current.thinking = `${current.thinking ?? ''}${fragment}`;
551
+ const index = state.blocks.length - 1;
552
+ this.onThinkingAppended(state, index, fragment, actualParentToolUseId);
553
+ }
554
+ /**
555
+ * Appends a tool_use block to the current message.
556
+ * Uses template method pattern with hooks for stream events.
557
+ *
558
+ * @param state - Message state
559
+ * @param request - Tool call request info
560
+ * @param parentToolUseId - null for main agent, string for subagent
561
+ */
562
+ appendToolUse(state, request, parentToolUseId) {
563
+ this.ensureBlockTypeConsistency(state, 'tool_use', parentToolUseId);
564
+ this.ensureMessageStarted(state, parentToolUseId);
565
+ this.finalizePendingBlocks(state, parentToolUseId);
566
+ const index = state.blocks.length;
567
+ const block = {
568
+ type: 'tool_use',
569
+ id: request.callId,
570
+ name: request.name,
571
+ input: request.args,
572
+ };
573
+ state.blocks.push(block);
574
+ this.openBlock(state, index, block);
575
+ // Emit tool_use block creation event (with empty input)
576
+ const startBlock = {
577
+ type: 'tool_use',
578
+ id: request.callId,
579
+ name: request.name,
580
+ input: {},
581
+ };
582
+ this.onToolUseBlockCreated(state, index, startBlock, parentToolUseId);
583
+ this.onToolUseInputSet(state, index, request.args ?? {}, parentToolUseId);
584
+ this.onBlockClosed(state, index, parentToolUseId);
585
+ this.closeBlock(state, index);
586
+ }
587
+ /**
588
+ * Ensures that a message has been started.
589
+ * Calls hook method for subclasses to emit message_start events.
590
+ *
591
+ * @param state - Message state
592
+ * @param parentToolUseId - null for main agent, string for subagent
593
+ */
594
+ ensureMessageStarted(state, parentToolUseId) {
595
+ if (state.messageStarted) {
596
+ return;
597
+ }
598
+ state.messageStarted = true;
599
+ this.onEnsureMessageStarted(state, parentToolUseId);
600
+ }
601
+ /**
602
+ * Creates and adds a tool_use block to the state.
603
+ * This is a shared helper method used by processSubagentToolCall implementations.
604
+ *
605
+ * @param state - Message state
606
+ * @param toolCall - Tool call information
607
+ * @param parentToolUseId - Parent tool use ID
608
+ * @returns The created block and its index
609
+ */
610
+ createSubagentToolUseBlock(state, toolCall, _parentToolUseId) {
611
+ const index = state.blocks.length;
612
+ const block = {
613
+ type: 'tool_use',
614
+ id: toolCall.callId,
615
+ name: toolCall.name,
616
+ input: toolCall.args || {},
617
+ };
618
+ state.blocks.push(block);
619
+ this.openBlock(state, index, block);
620
+ return { block, index };
621
+ }
622
+ /**
623
+ * Emits a user message.
624
+ * @param parts - Array of Part objects
625
+ * @param parentToolUseId - Optional parent tool use ID for subagent messages
626
+ */
627
+ emitUserMessage(parts, parentToolUseId) {
628
+ const content = partsToContentBlock(parts);
629
+ const message = {
630
+ type: 'user',
631
+ uuid: randomUUID(),
632
+ session_id: this.getSessionId(),
633
+ parent_tool_use_id: parentToolUseId ?? null,
634
+ message: {
635
+ role: 'user',
636
+ content,
637
+ },
638
+ };
639
+ this.emitMessageImpl(message);
640
+ }
641
+ /**
642
+ * Emits a tool result message.
643
+ * Collects execution denied tool calls for inclusion in result messages.
644
+ * @param request - Tool call request info
645
+ * @param response - Tool call response info
646
+ * @param parentToolUseId - Parent tool use ID (null for main agent)
647
+ */
648
+ emitToolResult(request, response, parentToolUseId = null) {
649
+ // Track permission denials (execution denied errors)
650
+ if (response.error &&
651
+ response.errorType === ToolErrorType.EXECUTION_DENIED) {
652
+ const denial = {
653
+ tool_name: request.name,
654
+ tool_use_id: request.callId,
655
+ tool_input: request.args,
656
+ };
657
+ this.permissionDenials.push(denial);
658
+ }
659
+ const block = {
660
+ type: 'tool_result',
661
+ tool_use_id: request.callId,
662
+ is_error: Boolean(response.error),
663
+ };
664
+ const content = toolResultContent(response);
665
+ if (content !== undefined) {
666
+ block.content = content;
667
+ }
668
+ const message = {
669
+ type: 'user',
670
+ uuid: randomUUID(),
671
+ session_id: this.getSessionId(),
672
+ parent_tool_use_id: parentToolUseId,
673
+ message: {
674
+ role: 'user',
675
+ content: [block],
676
+ },
677
+ };
678
+ this.emitMessageImpl(message);
679
+ }
680
+ /**
681
+ * Emits a system message.
682
+ * @param subtype - System message subtype
683
+ * @param data - Optional data payload
684
+ */
685
+ emitSystemMessage(subtype, data) {
686
+ const systemMessage = {
687
+ type: 'system',
688
+ subtype,
689
+ uuid: randomUUID(),
690
+ session_id: this.getSessionId(),
691
+ parent_tool_use_id: null,
692
+ data,
693
+ };
694
+ this.emitMessageImpl(systemMessage);
695
+ }
696
+ /**
697
+ * Builds a result message from options.
698
+ * Helper method used by both emitResult implementations.
699
+ * Includes permission denials collected from execution denied tool calls.
700
+ * @param options - Result options
701
+ * @param lastAssistantMessage - Last assistant message for text extraction
702
+ * @returns CLIResultMessage
703
+ */
704
+ buildResultMessage(options, lastAssistantMessage) {
705
+ const usage = options.usage ?? createExtendedUsage();
706
+ const resultText = options.summary ??
707
+ (lastAssistantMessage
708
+ ? extractTextFromBlocks(lastAssistantMessage.message.content)
709
+ : '');
710
+ const baseUuid = randomUUID();
711
+ const baseSessionId = this.getSessionId();
712
+ if (options.isError) {
713
+ const errorMessage = options.errorMessage ?? 'Unknown error';
714
+ return {
715
+ type: 'result',
716
+ subtype: options.subtype ??
717
+ 'error_during_execution',
718
+ uuid: baseUuid,
719
+ session_id: baseSessionId,
720
+ is_error: true,
721
+ duration_ms: options.durationMs,
722
+ duration_api_ms: options.apiDurationMs,
723
+ num_turns: options.numTurns,
724
+ usage,
725
+ permission_denials: [...this.permissionDenials],
726
+ error: { message: errorMessage },
727
+ };
728
+ }
729
+ else {
730
+ const success = {
731
+ type: 'result',
732
+ subtype: options.subtype ?? 'success',
733
+ uuid: baseUuid,
734
+ session_id: baseSessionId,
735
+ is_error: false,
736
+ duration_ms: options.durationMs,
737
+ duration_api_ms: options.apiDurationMs,
738
+ num_turns: options.numTurns,
739
+ result: resultText,
740
+ usage,
741
+ permission_denials: [...this.permissionDenials],
742
+ };
743
+ if (options.stats) {
744
+ success.stats = options.stats;
745
+ }
746
+ return success;
747
+ }
748
+ }
749
+ /**
750
+ * Builds a subagent error result message.
751
+ * Helper method used by both emitSubagentErrorResult implementations.
752
+ * Note: Subagent permission denials are not included here as they are tracked
753
+ * separately and would be included in the main agent's result message.
754
+ * @param errorMessage - Error message
755
+ * @param numTurns - Number of turns
756
+ * @returns CLIResultMessageError
757
+ */
758
+ buildSubagentErrorResult(errorMessage, numTurns) {
759
+ const usage = {
760
+ input_tokens: 0,
761
+ output_tokens: 0,
762
+ };
763
+ return {
764
+ type: 'result',
765
+ subtype: 'error_during_execution',
766
+ uuid: randomUUID(),
767
+ session_id: this.getSessionId(),
768
+ is_error: true,
769
+ duration_ms: 0,
770
+ duration_api_ms: 0,
771
+ num_turns: numTurns,
772
+ usage,
773
+ permission_denials: [],
774
+ error: { message: errorMessage },
775
+ };
776
+ }
777
+ }
778
+ /**
779
+ * Converts Part array to ContentBlock array.
780
+ * Handles various Part types including text, functionResponse, and other types.
781
+ * For functionResponse parts, extracts the output content.
782
+ * For other non-text parts, converts them to text representation.
783
+ *
784
+ * @param parts - Array of Part objects
785
+ * @returns Array of ContentBlock objects (primarily TextBlock)
786
+ */
787
+ export function partsToContentBlock(parts) {
788
+ const blocks = [];
789
+ let currentTextBlock = null;
790
+ for (const part of parts) {
791
+ let textContent = null;
792
+ // Handle text parts
793
+ if ('text' in part && typeof part.text === 'string') {
794
+ textContent = part.text;
795
+ }
796
+ // Handle functionResponse parts - extract output content
797
+ else if ('functionResponse' in part && part.functionResponse) {
798
+ const output = part.functionResponse.response?.['output'] ??
799
+ part.functionResponse.response?.['content'] ??
800
+ '';
801
+ textContent =
802
+ typeof output === 'string' ? output : JSON.stringify(output);
803
+ }
804
+ // Handle other part types - convert to JSON string
805
+ else {
806
+ textContent = JSON.stringify(part);
807
+ }
808
+ // If we have text content, add it to the current text block or create a new one
809
+ if (textContent !== null && textContent.length > 0) {
810
+ if (currentTextBlock === null) {
811
+ currentTextBlock = {
812
+ type: 'text',
813
+ text: textContent,
814
+ };
815
+ blocks.push(currentTextBlock);
816
+ }
817
+ else {
818
+ // Append to existing text block
819
+ currentTextBlock.text += textContent;
820
+ }
821
+ }
822
+ }
823
+ // Return blocks array, or empty array if no content
824
+ return blocks;
825
+ }
826
+ /**
827
+ * Converts Part array to string representation.
828
+ * This is a legacy function kept for backward compatibility.
829
+ * For new code, prefer using partsToContentBlock.
830
+ *
831
+ * @param parts - Array of Part objects
832
+ * @returns String representation
833
+ */
834
+ export function partsToString(parts) {
835
+ return parts
836
+ .map((part) => {
837
+ if ('text' in part && typeof part.text === 'string') {
838
+ return part.text;
839
+ }
840
+ return JSON.stringify(part);
841
+ })
842
+ .join('');
843
+ }
844
+ /**
845
+ * Extracts content from tool response.
846
+ * Uses functionResponsePartsToString to properly handle functionResponse parts,
847
+ * which correctly extracts output content from functionResponse objects rather
848
+ * than simply concatenating text or JSON.stringify.
849
+ *
850
+ * @param response - Tool call response
851
+ * @returns String content or undefined
852
+ */
853
+ export function toolResultContent(response) {
854
+ if (response.error) {
855
+ return response.error.message;
856
+ }
857
+ if (typeof response.resultDisplay === 'string' &&
858
+ response.resultDisplay.trim().length > 0) {
859
+ return response.resultDisplay;
860
+ }
861
+ if (response.responseParts && response.responseParts.length > 0) {
862
+ // Always use functionResponsePartsToString to properly handle
863
+ // functionResponse parts that contain output content
864
+ return functionResponsePartsToString(response.responseParts);
865
+ }
866
+ return undefined;
867
+ }
868
+ /**
869
+ * Extracts text from content blocks.
870
+ *
871
+ * @param blocks - Array of content blocks
872
+ * @returns Extracted text
873
+ */
874
+ export function extractTextFromBlocks(blocks) {
875
+ return blocks
876
+ .filter((block) => block.type === 'text')
877
+ .map((block) => (block.type === 'text' ? block.text : ''))
878
+ .join('');
879
+ }
880
+ /**
881
+ * Creates an extended usage object with default values.
882
+ *
883
+ * @returns ExtendedUsage object
884
+ */
885
+ export function createExtendedUsage() {
886
+ return {
887
+ input_tokens: 0,
888
+ output_tokens: 0,
889
+ };
890
+ }
891
+ //# sourceMappingURL=BaseJsonOutputAdapter.js.map