pi-antigravity-bridge 0.1.17 → 0.1.18
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 +6 -0
- package/package.json +1 -1
- package/src/catalog/model-discovery.ts +23 -10
- package/src/session/turn-coordinator.ts +11 -6
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -183,19 +183,22 @@ export interface DiscoveredCatalogSnapshot {
|
|
|
183
183
|
modelEfforts: Record<string, EffortSuffix[]>;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
/** 运行时从 usage_update.size
|
|
186
|
+
/** 运行时从 usage_update.size 观测到的后端容量,可能大于原生 Checkpointer 水位。 */
|
|
187
187
|
const runtimeObservedWindows = new Map<string, number>();
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
export function recordObservedContextWindow(modelId: string, size: number | undefined): boolean {
|
|
189
|
+
export function normalizeReportedContextWindow(size: number | undefined): number | undefined {
|
|
191
190
|
if (typeof size !== "number" || !Number.isFinite(size) || size < 16_000) {
|
|
192
|
-
return
|
|
191
|
+
return undefined;
|
|
193
192
|
}
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
return Math.floor(size);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function recordObservedContextWindow(modelId: string, size: number | undefined): boolean {
|
|
197
|
+
const window = normalizeReportedContextWindow(size);
|
|
198
|
+
if (window === undefined || runtimeObservedWindows.get(modelId) === window) {
|
|
196
199
|
return false;
|
|
197
200
|
}
|
|
198
|
-
runtimeObservedWindows.set(modelId,
|
|
201
|
+
runtimeObservedWindows.set(modelId, window);
|
|
199
202
|
return true;
|
|
200
203
|
}
|
|
201
204
|
|
|
@@ -203,6 +206,16 @@ export function getObservedContextWindow(modelId: string): number | undefined {
|
|
|
203
206
|
return runtimeObservedWindows.get(modelId);
|
|
204
207
|
}
|
|
205
208
|
|
|
209
|
+
/** 以已核实的 AGY 原生 Checkpointer 水位规划回放和 Pi 自动压缩。 */
|
|
210
|
+
export function resolveAgyContextWindow(modelId: string, capacity: number): number {
|
|
211
|
+
const lower = modelId.toLowerCase();
|
|
212
|
+
const baseId = splitEffortSuffix(lower)?.baseId ?? lower;
|
|
213
|
+
if (baseId === "gemini-4-neon" || baseId === "gemini-4-carbon") {
|
|
214
|
+
return Math.min(capacity, 512_000);
|
|
215
|
+
}
|
|
216
|
+
return capacity;
|
|
217
|
+
}
|
|
218
|
+
|
|
206
219
|
/** 按模型家族推断默认上下文窗口与最大输出 Token 规格 */
|
|
207
220
|
export function inferModelSpecs(modelId: string): {
|
|
208
221
|
contextWindow: number;
|
|
@@ -232,7 +245,7 @@ export function inferModelSpecs(modelId: string): {
|
|
|
232
245
|
lower.includes("orchestrator")
|
|
233
246
|
) {
|
|
234
247
|
return {
|
|
235
|
-
contextWindow: observed ?? 1_048_576,
|
|
248
|
+
contextWindow: resolveAgyContextWindow(modelId, observed ?? 1_048_576),
|
|
236
249
|
maxTokens: 65_536,
|
|
237
250
|
supportsImage: true,
|
|
238
251
|
};
|
|
@@ -426,11 +439,11 @@ export function readCachedCatalog(env: NodeJS.ProcessEnv = process.env): Discove
|
|
|
426
439
|
if (!fs.existsSync(cachePath)) return undefined;
|
|
427
440
|
const raw = JSON.parse(fs.readFileSync(cachePath, "utf8")) as DiscoveredCatalogSnapshot;
|
|
428
441
|
if (raw?.version === 1 && Array.isArray(raw.models) && raw.models.length > 0) {
|
|
429
|
-
//
|
|
442
|
+
// 应用最新观测的容量与 Checkpointer 水位,并为旧版零费用缓存补全参考定价。
|
|
430
443
|
const calibrated = raw.models.map((m) => ({
|
|
431
444
|
...m,
|
|
432
445
|
cost: hasNonZeroModelCost(m.cost) ? m.cost : resolveBuiltinModelCost(m.id, m.name),
|
|
433
|
-
contextWindow: getObservedContextWindow(m.id) ?? m.contextWindow,
|
|
446
|
+
contextWindow: resolveAgyContextWindow(m.id, getObservedContextWindow(m.id) ?? m.contextWindow),
|
|
434
447
|
}));
|
|
435
448
|
return { ...raw, models: calibrated };
|
|
436
449
|
}
|
|
@@ -34,8 +34,10 @@ import type {
|
|
|
34
34
|
} from "../acp/protocol.ts";
|
|
35
35
|
import {
|
|
36
36
|
ANTIGRAVITY_PROVIDER_ID,
|
|
37
|
+
normalizeReportedContextWindow,
|
|
37
38
|
recordObservedContextWindow,
|
|
38
39
|
removeEmptyProbeSessionFiles,
|
|
40
|
+
resolveAgyContextWindow,
|
|
39
41
|
resolveSessionModelSelection,
|
|
40
42
|
} from "../catalog/model-discovery.ts";
|
|
41
43
|
import {
|
|
@@ -734,21 +736,22 @@ export class TurnCoordinator {
|
|
|
734
736
|
}
|
|
735
737
|
ledger.usedTokens = update.used;
|
|
736
738
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
+
const reportedSize = normalizeReportedContextWindow(update.size);
|
|
740
|
+
if (reportedSize !== undefined) {
|
|
741
|
+
ledger.windowSize = reportedSize;
|
|
739
742
|
const activeModel = this.activeContext?.model;
|
|
740
743
|
const targetModelId =
|
|
741
744
|
ledger.lastSelectedModelId ??
|
|
742
745
|
(activeModel?.provider === ANTIGRAVITY_PROVIDER_ID ? activeModel.id : undefined);
|
|
743
746
|
if (targetModelId) {
|
|
744
|
-
recordObservedContextWindow(targetModelId,
|
|
747
|
+
recordObservedContextWindow(targetModelId, reportedSize);
|
|
745
748
|
}
|
|
746
749
|
if (
|
|
747
750
|
activeModel &&
|
|
748
751
|
activeModel.provider === ANTIGRAVITY_PROVIDER_ID &&
|
|
749
752
|
(!ledger.lastSelectedModelId || activeModel.id === ledger.lastSelectedModelId)
|
|
750
753
|
) {
|
|
751
|
-
activeModel.contextWindow =
|
|
754
|
+
activeModel.contextWindow = resolveAgyContextWindow(activeModel.id, reportedSize);
|
|
752
755
|
}
|
|
753
756
|
}
|
|
754
757
|
updateAntigravityStatusBar(
|
|
@@ -885,6 +888,8 @@ export class TurnCoordinator {
|
|
|
885
888
|
context: TranscriptContext,
|
|
886
889
|
options?: SimpleStreamOptions,
|
|
887
890
|
): Promise<void> {
|
|
891
|
+
// 兼容仍携带旧目录容量的模型对象,在规划重放前应用 Checkpointer 水位。
|
|
892
|
+
model.contextWindow = resolveAgyContextWindow(model.id, model.contextWindow);
|
|
888
893
|
const piSessionKey = this.resolveCurrentPiSessionKey(options?.sessionId);
|
|
889
894
|
const primaryLedger = this.ledgers.get(piSessionKey);
|
|
890
895
|
const hasBusyPrimary = Boolean(
|
|
@@ -3022,9 +3027,9 @@ export class TurnCoordinator {
|
|
|
3022
3027
|
if (item.kind === "prompt_done") {
|
|
3023
3028
|
this.mirrorBroker.completePendingCallsImplicitly(ledger.agySessionId);
|
|
3024
3029
|
|
|
3025
|
-
if (ledger.windowSize) {
|
|
3030
|
+
if (ledger.windowSize !== undefined) {
|
|
3026
3031
|
recordObservedContextWindow(model.id, ledger.windowSize);
|
|
3027
|
-
model.contextWindow = ledger.windowSize;
|
|
3032
|
+
model.contextWindow = resolveAgyContextWindow(model.id, ledger.windowSize);
|
|
3028
3033
|
}
|
|
3029
3034
|
|
|
3030
3035
|
if (item.response.stopReason === "cancelled") {
|