Open History to see the last commit
1import * as DateTime from "effect/DateTime";
2import * as Duration from "effect/Duration";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as Option from "effect/Option";
6import * as Result from "effect/Result";
7import * as Schema from "effect/Schema";
8import * as Scope from "effect/Scope";
9import * as Types from "effect/Types";
10import * as ChildProcess from "effect/unstable/process/ChildProcess";
11import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
12import * as CodexClient from "effect-codex-app-server/client";
13import * as CodexSchema from "effect-codex-app-server/schema";
14import * as CodexErrors from "effect-codex-app-server/errors";
15
16import type {
17 CodexSettings,
18 CustomModelSetting,
19 ServerProvider,
20 ServerProviderState,
21 ModelCapabilities,
22 ProviderOptionDescriptor,
23 ServerProviderModel,
24 ServerProviderSkill,
25} from "@t3tools/contracts";
26import { PREFERRED_DEFAULT_CODEX_MODELS, ServerSettingsError } from "@t3tools/contracts";
27
28import { createModelCapabilities, readCustomModelEntries } from "@t3tools/shared/model";
29import { resolveSpawnCommand } from "@t3tools/shared/shell";
30import { codexAppServerArgs, resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
31import {
32 AUTH_PROBE_TIMEOUT_MS,
33 buildServerProvider,
34 COMPACT_SLASH_COMMAND,
35 type ServerProviderDraft,
36} from "../providerSnapshot.ts";
37import { expandHomePath } from "../../pathExpansion.ts";
38import { makeUnavailableUsageLimits } from "../providerUsageLimits.ts";
39import {
40 codexRateLimitsFailureMessage,
41 codexRateLimitsToLimits,
42 type CodexRateLimitSnapshot,
43 type CodexResetCreditsSummary,
44} from "./codexUsageLimits.ts";
45import packageJson from "../../../package.json" with { type: "json" };
46const isCodexAppServerSpawnError = Schema.is(CodexErrors.CodexAppServerSpawnError);
47const RATE_LIMITS_PROBE_TIMEOUT_MS = 3_000;
48
49type CodexRateLimitsProbe =
50 | {
51 readonly snapshot: CodexRateLimitSnapshot;
52 readonly rateLimitsByLimitId?:
53 | Readonly<Record<string, CodexRateLimitSnapshot>>
54 | null
55 | undefined;
56 readonly resetCredits: CodexResetCreditsSummary | null | undefined;
57 }
58 | { readonly failure: string };
59
60const CODEX_APP_SERVER_PROBE_FORCE_KILL_AFTER = "2 seconds" as const;
61
62const CODEX_PRESENTATION = {
63 displayName: "Codex",
64 showInteractionModeToggle: true,
65 reportsContextWindow: true,
66} as const;
67
68export interface CodexAppServerProviderSnapshot {
69 readonly account: CodexSchema.V2GetAccountResponse;
70 readonly rateLimits?: CodexRateLimitsProbe;
71 readonly version: string | undefined;
72 readonly models: ReadonlyArray<ServerProviderModel>;
73 readonly skills: ReadonlyArray<ServerProviderSkill>;
74}
75
76const REASONING_EFFORT_LABELS: Readonly<Record<string, string>> = {
77 none: "None",
78 minimal: "Minimal",
79 low: "Low",
80 medium: "Medium",
81 high: "High",
82 xhigh: "Extra High",
83 max: "Max",
84 ultra: "Ultra",
85};
86
87const DEFAULT_SERVICE_TIER_ID = "default";
88
89function reasoningEffortLabel(reasoningEffort: string): string {
90 return REASONING_EFFORT_LABELS[reasoningEffort] ?? reasoningEffort;
91}
92
93function codexAccountAuthLabel(account: CodexSchema.V2GetAccountResponse["account"]) {
94 if (!account) return undefined;
95 if (account.type === "apiKey") return "OpenAI API Key";
96 if (account.type === "amazonBedrock") return "Amazon Bedrock";
97 if (account.type !== "chatgpt") return undefined;
98 return codexPlanLabel(account.planType);
99}
100
101/** Shared with usage-limit sources, which report the same `planType` slugs. */
102export function codexPlanLabel(planType: string | null | undefined): string | undefined {
103 switch (planType) {
104 case "free":
105 return "ChatGPT Free Subscription";
106 case "go":
107 return "ChatGPT Go Subscription";
108 case "plus":
109 return "ChatGPT Plus Subscription";
110 case "pro":
111 return "ChatGPT Pro 20x Subscription";
112 case "prolite":
113 return "ChatGPT Pro 5x Subscription";
114 case "team":
115 return "ChatGPT Team Subscription";
116 case "self_serve_business_prolite":
117 case "self_serve_business_usage_based":
118 case "business":
119 return "ChatGPT Business Subscription";
120 case "ent26":
121 case "enterprise_cbp_automation":
122 case "enterprise_cbp_usage_based":
123 case "enterprise":
124 return "ChatGPT Enterprise Subscription";
125 case "edu":
126 case "edu_plus":
127 case "edu_pro":
128 return "ChatGPT Edu Subscription";
129 case "unknown":
130 return "ChatGPT Subscription";
131 default:
132 return undefined;
133 }
134}
135
136function codexAccountEmail(account: CodexSchema.V2GetAccountResponse["account"]) {
137 if (!account || account.type !== "chatgpt") return undefined;
138 return account.email;
139}
140
141export function mapCodexModelCapabilities(
142 model: CodexSchema.V2ModelListResponse__Model,
143): ModelCapabilities {
144 const reasoningOptions = model.supportedReasoningEfforts.map(({ reasoningEffort }) =>
145 reasoningEffort === model.defaultReasoningEffort
146 ? {
147 id: reasoningEffort,
148 label: reasoningEffortLabel(reasoningEffort),
149 isDefault: true,
150 }
151 : {
152 id: reasoningEffort,
153 label: reasoningEffortLabel(reasoningEffort),
154 },
155 );
156 const defaultReasoning = reasoningOptions.find((option) => option.isDefault)?.id;
157 const serviceTiers =
158 model.serviceTiers && model.serviceTiers.length > 0
159 ? model.serviceTiers
160 : (model.additionalSpeedTiers ?? []).map((id) => ({
161 id,
162 name: id === "fast" ? "Fast" : id,
163 description: "",
164 }));
165 const catalogDefaultServiceTier = serviceTiers.some(
166 (tier) => tier.id === model.defaultServiceTier,
167 )
168 ? model.defaultServiceTier
169 : null;
170 const defaultServiceTier = catalogDefaultServiceTier ?? DEFAULT_SERVICE_TIER_ID;
171 const optionDescriptors: ProviderOptionDescriptor[] = [];
172
173 if (reasoningOptions.length > 0) {
174 optionDescriptors.push({
175 id: "reasoningEffort",
176 label: "Reasoning",
177 type: "select",
178 options: reasoningOptions,
179 ...(defaultReasoning ? { currentValue: defaultReasoning } : {}),
180 });
181 }
182 if (serviceTiers.length > 0) {
183 optionDescriptors.push({
184 id: "serviceTier",
185 label: "Service Tier",
186 type: "select",
187 options: [
188 {
189 id: DEFAULT_SERVICE_TIER_ID,
190 label: "Standard",
191 ...(defaultServiceTier === DEFAULT_SERVICE_TIER_ID ? { isDefault: true } : {}),
192 },
193 ...serviceTiers.map((tier) => ({
194 id: tier.id,
195 label: tier.name,
196 ...(tier.description ? { description: tier.description } : {}),
197 ...(defaultServiceTier === tier.id ? { isDefault: true } : {}),
198 })),
199 ],
200 currentValue: defaultServiceTier,
201 });
202 }
203
204 return createModelCapabilities({
205 optionDescriptors,
206 });
207}
208
209const toDisplayName = (model: CodexSchema.V2ModelListResponse__Model): string => {
210 // Capitalize 'gpt' to 'GPT-' and capitalize any letter following a dash
211 return model.displayName
212 .replace(/^gpt/i, "GPT") // Handle start with 'gpt' or 'GPT'
213 .replace(/-([a-z])/g, (_, c) => "-" + c.toUpperCase());
214};
215
216function parseCodexModelListResponse(
217 response: CodexSchema.V2ModelListResponse,
218): ReadonlyArray<ServerProviderModel> {
219 return response.data.map((model) => ({
220 slug: model.model,
221 name: toDisplayName(model),
222 isCustom: false,
223 ...(model.isDefault ? { isDefault: true } : {}),
224 capabilities: mapCodexModelCapabilities(model),
225 }));
226}
227
228/**
229 * Prefer our own default-model ranking when one of the preferred slugs is in
230 * the live catalog; otherwise keep whatever Codex itself flagged as default.
231 */
232export function applyPreferredCodexDefaultModel(
233 models: ReadonlyArray<ServerProviderModel>,
234): ReadonlyArray<ServerProviderModel> {
235 const preferredSlug = PREFERRED_DEFAULT_CODEX_MODELS.find((slug) =>
236 models.some((model) => model.slug === slug && !model.isCustom),
237 );
238 if (!preferredSlug) {
239 return models;
240 }
241 return models.map((model) => {
242 if (model.slug === preferredSlug) {
243 return model.isDefault ? model : { ...model, isDefault: true };
244 }
245 if (!model.isDefault) {
246 return model;
247 }
248 const { isDefault: _isDefault, ...rest } = model;
249 return rest;
250 });
251}
252
253/**
254 * Codex has no static default capability set, so a bare custom slug borrows
255 * the first built-in's descriptors; an entry with its own capabilities keeps
256 * them.
257 */
258function appendCustomCodexModels(
259 models: ReadonlyArray<ServerProviderModel>,
260 customModels: ReadonlyArray<CustomModelSetting>,
261): ReadonlyArray<ServerProviderModel> {
262 if (customModels.length === 0) {
263 return models;
264 }
265
266 const seen = new Set(models.map((model) => model.slug));
267 const fallbackCapabilities = models.find((model) => model.capabilities)?.capabilities ?? null;
268 const customEntries: ServerProviderModel[] = [];
269 for (const entry of readCustomModelEntries(customModels)) {
270 if (seen.has(entry.slug)) {
271 continue;
272 }
273 seen.add(entry.slug);
274 customEntries.push({
275 slug: entry.slug,
276 name: entry.name,
277 isCustom: true,
278 capabilities: entry.capabilities ?? fallbackCapabilities,
279 });
280 }
281 return customEntries.length === 0 ? models : [...models, ...customEntries];
282}
283
284function parseCodexSkillsListResponse(
285 response: CodexSchema.V2SkillsListResponse,
286 cwd: string,
287): ReadonlyArray<ServerProviderSkill> {
288 const matchingEntry = response.data.find((entry) => entry.cwd === cwd);
289 const skills = matchingEntry
290 ? matchingEntry.skills
291 : response.data.flatMap((entry) => entry.skills);
292
293 return skills.map((skill) => {
294 const shortDescription =
295 skill.shortDescription ?? skill.interface?.shortDescription ?? undefined;
296
297 const parsedSkill: Types.Mutable<ServerProviderSkill> = {
298 name: skill.name,
299 path: skill.path,
300 enabled: skill.enabled,
301 };
302
303 if (skill.description) {
304 parsedSkill.description = skill.description;
305 }
306 if (skill.scope) {
307 parsedSkill.scope = skill.scope;
308 }
309 if (skill.interface?.displayName) {
310 parsedSkill.displayName = skill.interface.displayName;
311 }
312 if (shortDescription) {
313 parsedSkill.shortDescription = shortDescription;
314 }
315
316 return parsedSkill;
317 });
318}
319
320const requestAllCodexModels = Effect.fn("requestAllCodexModels")(function* (
321 client: CodexClient.CodexAppServerClient["Service"],
322) {
323 const models: ServerProviderModel[] = [];
324 let cursor: string | null | undefined = undefined;
325
326 do {
327 const response: CodexSchema.V2ModelListResponse = yield* client.request(
328 "model/list",
329 cursor ? { cursor } : {},
330 );
331 models.push(...parseCodexModelListResponse(response));
332 cursor = response.nextCursor;
333 } while (cursor);
334
335 return models;
336});
337
338export function buildCodexInitializeParams(): CodexSchema.V1InitializeParams {
339 return {
340 clientInfo: {
341 name: "t3code_desktop",
342 title: "T3 Code Desktop",
343 version: packageJson.version,
344 },
345 capabilities: {
346 experimentalApi: true,
347 },
348 };
349}
350
351/**
352 * Spawns a short-lived `codex app-server`, runs the initialize handshake, and
353 * hands the caller a connected client. Scoped: the process is killed when
354 * the caller's scope closes. Shared by the status probe, the skills probe,
355 * and account-level requests such as reset-credit redemption.
356 */
357export const withCodexAppServerClient = Effect.fn("withCodexAppServerClient")(function* (input: {
358 readonly binaryPath: string;
359 readonly homePath?: string | undefined;
360 readonly launchArgs?: string | undefined;
361 readonly cwd: string;
362 readonly environment?: NodeJS.ProcessEnv | undefined;
363}) {
364 // `~` is not shell-expanded when env vars are set via `child_process.spawn`,
365 // so `CODEX_HOME=~/.codex_work` would reach codex verbatim and trip
366 // "CODEX_HOME points to '~/.codex_work', but that path does not exist".
367 // Expand here for parity with `CodexTextGeneration`/`CodexSessionRuntime`.
368 const resolvedHomePath = input.homePath ? expandHomePath(input.homePath) : undefined;
369 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
370 const environment = {
371 ...input.environment,
372 ...(resolvedHomePath ? { CODEX_HOME: resolvedHomePath } : {}),
373 };
374 const spawnCommand = yield* resolveSpawnCommand(
375 input.binaryPath,
376 codexAppServerArgs(input.launchArgs),
377 { env: environment, extendEnv: true },
378 );
379 const child = yield* spawner
380 .spawn(
381 ChildProcess.make(spawnCommand.command, spawnCommand.args, {
382 cwd: input.cwd,
383 env: environment,
384 extendEnv: true,
385 forceKillAfter: CODEX_APP_SERVER_PROBE_FORCE_KILL_AFTER,
386 shell: spawnCommand.shell,
387 }),
388 )
389 .pipe(
390 Effect.mapError(
391 (cause) =>
392 new CodexErrors.CodexAppServerSpawnError({
393 command: `${input.binaryPath} app-server`,
394 cause,
395 }),
396 ),
397 );
398 const clientContext = yield* Layer.build(CodexClient.layerChildProcess(child));
399 const client = yield* Effect.service(CodexClient.CodexAppServerClient).pipe(
400 Effect.provide(clientContext),
401 );
402 const initialize = yield* client.request("initialize", buildCodexInitializeParams());
403 yield* client.notify("initialized", undefined);
404 return { client, initialize };
405});
406
407const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(function* (input: {
408 readonly binaryPath: string;
409 readonly homePath?: string;
410 readonly launchArgs?: string;
411 readonly cwd: string;
412 readonly customModels?: ReadonlyArray<CustomModelSetting>;
413 readonly environment?: NodeJS.ProcessEnv;
414}) {
415 const { client, initialize } = yield* withCodexAppServerClient(input);
416
417 // Extract the version string after the first '/' in userAgent, up to the next space or the end
418 const versionMatch = initialize.userAgent.match(/\/([^\s]+)/);
419 const version = versionMatch ? versionMatch[1] : undefined;
420
421 const accountResponse = yield* client.request("account/read", {});
422 if (!accountResponse.account && accountResponse.requiresOpenaiAuth) {
423 return {
424 account: accountResponse,
425 version,
426 models: appendCustomCodexModels([], input.customModels ?? []),
427 skills: [],
428 } satisfies CodexAppServerProviderSnapshot;
429 }
430
431 const [skillsResponse, models, rateLimits] = yield* Effect.all(
432 [
433 client.request("skills/list", {
434 cwds: [input.cwd],
435 }),
436 requestAllCodexModels(client),
437 // Usage is an enrichment: a failure or a slow answer degrades to "no
438 // usage this probe" rather than costing the account and models.
439 client.request("account/rateLimits/read", undefined).pipe(
440 Effect.map((response): CodexRateLimitsProbe => ({
441 snapshot: response.rateLimits,
442 rateLimitsByLimitId: response.rateLimitsByLimitId,
443 resetCredits: response.rateLimitResetCredits,
444 })),
445 Effect.timeoutOption(Duration.millis(RATE_LIMITS_PROBE_TIMEOUT_MS)),
446 Effect.map(
447 Option.getOrElse((): CodexRateLimitsProbe => ({
448 failure: "Codex did not answer the usage request.",
449 })),
450 ),
451 Effect.catch((error) =>
452 Effect.logDebug("Codex rate-limit read failed.", { cause: error }).pipe(
453 Effect.as<CodexRateLimitsProbe>({ failure: codexRateLimitsFailureMessage(error) }),
454 ),
455 ),
456 ),
457 ],
458 { concurrency: "unbounded" },
459 );
460
461 return {
462 account: accountResponse,
463 rateLimits,
464 version,
465 models: applyPreferredCodexDefaultModel(
466 appendCustomCodexModels(models, input.customModels ?? []),
467 ),
468 skills: parseCodexSkillsListResponse(skillsResponse, input.cwd),
469 } satisfies CodexAppServerProviderSnapshot;
470});
471
472export const probeCodexSkillsForCwd = Effect.fn("probeCodexSkillsForCwd")(function* (input: {
473 readonly binaryPath: string;
474 readonly homePath?: string;
475 readonly launchArgs?: string;
476 readonly cwd: string;
477 readonly environment?: NodeJS.ProcessEnv;
478}) {
479 const { client } = yield* withCodexAppServerClient(input);
480 const skillsResponse = yield* client.request("skills/list", { cwds: [input.cwd] });
481 return parseCodexSkillsListResponse(skillsResponse, input.cwd);
482});
483
484const emptyCodexModelsFromSettings = (codexSettings: CodexSettings): ServerProvider["models"] =>
485 appendCustomCodexModels([], codexSettings.customModels);
486
487const makePendingCodexProvider = (
488 codexSettings: CodexSettings,
489): Effect.Effect<ServerProviderDraft> =>
490 Effect.gen(function* () {
491 const checkedAt = yield* Effect.map(DateTime.now, DateTime.formatIso);
492 const models = emptyCodexModelsFromSettings(codexSettings);
493
494 if (!codexSettings.enabled) {
495 return buildServerProvider({
496 presentation: CODEX_PRESENTATION,
497 enabled: false,
498 checkedAt,
499 models,
500 skills: [],
501 probe: {
502 installed: false,
503 version: null,
504 status: "warning",
505 auth: { status: "unknown" },
506 message: "Codex is disabled in T3 Code settings.",
507 },
508 });
509 }
510
511 return buildServerProvider({
512 presentation: CODEX_PRESENTATION,
513 enabled: true,
514 checkedAt,
515 models,
516 skills: [],
517 probe: {
518 installed: false,
519 version: null,
520 status: "warning",
521 auth: { status: "unknown" },
522 message: "Codex provider status has not been checked in this session yet.",
523 },
524 });
525 });
526
527function accountProbeStatus(account: CodexAppServerProviderSnapshot["account"]): {
528 readonly status: Exclude<ServerProviderState, "disabled">;
529 readonly auth: ServerProvider["auth"];
530 readonly message?: string;
531} {
532 const authLabel = codexAccountAuthLabel(account.account);
533 const authEmail = codexAccountEmail(account.account);
534 const auth = {
535 status: account.account ? ("authenticated" as const) : ("unknown" as const),
536 ...(account.account?.type ? { type: account.account?.type } : {}),
537 ...(authLabel ? { label: authLabel } : {}),
538 ...(authEmail ? { email: authEmail } : {}),
539 } satisfies ServerProvider["auth"];
540
541 if (account.account) {
542 return { status: "ready", auth };
543 }
544
545 if (account.requiresOpenaiAuth) {
546 return {
547 status: "error",
548 auth: { status: "unauthenticated" },
549 message: "Codex CLI is not authenticated. Run `codex login` and try again.",
550 };
551 }
552
553 return { status: "ready", auth };
554}
555
556export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(function* (
557 codexSettings: CodexSettings,
558 probe: (input: {
559 readonly binaryPath: string;
560 readonly homePath?: string;
561 readonly launchArgs?: string;
562 readonly cwd: string;
563 readonly customModels: ReadonlyArray<CustomModelSetting>;
564 readonly environment?: NodeJS.ProcessEnv;
565 }) => Effect.Effect<
566 CodexAppServerProviderSnapshot,
567 CodexErrors.CodexAppServerError,
568 ChildProcessSpawner.ChildProcessSpawner | Scope.Scope
569 > = probeCodexAppServerProvider,
570 environment?: NodeJS.ProcessEnv,
571): Effect.fn.Return<
572 ServerProviderDraft,
573 ServerSettingsError,
574 ChildProcessSpawner.ChildProcessSpawner
575> {
576 const resolvedEnvironment = environment ?? process.env;
577 const checkedAt = DateTime.formatIso(yield* DateTime.now);
578 const emptyModels = emptyCodexModelsFromSettings(codexSettings);
579
580 if (!codexSettings.enabled) {
581 return buildServerProvider({
582 presentation: CODEX_PRESENTATION,
583 enabled: false,
584 checkedAt,
585 models: emptyModels,
586 skills: [],
587 probe: {
588 installed: false,
589 version: null,
590 status: "warning",
591 auth: { status: "unknown" },
592 message: "Codex is disabled in T3 Code settings.",
593 },
594 });
595 }
596
597 const probeResult = yield* probe({
598 binaryPath: codexSettings.binaryPath,
599 homePath: codexSettings.homePath,
600 launchArgs: resolveCodexLaunchArgs(codexSettings.launchArgs, resolvedEnvironment),
601 cwd: process.cwd(),
602 customModels: codexSettings.customModels,
603 environment: resolvedEnvironment,
604 }).pipe(
605 Effect.scoped,
606 Effect.timeoutOption(Duration.millis(AUTH_PROBE_TIMEOUT_MS)),
607 Effect.result,
608 );
609
610 if (Result.isFailure(probeResult)) {
611 const error = probeResult.failure;
612 const installed = !isCodexAppServerSpawnError(error);
613 return buildServerProvider({
614 presentation: CODEX_PRESENTATION,
615 enabled: codexSettings.enabled,
616 checkedAt,
617 models: emptyModels,
618 skills: [],
619 probe: {
620 installed,
621 version: null,
622 status: "error",
623 auth: { status: "unknown" },
624 message: installed
625 ? `Codex app-server provider probe failed: ${error.message}.`
626 : "Codex CLI (`codex`) was not found on PATH.",
627 },
628 });
629 }
630
631 if (Option.isNone(probeResult.success)) {
632 return buildServerProvider({
633 presentation: CODEX_PRESENTATION,
634 enabled: codexSettings.enabled,
635 checkedAt,
636 models: emptyModels,
637 skills: [],
638 probe: {
639 installed: true,
640 version: null,
641 status: "error",
642 auth: { status: "unknown" },
643 message: "Timed out while checking Codex app-server provider status.",
644 },
645 });
646 }
647
648 const snapshot = probeResult.success.value;
649 const accountStatus = accountProbeStatus(snapshot.account);
650 const usageLimits =
651 snapshot.account.account?.type === "apiKey"
652 ? makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" })
653 : snapshot.rateLimits === undefined || "failure" in snapshot.rateLimits
654 ? makeUnavailableUsageLimits({
655 checkedAt,
656 reason: "probeFailed",
657 ...(snapshot.rateLimits ? { message: snapshot.rateLimits.failure } : {}),
658 })
659 : codexRateLimitsToLimits({
660 snapshot: snapshot.rateLimits.snapshot,
661 rateLimitsByLimitId: snapshot.rateLimits.rateLimitsByLimitId,
662 resetCredits: snapshot.rateLimits.resetCredits,
663 checkedAt,
664 });
665
666 return buildServerProvider({
667 presentation: CODEX_PRESENTATION,
668 enabled: codexSettings.enabled,
669 checkedAt,
670 models: snapshot.models,
671 skills: snapshot.skills,
672 slashCommands: [
673 COMPACT_SLASH_COMMAND,
674 {
675 name: "feedback",
676 description: "Send this thread and Codex logs to OpenAI",
677 input: { hint: "Describe the issue (optional)" },
678 },
679 ],
680 probe: {
681 installed: true,
682 version: snapshot.version ?? null,
683 status: accountStatus.status,
684 auth: accountStatus.auth,
685 ...(accountStatus.message ? { message: accountStatus.message } : {}),
686 usageLimits,
687 },
688 });
689});
690
691// NOTE: the singleton `CodexProviderLive` Layer has been removed as part of
692// the per-instance-driver refactor. `CodexDriver.create()` builds a managed
693// snapshot per instance (each with its own `CodexSettings`) and hands the
694// resulting `ServerProviderShape` back as `ProviderInstance.snapshot`.
695//
696// The `makePendingCodexProvider` and `checkCodexProviderStatus` helpers are
697// re-exported for use by `CodexDriver`.
698export { makePendingCodexProvider };