@superblocksteam/vite-plugin-file-sync 2.0.42-next.48 → 2.0.42-next.49

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 (259) hide show
  1. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts +2 -1
  2. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
  3. package/dist/ai-service/agent/prompts/build-base-system-prompt.js +31 -2
  4. package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
  5. package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts +30 -4
  6. package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts.map +1 -1
  7. package/dist/ai-service/agent/subagents/apis/generate-api-source.js +10 -6
  8. package/dist/ai-service/agent/subagents/apis/generate-api-source.js.map +1 -1
  9. package/dist/ai-service/agent/tool-message-utils.d.ts +1 -1
  10. package/dist/ai-service/agent/tool-message-utils.d.ts.map +1 -1
  11. package/dist/ai-service/agent/tool-message-utils.js +35 -6
  12. package/dist/ai-service/agent/tool-message-utils.js.map +1 -1
  13. package/dist/ai-service/agent/tools/build-add-event.d.ts +2 -4
  14. package/dist/ai-service/agent/tools/build-add-event.d.ts.map +1 -1
  15. package/dist/ai-service/agent/tools/build-add-event.js +9 -8
  16. package/dist/ai-service/agent/tools/build-add-event.js.map +1 -1
  17. package/dist/ai-service/agent/tools/build-add-state-var.d.ts +2 -4
  18. package/dist/ai-service/agent/tools/build-add-state-var.d.ts.map +1 -1
  19. package/dist/ai-service/agent/tools/build-add-state-var.js +6 -5
  20. package/dist/ai-service/agent/tools/build-add-state-var.js.map +1 -1
  21. package/dist/ai-service/agent/tools/build-add-timer.d.ts +2 -4
  22. package/dist/ai-service/agent/tools/build-add-timer.d.ts.map +1 -1
  23. package/dist/ai-service/agent/tools/build-add-timer.js +7 -6
  24. package/dist/ai-service/agent/tools/build-add-timer.js.map +1 -1
  25. package/dist/ai-service/agent/tools/build-create-page.d.ts +2 -3
  26. package/dist/ai-service/agent/tools/build-create-page.d.ts.map +1 -1
  27. package/dist/ai-service/agent/tools/build-create-page.js +11 -10
  28. package/dist/ai-service/agent/tools/build-create-page.js.map +1 -1
  29. package/dist/ai-service/agent/tools/build-debug.d.ts +1 -3
  30. package/dist/ai-service/agent/tools/build-debug.d.ts.map +1 -1
  31. package/dist/ai-service/agent/tools/build-debug.js +7 -5
  32. package/dist/ai-service/agent/tools/build-debug.js.map +1 -1
  33. package/dist/ai-service/agent/tools/build-edit-file.d.ts +2 -4
  34. package/dist/ai-service/agent/tools/build-edit-file.d.ts.map +1 -1
  35. package/dist/ai-service/agent/tools/build-edit-file.js +10 -7
  36. package/dist/ai-service/agent/tools/build-edit-file.js.map +1 -1
  37. package/dist/ai-service/agent/tools/build-finalize.d.ts +2 -4
  38. package/dist/ai-service/agent/tools/build-finalize.d.ts.map +1 -1
  39. package/dist/ai-service/agent/tools/build-finalize.js +6 -5
  40. package/dist/ai-service/agent/tools/build-finalize.js.map +1 -1
  41. package/dist/ai-service/agent/tools/build-install-packages.d.ts +2 -4
  42. package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
  43. package/dist/ai-service/agent/tools/build-install-packages.js +7 -6
  44. package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
  45. package/dist/ai-service/agent/tools/build-list-available-components.d.ts +3 -8
  46. package/dist/ai-service/agent/tools/build-list-available-components.d.ts.map +1 -1
  47. package/dist/ai-service/agent/tools/build-list-available-components.js +30 -9
  48. package/dist/ai-service/agent/tools/build-list-available-components.js.map +1 -1
  49. package/dist/ai-service/agent/tools/build-list-files.d.ts +2 -3
  50. package/dist/ai-service/agent/tools/build-list-files.d.ts.map +1 -1
  51. package/dist/ai-service/agent/tools/build-list-files.js +10 -8
  52. package/dist/ai-service/agent/tools/build-list-files.js.map +1 -1
  53. package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +3 -3
  54. package/dist/ai-service/agent/tools/build-manage-checklist.d.ts.map +1 -1
  55. package/dist/ai-service/agent/tools/build-manage-checklist.js +9 -8
  56. package/dist/ai-service/agent/tools/build-manage-checklist.js.map +1 -1
  57. package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts +2 -4
  58. package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts.map +1 -1
  59. package/dist/ai-service/agent/tools/build-multi-edit-file.js +9 -6
  60. package/dist/ai-service/agent/tools/build-multi-edit-file.js.map +1 -1
  61. package/dist/ai-service/agent/tools/build-read-files.d.ts +2 -4
  62. package/dist/ai-service/agent/tools/build-read-files.d.ts.map +1 -1
  63. package/dist/ai-service/agent/tools/build-read-files.js +9 -7
  64. package/dist/ai-service/agent/tools/build-read-files.js.map +1 -1
  65. package/dist/ai-service/agent/tools/build-register-component-name.d.ts +2 -4
  66. package/dist/ai-service/agent/tools/build-register-component-name.d.ts.map +1 -1
  67. package/dist/ai-service/agent/tools/build-register-component-name.js +9 -8
  68. package/dist/ai-service/agent/tools/build-register-component-name.js.map +1 -1
  69. package/dist/ai-service/agent/tools/build-rename-page.d.ts +2 -3
  70. package/dist/ai-service/agent/tools/build-rename-page.d.ts.map +1 -1
  71. package/dist/ai-service/agent/tools/build-rename-page.js +6 -5
  72. package/dist/ai-service/agent/tools/build-rename-page.js.map +1 -1
  73. package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts +2 -4
  74. package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts.map +1 -1
  75. package/dist/ai-service/agent/tools/build-set-api-triggers.js +6 -5
  76. package/dist/ai-service/agent/tools/build-set-api-triggers.js.map +1 -1
  77. package/dist/ai-service/agent/tools/build-update-state-var.d.ts +2 -3
  78. package/dist/ai-service/agent/tools/build-update-state-var.d.ts.map +1 -1
  79. package/dist/ai-service/agent/tools/build-update-state-var.js +6 -5
  80. package/dist/ai-service/agent/tools/build-update-state-var.js.map +1 -1
  81. package/dist/ai-service/agent/tools/build-validate-icons.d.ts +2 -3
  82. package/dist/ai-service/agent/tools/build-validate-icons.d.ts.map +1 -1
  83. package/dist/ai-service/agent/tools/build-validate-icons.js +8 -6
  84. package/dist/ai-service/agent/tools/build-validate-icons.js.map +1 -1
  85. package/dist/ai-service/agent/tools/build-write-file.d.ts +2 -4
  86. package/dist/ai-service/agent/tools/build-write-file.d.ts.map +1 -1
  87. package/dist/ai-service/agent/tools/build-write-file.js +6 -5
  88. package/dist/ai-service/agent/tools/build-write-file.js.map +1 -1
  89. package/dist/ai-service/agent/tools/debug-cache.d.ts.map +1 -1
  90. package/dist/ai-service/agent/tools/debug-cache.js +3 -0
  91. package/dist/ai-service/agent/tools/debug-cache.js.map +1 -1
  92. package/dist/ai-service/agent/tools/index.d.ts +23 -20
  93. package/dist/ai-service/agent/tools/index.d.ts.map +1 -1
  94. package/dist/ai-service/agent/tools/index.js +23 -20
  95. package/dist/ai-service/agent/tools/index.js.map +1 -1
  96. package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +25 -0
  97. package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -0
  98. package/dist/ai-service/agent/tools/integrations/execute-request.js +213 -0
  99. package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -0
  100. package/dist/ai-service/agent/tools/integrations/index.d.ts +4 -0
  101. package/dist/ai-service/agent/tools/integrations/index.d.ts.map +1 -0
  102. package/dist/ai-service/agent/tools/integrations/index.js +4 -0
  103. package/dist/ai-service/agent/tools/integrations/index.js.map +1 -0
  104. package/dist/ai-service/agent/tools/integrations/internal.d.ts +3 -0
  105. package/dist/ai-service/agent/tools/integrations/internal.d.ts.map +1 -0
  106. package/dist/ai-service/agent/tools/integrations/internal.js +11 -0
  107. package/dist/ai-service/agent/tools/integrations/internal.js.map +1 -0
  108. package/dist/ai-service/agent/tools/integrations/metadata.d.ts +9 -0
  109. package/dist/ai-service/agent/tools/integrations/metadata.d.ts.map +1 -0
  110. package/dist/ai-service/agent/tools/integrations/metadata.js +57 -0
  111. package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -0
  112. package/dist/ai-service/agent/tools/integrations/run-code.d.ts +5 -0
  113. package/dist/ai-service/agent/tools/integrations/run-code.d.ts.map +1 -0
  114. package/dist/ai-service/agent/tools/integrations/run-code.js +32 -0
  115. package/dist/ai-service/agent/tools/integrations/run-code.js.map +1 -0
  116. package/dist/ai-service/agent/tools/study-current-app-state.d.ts +2 -4
  117. package/dist/ai-service/agent/tools/study-current-app-state.d.ts.map +1 -1
  118. package/dist/ai-service/agent/tools/study-current-app-state.js +10 -8
  119. package/dist/ai-service/agent/tools/study-current-app-state.js.map +1 -1
  120. package/dist/ai-service/agent/tools.d.ts +3 -282
  121. package/dist/ai-service/agent/tools.d.ts.map +1 -1
  122. package/dist/ai-service/agent/tools.js +68 -55
  123. package/dist/ai-service/agent/tools.js.map +1 -1
  124. package/dist/ai-service/agent/tools2/access-control.d.ts +119 -0
  125. package/dist/ai-service/agent/tools2/access-control.d.ts.map +1 -0
  126. package/dist/ai-service/agent/tools2/access-control.js +216 -0
  127. package/dist/ai-service/agent/tools2/access-control.js.map +1 -0
  128. package/dist/ai-service/agent/tools2/example.d.ts +13 -0
  129. package/dist/ai-service/agent/tools2/example.d.ts.map +1 -0
  130. package/dist/ai-service/agent/tools2/example.js +143 -0
  131. package/dist/ai-service/agent/tools2/example.js.map +1 -0
  132. package/dist/ai-service/agent/tools2/index.d.ts +16 -0
  133. package/dist/ai-service/agent/tools2/index.d.ts.map +1 -0
  134. package/dist/ai-service/agent/tools2/index.js +18 -0
  135. package/dist/ai-service/agent/tools2/index.js.map +1 -0
  136. package/dist/ai-service/agent/tools2/registry.d.ts +167 -0
  137. package/dist/ai-service/agent/tools2/registry.d.ts.map +1 -0
  138. package/dist/ai-service/agent/tools2/registry.js +305 -0
  139. package/dist/ai-service/agent/tools2/registry.js.map +1 -0
  140. package/dist/ai-service/agent/tools2/tools/ask-multi-choice.d.ts +12 -0
  141. package/dist/ai-service/agent/tools2/tools/ask-multi-choice.d.ts.map +1 -0
  142. package/dist/ai-service/agent/tools2/tools/ask-multi-choice.js +73 -0
  143. package/dist/ai-service/agent/tools2/tools/ask-multi-choice.js.map +1 -0
  144. package/dist/ai-service/agent/tools2/tools/bash.d.ts +34 -0
  145. package/dist/ai-service/agent/tools2/tools/bash.d.ts.map +1 -0
  146. package/dist/ai-service/agent/tools2/tools/bash.js +76 -0
  147. package/dist/ai-service/agent/tools2/tools/bash.js.map +1 -0
  148. package/dist/ai-service/agent/tools2/tools/edit.d.ts +14 -0
  149. package/dist/ai-service/agent/tools2/tools/edit.d.ts.map +1 -0
  150. package/dist/ai-service/agent/tools2/tools/edit.js +60 -0
  151. package/dist/ai-service/agent/tools2/tools/edit.js.map +1 -0
  152. package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts +10 -0
  153. package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts.map +1 -0
  154. package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js +66 -0
  155. package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js.map +1 -0
  156. package/dist/ai-service/agent/tools2/tools/glob.d.ts +11 -0
  157. package/dist/ai-service/agent/tools2/tools/glob.d.ts.map +1 -0
  158. package/dist/ai-service/agent/tools2/tools/glob.js +44 -0
  159. package/dist/ai-service/agent/tools2/tools/glob.js.map +1 -0
  160. package/dist/ai-service/agent/tools2/tools/grep.d.ts +21 -0
  161. package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -0
  162. package/dist/ai-service/agent/tools2/tools/grep.js +100 -0
  163. package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -0
  164. package/dist/ai-service/agent/tools2/tools/index.d.ts +13 -0
  165. package/dist/ai-service/agent/tools2/tools/index.d.ts.map +1 -0
  166. package/dist/ai-service/agent/tools2/tools/index.js +13 -0
  167. package/dist/ai-service/agent/tools2/tools/index.js.map +1 -0
  168. package/dist/ai-service/agent/tools2/tools/read.d.ts +9 -0
  169. package/dist/ai-service/agent/tools2/tools/read.d.ts.map +1 -0
  170. package/dist/ai-service/agent/tools2/tools/read.js +43 -0
  171. package/dist/ai-service/agent/tools2/tools/read.js.map +1 -0
  172. package/dist/ai-service/agent/tools2/tools/write.d.ts +11 -0
  173. package/dist/ai-service/agent/tools2/tools/write.d.ts.map +1 -0
  174. package/dist/ai-service/agent/tools2/tools/write.js +28 -0
  175. package/dist/ai-service/agent/tools2/tools/write.js.map +1 -0
  176. package/dist/ai-service/agent/tools2/types.d.ts +148 -0
  177. package/dist/ai-service/agent/tools2/types.d.ts.map +1 -0
  178. package/dist/ai-service/agent/tools2/types.js +55 -0
  179. package/dist/ai-service/agent/tools2/types.js.map +1 -0
  180. package/dist/ai-service/agent/utils.d.ts.map +1 -1
  181. package/dist/ai-service/agent/utils.js +2 -0
  182. package/dist/ai-service/agent/utils.js.map +1 -1
  183. package/dist/ai-service/chat/chat-session-store.d.ts +5 -0
  184. package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
  185. package/dist/ai-service/chat/chat-session-store.js +486 -342
  186. package/dist/ai-service/chat/chat-session-store.js.map +1 -1
  187. package/dist/ai-service/chat/extract-history.d.ts +1 -0
  188. package/dist/ai-service/chat/extract-history.d.ts.map +1 -1
  189. package/dist/ai-service/chat/extract-history.js +12 -1
  190. package/dist/ai-service/chat/extract-history.js.map +1 -1
  191. package/dist/ai-service/const.d.ts +2 -1
  192. package/dist/ai-service/const.d.ts.map +1 -1
  193. package/dist/ai-service/const.js +7 -1
  194. package/dist/ai-service/const.js.map +1 -1
  195. package/dist/ai-service/index.d.ts +8 -8
  196. package/dist/ai-service/index.d.ts.map +1 -1
  197. package/dist/ai-service/index.js.map +1 -1
  198. package/dist/ai-service/integrations/store.d.ts +24 -1
  199. package/dist/ai-service/integrations/store.d.ts.map +1 -1
  200. package/dist/ai-service/integrations/store.js +86 -2
  201. package/dist/ai-service/integrations/store.js.map +1 -1
  202. package/dist/ai-service/llm/context/context.d.ts +1 -1
  203. package/dist/ai-service/llm/context/context.js +1 -1
  204. package/dist/ai-service/llmobs/middleware/stream-text.js +4 -1
  205. package/dist/ai-service/llmobs/middleware/stream-text.js.map +1 -1
  206. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ButtonPropsDocs.js +1 -1
  207. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/CheckboxPropsDocs.js +1 -1
  208. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ColumnPropsDocs.js +1 -1
  209. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ContainerPropsDocs.js +1 -1
  210. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DatePickerPropsDocs.js +1 -1
  211. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DropdownPropsDocs.js +1 -1
  212. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/IconPropsDocs.js +1 -1
  213. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ImagePropsDocs.js +1 -1
  214. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/InputPropsDocs.js +1 -1
  215. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ModalPropsDocs.js +1 -1
  216. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/PagePropsDocs.js +1 -1
  217. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SectionPropsDocs.js +1 -1
  218. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SlideoutPropsDocs.js +1 -1
  219. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SwitchPropsDocs.js +1 -1
  220. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TablePropsDocs.js +1 -1
  221. package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TextPropsDocs.js +1 -1
  222. package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/Dim.js +1 -1
  223. package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/EventFlow.js +1 -1
  224. package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/TextStyleWithVariant.js +1 -1
  225. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/full-examples.js +1 -1
  226. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-api.js +1 -1
  227. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-components-rules.js +1 -1
  228. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-custom-components.js +1 -1
  229. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-data-filtering.js +1 -1
  230. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-event-flow.js +1 -1
  231. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-forms.js +1 -1
  232. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-layouts.js +1 -1
  233. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-page.js +1 -1
  234. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-rbac.js +1 -1
  235. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-routes.js +1 -1
  236. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-state.js +1 -1
  237. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-theming-chakra-new.js +1 -1
  238. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-base.js +1 -1
  239. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-incremental.js +1 -1
  240. package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-specific-edit.js +1 -1
  241. package/dist/ai-service/state-machine/clark-fsm.d.ts +7 -5
  242. package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
  243. package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
  244. package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
  245. package/dist/ai-service/state-machine/handlers/agent-planning.js +36 -9
  246. package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
  247. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
  248. package/dist/ai-service/state-machine/handlers/llm-generating.js +35 -7
  249. package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
  250. package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -1
  251. package/dist/ai-service/state-machine/helpers/peer.js +7 -4
  252. package/dist/ai-service/state-machine/helpers/peer.js.map +1 -1
  253. package/dist/ai-service/state-machine/mocks.d.ts +2 -3
  254. package/dist/ai-service/state-machine/mocks.d.ts.map +1 -1
  255. package/dist/ai-service/state-machine/mocks.js.map +1 -1
  256. package/dist/ai-service/types.d.ts +3 -0
  257. package/dist/ai-service/types.d.ts.map +1 -1
  258. package/dist/ai-service/types.js.map +1 -1
  259. package/package.json +7 -7
