ai 7.0.102 → 7.0.103
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 +19 -0
- package/dist/index.d.ts +57 -3
- package/dist/index.js +427 -50
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +2 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +16 -2
- package/dist/test/index.js +17 -0
- package/dist/test/index.js.map +1 -1
- package/docs/03-ai-sdk-core/18-code-mode.mdx +39 -0
- package/docs/03-ai-sdk-core/32-evaluation.mdx +110 -0
- package/docs/03-ai-sdk-core/42-batch.mdx +1 -2
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +35 -0
- package/docs/06-advanced/11-secure-url-fetching.mdx +8 -2
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +54 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +12 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +12 -0
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +12 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +31 -0
- package/package.json +12 -12
- package/src/error/index.ts +1 -0
- package/src/evaluate/evaluate.ts +112 -0
- package/src/evaluate/evaluation-result.ts +39 -0
- package/src/evaluate/index.ts +7 -0
- package/src/evaluate/validate-evaluation.ts +298 -0
- package/src/generate-text/generate-text.ts +16 -12
- package/src/generate-text/stream-text.ts +6 -1
- package/src/generate-text/tool-caller-configuration.ts +58 -4
- package/src/index.ts +1 -0
- package/src/test/evaluation-mock-model-v4.ts +27 -0
- package/src/ui/convert-to-model-messages.ts +3 -0
- package/src/ui/process-ui-message-stream.ts +4 -0
- package/src/ui/ui-messages.ts +5 -1
- package/src/ui/validate-ui-messages.ts +3 -0
- package/src/ui/warn-if-ui-message-has-deprecated-raw-input.ts +36 -0
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
type ToolUIPart,
|
|
34
34
|
type UIMessage,
|
|
35
35
|
} from './ui-messages';
|
|
36
|
+
import { warnIfUIMessageHasDeprecatedRawInput } from './warn-if-ui-message-has-deprecated-raw-input';
|
|
36
37
|
/**
|
|
37
38
|
* Converts an array of UI messages from useChat into an array of ModelMessages that can be used
|
|
38
39
|
* with the AI functions (e.g. `streamText`, `generateText`).
|
|
@@ -56,6 +57,8 @@ export async function convertToModelMessages<UI_MESSAGE extends UIMessage>(
|
|
|
56
57
|
): Promise<ModelMessage[]> {
|
|
57
58
|
const modelMessages: ModelMessage[] = [];
|
|
58
59
|
|
|
60
|
+
warnIfUIMessageHasDeprecatedRawInput(messages);
|
|
61
|
+
|
|
59
62
|
if (options?.ignoreIncompleteToolCalls) {
|
|
60
63
|
messages = messages.map(message => ({
|
|
61
64
|
...message,
|
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
type UIMessage,
|
|
32
32
|
type UIMessagePart,
|
|
33
33
|
} from './ui-messages';
|
|
34
|
+
import { warnIfUIMessageHasDeprecatedRawInput } from './warn-if-ui-message-has-deprecated-raw-input';
|
|
35
|
+
|
|
34
36
|
export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
|
|
35
37
|
message: UI_MESSAGE;
|
|
36
38
|
activeTextParts: Record<string, TextUIPart>;
|
|
@@ -737,6 +739,8 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
737
739
|
providerMetadata: chunk.providerMetadata,
|
|
738
740
|
toolMetadata: chunk.toolMetadata,
|
|
739
741
|
});
|
|
742
|
+
|
|
743
|
+
warnIfUIMessageHasDeprecatedRawInput([state.message]);
|
|
740
744
|
}
|
|
741
745
|
|
|
742
746
|
write();
|
package/src/ui/ui-messages.ts
CHANGED
|
@@ -363,7 +363,11 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
363
363
|
| {
|
|
364
364
|
state: 'output-error';
|
|
365
365
|
input: asUITool<TOOL>['input'] | undefined;
|
|
366
|
-
|
|
366
|
+
/**
|
|
367
|
+
* @deprecated Use `input` instead. This field will be removed in the next
|
|
368
|
+
* major version.
|
|
369
|
+
*/
|
|
370
|
+
rawInput?: unknown;
|
|
367
371
|
output?: never;
|
|
368
372
|
errorText: string;
|
|
369
373
|
callProviderMetadata?: ProviderMetadata;
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
ToolUIPart,
|
|
21
21
|
UIMessage,
|
|
22
22
|
} from './ui-messages';
|
|
23
|
+
import { warnIfUIMessageHasDeprecatedRawInput } from './warn-if-ui-message-has-deprecated-raw-input';
|
|
23
24
|
|
|
24
25
|
const toolMetadataSchema: ZodType<JSONObject> = z.record(
|
|
25
26
|
z.string(),
|
|
@@ -484,6 +485,8 @@ async function safeValidateUIMessagesInternal<UI_MESSAGE extends UIMessage>(
|
|
|
484
485
|
schema: uiMessagesSchema,
|
|
485
486
|
});
|
|
486
487
|
|
|
488
|
+
warnIfUIMessageHasDeprecatedRawInput(validatedMessages);
|
|
489
|
+
|
|
487
490
|
if (metadataSchema) {
|
|
488
491
|
for (const [msgIdx, message] of validatedMessages.entries()) {
|
|
489
492
|
await validateTypes({
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { logWarnings } from '../logger/log-warnings';
|
|
2
|
+
|
|
3
|
+
const rawInputDeprecationWarning = {
|
|
4
|
+
type: 'deprecated',
|
|
5
|
+
setting: 'rawInput in output-error UI message parts',
|
|
6
|
+
message:
|
|
7
|
+
'Use the "input" field instead. The "rawInput" field will be removed in the next major version.',
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export function warnIfUIMessageHasDeprecatedRawInput(
|
|
11
|
+
messages: ReadonlyArray<{
|
|
12
|
+
parts: ReadonlyArray<unknown>;
|
|
13
|
+
}>,
|
|
14
|
+
): void {
|
|
15
|
+
const hasDeprecatedRawInput = messages.some(message =>
|
|
16
|
+
message.parts.some(
|
|
17
|
+
part =>
|
|
18
|
+
part != null &&
|
|
19
|
+
typeof part === 'object' &&
|
|
20
|
+
'type' in part &&
|
|
21
|
+
typeof part.type === 'string' &&
|
|
22
|
+
(part.type === 'dynamic-tool' || part.type.startsWith('tool-')) &&
|
|
23
|
+
'state' in part &&
|
|
24
|
+
part.state === 'output-error' &&
|
|
25
|
+
Object.prototype.hasOwnProperty.call(part, 'rawInput') &&
|
|
26
|
+
'rawInput' in part &&
|
|
27
|
+
part.rawInput !== undefined,
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (hasDeprecatedRawInput) {
|
|
32
|
+
logWarnings({
|
|
33
|
+
warnings: [rawInputDeprecationWarning],
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|