@yolk-sdk/agent 0.1.0-canary.44 → 0.1.0-canary.45
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.
- package/README.md +6 -5
- package/dist/providers/openai/codex-provider.d.mts +3 -6
- package/dist/providers/openai/codex-provider.d.mts.map +1 -1
- package/dist/providers/openai/codex-provider.mjs +13 -4
- package/dist/providers/openai/codex-provider.mjs.map +1 -1
- package/package.json +1 -1
- package/src/providers/openai/codex-provider.ts +32 -12
package/README.md
CHANGED
|
@@ -171,14 +171,15 @@ const ContextLayer = makeWindowCompactionTransformer({
|
|
|
171
171
|
|
|
172
172
|
Build sources with `inlineBase64AttachmentSource`, `urlAttachmentSource`, or
|
|
173
173
|
`refAttachmentSource`. Providers can pass through supported media URLs: OpenAI Chat supports image
|
|
174
|
-
URLs; OpenAI Codex and Anthropic
|
|
175
|
-
durable URLs for app-owned uploads, or persist `Ref` values and call
|
|
174
|
+
URLs; OpenAI Codex supports image and document URLs; Anthropic supports image and PDF URLs. Use
|
|
175
|
+
inline base64 for simple apps, durable URLs for app-owned uploads, or persist `Ref` values and call
|
|
176
176
|
`resolveContentAttachmentSources` at your storage boundary before provider execution. Host apps own
|
|
177
177
|
upload, auth, retention, URL durability, and ref hydration policy.
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
text, images, inline text documents, and URL/base64 PDFs
|
|
181
|
-
fail before the provider
|
|
179
|
+
OpenAI Codex preserves text, image, and document `ToolResultMessage` parts as native function output
|
|
180
|
+
content. Anthropic Claude preserves text, images, inline text documents, and URL/base64 PDFs as
|
|
181
|
+
nested tool-result content. Audio and unresolved `Ref` sources still fail before the provider
|
|
182
|
+
request.
|
|
182
183
|
|
|
183
184
|
```ts
|
|
184
185
|
import { ImagePart, UserMessage, urlAttachmentSource } from '@yolk-sdk/agent/protocol'
|
|
@@ -33,11 +33,8 @@ type OpenAiCodexInputFilePart = {
|
|
|
33
33
|
readonly type: 'input_file';
|
|
34
34
|
readonly file_url: string;
|
|
35
35
|
};
|
|
36
|
-
type
|
|
37
|
-
|
|
38
|
-
readonly text: string;
|
|
39
|
-
};
|
|
40
|
-
type OpenAiCodexInputContentPart = OpenAiCodexInputTextPart | OpenAiCodexInputImagePart | OpenAiCodexInputFilePart | OpenAiCodexOutputTextPart;
|
|
36
|
+
type OpenAiCodexInputContentPart = OpenAiCodexInputTextPart | OpenAiCodexInputImagePart | OpenAiCodexInputFilePart;
|
|
37
|
+
type OpenAiCodexFunctionOutput = string | ReadonlyArray<OpenAiCodexInputContentPart>;
|
|
41
38
|
type OpenAiCodexFunctionCallInput = {
|
|
42
39
|
readonly type: 'function_call';
|
|
43
40
|
readonly call_id: string;
|
|
@@ -47,7 +44,7 @@ type OpenAiCodexFunctionCallInput = {
|
|
|
47
44
|
type OpenAiCodexFunctionOutputInput = {
|
|
48
45
|
readonly type: 'function_call_output';
|
|
49
46
|
readonly call_id: string;
|
|
50
|
-
readonly output:
|
|
47
|
+
readonly output: OpenAiCodexFunctionOutput;
|
|
51
48
|
};
|
|
52
49
|
type OpenAiCodexInputItem = OpenAiCodexMessageInput | OpenAiCodexFunctionCallInput | OpenAiCodexFunctionOutputInput;
|
|
53
50
|
type OpenAiCodexTool = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-provider.d.mts","names":[],"sources":["../../../src/providers/openai/codex-provider.ts"],"mappings":";;;;;;;KAiDY,2BAAA;AAAA,KAEA,yBAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAAA,SACP,YAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA;EAAA,SACxB,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,2BAAA;AAAA;AAAA,KAGzB,uBAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA,WAAkB,aAAa,CAAC,2BAAA;AAAA;AAAA,KAGtC,wBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,KAGV,yBAAA;EAAA,SACM,IAAA;EAAA,SACA,SAAS;AAAA;AAAA,KAGf,wBAAA;EAAA,SAEU,IAAA;EAAA,SACA,QAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGV,
|
|
1
|
+
{"version":3,"file":"codex-provider.d.mts","names":[],"sources":["../../../src/providers/openai/codex-provider.ts"],"mappings":";;;;;;;KAiDY,2BAAA;AAAA,KAEA,yBAAA;EAAA,SACD,KAAA,EAAO,gBAAA;EAAA,SACP,YAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA;EAAA,SACxB,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,2BAAA;AAAA;AAAA,KAGzB,uBAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA,WAAkB,aAAa,CAAC,2BAAA;AAAA;AAAA,KAGtC,wBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,KAGV,yBAAA;EAAA,SACM,IAAA;EAAA,SACA,SAAS;AAAA;AAAA,KAGf,wBAAA;EAAA,SAEU,IAAA;EAAA,SACA,QAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGV,2BAAA,GACD,wBAAA,GACA,yBAAA,GACA,wBAAA;AAAA,KAEC,yBAAA,YAAqC,aAAa,CAAC,2BAAA;AAAA,KAEnD,4BAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA;EAAA,SACA,IAAA;EAAA,SACA,SAAA;AAAA;AAAA,KAGN,8BAAA;EAAA,SACM,IAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA,EAAQ,yBAAyB;AAAA;AAAA,KAGvC,oBAAA,GACD,uBAAA,GACA,4BAAA,GACA,8BAAA;AAAA,KAEC,eAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;AAAA;AAAA,KAGN,sBAAA;EAAA,SACM,KAAA;EAAA,SACA,YAAA;EAAA,SACA,KAAA,EAAO,aAAA,CAAc,oBAAA;EAAA,SACrB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,SAAA;IAAA,SACE,MAAA,EAAQ,oBAAA;IAAA,SACR,OAAA,EAAS,2BAAA;EAAA;EAAA,SAEX,KAAA,GAAQ,aAAA,CAAc,eAAA;EAAA,SACtB,mBAAA;AAAA;AAAA,cA2RE,wBAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SACW,sBAAA,GAAyB,oBAAA;EAAA,SACzB,gBAAA,GAAmB,2BAAA;AAAA,MAE7B,MAAA,CAAO,MAAA,CAAO,sBAAA,EAAwB,QAAA;AAAA,cA0lB5B,yBAAA,GACX,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cA0Fd,4BAAA,GAAgC,MAAA,EAAQ,yBAAA,KAAyB,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
|
|
@@ -77,7 +77,7 @@ const contentPartToText = (part, owner) => {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
const contentToText = (content, owner) => typeof content === "string" ? Effect.succeed(content) : Effect.forEach(content, (part) => contentPartToText(part, owner)).pipe(Effect.map((textParts) => textParts.join("\n")));
|
|
80
|
-
const
|
|
80
|
+
const contentPartToCodexInputPart = (part) => {
|
|
81
81
|
switch (part._tag) {
|
|
82
82
|
case "Text": return Effect.succeed({
|
|
83
83
|
type: "input_text",
|
|
@@ -105,7 +105,7 @@ const userPartToCodexInputPart = (part) => {
|
|
|
105
105
|
});
|
|
106
106
|
case "Ref": return Effect.fail(unsupportedContentError("Unresolved document source"));
|
|
107
107
|
}
|
|
108
|
-
case "Audio": return Effect.fail(unsupportedContentError("
|
|
108
|
+
case "Audio": return Effect.fail(unsupportedContentError("Audio"));
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
const contentToUserInput = (content) => {
|
|
@@ -113,8 +113,17 @@ const contentToUserInput = (content) => {
|
|
|
113
113
|
const parts = contentParts(content);
|
|
114
114
|
const onlyPart = parts[0];
|
|
115
115
|
if (onlyPart !== void 0 && parts.length === 1 && onlyPart._tag === "Text") return Effect.succeed(onlyPart.text);
|
|
116
|
-
return Effect.forEach(parts,
|
|
116
|
+
return Effect.forEach(parts, contentPartToCodexInputPart);
|
|
117
117
|
};
|
|
118
|
+
const contentToCodexFunctionOutput = (content) => typeof content === "string" ? Effect.succeed(content) : Effect.forEach(content, contentPartToCodexInputPart);
|
|
119
|
+
const codexToolResultOutput = (content, isError) => contentToCodexFunctionOutput(content).pipe(Effect.map((output) => {
|
|
120
|
+
if (isError !== true) return output;
|
|
121
|
+
const errorPart = {
|
|
122
|
+
type: "input_text",
|
|
123
|
+
text: "Tool execution failed."
|
|
124
|
+
};
|
|
125
|
+
return typeof output === "string" ? `${errorPart.text}\n\n${output}` : [errorPart, ...output];
|
|
126
|
+
}));
|
|
118
127
|
const serializeToolArguments = (params) => encodeJsonString(params, "Could not serialize OpenAI Codex tool arguments");
|
|
119
128
|
const toolCallToCodexInput = (call) => Effect.gen(function* () {
|
|
120
129
|
return {
|
|
@@ -142,7 +151,7 @@ const messageToCodexInput = (message) => Effect.gen(function* () {
|
|
|
142
151
|
case "ToolResult": return [{
|
|
143
152
|
type: "function_call_output",
|
|
144
153
|
call_id: message.toolCallId,
|
|
145
|
-
output: yield*
|
|
154
|
+
output: yield* codexToolResultOutput(prependMessageContextToContent(message.content, messageContextText(message)), message.isError)
|
|
146
155
|
}];
|
|
147
156
|
}
|
|
148
157
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-provider.mjs","names":["Arr","LLMReasoningDelta","LLMTextDelta"],"sources":["../../../src/providers/openai/codex-provider.ts"],"sourcesContent":["import { Array as Arr, Effect, Layer, Option, Ref, Stream } from 'effect'\nimport {\n HttpClient,\n HttpClientRequest,\n type HttpClientError,\n type HttpClientResponse\n} from 'effect/unstable/http'\nimport * as Schema from 'effect/Schema'\nimport {\n AgentInputUsage,\n AgentOutputUsage,\n AgentUsage,\n ToolCall,\n attachmentSourceDataUrl,\n attachmentSourceUrl,\n assistantContent,\n assistantHostToolCalls,\n contentParts,\n messageContextText,\n replaceLoneSurrogatesDeep,\n prependMessageContextToContent,\n type AgentMessage,\n type AgentReasoningEffort,\n type Content,\n type ContentPart,\n type ProviderFailureKind,\n type ToolDef\n} from '@yolk-sdk/agent/protocol'\nimport {\n LLMError,\n LLMDone,\n LLMProvider,\n LLMReasoningDelta,\n LLMTextDelta,\n LLMToolCall,\n LLMUsage,\n type LLMEvent,\n type LLMRequest\n} from '@yolk-sdk/agent/loop'\nimport { openAiCodexAuthorizationHeaders, openAiCodexResponsesUrl } from './codex.ts'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport {\n classifyProviderFailure,\n providerErrorInfo,\n providerFailureCause,\n providerFailureRetryable\n} from '../provider-error.ts'\nimport { validateProviderTranscript } from '../transcript.ts'\n\nexport type OpenAiCodexReasoningSummary = 'auto' | 'concise' | 'detailed'\n\nexport type OpenAiCodexProviderConfig = {\n readonly token: OAuthAccessToken\n readonly responsesUrl?: string\n readonly extraHeaders?: Readonly<Record<string, string>>\n readonly defaultReasoningEffort?: AgentReasoningEffort\n readonly reasoningSummary?: OpenAiCodexReasoningSummary\n}\n\ntype OpenAiCodexMessageInput = {\n readonly role: 'user' | 'assistant'\n readonly content: string | ReadonlyArray<OpenAiCodexInputContentPart>\n}\n\ntype OpenAiCodexInputTextPart = {\n readonly type: 'input_text'\n readonly text: string\n}\n\ntype OpenAiCodexInputImagePart = {\n readonly type: 'input_image'\n readonly image_url: string\n}\n\ntype OpenAiCodexInputFilePart =\n | {\n readonly type: 'input_file'\n readonly filename: string\n readonly file_data: string\n }\n | {\n readonly type: 'input_file'\n readonly file_url: string\n }\n\ntype OpenAiCodexOutputTextPart = {\n readonly type: 'output_text'\n readonly text: string\n}\n\ntype OpenAiCodexInputContentPart =\n | OpenAiCodexInputTextPart\n | OpenAiCodexInputImagePart\n | OpenAiCodexInputFilePart\n | OpenAiCodexOutputTextPart\n\ntype OpenAiCodexFunctionCallInput = {\n readonly type: 'function_call'\n readonly call_id: string\n readonly name: string\n readonly arguments: string\n}\n\ntype OpenAiCodexFunctionOutputInput = {\n readonly type: 'function_call_output'\n readonly call_id: string\n readonly output: string\n}\n\ntype OpenAiCodexInputItem =\n | OpenAiCodexMessageInput\n | OpenAiCodexFunctionCallInput\n | OpenAiCodexFunctionOutputInput\n\ntype OpenAiCodexTool = {\n readonly type: 'function'\n readonly name: string\n readonly description: string\n readonly parameters: unknown\n}\n\ntype OpenAiCodexRequestBody = {\n readonly model: string\n readonly instructions: string\n readonly input: ReadonlyArray<OpenAiCodexInputItem>\n readonly store: false\n readonly stream: true\n readonly reasoning: {\n readonly effort: AgentReasoningEffort\n readonly summary: OpenAiCodexReasoningSummary\n }\n readonly tools?: ReadonlyArray<OpenAiCodexTool>\n readonly parallel_tool_calls?: true\n}\n\nclass OpenAiCodexReasoningSummaryText extends Schema.Class<OpenAiCodexReasoningSummaryText>(\n 'OpenAiCodexReasoningSummaryText'\n)({\n type: Schema.Literals(['summary_text']),\n text: Schema.String\n}) {}\n\nclass OpenAiCodexReasoningText extends Schema.Class<OpenAiCodexReasoningText>(\n 'OpenAiCodexReasoningText'\n)({\n type: Schema.Literals(['reasoning_text']),\n text: Schema.String\n}) {}\n\nclass OpenAiCodexOutputText extends Schema.Class<OpenAiCodexOutputText>('OpenAiCodexOutputText')({\n type: Schema.Literals(['output_text']),\n text: Schema.String\n}) {}\n\nclass OpenAiCodexMessageOutput extends Schema.Class<OpenAiCodexMessageOutput>(\n 'OpenAiCodexMessageOutput'\n)({\n type: Schema.Literals(['message']),\n content: Schema.Array(OpenAiCodexOutputText)\n}) {}\n\nclass OpenAiCodexFunctionCallOutput extends Schema.Class<OpenAiCodexFunctionCallOutput>(\n 'OpenAiCodexFunctionCallOutput'\n)({\n type: Schema.Literals(['function_call']),\n call_id: Schema.String,\n name: Schema.String,\n arguments: Schema.String\n}) {}\n\nclass OpenAiCodexReasoningOutput extends Schema.Class<OpenAiCodexReasoningOutput>(\n 'OpenAiCodexReasoningOutput'\n)({\n type: Schema.Literals(['reasoning']),\n summary: Schema.optional(Schema.Array(OpenAiCodexReasoningSummaryText)),\n content: Schema.optional(Schema.Array(OpenAiCodexReasoningText))\n}) {}\n\nclass OpenAiCodexInputTokensDetails extends Schema.Class<OpenAiCodexInputTokensDetails>(\n 'OpenAiCodexInputTokensDetails'\n)({\n cached_tokens: Schema.optional(Schema.Number)\n}) {}\n\nclass OpenAiCodexOutputTokensDetails extends Schema.Class<OpenAiCodexOutputTokensDetails>(\n 'OpenAiCodexOutputTokensDetails'\n)({\n reasoning_tokens: Schema.optional(Schema.Number)\n}) {}\n\nclass OpenAiCodexUsageResponse extends Schema.Class<OpenAiCodexUsageResponse>(\n 'OpenAiCodexUsageResponse'\n)({\n input_tokens: Schema.Number,\n output_tokens: Schema.Number,\n input_tokens_details: Schema.optional(OpenAiCodexInputTokensDetails),\n output_tokens_details: Schema.optional(OpenAiCodexOutputTokensDetails)\n}) {}\n\nconst OpenAiCodexOutputItem = Schema.Union([\n OpenAiCodexMessageOutput,\n OpenAiCodexFunctionCallOutput,\n OpenAiCodexReasoningOutput\n])\ntype OpenAiCodexOutputItem = typeof OpenAiCodexOutputItem.Type\n\nclass OpenAiCodexResponse extends Schema.Class<OpenAiCodexResponse>('OpenAiCodexResponse')({\n output_text: Schema.optional(Schema.String),\n output: Schema.Array(OpenAiCodexOutputItem),\n usage: Schema.optional(OpenAiCodexUsageResponse)\n}) {}\n\nconst unknownToMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error)\n\nconst encodeJsonString = (value: unknown, message: string) =>\n Schema.encodeUnknownEffect(Schema.UnknownFromJsonString)(value).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'provider_error',\n message: `${message}: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst decodeJsonString = (raw: string, message: string) =>\n Schema.decodeUnknownEffect(Schema.UnknownFromJsonString)(raw).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'invalid_response',\n message: `${message}: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst unsupportedContentError = (contentType: string) =>\n new LLMError({\n cause: 'provider_error',\n message: `${contentType} content is not supported by the OpenAI Codex OAuth provider yet`,\n retryable: false\n })\n\nconst contentPartToText = (part: ContentPart, owner: string): Effect.Effect<string, LLMError> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed(part.text)\n case 'Image':\n return Effect.fail(unsupportedContentError(`${owner} image`))\n case 'Document':\n return Effect.fail(unsupportedContentError(`${owner} document`))\n case 'Audio':\n return Effect.fail(unsupportedContentError(`${owner} audio`))\n }\n}\n\nconst contentToText = (content: Content, owner: string): Effect.Effect<string, LLMError> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, part => contentPartToText(part, owner)).pipe(\n Effect.map(textParts => textParts.join('\\n'))\n )\n\nconst userPartToCodexInputPart = (\n part: ContentPart\n): Effect.Effect<\n OpenAiCodexInputTextPart | OpenAiCodexInputImagePart | OpenAiCodexInputFilePart,\n LLMError\n> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed({ type: 'input_text', text: part.text })\n case 'Image':\n return Option.match(attachmentSourceUrl(part.source, part.mimeType), {\n onNone: () => Effect.fail(unsupportedContentError('Unresolved image source')),\n onSome: url =>\n Effect.succeed({\n type: 'input_image',\n image_url: url\n })\n })\n case 'Document':\n switch (part.source._tag) {\n case 'InlineBase64':\n return Option.match(attachmentSourceDataUrl(part.source, part.mimeType), {\n onNone: () => Effect.fail(unsupportedContentError('Invalid document source')),\n onSome: url =>\n Effect.succeed({\n type: 'input_file',\n filename: part.filename,\n file_data: url\n })\n })\n case 'Url':\n return Effect.succeed({ type: 'input_file', file_url: part.source.url })\n case 'Ref':\n return Effect.fail(unsupportedContentError('Unresolved document source'))\n }\n case 'Audio':\n return Effect.fail(unsupportedContentError('User audio'))\n }\n}\n\nconst contentToUserInput = (\n content: Content\n): Effect.Effect<OpenAiCodexMessageInput['content'], LLMError> => {\n if (typeof content === 'string') {\n return Effect.succeed(content)\n }\n\n const parts = contentParts(content)\n const onlyPart = parts[0]\n\n if (onlyPart !== undefined && parts.length === 1 && onlyPart._tag === 'Text') {\n return Effect.succeed(onlyPart.text)\n }\n\n return Effect.forEach(parts, userPartToCodexInputPart)\n}\n\nconst serializeToolArguments = (params: unknown) =>\n encodeJsonString(params, 'Could not serialize OpenAI Codex tool arguments')\n\nconst toolCallToCodexInput = (\n call: ToolCall\n): Effect.Effect<OpenAiCodexFunctionCallInput, LLMError> =>\n Effect.gen(function* () {\n return {\n type: 'function_call',\n call_id: call.id,\n name: call.name,\n arguments: yield* serializeToolArguments(call.params)\n }\n })\n\nconst messageToCodexInput = (\n message: AgentMessage\n): Effect.Effect<ReadonlyArray<OpenAiCodexInputItem>, LLMError> =>\n Effect.gen(function* () {\n switch (message._tag) {\n case 'User':\n return [\n {\n role: 'user',\n content: yield* contentToUserInput(\n prependMessageContextToContent(message.content, messageContextText(message))\n )\n }\n ]\n case 'Assistant': {\n const content = yield* contentToText(\n prependMessageContextToContent(assistantContent(message), messageContextText(message)),\n 'Assistant'\n )\n const toolCallInputs = yield* Effect.forEach(\n assistantHostToolCalls(message),\n toolCallToCodexInput\n )\n\n if (content.length > 0) {\n const assistantMessage: OpenAiCodexInputItem = { role: 'assistant', content }\n\n return [assistantMessage, ...toolCallInputs]\n }\n\n return toolCallInputs\n }\n case 'ToolResult':\n return [\n {\n type: 'function_call_output',\n call_id: message.toolCallId,\n output: yield* contentToText(\n prependMessageContextToContent(message.content, messageContextText(message)),\n 'Tool result'\n )\n }\n ]\n }\n })\n\nconst toOpenAiCodexTool = (tool: ToolDef): OpenAiCodexTool => ({\n type: 'function',\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters\n})\n\nexport const toOpenAiCodexRequestBody = (\n request: LLMRequest,\n config?: {\n readonly defaultReasoningEffort?: AgentReasoningEffort\n readonly reasoningSummary?: OpenAiCodexReasoningSummary\n }\n): Effect.Effect<OpenAiCodexRequestBody, LLMError> =>\n Effect.gen(function* () {\n yield* validateProviderTranscript(request.messages)\n const input = Arr.flatten(yield* Effect.forEach(request.messages, messageToCodexInput))\n\n const body: Omit<OpenAiCodexRequestBody, 'tools'> = {\n model: request.model,\n instructions: request.systemPrompt,\n input,\n store: false,\n stream: true,\n reasoning: {\n effort: request.reasoningEffort ?? config?.defaultReasoningEffort ?? 'low',\n summary: config?.reasoningSummary ?? 'auto'\n }\n }\n\n if (request.tools.length === 0) {\n return body\n }\n\n return {\n ...body,\n tools: request.tools.map(toOpenAiCodexTool),\n parallel_tool_calls: true\n }\n })\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n\nconst stringField = (value: unknown, key: string) => {\n if (!isRecord(value)) {\n return undefined\n }\n\n const field = Object.getOwnPropertyDescriptor(value, key)?.value\n\n return typeof field === 'string' ? field : undefined\n}\n\nconst recordField = (value: unknown, key: string) => {\n if (!isRecord(value)) {\n return undefined\n }\n\n const field = Object.getOwnPropertyDescriptor(value, key)?.value\n\n return isRecord(field) ? field : undefined\n}\n\nconst openAiCodexProvider = 'openai_codex'\n\nconst providerSignalError = (input: {\n readonly message: string\n readonly providerCode?: string\n readonly fallbackKind?: ProviderFailureKind\n}) => {\n const provider = classifyProviderFailure({\n provider: openAiCodexProvider,\n message: input.message,\n ...(input.providerCode === undefined ? {} : { providerCode: input.providerCode }),\n ...(input.fallbackKind === undefined ? {} : { fallbackKind: input.fallbackKind })\n })\n\n return new LLMError({\n cause: providerFailureCause(provider.kind),\n message: `OpenAI Codex stream error: ${input.message}`,\n retryable: providerFailureRetryable(provider.kind),\n provider\n })\n}\n\nconst parseToolArguments = (raw: string) =>\n decodeJsonString(raw, 'Invalid OpenAI Codex tool arguments JSON')\n\nconst textFromOutputItem = (item: OpenAiCodexOutputItem) => {\n switch (item.type) {\n case 'message':\n return Arr.map(item.content, content => content.text)\n case 'function_call':\n case 'reasoning':\n return []\n }\n}\n\nconst textFromOutputItems = (items: ReadonlyArray<OpenAiCodexOutputItem>) => {\n const textParts = Arr.flatten(Arr.map(items, textFromOutputItem))\n\n return textParts.join('')\n}\n\nconst reasoningFromOutputItem = (item: OpenAiCodexOutputItem) => {\n switch (item.type) {\n case 'reasoning':\n return [\n ...(item.summary ?? []).map(summary => summary.text),\n ...(item.content ?? []).map(content => content.text)\n ]\n case 'message':\n case 'function_call':\n return []\n }\n}\n\nconst reasoningFromOutputItems = (items: ReadonlyArray<OpenAiCodexOutputItem>) => {\n const reasoningParts = Arr.flatten(Arr.map(items, reasoningFromOutputItem))\n\n return reasoningParts.join('')\n}\n\nconst toAgentUsage = (usage: OpenAiCodexUsageResponse) =>\n AgentUsage.make({\n input: AgentInputUsage.make({\n total: usage.input_tokens,\n uncached: usage.input_tokens - (usage.input_tokens_details?.cached_tokens ?? 0),\n cacheRead: usage.input_tokens_details?.cached_tokens\n }),\n output: AgentOutputUsage.make({\n total: usage.output_tokens,\n reasoning: usage.output_tokens_details?.reasoning_tokens,\n text: usage.output_tokens - (usage.output_tokens_details?.reasoning_tokens ?? 0)\n })\n })\n\ntype ToLlmEventsOptions = {\n readonly allowEmptyStop: boolean\n}\n\nconst toLlmEvents = (\n response: OpenAiCodexResponse,\n options: ToLlmEventsOptions\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const text = response.output_text ?? textFromOutputItems(response.output)\n const reasoning = reasoningFromOutputItems(response.output)\n const reasoningEvents =\n reasoning.length > 0 ? [LLMReasoningDelta.make({ text: reasoning })] : []\n const textEvents = text.length > 0 ? [LLMTextDelta.make({ text })] : []\n const toolCallEvents = Arr.getSomes(\n yield* Effect.forEach(response.output, item => {\n switch (item.type) {\n case 'message':\n case 'reasoning':\n return Effect.succeed(Option.none())\n case 'function_call':\n return parseToolArguments(item.arguments).pipe(\n Effect.map(params =>\n Option.some(\n LLMToolCall.make({\n call: ToolCall.make({\n id: item.call_id,\n name: item.name,\n params\n })\n })\n )\n )\n )\n }\n })\n )\n\n if (textEvents.length === 0 && toolCallEvents.length === 0 && !options.allowEmptyStop) {\n return yield* Effect.fail(\n new LLMError({\n cause: 'invalid_response',\n message: 'OpenAI Codex response did not include text or tool calls',\n retryable: false\n })\n )\n }\n\n const events: Array<LLMEvent> = [\n ...reasoningEvents,\n ...textEvents,\n ...toolCallEvents,\n LLMDone.make({ stopReason: toolCallEvents.length > 0 ? 'tool_use' : 'stop' })\n ]\n\n if (response.usage !== undefined) {\n events.push(LLMUsage.make({ usage: toAgentUsage(response.usage) }))\n }\n\n return events\n })\n\nconst decodeOpenAiCodexResponse = (json: unknown) =>\n Schema.decodeUnknownEffect(OpenAiCodexResponse)(json).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'invalid_response',\n message: `Invalid OpenAI Codex response: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst parseOpenAiCodexJsonResponse = (\n raw: string\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const json = yield* decodeJsonString(raw, 'Could not parse OpenAI Codex response JSON')\n const parsed = yield* decodeOpenAiCodexResponse(json)\n\n return yield* toLlmEvents(parsed, { allowEmptyStop: false })\n })\n\ntype OpenAiCodexBodyFormat = 'undecided' | 'sse' | 'json'\n\ntype OpenAiCodexSseState = {\n readonly hasTextDelta: boolean\n readonly hasReasoningDelta: boolean\n readonly hasToolCall: boolean\n readonly hasDone: boolean\n}\n\ntype OpenAiCodexSseStep = {\n readonly state: OpenAiCodexSseState\n readonly events: ReadonlyArray<LLMEvent>\n}\n\ntype OpenAiCodexBodyState = {\n readonly format: OpenAiCodexBodyFormat\n readonly buffer: string\n readonly sse: OpenAiCodexSseState\n}\n\nconst initialSseState: OpenAiCodexSseState = {\n hasTextDelta: false,\n hasReasoningDelta: false,\n hasToolCall: false,\n hasDone: false\n}\n\nconst initialBodyState: OpenAiCodexBodyState = {\n format: 'undecided',\n buffer: '',\n sse: initialSseState\n}\n\nconst normalizeNewlines = (text: string) => text.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n')\n\nconst classifyCodexBody = (buffer: string): OpenAiCodexBodyFormat => {\n const trimmed = buffer.trimStart()\n\n if (trimmed.length === 0) {\n return 'undecided'\n }\n\n if (trimmed.startsWith('event:') || trimmed.startsWith('data:')) {\n return 'sse'\n }\n\n if ('event:'.startsWith(trimmed) || 'data:'.startsWith(trimmed)) {\n return 'undecided'\n }\n\n return 'json'\n}\n\nconst splitCompleteSseBlocks = (buffer: string) => {\n const blocks = buffer.split('\\n\\n')\n const tail = blocks.at(-1) ?? ''\n\n return { completeBlocks: blocks.slice(0, -1), tail }\n}\n\nconst dataFromSseBlock = (block: string) => {\n const lines = Arr.map(\n Arr.filter(block.split('\\n'), line => line.startsWith('data:')),\n line => line.slice(5).trimStart()\n )\n\n const data = lines.join('\\n').trim()\n\n if (data.length === 0 || data === '[DONE]') {\n return undefined\n }\n\n return data\n}\n\nconst parseOpenAiCodexSseJson = (data: string) =>\n decodeJsonString(data, 'Could not parse OpenAI Codex stream event JSON')\n\nconst decodeOpenAiCodexOutputItem = (value: unknown) =>\n Schema.decodeUnknownEffect(OpenAiCodexOutputItem)(value).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'invalid_response',\n message: `Invalid OpenAI Codex output item: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst invalidFunctionCallSseItemError = () =>\n new LLMError({\n cause: 'invalid_response',\n message: 'Invalid OpenAI Codex function call stream item',\n retryable: false\n })\n\nconst eventsFromOutputItem = (\n item: OpenAiCodexOutputItem\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> => {\n switch (item.type) {\n case 'message': {\n const text = textFromOutputItems([item])\n\n return Effect.succeed(text.length > 0 ? [LLMTextDelta.make({ text })] : [])\n }\n case 'reasoning': {\n const reasoning = reasoningFromOutputItems([item])\n\n return Effect.succeed(\n reasoning.length > 0 ? [LLMReasoningDelta.make({ text: reasoning })] : []\n )\n }\n case 'function_call':\n return parseToolArguments(item.arguments).pipe(\n Effect.map(params => [\n LLMToolCall.make({\n call: ToolCall.make({\n id: item.call_id,\n name: item.name,\n params\n })\n })\n ])\n )\n }\n}\n\nconst eventsFromOutputItemDone = (\n event: Record<string, unknown>\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n if (event.type !== 'response.output_item.done') {\n return []\n }\n\n const item = event.item\n\n if (item === undefined) {\n return yield* Effect.fail(invalidFunctionCallSseItemError())\n }\n\n return yield* decodeOpenAiCodexOutputItem(item).pipe(Effect.flatMap(eventsFromOutputItem))\n })\n\nconst finalResponseToEvents = (\n response: unknown,\n state: OpenAiCodexSseState\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const parsedFinal = yield* decodeOpenAiCodexResponse(response)\n const finalEvents = yield* toLlmEvents(parsedFinal, {\n allowEmptyStop: state.hasTextDelta || state.hasToolCall\n })\n\n const shouldDedupe = state.hasTextDelta || state.hasReasoningDelta || state.hasToolCall\n const dedupedEvents = shouldDedupe\n ? finalEvents.filter(event => {\n if (state.hasTextDelta && event._tag === 'TextDelta') {\n return false\n }\n\n if (state.hasReasoningDelta && event._tag === 'ReasoningDelta') {\n return false\n }\n\n if (state.hasToolCall && event._tag === 'ToolCall') {\n return false\n }\n\n return true\n })\n : finalEvents\n\n if (!state.hasToolCall) {\n return dedupedEvents\n }\n\n return dedupedEvents.map(event =>\n event._tag === 'Done' ? LLMDone.make({ stopReason: 'tool_use' }) : event\n )\n })\n\nconst processSseData = (\n state: OpenAiCodexSseState,\n data: string\n): Effect.Effect<OpenAiCodexSseStep, LLMError> =>\n Effect.gen(function* () {\n const parsed = yield* parseOpenAiCodexSseJson(data)\n\n if (!isRecord(parsed)) {\n return { state, events: [] }\n }\n\n if (\n (parsed.type === 'response.output_text.delta' ||\n parsed.type === 'response.content_part.delta') &&\n typeof parsed.delta === 'string'\n ) {\n return {\n state: { ...state, hasTextDelta: true },\n events: [LLMTextDelta.make({ text: parsed.delta })]\n }\n }\n\n if (\n (parsed.type === 'response.reasoning_summary_text.delta' ||\n parsed.type === 'response.reasoning_text.delta') &&\n typeof parsed.delta === 'string'\n ) {\n return {\n state: { ...state, hasReasoningDelta: true },\n events: [LLMReasoningDelta.make({ text: parsed.delta })]\n }\n }\n\n const outputItemDoneEvents = yield* eventsFromOutputItemDone(parsed)\n if (outputItemDoneEvents.length > 0) {\n const events = outputItemDoneEvents.filter(event => {\n if (state.hasTextDelta && event._tag === 'TextDelta') {\n return false\n }\n\n if (state.hasReasoningDelta && event._tag === 'ReasoningDelta') {\n return false\n }\n\n if (state.hasToolCall && event._tag === 'ToolCall') {\n return false\n }\n\n return true\n })\n\n return {\n state: {\n hasTextDelta: state.hasTextDelta || events.some(event => event._tag === 'TextDelta'),\n hasReasoningDelta:\n state.hasReasoningDelta || events.some(event => event._tag === 'ReasoningDelta'),\n hasToolCall: state.hasToolCall || events.some(event => event._tag === 'ToolCall'),\n hasDone: state.hasDone\n },\n events\n }\n }\n\n if (parsed.type === 'response.completed') {\n const events = yield* finalResponseToEvents(parsed.response, state)\n const emittedText = events.some(event => event._tag === 'TextDelta')\n const emittedReasoning = events.some(event => event._tag === 'ReasoningDelta')\n const emittedToolCall = events.some(event => event._tag === 'ToolCall')\n\n return {\n state: {\n hasTextDelta: state.hasTextDelta || emittedText,\n hasReasoningDelta: state.hasReasoningDelta || emittedReasoning,\n hasToolCall: state.hasToolCall || emittedToolCall,\n hasDone: true\n },\n events\n }\n }\n\n if (parsed.type === 'response.failed') {\n const error = recordField(recordField(parsed, 'response'), 'error')\n const message = stringField(error, 'message') ?? 'OpenAI Codex response failed'\n const providerCode = stringField(error, 'code') ?? stringField(error, 'type')\n\n return yield* Effect.fail(\n providerSignalError({\n message,\n ...(providerCode === undefined ? {} : { providerCode })\n })\n )\n }\n\n if (parsed.type === 'error' && typeof parsed.message === 'string') {\n const providerCode = stringField(parsed, 'code') ?? stringField(parsed, 'type')\n\n return yield* Effect.fail(\n providerSignalError({\n message: parsed.message,\n ...(providerCode === undefined ? {} : { providerCode })\n })\n )\n }\n\n return { state, events: [] }\n })\n\nconst processSseBlock = (\n state: OpenAiCodexSseState,\n block: string\n): Effect.Effect<OpenAiCodexSseStep, LLMError> => {\n const data = dataFromSseBlock(block)\n\n if (data === undefined) {\n return Effect.succeed({ state, events: [] })\n }\n\n return processSseData(state, data)\n}\n\nconst processSseBlocks = (\n state: OpenAiCodexSseState,\n blocks: ReadonlyArray<string>\n): Effect.Effect<OpenAiCodexSseStep, LLMError> =>\n Effect.gen(function* () {\n const events: Array<LLMEvent> = []\n let currentState = state\n\n for (const block of blocks) {\n const step = yield* processSseBlock(currentState, block)\n currentState = step.state\n events.push(...step.events)\n }\n\n return { state: currentState, events }\n })\n\nconst processBodyChunk = (\n state: OpenAiCodexBodyState,\n chunk: string\n): Effect.Effect<OpenAiCodexSseStep & { readonly bodyState: OpenAiCodexBodyState }, LLMError> =>\n Effect.gen(function* () {\n const buffer = normalizeNewlines(`${state.buffer}${chunk}`)\n const format = state.format === 'undecided' ? classifyCodexBody(buffer) : state.format\n\n if (format !== 'sse') {\n return {\n state: state.sse,\n bodyState: { ...state, format, buffer },\n events: []\n }\n }\n\n const split = splitCompleteSseBlocks(buffer)\n const step = yield* processSseBlocks(state.sse, split.completeBlocks)\n\n return {\n state: step.state,\n bodyState: { format, buffer: split.tail, sse: step.state },\n events: step.events\n }\n })\n\nconst finalizeBodyState = (\n state: OpenAiCodexBodyState\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const buffer = normalizeNewlines(state.buffer)\n const format = state.format === 'undecided' ? classifyCodexBody(buffer) : state.format\n\n if (format === 'json') {\n return yield* parseOpenAiCodexJsonResponse(buffer)\n }\n\n const events: Array<LLMEvent> = []\n let sseState = state.sse\n\n if (format === 'sse') {\n const split = splitCompleteSseBlocks(buffer)\n const step = yield* processSseBlocks(sseState, split.completeBlocks)\n sseState = step.state\n events.push(...step.events)\n\n if (split.tail.trim().length > 0) {\n const tailStep = yield* processSseBlock(sseState, split.tail)\n sseState = tailStep.state\n events.push(...tailStep.events)\n }\n }\n\n if (!sseState.hasDone) {\n events.push(LLMDone.make({ stopReason: sseState.hasToolCall ? 'tool_use' : 'stop' }))\n }\n\n return events\n })\n\nconst toHttpClientLlmError =\n (message: string, retryable: boolean, kind: ProviderFailureKind = 'network') =>\n (error: HttpClientError.HttpClientError) =>\n new LLMError({\n cause: 'provider_error',\n message: `${message}: ${error.message}`,\n retryable,\n provider: providerErrorInfo({\n provider: openAiCodexProvider,\n kind: retryable ? kind : 'unknown'\n })\n })\n\nexport const streamOpenAiCodexResponse = (\n response: HttpClientResponse.HttpClientResponse\n): Stream.Stream<LLMEvent, LLMError> =>\n Stream.unwrap(\n Ref.make(initialBodyState).pipe(\n Effect.map(bodyStateRef => {\n const chunks = response.stream.pipe(\n Stream.mapError(\n toHttpClientLlmError('Could not read OpenAI Codex stream', true, 'stream')\n ),\n Stream.decodeText,\n Stream.mapEffect(chunk =>\n Effect.gen(function* () {\n const state = yield* Ref.get(bodyStateRef)\n const step = yield* processBodyChunk(state, chunk)\n yield* Ref.set(bodyStateRef, step.bodyState)\n return step.events\n })\n ),\n Stream.flatMap(events => Stream.fromIterable(events))\n )\n\n const finalEvents = Stream.fromEffect(\n Ref.get(bodyStateRef).pipe(Effect.flatMap(finalizeBodyState))\n ).pipe(Stream.flatMap(events => Stream.fromIterable(events)))\n\n return chunks.pipe(Stream.concat(finalEvents))\n })\n )\n )\n\nconst sendOpenAiCodexRequest = (\n config: OpenAiCodexProviderConfig,\n request: LLMRequest,\n client: HttpClient.HttpClient\n): Effect.Effect<HttpClientResponse.HttpClientResponse, LLMError> =>\n Effect.gen(function* () {\n const body = yield* toOpenAiCodexRequestBody(request, config)\n // Replayed transcripts can carry lone surrogates; harden the lowered\n // body so one bad historical string cannot poison every model call.\n const serializedBody = yield* encodeJsonString(\n replaceLoneSurrogatesDeep(body),\n 'Could not serialize OpenAI Codex request'\n )\n\n const headers: Record<string, string> = {\n accept: 'application/json',\n ...openAiCodexAuthorizationHeaders(config.token),\n 'content-type': 'application/json',\n ...config.extraHeaders\n }\n\n const httpRequest = HttpClientRequest.post(config.responsesUrl ?? openAiCodexResponsesUrl).pipe(\n HttpClientRequest.setHeaders(headers),\n HttpClientRequest.bodyText(serializedBody, 'application/json')\n )\n const response = yield* client\n .execute(httpRequest)\n .pipe(Effect.mapError(toHttpClientLlmError('OpenAI Codex request failed', true)))\n\n if (response.status < 200 || response.status >= 300) {\n const errorText = yield* response.text.pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'provider_error',\n message: `Could not read OpenAI Codex error body: ${error.message}`,\n retryable: false\n })\n )\n )\n\n const provider = classifyProviderFailure({\n provider: openAiCodexProvider,\n status: response.status,\n headers: response.headers,\n body: errorText\n })\n\n return yield* Effect.fail(\n new LLMError({\n cause: providerFailureCause(provider.kind),\n message: `OpenAI Codex returned ${response.status}`,\n retryable: providerFailureRetryable(provider.kind),\n provider\n })\n )\n }\n\n return response\n }).pipe(Effect.withSpan('OpenAiCodexProvider.stream'))\n\nexport const makeOpenAiCodexProviderLayer = (config: OpenAiCodexProviderConfig) =>\n Layer.effect(LLMProvider)(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n\n return LLMProvider.of({\n stream: request =>\n Stream.fromEffect(sendOpenAiCodexRequest(config, request, client)).pipe(\n Stream.flatMap(streamOpenAiCodexResponse)\n )\n })\n })\n )\n"],"mappings":";;;;;;;;;AAuIA,IAAM,kCAAN,cAA8C,OAAO,MACnD,iCACF,EAAE;CACA,MAAM,OAAO,SAAS,CAAC,cAAc,CAAC;CACtC,MAAM,OAAO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OAAO,SAAS,qBAAqB,+BAA+B,IAAI,CAAC,CAAC;CAElF,IAAI,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;EACnD,MAAM,YAAY,OAAO,SAAS,KAAK,KACrC,OAAO,UACL,UACE,IAAI,SAAS;GACX,OAAO;GACP,SAAS,2CAA2C,MAAM;GAC1D,WAAW;EACb,CAAC,CACL,CACF;EAEA,MAAM,WAAW,wBAAwB;GACvC,UAAU;GACV,QAAQ,SAAS;GACjB,SAAS,SAAS;GAClB,MAAM;EACR,CAAC;EAED,OAAO,OAAO,OAAO,KACnB,IAAI,SAAS;GACX,OAAO,qBAAqB,SAAS,IAAI;GACzC,SAAS,yBAAyB,SAAS;GAC3C,WAAW,yBAAyB,SAAS,IAAI;GACjD;EACF,CAAC,CACH;CACF;CAEA,OAAO;AACT,CAAC,EAAE,KAAK,OAAO,SAAS,4BAA4B,CAAC;AAEvD,MAAa,gCAAgC,WAC3C,MAAM,OAAO,WAAW,EACtB,OAAO,IAAI,aAAa;CACtB,MAAM,SAAS,OAAO,WAAW;CAEjC,OAAO,YAAY,GAAG,EACpB,SAAQ,YACN,OAAO,WAAW,uBAAuB,QAAQ,SAAS,MAAM,CAAC,EAAE,KACjE,OAAO,QAAQ,yBAAyB,CAC1C,EACJ,CAAC;AACH,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"codex-provider.mjs","names":["Arr","LLMReasoningDelta","LLMTextDelta"],"sources":["../../../src/providers/openai/codex-provider.ts"],"sourcesContent":["import { Array as Arr, Effect, Layer, Option, Ref, Stream } from 'effect'\nimport {\n HttpClient,\n HttpClientRequest,\n type HttpClientError,\n type HttpClientResponse\n} from 'effect/unstable/http'\nimport * as Schema from 'effect/Schema'\nimport {\n AgentInputUsage,\n AgentOutputUsage,\n AgentUsage,\n ToolCall,\n attachmentSourceDataUrl,\n attachmentSourceUrl,\n assistantContent,\n assistantHostToolCalls,\n contentParts,\n messageContextText,\n replaceLoneSurrogatesDeep,\n prependMessageContextToContent,\n type AgentMessage,\n type AgentReasoningEffort,\n type Content,\n type ContentPart,\n type ProviderFailureKind,\n type ToolDef\n} from '@yolk-sdk/agent/protocol'\nimport {\n LLMError,\n LLMDone,\n LLMProvider,\n LLMReasoningDelta,\n LLMTextDelta,\n LLMToolCall,\n LLMUsage,\n type LLMEvent,\n type LLMRequest\n} from '@yolk-sdk/agent/loop'\nimport { openAiCodexAuthorizationHeaders, openAiCodexResponsesUrl } from './codex.ts'\nimport type { OAuthAccessToken } from '@yolk-sdk/agent/oauth'\nimport {\n classifyProviderFailure,\n providerErrorInfo,\n providerFailureCause,\n providerFailureRetryable\n} from '../provider-error.ts'\nimport { validateProviderTranscript } from '../transcript.ts'\n\nexport type OpenAiCodexReasoningSummary = 'auto' | 'concise' | 'detailed'\n\nexport type OpenAiCodexProviderConfig = {\n readonly token: OAuthAccessToken\n readonly responsesUrl?: string\n readonly extraHeaders?: Readonly<Record<string, string>>\n readonly defaultReasoningEffort?: AgentReasoningEffort\n readonly reasoningSummary?: OpenAiCodexReasoningSummary\n}\n\ntype OpenAiCodexMessageInput = {\n readonly role: 'user' | 'assistant'\n readonly content: string | ReadonlyArray<OpenAiCodexInputContentPart>\n}\n\ntype OpenAiCodexInputTextPart = {\n readonly type: 'input_text'\n readonly text: string\n}\n\ntype OpenAiCodexInputImagePart = {\n readonly type: 'input_image'\n readonly image_url: string\n}\n\ntype OpenAiCodexInputFilePart =\n | {\n readonly type: 'input_file'\n readonly filename: string\n readonly file_data: string\n }\n | {\n readonly type: 'input_file'\n readonly file_url: string\n }\n\ntype OpenAiCodexInputContentPart =\n | OpenAiCodexInputTextPart\n | OpenAiCodexInputImagePart\n | OpenAiCodexInputFilePart\n\ntype OpenAiCodexFunctionOutput = string | ReadonlyArray<OpenAiCodexInputContentPart>\n\ntype OpenAiCodexFunctionCallInput = {\n readonly type: 'function_call'\n readonly call_id: string\n readonly name: string\n readonly arguments: string\n}\n\ntype OpenAiCodexFunctionOutputInput = {\n readonly type: 'function_call_output'\n readonly call_id: string\n readonly output: OpenAiCodexFunctionOutput\n}\n\ntype OpenAiCodexInputItem =\n | OpenAiCodexMessageInput\n | OpenAiCodexFunctionCallInput\n | OpenAiCodexFunctionOutputInput\n\ntype OpenAiCodexTool = {\n readonly type: 'function'\n readonly name: string\n readonly description: string\n readonly parameters: unknown\n}\n\ntype OpenAiCodexRequestBody = {\n readonly model: string\n readonly instructions: string\n readonly input: ReadonlyArray<OpenAiCodexInputItem>\n readonly store: false\n readonly stream: true\n readonly reasoning: {\n readonly effort: AgentReasoningEffort\n readonly summary: OpenAiCodexReasoningSummary\n }\n readonly tools?: ReadonlyArray<OpenAiCodexTool>\n readonly parallel_tool_calls?: true\n}\n\nclass OpenAiCodexReasoningSummaryText extends Schema.Class<OpenAiCodexReasoningSummaryText>(\n 'OpenAiCodexReasoningSummaryText'\n)({\n type: Schema.Literals(['summary_text']),\n text: Schema.String\n}) {}\n\nclass OpenAiCodexReasoningText extends Schema.Class<OpenAiCodexReasoningText>(\n 'OpenAiCodexReasoningText'\n)({\n type: Schema.Literals(['reasoning_text']),\n text: Schema.String\n}) {}\n\nclass OpenAiCodexOutputText extends Schema.Class<OpenAiCodexOutputText>('OpenAiCodexOutputText')({\n type: Schema.Literals(['output_text']),\n text: Schema.String\n}) {}\n\nclass OpenAiCodexMessageOutput extends Schema.Class<OpenAiCodexMessageOutput>(\n 'OpenAiCodexMessageOutput'\n)({\n type: Schema.Literals(['message']),\n content: Schema.Array(OpenAiCodexOutputText)\n}) {}\n\nclass OpenAiCodexFunctionCallOutput extends Schema.Class<OpenAiCodexFunctionCallOutput>(\n 'OpenAiCodexFunctionCallOutput'\n)({\n type: Schema.Literals(['function_call']),\n call_id: Schema.String,\n name: Schema.String,\n arguments: Schema.String\n}) {}\n\nclass OpenAiCodexReasoningOutput extends Schema.Class<OpenAiCodexReasoningOutput>(\n 'OpenAiCodexReasoningOutput'\n)({\n type: Schema.Literals(['reasoning']),\n summary: Schema.optional(Schema.Array(OpenAiCodexReasoningSummaryText)),\n content: Schema.optional(Schema.Array(OpenAiCodexReasoningText))\n}) {}\n\nclass OpenAiCodexInputTokensDetails extends Schema.Class<OpenAiCodexInputTokensDetails>(\n 'OpenAiCodexInputTokensDetails'\n)({\n cached_tokens: Schema.optional(Schema.Number)\n}) {}\n\nclass OpenAiCodexOutputTokensDetails extends Schema.Class<OpenAiCodexOutputTokensDetails>(\n 'OpenAiCodexOutputTokensDetails'\n)({\n reasoning_tokens: Schema.optional(Schema.Number)\n}) {}\n\nclass OpenAiCodexUsageResponse extends Schema.Class<OpenAiCodexUsageResponse>(\n 'OpenAiCodexUsageResponse'\n)({\n input_tokens: Schema.Number,\n output_tokens: Schema.Number,\n input_tokens_details: Schema.optional(OpenAiCodexInputTokensDetails),\n output_tokens_details: Schema.optional(OpenAiCodexOutputTokensDetails)\n}) {}\n\nconst OpenAiCodexOutputItem = Schema.Union([\n OpenAiCodexMessageOutput,\n OpenAiCodexFunctionCallOutput,\n OpenAiCodexReasoningOutput\n])\ntype OpenAiCodexOutputItem = typeof OpenAiCodexOutputItem.Type\n\nclass OpenAiCodexResponse extends Schema.Class<OpenAiCodexResponse>('OpenAiCodexResponse')({\n output_text: Schema.optional(Schema.String),\n output: Schema.Array(OpenAiCodexOutputItem),\n usage: Schema.optional(OpenAiCodexUsageResponse)\n}) {}\n\nconst unknownToMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error)\n\nconst encodeJsonString = (value: unknown, message: string) =>\n Schema.encodeUnknownEffect(Schema.UnknownFromJsonString)(value).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'provider_error',\n message: `${message}: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst decodeJsonString = (raw: string, message: string) =>\n Schema.decodeUnknownEffect(Schema.UnknownFromJsonString)(raw).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'invalid_response',\n message: `${message}: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst unsupportedContentError = (contentType: string) =>\n new LLMError({\n cause: 'provider_error',\n message: `${contentType} content is not supported by the OpenAI Codex OAuth provider yet`,\n retryable: false\n })\n\nconst contentPartToText = (part: ContentPart, owner: string): Effect.Effect<string, LLMError> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed(part.text)\n case 'Image':\n return Effect.fail(unsupportedContentError(`${owner} image`))\n case 'Document':\n return Effect.fail(unsupportedContentError(`${owner} document`))\n case 'Audio':\n return Effect.fail(unsupportedContentError(`${owner} audio`))\n }\n}\n\nconst contentToText = (content: Content, owner: string): Effect.Effect<string, LLMError> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, part => contentPartToText(part, owner)).pipe(\n Effect.map(textParts => textParts.join('\\n'))\n )\n\nconst contentPartToCodexInputPart = (\n part: ContentPart\n): Effect.Effect<\n OpenAiCodexInputTextPart | OpenAiCodexInputImagePart | OpenAiCodexInputFilePart,\n LLMError\n> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed({ type: 'input_text', text: part.text })\n case 'Image':\n return Option.match(attachmentSourceUrl(part.source, part.mimeType), {\n onNone: () => Effect.fail(unsupportedContentError('Unresolved image source')),\n onSome: url =>\n Effect.succeed({\n type: 'input_image',\n image_url: url\n })\n })\n case 'Document':\n switch (part.source._tag) {\n case 'InlineBase64':\n return Option.match(attachmentSourceDataUrl(part.source, part.mimeType), {\n onNone: () => Effect.fail(unsupportedContentError('Invalid document source')),\n onSome: url =>\n Effect.succeed({\n type: 'input_file',\n filename: part.filename,\n file_data: url\n })\n })\n case 'Url':\n return Effect.succeed({ type: 'input_file', file_url: part.source.url })\n case 'Ref':\n return Effect.fail(unsupportedContentError('Unresolved document source'))\n }\n case 'Audio':\n return Effect.fail(unsupportedContentError('Audio'))\n }\n}\n\nconst contentToUserInput = (\n content: Content\n): Effect.Effect<OpenAiCodexMessageInput['content'], LLMError> => {\n if (typeof content === 'string') {\n return Effect.succeed(content)\n }\n\n const parts = contentParts(content)\n const onlyPart = parts[0]\n\n if (onlyPart !== undefined && parts.length === 1 && onlyPart._tag === 'Text') {\n return Effect.succeed(onlyPart.text)\n }\n\n return Effect.forEach(parts, contentPartToCodexInputPart)\n}\n\nconst contentToCodexFunctionOutput = (\n content: Content\n): Effect.Effect<OpenAiCodexFunctionOutput, LLMError> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, contentPartToCodexInputPart)\n\nconst codexToolResultOutput = (\n content: Content,\n isError: boolean | undefined\n): Effect.Effect<OpenAiCodexFunctionOutput, LLMError> =>\n contentToCodexFunctionOutput(content).pipe(\n Effect.map(output => {\n if (isError !== true) return output\n\n const errorPart: OpenAiCodexInputTextPart = {\n type: 'input_text',\n text: 'Tool execution failed.'\n }\n\n return typeof output === 'string' ? `${errorPart.text}\\n\\n${output}` : [errorPart, ...output]\n })\n )\n\nconst serializeToolArguments = (params: unknown) =>\n encodeJsonString(params, 'Could not serialize OpenAI Codex tool arguments')\n\nconst toolCallToCodexInput = (\n call: ToolCall\n): Effect.Effect<OpenAiCodexFunctionCallInput, LLMError> =>\n Effect.gen(function* () {\n return {\n type: 'function_call',\n call_id: call.id,\n name: call.name,\n arguments: yield* serializeToolArguments(call.params)\n }\n })\n\nconst messageToCodexInput = (\n message: AgentMessage\n): Effect.Effect<ReadonlyArray<OpenAiCodexInputItem>, LLMError> =>\n Effect.gen(function* () {\n switch (message._tag) {\n case 'User':\n return [\n {\n role: 'user',\n content: yield* contentToUserInput(\n prependMessageContextToContent(message.content, messageContextText(message))\n )\n }\n ]\n case 'Assistant': {\n const content = yield* contentToText(\n prependMessageContextToContent(assistantContent(message), messageContextText(message)),\n 'Assistant'\n )\n const toolCallInputs = yield* Effect.forEach(\n assistantHostToolCalls(message),\n toolCallToCodexInput\n )\n\n if (content.length > 0) {\n const assistantMessage: OpenAiCodexInputItem = { role: 'assistant', content }\n\n return [assistantMessage, ...toolCallInputs]\n }\n\n return toolCallInputs\n }\n case 'ToolResult':\n return [\n {\n type: 'function_call_output',\n call_id: message.toolCallId,\n output: yield* codexToolResultOutput(\n prependMessageContextToContent(message.content, messageContextText(message)),\n message.isError\n )\n }\n ]\n }\n })\n\nconst toOpenAiCodexTool = (tool: ToolDef): OpenAiCodexTool => ({\n type: 'function',\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters\n})\n\nexport const toOpenAiCodexRequestBody = (\n request: LLMRequest,\n config?: {\n readonly defaultReasoningEffort?: AgentReasoningEffort\n readonly reasoningSummary?: OpenAiCodexReasoningSummary\n }\n): Effect.Effect<OpenAiCodexRequestBody, LLMError> =>\n Effect.gen(function* () {\n yield* validateProviderTranscript(request.messages)\n const input = Arr.flatten(yield* Effect.forEach(request.messages, messageToCodexInput))\n\n const body: Omit<OpenAiCodexRequestBody, 'tools'> = {\n model: request.model,\n instructions: request.systemPrompt,\n input,\n store: false,\n stream: true,\n reasoning: {\n effort: request.reasoningEffort ?? config?.defaultReasoningEffort ?? 'low',\n summary: config?.reasoningSummary ?? 'auto'\n }\n }\n\n if (request.tools.length === 0) {\n return body\n }\n\n return {\n ...body,\n tools: request.tools.map(toOpenAiCodexTool),\n parallel_tool_calls: true\n }\n })\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n\nconst stringField = (value: unknown, key: string) => {\n if (!isRecord(value)) {\n return undefined\n }\n\n const field = Object.getOwnPropertyDescriptor(value, key)?.value\n\n return typeof field === 'string' ? field : undefined\n}\n\nconst recordField = (value: unknown, key: string) => {\n if (!isRecord(value)) {\n return undefined\n }\n\n const field = Object.getOwnPropertyDescriptor(value, key)?.value\n\n return isRecord(field) ? field : undefined\n}\n\nconst openAiCodexProvider = 'openai_codex'\n\nconst providerSignalError = (input: {\n readonly message: string\n readonly providerCode?: string\n readonly fallbackKind?: ProviderFailureKind\n}) => {\n const provider = classifyProviderFailure({\n provider: openAiCodexProvider,\n message: input.message,\n ...(input.providerCode === undefined ? {} : { providerCode: input.providerCode }),\n ...(input.fallbackKind === undefined ? {} : { fallbackKind: input.fallbackKind })\n })\n\n return new LLMError({\n cause: providerFailureCause(provider.kind),\n message: `OpenAI Codex stream error: ${input.message}`,\n retryable: providerFailureRetryable(provider.kind),\n provider\n })\n}\n\nconst parseToolArguments = (raw: string) =>\n decodeJsonString(raw, 'Invalid OpenAI Codex tool arguments JSON')\n\nconst textFromOutputItem = (item: OpenAiCodexOutputItem) => {\n switch (item.type) {\n case 'message':\n return Arr.map(item.content, content => content.text)\n case 'function_call':\n case 'reasoning':\n return []\n }\n}\n\nconst textFromOutputItems = (items: ReadonlyArray<OpenAiCodexOutputItem>) => {\n const textParts = Arr.flatten(Arr.map(items, textFromOutputItem))\n\n return textParts.join('')\n}\n\nconst reasoningFromOutputItem = (item: OpenAiCodexOutputItem) => {\n switch (item.type) {\n case 'reasoning':\n return [\n ...(item.summary ?? []).map(summary => summary.text),\n ...(item.content ?? []).map(content => content.text)\n ]\n case 'message':\n case 'function_call':\n return []\n }\n}\n\nconst reasoningFromOutputItems = (items: ReadonlyArray<OpenAiCodexOutputItem>) => {\n const reasoningParts = Arr.flatten(Arr.map(items, reasoningFromOutputItem))\n\n return reasoningParts.join('')\n}\n\nconst toAgentUsage = (usage: OpenAiCodexUsageResponse) =>\n AgentUsage.make({\n input: AgentInputUsage.make({\n total: usage.input_tokens,\n uncached: usage.input_tokens - (usage.input_tokens_details?.cached_tokens ?? 0),\n cacheRead: usage.input_tokens_details?.cached_tokens\n }),\n output: AgentOutputUsage.make({\n total: usage.output_tokens,\n reasoning: usage.output_tokens_details?.reasoning_tokens,\n text: usage.output_tokens - (usage.output_tokens_details?.reasoning_tokens ?? 0)\n })\n })\n\ntype ToLlmEventsOptions = {\n readonly allowEmptyStop: boolean\n}\n\nconst toLlmEvents = (\n response: OpenAiCodexResponse,\n options: ToLlmEventsOptions\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const text = response.output_text ?? textFromOutputItems(response.output)\n const reasoning = reasoningFromOutputItems(response.output)\n const reasoningEvents =\n reasoning.length > 0 ? [LLMReasoningDelta.make({ text: reasoning })] : []\n const textEvents = text.length > 0 ? [LLMTextDelta.make({ text })] : []\n const toolCallEvents = Arr.getSomes(\n yield* Effect.forEach(response.output, item => {\n switch (item.type) {\n case 'message':\n case 'reasoning':\n return Effect.succeed(Option.none())\n case 'function_call':\n return parseToolArguments(item.arguments).pipe(\n Effect.map(params =>\n Option.some(\n LLMToolCall.make({\n call: ToolCall.make({\n id: item.call_id,\n name: item.name,\n params\n })\n })\n )\n )\n )\n }\n })\n )\n\n if (textEvents.length === 0 && toolCallEvents.length === 0 && !options.allowEmptyStop) {\n return yield* Effect.fail(\n new LLMError({\n cause: 'invalid_response',\n message: 'OpenAI Codex response did not include text or tool calls',\n retryable: false\n })\n )\n }\n\n const events: Array<LLMEvent> = [\n ...reasoningEvents,\n ...textEvents,\n ...toolCallEvents,\n LLMDone.make({ stopReason: toolCallEvents.length > 0 ? 'tool_use' : 'stop' })\n ]\n\n if (response.usage !== undefined) {\n events.push(LLMUsage.make({ usage: toAgentUsage(response.usage) }))\n }\n\n return events\n })\n\nconst decodeOpenAiCodexResponse = (json: unknown) =>\n Schema.decodeUnknownEffect(OpenAiCodexResponse)(json).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'invalid_response',\n message: `Invalid OpenAI Codex response: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst parseOpenAiCodexJsonResponse = (\n raw: string\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const json = yield* decodeJsonString(raw, 'Could not parse OpenAI Codex response JSON')\n const parsed = yield* decodeOpenAiCodexResponse(json)\n\n return yield* toLlmEvents(parsed, { allowEmptyStop: false })\n })\n\ntype OpenAiCodexBodyFormat = 'undecided' | 'sse' | 'json'\n\ntype OpenAiCodexSseState = {\n readonly hasTextDelta: boolean\n readonly hasReasoningDelta: boolean\n readonly hasToolCall: boolean\n readonly hasDone: boolean\n}\n\ntype OpenAiCodexSseStep = {\n readonly state: OpenAiCodexSseState\n readonly events: ReadonlyArray<LLMEvent>\n}\n\ntype OpenAiCodexBodyState = {\n readonly format: OpenAiCodexBodyFormat\n readonly buffer: string\n readonly sse: OpenAiCodexSseState\n}\n\nconst initialSseState: OpenAiCodexSseState = {\n hasTextDelta: false,\n hasReasoningDelta: false,\n hasToolCall: false,\n hasDone: false\n}\n\nconst initialBodyState: OpenAiCodexBodyState = {\n format: 'undecided',\n buffer: '',\n sse: initialSseState\n}\n\nconst normalizeNewlines = (text: string) => text.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n')\n\nconst classifyCodexBody = (buffer: string): OpenAiCodexBodyFormat => {\n const trimmed = buffer.trimStart()\n\n if (trimmed.length === 0) {\n return 'undecided'\n }\n\n if (trimmed.startsWith('event:') || trimmed.startsWith('data:')) {\n return 'sse'\n }\n\n if ('event:'.startsWith(trimmed) || 'data:'.startsWith(trimmed)) {\n return 'undecided'\n }\n\n return 'json'\n}\n\nconst splitCompleteSseBlocks = (buffer: string) => {\n const blocks = buffer.split('\\n\\n')\n const tail = blocks.at(-1) ?? ''\n\n return { completeBlocks: blocks.slice(0, -1), tail }\n}\n\nconst dataFromSseBlock = (block: string) => {\n const lines = Arr.map(\n Arr.filter(block.split('\\n'), line => line.startsWith('data:')),\n line => line.slice(5).trimStart()\n )\n\n const data = lines.join('\\n').trim()\n\n if (data.length === 0 || data === '[DONE]') {\n return undefined\n }\n\n return data\n}\n\nconst parseOpenAiCodexSseJson = (data: string) =>\n decodeJsonString(data, 'Could not parse OpenAI Codex stream event JSON')\n\nconst decodeOpenAiCodexOutputItem = (value: unknown) =>\n Schema.decodeUnknownEffect(OpenAiCodexOutputItem)(value).pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'invalid_response',\n message: `Invalid OpenAI Codex output item: ${unknownToMessage(error)}`,\n retryable: false\n })\n )\n )\n\nconst invalidFunctionCallSseItemError = () =>\n new LLMError({\n cause: 'invalid_response',\n message: 'Invalid OpenAI Codex function call stream item',\n retryable: false\n })\n\nconst eventsFromOutputItem = (\n item: OpenAiCodexOutputItem\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> => {\n switch (item.type) {\n case 'message': {\n const text = textFromOutputItems([item])\n\n return Effect.succeed(text.length > 0 ? [LLMTextDelta.make({ text })] : [])\n }\n case 'reasoning': {\n const reasoning = reasoningFromOutputItems([item])\n\n return Effect.succeed(\n reasoning.length > 0 ? [LLMReasoningDelta.make({ text: reasoning })] : []\n )\n }\n case 'function_call':\n return parseToolArguments(item.arguments).pipe(\n Effect.map(params => [\n LLMToolCall.make({\n call: ToolCall.make({\n id: item.call_id,\n name: item.name,\n params\n })\n })\n ])\n )\n }\n}\n\nconst eventsFromOutputItemDone = (\n event: Record<string, unknown>\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n if (event.type !== 'response.output_item.done') {\n return []\n }\n\n const item = event.item\n\n if (item === undefined) {\n return yield* Effect.fail(invalidFunctionCallSseItemError())\n }\n\n return yield* decodeOpenAiCodexOutputItem(item).pipe(Effect.flatMap(eventsFromOutputItem))\n })\n\nconst finalResponseToEvents = (\n response: unknown,\n state: OpenAiCodexSseState\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const parsedFinal = yield* decodeOpenAiCodexResponse(response)\n const finalEvents = yield* toLlmEvents(parsedFinal, {\n allowEmptyStop: state.hasTextDelta || state.hasToolCall\n })\n\n const shouldDedupe = state.hasTextDelta || state.hasReasoningDelta || state.hasToolCall\n const dedupedEvents = shouldDedupe\n ? finalEvents.filter(event => {\n if (state.hasTextDelta && event._tag === 'TextDelta') {\n return false\n }\n\n if (state.hasReasoningDelta && event._tag === 'ReasoningDelta') {\n return false\n }\n\n if (state.hasToolCall && event._tag === 'ToolCall') {\n return false\n }\n\n return true\n })\n : finalEvents\n\n if (!state.hasToolCall) {\n return dedupedEvents\n }\n\n return dedupedEvents.map(event =>\n event._tag === 'Done' ? LLMDone.make({ stopReason: 'tool_use' }) : event\n )\n })\n\nconst processSseData = (\n state: OpenAiCodexSseState,\n data: string\n): Effect.Effect<OpenAiCodexSseStep, LLMError> =>\n Effect.gen(function* () {\n const parsed = yield* parseOpenAiCodexSseJson(data)\n\n if (!isRecord(parsed)) {\n return { state, events: [] }\n }\n\n if (\n (parsed.type === 'response.output_text.delta' ||\n parsed.type === 'response.content_part.delta') &&\n typeof parsed.delta === 'string'\n ) {\n return {\n state: { ...state, hasTextDelta: true },\n events: [LLMTextDelta.make({ text: parsed.delta })]\n }\n }\n\n if (\n (parsed.type === 'response.reasoning_summary_text.delta' ||\n parsed.type === 'response.reasoning_text.delta') &&\n typeof parsed.delta === 'string'\n ) {\n return {\n state: { ...state, hasReasoningDelta: true },\n events: [LLMReasoningDelta.make({ text: parsed.delta })]\n }\n }\n\n const outputItemDoneEvents = yield* eventsFromOutputItemDone(parsed)\n if (outputItemDoneEvents.length > 0) {\n const events = outputItemDoneEvents.filter(event => {\n if (state.hasTextDelta && event._tag === 'TextDelta') {\n return false\n }\n\n if (state.hasReasoningDelta && event._tag === 'ReasoningDelta') {\n return false\n }\n\n if (state.hasToolCall && event._tag === 'ToolCall') {\n return false\n }\n\n return true\n })\n\n return {\n state: {\n hasTextDelta: state.hasTextDelta || events.some(event => event._tag === 'TextDelta'),\n hasReasoningDelta:\n state.hasReasoningDelta || events.some(event => event._tag === 'ReasoningDelta'),\n hasToolCall: state.hasToolCall || events.some(event => event._tag === 'ToolCall'),\n hasDone: state.hasDone\n },\n events\n }\n }\n\n if (parsed.type === 'response.completed') {\n const events = yield* finalResponseToEvents(parsed.response, state)\n const emittedText = events.some(event => event._tag === 'TextDelta')\n const emittedReasoning = events.some(event => event._tag === 'ReasoningDelta')\n const emittedToolCall = events.some(event => event._tag === 'ToolCall')\n\n return {\n state: {\n hasTextDelta: state.hasTextDelta || emittedText,\n hasReasoningDelta: state.hasReasoningDelta || emittedReasoning,\n hasToolCall: state.hasToolCall || emittedToolCall,\n hasDone: true\n },\n events\n }\n }\n\n if (parsed.type === 'response.failed') {\n const error = recordField(recordField(parsed, 'response'), 'error')\n const message = stringField(error, 'message') ?? 'OpenAI Codex response failed'\n const providerCode = stringField(error, 'code') ?? stringField(error, 'type')\n\n return yield* Effect.fail(\n providerSignalError({\n message,\n ...(providerCode === undefined ? {} : { providerCode })\n })\n )\n }\n\n if (parsed.type === 'error' && typeof parsed.message === 'string') {\n const providerCode = stringField(parsed, 'code') ?? stringField(parsed, 'type')\n\n return yield* Effect.fail(\n providerSignalError({\n message: parsed.message,\n ...(providerCode === undefined ? {} : { providerCode })\n })\n )\n }\n\n return { state, events: [] }\n })\n\nconst processSseBlock = (\n state: OpenAiCodexSseState,\n block: string\n): Effect.Effect<OpenAiCodexSseStep, LLMError> => {\n const data = dataFromSseBlock(block)\n\n if (data === undefined) {\n return Effect.succeed({ state, events: [] })\n }\n\n return processSseData(state, data)\n}\n\nconst processSseBlocks = (\n state: OpenAiCodexSseState,\n blocks: ReadonlyArray<string>\n): Effect.Effect<OpenAiCodexSseStep, LLMError> =>\n Effect.gen(function* () {\n const events: Array<LLMEvent> = []\n let currentState = state\n\n for (const block of blocks) {\n const step = yield* processSseBlock(currentState, block)\n currentState = step.state\n events.push(...step.events)\n }\n\n return { state: currentState, events }\n })\n\nconst processBodyChunk = (\n state: OpenAiCodexBodyState,\n chunk: string\n): Effect.Effect<OpenAiCodexSseStep & { readonly bodyState: OpenAiCodexBodyState }, LLMError> =>\n Effect.gen(function* () {\n const buffer = normalizeNewlines(`${state.buffer}${chunk}`)\n const format = state.format === 'undecided' ? classifyCodexBody(buffer) : state.format\n\n if (format !== 'sse') {\n return {\n state: state.sse,\n bodyState: { ...state, format, buffer },\n events: []\n }\n }\n\n const split = splitCompleteSseBlocks(buffer)\n const step = yield* processSseBlocks(state.sse, split.completeBlocks)\n\n return {\n state: step.state,\n bodyState: { format, buffer: split.tail, sse: step.state },\n events: step.events\n }\n })\n\nconst finalizeBodyState = (\n state: OpenAiCodexBodyState\n): Effect.Effect<ReadonlyArray<LLMEvent>, LLMError> =>\n Effect.gen(function* () {\n const buffer = normalizeNewlines(state.buffer)\n const format = state.format === 'undecided' ? classifyCodexBody(buffer) : state.format\n\n if (format === 'json') {\n return yield* parseOpenAiCodexJsonResponse(buffer)\n }\n\n const events: Array<LLMEvent> = []\n let sseState = state.sse\n\n if (format === 'sse') {\n const split = splitCompleteSseBlocks(buffer)\n const step = yield* processSseBlocks(sseState, split.completeBlocks)\n sseState = step.state\n events.push(...step.events)\n\n if (split.tail.trim().length > 0) {\n const tailStep = yield* processSseBlock(sseState, split.tail)\n sseState = tailStep.state\n events.push(...tailStep.events)\n }\n }\n\n if (!sseState.hasDone) {\n events.push(LLMDone.make({ stopReason: sseState.hasToolCall ? 'tool_use' : 'stop' }))\n }\n\n return events\n })\n\nconst toHttpClientLlmError =\n (message: string, retryable: boolean, kind: ProviderFailureKind = 'network') =>\n (error: HttpClientError.HttpClientError) =>\n new LLMError({\n cause: 'provider_error',\n message: `${message}: ${error.message}`,\n retryable,\n provider: providerErrorInfo({\n provider: openAiCodexProvider,\n kind: retryable ? kind : 'unknown'\n })\n })\n\nexport const streamOpenAiCodexResponse = (\n response: HttpClientResponse.HttpClientResponse\n): Stream.Stream<LLMEvent, LLMError> =>\n Stream.unwrap(\n Ref.make(initialBodyState).pipe(\n Effect.map(bodyStateRef => {\n const chunks = response.stream.pipe(\n Stream.mapError(\n toHttpClientLlmError('Could not read OpenAI Codex stream', true, 'stream')\n ),\n Stream.decodeText,\n Stream.mapEffect(chunk =>\n Effect.gen(function* () {\n const state = yield* Ref.get(bodyStateRef)\n const step = yield* processBodyChunk(state, chunk)\n yield* Ref.set(bodyStateRef, step.bodyState)\n return step.events\n })\n ),\n Stream.flatMap(events => Stream.fromIterable(events))\n )\n\n const finalEvents = Stream.fromEffect(\n Ref.get(bodyStateRef).pipe(Effect.flatMap(finalizeBodyState))\n ).pipe(Stream.flatMap(events => Stream.fromIterable(events)))\n\n return chunks.pipe(Stream.concat(finalEvents))\n })\n )\n )\n\nconst sendOpenAiCodexRequest = (\n config: OpenAiCodexProviderConfig,\n request: LLMRequest,\n client: HttpClient.HttpClient\n): Effect.Effect<HttpClientResponse.HttpClientResponse, LLMError> =>\n Effect.gen(function* () {\n const body = yield* toOpenAiCodexRequestBody(request, config)\n // Replayed transcripts can carry lone surrogates; harden the lowered\n // body so one bad historical string cannot poison every model call.\n const serializedBody = yield* encodeJsonString(\n replaceLoneSurrogatesDeep(body),\n 'Could not serialize OpenAI Codex request'\n )\n\n const headers: Record<string, string> = {\n accept: 'application/json',\n ...openAiCodexAuthorizationHeaders(config.token),\n 'content-type': 'application/json',\n ...config.extraHeaders\n }\n\n const httpRequest = HttpClientRequest.post(config.responsesUrl ?? openAiCodexResponsesUrl).pipe(\n HttpClientRequest.setHeaders(headers),\n HttpClientRequest.bodyText(serializedBody, 'application/json')\n )\n const response = yield* client\n .execute(httpRequest)\n .pipe(Effect.mapError(toHttpClientLlmError('OpenAI Codex request failed', true)))\n\n if (response.status < 200 || response.status >= 300) {\n const errorText = yield* response.text.pipe(\n Effect.mapError(\n error =>\n new LLMError({\n cause: 'provider_error',\n message: `Could not read OpenAI Codex error body: ${error.message}`,\n retryable: false\n })\n )\n )\n\n const provider = classifyProviderFailure({\n provider: openAiCodexProvider,\n status: response.status,\n headers: response.headers,\n body: errorText\n })\n\n return yield* Effect.fail(\n new LLMError({\n cause: providerFailureCause(provider.kind),\n message: `OpenAI Codex returned ${response.status}`,\n retryable: providerFailureRetryable(provider.kind),\n provider\n })\n )\n }\n\n return response\n }).pipe(Effect.withSpan('OpenAiCodexProvider.stream'))\n\nexport const makeOpenAiCodexProviderLayer = (config: OpenAiCodexProviderConfig) =>\n Layer.effect(LLMProvider)(\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient\n\n return LLMProvider.of({\n stream: request =>\n Stream.fromEffect(sendOpenAiCodexRequest(config, request, client)).pipe(\n Stream.flatMap(streamOp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uB,QAAQ,SAAS,MAAM,CAAC,EAAE,KACjE,OAAO,QAAQ,yBAAyB,CAC1C,EACJ,CAAC;AACH,CAAC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolk-sdk/agent",
|
|
3
|
-
"version": "0.1.0-canary.
|
|
3
|
+
"version": "0.1.0-canary.45",
|
|
4
4
|
"description": "Protocol, loop, runtime, client, compaction, tools, React, providers, OAuth, skillset, and voice primitives for building Yolk agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -83,16 +83,12 @@ type OpenAiCodexInputFilePart =
|
|
|
83
83
|
readonly file_url: string
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
type OpenAiCodexOutputTextPart = {
|
|
87
|
-
readonly type: 'output_text'
|
|
88
|
-
readonly text: string
|
|
89
|
-
}
|
|
90
|
-
|
|
91
86
|
type OpenAiCodexInputContentPart =
|
|
92
87
|
| OpenAiCodexInputTextPart
|
|
93
88
|
| OpenAiCodexInputImagePart
|
|
94
89
|
| OpenAiCodexInputFilePart
|
|
95
|
-
|
|
90
|
+
|
|
91
|
+
type OpenAiCodexFunctionOutput = string | ReadonlyArray<OpenAiCodexInputContentPart>
|
|
96
92
|
|
|
97
93
|
type OpenAiCodexFunctionCallInput = {
|
|
98
94
|
readonly type: 'function_call'
|
|
@@ -104,7 +100,7 @@ type OpenAiCodexFunctionCallInput = {
|
|
|
104
100
|
type OpenAiCodexFunctionOutputInput = {
|
|
105
101
|
readonly type: 'function_call_output'
|
|
106
102
|
readonly call_id: string
|
|
107
|
-
readonly output:
|
|
103
|
+
readonly output: OpenAiCodexFunctionOutput
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
type OpenAiCodexInputItem =
|
|
@@ -264,7 +260,7 @@ const contentToText = (content: Content, owner: string): Effect.Effect<string, L
|
|
|
264
260
|
Effect.map(textParts => textParts.join('\n'))
|
|
265
261
|
)
|
|
266
262
|
|
|
267
|
-
const
|
|
263
|
+
const contentPartToCodexInputPart = (
|
|
268
264
|
part: ContentPart
|
|
269
265
|
): Effect.Effect<
|
|
270
266
|
OpenAiCodexInputTextPart | OpenAiCodexInputImagePart | OpenAiCodexInputFilePart,
|
|
@@ -300,7 +296,7 @@ const userPartToCodexInputPart = (
|
|
|
300
296
|
return Effect.fail(unsupportedContentError('Unresolved document source'))
|
|
301
297
|
}
|
|
302
298
|
case 'Audio':
|
|
303
|
-
return Effect.fail(unsupportedContentError('
|
|
299
|
+
return Effect.fail(unsupportedContentError('Audio'))
|
|
304
300
|
}
|
|
305
301
|
}
|
|
306
302
|
|
|
@@ -318,9 +314,33 @@ const contentToUserInput = (
|
|
|
318
314
|
return Effect.succeed(onlyPart.text)
|
|
319
315
|
}
|
|
320
316
|
|
|
321
|
-
return Effect.forEach(parts,
|
|
317
|
+
return Effect.forEach(parts, contentPartToCodexInputPart)
|
|
322
318
|
}
|
|
323
319
|
|
|
320
|
+
const contentToCodexFunctionOutput = (
|
|
321
|
+
content: Content
|
|
322
|
+
): Effect.Effect<OpenAiCodexFunctionOutput, LLMError> =>
|
|
323
|
+
typeof content === 'string'
|
|
324
|
+
? Effect.succeed(content)
|
|
325
|
+
: Effect.forEach(content, contentPartToCodexInputPart)
|
|
326
|
+
|
|
327
|
+
const codexToolResultOutput = (
|
|
328
|
+
content: Content,
|
|
329
|
+
isError: boolean | undefined
|
|
330
|
+
): Effect.Effect<OpenAiCodexFunctionOutput, LLMError> =>
|
|
331
|
+
contentToCodexFunctionOutput(content).pipe(
|
|
332
|
+
Effect.map(output => {
|
|
333
|
+
if (isError !== true) return output
|
|
334
|
+
|
|
335
|
+
const errorPart: OpenAiCodexInputTextPart = {
|
|
336
|
+
type: 'input_text',
|
|
337
|
+
text: 'Tool execution failed.'
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return typeof output === 'string' ? `${errorPart.text}\n\n${output}` : [errorPart, ...output]
|
|
341
|
+
})
|
|
342
|
+
)
|
|
343
|
+
|
|
324
344
|
const serializeToolArguments = (params: unknown) =>
|
|
325
345
|
encodeJsonString(params, 'Could not serialize OpenAI Codex tool arguments')
|
|
326
346
|
|
|
@@ -373,9 +393,9 @@ const messageToCodexInput = (
|
|
|
373
393
|
{
|
|
374
394
|
type: 'function_call_output',
|
|
375
395
|
call_id: message.toolCallId,
|
|
376
|
-
output: yield*
|
|
396
|
+
output: yield* codexToolResultOutput(
|
|
377
397
|
prependMessageContextToContent(message.content, messageContextText(message)),
|
|
378
|
-
|
|
398
|
+
message.isError
|
|
379
399
|
)
|
|
380
400
|
}
|
|
381
401
|
]
|