@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,361 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Conversation state for the sheet.
5
- *
6
- * A module-level store rather than component state for two reasons: the sheet
7
- * is unmounted whenever the tool is closed or minimised (and a conversation
8
- * that vanished because someone tapped away would be maddening), and the sync
9
- * adapter needs to read the same transcript to show it on the desktop.
10
- *
11
- * Persisted across restarts, on purpose, with the payloads left out — see
12
- * `transcriptPersistence.ts` for what is written and what that costs. The
13
- * store itself stays a plain in-memory store; saving is a subscriber, and
14
- * `hydrate` is the one way anything comes back in.
15
- */
16
- import { idFactory } from "@buoy-gg/agent-core";
17
-
18
- /** A block in a message, and (for receipts) the tool call that produced it. */
19
-
20
- /**
21
- * A stretch of the model's own reasoning, and where it fell.
22
- *
23
- * `afterCalls` is how many tool calls this message had already made when the
24
- * thought arrived, so the thinking view can lay reasoning and steps out in the
25
- * order they actually happened. One assistant bubble spans every turn of a
26
- * multi-step run, so "think, act, think, act" is the normal shape and showing
27
- * all the thoughts in a lump at the top would misreport it.
28
- */
29
-
30
- /**
31
- * Message ids carry this run's token — see agent-core's `runId`. A plain `m1`
32
- * collided head-on with the `m1` in a restored transcript, and the message
33
- * list keys on it.
34
- */
35
- const nextId = idFactory("m");
36
-
37
- /**
38
- * Params, as one readable line. Capped because a step can carry a whole
39
- * response body or a store's full state, and this is chrome inside a chat
40
- * bubble — the full value is a tool read away.
41
- */
42
- const MAX_PARAM_CHARS = 400;
43
- function encodeParams(params) {
44
- if (!params || Object.keys(params).length === 0) return undefined;
45
- try {
46
- const json = JSON.stringify(params);
47
- return json.length > MAX_PARAM_CHARS ? `${json.slice(0, MAX_PARAM_CHARS)}…` : json;
48
- } catch {
49
- return undefined;
50
- }
51
- }
52
- let state = {
53
- messages: [],
54
- busy: false,
55
- pending: null,
56
- notice: null,
57
- configured: false,
58
- answers: {},
59
- awaitingBlockId: null,
60
- actionState: {},
61
- queued: null,
62
- usage: {
63
- input: 0,
64
- output: 0,
65
- requests: 0
66
- },
67
- meta: {}
68
- };
69
- const listeners = new Set();
70
- let ledgerRef = null;
71
-
72
- /**
73
- * The session outlives the sheet the same way the transcript does. Session and
74
- * ledger used to be per-mount: closing and reopening the tool kept the visible
75
- * conversation but silently swapped in an empty ledger and a blank model
76
- * memory — the undo bar vanished while the agent's changes stayed live in the
77
- * app. Held here, keyed by a config signature so a real reconfiguration
78
- * (different endpoint/model/tool set) still rebuilds.
79
- */
80
- let heldSession = null;
81
- function set(next) {
82
- state = {
83
- ...state,
84
- ...next
85
- };
86
- for (const fn of listeners) {
87
- try {
88
- fn();
89
- } catch {
90
- // A throwing subscriber must not take the transcript down mid-answer.
91
- }
92
- }
93
- }
94
- export const askBuoyStore = {
95
- getState: () => state,
96
- subscribe(fn) {
97
- listeners.add(fn);
98
- return () => listeners.delete(fn);
99
- },
100
- setLedger(ledger) {
101
- ledgerRef = ledger;
102
- },
103
- getLedger() {
104
- return ledgerRef;
105
- },
106
- holdSession(session, signature) {
107
- heldSession = {
108
- session,
109
- signature
110
- };
111
- },
112
- getHeldSession() {
113
- return heldSession;
114
- },
115
- setNotice(notice) {
116
- set({
117
- notice
118
- });
119
- },
120
- setConfigured(configured) {
121
- if (configured !== state.configured) set({
122
- configured
123
- });
124
- },
125
- setMeta(meta) {
126
- const same = Object.keys(meta).every(k => state.meta[k] === meta[k]);
127
- if (!same) set({
128
- meta: {
129
- ...state.meta,
130
- ...meta
131
- }
132
- });
133
- },
134
- addUser(text) {
135
- set({
136
- messages: [...state.messages, {
137
- id: nextId(),
138
- role: "user",
139
- text,
140
- toolCalls: [],
141
- blocks: []
142
- }],
143
- busy: true
144
- });
145
- },
146
- /** Mark a turn as running without adding a bubble — the retry path. */
147
- beginTurn() {
148
- set({
149
- busy: true
150
- });
151
- },
152
- /** Park a message typed mid-turn instead of silently dropping it. */
153
- setQueued(text) {
154
- set({
155
- queued: text
156
- });
157
- },
158
- /** Drop one message — the failed assistant bubble a retry replaces. */
159
- removeMessage(id) {
160
- set({
161
- messages: state.messages.filter(m => m.id !== id)
162
- });
163
- },
164
- /** The user answered (or skipped) an Ask block. */
165
- recordAnswer(answer) {
166
- set({
167
- answers: {
168
- ...state.answers,
169
- [answer.blockId]: answer
170
- },
171
- awaitingBlockId: state.awaitingBlockId === answer.blockId ? null : state.awaitingBlockId
172
- });
173
- },
174
- setActionState(key, value) {
175
- const next = {
176
- ...state.actionState
177
- };
178
- if (value === null) delete next[key];else next[key] = value;
179
- set({
180
- actionState: next
181
- });
182
- },
183
- /** Open a new assistant bubble for the turn that is about to stream. */
184
- startAssistant() {
185
- const id = nextId();
186
- set({
187
- messages: [...state.messages, {
188
- id,
189
- role: "assistant",
190
- text: "",
191
- toolCalls: [],
192
- blocks: [],
193
- streaming: true,
194
- startedAt: Date.now()
195
- }]
196
- });
197
- return id;
198
- },
199
- /**
200
- * Fold one engine event into the open assistant message.
201
- *
202
- * Tool calls render as rows inside the bubble rather than as raw payloads:
203
- * the label is already domain-flavoured ("Set points to 1500"), which is the
204
- * only form a non-developer can actually check.
205
- */
206
- applyEvent(messageId, ev) {
207
- const messages = state.messages.map(m => {
208
- if (m.id !== messageId) return m;
209
- switch (ev.type) {
210
- case "text":
211
- return {
212
- ...m,
213
- text: m.breakBeforeNextText && m.text ? `${m.text.trimEnd()}\n\n${ev.delta}` : m.text + ev.delta,
214
- breakBeforeNextText: false
215
- };
216
- case "reasoning":
217
- return {
218
- ...m,
219
- breakBeforeNextText: true,
220
- reasoning: [...(m.reasoning ?? []), {
221
- text: ev.text,
222
- afterCalls: m.toolCalls.length
223
- }]
224
- };
225
- case "tool-start":
226
- return {
227
- ...m,
228
- toolCalls: [...m.toolCalls, {
229
- id: ev.id,
230
- toolId: ev.toolId,
231
- action: ev.action,
232
- label: ev.label,
233
- description: ev.description,
234
- status: "running",
235
- params: encodeParams(ev.params),
236
- effect: ev.effect,
237
- startedAt: Date.now()
238
- }]
239
- };
240
- case "tool-end":
241
- return {
242
- ...m,
243
- breakBeforeNextText: true,
244
- toolCalls: m.toolCalls.map(c => c.id === ev.id ? {
245
- ...c,
246
- status: !ev.ok && ev.summary === "refused" ? "refused" : ev.ok ? "ok" : "failed",
247
- summary: ev.summary,
248
- durationMs: ev.durationMs,
249
- result: ev.result
250
- } : c)
251
- };
252
- case "block":
253
- return {
254
- ...m,
255
- breakBeforeNextText: true,
256
- blocks: [...m.blocks, {
257
- block: ev.block,
258
- forToolCallId: ev.forToolCallId
259
- }]
260
- };
261
- case "usage":
262
- // Also folded into the session total below. Per MESSAGE as well,
263
- // because "which answer cost 40k tokens" is the question you ask
264
- // when a bill looks wrong, and a session total cannot answer it.
265
- return {
266
- ...m,
267
- usage: {
268
- input: (m.usage?.input ?? 0) + ev.input,
269
- output: (m.usage?.output ?? 0) + ev.output,
270
- requests: (m.usage?.requests ?? 0) + 1
271
- }
272
- };
273
- case "error":
274
- return {
275
- ...m,
276
- error: ev.message
277
- };
278
- default:
279
- return m;
280
- }
281
- });
282
- set({
283
- messages,
284
- ...(ev.type === "awaiting-user" ? {
285
- awaitingBlockId: ev.blockId
286
- } : {}),
287
- ...(ev.type === "usage" ? {
288
- usage: {
289
- input: state.usage.input + ev.input,
290
- output: state.usage.output + ev.output,
291
- requests: state.usage.requests + 1
292
- }
293
- } : {})
294
- });
295
- },
296
- finishAssistant(messageId) {
297
- set({
298
- messages: state.messages.map(m => m.id === messageId ? {
299
- ...m,
300
- streaming: false,
301
- endedAt: Date.now()
302
- } : m),
303
- busy: false
304
- });
305
- },
306
- askApproval(input) {
307
- return new Promise(resolve => {
308
- set({
309
- pending: {
310
- ...input,
311
- resolve
312
- }
313
- });
314
- });
315
- },
316
- answerApproval(approved) {
317
- const pending = state.pending;
318
- set({
319
- pending: null
320
- });
321
- pending?.resolve(approved);
322
- },
323
- /**
324
- * Put a saved conversation back, once, at open.
325
- *
326
- * Refuses if anything has been said already: a slow disk read landing after
327
- * the user has started typing must not shove an old chat in front of them.
328
- */
329
- hydrate(input) {
330
- if (state.messages.length > 0 || state.busy) return false;
331
- set({
332
- messages: input.messages,
333
- answers: input.answers,
334
- usage: input.usage
335
- });
336
- return true;
337
- },
338
- reset() {
339
- // Reject anything still waiting, or the turn hangs forever on a promise
340
- // whose only resolver just left the screen.
341
- state.pending?.resolve(false);
342
- set({
343
- messages: [],
344
- busy: false,
345
- pending: null,
346
- notice: null,
347
- answers: {},
348
- awaitingBlockId: null,
349
- actionState: {},
350
- queued: null,
351
- usage: {
352
- input: 0,
353
- output: 0,
354
- requests: 0
355
- }
356
- // `meta` survives: it describes the app and the endpoint, not the
357
- // conversation, and re-deriving it would need another render pass.
358
- });
359
- }
360
- };
361
- //# sourceMappingURL=askBuoyStore.js.map
1
+ "use strict";import{idFactory}from"@buoy-gg/agent-core";const nextId=idFactory("m"),MAX_PARAM_CHARS=400;function encodeParams(e){if(e&&0!==Object.keys(e).length)try{const t=JSON.stringify(e);return t.length>400?`${t.slice(0,400)}…`:t}catch{return}}const nextQueuedId=idFactory("q");let state={messages:[],busy:!1,stopping:!1,pending:null,trusted:[],notice:null,configured:!1,answers:{},awaitingBlockId:null,actionState:{},queued:[],draft:null,usage:{input:0,output:0,requests:0},meta:{}};const listeners=new Set;let ledgerRef=null,heldSession=null;function set(e){state={...state,...e};for(const e of listeners)try{e()}catch{}}export const askBuoyStore={getState:()=>state,subscribe:e=>(listeners.add(e),()=>listeners.delete(e)),setLedger(e){ledgerRef=e},getLedger:()=>ledgerRef,holdSession(e,t){heldSession={session:e,signature:t}},getHeldSession:()=>heldSession,setNotice(e){set({notice:e})},setConfigured(e){e!==state.configured&&set({configured:e})},setMeta(e){Object.keys(e).every(t=>state.meta[t]===e[t])||set({meta:{...state.meta,...e}})},addUser(e){set({messages:[...state.messages,{id:nextId(),role:"user",text:e,toolCalls:[],blocks:[]}],busy:!0})},beginTurn(){set({busy:!0})},enqueue(e){const t={id:nextQueuedId(),text:e};return set({queued:[...state.queued,t]}),t},removeQueued(e){state.queued.some(t=>t.id===e)&&set({queued:state.queued.filter(t=>t.id!==e)})},shiftQueued(){const[e,...t]=state.queued;if(e)return set({queued:t}),e},takeQueuedToDraft(e){const t=state.queued.find(t=>t.id===e);t&&set({queued:state.queued.filter(t=>t.id!==e),draft:t.text})},requestStop(){state.busy&&!state.stopping&&set({stopping:!0})},clearDraft(){null!==state.draft&&set({draft:null})},removeMessage(e){set({messages:state.messages.filter(t=>t.id!==e)})},recordAnswer(e){set({answers:{...state.answers,[e.blockId]:e},awaitingBlockId:state.awaitingBlockId===e.blockId?null:state.awaitingBlockId})},setActionState(e,t){const s={...state.actionState};null===t?delete s[e]:s[e]=t,set({actionState:s})},startAssistant(){const e=nextId();return set({messages:[...state.messages,{id:e,role:"assistant",text:"",toolCalls:[],blocks:[],streaming:!0,startedAt:Date.now()}]}),e},applyEvent(e,t){if("history-trimmed"===t.type){const s=state.messages.findIndex(t=>t.id===e),a={id:nextId(),role:"assistant",system:!0,text:`Older messages were trimmed from the agent's memory (${t.droppedRounds} exchange${1===t.droppedRounds?"":"s"}).`+(t.droppedPinned?` ${1===t.droppedPinned?"One of them made a change that is":`${t.droppedPinned} of them made changes that are`} still applied — the changes bar still lists ${1===t.droppedPinned?"it":"them"}, but the agent no longer remembers making ${1===t.droppedPinned?"it":"them"}.`:" It may not recall setup from earlier in this chat — the changes bar still lists what is applied."),toolCalls:[],blocks:[],endedAt:Date.now()},n=[...state.messages];return n.splice(s<0?n.length:s,0,a),void set({messages:n})}set({messages:state.messages.map(s=>{if(s.id!==e)return s;switch(t.type){case"retrying":{const e=Math.max(1,Math.round(t.inMs/1e3));return{...s,waiting:"throttled"===t.reason?`Endpoint busy — retrying in ${e}s (${t.attempt} of ${t.maxAttempts})`:"Request too large — trimming older messages and retrying"}}case"text":return{...s,waiting:void 0,text:(s.breakBeforeNextText||t.breakBefore)&&s.text?`${s.text.trimEnd()}\n\n${t.delta}`:s.text+t.delta,breakBeforeNextText:!1};case"reasoning":return{...s,breakBeforeNextText:!0,reasoning:[...s.reasoning??[],{text:t.text,afterCalls:s.toolCalls.length}]};case"tool-start":return{...s,waiting:void 0,toolCalls:[...s.toolCalls,{id:t.id,toolId:t.toolId,action:t.action,label:t.label,description:t.description,status:"running",params:encodeParams(t.params),effect:t.effect,startedAt:Date.now()}]};case"tool-end":return{...s,breakBeforeNextText:!0,toolCalls:s.toolCalls.map(e=>e.id===t.id?{...e,status:t.ok||"refused"!==t.summary?t.ok||"declined"!==t.summary?t.ok||"stopped"!==t.summary?t.ok?"ok":"failed":"stopped":"declined":"refused",summary:t.summary,durationMs:t.durationMs,result:t.result}:e)};case"tool-verified":return{...s,toolCalls:s.toolCalls.map(e=>e.id===t.id?{...e,verification:t.verification}:e)};case"block":return{...s,breakBeforeNextText:!0,blocks:[...s.blocks,{block:t.block,forToolCallId:t.forToolCallId}]};case"usage":return{...s,usage:{input:(s.usage?.input??0)+t.input,output:(s.usage?.output??0)+t.output,requests:(s.usage?.requests??0)+1}};case"error":return{...s,waiting:void 0,error:t.message};default:return s}}),..."awaiting-user"===t.type?{awaitingBlockId:t.blockId}:{},..."usage"===t.type?{usage:{input:state.usage.input+t.input,output:state.usage.output+t.output,requests:state.usage.requests+1}}:{}})},markStopped(e){set({messages:state.messages.map(t=>t.id===e?{...t,stopped:!0}:t)})},finishAssistant(e){set({messages:state.messages.map(t=>t.id===e?{...t,streaming:!1,endedAt:Date.now()}:t),busy:!1,stopping:!1})},askApproval:e=>new Promise(t=>{set({pending:{...e,resolve:t}})}),answerApproval(e){const t=state.pending,s="boolean"==typeof e?e:e.approved,a="boolean"!=typeof e&&!0===e.trust&&s,n=t?`${t.toolId}.${t.action}`:"";set({pending:null,...a&&t&&!state.trusted.some(e=>e.key===n)?{trusted:[...state.trusted,{key:n,label:t.label}]}:{}}),t?.resolve(e)},untrust(e){heldSession?.session.untrust(e),set({trusted:state.trusted.filter(t=>t.key!==e)})},restorePending:e=>!state.pending&&!state.busy&&(set({pending:{...e,restored:!0,resolve:()=>{}}}),!0),addNote(e){set({messages:[...state.messages,{id:nextId(),role:"assistant",text:e,toolCalls:[],blocks:[],endedAt:Date.now()}]})},hydrate:e=>!(state.messages.length>0||state.busy||(set({messages:e.messages.map(e=>({...e,restored:!0})),answers:e.answers,usage:e.usage,queued:e.queued??[]}),0)),reset(){state.pending?.resolve(!1),set({messages:[],busy:!1,stopping:!1,pending:null,trusted:[],notice:null,answers:{},awaitingBlockId:null,actionState:{},queued:[],draft:null,usage:{input:0,output:0,requests:0}})}};export function turnPhaseOf(e){return e.pending?"awaitingApproval":e.busy?e.stopping?"stopping":"running":e.awaitingBlockId?"awaitingAnswer":"idle"}export function queuePauseReason(e){const t=turnPhaseOf(e);if("running"===t||"stopping"===t)return null;if("awaitingApproval"===t)return"Paused — answer the approval above first.";if("awaitingAnswer"===t)return"Paused — answer the question above first.";const s=e.messages[e.messages.length-1];return"assistant"===s?.role&&s.error?"Paused — the last turn failed.":"assistant"===s?.role&&s.stopped?"Paused — you stopped the last turn.":null}
@@ -0,0 +1 @@
1
+ "use strict";import{isAskBlock}from"@buoy-gg/agent-core";function nestsUnderStep({block:o,forToolCallId:e}){if(!e)return!1;const s="source"in o?o.source:void 0;return"live"===s||"mocked"===s}export function placeBlocks(o,e){const s=new Set(e),t=new Map,l=[],r=[];for(const e of o)if(isAskBlock(e.block))r.push(e);else if(nestsUnderStep(e)&&s.has(e.forToolCallId)){const o=t.get(e.forToolCallId)??[];o.push(e.block),t.set(e.forToolCallId,o)}else l.push(e);return{nested:t,afterText:l,ask:r}}
@@ -0,0 +1 @@
1
+ "use strict";import{describe,expect,it}from"vitest";import{placeBlocks}from"./blockPlacement";const placed=(e,t)=>({block:e,forToolCallId:t}),grid=(e="ui1")=>placed({id:e,kind:"imageGrid",source:"model",images:[{url:"https://cdn.example.com/25.png",alt:"Pikachu"}]},"call-ui");describe("model-authored blocks",()=>{it("renders in the answer, never nested under a step that has no row",()=>{const{afterText:e,nested:t}=placeBlocks([grid()],["c1"]);expect(e.map(e=>e.block.id)).toEqual(["ui1"]),expect(t.size).toBe(0)}),it("still renders even when a step with that id somehow exists",()=>{const{afterText:e}=placeBlocks([grid()],["call-ui"]);expect(e.map(e=>e.block.id)).toEqual(["ui1"])})}),describe("receipts",()=>{it("folds a read receipt into its own step row",()=>{const e=placed({id:"r1",kind:"keyValue",source:"live",pairs:[]},"c1"),{nested:t,afterText:c}=placeBlocks([e],["c1"]);expect(c).toEqual([]),expect(t.get("c1")?.map(e=>e.id)).toEqual(["r1"])}),it("keeps a write receipt afterText — the user must see it without asking",()=>{const e=placed({id:"w1",kind:"diff",source:"changed",changes:[]},"c1"),{nested:t,afterText:c}=placeBlocks([e],["c1"]);expect(t.size).toBe(0),expect(c.map(e=>e.block.id)).toEqual(["w1"])}),it("falls back to afterText when its step row was never drawn",()=>{const e=placed({id:"r2",kind:"keyValue",source:"live",pairs:[]},"gone"),{afterText:t}=placeBlocks([e],[]);expect(t.map(e=>e.block.id)).toEqual(["r2"])})}),describe("ask blocks",()=>{it("come out in their own bucket, after the answer",()=>{const e=placed({id:"a1",kind:"confirm",source:"model",change:"Wipe storage"},"call-ui"),{ask:t,afterText:c,nested:a}=placeBlocks([e,grid("ui2")],["c1"]);expect(t.map(e=>e.block.id)).toEqual(["a1"]),expect(c.map(e=>e.block.id)).toEqual(["ui2"]),expect(a.size).toBe(0)})}),describe("the answer comes after the prose",()=>{it("puts a model-authored card in the after-text bucket, never before it",()=>{const e=placeBlocks([grid()],["c1"]);expect(e.afterText.map(e=>e.block.id)).toEqual(["ui1"]),expect(e.nested.size).toBe(0)})});
@@ -0,0 +1 @@
1
+ "use strict";import{beforeEach,describe,expect,it}from"vitest";import{askBuoyStore,queuePauseReason,turnPhaseOf}from"./askBuoyStore";beforeEach(()=>askBuoyStore.reset());const texts=()=>askBuoyStore.getState().queued.map(e=>e.text);describe("queue",()=>{it("keeps every message, in the order typed",()=>{askBuoyStore.enqueue("then set points to 1500"),askBuoyStore.enqueue("and clear the cart after"),expect(texts()).toEqual(["then set points to 1500","and clear the cart after"])}),it("gives identical requests distinct ids",()=>{const e=askBuoyStore.enqueue("again"),t=askBuoyStore.enqueue("again");expect(e.id).not.toBe(t.id),askBuoyStore.removeQueued(e.id),expect(texts()).toEqual(["again"])}),it("delivers from the front, one at a time",()=>{askBuoyStore.enqueue("one"),askBuoyStore.enqueue("two"),expect(askBuoyStore.shiftQueued()?.text).toBe("one"),expect(texts()).toEqual(["two"]),expect(askBuoyStore.shiftQueued()?.text).toBe("two"),expect(askBuoyStore.shiftQueued()).toBeUndefined()}),it("comes back from disk as unsent rows",()=>{const e=askBuoyStore.hydrate({messages:[{id:"m1",role:"user",text:"hi",toolCalls:[],blocks:[]}],answers:{},usage:{input:0,output:0,requests:0},queued:[{id:"q1",text:"still waiting"}]});expect(e).toBe(!0),expect(texts()).toEqual(["still waiting"]),expect(turnPhaseOf(askBuoyStore.getState())).toBe("idle")}),it("is emptied by a new conversation",()=>{askBuoyStore.enqueue("gone"),askBuoyStore.reset(),expect(texts()).toEqual([])})}),describe("turnPhase",()=>{it("is idle with nothing going on",()=>{expect(turnPhaseOf(askBuoyStore.getState())).toBe("idle")}),it("is running during a turn, and stopping once Stop is pressed",()=>{askBuoyStore.addUser("go"),askBuoyStore.startAssistant(),expect(turnPhaseOf(askBuoyStore.getState())).toBe("running"),askBuoyStore.requestStop(),expect(turnPhaseOf(askBuoyStore.getState())).toBe("stopping")}),it("is awaitingApproval while a card is up, even though the turn is busy",()=>{askBuoyStore.addUser("wipe it"),askBuoyStore.startAssistant(),askBuoyStore.askApproval({id:"c1",toolId:"storage",action:"clearAll",label:"Clear all saved app data",reason:"Wipes everything"}),expect(turnPhaseOf(askBuoyStore.getState())).toBe("awaitingApproval")}),it("is awaitingAnswer after a turn ends on an Ask block",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"awaiting-user",blockId:"b1"}),askBuoyStore.finishAssistant(e),expect(turnPhaseOf(askBuoyStore.getState())).toBe("awaitingAnswer")})}),describe("when the queue holds",()=>{it("delivers when idle and the last turn was fine",()=>{askBuoyStore.addUser("hi");const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"text",delta:"Hello."}),askBuoyStore.finishAssistant(e),expect(queuePauseReason(askBuoyStore.getState())).toBeNull()}),it("holds after an error, and says so",()=>{askBuoyStore.addUser("hi");const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"error",message:"fetch failed"}),askBuoyStore.finishAssistant(e),expect(queuePauseReason(askBuoyStore.getState())).toMatch(/failed/)}),it("holds while an approval card is up",()=>{askBuoyStore.addUser("wipe"),askBuoyStore.startAssistant(),askBuoyStore.askApproval({id:"c1",toolId:"storage",action:"clearAll",label:"Clear all saved app data",reason:"Wipes everything"}),expect(queuePauseReason(askBuoyStore.getState())).toMatch(/approval/)}),it("holds while a question is unanswered — a queued task is not the answer",()=>{const e=askBuoyStore.startAssistant();askBuoyStore.applyEvent(e,{type:"awaiting-user",blockId:"b1"}),askBuoyStore.finishAssistant(e),expect(queuePauseReason(askBuoyStore.getState())).toMatch(/question/)}),it("says nothing while a turn is still running — the queue is simply waiting",()=>{askBuoyStore.addUser("go"),askBuoyStore.startAssistant(),expect(queuePauseReason(askBuoyStore.getState())).toBeNull()})});
@@ -0,0 +1 @@
1
+ "use strict";import{askBuoyStore}from"./askBuoyStore";import{clearTranscript}from"./transcriptPersistence";export function clearConversation(){askBuoyStore.getHeldSession()?.session.reset(),askBuoyStore.reset(),clearTranscript()}export async function resetConversation(e){if(askBuoyStore.getState().busy)return{cleared:!1,reverted:0,failed:[{label:"A turn is running",error:"Stop it first."}]};const r=askBuoyStore.getLedger();if(e.undoFirst&&r){const t=await r.revertAll(e.dispatch);return t.failed.length>0?{cleared:!1,reverted:t.reverted,failed:t.failed}:(clearConversation(),{cleared:!0,reverted:t.reverted,failed:[]})}return clearConversation(),{cleared:!0,reverted:0,failed:[]}}
@@ -0,0 +1 @@
1
+ "use strict";import{beforeEach,describe,expect,it}from"vitest";import{askBuoyStore}from"./askBuoyStore";const card={id:"c1",toolId:"zustand",action:"setState",label:"Update the Poké Mart bag store",reason:"This will change the app's state.",params:{storeName:"bag"}};beforeEach(()=>askBuoyStore.reset()),describe("restorePending",()=>{it("puts the card back on screen",()=>{expect(askBuoyStore.restorePending(card)).toBe(!0),expect(askBuoyStore.getState().pending).toMatchObject({toolId:"zustand",action:"setState",params:{storeName:"bag"}})}),it("marks it restored, so Allow runs the call instead of answering a dead promise",()=>{askBuoyStore.restorePending(card),expect(askBuoyStore.getState().pending?.restored).toBe(!0)}),it("refuses once a turn is under way",()=>{askBuoyStore.beginTurn(),expect(askBuoyStore.restorePending(card)).toBe(!1),expect(askBuoyStore.getState().pending).toBeNull()}),it("refuses when a live card is already asking",()=>{askBuoyStore.askApproval(card),expect(askBuoyStore.restorePending({...card,id:"c2"})).toBe(!1),expect(askBuoyStore.getState().pending?.id).toBe("c1")}),it("answers without throwing, though nothing is waiting on it",()=>{askBuoyStore.restorePending(card),expect(()=>askBuoyStore.answerApproval(!0)).not.toThrow(),expect(askBuoyStore.getState().pending).toBeNull()})});
@@ -1,46 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Ids from a RESTORED transcript must never collide with a fresh run's.
5
- *
6
- * The bug this covers, in full: every id counter restarted at 1 with the
7
- * process, which was harmless until the transcript started outliving a reload.
8
- * A restored conversation came back holding `rc1`, `ui1` and `m1`; the next
9
- * turn minted `rc1` again; React saw two children with one key and rendered
10
- * one of them twice while dropping the other. On screen that was the same
11
- * store card appearing twice after a reload.
12
- *
13
- * Simulating a restart in one process is the whole difficulty — the module
14
- * caches its counter. `idFactory` is the seam: a second factory stands in for
15
- * the second run, and the shared RUN_ID is what has to differ between them.
16
- */
17
- import { describe, expect, it } from "vitest";
18
- import { idFactory, RUN_ID } from "@buoy-gg/agent-core";
19
- describe("ids across a restart", () => {
20
- it("never reissues an id a restored transcript already holds", () => {
21
- // What a saved transcript carries, from a previous launch.
22
- const restored = ["rcOLDRUN-1", "rcOLDRUN-2", "uiOLDRUN-1", "mOLDRUN-1"];
23
- const rc = idFactory("rc");
24
- const ui = idFactory("ui");
25
- const m = idFactory("m");
26
- const fresh = [rc(), rc(), ui(), m()];
27
- for (const id of fresh) expect(restored).not.toContain(id);
28
- });
29
- it("still counts up within one run", () => {
30
- // The counter is what keeps two blocks in the SAME turn apart.
31
- const rc = idFactory("rc");
32
- const ids = [rc(), rc(), rc()];
33
- expect(new Set(ids).size).toBe(3);
34
- });
35
- it("keeps two prefixes apart even at the same count", () => {
36
- const rc = idFactory("rc");
37
- const ui = idFactory("ui");
38
- expect(rc()).not.toBe(ui());
39
- });
40
- it("stamps a run token that is not a fixed string", () => {
41
- // A constant here would put every install back where it started.
42
- expect(RUN_ID).toMatch(/^[a-z0-9]{4,8}$/);
43
- expect(idFactory("rc")()).toBe(`rc${RUN_ID}-1`);
44
- });
45
- });
46
- //# sourceMappingURL=restoredIds.test.js.map
1
+ "use strict";import{describe,expect,it}from"vitest";import{idFactory,RUN_ID}from"@buoy-gg/agent-core";describe("ids across a restart",()=>{it("never reissues an id a restored transcript already holds",()=>{const t=["rcOLDRUN-1","rcOLDRUN-2","uiOLDRUN-1","mOLDRUN-1"],e=idFactory("rc"),r=idFactory("ui"),o=idFactory("m"),i=[e(),e(),r(),o()];for(const e of i)expect(t).not.toContain(e)}),it("still counts up within one run",()=>{const t=idFactory("rc"),e=[t(),t(),t()];expect(new Set(e).size).toBe(3)}),it("keeps two prefixes apart even at the same count",()=>{const t=idFactory("rc"),e=idFactory("ui");expect(t()).not.toBe(e())}),it("stamps a run token that is not a fixed string",()=>{expect(RUN_ID).toMatch(/^[a-z0-9]{4,8}$/),expect(idFactory("rc")()).toBe(`rc${RUN_ID}-1`)})});
@@ -0,0 +1 @@
1
+ "use strict";export const SUGGESTIONS=[{text:"Why is this screen empty?"},{text:"What did the last few network calls return?",needs:"network"},{text:"Show me what's saved for this user",needs:"storage"},{text:"Make the next request to this screen fail with a 500",needs:"network",write:!0,devOnly:!0},{text:"Who am I signed in as right now?"},{text:"Did anything crash or log an error recently?",needs:"console"}];export const MAX_SUGGESTIONS=4;export function pickSuggestions(e){const t=e.availableToolIds.length>0;return SUGGESTIONS.filter(s=>(!s.write||!e.readOnly)&&(!s.devOnly||!e.isRelease)&&(!s.needs||t&&e.availableToolIds.includes(s.needs))).slice(0,4).map(e=>e.text)}
@@ -0,0 +1 @@
1
+ "use strict";import{describe,expect,it}from"vitest";import{MAX_SUGGESTIONS,pickSuggestions}from"./suggestions";const all=["network","storage","console","query"];describe("pickSuggestions",()=>{it("offers the simulation only on a dev build that may write",()=>{const e=pickSuggestions({availableToolIds:all,readOnly:!1,isRelease:!1});expect(e).toContain("Make the next request to this screen fail with a 500");const t=pickSuggestions({availableToolIds:all,readOnly:!1,isRelease:!0});expect(t).not.toContain("Make the next request to this screen fail with a 500");const s=pickSuggestions({availableToolIds:all,readOnly:!0,isRelease:!1});expect(s).not.toContain("Make the next request to this screen fail with a 500")}),it("drops chips whose tool is not on this device",()=>{const e=pickSuggestions({availableToolIds:["storage"],readOnly:!1,isRelease:!1});expect(e).not.toContain("What did the last few network calls return?"),expect(e).toContain("Show me what's saved for this user")}),it("shows only tool-free chips until the registry has reported",()=>{const e=pickSuggestions({availableToolIds:[],readOnly:!1,isRelease:!1});expect(e).toEqual(["Why is this screen empty?","Who am I signed in as right now?"])}),it("never exceeds the cap and keeps the order",()=>{const e=pickSuggestions({availableToolIds:all,readOnly:!1,isRelease:!1});expect(e.length).toBeLessThanOrEqual(MAX_SUGGESTIONS),expect(e[0]).toBe("Why is this screen empty?")})});
@@ -0,0 +1 @@
1
+ "use strict";import{beforeEach,describe,expect,it}from"vitest";import{askBuoyStore}from"./askBuoyStore";import{buildPayload,parsePayload}from"./transcriptPersistence";beforeEach(()=>askBuoyStore.reset()),describe("history-trimmed",()=>{it("inserts a system line before the answer it affects",()=>{askBuoyStore.addUser("turn off that override");const t=askBuoyStore.startAssistant();askBuoyStore.applyEvent(t,{type:"history-trimmed",droppedRounds:3}),askBuoyStore.applyEvent(t,{type:"text",delta:"Turning it off."});const e=askBuoyStore.getState().messages.map(t=>t.system?"system":t.role);expect(e).toEqual(["user","system","assistant"]);const s=askBuoyStore.getState().messages[1];expect(s.text).toMatch(/3 exchanges/),expect(s.text).toMatch(/changes bar still lists/)}),it("singular for one round",()=>{const t=askBuoyStore.startAssistant();askBuoyStore.applyEvent(t,{type:"history-trimmed",droppedRounds:1}),expect(askBuoyStore.getState().messages[0].text).toMatch(/1 exchange\)/)})}),describe("restored approval freshness",()=>{it("carries the target digest to disk and back, never the target",()=>{const t=buildPayload({messages:[{id:"m1",role:"user",text:"set it",toolCalls:[],blocks:[]}],history:[],answers:{},usage:{input:0,output:0,requests:0},pending:{id:"c1",toolId:"zustand",action:"setState",label:"Update the bag store",reason:"Replaces part of the store",params:{storeName:"bag",state:{qty:14}},targetDigest:"1a2b3c:512",resolve:()=>{}}}),e=JSON.stringify(t);expect(e).toContain("1a2b3c:512");const s=parsePayload(e);expect(s?.pending?.targetDigest).toBe("1a2b3c:512")})});
@@ -0,0 +1 @@
1
+ "use strict";export const TICKET_PROMPT="Summarize this conversation as a bug ticket, using one buoy_ui finding block and nothing else. Title it with the problem in one line. Evidence rows, in this order: Steps (what we did), Expected, Observed, Build (dev or release, platform), Evidence (the exact requests, statuses, logs or values you actually saw this conversation), Still applied (overrides or changes from your changes list that are still live, or 'none'). Only facts you observed in this conversation; write 'unknown' where you don't know rather than guessing, and put anything you inferred rather than saw in a final row labelled Inference. Do not run any tool or change anything to produce this.";
@@ -1,75 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * The agent's work for one answer, laid out in the order it happened.
5
- *
6
- * `traceEntries` is the ordering, shared by the collapsible strip in the chat
7
- * and by the JSON export — the two must agree, because the point of the export
8
- * is reading elsewhere the run you were just looking at. `traceToText` is the
9
- * plain-text rendering, kept for a quick paste into Slack; the debugging
10
- * artefact is `sessionExport.ts`.
11
- *
12
- * Reasoning and steps INTERLEAVE. One assistant bubble spans every turn of a
13
- * multi-step run, so the real shape is "think, act, think, act"; lumping the
14
- * thoughts at the top would misreport when the model knew what.
15
- */
16
-
17
- export function traceEntries(message) {
18
- const thoughts = [...(message.reasoning ?? [])].sort((a, b) => a.afterCalls - b.afterCalls);
19
- const out = [];
20
- let t = 0;
21
- const drainTo = calls => {
22
- while (t < thoughts.length && thoughts[t].afterCalls <= calls) {
23
- out.push({
24
- kind: "thought",
25
- text: thoughts[t].text
26
- });
27
- t += 1;
28
- }
29
- };
30
- message.toolCalls.forEach((call, i) => {
31
- drainTo(i);
32
- out.push({
33
- kind: "step",
34
- n: i + 1,
35
- call
36
- });
37
- });
38
- // Anything the model thought after its last tool call — usually the reasoning
39
- // behind the answer itself, which is the most useful line in the trace.
40
- drainTo(message.toolCalls.length);
41
- return out;
42
- }
43
-
44
- /** Has this message anything to show? Drives whether the strip renders at all. */
45
- export function hasTrace(message) {
46
- return (message.reasoning?.length ?? 0) > 0 || message.toolCalls.length > 0;
47
- }
48
- const statusWord = call => call.status === "ok" ? call.summary || "done" : call.status === "running" ? "running" : `${call.status}${call.summary ? ` — ${call.summary}` : ""}`;
49
-
50
- /**
51
- * The trace as plain text, for the clipboard.
52
- *
53
- * Indented under the answer it belongs to so a pasted session still reads as a
54
- * conversation rather than a log dump.
55
- */
56
- export function traceToText(message, indent = " ") {
57
- const lines = [];
58
- for (const entry of traceEntries(message)) {
59
- if (entry.kind === "thought") {
60
- lines.push(`${indent}[thinking]`);
61
- for (const line of entry.text.trim().split("\n")) {
62
- lines.push(`${indent} ${line}`);
63
- }
64
- } else {
65
- const {
66
- n,
67
- call
68
- } = entry;
69
- lines.push(`${indent}[${n}] ${call.toolId}.${call.action} — ${statusWord(call)}`);
70
- if (call.params) lines.push(`${indent} ${call.params}`);
71
- }
72
- }
73
- return lines;
74
- }
75
- //# sourceMappingURL=traceText.js.map
1
+ "use strict";export function traceEntries(t){const s=[...t.reasoning??[]].sort((t,s)=>t.afterCalls-s.afterCalls),n=[];let o=0;const r=t=>{for(;o<s.length&&s[o].afterCalls<=t;)n.push({kind:"thought",text:s[o].text}),o+=1};return t.toolCalls.forEach((t,s)=>{r(s),n.push({kind:"step",n:s+1,call:t})}),r(t.toolCalls.length),n}export function hasTrace(t){return(t.reasoning?.length??0)>0||t.toolCalls.length>0}const statusWord=t=>"ok"===t.status?t.summary||"done":"running"===t.status?"running":`${t.status}${t.summary?` — ${t.summary}`:""}`;export function traceToText(t,s=" "){const n=[];for(const o of traceEntries(t))if("thought"===o.kind){n.push(`${s}[thinking]`);for(const t of o.text.trim().split("\n"))n.push(`${s} ${t}`)}else{const{n:t,call:r}=o;n.push(`${s}[${t}] ${r.toolId}.${r.action} — ${statusWord(r)}`),r.params&&n.push(`${s} ${r.params}`)}return n}
@@ -1,111 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * The agent's working, as text.
5
- *
6
- * This exists so a tester can paste a run somewhere and find the step that
7
- * broke, which puts two properties on it: reasoning and steps come out in the
8
- * order they HAPPENED (a multi-step turn is think, act, think, act — not all
9
- * the thoughts and then all the steps), and a failed step says so with its
10
- * parameters attached, since "storage.set failed" without the value it wrote
11
- * is not a bug report.
12
- */
13
- import { describe, expect, it } from "vitest";
14
- import { hasTrace, traceEntries, traceToText } from "./traceText";
15
- const call = (over = {}) => ({
16
- id: "c1",
17
- toolId: "zustand",
18
- action: "getStoreState",
19
- label: "Read the bag",
20
- status: "ok",
21
- summary: "Done",
22
- ...over
23
- });
24
- const msg = (over = {}) => ({
25
- id: "m1",
26
- role: "assistant",
27
- text: "Five items.",
28
- toolCalls: [],
29
- blocks: [],
30
- ...over
31
- });
32
- describe("the order of a trace", () => {
33
- it("interleaves thinking with the steps it led to", () => {
34
- const m = msg({
35
- toolCalls: [call({
36
- id: "c1"
37
- }), call({
38
- id: "c2",
39
- action: "setState"
40
- })],
41
- reasoning: [{
42
- text: "I should read the bag first.",
43
- afterCalls: 0
44
- }, {
45
- text: "Now I can write the new quantity.",
46
- afterCalls: 1
47
- }]
48
- });
49
- expect(traceEntries(m).map(e => e.kind === "thought" ? "T" : `S${e.n}`)).toEqual(["T", "S1", "T", "S2"]);
50
- });
51
- it("keeps a closing thought after the last step", () => {
52
- // Usually the reasoning behind the ANSWER, which is the most useful line
53
- // in the whole trace.
54
- const m = msg({
55
- toolCalls: [call()],
56
- reasoning: [{
57
- text: "That is everything the user asked for.",
58
- afterCalls: 1
59
- }]
60
- });
61
- const entries = traceEntries(m);
62
- expect(entries[entries.length - 1]).toEqual({
63
- kind: "thought",
64
- text: "That is everything the user asked for."
65
- });
66
- });
67
- it("handles a turn with steps and no reasoning at all", () => {
68
- // The common case: gpt-4.1 and friends report none.
69
- const m = msg({
70
- toolCalls: [call()]
71
- });
72
- expect(traceEntries(m)).toHaveLength(1);
73
- expect(hasTrace(m)).toBe(true);
74
- });
75
- it("has nothing to show for a plain answer", () => {
76
- expect(hasTrace(msg())).toBe(false);
77
- });
78
- });
79
- describe("the text it produces", () => {
80
- it("names the tool, the action, the outcome and the parameters", () => {
81
- const m = msg({
82
- toolCalls: [call({
83
- params: '{"storeName":"Poké Mart bag"}'
84
- })]
85
- });
86
- expect(traceToText(m)).toEqual([" [1] zustand.getStoreState — Done", ' {"storeName":"Poké Mart bag"}']);
87
- });
88
- it("makes a failure and its parameters findable", () => {
89
- const m = msg({
90
- toolCalls: [call({
91
- toolId: "storage",
92
- action: "async.setItem",
93
- status: "failed",
94
- summary: "key not found",
95
- params: '{"key":"@pokemart/bag"}'
96
- })]
97
- });
98
- expect(traceToText(m).join("\n")).toContain("failed — key not found");
99
- expect(traceToText(m).join("\n")).toContain("@pokemart/bag");
100
- });
101
- it("indents a multi-line thought so a pasted session still reads as one", () => {
102
- const m = msg({
103
- reasoning: [{
104
- text: "First line.\nSecond line.",
105
- afterCalls: 0
106
- }]
107
- });
108
- expect(traceToText(m)).toEqual([" [thinking]", " First line.", " Second line."]);
109
- });
110
- });
111
- //# sourceMappingURL=traceText.test.js.map
1
+ "use strict";import{describe,expect,it}from"vitest";import{hasTrace,traceEntries,traceToText}from"./traceText";const call=(t={})=>({id:"c1",toolId:"zustand",action:"getStoreState",label:"Read the bag",status:"ok",summary:"Done",...t}),msg=(t={})=>({id:"m1",role:"assistant",text:"Five items.",toolCalls:[],blocks:[],...t});describe("the order of a trace",()=>{it("interleaves thinking with the steps it led to",()=>{const t=msg({toolCalls:[call({id:"c1"}),call({id:"c2",action:"setState"})],reasoning:[{text:"I should read the bag first.",afterCalls:0},{text:"Now I can write the new quantity.",afterCalls:1}]});expect(traceEntries(t).map(t=>"thought"===t.kind?"T":`S${t.n}`)).toEqual(["T","S1","T","S2"])}),it("keeps a closing thought after the last step",()=>{const t=msg({toolCalls:[call()],reasoning:[{text:"That is everything the user asked for.",afterCalls:1}]}),e=traceEntries(t);expect(e[e.length-1]).toEqual({kind:"thought",text:"That is everything the user asked for."})}),it("handles a turn with steps and no reasoning at all",()=>{const t=msg({toolCalls:[call()]});expect(traceEntries(t)).toHaveLength(1),expect(hasTrace(t)).toBe(!0)}),it("has nothing to show for a plain answer",()=>{expect(hasTrace(msg())).toBe(!1)})}),describe("the text it produces",()=>{it("names the tool, the action, the outcome and the parameters",()=>{const t=msg({toolCalls:[call({params:'{"storeName":"Poké Mart bag"}'})]});expect(traceToText(t)).toEqual([" [1] zustand.getStoreState — Done",' {"storeName":"Poké Mart bag"}'])}),it("makes a failure and its parameters findable",()=>{const t=msg({toolCalls:[call({toolId:"storage",action:"async.setItem",status:"failed",summary:"key not found",params:'{"key":"@pokemart/bag"}'})]});expect(traceToText(t).join("\n")).toContain("failed — key not found"),expect(traceToText(t).join("\n")).toContain("@pokemart/bag")}),it("indents a multi-line thought so a pasted session still reads as one",()=>{const t=msg({reasoning:[{text:"First line.\nSecond line.",afterCalls:0}]});expect(traceToText(t)).toEqual([" [thinking]"," First line."," Second line."])})});