@nanocollective/nanocoder 1.11.3

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 (392) hide show
  1. package/LICENSE.md +23 -0
  2. package/README.md +366 -0
  3. package/dist/app/hooks/useAppInitialization.d.ts +26 -0
  4. package/dist/app/hooks/useAppInitialization.d.ts.map +1 -0
  5. package/dist/app/hooks/useAppInitialization.js +151 -0
  6. package/dist/app/hooks/useAppInitialization.js.map +1 -0
  7. package/dist/app/hooks/useAppState.d.ts +84 -0
  8. package/dist/app/hooks/useAppState.d.ts.map +1 -0
  9. package/dist/app/hooks/useAppState.js +162 -0
  10. package/dist/app/hooks/useAppState.js.map +1 -0
  11. package/dist/app/hooks/useChatHandler.d.ts +26 -0
  12. package/dist/app/hooks/useChatHandler.d.ts.map +1 -0
  13. package/dist/app/hooks/useChatHandler.js +532 -0
  14. package/dist/app/hooks/useChatHandler.js.map +1 -0
  15. package/dist/app/hooks/useDirectoryTrust.d.ts +15 -0
  16. package/dist/app/hooks/useDirectoryTrust.d.ts.map +1 -0
  17. package/dist/app/hooks/useDirectoryTrust.js +77 -0
  18. package/dist/app/hooks/useDirectoryTrust.js.map +1 -0
  19. package/dist/app/hooks/useModeHandlers.d.ts +31 -0
  20. package/dist/app/hooks/useModeHandlers.d.ts.map +1 -0
  21. package/dist/app/hooks/useModeHandlers.js +98 -0
  22. package/dist/app/hooks/useModeHandlers.js.map +1 -0
  23. package/dist/app/hooks/useToolHandler.d.ts +32 -0
  24. package/dist/app/hooks/useToolHandler.d.ts.map +1 -0
  25. package/dist/app/hooks/useToolHandler.js +154 -0
  26. package/dist/app/hooks/useToolHandler.js.map +1 -0
  27. package/dist/app/utils/appUtils.d.ts +4 -0
  28. package/dist/app/utils/appUtils.d.ts.map +1 -0
  29. package/dist/app/utils/appUtils.js +147 -0
  30. package/dist/app/utils/appUtils.js.map +1 -0
  31. package/dist/app/utils/conversationState.d.ts +68 -0
  32. package/dist/app/utils/conversationState.d.ts.map +1 -0
  33. package/dist/app/utils/conversationState.js +199 -0
  34. package/dist/app/utils/conversationState.js.map +1 -0
  35. package/dist/app.d.ts +2 -0
  36. package/dist/app.d.ts.map +1 -0
  37. package/dist/app.js +193 -0
  38. package/dist/app.js.map +1 -0
  39. package/dist/cli.d.ts +3 -0
  40. package/dist/cli.d.ts.map +1 -0
  41. package/dist/cli.js +6 -0
  42. package/dist/cli.js.map +1 -0
  43. package/dist/client-factory.d.ts +6 -0
  44. package/dist/client-factory.d.ts.map +1 -0
  45. package/dist/client-factory.js +111 -0
  46. package/dist/client-factory.js.map +1 -0
  47. package/dist/command-parser.d.ts +5 -0
  48. package/dist/command-parser.d.ts.map +1 -0
  49. package/dist/command-parser.js +36 -0
  50. package/dist/command-parser.js.map +1 -0
  51. package/dist/commands/clear.d.ts +3 -0
  52. package/dist/commands/clear.d.ts.map +1 -0
  53. package/dist/commands/clear.js +17 -0
  54. package/dist/commands/clear.js.map +1 -0
  55. package/dist/commands/custom-commands.d.ts +3 -0
  56. package/dist/commands/custom-commands.d.ts.map +1 -0
  57. package/dist/commands/custom-commands.js +41 -0
  58. package/dist/commands/custom-commands.js.map +1 -0
  59. package/dist/commands/debug.d.ts +3 -0
  60. package/dist/commands/debug.d.ts.map +1 -0
  61. package/dist/commands/debug.js +86 -0
  62. package/dist/commands/debug.js.map +1 -0
  63. package/dist/commands/exit.d.ts +3 -0
  64. package/dist/commands/exit.d.ts.map +1 -0
  65. package/dist/commands/exit.js +17 -0
  66. package/dist/commands/exit.js.map +1 -0
  67. package/dist/commands/export.d.ts +3 -0
  68. package/dist/commands/export.d.ts.map +1 -0
  69. package/dist/commands/export.js +63 -0
  70. package/dist/commands/export.js.map +1 -0
  71. package/dist/commands/help.d.ts +3 -0
  72. package/dist/commands/help.d.ts.map +1 -0
  73. package/dist/commands/help.js +31 -0
  74. package/dist/commands/help.js.map +1 -0
  75. package/dist/commands/index.d.ts +13 -0
  76. package/dist/commands/index.d.ts.map +1 -0
  77. package/dist/commands/index.js +13 -0
  78. package/dist/commands/index.js.map +1 -0
  79. package/dist/commands/init.d.ts +3 -0
  80. package/dist/commands/init.d.ts.map +1 -0
  81. package/dist/commands/init.js +214 -0
  82. package/dist/commands/init.js.map +1 -0
  83. package/dist/commands/mcp.d.ts +9 -0
  84. package/dist/commands/mcp.d.ts.map +1 -0
  85. package/dist/commands/mcp.js +41 -0
  86. package/dist/commands/mcp.js.map +1 -0
  87. package/dist/commands/model.d.ts +3 -0
  88. package/dist/commands/model.d.ts.map +1 -0
  89. package/dist/commands/model.js +11 -0
  90. package/dist/commands/model.js.map +1 -0
  91. package/dist/commands/provider.d.ts +3 -0
  92. package/dist/commands/provider.d.ts.map +1 -0
  93. package/dist/commands/provider.js +11 -0
  94. package/dist/commands/provider.js.map +1 -0
  95. package/dist/commands/theme.d.ts +3 -0
  96. package/dist/commands/theme.d.ts.map +1 -0
  97. package/dist/commands/theme.js +11 -0
  98. package/dist/commands/theme.js.map +1 -0
  99. package/dist/commands/update.d.ts +3 -0
  100. package/dist/commands/update.d.ts.map +1 -0
  101. package/dist/commands/update.js +10 -0
  102. package/dist/commands/update.js.map +1 -0
  103. package/dist/commands.d.ts +16 -0
  104. package/dist/commands.d.ts.map +1 -0
  105. package/dist/commands.js +46 -0
  106. package/dist/commands.js.map +1 -0
  107. package/dist/components/assistant-message.d.ts +4 -0
  108. package/dist/components/assistant-message.d.ts.map +1 -0
  109. package/dist/components/assistant-message.js +43 -0
  110. package/dist/components/assistant-message.js.map +1 -0
  111. package/dist/components/bash-execution-indicator.d.ts +4 -0
  112. package/dist/components/bash-execution-indicator.d.ts.map +1 -0
  113. package/dist/components/bash-execution-indicator.js +9 -0
  114. package/dist/components/bash-execution-indicator.js.map +1 -0
  115. package/dist/components/cancelling-indicator.d.ts +3 -0
  116. package/dist/components/cancelling-indicator.d.ts.map +1 -0
  117. package/dist/components/cancelling-indicator.js +10 -0
  118. package/dist/components/cancelling-indicator.js.map +1 -0
  119. package/dist/components/chat-queue.d.ts +4 -0
  120. package/dist/components/chat-queue.d.ts.map +1 -0
  121. package/dist/components/chat-queue.js +23 -0
  122. package/dist/components/chat-queue.js.map +1 -0
  123. package/dist/components/custom-commands.d.ts +7 -0
  124. package/dist/components/custom-commands.d.ts.map +1 -0
  125. package/dist/components/custom-commands.js +27 -0
  126. package/dist/components/custom-commands.js.map +1 -0
  127. package/dist/components/error-message.d.ts +7 -0
  128. package/dist/components/error-message.d.ts.map +1 -0
  129. package/dist/components/error-message.js +12 -0
  130. package/dist/components/error-message.js.map +1 -0
  131. package/dist/components/info-message.d.ts +6 -0
  132. package/dist/components/info-message.d.ts.map +1 -0
  133. package/dist/components/info-message.js +11 -0
  134. package/dist/components/info-message.js.map +1 -0
  135. package/dist/components/model-selector.d.ts +10 -0
  136. package/dist/components/model-selector.d.ts.map +1 -0
  137. package/dist/components/model-selector.js +59 -0
  138. package/dist/components/model-selector.js.map +1 -0
  139. package/dist/components/provider-selector.d.ts +9 -0
  140. package/dist/components/provider-selector.d.ts.map +1 -0
  141. package/dist/components/provider-selector.js +36 -0
  142. package/dist/components/provider-selector.js.map +1 -0
  143. package/dist/components/security-disclaimer.d.ts +7 -0
  144. package/dist/components/security-disclaimer.d.ts.map +1 -0
  145. package/dist/components/security-disclaimer.js +36 -0
  146. package/dist/components/security-disclaimer.js.map +1 -0
  147. package/dist/components/status.d.ts +6 -0
  148. package/dist/components/status.d.ts.map +1 -0
  149. package/dist/components/status.js +35 -0
  150. package/dist/components/status.js.map +1 -0
  151. package/dist/components/success-message.d.ts +6 -0
  152. package/dist/components/success-message.d.ts.map +1 -0
  153. package/dist/components/success-message.js +11 -0
  154. package/dist/components/success-message.js.map +1 -0
  155. package/dist/components/theme-selector.d.ts +8 -0
  156. package/dist/components/theme-selector.d.ts.map +1 -0
  157. package/dist/components/theme-selector.js +40 -0
  158. package/dist/components/theme-selector.js.map +1 -0
  159. package/dist/components/thinking-indicator.d.ts +4 -0
  160. package/dist/components/thinking-indicator.d.ts.map +1 -0
  161. package/dist/components/thinking-indicator.js +32 -0
  162. package/dist/components/thinking-indicator.js.map +1 -0
  163. package/dist/components/tool-confirmation.d.ts +9 -0
  164. package/dist/components/tool-confirmation.d.ts.map +1 -0
  165. package/dist/components/tool-confirmation.js +72 -0
  166. package/dist/components/tool-confirmation.js.map +1 -0
  167. package/dist/components/tool-execution-indicator.d.ts +3 -0
  168. package/dist/components/tool-execution-indicator.d.ts.map +1 -0
  169. package/dist/components/tool-execution-indicator.js +9 -0
  170. package/dist/components/tool-execution-indicator.js.map +1 -0
  171. package/dist/components/tool-message.d.ts +10 -0
  172. package/dist/components/tool-message.d.ts.map +1 -0
  173. package/dist/components/tool-message.js +16 -0
  174. package/dist/components/tool-message.js.map +1 -0
  175. package/dist/components/update-message.d.ts +7 -0
  176. package/dist/components/update-message.d.ts.map +1 -0
  177. package/dist/components/update-message.js +93 -0
  178. package/dist/components/update-message.js.map +1 -0
  179. package/dist/components/user-input.d.ts +10 -0
  180. package/dist/components/user-input.d.ts.map +1 -0
  181. package/dist/components/user-input.js +188 -0
  182. package/dist/components/user-input.js.map +1 -0
  183. package/dist/components/user-message.d.ts +4 -0
  184. package/dist/components/user-message.d.ts.map +1 -0
  185. package/dist/components/user-message.js +15 -0
  186. package/dist/components/user-message.js.map +1 -0
  187. package/dist/components/welcome-message.d.ts +3 -0
  188. package/dist/components/welcome-message.d.ts.map +1 -0
  189. package/dist/components/welcome-message.js +21 -0
  190. package/dist/components/welcome-message.js.map +1 -0
  191. package/dist/config/index.d.ts +10 -0
  192. package/dist/config/index.d.ts.map +1 -0
  193. package/dist/config/index.js +44 -0
  194. package/dist/config/index.js.map +1 -0
  195. package/dist/config/logging.d.ts +14 -0
  196. package/dist/config/logging.d.ts.map +1 -0
  197. package/dist/config/logging.js +58 -0
  198. package/dist/config/logging.js.map +1 -0
  199. package/dist/config/preferences.d.ts +7 -0
  200. package/dist/config/preferences.d.ts.map +1 -0
  201. package/dist/config/preferences.js +46 -0
  202. package/dist/config/preferences.js.map +1 -0
  203. package/dist/config/themes.d.ts +6 -0
  204. package/dist/config/themes.d.ts.map +1 -0
  205. package/dist/config/themes.js +295 -0
  206. package/dist/config/themes.js.map +1 -0
  207. package/dist/custom-commands/executor.d.ts +12 -0
  208. package/dist/custom-commands/executor.d.ts.map +1 -0
  209. package/dist/custom-commands/executor.js +45 -0
  210. package/dist/custom-commands/executor.js.map +1 -0
  211. package/dist/custom-commands/index.d.ts +4 -0
  212. package/dist/custom-commands/index.d.ts.map +1 -0
  213. package/dist/custom-commands/index.js +4 -0
  214. package/dist/custom-commands/index.js.map +1 -0
  215. package/dist/custom-commands/loader.d.ts +41 -0
  216. package/dist/custom-commands/loader.d.ts.map +1 -0
  217. package/dist/custom-commands/loader.js +129 -0
  218. package/dist/custom-commands/loader.js.map +1 -0
  219. package/dist/custom-commands/parser.d.ts +10 -0
  220. package/dist/custom-commands/parser.d.ts.map +1 -0
  221. package/dist/custom-commands/parser.js +181 -0
  222. package/dist/custom-commands/parser.js.map +1 -0
  223. package/dist/hooks/useInputState.d.ts +14 -0
  224. package/dist/hooks/useInputState.d.ts.map +1 -0
  225. package/dist/hooks/useInputState.js +66 -0
  226. package/dist/hooks/useInputState.js.map +1 -0
  227. package/dist/hooks/useTerminalWidth.d.ts +2 -0
  228. package/dist/hooks/useTerminalWidth.d.ts.map +1 -0
  229. package/dist/hooks/useTerminalWidth.js +20 -0
  230. package/dist/hooks/useTerminalWidth.js.map +1 -0
  231. package/dist/hooks/useTheme.d.ts +9 -0
  232. package/dist/hooks/useTheme.d.ts.map +1 -0
  233. package/dist/hooks/useTheme.js +10 -0
  234. package/dist/hooks/useTheme.js.map +1 -0
  235. package/dist/hooks/useUIState.d.ts +19 -0
  236. package/dist/hooks/useUIState.d.ts.map +1 -0
  237. package/dist/hooks/useUIState.js +46 -0
  238. package/dist/hooks/useUIState.js.map +1 -0
  239. package/dist/init/agents-template-generator.d.ts +29 -0
  240. package/dist/init/agents-template-generator.d.ts.map +1 -0
  241. package/dist/init/agents-template-generator.js +340 -0
  242. package/dist/init/agents-template-generator.js.map +1 -0
  243. package/dist/init/existing-rules-extractor.d.ts +43 -0
  244. package/dist/init/existing-rules-extractor.d.ts.map +1 -0
  245. package/dist/init/existing-rules-extractor.js +226 -0
  246. package/dist/init/existing-rules-extractor.js.map +1 -0
  247. package/dist/init/file-scanner.d.ts +40 -0
  248. package/dist/init/file-scanner.d.ts.map +1 -0
  249. package/dist/init/file-scanner.js +153 -0
  250. package/dist/init/file-scanner.js.map +1 -0
  251. package/dist/init/framework-detector.d.ts +57 -0
  252. package/dist/init/framework-detector.d.ts.map +1 -0
  253. package/dist/init/framework-detector.js +277 -0
  254. package/dist/init/framework-detector.js.map +1 -0
  255. package/dist/init/language-detector.d.ts +31 -0
  256. package/dist/init/language-detector.d.ts.map +1 -0
  257. package/dist/init/language-detector.js +205 -0
  258. package/dist/init/language-detector.js.map +1 -0
  259. package/dist/init/project-analyzer.d.ts +62 -0
  260. package/dist/init/project-analyzer.d.ts.map +1 -0
  261. package/dist/init/project-analyzer.js +294 -0
  262. package/dist/init/project-analyzer.js.map +1 -0
  263. package/dist/langgraph-client.d.ts +20 -0
  264. package/dist/langgraph-client.d.ts.map +1 -0
  265. package/dist/langgraph-client.js +245 -0
  266. package/dist/langgraph-client.js.map +1 -0
  267. package/dist/mcp/mcp-client.d.ts +23 -0
  268. package/dist/mcp/mcp-client.d.ts.map +1 -0
  269. package/dist/mcp/mcp-client.js +194 -0
  270. package/dist/mcp/mcp-client.js.map +1 -0
  271. package/dist/mcp/mcp-tool-adapter.d.ts +22 -0
  272. package/dist/mcp/mcp-tool-adapter.d.ts.map +1 -0
  273. package/dist/mcp/mcp-tool-adapter.js +49 -0
  274. package/dist/mcp/mcp-tool-adapter.js.map +1 -0
  275. package/dist/message-handler.d.ts +7 -0
  276. package/dist/message-handler.d.ts.map +1 -0
  277. package/dist/message-handler.js +53 -0
  278. package/dist/message-handler.js.map +1 -0
  279. package/dist/prompt-history.d.ts +14 -0
  280. package/dist/prompt-history.d.ts.map +1 -0
  281. package/dist/prompt-history.js +88 -0
  282. package/dist/prompt-history.js.map +1 -0
  283. package/dist/tool-calling/index.d.ts +6 -0
  284. package/dist/tool-calling/index.d.ts.map +1 -0
  285. package/dist/tool-calling/index.js +5 -0
  286. package/dist/tool-calling/index.js.map +1 -0
  287. package/dist/tool-calling/json-parser.d.ts +7 -0
  288. package/dist/tool-calling/json-parser.d.ts.map +1 -0
  289. package/dist/tool-calling/json-parser.js +168 -0
  290. package/dist/tool-calling/json-parser.js.map +1 -0
  291. package/dist/tool-calling/xml-parser.d.ts +34 -0
  292. package/dist/tool-calling/xml-parser.d.ts.map +1 -0
  293. package/dist/tool-calling/xml-parser.js +113 -0
  294. package/dist/tool-calling/xml-parser.js.map +1 -0
  295. package/dist/tools/create-file.d.ts +3 -0
  296. package/dist/tools/create-file.d.ts.map +1 -0
  297. package/dist/tools/create-file.js +66 -0
  298. package/dist/tools/create-file.js.map +1 -0
  299. package/dist/tools/delete-lines.d.ts +3 -0
  300. package/dist/tools/delete-lines.d.ts.map +1 -0
  301. package/dist/tools/delete-lines.js +218 -0
  302. package/dist/tools/delete-lines.js.map +1 -0
  303. package/dist/tools/execute-bash.d.ts +3 -0
  304. package/dist/tools/execute-bash.d.ts.map +1 -0
  305. package/dist/tools/execute-bash.js +107 -0
  306. package/dist/tools/execute-bash.js.map +1 -0
  307. package/dist/tools/index.d.ts +7 -0
  308. package/dist/tools/index.d.ts.map +1 -0
  309. package/dist/tools/index.js +23 -0
  310. package/dist/tools/index.js.map +1 -0
  311. package/dist/tools/insert-lines.d.ts +3 -0
  312. package/dist/tools/insert-lines.d.ts.map +1 -0
  313. package/dist/tools/insert-lines.js +185 -0
  314. package/dist/tools/insert-lines.js.map +1 -0
  315. package/dist/tools/read-file.d.ts +3 -0
  316. package/dist/tools/read-file.d.ts.map +1 -0
  317. package/dist/tools/read-file.js +81 -0
  318. package/dist/tools/read-file.js.map +1 -0
  319. package/dist/tools/read-many-files.d.ts +3 -0
  320. package/dist/tools/read-many-files.d.ts.map +1 -0
  321. package/dist/tools/read-many-files.js +109 -0
  322. package/dist/tools/read-many-files.js.map +1 -0
  323. package/dist/tools/replace-lines.d.ts +3 -0
  324. package/dist/tools/replace-lines.d.ts.map +1 -0
  325. package/dist/tools/replace-lines.js +220 -0
  326. package/dist/tools/replace-lines.js.map +1 -0
  327. package/dist/tools/tool-manager.d.ts +54 -0
  328. package/dist/tools/tool-manager.d.ts.map +1 -0
  329. package/dist/tools/tool-manager.js +108 -0
  330. package/dist/tools/tool-manager.js.map +1 -0
  331. package/dist/types/app.d.ts +46 -0
  332. package/dist/types/app.d.ts.map +1 -0
  333. package/dist/types/app.js +2 -0
  334. package/dist/types/app.js.map +1 -0
  335. package/dist/types/commands.d.ts +36 -0
  336. package/dist/types/commands.d.ts.map +1 -0
  337. package/dist/types/commands.js +2 -0
  338. package/dist/types/commands.js.map +1 -0
  339. package/dist/types/components.d.ts +87 -0
  340. package/dist/types/components.d.ts.map +1 -0
  341. package/dist/types/components.js +2 -0
  342. package/dist/types/components.js.map +1 -0
  343. package/dist/types/config.d.ts +35 -0
  344. package/dist/types/config.d.ts.map +1 -0
  345. package/dist/types/config.js +2 -0
  346. package/dist/types/config.js.map +1 -0
  347. package/dist/types/core.d.ts +57 -0
  348. package/dist/types/core.d.ts.map +1 -0
  349. package/dist/types/core.js +2 -0
  350. package/dist/types/core.js.map +1 -0
  351. package/dist/types/hooks.d.ts +26 -0
  352. package/dist/types/hooks.d.ts.map +1 -0
  353. package/dist/types/hooks.js +2 -0
  354. package/dist/types/hooks.js.map +1 -0
  355. package/dist/types/index.d.ts +11 -0
  356. package/dist/types/index.d.ts.map +1 -0
  357. package/dist/types/index.js +12 -0
  358. package/dist/types/index.js.map +1 -0
  359. package/dist/types/mcp.d.ts +19 -0
  360. package/dist/types/mcp.d.ts.map +1 -0
  361. package/dist/types/mcp.js +2 -0
  362. package/dist/types/mcp.js.map +1 -0
  363. package/dist/types/tools.d.ts +31 -0
  364. package/dist/types/tools.d.ts.map +1 -0
  365. package/dist/types/tools.js +2 -0
  366. package/dist/types/tools.js.map +1 -0
  367. package/dist/types/ui.d.ts +22 -0
  368. package/dist/types/ui.d.ts.map +1 -0
  369. package/dist/types/ui.js +2 -0
  370. package/dist/types/ui.js.map +1 -0
  371. package/dist/types/utils.d.ts +19 -0
  372. package/dist/types/utils.d.ts.map +1 -0
  373. package/dist/types/utils.js +2 -0
  374. package/dist/types/utils.js.map +1 -0
  375. package/dist/utils/message-queue.d.ts +8 -0
  376. package/dist/utils/message-queue.d.ts.map +1 -0
  377. package/dist/utils/message-queue.js +50 -0
  378. package/dist/utils/message-queue.js.map +1 -0
  379. package/dist/utils/programming-language-helper.d.ts +2 -0
  380. package/dist/utils/programming-language-helper.d.ts.map +1 -0
  381. package/dist/utils/programming-language-helper.js +32 -0
  382. package/dist/utils/programming-language-helper.js.map +1 -0
  383. package/dist/utils/prompt-processor.d.ts +6 -0
  384. package/dist/utils/prompt-processor.d.ts.map +1 -0
  385. package/dist/utils/prompt-processor.js +103 -0
  386. package/dist/utils/prompt-processor.js.map +1 -0
  387. package/dist/utils/update-checker.d.ts +6 -0
  388. package/dist/utils/update-checker.d.ts.map +1 -0
  389. package/dist/utils/update-checker.js +120 -0
  390. package/dist/utils/update-checker.js.map +1 -0
  391. package/package.json +97 -0
  392. package/source/app/prompts/main-prompt.md +107 -0
