@buoy-gg/agent-core 7.0.34 → 7.0.36

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 (181) hide show
  1. package/README.md +10 -7
  2. package/lib/commonjs/blocks/receipts.js +83 -24
  3. package/lib/commonjs/blocks/receipts.js.map +1 -1
  4. package/lib/commonjs/blocks/runId.js +31 -0
  5. package/lib/commonjs/blocks/runId.js.map +1 -0
  6. package/lib/commonjs/blocks/types.js +23 -2
  7. package/lib/commonjs/blocks/types.js.map +1 -1
  8. package/lib/commonjs/blocks/uiTool.js +426 -12
  9. package/lib/commonjs/blocks/uiTool.js.map +1 -1
  10. package/lib/commonjs/catalog/catalog.g.js +121 -43
  11. package/lib/commonjs/catalog/catalog.g.js.map +1 -1
  12. package/lib/commonjs/catalog/catalog.source.json +121 -45
  13. package/lib/commonjs/catalog/catalog.types.g.js +44 -0
  14. package/lib/commonjs/catalog/catalog.types.g.js.map +1 -0
  15. package/lib/commonjs/catalog/normalizeParams.js +333 -0
  16. package/lib/commonjs/catalog/normalizeParams.js.map +1 -0
  17. package/lib/commonjs/catalog/signature.js +68 -0
  18. package/lib/commonjs/catalog/signature.js.map +1 -0
  19. package/lib/commonjs/catalog/snapshotReads.js +13 -6
  20. package/lib/commonjs/catalog/snapshotReads.js.map +1 -1
  21. package/lib/commonjs/catalog/toProviderTools.js +41 -5
  22. package/lib/commonjs/catalog/toProviderTools.js.map +1 -1
  23. package/lib/commonjs/context/buildContextPack.js +367 -19
  24. package/lib/commonjs/context/buildContextPack.js.map +1 -1
  25. package/lib/commonjs/effects/digest.js +34 -0
  26. package/lib/commonjs/effects/digest.js.map +1 -0
  27. package/lib/commonjs/effects/ledger.js +85 -1
  28. package/lib/commonjs/effects/ledger.js.map +1 -1
  29. package/lib/commonjs/engine/askGate.js +287 -0
  30. package/lib/commonjs/engine/askGate.js.map +1 -0
  31. package/lib/commonjs/engine/effectFor.js +82 -1
  32. package/lib/commonjs/engine/effectFor.js.map +1 -1
  33. package/lib/commonjs/engine/historyBudget.js +260 -0
  34. package/lib/commonjs/engine/historyBudget.js.map +1 -0
  35. package/lib/commonjs/engine/runAgentTurn.js +958 -88
  36. package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
  37. package/lib/commonjs/engine/systemPrompt.js +72 -8
  38. package/lib/commonjs/engine/systemPrompt.js.map +1 -1
  39. package/lib/commonjs/engine/textToolCalls.js +276 -0
  40. package/lib/commonjs/engine/textToolCalls.js.map +1 -0
  41. package/lib/commonjs/index.js +81 -1
  42. package/lib/commonjs/index.js.map +1 -1
  43. package/lib/commonjs/policy/labels.js +19 -3
  44. package/lib/commonjs/policy/labels.js.map +1 -1
  45. package/lib/commonjs/policy/policy.js +6 -1
  46. package/lib/commonjs/policy/policy.js.map +1 -1
  47. package/lib/commonjs/policy/redact.js +42 -5
  48. package/lib/commonjs/policy/redact.js.map +1 -1
  49. package/lib/commonjs/providers/anthropic.js +340 -174
  50. package/lib/commonjs/providers/anthropic.js.map +1 -1
  51. package/lib/commonjs/providers/openai.js +229 -103
  52. package/lib/commonjs/providers/openai.js.map +1 -1
  53. package/lib/commonjs/providers/sse.js +164 -29
  54. package/lib/commonjs/providers/sse.js.map +1 -1
  55. package/lib/commonjs/providers/streamTimer.js +123 -0
  56. package/lib/commonjs/providers/streamTimer.js.map +1 -0
  57. package/lib/commonjs/providers/transport.js +107 -0
  58. package/lib/commonjs/providers/transport.js.map +1 -0
  59. package/lib/commonjs/providers/xhrStream.js +209 -0
  60. package/lib/commonjs/providers/xhrStream.js.map +1 -0
  61. package/lib/commonjs/session.js +245 -52
  62. package/lib/commonjs/session.js.map +1 -1
  63. package/lib/module/blocks/receipts.js +83 -24
  64. package/lib/module/blocks/receipts.js.map +1 -1
  65. package/lib/module/blocks/runId.js +26 -0
  66. package/lib/module/blocks/runId.js.map +1 -0
  67. package/lib/module/blocks/types.js +23 -2
  68. package/lib/module/blocks/types.js.map +1 -1
  69. package/lib/module/blocks/uiTool.js +424 -12
  70. package/lib/module/blocks/uiTool.js.map +1 -1
  71. package/lib/module/catalog/catalog.g.js +121 -43
  72. package/lib/module/catalog/catalog.g.js.map +1 -1
  73. package/lib/module/catalog/catalog.source.json +121 -45
  74. package/lib/module/catalog/catalog.types.g.js +40 -0
  75. package/lib/module/catalog/catalog.types.g.js.map +1 -0
  76. package/lib/module/catalog/normalizeParams.js +327 -0
  77. package/lib/module/catalog/normalizeParams.js.map +1 -0
  78. package/lib/module/catalog/signature.js +63 -0
  79. package/lib/module/catalog/signature.js.map +1 -0
  80. package/lib/module/catalog/snapshotReads.js +13 -6
  81. package/lib/module/catalog/snapshotReads.js.map +1 -1
  82. package/lib/module/catalog/toProviderTools.js +41 -5
  83. package/lib/module/catalog/toProviderTools.js.map +1 -1
  84. package/lib/module/context/buildContextPack.js +366 -19
  85. package/lib/module/context/buildContextPack.js.map +1 -1
  86. package/lib/module/effects/digest.js +29 -0
  87. package/lib/module/effects/digest.js.map +1 -0
  88. package/lib/module/effects/ledger.js +85 -1
  89. package/lib/module/effects/ledger.js.map +1 -1
  90. package/lib/module/engine/askGate.js +280 -0
  91. package/lib/module/engine/askGate.js.map +1 -0
  92. package/lib/module/engine/effectFor.js +83 -1
  93. package/lib/module/engine/effectFor.js.map +1 -1
  94. package/lib/module/engine/historyBudget.js +251 -0
  95. package/lib/module/engine/historyBudget.js.map +1 -0
  96. package/lib/module/engine/runAgentTurn.js +954 -88
  97. package/lib/module/engine/runAgentTurn.js.map +1 -1
  98. package/lib/module/engine/systemPrompt.js +71 -8
  99. package/lib/module/engine/systemPrompt.js.map +1 -1
  100. package/lib/module/engine/textToolCalls.js +270 -0
  101. package/lib/module/engine/textToolCalls.js.map +1 -0
  102. package/lib/module/index.js +7 -4
  103. package/lib/module/index.js.map +1 -1
  104. package/lib/module/policy/labels.js +19 -3
  105. package/lib/module/policy/labels.js.map +1 -1
  106. package/lib/module/policy/policy.js +6 -1
  107. package/lib/module/policy/policy.js.map +1 -1
  108. package/lib/module/policy/redact.js +42 -5
  109. package/lib/module/policy/redact.js.map +1 -1
  110. package/lib/module/providers/anthropic.js +341 -175
  111. package/lib/module/providers/anthropic.js.map +1 -1
  112. package/lib/module/providers/openai.js +230 -104
  113. package/lib/module/providers/openai.js.map +1 -1
  114. package/lib/module/providers/sse.js +160 -29
  115. package/lib/module/providers/sse.js.map +1 -1
  116. package/lib/module/providers/streamTimer.js +118 -0
  117. package/lib/module/providers/streamTimer.js.map +1 -0
  118. package/lib/module/providers/transport.js +103 -0
  119. package/lib/module/providers/transport.js.map +1 -0
  120. package/lib/module/providers/xhrStream.js +204 -0
  121. package/lib/module/providers/xhrStream.js.map +1 -0
  122. package/lib/module/session.js +228 -54
  123. package/lib/module/session.js.map +1 -1
  124. package/lib/typescript/blocks/receipts.d.ts +5 -10
  125. package/lib/typescript/blocks/receipts.d.ts.map +1 -1
  126. package/lib/typescript/blocks/runId.d.ts +20 -0
  127. package/lib/typescript/blocks/runId.d.ts.map +1 -0
  128. package/lib/typescript/blocks/types.d.ts +23 -2
  129. package/lib/typescript/blocks/types.d.ts.map +1 -1
  130. package/lib/typescript/blocks/uiTool.d.ts +11 -2
  131. package/lib/typescript/blocks/uiTool.d.ts.map +1 -1
  132. package/lib/typescript/catalog/catalog.g.d.ts.map +1 -1
  133. package/lib/typescript/catalog/catalog.types.g.d.ts +40 -0
  134. package/lib/typescript/catalog/catalog.types.g.d.ts.map +1 -0
  135. package/lib/typescript/catalog/normalizeParams.d.ts +43 -0
  136. package/lib/typescript/catalog/normalizeParams.d.ts.map +1 -0
  137. package/lib/typescript/catalog/signature.d.ts +29 -0
  138. package/lib/typescript/catalog/signature.d.ts.map +1 -0
  139. package/lib/typescript/catalog/snapshotReads.d.ts.map +1 -1
  140. package/lib/typescript/catalog/toProviderTools.d.ts +28 -15
  141. package/lib/typescript/catalog/toProviderTools.d.ts.map +1 -1
  142. package/lib/typescript/context/buildContextPack.d.ts +24 -2
  143. package/lib/typescript/context/buildContextPack.d.ts.map +1 -1
  144. package/lib/typescript/effects/digest.d.ts +10 -0
  145. package/lib/typescript/effects/digest.d.ts.map +1 -0
  146. package/lib/typescript/effects/ledger.d.ts +55 -0
  147. package/lib/typescript/effects/ledger.d.ts.map +1 -1
  148. package/lib/typescript/engine/askGate.d.ts +29 -0
  149. package/lib/typescript/engine/askGate.d.ts.map +1 -0
  150. package/lib/typescript/engine/effectFor.d.ts +6 -1
  151. package/lib/typescript/engine/effectFor.d.ts.map +1 -1
  152. package/lib/typescript/engine/historyBudget.d.ts +92 -0
  153. package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
  154. package/lib/typescript/engine/runAgentTurn.d.ts +115 -1
  155. package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
  156. package/lib/typescript/engine/systemPrompt.d.ts +41 -0
  157. package/lib/typescript/engine/systemPrompt.d.ts.map +1 -1
  158. package/lib/typescript/engine/textToolCalls.d.ts +58 -0
  159. package/lib/typescript/engine/textToolCalls.d.ts.map +1 -0
  160. package/lib/typescript/index.d.ts +8 -5
  161. package/lib/typescript/index.d.ts.map +1 -1
  162. package/lib/typescript/policy/labels.d.ts.map +1 -1
  163. package/lib/typescript/policy/policy.d.ts.map +1 -1
  164. package/lib/typescript/policy/redact.d.ts.map +1 -1
  165. package/lib/typescript/providers/anthropic.d.ts +5 -0
  166. package/lib/typescript/providers/anthropic.d.ts.map +1 -1
  167. package/lib/typescript/providers/openai.d.ts +0 -16
  168. package/lib/typescript/providers/openai.d.ts.map +1 -1
  169. package/lib/typescript/providers/sse.d.ts +82 -1
  170. package/lib/typescript/providers/sse.d.ts.map +1 -1
  171. package/lib/typescript/providers/streamTimer.d.ts +59 -0
  172. package/lib/typescript/providers/streamTimer.d.ts.map +1 -0
  173. package/lib/typescript/providers/transport.d.ts +40 -0
  174. package/lib/typescript/providers/transport.d.ts.map +1 -0
  175. package/lib/typescript/providers/types.d.ts +116 -3
  176. package/lib/typescript/providers/types.d.ts.map +1 -1
  177. package/lib/typescript/providers/xhrStream.d.ts +43 -0
  178. package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
  179. package/lib/typescript/session.d.ts +63 -2
  180. package/lib/typescript/session.d.ts.map +1 -1
  181. package/package.json +2 -2
