@herbertgao/pi-extensions 2026.11.17 → 2026.11.19
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 +25 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +2 -23
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +7 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/agent-badge.ts +244 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -3
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +18 -0
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +18 -0
- package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +80 -0
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +320 -102
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -30
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +27 -13
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +217 -41
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -93
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/package.json +12 -15
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- package/node_modules/pi-antigravity/tsconfig.json +0 -21
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import type {
|
|
3
|
-
Api,
|
|
4
|
-
Credential,
|
|
5
|
-
Model,
|
|
6
|
-
ModelsStoreEntry,
|
|
7
|
-
RefreshModelsContext,
|
|
8
|
-
} from "@earendil-works/pi-ai";
|
|
9
|
-
import { getApiKey } from "../auth/index.js";
|
|
10
|
-
import { DEFAULT_ENDPOINT, fetchAvailableModelsCatalog, parseApiKey } from "../client/index.js";
|
|
11
|
-
import { ANTIGRAVITY_API, type AntigravityModelConfig } from "../types/types.js";
|
|
12
|
-
import { antigravityEnv, isRecord } from "../utils/util.js";
|
|
13
|
-
import { buildAntigravityCatalog, resolvedCatalog, type AntigravityCatalog } from "./grouping.js";
|
|
14
|
-
import {
|
|
15
|
-
ANTIGRAVITY_MODELS,
|
|
16
|
-
ANTIGRAVITY_ROUTING,
|
|
17
|
-
applyAntigravityCatalog,
|
|
18
|
-
getCurrentAntigravityCatalog,
|
|
19
|
-
registerDiscoveredModelEnums,
|
|
20
|
-
restoreDynamicModelEnums,
|
|
21
|
-
snapshotDynamicModelEnums,
|
|
22
|
-
} from "./models.js";
|
|
23
|
-
|
|
24
|
-
export const DEFAULT_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;
|
|
25
|
-
export const ANTIGRAVITY_PERSIST_KEY = "pi-antigravity";
|
|
26
|
-
export const CATALOG_SCHEMA_VERSION = 2;
|
|
27
|
-
|
|
28
|
-
type PersistedAntigravityCatalog = {
|
|
29
|
-
catalog: AntigravityCatalog;
|
|
30
|
-
checkedAt: number;
|
|
31
|
-
modelEnums: Record<string, string>;
|
|
32
|
-
schemaVersion: number;
|
|
33
|
-
credentialKey: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export function getCatalogRefreshIntervalMs(): number {
|
|
37
|
-
const envVal =
|
|
38
|
-
antigravityEnv("CATALOG_REFRESH_INTERVAL_MS") ?? antigravityEnv("REFRESH_INTERVAL_MS");
|
|
39
|
-
if (envVal) {
|
|
40
|
-
const parsed = Number.parseInt(envVal, 10);
|
|
41
|
-
if (!Number.isNaN(parsed) && parsed >= 0) return parsed;
|
|
42
|
-
}
|
|
43
|
-
return DEFAULT_CATALOG_REFRESH_INTERVAL_MS;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const fallbackCatalog = (): AntigravityCatalog => ({
|
|
47
|
-
models: ANTIGRAVITY_MODELS,
|
|
48
|
-
routing: { ...ANTIGRAVITY_ROUTING },
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
/** Restore provider state supplied by Pi before checking offline mode or refresh TTL. */
|
|
52
|
-
export function hydrateAntigravityCatalog(stored: unknown): number {
|
|
53
|
-
if (!isRecord(stored)) return 0;
|
|
54
|
-
const persisted = stored[ANTIGRAVITY_PERSIST_KEY];
|
|
55
|
-
if (!isRecord(persisted)) return 0;
|
|
56
|
-
|
|
57
|
-
if (isStringMap(persisted.modelEnums)) restoreDynamicModelEnums(persisted.modelEnums);
|
|
58
|
-
if (isCatalog(persisted.catalog)) applyAntigravityCatalog(persisted.catalog);
|
|
59
|
-
return typeof persisted.checkedAt === "number" && persisted.checkedAt > 0
|
|
60
|
-
? persisted.checkedAt
|
|
61
|
-
: 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function discoverAntigravityModels(
|
|
65
|
-
apiKey: string,
|
|
66
|
-
signal?: AbortSignal,
|
|
67
|
-
): Promise<AntigravityCatalog> {
|
|
68
|
-
const creds = parseApiKey(apiKey);
|
|
69
|
-
const available = await fetchAvailableModelsCatalog(creds.token, creds.projectId, signal);
|
|
70
|
-
const models = available.data.models;
|
|
71
|
-
if (!models || Object.keys(models).length === 0) {
|
|
72
|
-
throw new Error("Antigravity returned an empty or unrecognized model catalog");
|
|
73
|
-
}
|
|
74
|
-
registerDiscoveredModelEnums(models);
|
|
75
|
-
return buildAntigravityCatalog(models, fallbackCatalog(), available.data.agentModelSorts);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function refreshAntigravityModels(
|
|
79
|
-
context: RefreshModelsContext,
|
|
80
|
-
): Promise<AntigravityModelConfig[]> {
|
|
81
|
-
const checkedAt = hydrateAntigravityCatalog(context.stored);
|
|
82
|
-
const current = getCurrentAntigravityCatalog();
|
|
83
|
-
if (!context.allowNetwork) return current.models;
|
|
84
|
-
|
|
85
|
-
const apiKey = apiKeyFromCredential(context.credential);
|
|
86
|
-
if (!apiKey || context.signal.aborted) return current.models;
|
|
87
|
-
|
|
88
|
-
// A different account/project or pre-upgrade cache must not suppress a fresh
|
|
89
|
-
// discovery. Keep hydration above so offline startup still has usable models.
|
|
90
|
-
const credentialKey = createHash("sha256")
|
|
91
|
-
.update(
|
|
92
|
-
JSON.stringify([
|
|
93
|
-
context.credential?.type === "oauth" ? context.credential.refresh : apiKey,
|
|
94
|
-
parseApiKey(apiKey).projectId,
|
|
95
|
-
]),
|
|
96
|
-
)
|
|
97
|
-
.digest("hex");
|
|
98
|
-
const stored: unknown = context.stored;
|
|
99
|
-
const persisted = isRecord(stored) ? stored[ANTIGRAVITY_PERSIST_KEY] : undefined;
|
|
100
|
-
const sameSource =
|
|
101
|
-
isRecord(persisted) &&
|
|
102
|
-
persisted.schemaVersion === CATALOG_SCHEMA_VERSION &&
|
|
103
|
-
persisted.credentialKey === credentialKey;
|
|
104
|
-
const now = Date.now();
|
|
105
|
-
if (
|
|
106
|
-
!context.force &&
|
|
107
|
-
sameSource &&
|
|
108
|
-
checkedAt > 0 &&
|
|
109
|
-
now >= checkedAt &&
|
|
110
|
-
now - checkedAt < getCatalogRefreshIntervalMs()
|
|
111
|
-
) {
|
|
112
|
-
return current.models;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
const discovered = await discoverAntigravityModels(apiKey, context.signal);
|
|
117
|
-
if (context.signal.aborted) return current.models;
|
|
118
|
-
const next = resolvedCatalog(discovered, current);
|
|
119
|
-
if (next.models.length > 0 && discovered.models.length > 0) {
|
|
120
|
-
applyAntigravityCatalog(next);
|
|
121
|
-
const refreshedAt = Date.now();
|
|
122
|
-
await context.publish({
|
|
123
|
-
persist: {
|
|
124
|
-
models: toStoredModels(next.models),
|
|
125
|
-
[ANTIGRAVITY_PERSIST_KEY]: {
|
|
126
|
-
catalog: next,
|
|
127
|
-
checkedAt: refreshedAt,
|
|
128
|
-
modelEnums: snapshotDynamicModelEnums(),
|
|
129
|
-
schemaVersion: CATALOG_SCHEMA_VERSION,
|
|
130
|
-
credentialKey,
|
|
131
|
-
} satisfies PersistedAntigravityCatalog,
|
|
132
|
-
} as unknown as ModelsStoreEntry,
|
|
133
|
-
});
|
|
134
|
-
return next.models;
|
|
135
|
-
}
|
|
136
|
-
} catch (error) {
|
|
137
|
-
// Keep last-known-good models; a failed refresh must not wipe the catalog.
|
|
138
|
-
// Forced/manual refreshes must still report the failure to their caller.
|
|
139
|
-
if (context.force) throw error;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return getCurrentAntigravityCatalog().models;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function isCatalog(value: unknown): value is AntigravityCatalog {
|
|
146
|
-
return (
|
|
147
|
-
isRecord(value) &&
|
|
148
|
-
Array.isArray(value.models) &&
|
|
149
|
-
value.models.length > 0 &&
|
|
150
|
-
isRecord(value.routing)
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function isStringMap(value: unknown): value is Record<string, string> {
|
|
155
|
-
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function apiKeyFromCredential(credential: Credential | undefined): string | undefined {
|
|
159
|
-
if (!credential) return undefined;
|
|
160
|
-
if (credential.type === "api_key") {
|
|
161
|
-
return typeof credential.key === "string" && credential.key ? credential.key : undefined;
|
|
162
|
-
}
|
|
163
|
-
if (credential.type === "oauth" && typeof credential.access === "string") {
|
|
164
|
-
return getApiKey(credential);
|
|
165
|
-
}
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function toStoredModels(models: AntigravityModelConfig[]): Model<Api>[] {
|
|
170
|
-
return models.map((model) => ({
|
|
171
|
-
...model,
|
|
172
|
-
api: ANTIGRAVITY_API,
|
|
173
|
-
provider: "antigravity",
|
|
174
|
-
baseUrl: DEFAULT_ENDPOINT,
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
@@ -1,487 +0,0 @@
|
|
|
1
|
-
import { ThinkingEffort } from "../types/enums.js";
|
|
2
|
-
import type { AntigravityModelConfig, AntigravityRouting, ModelInfoRaw } from "../types/types.js";
|
|
3
|
-
import { isRecord } from "../utils/util.js";
|
|
4
|
-
import { getAntigravityModelCost, RUNTIME_MAX_OUTPUT_TOKENS } from "./models.js";
|
|
5
|
-
|
|
6
|
-
export type AntigravityCatalog = {
|
|
7
|
-
models: AntigravityModelConfig[];
|
|
8
|
-
routing: Record<string, AntigravityRouting>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type ThinkingLevel = ThinkingEffort;
|
|
12
|
-
|
|
13
|
-
type RuntimeGroup = {
|
|
14
|
-
publicId: string;
|
|
15
|
-
variants: Partial<Record<ThinkingLevel, string>>;
|
|
16
|
-
unsuffixed?: string;
|
|
17
|
-
displayNames: string[];
|
|
18
|
-
/** Catalog capability: true/false when advertised, undefined when omitted. */
|
|
19
|
-
supportsThinking?: boolean;
|
|
20
|
-
supportsImages?: boolean;
|
|
21
|
-
contextWindow?: number;
|
|
22
|
-
maxOutputTokens?: number;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const THINKING_SUFFIXES: Array<{ suffix: string; level: ThinkingLevel }> = [
|
|
26
|
-
{ suffix: "extra-low", level: ThinkingEffort.Low },
|
|
27
|
-
{ suffix: "extra-high", level: ThinkingEffort.Xhigh },
|
|
28
|
-
{ suffix: "xhigh", level: ThinkingEffort.Xhigh },
|
|
29
|
-
{ suffix: "thinking", level: ThinkingEffort.High },
|
|
30
|
-
{ suffix: "minimal", level: ThinkingEffort.Minimal },
|
|
31
|
-
{ suffix: "medium", level: ThinkingEffort.Medium },
|
|
32
|
-
{ suffix: "high", level: ThinkingEffort.High },
|
|
33
|
-
{ suffix: "low", level: ThinkingEffort.Low },
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const DISPLAY_LEVELS: Array<{ pattern: RegExp; level: ThinkingLevel }> = [
|
|
37
|
-
{ pattern: /\(\s*extra\s*low\s*\)/i, level: ThinkingEffort.Low },
|
|
38
|
-
{ pattern: /\(\s*extra\s*high\s*\)/i, level: ThinkingEffort.Xhigh },
|
|
39
|
-
{ pattern: /\(\s*x-?\s*high\s*\)/i, level: ThinkingEffort.Xhigh },
|
|
40
|
-
{ pattern: /\(\s*thinking\s*\)/i, level: ThinkingEffort.High },
|
|
41
|
-
{ pattern: /\(\s*minimal\s*\)/i, level: ThinkingEffort.Minimal },
|
|
42
|
-
{ pattern: /\(\s*medium\s*\)/i, level: ThinkingEffort.Medium },
|
|
43
|
-
{ pattern: /\(\s*high\s*\)/i, level: ThinkingEffort.High },
|
|
44
|
-
{ pattern: /\(\s*low\s*\)/i, level: ThinkingEffort.Low },
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
const PI_LEVELS = [
|
|
48
|
-
ThinkingEffort.Off,
|
|
49
|
-
ThinkingEffort.Minimal,
|
|
50
|
-
ThinkingEffort.Low,
|
|
51
|
-
ThinkingEffort.Medium,
|
|
52
|
-
ThinkingEffort.High,
|
|
53
|
-
ThinkingEffort.Xhigh,
|
|
54
|
-
"max",
|
|
55
|
-
] as const;
|
|
56
|
-
|
|
57
|
-
const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
58
|
-
|
|
59
|
-
export function isSelectableRuntimeModelId(id: string, info?: ModelInfoRaw): boolean {
|
|
60
|
-
if (!/^[a-z0-9][a-z0-9_.-]*$/i.test(id) || /^MODEL_/i.test(id)) return false;
|
|
61
|
-
if (/^(chat_|tab_)/i.test(id)) return false;
|
|
62
|
-
if (/image/i.test(id) || /image/i.test(modelDisplayName(info) ?? "")) return false;
|
|
63
|
-
if (info?.isInternal === true || info?.apiProvider === "API_PROVIDER_INTERNAL") return false;
|
|
64
|
-
if (info?.disabled === true || id.endsWith("-disabled")) return false;
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function resolvedCatalog(
|
|
69
|
-
discovered: AntigravityCatalog | undefined,
|
|
70
|
-
current: AntigravityCatalog,
|
|
71
|
-
): AntigravityCatalog {
|
|
72
|
-
if (discovered && discovered.models.length > 0) return discovered;
|
|
73
|
-
return current;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function extractRecommendedModelIds(agentModelSorts: unknown): Set<string> | undefined {
|
|
77
|
-
if (!Array.isArray(agentModelSorts) || agentModelSorts.length === 0) return undefined;
|
|
78
|
-
const ids = new Set<string>();
|
|
79
|
-
for (const sort of agentModelSorts) {
|
|
80
|
-
if (!isRecord(sort)) continue;
|
|
81
|
-
const groups = Array.isArray(sort.groups) ? sort.groups : [];
|
|
82
|
-
for (const group of groups) {
|
|
83
|
-
if (!isRecord(group) || !Array.isArray(group.modelIds)) continue;
|
|
84
|
-
for (const id of group.modelIds) {
|
|
85
|
-
if (typeof id === "string" && id) ids.add(id);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return ids.size > 0 ? ids : undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function isExtraAllowedModelId(runtimeId: string): boolean {
|
|
93
|
-
return /(?:^|-)(?:hydrogen|oxygen)(?:-|$)/i.test(runtimeId);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function buildAntigravityCatalog(
|
|
97
|
-
rawModels: Record<string, ModelInfoRaw>,
|
|
98
|
-
fallback: AntigravityCatalog,
|
|
99
|
-
agentModelSorts?: unknown,
|
|
100
|
-
): AntigravityCatalog {
|
|
101
|
-
const recommendedIds = extractRecommendedModelIds(agentModelSorts);
|
|
102
|
-
|
|
103
|
-
function collectGroups(filterIds?: Set<string>): Map<string, RuntimeGroup> {
|
|
104
|
-
const collected = new Map<string, RuntimeGroup>();
|
|
105
|
-
|
|
106
|
-
for (const [runtimeId, info] of Object.entries(rawModels)) {
|
|
107
|
-
if (!isSelectableRuntimeModelId(runtimeId, info)) continue;
|
|
108
|
-
if (info?.isInternal) continue;
|
|
109
|
-
if (filterIds && !filterIds.has(runtimeId) && !isExtraAllowedModelId(runtimeId)) continue;
|
|
110
|
-
|
|
111
|
-
const displayName = modelDisplayName(info);
|
|
112
|
-
if (runtimeId.endsWith("-tiered")) {
|
|
113
|
-
const baseId = runtimeId.slice(0, -"-tiered".length);
|
|
114
|
-
const group = ensureGroup(collected, baseId);
|
|
115
|
-
absorbMetadata(group, info, displayName);
|
|
116
|
-
if (!group.unsuffixed) group.unsuffixed = runtimeId;
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const suffix = parseThinkingSuffix(runtimeId);
|
|
121
|
-
const publicId = suffix?.baseId ?? runtimeId;
|
|
122
|
-
const group = ensureGroup(collected, publicId);
|
|
123
|
-
absorbMetadata(group, info, displayName);
|
|
124
|
-
|
|
125
|
-
const level = levelFromDisplayName(displayName) ?? suffix?.level;
|
|
126
|
-
if (level) group.variants[level] = runtimeId;
|
|
127
|
-
else group.unsuffixed = runtimeId;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
mergeAgentSingletons(collected);
|
|
131
|
-
return collected;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let groups = collectGroups(recommendedIds);
|
|
135
|
-
if (groups.size === 0 && recommendedIds) {
|
|
136
|
-
groups = collectGroups();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (groups.size === 0) throw new Error("Antigravity catalog contains no supported chat models");
|
|
140
|
-
|
|
141
|
-
const models: AntigravityModelConfig[] = [];
|
|
142
|
-
const routing: Record<string, AntigravityRouting> = {};
|
|
143
|
-
|
|
144
|
-
for (const group of groups.values()) {
|
|
145
|
-
const synthesized = synthesizeModel(group, fallback.models);
|
|
146
|
-
models.push(synthesized.model);
|
|
147
|
-
routing[group.publicId] = synthesized.routing;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
models.sort(comparePublicModels);
|
|
151
|
-
return { models, routing };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function positiveTokenLimit(value: unknown): number | undefined {
|
|
155
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function ensureGroup(groups: Map<string, RuntimeGroup>, publicId: string): RuntimeGroup {
|
|
159
|
-
const existing = groups.get(publicId);
|
|
160
|
-
if (existing) return existing;
|
|
161
|
-
const created: RuntimeGroup = {
|
|
162
|
-
publicId,
|
|
163
|
-
variants: {},
|
|
164
|
-
displayNames: [],
|
|
165
|
-
};
|
|
166
|
-
groups.set(publicId, created);
|
|
167
|
-
return created;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function absorbMetadata(
|
|
171
|
-
group: RuntimeGroup,
|
|
172
|
-
info: ModelInfoRaw | undefined,
|
|
173
|
-
displayName: string | undefined,
|
|
174
|
-
): void {
|
|
175
|
-
if (displayName) group.displayNames.push(displayName);
|
|
176
|
-
// A public model can route to any variant. Advertise the smallest supplied
|
|
177
|
-
// limit so every route remains within the server's advertised capabilities.
|
|
178
|
-
const contextWindow = positiveTokenLimit(info?.maxTokens);
|
|
179
|
-
const maxOutputTokens = positiveTokenLimit(info?.maxOutputTokens);
|
|
180
|
-
if (contextWindow !== undefined) {
|
|
181
|
-
group.contextWindow = Math.min(group.contextWindow ?? contextWindow, contextWindow);
|
|
182
|
-
}
|
|
183
|
-
if (maxOutputTokens !== undefined) {
|
|
184
|
-
group.maxOutputTokens = Math.min(group.maxOutputTokens ?? maxOutputTokens, maxOutputTokens);
|
|
185
|
-
}
|
|
186
|
-
if (info?.supportsThinking === true) group.supportsThinking = true;
|
|
187
|
-
else if (info?.supportsThinking === false && group.supportsThinking !== true) {
|
|
188
|
-
group.supportsThinking = false;
|
|
189
|
-
}
|
|
190
|
-
if (info?.supportsImages === false) group.supportsImages = false;
|
|
191
|
-
else if (info?.supportsImages === true && group.supportsImages === undefined) {
|
|
192
|
-
group.supportsImages = true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function mergeAgentSingletons(groups: Map<string, RuntimeGroup>): void {
|
|
197
|
-
for (const [publicId, group] of [...groups.entries()]) {
|
|
198
|
-
if (!publicId.endsWith("-agent") || group.supportsThinking === false) continue;
|
|
199
|
-
const runtimeIds = [group.unsuffixed, ...Object.values(group.variants)].filter(
|
|
200
|
-
(id): id is string => id !== undefined,
|
|
201
|
-
);
|
|
202
|
-
if (runtimeIds.length !== 1) continue;
|
|
203
|
-
const [runtimeId] = runtimeIds;
|
|
204
|
-
const family = displayFamily(group.displayNames[0]);
|
|
205
|
-
if (!family) continue;
|
|
206
|
-
const target = [...groups.values()].find(
|
|
207
|
-
(candidate) =>
|
|
208
|
-
candidate.publicId !== publicId &&
|
|
209
|
-
candidate.displayNames.some((name) => displayFamily(name) === family),
|
|
210
|
-
);
|
|
211
|
-
if (!target) continue;
|
|
212
|
-
const level =
|
|
213
|
-
(Object.keys(group.variants) as ThinkingLevel[]).find(
|
|
214
|
-
(candidate) => group.variants[candidate] === runtimeId,
|
|
215
|
-
) ?? levelFromDisplayName(group.displayNames[0]);
|
|
216
|
-
if (!level || target.variants[level]) continue;
|
|
217
|
-
target.variants[level] = runtimeId;
|
|
218
|
-
absorbMetadata(
|
|
219
|
-
target,
|
|
220
|
-
{
|
|
221
|
-
supportsThinking: group.supportsThinking,
|
|
222
|
-
supportsImages: group.supportsImages,
|
|
223
|
-
maxTokens: group.contextWindow,
|
|
224
|
-
maxOutputTokens: group.maxOutputTokens,
|
|
225
|
-
},
|
|
226
|
-
group.displayNames[0],
|
|
227
|
-
);
|
|
228
|
-
groups.delete(publicId);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function parseThinkingSuffix(
|
|
233
|
-
runtimeId: string,
|
|
234
|
-
): { baseId: string; level: ThinkingLevel } | undefined {
|
|
235
|
-
const lower = runtimeId.toLowerCase();
|
|
236
|
-
for (const { suffix, level } of THINKING_SUFFIXES) {
|
|
237
|
-
if (lower.endsWith(`-${suffix}`)) {
|
|
238
|
-
return { baseId: runtimeId.slice(0, -(suffix.length + 1)), level };
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return undefined;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function levelFromDisplayName(displayName: string | undefined): ThinkingLevel | undefined {
|
|
245
|
-
if (!displayName) return undefined;
|
|
246
|
-
for (const { pattern, level } of DISPLAY_LEVELS) {
|
|
247
|
-
if (pattern.test(displayName)) return level;
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function modelDisplayName(info: ModelInfoRaw | undefined): string | undefined {
|
|
253
|
-
if (!info) return undefined;
|
|
254
|
-
if (typeof info.displayName === "string" && info.displayName) return info.displayName;
|
|
255
|
-
if (typeof info.label === "string" && info.label) return info.label;
|
|
256
|
-
if (typeof info.modelName === "string" && info.modelName) return info.modelName;
|
|
257
|
-
return undefined;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function displayFamily(displayName: string | undefined): string | undefined {
|
|
261
|
-
if (!displayName) return undefined;
|
|
262
|
-
return displayName
|
|
263
|
-
.replace(
|
|
264
|
-
/\s*\((?:extra\s*low|extra\s*high|x-?\s*high|low|medium|high|minimal|thinking)\)\s*$/i,
|
|
265
|
-
"",
|
|
266
|
-
)
|
|
267
|
-
.trim()
|
|
268
|
-
.toLowerCase();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function synthesizeModel(
|
|
272
|
-
group: RuntimeGroup,
|
|
273
|
-
fallbackModels: AntigravityModelConfig[],
|
|
274
|
-
): { model: AntigravityModelConfig; routing: AntigravityRouting } {
|
|
275
|
-
const template = familyTemplate(group.publicId, fallbackModels);
|
|
276
|
-
const advertisedLevels = advertisedThinkingLevels(group);
|
|
277
|
-
const routing = routingFromVariants(group.publicId, group.variants, group.unsuffixed);
|
|
278
|
-
const supportsImages = group.supportsImages ?? template?.input.includes("image") ?? true;
|
|
279
|
-
const reasoning =
|
|
280
|
-
group.supportsThinking === false
|
|
281
|
-
? false
|
|
282
|
-
: advertisedLevels.size > 0 ||
|
|
283
|
-
group.supportsThinking === true ||
|
|
284
|
-
(group.supportsThinking === undefined && Boolean(template?.reasoning));
|
|
285
|
-
return {
|
|
286
|
-
model: {
|
|
287
|
-
id: group.publicId,
|
|
288
|
-
name: publicModelName(group),
|
|
289
|
-
reasoning,
|
|
290
|
-
thinkingLevelMap: reasoning ? thinkingLevelMapFromLevels(advertisedLevels) : undefined,
|
|
291
|
-
input: supportsImages ? ["text", "image"] : ["text"],
|
|
292
|
-
// Prefer this model's own published price over the family template's, so a
|
|
293
|
-
// newly discovered Flash variant is not billed at another Flash's rate.
|
|
294
|
-
cost: getAntigravityModelCost(group.publicId) ?? template?.cost ?? ZERO_COST,
|
|
295
|
-
contextWindow: group.contextWindow ?? template?.contextWindow ?? 128000,
|
|
296
|
-
maxTokens:
|
|
297
|
-
group.maxOutputTokens ??
|
|
298
|
-
RUNTIME_MAX_OUTPUT_TOKENS[group.publicId] ??
|
|
299
|
-
template?.maxTokens ??
|
|
300
|
-
8192,
|
|
301
|
-
},
|
|
302
|
-
routing,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function advertisedThinkingLevels(group: RuntimeGroup): Set<string> {
|
|
307
|
-
// An explicit denial overrides levels inferred from display names or suffixes.
|
|
308
|
-
if (group.supportsThinking === false) return new Set();
|
|
309
|
-
const levels = new Set(Object.keys(group.variants));
|
|
310
|
-
if (levels.size > 0) return levels;
|
|
311
|
-
if (group.supportsThinking === true) {
|
|
312
|
-
levels.add(ThinkingEffort.High);
|
|
313
|
-
}
|
|
314
|
-
return levels;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function routingFromVariants(
|
|
318
|
-
publicId: string,
|
|
319
|
-
variants: Partial<Record<ThinkingLevel, string>>,
|
|
320
|
-
unsuffixed?: string,
|
|
321
|
-
): AntigravityRouting {
|
|
322
|
-
const defaultRequestId =
|
|
323
|
-
variants[ThinkingEffort.Low] ??
|
|
324
|
-
variants[ThinkingEffort.Minimal] ??
|
|
325
|
-
variants[ThinkingEffort.Medium] ??
|
|
326
|
-
variants[ThinkingEffort.High] ??
|
|
327
|
-
variants[ThinkingEffort.Xhigh] ??
|
|
328
|
-
unsuffixed ??
|
|
329
|
-
publicId;
|
|
330
|
-
|
|
331
|
-
const pick = (...keys: ThinkingLevel[]): string => {
|
|
332
|
-
for (const key of keys) {
|
|
333
|
-
const id = variants[key];
|
|
334
|
-
if (id) return id;
|
|
335
|
-
}
|
|
336
|
-
return unsuffixed ?? defaultRequestId;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
return {
|
|
340
|
-
off: pick(
|
|
341
|
-
ThinkingEffort.Low,
|
|
342
|
-
ThinkingEffort.Minimal,
|
|
343
|
-
ThinkingEffort.Medium,
|
|
344
|
-
ThinkingEffort.High,
|
|
345
|
-
ThinkingEffort.Xhigh,
|
|
346
|
-
),
|
|
347
|
-
routing: {
|
|
348
|
-
minimal: pick(
|
|
349
|
-
ThinkingEffort.Minimal,
|
|
350
|
-
ThinkingEffort.Low,
|
|
351
|
-
ThinkingEffort.Medium,
|
|
352
|
-
ThinkingEffort.High,
|
|
353
|
-
ThinkingEffort.Xhigh,
|
|
354
|
-
),
|
|
355
|
-
low: pick(
|
|
356
|
-
ThinkingEffort.Low,
|
|
357
|
-
ThinkingEffort.Minimal,
|
|
358
|
-
ThinkingEffort.Medium,
|
|
359
|
-
ThinkingEffort.High,
|
|
360
|
-
ThinkingEffort.Xhigh,
|
|
361
|
-
),
|
|
362
|
-
medium: pick(
|
|
363
|
-
ThinkingEffort.Medium,
|
|
364
|
-
ThinkingEffort.Low,
|
|
365
|
-
ThinkingEffort.High,
|
|
366
|
-
ThinkingEffort.Minimal,
|
|
367
|
-
ThinkingEffort.Xhigh,
|
|
368
|
-
),
|
|
369
|
-
high: pick(
|
|
370
|
-
ThinkingEffort.High,
|
|
371
|
-
ThinkingEffort.Medium,
|
|
372
|
-
ThinkingEffort.Low,
|
|
373
|
-
ThinkingEffort.Minimal,
|
|
374
|
-
ThinkingEffort.Xhigh,
|
|
375
|
-
),
|
|
376
|
-
xhigh: pick(
|
|
377
|
-
ThinkingEffort.Xhigh,
|
|
378
|
-
ThinkingEffort.High,
|
|
379
|
-
ThinkingEffort.Medium,
|
|
380
|
-
ThinkingEffort.Low,
|
|
381
|
-
),
|
|
382
|
-
},
|
|
383
|
-
defaultRequestId,
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function thinkingLevelMapFromLevels(
|
|
388
|
-
levels: Set<string>,
|
|
389
|
-
): AntigravityModelConfig["thinkingLevelMap"] {
|
|
390
|
-
const map: NonNullable<AntigravityModelConfig["thinkingLevelMap"]> = {};
|
|
391
|
-
for (const level of PI_LEVELS) {
|
|
392
|
-
map[level] = levels.has(level) ? level : null;
|
|
393
|
-
}
|
|
394
|
-
return map;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function familyTemplate(
|
|
398
|
-
publicId: string,
|
|
399
|
-
fallbackModels: AntigravityModelConfig[],
|
|
400
|
-
): AntigravityModelConfig | undefined {
|
|
401
|
-
if (/^gemini-.*-flash/i.test(publicId)) {
|
|
402
|
-
return fallbackModels.find((model) => /^gemini-.*-flash/i.test(model.id));
|
|
403
|
-
}
|
|
404
|
-
if (/^gemini-.*-pro/i.test(publicId)) {
|
|
405
|
-
return fallbackModels.find((model) => /^gemini-.*-pro/i.test(model.id));
|
|
406
|
-
}
|
|
407
|
-
if (publicId.startsWith("claude-opus")) {
|
|
408
|
-
return fallbackModels.find((model) => model.id.startsWith("claude-opus"));
|
|
409
|
-
}
|
|
410
|
-
if (publicId.startsWith("claude-")) {
|
|
411
|
-
return (
|
|
412
|
-
fallbackModels.find((model) => model.id.startsWith("claude-sonnet")) ??
|
|
413
|
-
fallbackModels.find((model) => model.id.startsWith("claude-"))
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
if (publicId.startsWith("gpt-oss")) {
|
|
417
|
-
return fallbackModels.find((model) => model.id.startsWith("gpt-oss"));
|
|
418
|
-
}
|
|
419
|
-
if (publicId.startsWith("gemini-")) {
|
|
420
|
-
return fallbackModels.find((model) => model.id.startsWith("gemini-"));
|
|
421
|
-
}
|
|
422
|
-
return undefined;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function publicModelName(group: RuntimeGroup): string {
|
|
426
|
-
const family = group.displayNames.map((name) => displayFamily(name)).find(Boolean);
|
|
427
|
-
if (family) {
|
|
428
|
-
return `${titleCase(family)} (Antigravity)`;
|
|
429
|
-
}
|
|
430
|
-
return `${humanizePublicId(group.publicId)} (Antigravity)`;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
function titleCase(value: string): string {
|
|
434
|
-
return value.replace(/\b([a-z])/g, (char) => char.toUpperCase());
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
export function humanizePublicId(id: string): string {
|
|
438
|
-
const tokens = id.split("-");
|
|
439
|
-
const words: string[] = [];
|
|
440
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
441
|
-
const token = tokens[i];
|
|
442
|
-
if (!token) continue;
|
|
443
|
-
const next = tokens[i + 1];
|
|
444
|
-
if (token === "gpt" && next === "oss") {
|
|
445
|
-
words.push("GPT-OSS");
|
|
446
|
-
i++;
|
|
447
|
-
continue;
|
|
448
|
-
}
|
|
449
|
-
if (/^\d+$/.test(token) && next && /^\d+$/.test(next)) {
|
|
450
|
-
words.push(`${token}.${next}`);
|
|
451
|
-
i++;
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
if (/^\d/.test(token)) {
|
|
455
|
-
words.push(token.toUpperCase());
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
words.push(token.charAt(0).toUpperCase() + token.slice(1));
|
|
459
|
-
}
|
|
460
|
-
return words.join(" ");
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function parseGeminiVersion(id: string): number {
|
|
464
|
-
const match = id.match(/^gemini-(\d+)(?:\.(\d+))?/i);
|
|
465
|
-
if (!match) return 0;
|
|
466
|
-
return Number(match[1]) * 1000 + Number(match[2] || 0);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function comparePublicModels(a: AntigravityModelConfig, b: AntigravityModelConfig): number {
|
|
470
|
-
const rankA = modelRank(a.id);
|
|
471
|
-
const rankB = modelRank(b.id);
|
|
472
|
-
if (rankA[0] !== rankB[0]) return rankA[0] - rankB[0];
|
|
473
|
-
if (rankA[1] !== rankB[1]) return rankA[1] - rankB[1];
|
|
474
|
-
return a.id.localeCompare(b.id);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function modelRank(id: string): [number, number] {
|
|
478
|
-
const version = parseGeminiVersion(id);
|
|
479
|
-
if (/^gemini-.*flash/i.test(id) && !/pro/i.test(id)) return [0, -version];
|
|
480
|
-
if (id.startsWith("claude-opus")) return [1, 0];
|
|
481
|
-
if (id.startsWith("claude-sonnet")) return [2, 0];
|
|
482
|
-
if (id.startsWith("claude-")) return [3, 0];
|
|
483
|
-
if (/^gemini-.*pro/i.test(id)) return [4, -version];
|
|
484
|
-
if (id.startsWith("gemini-")) return [5, -version];
|
|
485
|
-
if (id.startsWith("gpt-oss")) return [6, 0];
|
|
486
|
-
return [7, 0];
|
|
487
|
-
}
|