@buoy-gg/ask-buoy 7.0.38 → 7.0.40

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 (306) hide show
  1. package/lib/commonjs/blocks/AskBlocks.js +338 -1
  2. package/lib/commonjs/blocks/AskBlocks.js.map +1 -0
  3. package/lib/commonjs/blocks/BlockRenderer.js +262 -1
  4. package/lib/commonjs/blocks/BlockRenderer.js.map +1 -0
  5. package/lib/commonjs/blocks/ChromePrototypes.js +514 -1
  6. package/lib/commonjs/blocks/ChromePrototypes.js.map +1 -0
  7. package/lib/commonjs/blocks/DataBlocks.js +781 -1
  8. package/lib/commonjs/blocks/DataBlocks.js.map +1 -0
  9. package/lib/commonjs/blocks/ExtraBlocks.js +1860 -1
  10. package/lib/commonjs/blocks/ExtraBlocks.js.map +1 -0
  11. package/lib/commonjs/blocks/MediaBlocks.js +156 -1
  12. package/lib/commonjs/blocks/MediaBlocks.js.map +1 -0
  13. package/lib/commonjs/blocks/ReceiptBlocks.js +586 -1
  14. package/lib/commonjs/blocks/ReceiptBlocks.js.map +1 -0
  15. package/lib/commonjs/blocks/blockText.js +60 -1
  16. package/lib/commonjs/blocks/blockText.js.map +1 -0
  17. package/lib/commonjs/blocks/blockText.test.js +53 -1
  18. package/lib/commonjs/blocks/blockText.test.js.map +1 -0
  19. package/lib/commonjs/blocks/context.js +42 -1
  20. package/lib/commonjs/blocks/context.js.map +1 -0
  21. package/lib/commonjs/blocks/icons.js +96 -1
  22. package/lib/commonjs/blocks/icons.js.map +1 -0
  23. package/lib/commonjs/blocks/index.js +95 -1
  24. package/lib/commonjs/blocks/index.js.map +1 -0
  25. package/lib/commonjs/blocks/listRow.test.js +55 -1
  26. package/lib/commonjs/blocks/listRow.test.js.map +1 -0
  27. package/lib/commonjs/blocks/pageState.js +34 -1
  28. package/lib/commonjs/blocks/pageState.js.map +1 -0
  29. package/lib/commonjs/blocks/pageState.test.js +57 -1
  30. package/lib/commonjs/blocks/pageState.test.js.map +1 -0
  31. package/lib/commonjs/blocks/primitives.js +457 -1
  32. package/lib/commonjs/blocks/primitives.js.map +1 -0
  33. package/lib/commonjs/blocks/primitivesIndex.js +62 -1
  34. package/lib/commonjs/blocks/primitivesIndex.js.map +1 -0
  35. package/lib/commonjs/components/ApprovalCard.js +297 -1
  36. package/lib/commonjs/components/ApprovalCard.js.map +1 -0
  37. package/lib/commonjs/components/AskBuoyHeader.js +196 -1
  38. package/lib/commonjs/components/AskBuoyHeader.js.map +1 -0
  39. package/lib/commonjs/components/AskBuoyIcon.js +19 -1
  40. package/lib/commonjs/components/AskBuoyIcon.js.map +1 -0
  41. package/lib/commonjs/components/AskBuoyModal.js +479 -1
  42. package/lib/commonjs/components/AskBuoyModal.js.map +1 -0
  43. package/lib/commonjs/components/AskBuoySettings.js +181 -1
  44. package/lib/commonjs/components/AskBuoySettings.js.map +1 -0
  45. package/lib/commonjs/components/ChangesBar.js +211 -1
  46. package/lib/commonjs/components/ChangesBar.js.map +1 -0
  47. package/lib/commonjs/components/Composer.js +255 -1
  48. package/lib/commonjs/components/Composer.js.map +1 -0
  49. package/lib/commonjs/components/EmptyState.js +161 -1
  50. package/lib/commonjs/components/EmptyState.js.map +1 -0
  51. package/lib/commonjs/components/KeyboardPad.js +80 -1
  52. package/lib/commonjs/components/KeyboardPad.js.map +1 -0
  53. package/lib/commonjs/components/Markdown.js +310 -1
  54. package/lib/commonjs/components/Markdown.js.map +1 -0
  55. package/lib/commonjs/components/MessageList.js +970 -1
  56. package/lib/commonjs/components/MessageList.js.map +1 -0
  57. package/lib/commonjs/components/QueuedMessages.js +145 -1
  58. package/lib/commonjs/components/QueuedMessages.js.map +1 -0
  59. package/lib/commonjs/components/ThinkingStrip.js +223 -1
  60. package/lib/commonjs/components/ThinkingStrip.js.map +1 -0
  61. package/lib/commonjs/components/TypingDots.js +63 -1
  62. package/lib/commonjs/components/TypingDots.js.map +1 -0
  63. package/lib/commonjs/components/markdownParse.js +131 -1
  64. package/lib/commonjs/components/markdownParse.js.map +1 -0
  65. package/lib/commonjs/components/markdownParse.test.js +99 -1
  66. package/lib/commonjs/components/markdownParse.test.js.map +1 -0
  67. package/lib/commonjs/components/useCopyAction.js +50 -1
  68. package/lib/commonjs/components/useCopyAction.js.map +1 -0
  69. package/lib/commonjs/index.js +252 -1
  70. package/lib/commonjs/index.js.map +1 -0
  71. package/lib/commonjs/preset.js +91 -1
  72. package/lib/commonjs/preset.js.map +1 -0
  73. package/lib/commonjs/store/activityGroups.js +110 -1
  74. package/lib/commonjs/store/activityGroups.js.map +1 -0
  75. package/lib/commonjs/store/activityGroups.test.js +78 -1
  76. package/lib/commonjs/store/activityGroups.test.js.map +1 -0
  77. package/lib/commonjs/store/askBuoySettings.js +72 -1
  78. package/lib/commonjs/store/askBuoySettings.js.map +1 -0
  79. package/lib/commonjs/store/askBuoyStore.js +589 -1
  80. package/lib/commonjs/store/askBuoyStore.js.map +1 -0
  81. package/lib/commonjs/store/blockPlacement.js +64 -1
  82. package/lib/commonjs/store/blockPlacement.js.map +1 -0
  83. package/lib/commonjs/store/blockPlacement.test.js +123 -1
  84. package/lib/commonjs/store/blockPlacement.test.js.map +1 -0
  85. package/lib/commonjs/store/queue.test.js +150 -1
  86. package/lib/commonjs/store/queue.test.js.map +1 -0
  87. package/lib/commonjs/store/resetConversation.js +77 -1
  88. package/lib/commonjs/store/resetConversation.js.map +1 -0
  89. package/lib/commonjs/store/restorePending.test.js +63 -1
  90. package/lib/commonjs/store/restorePending.test.js.map +1 -0
  91. package/lib/commonjs/store/restoredIds.test.js +47 -1
  92. package/lib/commonjs/store/restoredIds.test.js.map +1 -0
  93. package/lib/commonjs/store/suggestions.js +54 -1
  94. package/lib/commonjs/store/suggestions.js.map +1 -0
  95. package/lib/commonjs/store/suggestions.test.js +58 -1
  96. package/lib/commonjs/store/suggestions.test.js.map +1 -0
  97. package/lib/commonjs/store/systemLine.test.js +77 -1
  98. package/lib/commonjs/store/systemLine.test.js.map +1 -0
  99. package/lib/commonjs/store/ticketPrompt.js +17 -1
  100. package/lib/commonjs/store/ticketPrompt.js.map +1 -0
  101. package/lib/commonjs/store/traceText.js +81 -1
  102. package/lib/commonjs/store/traceText.js.map +1 -0
  103. package/lib/commonjs/store/traceText.test.js +112 -1
  104. package/lib/commonjs/store/traceText.test.js.map +1 -0
  105. package/lib/commonjs/store/transcriptPersistence.js +297 -1
  106. package/lib/commonjs/store/transcriptPersistence.js.map +1 -0
  107. package/lib/commonjs/store/transcriptPersistence.test.js +333 -1
  108. package/lib/commonjs/store/transcriptPersistence.test.js.map +1 -0
  109. package/lib/commonjs/store/turnRendering.test.js +151 -1
  110. package/lib/commonjs/store/turnRendering.test.js.map +1 -0
  111. package/lib/commonjs/store/useAskBuoy.js +651 -1
  112. package/lib/commonjs/store/useAskBuoy.js.map +1 -0
  113. package/lib/commonjs/store/useAskBuoySettings.js +14 -1
  114. package/lib/commonjs/store/useAskBuoySettings.js.map +1 -0
  115. package/lib/commonjs/sync/askBuoySyncAdapter.js +153 -1
  116. package/lib/commonjs/sync/askBuoySyncAdapter.js.map +1 -0
  117. package/lib/commonjs/sync/askBuoySyncAdapter.test.js +141 -1
  118. package/lib/commonjs/sync/askBuoySyncAdapter.test.js.map +1 -0
  119. package/lib/commonjs/sync/wire.js +58 -1
  120. package/lib/commonjs/sync/wire.js.map +1 -0
  121. package/lib/commonjs/types.js +6 -1
  122. package/lib/commonjs/types.js.map +1 -0
  123. package/lib/module/blocks/AskBlocks.js +331 -1
  124. package/lib/module/blocks/AskBlocks.js.map +1 -0
  125. package/lib/module/blocks/BlockRenderer.js +257 -1
  126. package/lib/module/blocks/BlockRenderer.js.map +1 -0
  127. package/lib/module/blocks/ChromePrototypes.js +503 -1
  128. package/lib/module/blocks/ChromePrototypes.js.map +1 -0
  129. package/lib/module/blocks/DataBlocks.js +767 -1
  130. package/lib/module/blocks/DataBlocks.js.map +1 -0
  131. package/lib/module/blocks/ExtraBlocks.js +1833 -1
  132. package/lib/module/blocks/ExtraBlocks.js.map +1 -0
  133. package/lib/module/blocks/MediaBlocks.js +151 -1
  134. package/lib/module/blocks/MediaBlocks.js.map +1 -0
  135. package/lib/module/blocks/ReceiptBlocks.js +574 -1
  136. package/lib/module/blocks/ReceiptBlocks.js.map +1 -0
  137. package/lib/module/blocks/blockText.js +55 -1
  138. package/lib/module/blocks/blockText.js.map +1 -0
  139. package/lib/module/blocks/blockText.test.js +53 -1
  140. package/lib/module/blocks/blockText.test.js.map +1 -0
  141. package/lib/module/blocks/context.js +35 -1
  142. package/lib/module/blocks/context.js.map +1 -0
  143. package/lib/module/blocks/icons.js +91 -1
  144. package/lib/module/blocks/icons.js.map +1 -0
  145. package/lib/module/blocks/index.js +8 -1
  146. package/lib/module/blocks/index.js.map +1 -0
  147. package/lib/module/blocks/listRow.test.js +56 -1
  148. package/lib/module/blocks/listRow.test.js.map +1 -0
  149. package/lib/module/blocks/pageState.js +30 -1
  150. package/lib/module/blocks/pageState.js.map +1 -0
  151. package/lib/module/blocks/pageState.test.js +56 -1
  152. package/lib/module/blocks/pageState.test.js.map +1 -0
  153. package/lib/module/blocks/primitives.js +445 -1
  154. package/lib/module/blocks/primitives.js.map +1 -0
  155. package/lib/module/blocks/primitivesIndex.js +5 -1
  156. package/lib/module/blocks/primitivesIndex.js.map +1 -0
  157. package/lib/module/components/ApprovalCard.js +292 -1
  158. package/lib/module/components/ApprovalCard.js.map +1 -0
  159. package/lib/module/components/AskBuoyHeader.js +193 -1
  160. package/lib/module/components/AskBuoyHeader.js.map +1 -0
  161. package/lib/module/components/AskBuoyIcon.js +8 -1
  162. package/lib/module/components/AskBuoyIcon.js.map +1 -0
  163. package/lib/module/components/AskBuoyModal.js +474 -1
  164. package/lib/module/components/AskBuoyModal.js.map +1 -0
  165. package/lib/module/components/AskBuoySettings.js +176 -1
  166. package/lib/module/components/AskBuoySettings.js.map +1 -0
  167. package/lib/module/components/ChangesBar.js +206 -1
  168. package/lib/module/components/ChangesBar.js.map +1 -0
  169. package/lib/module/components/Composer.js +250 -1
  170. package/lib/module/components/Composer.js.map +1 -0
  171. package/lib/module/components/EmptyState.js +156 -1
  172. package/lib/module/components/EmptyState.js.map +1 -0
  173. package/lib/module/components/KeyboardPad.js +75 -1
  174. package/lib/module/components/KeyboardPad.js.map +1 -0
  175. package/lib/module/components/Markdown.js +305 -1
  176. package/lib/module/components/Markdown.js.map +1 -0
  177. package/lib/module/components/MessageList.js +964 -1
  178. package/lib/module/components/MessageList.js.map +1 -0
  179. package/lib/module/components/QueuedMessages.js +140 -1
  180. package/lib/module/components/QueuedMessages.js.map +1 -0
  181. package/lib/module/components/ThinkingStrip.js +218 -1
  182. package/lib/module/components/ThinkingStrip.js.map +1 -0
  183. package/lib/module/components/TypingDots.js +58 -1
  184. package/lib/module/components/TypingDots.js.map +1 -0
  185. package/lib/module/components/markdownParse.js +125 -1
  186. package/lib/module/components/markdownParse.js.map +1 -0
  187. package/lib/module/components/markdownParse.test.js +98 -1
  188. package/lib/module/components/markdownParse.test.js.map +1 -0
  189. package/lib/module/components/useCopyAction.js +46 -1
  190. package/lib/module/components/useCopyAction.js.map +1 -0
  191. package/lib/module/index.js +34 -1
  192. package/lib/module/index.js.map +1 -0
  193. package/lib/module/preset.js +74 -1
  194. package/lib/module/preset.js.map +1 -0
  195. package/lib/module/store/activityGroups.js +103 -1
  196. package/lib/module/store/activityGroups.js.map +1 -0
  197. package/lib/module/store/activityGroups.test.js +77 -1
  198. package/lib/module/store/activityGroups.test.js.map +1 -0
  199. package/lib/module/store/askBuoySettings.js +67 -1
  200. package/lib/module/store/askBuoySettings.js.map +1 -0
  201. package/lib/module/store/askBuoyStore.js +583 -1
  202. package/lib/module/store/askBuoyStore.js.map +1 -0
  203. package/lib/module/store/blockPlacement.js +59 -1
  204. package/lib/module/store/blockPlacement.js.map +1 -0
  205. package/lib/module/store/blockPlacement.test.js +122 -1
  206. package/lib/module/store/blockPlacement.test.js.map +1 -0
  207. package/lib/module/store/queue.test.js +149 -1
  208. package/lib/module/store/queue.test.js.map +1 -0
  209. package/lib/module/store/resetConversation.js +72 -1
  210. package/lib/module/store/resetConversation.js.map +1 -0
  211. package/lib/module/store/restorePending.test.js +62 -1
  212. package/lib/module/store/restorePending.test.js.map +1 -0
  213. package/lib/module/store/restoredIds.test.js +46 -1
  214. package/lib/module/store/restoredIds.test.js.map +1 -0
  215. package/lib/module/store/suggestions.js +49 -1
  216. package/lib/module/store/suggestions.js.map +1 -0
  217. package/lib/module/store/suggestions.test.js +57 -1
  218. package/lib/module/store/suggestions.test.js.map +1 -0
  219. package/lib/module/store/systemLine.test.js +76 -1
  220. package/lib/module/store/systemLine.test.js.map +1 -0
  221. package/lib/module/store/ticketPrompt.js +13 -1
  222. package/lib/module/store/ticketPrompt.js.map +1 -0
  223. package/lib/module/store/traceText.js +75 -1
  224. package/lib/module/store/traceText.js.map +1 -0
  225. package/lib/module/store/traceText.test.js +111 -1
  226. package/lib/module/store/traceText.test.js.map +1 -0
  227. package/lib/module/store/transcriptPersistence.js +287 -1
  228. package/lib/module/store/transcriptPersistence.js.map +1 -0
  229. package/lib/module/store/transcriptPersistence.test.js +332 -1
  230. package/lib/module/store/transcriptPersistence.test.js.map +1 -0
  231. package/lib/module/store/turnRendering.test.js +150 -1
  232. package/lib/module/store/turnRendering.test.js.map +1 -0
  233. package/lib/module/store/useAskBuoy.js +646 -1
  234. package/lib/module/store/useAskBuoy.js.map +1 -0
  235. package/lib/module/store/useAskBuoySettings.js +9 -1
  236. package/lib/module/store/useAskBuoySettings.js.map +1 -0
  237. package/lib/module/sync/askBuoySyncAdapter.js +148 -1
  238. package/lib/module/sync/askBuoySyncAdapter.js.map +1 -0
  239. package/lib/module/sync/askBuoySyncAdapter.test.js +140 -1
  240. package/lib/module/sync/askBuoySyncAdapter.test.js.map +1 -0
  241. package/lib/module/sync/wire.js +47 -1
  242. package/lib/module/sync/wire.js.map +1 -0
  243. package/lib/module/types.js +4 -1
  244. package/lib/module/types.js.map +1 -0
  245. package/lib/typescript/blocks/AskBlocks.d.ts.map +1 -0
  246. package/lib/typescript/blocks/BlockRenderer.d.ts.map +1 -0
  247. package/lib/typescript/blocks/ChromePrototypes.d.ts.map +1 -0
  248. package/lib/typescript/blocks/DataBlocks.d.ts.map +1 -0
  249. package/lib/typescript/blocks/ExtraBlocks.d.ts.map +1 -0
  250. package/lib/typescript/blocks/MediaBlocks.d.ts.map +1 -0
  251. package/lib/typescript/blocks/ReceiptBlocks.d.ts.map +1 -0
  252. package/lib/typescript/blocks/blockText.d.ts.map +1 -0
  253. package/lib/typescript/blocks/blockText.test.d.ts.map +1 -0
  254. package/lib/typescript/blocks/context.d.ts.map +1 -0
  255. package/lib/typescript/blocks/icons.d.ts.map +1 -0
  256. package/lib/typescript/blocks/index.d.ts.map +1 -0
  257. package/lib/typescript/blocks/listRow.test.d.ts.map +1 -0
  258. package/lib/typescript/blocks/pageState.d.ts.map +1 -0
  259. package/lib/typescript/blocks/pageState.test.d.ts.map +1 -0
  260. package/lib/typescript/blocks/primitives.d.ts.map +1 -0
  261. package/lib/typescript/blocks/primitivesIndex.d.ts.map +1 -0
  262. package/lib/typescript/components/ApprovalCard.d.ts.map +1 -0
  263. package/lib/typescript/components/AskBuoyHeader.d.ts.map +1 -0
  264. package/lib/typescript/components/AskBuoyIcon.d.ts.map +1 -0
  265. package/lib/typescript/components/AskBuoyModal.d.ts.map +1 -0
  266. package/lib/typescript/components/AskBuoySettings.d.ts.map +1 -0
  267. package/lib/typescript/components/ChangesBar.d.ts.map +1 -0
  268. package/lib/typescript/components/Composer.d.ts.map +1 -0
  269. package/lib/typescript/components/EmptyState.d.ts.map +1 -0
  270. package/lib/typescript/components/KeyboardPad.d.ts.map +1 -0
  271. package/lib/typescript/components/Markdown.d.ts.map +1 -0
  272. package/lib/typescript/components/MessageList.d.ts.map +1 -0
  273. package/lib/typescript/components/QueuedMessages.d.ts.map +1 -0
  274. package/lib/typescript/components/ThinkingStrip.d.ts.map +1 -0
  275. package/lib/typescript/components/TypingDots.d.ts.map +1 -0
  276. package/lib/typescript/components/markdownParse.d.ts.map +1 -0
  277. package/lib/typescript/components/markdownParse.test.d.ts.map +1 -0
  278. package/lib/typescript/components/useCopyAction.d.ts.map +1 -0
  279. package/lib/typescript/index.d.ts.map +1 -0
  280. package/lib/typescript/preset.d.ts.map +1 -0
  281. package/lib/typescript/store/activityGroups.d.ts.map +1 -0
  282. package/lib/typescript/store/activityGroups.test.d.ts.map +1 -0
  283. package/lib/typescript/store/askBuoySettings.d.ts.map +1 -0
  284. package/lib/typescript/store/askBuoyStore.d.ts.map +1 -0
  285. package/lib/typescript/store/blockPlacement.d.ts.map +1 -0
  286. package/lib/typescript/store/blockPlacement.test.d.ts.map +1 -0
  287. package/lib/typescript/store/queue.test.d.ts.map +1 -0
  288. package/lib/typescript/store/resetConversation.d.ts.map +1 -0
  289. package/lib/typescript/store/restorePending.test.d.ts.map +1 -0
  290. package/lib/typescript/store/restoredIds.test.d.ts.map +1 -0
  291. package/lib/typescript/store/suggestions.d.ts.map +1 -0
  292. package/lib/typescript/store/suggestions.test.d.ts.map +1 -0
  293. package/lib/typescript/store/systemLine.test.d.ts.map +1 -0
  294. package/lib/typescript/store/ticketPrompt.d.ts.map +1 -0
  295. package/lib/typescript/store/traceText.d.ts.map +1 -0
  296. package/lib/typescript/store/traceText.test.d.ts.map +1 -0
  297. package/lib/typescript/store/transcriptPersistence.d.ts.map +1 -0
  298. package/lib/typescript/store/transcriptPersistence.test.d.ts.map +1 -0
  299. package/lib/typescript/store/turnRendering.test.d.ts.map +1 -0
  300. package/lib/typescript/store/useAskBuoy.d.ts.map +1 -0
  301. package/lib/typescript/store/useAskBuoySettings.d.ts.map +1 -0
  302. package/lib/typescript/sync/askBuoySyncAdapter.d.ts.map +1 -0
  303. package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts.map +1 -0
  304. package/lib/typescript/sync/wire.d.ts.map +1 -0
  305. package/lib/typescript/types.d.ts.map +1 -0
  306. package/package.json +8 -8