@@ -3,12 +3,32 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "compressConsumed", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _historyBudget.compressConsumed;
10
+ }
11
+ });
6
12
  exports.createAskBuoySession = createAskBuoySession;
13
+ exports.resumableHistory = resumableHistory;
14
+ Object.defineProperty(exports, "trimHistory", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _historyBudget.trimHistory;
18
+ }
19
+ });
20
+ Object.defineProperty(exports, "trimHistoryReport", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _historyBudget.trimHistoryReport;
24
+ }
25
+ });
7
26
  var _catalog = require("./catalog/catalog.g");
8
27
  var _buildContextPack = require("./context/buildContextPack");
9
28
  var _runAgentTurn = require("./engine/runAgentTurn");
10
29
  var _systemPrompt = require("./engine/systemPrompt");
11
30
  var _ledger = require("./effects/ledger");
31
+ var _historyBudget = require("./engine/historyBudget");
12
32
  var _anthropic = require("./providers/anthropic");
13
33
  var _openai = require("./providers/openai");
14
34
  var _policy = require("./policy/policy");
@@ -19,49 +39,91 @@ var _redact = require("./policy/redact");
19
39
  * This is the one-call surface the UI packages use. It owns the pieces that
20
40
  * have to agree with each other across a whole session — the provider, the
