@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,394 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Wire the sheet to the agent.
5
- *
6
- * Two things here are load-bearing:
7
- *
8
- * 1. DISPATCH GOES THROUGH `dispatchToolAction`, the same on-device seam a
9
- * Scenario step and a desktop click use. No second adapter map, nothing
10
- * that can drift from what the broker sees.
11
- * 2. THE SESSION IS REBUILT WHEN THE TOOL LIST CHANGES. The adapter map is a
12
- * memo whose contents depend on which packages resolved and whether a
13
- * QueryClientProvider is above FloatingDevTools — it is per-app and per
14
- * render, never a constant. A session that cached the tool list at open
15
- * would offer the model tools that are no longer there.
16
- */
17
- import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
18
- import { Platform } from "react-native";
19
- import { dispatchToolAction, listSnapshotToolIds, listToolActions, readToolSnapshot, waitForToolRegistry } from "@buoy-gg/shared-ui";
20
- import { answerToText, CATALOG, createAskBuoySession, runGatedAction, SNAPSHOT_ACTION } from "@buoy-gg/agent-core";
21
- import { askBuoyStore } from "./askBuoyStore";
22
- import { buildPayload, clearTranscript, readTranscript, writeTranscript } from "./transcriptPersistence";
23
- const isRelease = typeof __DEV__ !== "undefined" && !__DEV__;
24
-
25
- /** Long enough to coalesce a streaming answer's deltas, short enough to beat a crash. */
26
- const SAVE_DEBOUNCE_MS = 600;
27
- export function useAskBuoyState() {
28
- return useSyncExternalStore(askBuoyStore.subscribe, askBuoyStore.getState, askBuoyStore.getState);
29
- }
30
- export function useAskBuoy(config) {
31
- const state = useAskBuoyState();
32
- const sessionRef = useRef(null);
33
- /** One restore attempt per mount — see the note at the read. */
34
- const restoredRef = useRef(false);
35
- const abortRef = useRef(null);
36
- // Read through a ref where a stable callback needs the LATEST config (the
37
- // onEvent tap) without re-creating the callback per render.
38
- const configRef = useRef(config);
39
- configRef.current = config;
40
- const configured = !!config?.endpoint && !!config?.model;
41
- /**
42
- * On by default. The conversation surviving a reload is what makes the tool
43
- * usable while iterating, and it is the only thing that survives a crash —
44
- * but it puts the chat on disk, so a host handling regulated data can say no.
45
- */
46
- const persist = config?.persistTranscript !== false;
47
-
48
- // Recomputed each render: the set of dispatchable tools is not a constant.
49
- //
50
- // `getSnapshot` is folded in here because half of Buoy's read surface is not
51
- // an action at all — console entries, network events, routes and env live
52
- // only in the adapter's snapshot. Without this the model is offered a
53
- // console tool whose sole action wipes the logs, and no way to read them.
54
- const availableActions = useMemo(() => {
55
- try {
56
- const actions = listToolActions();
57
- for (const toolId of listSnapshotToolIds()) {
58
- if (!actions[toolId]) actions[toolId] = [];
59
- if (!actions[toolId].includes(SNAPSHOT_ACTION)) {
60
- actions[toolId] = [SNAPSHOT_ACTION, ...actions[toolId]];
61
- }
62
- }
63
- return actions;
64
- } catch {
65
- return {};
66
- }
67
- }, []);
68
- const toolKey = Object.keys(availableActions).sort().join(",");
69
- useEffect(() => {
70
- askBuoyStore.setConfigured(configured);
71
- // Stamped on the store so an exported run says what it ran against.
72
- askBuoyStore.setMeta({
73
- model: config?.model,
74
- protocol: config?.protocol ?? (config ? "anthropic" : undefined),
75
- appName: config?.appName,
76
- platform: Platform.OS,
77
- build: isRelease ? "release" : "development"
78
- });
79
- if (!configured || !config) {
80
- sessionRef.current = null;
81
- askBuoyStore.setNotice("Ask Buoy isn't set up in this app yet. A developer needs to point it at your team's AI endpoint.");
82
- return;
83
- }
84
- // The classic first-run mistake, caught statically: a provider's own URL
85
- // with the wrong protocol fails with a raw error that says nothing about
86
- // the one-line fix. ONLY the canonical provider hosts are checked — a
87
- // gateway may legitimately speak either protocol on any path (our own dev
88
- // gateway serves OpenAI framing on /v1/messages, and a path-based version
89
- // of this check flagged it on the first device run).
90
- const protocol = config.protocol ?? "anthropic";
91
- if (isRelease && config.apiKey) {
92
- askBuoyStore.setNotice("This build carries a plaintext apiKey — that's dev-only and it ships to every install. Use the headers callback with your own gateway for distributed builds.");
93
- } else if (protocol === "anthropic" && /^https?:\/\/api\.openai\.com\//i.test(config.endpoint)) {
94
- askBuoyStore.setNotice('This endpoint is api.openai.com but the protocol is "anthropic". Set protocol: "openai" in the askBuoy config.');
95
- } else if (protocol === "openai" && /^https?:\/\/api\.anthropic\.com\//i.test(config.endpoint)) {
96
- askBuoyStore.setNotice('This endpoint is api.anthropic.com but the protocol is "openai". Remove protocol or set it to "anthropic".');
97
- } else {
98
- askBuoyStore.setNotice(null);
99
- }
100
-
101
- // Reuse the held session while nothing material changed. The transcript
102
- // already survives close/reopen in the module store; without this the
103
- // session and ledger did not — reopening the sheet swapped in an empty
104
- // ledger (undo bar gone, agent changes still live in the app) and a blank
105
- // model memory behind a transcript that still showed the conversation.
106
- // The tool list is deliberately NOT part of this signature. Packages
107
- // register a frame or two apart, so `toolKey` legitimately changes right
108
- // after open — and keying on it silently rebuilt the session mid-chat,
109
- // throwing away the conversation, the model's memory and the undo ledger
110
- // while the transcript (a separate store) kept rendering as if nothing
111
- // happened. Verified on device: a destructive change went unrecorded
112
- // because it landed in a ledger that had just been replaced.
113
- const signature = [config.endpoint, config.protocol ?? "anthropic", config.model].join("|");
114
- const held = askBuoyStore.getHeldSession();
115
- if (held && held.signature === signature) {
116
- sessionRef.current = held.session;
117
- held.session.setAvailableActions(availableActions);
118
- askBuoyStore.setLedger(held.session.ledger);
119
- return;
120
- }
121
- const session = createAskBuoySession({
122
- endpoint: config.endpoint,
123
- protocol: config.protocol ?? "anthropic",
124
- model: config.model,
125
- headers: config.headers,
126
- apiKey: config.apiKey,
127
- maxTokens: config.maxTokens,
128
- anthropicVersion: config.anthropicVersion,
129
- requestOverrides: config.requestOverrides,
130
- // Host-declared custom tools join the built-in catalog. toProviderTools
131
- // still filters against the live registry, so a descriptor whose
132
- // `custom:<id>` adapter never registered is simply not offered.
133
- catalog: config.tools?.length ? [...CATALOG, ...config.tools] : undefined,
134
- dispatch: dispatchToolAction,
135
- readSnapshot: readToolSnapshot,
136
- availableActions,
137
- policy: config.policy,
138
- context: config.context,
139
- isRelease,
140
- appName: config.appName,
141
- platform: Platform.OS,
142
- requestApproval: input => askBuoyStore.askApproval(input)
143
- });
144
- sessionRef.current = session;
145
- askBuoyStore.holdSession(session, signature);
146
- askBuoyStore.setLedger(session.ledger);
147
-
148
- /**
149
- * Bring the last conversation back — both halves of it.
150
- *
151
- * The transcript and the model's memory are separate things (the store and
152
- * the session), and restoring only the first is worse than restoring
153
- * neither: the user reads a conversation the agent has no recollection of,
154
- * and "undo that" or "now do the same for Pikachu" lands on an empty
155
- * history. So the session is restored in the same pass, and only into a
156
- * session this effect just built.
157
- */
158
- // The registry publishes on mount, a frame or two after first paint. Warm
159
- // the grounding once it is there so the first question does not pay for it.
160
- let cancelled = false;
161
- void waitForToolRegistry().then(ready => {
162
- if (ready && !cancelled) void session.prime();
163
- });
164
-
165
- /**
166
- * NOT gated on `cancelled`, and once per mount.
167
- *
168
- * The disk read races the tool registry, and it was losing about half the
169
- * time. `availableActions` legitimately changes a frame or two after open
170
- * (see the note above) — that re-runs this effect, whose cleanup sets
171
- * `cancelled`, and the in-flight restore then threw its result away. The
172
- * second pass takes the held-session branch and returns early, so nothing
173
- * ever retried: the conversation was on disk, read correctly, and dropped
174
- * on the floor. Caught by the e2e, where one test restored and the next
175
- * did not, with no difference between them.
176
- *
177
- * Safe to leave running: `hydrate` refuses if anything has been said since,
178
- * and `restore` refuses a session that already has history. Resolved
179
- * against `sessionRef.current` rather than the captured `session` so a
180
- * genuine reconfiguration mid-read restores into the session in use.
181
- */
182
- if (persist && !restoredRef.current) {
183
- restoredRef.current = true;
184
- void readTranscript().then(saved => {
185
- if (!saved) return;
186
- const hydrated = askBuoyStore.hydrate({
187
- messages: saved.messages,
188
- answers: saved.answers,
189
- usage: saved.usage
190
- });
191
- if (hydrated) sessionRef.current?.restore(saved.history);
192
- });
193
- }
194
- return () => {
195
- cancelled = true;
196
- };
197
- }, [configured, config, availableActions, toolKey, persist]);
198
-
199
- /**
200
- * Save on change: coalesced while a turn streams, immediate the moment it ends.
201
- *
202
- * The debounce exists because a streaming answer changes the store on every
203
- * delta, and writing a whole transcript per token would cost more than the
204
- * turn does. But applying it to the END of a turn as well left a window
205
- * where the finished answer was on screen and not yet on disk — a crash or a
206
- * fast reload inside it lost the whole turn, which is precisely the case
207
- * this feature exists for. An e2e that relaunched as soon as the answer
208
- * rendered lost it every time, and that is a real user doing a fast reload,
209
- * not a harness artefact.
210
- *
211
- * Saving still happens DURING a turn as well, which is what lets a bubble
212
- * the app died in come back marked interrupted rather than blank.
213
- */
214
- const messages = state.messages;
215
- const answers = state.answers;
216
- const usage = state.usage;
217
- const busy = state.busy;
218
- useEffect(() => {
219
- if (!persist) return;
220
- if (messages.length === 0) return;
221
- const write = () => {
222
- void writeTranscript(buildPayload({
223
- messages,
224
- history: sessionRef.current?.messages ?? [],
225
- answers,
226
- usage
227
- }));
228
- };
229
- if (!busy) {
230
- write();
231
- return;
232
- }
233
- const timer = setTimeout(write, SAVE_DEBOUNCE_MS);
234
- return () => clearTimeout(timer);
235
- }, [persist, busy, messages, answers, usage]);
236
-
237
- /** Stream one turn into a fresh assistant bubble. Callers set up the user side. */
238
- const runTurn = useCallback(text => {
239
- const session = sessionRef.current;
240
- if (!session) return;
241
- askBuoyStore.beginTurn();
242
- const messageId = askBuoyStore.startAssistant();
243
- const controller = new AbortController();
244
- abortRef.current = controller;
245
- const onEvent = configRef.current?.onEvent;
246
- void (async () => {
247
- try {
248
- for await (const ev of session.send(text, controller.signal)) {
249
- askBuoyStore.applyEvent(messageId, ev);
250
- if (onEvent) {
251
- try {
252
- onEvent(ev);
253
- } catch {
254
- // The audit tap must never take the chat down.
255
- }
256
- }
257
- }
258
- } catch (err) {
259
- askBuoyStore.applyEvent(messageId, {
260
- type: "error",
261
- message: err instanceof Error ? err.message : "Something went wrong talking to your AI endpoint."
262
- });
263
- } finally {
264
- askBuoyStore.finishAssistant(messageId);
265
- abortRef.current = null;
266
- }
267
- })();
268
- }, []);
269
- const send = useCallback(text => {
270
- const trimmed = text.trim();
271
- if (!sessionRef.current || !trimmed) return;
272
-
273
- // Typed mid-turn: park it. The composer already cleared the field, and
274
- // silently dropping the words was the worst of all outcomes.
275
- if (askBuoyStore.getState().busy) {
276
- askBuoyStore.setQueued(trimmed);
277
- return;
278
- }
279
-
280
- // Typing past an Ask block IS an answer: the block is skipped and locks.
281
- // Without this the composer stayed on "Pick an option above…" forever and
282
- // a stale choice sat tappable in the history.
283
- const awaiting = askBuoyStore.getState().awaitingBlockId;
284
- if (awaiting) askBuoyStore.recordAnswer({
285
- blockId: awaiting,
286
- kind: "skipped"
287
- });
288
- askBuoyStore.addUser(trimmed);
289
- runTurn(trimmed);
290
- }, [runTurn]);
291
- const retry = useCallback(() => {
292
- const {
293
- messages,
294
- busy
295
- } = askBuoyStore.getState();
296
- if (busy || !sessionRef.current) return;
297
- const lastUser = [...messages].reverse().find(m => m.role === "user");
298
- if (!lastUser) return;
299
- // Replace the failed bubble rather than stacking a second one under it.
300
- const last = messages[messages.length - 1];
301
- if (last && last.role === "assistant" && last.error) askBuoyStore.removeMessage(last.id);
302
- runTurn(lastUser.text);
303
- }, [runTurn]);
304
- const stop = useCallback(() => {
305
- // A pending approval parks an unresolved promise inside the engine; the
306
- // abort signal is only read between steps, so Stop must also answer the
307
- // approval (as declined) or the generator hangs forever.
308
- if (askBuoyStore.getState().pending) askBuoyStore.answerApproval(false);
309
- abortRef.current?.abort();
310
- abortRef.current = null;
311
- }, []);
312
-
313
- // Flush the parked message the moment the turn ends.
314
- const queued = state.queued;
315
- useEffect(() => {
316
- if (!state.busy && queued) {
317
- askBuoyStore.setQueued(null);
318
- send(queued);
319
- }
320
- }, [state.busy, queued, send]);
321
- const reset = useCallback(() => {
322
- abortRef.current?.abort();
323
- sessionRef.current?.reset();
324
- askBuoyStore.reset();
325
- // "New conversation" means gone, not hidden. Leaving the last chat on disk
326
- // after the user asked for a clean one is the opposite of what they said.
327
- void clearTranscript();
328
- }, []);
329
- const approve = useCallback(approved => {
330
- askBuoyStore.answerApproval(approved);
331
- }, []);
332
- const answer = useCallback(a => {
333
- askBuoyStore.recordAnswer(a);
334
- // Plain words to the model, never JSON: "Business checkout", "Yes, go ahead."
335
- send(answerToText(a));
336
- }, [send]);
337
-
338
- /**
339
- * Block buttons. `send` is a chat reply; `dispatch` runs the action through
340
- * `runGatedAction` — the SAME validation, policy and ledger path a model
341
- * call takes, minus the model. The first version called `dispatchToolAction`
342
- * raw, which made a model-authored button an invisible, ungoverned,
343
- * unundoable mutation while the `buoy_ui` schema promised the opposite.
344
- * The human's tap satisfies `requireApproval`; deny lists, read-only mode
345
- * and release refusals still stand. Button state is tracked so a tap shows
346
- * running → done and can't double-fire.
347
- * (`minimize` / `openTool` are the sheet's to handle; see AskBuoyModal.)
348
- */
349
- const runAction = useCallback(async (action, blockId) => {
350
- if (action.send) {
351
- send(action.send);
352
- return;
353
- }
354
- if (!action.dispatch) return;
355
- const key = `${blockId}:${action.label}`;
356
- const ledger = askBuoyStore.getLedger();
357
- if (!ledger) {
358
- askBuoyStore.setNotice(`${action.label} failed — no active Ask Buoy session.`);
359
- return;
360
- }
361
- askBuoyStore.setActionState(key, "running");
362
- const outcome = await runGatedAction({
363
- toolId: action.dispatch.toolId,
364
- action: action.dispatch.action,
365
- params: action.dispatch.params ?? {},
366
- dispatch: dispatchToolAction,
367
- ledger,
368
- policy: config?.policy ?? {},
369
- isRelease,
370
- // Same merged catalog the session offers, so a button on a custom
371
- // tool's block is not refused as unknown.
372
- catalog: config?.tools?.length ? [...CATALOG, ...config.tools] : undefined
373
- });
374
- if (outcome.ok) {
375
- askBuoyStore.setActionState(key, "done");
376
- } else {
377
- askBuoyStore.setActionState(key, "failed");
378
- askBuoyStore.setNotice(`${action.label} failed — ${outcome.error}`);
379
- }
380
- }, [send, config]);
381
- return {
382
- state,
383
- send,
384
- stop,
385
- reset,
386
- approve,
387
- retry,
388
- answer,
389
- runAction,
390
- configured,
391
- toolCount: Object.keys(availableActions).length
392
- };
393
- }
394
- //# sourceMappingURL=useAskBuoy.js.map
1
+ "use strict";import{getUseIsPro,hasAccountAccess,subscribeAccountAccess}from"@buoy-gg/shared-ui";import{useCallback,useEffect,useMemo,useRef,useState,useSyncExternalStore}from"react";import{Platform}from"react-native";import{dispatchToolAction,listSnapshotToolIds,listToolActions,readToolSnapshot,waitForToolRegistry}from"@buoy-gg/shared-ui";import{answerToText,CATALOG,createAskBuoySession,readTargetDigest,runGatedAction,SNAPSHOT_ACTION}from"@buoy-gg/agent-core";import{askBuoyStore,queuePauseReason,turnPhaseOf}from"./askBuoyStore";import{clearConversation,resetConversation}from"./resetConversation";import{buildPayload,readTranscript,writeTranscript}from"./transcriptPersistence";import{useAskBuoySettings}from"./useAskBuoySettings";const isRelease="undefined"!=typeof __DEV__&&!__DEV__;function questionBehind(e){for(const t of askBuoyStore.getState().messages)if(t.restored)for(const o of t.blocks){const t=o.block;if(t?.id!==e)continue;const s=t.question??t.label??t.title;return"string"==typeof s&&s.trim()?s.trim():void 0}}function readAvailableActions(){try{const e=listToolActions();for(const t of listSnapshotToolIds())e[t]||(e[t]=[]),e[t].includes(SNAPSHOT_ACTION)||(e[t]=[SNAPSHOT_ACTION,...e[t]]);return e}catch{return{}}}const SAVE_DEBOUNCE_MS=600;export function useAskBuoyState(){return useSyncExternalStore(askBuoyStore.subscribe,askBuoyStore.getState,askBuoyStore.getState)}export function useAskBuoy(e){const t=useAskBuoyState(),o=getUseIsPro()(),s=useRef(o);s.current=o;const r=useCallback((...e)=>hasAccountAccess()&&s.current?dispatchToolAction(...e):Promise.reject(new Error("Ask Buoy requires Pro access.")),[]),a=useRef(null),n=useRef(!1),i=useRef(null),u=useRef(e);u.current=e;const c=!!e?.endpoint&&!!e?.model,l=!1!==e?.persistTranscript,{bypassApprovals:d,readOnly:p}=useAskBuoySettings(),y=useRef(d);y.current=d;const k=useRef(p);k.current=p;const g=useCallback(()=>k.current?{...e?.policy??{},readOnly:!0}:e?.policy??{},[e]),[S,f]=useState(0);useEffect(()=>{let e=!1;return waitForToolRegistry().then(()=>{e||f(e=>e+1)}),()=>{e=!0}},[]);const h=useMemo(()=>readAvailableActions(),[S]),A=Object.keys(h).sort().join(",");useEffect(()=>{if(askBuoyStore.setConfigured(c),askBuoyStore.setMeta({model:e?.model,protocol:e?.protocol??(e?"anthropic":void 0),appName:e?.appName,platform:Platform.OS,build:isRelease?"release":"development"}),!c||!e)return a.current=null,void askBuoyStore.setNotice("Ask Buoy isn't set up in this app yet. A developer needs to point it at your team's AI endpoint.");const t=e.protocol??"anthropic";isRelease&&e.apiKey?askBuoyStore.setNotice("This build carries a plaintext apiKey — that's dev-only and it ships to every install. Use the headers callback with your own gateway for distributed builds."):"anthropic"===t&&/^https?:\/\/api\.openai\.com\//i.test(e.endpoint)?askBuoyStore.setNotice('This endpoint is api.openai.com but the protocol is "anthropic". Set protocol: "openai" in the askBuoy config.'):"openai"===t&&/^https?:\/\/api\.anthropic\.com\//i.test(e.endpoint)?askBuoyStore.setNotice('This endpoint is api.anthropic.com but the protocol is "openai". Remove protocol or set it to "anthropic".'):askBuoyStore.setNotice(null);const o=[e.endpoint,e.protocol??"anthropic",e.model].join("|"),s=askBuoyStore.getHeldSession();if(s&&s.signature===o)return a.current=s.session,s.session.setAvailableActions(h),s.session.setApprovalBypass(y.current),s.session.setReadOnly(k.current),void askBuoyStore.setLedger(s.session.ledger);const i=createAskBuoySession({endpoint:e.endpoint,protocol:e.protocol??"anthropic",model:e.model,headers:e.headers,apiKey:e.apiKey,maxTokens:e.maxTokens,anthropicVersion:e.anthropicVersion,requestOverrides:e.requestOverrides,catalog:e.tools?.length?[...CATALOG,...e.tools]:void 0,dispatch:r,readSnapshot:readToolSnapshot,availableActions:h,policy:e.policy,context:e.context,isRelease:isRelease,appName:e.appName,platform:Platform.OS,requestApproval:e=>askBuoyStore.askApproval(e)});a.current=i,i.setApprovalBypass(y.current),i.setReadOnly(k.current),askBuoyStore.holdSession(i,o),askBuoyStore.setLedger(i.ledger);let u=!1;return waitForToolRegistry().then(e=>{e&&!u&&i.prime()}),l&&!n.current&&(n.current=!0,readTranscript().then(e=>{e&&askBuoyStore.hydrate({messages:e.messages,answers:e.answers,usage:e.usage,queued:e.queued})&&(a.current?.restore(e.history),e.ledger?.length&&a.current?.ledger.restore(e.ledger),e.pending&&askBuoyStore.restorePending(e.pending))})),()=>{u=!0}},[c,e,h,A,l]),useEffect(()=>{a.current?.setApprovalBypass(d)},[d]),useEffect(()=>{a.current?.setReadOnly(p)},[p]);const B=t.messages,m=t.answers,b=t.usage,v=t.busy,T=t.pending,w=t.queued;useEffect(()=>{if(!l)return;if(0===B.length)return;const e=()=>{writeTranscript(buildPayload({messages:B,history:a.current?.messages??[],answers:m,usage:b,pending:T,ledger:askBuoyStore.getLedger()?.list(),queued:w}))};if(!v)return void e();const t=setTimeout(e,600);return()=>clearTimeout(t)},[l,v,B,m,b,T,w]);const C=useCallback(e=>{if(!hasAccountAccess()||!s.current)return;const t=a.current;if(!t)return;askBuoyStore.beginTurn();const o=askBuoyStore.startAssistant(),r=new AbortController;i.current=r,t.setAvailableActions(readAvailableActions());const n=u.current?.onEvent;(async()=>{try{for await(const s of t.send(e,r.signal))if(askBuoyStore.applyEvent(o,s),n)try{n(s)}catch{}}catch(e){r.signal.aborted||askBuoyStore.applyEvent(o,{type:"error",message:e instanceof Error?e.message:"Something went wrong talking to your AI endpoint."})}finally{r.signal.aborted&&askBuoyStore.markStopped(o),askBuoyStore.finishAssistant(o),i.current=null}})()},[]),R=useCallback(e=>{if(!hasAccountAccess()||!s.current)return;const t=e.trim();if(!a.current||!t)return;if(askBuoyStore.getState().busy)return void askBuoyStore.enqueue(t);const o=askBuoyStore.getState().awaitingBlockId;o&&askBuoyStore.recordAnswer({blockId:o,kind:"skipped"}),askBuoyStore.addUser(t),C(t)},[C]),N=useCallback(()=>{const{messages:e,busy:t}=askBuoyStore.getState();if(t||!a.current)return;const o=[...e].reverse().find(e=>"user"===e.role);o&&C(o.text)},[C]),O=useCallback(()=>{askBuoyStore.requestStop(),askBuoyStore.getState().pending&&askBuoyStore.answerApproval(!1),i.current?.abort(),i.current=null},[]);useEffect(()=>{const e=subscribeAccountAccess(()=>{hasAccountAccess()||O()});return()=>{e(),O()}},[O]),useEffect(()=>{o||O()},[o,O]),useEffect(()=>{if(0===t.queued.length)return;if("idle"!==turnPhaseOf(t))return;if(null!==queuePauseReason(t))return;const e=askBuoyStore.shiftQueued();e&&R(e.text)},[t,R]);const E=useCallback(e=>askBuoyStore.takeQueuedToDraft(e),[]),I=useCallback(e=>askBuoyStore.removeQueued(e),[]),P=useCallback(()=>{i.current?.abort(),i.current=null,clearConversation()},[]),q=useCallback(()=>resetConversation({dispatch:dispatchToolAction,undoFirst:!0}),[]),x=useCallback(async t=>{const o=askBuoyStore.getLedger();if(!o)return void askBuoyStore.setNotice(`${t.label} couldn't run — no active Ask Buoy session.`);const s=e?.tools?.length?[...CATALOG,...e.tools]:void 0;if(t.targetDigest){const e=await readTargetDigest({toolId:t.toolId,action:t.action,params:t.params??{},dispatch:r,catalog:s});if(void 0!==e&&e!==t.targetDigest)return void askBuoyStore.addNote(`“${t.label}” wasn't applied — what it would change has moved on since the app restarted. Nothing was written. Ask again if you still want it.`)}const a=await runGatedAction({toolId:t.toolId,action:t.action,params:t.params??{},dispatch:r,ledger:o,policy:g(),isRelease:isRelease,catalog:s});a.ok?askBuoyStore.addNote(`Applied “${t.label}”, which was still waiting when the app restarted. Whatever else that answer was going to do is gone — ask again if there was more to it.`):askBuoyStore.setNotice(`${t.label} failed — ${a.error}`)},[e,g]),$=useCallback(e=>{const t=askBuoyStore.getState().pending,o="boolean"==typeof e?e:e.approved;askBuoyStore.answerApproval(e),t?.restored&&(o?x(t):askBuoyStore.addNote(`Skipped “${t.label}”. Nothing was changed.`))},[x]),_=useCallback(e=>{askBuoyStore.recordAnswer(e);const t=questionBehind(e.blockId);R(t?`${t} — ${answerToText(e)}`:answerToText(e))},[R]),L=useCallback(async(t,o)=>{if(!hasAccountAccess()||!s.current)return void askBuoyStore.setNotice("Ask Buoy requires Pro access.");if(t.send)return void R(t.send);if(!t.dispatch)return;const a=`${o}:${t.label}`,n=askBuoyStore.getLedger();if(!n)return void askBuoyStore.setNotice(`${t.label} failed — no active Ask Buoy session.`);askBuoyStore.setActionState(a,"running");const i=await runGatedAction({toolId:t.dispatch.toolId,action:t.dispatch.action,params:t.dispatch.params??{},dispatch:r,ledger:n,policy:g(),isRelease:isRelease,catalog:e?.tools?.length?[...CATALOG,...e.tools]:void 0});i.ok?askBuoyStore.setActionState(a,"done"):(askBuoyStore.setActionState(a,"failed"),askBuoyStore.setNotice(`${t.label} failed — ${i.error}`))},[R,e,g]);return{state:t,send:R,stop:O,reset:P,undoThenReset:q,approve:$,retry:N,answer:_,runAction:L,editQueued:E,removeQueued:I,configured:c,toolCount:Object.keys(h).length,availableToolIds:Object.keys(h)}}
@@ -1,9 +1 @@
1
- "use strict";
2
-
3
- /** Subscribe the sheet to Ask Buoy's own preferences. */
4
- import { useSyncExternalStore } from "react";
5
- import { askBuoySettings } from "./askBuoySettings";
6
- export function useAskBuoySettings() {
7
- return useSyncExternalStore(askBuoySettings.subscribe, askBuoySettings.get, askBuoySettings.get);
8
- }
9
- //# sourceMappingURL=useAskBuoySettings.js.map
1
+ "use strict";import{useSyncExternalStore}from"react";import{askBuoySettings}from"./askBuoySettings";export function useAskBuoySettings(){return useSyncExternalStore(askBuoySettings.subscribe,askBuoySettings.get,askBuoySettings.get)}
@@ -1,114 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * The sync adapter, so Buoy Desktop and MCP can see what Ask Buoy is doing.
5
- *
6
- * Read-heavy on purpose. There is no `send` action: letting a remote client
7
- * put words in the agent's mouth would mean anyone who can reach the broker —
8
- * which has no authentication at all, binds 0.0.0.0, and accepts any client
9
- * calling itself "Dashboard" — could drive a mutating agent on a tester's
10
- * device. The chat is initiated on-device, by a person, full stop.
11
- *
12
- * `undoAll` IS exposed, because the asymmetry is deliberate: putting things
13
- * back is the safe direction, and a dev watching from the desktop should be
14
- * able to clean up a device without walking over to it.
15
- *
16
- * The transcript is redacted before it crosses the wire. Action results the
17
- * agent read can contain storage values and response bodies, and this socket
18
- * broadcasts to every connected dashboard — it already leaks license keys the
19
- * same way.
20
- */
21
- import { dispatchToolAction, redactForWire } from "./wire";
22
- import { isReversible } from "@buoy-gg/agent-core";
23
- import { askBuoyStore } from "../store/askBuoyStore";
24
- export const ASK_BUOY_ADAPTER_VERSION = 1;
25
- export const askBuoySyncAdapter = {
26
- version: ASK_BUOY_ADAPTER_VERSION,
27
- getSnapshot() {
28
- const state = askBuoyStore.getState();
29
- const ledger = askBuoyStore.getLedger();
30
- const entries = ledger?.list() ?? [];
31
- const outstanding = entries.filter(e => !e.undoneAt);
32
- return {
33
- version: ASK_BUOY_ADAPTER_VERSION,
34
- busy: state.busy,
35
- configured: state.configured,
36
- notice: state.notice,
37
- messageCount: state.messages.length,
38
- // Only the shape of the conversation, never tool payloads.
39
- messages: state.messages.map(m => ({
40
- id: m.id,
41
- role: m.role,
42
- text: redactForWire(m.text),
43
- streaming: !!m.streaming,
44
- toolCalls: m.toolCalls.map(c => ({
45
- toolId: c.toolId,
46
- action: c.action,
47
- status: c.status
48
- }))
49
- })),
50
- // Session token totals, so a desktop/MCP observer can meter cost.
51
- usage: state.usage,
52
- pendingApproval: state.pending ? {
53
- toolId: state.pending.toolId,
54
- action: state.pending.action,
55
- label: state.pending.label
56
- } : null,
57
- changes: {
58
- // Transients (navigation, taps) are one-shot actions, not changes —
59
- // same rule as the on-device bar, so desktop and device tell one story.
60
- reversible: outstanding.filter(e => isReversible(e.effect)).length,
61
- permanent: outstanding.filter(e => e.effect.kind !== "transient" && !isReversible(e.effect)).length,
62
- transients: outstanding.filter(e => e.effect.kind === "transient").length,
63
- items: outstanding.map(e => ({
64
- kind: e.effect.kind,
65
- label: e.effect.label
66
- }))
67
- }
68
- };
69
- },
70
- subscribe(onChange) {
71
- const offStore = askBuoyStore.subscribe(onChange);
72
- const offLedger = askBuoyStore.getLedger()?.subscribe(onChange);
73
- return () => {
74
- offStore();
75
- offLedger?.();
76
- };
77
- },
78
- actions: {
79
- /** What the agent changed, and whether it can be put back. */
80
- listChanges: () => {
81
- const entries = askBuoyStore.getLedger()?.list() ?? [];
82
- return entries.filter(e => !e.undoneAt).map(e => ({
83
- id: e.id,
84
- at: e.at,
85
- toolId: e.toolId,
86
- action: e.action,
87
- kind: e.effect.kind,
88
- label: e.effect.label,
89
- reversible: isReversible(e.effect)
90
- }));
91
- },
92
- /** Put back everything that can be put back. Safe direction only. */
93
- undoAll: async () => {
94
- const ledger = askBuoyStore.getLedger();
95
- if (!ledger) return {
96
- ok: false,
97
- error: "No Ask Buoy session on this device."
98
- };
99
- const outcome = await ledger.revertAll(dispatchToolAction);
100
- return {
101
- ok: true,
102
- ...outcome
103
- };
104
- },
105
- /** Clear the transcript and the ledger. Does not undo anything. */
106
- reset: () => {
107
- askBuoyStore.reset();
108
- return {
109
- ok: true
110
- };
111
- }
112
- }
113
- };
114
- //# sourceMappingURL=askBuoySyncAdapter.js.map
1
+ "use strict";import{resetConversation}from"../store/resetConversation";import{dispatchToolAction,redactForWire}from"./wire";import{isReversible}from"@buoy-gg/agent-core";import{askBuoyStore}from"../store/askBuoyStore";export const ASK_BUOY_ADAPTER_VERSION=1;export const askBuoySyncAdapter={version:1,async dispose(e){const t=askBuoyStore.getLedger();for(const o of t?.list()??[])o.undoneAt||"network-override"===o.effect.kind&&await e("network","deleteOverrideRule",{id:o.effect.ruleId})},getSnapshot(){const e=askBuoyStore.getState(),t=askBuoyStore.getLedger(),o=(t?.list()??[]).filter(e=>!e.undoneAt);return{version:1,busy:e.busy,configured:e.configured,notice:e.notice,messageCount:e.messages.length,messages:e.messages.map(e=>({id:e.id,role:e.role,text:redactForWire(e.text),streaming:!!e.streaming,toolCalls:e.toolCalls.map(e=>({toolId:e.toolId,action:e.action,status:e.status}))})),usage:e.usage,pendingApproval:e.pending?{toolId:e.pending.toolId,action:e.pending.action,label:e.pending.label}:null,changes:{reversible:o.filter(e=>isReversible(e.effect)).length,permanent:o.filter(e=>"transient"!==e.effect.kind&&!isReversible(e.effect)).length,transients:o.filter(e=>"transient"===e.effect.kind).length,items:o.map(e=>({kind:e.effect.kind,label:e.effect.label}))}}},subscribe(e){const t=askBuoyStore.subscribe(e),o=askBuoyStore.getLedger()?.subscribe(e);return()=>{t(),o?.()}},actions:{listChanges:()=>(askBuoyStore.getLedger()?.list()??[]).filter(e=>!e.undoneAt).map(e=>({id:e.id,at:e.at,toolId:e.toolId,action:e.action,kind:e.effect.kind,label:e.effect.label,reversible:isReversible(e.effect)})),undoAll:async()=>{const e=askBuoyStore.getLedger();return e?{ok:!0,...await e.revertAll(dispatchToolAction)}:{ok:!1,error:"No Ask Buoy session on this device."}},reset:async()=>{const e=await resetConversation({dispatch:dispatchToolAction,undoFirst:!0});return e.cleared?{ok:!0,reverted:e.reverted}:{ok:!1,error:`Couldn't undo ${e.failed.length} change${1===e.failed.length?"":"s"} — conversation kept.`,failed:e.failed}}}};