@@ -1,4 +1,39 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
1
35
  import { getErrorMeta } from "../../util/logger.js";
36
+ import llmobs from "../llmobs/index.js";
2
37
  import { extractProductiveHistoryForContext, getLastUserMessage, } from "./extract-history.js";
3
38
  export function isAiChatMessage(item) {
4
39
  return "role" in item && "content" in item;
@@ -6,396 +41,505 @@ export function isAiChatMessage(item) {
6
41
  export function isAiChatSummary(item) {
7
42
  return "summary" in item && "relevantFilePaths" in item;
8
43
  }
9
- export class ChatSessionStore {
10
- applicationId;
11
- rpcClient;
12
- logger;
13
- messages;
14
- inFlightLoadFromServer;
15
- loadedFromServer = "no";
16
- constructor(config) {
17
- this.rpcClient = config.rpcClient;
18
- this.applicationId = config.applicationId;
19
- this.messages = [];
20
- this.logger = config.logger;
21
- // NOTE: This is used to serialize messages to be after any load.
22
- // We initialize it as resolved to handle the prompt-from-empty-state case.
23
- // TODO(ai): consider replacing this with a queue-based approach
24
- this.inFlightLoadFromServer = Promise.resolve();
25
- }
26
- /***
27
- * Validates and sanitizes the attachments array
28
- * @param attachments - The attachments array to validate
29
- * @returns A tuple containing:
30
- * - a boolean indicating if the attachments are valid
31
- * - the sanitized attachments array
32
- */
33
- validateAttachments(attachments) {
34
- if (!attachments) {
35
- return [true, undefined];
44
+ let ChatSessionStore = (() => {
45
+ let _instanceExtraInitializers = [];
46
+ let _getMessages_decorators;
47
+ let _getLatestSummary_decorators;
48
+ return class ChatSessionStore {
49
+ static {
50
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
51
+ _getMessages_decorators = [llmobs.decorate({
52
+ kind: "task",
53
+ name: "ChatSessionStore.getMessages",
54
+ })];
55
+ _getLatestSummary_decorators = [llmobs.decorate({
56
+ kind: "task",
57
+ name: "ChatSessionStore.getLatestSummary",
58
+ })];
59
+ __esDecorate(this, null, _getMessages_decorators, { kind: "method", name: "getMessages", static: false, private: false, access: { has: obj => "getMessages" in obj, get: obj => obj.getMessages }, metadata: _metadata }, null, _instanceExtraInitializers);
60
+ __esDecorate(this, null, _getLatestSummary_decorators, { kind: "method", name: "getLatestSummary", static: false, private: false, access: { has: obj => "getLatestSummary" in obj, get: obj => obj.getLatestSummary }, metadata: _metadata }, null, _instanceExtraInitializers);
61
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
36
62
  }
37
- if (typeof attachments !== "object" || !Array.isArray(attachments)) {
38
- return [false, undefined];
63
+ // Approximate number of characters per token for estimating token usage
64
+ static CHARS_PER_TOKEN = 3.5;
65
+ applicationId = __runInitializers(this, _instanceExtraInitializers);
66
+ rpcClient;
67
+ logger;
68
+ messages;
69
+ inFlightLoadFromServer;
70
+ loadedFromServer = "no";
71
+ constructor(config) {
72
+ this.rpcClient = config.rpcClient;
73
+ this.applicationId = config.applicationId;
74
+ this.messages = [];
75
+ this.logger = config.logger;
76
+ // NOTE: This is used to serialize messages to be after any load.
77
+ // We initialize it as resolved to handle the prompt-from-empty-state case.
78
+ // TODO(ai): consider replacing this with a queue-based approach
79
+ this.inFlightLoadFromServer = Promise.resolve();
39
80
  }
40
- const validAttachments = attachments
41
- .map((attachment) => {
42
- if (typeof attachment !== "object" || !("type" in attachment)) {
43
- return undefined;
81
+ /***
82
+ * Validates and sanitizes the attachments array
83
+ * @param attachments - The attachments array to validate
84
+ * @returns A tuple containing:
85
+ * - a boolean indicating if the attachments are valid
86
+ * - the sanitized attachments array
87
+ */
88
+ validateAttachments(attachments) {
89
+ if (!attachments) {
90
+ return [true, undefined];
91
+ }
92
+ if (typeof attachments !== "object" || !Array.isArray(attachments)) {
93
+ return [false, undefined];
44
94
  }
45
- // Validate image attachment
46
- if (attachment.type === "image") {
47
- if (typeof attachment.image !== "string") {
95
+ const validAttachments = attachments
96
+ .map((attachment) => {
97
+ if (typeof attachment !== "object" || !("type" in attachment)) {
48
98
  return undefined;
49
99
  }
50
- return {
51
- type: attachment.type,
52
- image: attachment.image,
53
- fileName: attachment.fileName,
54
- };
55
- }
56
- return undefined;
57
- })
58
- .filter(Boolean);
59
- return [validAttachments.length === attachments.length, validAttachments];
60
- }
61
- validateChatMessageV1(payload) {
62
- try {
63
- if (!payload || typeof payload !== "object") {
64
- return null;
65
- }
66
- const msg = payload;
67
- // Validate required fields
68
- if (typeof msg.role !== "string" ||
69
- !["user", "assistant", "server"].includes(msg.role)) {
70
- this.logger.warn(`[ai-service] Invalid message role: ${msg.role}`);
71
- return null;
72
- }
73
- if (typeof msg.content !== "string") {
74
- this.logger.warn(`[ai-service] Invalid message content`);
75
- return null;
76
- }
77
- if (typeof msg.type !== "string") {
78
- this.logger.warn(`[ai-service] Invalid message type: ${msg.type}`);
79
- return null;
80
- }
81
- // Validate optional fields with defaults
82
- const timestamp = typeof msg.timestamp === "number" ? msg.timestamp : Date.now();
83
- const group = typeof msg.group === "string" ? msg.group : undefined;
84
- const status = typeof msg.status === "string" ? msg.status : undefined;
85
- const action = typeof msg.action === "string" ? msg.action : undefined;
86
- const [isAttachmentsValid, attachments] = this.validateAttachments(msg.attachments);
87
- if (!isAttachmentsValid) {
88
- this.logger.warn(`[ai-service] Invalid attachments`);
89
- return null;
90
- }
91
- if (msg.type === "tool") {
100
+ // Validate image attachment
101
+ if (attachment.type === "image") {
102
+ if (typeof attachment.image !== "string") {
103
+ return undefined;
104
+ }
105
+ return {
106
+ type: attachment.type,
107
+ image: attachment.image,
108
+ fileName: attachment.fileName,
109
+ };
110
+ }
111
+ return undefined;
112
+ })
113
+ .filter(Boolean);
114
+ return [validAttachments.length === attachments.length, validAttachments];
115
+ }
116
+ validateChatMessageV1(payload) {
117
+ try {
118
+ if (!payload || typeof payload !== "object") {
119
+ return null;
120
+ }
121
+ const msg = payload;
122
+ // Validate required fields
123
+ if (typeof msg.role !== "string" ||
124
+ !["user", "assistant", "server"].includes(msg.role)) {
125
+ this.logger.warn(`[ai-service] Invalid message role: ${msg.role}`);
126
+ return null;
127
+ }
128
+ if (typeof msg.content !== "string") {
129
+ this.logger.warn(`[ai-service] Invalid message content`);
130
+ return null;
131
+ }
132
+ if (typeof msg.type !== "string") {
133
+ this.logger.warn(`[ai-service] Invalid message type: ${msg.type}`);
134
+ return null;
135
+ }
136
+ // Validate optional fields with defaults
137
+ const timestamp = typeof msg.timestamp === "number" ? msg.timestamp : Date.now();
138
+ const group = typeof msg.group === "string" ? msg.group : undefined;
139
+ const status = typeof msg.status === "string" ? msg.status : undefined;
140
+ const action = typeof msg.action === "string" ? msg.action : undefined;
141
+ const [isAttachmentsValid, attachments] = this.validateAttachments(msg.attachments);
142
+ if (!isAttachmentsValid) {
143
+ this.logger.warn(`[ai-service] Invalid attachments`);
144
+ return null;
145
+ }
146
+ if (msg.type === "tool") {
147
+ return {
148
+ role: msg.role,
149
+ content: msg.content,
150
+ type: "tool",
151
+ id: typeof msg.id === "string" ? msg.id : undefined,
152
+ timestamp,
153
+ status: status,
154
+ action: action,
155
+ args: msg.args,
156
+ tool: msg.tool,
157
+ };
158
+ }
159
+ else if (msg.group === "checklist") {
160
+ if (typeof msg.checklistData !== "object") {
161
+ this.logger.warn(`[ai-service] Invalid checklist data`);
162
+ return null;
163
+ }
164
+ return {
165
+ role: msg.role,
166
+ content: msg.content,
167
+ type: "tool",
168
+ id: typeof msg.id === "string" ? msg.id : undefined,
169
+ timestamp,
170
+ group,
171
+ status,
172
+ action,
173
+ checklistData: msg.checklistData,
174
+ };
175
+ }
176
+ else if (msg.type === "multi_choice") {
177
+ if (!Array.isArray(msg.choices) || msg.choices.length === 0) {
178
+ this.logger.warn(`[ai-service] Invalid choices for multi_choice message`);
179
+ return null;
180
+ }
181
+ return {
182
+ role: msg.role,
183
+ content: msg.content,
184
+ type: "multi_choice",
185
+ id: typeof msg.id === "string" ? msg.id : undefined,
186
+ timestamp,
187
+ choices: msg.choices,
188
+ selectionType: typeof msg.selectionType === "string"
189
+ ? msg.selectionType
190
+ : "single",
191
+ };
192
+ }
193
+ else if (msg.type === "multi_choice_response") {
194
+ if (typeof msg.responseToMessageId !== "string") {
195
+ this.logger.warn(`[ai-service] Invalid responseToMessageId for multi_choice_response`);
196
+ return null;
197
+ }
198
+ if (!Array.isArray(msg.selectedChoiceIndices)) {
199
+ this.logger.warn(`[ai-service] Invalid selectedChoiceIndices for multi_choice_response`);
200
+ return null;
201
+ }
202
+ return {
203
+ role: msg.role,
204
+ content: msg.content,
205
+ type: "multi_choice_response",
206
+ id: typeof msg.id === "string" ? msg.id : undefined,
207
+ timestamp,
208
+ responseToMessageId: msg.responseToMessageId,
209
+ selectedChoiceIndices: msg.selectedChoiceIndices,
210
+ };
211
+ }
212
+ else if (msg.type === "plan_response") {
213
+ if (typeof msg.responseToMessageId !== "string") {
214
+ this.logger.warn(`[ai-service] Invalid responseToMessageId for plan_response`);
215
+ return null;
216
+ }
217
+ return {
218
+ role: msg.role,
219
+ content: msg.content,
220
+ type: "plan_response",
221
+ id: typeof msg.id === "string" ? msg.id : undefined,
222
+ timestamp,
223
+ responseToMessageId: msg.responseToMessageId,
224
+ };
225
+ }
92
226
  return {
93
227
  role: msg.role,
94
228
  content: msg.content,
95
- type: "tool",
229
+ type: msg.type,
230
+ id: typeof msg.id === "string" ? msg.id : undefined,
96
231
  timestamp,
232
+ group,
97
233
  status: status,
98
234
  action: action,
99
- args: msg.args,
100
- tool: msg.tool,
235
+ attachments,
101
236
  };
102
237
  }
103
- else if (msg.group === "checklist") {
104
- if (typeof msg.checklistData !== "object") {
105
- this.logger.warn(`[ai-service] Invalid checklist data`);
238
+ catch (error) {
239
+ this.logger.error("[ai-service] Failed to validate message payload", getErrorMeta(error));
240
+ return null;
241
+ }
242
+ }
243
+ validateChatSummaryV1(payload) {
244
+ try {
245
+ if (!payload || typeof payload !== "object") {
246
+ return null;
247
+ }
248
+ const summary = payload;
249
+ // Validate required fields
250
+ if (typeof summary.summary !== "string") {
251
+ this.logger.warn(`[ai-service] Invalid summary content`);
252
+ return null;
253
+ }
254
+ if (!Array.isArray(summary.relevantFilePaths)) {
255
+ this.logger.warn(`[ai-service] Invalid relevantFilePaths - must be array`);
256
+ return null;
257
+ }
258
+ if (!summary.relevantFilePaths.every((path) => typeof path === "string")) {
259
+ this.logger.warn(`[ai-service] Invalid relevantFilePaths - all items must be strings`);
260
+ return null;
261
+ }
262
+ if (!Array.isArray(summary.goals)) {
263
+ this.logger.warn(`[ai-service] Invalid goals - must be array`);
264
+ return null;
265
+ }
266
+ if (!summary.goals.every((goal) => typeof goal === "string")) {
267
+ this.logger.warn(`[ai-service] Invalid goals - all items must be strings`);
268
+ return null;
269
+ }
270
+ if (!Array.isArray(summary.decisions)) {
271
+ this.logger.warn(`[ai-service] Invalid decisions - must be array`);
106
272
  return null;
107
273
  }
274
+ if (!summary.decisions.every((decision) => typeof decision === "string")) {
275
+ this.logger.warn(`[ai-service] Invalid decisions - all items must be strings`);
276
+ return null;
277
+ }
278
+ // Validate optional fields with defaults
279
+ const timestamp = typeof summary.timestamp === "number" ? summary.timestamp : Date.now();
108
280
  return {
109
- role: msg.role,
110
- content: msg.content,
111
- type: "tool",
281
+ summary: summary.summary,
282
+ relevantFilePaths: summary.relevantFilePaths,
283
+ goals: summary.goals,
284
+ decisions: summary.decisions,
285
+ adviceToAgents: summary.adviceToAgents,
112
286
  timestamp,
113
- group,
114
- status,
115
- action,
116
- checklistData: msg.checklistData,
117
287
  };
118
288
  }
119
- return {
120
- role: msg.role,
121
- content: msg.content,
122
- type: msg.type,
123
- timestamp,
124
- group,
125
- status: status,
126
- action: action,
127
- attachments,
128
- };
129
- }
130
- catch (error) {
131
- this.logger.error("[ai-service] Failed to validate message payload", getErrorMeta(error));
132
- return null;
133
- }
134
- }
135
- validateChatSummaryV1(payload) {
136
- try {
137
- if (!payload || typeof payload !== "object") {
138
- return null;
139
- }
140
- const summary = payload;
141
- // Validate required fields
142
- if (typeof summary.summary !== "string") {
143
- this.logger.warn(`[ai-service] Invalid summary content`);
289
+ catch (error) {
290
+ this.logger.error("[ai-service] Failed to validate summary payload", getErrorMeta(error));
144
291
  return null;
145
292
  }
146
- if (!Array.isArray(summary.relevantFilePaths)) {
147
- this.logger.warn(`[ai-service] Invalid relevantFilePaths - must be array`);
148
- return null;
149
- }
150
- if (!summary.relevantFilePaths.every((path) => typeof path === "string")) {
151
- this.logger.warn(`[ai-service] Invalid relevantFilePaths - all items must be strings`);
152
- return null;
293
+ }
294
+ validateChatItemV1(payload) {
295
+ // First try to validate as a message
296
+ const messageResult = this.validateChatMessageV1(payload);
297
+ if (messageResult) {
298
+ return messageResult;
153
299
  }
154
- if (!Array.isArray(summary.goals)) {
155
- this.logger.warn(`[ai-service] Invalid goals - must be array`);
156
- return null;
300
+ // If not a valid message, try to validate as a summary
301
+ const summaryResult = this.validateChatSummaryV1(payload);
302
+ if (summaryResult) {
303
+ return summaryResult;
157
304
  }
158
- if (!summary.goals.every((goal) => typeof goal === "string")) {
159
- this.logger.warn(`[ai-service] Invalid goals - all items must be strings`);
160
- return null;
305
+ return null;
306
+ }
307
+ async ensureLoadedFromServer() {
308
+ // NOTE: we will want to re-evaluate this if/when the auth token associated with this sandbox is changed
309
+ // the existing solution is that each time the page loaded by the client, we re-fetch from the server,
310
+ // so this may be a non-issue.
311
+ if (this.loadedFromServer === "loaded" ||
312
+ this.loadedFromServer === "loading") {
313
+ await this.inFlightLoadFromServer;
314
+ return;
161
315
  }
162
- if (!Array.isArray(summary.decisions)) {
163
- this.logger.warn(`[ai-service] Invalid decisions - must be array`);
164
- return null;
316
+ try {
317
+ this.loadedFromServer = "loading";
318
+ this.inFlightLoadFromServer = this.rpcClient.call(async (client) => {
319
+ const applicationId = this.applicationId;
320
+ const { data } = await client.call.v1.ai.chat.getMessages({
321
+ applicationId,
322
+ });
323
+ this.messages =
324
+ data?.messages
325
+ .map((msg) => this.validateChatItemV1(msg.chatPayload))
326
+ .filter((item) => item !== null)
327
+ .sort((a, b) => {
328
+ return (a.timestamp || 0) - (b.timestamp || 0);
329
+ }) ?? [];
330
+ });
331
+ await this.inFlightLoadFromServer;
332
+ this.loadedFromServer = "loaded";
165
333
  }
166
- if (!summary.decisions.every((decision) => typeof decision === "string")) {
167
- this.logger.warn(`[ai-service] Invalid decisions - all items must be strings`);
168
- return null;
334
+ catch (error) {
335
+ this.logger.error("[ai-service] Failed to load chat messages from server", getErrorMeta(error));
169
336
  }
170
- // Validate optional fields with defaults
171
- const timestamp = typeof summary.timestamp === "number" ? summary.timestamp : Date.now();
172
- return {
173
- summary: summary.summary,
174
- relevantFilePaths: summary.relevantFilePaths,
175
- goals: summary.goals,
176
- decisions: summary.decisions,
177
- adviceToAgents: summary.adviceToAgents,
178
- timestamp,
179
- };
180
337
  }
181
- catch (error) {
182
- this.logger.error("[ai-service] Failed to validate summary payload", getErrorMeta(error));
183
- return null;
184
- }
185
- }
186
- validateChatItemV1(payload) {
187
- // First try to validate as a message
188
- const messageResult = this.validateChatMessageV1(payload);
189
- if (messageResult) {
190
- return messageResult;
338
+ getLastUserMessage() {
339
+ const messages = this.messages.filter(isAiChatMessage);
340
+ return getLastUserMessage(messages);
191
341
  }
192
- // If not a valid message, try to validate as a summary
193
- const summaryResult = this.validateChatSummaryV1(payload);
194
- if (summaryResult) {
195
- return summaryResult;
196
- }
197
- return null;
198
- }
199
- async ensureLoadedFromServer() {
200
- // NOTE: we will want to re-evaluate this if/when the auth token associated with this sandbox is changed
201
- // the existing solution is that each time the page loaded by the client, we re-fetch from the server,
202
- // so this may be a non-issue.
203
- if (this.loadedFromServer === "loaded" ||
204
- this.loadedFromServer === "loading") {
205
- await this.inFlightLoadFromServer;
206
- return;
207
- }
208
- try {
209
- this.loadedFromServer = "loading";
210
- this.inFlightLoadFromServer = this.rpcClient.call(async (client) => {
211
- const applicationId = this.applicationId;
212
- const { data } = await client.call.v1.ai.chat.getMessages({
213
- applicationId,
214
- });
215
- this.messages =
216
- data?.messages
217
- .map((msg) => this.validateChatItemV1(msg.chatPayload))
218
- .filter((item) => item !== null)
219
- .sort((a, b) => {
220
- return (a.timestamp || 0) - (b.timestamp || 0);
221
- }) ?? [];
342
+ getRecentExchanges() {
343
+ // Filter out summaries but keep regular messages for the existing logic
344
+ const messages = this.messages.filter(isAiChatMessage);
345
+ return extractProductiveHistoryForContext(messages, {
346
+ maxAcceptedExchanges: 2,
347
+ includeRecentUnknown: true,
222
348
  });
223
- await this.inFlightLoadFromServer;
224
- this.loadedFromServer = "loaded";
225
349
  }
226
- catch (error) {
227
- this.logger.error("[ai-service] Failed to load chat messages from server", getErrorMeta(error));
350
+ async getMessages() {
351
+ await this.ensureLoadedFromServer();
352
+ return this.messages.filter(isAiChatMessage);
228
353
  }
229
- }
230
- getLastUserMessage() {
231
- const messages = this.messages.filter(isAiChatMessage);
232
- return getLastUserMessage(messages);
233
- }
234
- getRecentExchanges() {
235
- // Filter out summaries but keep regular messages for the existing logic
236
- const messages = this.messages.filter(isAiChatMessage);
237
- return extractProductiveHistoryForContext(messages, {
238
- maxAcceptedExchanges: 2,
239
- includeRecentUnknown: true,
240
- });
241
- }
242
- async getMessages() {
243
- await this.ensureLoadedFromServer();
244
- return this.messages.filter(isAiChatMessage);
245
- }
246
- async newChat() {
247
- try {
248
- await this.rpcClient.call(async (client) => {
249
- const applicationId = this.applicationId;
250
- return await client.call.v1.ai.chat.new({ applicationId });
251
- });
252
- this.messages = [];
253
- }
254
- catch (error) {
255
- this.logger.error("[ai-service] Failed to create new chat", getErrorMeta(error));
354
+ async newChat() {
355
+ try {
356
+ await this.rpcClient.call(async (client) => {
357
+ const applicationId = this.applicationId;
358
+ return await client.call.v1.ai.chat.new({ applicationId });
359
+ });
360
+ this.messages = [];
361
+ }
362
+ catch (error) {
363
+ this.logger.error("[ai-service] Failed to create new chat", getErrorMeta(error));
364
+ }
256
365
  }
257
- }
258
- async recordUser(text, options = {}) {
259
- const message = {
260
- role: "user",
261
- content: text,
262
- timestamp: Date.now(),
263
- type: "text",
264
- };
265
- if (options.attachments) {
266
- message.attachments = options.attachments;
366
+ async recordUser(text, options = {}) {
367
+ const message = {
368
+ role: "user",
369
+ content: text,
370
+ id: crypto.randomUUID(),
371
+ timestamp: Date.now(),
372
+ type: "text",
373
+ };
374
+ if (options.attachments) {
375
+ message.attachments = options.attachments;
376
+ }
377
+ await this.appendMessage(message);
267
378
  }
268
- await this.appendMessage(message);
269
- }
270
- async recordUserAcceptance() {
271
- const message = {
272
- role: "user",
273
- content: "",
274
- timestamp: Date.now(),
275
- type: "draftAccepted",
276
- };
277
- await this.appendMessage(message);
278
- }
279
- async recordUserRejection() {
280
- const message = {
281
- role: "user",
282
- content: "",
283
- timestamp: Date.now(),
284
- type: "draftRejected",
285
- };
286
- await this.appendMessage(message);
287
- }
288
- async recordAssistant(payload) {
289
- let message;
290
- if ("checklistData" in payload) {
291
- message = {
292
- role: "assistant",
293
- content: payload.text,
294
- type: "tool",
295
- group: "checklist",
296
- status: payload.status,
379
+ async recordUserAcceptance() {
380
+ const message = {
381
+ role: "user",
382
+ content: "",
383
+ id: crypto.randomUUID(),
297
384
  timestamp: Date.now(),
298
- checklistData: payload.checklistData,
385
+ type: "draftAccepted",
299
386
  };
387
+ await this.appendMessage(message);
300
388
  }
301
- else if (payload.type === "tool") {
302
- message = {
303
- role: "assistant",
389
+ async recordUserRejection() {
390
+ const message = {
391
+ role: "user",
304
392
  content: "",
305
- type: "tool",
306
- status: payload.status,
393
+ id: crypto.randomUUID(),
394
+ timestamp: Date.now(),
395
+ type: "draftRejected",
396
+ };
397
+ await this.appendMessage(message);
398
+ }
399
+ async recordUserResponse(text, responseType, metadata) {
400
+ const baseMessage = {
401
+ role: "user",
402
+ content: text,
403
+ id: crypto.randomUUID(),
307
404
  timestamp: Date.now(),
308
- args: payload.args,
309
- tool: payload.tool,
310
- group: "group" in payload ? payload.group : "",
405
+ type: responseType,
406
+ responseToMessageId: metadata.responseToMessageId,
311
407
  };
408
+ if (responseType === "multi_choice_response" &&
409
+ metadata.selectedChoiceIndices) {
410
+ baseMessage.selectedChoiceIndices =
411
+ metadata.selectedChoiceIndices;
412
+ }
413
+ await this.appendMessage(baseMessage);
312
414
  }
313
- else {
314
- message = {
415
+ async recordAssistant(payload) {
416
+ let message;
417
+ // Use ID from payload if present, otherwise generate new one
418
+ const messageId = payload.id ?? crypto.randomUUID();
419
+ if ("checklistData" in payload) {
420
+ message = {
421
+ role: "assistant",
422
+ content: payload.text,
423
+ type: "tool",
424
+ group: "checklist",
425
+ status: payload.status,
426
+ id: messageId,
427
+ timestamp: Date.now(),
428
+ checklistData: payload.checklistData,
429
+ };
430
+ }
431
+ else if (payload.type === "tool") {
432
+ message = {
433
+ role: "assistant",
434
+ content: "",
435
+ type: "tool",
436
+ status: payload.status,
437
+ id: messageId,
438
+ timestamp: Date.now(),
439
+ args: payload.args,
440
+ tool: payload.tool,
441
+ group: "group" in payload ? payload.group : "",
442
+ };
443
+ }
444
+ else {
445
+ message = {
446
+ role: "assistant",
447
+ content: payload.text,
448
+ type: payload.type || "text",
449
+ group: "group" in payload ? payload.group : "",
450
+ status: payload.status,
451
+ id: messageId,
452
+ timestamp: Date.now(),
453
+ ...("choices" in payload && payload.choices
454
+ ? { choices: payload.choices }
455
+ : {}),
456
+ ...("selectionType" in payload && payload.selectionType
457
+ ? { selectionType: payload.selectionType }
458
+ : {}),
459
+ };
460
+ }
461
+ await this.appendMessage(message);
462
+ }
463
+ async recordAssistantChangeInfo(payload) {
464
+ const message = {
315
465
  role: "assistant",
316
- content: payload.text,
317
- type: payload.type || "text",
318
- group: "group" in payload ? payload.group : "",
466
+ group: payload.type,
467
+ content: payload.name,
468
+ action: payload.action,
319
469
  status: payload.status,
470
+ type: "changeInfo",
471
+ id: crypto.randomUUID(),
320
472
  timestamp: Date.now(),
321
473
  };
474
+ await this.appendMessage(message);
322
475
  }
323
- await this.appendMessage(message);
324
- }
325
- async recordAssistantChangeInfo(payload) {
326
- const message = {
327
- role: "assistant",
328
- group: payload.type,
329
- content: payload.name,
330
- action: payload.action,
331
- status: payload.status,
332
- type: "changeInfo",
333
- timestamp: Date.now(),
334
- };
335
- await this.appendMessage(message);
336
- }
337
- async appendMessage(payload) {
338
- await this.ensureLoadedFromServer();
339
- this.messages.push(payload);
340
- try {
341
- await this.rpcClient.call(async (client) => {
342
- const applicationId = this.applicationId;
343
- return await client.call.v1.ai.chat.pushMessage({
344
- applicationId,
345
- payload: payload,
476
+ async appendMessage(message) {
477
+ await this.ensureLoadedFromServer();
478
+ this.messages.push(message);
479
+ const payload = {
480
+ ...message,
481
+ };
482
+ try {
483
+ await this.rpcClient.call(async (client) => {
484
+ const applicationId = this.applicationId;
485
+ return await client.call.v1.ai.chat.pushMessage({
486
+ applicationId,
487
+ payload,
488
+ });
346
489
  });
347
- });
348
- }
349
- catch (error) {
350
- this.logger.error("[ai-service] Failed to write chat message to server", getErrorMeta(error));
351
- }
352
- }
353
- determineSummaryOutcome(summary, allMessages) {
354
- // Find the index of this summary in all messages
355
- const summaryIndex = allMessages.findIndex((item) => isAiChatSummary(item) &&
356
- item.timestamp === summary.timestamp &&
357
- item.summary === summary.summary);
358
- if (summaryIndex === -1) {
359
- return "unknown";
490
+ }
491
+ catch (error) {
492
+ this.logger.error("[ai-service] Failed to write chat message to server", getErrorMeta(error));
493
+ }
360
494
  }
361
- // Look for acceptance/rejection messages after this summary
362
- const messagesAfterSummary = allMessages.slice(summaryIndex + 1);
363
- for (const item of messagesAfterSummary) {
364
- if (isAiChatMessage(item) && item.role === "user") {
365
- if (item.type === "draftAccepted") {
366
- return "accepted";
367
- }
368
- if (item.type === "draftRejected") {
369
- return "rejected";
495
+ determineSummaryOutcome(summary, allMessages) {
496
+ // Find the index of this summary in all messages
497
+ const summaryIndex = allMessages.findIndex((item) => isAiChatSummary(item) &&
498
+ item.timestamp === summary.timestamp &&
499
+ item.summary === summary.summary);
500
+ if (summaryIndex === -1) {
501
+ return "unknown";
502
+ }
503
+ // Look for acceptance/rejection messages after this summary
504
+ const messagesAfterSummary = allMessages.slice(summaryIndex + 1);
505
+ for (const item of messagesAfterSummary) {
506
+ if (isAiChatMessage(item) && item.role === "user") {
507
+ if (item.type === "draftAccepted") {
508
+ return "accepted";
509
+ }
510
+ if (item.type === "draftRejected") {
511
+ return "rejected";
512
+ }
370
513
  }
371
514
  }
515
+ return "unknown";
372
516
  }
373
- return "unknown";
374
- }
375
- async recordSummary(summaryData) {
376
- const summaryPayload = {
377
- ...summaryData,
378
- timestamp: Date.now(),
379
- };
380
- await this.appendMessage(summaryPayload);
381
- }
382
- async getSummaries() {
383
- await this.ensureLoadedFromServer();
384
- return this.messages.filter(isAiChatSummary);
385
- }
386
- async getLatestSummary() {
387
- return (await this.getLatestSummaries(1))[0];
388
- }
389
- async getLatestSummaries(count) {
390
- const summaries = await this.getSummaries();
391
- const sortedSummaries = summaries
392
- .sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0))
393
- .slice(0, count);
394
- // Add outcome information to each summary
395
- return sortedSummaries.map((summary) => ({
396
- ...summary,
397
- outcome: this.determineSummaryOutcome(summary, this.messages),
398
- }));
399
- }
400
- }
517
+ async recordSummary(summaryData) {
518
+ const summaryPayload = {
519
+ ...summaryData,
520
+ timestamp: Date.now(),
521
+ };
522
+ await this.appendMessage(summaryPayload);
523
+ }
524
+ async getSummaries() {
525
+ await this.ensureLoadedFromServer();
526
+ return this.messages.filter(isAiChatSummary);
527
+ }
528
+ async getLatestSummary() {
529
+ return (await this.getLatestSummaries(1))[0];
530
+ }
531
+ async getLatestSummaries(count) {
532
+ const summaries = await this.getSummaries();
533
+ const sortedSummaries = summaries
534
+ .sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0))
535
+ .slice(0, count);
536
+ // Add outcome information to each summary
537
+ return sortedSummaries.map((summary) => ({
538
+ ...summary,
539
+ outcome: this.determineSummaryOutcome(summary, this.messages),
540
+ }));
541
+ }
542
+ };
543
+ })();
544
+ export { ChatSessionStore };
401
545
  //# sourceMappingURL=chat-session-store.js.map