@@ -0,0 +1,77 @@
1
+ import { useState, useEffect, useCallback } from 'react';
2
+ import path from 'path';
3
+ import { loadPreferences, savePreferences } from '../../config/preferences.js';
4
+ import { logError } from '../../utils/message-queue.js';
5
+ import { shouldLog } from '../../config/logging.js';
6
+ /**
7
+ * Custom hook for managing directory trust functionality.
8
+ * Handles checking if a directory is trusted and adding it to trusted directories.
9
+ *
10
+ * @param directory - The directory path to check trust for (defaults to current working directory)
11
+ * @returns Object containing trust state and handler functions
12
+ */
13
+ export function useDirectoryTrust(directory = process.cwd()) {
14
+ const [isTrusted, setIsTrusted] = useState(false);
15
+ const [isLoading, setIsLoading] = useState(true);
16
+ const [error, setError] = useState(null);
17
+ // Check if directory is trusted on mount and when directory changes
18
+ useEffect(() => {
19
+ const checkTrustStatus = async () => {
20
+ try {
21
+ setIsLoading(true);
22
+ setError(null);
23
+ const preferences = loadPreferences();
24
+ const trustedDirectories = preferences.trustedDirectories || [];
25
+ // Normalize paths for comparison (resolve any relative path components)
26
+ const normalizedDirectory = path.resolve(directory);
27
+ const isTrustedDir = trustedDirectories.some(trustedDir => path.resolve(trustedDir) === normalizedDirectory);
28
+ setIsTrusted(isTrustedDir);
29
+ }
30
+ catch (err) {
31
+ const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
32
+ setError(`Failed to check directory trust status: ${errorMessage}`);
33
+ if (shouldLog('warn')) {
34
+ logError(`useDirectoryTrust: ${errorMessage}`);
35
+ }
36
+ }
37
+ finally {
38
+ setIsLoading(false);
39
+ }
40
+ };
41
+ checkTrustStatus();
42
+ }, [directory]);
43
+ // Handler to confirm trust for the current directory
44
+ const handleConfirmTrust = useCallback(() => {
45
+ try {
46
+ setError(null);
47
+ const preferences = loadPreferences();
48
+ const trustedDirectories = preferences.trustedDirectories || [];
49
+ // Normalize the directory path before storing and checking
50
+ const normalizedDirectory = path.resolve(directory);
51
+ // Only add if not already trusted (check using normalized paths)
52
+ if (!trustedDirectories.some(trustedDir => path.resolve(trustedDir) === normalizedDirectory)) {
53
+ trustedDirectories.push(normalizedDirectory);
54
+ preferences.trustedDirectories = trustedDirectories;
55
+ savePreferences(preferences);
56
+ if (shouldLog('info')) {
57
+ logError(`useDirectoryTrust (info): Directory added to trusted list: ${normalizedDirectory}`);
58
+ }
59
+ }
60
+ setIsTrusted(true);
61
+ }
62
+ catch (err) {
63
+ const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
64
+ setError(`Failed to save directory trust: ${errorMessage}`);
65
+ if (shouldLog('warn')) {
66
+ logError(`useDirectoryTrust: ${errorMessage}`);
67
+ }
68
+ }
69
+ }, [directory]);
70
+ return {
71
+ isTrusted,
72
+ handleConfirmTrust,
73
+ isTrustLoading: isLoading,
74
+ isTrustedError: error,
75
+ };
76
+ }
77
+ //# sourceMappingURL=useDirectoryTrust.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDirectoryTrust.js","sourceRoot":"","sources":["../../../source/app/hooks/useDirectoryTrust.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAC,MAAM,OAAO,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAC,QAAQ,EAAC,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AASlD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAoB,OAAO,CAAC,GAAG,EAAE;IAC/D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAExD,oEAAoE;IACpE,SAAS,CAAC,GAAG,EAAE;QACX,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;YAChC,IAAI,CAAC;gBACD,YAAY,CAAC,IAAI,CAAC,CAAC;gBACnB,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAEf,MAAM,WAAW,GAAG,eAAe,EAAE,CAAC;gBACtC,MAAM,kBAAkB,GAAG,WAAW,CAAC,kBAAkB,IAAI,EAAE,CAAC;gBAEhE,wEAAwE;gBACxE,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,C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CAAC;gBACpD,eAAe,CAAC,WAAW,CAAC,CAAC;gBAE7B,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;oBACpB,QAAQ,CAAC,8DAA8D,mBAAmB,EAAE,CAAC,CAAC;gBAClG,CAAC;YACL,CAAC;YAED,YAAY,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,YAAY,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;YACnF,QAAQ,CAAC,mCAAmC,YAAY,EAAE,CAAC,CAAC;YAE5D,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpB,QAAQ,CAAC,sBAAsB,YAAY,EAAE,CAAC,CAAC;YACnD,CAAC;QACL,CAAC;IACL,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACH,SAAS;QACT,kBAAkB;QAClB,cAAc,EAAE,SAAS;QACzB,cAAc,EAAE,KAAK;KACxB,CAAC;AACN,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { LLMClient, Message, ProviderType } from '../../types/core.js';
2
+ import React from 'react';
3
+ import type { ThemePreset } from '../../types/ui.js';
4
+ interface UseModeHandlersProps {
5
+ client: LLMClient | null;
6
+ currentModel: string;
7
+ currentProvider: ProviderType;
8
+ setClient: (client: LLMClient | null) => void;
9
+ setCurrentModel: (model: string) => void;
10
+ setCurrentProvider: (provider: ProviderType) => void;
11
+ setCurrentTheme: (theme: ThemePreset) => void;
12
+ setMessages: (messages: Message[]) => void;
13
+ setIsModelSelectionMode: (mode: boolean) => void;
14
+ setIsProviderSelectionMode: (mode: boolean) => void;
15
+ setIsThemeSelectionMode: (mode: boolean) => void;
16
+ addToChatQueue: (component: React.ReactNode) => void;
17
+ componentKeyCounter: number;
18
+ }
19
+ export declare function useModeHandlers({ client, currentModel, currentProvider, setClient, setCurrentModel, setCurrentProvider, setCurrentTheme, setMessages, setIsModelSelectionMode, setIsProviderSelectionMode, setIsThemeSelectionMode, addToChatQueue, componentKeyCounter, }: UseModeHandlersProps): {
20
+ enterModelSelectionMode: () => void;
21
+ enterProviderSelectionMode: () => void;
22
+ enterThemeSelectionMode: () => void;
23
+ handleModelSelect: (selectedModel: string) => Promise<void>;
24
+ handleModelSelectionCancel: () => void;
25
+ handleProviderSelect: (selectedProvider: ProviderType) => Promise<void>;
26
+ handleProviderSelectionCancel: () => void;
27
+ handleThemeSelect: (selectedTheme: ThemePreset) => void;
28
+ handleThemeSelectionCancel: () => void;
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=useModeHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useModeHandlers.d.ts","sourceRoot":"","sources":["../../../source/app/hooks/useModeHandlers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAKrE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAEnD,UAAU,oBAAoB;IAC7B,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,YAAY,CAAC;IAC9B,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IACrD,eAAe,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC9C,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3C,uBAAuB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,0BAA0B,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,uBAAuB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,cAAc,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;IACrD,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,eAAe,CAAC,EAC/B,MAAM,EACN,YAAY,EACZ,eAAe,EACf,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,0BAA0B,EAC1B,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACnB,EAAE,oBAAoB;;;;uCAa0B,MAAM;;6CA0BA,YAAY;;uCAoExB,WAAW;;EAoCrD"}
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createLLMClient } from '../../client-factory.js';
3
+ import { updateLastUsed, savePreferences, loadPreferences } from '../../config/preferences.js';
4
+ import SuccessMessage from '../../components/success-message.js';
5
+ import ErrorMessage from '../../components/error-message.js';
6
+ export function useModeHandlers({ client, currentModel, currentProvider, setClient, setCurrentModel, setCurrentProvider, setCurrentTheme, setMessages, setIsModelSelectionMode, setIsProviderSelectionMode, setIsThemeSelectionMode, addToChatQueue, componentKeyCounter, }) {
7
+ // Helper function to enter model selection mode
8
+ const enterModelSelectionMode = () => {
9
+ setIsModelSelectionMode(true);
10
+ };
11
+ // Helper function to enter provider selection mode
12
+ const enterProviderSelectionMode = () => {
13
+ setIsProviderSelectionMode(true);
14
+ };
15
+ // Handle model selection
16
+ const handleModelSelect = async (selectedModel) => {
17
+ if (client && selectedModel !== currentModel) {
18
+ client.setModel(selectedModel);
19
+ setCurrentModel(selectedModel);
20
+ // Update preferences
21
+ updateLastUsed(currentProvider, selectedModel);
22
+ // Add success message to chat queue
23
+ addToChatQueue(_jsx(SuccessMessage, { message: `Model changed to: ${selectedModel}`, hideBox: true }, `model-changed-${componentKeyCounter}`));
24
+ }
25
+ setIsModelSelectionMode(false);
26
+ };
27
+ // Handle model selection cancel
28
+ const handleModelSelectionCancel = () => {
29
+ setIsModelSelectionMode(false);
30
+ };
31
+ // Handle provider selection
32
+ const handleProviderSelect = async (selectedProvider) => {
33
+ if (selectedProvider !== currentProvider) {
34
+ try {
35
+ // Create new client for the selected provider
36
+ const { client: newClient, actualProvider } = await createLLMClient(selectedProvider);
37
+ // Check if we got the provider we requested
38
+ if (actualProvider !== selectedProvider) {
39
+ // Provider was forced to a different one (likely due to missing config)
40
+ addToChatQueue(_jsx(ErrorMessage, { message: `${selectedProvider} is not available. Please ensure it's properly configured in agents.config.json.`, hideBox: true }, `provider-forced-${componentKeyCounter}`));
41
+ return; // Don't change anything
42
+ }
43
+ setClient(newClient);
44
+ setCurrentProvider(actualProvider);
45
+ // Set the model from the new client
46
+ const newModel = newClient.getCurrentModel();
47
+ setCurrentModel(newModel);
48
+ // Clear message history when switching providers
49
+ setMessages([]);
50
+ await newClient.clearContext();
51
+ // Update preferences - use the actualProvider (which is what was successfully created)
52
+ updateLastUsed(actualProvider, newModel);
53
+ // Add success message to chat queue
54
+ addToChatQueue(_jsx(SuccessMessage, { message: `Provider changed to: ${actualProvider}, model: ${newModel}. Chat history cleared.`, hideBox: true }, `provider-changed-${componentKeyCounter}`));
55
+ }
56
+ catch (error) {
57
+ // Add error message if provider change fails
58
+ addToChatQueue(_jsx(ErrorMessage, { message: `Failed to change provider to ${selectedProvider}: ${error}`, hideBox: true }, `provider-error-${componentKeyCounter}`));
59
+ }
60
+ }
61
+ setIsProviderSelectionMode(false);
62
+ };
63
+ // Handle provider selection cancel
64
+ const handleProviderSelectionCancel = () => {
65
+ setIsProviderSelectionMode(false);
66
+ };
67
+ // Helper function to enter theme selection mode
68
+ const enterThemeSelectionMode = () => {
69
+ setIsThemeSelectionMode(true);
70
+ };
71
+ // Handle theme selection
72
+ const handleThemeSelect = (selectedTheme) => {
73
+ const preferences = loadPreferences();
74
+ preferences.selectedTheme = selectedTheme;
75
+ savePreferences(preferences);
76
+ // Update the theme state immediately for real-time switching
77
+ setCurrentTheme(selectedTheme);
78
+ // Add success message to chat queue
79
+ addToChatQueue(_jsx(SuccessMessage, { message: `Theme changed to: ${selectedTheme}.`, hideBox: true }, `theme-changed-${componentKeyCounter}`));
80
+ setIsThemeSelectionMode(false);
81
+ };
82
+ // Handle theme selection cancel
83
+ const handleThemeSelectionCancel = () => {
84
+ setIsThemeSelectionMode(false);
85
+ };
86
+ return {
87
+ enterModelSelectionMode,
88
+ enterProviderSelectionMode,
89
+ enterThemeSelectionMode,
90
+ handleModelSelect,
91
+ handleModelSelectionCancel,
92
+ handleProviderSelect,
93
+ handleProviderSelectionCancel,
94
+ handleThemeSelect,
95
+ handleThemeSelectionCancel,
96
+ };
97
+ }
98
+ //# sourceMappingURL=useModeHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useModeHandlers.js","sourceRoot":"","sources":["../../../source/app/hooks/useModeHandlers.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAC,cAAc,EAAE,eAAe,EAAE,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC7F,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,YAAY,MAAM,mCAAmC,CAAC;AAoB7D,MAAM,UAAU,eAAe,CAAC,EAC/B,MAAM,EACN,YAAY,EACZ,eAAe,EACf,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,0BAA0B,EAC1B,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACG;IAEtB,gDAAgD;IAChD,MAAM,uBAAuB,GAAG,GAAG,EAAE;QACpC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,mDAAmD;IACnD,MAAM,0BAA0B,GAAG,GAAG,EAAE;QACvC,0BAA0B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QACpC,cAAc,CACb,KAAC,cAAc,IAEd,OAAO,EAAE,qBAAqB,aAAa,GAAG,EAC9C,OAAO,EAAE,IAAI,IAFR,iBAAiB,mBAAmB,EAAE,CAG1C,CACF,CAAC;QAEF,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,gCAAgC;IAChC,MAAM,0BAA0B,GAAG,GAAG,EAAE;QACvC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO;QACN,uBAAuB;QACvB,0BAA0B;QAC1B,uBAAuB;QACvB,iBAAiB;QACjB,0BAA0B;QAC1B,oBAAoB;QACpB,6BAA6B;QAC7B,iBAAiB;QACjB,0BAA0B;KAC1B,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { Message, LLMClient, ProviderType } from '../../types/core.js';
2
+ import { ConversationContext } from './useAppState.js';
3
+ import React from 'react';
4
+ interface UseToolHandlerProps {
5
+ pendingToolCalls: any[];
6
+ currentToolIndex: number;
7
+ completedToolResults: any[];
8
+ currentConversationContext: ConversationContext | null;
9
+ setPendingToolCalls: (calls: any[]) => void;
10
+ setCurrentToolIndex: (index: number) => void;
11
+ setCompletedToolResults: (results: any[]) => void;
12
+ setCurrentConversationContext: (context: ConversationContext | null) => void;
13
+ setIsToolConfirmationMode: (mode: boolean) => void;
14
+ setIsToolExecuting: (executing: boolean) => void;
15
+ setMessages: (messages: Message[]) => void;
16
+ addToChatQueue: (component: React.ReactNode) => void;
17
+ componentKeyCounter: number;
18
+ resetToolConfirmationState: () => void;
19
+ onProcessAssistantResponse: (systemMessage: Message, messages: Message[]) => Promise<void>;
20
+ client?: LLMClient | null;
21
+ currentProvider?: ProviderType;
22
+ }
23
+ export declare function useToolHandler({ pendingToolCalls, currentToolIndex, completedToolResults, currentConversationContext, setPendingToolCalls, setCurrentToolIndex, setCompletedToolResults, setCurrentConversationContext, setIsToolConfirmationMode, setIsToolExecuting, setMessages, addToChatQueue, componentKeyCounter, resetToolConfirmationState, onProcessAssistantResponse, client, currentProvider, }: UseToolHandlerProps): {
24
+ handleToolConfirmation: (confirmed: boolean) => Promise<void>;
25
+ handleToolConfirmationCancel: () => void;
26
+ startToolConfirmationFlow: (toolCalls: any[], updatedMessages: Message[], assistantMsg: Message, systemMessage: Message) => void;
27
+ displayToolResult: (toolCall: any, result: any) => Promise<void>;
28
+ continueConversationWithToolResults: (toolResults?: any[]) => Promise<void>;
29
+ executeCurrentTool: () => Promise<void>;
30
+ };
31
+ export {};
32
+ //# sourceMappingURL=useToolHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolHandler.d.ts","sourceRoot":"","sources":["../../../source/app/hooks/useToolHandler.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAIrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,mBAAmB;IAC5B,gBAAgB,EAAE,GAAG,EAAE,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,GAAG,EAAE,CAAC;IAC5B,0BAA0B,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACvD,mBAAmB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC5C,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,uBAAuB,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAClD,6BAA6B,EAAE,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,KAAK,IAAI,CAAC;IAC7E,yBAAyB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD,kBAAkB,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3C,cAAc,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;IACrD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,0BAA0B,EAAE,MAAM,IAAI,CAAC;IACvC,0BAA0B,EAAE,CAC3B,aAAa,EAAE,OAAO,EACtB,QAAQ,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,EAAE,YAAY,CAAC;CAC/B;AAED,wBAAgB,cAAc,CAAC,EAC9B,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,MAAM,EACN,eAAe,GACf,EAAE,mBAAmB;wCAyG4B,OAAO;;2CAyF5C,GAAG,EAAE,mBACC,OAAO,EAAE,gBACZ,OAAO,iBACN,OAAO;kCAlMoB,GAAG,UAAU,GAAG;wDAgEM,GAAG,EAAE;;EAuJtE"}
@@ -0,0 +1,154 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { processToolUse, getToolManager } from '../../message-handler.js';
3
+ import InfoMessage from '../../components/info-message.js';
4
+ import ErrorMessage from '../../components/error-message.js';
5
+ import ToolMessage from '../../components/tool-message.js';
6
+ import React from 'react';
7
+ export function useToolHandler({ pendingToolCalls, currentToolIndex, completedToolResults, currentConversationContext, setPendingToolCalls, setCurrentToolIndex, setCompletedToolResults, setCurrentConversationContext, setIsToolConfirmationMode, setIsToolExecuting, setMessages, addToChatQueue, componentKeyCounter, resetToolConfirmationState, onProcessAssistantResponse, client, currentProvider, }) {
8
+ // Display tool result with proper formatting
9
+ const displayToolResult = async (toolCall, result) => {
10
+ const toolManager = getToolManager();
11
+ if (toolManager) {
12
+ const formatter = toolManager.getToolFormatter(result.name);
13
+ if (formatter) {
14
+ try {
15
+ // Parse arguments if they're a JSON string
16
+ let parsedArgs = toolCall.function.arguments;
17
+ if (typeof parsedArgs === 'string') {
18
+ try {
19
+ parsedArgs = JSON.parse(parsedArgs);
20
+ }
21
+ catch (e) {
22
+ // If parsing fails, use as-is
23
+ }
24
+ }
25
+ const formattedResult = await formatter(parsedArgs, result.content);
26
+ if (React.isValidElement(formattedResult)) {
27
+ addToChatQueue(React.cloneElement(formattedResult, {
28
+ key: `tool-result-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`,
29
+ }));
30
+ }
31
+ else {
32
+ addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: String(formattedResult), hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`));
33
+ }
34
+ }
35
+ catch (formatterError) {
36
+ // If formatter fails, show raw result
37
+ addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: result.content, hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}`));
38
+ }
39
+ }
40
+ else {
41
+ // No formatter, show raw result
42
+ addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: result.content, hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}`));
43
+ }
44
+ }
45
+ };
46
+ // Continue conversation with tool results - maintains the proper loop
47
+ const continueConversationWithToolResults = async (toolResults) => {
48
+ if (!currentConversationContext) {
49
+ resetToolConfirmationState();
50
+ return;
51
+ }
52
+ // Use passed results or fallback to state (for backwards compatibility)
53
+ const resultsToUse = toolResults || completedToolResults;
54
+ const { updatedMessages, assistantMsg, systemMessage } = currentConversationContext;
55
+ // Format tool results as standard tool messages
56
+ const toolMessages = resultsToUse.map(result => ({
57
+ role: 'tool',
58
+ content: result.content || '',
59
+ tool_call_id: result.tool_call_id,
60
+ name: result.name,
61
+ }));
62
+ // Update conversation history with tool results
63
+ // The assistantMsg is NOT included in updatedMessages (updatedMessages is the state before adding assistantMsg)
64
+ // We need to add both the assistant message and the tool results
65
+ const updatedMessagesWithTools = [
66
+ ...updatedMessages,
67
+ assistantMsg, // Add the assistant message with tool_calls intact for proper tool_call_id matching
68
+ ...toolMessages,
69
+ ];
70
+ setMessages(updatedMessagesWithTools);
71
+ // Reset tool confirmation state since we're continuing the conversation
72
+ resetToolConfirmationState();
73
+ // Continue the main conversation loop with tool results as context
74
+ await onProcessAssistantResponse(systemMessage, updatedMessagesWithTools);
75
+ };
76
+ // Handle tool confirmation
77
+ const handleToolConfirmation = async (confirmed) => {
78
+ if (!confirmed) {
79
+ // User cancelled - show message and reset state
80
+ addToChatQueue(_jsx(InfoMessage, { message: "Tool execution cancelled by user", hideBox: true }, `tool-cancelled-${componentKeyCounter}`));
81
+ resetToolConfirmationState();
82
+ return;
83
+ }
84
+ // Move to tool execution state - this allows UI to update immediately
85
+ setIsToolConfirmationMode(false);
86
+ setIsToolExecuting(true);
87
+ // Execute tools asynchronously
88
+ setImmediate(() => {
89
+ executeCurrentTool();
90
+ });
91
+ };
92
+ // Execute the current tool asynchronously
93
+ const executeCurrentTool = async () => {
94
+ const currentTool = pendingToolCalls[currentToolIndex];
95
+ // Check if this is an MCP tool and show appropriate messaging
96
+ const toolManager = getToolManager();
97
+ if (toolManager) {
98
+ const mcpInfo = toolManager.getMCPToolInfo(currentTool.function.name);
99
+ if (mcpInfo.isMCPTool) {
100
+ addToChatQueue(_jsx(InfoMessage, { message: `Executing MCP tool "${currentTool.function.name}" from server "${mcpInfo.serverName}"`, hideBox: true }, `mcp-tool-executing-${componentKeyCounter}-${Date.now()}`));
101
+ }
102
+ }
103
+ try {
104
+ const result = await processToolUse(currentTool);
105
+ const newResults = [...completedToolResults, result];
106
+ setCompletedToolResults(newResults);
107
+ // Display the tool result
108
+ await displayToolResult(currentTool, result);
109
+ // Move to next tool or complete the process
110
+ if (currentToolIndex + 1 < pendingToolCalls.length) {
111
+ setCurrentToolIndex(currentToolIndex + 1);
112
+ // Return to confirmation mode for next tool
113
+ setIsToolExecuting(false);
114
+ setIsToolConfirmationMode(true);
115
+ }
116
+ else {
117
+ // All tools executed, continue conversation loop with the updated results
118
+ setIsToolExecuting(false);
119
+ await continueConversationWithToolResults(newResults);
120
+ }
121
+ }
122
+ catch (error) {
123
+ setIsToolExecuting(false);
124
+ addToChatQueue(_jsx(ErrorMessage, { message: `Tool execution error: ${error}` }, `tool-exec-error-${componentKeyCounter}`));
125
+ resetToolConfirmationState();
126
+ }
127
+ };
128
+ // Handle tool confirmation cancel
129
+ const handleToolConfirmationCancel = () => {
130
+ addToChatQueue(_jsx(InfoMessage, { message: "Tool execution cancelled by user", hideBox: true }, `tool-cancelled-${componentKeyCounter}`));
131
+ resetToolConfirmationState();
132
+ };
133
+ // Start tool confirmation flow
134
+ const startToolConfirmationFlow = (toolCalls, updatedMessages, assistantMsg, systemMessage) => {
135
+ setPendingToolCalls(toolCalls);
136
+ setCurrentToolIndex(0);
137
+ setCompletedToolResults([]);
138
+ setCurrentConversationContext({
139
+ updatedMessages,
140
+ assistantMsg,
141
+ systemMessage,
142
+ });
143
+ setIsToolConfirmationMode(true);
144
+ };
145
+ return {
146
+ handleToolConfirmation,
147
+ handleToolConfirmationCancel,
148
+ startToolConfirmationFlow,
149
+ displayToolResult,
150
+ continueConversationWithToolResults,
151
+ executeCurrentTool,
152
+ };
153
+ }
154
+ //# sourceMappingURL=useToolHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToolHandler.js","sourceRoot":"","sources":["../../../source/app/hooks/useToolHandler.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAExE,OAAO,WAAW,MAAM,kCAAkC,CAAC;AAC3D,OAAO,YAAY,MAAM,mCAAmC,CAAC;AAC7D,OAAO,WAAW,MAAM,kC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AAC;IAEF,kCAAkC;IAClC,MAAM,4BAA4B,GAAG,GAAG,EAAE;QACzC,cAAc,CACb,KAAC,WAAW,IAEX,OAAO,EAAC,kCAAkC,EAC1C,OAAO,EAAE,IAAI,IAFR,kBAAkB,mBAAmB,EAAE,CAG3C,CACF,CAAC;QACF,0BAA0B,EAAE,CAAC;IAC9B,CAAC,CAAC;IAEF,+BAA+B;IAC/B,MAAM,yBAAyB,GAAG,CACjC,SAAgB,EAChB,eAA0B,EAC1B,YAAqB,EACrB,aAAsB,EACrB,EAAE;QACH,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC/B,mBAAmB,CAAC,CAAC,CAAC,CAAC;QACvB,uBAAuB,CAAC,EAAE,CAAC,CAAC;QAC5B,6BAA6B,CAAC;YAC7B,eAAe;YACf,YAAY;YACZ,aAAa;SACb,CAAC,CAAC;QACH,yBAAyB,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,OAAO;QACN,sBAAsB;QACtB,4BAA4B;QAC5B,yBAAyB;QACzB,iBAAiB;QACjB,mCAAmC;QACnC,kBAAkB;KAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MessageSubmissionOptions } from '../../types/index.js';
2
+ export declare function handleMessageSubmission(message: string, options: MessageSubmissionOptions): Promise<void>;
3
+ export declare function createClearMessagesHandler(setMessages: (messages: any[]) => void, client: any): () => Promise<void>;
4
+ //# sourceMappingURL=appUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appUtils.d.ts","sourceRoot":"","sources":["../../../source/app/utils/appUtils.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,sBAAsB,CAAC;AAEnE,wBAAsB,uBAAuB,CAC5C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,wBAAwB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAyKf;AAED,wBAAgB,0BAA0B,CACzC,WAAW,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,IAAI,EACtC,MAAM,EAAE,GAAG,uBASX"}
@@ -0,0 +1,147 @@
1
+ import React from 'react';
2
+ import { commandRegistry } from '../../commands.js';
3
+ import { parseInput } from '../../command-parser.js';
4
+ import { toolRegistry } from '../../tools/index.js';
5
+ import InfoMessage from '../../components/info-message.js';
6
+ import ToolMessage from '../../components/tool-message.js';
7
+ import ErrorMessage from '../../components/error-message.js';
8
+ export async function handleMessageSubmission(message, options) {
9
+ const { customCommandCache, customCommandLoader, customCommandExecutor, onClearMessages, onEnterModelSelectionMode, onEnterProviderSelectionMode, onEnterThemeSelectionMode, onHandleChatMessage, onAddToChatQueue, componentKeyCounter, setMessages, messages, setIsBashExecuting, setCurrentBashCommand, } = options;
10
+ // Parse the input to determine its type
11
+ const parsedInput = parseInput(message);
12
+ // Handle bash commands (prefixed with !)
13
+ if (parsedInput.isBashCommand && parsedInput.bashCommand) {
14
+ const bashCommand = parsedInput.bashCommand;
15
+ // Set bash execution state to show spinner
16
+ setCurrentBashCommand(bashCommand);
17
+ setIsBashExecuting(true);
18
+ try {
19
+ // Execute the bash command
20
+ const resultString = await toolRegistry.execute_bash({
21
+ command: bashCommand,
22
+ });
23
+ // Parse the result
24
+ let result;
25
+ try {
26
+ result = JSON.parse(resultString);
27
+ }
28
+ catch (e) {
29
+ // If parsing fails, treat as plain string
30
+ result = {
31
+ fullOutput: resultString,
32
+ llmContext: resultString.length > 4000
33
+ ? resultString.substring(0, 4000)
34
+ : resultString,
35
+ };
36
+ }
37
+ // Create a proper display of the command and its full output
38
+ const commandOutput = `$ ${bashCommand}
39
+ ${result.fullOutput || '(No output)'}`;
40
+ // Add the command and its output to the chat queue
41
+ onAddToChatQueue(React.createElement(ToolMessage, {
42
+ key: `bash-result-${componentKeyCounter}`,
43
+ message: commandOutput,
44
+ hideBox: true,
45
+ isBashMode: true,
46
+ }));
47
+ // Add the truncated output to the LLM context for future interactions
48
+ if (result.llmContext) {
49
+ const toolMessage = {
50
+ role: 'tool',
51
+ content: result.llmContext,
52
+ name: 'execute_bash',
53
+ };
54
+ setMessages([...messages, toolMessage]);
55
+ }
56
+ // Clear bash execution state
57
+ setIsBashExecuting(false);
58
+ setCurrentBashCommand('');
59
+ return;
60
+ }
61
+ catch (error) {
62
+ // Show error message if command fails
63
+ onAddToChatQueue(React.createElement(ErrorMessage, {
64
+ key: `bash-error-${componentKeyCounter}`,
65
+ message: `Error executing command: ${error.message}`,
66
+ }));
67
+ // Clear bash execution state
68
+ setIsBashExecuting(false);
69
+ setCurrentBashCommand('');
70
+ // Don't send to LLM - just return here
71
+ return;
72
+ }
73
+ }
74
+ // Handle regular commands (prefixed with /)
75
+ if (message.startsWith('/')) {
76
+ const commandName = message.slice(1).split(' ')[0];
77
+ // Check for custom command first
78
+ const customCommand = customCommandCache.get(commandName) ||
79
+ customCommandLoader?.getCommand(commandName);
80
+ if (customCommand) {
81
+ // Execute custom command with any arguments
82
+ const args = message
83
+ .slice(commandName.length + 1)
84
+ .trim()
85
+ .split(/\s+/)
86
+ .filter(arg => arg);
87
+ const processedPrompt = await customCommandExecutor?.execute(customCommand, args);
88
+ // Send the processed prompt to the AI
89
+ if (processedPrompt) {
90
+ await onHandleChatMessage(processedPrompt);
91
+ }
92
+ }
93
+ else {
94
+ // Handle special commands that need app state access
95
+ if (commandName === 'clear') {
96
+ await onClearMessages();
97
+ // Still show the clear command result
98
+ }
99
+ else if (commandName === 'model') {
100
+ onEnterModelSelectionMode();
101
+ return;
102
+ }
103
+ else if (commandName === 'provider') {
104
+ onEnterProviderSelectionMode();
105
+ return;
106
+ }
107
+ else if (commandName === 'theme') {
108
+ onEnterThemeSelectionMode();
109
+ return;
110
+ }
111
+ // Execute built-in command
112
+ const totalTokens = messages.reduce((sum, msg) => sum + options.getMessageTokens(msg), 0);
113
+ const result = await commandRegistry.execute(message.slice(1), messages, {
114
+ provider: options.provider,
115
+ model: options.model,
116
+ tokens: totalTokens,
117
+ });
118
+ if (result) {
119
+ // Check if result is JSX (React element)
120
+ if (React.isValidElement(result)) {
121
+ onAddToChatQueue(result);
122
+ }
123
+ else if (typeof result === 'string' && result.trim()) {
124
+ onAddToChatQueue(React.createElement(InfoMessage, {
125
+ key: `command-result-${componentKeyCounter}`,
126
+ message: result,
127
+ hideBox: true,
128
+ }));
129
+ }
130
+ }
131
+ }
132
+ // Return here to avoid sending to LLM
133
+ return;
134
+ }
135
+ // Regular chat message - process with AI
136
+ await onHandleChatMessage(message);
137
+ }
138
+ export function createClearMessagesHandler(setMessages, client) {
139
+ return async () => {
140
+ // Clear message history and client context
141
+ setMessages([]);
142
+ if (client) {
143
+ await client.clearContext();
144
+ }
145
+ };
146
+ }
147
+ //# sourceMappingURL=appUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appUtils.js","sourceRoot":"","sources":["../../../source/app/utils/appUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAClD,OAAO,WAAW,MAAM,kCAAkC,CAAC;AAC3D,OAAO,WAAW,MAAM,kCAAkC,CAAC;AAC3D,OAAO,YAAY,MAAM,mCAAmC,CAAC;AAG7D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC5C,OAAe,EACf,OAAiC;IAEjC,MAAM,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC5B,yBAAyB,EACzB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,qBAAqB,GACrB,GAAG,OAAO,CAAC;IAEZ,wCAAwC;IACxC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAExC,yCAAyC;IACz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