@buoy-gg/ask-buoy 7.0.33

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 (184) hide show
  1. package/LICENSE +58 -0
  2. package/README.md +50 -0
  3. package/lib/commonjs/blocks/AskBlocks.js +338 -0
  4. package/lib/commonjs/blocks/AskBlocks.js.map +1 -0
  5. package/lib/commonjs/blocks/BlockRenderer.js +250 -0
  6. package/lib/commonjs/blocks/BlockRenderer.js.map +1 -0
  7. package/lib/commonjs/blocks/ChromePrototypes.js +514 -0
  8. package/lib/commonjs/blocks/ChromePrototypes.js.map +1 -0
  9. package/lib/commonjs/blocks/DataBlocks.js +545 -0
  10. package/lib/commonjs/blocks/DataBlocks.js.map +1 -0
  11. package/lib/commonjs/blocks/ExtraBlocks.js +1821 -0
  12. package/lib/commonjs/blocks/ExtraBlocks.js.map +1 -0
  13. package/lib/commonjs/blocks/MediaBlocks.js +140 -0
  14. package/lib/commonjs/blocks/MediaBlocks.js.map +1 -0
  15. package/lib/commonjs/blocks/ReceiptBlocks.js +596 -0
  16. package/lib/commonjs/blocks/ReceiptBlocks.js.map +1 -0
  17. package/lib/commonjs/blocks/context.js +42 -0
  18. package/lib/commonjs/blocks/context.js.map +1 -0
  19. package/lib/commonjs/blocks/icons.js +96 -0
  20. package/lib/commonjs/blocks/icons.js.map +1 -0
  21. package/lib/commonjs/blocks/index.js +95 -0
  22. package/lib/commonjs/blocks/index.js.map +1 -0
  23. package/lib/commonjs/blocks/primitives.js +312 -0
  24. package/lib/commonjs/blocks/primitives.js.map +1 -0
  25. package/lib/commonjs/blocks/primitivesIndex.js +56 -0
  26. package/lib/commonjs/blocks/primitivesIndex.js.map +1 -0
  27. package/lib/commonjs/components/ApprovalCard.js +140 -0
  28. package/lib/commonjs/components/ApprovalCard.js.map +1 -0
  29. package/lib/commonjs/components/AskBuoyHeader.js +127 -0
  30. package/lib/commonjs/components/AskBuoyHeader.js.map +1 -0
  31. package/lib/commonjs/components/AskBuoyIcon.js +19 -0
  32. package/lib/commonjs/components/AskBuoyIcon.js.map +1 -0
  33. package/lib/commonjs/components/AskBuoyModal.js +322 -0
  34. package/lib/commonjs/components/AskBuoyModal.js.map +1 -0
  35. package/lib/commonjs/components/ChangesBar.js +211 -0
  36. package/lib/commonjs/components/ChangesBar.js.map +1 -0
  37. package/lib/commonjs/components/Composer.js +175 -0
  38. package/lib/commonjs/components/Composer.js.map +1 -0
  39. package/lib/commonjs/components/EmptyState.js +154 -0
  40. package/lib/commonjs/components/EmptyState.js.map +1 -0
  41. package/lib/commonjs/components/Markdown.js +252 -0
  42. package/lib/commonjs/components/Markdown.js.map +1 -0
  43. package/lib/commonjs/components/MessageList.js +648 -0
  44. package/lib/commonjs/components/MessageList.js.map +1 -0
  45. package/lib/commonjs/components/TypingDots.js +63 -0
  46. package/lib/commonjs/components/TypingDots.js.map +1 -0
  47. package/lib/commonjs/index.js +205 -0
  48. package/lib/commonjs/index.js.map +1 -0
  49. package/lib/commonjs/package.json +1 -0
  50. package/lib/commonjs/preset.js +90 -0
  51. package/lib/commonjs/preset.js.map +1 -0
  52. package/lib/commonjs/store/askBuoyStore.js +279 -0
  53. package/lib/commonjs/store/askBuoyStore.js.map +1 -0
  54. package/lib/commonjs/store/useAskBuoy.js +299 -0
  55. package/lib/commonjs/store/useAskBuoy.js.map +1 -0
  56. package/lib/commonjs/sync/askBuoySyncAdapter.js +119 -0
  57. package/lib/commonjs/sync/askBuoySyncAdapter.js.map +1 -0
  58. package/lib/commonjs/sync/askBuoySyncAdapter.test.js +136 -0
  59. package/lib/commonjs/sync/askBuoySyncAdapter.test.js.map +1 -0
  60. package/lib/commonjs/sync/wire.js +58 -0
  61. package/lib/commonjs/sync/wire.js.map +1 -0
  62. package/lib/commonjs/types.js +6 -0
  63. package/lib/commonjs/types.js.map +1 -0
  64. package/lib/module/blocks/AskBlocks.js +331 -0
  65. package/lib/module/blocks/AskBlocks.js.map +1 -0
  66. package/lib/module/blocks/BlockRenderer.js +245 -0
  67. package/lib/module/blocks/BlockRenderer.js.map +1 -0
  68. package/lib/module/blocks/ChromePrototypes.js +503 -0
  69. package/lib/module/blocks/ChromePrototypes.js.map +1 -0
  70. package/lib/module/blocks/DataBlocks.js +532 -0
  71. package/lib/module/blocks/DataBlocks.js.map +1 -0
  72. package/lib/module/blocks/ExtraBlocks.js +1794 -0
  73. package/lib/module/blocks/ExtraBlocks.js.map +1 -0
  74. package/lib/module/blocks/MediaBlocks.js +135 -0
  75. package/lib/module/blocks/MediaBlocks.js.map +1 -0
  76. package/lib/module/blocks/ReceiptBlocks.js +584 -0
  77. package/lib/module/blocks/ReceiptBlocks.js.map +1 -0
  78. package/lib/module/blocks/context.js +35 -0
  79. package/lib/module/blocks/context.js.map +1 -0
  80. package/lib/module/blocks/icons.js +91 -0
  81. package/lib/module/blocks/icons.js.map +1 -0
  82. package/lib/module/blocks/index.js +8 -0
  83. package/lib/module/blocks/index.js.map +1 -0
  84. package/lib/module/blocks/primitives.js +301 -0
  85. package/lib/module/blocks/primitives.js.map +1 -0
  86. package/lib/module/blocks/primitivesIndex.js +5 -0
  87. package/lib/module/blocks/primitivesIndex.js.map +1 -0
  88. package/lib/module/components/ApprovalCard.js +135 -0
  89. package/lib/module/components/ApprovalCard.js.map +1 -0
  90. package/lib/module/components/AskBuoyHeader.js +124 -0
  91. package/lib/module/components/AskBuoyHeader.js.map +1 -0
  92. package/lib/module/components/AskBuoyIcon.js +8 -0
  93. package/lib/module/components/AskBuoyIcon.js.map +1 -0
  94. package/lib/module/components/AskBuoyModal.js +317 -0
  95. package/lib/module/components/AskBuoyModal.js.map +1 -0
  96. package/lib/module/components/ChangesBar.js +206 -0
  97. package/lib/module/components/ChangesBar.js.map +1 -0
  98. package/lib/module/components/Composer.js +170 -0
  99. package/lib/module/components/Composer.js.map +1 -0
  100. package/lib/module/components/EmptyState.js +149 -0
  101. package/lib/module/components/EmptyState.js.map +1 -0
  102. package/lib/module/components/Markdown.js +246 -0
  103. package/lib/module/components/Markdown.js.map +1 -0
  104. package/lib/module/components/MessageList.js +642 -0
  105. package/lib/module/components/MessageList.js.map +1 -0
  106. package/lib/module/components/TypingDots.js +58 -0
  107. package/lib/module/components/TypingDots.js.map +1 -0
  108. package/lib/module/index.js +29 -0
  109. package/lib/module/index.js.map +1 -0
  110. package/lib/module/preset.js +73 -0
  111. package/lib/module/preset.js.map +1 -0
  112. package/lib/module/store/askBuoyStore.js +275 -0
  113. package/lib/module/store/askBuoyStore.js.map +1 -0
  114. package/lib/module/store/useAskBuoy.js +293 -0
  115. package/lib/module/store/useAskBuoy.js.map +1 -0
  116. package/lib/module/sync/askBuoySyncAdapter.js +114 -0
  117. package/lib/module/sync/askBuoySyncAdapter.js.map +1 -0
  118. package/lib/module/sync/askBuoySyncAdapter.test.js +135 -0
  119. package/lib/module/sync/askBuoySyncAdapter.test.js.map +1 -0
  120. package/lib/module/sync/wire.js +47 -0
  121. package/lib/module/sync/wire.js.map +1 -0
  122. package/lib/module/types.js +4 -0
  123. package/lib/module/types.js.map +1 -0
  124. package/lib/typescript/blocks/AskBlocks.d.ts +11 -0
  125. package/lib/typescript/blocks/AskBlocks.d.ts.map +1 -0
  126. package/lib/typescript/blocks/BlockRenderer.d.ts +5 -0
  127. package/lib/typescript/blocks/BlockRenderer.d.ts.map +1 -0
  128. package/lib/typescript/blocks/ChromePrototypes.d.ts +27 -0
  129. package/lib/typescript/blocks/ChromePrototypes.d.ts.map +1 -0
  130. package/lib/typescript/blocks/DataBlocks.d.ts +29 -0
  131. package/lib/typescript/blocks/DataBlocks.d.ts.map +1 -0
  132. package/lib/typescript/blocks/ExtraBlocks.d.ts +69 -0
  133. package/lib/typescript/blocks/ExtraBlocks.d.ts.map +1 -0
  134. package/lib/typescript/blocks/MediaBlocks.d.ts +5 -0
  135. package/lib/typescript/blocks/MediaBlocks.d.ts.map +1 -0
  136. package/lib/typescript/blocks/ReceiptBlocks.d.ts +27 -0
  137. package/lib/typescript/blocks/ReceiptBlocks.d.ts.map +1 -0
  138. package/lib/typescript/blocks/context.d.ts +35 -0
  139. package/lib/typescript/blocks/context.d.ts.map +1 -0
  140. package/lib/typescript/blocks/icons.d.ts +6 -0
  141. package/lib/typescript/blocks/icons.d.ts.map +1 -0
  142. package/lib/typescript/blocks/index.d.ts +6 -0
  143. package/lib/typescript/blocks/index.d.ts.map +1 -0
  144. package/lib/typescript/blocks/primitives.d.ts +85 -0
  145. package/lib/typescript/blocks/primitives.d.ts.map +1 -0
  146. package/lib/typescript/blocks/primitivesIndex.d.ts +3 -0
  147. package/lib/typescript/blocks/primitivesIndex.d.ts.map +1 -0
  148. package/lib/typescript/components/ApprovalCard.d.ts +7 -0
  149. package/lib/typescript/components/ApprovalCard.d.ts.map +1 -0
  150. package/lib/typescript/components/AskBuoyHeader.d.ts +14 -0
  151. package/lib/typescript/components/AskBuoyHeader.d.ts.map +1 -0
  152. package/lib/typescript/components/AskBuoyIcon.d.ts +6 -0
  153. package/lib/typescript/components/AskBuoyIcon.d.ts.map +1 -0
  154. package/lib/typescript/components/AskBuoyModal.d.ts +13 -0
  155. package/lib/typescript/components/AskBuoyModal.d.ts.map +1 -0
  156. package/lib/typescript/components/ChangesBar.d.ts +9 -0
  157. package/lib/typescript/components/ChangesBar.d.ts.map +1 -0
  158. package/lib/typescript/components/Composer.d.ts +9 -0
  159. package/lib/typescript/components/Composer.d.ts.map +1 -0
  160. package/lib/typescript/components/EmptyState.d.ts +6 -0
  161. package/lib/typescript/components/EmptyState.d.ts.map +1 -0
  162. package/lib/typescript/components/Markdown.d.ts +23 -0
  163. package/lib/typescript/components/Markdown.d.ts.map +1 -0
  164. package/lib/typescript/components/MessageList.d.ts +18 -0
  165. package/lib/typescript/components/MessageList.d.ts.map +1 -0
  166. package/lib/typescript/components/TypingDots.d.ts +2 -0
  167. package/lib/typescript/components/TypingDots.d.ts.map +1 -0
  168. package/lib/typescript/index.d.ts +28 -0
  169. package/lib/typescript/index.d.ts.map +1 -0
  170. package/lib/typescript/preset.d.ts +61 -0
  171. package/lib/typescript/preset.d.ts.map +1 -0
  172. package/lib/typescript/store/askBuoyStore.d.ts +124 -0
  173. package/lib/typescript/store/askBuoyStore.d.ts.map +1 -0
  174. package/lib/typescript/store/useAskBuoy.d.ts +22 -0
  175. package/lib/typescript/store/useAskBuoy.d.ts.map +1 -0
  176. package/lib/typescript/sync/askBuoySyncAdapter.d.ts +73 -0
  177. package/lib/typescript/sync/askBuoySyncAdapter.d.ts.map +1 -0
  178. package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts +2 -0
  179. package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts.map +1 -0
  180. package/lib/typescript/sync/wire.d.ts +17 -0
  181. package/lib/typescript/sync/wire.d.ts.map +1 -0
  182. package/lib/typescript/types.d.ts +119 -0
  183. package/lib/typescript/types.d.ts.map +1 -0
  184. package/package.json +83 -0
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.askBuoyStore = void 0;
7
+ /**
8
+ * Conversation state for the sheet.
9
+ *
10
+ * A module-level store rather than component state for two reasons: the sheet
11
+ * is unmounted whenever the tool is closed or minimised (and a conversation
12
+ * that vanished because someone tapped away would be maddening), and the sync
13
+ * adapter needs to read the same transcript to show it on the desktop.
14
+ *
15
+ * Deliberately NOT persisted. A transcript can contain anything the agent read
16
+ * — storage values, response bodies, a customer's record — and writing that to
17
+ * disk under a Buoy key would put it in the Storage tool and, from there, on
18
+ * the unauthenticated broker wire. It lives for the session and no longer.
19
+ */
20
+
21
+ /** A block in a message, and (for receipts) the tool call that produced it. */
22
+
23
+ let seq = 0;
24
+ const nextId = () => `m${++seq}`;
25
+ let state = {
26
+ messages: [],
27
+ busy: false,
28
+ pending: null,
29
+ notice: null,
30
+ configured: false,
31
+ answers: {},
32
+ awaitingBlockId: null,
33
+ actionState: {},
34
+ queued: null,
35
+ usage: {
36
+ input: 0,
37
+ output: 0,
38
+ requests: 0
39
+ }
40
+ };
41
+ const listeners = new Set();
42
+ let ledgerRef = null;
43
+
44
+ /**
45
+ * The session outlives the sheet the same way the transcript does. Session and
46
+ * ledger used to be per-mount: closing and reopening the tool kept the visible
47
+ * conversation but silently swapped in an empty ledger and a blank model
48
+ * memory — the undo bar vanished while the agent's changes stayed live in the
49
+ * app. Held here, keyed by a config signature so a real reconfiguration
50
+ * (different endpoint/model/tool set) still rebuilds.
51
+ */
52
+ let heldSession = null;
53
+ function set(next) {
54
+ state = {
55
+ ...state,
56
+ ...next
57
+ };
58
+ for (const fn of listeners) {
59
+ try {
60
+ fn();
61
+ } catch {
62
+ // A throwing subscriber must not take the transcript down mid-answer.
63
+ }
64
+ }
65
+ }
66
+ const askBuoyStore = exports.askBuoyStore = {
67
+ getState: () => state,
68
+ subscribe(fn) {
69
+ listeners.add(fn);
70
+ return () => listeners.delete(fn);
71
+ },
72
+ setLedger(ledger) {
73
+ ledgerRef = ledger;
74
+ },
75
+ getLedger() {
76
+ return ledgerRef;
77
+ },
78
+ holdSession(session, signature) {
79
+ heldSession = {
80
+ session,
81
+ signature
82
+ };
83
+ },
84
+ getHeldSession() {
85
+ return heldSession;
86
+ },
87
+ setNotice(notice) {
88
+ set({
89
+ notice
90
+ });
91
+ },
92
+ setConfigured(configured) {
93
+ if (configured !== state.configured) set({
94
+ configured
95
+ });
96
+ },
97
+ addUser(text) {
98
+ set({
99
+ messages: [...state.messages, {
100
+ id: nextId(),
101
+ role: "user",
102
+ text,
103
+ toolCalls: [],
104
+ blocks: []
105
+ }],
106
+ busy: true
107
+ });
108
+ },
109
+ /** Mark a turn as running without adding a bubble — the retry path. */
110
+ beginTurn() {
111
+ set({
112
+ busy: true
113
+ });
114
+ },
115
+ /** Park a message typed mid-turn instead of silently dropping it. */
116
+ setQueued(text) {
117
+ set({
118
+ queued: text
119
+ });
120
+ },
121
+ /** Drop one message — the failed assistant bubble a retry replaces. */
122
+ removeMessage(id) {
123
+ set({
124
+ messages: state.messages.filter(m => m.id !== id)
125
+ });
126
+ },
127
+ /** The user answered (or skipped) an Ask block. */
128
+ recordAnswer(answer) {
129
+ set({
130
+ answers: {
131
+ ...state.answers,
132
+ [answer.blockId]: answer
133
+ },
134
+ awaitingBlockId: state.awaitingBlockId === answer.blockId ? null : state.awaitingBlockId
135
+ });
136
+ },
137
+ setActionState(key, value) {
138
+ const next = {
139
+ ...state.actionState
140
+ };
141
+ if (value === null) delete next[key];else next[key] = value;
142
+ set({
143
+ actionState: next
144
+ });
145
+ },
146
+ /** Open a new assistant bubble for the turn that is about to stream. */
147
+ startAssistant() {
148
+ const id = nextId();
149
+ set({
150
+ messages: [...state.messages, {
151
+ id,
152
+ role: "assistant",
153
+ text: "",
154
+ toolCalls: [],
155
+ blocks: [],
156
+ streaming: true
157
+ }]
158
+ });
159
+ return id;
160
+ },
161
+ /**
162
+ * Fold one engine event into the open assistant message.
163
+ *
164
+ * Tool calls render as rows inside the bubble rather than as raw payloads:
165
+ * the label is already domain-flavoured ("Set points to 1500"), which is the
166
+ * only form a non-developer can actually check.
167
+ */
168
+ applyEvent(messageId, ev) {
169
+ const messages = state.messages.map(m => {
170
+ if (m.id !== messageId) return m;
171
+ switch (ev.type) {
172
+ case "text":
173
+ return {
174
+ ...m,
175
+ text: m.breakBeforeNextText && m.text ? `${m.text.trimEnd()}\n\n${ev.delta}` : m.text + ev.delta,
176
+ breakBeforeNextText: false
177
+ };
178
+ case "tool-start":
179
+ return {
180
+ ...m,
181
+ toolCalls: [...m.toolCalls, {
182
+ id: ev.id,
183
+ toolId: ev.toolId,
184
+ action: ev.action,
185
+ label: ev.label,
186
+ description: ev.description,
187
+ status: "running"
188
+ }]
189
+ };
190
+ case "tool-end":
191
+ return {
192
+ ...m,
193
+ breakBeforeNextText: true,
194
+ toolCalls: m.toolCalls.map(c => c.id === ev.id ? {
195
+ ...c,
196
+ status: !ev.ok && ev.summary === "refused" ? "refused" : ev.ok ? "ok" : "failed",
197
+ summary: ev.summary
198
+ } : c)
199
+ };
200
+ case "block":
201
+ return {
202
+ ...m,
203
+ breakBeforeNextText: true,
204
+ blocks: [...m.blocks, {
205
+ block: ev.block,
206
+ forToolCallId: ev.forToolCallId
207
+ }]
208
+ };
209
+ case "error":
210
+ return {
211
+ ...m,
212
+ error: ev.message
213
+ };
214
+ default:
215
+ return m;
216
+ }
217
+ });
218
+ set({
219
+ messages,
220
+ ...(ev.type === "awaiting-user" ? {
221
+ awaitingBlockId: ev.blockId
222
+ } : {}),
223
+ ...(ev.type === "usage" ? {
224
+ usage: {
225
+ input: state.usage.input + ev.input,
226
+ output: state.usage.output + ev.output,
227
+ requests: state.usage.requests + 1
228
+ }
229
+ } : {})
230
+ });
231
+ },
232
+ finishAssistant(messageId) {
233
+ set({
234
+ messages: state.messages.map(m => m.id === messageId ? {
235
+ ...m,
236
+ streaming: false
237
+ } : m),
238
+ busy: false
239
+ });
240
+ },
241
+ askApproval(input) {
242
+ return new Promise(resolve => {
243
+ set({
244
+ pending: {
245
+ ...input,
246
+ resolve
247
+ }
248
+ });
249
+ });
250
+ },
251
+ answerApproval(approved) {
252
+ const pending = state.pending;
253
+ set({
254
+ pending: null
255
+ });
256
+ pending?.resolve(approved);
257
+ },
258
+ reset() {
259
+ // Reject anything still waiting, or the turn hangs forever on a promise
260
+ // whose only resolver just left the screen.
261
+ state.pending?.resolve(false);
262
+ set({
263
+ messages: [],
264
+ busy: false,
265
+ pending: null,
266
+ notice: null,
267
+ answers: {},
268
+ awaitingBlockId: null,
269
+ actionState: {},
270
+ queued: null,
271
+ usage: {
272
+ input: 0,
273
+ output: 0,
274
+ requests: 0
275
+ }
276
+ });
277
+ }
278
+ };
279
+ //# sourceMappingURL=askBuoyStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["seq","nextId","state","messages","busy","pending","notice","configured","answers","awaitingBlockId","actionState","queued","usage","input","output","requests","listeners","Set","ledgerRef","heldSession","set","next","fn","askBuoyStore","exports","getState","subscribe","add","delete","setLedger","ledger","getLedger","holdSession","session","signature","getHeldSession","setNotice","setConfigured","addUser","text","id","role","toolCalls","blocks","beginTurn","setQueued","removeMessage","filter","m","recordAnswer","answer","blockId","setActionState","key","value","startAssistant","streaming","applyEvent","messageId","ev","map","type","breakBeforeNextText","trimEnd","delta","toolId","action","label","description","status","c","ok","summary","block","forToolCallId","error","message","finishAssistant","askApproval","Promise","resolve","answerApproval","approved","reset"],"sourceRoot":"../../../src","sources":["store/askBuoyStore.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;;AAyEA,IAAIA,GAAG,GAAG,CAAC;AACX,MAAMC,MAAM,GAAGA,CAAA,KAAM,IAAI,EAAED,GAAG,EAAE;AAEhC,IAAIE,KAAmB,GAAG;EACxBC,QAAQ,EAAE,EAAE;EACZC,IAAI,EAAE,KAAK;EACXC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,KAAK;EACjBC,OAAO,EAAE,CAAC,CAAC;EACXC,eAAe,EAAE,IAAI;EACrBC,WAAW,EAAE,CAAC,CAAC;EACfC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE;IAAEC,KAAK,EAAE,CAAC;IAAEC,MAAM,EAAE,CAAC;IAAEC,QAAQ,EAAE;EAAE;AAC5C,CAAC;AACD,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AACrC,IAAIC,SAA8B,GAAG,IAAI;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIC,WAAkE,GAAG,IAAI;AAE7E,SAASC,GAAGA,CAACC,IAA2B,EAAQ;EAC9CnB,KAAK,GAAG;IAAE,GAAGA,KAAK;IAAE,GAAGmB;EAAK,CAAC;EAC7B,KAAK,MAAMC,EAAE,IAAIN,SAAS,EAAE;IAC1B,IAAI;MACFM,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,MAAM;MACN;IAAA;EAEJ;AACF;AAEO,MAAMC,Y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AAuC,EAAoB;IACrE,OAAO,IAAIkE,OAAO,CAAWC,OAAO,IAAK;MACvC5D,GAAG,CAAC;QAAEf,OAAO,EAAE;UAAE,GAAGQ,KAAK;UAAEmE;QAAQ;MAAE,CAAC,CAAC;IACzC,CAAC,CAAC;EACJ,CAAC;EAEDC,cAAcA,CAACC,QAAiB,EAAQ;IACtC,MAAM7E,OAAO,GAAGH,KAAK,CAACG,OAAO;IAC7Be,GAAG,CAAC;MAAEf,OAAO,EAAE;IAAK,CAAC,CAAC;IACtBA,OAAO,EAAE2E,OAAO,CAACE,QAAQ,CAAC;EAC5B,CAAC;EAEDC,KAAKA,CAAA,EAAS;IACZ;IACA;IACAjF,KAAK,CAACG,OAAO,EAAE2E,OAAO,CAAC,KAAK,CAAC;IAC7B5D,GAAG,CAAC;MACFjB,QAAQ,EAAE,EAAE;MACZC,IAAI,EAAE,KAAK;MACXC,OAAO,EAAE,IAAI;MACbC,MAAM,EAAE,IAAI;MACZE,OAAO,EAAE,CAAC,CAAC;MACXC,eAAe,EAAE,IAAI;MACrBC,WAAW,EAAE,CAAC,CAAC;MACfC,MAAM,EAAE,IAAI;MACZC,KAAK,EAAE;QAAEC,KAAK,EAAE,CAAC;QAAEC,MAAM,EAAE,CAAC;QAAEC,QAAQ,EAAE;MAAE;IAC5C,CAAC,CAAC;EACJ;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAskBuoy = useAskBuoy;
7
+ exports.useAskBuoyState = useAskBuoyState;
8
+ var _react = require("react");
9
+ var _reactNative = require("react-native");
10
+ var _sharedUi = require("@buoy-gg/shared-ui");
11
+ var _agentCore = require("@buoy-gg/agent-core");
12
+ var _askBuoyStore = require("./askBuoyStore");
13
+ /**
14
+ * Wire the sheet to the agent.
15
+ *
16
+ * Two things here are load-bearing:
17
+ *
18
+ * 1. DISPATCH GOES THROUGH `dispatchToolAction`, the same on-device seam a
19
+ * Scenario step and a desktop click use. No second adapter map, nothing
20
+ * that can drift from what the broker sees.
21
+ * 2. THE SESSION IS REBUILT WHEN THE TOOL LIST CHANGES. The adapter map is a
22
+ * memo whose contents depend on which packages resolved and whether a
23
+ * QueryClientProvider is above FloatingDevTools — it is per-app and per
24
+ * render, never a constant. A session that cached the tool list at open
25
+ * would offer the model tools that are no longer there.
26
+ */
27
+
28
+ const isRelease = typeof __DEV__ !== "undefined" && !__DEV__;
29
+ function useAskBuoyState() {
30
+ return (0, _react.useSyncExternalStore)(_askBuoyStore.askBuoyStore.subscribe, _askBuoyStore.askBuoyStore.getState, _askBuoyStore.askBuoyStore.getState);
31
+ }
32
+ function useAskBuoy(config) {
33
+ const state = useAskBuoyState();
34
+ const sessionRef = (0, _react.useRef)(null);
35
+ const abortRef = (0, _react.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 = (0, _react.useRef)(config);
39
+ configRef.current = config;
40
+ const configured = !!config?.endpoint && !!config?.model;
41
+
42
+ // Recomputed each render: the set of dispatchable tools is not a constant.
43
+ //
44
+ // `getSnapshot` is folded in here because half of Buoy's read surface is not
45
+ // an action at all — console entries, network events, routes and env live
46
+ // only in the adapter's snapshot. Without this the model is offered a
47
+ // console tool whose sole action wipes the logs, and no way to read them.
48
+ const availableActions = (0, _react.useMemo)(() => {
49
+ try {
50
+ const actions = (0, _sharedUi.listToolActions)();
51
+ for (const toolId of (0, _sharedUi.listSnapshotToolIds)()) {
52
+ if (!actions[toolId]) actions[toolId] = [];
53
+ if (!actions[toolId].includes(_agentCore.SNAPSHOT_ACTION)) {
54
+ actions[toolId] = [_agentCore.SNAPSHOT_ACTION, ...actions[toolId]];
55
+ }
56
+ }
57
+ return actions;
58
+ } catch {
59
+ return {};
60
+ }
61
+ }, []);
62
+ const toolKey = Object.keys(availableActions).sort().join(",");
63
+ (0, _react.useEffect)(() => {
64
+ _askBuoyStore.askBuoyStore.setConfigured(configured);
65
+ if (!configured || !config) {
66
+ sessionRef.current = null;
67
+ _askBuoyStore.askBuoyStore.setNotice("Ask Buoy isn't set up in this app yet. A developer needs to point it at your team's AI endpoint.");
68
+ return;
69
+ }
70
+ // The classic first-run mistake, caught statically: a provider's own URL
71
+ // with the wrong protocol fails with a raw error that says nothing about
72
+ // the one-line fix. ONLY the canonical provider hosts are checked — a
73
+ // gateway may legitimately speak either protocol on any path (our own dev
74
+ // gateway serves OpenAI framing on /v1/messages, and a path-based version
75
+ // of this check flagged it on the first device run).
76
+ const protocol = config.protocol ?? "anthropic";
77
+ if (isRelease && config.apiKey) {
78
+ _askBuoyStore.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.");
79
+ } else if (protocol === "anthropic" && /^https?:\/\/api\.openai\.com\//i.test(config.endpoint)) {
80
+ _askBuoyStore.askBuoyStore.setNotice('This endpoint is api.openai.com but the protocol is "anthropic". Set protocol: "openai" in the askBuoy config.');
81
+ } else if (protocol === "openai" && /^https?:\/\/api\.anthropic\.com\//i.test(config.endpoint)) {
82
+ _askBuoyStore.askBuoyStore.setNotice('This endpoint is api.anthropic.com but the protocol is "openai". Remove protocol or set it to "anthropic".');
83
+ } else {
84
+ _askBuoyStore.askBuoyStore.setNotice(null);
85
+ }
86
+
87
+ // Reuse the held session while nothing material changed. The transcript
88
+ // already survives close/reopen in the module store; without this the
89
+ // session and ledger did not — reopening the sheet swapped in an empty
90
+ // ledger (undo bar gone, agent changes still live in the app) and a blank
91
+ // model memory behind a transcript that still showed the conversation.
92
+ // The tool list is deliberately NOT part of this signature. Packages
93
+ // register a frame or two apart, so `toolKey` legitimately changes right
94
+ // after open — and keying on it silently rebuilt the session mid-chat,
95
+ // throwing away the conversation, the model's memory and the undo ledger
96
+ // while the transcript (a separate store) kept rendering as if nothing
97
+ // happened. Verified on device: a destructive change went unrecorded
98
+ // because it landed in a ledger that had just been replaced.
99
+ const signature = [config.endpoint, config.protocol ?? "anthropic", config.model].join("|");
100
+ const held = _askBuoyStore.askBuoyStore.getHeldSession();
101
+ if (held && held.signature === signature) {
102
+ sessionRef.current = held.session;
103
+ held.session.setAvailableActions(availableActions);
104
+ _askBuoyStore.askBuoyStore.setLedger(held.session.ledger);
105
+ return;
106
+ }
107
+ const session = (0, _agentCore.createAskBuoySession)({
108
+ endpoint: config.endpoint,
109
+ protocol: config.protocol ?? "anthropic",
110
+ model: config.model,
111
+ headers: config.headers,
112
+ apiKey: config.apiKey,
113
+ maxTokens: config.maxTokens,
114
+ anthropicVersion: config.anthropicVersion,
115
+ requestOverrides: config.requestOverrides,
116
+ // Host-declared custom tools join the built-in catalog. toProviderTools
117
+ // still filters against the live registry, so a descriptor whose
118
+ // `custom:<id>` adapter never registered is simply not offered.
119
+ catalog: config.tools?.length ? [..._agentCore.CATALOG, ...config.tools] : undefined,
120
+ dispatch: _sharedUi.dispatchToolAction,
121
+ readSnapshot: _sharedUi.readToolSnapshot,
122
+ availableActions,
123
+ policy: config.policy,
124
+ context: config.context,
125
+ isRelease,
126
+ appName: config.appName,
127
+ platform: _reactNative.Platform.OS,
128
+ requestApproval: input => _askBuoyStore.askBuoyStore.askApproval(input)
129
+ });
130
+ sessionRef.current = session;
131
+ _askBuoyStore.askBuoyStore.holdSession(session, signature);
132
+ _askBuoyStore.askBuoyStore.setLedger(session.ledger);
133
+
134
+ // The registry publishes on mount, a frame or two after first paint. Warm
135
+ // the grounding once it is there so the first question does not pay for it.
136
+ let cancelled = false;
137
+ void (0, _sharedUi.waitForToolRegistry)().then(ready => {
138
+ if (ready && !cancelled) void session.prime();
139
+ });
140
+ return () => {
141
+ cancelled = true;
142
+ };
143
+ }, [configured, config, availableActions, toolKey]);
144
+
145
+ /** Stream one turn into a fresh assistant bubble. Callers set up the user side. */
146
+ const runTurn = (0, _react.useCallback)(text => {
147
+ const session = sessionRef.current;
148
+ if (!session) return;
149
+ _askBuoyStore.askBuoyStore.beginTurn();
150
+ const messageId = _askBuoyStore.askBuoyStore.startAssistant();
151
+ const controller = new AbortController();
152
+ abortRef.current = controller;
153
+ const onEvent = configRef.current?.onEvent;
154
+ void (async () => {
155
+ try {
156
+ for await (const ev of session.send(text, controller.signal)) {
157
+ _askBuoyStore.askBuoyStore.applyEvent(messageId, ev);
158
+ if (onEvent) {
159
+ try {
160
+ onEvent(ev);
161
+ } catch {
162
+ // The audit tap must never take the chat down.
163
+ }
164
+ }
165
+ }
166
+ } catch (err) {
167
+ _askBuoyStore.askBuoyStore.applyEvent(messageId, {
168
+ type: "error",
169
+ message: err instanceof Error ? err.message : "Something went wrong talking to your AI endpoint."
170
+ });
171
+ } finally {
172
+ _askBuoyStore.askBuoyStore.finishAssistant(messageId);
173
+ abortRef.current = null;
174
+ }
175
+ })();
176
+ }, []);
177
+ const send = (0, _react.useCallback)(text => {
178
+ const trimmed = text.trim();
179
+ if (!sessionRef.current || !trimmed) return;
180
+
181
+ // Typed mid-turn: park it. The composer already cleared the field, and
182
+ // silently dropping the words was the worst of all outcomes.
183
+ if (_askBuoyStore.askBuoyStore.getState().busy) {
184
+ _askBuoyStore.askBuoyStore.setQueued(trimmed);
185
+ return;
186
+ }
187
+
188
+ // Typing past an Ask block IS an answer: the block is skipped and locks.
189
+ // Without this the composer stayed on "Pick an option above…" forever and
190
+ // a stale choice sat tappable in the history.
191
+ const awaiting = _askBuoyStore.askBuoyStore.getState().awaitingBlockId;
192
+ if (awaiting) _askBuoyStore.askBuoyStore.recordAnswer({
193
+ blockId: awaiting,
194
+ kind: "skipped"
195
+ });
196
+ _askBuoyStore.askBuoyStore.addUser(trimmed);
197
+ runTurn(trimmed);
198
+ }, [runTurn]);
199
+ const retry = (0, _react.useCallback)(() => {
200
+ const {
201
+ messages,
202
+ busy
203
+ } = _askBuoyStore.askBuoyStore.getState();
204
+ if (busy || !sessionRef.current) return;
205
+ const lastUser = [...messages].reverse().find(m => m.role === "user");
206
+ if (!lastUser) return;
207
+ // Replace the failed bubble rather than stacking a second one under it.
208
+ const last = messages[messages.length - 1];
209
+ if (last && last.role === "assistant" && last.error) _askBuoyStore.askBuoyStore.removeMessage(last.id);
210
+ runTurn(lastUser.text);
211
+ }, [runTurn]);
212
+ const stop = (0, _react.useCallback)(() => {
213
+ // A pending approval parks an unresolved promise inside the engine; the
214
+ // abort signal is only read between steps, so Stop must also answer the
215
+ // approval (as declined) or the generator hangs forever.
216
+ if (_askBuoyStore.askBuoyStore.getState().pending) _askBuoyStore.askBuoyStore.answerApproval(false);
217
+ abortRef.current?.abort();
218
+ abortRef.current = null;
219
+ }, []);
220
+
221
+ // Flush the parked message the moment the turn ends.
222
+ const queued = state.queued;
223
+ (0, _react.useEffect)(() => {
224
+ if (!state.busy && queued) {
225
+ _askBuoyStore.askBuoyStore.setQueued(null);
226
+ send(queued);
227
+ }
228
+ }, [state.busy, queued, send]);
229
+ const reset = (0, _react.useCallback)(() => {
230
+ abortRef.current?.abort();
231
+ sessionRef.current?.reset();
232
+ _askBuoyStore.askBuoyStore.reset();
233
+ }, []);
234
+ const approve = (0, _react.useCallback)(approved => {
235
+ _askBuoyStore.askBuoyStore.answerApproval(approved);
236
+ }, []);
237
+ const answer = (0, _react.useCallback)(a => {
238
+ _askBuoyStore.askBuoyStore.recordAnswer(a);
239
+ // Plain words to the model, never JSON: "Business checkout", "Yes, go ahead."
240
+ send((0, _agentCore.answerToText)(a));
241
+ }, [send]);
242
+
243
+ /**
244
+ * Block buttons. `send` is a chat reply; `dispatch` runs the action through
245
+ * `runGatedAction` — the SAME validation, policy and ledger path a model
246
+ * call takes, minus the model. The first version called `dispatchToolAction`
247
+ * raw, which made a model-authored button an invisible, ungoverned,
248
+ * unundoable mutation while the `buoy_ui` schema promised the opposite.
249
+ * The human's tap satisfies `requireApproval`; deny lists, read-only mode
250
+ * and release refusals still stand. Button state is tracked so a tap shows
251
+ * running → done and can't double-fire.
252
+ * (`minimize` / `openTool` are the sheet's to handle; see AskBuoyModal.)
253
+ */
254
+ const runAction = (0, _react.useCallback)(async (action, blockId) => {
255
+ if (action.send) {
256
+ send(action.send);
257
+ return;
258
+ }
259
+ if (!action.dispatch) return;
260
+ const key = `${blockId}:${action.label}`;
261
+ const ledger = _askBuoyStore.askBuoyStore.getLedger();
262
+ if (!ledger) {
263
+ _askBuoyStore.askBuoyStore.setNotice(`${action.label} failed — no active Ask Buoy session.`);
264
+ return;
265
+ }
266
+ _askBuoyStore.askBuoyStore.setActionState(key, "running");
267
+ const outcome = await (0, _agentCore.runGatedAction)({
268
+ toolId: action.dispatch.toolId,
269
+ action: action.dispatch.action,
270
+ params: action.dispatch.params ?? {},
271
+ dispatch: _sharedUi.dispatchToolAction,
272
+ ledger,
273
+ policy: config?.policy ?? {},
274
+ isRelease,
275
+ // Same merged catalog the session offers, so a button on a custom
276
+ // tool's block is not refused as unknown.
277
+ catalog: config?.tools?.length ? [..._agentCore.CATALOG, ...config.tools] : undefined
278
+ });
279
+ if (outcome.ok) {
280
+ _askBuoyStore.askBuoyStore.setActionState(key, "done");
281
+ } else {
282
+ _askBuoyStore.askBuoyStore.setActionState(key, "failed");
283
+ _askBuoyStore.askBuoyStore.setNotice(`${action.label} failed — ${outcome.error}`);
284
+ }
285
+ }, [send, config]);
286
+ return {
287
+ state,
288
+ send,
289
+ stop,
290
+ reset,
291
+ approve,
292
+ retry,
293
+ answer,
294
+ runAction,
295
+ configured,
296
+ toolCount: Object.keys(availableActions).length
297
+ };
298
+ }
299
+ //# sourceMappingURL=useAskBuoy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_sharedUi","_agentCore","_askBuoyStore","isRelease","__DEV__","useAskBuoyState","useSyncExternalStore","askBuoyStore","subscribe","getState","useAskBuoy","config","state","sessionRef","useRef","abortRef","configRef","current","configured","endpoint","model","availableActions","useMemo","actions","listToolActions","toolId","listSnapshotToolIds","includes","SNAPSHOT_ACTION","toolKey","Object","keys","sort","join","useEffect","setConfigured","setNotice","protocol","apiKey","test","signature","held","getHeldSession","session","setAvailableActions","setLedger","ledger","createAskBuoySession","headers","maxTokens","anthropicVersion","requestOverrides","catalog","tools","length","CATALOG","undefined","dispatch","dispatchToolAction","readSnapshot","readToolSnapshot","policy","context","appName","platform","Platform","OS","requestApproval","input","askApproval","holdSession","cancelled","waitForToolRegistry","then","ready","prime","runTurn","useCallback","text","beginTurn","messageId","startAssistant","controller","AbortController","onEvent","ev","send","signal","applyEvent","err","type","message","Error","finishAssistant","trimmed","trim","busy","setQueued","awaiting","awaitingBlockId","recordAnswer","blockId","kind","addUser","retry","messages","lastUser","reverse","find","m","role","last","error","removeMessage","id","stop","pending","answerApproval","abort","queued","reset","approve","approved","answer","a","answerToText","runAction","action","key","label","getLedger","setActionState","outcome","runGatedAction","params","ok","toolCount"],"sourceRoot":"../../../src","sources":["store/useAskBuoy.ts"],"mappings":";;;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAOA,IAAAG,UAAA,GAAAH,OAAA;AAWA,IAAAI,aAAA,GAAAJ,OAAA;AAlCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA,MAAMK,SAAS,GAAG,OAAOC,OAAO,KAAK,WAAW,IAAI,CAACA,OAAO;AAErD,SAASC,eAAeA,CAAA,EAAiB;EAC9C,OAAO,IAAAC,2BAAoB,EAACC,0BAAY,CAACC,SAAS,EAAED,0BAAY,CAACE,QAAQ,EAAEF,0BAAY,CAACE,QAAQ,CAAC;AACnG;AAmBO,SAASC,UAAUA,CAACC,MAAiC,EAAqB;EAC/E,MAAMC,KAAK,GAAGP,eAAe,CAAC,CAAC;EAC/B,MAAMQ,UAAU,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EACtD,MAAMC,QAAQ,GAAG,IAAAD,aAAM,EAAyB,IAAI,CAAC;EACrD;EACA;EACA,MAAME,SAAS,GAAG,IAAAF,aAA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