@mariozechner/pi-ai 0.46.0 → 0.48.0

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.
Files changed (61) hide show
  1. package/dist/constants.d.ts +6 -0
  2. package/dist/constants.d.ts.map +1 -0
  3. package/dist/constants.js +14 -0
  4. package/dist/constants.js.map +1 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/models.generated.d.ts +20 -111
  10. package/dist/models.generated.d.ts.map +1 -1
  11. package/dist/models.generated.js +50 -136
  12. package/dist/models.generated.js.map +1 -1
  13. package/dist/providers/amazon-bedrock.d.ts.map +1 -1
  14. package/dist/providers/amazon-bedrock.js +7 -3
  15. package/dist/providers/amazon-bedrock.js.map +1 -1
  16. package/dist/providers/google-shared.d.ts.map +1 -1
  17. package/dist/providers/google-shared.js +2 -1
  18. package/dist/providers/google-shared.js.map +1 -1
  19. package/dist/providers/openai-codex-responses.d.ts +0 -2
  20. package/dist/providers/openai-codex-responses.d.ts.map +1 -1
  21. package/dist/providers/openai-codex-responses.js +476 -489
  22. package/dist/providers/openai-codex-responses.js.map +1 -1
  23. package/dist/providers/openai-completions.d.ts.map +1 -1
  24. package/dist/providers/openai-completions.js +18 -10
  25. package/dist/providers/openai-completions.js.map +1 -1
  26. package/dist/providers/transform-messages.d.ts.map +1 -1
  27. package/dist/providers/transform-messages.js +7 -0
  28. package/dist/providers/transform-messages.js.map +1 -1
  29. package/dist/utils/validation.d.ts +1 -1
  30. package/dist/utils/validation.d.ts.map +1 -1
  31. package/dist/utils/validation.js +7 -4
  32. package/dist/utils/validation.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/providers/openai-codex/constants.d.ts +0 -21
  35. package/dist/providers/openai-codex/constants.d.ts.map +0 -1
  36. package/dist/providers/openai-codex/constants.js +0 -21
  37. package/dist/providers/openai-codex/constants.js.map +0 -1
  38. package/dist/providers/openai-codex/index.d.ts +0 -7
  39. package/dist/providers/openai-codex/index.d.ts.map +0 -1
  40. package/dist/providers/openai-codex/index.js +0 -7
  41. package/dist/providers/openai-codex/index.js.map +0 -1
  42. package/dist/providers/openai-codex/prompts/codex.d.ts +0 -3
  43. package/dist/providers/openai-codex/prompts/codex.d.ts.map +0 -1
  44. package/dist/providers/openai-codex/prompts/codex.js +0 -323
  45. package/dist/providers/openai-codex/prompts/codex.js.map +0 -1
  46. package/dist/providers/openai-codex/prompts/pi-codex-bridge.d.ts +0 -7
  47. package/dist/providers/openai-codex/prompts/pi-codex-bridge.d.ts.map +0 -1
  48. package/dist/providers/openai-codex/prompts/pi-codex-bridge.js +0 -50
  49. package/dist/providers/openai-codex/prompts/pi-codex-bridge.js.map +0 -1
  50. package/dist/providers/openai-codex/prompts/system-prompt.d.ts +0 -10
  51. package/dist/providers/openai-codex/prompts/system-prompt.d.ts.map +0 -1
  52. package/dist/providers/openai-codex/prompts/system-prompt.js +0 -15
  53. package/dist/providers/openai-codex/prompts/system-prompt.js.map +0 -1
  54. package/dist/providers/openai-codex/request-transformer.d.ts +0 -44
  55. package/dist/providers/openai-codex/request-transformer.d.ts.map +0 -1
  56. package/dist/providers/openai-codex/request-transformer.js +0 -99
  57. package/dist/providers/openai-codex/request-transformer.js.map +0 -1
  58. package/dist/providers/openai-codex/response-handler.d.ts +0 -19
  59. package/dist/providers/openai-codex/response-handler.d.ts.map +0 -1
  60. package/dist/providers/openai-codex/response-handler.js +0 -107
  61. package/dist/providers/openai-codex/response-handler.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../../../src/providers/openai-codex/prompts/system-prompt.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,sBAAsB,CAAC,IAItC,EAAqB;IACrB,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACjE,MAAM,iBAAiB,GAAa,EAAE,CAAC;IAEvC,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,OAAO;QACN,YAAY,EAAE,iBAAiB,CAAC,IAAI,EAAE;QACtC,iBAAiB;KACjB,CAAC;AAAA,CACF","sourcesContent":["export interface CodexSystemPrompt {\n\tinstructions: string;\n\tdeveloperMessages: string[];\n}\n\nexport function buildCodexSystemPrompt(args: {\n\tcodexInstructions: string;\n\tbridgeText: string;\n\tuserSystemPrompt?: string;\n}): CodexSystemPrompt {\n\tconst { codexInstructions, bridgeText, userSystemPrompt } = args;\n\tconst developerMessages: string[] = [];\n\n\tif (bridgeText.trim().length > 0) {\n\t\tdeveloperMessages.push(bridgeText.trim());\n\t}\n\n\tif (userSystemPrompt && userSystemPrompt.trim().length > 0) {\n\t\tdeveloperMessages.push(userSystemPrompt.trim());\n\t}\n\n\treturn {\n\t\tinstructions: codexInstructions.trim(),\n\t\tdeveloperMessages,\n\t};\n}\n"]}
