@qmediat.io/gemini-code-context-mcp 1.10.0 → 1.12.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.
- package/CHANGELOG.md +51 -0
- package/dist/tools/ask-agentic.tool.js +10 -1
- package/dist/tools/ask-agentic.tool.js.map +1 -1
- package/dist/tools/ask.tool.d.ts +10 -0
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +148 -11
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.d.ts +5 -0
- package/dist/tools/code.tool.d.ts.map +1 -1
- package/dist/tools/code.tool.js +36 -6
- package/dist/tools/code.tool.js.map +1 -1
- package/dist/tools/shared/abort-timeout.d.ts +84 -31
- package/dist/tools/shared/abort-timeout.d.ts.map +1 -1
- package/dist/tools/shared/abort-timeout.js +193 -48
- package/dist/tools/shared/abort-timeout.js.map +1 -1
- package/dist/tools/shared/stream-collector.d.ts +12 -0
- package/dist/tools/shared/stream-collector.d.ts.map +1 -1
- package/dist/tools/shared/stream-collector.js +7 -0
- package/dist/tools/shared/stream-collector.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Per-call wall-clock timeout
|
|
2
|
+
* Per-call wall-clock timeout AND heartbeat-aware stall detector for tool
|
|
3
|
+
* dispatch (T19 v1.6.0 + Phase 4 v1.12.0).
|
|
3
4
|
*
|
|
4
5
|
* Why this exists:
|
|
5
6
|
*
|
|
@@ -10,86 +11,197 @@
|
|
|
10
11
|
* silent stall. The MCP host's own progress notifications keep the connection
|
|
11
12
|
* alive, but there is no upper bound on total wall-clock time.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* subscription side. Per Google's SDK comment: *"AbortSignal is a client-only
|
|
18
|
-
* operation. Using it to cancel an operation will not cancel the request in
|
|
19
|
-
* the service. You will still be charged usage for any applicable operations."*
|
|
14
|
+
* v1.6.0 introduced the wall-clock cap (`timeoutMs`). v1.12.0 adds a
|
|
15
|
+
* complementary stall watchdog (`stallMs`) that resets on every chunk
|
|
16
|
+
* (text or thought) and only fires when the stream goes silent. The two
|
|
17
|
+
* mechanisms are independent and BOTH supported simultaneously:
|
|
20
18
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* - **`timeoutMs`** (wall-clock) — cost ceiling. A stuck Gemini server-side
|
|
20
|
+
* process still bills the user until it self-terminates; a hard cap
|
|
21
|
+
* bounds the worst-case spend per call.
|
|
22
|
+
* - **`stallMs`** (heartbeat-aware) — liveness watchdog. Kills truly dead
|
|
23
|
+
* sockets ~30× faster than the wall-clock alternative. Does NOT fire while
|
|
24
|
+
* the model is actively thinking (the streaming heartbeat resets it).
|
|
25
|
+
*
|
|
26
|
+
* Both timers feed into ONE unified `signal` — whichever fires first wins.
|
|
27
|
+
* The composite abort reason carries `name === 'TimeoutError'` AND a `kind`
|
|
28
|
+
* suffix on the message ("total wall-clock" vs "stall — no chunk for Xms")
|
|
29
|
+
* so error reports can attribute the cause precisely.
|
|
30
|
+
*
|
|
31
|
+
* Resolution order (each timer independently):
|
|
32
|
+
* 1. Per-call schema parameter (e.g. `ask({ timeoutMs, stallMs })`) — wins.
|
|
33
|
+
* 2. Tool-specific env var (e.g. `GEMINI_CODE_CONTEXT_ASK_TIMEOUT_MS`,
|
|
34
|
+
* `GEMINI_CODE_CONTEXT_ASK_STALL_MS`).
|
|
24
35
|
* 3. Default disabled (`0` / `undefined` / negative).
|
|
25
36
|
*
|
|
26
|
-
* When disabled,
|
|
27
|
-
*
|
|
28
|
-
* no per-call branching on "is timeout enabled".
|
|
37
|
+
* When BOTH are disabled, the controller's signal NEVER fires — call sites
|
|
38
|
+
* pass it unconditionally and `recordChunk()` is a no-op.
|
|
29
39
|
*/
|
|
30
|
-
const ABSOLUTE_MAX_MS = 1_800_000; // 30 min — conservative ceiling
|
|
31
|
-
const ABSOLUTE_MIN_MS = 1_000; // 1 s — anything shorter is
|
|
40
|
+
const ABSOLUTE_MAX_MS = 1_800_000; // 30 min — conservative ceiling for total
|
|
41
|
+
const ABSOLUTE_MIN_MS = 1_000; // 1 s — anything shorter is a unit-conversion bug
|
|
42
|
+
const STALL_ABSOLUTE_MAX_MS = 600_000; // 10 min — a stall watchdog longer than this is just a slow total cap
|
|
43
|
+
function readEnvMs(envVarName) {
|
|
44
|
+
const raw = process.env[envVarName];
|
|
45
|
+
if (raw === undefined || raw.length === 0)
|
|
46
|
+
return 0;
|
|
47
|
+
const parsed = Number(raw);
|
|
48
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
49
|
+
}
|
|
32
50
|
/**
|
|
33
|
-
* Build a controller for a tool dispatch.
|
|
51
|
+
* Build a composite controller for a tool dispatch.
|
|
34
52
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
53
|
+
* The returned `signal` fires on EITHER (a) the wall-clock cap (`timeoutMs`)
|
|
54
|
+
* being exceeded, OR (b) the stall watchdog (`stallMs`) firing because no
|
|
55
|
+
* chunk arrived for that long. Whichever fires first wins; the abort
|
|
56
|
+
* reason's message says which kind ("total wall-clock" / "stall — no chunk
|
|
57
|
+
* for Xms"). Both reasons share `name === 'TimeoutError'` so
|
|
58
|
+
* `isTimeoutAbort` returns true uniformly.
|
|
38
59
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
60
|
+
* Bounds:
|
|
61
|
+
* - `timeoutMs` (total): `[1_000, 1_800_000]` ms (1 s to 30 min).
|
|
62
|
+
* - `stallMs`: `[1_000, 600_000]` ms (1 s to 10 min).
|
|
63
|
+
* Out-of-range positive values are clamped silently.
|
|
41
64
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* `
|
|
45
|
-
* workflow we've observed (a `code` task with HIGH thinking on a 1M-token
|
|
46
|
-
* cached workspace has finished within 4 min in measured benchmarks).
|
|
65
|
+
* Single API: only the structured-options form is supported. The previous
|
|
66
|
+
* v1.6.0–v1.11.0 2-arg signature was retired in v1.12.0 — all internal
|
|
67
|
+
* callers (`ask`, `code`, `ask_agentic`) now pass options.
|
|
47
68
|
*/
|
|
48
|
-
export function createTimeoutController(
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
export function createTimeoutController(opts) {
|
|
70
|
+
// Resolve total wall-clock cap.
|
|
71
|
+
const totalRequested = opts.totalMs !== undefined ? opts.totalMs : readEnvMs(opts.totalEnvVar);
|
|
72
|
+
const totalEffective = Number.isFinite(totalRequested) && totalRequested > 0
|
|
73
|
+
? Math.max(ABSOLUTE_MIN_MS, Math.min(ABSOLUTE_MAX_MS, Math.floor(totalRequested)))
|
|
74
|
+
: 0;
|
|
75
|
+
// Resolve stall watchdog.
|
|
76
|
+
const stallRequested = opts.stallMs !== undefined ? opts.stallMs : readEnvMs(opts.stallEnvVar);
|
|
77
|
+
const stallEffective = Number.isFinite(stallRequested) && stallRequested > 0
|
|
78
|
+
? Math.max(ABSOLUTE_MIN_MS, Math.min(STALL_ABSOLUTE_MAX_MS, Math.floor(stallRequested)))
|
|
79
|
+
: 0;
|
|
80
|
+
if (totalEffective === 0 && stallEffective === 0) {
|
|
54
81
|
return disabledController();
|
|
55
82
|
}
|
|
56
|
-
const effective = Math.max(ABSOLUTE_MIN_MS, Math.min(ABSOLUTE_MAX_MS, Math.floor(requested)));
|
|
57
83
|
const controller = new AbortController();
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
let totalTimer = null;
|
|
85
|
+
let stallTimer = null;
|
|
86
|
+
let disposed = false;
|
|
87
|
+
if (totalEffective > 0) {
|
|
88
|
+
totalTimer = setTimeout(() => {
|
|
89
|
+
const reason = new DOMException(`Timed out after ${totalEffective} ms (total wall-clock)`, 'TimeoutError');
|
|
90
|
+
// Embed the kind on the reason itself — message-string matching
|
|
91
|
+
// (the v1.12.0-pre approach) is brittle to any future copy changes.
|
|
92
|
+
Object.assign(reason, { timeoutKind: 'total' });
|
|
93
|
+
controller.abort(reason);
|
|
94
|
+
// Stall timer is now moot — clear it.
|
|
95
|
+
if (stallTimer !== null)
|
|
96
|
+
clearTimeout(stallTimer);
|
|
97
|
+
}, totalEffective);
|
|
98
|
+
totalTimer.unref?.();
|
|
99
|
+
}
|
|
100
|
+
// Stall watchdog (Phase 4, v1.12.0).
|
|
101
|
+
//
|
|
102
|
+
// The stall timer arms on the FIRST `recordChunk()` call (typically
|
|
103
|
+
// when `collectStream` begins iterating chunks). It does NOT arm on
|
|
104
|
+
// controller creation — counting the pre-stream phase (workspace scan,
|
|
105
|
+
// countTokens preflight, Files API eager upload, TLS handshake to
|
|
106
|
+
// generateContentStream) as "stall budget" is wrong: that latency is
|
|
107
|
+
// local I/O and SDK setup, not Gemini-side stall. If the user wants
|
|
108
|
+
// to bound that phase, they set `timeoutMs` (the wall-clock cost cap),
|
|
109
|
+
// which DOES include pre-stream time.
|
|
110
|
+
//
|
|
111
|
+
// After the first chunk, the timer resets on every subsequent chunk
|
|
112
|
+
// (text or thought — both prove the stream is alive). Gap > stallMs
|
|
113
|
+
// → abort with kind="stall".
|
|
114
|
+
//
|
|
115
|
+
// Edge case: if the stream opens but never yields any chunk
|
|
116
|
+
// (e.g. SDK fetch hangs after returning the response), `recordChunk`
|
|
117
|
+
// is never called, the stall watchdog never arms, and only `timeoutMs`
|
|
118
|
+
// can rescue. Documented limitation; users wanting that safety net
|
|
119
|
+
// should set both `stallMs` and `timeoutMs`.
|
|
120
|
+
const armStallTimer = () => {
|
|
121
|
+
const t = setTimeout(() => {
|
|
122
|
+
const reason = new DOMException(`Timed out after ${stallEffective} ms (stall — no chunk received)`, 'TimeoutError');
|
|
123
|
+
Object.assign(reason, { timeoutKind: 'stall' });
|
|
124
|
+
controller.abort(reason);
|
|
125
|
+
if (totalTimer !== null)
|
|
126
|
+
clearTimeout(totalTimer);
|
|
127
|
+
}, stallEffective);
|
|
128
|
+
t.unref?.();
|
|
129
|
+
return t;
|
|
130
|
+
};
|
|
131
|
+
if (stallEffective > 0) {
|
|
132
|
+
return {
|
|
133
|
+
signal: controller.signal,
|
|
134
|
+
timeoutMs: totalEffective > 0 ? totalEffective : null,
|
|
135
|
+
stallMs: stallEffective,
|
|
136
|
+
dispose: () => {
|
|
137
|
+
disposed = true;
|
|
138
|
+
if (totalTimer !== null) {
|
|
139
|
+
clearTimeout(totalTimer);
|
|
140
|
+
totalTimer = null;
|
|
141
|
+
}
|
|
142
|
+
if (stallTimer !== null) {
|
|
143
|
+
clearTimeout(stallTimer);
|
|
144
|
+
stallTimer = null;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
recordChunk: () => {
|
|
148
|
+
// Defense-in-depth: refuse to re-arm after dispose() clears
|
|
149
|
+
// timers, and don't re-arm a fired controller.
|
|
150
|
+
if (disposed || controller.signal.aborted)
|
|
151
|
+
return;
|
|
152
|
+
if (stallTimer !== null)
|
|
153
|
+
clearTimeout(stallTimer);
|
|
154
|
+
stallTimer = armStallTimer();
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// total-only path (no stall watchdog).
|
|
65
159
|
return {
|
|
66
160
|
signal: controller.signal,
|
|
67
|
-
timeoutMs:
|
|
68
|
-
|
|
161
|
+
timeoutMs: totalEffective,
|
|
162
|
+
stallMs: null,
|
|
163
|
+
dispose: () => {
|
|
164
|
+
disposed = true;
|
|
165
|
+
if (totalTimer !== null) {
|
|
166
|
+
clearTimeout(totalTimer);
|
|
167
|
+
totalTimer = null;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
recordChunk: () => {
|
|
171
|
+
/* stall disabled — no-op */
|
|
172
|
+
},
|
|
69
173
|
};
|
|
70
174
|
}
|
|
71
175
|
/**
|
|
72
176
|
* A "no-op" controller — its signal never fires.
|
|
73
177
|
*
|
|
74
|
-
* Returned when
|
|
75
|
-
* SDK and `withNetworkRetry` unconditionally without a per-call
|
|
76
|
-
* branch. The SDK accepts a never-firing signal cleanly
|
|
178
|
+
* Returned when both timers are disabled. Lets call sites pass the signal
|
|
179
|
+
* into the SDK and `withNetworkRetry` unconditionally without a per-call
|
|
180
|
+
* `if (signal)` branch. The SDK accepts a never-firing signal cleanly
|
|
181
|
+
* (no perf cost). `recordChunk()` is a no-op.
|
|
77
182
|
*/
|
|
78
183
|
function disabledController() {
|
|
79
184
|
return {
|
|
80
185
|
signal: new AbortController().signal, // never fires
|
|
81
186
|
timeoutMs: null,
|
|
187
|
+
stallMs: null,
|
|
82
188
|
dispose: () => {
|
|
83
189
|
/* nothing to dispose */
|
|
84
190
|
},
|
|
191
|
+
recordChunk: () => {
|
|
192
|
+
/* nothing to record */
|
|
193
|
+
},
|
|
85
194
|
};
|
|
86
195
|
}
|
|
87
196
|
/**
|
|
88
197
|
* Identify a timeout-driven abort vs a user-driven abort.
|
|
89
198
|
*
|
|
90
199
|
* `createTimeoutController` aborts with a `DOMException` whose `name` is
|
|
91
|
-
* `'TimeoutError'
|
|
92
|
-
* `errorCode: 'TIMEOUT'` rather
|
|
200
|
+
* `'TimeoutError'` — both for total wall-clock and for stall. Callers use
|
|
201
|
+
* this to map the error to a user-facing `errorCode: 'TIMEOUT'` rather
|
|
202
|
+
* than the generic `'ABORTED'`. The TIMEOUT-vs-stall split is captured in
|
|
203
|
+
* the abort reason's MESSAGE (and exposed via `getTimeoutKind` below) so
|
|
204
|
+
* structured-content metadata can distinguish them.
|
|
93
205
|
*
|
|
94
206
|
* Walks the full `error.cause` chain rather than just one level — the
|
|
95
207
|
* `@google/genai` SDK paths through Node `undici` can wrap errors more than
|
|
@@ -114,4 +226,37 @@ export function isTimeoutAbort(err) {
|
|
|
114
226
|
}
|
|
115
227
|
return false;
|
|
116
228
|
}
|
|
229
|
+
export function getTimeoutKind(err) {
|
|
230
|
+
let current = err;
|
|
231
|
+
const seen = new Set();
|
|
232
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH; depth += 1) {
|
|
233
|
+
if (!(current instanceof Error))
|
|
234
|
+
return null;
|
|
235
|
+
if (seen.has(current))
|
|
236
|
+
return null;
|
|
237
|
+
seen.add(current);
|
|
238
|
+
if (current.name === 'TimeoutError') {
|
|
239
|
+
// Prefer the structured `timeoutKind` property on the abort reason
|
|
240
|
+
// (set by `createTimeoutController` since v1.12.0). Property-based
|
|
241
|
+
// dispatch is robust against future message-copy changes.
|
|
242
|
+
const kind = current.timeoutKind;
|
|
243
|
+
if (kind === 'total' || kind === 'stall')
|
|
244
|
+
return kind;
|
|
245
|
+
// Fall back to message inspection ONLY for messages produced by
|
|
246
|
+
// older v1.12.0-pre code paths (or third-party TimeoutErrors that
|
|
247
|
+
// happen to use this exact wording). Anchored on the parenthetical
|
|
248
|
+
// suffix `createTimeoutController` writes — narrow enough to avoid
|
|
249
|
+
// collisions with arbitrary error text.
|
|
250
|
+
if (current.message.endsWith('(stall — no chunk received)'))
|
|
251
|
+
return 'stall';
|
|
252
|
+
if (current.message.endsWith('(total wall-clock)'))
|
|
253
|
+
return 'total';
|
|
254
|
+
// Backward compat: pre-v1.12.0 messages didn't include the suffix
|
|
255
|
+
// — treat as `'total'` (the only kind that existed then).
|
|
256
|
+
return 'total';
|
|
257
|
+
}
|
|
258
|
+
current = current.cause;
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
117
262
|
//# sourceMappingURL=abort-timeout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abort-timeout.js","sourceRoot":"","sources":["../../../src/tools/shared/abort-timeout.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"abort-timeout.js","sourceRoot":"","sources":["../../../src/tools/shared/abort-timeout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,MAAM,eAAe,GA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61
|
/** Minimum gap between `onThoughtChunk` emits. Default 1500ms — short
|
|
62
62
|
* enough to feel live, long enough to avoid flooding MCP host throttles. */
|
|
63
63
|
readonly thoughtEmitThrottleMs?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Called on EVERY chunk arrival (Phase 4, v1.12.0). Used to reset the
|
|
66
|
+
* heartbeat-aware stall watchdog. Both text-bearing and thought-only
|
|
67
|
+
* chunks reset the timer — both prove the stream is alive. No-op when
|
|
68
|
+
* caller didn't supply one.
|
|
69
|
+
*
|
|
70
|
+
* Wire this from `createTimeoutController(...).recordChunk`. The
|
|
71
|
+
* controller's `recordChunk` is also a safe no-op when stall is
|
|
72
|
+
* disabled, so callers can pass the controller's `recordChunk`
|
|
73
|
+
* unconditionally.
|
|
74
|
+
*/
|
|
75
|
+
readonly onChunkReceived?: () => void;
|
|
64
76
|
}
|
|
65
77
|
export interface CollectedResponse {
|
|
66
78
|
/** Concatenated text from all chunks. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-collector.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/stream-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAK7D,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;
|
|
1
|
+
{"version":3,"file":"stream-collector.d.ts","sourceRoot":"","sources":["../../../src/tools/shared/stream-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAK7D,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;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,cAAc,CAAC,uBAAuB,CAAC,EAC/C,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,iBAAiB,CAAC,CAqJ5B"}
|
|
@@ -62,6 +62,7 @@ const THOUGHTS_SUMMARY_MAX_CHARS = 1200;
|
|
|
62
62
|
export async function collectStream(stream, opts = {}) {
|
|
63
63
|
const signal = opts.signal;
|
|
64
64
|
const onThoughtChunk = opts.onThoughtChunk;
|
|
65
|
+
const onChunkReceived = opts.onChunkReceived;
|
|
65
66
|
const throttleMs = opts.thoughtEmitThrottleMs ?? DEFAULT_THOUGHT_EMIT_THROTTLE_MS;
|
|
66
67
|
// Pre-flight: never start consuming if abort already fired. Saves the cost
|
|
67
68
|
// of touching the generator at all.
|
|
@@ -103,6 +104,12 @@ export async function collectStream(stream, opts = {}) {
|
|
|
103
104
|
if (firstChunkAt === null)
|
|
104
105
|
firstChunkAt = now;
|
|
105
106
|
lastChunkAt = now;
|
|
107
|
+
// Reset the heartbeat-aware stall watchdog (Phase 4, v1.12.0).
|
|
108
|
+
// Both text-bearing and thought-only chunks reset — both prove the
|
|
109
|
+
// stream is alive. Called BEFORE the abort check below would
|
|
110
|
+
// re-fire to cover the (rare) race where stall fires AFTER the
|
|
111
|
+
// SDK yielded this chunk but BEFORE we processed it.
|
|
112
|
+
onChunkReceived?.();
|
|
106
113
|
// Text concat. `chunk.text` is a getter on GenerateContentResponse
|
|
107
114
|
// that joins parts.text from the first candidate; safe to read even
|
|
108
115
|
// when the chunk only carries thoughts (returns empty string then).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-collector.js","sourceRoot":"","sources":["../../../src/tools/shared/stream-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAIH,MAAM,gCAAgC,GAAG,IAAI,CAAC;AAC9C,MAAM,0BAA0B,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"stream-collector.js","sourceRoot":"","sources":["../../../src/tools/shared/stream-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAIH,MAAM,gCAAgC,GAAG,IAAI,CAAC;AAC9C,MAAM,0BAA0B,GAAG,IAAI,CAAC;AA2CxC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,C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CAAC;YAAS,CAAC;QACT,uEAAuE;QACvE,oEAAoE;QACpE,sEAAsE;QACtE,qEAAqE;QACrE,kEAAkE;QAClE,uBAAuB;QACvB,IAAI,YAAY,EAAE,CAAC;YACjB,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,eAAe,GACnB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAElG,OAAO;QACL,IAAI;QACJ,UAAU,EAAE,cAAc;QAC1B,aAAa,EAAE,iBAAiB;QAChC,eAAe;QACf,UAAU;QACV,YAAY;QACZ,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qmediat.io/gemini-code-context-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"mcpName": "io.github.qmediat/gemini-code-context-mcp",
|
|
5
5
|
"description": "MCP server that gives Claude Code persistent memory of your codebase, backed by Gemini's 2M-token context. Includes eager `ask`/`code` for cached repo Q&A and `ask_agentic` for agentic file access on repos that exceed the model's input-token limit.",
|
|
6
6
|
"keywords": [
|