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.
Files changed (100) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/index.d.ts +230 -155
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +386 -209
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +288 -70
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +407 -76
  9. package/dist/internal/index.js.map +1 -1
  10. package/dist/test/index.d.ts +25 -17
  11. package/dist/test/index.d.ts.map +1 -1
  12. package/dist/test/index.js +27 -21
  13. package/dist/test/index.js.map +1 -1
  14. package/docs/02-foundations/06-provider-options.mdx +11 -10
  15. package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
  16. package/docs/02-getting-started/07-expo.mdx +1 -1
  17. package/docs/03-agents/02-building-agents.mdx +16 -11
  18. package/docs/03-agents/07-workflow-agent.mdx +83 -15
  19. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
  20. package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
  21. package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
  22. package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
  23. package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +64 -67
  24. package/docs/03-ai-sdk-core/35-image-generation.mdx +3 -1
  25. package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
  26. package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
  27. package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
  28. package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
  29. package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -3
  30. package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
  31. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
  32. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
  33. package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
  34. package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
  35. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
  36. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
  37. package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
  38. package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
  39. package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
  40. package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
  41. package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
  42. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
  43. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
  44. package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
  45. package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
  46. package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
  47. package/package.json +15 -15
  48. package/src/decide/decide-events.ts +129 -0
  49. package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
  50. package/src/decide/decision-provider.ts +11 -0
  51. package/src/decide/decision-result.ts +39 -0
  52. package/src/decide/index.ts +64 -0
  53. package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
  54. package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
  55. package/src/error/index.ts +10 -1
  56. package/src/generate-object/generate-object.ts +10 -0
  57. package/src/generate-object/stream-object.ts +10 -0
  58. package/src/generate-speech/generated-audio-file.ts +5 -4
  59. package/src/generate-speech/index.ts +13 -1
  60. package/src/generate-text/default-generate-text-result.ts +127 -0
  61. package/src/generate-text/generate-text.ts +5 -123
  62. package/src/generate-text/tool-approval-signature.ts +7 -4
  63. package/src/global.ts +3 -2
  64. package/src/index.ts +1 -1
  65. package/src/logger/deprecations.ts +72 -0
  66. package/src/logger/log-warnings.ts +25 -3
  67. package/src/middleware/extract-reasoning-middleware.ts +25 -6
  68. package/src/model/as-language-model-v3.ts +4 -0
  69. package/src/model/resolve-model.ts +45 -14
  70. package/src/prompt/convert-to-language-model-prompt.ts +7 -1
  71. package/src/realtime/encode-realtime-frame.ts +7 -2
  72. package/src/registry/custom-provider.ts +38 -26
  73. package/src/registry/index.ts +13 -1
  74. package/src/registry/no-such-provider-error.ts +2 -0
  75. package/src/registry/provider-registry.ts +56 -29
  76. package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
  77. package/src/telemetry/telemetry.ts +35 -19
  78. package/src/telemetry/tracing-channel.ts +1 -1
  79. package/src/test/decision-mock-model-v4.ts +35 -0
  80. package/src/transcribe/index.ts +13 -1
  81. package/src/transcribe/transcribe.ts +1 -1
  82. package/src/types/index.ts +1 -0
  83. package/src/types/language-model.ts +9 -1
  84. package/src/types/usage.ts +21 -0
  85. package/src/ui/chat.ts +25 -9
  86. package/src/ui/convert-to-model-messages.ts +40 -8
  87. package/src/ui/http-chat-transport.ts +5 -3
  88. package/src/ui/process-text-stream.ts +5 -1
  89. package/src/ui/process-ui-message-stream.ts +21 -0
  90. package/src/ui/text-stream-chat-transport.ts +3 -1
  91. package/src/ui/ui-messages.ts +8 -0
  92. package/src/ui/unavailable-tool.ts +17 -0
  93. package/src/ui/validate-ui-messages.ts +10 -2
  94. package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
  95. package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
  96. package/src/evaluate/evaluate-events.ts +0 -131
  97. package/src/evaluate/evaluation-provider.ts +0 -6
  98. package/src/evaluate/evaluation-result.ts +0 -39
  99. package/src/evaluate/index.ts +0 -13
  100. package/src/test/evaluation-mock-model-v4.ts +0 -27
@@ -120,6 +120,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
120
120
  onError,
121
121
  onToolCall,
122
122
  onData,
