@opencode/ai 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -62
- package/dist/effect.d.ts +1 -1
- package/dist/effect.js +1 -1
- package/dist/image-client.d.ts +45 -0
- package/dist/index.d.ts +38 -20
- package/dist/index.js +14 -2
- package/dist/media-client.d.ts +1 -0
- package/dist/media-client.js +1 -0
- package/dist/protocols/alibaba-chat.d.ts +39 -4
- package/dist/protocols/alibaba-responses.d.ts +20 -3
- package/dist/protocols/google-images.js +3 -1
- package/dist/protocols/meta-responses.d.ts +40 -6
- package/dist/protocols/meta-responses.js +1 -1
- package/dist/protocols/minimax-images.d.ts +25 -0
- package/dist/protocols/minimax-images.js +150 -0
- package/dist/protocols/open-responses.d.ts +182 -27
- package/dist/protocols/open-responses.js +108 -36
- package/dist/protocols/openai-chat.d.ts +438 -46
- package/dist/protocols/openai-chat.js +121 -39
- package/dist/protocols/openai-compatible-chat.d.ts +35 -4
- package/dist/protocols/openai-compatible-responses.d.ts +20 -3
- package/dist/protocols/openai-freeform.d.ts +47 -0
- package/dist/protocols/openai-freeform.js +54 -0
- package/dist/protocols/openai-images.d.ts +16 -1
- package/dist/protocols/openai-images.js +49 -17
- package/dist/protocols/openai-responses.d.ts +120 -18
- package/dist/protocols/openai-responses.js +17 -8
- package/dist/protocols/venice-chat.d.ts +39 -4
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/xai-images.d.ts +6 -0
- package/dist/protocols/xai-images.js +4 -5
- package/dist/protocols/xai-responses.d.ts +20 -3
- package/dist/protocols/xai-responses.js +2 -1
- package/dist/protocols/zai-chat.d.ts +39 -4
- package/dist/provider-error.js +5 -4
- package/dist/provider-package.d.ts +2 -0
- package/dist/providers/alibaba.d.ts +58 -10
- package/dist/providers/amazon-bedrock-mantle.d.ts +66 -11
- package/dist/providers/amazon-bedrock-mantle.js +1 -1
- package/dist/providers/amazon-bedrock.d.ts +1 -1
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/azure.d.ts +79 -15
- package/dist/providers/baseten.d.ts +74 -12
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +73 -11
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +113 -17
- package/dist/providers/cloudflare-workers-ai.d.ts +73 -11
- package/dist/providers/cohere/chat.d.ts +1 -1
- package/dist/providers/cohere/chat.js +1 -1
- package/dist/providers/cohere.d.ts +73 -11
- package/dist/providers/cohere.js +1 -1
- package/dist/providers/deepinfra.d.ts +73 -11
- package/dist/providers/deepinfra.js +1 -1
- package/dist/providers/deepseek.d.ts +73 -11
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/digitalocean/responses.d.ts +4 -0
- package/dist/providers/digitalocean/responses.js +1 -0
- package/dist/providers/digitalocean.d.ts +320 -21
- package/dist/providers/digitalocean.js +18 -7
- package/dist/providers/fireworks.d.ts +73 -11
- package/dist/providers/fireworks.js +1 -1
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +1 -1
- package/dist/providers/google-vertex-chat.d.ts +36 -5
- package/dist/providers/google-vertex-chat.js +1 -1
- package/dist/providers/google-vertex-interactions.d.ts +1 -1
- package/dist/providers/google-vertex-interactions.js +1 -1
- package/dist/providers/google-vertex-messages.d.ts +1 -1
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-mistral.d.ts +1 -1
- package/dist/providers/google-vertex-mistral.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +21 -4
- package/dist/providers/google-vertex-responses.js +1 -1
- package/dist/providers/google-vertex.d.ts +2 -2
- package/dist/providers/google-vertex.js +1 -1
- package/dist/providers/google.d.ts +2 -2
- package/dist/providers/google.js +1 -1
- package/dist/providers/groq.d.ts +77 -11
- package/dist/providers/groq.js +1 -1
- package/dist/providers/index.d.ts +0 -4
- package/dist/providers/index.js +0 -4
- package/dist/providers/meta/images.d.ts +2 -0
- package/dist/providers/meta/images.js +1 -0
- package/dist/providers/meta.d.ts +61 -12
- package/dist/providers/meta.js +2 -1
- package/dist/providers/minimax/chat.d.ts +1 -1
- package/dist/providers/minimax/chat.js +1 -1
- package/dist/providers/minimax/images.d.ts +3 -0
- package/dist/providers/minimax/images.js +1 -0
- package/dist/providers/minimax/responses.d.ts +1 -1
- package/dist/providers/minimax/responses.js +1 -1
- package/dist/providers/minimax.d.ts +63 -9
- package/dist/providers/minimax.js +22 -9
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +1 -1
- package/dist/providers/moonshot/messages.d.ts +1 -1
- package/dist/providers/moonshot/messages.js +1 -1
- package/dist/providers/moonshot/responses.d.ts +1 -1
- package/dist/providers/moonshot/responses.js +1 -1
- package/dist/providers/moonshot.d.ts +56 -8
- package/dist/providers/moonshot.js +1 -1
- package/dist/providers/openai-compatible-responses.d.ts +21 -4
- package/dist/providers/openai-compatible.d.ts +38 -7
- package/dist/providers/openai-compatible.js +9 -2
- package/dist/providers/openai.d.ts +59 -11
- package/dist/providers/openai.js +4 -2
- package/dist/providers/opencode.d.ts +3 -3
- package/dist/providers/opencode.js +1 -1
- package/dist/providers/openrouter/responses.d.ts +4 -0
- package/dist/providers/openrouter/responses.js +1 -0
- package/dist/providers/openrouter.d.ts +356 -26
- package/dist/providers/openrouter.js +42 -13
- package/dist/providers/togetherai.d.ts +73 -11
- package/dist/providers/togetherai.js +1 -1
- package/dist/providers/typesafe-ai.d.ts +3 -3
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/providers/venice/responses.d.ts +4 -0
- package/dist/providers/venice/responses.js +1 -0
- package/dist/providers/venice.d.ts +242 -9
- package/dist/providers/venice.js +33 -17
- package/dist/providers/vercel-ai-gateway.d.ts +8 -8
- package/dist/providers/vercel-ai-gateway.js +12 -2
- package/dist/providers/xai.d.ts +39 -8
- package/dist/providers/xai.js +1 -1
- package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
- package/dist/providers/zai-coding-plan/messages.js +1 -1
- package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
- package/dist/providers/zai-coding-plan/responses.js +1 -1
- package/dist/providers/zai-coding-plan.d.ts +56 -8
- package/dist/providers/zai-coding-plan.js +1 -1
- package/dist/providers/zai.d.ts +37 -6
- package/dist/providers/zai.js +1 -1
- package/dist/route/auth.d.ts +1 -1
- package/dist/route/media-protocol.d.ts +2 -4
- package/dist/route/media.d.ts +1 -1
- package/dist/route/media.js +2 -4
- package/dist/schema/messages.d.ts +35 -1
- package/dist/schema/messages.js +20 -0
- package/dist/speech-client.d.ts +48 -0
- package/dist/testing/decision.d.ts +16 -0
- package/dist/testing/decision.js +20 -0
- package/dist/testing/image.d.ts +14 -0
- package/dist/testing/image.js +12 -0
- package/dist/testing/media.d.ts +18 -0
- package/dist/testing/media.js +36 -0
- package/dist/testing/script.d.ts +28 -0
- package/dist/testing/script.js +60 -0
- package/dist/testing/speech.d.ts +14 -0
- package/dist/testing/speech.js +12 -0
- package/dist/testing/transcription.d.ts +14 -0
- package/dist/testing/transcription.js +12 -0
- package/dist/testing/video.d.ts +14 -0
- package/dist/testing/video.js +12 -0
- package/dist/testing.d.ts +10 -21
- package/dist/testing.js +11 -54
- package/dist/tool.d.ts +12 -1
- package/dist/tool.js +10 -2
- package/dist/transcription-client.d.ts +64 -0
- package/dist/video-client.d.ts +41 -0
- package/package.json +22 -38
- package/dist/protocols/bfl-images.d.ts +0 -47
- package/dist/protocols/bfl-images.js +0 -155
- package/dist/protocols/fal-images.d.ts +0 -34
- package/dist/protocols/fal-images.js +0 -95
- package/dist/protocols/fal-video.d.ts +0 -29
- package/dist/protocols/fal-video.js +0 -73
- package/dist/protocols/replicate-images.d.ts +0 -28
- package/dist/protocols/replicate-images.js +0 -127
- package/dist/protocols/stability-images.d.ts +0 -44
- package/dist/protocols/stability-images.js +0 -131
- package/dist/protocols/utils/fal-queue.d.ts +0 -26
- package/dist/protocols/utils/fal-queue.js +0 -67
- package/dist/providers/black-forest-labs.d.ts +0 -21
- package/dist/providers/black-forest-labs.js +0 -23
- package/dist/providers/fal.d.ts +0 -24
- package/dist/providers/fal.js +0 -26
- package/dist/providers/replicate.d.ts +0 -21
- package/dist/providers/replicate.js +0 -17
- package/dist/providers/stability.d.ts +0 -23
- package/dist/providers/stability.js +0 -18
|
@@ -8,6 +8,7 @@ import { effortUpdate } from "../effort-updates.js";
|
|
|
8
8
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
9
9
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
10
10
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
11
|
+
import { OpenAIFreeform } from "./openai-freeform.js";
|
|
11
12
|
const ADAPTER = "open-responses";
|
|
12
13
|
const NAME = "Open Responses";
|
|
13
14
|
export const PATH = "/responses";
|
|
@@ -155,10 +156,17 @@ export const InputItem = Schema.Union([
|
|
|
155
156
|
arguments: Schema.String,
|
|
156
157
|
}),
|
|
157
158
|
Schema.Struct({
|
|
158
|
-
type: Schema.
|
|
159
|
+
type: Schema.Literals(["function_call_output", "custom_tool_call_output"]),
|
|
159
160
|
call_id: Schema.String,
|
|
160
161
|
output: OpenResponsesFunctionCallOutput,
|
|
161
162
|
}),
|
|
163
|
+
Schema.Struct({
|
|
164
|
+
type: Schema.tag("custom_tool_call"),
|
|
165
|
+
id: Schema.optionalKey(Schema.String),
|
|
166
|
+
call_id: Schema.String,
|
|
167
|
+
name: Schema.String,
|
|
168
|
+
input: Schema.String,
|
|
169
|
+
}),
|
|
162
170
|
HostedToolItem,
|
|
163
171
|
HostedToolReplay,
|
|
164
172
|
]);
|
|
@@ -169,16 +177,30 @@ export const Tool = Schema.Struct({
|
|
|
169
177
|
parameters: JsonObject,
|
|
170
178
|
strict: Schema.optional(Schema.Boolean),
|
|
171
179
|
});
|
|
180
|
+
export const CustomTool = Schema.Struct({
|
|
181
|
+
type: Schema.tag("custom"),
|
|
182
|
+
name: Schema.String,
|
|
183
|
+
description: Schema.String,
|
|
184
|
+
format: Schema.Union([
|
|
185
|
+
Schema.Struct({ type: Schema.tag("text") }),
|
|
186
|
+
Schema.Struct({
|
|
187
|
+
type: Schema.tag("grammar"),
|
|
188
|
+
syntax: Schema.Literals(["lark", "regex"]),
|
|
189
|
+
definition: Schema.String,
|
|
190
|
+
}),
|
|
191
|
+
]),
|
|
192
|
+
});
|
|
172
193
|
export const HostedTool = Schema.StructWithRest(Schema.Struct({
|
|
173
194
|
type: Schema.String,
|
|
174
195
|
}), [JsonObject]);
|
|
196
|
+
const NamedTool = Schema.Struct({ type: Schema.Literals(["function", "custom"]), name: Schema.String });
|
|
175
197
|
export const ToolChoice = Schema.Union([
|
|
176
198
|
Schema.Literals(["auto", "none", "required"]),
|
|
177
|
-
|
|
199
|
+
NamedTool,
|
|
178
200
|
Schema.Struct({
|
|
179
201
|
type: Schema.tag("allowed_tools"),
|
|
180
202
|
mode: Schema.Literals(["auto", "none", "required"]),
|
|
181
|
-
tools: Schema.Array(
|
|
203
|
+
tools: Schema.Array(NamedTool),
|
|
182
204
|
}),
|
|
183
205
|
]);
|
|
184
206
|
// Fields shared between the HTTP body and the WebSocket `response.create`
|
|
@@ -189,7 +211,7 @@ export const coreFields = {
|
|
|
189
211
|
model: Schema.String,
|
|
190
212
|
input: Schema.Array(InputItem),
|
|
191
213
|
instructions: Schema.optional(Schema.String),
|
|
192
|
-
tools: optionalArray(Schema.Union([Tool, HostedTool])),
|
|
214
|
+
tools: optionalArray(Schema.Union([Tool, CustomTool, HostedTool])),
|
|
193
215
|
tool_choice: Schema.optional(ToolChoice),
|
|
194
216
|
store: Schema.optional(Schema.Boolean),
|
|
195
217
|
metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
@@ -295,12 +317,30 @@ export const lowerTool = Effect.fnUntraced(function* (protocolName, tool) {
|
|
|
295
317
|
strict: false,
|
|
296
318
|
};
|
|
297
319
|
});
|
|
298
|
-
export const
|
|
299
|
-
|
|
320
|
+
export const lowerCustomTool = (tool, custom) => {
|
|
321
|
+
const grammar = OpenAIFreeform.grammar(custom.format);
|
|
322
|
+
return {
|
|
323
|
+
type: "custom",
|
|
324
|
+
name: tool.name,
|
|
325
|
+
description: tool.description,
|
|
326
|
+
format: grammar ? { type: "grammar", ...grammar } : { type: "text" },
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
export const lowerTools = (tools, adapter, custom) => Effect.forEach(tools, (tool) => {
|
|
330
|
+
if (tool.native !== undefined && adapter.nativeTool)
|
|
331
|
+
return adapter.nativeTool(tool.native);
|
|
332
|
+
const definition = custom.get(tool.name);
|
|
333
|
+
return definition ? Effect.succeed(lowerCustomTool(tool, definition)) : lowerTool(adapter.name, tool);
|
|
334
|
+
});
|
|
335
|
+
export const namedTool = (name, custom) => ({
|
|
336
|
+
type: custom.has(name) ? "custom" : "function",
|
|
337
|
+
name,
|
|
338
|
+
});
|
|
339
|
+
export const lowerToolChoice = (protocolName, toolChoice, custom) => ProviderShared.matchToolChoice(protocolName, toolChoice, {
|
|
300
340
|
auto: () => "auto",
|
|
301
341
|
none: () => "none",
|
|
302
342
|
required: () => "required",
|
|
303
|
-
tool: (toolName) => (
|
|
343
|
+
tool: (toolName) => namedTool(toolName, custom),
|
|
304
344
|
});
|
|
305
345
|
// Server-issued item ids need a nonempty prefix and suffix, but the prefix is
|
|
306
346
|
// provider-defined and does not necessarily identify the item's semantic type.
|
|
@@ -311,8 +351,19 @@ const itemID = (providerMetadata, providerMetadataKey) => {
|
|
|
311
351
|
const separator = metadata.itemId.indexOf("_");
|
|
312
352
|
return separator > 0 && separator < metadata.itemId.length - 1 ? metadata.itemId : undefined;
|
|
313
353
|
};
|
|
314
|
-
|
|
315
|
-
|
|
354
|
+
// A call replays as the type its tool is declared with now; the item id only survives when that type is unchanged.
|
|
355
|
+
const lowerToolCall = (part, providerMetadataKey, custom) => {
|
|
356
|
+
const id = OpenAIFreeform.keepsItemID(part.providerMetadata, providerMetadataKey, custom !== undefined)
|
|
357
|
+
? itemID(part.providerMetadata, providerMetadataKey)
|
|
358
|
+
: undefined;
|
|
359
|
+
if (custom)
|
|
360
|
+
return {
|
|
361
|
+
type: "custom_tool_call",
|
|
362
|
+
...(id === undefined ? {} : { id }),
|
|
363
|
+
call_id: part.id,
|
|
364
|
+
name: part.name,
|
|
365
|
+
input: OpenAIFreeform.toRaw(custom, part.input),
|
|
366
|
+
};
|
|
316
367
|
return {
|
|
317
368
|
type: "function_call",
|
|
318
369
|
...(id === undefined ? {} : { id }),
|
|
@@ -394,6 +445,8 @@ const DEFAULT_EFFORT = "medium";
|
|
|
394
445
|
const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
395
446
|
const input = [];
|
|
396
447
|
const providerMetadataKey = metadataKey(request.model);
|
|
448
|
+
const custom = OpenAIFreeform.tools(request);
|
|
449
|
+
const customTool = (part) => part.namespace === undefined ? custom.get(part.name) : undefined;
|
|
397
450
|
for (const message of request.messages) {
|
|
398
451
|
const rawMetadata = message.providerMetadata?.[providerMetadataKey];
|
|
399
452
|
const metadata = rawMetadata === undefined ? undefined : yield* decodeMessageMetadata(rawMetadata);
|
|
@@ -483,7 +536,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
483
536
|
flushText();
|
|
484
537
|
if (part.providerExecuted === true)
|
|
485
538
|
continue;
|
|
486
|
-
input.push(lowerToolCall(part, providerMetadataKey));
|
|
539
|
+
input.push(lowerToolCall(part, providerMetadataKey, customTool(part)));
|
|
487
540
|
continue;
|
|
488
541
|
}
|
|
489
542
|
if (part.type === "tool-result" && part.providerExecuted === true) {
|
|
@@ -536,7 +589,7 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
|
|
|
536
589
|
if (!ProviderShared.supportsContent(part, ["tool-result"]))
|
|
537
590
|
return yield* ProviderShared.unsupportedContent(adapter.name, "tool", ["tool-result"]);
|
|
538
591
|
input.push({
|
|
539
|
-
type: "function_call_output",
|
|
592
|
+
type: customTool(part) ? "custom_tool_call_output" : "function_call_output",
|
|
540
593
|
call_id: part.id,
|
|
541
594
|
output: yield* lowerToolResultOutput(part, request, adapter),
|
|
542
595
|
});
|
|
@@ -589,25 +642,26 @@ export const resolveParallelToolCalls = (request, options = OpenResponsesOptions
|
|
|
589
642
|
const disabled = request.toolChoice?.disableParallelToolUse;
|
|
590
643
|
return disabled === undefined ? undefined : !disabled;
|
|
591
644
|
};
|
|
592
|
-
export const allowedToolChoice = (
|
|
645
|
+
export const allowedToolChoice = (options, custom) => {
|
|
593
646
|
const allowed = options.allowedTools;
|
|
594
647
|
if (!allowed)
|
|
595
648
|
return undefined;
|
|
596
649
|
return {
|
|
597
650
|
type: "allowed_tools",
|
|
598
651
|
mode: allowed.mode,
|
|
599
|
-
tools: allowed.toolNames.map((name) => (
|
|
652
|
+
tools: allowed.toolNames.map((name) => namedTool(name, custom)),
|
|
600
653
|
};
|
|
601
654
|
};
|
|
602
655
|
export const fromRequestWithAdapter = Effect.fn("OpenResponses.fromRequestWithAdapter")(function* (request, adapter) {
|
|
603
656
|
const projected = ProviderShared.flattenToolRequest(request);
|
|
604
657
|
const options = OpenResponsesOptions.resolve(request);
|
|
658
|
+
const custom = OpenAIFreeform.tools(request);
|
|
605
659
|
return {
|
|
606
660
|
...(yield* lowerConversation(projected.request, adapter)),
|
|
607
661
|
...lowerGeneration(request, options),
|
|
608
|
-
tools: projected.tools.length === 0 ? undefined : yield* lowerTools(projected.tools, adapter),
|
|
609
|
-
tool_choice: allowedToolChoice(
|
|
610
|
-
(request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice) : undefined),
|
|
662
|
+
tools: projected.tools.length === 0 ? undefined : yield* lowerTools(projected.tools, adapter, custom),
|
|
663
|
+
tool_choice: allowedToolChoice(options, custom) ??
|
|
664
|
+
(request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice, custom) : undefined),
|
|
611
665
|
};
|
|
612
666
|
});
|
|
613
667
|
export const fromRequest = (request) => fromRequestWithAdapter(request, BASE_ADAPTER);
|
|
@@ -693,6 +747,7 @@ const ITEM_ID_PREFIX = {
|
|
|
693
747
|
message: "msg",
|
|
694
748
|
reasoning: "rs",
|
|
695
749
|
function_call: "fc",
|
|
750
|
+
custom_tool_call: "ctc",
|
|
696
751
|
compaction: "cmp",
|
|
697
752
|
};
|
|
698
753
|
// An item without an id adopts the id already open in its output slot,
|
|
@@ -829,25 +884,26 @@ const onOutputItemAdded = (state, event) => {
|
|
|
829
884
|
events,
|
|
830
885
|
];
|
|
831
886
|
}
|
|
832
|
-
if (item.type !== "function_call" || !item.call_id)
|
|
887
|
+
if ((item.type !== "function_call" && item.type !== "custom_tool_call") || !item.call_id)
|
|
833
888
|
return [state, NO_EVENTS];
|
|
834
889
|
if (state.tools[item.id] !== undefined)
|
|
835
890
|
return [state, NO_EVENTS];
|
|
836
|
-
const
|
|
891
|
+
const custom = item.type === "custom_tool_call";
|
|
892
|
+
const metadata = providerMetadata(state, OpenAIFreeform.metadata(item.id, custom));
|
|
837
893
|
const events = [];
|
|
838
894
|
const lifecycle = Lifecycle.stepStart(state.lifecycle, events);
|
|
895
|
+
const tools = ToolStream.start(state.tools, item.id, {
|
|
896
|
+
id: item.call_id,
|
|
897
|
+
name: item.name ?? "",
|
|
898
|
+
namespace: item.namespace,
|
|
899
|
+
input: custom ? "" : (item.arguments ?? ""),
|
|
900
|
+
providerMetadata: metadata,
|
|
901
|
+
});
|
|
902
|
+
const opened = custom
|
|
903
|
+
? ToolStream.append(tools, item.id, OpenAIFreeform.streamStart(state.custom.get(item.name ?? ""), rawInput(item)))
|
|
904
|
+
: undefined;
|
|
839
905
|
return [
|
|
840
|
-
{
|
|
841
|
-
...state,
|
|
842
|
-
lifecycle,
|
|
843
|
-
tools: ToolStream.start(state.tools, item.id, {
|
|
844
|
-
id: item.call_id,
|
|
845
|
-
name: item.name ?? "",
|
|
846
|
-
namespace: item.namespace,
|
|
847
|
-
input: item.arguments ?? "",
|
|
848
|
-
providerMetadata: metadata,
|
|
849
|
-
}),
|
|
850
|
-
},
|
|
906
|
+
{ ...state, lifecycle, tools: opened?.tools ?? tools },
|
|
851
907
|
[
|
|
852
908
|
...events,
|
|
853
909
|
LLMEvent.toolInputStart({
|
|
@@ -856,9 +912,11 @@ const onOutputItemAdded = (state, event) => {
|
|
|
856
912
|
namespace: item.namespace,
|
|
857
913
|
providerMetadata: metadata,
|
|
858
914
|
}),
|
|
915
|
+
...(opened?.events ?? []),
|
|
859
916
|
],
|
|
860
917
|
];
|
|
861
918
|
};
|
|
919
|
+
const rawInput = (item) => (typeof item.input === "string" ? item.input : "");
|
|
862
920
|
const onReasoningSummaryPartAdded = (state, event) => {
|
|
863
921
|
if (event.item_id === undefined || event.summary_index === undefined)
|
|
864
922
|
return [state, NO_EVENTS];
|
|
@@ -959,24 +1017,28 @@ const onOutputItemDone = Effect.fnUntraced(function* (state, item) {
|
|
|
959
1017
|
events,
|
|
960
1018
|
];
|
|
961
1019
|
}
|
|
962
|
-
if (item.type === "function_call") {
|
|
1020
|
+
if (item.type === "function_call" || item.type === "custom_tool_call") {
|
|
963
1021
|
if (!item.call_id || !item.name)
|
|
964
1022
|
return [state, NO_EVENTS];
|
|
965
|
-
const
|
|
1023
|
+
const custom = item.type === "custom_tool_call";
|
|
1024
|
+
const metadata = providerMetadata(state, OpenAIFreeform.metadata(item.id, custom));
|
|
1025
|
+
const final = { custom: state.custom.get(item.name), raw: rawInput(item) };
|
|
1026
|
+
const input = custom ? OpenAIFreeform.fromRaw(final.custom, final.raw) : item.arguments;
|
|
966
1027
|
const registered = state.tools[item.id] !== undefined;
|
|
1028
|
+
const closed = custom ? OpenAIFreeform.close(state.tools, [item.id], final) : undefined;
|
|
967
1029
|
const tools = registered
|
|
968
|
-
? state.tools
|
|
1030
|
+
? (closed?.tools ?? state.tools)
|
|
969
1031
|
: ToolStream.start(state.tools, item.id, {
|
|
970
1032
|
id: item.call_id,
|
|
971
1033
|
name: item.name,
|
|
972
1034
|
namespace: item.namespace,
|
|
973
1035
|
providerMetadata: metadata,
|
|
974
1036
|
});
|
|
975
|
-
const result =
|
|
1037
|
+
const result = input === undefined
|
|
976
1038
|
? yield* ToolStream.finish(state.id, tools, item.id)
|
|
977
|
-
: yield* ToolStream.finishWithInput(state.id, tools, item.id,
|
|
1039
|
+
: yield* ToolStream.finishWithInput(state.id, tools, item.id, input);
|
|
978
1040
|
const events = [];
|
|
979
|
-
const finished = result.events ?? [];
|
|
1041
|
+
const finished = [...(closed?.events ?? []), ...(result.events ?? [])];
|
|
980
1042
|
// A done-only call never streamed a start event, so open its lifecycle here.
|
|
981
1043
|
const resultEvents = registered || finished.length === 0
|
|
982
1044
|
? finished
|
|
@@ -1051,7 +1113,8 @@ const onResponseFinish = Effect.fnUntraced(function* (state, event) {
|
|
|
1051
1113
|
// Terminal recovery cannot insert a checkpoint before already-emitted content.
|
|
1052
1114
|
if (item.type === "compaction" && state.lifecycle.stepStarted && !state.completedCompactions.has(item.id))
|
|
1053
1115
|
return yield* ProviderShared.eventError(state.id, "Cannot recover a compaction checkpoint after output has been emitted");
|
|
1054
|
-
const recoverable = item.type === "compaction" ||
|
|
1116
|
+
const recoverable = item.type === "compaction" ||
|
|
1117
|
+
((item.type === "function_call" || item.type === "custom_tool_call") && current.tools[item.id] !== undefined);
|
|
1055
1118
|
if (!recoverable)
|
|
1056
1119
|
continue;
|
|
1057
1120
|
const [next, emitted] = yield* onOutputItemDone(current, item);
|
|
@@ -1163,6 +1226,14 @@ export const step = (state, event) => {
|
|
|
1163
1226
|
return event.item_id !== undefined
|
|
1164
1227
|
? onFunctionCallArgumentsDelta(state, event)
|
|
1165
1228
|
: ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
1229
|
+
if (event.type === "response.custom_tool_call_input.delta")
|
|
1230
|
+
return event.item_id !== undefined
|
|
1231
|
+
? onFunctionCallArgumentsDelta(state, {
|
|
1232
|
+
...event,
|
|
1233
|
+
type: "response.function_call_arguments.delta",
|
|
1234
|
+
delta: OpenAIFreeform.streamDelta(event.delta ?? ""),
|
|
1235
|
+
})
|
|
1236
|
+
: ProviderShared.eventError(state.id, `${event.type} is missing item_id`);
|
|
1166
1237
|
if (event.type === "response.output_item.done")
|
|
1167
1238
|
return onOutputItemDone(state, event.item);
|
|
1168
1239
|
if (event.type === "response.completed" || event.type === "response.incomplete")
|
|
@@ -1188,6 +1259,7 @@ export const initial = (request, adapter = BASE_ADAPTER) => ({
|
|
|
1188
1259
|
providerMetadataKey: metadataKey(request.model),
|
|
1189
1260
|
hasFunctionCall: false,
|
|
1190
1261
|
tools: ToolStream.empty(),
|
|
1262
|
+
custom: OpenAIFreeform.tools(request),
|
|
1191
1263
|
lifecycle: Lifecycle.initial(),
|
|
1192
1264
|
outputItems: {},
|
|
1193
1265
|
message: undefined,
|