@qmediat.io/gemini-code-context-mcp 1.23.1 → 1.25.0

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 (147) hide show
  1. package/CHANGELOG.md +161 -1
  2. package/README.md +1 -1
  3. package/dist/cache/ttl-watcher.d.ts +29 -0
  4. package/dist/cache/ttl-watcher.d.ts.map +1 -1
  5. package/dist/cache/ttl-watcher.js +104 -43
  6. package/dist/cache/ttl-watcher.js.map +1 -1
  7. package/dist/gemini/client.d.ts +7 -0
  8. package/dist/gemini/client.d.ts.map +1 -1
  9. package/dist/gemini/client.js +8 -1
  10. package/dist/gemini/client.js.map +1 -1
  11. package/dist/gemini/long-decode.d.ts +153 -0
  12. package/dist/gemini/long-decode.d.ts.map +1 -0
  13. package/dist/gemini/long-decode.js +178 -0
  14. package/dist/gemini/long-decode.js.map +1 -0
  15. package/dist/gemini/model-registry.d.ts +2 -0
  16. package/dist/gemini/model-registry.d.ts.map +1 -1
  17. package/dist/gemini/model-registry.js +5 -2
  18. package/dist/gemini/model-registry.js.map +1 -1
  19. package/dist/gemini/models.d.ts.map +1 -1
  20. package/dist/gemini/models.js +1 -0
  21. package/dist/gemini/models.js.map +1 -1
  22. package/dist/gemini/retry.d.ts +8 -0
  23. package/dist/gemini/retry.d.ts.map +1 -1
  24. package/dist/gemini/retry.js +33 -1
  25. package/dist/gemini/retry.js.map +1 -1
  26. package/dist/tools/agentic/dispatch.d.ts +68 -0
  27. package/dist/tools/agentic/dispatch.d.ts.map +1 -0
  28. package/dist/tools/agentic/dispatch.js +167 -0
  29. package/dist/tools/agentic/dispatch.js.map +1 -0
  30. package/dist/tools/agentic/input.d.ts +28 -0
  31. package/dist/tools/agentic/input.d.ts.map +1 -0
  32. package/dist/tools/agentic/input.js +66 -0
  33. package/dist/tools/agentic/input.js.map +1 -0
  34. package/dist/tools/agentic/instructions.d.ts +46 -0
  35. package/dist/tools/agentic/instructions.d.ts.map +1 -0
  36. package/dist/tools/agentic/instructions.js +170 -0
  37. package/dist/tools/agentic/instructions.js.map +1 -0
  38. package/dist/tools/agentic/iteration.d.ts +81 -0
  39. package/dist/tools/agentic/iteration.d.ts.map +1 -0
  40. package/dist/tools/agentic/iteration.js +317 -0
  41. package/dist/tools/agentic/iteration.js.map +1 -0
  42. package/dist/tools/agentic/ledger.d.ts +64 -0
  43. package/dist/tools/agentic/ledger.d.ts.map +1 -0
  44. package/dist/tools/agentic/ledger.js +110 -0
  45. package/dist/tools/agentic/ledger.js.map +1 -0
  46. package/dist/tools/agentic/loop.d.ts +10 -0
  47. package/dist/tools/agentic/loop.d.ts.map +1 -0
  48. package/dist/tools/agentic/loop.js +179 -0
  49. package/dist/tools/agentic/loop.js.map +1 -0
  50. package/dist/tools/agentic/no-progress.d.ts +90 -0
  51. package/dist/tools/agentic/no-progress.d.ts.map +1 -0
  52. package/dist/tools/agentic/no-progress.js +107 -0
  53. package/dist/tools/agentic/no-progress.js.map +1 -0
  54. package/dist/tools/agentic/pass-clock.d.ts +85 -0
  55. package/dist/tools/agentic/pass-clock.d.ts.map +1 -0
  56. package/dist/tools/agentic/pass-clock.js +162 -0
  57. package/dist/tools/agentic/pass-clock.js.map +1 -0
  58. package/dist/tools/agentic/phase-defaults.d.ts +29 -0
  59. package/dist/tools/agentic/phase-defaults.d.ts.map +1 -0
  60. package/dist/tools/agentic/phase-defaults.js +23 -0
  61. package/dist/tools/agentic/phase-defaults.js.map +1 -0
  62. package/dist/tools/agentic/rescue.d.ts +69 -0
  63. package/dist/tools/agentic/rescue.d.ts.map +1 -0
  64. package/dist/tools/agentic/rescue.js +203 -0
  65. package/dist/tools/agentic/rescue.js.map +1 -0
  66. package/dist/tools/agentic/response.d.ts +16 -0
  67. package/dist/tools/agentic/response.d.ts.map +1 -0
  68. package/dist/tools/agentic/response.js +25 -0
  69. package/dist/tools/agentic/response.js.map +1 -0
  70. package/dist/tools/agentic/results.d.ts +76 -0
  71. package/dist/tools/agentic/results.d.ts.map +1 -0
  72. package/dist/tools/agentic/results.js +228 -0
  73. package/dist/tools/agentic/results.js.map +1 -0
  74. package/dist/tools/agentic/run.d.ts +130 -0
  75. package/dist/tools/agentic/run.d.ts.map +1 -0
  76. package/dist/tools/agentic/run.js +131 -0
  77. package/dist/tools/agentic/run.js.map +1 -0
  78. package/dist/tools/agentic/sandbox.d.ts +13 -2
  79. package/dist/tools/agentic/sandbox.d.ts.map +1 -1
  80. package/dist/tools/agentic/sandbox.js +127 -111
  81. package/dist/tools/agentic/sandbox.js.map +1 -1
  82. package/dist/tools/agentic/workspace-tools.d.ts +30 -27
  83. package/dist/tools/agentic/workspace-tools.d.ts.map +1 -1
  84. package/dist/tools/agentic/workspace-tools.js +324 -385
  85. package/dist/tools/agentic/workspace-tools.js.map +1 -1
  86. package/dist/tools/ask-agentic-fallback.d.ts +33 -0
  87. package/dist/tools/ask-agentic-fallback.d.ts.map +1 -0
  88. package/dist/tools/ask-agentic-fallback.js +113 -0
  89. package/dist/tools/ask-agentic-fallback.js.map +1 -0
  90. package/dist/tools/ask-agentic.tool.d.ts +11 -44
  91. package/dist/tools/ask-agentic.tool.d.ts.map +1 -1
  92. package/dist/tools/ask-agentic.tool.js +143 -1618
  93. package/dist/tools/ask-agentic.tool.js.map +1 -1
  94. package/dist/tools/ask.tool.d.ts.map +1 -1
  95. package/dist/tools/ask.tool.js +195 -555
  96. package/dist/tools/ask.tool.js.map +1 -1
  97. package/dist/tools/code.tool.d.ts +6 -0
  98. package/dist/tools/code.tool.d.ts.map +1 -1
  99. package/dist/tools/code.tool.js +155 -306
  100. package/dist/tools/code.tool.js.map +1 -1
  101. package/dist/tools/shared/abort-timeout.d.ts +48 -4
  102. package/dist/tools/shared/abort-timeout.d.ts.map +1 -1
  103. package/dist/tools/shared/abort-timeout.js +116 -95
  104. package/dist/tools/shared/abort-timeout.js.map +1 -1
  105. package/dist/tools/shared/call-ledger.d.ts +88 -0
  106. package/dist/tools/shared/call-ledger.d.ts.map +1 -0
  107. package/dist/tools/shared/call-ledger.js +133 -0
  108. package/dist/tools/shared/call-ledger.js.map +1 -0
  109. package/dist/tools/shared/context-decode.d.ts +77 -0
  110. package/dist/tools/shared/context-decode.d.ts.map +1 -0
  111. package/dist/tools/shared/context-decode.js +125 -0
  112. package/dist/tools/shared/context-decode.js.map +1 -0
  113. package/dist/tools/shared/continuation.d.ts +124 -0
  114. package/dist/tools/shared/continuation.d.ts.map +1 -0
  115. package/dist/tools/shared/continuation.js +302 -0
  116. package/dist/tools/shared/continuation.js.map +1 -0
  117. package/dist/tools/shared/dispatch-throttle.d.ts +43 -0
  118. package/dist/tools/shared/dispatch-throttle.d.ts.map +1 -0
  119. package/dist/tools/shared/dispatch-throttle.js +65 -0
  120. package/dist/tools/shared/dispatch-throttle.js.map +1 -0
  121. package/dist/tools/shared/question-fields.d.ts +10 -0
  122. package/dist/tools/shared/question-fields.d.ts.map +1 -0
  123. package/dist/tools/shared/question-fields.js +13 -0
  124. package/dist/tools/shared/question-fields.js.map +1 -0
  125. package/dist/tools/shared/settle-call.d.ts +68 -0
  126. package/dist/tools/shared/settle-call.d.ts.map +1 -0
  127. package/dist/tools/shared/settle-call.js +59 -0
  128. package/dist/tools/shared/settle-call.js.map +1 -0
  129. package/dist/tools/shared/stream-collector.d.ts +7 -0
  130. package/dist/tools/shared/stream-collector.d.ts.map +1 -1
  131. package/dist/tools/shared/stream-collector.js +5 -1
  132. package/dist/tools/shared/stream-collector.js.map +1 -1
  133. package/dist/tools/shared/thinking.d.ts +41 -11
  134. package/dist/tools/shared/thinking.d.ts.map +1 -1
  135. package/dist/tools/shared/thinking.js +62 -9
  136. package/dist/tools/shared/thinking.js.map +1 -1
  137. package/dist/tools/shared/throttle.d.ts +7 -0
  138. package/dist/tools/shared/throttle.d.ts.map +1 -1
  139. package/dist/tools/shared/throttle.js +18 -0
  140. package/dist/tools/shared/throttle.js.map +1 -1
  141. package/dist/types.d.ts +2 -0
  142. package/dist/types.d.ts.map +1 -1
  143. package/dist/utils/cost-estimator.d.ts +17 -0
  144. package/dist/utils/cost-estimator.d.ts.map +1 -1
  145. package/dist/utils/cost-estimator.js +15 -2
  146. package/dist/utils/cost-estimator.js.map +1 -1
  147. package/package.json +4 -3
