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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.101
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5230482: fix(ai): Don't create duplicate tool parts when models call non-existent tools
|
|
8
|
+
|
|
9
|
+
## 6.0.100
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b7fba77: feat(ai): add event notifiers to core functions
|
|
14
|
+
|
|
3
15
|
## 6.0.99
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -623,6 +623,21 @@ var RetryError = class extends import_provider20.AISDKError {
|
|
|
623
623
|
};
|
|
624
624
|
_a19 = symbol19;
|
|
625
625
|
|
|
626
|
+
// src/util/as-array.ts
|
|
627
|
+
function asArray(value) {
|
|
628
|
+
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// src/util/notify.ts
|
|
632
|
+
async function notify(options) {
|
|
633
|
+
for (const callback of asArray(options.callbacks)) {
|
|
634
|
+
try {
|
|
635
|
+
await callback(options.event);
|
|
636
|
+
} catch (_ignored) {
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
626
641
|
// src/logger/log-warnings.ts
|
|
627
642
|
function formatWarning({
|
|
628
643
|
warning,
|
|
@@ -1211,7 +1226,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
1211
1226
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1212
1227
|
|
|
1213
1228
|
// src/version.ts
|
|
1214
|
-
var VERSION = true ? "6.0.
|
|
1229
|
+
var VERSION = true ? "6.0.101" : "0.0.0-test";
|
|
1215
1230
|
|
|
1216
1231
|
// src/util/download/download.ts
|
|
1217
1232
|
var download = async ({
|
|
@@ -1353,11 +1368,6 @@ function convertDataContentToUint8Array(content) {
|
|
|
1353
1368
|
throw new InvalidDataContentError({ content });
|
|
1354
1369
|
}
|
|
1355
1370
|
|
|
1356
|
-
// src/util/as-array.ts
|
|
1357
|
-
function asArray(value) {
|
|
1358
|
-
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
1371
|
// src/prompt/convert-to-language-model-prompt.ts
|
|
1362
1372
|
async function convertToLanguageModelPrompt({
|
|
1363
1373
|
prompt,
|
|
@@ -2808,10 +2818,7 @@ async function executeToolCall({
|
|
|
2808
2818
|
tracer,
|
|
2809
2819
|
fn: async (span) => {
|
|
2810
2820
|
let output;
|
|
2811
|
-
|
|
2812
|
-
await (onToolCallStart == null ? void 0 : onToolCallStart(baseCallbackEvent));
|
|
2813
|
-
} catch (_ignored) {
|
|
2814
|
-
}
|
|
2821
|
+
await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
|
|
2815
2822
|
const startTime = now();
|
|
2816
2823
|
try {
|
|
2817
2824
|
const stream = (0, import_provider_utils10.executeTool)({
|
|
@@ -2838,15 +2845,15 @@ async function executeToolCall({
|
|
|
2838
2845
|
}
|
|
2839
2846
|
} catch (error) {
|
|
2840
2847
|
const durationMs2 = now() - startTime;
|
|
2841
|
-
|
|
2842
|
-
|
|
2848
|
+
await notify({
|
|
2849
|
+
event: {
|
|
2843
2850
|
...baseCallbackEvent,
|
|
2844
2851
|
success: false,
|
|
2845
2852
|
error,
|
|
2846
2853
|
durationMs: durationMs2
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2849
|
-
}
|
|
2854
|
+
},
|
|
2855
|
+
callbacks: onToolCallFinish
|
|
2856
|
+
});
|
|
2850
2857
|
recordErrorOnSpan(span, error);
|
|
2851
2858
|
return {
|
|
2852
2859
|
type: "tool-error",
|
|
@@ -2859,15 +2866,15 @@ async function executeToolCall({
|
|
|
2859
2866
|
};
|
|
2860
2867
|
}
|
|
2861
2868
|
const durationMs = now() - startTime;
|
|
2862
|
-
|
|
2863
|
-
|
|
2869
|
+
await notify({
|
|
2870
|
+
event: {
|
|
2864
2871
|
...baseCallbackEvent,
|
|
2865
2872
|
success: true,
|
|
2866
2873
|
output,
|
|
2867
2874
|
durationMs
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
}
|
|
2875
|
+
},
|
|
2876
|
+
callbacks: onToolCallFinish
|
|
2877
|
+
});
|
|
2871
2878
|
try {
|
|
2872
2879
|
span.setAttributes(
|
|
2873
2880
|
await selectTelemetryAttributes({
|
|
@@ -4073,8 +4080,8 @@ async function generateText({
|
|
|
4073
4080
|
prompt,
|
|
4074
4081
|
messages
|
|
4075
4082
|
});
|
|
4076
|
-
|
|
4077
|
-
|
|
4083
|
+
await notify({
|
|
4084
|
+
event: {
|
|
4078
4085
|
model: modelInfo,
|
|
4079
4086
|
system,
|
|
4080
4087
|
prompt,
|
|
@@ -4101,9 +4108,9 @@ async function generateText({
|
|
|
4101
4108
|
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
4102
4109
|
metadata: telemetry == null ? void 0 : telemetry.metadata,
|
|
4103
4110
|
experimental_context
|
|
4104
|
-
}
|
|
4105
|
-
|
|
4106
|
-
}
|
|
4111
|
+
},
|
|
4112
|
+
callbacks: onStart
|
|
4113
|
+
});
|
|
4107
4114
|
const tracer = getTracer(telemetry);
|
|
4108
4115
|
try {
|
|
4109
4116
|
return await recordSpan({
|
|
@@ -4253,8 +4260,8 @@ async function generateText({
|
|
|
4253
4260
|
providerOptions,
|
|
4254
4261
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
4255
4262
|
);
|
|
4256
|
-
|
|
4257
|
-
|
|
4263
|
+
await notify({
|
|
4264
|
+
event: {
|
|
4258
4265
|
stepNumber: steps.length,
|
|
4259
4266
|
model: stepModelInfo,
|
|
4260
4267
|
system: stepSystem,
|
|
@@ -4273,9 +4280,9 @@ async function generateText({
|
|
|
4273
4280
|
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
4274
4281
|
metadata: telemetry == null ? void 0 : telemetry.metadata,
|
|
4275
4282
|
experimental_context
|
|
4276
|
-
}
|
|
4277
|
-
|
|
4278
|
-
}
|
|
4283
|
+
},
|
|
4284
|
+
callbacks: onStepStart
|
|
4285
|
+
});
|
|
4279
4286
|
currentModelResponse = await retry(
|
|
4280
4287
|
() => {
|
|
4281
4288
|
var _a22;
|
|
@@ -4520,7 +4527,7 @@ async function generateText({
|
|
|
4520
4527
|
model: stepModelInfo.modelId
|
|
4521
4528
|
});
|
|
4522
4529
|
steps.push(currentStepResult);
|
|
4523
|
-
await (
|
|
4530
|
+
await notify({ event: currentStepResult, callbacks: onStepFinish });
|
|
4524
4531
|
} finally {
|
|
4525
4532
|
if (stepTimeoutId != null) {
|
|
4526
4533
|
clearTimeout(stepTimeoutId);
|
|
@@ -4572,34 +4579,37 @@ async function generateText({
|
|
|
4572
4579
|
cachedInputTokens: void 0
|
|
4573
4580
|
}
|
|
4574
4581
|
);
|
|
4575
|
-
await (
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4582
|
+
await notify({
|
|
4583
|
+
event: {
|
|
4584
|
+
stepNumber: lastStep.stepNumber,
|
|
4585
|
+
model: lastStep.model,
|
|
4586
|
+
functionId: lastStep.functionId,
|
|
4587
|
+
metadata: lastStep.metadata,
|
|
4588
|
+
experimental_context: lastStep.experimental_context,
|
|
4589
|
+
finishReason: lastStep.finishReason,
|
|
4590
|
+
rawFinishReason: lastStep.rawFinishReason,
|
|
4591
|
+
usage: lastStep.usage,
|
|
4592
|
+
content: lastStep.content,
|
|
4593
|
+
text: lastStep.text,
|
|
4594
|
+
reasoningText: lastStep.reasoningText,
|
|
4595
|
+
reasoning: lastStep.reasoning,
|
|
4596
|
+
files: lastStep.files,
|
|
4597
|
+
sources: lastStep.sources,
|
|
4598
|
+
toolCalls: lastStep.toolCalls,
|
|
4599
|
+
staticToolCalls: lastStep.staticToolCalls,
|
|
4600
|
+
dynamicToolCalls: lastStep.dynamicToolCalls,
|
|
4601
|
+
toolResults: lastStep.toolResults,
|
|
4602
|
+
staticToolResults: lastStep.staticToolResults,
|
|
4603
|
+
dynamicToolResults: lastStep.dynamicToolResults,
|
|
4604
|
+
request: lastStep.request,
|
|
4605
|
+
response: lastStep.response,
|
|
4606
|
+
warnings: lastStep.warnings,
|
|
4607
|
+
providerMetadata: lastStep.providerMetadata,
|
|
4608
|
+
steps,
|
|
4609
|
+
totalUsage
|
|
4610
|
+
},
|
|
4611
|
+
callbacks: onFinish
|
|
4612
|
+
});
|
|
4603
4613
|
let resolvedOutput;
|
|
4604
4614
|
if (lastStep.finishReason === "stop") {
|
|
4605
4615
|
const outputSpecification = output != null ? output : text();
|
|
@@ -5552,7 +5562,9 @@ function processUIMessageStream({
|
|
|
5552
5562
|
break;
|
|
5553
5563
|
}
|
|
5554
5564
|
case "tool-input-error": {
|
|
5555
|
-
|
|
5565
|
+
const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
|
|
5566
|
+
const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
|
|
5567
|
+
if (isDynamic) {
|
|
5556
5568
|
updateDynamicToolPart({
|
|
5557
5569
|
toolCallId: chunk.toolCallId,
|
|
5558
5570
|
toolName: chunk.toolName,
|
|
@@ -6634,7 +6646,7 @@ var DefaultStreamTextResult = class {
|
|
|
6634
6646
|
},
|
|
6635
6647
|
providerMetadata: part.providerMetadata
|
|
6636
6648
|
});
|
|
6637
|
-
await (
|
|
6649
|
+
await notify({ event: currentStepResult, callbacks: onStepFinish });
|
|
6638
6650
|
logWarnings({
|
|
6639
6651
|
warnings: recordedWarnings,
|
|
6640
6652
|
provider: modelInfo.provider,
|
|
@@ -6669,34 +6681,37 @@ var DefaultStreamTextResult = class {
|
|
|
6669
6681
|
self._totalUsage.resolve(totalUsage);
|
|
6670
6682
|
self._steps.resolve(recordedSteps);
|
|
6671
6683
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
6672
|
-
await (
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6684
|
+
await notify({
|
|
6685
|
+
event: {
|
|
6686
|
+
stepNumber: finalStep.stepNumber,
|
|
6687
|
+
model: finalStep.model,
|
|
6688
|
+
functionId: finalStep.functionId,
|
|
6689
|
+
metadata: finalStep.metadata,
|
|
6690
|
+
experimental_context: finalStep.experimental_context,
|
|
6691
|
+
finishReason: finalStep.finishReason,
|
|
6692
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
6693
|
+
totalUsage,
|
|
6694
|
+
usage: finalStep.usage,
|
|
6695
|
+
content: finalStep.content,
|
|
6696
|
+
text: finalStep.text,
|
|
6697
|
+
reasoningText: finalStep.reasoningText,
|
|
6698
|
+
reasoning: finalStep.reasoning,
|
|
6699
|
+
files: finalStep.files,
|
|
6700
|
+
sources: finalStep.sources,
|
|
6701
|
+
toolCalls: finalStep.toolCalls,
|
|
6702
|
+
staticToolCalls: finalStep.staticToolCalls,
|
|
6703
|
+
dynamicToolCalls: finalStep.dynamicToolCalls,
|
|
6704
|
+
toolResults: finalStep.toolResults,
|
|
6705
|
+
staticToolResults: finalStep.staticToolResults,
|
|
6706
|
+
dynamicToolResults: finalStep.dynamicToolResults,
|
|
6707
|
+
request: finalStep.request,
|
|
6708
|
+
response: finalStep.response,
|
|
6709
|
+
warnings: finalStep.warnings,
|
|
6710
|
+
providerMetadata: finalStep.providerMetadata,
|
|
6711
|
+
steps: recordedSteps
|
|
6712
|
+
},
|
|
6713
|
+
callbacks: onFinish
|
|
6714
|
+
});
|
|
6700
6715
|
rootSpan.setAttributes(
|
|
6701
6716
|
await selectTelemetryAttributes({
|
|
6702
6717
|
telemetry,
|
|
@@ -6824,8 +6839,8 @@ var DefaultStreamTextResult = class {
|
|
|
6824
6839
|
prompt,
|
|
6825
6840
|
messages
|
|
6826
6841
|
});
|
|
6827
|
-
|
|
6828
|
-
|
|
6842
|
+
await notify({
|
|
6843
|
+
event: {
|
|
6829
6844
|
model: modelInfo,
|
|
6830
6845
|
system,
|
|
6831
6846
|
prompt,
|
|
@@ -6851,9 +6866,9 @@ var DefaultStreamTextResult = class {
|
|
|
6851
6866
|
include,
|
|
6852
6867
|
...callbackTelemetryProps,
|
|
6853
6868
|
experimental_context
|
|
6854
|
-
}
|
|
6855
|
-
|
|
6856
|
-
}
|
|
6869
|
+
},
|
|
6870
|
+
callbacks: onStart
|
|
6871
|
+
});
|
|
6857
6872
|
const initialMessages = initialPrompt.messages;
|
|
6858
6873
|
const initialResponseMessages = [];
|
|
6859
6874
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
@@ -7034,8 +7049,8 @@ var DefaultStreamTextResult = class {
|
|
|
7034
7049
|
providerOptions,
|
|
7035
7050
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
7036
7051
|
);
|
|
7037
|
-
|
|
7038
|
-
|
|
7052
|
+
await notify({
|
|
7053
|
+
event: {
|
|
7039
7054
|
stepNumber: recordedSteps.length,
|
|
7040
7055
|
model: stepModelInfo,
|
|
7041
7056
|
system: stepSystem,
|
|
@@ -7053,9 +7068,9 @@ var DefaultStreamTextResult = class {
|
|
|
7053
7068
|
include,
|
|
7054
7069
|
...callbackTelemetryProps,
|
|
7055
7070
|
experimental_context
|
|
7056
|
-
}
|
|
7057
|
-
|
|
7058
|
-
}
|
|
7071
|
+
},
|
|
7072
|
+
callbacks: onStepStart
|
|
7073
|
+
});
|
|
7059
7074
|
const {
|
|
7060
7075
|
result: { stream: stream2, response, request },
|
|
7061
7076
|
doStreamSpan,
|