@ai-sdk/openai 3.0.0-beta.109 → 3.0.0-beta.111
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/CHANGELOG.md +15 -0
- package/dist/index.d.mts +5 -16
- package/dist/index.d.ts +5 -16
- package/dist/index.js +131 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -137
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +130 -136
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +130 -136
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/internal/index.js
CHANGED
|
@@ -283,6 +283,9 @@ function convertToOpenAIChatMessages({
|
|
|
283
283
|
}
|
|
284
284
|
case "tool": {
|
|
285
285
|
for (const toolResponse of content) {
|
|
286
|
+
if (toolResponse.type === "tool-approval-response") {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
286
289
|
const output = toolResponse.output;
|
|
287
290
|
let contentValue;
|
|
288
291
|
switch (output.type) {
|
|
@@ -2689,6 +2692,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2689
2692
|
}
|
|
2690
2693
|
case "tool": {
|
|
2691
2694
|
for (const part of content) {
|
|
2695
|
+
if (part.type === "tool-approval-response") {
|
|
2696
|
+
continue;
|
|
2697
|
+
}
|
|
2692
2698
|
const output = part.output;
|
|
2693
2699
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
2694
2700
|
part.toolName
|
|
@@ -3215,6 +3221,19 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
|
|
|
3215
3221
|
item_id: import_v416.z.string(),
|
|
3216
3222
|
summary_index: import_v416.z.number()
|
|
3217
3223
|
}),
|
|
3224
|
+
import_v416.z.object({
|
|
3225
|
+
type: import_v416.z.literal("response.apply_patch_call_operation_diff.delta"),
|
|
3226
|
+
item_id: import_v416.z.string(),
|
|
3227
|
+
output_index: import_v416.z.number(),
|
|
3228
|
+
delta: import_v416.z.string(),
|
|
3229
|
+
obfuscation: import_v416.z.string().nullish()
|
|
3230
|
+
}),
|
|
3231
|
+
import_v416.z.object({
|
|
3232
|
+
type: import_v416.z.literal("response.apply_patch_call_operation_diff.done"),
|
|
3233
|
+
item_id: import_v416.z.string(),
|
|
3234
|
+
output_index: import_v416.z.number(),
|
|
3235
|
+
diff: import_v416.z.string()
|
|
3236
|
+
}),
|
|
3218
3237
|
import_v416.z.object({
|
|
3219
3238
|
type: import_v416.z.literal("error"),
|
|
3220
3239
|
sequence_number: import_v416.z.number(),
|
|
@@ -3878,16 +3897,14 @@ var mcpArgsSchema = (0, import_provider_utils28.lazySchema)(
|
|
|
3878
3897
|
authorization: import_v421.z.string().optional(),
|
|
3879
3898
|
connectorId: import_v421.z.string().optional(),
|
|
3880
3899
|
headers: import_v421.z.record(import_v421.z.string(), import_v421.z.string()).optional(),
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
// ])
|
|
3890
|
-
// .optional(),
|
|
3900
|
+
requireApproval: import_v421.z.union([
|
|
3901
|
+
import_v421.z.enum(["always", "never"]),
|
|
3902
|
+
import_v421.z.object({
|
|
3903
|
+
never: import_v421.z.object({
|
|
3904
|
+
toolNames: import_v421.z.array(import_v421.z.string()).optional()
|
|
3905
|
+
}).optional()
|
|
3906
|
+
})
|
|
3907
|
+
]).optional(),
|
|
3891
3908
|
serverDescription: import_v421.z.string().optional(),
|
|
3892
3909
|
serverUrl: import_v421.z.string().optional()
|
|
3893
3910
|
}).refine(
|
|
@@ -3899,36 +3916,14 @@ var mcpArgsSchema = (0, import_provider_utils28.lazySchema)(
|
|
|
3899
3916
|
var mcpInputSchema = (0, import_provider_utils28.lazySchema)(() => (0, import_provider_utils28.zodSchema)(import_v421.z.object({})));
|
|
3900
3917
|
var mcpOutputSchema = (0, import_provider_utils28.lazySchema)(
|
|
3901
3918
|
() => (0, import_provider_utils28.zodSchema)(
|
|
3902
|
-
import_v421.z.
|
|
3903
|
-
import_v421.z.
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
}),
|
|
3911
|
-
import_v421.z.object({
|
|
3912
|
-
type: import_v421.z.literal("listTools"),
|
|
3913
|
-
serverLabel: import_v421.z.string(),
|
|
3914
|
-
tools: import_v421.z.array(
|
|
3915
|
-
import_v421.z.object({
|
|
3916
|
-
name: import_v421.z.string(),
|
|
3917
|
-
description: import_v421.z.string().optional(),
|
|
3918
|
-
inputSchema: jsonValueSchema,
|
|
3919
|
-
annotations: import_v421.z.record(import_v421.z.string(), jsonValueSchema).optional()
|
|
3920
|
-
})
|
|
3921
|
-
),
|
|
3922
|
-
error: import_v421.z.union([import_v421.z.string(), jsonValueSchema]).optional()
|
|
3923
|
-
}),
|
|
3924
|
-
import_v421.z.object({
|
|
3925
|
-
type: import_v421.z.literal("approvalRequest"),
|
|
3926
|
-
serverLabel: import_v421.z.string(),
|
|
3927
|
-
name: import_v421.z.string(),
|
|
3928
|
-
arguments: import_v421.z.string(),
|
|
3929
|
-
approvalRequestId: import_v421.z.string()
|
|
3930
|
-
})
|
|
3931
|
-
])
|
|
3919
|
+
import_v421.z.object({
|
|
3920
|
+
type: import_v421.z.literal("call"),
|
|
3921
|
+
serverLabel: import_v421.z.string(),
|
|
3922
|
+
name: import_v421.z.string(),
|
|
3923
|
+
arguments: import_v421.z.string(),
|
|
3924
|
+
output: import_v421.z.string().nullable().optional(),
|
|
3925
|
+
error: import_v421.z.union([import_v421.z.string(), jsonValueSchema]).optional()
|
|
3926
|
+
})
|
|
3932
3927
|
)
|
|
3933
3928
|
);
|
|
3934
3929
|
var mcpToolFactory = (0, import_provider_utils28.createProviderToolFactoryWithOutputSchema)({
|
|
@@ -4699,54 +4694,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4699
4694
|
break;
|
|
4700
4695
|
}
|
|
4701
4696
|
case "mcp_list_tools": {
|
|
4702
|
-
content.push({
|
|
4703
|
-
type: "tool-call",
|
|
4704
|
-
toolCallId: part.id,
|
|
4705
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4706
|
-
input: JSON.stringify({}),
|
|
4707
|
-
providerExecuted: true
|
|
4708
|
-
});
|
|
4709
|
-
content.push({
|
|
4710
|
-
type: "tool-result",
|
|
4711
|
-
toolCallId: part.id,
|
|
4712
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4713
|
-
result: {
|
|
4714
|
-
type: "listTools",
|
|
4715
|
-
serverLabel: part.server_label,
|
|
4716
|
-
tools: part.tools.map((t) => {
|
|
4717
|
-
var _a2, _b2;
|
|
4718
|
-
return {
|
|
4719
|
-
name: t.name,
|
|
4720
|
-
description: (_a2 = t.description) != null ? _a2 : void 0,
|
|
4721
|
-
inputSchema: t.input_schema,
|
|
4722
|
-
annotations: (_b2 = t.annotations) != null ? _b2 : void 0
|
|
4723
|
-
};
|
|
4724
|
-
}),
|
|
4725
|
-
...part.error != null ? { error: part.error } : {}
|
|
4726
|
-
}
|
|
4727
|
-
});
|
|
4728
4697
|
break;
|
|
4729
4698
|
}
|
|
4730
4699
|
case "mcp_approval_request": {
|
|
4731
|
-
content.push({
|
|
4732
|
-
type: "tool-call",
|
|
4733
|
-
toolCallId: part.id,
|
|
4734
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4735
|
-
input: JSON.stringify({}),
|
|
4736
|
-
providerExecuted: true
|
|
4737
|
-
});
|
|
4738
|
-
content.push({
|
|
4739
|
-
type: "tool-result",
|
|
4740
|
-
toolCallId: part.id,
|
|
4741
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
4742
|
-
result: {
|
|
4743
|
-
type: "approvalRequest",
|
|
4744
|
-
serverLabel: part.server_label,
|
|
4745
|
-
name: part.name,
|
|
4746
|
-
arguments: part.arguments,
|
|
4747
|
-
approvalRequestId: part.approval_request_id
|
|
4748
|
-
}
|
|
4749
|
-
});
|
|
4750
4700
|
break;
|
|
4751
4701
|
}
|
|
4752
4702
|
case "computer_call": {
|
|
@@ -5015,24 +4965,40 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5015
4965
|
providerExecuted: true
|
|
5016
4966
|
});
|
|
5017
4967
|
} else if (value.item.type === "apply_patch_call") {
|
|
4968
|
+
const { call_id: callId, operation } = value.item;
|
|
5018
4969
|
ongoingToolCalls[value.output_index] = {
|
|
5019
4970
|
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
5020
|
-
toolCallId:
|
|
4971
|
+
toolCallId: callId,
|
|
4972
|
+
applyPatch: {
|
|
4973
|
+
// delete_file doesn't have diff
|
|
4974
|
+
hasDiff: operation.type === "delete_file",
|
|
4975
|
+
endEmitted: operation.type === "delete_file"
|
|
4976
|
+
}
|
|
5021
4977
|
};
|
|
5022
|
-
|
|
4978
|
+
controller.enqueue({
|
|
4979
|
+
type: "tool-input-start",
|
|
4980
|
+
id: callId,
|
|
4981
|
+
toolName: toolNameMapping.toCustomToolName("apply_patch")
|
|
4982
|
+
});
|
|
4983
|
+
if (operation.type === "delete_file") {
|
|
4984
|
+
const inputString = JSON.stringify({
|
|
4985
|
+
callId,
|
|
4986
|
+
operation
|
|
4987
|
+
});
|
|
5023
4988
|
controller.enqueue({
|
|
5024
|
-
type: "tool-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
4989
|
+
type: "tool-input-delta",
|
|
4990
|
+
id: callId,
|
|
4991
|
+
delta: inputString
|
|
4992
|
+
});
|
|
4993
|
+
controller.enqueue({
|
|
4994
|
+
type: "tool-input-end",
|
|
4995
|
+
id: callId
|
|
4996
|
+
});
|
|
4997
|
+
} else {
|
|
4998
|
+
controller.enqueue({
|
|
4999
|
+
type: "tool-input-delta",
|
|
5000
|
+
id: callId,
|
|
5001
|
+
delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
|
|
5036
5002
|
});
|
|
5037
5003
|
}
|
|
5038
5004
|
} else if (value.item.type === "shell_call") {
|
|
@@ -5184,31 +5150,31 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5184
5150
|
});
|
|
5185
5151
|
} else if (value.item.type === "mcp_list_tools") {
|
|
5186
5152
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5187
|
-
controller.enqueue({
|
|
5188
|
-
type: "tool-result",
|
|
5189
|
-
toolCallId: value.item.id,
|
|
5190
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
5191
|
-
result: {
|
|
5192
|
-
type: "listTools",
|
|
5193
|
-
serverLabel: value.item.server_label,
|
|
5194
|
-
tools: value.item.tools.map((t) => {
|
|
5195
|
-
var _a2, _b2;
|
|
5196
|
-
return {
|
|
5197
|
-
name: t.name,
|
|
5198
|
-
description: (_a2 = t.description) != null ? _a2 : void 0,
|
|
5199
|
-
inputSchema: t.input_schema,
|
|
5200
|
-
annotations: (_b2 = t.annotations) != null ? _b2 : void 0
|
|
5201
|
-
};
|
|
5202
|
-
}),
|
|
5203
|
-
...value.item.error != null ? { error: value.item.error } : {}
|
|
5204
|
-
}
|
|
5205
|
-
});
|
|
5206
5153
|
} else if (value.item.type === "apply_patch_call") {
|
|
5207
|
-
ongoingToolCalls[value.output_index]
|
|
5208
|
-
if (value.item.
|
|
5154
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5155
|
+
if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
|
|
5156
|
+
if (!toolCall.applyPatch.hasDiff) {
|
|
5157
|
+
controller.enqueue({
|
|
5158
|
+
type: "tool-input-delta",
|
|
5159
|
+
id: toolCall.toolCallId,
|
|
5160
|
+
delta: escapeJSONDelta(value.item.operation.diff)
|
|
5161
|
+
});
|
|
5162
|
+
}
|
|
5163
|
+
controller.enqueue({
|
|
5164
|
+
type: "tool-input-delta",
|
|
5165
|
+
id: toolCall.toolCallId,
|
|
5166
|
+
delta: '"}}'
|
|
5167
|
+
});
|
|
5168
|
+
controller.enqueue({
|
|
5169
|
+
type: "tool-input-end",
|
|
5170
|
+
id: toolCall.toolCallId
|
|
5171
|
+
});
|
|
5172
|
+
toolCall.applyPatch.endEmitted = true;
|
|
5173
|
+
}
|
|
5174
|
+
if (toolCall && value.item.status === "completed") {
|
|
5209
5175
|
controller.enqueue({
|
|
5210
5176
|
type: "tool-call",
|
|
5211
|
-
toolCallId:
|
|
5177
|
+
toolCallId: toolCall.toolCallId,
|
|
5212
5178
|
toolName: toolNameMapping.toCustomToolName("apply_patch"),
|
|
5213
5179
|
input: JSON.stringify({
|
|
5214
5180
|
callId: value.item.call_id,
|
|
@@ -5221,20 +5187,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5221
5187
|
}
|
|
5222
5188
|
});
|
|
5223
5189
|
}
|
|
5190
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
5224
5191
|
} else if (value.item.type === "mcp_approval_request") {
|
|
5225
5192
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5226
|
-
controller.enqueue({
|
|
5227
|
-
type: "tool-result",
|
|
5228
|
-
toolCallId: value.item.id,
|
|
5229
|
-
toolName: toolNameMapping.toCustomToolName("mcp"),
|
|
5230
|
-
result: {
|
|
5231
|
-
type: "approvalRequest",
|
|
5232
|
-
serverLabel: value.item.server_label,
|
|
5233
|
-
name: value.item.name,
|
|
5234
|
-
arguments: value.item.arguments,
|
|
5235
|
-
approvalRequestId: value.item.approval_request_id
|
|
5236
|
-
}
|
|
5237
|
-
});
|
|
5238
5193
|
} else if (value.item.type === "local_shell_call") {
|
|
5239
5194
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5240
5195
|
controller.enqueue({
|
|
@@ -5300,6 +5255,38 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5300
5255
|
delta: value.delta
|
|
5301
5256
|
});
|
|
5302
5257
|
}
|
|
5258
|
+
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
5259
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5260
|
+
if (toolCall == null ? void 0 : toolCall.applyPatch) {
|
|
5261
|
+
controller.enqueue({
|
|
5262
|
+
type: "tool-input-delta",
|
|
5263
|
+
id: toolCall.toolCallId,
|
|
5264
|
+
delta: escapeJSONDelta(value.delta)
|
|
5265
|
+
});
|
|
5266
|
+
toolCall.applyPatch.hasDiff = true;
|
|
5267
|
+
}
|
|
5268
|
+
} else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
|
|
5269
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5270
|
+
if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
|
|
5271
|
+
if (!toolCall.applyPatch.hasDiff) {
|
|
5272
|
+
controller.enqueue({
|
|
5273
|
+
type: "tool-input-delta",
|
|
5274
|
+
id: toolCall.toolCallId,
|
|
5275
|
+
delta: escapeJSONDelta(value.diff)
|
|
5276
|
+
});
|
|
5277
|
+
toolCall.applyPatch.hasDiff = true;
|
|
5278
|
+
}
|
|
5279
|
+
controller.enqueue({
|
|
5280
|
+
type: "tool-input-delta",
|
|
5281
|
+
id: toolCall.toolCallId,
|
|
5282
|
+
delta: '"}}'
|
|
5283
|
+
});
|
|
5284
|
+
controller.enqueue({
|
|
5285
|
+
type: "tool-input-end",
|
|
5286
|
+
id: toolCall.toolCallId
|
|
5287
|
+
});
|
|
5288
|
+
toolCall.applyPatch.endEmitted = true;
|
|
5289
|
+
}
|
|
5303
5290
|
} else if (isResponseImageGenerationCallPartialImageChunk(value)) {
|
|
5304
5291
|
controller.enqueue({
|
|
5305
5292
|
type: "tool-result",
|
|
@@ -5316,9 +5303,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5316
5303
|
controller.enqueue({
|
|
5317
5304
|
type: "tool-input-delta",
|
|
5318
5305
|
id: toolCall.toolCallId,
|
|
5319
|
-
|
|
5320
|
-
// To escape it, we use JSON.stringify and slice to remove the outer quotes.
|
|
5321
|
-
delta: JSON.stringify(value.delta).slice(1, -1)
|
|
5306
|
+
delta: escapeJSONDelta(value.delta)
|
|
5322
5307
|
});
|
|
5323
5308
|
}
|
|
5324
5309
|
} else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
|
|
@@ -5538,6 +5523,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
|
|
|
5538
5523
|
function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
|
|
5539
5524
|
return chunk.type === "response.code_interpreter_call_code.done";
|
|
5540
5525
|
}
|
|
5526
|
+
function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
|
|
5527
|
+
return chunk.type === "response.apply_patch_call_operation_diff.delta";
|
|
5528
|
+
}
|
|
5529
|
+
function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
|
|
5530
|
+
return chunk.type === "response.apply_patch_call_operation_diff.done";
|
|
5531
|
+
}
|
|
5541
5532
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
5542
5533
|
return chunk.type === "response.output_item.added";
|
|
5543
5534
|
}
|
|
@@ -5568,6 +5559,9 @@ function mapWebSearchOutput(action) {
|
|
|
5568
5559
|
};
|
|
5569
5560
|
}
|
|
5570
5561
|
}
|
|
5562
|
+
function escapeJSONDelta(delta) {
|
|
5563
|
+
return JSON.stringify(delta).slice(1, -1);
|
|
5564
|
+
}
|
|
5571
5565
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5572
5566
|
0 && (module.exports = {
|
|
5573
5567
|
OpenAIChatLanguageModel,
|