@@ -0,0 +1,302 @@
1
+ /**
2
+ * One decode over one or more requests (Gemini 4 long decode, `src/gemini/long-decode.ts`).
3
+ *
4
+ * A request that stops with `finishReason: CONTINUATION` and a continuation token is followed by the same request
5
+ * with `continuationToken` set to the latest token — the payload is never changed and the text decoded so far is
6
+ * never appended to it. Every request is sent with `automaticContinuation: false`, so the SDK hands each request's
7
+ * end back here: this loop counts the requests, stops at the cap the budget reservation assumed, and
8
+ * never re-sends a request that already streamed (billed) work.
9
+ *
10
+ * The requests share the caller's abort signal and chunk callback, so `timeoutMs` covers the whole decode and the
11
+ * stall watchdog every gap between two chunks of a request; the caller's `afterRequest` hook pauses the watchdog
12
+ * between requests, as before the first. A request that made no progress (the same token again, nothing decoded)
13
+ * is not continued. The result is ONE response: the text and thought summary of every request in order, the usage
14
+ * summed over the requests (each one bills its own input again), the last request's finish reason.
15
+ */
16
+ import { FinishReason, } from '@google/genai';
17
+ import { abortableSleep, withNetworkRetry } from '../../gemini/retry.js';
18
+ import { logger } from '../../utils/logger.js';
19
+ import { billedInputTokens } from './call-ledger.js';
20
+ import { statusOf } from './service-tier.js';
21
+ import { THOUGHTS_SUMMARY_MAX_CHARS, collectStream, } from './stream-collector.js';
22
+ import { isGemini429, parseRetryDelayMs } from './throttle.js';
23
+ /** The long-decode sentences of the `maxOutputTokens` description of `ask` and `code`. */
24
+ export const LONG_DECODE_CAP_DESCRIPTION = "On a model with long decode (Gemini 4: Argon, Carbon, Hydrogen) a value above its per-request limit is sent up to 1,048,576: a response that reaches the per-request limit continues in further requests until the model stops or the cap is reached, and the result's `continuationHops` counts them. Each continuation request bills the prompt again plus everything decoded before it, so a long decode costs more than one request; the budget reservation counts that input too. Use it when a high thinking level leaves no room for the answer (`errorCode: 'OUTPUT_CAP'`, thinking tokens count against the cap). An answer cut at the cap comes back with `truncated: true` and its `finishReason`.";
25
+ /**
26
+ * Every request of one call that streamed to its end. Each one is billed whatever becomes of the call — an answer,
27
+ * a later request that fails, a stale-cache retry that starts a new decode — so the call settles its ledger from
28
+ * here, never from the answer alone. A request that reported no input is billed at the input it was estimated to
29
+ * send (`billedInputTokens`).
30
+ */
31
+ export class CompletedRequests {
32
+ billed = [];
33
+ total = 0;
34
+ completedInDecode = 0;
35
+ sentInDecode = 0;
36
+ /** A new decode of the call starts: its requests are counted from zero. */
37
+ beginDecode() {
38
+ this.completedInDecode = 0;
39
+ this.sentInDecode = 0;
40
+ }
41
+ /** A request of the latest decode went to the API (its stream opened or the API refused it). */
42
+ sent() {
43
+ this.sentInDecode += 1;
44
+ }
45
+ /** A request streamed to its end with `usage`; `inputEstimate` is the input it was estimated to send. */
46
+ record(usage, inputEstimate) {
47
+ const promptTokenCount = billedInputTokens(usage?.promptTokenCount, inputEstimate);
48
+ this.billed.push({ ...usage, promptTokenCount });
49
+ this.total += 1;
50
+ this.completedInDecode += 1;
51
+ }
52
+ /** The requests of the call that completed, over all its decodes. */
53
+ get count() {
54
+ return this.total;
55
+ }
56
+ /** The requests of the latest decode that completed. */
57
+ get completedInLatestDecode() {
58
+ return this.completedInDecode;
59
+ }
60
+ /**
61
+ * The continuation requests the latest decode sent: every request that went to the API, but the first — whether
62
+ * the decode answered, failed in a request, or stopped before the next request was sent.
63
+ */
64
+ continuationHops() {
65
+ return Math.max(0, this.sentInDecode - 1);
66
+ }
67
+ /** Each counter summed over the completed requests that have it; `undefined` before any request completed. */
68
+ usage() {
69
+ return sumUsage(this.billed);
70
+ }
71
+ }
72
+ /**
73
+ * Run the decode: each request opens through `withNetworkRetry` (only the opening is retried — a mid-stream
74
+ * failure would bill the work again), a continuation request refused at its opening is reopened with the same token
75
+ * (`reopenRefused`), and the requests are collected into one response.
76
+ */
77
+ export function runDecode(call) {
78
+ const open = async (continuationToken) => {
79
+ const budget = new OpeningBudget(call.openAttempts);
80
+ const send = () => sendRequest(call, continuationToken, budget);
81
+ try {
82
+ const stream = continuationToken === undefined ? await send() : await reopenRefused(send, call, budget);
83
+ call.onRequestOpened();
84
+ return stream;
85
+ }
86
+ finally {
87
+ // Counted once per request, however many attempts its opening took; a request never sent is not counted.
88
+ if (budget.spent > 0)
89
+ call.completed.sent();
90
+ }
91
+ };
92
+ call.completed.beginDecode();
93
+ return collectDecode(open, call.limits, call.collector, {
94
+ ...call.hooks,
95
+ completed: call.completed,
96
+ });
97
+ }
98
+ /**
99
+ * The SDK calls one request's opening may still make: the network retries of every attempt and the reopenings after a
100
+ * refusal draw on the same `openAttempts`.
101
+ */
102
+ class OpeningBudget {
103
+ attempts;
104
+ used = 0;
105
+ constructor(attempts) {
106
+ this.attempts = attempts;
107
+ }
108
+ spend() {
109
+ this.used += 1;
110
+ }
111
+ get spent() {
112
+ return this.used;
113
+ }
114
+ get remaining() {
115
+ return Math.max(0, this.attempts - this.used);
116
+ }
117
+ }
118
+ /** Open one request with the calls `budget` has left; each call that goes to the SDK is spent from it. */
119
+ function sendRequest(call, continuationToken, budget) {
120
+ const signal = call.collector.signal;
121
+ return withNetworkRetry(() => {
122
+ budget.spend();
123
+ return call.client.models.generateContentStream({
124
+ model: call.model,
125
+ contents: call.contents,
126
+ config: {
127
+ ...call.config,
128
+ automaticContinuation: false,
129
+ ...(continuationToken !== undefined ? { continuationToken } : {}),
130
+ abortSignal: signal,
131
+ },
132
+ });
133
+ }, {
134
+ attempts: budget.remaining,
135
+ signal,
136
+ onRetry: (attempt, err) => logRetry(call.label, attempt, err),
137
+ });
138
+ }
139
+ function logRetry(label, attempt, err) {
140
+ logger.warn(`${label}: retrying generateContent after transient network failure (attempt ${attempt}): ${err instanceof Error ? err.message : String(err)}`);
141
+ }
142
+ /**
143
+ * The statuses a request is refused with at its opening, before any of it is billed: a quota (429) and an
144
+ * overloaded server (503).
145
+ */
146
+ const REFUSED_AT_OPENING = new Set([429, 503]);
147
+ /** The wait before the first reopening when Google sent no retry hint; each further one waits three times longer. */
148
+ const REOPEN_BASE_WAIT_MS = 2_000;
149
+ /**
150
+ * Open a continuation request; a 429 or 503 at its opening (nothing of it billed yet) waits Google's retry hint, else
151
+ * the base wait, takes its per-minute reservation again (`beforeReopen`) and reopens with the same token — while the
152
+ * request's opening budget lasts (`openAttempts` SDK calls, network retries included), every wait abortable by the
153
+ * call's signal (`timeoutMs`). A refused first request is not reopened: nothing of the call is billed yet, and the
154
+ * caller sees the 429 / 503 as before.
155
+ */
156
+ async function reopenRefused(send, call, budget) {
157
+ for (let attempt = 1;; attempt += 1) {
158
+ try {
159
+ return await send();
160
+ }
161
+ catch (err) {
162
+ const status = statusOf(err);
163
+ if (status === undefined || !REFUSED_AT_OPENING.has(status) || budget.remaining === 0)
164
+ throw err;
165
+ const waitMs = (isGemini429(err) ? parseRetryDelayMs(err.message) : null) ?? reopenWaitMs(attempt);
166
+ logger.warn(`${call.label}: continuation request refused at its opening (HTTP ${status}); reopening with the same token in ${waitMs} ms (attempt ${attempt})`);
167
+ await abortableSleep(waitMs, call.collector.signal);
168
+ await call.beforeReopen?.();
169
+ }
170
+ }
171
+ }
172
+ function reopenWaitMs(attempt) {
173
+ return REOPEN_BASE_WAIT_MS * 3 ** (attempt - 1);
174
+ }
175
+ /** The usage counters a request reports for itself and the decode sums. */
176
+ const USAGE_COUNTERS = [
177
+ 'promptTokenCount',
178
+ 'cachedContentTokenCount',
179
+ 'candidatesTokenCount',
180
+ 'thoughtsTokenCount',
181
+ 'toolUsePromptTokenCount',
182
+ 'totalTokenCount',
183
+ ];
184
+ /**
185
+ * Collect the decode: one request, plus a continuation request after each one that stopped with CONTINUATION.
186
+ * Each request that streamed to its end goes into `completed` at once: a later request's failure leaves it there.
187
+ */
188
+ export async function collectDecode(open, limits, opts, hooks = {}) {
189
+ const requests = [];
190
+ const firstInput = hooks.firstRequestInput ?? 0;
191
+ let input = firstInput;
192
+ let token;
193
+ for (;;) {
194
+ const collected = await collectStream(await open(token), opts);
195
+ hooks.completed?.record(collected.usageMetadata, input);
196
+ hooks.afterRequest?.(collected.usageMetadata);
197
+ requests.push(collected);
198
+ const next = nextContinuationToken(requests, token, limits);
199
+ if (next === undefined)
200
+ return mergeRequests(requests);
201
+ input = continuationInput(requests, firstInput);
202
+ await hooks.beforeContinuation?.(input);
203
+ token = next;
204
+ }
205
+ }
206
+ /**
207
+ * The token to continue with, or `undefined` when the decode is over, has reached its limits, or made no progress
208
+ * in its last request.
209
+ */
210
+ function nextContinuationToken(requests, openedWith, limits) {
211
+ const last = requests[requests.length - 1];
212
+ if (last === undefined || last.continuationToken === null)
213
+ return undefined;
214
+ if (last.candidates?.[0]?.finishReason !== FinishReason.CONTINUATION)
215
+ return undefined;
216
+ if (requests.length >= limits.maxRequests)
217
+ return undefined;
218
+ if (decodedTokens(requests) >= limits.cap)
219
+ return undefined;
220
+ if (!madeProgress(last, openedWith))
221
+ return undefined;
222
+ return last.continuationToken;
223
+ }
224
+ /**
225
+ * A request that stopped with CONTINUATION moved the decode on: it returned a token other than the one it was opened
226
+ * with and decoded at least one token. Replaying the same token, or a request that decoded nothing, would only bill
227
+ * the whole input again for the same stop.
228
+ */
229
+ function madeProgress(request, openedWith) {
230
+ const decoded = decodedTokens([request]);
231
+ if (request.continuationToken !== openedWith && decoded > 0)
232
+ return true;
233
+ logger.warn(`long decode: a request stopped with CONTINUATION ${decoded > 0 ? 'and returned the token it was opened with' : 'having decoded no token'}; the decode stops there`);
234
+ return false;
235
+ }
236
+ /**
237
+ * The input a continuation request sends: the first request's prompt (its estimate when it reported none) plus every
238
+ * token decoded so far.
239
+ */
240
+ function continuationInput(requests, firstInput) {
241
+ const prompt = billedInputTokens(requests[0]?.usageMetadata?.promptTokenCount, firstInput);
242
+ return prompt + decodedTokens(requests);
243
+ }
244
+ /** The tokens the requests decoded so far: thinking and answer. */
245
+ function decodedTokens(requests) {
246
+ let total = 0;
247
+ for (const r of requests) {
248
+ total +=
249
+ (r.usageMetadata?.thoughtsTokenCount ?? 0) + (r.usageMetadata?.candidatesTokenCount ?? 0);
250
+ }
251
+ return total;
252
+ }
253
+ function mergeRequests(requests) {
254
+ const first = requests[0];
255
+ const last = requests[requests.length - 1];
256
+ if (first === undefined || last === undefined)
257
+ throw new Error('collectDecode: no request was collected');
258
+ if (requests.length === 1)
259
+ return { ...first, continuationHops: 0 };
260
+ const thoughts = requests.flatMap((r) => (r.thoughtsSummary === null ? [] : [r.thoughtsSummary]));
261
+ return {
262
+ text: requests.map((r) => r.text).join(''),
263
+ candidates: mergeCandidates(requests),
264
+ usageMetadata: sumUsage(reportedUsage(requests)),
265
+ thoughtsSummary: thoughts.length > 0 ? thoughts.join('\n').slice(0, THOUGHTS_SUMMARY_MAX_CHARS) : null,
266
+ chunkCount: requests.reduce((n, r) => n + r.chunkCount, 0),
267
+ firstChunkAt: first.firstChunkAt,
268
+ lastChunkAt: last.lastChunkAt,
269
+ continuationToken: last.continuationToken,
270
+ continuationHops: requests.length - 1,
271
+ };
272
+ }
273
+ /** The last request's candidates (its finish reason and metadata), each with the parts of every request. */
274
+ function mergeCandidates(requests) {
275
+ const last = requests[requests.length - 1]?.candidates;
276
+ if (last === undefined)
277
+ return undefined;
278
+ return last.map((cand, i) => {
279
+ const index = cand.index ?? i;
280
+ const parts = requests.flatMap((r) => r.candidates?.find((c, j) => (c.index ?? j) === index)?.content?.parts ?? []);
281
+ return {
282
+ ...cand,
283
+ content: { ...(cand.content ?? {}), role: cand.content?.role ?? 'model', parts },
284
+ };
285
+ });
286
+ }
287
+ function reportedUsage(requests) {
288
+ return requests.flatMap((r) => (r.usageMetadata === undefined ? [] : [r.usageMetadata]));
289
+ }
290
+ /** Each counter summed over the usages reported; `undefined` when none was. */
291
+ function sumUsage(reported) {
292
+ if (reported.length === 0)
293
+ return undefined;
294
+ const sum = {};
295
+ for (const counter of USAGE_COUNTERS) {
296
+ const values = reported.flatMap((u) => (typeof u[counter] === 'number' ? [u[counter]] : []));
297
+ if (values.length > 0)
298
+ sum[counter] = values.reduce((a, b) => a + b, 0);
299
+ }
300
+ return sum;
301
+ }
302
+ //# sourceMappingURL=continuation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continuation.js","sourceRoot":"","sources":["../../../src/tools/shared/continuation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,YAAY,GAMb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAGL,0BAA0B,EAC1B,aAAa,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE/D,0FAA0F;AAC1F,MAAM,CAAC,MAAM,2BAA2B,GACtC,+qBAA+qB,CAAC;AAsElrB;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACX,MAAM,GAAkB,EAAE,CAAC;IACpC,KAAK,GAAG,CAAC,CAAC;IACV,iBAAiB,GAAG,CAAC,CAAC;IACtB,YAAY,GAAG,CAAC,CAAC;IAEzB,2EAA2E;IAC3E,WAAW;QACT,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,gGAAgG;IAChG,IAAI;QACF,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,yGAAyG;IACzG,MAAM,CAAC,KAA8B,EAAE,aAAqB;QAC1D,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,CAAC,IAAI,CAA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TLE_LIMIT`).
3
+ *
4
+ * Each request of the call's decode holds its own reservation, made just before the request is sent and settled
5
+ * when it ends at the input it reported — so every request of a long decode, each of which sends the prompt again
6
+ * plus everything decoded before it, is counted in the window of the minute it was sent in. At most one reservation
7
+ * is held at a time; the call's failure path drops it.
8
+ */
9
+ import type { TpmThrottle } from './throttle.js';
10
+ export interface DispatchThrottleOptions {
11
+ readonly throttle: TpmThrottle;
12
+ /** `false` when the throttle is off (a limit of 0 or less): nothing is reserved. */
13
+ readonly enabled: boolean;
14
+ /** The call's abort signal: a wait for the window ends with it (`timeoutMs`). */
15
+ readonly signal: AbortSignal;
16
+ /** Says a wait for the window on the call's progress channel. */
17
+ readonly emit: (message: string) => void;
18
+ }
19
+ export declare class DispatchThrottle {
20
+ private readonly opts;
21
+ private releaseId;
22
+ private heldModel;
23
+ private heldTokens;
24
+ constructor(opts: DispatchThrottleOptions);
25
+ /**
26
+ * Reserve the input of the next request of `model`, waiting out the window when it is full. A reservation still
27
+ * held (a request that was never sent) is dropped first.
28
+ */
29
+ reserve(model: string, inputTokens: number): Promise<void>;
30
+ /**
31
+ * The request held is sent later than its reservation planned (a reopening after a refusal and its wait): it is
32
+ * reserved again for the window it is sent in now. Nothing is held: nothing to renew.
33
+ */
34
+ renew(): Promise<void>;
35
+ /**
36
+ * The request ended: its reservation settles at the input it reported (cached and uncached alike count against
37
+ * the per-minute quota), or at the reserved estimate when it reported none.
38
+ */
39
+ settle(promptTokens: number | undefined): void;
40
+ /** The call failed: the reservation it holds is dropped. */
41
+ cancel(): void;
42
+ }
43
+ //# sourceMappingURL=dispatch-throttle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch-throttle.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/dispatch-throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;AAKD,qBAAa,gBAAgB;IAKf,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJjC,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAK;IAEvB,YAA6B,IAAI,EAAE,uBAAuB,EAAI;IAE9D;;;OAGG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/D;IAED;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3B;IAED;;;OAGG;IACH,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI7C;IAED,4DAA4D;IAC5D,MAAM,IAAI,IAAI,CAIb;CACF"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The per-minute input throttle of one `ask` / `code` call (`GEMINI_CODE_CONTEXT_TPM_THROTTLE_LIMIT`).
3
+ *
4
+ * Each request of the call's decode holds its own reservation, made just before the request is sent and settled
5
+ * when it ends at the input it reported — so every request of a long decode, each of which sends the prompt again
6
+ * plus everything decoded before it, is counted in the window of the minute it was sent in. At most one reservation
7
+ * is held at a time; the call's failure path drops it.
8
+ */
9
+ import { abortableSleep } from '../../gemini/retry.js';
10
+ import { billedInputTokens } from './call-ledger.js';
11
+ /** No reservation held. */
12
+ const NONE = -1;
13
+ export class DispatchThrottle {
14
+ opts;
15
+ releaseId = NONE;
16
+ heldModel = '';
17
+ heldTokens = 0;
18
+ constructor(opts) {
19
+ this.opts = opts;
20
+ }
21
+ /**
22
+ * Reserve the input of the next request of `model`, waiting out the window when it is full. A reservation still
23
+ * held (a request that was never sent) is dropped first.
24
+ */
25
+ async reserve(model, inputTokens) {
26
+ if (!this.opts.enabled)
27
+ return;
28
+ this.cancel();
29
+ const reservation = this.opts.throttle.reserve(model, inputTokens);
30
+ this.releaseId = reservation.releaseId;
31
+ this.heldModel = model;
32
+ this.heldTokens = inputTokens;
33
+ if (reservation.delayMs <= 0)
34
+ return;
35
+ this.opts.emit(`throttle: waiting ${Math.ceil(reservation.delayMs / 1000)}s for TPM window…`);
36
+ await abortableSleep(reservation.delayMs, this.opts.signal);
37
+ }
38
+ /**
39
+ * The request held is sent later than its reservation planned (a reopening after a refusal and its wait): it is
40
+ * reserved again for the window it is sent in now. Nothing is held: nothing to renew.
41
+ */
42
+ async renew() {
43
+ if (this.releaseId === NONE)
44
+ return;
45
+ await this.reserve(this.heldModel, this.heldTokens);
46
+ }
47
+ /**
48
+ * The request ended: its reservation settles at the input it reported (cached and uncached alike count against
49
+ * the per-minute quota), or at the reserved estimate when it reported none.
50
+ */
51
+ settle(promptTokens) {
52
+ if (this.releaseId === NONE)
53
+ return;
54
+ this.opts.throttle.release(this.releaseId, billedInputTokens(promptTokens, this.heldTokens));
55
+ this.releaseId = NONE;
56
+ }
57
+ /** The call failed: the reservation it holds is dropped. */
58
+ cancel() {
59
+ if (this.releaseId === NONE)
60
+ return;
61
+ this.opts.throttle.cancel(this.releaseId);
62
+ this.releaseId = NONE;
63
+ }
64
+ }
65
+ //# sourceMappingURL=dispatch-throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch-throttle.js","sourceRoot":"","sources":["../../../src/tools/shared/dispatch-throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAarD,2BAA2B;AAC3B,MAAM,IAAI,GAAG,CAAC,CA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,SAAS,EAAE,iBAAiB,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,4DAA4D;IAC5D,MAAM;QACJ,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YAAE,OAAO;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The input fields `ask` and `ask_agentic` share — the question and the workspace it is about: one schema, one text
3
+ * (`ask` hands its input to `ask_agentic` when a workspace is too large for it).
4
+ */
5
+ import { z } from 'zod';
6
+ /** The question, as both tools take it. */
7
+ export declare const PROMPT_FIELD: z.ZodString;
8
+ /** The workspace the question is about, as both tools take it. */
9
+ export declare const WORKSPACE_FIELD: z.ZodOptional<z.ZodString>;
10
+ //# sourceMappingURL=question-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-fields.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/question-fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2CAA2C;AAC3C,eAAO,MAAM,YAAY,aAAkE,CAAC;AAE5F,kEAAkE;AAClE,eAAO,MAAM,eAAe,4BAG6D,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The input fields `ask` and `ask_agentic` share — the question and the workspace it is about: one schema, one text
3
+ * (`ask` hands its input to `ask_agentic` when a workspace is too large for it).
4
+ */
5
+ import { z } from 'zod';
6
+ /** The question, as both tools take it. */
7
+ export const PROMPT_FIELD = z.string().min(1).describe('The question or analysis request.');
8
+ /** The workspace the question is about, as both tools take it. */
9
+ export const WORKSPACE_FIELD = z
10
+ .string()
11
+ .optional()
12
+ .describe('Absolute or cwd-relative path to the workspace. Defaults to process.cwd().');
13
+ //# sourceMappingURL=question-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-fields.js","sourceRoot":"","sources":["../../../src/tools/shared/question-fields.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2CAA2C;AAC3C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,mCAAmC,CAAC,CAAC;AAE5F,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,EAAE;KACR,QAAQ,EAAE;KACV,QAAQ,CAAC,4EAA4E,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * How an `ask` / `code` call settles — the one place both tools do it, so they book the same way and return the same
3
+ * fields.
4
+ *
5
+ * - An answer: the ledger books every completed request at what it billed (best-effort: a failed write is logged, the
6
+ * answer is returned); a stop at the output cap with no text is an `OUTPUT_CAP` error with the usage, the model,
7
+ * the tier and the finish reason.
8
+ * - A failure: a 429's retry hint seeds the per-minute throttle, the ledger keeps what the completed requests billed
9
+ * and releases the rest (all of it when none completed), and the request's per-minute reservation is dropped.
10
+ */
11
+ import type { InputWindowCut } from '../../gemini/long-decode.js';
12
+ import type { ManifestDb } from '../../manifest/db.js';
13
+ import { type FailedCall, type LedgerEntry, type UsageFields } from './call-ledger.js';
14
+ import type { CompletedRequests, DecodedResponse } from './continuation.js';
15
+ import type { DispatchThrottle } from './dispatch-throttle.js';
16
+ import { type AnswerFinish, type CapThatRan } from './thinking.js';
17
+ import { type TpmThrottle } from './throttle.js';
18
+ /** A call whose decode answered. */
19
+ export interface AnsweredCall {
20
+ readonly manifest: ManifestDb;
21
+ readonly reservationId: number | null;
22
+ /** The booking: the tool, the model, the tier, the caching mode that ran. */
23
+ readonly entry: LedgerEntry;
24
+ readonly completed: CompletedRequests;
25
+ readonly response: DecodedResponse;
26
+ /** The cap the decode ran under. */
27
+ readonly cap: CapThatRan;
28
+ /** The cut the model's input window made to the caller's cap; `null`: none. */
29
+ readonly cut: InputWindowCut | null;
30
+ readonly durationMs: number;
31
+ }
32
+ /** A stop at the output cap with no answer: the message (without the tool's prefix) and the result's fields. */
33
+ export interface OutputCapStop {
34
+ readonly message: string;
35
+ readonly fields: Readonly<Record<string, unknown>>;
36
+ }
37
+ export interface SettledAnswer {
38
+ /** What the call billed, for the result. */
39
+ readonly usage: UsageFields;
40
+ readonly finish: AnswerFinish;
41
+ /** The input-window cut as a result field (`outputCapCutByInputWindow`), or nothing. */
42
+ readonly cutFields: Readonly<Record<string, unknown>>;
43
+ /** Set when the call stopped at the cap before writing an answer: the caller returns it as an error. */
44
+ readonly outputCapStop: OutputCapStop | null;
45
+ }
46
+ /**
47
+ * Book the answered call at what its requests billed, and say whether it stopped at the cap with no answer. The booking
48
+ * is best-effort (`recordBilledCall` logs a failed write and never throws): the paid answer is returned whatever the
49
+ * ledger does.
50
+ */
51
+ export declare function settleAnswer(call: AnsweredCall): SettledAnswer;
52
+ /** A call that failed, with what its failure path settles. */
53
+ export interface FailedCallSettlement {
54
+ readonly manifest: ManifestDb;
55
+ readonly failed: FailedCall;
56
+ readonly err: unknown;
57
+ /** The resolved model a 429's retry hint is recorded for; `null` before the model was resolved. */
58
+ readonly model: string | null;
59
+ readonly throttle: Pick<TpmThrottle, 'recordRetryHint'>;
60
+ readonly dispatch: DispatchThrottle;
61
+ }
62
+ /**
63
+ * Settle a failed call; its usage when completed requests were billed, else `null`. A 429's retry hint seeds the
64
+ * throttle through `seedRetryHint`, once per error. A ledger write that throws is logged by `recordBilledCall` /
65
+ * `settleFailedCall` and never replaces the call's own error.
66
+ */
67
+ export declare function settleFailure(settlement: FailedCallSettlement): UsageFields | null;
68
+ //# sourceMappingURL=settle-call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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B,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,wFAAwF;IACxF,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,wGAAwG;IACxG,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;CAC9C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,aAAa,CAuB9D;AAMD,8DAA8D;AAC9D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,mGAAmG;IACnG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;IACxD,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,oBAAoB,GAAG,WAAW,GAAG,IAAI,CAQlF"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * How an `ask` / `code` call settles — the one place both tools do it, so they book the same way and return the same
3
+ * fields.
4
+ *
5
+ * - An answer: the ledger books every completed request at what it billed (best-effort: a failed write is logged, the
6
+ * answer is returned); a stop at the output cap with no text is an `OUTPUT_CAP` error with the usage, the model,
7
+ * the tier and the finish reason.
8
+ * - A failure: a 429's retry hint seeds the per-minute throttle, the ledger keeps what the completed requests billed
9
+ * and releases the rest (all of it when none completed), and the request's per-minute reservation is dropped.
10
+ */
11
+ import { billedUsage, recordBilledCall, settleFailedCall, usageFields, } from './call-ledger.js';
12
+ import { OUTPUT_CAP_ERROR_CODE, answerFinish, emptyAtOutputCap, } from './thinking.js';
13
+ import { seedRetryHint } from './throttle.js';
14
+ /**
15
+ * Book the answered call at what its requests billed, and say whether it stopped at the cap with no answer. The booking
16
+ * is best-effort (`recordBilledCall` logs a failed write and never throws): the paid answer is returned whatever the
17
+ * ledger does.
18
+ */
19
+ export function settleAnswer(call) {
20
+ const billed = billedUsage(call.completed.usage(), call.entry.model, call.entry.serviceTier);
21
+ recordBilledCall(call.manifest, call.reservationId, call.entry, billed, call.durationMs);
22
+ const usage = usageFields(billed, call.response.continuationHops);
23
+ const finish = answerFinish(call.response);
24
+ const cutFields = inputWindowCutFields(call.cut);
25
+ const starved = emptyAtOutputCap(call.response, billed.thinkingTokens, call.cap, call.cut);
26
+ const outputCapStop = starved === null
27
+ ? null
28
+ : {
29
+ message: starved,
30
+ fields: {
31
+ errorCode: OUTPUT_CAP_ERROR_CODE,
32
+ retryable: false,
33
+ resolvedModel: call.entry.model,
34
+ serviceTier: call.entry.serviceTier,
35
+ finishReason: finish.finishReason,
36
+ ...usage,
37
+ ...cutFields,
38
+ },
39
+ };
40
+ return { usage, finish, cutFields, outputCapStop };
41
+ }
42
+ function inputWindowCutFields(cut) {
43
+ return cut === null ? {} : { outputCapCutByInputWindow: cut };
44
+ }
45
+ /**
46
+ * Settle a failed call; its usage when completed requests were billed, else `null`. A 429's retry hint seeds the
47
+ * throttle through `seedRetryHint`, once per error. A ledger write that throws is logged by `recordBilledCall` /
48
+ * `settleFailedCall` and never replaces the call's own error.
49
+ */
50
+ export function settleFailure(settlement) {
51
+ const { err, model } = settlement;
52
+ if (model !== null) {
53
+ seedRetryHint(settlement.throttle, model, err);
54
+ }
55
+ const usage = settleFailedCall(settlement.manifest, settlement.failed);
56
+ settlement.dispatch.cancel();
57
+ return usage;
58
+ }
59
+ //# sourceMappingURL=settle-call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settle-call.js","sourceRoot":"","sources":["../../../src/tools/shared/settle-call.ts"],"names":[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AAC,WAAW;gBACnC,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,GAAG,KAAK;gBACR,GAAG,SAAS;aACb;SACF,CAAC;IACR,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,GAA0B;IACtD,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,yBAAyB,EAAE,GAAG,EAAE,CAAC;AAChE,CAAC;AAaD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAAgC;IAC5D,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC;IAClC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACvE,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC7B,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -70,6 +70,8 @@
70
70
  * branch invalidates and opens a NEW full stream. Discards partial.
