@buoy-gg/ask-buoy 7.0.33 → 7.0.34

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 (153) hide show
  1. package/README.md +1 -1
  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 -545
  6. package/lib/commonjs/blocks/ExtraBlocks.js +1 -1821
  7. package/lib/commonjs/blocks/MediaBlocks.js +1 -140
  8. package/lib/commonjs/blocks/ReceiptBlocks.js +1 -596
  9. package/lib/commonjs/blocks/context.js +1 -42
  10. package/lib/commonjs/blocks/icons.js +1 -96
  11. package/lib/commonjs/blocks/index.js +1 -95
  12. package/lib/commonjs/blocks/primitives.js +1 -312
  13. package/lib/commonjs/blocks/primitivesIndex.js +1 -56
  14. package/lib/commonjs/components/ApprovalCard.js +1 -140
  15. package/lib/commonjs/components/AskBuoyHeader.js +1 -127
  16. package/lib/commonjs/components/AskBuoyIcon.js +1 -19
  17. package/lib/commonjs/components/AskBuoyModal.js +1 -322
  18. package/lib/commonjs/components/ChangesBar.js +1 -211
  19. package/lib/commonjs/components/Composer.js +1 -175
  20. package/lib/commonjs/components/EmptyState.js +1 -154
  21. package/lib/commonjs/components/Markdown.js +1 -252
  22. package/lib/commonjs/components/MessageList.js +1 -648
  23. package/lib/commonjs/components/TypingDots.js +1 -63
  24. package/lib/commonjs/index.js +1 -205
  25. package/lib/commonjs/preset.js +1 -90
  26. package/lib/commonjs/store/askBuoyStore.js +1 -279
  27. package/lib/commonjs/store/useAskBuoy.js +1 -299
  28. package/lib/commonjs/sync/askBuoySyncAdapter.js +1 -119
  29. package/lib/commonjs/sync/askBuoySyncAdapter.test.js +1 -136
  30. package/lib/commonjs/sync/wire.js +1 -58
  31. package/lib/commonjs/types.js +1 -6
  32. package/lib/module/blocks/AskBlocks.js +1 -331
  33. package/lib/module/blocks/BlockRenderer.js +1 -245
  34. package/lib/module/blocks/ChromePrototypes.js +1 -503
  35. package/lib/module/blocks/DataBlocks.js +1 -532
  36. package/lib/module/blocks/ExtraBlocks.js +1 -1794
  37. package/lib/module/blocks/MediaBlocks.js +1 -135
  38. package/lib/module/blocks/ReceiptBlocks.js +1 -584
  39. package/lib/module/blocks/context.js +1 -35
  40. package/lib/module/blocks/icons.js +1 -91
  41. package/lib/module/blocks/index.js +1 -8
  42. package/lib/module/blocks/primitives.js +1 -301
  43. package/lib/module/blocks/primitivesIndex.js +1 -5
  44. package/lib/module/components/ApprovalCard.js +1 -135
  45. package/lib/module/components/AskBuoyHeader.js +1 -124
  46. package/lib/module/components/AskBuoyIcon.js +1 -8
  47. package/lib/module/components/AskBuoyModal.js +1 -317
  48. package/lib/module/components/ChangesBar.js +1 -206
  49. package/lib/module/components/Composer.js +1 -170
  50. package/lib/module/components/EmptyState.js +1 -149
  51. package/lib/module/components/Markdown.js +1 -246
  52. package/lib/module/components/MessageList.js +1 -642
  53. package/lib/module/components/TypingDots.js +1 -58
  54. package/lib/module/index.js +1 -29
  55. package/lib/module/preset.js +1 -73
  56. package/lib/module/store/askBuoyStore.js +1 -275
  57. package/lib/module/store/useAskBuoy.js +1 -293
  58. package/lib/module/sync/askBuoySyncAdapter.js +1 -114
  59. package/lib/module/sync/askBuoySyncAdapter.test.js +1 -135
  60. package/lib/module/sync/wire.js +1 -47
  61. package/lib/module/types.js +1 -4
  62. package/lib/typescript/preset.d.ts +1 -1
  63. package/package.json +8 -8
  64. package/lib/commonjs/blocks/AskBlocks.js.map +0 -1
  65. package/lib/commonjs/blocks/BlockRenderer.js.map +0 -1
  66. package/lib/commonjs/blocks/ChromePrototypes.js.map +0 -1
  67. package/lib/commonjs/blocks/DataBlocks.js.map +0 -1
  68. package/lib/commonjs/blocks/ExtraBlocks.js.map +0 -1
  69. package/lib/commonjs/blocks/MediaBlocks.js.map +0 -1
  70. package/lib/commonjs/blocks/ReceiptBlocks.js.map +0 -1
  71. package/lib/commonjs/blocks/context.js.map +0 -1
  72. package/lib/commonjs/blocks/icons.js.map +0 -1
  73. package/lib/commonjs/blocks/index.js.map +0 -1
  74. package/lib/commonjs/blocks/primitives.js.map +0 -1
  75. package/lib/commonjs/blocks/primitivesIndex.js.map +0 -1
  76. package/lib/commonjs/components/ApprovalCard.js.map +0 -1
  77. package/lib/commonjs/components/AskBuoyHeader.js.map +0 -1
  78. package/lib/commonjs/components/AskBuoyIcon.js.map +0 -1
  79. package/lib/commonjs/components/AskBuoyModal.js.map +0 -1
  80. package/lib/commonjs/components/ChangesBar.js.map +0 -1
  81. package/lib/commonjs/components/Composer.js.map +0 -1
  82. package/lib/commonjs/components/EmptyState.js.map +0 -1
  83. package/lib/commonjs/components/Markdown.js.map +0 -1
  84. package/lib/commonjs/components/MessageList.js.map +0 -1
  85. package/lib/commonjs/components/TypingDots.js.map +0 -1
  86. package/lib/commonjs/index.js.map +0 -1
  87. package/lib/commonjs/preset.js.map +0 -1
  88. package/lib/commonjs/store/askBuoyStore.js.map +0 -1
  89. package/lib/commonjs/store/useAskBuoy.js.map +0 -1
  90. package/lib/commonjs/sync/askBuoySyncAdapter.js.map +0 -1
  91. package/lib/commonjs/sync/askBuoySyncAdapter.test.js.map +0 -1
  92. package/lib/commonjs/sync/wire.js.map +0 -1
  93. package/lib/commonjs/types.js.map +0 -1
  94. package/lib/module/blocks/AskBlocks.js.map +0 -1
  95. package/lib/module/blocks/BlockRenderer.js.map +0 -1
  96. package/lib/module/blocks/ChromePrototypes.js.map +0 -1
  97. package/lib/module/blocks/DataBlocks.js.map +0 -1
  98. package/lib/module/blocks/ExtraBlocks.js.map +0 -1
  99. package/lib/module/blocks/MediaBlocks.js.map +0 -1
  100. package/lib/module/blocks/ReceiptBlocks.js.map +0 -1
  101. package/lib/module/blocks/context.js.map +0 -1
  102. package/lib/module/blocks/icons.js.map +0 -1
  103. package/lib/module/blocks/index.js.map +0 -1
  104. package/lib/module/blocks/primitives.js.map +0 -1
  105. package/lib/module/blocks/primitivesIndex.js.map +0 -1
  106. package/lib/module/components/ApprovalCard.js.map +0 -1
  107. package/lib/module/components/AskBuoyHeader.js.map +0 -1
  108. package/lib/module/components/AskBuoyIcon.js.map +0 -1
  109. package/lib/module/components/AskBuoyModal.js.map +0 -1
  110. package/lib/module/components/ChangesBar.js.map +0 -1
  111. package/lib/module/components/Composer.js.map +0 -1
  112. package/lib/module/components/EmptyState.js.map +0 -1
  113. package/lib/module/components/Markdown.js.map +0 -1
  114. package/lib/module/components/MessageList.js.map +0 -1
  115. package/lib/module/components/TypingDots.js.map +0 -1
  116. package/lib/module/index.js.map +0 -1
  117. package/lib/module/preset.js.map +0 -1
  118. package/lib/module/store/askBuoyStore.js.map +0 -1
  119. package/lib/module/store/useAskBuoy.js.map +0 -1
  120. package/lib/module/sync/askBuoySyncAdapter.js.map +0 -1
  121. package/lib/module/sync/askBuoySyncAdapter.test.js.map +0 -1
  122. package/lib/module/sync/wire.js.map +0 -1
  123. package/lib/module/types.js.map +0 -1
  124. package/lib/typescript/blocks/AskBlocks.d.ts.map +0 -1
  125. package/lib/typescript/blocks/BlockRenderer.d.ts.map +0 -1
  126. package/lib/typescript/blocks/ChromePrototypes.d.ts.map +0 -1
  127. package/lib/typescript/blocks/DataBlocks.d.ts.map +0 -1
  128. package/lib/typescript/blocks/ExtraBlocks.d.ts.map +0 -1
  129. package/lib/typescript/blocks/MediaBlocks.d.ts.map +0 -1
  130. package/lib/typescript/blocks/ReceiptBlocks.d.ts.map +0 -1
  131. package/lib/typescript/blocks/context.d.ts.map +0 -1
  132. package/lib/typescript/blocks/icons.d.ts.map +0 -1
  133. package/lib/typescript/blocks/index.d.ts.map +0 -1
  134. package/lib/typescript/blocks/primitives.d.ts.map +0 -1
  135. package/lib/typescript/blocks/primitivesIndex.d.ts.map +0 -1
  136. package/lib/typescript/components/ApprovalCard.d.ts.map +0 -1
  137. package/lib/typescript/components/AskBuoyHeader.d.ts.map +0 -1
  138. package/lib/typescript/components/AskBuoyIcon.d.ts.map +0 -1
  139. package/lib/typescript/components/AskBuoyModal.d.ts.map +0 -1
  140. package/lib/typescript/components/ChangesBar.d.ts.map +0 -1
  141. package/lib/typescript/components/Composer.d.ts.map +0 -1
  142. package/lib/typescript/components/EmptyState.d.ts.map +0 -1
  143. package/lib/typescript/components/Markdown.d.ts.map +0 -1
  144. package/lib/typescript/components/MessageList.d.ts.map +0 -1
  145. package/lib/typescript/components/TypingDots.d.ts.map +0 -1
  146. package/lib/typescript/index.d.ts.map +0 -1
  147. package/lib/typescript/preset.d.ts.map +0 -1
  148. package/lib/typescript/store/askBuoyStore.d.ts.map +0 -1
  149. package/lib/typescript/store/useAskBuoy.d.ts.map +0 -1
  150. package/lib/typescript/sync/askBuoySyncAdapter.d.ts.map +0 -1
  151. package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts.map +0 -1
  152. package/lib/typescript/sync/wire.d.ts.map +0 -1
  153. package/lib/typescript/types.d.ts.map +0 -1
