@buoy-gg/agent-core 7.0.41 → 7.0.42
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/lib/commonjs/blocks/receipts.js +1 -761
- package/lib/commonjs/blocks/runId.js +1 -31
- package/lib/commonjs/blocks/types.js +1 -140
- package/lib/commonjs/blocks/uiTool.js +6 -1405
- package/lib/commonjs/catalog/catalog.g.js +5 -4556
- package/lib/commonjs/catalog/catalog.source.json +249 -0
- package/lib/commonjs/catalog/catalog.types.g.js +1 -46
- package/lib/commonjs/catalog/normalizeParams.js +2 -332
- package/lib/commonjs/catalog/signature.js +1 -68
- package/lib/commonjs/catalog/snapshotReads.js +1 -263
- package/lib/commonjs/catalog/toProviderTools.js +2 -145
- package/lib/commonjs/catalog/validateParams.js +1 -129
- package/lib/commonjs/context/buildContextPack.js +1 -489
- package/lib/commonjs/effects/digest.js +1 -34
- package/lib/commonjs/effects/ledger.js +1 -345
- package/lib/commonjs/engine/askGate.js +1 -287
- package/lib/commonjs/engine/effectFor.js +1 -223
- package/lib/commonjs/engine/evidence.js +3 -111
- package/lib/commonjs/engine/historyBudget.js +1 -363
- package/lib/commonjs/engine/retrieve.js +1 -214
- package/lib/commonjs/engine/runAgentTurn.js +8 -1836
- package/lib/commonjs/engine/systemPrompt.js +54 -163
- package/lib/commonjs/engine/textToolCalls.js +1 -276
- package/lib/commonjs/engine/tokenCalibration.js +1 -81
- package/lib/commonjs/engine/verify.js +4 -297
- package/lib/commonjs/index.js +1 -384
- package/lib/commonjs/policy/labels.js +1 -319
- package/lib/commonjs/policy/policy.js +1 -148
- package/lib/commonjs/policy/redact.js +1 -172
- package/lib/commonjs/providers/anthropic.js +3 -445
- package/lib/commonjs/providers/openai.js +4 -324
- package/lib/commonjs/providers/problem.js +1 -98
- package/lib/commonjs/providers/sse.js +1 -240
- package/lib/commonjs/providers/streamTimer.js +1 -123
- package/lib/commonjs/providers/transport.js +1 -123
- package/lib/commonjs/providers/types.js +1 -6
- package/lib/commonjs/providers/xhrStream.js +1 -212
- package/lib/commonjs/realNow.js +1 -0
- package/lib/commonjs/session.js +1 -393
- package/lib/commonjs/types.js +0 -1
- package/lib/module/blocks/receipts.js +1 -755
- package/lib/module/blocks/runId.js +1 -26
- package/lib/module/blocks/types.js +1 -134
- package/lib/module/blocks/uiTool.js +6 -1396
- package/lib/module/catalog/catalog.g.js +5 -4552
- package/lib/module/catalog/catalog.source.json +249 -0
- package/lib/module/catalog/catalog.types.g.js +1 -42
- package/lib/module/catalog/normalizeParams.js +2 -326
- package/lib/module/catalog/signature.js +1 -63
- package/lib/module/catalog/snapshotReads.js +1 -259
- package/lib/module/catalog/toProviderTools.js +2 -139
- package/lib/module/catalog/validateParams.js +1 -124
- package/lib/module/context/buildContextPack.js +1 -485
- package/lib/module/effects/digest.js +1 -29
- package/lib/module/effects/ledger.js +1 -339
- package/lib/module/engine/askGate.js +1 -280
- package/lib/module/engine/effectFor.js +1 -220
- package/lib/module/engine/evidence.js +3 -105
- package/lib/module/engine/historyBudget.js +1 -355
- package/lib/module/engine/retrieve.js +1 -210
- package/lib/module/engine/runAgentTurn.js +8 -1827
- package/lib/module/engine/systemPrompt.js +54 -157
- package/lib/module/engine/textToolCalls.js +1 -270
- package/lib/module/engine/tokenCalibration.js +1 -75
- package/lib/module/engine/verify.js +4 -289
- package/lib/module/index.js +1 -35
- package/lib/module/policy/labels.js +1 -312
- package/lib/module/policy/policy.js +1 -142
- package/lib/module/policy/redact.js +1 -165
- package/lib/module/providers/anthropic.js +3 -441
- package/lib/module/providers/openai.js +4 -320
- package/lib/module/providers/problem.js +1 -92
- package/lib/module/providers/sse.js +1 -231
- package/lib/module/providers/streamTimer.js +1 -118
- package/lib/module/providers/transport.js +1 -119
- package/lib/module/providers/types.js +1 -4
- package/lib/module/providers/xhrStream.js +1 -207
- package/lib/module/realNow.js +1 -0
- package/lib/module/session.js +1 -369
- package/lib/module/types.js +0 -1
- package/lib/typescript/catalog/catalog.g.d.ts +3 -3
- package/lib/typescript/catalog/catalog.types.g.d.ts +3 -2
- package/lib/typescript/providers/problem.d.ts +0 -20
- package/lib/typescript/providers/streamTimer.d.ts +0 -24
- package/lib/typescript/realNow.d.ts +18 -0
- package/lib/web/index.mjs +52 -53
- package/package.json +1 -1
- package/lib/commonjs/blocks/receipts.js.map +0 -1
- package/lib/commonjs/blocks/runId.js.map +0 -1
- package/lib/commonjs/blocks/types.js.map +0 -1
- package/lib/commonjs/blocks/uiTool.js.map +0 -1
- package/lib/commonjs/catalog/catalog.g.js.map +0 -1
- package/lib/commonjs/catalog/catalog.types.g.js.map +0 -1
- package/lib/commonjs/catalog/normalizeParams.js.map +0 -1
- package/lib/commonjs/catalog/signature.js.map +0 -1
- package/lib/commonjs/catalog/snapshotReads.js.map +0 -1
- package/lib/commonjs/catalog/toProviderTools.js.map +0 -1
- package/lib/commonjs/catalog/validateParams.js.map +0 -1
- package/lib/commonjs/context/buildContextPack.js.map +0 -1
- package/lib/commonjs/effects/digest.js.map +0 -1
- package/lib/commonjs/effects/ledger.js.map +0 -1
- package/lib/commonjs/engine/askGate.js.map +0 -1
- package/lib/commonjs/engine/effectFor.js.map +0 -1
- package/lib/commonjs/engine/evidence.js.map +0 -1
- package/lib/commonjs/engine/historyBudget.js.map +0 -1
- package/lib/commonjs/engine/retrieve.js.map +0 -1
- package/lib/commonjs/engine/runAgentTurn.js.map +0 -1
- package/lib/commonjs/engine/systemPrompt.js.map +0 -1
- package/lib/commonjs/engine/textToolCalls.js.map +0 -1
- package/lib/commonjs/engine/tokenCalibration.js.map +0 -1
- package/lib/commonjs/engine/verify.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/policy/labels.js.map +0 -1
- package/lib/commonjs/policy/policy.js.map +0 -1
- package/lib/commonjs/policy/redact.js.map +0 -1
- package/lib/commonjs/providers/anthropic.js.map +0 -1
- package/lib/commonjs/providers/openai.js.map +0 -1
- package/lib/commonjs/providers/problem.js.map +0 -1
- package/lib/commonjs/providers/sse.js.map +0 -1
- package/lib/commonjs/providers/streamTimer.js.map +0 -1
- package/lib/commonjs/providers/transport.js.map +0 -1
- package/lib/commonjs/providers/types.js.map +0 -1
- package/lib/commonjs/providers/xhrStream.js.map +0 -1
- package/lib/commonjs/session.js.map +0 -1
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/blocks/receipts.js.map +0 -1
- package/lib/module/blocks/runId.js.map +0 -1
- package/lib/module/blocks/types.js.map +0 -1
- package/lib/module/blocks/uiTool.js.map +0 -1
- package/lib/module/catalog/catalog.g.js.map +0 -1
- package/lib/module/catalog/catalog.types.g.js.map +0 -1
- package/lib/module/catalog/normalizeParams.js.map +0 -1
- package/lib/module/catalog/signature.js.map +0 -1
- package/lib/module/catalog/snapshotReads.js.map +0 -1
- package/lib/module/catalog/toProviderTools.js.map +0 -1
- package/lib/module/catalog/validateParams.js.map +0 -1
- package/lib/module/context/buildContextPack.js.map +0 -1
- package/lib/module/effects/digest.js.map +0 -1
- package/lib/module/effects/ledger.js.map +0 -1
- package/lib/module/engine/askGate.js.map +0 -1
- package/lib/module/engine/effectFor.js.map +0 -1
- package/lib/module/engine/evidence.js.map +0 -1
- package/lib/module/engine/historyBudget.js.map +0 -1
- package/lib/module/engine/retrieve.js.map +0 -1
- package/lib/module/engine/runAgentTurn.js.map +0 -1
- package/lib/module/engine/systemPrompt.js.map +0 -1
- package/lib/module/engine/textToolCalls.js.map +0 -1
- package/lib/module/engine/tokenCalibration.js.map +0 -1
- package/lib/module/engine/verify.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/policy/labels.js.map +0 -1
- package/lib/module/policy/policy.js.map +0 -1
- package/lib/module/policy/redact.js.map +0 -1
- package/lib/module/providers/anthropic.js.map +0 -1
- package/lib/module/providers/openai.js.map +0 -1
- package/lib/module/providers/problem.js.map +0 -1
- package/lib/module/providers/sse.js.map +0 -1
- package/lib/module/providers/streamTimer.js.map +0 -1
- package/lib/module/providers/transport.js.map +0 -1
- package/lib/module/providers/types.js.map +0 -1
- package/lib/module/providers/xhrStream.js.map +0 -1
- package/lib/module/session.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/blocks/receipts.d.ts.map +0 -1
- package/lib/typescript/blocks/runId.d.ts.map +0 -1
- package/lib/typescript/blocks/types.d.ts.map +0 -1
- package/lib/typescript/blocks/uiTool.d.ts.map +0 -1
- package/lib/typescript/catalog/catalog.g.d.ts.map +0 -1
- package/lib/typescript/catalog/catalog.types.g.d.ts.map +0 -1
- package/lib/typescript/catalog/normalizeParams.d.ts.map +0 -1
- package/lib/typescript/catalog/signature.d.ts.map +0 -1
- package/lib/typescript/catalog/snapshotReads.d.ts.map +0 -1
- package/lib/typescript/catalog/toProviderTools.d.ts.map +0 -1
- package/lib/typescript/catalog/validateParams.d.ts.map +0 -1
- package/lib/typescript/context/buildContextPack.d.ts.map +0 -1
- package/lib/typescript/effects/digest.d.ts.map +0 -1
- package/lib/typescript/effects/ledger.d.ts.map +0 -1
- package/lib/typescript/engine/askGate.d.ts.map +0 -1
- package/lib/typescript/engine/effectFor.d.ts.map +0 -1
- package/lib/typescript/engine/evidence.d.ts.map +0 -1
- package/lib/typescript/engine/historyBudget.d.ts.map +0 -1
- package/lib/typescript/engine/retrieve.d.ts.map +0 -1
- package/lib/typescript/engine/runAgentTurn.d.ts.map +0 -1
- package/lib/typescript/engine/systemPrompt.d.ts.map +0 -1
- package/lib/typescript/engine/textToolCalls.d.ts.map +0 -1
- package/lib/typescript/engine/tokenCalibration.d.ts.map +0 -1
- package/lib/typescript/engine/verify.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/policy/labels.d.ts.map +0 -1
- package/lib/typescript/policy/policy.d.ts.map +0 -1
- package/lib/typescript/policy/redact.d.ts.map +0 -1
- package/lib/typescript/providers/anthropic.d.ts.map +0 -1
- package/lib/typescript/providers/openai.d.ts.map +0 -1
- package/lib/typescript/providers/problem.d.ts.map +0 -1
- package/lib/typescript/providers/sse.d.ts.map +0 -1
- package/lib/typescript/providers/streamTimer.d.ts.map +0 -1
- package/lib/typescript/providers/transport.d.ts.map +0 -1
- package/lib/typescript/providers/types.d.ts.map +0 -1
- package/lib/typescript/providers/xhrStream.d.ts.map +0 -1
- package/lib/typescript/session.d.ts.map +0 -1
- package/lib/typescript/types.d.ts.map +0 -1
|
@@ -1,220 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Turn a completed mutation into a ledger entry.
|
|
5
|
-
*
|
|
6
|
-
* The shape is Scenarios' `extractEffect`, but the classification here is much
|
|
7
|
-
* more conservative, because auditing the catalog's undo claims found almost
|
|
8
|
-
* all of them unsound: the information needed to reverse a call usually does
|
|
9
|
-
* not survive the call. So an effect is only marked reversible when THIS
|
|
10
|
-
* module can point at the exact input the reversal needs.
|
|
11
|
-
*
|
|
12
|
-
* Everything else becomes `state-write` (changed something, no automatic
|
|
13
|
-
* inverse) or `transient` (one-shot). Both are shown to the user as such. A
|
|
14
|
-
* banner that says "4 changes" and then reverses one of them is worse than a
|
|
15
|
-
* banner that admits three of them are permanent.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { describeCall } from "../policy/policy";
|
|
19
|
-
import { digestOf, jsonLength } from "../effects/digest";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The largest prior value an undo will hold. The ledger is persisted with the
|
|
23
|
-
* transcript under a 256KB cap; a payload past this is recorded as a visible,
|
|
24
|
-
* honestly-permanent change instead of silently evicting the conversation.
|
|
25
|
-
*/
|
|
26
|
-
const MAX_UNDO_JSON_CHARS = 64_000;
|
|
27
|
-
|
|
28
|
-
/** The `getQueryData` read the engine takes on both sides of a cache write. */
|
|
29
|
-
|
|
30
|
-
const cacheRead = v => v && typeof v === "object" ? v : undefined;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* How each query change is actually put back, named in the row so the bar is
|
|
34
|
-
* useful rather than merely honest. A cache edit's real inverse is a refetch:
|
|
35
|
-
* the tool's own description says a cache edit "lasts until the next
|
|
36
|
-
* successful refetch".
|
|
37
|
-
*/
|
|
38
|
-
const QUERY_RESTORES = {
|
|
39
|
-
setQueryData: "query.invalidate",
|
|
40
|
-
triggerError: "query.restoreError",
|
|
41
|
-
triggerLoading: "query.restoreLoading",
|
|
42
|
-
setOnline: "query.setOnline"
|
|
43
|
-
};
|
|
44
|
-
export function effectFor(toolId, descriptor, params, result, before, /** The query cache read before and after a `setQueryData` — see runAgentTurn. */
|
|
45
|
-
cache) {
|
|
46
|
-
const label = describeCall(toolId, descriptor, params);
|
|
47
|
-
const rec = result ?? {};
|
|
48
|
-
|
|
49
|
-
// A network override rule. Reversible ONLY when we created it: `upsert` with
|
|
50
|
-
// an id that already exists UPDATES that rule in place, so deleting it would
|
|
51
|
-
// destroy a rule the user had set up themselves rather than undo our change.
|
|
52
|
-
// The model supplying no id is the create case.
|
|
53
|
-
if (toolId === "network" && descriptor.action === "upsertOverrideRule") {
|
|
54
|
-
const rule = rec.rule;
|
|
55
|
-
const ruleId = rule?.id ?? rec.id;
|
|
56
|
-
const wasCreate = params.id === undefined;
|
|
57
|
-
if (ruleId && wasCreate) return {
|
|
58
|
-
kind: "network-override",
|
|
59
|
-
ruleId,
|
|
60
|
-
label
|
|
61
|
-
};
|
|
62
|
-
return {
|
|
63
|
-
kind: "state-write",
|
|
64
|
-
toolId,
|
|
65
|
-
action: descriptor.action,
|
|
66
|
-
label
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Impersonation. `stopImpersonation` restores the identity but ALSO re-runs
|
|
71
|
-
// the data nuke — it clears react-query, redux, AsyncStorage and MMKV per
|
|
72
|
-
// the app's dataNukeSettings. So this is reversible in the sense that
|
|
73
|
-
// matters (the user stops being someone else) and the label has to say the
|
|
74
|
-
// rest out loud, because caches do not come back.
|
|
75
|
-
if (toolId === "impersonate" && descriptor.action === "startImpersonation") {
|
|
76
|
-
return {
|
|
77
|
-
kind: "impersonation",
|
|
78
|
-
label: `${label} — stopping also clears cached app data`
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Storage, reversible because we read the old value first (see captureBefore).
|
|
83
|
-
// `before` is undefined when the pre-read could not be made — an MMKV write
|
|
84
|
-
// with no instance, a secure key behind biometrics — and that must fall
|
|
85
|
-
// through to a one-off rather than claim an undo it cannot perform.
|
|
86
|
-
if (toolId === "storage" && typeof params.key === "string" && before) {
|
|
87
|
-
const isMmkv = descriptor.action.startsWith("mmkv.");
|
|
88
|
-
const writeAction = isMmkv ? "mmkv.set" : "async.setItem";
|
|
89
|
-
return {
|
|
90
|
-
kind: "storage-write",
|
|
91
|
-
toolId,
|
|
92
|
-
action: writeAction,
|
|
93
|
-
key: params.key,
|
|
94
|
-
instanceId: isMmkv && typeof params.instanceId === "string" ? params.instanceId : undefined,
|
|
95
|
-
before: before.had ? before.value : undefined,
|
|
96
|
-
wrote: typeof params.value === "string" ? params.value : undefined,
|
|
97
|
-
removeAction: isMmkv ? "mmkv.remove" : "async.removeItem",
|
|
98
|
-
label
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* A cache edit is a CHANGE, not a one-shot.
|
|
104
|
-
*
|
|
105
|
-
* `setQueryData` is the headline write of the whole product — "THE way to
|
|
106
|
-
* change what a server-backed screen shows" — and it fell through to
|
|
107
|
-
* `transient` here, which the changes bar deliberately does not count. So
|
|
108
|
-
* the sheet said "Anything it changes shows up in a bar at the top, and you
|
|
109
|
-
* can undo it" and then changed the screen in front of you with no row, no
|
|
110
|
-
* count and no undo. Same for `triggerError` and `triggerLoading`: the app
|
|
111
|
-
* is left showing a failure state that nothing on screen admits to putting
|
|
112
|
-
* there, which is exactly how a QA tester files a bug against a state Buoy
|
|
113
|
-
* created.
|
|
114
|
-
*
|
|
115
|
-
* `setQueryData` is now a real `query-write` above, because the engine
|
|
116
|
-
* reads the query's data before the write (captureStoreState) — the same
|
|
117
|
-
* pre-read that makes storage reversible. The rest — triggerError,
|
|
118
|
-
* triggerLoading, setOnline, a setQueryData whose pre-read failed — stay
|
|
119
|
-
* `state-write` (visible, honestly permanent): this module only claims an
|
|
120
|
-
* undo it can actually perform, and the label carries the real revert so
|
|
121
|
-
* the row is still useful.
|
|
122
|
-
*/
|
|
123
|
-
if (toolId === "query" && descriptor.action === "setQueryData") {
|
|
124
|
-
const prior = cacheRead(cache?.before);
|
|
125
|
-
const queryHash = typeof params.queryHash === "string" ? params.queryHash : prior?.queryHash;
|
|
126
|
-
if (prior?.found === true && typeof queryHash === "string") {
|
|
127
|
-
const had = prior.hasData !== false && prior.data !== undefined;
|
|
128
|
-
const beforeData = had ? prior.data : undefined;
|
|
129
|
-
if (jsonLength(beforeData) <= MAX_UNDO_JSON_CHARS) {
|
|
130
|
-
const after = cacheRead(cache?.after);
|
|
131
|
-
const wroteDigest = after?.found === true && after.hasData !== false ? digestOf(after.data) : undefined;
|
|
132
|
-
return {
|
|
133
|
-
kind: "query-write",
|
|
134
|
-
queryHash,
|
|
135
|
-
before: beforeData,
|
|
136
|
-
wroteDigest,
|
|
137
|
-
label
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
kind: "state-write",
|
|
142
|
-
toolId,
|
|
143
|
-
action: descriptor.action,
|
|
144
|
-
label: `${label} — prior value too large to hold for undo; undo with query.invalidate`
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Loading and error pins have a documented, exact inverse by queryHash.
|
|
150
|
-
if (toolId === "query" && typeof params.queryHash === "string") {
|
|
151
|
-
const inverse = descriptor.action === "triggerLoading" ? "restoreLoading" : descriptor.action === "triggerError" ? "restoreError" : undefined;
|
|
152
|
-
if (inverse) {
|
|
153
|
-
return {
|
|
154
|
-
kind: "inverse-call",
|
|
155
|
-
toolId,
|
|
156
|
-
action: inverse,
|
|
157
|
-
params: {
|
|
158
|
-
queryHash: params.queryHash
|
|
159
|
-
},
|
|
160
|
-
label
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// A refetch or invalidate brings the server's data back; it changes nothing
|
|
166
|
-
// Undo could put back. Counting it "permanent" read as if Ask Buoy had left
|
|
167
|
-
// the app altered after a plain refresh.
|
|
168
|
-
if (toolId === "query" && ["refetch", "invalidate", "restoreLoading"].includes(descriptor.action)) {
|
|
169
|
-
return {
|
|
170
|
-
kind: "transient",
|
|
171
|
-
label
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// A rule's switch, reversible because the engine read the flag first
|
|
176
|
-
// (captureRuleSwitch). A toggle that left the flag where it was is no change.
|
|
177
|
-
if (toolId === "network" && (descriptor.action === "setOverrideRuleEnabled" || descriptor.action === "setOverridesEnabled") && before?.had && (before.value === "true" || before.value === "false")) {
|
|
178
|
-
const was = before.value === "true";
|
|
179
|
-
const now = params.enabled === true;
|
|
180
|
-
if (was === now) return undefined;
|
|
181
|
-
const inverseParams = descriptor.action === "setOverrideRuleEnabled" ? {
|
|
182
|
-
id: params.id,
|
|
183
|
-
enabled: was
|
|
184
|
-
} : {
|
|
185
|
-
enabled: was
|
|
186
|
-
};
|
|
187
|
-
return {
|
|
188
|
-
kind: "inverse-call",
|
|
189
|
-
toolId,
|
|
190
|
-
action: descriptor.action,
|
|
191
|
-
params: inverseParams,
|
|
192
|
-
label
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
if (toolId === "query" && descriptor.effect !== "read") {
|
|
196
|
-
const restores = QUERY_RESTORES[descriptor.action];
|
|
197
|
-
return {
|
|
198
|
-
kind: "state-write",
|
|
199
|
-
toolId,
|
|
200
|
-
action: descriptor.action,
|
|
201
|
-
label: restores ? `${label} — undo with ${restores}` : label
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Wipes with no captured prior state are permanent. Say so rather than
|
|
206
|
-
// filing them under something Undo appears to cover.
|
|
207
|
-
if (descriptor.effect === "destructive") {
|
|
208
|
-
return {
|
|
209
|
-
kind: "state-write",
|
|
210
|
-
toolId,
|
|
211
|
-
action: descriptor.action,
|
|
212
|
-
label
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
return {
|
|
216
|
-
kind: "transient",
|
|
217
|
-
label
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
//# sourceMappingURL=effectFor.js.map
|
|
1
|
+
"use strict";import{describeCall as v}from"../policy/policy";import{digestOf as k,jsonLength as h}from"../effects/digest";const q=64e3;const l=n=>n&&typeof n==="object"?n:void 0;const w={setQueryData:"query.invalidate",triggerError:"query.restoreError",triggerLoading:"query.restoreLoading",setOnline:"query.setOnline"};export function effectFor(n,t,i,y,u,c){const r=v(n,t,i);const f=y??{};if(n==="network"&&t.action==="upsertOverrideRule"){const e=f.rule;const a=e?.id??f.id;const s=i.id===void 0;if(a&&s)return{kind:"network-override",ruleId:a,label:r};return{kind:"state-write",toolId:n,action:t.action,label:r}}if(n==="impersonate"&&t.action==="startImpersonation"){return{kind:"impersonation",label:`${r} \u2014 stopping also clears cached app data`}}if(n==="storage"&&typeof i.key==="string"&&u){const e=t.action.startsWith("mmkv.");const a=e?"mmkv.set":"async.setItem";return{kind:"storage-write",toolId:n,action:a,key:i.key,instanceId:e&&typeof i.instanceId==="string"?i.instanceId:void 0,before:u.had?u.value:void 0,wrote:typeof i.value==="string"?i.value:void 0,removeAction:e?"mmkv.remove":"async.removeItem",label:r}}if(n==="query"&&t.action==="setQueryData"){const e=l(c?.before);const a=typeof i.queryHash==="string"?i.queryHash:e?.queryHash;if(e?.found===true&&typeof a==="string"){const s=e.hasData!==false&&e.data!==void 0;const d=s?e.data:void 0;if(h(d)<=q){const o=l(c?.after);const g=o?.found===true&&o.hasData!==false?k(o.data):void 0;return{kind:"query-write",queryHash:a,before:d,wroteDigest:g,label:r}}return{kind:"state-write",toolId:n,action:t.action,label:`${r} \u2014 prior value too large to hold for undo; undo with query.invalidate`}}}if(n==="query"&&typeof i.queryHash==="string"){const e=t.action==="triggerLoading"?"restoreLoading":t.action==="triggerError"?"restoreError":void 0;if(e){return{kind:"inverse-call",toolId:n,action:e,params:{queryHash:i.queryHash},label:r}}}if(n==="query"&&["refetch","invalidate","restoreLoading"].includes(t.action)){return{kind:"transient",label:r}}if(n==="network"&&(t.action==="setOverrideRuleEnabled"||t.action==="setOverridesEnabled")&&u?.had&&(u.value==="true"||u.value==="false")){const e=u.value==="true";const a=i.enabled===true;if(e===a)return void 0;const s=t.action==="setOverrideRuleEnabled"?{id:i.id,enabled:e}:{enabled:e};return{kind:"inverse-call",toolId:n,action:t.action,params:s,label:r}}if(n==="query"&&t.effect!=="read"){const e=w[t.action];return{kind:"state-write",toolId:n,action:t.action,label:e?`${r} \u2014 undo with ${e}`:r}}if(t.effect==="destructive"){return{kind:"state-write",toolId:n,action:t.action,label:r}}return{kind:"transient",label:r}}
|
|
@@ -1,107 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";const i=4e6;const n=200;export class EvidenceStore{entries=new Map;evictedRefs=new Set;chars=0;seq=0;constructor(e={}){this.maxChars=e.maxChars??i;this.maxEntries=e.maxEntries??n}stash(e){const t=`ev_${++this.seq}`;const s={...e,ref:t};this.entries.set(t,s);this.chars+=s.text.length;this.evict();return t}get(e){return this.entries.get(e)}wasEvicted(e){return this.evictedRefs.has(e)}get size(){return this.entries.size}get totalChars(){return this.chars}clear(){this.entries.clear();this.evictedRefs.clear();this.chars=0}evict(){for(const[e,t]of this.entries){const s=this.chars>this.maxChars||this.entries.size>this.maxEntries;if(!s||this.entries.size===1)return;this.entries.delete(e);this.evictedRefs.add(e);this.chars-=t.text.length}}}const a="ask-buoy.retrieve";export function truncationMarker(r,e){const t=r.toLocaleString("en-US");if(!e)return`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* The evidence store: every tool result this conversation produced, kept in
|
|
5
|
-
* full so the model can go back to it.
|
|
6
|
-
*
|
|
7
|
-
* Two markers used to point nowhere. A result over 24 000 characters was cut
|
|
8
|
-
* with "ask for a narrower slice" — and no tool offers one, so the bank has
|
|
9
|
-
* cases tagged `capability` (Pokémon `stats` sit at offset ~180 000 of a
|
|
10
|
-
* 400 000-character detail; unreadable by design). And a result compressed
|
|
11
|
-
* out of memory said "ask again" — a re-dispatch returns the CURRENT value,
|
|
12
|
-
* not what the model saw before it wrote, which is the one it needs when a
|
|
13
|
-
* write is refused and it has to say what it changed FROM.
|
|
14
|
-
*
|
|
15
|
-
* So the full text is kept here, keyed by a short ref the markers carry, and
|
|
16
|
-
* `ask-buoy.retrieve` reads any part of it back: a path, a substring, a
|
|
17
|
-
* window. Borrowed from Strands' ContextOffloader (`retrieve_offloaded_content`
|
|
18
|
-
* with pattern / line_range), minus the storage layer — this is in-memory and
|
|
19
|
-
* per session on purpose: persisted transcripts deliberately carry no tool
|
|
20
|
-
* result payloads (see ask-buoy transcriptPersistence.ts), and this must not
|
|
21
|
-
* quietly change that.
|
|
22
|
-
*
|
|
23
|
-
* What goes in is what the MODEL was given: after `redact` (credential names
|
|
24
|
-
* and value shapes) and `stripSelfTraffic`. Never the raw adapter value.
|
|
25
|
-
*
|
|
26
|
-
* Bounded by bytes and entries, oldest out first; an evicted ref is remembered
|
|
27
|
-
* so the answer is "evicted" rather than "never existed" — the marker still
|
|
28
|
-
* names a real thing, and the honest reply is to call the tool again.
|
|
29
|
-
*/
|
|
3
|
+
[truncated \u2014 ${t} characters total. Ask for a narrower slice if you need more.]`;return`
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const DEFAULT_MAX_ENTRIES = 200;
|
|
33
|
-
export class EvidenceStore {
|
|
34
|
-
entries = new Map();
|
|
35
|
-
evictedRefs = new Set();
|
|
36
|
-
chars = 0;
|
|
37
|
-
seq = 0;
|
|
38
|
-
constructor(opts = {}) {
|
|
39
|
-
this.maxChars = opts.maxChars ?? DEFAULT_MAX_CHARS;
|
|
40
|
-
this.maxEntries = opts.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Keep a result. Returns its ref — `ev_<n>`, counting up for the life of the store. */
|
|
44
|
-
stash(input) {
|
|
45
|
-
const ref = `ev_${++this.seq}`;
|
|
46
|
-
const entry = {
|
|
47
|
-
...input,
|
|
48
|
-
ref
|
|
49
|
-
};
|
|
50
|
-
// A single result larger than the whole store still gets a ref — it is
|
|
51
|
-
// the case the store exists for — and simply evicts everything else.
|
|
52
|
-
this.entries.set(ref, entry);
|
|
53
|
-
this.chars += entry.text.length;
|
|
54
|
-
this.evict();
|
|
55
|
-
return ref;
|
|
56
|
-
}
|
|
57
|
-
get(ref) {
|
|
58
|
-
return this.entries.get(ref);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** True when the ref was real and has since been dropped for space. */
|
|
62
|
-
wasEvicted(ref) {
|
|
63
|
-
return this.evictedRefs.has(ref);
|
|
64
|
-
}
|
|
65
|
-
get size() {
|
|
66
|
-
return this.entries.size;
|
|
67
|
-
}
|
|
68
|
-
get totalChars() {
|
|
69
|
-
return this.chars;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** New conversation: nothing from the old one is retrievable. */
|
|
73
|
-
clear() {
|
|
74
|
-
this.entries.clear();
|
|
75
|
-
this.evictedRefs.clear();
|
|
76
|
-
this.chars = 0;
|
|
77
|
-
}
|
|
78
|
-
evict() {
|
|
79
|
-
// Map iteration is insertion order, so the first key is the oldest.
|
|
80
|
-
for (const [ref, entry] of this.entries) {
|
|
81
|
-
const over = this.chars > this.maxChars || this.entries.size > this.maxEntries;
|
|
82
|
-
if (!over || this.entries.size === 1) return;
|
|
83
|
-
this.entries.delete(ref);
|
|
84
|
-
this.evictedRefs.add(ref);
|
|
85
|
-
this.chars -= entry.text.length;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ── the markers ──────────────────────────────────────────────────────────────
|
|
91
|
-
|
|
92
|
-
const RETRIEVE_HINT = "ask-buoy.retrieve";
|
|
93
|
-
|
|
94
|
-
/** The tail of a result cut at the engine's cap. */
|
|
95
|
-
export function truncationMarker(totalChars, ref) {
|
|
96
|
-
const size = totalChars.toLocaleString("en-US");
|
|
97
|
-
if (!ref) return `\n\n[truncated — ${size} characters total. Ask for a narrower slice if you need more.]`;
|
|
98
|
-
return `\n\n[truncated — ${size} characters total; ref ${ref}. Call ${RETRIEVE_HINT} {"ref":"${ref}"} to see its shape, then {"ref":"${ref}","path":"…"} or {"ref":"${ref}","pattern":"…"} to read the part you need.]`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** What a consumed result is replaced with when history is compressed. Keep the `[earlier result` prefix — historyBudget skips on it. */
|
|
102
|
-
export function compressedMarker(totalChars, ref) {
|
|
103
|
-
const size = totalChars.toLocaleString("en-US");
|
|
104
|
-
if (!ref) return `[earlier result — ${size} characters, already read. Ask again if you need it.]`;
|
|
105
|
-
return `[earlier result — ${size} characters, already read; ref ${ref}. ${RETRIEVE_HINT} {"ref":"${ref}",…} re-reads exactly what you saw then; calling the tool again gives the CURRENT value.]`;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=evidence.js.map
|
|
5
|
+
[truncated \u2014 ${t} characters total; ref ${e}. Call ${a} {"ref":"${e}"} to see its shape, then {"ref":"${e}","path":"\u2026"} or {"ref":"${e}","pattern":"\u2026"} to read the part you need.]`}export function compressedMarker(r,e){const t=r.toLocaleString("en-US");if(!e)return`[earlier result \u2014 ${t} characters, already read. Ask again if you need it.]`;return`[earlier result \u2014 ${t} characters, already read; ref ${e}. ${a} {"ref":"${e}",\u2026} re-reads exactly what you saw then; calling the tool again gives the CURRENT value.]`}
|