@opengeni/config 0.13.2 → 0.16.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/config",
3
- "version": "0.13.2",
3
+ "version": "0.16.1",
4
4
  "description": "OpenGeni runtime configuration: settings resolution, deployment knobs, and config validation shared across the server packages.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -33,8 +33,9 @@
33
33
  "prepublishOnly": "bash ../../scripts/prepublish-guard"
34
34
  },
35
35
  "dependencies": {
36
- "@opengeni/codex": "^0.2.15",
37
- "@opengeni/contracts": "^0.44.1",
36
+ "@opengeni/codex": "^0.2.16",
37
+ "@opengeni/contracts": "^0.50.0",
38
+ "@opengeni/xai-subscription": "^0.1.0",
38
39
  "zod": "^4.2.1"
39
40
  },
40
41
  "engines": {
package/src/index.ts CHANGED
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  BillingMode,
3
3
  CAPABILITY_DESCRIPTORS,
4
+ DEFAULT_FIRST_PARTY_MCP_TOOLS,
4
5
  Entitlements,
5
6
  EntitlementsMode,
6
7
  LatencyMode,
7
8
  MAX_NESTED_AGENT_DEPTH,
8
9
  ProductAccessMode,
9
10
  ReasoningEffort,
11
+ FIRST_PARTY_MCP_TOOL_NAMES,
12
+ FirstPartyMcpToolName,
10
13
  SandboxBackend,
11
14
  SessionMcpApprovalPolicy,
12
15
  SEEDANCE_2_5_MODEL_ID,
@@ -17,6 +20,7 @@ import {
17
20
  type TurnExecutionModelSourceV1,
18
21
  type TurnExecutionReasoningSourceV1,
19
22
  type VideoGenerationResolution,
23
+ type FirstPartyMcpToolName as FirstPartyMcpToolNameType,
20
24
  } from "@opengeni/contracts";
21
25
  import { CODEX_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS } from "@opengeni/codex";
22
26
  import {
@@ -28,6 +32,16 @@ import {
28
32
  CODEX_PROVIDER_BASE_URL,
29
33
  CODEX_PROVIDER_ID,
30
34
  } from "@opengeni/codex/constants";
35
+ import {
36
+ XAI_SUBSCRIPTION_MODEL_SLUGS,
37
+ XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT,
38
+ XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS,
39
+ XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS,
40
+ XAI_SUBSCRIPTION_MODEL_ID_PREFIX,
41
+ XAI_SUBSCRIPTION_PROVIDER_ID,
42
+ XAI_SUBSCRIPTION_PROXY_BASE_URL,
43
+ } from "@opengeni/xai-subscription";
44
+ export { XAI_SUBSCRIPTION_MODEL_ID_PREFIX } from "@opengeni/xai-subscription";
31
45
  import { createHash } from "node:crypto";
32
46
  import { z } from "zod";
33
47
 
@@ -65,6 +79,38 @@ const EnvBoolean = z.preprocess((value) => {
65
79
  return value;
66
80
  }, z.boolean());
67
81
 
82
+ const EnvFirstPartyMcpTools = z.preprocess(
83
+ (value) => {
84
+ if (typeof value !== "string") return value;
85
+ const source = value.trim();
86
+ if (!source) return undefined;
87
+ if (source.startsWith("[")) {
88
+ try {
89
+ return JSON.parse(source);
90
+ } catch {
91
+ return value;
92
+ }
93
+ }
94
+ return source.split(",").map((entry) => entry.trim());
95
+ },
96
+ z
97
+ .array(FirstPartyMcpToolName)
98
+ .superRefine((tools, context) => {
99
+ const seen = new Set<FirstPartyMcpToolNameType>();
100
+ for (const [index, tool] of tools.entries()) {
101
+ if (seen.has(tool)) {
102
+ context.addIssue({
103
+ code: "custom",
104
+ message: "first-party MCP tool lists must not contain duplicates",
105
+ path: [index],
106
+ });
107
+ }
108
+ seen.add(tool);
109
+ }
110
+ })
111
+ .optional(),
112
+ );
113
+
68
114
  export const sandboxPreparationProfiles: Record<string, { env: string[]; hooks: string[] }> = {
69
115
  none: {
70
116
  env: [],
@@ -130,7 +176,7 @@ export const DEFAULT_AGENT_INSTRUCTIONS = [
130
176
  "Repository resources are mounted under repos/<host>/<owner>/<repo> unless the session specifies another collision-free mount path.",
131
177
  "File resources are mounted under .opengeni/files/<file-id>/ unless the session specifies another mount path.",
132
178
  "Attached files are mounted read-only; copy them before modifying.",
133
- "Bundled skills are under .agents/ and can include infrastructure, marketing, or other role-specific guidance.",
179
+ "Installed and selected Skills are indexed under .agents/ and may include role-specific guidance.",
134
180
  "Use Checkov, Terraform, Azure CLI, git provider CLIs, and repository tools when relevant; gh, glab, and az repos are pre-authenticated when the host brokers matching git credentials.",
135
181
  "When the Azure sandbox preparation profile is enabled and service-principal variables are present, the sandbox is pre-authenticated with normal Azure CLI before work starts.",
136
182
  "Treat code-changing work as GitOps work: create a focused branch/commit/PR when git provider credentials are available; otherwise report exact commands and blockers.",
@@ -289,6 +335,8 @@ const SettingsSchema = z.object({
289
335
  staticEntitlementsJson: z.string().default("{}"),
290
336
  staticUsageLimitsJson: z.string().default("{}"),
291
337
  delegationSecret: z.string().optional(),
338
+ defaultFirstPartyMcpTools: EnvFirstPartyMcpTools,
339
+ allowedFirstPartyMcpTools: EnvFirstPartyMcpTools,
292
340
  // sandbox workspace scoped stream-token HMAC secret (sandbox contract §C.3 / stream-token availability contract).
293
341
  // When unset, the API falls back to `delegationSecret` (the same HMAC envelope
294
342
  // family, `ogs_` vs `ogd_` prefix). REQUIRED-WHEN-DESKTOP, but the absence of
@@ -318,6 +366,8 @@ const SettingsSchema = z.object({
318
366
  slackSigningSecret: z.string().optional(),
319
367
  googleDriveClientId: z.string().optional(),
320
368
  googleDriveClientSecret: z.string().optional(),
369
+ fikenClientId: z.string().optional(),
370
+ fikenClientSecret: z.string().optional(),
321
371
  googleDriveWorkspaceEventsEnabled: EnvBoolean.optional(),
322
372
  atlassianClientId: z.string().optional(),
323
373
  atlassianClientSecret: z.string().optional(),
@@ -474,10 +524,12 @@ const SettingsSchema = z.object({
474
524
  .default(24 * 60 * 60),
475
525
  voiceInputFfmpegPath: z.string().trim().min(1).max(1024).default("ffmpeg"),
476
526
  // Preferred provider order (comma-separated ids). First configured+ready wins.
477
- // Codex subscription STT is preferred by default when subscription routing is
478
- // enabled; operators can put openai/azure-openai first explicitly.
479
- // Supported: openai, azure-openai, codex-subscription.
480
- voiceInputProviderOrder: z.string().default("codex-subscription,openai,azure-openai"),
527
+ // Connected subscription STT is preferred by default; operators can put
528
+ // openai/azure-openai first explicitly.
529
+ // Supported: supergrok-subscription, codex-subscription, openai, azure-openai.
530
+ voiceInputProviderOrder: z
531
+ .string()
532
+ .default("supergrok-subscription,codex-subscription,openai,azure-openai"),
481
533
  // OpenAI public /v1/audio/transcriptions path. Reuses OPENGENI_OPENAI_API_KEY
482
534
  // when voiceInputOpenaiApiKey is unset. Default model is gpt-transcribe.
483
535
  voiceInputOpenaiEnabled: EnvBoolean.default(true),
@@ -509,6 +561,9 @@ const SettingsSchema = z.object({
509
561
  // subscription is injected as a synthetic "codex-subscription" registry
510
562
  // provider whose models route through the ChatGPT backend (@opengeni/codex).
511
563
  codexSubscriptionEnabled: EnvBoolean.default(false), // OPENGENI_CODEX_SUBSCRIPTION_ENABLED
564
+ // SuperGrok/xAI connected subscription. This is a workspace-scoped OAuth
565
+ // account pool and a distinct rail from the existing xai/* API-key provider.
566
+ supergrokSubscriptionEnabled: EnvBoolean.default(false), // OPENGENI_SUPERGROK_SUBSCRIPTION_ENABLED
512
567
  // Expose the connected apps attached to a Codex subscription through the
513
568
  // synthetic codex_apps MCP server. Independent from subscription routing so
514
569
  // operators can use Codex models without exposing ChatGPT connectors.
@@ -608,7 +663,13 @@ const SettingsSchema = z.object({
608
663
  // the Modal session envelope persists the actual image ID.
609
664
  modalImageId: z
610
665
  .string()
611
- .regex(/^im-[A-Za-z0-9]{22}$/)
666
+ // Modal image IDs are provider-opaque. Older builds use a 22-character
667
+ // random suffix while current filesystem snapshots use a 26-character
668
+ // ULID suffix. Validate the stable namespace/safe alphabet and let Modal
669
+ // remain authoritative over current/future suffix lengths.
670
+ .min(4)
671
+ .max(128)
672
+ .regex(/^im-[A-Za-z0-9]+$/)
612
673
  .optional(),
613
674
  // Name of a Modal Secret (containing REGISTRY_USERNAME + REGISTRY_PASSWORD) used
614
675
  // to authenticate the pull of `modalImageRef` from a PRIVATE registry. When UNSET
@@ -654,8 +715,9 @@ const SettingsSchema = z.object({
654
715
  // /workspace FILE PERSISTENCE across warm/cold cycles. Directory snapshots
655
716
  // preserve only the durable user workspace, so provider recovery does not
656
717
  // restore an entire machine image or replace the selected rig/base image.
657
- // Existing serialized sessions retain their original persistence mode and
658
- // remain recoverable; this default governs newly created Modal sandboxes.
718
+ // Cold restore derives the mode from its verified native artifact, so existing
719
+ // serialized sessions remain recoverable; this default governs archive-free
720
+ // Modal creations only.
659
721
  // `snapshot_filesystem` remains available for explicit compatibility and
660
722
  // immutable rig-image materialization. `tar` is the portable fallback.
661
723
  modalWorkspacePersistence: z
@@ -739,6 +801,14 @@ const SettingsSchema = z.object({
739
801
  // --- cloudflare (headless) ---
740
802
  cloudflareWorkerUrl: z.string().url().optional(),
741
803
  cloudflareApiKey: z.string().optional(),
804
+ // --- remote browser placements ---
805
+ // Provider credentials are injected only into the placement-resident
806
+ // browserd launch. They never enter session contracts, journals, or sandboxes.
807
+ browserbaseApiKey: z.string().min(1).max(8192).optional(),
808
+ kernelApiKey: z.string().min(1).max(8192).optional(),
809
+ kernelEndpoint: z.string().url().optional(),
810
+ kernelBrowserTimeoutSeconds: z.coerce.number().int().positive().max(86_400).default(3_600),
811
+ kernelBrowserStealth: EnvBoolean.default(false),
742
812
  // --- vercel (headless) ---
743
813
  vercelToken: z.string().optional(),
744
814
  vercelProjectId: z.string().optional(),
@@ -1027,7 +1097,11 @@ export type Settings = z.infer<typeof SettingsSchema>;
1027
1097
  export type McpServerConfig = Settings["mcpServers"][number];
1028
1098
 
1029
1099
  /** Declarative voice-input transcription provider ids. */
1030
- export type VoiceInputProviderId = "openai" | "azure-openai" | "codex-subscription";
1100
+ export type VoiceInputProviderId =
1101
+ | "openai"
1102
+ | "azure-openai"
1103
+ | "codex-subscription"
1104
+ | "supergrok-subscription";
1031
1105
 
1032
1106
  export type VoiceInputProviderConfig =
1033
1107
  | {
@@ -1050,6 +1124,11 @@ export type VoiceInputProviderConfig =
1050
1124
  id: "codex-subscription";
1051
1125
  kind: "codex-subscription";
1052
1126
  experimental: true;
1127
+ }
1128
+ | {
1129
+ id: "supergrok-subscription";
1130
+ kind: "supergrok-subscription";
1131
+ experimental: true;
1053
1132
  };
1054
1133
 
1055
1134
  /**
@@ -1086,7 +1165,10 @@ export function resolveVoiceInputProviderRegistry(settings: Settings): VoiceInpu
1086
1165
  .map((part) => part.trim())
1087
1166
  .filter(
1088
1167
  (part): part is VoiceInputProviderId =>
1089
- part === "openai" || part === "azure-openai" || part === "codex-subscription",
1168
+ part === "openai" ||
1169
+ part === "azure-openai" ||
1170
+ part === "codex-subscription" ||
1171
+ part === "supergrok-subscription",
1090
1172
  );
1091
1173
  const seen = new Set<VoiceInputProviderId>();
1092
1174
  const providers: VoiceInputProviderConfig[] = [];
@@ -1174,6 +1256,15 @@ export function resolveVoiceInputProviderRegistry(settings: Settings): VoiceInpu
1174
1256
  kind: "codex-subscription",
1175
1257
  experimental: true,
1176
1258
  });
1259
+ continue;
1260
+ }
1261
+ if (id === "supergrok-subscription") {
1262
+ if (!settings.supergrokSubscriptionEnabled) continue;
1263
+ providers.push({
1264
+ id: "supergrok-subscription",
1265
+ kind: "supergrok-subscription",
1266
+ experimental: true,
1267
+ });
1177
1268
  }
1178
1269
  }
1179
1270
  return providers;
@@ -1182,7 +1273,8 @@ export function resolveVoiceInputProviderRegistry(settings: Settings): VoiceInpu
1182
1273
  /** True when the deployment has at least one supported (non-experimental) provider. */
1183
1274
  export function voiceInputDeploymentConfigured(settings: Settings): boolean {
1184
1275
  return resolveVoiceInputProviderRegistry(settings).some(
1185
- (provider) => provider.kind !== "codex-subscription",
1276
+ (provider) =>
1277
+ provider.kind !== "codex-subscription" && provider.kind !== "supergrok-subscription",
1186
1278
  );
1187
1279
  }
1188
1280
 
@@ -1398,7 +1490,7 @@ export type ModelExecutionLimitsV1 = {
1398
1490
 
1399
1491
  export type CredentialSourceV1 =
1400
1492
  | { kind: "deployment"; mechanism: "api_key" | "azure_ad_bearer" }
1401
- | { kind: "connected_subscription"; provider: "codex" }
1493
+ | { kind: "connected_subscription"; provider: "codex" | "xai" }
1402
1494
  | { kind: "workspace_connection"; mechanism: "api_key" };
1403
1495
 
1404
1496
  export type BillingAttributionV1 = {
@@ -1418,12 +1510,13 @@ export type ModelProviderApi = z.infer<typeof ModelProviderApi>;
1418
1510
 
1419
1511
  /**
1420
1512
  * Registry provider kind. "api-key" providers carry their own static key/headers;
1421
- * "codex-subscription" providers authenticate per-request with a ChatGPT/Codex
1422
- * subscription token resolved at call time (no static key) see @opengeni/codex.
1513
+ * connected-subscription providers resolve a workspace account token at call
1514
+ * time and never carry a static key in the registry definition.
1423
1515
  */
1424
1516
  export const RegistryProviderKind = z.enum([
1425
1517
  "api-key",
1426
1518
  "codex-subscription",
1519
+ "xai-subscription",
1427
1520
  "vercel-gateway-managed",
1428
1521
  "vercel-gateway-workspace",
1429
1522
  ]);
@@ -1573,6 +1666,7 @@ export const VERCEL_AI_GATEWAY_CONNECTION_DOMAIN = "ai-gateway.vercel.sh" as con
1573
1666
  export const VERCEL_AI_GATEWAY_CONNECTION_ROLE = "vercel_ai_gateway" as const;
1574
1667
 
1575
1668
  export const CODEX_REALTIME_MODEL_ID = "gpt-live-1-boulder-alpha" as const;
1669
+ export const SUPERGROK_REALTIME_MODEL_ID = "supergrok/grok-voice-think-fast-2.0" as const;
1576
1670
  export const OPENGENI_REALTIME_MODEL_ID_PREFIX = "opengeni-gateway/" as const;
1577
1671
  export const WORKSPACE_REALTIME_MODEL_ID_PREFIX = "workspace-gateway/" as const;
1578
1672
 
@@ -1867,6 +1961,8 @@ export function getSettings(): Settings {
1867
1961
  staticEntitlementsJson: optional("OPENGENI_STATIC_ENTITLEMENTS_JSON"),
1868
1962
  staticUsageLimitsJson: optional("OPENGENI_STATIC_USAGE_LIMITS_JSON"),
1869
1963
  delegationSecret: optional("OPENGENI_DELEGATION_SECRET"),
1964
+ defaultFirstPartyMcpTools: optional("OPENGENI_DEFAULT_FIRST_PARTY_MCP_TOOLS"),
1965
+ allowedFirstPartyMcpTools: optional("OPENGENI_ALLOWED_FIRST_PARTY_MCP_TOOLS"),
1870
1966
  streamTokenSecret: optional("OPENGENI_STREAM_TOKEN_SECRET"),
1871
1967
  streamControlEnabled: optional("OPENGENI_STREAM_CONTROL_ENABLED"),
1872
1968
  codemodeMaxCallsPerTurn: optional("OPENGENI_CODEMODE_MAX_CALLS_PER_TURN"),
@@ -1884,6 +1980,8 @@ export function getSettings(): Settings {
1884
1980
  slackSigningSecret: optional("OPENGENI_SLACK_SIGNING_SECRET"),
1885
1981
  googleDriveClientId: optional("OPENGENI_GOOGLE_DRIVE_CLIENT_ID"),
1886
1982
  googleDriveClientSecret: optional("OPENGENI_GOOGLE_DRIVE_CLIENT_SECRET"),
1983
+ fikenClientId: optional("OPENGENI_FIKEN_OAUTH_CLIENT_ID"),
1984
+ fikenClientSecret: optional("OPENGENI_FIKEN_OAUTH_CLIENT_SECRET"),
1887
1985
  googleDriveWorkspaceEventsEnabled: optional("OPENGENI_GOOGLE_DRIVE_WORKSPACE_EVENTS_ENABLED"),
1888
1986
  atlassianClientId: optional("OPENGENI_ATLASSIAN_CLIENT_ID"),
1889
1987
  atlassianClientSecret: optional("OPENGENI_ATLASSIAN_CLIENT_SECRET"),
@@ -1960,6 +2058,7 @@ export function getSettings(): Settings {
1960
2058
  modelPricingJson: optional("OPENGENI_MODEL_PRICING_JSON"),
1961
2059
  modelProvidersJson: optional("OPENGENI_MODEL_PROVIDERS_JSON"),
1962
2060
  codexSubscriptionEnabled: optional("OPENGENI_CODEX_SUBSCRIPTION_ENABLED"),
2061
+ supergrokSubscriptionEnabled: optional("OPENGENI_SUPERGROK_SUBSCRIPTION_ENABLED"),
1963
2062
  codexConnectedAppsEnabled: optional("OPENGENI_CODEX_CONNECTED_APPS_ENABLED"),
1964
2063
  codexToolSearchEnabled: optional("OPENGENI_CODEX_TOOL_SEARCH_ENABLED"),
1965
2064
  lazyToolSearchEnabled: optional("OPENGENI_LAZY_TOOL_SEARCH_ENABLED"),
@@ -2040,6 +2139,11 @@ export function getSettings(): Settings {
2040
2139
  blaxelTtl: optional("OPENGENI_BLAXEL_TTL"),
2041
2140
  cloudflareWorkerUrl: optional("OPENGENI_CLOUDFLARE_WORKER_URL"),
2042
2141
  cloudflareApiKey: optional("OPENGENI_CLOUDFLARE_API_KEY"),
2142
+ browserbaseApiKey: optional("OPENGENI_BROWSERBASE_API_KEY"),
2143
+ kernelApiKey: optional("OPENGENI_KERNEL_API_KEY"),
2144
+ kernelEndpoint: optional("OPENGENI_KERNEL_ENDPOINT"),
2145
+ kernelBrowserTimeoutSeconds: optional("OPENGENI_KERNEL_BROWSER_TIMEOUT_SECONDS"),
2146
+ kernelBrowserStealth: optional("OPENGENI_KERNEL_BROWSER_STEALTH"),
2043
2147
  vercelToken: optional("OPENGENI_VERCEL_TOKEN"),
2044
2148
  vercelProjectId: optional("OPENGENI_VERCEL_PROJECT_ID"),
2045
2149
  vercelTeamId: optional("OPENGENI_VERCEL_TEAM_ID"),
@@ -2164,12 +2268,44 @@ const LOCAL_FIRST_PARTY_DELEGATION_SECRET = "opengeni-local-first-party-delegati
2164
2268
  export function resolveFirstPartyDelegationSecret(settings: Settings): string | undefined {
2165
2269
  const explicit = settings.delegationSecret?.trim();
2166
2270
  if (explicit) return explicit;
2271
+ const configuredAccessKey = settings.accessKey?.trim();
2272
+ if (settings.productAccessMode === "configured" && settings.authRequired && configuredAccessKey) {
2273
+ return configuredAccessKey;
2274
+ }
2167
2275
  return settings.productAccessMode === "local" &&
2168
2276
  (settings.environment === "local" || settings.environment === "test")
2169
2277
  ? LOCAL_FIRST_PARTY_DELEGATION_SECRET
2170
2278
  : undefined;
2171
2279
  }
2172
2280
 
2281
+ export type FirstPartyMcpToolPolicy = {
2282
+ default: FirstPartyMcpToolNameType[];
2283
+ allowed: FirstPartyMcpToolNameType[];
2284
+ };
2285
+
2286
+ /** Resolve the deployment's session-tool defaults and hard execution ceiling. */
2287
+ export function resolveFirstPartyMcpToolPolicy(
2288
+ settings: Pick<Settings, "defaultFirstPartyMcpTools" | "allowedFirstPartyMcpTools">,
2289
+ ): FirstPartyMcpToolPolicy {
2290
+ const allowed = settings.allowedFirstPartyMcpTools ?? [...FIRST_PARTY_MCP_TOOL_NAMES];
2291
+ const allowedSet = new Set(allowed);
2292
+ const defaults = settings.defaultFirstPartyMcpTools ?? [...DEFAULT_FIRST_PARTY_MCP_TOOLS];
2293
+ return {
2294
+ default: defaults.filter((tool) => allowedSet.has(tool)),
2295
+ allowed: [...allowed],
2296
+ };
2297
+ }
2298
+
2299
+ /** Apply the deployment ceiling to an existing durable session selection. */
2300
+ export function allowedFirstPartyMcpToolsForSession(
2301
+ settings: Pick<Settings, "defaultFirstPartyMcpTools" | "allowedFirstPartyMcpTools">,
2302
+ selected: readonly FirstPartyMcpToolNameType[] | null | undefined,
2303
+ ): FirstPartyMcpToolNameType[] {
2304
+ const policy = resolveFirstPartyMcpToolPolicy(settings);
2305
+ const allowed = new Set(policy.allowed);
2306
+ return [...(selected ?? policy.default)].filter((tool) => allowed.has(tool));
2307
+ }
2308
+
2173
2309
  /**
2174
2310
  * The Modal sandbox idle timeout (seconds) the provider actually passes as
2175
2311
  * idleTimeoutMs (sandbox-file-persistence). When the operator did not pin
@@ -2655,12 +2791,17 @@ const GPT56_FAST_BILLING_MULTIPLIER_BPS = 20_000;
2655
2791
  /**
2656
2792
  * Product display label for catalog/picker UI.
2657
2793
  * Same string for OpenAI and Codex copies of a slug (`gpt-5.6-luna` and
2658
- * `codex/gpt-5.6-luna` → `GPT-5.6 Luna`). Non-gpt ids pass through unchanged.
2794
+ * `codex/gpt-5.6-luna` → `GPT-5.6 Luna`). Curated Grok slugs receive the same
2795
+ * product casing; other ids pass through unchanged.
2659
2796
  */
2660
2797
  export function productLabelForModelId(modelId: string): string {
2661
2798
  const slug = modelId.startsWith(CODEX_MODEL_ID_PREFIX)
2662
2799
  ? modelId.slice(CODEX_MODEL_ID_PREFIX.length)
2663
2800
  : modelId;
2801
+ const grokMatch = /^grok-(\d+(?:\.\d+)?)$/i.exec(slug);
2802
+ if (grokMatch) {
2803
+ return `Grok ${grokMatch[1]}`;
2804
+ }
2664
2805
  const match = /^(gpt-\d+(?:\.\d+)?)(?:-(.+))?$/i.exec(slug);
2665
2806
  if (!match) {
2666
2807
  return slug;
@@ -2679,14 +2820,16 @@ export function productLabelForModelId(modelId: string): string {
2679
2820
  }
2680
2821
 
2681
2822
  /**
2682
- * Curated compact product labels for dense UI. Only known GPT family slugs;
2683
- * everything else returns null so callers fall back to the full `label`.
2823
+ * Curated compact product labels for dense UI. Unknown model slugs return null
2824
+ * so callers fall back to the full `label`.
2684
2825
  */
2685
2826
  export function productShortLabelForModelId(modelId: string): string | null {
2686
2827
  const slug = modelId.startsWith(CODEX_MODEL_ID_PREFIX)
2687
2828
  ? modelId.slice(CODEX_MODEL_ID_PREFIX.length)
2688
2829
  : modelId;
2689
2830
  switch (slug) {
2831
+ case "grok-4.6":
2832
+ return "4.6";
2690
2833
  case "gpt-5.6-sol":
2691
2834
  return "5.6 Sol";
2692
2835
  case "gpt-5.6-terra":
@@ -2765,7 +2908,7 @@ export function isDirectOpenAiApiBaseUrl(baseUrl: string | undefined): boolean {
2765
2908
 
2766
2909
  /**
2767
2910
  * Map OpenGeni latency mode to the provider `service_tier` wire value.
2768
- * Azure and Codex ChatGPT accept `priority`; OpenAI API accepts `fast` (alias of priority).
2911
+ * Azure, Codex ChatGPT, and xAI accept `priority`; OpenAI API accepts `fast`.
2769
2912
  * Standard omits the field.
2770
2913
  */
2771
2914
  export function serviceTierForLatencyMode(
@@ -2775,7 +2918,11 @@ export function serviceTierForLatencyMode(
2775
2918
  if (latencyMode === "standard") {
2776
2919
  return undefined;
2777
2920
  }
2778
- if (providerId === "azure" || providerId === CODEX_PROVIDER_ID) {
2921
+ if (
2922
+ providerId === "azure" ||
2923
+ providerId === CODEX_PROVIDER_ID ||
2924
+ providerId === XAI_SUBSCRIPTION_PROVIDER_ID
2925
+ ) {
2779
2926
  return "priority";
2780
2927
  }
2781
2928
  return "fast";
@@ -2822,6 +2969,9 @@ function registryCredentialSource(provider: RegistryProvider): CredentialSourceV
2822
2969
  if (provider.kind === "codex-subscription") {
2823
2970
  return { kind: "connected_subscription", provider: "codex" };
2824
2971
  }
2972
+ if (provider.kind === "xai-subscription") {
2973
+ return { kind: "connected_subscription", provider: "xai" };
2974
+ }
2825
2975
  if (provider.kind === "vercel-gateway-workspace") {
2826
2976
  return { kind: "workspace_connection", mechanism: "api_key" };
2827
2977
  }
@@ -2829,7 +2979,7 @@ function registryCredentialSource(provider: RegistryProvider): CredentialSourceV
2829
2979
  }
2830
2980
 
2831
2981
  function registryBilling(provider: RegistryProvider): BillingAttributionV1 {
2832
- if (provider.kind === "codex-subscription") {
2982
+ if (provider.kind === "codex-subscription" || provider.kind === "xai-subscription") {
2833
2983
  return { upstreamPayer: "connected_subscription", metering: "external" };
2834
2984
  }
2835
2985
  if (provider.kind === "vercel-gateway-workspace") {
@@ -3049,6 +3199,55 @@ export function withCodexCatalogProvider(settings: Settings): Settings {
3049
3199
  };
3050
3200
  }
3051
3201
 
3202
+ /**
3203
+ * Static SuperGrok product catalogue, matching the Codex subscription seam.
3204
+ * The overlay never contains a concrete account id or bearer; selection and
3205
+ * per-turn credential freeze remain worker/DB responsibilities.
3206
+ */
3207
+ export function withXaiSubscriptionCatalogProvider(settings: Settings): Settings {
3208
+ const providers = parseModelProvidersJson(settings.modelProvidersJson);
3209
+ if (providers.some((provider) => provider.id === XAI_SUBSCRIPTION_PROVIDER_ID)) {
3210
+ return settings;
3211
+ }
3212
+ const provider: RegistryProvider = {
3213
+ kind: "xai-subscription",
3214
+ id: XAI_SUBSCRIPTION_PROVIDER_ID,
3215
+ label: "SuperGrok (xAI subscription)",
3216
+ api: "responses",
3217
+ baseUrl: XAI_SUBSCRIPTION_PROXY_BASE_URL,
3218
+ models: XAI_SUBSCRIPTION_MODEL_SLUGS.map((slug) => {
3219
+ const capabilities = legacyModelCapabilities(settings, {
3220
+ reasoningEffort: true,
3221
+ hostedWebSearch: true,
3222
+ });
3223
+ capabilities.reasoning.efforts = ["low", "medium", "high", "xhigh"];
3224
+ capabilities.reasoning.defaultEffort = "high";
3225
+ capabilities.latencyModes = [
3226
+ { id: "standard", upstream: "supported", runnable: true },
3227
+ { id: "fast", upstream: "supported", runnable: true },
3228
+ ];
3229
+ capabilities.hostedTools.xSearch = { upstream: "supported", runnable: true };
3230
+ capabilities.hostedTools.imageGeneration = { upstream: "supported", runnable: true };
3231
+ return {
3232
+ id: `${XAI_SUBSCRIPTION_MODEL_ID_PREFIX}${slug}`,
3233
+ upstreamModelId: slug,
3234
+ label: productLabelForModelId(slug),
3235
+ ...(productShortLabelForModelId(slug)
3236
+ ? { shortLabel: productShortLabelForModelId(slug)! }
3237
+ : {}),
3238
+ reasoningEffort: true,
3239
+ hostedWebSearch: true,
3240
+ capabilities,
3241
+ contextWindowTokens: XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS,
3242
+ effectiveContextWindowTokens: XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS,
3243
+ autoCompactTokenLimit: XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT,
3244
+ toolOutputTruncationTokens: settings.modelToolOutputTruncationTokens,
3245
+ };
3246
+ }),
3247
+ };
3248
+ return { ...settings, modelProvidersJson: JSON.stringify([...providers, provider]) };
3249
+ }
3250
+
3052
3251
  /**
3053
3252
  * The provider identity a model id resolves to, for workspace model-policy
3054
3253
  * evaluation — MUST agree with the real router (resolveTurnModel /
@@ -3067,6 +3266,9 @@ export function policyProviderIdForModel(settings: Settings, modelId: string): s
3067
3266
  if (canonicalModelId.startsWith(CODEX_MODEL_ID_PREFIX)) {
3068
3267
  return CODEX_PROVIDER_ID;
3069
3268
  }
3269
+ if (canonicalModelId.startsWith(XAI_SUBSCRIPTION_MODEL_ID_PREFIX)) {
3270
+ return XAI_SUBSCRIPTION_PROVIDER_ID;
3271
+ }
3070
3272
  if (canonicalModelId.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX)) {
3071
3273
  return WORKSPACE_GATEWAY_PROVIDER_ID;
3072
3274
  }
@@ -3187,6 +3389,7 @@ export function configuredModels(settings: Settings): ConfiguredModel[] {
3187
3389
  );
3188
3390
  const isRegistryNamespaced = (id: string): boolean =>
3189
3391
  id.startsWith(CODEX_MODEL_ID_PREFIX) ||
3392
+ id.startsWith(XAI_SUBSCRIPTION_MODEL_ID_PREFIX) ||
3190
3393
  registryAliases.has(id) ||
3191
3394
  (id.includes("/") && registryOwnedIds.has(id));
3192
3395
  const builtinProvider = providerById.get(builtinId);
@@ -3353,6 +3556,12 @@ function settingsForTurnExecutionPolicy(settings: Settings, modelId: string): Se
3353
3556
  if (settings.codexSubscriptionEnabled && modelId.startsWith(CODEX_MODEL_ID_PREFIX)) {
3354
3557
  return withCodexCatalogProvider(settings);
3355
3558
  }
3559
+ if (
3560
+ settings.supergrokSubscriptionEnabled &&
3561
+ modelId.startsWith(XAI_SUBSCRIPTION_MODEL_ID_PREFIX)
3562
+ ) {
3563
+ return withXaiSubscriptionCatalogProvider(settings);
3564
+ }
3356
3565
  if (modelId.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX)) {
3357
3566
  return withWorkspaceGatewayCatalogProvider(settings);
3358
3567
  }
@@ -4455,6 +4664,8 @@ function ensureBuiltInMcpServers(settings: Settings): Settings["mcpServers"] {
4455
4664
  "list_document_bases",
4456
4665
  "list_indexed_documents",
4457
4666
  "knowledge_search",
4667
+ "knowledge_get",
4668
+ "knowledge_browse",
4458
4669
  "knowledge_fetch",
4459
4670
  "memory_search",
4460
4671
  "memory_propose",
@@ -4507,11 +4718,30 @@ export function firstPartyMcpWorkspaceUrl(settings: Settings, workspaceId: strin
4507
4718
  }
4508
4719
 
4509
4720
  export function codemodeWorkspaceUrl(settings: Settings, workspaceId: string): string {
4510
- const url = new URL(firstPartyMcpWorkspaceUrl(settings, workspaceId));
4511
- if (!url.pathname.endsWith("/mcp")) {
4512
- throw new Error("First-party MCP URL cannot be projected to the Codemode endpoint");
4513
- }
4514
- url.pathname = `${url.pathname.slice(0, -4)}/codemode`;
4721
+ if (settings.opengeniMcpUrl) {
4722
+ const url = new URL(firstPartyMcpWorkspaceUrl(settings, workspaceId));
4723
+ if (!url.pathname.endsWith("/mcp")) {
4724
+ throw new Error("First-party MCP URL cannot be projected to the Codemode endpoint");
4725
+ }
4726
+ url.pathname = `${url.pathname.slice(0, -4)}/codemode`;
4727
+ return url.toString();
4728
+ }
4729
+
4730
+ // Codemode executes inside the selected placement, not beside the worker.
4731
+ // Local Docker reaches the host through Docker's canonical host alias; an
4732
+ // in-process local sandbox uses loopback; remote managed providers use the
4733
+ // deployment's public origin. `OPENGENI_MCP_URL` above remains the explicit
4734
+ // escape hatch for mounted deployments and local remote-provider tunnels.
4735
+ const executionOrigin =
4736
+ settings.sandboxBackend === "docker"
4737
+ ? `http://host.docker.internal:${settings.apiPort}`
4738
+ : settings.sandboxBackend === "local"
4739
+ ? `http://127.0.0.1:${settings.apiPort}`
4740
+ : (settings.publicBaseUrl ?? `http://127.0.0.1:${settings.apiPort}`);
4741
+ const url = new URL(executionOrigin);
4742
+ url.pathname = `${url.pathname.replace(/\/+$/u, "")}/v1/workspaces/${workspaceId}/codemode`;
4743
+ url.search = "";
4744
+ url.hash = "";
4515
4745
  return url.toString();
4516
4746
  }
4517
4747
 
@@ -4529,6 +4759,17 @@ function firstPartyFilesMcpServerUrl(mcpUrl: string): string {
4529
4759
 
4530
4760
  function validateSettings(settings: Settings): void {
4531
4761
  temporalConnectionOptions(settings);
4762
+ const allowedFirstPartyMcpTools = new Set(
4763
+ settings.allowedFirstPartyMcpTools ?? FIRST_PARTY_MCP_TOOL_NAMES,
4764
+ );
4765
+ const disallowedDefaults = (settings.defaultFirstPartyMcpTools ?? []).filter(
4766
+ (tool) => !allowedFirstPartyMcpTools.has(tool),
4767
+ );
4768
+ if (disallowedDefaults.length > 0) {
4769
+ throw new Error(
4770
+ `OPENGENI_DEFAULT_FIRST_PARTY_MCP_TOOLS must be a subset of OPENGENI_ALLOWED_FIRST_PARTY_MCP_TOOLS: ${disallowedDefaults.join(", ")}`,
4771
+ );
4772
+ }
4532
4773
  if (settings.productAccessMode === "managed") {
4533
4774
  if (!settings.publicBaseUrl) {
4534
4775
  throw new Error(
@@ -4606,6 +4847,31 @@ function validateSettings(settings: Settings): void {
4606
4847
  "OPENGENI_GOOGLE_DRIVE_CLIENT_ID and OPENGENI_GOOGLE_DRIVE_CLIENT_SECRET must be configured together",
4607
4848
  );
4608
4849
  }
4850
+ if (Boolean(settings.fikenClientId) !== Boolean(settings.fikenClientSecret)) {
4851
+ throw new Error(
4852
+ "OPENGENI_FIKEN_OAUTH_CLIENT_ID and OPENGENI_FIKEN_OAUTH_CLIENT_SECRET must be configured together",
4853
+ );
4854
+ }
4855
+ if (settings.fikenClientId) {
4856
+ if (!settings.publicBaseUrl) {
4857
+ throw new Error(
4858
+ "OPENGENI_PUBLIC_BASE_URL is required when the Fiken OAuth integration is configured",
4859
+ );
4860
+ }
4861
+ if (
4862
+ !settings.publicBaseUrl.startsWith("https://") &&
4863
+ !["local", "test"].includes(settings.environment)
4864
+ ) {
4865
+ throw new Error(
4866
+ "OPENGENI_PUBLIC_BASE_URL must use https when the Fiken OAuth integration is configured outside local/test",
4867
+ );
4868
+ }
4869
+ if (!settings.integrationsStateSecret) {
4870
+ throw new Error(
4871
+ "OPENGENI_INTEGRATIONS_STATE_SECRET is required when the Fiken OAuth integration is configured",
4872
+ );
4873
+ }
4874
+ }
4609
4875
  if (settings.googleDriveClientId) {
4610
4876
  if (!settings.publicBaseUrl) {
4611
4877
  throw new Error(
@@ -4979,10 +5245,11 @@ function validateSettings(settings: Settings): void {
4979
5245
  for (const provider of registryProviders) {
4980
5246
  if (
4981
5247
  provider.kind === "vercel-gateway-managed" ||
4982
- provider.kind === "vercel-gateway-workspace"
5248
+ provider.kind === "vercel-gateway-workspace" ||
5249
+ provider.kind === "xai-subscription"
4983
5250
  ) {
4984
5251
  throw new Error(
4985
- `OPENGENI_MODEL_PROVIDERS_JSON provider kind ${provider.kind} is reserved for the reviewed AI Gateway broker`,
5252
+ `OPENGENI_MODEL_PROVIDERS_JSON provider kind ${provider.kind} is reserved for a reviewed OpenGeni credential broker`,
4986
5253
  );
4987
5254
  }
4988
5255
  if (provider.id === builtinId) {