ai 6.0.99 → 6.0.101
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 +12 -0
- package/dist/index.js +114 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -99
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-agents/01-overview.mdx +5 -5
- package/docs/03-agents/02-building-agents.mdx +3 -3
- package/docs/03-agents/index.mdx +2 -2
- package/docs/03-ai-sdk-core/65-event-listeners.mdx +915 -0
- package/package.json +1 -1
- package/src/generate-text/execute-tool-call.ts +14 -19
- package/src/generate-text/generate-text.ts +43 -40
- package/src/generate-text/stream-text.ts +43 -40
- package/src/ui/process-ui-message-stream.ts +12 -1
- package/src/util/notify.ts +18 -0
package/dist/index.mjs
CHANGED
|
@@ -507,6 +507,21 @@ var RetryError = class extends AISDKError20 {
|
|
|
507
507
|
};
|
|
508
508
|
_a19 = symbol19;
|
|
509
509
|
|
|
510
|
+
// src/util/as-array.ts
|
|
511
|
+
function asArray(value) {
|
|
512
|
+
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/util/notify.ts
|
|
516
|
+
async function notify(options) {
|
|
517
|
+
for (const callback of asArray(options.callbacks)) {
|
|
518
|
+
try {
|
|
519
|
+
await callback(options.event);
|
|
520
|
+
} catch (_ignored) {
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
510
525
|
// src/logger/log-warnings.ts
|
|
511
526
|
function formatWarning({
|
|
512
527
|
warning,
|
|
@@ -1104,7 +1119,7 @@ import {
|
|
|
1104
1119
|
} from "@ai-sdk/provider-utils";
|
|
1105
1120
|
|
|
1106
1121
|
// src/version.ts
|
|
1107
|
-
var VERSION = true ? "6.0.
|
|
1122
|
+
var VERSION = true ? "6.0.101" : "0.0.0-test";
|
|
1108
1123
|
|
|
1109
1124
|
// src/util/download/download.ts
|
|
1110
1125
|
var download = async ({
|
|
@@ -1249,11 +1264,6 @@ function convertDataContentToUint8Array(content) {
|
|
|
1249
1264
|
throw new InvalidDataContentError({ content });
|
|
1250
1265
|
}
|
|
1251
1266
|
|
|
1252
|
-
// src/util/as-array.ts
|
|
1253
|
-
function asArray(value) {
|
|
1254
|
-
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
1267
|
// src/prompt/convert-to-language-model-prompt.ts
|
|
1258
1268
|
async function convertToLanguageModelPrompt({
|
|
1259
1269
|
prompt,
|
|
@@ -2709,10 +2719,7 @@ async function executeToolCall({
|
|
|
2709
2719
|
tracer,
|
|
2710
2720
|
fn: async (span) => {
|
|
2711
2721
|
let output;
|
|
2712
|
-
|
|
2713
|
-
await (onToolCallStart == null ? void 0 : onToolCallStart(baseCallbackEvent));
|
|
2714
|
-
} catch (_ignored) {
|
|
2715
|
-
}
|
|
2722
|
+
await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
|
|
2716
2723
|
const startTime = now();
|
|
2717
2724
|
try {
|
|
2718
2725
|
const stream = executeTool({
|
|
@@ -2739,15 +2746,15 @@ async function executeToolCall({
|
|
|
2739
2746
|
}
|
|
2740
2747
|
} catch (error) {
|
|
2741
2748
|
const durationMs2 = now() - startTime;
|
|
2742
|
-
|
|
2743
|
-
|
|
2749
|
+
await notify({
|
|
2750
|
+
event: {
|
|
2744
2751
|
...baseCallbackEvent,
|
|
2745
2752
|
success: false,
|
|
2746
2753
|
error,
|
|
2747
2754
|
durationMs: durationMs2
|
|
2748
|
-
}
|
|
2749
|
-
|
|
2750
|
-
}
|
|
2755
|
+
},
|
|
2756
|
+
callbacks: onToolCallFinish
|
|
2757
|
+
});
|
|
2751
2758
|
recordErrorOnSpan(span, error);
|
|
2752
2759
|
return {
|
|
2753
2760
|
type: "tool-error",
|
|
@@ -2760,15 +2767,15 @@ async function executeToolCall({
|
|
|
2760
2767
|
};
|
|
2761
2768
|
}
|
|
2762
2769
|
const durationMs = now() - startTime;
|
|
2763
|
-
|
|
2764
|
-
|
|
2770
|
+
await notify({
|
|
2771
|
+
event: {
|
|
2765
2772
|
...baseCallbackEvent,
|
|
2766
2773
|
success: true,
|
|
2767
2774
|
output,
|
|
2768
2775
|
durationMs
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
}
|
|
2776
|
+
},
|
|
2777
|
+
callbacks: onToolCallFinish
|
|
2778
|
+
});
|
|
2772
2779
|
try {
|
|
2773
2780
|
span.setAttributes(
|
|
2774
2781
|
await selectTelemetryAttributes({
|
|
@@ -3988,8 +3995,8 @@ async function generateText({
|
|
|
3988
3995
|
prompt,
|
|
3989
3996
|
messages
|
|
3990
3997
|
});
|
|
3991
|
-
|
|
3992
|
-
|
|
3998
|
+
await notify({
|
|
3999
|
+
event: {
|
|
3993
4000
|
model: modelInfo,
|
|
3994
4001
|
system,
|
|
3995
4002
|
prompt,
|
|
@@ -4016,9 +4023,9 @@ async function generateText({
|
|
|
4016
4023
|
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
4017
4024
|
metadata: telemetry == null ? void 0 : telemetry.metadata,
|
|
4018
4025
|
experimental_context
|
|
4019
|
-
}
|
|
4020
|
-
|
|
4021
|
-
}
|
|
4026
|
+
},
|
|
4027
|
+
callbacks: onStart
|
|
4028
|
+
});
|
|
4022
4029
|
const tracer = getTracer(telemetry);
|
|
4023
4030
|
try {
|
|
4024
4031
|
return await recordSpan({
|
|
@@ -4168,8 +4175,8 @@ async function generateText({
|
|
|
4168
4175
|
providerOptions,
|
|
4169
4176
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
4170
4177
|
);
|
|
4171
|
-
|
|
4172
|
-
|
|
4178
|
+
await notify({
|
|
4179
|
+
event: {
|
|
4173
4180
|
stepNumber: steps.length,
|
|
4174
4181
|
model: stepModelInfo,
|
|
4175
4182
|
system: stepSystem,
|
|
@@ -4188,9 +4195,9 @@ async function generateText({
|
|
|
4188
4195
|
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
4189
4196
|
metadata: telemetry == null ? void 0 : telemetry.metadata,
|
|
4190
4197
|
experimental_context
|
|
4191
|
-
}
|
|
4192
|
-
|
|
4193
|
-
}
|
|
4198
|
+
},
|
|
4199
|
+
callbacks: onStepStart
|
|
4200
|
+
});
|
|
4194
4201
|
currentModelResponse = await retry(
|
|
4195
4202
|
() => {
|
|
4196
4203
|
var _a22;
|
|
@@ -4435,7 +4442,7 @@ async function generateText({
|
|
|
4435
4442
|
model: stepModelInfo.modelId
|
|
4436
4443
|
});
|
|
4437
4444
|
steps.push(currentStepResult);
|
|
4438
|
-
await (
|
|
4445
|
+
await notify({ event: currentStepResult, callbacks: onStepFinish });
|
|
4439
4446
|
} finally {
|
|
4440
4447
|
if (stepTimeoutId != null) {
|
|
4441
4448
|
clearTimeout(stepTimeoutId);
|
|
@@ -4487,34 +4494,37 @@ async function generateText({
|
|
|
4487
4494
|
cachedInputTokens: void 0
|
|
4488
4495
|
}
|
|
4489
4496
|
);
|
|
4490
|
-
await (
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4497
|
+
await notify({
|
|
4498
|
+
event: {
|
|
4499
|
+
stepNumber: lastStep.stepNumber,
|
|
4500
|
+
model: lastStep.model,
|
|
4501
|
+
functionId: lastStep.functionId,
|
|
4502
|
+
metadata: lastStep.metadata,
|
|
4503
|
+
experimental_context: lastStep.experimental_context,
|
|
4504
|
+
finishReason: lastStep.finishReason,
|
|
4505
|
+
rawFinishReason: lastStep.rawFinishReason,
|
|
4506
|
+
usage: lastStep.usage,
|
|
4507
|
+
content: lastStep.content,
|
|
4508
|
+
text: lastStep.text,
|
|
4509
|
+
reasoningText: lastStep.reasoningText,
|
|
4510
|
+
reasoning: lastStep.reasoning,
|
|
4511
|
+
files: lastStep.files,
|
|
4512
|
+
sources: lastStep.sources,
|
|
4513
|
+
toolCalls: lastStep.toolCalls,
|
|
4514
|
+
staticToolCalls: lastStep.staticToolCalls,
|
|
4515
|
+
dynamicToolCalls: lastStep.dynamicToolCalls,
|
|
4516
|
+
toolResults: lastStep.toolResults,
|
|
4517
|
+
staticToolResults: lastStep.staticToolResults,
|
|
4518
|
+
dynamicToolResults: lastStep.dynamicToolResults,
|
|
4519
|
+
request: lastStep.request,
|
|
4520
|
+
response: lastStep.response,
|
|
4521
|
+
warnings: lastStep.warnings,
|
|
4522
|
+
providerMetadata: lastStep.providerMetadata,
|
|
4523
|
+
steps,
|
|
4524
|
+
totalUsage
|
|
4525
|
+
},
|
|
4526
|
+
callbacks: onFinish
|
|
4527
|
+
});
|
|
4518
4528
|
let resolvedOutput;
|
|
4519
4529
|
if (lastStep.finishReason === "stop") {
|
|
4520
4530
|
const outputSpecification = output != null ? output : text();
|
|
@@ -5474,7 +5484,9 @@ function processUIMessageStream({
|
|
|
5474
5484
|
break;
|
|
5475
5485
|
}
|
|
5476
5486
|
case "tool-input-error": {
|
|
5477
|
-
|
|
5487
|
+
const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
|
|
5488
|
+
const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
|
|
5489
|
+
if (isDynamic) {
|
|
5478
5490
|
updateDynamicToolPart({
|
|
5479
5491
|
toolCallId: chunk.toolCallId,
|
|
5480
5492
|
toolName: chunk.toolName,
|
|
@@ -6558,7 +6570,7 @@ var DefaultStreamTextResult = class {
|
|
|
6558
6570
|
},
|
|
6559
6571
|
providerMetadata: part.providerMetadata
|
|
6560
6572
|
});
|
|
6561
|
-
await (
|
|
6573
|
+
await notify({ event: currentStepResult, callbacks: onStepFinish });
|
|
6562
6574
|
logWarnings({
|
|
6563
6575
|
warnings: recordedWarnings,
|
|
6564
6576
|
provider: modelInfo.provider,
|
|
@@ -6593,34 +6605,37 @@ var DefaultStreamTextResult = class {
|
|
|
6593
6605
|
self._totalUsage.resolve(totalUsage);
|
|
6594
6606
|
self._steps.resolve(recordedSteps);
|
|
6595
6607
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
6596
|
-
await (
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6608
|
+
await notify({
|
|
6609
|
+
event: {
|
|
6610
|
+
stepNumber: finalStep.stepNumber,
|
|
6611
|
+
model: finalStep.model,
|
|
6612
|
+
functionId: finalStep.functionId,
|
|
6613
|
+
metadata: finalStep.metadata,
|
|
6614
|
+
experimental_context: finalStep.experimental_context,
|
|
6615
|
+
finishReason: finalStep.finishReason,
|
|
6616
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
6617
|
+
totalUsage,
|
|
6618
|
+
usage: finalStep.usage,
|
|
6619
|
+
content: finalStep.content,
|
|
6620
|
+
text: finalStep.text,
|
|
6621
|
+
reasoningText: finalStep.reasoningText,
|
|
6622
|
+
reasoning: finalStep.reasoning,
|
|
6623
|
+
files: finalStep.files,
|
|
6624
|
+
sources: finalStep.sources,
|
|
6625
|
+
toolCalls: finalStep.toolCalls,
|
|
6626
|
+
staticToolCalls: finalStep.staticToolCalls,
|
|
6627
|
+
dynamicToolCalls: finalStep.dynamicToolCalls,
|
|
6628
|
+
toolResults: finalStep.toolResults,
|
|
6629
|
+
staticToolResults: finalStep.staticToolResults,
|
|
6630
|
+
dynamicToolResults: finalStep.dynamicToolResults,
|
|
6631
|
+
request: finalStep.request,
|
|
6632
|
+
response: finalStep.response,
|
|
6633
|
+
warnings: finalStep.warnings,
|
|
6634
|
+
providerMetadata: finalStep.providerMetadata,
|
|
6635
|
+
steps: recordedSteps
|
|
6636
|
+
},
|
|
6637
|
+
callbacks: onFinish
|
|
6638
|
+
});
|
|
6624
6639
|
rootSpan.setAttributes(
|
|
6625
6640
|
await selectTelemetryAttributes({
|
|
6626
6641
|
telemetry,
|
|
@@ -6748,8 +6763,8 @@ var DefaultStreamTextResult = class {
|
|
|
6748
6763
|
prompt,
|
|
6749
6764
|
messages
|
|
6750
6765
|
});
|
|
6751
|
-
|
|
6752
|
-
|
|
6766
|
+
await notify({
|
|
6767
|
+
event: {
|
|
6753
6768
|
model: modelInfo,
|
|
6754
6769
|
system,
|
|
6755
6770
|
prompt,
|
|
@@ -6775,9 +6790,9 @@ var DefaultStreamTextResult = class {
|
|
|
6775
6790
|
include,
|
|
6776
6791
|
...callbackTelemetryProps,
|
|
6777
6792
|
experimental_context
|
|
6778
|
-
}
|
|
6779
|
-
|
|
6780
|
-
}
|
|
6793
|
+
},
|
|
6794
|
+
callbacks: onStart
|
|
6795
|
+
});
|
|
6781
6796
|
const initialMessages = initialPrompt.messages;
|
|
6782
6797
|
const initialResponseMessages = [];
|
|
6783
6798
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
@@ -6958,8 +6973,8 @@ var DefaultStreamTextResult = class {
|
|
|
6958
6973
|
providerOptions,
|
|
6959
6974
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
6960
6975
|
);
|
|
6961
|
-
|
|
6962
|
-
|
|
6976
|
+
await notify({
|
|
6977
|
+
event: {
|
|
6963
6978
|
stepNumber: recordedSteps.length,
|
|
6964
6979
|
model: stepModelInfo,
|
|
6965
6980
|
system: stepSystem,
|
|
@@ -6977,9 +6992,9 @@ var DefaultStreamTextResult = class {
|
|
|
6977
6992
|
include,
|
|
6978
6993
|
...callbackTelemetryProps,
|
|
6979
6994
|
experimental_context
|
|
6980
|
-
}
|
|
6981
|
-
|
|
6982
|
-
}
|
|
6995
|
+
},
|
|
6996
|
+
callbacks: onStepStart
|
|
6997
|
+
});
|
|
6983
6998
|
const {
|
|
6984
6999
|
result: { stream: stream2, response, request },
|
|
6985
7000
|
doStreamSpan,
|