@ai-sdk/openai 4.0.32 → 4.0.34
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 +13 -0
- package/dist/index.d.ts +22 -18
- package/dist/index.js +2947 -2402
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +650 -22
- package/dist/internal/index.js +117 -70
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +38 -0
- package/package.json +1 -1
- package/src/index.ts +12 -4
- package/src/openai-provider.ts +19 -14
- package/src/openai-responses-batch.ts +675 -0
- package/src/responses/openai-responses-api.ts +4 -0
- package/src/responses/openai-responses-language-model.ts +137 -90
- package/src/speech-translation/openai-speech-translation-model-options.ts +18 -0
- package/src/{translation/openai-translation-model.ts → speech-translation/openai-speech-translation-model.ts} +22 -22
- package/src/translation/openai-translation-model-options.ts +0 -16
package/dist/internal/index.js
CHANGED
|
@@ -4497,6 +4497,7 @@ var openaiResponsesChunkSchema = lazySchema18(
|
|
|
4497
4497
|
z20.object({
|
|
4498
4498
|
type: z20.literal("response.output_text.delta"),
|
|
4499
4499
|
item_id: z20.string(),
|
|
4500
|
+
output_index: z20.number().nullish(),
|
|
4500
4501
|
delta: z20.string(),
|
|
4501
4502
|
logprobs: z20.array(
|
|
4502
4503
|
z20.object({
|
|
@@ -5021,17 +5022,20 @@ var openaiResponsesChunkSchema = lazySchema18(
|
|
|
5021
5022
|
z20.object({
|
|
5022
5023
|
type: z20.literal("response.reasoning_summary_part.added"),
|
|
5023
5024
|
item_id: z20.string(),
|
|
5025
|
+
output_index: z20.number().nullish(),
|
|
5024
5026
|
summary_index: z20.number()
|
|
5025
5027
|
}),
|
|
5026
5028
|
z20.object({
|
|
5027
5029
|
type: z20.literal("response.reasoning_summary_text.delta"),
|
|
5028
5030
|
item_id: z20.string(),
|
|
5031
|
+
output_index: z20.number().nullish(),
|
|
5029
5032
|
summary_index: z20.number(),
|
|
5030
5033
|
delta: z20.string()
|
|
5031
5034
|
}),
|
|
5032
5035
|
z20.object({
|
|
5033
5036
|
type: z20.literal("response.reasoning_summary_part.done"),
|
|
5034
5037
|
item_id: z20.string(),
|
|
5038
|
+
output_index: z20.number().nullish(),
|
|
5035
5039
|
summary_index: z20.number()
|
|
5036
5040
|
}),
|
|
5037
5041
|
z20.object({
|
|
@@ -7358,6 +7362,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7358
7362
|
let activeMessagePhase;
|
|
7359
7363
|
let hasFunctionCall = false;
|
|
7360
7364
|
const activeReasoning = {};
|
|
7365
|
+
const activeOutputItemIds = {};
|
|
7366
|
+
const resolveOutputItemId = ({
|
|
7367
|
+
itemId,
|
|
7368
|
+
outputIndex
|
|
7369
|
+
}) => {
|
|
7370
|
+
var _a2;
|
|
7371
|
+
return outputIndex == null ? itemId : (_a2 = activeOutputItemIds[outputIndex]) != null ? _a2 : itemId;
|
|
7372
|
+
};
|
|
7361
7373
|
let serviceTier;
|
|
7362
7374
|
let reasoningContext;
|
|
7363
7375
|
const hostedToolSearchCallIds = [];
|
|
@@ -7369,7 +7381,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7369
7381
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7370
7382
|
},
|
|
7371
7383
|
transform(chunk, controller) {
|
|
7372
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N
|
|
7384
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N;
|
|
7373
7385
|
if (options.includeRawChunks) {
|
|
7374
7386
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
7375
7387
|
}
|
|
@@ -7547,6 +7559,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7547
7559
|
};
|
|
7548
7560
|
} else if (value.item.type === "shell_call_output") {
|
|
7549
7561
|
} else if (value.item.type === "message") {
|
|
7562
|
+
activeOutputItemIds[value.output_index] = value.item.id;
|
|
7550
7563
|
ongoingAnnotations.splice(0, ongoingAnnotations.length);
|
|
7551
7564
|
activeMessagePhase = (_c = value.item.phase) != null ? _c : void 0;
|
|
7552
7565
|
controller.enqueue({
|
|
@@ -7562,6 +7575,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7562
7575
|
}
|
|
7563
7576
|
});
|
|
7564
7577
|
} else if (isResponseOutputItemAddedChunk(value) && value.item.type === "reasoning") {
|
|
7578
|
+
activeOutputItemIds[value.output_index] = value.item.id;
|
|
7565
7579
|
activeReasoning[value.item.id] = {
|
|
7566
7580
|
encryptedContent: value.item.encrypted_content,
|
|
7567
7581
|
summaryParts: { 0: "active" }
|
|
@@ -7579,14 +7593,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7579
7593
|
}
|
|
7580
7594
|
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
7581
7595
|
if (value.item.type === "message") {
|
|
7596
|
+
const itemId = resolveOutputItemId({
|
|
7597
|
+
itemId: value.item.id,
|
|
7598
|
+
outputIndex: value.output_index
|
|
7599
|
+
});
|
|
7582
7600
|
const phase = (_e = value.item.phase) != null ? _e : activeMessagePhase;
|
|
7583
7601
|
activeMessagePhase = void 0;
|
|
7584
7602
|
controller.enqueue({
|
|
7585
7603
|
type: "text-end",
|
|
7586
|
-
id:
|
|
7604
|
+
id: itemId,
|
|
7587
7605
|
providerMetadata: {
|
|
7588
7606
|
[providerOptionsName]: {
|
|
7589
|
-
itemId
|
|
7607
|
+
itemId,
|
|
7590
7608
|
...phase != null && { phase },
|
|
7591
7609
|
...ongoingAnnotations.length > 0 && {
|
|
7592
7610
|
annotations: ongoingAnnotations
|
|
@@ -7594,6 +7612,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7594
7612
|
}
|
|
7595
7613
|
}
|
|
7596
7614
|
});
|
|
7615
|
+
activeOutputItemIds[value.output_index] = void 0;
|
|
7597
7616
|
} else if (value.item.type === "function_call") {
|
|
7598
7617
|
ongoingToolCalls[value.output_index] = void 0;
|
|
7599
7618
|
hasFunctionCall = true;
|
|
@@ -7980,25 +7999,32 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7980
7999
|
}
|
|
7981
8000
|
});
|
|
7982
8001
|
} else if (value.item.type === "reasoning") {
|
|
7983
|
-
const
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
)
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
8002
|
+
const itemId = resolveOutputItemId({
|
|
8003
|
+
itemId: value.item.id,
|
|
8004
|
+
outputIndex: value.output_index
|
|
8005
|
+
});
|
|
8006
|
+
const activeReasoningPart = activeReasoning[itemId];
|
|
8007
|
+
if (activeReasoningPart != null) {
|
|
8008
|
+
const summaryPartIndices = Object.entries(
|
|
8009
|
+
activeReasoningPart.summaryParts
|
|
8010
|
+
).filter(
|
|
8011
|
+
([_, status]) => status === "active" || status === "can-conclude"
|
|
8012
|
+
).map(([summaryIndex]) => summaryIndex);
|
|
8013
|
+
for (const summaryIndex of summaryPartIndices) {
|
|
8014
|
+
controller.enqueue({
|
|
8015
|
+
type: "reasoning-end",
|
|
8016
|
+
id: `${itemId}:${summaryIndex}`,
|
|
8017
|
+
providerMetadata: {
|
|
8018
|
+
[providerOptionsName]: {
|
|
8019
|
+
itemId,
|
|
8020
|
+
reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
|
|
8021
|
+
}
|
|
7997
8022
|
}
|
|
7998
|
-
}
|
|
7999
|
-
}
|
|
8023
|
+
});
|
|
8024
|
+
}
|
|
8025
|
+
delete activeReasoning[itemId];
|
|
8000
8026
|
}
|
|
8001
|
-
|
|
8027
|
+
activeOutputItemIds[value.output_index] = void 0;
|
|
8002
8028
|
} else if (value.item.type === "compaction") {
|
|
8003
8029
|
controller.enqueue({
|
|
8004
8030
|
type: "custom",
|
|
@@ -8113,88 +8139,109 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8113
8139
|
modelId: value.response.model
|
|
8114
8140
|
});
|
|
8115
8141
|
} else if (isTextDeltaChunk(value)) {
|
|
8142
|
+
const itemId = resolveOutputItemId({
|
|
8143
|
+
itemId: value.item_id,
|
|
8144
|
+
outputIndex: value.output_index
|
|
8145
|
+
});
|
|
8116
8146
|
controller.enqueue({
|
|
8117
8147
|
type: "text-delta",
|
|
8118
|
-
id:
|
|
8148
|
+
id: itemId,
|
|
8119
8149
|
delta: value.delta
|
|
8120
8150
|
});
|
|
8121
8151
|
if (((_t = (_s = options.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.logprobs) && value.logprobs) {
|
|
8122
8152
|
logprobs.push(value.logprobs);
|
|
8123
8153
|
}
|
|
8124
8154
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
8155
|
+
const itemId = resolveOutputItemId({
|
|
8156
|
+
itemId: value.item_id,
|
|
8157
|
+
outputIndex: value.output_index
|
|
8158
|
+
});
|
|
8125
8159
|
if (value.summary_index > 0) {
|
|
8126
|
-
const activeReasoningPart = activeReasoning[
|
|
8127
|
-
activeReasoningPart
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8160
|
+
const activeReasoningPart = activeReasoning[itemId];
|
|
8161
|
+
if (activeReasoningPart != null) {
|
|
8162
|
+
activeReasoningPart.summaryParts[value.summary_index] = "active";
|
|
8163
|
+
for (const summaryIndex of Object.keys(
|
|
8164
|
+
activeReasoningPart.summaryParts
|
|
8165
|
+
)) {
|
|
8166
|
+
if (activeReasoningPart.summaryParts[summaryIndex] === "can-conclude") {
|
|
8167
|
+
controller.enqueue({
|
|
8168
|
+
type: "reasoning-end",
|
|
8169
|
+
id: `${itemId}:${summaryIndex}`,
|
|
8170
|
+
providerMetadata: {
|
|
8171
|
+
[providerOptionsName]: {
|
|
8172
|
+
itemId
|
|
8173
|
+
}
|
|
8138
8174
|
}
|
|
8139
|
-
}
|
|
8140
|
-
|
|
8141
|
-
activeReasoningPart.summaryParts[summaryIndex] = "concluded";
|
|
8142
|
-
}
|
|
8143
|
-
}
|
|
8144
|
-
controller.enqueue({
|
|
8145
|
-
type: "reasoning-start",
|
|
8146
|
-
id: `${value.item_id}:${value.summary_index}`,
|
|
8147
|
-
providerMetadata: {
|
|
8148
|
-
[providerOptionsName]: {
|
|
8149
|
-
itemId: value.item_id,
|
|
8150
|
-
reasoningEncryptedContent: (_v = (_u = activeReasoning[value.item_id]) == null ? void 0 : _u.encryptedContent) != null ? _v : null
|
|
8175
|
+
});
|
|
8176
|
+
activeReasoningPart.summaryParts[summaryIndex] = "concluded";
|
|
8151
8177
|
}
|
|
8152
8178
|
}
|
|
8153
|
-
|
|
8179
|
+
controller.enqueue({
|
|
8180
|
+
type: "reasoning-start",
|
|
8181
|
+
id: `${itemId}:${value.summary_index}`,
|
|
8182
|
+
providerMetadata: {
|
|
8183
|
+
[providerOptionsName]: {
|
|
8184
|
+
itemId,
|
|
8185
|
+
reasoningEncryptedContent: (_u = activeReasoningPart.encryptedContent) != null ? _u : null
|
|
8186
|
+
}
|
|
8187
|
+
}
|
|
8188
|
+
});
|
|
8189
|
+
}
|
|
8154
8190
|
}
|
|
8155
8191
|
} else if (value.type === "response.reasoning_summary_text.delta") {
|
|
8192
|
+
const itemId = resolveOutputItemId({
|
|
8193
|
+
itemId: value.item_id,
|
|
8194
|
+
outputIndex: value.output_index
|
|
8195
|
+
});
|
|
8156
8196
|
controller.enqueue({
|
|
8157
8197
|
type: "reasoning-delta",
|
|
8158
|
-
id: `${
|
|
8198
|
+
id: `${itemId}:${value.summary_index}`,
|
|
8159
8199
|
delta: value.delta,
|
|
8160
8200
|
providerMetadata: {
|
|
8161
8201
|
[providerOptionsName]: {
|
|
8162
|
-
itemId
|
|
8202
|
+
itemId
|
|
8163
8203
|
}
|
|
8164
8204
|
}
|
|
8165
8205
|
});
|
|
8166
8206
|
} else if (value.type === "response.reasoning_summary_part.done") {
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8207
|
+
const itemId = resolveOutputItemId({
|
|
8208
|
+
itemId: value.item_id,
|
|
8209
|
+
outputIndex: value.output_index
|
|
8210
|
+
});
|
|
8211
|
+
const activeReasoningPart = activeReasoning[itemId];
|
|
8212
|
+
if (activeReasoningPart != null) {
|
|
8213
|
+
if (store) {
|
|
8214
|
+
controller.enqueue({
|
|
8215
|
+
type: "reasoning-end",
|
|
8216
|
+
id: `${itemId}:${value.summary_index}`,
|
|
8217
|
+
providerMetadata: {
|
|
8218
|
+
[providerOptionsName]: {
|
|
8219
|
+
itemId
|
|
8220
|
+
}
|
|
8174
8221
|
}
|
|
8175
|
-
}
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8222
|
+
});
|
|
8223
|
+
activeReasoningPart.summaryParts[value.summary_index] = "concluded";
|
|
8224
|
+
} else {
|
|
8225
|
+
activeReasoningPart.summaryParts[value.summary_index] = "can-conclude";
|
|
8226
|
+
}
|
|
8180
8227
|
}
|
|
8181
8228
|
} else if (isResponseFinishedChunk(value)) {
|
|
8182
8229
|
finishReason = {
|
|
8183
8230
|
unified: mapOpenAIResponseFinishReason({
|
|
8184
|
-
finishReason: (
|
|
8231
|
+
finishReason: (_v = value.response.incomplete_details) == null ? void 0 : _v.reason,
|
|
8185
8232
|
hasFunctionCall
|
|
8186
8233
|
}),
|
|
8187
|
-
raw: (
|
|
8234
|
+
raw: (_x = (_w = value.response.incomplete_details) == null ? void 0 : _w.reason) != null ? _x : void 0
|
|
8188
8235
|
};
|
|
8189
8236
|
usage = value.response.usage;
|
|
8190
8237
|
if (typeof value.response.service_tier === "string") {
|
|
8191
8238
|
serviceTier = value.response.service_tier;
|
|
8192
8239
|
}
|
|
8193
|
-
if (((
|
|
8240
|
+
if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
|
|
8194
8241
|
reasoningContext = value.response.reasoning.context;
|
|
8195
8242
|
}
|
|
8196
8243
|
} else if (isResponseFailedChunk(value)) {
|
|
8197
|
-
const incompleteReason = (
|
|
8244
|
+
const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
|
|
8198
8245
|
finishReason = {
|
|
8199
8246
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
8200
8247
|
finishReason: incompleteReason,
|
|
@@ -8202,8 +8249,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8202
8249
|
}) : "error",
|
|
8203
8250
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
8204
8251
|
};
|
|
8205
|
-
usage = (
|
|
8206
|
-
if (((
|
|
8252
|
+
usage = (_A = value.response.usage) != null ? _A : void 0;
|
|
8253
|
+
if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
|
|
8207
8254
|
reasoningContext = value.response.reasoning.context;
|
|
8208
8255
|
}
|
|
8209
8256
|
if (!encounteredStreamError && value.response.error != null) {
|
|
@@ -8227,7 +8274,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8227
8274
|
controller.enqueue({
|
|
8228
8275
|
type: "source",
|
|
8229
8276
|
sourceType: "url",
|
|
8230
|
-
id: (
|
|
8277
|
+
id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
|
|
8231
8278
|
url: value.annotation.url,
|
|
8232
8279
|
title: value.annotation.title
|
|
8233
8280
|
});
|
|
@@ -8235,7 +8282,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8235
8282
|
controller.enqueue({
|
|
8236
8283
|
type: "source",
|
|
8237
8284
|
sourceType: "document",
|
|
8238
|
-
id: (
|
|
8285
|
+
id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
|
|
8239
8286
|
mediaType: "text/plain",
|
|
8240
8287
|
title: value.annotation.filename,
|
|
8241
8288
|
filename: value.annotation.filename,
|
|
@@ -8251,7 +8298,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8251
8298
|
controller.enqueue({
|
|
8252
8299
|
type: "source",
|
|
8253
8300
|
sourceType: "document",
|
|
8254
|
-
id: (
|
|
8301
|
+
id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
|
|
8255
8302
|
mediaType: "text/plain",
|
|
8256
8303
|
title: value.annotation.filename,
|
|
8257
8304
|
filename: value.annotation.filename,
|
|
@@ -8267,7 +8314,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8267
8314
|
controller.enqueue({
|
|
8268
8315
|
type: "source",
|
|
8269
8316
|
sourceType: "document",
|
|
8270
|
-
id: (
|
|
8317
|
+
id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
|
|
8271
8318
|
mediaType: "application/octet-stream",
|
|
8272
8319
|
title: value.annotation.file_id,
|
|
8273
8320
|
filename: value.annotation.file_id,
|