123
+ resetStateOnMessageIdChange = false,
123
124
  }: {
124
125
  // input stream is not fully typed yet:
125
126
  stream: ReadableStream<UIMessageChunk>;
@@ -136,6 +137,8 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
136
137
  }) => Promise<void>,
137
138
  ) => Promise<void>;
138
139
  onError: ErrorHandler;
140
+ // During resume, a different message ID identifies a separate response.
141
+ resetStateOnMessageIdChange?: boolean;
139
142
  }): ReadableStream<InferUIMessageChunk<UI_MESSAGE>> {
140
143
  return stream.pipeThrough(
141
144
  new TransformStream<UIMessageChunk, InferUIMessageChunk<UI_MESSAGE>>({
@@ -953,6 +956,24 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
953
956
  }
954
957
 
955
958
  case 'start': {
959
+ if (
960
+ resetStateOnMessageIdChange &&
961
+ chunk.messageId != null &&
962
+ chunk.messageId !== state.message.id
963
+ ) {
964
+ // Start the separate response with empty parts and metadata.
965
+ // Reset the active-part maps too, so earlier chunks stay with
966
+ // the previous response. Keep the state object for its callers.
967
+ Object.assign(
968
+ state,
969
+ createStreamingUIMessageState({
970
+ lastMessage: undefined,
971
+ messageId: chunk.messageId,
972
+ }),
973
+ { finishReason: undefined },
974
+ );
975
+ }
976
+
956
977
  if (chunk.messageId != null) {
957
978
  state.message.id = chunk.messageId;
958
979
  }
@@ -17,7 +17,9 @@ export class TextStreamChatTransport<
17
17
  stream: ReadableStream<Uint8Array<ArrayBufferLike>>,
18
18
  ): ReadableStream<UIMessageChunk> {
19
19
  return transformTextToUiMessageStream({
20
- stream: stream.pipeThrough(new TextDecoderStream()),
20
+ stream: stream.pipeThrough(
21
+ new TextDecoderStream() as ReadableWritablePair<string, Uint8Array>,
22
+ ),
21
23
  });
22
24
  }
23
25
  }
@@ -421,6 +421,14 @@ export type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
421
421
  export type DynamicToolUIPart = {
422
422
  type: 'dynamic-tool';
423
423
 
424
+ /**
425
+ * `false` when a static tool part was normalized to a dynamic tool part
426
+ * because its current tool schema was unavailable or incompatible.
427
+ *
428
+ * This preserves its static origin across persistence boundaries.
429
+ */
430
+ dynamic?: false;
431
+
424
432
  /**
425
433
  * Name of the tool that is being called.
426
434
  */
@@ -0,0 +1,17 @@
1
+ import type { DynamicToolUIPart, ToolUIPart } from './ui-messages';
2
+
3
+ export function markToolPartAsUnavailable(
4
+ part: DynamicToolUIPart,
5
+ ): DynamicToolUIPart {
6
+ // Preserve the static tool's provenance across persistence boundaries so
7
+ // model-message conversion never falls back to its unfiltered raw output.
8
+ part.dynamic = false;
9
+
10
+ return part;
11
+ }
12
+
13
+ export function isToolPartFromUnavailableTool(
14
+ part: ToolUIPart | DynamicToolUIPart,
15
+ ): boolean {
16
+ return part.type === 'dynamic-tool' && part.dynamic === false;
17
+ }
@@ -22,6 +22,7 @@ import type {
22
22
  ToolUIPart,
23
23
  UIMessage,
24
24
  } from './ui-messages';
25
+ import { markToolPartAsUnavailable } from './unavailable-tool';
25
26
  import { warnIfUIMessageHasDeprecatedRawInput } from './warn-if-ui-message-has-deprecated-raw-input';
26
27
 
27
28
  const toolMetadataSchema: ZodType<JSONObject> = z.record(
@@ -43,11 +44,11 @@ function isEmptyObject(value: unknown): value is Record<string, never> {
43
44
  function asDynamicToolPart(toolPart: ToolUIPart): DynamicToolUIPart {
44
45
  const { type, ...part } = toolPart;
45
46
 
46
- return {
47
+ return markToolPartAsUnavailable({
47
48
  ...part,
48
49
  type: 'dynamic-tool',
49
50
  toolName: type.slice(5),
50
- } as DynamicToolUIPart;
51
+ } as DynamicToolUIPart);
51
52
  }
52
53
 
53
54
  function getToolPartInputSchemaInput(
@@ -148,6 +149,7 @@ const uiMessagesSchema = lazySchema(() => {
148
149
  }),
149
150
  z.object({
150
151
  type: z.literal('dynamic-tool'),
152
+ dynamic: z.literal(false).optional(),
151
153
  toolName: z.string(),
152
154
  toolCallId: z.string(),
153
155
  title: z.string().optional(),
@@ -163,6 +165,7 @@ const uiMessagesSchema = lazySchema(() => {
163
165
  }),
164
166
  z.object({
165
167
  type: z.literal('dynamic-tool'),
168
+ dynamic: z.literal(false).optional(),
166
169
  toolName: z.string(),
167
170
  toolCallId: z.string(),
168
171
  title: z.string().optional(),
@@ -177,6 +180,7 @@ const uiMessagesSchema = lazySchema(() => {
177
180
  }),
178
181
  z.object({
179
182
  type: z.literal('dynamic-tool'),
183
+ dynamic: z.literal(false).optional(),
180
184
  toolName: z.string(),
181
185
  toolCallId: z.string(),
182
186
  title: z.string().optional(),
@@ -191,6 +195,7 @@ const uiMessagesSchema = lazySchema(() => {
191
195
  }),
192
196
  z.object({
193
197
  type: z.literal('dynamic-tool'),
198
+ dynamic: z.literal(false).optional(),
194
199
  toolName: z.string(),
195
200
  toolCallId: z.string(),
196
201
  title: z.string().optional(),
@@ -205,6 +210,7 @@ const uiMessagesSchema = lazySchema(() => {
205
210
  }),
206
211
  z.object({
207
212
  type: z.literal('dynamic-tool'),
213
+ dynamic: z.literal(false).optional(),
208
214
  toolName: z.string(),
209
215
  toolCallId: z.string(),
210
216
  title: z.string().optional(),
@@ -221,6 +227,7 @@ const uiMessagesSchema = lazySchema(() => {
221
227
  }),
222
228
  z.object({
223
229
  type: z.literal('dynamic-tool'),
230
+ dynamic: z.literal(false).optional(),
224
231
  toolName: z.string(),
225
232
  toolCallId: z.string(),
226
233
  title: z.string().optional(),
@@ -237,6 +244,7 @@ const uiMessagesSchema = lazySchema(() => {
237
244
  }),
238
245
  z.object({
239
246
  type: z.literal('dynamic-tool'),
247
+ dynamic: z.literal(false).optional(),
240
248
  toolName: z.string(),
241
249
  toolCallId: z.string(),
242
250
  title: z.string().optional(),
@@ -1,74 +0,0 @@
1
- ---
2
- title: experimental_evaluate
3
- description: Evaluate typed questions against shared state with an evaluation model.
4
- ---
5
-
6
- # `experimental_evaluate()`
7
-
8
- ```ts
9
- import { experimental_evaluate } from 'ai';
10
- ```
11
-
12
- Evaluates a nonempty map of `choice`, `score`, and `boolean` questions against one
13
- state. See [Evaluation](/docs/ai-sdk-core/evaluation) for examples and semantics.
14
-
15
- ## Parameters
16
-
17
- | Parameter | Type | Description |
18
- | ----------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
19
- | `model` | `Experimental_EvaluationModel` | Required experimental v4 model instance or a string ID resolved by Gateway or an explicitly configured evaluation-capable default provider. |
20
- | `state` | `string \| object \| array` | Required JSON-compatible shared state. |
21
- | `questions` | `Record<string, Experimental_EvaluationQuestion>` | Required nonempty question map. |
22
- | `maxRetries` | `number` | Nonnegative integer; defaults to 2. |
23
- | `abortSignal` | `AbortSignal` | Cancels evaluation. |
24
- | `headers` | `Record<string, string>` | Additional HTTP headers. |
25
- | `providerOptions` | `ProviderOptions` | Provider-specific options. |
26
- | `telemetry` | `TelemetryOptions` | Telemetry configuration, including per-call integrations, input/output recording, and a function ID. |
27
- | `runtimeContext` | `Record<string, unknown>` | Context available to lifecycle callbacks and selectively included in telemetry with `telemetry.includeRuntimeContext`. |
28
- | `onStart` | `(event: Experimental_EvaluateStartEvent) => void` | Called when the evaluation operation begins. |
29
- | `onEnd` | `(event: Experimental_EvaluateEndEvent) => void` | Called when the evaluation operation completes successfully. |
30
-
31
- See [Lifecycle Callbacks](/docs/ai-sdk-core/lifecycle-callbacks#experimental_evaluate)
32
- for the complete `onStart` and `onEnd` event fields.
33
-
34
- ## Result
35
-
36
- Returns `Promise<Experimental_EvaluationResult<QUESTIONS>>`:
37
-
38
- - `answers`: One typed answer per question ID, with literal Choice option inference.
39
- - `usage`: `inputTokens`, `outputTokens`, and `totalTokens`, each possibly undefined.
40
- - `warnings`: Provider warnings, also passed to the SDK warning logger.
41
- - `rounding`: Optional provider-declared decimal precision for probabilities and scores.
42
- - `providerMetadata`: Optional provider-specific metadata.
43
- - `response`: Timestamp, model ID, and optional response ID, headers, and body.
44
-
45
- ## Provider specification
46
-
47
- `Experimental_EvaluationModelV4` is exported from `@ai-sdk/provider` and declares
48
- `specificationVersion: 'v4'`, `provider`, `modelId`, `supportedQuestionTypes`, and
49
- `doEvaluate(options)`. Evaluation is isolated from stable `ProviderV4`.
50
-
51
- The public core types are `Experimental_EvaluationModel`,
52
- `Experimental_EvaluationQuestion`, `Experimental_EvaluationAnswer`, and
53
- `Experimental_EvaluationResult`. All evaluation-specific classes use the
54
- `Evaluation` prefix, with `Experimental_` aliases at package boundaries.
55
-
56
- ## Errors
57
-
58
- Unsupported types throw `Experimental_EvaluationUnsupportedQuestionTypeError`
59
- before provider I/O. Invalid inputs throw `InvalidArgumentError`; malformed
60
- answers throw `InvalidResponseDataError`. Invalid answers are not retried.
61
- Neither partial results nor missing probability synthesis are supported.
62
-
63
- ## Model resolution
64
-
65
- Use `registry.evaluationModel('provider:model')` or
66
- `customProvider({ evaluationModels: { alias: model } }).evaluationModel('alias')`
67
- to resolve models. Strings passed directly to `experimental_evaluate` use
68
- `globalThis.AI_SDK_DEFAULT_PROVIDER.evaluationModel(id)`, when available. Evaluation
69
- never implicitly falls back to Gateway.
70
-
71
- Resolution errors use the existing `NoSuchModelError` and `NoSuchProviderError`
72
- classes with `modelType: 'evaluationModel'`. Model instances and resolved models
73
- must implement v4; other versions throw `UnsupportedModelVersionError`.
74
- See [model resolution examples](/docs/ai-sdk-core/evaluation#model-aliases-and-registries).
@@ -1,31 +0,0 @@
1
- ---
2
- title: AI_EvaluationUnsupportedQuestionTypeError
3
- description: Identify an evaluation question type that a model does not support.
4
- ---
5
-
6
- # AI_EvaluationUnsupportedQuestionTypeError
7
-
8
- This experimental error identifies a question whose type is unsupported by an
9
- evaluation model. It is exported from `ai` and `@ai-sdk/provider` as
10
- `Experimental_EvaluationUnsupportedQuestionTypeError`.
11
-
12
- ## Properties
13
-
14
- - `questionId`: The ID of the unsupported question.
15
- - `questionType`: The requested question type.
16
- - `provider`: The provider of the evaluation model.
17
- - `modelId`: The evaluation model ID.
18
- - `message`: A description of the unsupported question and model. Providers can
19
- supply a custom message.
20
-
21
- ## Checking for this Error
22
-
23
- Use the marker-based `isInstance` check, which works across package copies:
24
-
25
- ```typescript
26
- import { Experimental_EvaluationUnsupportedQuestionTypeError as EvaluationUnsupportedQuestionTypeError } from 'ai';
27
-
28
- if (EvaluationUnsupportedQuestionTypeError.isInstance(error)) {
29
- console.log(error.questionId, error.questionType, error.modelId);
30
- }
31
- ```
@@ -1,131 +0,0 @@
1
- import type {
2
- Experimental_EvaluationModelV4CallOptions as EvaluationModelV4CallOptions,
3
- Experimental_EvaluationModelV4Result as EvaluationModelV4Result,
4
- } from '@ai-sdk/provider';
5
- import type { Context, ProviderOptions } from '@ai-sdk/provider-utils';
6
- import type { EvaluationQuestion, EvaluationResult } from './evaluation-result';
7
-
8
- /**
9
- * Event passed to the `onStart` callback for evaluation operations.
10
- *
11
- * Called when the operation begins, before the evaluation model is called.
12
- */
13
- export type EvaluateStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
14
- /** User-defined runtime context. */
15
- readonly runtimeContext: RUNTIME_CONTEXT;
16
-
17
- /** Unique identifier for this evaluation call, used to correlate events. */
18
- readonly callId: string;
19
-
20
- /** Identifies the operation type (`ai.evaluate`). */
21
- readonly operationId: 'ai.evaluate';
22
-
23
- /** The provider identifier. */
24
- readonly provider: string;
25
-
26
- /** The evaluation model identifier. */
27
- readonly modelId: string;
28
-
29
- /** The shared state being evaluated. */
30
- readonly state: EvaluationModelV4CallOptions['state'];
31
-
32
- /** The questions being evaluated against the shared state. */
33
- readonly questions: Readonly<Record<string, EvaluationQuestion>>;
34
-
35
- /** Maximum number of retries for the evaluation model call. */
36
- readonly maxRetries: number;
37
-
38
- /** Additional HTTP headers sent with the request. */
39
- readonly headers: Record<string, string> | undefined;
40
-
41
- /** Additional provider-specific options. */
42
- readonly providerOptions: ProviderOptions;
43
- };
44
-
45
- /**
46
- * Event passed to the `onEnd` callback for evaluation operations.
47
- *
48
- * Called when the operation completes successfully.
49
- */
50
- export type EvaluateEndEvent<RUNTIME_CONTEXT extends Context = Context> =
51
- EvaluateStartEvent<RUNTIME_CONTEXT> & {
52
- /** Exactly one typed answer per question ID. */
53
- readonly answers: EvaluationResult<
54
- Record<string, EvaluationQuestion>
55
- >['answers'];
56
-
57
- /** Token usage for the evaluation operation. */
58
- readonly usage: EvaluationResult<
59
- Record<string, EvaluationQuestion>
60
- >['usage'];
61
-
62
- /** Warnings from the evaluation model. */
63
- readonly warnings: EvaluationResult<
64
- Record<string, EvaluationQuestion>
65
- >['warnings'];
66
-
67
- /** Provider-declared decimal precision for probabilities and scores. */
68
- readonly rounding: EvaluationResult<
69
- Record<string, EvaluationQuestion>
70
- >['rounding'];
71
-
72
- /** Optional provider-specific metadata. */
73
- readonly providerMetadata: EvaluationResult<
74
- Record<string, EvaluationQuestion>
75
- >['providerMetadata'];
76
-
77
- /** Response metadata, including the resolved model ID and timestamp. */
78
- readonly response: EvaluationResult<
79
- Record<string, EvaluationQuestion>
80
- >['response'];
81
- };
82
-
83
- /**
84
- * Event fired when the evaluation model call begins.
85
- *
86
- * The logical model call includes any provider retries.
87
- */
88
- export type EvaluationModelCallStartEvent = {
89
- /** Unique identifier for the outer evaluation call. */
90
- readonly callId: string;
91
-
92
- /** Identifies the inner operation (`ai.evaluate.doEvaluate`). */
93
- readonly operationId: 'ai.evaluate.doEvaluate';
94
-
95
- /** The provider identifier. */
96
- readonly provider: string;
97
-
98
- /** The evaluation model identifier. */
99
- readonly modelId: string;
100
-
101
- /** The shared state being evaluated. */
102
- readonly state: EvaluationModelV4CallOptions['state'];
103
-
104
- /** The questions being evaluated against the shared state. */
105
- readonly questions: Readonly<Record<string, EvaluationQuestion>>;
106
- };
107
-
108
- /**
109
- * Event fired after the evaluation model response has been validated.
110
- *
111
- * Contains the result of the logical model call, including any retries.
112
- */
113
- export type EvaluationModelCallEndEvent = EvaluationModelCallStartEvent & {
114
- /** Exactly one answer per question ID. */
115
- readonly answers: EvaluationModelV4Result['answers'];
116
-
117
- /** Token usage reported by the evaluation model. */
118
- readonly usage?: EvaluationModelV4Result['usage'];
119
-
120
- /** Warnings from the evaluation model. */
121
- readonly warnings: EvaluationModelV4Result['warnings'];
122
-
123
- /** Provider-declared decimal precision for probabilities and scores. */
124
- readonly rounding?: EvaluationModelV4Result['rounding'];
125
-
126
- /** Optional provider-specific metadata. */
127
- readonly providerMetadata?: EvaluationModelV4Result['providerMetadata'];
128
-
129
- /** Optional raw response metadata from the provider. */
130
- readonly response?: EvaluationModelV4Result['response'];
131
- };
@@ -1,6 +0,0 @@
1
- import type { Experimental_EvaluationModelV4 as EvaluationModelV4 } from '@ai-sdk/provider';
2
-
3
- /** Structural extension; evaluation is not part of the stable provider contract. */
4
- export type EvaluationProvider = {
5
- evaluationModel?: (modelId: string) => EvaluationModelV4;
6
- };
@@ -1,39 +0,0 @@
1
- import type {
2
- Experimental_EvaluationModelV4 as EvaluationModelV4,
3
- Experimental_EvaluationModelV4Question as EvaluationModelV4Question,
4
- Experimental_EvaluationModelV4Result as EvaluationModelV4Result,
5
- } from '@ai-sdk/provider';
6
-
7
- export type EvaluationModel = string | EvaluationModelV4;
8
- export type EvaluationQuestion = EvaluationModelV4Question;
9
-
10
- export type EvaluationAnswer<QUESTION extends EvaluationQuestion> =
11
- QUESTION extends { type: 'choice'; criteria: infer CRITERIA }
12
- ? {
13
- type: 'choice';
14
- choice: Extract<keyof CRITERIA, string>;
15
- probabilities?: Record<Extract<keyof CRITERIA, string>, number>;
16
- }
17
- : QUESTION extends { type: 'score' }
18
- ? { type: 'score'; score: number; probabilities?: Record<string, number> }
19
- : { type: 'boolean'; probability: number };
20
-
21
- export type EvaluationResult<
22
- QUESTIONS extends Record<string, EvaluationQuestion>,
23
- > = {
24
- readonly answers: {
25
- [ID in keyof QUESTIONS]: EvaluationAnswer<QUESTIONS[ID]>;
26
- };
27
- readonly usage: {
28
- inputTokens: number | undefined;
29
- outputTokens: number | undefined;
30
- totalTokens: number | undefined;
31
- };
32
- readonly warnings: EvaluationModelV4Result['warnings'];
33
- readonly rounding: EvaluationModelV4Result['rounding'];
34
- readonly providerMetadata: EvaluationModelV4Result['providerMetadata'];
35
- readonly response: NonNullable<EvaluationModelV4Result['response']> & {
36
- timestamp: Date;
37
- modelId: string;
38
- };
39
- };
@@ -1,13 +0,0 @@
1
- export { evaluate as experimental_evaluate } from './evaluate';
2
- export type {
3
- EvaluateStartEvent as Experimental_EvaluateStartEvent,
4
- EvaluateEndEvent as Experimental_EvaluateEndEvent,
5
- EvaluationModelCallStartEvent as Experimental_EvaluationModelCallStartEvent,
6
- EvaluationModelCallEndEvent as Experimental_EvaluationModelCallEndEvent,
7
- } from './evaluate-events';
8
- export type {
9
- EvaluationModel as Experimental_EvaluationModel,
10
- EvaluationQuestion as Experimental_EvaluationQuestion,
11
- EvaluationAnswer as Experimental_EvaluationAnswer,
12
- EvaluationResult as Experimental_EvaluationResult,
13
- } from './evaluation-result';
@@ -1,27 +0,0 @@
1
- import type { Experimental_EvaluationModelV4 as EvaluationModelV4 } from '@ai-sdk/provider';
2
- import { notImplemented } from './not-implemented';
3
-
4
- export class EvaluationMockModelV4 implements EvaluationModelV4 {
5
- readonly specificationVersion = 'v4';
6
- readonly provider: string;
7
- readonly modelId: string;
8
- readonly supportedQuestionTypes: EvaluationModelV4['supportedQuestionTypes'];
9
- doEvaluate: EvaluationModelV4['doEvaluate'];
10
-
11
- constructor({
12
- provider = 'mock-provider',
13
- modelId = 'mock-model-id',
14
- supportedQuestionTypes = ['choice', 'score', 'boolean'],
15
- doEvaluate = notImplemented,
16
- }: {
17
- provider?: string;
18
- modelId?: string;
19
- supportedQuestionTypes?: EvaluationModelV4['supportedQuestionTypes'];
20
- doEvaluate?: EvaluationModelV4['doEvaluate'];
21
- } = {}) {
22
- this.provider = provider;
23
- this.modelId = modelId;
24
- this.supportedQuestionTypes = supportedQuestionTypes;
25
- this.doEvaluate = doEvaluate;
26
- }
27
- }