@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.
- package/README.md +1 -1
- package/lib/commonjs/blocks/AskBlocks.js +1 -338
- package/lib/commonjs/blocks/BlockRenderer.js +1 -250
- package/lib/commonjs/blocks/ChromePrototypes.js +1 -514
- package/lib/commonjs/blocks/DataBlocks.js +1 -545
- package/lib/commonjs/blocks/ExtraBlocks.js +1 -1821
- package/lib/commonjs/blocks/MediaBlocks.js +1 -140
- package/lib/commonjs/blocks/ReceiptBlocks.js +1 -596
- package/lib/commonjs/blocks/context.js +1 -42
- package/lib/commonjs/blocks/icons.js +1 -96
- package/lib/commonjs/blocks/index.js +1 -95
- package/lib/commonjs/blocks/primitives.js +1 -312
- package/lib/commonjs/blocks/primitivesIndex.js +1 -56
- package/lib/commonjs/components/ApprovalCard.js +1 -140
- package/lib/commonjs/components/AskBuoyHeader.js +1 -127
- package/lib/commonjs/components/AskBuoyIcon.js +1 -19
- package/lib/commonjs/components/AskBuoyModal.js +1 -322
- package/lib/commonjs/components/ChangesBar.js +1 -211
- package/lib/commonjs/components/Composer.js +1 -175
- package/lib/commonjs/components/EmptyState.js +1 -154
- package/lib/commonjs/components/Markdown.js +1 -252
- package/lib/commonjs/components/MessageList.js +1 -648
- package/lib/commonjs/components/TypingDots.js +1 -63
- package/lib/commonjs/index.js +1 -205
- package/lib/commonjs/preset.js +1 -90
- package/lib/commonjs/store/askBuoyStore.js +1 -279
- package/lib/commonjs/store/useAskBuoy.js +1 -299
- package/lib/commonjs/sync/askBuoySyncAdapter.js +1 -119
- package/lib/commonjs/sync/askBuoySyncAdapter.test.js +1 -136
- package/lib/commonjs/sync/wire.js +1 -58
- package/lib/commonjs/types.js +1 -6
- package/lib/module/blocks/AskBlocks.js +1 -331
- package/lib/module/blocks/BlockRenderer.js +1 -245
- package/lib/module/blocks/ChromePrototypes.js +1 -503
- package/lib/module/blocks/DataBlocks.js +1 -532
- package/lib/module/blocks/ExtraBlocks.js +1 -1794
- package/lib/module/blocks/MediaBlocks.js +1 -135
- package/lib/module/blocks/ReceiptBlocks.js +1 -584
- package/lib/module/blocks/context.js +1 -35
- package/lib/module/blocks/icons.js +1 -91
- package/lib/module/blocks/index.js +1 -8
- package/lib/module/blocks/primitives.js +1 -301
- package/lib/module/blocks/primitivesIndex.js +1 -5
- package/lib/module/components/ApprovalCard.js +1 -135
- package/lib/module/components/AskBuoyHeader.js +1 -124
- package/lib/module/components/AskBuoyIcon.js +1 -8
- package/lib/module/components/AskBuoyModal.js +1 -317
- package/lib/module/components/ChangesBar.js +1 -206
- package/lib/module/components/Composer.js +1 -170
- package/lib/module/components/EmptyState.js +1 -149
- package/lib/module/components/Markdown.js +1 -246
- package/lib/module/components/MessageList.js +1 -642
- package/lib/module/components/TypingDots.js +1 -58
- package/lib/module/index.js +1 -29
- package/lib/module/preset.js +1 -73
- package/lib/module/store/askBuoyStore.js +1 -275
- package/lib/module/store/useAskBuoy.js +1 -293
- package/lib/module/sync/askBuoySyncAdapter.js +1 -114
- package/lib/module/sync/askBuoySyncAdapter.test.js +1 -135
- package/lib/module/sync/wire.js +1 -47
- package/lib/module/types.js +1 -4
- package/lib/typescript/preset.d.ts +1 -1
- package/package.json +8 -8
- package/lib/commonjs/blocks/AskBlocks.js.map +0 -1
- package/lib/commonjs/blocks/BlockRenderer.js.map +0 -1
- package/lib/commonjs/blocks/ChromePrototypes.js.map +0 -1
- package/lib/commonjs/blocks/DataBlocks.js.map +0 -1
- package/lib/commonjs/blocks/ExtraBlocks.js.map +0 -1
- package/lib/commonjs/blocks/MediaBlocks.js.map +0 -1
- package/lib/commonjs/blocks/ReceiptBlocks.js.map +0 -1
- package/lib/commonjs/blocks/context.js.map +0 -1
- package/lib/commonjs/blocks/icons.js.map +0 -1
- package/lib/commonjs/blocks/index.js.map +0 -1
- package/lib/commonjs/blocks/primitives.js.map +0 -1
- package/lib/commonjs/blocks/primitivesIndex.js.map +0 -1
- package/lib/commonjs/components/ApprovalCard.js.map +0 -1
- package/lib/commonjs/components/AskBuoyHeader.js.map +0 -1
- package/lib/commonjs/components/AskBuoyIcon.js.map +0 -1
- package/lib/commonjs/components/AskBuoyModal.js.map +0 -1
- package/lib/commonjs/components/ChangesBar.js.map +0 -1
- package/lib/commonjs/components/Composer.js.map +0 -1
- package/lib/commonjs/components/EmptyState.js.map +0 -1
- package/lib/commonjs/components/Markdown.js.map +0 -1
- package/lib/commonjs/components/MessageList.js.map +0 -1
- package/lib/commonjs/components/TypingDots.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/preset.js.map +0 -1
- package/lib/commonjs/store/askBuoyStore.js.map +0 -1
- package/lib/commonjs/store/useAskBuoy.js.map +0 -1
- package/lib/commonjs/sync/askBuoySyncAdapter.js.map +0 -1
- package/lib/commonjs/sync/askBuoySyncAdapter.test.js.map +0 -1
- package/lib/commonjs/sync/wire.js.map +0 -1
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/blocks/AskBlocks.js.map +0 -1
- package/lib/module/blocks/BlockRenderer.js.map +0 -1
- package/lib/module/blocks/ChromePrototypes.js.map +0 -1
- package/lib/module/blocks/DataBlocks.js.map +0 -1
- package/lib/module/blocks/ExtraBlocks.js.map +0 -1
- package/lib/module/blocks/MediaBlocks.js.map +0 -1
- package/lib/module/blocks/ReceiptBlocks.js.map +0 -1
- package/lib/module/blocks/context.js.map +0 -1
- package/lib/module/blocks/icons.js.map +0 -1
- package/lib/module/blocks/index.js.map +0 -1
- package/lib/module/blocks/primitives.js.map +0 -1
- package/lib/module/blocks/primitivesIndex.js.map +0 -1
- package/lib/module/components/ApprovalCard.js.map +0 -1
- package/lib/module/components/AskBuoyHeader.js.map +0 -1
- package/lib/module/components/AskBuoyIcon.js.map +0 -1
- package/lib/module/components/AskBuoyModal.js.map +0 -1
- package/lib/module/components/ChangesBar.js.map +0 -1
- package/lib/module/components/Composer.js.map +0 -1
- package/lib/module/components/EmptyState.js.map +0 -1
- package/lib/module/components/Markdown.js.map +0 -1
- package/lib/module/components/MessageList.js.map +0 -1
- package/lib/module/components/TypingDots.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/preset.js.map +0 -1
- package/lib/module/store/askBuoyStore.js.map +0 -1
- package/lib/module/store/useAskBuoy.js.map +0 -1
- package/lib/module/sync/askBuoySyncAdapter.js.map +0 -1
- package/lib/module/sync/askBuoySyncAdapter.test.js.map +0 -1
- package/lib/module/sync/wire.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/blocks/AskBlocks.d.ts.map +0 -1
- package/lib/typescript/blocks/BlockRenderer.d.ts.map +0 -1
- package/lib/typescript/blocks/ChromePrototypes.d.ts.map +0 -1
- package/lib/typescript/blocks/DataBlocks.d.ts.map +0 -1
- package/lib/typescript/blocks/ExtraBlocks.d.ts.map +0 -1
- package/lib/typescript/blocks/MediaBlocks.d.ts.map +0 -1
- package/lib/typescript/blocks/ReceiptBlocks.d.ts.map +0 -1
- package/lib/typescript/blocks/context.d.ts.map +0 -1
- package/lib/typescript/blocks/icons.d.ts.map +0 -1
- package/lib/typescript/blocks/index.d.ts.map +0 -1
- package/lib/typescript/blocks/primitives.d.ts.map +0 -1
- package/lib/typescript/blocks/primitivesIndex.d.ts.map +0 -1
- package/lib/typescript/components/ApprovalCard.d.ts.map +0 -1
- package/lib/typescript/components/AskBuoyHeader.d.ts.map +0 -1
- package/lib/typescript/components/AskBuoyIcon.d.ts.map +0 -1
- package/lib/typescript/components/AskBuoyModal.d.ts.map +0 -1
- package/lib/typescript/components/ChangesBar.d.ts.map +0 -1
- package/lib/typescript/components/Composer.d.ts.map +0 -1
- package/lib/typescript/components/EmptyState.d.ts.map +0 -1
- package/lib/typescript/components/Markdown.d.ts.map +0 -1
- package/lib/typescript/components/MessageList.d.ts.map +0 -1
- package/lib/typescript/components/TypingDots.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/store/askBuoyStore.d.ts.map +0 -1
- package/lib/typescript/store/useAskBuoy.d.ts.map +0 -1
- package/lib/typescript/sync/askBuoySyncAdapter.d.ts.map +0 -1
- package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts.map +0 -1
- package/lib/typescript/sync/wire.d.ts.map +0 -1
- package/lib/typescript/types.d.ts.map +0 -1
|
@@ -1,299 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useAskBuoy=useAskBuoy,exports.useAskBuoyState=useAskBuoyState;var _react=require("react"),_reactNative=require("react-native"),_sharedUi=require("@buoy-gg/shared-ui"),_agentCore=require("@buoy-gg/agent-core"),_askBuoyStore=require("./askBuoyStore");const isRelease="undefined"!=typeof __DEV__&&!__DEV__;function useAskBuoyState(){return(0,_react.useSyncExternalStore)(_askBuoyStore.askBuoyStore.subscribe,_askBuoyStore.askBuoyStore.getState,_askBuoyStore.askBuoyStore.getState)}function useAskBuoy(e){const o=useAskBuoyState(),t=(0,_react.useRef)(null),r=(0,_react.useRef)(null),s=(0,_react.useRef)(e);s.current=e;const a=!!e?.endpoint&&!!e?.model,n=(0,_react.useMemo)(()=>{try{const e=(0,_sharedUi.listToolActions)();for(const o of(0,_sharedUi.listSnapshotToolIds)())e[o]||(e[o]=[]),e[o].includes(_agentCore.SNAPSHOT_ACTION)||(e[o]=[_agentCore.SNAPSHOT_ACTION,...e[o]]);return e}catch{return{}}},[]),u=Object.keys(n).sort().join(",");(0,_react.useEffect)(()=>{if(_askBuoyStore.askBuoyStore.setConfigured(a),!a||!e)return t.current=null,void _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.");const o=e.protocol??"anthropic";isRelease&&e.apiKey?_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."):"anthropic"===o&&/^https?:\/\/api\.openai\.com\//i.test(e.endpoint)?_askBuoyStore.askBuoyStore.setNotice('This endpoint is api.openai.com but the protocol is "anthropic". Set protocol: "openai" in the askBuoy config.'):"openai"===o&&/^https?:\/\/api\.anthropic\.com\//i.test(e.endpoint)?_askBuoyStore.askBuoyStore.setNotice('This endpoint is api.anthropic.com but the protocol is "openai". Remove protocol or set it to "anthropic".'):_askBuoyStore.askBuoyStore.setNotice(null);const r=[e.endpoint,e.protocol??"anthropic",e.model].join("|"),s=_askBuoyStore.askBuoyStore.getHeldSession();if(s&&s.signature===r)return t.current=s.session,s.session.setAvailableActions(n),void _askBuoyStore.askBuoyStore.setLedger(s.session.ledger);const u=(0,_agentCore.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?[..._agentCore.CATALOG,...e.tools]:void 0,dispatch:_sharedUi.dispatchToolAction,readSnapshot:_sharedUi.readToolSnapshot,availableActions:n,policy:e.policy,context:e.context,isRelease:isRelease,appName:e.appName,platform:_reactNative.Platform.OS,requestApproval:e=>_askBuoyStore.askBuoyStore.askApproval(e)});t.current=u,_askBuoyStore.askBuoyStore.holdSession(u,r),_askBuoyStore.askBuoyStore.setLedger(u.ledger);let i=!1;return(0,_sharedUi.waitForToolRegistry)().then(e=>{e&&!i&&u.prime()}),()=>{i=!0}},[a,e,n,u]);const i=(0,_react.useCallback)(e=>{const o=t.current;if(!o)return;_askBuoyStore.askBuoyStore.beginTurn();const a=_askBuoyStore.askBuoyStore.startAssistant(),n=new AbortController;r.current=n;const u=s.current?.onEvent;(async()=>{try{for await(const t of o.send(e,n.signal))if(_askBuoyStore.askBuoyStore.applyEvent(a,t),u)try{u(t)}catch{}}catch(e){_askBuoyStore.askBuoyStore.applyEvent(a,{type:"error",message:e instanceof Error?e.message:"Something went wrong talking to your AI endpoint."})}finally{_askBuoyStore.askBuoyStore.finishAssistant(a),r.current=null}})()},[]),c=(0,_react.useCallback)(e=>{const o=e.trim();if(!t.current||!o)return;if(_askBuoyStore.askBuoyStore.getState().busy)return void _askBuoyStore.askBuoyStore.setQueued(o);const r=_askBuoyStore.askBuoyStore.getState().awaitingBlockId;r&&_askBuoyStore.askBuoyStore.recordAnswer({blockId:r,kind:"skipped"}),_askBuoyStore.askBuoyStore.addUser(o),i(o)},[i]),y=(0,_react.useCallback)(()=>{const{messages:e,busy:o}=_askBuoyStore.askBuoyStore.getState();if(o||!t.current)return;const r=[...e].reverse().find(e=>"user"===e.role);if(!r)return;const s=e[e.length-1];s&&"assistant"===s.role&&s.error&&_askBuoyStore.askBuoyStore.removeMessage(s.id),i(r.text)},[i]),l=(0,_react.useCallback)(()=>{_askBuoyStore.askBuoyStore.getState().pending&&_askBuoyStore.askBuoyStore.answerApproval(!1),r.current?.abort(),r.current=null},[]),k=o.queued;(0,_react.useEffect)(()=>{!o.busy&&k&&(_askBuoyStore.askBuoyStore.setQueued(null),c(k))},[o.busy,k,c]);const S=(0,_react.useCallback)(()=>{r.current?.abort(),t.current?.reset(),_askBuoyStore.askBuoyStore.reset()},[]),p=(0,_react.useCallback)(e=>{_askBuoyStore.askBuoyStore.answerApproval(e)},[]),d=(0,_react.useCallback)(e=>{_askBuoyStore.askBuoyStore.recordAnswer(e),c((0,_agentCore.answerToText)(e))},[c]),B=(0,_react.useCallback)(async(o,t)=>{if(o.send)return void c(o.send);if(!o.dispatch)return;const r=`${t}:${o.label}`,s=_askBuoyStore.askBuoyStore.getLedger();if(!s)return void _askBuoyStore.askBuoyStore.setNotice(`${o.label} failed — no active Ask Buoy session.`);_askBuoyStore.askBuoyStore.setActionState(r,"running");const a=await(0,_agentCore.runGatedAction)({toolId:o.dispatch.toolId,action:o.dispatch.action,params:o.dispatch.params??{},dispatch:_sharedUi.dispatchToolAction,ledger:s,policy:e?.policy??{},isRelease:isRelease,catalog:e?.tools?.length?[..._agentCore.CATALOG,...e.tools]:void 0});a.ok?_askBuoyStore.askBuoyStore.setActionState(r,"done"):(_askBuoyStore.askBuoyStore.setActionState(r,"failed"),_askBuoyStore.askBuoyStore.setNotice(`${o.label} failed — ${a.error}`))},[c,e]);return{state:o,send:c,stop:l,reset:S,approve:p,retry:y,answer:d,runAction:B,configured:a,toolCount:Object.keys(n).length}}
|
|
@@ -1,119 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.askBuoySyncAdapter = exports.ASK_BUOY_ADAPTER_VERSION = void 0;
|
|
7
|
-
var _wire = require("./wire");
|
|
8
|
-
var _agentCore = require("@buoy-gg/agent-core");
|
|
9
|
-
var _askBuoyStore = require("../store/askBuoyStore");
|
|
10
|
-
/**
|
|
11
|
-
* The sync adapter, so Buoy Desktop and MCP can see what Ask Buoy is doing.
|
|
12
|
-
*
|
|
13
|
-
* Read-heavy on purpose. There is no `send` action: letting a remote client
|
|
14
|
-
* put words in the agent's mouth would mean anyone who can reach the broker —
|
|
15
|
-
* which has no authentication at all, binds 0.0.0.0, and accepts any client
|
|
16
|
-
* calling itself "Dashboard" — could drive a mutating agent on a tester's
|
|
17
|
-
* device. The chat is initiated on-device, by a person, full stop.
|
|
18
|
-
*
|
|
19
|
-
* `undoAll` IS exposed, because the asymmetry is deliberate: putting things
|
|
20
|
-
* back is the safe direction, and a dev watching from the desktop should be
|
|
21
|
-
* able to clean up a device without walking over to it.
|
|
22
|
-
*
|
|
23
|
-
* The transcript is redacted before it crosses the wire. Action results the
|
|
24
|
-
* agent read can contain storage values and response bodies, and this socket
|
|
25
|
-
* broadcasts to every connected dashboard — it already leaks license keys the
|
|
26
|
-
* same way.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
const ASK_BUOY_ADAPTER_VERSION = exports.ASK_BUOY_ADAPTER_VERSION = 1;
|
|
30
|
-
const askBuoySyncAdapter = exports.askBuoySyncAdapter = {
|
|
31
|
-
version: ASK_BUOY_ADAPTER_VERSION,
|
|
32
|
-
getSnapshot() {
|
|
33
|
-
const state = _askBuoyStore.askBuoyStore.getState();
|
|
34
|
-
const ledger = _askBuoyStore.askBuoyStore.getLedger();
|
|
35
|
-
const entries = ledger?.list() ?? [];
|
|
36
|
-
const outstanding = entries.filter(e => !e.undoneAt);
|
|
37
|
-
return {
|
|
38
|
-
version: ASK_BUOY_ADAPTER_VERSION,
|
|
39
|
-
busy: state.busy,
|
|
40
|
-
configured: state.configured,
|
|
41
|
-
notice: state.notice,
|
|
42
|
-
messageCount: state.messages.length,
|
|
43
|
-
// Only the shape of the conversation, never tool payloads.
|
|
44
|
-
messages: state.messages.map(m => ({
|
|
45
|
-
id: m.id,
|
|
46
|
-
role: m.role,
|
|
47
|
-
text: (0, _wire.redactForWire)(m.text),
|
|
48
|
-
streaming: !!m.streaming,
|
|
49
|
-
toolCalls: m.toolCalls.map(c => ({
|
|
50
|
-
toolId: c.toolId,
|
|
51
|
-
action: c.action,
|
|
52
|
-
status: c.status
|
|
53
|
-
}))
|
|
54
|
-
})),
|
|
55
|
-
// Session token totals, so a desktop/MCP observer can meter cost.
|
|
56
|
-
usage: state.usage,
|
|
57
|
-
pendingApproval: state.pending ? {
|
|
58
|
-
toolId: state.pending.toolId,
|
|
59
|
-
action: state.pending.action,
|
|
60
|
-
label: state.pending.label
|
|
61
|
-
} : null,
|
|
62
|
-
changes: {
|
|
63
|
-
// Transients (navigation, taps) are one-shot actions, not changes —
|
|
64
|
-
// same rule as the on-device bar, so desktop and device tell one story.
|
|
65
|
-
reversible: outstanding.filter(e => (0, _agentCore.isReversible)(e.effect)).length,
|
|
66
|
-
permanent: outstanding.filter(e => e.effect.kind !== "transient" && !(0, _agentCore.isReversible)(e.effect)).length,
|
|
67
|
-
transients: outstanding.filter(e => e.effect.kind === "transient").length,
|
|
68
|
-
items: outstanding.map(e => ({
|
|
69
|
-
kind: e.effect.kind,
|
|
70
|
-
label: e.effect.label
|
|
71
|
-
}))
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
subscribe(onChange) {
|
|
76
|
-
const offStore = _askBuoyStore.askBuoyStore.subscribe(onChange);
|
|
77
|
-
const offLedger = _askBuoyStore.askBuoyStore.getLedger()?.subscribe(onChange);
|
|
78
|
-
return () => {
|
|
79
|
-
offStore();
|
|
80
|
-
offLedger?.();
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
actions: {
|
|
84
|
-
/** What the agent changed, and whether it can be put back. */
|
|
85
|
-
listChanges: () => {
|
|
86
|
-
const entries = _askBuoyStore.askBuoyStore.getLedger()?.list() ?? [];
|
|
87
|
-
return entries.filter(e => !e.undoneAt).map(e => ({
|
|
88
|
-
id: e.id,
|
|
89
|
-
at: e.at,
|
|
90
|
-
toolId: e.toolId,
|
|
91
|
-
action: e.action,
|
|
92
|
-
kind: e.effect.kind,
|
|
93
|
-
label: e.effect.label,
|
|
94
|
-
reversible: (0, _agentCore.isReversible)(e.effect)
|
|
95
|
-
}));
|
|
96
|
-
},
|
|
97
|
-
/** Put back everything that can be put back. Safe direction only. */
|
|
98
|
-
undoAll: async () => {
|
|
99
|
-
const ledger = _askBuoyStore.askBuoyStore.getLedger();
|
|
100
|
-
if (!ledger) return {
|
|
101
|
-
ok: false,
|
|
102
|
-
error: "No Ask Buoy session on this device."
|
|
103
|
-
};
|
|
104
|
-
const outcome = await ledger.revertAll(_wire.dispatchToolAction);
|
|
105
|
-
return {
|
|
106
|
-
ok: true,
|
|
107
|
-
...outcome
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
/** Clear the transcript and the ledger. Does not undo anything. */
|
|
111
|
-
reset: () => {
|
|
112
|
-
_askBuoyStore.askBuoyStore.reset();
|
|
113
|
-
return {
|
|
114
|
-
ok: true
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=askBuoySyncAdapter.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.askBuoySyncAdapter=exports.ASK_BUOY_ADAPTER_VERSION=void 0;var _wire=require("./wire"),_agentCore=require("@buoy-gg/agent-core"),_askBuoyStore=require("../store/askBuoyStore");const ASK_BUOY_ADAPTER_VERSION=exports.ASK_BUOY_ADAPTER_VERSION=1,askBuoySyncAdapter=exports.askBuoySyncAdapter={version:ASK_BUOY_ADAPTER_VERSION,getSnapshot(){const e=_askBuoyStore.askBuoyStore.getState(),t=_askBuoyStore.askBuoyStore.getLedger(),o=(t?.list()??[]).filter(e=>!e.undoneAt);return{version:ASK_BUOY_ADAPTER_VERSION,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:(0,_wire.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=>(0,_agentCore.isReversible)(e.effect)).length,permanent:o.filter(e=>"transient"!==e.effect.kind&&!(0,_agentCore.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.askBuoyStore.subscribe(e),o=_askBuoyStore.askBuoyStore.getLedger()?.subscribe(e);return()=>{t(),o?.()}},actions:{listChanges:()=>(_askBuoyStore.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:(0,_agentCore.isReversible)(e.effect)})),undoAll:async()=>{const e=_askBuoyStore.askBuoyStore.getLedger();return e?{ok:!0,...await e.revertAll(_wire.dispatchToolAction)}:{ok:!1,error:"No Ask Buoy session on this device."}},reset:()=>(_askBuoyStore.askBuoyStore.reset(),{ok:!0})}};
|
|
@@ -1,136 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _agentCore = require("@buoy-gg/agent-core");
|
|
5
|
-
var _askBuoySyncAdapter = require("./askBuoySyncAdapter");
|
|
6
|
-
var _wire = require("./wire");
|
|
7
|
-
var _askBuoyStore = require("../store/askBuoyStore");
|
|
8
|
-
/**
|
|
9
|
-
* What Ask Buoy is allowed to put on the broker wire, and what it refuses to
|
|
10
|
-
* accept from it.
|
|
11
|
-
*
|
|
12
|
-
* Both directions matter. The broker has no authentication, accepts any client
|
|
13
|
-
* that calls itself "Dashboard", and forwards to every connected dashboard — it
|
|
14
|
-
* already broadcasts license keys that way. So: no tool results go out, and no
|
|
15
|
-
* remote client can make the agent say anything.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
(0, _vitest.beforeEach)(() => {
|
|
19
|
-
_askBuoyStore.askBuoyStore.reset();
|
|
20
|
-
_askBuoyStore.askBuoyStore.setLedger(null);
|
|
21
|
-
});
|
|
22
|
-
(0, _vitest.describe)("the wire surface", () => {
|
|
23
|
-
(0, _vitest.it)("exposes no action that can make the agent talk", () => {
|
|
24
|
-
// A `send` here would let anyone on the LAN drive a mutating agent on a
|
|
25
|
-
// tester's phone. The conversation starts on-device, by a person.
|
|
26
|
-
const actions = Object.keys(_askBuoySyncAdapter.askBuoySyncAdapter.actions);
|
|
27
|
-
(0, _vitest.expect)(actions).not.toContain("send");
|
|
28
|
-
(0, _vitest.expect)(actions).not.toContain("ask");
|
|
29
|
-
(0, _vitest.expect)(actions).not.toContain("prompt");
|
|
30
|
-
(0, _vitest.expect)(actions.sort()).toEqual(["listChanges", "reset", "undoAll"]);
|
|
31
|
-
});
|
|
32
|
-
(0, _vitest.it)("puts the shape of the conversation on the wire, never tool payloads", () => {
|
|
33
|
-
_askBuoyStore.askBuoyStore.addUser("what is in storage");
|
|
34
|
-
const id = _askBuoyStore.askBuoyStore.startAssistant();
|
|
35
|
-
_askBuoyStore.askBuoyStore.applyEvent(id, {
|
|
36
|
-
type: "tool-start",
|
|
37
|
-
id: "c1",
|
|
38
|
-
toolId: "storage",
|
|
39
|
-
action: "async.getItem",
|
|
40
|
-
label: "Read session",
|
|
41
|
-
description: "Read one AsyncStorage key"
|
|
42
|
-
});
|
|
43
|
-
_askBuoyStore.askBuoyStore.applyEvent(id, {
|
|
44
|
-
type: "tool-end",
|
|
45
|
-
id: "c1",
|
|
46
|
-
ok: true,
|
|
47
|
-
summary: "eyJhbGciOiJIUzI1NiJ9.super.secret"
|
|
48
|
-
});
|
|
49
|
-
const snap = _askBuoySyncAdapter.askBuoySyncAdapter.getSnapshot();
|
|
50
|
-
const call = snap.messages[1].toolCalls[0];
|
|
51
|
-
(0, _vitest.expect)(call).toEqual({
|
|
52
|
-
toolId: "storage",
|
|
53
|
-
action: "async.getItem",
|
|
54
|
-
status: "ok"
|
|
55
|
-
});
|
|
56
|
-
// The result summary is not on the wire at all — there is no field for it.
|
|
57
|
-
(0, _vitest.expect)(JSON.stringify(snap)).not.toContain("super.secret");
|
|
58
|
-
});
|
|
59
|
-
(0, _vitest.it)("redacts credentials that made it into the assistant's prose", () => {
|
|
60
|
-
_askBuoyStore.askBuoyStore.addUser("show me the auth header");
|
|
61
|
-
const id = _askBuoyStore.askBuoyStore.startAssistant();
|
|
62
|
-
_askBuoyStore.askBuoyStore.applyEvent(id, {
|
|
63
|
-
type: "text",
|
|
64
|
-
delta: "It sends Authorization: Bearer abcdef0123456789ghijkl to the API."
|
|
65
|
-
});
|
|
66
|
-
const snap = _askBuoySyncAdapter.askBuoySyncAdapter.getSnapshot();
|
|
67
|
-
(0, _vitest.expect)(JSON.stringify(snap)).not.toContain("abcdef0123456789ghijkl");
|
|
68
|
-
});
|
|
69
|
-
(0, _vitest.it)("reports reversible and permanent changes separately", () => {
|
|
70
|
-
const ledger = new _agentCore.EffectLedger();
|
|
71
|
-
_askBuoyStore.askBuoyStore.setLedger(ledger);
|
|
72
|
-
ledger.record("storage", "async.setItem", {
|
|
73
|
-
kind: "storage-write",
|
|
74
|
-
toolId: "storage",
|
|
75
|
-
action: "async.setItem",
|
|
76
|
-
key: "points",
|
|
77
|
-
before: "240",
|
|
78
|
-
label: "Set points to 1500"
|
|
79
|
-
});
|
|
80
|
-
ledger.record("perf-monitor", "clearAll", {
|
|
81
|
-
kind: "transient",
|
|
82
|
-
label: "Cleared samples"
|
|
83
|
-
});
|
|
84
|
-
// A store write with no captured prior state: recorded, visible, and
|
|
85
|
-
// NOT something Undo can deliver — it must count as permanent.
|
|
86
|
-
ledger.record("zustand", "setState", {
|
|
87
|
-
kind: "state-write",
|
|
88
|
-
toolId: "zustand",
|
|
89
|
-
action: "setState",
|
|
90
|
-
label: "Update the cart store"
|
|
91
|
-
});
|
|
92
|
-
const snap = _askBuoySyncAdapter.askBuoySyncAdapter.getSnapshot();
|
|
93
|
-
(0, _vitest.expect)(snap.changes.reversible).toBe(1);
|
|
94
|
-
// The transient is an ACTION, not a change — it must not inflate
|
|
95
|
-
// "permanent" (that read "Changed this app · N permanent" after a
|
|
96
|
-
// read-only tour). It is still reported, in its own count.
|
|
97
|
-
(0, _vitest.expect)(snap.changes.permanent).toBe(1);
|
|
98
|
-
(0, _vitest.expect)(snap.changes.transients).toBe(1);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
(0, _vitest.describe)("redactForWire", () => {
|
|
102
|
-
(0, _vitest.it)("removes bearer tokens, JWTs, api keys and license keys", () => {
|
|
103
|
-
const cases = ["Authorization: Bearer abcdefghijklmnop123456", "token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9abcdefgh", "key sk-abcdefghijklmnop1234", "license BUOY-ABCD-1234-EFGH", 'the header is "x-api-key": "supersecretvalue"'];
|
|
104
|
-
for (const input of cases) {
|
|
105
|
-
(0, _vitest.expect)((0, _wire.redactForWire)(input)).toContain("removed]");
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
(0, _vitest.it)("leaves ordinary prose alone", () => {
|
|
109
|
-
const text = "The /menu call returned 200 with 12 items and the burger was in stock.";
|
|
110
|
-
(0, _vitest.expect)((0, _wire.redactForWire)(text)).toBe(text);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
(0, _vitest.describe)("undo from the desktop", () => {
|
|
114
|
-
(0, _vitest.it)("is allowed, because putting things back is the safe direction", async () => {
|
|
115
|
-
const ledger = new _agentCore.EffectLedger();
|
|
116
|
-
_askBuoyStore.askBuoyStore.setLedger(ledger);
|
|
117
|
-
const store = new Map([["points", "1500"]]);
|
|
118
|
-
ledger.record("storage", "async.setItem", {
|
|
119
|
-
kind: "storage-write",
|
|
120
|
-
toolId: "storage",
|
|
121
|
-
action: "async.setItem",
|
|
122
|
-
key: "points",
|
|
123
|
-
before: "240",
|
|
124
|
-
label: "Set points to 1500"
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// The adapter dispatches through the real seam; stub it at the ledger.
|
|
128
|
-
await ledger.revertAll(async (_t, action, params) => {
|
|
129
|
-
const p = params;
|
|
130
|
-
if (action === "async.setItem") store.set(p.key, p.value);
|
|
131
|
-
return undefined;
|
|
132
|
-
});
|
|
133
|
-
(0, _vitest.expect)(store.get("points")).toBe("240");
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
//# sourceMappingURL=askBuoySyncAdapter.test.js.map
|
|
1
|
+
"use strict";var _vitest=require("vitest"),_agentCore=require("@buoy-gg/agent-core"),_askBuoySyncAdapter=require("./askBuoySyncAdapter"),_wire=require("./wire"),_askBuoyStore=require("../store/askBuoyStore");(0,_vitest.beforeEach)(()=>{_askBuoyStore.askBuoyStore.reset(),_askBuoyStore.askBuoyStore.setLedger(null)}),(0,_vitest.describe)("the wire surface",()=>{(0,_vitest.it)("exposes no action that can make the agent talk",()=>{const e=Object.keys(_askBuoySyncAdapter.askBuoySyncAdapter.actions);(0,_vitest.expect)(e).not.toContain("send"),(0,_vitest.expect)(e).not.toContain("ask"),(0,_vitest.expect)(e).not.toContain("prompt"),(0,_vitest.expect)(e.sort()).toEqual(["listChanges","reset","undoAll"])}),(0,_vitest.it)("puts the shape of the conversation on the wire, never tool payloads",()=>{_askBuoyStore.askBuoyStore.addUser("what is in storage");const e=_askBuoyStore.askBuoyStore.startAssistant();_askBuoyStore.askBuoyStore.applyEvent(e,{type:"tool-start",id:"c1",toolId:"storage",action:"async.getItem",label:"Read session",description:"Read one AsyncStorage key"}),_askBuoyStore.askBuoyStore.applyEvent(e,{type:"tool-end",id:"c1",ok:!0,summary:"eyJhbGciOiJIUzI1NiJ9.super.secret"});const t=_askBuoySyncAdapter.askBuoySyncAdapter.getSnapshot(),s=t.messages[1].toolCalls[0];(0,_vitest.expect)(s).toEqual({toolId:"storage",action:"async.getItem",status:"ok"}),(0,_vitest.expect)(JSON.stringify(t)).not.toContain("super.secret")}),(0,_vitest.it)("redacts credentials that made it into the assistant's prose",()=>{_askBuoyStore.askBuoyStore.addUser("show me the auth header");const e=_askBuoyStore.askBuoyStore.startAssistant();_askBuoyStore.askBuoyStore.applyEvent(e,{type:"text",delta:"It sends Authorization: Bearer abcdef0123456789ghijkl to the API."});const t=_askBuoySyncAdapter.askBuoySyncAdapter.getSnapshot();(0,_vitest.expect)(JSON.stringify(t)).not.toContain("abcdef0123456789ghijkl")}),(0,_vitest.it)("reports reversible and permanent changes separately",()=>{const e=new _agentCore.EffectLedger;_askBuoyStore.askBuoyStore.setLedger(e),e.record("storage","async.setItem",{kind:"storage-write",toolId:"storage",action:"async.setItem",key:"points",before:"240",label:"Set points to 1500"}),e.record("perf-monitor","clearAll",{kind:"transient",label:"Cleared samples"}),e.record("zustand","setState",{kind:"state-write",toolId:"zustand",action:"setState",label:"Update the cart store"});const t=_askBuoySyncAdapter.askBuoySyncAdapter.getSnapshot();(0,_vitest.expect)(t.changes.reversible).toBe(1),(0,_vitest.expect)(t.changes.permanent).toBe(1),(0,_vitest.expect)(t.changes.transients).toBe(1)})}),(0,_vitest.describe)("redactForWire",()=>{(0,_vitest.it)("removes bearer tokens, JWTs, api keys and license keys",()=>{const e=["Authorization: Bearer abcdefghijklmnop123456","token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9abcdefgh","key sk-abcdefghijklmnop1234","license BUOY-ABCD-1234-EFGH",'the header is "x-api-key": "supersecretvalue"'];for(const t of e)(0,_vitest.expect)((0,_wire.redactForWire)(t)).toContain("removed]")}),(0,_vitest.it)("leaves ordinary prose alone",()=>{const e="The /menu call returned 200 with 12 items and the burger was in stock.";(0,_vitest.expect)((0,_wire.redactForWire)(e)).toBe(e)})}),(0,_vitest.describe)("undo from the desktop",()=>{(0,_vitest.it)("is allowed, because putting things back is the safe direction",async()=>{const e=new _agentCore.EffectLedger;_askBuoyStore.askBuoyStore.setLedger(e);const t=new Map([["points","1500"]]);e.record("storage","async.setItem",{kind:"storage-write",toolId:"storage",action:"async.setItem",key:"points",before:"240",label:"Set points to 1500"}),await e.revertAll(async(e,s,o)=>{const a=o;"async.setItem"===s&&t.set(a.key,a.value)}),(0,_vitest.expect)(t.get("points")).toBe("240")})});
|
|
@@ -1,58 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "dispatchToolAction", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _sharedUi.dispatchToolAction;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
exports.redactForWire = redactForWire;
|
|
13
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
14
|
-
/**
|
|
15
|
-
* What the sync adapter is allowed to put on the broker wire.
|
|
16
|
-
*
|
|
17
|
-
* The broker has no authentication, `cors.origin: "*"`, binds every interface,
|
|
18
|
-
* and forwards to every connected dashboard — it already broadcasts each
|
|
19
|
-
* device's license key to every socket. A chat transcript is not a safe thing
|
|
20
|
-
* to add to that channel unfiltered: the agent reads storage values, network
|
|
21
|
-
* response bodies and user records, and any of it can end up quoted in an
|
|
22
|
-
* answer.
|
|
23
|
-
*
|
|
24
|
-
* So text crossing the wire is scrubbed for the shapes that are unambiguously
|
|
25
|
-
* credentials. This is a reduction in blast radius, not a guarantee — the real
|
|
26
|
-
* guarantee is that tool RESULTS never cross at all (see askBuoySyncAdapter).
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
const PATTERNS = [{
|
|
30
|
-
re: /\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*/gi,
|
|
31
|
-
label: "[bearer token removed]"
|
|
32
|
-
}, {
|
|
33
|
-
re: /\beyJ[A-Za-z0-9._-]{20,}/g,
|
|
34
|
-
label: "[jwt removed]"
|
|
35
|
-
}, {
|
|
36
|
-
re: /\bsk-[A-Za-z0-9_-]{16,}/g,
|
|
37
|
-
label: "[api key removed]"
|
|
38
|
-
}, {
|
|
39
|
-
re: /\bBUOY-[A-Z0-9-]{8,}/g,
|
|
40
|
-
label: "[license key removed]"
|
|
41
|
-
},
|
|
42
|
-
// Common "key: value" credential shapes in a quoted payload.
|
|
43
|
-
{
|
|
44
|
-
re: /("|')?(authorization|x-api-key|api[_-]?key|password|secret|access_token|refresh_token)\1?\s*[:=]\s*("|')?[^\s"',}]{6,}/gi,
|
|
45
|
-
label: "[credential removed]"
|
|
46
|
-
}];
|
|
47
|
-
function redactForWire(text) {
|
|
48
|
-
if (!text) return text;
|
|
49
|
-
let out = text;
|
|
50
|
-
for (const {
|
|
51
|
-
re,
|
|
52
|
-
label
|
|
53
|
-
} of PATTERNS) {
|
|
54
|
-
out = out.replace(re, label);
|
|
55
|
-
}
|
|
56
|
-
return out;
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=wire.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"dispatchToolAction",{enumerable:!0,get:function(){return _sharedUi.dispatchToolAction}}),exports.redactForWire=redactForWire;var _sharedUi=require("@buoy-gg/shared-ui");const PATTERNS=[{re:/\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*/gi,label:"[bearer token removed]"},{re:/\beyJ[A-Za-z0-9._-]{20,}/g,label:"[jwt removed]"},{re:/\bsk-[A-Za-z0-9_-]{16,}/g,label:"[api key removed]"},{re:/\bBUOY-[A-Z0-9-]{8,}/g,label:"[license key removed]"},{re:/("|')?(authorization|x-api-key|api[_-]?key|password|secret|access_token|refresh_token)\1?\s*[:=]\s*("|')?[^\s"',}]{6,}/gi,label:"[credential removed]"}];function redactForWire(e){if(!e)return e;let r=e;for(const{re:e,label:o}of PATTERNS)r=r.replace(e,o);return r}
|