@ai-sdk/openai 3.0.119 → 3.0.120
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 +8 -0
- package/dist/index.js +9 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -77
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +8 -76
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +9 -76
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/chat/openai-chat-language-model.ts +8 -109
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 3.0.120
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 29dc427: fix(provider-utils): preserve streamed tool calls with unreliable IDs and indices
|
|
8
|
+
- Updated dependencies [29dc427]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.56
|
|
10
|
+
|
|
3
11
|
## 3.0.119
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1234,7 +1234,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1234
1234
|
requestBodyValues: body,
|
|
1235
1235
|
responseHeaders
|
|
1236
1236
|
});
|
|
1237
|
-
|
|
1237
|
+
let toolCallTracker;
|
|
1238
1238
|
let finishReason = {
|
|
1239
1239
|
unified: "other",
|
|
1240
1240
|
raw: void 0
|
|
@@ -1247,10 +1247,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
1247
1247
|
stream: checkedResponse.pipeThrough(
|
|
1248
1248
|
new TransformStream({
|
|
1249
1249
|
start(controller) {
|
|
1250
|
+
toolCallTracker = new import_provider_utils5.StreamingToolCallTracker(controller, {
|
|
1251
|
+
generateId: import_provider_utils5.generateId,
|
|
1252
|
+
typeValidation: "if-present"
|
|
1253
|
+
});
|
|
1250
1254
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1251
1255
|
},
|
|
1252
1256
|
transform(chunk, controller) {
|
|
1253
|
-
var _a2, _b, _c, _d, _e
|
|
1257
|
+
var _a2, _b, _c, _d, _e;
|
|
1254
1258
|
if (options.includeRawChunks) {
|
|
1255
1259
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1256
1260
|
}
|
|
@@ -1311,64 +1315,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1311
1315
|
}
|
|
1312
1316
|
if (delta.tool_calls != null) {
|
|
1313
1317
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1314
|
-
|
|
1315
|
-
if (toolCalls[index] == null) {
|
|
1316
|
-
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
1317
|
-
throw new import_provider4.InvalidResponseDataError({
|
|
1318
|
-
data: toolCallDelta,
|
|
1319
|
-
message: `Expected 'function' type.`
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
if (toolCallDelta.id == null) {
|
|
1323
|
-
throw new import_provider4.InvalidResponseDataError({
|
|
1324
|
-
data: toolCallDelta,
|
|
1325
|
-
message: `Expected 'id' to be a string.`
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
if (((_f = toolCallDelta.function) == null ? void 0 : _f.name) == null) {
|
|
1329
|
-
throw new import_provider4.InvalidResponseDataError({
|
|
1330
|
-
data: toolCallDelta,
|
|
1331
|
-
message: `Expected 'function.name' to be a string.`
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
controller.enqueue({
|
|
1335
|
-
type: "tool-input-start",
|
|
1336
|
-
id: toolCallDelta.id,
|
|
1337
|
-
toolName: toolCallDelta.function.name
|
|
1338
|
-
});
|
|
1339
|
-
toolCalls[index] = {
|
|
1340
|
-
id: toolCallDelta.id,
|
|
1341
|
-
type: "function",
|
|
1342
|
-
function: {
|
|
1343
|
-
name: toolCallDelta.function.name,
|
|
1344
|
-
arguments: (_g = toolCallDelta.function.arguments) != null ? _g : ""
|
|
1345
|
-
},
|
|
1346
|
-
hasFinished: false
|
|
1347
|
-
};
|
|
1348
|
-
const toolCall2 = toolCalls[index];
|
|
1349
|
-
if (((_h = toolCall2.function) == null ? void 0 : _h.name) != null && ((_i = toolCall2.function) == null ? void 0 : _i.arguments) != null) {
|
|
1350
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
1351
|
-
controller.enqueue({
|
|
1352
|
-
type: "tool-input-delta",
|
|
1353
|
-
id: toolCall2.id,
|
|
1354
|
-
delta: toolCall2.function.arguments
|
|
1355
|
-
});
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
continue;
|
|
1359
|
-
}
|
|
1360
|
-
const toolCall = toolCalls[index];
|
|
1361
|
-
if (toolCall.hasFinished) {
|
|
1362
|
-
continue;
|
|
1363
|
-
}
|
|
1364
|
-
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
|
|
1365
|
-
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
1366
|
-
}
|
|
1367
|
-
controller.enqueue({
|
|
1368
|
-
type: "tool-input-delta",
|
|
1369
|
-
id: toolCall.id,
|
|
1370
|
-
delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
1371
|
-
});
|
|
1318
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
1372
1319
|
}
|
|
1373
1320
|
}
|
|
1374
1321
|
if (delta.annotations != null) {
|
|
@@ -1384,25 +1331,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
1384
1331
|
}
|
|
1385
1332
|
},
|
|
1386
1333
|
flush(controller) {
|
|
1387
|
-
var _a2;
|
|
1388
1334
|
if (isActiveText) {
|
|
1389
1335
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1390
1336
|
}
|
|
1391
|
-
|
|
1392
|
-
if (!toolCall.hasFinished) {
|
|
1393
|
-
controller.enqueue({
|
|
1394
|
-
type: "tool-input-end",
|
|
1395
|
-
id: toolCall.id
|
|
1396
|
-
});
|
|
1397
|
-
controller.enqueue({
|
|
1398
|
-
type: "tool-call",
|
|
1399
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils5.generateId)(),
|
|
1400
|
-
toolName: toolCall.function.name,
|
|
1401
|
-
input: toolCall.function.arguments
|
|
1402
|
-
});
|
|
1403
|
-
toolCall.hasFinished = true;
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1337
|
+
toolCallTracker.flush();
|
|
1406
1338
|
controller.enqueue({
|
|
1407
1339
|
type: "finish",
|
|
1408
1340
|
finishReason,
|
|
@@ -8205,7 +8137,7 @@ var OpenAITranscriptionModel = class {
|
|
|
8205
8137
|
};
|
|
8206
8138
|
|
|
8207
8139
|
// src/version.ts
|
|
8208
|
-
var VERSION = true ? "3.0.
|
|
8140
|
+
var VERSION = true ? "3.0.120" : "0.0.0-test";
|
|
8209
8141
|
|
|
8210
8142
|
// src/openai-provider.ts
|
|
8211
8143
|
function createOpenAI(options = {}) {
|