@@ -1 +1,297 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TRANSCRIPT_KEY=void 0,exports.buildPayload=buildPayload,exports.clearTranscript=clearTranscript,exports.fitToCaps=fitToCaps,exports.parsePayload=parsePayload,exports.readTranscript=readTranscript,exports.writeTranscript=writeTranscript;var _sharedUi=require("@buoy-gg/shared-ui"),_wire=require("../sync/wire");const TRANSCRIPT_KEY=exports.TRANSCRIPT_KEY=`${_sharedUi.devToolsStorageKeys.base}_ask_buoy_transcript`,VERSION=1,MAX_MESSAGES=60,MAX_BYTES=256e3,DROPPED_RESULT="[not kept across a restart — read it again if you need it]";function scrub(e){return e?(0,_wire.redactForWire)(e):e}function settle(e){const r=!0===e.streaming;return{...e,text:scrub(e.text),streaming:!1,reasoning:e.reasoning?.map(e=>({...e,text:scrub(e.text)})),toolCalls:e.toolCalls.map(e=>{const r=e.params?scrub(e.params):void 0,{result:t,...s}=e;return"running"===e.status?{...s,params:r,status:"failed",summary:"Interrupted"}:{...s,params:r}}),error:e.error??(r&&!e.text?"This answer was interrupted — the app restarted mid-turn.":void 0)}}function withoutResults(e){return e.map(e=>"tool-results"===e.role?{...e,results:e.results.map(e=>({...e,content:DROPPED_RESULT}))}:(e.role,{...e,text:scrub(e.text)}))}function fitToCaps(e){let r={...e,messages:e.messages.slice(-MAX_MESSAGES),history:e.history.slice(2*-MAX_MESSAGES)},t=JSON.stringify(r);for(;t.length>MAX_BYTES&&r.messages.length>1;)r={...r,messages:r.messages.slice(1),history:r.history.slice(Math.min(2,r.history.length))},t=JSON.stringify(r);return r}function storableApproval(e){if(!e)return null;const r=e.params;if(!r)return null;let t;try{t=JSON.stringify(r)}catch{return null}return(0,_wire.redactForWire)(t)!==t?null:{id:e.id,toolId:e.toolId,action:e.action,label:scrub(e.label),description:e.description?scrub(e.description):void 0,reason:scrub(e.reason),params:r,targetDigest:e.targetDigest}}function isStoredApproval(e){if("object"!=typeof e||null===e)return!1;const r=e;return"string"==typeof r.id&&"string"==typeof r.toolId&&"string"==typeof r.action&&"string"==typeof r.label&&"string"==typeof r.reason&&"object"==typeof r.params&&null!==r.params}function storableLedger(e){if(!e?.length)return;const r=e.filter(e=>{try{const r=JSON.stringify(e);return(0,_wire.redactForWire)(r)===r}catch{return!1}});return r.length?r:void 0}function buildPayload(e){return fitToCaps({v:VERSION,savedAt:Date.now(),messages:e.messages.map(settle),history:withoutResults(e.history),answers:e.answers,usage:e.usage,pending:storableApproval(e.pending),ledger:storableLedger(e.ledger),queued:e.queued?.length?e.queued.map(e=>({id:e.id,text:scrub(e.text)})):void 0})}function parsePayload(e){if(!e)return null;try{const r=JSON.parse(e);return r?.v===VERSION&&Array.isArray(r.messages)?0===r.messages.length?null:{v:VERSION,savedAt:"number"==typeof r.savedAt?r.savedAt:0,messages:r.messages,history:Array.isArray(r.history)?r.history:[],answers:r.answers??{},usage:r.usage??{input:0,output:0,requests:0},pending:isStoredApproval(r.pending)?r.pending:null,ledger:Array.isArray(r.ledger)?r.ledger.filter(e=>"object"==typeof e&&null!==e&&"string"==typeof e.id):void 0,queued:Array.isArray(r.queued)?r.queued.filter(e=>"object"==typeof e&&null!==e&&"string"==typeof e.id&&"string"==typeof e.text):void 0}:null}catch{return null}}async function readTranscript(){try{return parsePayload(await _sharedUi.persistentStorage.getItem(TRANSCRIPT_KEY))}catch{return null}}async function writeTranscript(e){try{await _sharedUi.persistentStorage.setItem(TRANSCRIPT_KEY,JSON.stringify(e))}catch{}}async function clearTranscript(){try{await _sharedUi.persistentStorage.removeItem(TRANSCRIPT_KEY)}catch{}}
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TRANSCRIPT_KEY = void 0;
7
+ exports.buildPayload = buildPayload;
8
+ exports.clearTranscript = clearTranscript;
9
+ exports.fitToCaps = fitToCaps;
10
+ exports.parsePayload = parsePayload;
11
+ exports.readTranscript = readTranscript;
12
+ exports.writeTranscript = writeTranscript;
13
+ var _sharedUi = require("@buoy-gg/shared-ui");
14
+ var _wire = require("../sync/wire");
15
+ /**
16
+ * The conversation, across a reload or a crash.
17
+ *
18
+ * This reverses a deliberate earlier decision, so the reasoning is worth
19
+ * stating. The transcript used to live only in memory because it can quote
20
+ * anything the agent read — a storage value, a response body, a customer
21
+ * record — and a Buoy key on disk is readable by the Storage tool, which the
22
+ * unauthenticated broker mirrors to every connected dashboard. That risk did
23
+ * not go away; it is now a trade the host app makes knowingly, and can decline
24
+ * with `askBuoy={{ persistTranscript: false }}`.
25
+ *
26
+ * What lowers it:
27
+ * - Tool RESULTS are never written. The model's saved history keeps the shape
28
+ * of each round (which tool ran, what it was asked) and replaces every result
29
+ * payload with a placeholder — so the agent resumes knowing what it did, not
30
+ * what it saw. Raw payloads are the sensitive part and they stay in memory.
31
+ * - Everything written passes `redactForWire`, the same credential scrubber the
32
+ * broker wire uses.
33
+ * - It is capped, oldest-first, so a long QA session cannot grow a file without
34
+ * bound.
35
+ * - "New conversation" deletes it, rather than leaving the last chat on disk.
36
+ */
37
+
38
+ /** `@react_buoy` prefix, so the Storage tool treats it as one of its own. */
39
+ const TRANSCRIPT_KEY = exports.TRANSCRIPT_KEY = `${_sharedUi.devToolsStorageKeys.base}_ask_buoy_transcript`;
40
+
41
+ /**
42
+ * Bumped when the saved shape changes; an older payload is dropped, not parsed.
43
+ *
44
+ * Purely ADDITIVE optional fields do not bump it — `pending` reads back as
45
+ * absent from a v1 file written before it existed, and throwing away someone's
46
+ * conversation to add a field they did not have is a worse trade than the one
47
+ * this version number exists to make.
48
+ */
49
+ const VERSION = 1;
50
+
51
+ /** Newest N bubbles. Beyond this a reader is scrolling history, not testing. */
52
+ const MAX_MESSAGES = 60;
53
+
54
+ /**
55
+ * Hard ceiling on the file. Blocks carry image URLs and table rows, so a
56
+ * message is not a small object; this is checked AFTER the message cap and
57
+ * drops from the oldest end until it fits.
58
+ */
59
+ const MAX_BYTES = 256_000;
60
+
61
+ /** What replaces a tool result. Addressed to the model, which will read it. */
62
+ const DROPPED_RESULT = "[not kept across a restart — read it again if you need it]";
63
+
64
+ /**
65
+ * An approval the user never answered.
66
+ *
67
+ * Saved with the conversation because an unanswered question is exactly the
68
+ * state a reload must not quietly resolve for them: nothing was tapped, so the
69
+ * change is still pending as far as they know. `params` is the real call —
70
+ * after a restart there is no turn left to resume, so Allow re-dispatches it.
71
+ */
72
+
73
+ function scrub(text) {
74
+ return text ? (0, _wire.redactForWire)(text) : text;
75
+ }
76
+
77
+ /**
78
+ * A bubble as it should look after a restart.
79
+ *
80
+ * `streaming` is cleared because nothing is streaming into a bubble the app
81
+ * has just rebuilt, and a message caught mid-turn is marked as interrupted
82
+ * rather than left looking like a silent, empty answer — which is exactly the
83
+ * crash case this feature exists for. `actionState` is not saved at all: a
84
+ * button stuck on "running" would be a lie about work that died with the
85
+ * process.
86
+ */
87
+ function settle(m) {
88
+ const cutOff = m.streaming === true;
89
+ return {
90
+ ...m,
91
+ text: scrub(m.text),
92
+ streaming: false,
93
+ // The thinking view's payloads go through the same scrubber as the answer:
94
+ // step parameters carry whatever the model passed a tool, which is exactly
95
+ // where a token ends up when the agent has been asked to set one.
96
+ reasoning: m.reasoning?.map(r => ({
97
+ ...r,
98
+ text: scrub(r.text)
99
+ })),
100
+ toolCalls: m.toolCalls.map(c => {
101
+ const params = c.params ? scrub(c.params) : undefined;
102
+ // `result` is dropped, never scrubbed. It is the tool payload itself —
103
+ // a store's whole state, a response body — and "tool results are never
104
+ // written to disk" is the promise this file is built on. It stays in
105
+ // memory for the thinking view and the JSON export.
106
+ const {
107
+ result: _dropped,
108
+ ...rest
109
+ } = c;
110
+ return c.status === "running" ? {
111
+ ...rest,
112
+ params,
113
+ status: "failed",
114
+ summary: "Interrupted"
115
+ } : {
116
+ ...rest,
117
+ params
118
+ };
119
+ }),
120
+ error: m.error ?? (cutOff && !m.text ? "This answer was interrupted — the app restarted mid-turn." : undefined)
121
+ };
122
+ }
123
+
124
+ /** Model history with every tool result replaced by a placeholder. */
125
+ function withoutResults(history) {
126
+ return history.map(m => {
127
+ if (m.role === "tool-results") {
128
+ return {
129
+ ...m,
130
+ results: m.results.map(r => ({
131
+ ...r,
132
+ content: DROPPED_RESULT
133
+ }))
134
+ };
135
+ }
136
+ if (m.role === "assistant") return {
137
+ ...m,
138
+ text: scrub(m.text)
139
+ };
140
+ return {
141
+ ...m,
142
+ text: scrub(m.text)
143
+ };
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Trim to the caps. Messages and history are trimmed together and from the
149
+ * same end, so what the user sees and what the model remembers stay the same
150
+ * conversation rather than drifting apart across restarts.
151
+ */
152
+ function fitToCaps(payload) {
153
+ let out = {
154
+ ...payload,
155
+ messages: payload.messages.slice(-MAX_MESSAGES),
156
+ history: payload.history.slice(-MAX_MESSAGES * 2)
157
+ };
158
+ let json = JSON.stringify(out);
159
+ while (json.length > MAX_BYTES && out.messages.length > 1) {
160
+ out = {
161
+ ...out,
162
+ messages: out.messages.slice(1),
163
+ history: out.history.slice(Math.min(2, out.history.length))
164
+ };
165
+ json = JSON.stringify(out);
166
+ }
167
+ return out;
168
+ }
169
+
170
+ /**
171
+ * The pending approval, if it is safe to bring back.
172
+ *
173
+ * Params are NOT scrubbed on the way out, and that is the point of the check:
174
+ * a redacted token written back into the call is no longer the change the user
175
+ * was asked about, so re-running it would apply something they never saw. A
176
+ * call the wire scrubber touches at all is therefore not persisted — an action
177
+ * carrying a credential is precisely the one that should not come back after a
178
+ * restart and run itself. The card is lost in that case, which is the same
179
+ * behaviour as before this existed.
180
+ */
181
+ function storableApproval(pending) {
182
+ // A RESTORED card is saved again too: reloading twice without answering must
183
+ // not be the thing that finally loses the question.
184
+ if (!pending) return null;
185
+ const params = pending.params;
186
+ if (!params) return null;
187
+ let json;
188
+ try {
189
+ json = JSON.stringify(params);
190
+ } catch {
191
+ return null;
192
+ }
193
+ if ((0, _wire.redactForWire)(json) !== json) return null;
194
+ return {
195
+ id: pending.id,
196
+ toolId: pending.toolId,
197
+ action: pending.action,
198
+ label: scrub(pending.label),
199
+ description: pending.description ? scrub(pending.description) : undefined,
200
+ reason: scrub(pending.reason),
201
+ params,
202
+ targetDigest: pending.targetDigest
203
+ };
204
+ }
205
+ function isStoredApproval(value) {
206
+ if (typeof value !== "object" || value === null) return false;
207
+ const v = value;
208
+ return typeof v.id === "string" && typeof v.toolId === "string" && typeof v.action === "string" && typeof v.label === "string" && typeof v.reason === "string" && typeof v.params === "object" && v.params !== null;
209
+ }
210
+
211
+ /**
212
+ * Ledger entries safe to write.
213
+ *
214
+ * Same rule as `storableApproval`: an entry the wire scrubber would touch
215
+ * carries a credential in the value it is holding for the undo, and scrubbing
216
+ * it would make the undo restore a redacted string over the real one. Such an
217
+ * entry is dropped rather than rewritten — losing an undo is recoverable,
218
+ * writing "[redacted]" into the user's storage is not.
219
+ */
220
+ function storableLedger(entries) {
221
+ if (!entries?.length) return undefined;
222
+ const kept = entries.filter(e => {
223
+ try {
224
+ const json = JSON.stringify(e);
225
+ return (0, _wire.redactForWire)(json) === json;
226
+ } catch {
227
+ return false;
228
+ }
229
+ });
230
+ return kept.length ? kept : undefined;
231
+ }
232
+ function buildPayload(input) {
233
+ return fitToCaps({
234
+ v: VERSION,
235
+ savedAt: Date.now(),
236
+ messages: input.messages.map(settle),
237
+ history: withoutResults(input.history),
238
+ answers: input.answers,
239
+ usage: input.usage,
240
+ pending: storableApproval(input.pending),
241
+ ledger: storableLedger(input.ledger),
242
+ queued: input.queued?.length ? input.queued.map(q => ({
243
+ id: q.id,
244
+ text: scrub(q.text)
245
+ })) : undefined
246
+ });
247
+ }
248
+
249
+ /** Anything unparseable, or from an older shape, is treated as "no transcript". */
250
+ function parsePayload(raw) {
251
+ if (!raw) return null;
252
+ try {
253
+ const parsed = JSON.parse(raw);
254
+ if (parsed?.v !== VERSION || !Array.isArray(parsed.messages)) return null;
255
+ if (parsed.messages.length === 0) return null;
256
+ return {
257
+ v: VERSION,
258
+ savedAt: typeof parsed.savedAt === "number" ? parsed.savedAt : 0,
259
+ messages: parsed.messages,
260
+ history: Array.isArray(parsed.history) ? parsed.history : [],
261
+ answers: parsed.answers ?? {},
262
+ usage: parsed.usage ?? {
263
+ input: 0,
264
+ output: 0,
265
+ requests: 0
266
+ },
267
+ pending: isStoredApproval(parsed.pending) ? parsed.pending : null,
268
+ ledger: Array.isArray(parsed.ledger) ? parsed.ledger.filter(e => typeof e === "object" && e !== null && typeof e.id === "string") : undefined,
269
+ queued: Array.isArray(parsed.queued) ? parsed.queued.filter(q => typeof q === "object" && q !== null && typeof q.id === "string" && typeof q.text === "string") : undefined
270
+ };
271
+ } catch {
272
+ return null;
273
+ }
274
+ }
275
+ async function readTranscript() {
276
+ try {
277
+ return parsePayload(await _sharedUi.persistentStorage.getItem(TRANSCRIPT_KEY));
278
+ } catch {
279
+ return null;
280
+ }
281
+ }
282
+ async function writeTranscript(payload) {
283
+ try {
284
+ await _sharedUi.persistentStorage.setItem(TRANSCRIPT_KEY, JSON.stringify(payload));
285
+ } catch {
286
+ // A transcript that cannot be saved must never break the chat that
287
+ // produced it.
288
+ }
289
+ }
290
+ async function clearTranscript() {
291
+ try {
292
+ await _sharedUi.persistentStorage.removeItem(TRANSCRIPT_KEY);
293
+ } catch {
294
+ /* nothing to do — see writeTranscript */
295
+ }
296
+ }
297
+ //# sourceMappingURL=transcriptPersistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_sharedUi","require","_wire","TRANSCRIPT_KEY","exports","devToolsStorageKeys","base","VERSION","MAX_MESSAGES","MAX_BYTES","DROPPED_RESULT","scrub","text","redactForWire","settle","m","cutOff","streaming","reasoning","map","r","toolCalls","c","params","undefined","result","_dropped","rest","status","summary","error","withoutResults","history","role","results","content","fitToCaps","payload","out","messages","slice","json","JSON","stringify","length","Math","min","storableApproval","pending","id","toolId","action","label","description","reason","targetDigest","isStoredApproval","value","v","storableLedger","entries","kept","filter","e","buildPayload","input","savedAt","Date","now","answers","usage","ledger","queued","q","parsePayload","raw","parsed","parse","Array","isArray","output","requests","readTranscript","persistentStorage","getItem","writeTranscript","setItem","clearTranscript","removeItem"],"sourceRoot":"../../../src","sources":["store/transcriptPersistence.ts"],"mappings":";;;;;;;;;;;;AAsBA,IAAAA,SAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AA1BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACO,MAAME,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,GAAGE,6BAAmB,CAACC,IAAI,sBAAsB;;AAE/E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,OAAO,GAAG,CAAC;;AAEjB;AACA,MAAMC,YAAY,GAAG,EAAE;;AAEvB;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG,OAAO;;AAEzB;AACA,MAAMC,cAAc,GAAG,4DAA4D;;AAEnF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAyCA,SAASC,KAAKA,CAACC,IAAY,EAAU;EACnC,OAAOA,IAAI,GAAG,IAAAC,mBAAa,EAACD,IAAI,CAAC,GAAGA,IAAI;AAC1C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,MAAMA,CAACC,CAAc,EAAe;EAC3C,MAAMC,MAAM,GAAGD,CAAC,CAACE,SAAS,KAAK,IAAI;EACnC,OAAO;IACL,GAAGF,CAAC;IACJH,IAAI,EAAED,KAAK,CAACI,CAAC,CAACH,IAAI,CAAC;IACnBK,SAAS,EAAE,KAAK;IAChB;IACA;IACA;IACAC,SAAS,EAAEH,CAAC,CAACG,SAAS,EAAEC,GAAG,CAAEC,CAAC,KAAM;MAAE,GAAGA,CAAC;MAAER,IAAI,EAAED,KAAK,CAACS,CAAC,CAACR,IAAI;IAAE,CAAC,CAAC,CAAC;IACnES,SAAS,EAAEN,CAAC,CAACM,SAAS,CAACF,GAAG,CAAEG,CAAC,IAAK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CAAC,CAAC,MAAM;IACN,OAAO,IAAI;EACb;AACF;AAEO,eAAekF,eAAeA,CAAChD,OAAyB,EAAiB;EAC9E,IAAI;IACF,MAAM8C,2BAAiB,CAACG,OAAO,CAACnF,cAAc,EAAEuC,IAAI,CAACC,SAAS,CAACN,OAAO,CAAC,CAAC;EAC1E,CAAC,CAAC,MAAM;IACN;IACA;EAAA;AAEJ;AAEO,eAAekD,eAAeA,CAAA,EAAkB;EACrD,IAAI;IACF,MAAMJ,2BAAiB,CAACK,UAAU,CAACrF,cAAc,CAAC;EACpD,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ","ignoreList":[]}
@@ -1 +1,333 @@
1
- "use strict";var _vitest=require("vitest"),_transcriptPersistence=require("./transcriptPersistence");const msg=(t={})=>({id:"m1",role:"assistant",text:"ok",toolCalls:[],blocks:[],...t}),build=(t,e=[])=>(0,_transcriptPersistence.buildPayload)({messages:t,history:e,answers:{},usage:{input:0,output:0,requests:0}});(0,_vitest.describe)("what reaches the disk",()=>{(0,_vitest.it)("never writes a tool result",()=>{const t=build([msg()],[{role:"user",text:"what's in the bag?"},{role:"assistant",text:"",toolCalls:[{id:"c1",name:"buoy_zustand",input:{}}]},{role:"tool-results",results:[{toolCallId:"c1",content:'{"lines":[{"card":"4111111111111111"}]}'}]},{role:"assistant",text:"Five items."}]),e=JSON.stringify(t);(0,_vitest.expect)(e).not.toContain("4111111111111111"),(0,_vitest.expect)(t.history.map(t=>t.role)).toEqual(["user","assistant","tool-results","assistant"])}),(0,_vitest.it)("never writes a step's result, even when it writes the step",()=>{const t=build([msg({toolCalls:[{id:"c1",toolId:"zustand",action:"getStoreState",label:"Read the bag",status:"ok",summary:"Done",params:'{"storeName":"bag"}',result:'{"card":"4111111111111111"}'}]})]);(0,_vitest.expect)(JSON.stringify(t)).not.toContain("4111111111111111"),(0,_vitest.expect)(t.messages[0].toolCalls[0].result).toBeUndefined(),(0,_vitest.expect)(t.messages[0].toolCalls[0].action).toBe("getStoreState")}),(0,_vitest.it)("scrubs credential shapes out of what the agent said",()=>{const t=build([msg({text:"The header was Bearer abcdefghijklmnop123456"})]);(0,_vitest.expect)(t.messages[0].text).not.toContain("abcdefghijklmnop123456")}),(0,_vitest.it)("caps a long session instead of growing a file forever",()=>{const t=Array.from({length:400},(t,e)=>msg({id:`m${e}`,text:`answer ${e}`})),e=build(t);(0,_vitest.expect)(e.messages.length).toBeLessThanOrEqual(60),(0,_vitest.expect)(e.messages[e.messages.length-1].text).toBe("answer 399")}),(0,_vitest.it)("drops from the oldest end until a heavy transcript fits",()=>{const t=Array.from({length:20},(t,e)=>msg({id:`m${e}`,text:"x".repeat(4e4)})),e=(0,_transcriptPersistence.fitToCaps)({v:1,savedAt:0,messages:t,history:[],answers:{},usage:{input:0,output:0,requests:0}});(0,_vitest.expect)(JSON.stringify(e).length).toBeLessThanOrEqual(256e3),(0,_vitest.expect)(e.messages.length).toBeGreaterThan(0)})}),(0,_vitest.describe)("what comes back",()=>{(0,_vitest.it)("marks a turn the app died in as interrupted rather than blank",()=>{const t=build([msg({text:"",streaming:!0})]);(0,_vitest.expect)(t.messages[0].streaming).toBe(!1),(0,_vitest.expect)(t.messages[0].error).toMatch(/interrupted/i)}),(0,_vitest.it)("never restores a tool call still claiming to run",()=>{const t=build([msg({streaming:!0,toolCalls:[{id:"c1",toolId:"storage",action:"set",label:"Write a key",status:"running"}]})]);(0,_vitest.expect)(t.messages[0].toolCalls[0].status).toBe("failed"),(0,_vitest.expect)(t.messages[0].toolCalls[0].summary).toBe("Interrupted")}),(0,_vitest.it)("keeps an answer that already finished exactly as it was",()=>{const t=build([msg({text:"Five items.",streaming:!1})]);(0,_vitest.expect)(t.messages[0].error).toBeUndefined(),(0,_vitest.expect)(t.messages[0].text).toBe("Five items.")}),(0,_vitest.it)("treats anything it cannot trust as no transcript at all",()=>{(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)(null)).toBeNull(),(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)("not json")).toBeNull(),(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)(JSON.stringify({v:0,messages:[msg()]}))).toBeNull(),(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)(JSON.stringify({v:1,messages:[]}))).toBeNull()}),(0,_vitest.it)("round-trips a real conversation",()=>{const t=build([msg({role:"user",text:"hi"}),msg({id:"m2",text:"hello"})]),e=(0,_transcriptPersistence.parsePayload)(JSON.stringify(t));(0,_vitest.expect)(e?.messages.map(t=>t.text)).toEqual(["hi","hello"])})}),(0,_vitest.describe)("an unanswered approval",()=>{const t={id:"c1",toolId:"zustand",action:"setState",label:"Update the Poké Mart bag store",description:"Change a live zustand store.",reason:"This will change the app's state.",params:{storeName:"bag",data:{lines:[]}},resolve:()=>{}},e=(e={})=>(0,_transcriptPersistence.buildPayload)({messages:[msg()],history:[],answers:{},usage:{input:0,output:0,requests:0},pending:{...t,...e}});(0,_vitest.it)("survives the round trip with the exact call it asked about",()=>{const t=(0,_transcriptPersistence.parsePayload)(JSON.stringify(e()));(0,_vitest.expect)(t?.pending).toMatchObject({toolId:"zustand",action:"setState",label:"Update the Poké Mart bag store",params:{storeName:"bag",data:{lines:[]}}})}),(0,_vitest.it)("is saved again after it has already been restored once",()=>{(0,_vitest.expect)(e({restored:!0}).pending).toBeTruthy()}),(0,_vitest.it)("is dropped rather than scrubbed when the call carries a credential",()=>{const t=e({params:{key:"auth",value:"Bearer abcdefghijklmnop123456"}});(0,_vitest.expect)(t.pending).toBeNull(),(0,_vitest.expect)(JSON.stringify(t)).not.toContain("abcdefghijklmnop123456")}),(0,_vitest.it)("reads back as absent from a transcript written before it existed",()=>{const t=build([msg()]);(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)(JSON.stringify(t))?.pending).toBeNull()}),(0,_vitest.it)("refuses a malformed one rather than restoring half a question",()=>{const t=JSON.stringify({...build([msg()]),pending:{toolId:"zustand"}});(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)(t)?.pending).toBeNull()})}),(0,_vitest.describe)("the effect ledger",()=>{const t={id:"fx-1-1",at:1,toolId:"storage",action:"async.setItem",effect:{kind:"storage-write",toolId:"storage",action:"async.setItem",label:"Save @qa/key",key:"@qa/key",had:!0,previous:"old value"}},e=t=>(0,_transcriptPersistence.buildPayload)({messages:[msg()],history:[],answers:{},usage:{input:0,output:0,requests:0},ledger:t});(0,_vitest.it)("survives the round trip with the prior value an undo needs",()=>{const s=(0,_transcriptPersistence.parsePayload)(JSON.stringify(e([t])));(0,_vitest.expect)(s?.ledger).toHaveLength(1),(0,_vitest.expect)(s?.ledger?.[0]).toMatchObject({toolId:"storage",action:"async.setItem"})}),(0,_vitest.it)("drops an entry holding a credential rather than rewriting it",()=>{const s={...t,effect:{...t.effect,previous:"Bearer abcdefghijklmnop123456"}},a=e([s]);(0,_vitest.expect)(a.ledger).toBeUndefined(),(0,_vitest.expect)(JSON.stringify(a)).not.toContain("abcdefghijklmnop123456")}),(0,_vitest.it)("reads back as absent from a transcript written before it existed",()=>{(0,_vitest.expect)((0,_transcriptPersistence.parsePayload)(JSON.stringify(build([msg()])))?.ledger).toBeUndefined()})});
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _transcriptPersistence = require("./transcriptPersistence");
5
+ /**
6
+ * What a saved conversation is allowed to contain, and what it looks like on
7
+ * the way back in.
8
+ *
9
+ * The transcript is on disk under a `@react_buoy` key now, which the Storage
10
+ * tool can read and the unauthenticated broker mirrors. Everything below is a
11
+ * property that keeps that trade bounded: no tool-result payloads, no
12
+ * credentials, no unbounded growth, and nothing that comes back claiming to
13
+ * still be running.
14
+ */
15
+
16
+ const msg = (over = {}) => ({
17
+ id: "m1",
18
+ role: "assistant",
19
+ text: "ok",
20
+ toolCalls: [],
21
+ blocks: [],
22
+ ...over
23
+ });
24
+ const build = (messages, history = []) => (0, _transcriptPersistence.buildPayload)({
25
+ messages,
26
+ history,
27
+ answers: {},
28
+ usage: {
29
+ input: 0,
30
+ output: 0,
31
+ requests: 0
32
+ }
33
+ });
34
+ (0, _vitest.describe)("what reaches the disk", () => {
35
+ (0, _vitest.it)("never writes a tool result", () => {
36
+ // The payloads are the sensitive half: storage values, response bodies, a
37
+ // customer's record. The ROUND survives so the model can resume; what it
38
+ // saw does not.
39
+ const history = [{
40
+ role: "user",
41
+ text: "what's in the bag?"
42
+ }, {
43
+ role: "assistant",
44
+ text: "",
45
+ toolCalls: [{
46
+ id: "c1",
47
+ name: "buoy_zustand",
48
+ input: {}
49
+ }]
50
+ }, {
51
+ role: "tool-results",
52
+ results: [{
53
+ toolCallId: "c1",
54
+ content: '{"lines":[{"card":"4111111111111111"}]}'
55
+ }]
56
+ }, {
57
+ role: "assistant",
58
+ text: "Five items."
59
+ }];
60
+ const saved = build([msg()], history);
61
+ const json = JSON.stringify(saved);
62
+ (0, _vitest.expect)(json).not.toContain("4111111111111111");
63
+ // The round itself is intact, so the pairing every provider requires holds.
64
+ (0, _vitest.expect)(saved.history.map(m => m.role)).toEqual(["user", "assistant", "tool-results", "assistant"]);
65
+ });
66
+ (0, _vitest.it)("never writes a step's result, even when it writes the step", () => {
67
+ // The step survives so the trace still reads; the payload is the thing the
68
+ // no-tool-results-on-disk promise is about.
69
+ const saved = build([msg({
70
+ toolCalls: [{
71
+ id: "c1",
72
+ toolId: "zustand",
73
+ action: "getStoreState",
74
+ label: "Read the bag",
75
+ status: "ok",
76
+ summary: "Done",
77
+ params: '{"storeName":"bag"}',
78
+ result: '{"card":"4111111111111111"}'
79
+ }]
80
+ })]);
81
+ (0, _vitest.expect)(JSON.stringify(saved)).not.toContain("4111111111111111");
82
+ (0, _vitest.expect)(saved.messages[0].toolCalls[0].result).toBeUndefined();
83
+ (0, _vitest.expect)(saved.messages[0].toolCalls[0].action).toBe("getStoreState");
84
+ });
85
+ (0, _vitest.it)("scrubs credential shapes out of what the agent said", () => {
86
+ const saved = build([msg({
87
+ text: "The header was Bearer abcdefghijklmnop123456"
88
+ })]);
89
+ (0, _vitest.expect)(saved.messages[0].text).not.toContain("abcdefghijklmnop123456");
90
+ });
91
+ (0, _vitest.it)("caps a long session instead of growing a file forever", () => {
92
+ const many = Array.from({
93
+ length: 400
94
+ }, (_, i) => msg({
95
+ id: `m${i}`,
96
+ text: `answer ${i}`
97
+ }));
98
+ const saved = build(many);
99
+ (0, _vitest.expect)(saved.messages.length).toBeLessThanOrEqual(60);
100
+ // Newest kept, oldest dropped — the end of a session is the useful end.
101
+ (0, _vitest.expect)(saved.messages[saved.messages.length - 1].text).toBe("answer 399");
102
+ });
103
+ (0, _vitest.it)("drops from the oldest end until a heavy transcript fits", () => {
104
+ const heavy = Array.from({
105
+ length: 20
106
+ }, (_, i) => msg({
107
+ id: `m${i}`,
108
+ text: "x".repeat(40_000)
109
+ }));
110
+ const saved = (0, _transcriptPersistence.fitToCaps)({
111
+ v: 1,
112
+ savedAt: 0,
113
+ messages: heavy,
114
+ history: [],
115
+ answers: {},
116
+ usage: {
117
+ input: 0,
118
+ output: 0,
119
+ requests: 0
120
+ }
121
+ });
122
+ (0, _vitest.expect)(JSON.stringify(saved).length).toBeLessThanOrEqual(256_000);
123
+ (0, _vitest.expect)(saved.messages.length).toBeGreaterThan(0);
124
+ });
125
+ });
126
+ (0, _vitest.describe)("what comes back", () => {
127
+ (0, _vitest.it)("marks a turn the app died in as interrupted rather than blank", () => {
128
+ // The crash case this feature exists for. An empty bubble with no
129
+ // explanation reads as the model having nothing to say.
130
+ const saved = build([msg({
131
+ text: "",
132
+ streaming: true
133
+ })]);
134
+ (0, _vitest.expect)(saved.messages[0].streaming).toBe(false);
135
+ (0, _vitest.expect)(saved.messages[0].error).toMatch(/interrupted/i);
136
+ });
137
+ (0, _vitest.it)("never restores a tool call still claiming to run", () => {
138
+ const saved = build([msg({
139
+ streaming: true,
140
+ toolCalls: [{
141
+ id: "c1",
142
+ toolId: "storage",
143
+ action: "set",
144
+ label: "Write a key",
145
+ status: "running"
146
+ }]
147
+ })]);
148
+ (0, _vitest.expect)(saved.messages[0].toolCalls[0].status).toBe("failed");
149
+ (0, _vitest.expect)(saved.messages[0].toolCalls[0].summary).toBe("Interrupted");
150
+ });
151
+ (0, _vitest.it)("keeps an answer that already finished exactly as it was", () => {
152
+ const saved = build([msg({
153
+ text: "Five items.",
154
+ streaming: false
155
+ })]);
156
+ (0, _vitest.expect)(saved.messages[0].error).toBeUndefined();
157
+ (0, _vitest.expect)(saved.messages[0].text).toBe("Five items.");
158
+ });
159
+ (0, _vitest.it)("treats anything it cannot trust as no transcript at all", () => {
160
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)(null)).toBeNull();
161
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)("not json")).toBeNull();
162
+ // An older shape is dropped, not coerced — a half-read transcript is worse
163
+ // than a missing one.
164
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)(JSON.stringify({
165
+ v: 0,
166
+ messages: [msg()]
167
+ }))).toBeNull();
168
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)(JSON.stringify({
169
+ v: 1,
170
+ messages: []
171
+ }))).toBeNull();
172
+ });
173
+ (0, _vitest.it)("round-trips a real conversation", () => {
174
+ const saved = build([msg({
175
+ role: "user",
176
+ text: "hi"
177
+ }), msg({
178
+ id: "m2",
179
+ text: "hello"
180
+ })]);
181
+ const back = (0, _transcriptPersistence.parsePayload)(JSON.stringify(saved));
182
+ (0, _vitest.expect)(back?.messages.map(m => m.text)).toEqual(["hi", "hello"]);
183
+ });
184
+ });
185
+
186
+ /**
187
+ * The card the user never answered.
188
+ *
189
+ * An unanswered question that disappears on reload reads as consent nobody
190
+ * gave — nothing was tapped, so as far as the user is concerned the change is
191
+ * still waiting for them.
192
+ */
193
+ (0, _vitest.describe)("an unanswered approval", () => {
194
+ const pending = {
195
+ id: "c1",
196
+ toolId: "zustand",
197
+ action: "setState",
198
+ label: "Update the Poké Mart bag store",
199
+ description: "Change a live zustand store.",
200
+ reason: "This will change the app's state.",
201
+ params: {
202
+ storeName: "bag",
203
+ data: {
204
+ lines: []
205
+ }
206
+ },
207
+ resolve: () => {}
208
+ };
209
+ const withPending = (over = {}) => (0, _transcriptPersistence.buildPayload)({
210
+ messages: [msg()],
211
+ history: [],
212
+ answers: {},
213
+ usage: {
214
+ input: 0,
215
+ output: 0,
216
+ requests: 0
217
+ },
218
+ pending: {
219
+ ...pending,
220
+ ...over
221
+ }
222
+ });
223
+ (0, _vitest.it)("survives the round trip with the exact call it asked about", () => {
224
+ const back = (0, _transcriptPersistence.parsePayload)(JSON.stringify(withPending()));
225
+ // The params are what makes the restored card answerable at all: the turn
226
+ // that asked is gone, so Allow has to re-dispatch this itself.
227
+ (0, _vitest.expect)(back?.pending).toMatchObject({
228
+ toolId: "zustand",
229
+ action: "setState",
230
+ label: "Update the Poké Mart bag store",
231
+ params: {
232
+ storeName: "bag",
233
+ data: {
234
+ lines: []
235
+ }
236
+ }
237
+ });
238
+ });
239
+ (0, _vitest.it)("is saved again after it has already been restored once", () => {
240
+ // Reloading twice without answering must not be the thing that finally
241
+ // loses the question.
242
+ (0, _vitest.expect)(withPending({
243
+ restored: true
244
+ }).pending).toBeTruthy();
245
+ });
246
+ (0, _vitest.it)("is dropped rather than scrubbed when the call carries a credential", () => {
247
+ // Scrubbing would change the call: a redacted token written back is not
248
+ // the change the user was shown. So the card is lost instead — an action
249
+ // carrying a credential is the one that must not re-run itself unattended.
250
+ const saved = withPending({
251
+ params: {
252
+ key: "auth",
253
+ value: "Bearer abcdefghijklmnop123456"
254
+ }
255
+ });
256
+ (0, _vitest.expect)(saved.pending).toBeNull();
257
+ (0, _vitest.expect)(JSON.stringify(saved)).not.toContain("abcdefghijklmnop123456");
258
+ });
259
+ (0, _vitest.it)("reads back as absent from a transcript written before it existed", () => {
260
+ const old = build([msg()]);
261
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)(JSON.stringify(old))?.pending).toBeNull();
262
+ });
263
+ (0, _vitest.it)("refuses a malformed one rather than restoring half a question", () => {
264
+ const raw = JSON.stringify({
265
+ ...build([msg()]),
266
+ pending: {
267
+ toolId: "zustand"
268
+ }
269
+ });
270
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)(raw)?.pending).toBeNull();
271
+ });
272
+ });
273
+
274
+ /**
275
+ * The undo bar, across a restart.
276
+ *
277
+ * The ledger is the ONLY undo surface and it used to die with the JS context:
278
+ * the transcript came back with its "saved" lines and receipt cards intact
279
+ * while the bar vanished and the changes stayed applied.
280
+ */
281
+ (0, _vitest.describe)("the effect ledger", () => {
282
+ const entry = {
283
+ id: "fx-1-1",
284
+ at: 1,
285
+ toolId: "storage",
286
+ action: "async.setItem",
287
+ effect: {
288
+ kind: "storage-write",
289
+ toolId: "storage",
290
+ action: "async.setItem",
291
+ label: "Save @qa/key",
292
+ key: "@qa/key",
293
+ had: true,
294
+ previous: "old value"
295
+ }
296
+ };
297
+ const withLedger = entries => (0, _transcriptPersistence.buildPayload)({
298
+ messages: [msg()],
299
+ history: [],
300
+ answers: {},
301
+ usage: {
302
+ input: 0,
303
+ output: 0,
304
+ requests: 0
305
+ },
306
+ ledger: entries
307
+ });
308
+ (0, _vitest.it)("survives the round trip with the prior value an undo needs", () => {
309
+ const back = (0, _transcriptPersistence.parsePayload)(JSON.stringify(withLedger([entry])));
310
+ (0, _vitest.expect)(back?.ledger).toHaveLength(1);
311
+ (0, _vitest.expect)(back?.ledger?.[0]).toMatchObject({
312
+ toolId: "storage",
313
+ action: "async.setItem"
314
+ });
315
+ });
316
+ (0, _vitest.it)("drops an entry holding a credential rather than rewriting it", () => {
317
+ // Scrubbing would make the undo restore "[redacted]" over the real value.
318
+ const secret = {
319
+ ...entry,
320
+ effect: {
321
+ ...entry.effect,
322
+ previous: "Bearer abcdefghijklmnop123456"
323
+ }
324
+ };
325
+ const saved = withLedger([secret]);
326
+ (0, _vitest.expect)(saved.ledger).toBeUndefined();
327
+ (0, _vitest.expect)(JSON.stringify(saved)).not.toContain("abcdefghijklmnop123456");
328
+ });
329
+ (0, _vitest.it)("reads back as absent from a transcript written before it existed", () => {
330
+ (0, _vitest.expect)((0, _transcriptPersistence.parsePayload)(JSON.stringify(build([msg()])))?.ledger).toBeUndefined();
331
+ });
332
+ });
333
+ //# sourceMappingURL=transcriptPersistence.test.js.map