|
1 | | -import * as NodeOS from "node:os"; |
2 | | -import { decodeJwt } from "jose"; |
3 | | -import * as FileSystem from "effect/FileSystem"; |
4 | | -import * as Path from "effect/Path"; |
5 | 1 | import * as DateTime from "effect/DateTime"; |
6 | 2 | import * as Duration from "effect/Duration"; |
7 | 3 | import * as Effect from "effect/Effect"; |
@@ -75,7 +71,6 @@ const CODEX_PRESENTATION = { |
75 | 71 | } as const; |
76 | 72 |
|
77 | 73 | export interface CodexAppServerProviderSnapshot { |
78 | | - readonly accountId?: string; |
79 | 74 | readonly account: CodexSchema.V2GetAccountResponse; |
80 | 75 | readonly rateLimits?: CodexRateLimitsProbe; |
81 | 76 | readonly version: string | undefined; |
@@ -155,48 +150,6 @@ function codexAccountEmail(account: CodexSchema.V2GetAccountResponse["account"]) |
155 | 150 | return account.email; |
156 | 151 | } |
157 | 152 |
|
158 | | -const CodexAuthIdentity = Schema.Struct({ |
159 | | - tokens: Schema.optional( |
160 | | - Schema.Struct({ |
161 | | - account_id: Schema.optional(Schema.String), |
162 | | - id_token: Schema.optional(Schema.String), |
163 | | - }), |
164 | | - ), |
165 | | -}); |
166 | | -const CodexIdentityClaims = Schema.Struct({ |
167 | | - "https://api.openai.com/auth": Schema.optional( |
168 | | - Schema.Struct({ |
169 | | - chatgpt_account_id: Schema.optional(Schema.String), |
170 | | - }), |
171 | | - ), |
172 | | -}); |
173 | | - |
174 | | -/** Reads only grouping identity from the same native home used by the app server. */ |
175 | | -export const readCodexAccountId = Effect.fn("readCodexAccountId")(function* ( |
176 | | - homePath: string, |
177 | | - environment: NodeJS.ProcessEnv, |
178 | | -) { |
179 | | - const fs = yield* FileSystem.FileSystem; |
180 | | - const path = yield* Path.Path; |
181 | | - const home = homePath.trim() |
182 | | - ? expandHomePath(homePath) |
183 | | - : environment.CODEX_HOME || path.join(environment.HOME || NodeOS.homedir(), ".codex"); |
184 | | - const auth = yield* fs.readFileString(path.join(home, "auth.json")).pipe( |
185 | | - Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(CodexAuthIdentity))), |
186 | | - Effect.orElseSucceed(() => undefined), |
187 | | - ); |
188 | | - const accountId = auth?.tokens?.account_id?.trim(); |
189 | | - if (accountId) return accountId; |
190 | | - const idToken = auth?.tokens?.id_token; |
191 | | - if (!idToken) return undefined; |
192 | | - // This is grouping metadata, not authentication; the CLI verifies its tokens. |
193 | | - const claims = yield* Effect.try(() => decodeJwt(idToken)).pipe( |
194 | | - Effect.flatMap(Schema.decodeUnknownEffect(CodexIdentityClaims)), |
195 | | - Effect.orElseSucceed(() => undefined), |
196 | | - ); |
197 | | - return claims?.["https://api.openai.com/auth"]?.chatgpt_account_id?.trim() || undefined; |
198 | | -}); |
199 | | - |
200 | 153 | export function mapCodexModelCapabilities( |
201 | 154 | model: CodexSchema.V2ModelListResponse__Model, |
202 | 155 | ): ModelCapabilities { |
@@ -485,10 +438,6 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun |
485 | 438 | } satisfies CodexAppServerProviderSnapshot; |
486 | 439 | } |
487 | 440 |
|
488 | | - const accountId = |
489 | | - !input.skipNativeUsage && accountResponse.account?.type === "chatgpt" |
490 | | - ? yield* readCodexAccountId(input.homePath ?? "", input.environment ?? process.env) |
491 | | - : undefined; |
492 | 441 | const [skillsResponse, models, rateLimits] = yield* Effect.all( |
493 | 442 | [ |
494 | 443 | client.request("skills/list", { |
@@ -523,7 +472,6 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun |
523 | 472 |
|
524 | 473 | return { |
525 | 474 | account: accountResponse, |
526 | | - ...(accountId ? { accountId } : {}), |
527 | 475 | ...(rateLimits ? { rateLimits } : {}), |
528 | 476 | version, |
529 | 477 | models: applyPreferredCodexDefaultModel( |
@@ -630,14 +578,14 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu |
630 | 578 | }) => Effect.Effect< |
631 | 579 | CodexAppServerProviderSnapshot, |
632 | 580 | CodexErrors.CodexAppServerError, |
633 | | - ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path | Scope.Scope |
| 581 | + ChildProcessSpawner.ChildProcessSpawner | Scope.Scope |
634 | 582 | > = probeCodexAppServerProvider, |
635 | 583 | environment?: NodeJS.ProcessEnv, |
636 | 584 | managedAuth?: ServerProvider["auth"], |
637 | 585 | ): Effect.fn.Return< |
638 | 586 | ServerProviderDraft, |
639 | 587 | ServerSettingsError, |
640 | | - ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path |
| 588 | + ChildProcessSpawner.ChildProcessSpawner |
641 | 589 | > { |
642 | 590 | const resolvedEnvironment = environment ?? process.env; |
643 | 591 | const checkedAt = DateTime.formatIso(yield* DateTime.now); |
@@ -753,10 +701,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu |
753 | 701 | installed: true, |
754 | 702 | version: snapshot.version ?? null, |
755 | 703 | status: accountStatus.status, |
756 | | - auth: { |
757 | | - ...accountStatus.auth, |
758 | | - ...(snapshot.accountId ? { accountId: snapshot.accountId } : {}), |
759 | | - }, |
| 704 | + auth: accountStatus.auth, |
760 | 705 | ...(accountStatus.message ? { message: accountStatus.message } : {}), |
761 | 706 | ...(managedAuth ? {} : { usageLimits }), |
762 | 707 | }, |
|
0 commit comments