@nanocollective/nanocoder 1.22.5 → 1.23.0

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 (296) hide show
  1. package/README.md +93 -30
  2. package/assets/nanocoder-vscode.vsix +0 -0
  3. package/dist/ai-sdk-client/chat/chat-handler.js +1 -1
  4. package/dist/ai-sdk-client/chat/chat-handler.js.map +1 -1
  5. package/dist/ai-sdk-client/chat/tool-processor.d.ts +1 -1
  6. package/dist/ai-sdk-client/chat/tool-processor.d.ts.map +1 -1
  7. package/dist/ai-sdk-client/chat/tool-processor.js +8 -3
  8. package/dist/ai-sdk-client/chat/tool-processor.js.map +1 -1
  9. package/dist/ai-sdk-client/error-handling/error-parser.d.ts.map +1 -1
  10. package/dist/ai-sdk-client/error-handling/error-parser.js +4 -1
  11. package/dist/ai-sdk-client/error-handling/error-parser.js.map +1 -1
  12. package/dist/app/App.d.ts.map +1 -1
  13. package/dist/app/App.js +106 -11
  14. package/dist/app/App.js.map +1 -1
  15. package/dist/app/components/chat-input.d.ts +6 -1
  16. package/dist/app/components/chat-input.d.ts.map +1 -1
  17. package/dist/app/components/chat-input.js +9 -7
  18. package/dist/app/components/chat-input.js.map +1 -1
  19. package/dist/app/utils/app-util.d.ts +5 -0
  20. package/dist/app/utils/app-util.d.ts.map +1 -1
  21. package/dist/app/utils/app-util.js +265 -0
  22. package/dist/app/utils/app-util.js.map +1 -1
  23. package/dist/client-factory.d.ts.map +1 -1
  24. package/dist/client-factory.js +3 -2
  25. package/dist/client-factory.js.map +1 -1
  26. package/dist/commands/context-max.d.ts +15 -0
  27. package/dist/commands/context-max.d.ts.map +1 -0
  28. package/dist/commands/context-max.js +22 -0
  29. package/dist/commands/context-max.js.map +1 -0
  30. package/dist/commands/custom-commands.d.ts.map +1 -1
  31. package/dist/commands/custom-commands.js +88 -4
  32. package/dist/commands/custom-commands.js.map +1 -1
  33. package/dist/commands/exit.d.ts.map +1 -1
  34. package/dist/commands/exit.js +5 -8
  35. package/dist/commands/exit.js.map +1 -1
  36. package/dist/commands/ide.d.ts +3 -0
  37. package/dist/commands/ide.d.ts.map +1 -0
  38. package/dist/commands/ide.js +10 -0
  39. package/dist/commands/ide.js.map +1 -0
  40. package/dist/commands/index.d.ts +3 -0
  41. package/dist/commands/index.d.ts.map +1 -1
  42. package/dist/commands/index.js +3 -0
  43. package/dist/commands/index.js.map +1 -1
  44. package/dist/commands/schedule.d.ts +3 -0
  45. package/dist/commands/schedule.d.ts.map +1 -0
  46. package/dist/commands/schedule.js +177 -0
  47. package/dist/commands/schedule.js.map +1 -0
  48. package/dist/commands/usage.d.ts.map +1 -1
  49. package/dist/commands/usage.js +4 -3
  50. package/dist/commands/usage.js.map +1 -1
  51. package/dist/components/development-mode-indicator.d.ts +3 -2
  52. package/dist/components/development-mode-indicator.d.ts.map +1 -1
  53. package/dist/components/development-mode-indicator.js +23 -9
  54. package/dist/components/development-mode-indicator.js.map +1 -1
  55. package/dist/components/ide-selector.d.ts +7 -0
  56. package/dist/components/ide-selector.d.ts.map +1 -0
  57. package/dist/components/ide-selector.js +17 -0
  58. package/dist/components/ide-selector.js.map +1 -0
  59. package/dist/components/question-prompt.d.ts +8 -0
  60. package/dist/components/question-prompt.d.ts.map +1 -0
  61. package/dist/components/question-prompt.js +58 -0
  62. package/dist/components/question-prompt.js.map +1 -0
  63. package/dist/components/scheduler-view.d.ts +14 -0
  64. package/dist/components/scheduler-view.d.ts.map +1 -0
  65. package/dist/components/scheduler-view.js +17 -0
  66. package/dist/components/scheduler-view.js.map +1 -0
  67. package/dist/components/text-input.d.ts +13 -0
  68. package/dist/components/text-input.d.ts.map +1 -0
  69. package/dist/components/text-input.js +175 -0
  70. package/dist/components/text-input.js.map +1 -0
  71. package/dist/components/user-input.d.ts +2 -1
  72. package/dist/components/user-input.d.ts.map +1 -1
  73. package/dist/components/user-input.js +8 -15
  74. package/dist/components/user-input.js.map +1 -1
  75. package/dist/config/themes.d.ts.map +1 -1
  76. package/dist/config/themes.js +20 -0
  77. package/dist/config/themes.js.map +1 -1
  78. package/dist/custom-commands/command-integration.d.ts +24 -0
  79. package/dist/custom-commands/command-integration.d.ts.map +1 -0
  80. package/dist/custom-commands/command-integration.js +68 -0
  81. package/dist/custom-commands/command-integration.js.map +1 -0
  82. package/dist/custom-commands/executor.d.ts.map +1 -1
  83. package/dist/custom-commands/executor.js +12 -2
  84. package/dist/custom-commands/executor.js.map +1 -1
  85. package/dist/custom-commands/loader.d.ts +33 -5
  86. package/dist/custom-commands/loader.d.ts.map +1 -1
  87. package/dist/custom-commands/loader.js +191 -18
  88. package/dist/custom-commands/loader.js.map +1 -1
  89. package/dist/custom-commands/parser.d.ts.map +1 -1
  90. package/dist/custom-commands/parser.js +115 -48
  91. package/dist/custom-commands/parser.js.map +1 -1
  92. package/dist/hooks/chat-handler/conversation/conversation-loop.d.ts +1 -1
  93. package/dist/hooks/chat-handler/conversation/conversation-loop.d.ts.map +1 -1
  94. package/dist/hooks/chat-handler/conversation/conversation-loop.js +37 -5
  95. package/dist/hooks/chat-handler/conversation/conversation-loop.js.map +1 -1
  96. package/dist/hooks/chat-handler/types.d.ts +3 -1
  97. package/dist/hooks/chat-handler/types.d.ts.map +1 -1
  98. package/dist/hooks/chat-handler/useChatHandler.d.ts +1 -1
  99. package/dist/hooks/chat-handler/useChatHandler.d.ts.map +1 -1
  100. package/dist/hooks/chat-handler/useChatHandler.js +13 -5
  101. package/dist/hooks/chat-handler/useChatHandler.js.map +1 -1
  102. package/dist/hooks/useAppHandlers.d.ts +2 -0
  103. package/dist/hooks/useAppHandlers.d.ts.map +1 -1
  104. package/dist/hooks/useAppHandlers.js +5 -0
  105. package/dist/hooks/useAppHandlers.js.map +1 -1
  106. package/dist/hooks/useAppInitialization.d.ts.map +1 -1
  107. package/dist/hooks/useAppInitialization.js +4 -1
  108. package/dist/hooks/useAppInitialization.js.map +1 -1
  109. package/dist/hooks/useAppState.d.ts +15 -0
  110. package/dist/hooks/useAppState.d.ts.map +1 -1
  111. package/dist/hooks/useAppState.js +23 -0
  112. package/dist/hooks/useAppState.js.map +1 -1
  113. package/dist/hooks/useContextPercentage.d.ts +17 -0
  114. package/dist/hooks/useContextPercentage.d.ts.map +1 -0
  115. package/dist/hooks/useContextPercentage.js +71 -0
  116. package/dist/hooks/useContextPercentage.js.map +1 -0
  117. package/dist/hooks/useModeHandlers.d.ts +4 -1
  118. package/dist/hooks/useModeHandlers.d.ts.map +1 -1
  119. package/dist/hooks/useModeHandlers.js +11 -1
  120. package/dist/hooks/useModeHandlers.js.map +1 -1
  121. package/dist/hooks/useNonInteractiveMode.d.ts.map +1 -1
  122. package/dist/hooks/useNonInteractiveMode.js +3 -1
  123. package/dist/hooks/useNonInteractiveMode.js.map +1 -1
  124. package/dist/hooks/useSchedulerMode.d.ts +30 -0
  125. package/dist/hooks/useSchedulerMode.d.ts.map +1 -0
  126. package/dist/hooks/useSchedulerMode.js +99 -0
  127. package/dist/hooks/useSchedulerMode.js.map +1 -0
  128. package/dist/lsp/lsp-manager.d.ts.map +1 -1
  129. package/dist/lsp/lsp-manager.js +10 -0
  130. package/dist/lsp/lsp-manager.js.map +1 -1
  131. package/dist/mcp/mcp-client.d.ts.map +1 -1
  132. package/dist/mcp/mcp-client.js +20 -1
  133. package/dist/mcp/mcp-client.js.map +1 -1
  134. package/dist/models/index.d.ts +1 -1
  135. package/dist/models/index.d.ts.map +1 -1
  136. package/dist/models/index.js +1 -1
  137. package/dist/models/index.js.map +1 -1
  138. package/dist/models/models-dev-client.d.ts +8 -1
  139. package/dist/models/models-dev-client.d.ts.map +1 -1
  140. package/dist/models/models-dev-client.js +50 -1
  141. package/dist/models/models-dev-client.js.map +1 -1
  142. package/dist/schedule/cron.d.ts +14 -0
  143. package/dist/schedule/cron.d.ts.map +1 -0
  144. package/dist/schedule/cron.js +107 -0
  145. package/dist/schedule/cron.js.map +1 -0
  146. package/dist/schedule/index.d.ts +4 -0
  147. package/dist/schedule/index.d.ts.map +1 -0
  148. package/dist/schedule/index.js +4 -0
  149. package/dist/schedule/index.js.map +1 -0
  150. package/dist/schedule/runner.d.ts +42 -0
  151. package/dist/schedule/runner.d.ts.map +1 -0
  152. package/dist/schedule/runner.js +136 -0
  153. package/dist/schedule/runner.js.map +1 -0
  154. package/dist/schedule/storage.d.ts +9 -0
  155. package/dist/schedule/storage.d.ts.map +1 -0
  156. package/dist/schedule/storage.js +68 -0
  157. package/dist/schedule/storage.js.map +1 -0
  158. package/dist/schedule/types.d.ts +24 -0
  159. package/dist/schedule/types.d.ts.map +1 -0
  160. package/dist/schedule/types.js +2 -0
  161. package/dist/schedule/types.js.map +1 -0
  162. package/dist/services/bash-executor.d.ts.map +1 -1
  163. package/dist/services/bash-executor.js +5 -0
  164. package/dist/services/bash-executor.js.map +1 -1
  165. package/dist/tool-calling/json-parser.d.ts +7 -3
  166. package/dist/tool-calling/json-parser.d.ts.map +1 -1
  167. package/dist/tool-calling/json-parser.js +30 -13
  168. package/dist/tool-calling/json-parser.js.map +1 -1
  169. package/dist/tool-calling/tool-parser.d.ts +2 -2
  170. package/dist/tool-calling/tool-parser.d.ts.map +1 -1
  171. package/dist/tool-calling/tool-parser.js +27 -23
  172. package/dist/tool-calling/tool-parser.js.map +1 -1
  173. package/dist/tool-calling/xml-parser.d.ts +8 -4
  174. package/dist/tool-calling/xml-parser.d.ts.map +1 -1
  175. package/dist/tool-calling/xml-parser.js +15 -5
  176. package/dist/tool-calling/xml-parser.js.map +1 -1
  177. package/dist/tools/ask-question.d.ts +3 -0
  178. package/dist/tools/ask-question.d.ts.map +1 -0
  179. package/dist/tools/ask-question.js +66 -0
  180. package/dist/tools/ask-question.js.map +1 -0
  181. package/dist/tools/execute-bash.js +1 -1
  182. package/dist/tools/execute-bash.js.map +1 -1
  183. package/dist/tools/file-ops/copy-file.d.ts +3 -0
  184. package/dist/tools/file-ops/copy-file.d.ts.map +1 -0
  185. package/dist/tools/file-ops/copy-file.js +126 -0
  186. package/dist/tools/file-ops/copy-file.js.map +1 -0
  187. package/dist/tools/file-ops/create-directory.d.ts +3 -0
  188. package/dist/tools/file-ops/create-directory.d.ts.map +1 -0
  189. package/dist/tools/file-ops/create-directory.js +76 -0
  190. package/dist/tools/file-ops/create-directory.js.map +1 -0
  191. package/dist/tools/file-ops/delete-file.d.ts +3 -0
  192. package/dist/tools/file-ops/delete-file.d.ts.map +1 -0
  193. package/dist/tools/file-ops/delete-file.js +88 -0
  194. package/dist/tools/file-ops/delete-file.js.map +1 -0
  195. package/dist/tools/file-ops/index.d.ts +3 -0
  196. package/dist/tools/file-ops/index.d.ts.map +1 -0
  197. package/dist/tools/file-ops/index.js +8 -0
  198. package/dist/tools/file-ops/index.js.map +1 -0
  199. package/dist/tools/file-ops/move-file.d.ts +3 -0
  200. package/dist/tools/file-ops/move-file.d.ts.map +1 -0
  201. package/dist/tools/file-ops/move-file.js +126 -0
  202. package/dist/tools/file-ops/move-file.js.map +1 -0
  203. package/dist/tools/file-ops/string-replace.d.ts +3 -0
  204. package/dist/tools/file-ops/string-replace.d.ts.map +1 -0
  205. package/dist/tools/{string-replace.js → file-ops/string-replace.js} +13 -13
  206. package/dist/tools/file-ops/string-replace.js.map +1 -0
  207. package/dist/tools/file-ops/write-file.d.ts +3 -0
  208. package/dist/tools/file-ops/write-file.d.ts.map +1 -0
  209. package/dist/tools/{write-file.js → file-ops/write-file.js} +31 -17
  210. package/dist/tools/file-ops/write-file.js.map +1 -0
  211. package/dist/tools/git/git-reset.js +1 -1
  212. package/dist/tools/git/git-reset.js.map +1 -1
  213. package/dist/tools/git/index.js +3 -3
  214. package/dist/tools/git/index.js.map +1 -1
  215. package/dist/tools/git/utils.d.ts +4 -0
  216. package/dist/tools/git/utils.d.ts.map +1 -1
  217. package/dist/tools/git/utils.js +12 -0
  218. package/dist/tools/git/utils.js.map +1 -1
  219. package/dist/tools/index.d.ts.map +1 -1
  220. package/dist/tools/index.js +8 -2
  221. package/dist/tools/index.js.map +1 -1
  222. package/dist/tools/search-file-contents.d.ts.map +1 -1
  223. package/dist/tools/search-file-contents.js +59 -10
  224. package/dist/tools/search-file-contents.js.map +1 -1
  225. package/dist/tools/tool-manager.d.ts.map +1 -1
  226. package/dist/tools/tool-manager.js +9 -0
  227. package/dist/tools/tool-manager.js.map +1 -1
  228. package/dist/types/app.d.ts +2 -0
  229. package/dist/types/app.d.ts.map +1 -1
  230. package/dist/types/commands.d.ts +20 -0
  231. package/dist/types/commands.d.ts.map +1 -1
  232. package/dist/types/core.d.ts +2 -1
  233. package/dist/types/core.d.ts.map +1 -1
  234. package/dist/types/core.js +7 -0
  235. package/dist/types/core.js.map +1 -1
  236. package/dist/types/ui.d.ts +1 -1
  237. package/dist/types/ui.d.ts.map +1 -1
  238. package/dist/utils/auto-compact.d.ts.map +1 -1
  239. package/dist/utils/auto-compact.js +13 -7
  240. package/dist/utils/auto-compact.js.map +1 -1
  241. package/dist/utils/logging/index.d.ts.map +1 -1
  242. package/dist/utils/logging/index.js +18 -30
  243. package/dist/utils/logging/index.js.map +1 -1
  244. package/dist/utils/question-queue.d.ts +15 -0
  245. package/dist/utils/question-queue.d.ts.map +1 -0
  246. package/dist/utils/question-queue.js +25 -0
  247. package/dist/utils/question-queue.js.map +1 -0
  248. package/dist/utils/response-formatter.d.ts +108 -0
  249. package/dist/utils/response-formatter.d.ts.map +1 -0
  250. package/dist/utils/response-formatter.js +387 -0
  251. package/dist/utils/response-formatter.js.map +1 -0
  252. package/dist/utils/shutdown/index.d.ts +7 -0
  253. package/dist/utils/shutdown/index.d.ts.map +1 -0
  254. package/dist/utils/shutdown/index.js +6 -0
  255. package/dist/utils/shutdown/index.js.map +1 -0
  256. package/dist/utils/shutdown/shutdown-manager.d.ts +19 -0
  257. package/dist/utils/shutdown/shutdown-manager.d.ts.map +1 -0
  258. package/dist/utils/shutdown/shutdown-manager.js +100 -0
  259. package/dist/utils/shutdown/shutdown-manager.js.map +1 -0
  260. package/dist/utils/shutdown/types.d.ts +9 -0
  261. package/dist/utils/shutdown/types.d.ts.map +1 -0
  262. package/dist/utils/shutdown/types.js +2 -0
  263. package/dist/utils/shutdown/types.js.map +1 -0
  264. package/dist/utils/type-helpers.d.ts +140 -0
  265. package/dist/utils/type-helpers.d.ts.map +1 -0
  266. package/dist/utils/type-helpers.js +220 -0
  267. package/dist/utils/type-helpers.js.map +1 -0
  268. package/dist/utils/url-utils.d.ts +6 -0
  269. package/dist/utils/url-utils.d.ts.map +1 -0
  270. package/dist/utils/url-utils.js +22 -0
  271. package/dist/utils/url-utils.js.map +1 -0
  272. package/dist/vscode/vscode-server.d.ts.map +1 -1
  273. package/dist/vscode/vscode-server.js +10 -0
  274. package/dist/vscode/vscode-server.js.map +1 -1
  275. package/dist/wizards/steps/mcp-step.js +1 -1
  276. package/dist/wizards/steps/mcp-step.js.map +1 -1
  277. package/dist/wizards/steps/provider-step.js +1 -1
  278. package/dist/wizards/steps/provider-step.js.map +1 -1
  279. package/dist/wizards/templates/mcp-templates.d.ts.map +1 -1
  280. package/dist/wizards/templates/mcp-templates.js +8 -6
  281. package/dist/wizards/templates/mcp-templates.js.map +1 -1
  282. package/dist/wizards/validation.d.ts.map +1 -1
  283. package/dist/wizards/validation.js +2 -3
  284. package/dist/wizards/validation.js.map +1 -1
  285. package/package.json +8 -17
  286. package/source/app/prompts/main-prompt.md +21 -3
  287. package/dist/hooks/chat-handler/utils/context-checker.d.ts +0 -15
  288. package/dist/hooks/chat-handler/utils/context-checker.d.ts.map +0 -1
  289. package/dist/hooks/chat-handler/utils/context-checker.js +0 -68
  290. package/dist/hooks/chat-handler/utils/context-checker.js.map +0 -1
  291. package/dist/tools/string-replace.d.ts +0 -3
  292. package/dist/tools/string-replace.d.ts.map +0 -1
  293. package/dist/tools/string-replace.js.map +0 -1
  294. package/dist/tools/write-file.d.ts +0 -3
  295. package/dist/tools/write-file.d.ts.map +0 -1
  296. package/dist/tools/write-file.js.map +0 -1
