@qmediat.io/gemini-code-context-mcp 1.24.0 → 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 (98) hide show
  1. package/CHANGELOG.md +90 -1
  2. package/README.md +1 -1
  3. package/dist/tools/agentic/dispatch.d.ts +68 -0
  4. package/dist/tools/agentic/dispatch.d.ts.map +1 -0
  5. package/dist/tools/agentic/dispatch.js +167 -0
  6. package/dist/tools/agentic/dispatch.js.map +1 -0
  7. package/dist/tools/agentic/input.d.ts +28 -0
  8. package/dist/tools/agentic/input.d.ts.map +1 -0
  9. package/dist/tools/agentic/input.js +66 -0
  10. package/dist/tools/agentic/input.js.map +1 -0
  11. package/dist/tools/agentic/instructions.d.ts +46 -0
  12. package/dist/tools/agentic/instructions.d.ts.map +1 -0
  13. package/dist/tools/agentic/instructions.js +170 -0
  14. package/dist/tools/agentic/instructions.js.map +1 -0
  15. package/dist/tools/agentic/iteration.d.ts +81 -0
  16. package/dist/tools/agentic/iteration.d.ts.map +1 -0
  17. package/dist/tools/agentic/iteration.js +317 -0
  18. package/dist/tools/agentic/iteration.js.map +1 -0
  19. package/dist/tools/agentic/ledger.d.ts +64 -0
  20. package/dist/tools/agentic/ledger.d.ts.map +1 -0
  21. package/dist/tools/agentic/ledger.js +110 -0
  22. package/dist/tools/agentic/ledger.js.map +1 -0
  23. package/dist/tools/agentic/loop.d.ts +10 -0
  24. package/dist/tools/agentic/loop.d.ts.map +1 -0
  25. package/dist/tools/agentic/loop.js +179 -0
  26. package/dist/tools/agentic/loop.js.map +1 -0
  27. package/dist/tools/agentic/no-progress.d.ts +90 -0
  28. package/dist/tools/agentic/no-progress.d.ts.map +1 -0
  29. package/dist/tools/agentic/no-progress.js +107 -0
  30. package/dist/tools/agentic/no-progress.js.map +1 -0
  31. package/dist/tools/agentic/pass-clock.d.ts +85 -0
  32. package/dist/tools/agentic/pass-clock.d.ts.map +1 -0
  33. package/dist/tools/agentic/pass-clock.js +162 -0
  34. package/dist/tools/agentic/pass-clock.js.map +1 -0
  35. package/dist/tools/agentic/phase-defaults.d.ts +29 -0
  36. package/dist/tools/agentic/phase-defaults.d.ts.map +1 -0
  37. package/dist/tools/agentic/phase-defaults.js +23 -0
  38. package/dist/tools/agentic/phase-defaults.js.map +1 -0
  39. package/dist/tools/agentic/rescue.d.ts +69 -0
  40. package/dist/tools/agentic/rescue.d.ts.map +1 -0
  41. package/dist/tools/agentic/rescue.js +203 -0
  42. package/dist/tools/agentic/rescue.js.map +1 -0
  43. package/dist/tools/agentic/response.d.ts +16 -0
  44. package/dist/tools/agentic/response.d.ts.map +1 -0
  45. package/dist/tools/agentic/response.js +25 -0
  46. package/dist/tools/agentic/response.js.map +1 -0
  47. package/dist/tools/agentic/results.d.ts +76 -0
  48. package/dist/tools/agentic/results.d.ts.map +1 -0
  49. package/dist/tools/agentic/results.js +228 -0
  50. package/dist/tools/agentic/results.js.map +1 -0
  51. package/dist/tools/agentic/run.d.ts +130 -0
  52. package/dist/tools/agentic/run.d.ts.map +1 -0
  53. package/dist/tools/agentic/run.js +131 -0
  54. package/dist/tools/agentic/run.js.map +1 -0
  55. package/dist/tools/agentic/sandbox.d.ts +13 -2
  56. package/dist/tools/agentic/sandbox.d.ts.map +1 -1
  57. package/dist/tools/agentic/sandbox.js +127 -111
  58. package/dist/tools/agentic/sandbox.js.map +1 -1
  59. package/dist/tools/agentic/workspace-tools.d.ts +30 -27
  60. package/dist/tools/agentic/workspace-tools.d.ts.map +1 -1
  61. package/dist/tools/agentic/workspace-tools.js +324 -385
  62. package/dist/tools/agentic/workspace-tools.js.map +1 -1
  63. package/dist/tools/ask-agentic-fallback.d.ts +33 -0
  64. package/dist/tools/ask-agentic-fallback.d.ts.map +1 -0
  65. package/dist/tools/ask-agentic-fallback.js +113 -0
  66. package/dist/tools/ask-agentic-fallback.js.map +1 -0
  67. package/dist/tools/ask-agentic.tool.d.ts +11 -44
  68. package/dist/tools/ask-agentic.tool.d.ts.map +1 -1
  69. package/dist/tools/ask-agentic.tool.js +142 -1615
  70. package/dist/tools/ask-agentic.tool.js.map +1 -1
  71. package/dist/tools/ask.tool.d.ts.map +1 -1
  72. package/dist/tools/ask.tool.js +29 -178
  73. package/dist/tools/ask.tool.js.map +1 -1
  74. package/dist/tools/code.tool.js +9 -20
  75. package/dist/tools/code.tool.js.map +1 -1
  76. package/dist/tools/shared/abort-timeout.d.ts +43 -5
  77. package/dist/tools/shared/abort-timeout.d.ts.map +1 -1
  78. package/dist/tools/shared/abort-timeout.js +111 -102
  79. package/dist/tools/shared/abort-timeout.js.map +1 -1
  80. package/dist/tools/shared/call-ledger.d.ts +27 -12
  81. package/dist/tools/shared/call-ledger.d.ts.map +1 -1
  82. package/dist/tools/shared/call-ledger.js +57 -39
  83. package/dist/tools/shared/call-ledger.js.map +1 -1
  84. package/dist/tools/shared/continuation.d.ts +1 -1
  85. package/dist/tools/shared/continuation.d.ts.map +1 -1
  86. package/dist/tools/shared/question-fields.d.ts +10 -0
  87. package/dist/tools/shared/question-fields.d.ts.map +1 -0
  88. package/dist/tools/shared/question-fields.js +13 -0
  89. package/dist/tools/shared/question-fields.js.map +1 -0
  90. package/dist/tools/shared/settle-call.d.ts +11 -6
  91. package/dist/tools/shared/settle-call.d.ts.map +1 -1
  92. package/dist/tools/shared/settle-call.js +14 -10
  93. package/dist/tools/shared/settle-call.js.map +1 -1
  94. package/dist/tools/shared/throttle.d.ts +7 -0
  95. package/dist/tools/shared/throttle.d.ts.map +1 -1
  96. package/dist/tools/shared/throttle.js +18 -0
  97. package/dist/tools/shared/throttle.js.map +1 -1
  98. package/package.json +1 -1
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The one clock of an `ask_agentic` pass (a loop iteration or the forced-finalization pass): every phase of the pass
3
+ * reads its bound from it (`docs/DESIGN-agentic-time-bounds.md`). `iterationTimeoutMs` is the pass's wall clock, armed
4
+ * at creation over every phase; `stallMs` bounds the gaps of the stream only — armed at the first chunk, re-armed per
5
+ * chunk, cleared when the pass leaves the stream; a phase's default (`phase-defaults.ts`) applies only where no knob
6
+ * bounds that phase — the tools phase's is a bound on silence, which executor progress (`recordProgress`) defers. At
7
+ * most two timers are alive at once: the pass deadline and the current phase's.
8
+ */
9
+ import { type TimeoutKind } from '../shared/abort-timeout.js';
10
+ import { type PhaseDefaults } from './phase-defaults.js';
11
+ /** The phases of one pass, in order. The forced pass has `tpm-wait` and `finalization` only. */
12
+ export type PassPhase = 'tpm-wait' | 'opening' | 'stream' | 'tools' | 'finalization';
13
+ /** The phases a default bounds: every phase but the TPM wait, whose throttle delay is finite and known at its start. */
14
+ export type DefaultedPhase = Exclude<PassPhase, 'tpm-wait'>;
15
+ /** The knobs of a call that the clock keeps as bounds. */
16
+ export type KnobSource = 'iterationTimeoutMs' | 'stallMs';
17
+ /** Where a bound the clock keeps comes from. */
18
+ export type ClockSource = KnobSource | 'default';
19
+ /** Where the timeout that ended a pass comes from: a bound of the clock, or `external` — a `TimeoutError` the clock did
20
+ * not raise (an SDK's own), which no bound of this call set. */
21
+ export type BoundSource = ClockSource | 'external';
22
+ /** The call's two knobs, resolved once per call (per call, else the environment); `null` when unset. */
23
+ export interface AgenticKnobs {
24
+ readonly iterationMs: number | null;
25
+ readonly stallMs: number | null;
26
+ }
27
+ /** A knob of the call fired, in the phase the pass was in: read from the clock, never parsed from a message. */
28
+ export interface KnobTimeout {
29
+ readonly phase: PassPhase;
30
+ readonly kind: TimeoutKind;
31
+ readonly source: KnobSource;
32
+ readonly limitMs: number;
33
+ }
34
+ /** A phase's default fired: never in the TPM wait, which has none. */
35
+ export interface DefaultTimeout {
36
+ readonly phase: DefaultedPhase;
37
+ readonly kind: TimeoutKind;
38
+ readonly source: 'default';
39
+ readonly limitMs: number;
40
+ }
41
+ /** A bound of the clock fired. */
42
+ export type ClockTimeout = KnobTimeout | DefaultTimeout;
43
+ /** A `TimeoutError` the clock did not raise ended the pass: no bound of this call fired; `message` is the error's own. */
44
+ export interface ExternalTimeout {
45
+ readonly phase: PassPhase;
46
+ readonly kind: TimeoutKind;
47
+ readonly source: 'external';
48
+ readonly limitMs: null;
49
+ readonly message: string;
50
+ }
51
+ /** What ended a pass on a timeout. */
52
+ export type PassTimeout = ClockTimeout | ExternalTimeout;
53
+ export interface PassClock {
54
+ /** Fires when a bound of the pass fires; its reason is a `TimeoutError` carrying `timeoutPhase` / `timeoutSource`. */
55
+ readonly signal: AbortSignal;
56
+ /** The pass's wall clock (`iterationTimeoutMs`), `null` when unset. */
57
+ readonly timeoutMs: number | null;
58
+ /** The stream's gap watchdog (`stallMs`), `null` when unset. */
59
+ readonly stallMs: number | null;
60
+ readonly phase: PassPhase;
61
+ /** The bound that fired, `null` while none has. */
62
+ readonly timedOut: ClockTimeout | null;
63
+ /** How long, after the tools phase's bound fired, the executors still running are given to settle. */
64
+ readonly settleGraceMs: number;
65
+ /** Leave the current phase: its timer is cleared and the next phase's armed. Entering the phase the pass is in arms
66
+ * its default afresh. A no-op after a fire and after `dispose`: the clock's phase is then the one it stopped in. */
67
+ enter(phase: PassPhase): void;
68
+ /** A chunk arrived: the first one moves `opening` to `stream`; each one re-arms the gap timer. A no-op after a fire
69
+ * and after `dispose`. */
70
+ recordChunk(): void;
71
+ /** An executor made progress: in phase `tools` the silence its default counts starts again; a no-op in every other
72
+ * phase, under `iterationTimeoutMs` (no phase timer: the deadline stays a wall clock), after a fire and after
73
+ * `dispose`. A tick writes one timestamp; the timer is re-armed only when it expires. */
74
+ recordProgress(): void;
75
+ /** Clear both timers. Idempotent; nothing is armed afterwards. */
76
+ dispose(): void;
77
+ }
78
+ /** A new pass's clock, in phase `tpm-wait`, the pass deadline armed when `iterationTimeoutMs` is set. */
79
+ export declare function createPassClock(knobs: AgenticKnobs, defaults?: PhaseDefaults): PassClock;
80
+ /**
81
+ * What ended a pass that failed on a timeout: the bound the clock fired, else an `external` timeout — the error's own
82
+ * kind and message, in the phase the pass was in, no bound of this call named.
83
+ */
84
+ export declare function passTimeoutOf(clock: PassClock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E,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,WAAW,CASzE"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The one clock of an `ask_agentic` pass (a loop iteration or the forced-finalization pass): every phase of the pass
3
+ * reads its bound from it (`docs/DESIGN-agentic-time-bounds.md`). `iterationTimeoutMs` is the pass's wall clock, armed
4
+ * at creation over every phase; `stallMs` bounds the gaps of the stream only — armed at the first chunk, re-armed per
5
+ * chunk, cleared when the pass leaves the stream; a phase's default (`phase-defaults.ts`) applies only where no knob
6
+ * bounds that phase — the tools phase's is a bound on silence, which executor progress (`recordProgress`) defers. At
7
+ * most two timers are alive at once: the pass deadline and the current phase's.
8
+ */
9
+ import { getTimeoutKind, timeoutReason, unrefTimer, } from '../shared/abort-timeout.js';
10
+ import { PHASE_DEFAULTS } from './phase-defaults.js';
11
+ /** The default of phase `phase` when no knob bounds it; `null` while `iterationTimeoutMs` bounds the pass. */
12
+ const unlessDeadline = (phase, defaultMs, idle = false) => (knobs, d) => knobs.iterationMs === null
13
+ ? { kind: 'total', source: 'default', phase, limitMs: defaultMs(d), idle }
14
+ : null;
15
+ /** A stream gap: `stallMs`, else the default when no knob bounds the stream. Each chunk re-arms it (`recordChunk`). */
16
+ function streamGapBound(knobs, d) {
17
+ if (knobs.stallMs !== null) {
18
+ return { kind: 'stall', source: 'stallMs', limitMs: knobs.stallMs, idle: false };
19
+ }
20
+ if (knobs.iterationMs !== null)
21
+ return null;
22
+ return { kind: 'stall', source: 'default', phase: 'stream', limitMs: d.streamGapMs, idle: false };
23
+ }
24
+ const PHASE_BOUND = {
25
+ 'tpm-wait': () => null,
26
+ opening: unlessDeadline('opening', (d) => d.openingMs),
27
+ stream: streamGapBound,
28
+ tools: unlessDeadline('tools', (d) => d.toolsIdleMs, true),
29
+ finalization: unlessDeadline('finalization', (d) => d.finalizationMs),
30
+ };
31
+ /** What a fired bound reports: a default its own phase — the one it was armed for, which is the pass's phase, since
32
+ * leaving the phase clears it —, a knob the phase the pass is in. */
33
+ function timeoutOf(bound, current) {
34
+ const { kind, limitMs } = bound;
35
+ if (bound.source === 'default')
36
+ return { phase: bound.phase, kind, source: 'default', limitMs };
37
+ return { phase: current, kind, source: bound.source, limitMs };
38
+ }
39
+ /** One pass's clock: one `AbortController`, the pass deadline's timer and the current phase's. */
40
+ class Clock {
41
+ knobs;
42
+ defaults;
43
+ signal;
44
+ timeoutMs;
45
+ stallMs;
46
+ controller = new AbortController();
47
+ current = 'tpm-wait';
48
+ fired = null;
49
+ /** When the current phase's silence started: its timer's arming, or the last executor progress since. */
50
+ quietSince = 0;
51
+ disposed = false;
52
+ passTimer = null;
53
+ phaseTimer = null;
54
+ constructor(knobs, defaults) {
55
+ this.knobs = knobs;
56
+ this.defaults = defaults;
57
+ this.signal = this.controller.signal;
58
+ this.timeoutMs = knobs.iterationMs;
59
+ this.stallMs = knobs.stallMs;
60
+ if (knobs.iterationMs !== null) {
61
+ const deadline = {
62
+ kind: 'total',
63
+ source: 'iterationTimeoutMs',
64
+ limitMs: knobs.iterationMs,
65
+ idle: false,
66
+ };
67
+ this.passTimer = unrefTimer(deadline.limitMs, () => this.fire(deadline));
68
+ }
69
+ }
70
+ get phase() {
71
+ return this.current;
72
+ }
73
+ get timedOut() {
74
+ return this.fired;
75
+ }
76
+ get settleGraceMs() {
77
+ return this.defaults.toolSettleGraceMs;
78
+ }
79
+ enter(phase) {
80
+ if (this.stopped())
81
+ return;
82
+ this.current = phase;
83
+ this.armPhase();
84
+ }
85
+ recordChunk() {
86
+ if (this.stopped())
87
+ return;
88
+ if (this.current === 'opening')
89
+ this.current = 'stream';
90
+ if (this.current === 'stream')
91
+ this.armPhase();
92
+ }
93
+ recordProgress() {
94
+ if (this.current === 'tools' && this.phaseTimer !== null)
95
+ this.quietSince = performance.now();
96
+ }
97
+ dispose() {
98
+ this.disposed = true;
99
+ this.clearTimers();
100
+ }
101
+ /** A fired or disposed clock arms nothing and its phase stays where it stopped. */
102
+ stopped() {
103
+ return this.disposed || this.signal.aborted;
104
+ }
105
+ armPhase() {
106
+ this.clearPhaseTimer();
107
+ const bound = PHASE_BOUND[this.current](this.knobs, this.defaults);
108
+ if (bound === null)
109
+ return;
110
+ this.quietSince = performance.now();
111
+ this.phaseTimer = unrefTimer(bound.limitMs, () => this.phaseExpired(bound));
112
+ }
113
+ /** The phase's timer ran out: an idle bound with progress since its arming waits out the rest of its silence. */
114
+ phaseExpired(bound) {
115
+ const quietMs = performance.now() - this.quietSince;
116
+ if (bound.idle && quietMs < bound.limitMs) {
117
+ this.phaseTimer = unrefTimer(bound.limitMs - quietMs, () => this.phaseExpired(bound));
118
+ return;
119
+ }
120
+ this.fire(bound);
121
+ }
122
+ fire(bound) {
123
+ if (this.signal.aborted)
124
+ return;
125
+ const fired = timeoutOf(bound, this.current);
126
+ this.fired = fired;
127
+ this.clearTimers();
128
+ const extra = { timeoutPhase: fired.phase, timeoutSource: fired.source };
129
+ this.controller.abort(timeoutReason(fired.limitMs, fired.kind, extra));
130
+ }
131
+ clearPhaseTimer() {
132
+ if (this.phaseTimer !== null)
133
+ clearTimeout(this.phaseTimer);
134
+ this.phaseTimer = null;
135
+ }
136
+ clearTimers() {
137
+ if (this.passTimer !== null)
138
+ clearTimeout(this.passTimer);
139
+ this.passTimer = null;
140
+ this.clearPhaseTimer();
141
+ }
142
+ }
143
+ /** A new pass's clock, in phase `tpm-wait`, the pass deadline armed when `iterationTimeoutMs` is set. */
144
+ export function createPassClock(knobs, defaults = PHASE_DEFAULTS) {
145
+ return new Clock(knobs, defaults);
146
+ }
147
+ /**
148
+ * What ended a pass that failed on a timeout: the bound the clock fired, else an `external` timeout — the error's own
149
+ * kind and message, in the phase the pass was in, no bound of this call named.
150
+ */
151
+ export function passTimeoutOf(clock, err) {
152
+ if (clock.timedOut !== null)
153
+ return clock.timedOut;
154
+ return {
155
+ phase: clock.phase,
156
+ kind: getTimeoutKind(err) ?? 'total',
157
+ source: 'external',
158
+ limitMs: null,
159
+ message: err instanceof Error ? err.message : String(err),
160
+ };
161
+ }
162
+ //# sourceMappingURL=pass-clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pass-clock.js","sourceRoot":"","sources":["../../../src/tools/agentic/pass-clock.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,cAAc,EACd,aAAa,EACb,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAsB,MAAM,qBAAqB,CAAC;AAqGzE,8GAA8G;AAC9G,MAAM,cAAc,GAClB,CAA2B,KAAQ,EAAE,SAAuC,EAAE,IAAI,GAAG,KAAK,EAAE,EAAE,CAC9F,CAAC,KAAmB,EAAE,CAAgB,EAAiD,EAAE,CACvF,KAAK,CAAC,WAAW,KAAK,IAAI;IACxB,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE;IAC1E,CAAC,CAAC,IAAI,CAAC;AAEb,uHAAuH;AACvH,SAAS,cAAc,CACrB,KAAmB,EACnB,CAAgB;IAEhB,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACnF,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACpG,CAAC;AAWD,MAAM,WAAW,GAAgB;IAC/B,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI;IACtB,OAAO,EAAE,cAAc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@
1
+ /**
2
+ * The bound of each phase of an `ask_agentic` pass that no knob bounds (`docs/DESIGN-agentic-time-bounds.md`):
3
+ * `iterationTimeoutMs` bounds every phase of a pass, `stallMs` the gaps of a stream, and a default applies only where
4
+ * neither does. The tests replace this module with bounds of milliseconds.
5
+ */
6
+ export interface PhaseDefaults {
7
+ /** A request's opening, until its first chunk. */
8
+ readonly openingMs: number;
9
+ /** A gap between two chunks of a stream (reported as a `stall`). */
10
+ readonly streamGapMs: number;
11
+ /** The silence of an iteration's tools phase (path resolution and the tool batch): how long it may go without
12
+ * executor progress (`PassClock.recordProgress`). */
13
+ readonly toolsIdleMs: number;
14
+ /** The forced-finalization pass's call. */
15
+ readonly finalizationMs: number;
16
+ /** How long, after the tools bound fired, the executors still running are given to settle. */
17
+ readonly toolSettleGraceMs: number;
18
+ }
19
+ /**
20
+ * Silence longer than the longest stall watchdog a caller may set (`stallMs` ≤ 600 000 ms) is a hang, not a slow
21
+ * model: each request's opening, a stream gap and each request of the forced pass end there. The tools phase is bounded
22
+ * by silence too, never by its length: the executors bound what they return (200 KB per read, 100 grep matches, 200
23
+ * entries, a walk depth of 20), not how long they run, and a healthy batch of `grep` calls over a large workspace runs
24
+ * for minutes (ten in parallel over 80 000 files: 32 s; forty: 133 s) while it reports progress at every directory and
25
+ * file — 120 000 ms without any ends a batch that hangs. An executor that reads the abort signal settles in well under
26
+ * the 1 000 ms grace.
27
+ */
28
+ export declare const PHASE_DEFAULTS: PhaseDefaults;
29
+ //# sourceMappingURL=phase-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase-defaults.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/phase-defaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;yDACqD;IACrD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,EAAE,aAM3B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The bound of each phase of an `ask_agentic` pass that no knob bounds (`docs/DESIGN-agentic-time-bounds.md`):
3
+ * `iterationTimeoutMs` bounds every phase of a pass, `stallMs` the gaps of a stream, and a default applies only where
4
+ * neither does. The tests replace this module with bounds of milliseconds.
5
+ */
6
+ import { STALL_ABSOLUTE_MAX_MS } from '../shared/abort-timeout.js';
7
+ /**
8
+ * Silence longer than the longest stall watchdog a caller may set (`stallMs` ≤ 600 000 ms) is a hang, not a slow
9
+ * model: each request's opening, a stream gap and each request of the forced pass end there. The tools phase is bounded
10
+ * by silence too, never by its length: the executors bound what they return (200 KB per read, 100 grep matches, 200
11
+ * entries, a walk depth of 20), not how long they run, and a healthy batch of `grep` calls over a large workspace runs
12
+ * for minutes (ten in parallel over 80 000 files: 32 s; forty: 133 s) while it reports progress at every directory and
13
+ * file — 120 000 ms without any ends a batch that hangs. An executor that reads the abort signal settles in well under
14
+ * the 1 000 ms grace.
15
+ */
16
+ export const PHASE_DEFAULTS = Object.freeze({
17
+ openingMs: STALL_ABSOLUTE_MAX_MS,
18
+ streamGapMs: STALL_ABSOLUTE_MAX_MS,
19
+ toolsIdleMs: 120_000,
20
+ finalizationMs: STALL_ABSOLUTE_MAX_MS,
21
+ toolSettleGraceMs: 1_000,
22
+ });
23
+ //# sourceMappingURL=phase-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase-defaults.js","sourceRoot":"","sources":["../../../src/tools/agentic/phase-defaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAgBnE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkB,MAAM,CAAC,MAAM,CAAC;IACzD,SAAS,EAAE,qBAAqB;IAChC,WAAW,EAAE,qBAAqB;IAClC,WAAW,EAAE,OAAO;IACpB,cAAc,EAAE,qBAAqB;IACrC,iBAAiB,EAAE,KAAK;CACzB,CAAC,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The forced-finalization rescue: the loop exhausted `maxIterations` without an organic final-text turn, so ONE more
3
+ * `generateContent` runs with `toolConfig.functionCallingConfig.mode = NONE` — the model is prohibited from emitting
4
+ * more function calls (Gemini API spec: NONE = "equivalent to sending a request without any function declarations")
5
+ * and must answer in text using the conversation it has already accumulated. This converts what was previously an
6
+ * opaque error into a synthesized text answer derived from the tool responses gathered so far. If the forced call
7
+ * itself fails (timeout, network, budget exhausted, empty text), the caller still gets a structured failure signal.
8
+ *
9
+ * v1.14.2: the rescue pass is NOT gated on `maxTotalInputTokens`. It is the documented exit path for "loop ran out
10
+ * of iterations without final text" and blocking it on rescue's own potential overshoot defeats the v1.14.1 feature —
11
+ * an operator running near the cap would never get the synthesised answer the rescue is designed to produce. Rescue
12
+ * cost remains bounded by the `dailyBudgetUsd` reservation, wall-clock by `iterationTimeoutMs` — else by the
13
+ * finalization default (`phase-defaults.ts`). Cap-overshoot is signalled via `overBudget: true` on the result so
14
+ * callers can detect the trade.
15
+ *
16
+ * The rescue calls `generateContent`, not the stream: its pass clock has the phases `tpm-wait` and `finalization` —
17
+ * entered by each request and by a retry's announcement, so each request, its backoff included, gets the whole default
18
+ * — and no stream gap to watch. Its call is marked completed the moment `generateContent` returned (`completeCall`, the
19
+ * idiom of the loop iteration), before the response is read.
20
+ */
21
+ import type { BilledFields } from '../shared/call-ledger.js';
22
+ import { type PassTimeout } from './pass-clock.js';
23
+ import { type UsageCounts } from './response.js';
24
+ import { type AgenticRun, type LoopState } from './run.js';
25
+ /**
26
+ * P4 (v1.15.0): caller-visible rescue failure-class signal, surfaced as
27
+ * `structuredContent.rescueErrorCode` so wrappers can branch retry behaviour
28
+ * without log scraping. Strict union — extend here when adding new error
29
+ * classes.
30
+ *
31
+ * - 'TIMEOUT' — iterationTimeoutMs, else the finalization default, fired (isTimeoutAbort)
32
+ * - 'RATE_LIMIT' — Google 429 (isGemini429: ApiError + status===429)
33
+ * - 'INTERNAL' — the call completed (await returned), but reading its
34
+ * response threw — the pass is booked, but the caller
35
+ * sees a structured failure. Distinguishes "API ok, our
36
+ * code bug" from "API failure" so wrappers don't blindly
37
+ * retry our parse bugs.
38
+ * - 'API_ERROR' — `instanceof ApiError` with status≠429 (4xx other
39
+ * than 429, or 5xx). Wrapper should NOT retry 4xx
40
+ * (fix the payload) but MAY retry 5xx with backoff.
41
+ * - 'NETWORK' — fetch-layer / DNS / TCP / pre-dispatch SDK error.
42
+ * Real transient connectivity case; safe to retry.
43
+ * - 'EMPTY_TEXT' — set in success path: API returned, but extracted
44
+ * text was empty after .trim(). Budget IS finalized.
45
+ */
46
+ export type RescueErrorCode = 'TIMEOUT' | 'RATE_LIMIT' | 'INTERNAL' | 'API_ERROR' | 'NETWORK' | 'EMPTY_TEXT';
47
+ /** What the finalization pass produced. */
48
+ export interface RescueOutcome {
49
+ /** The answer, trimmed; empty when the pass produced none. */
50
+ text: string;
51
+ usage: UsageCounts;
52
+ thinkingSummary: string | null;
53
+ /** Whether the finalization `generateContent` call was dispatched (regardless of outcome) — `apiCalls`
54
+ * counts it even when a mid-flight timeout or a pre-response network failure left the usage at 0. */
55
+ attempted: boolean;
56
+ /** `null` when the rescue produced text (the answer then carries `convergenceForced: true`) or was skipped. */
57
+ errorCode: RescueErrorCode | null;
58
+ /** The failure's message, cut to 500 characters; `null` unless the call threw. */
59
+ errorMessage: string | null;
60
+ /** v1.14.2 Fix 5: WHY the rescue pass was skipped — 'daily-budget' when `reserveBudget` rejected. */
61
+ skipReason: 'daily-budget' | null;
62
+ /** The pass's billed fields when its call completed and it was booked; `null` when it was skipped or cancelled. */
63
+ billed: BilledFields | null;
64
+ /** What ended the pass when it timed out (`errorCode: 'TIMEOUT'`), read from its clock; `null` otherwise. */
65
+ timeout: PassTimeout | null;
66
+ }
67
+ /** Run the forced-finalization pass after the loop exhausted `maxIterations`. */
68
+ export declare function runRescue(run: AgenticRun, state: LoopState): Promise<RescueOutcome>;
69
+ //# sourceMappingURL=rescue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rescue.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/rescue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAOH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAa7D,OAAO,EAAkB,KAAK,WAAW,EAAkC,MAAM,iBAAiB,CAAC;AACnG,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EAGf,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,YAAY,GACZ,UAAU,GACV,WAAW,GACX,SAAS,GACT,YAAY,CAAC;AAEjB,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;yGACqG;IACrG,SAAS,EAAE,OAAO,CAAC;IACnB,+GAA+G;IAC/G,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,kFAAkF;IAClF,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,qGAAqG;IACrG,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;IAClC,mHAAmH;IACnH,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,6GAA6G;IAC7G,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;CAC7B;AAoND,iFAAiF;AACjF,wBAAsB,SAAS,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAqBzF"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * The forced-finalization rescue: the loop exhausted `maxIterations` without an organic final-text turn, so ONE more
3
+ * `generateContent` runs with `toolConfig.functionCallingConfig.mode = NONE` — the model is prohibited from emitting
4
+ * more function calls (Gemini API spec: NONE = "equivalent to sending a request without any function declarations")
5
+ * and must answer in text using the conversation it has already accumulated. This converts what was previously an
6
+ * opaque error into a synthesized text answer derived from the tool responses gathered so far. If the forced call
7
+ * itself fails (timeout, network, budget exhausted, empty text), the caller still gets a structured failure signal.
8
+ *
9
+ * v1.14.2: the rescue pass is NOT gated on `maxTotalInputTokens`. It is the documented exit path for "loop ran out
10
+ * of iterations without final text" and blocking it on rescue's own potential overshoot defeats the v1.14.1 feature —
11
+ * an operator running near the cap would never get the synthesised answer the rescue is designed to produce. Rescue
12
+ * cost remains bounded by the `dailyBudgetUsd` reservation, wall-clock by `iterationTimeoutMs` — else by the
13
+ * finalization default (`phase-defaults.ts`). Cap-overshoot is signalled via `overBudget: true` on the result so
14
+ * callers can detect the trade.
15
+ *
16
+ * The rescue calls `generateContent`, not the stream: its pass clock has the phases `tpm-wait` and `finalization` —
17
+ * entered by each request and by a retry's announcement, so each request, its backoff included, gets the whole default
18
+ * — and no stream gap to watch. Its call is marked completed the moment `generateContent` returned (`completeCall`, the
19
+ * idiom of the loop iteration), before the response is read.
20
+ */
21
+ import { ApiError, FunctionCallingConfigMode } from '@google/genai';
22
+ import { withNetworkRetry } from '../../gemini/retry.js';
23
+ import { logger } from '../../utils/logger.js';
24
+ import { isTimeoutAbort } from '../shared/abort-timeout.js';
25
+ import { isGemini429, seedRetryHint } from '../shared/throttle.js';
26
+ import { SYSTEM_INSTRUCTION_FINALIZATION } from './instructions.js';
27
+ import { NO_THROTTLE_RESERVATION, callNotMade, closePass, completeCall, reservePass, waitForTpm, } from './ledger.js';
28
+ import { createPassClock, passTimeoutOf } from './pass-clock.js';
29
+ import { thinkingSummaryOf } from './response.js';
30
+ import { PER_ITERATION_INPUT_TOKENS, passReservationUsd, } from './run.js';
31
+ const errorText = (err) => (err instanceof Error ? err.message : String(err));
32
+ /**
33
+ * v1.14.2: dynamic estimate for the rescue pass — the actual size of the last observed iteration
34
+ * (+5k margin for SYSTEM_INSTRUCTION_FINALIZATION + thinking-config overhead) instead of the static
35
+ * `PER_ITERATION_INPUT_TOKENS` baseline. Used by BOTH the daily-budget reservation AND the
36
+ * TPM-throttle reservation so cost and rate-limit gates stay symmetric (the reservation covers the
37
+ * replayed conversation). Fallback to the static estimate when the loop produced no usage record.
38
+ *
39
+ * v1.15.0 (P5): also folds in `lastToolResponseTokens` — the tool-response Parts appended to
40
+ * `conversation` AFTER the last iteration's `generateContent` returned. The rescue's prompt replays
41
+ * the entire accumulated conversation, so its actual size ≈ last-iter prompt + the tool responses
42
+ * appended after; without them a final iteration that read several large files concurrently could
43
+ * under-reserve TPM by 100k+ tokens and 429 mid-flight.
44
+ */
45
+ function finalizationEstimateOf(state) {
46
+ return state.lastIterationPromptTokens > 0
47
+ ? state.lastIterationPromptTokens + state.lastToolResponseTokens + 5_000
48
+ : PER_ITERATION_INPUT_TOKENS;
49
+ }
50
+ /** The pass's budget reservation id, or `null` — not enforced, or refused (then `outcome.skipReason`). */
51
+ function reserveRescue(run, costUsd, outcome) {
52
+ if (!run.budget.dailyBudgetEnforced)
53
+ return null;
54
+ const reserve = reservePass(run, costUsd);
55
+ if (!('rejected' in reserve))
56
+ return reserve.id;
57
+ const spent = (reserve.spentMicros / 1_000_000).toFixed(4);
58
+ run.emitter.emit(`skipping forced-finalization pass — daily budget cap reached (spent $${spent})`);
59
+ logger.warn(`ask_agentic: skipping forced-finalization pass — daily budget cap reached (spent $${spent})`);
60
+ outcome.skipReason = 'daily-budget';
61
+ return null;
62
+ }
63
+ /**
64
+ * The finalization call. G2 fix: `tools` (function declarations) are omitted — per Gemini API spec,
65
+ * `mode: NONE` is "equivalent to sending a request without any function declarations"; sending the
66
+ * declarations alongside NONE wastes ~150-300 input tokens and contradicts the spec we depend on.
67
+ */
68
+ function callFinalization(run, state, baseConfigNoTools, clock) {
69
+ const model = run.resolved.resolved;
70
+ const { signal } = clock;
71
+ return withNetworkRetry(() => {
72
+ clock.enter('finalization');
73
+ return run.ctx.client.models.generateContent({
74
+ model,
75
+ contents: state.conversation,
76
+ config: {
77
+ ...baseConfigNoTools,
78
+ systemInstruction: SYSTEM_INSTRUCTION_FINALIZATION,
79
+ toolConfig: {
80
+ functionCallingConfig: { mode: FunctionCallingConfigMode.NONE },
81
+ },
82
+ abortSignal: signal,
83
+ },
84
+ });
85
+ }, {
86
+ signal,
87
+ onRetry: (attempt, retryErr) => {
88
+ clock.enter('finalization');
89
+ logger.warn(`ask_agentic finalization: retry attempt ${attempt}: ${errorText(retryErr)}`);
90
+ },
91
+ });
92
+ }
93
+ /** Read the returned response. An empty text is a rescue failure mode (model dispatched, returned a
94
+ * candidate with no extractable text) — distinct from timeouts / 429s / network errors. */
95
+ function readFinalization(response, usage, outcome) {
96
+ outcome.usage = usage;
97
+ const parts = response.candidates?.[0]?.content?.parts ?? [];
98
+ outcome.text = (response.text ?? parts.map((p) => p.text ?? '').join('')).trim();
99
+ outcome.thinkingSummary = thinkingSummaryOf(parts);
100
+ if (outcome.text.length === 0) {
101
+ outcome.errorCode = 'EMPTY_TEXT';
102
+ }
103
+ }
104
+ /**
105
+ * Classify a rescue failure for caller-facing telemetry. Order matters — earlier branches signal the
106
+ * most user-actionable remediation:
107
+ * 1. TIMEOUT — checked first because a 429 surfaced via an aborted-fetch can race the timeout signal.
108
+ * 2. RATE_LIMIT — wait the retry-hint window then retry (429).
109
+ * 3. INTERNAL — a completed call means the await returned cleanly; any throw past that point is
110
+ * processing logic our side, not Gemini's API — investigate, do not retry blindly.
111
+ * 4. API_ERROR — Gemini returned a non-429 4xx/5xx; distinct from NETWORK so wrappers don't retry
112
+ * 400 INVALID_ARGUMENT forever.
113
+ * 5. NETWORK — fetch-layer / DNS / TCP / SDK pre-dispatch; safe to retry.
114
+ */
115
+ function rescueFailureCode(finalErr, retryDelayMs, callCompleted) {
116
+ if (isTimeoutAbort(finalErr)) {
117
+ logger.warn('ask_agentic finalization: timed out after maxIterations exhaustion');
118
+ return 'TIMEOUT';
119
+ }
120
+ if (isGemini429(finalErr)) {
121
+ logger.warn(`ask_agentic finalization: 429 rate-limit (retryDelay=${retryDelayMs ?? 'unknown'}ms)`);
122
+ return 'RATE_LIMIT';
123
+ }
124
+ if (callCompleted) {
125
+ logger.warn(`ask_agentic finalization: post-await processing failed: ${errorText(finalErr)}`);
126
+ return 'INTERNAL';
127
+ }
128
+ if (finalErr instanceof ApiError) {
129
+ logger.warn(`ask_agentic finalization: Gemini API returned ${finalErr.status ?? 'unknown'}: ${finalErr.message.slice(0, 200)}`);
130
+ return 'API_ERROR';
131
+ }
132
+ logger.warn(`ask_agentic finalization: network failure: ${errorText(finalErr)}`);
133
+ return 'NETWORK';
134
+ }
135
+ /** The rescue's generateContent can also 429 — its retry hint seeds the throttle cache for future
136
+ * ask_agentic / ask / code calls, the same way the per-iteration catch does. A timeout records what fired. */
137
+ function recordRescueFailure(run, finalErr, clock, callCompleted, outcome) {
138
+ const finalRetryDelayMs = seedRetryHint(run.ctx.throttle, run.resolved.resolved, finalErr);
139
+ outcome.errorCode = rescueFailureCode(finalErr, finalRetryDelayMs, callCompleted);
140
+ if (outcome.errorCode === 'TIMEOUT')
141
+ outcome.timeout = passTimeoutOf(clock, finalErr);
142
+ outcome.errorMessage =
143
+ finalErr instanceof Error ? finalErr.message.slice(0, 500) : String(finalErr).slice(0, 500);
144
+ }
145
+ /** Dispatch the finalization call and read its answer. The API attempt is marked before dispatch (after
146
+ * the throttle wait, so a throttle-wait abort doesn't count it). */
147
+ async function dispatchRescue(run, state, flight, clock, outcome) {
148
+ if (run.budget.tpmEnforced) {
149
+ // The dynamic estimate, the same value and margin as the daily-budget reserve: over-reserve =
150
+ // transient throttle wait (harmless); under-reserve = 429 risk; the bias is intentional.
151
+ await waitForTpm(run, flight, flight.estimate, clock.signal, (seconds) => `finalization throttle: waiting ${seconds}s for TPM window…`);
152
+ }
153
+ const { tools: _unusedTools, ...baseConfigNoTools } = run.baseConfig;
154
+ outcome.attempted = true;
155
+ const response = await callFinalization(run, state, baseConfigNoTools, clock);
156
+ const usage = completeCall(flight.call, response);
157
+ readFinalization(response, usage, outcome);
158
+ }
159
+ /** Run the pass under its own clock; close it by its call (`closePass`): booked when the call completed, both
160
+ * reservations cancelled when it did not. */
161
+ async function attemptRescue(run, state, reservationId, estimate, outcome) {
162
+ run.emitter.emit('running forced-finalization pass (tools disabled)');
163
+ const clock = createPassClock(run.knobs);
164
+ const flight = {
165
+ reservationId,
166
+ throttleReservationId: NO_THROTTLE_RESERVATION,
167
+ estimate,
168
+ startedAt: Date.now(),
169
+ call: callNotMade(),
170
+ };
171
+ try {
172
+ await dispatchRescue(run, state, flight, clock, outcome);
173
+ }
174
+ catch (finalErr) {
175
+ recordRescueFailure(run, finalErr, clock, flight.call.completed, outcome);
176
+ }
177
+ finally {
178
+ outcome.billed = closePass(run, flight, flight.call, 'ask_agentic finalization');
179
+ clock.dispose();
180
+ }
181
+ }
182
+ /** Run the forced-finalization pass after the loop exhausted `maxIterations`. */
183
+ export async function runRescue(run, state) {
184
+ run.emitter.emit(`maxIterations (${run.limits.maxIterations}) reached — running forced-finalization pass`);
185
+ const outcome = {
186
+ text: '',
187
+ usage: { promptTokenCount: 0, candidatesTokenCount: 0, thoughtsTokenCount: 0 },
188
+ thinkingSummary: null,
189
+ attempted: false,
190
+ errorCode: null,
191
+ errorMessage: null,
192
+ skipReason: null,
193
+ billed: null,
194
+ timeout: null,
195
+ };
196
+ const estimate = finalizationEstimateOf(state);
197
+ const reservationId = reserveRescue(run, passReservationUsd(run, estimate), outcome);
198
+ if (reservationId !== null || !run.budget.dailyBudgetEnforced) {
199
+ await attemptRescue(run, state, reservationId, estimate, outcome);
200
+ }
201
+ return outcome;
202
+ }
203
+ //# sourceMappingURL=rescue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rescue.js","sourceRoot":"","sources":["../../../src/tools/agentic/rescue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACL,uBAAuB,EAGvB,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAoC,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,EAAoB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAGL,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,UAAU,CAAC;AA2DlB,MAAM,SAAS,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/F;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAAC,KAAgB;IAC9C,OAAO,KAAK,CAAC,yBAAyB,GAAG,CAAC;QACxC,CAAC,CAAC,KAAK,CAAC,yBAAyB,GAAG,KAAK,CAAC,sBAAsB,GAA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AQ,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What `ask_agentic` reads from a model response, the same way for a loop iteration and for the forced-finalization
3
+ * pass: the token counts (0 where the response reported none) and the thought summary.
4
+ */
5
+ import type { GenerateContentResponse, Part } from '@google/genai';
6
+ /** The token counts of one model call. */
7
+ export interface UsageCounts {
8
+ promptTokenCount: number;
9
+ candidatesTokenCount: number;
10
+ thoughtsTokenCount: number;
11
+ }
12
+ /** A response's token counts, each 0 when its `usageMetadata` does not carry it as a number. */
13
+ export declare function usageCounts(usage: GenerateContentResponse['usageMetadata']): UsageCounts;
14
+ /** The thought parts' text joined by newlines and cut to 1200 characters, or `null` when there is none. */
15
+ export declare function thinkingSummaryOf(parts: Part[]): string | null;
16
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../src/tools/agentic/response.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEnE,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAOD,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,KAAK,EAAE,uBAAuB,CAAC,eAAe,CAAC,GAAG,WAAW,CAMxF;AAED,2GAA2G;AAC3G,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,GAAG,IAAI,CAO9D"}