ai 6.0.170 → 6.0.172
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 +24 -0
- package/dist/index.d.mts +792 -792
- package/dist/index.d.ts +792 -792
- package/dist/index.js +77 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -15
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +16 -17
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +2 -4
- package/dist/internal/index.mjs.map +1 -1
- package/dist/test/index.d.mts +18 -18
- package/dist/test/index.d.ts +18 -18
- package/dist/test/index.js +24 -22
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +22 -22
- package/dist/test/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/agent/agent.ts +7 -7
- package/src/agent/create-agent-ui-stream-response.ts +10 -7
- package/src/agent/create-agent-ui-stream.ts +11 -8
- package/src/agent/infer-agent-tools.ts +1 -1
- package/src/agent/infer-agent-ui-message.ts +2 -2
- package/src/agent/pipe-agent-ui-stream-to-response.ts +11 -8
- package/src/agent/tool-loop-agent-settings.ts +12 -12
- package/src/agent/tool-loop-agent.ts +27 -10
- package/src/embed/embed-many-result.ts +3 -4
- package/src/embed/embed-many.ts +8 -5
- package/src/embed/embed-result.ts +3 -4
- package/src/embed/embed.ts +7 -4
- package/src/error/invalid-stream-part-error.ts +1 -1
- package/src/error/no-image-generated-error.ts +1 -1
- package/src/error/no-object-generated-error.ts +3 -3
- package/src/error/no-speech-generated-error.ts +1 -1
- package/src/error/no-transcript-generated-error.ts +1 -1
- package/src/error/no-video-generated-error.ts +1 -1
- package/src/error/tool-call-repair-error.ts +2 -2
- package/src/error/verify-no-object-generated-error.ts +1 -1
- package/src/generate-image/generate-image-result.ts +5 -5
- package/src/generate-image/generate-image.ts +8 -8
- package/src/generate-image/index.ts +3 -2
- package/src/generate-object/generate-object-result.ts +2 -2
- package/src/generate-object/generate-object.ts +15 -15
- package/src/generate-object/inject-json-instruction.ts +1 -1
- package/src/generate-object/output-strategy.ts +10 -10
- package/src/generate-object/parse-and-validate-object-result.ts +1 -1
- package/src/generate-object/repair-text.ts +1 -1
- package/src/generate-object/stream-object-result.ts +4 -4
- package/src/generate-object/stream-object.ts +21 -18
- package/src/generate-object/validate-object-generation-input.ts +1 -1
- package/src/generate-speech/generate-speech-result.ts +4 -4
- package/src/generate-speech/generate-speech.ts +10 -7
- package/src/generate-speech/generated-audio-file.ts +1 -1
- package/src/generate-text/collect-tool-approvals.ts +4 -4
- package/src/generate-text/content-part.ts +9 -9
- package/src/generate-text/execute-tool-call.ts +9 -9
- package/src/generate-text/extract-reasoning-content.ts +1 -1
- package/src/generate-text/extract-text-content.ts +4 -1
- package/src/generate-text/generate-text-result.ts +19 -15
- package/src/generate-text/generate-text.ts +26 -26
- package/src/generate-text/is-approval-needed.ts +3 -3
- package/src/generate-text/output-utils.ts +1 -1
- package/src/generate-text/output.ts +8 -8
- package/src/generate-text/parse-tool-call.ts +6 -6
- package/src/generate-text/prepare-step.ts +3 -3
- package/src/generate-text/prune-messages.ts +1 -1
- package/src/generate-text/reasoning-output.ts +1 -1
- package/src/generate-text/reasoning.ts +1 -1
- package/src/generate-text/response-message.ts +1 -1
- package/src/generate-text/run-tools-transformation.ts +26 -16
- package/src/generate-text/smooth-stream.ts +6 -4
- package/src/generate-text/step-result.ts +14 -10
- package/src/generate-text/stop-condition.ts +2 -2
- package/src/generate-text/stream-text-result.ts +29 -25
- package/src/generate-text/stream-text.ts +38 -35
- package/src/generate-text/to-response-messages.ts +3 -3
- package/src/generate-text/tool-approval-request-output.ts +2 -2
- package/src/generate-text/tool-call-repair-function.ts +5 -5
- package/src/generate-text/tool-call.ts +4 -4
- package/src/generate-text/tool-error.ts +4 -4
- package/src/generate-text/tool-output-denied.ts +2 -2
- package/src/generate-text/tool-output.ts +3 -3
- package/src/generate-text/tool-result.ts +4 -4
- package/src/generate-text/tool-set.ts +1 -1
- package/src/generate-video/generate-video-result.ts +4 -4
- package/src/global.ts +2 -2
- package/src/index.ts +3 -3
- package/src/logger/log-warnings.ts +1 -1
- package/src/middleware/add-tool-input-examples-middleware.ts +2 -2
- package/src/middleware/default-embedding-settings-middleware.ts +2 -2
- package/src/middleware/default-settings-middleware.ts +2 -2
- package/src/middleware/extract-json-middleware.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +1 -1
- package/src/middleware/simulate-streaming-middleware.ts +1 -1
- package/src/middleware/wrap-embedding-model.ts +2 -2
- package/src/middleware/wrap-image-model.ts +2 -2
- package/src/middleware/wrap-language-model.ts +2 -2
- package/src/middleware/wrap-provider.ts +2 -2
- package/src/model/as-embedding-model-v3.ts +1 -1
- package/src/model/as-image-model-v3.ts +1 -1
- package/src/model/as-language-model-v3.ts +1 -1
- package/src/model/as-provider-v3.ts +1 -1
- package/src/model/as-speech-model-v3.ts +1 -1
- package/src/model/as-transcription-model-v3.ts +4 -1
- package/src/model/resolve-model.ts +8 -8
- package/src/prompt/content-part.ts +1 -1
- package/src/prompt/convert-to-language-model-prompt.ts +12 -12
- package/src/prompt/create-tool-model-output.ts +2 -2
- package/src/prompt/data-content.ts +2 -2
- package/src/prompt/message-conversion-error.ts +1 -1
- package/src/prompt/message.ts +1 -1
- package/src/prompt/prepare-call-settings.ts +1 -1
- package/src/prompt/prepare-tools-and-tool-choice.ts +3 -3
- package/src/prompt/prompt.ts +1 -1
- package/src/prompt/standardize-prompt.ts +3 -3
- package/src/registry/custom-provider.ts +9 -9
- package/src/registry/provider-registry.ts +8 -8
- package/src/rerank/rerank-result.ts +1 -1
- package/src/rerank/rerank.ts +5 -5
- package/src/telemetry/assemble-operation-name.ts +1 -1
- package/src/telemetry/get-base-telemetry-attributes.ts +3 -3
- package/src/telemetry/get-tracer.ts +1 -1
- package/src/telemetry/noop-tracer.ts +1 -1
- package/src/telemetry/record-span.ts +3 -3
- package/src/telemetry/stringify-for-telemetry.ts +1 -1
- package/src/telemetry/telemetry-integration.ts +1 -1
- package/src/telemetry/telemetry-settings.ts +1 -1
- package/src/test/mock-embedding-model-v2.ts +1 -1
- package/src/test/mock-embedding-model-v3.ts +1 -1
- package/src/test/mock-image-model-v2.ts +1 -1
- package/src/test/mock-image-model-v3.ts +1 -1
- package/src/test/mock-language-model-v2.ts +1 -1
- package/src/test/mock-language-model-v3.ts +1 -1
- package/src/test/mock-provider-v2.ts +6 -6
- package/src/test/mock-provider-v3.ts +7 -7
- package/src/test/mock-reranking-model-v3.ts +1 -1
- package/src/test/mock-server-response.ts +1 -1
- package/src/test/mock-speech-model-v2.ts +1 -1
- package/src/test/mock-speech-model-v3.ts +1 -1
- package/src/test/mock-tracer.ts +1 -1
- package/src/test/mock-transcription-model-v2.ts +1 -1
- package/src/test/mock-transcription-model-v3.ts +1 -1
- package/src/test/mock-video-model-v3.ts +1 -1
- package/src/text-stream/pipe-text-stream-to-response.ts +1 -1
- package/src/transcribe/transcribe-result.ts +3 -3
- package/src/transcribe/transcribe.ts +10 -7
- package/src/types/embedding-model-middleware.ts +1 -1
- package/src/types/embedding-model.ts +1 -1
- package/src/types/image-model-middleware.ts +1 -1
- package/src/types/image-model.ts +1 -1
- package/src/types/json-value.ts +1 -1
- package/src/types/language-model-middleware.ts +1 -1
- package/src/types/language-model.ts +2 -2
- package/src/types/provider-metadata.ts +1 -1
- package/src/types/provider.ts +4 -4
- package/src/types/reranking-model.ts +1 -1
- package/src/types/speech-model.ts +1 -1
- package/src/types/transcription-model.ts +4 -1
- package/src/types/usage.ts +1 -1
- package/src/types/video-model.ts +1 -1
- package/src/types/warning.ts +1 -1
- package/src/ui/call-completion-api.ts +2 -2
- package/src/ui/chat-transport.ts +3 -3
- package/src/ui/chat.ts +10 -10
- package/src/ui/convert-file-list-to-file-ui-parts.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +16 -16
- package/src/ui/default-chat-transport.ts +4 -4
- package/src/ui/direct-chat-transport.ts +7 -7
- package/src/ui/http-chat-transport.ts +5 -5
- package/src/ui/process-ui-message-stream.ts +19 -19
- package/src/ui/text-stream-chat-transport.ts +3 -3
- package/src/ui/transform-text-to-ui-message-stream.ts +1 -1
- package/src/ui/ui-messages.ts +5 -5
- package/src/ui/use-completion.ts +1 -1
- package/src/ui/validate-ui-messages.ts +3 -3
- package/src/ui-message-stream/create-ui-message-stream-response.ts +2 -2
- package/src/ui-message-stream/create-ui-message-stream.ts +6 -6
- package/src/ui-message-stream/get-response-ui-message-id.ts +2 -2
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +6 -6
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -3
- package/src/ui-message-stream/read-ui-message-stream.ts +4 -4
- package/src/ui-message-stream/ui-message-chunks.ts +4 -4
- package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +2 -2
- package/src/ui-message-stream/ui-message-stream-on-step-finish-callback.ts +1 -1
- package/src/ui-message-stream/ui-message-stream-writer.ts +3 -3
- package/src/util/create-resolvable-promise.ts +1 -1
- package/src/util/deep-partial.ts +1 -1
- package/src/util/download/download.ts +0 -2
- package/src/util/merge-objects.ts +5 -0
- package/src/util/parse-partial-json.ts +1 -1
- package/src/util/prepare-retries.ts +1 -1
- package/src/util/serial-job-executor.ts +1 -1
- package/src/util/write-to-server-response.ts +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
|
+
import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, EmbeddingModelV3Middleware, ImageModelV3, ImageModelV2, ImageModelV3ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV3Middleware, JSONValue as JSONValue$1, LanguageModelV3, LanguageModelV2, SharedV3Warning, LanguageModelV3Source, LanguageModelV3Middleware, RerankingModelV3, SharedV3ProviderMetadata, SpeechModelV3, SpeechModelV2, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV3Usage, AISDKError, LanguageModelV3ToolCall, JSONSchema7, LanguageModelV3CallOptions, LanguageModelV3ToolChoice, ProviderV3, JSONParseError, TypeValidationError, Experimental_VideoModelV3, EmbeddingModelV3CallOptions, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
|
3
|
+
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
1
4
|
import { GatewayModelId } from '@ai-sdk/gateway';
|
|
2
5
|
export { GatewayModelId, createGateway, gateway } from '@ai-sdk/gateway';
|
|
3
6
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
|
-
import {
|
|
7
|
+
import { FlexibleSchema, InferSchema, SystemModelMessage, ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, ProviderOptions, UserModelMessage, IdGenerator, ToolCall, MaybePromiseLike, TextPart, FilePart, Resolvable, FetchFunction, DataContent } from '@ai-sdk/provider-utils';
|
|
5
8
|
export { AssistantContent, AssistantModelMessage, DataContent, DownloadError, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolExecutionOptions, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
|
|
6
|
-
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
7
|
-
import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, EmbeddingModelV3Middleware, ImageModelV3, ImageModelV2, ImageModelV3ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV3Middleware, JSONValue as JSONValue$1, LanguageModelV3, LanguageModelV2, SharedV3Warning, LanguageModelV3Source, LanguageModelV3Middleware, RerankingModelV3, SharedV3ProviderMetadata, SpeechModelV3, SpeechModelV2, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV3Usage, LanguageModelV3ToolChoice, AISDKError, LanguageModelV3ToolCall, JSONSchema7, LanguageModelV3CallOptions, JSONParseError, TypeValidationError, Experimental_VideoModelV3, EmbeddingModelV3CallOptions, ProviderV3, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
|
8
|
-
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
9
9
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
|
10
10
|
import { ServerResponse } from 'node:http';
|
|
11
11
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
|
@@ -344,241 +344,31 @@ type ImageModelUsage = ImageModelV3Usage;
|
|
|
344
344
|
type Warning = SharedV3Warning;
|
|
345
345
|
|
|
346
346
|
/**
|
|
347
|
-
* A
|
|
348
|
-
*/
|
|
349
|
-
interface GeneratedFile {
|
|
350
|
-
/**
|
|
351
|
-
* File as a base64 encoded string.
|
|
352
|
-
*/
|
|
353
|
-
readonly base64: string;
|
|
354
|
-
/**
|
|
355
|
-
* File as a Uint8Array.
|
|
356
|
-
*/
|
|
357
|
-
readonly uint8Array: Uint8Array;
|
|
358
|
-
/**
|
|
359
|
-
* The IANA media type of the file.
|
|
360
|
-
*
|
|
361
|
-
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
362
|
-
*/
|
|
363
|
-
readonly mediaType: string;
|
|
364
|
-
}
|
|
365
|
-
declare class DefaultGeneratedFile implements GeneratedFile {
|
|
366
|
-
private base64Data;
|
|
367
|
-
private uint8ArrayData;
|
|
368
|
-
readonly mediaType: string;
|
|
369
|
-
constructor({ data, mediaType, }: {
|
|
370
|
-
data: string | Uint8Array;
|
|
371
|
-
mediaType: string;
|
|
372
|
-
});
|
|
373
|
-
get base64(): string;
|
|
374
|
-
get uint8Array(): Uint8Array<ArrayBufferLike>;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
347
|
+
* A function for logging warnings.
|
|
379
348
|
*
|
|
380
|
-
*
|
|
349
|
+
* You can assign it to the `AI_SDK_LOG_WARNINGS` global variable to use it as the default warning logger.
|
|
381
350
|
*
|
|
382
351
|
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* globalThis.AI_SDK_LOG_WARNINGS = (options) => {
|
|
354
|
+
* console.log('WARNINGS:', options.warnings, options.provider, options.model);
|
|
355
|
+
* };
|
|
383
356
|
* ```
|
|
384
|
-
* // data.json
|
|
385
|
-
* {
|
|
386
|
-
* 'foo': 1,
|
|
387
|
-
* 'bar': 2,
|
|
388
|
-
* 'biz': 3
|
|
389
|
-
* }
|
|
390
|
-
*
|
|
391
|
-
* // main.ts
|
|
392
|
-
* import type {ValueOf} from 'type-fest';
|
|
393
|
-
* import data = require('./data.json');
|
|
394
|
-
*
|
|
395
|
-
* export function getData(name: string): ValueOf<typeof data> {
|
|
396
|
-
* return data[name];
|
|
397
|
-
* }
|
|
398
|
-
*
|
|
399
|
-
* export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
|
400
|
-
* return data[name];
|
|
401
|
-
* }
|
|
402
|
-
*
|
|
403
|
-
* // file.ts
|
|
404
|
-
* import {getData, onlyBar} from './main';
|
|
405
|
-
*
|
|
406
|
-
* getData('foo');
|
|
407
|
-
* //=> 1
|
|
408
|
-
*
|
|
409
|
-
* onlyBar('foo');
|
|
410
|
-
* //=> TypeError ...
|
|
411
|
-
*
|
|
412
|
-
* onlyBar('bar');
|
|
413
|
-
* //=> 2
|
|
414
|
-
* ```
|
|
415
|
-
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
|
416
|
-
*/
|
|
417
|
-
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
418
|
-
|
|
419
|
-
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
|
|
420
|
-
|
|
421
|
-
type BaseToolCall = {
|
|
422
|
-
type: 'tool-call';
|
|
423
|
-
toolCallId: string;
|
|
424
|
-
providerExecuted?: boolean;
|
|
425
|
-
providerMetadata?: ProviderMetadata;
|
|
426
|
-
};
|
|
427
|
-
type StaticToolCall<TOOLS extends ToolSet> = ValueOf<{
|
|
428
|
-
[NAME in keyof TOOLS]: BaseToolCall & {
|
|
429
|
-
toolName: NAME & string;
|
|
430
|
-
input: TOOLS[NAME] extends Tool<infer PARAMETERS> ? PARAMETERS : never;
|
|
431
|
-
dynamic?: false | undefined;
|
|
432
|
-
invalid?: false | undefined;
|
|
433
|
-
error?: never;
|
|
434
|
-
title?: string;
|
|
435
|
-
};
|
|
436
|
-
}>;
|
|
437
|
-
type DynamicToolCall = BaseToolCall & {
|
|
438
|
-
toolName: string;
|
|
439
|
-
input: unknown;
|
|
440
|
-
dynamic: true;
|
|
441
|
-
title?: string;
|
|
442
|
-
/**
|
|
443
|
-
* True if this is caused by an unparsable tool call or
|
|
444
|
-
* a tool that does not exist.
|
|
445
|
-
*/
|
|
446
|
-
invalid?: boolean;
|
|
447
|
-
/**
|
|
448
|
-
* The error that caused the tool call to be invalid.
|
|
449
|
-
*/
|
|
450
|
-
error?: unknown;
|
|
451
|
-
};
|
|
452
|
-
type TypedToolCall<TOOLS extends ToolSet> = StaticToolCall<TOOLS> | DynamicToolCall;
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Output part that indicates that a tool approval request has been made.
|
|
456
|
-
*
|
|
457
|
-
* The tool approval request can be approved or denied in the next tool message.
|
|
458
357
|
*/
|
|
459
|
-
type
|
|
460
|
-
type: 'tool-approval-request';
|
|
461
|
-
/**
|
|
462
|
-
* ID of the tool approval request.
|
|
463
|
-
*/
|
|
464
|
-
approvalId: string;
|
|
358
|
+
type LogWarningsFunction = (options: {
|
|
465
359
|
/**
|
|
466
|
-
*
|
|
360
|
+
* The warnings returned by the model provider.
|
|
467
361
|
*/
|
|
468
|
-
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* Reasoning output of a text generation. It contains a reasoning.
|
|
473
|
-
*/
|
|
474
|
-
interface ReasoningOutput {
|
|
475
|
-
type: 'reasoning';
|
|
362
|
+
warnings: Warning[];
|
|
476
363
|
/**
|
|
477
|
-
* The
|
|
364
|
+
* The provider id used for the call.
|
|
478
365
|
*/
|
|
479
|
-
|
|
366
|
+
provider: string;
|
|
480
367
|
/**
|
|
481
|
-
*
|
|
482
|
-
* to the provider from the AI SDK and enable provider-specific
|
|
483
|
-
* functionality that can be fully encapsulated in the provider.
|
|
368
|
+
* The model id used for the call.
|
|
484
369
|
*/
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
type StaticToolError<TOOLS extends ToolSet> = ValueOf<{
|
|
489
|
-
[NAME in keyof TOOLS]: {
|
|
490
|
-
type: 'tool-error';
|
|
491
|
-
toolCallId: string;
|
|
492
|
-
toolName: NAME & string;
|
|
493
|
-
input: InferToolInput<TOOLS[NAME]>;
|
|
494
|
-
error: unknown;
|
|
495
|
-
providerExecuted?: boolean;
|
|
496
|
-
providerMetadata?: ProviderMetadata;
|
|
497
|
-
dynamic?: false | undefined;
|
|
498
|
-
title?: string;
|
|
499
|
-
};
|
|
500
|
-
}>;
|
|
501
|
-
type DynamicToolError = {
|
|
502
|
-
type: 'tool-error';
|
|
503
|
-
toolCallId: string;
|
|
504
|
-
toolName: string;
|
|
505
|
-
input: unknown;
|
|
506
|
-
error: unknown;
|
|
507
|
-
providerExecuted?: boolean;
|
|
508
|
-
providerMetadata?: ProviderMetadata;
|
|
509
|
-
dynamic: true;
|
|
510
|
-
title?: string;
|
|
511
|
-
};
|
|
512
|
-
type TypedToolError<TOOLS extends ToolSet> = StaticToolError<TOOLS> | DynamicToolError;
|
|
513
|
-
|
|
514
|
-
type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{
|
|
515
|
-
[NAME in keyof TOOLS]: {
|
|
516
|
-
type: 'tool-result';
|
|
517
|
-
toolCallId: string;
|
|
518
|
-
toolName: NAME & string;
|
|
519
|
-
input: InferToolInput<TOOLS[NAME]>;
|
|
520
|
-
output: InferToolOutput<TOOLS[NAME]>;
|
|
521
|
-
providerExecuted?: boolean;
|
|
522
|
-
providerMetadata?: ProviderMetadata;
|
|
523
|
-
dynamic?: false | undefined;
|
|
524
|
-
preliminary?: boolean;
|
|
525
|
-
title?: string;
|
|
526
|
-
};
|
|
527
|
-
}>;
|
|
528
|
-
type DynamicToolResult = {
|
|
529
|
-
type: 'tool-result';
|
|
530
|
-
toolCallId: string;
|
|
531
|
-
toolName: string;
|
|
532
|
-
input: unknown;
|
|
533
|
-
output: unknown;
|
|
534
|
-
providerExecuted?: boolean;
|
|
535
|
-
providerMetadata?: ProviderMetadata;
|
|
536
|
-
dynamic: true;
|
|
537
|
-
preliminary?: boolean;
|
|
538
|
-
title?: string;
|
|
539
|
-
};
|
|
540
|
-
type TypedToolResult<TOOLS extends ToolSet> = StaticToolResult<TOOLS> | DynamicToolResult;
|
|
541
|
-
|
|
542
|
-
type ContentPart<TOOLS extends ToolSet> = {
|
|
543
|
-
type: 'text';
|
|
544
|
-
text: string;
|
|
545
|
-
providerMetadata?: ProviderMetadata;
|
|
546
|
-
} | ReasoningOutput | ({
|
|
547
|
-
type: 'source';
|
|
548
|
-
} & Source) | {
|
|
549
|
-
type: 'file';
|
|
550
|
-
file: GeneratedFile;
|
|
551
|
-
providerMetadata?: ProviderMetadata;
|
|
552
|
-
} | ({
|
|
553
|
-
type: 'tool-call';
|
|
554
|
-
} & TypedToolCall<TOOLS> & {
|
|
555
|
-
providerMetadata?: ProviderMetadata;
|
|
556
|
-
}) | ({
|
|
557
|
-
type: 'tool-result';
|
|
558
|
-
} & TypedToolResult<TOOLS> & {
|
|
559
|
-
providerMetadata?: ProviderMetadata;
|
|
560
|
-
}) | ({
|
|
561
|
-
type: 'tool-error';
|
|
562
|
-
} & TypedToolError<TOOLS> & {
|
|
563
|
-
providerMetadata?: ProviderMetadata;
|
|
564
|
-
}) | ToolApprovalRequestOutput<TOOLS>;
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Create a type from an object with all keys and nested keys set to optional.
|
|
568
|
-
* The helper supports normal objects and schemas (which are resolved automatically).
|
|
569
|
-
* It always recurses into arrays.
|
|
570
|
-
*
|
|
571
|
-
* Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
|
572
|
-
*/
|
|
573
|
-
type DeepPartial<T> = T extends FlexibleSchema ? DeepPartialInternal<InferSchema<T>> : DeepPartialInternal<T>;
|
|
574
|
-
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
|
575
|
-
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
|
576
|
-
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
|
577
|
-
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
|
578
|
-
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
|
579
|
-
type PartialObject<ObjectType extends object> = {
|
|
580
|
-
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
|
581
|
-
};
|
|
370
|
+
model: string;
|
|
371
|
+
}) => void;
|
|
582
372
|
|
|
583
373
|
/**
|
|
584
374
|
* Timeout configuration for API calls. Can be specified as:
|
|
@@ -671,16 +461,33 @@ type CallSettings = {
|
|
|
671
461
|
};
|
|
672
462
|
|
|
673
463
|
/**
|
|
674
|
-
*
|
|
675
|
-
*
|
|
464
|
+
* Create a type from an object with all keys and nested keys set to optional.
|
|
465
|
+
* The helper supports normal objects and schemas (which are resolved automatically).
|
|
466
|
+
* It always recurses into arrays.
|
|
467
|
+
*
|
|
468
|
+
* Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
|
676
469
|
*/
|
|
677
|
-
type
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
470
|
+
type DeepPartial<T> = T extends FlexibleSchema ? DeepPartialInternal<InferSchema<T>> : DeepPartialInternal<T>;
|
|
471
|
+
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
|
472
|
+
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
|
473
|
+
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
|
474
|
+
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
|
475
|
+
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
|
476
|
+
type PartialObject<ObjectType extends object> = {
|
|
477
|
+
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Prompt part of the AI function options.
|
|
482
|
+
* It contains a system message, a simple text prompt, or a list of messages.
|
|
483
|
+
*/
|
|
484
|
+
type Prompt = {
|
|
485
|
+
/**
|
|
486
|
+
* System message to include in the prompt. Can be used with `prompt` or `messages`.
|
|
487
|
+
*/
|
|
488
|
+
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
489
|
+
/**
|
|
490
|
+
* Whether system messages are allowed in the `prompt` or `messages` fields.
|
|
684
491
|
*
|
|
685
492
|
* When disabled, system messages must be provided through the `system`
|
|
686
493
|
* option. When unset, system messages are allowed with a warning.
|
|
@@ -717,103 +524,391 @@ type Prompt = {
|
|
|
717
524
|
});
|
|
718
525
|
|
|
719
526
|
/**
|
|
720
|
-
*
|
|
721
|
-
* It can be either an assistant message or a tool message.
|
|
722
|
-
*/
|
|
723
|
-
type ResponseMessage = AssistantModelMessage | ToolModelMessage;
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* The result of a single step in the generation process.
|
|
527
|
+
* Telemetry configuration.
|
|
727
528
|
*/
|
|
728
|
-
type
|
|
729
|
-
/**
|
|
730
|
-
* Zero-based index of this step.
|
|
731
|
-
*/
|
|
732
|
-
readonly stepNumber: number;
|
|
733
|
-
/**
|
|
734
|
-
* Information about the model that produced this step.
|
|
735
|
-
*/
|
|
736
|
-
readonly model: {
|
|
737
|
-
/** The provider of the model. */
|
|
738
|
-
readonly provider: string;
|
|
739
|
-
/** The ID of the model. */
|
|
740
|
-
readonly modelId: string;
|
|
741
|
-
};
|
|
742
|
-
/**
|
|
743
|
-
* Identifier from telemetry settings for grouping related operations.
|
|
744
|
-
*/
|
|
745
|
-
readonly functionId: string | undefined;
|
|
529
|
+
type TelemetrySettings = {
|
|
746
530
|
/**
|
|
747
|
-
*
|
|
531
|
+
* Enable or disable telemetry. Disabled by default while experimental.
|
|
748
532
|
*/
|
|
749
|
-
|
|
533
|
+
isEnabled?: boolean;
|
|
750
534
|
/**
|
|
751
|
-
*
|
|
535
|
+
* Enable or disable input recording. Enabled by default.
|
|
752
536
|
*
|
|
753
|
-
*
|
|
754
|
-
|
|
755
|
-
readonly experimental_context: unknown;
|
|
756
|
-
/**
|
|
757
|
-
* The content that was generated in the last step.
|
|
537
|
+
* You might want to disable input recording to avoid recording sensitive
|
|
538
|
+
* information, to reduce data transfers, or to increase performance.
|
|
758
539
|
*/
|
|
759
|
-
|
|
540
|
+
recordInputs?: boolean;
|
|
760
541
|
/**
|
|
761
|
-
*
|
|
542
|
+
* Enable or disable output recording. Enabled by default.
|
|
543
|
+
*
|
|
544
|
+
* You might want to disable output recording to avoid recording sensitive
|
|
545
|
+
* information, to reduce data transfers, or to increase performance.
|
|
762
546
|
*/
|
|
763
|
-
|
|
547
|
+
recordOutputs?: boolean;
|
|
764
548
|
/**
|
|
765
|
-
*
|
|
549
|
+
* Identifier for this function. Used to group telemetry data by function.
|
|
766
550
|
*/
|
|
767
|
-
|
|
551
|
+
functionId?: string;
|
|
768
552
|
/**
|
|
769
|
-
*
|
|
553
|
+
* Additional information to include in the telemetry data.
|
|
770
554
|
*/
|
|
771
|
-
|
|
555
|
+
metadata?: Record<string, AttributeValue>;
|
|
772
556
|
/**
|
|
773
|
-
*
|
|
557
|
+
* A custom tracer to use for the telemetry data.
|
|
774
558
|
*/
|
|
775
|
-
|
|
559
|
+
tracer?: Tracer;
|
|
776
560
|
/**
|
|
777
|
-
*
|
|
561
|
+
* Per-call telemetry integrations that receive lifecycle events during generation.
|
|
562
|
+
*
|
|
563
|
+
* These integrations run after any globally registered integrations
|
|
564
|
+
* (see `registerTelemetryIntegration`).
|
|
778
565
|
*/
|
|
779
|
-
|
|
566
|
+
integrations?: TelemetryIntegration | TelemetryIntegration[];
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Experimental. Can change in patch versions without warning.
|
|
571
|
+
*
|
|
572
|
+
* Download function. Called with the array of URLs and a boolean indicating
|
|
573
|
+
* whether the URL is supported by the model.
|
|
574
|
+
*
|
|
575
|
+
* The download function can decide for each URL:
|
|
576
|
+
* - to return null (which means that the URL should be passed to the model)
|
|
577
|
+
* - to download the asset and return the data (incl. retries, authentication, etc.)
|
|
578
|
+
*
|
|
579
|
+
* Should throw DownloadError if the download fails.
|
|
580
|
+
*
|
|
581
|
+
* Should return an array of objects sorted by the order of the requested downloads.
|
|
582
|
+
* For each object, the data should be a Uint8Array if the URL was downloaded.
|
|
583
|
+
* For each object, the mediaType should be the media type of the downloaded asset.
|
|
584
|
+
* For each object, the data should be null if the URL should be passed through as is.
|
|
585
|
+
*/
|
|
586
|
+
type DownloadFunction = (options: Array<{
|
|
587
|
+
url: URL;
|
|
588
|
+
isUrlSupportedByModel: boolean;
|
|
589
|
+
}>) => PromiseLike<Array<{
|
|
590
|
+
data: Uint8Array;
|
|
591
|
+
mediaType: string | undefined;
|
|
592
|
+
} | null>>;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Reasoning output of a text generation. It contains a reasoning.
|
|
596
|
+
*/
|
|
597
|
+
interface ReasoningOutput {
|
|
598
|
+
type: 'reasoning';
|
|
780
599
|
/**
|
|
781
|
-
* The
|
|
600
|
+
* The reasoning text.
|
|
782
601
|
*/
|
|
783
|
-
|
|
602
|
+
text: string;
|
|
784
603
|
/**
|
|
785
|
-
*
|
|
604
|
+
* Additional provider-specific metadata. They are passed through
|
|
605
|
+
* to the provider from the AI SDK and enable provider-specific
|
|
606
|
+
* functionality that can be fully encapsulated in the provider.
|
|
786
607
|
*/
|
|
787
|
-
|
|
608
|
+
providerMetadata?: ProviderMetadata;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* A generated file.
|
|
613
|
+
*/
|
|
614
|
+
interface GeneratedFile {
|
|
788
615
|
/**
|
|
789
|
-
*
|
|
616
|
+
* File as a base64 encoded string.
|
|
790
617
|
*/
|
|
791
|
-
readonly
|
|
618
|
+
readonly base64: string;
|
|
792
619
|
/**
|
|
793
|
-
*
|
|
620
|
+
* File as a Uint8Array.
|
|
794
621
|
*/
|
|
795
|
-
readonly
|
|
622
|
+
readonly uint8Array: Uint8Array;
|
|
796
623
|
/**
|
|
797
|
-
* The
|
|
624
|
+
* The IANA media type of the file.
|
|
625
|
+
*
|
|
626
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
798
627
|
*/
|
|
799
|
-
readonly
|
|
628
|
+
readonly mediaType: string;
|
|
629
|
+
}
|
|
630
|
+
declare class DefaultGeneratedFile implements GeneratedFile {
|
|
631
|
+
private base64Data;
|
|
632
|
+
private uint8ArrayData;
|
|
633
|
+
readonly mediaType: string;
|
|
634
|
+
constructor({ data, mediaType, }: {
|
|
635
|
+
data: string | Uint8Array;
|
|
636
|
+
mediaType: string;
|
|
637
|
+
});
|
|
638
|
+
get base64(): string;
|
|
639
|
+
get uint8Array(): Uint8Array<ArrayBufferLike>;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
644
|
+
*
|
|
645
|
+
* Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```
|
|
649
|
+
* // data.json
|
|
650
|
+
* {
|
|
651
|
+
* 'foo': 1,
|
|
652
|
+
* 'bar': 2,
|
|
653
|
+
* 'biz': 3
|
|
654
|
+
* }
|
|
655
|
+
*
|
|
656
|
+
* // main.ts
|
|
657
|
+
* import type {ValueOf} from 'type-fest';
|
|
658
|
+
* import data = require('./data.json');
|
|
659
|
+
*
|
|
660
|
+
* export function getData(name: string): ValueOf<typeof data> {
|
|
661
|
+
* return data[name];
|
|
662
|
+
* }
|
|
663
|
+
*
|
|
664
|
+
* export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
|
665
|
+
* return data[name];
|
|
666
|
+
* }
|
|
667
|
+
*
|
|
668
|
+
* // file.ts
|
|
669
|
+
* import {getData, onlyBar} from './main';
|
|
670
|
+
*
|
|
671
|
+
* getData('foo');
|
|
672
|
+
* //=> 1
|
|
673
|
+
*
|
|
674
|
+
* onlyBar('foo');
|
|
675
|
+
* //=> TypeError ...
|
|
676
|
+
*
|
|
677
|
+
* onlyBar('bar');
|
|
678
|
+
* //=> 2
|
|
679
|
+
* ```
|
|
680
|
+
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
|
681
|
+
*/
|
|
682
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
|
683
|
+
|
|
684
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
|
|
685
|
+
|
|
686
|
+
type BaseToolCall = {
|
|
687
|
+
type: 'tool-call';
|
|
688
|
+
toolCallId: string;
|
|
689
|
+
providerExecuted?: boolean;
|
|
690
|
+
providerMetadata?: ProviderMetadata;
|
|
691
|
+
};
|
|
692
|
+
type StaticToolCall<TOOLS extends ToolSet> = ValueOf<{
|
|
693
|
+
[NAME in keyof TOOLS]: BaseToolCall & {
|
|
694
|
+
toolName: NAME & string;
|
|
695
|
+
input: TOOLS[NAME] extends Tool<infer PARAMETERS> ? PARAMETERS : never;
|
|
696
|
+
dynamic?: false | undefined;
|
|
697
|
+
invalid?: false | undefined;
|
|
698
|
+
error?: never;
|
|
699
|
+
title?: string;
|
|
700
|
+
};
|
|
701
|
+
}>;
|
|
702
|
+
type DynamicToolCall = BaseToolCall & {
|
|
703
|
+
toolName: string;
|
|
704
|
+
input: unknown;
|
|
705
|
+
dynamic: true;
|
|
706
|
+
title?: string;
|
|
800
707
|
/**
|
|
801
|
-
*
|
|
708
|
+
* True if this is caused by an unparsable tool call or
|
|
709
|
+
* a tool that does not exist.
|
|
802
710
|
*/
|
|
803
|
-
|
|
711
|
+
invalid?: boolean;
|
|
804
712
|
/**
|
|
805
|
-
* The
|
|
713
|
+
* The error that caused the tool call to be invalid.
|
|
806
714
|
*/
|
|
807
|
-
|
|
715
|
+
error?: unknown;
|
|
716
|
+
};
|
|
717
|
+
type TypedToolCall<TOOLS extends ToolSet> = StaticToolCall<TOOLS> | DynamicToolCall;
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Output part that indicates that a tool approval request has been made.
|
|
721
|
+
*
|
|
722
|
+
* The tool approval request can be approved or denied in the next tool message.
|
|
723
|
+
*/
|
|
724
|
+
type ToolApprovalRequestOutput<TOOLS extends ToolSet> = {
|
|
725
|
+
type: 'tool-approval-request';
|
|
808
726
|
/**
|
|
809
|
-
*
|
|
727
|
+
* ID of the tool approval request.
|
|
810
728
|
*/
|
|
811
|
-
|
|
729
|
+
approvalId: string;
|
|
812
730
|
/**
|
|
813
|
-
*
|
|
731
|
+
* Tool call that the approval request is for.
|
|
814
732
|
*/
|
|
815
|
-
|
|
816
|
-
|
|
733
|
+
toolCall: TypedToolCall<TOOLS>;
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
type StaticToolError<TOOLS extends ToolSet> = ValueOf<{
|
|
737
|
+
[NAME in keyof TOOLS]: {
|
|
738
|
+
type: 'tool-error';
|
|
739
|
+
toolCallId: string;
|
|
740
|
+
toolName: NAME & string;
|
|
741
|
+
input: InferToolInput<TOOLS[NAME]>;
|
|
742
|
+
error: unknown;
|
|
743
|
+
providerExecuted?: boolean;
|
|
744
|
+
providerMetadata?: ProviderMetadata;
|
|
745
|
+
dynamic?: false | undefined;
|
|
746
|
+
title?: string;
|
|
747
|
+
};
|
|
748
|
+
}>;
|
|
749
|
+
type DynamicToolError = {
|
|
750
|
+
type: 'tool-error';
|
|
751
|
+
toolCallId: string;
|
|
752
|
+
toolName: string;
|
|
753
|
+
input: unknown;
|
|
754
|
+
error: unknown;
|
|
755
|
+
providerExecuted?: boolean;
|
|
756
|
+
providerMetadata?: ProviderMetadata;
|
|
757
|
+
dynamic: true;
|
|
758
|
+
title?: string;
|
|
759
|
+
};
|
|
760
|
+
type TypedToolError<TOOLS extends ToolSet> = StaticToolError<TOOLS> | DynamicToolError;
|
|
761
|
+
|
|
762
|
+
type StaticToolResult<TOOLS extends ToolSet> = ValueOf<{
|
|
763
|
+
[NAME in keyof TOOLS]: {
|
|
764
|
+
type: 'tool-result';
|
|
765
|
+
toolCallId: string;
|
|
766
|
+
toolName: NAME & string;
|
|
767
|
+
input: InferToolInput<TOOLS[NAME]>;
|
|
768
|
+
output: InferToolOutput<TOOLS[NAME]>;
|
|
769
|
+
providerExecuted?: boolean;
|
|
770
|
+
providerMetadata?: ProviderMetadata;
|
|
771
|
+
dynamic?: false | undefined;
|
|
772
|
+
preliminary?: boolean;
|
|
773
|
+
title?: string;
|
|
774
|
+
};
|
|
775
|
+
}>;
|
|
776
|
+
type DynamicToolResult = {
|
|
777
|
+
type: 'tool-result';
|
|
778
|
+
toolCallId: string;
|
|
779
|
+
toolName: string;
|
|
780
|
+
input: unknown;
|
|
781
|
+
output: unknown;
|
|
782
|
+
providerExecuted?: boolean;
|
|
783
|
+
providerMetadata?: ProviderMetadata;
|
|
784
|
+
dynamic: true;
|
|
785
|
+
preliminary?: boolean;
|
|
786
|
+
title?: string;
|
|
787
|
+
};
|
|
788
|
+
type TypedToolResult<TOOLS extends ToolSet> = StaticToolResult<TOOLS> | DynamicToolResult;
|
|
789
|
+
|
|
790
|
+
type ContentPart<TOOLS extends ToolSet> = {
|
|
791
|
+
type: 'text';
|
|
792
|
+
text: string;
|
|
793
|
+
providerMetadata?: ProviderMetadata;
|
|
794
|
+
} | ReasoningOutput | ({
|
|
795
|
+
type: 'source';
|
|
796
|
+
} & Source) | {
|
|
797
|
+
type: 'file';
|
|
798
|
+
file: GeneratedFile;
|
|
799
|
+
providerMetadata?: ProviderMetadata;
|
|
800
|
+
} | ({
|
|
801
|
+
type: 'tool-call';
|
|
802
|
+
} & TypedToolCall<TOOLS> & {
|
|
803
|
+
providerMetadata?: ProviderMetadata;
|
|
804
|
+
}) | ({
|
|
805
|
+
type: 'tool-result';
|
|
806
|
+
} & TypedToolResult<TOOLS> & {
|
|
807
|
+
providerMetadata?: ProviderMetadata;
|
|
808
|
+
}) | ({
|
|
809
|
+
type: 'tool-error';
|
|
810
|
+
} & TypedToolError<TOOLS> & {
|
|
811
|
+
providerMetadata?: ProviderMetadata;
|
|
812
|
+
}) | ToolApprovalRequestOutput<TOOLS>;
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* A message that was generated during the generation process.
|
|
816
|
+
* It can be either an assistant message or a tool message.
|
|
817
|
+
*/
|
|
818
|
+
type ResponseMessage = AssistantModelMessage | ToolModelMessage;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* The result of a single step in the generation process.
|
|
822
|
+
*/
|
|
823
|
+
type StepResult<TOOLS extends ToolSet> = {
|
|
824
|
+
/**
|
|
825
|
+
* Zero-based index of this step.
|
|
826
|
+
*/
|
|
827
|
+
readonly stepNumber: number;
|
|
828
|
+
/**
|
|
829
|
+
* Information about the model that produced this step.
|
|
830
|
+
*/
|
|
831
|
+
readonly model: {
|
|
832
|
+
/** The provider of the model. */
|
|
833
|
+
readonly provider: string;
|
|
834
|
+
/** The ID of the model. */
|
|
835
|
+
readonly modelId: string;
|
|
836
|
+
};
|
|
837
|
+
/**
|
|
838
|
+
* Identifier from telemetry settings for grouping related operations.
|
|
839
|
+
*/
|
|
840
|
+
readonly functionId: string | undefined;
|
|
841
|
+
/**
|
|
842
|
+
* Additional metadata from telemetry settings.
|
|
843
|
+
*/
|
|
844
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
845
|
+
/**
|
|
846
|
+
* User-defined context object flowing through the generation.
|
|
847
|
+
*
|
|
848
|
+
* Experimental (can break in patch releases).
|
|
849
|
+
*/
|
|
850
|
+
readonly experimental_context: unknown;
|
|
851
|
+
/**
|
|
852
|
+
* The content that was generated in the last step.
|
|
853
|
+
*/
|
|
854
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
|
855
|
+
/**
|
|
856
|
+
* The generated text.
|
|
857
|
+
*/
|
|
858
|
+
readonly text: string;
|
|
859
|
+
/**
|
|
860
|
+
* The reasoning that was generated during the generation.
|
|
861
|
+
*/
|
|
862
|
+
readonly reasoning: Array<ReasoningPart>;
|
|
863
|
+
/**
|
|
864
|
+
* The reasoning text that was generated during the generation.
|
|
865
|
+
*/
|
|
866
|
+
readonly reasoningText: string | undefined;
|
|
867
|
+
/**
|
|
868
|
+
* The files that were generated during the generation.
|
|
869
|
+
*/
|
|
870
|
+
readonly files: Array<GeneratedFile>;
|
|
871
|
+
/**
|
|
872
|
+
* The sources that were used to generate the text.
|
|
873
|
+
*/
|
|
874
|
+
readonly sources: Array<Source>;
|
|
875
|
+
/**
|
|
876
|
+
* The tool calls that were made during the generation.
|
|
877
|
+
*/
|
|
878
|
+
readonly toolCalls: Array<TypedToolCall<TOOLS>>;
|
|
879
|
+
/**
|
|
880
|
+
* The static tool calls that were made in the last step.
|
|
881
|
+
*/
|
|
882
|
+
readonly staticToolCalls: Array<StaticToolCall<TOOLS>>;
|
|
883
|
+
/**
|
|
884
|
+
* The dynamic tool calls that were made in the last step.
|
|
885
|
+
*/
|
|
886
|
+
readonly dynamicToolCalls: Array<DynamicToolCall>;
|
|
887
|
+
/**
|
|
888
|
+
* The results of the tool calls.
|
|
889
|
+
*/
|
|
890
|
+
readonly toolResults: Array<TypedToolResult<TOOLS>>;
|
|
891
|
+
/**
|
|
892
|
+
* The static tool results that were made in the last step.
|
|
893
|
+
*/
|
|
894
|
+
readonly staticToolResults: Array<StaticToolResult<TOOLS>>;
|
|
895
|
+
/**
|
|
896
|
+
* The dynamic tool results that were made in the last step.
|
|
897
|
+
*/
|
|
898
|
+
readonly dynamicToolResults: Array<DynamicToolResult>;
|
|
899
|
+
/**
|
|
900
|
+
* The unified reason why the generation finished.
|
|
901
|
+
*/
|
|
902
|
+
readonly finishReason: FinishReason;
|
|
903
|
+
/**
|
|
904
|
+
* The raw reason why the generation finished (from the provider).
|
|
905
|
+
*/
|
|
906
|
+
readonly rawFinishReason: string | undefined;
|
|
907
|
+
/**
|
|
908
|
+
* The token usage of the generated text.
|
|
909
|
+
*/
|
|
910
|
+
readonly usage: LanguageModelUsage;
|
|
911
|
+
/**
|
|
817
912
|
* Warnings from the model provider (e.g. unsupported settings).
|
|
818
913
|
*/
|
|
819
914
|
readonly warnings: CallWarning[] | undefined;
|
|
@@ -844,414 +939,226 @@ type StepResult<TOOLS extends ToolSet> = {
|
|
|
844
939
|
readonly providerMetadata: ProviderMetadata | undefined;
|
|
845
940
|
};
|
|
846
941
|
|
|
847
|
-
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
848
|
-
steps: Array<StepResult<TOOLS>>;
|
|
849
|
-
}) => PromiseLike<boolean> | boolean;
|
|
850
|
-
declare function stepCountIs(stepCount: number): StopCondition<any>;
|
|
851
|
-
declare function isLoopFinished(): StopCondition<any>;
|
|
852
|
-
declare function hasToolCall(toolName: string): StopCondition<any>;
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* Common model information used across callback events.
|
|
856
|
-
*/
|
|
857
|
-
interface CallbackModelInfo {
|
|
858
|
-
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
859
|
-
readonly provider: string;
|
|
860
|
-
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
861
|
-
readonly modelId: string;
|
|
862
|
-
}
|
|
863
942
|
/**
|
|
864
|
-
*
|
|
943
|
+
* Function that you can use to provide different settings for a step.
|
|
865
944
|
*
|
|
866
|
-
*
|
|
945
|
+
* @param options - The options for the step.
|
|
946
|
+
* @param options.steps - The steps that have been executed so far.
|
|
947
|
+
* @param options.stepNumber - The number of the step that is being executed.
|
|
948
|
+
* @param options.model - The model that is being used.
|
|
949
|
+
* @param options.messages - The messages that will be sent to the model for the current step.
|
|
950
|
+
* @param options.experimental_context - The context passed via the experimental_context setting (experimental).
|
|
951
|
+
*
|
|
952
|
+
* @returns An object that contains the settings for the step.
|
|
953
|
+
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
867
954
|
*/
|
|
868
|
-
|
|
869
|
-
requestBody?: boolean;
|
|
870
|
-
responseBody?: boolean;
|
|
871
|
-
}> {
|
|
872
|
-
/** The model being used for generation. */
|
|
873
|
-
readonly model: CallbackModelInfo;
|
|
874
|
-
/** The system message(s) provided to the model. */
|
|
875
|
-
readonly system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
|
|
876
|
-
/** The prompt string or array of messages if using the prompt option. */
|
|
877
|
-
readonly prompt: string | Array<ModelMessage> | undefined;
|
|
878
|
-
/** The messages array if using the messages option. */
|
|
879
|
-
readonly messages: Array<ModelMessage> | undefined;
|
|
880
|
-
/** The tools available for this generation. */
|
|
881
|
-
readonly tools: TOOLS | undefined;
|
|
882
|
-
/** The tool choice strategy for this generation. */
|
|
883
|
-
readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
|
|
884
|
-
/** Limits which tools are available for the model to call. */
|
|
885
|
-
readonly activeTools: Array<keyof TOOLS> | undefined;
|
|
886
|
-
/** Maximum number of tokens to generate. */
|
|
887
|
-
readonly maxOutputTokens: number | undefined;
|
|
888
|
-
/** Sampling temperature for generation. */
|
|
889
|
-
readonly temperature: number | undefined;
|
|
890
|
-
/** Top-p (nucleus) sampling parameter. */
|
|
891
|
-
readonly topP: number | undefined;
|
|
892
|
-
/** Top-k sampling parameter. */
|
|
893
|
-
readonly topK: number | undefined;
|
|
894
|
-
/** Presence penalty for generation. */
|
|
895
|
-
readonly presencePenalty: number | undefined;
|
|
896
|
-
/** Frequency penalty for generation. */
|
|
897
|
-
readonly frequencyPenalty: number | undefined;
|
|
898
|
-
/** Sequences that will stop generation. */
|
|
899
|
-
readonly stopSequences: string[] | undefined;
|
|
900
|
-
/** Random seed for reproducible generation. */
|
|
901
|
-
readonly seed: number | undefined;
|
|
902
|
-
/** Maximum number of retries for failed requests. */
|
|
903
|
-
readonly maxRetries: number;
|
|
955
|
+
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
904
956
|
/**
|
|
905
|
-
*
|
|
906
|
-
* Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.
|
|
957
|
+
* The steps that have been executed so far.
|
|
907
958
|
*/
|
|
908
|
-
|
|
909
|
-
/** Additional HTTP headers sent with the request. */
|
|
910
|
-
readonly headers: Record<string, string | undefined> | undefined;
|
|
911
|
-
/** Additional provider-specific options. */
|
|
912
|
-
readonly providerOptions: ProviderOptions | undefined;
|
|
959
|
+
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
|
913
960
|
/**
|
|
914
|
-
*
|
|
915
|
-
* When the condition is an array, any of the conditions can be met to stop.
|
|
961
|
+
* The number of the step that is being executed.
|
|
916
962
|
*/
|
|
917
|
-
|
|
918
|
-
/** The output specification for structured outputs, if configured. */
|
|
919
|
-
readonly output: OUTPUT | undefined;
|
|
920
|
-
/** Abort signal for cancelling the operation. */
|
|
921
|
-
readonly abortSignal: AbortSignal | undefined;
|
|
963
|
+
stepNumber: number;
|
|
922
964
|
/**
|
|
923
|
-
*
|
|
965
|
+
* The model instance that is being used for this step.
|
|
924
966
|
*/
|
|
925
|
-
|
|
926
|
-
/** Identifier from telemetry settings for grouping related operations. */
|
|
927
|
-
readonly functionId: string | undefined;
|
|
928
|
-
/** Additional metadata passed to the generation. */
|
|
929
|
-
readonly metadata: Record<string, unknown> | undefined;
|
|
967
|
+
model: LanguageModel;
|
|
930
968
|
/**
|
|
931
|
-
*
|
|
932
|
-
* Can be accessed and modified in `prepareStep` and tool `execute` functions.
|
|
969
|
+
* The messages that will be sent to the model for the current step.
|
|
933
970
|
*/
|
|
934
|
-
|
|
935
|
-
|
|
971
|
+
messages: Array<ModelMessage>;
|
|
972
|
+
/**
|
|
973
|
+
* The context passed via the experimental_context setting (experimental).
|
|
974
|
+
*/
|
|
975
|
+
experimental_context: unknown;
|
|
976
|
+
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
936
977
|
/**
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
* Called when a step (LLM call) begins, before the provider is called.
|
|
940
|
-
* Each step represents a single LLM invocation.
|
|
978
|
+
* The result type returned by a {@link PrepareStepFunction},
|
|
979
|
+
* allowing per-step overrides of model, tools, or messages.
|
|
941
980
|
*/
|
|
942
|
-
|
|
943
|
-
requestBody?: boolean;
|
|
944
|
-
responseBody?: boolean;
|
|
945
|
-
}> {
|
|
946
|
-
/** Zero-based index of the current step. */
|
|
947
|
-
readonly stepNumber: number;
|
|
948
|
-
/** The model being used for this step. */
|
|
949
|
-
readonly model: CallbackModelInfo;
|
|
981
|
+
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
950
982
|
/**
|
|
951
|
-
*
|
|
983
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
952
984
|
*/
|
|
953
|
-
|
|
985
|
+
model?: LanguageModel;
|
|
954
986
|
/**
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
* May be overridden by prepareStep.
|
|
987
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
988
|
+
* for this step.
|
|
958
989
|
*/
|
|
959
|
-
|
|
960
|
-
/** The tools available for this generation. */
|
|
961
|
-
readonly tools: TOOLS | undefined;
|
|
962
|
-
/** The tool choice configuration for this step. */
|
|
963
|
-
readonly toolChoice: LanguageModelV3ToolChoice | undefined;
|
|
964
|
-
/** Limits which tools are available for this step. */
|
|
965
|
-
readonly activeTools: Array<keyof TOOLS> | undefined;
|
|
966
|
-
/** Array of results from previous steps (empty for first step). */
|
|
967
|
-
readonly steps: ReadonlyArray<StepResult<TOOLS>>;
|
|
968
|
-
/** Additional provider-specific options for this step. */
|
|
969
|
-
readonly providerOptions: ProviderOptions | undefined;
|
|
990
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
970
991
|
/**
|
|
971
|
-
*
|
|
972
|
-
* Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.
|
|
992
|
+
* If provided, only these tools are enabled/available for this step.
|
|
973
993
|
*/
|
|
974
|
-
|
|
975
|
-
/** Additional HTTP headers sent with the request. */
|
|
976
|
-
readonly headers: Record<string, string | undefined> | undefined;
|
|
994
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
977
995
|
/**
|
|
978
|
-
*
|
|
979
|
-
* When the condition is an array, any of the conditions can be met to stop.
|
|
996
|
+
* Optionally override the system message(s) sent to the model for this step.
|
|
980
997
|
*/
|
|
981
|
-
|
|
982
|
-
/** The output specification for structured outputs, if configured. */
|
|
983
|
-
readonly output: OUTPUT | undefined;
|
|
984
|
-
/** Abort signal for cancelling the operation. */
|
|
985
|
-
readonly abortSignal: AbortSignal | undefined;
|
|
998
|
+
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
986
999
|
/**
|
|
987
|
-
*
|
|
1000
|
+
* Optionally override the full set of messages sent to the model
|
|
1001
|
+
* for this step.
|
|
988
1002
|
*/
|
|
989
|
-
|
|
990
|
-
/** Identifier from telemetry settings for grouping related operations. */
|
|
991
|
-
readonly functionId: string | undefined;
|
|
992
|
-
/** Additional metadata from telemetry settings. */
|
|
993
|
-
readonly metadata: Record<string, unknown> | undefined;
|
|
1003
|
+
messages?: Array<ModelMessage>;
|
|
994
1004
|
/**
|
|
995
|
-
*
|
|
1005
|
+
* Context that is passed into tool execution. Experimental.
|
|
1006
|
+
*
|
|
1007
|
+
* Changing the context will affect the context in this step
|
|
1008
|
+
* and all subsequent steps.
|
|
996
1009
|
*/
|
|
997
|
-
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Event passed to the `onToolCallStart` callback.
|
|
1001
|
-
*
|
|
1002
|
-
* Called when a tool execution begins, before the tool's `execute` function is invoked.
|
|
1003
|
-
*/
|
|
1004
|
-
interface OnToolCallStartEvent<TOOLS extends ToolSet = ToolSet> {
|
|
1005
|
-
/** Zero-based index of the current step where this tool call occurs. */
|
|
1006
|
-
readonly stepNumber: number | undefined;
|
|
1007
|
-
/** The model being used for this step. */
|
|
1008
|
-
readonly model: CallbackModelInfo | undefined;
|
|
1009
|
-
/** The full tool call object. */
|
|
1010
|
-
readonly toolCall: TypedToolCall<TOOLS>;
|
|
1011
|
-
/** The conversation messages available at tool execution time. */
|
|
1012
|
-
readonly messages: Array<ModelMessage>;
|
|
1013
|
-
/** Signal for cancelling the operation. */
|
|
1014
|
-
readonly abortSignal: AbortSignal | undefined;
|
|
1015
|
-
/** Identifier from telemetry settings for grouping related operations. */
|
|
1016
|
-
readonly functionId: string | undefined;
|
|
1017
|
-
/** Additional metadata from telemetry settings. */
|
|
1018
|
-
readonly metadata: Record<string, unknown> | undefined;
|
|
1019
|
-
/** User-defined context object flowing through the generation. */
|
|
1020
|
-
readonly experimental_context: unknown;
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Event passed to the `onToolCallFinish` callback.
|
|
1024
|
-
*
|
|
1025
|
-
* Called when a tool execution completes, either successfully or with an error.
|
|
1026
|
-
* Uses a discriminated union on the `success` field.
|
|
1027
|
-
*/
|
|
1028
|
-
type OnToolCallFinishEvent<TOOLS extends ToolSet = ToolSet> = {
|
|
1029
|
-
/** Zero-based index of the current step where this tool call occurred. */
|
|
1030
|
-
readonly stepNumber: number | undefined;
|
|
1031
|
-
/** The model being used for this step. */
|
|
1032
|
-
readonly model: CallbackModelInfo | undefined;
|
|
1033
|
-
/** The full tool call object. */
|
|
1034
|
-
readonly toolCall: TypedToolCall<TOOLS>;
|
|
1035
|
-
/** The conversation messages available at tool execution time. */
|
|
1036
|
-
readonly messages: Array<ModelMessage>;
|
|
1037
|
-
/** Signal for cancelling the operation. */
|
|
1038
|
-
readonly abortSignal: AbortSignal | undefined;
|
|
1039
|
-
/** Execution time of the tool call in milliseconds. */
|
|
1040
|
-
readonly durationMs: number;
|
|
1041
|
-
/** Identifier from telemetry settings for grouping related operations. */
|
|
1042
|
-
readonly functionId: string | undefined;
|
|
1043
|
-
/** Additional metadata from telemetry settings. */
|
|
1044
|
-
readonly metadata: Record<string, unknown> | undefined;
|
|
1045
|
-
/** User-defined context object flowing through the generation. */
|
|
1046
|
-
readonly experimental_context: unknown;
|
|
1047
|
-
} & ({
|
|
1048
|
-
/** Indicates the tool call succeeded. */
|
|
1049
|
-
readonly success: true;
|
|
1050
|
-
/** The tool's return value. */
|
|
1051
|
-
readonly output: unknown;
|
|
1052
|
-
readonly error?: never;
|
|
1053
|
-
} | {
|
|
1054
|
-
/** Indicates the tool call failed. */
|
|
1055
|
-
readonly success: false;
|
|
1056
|
-
readonly output?: never;
|
|
1057
|
-
/** The error that occurred during tool execution. */
|
|
1058
|
-
readonly error: unknown;
|
|
1059
|
-
});
|
|
1060
|
-
/**
|
|
1061
|
-
* Event passed to the `onStepFinish` callback.
|
|
1062
|
-
*
|
|
1063
|
-
* Called when a step (LLM call) completes.
|
|
1064
|
-
* This is simply the StepResult for that step.
|
|
1065
|
-
*/
|
|
1066
|
-
type OnStepFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS>;
|
|
1067
|
-
/**
|
|
1068
|
-
* Event passed to the `onFinish` callback.
|
|
1069
|
-
*
|
|
1070
|
-
* Called when the entire generation completes (all steps finished).
|
|
1071
|
-
* Includes the final step's result along with aggregated data from all steps.
|
|
1072
|
-
*/
|
|
1073
|
-
type OnFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS> & {
|
|
1074
|
-
/** Array containing results from all steps in the generation. */
|
|
1075
|
-
readonly steps: StepResult<TOOLS>[];
|
|
1076
|
-
/** Aggregated token usage across all steps. */
|
|
1077
|
-
readonly totalUsage: LanguageModelUsage;
|
|
1010
|
+
experimental_context?: unknown;
|
|
1078
1011
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1081
|
-
* Experimental (can break in patch releases).
|
|
1012
|
+
* Additional provider-specific options for this step.
|
|
1082
1013
|
*
|
|
1083
|
-
*
|
|
1014
|
+
* Can be used to pass provider-specific configuration such as
|
|
1015
|
+
* container IDs for Anthropic's code execution.
|
|
1084
1016
|
*/
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
};
|
|
1017
|
+
providerOptions?: ProviderOptions;
|
|
1018
|
+
} | undefined;
|
|
1019
|
+
|
|
1020
|
+
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
1021
|
+
steps: Array<StepResult<TOOLS>>;
|
|
1022
|
+
}) => PromiseLike<boolean> | boolean;
|
|
1023
|
+
declare function stepCountIs(stepCount: number): StopCondition<any>;
|
|
1024
|
+
declare function isLoopFinished(): StopCondition<any>;
|
|
1025
|
+
declare function hasToolCall(toolName: string): StopCondition<any>;
|
|
1091
1026
|
|
|
1092
1027
|
/**
|
|
1093
|
-
*
|
|
1028
|
+
* Infers the complete output type from the output specification.
|
|
1094
1029
|
*/
|
|
1095
|
-
type
|
|
1096
|
-
|
|
1030
|
+
type InferCompleteOutput<OUTPUT extends Output> = OUTPUT extends Output<infer COMPLETE_OUTPUT, any, any> ? COMPLETE_OUTPUT : never;
|
|
1097
1031
|
/**
|
|
1098
|
-
*
|
|
1099
|
-
* Methods can be sync or return a PromiseLike.
|
|
1032
|
+
* Infers the partial output type from the output specification.
|
|
1100
1033
|
*/
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
onStepFinish?: Listener<OnStepFinishEvent<ToolSet>>;
|
|
1107
|
-
onFinish?: Listener<OnFinishEvent<ToolSet>>;
|
|
1108
|
-
}
|
|
1034
|
+
type InferPartialOutput<OUTPUT extends Output> = OUTPUT extends Output<any, infer PARTIAL_OUTPUT, any> ? PARTIAL_OUTPUT : never;
|
|
1035
|
+
/**
|
|
1036
|
+
* Infers the element type from an array output specification.
|
|
1037
|
+
*/
|
|
1038
|
+
type InferElementOutput<OUTPUT extends Output> = OUTPUT extends Output<any, any, infer ELEMENT> ? ELEMENT : never;
|
|
1109
1039
|
|
|
1110
1040
|
/**
|
|
1111
|
-
*
|
|
1041
|
+
* The result of a `generateText` call.
|
|
1042
|
+
* It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
|
1112
1043
|
*/
|
|
1113
|
-
|
|
1044
|
+
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
1114
1045
|
/**
|
|
1115
|
-
*
|
|
1046
|
+
* The content that was generated in the last step.
|
|
1116
1047
|
*/
|
|
1117
|
-
|
|
1048
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
|
1118
1049
|
/**
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
* You might want to disable input recording to avoid recording sensitive
|
|
1122
|
-
* information, to reduce data transfers, or to increase performance.
|
|
1050
|
+
* The text that was generated in the last step.
|
|
1123
1051
|
*/
|
|
1124
|
-
|
|
1052
|
+
readonly text: string;
|
|
1125
1053
|
/**
|
|
1126
|
-
*
|
|
1127
|
-
*
|
|
1128
|
-
* You might want to disable output recording to avoid recording sensitive
|
|
1129
|
-
* information, to reduce data transfers, or to increase performance.
|
|
1054
|
+
* The full reasoning that the model has generated in the last step.
|
|
1130
1055
|
*/
|
|
1131
|
-
|
|
1056
|
+
readonly reasoning: Array<ReasoningOutput>;
|
|
1132
1057
|
/**
|
|
1133
|
-
*
|
|
1058
|
+
* The reasoning text that the model has generated in the last step. Can be undefined if the model
|
|
1059
|
+
* has only generated text.
|
|
1134
1060
|
*/
|
|
1135
|
-
|
|
1061
|
+
readonly reasoningText: string | undefined;
|
|
1136
1062
|
/**
|
|
1137
|
-
*
|
|
1063
|
+
* The files that were generated in the last step.
|
|
1064
|
+
* Empty array if no files were generated.
|
|
1138
1065
|
*/
|
|
1139
|
-
|
|
1066
|
+
readonly files: Array<GeneratedFile>;
|
|
1140
1067
|
/**
|
|
1141
|
-
*
|
|
1068
|
+
* Sources that have been used as references in the last step.
|
|
1142
1069
|
*/
|
|
1143
|
-
|
|
1070
|
+
readonly sources: Array<Source>;
|
|
1144
1071
|
/**
|
|
1145
|
-
*
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
* (see `registerTelemetryIntegration`).
|
|
1149
|
-
*/
|
|
1150
|
-
integrations?: TelemetryIntegration | TelemetryIntegration[];
|
|
1151
|
-
};
|
|
1152
|
-
|
|
1153
|
-
/**
|
|
1154
|
-
* Experimental. Can change in patch versions without warning.
|
|
1155
|
-
*
|
|
1156
|
-
* Download function. Called with the array of URLs and a boolean indicating
|
|
1157
|
-
* whether the URL is supported by the model.
|
|
1158
|
-
*
|
|
1159
|
-
* The download function can decide for each URL:
|
|
1160
|
-
* - to return null (which means that the URL should be passed to the model)
|
|
1161
|
-
* - to download the asset and return the data (incl. retries, authentication, etc.)
|
|
1162
|
-
*
|
|
1163
|
-
* Should throw DownloadError if the download fails.
|
|
1164
|
-
*
|
|
1165
|
-
* Should return an array of objects sorted by the order of the requested downloads.
|
|
1166
|
-
* For each object, the data should be a Uint8Array if the URL was downloaded.
|
|
1167
|
-
* For each object, the mediaType should be the media type of the downloaded asset.
|
|
1168
|
-
* For each object, the data should be null if the URL should be passed through as is.
|
|
1169
|
-
*/
|
|
1170
|
-
type DownloadFunction = (options: Array<{
|
|
1171
|
-
url: URL;
|
|
1172
|
-
isUrlSupportedByModel: boolean;
|
|
1173
|
-
}>) => PromiseLike<Array<{
|
|
1174
|
-
data: Uint8Array;
|
|
1175
|
-
mediaType: string | undefined;
|
|
1176
|
-
} | null>>;
|
|
1177
|
-
|
|
1178
|
-
/**
|
|
1179
|
-
* Function that you can use to provide different settings for a step.
|
|
1180
|
-
*
|
|
1181
|
-
* @param options - The options for the step.
|
|
1182
|
-
* @param options.steps - The steps that have been executed so far.
|
|
1183
|
-
* @param options.stepNumber - The number of the step that is being executed.
|
|
1184
|
-
* @param options.model - The model that is being used.
|
|
1185
|
-
* @param options.messages - The messages that will be sent to the model for the current step.
|
|
1186
|
-
* @param options.experimental_context - The context passed via the experimental_context setting (experimental).
|
|
1187
|
-
*
|
|
1188
|
-
* @returns An object that contains the settings for the step.
|
|
1189
|
-
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1190
|
-
*/
|
|
1191
|
-
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
1072
|
+
* The tool calls that were made in the last step.
|
|
1073
|
+
*/
|
|
1074
|
+
readonly toolCalls: Array<TypedToolCall<TOOLS>>;
|
|
1192
1075
|
/**
|
|
1193
|
-
* The
|
|
1076
|
+
* The static tool calls that were made in the last step.
|
|
1194
1077
|
*/
|
|
1195
|
-
|
|
1078
|
+
readonly staticToolCalls: Array<StaticToolCall<TOOLS>>;
|
|
1196
1079
|
/**
|
|
1197
|
-
* The
|
|
1080
|
+
* The dynamic tool calls that were made in the last step.
|
|
1198
1081
|
*/
|
|
1199
|
-
|
|
1082
|
+
readonly dynamicToolCalls: Array<DynamicToolCall>;
|
|
1200
1083
|
/**
|
|
1201
|
-
* The
|
|
1084
|
+
* The results of the tool calls from the last step.
|
|
1202
1085
|
*/
|
|
1203
|
-
|
|
1086
|
+
readonly toolResults: Array<TypedToolResult<TOOLS>>;
|
|
1204
1087
|
/**
|
|
1205
|
-
* The
|
|
1088
|
+
* The static tool results that were made in the last step.
|
|
1206
1089
|
*/
|
|
1207
|
-
|
|
1090
|
+
readonly staticToolResults: Array<StaticToolResult<TOOLS>>;
|
|
1208
1091
|
/**
|
|
1209
|
-
* The
|
|
1092
|
+
* The dynamic tool results that were made in the last step.
|
|
1210
1093
|
*/
|
|
1211
|
-
|
|
1212
|
-
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
1213
|
-
/**
|
|
1214
|
-
* The result type returned by a {@link PrepareStepFunction},
|
|
1215
|
-
* allowing per-step overrides of model, tools, or messages.
|
|
1216
|
-
*/
|
|
1217
|
-
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
1094
|
+
readonly dynamicToolResults: Array<DynamicToolResult>;
|
|
1218
1095
|
/**
|
|
1219
|
-
*
|
|
1096
|
+
* The unified reason why the generation finished.
|
|
1220
1097
|
*/
|
|
1221
|
-
|
|
1098
|
+
readonly finishReason: FinishReason;
|
|
1222
1099
|
/**
|
|
1223
|
-
*
|
|
1224
|
-
* for this step.
|
|
1100
|
+
* The raw reason why the generation finished (from the provider).
|
|
1225
1101
|
*/
|
|
1226
|
-
|
|
1102
|
+
readonly rawFinishReason: string | undefined;
|
|
1227
1103
|
/**
|
|
1228
|
-
*
|
|
1104
|
+
* The token usage of the last step.
|
|
1229
1105
|
*/
|
|
1230
|
-
|
|
1106
|
+
readonly usage: LanguageModelUsage;
|
|
1231
1107
|
/**
|
|
1232
|
-
*
|
|
1108
|
+
* The total token usage of all steps.
|
|
1109
|
+
* When there are multiple steps, the usage is the sum of all step usages.
|
|
1233
1110
|
*/
|
|
1234
|
-
|
|
1111
|
+
readonly totalUsage: LanguageModelUsage;
|
|
1235
1112
|
/**
|
|
1236
|
-
*
|
|
1237
|
-
* for this step.
|
|
1113
|
+
* Warnings from the model provider (e.g. unsupported settings)
|
|
1238
1114
|
*/
|
|
1239
|
-
|
|
1115
|
+
readonly warnings: CallWarning[] | undefined;
|
|
1240
1116
|
/**
|
|
1241
|
-
*
|
|
1117
|
+
* Additional request information.
|
|
1118
|
+
*/
|
|
1119
|
+
readonly request: LanguageModelRequestMetadata;
|
|
1120
|
+
/**
|
|
1121
|
+
* Additional response information.
|
|
1122
|
+
*/
|
|
1123
|
+
readonly response: LanguageModelResponseMetadata & {
|
|
1124
|
+
/**
|
|
1125
|
+
* The response messages that were generated during the call. It consists of an assistant message,
|
|
1126
|
+
* potentially containing tool calls.
|
|
1127
|
+
*
|
|
1128
|
+
* When there are tool results, there is an additional tool message with the tool results that are available.
|
|
1129
|
+
* If there are tools that do not have execute functions, they are not included in the tool results and
|
|
1130
|
+
* need to be added separately.
|
|
1131
|
+
*/
|
|
1132
|
+
messages: Array<ResponseMessage>;
|
|
1133
|
+
/**
|
|
1134
|
+
* Response body (available only for providers that use HTTP requests).
|
|
1135
|
+
*/
|
|
1136
|
+
body?: unknown;
|
|
1137
|
+
};
|
|
1138
|
+
/**
|
|
1139
|
+
* Additional provider-specific metadata. They are passed through
|
|
1140
|
+
* from the provider to the AI SDK and enable provider-specific
|
|
1141
|
+
* results that can be fully encapsulated in the provider.
|
|
1142
|
+
*/
|
|
1143
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
|
1144
|
+
/**
|
|
1145
|
+
* Details for all steps.
|
|
1146
|
+
* You can use this to get information about intermediate steps,
|
|
1147
|
+
* such as the tool calls or the response headers.
|
|
1148
|
+
*/
|
|
1149
|
+
readonly steps: Array<StepResult<TOOLS>>;
|
|
1150
|
+
/**
|
|
1151
|
+
* The generated structured output. It uses the `output` specification.
|
|
1242
1152
|
*
|
|
1243
|
-
*
|
|
1244
|
-
* and all subsequent steps.
|
|
1153
|
+
* @deprecated Use `output` instead.
|
|
1245
1154
|
*/
|
|
1246
|
-
|
|
1155
|
+
readonly experimental_output: InferCompleteOutput<OUTPUT>;
|
|
1247
1156
|
/**
|
|
1248
|
-
*
|
|
1157
|
+
* The generated structured output. It uses the `output` specification.
|
|
1249
1158
|
*
|
|
1250
|
-
* Can be used to pass provider-specific configuration such as
|
|
1251
|
-
* container IDs for Anthropic's code execution.
|
|
1252
1159
|
*/
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1160
|
+
readonly output: InferCompleteOutput<OUTPUT>;
|
|
1161
|
+
}
|
|
1255
1162
|
|
|
1256
1163
|
declare const symbol$j: unique symbol;
|
|
1257
1164
|
declare class InvalidToolInputError extends AISDKError {
|
|
@@ -1562,19 +1469,6 @@ declare function generateText<TOOLS extends ToolSet, OUTPUT extends Output = Out
|
|
|
1562
1469
|
};
|
|
1563
1470
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
1564
1471
|
|
|
1565
|
-
/**
|
|
1566
|
-
* Infers the complete output type from the output specification.
|
|
1567
|
-
*/
|
|
1568
|
-
type InferCompleteOutput<OUTPUT extends Output> = OUTPUT extends Output<infer COMPLETE_OUTPUT, any, any> ? COMPLETE_OUTPUT : never;
|
|
1569
|
-
/**
|
|
1570
|
-
* Infers the partial output type from the output specification.
|
|
1571
|
-
*/
|
|
1572
|
-
type InferPartialOutput<OUTPUT extends Output> = OUTPUT extends Output<any, infer PARTIAL_OUTPUT, any> ? PARTIAL_OUTPUT : never;
|
|
1573
|
-
/**
|
|
1574
|
-
* Infers the element type from an array output specification.
|
|
1575
|
-
*/
|
|
1576
|
-
type InferElementOutput<OUTPUT extends Output> = OUTPUT extends Output<any, any, infer ELEMENT> ? ELEMENT : never;
|
|
1577
|
-
|
|
1578
1472
|
/**
|
|
1579
1473
|
* Prunes model messages from a list of model messages.
|
|
1580
1474
|
*
|
|
@@ -3129,126 +3023,289 @@ declare namespace output {
|
|
|
3129
3023
|
}
|
|
3130
3024
|
|
|
3131
3025
|
/**
|
|
3132
|
-
*
|
|
3133
|
-
* It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
|
3026
|
+
* Common model information used across callback events.
|
|
3134
3027
|
*/
|
|
3135
|
-
interface
|
|
3136
|
-
/**
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
readonly
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
readonly
|
|
3158
|
-
/**
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
readonly
|
|
3162
|
-
/**
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
readonly
|
|
3166
|
-
/**
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
readonly
|
|
3170
|
-
/**
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
readonly
|
|
3028
|
+
interface CallbackModelInfo {
|
|
3029
|
+
/** The provider identifier (e.g., 'openai', 'anthropic'). */
|
|
3030
|
+
readonly provider: string;
|
|
3031
|
+
/** The specific model identifier (e.g., 'gpt-4o'). */
|
|
3032
|
+
readonly modelId: string;
|
|
3033
|
+
}
|
|
3034
|
+
/**
|
|
3035
|
+
* Event passed to the `onStart` callback.
|
|
3036
|
+
*
|
|
3037
|
+
* Called when the generation operation begins, before any LLM calls.
|
|
3038
|
+
*/
|
|
3039
|
+
interface OnStartEvent<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output, INCLUDE = {
|
|
3040
|
+
requestBody?: boolean;
|
|
3041
|
+
responseBody?: boolean;
|
|
3042
|
+
}> {
|
|
3043
|
+
/** The model being used for generation. */
|
|
3044
|
+
readonly model: CallbackModelInfo;
|
|
3045
|
+
/** The system message(s) provided to the model. */
|
|
3046
|
+
readonly system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
|
|
3047
|
+
/** The prompt string or array of messages if using the prompt option. */
|
|
3048
|
+
readonly prompt: string | Array<ModelMessage> | undefined;
|
|
3049
|
+
/** The messages array if using the messages option. */
|
|
3050
|
+
readonly messages: Array<ModelMessage> | undefined;
|
|
3051
|
+
/** The tools available for this generation. */
|
|
3052
|
+
readonly tools: TOOLS | undefined;
|
|
3053
|
+
/** The tool choice strategy for this generation. */
|
|
3054
|
+
readonly toolChoice: ToolChoice<NoInfer<TOOLS>> | undefined;
|
|
3055
|
+
/** Limits which tools are available for the model to call. */
|
|
3056
|
+
readonly activeTools: Array<keyof TOOLS> | undefined;
|
|
3057
|
+
/** Maximum number of tokens to generate. */
|
|
3058
|
+
readonly maxOutputTokens: number | undefined;
|
|
3059
|
+
/** Sampling temperature for generation. */
|
|
3060
|
+
readonly temperature: number | undefined;
|
|
3061
|
+
/** Top-p (nucleus) sampling parameter. */
|
|
3062
|
+
readonly topP: number | undefined;
|
|
3063
|
+
/** Top-k sampling parameter. */
|
|
3064
|
+
readonly topK: number | undefined;
|
|
3065
|
+
/** Presence penalty for generation. */
|
|
3066
|
+
readonly presencePenalty: number | undefined;
|
|
3067
|
+
/** Frequency penalty for generation. */
|
|
3068
|
+
readonly frequencyPenalty: number | undefined;
|
|
3069
|
+
/** Sequences that will stop generation. */
|
|
3070
|
+
readonly stopSequences: string[] | undefined;
|
|
3071
|
+
/** Random seed for reproducible generation. */
|
|
3072
|
+
readonly seed: number | undefined;
|
|
3073
|
+
/** Maximum number of retries for failed requests. */
|
|
3074
|
+
readonly maxRetries: number;
|
|
3174
3075
|
/**
|
|
3175
|
-
*
|
|
3076
|
+
* Timeout configuration for the generation.
|
|
3077
|
+
* Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.
|
|
3176
3078
|
*/
|
|
3177
|
-
readonly
|
|
3079
|
+
readonly timeout: TimeoutConfiguration | undefined;
|
|
3080
|
+
/** Additional HTTP headers sent with the request. */
|
|
3081
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
3082
|
+
/** Additional provider-specific options. */
|
|
3083
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
3178
3084
|
/**
|
|
3179
|
-
*
|
|
3085
|
+
* Condition(s) for stopping the generation.
|
|
3086
|
+
* When the condition is an array, any of the conditions can be met to stop.
|
|
3180
3087
|
*/
|
|
3181
|
-
readonly
|
|
3088
|
+
readonly stopWhen: StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined;
|
|
3089
|
+
/** The output specification for structured outputs, if configured. */
|
|
3090
|
+
readonly output: OUTPUT | undefined;
|
|
3091
|
+
/** Abort signal for cancelling the operation. */
|
|
3092
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
3182
3093
|
/**
|
|
3183
|
-
*
|
|
3094
|
+
* Settings for controlling what data is included in step results.
|
|
3184
3095
|
*/
|
|
3185
|
-
readonly
|
|
3096
|
+
readonly include: INCLUDE | undefined;
|
|
3097
|
+
/** Identifier from telemetry settings for grouping related operations. */
|
|
3098
|
+
readonly functionId: string | undefined;
|
|
3099
|
+
/** Additional metadata passed to the generation. */
|
|
3100
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
3186
3101
|
/**
|
|
3187
|
-
*
|
|
3102
|
+
* User-defined context object that flows through the entire generation lifecycle.
|
|
3103
|
+
* Can be accessed and modified in `prepareStep` and tool `execute` functions.
|
|
3188
3104
|
*/
|
|
3189
|
-
readonly
|
|
3105
|
+
readonly experimental_context: unknown;
|
|
3106
|
+
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Event passed to the `onStepStart` callback.
|
|
3109
|
+
*
|
|
3110
|
+
* Called when a step (LLM call) begins, before the provider is called.
|
|
3111
|
+
* Each step represents a single LLM invocation.
|
|
3112
|
+
*/
|
|
3113
|
+
interface OnStepStartEvent<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output, INCLUDE = {
|
|
3114
|
+
requestBody?: boolean;
|
|
3115
|
+
responseBody?: boolean;
|
|
3116
|
+
}> {
|
|
3117
|
+
/** Zero-based index of the current step. */
|
|
3118
|
+
readonly stepNumber: number;
|
|
3119
|
+
/** The model being used for this step. */
|
|
3120
|
+
readonly model: CallbackModelInfo;
|
|
3190
3121
|
/**
|
|
3191
|
-
* The
|
|
3122
|
+
* The system message for this step.
|
|
3192
3123
|
*/
|
|
3193
|
-
readonly
|
|
3124
|
+
readonly system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
|
|
3194
3125
|
/**
|
|
3195
|
-
* The
|
|
3126
|
+
* The messages that will be sent to the model for this step.
|
|
3127
|
+
* Uses the user-facing `ModelMessage` format.
|
|
3128
|
+
* May be overridden by prepareStep.
|
|
3196
3129
|
*/
|
|
3197
|
-
readonly
|
|
3130
|
+
readonly messages: Array<ModelMessage>;
|
|
3131
|
+
/** The tools available for this generation. */
|
|
3132
|
+
readonly tools: TOOLS | undefined;
|
|
3133
|
+
/** The tool choice configuration for this step. */
|
|
3134
|
+
readonly toolChoice: LanguageModelV3ToolChoice | undefined;
|
|
3135
|
+
/** Limits which tools are available for this step. */
|
|
3136
|
+
readonly activeTools: Array<keyof TOOLS> | undefined;
|
|
3137
|
+
/** Array of results from previous steps (empty for first step). */
|
|
3138
|
+
readonly steps: ReadonlyArray<StepResult<TOOLS>>;
|
|
3139
|
+
/** Additional provider-specific options for this step. */
|
|
3140
|
+
readonly providerOptions: ProviderOptions | undefined;
|
|
3198
3141
|
/**
|
|
3199
|
-
*
|
|
3200
|
-
*
|
|
3142
|
+
* Timeout configuration for the generation.
|
|
3143
|
+
* Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.
|
|
3201
3144
|
*/
|
|
3202
|
-
readonly
|
|
3145
|
+
readonly timeout: TimeoutConfiguration | undefined;
|
|
3146
|
+
/** Additional HTTP headers sent with the request. */
|
|
3147
|
+
readonly headers: Record<string, string | undefined> | undefined;
|
|
3203
3148
|
/**
|
|
3204
|
-
*
|
|
3149
|
+
* Condition(s) for stopping the generation.
|
|
3150
|
+
* When the condition is an array, any of the conditions can be met to stop.
|
|
3205
3151
|
*/
|
|
3206
|
-
readonly
|
|
3152
|
+
readonly stopWhen: StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined;
|
|
3153
|
+
/** The output specification for structured outputs, if configured. */
|
|
3154
|
+
readonly output: OUTPUT | undefined;
|
|
3155
|
+
/** Abort signal for cancelling the operation. */
|
|
3156
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
3207
3157
|
/**
|
|
3208
|
-
*
|
|
3158
|
+
* Settings for controlling what data is included in step results.
|
|
3209
3159
|
*/
|
|
3210
|
-
readonly
|
|
3160
|
+
readonly include: INCLUDE | undefined;
|
|
3161
|
+
/** Identifier from telemetry settings for grouping related operations. */
|
|
3162
|
+
readonly functionId: string | undefined;
|
|
3163
|
+
/** Additional metadata from telemetry settings. */
|
|
3164
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
3211
3165
|
/**
|
|
3212
|
-
*
|
|
3166
|
+
* User-defined context object. May be updated from `prepareStep` between steps.
|
|
3213
3167
|
*/
|
|
3214
|
-
readonly
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3168
|
+
readonly experimental_context: unknown;
|
|
3169
|
+
}
|
|
3170
|
+
/**
|
|
3171
|
+
* Event passed to the `onToolCallStart` callback.
|
|
3172
|
+
*
|
|
3173
|
+
* Called when a tool execution begins, before the tool's `execute` function is invoked.
|
|
3174
|
+
*/
|
|
3175
|
+
interface OnToolCallStartEvent<TOOLS extends ToolSet = ToolSet> {
|
|
3176
|
+
/** Zero-based index of the current step where this tool call occurs. */
|
|
3177
|
+
readonly stepNumber: number | undefined;
|
|
3178
|
+
/** The model being used for this step. */
|
|
3179
|
+
readonly model: CallbackModelInfo | undefined;
|
|
3180
|
+
/** The full tool call object. */
|
|
3181
|
+
readonly toolCall: TypedToolCall<TOOLS>;
|
|
3182
|
+
/** The conversation messages available at tool execution time. */
|
|
3183
|
+
readonly messages: Array<ModelMessage>;
|
|
3184
|
+
/** Signal for cancelling the operation. */
|
|
3185
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
3186
|
+
/** Identifier from telemetry settings for grouping related operations. */
|
|
3187
|
+
readonly functionId: string | undefined;
|
|
3188
|
+
/** Additional metadata from telemetry settings. */
|
|
3189
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
3190
|
+
/** User-defined context object flowing through the generation. */
|
|
3191
|
+
readonly experimental_context: unknown;
|
|
3192
|
+
}
|
|
3193
|
+
/**
|
|
3194
|
+
* Event passed to the `onToolCallFinish` callback.
|
|
3195
|
+
*
|
|
3196
|
+
* Called when a tool execution completes, either successfully or with an error.
|
|
3197
|
+
* Uses a discriminated union on the `success` field.
|
|
3198
|
+
*/
|
|
3199
|
+
type OnToolCallFinishEvent<TOOLS extends ToolSet = ToolSet> = {
|
|
3200
|
+
/** Zero-based index of the current step where this tool call occurred. */
|
|
3201
|
+
readonly stepNumber: number | undefined;
|
|
3202
|
+
/** The model being used for this step. */
|
|
3203
|
+
readonly model: CallbackModelInfo | undefined;
|
|
3204
|
+
/** The full tool call object. */
|
|
3205
|
+
readonly toolCall: TypedToolCall<TOOLS>;
|
|
3206
|
+
/** The conversation messages available at tool execution time. */
|
|
3207
|
+
readonly messages: Array<ModelMessage>;
|
|
3208
|
+
/** Signal for cancelling the operation. */
|
|
3209
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
3210
|
+
/** Execution time of the tool call in milliseconds. */
|
|
3211
|
+
readonly durationMs: number;
|
|
3212
|
+
/** Identifier from telemetry settings for grouping related operations. */
|
|
3213
|
+
readonly functionId: string | undefined;
|
|
3214
|
+
/** Additional metadata from telemetry settings. */
|
|
3215
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
3216
|
+
/** User-defined context object flowing through the generation. */
|
|
3217
|
+
readonly experimental_context: unknown;
|
|
3218
|
+
} & ({
|
|
3219
|
+
/** Indicates the tool call succeeded. */
|
|
3220
|
+
readonly success: true;
|
|
3221
|
+
/** The tool's return value. */
|
|
3222
|
+
readonly output: unknown;
|
|
3223
|
+
readonly error?: never;
|
|
3224
|
+
} | {
|
|
3225
|
+
/** Indicates the tool call failed. */
|
|
3226
|
+
readonly success: false;
|
|
3227
|
+
readonly output?: never;
|
|
3228
|
+
/** The error that occurred during tool execution. */
|
|
3229
|
+
readonly error: unknown;
|
|
3230
|
+
});
|
|
3231
|
+
/**
|
|
3232
|
+
* Event passed to the `onStepFinish` callback.
|
|
3233
|
+
*
|
|
3234
|
+
* Called when a step (LLM call) completes.
|
|
3235
|
+
* This is simply the StepResult for that step.
|
|
3236
|
+
*/
|
|
3237
|
+
type OnStepFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS>;
|
|
3238
|
+
/**
|
|
3239
|
+
* Event passed to the `onFinish` callback.
|
|
3240
|
+
*
|
|
3241
|
+
* Called when the entire generation completes (all steps finished).
|
|
3242
|
+
* Includes the final step's result along with aggregated data from all steps.
|
|
3243
|
+
*/
|
|
3244
|
+
type OnFinishEvent<TOOLS extends ToolSet = ToolSet> = StepResult<TOOLS> & {
|
|
3245
|
+
/** Array containing results from all steps in the generation. */
|
|
3246
|
+
readonly steps: StepResult<TOOLS>[];
|
|
3247
|
+
/** Aggregated token usage across all steps. */
|
|
3248
|
+
readonly totalUsage: LanguageModelUsage;
|
|
3229
3249
|
/**
|
|
3230
|
-
*
|
|
3231
|
-
*
|
|
3232
|
-
*
|
|
3250
|
+
* The final state of the user-defined context object.
|
|
3251
|
+
*
|
|
3252
|
+
* Experimental (can break in patch releases).
|
|
3253
|
+
*
|
|
3254
|
+
* @default undefined
|
|
3233
3255
|
*/
|
|
3234
|
-
|
|
3256
|
+
experimental_context: unknown;
|
|
3257
|
+
/** Identifier from telemetry settings for grouping related operations. */
|
|
3258
|
+
readonly functionId: string | undefined;
|
|
3259
|
+
/** Additional metadata from telemetry settings. */
|
|
3260
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
3261
|
+
};
|
|
3262
|
+
|
|
3263
|
+
/**
|
|
3264
|
+
* A callback function that can be used to notify listeners.
|
|
3265
|
+
*/
|
|
3266
|
+
type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;
|
|
3267
|
+
|
|
3268
|
+
/**
|
|
3269
|
+
* Implement this interface to create custom telemetry integrations.
|
|
3270
|
+
* Methods can be sync or return a PromiseLike.
|
|
3271
|
+
*/
|
|
3272
|
+
interface TelemetryIntegration {
|
|
3273
|
+
onStart?: Listener<OnStartEvent<ToolSet, Output>>;
|
|
3274
|
+
onStepStart?: Listener<OnStepStartEvent<ToolSet, Output>>;
|
|
3275
|
+
onToolCallStart?: Listener<OnToolCallStartEvent<ToolSet>>;
|
|
3276
|
+
onToolCallFinish?: Listener<OnToolCallFinishEvent<ToolSet>>;
|
|
3277
|
+
onStepFinish?: Listener<OnStepFinishEvent<ToolSet>>;
|
|
3278
|
+
onFinish?: Listener<OnFinishEvent<ToolSet>>;
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
declare global {
|
|
3235
3282
|
/**
|
|
3236
|
-
*
|
|
3237
|
-
*
|
|
3238
|
-
*
|
|
3283
|
+
* The default provider to use for the AI SDK.
|
|
3284
|
+
* String model ids are resolved to the default provider and model id.
|
|
3285
|
+
*
|
|
3286
|
+
* If not set, the default provider is the Vercel AI gateway provider.
|
|
3287
|
+
*
|
|
3288
|
+
* @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
|
|
3239
3289
|
*/
|
|
3240
|
-
|
|
3290
|
+
var AI_SDK_DEFAULT_PROVIDER: ProviderV3 | undefined;
|
|
3241
3291
|
/**
|
|
3242
|
-
* The
|
|
3292
|
+
* The warning logger to use for the AI SDK.
|
|
3243
3293
|
*
|
|
3244
|
-
*
|
|
3294
|
+
* If not set, the default logger is the console.warn function.
|
|
3295
|
+
*
|
|
3296
|
+
* If set to false, no warnings are logged.
|
|
3245
3297
|
*/
|
|
3246
|
-
|
|
3298
|
+
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
3247
3299
|
/**
|
|
3248
|
-
*
|
|
3300
|
+
* Globally registered telemetry integrations for the AI SDK.
|
|
3249
3301
|
*
|
|
3302
|
+
* Integrations registered here receive lifecycle events (onStart, onStepStart,
|
|
3303
|
+
* etc.) from every `generateText`, `streamText`, and similar call.
|
|
3304
|
+
*
|
|
3305
|
+
* Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
|
|
3306
|
+
* assigning this directly.
|
|
3250
3307
|
*/
|
|
3251
|
-
|
|
3308
|
+
var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
|
|
3252
3309
|
}
|
|
3253
3310
|
|
|
3254
3311
|
type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
|
|
@@ -5805,33 +5862,6 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
|
|
|
5805
5862
|
}>;
|
|
5806
5863
|
}): Promise<GenerateVideoResult>;
|
|
5807
5864
|
|
|
5808
|
-
/**
|
|
5809
|
-
* A function for logging warnings.
|
|
5810
|
-
*
|
|
5811
|
-
* You can assign it to the `AI_SDK_LOG_WARNINGS` global variable to use it as the default warning logger.
|
|
5812
|
-
*
|
|
5813
|
-
* @example
|
|
5814
|
-
* ```ts
|
|
5815
|
-
* globalThis.AI_SDK_LOG_WARNINGS = (options) => {
|
|
5816
|
-
* console.log('WARNINGS:', options.warnings, options.provider, options.model);
|
|
5817
|
-
* };
|
|
5818
|
-
* ```
|
|
5819
|
-
*/
|
|
5820
|
-
type LogWarningsFunction = (options: {
|
|
5821
|
-
/**
|
|
5822
|
-
* The warnings returned by the model provider.
|
|
5823
|
-
*/
|
|
5824
|
-
warnings: Warning[];
|
|
5825
|
-
/**
|
|
5826
|
-
* The provider id used for the call.
|
|
5827
|
-
*/
|
|
5828
|
-
provider: string;
|
|
5829
|
-
/**
|
|
5830
|
-
* The model id used for the call.
|
|
5831
|
-
*/
|
|
5832
|
-
model: string;
|
|
5833
|
-
}) => void;
|
|
5834
|
-
|
|
5835
5865
|
/**
|
|
5836
5866
|
* Applies default settings for an embedding model.
|
|
5837
5867
|
*/
|
|
@@ -6383,34 +6413,4 @@ declare function bindTelemetryIntegration(integration: TelemetryIntegration): Te
|
|
|
6383
6413
|
*/
|
|
6384
6414
|
declare function registerTelemetryIntegration(integration: TelemetryIntegration): void;
|
|
6385
6415
|
|
|
6386
|
-
declare global {
|
|
6387
|
-
/**
|
|
6388
|
-
* The default provider to use for the AI SDK.
|
|
6389
|
-
* String model ids are resolved to the default provider and model id.
|
|
6390
|
-
*
|
|
6391
|
-
* If not set, the default provider is the Vercel AI gateway provider.
|
|
6392
|
-
*
|
|
6393
|
-
* @see https://ai-sdk.dev/docs/ai-sdk-core/provider-management#global-provider-configuration
|
|
6394
|
-
*/
|
|
6395
|
-
var AI_SDK_DEFAULT_PROVIDER: ProviderV3 | undefined;
|
|
6396
|
-
/**
|
|
6397
|
-
* The warning logger to use for the AI SDK.
|
|
6398
|
-
*
|
|
6399
|
-
* If not set, the default logger is the console.warn function.
|
|
6400
|
-
*
|
|
6401
|
-
* If set to false, no warnings are logged.
|
|
6402
|
-
*/
|
|
6403
|
-
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
6404
|
-
/**
|
|
6405
|
-
* Globally registered telemetry integrations for the AI SDK.
|
|
6406
|
-
*
|
|
6407
|
-
* Integrations registered here receive lifecycle events (onStart, onStepStart,
|
|
6408
|
-
* etc.) from every `generateText`, `streamText`, and similar call.
|
|
6409
|
-
*
|
|
6410
|
-
* Prefer using `registerTelemetryIntegration()` from `'ai'` instead of
|
|
6411
|
-
* assigning this directly.
|
|
6412
|
-
*/
|
|
6413
|
-
var AI_SDK_TELEMETRY_INTEGRATIONS: TelemetryIntegration[] | undefined;
|
|
6414
|
-
}
|
|
6415
|
-
|
|
6416
6416
|
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isLoopFinished, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|