21
41
  * catalog filtered to what this device can actually do, the system prompt
22
- * (built once, after grounding), the effect ledger, and the message history —
42
+ * (the stable part built once after grounding, the RIGHT NOW part re-read every
43
+ * turn), the effect ledger, and the message history —
23
44
  * so a chat UI is a message list plus a text box rather than an orchestrator.
24
45
  */
25
46
 
26
47
  /**
27
- * A long QA session must not die on the provider's context limit with an
28
- * opaque error — the transcript grows without bound (tool results are the
29
- * heavy part), so the OLDEST rounds are dropped once the history passes a
30
- * budget. Rounds are dropped whole — a round starts at a user message — so
31
- * the assistant/tool-result pairing every provider requires stays intact and
32
- * the history still begins with a user message.
48
+ * A stored history, made safe to send as the start of a new request.
49
+ *
50
+ * Two things make a saved conversation unusable as-is.
51
+ *
52
+ * A history captured mid-turn ends with an assistant message whose `tool_use`
53
+ * blocks were never answered, or with the `tool_result`s and no reply after
54
+ * them. Every provider rejects both: the blocks must pair up. So this rewinds
55
+ * to the last COMPLETE round — an assistant message that made no tool calls,
56
+ * which is where a conversation is always safe to resume from.
57
+ *
58
+ * And thinking blocks are dropped. Anthropic needs them replayed only when the
59
+ * very next thing sent is that turn's `tool_result`s; a restored conversation
60
+ * always resumes with a fresh user message instead, so their signatures are
61
+ * dead weight at best and a stale-signature 400 at worst.
33
62
  */