@@ -1,44 +0,0 @@
1
- export interface ReasoningConfig {
2
- effort: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
3
- summary: "auto" | "concise" | "detailed" | "off" | "on";
4
- }
5
- export interface CodexRequestOptions {
6
- reasoningEffort?: ReasoningConfig["effort"];
7
- reasoningSummary?: ReasoningConfig["summary"] | null;
8
- textVerbosity?: "low" | "medium" | "high";
9
- include?: string[];
10
- }
11
- export interface InputItem {
12
- id?: string | null;
13
- type?: string | null;
14
- role?: string;
15
- content?: unknown;
16
- call_id?: string | null;
17
- name?: string;
18
- output?: unknown;
19
- arguments?: string;
20
- }
21
- export interface RequestBody {
22
- model: string;
23
- store?: boolean;
24
- stream?: boolean;
25
- instructions?: string;
26
- input?: InputItem[];
27
- tools?: unknown;
28
- temperature?: number;
29
- reasoning?: Partial<ReasoningConfig>;
30
- text?: {
31
- verbosity?: "low" | "medium" | "high";
32
- };
33
- include?: string[];
34
- prompt_cache_key?: string;
35
- prompt_cache_retention?: "in_memory" | "24h";
36
- max_output_tokens?: number;
37
- max_completion_tokens?: number;
38
- [key: string]: unknown;
39
- }
40
- export declare function transformRequestBody(body: RequestBody, options?: CodexRequestOptions, prompt?: {
41
- instructions: string;
42
- developerMessages: string[];
43
- }): Promise<RequestBody>;
44
- //# sourceMappingURL=request-transformer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-transformer.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-codex/request-transformer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IACjE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,KAAK,GAAG,IAAI,CAAC;CACxD;AAED,MAAM,WAAW,mBAAmB;IACnC,eAAe,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,gBAAgB,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IACrD,aAAa,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC1C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACzB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;KACtC,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAwCD,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,mBAAwB,EACjC,MAAM,CAAC,EAAE;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAAE,GAC5D,OAAO,CAAC,WAAW,CAAC,CA6EtB","sourcesContent":["export interface ReasoningConfig {\n\teffort: \"none\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\tsummary: \"auto\" | \"concise\" | \"detailed\" | \"off\" | \"on\";\n}\n\nexport interface CodexRequestOptions {\n\treasoningEffort?: ReasoningConfig[\"effort\"];\n\treasoningSummary?: ReasoningConfig[\"summary\"] | null;\n\ttextVerbosity?: \"low\" | \"medium\" | \"high\";\n\tinclude?: string[];\n}\n\nexport interface InputItem {\n\tid?: string | null;\n\ttype?: string | null;\n\trole?: string;\n\tcontent?: unknown;\n\tcall_id?: string | null;\n\tname?: string;\n\toutput?: unknown;\n\targuments?: string;\n}\n\nexport interface RequestBody {\n\tmodel: string;\n\tstore?: boolean;\n\tstream?: boolean;\n\tinstructions?: string;\n\tinput?: InputItem[];\n\ttools?: unknown;\n\ttemperature?: number;\n\treasoning?: Partial<ReasoningConfig>;\n\ttext?: {\n\t\tverbosity?: \"low\" | \"medium\" | \"high\";\n\t};\n\tinclude?: string[];\n\tprompt_cache_key?: string;\n\tprompt_cache_retention?: \"in_memory\" | \"24h\";\n\tmax_output_tokens?: number;\n\tmax_completion_tokens?: number;\n\t[key: string]: unknown;\n}\n\nfunction clampReasoningEffort(model: string, effort: ReasoningConfig[\"effort\"]): ReasoningConfig[\"effort\"] {\n\t// Codex backend expects exact model IDs. Do not normalize model names here.\n\tconst modelId = model.includes(\"/\") ? model.split(\"/\").pop()! : model;\n\n\t// gpt-5.1 does not support xhigh.\n\tif (modelId === \"gpt-5.1\" && effort === \"xhigh\") {\n\t\treturn \"high\";\n\t}\n\n\t// gpt-5.1-codex-mini only supports medium/high.\n\tif (modelId === \"gpt-5.1-codex-mini\") {\n\t\treturn effort === \"high\" || effort === \"xhigh\" ? \"high\" : \"medium\";\n\t}\n\n\treturn effort;\n}\n\nfunction getReasoningConfig(model: string, options: CodexRequestOptions): ReasoningConfig {\n\treturn {\n\t\teffort: clampReasoningEffort(model, options.reasoningEffort as ReasoningConfig[\"effort\"]),\n\t\tsummary: options.reasoningSummary ?? \"auto\",\n\t};\n}\n\nfunction filterInput(input: InputItem[] | undefined): InputItem[] | undefined {\n\tif (!Array.isArray(input)) return input;\n\n\treturn input\n\t\t.filter((item) => item.type !== \"item_reference\")\n\t\t.map((item) => {\n\t\t\tif (item.id != null) {\n\t\t\t\tconst { id: _id, ...rest } = item;\n\t\t\t\treturn rest as InputItem;\n\t\t\t}\n\t\t\treturn item;\n\t\t});\n}\n\nexport async function transformRequestBody(\n\tbody: RequestBody,\n\toptions: CodexRequestOptions = {},\n\tprompt?: { instructions: string; developerMessages: string[] },\n): Promise<RequestBody> {\n\tbody.store = false;\n\tbody.stream = true;\n\n\tif (body.input && Array.isArray(body.input)) {\n\t\tbody.input = filterInput(body.input);\n\n\t\tif (body.input) {\n\t\t\tconst functionCallIds = new Set(\n\t\t\t\tbody.input\n\t\t\t\t\t.filter((item) => item.type === \"function_call\" && typeof item.call_id === \"string\")\n\t\t\t\t\t.map((item) => item.call_id as string),\n\t\t\t);\n\n\t\t\tbody.input = body.input.map((item) => {\n\t\t\t\tif (item.type === \"function_call_output\" && typeof item.call_id === \"string\") {\n\t\t\t\t\tconst callId = item.call_id as string;\n\t\t\t\t\tif (!functionCallIds.has(callId)) {\n\t\t\t\t\t\tconst itemRecord = item as unknown as Record<string, unknown>;\n\t\t\t\t\t\tconst toolName = typeof itemRecord.name === \"string\" ? itemRecord.name : \"tool\";\n\t\t\t\t\t\tlet text = \"\";\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst output = itemRecord.output;\n\t\t\t\t\t\t\ttext = typeof output === \"string\" ? output : JSON.stringify(output);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\ttext = String(itemRecord.output ?? \"\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (text.length > 16000) {\n\t\t\t\t\t\t\ttext = `${text.slice(0, 16000)}\\n...[truncated]`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn {\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\tcontent: `[Previous ${toolName} result; call_id=${callId}]: ${text}`,\n\t\t\t\t\t\t} as InputItem;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn item;\n\t\t\t});\n\t\t}\n\t}\n\n\tif (prompt?.developerMessages && prompt.developerMessages.length > 0 && Array.isArray(body.input)) {\n\t\tconst developerMessages = prompt.developerMessages.map(\n\t\t\t(text) =>\n\t\t\t\t({\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\trole: \"developer\",\n\t\t\t\t\tcontent: [{ type: \"input_text\", text }],\n\t\t\t\t}) as InputItem,\n\t\t);\n\t\tbody.input = [...developerMessages, ...body.input];\n\t}\n\n\tif (options.reasoningEffort !== undefined) {\n\t\tconst reasoningConfig = getReasoningConfig(body.model, options);\n\t\tbody.reasoning = {\n\t\t\t...body.reasoning,\n\t\t\t...reasoningConfig,\n\t\t};\n\t} else {\n\t\tdelete body.reasoning;\n\t}\n\n\tbody.text = {\n\t\t...body.text,\n\t\tverbosity: options.textVerbosity || \"medium\",\n\t};\n\n\tconst include = Array.isArray(options.include) ? [...options.include] : [];\n\tinclude.push(\"reasoning.encrypted_content\");\n\tbody.include = Array.from(new Set(include));\n\n\tdelete body.max_output_tokens;\n\tdelete body.max_completion_tokens;\n\n\treturn body;\n}\n"]}
@@ -1,99 +0,0 @@
1
- function clampReasoningEffort(model, effort) {
2
- // Codex backend expects exact model IDs. Do not normalize model names here.
3
- const modelId = model.includes("/") ? model.split("/").pop() : model;
4
- // gpt-5.1 does not support xhigh.
5
- if (modelId === "gpt-5.1" && effort === "xhigh") {
6
- return "high";
7
- }
8
- // gpt-5.1-codex-mini only supports medium/high.
9
- if (modelId === "gpt-5.1-codex-mini") {
10
- return effort === "high" || effort === "xhigh" ? "high" : "medium";
11
- }
12
- return effort;
13
- }
14
- function getReasoningConfig(model, options) {
15
- return {
16
- effort: clampReasoningEffort(model, options.reasoningEffort),
17
- summary: options.reasoningSummary ?? "auto",
18
- };
19
- }
20
- function filterInput(input) {
21
- if (!Array.isArray(input))
22
- return input;
23
- return input
24
- .filter((item) => item.type !== "item_reference")
25
- .map((item) => {
26
- if (item.id != null) {
27
- const { id: _id, ...rest } = item;
28
- return rest;
29
- }
30
- return item;
31
- });
32
- }
33
- export async function transformRequestBody(body, options = {}, prompt) {
34
- body.store = false;
35
- body.stream = true;
36
- if (body.input && Array.isArray(body.input)) {
37
- body.input = filterInput(body.input);
38
- if (body.input) {
39
- const functionCallIds = new Set(body.input
40
- .filter((item) => item.type === "function_call" && typeof item.call_id === "string")
41
- .map((item) => item.call_id));
42
- body.input = body.input.map((item) => {
43
- if (item.type === "function_call_output" && typeof item.call_id === "string") {
44
- const callId = item.call_id;
45
- if (!functionCallIds.has(callId)) {
46
- const itemRecord = item;
47
- const toolName = typeof itemRecord.name === "string" ? itemRecord.name : "tool";
48
- let text = "";
49
- try {
50
- const output = itemRecord.output;
51
- text = typeof output === "string" ? output : JSON.stringify(output);
52
- }
53
- catch {
54
- text = String(itemRecord.output ?? "");
55
- }
56
- if (text.length > 16000) {
57
- text = `${text.slice(0, 16000)}\n...[truncated]`;
58
- }
59
- return {
60
- type: "message",
61
- role: "assistant",
62
- content: `[Previous ${toolName} result; call_id=${callId}]: ${text}`,
63
- };
64
- }
65
- }
66
- return item;
67
- });
68
- }
69
- }
70
- if (prompt?.developerMessages && prompt.developerMessages.length > 0 && Array.isArray(body.input)) {
71
- const developerMessages = prompt.developerMessages.map((text) => ({
72
- type: "message",
73
- role: "developer",
74
- content: [{ type: "input_text", text }],
75
- }));
76
- body.input = [...developerMessages, ...body.input];
77
- }
78
- if (options.reasoningEffort !== undefined) {
79
- const reasoningConfig = getReasoningConfig(body.model, options);
80
- body.reasoning = {
81
- ...body.reasoning,
82
- ...reasoningConfig,
83
- };
84
- }
85
- else {
86
- delete body.reasoning;
87
- }
88
- body.text = {
89
- ...body.text,
90
- verbosity: options.textVerbosity || "medium",
91
- };
92
- const include = Array.isArray(options.include) ? [...options.include] : [];
93
- include.push("reasoning.encrypted_content");
94
- body.include = Array.from(new Set(include));
95
- delete body.max_output_tokens;
96
- delete body.max_completion_tokens;
97
- return body;
98
- }
99
- //# sourceMappingURL=request-transformer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-transformer.js","sourceRoot":"","sources":["../../../src/providers/openai-codex/request-transformer.ts"],"names":[],"mappings":"AA2CA,SAAS,oBAAoB,CAAC,KAAa,EAAE,MAAiC,EAA6B;IAC1G,4EAA4E;IAC5E,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAG,CAAC,CAAC,CAAC,KAAK,CAAC;IAEtE,kCAAkC;IAClC,IAAI,OAAO,KAAK,SAAS,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACjD,OAAO,MAAM,CAAC;IACf,CAAC;IAED,gDAAgD;IAChD,IAAI,OAAO,KAAK,oBAAoB,EAAE,CAAC;QACtC,OAAO,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACpE,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,OAA4B,EAAmB;IACzF,OAAO;QACN,MAAM,EAAE,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,eAA4C,CAAC;QACzF,OAAO,EAAE,OAAO,CAAC,gBAAgB,IAAI,MAAM;KAC3C,CAAC;AAAA,CACF;AAED,SAAS,WAAW,CAAC,KAA8B,EAA2B;IAC7E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,OAAO,KAAK;SACV,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,CAAC;SAChD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACd,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,IA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,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,OAAO,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;QAC3C,MAAM,eAAe,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAChE,IAAI,CAAC,SAAS,GAAG;YAChB,GAAG,IAAI,CAAC,SAAS;YACjB,GAAG,eAAe;SAClB,CAAC;IACH,CAAC;SAAM,CAAC;QACP,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,IAAI,CAAC,IAAI,GAAG;QACX,GAAG,IAAI,CAAC,IAAI;QACZ,SAAS,EAAE,OAAO,CAAC,aAAa,IAAI,QAAQ;KAC5C,CAAC;IAEF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAC5C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5C,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC;IAElC,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["export interface ReasoningConfig {\n\teffort: \"none\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\tsummary: \"auto\" | \"concise\" | \"detailed\" | \"off\" | \"on\";\n}\n\nexport interface CodexRequestOptions {\n\treasoningEffort?: ReasoningConfig[\"effort\"];\n\treasoningSummary?: ReasoningConfig[\"summary\"] | null;\n\ttextVerbosity?: \"low\" | \"medium\" | \"high\";\n\tinclude?: string[];\n}\n\nexport interface InputItem {\n\tid?: string | null;\n\ttype?: string | null;\n\trole?: string;\n\tcontent?: unknown;\n\tcall_id?: string | null;\n\tname?: string;\n\toutput?: unknown;\n\targuments?: string;\n}\n\nexport interface RequestBody {\n\tmodel: string;\n\tstore?: boolean;\n\tstream?: boolean;\n\tinstructions?: string;\n\tinput?: InputItem[];\n\ttools?: unknown;\n\ttemperature?: number;\n\treasoning?: Partial<ReasoningConfig>;\n\ttext?: {\n\t\tverbosity?: \"low\" | \"medium\" | \"high\";\n\t};\n\tinclude?: string[];\n\tprompt_cache_key?: string;\n\tprompt_cache_retention?: \"in_memory\" | \"24h\";\n\tmax_output_tokens?: number;\n\tmax_completion_tokens?: number;\n\t[key: string]: unknown;\n}\n\nfunction clampReasoningEffort(model: string, effort: ReasoningConfig[\"effort\"]): ReasoningConfig[\"effort\"] {\n\t// Codex backend expects exact model IDs. Do not normalize model names here.\n\tconst modelId = model.includes(\"/\") ? model.split(\"/\").pop()! : model;\n\n\t// gpt-5.1 does not support xhigh.\n\tif (modelId === \"gpt-5.1\" && effort === \"xhigh\") {\n\t\treturn \"high\";\n\t}\n\n\t// gpt-5.1-codex-mini only supports medium/high.\n\tif (modelId === \"gpt-5.1-codex-mini\") {\n\t\treturn effort === \"high\" || effort === \"xhigh\" ? \"high\" : \"medium\";\n\t}\n\n\treturn effort;\n}\n\nfunction getReasoningConfig(model: string, options: CodexRequestOptions): ReasoningConfig {\n\treturn {\n\t\teffort: clampReasoningEffort(model, options.reasoningEffort as ReasoningConfig[\"effort\"]),\n\t\tsummary: options.reasoningSummary ?? \"auto\",\n\t};\n}\n\nfunction filterInput(input: InputItem[] | undefined): InputItem[] | undefined {\n\tif (!Array.isArray(input)) return input;\n\n\treturn input\n\t\t.filter((item) => item.type !== \"item_reference\")\n\t\t.map((item) => {\n\t\t\tif (item.id != null) {\n\t\t\t\tconst { id: _id, ...rest } = item;\n\t\t\t\treturn rest as InputItem;\n\t\t\t}\n\t\t\treturn item;\n\t\t});\n}\n\nexport async function transformRequestBody(\n\tbody: RequestBody,\n\toptions: CodexRequestOptions = {},\n\tprompt?: { instructions: string; developerMessages: string[] },\n): Promise<RequestBody> {\n\tbody.store = false;\n\tbody.stream = true;\n\n\tif (body.input && Array.isArray(body.input)) {\n\t\tbody.input = filterInput(body.input);\n\n\t\tif (body.input) {\n\t\t\tconst functionCallIds = new Set(\n\t\t\t\tbody.input\n\t\t\t\t\t.filter((item) => item.type === \"function_call\" && typeof item.call_id === \"string\")\n\t\t\t\t\t.map((item) => item.call_id as string),\n\t\t\t);\n\n\t\t\tbody.input = body.input.map((item) => {\n\t\t\t\tif (item.type === \"function_call_output\" && typeof item.call_id === \"string\") {\n\t\t\t\t\tconst callId = item.call_id as string;\n\t\t\t\t\tif (!functionCallIds.has(callId)) {\n\t\t\t\t\t\tconst itemRecord = item as unknown as Record<string, unknown>;\n\t\t\t\t\t\tconst toolName = typeof itemRecord.name === \"string\" ? itemRecord.name : \"tool\";\n\t\t\t\t\t\tlet text = \"\";\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst output = itemRecord.output;\n\t\t\t\t\t\t\ttext = typeof output === \"string\" ? output : JSON.stringify(output);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\ttext = String(itemRecord.output ?? \"\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (text.length > 16000) {\n\t\t\t\t\t\t\ttext = `${text.slice(0, 16000)}\\n...[truncated]`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn {\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\tcontent: `[Previous ${toolName} result; call_id=${callId}]: ${text}`,\n\t\t\t\t\t\t} as InputItem;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn item;\n\t\t\t});\n\t\t}\n\t}\n\n\tif (prompt?.developerMessages && prompt.developerMessages.length > 0 && Array.isArray(body.input)) {\n\t\tconst developerMessages = prompt.developerMessages.map(\n\t\t\t(text) =>\n\t\t\t\t({\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\trole: \"developer\",\n\t\t\t\t\tcontent: [{ type: \"input_text\", text }],\n\t\t\t\t}) as InputItem,\n\t\t);\n\t\tbody.input = [...developerMessages, ...body.input];\n\t}\n\n\tif (options.reasoningEffort !== undefined) {\n\t\tconst reasoningConfig = getReasoningConfig(body.model, options);\n\t\tbody.reasoning = {\n\t\t\t...body.reasoning,\n\t\t\t...reasoningConfig,\n\t\t};\n\t} else {\n\t\tdelete body.reasoning;\n\t}\n\n\tbody.text = {\n\t\t...body.text,\n\t\tverbosity: options.textVerbosity || \"medium\",\n\t};\n\n\tconst include = Array.isArray(options.include) ? [...options.include] : [];\n\tinclude.push(\"reasoning.encrypted_content\");\n\tbody.include = Array.from(new Set(include));\n\n\tdelete body.max_output_tokens;\n\tdelete body.max_completion_tokens;\n\n\treturn body;\n}\n"]}
@@ -1,19 +0,0 @@
1
- export type CodexRateLimit = {
2
- used_percent?: number;
3
- window_minutes?: number;
4
- resets_at?: number;
5
- };
6
- export type CodexRateLimits = {
7
- primary?: CodexRateLimit;
8
- secondary?: CodexRateLimit;
9
- };
10
- export type CodexErrorInfo = {
11
- message: string;
12
- status: number;
13
- friendlyMessage?: string;
14
- rateLimits?: CodexRateLimits;
15
- raw?: string;
16
- };
17
- export declare function parseCodexError(response: Response): Promise<CodexErrorInfo>;
18
- export declare function parseCodexSseStream(response: Response): AsyncGenerator<Record<string, unknown>>;
19
- //# sourceMappingURL=response-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-codex/response-handler.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,SAAS,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CAkDjF;AAED,wBAAuB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA4BtG","sourcesContent":["export type CodexRateLimit = {\n\tused_percent?: number;\n\twindow_minutes?: number;\n\tresets_at?: number;\n};\n\nexport type CodexRateLimits = {\n\tprimary?: CodexRateLimit;\n\tsecondary?: CodexRateLimit;\n};\n\nexport type CodexErrorInfo = {\n\tmessage: string;\n\tstatus: number;\n\tfriendlyMessage?: string;\n\trateLimits?: CodexRateLimits;\n\traw?: string;\n};\n\nexport async function parseCodexError(response: Response): Promise<CodexErrorInfo> {\n\tconst raw = await response.text();\n\tlet message = raw || response.statusText || \"Request failed\";\n\tlet friendlyMessage: string | undefined;\n\tlet rateLimits: CodexRateLimits | undefined;\n\n\ttry {\n\t\tconst parsed = JSON.parse(raw) as { error?: Record<string, unknown> };\n\t\tconst err = parsed?.error ?? {};\n\n\t\tconst headers = response.headers;\n\t\tconst primary = {\n\t\t\tused_percent: toNumber(headers.get(\"x-codex-primary-used-percent\")),\n\t\t\twindow_minutes: toInt(headers.get(\"x-codex-primary-window-minutes\")),\n\t\t\tresets_at: toInt(headers.get(\"x-codex-primary-reset-at\")),\n\t\t};\n\t\tconst secondary = {\n\t\t\tused_percent: toNumber(headers.get(\"x-codex-secondary-used-percent\")),\n\t\t\twindow_minutes: toInt(headers.get(\"x-codex-secondary-window-minutes\")),\n\t\t\tresets_at: toInt(headers.get(\"x-codex-secondary-reset-at\")),\n\t\t};\n\t\trateLimits =\n\t\t\tprimary.used_percent !== undefined || secondary.used_percent !== undefined\n\t\t\t\t? { primary, secondary }\n\t\t\t\t: undefined;\n\n\t\tconst code = String((err as { code?: string; type?: string }).code ?? (err as { type?: string }).type ?? \"\");\n\t\tconst resetsAt = (err as { resets_at?: number }).resets_at ?? primary.resets_at ?? secondary.resets_at;\n\t\tconst mins = resetsAt ? Math.max(0, Math.round((resetsAt * 1000 - Date.now()) / 60000)) : undefined;\n\n\t\tif (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) || response.status === 429) {\n\t\t\tconst planType = (err as { plan_type?: string }).plan_type;\n\t\t\tconst plan = planType ? ` (${String(planType).toLowerCase()} plan)` : \"\";\n\t\t\tconst when = mins !== undefined ? ` Try again in ~${mins} min.` : \"\";\n\t\t\tfriendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();\n\t\t}\n\n\t\tconst errMessage = (err as { message?: string }).message;\n\t\tmessage = errMessage || friendlyMessage || message;\n\t} catch {\n\t\t// raw body not JSON\n\t}\n\n\treturn {\n\t\tmessage,\n\t\tstatus: response.status,\n\t\tfriendlyMessage,\n\t\trateLimits,\n\t\traw: raw,\n\t};\n}\n\nexport async function* parseCodexSseStream(response: Response): AsyncGenerator<Record<string, unknown>> {\n\tif (!response.body) {\n\t\treturn;\n\t}\n\n\tconst reader = response.body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\twhile (true) {\n\t\tconst { done, value } = await reader.read();\n\t\tif (done) break;\n\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\tlet index = buffer.indexOf(\"\\n\\n\");\n\t\twhile (index !== -1) {\n\t\t\tconst chunk = buffer.slice(0, index);\n\t\t\tbuffer = buffer.slice(index + 2);\n\t\t\tconst event = parseSseChunk(chunk);\n\t\t\tif (event) yield event;\n\t\t\tindex = buffer.indexOf(\"\\n\\n\");\n\t\t}\n\t}\n\n\tif (buffer.trim()) {\n\t\tconst event = parseSseChunk(buffer);\n\t\tif (event) yield event;\n\t}\n}\n\nfunction parseSseChunk(chunk: string): Record<string, unknown> | null {\n\tconst lines = chunk.split(\"\\n\");\n\tconst dataLines: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (line.startsWith(\"data:\")) {\n\t\t\tdataLines.push(line.slice(5).trim());\n\t\t}\n\t}\n\n\tif (dataLines.length === 0) return null;\n\tconst data = dataLines.join(\"\\n\").trim();\n\tif (!data || data === \"[DONE]\") return null;\n\n\ttry {\n\t\treturn JSON.parse(data) as Record<string, unknown>;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction toNumber(v: string | null): number | undefined {\n\tif (v == null) return undefined;\n\tconst n = Number(v);\n\treturn Number.isFinite(n) ? n : undefined;\n}\n\nfunction toInt(v: string | null): number | undefined {\n\tif (v == null) return undefined;\n\tconst n = parseInt(v, 10);\n\treturn Number.isFinite(n) ? n : undefined;\n}\n"]}
@@ -1,107 +0,0 @@
1
- export async function parseCodexError(response) {
2
- const raw = await response.text();
3
- let message = raw || response.statusText || "Request failed";
4
- let friendlyMessage;
5
- let rateLimits;
6
- try {
7
- const parsed = JSON.parse(raw);
8
- const err = parsed?.error ?? {};
9
- const headers = response.headers;
10
- const primary = {
11
- used_percent: toNumber(headers.get("x-codex-primary-used-percent")),
12
- window_minutes: toInt(headers.get("x-codex-primary-window-minutes")),
13
- resets_at: toInt(headers.get("x-codex-primary-reset-at")),
14
- };
15
- const secondary = {
16
- used_percent: toNumber(headers.get("x-codex-secondary-used-percent")),
17
- window_minutes: toInt(headers.get("x-codex-secondary-window-minutes")),
18
- resets_at: toInt(headers.get("x-codex-secondary-reset-at")),
19
- };
20
- rateLimits =
21
- primary.used_percent !== undefined || secondary.used_percent !== undefined
22
- ? { primary, secondary }
23
- : undefined;
24
- const code = String(err.code ?? err.type ?? "");
25
- const resetsAt = err.resets_at ?? primary.resets_at ?? secondary.resets_at;
26
- const mins = resetsAt ? Math.max(0, Math.round((resetsAt * 1000 - Date.now()) / 60000)) : undefined;
27
- if (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) || response.status === 429) {
28
- const planType = err.plan_type;
29
- const plan = planType ? ` (${String(planType).toLowerCase()} plan)` : "";
30
- const when = mins !== undefined ? ` Try again in ~${mins} min.` : "";
31
- friendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();
32
- }
33
- const errMessage = err.message;
34
- message = errMessage || friendlyMessage || message;
35
- }
36
- catch {
37
- // raw body not JSON
38
- }
39
- return {
40
- message,
41
- status: response.status,
42
- friendlyMessage,
43
- rateLimits,
44
- raw: raw,
45
- };
46
- }
47
- export async function* parseCodexSseStream(response) {
48
- if (!response.body) {
49
- return;
50
- }
51
- const reader = response.body.getReader();
52
- const decoder = new TextDecoder();
53
- let buffer = "";
54
- while (true) {
55
- const { done, value } = await reader.read();
56
- if (done)
57
- break;
58
- buffer += decoder.decode(value, { stream: true });
59
- let index = buffer.indexOf("\n\n");
60
- while (index !== -1) {
61
- const chunk = buffer.slice(0, index);
62
- buffer = buffer.slice(index + 2);
63
- const event = parseSseChunk(chunk);
64
- if (event)
65
- yield event;
66
- index = buffer.indexOf("\n\n");
67
- }
68
- }
69
- if (buffer.trim()) {
70
- const event = parseSseChunk(buffer);
71
- if (event)
72
- yield event;
73
- }
74
- }
75
- function parseSseChunk(chunk) {
76
- const lines = chunk.split("\n");
77
- const dataLines = [];
78
- for (const line of lines) {
79
- if (line.startsWith("data:")) {
80
- dataLines.push(line.slice(5).trim());
81
- }
82
- }
83
- if (dataLines.length === 0)
84
- return null;
85
- const data = dataLines.join("\n").trim();
86
- if (!data || data === "[DONE]")
87
- return null;
88
- try {
89
- return JSON.parse(data);
90
- }
91
- catch {
92
- return null;
93
- }
94
- }
95
- function toNumber(v) {
96
- if (v == null)
97
- return undefined;
98
- const n = Number(v);
99
- return Number.isFinite(n) ? n : undefined;
100
- }
101
- function toInt(v) {
102
- if (v == null)
103
- return undefined;
104
- const n = parseInt(v, 10);
105
- return Number.isFinite(n) ? n : undefined;
106
- }
107
- //# sourceMappingURL=response-handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"response-handler.js","sourceRoot":"","sources":["../../../src/providers/openai-codex/response-handler.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAkB,EAA2B;IAClF,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,OAAO,GAAG,GAAG,IAAI,QAAQ,CAAC,UAAU,IAAI,gBAAgB,CAAC;IAC7D,IAAI,eAAmC,CAAC;IACxC,IAAI,UAAuC,CAAC;IAE5C,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAwC,CAAC;QACtE,MAAM,GAAG,GAAG,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;QAEhC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QACjC,MAAM,OAAO,GAAG;YACf,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;YACnE,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;YACpE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;SACzD,CAAC;QACF,MAAM,SAAS,GAAG;YACjB,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;YACrE,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;YACtE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;SAC3D,CAAC;QACF,UAAU;YACT,OAAO,CAAC,YAAY,KAAK,SAAS,IAAI,SAAS,CAAC,YAAY,KAAK,SA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AAAA,CAC1C","sourcesContent":["export type CodexRateLimit = {\n\tused_percent?: number;\n\twindow_minutes?: number;\n\tresets_at?: number;\n};\n\nexport type CodexRateLimits = {\n\tprimary?: CodexRateLimit;\n\tsecondary?: CodexRateLimit;\n};\n\nexport type CodexErrorInfo = {\n\tmessage: string;\n\tstatus: number;\n\tfriendlyMessage?: string;\n\trateLimits?: CodexRateLimits;\n\traw?: string;\n};\n\nexport async function parseCodexError(response: Response): Promise<CodexErrorInfo> {\n\tconst raw = await response.text();\n\tlet message = raw || response.statusText || \"Request failed\";\n\tlet friendlyMessage: string | undefined;\n\tlet rateLimits: CodexRateLimits | undefined;\n\n\ttry {\n\t\tconst parsed = JSON.parse(raw) as { error?: Record<string, unknown> };\n\t\tconst err = parsed?.error ?? {};\n\n\t\tconst headers = response.headers;\n\t\tconst primary = {\n\t\t\tused_percent: toNumber(headers.get(\"x-codex-primary-used-percent\")),\n\t\t\twindow_minutes: toInt(headers.get(\"x-codex-primary-window-minutes\")),\n\t\t\tresets_at: toInt(headers.get(\"x-codex-primary-reset-at\")),\n\t\t};\n\t\tconst secondary = {\n\t\t\tused_percent: toNumber(headers.get(\"x-codex-secondary-used-percent\")),\n\t\t\twindow_minutes: toInt(headers.get(\"x-codex-secondary-window-minutes\")),\n\t\t\tresets_at: toInt(headers.get(\"x-codex-secondary-reset-at\")),\n\t\t};\n\t\trateLimits =\n\t\t\tprimary.used_percent !== undefined || secondary.used_percent !== undefined\n\t\t\t\t? { primary, secondary }\n\t\t\t\t: undefined;\n\n\t\tconst code = String((err as { code?: string; type?: string }).code ?? (err as { type?: string }).type ?? \"\");\n\t\tconst resetsAt = (err as { resets_at?: number }).resets_at ?? primary.resets_at ?? secondary.resets_at;\n\t\tconst mins = resetsAt ? Math.max(0, Math.round((resetsAt * 1000 - Date.now()) / 60000)) : undefined;\n\n\t\tif (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) || response.status === 429) {\n\t\t\tconst planType = (err as { plan_type?: string }).plan_type;\n\t\t\tconst plan = planType ? ` (${String(planType).toLowerCase()} plan)` : \"\";\n\t\t\tconst when = mins !== undefined ? ` Try again in ~${mins} min.` : \"\";\n\t\t\tfriendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();\n\t\t}\n\n\t\tconst errMessage = (err as { message?: string }).message;\n\t\tmessage = errMessage || friendlyMessage || message;\n\t} catch {\n\t\t// raw body not JSON\n\t}\n\n\treturn {\n\t\tmessage,\n\t\tstatus: response.status,\n\t\tfriendlyMessage,\n\t\trateLimits,\n\t\traw: raw,\n\t};\n}\n\nexport async function* parseCodexSseStream(response: Response): AsyncGenerator<Record<string, unknown>> {\n\tif (!response.body) {\n\t\treturn;\n\t}\n\n\tconst reader = response.body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\twhile (true) {\n\t\tconst { done, value } = await reader.read();\n\t\tif (done) break;\n\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\tlet index = buffer.indexOf(\"\\n\\n\");\n\t\twhile (index !== -1) {\n\t\t\tconst chunk = buffer.slice(0, index);\n\t\t\tbuffer = buffer.slice(index + 2);\n\t\t\tconst event = parseSseChunk(chunk);\n\t\t\tif (event) yield event;\n\t\t\tindex = buffer.indexOf(\"\\n\\n\");\n\t\t}\n\t}\n\n\tif (buffer.trim()) {\n\t\tconst event = parseSseChunk(buffer);\n\t\tif (event) yield event;\n\t}\n}\n\nfunction parseSseChunk(chunk: string): Record<string, unknown> | null {\n\tconst lines = chunk.split(\"\\n\");\n\tconst dataLines: string[] = [];\n\n\tfor (const line of lines) {\n\t\tif (line.startsWith(\"data:\")) {\n\t\t\tdataLines.push(line.slice(5).trim());\n\t\t}\n\t}\n\n\tif (dataLines.length === 0) return null;\n\tconst data = dataLines.join(\"\\n\").trim();\n\tif (!data || data === \"[DONE]\") return null;\n\n\ttry {\n\t\treturn JSON.parse(data) as Record<string, unknown>;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction toNumber(v: string | null): number | undefined {\n\tif (v == null) return undefined;\n\tconst n = Number(v);\n\treturn Number.isFinite(n) ? n : undefined;\n}\n\nfunction toInt(v: string | null): number | undefined {\n\tif (v == null) return undefined;\n\tconst n = parseInt(v, 10);\n\treturn Number.isFinite(n) ? n : undefined;\n}\n"]}