@buoy-gg/ask-buoy 7.0.35 → 7.0.38

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 (286) hide show
  1. package/README.md +73 -15
  2. package/lib/commonjs/blocks/AskBlocks.js +1 -338
  3. package/lib/commonjs/blocks/BlockRenderer.js +1 -250
  4. package/lib/commonjs/blocks/ChromePrototypes.js +1 -514
  5. package/lib/commonjs/blocks/DataBlocks.js +1 -688
  6. package/lib/commonjs/blocks/ExtraBlocks.js +1 -1854
  7. package/lib/commonjs/blocks/MediaBlocks.js +1 -140
  8. package/lib/commonjs/blocks/ReceiptBlocks.js +1 -586
  9. package/lib/commonjs/blocks/blockText.js +1 -0
  10. package/lib/commonjs/blocks/blockText.test.js +1 -0
  11. package/lib/commonjs/blocks/context.js +1 -42
  12. package/lib/commonjs/blocks/icons.js +1 -96
  13. package/lib/commonjs/blocks/index.js +1 -95
  14. package/lib/commonjs/blocks/listRow.test.js +1 -55
  15. package/lib/commonjs/blocks/pageState.js +1 -34
  16. package/lib/commonjs/blocks/pageState.test.js +1 -57
  17. package/lib/commonjs/blocks/primitives.js +1 -401
  18. package/lib/commonjs/blocks/primitivesIndex.js +1 -62
  19. package/lib/commonjs/components/ApprovalCard.js +1 -140
  20. package/lib/commonjs/components/AskBuoyHeader.js +1 -164
  21. package/lib/commonjs/components/AskBuoyIcon.js +1 -19
  22. package/lib/commonjs/components/AskBuoyModal.js +1 -353
  23. package/lib/commonjs/components/AskBuoySettings.js +1 -69
  24. package/lib/commonjs/components/ChangesBar.js +1 -211
  25. package/lib/commonjs/components/Composer.js +1 -175
  26. package/lib/commonjs/components/EmptyState.js +1 -154
  27. package/lib/commonjs/components/KeyboardPad.js +1 -0
  28. package/lib/commonjs/components/Markdown.js +1 -252
  29. package/lib/commonjs/components/MessageList.js +1 -683
  30. package/lib/commonjs/components/QueuedMessages.js +1 -0
  31. package/lib/commonjs/components/ThinkingStrip.js +1 -223
  32. package/lib/commonjs/components/TypingDots.js +1 -63
  33. package/lib/commonjs/components/markdownParse.js +1 -0
  34. package/lib/commonjs/components/markdownParse.test.js +1 -0
  35. package/lib/commonjs/components/useCopyAction.js +1 -50
  36. package/lib/commonjs/index.js +1 -252
  37. package/lib/commonjs/preset.js +1 -90
  38. package/lib/commonjs/store/activityGroups.js +1 -0
  39. package/lib/commonjs/store/activityGroups.test.js +1 -0
  40. package/lib/commonjs/store/askBuoySettings.js +1 -67
  41. package/lib/commonjs/store/askBuoyStore.js +1 -365
  42. package/lib/commonjs/store/blockPlacement.js +1 -0
  43. package/lib/commonjs/store/blockPlacement.test.js +1 -0
  44. package/lib/commonjs/store/queue.test.js +1 -0
  45. package/lib/commonjs/store/resetConversation.js +1 -0
  46. package/lib/commonjs/store/restorePending.test.js +1 -0
  47. package/lib/commonjs/store/restoredIds.test.js +1 -47
  48. package/lib/commonjs/store/suggestions.js +1 -0
  49. package/lib/commonjs/store/suggestions.test.js +1 -0
  50. package/lib/commonjs/store/systemLine.test.js +1 -0
  51. package/lib/commonjs/store/ticketPrompt.js +1 -0
  52. package/lib/commonjs/store/traceText.js +1 -81
  53. package/lib/commonjs/store/traceText.test.js +1 -112
  54. package/lib/commonjs/store/transcriptPersistence.js +1 -208
  55. package/lib/commonjs/store/transcriptPersistence.test.js +1 -185
  56. package/lib/commonjs/store/turnRendering.test.js +1 -0
  57. package/lib/commonjs/store/useAskBuoy.js +1 -400
  58. package/lib/commonjs/store/useAskBuoySettings.js +1 -14
  59. package/lib/commonjs/sync/askBuoySyncAdapter.js +1 -119
  60. package/lib/commonjs/sync/askBuoySyncAdapter.test.js +1 -141
  61. package/lib/commonjs/sync/wire.js +1 -58
  62. package/lib/commonjs/types.js +1 -6
  63. package/lib/module/blocks/AskBlocks.js +1 -331
  64. package/lib/module/blocks/BlockRenderer.js +1 -245
  65. package/lib/module/blocks/ChromePrototypes.js +1 -503
  66. package/lib/module/blocks/DataBlocks.js +1 -674
  67. package/lib/module/blocks/ExtraBlocks.js +1 -1827
  68. package/lib/module/blocks/MediaBlocks.js +1 -135
  69. package/lib/module/blocks/ReceiptBlocks.js +1 -574
  70. package/lib/module/blocks/blockText.js +1 -0
  71. package/lib/module/blocks/blockText.test.js +1 -0
  72. package/lib/module/blocks/context.js +1 -35
  73. package/lib/module/blocks/icons.js +1 -91
  74. package/lib/module/blocks/index.js +1 -8
  75. package/lib/module/blocks/listRow.test.js +1 -56
  76. package/lib/module/blocks/pageState.js +1 -30
  77. package/lib/module/blocks/pageState.test.js +1 -56
  78. package/lib/module/blocks/primitives.js +1 -389
  79. package/lib/module/blocks/primitivesIndex.js +1 -5
  80. package/lib/module/components/ApprovalCard.js +1 -135
  81. package/lib/module/components/AskBuoyHeader.js +1 -161
  82. package/lib/module/components/AskBuoyIcon.js +1 -8
  83. package/lib/module/components/AskBuoyModal.js +1 -348
  84. package/lib/module/components/AskBuoySettings.js +1 -64
  85. package/lib/module/components/ChangesBar.js +1 -206
  86. package/lib/module/components/Composer.js +1 -170
  87. package/lib/module/components/EmptyState.js +1 -149
  88. package/lib/module/components/KeyboardPad.js +1 -0
  89. package/lib/module/components/Markdown.js +1 -246
  90. package/lib/module/components/MessageList.js +1 -677
  91. package/lib/module/components/QueuedMessages.js +1 -0
  92. package/lib/module/components/ThinkingStrip.js +1 -218
  93. package/lib/module/components/TypingDots.js +1 -58
  94. package/lib/module/components/markdownParse.js +1 -0
  95. package/lib/module/components/markdownParse.test.js +1 -0
  96. package/lib/module/components/useCopyAction.js +1 -46
  97. package/lib/module/index.js +1 -34
  98. package/lib/module/preset.js +1 -73
  99. package/lib/module/store/activityGroups.js +1 -0
  100. package/lib/module/store/activityGroups.test.js +1 -0
  101. package/lib/module/store/askBuoySettings.js +1 -62
  102. package/lib/module/store/askBuoyStore.js +1 -361
  103. package/lib/module/store/blockPlacement.js +1 -0
  104. package/lib/module/store/blockPlacement.test.js +1 -0
  105. package/lib/module/store/queue.test.js +1 -0
  106. package/lib/module/store/resetConversation.js +1 -0
  107. package/lib/module/store/restorePending.test.js +1 -0
  108. package/lib/module/store/restoredIds.test.js +1 -46
  109. package/lib/module/store/suggestions.js +1 -0
  110. package/lib/module/store/suggestions.test.js +1 -0
  111. package/lib/module/store/systemLine.test.js +1 -0
  112. package/lib/module/store/ticketPrompt.js +1 -0
  113. package/lib/module/store/traceText.js +1 -75
  114. package/lib/module/store/traceText.test.js +1 -111
  115. package/lib/module/store/transcriptPersistence.js +1 -198
  116. package/lib/module/store/transcriptPersistence.test.js +1 -184
  117. package/lib/module/store/turnRendering.test.js +1 -0
  118. package/lib/module/store/useAskBuoy.js +1 -394
  119. package/lib/module/store/useAskBuoySettings.js +1 -9
  120. package/lib/module/sync/askBuoySyncAdapter.js +1 -114
  121. package/lib/module/sync/askBuoySyncAdapter.test.js +1 -140
  122. package/lib/module/sync/wire.js +1 -47
  123. package/lib/module/types.js +1 -4
  124. package/lib/typescript/blocks/DataBlocks.d.ts +11 -0
  125. package/lib/typescript/blocks/ExtraBlocks.d.ts +18 -2
  126. package/lib/typescript/blocks/blockText.d.ts +14 -0
  127. package/lib/typescript/blocks/blockText.test.d.ts +2 -0
  128. package/lib/typescript/blocks/primitives.d.ts +16 -1
  129. package/lib/typescript/components/ApprovalCard.d.ts +9 -1
  130. package/lib/typescript/components/AskBuoyHeader.d.ts +31 -1
  131. package/lib/typescript/components/Composer.d.ts +16 -1
  132. package/lib/typescript/components/EmptyState.d.ts +5 -1
  133. package/lib/typescript/components/KeyboardPad.d.ts +33 -0
  134. package/lib/typescript/components/Markdown.d.ts +0 -10
  135. package/lib/typescript/components/MessageList.d.ts +7 -2
  136. package/lib/typescript/components/QueuedMessages.d.ts +10 -0
  137. package/lib/typescript/components/markdownParse.d.ts +49 -0
  138. package/lib/typescript/components/markdownParse.test.d.ts +2 -0
  139. package/lib/typescript/preset.d.ts +4 -2
  140. package/lib/typescript/store/activityGroups.d.ts +29 -0
  141. package/lib/typescript/store/activityGroups.test.d.ts +2 -0
  142. package/lib/typescript/store/askBuoySettings.d.ts +22 -0
  143. package/lib/typescript/store/askBuoyStore.d.ts +174 -9
  144. package/lib/typescript/store/blockPlacement.d.ts +30 -0
  145. package/lib/typescript/store/blockPlacement.test.d.ts +2 -0
  146. package/lib/typescript/store/queue.test.d.ts +2 -0
  147. package/lib/typescript/store/resetConversation.d.ts +38 -0
  148. package/lib/typescript/store/restorePending.test.d.ts +2 -0
  149. package/lib/typescript/store/suggestions.d.ts +32 -0
  150. package/lib/typescript/store/suggestions.test.d.ts +2 -0
  151. package/lib/typescript/store/systemLine.test.d.ts +2 -0
  152. package/lib/typescript/store/ticketPrompt.d.ts +11 -0
  153. package/lib/typescript/store/transcriptPersistence.d.ts +41 -2
  154. package/lib/typescript/store/turnRendering.test.d.ts +2 -0
  155. package/lib/typescript/store/useAskBuoy.d.ts +26 -3
  156. package/lib/typescript/sync/askBuoySyncAdapter.d.ts +29 -6
  157. package/package.json +10 -10
  158. package/lib/commonjs/blocks/AskBlocks.js.map +0 -1
  159. package/lib/commonjs/blocks/BlockRenderer.js.map +0 -1
  160. package/lib/commonjs/blocks/ChromePrototypes.js.map +0 -1
  161. package/lib/commonjs/blocks/DataBlocks.js.map +0 -1
  162. package/lib/commonjs/blocks/ExtraBlocks.js.map +0 -1
  163. package/lib/commonjs/blocks/MediaBlocks.js.map +0 -1
  164. package/lib/commonjs/blocks/ReceiptBlocks.js.map +0 -1
  165. package/lib/commonjs/blocks/context.js.map +0 -1
  166. package/lib/commonjs/blocks/icons.js.map +0 -1
  167. package/lib/commonjs/blocks/index.js.map +0 -1
  168. package/lib/commonjs/blocks/listRow.test.js.map +0 -1
  169. package/lib/commonjs/blocks/pageState.js.map +0 -1
  170. package/lib/commonjs/blocks/pageState.test.js.map +0 -1
  171. package/lib/commonjs/blocks/primitives.js.map +0 -1
  172. package/lib/commonjs/blocks/primitivesIndex.js.map +0 -1
  173. package/lib/commonjs/components/ApprovalCard.js.map +0 -1
  174. package/lib/commonjs/components/AskBuoyHeader.js.map +0 -1
  175. package/lib/commonjs/components/AskBuoyIcon.js.map +0 -1
  176. package/lib/commonjs/components/AskBuoyModal.js.map +0 -1
  177. package/lib/commonjs/components/AskBuoySettings.js.map +0 -1
  178. package/lib/commonjs/components/ChangesBar.js.map +0 -1
  179. package/lib/commonjs/components/Composer.js.map +0 -1
  180. package/lib/commonjs/components/EmptyState.js.map +0 -1
  181. package/lib/commonjs/components/Markdown.js.map +0 -1
  182. package/lib/commonjs/components/MessageList.js.map +0 -1
  183. package/lib/commonjs/components/ThinkingStrip.js.map +0 -1
  184. package/lib/commonjs/components/TypingDots.js.map +0 -1
  185. package/lib/commonjs/components/useCopyAction.js.map +0 -1
  186. package/lib/commonjs/index.js.map +0 -1
  187. package/lib/commonjs/preset.js.map +0 -1
  188. package/lib/commonjs/store/askBuoySettings.js.map +0 -1
  189. package/lib/commonjs/store/askBuoyStore.js.map +0 -1
  190. package/lib/commonjs/store/restoredIds.test.js.map +0 -1
  191. package/lib/commonjs/store/traceText.js.map +0 -1
  192. package/lib/commonjs/store/traceText.test.js.map +0 -1
  193. package/lib/commonjs/store/transcriptPersistence.js.map +0 -1
  194. package/lib/commonjs/store/transcriptPersistence.test.js.map +0 -1
  195. package/lib/commonjs/store/useAskBuoy.js.map +0 -1
  196. package/lib/commonjs/store/useAskBuoySettings.js.map +0 -1
  197. package/lib/commonjs/sync/askBuoySyncAdapter.js.map +0 -1
  198. package/lib/commonjs/sync/askBuoySyncAdapter.test.js.map +0 -1
  199. package/lib/commonjs/sync/wire.js.map +0 -1
  200. package/lib/commonjs/types.js.map +0 -1
  201. package/lib/module/blocks/AskBlocks.js.map +0 -1
  202. package/lib/module/blocks/BlockRenderer.js.map +0 -1
  203. package/lib/module/blocks/ChromePrototypes.js.map +0 -1
  204. package/lib/module/blocks/DataBlocks.js.map +0 -1
  205. package/lib/module/blocks/ExtraBlocks.js.map +0 -1
  206. package/lib/module/blocks/MediaBlocks.js.map +0 -1
  207. package/lib/module/blocks/ReceiptBlocks.js.map +0 -1
  208. package/lib/module/blocks/context.js.map +0 -1
  209. package/lib/module/blocks/icons.js.map +0 -1
  210. package/lib/module/blocks/index.js.map +0 -1
  211. package/lib/module/blocks/listRow.test.js.map +0 -1
  212. package/lib/module/blocks/pageState.js.map +0 -1
  213. package/lib/module/blocks/pageState.test.js.map +0 -1
  214. package/lib/module/blocks/primitives.js.map +0 -1
  215. package/lib/module/blocks/primitivesIndex.js.map +0 -1
  216. package/lib/module/components/ApprovalCard.js.map +0 -1
  217. package/lib/module/components/AskBuoyHeader.js.map +0 -1
  218. package/lib/module/components/AskBuoyIcon.js.map +0 -1
  219. package/lib/module/components/AskBuoyModal.js.map +0 -1
  220. package/lib/module/components/AskBuoySettings.js.map +0 -1
  221. package/lib/module/components/ChangesBar.js.map +0 -1
  222. package/lib/module/components/Composer.js.map +0 -1
  223. package/lib/module/components/EmptyState.js.map +0 -1
  224. package/lib/module/components/Markdown.js.map +0 -1
  225. package/lib/module/components/MessageList.js.map +0 -1
  226. package/lib/module/components/ThinkingStrip.js.map +0 -1
  227. package/lib/module/components/TypingDots.js.map +0 -1
  228. package/lib/module/components/useCopyAction.js.map +0 -1
  229. package/lib/module/index.js.map +0 -1
  230. package/lib/module/preset.js.map +0 -1
  231. package/lib/module/store/askBuoySettings.js.map +0 -1
  232. package/lib/module/store/askBuoyStore.js.map +0 -1
  233. package/lib/module/store/restoredIds.test.js.map +0 -1
  234. package/lib/module/store/traceText.js.map +0 -1
  235. package/lib/module/store/traceText.test.js.map +0 -1
  236. package/lib/module/store/transcriptPersistence.js.map +0 -1
  237. package/lib/module/store/transcriptPersistence.test.js.map +0 -1
  238. package/lib/module/store/useAskBuoy.js.map +0 -1
  239. package/lib/module/store/useAskBuoySettings.js.map +0 -1
  240. package/lib/module/sync/askBuoySyncAdapter.js.map +0 -1
  241. package/lib/module/sync/askBuoySyncAdapter.test.js.map +0 -1
  242. package/lib/module/sync/wire.js.map +0 -1
  243. package/lib/module/types.js.map +0 -1
  244. package/lib/typescript/blocks/AskBlocks.d.ts.map +0 -1
  245. package/lib/typescript/blocks/BlockRenderer.d.ts.map +0 -1
  246. package/lib/typescript/blocks/ChromePrototypes.d.ts.map +0 -1
  247. package/lib/typescript/blocks/DataBlocks.d.ts.map +0 -1
  248. package/lib/typescript/blocks/ExtraBlocks.d.ts.map +0 -1
  249. package/lib/typescript/blocks/MediaBlocks.d.ts.map +0 -1
  250. package/lib/typescript/blocks/ReceiptBlocks.d.ts.map +0 -1
  251. package/lib/typescript/blocks/context.d.ts.map +0 -1
  252. package/lib/typescript/blocks/icons.d.ts.map +0 -1
  253. package/lib/typescript/blocks/index.d.ts.map +0 -1
  254. package/lib/typescript/blocks/listRow.test.d.ts.map +0 -1
  255. package/lib/typescript/blocks/pageState.d.ts.map +0 -1
  256. package/lib/typescript/blocks/pageState.test.d.ts.map +0 -1
  257. package/lib/typescript/blocks/primitives.d.ts.map +0 -1
  258. package/lib/typescript/blocks/primitivesIndex.d.ts.map +0 -1
  259. package/lib/typescript/components/ApprovalCard.d.ts.map +0 -1
  260. package/lib/typescript/components/AskBuoyHeader.d.ts.map +0 -1
  261. package/lib/typescript/components/AskBuoyIcon.d.ts.map +0 -1
  262. package/lib/typescript/components/AskBuoyModal.d.ts.map +0 -1
  263. package/lib/typescript/components/AskBuoySettings.d.ts.map +0 -1
  264. package/lib/typescript/components/ChangesBar.d.ts.map +0 -1
  265. package/lib/typescript/components/Composer.d.ts.map +0 -1
  266. package/lib/typescript/components/EmptyState.d.ts.map +0 -1
  267. package/lib/typescript/components/Markdown.d.ts.map +0 -1
  268. package/lib/typescript/components/MessageList.d.ts.map +0 -1
  269. package/lib/typescript/components/ThinkingStrip.d.ts.map +0 -1
  270. package/lib/typescript/components/TypingDots.d.ts.map +0 -1
  271. package/lib/typescript/components/useCopyAction.d.ts.map +0 -1
  272. package/lib/typescript/index.d.ts.map +0 -1
  273. package/lib/typescript/preset.d.ts.map +0 -1
  274. package/lib/typescript/store/askBuoySettings.d.ts.map +0 -1
  275. package/lib/typescript/store/askBuoyStore.d.ts.map +0 -1
  276. package/lib/typescript/store/restoredIds.test.d.ts.map +0 -1
  277. package/lib/typescript/store/traceText.d.ts.map +0 -1
  278. package/lib/typescript/store/traceText.test.d.ts.map +0 -1
  279. package/lib/typescript/store/transcriptPersistence.d.ts.map +0 -1
  280. package/lib/typescript/store/transcriptPersistence.test.d.ts.map +0 -1
  281. package/lib/typescript/store/useAskBuoy.d.ts.map +0 -1
  282. package/lib/typescript/store/useAskBuoySettings.d.ts.map +0 -1
  283. package/lib/typescript/sync/askBuoySyncAdapter.d.ts.map +0 -1
  284. package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts.map +0 -1
  285. package/lib/typescript/sync/wire.d.ts.map +0 -1
  286. package/lib/typescript/types.d.ts.map +0 -1