34
- const MAX_HISTORY_CHARS = 150_000;
35
- const MIN_KEEP_MESSAGES = 4;
36
- function messageSize(m) {
37
- try {
38
- return JSON.stringify(m).length;
39
- } catch {
40
- return 0;
41
- }
42
- }
43
- function trimHistory(messages) {
44
- let total = 0;
45
- for (const m of messages) total += messageSize(m);
46
- if (total <= MAX_HISTORY_CHARS) return messages;
47
- const out = [...messages];
48
- while (out.length > MIN_KEEP_MESSAGES && total > MAX_HISTORY_CHARS) {
49
- total -= messageSize(out[0]);
50
- out.shift();
51
- while (out.length > MIN_KEEP_MESSAGES && out[0].role !== "user") {
52
- total -= messageSize(out[0]);
53
- out.shift();
54
- }
63
+ // Re-exported: these were defined here before the engine needed them too, and
64
+ // the tests and the package surface still reach them through this module.
65
+
66
+ function resumableHistory(history) {
67
+ let end = history.length;
68
+ while (end > 0) {
69
+ const m = history[end - 1];
70
+ if (m.role === "assistant" && !m.toolCalls?.length) break;
71
+ end -= 1;
55
72
  }
56
- return out;
73
+ return history.slice(0, end).map(m => m.role === "assistant" && m.thinking ? {
74
+ ...m,
75
+ thinking: undefined
76
+ } : m);
57
77
  }
58
78
  function createAskBuoySession(config) {
59
79
  const catalog = config.catalog ?? _catalog.CATALOG;
60
80
  const ledger = new _ledger.EffectLedger();
61
81
  const policy = config.policy ?? {};
62
82
  let messages = [];
83
+ /**
84
+ * Image-URL provenance for the whole conversation, not one turn of it.
85
+ *
86
+ * "Show me the shop as pictures" and "no, actually render them" are two
87
+ * turns; the second has no tool calls of its own, so a per-turn set held
88
+ * nothing and every image was stripped out from under the model. It kept
89
+ * describing artwork that was not on screen. The rule is unchanged — a URL
90
+ * still has to have been READ — the window is just the conversation. Reset
91
+ * with the conversation.
92
+ */
93
+ const seenUrls = new Set();
63
94
  let system;
64
95
  let primed = false;
96
+ /** See `setApprovalBypass`. Consulted per turn, never captured. */
97
+ let bypassApproval = false;
98
+ /** See `setReadOnly`. */
99
+ let deviceReadOnly = false;
100
+ /**
101
+ * Rounds dropped by `restore` — reported on the first send, because there is
102
+ * no open turn to carry the event when the restore happens.
103
+ */
104
+ let trimmedOnRestore = 0;
105
+ /**
106
+ * Which conversation is live. Bumped by `reset`.
107
+ *
108
+ * A turn's history is committed when its generator drains, and a turn does
109
+ * not stop the moment Stop is pressed — an in-flight dispatch has to settle
110
+ * first, and nothing can pull a store write back out of an adapter. So the
111
+ * sequence Stop -> "New conversation" -> the write finishes used to end with
112
+ * the OLD turn assigning its whole history over the empty one: a chat the
113
+ * user had just cleared came back, carrying a change they never saw made.
114
+ * The turn still finishes and its effect still lands in the app; it simply
115
+ * no longer owns a conversation that has moved on.
116
+ */
117
+ let generation = 0;
118
+ /**
119
+ * The grounding probe's result, held past `prime`.
120
+ *
121
+ * The system prompt is a pure function of this plus the policy, and the
122
+ * approval paragraph changes when the device toggle does — holding the
123
+ * digest lets the prompt be rebuilt without re-probing the app for state it
124
+ * already read.
125
+ */
126
+ let digest = {};
65
127
  /**
66
128
  * `storage key -> the live store that owns it`, derived from the grounding.
67
129
  *
@@ -75,16 +137,62 @@ function createAskBuoySession(config) {
75
137
  // So the agent's own requests to the model endpoint never come back to it
76
138
  // out of the network tool — that would feed it its own auth headers.
77
139
  (0, _redact.registerSelfEndpoint)(config.endpoint);
78
- const provider = config.protocol === "openai" ? (0, _openai.createOpenAIProvider)(config) : (0, _anthropic.createAnthropicProvider)(config);
140
+ const provider = config.provider ?? (config.protocol === "openai" ? (0, _openai.createOpenAIProvider)(config) : (0, _anthropic.createAnthropicProvider)(config));
79
141
 
80
142
  // Mutable: the device's tool list fills in over the first frames and can
81
143
  // change while the sheet is open. See setAvailableActions.
82
144
  let availableActions = config.availableActions;
83
145
  let availableToolIds = Object.keys(availableActions);
146
+
147
+ /**
148
+ * THE policy object the engine reads, mutated in place.
149
+ *
150
+ * One object for the life of the session, not a fresh one per turn: the
151
+ * engine reads `policy.readOnly` and the approval lists at each call, so a
152
+ * toggle flipped mid-turn lands on the very next call of that turn. A new
153
+ * object per turn would leave a running turn on the old rules until it
154
+ * finished — "Read only" switched on while the agent was writing would let
155
+ * the rest of the batch through.
156
+ */
157
+ const live = {
158
+ ...policy
159
+ };
160
+ function refreshLive() {
161
+ for (const k of Object.keys(live)) delete live[k];
162
+ Object.assign(live, policy);
163
+ if (bypassApproval) {
164
+ live.requireApproval = [];
165
+ live.requireApprovalFor = [];
166
+ }
167
+ // OR, never override: the device can narrow, the app's own read-only stands.
168
+ if (deviceReadOnly) live.readOnly = true;
169
+ }
170
+ function activePolicy() {
171
+ return live;
172
+ }
173
+ function composeSystem() {
174
+ system = (0, _systemPrompt.buildSystemPrompt)({
175
+ catalog,
176
+ context: {
177
+ ...config.context,
178
+ digest: {
179
+ ...digest,
180
+ ...config.context?.digest
181
+ }
182
+ },
183
+ isRelease: config.isRelease,
184
+ readOnly: live.readOnly ?? false,
185
+ readOnlySource: policy.readOnly ? "app" : deviceReadOnly ? "device" : undefined,
186
+ requireApproval: (0, _policy.resolveRequireApproval)(live),
187
+ approvalsBypassed: bypassApproval,
188
+ appName: config.appName,
189
+ platform: config.platform
190
+ });
191
+ }
84
192
  async function prime() {
85
193
  if (primed) return;
86
194
  primed = true;
87
- let digest = {};
195
+ digest = {};
88
196
  try {
89
197
  digest = await (0, _buildContextPack.buildContextDigest)({
90
198
  dispatch: config.dispatch,
@@ -101,21 +209,7 @@ function createAskBuoySession(config) {
101
209
  const store = raw;
102
210
  if (store?.persistsTo && store.name) storeKeyOwners[store.persistsTo] = store.name;
103
211
  }
104
- system = (0, _systemPrompt.buildSystemPrompt)({
105
- catalog,
106
- context: {
107
- ...config.context,
108
- digest: {
109
- ...digest,
110
- ...config.context?.digest
111
- }
112
- },
113
- isRelease: config.isRelease,
114
- readOnly: policy.readOnly ?? false,
115
- requireApproval: (0, _policy.resolveRequireApproval)(policy),
116
- appName: config.appName,
117
- platform: config.platform
118
- });
212
+ composeSystem();
119
213
  }
120
214
  return {
121
215
  ledger,
@@ -127,29 +221,122 @@ function createAskBuoySession(config) {
127
221
  availableActions = actions;
128
222
  availableToolIds = Object.keys(actions);
129
223
  },
224
+ setApprovalBypass(enabled) {
225
+ if (bypassApproval === enabled) return;
226
+ bypassApproval = enabled;
227
+ refreshLive();
228
+ // The prompt tells the model whether a card will appear before its
229
+ // change lands; leaving that paragraph stale would have it announce an
230
+ // approval step that no longer exists. Rebuilt from the held digest, so
231
+ // toggling mid-conversation costs nothing and re-reads nothing.
232
+ if (system) composeSystem();
233
+ },
234
+ setReadOnly(enabled) {
235
+ if (deviceReadOnly === enabled) return;
236
+ deviceReadOnly = enabled;
237
+ refreshLive();
238
+ if (system) composeSystem();
239
+ },
240
+ restore(history) {
241
+ // Only into a session that has not been talked to. Restoring over a live
242
+ // conversation would drop whatever was said since the app started.
243
+ if (messages.length > 0) return;
244
+ const report = (0, _historyBudget.trimHistoryReport)(resumableHistory(history));
245
+ messages = report.messages;
246
+ trimmedOnRestore = report.droppedRounds;
247
+ },
130
248
  async *send(text, signal) {
249
+ /**
250
+ * Captured FIRST, before any await.
251
+ *
252
+ * Priming and the live-context probes are awaits like any other, and a
253
+ * reset can land inside them. Reading the generation after them would
254
+ * pick up the NEW conversation's value and let this turn commit into it —
255
+ * the precise bug this guards against, reintroduced one line lower.
256
+ */
257
+ const myGeneration = generation;
131
258
  await prime();
132
- messages.push({
259
+ // The RIGHT NOW block: re-read on EVERY turn, not once at open. The
260
+ // stable digest above was once the whole picture, and it was built
261
+ // before the user had navigated anywhere — so the query that owned the
262
+ // screen they were looking at was simply not in the prompt. This is the
263
+ // uncached tail of the system prompt (see ProviderRequest.systemVolatile).
264
+ let live;
265
+ try {
266
+ live = await (0, _buildContextPack.buildLiveContext)({
267
+ dispatch: config.dispatch,
268
+ readSnapshot: config.readSnapshot,
269
+ availableToolIds,
270
+ availableActions
271
+ });
272
+ } catch {
273
+ live = undefined;
274
+ }
275
+ /**
276
+ * The conversation was cleared while this turn was still getting ready.
277
+ *
278
+ * Priming and the live probes take real time, so "New conversation"
279
+ * lands here often enough to matter. Abandoning now costs nothing: the
280
+ * model has not been asked anything yet.
281
+ */
282
+ if (myGeneration !== generation) {
283
+ yield {
284
+ type: "done"
285
+ };
286
+ return;
287
+ }
288
+
289
+ /**
290
+ * The turn works on its OWN array, and `messages` is assigned in exactly
291
+ * one place — the commit at the bottom.
292
+ *
293
+ * `runAgentTurn` pushes each round into the array it is handed. Handing
294
+ * it the session's own array made every push a live edit of session
295
+ * state, so a turn racing a reset wrote its whole history into the new
296
+ * conversation one push at a time and the commit guard had nothing left
297
+ * to protect. Copying makes ownership checkable in one place instead of
298
+ * spread across the loop.
299
+ */
300
+ const trimmed = (0, _historyBudget.trimHistoryReport)([...messages, {
133
301
  role: "user",
134
302
  text
135
- });
136
- messages = trimHistory(messages);
303
+ }]);
304
+ const working = trimmed.messages;
305
+ // Said once, before the answer it affects. The screen still shows the
306
+ // rounds the model just lost; this is the only thing that tells the two
307
+ // apart. See the `history-trimmed` event.
308
+ const droppedRounds = trimmed.droppedRounds + trimmedOnRestore;
309
+ trimmedOnRestore = 0;
310
+ if (droppedRounds > 0) yield {
311
+ type: "history-trimmed",
312
+ droppedRounds
313
+ };
137
314
  const gen = (0, _runAgentTurn.runAgentTurn)({
138
315
  provider,
139
316
  catalog,
140
- messages,
317
+ messages: working,
141
318
  system: system,
319
+ systemVolatile: (0, _systemPrompt.buildLiveBlock)(live,
320
+ // What this conversation has already done to the app. See
321
+ // buildLiveBlock — without it the model answers "what have you
322
+ // changed?" from memory of its own sentences, and reports a value it
323
+ // overwrote itself as the app's own.
324
+ ledger.list().map(e => ({
325
+ label: `${e.toolId}.${e.action}${e.effect.label ? ` — ${e.effect.label}` : ""}`,
326
+ undone: e.undoneAt !== undefined
327
+ }))),
142
328
  model: config.model,
143
329
  maxTokens: config.maxTokens ?? 4096,
144
330
  dispatch: config.dispatch,
145
331
  readSnapshot: config.readSnapshot,
146
332
  storeKeyOwners,
147
333
  ledger,
148
- policy,
334
+ policy: activePolicy(),
149
335
  isRelease: config.isRelease,
150
336
  availableToolIds,
151
337
  availableActions,
152
338
  requestApproval: config.requestApproval,
339
+ seenUrls,
153
340
  signal
154
341
  });
155
342
  let next = await gen.next();
@@ -158,11 +345,17 @@ function createAskBuoySession(config) {
158
345
  next = await gen.next();
159
346
  }
160
347
  // The generator's return value is the full history including tool turns.
161
- messages = next.value;
348
+ // Committed only if this turn still owns the conversation — see
349
+ // `generation`.
350
+ if (myGeneration === generation) messages = next.value;
162
351
  },
163
352
  reset() {
353
+ // Before anything else: a turn still draining must not commit over this.
354
+ generation += 1;
164
355
  messages = [];
356
+ trimmedOnRestore = 0;
165
357
  ledger.clear();
358
+ seenUrls.clear();
166
359
  // The grounding digest is a snapshot of the app AT OPEN — stores and
167
360
  // routes registered since are invisible to it. A new conversation is
168
361
  // the natural moment to re-read the world.
@@ -1 +1 @@
1
- {"version":3,"names":["_catalog","require","_buildContextPack","_runAgentTurn","_systemPrompt","_ledger","_anthropic","_openai","_policy","_redact","MAX_HISTORY_CHARS","MIN_KEEP_MESSAGES","messageSize","m","JSON","stringify","length","trimHistory","messages","total","out","shift","role","createAskBuoySession","config","catalog","CATALOG","ledger","EffectLedger","policy","system","primed","storeKeyOwners","registerSelfEndpoint","endpoint","provider","protocol","createOpenAIProvider","createAnthropicProvider","availableActions","availableToolIds","Object","keys","prime","digest","buildContextDigest","dispatch","readSnapshot","raw","zustandStores","store","persistsTo","name","buildSystemPrompt","context","isRelease","readOnly","requireApproval","resolveRequireApproval","appName","platform","setAvailableActions","actions","send","text","signal","push","gen","runAgentTurn","model","maxTokens","requestApproval","next","done","value","reset","clear"],"sourceRoot":"../../src","sources":["session.ts"],"mappings":";;;;;;AASA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAEA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAlBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMS,iBAAiB,GAAG,OAAO;AACjC,MAAMC,iBAAiB,GAAG,CAAC;AAE3B,SAASC,WAAWA,CAACC,CAAe,EAAU;EAC5C,IAAI;IACF,OAAOC,IAAI,CAACC,SAAS,CAACF,CAAC,CAAC,CAACG,MAAM;EACjC,CAAC,CAAC,MAAM;IACN,OAAO,CAAC;EACV;AACF;AAEA,SAASC,WAAWA,CAACC,QAAwB,EAAkB;EAC7D,IAAIC,KAAK,GAAG,CAAC;EACb,KAAK,MAAMN,CAAC,IAAIK,QAAQ,EAAEC,KAAK,IAAIP,WAAW,CAACC,CAAC,CAAC;EACjD,IAAIM,KAAK,IAAIT,iBAAiB,EAAE,OAAOQ,QAAQ;EAE/C,MAAME,GAAG,GAAG,CAAC,GAAGF,QAAQ,CAAC;EACzB,OAAOE,GAAG,CAACJ,MAAM,GAAGL,iBAAiB,IAAIQ,KAAK,GAAGT,iBAAiB,EAAE;IAClES,KAAK,IAAIP,WAAW,CAACQ,GAAG,CAAC,CAAC,CAAE,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EAAE,MAAM;QAAE0C;MAAK,CAAC,CAAC;MACrC9C,QAAQ,GAAGD,WAAW,CAACC,QAAQ,CAAC;MAEhC,MAAMiD,GAAG,GAAG,IAAAC,0BAAY,EAAC;QACvBjC,QAAQ;QACRV,OAAO;QACPP,QAAQ;QACRY,MAAM,EAAEA,MAAO;QACfuC,KAAK,EAAE7C,MAAM,CAAC6C,KAAK;QACnBC,SAAS,EAAE9C,MAAM,CAAC8C,SAAS,IAAI,IAAI;QACnCxB,QAAQ,EAAEtB,MAAM,CAACsB,QAAQ;QACzBC,YAAY,EAAEvB,MAAM,CAACuB,YAAY;QACjCf,cAAc;QACdL,MAAM;QACNE,MAAM;QACN0B,SAAS,EAAE/B,MAAM,CAAC+B,SAAS;QAC3Bf,gBAAgB;QAChBD,gBAAgB;QAChBgC,eAAe,EAAE/C,MAAM,CAAC+C,eAAe;QACvCN;MACF,CAAC,CAAC;MAEF,IAAIO,IAAI,GAAG,MAAML,GAAG,CAACK,IAAI,CAAC,CAAC;MAC3B,OAAO,CAACA,IAAI,CAACC,IAAI,EAAE;QACjB,MAAMD,IAAI,CAACE,KAAK;QAChBF,IAAI,GAAG,MAAML,GAAG,CAACK,IAAI,CAAC,CAAC;MACzB;MACA;MACAtD,QAAQ,GAAGsD,IAAI,CAACE,KAAK;IACvB,CAAC;IAEDC,KAAKA,CAAA,EAAG;MACNzD,QAAQ,GAAG,EAAE;MACbS,MAAM,CAACiD,KAAK,CAAC,CAAC;MACd;MACA;MACA;MACA7C,MAAM,GAAG,KAAK;IAChB;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["_catalog","require","_buildContextPack","_runAgentTurn","_systemPrompt","_ledger","_historyBudget","_anthropic","_openai","_policy","_redact","resumableHistory","history","end","length","m","role","toolCalls","slice","map","thinking","undefined","createAskBuoySession","config","catalog","CATALOG","ledger","EffectLedger","policy","messages","seenUrls","Set","system","primed","bypassApproval","deviceReadOnly","trimmedOnRestore","generation","digest","storeKeyOwners","registerSelfEndpoint","endpoint","provider","protocol","createOpenAIProvider","createAnthropicProvider","availableActions","availableToolIds","Object","keys","live","refreshLive","k","assign","requireApproval","requireApprovalFor","readOnly","activePolicy","composeSystem","buildSystemPrompt","context","isRelease","readOnlySource","resolveRequireApproval","approvalsBypassed","appName","platform","prime","buildContextDigest","dispatch","readSnapshot","raw","zustandStores","store","persistsTo","name","setAvailableActions","actions","setApprovalBypass","enabled","setReadOnly","restore","report","trimHistoryReport","droppedRounds","send","text","signal","myGeneration","buildLiveContext","type","trimmed","working","gen","runAgentTurn","systemVolatile","buildLiveBlock","list","e","label","toolId","action","effect","undone","undoneAt","model","maxTokens","requestApproval","next","done","value","reset","clear"],"sourceRoot":"../../src","sources":["session.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAOA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAEA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AA1BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGO,SAASU,gBAAgBA,CAACC,OAAuB,EAAkB;EACxE,IAAIC,GAAG,GAAGD,OAAO,CAACE,MAAM;EACxB,OAAOD,GAAG,GAAG,CAAC,EAAE;IACd,MAAME,CAAC,GAAGH,OAAO,CAACC,GAAG,GAAG,CAAC,CAAE;IAC3B,IAAIE,CAAC,CAACC,IAAI,KAAK,WAAW,IAAI,CAACD,CAAC,CAACE,SAAS,EAAEH,MAAM,EAAE;IAC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