{"repo": "chirantan02/omo-kernel", "files": {"opencode-dev/packages/opencode/src/session/retry.ts": {"922bb130fd0baa93a52396947059dcae9ffef492": {"t": 1785596388.626645, "n": 7152, "h": "0c7fcace557156bd", "c": "import type { NamedError } from \"@opencode-ai/core/util/error\"\nimport { SessionV1 } from \"@opencode-ai/core/v1/session\"\nimport { Cause, Clock, Duration, Effect, Schedule } from \"effect\"\nimport { MessageV2 } from \"./message-v2\"\nimport { iife } from \"@/util/iife\"\nimport { isRecord } from \"@/util/record\"\n\nexport type Err = ReturnType\n\nexport const GO_UPSELL_MESSAGE = \"Free usage exceeded, subscribe to Go\"\nexport const GO_UPSELL_URL = \"https://opencode.ai/go\"\nexport type RetryReason = \"free_tier_limit\" | \"account_rate_limit\" | (string & {})\n\nexport type Retryable = {\n message: string\n action?: {\n reason: RetryReason\n provider: string\n title: string\n message: string\n label: string\n link?: string\n }\n}\n\nexport const RETRY_INITIAL_DELAY = 2000\nexport const RETRY_BACKOFF_FACTOR = 2\nexport const RETRY_MAX_DELAY_NO_HEADERS = 30_000 // 30 seconds\nexport const RETRY_MAX_DELAY = 2_147_483_647 // max 32-bit signed integer for setTimeout\n\nfunction cap(ms: number) {\n return Math.min(ms, RETRY_MAX_DELAY)\n}\n\nexport function delay(attempt: number, error?: SessionV1.APIError) {\n if (error) {\n const headers = error.data.responseHeaders\n if (headers) {\n const retryAfterMs = headers[\"retry-after-ms\"]\n if (retryAfterMs) {\n const parsedMs = Number.parseFloat(retryAfterMs)\n if (!Number.isNaN(parsedMs)) {\n return cap(parsedMs)\n }\n }\n\n const retryAfter = headers[\"retry-after\"]\n if (retryAfter) {\n const parsedSeconds = Number.parseFloat(retryAfter)\n if (!Number.isNaN(parsedSeconds)) {\n // convert seconds to milliseconds\n return cap(Math.ceil(parsedSeconds * 1000))\n }\n // Try parsing as HTTP date format\n const parsed = Date.parse(retryAfter) - Date.now()\n if (!Number.isNaN(parsed) && parsed > 0) {\n return cap(Math.ceil(parsed))\n }\n }\n\n return cap(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1))\n }\n }\n\n return cap(Math.min(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1), RETRY_MAX_DELAY_NO_HEADERS))\n}\n\nexport function retryable(error: Err, provider: string) {\n // context overflow errors should not be retried\n if (SessionV1.ContextOverflowError.isInstance(error)) return undefined\n if (SessionV1.APIError.isInstance(error)) {\n const status = error.data.statusCode\n // 5xx errors are transient server failures and should always be retried,\n // even when the provider SDK doesn't explicitly mark them as retryable.\n if (!error.data.isRetryable && !(status !== undefined && status >= 500)) return undefined\n if (error.data.responseBody?.includes(\"FreeUsageLimitError\")) {\n return {\n message: GO_UPSELL_MESSAGE,\n action: {\n reason: \"free_tier_limit\",\n provider,\n title: \"Free limit reached\",\n message: \"Subscribe to OpenCode Go for reliable access to the best open-source models, starting at $5/month.\",\n label: \"subscribe\",\n link: GO_UPSELL_URL,\n },\n }\n }\n if (error.data.responseBody?.includes(\"GoUsageLimitError\")) {\n const body = parseJSON(error.data.responseBody)\n const workspace = str(body?.metadata?.workspace)\n const limitName = str(body?.metadata?.limitName)\n const retryAfter = num(error.data.responseHeaders?.[\"retry-after\"])\n const resetIn = iife(() => {\n if (retryAfter === undefined) return \"\"\n const seconds = Math.max(0, Math.ceil(retryAfter))\n const days = Math.floor(seconds / 86_400)\n const hours = Math.floor((seconds % 86_400) / 3_600)\n const minutes = Math.ceil((seconds % 3_600) / 60)\n const unit = (value: number, name: string) => `${value} ${name}${value === 1 ? \"\" : \"s\"}`\n\n if (days > 0) return hours > 0 ? `${unit(days, \"day\")} ${unit(hours, \"hour\")}` : unit(days, \"day\")\n if (hours > 0) return minutes > 0 ? `${unit(hours, \"hour\")} ${unit(minutes, \"minute\")}` : unit(hours, \"hour\")\n return minutes > 0 ? unit(minutes, \"minute\") : \"less than a minute\"\n })\n\n const message = `${limitName ? `${limitName} usage limit` : \"Usage limit\"} reached. It will reset in ${resetIn}. To continue using this model now, enable usage from your available balance`\n\n const link = `https://opencode.ai/workspace/${workspace}/go`\n return {\n message: `${message} - ${link}`,\n action: {\n reason: \"account_rate_limit\",\n provider,\n title: \"Go limit reached\",\n message,\n label: \"open settings\",\n link,\n },\n }\n }\n return { message: error.data.message.includes(\"Overloaded\") ? \"Provider is overloaded\" : error.data.message }\n }\n\n // Check for rate limit patterns in plain text error messages\n const msg = isRecord(error.data) ? error.data.message : undefined\n if (typeof msg === \"string\") {\n const lower = msg.toLowerCase()\n if (\n lower.includes(\"rate increased too quickly\") ||\n lower.includes(\"rate limit\") ||\n lower.includes(\"too many requests\")\n ) {\n return { message: msg }\n }\n }\n\n const json = parseJSON(msg)\n if (!json || typeof json !== \"object\") return undefined\n const code = typeof json.code === \"string\" ? json.code : \"\"\n\n if (json.type === \"error\" && json.error?.type === \"too_many_requests\") {\n return { message: \"Too Many Requests\" }\n }\n if (code.includes(\"exhausted\") || code.includes(\"unavailable\")) {\n return { message: \"Provider is overloaded\" }\n }\n if (json.type === \"error\" && typeof json.error?.code === \"string\" && json.error.code.includes(\"rate_limit\")) {\n return { message: \"Rate Limited\" }\n }\n return undefined\n}\n\nfunction str(value: unknown) {\n if (value === undefined || value === null) return \"\"\n return String(value)\n}\n\nfunction num(value: unknown) {\n const parsed = Number.parseFloat(str(value))\n if (Number.isNaN(parsed)) return undefined\n return parsed\n}\n\nfunction parseJSON(value: unknown) {\n return iife(() => {\n try {\n if (typeof value !== \"string\") return undefined\n return JSON.parse(value)\n } catch {\n return undefined\n }\n })\n}\n\nexport function policy(opts: {\n provider: string\n parse: (error: unknown) => Err\n set: (input: { attempt: number; message: string; action?: Retryable[\"action\"]; next: number }) => Effect.Effect\n}) {\n return Schedule.fromStepWithMetadata(\n Effect.succeed((meta: Schedule.InputMetadata) => {\n const error = opts.parse(meta.input)\n const retry = retryable(error, opts.provider)\n if (!retry) return Cause.done(meta.attempt)\n return Effect.gen(function* () {\n const wait = delay(meta.attempt, SessionV1.APIError.isInstance(error) ? error : undefined)\n const now = yield* Clock.currentTimeMillis\n yield* opts.set({\n attempt: meta.attempt,\n message: retry.message,\n action: retry.action,\n next: now + wait,\n })\n return [meta.attempt, Duration.millis(wait)] as [number, Duration.Duration]\n })\n }),\n )\n}\n\nexport * as SessionRetry from \"./retry\"\n"}}, "opencode-dev/packages/opencode/test/session/schema-decoding.test.ts": {"922bb130fd0baa93a52396947059dcae9ffef492": {"t": 1785596396.188532, "n": 9979, "h": "a5deb90cd7f1e8dc", "c": "import { describe, expect, test } from \"bun:test\"\nimport { Schema } from \"effect\"\n\nimport { Session } from \"@/session/session\"\nimport { SessionPrompt } from \"../../src/session/prompt\"\nimport { SessionRevert } from \"../../src/session/revert\"\nimport { SessionStatus } from \"../../src/session/status\"\nimport { SessionSummary } from \"../../src/session/summary\"\nimport { Todo } from \"../../src/session/todo\"\nimport { SessionID, MessageID, PartID } from \"../../src/session/schema\"\nimport { ProjectV2 } from \"@opencode-ai/core/project\"\nimport { WorkspaceV2 } from \"@opencode-ai/core/workspace\"\n\n// Covers the session-domain Effect Schema migration. For each migrated\n// schema we assert:\n// 1. The Effect decoder (`Schema.decodeUnknownSync`) accepts valid input.\n// 2. Clearly-invalid input is rejected.\n\n// Representative valid IDs — the branded schemas require the right prefix\n// (see src/id/id.ts).\nconst sessionID = Schema.decodeUnknownSync(SessionID)(\"ses_01J5Y5H0AH4Q4NXJ6P4C3P5V2K\")\nconst sessionIDChild = Schema.decodeUnknownSync(SessionID)(\"ses_01J5Y5H0AH4Q4NXJ6P4C3P5V2L\")\nconst messageID = Schema.decodeUnknownSync(MessageID)(\"msg_01J5Y5H0AH4Q4NXJ6P4C3P5V2M\")\nconst partID = Schema.decodeUnknownSync(PartID)(\"prt_01J5Y5H0AH4Q4NXJ6P4C3P5V2N\")\nconst projectID = ProjectV2.ID.make(\"proj-alpha\")\nconst workspaceID = Schema.decodeUnknownSync(WorkspaceV2.ID)(\"wrk-primary\")\n\nfunction decodeUnknown(schema: S) {\n const decode = Schema.decodeUnknownSync(schema as any)\n return (input: unknown): Schema.Schema.Type => decode(input) as Schema.Schema.Type\n}\n\ndescribe(\"Session.Info\", () => {\n const decode = decodeUnknown(Session.Info)\n\n test(\"accepts minimal session\", () => {\n const input = {\n id: sessionID,\n slug: \"hello\",\n projectID,\n directory: \"/tmp/proj\",\n title: \"First session\",\n version: \"0.1.0\",\n time: { created: 1, updated: 2 },\n }\n expect(decode(input)).toEqual(input)\n })\n\n test(\"round-trips every optional field\", () => {\n const input = {\n id: sessionID,\n slug: \"fullshape\",\n projectID,\n workspaceID,\n directory: \"/tmp/proj\",\n path: \"packages/opencode\",\n parentID: sessionIDChild,\n summary: {\n additions: 10,\n deletions: 5,\n files: 2,\n diffs: [{ additions: 1, deletions: 0, file: \"a.ts\", patch: \"--- a/a.ts\" }],\n },\n share: { url: \"https://share.example.com/s/1\" },\n title: \"Full session\",\n version: \"1.0.0\",\n metadata: { source: \"test\" },\n time: { created: 100, updated: 200, compacting: 150, archived: 300 },\n permission: [{ action: \"allow\" as const, pattern: \"*\", permission: \"read\" }],\n revert: {\n messageID,\n partID,\n snapshot: \"snap-1\",\n diff: \"diff-1\",\n },\n }\n expect(decode(input)).toEqual(input)\n })\n\n test(\"accepts migrated summary diffs without file details\", () => {\n const input = {\n id: sessionID,\n slug: \"legacy-diff\",\n projectID,\n directory: \"/tmp/proj\",\n title: \"Legacy diff\",\n version: \"0.1.0\",\n summary: {\n additions: 1,\n deletions: 0,\n files: 1,\n diffs: [{ additions: 1, deletions: 0 }],\n },\n time: { created: 1, updated: 2 },\n }\n expect(decode(input)).toEqual(input)\n })\n\n test(\"rejects unbranded session id\", () => {\n const bad = { id: \"not-a-session-id\" } as unknown\n expect(() => decode(bad)).toThrow()\n })\n\n test(\"rejects missing required fields\", () => {\n const bad = { id: sessionID } as unknown\n expect(() => decode(bad)).toThrow()\n })\n})\n\ndescribe(\"Session.ProjectInfo\", () => {\n const decode = decodeUnknown(Session.ProjectInfo)\n\n test(\"accepts with and without optional name\", () => {\n const noName = { id: projectID, worktree: \"/tmp/wt\" }\n const withName = { ...noName, name: \"alpha\" }\n expect(decode(noName)).toEqual(noName)\n expect(decode(withName)).toEqual(withName)\n })\n})\n\ndescribe(\"Session.GlobalInfo\", () => {\n const decode = decodeUnknown(Session.GlobalInfo)\n\n test(\"accepts null project\", () => {\n const input = {\n id: sessionID,\n slug: \"global\",\n projectID,\n directory: \"/tmp/proj\",\n title: \"global\",\n version: \"0\",\n time: { created: 0, updated: 0 },\n project: null,\n }\n expect(decode(input)).toEqual(input)\n })\n\n test(\"accepts populated project\", () => {\n const input = {\n id: sessionID,\n slug: \"global\",\n projectID,\n directory: \"/tmp/proj\",\n title: \"global\",\n version: \"0\",\n time: { created: 0, updated: 0 },\n project: { id: projectID, worktree: \"/tmp/wt\", name: \"alpha\" },\n }\n expect(decode(input)).toEqual(input)\n })\n})\n\ndescribe(\"Session input schemas\", () => {\n test(\"CreateInput accepts undefined and populated forms\", () => {\n const decode = decodeUnknown(Session.CreateInput)\n expect(decode(undefined)).toBeUndefined()\n\n const populated = {\n parentID: sessionID,\n title: \"child\",\n metadata: { source: \"test\" },\n permission: [{ action: \"ask\" as const, pattern: \"*\", permission: \"bash\" }],\n workspaceID,\n }\n expect(decode(populated)).toEqual(populated)\n })\n\n test(\"ForkInput round-trips\", () => {\n const decode = decodeUnknown(Session.ForkInput)\n const input = { sessionID, messageID }\n expect(decode(input)).toEqual(input)\n // messageID is optional\n const bare = { sessionID }\n expect(decode(bare)).toEqual(bare)\n })\n\n test(\"SetTitleInput rejects missing title\", () => {\n expect(() => decodeUnknown(Session.SetTitleInput)({ sessionID })).toThrow()\n })\n\n test(\"SetArchivedInput accepts both with and without time\", () => {\n const decode = decodeUnknown(Session.SetArchivedInput)\n expect(decode({ sessionID })).toEqual({ sessionID })\n expect(decode({ sessionID, time: 123 })).toEqual({ sessionID, time: 123 })\n })\n\n test(\"SetPermissionInput requires a ruleset\", () => {\n const decode = decodeUnknown(Session.SetPermissionInput)\n const input = { sessionID, permission: [{ action: \"deny\" as const, pattern: \"*\", permission: \"write\" }] }\n expect(decode(input)).toEqual(input)\n expect(() => decode({ sessionID })).toThrow()\n })\n\n test(\"MessagesInput accepts optional limit\", () => {\n const decode = decodeUnknown(Session.MessagesInput)\n expect(decode({ sessionID })).toEqual({ sessionID })\n expect(decode({ sessionID, limit: 50 })).toEqual({ sessionID, limit: 50 })\n })\n})\n\ndescribe(\"SessionRevert.RevertInput\", () => {\n const decode = decodeUnknown(SessionRevert.RevertInput)\n\n test(\"messageID is required, partID is optional\", () => {\n const withPart = { sessionID, messageID, partID }\n expect(decode(withPart)).toEqual(withPart)\n\n const noPart = { sessionID, messageID }\n expect(decode(noPart)).toEqual(noPart)\n\n expect(() => decode({ sessionID })).toThrow()\n })\n})\n\ndescribe(\"SessionSummary.DiffInput\", () => {\n const decode = decodeUnknown(SessionSummary.DiffInput)\n\n test(\"messageID optional\", () => {\n expect(decode({ sessionID })).toEqual({ sessionID })\n expect(decode({ sessionID, messageID })).toEqual({ sessionID, messageID })\n })\n})\n\ndescribe(\"SessionStatus.Info\", () => {\n const decode = decodeUnknown(SessionStatus.Info)\n\n test(\"idle / busy discriminators\", () => {\n expect(decode({ type: \"idle\" })).toEqual({ type: \"idle\" })\n expect(decode({ type: \"busy\" })).toEqual({ type: \"busy\" })\n })\n\n test(\"retry carries attempt/message/action/next\", () => {\n const input = {\n type: \"retry\" as const,\n attempt: 1,\n message: \"transient\",\n action: {\n reason: \"free_tier_limit\",\n provider: \"opencode\",\n title: \"Free limit reached\",\n message: \"Subscribe to OpenCode Go.\",\n label: \"subscribe\",\n link: \"https://opencode.ai/go\",\n },\n next: 500,\n }\n expect(decode(input)).toEqual(input)\n })\n\n test(\"rejects unknown type\", () => {\n expect(() => decode({ type: \"bogus\" })).toThrow()\n })\n})\n\ndescribe(\"Todo.Info\", () => {\n const decode = decodeUnknown(Todo.Info)\n\n test(\"three-field round-trip\", () => {\n const input = Todo.Info.make({ content: \"do a thing\", status: \"pending\", priority: \"high\" })\n expect(decode(input)).toEqual(input)\n })\n})\n\ndescribe(\"SessionPrompt input schemas\", () => {\n test(\"LoopInput is just sessionID\", () => {\n const decode = decodeUnknown(SessionPrompt.LoopInput)\n expect(decode({ sessionID })).toEqual({ sessionID })\n })\n\n test(\"ShellInput requires agent + command\", () => {\n const decode = decodeUnknown(SessionPrompt.ShellInput)\n const expected = { sessionID, agent: \"build\", command: \"echo hi\" }\n const input: unknown = expected\n expect(decode(input)).toEqual(expected)\n expect(() => decode({ sessionID })).toThrow()\n })\n\n test(\"PromptInput accepts a text part and a file part\", () => {\n const decode = decodeUnknown(SessionPrompt.PromptInput)\n const expected = {\n sessionID,\n parts: [\n { type: \"text\" as const, text: \"hello\" },\n { type: \"file\" as const, mime: \"image/png\", url: \"data:image/png;base64,AAAA\" },\n ],\n }\n const input: unknown = expected\n const decoded = decode(input)\n expect(decoded.parts).toHaveLength(2)\n expect(decoded.parts[0]).toMatchObject({ type: \"text\", text: \"hello\" })\n expect(decoded.parts[1]).toMatchObject({ type: \"file\", mime: \"image/png\" })\n })\n\n test(\"PromptInput rejects unknown part type\", () => {\n const decode = decodeUnknown(SessionPrompt.PromptInput)\n const bad = {\n sessionID,\n parts: [{ type: \"nonsense\", payload: 42 }],\n }\n expect(() => decode(bad)).toThrow()\n })\n\n test(\"CommandInput round-trips core fields\", () => {\n const decode = decodeUnknown(SessionPrompt.CommandInput)\n const expected = {\n sessionID,\n arguments: \"--flag\",\n command: \"deploy\",\n }\n const input: unknown = expected\n expect(decode(input)).toEqual(expected)\n })\n})\n"}}, "opencode-dev/packages/llm/test/auth-options.types.ts": {"922bb130fd0baa93a52396947059dcae9ffef492": {"t": 1785746536.968615, "n": 8381, "h": "facbb670816111de", "c": "import { Config } from \"effect\"\nimport type { Auth } from \"../src/route/auth\"\nimport type { ModelFactory } from \"../src/route/auth-options\"\nimport { Auth as RuntimeAuth } from \"../src/route/auth\"\nimport * as OpenAIChat from \"../src/protocols/openai-chat\"\nimport * as AmazonBedrock from \"../src/providers/amazon-bedrock\"\nimport * as Anthropic from \"../src/providers/anthropic\"\nimport * as Azure from \"../src/providers/azure\"\nimport * as Cloudflare from \"../src/providers/cloudflare\"\nimport * as GitHubCopilot from \"../src/providers/github-copilot\"\nimport * as Google from \"../src/providers/google\"\nimport * as OpenAI from \"../src/providers/openai\"\nimport * as OpenAICompatible from \"../src/providers/openai-compatible\"\nimport * as OpenRouter from \"../src/providers/openrouter\"\nimport * as XAI from \"../src/providers/xai\"\n\ntype BaseOptions = {\n readonly baseURL?: string\n readonly headers?: Record\n}\n\ntype Model = {\n readonly id: string\n}\n\ndeclare const auth: Auth\ndeclare const optionalAuthModel: ModelFactory\ndeclare const requiredAuthModel: ModelFactory\nconst configApiKey = Config.redacted(\"OPENAI_API_KEY\")\n\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\" })\n\n// @ts-expect-error route model selection does not configure endpoints.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", baseURL: \"https://gateway.example.com/v1\" })\n\n// @ts-expect-error route model selection does not configure query params.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", queryParams: { debug: \"1\" } })\n\n// @ts-expect-error route model selection does not configure auth.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", auth })\n\n// @ts-expect-error route model selection does not configure api keys.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", apiKey: \"sk-test\" })\n\noptionalAuthModel(\"gpt-4.1-mini\")\noptionalAuthModel(\"gpt-4.1-mini\", {})\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: \"sk-test\" })\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: configApiKey })\noptionalAuthModel(\"gpt-4.1-mini\", { auth })\noptionalAuthModel(\"gpt-4.1-mini\", { auth, baseURL: \"https://gateway.example.com/v1\" })\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: \"sk-test\", headers: { \"x-source\": \"test\" } })\n\n// @ts-expect-error auth is an override, so apiKey cannot be supplied with it.\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: \"sk-test\", auth })\n\nrequiredAuthModel(\"custom-model\", { apiKey: \"key\" })\nrequiredAuthModel(\"custom-model\", { apiKey: configApiKey })\nrequiredAuthModel(\"custom-model\", { auth })\nrequiredAuthModel(\"custom-model\", { auth, headers: { \"x-tenant-id\": \"tenant\" } })\n\n// @ts-expect-error providers without config fallback need apiKey or auth.\nrequiredAuthModel(\"custom-model\")\n\n// @ts-expect-error providers without config fallback need apiKey or auth.\nrequiredAuthModel(\"custom-model\", {})\n\n// @ts-expect-error auth is an override, so apiKey cannot be supplied with it.\nrequiredAuthModel(\"custom-model\", { apiKey: \"key\", auth })\n\nOpenAI.responses(\"gpt-4.1-mini\")\nOpenAI.configure({}).responses(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: \"sk-test\" }).responses(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: configApiKey }).responses(\"gpt-4.1-mini\")\nOpenAI.configure({ auth: RuntimeAuth.bearer(\"oauth-token\") }).responses(\"gpt-4.1-mini\")\nOpenAI.configure({\n auth: RuntimeAuth.headers({ authorization: \"Bearer gateway\" }),\n baseURL: \"https://gateway.example.com/v1\",\n}).responses(\"gpt-4.1-mini\")\nOpenAI.configure({\n generation: { maxTokens: 100 },\n providerOptions: { openai: { store: false } },\n}).responses(\"gpt-4.1-mini\")\n\n// @ts-expect-error OpenAI model selectors only accept model ids.\nOpenAI.configure({ apiKey: \"sk-test\" }).responses(\"gpt-4.1-mini\", {})\n\n// @ts-expect-error apiKey only accepts string, Redacted, or Config>.\nOpenAI.configure({ apiKey: 123 })\n\n// @ts-expect-error provider helpers reject unknown top-level options.\nOpenAI.configure({ bogus: true })\n\n// @ts-expect-error common generation options remain typed.\nOpenAI.configure({ generation: { maxTokens: \"many\" } })\n\n// @ts-expect-error provider-native options remain typed.\nOpenAI.configure({ providerOptions: { openai: { store: \"false\" } } })\n\n// @ts-expect-error auth is an override, so OpenAI rejects apiKey with auth.\nOpenAI.configure({ apiKey: \"sk-test\", auth: RuntimeAuth.bearer(\"oauth-token\") })\n\nOpenAI.chat(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: \"sk-test\" }).chat(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: configApiKey }).chat(\"gpt-4.1-mini\")\nOpenAI.configure({ auth: RuntimeAuth.bearer(\"oauth-token\") }).chat(\"gpt-4.1-mini\")\n\n// @ts-expect-error OpenAI chat selectors only accept model ids.\nOpenAI.configure({ apiKey: \"sk-test\" }).chat(\"gpt-4.1-mini\", {})\n\n// @ts-expect-error auth is an override, so OpenAI Chat rejects apiKey with auth.\nOpenAI.configure({ apiKey: \"sk-test\", auth: RuntimeAuth.bearer(\"oauth-token\") })\n\n// @ts-expect-error Azure requires at least one of `resourceName` or `baseURL`.\nAzure.configure()\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).responses(\"deployment\")\nAzure.configure({ apiKey: configApiKey, resourceName: \"resource\" }).responses(\"deployment\")\nAzure.configure({ auth: RuntimeAuth.header(\"api-key\", \"azure-key\"), resourceName: \"resource\" }).responses(\"deployment\")\n\n// @ts-expect-error Azure model selectors only accept deployment ids.\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).responses(\"deployment\", {})\n\n// @ts-expect-error auth is an override, so Azure rejects apiKey with auth.\nAzure.configure({ resourceName: \"resource\", apiKey: \"azure-key\", auth: RuntimeAuth.header(\"api-key\", \"override\") })\n\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).chat(\"deployment\")\nAzure.configure({ apiKey: configApiKey, resourceName: \"resource\" }).chat(\"deployment\")\nAzure.configure({ auth: RuntimeAuth.header(\"api-key\", \"azure-key\"), resourceName: \"resource\" }).chat(\"deployment\")\n\n// @ts-expect-error Azure chat model selectors only accept deployment ids.\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).chat(\"deployment\", {})\n\n// @ts-expect-error auth is an override, so Azure Chat rejects apiKey with auth.\nAzure.configure({ resourceName: \"resource\", apiKey: \"azure-key\", auth: RuntimeAuth.header(\"api-key\", \"override\") })\n\nAnthropic.configure({ apiKey: \"anthropic-key\" }).model(\"claude-haiku\")\n// @ts-expect-error Anthropic model selectors only accept model ids.\nAnthropic.configure({ apiKey: \"anthropic-key\" }).model(\"claude-haiku\", {})\n\nGoogle.configure({ apiKey: \"google-key\" }).model(\"gemini-2.5-flash\")\n// @ts-expect-error Google model selectors only accept model ids.\nGoogle.configure({ apiKey: \"google-key\" }).model(\"gemini-2.5-flash\", {})\n\nAmazonBedrock.configure({ apiKey: \"bedrock-key\" }).model(\"anthropic.claude\")\n// @ts-expect-error Bedrock model selectors only accept model ids.\nAmazonBedrock.configure({ apiKey: \"bedrock-key\" }).model(\"anthropic.claude\", {})\n\nOpenRouter.configure({ apiKey: \"openrouter-key\" }).model(\"openai/gpt-4o-mini\")\n// @ts-expect-error OpenRouter model selectors only accept model ids.\nOpenRouter.configure({ apiKey: \"openrouter-key\" }).model(\"openai/gpt-4o-mini\", {})\n\nXAI.configure({ apiKey: \"xai-key\" }).responses(\"grok-4\")\nXAI.configure({ apiKey: \"xai-key\" }).chat(\"grok-4\")\n// @ts-expect-error xAI Responses selectors only accept model ids.\nXAI.configure({ apiKey: \"xai-key\" }).responses(\"grok-4\", {})\n// @ts-expect-error xAI Chat selectors only accept model ids.\nXAI.configure({ apiKey: \"xai-key\" }).chat(\"grok-4\", {})\n\nOpenAICompatible.deepseek.configure({ apiKey: \"deepseek-key\" }).model(\"deepseek-chat\")\n// @ts-expect-error OpenAI-compatible family selectors only accept model ids.\nOpenAICompatible.deepseek.configure({ apiKey: \"deepseek-key\" }).model(\"deepseek-chat\", {})\n\nCloudflare.CloudflareWorkersAI.configure({ accountId: \"account\", apiKey: \"cf-key\" }).model(\"@cf/meta/llama\")\n// @ts-expect-error Cloudflare Workers AI model selectors only accept model ids.\nCloudflare.CloudflareWorkersAI.configure({ accountId: \"account\", apiKey: \"cf-key\" }).model(\"@cf/meta/llama\", {})\n\nGitHubCopilot.configure({ baseURL: \"https://copilot.test\", apiKey: \"copilot-key\" }).model(\"gpt-4.1\")\n// @ts-expect-error GitHub Copilot model selectors only accept model ids.\nGitHubCopilot.configure({ baseURL: \"https://copilot.test\", apiKey: \"copilot-key\" }).model(\"gpt-4.1\", {})\n"}, "aa12d9ea77998b84ea883b46bebf354cbb6493cc": {"t": 1785765440.7754703, "n": 8381, "h": "facbb670816111de", "c": "import { Config } from \"effect\"\nimport type { Auth } from \"../src/route/auth\"\nimport type { ModelFactory } from \"../src/route/auth-options\"\nimport { Auth as RuntimeAuth } from \"../src/route/auth\"\nimport * as OpenAIChat from \"../src/protocols/openai-chat\"\nimport * as AmazonBedrock from \"../src/providers/amazon-bedrock\"\nimport * as Anthropic from \"../src/providers/anthropic\"\nimport * as Azure from \"../src/providers/azure\"\nimport * as Cloudflare from \"../src/providers/cloudflare\"\nimport * as GitHubCopilot from \"../src/providers/github-copilot\"\nimport * as Google from \"../src/providers/google\"\nimport * as OpenAI from \"../src/providers/openai\"\nimport * as OpenAICompatible from \"../src/providers/openai-compatible\"\nimport * as OpenRouter from \"../src/providers/openrouter\"\nimport * as XAI from \"../src/providers/xai\"\n\ntype BaseOptions = {\n readonly baseURL?: string\n readonly headers?: Record\n}\n\ntype Model = {\n readonly id: string\n}\n\ndeclare const auth: Auth\ndeclare const optionalAuthModel: ModelFactory\ndeclare const requiredAuthModel: ModelFactory\nconst configApiKey = Config.redacted(\"OPENAI_API_KEY\")\n\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\" })\n\n// @ts-expect-error route model selection does not configure endpoints.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", baseURL: \"https://gateway.example.com/v1\" })\n\n// @ts-expect-error route model selection does not configure query params.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", queryParams: { debug: \"1\" } })\n\n// @ts-expect-error route model selection does not configure auth.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", auth })\n\n// @ts-expect-error route model selection does not configure api keys.\nOpenAIChat.route.model({ id: \"gpt-4.1-mini\", apiKey: \"sk-test\" })\n\noptionalAuthModel(\"gpt-4.1-mini\")\noptionalAuthModel(\"gpt-4.1-mini\", {})\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: \"sk-test\" })\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: configApiKey })\noptionalAuthModel(\"gpt-4.1-mini\", { auth })\noptionalAuthModel(\"gpt-4.1-mini\", { auth, baseURL: \"https://gateway.example.com/v1\" })\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: \"sk-test\", headers: { \"x-source\": \"test\" } })\n\n// @ts-expect-error auth is an override, so apiKey cannot be supplied with it.\noptionalAuthModel(\"gpt-4.1-mini\", { apiKey: \"sk-test\", auth })\n\nrequiredAuthModel(\"custom-model\", { apiKey: \"key\" })\nrequiredAuthModel(\"custom-model\", { apiKey: configApiKey })\nrequiredAuthModel(\"custom-model\", { auth })\nrequiredAuthModel(\"custom-model\", { auth, headers: { \"x-tenant-id\": \"tenant\" } })\n\n// @ts-expect-error providers without config fallback need apiKey or auth.\nrequiredAuthModel(\"custom-model\")\n\n// @ts-expect-error providers without config fallback need apiKey or auth.\nrequiredAuthModel(\"custom-model\", {})\n\n// @ts-expect-error auth is an override, so apiKey cannot be supplied with it.\nrequiredAuthModel(\"custom-model\", { apiKey: \"key\", auth })\n\nOpenAI.responses(\"gpt-4.1-mini\")\nOpenAI.configure({}).responses(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: \"sk-test\" }).responses(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: configApiKey }).responses(\"gpt-4.1-mini\")\nOpenAI.configure({ auth: RuntimeAuth.bearer(\"oauth-token\") }).responses(\"gpt-4.1-mini\")\nOpenAI.configure({\n auth: RuntimeAuth.headers({ authorization: \"Bearer gateway\" }),\n baseURL: \"https://gateway.example.com/v1\",\n}).responses(\"gpt-4.1-mini\")\nOpenAI.configure({\n generation: { maxTokens: 100 },\n providerOptions: { openai: { store: false } },\n}).responses(\"gpt-4.1-mini\")\n\n// @ts-expect-error OpenAI model selectors only accept model ids.\nOpenAI.configure({ apiKey: \"sk-test\" }).responses(\"gpt-4.1-mini\", {})\n\n// @ts-expect-error apiKey only accepts string, Redacted, or Config>.\nOpenAI.configure({ apiKey: 123 })\n\n// @ts-expect-error provider helpers reject unknown top-level options.\nOpenAI.configure({ bogus: true })\n\n// @ts-expect-error common generation options remain typed.\nOpenAI.configure({ generation: { maxTokens: \"many\" } })\n\n// @ts-expect-error provider-native options remain typed.\nOpenAI.configure({ providerOptions: { openai: { store: \"false\" } } })\n\n// @ts-expect-error auth is an override, so OpenAI rejects apiKey with auth.\nOpenAI.configure({ apiKey: \"sk-test\", auth: RuntimeAuth.bearer(\"oauth-token\") })\n\nOpenAI.chat(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: \"sk-test\" }).chat(\"gpt-4.1-mini\")\nOpenAI.configure({ apiKey: configApiKey }).chat(\"gpt-4.1-mini\")\nOpenAI.configure({ auth: RuntimeAuth.bearer(\"oauth-token\") }).chat(\"gpt-4.1-mini\")\n\n// @ts-expect-error OpenAI chat selectors only accept model ids.\nOpenAI.configure({ apiKey: \"sk-test\" }).chat(\"gpt-4.1-mini\", {})\n\n// @ts-expect-error auth is an override, so OpenAI Chat rejects apiKey with auth.\nOpenAI.configure({ apiKey: \"sk-test\", auth: RuntimeAuth.bearer(\"oauth-token\") })\n\n// @ts-expect-error Azure requires at least one of `resourceName` or `baseURL`.\nAzure.configure()\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).responses(\"deployment\")\nAzure.configure({ apiKey: configApiKey, resourceName: \"resource\" }).responses(\"deployment\")\nAzure.configure({ auth: RuntimeAuth.header(\"api-key\", \"azure-key\"), resourceName: \"resource\" }).responses(\"deployment\")\n\n// @ts-expect-error Azure model selectors only accept deployment ids.\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).responses(\"deployment\", {})\n\n// @ts-expect-error auth is an override, so Azure rejects apiKey with auth.\nAzure.configure({ resourceName: \"resource\", apiKey: \"azure-key\", auth: RuntimeAuth.header(\"api-key\", \"override\") })\n\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).chat(\"deployment\")\nAzure.configure({ apiKey: configApiKey, resourceName: \"resource\" }).chat(\"deployment\")\nAzure.configure({ auth: RuntimeAuth.header(\"api-key\", \"azure-key\"), resourceName: \"resource\" }).chat(\"deployment\")\n\n// @ts-expect-error Azure chat model selectors only accept deployment ids.\nAzure.configure({ apiKey: \"azure-key\", resourceName: \"resource\" }).chat(\"deployment\", {})\n\n// @ts-expect-error auth is an override, so Azure Chat rejects apiKey with auth.\nAzure.configure({ resourceName: \"resource\", apiKey: \"azure-key\", auth: RuntimeAuth.header(\"api-key\", \"override\") })\n\nAnthropic.configure({ apiKey: \"anthropic-key\" }).model(\"claude-haiku\")\n// @ts-expect-error Anthropic model selectors only accept model ids.\nAnthropic.configure({ apiKey: \"anthropic-key\" }).model(\"claude-haiku\", {})\n\nGoogle.configure({ apiKey: \"google-key\" }).model(\"gemini-2.5-flash\")\n// @ts-expect-error Google model selectors only accept model ids.\nGoogle.configure({ apiKey: \"google-key\" }).model(\"gemini-2.5-flash\", {})\n\nAmazonBedrock.configure({ apiKey: \"bedrock-key\" }).model(\"anthropic.claude\")\n// @ts-expect-error Bedrock model selectors only accept model ids.\nAmazonBedrock.configure({ apiKey: \"bedrock-key\" }).model(\"anthropic.claude\", {})\n\nOpenRouter.configure({ apiKey: \"openrouter-key\" }).model(\"openai/gpt-4o-mini\")\n// @ts-expect-error OpenRouter model selectors only accept model ids.\nOpenRouter.configure({ apiKey: \"openrouter-key\" }).model(\"openai/gpt-4o-mini\", {})\n\nXAI.configure({ apiKey: \"xai-key\" }).responses(\"grok-4\")\nXAI.configure({ apiKey: \"xai-key\" }).chat(\"grok-4\")\n// @ts-expect-error xAI Responses selectors only accept model ids.\nXAI.configure({ apiKey: \"xai-key\" }).responses(\"grok-4\", {})\n// @ts-expect-error xAI Chat selectors only accept model ids.\nXAI.configure({ apiKey: \"xai-key\" }).chat(\"grok-4\", {})\n\nOpenAICompatible.deepseek.configure({ apiKey: \"deepseek-key\" }).model(\"deepseek-chat\")\n// @ts-expect-error OpenAI-compatible family selectors only accept model ids.\nOpenAICompatible.deepseek.configure({ apiKey: \"deepseek-key\" }).model(\"deepseek-chat\", {})\n\nCloudflare.CloudflareWorkersAI.configure({ accountId: \"account\", apiKey: \"cf-key\" }).model(\"@cf/meta/llama\")\n// @ts-expect-error Cloudflare Workers AI model selectors only accept model ids.\nCloudflare.CloudflareWorkersAI.configure({ accountId: \"account\", apiKey: \"cf-key\" }).model(\"@cf/meta/llama\", {})\n\nGitHubCopilot.configure({ baseURL: \"https://copilot.test\", apiKey: \"copilot-key\" }).model(\"gpt-4.1\")\n// @ts-expect-error GitHub Copilot model selectors only accept model ids.\nGitHubCopilot.configure({ baseURL: \"https://copilot.test\", apiKey: \"copilot-key\" }).model(\"gpt-4.1\", {})\n"}}}}