@qmediat.io/gemini-code-context-mcp 1.23.0 → 1.24.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 +94 -1
- package/README.md +36 -227
- package/dist/auth/profile-loader.js +1 -1
- package/dist/auth/profile-loader.js.map +1 -1
- package/dist/cache/ttl-watcher.d.ts +29 -0
- package/dist/cache/ttl-watcher.d.ts.map +1 -1
- package/dist/cache/ttl-watcher.js +104 -43
- package/dist/cache/ttl-watcher.js.map +1 -1
- package/dist/gemini/client.d.ts +7 -0
- package/dist/gemini/client.d.ts.map +1 -1
- package/dist/gemini/client.js +8 -1
- package/dist/gemini/client.js.map +1 -1
- package/dist/gemini/long-decode.d.ts +153 -0
- package/dist/gemini/long-decode.d.ts.map +1 -0
- package/dist/gemini/long-decode.js +178 -0
- package/dist/gemini/long-decode.js.map +1 -0
- package/dist/gemini/model-registry.d.ts +2 -0
- package/dist/gemini/model-registry.d.ts.map +1 -1
- package/dist/gemini/model-registry.js +5 -2
- package/dist/gemini/model-registry.js.map +1 -1
- package/dist/gemini/models.d.ts.map +1 -1
- package/dist/gemini/models.js +1 -0
- package/dist/gemini/models.js.map +1 -1
- package/dist/gemini/retry.d.ts +8 -0
- package/dist/gemini/retry.d.ts.map +1 -1
- package/dist/gemini/retry.js +33 -1
- package/dist/gemini/retry.js.map +1 -1
- package/dist/tools/ask-agentic.tool.d.ts.map +1 -1
- package/dist/tools/ask-agentic.tool.js +10 -12
- package/dist/tools/ask-agentic.tool.js.map +1 -1
- package/dist/tools/ask.tool.d.ts.map +1 -1
- package/dist/tools/ask.tool.js +168 -379
- package/dist/tools/ask.tool.js.map +1 -1
- package/dist/tools/code.tool.d.ts +6 -0
- package/dist/tools/code.tool.d.ts.map +1 -1
- package/dist/tools/code.tool.js +146 -286
- package/dist/tools/code.tool.js.map +1 -1
- package/dist/tools/shared/abort-timeout.d.ts +6 -0
- package/dist/tools/shared/abort-timeout.d.ts.map +1 -1
- package/dist/tools/shared/abort-timeout.js +12 -0
- package/dist/tools/shared/abort-timeout.js.map +1 -1
- package/dist/tools/shared/call-ledger.d.ts +73 -0
- package/dist/tools/shared/call-ledger.d.ts.map +1 -0
- package/dist/tools/shared/call-ledger.js +115 -0
- package/dist/tools/shared/call-ledger.js.map +1 -0
- package/dist/tools/shared/context-decode.d.ts +77 -0
- package/dist/tools/shared/context-decode.d.ts.map +1 -0
- package/dist/tools/shared/context-decode.js +125 -0
- package/dist/tools/shared/context-decode.js.map +1 -0
- package/dist/tools/shared/continuation.d.ts +124 -0
- package/dist/tools/shared/continuation.d.ts.map +1 -0
- package/dist/tools/shared/continuation.js +302 -0
- package/dist/tools/shared/continuation.js.map +1 -0
- package/dist/tools/shared/dispatch-throttle.d.ts +43 -0
- package/dist/tools/shared/dispatch-throttle.d.ts.map +1 -0
- package/dist/tools/shared/dispatch-throttle.js +65 -0
- package/dist/tools/shared/dispatch-throttle.js.map +1 -0
- package/dist/tools/shared/settle-call.d.ts +63 -0
- package/dist/tools/shared/settle-call.d.ts.map +1 -0
- package/dist/tools/shared/settle-call.js +55 -0
- package/dist/tools/shared/settle-call.js.map +1 -0
- package/dist/tools/shared/stream-collector.d.ts +7 -0
- package/dist/tools/shared/stream-collector.d.ts.map +1 -1
- package/dist/tools/shared/stream-collector.js +5 -1
- package/dist/tools/shared/stream-collector.js.map +1 -1
- package/dist/tools/shared/thinking.d.ts +41 -11
- package/dist/tools/shared/thinking.d.ts.map +1 -1
- package/dist/tools/shared/thinking.js +62 -9
- package/dist/tools/shared/thinking.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cost-estimator.d.ts +17 -0
- package/dist/utils/cost-estimator.d.ts.map +1 -1
- package/dist/utils/cost-estimator.js +15 -2
- package/dist/utils/cost-estimator.js.map +1 -1
- package/package.json +5 -3
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* with a new `ttl` value. We only refresh caches that were used in the last
|
|
6
6
|
* 10 minutes — cold workspaces are allowed to expire.
|
|
7
7
|
*/
|
|
8
|
+
import { abortable, throwIfAborted } from '../gemini/retry.js';
|
|
8
9
|
import { logger, safeForLog } from '../utils/logger.js';
|
|
9
10
|
const TICK_MS = 5 * 60 * 1000; // 5 minutes
|
|
10
11
|
const HOT_WINDOW_MS = 10 * 60 * 1000; // used in last 10 minutes
|
|
@@ -21,6 +22,8 @@ export class TtlWatcher {
|
|
|
21
22
|
timer = null;
|
|
22
23
|
/** Re-entrancy guard: a slow `caches.update` round-trip must not overlap the next tick. */
|
|
23
24
|
tickInProgress = false;
|
|
25
|
+
/** The refresh running for each cache name: the tick and every keep-alive of that cache join it. */
|
|
26
|
+
refreshing = new Map();
|
|
24
27
|
constructor(client, manifest) {
|
|
25
28
|
this.client = client;
|
|
26
29
|
this.manifest = manifest;
|
|
@@ -42,12 +45,29 @@ export class TtlWatcher {
|
|
|
42
45
|
this.hot.clear();
|
|
43
46
|
}
|
|
44
47
|
markHot(workspaceRoot, cacheId, ttlSeconds) {
|
|
45
|
-
this.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
this.hotEntry(workspaceRoot, cacheId, ttlSeconds);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A request is about to be sent on the cache: mark it hot and, when it expires within the refresh window
|
|
52
|
+
* (15 minutes), extend it now instead of at the next tick — so a decode of many requests, each opened through here,
|
|
53
|
+
* never sends one on a cache that expires before the request ends (a request of a decode lasts minutes). The
|
|
54
|
+
* keep-alive is best-effort: a failed refresh, or a manifest that cannot be read or written, is logged and leaves
|
|
55
|
+
* the request to meet the cache as it is.
|
|
56
|
+
*
|
|
57
|
+
* `signal` is the calling request's: an aborted signal starts no refresh, and the wait ends with its abort reason the
|
|
58
|
+
* moment it fires — the only rejection of this method, so a slow or hanging refresh never holds a call past its
|
|
59
|
+
* timeout. The refresh itself carries no caller's signal: it is shared by every keep-alive of the cache and by the
|
|
60
|
+
* tick, so it runs to its end for the others when the call that started it leaves.
|
|
61
|
+
*/
|
|
62
|
+
async keepAlive(workspaceRoot, cacheId, ttlSeconds, signal) {
|
|
63
|
+
throwIfAborted(signal);
|
|
64
|
+
const entry = this.hotEntry(workspaceRoot, cacheId, ttlSeconds);
|
|
65
|
+
await abortable(this.refresh(entry, Date.now()), signal);
|
|
66
|
+
}
|
|
67
|
+
hotEntry(workspaceRoot, cacheId, ttlSeconds) {
|
|
68
|
+
const entry = { workspaceRoot, cacheId, lastUsed: Date.now(), ttlSeconds };
|
|
69
|
+
this.hot.set(workspaceRoot, entry);
|
|
70
|
+
return entry;
|
|
51
71
|
}
|
|
52
72
|
async tick() {
|
|
53
73
|
// Prevent overlap: if the previous tick is still running (slow Gemini
|
|
@@ -60,51 +80,92 @@ export class TtlWatcher {
|
|
|
60
80
|
this.tickInProgress = true;
|
|
61
81
|
try {
|
|
62
82
|
const now = Date.now();
|
|
63
|
-
for (const
|
|
83
|
+
for (const entry of [...this.hot.values()]) {
|
|
64
84
|
if (now - entry.lastUsed > HOT_WINDOW_MS) {
|
|
65
|
-
this.hot.delete(
|
|
85
|
+
this.hot.delete(entry.workspaceRoot);
|
|
66
86
|
continue;
|
|
67
87
|
}
|
|
68
|
-
|
|
69
|
-
if (!ws?.cacheId || ws.cacheId !== entry.cacheId) {
|
|
70
|
-
this.hot.delete(key);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (ws.cacheExpiresAt !== null && ws.cacheExpiresAt - now > REFRESH_IF_EXPIRES_WITHIN_MS) {
|
|
74
|
-
continue; // plenty of time left
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
await this.client.caches.update({
|
|
78
|
-
name: entry.cacheId,
|
|
79
|
-
config: { ttl: `${entry.ttlSeconds}s` },
|
|
80
|
-
});
|
|
81
|
-
const newExpires = now + entry.ttlSeconds * 1000;
|
|
82
|
-
this.manifest.upsertWorkspace({ ...ws, cacheExpiresAt: newExpires, updatedAt: now });
|
|
83
|
-
logger.debug(`refreshed TTL for ${safeForLog(entry.cacheId)}`);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
// Evict the entry when Gemini reports the cache is gone (deleted
|
|
87
|
-
// externally, admin quota action, etc). Without this, we'd retry
|
|
88
|
-
// the update every TICK_MS forever and log-spam the 404.
|
|
89
|
-
if (isNotFoundError(err)) {
|
|
90
|
-
logger.debug(`ttl refresh for ${entry.cacheId} returned not-found; dropping hot entry and nulling manifest cacheId`);
|
|
91
|
-
this.hot.delete(key);
|
|
92
|
-
this.manifest.upsertWorkspace({
|
|
93
|
-
...ws,
|
|
94
|
-
cacheId: null,
|
|
95
|
-
cacheExpiresAt: null,
|
|
96
|
-
updatedAt: now,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
logger.debug(`ttl refresh failed for ${safeForLog(entry.cacheId)}: ${safeForLog(err)}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
88
|
+
await this.refresh(entry, now);
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
91
|
finally {
|
|
106
92
|
this.tickInProgress = false;
|
|
107
93
|
}
|
|
108
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The one refresh of the entry's cache: the running one when there is one, else a new one. It never rejects — a
|
|
97
|
+
* failure of the refresh or of the manifest is logged here, for the tick and the keep-alive alike.
|
|
98
|
+
*/
|
|
99
|
+
refresh(entry, now) {
|
|
100
|
+
const running = this.refreshing.get(entry.cacheId);
|
|
101
|
+
if (running !== undefined)
|
|
102
|
+
return running;
|
|
103
|
+
const started = this.refreshIfDue(entry, now)
|
|
104
|
+
.catch((err) => {
|
|
105
|
+
logger.warn(`ttl refresh failed for ${safeForLog(entry.cacheId)}: ${safeForLog(err)}`);
|
|
106
|
+
})
|
|
107
|
+
.finally(() => this.refreshing.delete(entry.cacheId));
|
|
108
|
+
this.refreshing.set(entry.cacheId, started);
|
|
109
|
+
return started;
|
|
110
|
+
}
|
|
111
|
+
/** Extends the entry's cache when it expires within the refresh window; drops an entry whose cache is gone. */
|
|
112
|
+
async refreshIfDue(entry, now) {
|
|
113
|
+
const ws = this.manifest.getWorkspace(entry.workspaceRoot);
|
|
114
|
+
if (!ws?.cacheId || ws.cacheId !== entry.cacheId) {
|
|
115
|
+
this.hot.delete(entry.workspaceRoot);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (ws.cacheExpiresAt !== null && ws.cacheExpiresAt - now > REFRESH_IF_EXPIRES_WITHIN_MS) {
|
|
119
|
+
return; // plenty of time left
|
|
120
|
+
}
|
|
121
|
+
let answered;
|
|
122
|
+
try {
|
|
123
|
+
answered = await this.client.caches.update({
|
|
124
|
+
name: entry.cacheId,
|
|
125
|
+
config: { ttl: `${entry.ttlSeconds}s` },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
this.updateFailed(entry, err);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.storeExpiry(entry, expiryOf(answered, entry.ttlSeconds));
|
|
133
|
+
logger.debug(`refreshed TTL for ${safeForLog(entry.cacheId)}`);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The expiry the API answered goes to the manifest row as it is NOW — read again after the round-trip, so a row
|
|
137
|
+
* rewritten meanwhile keeps its other fields, and a row that moved to another cache is left alone.
|
|
138
|
+
*/
|
|
139
|
+
storeExpiry(entry, expiresAt) {
|
|
140
|
+
const current = this.manifest.getWorkspace(entry.workspaceRoot);
|
|
141
|
+
if (current?.cacheId !== entry.cacheId)
|
|
142
|
+
return;
|
|
143
|
+
this.manifest.upsertWorkspace({ ...current, cacheExpiresAt: expiresAt, updatedAt: Date.now() });
|
|
144
|
+
}
|
|
145
|
+
updateFailed(entry, err) {
|
|
146
|
+
// Evict the entry when Gemini reports the cache is gone (deleted
|
|
147
|
+
// externally, admin quota action, etc). Without this, we'd retry
|
|
148
|
+
// the update every TICK_MS forever and log-spam the 404.
|
|
149
|
+
if (!isNotFoundError(err)) {
|
|
150
|
+
logger.debug(`ttl refresh failed for ${safeForLog(entry.cacheId)}: ${safeForLog(err)}`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
logger.debug(`ttl refresh for ${entry.cacheId} returned not-found; dropping hot entry and nulling manifest cacheId`);
|
|
154
|
+
this.hot.delete(entry.workspaceRoot);
|
|
155
|
+
const current = this.manifest.getWorkspace(entry.workspaceRoot);
|
|
156
|
+
if (current?.cacheId !== entry.cacheId)
|
|
157
|
+
return;
|
|
158
|
+
this.manifest.upsertWorkspace({
|
|
159
|
+
...current,
|
|
160
|
+
cacheId: null,
|
|
161
|
+
cacheExpiresAt: null,
|
|
162
|
+
updatedAt: Date.now(),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** The expiry `caches.update` answered; the requested TTL from now when the answer carries none. */
|
|
167
|
+
function expiryOf(answered, ttlSeconds) {
|
|
168
|
+
const parsed = answered.expireTime === undefined ? Number.NaN : Date.parse(answered.expireTime);
|
|
169
|
+
return Number.isFinite(parsed) ? parsed : Date.now() + ttlSeconds * 1000;
|
|
109
170
|
}
|
|
110
171
|
//# sourceMappingURL=ttl-watcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ttl-watcher.js","sourceRoot":"","sources":["../../src/cache/ttl-watcher.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"ttl-watcher.js","sourceRoot":"","sources":["../../src/cache/ttl-watcher.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAC3C,MAAM,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,KAAK,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACxF,OAAO;QACT,CAAC;QACD,MAAM,CAAC,KAAK,CACV,mBAAmB,KAAK,CAAC,OAAO,sEAAsE,CACvG,CAAC;QACF,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAChE,IAAI,OAAO,EAAE,OAAO,KAAK,KAAK,CAAC,OAAO;YAAE,OAAO;QAC/C,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;YAC5B,GAAG,OAAO;YACV,OAAO,EAAE,IAAI;YACb,cAAc,EAAE,IAAI;YACpB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;CACF;AAED,oGAAoG;AACpG,SAAS,QAAQ,CAAC,QAAuB,EAAE,UAAkB;IAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAChG,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,GAAG,IAAI,CAAC;AAC3E,CAAC"}
|
package/dist/gemini/client.d.ts
CHANGED
|
@@ -3,5 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { GoogleGenAI } from '@google/genai';
|
|
5
5
|
import type { AuthProfile } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The Gemini Developer API version every request of an API-key client goes to. `@google/genai` defaults to the
|
|
8
|
+
* stable `v1`, which has no `cachedContents` resource (an explicit Context Cache answers 404 there); `v1beta`
|
|
9
|
+
* serves every surface this server calls — the Files API, `cachedContents`, `models`, `countTokens`,
|
|
10
|
+
* `generateContent` and its stream. Set in the constructor, it also wins over `GOOGLE_GENAI_API_VERSION`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const GEMINI_API_VERSION = "v1beta";
|
|
6
13
|
export declare function createGeminiClient(profile: AuthProfile): GoogleGenAI;
|
|
7
14
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/gemini/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/gemini/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAc/C;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,CAapE"}
|
package/dist/gemini/client.js
CHANGED
|
@@ -13,10 +13,17 @@ import { GoogleGenAI } from '@google/genai';
|
|
|
13
13
|
// handled at the tool layer by `isGemini429` + `parseRetryDelayMs` (see
|
|
14
14
|
// `src/tools/shared/throttle.ts`). Pre-response network failures are handled
|
|
15
15
|
// by `withNetworkRetry` in `src/gemini/retry.ts`.
|
|
16
|
+
/**
|
|
17
|
+
* The Gemini Developer API version every request of an API-key client goes to. `@google/genai` defaults to the
|
|
18
|
+
* stable `v1`, which has no `cachedContents` resource (an explicit Context Cache answers 404 there); `v1beta`
|
|
19
|
+
* serves every surface this server calls — the Files API, `cachedContents`, `models`, `countTokens`,
|
|
20
|
+
* `generateContent` and its stream. Set in the constructor, it also wins over `GOOGLE_GENAI_API_VERSION`.
|
|
21
|
+
*/
|
|
22
|
+
export const GEMINI_API_VERSION = 'v1beta';
|
|
16
23
|
export function createGeminiClient(profile) {
|
|
17
24
|
switch (profile.kind) {
|
|
18
25
|
case 'api-key':
|
|
19
|
-
return new GoogleGenAI({ apiKey: profile.apiKey });
|
|
26
|
+
return new GoogleGenAI({ apiKey: profile.apiKey, apiVersion: GEMINI_API_VERSION });
|
|
20
27
|
case 'vertex':
|
|
21
28
|
// Vertex path implicitly uses ADC (gcloud application-default credentials).
|
|
22
29
|
// Set GEMINI_USE_VERTEX=true + GOOGLE_CLOUD_PROJECT to route through here.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/gemini/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,0EAA0E;AAC1E,wEAAwE;AACxE,6EAA6E;AAC7E,kDAAkD;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/gemini/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,0EAA0E;AAC1E,wEAAwE;AACxE,6EAA6E;AAC7E,kDAAkD;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE3C,MAAM,UAAU,kBAAkB,CAAC,OAAoB;IACrD,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,SAAS;YACZ,OAAO,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC,CAAC;QACrF,KAAK,QAAQ;YACX,4EAA4E;YAC5E,2EAA2E;YAC3E,OAAO,IAAI,WAAW,CAAC;gBACrB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC3B,CAAC,CAAC;IACP,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long decode — the facts of Gemini 4's continuation protocol and the output cap a call runs under.
|
|
3
|
+
*
|
|
4
|
+
* Google's reference (docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini): on a Gemini 4
|
|
5
|
+
* model a response that reaches the per-request decode limit stops with `finishReason: CONTINUATION` and a
|
|
6
|
+
* `continuationToken`; the ORIGINAL request sent again with `continuationToken` set to the latest token continues
|
|
7
|
+
* it, up to 1 048 576 decoded tokens in total. Thinking tokens count against the decode, and every request bills
|
|
8
|
+
* its whole input again: the prompt plus everything decoded before it.
|
|
9
|
+
*/
|
|
10
|
+
import type { PreflightInput } from './token-counter.js';
|
|
11
|
+
/** The most a Gemini 4 decode can produce over all its requests. */
|
|
12
|
+
export declare const LONG_DECODE_TOTAL_TOKENS = 1048576;
|
|
13
|
+
/** The most one streaming request decodes before it stops with `CONTINUATION` (a non-streaming one: 32 768). */
|
|
14
|
+
export declare const LONG_DECODE_STREAM_REQUEST_TOKENS = 65536;
|
|
15
|
+
/** The API a client was built for: the Gemini Developer API (an API key) or Vertex AI. */
|
|
16
|
+
export type ApiBackend = 'developer' | 'vertex';
|
|
17
|
+
/**
|
|
18
|
+
* The total a decode of `modelId` may reach through continuation, or `null` for a model without long decode. Long
|
|
19
|
+
* decode runs on the Gemini Developer API only: on Vertex AI every model is clamped to its per-request limit,
|
|
20
|
+
* whatever the shape of its id. The model registry carries it beside the advertised input and output limits.
|
|
21
|
+
*/
|
|
22
|
+
export declare function longDecodeTokenLimitOf(modelId: string, backend: ApiBackend): number | null;
|
|
23
|
+
/**
|
|
24
|
+
* Input a continuation request bills beyond the prompt and the tokens decoded before it. Measured on
|
|
25
|
+
* gemini-4-hydrogen in two runs: +125 tokens (99 712-token prompt, request 2 billed 165 373) and +89; reserved at
|
|
26
|
+
* twice the larger, rounded up.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CONTINUATION_REQUEST_OVERHEAD_TOKENS = 256;
|
|
29
|
+
/** The output cap of one call: what goes on the wire and how many requests the decode may take. */
|
|
30
|
+
export interface OutputCap {
|
|
31
|
+
/**
|
|
32
|
+
* `maxOutputTokens` on the wire; `undefined` sends none and the model applies its own default. A cap the input window
|
|
33
|
+
* cut to one request sends the cut value (`boundByInputWindow`).
|
|
34
|
+
*/
|
|
35
|
+
readonly wire: number | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The most the call decodes: the wire cap, else the model's per-request limit (its default) — less when the
|
|
38
|
+
* model's input window bounds a long decode (`boundByInputWindow`).
|
|
39
|
+
*/
|
|
40
|
+
readonly effective: number;
|
|
41
|
+
/** The model's advertised per-request output limit. */
|
|
42
|
+
readonly perRequest: number;
|
|
43
|
+
/**
|
|
44
|
+
* The most a caller may ask for: the long-decode total on a model with long decode, else `perRequest`; for a prompt
|
|
45
|
+
* the input window bounds, what that window leaves.
|
|
46
|
+
*/
|
|
47
|
+
readonly ceiling: number;
|
|
48
|
+
/** The requests the decode may take: 1 unless the cap is above the per-request limit on a long-decode model. */
|
|
49
|
+
readonly maxRequests: number;
|
|
50
|
+
}
|
|
51
|
+
export interface OutputCapInputs {
|
|
52
|
+
/** The caller's `maxOutputTokens`, if any. */
|
|
53
|
+
readonly requested: number | undefined;
|
|
54
|
+
/** `GEMINI_CODE_CONTEXT_FORCE_MAX_OUTPUT`: send the per-request limit when the caller sets no cap. */
|
|
55
|
+
readonly forceMax: boolean;
|
|
56
|
+
readonly outputTokenLimit: number | null;
|
|
57
|
+
/** `ResolvedModel.longDecodeTokenLimit`; `undefined` reads as none. */
|
|
58
|
+
readonly longDecodeTokenLimit: number | null | undefined;
|
|
59
|
+
/** The per-request limit assumed when the model advertises none. */
|
|
60
|
+
readonly fallbackLimit: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The caller's cap is clamped to the model's per-request limit, or — on a model with long decode — to its long
|
|
64
|
+
* decode total. Without a caller's cap nothing goes on the wire (one request, the model's default), unless the
|
|
65
|
+
* operator forces the per-request limit.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveOutputCap(inputs: OutputCapInputs): OutputCap;
|
|
68
|
+
/** A long decode's cap cut so that no continuation request's input passes the model's input window. */
|
|
69
|
+
export interface InputWindowCut {
|
|
70
|
+
/** The cap before the cut: the caller's, clamped to the model's limits. */
|
|
71
|
+
readonly from: number;
|
|
72
|
+
/** The cap the decode runs under. */
|
|
73
|
+
readonly to: number;
|
|
74
|
+
/** The model's input window that cut it. */
|
|
75
|
+
readonly inputTokenLimit: number;
|
|
76
|
+
}
|
|
77
|
+
/** The cap a decode runs under, and the cut the input window made to it (`null`: none). */
|
|
78
|
+
export interface BoundedOutputCap {
|
|
79
|
+
readonly cap: OutputCap;
|
|
80
|
+
readonly cut: InputWindowCut | null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The cap of a long decode bounded by the model's input window W. Request k sends the prompt P again plus every token
|
|
84
|
+
* decoded before it, and the client opens no further request once the decoded tokens reached the cap: under a cap of
|
|
85
|
+
* at most W − P − O no request's input passes W. The premise — the API refuses a continuation request whose prompt
|
|
86
|
+
* plus decoded tokens pass W — is assumed, not measured: the repository holds a measurement of what a continuation
|
|
87
|
+
* request bills, none of a refusal at the window (docs/FOLLOW-UP-PRS.md T41).
|
|
88
|
+
*
|
|
89
|
+
* The cap is never cut below one request's limit — the first request sends the prompt alone, which the preflight
|
|
90
|
+
* bounds. A cut that leaves several requests keeps the caller's `wire`: the client stops the decode at `effective`,
|
|
91
|
+
* after `maxRequests`. A cut that leaves one request sends the cut value as `maxOutputTokens`, so the server holds it
|
|
92
|
+
* (a stop at it is `MAX_TOKENS`) — one streaming request would otherwise decode past it. Without a counted prompt or
|
|
93
|
+
* an advertised window nothing is cut.
|
|
94
|
+
*/
|
|
95
|
+
export declare function boundByInputWindow(cap: OutputCap, promptTokens: number | undefined, inputTokenLimit: number | null): BoundedOutputCap;
|
|
96
|
+
/** The progress and log line of a cut cap. */
|
|
97
|
+
export declare function describeInputWindowCut(cut: InputWindowCut): string;
|
|
98
|
+
/** What `capThatRuns` bounds: the cap a tool resolved, the prompt's count and the model's input window. */
|
|
99
|
+
export interface CapToBound {
|
|
100
|
+
/** The tool's name, which prefixes the note of a cut. */
|
|
101
|
+
readonly tool: string;
|
|
102
|
+
readonly cap: OutputCap;
|
|
103
|
+
/** The preflight's count of the prompt, when it ran. */
|
|
104
|
+
readonly promptTokens: number | undefined;
|
|
105
|
+
readonly inputTokenLimit: number | null;
|
|
106
|
+
/** The call's progress channel. */
|
|
107
|
+
readonly emit: (message: string) => void;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The cap a call's decode runs under: a long decode never sends a continuation request past the model's input
|
|
111
|
+
* window (`boundByInputWindow`). A cut is said on the call's progress channel and in the log.
|
|
112
|
+
*/
|
|
113
|
+
export declare function capThatRuns(call: CapToBound): BoundedOutputCap;
|
|
114
|
+
/** The answer the output cap keeps beside a thinking budget: Gemini requires `thinkingBudget < maxOutputTokens`. */
|
|
115
|
+
export declare const ANSWER_RESERVE_TOKENS = 1024;
|
|
116
|
+
/**
|
|
117
|
+
* The refusal of a caller's positive `thinkingBudget` that leaves less than the answer reserve under the caller's own
|
|
118
|
+
* `maxOutputTokens` (`cap`: what that cap became under the model's limits) — refused, never clamped to 0, which
|
|
119
|
+
* Gemini 3 Pro answers with a 400 that hides the cause. `null` when it fits, or the caller set either one not.
|
|
120
|
+
*/
|
|
121
|
+
export declare function thinkingBudgetRefusal(budget: number | undefined, requestedCap: number | undefined, cap: number): string | null;
|
|
122
|
+
/** The preflight's count modes (`preflightMode` of `ask` and `code`). */
|
|
123
|
+
export type PreflightMode = NonNullable<PreflightInput['preflightMode']>;
|
|
124
|
+
/**
|
|
125
|
+
* The count mode the preflight runs in. A decode that may take more than one request bills its prompt once per
|
|
126
|
+
* request, so the budget reservation takes the exact count (`countTokens`) whatever mode was asked for; a
|
|
127
|
+
* one-request call keeps the caller's mode.
|
|
128
|
+
*/
|
|
129
|
+
export declare function preflightModeFor(requested: PreflightMode | undefined, cap: OutputCap): PreflightMode | undefined;
|
|
130
|
+
/** The requests a decode of `cap` tokens may take when each request decodes up to `perRequest` tokens. */
|
|
131
|
+
export declare function maxDecodeRequests(cap: number, perRequest: number): number;
|
|
132
|
+
/**
|
|
133
|
+
* The input tokens the continuation requests bill again, at most, for a prompt of `promptTokens` tokens:
|
|
134
|
+
*
|
|
135
|
+
* R = ceil(C / L) requests (the client stops there; L = the per-request limit)
|
|
136
|
+
* M = max(L, 65 536) the most one streaming request decodes
|
|
137
|
+
* O = CONTINUATION_REQUEST_OVERHEAD_TOKENS what a continuation request bills beyond the two terms below
|
|
138
|
+
* re-billed input = Σ_{k=1..R−1} (P + min(k·M, C) + O)
|
|
139
|
+
*
|
|
140
|
+
* Request k sends the prompt P again plus the tokens decoded before it, which are at most k·M and below the cap C
|
|
141
|
+
* (the client opens no request once the decoded tokens reached C). The first request's prompt is not part of this
|
|
142
|
+
* sum.
|
|
143
|
+
*/
|
|
144
|
+
export declare function continuationInputTokens(promptTokens: number, cap: number, perRequest: number): number;
|
|
145
|
+
/**
|
|
146
|
+
* The most a decode of cap C produces (thinking and answer). One request honours `maxOutputTokens` = C. Over several
|
|
147
|
+
* requests C stays the bound only while Google holds `maxOutputTokens` over the whole chain, which the client cannot
|
|
148
|
+
* check: it stops after a request ends, once the decoded tokens reached C, so a server that holds the cap per
|
|
149
|
+
* request lets the last request run up to one request's decode past it — at most C + M − 1, and never more than
|
|
150
|
+
* R requests of M.
|
|
151
|
+
*/
|
|
152
|
+
export declare function decodedTokensBound(cap: number, perRequest: number): number;
|
|
153
|
+
//# sourceMappingURL=long-decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"long-decode.d.ts","sourceRoot":"","sources":["../../src/gemini/long-decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,oEAAoE;AACpE,eAAO,MAAM,wBAAwB,UAAY,CAAC;AAElD,gHAAgH;AAChH,eAAO,MAAM,iCAAiC,QAAS,CAAC;AAKxD,0FAA0F;AAC1F,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAG1F;AAED;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,MAAM,CAAC;AAExD,mGAAmG;AACnG,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gHAAgH;IAChH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,MAA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GG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAO9D;AAED,oHAAoH;AACpH,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,IAAI,CAKf;AAED,yEAAyE;AACzE,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;AAEzE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,aAAa,GAAG,SAAS,EACpC,GAAG,EAAE,SAAS,GACb,aAAa,GAAG,SAAS,CAE3B;AAED,0GAA0G;AAC1G,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAGzE;AAOD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK1E"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long decode — the facts of Gemini 4's continuation protocol and the output cap a call runs under.
|
|
3
|
+
*
|
|
4
|
+
* Google's reference (docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini): on a Gemini 4
|
|
5
|
+
* model a response that reaches the per-request decode limit stops with `finishReason: CONTINUATION` and a
|
|
6
|
+
* `continuationToken`; the ORIGINAL request sent again with `continuationToken` set to the latest token continues
|
|
7
|
+
* it, up to 1 048 576 decoded tokens in total. Thinking tokens count against the decode, and every request bills
|
|
8
|
+
* its whole input again: the prompt plus everything decoded before it.
|
|
9
|
+
*/
|
|
10
|
+
import { logger } from '../utils/logger.js';
|
|
11
|
+
import { categorizeModel, isTextGenCategory } from './model-taxonomy.js';
|
|
12
|
+
/** The most a Gemini 4 decode can produce over all its requests. */
|
|
13
|
+
export const LONG_DECODE_TOTAL_TOKENS = 1_048_576;
|
|
14
|
+
/** The most one streaming request decodes before it stops with `CONTINUATION` (a non-streaming one: 32 768). */
|
|
15
|
+
export const LONG_DECODE_STREAM_REQUEST_TOKENS = 65_536;
|
|
16
|
+
/** A text model of the Gemini 4 family (`gemini-4-<codename>`, `gemini-4.1-<codename>`, their `-preview` twins). */
|
|
17
|
+
const GEMINI_4_ID = /^gemini-4(?:\.\d+)?-/i;
|
|
18
|
+
/**
|
|
19
|
+
* The total a decode of `modelId` may reach through continuation, or `null` for a model without long decode. Long
|
|
20
|
+
* decode runs on the Gemini Developer API only: on Vertex AI every model is clamped to its per-request limit,
|
|
21
|
+
* whatever the shape of its id. The model registry carries it beside the advertised input and output limits.
|
|
22
|
+
*/
|
|
23
|
+
export function longDecodeTokenLimitOf(modelId, backend) {
|
|
24
|
+
if (backend !== 'developer' || !GEMINI_4_ID.test(modelId))
|
|
25
|
+
return null;
|
|
26
|
+
return isTextGenCategory(categorizeModel(modelId)) ? LONG_DECODE_TOTAL_TOKENS : null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Input a continuation request bills beyond the prompt and the tokens decoded before it. Measured on
|
|
30
|
+
* gemini-4-hydrogen in two runs: +125 tokens (99 712-token prompt, request 2 billed 165 373) and +89; reserved at
|
|
31
|
+
* twice the larger, rounded up.
|
|
32
|
+
*/
|
|
33
|
+
export const CONTINUATION_REQUEST_OVERHEAD_TOKENS = 256;
|
|
34
|
+
/**
|
|
35
|
+
* The caller's cap is clamped to the model's per-request limit, or — on a model with long decode — to its long
|
|
36
|
+
* decode total. Without a caller's cap nothing goes on the wire (one request, the model's default), unless the
|
|
37
|
+
* operator forces the per-request limit.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveOutputCap(inputs) {
|
|
40
|
+
const perRequest = typeof inputs.outputTokenLimit === 'number' && inputs.outputTokenLimit > 0
|
|
41
|
+
? inputs.outputTokenLimit
|
|
42
|
+
: inputs.fallbackLimit;
|
|
43
|
+
const ceiling = Math.max(perRequest, inputs.longDecodeTokenLimit ?? 0);
|
|
44
|
+
const wire = inputs.requested !== undefined
|
|
45
|
+
? Math.min(inputs.requested, ceiling)
|
|
46
|
+
: inputs.forceMax
|
|
47
|
+
? perRequest
|
|
48
|
+
: undefined;
|
|
49
|
+
const effective = wire ?? perRequest;
|
|
50
|
+
return {
|
|
51
|
+
wire,
|
|
52
|
+
effective,
|
|
53
|
+
perRequest,
|
|
54
|
+
ceiling,
|
|
55
|
+
maxRequests: maxDecodeRequests(effective, perRequest),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The cap of a long decode bounded by the model's input window W. Request k sends the prompt P again plus every token
|
|
60
|
+
* decoded before it, and the client opens no further request once the decoded tokens reached the cap: under a cap of
|
|
61
|
+
* at most W − P − O no request's input passes W. The premise — the API refuses a continuation request whose prompt
|
|
62
|
+
* plus decoded tokens pass W — is assumed, not measured: the repository holds a measurement of what a continuation
|
|
63
|
+
* request bills, none of a refusal at the window (docs/FOLLOW-UP-PRS.md T41).
|
|
64
|
+
*
|
|
65
|
+
* The cap is never cut below one request's limit — the first request sends the prompt alone, which the preflight
|
|
66
|
+
* bounds. A cut that leaves several requests keeps the caller's `wire`: the client stops the decode at `effective`,
|
|
67
|
+
* after `maxRequests`. A cut that leaves one request sends the cut value as `maxOutputTokens`, so the server holds it
|
|
68
|
+
* (a stop at it is `MAX_TOKENS`) — one streaming request would otherwise decode past it. Without a counted prompt or
|
|
69
|
+
* an advertised window nothing is cut.
|
|
70
|
+
*/
|
|
71
|
+
export function boundByInputWindow(cap, promptTokens, inputTokenLimit) {
|
|
72
|
+
if (cap.maxRequests <= 1 || promptTokens === undefined || inputTokenLimit === null) {
|
|
73
|
+
return { cap, cut: null };
|
|
74
|
+
}
|
|
75
|
+
const room = inputTokenLimit - promptTokens - CONTINUATION_REQUEST_OVERHEAD_TOKENS;
|
|
76
|
+
const most = Math.min(cap.ceiling, Math.max(room, cap.perRequest));
|
|
77
|
+
if (cap.effective <= most)
|
|
78
|
+
return { cap, cut: null };
|
|
79
|
+
const maxRequests = maxDecodeRequests(most, cap.perRequest);
|
|
80
|
+
return {
|
|
81
|
+
cap: {
|
|
82
|
+
wire: maxRequests === 1 ? most : cap.wire,
|
|
83
|
+
effective: most,
|
|
84
|
+
perRequest: cap.perRequest,
|
|
85
|
+
ceiling: most,
|
|
86
|
+
maxRequests,
|
|
87
|
+
},
|
|
88
|
+
cut: { from: cap.effective, to: most, inputTokenLimit },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** The progress and log line of a cut cap. */
|
|
92
|
+
export function describeInputWindowCut(cut) {
|
|
93
|
+
const n = (v) => v.toLocaleString('en-US');
|
|
94
|
+
return `maxOutputTokens cut from ${n(cut.from)} to ${n(cut.to)}: each continuation request sends the prompt again plus everything decoded before it, and the model's ${n(cut.inputTokenLimit)}-token input window holds no more`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The cap a call's decode runs under: a long decode never sends a continuation request past the model's input
|
|
98
|
+
* window (`boundByInputWindow`). A cut is said on the call's progress channel and in the log.
|
|
99
|
+
*/
|
|
100
|
+
export function capThatRuns(call) {
|
|
101
|
+
const bounded = boundByInputWindow(call.cap, call.promptTokens, call.inputTokenLimit);
|
|
102
|
+
if (bounded.cut === null)
|
|
103
|
+
return bounded;
|
|
104
|
+
const note = `${call.tool}: ${describeInputWindowCut(bounded.cut)}`;
|
|
105
|
+
call.emit(note);
|
|
106
|
+
logger.warn(note);
|
|
107
|
+
return bounded;
|
|
108
|
+
}
|
|
109
|
+
/** The answer the output cap keeps beside a thinking budget: Gemini requires `thinkingBudget < maxOutputTokens`. */
|
|
110
|
+
export const ANSWER_RESERVE_TOKENS = 1_024;
|
|
111
|
+
/**
|
|
112
|
+
* The refusal of a caller's positive `thinkingBudget` that leaves less than the answer reserve under the caller's own
|
|
113
|
+
* `maxOutputTokens` (`cap`: what that cap became under the model's limits) — refused, never clamped to 0, which
|
|
114
|
+
* Gemini 3 Pro answers with a 400 that hides the cause. `null` when it fits, or the caller set either one not.
|
|
115
|
+
*/
|
|
116
|
+
export function thinkingBudgetRefusal(budget, requestedCap, cap) {
|
|
117
|
+
if (budget === undefined || budget <= 0 || requestedCap === undefined)
|
|
118
|
+
return null;
|
|
119
|
+
const least = budget + ANSWER_RESERVE_TOKENS;
|
|
120
|
+
if (cap >= least)
|
|
121
|
+
return null;
|
|
122
|
+
return `thinkingBudget (${budget}) + ${ANSWER_RESERVE_TOKENS}-token answer reserve exceeds maxOutputTokens (${cap}). Raise \`maxOutputTokens\` to at least ${least}, or lower \`thinkingBudget\`.`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The count mode the preflight runs in. A decode that may take more than one request bills its prompt once per
|
|
126
|
+
* request, so the budget reservation takes the exact count (`countTokens`) whatever mode was asked for; a
|
|
127
|
+
* one-request call keeps the caller's mode.
|
|
128
|
+
*/
|
|
129
|
+
export function preflightModeFor(requested, cap) {
|
|
130
|
+
return cap.maxRequests > 1 ? 'exact' : requested;
|
|
131
|
+
}
|
|
132
|
+
/** The requests a decode of `cap` tokens may take when each request decodes up to `perRequest` tokens. */
|
|
133
|
+
export function maxDecodeRequests(cap, perRequest) {
|
|
134
|
+
if (perRequest <= 0)
|
|
135
|
+
return 1;
|
|
136
|
+
return Math.max(1, Math.ceil(cap / perRequest));
|
|
137
|
+
}
|
|
138
|
+
/** The most one streaming request of a model with per-request limit `perRequest` decodes (M). */
|
|
139
|
+
function streamRequestTokens(perRequest) {
|
|
140
|
+
return Math.max(perRequest, LONG_DECODE_STREAM_REQUEST_TOKENS);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The input tokens the continuation requests bill again, at most, for a prompt of `promptTokens` tokens:
|
|
144
|
+
*
|
|
145
|
+
* R = ceil(C / L) requests (the client stops there; L = the per-request limit)
|
|
146
|
+
* M = max(L, 65 536) the most one streaming request decodes
|
|
147
|
+
* O = CONTINUATION_REQUEST_OVERHEAD_TOKENS what a continuation request bills beyond the two terms below
|
|
148
|
+
* re-billed input = Σ_{k=1..R−1} (P + min(k·M, C) + O)
|
|
149
|
+
*
|
|
150
|
+
* Request k sends the prompt P again plus the tokens decoded before it, which are at most k·M and below the cap C
|
|
151
|
+
* (the client opens no request once the decoded tokens reached C). The first request's prompt is not part of this
|
|
152
|
+
* sum.
|
|
153
|
+
*/
|
|
154
|
+
export function continuationInputTokens(promptTokens, cap, perRequest) {
|
|
155
|
+
const requests = maxDecodeRequests(cap, perRequest);
|
|
156
|
+
const perRequestCeiling = streamRequestTokens(perRequest);
|
|
157
|
+
let total = 0;
|
|
158
|
+
for (let k = 1; k < requests; k++) {
|
|
159
|
+
total +=
|
|
160
|
+
promptTokens + Math.min(k * perRequestCeiling, cap) + CONTINUATION_REQUEST_OVERHEAD_TOKENS;
|
|
161
|
+
}
|
|
162
|
+
return total;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The most a decode of cap C produces (thinking and answer). One request honours `maxOutputTokens` = C. Over several
|
|
166
|
+
* requests C stays the bound only while Google holds `maxOutputTokens` over the whole chain, which the client cannot
|
|
167
|
+
* check: it stops after a request ends, once the decoded tokens reached C, so a server that holds the cap per
|
|
168
|
+
* request lets the last request run up to one request's decode past it — at most C + M − 1, and never more than
|
|
169
|
+
* R requests of M.
|
|
170
|
+
*/
|
|
171
|
+
export function decodedTokensBound(cap, perRequest) {
|
|
172
|
+
const requests = maxDecodeRequests(cap, perRequest);
|
|
173
|
+
if (requests === 1)
|
|
174
|
+
return cap;
|
|
175
|
+
const perRequestCeiling = streamRequestTokens(perRequest);
|
|
176
|
+
return Math.min(requests * perRequestCeiling, cap + perRequestCeiling - 1);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=long-decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"long-decode.js","sourceRoot":"","sources":["../../src/gemini/long-decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGzE,oEAAoE;AACpE,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAElD,gHAAgH;AAChH,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AAExD,oHAAoH;AACpH,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAK5C;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,OAAmB;IACzE,IAAI,OAAO,KAAK,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACvE,OAAO,iBAAiB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,CAAC;AAqCxD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAuB;IACtD,MAAM,UAAU,GACd,OAAO,MAAM,CAAC,gBAAgB,KAAK,QAAQ,IAAI,MAAM,CAAC,gBAAgB,GAAG,CAAC;QACxE,CAAC,CAAC,MAAM,CAAC,gBAAgB;QACzB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,oBAAoB,IAAI,CAAC,CAAC,CAAC;IACvE,MAAM,IAAI,GACR,MAAM,CAAC,SAAS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AkB,CAAC,GAAW,EAAE,UAAkB;IAChE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACpD,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAC/B,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,iBAAiB,EAAE,GAAG,GAAG,iBAAiB,GAAG,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -13,6 +13,8 @@ export interface ModelInfo {
|
|
|
13
13
|
displayName: string;
|
|
14
14
|
inputTokenLimit: number | null;
|
|
15
15
|
outputTokenLimit: number | null;
|
|
16
|
+
/** The total a decode may reach through continuation requests (Gemini 4: 1 048 576); `null` without long decode. */
|
|
17
|
+
longDecodeTokenLimit: number | null;
|
|
16
18
|
supportsThinking: boolean;
|
|
17
19
|
/** Inferred from input limit ≥ 100k — a heuristic for context-cache eligibility. */
|
|
18
20
|
supportsLongContext: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.d.ts","sourceRoot":"","sources":["../../src/gemini/model-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"model-registry.d.ts","sourceRoot":"","sources":["../../src/gemini/model-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,eAAe,CAAC;AA6FxD,MAAM,WAAW,SAAS;IACxB,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,oHAAoH;IACpH,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,oFAAoF;IACpF,mBAAmB,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;CAC1B;AA+BD,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,WAAW,EACnB,EAAE,KAAK,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAClC,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBtB;AAED,iEAAiE;AACjE,wBAAgB,oBAAoB,IAAI,IAAI,CAG3C"}
|