@opencode/ai 2.1.4 → 2.2.1
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 +339 -166
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +50 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1444 -34
- package/dist/index.js +139 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +3 -1
- package/dist/media-client.js +1 -0
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +59 -4
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +26 -6
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +10 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +46 -6
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +212 -27
- package/dist/protocols/open-responses.js +116 -54
- package/dist/protocols/openai-chat.d.ts +1135 -31
- package/dist/protocols/openai-chat.js +155 -60
- package/dist/protocols/openai-compatible-chat.d.ts +57 -5
- package/dist/protocols/openai-compatible-responses.d.ts +28 -8
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +36 -24
- package/dist/protocols/openai-images.js +137 -39
- package/dist/protocols/openai-responses.d.ts +202 -42
- package/dist/protocols/openai-responses.js +49 -10
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +58 -4
- package/dist/protocols/venice-chat.js +2 -2
- package/dist/protocols/xai-images.d.ts +7 -2
- package/dist/protocols/xai-images.js +11 -5
- package/dist/protocols/xai-responses.d.ts +30 -3
- package/dist/protocols/xai-responses.js +30 -3
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +60 -4
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +23 -7
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +137 -28
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +259 -145
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +53 -18
- package/dist/providers/anthropic.d.ts +53 -18
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +129 -24
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +124 -12
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +115 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +290 -60
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +128 -12
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +115 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +115 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +115 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +390 -20
- package/dist/providers/digitalocean.js +53 -11
- package/dist/providers/fireworks.d.ts +115 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +57 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +53 -18
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +24 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +4 -2
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +6 -5
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +119 -15
- package/dist/providers/groq.js +1 -7
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +254 -146
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +139 -26
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +132 -25
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +24 -4
- package/dist/providers/openai-compatible.d.ts +62 -8
- package/dist/providers/openai-compatible.js +29 -10
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +103 -18
- package/dist/providers/openai.js +23 -5
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +11 -12
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +446 -35
- package/dist/providers/openrouter.js +78 -27
- package/dist/providers/togetherai.d.ts +115 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +11 -12
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +261 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +16 -22
- package/dist/providers/vercel-ai-gateway.js +41 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +66 -12
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +132 -25
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +62 -9
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +3 -4
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +6 -2
- package/dist/route/media.js +8 -6
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +41 -3
- package/dist/schema/messages.js +23 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +53 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +35 -45
- package/dist/testing.js +14 -75
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +69 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +46 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +497 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/protocols/bfl-images.d.ts +0 -38
- package/dist/protocols/bfl-images.js +0 -153
- package/dist/protocols/fal-images.d.ts +0 -25
- package/dist/protocols/fal-images.js +0 -104
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -39
- package/dist/protocols/stability-images.js +0 -136
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -8,6 +8,7 @@ import { effortUpdate } from "../effort-updates.js";
|
|
|
8
8
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
9
9
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
10
10
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
11
|
+
import { OpenAIFreeform } from "./openai-freeform.js";
|
|
11
12
|
const ADAPTER = "open-responses";
|
|
12
13
|
const NAME = "Open Responses";
|
|
13
14
|
export const PATH = "/responses";
|
|
@@ -34,7 +35,7 @@ const OpenResponsesInputVideo = Schema.Struct({
|
|
|
34
35
|
type: Schema.tag("input_video"),
|
|
35
36
|
video_url: Schema.String,
|
|
36
37
|
});
|
|
37
|
-
const MediaInput = Schema.Union([OpenResponsesInputImage, OpenResponsesInputFile]);
|
|
38
|
+
const MediaInput = Schema.Union([OpenResponsesInputImage, OpenResponsesInputFile, OpenResponsesInputVideo]);
|
|
38
39
|
const OpenResponsesInputContent = Schema.Union([OpenResponsesInputText, MediaInput]);
|
|
39
40
|
export const OpenResponsesOutputText = Schema.Struct({
|
|
40
41
|
type: Schema.tag("output_text"),
|
|
@@ -155,10 +156,17 @@ export const InputItem = Schema.Union([
|
|
|
155
156
|
arguments: Schema.String,
|
|
156
157
|
}),
|
|
157
158
|
Schema.Struct({
|
|
158
|
-
type: Schema.
|
|
159
|
+
type: Schema.Literals(["function_call_output", "custom_tool_call_output"]),
|
|
159
160
|
call_id: Schema.String,
|
|
160
161
|
output: OpenResponsesFunctionCallOutput,
|
|
161
162
|
}),
|
|
163
|
+
Schema.Struct({
|
|
164
|
+
type: Schema.tag("custom_tool_call"),
|
|
165
|
+
id: Schema.optionalKey(Schema.String),
|
|
166
|
+
call_id: Schema.String,
|
|
167
|
+
name: Schema.String,
|
|
168
|
+
input: Schema.String,
|
|
169
|
+
}),
|
|
162
170
|
HostedToolItem,
|
|
163
171
|
HostedToolReplay,
|
|
164
172
|
]);
|
|
@@ -169,16 +177,30 @@ export const Tool = Schema.Struct({
|
|
|
169
177
|
parameters: JsonObject,
|
|
170
178
|
strict: Schema.optional(Schema.Boolean),
|
|
171
179
|
});
|
|
180
|
+
export const CustomTool = Schema.Struct({
|
|
181
|
+
type: Schema.tag("custom"),
|
|
182
|
+
name: Schema.String,
|
|
183
|
+
description: Schema.String,
|
|
184
|
+
format: Schema.Union([
|
|
185
|
+
Schema.Struct({ type: Schema.tag("text") }),
|
|
186
|
+
Schema.Struct({
|
|
187
|
+
type: Schema.tag("grammar"),
|
|
188
|
+
syntax: Schema.Literals(["lark", "regex"]),
|
|
189
|
+
definition: Schema.String,
|
|
190
|
+
}),
|
|
191
|
+
]),
|
|
192
|
+
});
|
|
172
193
|
export const HostedTool = Schema.StructWithRest(Schema.Struct({
|
|
173
194
|
type: Schema.String,
|
|
174
195
|
}), [JsonObject]);
|
|
196
|
+
const NamedTool = Schema.Struct({ type: Schema.Literals(["function", "custom"]), name: Schema.String });
|
|
175
197
|
export const ToolChoice = Schema.Union([
|
|
176
198
|
Schema.Literals(["auto", "none", "required"]),
|
|
177
|
-
|
|
199
|
+
NamedTool,
|
|
178
200
|
Schema.Struct({
|
|
179
201
|
type: Schema.tag("allowed_tools"),
|
|
180
202
|
mode: Schema.Literals(["auto", "none", "required"]),
|
|
181
|
-
tools: Schema.Array(
|
|
203
|
+
tools: Schema.Array(NamedTool),
|
|
182
204
|
}),
|
|
183
205
|
]);
|
|
184
206
|
// Fields shared between the HTTP body and the WebSocket `response.create`
|
|
@@ -189,7 +211,7 @@ export const coreFields = {
|
|
|
189
211
|
model: Schema.String,
|
|
190
212
|
input: Schema.Array(InputItem),
|
|
191
213
|
instructions: Schema.optional(Schema.String),
|
|
192
|
-
tools: optionalArray(Schema.Union([Tool, HostedTool])),
|
|
214
|
+
tools: optionalArray(Schema.Union([Tool, CustomTool, HostedTool])),
|
|
193
215
|
tool_choice: Schema.optional(ToolChoice),
|
|
194
216
|
store: Schema.optional(Schema.Boolean),
|
|
195
217
|
metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
@@ -295,12 +317,30 @@ export const lowerTool = Effect.fnUntraced(function* (protocolName, tool) {
|
|
|
295
317
|
strict: false,
|
|
296
318
|
};
|
|
297
319
|
});
|
|
298
|
-
export const
|
|
299
|
-
|
|
320
|
+
export const lowerCustomTool = (tool, custom) => {
|
|
321
|
+
const grammar = OpenAIFreeform.grammar(custom.format);
|
|
322
|
+
return {
|
|
323
|
+
type: "custom",
|
|
324
|
+
name: tool.name,
|
|
325
|
+
description: tool.description,
|
|
326
|
+
format: grammar ? { type: "grammar", ...grammar } : { type: "text" },
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
export const lowerTools = (tools, adapter, custom) => Effect.forEach(tools, (tool) => {
|
|
330
|
+
if (tool.native !== undefined && adapter.nativeTool)
|
|
331
|
+
return adapter.nativeTool(tool.native);
|
|
332
|
+
const definition = custom.get(tool.name);
|
|
333
|
+
return definition ? Effect.succeed(lowerCustomTool(tool, definition)) : lowerTool(adapter.name, tool);
|
|
334
|
+
});
|
|
335
|
+
export const namedTool = (name, custom) => ({
|
|
336
|
+
type: custom.has(name) ? "custom" : "function",
|
|
337
|
+
name,
|
|
338
|
+
});
|
|
339
|
+
export const lowerToolChoice = (protocolName, toolChoice, custom) => ProviderShared.matchToolChoice(protocolName, toolChoice, {
|
|
300
340
|
auto: () => "auto",
|
|
301
341
|
none: () => "none",
|
|
302
342
|
required: () => "required",
|
|
303
|
-
tool: (toolName) => (
|
|
343
|
+
tool: (toolName) => namedTool(toolName, custom),
|
|
304
344
|
});
|
|
305
345
|
// Server-issued item ids need a nonempty prefix and suffix, but the prefix is
|
|
306
346
|
// provider-defined and does not necessarily identify the item's semantic type.
|
|
@@ -311,8 +351,19 @@ const itemID = (providerMetadata, providerMetadataKey) => {
|
|
|
311
351
|
const separator = metadata.itemId.indexOf("_");
|
|
312
352
|
return separator > 0 && separator < metadata.itemId.length - 1 ? metadata.itemId : undefined;
|
|
313
353
|
};
|
|
314
|
-
|
|
315
|
-
|
|
354
|
+
// A call replays as the type its tool is declared with now; the item id only survives when that type is unchanged.
|
|
355
|
+
const lowerToolCall = (part, providerMetadataKey, custom) => {
|
|
356
|
+
const id = OpenAIFreeform.keepsItemID(part.providerMetadata, providerMetadataKey, custom !== undefined)
|
|
357
|
+
? itemID(part.providerMetadata, providerMetadataKey)
|
|
358
|
+
: undefined;
|
|
359
|
+
if (custom)
|
|
360
|
+
return {
|
|
361
|
+
type: "custom_tool_call",
|
|
362
|
+
...(id === undefined ? {} : { id }),
|
|
363
|
+
call_id: part.id,
|
|
364
|
+
name: part.name,
|
|
365
|
+
input: OpenAIFreeform.toRaw(custom, part.input),
|
|
366
|
+
};
|
|
316
367
|
return {
|
|
317
368
|
type: "function_call",
|
|
318
369
|
...(id === undefined ? {} : { id }),
|
|
@@ -341,7 +392,7 @@ const lowerReasoning = (part, providerMetadataKey) => {
|
|
|
341
392
|
};
|
|
342
393
|
const decodeImageDetail = ProviderShared.validateWith(Schema.decodeUnknownEffect(OpenResponsesInputImage.fields.detail));
|
|
343
394
|
const decodeMessageMetadata = ProviderShared.validateWith(Schema.decodeUnknownEffect(MessageMetadata));
|
|
344
|
-
const lowerMedia = Effect.fnUntraced(function* (part, request, adapter
|
|
395
|
+
const lowerMedia = Effect.fnUntraced(function* (part, request, adapter) {
|
|
345
396
|
const media = part.media.inline();
|
|
346
397
|
const providerMedia = adapter.lowerMedia?.({ part, media, request });
|
|
347
398
|
if (providerMedia)
|
|
@@ -352,7 +403,7 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, adapter, target)
|
|
|
352
403
|
const url = ProviderShared.mediaUrl(part.media);
|
|
353
404
|
const location = url ?? (yield* ProviderShared.requireInlineMedia(adapter.name, part.media)).dataUrl;
|
|
354
405
|
if (part.media.kind !== "image") {
|
|
355
|
-
if (
|
|
406
|
+
if (part.media.kind === "video")
|
|
356
407
|
return { type: "input_video", video_url: location };
|
|
357
408
|
return {
|
|
358
409
|
type: "input_file",
|
|
@@ -371,26 +422,15 @@ const lowerUserContent = Effect.fnUntraced(function* (part, request, adapter) {
|
|
|
371
422
|
if (part.type === "text")
|
|
372
423
|
return { type: "input_text", text: part.text };
|
|
373
424
|
if (part.type === "media")
|
|
374
|
-
return yield*
|
|
425
|
+
return yield* lowerMedia(part, request, adapter);
|
|
375
426
|
return yield* ProviderShared.unsupportedContent(adapter.name, "user", ["text", "media"]);
|
|
376
427
|
});
|
|
377
|
-
const lowerMessageMedia = Effect.fnUntraced(function* (part, request, adapter) {
|
|
378
|
-
const lowered = yield* lowerMedia(part, request, adapter, "message");
|
|
379
|
-
if (lowered.type === "input_video")
|
|
380
|
-
return yield* ProviderShared.invalidRequest(`${adapter.name} user messages do not support input_video`);
|
|
381
|
-
return lowered;
|
|
382
|
-
});
|
|
383
428
|
// Tool results may carry structured text, images, and files. Keep media as provider-native
|
|
384
429
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
385
430
|
const lowerToolResultContentItem = Effect.fnUntraced(function* (item, request, adapter) {
|
|
386
431
|
if (item.type === "text")
|
|
387
432
|
return { type: "input_text", text: item.text };
|
|
388
|
-
return yield* lowerMedia(ProviderShared.toolFileMedia(item), request, adapter
|
|
389
|
-
});
|
|
390
|
-
const lowerHostedToolResultContentItem = Effect.fnUntraced(function* (item, request, adapter) {
|
|
391
|
-
if (item.type === "text")
|
|
392
|
-
return { type: "input_text", text: item.text };
|
|
393
|
-
return yield* lowerMessageMedia(ProviderShared.toolFileMedia(item), request, adapter);
|
|
433
|
+
return yield* lowerMedia(ProviderShared.toolFileMedia(item), request, adapter);
|
|
394
434
|
});
|
|
395
435
|
const lowerToolResultOutput = Effect.fnUntraced(function* (part, request, adapter) {
|
|
396
436
|
// Text/json/error results are encoded as a plain string for backward
|
|
@@ -405,6 +445,8 @@ const DEFAULT_EFFORT = "medium";
|
|
|
405
445
|
const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
406
446
|
const input = [];
|
|
407
447
|
const providerMetadataKey = metadataKey(request.model);
|
|
448
|
+
const custom = OpenAIFreeform.tools(request);
|
|
449
|
+
const customTool = (part) => part.namespace === undefined ? custom.get(part.name) : undefined;
|
|
408
450
|
for (const message of request.messages) {
|
|
409
451
|
const rawMetadata = message.providerMetadata?.[providerMetadataKey];
|
|
410
452
|
const metadata = rawMetadata === undefined ? undefined : yield* decodeMessageMetadata(rawMetadata);
|
|
@@ -494,7 +536,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
494
536
|
flushText();
|
|
495
537
|
if (part.providerExecuted === true)
|
|
496
538
|
continue;
|
|
497
|
-
input.push(lowerToolCall(part, providerMetadataKey));
|
|
539
|
+
input.push(lowerToolCall(part, providerMetadataKey, customTool(part)));
|
|
498
540
|
continue;
|
|
499
541
|
}
|
|
500
542
|
if (part.type === "tool-result" && part.providerExecuted === true) {
|
|
@@ -518,7 +560,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
518
560
|
input.push({
|
|
519
561
|
type: "message",
|
|
520
562
|
role: "user",
|
|
521
|
-
content: yield* Effect.forEach(content, (item) =>
|
|
563
|
+
content: yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, adapter)),
|
|
522
564
|
});
|
|
523
565
|
continue;
|
|
524
566
|
}
|
|
@@ -528,7 +570,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
528
570
|
input.push({
|
|
529
571
|
type: "message",
|
|
530
572
|
role: "user",
|
|
531
|
-
content: [yield*
|
|
573
|
+
content: [yield* lowerMedia(part, request, adapter)],
|
|
532
574
|
});
|
|
533
575
|
continue;
|
|
534
576
|
}
|
|
@@ -547,7 +589,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
547
589
|
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
548
590
|
return yield* ProviderShared.unsupportedContent(adapter.name, "tool", ["tool-result"]);
|
|
549
591
|
input.push({
|
|
550
|
-
type: "function_call_output",
|
|
592
|
+
type: customTool(part) ? "custom_tool_call_output" : "function_call_output",
|
|
551
593
|
call_id: part.id,
|
|
552
594
|
output: yield* lowerToolResultOutput(part, request, adapter),
|
|
553
595
|
});
|
|
@@ -600,25 +642,26 @@ export const resolveParallelToolCalls = (request, options = OpenResponsesOptions
|
|
|
600
642
|
const disabled = request.toolChoice?.disableParallelToolUse;
|
|
601
643
|
return disabled === undefined ? undefined : !disabled;
|
|
602
644
|
};
|
|
603
|
-
export const allowedToolChoice = (
|
|
645
|
+
export const allowedToolChoice = (options, custom) => {
|
|
604
646
|
const allowed = options.allowedTools;
|
|
605
647
|
if (!allowed)
|
|
606
648
|
return undefined;
|
|
607
649
|
return {
|
|
608
650
|
type: "allowed_tools",
|
|
609
651
|
mode: allowed.mode,
|
|
610
|
-
tools: allowed.toolNames.map((name) => (
|
|
652
|
+
tools: allowed.toolNames.map((name) => namedTool(name, custom)),
|
|
611
653
|
};
|
|
612
654
|
};
|
|
613
655
|
export const fromRequestWithAdapter = Effect.fn("OpenResponses.fromRequestWithAdapter")(function* (request, adapter) {
|
|
614
656
|
const projected = ProviderShared.flattenToolRequest(request);
|
|
615
657
|
const options = OpenResponsesOptions.resolve(request);
|
|
658
|
+
const custom = OpenAIFreeform.tools(request);
|
|
616
659
|
return {
|
|
617
660
|
...(yield* lowerConversation(projected.request, adapter)),
|
|
618
661
|
...lowerGeneration(request, options),
|
|
619
|
-
tools: projected.tools.length === 0 ? undefined : yield* lowerTools(projected.tools, adapter),
|
|
620
|
-
tool_choice: allowedToolChoice(
|
|
621
|
-
(request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice) : undefined),
|
|
662
|
+
tools: projected.tools.length === 0 ? undefined : yield* lowerTools(projected.tools, adapter, custom),
|
|
663
|
+
tool_choice: allowedToolChoice(options, custom) ??
|
|
664
|
+
(request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice, custom) : undefined),
|
|
622
665
|
};
|
|
623
666
|
});
|
|
624
667
|
export const fromRequest = (request) => fromRequestWithAdapter(request, BASE_ADAPTER);
|
|
@@ -644,6 +687,7 @@ export const mapUsage = (usage, providerMetadataKey) => {
|
|
|
644
687
|
cacheWriteInputTokens: cacheWrite,
|
|
645
688
|
reasoningTokens: reasoning,
|
|
646
689
|
totalTokens: ProviderShared.totalTokens(usage.input_tokens, usage.output_tokens, usage.total_tokens),
|
|
690
|
+
...ProviderShared.reportedBilling(usage),
|
|
647
691
|
providerMetadata: { [providerMetadataKey]: usage },
|
|
648
692
|
});
|
|
649
693
|
};
|
|
@@ -703,6 +747,7 @@ const ITEM_ID_PREFIX = {
|
|
|
703
747
|
message: "msg",
|
|
704
748
|
reasoning: "rs",
|
|
705
749
|
function_call: "fc",
|
|
750
|
+
custom_tool_call: "ctc",
|
|
706
751
|
compaction: "cmp",
|
|
707
752
|
};
|
|
708
753
|
// An item without an id adopts the id already open in its output slot,
|
|
@@ -839,25 +884,26 @@ const onOutputItemAdded = (state, event) => {
|
|
|
839
884
|
events,
|
|
840
885
|
];
|
|
841
886
|
}
|
|
842
|
-
if (item.type !== "function_call" || !item.call_id)
|
|
887
|
+
if ((item.type !== "function_call" && item.type !== "custom_tool_call") || !item.call_id)
|
|
843
888
|
return [state, NO_EVENTS];
|
|
844
889
|
if (state.tools[item.id] !== undefined)
|
|
845
890
|
return [state, NO_EVENTS];
|
|
846
|
-
const
|
|
891
|
+
const custom = item.type === "custom_tool_call";
|
|
892
|
+
const metadata = providerMetadata(state, OpenAIFreeform.metadata(item.id, custom));
|
|
847
893
|
const events = [];
|
|
848
894
|
const lifecycle = Lifecycle.stepStart(state.lifecycle, events);
|
|
895
|
+
const tools = ToolStream.start(state.tools, item.id, {
|
|
896
|
+
id: item.call_id,
|
|
897
|
+
name: item.name ?? "",
|
|
898
|
+
namespace: item.namespace,
|
|
899
|
+
input: custom ? "" : (item.arguments ?? ""),
|
|
900
|
+
providerMetadata: metadata,
|
|
901
|
+
});
|
|
902
|
+
const opened = custom
|
|
903
|
+
? ToolStream.append(tools, item.id, OpenAIFreeform.streamStart(state.custom.get(item.name ?? ""), rawInput(item)))
|
|
904
|
+
: undefined;
|
|
849
905
|
return [
|
|
850
|
-
{
|
|
851
|
-
...state,
|
|
852
|
-
lifecycle,
|
|
853
|
-
tools: ToolStream.start(state.tools, item.id, {
|
|
854
|
-
id: item.call_id,
|
|
855
|
-
name: item.name ?? "",
|
|
856
|
-
namespace: item.namespace,
|
|
857
|
-
input: item.arguments ?? "",
|
|
858
|
-
providerMetadata: metadata,
|
|
859
|
-
}),
|
|
860
|
-
},
|
|
906
|
+
{ ...state, lifecycle, tools: opened?.tools ?? tools },
|
|
861
907
|
[
|
|
862
908
|
...events,
|
|
863
909
|
LLMEvent.toolInputStart({
|
|
@@ -866,9 +912,11 @@ const onOutputItemAdded = (state, event) => {
|
|
|
866
912
|
namespace: item.namespace,
|
|
867
913
|
providerMetadata: metadata,
|
|
868
914
|
}),
|
|
915
|
+
...(opened?.events ?? []),
|
|
869
916
|
],
|
|
870
917
|
];
|
|
871
918
|
};
|
|
919
|
+
const rawInput = (item) => (typeof item.input === "string" ? item.input : "");
|
|
872
920
|
const onReasoningSummaryPartAdded = (state, event) => {
|
|
873
921
|
if (event.item_id === undefined || event.summary_index === undefined)
|
|
874
922
|
return [state, NO_EVENTS];
|
|
@@ -969,24 +1017,28 @@ const onOutputItemDone = Effect.fnUntraced(function* (state, item) {
|
|
|
969
1017
|
events,
|
|
970
1018
|
];
|
|
971
1019
|
}
|
|
972
|
-
if (item.type === "function_call") {
|
|
1020
|
+
if (item.type === "function_call" || item.type === "custom_tool_call") {
|
|
973
1021
|
if (!item.call_id || !item.name)
|
|
974
1022
|
return [state, NO_EVENTS];
|
|
975
|
-
const
|
|
1023
|
+
const custom = item.type === "custom_tool_call";
|
|
1024
|
+
const metadata = providerMetadata(state, OpenAIFreeform.metadata(item.id, custom));
|
|
1025
|
+
const final = { custom: state.custom.get(item.name), raw: rawInput(item) };
|
|
1026
|
+
const input = custom ? OpenAIFreeform.fromRaw(final.custom, final.raw) : item.arguments;
|
|
976
1027
|
const registered = state.tools[item.id] !== undefined;
|
|
1028
|
+
const closed = custom ? OpenAIFreeform.close(state.tools, [item.id], final) : undefined;
|
|
977
1029
|
const tools = registered
|
|
978
|
-
? state.tools
|
|
1030
|
+
? (closed?.tools ?? state.tools)
|
|
979
1031
|
: ToolStream.start(state.tools, item.id, {
|
|
980
1032
|
id: item.call_id,
|
|
981
1033
|
name: item.name,
|
|
982
1034
|
namespace: item.namespace,
|
|
983
1035
|
providerMetadata: metadata,
|
|
984
1036
|
});
|
|
985
|
-
const result =
|
|
1037
|
+
const result = input === undefined
|
|
986
1038
|
? yield* ToolStream.finish(state.id, tools, item.id)
|
|
987
|
-
: yield* ToolStream.finishWithInput(state.id, tools, item.id,
|
|
1039
|
+
: yield* ToolStream.finishWithInput(state.id, tools, item.id, input);
|
|
988
1040
|
const events = [];
|
|
989
|
-
const finished = result.events ?? [];
|
|
1041
|
+
const finished = [...(closed?.events ?? []), ...(result.events ?? [])];
|
|
990
1042
|
// A done-only call never streamed a start event, so open its lifecycle here.
|
|
991
1043
|
const resultEvents = registered || finished.length === 0
|
|
992
1044
|
? finished
|
|
@@ -1061,7 +1113,8 @@ const onResponseFinish = Effect.fnUntraced(function* (state, event) {
|
|
|
1061
1113
|
// Terminal recovery cannot insert a checkpoint before already-emitted content.
|
|
1062
1114
|
if (item.type === "compaction" && state.lifecycle.stepStarted && !state.completedCompactions.has(item.id))
|
|
1063
1115
|
return yield* ProviderShared.eventError(state.id, "Cannot recover a compaction checkpoint after output has been emitted");
|
|
1064
|
-
const recoverable = item.type === "compaction" ||
|
|
1116
|
+
const recoverable = item.type === "compaction" ||
|
|
1117
|
+
((item.type === "function_call" || item.type === "custom_tool_call") && current.tools[item.id] !== undefined);
|
|
1065
1118
|
if (!recoverable)
|
|
1066
1119
|
continue;
|
|
1067
1120
|
const [next, emitted] = yield* onOutputItemDone(current, item);
|
|
@@ -1173,6 +1226,14 @@ export const step = (state, event) => {
|
|
|
1173
1226
|
return event.item_id !== undefined
|
|
1174
1227
|
? onFunctionCallArgumentsDelta(state, event)
|
|
1175
1228
|
: ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
1229
|
+
if (event.type === "response.custom_tool_call_input.delta")
|
|
1230
|
+
return event.item_id !== undefined
|
|
1231
|
+
? onFunctionCallArgumentsDelta(state, {
|
|
1232
|
+
...event,
|
|
1233
|
+
type: "response.function_call_arguments.delta",
|
|
1234
|
+
delta: OpenAIFreeform.streamDelta(event.delta ?? ""),
|
|
1235
|
+
})
|
|
1236
|
+
: ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
1176
1237
|
if (event.type === "response.output_item.done")
|
|
1177
1238
|
return onOutputItemDone(state, event.item);
|
|
1178
1239
|
if (event.type === "response.completed" || event.type === "response.incomplete")
|
|
@@ -1198,6 +1259,7 @@ export const initial = (request, adapter = BASE_ADAPTER) => ({
|
|
|
1198
1259
|
providerMetadataKey: metadataKey(request.model),
|
|
1199
1260
|
hasFunctionCall: false,
|
|
1200
1261
|
tools: ToolStream.empty(),
|
|
1262
|
+
custom: OpenAIFreeform.tools(request),
|
|
1201
1263
|
lifecycle: Lifecycle.initial(),
|
|
1202
1264
|
outputItems: {},
|
|
1203
1265
|
message: undefined,
|