ai 7.0.0-beta.78 → 7.0.0-beta.79
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 +6 -0
- package/dist/index.d.mts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.js +26 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -41
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +3 -3
- package/src/agent/tool-loop-agent.ts +13 -31
- package/src/generate-text/generate-text.ts +10 -12
- package/src/generate-text/stream-text.ts +0 -5
- package/src/telemetry/get-global-telemetry-integration.ts +7 -11
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -2
- package/src/util/merge-listeners.ts +22 -0
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -958,6 +958,11 @@ type DownloadFunction = (options: Array<{
|
|
|
958
958
|
mediaType: string | undefined;
|
|
959
959
|
} | null>>;
|
|
960
960
|
|
|
961
|
+
/**
|
|
962
|
+
* A callback function that can be used to notify listeners.
|
|
963
|
+
*/
|
|
964
|
+
type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
965
|
+
|
|
961
966
|
/**
|
|
962
967
|
* Function that you can use to provide different settings for a step.
|
|
963
968
|
*
|
|
@@ -1119,7 +1124,7 @@ type GenerateTextIncludeSettings = {
|
|
|
1119
1124
|
*
|
|
1120
1125
|
* @param event - The event object containing generation configuration.
|
|
1121
1126
|
*/
|
|
1122
|
-
type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> =
|
|
1127
|
+
type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> = Listener<OnStartEvent<TOOLS, CONTEXT, OUTPUT, GenerateTextIncludeSettings>>;
|
|
1123
1128
|
/**
|
|
1124
1129
|
* Callback that is set using the `experimental_onStepStart` option.
|
|
1125
1130
|
*
|
|
@@ -1129,7 +1134,7 @@ type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extend
|
|
|
1129
1134
|
*
|
|
1130
1135
|
* @param event - The event object containing step configuration.
|
|
1131
1136
|
*/
|
|
1132
|
-
type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> =
|
|
1137
|
+
type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> = Listener<OnStepStartEvent<TOOLS, CONTEXT, OUTPUT, GenerateTextIncludeSettings>>;
|
|
1133
1138
|
/**
|
|
1134
1139
|
* Callback that is set using the `experimental_onToolCallStart` option.
|
|
1135
1140
|
*
|
|
@@ -1138,7 +1143,7 @@ type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT ex
|
|
|
1138
1143
|
*
|
|
1139
1144
|
* @param event - The event object containing tool call information.
|
|
1140
1145
|
*/
|
|
1141
|
-
type GenerateTextOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> =
|
|
1146
|
+
type GenerateTextOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> = Listener<OnToolCallStartEvent<TOOLS>>;
|
|
1142
1147
|
/**
|
|
1143
1148
|
* Callback that is set using the `experimental_onToolCallFinish` option.
|
|
1144
1149
|
*
|
|
@@ -1151,7 +1156,7 @@ type GenerateTextOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> = (eve
|
|
|
1151
1156
|
*
|
|
1152
1157
|
* @param event - The event object containing tool call result information.
|
|
1153
1158
|
*/
|
|
1154
|
-
type GenerateTextOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> =
|
|
1159
|
+
type GenerateTextOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> = Listener<OnToolCallFinishEvent<TOOLS>>;
|
|
1155
1160
|
/**
|
|
1156
1161
|
* Callback that is set using the `onStepFinish` option.
|
|
1157
1162
|
*
|
|
@@ -1160,7 +1165,7 @@ type GenerateTextOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> = (ev
|
|
|
1160
1165
|
*
|
|
1161
1166
|
* @param stepResult - The result of the step.
|
|
1162
1167
|
*/
|
|
1163
|
-
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> =
|
|
1168
|
+
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> = Listener<OnStepFinishEvent<TOOLS, CONTEXT>>;
|
|
1164
1169
|
/**
|
|
1165
1170
|
* Callback that is set using the `onFinish` option.
|
|
1166
1171
|
*
|
|
@@ -1170,7 +1175,7 @@ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT e
|
|
|
1170
1175
|
*
|
|
1171
1176
|
* @param event - The final result along with aggregated step data.
|
|
1172
1177
|
*/
|
|
1173
|
-
type GenerateTextOnFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> =
|
|
1178
|
+
type GenerateTextOnFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> = Listener<OnFinishEvent<TOOLS, CONTEXT>>;
|
|
1174
1179
|
/**
|
|
1175
1180
|
* Generate a text and call tools for a given prompt using a language model.
|
|
1176
1181
|
*
|
|
@@ -3426,11 +3431,6 @@ interface RerankFinishEvent {
|
|
|
3426
3431
|
}>;
|
|
3427
3432
|
}
|
|
3428
3433
|
|
|
3429
|
-
/**
|
|
3430
|
-
* A callback function that can be used to notify listeners.
|
|
3431
|
-
*/
|
|
3432
|
-
type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
3433
|
-
|
|
3434
3434
|
/**
|
|
3435
3435
|
* Implement this interface to create custom telemetry integrations.
|
|
3436
3436
|
* Methods can be sync or return a PromiseLike.
|
|
@@ -4415,7 +4415,6 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, CO
|
|
|
4415
4415
|
*/
|
|
4416
4416
|
get tools(): TOOLS;
|
|
4417
4417
|
private prepareCall;
|
|
4418
|
-
private mergeCallbacks;
|
|
4419
4418
|
/**
|
|
4420
4419
|
* Generates an output from the agent (non-streaming).
|
|
4421
4420
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -958,6 +958,11 @@ type DownloadFunction = (options: Array<{
|
|
|
958
958
|
mediaType: string | undefined;
|
|
959
959
|
} | null>>;
|
|
960
960
|
|
|
961
|
+
/**
|
|
962
|
+
* A callback function that can be used to notify listeners.
|
|
963
|
+
*/
|
|
964
|
+
type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
965
|
+
|
|
961
966
|
/**
|
|
962
967
|
* Function that you can use to provide different settings for a step.
|
|
963
968
|
*
|
|
@@ -1119,7 +1124,7 @@ type GenerateTextIncludeSettings = {
|
|
|
1119
1124
|
*
|
|
1120
1125
|
* @param event - The event object containing generation configuration.
|
|
1121
1126
|
*/
|
|
1122
|
-
type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> =
|
|
1127
|
+
type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> = Listener<OnStartEvent<TOOLS, CONTEXT, OUTPUT, GenerateTextIncludeSettings>>;
|
|
1123
1128
|
/**
|
|
1124
1129
|
* Callback that is set using the `experimental_onStepStart` option.
|
|
1125
1130
|
*
|
|
@@ -1129,7 +1134,7 @@ type GenerateTextOnStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extend
|
|
|
1129
1134
|
*
|
|
1130
1135
|
* @param event - The event object containing step configuration.
|
|
1131
1136
|
*/
|
|
1132
|
-
type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> =
|
|
1137
|
+
type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>, OUTPUT extends Output = Output> = Listener<OnStepStartEvent<TOOLS, CONTEXT, OUTPUT, GenerateTextIncludeSettings>>;
|
|
1133
1138
|
/**
|
|
1134
1139
|
* Callback that is set using the `experimental_onToolCallStart` option.
|
|
1135
1140
|
*
|
|
@@ -1138,7 +1143,7 @@ type GenerateTextOnStepStartCallback<TOOLS extends ToolSet = ToolSet, CONTEXT ex
|
|
|
1138
1143
|
*
|
|
1139
1144
|
* @param event - The event object containing tool call information.
|
|
1140
1145
|
*/
|
|
1141
|
-
type GenerateTextOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> =
|
|
1146
|
+
type GenerateTextOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> = Listener<OnToolCallStartEvent<TOOLS>>;
|
|
1142
1147
|
/**
|
|
1143
1148
|
* Callback that is set using the `experimental_onToolCallFinish` option.
|
|
1144
1149
|
*
|
|
@@ -1151,7 +1156,7 @@ type GenerateTextOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> = (eve
|
|
|
1151
1156
|
*
|
|
1152
1157
|
* @param event - The event object containing tool call result information.
|
|
1153
1158
|
*/
|
|
1154
|
-
type GenerateTextOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> =
|
|
1159
|
+
type GenerateTextOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> = Listener<OnToolCallFinishEvent<TOOLS>>;
|
|
1155
1160
|
/**
|
|
1156
1161
|
* Callback that is set using the `onStepFinish` option.
|
|
1157
1162
|
*
|
|
@@ -1160,7 +1165,7 @@ type GenerateTextOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> = (ev
|
|
|
1160
1165
|
*
|
|
1161
1166
|
* @param stepResult - The result of the step.
|
|
1162
1167
|
*/
|
|
1163
|
-
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> =
|
|
1168
|
+
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> = Listener<OnStepFinishEvent<TOOLS, CONTEXT>>;
|
|
1164
1169
|
/**
|
|
1165
1170
|
* Callback that is set using the `onFinish` option.
|
|
1166
1171
|
*
|
|
@@ -1170,7 +1175,7 @@ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT e
|
|
|
1170
1175
|
*
|
|
1171
1176
|
* @param event - The final result along with aggregated step data.
|
|
1172
1177
|
*/
|
|
1173
|
-
type GenerateTextOnFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> =
|
|
1178
|
+
type GenerateTextOnFinishCallback<TOOLS extends ToolSet = ToolSet, CONTEXT extends GenerationContext<TOOLS> = GenerationContext<TOOLS>> = Listener<OnFinishEvent<TOOLS, CONTEXT>>;
|
|
1174
1179
|
/**
|
|
1175
1180
|
* Generate a text and call tools for a given prompt using a language model.
|
|
1176
1181
|
*
|
|
@@ -3426,11 +3431,6 @@ interface RerankFinishEvent {
|
|
|
3426
3431
|
}>;
|
|
3427
3432
|
}
|
|
3428
3433
|
|
|
3429
|
-
/**
|
|
3430
|
-
* A callback function that can be used to notify listeners.
|
|
3431
|
-
*/
|
|
3432
|
-
type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
3433
|
-
|
|
3434
3434
|
/**
|
|
3435
3435
|
* Implement this interface to create custom telemetry integrations.
|
|
3436
3436
|
* Methods can be sync or return a PromiseLike.
|
|
@@ -4415,7 +4415,6 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, CO
|
|
|
4415
4415
|
*/
|
|
4416
4416
|
get tools(): TOOLS;
|
|
4417
4417
|
private prepareCall;
|
|
4418
|
-
private mergeCallbacks;
|
|
4419
4418
|
/**
|
|
4420
4419
|
* Generates an output from the agent (non-streaming).
|
|
4421
4420
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1401,7 +1401,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
1401
1401
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1402
1402
|
|
|
1403
1403
|
// src/version.ts
|
|
1404
|
-
var VERSION = true ? "7.0.0-beta.
|
|
1404
|
+
var VERSION = true ? "7.0.0-beta.79" : "0.0.0-test";
|
|
1405
1405
|
|
|
1406
1406
|
// src/util/download/download.ts
|
|
1407
1407
|
var download = async ({
|
|
@@ -2475,6 +2475,17 @@ Learn more: \x1B[34m${moreInfoURL}\x1B[0m
|
|
|
2475
2475
|
);
|
|
2476
2476
|
}
|
|
2477
2477
|
|
|
2478
|
+
// src/util/merge-listeners.ts
|
|
2479
|
+
function mergeListeners(...listeners) {
|
|
2480
|
+
return async (event) => {
|
|
2481
|
+
await Promise.allSettled(
|
|
2482
|
+
listeners.map(async (listener) => {
|
|
2483
|
+
await (listener == null ? void 0 : listener(event));
|
|
2484
|
+
})
|
|
2485
|
+
);
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2478
2489
|
// src/telemetry/telemetry-integration-registry.ts
|
|
2479
2490
|
function registerTelemetryIntegration(integration) {
|
|
2480
2491
|
if (!globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) {
|
|
@@ -2519,14 +2530,7 @@ function getGlobalTelemetryIntegration() {
|
|
|
2519
2530
|
);
|
|
2520
2531
|
function createTelemetryComposite(getListenerFromIntegration) {
|
|
2521
2532
|
const listeners = allIntegrations.map(getListenerFromIntegration).filter(Boolean);
|
|
2522
|
-
return
|
|
2523
|
-
for (const listener of listeners) {
|
|
2524
|
-
try {
|
|
2525
|
-
await listener(event);
|
|
2526
|
-
} catch (_ignored) {
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
};
|
|
2533
|
+
return mergeListeners(...listeners);
|
|
2530
2534
|
}
|
|
2531
2535
|
const executeWrappers = allIntegrations.map((integration) => integration.executeTool).filter(Boolean);
|
|
2532
2536
|
return {
|
|
@@ -7180,10 +7184,6 @@ var DefaultStreamTextResult = class {
|
|
|
7180
7184
|
const initialResponseMessages = [];
|
|
7181
7185
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
7182
7186
|
if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
|
|
7183
|
-
const providerExecutedToolApprovals = [
|
|
7184
|
-
...approvedToolApprovals,
|
|
7185
|
-
...deniedToolApprovals
|
|
7186
|
-
].filter((toolApproval) => toolApproval.toolCall.providerExecuted);
|
|
7187
7187
|
const localApprovedToolApprovals = approvedToolApprovals.filter(
|
|
7188
7188
|
(toolApproval) => !toolApproval.toolCall.providerExecuted
|
|
7189
7189
|
);
|
|
@@ -8247,15 +8247,6 @@ var ToolLoopAgent = class {
|
|
|
8247
8247
|
...{ system: instructions, messages, prompt }
|
|
8248
8248
|
};
|
|
8249
8249
|
}
|
|
8250
|
-
mergeCallbacks(settingsCallback, methodCallback) {
|
|
8251
|
-
if (methodCallback && settingsCallback) {
|
|
8252
|
-
return async (event) => {
|
|
8253
|
-
await settingsCallback(event);
|
|
8254
|
-
await methodCallback(event);
|
|
8255
|
-
};
|
|
8256
|
-
}
|
|
8257
|
-
return methodCallback != null ? methodCallback : settingsCallback;
|
|
8258
|
-
}
|
|
8259
8250
|
/**
|
|
8260
8251
|
* Generates an output from the agent (non-streaming).
|
|
8261
8252
|
*/
|
|
@@ -8274,27 +8265,24 @@ var ToolLoopAgent = class {
|
|
|
8274
8265
|
...await this.prepareCall(options),
|
|
8275
8266
|
abortSignal,
|
|
8276
8267
|
timeout,
|
|
8277
|
-
experimental_onStart:
|
|
8268
|
+
experimental_onStart: mergeListeners(
|
|
8278
8269
|
this.settings.experimental_onStart,
|
|
8279
8270
|
experimental_onStart
|
|
8280
8271
|
),
|
|
8281
|
-
experimental_onStepStart:
|
|
8272
|
+
experimental_onStepStart: mergeListeners(
|
|
8282
8273
|
this.settings.experimental_onStepStart,
|
|
8283
8274
|
experimental_onStepStart
|
|
8284
8275
|
),
|
|
8285
|
-
experimental_onToolCallStart:
|
|
8276
|
+
experimental_onToolCallStart: mergeListeners(
|
|
8286
8277
|
this.settings.experimental_onToolCallStart,
|
|
8287
8278
|
experimental_onToolCallStart
|
|
8288
8279
|
),
|
|
8289
|
-
experimental_onToolCallFinish:
|
|
8280
|
+
experimental_onToolCallFinish: mergeListeners(
|
|
8290
8281
|
this.settings.experimental_onToolCallFinish,
|
|
8291
8282
|
experimental_onToolCallFinish
|
|
8292
8283
|
),
|
|
8293
|
-
onStepFinish: this.
|
|
8294
|
-
|
|
8295
|
-
onStepFinish
|
|
8296
|
-
),
|
|
8297
|
-
onFinish: this.mergeCallbacks(this.settings.onFinish, onFinish)
|
|
8284
|
+
onStepFinish: mergeListeners(this.settings.onStepFinish, onStepFinish),
|
|
8285
|
+
onFinish: mergeListeners(this.settings.onFinish, onFinish)
|
|
8298
8286
|
});
|
|
8299
8287
|
}
|
|
8300
8288
|
/**
|
|
@@ -8317,27 +8305,24 @@ var ToolLoopAgent = class {
|
|
|
8317
8305
|
abortSignal,
|
|
8318
8306
|
timeout,
|
|
8319
8307
|
experimental_transform,
|
|
8320
|
-
experimental_onStart:
|
|
8308
|
+
experimental_onStart: mergeListeners(
|
|
8321
8309
|
this.settings.experimental_onStart,
|
|
8322
8310
|
experimental_onStart
|
|
8323
8311
|
),
|
|
8324
|
-
experimental_onStepStart:
|
|
8312
|
+
experimental_onStepStart: mergeListeners(
|
|
8325
8313
|
this.settings.experimental_onStepStart,
|
|
8326
8314
|
experimental_onStepStart
|
|
8327
8315
|
),
|
|
8328
|
-
experimental_onToolCallStart:
|
|
8316
|
+
experimental_onToolCallStart: mergeListeners(
|
|
8329
8317
|
this.settings.experimental_onToolCallStart,
|
|
8330
8318
|
experimental_onToolCallStart
|
|
8331
8319
|
),
|
|
8332
|
-
experimental_onToolCallFinish:
|
|
8320
|
+
experimental_onToolCallFinish: mergeListeners(
|
|
8333
8321
|
this.settings.experimental_onToolCallFinish,
|
|
8334
8322
|
experimental_onToolCallFinish
|
|
8335
8323
|
),
|
|
8336
|
-
onStepFinish: this.
|
|
8337
|
-
|
|
8338
|
-
onStepFinish
|
|
8339
|
-
),
|
|
8340
|
-
onFinish: this.mergeCallbacks(this.settings.onFinish, onFinish)
|
|
8324
|
+
onStepFinish: mergeListeners(this.settings.onStepFinish, onStepFinish),
|
|
8325
|
+
onFinish: mergeListeners(this.settings.onFinish, onFinish)
|
|
8341
8326
|
});
|
|
8342
8327
|
}
|
|
8343
8328
|
};
|
|
@@ -13592,7 +13577,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
|
|
|
13592
13577
|
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
|
13593
13578
|
return part.type === "step-start" ? index : lastIndex;
|
|
13594
13579
|
}, -1);
|
|
13595
|
-
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart)
|
|
13580
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
|
|
13596
13581
|
return (
|
|
13597
13582
|
// has at least one tool approval response
|
|
13598
13583
|
lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
|