ai 7.0.127 → 7.0.129
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 +53 -0
- package/dist/index.d.ts +230 -155
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -209
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +288 -70
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +407 -76
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +25 -17
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +27 -21
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/06-provider-options.mdx +11 -10
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
- package/docs/02-getting-started/07-expo.mdx +1 -1
- package/docs/03-agents/02-building-agents.mdx +16 -11
- package/docs/03-agents/07-workflow-agent.mdx +83 -15
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
- package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
- package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +64 -67
- package/docs/03-ai-sdk-core/35-image-generation.mdx +3 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -3
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
- package/package.json +15 -15
- package/src/decide/decide-events.ts +129 -0
- package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
- package/src/decide/decision-provider.ts +11 -0
- package/src/decide/decision-result.ts +39 -0
- package/src/decide/index.ts +64 -0
- package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
- package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
- package/src/error/index.ts +10 -1
- package/src/generate-object/generate-object.ts +10 -0
- package/src/generate-object/stream-object.ts +10 -0
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-speech/index.ts +13 -1
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +5 -123
- package/src/generate-text/tool-approval-signature.ts +7 -4
- package/src/global.ts +3 -2
- package/src/index.ts +1 -1
- package/src/logger/deprecations.ts +72 -0
- package/src/logger/log-warnings.ts +25 -3
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/as-language-model-v3.ts +4 -0
- package/src/model/resolve-model.ts +45 -14
- package/src/prompt/convert-to-language-model-prompt.ts +7 -1
- package/src/realtime/encode-realtime-frame.ts +7 -2
- package/src/registry/custom-provider.ts +38 -26
- package/src/registry/index.ts +13 -1
- package/src/registry/no-such-provider-error.ts +2 -0
- package/src/registry/provider-registry.ts +56 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
- package/src/telemetry/telemetry.ts +35 -19
- package/src/telemetry/tracing-channel.ts +1 -1
- package/src/test/decision-mock-model-v4.ts +35 -0
- package/src/transcribe/index.ts +13 -1
- package/src/transcribe/transcribe.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/types/language-model.ts +9 -1
- package/src/types/usage.ts +21 -0
- package/src/ui/chat.ts +25 -9
- package/src/ui/convert-to-model-messages.ts +40 -8
- package/src/ui/http-chat-transport.ts +5 -3
- package/src/ui/process-text-stream.ts +5 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/src/ui/text-stream-chat-transport.ts +3 -1
- package/src/ui/ui-messages.ts +8 -0
- package/src/ui/unavailable-tool.ts +17 -0
- package/src/ui/validate-ui-messages.ts +10 -2
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
- package/src/evaluate/evaluate-events.ts +0 -131
- package/src/evaluate/evaluation-provider.ts +0 -6
- package/src/evaluate/evaluation-result.ts +0 -39
- package/src/evaluate/index.ts +0 -13
- package/src/test/evaluation-mock-model-v4.ts +0 -27
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Experimental_DecisionModelV4 as DecisionModelV4,
|
|
3
|
+
Experimental_EvaluationModelV4 as EvaluationModelV4,
|
|
4
|
+
Experimental_DecisionModelV4Question as DecisionModelV4Question,
|
|
5
|
+
Experimental_DecisionModelV4Result as DecisionModelV4Result,
|
|
6
|
+
} from '@ai-sdk/provider';
|
|
7
|
+
|
|
8
|
+
export type DecisionModel = string | DecisionModelV4 | EvaluationModelV4;
|
|
9
|
+
export type DecisionQuestion = DecisionModelV4Question;
|
|
10
|
+
|
|
11
|
+
export type DecisionAnswer<QUESTION extends DecisionQuestion> =
|
|
12
|
+
QUESTION extends { type: 'choice'; criteria: infer CRITERIA }
|
|
13
|
+
? {
|
|
14
|
+
type: 'choice';
|
|
15
|
+
choice: Extract<keyof CRITERIA, string>;
|
|
16
|
+
probabilities?: Record<Extract<keyof CRITERIA, string>, number>;
|
|
17
|
+
}
|
|
18
|
+
: QUESTION extends { type: 'score' }
|
|
19
|
+
? { type: 'score'; score: number; probabilities?: Record<string, number> }
|
|
20
|
+
: { type: 'boolean'; probability: number };
|
|
21
|
+
|
|
22
|
+
export type DecisionResult<QUESTIONS extends Record<string, DecisionQuestion>> =
|
|
23
|
+
{
|
|
24
|
+
readonly answers: {
|
|
25
|
+
[ID in keyof QUESTIONS]: DecisionAnswer<QUESTIONS[ID]>;
|
|
26
|
+
};
|
|
27
|
+
readonly usage: {
|
|
28
|
+
inputTokens: number | undefined;
|
|
29
|
+
outputTokens: number | undefined;
|
|
30
|
+
totalTokens: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
readonly warnings: DecisionModelV4Result['warnings'];
|
|
33
|
+
readonly rounding: DecisionModelV4Result['rounding'];
|
|
34
|
+
readonly providerMetadata: DecisionModelV4Result['providerMetadata'];
|
|
35
|
+
readonly response: NonNullable<DecisionModelV4Result['response']> & {
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
modelId: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Context } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { decide } from './decide';
|
|
3
|
+
import type {
|
|
4
|
+
DecideStartEvent,
|
|
5
|
+
DecideEndEvent,
|
|
6
|
+
DecisionModelCallStartEvent,
|
|
7
|
+
DecisionModelCallEndEvent,
|
|
8
|
+
} from './decide-events';
|
|
9
|
+
import type {
|
|
10
|
+
DecisionModel,
|
|
11
|
+
DecisionQuestion,
|
|
12
|
+
DecisionAnswer,
|
|
13
|
+
DecisionResult,
|
|
14
|
+
} from './decision-result';
|
|
15
|
+
|
|
16
|
+
export { decide as experimental_decide } from './decide';
|
|
17
|
+
export type {
|
|
18
|
+
DecideStartEvent as Experimental_DecideStartEvent,
|
|
19
|
+
DecideEndEvent as Experimental_DecideEndEvent,
|
|
20
|
+
DecisionModelCallStartEvent as Experimental_DecisionModelCallStartEvent,
|
|
21
|
+
DecisionModelCallEndEvent as Experimental_DecisionModelCallEndEvent,
|
|
22
|
+
} from './decide-events';
|
|
23
|
+
export type {
|
|
24
|
+
DecisionModel as Experimental_DecisionModel,
|
|
25
|
+
DecisionQuestion as Experimental_DecisionQuestion,
|
|
26
|
+
DecisionAnswer as Experimental_DecisionAnswer,
|
|
27
|
+
DecisionResult as Experimental_DecisionResult,
|
|
28
|
+
} from './decision-result';
|
|
29
|
+
|
|
30
|
+
/** @deprecated Use `experimental_decide` instead. */
|
|
31
|
+
export const experimental_evaluate: typeof decide = decide;
|
|
32
|
+
|
|
33
|
+
/** @deprecated Use `Experimental_DecideStartEvent` instead. */
|
|
34
|
+
export type Experimental_EvaluateStartEvent<
|
|
35
|
+
RUNTIME_CONTEXT extends Context = Context,
|
|
36
|
+
> = DecideStartEvent<RUNTIME_CONTEXT>;
|
|
37
|
+
|
|
38
|
+
/** @deprecated Use `Experimental_DecideEndEvent` instead. */
|
|
39
|
+
export type Experimental_EvaluateEndEvent<
|
|
40
|
+
RUNTIME_CONTEXT extends Context = Context,
|
|
41
|
+
> = DecideEndEvent<RUNTIME_CONTEXT>;
|
|
42
|
+
|
|
43
|
+
/** @deprecated Use `Experimental_DecisionModelCallStartEvent` instead. */
|
|
44
|
+
export type Experimental_EvaluationModelCallStartEvent =
|
|
45
|
+
DecisionModelCallStartEvent;
|
|
46
|
+
|
|
47
|
+
/** @deprecated Use `Experimental_DecisionModelCallEndEvent` instead. */
|
|
48
|
+
export type Experimental_EvaluationModelCallEndEvent =
|
|
49
|
+
DecisionModelCallEndEvent;
|
|
50
|
+
|
|
51
|
+
/** @deprecated Use `Experimental_DecisionModel` instead. */
|
|
52
|
+
export type Experimental_EvaluationModel = DecisionModel;
|
|
53
|
+
|
|
54
|
+
/** @deprecated Use `Experimental_DecisionQuestion` instead. */
|
|
55
|
+
export type Experimental_EvaluationQuestion = DecisionQuestion;
|
|
56
|
+
|
|
57
|
+
/** @deprecated Use `Experimental_DecisionAnswer` instead. */
|
|
58
|
+
export type Experimental_EvaluationAnswer<QUESTION extends DecisionQuestion> =
|
|
59
|
+
DecisionAnswer<QUESTION>;
|
|
60
|
+
|
|
61
|
+
/** @deprecated Use `Experimental_DecisionResult` instead. */
|
|
62
|
+
export type Experimental_EvaluationResult<
|
|
63
|
+
QUESTIONS extends Record<string, DecisionQuestion>,
|
|
64
|
+
> = DecisionResult<QUESTIONS>;
|
|
@@ -4,7 +4,7 @@ import { filterIncludedContext } from '../telemetry/filter-included-context';
|
|
|
4
4
|
import type { TelemetryDispatcher } from '../telemetry/telemetry';
|
|
5
5
|
import type { TelemetryOptions } from '../telemetry/telemetry-options';
|
|
6
6
|
import type { Callback } from '../util/callback';
|
|
7
|
-
import type {
|
|
7
|
+
import type { DecideEndEvent, DecideStartEvent } from './decide-events';
|
|
8
8
|
|
|
9
9
|
export function createRestrictedTelemetryDispatcher<
|
|
10
10
|
RUNTIME_CONTEXT extends Context,
|
|
@@ -16,18 +16,18 @@ export function createRestrictedTelemetryDispatcher<
|
|
|
16
16
|
TelemetryDispatcher,
|
|
17
17
|
| 'onStart'
|
|
18
18
|
| 'onEnd'
|
|
19
|
-
| '
|
|
20
|
-
| '
|
|
19
|
+
| 'experimental_onDecideStart'
|
|
20
|
+
| 'experimental_onDecideEnd'
|
|
21
21
|
> & {
|
|
22
|
-
onStart: Callback<
|
|
23
|
-
onEnd: Callback<
|
|
22
|
+
onStart: Callback<DecideStartEvent<RUNTIME_CONTEXT>>;
|
|
23
|
+
onEnd: Callback<DecideEndEvent<RUNTIME_CONTEXT>>;
|
|
24
24
|
} {
|
|
25
25
|
const dispatcher = createTelemetryDispatcher({ telemetry });
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
...dispatcher,
|
|
29
29
|
onStart: event =>
|
|
30
|
-
dispatcher.
|
|
30
|
+
dispatcher.experimental_onDecideStart?.({
|
|
31
31
|
...event,
|
|
32
32
|
runtimeContext: filterIncludedContext({
|
|
33
33
|
context: event.runtimeContext,
|
|
@@ -35,7 +35,7 @@ export function createRestrictedTelemetryDispatcher<
|
|
|
35
35
|
}),
|
|
36
36
|
}),
|
|
37
37
|
onEnd: event =>
|
|
38
|
-
dispatcher.
|
|
38
|
+
dispatcher.experimental_onDecideEnd?.({
|
|
39
39
|
...event,
|
|
40
40
|
runtimeContext: filterIncludedContext({
|
|
41
41
|
context: event.runtimeContext,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidResponseDataError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type Experimental_DecisionModelV4CallOptions as DecisionModelV4CallOptions,
|
|
4
|
+
type Experimental_DecisionModelV4Result as DecisionModelV4Result,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { InvalidArgumentError } from '../error/invalid-argument-error';
|
|
7
7
|
|
|
@@ -47,10 +47,10 @@ function invalidInput(
|
|
|
47
47
|
throw new InvalidArgumentError({ parameter, value, message });
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export function
|
|
50
|
+
export function validateDecisionInput({
|
|
51
51
|
state,
|
|
52
52
|
questions,
|
|
53
|
-
}:
|
|
53
|
+
}: DecisionModelV4CallOptions) {
|
|
54
54
|
if (!isInput(state)) {
|
|
55
55
|
invalidInput(
|
|
56
56
|
'state',
|
|
@@ -173,21 +173,21 @@ function validateDistribution(
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
export function
|
|
176
|
+
export function validateDecisionAnswers({
|
|
177
177
|
questions,
|
|
178
178
|
answers,
|
|
179
179
|
rounding,
|
|
180
180
|
}: {
|
|
181
|
-
questions:
|
|
181
|
+
questions: DecisionModelV4CallOptions['questions'];
|
|
182
182
|
answers: unknown;
|
|
183
|
-
rounding?:
|
|
183
|
+
rounding?: DecisionModelV4Result['rounding'];
|
|
184
184
|
}) {
|
|
185
185
|
function roundingError(decimals: number | undefined): number {
|
|
186
186
|
if (decimals === undefined) return 0;
|
|
187
187
|
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 15) {
|
|
188
188
|
invalidAnswer(
|
|
189
189
|
answers,
|
|
190
|
-
'
|
|
190
|
+
'Decision rounding decimals must be integers between 0 and 15.',
|
|
191
191
|
);
|
|
192
192
|
}
|
|
193
193
|
return 0.5 * 10 ** -decimals;
|
|
@@ -197,7 +197,7 @@ export function validateEvaluationAnswers({
|
|
|
197
197
|
if (!isRecord(answers) || !hasExactKeys(answers, Object.keys(questions))) {
|
|
198
198
|
invalidAnswer(
|
|
199
199
|
answers,
|
|
200
|
-
'
|
|
200
|
+
'Decision must return exactly one answer for every question.',
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
203
|
|
package/src/error/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Experimental_DecisionUnsupportedQuestionTypeError } from '@ai-sdk/provider';
|
|
2
|
+
|
|
1
3
|
export {
|
|
2
4
|
AISDKError,
|
|
3
5
|
APICallError,
|
|
4
6
|
EmptyResponseBodyError,
|
|
5
|
-
|
|
7
|
+
Experimental_DecisionUnsupportedQuestionTypeError,
|
|
6
8
|
InvalidPromptError,
|
|
7
9
|
InvalidResponseDataError,
|
|
8
10
|
JSONParseError,
|
|
@@ -41,3 +43,10 @@ export { InvalidMessageRoleError } from '../prompt/invalid-message-role-error';
|
|
|
41
43
|
export { MessageConversionError } from '../prompt/message-conversion-error';
|
|
42
44
|
export { DownloadError } from '@ai-sdk/provider-utils';
|
|
43
45
|
export { RetryError } from '../util/retry-error';
|
|
46
|
+
|
|
47
|
+
/** @deprecated Use `Experimental_DecisionUnsupportedQuestionTypeError` instead. */
|
|
48
|
+
export const Experimental_EvaluationUnsupportedQuestionTypeError =
|
|
49
|
+
Experimental_DecisionUnsupportedQuestionTypeError;
|
|
50
|
+
/** @deprecated Use `Experimental_DecisionUnsupportedQuestionTypeError` instead. */
|
|
51
|
+
export type Experimental_EvaluationUnsupportedQuestionTypeError =
|
|
52
|
+
Experimental_DecisionUnsupportedQuestionTypeError;
|
|
@@ -263,6 +263,16 @@ export async function generateObject<
|
|
|
263
263
|
};
|
|
264
264
|
},
|
|
265
265
|
): Promise<GenerateObjectResult<RESULT>> {
|
|
266
|
+
logWarnings({
|
|
267
|
+
warnings: [
|
|
268
|
+
{
|
|
269
|
+
type: 'deprecated',
|
|
270
|
+
setting: 'generateObject',
|
|
271
|
+
message: 'Use generateText with an output setting instead.',
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
});
|
|
275
|
+
|
|
266
276
|
const {
|
|
267
277
|
model: modelArg,
|
|
268
278
|
output = 'object',
|
|
@@ -353,6 +353,16 @@ export function streamObject<
|
|
|
353
353
|
: never
|
|
354
354
|
: never
|
|
355
355
|
> {
|
|
356
|
+
logWarnings({
|
|
357
|
+
warnings: [
|
|
358
|
+
{
|
|
359
|
+
type: 'deprecated',
|
|
360
|
+
setting: 'streamObject',
|
|
361
|
+
message: 'Use streamText with an output setting instead.',
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
});
|
|
365
|
+
|
|
356
366
|
const {
|
|
357
367
|
model,
|
|
358
368
|
output = 'object',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InvalidResponseDataError } from '@ai-sdk/provider';
|
|
1
2
|
import {
|
|
2
3
|
DefaultGeneratedFile,
|
|
3
4
|
type GeneratedFile,
|
|
@@ -41,10 +42,10 @@ export class DefaultGeneratedAudioFile
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
if (!format) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
45
|
+
throw new InvalidResponseDataError({
|
|
46
|
+
data: mediaType,
|
|
47
|
+
message: `Could not determine audio format from media type: ${mediaType}`,
|
|
48
|
+
});
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
this.format = format;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SpeechResult } from './generate-speech-result';
|
|
2
2
|
import { generateSpeech } from './generate-speech';
|
|
3
|
+
import { logWarnings } from '../logger/log-warnings';
|
|
3
4
|
|
|
4
5
|
export { generateSpeech } from './generate-speech';
|
|
5
6
|
export type { SpeechResult } from './generate-speech-result';
|
|
@@ -14,7 +15,18 @@ export type {
|
|
|
14
15
|
/**
|
|
15
16
|
* @deprecated Use `generateSpeech` instead.
|
|
16
17
|
*/
|
|
17
|
-
const experimental_generateSpeech =
|
|
18
|
+
const experimental_generateSpeech: typeof generateSpeech = options => {
|
|
19
|
+
logWarnings({
|
|
20
|
+
warnings: [
|
|
21
|
+
{
|
|
22
|
+
type: 'deprecated',
|
|
23
|
+
setting: 'experimental_generateSpeech',
|
|
24
|
+
message: 'Use generateSpeech instead.',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
return generateSpeech(options);
|
|
29
|
+
};
|
|
18
30
|
export { experimental_generateSpeech };
|
|
19
31
|
|
|
20
32
|
/**
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { Context, ToolSet } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { NoOutputGeneratedError } from '../error/no-output-generated-error';
|
|
3
|
+
import type { LanguageModelUsage } from '../types/usage';
|
|
4
|
+
import type { GenerateTextResult } from './generate-text-result';
|
|
5
|
+
import type { Output } from './output';
|
|
6
|
+
import type { InferCompleteOutput } from './output-utils';
|
|
7
|
+
import { convertToReasoningOutputs } from './reasoning-output';
|
|
8
|
+
import type { ResponseMessage } from './response-message';
|
|
9
|
+
|
|
10
|
+
export class DefaultGenerateTextResult<
|
|
11
|
+
TOOLS extends ToolSet,
|
|
12
|
+
RUNTIME_CONTEXT extends Context,
|
|
13
|
+
OUTPUT extends Output,
|
|
14
|
+
> implements GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT> {
|
|
15
|
+
readonly steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
16
|
+
readonly totalUsage: LanguageModelUsage;
|
|
17
|
+
private readonly _output: InferCompleteOutput<OUTPUT> | undefined;
|
|
18
|
+
|
|
19
|
+
constructor(options: {
|
|
20
|
+
initialResponseMessages: Array<ResponseMessage>;
|
|
21
|
+
steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
22
|
+
output: InferCompleteOutput<OUTPUT> | undefined;
|
|
23
|
+
totalUsage: LanguageModelUsage;
|
|
24
|
+
}) {
|
|
25
|
+
this.initialResponseMessages = options.initialResponseMessages;
|
|
26
|
+
this.steps = options.steps;
|
|
27
|
+
this._output = options.output;
|
|
28
|
+
this.totalUsage = options.totalUsage;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private readonly initialResponseMessages: Array<ResponseMessage>;
|
|
32
|
+
|
|
33
|
+
get finalStep() {
|
|
34
|
+
return this.steps.at(-1)!;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get content() {
|
|
38
|
+
return this.steps.flatMap(step => step.content);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get text() {
|
|
42
|
+
return this.finalStep.text;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get files() {
|
|
46
|
+
return this.steps.flatMap(step => step.files);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get reasoningText() {
|
|
50
|
+
return this.finalStep.reasoningText;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get reasoning() {
|
|
54
|
+
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get toolCalls() {
|
|
58
|
+
return this.steps.flatMap(step => step.toolCalls);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get staticToolCalls() {
|
|
62
|
+
return this.steps.flatMap(step => step.staticToolCalls);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get dynamicToolCalls() {
|
|
66
|
+
return this.steps.flatMap(step => step.dynamicToolCalls);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get toolResults() {
|
|
70
|
+
return this.steps.flatMap(step => step.toolResults);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get staticToolResults() {
|
|
74
|
+
return this.steps.flatMap(step => step.staticToolResults);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get dynamicToolResults() {
|
|
78
|
+
return this.steps.flatMap(step => step.dynamicToolResults);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get sources() {
|
|
82
|
+
return this.steps.flatMap(step => step.sources);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get finishReason() {
|
|
86
|
+
return this.finalStep.finishReason;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get rawFinishReason() {
|
|
90
|
+
return this.finalStep.rawFinishReason;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get warnings() {
|
|
94
|
+
return this.steps.flatMap(step => step.warnings ?? []);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get providerMetadata() {
|
|
98
|
+
return this.finalStep.providerMetadata;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get response() {
|
|
102
|
+
return this.finalStep.response;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get responseMessages() {
|
|
106
|
+
return [
|
|
107
|
+
...this.initialResponseMessages,
|
|
108
|
+
...this.steps.flatMap(step => step.response.messages),
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get request() {
|
|
113
|
+
return this.finalStep.request;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get usage() {
|
|
117
|
+
return this.totalUsage;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
get output() {
|
|
121
|
+
if (this._output == null) {
|
|
122
|
+
throw new NoOutputGeneratedError();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return this._output;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type ProviderOptions,
|
|
16
16
|
type ToolSet,
|
|
17
17
|
} from '@ai-sdk/provider-utils';
|
|
18
|
-
import {
|
|
18
|
+
import { ToolChoiceViolationError } from '../error';
|
|
19
19
|
import { logWarnings } from '../logger/log-warnings';
|
|
20
20
|
import { resolveLanguageModel } from '../model/resolve-model';
|
|
21
21
|
import type { ModelMessage } from '../prompt';
|
|
@@ -76,6 +76,7 @@ import type {
|
|
|
76
76
|
GenerateTextOnStepFinishCallback,
|
|
77
77
|
GenerateTextOnStepStartCallback,
|
|
78
78
|
} from './generate-text-events';
|
|
79
|
+
import { DefaultGenerateTextResult } from './default-generate-text-result';
|
|
79
80
|
import type { GenerateTextResult } from './generate-text-result';
|
|
80
81
|
import { isToolExecutionAllowedFinishReason } from './is-tool-execution-allowed-finish-reason';
|
|
81
82
|
import type {
|
|
@@ -83,11 +84,9 @@ import type {
|
|
|
83
84
|
OnLanguageModelCallStartCallback,
|
|
84
85
|
} from './language-model-events';
|
|
85
86
|
import { text, type Output } from './output';
|
|
86
|
-
import type { InferCompleteOutput } from './output-utils';
|
|
87
87
|
import { parseToolCall } from './parse-tool-call';
|
|
88
88
|
import type { PrepareStepFunction } from './prepare-step';
|
|
89
89
|
import { prepareStepCallSettings } from './prepare-step-call-settings';
|
|
90
|
-
import { convertToReasoningOutputs } from './reasoning-output';
|
|
91
90
|
import { resolveToolApproval } from './resolve-tool-approval';
|
|
92
91
|
import type { ResponseMessage } from './response-message';
|
|
93
92
|
import { createRestrictedTelemetryDispatcher } from './restricted-telemetry-dispatcher';
|
|
@@ -1100,7 +1099,9 @@ export async function generateText<
|
|
|
1100
1099
|
> = {};
|
|
1101
1100
|
const blockedToolCallIds = new Set<string>();
|
|
1102
1101
|
|
|
1103
|
-
const generatedFileDataCache
|
|
1102
|
+
const generatedFileDataCache: Parameters<
|
|
1103
|
+
typeof convertLanguageModelContent
|
|
1104
|
+
>[0]['generatedFileDataCache'] = new WeakMap();
|
|
1104
1105
|
const modelCallContent = await convertLanguageModelContent({
|
|
1105
1106
|
content: currentModelResponse.content,
|
|
1106
1107
|
toolCalls: stepToolCalls,
|
|
@@ -1687,122 +1688,3 @@ async function executeTools<TOOLS extends ToolSet>({
|
|
|
1687
1688
|
(result): result is NonNullable<typeof result> => result != null,
|
|
1688
1689
|
);
|
|
1689
1690
|
}
|
|
1690
|
-
|
|
1691
|
-
class DefaultGenerateTextResult<
|
|
1692
|
-
TOOLS extends ToolSet,
|
|
1693
|
-
RUNTIME_CONTEXT extends Context,
|
|
1694
|
-
OUTPUT extends Output,
|
|
1695
|
-
> implements GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT> {
|
|
1696
|
-
readonly steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
1697
|
-
readonly totalUsage: LanguageModelUsage;
|
|
1698
|
-
private readonly _output: InferCompleteOutput<OUTPUT> | undefined;
|
|
1699
|
-
|
|
1700
|
-
constructor(options: {
|
|
1701
|
-
initialResponseMessages: Array<ResponseMessage>;
|
|
1702
|
-
steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
1703
|
-
output: InferCompleteOutput<OUTPUT> | undefined;
|
|
1704
|
-
totalUsage: LanguageModelUsage;
|
|
1705
|
-
}) {
|
|
1706
|
-
this.initialResponseMessages = options.initialResponseMessages;
|
|
1707
|
-
this.steps = options.steps;
|
|
1708
|
-
this._output = options.output;
|
|
1709
|
-
this.totalUsage = options.totalUsage;
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
private readonly initialResponseMessages: Array<ResponseMessage>;
|
|
1713
|
-
|
|
1714
|
-
get finalStep() {
|
|
1715
|
-
return this.steps.at(-1)!;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
get content() {
|
|
1719
|
-
return this.steps.flatMap(step => step.content);
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
get text() {
|
|
1723
|
-
return this.finalStep.text;
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
get files() {
|
|
1727
|
-
return this.steps.flatMap(step => step.files);
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
get reasoningText() {
|
|
1731
|
-
return this.finalStep.reasoningText;
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
get reasoning() {
|
|
1735
|
-
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
get toolCalls() {
|
|
1739
|
-
return this.steps.flatMap(step => step.toolCalls);
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
get staticToolCalls() {
|
|
1743
|
-
return this.steps.flatMap(step => step.staticToolCalls);
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
get dynamicToolCalls() {
|
|
1747
|
-
return this.steps.flatMap(step => step.dynamicToolCalls);
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
get toolResults() {
|
|
1751
|
-
return this.steps.flatMap(step => step.toolResults);
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
get staticToolResults() {
|
|
1755
|
-
return this.steps.flatMap(step => step.staticToolResults);
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
get dynamicToolResults() {
|
|
1759
|
-
return this.steps.flatMap(step => step.dynamicToolResults);
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
get sources() {
|
|
1763
|
-
return this.steps.flatMap(step => step.sources);
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
get finishReason() {
|
|
1767
|
-
return this.finalStep.finishReason;
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
get rawFinishReason() {
|
|
1771
|
-
return this.finalStep.rawFinishReason;
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
get warnings() {
|
|
1775
|
-
return this.steps.flatMap(step => step.warnings ?? []);
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
get providerMetadata() {
|
|
1779
|
-
return this.finalStep.providerMetadata;
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
get response() {
|
|
1783
|
-
return this.finalStep.response;
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
get responseMessages() {
|
|
1787
|
-
return [
|
|
1788
|
-
...this.initialResponseMessages,
|
|
1789
|
-
...this.steps.flatMap(step => step.response.messages),
|
|
1790
|
-
];
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
get request() {
|
|
1794
|
-
return this.finalStep.request;
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
get usage() {
|
|
1798
|
-
return this.totalUsage;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
get output() {
|
|
1802
|
-
if (this._output == null) {
|
|
1803
|
-
throw new NoOutputGeneratedError();
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
return this._output;
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
@@ -3,12 +3,15 @@ import { hashCanonical, toBase64url } from '../util/canonical-hash';
|
|
|
3
3
|
|
|
4
4
|
const encoder = new TextEncoder();
|
|
5
5
|
|
|
6
|
-
function fromBase64url(str: string)
|
|
6
|
+
function fromBase64url(str: string) {
|
|
7
7
|
return convertBase64ToUint8Array(str);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
async function importKey(secret: string | Uint8Array): Promise<CryptoKey> {
|
|
11
|
-
const keyData =
|
|
11
|
+
const keyData =
|
|
12
|
+
typeof secret === 'string'
|
|
13
|
+
? encoder.encode(secret)
|
|
14
|
+
: (secret as Uint8Array<ArrayBuffer>);
|
|
12
15
|
return crypto.subtle.importKey(
|
|
13
16
|
'raw',
|
|
14
17
|
keyData,
|
|
@@ -26,7 +29,7 @@ function buildPayload(
|
|
|
26
29
|
toolCallId: string,
|
|
27
30
|
toolName: string,
|
|
28
31
|
inputDigest: string,
|
|
29
|
-
)
|
|
32
|
+
) {
|
|
30
33
|
return encoder.encode(
|
|
31
34
|
JSON.stringify([
|
|
32
35
|
'ai-sdk-tool-approval-v1',
|
|
@@ -49,7 +52,7 @@ function buildLegacyPayload(
|
|
|
49
52
|
toolCallId: string,
|
|
50
53
|
toolName: string,
|
|
51
54
|
inputDigest: string,
|
|
52
|
-
)
|
|
55
|
+
) {
|
|
53
56
|
return encoder.encode(
|
|
54
57
|
`${approvalId}\n${toolCallId}\n${toolName}\n${inputDigest}`,
|
|
55
58
|
);
|
package/src/global.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare global {
|
|
|
9
9
|
* String model ids are resolved to the default provider and model id.
|
|
10
10
|
*
|
|
11
11
|
* If not set, the default provider is the Vercel AI gateway provider.
|
|
12
|
-
*
|
|
12
|
+
* An explicitly configured provider must support decision models to use experimental_decide.
|
|
13
13
|
*
|
|
14
14
|
* @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
|
|
15
15
|
*/
|
|
@@ -18,7 +18,8 @@ declare global {
|
|
|
18
18
|
/**
|
|
19
19
|
* The warning logger to use for the AI SDK.
|
|
20
20
|
*
|
|
21
|
-
* If not set,
|
|
21
|
+
* If not set, warnings use process.emitWarning when available, otherwise
|
|
22
|
+
* console.warn. Deprecations are emitted once per code by the default logger.
|
|
22
23
|
*
|
|
23
24
|
* If set to false, no warnings are logged.
|
|
24
25
|
*/
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export * from './agent';
|
|
|
41
41
|
export * from './batch';
|
|
42
42
|
export * from './embed';
|
|
43
43
|
export * from './error';
|
|
44
|
-
export * from './
|
|
44
|
+
export * from './decide';
|
|
45
45
|
export * from './generate-image';
|
|
46
46
|
export * from './generate-object';
|
|
47
47
|
export * from './generate-speech';
|