@codeworksh/aikit 0.6.0 → 0.7.1-dev.20260824182047

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-codex-_3XkJ4bs.mjs","names":[],"sources":["../../src/providers/openai-codex/codex-tools.ts","../../src/utils/hash.ts","../../src/providers/openai-codex/codex-error.ts","../../src/providers/openai-codex/codex-prompt.ts","../../src/providers/openai-codex/codex-sse.ts","../../src/providers/openai-codex/codex-usage.ts","../../src/providers/openai-codex/codex-language-model.ts","../../src/providers/openai-codex/codex-provider.ts"],"sourcesContent":["import type { LanguageModelV3CallOptions, LanguageModelV3ToolChoice, SharedV3Warning } from \"@ai-sdk/provider\";\nimport type { TSchema } from \"typebox\";\nimport type * as Message from \"../../message/message.ts\";\nimport type { OpenAICodexCompatibility } from \"./codex-language-model.ts\";\n\nexport type OpenAICodexTool =\n\t| {\n\t\t\ttype: \"function\";\n\t\t\tname: string;\n\t\t\tdescription?: string;\n\t\t\tparameters: Record<string, unknown>;\n\t\t\tstrict?: boolean | null;\n\t\t\tdefer_loading?: boolean;\n\t }\n\t| {\n\t\t\ttype: \"custom\";\n\t\t\tname: string;\n\t\t\tdescription?: string;\n\t\t\tformat: {\n\t\t\t\ttype: \"grammar\";\n\t\t\t\tsyntax: \"lark\" | \"regex\";\n\t\t\t\tdefinition: string;\n\t\t\t};\n\t\t\tdefer_loading?: boolean;\n\t };\n\nexport type OpenAICodexGrammarConstraint = {\n\ttype: \"grammar\";\n\tformat: \"lark\" | \"regex\";\n\tdefinition: string;\n\tinputProperty: string;\n};\n\nexport type OpenAICodexGrammarInputBuffer = {\n\tinput: string;\n\tstarted: boolean;\n\tclosed: boolean;\n};\n\nexport function appendOpenAICodexGrammarInputJsonDelta(\n\tbuffer: OpenAICodexGrammarInputBuffer,\n\tinputProperty: string,\n\tnextInput: string,\n\tclose: boolean,\n): string | undefined {\n\tif (buffer.closed) {\n\t\tif (close && nextInput === buffer.input) return undefined;\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n\t}\n\tif (!nextInput.startsWith(buffer.input)) {\n\t\tthrow new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n\t}\n\n\tconst inputDelta = nextInput.slice(buffer.input.length);\n\tif (!close && inputDelta.length === 0) return undefined;\n\n\tlet delta = \"\";\n\tif (!buffer.started) {\n\t\tdelta += `{${JSON.stringify(inputProperty)}:\"`;\n\t\tbuffer.started = true;\n\t}\n\tdelta += JSON.stringify(inputDelta).slice(1, -1);\n\tbuffer.input = nextInput;\n\n\tif (close) {\n\t\tdelta += '\"}';\n\t\tbuffer.closed = true;\n\t}\n\treturn delta;\n}\n\ntype JsonSchemaObject = {\n\ttype?: unknown;\n\tproperties?: Record<string, { type?: unknown } | undefined>;\n\trequired?: unknown;\n};\n\nfunction inferGrammarInputProperty(parameters: TSchema): string {\n\tconst schema = parameters as JsonSchemaObject;\n\tif (schema.type !== \"object\") throw new Error(\"grammar constrained sampling requires an object parameter schema\");\n\tif (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== \"string\") {\n\t\tthrow new Error(\"grammar constrained sampling requires exactly one required string property\");\n\t}\n\tconst inputProperty = schema.required[0];\n\tif (!schema.properties?.[inputProperty]) {\n\t\tthrow new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);\n\t}\n\tif (schema.properties[inputProperty]?.type !== \"string\") {\n\t\tthrow new Error(`grammar constrained sampling property ${inputProperty} must have type string`);\n\t}\n\treturn inputProperty;\n}\n\nexport function resolveOpenAICodexToolConstraint(\n\ttool: Message.Tool,\n\tcompat?: OpenAICodexCompatibility,\n): OpenAICodexGrammarConstraint | { type: \"json_schema\"; strict: true } | undefined {\n\tconst config = tool.constrainedSampling;\n\tif (!config) return undefined;\n\tif (config.type === \"json_schema\") {\n\t\tif (compat?.supportsStrictMode ?? true) return { type: \"json_schema\", strict: true };\n\t\tif (config.strict === \"require\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but strict tools are unsupported.`,\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (!(compat?.supportsOpenAIGrammarTools ?? false)) return undefined;\n\n\tconst lark = config.variants.openai_lark;\n\tconst regex = config.variants.openai_regex;\n\tconst hasLark = typeof lark === \"string\" && lark.trim().length > 0;\n\tconst hasRegex = typeof regex === \"string\" && regex.trim().length > 0;\n\tif (!hasLark && !hasRegex) {\n\t\tthrow new Error(\n\t\t\t`Tool \"${tool.name}\" cannot use grammar constrained sampling: no supported grammar variant was provided.`,\n\t\t);\n\t}\n\ttry {\n\t\treturn {\n\t\t\ttype: \"grammar\",\n\t\t\tformat: hasLark ? \"lark\" : \"regex\",\n\t\t\tdefinition: hasLark ? lark! : regex!,\n\t\t\tinputProperty: inferGrammarInputProperty(tool.parameters),\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.`);\n\t}\n}\n\nexport const openAICodexTools = {\n\tcustom<TParameters extends TSchema>(args: {\n\t\tname: string;\n\t\tdescription: string;\n\t\tparameters: TParameters;\n\t\tformat: { type: \"grammar\"; syntax: \"lark\" | \"regex\"; definition: string };\n\t}): Message.Tool<TParameters> {\n\t\treturn {\n\t\t\tname: args.name,\n\t\t\tdescription: args.description,\n\t\t\tparameters: args.parameters,\n\t\t\tconstrainedSampling: {\n\t\t\t\ttype: \"grammar\",\n\t\t\t\tvariants:\n\t\t\t\t\targs.format.syntax === \"lark\"\n\t\t\t\t\t\t? { openai_lark: args.format.definition }\n\t\t\t\t\t\t: { openai_regex: args.format.definition },\n\t\t\t},\n\t\t};\n\t},\n};\n\nexport type OpenAICodexToolChoice = \"auto\" | \"none\" | \"required\";\nexport type OpenAICodexDeferredToolsMode = \"additional-tools\" | \"tool-search\";\n\nconst TOOL_SEARCH_MODEL_IDS = new Set([\n\t\"gpt-5.4\",\n\t\"gpt-5.4-mini\",\n\t\"gpt-5.5\",\n\t\"gpt-5.6-luna\",\n\t\"gpt-5.6-sol\",\n\t\"gpt-5.6-terra\",\n]);\nconst ADDITIONAL_TOOLS_MODEL_IDS = new Set([\"gpt-5.6-luna\", \"gpt-5.6-sol\", \"gpt-5.6-terra\"]);\n\nexport function resolveOpenAICodexDeferredToolsMode(\n\tmodelId: string,\n\tcompat?: OpenAICodexCompatibility,\n): OpenAICodexDeferredToolsMode | undefined {\n\tconst supportsAdditionalTools = compat?.supportsAdditionalTools ?? ADDITIONAL_TOOLS_MODEL_IDS.has(modelId);\n\tif (supportsAdditionalTools) return \"additional-tools\";\n\n\tconst supportsToolSearch = compat?.supportsToolSearch ?? TOOL_SEARCH_MODEL_IDS.has(modelId);\n\treturn supportsToolSearch ? \"tool-search\" : undefined;\n}\n\nexport function prepareOpenAICodexTools({\n\ttools,\n\ttoolChoice,\n\tdeferredToolNames,\n}: {\n\ttools: LanguageModelV3CallOptions[\"tools\"];\n\ttoolChoice: LanguageModelV3ToolChoice | undefined;\n\tdeferredToolNames?: ReadonlySet<string>;\n}): {\n\tcodexTools: OpenAICodexTool[] | undefined;\n\tdeferredCodexTools: ReadonlyMap<string, OpenAICodexTool>;\n\tgrammarToolInputProperties: ReadonlyMap<string, string>;\n\tcodexToolChoice: OpenAICodexToolChoice | undefined;\n\twarnings: SharedV3Warning[];\n} {\n\tconst warnings: SharedV3Warning[] = [];\n\tconst deferredCodexTools = new Map<string, OpenAICodexTool>();\n\tconst grammarToolInputProperties = new Map<string, string>();\n\n\tif (!tools || tools.length === 0) {\n\t\treturn {\n\t\t\tcodexTools: undefined,\n\t\t\tdeferredCodexTools,\n\t\t\tgrammarToolInputProperties,\n\t\t\tcodexToolChoice: undefined,\n\t\t\twarnings,\n\t\t};\n\t}\n\n\tconst codexTools: OpenAICodexTool[] = [];\n\tfor (const tool of tools) {\n\t\tif (tool.type !== \"function\") {\n\t\t\twarnings.push({\n\t\t\t\ttype: \"unsupported\",\n\t\t\t\tfeature: `tool type ${tool.type}`,\n\t\t\t\tdetails: `OpenAI Codex only supports function tools; ignoring ${tool.name}.`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst metadata = tool.providerOptions?.[\"openai-codex\"] as Record<string, unknown> | undefined;\n\t\tconst grammar = metadata?.grammar as OpenAICodexGrammarConstraint | undefined;\n\t\tconst codexTool: OpenAICodexTool =\n\t\t\tgrammar?.type === \"grammar\"\n\t\t\t\t? {\n\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t...(tool.description !== undefined && { description: tool.description }),\n\t\t\t\t\t\tformat: {\n\t\t\t\t\t\t\ttype: \"grammar\",\n\t\t\t\t\t\t\tsyntax: grammar.format,\n\t\t\t\t\t\t\tdefinition: grammar.definition,\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\ttype: \"function\",\n\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t...(tool.description !== undefined && { description: tool.description }),\n\t\t\t\t\t\tparameters: tool.inputSchema as Record<string, unknown>,\n\t\t\t\t\t\tstrict: tool.strict ?? null,\n\t\t\t\t\t};\n\t\tif (grammar?.type === \"grammar\") grammarToolInputProperties.set(tool.name, grammar.inputProperty);\n\t\tif (deferredToolNames?.has(tool.name)) deferredCodexTools.set(tool.name, codexTool);\n\t\telse codexTools.push(codexTool);\n\t}\n\n\tlet codexToolChoice: OpenAICodexToolChoice | undefined;\n\tswitch (toolChoice?.type) {\n\t\tcase undefined:\n\t\t\tbreak;\n\t\tcase \"auto\":\n\t\tcase \"none\":\n\t\tcase \"required\":\n\t\t\tcodexToolChoice = toolChoice.type;\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\twarnings.push({\n\t\t\t\ttype: \"unsupported\",\n\t\t\t\tfeature: \"toolChoice tool name\",\n\t\t\t\tdetails: \"OpenAI Codex does not support forcing a specific tool; using 'required' instead.\",\n\t\t\t});\n\t\t\tcodexToolChoice = \"required\";\n\t\t\tbreak;\n\t}\n\n\treturn {\n\t\tcodexTools: codexTools.length > 0 ? codexTools : undefined,\n\t\tdeferredCodexTools,\n\t\tgrammarToolInputProperties,\n\t\tcodexToolChoice,\n\t\twarnings,\n\t};\n}\n","/** Fast deterministic hash for shortening provider wire identifiers. */\nexport function shortHash(value: string): string {\n\tlet high = 0xdeadbeef;\n\tlet low = 0x41c6ce57;\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst character = value.charCodeAt(index);\n\t\thigh = Math.imul(high ^ character, 2654435761);\n\t\tlow = Math.imul(low ^ character, 1597334677);\n\t}\n\thigh = Math.imul(high ^ (high >>> 16), 2246822507) ^ Math.imul(low ^ (low >>> 13), 3266489909);\n\tlow = Math.imul(low ^ (low >>> 16), 2246822507) ^ Math.imul(high ^ (high >>> 13), 3266489909);\n\treturn (low >>> 0).toString(36) + (high >>> 0).toString(36);\n}\n","import { APICallError } from \"@ai-sdk/provider\";\n\ntype OpenAICodexErrorPayload = {\n\terror?: {\n\t\tcode?: string;\n\t\ttype?: string;\n\t\tmessage?: string;\n\t\tplan_type?: string;\n\t\tresets_at?: number;\n\t};\n};\n\nfunction isTerminalRateLimitError(body: string): boolean {\n\treturn /GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(\n\t\tbody,\n\t);\n}\n\n/**\n * Turn a Codex error payload into a human-friendly message. ChatGPT plan usage\n * limits deserve a clearer message than the raw backend error.\n */\nexport function openAICodexErrorMessage(status: number, body: string, statusText?: string): string {\n\tlet message = body || statusText || \"OpenAI Codex request failed\";\n\n\ttry {\n\t\tconst parsed = JSON.parse(body) as OpenAICodexErrorPayload;\n\t\tconst error = parsed?.error;\n\t\tif (error) {\n\t\t\tconst code = error.code ?? error.type ?? \"\";\n\t\t\tif (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) || status === 429) {\n\t\t\t\tconst plan = error.plan_type ? ` (${error.plan_type.toLowerCase()} plan)` : \"\";\n\t\t\t\tconst minutes = error.resets_at\n\t\t\t\t\t? Math.max(0, Math.round((error.resets_at * 1000 - Date.now()) / 60000))\n\t\t\t\t\t: undefined;\n\t\t\t\tconst when = minutes === undefined ? \"\" : ` Try again in ~${minutes} min.`;\n\t\t\t\treturn `You have hit your ChatGPT usage limit${plan}.${when}`.trim();\n\t\t\t}\n\t\t\tmessage = error.message || message;\n\t\t}\n\t} catch {\n\t\t// Not JSON; keep the raw body as the message.\n\t}\n\n\treturn message;\n}\n\nexport async function createOpenAICodexAPICallError(args: {\n\tresponse: Response;\n\turl: string;\n\trequestBodyValues: unknown;\n}): Promise<APICallError> {\n\tconst { response, url, requestBodyValues } = args;\n\tconst responseBody = await response.text().catch(() => \"\");\n\tconst responseHeaders: Record<string, string> = {};\n\tresponse.headers.forEach((value, key) => {\n\t\tresponseHeaders[key] = value;\n\t});\n\n\treturn new APICallError({\n\t\tmessage: openAICodexErrorMessage(response.status, responseBody, response.statusText),\n\t\turl,\n\t\trequestBodyValues,\n\t\tstatusCode: response.status,\n\t\tresponseHeaders,\n\t\tresponseBody,\n\t\tisRetryable:\n\t\t\tresponse.status === 408 ||\n\t\t\tresponse.status === 409 ||\n\t\t\t(response.status === 429 && !isTerminalRateLimitError(responseBody)) ||\n\t\t\tresponse.status >= 500,\n\t});\n}\n","import type {\n\tLanguageModelV3FilePart,\n\tLanguageModelV3Prompt,\n\tLanguageModelV3ToolResultOutput,\n\tLanguageModelV4FilePart,\n\tLanguageModelV4Prompt,\n\tLanguageModelV4ToolResultOutput,\n} from \"@ai-sdk/provider\";\nimport { shortHash } from \"../../utils/hash.ts\";\nimport type { OpenAICodexDeferredToolsMode, OpenAICodexTool } from \"./codex-tools.ts\";\n\n/**\n * OpenAI Responses API input item types accepted by the Codex backend.\n */\nexport type OpenAICodexInputItem =\n\t| {\n\t\t\trole: \"user\";\n\t\t\tcontent: Array<\n\t\t\t\t{ type: \"input_text\"; text: string } | { type: \"input_image\"; image_url: string; detail?: string }\n\t\t\t>;\n\t }\n\t| {\n\t\t\ttype: \"message\";\n\t\t\trole: \"assistant\";\n\t\t\tid: string;\n\t\t\tcontent: Array<{ type: \"output_text\"; text: string; annotations: unknown[] }>;\n\t\t\tstatus: \"completed\";\n\t }\n\t| {\n\t\t\ttype: \"function_call\";\n\t\t\tid?: string;\n\t\t\tcall_id: string;\n\t\t\tname: string;\n\t\t\targuments: string;\n\t\t\tnamespace?: string;\n\t }\n\t| {\n\t\t\ttype: \"custom_tool_call\";\n\t\t\tid?: string;\n\t\t\tcall_id: string;\n\t\t\tname: string;\n\t\t\tinput: string;\n\t\t\tnamespace?: string;\n\t }\n\t| {\n\t\t\ttype: \"reasoning\";\n\t\t\tid: string;\n\t\t\t[key: string]: unknown;\n\t }\n\t| {\n\t\t\ttype: \"function_call_output\";\n\t\t\tcall_id: string;\n\t\t\toutput:\n\t\t\t\t| string\n\t\t\t\t| Array<{ type: \"input_text\"; text: string } | { type: \"input_image\"; image_url: string; detail: \"auto\" }>;\n\t }\n\t| {\n\t\t\ttype: \"custom_tool_call_output\";\n\t\t\tcall_id: string;\n\t\t\toutput: string;\n\t }\n\t| {\n\t\t\ttype: \"additional_tools\";\n\t\t\trole: \"developer\";\n\t\t\ttools: OpenAICodexTool[];\n\t }\n\t| {\n\t\t\ttype: \"tool_search_call\";\n\t\t\tcall_id: string;\n\t\t\texecution: \"client\";\n\t\t\tstatus: \"completed\";\n\t\t\targuments: { query: string; limit: number };\n\t }\n\t| {\n\t\t\ttype: \"tool_search_output\";\n\t\t\tcall_id: string;\n\t\t\texecution: \"client\";\n\t\t\tstatus: \"completed\";\n\t\t\ttools: OpenAICodexTool[];\n\t };\n\nexport type OpenAICodexPrompt = {\n\tinstructions: string;\n\tinput: OpenAICodexInputItem[];\n};\n\nconst DEFAULT_INSTRUCTIONS = \"You are a helpful assistant.\";\n\nexport type OpenAICodexPromptOptions = {\n\tdeferredTools?: ReadonlyMap<string, OpenAICodexTool>;\n\tdeferredToolsMode?: OpenAICodexDeferredToolsMode;\n\tgrammarToolInputProperties?: ReadonlyMap<string, string>;\n\tsupportsImages?: boolean;\n};\n\n// Tool call ids round-trip through the AI SDK as `call_id|item_id` because the\n// Responses API needs both halves: `call_id` to pair function_call_output and\n// `id` for the function_call item itself.\nexport function splitToolCallId(toolCallId: string): { callId: string; itemId: string } {\n\tconst separator = toolCallId.indexOf(\"|\");\n\tif (separator === -1) return { callId: toolCallId, itemId: toolCallId };\n\treturn { callId: toolCallId.slice(0, separator), itemId: toolCallId.slice(separator + 1) };\n}\n\nexport function joinToolCallId(callId: string, itemId: string): string {\n\treturn `${callId}|${itemId}`;\n}\n\nfunction uint8ArrayToBase64(bytes: Uint8Array): string {\n\tlet binary = \"\";\n\tfor (const byte of bytes) {\n\t\tbinary += String.fromCharCode(byte);\n\t}\n\treturn btoa(binary);\n}\n\nfunction imageUrlFromFilePart(part: LanguageModelV3FilePart | LanguageModelV4FilePart): string | undefined {\n\tconst data = part.data;\n\tif (data instanceof URL) return data.toString();\n\tif (typeof data === \"string\") {\n\t\tif (data.startsWith(\"data:\") || data.startsWith(\"http://\") || data.startsWith(\"https://\")) return data;\n\t\treturn `data:${part.mediaType};base64,${data}`;\n\t}\n\tif (data instanceof Uint8Array) {\n\t\treturn `data:${part.mediaType};base64,${uint8ArrayToBase64(data)}`;\n\t}\n\tif (\"type\" in data) {\n\t\tif (data.type === \"url\") return data.url.toString();\n\t\tif (data.type === \"data\") {\n\t\t\treturn typeof data.data === \"string\"\n\t\t\t\t? `data:${part.mediaType};base64,${data.data}`\n\t\t\t\t: `data:${part.mediaType};base64,${uint8ArrayToBase64(data.data)}`;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction toolResultOutput(\n\toutput: LanguageModelV3ToolResultOutput | LanguageModelV4ToolResultOutput,\n\tsupportsImages: boolean,\n): Extract<OpenAICodexInputItem, { type: \"function_call_output\" }>[\"output\"] {\n\tswitch (output.type) {\n\t\tcase \"text\":\n\t\tcase \"error-text\":\n\t\t\treturn output.value || \"(no tool output)\";\n\t\tcase \"json\":\n\t\tcase \"error-json\":\n\t\t\treturn JSON.stringify(output.value);\n\t\tcase \"execution-denied\":\n\t\t\treturn output.reason ?? \"Tool execution denied\";\n\t\tcase \"content\": {\n\t\t\tconst text = output.value\n\t\t\t\t.filter((part): part is Extract<typeof part, { type: \"text\" }> => part.type === \"text\")\n\t\t\t\t.map((part) => part.text)\n\t\t\t\t.join(\"\\n\");\n\t\t\tconst images: Array<{ type: \"input_image\"; image_url: string; detail: \"auto\" }> = [];\n\t\t\tif (supportsImages) {\n\t\t\t\tfor (const part of output.value) {\n\t\t\t\t\tif (part.type === \"file-data\" && part.mediaType.startsWith(\"image/\")) {\n\t\t\t\t\t\timages.push({\n\t\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\t\timage_url: `data:${part.mediaType};base64,${part.data}`,\n\t\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (part.type === \"file-url\") {\n\t\t\t\t\t\timages.push({ type: \"input_image\", image_url: part.url, detail: \"auto\" });\n\t\t\t\t\t} else if (part.type === \"file\" && part.mediaType.startsWith(\"image/\")) {\n\t\t\t\t\t\tconst data = part.data;\n\t\t\t\t\t\tif (data.type === \"url\") {\n\t\t\t\t\t\t\timages.push({ type: \"input_image\", image_url: data.url.toString(), detail: \"auto\" });\n\t\t\t\t\t\t} else if (data.type === \"data\") {\n\t\t\t\t\t\t\tconst encoded = typeof data.data === \"string\" ? data.data : uint8ArrayToBase64(data.data);\n\t\t\t\t\t\t\timages.push({\n\t\t\t\t\t\t\t\ttype: \"input_image\",\n\t\t\t\t\t\t\t\timage_url: `data:${part.mediaType};base64,${encoded}`,\n\t\t\t\t\t\t\t\tdetail: \"auto\",\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (images.length === 0)\n\t\t\t\treturn text || (output.value.length > 0 ? \"(see attached image)\" : \"(no tool output)\");\n\t\t\treturn [...(text ? [{ type: \"input_text\" as const, text }] : []), ...images];\n\t\t}\n\t\tdefault:\n\t\t\treturn JSON.stringify(output);\n\t}\n}\n\nfunction customToolInput(input: unknown, toolName: string, inputProperty: string): string {\n\tif (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n\t\tthrow new Error(`Custom tool \"${toolName}\" requires object input with string property \"${inputProperty}\".`);\n\t}\n\tconst value = (input as Record<string, unknown>)[inputProperty];\n\tif (typeof value !== \"string\") {\n\t\tthrow new Error(`Custom tool \"${toolName}\" requires string input property \"${inputProperty}\".`);\n\t}\n\treturn value;\n}\n\nfunction customToolOutput(\n\toutput: LanguageModelV3ToolResultOutput | LanguageModelV4ToolResultOutput,\n\tsupportsImages: boolean,\n): string {\n\tconst value = toolResultOutput(output, supportsImages);\n\treturn typeof value === \"string\" ? value : JSON.stringify(value);\n}\n\nfunction codexProviderMetadata(\n\tproviderOptions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tconst codex = providerOptions?.[\"openai-codex\"];\n\treturn typeof codex === \"object\" && codex !== null && !Array.isArray(codex)\n\t\t? (codex as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction addedToolNames(providerOptions: Record<string, unknown> | undefined): string[] {\n\tconst names = codexProviderMetadata(providerOptions)?.addedToolNames;\n\treturn Array.isArray(names) ? names.filter((name): name is string => typeof name === \"string\") : [];\n}\n\nfunction reasoningItem(\n\tproviderOptions: Record<string, unknown> | undefined,\n): Extract<OpenAICodexInputItem, { type: \"reasoning\" }> | undefined {\n\tconst value = codexProviderMetadata(providerOptions)?.reasoningItem;\n\tif (typeof value !== \"string\") return undefined;\n\ttry {\n\t\tconst parsed = JSON.parse(value) as unknown;\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) return undefined;\n\t\tconst item = parsed as Record<string, unknown>;\n\t\treturn item.type === \"reasoning\" && typeof item.id === \"string\"\n\t\t\t? (item as Extract<OpenAICodexInputItem, { type: \"reasoning\" }>)\n\t\t\t: undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Collect definitions that were introduced at a transcript load point rather than at request start. */\nexport function collectOpenAICodexDeferredToolNames(\n\tprompt: LanguageModelV3Prompt | LanguageModelV4Prompt,\n): Set<string> {\n\tconst deferredNames = new Set<string>();\n\tconst usedNames = new Set<string>();\n\n\tfor (const message of prompt) {\n\t\tif (message.role === \"assistant\") {\n\t\t\tfor (const part of message.content) {\n\t\t\t\tif (part.type === \"tool-call\") usedNames.add(part.toolName);\n\t\t\t\tif (part.type === \"tool-result\") {\n\t\t\t\t\tfor (const name of addedToolNames(part.providerOptions)) {\n\t\t\t\t\t\tif (!usedNames.has(name)) deferredNames.add(name);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"tool\") continue;\n\t\tfor (const part of message.content) {\n\t\t\tif (part.type !== \"tool-result\") continue;\n\t\t\tfor (const name of addedToolNames(part.providerOptions)) {\n\t\t\t\tif (!usedNames.has(name)) deferredNames.add(name);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn deferredNames;\n}\n\nfunction deferredToolCallId(toolCallId: string, names: readonly string[]): string {\n\treturn `aikit_tool_load_${shortHash(`${toolCallId}:${names.join(\",\")}`)}`;\n}\n\n/**\n * Convert an AI SDK V3 prompt into the Codex Responses request shape.\n * System messages become `instructions`; everything else maps to `input` items.\n */\nexport function convertToOpenAICodexPrompt(\n\tprompt: LanguageModelV3Prompt | LanguageModelV4Prompt,\n\toptions?: OpenAICodexPromptOptions,\n): OpenAICodexPrompt {\n\tlet instructions: string | undefined;\n\tconst input: OpenAICodexInputItem[] = [];\n\tlet syntheticMessageCounter = 0;\n\tconst loadedToolNames = new Set<string>();\n\n\tconst appendDeferredTools = (toolCallId: string, names: readonly string[]): void => {\n\t\tconst tools: OpenAICodexTool[] = [];\n\t\tfor (const name of names) {\n\t\t\tconst tool = options?.deferredTools?.get(name);\n\t\t\tif (!tool || loadedToolNames.has(name)) continue;\n\t\t\tloadedToolNames.add(name);\n\t\t\ttools.push(tool);\n\t\t}\n\t\tif (tools.length === 0) return;\n\n\t\tif (options?.deferredToolsMode === \"additional-tools\") {\n\t\t\tinput.push({ type: \"additional_tools\", role: \"developer\", tools });\n\t\t\treturn;\n\t\t}\n\t\tif (options?.deferredToolsMode === \"tool-search\") {\n\t\t\tconst callId = deferredToolCallId(\n\t\t\t\ttoolCallId,\n\t\t\t\ttools.map((tool) => tool.name),\n\t\t\t);\n\t\t\tinput.push({\n\t\t\t\ttype: \"tool_search_call\",\n\t\t\t\tcall_id: callId,\n\t\t\t\texecution: \"client\",\n\t\t\t\tstatus: \"completed\",\n\t\t\t\targuments: { query: tools.map((tool) => tool.name).join(\" \"), limit: tools.length },\n\t\t\t});\n\t\t\tinput.push({\n\t\t\t\ttype: \"tool_search_output\",\n\t\t\t\tcall_id: callId,\n\t\t\t\texecution: \"client\",\n\t\t\t\tstatus: \"completed\",\n\t\t\t\ttools: tools.map((tool) => ({ ...tool, defer_loading: true })),\n\t\t\t});\n\t\t}\n\t};\n\n\tfor (const message of prompt) {\n\t\tswitch (message.role) {\n\t\t\tcase \"system\": {\n\t\t\t\tinstructions = instructions == null ? message.content : `${instructions}\\n\\n${message.content}`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"user\": {\n\t\t\t\tconst content: Extract<OpenAICodexInputItem, { role: \"user\" }>[\"content\"] = [];\n\t\t\t\tfor (const part of message.content) {\n\t\t\t\t\tif (part.type === \"text\") {\n\t\t\t\t\t\tcontent.push({ type: \"input_text\", text: part.text });\n\t\t\t\t\t} else if (part.type === \"file\" && part.mediaType.startsWith(\"image/\")) {\n\t\t\t\t\t\tconst imageUrl = imageUrlFromFilePart(part);\n\t\t\t\t\t\tif (imageUrl) content.push({ type: \"input_image\", image_url: imageUrl, detail: \"auto\" });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (content.length > 0) {\n\t\t\t\t\tinput.push({ role: \"user\", content });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"assistant\": {\n\t\t\t\tfor (const part of message.content) {\n\t\t\t\t\tif (part.type === \"reasoning\") {\n\t\t\t\t\t\tconst item = reasoningItem(part.providerOptions);\n\t\t\t\t\t\tif (item) input.push(item);\n\t\t\t\t\t} else if (part.type === \"text\") {\n\t\t\t\t\t\tsyntheticMessageCounter++;\n\t\t\t\t\t\tconst messageId = codexProviderMetadata(part.providerOptions)?.messageId;\n\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\tid:\n\t\t\t\t\t\t\t\ttypeof messageId === \"string\" && messageId.length <= 64\n\t\t\t\t\t\t\t\t\t? messageId\n\t\t\t\t\t\t\t\t\t: `msg_aikit_${syntheticMessageCounter}`,\n\t\t\t\t\t\t\tcontent: [{ type: \"output_text\", text: part.text, annotations: [] }],\n\t\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (part.type === \"tool-call\") {\n\t\t\t\t\t\tconst { callId, itemId } = splitToolCallId(part.toolCallId);\n\t\t\t\t\t\tconst metadata = codexProviderMetadata(part.providerOptions);\n\t\t\t\t\t\tconst namespace = metadata?.namespace;\n\t\t\t\t\t\tconst inputProperty = options?.grammarToolInputProperties?.get(part.toolName);\n\t\t\t\t\t\tif (inputProperty) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\ttype: \"custom_tool_call\",\n\t\t\t\t\t\t\t\t...(metadata?.omitItemId === true || !itemId.startsWith(\"ctc_\") ? {} : { id: itemId }),\n\t\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\t\tname: part.toolName,\n\t\t\t\t\t\t\t\tinput: customToolInput(part.input, part.toolName, inputProperty),\n\t\t\t\t\t\t\t\t...(typeof namespace === \"string\" ? { namespace } : {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\ttype: \"function_call\",\n\t\t\t\t\t\t\t\t...(metadata?.omitItemId === true || !itemId.startsWith(\"fc_\") ? {} : { id: itemId }),\n\t\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\t\tname: part.toolName,\n\t\t\t\t\t\t\t\targuments: typeof part.input === \"string\" ? part.input : JSON.stringify(part.input ?? {}),\n\t\t\t\t\t\t\t\t...(typeof namespace === \"string\" ? { namespace } : {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"tool\": {\n\t\t\t\tfor (const part of message.content) {\n\t\t\t\t\tif (part.type !== \"tool-result\") continue;\n\t\t\t\t\tconst { callId } = splitToolCallId(part.toolCallId);\n\t\t\t\t\tif (options?.grammarToolInputProperties?.has(part.toolName)) {\n\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\ttype: \"custom_tool_call_output\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\toutput: customToolOutput(part.output, options?.supportsImages ?? true),\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\ttype: \"function_call_output\",\n\t\t\t\t\t\t\tcall_id: callId,\n\t\t\t\t\t\t\toutput: toolResultOutput(part.output, options?.supportsImages ?? true),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tappendDeferredTools(part.toolCallId, addedToolNames(part.providerOptions));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { instructions: instructions || DEFAULT_INSTRUCTIONS, input };\n}\n","/**\n * Minimal SSE parsing for the Codex Responses endpoint. Each event is a JSON\n * payload on `data:` lines; `[DONE]` terminates the stream.\n */\nexport function parseOpenAICodexSSEStream(body: ReadableStream<Uint8Array>): ReadableStream<Record<string, unknown>> {\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\tconst parseChunk = (chunk: string, controller: TransformStreamDefaultController<Record<string, unknown>>) => {\n\t\tconst dataLines = chunk\n\t\t\t.split(\"\\n\")\n\t\t\t.filter((line) => line.startsWith(\"data:\"))\n\t\t\t.map((line) => line.slice(5).trim());\n\t\tif (dataLines.length === 0) return;\n\n\t\tconst data = dataLines.join(\"\\n\").trim();\n\t\tif (!data || data === \"[DONE]\") return;\n\n\t\ttry {\n\t\t\tcontroller.enqueue(JSON.parse(data) as Record<string, unknown>);\n\t\t} catch (cause) {\n\t\t\tcontroller.error(new Error(`Invalid OpenAI Codex SSE JSON: ${data.slice(0, 200)}`, { cause }));\n\t\t}\n\t};\n\n\treturn body.pipeThrough(\n\t\tnew TransformStream<Uint8Array, Record<string, unknown>>({\n\t\t\ttransform(value, controller) {\n\t\t\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\t\t\tlet index = buffer.indexOf(\"\\n\\n\");\n\t\t\t\twhile (index !== -1) {\n\t\t\t\t\tconst chunk = buffer.slice(0, index);\n\t\t\t\t\tbuffer = buffer.slice(index + 2);\n\t\t\t\t\tparseChunk(chunk, controller);\n\t\t\t\t\tindex = buffer.indexOf(\"\\n\\n\");\n\t\t\t\t}\n\t\t\t},\n\t\t\tflush(controller) {\n\t\t\t\tbuffer += decoder.decode();\n\t\t\t\tif (buffer.trim()) parseChunk(buffer, controller);\n\t\t\t},\n\t\t}),\n\t);\n}\n","import type { JSONObject, LanguageModelV3FinishReason, LanguageModelV3Usage } from \"@ai-sdk/provider\";\n\nexport type OpenAICodexUsage = {\n\tinput_tokens?: number;\n\toutput_tokens?: number;\n\ttotal_tokens?: number;\n\tinput_tokens_details?: { cached_tokens?: number; cache_write_tokens?: number };\n\toutput_tokens_details?: { reasoning_tokens?: number };\n};\n\nexport function convertOpenAICodexUsage(usage: OpenAICodexUsage | undefined): LanguageModelV3Usage {\n\tconst inputTotal = usage?.input_tokens;\n\tconst cachedTokens = usage?.input_tokens_details?.cached_tokens ?? 0;\n\tconst cacheWriteTokens = usage?.input_tokens_details?.cache_write_tokens ?? 0;\n\tconst outputTotal = usage?.output_tokens;\n\tconst reasoningTokens = usage?.output_tokens_details?.reasoning_tokens ?? 0;\n\n\treturn {\n\t\tinputTokens: {\n\t\t\ttotal: inputTotal,\n\t\t\tnoCache: inputTotal === undefined ? undefined : Math.max(inputTotal - cachedTokens - cacheWriteTokens, 0),\n\t\t\tcacheRead: inputTotal === undefined ? undefined : cachedTokens,\n\t\t\tcacheWrite: inputTotal === undefined ? undefined : cacheWriteTokens,\n\t\t},\n\t\toutputTokens: {\n\t\t\ttotal: outputTotal,\n\t\t\ttext: outputTotal === undefined ? undefined : outputTotal - reasoningTokens,\n\t\t\treasoning: outputTotal === undefined ? undefined : reasoningTokens,\n\t\t},\n\t\t...(usage ? { raw: usage as JSONObject } : {}),\n\t};\n}\n\nexport function mapOpenAICodexFinishReason(\n\tstatus: string | undefined,\n\thasToolCalls: boolean,\n\tincompleteReason?: string,\n): LanguageModelV3FinishReason {\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn { unified: hasToolCalls ? \"tool-calls\" : \"stop\", raw: status };\n\t\tcase \"incomplete\":\n\t\t\treturn incompleteReason === \"max_output_tokens\"\n\t\t\t\t? { unified: \"length\", raw: `${status}.${incompleteReason}` }\n\t\t\t\t: { unified: \"error\", raw: incompleteReason ? `${status}.${incompleteReason}` : status };\n\t\tcase \"failed\":\n\t\tcase \"cancelled\":\n\t\t\treturn { unified: \"error\", raw: status };\n\t\tcase undefined:\n\t\t\treturn { unified: \"other\", raw: undefined };\n\t\tdefault:\n\t\t\treturn { unified: \"stop\", raw: status };\n\t}\n}\n","import type * as NodeZlib from \"node:zlib\";\nimport type {\n\tLanguageModelV3,\n\tLanguageModelV3CallOptions,\n\tLanguageModelV3Content,\n\tLanguageModelV3FinishReason,\n\tLanguageModelV3GenerateResult,\n\tLanguageModelV3StreamPart,\n\tLanguageModelV3StreamResult,\n\tLanguageModelV3Usage,\n\tSharedV3Warning,\n} from \"@ai-sdk/provider\";\nimport { createOpenAICodexAPICallError } from \"./codex-error.ts\";\nimport { collectOpenAICodexDeferredToolNames, convertToOpenAICodexPrompt, joinToolCallId } from \"./codex-prompt.ts\";\nimport { parseOpenAICodexSSEStream } from \"./codex-sse.ts\";\nimport {\n\tappendOpenAICodexGrammarInputJsonDelta,\n\tprepareOpenAICodexTools,\n\tresolveOpenAICodexDeferredToolsMode,\n\ttype OpenAICodexGrammarInputBuffer,\n} from \"./codex-tools.ts\";\nimport { convertOpenAICodexUsage, mapOpenAICodexFinishReason, type OpenAICodexUsage } from \"./codex-usage.ts\";\n\nexport const OPENAI_CODEX_DEFAULT_BASE_URL = \"https://chatgpt.com/backend-api\";\nexport const OPENAI_CODEX_PROMPT_CACHE_KEY_MAX_LENGTH = 64;\nconst REQUEST_COMPRESSION_ZSTD_LEVEL = 3;\n\ntype ProcessWithBuiltinModule = typeof process & {\n\tgetBuiltinModule?: (id: \"node:zlib\") => typeof NodeZlib;\n};\n\nfunction compressOpenAICodexRequest(body: string): Uint8Array | undefined {\n\tif (typeof process === \"undefined\" || !(process.versions?.node || process.versions?.bun)) return undefined;\n\tconst zlib = (process as ProcessWithBuiltinModule).getBuiltinModule?.(\"node:zlib\");\n\tif (!zlib || typeof zlib.zstdCompressSync !== \"function\") return undefined;\n\ttry {\n\t\tconst compressed = zlib.zstdCompressSync(body, {\n\t\t\tparams: { [zlib.constants.ZSTD_c_compressionLevel]: REQUEST_COMPRESSION_ZSTD_LEVEL },\n\t\t});\n\t\treturn new Uint8Array(compressed.buffer, compressed.byteOffset, compressed.byteLength);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function clampOpenAICodexPromptCacheKey(key: string | undefined): string | undefined {\n\tif (key === undefined) return undefined;\n\tconst characters = Array.from(key);\n\treturn characters.length <= OPENAI_CODEX_PROMPT_CACHE_KEY_MAX_LENGTH\n\t\t? key\n\t\t: characters.slice(0, OPENAI_CODEX_PROMPT_CACHE_KEY_MAX_LENGTH).join(\"\");\n}\n\nexport type OpenAICodexModelId =\n\t| \"gpt-5.3-codex-spark\"\n\t| \"gpt-5.4\"\n\t| \"gpt-5.4-mini\"\n\t| \"gpt-5.5\"\n\t| \"gpt-5.6-luna\"\n\t| \"gpt-5.6-sol\"\n\t| \"gpt-5.6-terra\"\n\t| (string & {});\n\nexport type OpenAICodexServiceTier = \"auto\" | \"default\" | \"flex\" | \"scale\" | \"priority\";\n\nexport type OpenAICodexCompatibility = {\n\tsupportsToolSearch?: boolean;\n\tsupportsAdditionalTools?: boolean;\n\tsupportsStrictMode?: boolean;\n\tsupportsOpenAIGrammarTools?: boolean;\n\t/** Internal transport capability derived from the model's input modalities. */\n\tsupportsImages?: boolean;\n};\n\n/**\n * Per-call options, passed via `providerOptions[\"openai-codex\"]`.\n */\nexport type OpenAICodexLanguageModelOptions = {\n\t/** Reasoning effort forwarded as `reasoning.effort`. */\n\treasoningEffort?: \"none\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\" | (string & {});\n\t/** Reasoning summary verbosity; defaults to `auto` when an effort is set. */\n\treasoningSummary?: \"auto\" | \"concise\" | \"detailed\" | \"off\" | \"on\" | null;\n\t/** Output text verbosity; defaults to `low`. */\n\ttextVerbosity?: \"low\" | \"medium\" | \"high\";\n\tserviceTier?: OpenAICodexServiceTier;\n\t/** Prompt cache key; defaults to the provider `sessionId`. */\n\tpromptCacheKey?: string;\n\t/** `include` fields; defaults to `[\"reasoning.encrypted_content\"]`. */\n\tinclude?: string[];\n\t/** @deprecated Codex always requires `store: false`; this value is ignored. */\n\tstore?: boolean;\n};\n\nexport type OpenAICodexLanguageModelConfig = {\n\tprovider: string;\n\tbaseURL: string;\n\theaders: () => PromiseLike<Record<string, string | undefined>> | Record<string, string | undefined>;\n\tfetch?: typeof globalThis.fetch;\n\tsessionId?: string;\n\tserviceTier?: OpenAICodexServiceTier;\n\tcompat?: OpenAICodexCompatibility;\n};\n\n/**\n * Resolve the Codex responses endpoint from a base URL that may already\n * include the `/codex` or `/codex/responses` suffix.\n */\nexport function resolveOpenAICodexUrl(baseUrl?: string): string {\n\tconst raw = baseUrl?.trim() ? baseUrl : OPENAI_CODEX_DEFAULT_BASE_URL;\n\tconst normalized = raw.replace(/\\/+$/, \"\");\n\tif (normalized.endsWith(\"/codex/responses\")) return normalized;\n\tif (normalized.endsWith(\"/codex\")) return `${normalized}/responses`;\n\treturn `${normalized}/codex/responses`;\n}\n\ntype CodexEvent = Record<string, unknown>;\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value) ? (value as CodexEvent) : undefined;\n}\n\nfunction asString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction cleanHeaders(headers: Record<string, string | undefined>): Record<string, string> {\n\tconst result: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (value !== undefined) result[key] = value;\n\t}\n\treturn result;\n}\n\nexport class OpenAICodexLanguageModel implements LanguageModelV3 {\n\treadonly specificationVersion = \"v3\" as const;\n\treadonly modelId: OpenAICodexModelId;\n\n\tprivate readonly config: OpenAICodexLanguageModelConfig;\n\n\tconstructor(modelId: OpenAICodexModelId, config: OpenAICodexLanguageModelConfig) {\n\t\tthis.modelId = modelId;\n\t\tthis.config = config;\n\t}\n\n\tget provider(): string {\n\t\treturn this.config.provider;\n\t}\n\n\tget supportedUrls(): Record<string, RegExp[]> {\n\t\treturn {};\n\t}\n\n\tprivate getArgs(options: LanguageModelV3CallOptions): {\n\t\targs: Record<string, unknown>;\n\t\twarnings: SharedV3Warning[];\n\t\tgrammarToolInputProperties: ReadonlyMap<string, string>;\n\t} {\n\t\tconst warnings: SharedV3Warning[] = [];\n\n\t\tif (options.topP != null) warnings.push({ type: \"unsupported\", feature: \"topP\" });\n\t\tif (options.topK != null) warnings.push({ type: \"unsupported\", feature: \"topK\" });\n\t\tif (options.presencePenalty != null) warnings.push({ type: \"unsupported\", feature: \"presencePenalty\" });\n\t\tif (options.frequencyPenalty != null) warnings.push({ type: \"unsupported\", feature: \"frequencyPenalty\" });\n\t\tif (options.seed != null) warnings.push({ type: \"unsupported\", feature: \"seed\" });\n\t\tif (options.stopSequences != null) warnings.push({ type: \"unsupported\", feature: \"stopSequences\" });\n\t\tif (options.maxOutputTokens != null) {\n\t\t\t// The ChatGPT Codex backend rejects max_output_tokens with a 400.\n\t\t\twarnings.push({ type: \"unsupported\", feature: \"maxOutputTokens\" });\n\t\t}\n\t\tif (options.responseFormat && options.responseFormat.type !== \"text\") {\n\t\t\twarnings.push({ type: \"unsupported\", feature: \"responseFormat\" });\n\t\t}\n\n\t\tconst codexOptions = (options.providerOptions?.[\"openai-codex\"] ?? {}) as OpenAICodexLanguageModelOptions;\n\t\tconst deferredToolsMode = resolveOpenAICodexDeferredToolsMode(this.modelId, this.config.compat);\n\t\tconst deferredToolNames = deferredToolsMode ? collectOpenAICodexDeferredToolNames(options.prompt) : undefined;\n\t\tconst tools = prepareOpenAICodexTools({\n\t\t\ttools: options.tools,\n\t\t\ttoolChoice: options.toolChoice,\n\t\t\t...(deferredToolNames !== undefined && { deferredToolNames }),\n\t\t});\n\t\tconst { instructions, input } = convertToOpenAICodexPrompt(options.prompt, {\n\t\t\tdeferredTools: tools.deferredCodexTools,\n\t\t\t...(deferredToolsMode !== undefined && { deferredToolsMode }),\n\t\t\tgrammarToolInputProperties: tools.grammarToolInputProperties,\n\t\t\tsupportsImages: this.config.compat?.supportsImages ?? this.modelId !== \"gpt-5.3-codex-spark\",\n\t\t});\n\t\twarnings.push(...tools.warnings);\n\n\t\tconst args: Record<string, unknown> = {\n\t\t\tmodel: this.modelId,\n\t\t\t// The ChatGPT backend rejects stored responses for Codex subscriptions.\n\t\t\tstore: false,\n\t\t\tinstructions,\n\t\t\tinput,\n\t\t\ttool_choice: tools.codexToolChoice ?? \"auto\",\n\t\t\tparallel_tool_calls: true,\n\t\t\tinclude: codexOptions.include ?? [\"reasoning.encrypted_content\"],\n\t\t\ttext: { verbosity: codexOptions.textVerbosity ?? \"low\" },\n\t\t};\n\n\t\tif (tools.codexTools) args.tools = tools.codexTools;\n\t\tif (options.temperature != null) args.temperature = options.temperature;\n\n\t\tconst promptCacheKey = clampOpenAICodexPromptCacheKey(codexOptions.promptCacheKey ?? this.config.sessionId);\n\t\tif (promptCacheKey) args.prompt_cache_key = promptCacheKey;\n\n\t\tconst serviceTier = codexOptions.serviceTier ?? this.config.serviceTier;\n\t\tif (serviceTier) args.service_tier = serviceTier;\n\n\t\tif (codexOptions.reasoningEffort) {\n\t\t\targs.reasoning = {\n\t\t\t\teffort: codexOptions.reasoningEffort,\n\t\t\t\tsummary: codexOptions.reasoningSummary ?? \"auto\",\n\t\t\t};\n\t\t}\n\n\t\treturn { args, warnings, grammarToolInputProperties: tools.grammarToolInputProperties };\n\t}\n\n\tasync doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult> {\n\t\tconst { stream, request, response } = await this.doStream(options);\n\n\t\tconst content: LanguageModelV3Content[] = [];\n\t\tconst textBlocks = new Map<string, Extract<LanguageModelV3Content, { type: \"text\" }>>();\n\t\tconst reasoningBlocks = new Map<string, Extract<LanguageModelV3Content, { type: \"reasoning\" }>>();\n\t\tconst warnings: SharedV3Warning[] = [];\n\t\tlet finishReason: LanguageModelV3FinishReason = { unified: \"other\", raw: undefined };\n\t\tlet usage: LanguageModelV3Usage = convertOpenAICodexUsage(undefined);\n\t\tlet responseId: string | undefined;\n\t\tlet responseModelId: string | undefined;\n\n\t\tconst reader = stream.getReader();\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\n\t\t\tswitch (value.type) {\n\t\t\t\tcase \"stream-start\":\n\t\t\t\t\twarnings.push(...value.warnings);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"response-metadata\":\n\t\t\t\t\tresponseId = value.id;\n\t\t\t\t\tresponseModelId = value.modelId;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"text-start\": {\n\t\t\t\t\tconst block = { type: \"text\" as const, text: \"\" };\n\t\t\t\t\ttextBlocks.set(value.id, block);\n\t\t\t\t\tcontent.push(block);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"text-delta\": {\n\t\t\t\t\tconst block = textBlocks.get(value.id);\n\t\t\t\t\tif (block) block.text += value.delta;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"text-end\": {\n\t\t\t\t\tconst block = textBlocks.get(value.id);\n\t\t\t\t\tif (block && value.providerMetadata !== undefined) block.providerMetadata = value.providerMetadata;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"reasoning-start\": {\n\t\t\t\t\tconst block = { type: \"reasoning\" as const, text: \"\" };\n\t\t\t\t\treasoningBlocks.set(value.id, block);\n\t\t\t\t\tcontent.push(block);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"reasoning-delta\": {\n\t\t\t\t\tconst block = reasoningBlocks.get(value.id);\n\t\t\t\t\tif (block) block.text += value.delta;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"reasoning-end\": {\n\t\t\t\t\tconst block = reasoningBlocks.get(value.id);\n\t\t\t\t\tif (block && value.providerMetadata !== undefined) block.providerMetadata = value.providerMetadata;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"tool-call\":\n\t\t\t\t\tcontent.push(value);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"finish\":\n\t\t\t\t\tfinishReason = value.finishReason;\n\t\t\t\t\tusage = value.usage;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"error\":\n\t\t\t\t\tthrow value.error instanceof Error ? value.error : new Error(String(value.error));\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: content.filter((part) =>\n\t\t\t\tpart.type === \"text\" || part.type === \"reasoning\"\n\t\t\t\t\t? part.text !== \"\" || part.providerMetadata !== undefined\n\t\t\t\t\t: true,\n\t\t\t),\n\t\t\tfinishReason,\n\t\t\tusage,\n\t\t\t...(request !== undefined && { request }),\n\t\t\tresponse: {\n\t\t\t\t...response,\n\t\t\t\t...(responseId !== undefined && { id: responseId }),\n\t\t\t\t...(responseModelId !== undefined && { modelId: responseModelId }),\n\t\t\t},\n\t\t\twarnings,\n\t\t};\n\t}\n\n\tasync doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult> {\n\t\tconst { args, warnings, grammarToolInputProperties } = this.getArgs(options);\n\t\tconst body = { ...args, stream: true };\n\t\tconst url = resolveOpenAICodexUrl(this.config.baseURL);\n\n\t\tconst headers = cleanHeaders({\n\t\t\t...(await this.config.headers()),\n\t\t\t...options.headers,\n\t\t});\n\t\tconst bodyJson = JSON.stringify(body);\n\t\tconst compressedBody = compressOpenAICodexRequest(bodyJson);\n\t\tif (compressedBody) headers[\"content-encoding\"] = \"zstd\";\n\n\t\tconst fetchImpl = this.config.fetch ?? globalThis.fetch;\n\t\tconst response = await fetchImpl(url, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders,\n\t\t\tbody: compressedBody ?? bodyJson,\n\t\t\t...(options.abortSignal !== undefined && { signal: options.abortSignal }),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow await createOpenAICodexAPICallError({ response, url, requestBodyValues: body });\n\t\t}\n\t\tif (!response.body) {\n\t\t\tthrow new Error(\"OpenAI Codex response has no body\");\n\t\t}\n\n\t\tconst responseHeaders: Record<string, string> = {};\n\t\tresponse.headers.forEach((value, key) => {\n\t\t\tresponseHeaders[key] = value;\n\t\t});\n\n\t\treturn {\n\t\t\tstream: parseOpenAICodexSSEStream(response.body).pipeThrough(\n\t\t\t\tthis.createTransformStream(warnings, options.includeRawChunks ?? false, grammarToolInputProperties),\n\t\t\t),\n\t\t\trequest: { body },\n\t\t\tresponse: { headers: responseHeaders },\n\t\t};\n\t}\n\n\tprivate createTransformStream(\n\t\twarnings: SharedV3Warning[],\n\t\tincludeRawChunks: boolean,\n\t\tgrammarToolInputProperties: ReadonlyMap<string, string>,\n\t): TransformStream<CodexEvent, LanguageModelV3StreamPart> {\n\t\tlet finishReason: LanguageModelV3FinishReason = { unified: \"other\", raw: undefined };\n\t\tlet usage: OpenAICodexUsage | undefined;\n\t\tlet hasToolCalls = false;\n\t\tlet finished = false;\n\t\t// function_call argument deltas arrive keyed by item id; tool parts use the\n\t\t// composite `call_id|item_id` so multi-turn replay can recover both halves.\n\t\tconst toolCallIdsByItemId = new Map<string, string>();\n\t\tconst customToolInputsByItemId = new Map<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\ttoolCallId: string;\n\t\t\t\ttoolName: string;\n\t\t\t\tinputProperty: string;\n\t\t\t\tbuffer: OpenAICodexGrammarInputBuffer;\n\t\t\t}\n\t\t>();\n\t\tconst finish = (controller: TransformStreamDefaultController<LanguageModelV3StreamPart>): void => {\n\t\t\tif (finished) return;\n\t\t\tfinished = true;\n\t\t\tcontroller.enqueue({\n\t\t\t\ttype: \"finish\",\n\t\t\t\tfinishReason,\n\t\t\t\tusage: convertOpenAICodexUsage(usage),\n\t\t\t});\n\t\t};\n\n\t\tconst handleOutputItemAdded = (\n\t\t\titem: CodexEvent,\n\t\t\tcontroller: TransformStreamDefaultController<LanguageModelV3StreamPart>,\n\t\t) => {\n\t\t\tconst itemType = asString(item.type);\n\t\t\tconst itemId = asString(item.id);\n\t\t\tif (!itemType || !itemId) return;\n\n\t\t\tif (itemType === \"message\") {\n\t\t\t\tcontroller.enqueue({ type: \"text-start\", id: itemId });\n\t\t\t} else if (itemType === \"reasoning\") {\n\t\t\t\tcontroller.enqueue({ type: \"reasoning-start\", id: itemId });\n\t\t\t} else if (itemType === \"function_call\") {\n\t\t\t\tconst toolCallId = joinToolCallId(asString(item.call_id) ?? itemId, itemId);\n\t\t\t\ttoolCallIdsByItemId.set(itemId, toolCallId);\n\t\t\t\thasToolCalls = true;\n\t\t\t\tcontroller.enqueue({\n\t\t\t\t\ttype: \"tool-input-start\",\n\t\t\t\t\tid: toolCallId,\n\t\t\t\t\ttoolName: asString(item.name) ?? \"\",\n\t\t\t\t});\n\t\t\t} else if (itemType === \"custom_tool_call\") {\n\t\t\t\tconst toolName = asString(item.name) ?? \"\";\n\t\t\t\tconst inputProperty = grammarToolInputProperties.get(toolName) ?? \"input\";\n\t\t\t\tconst toolCallId = joinToolCallId(asString(item.call_id) ?? itemId, itemId);\n\t\t\t\tcustomToolInputsByItemId.set(itemId, {\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolName,\n\t\t\t\t\tinputProperty,\n\t\t\t\t\tbuffer: { input: \"\", started: false, closed: false },\n\t\t\t\t});\n\t\t\t\thasToolCalls = true;\n\t\t\t\tcontroller.enqueue({ type: \"tool-input-start\", id: toolCallId, toolName });\n\t\t\t}\n\t\t};\n\n\t\tconst handleOutputItemDone = (\n\t\t\titem: CodexEvent,\n\t\t\tcontroller: TransformStreamDefaultController<LanguageModelV3StreamPart>,\n\t\t) => {\n\t\t\tconst itemType = asString(item.type);\n\t\t\tconst itemId = asString(item.id);\n\t\t\tif (!itemType || !itemId) return;\n\n\t\t\tif (itemType === \"message\") {\n\t\t\t\tcontroller.enqueue({\n\t\t\t\t\ttype: \"text-end\",\n\t\t\t\t\tid: itemId,\n\t\t\t\t\tproviderMetadata: { \"openai-codex\": { messageId: itemId } },\n\t\t\t\t});\n\t\t\t} else if (itemType === \"reasoning\") {\n\t\t\t\tcontroller.enqueue({\n\t\t\t\t\ttype: \"reasoning-end\",\n\t\t\t\t\tid: itemId,\n\t\t\t\t\tproviderMetadata: { \"openai-codex\": { reasoningItem: JSON.stringify(item) } },\n\t\t\t\t});\n\t\t\t} else if (itemType === \"function_call\") {\n\t\t\t\tconst toolCallId =\n\t\t\t\t\ttoolCallIdsByItemId.get(itemId) ?? joinToolCallId(asString(item.call_id) ?? itemId, itemId);\n\t\t\t\thasToolCalls = true;\n\t\t\t\tcontroller.enqueue({ type: \"tool-input-end\", id: toolCallId });\n\t\t\t\tcontroller.enqueue({\n\t\t\t\t\ttype: \"tool-call\",\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolName: asString(item.name) ?? \"\",\n\t\t\t\t\tinput: asString(item.arguments) ?? \"\",\n\t\t\t\t\t...(asString(item.namespace)\n\t\t\t\t\t\t? { providerMetadata: { \"openai-codex\": { namespace: asString(item.namespace)! } } }\n\t\t\t\t\t\t: {}),\n\t\t\t\t});\n\t\t\t} else if (itemType === \"custom_tool_call\") {\n\t\t\t\tconst state = customToolInputsByItemId.get(itemId);\n\t\t\t\tif (!state) return;\n\t\t\t\tconst input = asString(item.input) ?? state.buffer.input;\n\t\t\t\tconst delta = appendOpenAICodexGrammarInputJsonDelta(state.buffer, state.inputProperty, input, true);\n\t\t\t\tif (delta) controller.enqueue({ type: \"tool-input-delta\", id: state.toolCallId, delta });\n\t\t\t\thasToolCalls = true;\n\t\t\t\tcontroller.enqueue({ type: \"tool-input-end\", id: state.toolCallId });\n\t\t\t\tcontroller.enqueue({\n\t\t\t\t\ttype: \"tool-call\",\n\t\t\t\t\ttoolCallId: state.toolCallId,\n\t\t\t\t\ttoolName: state.toolName,\n\t\t\t\t\tinput: JSON.stringify({ [state.inputProperty]: input }),\n\t\t\t\t\t...(asString(item.namespace)\n\t\t\t\t\t\t? { providerMetadata: { \"openai-codex\": { namespace: asString(item.namespace)! } } }\n\t\t\t\t\t\t: {}),\n\t\t\t\t});\n\t\t\t\tcustomToolInputsByItemId.delete(itemId);\n\t\t\t}\n\t\t};\n\n\t\treturn new TransformStream<CodexEvent, LanguageModelV3StreamPart>({\n\t\t\tstart(controller) {\n\t\t\t\tcontroller.enqueue({ type: \"stream-start\", warnings });\n\t\t\t},\n\n\t\t\ttransform(event, controller) {\n\t\t\t\tif (includeRawChunks) {\n\t\t\t\t\tcontroller.enqueue({ type: \"raw\", rawValue: event });\n\t\t\t\t}\n\n\t\t\t\tconst type = asString(event.type);\n\t\t\t\tif (!type) return;\n\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase \"response.created\": {\n\t\t\t\t\t\tconst response = asRecord(event.response);\n\t\t\t\t\t\tconst id = asString(response?.id);\n\t\t\t\t\t\tconst modelId = asString(response?.model);\n\t\t\t\t\t\tcontroller.enqueue({\n\t\t\t\t\t\t\ttype: \"response-metadata\",\n\t\t\t\t\t\t\t...(id !== undefined && { id }),\n\t\t\t\t\t\t\t...(modelId !== undefined && { modelId }),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.output_item.added\": {\n\t\t\t\t\t\tconst item = asRecord(event.item);\n\t\t\t\t\t\tif (item) handleOutputItemAdded(item, controller);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.output_text.delta\": {\n\t\t\t\t\t\tconst itemId = asString(event.item_id);\n\t\t\t\t\t\tconst delta = asString(event.delta);\n\t\t\t\t\t\tif (itemId && delta) controller.enqueue({ type: \"text-delta\", id: itemId, delta });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.reasoning_text.delta\":\n\t\t\t\t\tcase \"response.reasoning_summary_text.delta\": {\n\t\t\t\t\t\tconst itemId = asString(event.item_id);\n\t\t\t\t\t\tconst delta = asString(event.delta);\n\t\t\t\t\t\tif (itemId && delta) controller.enqueue({ type: \"reasoning-delta\", id: itemId, delta });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.function_call_arguments.delta\": {\n\t\t\t\t\t\tconst itemId = asString(event.item_id);\n\t\t\t\t\t\tconst delta = asString(event.delta);\n\t\t\t\t\t\tconst toolCallId = itemId ? toolCallIdsByItemId.get(itemId) : undefined;\n\t\t\t\t\t\tif (toolCallId && delta) controller.enqueue({ type: \"tool-input-delta\", id: toolCallId, delta });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.custom_tool_call_input.delta\": {\n\t\t\t\t\t\tconst itemId = asString(event.item_id);\n\t\t\t\t\t\tconst delta = asString(event.delta);\n\t\t\t\t\t\tconst state = itemId ? customToolInputsByItemId.get(itemId) : undefined;\n\t\t\t\t\t\tif (!state || delta === undefined) break;\n\t\t\t\t\t\tconst jsonDelta = appendOpenAICodexGrammarInputJsonDelta(\n\t\t\t\t\t\t\tstate.buffer,\n\t\t\t\t\t\t\tstate.inputProperty,\n\t\t\t\t\t\t\tstate.buffer.input + delta,\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (jsonDelta)\n\t\t\t\t\t\t\tcontroller.enqueue({ type: \"tool-input-delta\", id: state.toolCallId, delta: jsonDelta });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.custom_tool_call_input.done\": {\n\t\t\t\t\t\tconst itemId = asString(event.item_id);\n\t\t\t\t\t\tconst input = asString(event.input);\n\t\t\t\t\t\tconst state = itemId ? customToolInputsByItemId.get(itemId) : undefined;\n\t\t\t\t\t\tif (!state || input === undefined) break;\n\t\t\t\t\t\tconst jsonDelta = appendOpenAICodexGrammarInputJsonDelta(\n\t\t\t\t\t\t\tstate.buffer,\n\t\t\t\t\t\t\tstate.inputProperty,\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (jsonDelta)\n\t\t\t\t\t\t\tcontroller.enqueue({ type: \"tool-input-delta\", id: state.toolCallId, delta: jsonDelta });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.output_item.done\": {\n\t\t\t\t\t\tconst item = asRecord(event.item);\n\t\t\t\t\t\tif (item) handleOutputItemDone(item, controller);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.completed\":\n\t\t\t\t\tcase \"response.done\":\n\t\t\t\t\tcase \"response.incomplete\": {\n\t\t\t\t\t\tconst response = asRecord(event.response);\n\t\t\t\t\t\tusage = (response?.usage as OpenAICodexUsage | undefined) ?? usage;\n\t\t\t\t\t\tconst status =\n\t\t\t\t\t\t\tasString(response?.status) ?? (type === \"response.incomplete\" ? \"incomplete\" : \"completed\");\n\t\t\t\t\t\tconst incompleteReason = asString(asRecord(response?.incomplete_details)?.reason);\n\t\t\t\t\t\tfinishReason = mapOpenAICodexFinishReason(status, hasToolCalls, incompleteReason);\n\t\t\t\t\t\tfinish(controller);\n\t\t\t\t\t\tcontroller.terminate();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"response.failed\": {\n\t\t\t\t\t\tconst response = asRecord(event.response);\n\t\t\t\t\t\tconst error = asRecord(response?.error);\n\t\t\t\t\t\tfinishReason = { unified: \"error\", raw: \"failed\" };\n\t\t\t\t\t\tcontroller.enqueue({\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\terror: new Error(asString(error?.message) ?? \"OpenAI Codex response failed\"),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"error\": {\n\t\t\t\t\t\tconst code = asString(event.code);\n\t\t\t\t\t\tconst message = asString(event.message);\n\t\t\t\t\t\tfinishReason = { unified: \"error\", raw: code ?? \"error\" };\n\t\t\t\t\t\tcontroller.enqueue({\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\terror: new Error(\n\t\t\t\t\t\t\t\t`OpenAI Codex error${code ? ` ${code}` : \"\"}: ${message ?? JSON.stringify(event)}`,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// Ignore lifecycle events we do not surface (content_part, in_progress, ...).\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tflush(controller) {\n\t\t\t\tfinish(controller);\n\t\t\t},\n\t\t});\n\t}\n}\n","import { LoadAPIKeyError, NoSuchModelError, type LanguageModelV3, type ProviderV3 } from \"@ai-sdk/provider\";\nimport { getOpenAICodexAccountId } from \"../../oauth/openai/codex.ts\";\nimport {\n\tOPENAI_CODEX_DEFAULT_BASE_URL,\n\tOpenAICodexLanguageModel,\n\tclampOpenAICodexPromptCacheKey,\n\ttype OpenAICodexModelId,\n\ttype OpenAICodexCompatibility,\n\ttype OpenAICodexServiceTier,\n} from \"./codex-language-model.ts\";\n\nexport const OPENAI_CODEX_API_KEY_ENV = \"OPENAI_CODEX_API_KEY\";\n\nconst DEFAULT_ORIGINATOR = \"codework\";\n\nexport interface OpenAICodexProvider extends ProviderV3 {\n\t(modelId: OpenAICodexModelId): LanguageModelV3;\n\n\tlanguageModel(modelId: OpenAICodexModelId): LanguageModelV3;\n\n\t/** Alias for `languageModel`; the Codex API only speaks the Responses protocol. */\n\tresponses(modelId: OpenAICodexModelId): LanguageModelV3;\n}\n\nexport interface OpenAICodexProviderSettings {\n\t/**\n\t * Base URL for the Codex backend.\n\t * Defaults to `https://chatgpt.com/backend-api`.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * ChatGPT OAuth access token (JWT) used as the API key.\n\t * Defaults to the `OPENAI_CODEX_API_KEY` environment variable.\n\t * A function can be passed to resolve a fresh token per request.\n\t */\n\tapiKey?: string | (() => string | PromiseLike<string>);\n\n\t/**\n\t * ChatGPT account id sent as the `chatgpt-account-id` header.\n\t * Extracted from the JWT access token when omitted.\n\t */\n\taccountId?: string;\n\n\t/** Custom headers merged into every request. */\n\theaders?: Record<string, string>;\n\n\t/** Custom fetch implementation. */\n\tfetch?: typeof globalThis.fetch;\n\n\t/** Session id used for the `session-id` header and the default prompt cache key. */\n\tsessionId?: string;\n\n\t/** Default service tier for requests. */\n\tserviceTier?: OpenAICodexServiceTier;\n\n\t/** `originator` header value; defaults to `codework`. */\n\toriginator?: string;\n\n\t/** Optional model capability overrides. Known Codex models use built-in defaults. */\n\tcompat?: OpenAICodexCompatibility;\n}\n\nasync function resolveApiKey(settings: OpenAICodexProviderSettings): Promise<string> {\n\tconst apiKey =\n\t\ttypeof settings.apiKey === \"function\"\n\t\t\t? await settings.apiKey()\n\t\t\t: (settings.apiKey ?? (typeof process === \"undefined\" ? undefined : process.env[OPENAI_CODEX_API_KEY_ENV]));\n\n\tif (!apiKey) {\n\t\tthrow new LoadAPIKeyError({\n\t\t\tmessage: `OpenAI Codex API key is missing. Pass it using the 'apiKey' option or the ${OPENAI_CODEX_API_KEY_ENV} environment variable.`,\n\t\t});\n\t}\n\n\treturn apiKey;\n}\n\nfunction resolveAccountId(settings: OpenAICodexProviderSettings, apiKey: string): string {\n\tconst accountId = settings.accountId ?? getOpenAICodexAccountId(apiKey);\n\tif (!accountId) {\n\t\tthrow new LoadAPIKeyError({\n\t\t\tmessage:\n\t\t\t\t\"Failed to extract the ChatGPT account id from the OpenAI Codex access token. \" +\n\t\t\t\t\"Provide it using the 'accountId' option or pass a valid ChatGPT OAuth JWT as the API key.\",\n\t\t});\n\t}\n\treturn accountId;\n}\n\nexport function createOpenAICodex(options: OpenAICodexProviderSettings = {}): OpenAICodexProvider {\n\tconst baseURL = options.baseURL?.replace(/\\/+$/, \"\") || OPENAI_CODEX_DEFAULT_BASE_URL;\n\tconst sessionId = clampOpenAICodexPromptCacheKey(options.sessionId);\n\n\tconst getHeaders = async (): Promise<Record<string, string | undefined>> => {\n\t\tconst apiKey = await resolveApiKey(options);\n\t\tconst accountId = resolveAccountId(options, apiKey);\n\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\"chatgpt-account-id\": accountId,\n\t\t\t\"OpenAI-Beta\": \"responses=experimental\",\n\t\t\toriginator: options.originator ?? DEFAULT_ORIGINATOR,\n\t\t\taccept: \"text/event-stream\",\n\t\t\t\"content-type\": \"application/json\",\n\t\t\t...(sessionId ? { \"session-id\": sessionId, \"x-client-request-id\": sessionId } : {}),\n\t\t\t...options.headers,\n\t\t};\n\t};\n\n\tconst createLanguageModel = (modelId: OpenAICodexModelId) =>\n\t\tnew OpenAICodexLanguageModel(modelId, {\n\t\t\tprovider: \"openai-codex\",\n\t\t\tbaseURL,\n\t\t\theaders: getHeaders,\n\t\t\t...(options.fetch !== undefined && { fetch: options.fetch }),\n\t\t\t...(sessionId !== undefined && { sessionId }),\n\t\t\t...(options.serviceTier !== undefined && { serviceTier: options.serviceTier }),\n\t\t\t...(options.compat !== undefined && { compat: options.compat }),\n\t\t});\n\n\tconst provider = function (modelId: OpenAICodexModelId) {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\"The OpenAI Codex model function cannot be called with the new keyword.\");\n\t\t}\n\t\treturn createLanguageModel(modelId);\n\t};\n\n\tprovider.specificationVersion = \"v3\" as const;\n\tprovider.languageModel = createLanguageModel;\n\tprovider.responses = createLanguageModel;\n\n\tprovider.embeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n\t};\n\tprovider.textEmbeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n\t};\n\tprovider.imageModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"imageModel\" });\n\t};\n\n\treturn provider as OpenAICodexProvider;\n}\n\n/**\n * Default provider instance using `OPENAI_CODEX_API_KEY`.\n */\nexport const openaiCodex = createOpenAICodex();\n"],"mappings":";;;AAuCA,SAAgB,uCACf,QACA,eACA,WACA,OACqB;CACrB,IAAI,OAAO,QAAQ;EAClB,IAAI,SAAS,cAAc,OAAO,OAAO,OAAO,KAAA;EAChD,MAAM,IAAI,MAAM,oCAAoC,cAAc,8BAA8B;CACjG;CACA,I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;EAAa,CAAC;CAChE;CAEA,OAAO;AACR;;;;AAKA,MAAa,cAAc,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeworksh/aikit",
3
- "version": "0.6.0",
3
+ "version": "0.7.1-dev.20260824182047",
4
4
  "description": "TypeScript SDK that provides a unified API for working with multiple LLM providers, automatic model discovery, and more.",