71
71
  */
72
72
  import type { GenerateContentResponse } from '@google/genai';
73
+ /** The thought summary a response carries is cut to this many characters. */
74
+ export declare const THOUGHTS_SUMMARY_MAX_CHARS = 1200;
73
75
  export interface StreamCollectorOptions {
74
76
  /** Per-call abort (T19). Threading through here means we drop chunks the
75
77
  * moment timeout fires, not after the next one comes through. */
@@ -108,6 +110,11 @@ export interface CollectedResponse {
108
110
  /** Wall-clock timestamps for first/last chunk arrival (Date.now() values). */
109
111
  readonly firstChunkAt: number | null;
110
112
  readonly lastChunkAt: number | null;
113
+ /**
114
+ * The latest `continuationToken` the first candidate carried (Gemini 4 long decode: the stream ended with
115
+ * `finishReason: CONTINUATION`, or passed a checkpoint); `null` when no chunk carried one.
116
+ */
117
+ readonly continuationToken: string | null;
111
118
  }
112
119
  /**
113
120
  * Drive an `AsyncGenerator<GenerateContentResponse>` to completion and
@@ -1 +1 @@
1
- {"version":3,"file":"stream-collector.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/stream-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,OAAO,KAAK,EAAa,uBAAuB,EAAQ,MAAM,eAAe,CAAC;AAK9E,MAAM,WAAW,sBAAsB;IACrC;qEACiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B;;sEAEkE;IAClE,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD;gFAC4E;IAC5E,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACxC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,UAAU,EAAE,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC3D,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,EAAE,uBAAuB,CAAC,eAAe,CAAC,CAAC;IACjE,4EAA4E;IAC5E,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAED;;;;;;;GAOG;A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