@bitkyc08/opencodex 2.100.6 → 2.100.7
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/gui/dist/assets/App-BfoDjNBU.js +65 -0
- package/gui/dist/assets/App-hklyKJR5.css +1 -0
- package/gui/dist/assets/{Tray-CVqm4S4W.js → Tray-BN6pxM_V.js} +1 -1
- package/gui/dist/assets/brand-mark-CDZQ-wa9.js +1 -0
- package/gui/dist/assets/index-B85uU8rK.css +2 -0
- package/gui/dist/assets/index-Bt9ze3XN.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-COdzmORE.js → segment-thumb-features-BM5n8NMX.js} +1 -1
- package/gui/dist/classic/assets/App-D4cjNg2I.js +64 -0
- package/gui/dist/classic/assets/App-DSivR528.css +1 -0
- package/gui/dist/classic/assets/{Tray-BDlcOLDK.js → Tray-DTgGR7wt.js} +1 -1
- package/gui/dist/classic/assets/index-ALDeKRg9.js +138 -0
- package/gui/dist/classic/assets/usage-companion-chart-BC-Nos9Q.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +2 -2
- package/src/adapters/coding-agent/process-tree.ts +30 -0
- package/src/adapters/coding-agent/profile.ts +1 -1
- package/src/adapters/coding-agent/turn.ts +2 -9
- package/src/adapters/command-code-decision-guard.ts +25 -0
- package/src/adapters/cursor/catalog.ts +14 -0
- package/src/adapters/cursor/effort-map.ts +3 -0
- package/src/adapters/google-usage.ts +28 -0
- package/src/adapters/google.ts +9 -26
- package/src/adapters/qoder/adapter.ts +197 -13
- package/src/adapters/registry.ts +13 -0
- package/src/adapters/step-cli/adapter.ts +401 -0
- package/src/adapters/step-cli/constants.ts +11 -0
- package/src/adapters/step-cli/conversation.ts +159 -0
- package/src/adapters/step-cli/env.ts +49 -0
- package/src/adapters/step-cli/errors.ts +76 -0
- package/src/adapters/step-cli/events.ts +227 -0
- package/src/adapters/step-cli/profiles.ts +134 -0
- package/src/adapters/step-cli/projection.ts +242 -0
- package/src/adapters/step-cli/registry.ts +181 -0
- package/src/adapters/step-cli/session-pool.ts +225 -0
- package/src/adapters/step-cli/session.ts +842 -0
- package/src/adapters/step-cli/stdio-frames.ts +330 -0
- package/src/adapters/step-cli/tool-bridge.ts +92 -0
- package/src/cli/claude.ts +5 -2
- package/src/client/link-management-relay.ts +11 -0
- package/src/client/machine-listener.ts +6 -2
- package/src/codex/account-label.ts +1 -1
- package/src/codex/catalog/gather-capture.ts +2 -1
- package/src/codex/catalog/metadata.ts +48 -2
- package/src/codex/catalog/model-hints.ts +19 -5
- package/src/codex/catalog/model-visibility.ts +4 -7
- package/src/codex/catalog/native-ultrafast.ts +8 -6
- package/src/generated/compatibility-version.json +137 -61
- package/src/generated/model-metadata.ts +1 -1
- package/src/lib/client-error-body.ts +2 -0
- package/src/lib/messages-error-body.ts +3 -1
- package/src/lib/optional-shutdown-hooks.ts +55 -5
- package/src/lib/process-control.ts +3 -2
- package/src/lib/shutdown-budget.ts +5 -0
- package/src/link/remote-platform.ts +24 -9
- package/src/link/ssh-argv.ts +8 -2
- package/src/link/ssh-runner.ts +15 -2
- package/src/oauth/m365-copilot-web-session.ts +28 -4
- package/src/protocols/dto.ts +24 -12
- package/src/protocols/settings.ts +20 -16
- package/src/protocols/shadow.ts +2 -3
- package/src/protocols/trace.ts +24 -2
- package/src/providers/command-code-decision-models.ts +65 -0
- package/src/providers/quota.ts +4 -4
- package/src/providers/registry/entries-core.ts +18 -7
- package/src/providers/registry/entries-extended.ts +41 -0
- package/src/providers/registry/model-seeds.ts +42 -0
- package/src/providers/resolved-model-policy-merge.ts +8 -0
- package/src/providers/resolved-model-policy.ts +185 -165
- package/src/providers/slug-codec.ts +5 -0
- package/src/server/chat-native-eligibility.ts +5 -0
- package/src/server/credential-recovery-attempt.ts +2 -2
- package/src/server/gemini-inbound.ts +15 -11
- package/src/server/gemini-native-catalog.ts +27 -2
- package/src/server/gemini-native-wire.ts +71 -6
- package/src/server/gemini-native.ts +129 -34
- package/src/server/index/gemini-routes.ts +6 -1
- package/src/server/lifecycle.ts +2 -1
- package/src/server/management/agent-settings-routes.ts +26 -28
- package/src/server/management/api-access.ts +5 -3
- package/src/server/management/protocol-routes.ts +3 -1
- package/src/server/management/protocol-settings-patch.ts +25 -10
- package/src/server/management/shared.ts +20 -5
- package/src/server/messages-native-eligibility.ts +4 -0
- package/src/server/messages-native-tool-guard.ts +18 -5
- package/src/server/request-log-generation-window.ts +7 -2
- package/src/server/responses/command-code-decision-refusal.ts +24 -0
- package/src/server/responses/compact.ts +2 -2
- package/src/server/responses/core-combo.ts +18 -3
- package/src/server/responses/core-pipeline.ts +6 -0
- package/src/server/responses/sidecar-execution.ts +10 -7
- package/src/types/config.ts +2 -0
- package/src/usage/expected-prices.ts +17 -0
- package/src/usage/telemetry-contract.ts +3 -0
- package/gui/dist/assets/App-BI8LQ7Qk.css +0 -1
- package/gui/dist/assets/App-CsZ1Gr7S.js +0 -60
- package/gui/dist/assets/brand-mark-BebhnAtV.js +0 -1
- package/gui/dist/assets/index-BtwVlpeQ.css +0 -2
- package/gui/dist/assets/index-CEeMegqE.js +0 -138
- package/gui/dist/classic/assets/App-BJgUWNJ8.js +0 -59
- package/gui/dist/classic/assets/App-CoiVLRW3.css +0 -1
- package/gui/dist/classic/assets/index-B9Jgli_W.js +0 -138
- package/gui/dist/classic/assets/usage-companion-chart-vbzDcND0.js +0 -1
|
@@ -1,11 +1,46 @@
|
|
|
1
|
+
import { usageFromGemini } from "../adapters/google-usage";
|
|
2
|
+
import type { OcxUsage } from "../types";
|
|
3
|
+
|
|
1
4
|
/** Gemini payloads remain source text: parsing is validation, never serialization. */
|
|
2
5
|
export const GEMINI_NATIVE_MAX_BYTES = 16 * 1024 * 1024;
|
|
3
6
|
export const GEMINI_NATIVE_ERROR_CODE = "gemini_native_upstream_error";
|
|
4
7
|
const SAFE_UPSTREAM_ERROR = '{"error":{"code":502,"message":"Antigravity upstream rejected the request","status":"INTERNAL"}}';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
function jsonObject(value: unknown): Record<string, unknown> | undefined {
|
|
10
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validateGeminiObject(raw: string): Record<string, unknown> {
|
|
14
|
+
const object = jsonObject(JSON.parse(raw));
|
|
15
|
+
if (!object) throw new Error("expected a JSON object");
|
|
16
|
+
return object;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const GEMINI_THINKING_LEVEL = /^(minimal|low|medium|high|xhigh)$/i;
|
|
20
|
+
const ANTIGRAVITY_WIRE_EFFORT = /-(low|medium|high|xhigh)$/;
|
|
21
|
+
|
|
22
|
+
/** Capture only reasoning values sent on the wire, without rewriting the request. */
|
|
23
|
+
export function geminiNativeReasoningFields(body: Record<string, unknown>, model: string) {
|
|
24
|
+
const wireEffort = ANTIGRAVITY_WIRE_EFFORT.exec(model)?.[1];
|
|
25
|
+
const generation = jsonObject(body.generationConfig ?? body.generation_config);
|
|
26
|
+
const thinking = jsonObject(generation?.thinkingConfig ?? generation?.thinking_config);
|
|
27
|
+
const level = thinking?.thinkingLevel ?? thinking?.thinking_level;
|
|
28
|
+
if (typeof level === "string" && GEMINI_THINKING_LEVEL.test(level)) {
|
|
29
|
+
const requestedEffort = level.toLowerCase();
|
|
30
|
+
return {
|
|
31
|
+
requestedEffort, effectiveEffort: wireEffort ?? requestedEffort,
|
|
32
|
+
reasoningWireField: "thinkingLevel", reasoningWireValue: level,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const budget = thinking?.thinkingBudget ?? thinking?.thinking_budget;
|
|
36
|
+
if (level === undefined && typeof budget === "number" && Number.isSafeInteger(budget) && budget >= -1) {
|
|
37
|
+
return {
|
|
38
|
+
requestedEffort: budget === -1 ? "auto" : budget === 0 ? "none" : String(budget),
|
|
39
|
+
effectiveEffort: wireEffort,
|
|
40
|
+
reasoningWireField: "thinkingBudget", reasoningWireValue: budget === -1 ? "-1" : budget,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return { effectiveEffort: wireEffort };
|
|
9
44
|
}
|
|
10
45
|
|
|
11
46
|
/** Find a top-level member's original value, including exact numeric/string spelling. */
|
|
@@ -74,10 +109,16 @@ export function wrapGeminiRequest(raw: string, model: string, project: string):
|
|
|
74
109
|
return `${envelope.slice(0, -1)},"request":${raw}}`;
|
|
75
110
|
}
|
|
76
111
|
|
|
112
|
+
interface GeminiStreamObservers {
|
|
113
|
+
onNativeError?: () => void;
|
|
114
|
+
onUsage?: (usage: OcxUsage) => void;
|
|
115
|
+
onOutput?: (visible: boolean, thought: boolean) => void;
|
|
116
|
+
}
|
|
117
|
+
|
|
77
118
|
/** Decode bounded upstream SSE events and frame the unwrapped JSON for the client. */
|
|
78
119
|
export function geminiSseTransform(
|
|
79
120
|
maxBytes = GEMINI_NATIVE_MAX_BYTES,
|
|
80
|
-
|
|
121
|
+
observers?: GeminiStreamObservers,
|
|
81
122
|
format: "sse" | "array" = "sse",
|
|
82
123
|
credentials: readonly string[] = [],
|
|
83
124
|
): TransformStream<Uint8Array, Uint8Array> {
|
|
@@ -86,25 +127,47 @@ export function geminiSseTransform(
|
|
|
86
127
|
let lineParts: string[] = [], data: string[] = [], eventBytes = 0, afterCR = false;
|
|
87
128
|
const candidates = new Map<number, boolean>();
|
|
88
129
|
let terminal = false, blocked = false, arrayOpened = false;
|
|
130
|
+
let usage: OcxUsage | undefined;
|
|
131
|
+
const reportUsage = () => {
|
|
132
|
+
if (!usage) return;
|
|
133
|
+
try { observers?.onUsage?.(usage); } catch { /* Observational callbacks never change delivery. */ }
|
|
134
|
+
};
|
|
89
135
|
const complete = () => candidates.size ? [...candidates.values()].every(Boolean) : blocked;
|
|
90
136
|
const closeArray = (controller: TransformStreamDefaultController<Uint8Array>) => {
|
|
91
137
|
if (format === "array") controller.enqueue(encoder.encode("\n]"));
|
|
92
138
|
};
|
|
93
139
|
function observe(raw: string) {
|
|
94
|
-
const value = JSON.parse(raw) as {
|
|
140
|
+
const value = JSON.parse(raw) as {
|
|
141
|
+
candidates?: Array<{ index?: number; finishReason?: string; content?: { parts?: unknown } }>;
|
|
142
|
+
promptFeedback?: { blockReason?: string };
|
|
143
|
+
usageMetadata?: unknown;
|
|
144
|
+
};
|
|
95
145
|
if (Object.hasOwn(value, "error") || containsGeminiCredential(raw, credentials)) {
|
|
96
146
|
terminal = true;
|
|
97
|
-
try { onNativeError?.(); } catch { /* Observational callbacks never change delivery. */ }
|
|
147
|
+
try { observers?.onNativeError?.(); } catch { /* Observational callbacks never change delivery. */ }
|
|
98
148
|
return SAFE_UPSTREAM_ERROR;
|
|
99
149
|
}
|
|
100
150
|
blocked ||= !!value.promptFeedback?.blockReason;
|
|
101
151
|
if (value.candidates !== undefined && !Array.isArray(value.candidates)) throw new Error("invalid Gemini candidates");
|
|
152
|
+
let visible = false, thought = false;
|
|
102
153
|
for (const [position, candidate] of (value.candidates ?? []).entries()) {
|
|
103
154
|
if (!candidate || typeof candidate !== "object") throw new Error("invalid Gemini candidate");
|
|
104
155
|
const index = candidate.index ?? position;
|
|
105
156
|
if (!Number.isSafeInteger(index) || index < 0 || candidates.size >= 1024 && !candidates.has(index)) throw new Error("invalid Gemini candidate index");
|
|
106
157
|
candidates.set(index, candidates.get(index) === true || typeof candidate.finishReason === "string" && candidate.finishReason.length > 0);
|
|
158
|
+
if (observers?.onOutput && Array.isArray(candidate.content?.parts)) {
|
|
159
|
+
for (const rawPart of candidate.content.parts) {
|
|
160
|
+
const part = jsonObject(rawPart);
|
|
161
|
+
if (!part || !(typeof part.text === "string" && part.text.length > 0) && !jsonObject(part.functionCall ?? part.function_call)) continue;
|
|
162
|
+
if (part.thought === true) thought = true;
|
|
163
|
+
else visible = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (visible || thought) {
|
|
168
|
+
try { observers?.onOutput?.(visible, thought); } catch { /* Observational callbacks never change delivery. */ }
|
|
107
169
|
}
|
|
170
|
+
if (observers?.onUsage) usage = usageFromGemini(value.usageMetadata) ?? usage;
|
|
108
171
|
return raw;
|
|
109
172
|
}
|
|
110
173
|
function emit(controller: TransformStreamDefaultController<Uint8Array>) {
|
|
@@ -112,6 +175,7 @@ export function geminiSseTransform(
|
|
|
112
175
|
const payload = data.join("\n");
|
|
113
176
|
if (payload.trim() === "[DONE]") {
|
|
114
177
|
if (!complete()) throw new Error("premature Gemini stream terminator");
|
|
178
|
+
reportUsage();
|
|
115
179
|
terminal = true;
|
|
116
180
|
} else {
|
|
117
181
|
const response = observe(unwrapGeminiResponse(payload));
|
|
@@ -168,6 +232,7 @@ export function geminiSseTransform(
|
|
|
168
232
|
if (tail) lineParts.push(tail);
|
|
169
233
|
if (lineParts.join("").trim() || data.length) throw new Error("truncated Gemini SSE event");
|
|
170
234
|
if (!complete()) throw new Error("incomplete Gemini generation");
|
|
235
|
+
reportUsage();
|
|
171
236
|
closeArray(controller);
|
|
172
237
|
},
|
|
173
238
|
});
|
|
@@ -1,68 +1,87 @@
|
|
|
1
|
-
import type { OcxConfig } from "../types";
|
|
1
|
+
import type { OcxConfig, OcxUsage } from "../types";
|
|
2
|
+
import { markNativeGeminiProtocol } from "../protocols/trace";
|
|
2
3
|
import { getValidAccessSnapshotForAccount, forceRefreshOAuthAccessSnapshot, OAuthLoginRequiredError, OAuthAccountPausedError, OAuthTokenRefreshBusyError, OAuthTokenRefreshStaleError, type OAuthAccessSnapshot } from "../oauth";
|
|
3
4
|
import { getAccountSet, getAccountCredentialWithStatus } from "../oauth/store";
|
|
5
|
+
import {
|
|
6
|
+
antigravityModelRefusal, isProactivePreferenceEnabled, noteGenericPoolSelection, preferredInitialAccount, routeAntigravityModel,
|
|
7
|
+
} from "../oauth/generic-account-failover";
|
|
8
|
+
import { stampOAuthAccountLabel } from "../providers/label";
|
|
4
9
|
import { getProviderRegistryEntry } from "../providers/registry";
|
|
5
10
|
import { sendTrackingRequestSlot, waitForProviderRequestSlot, RequestPacingQueueOverloadError, RequestPacingProviderRemovedError } from "../providers/request-pacing";
|
|
11
|
+
import { usageFromGemini } from "../adapters/google-usage";
|
|
6
12
|
import { antigravityUserAgentForWireModel } from "../adapters/google-antigravity-wire";
|
|
7
13
|
import { fetchWithAttemptDeadline, releaseResponseBodyBestEffort } from "../lib/upstream-retry";
|
|
8
14
|
import { reserveWorkflowSend } from "../lib/workflow-budget";
|
|
9
15
|
import { currentWorkflowBudgetPolicy } from "../lib/workflow-budget-config";
|
|
10
16
|
import { spendPolicyFromConfig } from "../lib/spend-reservation-ledger";
|
|
11
17
|
import { carryWorkflowRefusal, workflowRefusalResponse } from "./workflow-refusal";
|
|
12
|
-
import { geminiErrorBody } from "./gemini-inbound";
|
|
13
|
-
import
|
|
18
|
+
import { geminiErrorBody, toGeminiRefusal } from "./gemini-inbound";
|
|
19
|
+
import { estimateTokens } from "../lib/token-estimate";
|
|
20
|
+
import { createPhysicalSendReporter } from "../lib/request-execution-budget";
|
|
21
|
+
import { createInferenceSendBudget } from "./inference/context";
|
|
22
|
+
import { attachRequestSpendTracker } from "./responses/request-spend";
|
|
23
|
+
import { markLocalRequestLogRefusal, type RequestLogContext } from "./request-log";
|
|
24
|
+
import { recordGenerationOutput } from "./request-log-generation-window";
|
|
25
|
+
import { noteCredentialAttemptSend, sealCredentialRefusal } from "./credential-recovery-attempt";
|
|
14
26
|
import { DEFAULT_STALL_TIMEOUT_SEC, resolveStallTimeoutMs } from "../stall-timeout";
|
|
15
27
|
import { isLocalUpstream } from "../lib/local-upstream";
|
|
16
28
|
import { assertProviderDestinationAllowed } from "../lib/destination-policy";
|
|
29
|
+
import { clientFacingModelLabel, type ClientFacingModelLabel } from "../lib/error-destination";
|
|
17
30
|
import { registerTurn, unregisterTurn, type ActiveTurnLease } from "./lifecycle";
|
|
18
|
-
import { containsGeminiCredential, geminiSseTransform, readGeminiText, validateGeminiObject, GEMINI_NATIVE_MAX_BYTES, GEMINI_NATIVE_ERROR_CODE, unwrapGeminiResponse, wrapGeminiRequest } from "./gemini-native-wire";
|
|
31
|
+
import { containsGeminiCredential, geminiNativeReasoningFields, geminiSseTransform, readGeminiText, validateGeminiObject, GEMINI_NATIVE_MAX_BYTES, GEMINI_NATIVE_ERROR_CODE, unwrapGeminiResponse, wrapGeminiRequest } from "./gemini-native-wire";
|
|
19
32
|
|
|
20
33
|
export const GEMINI_NATIVE_PROVIDER = "google-antigravity";
|
|
21
34
|
class NativeWorkflowSendDenied extends Error {}
|
|
22
|
-
class NativeSpendLimitsUnsupported extends Error {}
|
|
23
35
|
class NativeRequestBodyTimeout extends Error {}
|
|
24
36
|
class NativeConfigurationInvalid extends Error {}
|
|
37
|
+
class NativeModelUnavailable extends Error {}
|
|
25
38
|
export function geminiNativeError(status: number, message: string, reason?: string): Response {
|
|
26
39
|
const { error } = geminiErrorBody(status, message);
|
|
27
40
|
return Response.json({ error: { ...error, ...(reason ? { details: [{ reason }] } : {}) } }, { status });
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
export interface GeminiNativeDeps {
|
|
31
|
-
access: () => Promise<OAuthAccessSnapshot>;
|
|
44
|
+
access: (config: OcxConfig, model: string, clientModel: ClientFacingModelLabel) => Promise<OAuthAccessSnapshot>;
|
|
32
45
|
refresh: (snapshot: OAuthAccessSnapshot) => Promise<OAuthAccessSnapshot>;
|
|
33
46
|
fetch: typeof globalThis.fetch;
|
|
34
47
|
}
|
|
35
48
|
const defaults: Omit<GeminiNativeDeps, "fetch"> = {
|
|
36
|
-
access: async () => {
|
|
49
|
+
access: async (config, model, clientModel) => {
|
|
37
50
|
const set = getAccountSet(GEMINI_NATIVE_PROVIDER);
|
|
38
51
|
if (!set) throw new OAuthLoginRequiredError(GEMINI_NATIVE_PROVIDER);
|
|
39
|
-
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
const planned = preferredInitialAccount(config, GEMINI_NATIVE_PROVIDER, now, model) ?? set.activeAccountId;
|
|
54
|
+
const route = routeAntigravityModel(config, GEMINI_NATIVE_PROVIDER, planned, model, now, clientModel);
|
|
55
|
+
if (route.kind === "refuse") throw new NativeModelUnavailable(route.message);
|
|
56
|
+
const accountId = route.kind === "reroute" ? route.accountId : planned;
|
|
57
|
+
return getValidAccessSnapshotForAccount(GEMINI_NATIVE_PROVIDER, accountId, { requireUsableAccount: true });
|
|
40
58
|
}, refresh: forceRefreshOAuthAccessSnapshot,
|
|
41
59
|
};
|
|
42
60
|
|
|
43
|
-
/**
|
|
61
|
+
/** Native leg using an account-scoped Antigravity token and project. */
|
|
44
62
|
export async function handleGeminiNative(
|
|
45
63
|
req: Request, config: OcxConfig, model: string, streamFormat: "sse" | "array" | undefined,
|
|
46
|
-
lease: ActiveTurnLease, deps: GeminiNativeDeps = { ...defaults, fetch: globalThis.fetch }, logCtx?: RequestLogContext,
|
|
64
|
+
lease: ActiveTurnLease, deps: GeminiNativeDeps = { ...defaults, fetch: globalThis.fetch }, logCtx?: RequestLogContext, start?: number,
|
|
47
65
|
): Promise<Response> {
|
|
48
66
|
const rootId = req.headers.get("x-codex-parent-thread-id")?.trim() || undefined;
|
|
49
|
-
|
|
50
|
-
// ceilings rather than allowing an unmeasured request to escape the common ledger.
|
|
51
|
-
const spendUnsupported = () => {
|
|
67
|
+
if (!logCtx) {
|
|
52
68
|
const policy = spendPolicyFromConfig(config.spend);
|
|
53
|
-
|
|
54
|
-
|| rootId !== undefined && policy.root.maxTokens !== undefined
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"gemini_native_spend_limits_unsupported");
|
|
59
|
-
if (spendUnsupported()) return unsupportedSpend();
|
|
69
|
+
if (policy.identity.maxTokens !== undefined || policy.pool.maxTokens !== undefined
|
|
70
|
+
|| (rootId !== undefined && policy.root.maxTokens !== undefined)) {
|
|
71
|
+
return geminiNativeError(503, "Token budget accounting is unavailable for this request");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
60
74
|
const provider = config.providers[GEMINI_NATIVE_PROVIDER];
|
|
61
75
|
if (!provider || provider.disabled === true) return geminiNativeError(503, "Enable google-antigravity and sign in before using Gemini native requests");
|
|
62
76
|
if (provider.adapter !== "google" || (provider.authMode && provider.authMode !== "oauth") || (provider.googleMode && provider.googleMode !== "cloud-code-assist")) {
|
|
63
77
|
return geminiNativeError(503, "Gemini native requests require a Google Antigravity OAuth provider");
|
|
64
78
|
}
|
|
65
79
|
if (req.headers.get("content-encoding") && req.headers.get("content-encoding") !== "identity") return geminiNativeError(415, "Gemini native requests require identity content encoding");
|
|
80
|
+
// Native admission accepts the canonical provider's implicit OAuth mode. Account helpers
|
|
81
|
+
// require an explicit mode, so give them the same default without changing saved settings.
|
|
82
|
+
const accountConfig: OcxConfig = provider.authMode === undefined ? {
|
|
83
|
+
...config, providers: { ...config.providers, [GEMINI_NATIVE_PROVIDER]: { ...provider, authMode: "oauth" } },
|
|
84
|
+
} : config;
|
|
66
85
|
const ac = new AbortController();
|
|
67
86
|
const onAbort = () => ac.abort(req.signal.reason);
|
|
68
87
|
req.signal.addEventListener("abort", onAbort, { once: true });
|
|
@@ -89,6 +108,23 @@ export async function handleGeminiNative(
|
|
|
89
108
|
const noteNativeError = () => {
|
|
90
109
|
if (logCtx) { logCtx.errorCode = GEMINI_NATIVE_ERROR_CODE; logCtx.terminalSource = "upstream"; }
|
|
91
110
|
};
|
|
111
|
+
let sawThoughtOutput = false;
|
|
112
|
+
const noteUsage = logCtx ? (usage: OcxUsage) => {
|
|
113
|
+
logCtx.usage = usage;
|
|
114
|
+
// Reported thought tokens count in the numerator. Their generation must also be observed.
|
|
115
|
+
if (usage.reasoningOutputTokens && !sawThoughtOutput) {
|
|
116
|
+
delete logCtx.generationStartedAt;
|
|
117
|
+
delete logCtx.lastOutputAt;
|
|
118
|
+
}
|
|
119
|
+
} : undefined;
|
|
120
|
+
const noteOutput = logCtx && start !== undefined ? (visible: boolean, thought: boolean) => {
|
|
121
|
+
const now = Date.now();
|
|
122
|
+
sawThoughtOutput ||= thought;
|
|
123
|
+
recordGenerationOutput(logCtx, now);
|
|
124
|
+
if (visible) logCtx.firstOutputMs ??= Math.max(0, now - start);
|
|
125
|
+
} : undefined;
|
|
126
|
+
const spendTracker = logCtx ? attachRequestSpendTracker(req, logCtx) : undefined;
|
|
127
|
+
const physicalBudget = logCtx ? createInferenceSendBudget(req, logCtx) : undefined;
|
|
92
128
|
let upstream: Response | undefined;
|
|
93
129
|
try {
|
|
94
130
|
const maxBytes = Math.min(GEMINI_NATIVE_MAX_BYTES, config.maxInboundBodyBytes ?? GEMINI_NATIVE_MAX_BYTES);
|
|
@@ -110,9 +146,25 @@ export async function handleGeminiNative(
|
|
|
110
146
|
finish(); return geminiNativeError(400, "Gemini request body must be readable UTF-8 JSON");
|
|
111
147
|
} finally { clearTimeout(bodyReadTimer); bodyReadTimer = undefined; }
|
|
112
148
|
if (raw === null) { finish(); return geminiNativeError(413, "Gemini native request exceeds the body limit"); }
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
149
|
+
let reasoning: ReturnType<typeof geminiNativeReasoningFields> | undefined;
|
|
150
|
+
try {
|
|
151
|
+
const payload = validateGeminiObject(raw);
|
|
152
|
+
if (logCtx) {
|
|
153
|
+
reasoning = geminiNativeReasoningFields(payload, model);
|
|
154
|
+
const generation = (payload.generationConfig ?? payload.generation_config) as Record<string, unknown> | undefined;
|
|
155
|
+
const maxOutput = generation?.maxOutputTokens ?? generation?.max_output_tokens;
|
|
156
|
+
const candidates = generation?.candidateCount ?? generation?.candidate_count;
|
|
157
|
+
const candidateCount = typeof candidates === "number" && Number.isSafeInteger(candidates) && candidates > 0 ? candidates : 1;
|
|
158
|
+
// Measure the native JSON for reservation only. Usage comes from the upstream response.
|
|
159
|
+
logCtx.spendInputEstimateTokens = estimateTokens(raw, model);
|
|
160
|
+
if (typeof maxOutput === "number" && Number.isSafeInteger(maxOutput) && maxOutput > 0) {
|
|
161
|
+
logCtx.spendOutputCeilingTokens = Math.min(Number.MAX_SAFE_INTEGER, maxOutput * candidateCount);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} catch { finish(); return geminiNativeError(400, "Expected a Gemini JSON object"); }
|
|
165
|
+
ac.signal.throwIfAborted();
|
|
166
|
+
const clientModel = clientFacingModelLabel(logCtx?.requestedModel ?? model);
|
|
167
|
+
let access = await deps.access(accountConfig, model, clientModel);
|
|
116
168
|
const boundCredentials = new Set<string>();
|
|
117
169
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
118
170
|
ac.signal.throwIfAborted();
|
|
@@ -124,34 +176,61 @@ export async function handleGeminiNative(
|
|
|
124
176
|
} catch { throw new NativeConfigurationInvalid(); }
|
|
125
177
|
const method = streamFormat ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
126
178
|
const slot = await waitForProviderRequestSlot(GEMINI_NATIVE_PROVIDER, provider, model, ac.signal);
|
|
127
|
-
upstream = await sendTrackingRequestSlot(slot, () => {
|
|
179
|
+
upstream = await sendTrackingRequestSlot(slot, async () => {
|
|
128
180
|
ac.signal.throwIfAborted();
|
|
129
181
|
// A pacing wait must not outlive an operator pause, reauth mark or account removal.
|
|
130
182
|
const account = getAccountCredentialWithStatus(GEMINI_NATIVE_PROVIDER, access.accountId);
|
|
131
183
|
if (!account) throw new OAuthLoginRequiredError(GEMINI_NATIVE_PROVIDER);
|
|
132
184
|
if (account.paused) throw new OAuthAccountPausedError();
|
|
133
185
|
if (account.needsReauth) throw new OAuthLoginRequiredError(GEMINI_NATIVE_PROVIDER);
|
|
134
|
-
|
|
135
|
-
if (
|
|
186
|
+
const refusal = antigravityModelRefusal(accountConfig, GEMINI_NATIVE_PROVIDER, access.accountId, model, undefined, clientModel);
|
|
187
|
+
if (refusal) throw new NativeModelUnavailable(refusal);
|
|
136
188
|
const { credential } = account;
|
|
137
189
|
// Keep both generations across a 401 recovery. The store can also rotate during pacing.
|
|
138
190
|
for (const value of [access.accessToken, access.projectId, access.accountId, credential.access,
|
|
139
191
|
credential.refresh, credential.projectId, credential.accountId, credential.email]) {
|
|
140
192
|
if (value) boundCredentials.add(value);
|
|
141
193
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
194
|
+
const body = wrapGeminiRequest(raw, model, access.projectId!);
|
|
195
|
+
if (logCtx) stampOAuthAccountLabel(logCtx, GEMINI_NATIVE_PROVIDER, { authMode: "oauth" }, access.accountId);
|
|
196
|
+
const report = physicalBudget && createPhysicalSendReporter(physicalBudget, () => ({
|
|
197
|
+
poolId: GEMINI_NATIVE_PROVIDER, identityId: logCtx?.accountLogLabel,
|
|
198
|
+
}));
|
|
199
|
+
let dispatched = false;
|
|
200
|
+
try {
|
|
201
|
+
if (report ? !report.beforeSend?.(attempt > 0) : !reserveWorkflowSend(rootId, currentWorkflowBudgetPolicy())) {
|
|
202
|
+
throw new NativeWorkflowSendDenied();
|
|
203
|
+
}
|
|
204
|
+
if (attempt === 0 && isProactivePreferenceEnabled(accountConfig, GEMINI_NATIVE_PROVIDER, Date.now())) {
|
|
205
|
+
noteGenericPoolSelection(accountConfig, GEMINI_NATIVE_PROVIDER, access.accountId, model);
|
|
206
|
+
}
|
|
207
|
+
if (logCtx) {
|
|
208
|
+
Object.assign(logCtx, reasoning);
|
|
209
|
+
markNativeGeminiProtocol(logCtx);
|
|
210
|
+
noteCredentialAttemptSend(logCtx, { providerName: GEMINI_NATIVE_PROVIDER, modelId: model }, provider,
|
|
211
|
+
attempt === 0 ? undefined : "oauth-401");
|
|
212
|
+
Object.assign(logCtx.activeAttempt!, reasoning);
|
|
213
|
+
}
|
|
214
|
+
dispatched = true;
|
|
215
|
+
return await fetchWithAttemptDeadline(`${baseUrl.replace(/\/$/, "")}/v1internal:${method}`, {
|
|
216
|
+
method: "POST",
|
|
217
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${access.accessToken}`, "User-Agent": antigravityUserAgentForWireModel(model) },
|
|
218
|
+
body,
|
|
219
|
+
}, config.connectTimeoutMs ?? 200_000, ac.signal, true, deps.fetch);
|
|
220
|
+
} finally {
|
|
221
|
+
try { if (dispatched) report?.(1); }
|
|
222
|
+
finally { report?.close?.(); }
|
|
223
|
+
}
|
|
147
224
|
});
|
|
148
225
|
if (upstream.status !== 401 || attempt === 1) break;
|
|
226
|
+
if (logCtx) sealCredentialRefusal(logCtx, 401, "oauth-401");
|
|
149
227
|
await releaseResponseBodyBestEffort(upstream.body, ac.signal);
|
|
150
228
|
ac.signal.throwIfAborted();
|
|
151
229
|
access = await deps.refresh(access);
|
|
152
230
|
}
|
|
153
231
|
if (!upstream) throw new Error("missing upstream response");
|
|
154
232
|
if (!upstream.ok) {
|
|
233
|
+
if (logCtx) logCtx.terminalSource = "upstream";
|
|
155
234
|
void upstream.body?.cancel().catch(() => {});
|
|
156
235
|
finish();
|
|
157
236
|
const response = geminiNativeError(upstream.status >= 400 ? upstream.status : 502, "Antigravity upstream rejected the request");
|
|
@@ -179,15 +258,20 @@ export async function handleGeminiNative(
|
|
|
179
258
|
const credentials = [...boundCredentials];
|
|
180
259
|
if (streamFormat) {
|
|
181
260
|
const headers = { "Content-Type": streamFormat === "sse" ? "text/event-stream" : "application/json", "Cache-Control": "no-cache" };
|
|
182
|
-
return new Response(body.pipeThrough(geminiSseTransform(
|
|
261
|
+
return new Response(body.pipeThrough(geminiSseTransform(
|
|
262
|
+
GEMINI_NATIVE_MAX_BYTES, { onNativeError: noteNativeError, onUsage: noteUsage, onOutput: noteOutput }, streamFormat, credentials,
|
|
263
|
+
)), { headers });
|
|
183
264
|
}
|
|
184
265
|
const text = await readGeminiText(body, GEMINI_NATIVE_MAX_BYTES, ac.signal);
|
|
185
266
|
if (text === null) return geminiNativeError(502, "Gemini upstream response exceeds the body limit");
|
|
186
267
|
const response = unwrapGeminiResponse(text);
|
|
187
|
-
|
|
268
|
+
const payload = JSON.parse(response) as { usageMetadata?: unknown };
|
|
269
|
+
if (Object.hasOwn(payload, "error") || containsGeminiCredential(response, credentials)) {
|
|
188
270
|
noteNativeError();
|
|
189
271
|
return geminiNativeError(502, "Antigravity upstream rejected the request");
|
|
190
272
|
}
|
|
273
|
+
const usage = usageFromGemini(payload.usageMetadata);
|
|
274
|
+
if (usage) noteUsage?.(usage);
|
|
191
275
|
return new Response(response, { headers: { "Content-Type": "application/json" } });
|
|
192
276
|
} catch (error) {
|
|
193
277
|
ac.abort(); finish();
|
|
@@ -208,8 +292,19 @@ export async function handleGeminiNative(
|
|
|
208
292
|
if (error instanceof RequestPacingProviderRemovedError || error instanceof NativeConfigurationInvalid) {
|
|
209
293
|
return geminiNativeError(503, "Antigravity provider configuration is unavailable or invalid; check its baseUrl and destination policy in OC settings");
|
|
210
294
|
}
|
|
211
|
-
if (error instanceof
|
|
295
|
+
if (error instanceof NativeModelUnavailable) {
|
|
296
|
+
if (logCtx) {
|
|
297
|
+
logCtx.errorCode = "gemini_native_model_unlisted";
|
|
298
|
+
markLocalRequestLogRefusal(logCtx, "gemini_native_model_unlisted");
|
|
299
|
+
}
|
|
300
|
+
return geminiNativeError(403, error.message, "gemini_native_model_unlisted");
|
|
301
|
+
}
|
|
212
302
|
if (error instanceof NativeWorkflowSendDenied) {
|
|
303
|
+
const denial = spendTracker?.lastRefusal;
|
|
304
|
+
if (denial) {
|
|
305
|
+
const refusal = workflowRefusalResponse(denial.reason, logCtx, undefined, undefined, denial.spend);
|
|
306
|
+
return carryWorkflowRefusal(refusal, toGeminiRefusal(refusal));
|
|
307
|
+
}
|
|
213
308
|
const refusal = workflowRefusalResponse("workflow-sends-exhausted", logCtx, undefined, rootId);
|
|
214
309
|
return carryWorkflowRefusal(refusal, geminiNativeError(429, "OpenCodex workflow physical-send budget exhausted"));
|
|
215
310
|
}
|
|
@@ -15,6 +15,7 @@ import { SIDECAR_INTERNAL_CAPABILITY_HEADER } from "../advisor-admission-scope";
|
|
|
15
15
|
import { withCallerSessionIdentity } from "../caller-session-identity";
|
|
16
16
|
import { captureAdmissionPolicy } from "../capture-admission-policy";
|
|
17
17
|
import { isDraining } from "../lifecycle";
|
|
18
|
+
import { resolveGeminiApiSurface } from "../../protocols/settings";
|
|
18
19
|
import { geminiRouteAllowHeader, geminiRouteAllows, parseGeminiNativePath, type GeminiNativeRoute } from "../gemini-native-paths";
|
|
19
20
|
import { geminiError, handleGeminiCountTokens, handleGeminiGeneration, handleGeminiModel, handleGeminiModels, toGeminiRefusal } from "../gemini-inbound";
|
|
20
21
|
import { handleGeminiInteraction, handleGeminiInteractionResource } from "../gemini-interactions-inbound";
|
|
@@ -62,6 +63,9 @@ async function handleGeminiRoute(route: GeminiNativeRoute, original: Request, ur
|
|
|
62
63
|
refused.headers.set("Allow", geminiRouteAllowHeader(route));
|
|
63
64
|
return withCors(refused, original, policy);
|
|
64
65
|
}
|
|
66
|
+
if (!resolveGeminiApiSurface(config).enabled) {
|
|
67
|
+
return withCors(geminiError(403, "Gemini API is disabled"), original, policy);
|
|
68
|
+
}
|
|
65
69
|
const generation = route.kind === "interactions"
|
|
66
70
|
|| (route.kind === "method" && (route.method === "generateContent" || route.method === "streamGenerateContent"));
|
|
67
71
|
if (generation) disableResponsesRequestTimeout(original, deps.requestServer);
|
|
@@ -126,8 +130,9 @@ async function handleGeminiRoute(route: GeminiNativeRoute, original: Request, ur
|
|
|
126
130
|
} else {
|
|
127
131
|
logCtx.model = native.route.modelId;
|
|
128
132
|
logCtx.provider = native.route.providerName;
|
|
133
|
+
logCtx.routeDecision = native.route.routeDecision;
|
|
129
134
|
const delivery = route.method === "streamGenerateContent" ? (sse ? "sse" : "array") : undefined;
|
|
130
|
-
result = await handleGeminiNative(sessionReq, config, native.wireModel, delivery, turnAdmissionLease, undefined, logCtx);
|
|
135
|
+
result = await handleGeminiNative(sessionReq, config, native.wireModel, delivery, turnAdmissionLease, undefined, logCtx, start);
|
|
131
136
|
}
|
|
132
137
|
return withCors(logGeminiNativeDelivery(result, sessionReq, requestId, start, logCtx), original, policy);
|
|
133
138
|
}
|
package/src/server/lifecycle.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { abortRestoreTrashJobAsync } from "../storage/restore-job";
|
|
10
10
|
import { stopStorageCleanupScheduler } from "../storage/policy-scheduler";
|
|
11
11
|
import { runDrainStartHooks, runOptionalShutdownHooks } from "../lib/optional-shutdown-hooks";
|
|
12
|
+
import { OPTIONAL_SHUTDOWN_GRACE_MS } from "../lib/shutdown-budget";
|
|
12
13
|
import { stopStateStoreSweeper } from "../lib/state-store-sweeper";
|
|
13
14
|
import {
|
|
14
15
|
cancelQueuedStorageWorkerSpawns,
|
|
@@ -575,7 +576,7 @@ export async function drainAndShutdown(
|
|
|
575
576
|
// Optional subsystems (Compatibility Lab today, anything added later) tear themselves
|
|
576
577
|
// down through hooks registered at activation. A process that never activated one runs
|
|
577
578
|
// nothing here and never loads its module graph.
|
|
578
|
-
runOptionalShutdownHooks();
|
|
579
|
+
if (!(await runOptionalShutdownHooks({ deadlineMs: deadline + OPTIONAL_SHUTDOWN_GRACE_MS }))) shutdownSucceeded = false;
|
|
579
580
|
stopStateStoreSweeper();
|
|
580
581
|
// The overlay reconciler is owner-scoped: the startServer stop override
|
|
581
582
|
// releases THIS server's lease through runListenerShutdown →
|
|
@@ -55,7 +55,7 @@ import { providerDestinationResolvedError } from "../../lib/destination-policy";
|
|
|
55
55
|
import { enrichProviderFromCatalog, listKeyLoginProviders } from "../../oauth/key-providers";
|
|
56
56
|
import { deriveProviderPresets } from "../../providers/derive";
|
|
57
57
|
import { providerCodexAccountMode } from "../../providers/registry";
|
|
58
|
-
import { routedSlug, slugEquals } from "../../providers/slug-codec";
|
|
58
|
+
import { hasRoutedSlug, routedSlug, slugEquals } from "../../providers/slug-codec";
|
|
59
59
|
import { clearProviderQuotaCache, fetchProviderQuotaReports } from "../../providers/quota";
|
|
60
60
|
import { isCanonicalOpenAiForwardProvider, OPENAI_CODEX_PROVIDER_ID } from "../../providers/openai-tiers";
|
|
61
61
|
import { clearThreadAccountMap } from "../../codex/routing";
|
|
@@ -1537,35 +1537,8 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
1537
1537
|
}
|
|
1538
1538
|
if (url.pathname === "/api/claude-code" && req.method === "GET") {
|
|
1539
1539
|
const models = await fetchAllModels(config);
|
|
1540
|
-
const { listCatalogNativeSlugs } = await import("../../codex/catalog");
|
|
1541
|
-
const { claudeCodeAlias, claudeCodeNativeAlias } = await import("../../claude/alias");
|
|
1542
1540
|
const { buildClaudeContextWindows, effectiveModelEnv, nativeClaudePassthroughFor, probeClaudeCodeVersionForTierFill } = await import("../../claude/context-windows");
|
|
1543
1541
|
const { visibleNativeSlugs } = await import("../../codex/catalog");
|
|
1544
|
-
const disabled = new Set(config.disabledModels ?? []);
|
|
1545
|
-
const isDisabled = (provider: string, id: string) =>
|
|
1546
|
-
[...disabled].some(stored => slugEquals(stored, provider, id));
|
|
1547
|
-
const available = [
|
|
1548
|
-
...listCatalogNativeSlugs().filter(ns => !disabled.has(ns)),
|
|
1549
|
-
// Claude-facing values stay RAW native selectors (resolved inbound via routeModel,
|
|
1550
|
-
// which accepts the raw full-slash form); only the disabled check goes tolerant.
|
|
1551
|
-
...models.filter(m => !isDisabled(m.provider, m.id)).map(m => `${m.provider}/${m.id}`),
|
|
1552
|
-
];
|
|
1553
|
-
const aliases: { id: string; display_name: string }[] = [];
|
|
1554
|
-
// Resolved once, not per model: with the global fast switch on, Claude Code discovers the
|
|
1555
|
-
// fast identity, so the dashboard must list the same id rather than the umbrella one.
|
|
1556
|
-
const cursorFastIdFor = config.fastMode === true
|
|
1557
|
-
? (await import("../../adapters/cursor/catalog")).cursorFastIdFor
|
|
1558
|
-
: undefined;
|
|
1559
|
-
for (const slug of listCatalogNativeSlugs()) {
|
|
1560
|
-
// Readable CLI-surface alias with hash fallback (devlog 050 / audit 051 #2) —
|
|
1561
|
-
// the same shared helper the /v1/models ?ids=cli path uses.
|
|
1562
|
-
if (!disabled.has(slug)) aliases.push({ id: claudeCodeNativeAlias(slug), display_name: `${slug} (native)` });
|
|
1563
|
-
}
|
|
1564
|
-
for (const m of models) {
|
|
1565
|
-
if (isDisabled(m.provider, m.id)) continue;
|
|
1566
|
-
const listedId = (m.provider === "cursor" ? cursorFastIdFor?.(m.id) : undefined) ?? m.id;
|
|
1567
|
-
aliases.push({ id: claudeCodeAlias(m.provider, listedId), display_name: `${listedId} (${m.provider})` });
|
|
1568
|
-
}
|
|
1569
1542
|
// Auto is a RESOLUTION, recomputed per request — never stored state. Detection is
|
|
1570
1543
|
// daemon-side, so it cannot see a key exported only in the user's terminal; the
|
|
1571
1544
|
// GUI labels the badge with detectionScope for exactly that reason.
|
|
@@ -1588,6 +1561,31 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
1588
1561
|
};
|
|
1589
1562
|
// The launcher probes its own CLI. Only the dashboard snapshot needs the daemon's version.
|
|
1590
1563
|
if (url.searchParams.get("view") === "launch") return jsonResponse(launchState);
|
|
1564
|
+
const { listCatalogNativeSlugs } = await import("../../codex/catalog");
|
|
1565
|
+
const { claudeCodeAlias, claudeCodeNativeAlias } = await import("../../claude/alias");
|
|
1566
|
+
const disabled = new Set(config.disabledModels ?? []);
|
|
1567
|
+
const availableRouted = models.filter(m => !hasRoutedSlug(disabled, m.provider, m.id));
|
|
1568
|
+
const available = [
|
|
1569
|
+
...listCatalogNativeSlugs().filter(ns => !disabled.has(ns)),
|
|
1570
|
+
// Claude-facing values stay RAW native selectors (resolved inbound via routeModel,
|
|
1571
|
+
// which accepts the raw full-slash form); only the disabled check goes tolerant.
|
|
1572
|
+
...availableRouted.map(m => `${m.provider}/${m.id}`),
|
|
1573
|
+
];
|
|
1574
|
+
const aliases: { id: string; display_name: string }[] = [];
|
|
1575
|
+
// Resolved once, not per model: with the global fast switch on, Claude Code discovers the
|
|
1576
|
+
// fast identity, so the dashboard must list the same id rather than the umbrella one.
|
|
1577
|
+
const cursorFastIdFor = config.fastMode === true
|
|
1578
|
+
? (await import("../../adapters/cursor/catalog")).cursorFastIdFor
|
|
1579
|
+
: undefined;
|
|
1580
|
+
for (const slug of listCatalogNativeSlugs()) {
|
|
1581
|
+
// Readable CLI-surface alias with hash fallback (devlog 050 / audit 051 #2) —
|
|
1582
|
+
// the same shared helper the /v1/models ?ids=cli path uses.
|
|
1583
|
+
if (!disabled.has(slug)) aliases.push({ id: claudeCodeNativeAlias(slug), display_name: `${slug} (native)` });
|
|
1584
|
+
}
|
|
1585
|
+
for (const m of availableRouted) {
|
|
1586
|
+
const listedId = (m.provider === "cursor" ? cursorFastIdFor?.(m.id) : undefined) ?? m.id;
|
|
1587
|
+
aliases.push({ id: claudeCodeAlias(m.provider, listedId), display_name: `${listedId} (${m.provider})` });
|
|
1588
|
+
}
|
|
1591
1589
|
const claudeCodeVersion = await probeClaudeCodeVersionForTierFill(config.claudeCode, contextWindows);
|
|
1592
1590
|
const webSearchOverride = config.claudeCode?.webSearchSidecar;
|
|
1593
1591
|
const visionOverride = config.claudeCode?.visionSidecar;
|
|
@@ -3,7 +3,7 @@ import { isWildcardHostname } from "../../codex/loopback-target";
|
|
|
3
3
|
import { localCredentialDestinationHostname, localInferenceDestination } from "../../lib/local-destinations";
|
|
4
4
|
import { isCanonicalOpenAiForwardProvider, OPENAI_API_PROVIDER_ID, OPENAI_CODEX_PROVIDER_ID } from "../../providers/openai-tiers-destination";
|
|
5
5
|
import { LIVE_AUDIO_MODEL, TRANSCRIPTION_MODEL } from "../audio-upstream";
|
|
6
|
-
import { resolveApiSurfaceSettings, type ApiSurfaceSettings } from "../../protocols/settings";
|
|
6
|
+
import { resolveApiSurfaceSettings, resolveGeminiApiSurface, type ApiSurfaceSetting, type ApiSurfaceSettings } from "../../protocols/settings";
|
|
7
7
|
|
|
8
8
|
export interface AudioApiAccess {
|
|
9
9
|
transcriptionEndpoint: string;
|
|
@@ -24,8 +24,9 @@ export interface ApiAccessEndpoints {
|
|
|
24
24
|
chatCompletionsEndpoint: string;
|
|
25
25
|
messagesEndpoint: string;
|
|
26
26
|
modelsEndpoint: string;
|
|
27
|
+
geminiModelsEndpoint: string;
|
|
27
28
|
/** Which public APIs are served and who decided it, from `resolveApiSurfaceSettings`. */
|
|
28
|
-
surfaces: ApiSurfaceSettings;
|
|
29
|
+
surfaces: ApiSurfaceSettings & { gemini: ApiSurfaceSetting };
|
|
29
30
|
/**
|
|
30
31
|
* Back-compat for dashboards that predate `surfaces`: they hide the Messages endpoint when
|
|
31
32
|
* this is false. It mirrors `surfaces.messages.enabled`, not `claudeCode.enabled`, so an
|
|
@@ -180,7 +181,8 @@ export function buildApiAccessEndpoints(
|
|
|
180
181
|
chatCompletionsEndpoint: `${baseUrl}/chat/completions`,
|
|
181
182
|
messagesEndpoint: `${baseUrl}/messages`,
|
|
182
183
|
modelsEndpoint: `${baseUrl}/models`,
|
|
183
|
-
|
|
184
|
+
geminiModelsEndpoint: baseUrl.replace(/\/v1$/, "/v1beta/models"),
|
|
185
|
+
surfaces: { ...surfaces, gemini: resolveGeminiApiSurface(config) },
|
|
184
186
|
claudeCodeEnabled: surfaces.messages.enabled,
|
|
185
187
|
audio: {
|
|
186
188
|
transcriptionEndpoint: `${baseUrl}/audio/transcriptions`,
|
|
@@ -18,7 +18,7 @@ import { isProtocol, PROTOCOL_CONTRACT_VERSION } from "../../protocols/contract"
|
|
|
18
18
|
import { isProtocolFeature, PROTOCOL_FEATURES, type ProtocolFeature } from "../../protocols/features";
|
|
19
19
|
import { previewProtocolPlan, type ProtocolPlanRequest } from "../../protocols/plan-snapshot";
|
|
20
20
|
import { buildProtocolProviderSummary } from "../../protocols/provider-summary";
|
|
21
|
-
import { protocolPolicyRevision, resolveApiSurfaceSettings, resolveProtocolSettings } from "../../protocols/settings";
|
|
21
|
+
import { protocolPolicyRevision, resolveApiSurfaceSettings, resolveGeminiApiSurface, resolveProtocolSettings } from "../../protocols/settings";
|
|
22
22
|
import type { OcxConfig } from "../../types";
|
|
23
23
|
import type { ManagementContext } from "./context";
|
|
24
24
|
import { readManagementJsonBodyOr } from "./body";
|
|
@@ -71,6 +71,8 @@ function protocolInfo(config: OcxConfig) {
|
|
|
71
71
|
contractVersion: PROTOCOL_CONTRACT_VERSION,
|
|
72
72
|
policyRevision: protocolPolicyRevision(config),
|
|
73
73
|
surfaces: resolveApiSurfaceSettings(config),
|
|
74
|
+
// Older dashboards require exactly the three planning protocols inside surfaces.
|
|
75
|
+
geminiSurface: resolveGeminiApiSurface(config),
|
|
74
76
|
settings: resolveProtocolSettings(config),
|
|
75
77
|
features: PROTOCOL_FEATURES,
|
|
76
78
|
};
|