@bitkyc08/opencodex 2.100.3 → 2.100.4
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/AGENTS_INSTALL.md +23 -1
- package/bin/ocx.mjs +8 -1
- package/gui/dist/assets/{App-Dnb6VMsP.js → App-DcpyI78f.js} +20 -19
- package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-CzjPJprT.js} +1 -1
- package/gui/dist/assets/brand-mark-BTIi7e69.js +1 -0
- package/gui/dist/assets/index-DJxM-imn.css +2 -0
- package/gui/dist/assets/index-DVgU6S3y.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bn6Y-g3R.js} +1 -1
- package/gui/dist/classic/assets/{App-DA-scMPq.js → App-eYJAyNHM.js} +19 -18
- package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-xHMYxLkV.js} +1 -1
- package/gui/dist/classic/assets/index-DSaVRW4F.js +138 -0
- package/gui/dist/classic/assets/quota-summary-DyzHlkFl.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/src/cli.rs +5 -3
- package/native/ocx-child/src/codex_home.rs +1 -0
- package/package.json +2 -2
- package/src/adapters/anthropic/per-message-effort.ts +296 -0
- package/src/adapters/anthropic.ts +3 -0
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/devin/cloud-direct/chat.ts +71 -14
- package/src/adapters/google-errors.ts +14 -2
- package/src/adapters/qoder/adapter.ts +9 -1
- package/src/adapters/zed.ts +4 -2
- package/src/claude/desktop-remote-store.ts +60 -10
- package/src/cli/account-api.ts +4 -0
- package/src/cli/account-auth.ts +30 -2
- package/src/cli/account-extended.ts +33 -2
- package/src/cli/capabilities-access-remote.ts +3 -3
- package/src/cli/capabilities-accounts.ts +3 -3
- package/src/cli/capabilities-base.ts +11 -6
- package/src/cli/capabilities-observe-system.ts +2 -2
- package/src/cli/claude.ts +3 -3
- package/src/cli/disconnect-runtime.ts +16 -6
- package/src/cli/dispatch.ts +7 -1
- package/src/cli/index.ts +2 -2
- package/src/cli/link-apply-restart.ts +4 -2
- package/src/cli/link-routes.ts +4 -1
- package/src/cli/link.ts +5 -4
- package/src/cli/preflight-exemptions.ts +3 -0
- package/src/cli/registry.ts +5 -2
- package/src/cli/resolve.ts +23 -8
- package/src/cli/restart-failure.ts +11 -1
- package/src/cli/runtime-api.ts +4 -0
- package/src/cli/status.ts +4 -1
- package/src/cli/system-command.ts +1 -1
- package/src/cli/system-restart-client.ts +9 -3
- package/src/cli/system-settings-parity.ts +2 -1
- package/src/client/connect.ts +63 -9
- package/src/client/desktop-refusal.ts +38 -0
- package/src/client/lifecycle-lock.ts +29 -4
- package/src/client/runtime-restart.ts +27 -15
- package/src/client/runtime.ts +4 -2
- package/src/client/state.ts +14 -0
- package/src/codex/account-pause.ts +4 -0
- package/src/codex/account-runtime-state.ts +4 -0
- package/src/codex/auth-api/main-account-probe.ts +3 -1
- package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
- package/src/codex/auth-context.ts +40 -2
- package/src/codex/catalog/build-entries.ts +10 -0
- package/src/codex/catalog/derive-entry.ts +7 -0
- package/src/codex/catalog/reserve-warn.ts +7 -5
- package/src/codex/catalog/reserve.ts +4 -3
- package/src/codex/catalog/retained-sync.ts +2 -0
- package/src/codex/catalog/routed-defaults.ts +35 -0
- package/src/codex/convergence.ts +2 -0
- package/src/codex/loopback-target.ts +22 -8
- package/src/codex/main-account.ts +88 -29
- package/src/codex/native-main-auth-file.ts +14 -0
- package/src/codex/native-main-credentials.ts +270 -0
- package/src/codex/native-main-owner.ts +3 -0
- package/src/codex/native-main-refresh-mode.ts +14 -1
- package/src/codex/quota.ts +63 -14
- package/src/combos/failover.ts +12 -1
- package/src/combos/index.ts +5 -0
- package/src/combos/resolve.ts +115 -19
- package/src/config/diagnostics.ts +3 -0
- package/src/config/live-reconcile.ts +6 -3
- package/src/config/load-degrade.ts +2 -0
- package/src/config/persisted-mutation.ts +2 -2
- package/src/config/persisted-projections.ts +18 -0
- package/src/config/process-state.ts +4 -3
- package/src/config/reserve-capability.ts +96 -0
- package/src/config/schema/config-schema.ts +6 -0
- package/src/config/schema/leaf-validators.ts +2 -0
- package/src/config/schema/routed-catalog-defaults.ts +49 -0
- package/src/config.ts +7 -7
- package/src/desktop-update/acquire.ts +202 -0
- package/src/desktop-update/cli.ts +168 -0
- package/src/desktop-update/drain.ts +40 -0
- package/src/desktop-update/headless.ts +285 -0
- package/src/desktop-update/image.ts +85 -0
- package/src/desktop-update/install.ts +53 -0
- package/src/desktop-update/msi.ts +72 -0
- package/src/desktop-update/release.ts +128 -0
- package/src/desktop-update/runtime.ts +155 -0
- package/src/desktop-update/staging.ts +118 -0
- package/src/desktop-update/trust.ts +45 -0
- package/src/generated/compatibility-version.json +246 -130
- package/src/images/fulfill-video.ts +3 -3
- package/src/images/loop.ts +6 -2
- package/src/images/plan.ts +147 -11
- package/src/images/types.ts +13 -4
- package/src/images/xai-video-client.ts +72 -10
- package/src/lib/gcp-adc.ts +48 -4
- package/src/lib/offline-resend.ts +150 -0
- package/src/lib/paced-stream.ts +3 -3
- package/src/lib/provider-outbound.ts +17 -6
- package/src/lib/request-failure-model.ts +2 -0
- package/src/lib/response-body-inactivity.ts +23 -1
- package/src/lib/upstream-retry.ts +38 -5
- package/src/link/explicit-route.ts +4 -4
- package/src/link/remote-windows.ts +79 -31
- package/src/link/residual-recovery.ts +20 -8
- package/src/messaging/budget.ts +23 -5
- package/src/messaging/rpc.ts +4 -4
- package/src/oauth/antigravity-risk.ts +126 -0
- package/src/oauth/generic-account-failover.ts +89 -18
- package/src/oauth/generic-session-affinity.ts +10 -3
- package/src/oauth/login-cli.ts +35 -1
- package/src/oauth/pool-kernel.ts +3 -3
- package/src/providers/anthropic-billing-refusal.ts +27 -3
- package/src/providers/google-vertex-model-discovery.ts +6 -1
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/quota/workbuddy.ts +6 -2
- package/src/providers/workbuddy-credit-balance.ts +125 -16
- package/src/responses/effort-history.ts +732 -0
- package/src/routing/history/integrity.ts +41 -4
- package/src/server/auth-cors.ts +13 -3
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/direct-local-http.ts +26 -3
- package/src/server/index/link-listener.ts +20 -14
- package/src/server/index/serve-options.ts +1 -0
- package/src/server/index.ts +3 -2
- package/src/server/link-turn.ts +17 -5
- package/src/server/management/config-routes.ts +39 -3
- package/src/server/management/link-child-preflight.ts +1 -1
- package/src/server/management/link-route-edit.ts +20 -1
- package/src/server/management/oauth-account-routes.ts +22 -5
- package/src/server/management/provider-overwrite-carry.ts +3 -0
- package/src/server/management/provider-routes.ts +4 -4
- package/src/server/management/static-catalog-probe.ts +33 -0
- package/src/server/proxy-liveness.ts +54 -9
- package/src/server/relay.ts +6 -1
- package/src/server/request-log-conversation.ts +2 -2
- package/src/server/request-log.ts +5 -1
- package/src/server/reserve-capability-startup.ts +32 -0
- package/src/server/responses/adapter-delivery.ts +2 -0
- package/src/server/responses/adapter-dispatch.ts +31 -10
- package/src/server/responses/antigravity-fault-rotation.ts +24 -0
- package/src/server/responses/antigravity-validation-refusal.ts +43 -6
- package/src/server/responses/combo-selection-keepalive.ts +254 -0
- package/src/server/responses/core-combo.ts +24 -9
- package/src/server/responses/core-errors.ts +9 -6
- package/src/server/responses/core-options.ts +8 -0
- package/src/server/responses/core.ts +21 -0
- package/src/server/responses/estimated-usage.ts +115 -0
- package/src/server/responses/jev-model-invoke.ts +7 -2
- package/src/server/responses/passthrough-completion.ts +6 -3
- package/src/server/responses/passthrough-delivery.ts +47 -8
- package/src/server/responses/passthrough-dispatch.ts +3 -0
- package/src/server/responses/request-prepare.ts +9 -5
- package/src/server/responses/sidecar-execution.ts +5 -0
- package/src/service/desktop-supervision.d.mts +2 -0
- package/src/service/desktop-supervision.mjs +5 -0
- package/src/stall-timeout.ts +11 -0
- package/src/types/config.ts +15 -92
- package/src/types/provider.ts +13 -0
- package/src/types/request.ts +19 -0
- package/src/types/routed-catalog-defaults.ts +17 -0
- package/src/types/routing-profile.ts +90 -0
- package/src/types.ts +1 -0
- package/src/update/index.ts +1 -1
- package/src/usage/log.ts +14 -4
- package/src/usage/telemetry-contract.ts +1 -0
- package/src/web-search/passthrough-bridge.ts +7 -0
- package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
- package/gui/dist/assets/index-DCdXsMyZ.js +0 -105
- package/gui/dist/assets/index-DQtCRNAw.css +0 -2
- package/gui/dist/classic/assets/index-BqOaGLf5.js +0 -105
- package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url";
|
|
2
2
|
import type { VideoBridgePlan, VideoCallResult } from "./types";
|
|
3
|
-
import { submitVideoJob, pollVideoJob } from "./xai-video-client";
|
|
3
|
+
import { submitVideoJob, pollVideoJob, type VideoProviderAuth } from "./xai-video-client";
|
|
4
4
|
import { downloadVideoToArtifact, createVideoBudget, type VideoBudget } from "./artifacts";
|
|
5
5
|
|
|
6
6
|
/** Parsed arguments from the model's video_gen tool call. */
|
|
@@ -20,7 +20,7 @@ const DEFAULT_VIDEO_TIMEOUT_MS = 300_000; // 5 min
|
|
|
20
20
|
export type SleepFn = (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
21
21
|
export type PollVideoJobFn = (
|
|
22
22
|
requestId: string,
|
|
23
|
-
auth:
|
|
23
|
+
auth: VideoProviderAuth,
|
|
24
24
|
signal?: AbortSignal,
|
|
25
25
|
) => ReturnType<typeof pollVideoJob>;
|
|
26
26
|
|
|
@@ -82,7 +82,7 @@ export function parseVideoCallArgs(raw: string):
|
|
|
82
82
|
*/
|
|
83
83
|
export async function* pollVideoWithHeartbeats(
|
|
84
84
|
requestId: string,
|
|
85
|
-
auth:
|
|
85
|
+
auth: VideoProviderAuth,
|
|
86
86
|
signal: AbortSignal,
|
|
87
87
|
timeoutMs: number = DEFAULT_VIDEO_TIMEOUT_MS,
|
|
88
88
|
/** Test seams — avoid mock.module / global setTimeout (both poison parallel Bun CI). */
|
package/src/images/loop.ts
CHANGED
|
@@ -1028,9 +1028,13 @@ export async function runWithImageBridge(deps: ImageBridgeDeps): Promise<Respons
|
|
|
1028
1028
|
continue;
|
|
1029
1029
|
}
|
|
1030
1030
|
const vArgs = parseVideoCallArgs(call.args);
|
|
1031
|
+
const videoAuth = videoPlan!.auth;
|
|
1031
1032
|
let vResult;
|
|
1032
1033
|
if (!vArgs.ok) {
|
|
1033
1034
|
vResult = { ok: false, model: videoPlan!.model, prompt: "", files: [], count: 0, error: vArgs.error };
|
|
1035
|
+
} else if (!videoAuth) {
|
|
1036
|
+
// An unusable images.videoProvider answers the call; it never reaches any upstream.
|
|
1037
|
+
vResult = { ok: false, model: videoPlan!.model, prompt: vArgs.prompt, files: [], count: 0, error: videoPlan!.unavailable };
|
|
1034
1038
|
} else {
|
|
1035
1039
|
paidVideoCalls += 1;
|
|
1036
1040
|
const videoTimeout = videoTimeoutMs ?? 300_000;
|
|
@@ -1048,13 +1052,13 @@ export async function runWithImageBridge(deps: ImageBridgeDeps): Promise<Respons
|
|
|
1048
1052
|
...(vArgs.resolution != null ? { resolution: vArgs.resolution } : {}),
|
|
1049
1053
|
...(vArgs.aspectRatio != null ? { aspectRatio: vArgs.aspectRatio } : {}),
|
|
1050
1054
|
},
|
|
1051
|
-
|
|
1055
|
+
videoAuth, linkedDeadline,
|
|
1052
1056
|
);
|
|
1053
1057
|
const remainingMs = videoDeadline - Date.now();
|
|
1054
1058
|
if (remainingMs <= 0) {
|
|
1055
1059
|
vResult = { ok: false, model: videoPlan!.model, prompt: vArgs.prompt, files: [], count: 0, error: `video generation timed out after ${Math.floor(videoTimeout / 1000)}s` };
|
|
1056
1060
|
} else {
|
|
1057
|
-
const pollGen = pollVideoWithHeartbeats(requestId,
|
|
1061
|
+
const pollGen = pollVideoWithHeartbeats(requestId, videoAuth, linkedDeadline, remainingMs);
|
|
1058
1062
|
let pollResult: { ok: true; videoUrl: string } | { ok: false; error: string };
|
|
1059
1063
|
try {
|
|
1060
1064
|
for (;;) {
|
package/src/images/plan.ts
CHANGED
|
@@ -2,9 +2,13 @@ import type { OcxConfig, OcxParsedRequest, OcxProviderConfig } from "../types";
|
|
|
2
2
|
import { toolChoiceToolPredicate } from "../types";
|
|
3
3
|
import type { ImageBridgePlan, VideoBridgePlan } from "./types";
|
|
4
4
|
import { resolveProviderApiKey } from "../providers/key-store";
|
|
5
|
+
import { isProviderApiKeyPaused } from "../providers/api-key-pause-state";
|
|
6
|
+
import { isKeychainReference, keychainReferenceBelongsToProvider } from "../providers/api-key-resolve";
|
|
5
7
|
import { getValidAccessToken } from "../oauth/index";
|
|
6
8
|
import { getProviderRegistryEntry } from "../providers/registry";
|
|
9
|
+
import { providerDestinationConfigError } from "../lib/destination-policy";
|
|
7
10
|
import { IMAGE_GEN_TOOL_NAME, VIDEO_GEN_TOOL_NAME, isVideoGenName } from "./synthetic-tool";
|
|
11
|
+
import type { VideoProviderAuth } from "./xai-video-client";
|
|
8
12
|
|
|
9
13
|
const DEFAULT_MODEL = "grok-imagine-image-quality";
|
|
10
14
|
/** Absolute ceiling for `images.timeoutMs` (matches /v1/images relay budget). */
|
|
@@ -100,6 +104,133 @@ export async function planImageBridge(
|
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
const DEFAULT_VIDEO_MODEL = "grok-imagine-video";
|
|
107
|
+
const XAI_HOSTS = new Set(["api.x.ai", "cli-chat-proxy.grok.com"]);
|
|
108
|
+
|
|
109
|
+
function pinnedXaiBaseUrl(): string {
|
|
110
|
+
return (getProviderRegistryEntry("xai")?.baseUrl ?? "https://api.x.ai/v1").replace(/\/+$/, "");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function hostnameOf(baseUrl: string): string | undefined {
|
|
114
|
+
try { return new URL(baseUrl).hostname.toLowerCase(); } catch { return undefined; }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Only these exact origins may receive an xAI credential: HTTPS, an xAI host, the default port. */
|
|
118
|
+
function isTrustedXaiOrigin(baseUrl: string): boolean {
|
|
119
|
+
try {
|
|
120
|
+
const url = new URL(baseUrl);
|
|
121
|
+
return url.protocol === "https:" && url.port === "" && XAI_HOSTS.has(url.hostname.toLowerCase());
|
|
122
|
+
} catch { return false; }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isXaiRow(name: string, provider: OcxProviderConfig): boolean {
|
|
126
|
+
const host = hostnameOf(provider.baseUrl);
|
|
127
|
+
return name.trim().toLowerCase() === "xai" || (host !== undefined && XAI_HOSTS.has(host));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Whether a credential is recognizably xAI's, from any of: xAI's `xai-` key format, a key held by an
|
|
132
|
+
* xAI row (disabled rows and pooled keys included), or an environment reference whose name points at
|
|
133
|
+
* xAI/Grok. Such a key may reach only xAI. An arbitrary string with none of these marks cannot be
|
|
134
|
+
* attributed to xAI; foreign keychain references are refused earlier for every destination.
|
|
135
|
+
*/
|
|
136
|
+
function isXaiCredential(config: OcxConfig, reference: string | undefined, token: string): boolean {
|
|
137
|
+
if (token.toLowerCase().startsWith("xai-")) return true;
|
|
138
|
+
const ref = reference?.trim() ?? "";
|
|
139
|
+
if (/^\$\{?[A-Za-z0-9_]*(XAI|GROK)[A-Za-z0-9_]*\}?$/i.test(ref)) return true;
|
|
140
|
+
for (const [name, provider] of Object.entries(config.providers)) {
|
|
141
|
+
if (!isXaiRow(name, provider)) continue;
|
|
142
|
+
for (const candidate of [provider.apiKey, ...(provider.apiKeyPool ?? []).map(entry => entry.key)]) {
|
|
143
|
+
if (resolveProviderApiKey(candidate)?.trim() === token) return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type VideoProviderSelection =
|
|
150
|
+
| { ok: true; providerName: string; provider: OcxProviderConfig; auth: VideoProviderAuth }
|
|
151
|
+
| { ok: false; error: string };
|
|
152
|
+
|
|
153
|
+
/** The pinned xAI destination: registry host, no private-network opt-in, the row's egress route. */
|
|
154
|
+
function pinnedXaiVideoAuth(provider: OcxProviderConfig, token: string): VideoProviderAuth {
|
|
155
|
+
return {
|
|
156
|
+
baseUrl: pinnedXaiBaseUrl(),
|
|
157
|
+
token,
|
|
158
|
+
providerName: "xai",
|
|
159
|
+
...(provider.proxy !== undefined ? { proxy: provider.proxy } : {}),
|
|
160
|
+
...(provider.noProxy !== undefined ? { noProxy: provider.noProxy } : {}),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Resolve an explicit `images.videoProvider`. Returns undefined when the setting is absent, which
|
|
166
|
+
* keeps the historical xAI discovery. Every other outcome is final: an unusable selection is an
|
|
167
|
+
* error and never falls back to xAI. The chosen row's own baseUrl and key are the only destination
|
|
168
|
+
* and credential; `xai` itself stays pinned to the registry host, and a recognizably xAI credential
|
|
169
|
+
* (see {@link isXaiCredential}) is refused for every origin except HTTPS xAI hosts on the default port.
|
|
170
|
+
*/
|
|
171
|
+
export function selectVideoProvider(config: OcxConfig): VideoProviderSelection | undefined {
|
|
172
|
+
const configured = config.images?.videoProvider;
|
|
173
|
+
if (configured === undefined) return undefined;
|
|
174
|
+
if (typeof configured !== "string" || !configured.trim()) {
|
|
175
|
+
return { ok: false, error: "images.videoProvider must be a nonblank provider name" };
|
|
176
|
+
}
|
|
177
|
+
const providerName = configured.trim();
|
|
178
|
+
const label = `images.videoProvider "${providerName}"`;
|
|
179
|
+
const isXai = providerName === "xai";
|
|
180
|
+
if (!isXai && getProviderRegistryEntry(providerName)) {
|
|
181
|
+
return { ok: false, error: `${label} must name a custom provider or xai` };
|
|
182
|
+
}
|
|
183
|
+
const provider = Object.prototype.hasOwnProperty.call(config.providers, providerName)
|
|
184
|
+
? config.providers[providerName]
|
|
185
|
+
: undefined;
|
|
186
|
+
if (!provider) return { ok: false, error: `${label} is not configured` };
|
|
187
|
+
if (provider.disabled === true) return { ok: false, error: `${label} is disabled` };
|
|
188
|
+
if (provider.authMode !== undefined && provider.authMode !== "key") {
|
|
189
|
+
return { ok: false, error: `${label} must be an API-key provider` };
|
|
190
|
+
}
|
|
191
|
+
if (isProviderApiKeyPaused(provider)) {
|
|
192
|
+
return { ok: false, error: `${label} is paused: its active API key is disabled` };
|
|
193
|
+
}
|
|
194
|
+
// Never resolve another row's keychain secret, whatever the destination (xAI included).
|
|
195
|
+
if (isKeychainReference(provider.apiKey) && !keychainReferenceBelongsToProvider(provider.apiKey, providerName)) {
|
|
196
|
+
return { ok: false, error: `${label} references a keychain secret it does not own` };
|
|
197
|
+
}
|
|
198
|
+
let baseUrl: string;
|
|
199
|
+
if (isXai) {
|
|
200
|
+
baseUrl = pinnedXaiBaseUrl();
|
|
201
|
+
} else {
|
|
202
|
+
baseUrl = provider.baseUrl.trim().replace(/\/+$/, "");
|
|
203
|
+
let parsed: URL | undefined;
|
|
204
|
+
try { parsed = new URL(baseUrl); } catch { /* reported below */ }
|
|
205
|
+
// The client appends paths as strings, so a query or fragment would swallow them.
|
|
206
|
+
if (!parsed || (parsed.protocol !== "https:" && parsed.protocol !== "http:")
|
|
207
|
+
|| parsed.username || parsed.password || parsed.search || parsed.hash
|
|
208
|
+
|| baseUrl.includes("?") || baseUrl.includes("#")) {
|
|
209
|
+
return { ok: false, error: `${label} needs a plain http(s) baseUrl without credentials, query or fragment` };
|
|
210
|
+
}
|
|
211
|
+
const destinationError = providerDestinationConfigError(providerName, provider);
|
|
212
|
+
if (destinationError) return { ok: false, error: `${label} ${destinationError}` };
|
|
213
|
+
}
|
|
214
|
+
const token = resolveProviderApiKey(provider.apiKey)?.trim();
|
|
215
|
+
if (!token) return { ok: false, error: `${label} has no usable API key` };
|
|
216
|
+
if (!isXai && !isTrustedXaiOrigin(baseUrl) && isXaiCredential(config, provider.apiKey, token)) {
|
|
217
|
+
return { ok: false, error: `${label} uses an xAI API key; an xAI API key is only sent to xAI over HTTPS` };
|
|
218
|
+
}
|
|
219
|
+
// The literal check above runs at plan time; the outbound transport repeats it on the resolved
|
|
220
|
+
// addresses at connect time, so a hostname that resolves to loopback or private space needs the
|
|
221
|
+
// same allowPrivateNetwork opt-in.
|
|
222
|
+
const auth: VideoProviderAuth = isXai
|
|
223
|
+
? pinnedXaiVideoAuth(provider, token)
|
|
224
|
+
: {
|
|
225
|
+
baseUrl,
|
|
226
|
+
token,
|
|
227
|
+
providerName,
|
|
228
|
+
...(provider.allowPrivateNetwork === true ? { allowPrivateNetwork: true } : {}),
|
|
229
|
+
...(provider.proxy !== undefined ? { proxy: provider.proxy } : {}),
|
|
230
|
+
...(provider.noProxy !== undefined ? { noProxy: provider.noProxy } : {}),
|
|
231
|
+
};
|
|
232
|
+
return { ok: true, providerName, provider, auth };
|
|
233
|
+
}
|
|
103
234
|
|
|
104
235
|
/**
|
|
105
236
|
* Decide whether the video bridge should activate for this request. Unlike images, video
|
|
@@ -107,7 +238,9 @@ const DEFAULT_VIDEO_MODEL = "grok-imagine-video";
|
|
|
107
238
|
* injected when `videoBridgeEnabled` is true. The bridge activates only when:
|
|
108
239
|
* 1. videoBridgeEnabled is explicitly true (opt-in)
|
|
109
240
|
* 2. the routed provider is NOT api.openai.com (native passthrough)
|
|
110
|
-
* 3.
|
|
241
|
+
* 3. `images.videoProvider` names a usable provider, or, when it is unset, an xAI provider with a
|
|
242
|
+
* valid API key is available. An unusable explicit provider yields an unavailable plan that
|
|
243
|
+
* answers every call with its error; it never falls back to xAI.
|
|
111
244
|
*/
|
|
112
245
|
export async function planVideoBridge(
|
|
113
246
|
config: OcxConfig,
|
|
@@ -136,23 +269,26 @@ export async function planVideoBridge(
|
|
|
136
269
|
// Don't intercept for OpenAI native passthrough
|
|
137
270
|
const host = (() => { try { return new URL(routedProvider.baseUrl).hostname; } catch { return ""; } })();
|
|
138
271
|
if (host === "api.openai.com") return undefined;
|
|
139
|
-
const found = findXaiProvider(config);
|
|
140
|
-
if (!found) return undefined;
|
|
141
|
-
const token = resolveXaiImageApiKey(found.provider);
|
|
142
|
-
if (!token) return undefined;
|
|
143
|
-
// Pin the baseUrl to the registry entry, ignoring any config-level baseUrl override.
|
|
144
|
-
const registryEntry = getProviderRegistryEntry("xai");
|
|
145
|
-
const pinnedBaseUrl = (registryEntry?.baseUrl ?? "https://api.x.ai/v1").replace(/\/+$/, "");
|
|
146
272
|
const timeoutMs = clampImageTimeoutMs(config.images?.videoTimeoutMs);
|
|
147
273
|
const keepRaw = config.images?.artifactsKeepCount;
|
|
148
274
|
const artifactsKeepCount =
|
|
149
275
|
typeof keepRaw === "number" && Number.isFinite(keepRaw) ? Math.floor(keepRaw) : undefined;
|
|
150
|
-
|
|
151
|
-
provider: found.provider,
|
|
152
|
-
auth: { baseUrl: pinnedBaseUrl, token },
|
|
276
|
+
const common = {
|
|
153
277
|
model: config.images?.videoBridgeModel ?? DEFAULT_VIDEO_MODEL,
|
|
154
278
|
toolNames,
|
|
155
279
|
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
156
280
|
...(artifactsKeepCount !== undefined ? { artifactsKeepCount } : {}),
|
|
157
281
|
};
|
|
282
|
+
const selection = selectVideoProvider(config);
|
|
283
|
+
if (selection) {
|
|
284
|
+
return selection.ok
|
|
285
|
+
? { ...common, provider: selection.provider, auth: selection.auth }
|
|
286
|
+
: { ...common, unavailable: selection.error };
|
|
287
|
+
}
|
|
288
|
+
const found = findXaiProvider(config);
|
|
289
|
+
if (!found) return undefined;
|
|
290
|
+
const token = resolveXaiImageApiKey(found.provider);
|
|
291
|
+
if (!token) return undefined;
|
|
292
|
+
// Pin the baseUrl to the registry entry, ignoring any config-level baseUrl override.
|
|
293
|
+
return { ...common, provider: found.provider, auth: pinnedXaiVideoAuth(found.provider, token) };
|
|
158
294
|
}
|
package/src/images/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OcxProviderConfig } from "../types";
|
|
2
|
+
import type { VideoProviderAuth } from "./xai-video-client";
|
|
2
3
|
|
|
3
4
|
export interface ImageBridgePlan {
|
|
4
5
|
provider: OcxProviderConfig;
|
|
@@ -25,10 +26,7 @@ export interface ImageCallResult {
|
|
|
25
26
|
error?: string;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
export interface VideoBridgePlan {
|
|
30
|
-
provider: OcxProviderConfig;
|
|
31
|
-
auth: { baseUrl: string; token: string };
|
|
29
|
+
interface VideoBridgePlanBase {
|
|
32
30
|
model: string;
|
|
33
31
|
toolNames: Set<string>;
|
|
34
32
|
/** Per-call xAI deadline (ms) for submit + poll. */
|
|
@@ -37,5 +35,16 @@ export interface VideoBridgePlan {
|
|
|
37
35
|
artifactsKeepCount?: number;
|
|
38
36
|
}
|
|
39
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Plan for the video bridge. A ready plan carries the one destination and credential the
|
|
40
|
+
* bridge may use. An unavailable plan (an explicit `images.videoProvider` that cannot be used)
|
|
41
|
+
* still claims the `video_gen` tool so each call is answered with the configuration error
|
|
42
|
+
* instead of reaching any upstream; it carries no provider and no credential.
|
|
43
|
+
*/
|
|
44
|
+
export type VideoBridgePlan = VideoBridgePlanBase & (
|
|
45
|
+
| { provider: OcxProviderConfig; auth: VideoProviderAuth; unavailable?: undefined }
|
|
46
|
+
| { provider?: undefined; auth?: undefined; unavailable: string }
|
|
47
|
+
);
|
|
48
|
+
|
|
40
49
|
/** Result shape for video fulfillment — same as image. */
|
|
41
50
|
export type VideoCallResult = ImageCallResult;
|
|
@@ -6,7 +6,37 @@
|
|
|
6
6
|
* The submit call uses a 60 s timeout (it only returns an ID); the poll call uses 30 s.
|
|
7
7
|
* Non-2xx responses throw with the original status code so callers can distinguish
|
|
8
8
|
* rate-limit / auth failures from transient errors.
|
|
9
|
+
*
|
|
10
|
+
* Both calls go through the provider outbound transport, which resolves the destination host,
|
|
11
|
+
* applies the selected row's `allowPrivateNetwork` to every DNS answer and pins the connection to
|
|
12
|
+
* a validated address, so a hostname that resolves to loopback or private space never receives the
|
|
13
|
+
* bearer key without the opt-in and a later DNS answer cannot redirect it (rebinding).
|
|
14
|
+
* The poll GET carries the same key as the submit POST, so it obeys the same cleartext rules.
|
|
9
15
|
*/
|
|
16
|
+
import type { OcxProviderConfig } from "../types";
|
|
17
|
+
import { getProviderRegistryEntry } from "../providers/registry";
|
|
18
|
+
import {
|
|
19
|
+
providerOutboundGet,
|
|
20
|
+
providerOutboundPost,
|
|
21
|
+
type ProviderOutboundDependencies,
|
|
22
|
+
} from "../lib/provider-outbound";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Destination and credential of one video provider. `providerName` and the destination fields are
|
|
26
|
+
* the selected row's, read by the outbound policy; the pinned xAI path uses `xai` with no
|
|
27
|
+
* private-network opt-in because its destination is the registry host.
|
|
28
|
+
*/
|
|
29
|
+
export interface VideoProviderAuth {
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
token: string;
|
|
32
|
+
providerName: string;
|
|
33
|
+
allowPrivateNetwork?: boolean;
|
|
34
|
+
proxy?: OcxProviderConfig["proxy"];
|
|
35
|
+
noProxy?: OcxProviderConfig["noProxy"];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Test seam for DNS resolution and the pinned transport; production passes nothing. */
|
|
39
|
+
export type VideoOutboundDependencies = Pick<ProviderOutboundDependencies, "resolveAddresses" | "pinnedGet" | "pinnedPost">;
|
|
10
40
|
|
|
11
41
|
export interface XaiVideoSubmitRequest {
|
|
12
42
|
prompt: string;
|
|
@@ -30,6 +60,40 @@ const SUBMIT_TIMEOUT_MS = 60_000;
|
|
|
30
60
|
const POLL_TIMEOUT_MS = 30_000;
|
|
31
61
|
const DEFAULT_VIDEO_MODEL = "grok-imagine-video";
|
|
32
62
|
|
|
63
|
+
function xaiRegistryBaseUrl(): string {
|
|
64
|
+
return (getProviderRegistryEntry("xai")?.baseUrl ?? "https://api.x.ai/v1").replace(/\/+$/, "");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Only the registry xAI video endpoints qualify for the outbound fake-IP TUN exception, which
|
|
69
|
+
* keeps the pinned xAI path reachable under Clash/Surge TUN mode as it was with plain fetch.
|
|
70
|
+
*/
|
|
71
|
+
function isCanonicalXaiVideoUrl(name: string, url: string): boolean {
|
|
72
|
+
return name === "xai" && url.startsWith(`${xaiRegistryBaseUrl()}/videos/`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function outboundConfig(auth: VideoProviderAuth) {
|
|
76
|
+
return {
|
|
77
|
+
baseUrl: auth.baseUrl,
|
|
78
|
+
...(auth.allowPrivateNetwork === true ? { allowPrivateNetwork: true } : {}),
|
|
79
|
+
...(auth.proxy !== undefined ? { proxy: auth.proxy } : {}),
|
|
80
|
+
...(auth.noProxy !== undefined ? { noProxy: auth.noProxy } : {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function outboundDependencies(dependencies: VideoOutboundDependencies): ProviderOutboundDependencies {
|
|
85
|
+
return {
|
|
86
|
+
...dependencies,
|
|
87
|
+
isCanonicalUrl: isCanonicalXaiVideoUrl,
|
|
88
|
+
// A self-hosted http video service is reachable only on localhost or a local address
|
|
89
|
+
// literal, and only when the row itself sets allowPrivateNetwork (see provider-outbound).
|
|
90
|
+
allowLocalCleartextPost: true,
|
|
91
|
+
// The poll GET sends the bearer key too, so it gets exactly the submit POST's cleartext rules:
|
|
92
|
+
// a public answer for an http host, or a proxied http route, is refused before any send.
|
|
93
|
+
cleartextPolicy: "credentialed",
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
33
97
|
/** Maximum response body size for the submit and poll calls (responses are small JSON). */
|
|
34
98
|
const MAX_RESPONSE_BYTES = 1024 * 1024; // 1 MiB — these endpoints return small JSON
|
|
35
99
|
|
|
@@ -64,8 +128,9 @@ async function readBoundedText(resp: Response): Promise<string> {
|
|
|
64
128
|
*/
|
|
65
129
|
export async function submitVideoJob(
|
|
66
130
|
req: XaiVideoSubmitRequest,
|
|
67
|
-
auth:
|
|
131
|
+
auth: VideoProviderAuth,
|
|
68
132
|
signal?: AbortSignal,
|
|
133
|
+
dependencies: VideoOutboundDependencies = {},
|
|
69
134
|
): Promise<XaiVideoSubmitResult> {
|
|
70
135
|
const body: Record<string, unknown> = {
|
|
71
136
|
model: req.model ?? DEFAULT_VIDEO_MODEL,
|
|
@@ -78,16 +143,14 @@ export async function submitVideoJob(
|
|
|
78
143
|
const timeout = AbortSignal.timeout(SUBMIT_TIMEOUT_MS);
|
|
79
144
|
const linkedSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
80
145
|
|
|
81
|
-
const resp = await
|
|
82
|
-
method: "POST",
|
|
83
|
-
redirect: "manual",
|
|
146
|
+
const resp = await providerOutboundPost(auth.providerName, outboundConfig(auth), `${auth.baseUrl}/videos/generations`, {
|
|
84
147
|
headers: {
|
|
85
148
|
"Authorization": `Bearer ${auth.token}`,
|
|
86
149
|
"Content-Type": "application/json",
|
|
87
150
|
},
|
|
88
151
|
body: JSON.stringify(body),
|
|
89
152
|
signal: linkedSignal,
|
|
90
|
-
});
|
|
153
|
+
}, outboundDependencies(dependencies));
|
|
91
154
|
|
|
92
155
|
if (!resp.ok) {
|
|
93
156
|
try { await resp.body?.cancel(); } catch { /* ignore */ }
|
|
@@ -111,20 +174,19 @@ export async function submitVideoJob(
|
|
|
111
174
|
*/
|
|
112
175
|
export async function pollVideoJob(
|
|
113
176
|
requestId: string,
|
|
114
|
-
auth:
|
|
177
|
+
auth: VideoProviderAuth,
|
|
115
178
|
signal?: AbortSignal,
|
|
179
|
+
dependencies: VideoOutboundDependencies = {},
|
|
116
180
|
): Promise<XaiVideoPollResult> {
|
|
117
181
|
const timeout = AbortSignal.timeout(POLL_TIMEOUT_MS);
|
|
118
182
|
const linkedSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
119
183
|
|
|
120
|
-
const resp = await
|
|
121
|
-
method: "GET",
|
|
122
|
-
redirect: "manual",
|
|
184
|
+
const resp = await providerOutboundGet(auth.providerName, outboundConfig(auth), `${auth.baseUrl}/videos/${encodeURIComponent(requestId)}`, {
|
|
123
185
|
headers: {
|
|
124
186
|
"Authorization": `Bearer ${auth.token}`,
|
|
125
187
|
},
|
|
126
188
|
signal: linkedSignal,
|
|
127
|
-
});
|
|
189
|
+
}, outboundDependencies(dependencies));
|
|
128
190
|
|
|
129
191
|
if (!resp.ok) {
|
|
130
192
|
try { await resp.body?.cancel(); } catch { /* ignore */ }
|
package/src/lib/gcp-adc.ts
CHANGED
|
@@ -60,6 +60,19 @@ export function gcpCredentialMarkerAccount(value: string | undefined): string |
|
|
|
60
60
|
return account;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
export type VertexConfiguredCredentialKind = "marker" | "ambient" | "reference" | "api-key";
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Classify a Vertex row's configured `apiKey` text without resolving it, so no caller has to read a
|
|
67
|
+
* keychain or the environment just to learn which kind of credential the row names. The management
|
|
68
|
+
* DTO and the static-catalog connection test share this one rule.
|
|
69
|
+
*/
|
|
70
|
+
export function vertexConfiguredCredentialKind(key: string | undefined): VertexConfiguredCredentialKind {
|
|
71
|
+
if (key?.startsWith(GCP_CREDENTIAL_MARKER_PREFIX)) return "marker";
|
|
72
|
+
if (!key?.trim() || key === "N/A" || key.startsWith("<")) return "ambient";
|
|
73
|
+
return key.startsWith("keychain:") || /^\$\{?\w+\}?$/.test(key) ? "reference" : "api-key";
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
/**
|
|
64
77
|
* Whether a pasted API-key value is in fact a GCP credential JSON. Used by the save path to
|
|
65
78
|
* divert JSON material out of the literal-key flow before it reaches `config.json`. Deliberately
|
|
@@ -125,6 +138,18 @@ const sourceObservations = new Map<string, { source: string; generation: number
|
|
|
125
138
|
let sourceEpoch = 0;
|
|
126
139
|
let lastReconciledGeneration = 0;
|
|
127
140
|
let liveSources = new Set<string>();
|
|
141
|
+
// Last token exchange that succeeded, per credential scope. Proof the dashboard can show without a
|
|
142
|
+
// network call; it lapses on its own once the source the next resolve would use changes.
|
|
143
|
+
const verifiedSources = new Map<string, { source: string; generation: number }>();
|
|
144
|
+
const adcScope = (markerAccount: string | undefined) => markerAccount ? `marker:${markerAccount}` : "host";
|
|
145
|
+
|
|
146
|
+
/** True when this process minted a token from the credential source the next request would use. */
|
|
147
|
+
export function vertexAdcCredentialVerified(markerAccount?: string): boolean {
|
|
148
|
+
const verified = verifiedSources.get(adcScope(markerAccount));
|
|
149
|
+
if (!verified) return false;
|
|
150
|
+
const current = observeAdcSource(markerAccount);
|
|
151
|
+
return current.source === verified.source && current.generation === verified.generation;
|
|
152
|
+
}
|
|
128
153
|
|
|
129
154
|
export function sweepExpiredGcpAdcTokens(now = Date.now()): number {
|
|
130
155
|
const skew = getRefreshSkewMs();
|
|
@@ -244,7 +269,7 @@ function currentAdcSourceKey(markerAccount: string | undefined): string {
|
|
|
244
269
|
|
|
245
270
|
/** Every observed source transition gets a fresh incarnation, including A→B→A. */
|
|
246
271
|
function observeAdcSource(markerAccount: string | undefined): { source: string; generation: number } {
|
|
247
|
-
const scope = markerAccount
|
|
272
|
+
const scope = adcScope(markerAccount);
|
|
248
273
|
const source = currentAdcSourceKey(markerAccount);
|
|
249
274
|
const previous = sourceObservations.get(scope);
|
|
250
275
|
if (previous?.source === source) return previous;
|
|
@@ -394,8 +419,13 @@ async function resolveAccessTokenUncached(markerAccount: string | undefined, sig
|
|
|
394
419
|
);
|
|
395
420
|
}
|
|
396
421
|
|
|
397
|
-
/**
|
|
398
|
-
|
|
422
|
+
/**
|
|
423
|
+
* Returns a Bearer access token for the `Authorization` header on Vertex AI calls (cached + refreshed).
|
|
424
|
+
* `forceExchange` skips the completed-token cache so the caller observes a real exchange: the
|
|
425
|
+
* connection test uses it, because a cached token outlives a revoked refresh credential. It still
|
|
426
|
+
* joins an exchange already in flight and refreshes the cache on success; other callers keep the cache.
|
|
427
|
+
*/
|
|
428
|
+
export async function getVertexAccessTokenWithAuthority(options?: { signal?: AbortSignal; fetch?: FetchImpl; markerAccount?: string; beforeSend?: () => void; forceExchange?: boolean }): Promise<VertexTokenAuthority> {
|
|
399
429
|
// The marker travels as an argument, never as process-global state: a module-level "active
|
|
400
430
|
// marker" written by the router would race across concurrent requests for different providers
|
|
401
431
|
// and could resolve one provider's Vertex call with another provider's service account. The
|
|
@@ -418,7 +448,7 @@ export async function getVertexAccessTokenWithAuthority(options?: { signal?: Abo
|
|
|
418
448
|
}
|
|
419
449
|
const writerGeneration = captureConfigGeneration();
|
|
420
450
|
for (const [source, cached] of tokenCache) {
|
|
421
|
-
if (source === expectedSource && cached.generation === expected.generation && cached.expiresAtMs - skew > now) {
|
|
451
|
+
if (!options?.forceExchange && source === expectedSource && cached.generation === expected.generation && cached.expiresAtMs - skew > now) {
|
|
422
452
|
return { token: cached.token, source, generation: expected.generation, markerAccount };
|
|
423
453
|
}
|
|
424
454
|
if (cached.expiresAtMs - skew <= now) tokenCache.delete(source);
|
|
@@ -449,12 +479,25 @@ export async function getVertexAccessTokenWithAuthority(options?: { signal?: Abo
|
|
|
449
479
|
if (source !== expectedSource || current.source !== source || current.generation !== expected.generation) {
|
|
450
480
|
throw new Error("Vertex ADC source changed during token exchange");
|
|
451
481
|
}
|
|
482
|
+
if (typeof token.access_token !== "string" || !token.access_token) {
|
|
483
|
+
throw new Error("Google OAuth token response has no access_token");
|
|
484
|
+
}
|
|
452
485
|
const expiresAtMs = Date.now() + Math.max(0, token.expires_in * 1000);
|
|
453
486
|
if (writerGeneration >= lastReconciledGeneration || liveSources.has(source)) {
|
|
454
487
|
tokenCache.set(source, { token: token.access_token, expiresAtMs, generation: expected.generation });
|
|
455
488
|
sweepExpiredOnWrite(Date.now());
|
|
456
489
|
}
|
|
490
|
+
verifiedSources.set(adcScope(markerAccount), { source, generation: expected.generation });
|
|
457
491
|
return { token: token.access_token, source, generation: expected.generation, markerAccount };
|
|
492
|
+
} catch (error) {
|
|
493
|
+
// Drop only this exchange's own proof: a newer exchange for a changed source may already
|
|
494
|
+
// have recorded its success under the same scope, and that proof still holds.
|
|
495
|
+
const scope = adcScope(markerAccount);
|
|
496
|
+
const verified = verifiedSources.get(scope);
|
|
497
|
+
if (!controller.signal.aborted && verified?.source === expectedSource && verified.generation === expected.generation) {
|
|
498
|
+
verifiedSources.delete(scope);
|
|
499
|
+
}
|
|
500
|
+
throw error;
|
|
458
501
|
} finally {
|
|
459
502
|
owned.settled = true;
|
|
460
503
|
if (inflight.get(cacheKey) === owned) inflight.delete(cacheKey);
|
|
@@ -538,6 +581,7 @@ export function vertexRequestAuthorityIsCurrent(request: object, target?: string
|
|
|
538
581
|
|
|
539
582
|
/** Test seam: restores complete process-local token and reconciliation state. */
|
|
540
583
|
export function __resetVertexTokenCache(): void {
|
|
584
|
+
verifiedSources.clear();
|
|
541
585
|
tokenCache.clear();
|
|
542
586
|
for (const entry of inflight.values()) entry.controller.abort();
|
|
543
587
|
inflight.clear();
|