ai 7.0.110 → 7.0.112
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 +22 -0
- package/dist/index.d.ts +163 -41
- package/dist/index.js +262 -73
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +141 -2
- package/dist/internal/index.js +33 -4
- package/dist/internal/index.js.map +1 -1
- package/docs/03-ai-sdk-core/40-middleware.mdx +92 -7
- package/docs/03-ai-sdk-core/60-telemetry.mdx +56 -3
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +124 -2
- package/docs/06-advanced/02-stopping-streams.mdx +8 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +16 -9
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +9 -3
- package/package.json +12 -12
- package/src/batch/batch.ts +18 -3
- package/src/evaluate/evaluate-events.ts +131 -0
- package/src/evaluate/evaluate.ts +145 -40
- package/src/evaluate/index.ts +6 -0
- package/src/evaluate/restricted-telemetry-dispatcher.ts +46 -0
- package/src/generate-text/convert-language-model-content.ts +15 -6
- package/src/generate-text/generate-text.ts +7 -2
- package/src/generate-text/prune-messages.ts +3 -1
- package/src/generate-text/resolve-generated-file-data.ts +41 -0
- package/src/generate-text/stream-language-model-call.ts +5 -4
- package/src/prompt/convert-to-language-model-prompt.ts +12 -2
- package/src/prompt/file-part-data.ts +11 -1
- package/src/telemetry/create-telemetry-dispatcher.ts +12 -0
- package/src/telemetry/telemetry.ts +34 -0
- package/src/telemetry/tracing-channel.ts +2 -1
- package/src/ui/validate-ui-messages.ts +2 -2
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +5 -3
- package/src/ui-message-stream/ui-message-stream-on-end-callback.ts +8 -0
- package/src/ui-message-stream/ui-message-stream-outcome.ts +4 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
|
-
import { EmbeddingModelV4Embedding, LanguageModelV4Source, SharedV4Warning, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4ProviderMetadata, JSONObject, LanguageModelV4Usage, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, LanguageModelV4ToolResultOutput, LanguageModelV4ToolChoice, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool } from '@ai-sdk/provider';
|
|
2
|
+
import { EmbeddingModelV4Embedding, LanguageModelV4Source, SharedV4Warning, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4ProviderMetadata, JSONObject, LanguageModelV4Usage, Experimental_EvaluationModelV4Question, Experimental_EvaluationModelV4Result, Experimental_EvaluationModelV4CallOptions, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, LanguageModelV4ToolResultOutput, LanguageModelV4ToolChoice, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool } from '@ai-sdk/provider';
|
|
3
3
|
import { GatewayModelId } from '@ai-sdk/gateway';
|
|
4
4
|
import { ModelMessage, AssistantModelMessage, ToolModelMessage, Context, ProviderOptions, ToolSet, SystemModelMessage, InferToolSetContext, Arrayable, InferToolInput, InferToolOutput, ReasoningPart, ReasoningFilePart, MaybePromiseLike, ToolExecutionOptions, InferToolContext, HasRequiredKey, ToolResultOutput, Tool, Experimental_SandboxSession, ShouldRetryFunction, RetryFunction, FlexibleSchema, ToolApprovalRequest, ToolApprovalResponse, ToolResultPart } from '@ai-sdk/provider-utils';
|
|
5
5
|
export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';
|
|
@@ -351,6 +351,127 @@ type EmbeddingModelCallEndEvent = {
|
|
|
351
351
|
readonly usage: EmbeddingModelUsage;
|
|
352
352
|
};
|
|
353
353
|
|
|
354
|
+
type EvaluationQuestion = Experimental_EvaluationModelV4Question;
|
|
355
|
+
type EvaluationAnswer<QUESTION extends EvaluationQuestion> = QUESTION extends {
|
|
356
|
+
type: 'choice';
|
|
357
|
+
criteria: infer CRITERIA;
|
|
358
|
+
} ? {
|
|
359
|
+
type: 'choice';
|
|
360
|
+
choice: Extract<keyof CRITERIA, string>;
|
|
361
|
+
probabilities?: Record<Extract<keyof CRITERIA, string>, number>;
|
|
362
|
+
} : QUESTION extends {
|
|
363
|
+
type: 'score';
|
|
364
|
+
} ? {
|
|
365
|
+
type: 'score';
|
|
366
|
+
score: number;
|
|
367
|
+
probabilities?: Record<string, number>;
|
|
368
|
+
} : {
|
|
369
|
+
type: 'boolean';
|
|
370
|
+
probability: number;
|
|
371
|
+
};
|
|
372
|
+
type EvaluationResult<QUESTIONS extends Record<string, EvaluationQuestion>> = {
|
|
373
|
+
readonly answers: {
|
|
374
|
+
[ID in keyof QUESTIONS]: EvaluationAnswer<QUESTIONS[ID]>;
|
|
375
|
+
};
|
|
376
|
+
readonly usage: {
|
|
377
|
+
inputTokens: number | undefined;
|
|
378
|
+
outputTokens: number | undefined;
|
|
379
|
+
totalTokens: number | undefined;
|
|
380
|
+
};
|
|
381
|
+
readonly warnings: Experimental_EvaluationModelV4Result['warnings'];
|
|
382
|
+
readonly rounding: Experimental_EvaluationModelV4Result['rounding'];
|
|
383
|
+
readonly providerMetadata: Experimental_EvaluationModelV4Result['providerMetadata'];
|
|
384
|
+
readonly response: NonNullable<Experimental_EvaluationModelV4Result['response']> & {
|
|
385
|
+
timestamp: Date;
|
|
386
|
+
modelId: string;
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Event passed to the `onStart` callback for evaluation operations.
|
|
392
|
+
*
|
|
393
|
+
* Called when the operation begins, before the evaluation model is called.
|
|
394
|
+
*/
|
|
395
|
+
type EvaluateStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
396
|
+
/** User-defined runtime context. */
|
|
397
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
398
|
+
/** Unique identifier for this evaluation call, used to correlate events. */
|
|
399
|
+
readonly callId: string;
|
|
400
|
+
/** Identifies the operation type (`ai.evaluate`). */
|
|
401
|
+
readonly operationId: 'ai.evaluate';
|
|
402
|
+
/** The provider identifier. */
|
|
403
|
+
readonly provider: string;
|
|
404
|
+
/** The evaluation model identifier. */
|
|
405
|
+
readonly modelId: string;
|
|
406
|
+
/** The shared state being evaluated. */
|
|
407
|
+
readonly state: Experimental_EvaluationModelV4CallOptions['state'];
|
|
408
|
+
/** The questions being evaluated against the shared state. */
|
|
409
|
+
readonly questions: Readonly<Record<string, EvaluationQuestion>>;
|
|
410
|
+
/** Maximum number of retries for the evaluation model call. */
|
|
411
|
+
readonly maxRetries: number;
|
|
412
|
+
/** Additional HTTP headers sent with the request. */
|
|
413
|
+
readonly headers: Record<string, string> | undefined;
|
|
414
|
+
/** Additional provider-specific options. */
|
|
415
|
+
readonly providerOptions: ProviderOptions;
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* Event passed to the `onEnd` callback for evaluation operations.
|
|
419
|
+
*
|
|
420
|
+
* Called when the operation completes successfully.
|
|
421
|
+
*/
|
|
422
|
+
type EvaluateEndEvent<RUNTIME_CONTEXT extends Context = Context> = EvaluateStartEvent<RUNTIME_CONTEXT> & {
|
|
423
|
+
/** Exactly one typed answer per question ID. */
|
|
424
|
+
readonly answers: EvaluationResult<Record<string, EvaluationQuestion>>['answers'];
|
|
425
|
+
/** Token usage for the evaluation operation. */
|
|
426
|
+
readonly usage: EvaluationResult<Record<string, EvaluationQuestion>>['usage'];
|
|
427
|
+
/** Warnings from the evaluation model. */
|
|
428
|
+
readonly warnings: EvaluationResult<Record<string, EvaluationQuestion>>['warnings'];
|
|
429
|
+
/** Provider-declared decimal precision for probabilities and scores. */
|
|
430
|
+
readonly rounding: EvaluationResult<Record<string, EvaluationQuestion>>['rounding'];
|
|
431
|
+
/** Optional provider-specific metadata. */
|
|
432
|
+
readonly providerMetadata: EvaluationResult<Record<string, EvaluationQuestion>>['providerMetadata'];
|
|
433
|
+
/** Response metadata, including the resolved model ID and timestamp. */
|
|
434
|
+
readonly response: EvaluationResult<Record<string, EvaluationQuestion>>['response'];
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* Event fired when the evaluation model call begins.
|
|
438
|
+
*
|
|
439
|
+
* The logical model call includes any provider retries.
|
|
440
|
+
*/
|
|
441
|
+
type EvaluationModelCallStartEvent = {
|
|
442
|
+
/** Unique identifier for the outer evaluation call. */
|
|
443
|
+
readonly callId: string;
|
|
444
|
+
/** Identifies the inner operation (`ai.evaluate.doEvaluate`). */
|
|
445
|
+
readonly operationId: 'ai.evaluate.doEvaluate';
|
|
446
|
+
/** The provider identifier. */
|
|
447
|
+
readonly provider: string;
|
|
448
|
+
/** The evaluation model identifier. */
|
|
449
|
+
readonly modelId: string;
|
|
450
|
+
/** The shared state being evaluated. */
|
|
451
|
+
readonly state: Experimental_EvaluationModelV4CallOptions['state'];
|
|
452
|
+
/** The questions being evaluated against the shared state. */
|
|
453
|
+
readonly questions: Readonly<Record<string, EvaluationQuestion>>;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Event fired after the evaluation model response has been validated.
|
|
457
|
+
*
|
|
458
|
+
* Contains the result of the logical model call, including any retries.
|
|
459
|
+
*/
|
|
460
|
+
type EvaluationModelCallEndEvent = EvaluationModelCallStartEvent & {
|
|
461
|
+
/** Exactly one answer per question ID. */
|
|
462
|
+
readonly answers: Experimental_EvaluationModelV4Result['answers'];
|
|
463
|
+
/** Token usage reported by the evaluation model. */
|
|
464
|
+
readonly usage?: Experimental_EvaluationModelV4Result['usage'];
|
|
465
|
+
/** Warnings from the evaluation model. */
|
|
466
|
+
readonly warnings: Experimental_EvaluationModelV4Result['warnings'];
|
|
467
|
+
/** Provider-declared decimal precision for probabilities and scores. */
|
|
468
|
+
readonly rounding?: Experimental_EvaluationModelV4Result['rounding'];
|
|
469
|
+
/** Optional provider-specific metadata. */
|
|
470
|
+
readonly providerMetadata?: Experimental_EvaluationModelV4Result['providerMetadata'];
|
|
471
|
+
/** Optional raw response metadata from the provider. */
|
|
472
|
+
readonly response?: Experimental_EvaluationModelV4Result['response'];
|
|
473
|
+
};
|
|
474
|
+
|
|
354
475
|
/**
|
|
355
476
|
* Model-facing generation controls. These settings influence how the model
|
|
356
477
|
* generates its response (token limits, sampling, penalties, stop sequences,
|
|
@@ -2345,7 +2466,7 @@ type RerankingModelCallEndEvent = {
|
|
|
2345
2466
|
}>;
|
|
2346
2467
|
};
|
|
2347
2468
|
|
|
2348
|
-
type TelemetryTracingEventType = 'generateText' | 'streamText' | 'step' | 'languageModelCall' | 'executeTool' | 'embed' | 'embedMany' | 'rerank';
|
|
2469
|
+
type TelemetryTracingEventType = 'generateText' | 'streamText' | 'step' | 'languageModelCall' | 'executeTool' | 'embed' | 'embedMany' | 'rerank' | 'experimental_evaluate';
|
|
2349
2470
|
|
|
2350
2471
|
type TracingChannelContext = {
|
|
2351
2472
|
run<T>(execute: () => T): T;
|
|
@@ -2388,6 +2509,10 @@ interface TelemetryDispatcher {
|
|
|
2388
2509
|
onEmbedEnd?: Callback<EmbeddingModelCallEndEvent>;
|
|
2389
2510
|
onRerankStart?: Callback<RerankingModelCallStartEvent>;
|
|
2390
2511
|
onRerankEnd?: Callback<RerankingModelCallEndEvent>;
|
|
2512
|
+
experimental_onEvaluateStart?: Callback<EvaluateStartEvent>;
|
|
2513
|
+
experimental_onEvaluationModelCallStart?: Callback<EvaluationModelCallStartEvent>;
|
|
2514
|
+
experimental_onEvaluationModelCallEnd?: Callback<EvaluationModelCallEndEvent>;
|
|
2515
|
+
experimental_onEvaluateEnd?: Callback<EvaluateEndEvent>;
|
|
2391
2516
|
onEnd?: Callback<OperationEndEvent>;
|
|
2392
2517
|
onAbort?: Callback<GenerateTextAbortEvent<ToolSet>>;
|
|
2393
2518
|
onError?: Callback<unknown>;
|
|
@@ -2489,6 +2614,20 @@ interface Telemetry {
|
|
|
2489
2614
|
* Contains the ranking results from the model response.
|
|
2490
2615
|
*/
|
|
2491
2616
|
onRerankEnd?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>;
|
|
2617
|
+
/** Called when an experimental evaluation operation begins. */
|
|
2618
|
+
experimental_onEvaluateStart?: Callback<InferTelemetryEvent<EvaluateStartEvent>>;
|
|
2619
|
+
/**
|
|
2620
|
+
* Called immediately before an experimental evaluation model call begins.
|
|
2621
|
+
* The logical model call includes any provider retries.
|
|
2622
|
+
*/
|
|
2623
|
+
experimental_onEvaluationModelCallStart?: Callback<InferTelemetryEvent<EvaluationModelCallStartEvent>>;
|
|
2624
|
+
/**
|
|
2625
|
+
* Called after an experimental evaluation model response has been validated.
|
|
2626
|
+
* The logical model call includes any provider retries.
|
|
2627
|
+
*/
|
|
2628
|
+
experimental_onEvaluationModelCallEnd?: Callback<InferTelemetryEvent<EvaluationModelCallEndEvent>>;
|
|
2629
|
+
/** Called when an experimental evaluation operation completes. */
|
|
2630
|
+
experimental_onEvaluateEnd?: Callback<InferTelemetryEvent<EvaluateEndEvent>>;
|
|
2492
2631
|
/**
|
|
2493
2632
|
* Called when an operation completes. Fired for text generation
|
|
2494
2633
|
* (generateText/streamText), object generation (generateObject/streamObject),
|
package/dist/internal/index.js
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
} from "@ai-sdk/provider-utils";
|
|
92
92
|
|
|
93
93
|
// src/version.ts
|
|
94
|
-
var VERSION = true ? "7.0.
|
|
94
|
+
var VERSION = true ? "7.0.112" : "0.0.0-test";
|
|
95
95
|
|
|
96
96
|
// src/util/download/download.ts
|
|
97
97
|
var download = async ({
|
|
@@ -241,6 +241,13 @@ function convertUrlToFilePartData(url) {
|
|
|
241
241
|
}
|
|
242
242
|
return { data: { type: "url", url }, mediaType: void 0 };
|
|
243
243
|
}
|
|
244
|
+
function convertUrlStringToFilePartData(content) {
|
|
245
|
+
const result = convertUrlToFilePartData(new URL(content));
|
|
246
|
+
if (result.data.type === "url" && result.data.url.toString() !== content) {
|
|
247
|
+
result.data.originalUrl = content;
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
244
251
|
function convertInlineDataToFilePartData(content) {
|
|
245
252
|
if (content instanceof Uint8Array) {
|
|
246
253
|
return { data: { type: "data", data: content }, mediaType: void 0 };
|
|
@@ -292,7 +299,7 @@ function convertToLanguageModelV4FilePart(content) {
|
|
|
292
299
|
}
|
|
293
300
|
if (typeof content === "string") {
|
|
294
301
|
try {
|
|
295
|
-
return
|
|
302
|
+
return convertUrlStringToFilePartData(content);
|
|
296
303
|
} catch (e) {
|
|
297
304
|
return convertInlineDataToFilePartData(content);
|
|
298
305
|
}
|
|
@@ -893,6 +900,7 @@ function mapToolResultOutput({
|
|
|
893
900
|
}
|
|
894
901
|
case "file-url": {
|
|
895
902
|
const mediaType = (_a12 = item.mediaType) != null ? _a12 : getMediaTypeFromUrl(item.url);
|
|
903
|
+
const url = new URL(item.url);
|
|
896
904
|
let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
|
|
897
905
|
if (!item.mediaType) {
|
|
898
906
|
const inferenceSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
|
|
@@ -905,7 +913,11 @@ function mapToolResultOutput({
|
|
|
905
913
|
});
|
|
906
914
|
return {
|
|
907
915
|
type: "file",
|
|
908
|
-
data: {
|
|
916
|
+
data: {
|
|
917
|
+
type: "url",
|
|
918
|
+
url,
|
|
919
|
+
...url.toString() !== item.url ? { originalUrl: item.url } : {}
|
|
920
|
+
},
|
|
909
921
|
mediaType,
|
|
910
922
|
providerOptions: item.providerOptions
|
|
911
923
|
};
|
|
@@ -961,6 +973,7 @@ function mapToolResultOutput({
|
|
|
961
973
|
};
|
|
962
974
|
}
|
|
963
975
|
case "image-url": {
|
|
976
|
+
const url = new URL(item.url);
|
|
964
977
|
warnings.push({
|
|
965
978
|
type: "deprecated",
|
|
966
979
|
setting: '"tool-result" content of type "image-url"',
|
|
@@ -968,7 +981,11 @@ function mapToolResultOutput({
|
|
|
968
981
|
});
|
|
969
982
|
return {
|
|
970
983
|
type: "file",
|
|
971
|
-
data: {
|
|
984
|
+
data: {
|
|
985
|
+
type: "url",
|
|
986
|
+
url,
|
|
987
|
+
...url.toString() !== item.url ? { originalUrl: item.url } : {}
|
|
988
|
+
},
|
|
972
989
|
mediaType: "image",
|
|
973
990
|
providerOptions: item.providerOptions
|
|
974
991
|
};
|
|
@@ -2723,6 +2740,18 @@ function createTelemetryDispatcher({
|
|
|
2723
2740
|
onEmbedEnd: mergeTelemetryCallback("onEmbedEnd"),
|
|
2724
2741
|
onRerankStart: mergeTelemetryCallback("onRerankStart"),
|
|
2725
2742
|
onRerankEnd: mergeTelemetryCallback("onRerankEnd"),
|
|
2743
|
+
experimental_onEvaluateStart: mergeTelemetryCallback(
|
|
2744
|
+
"experimental_onEvaluateStart"
|
|
2745
|
+
),
|
|
2746
|
+
experimental_onEvaluationModelCallStart: mergeTelemetryCallback(
|
|
2747
|
+
"experimental_onEvaluationModelCallStart"
|
|
2748
|
+
),
|
|
2749
|
+
experimental_onEvaluationModelCallEnd: mergeTelemetryCallback(
|
|
2750
|
+
"experimental_onEvaluationModelCallEnd"
|
|
2751
|
+
),
|
|
2752
|
+
experimental_onEvaluateEnd: mergeTelemetryCallback(
|
|
2753
|
+
"experimental_onEvaluateEnd"
|
|
2754
|
+
),
|
|
2726
2755
|
onEnd: mergeTelemetryCallback("onEnd"),
|
|
2727
2756
|
onAbort: mergeTelemetryCallback("onAbort"),
|
|
2728
2757
|
onError: mergeTelemetryCallback("onError"),
|