@opencode/ai 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +250 -24
- package/dist/protocols/open-responses.js +40 -24
- 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 +7 -3
- 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
|
@@ -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
|
+
...conversation,
|
|
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
|
};
|
|
@@ -11,7 +11,8 @@ export const PATH = "/videos";
|
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// 2. Token and response schemas
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
|
-
|
|
14
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
15
|
+
export const Token = Schema.String;
|
|
15
16
|
const StartResponse = Schema.Struct({ id: Schema.String, status: optionalNull(Schema.String) });
|
|
16
17
|
const Job = Schema.Struct({
|
|
17
18
|
id: optionalNull(Schema.String),
|
|
@@ -29,7 +30,7 @@ const Job = Schema.Struct({
|
|
|
29
30
|
// 3. Status
|
|
30
31
|
// ---------------------------------------------------------------------------
|
|
31
32
|
const STATUS = {
|
|
32
|
-
pending: "
|
|
33
|
+
pending: "running",
|
|
33
34
|
in_progress: "running",
|
|
34
35
|
completed: "completed",
|
|
35
36
|
failed: "failed",
|
|
@@ -77,20 +78,20 @@ const resolution = (value) => (/^\dk$/.test(value) ? value.toUpperCase() : value
|
|
|
77
78
|
// 5. Response decoding
|
|
78
79
|
// ---------------------------------------------------------------------------
|
|
79
80
|
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
80
|
-
token:
|
|
81
|
-
snapshot: { id: value.id,
|
|
81
|
+
token: value.id,
|
|
82
|
+
snapshot: { id: value.id, ...MediaProtocol.status(STATUS, value.status ?? "pending") },
|
|
82
83
|
}));
|
|
83
84
|
const decodeJob = route.decodeJson(Job);
|
|
84
85
|
const decodeStatus = Effect.fn("OpenRouterVideo.decodeStatus")(function* (response, context) {
|
|
85
86
|
const output = yield* decodeJob(response);
|
|
86
|
-
return { id: context.token
|
|
87
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
87
88
|
});
|
|
88
89
|
const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (response, context) {
|
|
89
90
|
const output = yield* decodeJob(response);
|
|
90
91
|
const job = output.value;
|
|
91
|
-
const status = MediaProtocol.
|
|
92
|
-
if (status === "
|
|
93
|
-
return yield* output.pending(context.token
|
|
92
|
+
const status = MediaProtocol.state(STATUS, job.status);
|
|
93
|
+
if (status === "running")
|
|
94
|
+
return yield* output.pending(context.token);
|
|
94
95
|
if (status === "failed") {
|
|
95
96
|
const message = `${route.name} generation failed${job.error ? `: ${job.error}` : ""}`;
|
|
96
97
|
if (job.error && /content policy|moderat/i.test(job.error))
|
|
@@ -98,21 +99,21 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
|
|
|
98
99
|
return yield* output.ended("failed", message);
|
|
99
100
|
}
|
|
100
101
|
if (status !== "completed")
|
|
101
|
-
return yield* output.ended(status, `${route.name} job ${context.token
|
|
102
|
+
return yield* output.ended(status, `${route.name} job ${context.token} ${status}${job.error ? `: ${job.error}` : ""}`);
|
|
102
103
|
const urls = job.unsigned_urls ?? [];
|
|
103
104
|
if (urls.length === 0)
|
|
104
105
|
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
105
106
|
// The content URLs are OpenRouter's own and only download with the API key.
|
|
106
|
-
const videos = yield* Effect.forEach(urls, (url) => context.
|
|
107
|
+
const videos = yield* Effect.forEach(urls, (url) => context.credentials(url).pipe(Effect.map((credentials) => Media.url(url, {
|
|
107
108
|
mediaType: "video/mp4",
|
|
108
109
|
expiresAt: job.expires_at === undefined || job.expires_at === null ? undefined : job.expires_at * 1000,
|
|
109
|
-
|
|
110
|
+
...credentials,
|
|
110
111
|
}))));
|
|
111
112
|
return new VideoResponse({
|
|
112
113
|
videos,
|
|
113
114
|
providerMetadata: {
|
|
114
115
|
openrouter: {
|
|
115
|
-
id: context.token
|
|
116
|
+
id: context.token,
|
|
116
117
|
generationId: job.generation_id ?? undefined,
|
|
117
118
|
cost: job.usage?.cost ?? undefined,
|
|
118
119
|
isByok: job.usage?.is_byok ?? undefined,
|
|
@@ -123,7 +124,7 @@ const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (respon
|
|
|
123
124
|
// ---------------------------------------------------------------------------
|
|
124
125
|
// 6. Protocol and route
|
|
125
126
|
// ---------------------------------------------------------------------------
|
|
126
|
-
const jobPath = (token) => `${PATH}/${encodeURIComponent(token
|
|
127
|
+
const jobPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
127
128
|
// OpenRouter has no cancel endpoint; `cancelled` only appears when it stops a job itself.
|
|
128
129
|
export const protocol = MediaProtocol.queued(route, {
|
|
129
130
|
token: Token,
|
|
@@ -29,22 +29,17 @@ export type SeedanceVideoOptions = {
|
|
|
29
29
|
readonly safety_identifier?: string;
|
|
30
30
|
} & Record<string, unknown>;
|
|
31
31
|
export type Request = VideoRequest<VideoModel<SeedanceVideoOptions>>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}>;
|
|
32
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
33
|
+
export declare const Token: Schema.String;
|
|
35
34
|
export type Token = Schema.Schema.Type<typeof Token>;
|
|
36
35
|
export type Provider = "volcengine" | "byteplus";
|
|
37
36
|
export declare const SeedanceVideo: {
|
|
38
37
|
readonly volcengine: {
|
|
39
|
-
protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
40
|
-
readonly taskID: string;
|
|
41
|
-
}>;
|
|
38
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
42
39
|
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
43
40
|
};
|
|
44
41
|
readonly byteplus: {
|
|
45
|
-
protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
46
|
-
readonly taskID: string;
|
|
47
|
-
}>;
|
|
42
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
48
43
|
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
49
44
|
};
|
|
50
45
|
};
|
|
@@ -14,7 +14,8 @@ const OUTPUT_RETENTION = Duration.hours(24);
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// 2. Token and response schemas
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
|
-
|
|
17
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
18
|
+
export const Token = Schema.String;
|
|
18
19
|
const StartResponse = Schema.Struct({ id: Schema.String });
|
|
19
20
|
const Task = Schema.Struct({
|
|
20
21
|
id: optionalNull(Schema.String),
|
|
@@ -45,7 +46,7 @@ const Task = Schema.Struct({
|
|
|
45
46
|
service_tier: optionalNull(Schema.String),
|
|
46
47
|
});
|
|
47
48
|
const STATUS = {
|
|
48
|
-
queued: "
|
|
49
|
+
queued: "running",
|
|
49
50
|
running: "running",
|
|
50
51
|
succeeded: "completed",
|
|
51
52
|
failed: "failed",
|
|
@@ -125,20 +126,20 @@ const make = (provider) => {
|
|
|
125
126
|
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
126
127
|
});
|
|
127
128
|
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
128
|
-
token:
|
|
129
|
-
snapshot: { id: value.id, status: "
|
|
129
|
+
token: value.id,
|
|
130
|
+
snapshot: { id: value.id, status: "running" },
|
|
130
131
|
}));
|
|
131
132
|
const decodeTask = route.decodeJson(Task);
|
|
132
133
|
const decodeStatus = Effect.fn("SeedanceVideo.decodeStatus")(function* (response, context) {
|
|
133
134
|
const output = yield* decodeTask(response);
|
|
134
|
-
return { id: context.token
|
|
135
|
+
return { id: context.token, ...MediaProtocol.status(STATUS, output.value.status) };
|
|
135
136
|
});
|
|
136
137
|
const decodeResult = Effect.fn("SeedanceVideo.decodeResult")(function* (response, context) {
|
|
137
138
|
const output = yield* decodeTask(response);
|
|
138
139
|
const task = output.value;
|
|
139
|
-
const status = MediaProtocol.
|
|
140
|
-
if (status === "
|
|
141
|
-
return yield* output.pending(context.token
|
|
140
|
+
const status = MediaProtocol.state(STATUS, task.status);
|
|
141
|
+
if (status === "running")
|
|
142
|
+
return yield* output.pending(context.token);
|
|
142
143
|
if (status === "failed") {
|
|
143
144
|
const code = task.error?.code ?? undefined;
|
|
144
145
|
const detail = task.error?.message ?? undefined;
|
|
@@ -148,9 +149,9 @@ const make = (provider) => {
|
|
|
148
149
|
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, code?.split(".")[0]));
|
|
149
150
|
}
|
|
150
151
|
if (status === "cancelled")
|
|
151
|
-
return yield* output.ended("cancelled", `${route.name} task ${context.token
|
|
152
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token} was cancelled`);
|
|
152
153
|
if (status === "expired")
|
|
153
|
-
return yield* output.ended("expired", `${route.name} task ${context.token
|
|
154
|
+
return yield* output.ended("expired", `${route.name} task ${context.token} expired`);
|
|
154
155
|
const videoURL = task.content?.video_url ?? undefined;
|
|
155
156
|
if (videoURL === undefined)
|
|
156
157
|
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
@@ -177,7 +178,7 @@ const make = (provider) => {
|
|
|
177
178
|
},
|
|
178
179
|
providerMetadata: {
|
|
179
180
|
[provider]: {
|
|
180
|
-
taskId: context.token
|
|
181
|
+
taskId: context.token,
|
|
181
182
|
model: task.model ?? undefined,
|
|
182
183
|
seed: task.seed ?? undefined,
|
|
183
184
|
ratio: task.ratio ?? undefined,
|
|
@@ -194,7 +195,7 @@ const make = (provider) => {
|
|
|
194
195
|
},
|
|
195
196
|
});
|
|
196
197
|
});
|
|
197
|
-
const taskPath = (token) => `${PATH}/${token
|
|
198
|
+
const taskPath = (token) => `${PATH}/${encodeURIComponent(token)}`;
|
|
198
199
|
// DELETE cancels a queued task. Ark refuses it for a running task, and deletes the record of a finished one.
|
|
199
200
|
const protocol = MediaProtocol.queued(route, {
|
|
200
201
|
token: Token,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
2
|
import { AIError, InvalidProviderOutputError, CompactionPart, CompactionResponse, Message, mergeJsonRecords, } from "../../schema/index.js";
|
|
3
3
|
import { stripEffortUpdates } from "../../effort-updates.js";
|
|
4
|
+
import { foldToolUpdates } from "../../tool-updates.js";
|
|
4
5
|
import { Endpoint } from "../../route/endpoint.js";
|
|
5
6
|
import { RequestExecutor } from "../../route/executor.js";
|
|
6
7
|
import { HttpTransport } from "../../route/transport/index.js";
|
|
@@ -62,10 +63,13 @@ const Response = Schema.Struct({
|
|
|
62
63
|
});
|
|
63
64
|
export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.execute")(function* (request, executor, options) {
|
|
64
65
|
const route = request.model.route;
|
|
65
|
-
// The standalone compaction endpoint rejects
|
|
66
|
-
|
|
66
|
+
// The standalone compaction endpoint rejects effort updates (`configuration_update`). Every tool goes in
|
|
67
|
+
// top-level `tools`: after compacting a history whose tools were only in `additional_tools`, small models lost
|
|
68
|
+
// track of them more often.
|
|
69
|
+
const folded = foldToolUpdates(stripEffortUpdates(request));
|
|
70
|
+
const native = yield* OpenResponses.lowerConversation(folded, adapter);
|
|
67
71
|
const generation = OpenResponses.lowerGeneration(request);
|
|
68
|
-
const tools =
|
|
72
|
+
const tools = folded.tools.length === 0 ? undefined : yield* lowerTools(folded);
|
|
69
73
|
const body = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))(mergeJsonRecords({
|
|
70
74
|
...native,
|
|
71
75
|
service_tier: generation.service_tier,
|
|
@@ -12,6 +12,32 @@ export declare const protocol: Protocol<{
|
|
|
12
12
|
readonly reasoning: {
|
|
13
13
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
14
14
|
};
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "additional_tools";
|
|
17
|
+
readonly role: "developer";
|
|
18
|
+
readonly tools: readonly ({
|
|
19
|
+
readonly type: "custom";
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly format: {
|
|
23
|
+
readonly type: "text";
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "grammar";
|
|
26
|
+
readonly syntax: "lark" | "regex";
|
|
27
|
+
readonly definition: string;
|
|
28
|
+
};
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "function";
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly parameters: {
|
|
34
|
+
readonly [x: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
readonly strict?: boolean | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
readonly [x: string]: unknown;
|
|
39
|
+
readonly type: string;
|
|
40
|
+
})[];
|
|
15
41
|
} | {
|
|
16
42
|
readonly type: "message";
|
|
17
43
|
readonly role: "system";
|
|
@@ -24,17 +24,12 @@ export type XAIVideoOptions = {
|
|
|
24
24
|
}>;
|
|
25
25
|
} & Record<string, unknown>;
|
|
26
26
|
export type Request = VideoRequest<VideoModel<XAIVideoOptions>>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}>;
|
|
27
|
+
/** The provider's job ID; it is all a later status, result or cancel call needs. */
|
|
28
|
+
export declare const Token: Schema.String;
|
|
30
29
|
export type Token = Schema.Schema.Type<typeof Token>;
|
|
31
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
32
|
-
readonly requestID: string;
|
|
33
|
-
}>;
|
|
30
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
34
31
|
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<XAIVideoOptions>;
|
|
35
32
|
export declare const XAIVideo: {
|
|
36
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse,
|
|
37
|
-
readonly requestID: string;
|
|
38
|
-
}>;
|
|
33
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, string>;
|
|
39
34
|
readonly model: typeof model;
|
|
40
35
|
};
|