5
5
  "keywords": [
6
6
  "agent",
@@ -39,6 +39,11 @@
39
39
  "import": "./oauth/openai/codex.mjs",
40
40
  "default": "./oauth/openai/codex.mjs"
41
41
  },
42
+ "./modelgen": {
43
+ "types": "./modelgen.d.mts",
44
+ "import": "./modelgen.mjs",
45
+ "default": "./modelgen.mjs"
46
+ },
42
47
  "./package.json": "./package.json"
43
48
  },
44
49
  "files": [
@@ -53,20 +58,20 @@
53
58
  "node": ">=22.0.0"
54
59
  },
55
60
  "dependencies": {
56
- "@ai-sdk/anthropic": "^3.0.79",
57
- "@ai-sdk/google": "^3.0.79",
58
- "@ai-sdk/google-vertex": "^4.0.137",
59
- "@ai-sdk/openai": "^3.0.65",
60
- "@ai-sdk/openai-compatible": "^2.0.48",
61
- "@ai-sdk/provider": "^3.0.10",
62
- "@ai-sdk/xai": "^3.0.92",
63
- "@openrouter/ai-sdk-provider": "^2.9.0",
64
- "ai": "^6.0.191",
61
+ "@ai-sdk/anthropic": "^4.0.36",
62
+ "@ai-sdk/google": "^4.0.39",
63
+ "@ai-sdk/google-vertex": "^5.0.48",
64
+ "@ai-sdk/openai": "^4.0.36",
65
+ "@ai-sdk/openai-compatible": "^3.0.28",
66
+ "@ai-sdk/provider": "^4.0.7",
67
+ "@ai-sdk/xai": "^4.0.33",
68
+ "@openrouter/ai-sdk-provider": "^3.0.0",
69
+ "ai": "^7.0.58",
65
70
  "dedent": "^1.7.2",
66
71
  "partial-json": "^0.1.7",
67
- "remeda": "^2.33.6",
68
- "typebox": "^1.1.37",
72
+ "remeda": "^2.39.0",
73
+ "typebox": "^1.3.12",
69
74
  "uuidv7": "^1.2.1",
70
- "yargs": "^18.0.0"
75
+ "yargs": "^18.1.0"
71
76
  }
72
77
  }