@buoy-gg/agent-core 7.0.41 → 7.0.43

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