@buoy-gg/ask-buoy 7.0.34 → 7.0.35
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 +338 -1
- package/lib/commonjs/blocks/AskBlocks.js.map +1 -0
- package/lib/commonjs/blocks/BlockRenderer.js +250 -1
- package/lib/commonjs/blocks/BlockRenderer.js.map +1 -0
- package/lib/commonjs/blocks/ChromePrototypes.js +514 -1
- package/lib/commonjs/blocks/ChromePrototypes.js.map +1 -0
- package/lib/commonjs/blocks/DataBlocks.js +688 -1
- package/lib/commonjs/blocks/DataBlocks.js.map +1 -0
- package/lib/commonjs/blocks/ExtraBlocks.js +1854 -1
- package/lib/commonjs/blocks/ExtraBlocks.js.map +1 -0
- package/lib/commonjs/blocks/MediaBlocks.js +140 -1
- package/lib/commonjs/blocks/MediaBlocks.js.map +1 -0
- package/lib/commonjs/blocks/ReceiptBlocks.js +586 -1
- package/lib/commonjs/blocks/ReceiptBlocks.js.map +1 -0
- package/lib/commonjs/blocks/context.js +42 -1
- package/lib/commonjs/blocks/context.js.map +1 -0
- package/lib/commonjs/blocks/icons.js +96 -1
- package/lib/commonjs/blocks/icons.js.map +1 -0
- package/lib/commonjs/blocks/index.js +95 -1
- package/lib/commonjs/blocks/index.js.map +1 -0
- package/lib/commonjs/blocks/listRow.test.js +55 -0
- package/lib/commonjs/blocks/listRow.test.js.map +1 -0
- package/lib/commonjs/blocks/pageState.js +34 -0
- package/lib/commonjs/blocks/pageState.js.map +1 -0
- package/lib/commonjs/blocks/pageState.test.js +57 -0
- package/lib/commonjs/blocks/pageState.test.js.map +1 -0
- package/lib/commonjs/blocks/primitives.js +401 -1
- package/lib/commonjs/blocks/primitives.js.map +1 -0
- package/lib/commonjs/blocks/primitivesIndex.js +62 -1
- package/lib/commonjs/blocks/primitivesIndex.js.map +1 -0
- package/lib/commonjs/components/ApprovalCard.js +140 -1
- package/lib/commonjs/components/ApprovalCard.js.map +1 -0
- package/lib/commonjs/components/AskBuoyHeader.js +164 -1
- package/lib/commonjs/components/AskBuoyHeader.js.map +1 -0
- package/lib/commonjs/components/AskBuoyIcon.js +19 -1
- package/lib/commonjs/components/AskBuoyIcon.js.map +1 -0
- package/lib/commonjs/components/AskBuoyModal.js +353 -1
- package/lib/commonjs/components/AskBuoyModal.js.map +1 -0
- package/lib/commonjs/components/AskBuoySettings.js +69 -0
- package/lib/commonjs/components/AskBuoySettings.js.map +1 -0
- package/lib/commonjs/components/ChangesBar.js +211 -1
- package/lib/commonjs/components/ChangesBar.js.map +1 -0
- package/lib/commonjs/components/Composer.js +175 -1
- package/lib/commonjs/components/Composer.js.map +1 -0
- package/lib/commonjs/components/EmptyState.js +154 -1
- package/lib/commonjs/components/EmptyState.js.map +1 -0
- package/lib/commonjs/components/Markdown.js +252 -1
- package/lib/commonjs/components/Markdown.js.map +1 -0
- package/lib/commonjs/components/MessageList.js +683 -1
- package/lib/commonjs/components/MessageList.js.map +1 -0
- package/lib/commonjs/components/ThinkingStrip.js +223 -0
- package/lib/commonjs/components/ThinkingStrip.js.map +1 -0
- package/lib/commonjs/components/TypingDots.js +63 -1
- package/lib/commonjs/components/TypingDots.js.map +1 -0
- package/lib/commonjs/components/useCopyAction.js +50 -0
- package/lib/commonjs/components/useCopyAction.js.map +1 -0
- package/lib/commonjs/index.js +252 -1
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/preset.js +90 -1
- package/lib/commonjs/preset.js.map +1 -0
- package/lib/commonjs/store/askBuoySettings.js +67 -0
- package/lib/commonjs/store/askBuoySettings.js.map +1 -0
- package/lib/commonjs/store/askBuoyStore.js +365 -1
- package/lib/commonjs/store/askBuoyStore.js.map +1 -0
- package/lib/commonjs/store/restoredIds.test.js +47 -0
- package/lib/commonjs/store/restoredIds.test.js.map +1 -0
- package/lib/commonjs/store/traceText.js +81 -0
- package/lib/commonjs/store/traceText.js.map +1 -0
- package/lib/commonjs/store/traceText.test.js +112 -0
- package/lib/commonjs/store/traceText.test.js.map +1 -0
- package/lib/commonjs/store/transcriptPersistence.js +208 -0
- package/lib/commonjs/store/transcriptPersistence.js.map +1 -0
- package/lib/commonjs/store/transcriptPersistence.test.js +185 -0
- package/lib/commonjs/store/transcriptPersistence.test.js.map +1 -0
- package/lib/commonjs/store/useAskBuoy.js +400 -1
- package/lib/commonjs/store/useAskBuoy.js.map +1 -0
- package/lib/commonjs/store/useAskBuoySettings.js +14 -0
- package/lib/commonjs/store/useAskBuoySettings.js.map +1 -0
- package/lib/commonjs/sync/askBuoySyncAdapter.js +119 -1
- package/lib/commonjs/sync/askBuoySyncAdapter.js.map +1 -0
- package/lib/commonjs/sync/askBuoySyncAdapter.test.js +141 -1
- package/lib/commonjs/sync/askBuoySyncAdapter.test.js.map +1 -0
- package/lib/commonjs/sync/wire.js +58 -1
- package/lib/commonjs/sync/wire.js.map +1 -0
- package/lib/commonjs/types.js +6 -1
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/blocks/AskBlocks.js +331 -1
- package/lib/module/blocks/AskBlocks.js.map +1 -0
- package/lib/module/blocks/BlockRenderer.js +245 -1
- package/lib/module/blocks/BlockRenderer.js.map +1 -0
- package/lib/module/blocks/ChromePrototypes.js +503 -1
- package/lib/module/blocks/ChromePrototypes.js.map +1 -0
- package/lib/module/blocks/DataBlocks.js +674 -1
- package/lib/module/blocks/DataBlocks.js.map +1 -0
- package/lib/module/blocks/ExtraBlocks.js +1827 -1
- package/lib/module/blocks/ExtraBlocks.js.map +1 -0
- package/lib/module/blocks/MediaBlocks.js +135 -1
- package/lib/module/blocks/MediaBlocks.js.map +1 -0
- package/lib/module/blocks/ReceiptBlocks.js +574 -1
- package/lib/module/blocks/ReceiptBlocks.js.map +1 -0
- package/lib/module/blocks/context.js +35 -1
- package/lib/module/blocks/context.js.map +1 -0
- package/lib/module/blocks/icons.js +91 -1
- package/lib/module/blocks/icons.js.map +1 -0
- package/lib/module/blocks/index.js +8 -1
- package/lib/module/blocks/index.js.map +1 -0
- package/lib/module/blocks/listRow.test.js +56 -0
- package/lib/module/blocks/listRow.test.js.map +1 -0
- package/lib/module/blocks/pageState.js +30 -0
- package/lib/module/blocks/pageState.js.map +1 -0
- package/lib/module/blocks/pageState.test.js +56 -0
- package/lib/module/blocks/pageState.test.js.map +1 -0
- package/lib/module/blocks/primitives.js +389 -1
- package/lib/module/blocks/primitives.js.map +1 -0
- package/lib/module/blocks/primitivesIndex.js +5 -1
- package/lib/module/blocks/primitivesIndex.js.map +1 -0
- package/lib/module/components/ApprovalCard.js +135 -1
- package/lib/module/components/ApprovalCard.js.map +1 -0
- package/lib/module/components/AskBuoyHeader.js +161 -1
- package/lib/module/components/AskBuoyHeader.js.map +1 -0
- package/lib/module/components/AskBuoyIcon.js +8 -1
- package/lib/module/components/AskBuoyIcon.js.map +1 -0
- package/lib/module/components/AskBuoyModal.js +348 -1
- package/lib/module/components/AskBuoyModal.js.map +1 -0
- package/lib/module/components/AskBuoySettings.js +64 -0
- package/lib/module/components/AskBuoySettings.js.map +1 -0
- package/lib/module/components/ChangesBar.js +206 -1
- package/lib/module/components/ChangesBar.js.map +1 -0
- package/lib/module/components/Composer.js +170 -1
- package/lib/module/components/Composer.js.map +1 -0
- package/lib/module/components/EmptyState.js +149 -1
- package/lib/module/components/EmptyState.js.map +1 -0
- package/lib/module/components/Markdown.js +246 -1
- package/lib/module/components/Markdown.js.map +1 -0
- package/lib/module/components/MessageList.js +677 -1
- package/lib/module/components/MessageList.js.map +1 -0
- package/lib/module/components/ThinkingStrip.js +218 -0
- package/lib/module/components/ThinkingStrip.js.map +1 -0
- package/lib/module/components/TypingDots.js +58 -1
- package/lib/module/components/TypingDots.js.map +1 -0
- package/lib/module/components/useCopyAction.js +46 -0
- package/lib/module/components/useCopyAction.js.map +1 -0
- package/lib/module/index.js +34 -1
- package/lib/module/index.js.map +1 -0
- package/lib/module/preset.js +73 -1
- package/lib/module/preset.js.map +1 -0
- package/lib/module/store/askBuoySettings.js +62 -0
- package/lib/module/store/askBuoySettings.js.map +1 -0
- package/lib/module/store/askBuoyStore.js +361 -1
- package/lib/module/store/askBuoyStore.js.map +1 -0
- package/lib/module/store/restoredIds.test.js +46 -0
- package/lib/module/store/restoredIds.test.js.map +1 -0
- package/lib/module/store/traceText.js +75 -0
- package/lib/module/store/traceText.js.map +1 -0
- package/lib/module/store/traceText.test.js +111 -0
- package/lib/module/store/traceText.test.js.map +1 -0
- package/lib/module/store/transcriptPersistence.js +198 -0
- package/lib/module/store/transcriptPersistence.js.map +1 -0
- package/lib/module/store/transcriptPersistence.test.js +184 -0
- package/lib/module/store/transcriptPersistence.test.js.map +1 -0
- package/lib/module/store/useAskBuoy.js +394 -1
- package/lib/module/store/useAskBuoy.js.map +1 -0
- package/lib/module/store/useAskBuoySettings.js +9 -0
- package/lib/module/store/useAskBuoySettings.js.map +1 -0
- package/lib/module/sync/askBuoySyncAdapter.js +114 -1
- package/lib/module/sync/askBuoySyncAdapter.js.map +1 -0
- package/lib/module/sync/askBuoySyncAdapter.test.js +140 -1
- package/lib/module/sync/askBuoySyncAdapter.test.js.map +1 -0
- package/lib/module/sync/wire.js +47 -1
- package/lib/module/sync/wire.js.map +1 -0
- package/lib/module/types.js +4 -1
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/blocks/AskBlocks.d.ts.map +1 -0
- package/lib/typescript/blocks/BlockRenderer.d.ts.map +1 -0
- package/lib/typescript/blocks/ChromePrototypes.d.ts.map +1 -0
- package/lib/typescript/blocks/DataBlocks.d.ts +31 -0
- package/lib/typescript/blocks/DataBlocks.d.ts.map +1 -0
- package/lib/typescript/blocks/ExtraBlocks.d.ts +11 -0
- package/lib/typescript/blocks/ExtraBlocks.d.ts.map +1 -0
- package/lib/typescript/blocks/MediaBlocks.d.ts.map +1 -0
- package/lib/typescript/blocks/ReceiptBlocks.d.ts.map +1 -0
- package/lib/typescript/blocks/context.d.ts.map +1 -0
- package/lib/typescript/blocks/icons.d.ts.map +1 -0
- package/lib/typescript/blocks/index.d.ts.map +1 -0
- package/lib/typescript/blocks/listRow.test.d.ts +2 -0
- package/lib/typescript/blocks/listRow.test.d.ts.map +1 -0
- package/lib/typescript/blocks/pageState.d.ts +23 -0
- package/lib/typescript/blocks/pageState.d.ts.map +1 -0
- package/lib/typescript/blocks/pageState.test.d.ts +2 -0
- package/lib/typescript/blocks/pageState.test.d.ts.map +1 -0
- package/lib/typescript/blocks/primitives.d.ts +39 -9
- package/lib/typescript/blocks/primitives.d.ts.map +1 -0
- package/lib/typescript/blocks/primitivesIndex.d.ts +2 -1
- package/lib/typescript/blocks/primitivesIndex.d.ts.map +1 -0
- package/lib/typescript/components/ApprovalCard.d.ts.map +1 -0
- package/lib/typescript/components/AskBuoyHeader.d.ts +11 -1
- package/lib/typescript/components/AskBuoyHeader.d.ts.map +1 -0
- package/lib/typescript/components/AskBuoyIcon.d.ts.map +1 -0
- package/lib/typescript/components/AskBuoyModal.d.ts.map +1 -0
- package/lib/typescript/components/AskBuoySettings.d.ts +2 -0
- package/lib/typescript/components/AskBuoySettings.d.ts.map +1 -0
- package/lib/typescript/components/ChangesBar.d.ts.map +1 -0
- package/lib/typescript/components/Composer.d.ts.map +1 -0
- package/lib/typescript/components/EmptyState.d.ts.map +1 -0
- package/lib/typescript/components/Markdown.d.ts.map +1 -0
- package/lib/typescript/components/MessageList.d.ts +12 -5
- package/lib/typescript/components/MessageList.d.ts.map +1 -0
- package/lib/typescript/components/ThinkingStrip.d.ts +5 -0
- package/lib/typescript/components/ThinkingStrip.d.ts.map +1 -0
- package/lib/typescript/components/TypingDots.d.ts.map +1 -0
- package/lib/typescript/components/useCopyAction.d.ts +5 -0
- package/lib/typescript/components/useCopyAction.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/lib/typescript/store/askBuoySettings.d.ts +22 -0
- package/lib/typescript/store/askBuoySettings.d.ts.map +1 -0
- package/lib/typescript/store/askBuoyStore.d.ts +74 -13
- package/lib/typescript/store/askBuoyStore.d.ts.map +1 -0
- package/lib/typescript/store/restoredIds.test.d.ts +2 -0
- package/lib/typescript/store/restoredIds.test.d.ts.map +1 -0
- package/lib/typescript/store/traceText.d.ts +33 -0
- package/lib/typescript/store/traceText.d.ts.map +1 -0
- package/lib/typescript/store/traceText.test.d.ts +2 -0
- package/lib/typescript/store/traceText.test.d.ts.map +1 -0
- package/lib/typescript/store/transcriptPersistence.d.ts +40 -0
- package/lib/typescript/store/transcriptPersistence.d.ts.map +1 -0
- package/lib/typescript/store/transcriptPersistence.test.d.ts +2 -0
- package/lib/typescript/store/transcriptPersistence.test.d.ts.map +1 -0
- package/lib/typescript/store/useAskBuoy.d.ts.map +1 -0
- package/lib/typescript/store/useAskBuoySettings.d.ts +3 -0
- package/lib/typescript/store/useAskBuoySettings.d.ts.map +1 -0
- package/lib/typescript/sync/askBuoySyncAdapter.d.ts.map +1 -0
- package/lib/typescript/sync/askBuoySyncAdapter.test.d.ts.map +1 -0
- package/lib/typescript/sync/wire.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +24 -1
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +8 -8
|
@@ -1 +1,365 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.askBuoyStore = void 0;
|
|
7
|
+
var _agentCore = require("@buoy-gg/agent-core");
|
|
8
|
+
/**
|
|
9
|
+
* Conversation state for the sheet.
|
|
10
|
+
*
|
|
11
|
+
* A module-level store rather than component state for two reasons: the sheet
|
|
12
|
+
* is unmounted whenever the tool is closed or minimised (and a conversation
|
|
13
|
+
* that vanished because someone tapped away would be maddening), and the sync
|
|
14
|
+
* adapter needs to read the same transcript to show it on the desktop.
|
|
15
|
+
*
|
|
16
|
+
* Persisted across restarts, on purpose, with the payloads left out — see
|
|
17
|
+
* `transcriptPersistence.ts` for what is written and what that costs. The
|
|
18
|
+
* store itself stays a plain in-memory store; saving is a subscriber, and
|
|
19
|
+
* `hydrate` is the one way anything comes back in.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** A block in a message, and (for receipts) the tool call that produced it. */
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A stretch of the model's own reasoning, and where it fell.
|
|
26
|
+
*
|
|
27
|
+
* `afterCalls` is how many tool calls this message had already made when the
|
|
28
|
+
* thought arrived, so the thinking view can lay reasoning and steps out in the
|
|
29
|
+
* order they actually happened. One assistant bubble spans every turn of a
|
|
30
|
+
* multi-step run, so "think, act, think, act" is the normal shape and showing
|
|
31
|
+
* all the thoughts in a lump at the top would misreport it.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Message ids carry this run's token — see agent-core's `runId`. A plain `m1`
|
|
36
|
+
* collided head-on with the `m1` in a restored transcript, and the message
|
|
37
|
+
* list keys on it.
|
|
38
|
+
*/
|
|
39
|
+
const nextId = (0, _agentCore.idFactory)("m");
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Params, as one readable line. Capped because a step can carry a whole
|
|
43
|
+
* response body or a store's full state, and this is chrome inside a chat
|
|
44
|
+
* bubble — the full value is a tool read away.
|
|
45
|
+
*/
|
|
46
|
+
const MAX_PARAM_CHARS = 400;
|
|
47
|
+
function encodeParams(params) {
|
|
48
|
+
if (!params || Object.keys(params).length === 0) return undefined;
|
|
49
|
+
try {
|
|
50
|
+
const json = JSON.stringify(params);
|
|
51
|
+
return json.length > MAX_PARAM_CHARS ? `${json.slice(0, MAX_PARAM_CHARS)}…` : json;
|
|
52
|
+
} catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let state = {
|
|
57
|
+
messages: [],
|
|
58
|
+
busy: false,
|
|
59
|
+
pending: null,
|
|
60
|
+
notice: null,
|
|
61
|
+
configured: false,
|
|
62
|
+
answers: {},
|
|
63
|
+
awaitingBlockId: null,
|
|
64
|
+
actionState: {},
|
|
65
|
+
queued: null,
|
|
66
|
+
usage: {
|
|
67
|
+
input: 0,
|
|
68
|
+
output: 0,
|
|
69
|
+
requests: 0
|
|
70
|
+
},
|
|
71
|
+
meta: {}
|
|
72
|
+
};
|
|
73
|
+
const listeners = new Set();
|
|
74
|
+
let ledgerRef = null;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The session outlives the sheet the same way the transcript does. Session and
|
|
78
|
+
* ledger used to be per-mount: closing and reopening the tool kept the visible
|
|
79
|
+
* conversation but silently swapped in an empty ledger and a blank model
|
|
80
|
+
* memory — the undo bar vanished while the agent's changes stayed live in the
|
|
81
|
+
* app. Held here, keyed by a config signature so a real reconfiguration
|
|
82
|
+
* (different endpoint/model/tool set) still rebuilds.
|
|
83
|
+
*/
|
|
84
|
+
let heldSession = null;
|
|
85
|
+
function set(next) {
|
|
86
|
+
state = {
|
|
87
|
+
...state,
|
|
88
|
+
...next
|
|
89
|
+
};
|
|
90
|
+
for (const fn of listeners) {
|
|
91
|
+
try {
|
|
92
|
+
fn();
|
|
93
|
+
} catch {
|
|
94
|
+
// A throwing subscriber must not take the transcript down mid-answer.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const askBuoyStore = exports.askBuoyStore = {
|
|
99
|
+
getState: () => state,
|
|
100
|
+
subscribe(fn) {
|
|
101
|
+
listeners.add(fn);
|
|
102
|
+
return () => listeners.delete(fn);
|
|
103
|
+
},
|
|
104
|
+
setLedger(ledger) {
|
|
105
|
+
ledgerRef = ledger;
|
|
106
|
+
},
|
|
107
|
+
getLedger() {
|
|
108
|
+
return ledgerRef;
|
|
109
|
+
},
|
|
110
|
+
holdSession(session, signature) {
|
|
111
|
+
heldSession = {
|
|
112
|
+
session,
|
|
113
|
+
signature
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
getHeldSession() {
|
|
117
|
+
return heldSession;
|
|
118
|
+
},
|
|
119
|
+
setNotice(notice) {
|
|
120
|
+
set({
|
|
121
|
+
notice
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
setConfigured(configured) {
|
|
125
|
+
if (configured !== state.configured) set({
|
|
126
|
+
configured
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
setMeta(meta) {
|
|
130
|
+
const same = Object.keys(meta).every(k => state.meta[k] === meta[k]);
|
|
131
|
+
if (!same) set({
|
|
132
|
+
meta: {
|
|
133
|
+
...state.meta,
|
|
134
|
+
...meta
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
addUser(text) {
|
|
139
|
+
set({
|
|
140
|
+
messages: [...state.messages, {
|
|
141
|
+
id: nextId(),
|
|
142
|
+
role: "user",
|
|
143
|
+
text,
|
|
144
|
+
toolCalls: [],
|
|
145
|
+
blocks: []
|
|
146
|
+
}],
|
|
147
|
+
busy: true
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
/** Mark a turn as running without adding a bubble — the retry path. */
|
|
151
|
+
beginTurn() {
|
|
152
|
+
set({
|
|
153
|
+
busy: true
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
/** Park a message typed mid-turn instead of silently dropping it. */
|
|
157
|
+
setQueued(text) {
|
|
158
|
+
set({
|
|
159
|
+
queued: text
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
/** Drop one message — the failed assistant bubble a retry replaces. */
|
|
163
|
+
removeMessage(id) {
|
|
164
|
+
set({
|
|
165
|
+
messages: state.messages.filter(m => m.id !== id)
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
/** The user answered (or skipped) an Ask block. */
|
|
169
|
+
recordAnswer(answer) {
|
|
170
|
+
set({
|
|
171
|
+
answers: {
|
|
172
|
+
...state.answers,
|
|
173
|
+
[answer.blockId]: answer
|
|
174
|
+
},
|
|
175
|
+
awaitingBlockId: state.awaitingBlockId === answer.blockId ? null : state.awaitingBlockId
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
setActionState(key, value) {
|
|
179
|
+
const next = {
|
|
180
|
+
...state.actionState
|
|
181
|
+
};
|
|
182
|
+
if (value === null) delete next[key];else next[key] = value;
|
|
183
|
+
set({
|
|
184
|
+
actionState: next
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
/** Open a new assistant bubble for the turn that is about to stream. */
|
|
188
|
+
startAssistant() {
|
|
189
|
+
const id = nextId();
|
|
190
|
+
set({
|
|
191
|
+
messages: [...state.messages, {
|
|
192
|
+
id,
|
|
193
|
+
role: "assistant",
|
|
194
|
+
text: "",
|
|
195
|
+
toolCalls: [],
|
|
196
|
+
blocks: [],
|
|
197
|
+
streaming: true,
|
|
198
|
+
startedAt: Date.now()
|
|
199
|
+
}]
|
|
200
|
+
});
|
|
201
|
+
return id;
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* Fold one engine event into the open assistant message.
|
|
205
|
+
*
|
|
206
|
+
* Tool calls render as rows inside the bubble rather than as raw payloads:
|
|
207
|
+
* the label is already domain-flavoured ("Set points to 1500"), which is the
|
|
208
|
+
* only form a non-developer can actually check.
|
|
209
|
+
*/
|
|
210
|
+
applyEvent(messageId, ev) {
|
|
211
|
+
const messages = state.messages.map(m => {
|
|
212
|
+
if (m.id !== messageId) return m;
|
|
213
|
+
switch (ev.type) {
|
|
214
|
+
case "text":
|
|
215
|
+
return {
|
|
216
|
+
...m,
|
|
217
|
+
text: m.breakBeforeNextText && m.text ? `${m.text.trimEnd()}\n\n${ev.delta}` : m.text + ev.delta,
|
|
218
|
+
breakBeforeNextText: false
|
|
219
|
+
};
|
|
220
|
+
case "reasoning":
|
|
221
|
+
return {
|
|
222
|
+
...m,
|
|
223
|
+
breakBeforeNextText: true,
|
|
224
|
+
reasoning: [...(m.reasoning ?? []), {
|
|
225
|
+
text: ev.text,
|
|
226
|
+
afterCalls: m.toolCalls.length
|
|
227
|
+
}]
|
|
228
|
+
};
|
|
229
|
+
case "tool-start":
|
|
230
|
+
return {
|
|
231
|
+
...m,
|
|
232
|
+
toolCalls: [...m.toolCalls, {
|
|
233
|
+
id: ev.id,
|
|
234
|
+
toolId: ev.toolId,
|
|
235
|
+
action: ev.action,
|
|
236
|
+
label: ev.label,
|
|
237
|
+
description: ev.description,
|
|
238
|
+
status: "running",
|
|
239
|
+
params: encodeParams(ev.params),
|
|
240
|
+
effect: ev.effect,
|
|
241
|
+
startedAt: Date.now()
|
|
242
|
+
}]
|
|
243
|
+
};
|
|
244
|
+
case "tool-end":
|
|
245
|
+
return {
|
|
246
|
+
...m,
|
|
247
|
+
breakBeforeNextText: true,
|
|
248
|
+
toolCalls: m.toolCalls.map(c => c.id === ev.id ? {
|
|
249
|
+
...c,
|
|
250
|
+
status: !ev.ok && ev.summary === "refused" ? "refused" : ev.ok ? "ok" : "failed",
|
|
251
|
+
summary: ev.summary,
|
|
252
|
+
durationMs: ev.durationMs,
|
|
253
|
+
result: ev.result
|
|
254
|
+
} : c)
|
|
255
|
+
};
|
|
256
|
+
case "block":
|
|
257
|
+
return {
|
|
258
|
+
...m,
|
|
259
|
+
breakBeforeNextText: true,
|
|
260
|
+
blocks: [...m.blocks, {
|
|
261
|
+
block: ev.block,
|
|
262
|
+
forToolCallId: ev.forToolCallId
|
|
263
|
+
}]
|
|
264
|
+
};
|
|
265
|
+
case "usage":
|
|
266
|
+
// Also folded into the session total below. Per MESSAGE as well,
|
|
267
|
+
// because "which answer cost 40k tokens" is the question you ask
|
|
268
|
+
// when a bill looks wrong, and a session total cannot answer it.
|
|
269
|
+
return {
|
|
270
|
+
...m,
|
|
271
|
+
usage: {
|
|
272
|
+
input: (m.usage?.input ?? 0) + ev.input,
|
|
273
|
+
output: (m.usage?.output ?? 0) + ev.output,
|
|
274
|
+
requests: (m.usage?.requests ?? 0) + 1
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
case "error":
|
|
278
|
+
return {
|
|
279
|
+
...m,
|
|
280
|
+
error: ev.message
|
|
281
|
+
};
|
|
282
|
+
default:
|
|
283
|
+
return m;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
set({
|
|
287
|
+
messages,
|
|
288
|
+
...(ev.type === "awaiting-user" ? {
|
|
289
|
+
awaitingBlockId: ev.blockId
|
|
290
|
+
} : {}),
|
|
291
|
+
...(ev.type === "usage" ? {
|
|
292
|
+
usage: {
|
|
293
|
+
input: state.usage.input + ev.input,
|
|
294
|
+
output: state.usage.output + ev.output,
|
|
295
|
+
requests: state.usage.requests + 1
|
|
296
|
+
}
|
|
297
|
+
} : {})
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
finishAssistant(messageId) {
|
|
301
|
+
set({
|
|
302
|
+
messages: state.messages.map(m => m.id === messageId ? {
|
|
303
|
+
...m,
|
|
304
|
+
streaming: false,
|
|
305
|
+
endedAt: Date.now()
|
|
306
|
+
} : m),
|
|
307
|
+
busy: false
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
askApproval(input) {
|
|
311
|
+
return new Promise(resolve => {
|
|
312
|
+
set({
|
|
313
|
+
pending: {
|
|
314
|
+
...input,
|
|
315
|
+
resolve
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
answerApproval(approved) {
|
|
321
|
+
const pending = state.pending;
|
|
322
|
+
set({
|
|
323
|
+
pending: null
|
|
324
|
+
});
|
|
325
|
+
pending?.resolve(approved);
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* Put a saved conversation back, once, at open.
|
|
329
|
+
*
|
|
330
|
+
* Refuses if anything has been said already: a slow disk read landing after
|
|
331
|
+
* the user has started typing must not shove an old chat in front of them.
|
|
332
|
+
*/
|
|
333
|
+
hydrate(input) {
|
|
334
|
+
if (state.messages.length > 0 || state.busy) return false;
|
|
335
|
+
set({
|
|
336
|
+
messages: input.messages,
|
|
337
|
+
answers: input.answers,
|
|
338
|
+
usage: input.usage
|
|
339
|
+
});
|
|
340
|
+
return true;
|
|
341
|
+
},
|
|
342
|
+
reset() {
|
|
343
|
+
// Reject anything still waiting, or the turn hangs forever on a promise
|
|
344
|
+
// whose only resolver just left the screen.
|
|
345
|
+
state.pending?.resolve(false);
|
|
346
|
+
set({
|
|
347
|
+
messages: [],
|
|
348
|
+
busy: false,
|
|
349
|
+
pending: null,
|
|
350
|
+
notice: null,
|
|
351
|
+
answers: {},
|
|
352
|
+
awaitingBlockId: null,
|
|
353
|
+
actionState: {},
|
|
354
|
+
queued: null,
|
|
355
|
+
usage: {
|
|
356
|
+
input: 0,
|
|
357
|
+
output: 0,
|
|
358
|
+
requests: 0
|
|
359
|
+
}
|
|
360
|
+
// `meta` survives: it describes the app and the endpoint, not the
|
|
361
|
+
// conversation, and re-deriving it would need another render pass.
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
//# sourceMappingURL=askBuoyStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_agentCore","require","nextId","idFactory","MAX_PARAM_CHARS","encodeParams","params","Object","keys","length","undefined","json","JSON","stringify","slice","state","messages","busy","pending","notice","configured","answers","awaitingBlockId","actionState","queued","usage","input","output","requests","meta","listeners","Set","ledgerRef","heldSession","set","next","fn","askBuoyStore","exports","getState","subscribe","add","delete","setLedger","ledger","getLedger","holdSession","session","signature","getHeldSession","setNotice","setConfigured","setMeta","same","every","k","addUser","text","id","role","toolCalls","blocks","beginTurn","setQueued","removeMessage","filter","m","recordAnswer","answer","blockId","setActionState","key","value","startAssistant","streaming","startedAt","Date","now","applyEvent","messageId","ev","map","type","breakBeforeNextText","trimEnd","delta","reasoning","afterCalls","toolId","action","label","description","status","effect","c","ok","summary","durationMs","result","block","forToolCallId","error","message","finishAssistant","endedAt","askApproval","Promise","resolve","answerApproval","approved","hydrate","reset"],"sourceRoot":"../../../src","sources":["store/askBuoyStore.ts"],"mappings":";;;;;;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ACFlB,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;MAC1C;MACA;IACF,CAAC,CAAC;EACJ;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _agentCore = require("@buoy-gg/agent-core");
|
|
5
|
+
/**
|
|
6
|
+
* Ids from a RESTORED transcript must never collide with a fresh run's.
|
|
7
|
+
*
|
|
8
|
+
* The bug this covers, in full: every id counter restarted at 1 with the
|
|
9
|
+
* process, which was harmless until the transcript started outliving a reload.
|
|
10
|
+
* A restored conversation came back holding `rc1`, `ui1` and `m1`; the next
|
|
11
|
+
* turn minted `rc1` again; React saw two children with one key and rendered
|
|
12
|
+
* one of them twice while dropping the other. On screen that was the same
|
|
13
|
+
* store card appearing twice after a reload.
|
|
14
|
+
*
|
|
15
|
+
* Simulating a restart in one process is the whole difficulty — the module
|
|
16
|
+
* caches its counter. `idFactory` is the seam: a second factory stands in for
|
|
17
|
+
* the second run, and the shared RUN_ID is what has to differ between them.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
(0, _vitest.describe)("ids across a restart", () => {
|
|
21
|
+
(0, _vitest.it)("never reissues an id a restored transcript already holds", () => {
|
|
22
|
+
// What a saved transcript carries, from a previous launch.
|
|
23
|
+
const restored = ["rcOLDRUN-1", "rcOLDRUN-2", "uiOLDRUN-1", "mOLDRUN-1"];
|
|
24
|
+
const rc = (0, _agentCore.idFactory)("rc");
|
|
25
|
+
const ui = (0, _agentCore.idFactory)("ui");
|
|
26
|
+
const m = (0, _agentCore.idFactory)("m");
|
|
27
|
+
const fresh = [rc(), rc(), ui(), m()];
|
|
28
|
+
for (const id of fresh) (0, _vitest.expect)(restored).not.toContain(id);
|
|
29
|
+
});
|
|
30
|
+
(0, _vitest.it)("still counts up within one run", () => {
|
|
31
|
+
// The counter is what keeps two blocks in the SAME turn apart.
|
|
32
|
+
const rc = (0, _agentCore.idFactory)("rc");
|
|
33
|
+
const ids = [rc(), rc(), rc()];
|
|
34
|
+
(0, _vitest.expect)(new Set(ids).size).toBe(3);
|
|
35
|
+
});
|
|
36
|
+
(0, _vitest.it)("keeps two prefixes apart even at the same count", () => {
|
|
37
|
+
const rc = (0, _agentCore.idFactory)("rc");
|
|
38
|
+
const ui = (0, _agentCore.idFactory)("ui");
|
|
39
|
+
(0, _vitest.expect)(rc()).not.toBe(ui());
|
|
40
|
+
});
|
|
41
|
+
(0, _vitest.it)("stamps a run token that is not a fixed string", () => {
|
|
42
|
+
// A constant here would put every install back where it started.
|
|
43
|
+
(0, _vitest.expect)(_agentCore.RUN_ID).toMatch(/^[a-z0-9]{4,8}$/);
|
|
44
|
+
(0, _vitest.expect)((0, _agentCore.idFactory)("rc")()).toBe(`rc${_agentCore.RUN_ID}-1`);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=restoredIds.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_vitest","require","_agentCore","describe","it","restored","rc","idFactory","ui","m","fresh","id","expect","not","toContain","ids","Set","size","toBe","RUN_ID","toMatch"],"sourceRoot":"../../../src","sources":["store/restoredIds.test.ts"],"mappings":";;AAcA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,IAAAE,gBAAQ,EAAC,sBAAsB,EAAE,MAAM;EACrC,IAAA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AM;IACxD;IACA,IAAAQ,cAAM,EAACO,iBAAM,CAAC,CAACC,OAAO,CAAC,iBAAiB,CAAC;IACzC,IAAAR,cAAM,EAAC,IAAAL,oBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAACW,IAAI,CAAC,KAAKC,iBAAM,IAAI,CAAC;EACjD,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasTrace = hasTrace;
|
|
7
|
+
exports.traceEntries = traceEntries;
|
|
8
|
+
exports.traceToText = traceToText;
|
|
9
|
+
/**
|
|
10
|
+
* The agent's work for one answer, laid out in the order it happened.
|
|
11
|
+
*
|
|
12
|
+
* `traceEntries` is the ordering, shared by the collapsible strip in the chat
|
|
13
|
+
* and by the JSON export — the two must agree, because the point of the export
|
|
14
|
+
* is reading elsewhere the run you were just looking at. `traceToText` is the
|
|
15
|
+
* plain-text rendering, kept for a quick paste into Slack; the debugging
|
|
16
|
+
* artefact is `sessionExport.ts`.
|
|
17
|
+
*
|
|
18
|
+
* Reasoning and steps INTERLEAVE. One assistant bubble spans every turn of a
|
|
19
|
+
* multi-step run, so the real shape is "think, act, think, act"; lumping the
|
|
20
|
+
* thoughts at the top would misreport when the model knew what.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function traceEntries(message) {
|
|
24
|
+
const thoughts = [...(message.reasoning ?? [])].sort((a, b) => a.afterCalls - b.afterCalls);
|
|
25
|
+
const out = [];
|
|
26
|
+
let t = 0;
|
|
27
|
+
const drainTo = calls => {
|
|
28
|
+
while (t < thoughts.length && thoughts[t].afterCalls <= calls) {
|
|
29
|
+
out.push({
|
|
30
|
+
kind: "thought",
|
|
31
|
+
text: thoughts[t].text
|
|
32
|
+
});
|
|
33
|
+
t += 1;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
message.toolCalls.forEach((call, i) => {
|
|
37
|
+
drainTo(i);
|
|
38
|
+
out.push({
|
|
39
|
+
kind: "step",
|
|
40
|
+
n: i + 1,
|
|
41
|
+
call
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
// Anything the model thought after its last tool call — usually the reasoning
|
|
45
|
+
// behind the answer itself, which is the most useful line in the trace.
|
|
46
|
+
drainTo(message.toolCalls.length);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Has this message anything to show? Drives whether the strip renders at all. */
|
|
51
|
+
function hasTrace(message) {
|
|
52
|
+
return (message.reasoning?.length ?? 0) > 0 || message.toolCalls.length > 0;
|
|
53
|
+
}
|
|
54
|
+
const statusWord = call => call.status === "ok" ? call.summary || "done" : call.status === "running" ? "running" : `${call.status}${call.summary ? ` — ${call.summary}` : ""}`;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The trace as plain text, for the clipboard.
|
|
58
|
+
*
|
|
59
|
+
* Indented under the answer it belongs to so a pasted session still reads as a
|
|
60
|
+
* conversation rather than a log dump.
|
|
61
|
+
*/
|
|
62
|
+
function traceToText(message, indent = " ") {
|
|
63
|
+
const lines = [];
|
|
64
|
+
for (const entry of traceEntries(message)) {
|
|
65
|
+
if (entry.kind === "thought") {
|
|
66
|
+
lines.push(`${indent}[thinking]`);
|
|
67
|
+
for (const line of entry.text.trim().split("\n")) {
|
|
68
|
+
lines.push(`${indent} ${line}`);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
const {
|
|
72
|
+
n,
|
|
73
|
+
call
|
|
74
|
+
} = entry;
|
|
75
|
+
lines.push(`${indent}[${n}] ${call.toolId}.${call.action} — ${statusWord(call)}`);
|
|
76
|
+
if (call.params) lines.push(`${indent} ${call.params}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return lines;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=traceText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["traceEntries","message","thoughts","reasoning","sort","a","b","afterCalls","out","t","drainTo","calls","length","push","kind","text","toolCalls","forEach","call","i","n","hasTrace","statusWord","status","summary","traceToText","indent","lines","entry","line","trim","split","toolId","action","params"],"sourceRoot":"../../../src","sources":["store/traceText.ts"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOO,SAASA,YAAYA,CAACC,OAAoB,EAAgB;EAC/D,MAAMC,QAAyB,GAAG,CAAC,IAAID,OAAO,CAACE,SAAS,IAAI,EAAE,CAAC,CAAC,CAACC,IAAI,CACnE,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAACE,UAAU,GAAGD,CAAC,CAACC,UAC7B,CAAC;EACD,MAAMC,GAAiB,GAAG,EAAE;EAC5B,IAAIC,CAAC,GAAG,CAAC;EACT,MAAMC,OAAO,GAAIC,KAAa,IAAK;IACjC,OAAOF,CAAC,GAAGP,QAAQ,CAACU,MAAM,IAAIV,QAAQ,CAACO,CAAC,CAAC,CAAEF,UAAU,IAAII,KAAK,EAAE;MAC9DH,GAAG,CAACK,IAAI,CAAC;QAAEC,IAAI,EAAE,SAAS;QAAEC,IAAI,EAAEb,QAAQ,CAACO,CAAC,CAAC,CAAEM;MAAK,CAAC,CAAC;MACtDN,CAAC,IAAI,CAAC;IACR;EACF,CAAC;EACDR,OAAO,CAACe,SAAS,CAACC,OAAO,CAAC,CAACC,IAAI,EAAEC,CAAC,KAAK;IACrCT,OAAO,CAACS,CAAC,CAAC;IACVX,GAAG,CAACK,IAAI,CAAC;MAAEC,IAAI,EAAE,MAAM;MAAEM,CAAC,EAAED,CAAC,GAAG,CAAC;MAAED;IAAK,CAAC,CAAC;EAC5C,CAAC,CAAC;EACF;EACA;EACAR,OAAO,CAACT,OAAO,CAACe,SAAS,CAACJ,MAAM,CAAC;EACjC,OAAOJ,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C,GAAGa,MAAM,OAAOR,IAAI,CAACgB,MAAM,EAAE,CAAC;IAC5D;EACF;EACA,OAAOP,KAAK;AACd","ignoreList":[]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _traceText = require("./traceText");
|
|
5
|
+
/**
|
|
6
|
+
* The agent's working, as text.
|
|
7
|
+
*
|
|
8
|
+
* This exists so a tester can paste a run somewhere and find the step that
|
|
9
|
+
* broke, which puts two properties on it: reasoning and steps come out in the
|
|
10
|
+
* order they HAPPENED (a multi-step turn is think, act, think, act — not all
|
|
11
|
+
* the thoughts and then all the steps), and a failed step says so with its
|
|
12
|
+
* parameters attached, since "storage.set failed" without the value it wrote
|
|
13
|
+
* is not a bug report.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const call = (over = {}) => ({
|
|
17
|
+
id: "c1",
|
|
18
|
+
toolId: "zustand",
|
|
19
|
+
action: "getStoreState",
|
|
20
|
+
label: "Read the bag",
|
|
21
|
+
status: "ok",
|
|
22
|
+
summary: "Done",
|
|
23
|
+
...over
|
|
24
|
+
});
|
|
25
|
+
const msg = (over = {}) => ({
|
|
26
|
+
id: "m1",
|
|
27
|
+
role: "assistant",
|
|
28
|
+
text: "Five items.",
|
|
29
|
+
toolCalls: [],
|
|
30
|
+
blocks: [],
|
|
31
|
+
...over
|
|
32
|
+
});
|
|
33
|
+
(0, _vitest.describe)("the order of a trace", () => {
|
|
34
|
+
(0, _vitest.it)("interleaves thinking with the steps it led to", () => {
|
|
35
|
+
const m = msg({
|
|
36
|
+
toolCalls: [call({
|
|
37
|
+
id: "c1"
|
|
38
|
+
}), call({
|
|
39
|
+
id: "c2",
|
|
40
|
+
action: "setState"
|
|
41
|
+
})],
|
|
42
|
+
reasoning: [{
|
|
43
|
+
text: "I should read the bag first.",
|
|
44
|
+
afterCalls: 0
|
|
45
|
+
}, {
|
|
46
|
+
text: "Now I can write the new quantity.",
|
|
47
|
+
afterCalls: 1
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
(0, _vitest.expect)((0, _traceText.traceEntries)(m).map(e => e.kind === "thought" ? "T" : `S${e.n}`)).toEqual(["T", "S1", "T", "S2"]);
|
|
51
|
+
});
|
|
52
|
+
(0, _vitest.it)("keeps a closing thought after the last step", () => {
|
|
53
|
+
// Usually the reasoning behind the ANSWER, which is the most useful line
|
|
54
|
+
// in the whole trace.
|
|
55
|
+
const m = msg({
|
|
56
|
+
toolCalls: [call()],
|
|
57
|
+
reasoning: [{
|
|
58
|
+
text: "That is everything the user asked for.",
|
|
59
|
+
afterCalls: 1
|
|
60
|
+
}]
|
|
61
|
+
});
|
|
62
|
+
const entries = (0, _traceText.traceEntries)(m);
|
|
63
|
+
(0, _vitest.expect)(entries[entries.length - 1]).toEqual({
|
|
64
|
+
kind: "thought",
|
|
65
|
+
text: "That is everything the user asked for."
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
(0, _vitest.it)("handles a turn with steps and no reasoning at all", () => {
|
|
69
|
+
// The common case: gpt-4.1 and friends report none.
|
|
70
|
+
const m = msg({
|
|
71
|
+
toolCalls: [call()]
|
|
72
|
+
});
|
|
73
|
+
(0, _vitest.expect)((0, _traceText.traceEntries)(m)).toHaveLength(1);
|
|
74
|
+
(0, _vitest.expect)((0, _traceText.hasTrace)(m)).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
(0, _vitest.it)("has nothing to show for a plain answer", () => {
|
|
77
|
+
(0, _vitest.expect)((0, _traceText.hasTrace)(msg())).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
(0, _vitest.describe)("the text it produces", () => {
|
|
81
|
+
(0, _vitest.it)("names the tool, the action, the outcome and the parameters", () => {
|
|
82
|
+
const m = msg({
|
|
83
|
+
toolCalls: [call({
|
|
84
|
+
params: '{"storeName":"Poké Mart bag"}'
|
|
85
|
+
})]
|
|
86
|
+
});
|
|
87
|
+
(0, _vitest.expect)((0, _traceText.traceToText)(m)).toEqual([" [1] zustand.getStoreState — Done", ' {"storeName":"Poké Mart bag"}']);
|
|
88
|
+
});
|
|
89
|
+
(0, _vitest.it)("makes a failure and its parameters findable", () => {
|
|
90
|
+
const m = msg({
|
|
91
|
+
toolCalls: [call({
|
|
92
|
+
toolId: "storage",
|
|
93
|
+
action: "async.setItem",
|
|
94
|
+
status: "failed",
|
|
95
|
+
summary: "key not found",
|
|
96
|
+
params: '{"key":"@pokemart/bag"}'
|
|
97
|
+
})]
|
|
98
|
+
});
|
|
99
|
+
(0, _vitest.expect)((0, _traceText.traceToText)(m).join("\n")).toContain("failed — key not found");
|
|
100
|
+
(0, _vitest.expect)((0, _traceText.traceToText)(m).join("\n")).toContain("@pokemart/bag");
|
|
101
|
+
});
|
|
102
|
+
(0, _vitest.it)("indents a multi-line thought so a pasted session still reads as one", () => {
|
|
103
|
+
const m = msg({
|
|
104
|
+
reasoning: [{
|
|
105
|
+
text: "First line.\nSecond line.",
|
|
106
|
+
afterCalls: 0
|
|
107
|
+
}]
|
|
108
|
+
});
|
|
109
|
+
(0, _vitest.expect)((0, _traceText.traceToText)(m)).toEqual([" [thinking]", " First line.", " Second line."]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=traceText.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_vitest","require","_traceText","call","over","id","toolId","action","label","status","summary","msg","role","text","toolCalls","blocks","describe","it","m","reasoning","afterCalls","expect","traceEntries","map","e","kind","n","toEqual","entries","length","toHaveLength","hasTrace","toBe","params","traceToText","join","toContain"],"sourceRoot":"../../../src","sources":["store/traceText.test.ts"],"mappings":";;AAUA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,MAAME,IAAI,GAAGA,CAACC,IAA2B,GAAG,CAAC,CAAC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