@opencode/ai 2.2.4 → 2.2.6
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 +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -185
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +11 -22
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +56 -89
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +54 -32
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +14 -20
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +9 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -24
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +11 -23
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Base64 } from "effect/encoding";
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
|
-
import {
|
|
4
|
+
import { AssistantMessage, LLMEvent, ToolResultPart } from "../schema/index.js";
|
|
5
5
|
import { OpenResponses } from "./open-responses.js";
|
|
6
6
|
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
7
7
|
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
@@ -48,27 +48,30 @@ const adapter = {
|
|
|
48
48
|
};
|
|
49
49
|
const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
50
50
|
const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
|
|
51
|
-
const body = yield* OpenResponses.fromRequestWithAdapter(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
part.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
const body = yield* OpenResponses.fromRequestWithAdapter({
|
|
52
|
+
...request,
|
|
53
|
+
messages: request.messages.map((message) => message.role !== "assistant"
|
|
54
|
+
? message
|
|
55
|
+
: new AssistantMessage({
|
|
56
|
+
...message,
|
|
57
|
+
content: message.content.map((part) => {
|
|
58
|
+
if (part.type !== "tool-result" ||
|
|
59
|
+
!part.providerExecuted ||
|
|
60
|
+
part.name !== "image_generation" ||
|
|
61
|
+
part.result.type !== "content" ||
|
|
62
|
+
part.providerMetadata?.[key]?.itemId !== part.id)
|
|
63
|
+
return part;
|
|
64
|
+
// Meta's signed image ID carries edit state; replay the handle, not the image bytes as a user message.
|
|
65
|
+
return ToolResultPart.make({
|
|
66
|
+
...part,
|
|
67
|
+
result: {
|
|
68
|
+
type: "json",
|
|
69
|
+
value: { type: "image_generation_call", id: part.id, status: "completed", result: null },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
})),
|
|
74
|
+
}, adapter);
|
|
72
75
|
// Meta cannot see video nested in tool results; attach it after the complete result batch.
|
|
73
76
|
const input = [];
|
|
74
77
|
const videos = [];
|
|
@@ -99,7 +102,7 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
99
102
|
// Hosted replay items have an open `type`, so a plain tag check does not narrow the union.
|
|
100
103
|
const isFunctionCallOutput = (item) => item.type === "function_call_output" || item.type === "custom_tool_call_output";
|
|
101
104
|
const HOSTED_TOOLS = {
|
|
102
|
-
web_search_call:
|
|
105
|
+
web_search_call: ResponsesHostedTools.common.web_search_call,
|
|
103
106
|
image_generation_call: {
|
|
104
107
|
name: "image_generation",
|
|
105
108
|
input: () => ({}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -16,7 +16,7 @@ export type MiniMaxImageOptions = {
|
|
|
16
16
|
readonly width?: number;
|
|
17
17
|
readonly height?: number;
|
|
18
18
|
} & Record<string, unknown>;
|
|
19
|
-
export type Request =
|
|
19
|
+
export type Request = ImageRequest<ImageModel<MiniMaxImageOptions>>;
|
|
20
20
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
21
21
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<MiniMaxImageOptions>;
|
|
22
22
|
export declare const MiniMaxImages: {
|
|
@@ -165,7 +165,6 @@ const lowerUser = Effect.fnUntraced(function* (message) {
|
|
|
165
165
|
content.push(yield* lowerMedia(part));
|
|
166
166
|
continue;
|
|
167
167
|
}
|
|
168
|
-
return yield* ProviderShared.unsupportedContent("Mistral Chat", "user", ["text", "media"]);
|
|
169
168
|
}
|
|
170
169
|
if (content.every((part) => part.type === "text"))
|
|
171
170
|
return { role: "user", content: content.map((part) => part.text).join("") };
|
|
@@ -176,7 +175,7 @@ const lowerToolCall = (part, normalizeID) => ({
|
|
|
176
175
|
type: "function",
|
|
177
176
|
function: { name: part.name, arguments: ProviderShared.encodeJson(part.input) },
|
|
178
177
|
});
|
|
179
|
-
const lowerAssistant = Effect.fnUntraced(function* (message, normalizeID
|
|
178
|
+
const lowerAssistant = Effect.fnUntraced(function* (message, normalizeID) {
|
|
180
179
|
const structured = message.content.some((part) => part.type === "reasoning" && isMistralThinkingContent(part.providerMetadata?.mistral?.thinking));
|
|
181
180
|
const content = [];
|
|
182
181
|
const text = [];
|
|
@@ -193,10 +192,6 @@ const lowerAssistant = Effect.fnUntraced(function* (message, normalizeID, prefix
|
|
|
193
192
|
const native = part.providerMetadata?.mistral?.thinking;
|
|
194
193
|
if (structured && isMistralThinkingContent(native))
|
|
195
194
|
content.push(native);
|
|
196
|
-
else if (structured)
|
|
197
|
-
content.push({ type: "text", text: part.text });
|
|
198
|
-
else
|
|
199
|
-
text.push(part.text);
|
|
200
195
|
continue;
|
|
201
196
|
}
|
|
202
197
|
if (part.type === "tool-call") {
|
|
@@ -209,14 +204,11 @@ const lowerAssistant = Effect.fnUntraced(function* (message, normalizeID, prefix
|
|
|
209
204
|
role: "assistant",
|
|
210
205
|
content: structured ? content : text.join(""),
|
|
211
206
|
...(toolCalls.length > 0 ? { tool_calls: toolCalls } : {}),
|
|
212
|
-
...(prefix ? { prefix: true } : {}),
|
|
213
207
|
};
|
|
214
208
|
});
|
|
215
209
|
const lowerToolResults = Effect.fnUntraced(function* (message, normalizeID) {
|
|
216
210
|
const output = [];
|
|
217
211
|
for (const part of message.content) {
|
|
218
|
-
if (part.type !== "tool-result")
|
|
219
|
-
return yield* ProviderShared.unsupportedContent("Mistral Chat", "tool", ["tool-result"]);
|
|
220
212
|
if (part.result.type !== "content") {
|
|
221
213
|
output.push({
|
|
222
214
|
role: "tool",
|
|
@@ -273,16 +265,18 @@ const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
|
273
265
|
if (message.role === "assistant") {
|
|
274
266
|
const hasToolCalls = message.content.some((part) => part.type === "tool-call");
|
|
275
267
|
const hasNativeThinking = message.content.some((part) => part.type === "reasoning" && isMistralThinkingContent(part.providerMetadata?.mistral?.thinking));
|
|
276
|
-
const text = message.content
|
|
277
|
-
.flatMap((part) => (part.type === "text" || part.type === "reasoning" ? [part.text] : []))
|
|
278
|
-
.join("");
|
|
268
|
+
const text = message.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("");
|
|
279
269
|
if (!hasToolCalls && !hasNativeThinking && text.trim() === "")
|
|
280
270
|
continue;
|
|
281
|
-
messages.push(yield* lowerAssistant(message, normalizeID
|
|
271
|
+
messages.push(yield* lowerAssistant(message, normalizeID));
|
|
282
272
|
continue;
|
|
283
273
|
}
|
|
284
274
|
messages.push(...(yield* lowerToolResults(message, normalizeID)));
|
|
285
275
|
}
|
|
276
|
+
const trailing = messages.at(-1);
|
|
277
|
+
if (trailing?.role === "assistant" && !trailing.tool_calls) {
|
|
278
|
+
messages[messages.length - 1] = { ...trailing, prefix: true };
|
|
279
|
+
}
|
|
286
280
|
return messages;
|
|
287
281
|
});
|
|
288
282
|
const lowerTool = (tool) => ({
|
|
@@ -308,13 +302,13 @@ export const fromRequest = Effect.fn("MistralChat.fromRequest")(function* (reque
|
|
|
308
302
|
tools: flattened.tools.length > 0 ? flattened.tools.map(lowerTool) : undefined,
|
|
309
303
|
tool_choice: toolChoice,
|
|
310
304
|
stream: true,
|
|
311
|
-
max_tokens: request.
|
|
312
|
-
random_seed: request.
|
|
313
|
-
temperature: request.
|
|
314
|
-
top_p: request.
|
|
315
|
-
frequency_penalty: request.
|
|
316
|
-
presence_penalty: request.
|
|
317
|
-
stop: request.
|
|
305
|
+
max_tokens: request.maxTokens,
|
|
306
|
+
random_seed: request.seed,
|
|
307
|
+
temperature: request.temperature,
|
|
308
|
+
top_p: request.topP,
|
|
309
|
+
frequency_penalty: request.frequencyPenalty,
|
|
310
|
+
presence_penalty: request.presencePenalty,
|
|
311
|
+
stop: request.stop,
|
|
318
312
|
prompt_cache_key: ProviderShared.sendsPromptCacheKey(request)
|
|
319
313
|
? (options.promptCacheKey ?? request.promptCacheKey)
|
|
320
314
|
: undefined,
|
|
@@ -9,18 +9,16 @@ const WebSocketResponseCreate = Schema.StructWithRest(Schema.Struct({ type: Sche
|
|
|
9
9
|
Schema.Record(Schema.String, Schema.Unknown),
|
|
10
10
|
]);
|
|
11
11
|
const decodeMessage = ProviderShared.validateWith(Schema.decodeUnknownEffect(WebSocketResponseCreate));
|
|
12
|
-
const encodeMessage = Schema.encodeSync(Schema.fromJsonString(WebSocketResponseCreate));
|
|
13
12
|
const message = (body) => Effect.gen(function* () {
|
|
14
13
|
if (!ProviderShared.isRecord(body))
|
|
15
14
|
return yield* ProviderShared.invalidRequest("Open Responses WebSocket body must be a JSON object");
|
|
16
15
|
const { stream: _stream, stream_options: _streamOptions, background: _background, ...request } = body;
|
|
17
|
-
|
|
18
|
-
return { request: decoded, message: encodeMessage(decoded) };
|
|
16
|
+
return yield* decodeMessage({ ...request, type: "response.create" });
|
|
19
17
|
});
|
|
20
|
-
const
|
|
18
|
+
const observer = (options) => {
|
|
21
19
|
let responseID;
|
|
22
20
|
let terminal = false;
|
|
23
|
-
|
|
21
|
+
return Effect.fnUntraced(function* (_create, frame, event) {
|
|
24
22
|
if (terminal)
|
|
25
23
|
return yield* ProviderShared.eventError(options.id, `${options.name} emitted ${event.type} after a terminal event`, frame);
|
|
26
24
|
if (event.type === "error") {
|
|
@@ -65,15 +63,6 @@ const driver = (options, body) => {
|
|
|
65
63
|
}
|
|
66
64
|
return { type: "frame", frame };
|
|
67
65
|
});
|
|
68
|
-
return {
|
|
69
|
-
create: () => Effect.sync(() => {
|
|
70
|
-
responseID = undefined;
|
|
71
|
-
terminal = false;
|
|
72
|
-
return { message: body, mode: "full" };
|
|
73
|
-
}),
|
|
74
|
-
observeEvent,
|
|
75
|
-
observe: (create, frame) => OpenResponses.decodeChannelEvent(frame).pipe(Effect.mapError((cause) => ProviderShared.eventError(options.id, `Invalid ${options.name} WebSocket event`, frame, cause)), Effect.flatMap((event) => observeEvent(create, frame, event))),
|
|
76
|
-
};
|
|
77
66
|
};
|
|
78
67
|
export const transport = (options) => {
|
|
79
68
|
const http = HttpTransport.sseJson.with();
|
|
@@ -84,8 +73,7 @@ export const transport = (options) => {
|
|
|
84
73
|
const headers = Headers.remove(options.headers?.(parts.headers) ?? parts.headers, "content-length");
|
|
85
74
|
const channel = input.webSocket && (options.enabled?.(parts.url) ?? true)
|
|
86
75
|
? yield* Effect.gen(function* () {
|
|
87
|
-
const
|
|
88
|
-
const base = driver(options, create.message);
|
|
76
|
+
const request = yield* message(parts.jsonBody);
|
|
89
77
|
return {
|
|
90
78
|
url: yield* WebSocketTransport.toWebSocketUrl(options.url?.(parts.url) ?? parts.url),
|
|
91
79
|
headers,
|
|
@@ -93,9 +81,8 @@ export const transport = (options) => {
|
|
|
93
81
|
driver: OpenResponsesContinuation.driver({
|
|
94
82
|
id: options.id,
|
|
95
83
|
name: options.name,
|
|
96
|
-
request
|
|
97
|
-
|
|
98
|
-
base,
|
|
84
|
+
request,
|
|
85
|
+
base: observer(options),
|
|
99
86
|
continuation: options.continuation,
|
|
100
87
|
}),
|
|
101
88
|
};
|
|
@@ -7,15 +7,11 @@ import { OpenResponses } from "./open-responses.js";
|
|
|
7
7
|
* Whether omitted fields carry over from the continued response is provider behavior the route must know.
|
|
8
8
|
*/
|
|
9
9
|
export type Shape = (request: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>> | undefined;
|
|
10
|
-
export interface BaseDriver extends WebSocketChannelDriver {
|
|
11
|
-
readonly observeEvent?: (create: ChannelCreate, frame: string, event: OpenResponses.Event) => Effect.Effect<ChannelObservation, AIError>;
|
|
12
|
-
}
|
|
13
10
|
export interface DriverInput {
|
|
14
11
|
readonly id: string;
|
|
15
12
|
readonly name: string;
|
|
16
13
|
readonly request: Readonly<Record<string, unknown>>;
|
|
17
|
-
readonly
|
|
18
|
-
readonly base: BaseDriver;
|
|
14
|
+
readonly base: (create: ChannelCreate, frame: string, event: OpenResponses.Event) => Effect.Effect<ChannelObservation, AIError>;
|
|
19
15
|
readonly continuation?: Shape;
|
|
20
16
|
}
|
|
21
17
|
export declare const driver: (input: DriverInput) => WebSocketChannelDriver;
|
|
@@ -121,9 +121,7 @@ export const driver = (input) => {
|
|
|
121
121
|
}),
|
|
122
122
|
observe: (create, frame) => Effect.gen(function* () {
|
|
123
123
|
const event = yield* OpenResponses.decodeChannelEvent(frame).pipe(Effect.mapError((cause) => ProviderShared.eventError(input.id, `Invalid ${input.name} WebSocket event`, frame, cause)));
|
|
124
|
-
const observation = yield* input.base
|
|
125
|
-
? input.base.observeEvent(create, frame, event)
|
|
126
|
-
: input.base.observe(create, frame);
|
|
124
|
+
const observation = yield* input.base(create, frame, event);
|
|
127
125
|
if (event.type === "response.output_item.done" && event.item)
|
|
128
126
|
output.push(event.item);
|
|
129
127
|
if (observation.type === "provider-failure") {
|
|
@@ -1728,18 +1728,6 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1728
1728
|
readonly [x: string]: unknown;
|
|
1729
1729
|
};
|
|
1730
1730
|
} | undefined;
|
|
1731
|
-
} | {
|
|
1732
|
-
readonly type: "tool-error";
|
|
1733
|
-
readonly id: string;
|
|
1734
|
-
readonly name: string;
|
|
1735
|
-
readonly namespace?: string | undefined;
|
|
1736
|
-
readonly message: string;
|
|
1737
|
-
readonly error?: unknown;
|
|
1738
|
-
readonly providerMetadata?: {
|
|
1739
|
-
readonly [x: string]: {
|
|
1740
|
-
readonly [x: string]: unknown;
|
|
1741
|
-
};
|
|
1742
|
-
} | undefined;
|
|
1743
1731
|
} | {
|
|
1744
1732
|
readonly type: "step-finish";
|
|
1745
1733
|
readonly index: number;
|
|
@@ -1764,6 +1752,7 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1764
1752
|
readonly explanation?: string | undefined;
|
|
1765
1753
|
};
|
|
1766
1754
|
readonly usage?: Usage | undefined;
|
|
1755
|
+
readonly message?: import("../schema/messages.js").AssistantMessage | undefined;
|
|
1767
1756
|
readonly providerMetadata?: {
|
|
1768
1757
|
readonly [x: string]: {
|
|
1769
1758
|
readonly [x: string]: unknown;
|
|
@@ -1777,15 +1766,6 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1777
1766
|
readonly [x: string]: unknown;
|
|
1778
1767
|
};
|
|
1779
1768
|
} | undefined;
|
|
1780
|
-
} | {
|
|
1781
|
-
readonly type: "provider-error";
|
|
1782
|
-
readonly message: string;
|
|
1783
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1784
|
-
readonly providerMetadata?: {
|
|
1785
|
-
readonly [x: string]: {
|
|
1786
|
-
readonly [x: string]: unknown;
|
|
1787
|
-
};
|
|
1788
|
-
} | undefined;
|
|
1789
1769
|
} | ({
|
|
1790
1770
|
readonly type: "compaction";
|
|
1791
1771
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -423,9 +423,7 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, adapter) {
|
|
|
423
423
|
const lowerUserContent = Effect.fnUntraced(function* (part, request, adapter) {
|
|
424
424
|
if (part.type === "text")
|
|
425
425
|
return { type: "input_text", text: part.text };
|
|
426
|
-
|
|
427
|
-
return yield* lowerMedia(part, request, adapter);
|
|
428
|
-
return yield* ProviderShared.unsupportedContent(adapter.name, "user", ["text", "media"]);
|
|
426
|
+
return yield* lowerMedia(part, request, adapter);
|
|
429
427
|
});
|
|
430
428
|
// Tool results may carry structured text, images, and files. Keep media as provider-native
|
|
431
429
|
// content instead of JSON-stringifying base64 into a prompt string.
|
|
@@ -450,7 +448,9 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
450
448
|
const custom = OpenAIFreeform.tools(request);
|
|
451
449
|
const customTool = (part) => part.namespace === undefined ? custom.get(part.name) : undefined;
|
|
452
450
|
for (const message of request.messages) {
|
|
453
|
-
const rawMetadata = message.
|
|
451
|
+
const rawMetadata = message.role === "user" || message.role === "assistant"
|
|
452
|
+
? message.providerMetadata?.[providerMetadataKey]
|
|
453
|
+
: undefined;
|
|
454
454
|
const metadata = rawMetadata === undefined ? undefined : yield* decodeMessageMetadata(rawMetadata);
|
|
455
455
|
if (message.role === "system") {
|
|
456
456
|
const update = effortUpdate(message);
|
|
@@ -588,8 +588,6 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
588
588
|
continue;
|
|
589
589
|
}
|
|
590
590
|
for (const part of message.content) {
|
|
591
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
592
|
-
return yield* ProviderShared.unsupportedContent(adapter.name, "tool", ["tool-result"]);
|
|
593
591
|
input.push({
|
|
594
592
|
type: customTool(part) ? "custom_tool_call_output" : "function_call_output",
|
|
595
593
|
call_id: part.id,
|
|
@@ -608,16 +606,15 @@ export const lowerConversation = Effect.fnUntraced(function* (request, adapter)
|
|
|
608
606
|
};
|
|
609
607
|
});
|
|
610
608
|
export const lowerGeneration = (request, options = OpenResponsesOptions.resolve(request)) => {
|
|
611
|
-
const generation = request.generation;
|
|
612
609
|
const cacheKey = ProviderShared.promptCacheKey(request);
|
|
613
610
|
const parallelToolCalls = resolveParallelToolCalls(request, options);
|
|
614
611
|
return {
|
|
615
612
|
stream: true,
|
|
616
|
-
max_output_tokens:
|
|
617
|
-
temperature:
|
|
618
|
-
top_p:
|
|
619
|
-
presence_penalty:
|
|
620
|
-
frequency_penalty:
|
|
613
|
+
max_output_tokens: request.maxTokens,
|
|
614
|
+
temperature: request.temperature,
|
|
615
|
+
top_p: request.topP,
|
|
616
|
+
presence_penalty: request.presencePenalty,
|
|
617
|
+
frequency_penalty: request.frequencyPenalty,
|
|
621
618
|
...(options.store !== undefined ? { store: options.store } : {}),
|
|
622
619
|
...(options.metadata ? { metadata: options.metadata } : {}),
|
|
623
620
|
...(options.safetyIdentifier ? { safety_identifier: options.safetyIdentifier } : {}),
|
|
@@ -1036,9 +1033,7 @@ const onOutputItemDone = Effect.fnUntraced(function* (state, item) {
|
|
|
1036
1033
|
namespace: item.namespace,
|
|
1037
1034
|
providerMetadata: metadata,
|
|
1038
1035
|
});
|
|
1039
|
-
const result =
|
|
1040
|
-
? yield* ToolStream.finish(state.id, tools, item.id)
|
|
1041
|
-
: yield* ToolStream.finishWithInput(state.id, tools, item.id, input);
|
|
1036
|
+
const result = yield* ToolStream.finish(state.id, tools, item.id, input);
|
|
1042
1037
|
const events = [];
|
|
1043
1038
|
const finished = [...(closed?.events ?? []), ...(result.events ?? [])];
|
|
1044
1039
|
// A done-only call never streamed a start event, so open its lifecycle here.
|
|
@@ -3,7 +3,7 @@ import { Route } from "../route/client.js";
|
|
|
3
3
|
import { Framing } from "../route/framing.js";
|
|
4
4
|
import { HttpTransport } from "../route/transport/index.js";
|
|
5
5
|
import { Protocol } from "../route/protocol.js";
|
|
6
|
-
import { AIError, LLMEvent, Usage, type FinishReasonDetails, type CacheHint, type LLMRequest } from "../schema/index.js";
|
|
6
|
+
import { AIError, LLMEvent, Usage, type FinishReasonDetails, type AssistantMessage, type CacheHint, type LLMRequest } from "../schema/index.js";
|
|
7
7
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
8
8
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
9
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
@@ -704,7 +704,7 @@ interface LoweringOptions {
|
|
|
704
704
|
readonly cacheControl?: (cache: CacheHint | undefined) => OpenAIChatCacheControl | undefined;
|
|
705
705
|
readonly toolCallID?: (id: string) => string;
|
|
706
706
|
/** Project provider-specific fields from the exact source, even when other messages are dropped during lowering. */
|
|
707
|
-
readonly assistant?: (source:
|
|
707
|
+
readonly assistant?: (source: AssistantMessage, message: OpenAIChatMessage) => OpenAIChatMessage;
|
|
708
708
|
}
|
|
709
709
|
export declare const fromRequest: (request: LLMRequest<import("../schema/options.js").LanguageModel<{
|
|
710
710
|
readonly [x: string]: unknown;
|
|
@@ -1893,18 +1893,6 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1893
1893
|
readonly [x: string]: unknown;
|
|
1894
1894
|
};
|
|
1895
1895
|
} | undefined;
|
|
1896
|
-
} | {
|
|
1897
|
-
readonly type: "tool-error";
|
|
1898
|
-
readonly id: string;
|
|
1899
|
-
readonly name: string;
|
|
1900
|
-
readonly namespace?: string | undefined;
|
|
1901
|
-
readonly message: string;
|
|
1902
|
-
readonly error?: unknown;
|
|
1903
|
-
readonly providerMetadata?: {
|
|
1904
|
-
readonly [x: string]: {
|
|
1905
|
-
readonly [x: string]: unknown;
|
|
1906
|
-
};
|
|
1907
|
-
} | undefined;
|
|
1908
1896
|
} | {
|
|
1909
1897
|
readonly type: "step-finish";
|
|
1910
1898
|
readonly index: number;
|
|
@@ -1929,6 +1917,7 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1929
1917
|
readonly explanation?: string | undefined;
|
|
1930
1918
|
};
|
|
1931
1919
|
readonly usage?: Usage | undefined;
|
|
1920
|
+
readonly message?: AssistantMessage | undefined;
|
|
1932
1921
|
readonly providerMetadata?: {
|
|
1933
1922
|
readonly [x: string]: {
|
|
1934
1923
|
readonly [x: string]: unknown;
|
|
@@ -1942,15 +1931,6 @@ export declare const finishEvents: (state: ParserState) => Effect.Effect<({
|
|
|
1942
1931
|
readonly [x: string]: unknown;
|
|
1943
1932
|
};
|
|
1944
1933
|
} | undefined;
|
|
1945
|
-
} | {
|
|
1946
|
-
readonly type: "provider-error";
|
|
1947
|
-
readonly message: string;
|
|
1948
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1949
|
-
readonly providerMetadata?: {
|
|
1950
|
-
readonly [x: string]: {
|
|
1951
|
-
readonly [x: string]: unknown;
|
|
1952
|
-
};
|
|
1953
|
-
} | undefined;
|
|
1954
1934
|
} | ({
|
|
1955
1935
|
readonly type: "compaction";
|
|
1956
1936
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -8,7 +8,7 @@ import { HttpTransport } from "../route/transport/index.js";
|
|
|
8
8
|
import { Protocol } from "../route/protocol.js";
|
|
9
9
|
import { AIError, AIErrorReason, InvalidProviderOutputError, LLMEvent, ProviderInternalError, UnknownProviderError, Usage, } from "../schema/index.js";
|
|
10
10
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
11
|
-
import {
|
|
11
|
+
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
12
12
|
import { placesMarkers, requestTTL } from "../cache-policy.js";
|
|
13
13
|
import * as Cache from "./utils/cache.js";
|
|
14
14
|
import { resolveParallelToolCalls } from "./open-responses.js";
|
|
@@ -95,7 +95,11 @@ const OpenRouterDetailFields = {
|
|
|
95
95
|
signature: Schema.optional(Schema.NullOr(Schema.String)),
|
|
96
96
|
};
|
|
97
97
|
const ReasoningDetail = Schema.Union([
|
|
98
|
-
Schema.StructWithRest(Schema.Struct({
|
|
98
|
+
Schema.StructWithRest(Schema.Struct({
|
|
99
|
+
type: Schema.Literal("reasoning.text"),
|
|
100
|
+
text: Schema.optional(Schema.String),
|
|
101
|
+
...OpenRouterDetailFields,
|
|
102
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]),
|
|
99
103
|
Schema.StructWithRest(Schema.Struct({
|
|
100
104
|
type: Schema.Literal("reasoning.summary"),
|
|
101
105
|
summary: Schema.optional(Schema.String),
|
|
@@ -321,20 +325,17 @@ const lowerMedia = Effect.fnUntraced(function* (part) {
|
|
|
321
325
|
return { type: "video_url", video_url: { url } };
|
|
322
326
|
return { type: "image_url", image_url: { url } };
|
|
323
327
|
});
|
|
324
|
-
const openAICompatibleReasoningContent = (native) => isRecord(native) && typeof native.reasoning_content === "string" ? native.reasoning_content : undefined;
|
|
325
328
|
const reasoningField = (part, providerMetadataKey) => {
|
|
326
329
|
const field = part.providerMetadata?.[providerMetadataKey]?.reasoningField;
|
|
327
330
|
return typeof field === "string" ? field : undefined;
|
|
328
331
|
};
|
|
329
|
-
const reasoningDetails = (parts,
|
|
332
|
+
const reasoningDetails = (parts, providerMetadataKey) => {
|
|
330
333
|
const observed = parts.flatMap((part) => {
|
|
331
334
|
const details = part.providerMetadata?.[providerMetadataKey]?.reasoningDetails;
|
|
332
335
|
return Array.isArray(details) ? details : [];
|
|
333
336
|
});
|
|
334
337
|
if (parts.some((part) => Array.isArray(part.providerMetadata?.[providerMetadataKey]?.reasoningDetails)))
|
|
335
338
|
return knownReasoningDetails(observed).map(lowerReasoningDetail);
|
|
336
|
-
if (isRecord(native) && Array.isArray(native.reasoning_details))
|
|
337
|
-
return knownReasoningDetails(native.reasoning_details).map(lowerReasoningDetail);
|
|
338
339
|
};
|
|
339
340
|
// Kimi rejects its stream-only `index` on requests
|
|
340
341
|
// ("the reasoning_details ... must not contain streaming index").
|
|
@@ -357,7 +358,6 @@ const lowerUserMessage = Effect.fnUntraced(function* (message, options) {
|
|
|
357
358
|
content.push(yield* lowerMedia(part));
|
|
358
359
|
continue;
|
|
359
360
|
}
|
|
360
|
-
return yield* ProviderShared.unsupportedContent("OpenAI Chat", "user", ["text", "media"]);
|
|
361
361
|
}
|
|
362
362
|
if (content.every((part) => part.type === "text" && part.cache_control === undefined))
|
|
363
363
|
return {
|
|
@@ -387,21 +387,18 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
const text = reasoning.map((part) => part.text).join("");
|
|
390
|
-
const details = reasoningDetails(reasoning,
|
|
390
|
+
const details = reasoningDetails(reasoning, options.providerMetadataKey);
|
|
391
391
|
const observedField = reasoning
|
|
392
392
|
.map((part) => reasoningField(part, options.providerMetadataKey))
|
|
393
393
|
.find((value) => value !== undefined);
|
|
394
|
-
const nativeReasoning = openAICompatibleReasoningContent(message.native?.openaiCompatible);
|
|
395
394
|
const fullyStructured = reasoning.every((part) => Array.isArray(part.providerMetadata?.[options.providerMetadataKey]?.reasoningDetails));
|
|
396
395
|
const field = (() => {
|
|
397
|
-
if (configuredField !== undefined && (requireReasoning || reasoning.length > 0
|
|
396
|
+
if (configuredField !== undefined && (requireReasoning || reasoning.length > 0))
|
|
398
397
|
return configuredField;
|
|
399
398
|
if (reasoning.length === 0)
|
|
400
399
|
return requireReasoning ? "reasoning_content" : undefined;
|
|
401
400
|
if (observedField !== undefined)
|
|
402
401
|
return observedField;
|
|
403
|
-
if (nativeReasoning !== undefined)
|
|
404
|
-
return "reasoning_content";
|
|
405
402
|
if (!fullyStructured || requireReasoning)
|
|
406
403
|
return "reasoning_content";
|
|
407
404
|
// Kimi always expects `reasoning_content` on replayed assistant messages,
|
|
@@ -409,13 +406,7 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
409
406
|
if (details?.some(isKimiDetail))
|
|
410
407
|
return "reasoning_content";
|
|
411
408
|
})();
|
|
412
|
-
const reasoningText = (
|
|
413
|
-
if (configuredField !== undefined)
|
|
414
|
-
return reasoning.length === 0 ? (nativeReasoning ?? (requireReasoning ? "" : undefined)) : text;
|
|
415
|
-
if (reasoning.length === 0)
|
|
416
|
-
return nativeReasoning ?? (requireReasoning ? "" : undefined);
|
|
417
|
-
return text;
|
|
418
|
-
})();
|
|
409
|
+
const reasoningText = reasoning.length === 0 ? (requireReasoning ? "" : undefined) : text;
|
|
419
410
|
const result = {
|
|
420
411
|
role: "assistant",
|
|
421
412
|
content: (() => {
|
|
@@ -436,8 +427,6 @@ const lowerToolMessages = Effect.fnUntraced(function* (message, options) {
|
|
|
436
427
|
const messages = [];
|
|
437
428
|
const attachments = [];
|
|
438
429
|
for (const part of message.content) {
|
|
439
|
-
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
440
|
-
return yield* ProviderShared.unsupportedContent("OpenAI Chat", "tool", ["tool-result"]);
|
|
441
430
|
if (part.result.type !== "content") {
|
|
442
431
|
messages.push(toolMessage(options.toolCallID?.(part.id) ?? part.id, ProviderShared.toolResultText(part), options.cacheControl?.(part.cache)));
|
|
443
432
|
continue;
|
|
@@ -459,11 +448,8 @@ const toolMessage = (toolCallID, text, cacheControl) => ({
|
|
|
459
448
|
const lowerMessage = Effect.fnUntraced(function* (message, reasoningField, requireReasoning, options) {
|
|
460
449
|
if (message.role === "user")
|
|
461
450
|
return [yield* lowerUserMessage(message, options)];
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
return [options.assistant?.(message, lowered) ?? lowered];
|
|
465
|
-
}
|
|
466
|
-
return (yield* lowerToolMessages(message, options)).messages;
|
|
451
|
+
const lowered = yield* lowerAssistantMessage(message, reasoningField, requireReasoning, options);
|
|
452
|
+
return [options.assistant?.(message, lowered) ?? lowered];
|
|
467
453
|
});
|
|
468
454
|
const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
469
455
|
const system = request.system.length === 0
|
|
@@ -526,10 +512,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
|
526
512
|
if (pendingAttachments.length > 0) {
|
|
527
513
|
messages.push({
|
|
528
514
|
role: "user",
|
|
529
|
-
content: [
|
|
530
|
-
...pendingAttachments.splice(0),
|
|
531
|
-
{ type: "text", text: part.text, cache_control: cacheControl },
|
|
532
|
-
],
|
|
515
|
+
content: [...pendingAttachments.splice(0), { type: "text", text: part.text, cache_control: cacheControl }],
|
|
533
516
|
});
|
|
534
517
|
continue;
|
|
535
518
|
}
|
|
@@ -547,10 +530,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, options) {
|
|
|
547
530
|
else if (previous?.role === "user" && Array.isArray(previous.content))
|
|
548
531
|
messages[messages.length - 1] = {
|
|
549
532
|
role: "user",
|
|
550
|
-
content: [
|
|
551
|
-
...previous.content,
|
|
552
|
-
{ type: "text", text: part.text, cache_control: cacheControl },
|
|
553
|
-
],
|
|
533
|
+
content: [...previous.content, { type: "text", text: part.text, cache_control: cacheControl }],
|
|
554
534
|
};
|
|
555
535
|
else
|
|
556
536
|
messages.push(cacheControl
|
|
@@ -666,7 +646,7 @@ const lowerOptions = (request, supportsStore, hasActiveTools) => {
|
|
|
666
646
|
// Default off: strict providers 400 on unknown body fields, so only send
|
|
667
647
|
// the key where compatibility explicitly allows it. Header-based affinity
|
|
668
648
|
// (x-session-affinity, x-grok-conv-id, ...) is unaffected.
|
|
669
|
-
const cacheKey = (request.model.
|
|
649
|
+
const cacheKey = (request.model.capabilities?.promptCacheKey ?? false) ? ProviderShared.promptCacheKey(request) : undefined;
|
|
670
650
|
return {
|
|
671
651
|
...(supportsStore ? { store: options.store ?? false } : {}),
|
|
672
652
|
...(cacheKey ? { prompt_cache_key: cacheKey } : {}),
|
|
@@ -686,14 +666,13 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
|
|
|
686
666
|
const reasoningField = request.model.compatibility?.reasoningField;
|
|
687
667
|
if (reasoningField && RESERVED_REASONING_FIELDS.has(reasoningField))
|
|
688
668
|
return yield* ProviderShared.invalidRequest(`OpenAI Chat reasoning field conflicts with reserved field ${reasoningField}`);
|
|
689
|
-
const generation = request.generation;
|
|
690
669
|
const flattened = ProviderShared.flattenToolRequest(request);
|
|
691
670
|
const provider = request.model.provider;
|
|
692
671
|
const baseURL = request.model.route.endpoint.baseURL;
|
|
693
672
|
const detectedMaxTokensField = detectMaxTokensField(provider, baseURL);
|
|
694
673
|
const maxTokensField = request.model.compatibility?.maxTokensField ?? detectedMaxTokensField;
|
|
695
|
-
const supportsStore = request.model.
|
|
696
|
-
const supportsStrictMode = request.model.
|
|
674
|
+
const supportsStore = request.model.capabilities?.store ?? detectSupportsStore(provider, baseURL);
|
|
675
|
+
const supportsStrictMode = request.model.capabilities?.tools?.strict ?? detectSupportsStrictMode(provider, baseURL);
|
|
697
676
|
const zaiToolStream = request.model.compatibility?.zaiToolStream ?? detectZaiToolStream(provider, baseURL, request.model.id);
|
|
698
677
|
const hasHistory = hasToolHistory(request.messages);
|
|
699
678
|
const hasActiveTools = flattened.tools.length > 0;
|
|
@@ -709,17 +688,17 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
|
|
|
709
688
|
: flattened.tools.map((tool) => lowerTool(tool, lowering, supportsStrictMode, custom.get(tool.name))),
|
|
710
689
|
tool_choice: hasActiveTools && request.toolChoice ? yield* lowerToolChoice(request.toolChoice, custom) : undefined,
|
|
711
690
|
stream: true,
|
|
712
|
-
...((request.model.
|
|
691
|
+
...((request.model.capabilities?.streamUsage ?? true) ? { stream_options: { include_usage: true } } : {}),
|
|
713
692
|
...(zaiToolStream && hasActiveTools ? { tool_stream: true } : {}),
|
|
714
693
|
...(maxTokensField === "max_completion_tokens"
|
|
715
|
-
? { max_completion_tokens:
|
|
716
|
-
: { max_tokens:
|
|
717
|
-
temperature:
|
|
718
|
-
top_p:
|
|
719
|
-
frequency_penalty:
|
|
720
|
-
presence_penalty:
|
|
721
|
-
seed:
|
|
722
|
-
stop:
|
|
694
|
+
? { max_completion_tokens: request.maxTokens }
|
|
695
|
+
: { max_tokens: request.maxTokens }),
|
|
696
|
+
temperature: request.temperature,
|
|
697
|
+
top_p: request.topP,
|
|
698
|
+
frequency_penalty: request.frequencyPenalty,
|
|
699
|
+
presence_penalty: request.presencePenalty,
|
|
700
|
+
seed: request.seed,
|
|
701
|
+
stop: request.stop,
|
|
723
702
|
...lowerOptions(request, supportsStore, hasActiveTools),
|
|
724
703
|
};
|
|
725
704
|
});
|
|
@@ -162,7 +162,7 @@ export declare const route: Route<{
|
|
|
162
162
|
readonly prompt_cache_options?: {
|
|
163
163
|
readonly ttl?: string | undefined;
|
|
164
164
|
} | undefined;
|
|
165
|
-
readonly reasoning_effort?: import("../
|
|
165
|
+
readonly reasoning_effort?: import("../public.js").ReasoningEffort | undefined;
|
|
166
166
|
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
167
167
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
168
168
|
readonly parallel_tool_calls?: boolean | undefined;
|