@@ -1,198 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * The conversation, across a reload or a crash.
5
- *
6
- * This reverses a deliberate earlier decision, so the reasoning is worth
7
- * stating. The transcript used to live only in memory because it can quote
8
- * anything the agent read — a storage value, a response body, a customer
9
- * record — and a Buoy key on disk is readable by the Storage tool, which the
10
- * unauthenticated broker mirrors to every connected dashboard. That risk did
11
- * not go away; it is now a trade the host app makes knowingly, and can decline
12
- * with `askBuoy={{ persistTranscript: false }}`.
13
- *
14
- * What lowers it:
15
- * - Tool RESULTS are never written. The model's saved history keeps the shape
16
- * of each round (which tool ran, what it was asked) and replaces every result
17
- * payload with a placeholder — so the agent resumes knowing what it did, not
18
- * what it saw. Raw payloads are the sensitive part and they stay in memory.
19
- * - Everything written passes `redactForWire`, the same credential scrubber the
20
- * broker wire uses.
21
- * - It is capped, oldest-first, so a long QA session cannot grow a file without
22
- * bound.
23
- * - "New conversation" deletes it, rather than leaving the last chat on disk.
24
- */
25
- import { persistentStorage, devToolsStorageKeys } from "@buoy-gg/shared-ui";
26
- import { redactForWire } from "../sync/wire";
27
-
28
- /** `@react_buoy` prefix, so the Storage tool treats it as one of its own. */
29
- export const TRANSCRIPT_KEY = `${devToolsStorageKeys.base}_ask_buoy_transcript`;
30
-
31
- /** Bumped when the saved shape changes; an older payload is dropped, not parsed. */
32
- const VERSION = 1;
33
-
34
- /** Newest N bubbles. Beyond this a reader is scrolling history, not testing. */
35
- const MAX_MESSAGES = 60;
36
-
37
- /**
38
- * Hard ceiling on the file. Blocks carry image URLs and table rows, so a
39
- * message is not a small object; this is checked AFTER the message cap and
40
- * drops from the oldest end until it fits.
41
- */
42
- const MAX_BYTES = 256_000;
43
-
44
- /** What replaces a tool result. Addressed to the model, which will read it. */
45
- const DROPPED_RESULT = "[not kept across a restart — read it again if you need it]";
46
- function scrub(text) {
47
- return text ? redactForWire(text) : text;
48
- }
49
-
50
- /**
51
- * A bubble as it should look after a restart.
52
- *
53
- * `streaming` is cleared because nothing is streaming into a bubble the app
54
- * has just rebuilt, and a message caught mid-turn is marked as interrupted
55
- * rather than left looking like a silent, empty answer — which is exactly the
56
- * crash case this feature exists for. `actionState` is not saved at all: a
57
- * button stuck on "running" would be a lie about work that died with the
58
- * process.
59
- */
60
- function settle(m) {
61
- const cutOff = m.streaming === true;
62
- return {
63
- ...m,
64
- text: scrub(m.text),
65
- streaming: false,
66
- // The thinking view's payloads go through the same scrubber as the answer:
67
- // step parameters carry whatever the model passed a tool, which is exactly
68
- // where a token ends up when the agent has been asked to set one.
69
- reasoning: m.reasoning?.map(r => ({
70
- ...r,
71
- text: scrub(r.text)
72
- })),
73
- toolCalls: m.toolCalls.map(c => {
74
- const params = c.params ? scrub(c.params) : undefined;
75
- // `result` is dropped, never scrubbed. It is the tool payload itself —
76
- // a store's whole state, a response body — and "tool results are never
77
- // written to disk" is the promise this file is built on. It stays in
78
- // memory for the thinking view and the JSON export.
79
- const {
80
- result: _dropped,
81
- ...rest
82
- } = c;
83
- return c.status === "running" ? {
84
- ...rest,
85
- params,
86
- status: "failed",
87
- summary: "Interrupted"
88
- } : {
89
- ...rest,
90
- params
91
- };
92
- }),
93
- error: m.error ?? (cutOff && !m.text ? "This answer was interrupted — the app restarted mid-turn." : undefined)
94
- };
95
- }
96
-
97
- /** Model history with every tool result replaced by a placeholder. */
98
- function withoutResults(history) {
99
- return history.map(m => {
100
- if (m.role === "tool-results") {
101
- return {
102
- ...m,
103
- results: m.results.map(r => ({
104
- ...r,
105
- content: DROPPED_RESULT
106
- }))
107
- };
108
- }
109
- if (m.role === "assistant") return {
110
- ...m,
111
- text: scrub(m.text)
112
- };
113
- return {
114
- ...m,
115
- text: scrub(m.text)
116
- };
117
- });
118
- }
119
-
120
- /**
121
- * Trim to the caps. Messages and history are trimmed together and from the
122
- * same end, so what the user sees and what the model remembers stay the same
123
- * conversation rather than drifting apart across restarts.
124
- */
125
- export function fitToCaps(payload) {
126
- let out = {
127
- ...payload,
128
- messages: payload.messages.slice(-MAX_MESSAGES),
129
- history: payload.history.slice(-MAX_MESSAGES * 2)
130
- };
131
- let json = JSON.stringify(out);
132
- while (json.length > MAX_BYTES && out.messages.length > 1) {
133
- out = {
134
- ...out,
135
- messages: out.messages.slice(1),
136
- history: out.history.slice(Math.min(2, out.history.length))
137
- };
138
- json = JSON.stringify(out);
139
- }
140
- return out;
141
- }
142
- export function buildPayload(input) {
143
- return fitToCaps({
144
- v: VERSION,
145
- savedAt: Date.now(),
146
- messages: input.messages.map(settle),
147
- history: withoutResults(input.history),
148
- answers: input.answers,
149
- usage: input.usage
150
- });
151
- }
152
-
153
- /** Anything unparseable, or from an older shape, is treated as "no transcript". */
154
- export function parsePayload(raw) {
155
- if (!raw) return null;
156
- try {
157
- const parsed = JSON.parse(raw);
158
- if (parsed?.v !== VERSION || !Array.isArray(parsed.messages)) return null;
159
- if (parsed.messages.length === 0) return null;
160
- return {
161
- v: VERSION,
162
- savedAt: typeof parsed.savedAt === "number" ? parsed.savedAt : 0,
163
- messages: parsed.messages,
164
- history: Array.isArray(parsed.history) ? parsed.history : [],
165
- answers: parsed.answers ?? {},
166
- usage: parsed.usage ?? {
167
- input: 0,
168
- output: 0,
169
- requests: 0
170
- }
171
- };
172
- } catch {
173
- return null;
174
- }
175
- }
176
- export async function readTranscript() {
177
- try {
178
- return parsePayload(await persistentStorage.getItem(TRANSCRIPT_KEY));
179
- } catch {
180
- return null;
181
- }
182
- }
183
- export async function writeTranscript(payload) {
184
- try {
185
- await persistentStorage.setItem(TRANSCRIPT_KEY, JSON.stringify(payload));
186
- } catch {
187
- // A transcript that cannot be saved must never break the chat that
188
- // produced it.
189
- }
190
- }
191
- export async function clearTranscript() {
192
- try {
193
- await persistentStorage.removeItem(TRANSCRIPT_KEY);
194
- } catch {
195
- /* nothing to do — see writeTranscript */
196
- }
197
- }
198
- //# sourceMappingURL=transcriptPersistence.js.map
1
+ "use strict";import{persistentStorage,devToolsStorageKeys}from"@buoy-gg/shared-ui";import{redactForWire}from"../sync/wire";export const TRANSCRIPT_KEY=`${devToolsStorageKeys.base}_ask_buoy_transcript`;const VERSION=1,MAX_MESSAGES=60,MAX_BYTES=256e3,DROPPED_RESULT="[not kept across a restart — read it again if you need it]";function scrub(t){return t?redactForWire(t):t}function settle(t){const e=!0===t.streaming;return{...t,text:scrub(t.text),streaming:!1,reasoning:t.reasoning?.map(t=>({...t,text:scrub(t.text)})),toolCalls:t.toolCalls.map(t=>{const e=t.params?scrub(t.params):void 0,{result:r,...s}=t;return"running"===t.status?{...s,params:e,status:"failed",summary:"Interrupted"}:{...s,params:e}}),error:t.error??(e&&!t.text?"This answer was interrupted — the app restarted mid-turn.":void 0)}}function withoutResults(t){return t.map(t=>"tool-results"===t.role?{...t,results:t.results.map(t=>({...t,content:DROPPED_RESULT}))}:(t.role,{...t,text:scrub(t.text)}))}export function fitToCaps(t){let e={...t,messages:t.messages.slice(-60),history:t.history.slice(-120)},r=JSON.stringify(e);for(;r.length>256e3&&e.messages.length>1;)e={...e,messages:e.messages.slice(1),history:e.history.slice(Math.min(2,e.history.length))},r=JSON.stringify(e);return e}function storableApproval(t){if(!t)return null;const e=t.params;if(!e)return null;let r;try{r=JSON.stringify(e)}catch{return null}return redactForWire(r)!==r?null:{id:t.id,toolId:t.toolId,action:t.action,label:scrub(t.label),description:t.description?scrub(t.description):void 0,reason:scrub(t.reason),params:e,targetDigest:t.targetDigest}}function isStoredApproval(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.id&&"string"==typeof e.toolId&&"string"==typeof e.action&&"string"==typeof e.label&&"string"==typeof e.reason&&"object"==typeof e.params&&null!==e.params}function storableLedger(t){if(!t?.length)return;const e=t.filter(t=>{try{const e=JSON.stringify(t);return redactForWire(e)===e}catch{return!1}});return e.length?e:void 0}export function buildPayload(t){return fitToCaps({v:1,savedAt:Date.now(),messages:t.messages.map(settle),history:withoutResults(t.history),answers:t.answers,usage:t.usage,pending:storableApproval(t.pending),ledger:storableLedger(t.ledger),queued:t.queued?.length?t.queued.map(t=>({id:t.id,text:scrub(t.text)})):void 0})}export function parsePayload(t){if(!t)return null;try{const e=JSON.parse(t);return 1===e?.v&&Array.isArray(e.messages)?0===e.messages.length?null:{v:1,savedAt:"number"==typeof e.savedAt?e.savedAt:0,messages:e.messages,history:Array.isArray(e.history)?e.history:[],answers:e.answers??{},usage:e.usage??{input:0,output:0,requests:0},pending:isStoredApproval(e.pending)?e.pending:null,ledger:Array.isArray(e.ledger)?e.ledger.filter(t=>"object"==typeof t&&null!==t&&"string"==typeof t.id):void 0,queued:Array.isArray(e.queued)?e.queued.filter(t=>"object"==typeof t&&null!==t&&"string"==typeof t.id&&"string"==typeof t.text):void 0}:null}catch{return null}}export async function readTranscript(){try{return parsePayload(await persistentStorage.getItem(TRANSCRIPT_KEY))}catch{return null}}export async function writeTranscript(t){try{await persistentStorage.setItem(TRANSCRIPT_KEY,JSON.stringify(t))}catch{}}export async function clearTranscript(){try{await persistentStorage.removeItem(TRANSCRIPT_KEY)}catch{}}
@@ -1,184 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * What a saved conversation is allowed to contain, and what it looks like on
5
- * the way back in.
6
- *
7
- * The transcript is on disk under a `@react_buoy` key now, which the Storage
8
- * tool can read and the unauthenticated broker mirrors. Everything below is a
9
- * property that keeps that trade bounded: no tool-result payloads, no
10
- * credentials, no unbounded growth, and nothing that comes back claiming to
11
- * still be running.
12
- */
13
- import { describe, expect, it } from "vitest";
14
- import { buildPayload, fitToCaps, parsePayload } from "./transcriptPersistence";
15
- const msg = (over = {}) => ({
16
- id: "m1",
17
- role: "assistant",
18
- text: "ok",
19
- toolCalls: [],
20
- blocks: [],
21
- ...over
22
- });
23
- const build = (messages, history = []) => buildPayload({
24
- messages,
25
- history,
26
- answers: {},
27
- usage: {
28
- input: 0,
29
- output: 0,
30
- requests: 0
31
- }
32
- });
33
- describe("what reaches the disk", () => {
34
- it("never writes a tool result", () => {
35
- // The payloads are the sensitive half: storage values, response bodies, a
36
- // customer's record. The ROUND survives so the model can resume; what it
37
- // saw does not.
38
- const history = [{
39
- role: "user",
40
- text: "what's in the bag?"
41
- }, {
42
- role: "assistant",
43
- text: "",
44
- toolCalls: [{
45
- id: "c1",
46
- name: "buoy_zustand",
47
- input: {}
48
- }]
49
- }, {
50
- role: "tool-results",
51
- results: [{
52
- toolCallId: "c1",
53
- content: '{"lines":[{"card":"4111111111111111"}]}'
54
- }]
55
- }, {
56
- role: "assistant",
57
- text: "Five items."
58
- }];
59
- const saved = build([msg()], history);
60
- const json = JSON.stringify(saved);
61
- expect(json).not.toContain("4111111111111111");
62
- // The round itself is intact, so the pairing every provider requires holds.
63
- expect(saved.history.map(m => m.role)).toEqual(["user", "assistant", "tool-results", "assistant"]);
64
- });
65
- it("never writes a step's result, even when it writes the step", () => {
66
- // The step survives so the trace still reads; the payload is the thing the
67
- // no-tool-results-on-disk promise is about.
68
- const saved = build([msg({
69
- toolCalls: [{
70
- id: "c1",
71
- toolId: "zustand",
72
- action: "getStoreState",
73
- label: "Read the bag",
74
- status: "ok",
75
- summary: "Done",
76
- params: '{"storeName":"bag"}',
77
- result: '{"card":"4111111111111111"}'
78
- }]
79
- })]);
80
- expect(JSON.stringify(saved)).not.toContain("4111111111111111");
81
- expect(saved.messages[0].toolCalls[0].result).toBeUndefined();
82
- expect(saved.messages[0].toolCalls[0].action).toBe("getStoreState");
83
- });
84
- it("scrubs credential shapes out of what the agent said", () => {
85
- const saved = build([msg({
86
- text: "The header was Bearer abcdefghijklmnop123456"
87
- })]);
88
- expect(saved.messages[0].text).not.toContain("abcdefghijklmnop123456");
89
- });
90
- it("caps a long session instead of growing a file forever", () => {
91
- const many = Array.from({
92
- length: 400
93
- }, (_, i) => msg({
94
- id: `m${i}`,
95
- text: `answer ${i}`
96
- }));
97
- const saved = build(many);
98
- expect(saved.messages.length).toBeLessThanOrEqual(60);
99
- // Newest kept, oldest dropped — the end of a session is the useful end.
100
- expect(saved.messages[saved.messages.length - 1].text).toBe("answer 399");
101
- });
102
- it("drops from the oldest end until a heavy transcript fits", () => {
103
- const heavy = Array.from({
104
- length: 20
105
- }, (_, i) => msg({
106
- id: `m${i}`,
107
- text: "x".repeat(40_000)
108
- }));
109
- const saved = fitToCaps({
110
- v: 1,
111
- savedAt: 0,
112
- messages: heavy,
113
- history: [],
114
- answers: {},
115
- usage: {
116
- input: 0,
117
- output: 0,
118
- requests: 0
119
- }
120
- });
121
- expect(JSON.stringify(saved).length).toBeLessThanOrEqual(256_000);
122
- expect(saved.messages.length).toBeGreaterThan(0);
123
- });
124
- });
125
- describe("what comes back", () => {
126
- it("marks a turn the app died in as interrupted rather than blank", () => {
127
- // The crash case this feature exists for. An empty bubble with no
128
- // explanation reads as the model having nothing to say.
129
- const saved = build([msg({
130
- text: "",
131
- streaming: true
132
- })]);
133
- expect(saved.messages[0].streaming).toBe(false);
134
- expect(saved.messages[0].error).toMatch(/interrupted/i);
135
- });
136
- it("never restores a tool call still claiming to run", () => {
137
- const saved = build([msg({
138
- streaming: true,
139
- toolCalls: [{
140
- id: "c1",
141
- toolId: "storage",
142
- action: "set",
143
- label: "Write a key",
144
- status: "running"
145
- }]
146
- })]);
147
- expect(saved.messages[0].toolCalls[0].status).toBe("failed");
148
- expect(saved.messages[0].toolCalls[0].summary).toBe("Interrupted");
149
- });
150
- it("keeps an answer that already finished exactly as it was", () => {
151
- const saved = build([msg({
152
- text: "Five items.",
153
- streaming: false
154
- })]);
155
- expect(saved.messages[0].error).toBeUndefined();
156
- expect(saved.messages[0].text).toBe("Five items.");
157
- });
158
- it("treats anything it cannot trust as no transcript at all", () => {
159
- expect(parsePayload(null)).toBeNull();
160
- expect(parsePayload("not json")).toBeNull();
161
- // An older shape is dropped, not coerced — a half-read transcript is worse
162
- // than a missing one.
163
- expect(parsePayload(JSON.stringify({
164
- v: 0,
165
- messages: [msg()]
166
- }))).toBeNull();
167
- expect(parsePayload(JSON.stringify({
168
- v: 1,
169
- messages: []
170
- }))).toBeNull();
171
- });
172
- it("round-trips a real conversation", () => {
173
- const saved = build([msg({
174
- role: "user",
175
- text: "hi"
176
- }), msg({
177
- id: "m2",
178
- text: "hello"
179
- })]);
180
- const back = parsePayload(JSON.stringify(saved));
181
- expect(back?.messages.map(m => m.text)).toEqual(["hi", "hello"]);
182
- });
183
- });
184
- //# sourceMappingURL=transcriptPersistence.test.js.map
1
+ "use strict";import{describe,expect,it}from"vitest";import{buildPayload,fitToCaps,parsePayload}from"./transcriptPersistence";const msg=(e={})=>({id:"m1",role:"assistant",text:"ok",toolCalls:[],blocks:[],...e}),build=(e,t=[])=>buildPayload({messages:e,history:t,answers:{},usage:{input:0,output:0,requests:0}});describe("what reaches the disk",()=>{it("never writes a tool result",()=>{const e=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."}]),t=JSON.stringify(e);expect(t).not.toContain("4111111111111111"),expect(e.history.map(e=>e.role)).toEqual(["user","assistant","tool-results","assistant"])}),it("never writes a step's result, even when it writes the step",()=>{const e=build([msg({toolCalls:[{id:"c1",toolId:"zustand",action:"getStoreState",label:"Read the bag",status:"ok",summary:"Done",params:'{"storeName":"bag"}',result:'{"card":"4111111111111111"}'}]})]);expect(JSON.stringify(e)).not.toContain("4111111111111111"),expect(e.messages[0].toolCalls[0].result).toBeUndefined(),expect(e.messages[0].toolCalls[0].action).toBe("getStoreState")}),it("scrubs credential shapes out of what the agent said",()=>{const e=build([msg({text:"The header was Bearer abcdefghijklmnop123456"})]);expect(e.messages[0].text).not.toContain("abcdefghijklmnop123456")}),it("caps a long session instead of growing a file forever",()=>{const e=Array.from({length:400},(e,t)=>msg({id:`m${t}`,text:`answer ${t}`})),t=build(e);expect(t.messages.length).toBeLessThanOrEqual(60),expect(t.messages[t.messages.length-1].text).toBe("answer 399")}),it("drops from the oldest end until a heavy transcript fits",()=>{const e=Array.from({length:20},(e,t)=>msg({id:`m${t}`,text:"x".repeat(4e4)})),t=fitToCaps({v:1,savedAt:0,messages:e,history:[],answers:{},usage:{input:0,output:0,requests:0}});expect(JSON.stringify(t).length).toBeLessThanOrEqual(256e3),expect(t.messages.length).toBeGreaterThan(0)})}),describe("what comes back",()=>{it("marks a turn the app died in as interrupted rather than blank",()=>{const e=build([msg({text:"",streaming:!0})]);expect(e.messages[0].streaming).toBe(!1),expect(e.messages[0].error).toMatch(/interrupted/i)}),it("never restores a tool call still claiming to run",()=>{const e=build([msg({streaming:!0,toolCalls:[{id:"c1",toolId:"storage",action:"set",label:"Write a key",status:"running"}]})]);expect(e.messages[0].toolCalls[0].status).toBe("failed"),expect(e.messages[0].toolCalls[0].summary).toBe("Interrupted")}),it("keeps an answer that already finished exactly as it was",()=>{const e=build([msg({text:"Five items.",streaming:!1})]);expect(e.messages[0].error).toBeUndefined(),expect(e.messages[0].text).toBe("Five items.")}),it("treats anything it cannot trust as no transcript at all",()=>{expect(parsePayload(null)).toBeNull(),expect(parsePayload("not json")).toBeNull(),expect(parsePayload(JSON.stringify({v:0,messages:[msg()]}))).toBeNull(),expect(parsePayload(JSON.stringify({v:1,messages:[]}))).toBeNull()}),it("round-trips a real conversation",()=>{const e=build([msg({role:"user",text:"hi"}),msg({id:"m2",text:"hello"})]),t=parsePayload(JSON.stringify(e));expect(t?.messages.map(e=>e.text)).toEqual(["hi","hello"])})}),describe("an unanswered approval",()=>{const e={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:()=>{}},t=(t={})=>buildPayload({messages:[msg()],history:[],answers:{},usage:{input:0,output:0,requests:0},pending:{...e,...t}});it("survives the round trip with the exact call it asked about",()=>{const e=parsePayload(JSON.stringify(t()));expect(e?.pending).toMatchObject({toolId:"zustand",action:"setState",label:"Update the Poké Mart bag store",params:{storeName:"bag",data:{lines:[]}}})}),it("is saved again after it has already been restored once",()=>{expect(t({restored:!0}).pending).toBeTruthy()}),it("is dropped rather than scrubbed when the call carries a credential",()=>{const e=t({params:{key:"auth",value:"Bearer abcdefghijklmnop123456"}});expect(e.pending).toBeNull(),expect(JSON.stringify(e)).not.toContain("abcdefghijklmnop123456")}),it("reads back as absent from a transcript written before it existed",()=>{const e=build([msg()]);expect(parsePayload(JSON.stringify(e))?.pending).toBeNull()}),it("refuses a malformed one rather than restoring half a question",()=>{const e=JSON.stringify({...build([msg()]),pending:{toolId:"zustand"}});expect(parsePayload(e)?.pending).toBeNull()})}),describe("the effect ledger",()=>{const e={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"}},t=e=>buildPayload({messages:[msg()],history:[],answers:{},usage:{input:0,output:0,requests:0},ledger:e});it("survives the round trip with the prior value an undo needs",()=>{const s=parsePayload(JSON.stringify(t([e])));expect(s?.ledger).toHaveLength(1),expect(s?.ledger?.[0]).toMatchObject({toolId:"storage",action:"async.setItem"})}),it("drops an entry holding a credential rather than rewriting it",()=>{const s={...e,effect:{...e.effect,previous:"Bearer abcdefghijklmnop123456"}},a=t([s]);expect(a.ledger).toBeUndefined(),expect(JSON.stringify(a)).not.toContain("abcdefghijklmnop123456")}),it("reads back as absent from a transcript written before it existed",()=>{expect(parsePayload(JSON.stringify(build([msg()])))?.ledger).toBeUndefined()})});
@@ -0,0 +1 @@
1
+ "use strict";import{beforeEach,describe,expect,it}from"vitest";import{askBuoyStore,queuePauseReason}from"./askBuoyStore";beforeEach(()=>askBuoyStore.reset());const lastText=()=>askBuoyStore.getState().messages.at(-1)?.text??"";describe("round boundaries",()=>{it("opens a paragraph when the engine says a new round began",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"text",delta:"Wiping storage now."}),askBuoyStore.applyEvent(e,{type:"text",delta:"No problem — I left it alone.",breakBefore:!0}),expect(lastText()).toBe("Wiping storage now.\n\nNo problem — I left it alone.")}),it("still streams deltas within one round straight together",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"text",delta:"Hello"}),askBuoyStore.applyEvent(e,{type:"text",delta:" there."}),expect(lastText()).toBe("Hello there.")}),it("never opens with a blank line",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"text",delta:"First words.",breakBefore:!0}),expect(lastText()).toBe("First words.")})}),describe("a declined call",()=>{it("keeps its row and reads as declined, not failed",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"tool-start",id:"c1",toolId:"storage",action:"clearAll",label:"Clear all saved app data",description:"Wipe every stored key",params:{},effect:"destructive"}),askBuoyStore.applyEvent(e,{type:"tool-end",id:"c1",ok:!1,summary:"declined",durationMs:0}),expect(askBuoyStore.getState().messages.at(-1)?.toolCalls[0]).toMatchObject({label:"Clear all saved app data",status:"declined"})})}),describe("stop",()=>{it("marks the turn stopped and leaves no error on it",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"text",delta:"Looking…"}),askBuoyStore.markStopped(e);const t=askBuoyStore.getState().messages.at(-1);expect(t?.stopped).toBe(!0),expect(t?.error).toBeUndefined()})}),describe("stop and the queue",()=>{it("keeps parked messages parked, and says why",()=>{askBuoyStore.addUser("first");const e=askBuoyStore.startAssistant();askBuoyStore.enqueue("do this next"),askBuoyStore.requestStop(),askBuoyStore.markStopped(e),askBuoyStore.finishAssistant(e);const t=askBuoyStore.getState();expect(t.queued.map(e=>e.text)).toEqual(["do this next"]),expect(queuePauseReason(t)).toMatch(/stopped/)}),it("hands one parked message back to the composer to edit",()=>{const e=askBuoyStore.enqueue("words");askBuoyStore.takeQueuedToDraft(e.id),expect(askBuoyStore.getState().queued).toEqual([]),expect(askBuoyStore.getState().draft).toBe("words"),askBuoyStore.clearDraft(),expect(askBuoyStore.getState().draft).toBeNull()})}),describe("hydrate",()=>{it("marks what it puts back",()=>{askBuoyStore.hydrate({messages:[{id:"m1",role:"assistant",text:"hi",toolCalls:[],blocks:[]}],answers:{},usage:{input:0,output:0,requests:0}}),expect(askBuoyStore.getState().messages[0]?.restored).toBe(!0)}),it("leaves a live message unmarked",()=>{askBuoyStore.addUser("live one"),expect(askBuoyStore.getState().messages[0]?.restored).toBeUndefined()})});