@opencode/ai 2.3.0 → 2.3.2
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 +65 -18
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +3 -1
- package/dist/generation.d.ts +10 -10
- package/dist/generation.js +8 -14
- package/dist/image-client.d.ts +56 -59
- package/dist/image-client.js +47 -8
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +25 -25
- package/dist/index.js +29 -22
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/media-client.d.ts +18 -6
- package/dist/media-client.js +42 -37
- package/dist/media.d.ts +17 -1
- package/dist/media.js +28 -7
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/assemblyai-transcription.js +7 -6
- package/dist/protocols/cartesia-speech.d.ts +0 -8
- package/dist/protocols/deepgram-speech.d.ts +0 -8
- package/dist/protocols/elevenlabs-speech.d.ts +0 -8
- package/dist/protocols/google-interactions-video.d.ts +4 -9
- package/dist/protocols/google-interactions-video.js +9 -10
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/minimax-video.d.ts +6 -15
- package/dist/protocols/minimax-video.js +25 -27
- package/dist/protocols/open-responses.d.ts +410 -138
- package/dist/protocols/open-responses.js +47 -28
- package/dist/protocols/openai-chat.js +7 -3
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-images.d.ts +0 -8
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/openai-speech.d.ts +0 -8
- package/dist/protocols/openai-transcription.d.ts +0 -8
- package/dist/protocols/openrouter-video.d.ts +4 -9
- package/dist/protocols/openrouter-video.js +14 -13
- package/dist/protocols/seedance-video.d.ts +4 -9
- package/dist/protocols/seedance-video.js +13 -12
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +14 -4
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +4 -9
- package/dist/protocols/xai-video.js +13 -9
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/google.d.ts +3 -3
- package/dist/providers/google.js +5 -2
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax.d.ts +50 -2
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter.d.ts +26 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +4 -3
- package/dist/providers/xai.js +5 -1
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +5 -4
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +14 -1
- package/dist/route/executor-service.js +28 -1
- package/dist/route/executor.d.ts +5 -2
- package/dist/route/executor.js +20 -5
- package/dist/route/media-protocol.d.ts +12 -7
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.js +12 -3
- package/dist/route/protocol.d.ts +3 -0
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +24 -1
- package/dist/schema/messages.js +26 -2
- package/dist/schema/options.d.ts +10 -2
- package/dist/speech-client.d.ts +5 -5
- package/dist/speech.d.ts +7 -88
- package/dist/speech.js +1 -3
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/dist/transcription-client.d.ts +5 -5
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +6 -6
- package/dist/video-client.js +13 -11
- package/dist/video.d.ts +17 -73
- package/dist/video.js +9 -8
- package/package.json +7 -3
|
@@ -5,6 +5,7 @@ import { AIError, LLMEvent, ProviderInternalError, Usage, } from "../schema/inde
|
|
|
5
5
|
import { JsonObject, lenient, optionalArray, optionalNull, optionalNullish, ProviderShared, withUntypedFrames, } from "./shared.js";
|
|
6
6
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
7
7
|
import { effortUpdate } from "../effort-updates.js";
|
|
8
|
+
import { toolsUpdate } from "../tool-updates.js";
|
|
8
9
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
9
10
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
10
11
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
@@ -126,9 +127,40 @@ export const HostedToolReplay = Schema.StructWithRest(Schema.Struct({
|
|
|
126
127
|
type: Schema.String,
|
|
127
128
|
id: Schema.String,
|
|
128
129
|
}), [JsonObject]);
|
|
130
|
+
export const Tool = Schema.Struct({
|
|
131
|
+
type: Schema.tag("function"),
|
|
132
|
+
name: Schema.String,
|
|
133
|
+
description: Schema.String,
|
|
134
|
+
parameters: JsonObject,
|
|
135
|
+
strict: Schema.optional(Schema.Boolean),
|
|
136
|
+
});
|
|
137
|
+
export const CustomTool = Schema.Struct({
|
|
138
|
+
type: Schema.tag("custom"),
|
|
139
|
+
name: Schema.String,
|
|
140
|
+
description: Schema.String,
|
|
141
|
+
format: Schema.Union([
|
|
142
|
+
Schema.Struct({ type: Schema.tag("text") }),
|
|
143
|
+
Schema.Struct({
|
|
144
|
+
type: Schema.tag("grammar"),
|
|
145
|
+
syntax: Schema.Literals(["lark", "regex"]),
|
|
146
|
+
definition: Schema.String,
|
|
147
|
+
}),
|
|
148
|
+
]),
|
|
149
|
+
});
|
|
150
|
+
export const HostedTool = Schema.StructWithRest(Schema.Struct({
|
|
151
|
+
type: Schema.String,
|
|
152
|
+
}), [JsonObject]);
|
|
153
|
+
const NamedTool = Schema.Struct({ type: Schema.Literals(["function", "custom"]), name: Schema.String });
|
|
154
|
+
// Tools added mid-conversation. Only the OpenAI extension lowers it; other hosts fold tool updates.
|
|
155
|
+
export const AdditionalTools = Schema.Struct({
|
|
156
|
+
type: Schema.Literal("additional_tools"),
|
|
157
|
+
role: Schema.Literal("developer"),
|
|
158
|
+
tools: Schema.Array(Schema.Union([Tool, CustomTool, HostedTool])),
|
|
159
|
+
});
|
|
129
160
|
export const InputItem = Schema.Union([
|
|
130
161
|
CompactionItem,
|
|
131
162
|
ConfigurationUpdate,
|
|
163
|
+
AdditionalTools,
|
|
132
164
|
Schema.Struct({ type: Schema.tag("message"), role: Schema.tag("system"), content: Schema.String }),
|
|
133
165
|
Schema.Struct({ type: Schema.tag("message"), role: Schema.tag("developer"), content: Schema.String }),
|
|
134
166
|
Schema.Struct({
|
|
@@ -170,30 +202,6 @@ export const InputItem = Schema.Union([
|
|
|
170
202
|
HostedToolItem,
|
|
171
203
|
HostedToolReplay,
|
|
172
204
|
]);
|
|
173
|
-
export const Tool = Schema.Struct({
|
|
174
|
-
type: Schema.tag("function"),
|
|
175
|
-
name: Schema.String,
|
|
176
|
-
description: Schema.String,
|
|
177
|
-
parameters: JsonObject,
|
|
178
|
-
strict: Schema.optional(Schema.Boolean),
|
|
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
|
-
});
|
|
193
|
-
export const HostedTool = Schema.StructWithRest(Schema.Struct({
|
|
194
|
-
type: Schema.String,
|
|
195
|
-
}), [JsonObject]);
|
|
196
|
-
const NamedTool = Schema.Struct({ type: Schema.Literals(["function", "custom"]), name: Schema.String });
|
|
197
205
|
export const ToolChoice = Schema.Union([
|
|
198
206
|
Schema.Literals(["auto", "none", "required"]),
|
|
199
207
|
NamedTool,
|
|
@@ -442,7 +450,7 @@ const lowerToolResultOutput = Effect.fnUntraced(function* (part, request, adapte
|
|
|
442
450
|
return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, adapter));
|
|
443
451
|
});
|
|
444
452
|
const DEFAULT_EFFORT = "medium";
|
|
445
|
-
const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
453
|
+
export const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
446
454
|
const input = [];
|
|
447
455
|
const providerMetadataKey = metadataKey(request.model);
|
|
448
456
|
const custom = OpenAIFreeform.tools(request);
|
|
@@ -462,6 +470,14 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
462
470
|
input.push({ type: "configuration_update", reasoning: { effort: update.effort ?? DEFAULT_EFFORT } });
|
|
463
471
|
continue;
|
|
464
472
|
}
|
|
473
|
+
// Planning folds every marker on routes whose protocol has no `toolUpdates`, so only adapters with
|
|
474
|
+
// `lowerToolChanges` see one.
|
|
475
|
+
const tools = toolsUpdate(message);
|
|
476
|
+
if (tools && adapter.lowerToolChanges) {
|
|
477
|
+
input.push(...(yield* adapter.lowerToolChanges(tools)));
|
|
478
|
+
if (message.content.length === 0)
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
465
481
|
input.push({
|
|
466
482
|
type: "message",
|
|
467
483
|
role: "developer",
|
|
@@ -597,12 +613,15 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
597
613
|
}
|
|
598
614
|
return input;
|
|
599
615
|
});
|
|
616
|
+
// The system prompt leads `input` as a developer message: GPT-6.2 models never cache top-level `instructions`.
|
|
600
617
|
export const lowerConversation = Effect.fnUntraced(function* (request, adapter) {
|
|
601
|
-
const
|
|
618
|
+
const system = ProviderShared.joinText(request.system);
|
|
602
619
|
return {
|
|
603
620
|
model: request.model.id,
|
|
604
|
-
input:
|
|
605
|
-
|
|
621
|
+
input: [
|
|
622
|
+
...(system ? [{ type: "message", role: "developer", content: system }] : []),
|
|
623
|
+
...(yield* lowerMessages(request, adapter)),
|
|
624
|
+
],
|
|
606
625
|
};
|
|
607
626
|
});
|
|
608
627
|
export const lowerGeneration = (request, options = OpenResponsesOptions.resolve(request)) => {
|
|
@@ -418,6 +418,9 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
418
418
|
})();
|
|
419
419
|
const opaque = reasoningOpaque(reasoning, options.providerMetadataKey);
|
|
420
420
|
const reasoningText = reasoning.length === 0 || (opaque !== undefined && text === "") ? (requireReasoning ? "" : undefined) : text;
|
|
421
|
+
// A model that declares a different reasoning field reads reasoning there, so structured details and opaque values
|
|
422
|
+
// from earlier turns (including another model served under the same provider metadata key) must not be replayed.
|
|
423
|
+
const replaysStructured = configuredField === undefined || configuredField === "reasoning_details";
|
|
421
424
|
const result = {
|
|
422
425
|
role: "assistant",
|
|
423
426
|
content: (() => {
|
|
@@ -428,10 +431,11 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
|
|
|
428
431
|
return content.map((part) => part.text).join("");
|
|
429
432
|
})(),
|
|
430
433
|
...(toolCalls.length > 0 ? { tool_calls: toolCalls } : {}),
|
|
431
|
-
...(details !== undefined ? { reasoning_details: details } : {}),
|
|
432
|
-
...(opaque !== undefined ? { reasoning_opaque: opaque } : {}),
|
|
434
|
+
...(details !== undefined && replaysStructured ? { reasoning_details: details } : {}),
|
|
435
|
+
...(opaque !== undefined && replaysStructured ? { reasoning_opaque: opaque } : {}),
|
|
433
436
|
};
|
|
434
|
-
|
|
437
|
+
// `reasoning_details` is the structured list itself, so scalar text must not be written over it.
|
|
438
|
+
if (field === undefined || reasoningText === undefined || field === "reasoning_details")
|
|
435
439
|
return result;
|
|
436
440
|
return { ...result, [field]: reasoningText };
|
|
437
441
|
});
|
|
@@ -11,6 +11,32 @@ export declare const route: Route<{
|
|
|
11
11
|
readonly reasoning: {
|
|
12
12
|
readonly effort: import("../public.js").ReasoningEffort;
|
|
13
13
|
};
|
|
14
|
+
} | {
|
|
15
|
+
readonly type: "additional_tools";
|
|
16
|
+
readonly role: "developer";
|
|
17
|
+
readonly tools: readonly ({
|
|
18
|
+
readonly type: "custom";
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly format: {
|
|
22
|
+
readonly type: "text";
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "grammar";
|
|
25
|
+
readonly syntax: "lark" | "regex";
|
|
26
|
+
readonly definition: string;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "function";
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly description: string;
|
|
32
|
+
readonly parameters: {
|
|
33
|
+
readonly [x: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
readonly strict?: boolean | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
readonly [x: string]: unknown;
|
|
38
|
+
readonly type: string;
|
|
39
|
+
})[];
|
|
14
40
|
} | {
|
|
15
41
|
readonly type: "message";
|
|
16
42
|
readonly role: "system";
|
|
@@ -7,7 +7,7 @@ export interface Custom {
|
|
|
7
7
|
}
|
|
8
8
|
/** How a tool goes out: a custom tool when it declares `freeform` with one required string parameter. */
|
|
9
9
|
export declare const resolve: (tool: ToolDefinition) => Custom | undefined;
|
|
10
|
-
/** Custom tools in this request, by flattened tool name. */
|
|
10
|
+
/** Custom tools in this request, including ones added mid-conversation, by flattened tool name. */
|
|
11
11
|
export declare const tools: (request: LLMRequest) => ReadonlyMap<string, Custom>;
|
|
12
12
|
/** The format's grammar, or `undefined` for unconstrained text. */
|
|
13
13
|
export declare const grammar: (format: Freeform) => {
|
|
@@ -2,6 +2,7 @@ import { Option, Schema } from "effect";
|
|
|
2
2
|
import { ToolDefinition, } from "../schema/index.js";
|
|
3
3
|
import { encodeJson, flattenTools, isRecord } from "./shared.js";
|
|
4
4
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
5
|
+
import { toolsUpdate } from "../tool-updates.js";
|
|
5
6
|
/** How a tool goes out: a custom tool when it declares `freeform` with one required string parameter. */
|
|
6
7
|
export const resolve = (tool) => {
|
|
7
8
|
const field = ToolDefinition.freeformField(tool.inputSchema);
|
|
@@ -9,11 +10,14 @@ export const resolve = (tool) => {
|
|
|
9
10
|
return undefined;
|
|
10
11
|
return { field, format: tool.freeform };
|
|
11
12
|
};
|
|
12
|
-
/** Custom tools in this request, by flattened tool name. */
|
|
13
|
-
export const tools = (request) =>
|
|
14
|
-
const
|
|
15
|
-
return
|
|
16
|
-
|
|
13
|
+
/** Custom tools in this request, including ones added mid-conversation, by flattened tool name. */
|
|
14
|
+
export const tools = (request) => {
|
|
15
|
+
const added = request.messages.flatMap((message) => toolsUpdate(message)?.add ?? []);
|
|
16
|
+
return new Map(flattenTools([...request.tools, ...added]).flatMap((tool) => {
|
|
17
|
+
const custom = resolve(tool);
|
|
18
|
+
return custom ? [[tool.name, custom]] : [];
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
17
21
|
/** The format's grammar, or `undefined` for unconstrained text. */
|
|
18
22
|
export const grammar = (format) => format.type === "text"
|
|
19
23
|
? undefined
|
|
@@ -58,10 +58,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
58
58
|
readonly type: "image";
|
|
59
59
|
readonly index: number;
|
|
60
60
|
readonly image: Media.Asset;
|
|
61
|
-
} | {
|
|
62
|
-
readonly type: "generation-queued";
|
|
63
|
-
readonly id: string;
|
|
64
|
-
readonly position?: number | undefined;
|
|
65
61
|
} | {
|
|
66
62
|
readonly type: "generation-progress";
|
|
67
63
|
readonly id: string;
|
|
@@ -113,10 +109,6 @@ export declare const OpenAIImages: {
|
|
|
113
109
|
readonly type: "image";
|
|
114
110
|
readonly index: number;
|
|
115
111
|
readonly image: Media.Asset;
|
|
116
|
-
} | {
|
|
117
|
-
readonly type: "generation-queued";
|
|
118
|
-
readonly id: string;
|
|
119
|
-
readonly position?: number | undefined;
|
|
120
112
|
} | {
|
|
121
113
|
readonly type: "generation-progress";
|
|
122
114
|
readonly id: string;
|
|
@@ -26,6 +26,29 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
26
26
|
readonly reasoning: Schema.Struct<{
|
|
27
27
|
readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
|
|
28
28
|
}>;
|
|
29
|
+
}>, Schema.Struct<{
|
|
30
|
+
readonly type: Schema.Literal<"additional_tools">;
|
|
31
|
+
readonly role: Schema.Literal<"developer">;
|
|
32
|
+
readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
33
|
+
readonly type: Schema.tag<"function">;
|
|
34
|
+
readonly name: Schema.String;
|
|
35
|
+
readonly description: Schema.String;
|
|
36
|
+
readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
37
|
+
readonly strict: Schema.optional<Schema.Boolean>;
|
|
38
|
+
}>, Schema.Struct<{
|
|
39
|
+
readonly type: Schema.tag<"custom">;
|
|
40
|
+
readonly name: Schema.String;
|
|
41
|
+
readonly description: Schema.String;
|
|
42
|
+
readonly format: Schema.Union<readonly [Schema.Struct<{
|
|
43
|
+
readonly type: Schema.tag<"text">;
|
|
44
|
+
}>, Schema.Struct<{
|
|
45
|
+
readonly type: Schema.tag<"grammar">;
|
|
46
|
+
readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
|
|
47
|
+
readonly definition: Schema.String;
|
|
48
|
+
}>]>;
|
|
49
|
+
}>, Schema.StructWithRest<Schema.Struct<{
|
|
50
|
+
readonly type: Schema.String;
|
|
51
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
|
|
29
52
|
}>, Schema.Struct<{
|
|
30
53
|
readonly type: Schema.tag<"message">;
|
|
31
54
|
readonly role: Schema.tag<"system">;
|
|
@@ -240,6 +263,32 @@ export declare const protocol: Protocol<{
|
|
|
240
263
|
readonly reasoning: {
|
|
241
264
|
readonly effort: OpenResponsesOptions.ReasoningEffort;
|
|
242
265
|
};
|
|
266
|
+
} | {
|
|
267
|
+
readonly type: "additional_tools";
|
|
268
|
+
readonly role: "developer";
|
|
269
|
+
readonly tools: readonly ({
|
|
270
|
+
readonly type: "custom";
|
|
271
|
+
readonly name: string;
|
|
272
|
+
readonly description: string;
|
|
273
|
+
readonly format: {
|
|
274
|
+
readonly type: "text";
|
|
275
|
+
} | {
|
|
276
|
+
readonly type: "grammar";
|
|
277
|
+
readonly syntax: "lark" | "regex";
|
|
278
|
+
readonly definition: string;
|
|
279
|
+
};
|
|
280
|
+
} | {
|
|
281
|
+
readonly type: "function";
|
|
282
|
+
readonly name: string;
|
|
283
|
+
readonly description: string;
|
|
284
|
+
readonly parameters: {
|
|
285
|
+
readonly [x: string]: unknown;
|
|
286
|
+
};
|
|
287
|
+
readonly strict?: boolean | undefined;
|
|
288
|
+
} | {
|
|
289
|
+
readonly [x: string]: unknown;
|
|
290
|
+
readonly type: string;
|
|
291
|
+
})[];
|
|
243
292
|
} | {
|
|
244
293
|
readonly type: "message";
|
|
245
294
|
readonly role: "system";
|
|
@@ -528,6 +577,32 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
528
577
|
readonly reasoning: {
|
|
529
578
|
readonly effort: OpenResponsesOptions.ReasoningEffort;
|
|
530
579
|
};
|
|
580
|
+
} | {
|
|
581
|
+
readonly type: "additional_tools";
|
|
582
|
+
readonly role: "developer";
|
|
583
|
+
readonly tools: readonly ({
|
|
584
|
+
readonly type: "custom";
|
|
585
|
+
readonly name: string;
|
|
586
|
+
readonly description: string;
|
|
587
|
+
readonly format: {
|
|
588
|
+
readonly type: "text";
|
|
589
|
+
} | {
|
|
590
|
+
readonly type: "grammar";
|
|
591
|
+
readonly syntax: "lark" | "regex";
|
|
592
|
+
readonly definition: string;
|
|
593
|
+
};
|
|
594
|
+
} | {
|
|
595
|
+
readonly type: "function";
|
|
596
|
+
readonly name: string;
|
|
597
|
+
readonly description: string;
|
|
598
|
+
readonly parameters: {
|
|
599
|
+
readonly [x: string]: unknown;
|
|
600
|
+
};
|
|
601
|
+
readonly strict?: boolean | undefined;
|
|
602
|
+
} | {
|
|
603
|
+
readonly [x: string]: unknown;
|
|
604
|
+
readonly type: string;
|
|
605
|
+
})[];
|
|
531
606
|
} | {
|
|
532
607
|
readonly type: "message";
|
|
533
608
|
readonly role: "system";
|
|
@@ -758,6 +833,32 @@ export declare const channelTransport: (options: import("./open-responses-channe
|
|
|
758
833
|
readonly reasoning: {
|
|
759
834
|
readonly effort: OpenResponsesOptions.ReasoningEffort;
|
|
760
835
|
};
|
|
836
|
+
} | {
|
|
837
|
+
readonly type: "additional_tools";
|
|
838
|
+
readonly role: "developer";
|
|
839
|
+
readonly tools: readonly ({
|
|
840
|
+
readonly type: "custom";
|
|
841
|
+
readonly name: string;
|
|
842
|
+
readonly description: string;
|
|
843
|
+
readonly format: {
|
|
844
|
+
readonly type: "text";
|
|
845
|
+
} | {
|
|
846
|
+
readonly type: "grammar";
|
|
847
|
+
readonly syntax: "lark" | "regex";
|
|
848
|
+
readonly definition: string;
|
|
849
|
+
};
|
|
850
|
+
} | {
|
|
851
|
+
readonly type: "function";
|
|
852
|
+
readonly name: string;
|
|
853
|
+
readonly description: string;
|
|
854
|
+
readonly parameters: {
|
|
855
|
+
readonly [x: string]: unknown;
|
|
856
|
+
};
|
|
857
|
+
readonly strict?: boolean | undefined;
|
|
858
|
+
} | {
|
|
859
|
+
readonly [x: string]: unknown;
|
|
860
|
+
readonly type: string;
|
|
861
|
+
})[];
|
|
761
862
|
} | {
|
|
762
863
|
readonly type: "message";
|
|
763
864
|
readonly role: "system";
|
|
@@ -988,6 +1089,32 @@ export declare const transport: import("../route/transport/index.js").Transport<
|
|
|
988
1089
|
readonly reasoning: {
|
|
989
1090
|
readonly effort: OpenResponsesOptions.ReasoningEffort;
|
|
990
1091
|
};
|
|
1092
|
+
} | {
|
|
1093
|
+
readonly type: "additional_tools";
|
|
1094
|
+
readonly role: "developer";
|
|
1095
|
+
readonly tools: readonly ({
|
|
1096
|
+
readonly type: "custom";
|
|
1097
|
+
readonly name: string;
|
|
1098
|
+
readonly description: string;
|
|
1099
|
+
readonly format: {
|
|
1100
|
+
readonly type: "text";
|
|
1101
|
+
} | {
|
|
1102
|
+
readonly type: "grammar";
|
|
1103
|
+
readonly syntax: "lark" | "regex";
|
|
1104
|
+
readonly definition: string;
|
|
1105
|
+
};
|
|
1106
|
+
} | {
|
|
1107
|
+
readonly type: "function";
|
|
1108
|
+
readonly name: string;
|
|
1109
|
+
readonly description: string;
|
|
1110
|
+
readonly parameters: {
|
|
1111
|
+
readonly [x: string]: unknown;
|
|
1112
|
+
};
|
|
1113
|
+
readonly strict?: boolean | undefined;
|
|
1114
|
+
} | {
|
|
1115
|
+
readonly [x: string]: unknown;
|
|
1116
|
+
readonly type: string;
|
|
1117
|
+
})[];
|
|
991
1118
|
} | {
|
|
992
1119
|
readonly type: "message";
|
|
993
1120
|
readonly role: "system";
|
|
@@ -1218,6 +1345,32 @@ export declare const route: Route<{
|
|
|
1218
1345
|
readonly reasoning: {
|
|
1219
1346
|
readonly effort: OpenResponsesOptions.ReasoningEffort;
|
|
1220
1347
|
};
|
|
1348
|
+
} | {
|
|
1349
|
+
readonly type: "additional_tools";
|
|
1350
|
+
readonly role: "developer";
|
|
1351
|
+
readonly tools: readonly ({
|
|
1352
|
+
readonly type: "custom";
|
|
1353
|
+
readonly name: string;
|
|
1354
|
+
readonly description: string;
|
|
1355
|
+
readonly format: {
|
|
1356
|
+
readonly type: "text";
|
|
1357
|
+
} | {
|
|
1358
|
+
readonly type: "grammar";
|
|
1359
|
+
readonly syntax: "lark" | "regex";
|
|
1360
|
+
readonly definition: string;
|
|
1361
|
+
};
|
|
1362
|
+
} | {
|
|
1363
|
+
readonly type: "function";
|
|
1364
|
+
readonly name: string;
|
|
1365
|
+
readonly description: string;
|
|
1366
|
+
readonly parameters: {
|
|
1367
|
+
readonly [x: string]: unknown;
|
|
1368
|
+
};
|
|
1369
|
+
readonly strict?: boolean | undefined;
|
|
1370
|
+
} | {
|
|
1371
|
+
readonly [x: string]: unknown;
|
|
1372
|
+
readonly type: string;
|
|
1373
|
+
})[];
|
|
1221
1374
|
} | {
|
|
1222
1375
|
readonly type: "message";
|
|
1223
1376
|
readonly role: "system";
|
|
@@ -8,6 +8,7 @@ import { Protocol } from "../route/protocol.js";
|
|
|
8
8
|
import { HttpTransport } from "../route/transport/index.js";
|
|
9
9
|
import { requestTTL } from "../cache-policy.js";
|
|
10
10
|
import { resolveEffortUpdates } from "../effort-updates.js";
|
|
11
|
+
import { addsTools, toolUpdateKinds } from "../tool-updates.js";
|
|
11
12
|
import { OpenResponses } from "./open-responses.js";
|
|
12
13
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
13
14
|
import { JsonObject, lenient, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
@@ -138,6 +139,19 @@ const supportsEffortUpdates = (request) => {
|
|
|
138
139
|
const match = /(?:^|\/)gpt-(\d+)(?:\.\d+)?(?:-|$)/i.exec(request.model.id);
|
|
139
140
|
return match !== null && Number(match[1]) >= 6;
|
|
140
141
|
};
|
|
142
|
+
// `additional_tools` adds tools, and redefines one by name only when that one was declared through `additional_tools`
|
|
143
|
+
// too. So a model whose `tools.updates` includes "add" gets every tool the request declares in a leading
|
|
144
|
+
// `additional_tools` item instead of top-level `tools`; without "add" nothing goes in place. Later additions and
|
|
145
|
+
// redefinitions ("replace") are later items. The API can't withdraw a tool, so a removal ("remove") is announced in
|
|
146
|
+
// a developer message and the tool stays declared. Hosted tools stay in `tools`, since the model doesn't use one
|
|
147
|
+
// declared in `additional_tools`, and changing one folds.
|
|
148
|
+
const toolUpdates = {
|
|
149
|
+
kinds: ["add", "remove", "replace"],
|
|
150
|
+
placeable: (request) => declaresInPlace(request),
|
|
151
|
+
declarable: (tool) => !isHostedTool(tool),
|
|
152
|
+
};
|
|
153
|
+
const isHostedTool = (tool) => tool.type === "tool" && tool.native !== undefined;
|
|
154
|
+
const declaresInPlace = (request) => toolUpdateKinds(request).includes("add");
|
|
141
155
|
const nativeImageToolInput = (tool) => {
|
|
142
156
|
const native = tool.native?.openai;
|
|
143
157
|
return ProviderShared.isRecord(native) && native.type === "image_generation" ? native : undefined;
|
|
@@ -172,10 +186,47 @@ const lowerToolEntry = Effect.fnUntraced(function* (tool, custom) {
|
|
|
172
186
|
tools: yield* Effect.forEach(ProviderShared.flattenTools(tool.tools), (leaf) => OpenResponses.lowerTool(NAME, leaf)),
|
|
173
187
|
};
|
|
174
188
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
189
|
+
// Lowers one request's tool updates, in message order. Every `additional_tools` item after the first is preceded by
|
|
190
|
+
// a hint that it adds to the tools declared before it, naming tools removed and not declared again since. Without
|
|
191
|
+
// it, models can read the latest item as the whole set.
|
|
192
|
+
const toolChangeLowering = (declaredInPlace, custom) => {
|
|
193
|
+
let declared = declaredInPlace;
|
|
194
|
+
const unavailable = new Set();
|
|
195
|
+
return Effect.fnUntraced(function* (changes) {
|
|
196
|
+
changes.add.forEach((tool) => unavailable.delete(tool.name));
|
|
197
|
+
const hint = declared && changes.add.length > 0 ? [developer(incrementalNotice([...unavailable]))] : [];
|
|
198
|
+
const additions = changes.add.length === 0
|
|
199
|
+
? []
|
|
200
|
+
: [
|
|
201
|
+
{
|
|
202
|
+
type: "additional_tools",
|
|
203
|
+
role: "developer",
|
|
204
|
+
tools: yield* Effect.forEach(changes.add, (tool) => lowerToolEntry(tool, custom)),
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
declared = declared || changes.add.length > 0;
|
|
208
|
+
changes.remove.forEach((name) => unavailable.add(name));
|
|
209
|
+
return [...hint, ...additions, ...(changes.remove.length === 0 ? [] : [developer(removalNotice(changes.remove))])];
|
|
210
|
+
});
|
|
178
211
|
};
|
|
212
|
+
const developer = (content) => ({ type: "message", role: "developer", content });
|
|
213
|
+
const incrementalNotice = (unavailable) => [
|
|
214
|
+
"Tool update: the tools below are added to the ones you already have. Earlier tools stay available unless marked unavailable, and a tool declared again replaces its earlier definition.",
|
|
215
|
+
...(unavailable.length === 0 ? [] : [`Still unavailable: ${unavailable.join(", ")}.`]),
|
|
216
|
+
].join("\n");
|
|
217
|
+
const removalNotice = (names) => `These tools are no longer available. Do not call them: ${names.join(", ")}.`;
|
|
218
|
+
// The leading declaration: top-level `tools`, or a leading `additional_tools` item on models that add tools in place.
|
|
219
|
+
const lowerToolLayout = Effect.fnUntraced(function* (request, custom) {
|
|
220
|
+
const lower = (tools) => Effect.forEach(tools, (tool) => lowerToolEntry(tool, custom));
|
|
221
|
+
const declared = declaresInPlace(request) ? request.tools.filter((tool) => !isHostedTool(tool)) : [];
|
|
222
|
+
const top = declared.length === 0 ? request.tools : request.tools.filter(isHostedTool);
|
|
223
|
+
return {
|
|
224
|
+
head: declared.length === 0
|
|
225
|
+
? []
|
|
226
|
+
: [{ type: "additional_tools", role: "developer", tools: yield* lower(declared) }],
|
|
227
|
+
tools: top.length === 0 ? undefined : yield* lower(top),
|
|
228
|
+
};
|
|
229
|
+
});
|
|
179
230
|
const lowerToolChoice = (toolChoice, tools, custom) => ProviderShared.matchToolChoice(NAME, toolChoice, {
|
|
180
231
|
auto: () => "auto",
|
|
181
232
|
none: () => "none",
|
|
@@ -191,8 +242,14 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
191
242
|
const updates = resolveEffortUpdates(request, options.reasoningEffort);
|
|
192
243
|
const generation = OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort });
|
|
193
244
|
const custom = OpenAIFreeform.tools(request);
|
|
245
|
+
const layout = yield* lowerToolLayout(request, custom);
|
|
246
|
+
const conversation = yield* OpenResponses.lowerConversation(updates.request, {
|
|
247
|
+
...adapter,
|
|
248
|
+
lowerToolChanges: toolChangeLowering(layout.head.length > 0, custom),
|
|
249
|
+
});
|
|
194
250
|
return {
|
|
195
|
-
|
|
251
|
+
model: conversation.model,
|
|
252
|
+
input: [...layout.head, ...conversation.input],
|
|
196
253
|
...generation,
|
|
197
254
|
...Cache.openAIRequestTTL(requestTTL(request)),
|
|
198
255
|
...(generation.reasoning || reasoning.reasoningMode || reasoning.reasoningContext
|
|
@@ -205,8 +262,8 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
205
262
|
}
|
|
206
263
|
: {}),
|
|
207
264
|
context_management: management?.map((edit) => ({ type: edit.type, compact_threshold: edit.compactThreshold })),
|
|
208
|
-
tools:
|
|
209
|
-
tool_choice: request.tools.length === 0
|
|
265
|
+
tools: layout.tools,
|
|
266
|
+
tool_choice: request.tools.length === 0 && !addsTools(request)
|
|
210
267
|
? undefined
|
|
211
268
|
: (OpenResponses.allowedToolChoice(options, custom) ??
|
|
212
269
|
(request.toolChoice ? yield* lowerToolChoice(request.toolChoice, request.tools, custom) : undefined)),
|
|
@@ -268,6 +325,7 @@ export const protocol = Protocol.make({
|
|
|
268
325
|
: ProviderShared.eventError(ADAPTER, `${event.type} is missing item_id`);
|
|
269
326
|
}),
|
|
270
327
|
supportsEffortUpdates,
|
|
328
|
+
toolUpdates,
|
|
271
329
|
});
|
|
272
330
|
const endpoint = Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL });
|
|
273
331
|
const auth = Auth.none;
|
|
@@ -281,7 +339,10 @@ export const transport = channelTransport({
|
|
|
281
339
|
});
|
|
282
340
|
export const route = Route.make({
|
|
283
341
|
compact: {
|
|
284
|
-
endpoint: ResponsesCompaction.make(adapter,
|
|
342
|
+
endpoint: ResponsesCompaction.make(adapter, (request) => {
|
|
343
|
+
const custom = OpenAIFreeform.tools(request);
|
|
344
|
+
return Effect.forEach(request.tools, (tool) => lowerToolEntry(tool, custom));
|
|
345
|
+
}),
|
|
285
346
|
trigger: ResponsesCheckpoint.make(checkpointBody),
|
|
286
347
|
},
|
|
287
348
|
id: ADAPTER,
|
|
@@ -25,10 +25,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
25
25
|
readonly startSeconds: number;
|
|
26
26
|
readonly endSeconds: number;
|
|
27
27
|
}[];
|
|
28
|
-
} | {
|
|
29
|
-
readonly type: "generation-queued";
|
|
30
|
-
readonly id: string;
|
|
31
|
-
readonly position?: number | undefined;
|
|
32
28
|
} | {
|
|
33
29
|
readonly type: "generation-progress";
|
|
34
30
|
readonly id: string;
|
|
@@ -75,10 +71,6 @@ export declare const OpenAISpeech: {
|
|
|
75
71
|
readonly startSeconds: number;
|
|
76
72
|
readonly endSeconds: number;
|
|
77
73
|
}[];
|
|
78
|
-
} | {
|
|
79
|
-
readonly type: "generation-queued";
|
|
80
|
-
readonly id: string;
|
|
81
|
-
readonly position?: number | undefined;
|
|
82
74
|
} | {
|
|
83
75
|
readonly type: "generation-progress";
|
|
84
76
|
readonly id: string;
|
|
@@ -69,10 +69,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
|
69
69
|
readonly endSeconds: number;
|
|
70
70
|
readonly speaker?: string | undefined;
|
|
71
71
|
};
|
|
72
|
-
} | {
|
|
73
|
-
readonly type: "generation-queued";
|
|
74
|
-
readonly id: string;
|
|
75
|
-
readonly position?: number | undefined;
|
|
76
72
|
} | {
|
|
77
73
|
readonly type: "generation-progress";
|
|
78
74
|
readonly id: string;
|
|
@@ -135,10 +131,6 @@ export declare const OpenAITranscription: {
|
|
|
135
131
|
readonly endSeconds: number;
|
|
136
132
|
readonly speaker?: string | undefined;
|
|
137
133
|
};
|
|
138
|
-
} | {
|
|
139
|
-
readonly type: "generation-queued";
|
|
140
|
-
readonly id: string;
|
|
141
|
-
readonly position?: number | undefined;
|
|
142
134
|
} | {
|
|
143
135
|
readonly type: "generation-progress";
|
|
144
136
|
readonly id: string;
|
|
@@ -25,17 +25,12 @@ export type OpenRouterVideoOptions = {
|
|
|
25
25
|
readonly session_id?: string;
|
|
26
26
|
} & Record<string, unknown>;
|
|
27
27
|
export type Request = VideoRequest<VideoModel<OpenRouterVideoOptions>>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}>;
|
|
28
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
29
|
+
export declare const Token: Schema.String;
|
|
31
30
|
export type Token = Schema.Schema.Type<typeof Token>;
|
|
32
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
33
|
-
readonly id: string;
|
|
34
|
-
}>;
|
|
31
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
35
32
|
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<OpenRouterVideoOptions>;
|
|
36
33
|
export declare const OpenRouterVideo: {
|
|
37
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
38
|
-
readonly id: string;
|
|
39
|
-
}>;
|
|
34
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
40
35
|
readonly model: typeof model;
|
|
41
36
|
};
|