@@ -1,8 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Re-exported from floating-tools-core so the tool package has one import
5
- * surface, matching how every other Buoy tool exposes its icon.
6
- */
7
- export { AskBuoyIcon, ASK_BUOY_ICON_COLOR } from "@buoy-gg/floating-tools-core";
8
- //# sourceMappingURL=AskBuoyIcon.js.map
1
+ "use strict";export{AskBuoyIcon,ASK_BUOY_ICON_COLOR}from"@buoy-gg/floating-tools-core";
@@ -1,317 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Ask Buoy — the sheet.
5
- *
6
- * Manual JsModal chrome rather than the declarative `InstalledApp.modal` path,
7
- * because `ToolModalShell` forwards neither `footer`/`footerHeight` nor
8
- * `initialHeight`, and a conversation in a 400pt sheet with no sticky composer
9
- * is not usable.
10
- *
11
- * The layout rules here are all learned ones, each noted at its line: one
12
- * scroller owned by the message list, no animated background competing with
13
- * streaming text, transparent containers so the sheet's own chrome shows, and
14
- * an iOS-only keyboard offset.
15
- *
16
- * Top to bottom: header (title, live status, new-conversation) · changes bar
17
- * (only once something has been changed) · transcript · approval card (only
18
- * with `requireApproval`) · composer. Nothing else. The old "New conversation"
19
- * text link under the composer is gone — it is the header's + button now.
20
- */
21
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
- import { Alert, Animated, KeyboardAvoidingView, Platform, StyleSheet, Text, View } from "react-native";
23
- import { isReversible } from "@buoy-gg/agent-core";
24
- import { dispatchToolAction, FeatureGate, Info, JsModal, night, useSafeAreaInsets } from "@buoy-gg/shared-ui";
25
- import { BlockHandlersProvider } from "../blocks";
26
- import { ApprovalCard } from "./ApprovalCard";
27
- import { ChangesBar } from "./ChangesBar";
28
- import { Composer } from "./Composer";
29
- import { AskBuoyHeader } from "./AskBuoyHeader";
30
- import { EmptyState } from "./EmptyState";
31
- import { MessageList } from "./MessageList";
32
- import { askBuoyStore } from "../store/askBuoyStore";
33
- import { useAskBuoy } from "../store/useAskBuoy";
34
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
35
- export function AskBuoyModal({
36
- visible,
37
- onClose,
38
- onBack,
39
- onMinimize,
40
- persistenceKey,
41
- config
42
- }) {
43
- const {
44
- state,
45
- send,
46
- stop,
47
- reset,
48
- approve,
49
- retry,
50
- answer,
51
- runAction,
52
- configured,
53
- toolCount
54
- } = useAskBuoy(config);
55
- const [changesOpen, setChangesOpen] = useState(false);
56
- // A hardcoded device map, not the native library — an unmapped phone
57
- // silently returns bottom: 0, which is how footers ended up sitting on the
58
- // home indicator.
59
- const insets = useSafeAreaInsets({
60
- minBottom: 16
61
- });
62
-
63
- /**
64
- * `dispatchToolAction` is imported STATICALLY at the top of this file, not
65
- * with `import()`. A dynamic import here resolves through Metro's
66
- * async-require path, which in a lazy dev bundle rejects with "Expected
67
- * HMRClient.setup() call at startup" — and because the promise was voided,
68
- * Undo did nothing at all while the bar went on claiming the changes were
69
- * undoable. shared-ui is already a static dependency of this component.
70
- *
71
- * A failed revert is SHOWN. `revertAll` reports what it could not put back,
72
- * and swallowing that is the same failure in a quieter form: the whole
73
- * reason mutations may auto-run is that undo is real.
74
- */
75
- const undoAll = useCallback(() => {
76
- const ledger = askBuoyStore.getLedger();
77
- if (!ledger) return;
78
- void (async () => {
79
- const outcome = await ledger.revertAll(dispatchToolAction);
80
- if (outcome.failed.length === 0) {
81
- askBuoyStore.setNotice(null);
82
- return;
83
- }
84
- const detail = outcome.failed.map(f => `${f.label} (${f.error})`).join("; ");
85
- askBuoyStore.setNotice(`Couldn't undo ${outcome.failed.length} change${outcome.failed.length === 1 ? "" : "s"} — ${detail}`);
86
- })();
87
- }, []);
88
- const toggleChanges = useCallback(() => setChangesOpen(v => !v), []);
89
-
90
- /**
91
- * PEEK. When the agent navigates or taps, the sheet drops to a 120pt strip
92
- * for ~2.5s so the user watches the app do it, then springs back to the
93
- * height it had (including a user's drag-resize — the value is read live,
94
- * never assumed). Rides JsModal's external `animatedHeight` seam, so the
95
- * modal's own drag-resize keeps working on the same value.
96
- */
97
- const sheetHeight = useRef(new Animated.Value(560)).current;
98
- const peeking = useRef(false);
99
- const runPeek = useCallback(() => {
100
- if (peeking.current) return;
101
- peeking.current = true;
102
- sheetHeight.stopAnimation(from => {
103
- const restoreTo = typeof from === "number" && from > 200 ? from : 560;
104
- Animated.timing(sheetHeight, {
105
- toValue: 120,
106
- duration: 220,
107
- useNativeDriver: false
108
- }).start(() => {
109
- setTimeout(() => {
110
- Animated.spring(sheetHeight, {
111
- toValue: restoreTo,
112
- friction: 9,
113
- useNativeDriver: false
114
- }).start(() => {
115
- peeking.current = false;
116
- });
117
- }, 2500);
118
- });
119
- });
120
- }, [sheetHeight]);
121
-
122
- // A new `peek` receipt (navigate, tap) triggers the shrink. Keyed by
123
- // message id + count so a fresh assistant message restarts the count.
124
- const peekKey = useMemo(() => {
125
- const last = state.messages[state.messages.length - 1];
126
- if (!last || last.role !== "assistant") return "";
127
- const peeks = last.blocks.filter(p => p.block.kind === "peek").length;
128
- return peeks > 0 ? `${last.id}:${peeks}` : "";
129
- }, [state.messages]);
130
- const prevPeekKey = useRef("");
131
- useEffect(() => {
132
- if (peekKey && peekKey !== prevPeekKey.current && config?.peek !== false) runPeek();
133
- prevPeekKey.current = peekKey;
134
- }, [peekKey, runPeek, config]);
135
-
136
- /**
137
- * New conversation, guarded. Clearing the session clears the ledger — the
138
- * ONLY undo surface — while the agent's changes stay live in the app, so
139
- * with reversible changes outstanding the user chooses their fate first.
140
- */
141
- const confirmReset = useCallback(() => {
142
- const ledger = askBuoyStore.getLedger();
143
- const reversible = ledger?.list().filter(e => !e.undoneAt && isReversible(e.effect)).length ?? 0;
144
- if (reversible === 0) {
145
- reset();
146
- return;
147
- }
148
- Alert.alert("Undo changes first?", `Ask Buoy made ${reversible} change${reversible === 1 ? "" : "s"} that can still be undone. Clearing the conversation loses the only automatic undo for ${reversible === 1 ? "it" : "them"}.`, [{
149
- text: "Undo, then clear",
150
- onPress: () => {
151
- void (async () => {
152
- const l = askBuoyStore.getLedger();
153
- if (l) await l.revertAll(dispatchToolAction);
154
- reset();
155
- })();
156
- }
157
- }, {
158
- text: "Clear anyway",
159
- style: "destructive",
160
- onPress: reset
161
- }, {
162
- text: "Cancel",
163
- style: "cancel"
164
- }]);
165
- }, [reset]);
166
-
167
- // The header's live status: the title of whichever tool call is in flight.
168
- const activeLabel = useMemo(() => {
169
- const last = state.messages[state.messages.length - 1];
170
- if (!last || last.role !== "assistant" || !last.streaming) return null;
171
- return last.toolCalls.find(c => c.status === "running")?.label ?? null;
172
- }, [state.messages]);
173
-
174
- /**
175
- * What a block can do in THIS host. `minimize` collapses the sheet to the
176
- * rail so the user can look at the app (the peek chip). `openTool` has no
177
- * seam yet, so those buttons don't render here rather than render dead.
178
- */
179
- const blockHandlers = useMemo(() => ({
180
- answer,
181
- runAction: (action, blockId) => {
182
- if (action.minimize) {
183
- onMinimize?.({
184
- mode: "bottomSheet"
185
- });
186
- return;
187
- }
188
- return runAction(action, blockId);
189
- },
190
- answered: state.answers,
191
- actionState: state.actionState,
192
- busy: state.busy,
193
- supports: {
194
- openTool: false,
195
- minimize: !!onMinimize,
196
- dispatch: true
197
- }
198
- }), [answer, runAction, onMinimize, state.answers, state.actionState, state.busy]);
199
-
200
- // The last assistant turn carrying an error is the only "it went wrong"
201
- // signal the header can read; it clears as soon as the next send starts.
202
- const lastMessage = state.messages[state.messages.length - 1];
203
- const failed = !state.busy && lastMessage?.role === "assistant" && !!lastMessage.error;
204
- const header = /*#__PURE__*/_jsx(AskBuoyHeader, {
205
- configured: configured,
206
- busy: state.busy,
207
- failed: failed,
208
- activeLabel: activeLabel,
209
- toolCount: toolCount,
210
- hasMessages: state.messages.length > 0,
211
- onBack: onBack,
212
- onReset: confirmReset
213
- });
214
- return /*#__PURE__*/_jsx(JsModal, {
215
- visible: visible,
216
- onClose: onClose
217
- // The message list is the only scroller. JsModal's default wrapper is
218
- // flexGrow:1, which makes a nested flex:1 scroller resolve against the
219
- // content and never scroll at all.
220
- ,
221
- disableScrollWrapper: true
222
- // ToolBackground is an animated star field. A chat re-renders on every
223
- // streamed token; two continuous animations competing is a dropped
224
- // frame budget for no benefit.
225
- ,
226
- background: false,
227
- initialHeight: 560,
228
- animatedHeight: sheetHeight,
229
- header: {
230
- customContent: header,
231
- showToggleButton: false
232
- },
233
- onBack: onBack,
234
- onMinimize: onMinimize,
235
- persistenceKey: persistenceKey ?? "buoy-ask-buoy",
236
- enablePersistence: true,
237
- children: /*#__PURE__*/_jsx(BlockHandlersProvider, {
238
- value: blockHandlers,
239
- children: /*#__PURE__*/_jsxs(View, {
240
- style: [styles.root, {
241
- paddingBottom: insets.bottom
242
- }],
243
- children: [/*#__PURE__*/_jsx(ChangesBar, {
244
- ledger: askBuoyStore.getLedger(),
245
- onUndoAll: undoAll,
246
- expanded: changesOpen,
247
- onToggle: toggleChanges
248
- }), state.notice && /*#__PURE__*/_jsxs(View, {
249
- style: styles.notice,
250
- testID: "buoy-ask-buoy-notice",
251
- children: [/*#__PURE__*/_jsx(Info, {
252
- size: 14,
253
- color: night.color.info
254
- }), /*#__PURE__*/_jsx(Text, {
255
- style: styles.noticeText,
256
- children: state.notice
257
- })]
258
- }), /*#__PURE__*/_jsx(KeyboardAvoidingView, {
259
- style: styles.flex
260
- // iOS only: Android's default softwareKeyboardLayoutMode is "resize",
261
- // so the window shrinks and a bottom-anchored view rides up already.
262
- // Padding on both would lift the composer twice.
263
- ,
264
- behavior: Platform.OS === "ios" ? "padding" : undefined,
265
- enabled: Platform.OS === "ios",
266
- keyboardVerticalOffset: insets.bottom,
267
- children: /*#__PURE__*/_jsxs(FeatureGate, {
268
- featureName: "Ask Buoy",
269
- children: [/*#__PURE__*/_jsx(MessageList, {
270
- messages: state.messages,
271
- onRetry: retry,
272
- ListEmptyComponent: /*#__PURE__*/_jsx(EmptyState, {
273
- configured: configured,
274
- onPick: send
275
- })
276
- }), state.pending && /*#__PURE__*/_jsx(ApprovalCard, {
277
- pending: state.pending,
278
- onAnswer: approve
279
- }), /*#__PURE__*/_jsx(Composer, {
280
- onSend: send,
281
- onStop: stop,
282
- busy: state.busy,
283
- disabled: !configured,
284
- placeholder: state.queued ? "Queued — sends when this turn finishes" : state.awaitingBlockId ? "Pick an option above, or type…" : undefined
285
- })]
286
- })
287
- })]
288
- })
289
- })
290
- });
291
- }
292
- const styles = StyleSheet.create({
293
- // Transparent or it paints over the sheet's own chrome — the convention is
294
- // repeated verbatim across every Buoy tool body.
295
- root: {
296
- flex: 1,
297
- backgroundColor: "transparent"
298
- },
299
- flex: {
300
- flex: 1
301
- },
302
- notice: {
303
- flexDirection: "row",
304
- alignItems: "flex-start",
305
- gap: 8,
306
- paddingHorizontal: night.gutter,
307
- paddingVertical: 10,
308
- backgroundColor: night.color.infoSoft
309
- },
310
- noticeText: {
311
- flex: 1,
312
- color: night.color.text,
313
- fontSize: night.font.caption,
314
- lineHeight: 18
315
- }
316
- });
317
- //# sourceMappingURL=AskBuoyModal.js.map
1
+ "use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Alert,Animated,KeyboardAvoidingView,Platform,StyleSheet,Text,View}from"react-native";import{isReversible}from"@buoy-gg/agent-core";import{dispatchToolAction,FeatureGate,Info,JsModal,night,useSafeAreaInsets}from"@buoy-gg/shared-ui";import{BlockHandlersProvider}from"../blocks";import{ApprovalCard}from"./ApprovalCard";import{ChangesBar}from"./ChangesBar";import{Composer}from"./Composer";import{AskBuoyHeader}from"./AskBuoyHeader";import{EmptyState}from"./EmptyState";import{MessageList}from"./MessageList";import{askBuoyStore}from"../store/askBuoyStore";import{useAskBuoy}from"../store/useAskBuoy";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function AskBuoyModal({visible:e,onClose:t,onBack:o,onMinimize:s,persistenceKey:n,config:r}){const{state:a,send:i,stop:l,reset:u,approve:c,retry:d,answer:m,runAction:g,configured:f,toolCount:p}=useAskBuoy(r),[y,h]=useState(!1),b=useSafeAreaInsets({minBottom:16}),k=useCallback(()=>{const e=askBuoyStore.getLedger();e&&(async()=>{const t=await e.revertAll(dispatchToolAction);if(0===t.failed.length)return void askBuoyStore.setNotice(null);const o=t.failed.map(e=>`${e.label} (${e.error})`).join("; ");askBuoyStore.setNotice(`Couldn't undo ${t.failed.length} change${1===t.failed.length?"":"s"} — ${o}`)})()},[]),x=useCallback(()=>h(e=>!e),[]),A=useRef(new Animated.Value(560)).current,S=useRef(!1),B=useCallback(()=>{S.current||(S.current=!0,A.stopAnimation(e=>{const t="number"==typeof e&&e>200?e:560;Animated.timing(A,{toValue:120,duration:220,useNativeDriver:!1}).start(()=>{setTimeout(()=>{Animated.spring(A,{toValue:t,friction:9,useNativeDriver:!1}).start(()=>{S.current=!1})},2500)})}))},[A]),v=useMemo(()=>{const e=a.messages[a.messages.length-1];if(!e||"assistant"!==e.role)return"";const t=e.blocks.filter(e=>"peek"===e.block.kind).length;return t>0?`${e.id}:${t}`:""},[a.messages]),C=useRef("");useEffect(()=>{v&&v!==C.current&&!1!==r?.peek&&B(),C.current=v},[v,B,r]);const j=useCallback(()=>{const e=askBuoyStore.getLedger(),t=e?.list().filter(e=>!e.undoneAt&&isReversible(e.effect)).length??0;0!==t?Alert.alert("Undo changes first?",`Ask Buoy made ${t} change${1===t?"":"s"} that can still be undone. Clearing the conversation loses the only automatic undo for ${1===t?"it":"them"}.`,[{text:"Undo, then clear",onPress:()=>{(async()=>{const e=askBuoyStore.getLedger();e&&await e.revertAll(dispatchToolAction),u()})()}},{text:"Clear anyway",style:"destructive",onPress:u},{text:"Cancel",style:"cancel"}]):u()},[u]),w=useMemo(()=>{const e=a.messages[a.messages.length-1];return e&&"assistant"===e.role&&e.streaming?e.toolCalls.find(e=>"running"===e.status)?.label??null:null},[a.messages]),_=useMemo(()=>({answer:m,runAction:(e,t)=>{if(!e.minimize)return g(e,t);s?.({mode:"bottomSheet"})},answered:a.answers,actionState:a.actionState,busy:a.busy,supports:{openTool:!1,minimize:!!s,dispatch:!0}}),[m,g,s,a.answers,a.actionState,a.busy]),M=a.messages[a.messages.length-1],T=!a.busy&&"assistant"===M?.role&&!!M.error,P=_jsx(AskBuoyHeader,{configured:f,busy:a.busy,failed:T,activeLabel:w,toolCount:p,hasMessages:a.messages.length>0,onBack:o,onReset:j});return _jsx(JsModal,{visible:e,onClose:t,disableScrollWrapper:!0,background:!1,initialHeight:560,animatedHeight:A,header:{customContent:P,showToggleButton:!1},onBack:o,onMinimize:s,persistenceKey:n??"buoy-ask-buoy",enablePersistence:!0,children:_jsx(BlockHandlersProvider,{value:_,children:_jsxs(View,{style:[styles.root,{paddingBottom:b.bottom}],children:[_jsx(ChangesBar,{ledger:askBuoyStore.getLedger(),onUndoAll:k,expanded:y,onToggle:x}),a.notice&&_jsxs(View,{style:styles.notice,testID:"buoy-ask-buoy-notice",children:[_jsx(Info,{size:14,color:night.color.info}),_jsx(Text,{style:styles.noticeText,children:a.notice})]}),_jsx(KeyboardAvoidingView,{style:styles.flex,behavior:"ios"===Platform.OS?"padding":void 0,enabled:"ios"===Platform.OS,keyboardVerticalOffset:b.bottom,children:_jsxs(FeatureGate,{featureName:"Ask Buoy",children:[_jsx(MessageList,{messages:a.messages,onRetry:d,ListEmptyComponent:_jsx(EmptyState,{configured:f,onPick:i})}),a.pending&&_jsx(ApprovalCard,{pending:a.pending,onAnswer:c}),_jsx(Composer,{onSend:i,onStop:l,busy:a.busy,disabled:!f,placeholder:a.queued?"Queued — sends when this turn finishes":a.awaitingBlockId?"Pick an option above, or type…":void 0})]})})]})})})}const styles=StyleSheet.create({root:{flex:1,backgroundColor:"transparent"},flex:{flex:1},notice:{flexDirection:"row",alignItems:"flex-start",gap:8,paddingHorizontal:night.gutter,paddingVertical:10,backgroundColor:night.color.infoSoft},noticeText:{flex:1,color:night.color.text,fontSize:night.font.caption,lineHeight:18}});
@@ -1,206 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * "The agent changed things" — the bar, and the list behind it.
5
- *
6
- * Ask Buoy mutates without asking, so this is what keeps the user in control:
7
- * if reality has been bent, you can never not know it. Same principle as the
8
- * impersonate and override banners.
9
- *
10
- * It counts REVERSIBLE and ONE-SHOT effects separately, which is the one place
11
- * this deliberately differs from the Scenarios banner. That one folds
12
- * transients into a single "N changes" total and then silently no-ops on them
13
- * at revert — a user who taps Undo, sees "4 changes", and finds three of them
14
- * still in place learns not to trust the bar. Better to say "1 undoable ·
15
- * 1 permanent" and be believed.
16
- */
17
- import { useSyncExternalStore } from "react";
18
- import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
19
- import { ChevronDown, ChevronRight, night } from "@buoy-gg/shared-ui";
20
- import { isReversible } from "@buoy-gg/agent-core";
21
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
- const EMPTY = [];
23
- function useLedgerEntries(ledger) {
24
- return useSyncExternalStore(fn => ledger?.subscribe(fn) ?? (() => {}), () => ledger?.list() ?? EMPTY, () => ledger?.list() ?? EMPTY);
25
- }
26
- export function ChangesBar({
27
- ledger,
28
- onUndoAll,
29
- expanded,
30
- onToggle
31
- }) {
32
- const entries = useLedgerEntries(ledger);
33
- const outstanding = entries.filter(e => !e.undoneAt);
34
- // Transients — navigation, taps — are one-shot ACTIONS, not changes. Counting
35
- // them here read "Changed this app · 9 permanent" after a read-only tour,
36
- // which is the bar lying in the alarming direction. They still appear in the
37
- // expanded panel's footnote, because honesty, but they raise no banner.
38
- const changes = outstanding.filter(e => e.effect.kind !== "transient");
39
- if (changes.length === 0) return null;
40
- const reversible = changes.filter(e => isReversible(e.effect));
41
- const permanent = changes.length - reversible.length;
42
- const transients = outstanding.length - changes.length;
43
- const Chevron = expanded ? ChevronDown : ChevronRight;
44
- const counts = [reversible.length > 0 ? `${reversible.length} undoable` : null, permanent > 0 ? `${permanent} permanent` : null].filter(Boolean).join(" · ");
45
- return /*#__PURE__*/_jsxs(View, {
46
- style: styles.wrap,
47
- children: [/*#__PURE__*/_jsxs(Pressable, {
48
- testID: "buoy-ask-buoy-changes-bar",
49
- accessibilityRole: "button",
50
- accessibilityState: {
51
- expanded
52
- },
53
- onPress: onToggle,
54
- style: styles.bar,
55
- children: [/*#__PURE__*/_jsx(View, {
56
- style: styles.dot
57
- }), /*#__PURE__*/_jsx(Text, {
58
- style: styles.summary,
59
- numberOfLines: 1,
60
- children: "Changed this app"
61
- }), /*#__PURE__*/_jsx(Text, {
62
- style: styles.counts,
63
- numberOfLines: 1,
64
- children: counts
65
- }), /*#__PURE__*/_jsx(Chevron, {
66
- size: 12,
67
- color: night.color.textSecondary
68
- })]
69
- }), expanded && /*#__PURE__*/_jsxs(View, {
70
- style: styles.panel,
71
- children: [/*#__PURE__*/_jsxs(ScrollView, {
72
- style: styles.panelScroll,
73
- testID: "buoy-ask-buoy-changes-scroll",
74
- keyboardShouldPersistTaps: "handled",
75
- children: [changes.map(entry => {
76
- const oneOff = !isReversible(entry.effect);
77
- return /*#__PURE__*/_jsxs(View, {
78
- style: styles.row,
79
- children: [/*#__PURE__*/_jsx(Text, {
80
- style: styles.rowLabel,
81
- children: entry.effect.label
82
- }), /*#__PURE__*/_jsx(Text, {
83
- style: [styles.rowTag, oneOff && styles.rowTagMuted],
84
- children: oneOff ? "Permanent" : "Undoable"
85
- })]
86
- }, entry.id);
87
- }), transients > 0 && /*#__PURE__*/_jsx(View, {
88
- style: styles.row,
89
- children: /*#__PURE__*/_jsxs(Text, {
90
- style: [styles.rowLabel, styles.rowLabelMuted],
91
- children: ["Also did ", transients, " one-shot action", transients === 1 ? "" : "s", " (navigation, taps) \u2014 nothing to undo."]
92
- })
93
- })]
94
- }), /*#__PURE__*/_jsxs(View, {
95
- style: styles.footer,
96
- children: [reversible.length > 0 && /*#__PURE__*/_jsx(Pressable, {
97
- testID: "buoy-ask-buoy-undo-all",
98
- accessibilityRole: "button",
99
- onPress: onUndoAll,
100
- style: ({
101
- pressed
102
- }) => [styles.undo, pressed && styles.pressed],
103
- children: /*#__PURE__*/_jsxs(Text, {
104
- style: styles.undoText,
105
- children: ["Undo ", reversible.length, " change", reversible.length === 1 ? "" : "s"]
106
- })
107
- }), permanent > 0 && /*#__PURE__*/_jsx(Text, {
108
- style: styles.footnote,
109
- children: "Permanent changes can't be undone from here."
110
- })]
111
- })]
112
- })]
113
- });
114
- }
115
- const styles = StyleSheet.create({
116
- wrap: {
117
- borderBottomWidth: StyleSheet.hairlineWidth,
118
- borderBottomColor: night.color.border,
119
- backgroundColor: night.color.warningSoft
120
- },
121
- bar: {
122
- flexDirection: "row",
123
- alignItems: "center",
124
- gap: 8,
125
- paddingHorizontal: night.gutter,
126
- paddingVertical: 10
127
- },
128
- dot: {
129
- width: 7,
130
- height: 7,
131
- borderRadius: 4,
132
- backgroundColor: night.color.warning
133
- },
134
- summary: {
135
- color: night.color.text,
136
- fontSize: night.font.caption,
137
- fontWeight: "600"
138
- },
139
- counts: {
140
- flex: 1,
141
- color: night.color.textSecondary,
142
- fontSize: night.font.caption
143
- },
144
- panel: {
145
- paddingHorizontal: night.gutter,
146
- paddingBottom: 12,
147
- gap: 10
148
- },
149
- panelScroll: {
150
- maxHeight: 180
151
- },
152
- row: {
153
- flexDirection: "row",
154
- alignItems: "flex-start",
155
- gap: 10,
156
- paddingVertical: 8,
157
- borderTopWidth: StyleSheet.hairlineWidth,
158
- borderTopColor: night.color.separator
159
- },
160
- rowLabel: {
161
- flex: 1,
162
- color: night.color.text,
163
- fontSize: night.font.caption,
164
- lineHeight: 18
165
- },
166
- rowTag: {
167
- color: night.color.accent,
168
- fontSize: night.font.micro,
169
- fontWeight: "600",
170
- letterSpacing: 0.6,
171
- textTransform: "uppercase",
172
- paddingTop: 2
173
- },
174
- rowTagMuted: {
175
- color: night.color.textTertiary
176
- },
177
- rowLabelMuted: {
178
- color: night.color.textTertiary
179
- },
180
- footer: {
181
- flexDirection: "row",
182
- alignItems: "center",
183
- gap: 12,
184
- flexWrap: "wrap"
185
- },
186
- undo: {
187
- paddingHorizontal: 14,
188
- paddingVertical: 8,
189
- borderRadius: night.radius.row,
190
- backgroundColor: night.color.button
191
- },
192
- undoText: {
193
- color: night.color.accent,
194
- fontSize: night.font.caption,
195
- fontWeight: "600"
196
- },
197
- footnote: {
198
- flex: 1,
199
- color: night.color.textTertiary,
200
- fontSize: night.font.micro
201
- },
202
- pressed: {
203
- opacity: 0.7
204
- }
205
- });
206
- //# sourceMappingURL=ChangesBar.js.map
1
+ "use strict";import{useSyncExternalStore}from"react";import{Pressable,ScrollView,StyleSheet,Text,View}from"react-native";import{ChevronDown,ChevronRight,night}from"@buoy-gg/shared-ui";import{isReversible}from"@buoy-gg/agent-core";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const EMPTY=[];function useLedgerEntries(e){return useSyncExternalStore(t=>e?.subscribe(t)??(()=>{}),()=>e?.list()??EMPTY,()=>e?.list()??EMPTY)}export function ChangesBar({ledger:e,onUndoAll:t,expanded:o,onToggle:n}){const r=useLedgerEntries(e).filter(e=>!e.undoneAt),s=r.filter(e=>"transient"!==e.effect.kind);if(0===s.length)return null;const l=s.filter(e=>isReversible(e.effect)),i=s.length-l.length,a=r.length-s.length,c=o?ChevronDown:ChevronRight,d=[l.length>0?`${l.length} undoable`:null,i>0?`${i} permanent`:null].filter(Boolean).join(" · ");return _jsxs(View,{style:styles.wrap,children:[_jsxs(Pressable,{testID:"buoy-ask-buoy-changes-bar",accessibilityRole:"button",accessibilityState:{expanded:o},onPress:n,style:styles.bar,children:[_jsx(View,{style:styles.dot}),_jsx(Text,{style:styles.summary,numberOfLines:1,children:"Changed this app"}),_jsx(Text,{style:styles.counts,numberOfLines:1,children:d}),_jsx(c,{size:12,color:night.color.textSecondary})]}),o&&_jsxs(View,{style:styles.panel,children:[_jsxs(ScrollView,{style:styles.panelScroll,testID:"buoy-ask-buoy-changes-scroll",keyboardShouldPersistTaps:"handled",children:[s.map(e=>{const t=!isReversible(e.effect);return _jsxs(View,{style:styles.row,children:[_jsx(Text,{style:styles.rowLabel,children:e.effect.label}),_jsx(Text,{style:[styles.rowTag,t&&styles.rowTagMuted],children:t?"Permanent":"Undoable"})]},e.id)}),a>0&&_jsx(View,{style:styles.row,children:_jsxs(Text,{style:[styles.rowLabel,styles.rowLabelMuted],children:["Also did ",a," one-shot action",1===a?"":"s"," (navigation, taps) — nothing to undo."]})})]}),_jsxs(View,{style:styles.footer,children:[l.length>0&&_jsx(Pressable,{testID:"buoy-ask-buoy-undo-all",accessibilityRole:"button",onPress:t,style:({pressed:e})=>[styles.undo,e&&styles.pressed],children:_jsxs(Text,{style:styles.undoText,children:["Undo ",l.length," change",1===l.length?"":"s"]})}),i>0&&_jsx(Text,{style:styles.footnote,children:"Permanent changes can't be undone from here."})]})]})]})}const styles=StyleSheet.create({wrap:{borderBottomWidth:StyleSheet.hairlineWidth,borderBottomColor:night.color.border,backgroundColor:night.color.warningSoft},bar:{flexDirection:"row",alignItems:"center",gap:8,paddingHorizontal:night.gutter,paddingVertical:10},dot:{width:7,height:7,borderRadius:4,backgroundColor:night.color.warning},summary:{color:night.color.text,fontSize:night.font.caption,fontWeight:"600"},counts:{flex:1,color:night.color.textSecondary,fontSize:night.font.caption},panel:{paddingHorizontal:night.gutter,paddingBottom:12,gap:10},panelScroll:{maxHeight:180},row:{flexDirection:"row",alignItems:"flex-start",gap:10,paddingVertical:8,borderTopWidth:StyleSheet.hairlineWidth,borderTopColor:night.color.separator},rowLabel:{flex:1,color:night.color.text,fontSize:night.font.caption,lineHeight:18},rowTag:{color:night.color.accent,fontSize:night.font.micro,fontWeight:"600",letterSpacing:.6,textTransform:"uppercase",paddingTop:2},rowTagMuted:{color:night.color.textTertiary},rowLabelMuted:{color:night.color.textTertiary},footer:{flexDirection:"row",alignItems:"center",gap:12,flexWrap:"wrap"},undo:{paddingHorizontal:14,paddingVertical:8,borderRadius:night.radius.row,backgroundColor:night.color.button},undoText:{color:night.color.accent,fontSize:night.font.caption,fontWeight:"600"},footnote:{flex:1,color:night.color.textTertiary,fontSize:night.font.micro},pressed:{opacity:.7}});