ai 6.0.285 → 6.0.287
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 +25 -0
- package/dist/index.js +73 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +6 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +6 -5
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/generate-object/generate-object.ts +1 -0
- package/src/generate-object/stream-object.ts +1 -0
- package/src/generate-text/generate-text.ts +1 -0
- package/src/generate-text/prune-messages.ts +13 -0
- package/src/generate-text/stream-text.ts +27 -7
- package/src/middleware/simulate-streaming-middleware.ts +7 -1
- package/src/prompt/convert-to-language-model-prompt.ts +4 -2
- package/src/ui/convert-to-model-messages.ts +8 -2
- package/src/ui-message-stream/read-ui-message-stream.ts +13 -4
- package/src/util/download/download-function.ts +5 -2
package/dist/index.mjs
CHANGED
|
@@ -1224,7 +1224,7 @@ import {
|
|
|
1224
1224
|
} from "@ai-sdk/provider-utils";
|
|
1225
1225
|
|
|
1226
1226
|
// src/version.ts
|
|
1227
|
-
var VERSION = true ? "6.0.
|
|
1227
|
+
var VERSION = true ? "6.0.287" : "0.0.0-test";
|
|
1228
1228
|
|
|
1229
1229
|
// src/util/download/download.ts
|
|
1230
1230
|
var download = async ({
|
|
@@ -1271,9 +1271,9 @@ var download = async ({
|
|
|
1271
1271
|
};
|
|
1272
1272
|
|
|
1273
1273
|
// src/util/download/download-function.ts
|
|
1274
|
-
var createDefaultDownloadFunction = (download2 = download) => (requestedDownloads) => Promise.all(
|
|
1274
|
+
var createDefaultDownloadFunction = (download2 = download, abortSignal) => (requestedDownloads) => Promise.all(
|
|
1275
1275
|
requestedDownloads.map(
|
|
1276
|
-
async (requestedDownload) => requestedDownload.isUrlSupportedByModel ? null : download2(requestedDownload)
|
|
1276
|
+
async (requestedDownload) => requestedDownload.isUrlSupportedByModel ? null : await download2({ ...requestedDownload, abortSignal })
|
|
1277
1277
|
)
|
|
1278
1278
|
);
|
|
1279
1279
|
|
|
@@ -1412,11 +1412,12 @@ function convertDataContentToUint8Array(content) {
|
|
|
1412
1412
|
async function convertToLanguageModelPrompt({
|
|
1413
1413
|
prompt,
|
|
1414
1414
|
supportedUrls,
|
|
1415
|
-
download: download2
|
|
1415
|
+
download: download2,
|
|
1416
|
+
abortSignal
|
|
1416
1417
|
}) {
|
|
1417
1418
|
const downloadedAssets = await downloadAssets(
|
|
1418
1419
|
prompt.messages,
|
|
1419
|
-
download2,
|
|
1420
|
+
download2 != null ? download2 : createDefaultDownloadFunction(void 0, abortSignal),
|
|
1420
1421
|
supportedUrls
|
|
1421
1422
|
);
|
|
1422
1423
|
const approvalIdToToolCallId = /* @__PURE__ */ new Map();
|
|
@@ -4735,7 +4736,8 @@ async function generateText({
|
|
|
4735
4736
|
messages: (_c = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _c : stepInputMessages
|
|
4736
4737
|
},
|
|
4737
4738
|
supportedUrls: await stepModel.supportedUrls,
|
|
4738
|
-
download: download2
|
|
4739
|
+
download: download2,
|
|
4740
|
+
abortSignal: mergedAbortSignal
|
|
4739
4741
|
});
|
|
4740
4742
|
experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
|
|
4741
4743
|
const stepActiveTools = (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools;
|
|
@@ -7223,7 +7225,15 @@ function createOutputTransformStream(output) {
|
|
|
7223
7225
|
let text2 = "";
|
|
7224
7226
|
let textChunk = "";
|
|
7225
7227
|
let textProviderMetadata = void 0;
|
|
7226
|
-
let lastPublishedValue =
|
|
7228
|
+
let lastPublishedValue = void 0;
|
|
7229
|
+
let hasPublishedValue = false;
|
|
7230
|
+
function resetOutputState() {
|
|
7231
|
+
firstTextChunkId = void 0;
|
|
7232
|
+
text2 = "";
|
|
7233
|
+
textChunk = "";
|
|
7234
|
+
textProviderMetadata = void 0;
|
|
7235
|
+
lastPublishedValue = "";
|
|
7236
|
+
}
|
|
7227
7237
|
function publishTextChunk({
|
|
7228
7238
|
controller,
|
|
7229
7239
|
partialOutput = void 0
|
|
@@ -7242,6 +7252,9 @@ function createOutputTransformStream(output) {
|
|
|
7242
7252
|
return new TransformStream({
|
|
7243
7253
|
async transform(chunk, controller) {
|
|
7244
7254
|
var _a23;
|
|
7255
|
+
if (chunk.type === "start-step") {
|
|
7256
|
+
resetOutputState();
|
|
7257
|
+
}
|
|
7245
7258
|
if (chunk.type === "finish-step" && textChunk.length > 0) {
|
|
7246
7259
|
publishTextChunk({ controller });
|
|
7247
7260
|
}
|
|
@@ -7276,9 +7289,10 @@ function createOutputTransformStream(output) {
|
|
|
7276
7289
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
7277
7290
|
if (result !== void 0) {
|
|
7278
7291
|
const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
|
|
7279
|
-
if (currentValue !== lastPublishedValue) {
|
|
7292
|
+
if (!hasPublishedValue || currentValue !== lastPublishedValue) {
|
|
7280
7293
|
publishTextChunk({ controller, partialOutput: result.partial });
|
|
7281
7294
|
lastPublishedValue = currentValue;
|
|
7295
|
+
hasPublishedValue = true;
|
|
7282
7296
|
}
|
|
7283
7297
|
}
|
|
7284
7298
|
}
|
|
@@ -7349,6 +7363,7 @@ var DefaultStreamTextResult = class {
|
|
|
7349
7363
|
const recordedSteps = [];
|
|
7350
7364
|
let recordedNoOutputError;
|
|
7351
7365
|
let currentStepToolSet = tools;
|
|
7366
|
+
let currentStepModel = model;
|
|
7352
7367
|
const createPartIdReserver = () => {
|
|
7353
7368
|
const usedIds = /* @__PURE__ */ new Set();
|
|
7354
7369
|
return (id) => {
|
|
@@ -7505,7 +7520,10 @@ var DefaultStreamTextResult = class {
|
|
|
7505
7520
|
});
|
|
7506
7521
|
const currentStepResult = new DefaultStepResult({
|
|
7507
7522
|
stepNumber: recordedSteps.length,
|
|
7508
|
-
model:
|
|
7523
|
+
model: {
|
|
7524
|
+
provider: currentStepModel.provider,
|
|
7525
|
+
modelId: currentStepModel.modelId
|
|
7526
|
+
},
|
|
7509
7527
|
...callbackTelemetryProps,
|
|
7510
7528
|
experimental_context,
|
|
7511
7529
|
content: recordedContent,
|
|
@@ -7526,8 +7544,8 @@ var DefaultStreamTextResult = class {
|
|
|
7526
7544
|
});
|
|
7527
7545
|
logWarnings({
|
|
7528
7546
|
warnings: recordedWarnings,
|
|
7529
|
-
provider:
|
|
7530
|
-
model:
|
|
7547
|
+
provider: currentStepModel.provider,
|
|
7548
|
+
model: currentStepModel.modelId
|
|
7531
7549
|
});
|
|
7532
7550
|
recordedSteps.push(currentStepResult);
|
|
7533
7551
|
recordedResponseMessages.push(...stepMessages);
|
|
@@ -7966,6 +7984,7 @@ var DefaultStreamTextResult = class {
|
|
|
7966
7984
|
const stepModel = resolveLanguageModel(
|
|
7967
7985
|
(_a23 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a23 : model
|
|
7968
7986
|
);
|
|
7987
|
+
currentStepModel = stepModel;
|
|
7969
7988
|
const stepModelInfo = {
|
|
7970
7989
|
provider: stepModel.provider,
|
|
7971
7990
|
modelId: stepModel.modelId
|
|
@@ -7976,7 +7995,8 @@ var DefaultStreamTextResult = class {
|
|
|
7976
7995
|
messages: (_c = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _c : stepInputMessages
|
|
7977
7996
|
},
|
|
7978
7997
|
supportedUrls: await stepModel.supportedUrls,
|
|
7979
|
-
download: download2
|
|
7998
|
+
download: download2,
|
|
7999
|
+
abortSignal
|
|
7980
8000
|
});
|
|
7981
8001
|
const stepActiveTools = (_d = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _d : activeTools;
|
|
7982
8002
|
const stepToolSet = filterActiveTools({
|
|
@@ -8125,7 +8145,7 @@ var DefaultStreamTextResult = class {
|
|
|
8125
8145
|
let stepResponse = {
|
|
8126
8146
|
id: generateId2(),
|
|
8127
8147
|
timestamp: /* @__PURE__ */ new Date(),
|
|
8128
|
-
modelId:
|
|
8148
|
+
modelId: stepModelInfo.modelId
|
|
8129
8149
|
};
|
|
8130
8150
|
let activeText = "";
|
|
8131
8151
|
const textPartIds = /* @__PURE__ */ new Map();
|
|
@@ -8647,7 +8667,7 @@ var DefaultStreamTextResult = class {
|
|
|
8647
8667
|
this.teeStream().pipeThrough(
|
|
8648
8668
|
new TransformStream({
|
|
8649
8669
|
transform({ partialOutput }, controller) {
|
|
8650
|
-
if (partialOutput
|
|
8670
|
+
if (partialOutput !== void 0) {
|
|
8651
8671
|
controller.enqueue(partialOutput);
|
|
8652
8672
|
}
|
|
8653
8673
|
}
|
|
@@ -9341,9 +9361,15 @@ function readUIMessageStream({
|
|
|
9341
9361
|
var _a23;
|
|
9342
9362
|
let controller;
|
|
9343
9363
|
let hasErrored = false;
|
|
9364
|
+
let isCancelled = false;
|
|
9365
|
+
const abortController = new AbortController();
|
|
9344
9366
|
const outputStream = new ReadableStream({
|
|
9345
9367
|
start(controllerParam) {
|
|
9346
9368
|
controller = controllerParam;
|
|
9369
|
+
},
|
|
9370
|
+
cancel() {
|
|
9371
|
+
isCancelled = true;
|
|
9372
|
+
abortController.abort();
|
|
9347
9373
|
}
|
|
9348
9374
|
});
|
|
9349
9375
|
const state = createStreamingUIMessageState({
|
|
@@ -9364,15 +9390,18 @@ function readUIMessageStream({
|
|
|
9364
9390
|
return job({
|
|
9365
9391
|
state,
|
|
9366
9392
|
write: () => {
|
|
9367
|
-
|
|
9393
|
+
if (!isCancelled) {
|
|
9394
|
+
controller == null ? void 0 : controller.enqueue(createUIMessageSnapshot(state.message));
|
|
9395
|
+
}
|
|
9368
9396
|
}
|
|
9369
9397
|
});
|
|
9370
9398
|
},
|
|
9371
9399
|
onError: handleError
|
|
9372
9400
|
}),
|
|
9373
|
-
onError: handleError
|
|
9401
|
+
onError: handleError,
|
|
9402
|
+
abortSignal: abortController.signal
|
|
9374
9403
|
}).finally(() => {
|
|
9375
|
-
if (!hasErrored) {
|
|
9404
|
+
if (!hasErrored && !isCancelled) {
|
|
9376
9405
|
controller == null ? void 0 : controller.close();
|
|
9377
9406
|
}
|
|
9378
9407
|
});
|
|
@@ -9447,7 +9476,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9447
9476
|
if (message.parts != null) {
|
|
9448
9477
|
let block = [];
|
|
9449
9478
|
async function processBlock() {
|
|
9450
|
-
var _a23, _b, _c, _d, _e, _f, _g, _h;
|
|
9479
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9451
9480
|
if (block.length === 0) {
|
|
9452
9481
|
return;
|
|
9453
9482
|
}
|
|
@@ -9476,13 +9505,14 @@ async function convertToModelMessages(messages, options) {
|
|
|
9476
9505
|
} else if (isToolUIPart(part)) {
|
|
9477
9506
|
const toolName = getToolName(part);
|
|
9478
9507
|
if (part.state !== "input-streaming") {
|
|
9508
|
+
const callProviderMetadata = (_a23 = part.callProviderMetadata) != null ? _a23 : part.state === "output-error" ? part.resultProviderMetadata : void 0;
|
|
9479
9509
|
content.push({
|
|
9480
9510
|
type: "tool-call",
|
|
9481
9511
|
toolCallId: part.toolCallId,
|
|
9482
9512
|
toolName,
|
|
9483
|
-
input: part.state === "output-error" ? (
|
|
9513
|
+
input: part.state === "output-error" ? (_b = part.input) != null ? _b : "rawInput" in part ? part.rawInput : void 0 : part.input,
|
|
9484
9514
|
providerExecuted: part.providerExecuted,
|
|
9485
|
-
...
|
|
9515
|
+
...callProviderMetadata != null ? { providerOptions: callProviderMetadata } : {}
|
|
9486
9516
|
});
|
|
9487
9517
|
if (part.approval != null) {
|
|
9488
9518
|
content.push({
|
|
@@ -9493,7 +9523,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9493
9523
|
});
|
|
9494
9524
|
}
|
|
9495
9525
|
if (part.providerExecuted === true && part.state !== "approval-responded" && (part.state === "output-available" || part.state === "output-error")) {
|
|
9496
|
-
const resultProviderMetadata = (
|
|
9526
|
+
const resultProviderMetadata = (_c = part.resultProviderMetadata) != null ? _c : part.callProviderMetadata;
|
|
9497
9527
|
content.push({
|
|
9498
9528
|
type: "tool-result",
|
|
9499
9529
|
toolCallId: part.toolCallId,
|
|
@@ -9502,7 +9532,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9502
9532
|
toolCallId: part.toolCallId,
|
|
9503
9533
|
input: part.input,
|
|
9504
9534
|
output: part.state === "output-error" ? part.errorText : part.output,
|
|
9505
|
-
tool: (
|
|
9535
|
+
tool: (_d = options == null ? void 0 : options.tools) == null ? void 0 : _d[toolName],
|
|
9506
9536
|
errorMode: part.state === "output-error" ? "json" : "none"
|
|
9507
9537
|
}),
|
|
9508
9538
|
...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
|
|
@@ -9510,7 +9540,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9510
9540
|
}
|
|
9511
9541
|
}
|
|
9512
9542
|
} else if (isDataUIPart(part)) {
|
|
9513
|
-
const dataPart = (
|
|
9543
|
+
const dataPart = (_e = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _e.call(
|
|
9514
9544
|
options,
|
|
9515
9545
|
part
|
|
9516
9546
|
);
|
|
@@ -9538,7 +9568,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9538
9568
|
{
|
|
9539
9569
|
const content2 = [];
|
|
9540
9570
|
for (const toolPart of toolParts) {
|
|
9541
|
-
if (((
|
|
9571
|
+
if (((_f = toolPart.approval) == null ? void 0 : _f.approved) != null) {
|
|
9542
9572
|
content2.push({
|
|
9543
9573
|
type: "tool-approval-response",
|
|
9544
9574
|
approvalId: toolPart.approval.id,
|
|
@@ -9558,7 +9588,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9558
9588
|
toolName: getToolName(toolPart),
|
|
9559
9589
|
output: {
|
|
9560
9590
|
type: "error-text",
|
|
9561
|
-
value: (
|
|
9591
|
+
value: (_h = (_g = toolPart.approval) == null ? void 0 : _g.reason) != null ? _h : "Tool call execution denied."
|
|
9562
9592
|
},
|
|
9563
9593
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
9564
9594
|
});
|
|
@@ -9575,7 +9605,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9575
9605
|
toolCallId: toolPart.toolCallId,
|
|
9576
9606
|
input: toolPart.input,
|
|
9577
9607
|
output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
|
|
9578
|
-
tool: (
|
|
9608
|
+
tool: (_i = options == null ? void 0 : options.tools) == null ? void 0 : _i[toolName],
|
|
9579
9609
|
errorMode: toolPart.state === "output-error" ? "text" : "none"
|
|
9580
9610
|
}),
|
|
9581
9611
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
@@ -11418,7 +11448,8 @@ async function generateObject(options) {
|
|
|
11418
11448
|
const promptMessages = await convertToLanguageModelPrompt({
|
|
11419
11449
|
prompt: standardizedPrompt,
|
|
11420
11450
|
supportedUrls: await model.supportedUrls,
|
|
11421
|
-
download: download2
|
|
11451
|
+
download: download2,
|
|
11452
|
+
abortSignal
|
|
11422
11453
|
});
|
|
11423
11454
|
const generateResult = await retry(
|
|
11424
11455
|
() => recordSpan({
|
|
@@ -11910,7 +11941,8 @@ var DefaultStreamObjectResult = class {
|
|
|
11910
11941
|
prompt: await convertToLanguageModelPrompt({
|
|
11911
11942
|
prompt: standardizedPrompt,
|
|
11912
11943
|
supportedUrls: await model.supportedUrls,
|
|
11913
|
-
download: download2
|
|
11944
|
+
download: download2,
|
|
11945
|
+
abortSignal
|
|
11914
11946
|
}),
|
|
11915
11947
|
providerOptions,
|
|
11916
11948
|
abortSignal,
|
|
@@ -12472,11 +12504,13 @@ function pruneMessages({
|
|
|
12472
12504
|
}
|
|
12473
12505
|
}
|
|
12474
12506
|
}
|
|
12507
|
+
const approvalIdToToolCallId = /* @__PURE__ */ new Map();
|
|
12475
12508
|
const approvalIdToToolName = /* @__PURE__ */ new Map();
|
|
12476
12509
|
for (const message of messages) {
|
|
12477
12510
|
if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
|
|
12478
12511
|
for (const part of message.content) {
|
|
12479
12512
|
if (part.type === "tool-approval-request") {
|
|
12513
|
+
approvalIdToToolCallId.set(part.approvalId, part.toolCallId);
|
|
12480
12514
|
const toolName = toolCallIdToToolName.get(part.toolCallId);
|
|
12481
12515
|
if (toolName != null) {
|
|
12482
12516
|
approvalIdToToolName.set(part.approvalId, toolName);
|
|
@@ -12485,6 +12519,12 @@ function pruneMessages({
|
|
|
12485
12519
|
}
|
|
12486
12520
|
}
|
|
12487
12521
|
}
|
|
12522
|
+
for (const approvalId of keptApprovalIds) {
|
|
12523
|
+
const toolCallId = approvalIdToToolCallId.get(approvalId);
|
|
12524
|
+
if (toolCallId != null) {
|
|
12525
|
+
keptToolCallIds.add(toolCallId);
|
|
12526
|
+
}
|
|
12527
|
+
}
|
|
12488
12528
|
messages = messages.map((message, messageIndex) => {
|
|
12489
12529
|
if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
|
|
12490
12530
|
return message;
|
|
@@ -13221,7 +13261,11 @@ function simulateStreamingMiddleware() {
|
|
|
13221
13261
|
switch (part.type) {
|
|
13222
13262
|
case "text": {
|
|
13223
13263
|
if (part.text.length > 0) {
|
|
13224
|
-
controller.enqueue({
|
|
13264
|
+
controller.enqueue({
|
|
13265
|
+
type: "text-start",
|
|
13266
|
+
id: String(id),
|
|
13267
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
13268
|
+
});
|
|
13225
13269
|
controller.enqueue({
|
|
13226
13270
|
type: "text-delta",
|
|
13227
13271
|
id: String(id),
|