ai 6.0.98 → 6.0.100
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.js +111 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -98
- 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 +2 -2
- 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/util/notify.ts +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.100
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b7fba77: feat(ai): add event notifiers to core functions
|
|
8
|
+
|
|
9
|
+
## 6.0.99
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [e8172b6]
|
|
14
|
+
- @ai-sdk/gateway@3.0.55
|
|
15
|
+
|
|
3
16
|
## 6.0.98
|
|
4
17
|
|
|
5
18
|
### 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.100" : "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();
|
|
@@ -6634,7 +6644,7 @@ var DefaultStreamTextResult = class {
|
|
|
6634
6644
|
},
|
|
6635
6645
|
providerMetadata: part.providerMetadata
|
|
6636
6646
|
});
|
|
6637
|
-
await (
|
|
6647
|
+
await notify({ event: currentStepResult, callbacks: onStepFinish });
|
|
6638
6648
|
logWarnings({
|
|
6639
6649
|
warnings: recordedWarnings,
|
|
6640
6650
|
provider: modelInfo.provider,
|
|
@@ -6669,34 +6679,37 @@ var DefaultStreamTextResult = class {
|
|
|
6669
6679
|
self._totalUsage.resolve(totalUsage);
|
|
6670
6680
|
self._steps.resolve(recordedSteps);
|
|
6671
6681
|
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
|
-
|
|
6682
|
+
await notify({
|
|
6683
|
+
event: {
|
|
6684
|
+
stepNumber: finalStep.stepNumber,
|
|
6685
|
+
model: finalStep.model,
|
|
6686
|
+
functionId: finalStep.functionId,
|
|
6687
|
+
metadata: finalStep.metadata,
|
|
6688
|
+
experimental_context: finalStep.experimental_context,
|
|
6689
|
+
finishReason: finalStep.finishReason,
|
|
6690
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
6691
|
+
totalUsage,
|
|
6692
|
+
usage: finalStep.usage,
|
|
6693
|
+
content: finalStep.content,
|
|
6694
|
+
text: finalStep.text,
|
|
6695
|
+
reasoningText: finalStep.reasoningText,
|
|
6696
|
+
reasoning: finalStep.reasoning,
|
|
6697
|
+
files: finalStep.files,
|
|
6698
|
+
sources: finalStep.sources,
|
|
6699
|
+
toolCalls: finalStep.toolCalls,
|
|
6700
|
+
staticToolCalls: finalStep.staticToolCalls,
|
|
6701
|
+
dynamicToolCalls: finalStep.dynamicToolCalls,
|
|
6702
|
+
toolResults: finalStep.toolResults,
|
|
6703
|
+
staticToolResults: finalStep.staticToolResults,
|
|
6704
|
+
dynamicToolResults: finalStep.dynamicToolResults,
|
|
6705
|
+
request: finalStep.request,
|
|
6706
|
+
response: finalStep.response,
|
|
6707
|
+
warnings: finalStep.warnings,
|
|
6708
|
+
providerMetadata: finalStep.providerMetadata,
|
|
6709
|
+
steps: recordedSteps
|
|
6710
|
+
},
|
|
6711
|
+
callbacks: onFinish
|
|
6712
|
+
});
|
|
6700
6713
|
rootSpan.setAttributes(
|
|
6701
6714
|
await selectTelemetryAttributes({
|
|
6702
6715
|
telemetry,
|
|
@@ -6824,8 +6837,8 @@ var DefaultStreamTextResult = class {
|
|
|
6824
6837
|
prompt,
|
|
6825
6838
|
messages
|
|
6826
6839
|
});
|
|
6827
|
-
|
|
6828
|
-
|
|
6840
|
+
await notify({
|
|
6841
|
+
event: {
|
|
6829
6842
|
model: modelInfo,
|
|
6830
6843
|
system,
|
|
6831
6844
|
prompt,
|
|
@@ -6851,9 +6864,9 @@ var DefaultStreamTextResult = class {
|
|
|
6851
6864
|
include,
|
|
6852
6865
|
...callbackTelemetryProps,
|
|
6853
6866
|
experimental_context
|
|
6854
|
-
}
|
|
6855
|
-
|
|
6856
|
-
}
|
|
6867
|
+
},
|
|
6868
|
+
callbacks: onStart
|
|
6869
|
+
});
|
|
6857
6870
|
const initialMessages = initialPrompt.messages;
|
|
6858
6871
|
const initialResponseMessages = [];
|
|
6859
6872
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
@@ -7034,8 +7047,8 @@ var DefaultStreamTextResult = class {
|
|
|
7034
7047
|
providerOptions,
|
|
7035
7048
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
7036
7049
|
);
|
|
7037
|
-
|
|
7038
|
-
|
|
7050
|
+
await notify({
|
|
7051
|
+
event: {
|
|
7039
7052
|
stepNumber: recordedSteps.length,
|
|
7040
7053
|
model: stepModelInfo,
|
|
7041
7054
|
system: stepSystem,
|
|
@@ -7053,9 +7066,9 @@ var DefaultStreamTextResult = class {
|
|
|
7053
7066
|
include,
|
|
7054
7067
|
...callbackTelemetryProps,
|
|
7055
7068
|
experimental_context
|
|
7056
|
-
}
|
|
7057
|
-
|
|
7058
|
-
}
|
|
7069
|
+
},
|
|
7070
|
+
callbacks: onStepStart
|
|
7071
|
+
});
|
|
7059
7072
|
const {
|
|
7060
7073
|
result: { stream: stream2, response, request },
|
|
7061
7074
|
doStreamSpan,
|