@opencode/ai 2.2.5 → 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 +54 -173
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +10 -16
- 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 +54 -72
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +44 -30
- 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 +7 -10
- 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 +7 -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 -23
- 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 +7 -22
- 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
package/dist/schema/messages.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Option, Schema } from "effect";
|
|
2
2
|
import { withStatics } from "@opencode/schema/schema";
|
|
3
3
|
import { Tool } from "@opencode/schema/tool";
|
|
4
|
-
import { CacheHint,
|
|
4
|
+
import { CacheHint, JsonSchema, ProviderMetadata, ReasoningEffort, } from "./options.js";
|
|
5
5
|
import { ProviderID } from "./ids.js";
|
|
6
6
|
import { Media } from "../media.js";
|
|
7
7
|
import { Json } from "../utils/json.js";
|
|
@@ -25,7 +25,6 @@ export const TextPart = Schema.Struct({
|
|
|
25
25
|
type: Schema.Literal("text"),
|
|
26
26
|
text: Schema.String,
|
|
27
27
|
cache: Schema.optional(CacheHint),
|
|
28
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
29
28
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
30
29
|
}).annotate({ identifier: "LLM.Content.Text" });
|
|
31
30
|
export const MediaPart = Schema.Struct({
|
|
@@ -33,9 +32,12 @@ export const MediaPart = Schema.Struct({
|
|
|
33
32
|
media: Media.AssetSchema,
|
|
34
33
|
filename: Schema.optional(Schema.String),
|
|
35
34
|
cache: Schema.optional(CacheHint),
|
|
36
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
37
35
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
38
36
|
}).annotate({ identifier: "LLM.Content.Media" });
|
|
37
|
+
const mediaPart = (input) => {
|
|
38
|
+
const { mediaType, ...part } = input;
|
|
39
|
+
return { ...part, media: Media.make(input.media, mediaType) };
|
|
40
|
+
};
|
|
39
41
|
const toolResultValueSchema = Schema.Union([
|
|
40
42
|
Schema.Struct({
|
|
41
43
|
type: Schema.Literal("json"),
|
|
@@ -104,7 +106,6 @@ export const ToolCallPart = withStatics(Schema.Struct({
|
|
|
104
106
|
input: Schema.Unknown,
|
|
105
107
|
providerExecuted: Schema.optional(Schema.Boolean),
|
|
106
108
|
cache: Schema.optional(CacheHint),
|
|
107
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
108
109
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
109
110
|
}).annotate({ identifier: "LLM.Content.ToolCall" }), {
|
|
110
111
|
make: (input) => ({ type: "tool-call", ...input }),
|
|
@@ -117,7 +118,6 @@ export const ToolResultPart = withStatics(Schema.Struct({
|
|
|
117
118
|
result: ToolResultValue,
|
|
118
119
|
providerExecuted: Schema.optional(Schema.Boolean),
|
|
119
120
|
cache: Schema.optional(CacheHint),
|
|
120
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
121
121
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
122
122
|
}).annotate({ identifier: "LLM.Content.ToolResult" }), {
|
|
123
123
|
make: (input) => ({
|
|
@@ -128,7 +128,6 @@ export const ToolResultPart = withStatics(Schema.Struct({
|
|
|
128
128
|
result: ToolResultValue.make(input.result, input.resultType),
|
|
129
129
|
providerExecuted: input.providerExecuted,
|
|
130
130
|
cache: input.cache,
|
|
131
|
-
metadata: input.metadata,
|
|
132
131
|
providerMetadata: input.providerMetadata,
|
|
133
132
|
}),
|
|
134
133
|
});
|
|
@@ -137,7 +136,6 @@ export const ReasoningPart = Schema.Struct({
|
|
|
137
136
|
text: Schema.String,
|
|
138
137
|
encrypted: Schema.optional(Schema.String),
|
|
139
138
|
cache: Schema.optional(CacheHint),
|
|
140
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
141
139
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
142
140
|
}).annotate({ identifier: "LLM.Content.Reasoning" });
|
|
143
141
|
const compactionPartSchema = Schema.Struct({
|
|
@@ -168,40 +166,77 @@ export const ContentPart = Schema.Union([
|
|
|
168
166
|
CompactionPart,
|
|
169
167
|
EffortPart,
|
|
170
168
|
]).pipe(Schema.toTaggedUnion("type"));
|
|
171
|
-
export class
|
|
169
|
+
export class SystemMessage extends Schema.Class("LLM.SystemMessage")({
|
|
172
170
|
id: Schema.optional(Schema.String),
|
|
173
|
-
role:
|
|
174
|
-
content: Schema.Array(
|
|
175
|
-
|
|
171
|
+
role: Schema.Literal("system"),
|
|
172
|
+
content: Schema.Array(Schema.Union([TextPart, EffortPart]).pipe(Schema.toTaggedUnion("type"))),
|
|
173
|
+
}) {
|
|
174
|
+
}
|
|
175
|
+
export class UserMessage extends Schema.Class("LLM.UserMessage")({
|
|
176
|
+
id: Schema.optional(Schema.String),
|
|
177
|
+
role: Schema.Literal("user"),
|
|
178
|
+
content: Schema.Array(Schema.Union([TextPart, MediaPart]).pipe(Schema.toTaggedUnion("type"))),
|
|
176
179
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
177
|
-
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
178
180
|
}) {
|
|
179
181
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
182
|
+
export class AssistantMessage extends Schema.Class("LLM.AssistantMessage")({
|
|
183
|
+
id: Schema.optional(Schema.String),
|
|
184
|
+
role: Schema.Literal("assistant"),
|
|
185
|
+
content: Schema.Array(Schema.Union([TextPart, ReasoningPart, ToolCallPart, ToolResultPart, MediaPart, CompactionPart]).pipe(Schema.toTaggedUnion("type"))),
|
|
186
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
187
|
+
}) {
|
|
188
|
+
}
|
|
189
|
+
export class ToolMessage extends Schema.Class("LLM.ToolMessage")({
|
|
190
|
+
id: Schema.optional(Schema.String),
|
|
191
|
+
role: Schema.Literal("tool"),
|
|
192
|
+
content: Schema.Array(ToolResultPart),
|
|
193
|
+
}) {
|
|
194
|
+
}
|
|
195
|
+
const messageSchema = Schema.Union([SystemMessage, UserMessage, AssistantMessage, ToolMessage]).pipe(Schema.toTaggedUnion("role"), Schema.annotate({ identifier: "LLM.Message" }));
|
|
196
|
+
const text = (value) => ({ type: "text", text: value });
|
|
197
|
+
const isParts = (input) => Array.isArray(input);
|
|
198
|
+
const content = (input) => (typeof input === "string" ? [text(input)] : isParts(input) ? [...input] : [input]);
|
|
199
|
+
function contentWithMedia(input) {
|
|
200
|
+
return content(input).map((part) => (part.type === "media" ? mediaPart(part) : part));
|
|
201
|
+
}
|
|
202
|
+
function make(input) {
|
|
203
|
+
switch (input.role) {
|
|
204
|
+
case "system":
|
|
205
|
+
return input instanceof SystemMessage ? input : new SystemMessage({ ...input, content: content(input.content) });
|
|
206
|
+
case "user":
|
|
207
|
+
return input instanceof UserMessage
|
|
208
|
+
? input
|
|
209
|
+
: new UserMessage({ ...input, content: contentWithMedia(input.content) });
|
|
210
|
+
case "assistant":
|
|
211
|
+
return input instanceof AssistantMessage
|
|
212
|
+
? input
|
|
213
|
+
: new AssistantMessage({ ...input, content: contentWithMedia(input.content) });
|
|
214
|
+
case "tool":
|
|
215
|
+
return input instanceof ToolMessage
|
|
216
|
+
? input
|
|
217
|
+
: new ToolMessage({ ...input, content: isParts(input.content) ? [...input.content] : [input.content] });
|
|
218
|
+
}
|
|
219
|
+
// Untyped callers can still pass an unknown role; reject it the way the schema does.
|
|
220
|
+
return Schema.decodeUnknownSync(messageSchema)(input);
|
|
221
|
+
}
|
|
222
|
+
export const Message = withStatics(messageSchema, {
|
|
223
|
+
text,
|
|
224
|
+
// Typed through `MediaPartInput` so packages that infer types from `Message` can still emit declarations.
|
|
225
|
+
media: (media, options) => mediaPart({ type: "media", media, ...options }),
|
|
226
|
+
content: contentWithMedia,
|
|
227
|
+
make,
|
|
228
|
+
user: (input) => make({ role: "user", content: input }),
|
|
229
|
+
assistant: (input) => make({ role: "assistant", content: input }),
|
|
195
230
|
/**
|
|
196
231
|
* Add an operator-authored instruction at this chronological point in the
|
|
197
232
|
* conversation. This is distinct from the initial `LLMRequest.system`
|
|
198
233
|
* prompt. Keep raw retrieved, tool, and web content out of privileged system
|
|
199
234
|
* updates; pass that untrusted content through ordinary user/tool channels.
|
|
200
235
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
236
|
+
system: (input) => make({ role: "system", content: input }),
|
|
237
|
+
effort: (input) => make({ role: "system", content: [{ type: "effort", effort: input.effort, previous: input.previous }] }),
|
|
238
|
+
tool: (result) => make({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] }),
|
|
239
|
+
});
|
|
205
240
|
/**
|
|
206
241
|
* Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
|
|
207
242
|
* write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
|
|
@@ -218,7 +253,6 @@ const toolDefinitionFields = {
|
|
|
218
253
|
outputSchema: Schema.optional(JsonSchema),
|
|
219
254
|
freeform: Schema.optional(Freeform),
|
|
220
255
|
cache: Schema.optional(CacheHint),
|
|
221
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
222
256
|
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
223
257
|
};
|
|
224
258
|
export class ToolDefinition extends Schema.Class("LLM.ToolDefinition")({
|
|
@@ -279,54 +313,3 @@ export class ToolChoice extends Schema.Class("LLM.ToolChoice")({
|
|
|
279
313
|
return new ToolChoice(input);
|
|
280
314
|
};
|
|
281
315
|
})(ToolChoice || (ToolChoice = {}));
|
|
282
|
-
const requestSchema = Schema.Struct({
|
|
283
|
-
id: Schema.optional(Schema.String),
|
|
284
|
-
model: LanguageModelSchema,
|
|
285
|
-
system: Schema.Array(SystemPart),
|
|
286
|
-
messages: Schema.Array(Message),
|
|
287
|
-
tools: Schema.Array(ToolEntry),
|
|
288
|
-
toolChoice: Schema.optional(ToolChoice),
|
|
289
|
-
generation: Schema.optional(GenerationOptions),
|
|
290
|
-
providerOptions: Schema.optional(ProviderOptions),
|
|
291
|
-
http: Schema.optional(HttpOptions),
|
|
292
|
-
cache: Schema.optional(CachePolicy),
|
|
293
|
-
// Stable cache affinity for protocols that support provider-managed prompt caching.
|
|
294
|
-
promptCacheKey: Schema.optional(Schema.String),
|
|
295
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
296
|
-
/** Emit a `raw` event with each provider frame before the events parsed from it. */
|
|
297
|
-
includeRaw: Schema.optional(Schema.Boolean),
|
|
298
|
-
});
|
|
299
|
-
export class LLMRequest extends Schema.Class("LLM.Request")(requestSchema.fields) {
|
|
300
|
-
// Preserve model inference instead of inheriting the schema's erased constructor signature.
|
|
301
|
-
// oxlint-disable-next-line no-useless-constructor
|
|
302
|
-
constructor(input) {
|
|
303
|
-
super(input);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
(function (LLMRequest) {
|
|
307
|
-
LLMRequest.input = (request) => ({
|
|
308
|
-
id: request.id,
|
|
309
|
-
model: request.model,
|
|
310
|
-
system: request.system,
|
|
311
|
-
messages: request.messages,
|
|
312
|
-
tools: request.tools,
|
|
313
|
-
toolChoice: request.toolChoice,
|
|
314
|
-
generation: request.generation,
|
|
315
|
-
providerOptions: request.providerOptions,
|
|
316
|
-
http: request.http,
|
|
317
|
-
cache: request.cache,
|
|
318
|
-
promptCacheKey: request.promptCacheKey,
|
|
319
|
-
metadata: request.metadata,
|
|
320
|
-
includeRaw: request.includeRaw,
|
|
321
|
-
});
|
|
322
|
-
function update(request, patch) {
|
|
323
|
-
if (Object.keys(patch).length === 0)
|
|
324
|
-
return request;
|
|
325
|
-
return new LLMRequest({
|
|
326
|
-
...LLMRequest.input(request),
|
|
327
|
-
...patch,
|
|
328
|
-
model: patch.model ?? request.model,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
LLMRequest.update = update;
|
|
332
|
-
})(LLMRequest || (LLMRequest = {}));
|
package/dist/schema/options.d.ts
CHANGED
|
@@ -12,56 +12,55 @@ export declare const mergeProviderOptions: (...items: ReadonlyArray<ProviderOpti
|
|
|
12
12
|
/** Milliseconds for an HTTP timeout, or `false` to disable it. */
|
|
13
13
|
export declare const HttpTimeout: Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>;
|
|
14
14
|
export type HttpTimeout = Schema.Schema.Type<typeof HttpTimeout>;
|
|
15
|
-
/** Applied to `
|
|
15
|
+
/** Applied to `timeout.headers` when a request leaves it unset. */
|
|
16
16
|
export declare const DEFAULT_HTTP_TIMEOUT_MS = 300000;
|
|
17
17
|
/**
|
|
18
|
-
* Applied to `
|
|
18
|
+
* Applied to `timeout.chunk` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
|
|
19
19
|
* clients to allow at least 15 minutes, because their models can stream nothing for minutes while they reason.
|
|
20
20
|
*/
|
|
21
21
|
export declare const DEFAULT_CHUNK_TIMEOUT_MS = 900000;
|
|
22
22
|
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
|
|
23
23
|
export declare const RequestEncoding: Schema.Literals<readonly ["zstd", "gzip", "none"]>;
|
|
24
24
|
export type RequestEncoding = Schema.Schema.Type<typeof RequestEncoding>;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly timeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
31
|
-
/** Time allowed for response headers to arrive. */
|
|
32
|
-
readonly headerTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
33
|
-
/** Time allowed between streamed response chunks once headers have arrived. */
|
|
34
|
-
readonly chunkTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
25
|
+
/** Rare wire-level overrides. */
|
|
26
|
+
export interface HttpOptions {
|
|
27
|
+
readonly query?: Record<string, string>;
|
|
28
|
+
/** Deep-merged over the provider-native JSON body. */
|
|
29
|
+
readonly body?: Record<string, unknown>;
|
|
35
30
|
/** Compression for JSON request bodies. Only set it for endpoints known to decode it. */
|
|
36
|
-
readonly encoding
|
|
37
|
-
}>, {}>;
|
|
38
|
-
export declare class HttpOptions extends HttpOptions_base {
|
|
31
|
+
readonly encoding?: RequestEncoding;
|
|
39
32
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
/** Per-phase time limits in milliseconds. */
|
|
34
|
+
export interface TimeoutConfig {
|
|
35
|
+
/** The whole request, from send until the response completes. Unbounded when unset. */
|
|
36
|
+
readonly total?: HttpTimeout;
|
|
37
|
+
/** Until response headers arrive. */
|
|
38
|
+
readonly headers?: HttpTimeout;
|
|
39
|
+
/** Between streamed response chunks once headers have arrived. */
|
|
40
|
+
readonly chunk?: HttpTimeout;
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
readonly
|
|
52
|
-
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
readonly stop: Schema.optional<Schema.$Array<Schema.String>>;
|
|
56
|
-
}>, {}>;
|
|
57
|
-
export declare class GenerationOptions extends GenerationOptions_base {
|
|
42
|
+
/** Milliseconds for the whole request, `false` to disable it, or per-phase limits. */
|
|
43
|
+
export type RequestTimeout = HttpTimeout | TimeoutConfig;
|
|
44
|
+
/** Transport settings shared by requests, models and routes. */
|
|
45
|
+
export interface TransportOptions {
|
|
46
|
+
/** Merged over the provider's headers; these win. */
|
|
47
|
+
readonly headers?: Record<string, string>;
|
|
48
|
+
/** Applied to text requests; media requests do not apply it yet. */
|
|
49
|
+
readonly timeout?: RequestTimeout;
|
|
50
|
+
readonly http?: HttpOptions;
|
|
58
51
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
/** The fields every request shares, whatever its modality. */
|
|
53
|
+
export interface BaseRequest<Model, Options = ProviderOptions> extends TransportOptions {
|
|
54
|
+
readonly model: Model;
|
|
55
|
+
readonly providerOptions?: Options;
|
|
56
|
+
/** Sends this call through `fetch` instead of the client's HTTP executor. */
|
|
57
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
63
58
|
}
|
|
64
|
-
export
|
|
59
|
+
export declare const timeoutConfig: (timeout: RequestTimeout | undefined) => TimeoutConfig;
|
|
60
|
+
/** Merge transport settings; later items win, headers, query and body merge by key. */
|
|
61
|
+
export declare const mergeTransport: (...items: ReadonlyArray<TransportOptions | undefined>) => TransportOptions;
|
|
62
|
+
/** Portable sampling knobs, set at the top level of text requests, model defaults and route defaults. */
|
|
63
|
+
export interface GenerationOptionsFields {
|
|
65
64
|
readonly maxTokens?: number;
|
|
66
65
|
readonly temperature?: number;
|
|
67
66
|
readonly topP?: number;
|
|
@@ -70,25 +69,17 @@ export type GenerationOptionsFields = {
|
|
|
70
69
|
readonly presencePenalty?: number;
|
|
71
70
|
readonly seed?: number;
|
|
72
71
|
readonly stop?: ReadonlyArray<string>;
|
|
73
|
-
};
|
|
74
|
-
export type GenerationOptionsInput = GenerationOptions | GenerationOptionsFields;
|
|
75
|
-
export declare const mergeGenerationOptions: (...items: ReadonlyArray<GenerationOptionsInput | undefined>) => GenerationOptions | undefined;
|
|
76
|
-
declare const LanguageModelDefaults_base: Schema.Class<LanguageModelDefaults, Schema.Struct<{
|
|
77
|
-
readonly generation: Schema.optional<typeof GenerationOptions>;
|
|
78
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
79
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
80
|
-
}>, {}>;
|
|
81
|
-
export declare class LanguageModelDefaults extends LanguageModelDefaults_base {
|
|
82
72
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const make: (input: Input) => LanguageModelDefaults;
|
|
73
|
+
/** The keys of `GenerationOptionsFields`, for splitting a flat record into portable knobs and provider options. */
|
|
74
|
+
export declare const GENERATION_KEYS: ReadonlySet<string>;
|
|
75
|
+
/** Pick the generation knobs out of each item; later items win per knob. */
|
|
76
|
+
export declare const mergeGeneration: (...items: ReadonlyArray<GenerationOptionsFields | undefined>) => GenerationOptionsFields;
|
|
77
|
+
/** Request options a model applies under each request: the same keys as a request, and the request wins. */
|
|
78
|
+
export interface RequestOptions extends TransportOptions, GenerationOptionsFields {
|
|
79
|
+
readonly providerOptions?: ProviderOptions;
|
|
91
80
|
}
|
|
81
|
+
/** Merge model options; later items win per key. Empty results are `undefined`. */
|
|
82
|
+
export declare const mergeRequestOptions: (...items: ReadonlyArray<RequestOptions | undefined>) => RequestOptions | undefined;
|
|
92
83
|
/** Provider-defined string enum: known values for autocomplete, any string accepted. */
|
|
93
84
|
export type OpenString<Known extends string> = Known | (string & {});
|
|
94
85
|
export declare const ReasoningEfforts: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
@@ -109,19 +100,12 @@ declare const LanguageModelCompatibility_base: Schema.Class<LanguageModelCompati
|
|
|
109
100
|
readonly maxTokensField: Schema.optional<Schema.Literals<readonly ["max_completion_tokens", "max_tokens"]>>;
|
|
110
101
|
readonly requireFinishReason: Schema.optional<Schema.Boolean>;
|
|
111
102
|
readonly requireAssistantAfterTool: Schema.optional<Schema.Boolean>;
|
|
112
|
-
readonly supportsStore: Schema.optional<Schema.Boolean>;
|
|
113
|
-
/** Request usage in the stream with `stream_options.include_usage`. Defaults to true. */
|
|
114
|
-
readonly streamUsage: Schema.optional<Schema.Boolean>;
|
|
115
|
-
readonly supportsStrictMode: Schema.optional<Schema.Boolean>;
|
|
116
|
-
readonly supportsPromptCacheKey: Schema.optional<Schema.Boolean>;
|
|
117
103
|
/** Prompt-cache marker syntax the endpoint accepts. Overrides the route default; both send `cache_control`, and `alibaba` skips tool definitions. */
|
|
118
104
|
readonly cacheFormat: Schema.optional<Schema.Literals<readonly ["anthropic", "alibaba"]>>;
|
|
119
105
|
readonly zaiToolStream: Schema.optional<Schema.Boolean>;
|
|
120
106
|
readonly requireSignature: Schema.optional<Schema.Boolean>;
|
|
121
107
|
/** Supports Anthropic's thinking-prefix mismatch controls. Overrides model-ID detection. */
|
|
122
108
|
readonly supportsThinkingBlockBinding: Schema.optional<Schema.Boolean>;
|
|
123
|
-
/** Supports per-message effort updates. Overrides model-ID detection. */
|
|
124
|
-
readonly supportsEffortUpdates: Schema.optional<Schema.Boolean>;
|
|
125
109
|
}>, {}>;
|
|
126
110
|
export declare class LanguageModelCompatibility extends LanguageModelCompatibility_base {
|
|
127
111
|
}
|
|
@@ -130,12 +114,75 @@ export declare namespace LanguageModelCompatibility {
|
|
|
130
114
|
/** Normalize model/upstream compatibility metadata without projecting requests. */
|
|
131
115
|
const make: (input: Input) => LanguageModelCompatibility;
|
|
132
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* What the model accepts on its API: models.dev v2 `capabilities` in camelCase, with the API's own overrides merged in.
|
|
119
|
+
* Unset fields keep the protocol default, which may still guess from the provider, base URL or model ID.
|
|
120
|
+
*/
|
|
121
|
+
export interface Capabilities {
|
|
122
|
+
readonly tools?: {
|
|
123
|
+
readonly supported?: boolean;
|
|
124
|
+
/** Accepts `strict` on function tools. OpenAI Chat detects it from the provider when unset. */
|
|
125
|
+
readonly strict?: boolean;
|
|
126
|
+
readonly choice?: ReadonlyArray<"auto" | "none" | "required" | "tool">;
|
|
127
|
+
readonly search?: boolean;
|
|
128
|
+
/** Input formats accepted by custom (free-form) tools. */
|
|
129
|
+
readonly freeform?: ReadonlyArray<"text" | "lark" | "regex">;
|
|
130
|
+
/** Accepts a changed tool list mid-conversation. */
|
|
131
|
+
readonly updates?: boolean;
|
|
132
|
+
};
|
|
133
|
+
readonly reasoning?: {
|
|
134
|
+
readonly supported?: boolean;
|
|
135
|
+
readonly default?: {
|
|
136
|
+
readonly type: "toggle";
|
|
137
|
+
readonly value: boolean;
|
|
138
|
+
} | {
|
|
139
|
+
readonly type: "effort";
|
|
140
|
+
readonly value: ReasoningEffort;
|
|
141
|
+
} | {
|
|
142
|
+
readonly type: "budget";
|
|
143
|
+
readonly value: number;
|
|
144
|
+
};
|
|
145
|
+
readonly toggle?: boolean;
|
|
146
|
+
readonly effort?: ReadonlyArray<ReasoningEffort>;
|
|
147
|
+
readonly budget?: {
|
|
148
|
+
readonly min?: number;
|
|
149
|
+
readonly max?: number;
|
|
150
|
+
};
|
|
151
|
+
/** Accepts per-message effort updates. Detected from the model ID when unset. */
|
|
152
|
+
readonly updates?: boolean;
|
|
153
|
+
};
|
|
154
|
+
readonly cache?: false | {
|
|
155
|
+
readonly implicit?: true | {
|
|
156
|
+
readonly ttl?: ReadonlyArray<CacheTTL>;
|
|
157
|
+
readonly minTokens?: number;
|
|
158
|
+
};
|
|
159
|
+
readonly explicit?: true | {
|
|
160
|
+
readonly ttl?: ReadonlyArray<CacheTTL>;
|
|
161
|
+
readonly maxBreakpoints?: number;
|
|
162
|
+
readonly targets?: ReadonlyArray<"tools" | "system" | "messages">;
|
|
163
|
+
readonly minTokens?: number;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
readonly structuredOutput?: boolean;
|
|
167
|
+
readonly temperature?: boolean;
|
|
168
|
+
readonly topP?: boolean;
|
|
169
|
+
readonly topK?: boolean;
|
|
170
|
+
/** Accepts mid-conversation system messages. Anthropic Messages detects it from the model ID when unset. */
|
|
171
|
+
readonly systemUpdates?: boolean;
|
|
172
|
+
/** Accepts `store`. OpenAI Chat detects it from the provider when unset. */
|
|
173
|
+
readonly store?: boolean;
|
|
174
|
+
/** Accepts `stream_options.include_usage`. OpenAI Chat defaults to true. */
|
|
175
|
+
readonly streamUsage?: boolean;
|
|
176
|
+
readonly promptCacheKey?: boolean;
|
|
177
|
+
readonly serviceTier?: ReadonlyArray<OpenString<"flex" | "priority" | "fast" | "ultrafast" | "standby">>;
|
|
178
|
+
}
|
|
133
179
|
export declare class LanguageModel<Options extends ProviderOptions = ProviderOptions, Compact extends CompactionOperations | undefined = CompactionOperations | undefined> {
|
|
134
180
|
protected readonly _ProviderOptions: Options;
|
|
135
181
|
readonly id: ModelID;
|
|
136
182
|
readonly provider: ProviderID;
|
|
137
183
|
readonly route: AnyRoute<Compact>;
|
|
138
|
-
readonly
|
|
184
|
+
readonly options?: RequestOptions;
|
|
185
|
+
readonly capabilities?: Capabilities;
|
|
139
186
|
readonly compatibility?: LanguageModelCompatibility;
|
|
140
187
|
constructor(input: LanguageModel.ConstructorInput<Compact>);
|
|
141
188
|
static make<Options extends ProviderOptions = ProviderOptions, Compact extends CompactionOperations | undefined = CompactionOperations | undefined>(input: LanguageModel.Input<Compact>): LanguageModel<Options, Compact>;
|
|
@@ -153,13 +200,13 @@ export declare namespace LanguageModel {
|
|
|
153
200
|
readonly id: ModelID;
|
|
154
201
|
readonly provider: ProviderID;
|
|
155
202
|
readonly route: AnyRoute<Compact>;
|
|
156
|
-
readonly
|
|
203
|
+
readonly options?: RequestOptions;
|
|
204
|
+
readonly capabilities?: Capabilities;
|
|
157
205
|
readonly compatibility?: LanguageModelCompatibility;
|
|
158
206
|
};
|
|
159
|
-
type Input<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Omit<ConstructorInput<Compact>, "id" | "provider" | "
|
|
207
|
+
type Input<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Omit<ConstructorInput<Compact>, "id" | "provider" | "compatibility"> & {
|
|
160
208
|
readonly id: string | ModelID;
|
|
161
209
|
readonly provider: string | ProviderID;
|
|
162
|
-
readonly defaults?: LanguageModelDefaults.Input;
|
|
163
210
|
readonly compatibility?: LanguageModelCompatibility.Input;
|
|
164
211
|
};
|
|
165
212
|
}
|