@@ -0,0 +1,15 @@
1
+ export interface PendingQuestion {
2
+ question: string;
3
+ options: string[];
4
+ allowFreeform: boolean;
5
+ }
6
+ /**
7
+ * Called once from App.tsx to wire up the UI handler.
8
+ */
9
+ export declare function setGlobalQuestionHandler(handler: (question: PendingQuestion) => Promise<string>): void;
10
+ /**
11
+ * Called from the ask_question tool's execute function.
12
+ * Returns a Promise that resolves with the user's answer string.
13
+ */
14
+ export declare function signalQuestion(question: PendingQuestion): Promise<string>;
15
+ //# sourceMappingURL=question-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-queue.d.ts","sourceRoot":"","sources":["../../source/utils/question-queue.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACvB;AAQD;;GAEG;AACH,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,QAGvD;AAED;;;GAGG;AACH,wBAAsB,cAAc,CACnC,QAAQ,EAAE,eAAe,GACvB,OAAO,CAAC,MAAM,CAAC,CAKjB"}
@@ -0,0 +1,25 @@
1
+ // Global question queue - allows the ask_question tool to present
2
+ // interactive questions to the user via the UI.
3
+ //
4
+ // Pattern mirrors message-queue.tsx: a module-level singleton handler
5
+ // set by App.tsx, called from the tool's execute function.
6
+ // The handler set by App.tsx. It receives the question data and returns
7
+ // a Promise<string> that resolves when the user picks an answer.
8
+ let globalQuestionHandler = null;
9
+ /**
10
+ * Called once from App.tsx to wire up the UI handler.
11
+ */
12
+ export function setGlobalQuestionHandler(handler) {
13
+ globalQuestionHandler = handler;
14
+ }
15
+ /**
16
+ * Called from the ask_question tool's execute function.
17
+ * Returns a Promise that resolves with the user's answer string.
18
+ */
19
+ export async function signalQuestion(question) {
20
+ if (!globalQuestionHandler) {
21
+ return 'Error: Question handler not initialized. The UI is not ready to accept questions.';
22
+ }
23
+ return globalQuestionHandler(question);
24
+ }
25
+ //# sourceMappingURL=question-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-queue.js","sourceRoot":"","sources":["../../source/utils/question-queue.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,2DAA2D;AAQ3D,wEAAwE;AACxE,iEAAiE;AACjE,IAAI,qBAAqB,GAEf,IAAI,CAAC;AAEf;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACvC,OAAuD;IAEvD,qBAAqB,GAAG,OAAO,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,QAAyB;IAEzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC5B,OAAO,mFAAmF,CAAC;IAC5F,CAAC;IACD,OAAO,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * TYPE PRESERVATION STRATEGY EXPLAINED
3
+ * =====================================
4
+ *
5
+ * "Preserving types" does NOT mean keeping everything as objects/arrays in memory.
6
+ * It means:
7
+ *
8
+ * 1. When receiving LLM responses (which can be ANY type):
9
+ * - We accept unknown types (string, object, array, null, undefined)
10
+ * - We convert to string ONLY for PARSING OPERATIONS
11
+ * - We preserve the original type in the tool call structure
12
+ *
13
+ * 2. When storing ToolCall.arguments:
14
+ * - MUST preserve as Record<string, unknown> (object type)
15
+ * - NOT convert to string
16
+ * - Enables direct property access without JSON.parse
17
+ *
18
+ * 3. When displaying/writing to disk:
19
+ * - Convert to string for display/storage operations
20
+ * - Use JSON.stringify for objects/arrays
21
+ * - Use String() for primitives
22
+ *
23
+ * The confusion comes from mixing up:
24
+ * - "Preserve types in memory" (CRITICAL: ToolCall.arguments stays as object)
25
+ * - "Convert to string for processing" (NECESSARY: Parser expects strings)
26
+ *
27
+ * This formatter handles the INCOMING data, then the parser handles the
28
+ * conversion to ToolCall format with type preservation.
29
+ */
30
+ import type { ToolCall } from '../types/index.js';
31
+ /**
32
+ * Result of normalizing an LLM response
33
+ * Contains the raw response, processed content, extracted tool calls, and metadata
34
+ */
35
+ export interface NormalizedResponse {
36
+ /** The original response from the LLM (unknown type for maximum flexibility) */
37
+ raw: unknown;
38
+ /** The content after normalization (always a string for parsing) */
39
+ content: string;
40
+ /** Any tool calls extracted during normalization */
41
+ toolCalls: ToolCall[];
42
+ /** Metadata about the response for debugging and strategy selection */
43
+ metadata: ResponseMetadata;
44
+ }
45
+ /**
46
+ * Metadata about the normalized response
47
+ * Used for:
48
+ * - Debugging and logging
49
+ * - Selecting the best parsing strategy
50
+ * - Error handling and recovery
51
+ */
52
+ export interface ResponseMetadata {
53
+ /** Whether response contained markdown code blocks */
54
+ hasCodeBlocks: boolean;
55
+ /** Whether response contained XML tags */
56
+ hasXMLTags: boolean;
57
+ /** Whether response contained JSON tool call structures */
58
+ hasJSONBlocks: boolean;
59
+ /** Confidence level in the response type classification */
60
+ confidence: 'high' | 'medium' | 'low';
61
+ /** Detected response format */
62
+ detectedFormat: 'plain' | 'json' | 'xml' | 'mixed' | 'unknown';
63
+ /** Whether response appears to be malformed */
64
+ isMalformed: boolean;
65
+ /** Detected error if malformed */
66
+ malformedError?: string;
67
+ }
68
+ /**
69
+ * Main entry point for normalizing LLM responses
70
+ *
71
+ * This function handles all possible LLM response types:
72
+ * - Plain strings (most common)
73
+ * - JSON objects (with/without tool_calls field)
74
+ * - Arrays (line-based content)
75
+ * - Null/undefined (error responses)
76
+ * - Mixed content (text + tool calls embedded)
77
+ *
78
+ * @param response - The raw response from the LLM (can be any type)
79
+ * @param options - Configuration options
80
+ * @returns A normalized response with content and extracted tool calls
81
+ */
82
+ export declare function normalizeLLMResponse(response: unknown, options?: NormalizeOptions): Promise<NormalizedResponse>;
83
+ /**
84
+ * Formats a normalized response for debugging
85
+ *
86
+ * @param response - Normalized response to format
87
+ * @returns Formatted string for debugging
88
+ */
89
+ export declare function formatNormalizedResponse(response: NormalizedResponse): string;
90
+ /**
91
+ * Checks if a response is complete and ready for processing
92
+ *
93
+ * A response is complete if:
94
+ * 1. It has content
95
+ * 2. It has low confidence (means no tool calls were found, so no further processing needed)
96
+ * 3. It's not malformed
97
+ *
98
+ * @param response - Normalized response to check
99
+ * @returns True if response is complete
100
+ */
101
+ export declare function isResponseComplete(response: NormalizedResponse): boolean;
102
+ export interface NormalizeOptions {
103
+ /** If true, keeps the raw object structure instead of JSON.stringify */
104
+ preserveRawTypes?: boolean;
105
+ /** If true, extracts tool calls from mixed content (text + tool calls) */
106
+ allowMixedContent?: boolean;
107
+ }
108
+ //# sourceMappingURL=response-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-formatter.d.ts","sourceRoot":"","sources":["../../source/utils/response-formatter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAM5C;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,gFAAgF;IAChF,GAAG,EAAE,OAAO,CAAC;IAEb,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAEhB,oDAAoD;IACpD,SAAS,EAAE,QAAQ,EAAE,CAAC;IAEtB,uEAAuE;IACvE,QAAQ,EAAE,gBAAgB,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,sDAAsD;IACtD,aAAa,EAAE,OAAO,CAAC;IAEvB,0CAA0C;IAC1C,UAAU,EAAE,OAAO,CAAC;IAEpB,2DAA2D;IAC3D,aAAa,EAAE,OAAO,CAAC;IAEvB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IAEtC,+BAA+B;IAC/B,cAAc,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;IAE/D,+CAA+C;IAC/C,WAAW,EAAE,OAAO,CAAC;IAErB,kCAAkC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,gBAAqB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CA4C7B;AAuVD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CA0B7E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAOxE;AAMD,MAAM,WAAW,gBAAgB;IAChC,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,0EAA0E;IAC1E,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
@@ -0,0 +1,387 @@
1
+ // source/utils/response-formatter.ts
2
+ // ============================================================================
3
+ // NORMALIZATION FUNCTIONS
4
+ // ============================================================================
5
+ /**
6
+ * Main entry point for normalizing LLM responses
7
+ *
8
+ * This function handles all possible LLM response types:
9
+ * - Plain strings (most common)
10
+ * - JSON objects (with/without tool_calls field)
11
+ * - Arrays (line-based content)
12
+ * - Null/undefined (error responses)
13
+ * - Mixed content (text + tool calls embedded)
14
+ *
15
+ * @param response - The raw response from the LLM (can be any type)
16
+ * @param options - Configuration options
17
+ * @returns A normalized response with content and extracted tool calls
18
+ */
19
+ export async function normalizeLLMResponse(response, options = {}) {
20
+ const { preserveRawTypes = false, // If true, keeps object structure instead of JSON.stringify
21
+ allowMixedContent = true, // If true, extracts tool calls from mixed content
22
+ } = options;
23
+ // Step 1: Detect response type and convert to string for parsing
24
+ const { content, detectedFormat } = convertToProcessableString(response);
25
+ // Step 2: Extract tool calls from the content
26
+ const { toolCalls, malformedError } = await extractToolCalls(content, {
27
+ allowMixedContent,
28
+ detectedFormat,
29
+ });
30
+ // Step 3: Detect if response is malformed
31
+ const isMalformed = !toolCalls.length && hasMalformedPatterns(content);
32
+ // Step 4: Build metadata for debugging and strategy selection
33
+ // Check for JSON blocks in content - only match tool call patterns, not plain JSON objects
34
+ const hasCodeBlocks = /```/.test(content);
35
+ const hasJSONBlocks = /"name"\s*:\s*"[^"]+"\s*,\s*"arguments"\s*:\s*\{/.test(content);
36
+ const metadata = buildMetadata(content, {
37
+ hasCodeBlocks,
38
+ hasXMLTags: /<[^>]+>/.test(content),
39
+ hasJSONBlocks,
40
+ detectedFormat,
41
+ malformedError,
42
+ isMalformed,
43
+ }, toolCalls.length > 0);
44
+ return {
45
+ raw: preserveRawTypes ? response : undefined, // Only preserve if requested
46
+ content,
47
+ toolCalls,
48
+ metadata,
49
+ };
50
+ }
51
+ /**
52
+ * Converts any LLM response type to a string suitable for parsing
53
+ *
54
+ * Handles the following cases:
55
+ * 1. string → string (identity, already processable)
56
+ * 2. object → JSON.stringify (structured data)
57
+ * 3. array → JSON.stringify (array data)
58
+ * 4. null/undefined → empty string (error handling)
59
+ * 5. number/boolean → String() (primitive types)
60
+ *
61
+ * This conversion is NECESSARY because our parsers expect strings.
62
+ * The type preservation happens later in the ToolCall structure.
63
+ *
64
+ * @param response - Raw response from LLM (any type)
65
+ * @returns Object with processable string content and detected format
66
+ */
67
+ function convertToProcessableString(response) {
68
+ let content;
69
+ let detectedFormat = 'plain';
70
+ // CASE 1: Plain string response (most common)
71
+ if (typeof response === 'string') {
72
+ content = response.trim();
73
+ // Check if it looks like a JSON structure
74
+ if (content.startsWith('{') && content.endsWith('}')) {
75
+ detectedFormat = 'json';
76
+ // Don't JSON.stringify a string that's already JSON - just use it as-is
77
+ // The parser will parse it correctly
78
+ }
79
+ // Check if it looks like XML
80
+ else if (content.startsWith('<') && content.endsWith('>')) {
81
+ detectedFormat = 'xml';
82
+ // Don't JSON.stringify a string that's already XML - just use it as-is
83
+ // The parser will parse it correctly
84
+ }
85
+ // Check for mixed content (text + tool calls)
86
+ else if (hasEmbeddedToolCallPatterns(content)) {
87
+ detectedFormat = 'mixed';
88
+ // Don't JSON.stringify - keep as plain string for parser to handle
89
+ }
90
+ }
91
+ // CASE 2: JSON object response (structured data)
92
+ else if (response !== null && typeof response === 'object') {
93
+ // Check if it has a tool_calls field (AI SDK format)
94
+ if ('tool_calls' in response || 'function' in response) {
95
+ detectedFormat = 'json';
96
+ // If it's already structured, we might not need JSON.stringify
97
+ // But for consistency with parsers, we still convert to string
98
+ content = JSON.stringify(response);
99
+ }
100
+ // Regular object (not a tool_calls response)
101
+ else {
102
+ detectedFormat = 'json';
103
+ content = JSON.stringify(response);
104
+ }
105
+ }
106
+ // CASE 3: Array response (line-based content)
107
+ else if (Array.isArray(response)) {
108
+ detectedFormat = 'mixed';
109
+ content = response.join('\n').trim();
110
+ }
111
+ // CASE 4: Primitives (number, boolean, null, undefined)
112
+ else {
113
+ // Convert primitives to strings
114
+ content = String(response);
115
+ // Empty string if null or undefined
116
+ if (response === null || response === undefined) {
117
+ content = '';
118
+ }
119
+ }
120
+ return { content, detectedFormat };
121
+ }
122
+ /**
123
+ * Extracts tool calls from normalized content
124
+ *
125
+ * This function uses the unified parser to extract tool calls from:
126
+ * - Plain text with embedded JSON/XML tool calls
127
+ * - JSON objects with tool_calls field
128
+ * - Mixed content (text + tool calls)
129
+ *
130
+ * @param content - Normalized content string
131
+ * @param options - Extraction options
132
+ * @returns Object with extracted tool calls and any malformed error
133
+ */
134
+ async function extractToolCalls(content, options) {
135
+ const { allowMixedContent, detectedFormat } = options;
136
+ // If no content, no tool calls
137
+ if (!content) {
138
+ return { toolCalls: [] };
139
+ }
140
+ // CASE 1: Detected JSON format - try JSON parser
141
+ if (detectedFormat === 'json') {
142
+ try {
143
+ // Import here to avoid circular dependencies
144
+ const { parseJSONToolCalls } = await import('../tool-calling/json-parser.js');
145
+ const toolCalls = parseJSONToolCalls(content);
146
+ if (toolCalls.length > 0) {
147
+ return { toolCalls };
148
+ }
149
+ }
150
+ catch (error) {
151
+ // If JSON parsing fails, fall through to mixed content handling
152
+ console.warn('JSON parsing failed, trying mixed content:', error);
153
+ }
154
+ }
155
+ // CASE 2: Try XML parser
156
+ try {
157
+ const { XMLToolCallParser } = await import('../tool-calling/xml-parser.js');
158
+ // Check for malformed XML first
159
+ const malformedError = XMLToolCallParser.detectMalformedToolCall(content);
160
+ if (malformedError) {
161
+ return { toolCalls: [], malformedError: malformedError.error };
162
+ }
163
+ // Check if has XML tool calls
164
+ if (XMLToolCallParser.hasToolCalls(content)) {
165
+ const parsedCalls = XMLToolCallParser.parseToolCalls(content);
166
+ const toolCalls = XMLToolCallParser.convertToToolCalls(parsedCalls);
167
+ if (toolCalls.length > 0) {
168
+ return { toolCalls };
169
+ }
170
+ }
171
+ }
172
+ catch (error) {
173
+ // XML parsing failed, continue
174
+ console.warn('XML parsing failed:', error);
175
+ }
176
+ // CASE 3: Mixed content - use unified parser
177
+ if (allowMixedContent) {
178
+ try {
179
+ const { parseToolCalls } = await import('../tool-calling/tool-parser.js');
180
+ const result = parseToolCalls(content);
181
+ if (result.success && result.toolCalls.length > 0) {
182
+ return { toolCalls: result.toolCalls };
183
+ }
184
+ if (!result.success) {
185
+ return { toolCalls: [], malformedError: result.error };
186
+ }
187
+ }
188
+ catch (error) {
189
+ // Parsing failed, return empty tool calls
190
+ console.warn('Mixed content parsing failed:', error);
191
+ }
192
+ }
193
+ // No tool calls found
194
+ return { toolCalls: [] };
195
+ }
196
+ /**
197
+ * Detects if content contains malformed patterns
198
+ *
199
+ * Logic:
200
+ * 1. If it parses as valid JSON via try/catch, it is NOT malformed.
201
+ * 2. If parsing fails, check for known "broken tool call" signatures.
202
+ *
203
+ * @param content - Content to check
204
+ * @returns True if malformed patterns detected
205
+ */
206
+ function hasMalformedPatterns(content) {
207
+ const trimmed = content.trim();
208
+ // 1. Sanity Check: Empty content is not "malformed", just empty.
209
+ if (!trimmed) {
210
+ return false;
211
+ }
212
+ // 2. THE SAFETY CHECK: Trust the Runtime (JSON.parse)
213
+ // We check if it starts and ends with braces to identify it as a candidate for an Object.
214
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
215
+ try {
216
+ // CRASH PROTECTION: If this succeeds, the JSON is valid.
217
+ // Therefore, it cannot be "malformed".
218
+ JSON.parse(trimmed);
219
+ return false;
220
+ }
221
+ catch (_e) {
222
+ // It crashed. It might be malformed.
223
+ // Fall through to regex checks below.
224
+ }
225
+ }
226
+ // 3. Check for specific broken tool call patterns.
227
+ const malformedJSONPatterns = [
228
+ /^\s*\{\s*"name"\s*:\s*"[^"]+"\s*\}\s*$/, // name only, no arguments
229
+ /^\s*\{\s*"arguments"\s*:\s*\}\s*$/, // arguments only, no name
230
+ /"arguments"\s*:\s*null\s*([,}\s]*$)/s, // arguments as JSON null (followed by comma, brace, or end)
231
+ /^\s*\{\s*"arguments"\s*:\s*\[\s*\]\s*\}$/, // arguments as empty array
232
+ /^\s*\{\s*"arguments"\s*:\s*""\s*\}$/, // arguments as empty string
233
+ ];
234
+ for (const pattern of malformedJSONPatterns) {
235
+ if (pattern.test(trimmed)) {
236
+ return true;
237
+ }
238
+ }
239
+ // 4. Check for malformed XML patterns
240
+ const malformedXMLPatterns = [
241
+ /\[(?:tool_use|Tool):\s*(\w+)\]/i, // [tool_use: name] syntax
242
+ /<function=(\w+)>/, // <function=name> syntax
243
+ /<parameter=(\w+)>/, // <parameter=name> syntax
244
+ ];
245
+ for (const pattern of malformedXMLPatterns) {
246
+ if (pattern.test(content)) {
247
+ return true;
248
+ }
249
+ }
250
+ return false;
251
+ }
252
+ /**
253
+ * Builds metadata object for debugging and strategy selection
254
+ *
255
+ * @param content - Normalized content
256
+ * @param partialMetadata - Partial metadata from earlier detection
257
+ * @param hasToolCalls - Whether tool calls were actually extracted
258
+ * @returns Complete metadata object
259
+ */
260
+ function buildMetadata(content, partialMetadata, hasToolCalls) {
261
+ // Check if content looks like JSON (has { and })
262
+ // Check if content looks like XML (has < and >)
263
+ // Check if content has code blocks
264
+ const hasCodeBlocks = /```/.test(content);
265
+ // Check if content has XML tags
266
+ const hasXMLTags = /<[^>]+>/.test(content);
267
+ // Check if content has JSON blocks (tool call patterns only, not plain JSON objects)
268
+ const hasJSONBlocks = /"name"\s*:\s*"[^"]+"\s*,\s*"arguments"\s*:\s*\{/.test(content);
269
+ return {
270
+ hasCodeBlocks: partialMetadata.hasCodeBlocks ?? hasCodeBlocks,
271
+ hasXMLTags: partialMetadata.hasXMLTags ?? hasXMLTags,
272
+ hasJSONBlocks: partialMetadata.hasJSONBlocks ?? hasJSONBlocks,
273
+ confidence: determineConfidence({
274
+ ...partialMetadata,
275
+ hasCodeBlocks,
276
+ hasXMLTags,
277
+ hasJSONBlocks,
278
+ }, hasToolCalls),
279
+ detectedFormat: partialMetadata.detectedFormat ?? 'unknown',
280
+ isMalformed: partialMetadata.isMalformed ?? hasMalformedPatterns(content),
281
+ malformedError: partialMetadata.malformedError,
282
+ };
283
+ }
284
+ /**
285
+ * Determines confidence level in the response type classification
286
+ *
287
+ * Confidence levels:
288
+ * - HIGH: Clear format detected (JSON with tool_calls, XML with tool calls)
289
+ * - MEDIUM: Unclear format (plain text with possible tool calls)
290
+ * - LOW: No format detected (plain text with no tool calls)
291
+ *
292
+ * @param metadata - Metadata from response
293
+ * @param hasToolCalls - Whether tool calls were actually extracted
294
+ * @returns Confidence level
295
+ */
296
+ function determineConfidence(metadata, hasToolCalls) {
297
+ // High confidence if we actually extracted tool calls
298
+ if (hasToolCalls) {
299
+ return 'high';
300
+ }
301
+ // If it is explicitly malformed, confidence is LOW
302
+ if (metadata.isMalformed) {
303
+ return 'low';
304
+ }
305
+ // Medium confidence if it looks like code/data, but contained no valid tools
306
+ if (metadata.detectedFormat === 'json' ||
307
+ metadata.detectedFormat === 'xml' ||
308
+ metadata.hasCodeBlocks ||
309
+ metadata.hasJSONBlocks ||
310
+ metadata.hasXMLTags) {
311
+ return 'medium';
312
+ }
313
+ // LOW: Plain text with no format indicators
314
+ return 'low';
315
+ }
316
+ /**
317
+ * Checks if content contains embedded tool call patterns
318
+ *
319
+ * @param content - Content to check
320
+ * @returns True if embedded patterns detected
321
+ */
322
+ function hasEmbeddedToolCallPatterns(content) {
323
+ // JSON tool call patterns (allow text before the pattern)
324
+ const jsonPatterns = [
325
+ /\s*\{\s*"name"\s*:\s*"[^"]+"\s*,\s*"arguments"\s*:\s*\{/s,
326
+ /\s*\{"name":\s*"([^"]+)",\s*"arguments":\s*\{/s,
327
+ ];
328
+ // XML tool call patterns
329
+ const xmlPatterns = [/<(\w+)>(.*?)<\/\1>/s];
330
+ for (const pattern of [...jsonPatterns, ...xmlPatterns]) {
331
+ if (pattern.test(content)) {
332
+ return true;
333
+ }
334
+ }
335
+ return false;
336
+ }
337
+ // ============================================================================
338
+ // UTILITY FUNCTIONS
339
+ // ============================================================================
340
+ /**
341
+ * Formats a normalized response for debugging
342
+ *
343
+ * @param response - Normalized response to format
344
+ * @returns Formatted string for debugging
345
+ */
346
+ export function formatNormalizedResponse(response) {
347
+ return [
348
+ `=== Normalized Response ===`,
349
+ `Raw Type: ${response.raw !== undefined ? typeof response.raw : 'undefined'}`,
350
+ `Content Type: ${typeof response.content}`,
351
+ `Content Length: ${response.content.length} chars`,
352
+ `Detected Format: ${response.metadata.detectedFormat}`,
353
+ `Confidence: ${response.metadata.confidence}`,
354
+ `Has Code Blocks: ${response.metadata.hasCodeBlocks}`,
355
+ `Has XML Tags: ${response.metadata.hasXMLTags}`,
356
+ `Has JSON Blocks: ${response.metadata.hasJSONBlocks}`,
357
+ `Is Malformed: ${response.metadata.isMalformed}`,
358
+ `Tool Calls: ${response.toolCalls.length}`,
359
+ ``,
360
+ `Content Preview:`,
361
+ response.content.slice(0, 500) +
362
+ (response.content.length > 500 ? '...' : ''),
363
+ ``,
364
+ `Tool Calls:`,
365
+ response.toolCalls
366
+ .map(tc => ` - ${tc.function.name}: ${JSON.stringify(tc.function.arguments)}`)
367
+ .join('\n'),
368
+ ].join('\n');
369
+ }
370
+ /**
371
+ * Checks if a response is complete and ready for processing
372
+ *
373
+ * A response is complete if:
374
+ * 1. It has content
375
+ * 2. It has low confidence (means no tool calls were found, so no further processing needed)
376
+ * 3. It's not malformed
377
+ *
378
+ * @param response - Normalized response to check
379
+ * @returns True if response is complete
380
+ */
381
+ export function isResponseComplete(response) {
382
+ // Response is complete if it has content and is not malformed
383
+ return (response.content.length > 0 &&
384
+ !response.metadata.isMalformed &&
385
+ response.metadata.confidence !== 'low');
386
+ }
387
+ //# sourceMappingURL=response-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-formatter.js","sourceRoot":"","sources":["../../source/utils/response-formatter.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAsFrC,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACzC,QAAiB,EACjB,UAA4B,EAAE;IAE9B,MAAM,EACL,gBAAgB,GAAG,KAAK,EAAE,4DAA4D;IACtF,iBAAiB,GAAG,IAAI,EAAE,kDAAkD;MAC5E,GAAG,OAAO,CAAC;IAEZ,iEAAiE;IACjE,MAAM,EAAC,OAAO,EAAE,cAAc,EAAC,GAAG,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IAEvE,8CAA8C;IAC9C,MAAM,EAAC,SAAS,EAAE,cAAc,EAAC,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE;QACnE,iBAAiB;QACjB,cAAc;KACd,CAAC,CAAC;IAEH,0CAA0C;IAC1C,MAAM,WAAW,GAAG,CAAC,SAAS,CAAC,MAAM,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAEvE,8DAA8D;IAC9D,2FAA2F;IAC3F,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,iDAAiD,CAAC,IAAI,CAC3E,OAAO,CACP,CAAC;IAEF,MAAM,QAAQ,GAAG,aAAa,CAC7B,OAAO,EACP;QACC,aAAa;QACb,UAAU,EAAE,SAAS,CAAC,I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downManager,
2
+ /** @internal */
3
+ resetShutdownManager,
4
+ /** @internal */
5
+ ShutdownManager, } from './shutdown-manager.js';
6
+ export type { ShutdownHandler, ShutdownManagerOptions } from './types.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/shutdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB;AAClB,gBAAgB;AAChB,oBAAoB;AACpB,gBAAgB;AAChB,eAAe,GACf,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAC,eAAe,EAAE,sBAAsB,EAAC,MAAM,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { getShutdownManager,
2
+ /** @internal */
3
+ resetShutdownManager,
4
+ /** @internal */
5
+ ShutdownManager, } from './shutdown-manager.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/utils/shutdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB;AAClB,gBAAgB;AAChB,oBAAoB;AACpB,gBAAgB;AAChB,eAAe,GACf,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { ShutdownHandler, ShutdownManagerOptions } from './types.js';
2
+ export declare class ShutdownManager {
3
+ private handlers;
4
+ private isShuttingDown;
5
+ private timeoutMs;
6
+ private boundSigterm;
7
+ private boundSigint;
8
+ private boundUncaughtException;
9
+ private boundUnhandledRejection;
10
+ constructor(options?: ShutdownManagerOptions);
11
+ register(handler: ShutdownHandler): void;
12
+ unregister(name: string): void;
13
+ gracefulShutdown(exitCode?: number): Promise<void>;
14
+ private setupSignalHandlers;
15
+ reset(): void;
16
+ }
17
+ export declare function getShutdownManager(options?: ShutdownManagerOptions): ShutdownManager;
18
+ export declare function resetShutdownManager(): void;
19
+ //# sourceMappingURL=shutdown-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown-manager.d.ts","sourceRoot":"","sources":["../../../source/utils/shutdown/shutdown-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,eAAe,EAAE,sBAAsB,EAAC,MAAM,SAAS,CAAC;AAKrE,qBAAa,eAAe;IAC3B,OAAO,CAAC,QAAQ,CAA2C;IAC3D,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,sBAAsB,CAAuB;IACrD,OAAO,CAAC,uBAAuB,CAGrB;gBAEE,OAAO,CAAC,EAAE,sBAAsB;IAgC5C,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAIxC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB,gBAAgB,CAAC,QAAQ,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAoCnD,OAAO,CAAC,mBAAmB;IAO3B,KAAK,IAAI,IAAI;CAQb;AAID,wBAAgB,kBAAkB,CACjC,OAAO,CAAC,EAAE,sBAAsB,GAC9B,eAAe,CAKjB;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAK3C"}