ai 7.0.91 → 7.0.93
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 +27 -0
- package/dist/index.d.ts +178 -159
- package/dist/index.js +143 -25
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +2 -2
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/03-agents/04-loop-control.mdx +5 -3
- package/docs/03-agents/07-workflow-agent.mdx +27 -6
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +15 -3
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +64 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +7 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +36 -35
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +36 -0
- package/docs/04-ai-sdk-ui/20-streaming-data.mdx +11 -6
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +14 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +30 -3
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +27 -1
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +4 -0
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +6 -1
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +42 -28
- package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +7 -0
- package/package.json +6 -6
- package/src/agent/tool-loop-agent-settings.ts +15 -0
- package/src/embed/embed-many.ts +27 -2
- package/src/error/no-image-generated-error.ts +9 -0
- package/src/generate-image/generate-image.ts +1 -1
- package/src/generate-text/generate-text-events.ts +1 -1
- package/src/generate-text/output.ts +111 -1
- package/src/generate-text/smooth-stream.ts +19 -4
- package/src/generate-text/stream-text.ts +2 -6
- package/src/ui/call-completion-api.ts +1 -1
- package/src/ui/chat.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +8 -2
- package/src/ui/http-chat-transport.ts +2 -2
- package/src/ui/validate-ui-messages.ts +14 -0
- package/src/util/async-iterable-stream.ts +1 -1
- package/src/util/data-url.ts +1 -1
- package/src/util/merge-abort-signals.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.93
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- df6c009: fix(ai): use new message ID when replacing a message in `sendMessage`
|
|
8
|
+
- 6ee74a3: fix(ai): preserve tool part titles when validating UI messages
|
|
9
|
+
- f13d371: fix(ai): preserve provider metadata when converting failed tool calls
|
|
10
|
+
- d4485fe: feat(ai): support minItems and maxItems in array outputs
|
|
11
|
+
- 4f201cc: chore(ai): formally include already supported `onLanguageModelCallStart` and `onLanguageModelCallEnd` in `ToolLoopAgentSettings` type
|
|
12
|
+
- 8cdb2a7: fix(ai): decode text data URLs in Node.js
|
|
13
|
+
- 0f2281e: fix(ai): reject embedding responses whose count does not match the input values
|
|
14
|
+
- fc8e8ac: fix(ai): preserve image call diagnostics when no image is generated
|
|
15
|
+
- ee8391e: fix(ai): support abort signals when the global AbortSignal is not a constructor
|
|
16
|
+
- Updated dependencies [3cfc1fc]
|
|
17
|
+
- @ai-sdk/gateway@4.0.75
|
|
18
|
+
|
|
19
|
+
## 7.0.92
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- a51cc94: fix(ai): preserve provider metadata from empty smooth stream deltas
|
|
24
|
+
- d1904d3: fix(ai): surface fallback errors for empty HTTP response bodies
|
|
25
|
+
- 84e5a79: fix(ai): skip `smoothStream` delays while the document is hidden
|
|
26
|
+
- a8e8ad0: fix(ai): expose call ID and abort reason in streamText onAbort callbacks
|
|
27
|
+
- Updated dependencies [a7e324b]
|
|
28
|
+
- @ai-sdk/gateway@4.0.74
|
|
29
|
+
|
|
3
30
|
## 7.0.91
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -3401,12 +3401,7 @@ type StreamTextOnEndCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT ex
|
|
|
3401
3401
|
*
|
|
3402
3402
|
* @param event - The event that is passed to the callback.
|
|
3403
3403
|
*/
|
|
3404
|
-
type StreamTextOnAbortCallback<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = Callback<
|
|
3405
|
-
/**
|
|
3406
|
-
* Details for all previously finished steps.
|
|
3407
|
-
*/
|
|
3408
|
-
readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
|
|
3409
|
-
}>;
|
|
3404
|
+
type StreamTextOnAbortCallback<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = Callback<GenerateTextAbortEvent<TOOLS, RUNTIME_CONTEXT>>;
|
|
3410
3405
|
/**
|
|
3411
3406
|
* Generate a text and call tools for a given prompt using a language model.
|
|
3412
3407
|
*
|
|
@@ -3819,13 +3814,23 @@ declare const object: <OBJECT>({ schema: inputSchema, name, description, }: {
|
|
|
3819
3814
|
* When the model generates a text response, it will return an array of elements.
|
|
3820
3815
|
*
|
|
3821
3816
|
* @param element - The schema of the array elements to generate.
|
|
3817
|
+
* @param minItems - Optional minimum number of elements to generate.
|
|
3818
|
+
* @param maxItems - Optional maximum number of elements to generate.
|
|
3822
3819
|
* @param name - Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
3823
3820
|
* @param description - Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g. via tool or schema description.
|
|
3824
3821
|
*
|
|
3825
3822
|
* @returns An output specification for generating an array of elements.
|
|
3826
3823
|
*/
|
|
3827
|
-
declare const array: <ELEMENT>({ element: inputElementSchema, name, description, }: {
|
|
3824
|
+
declare const array: <ELEMENT>({ element: inputElementSchema, minItems, maxItems, name, description, }: {
|
|
3828
3825
|
element: FlexibleSchema<ELEMENT>;
|
|
3826
|
+
/**
|
|
3827
|
+
* Optional minimum number of elements to generate.
|
|
3828
|
+
*/
|
|
3829
|
+
minItems?: number;
|
|
3830
|
+
/**
|
|
3831
|
+
* Optional maximum number of elements to generate.
|
|
3832
|
+
*/
|
|
3833
|
+
maxItems?: number;
|
|
3829
3834
|
/**
|
|
3830
3835
|
* Optional name of the output that should be generated.
|
|
3831
3836
|
* Used by some providers for additional LLM guidance, e.g. via tool or schema name.
|
|
@@ -4079,7 +4084,7 @@ type GenerateTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT exten
|
|
|
4079
4084
|
readonly finalStep: StepResult<TOOLS, RUNTIME_CONTEXT>;
|
|
4080
4085
|
};
|
|
4081
4086
|
/**
|
|
4082
|
-
* Event passed to
|
|
4087
|
+
* Event passed to an `onAbort` callback for text generation.
|
|
4083
4088
|
*
|
|
4084
4089
|
* Called when a streaming text generation operation is aborted before it
|
|
4085
4090
|
* completes.
|
|
@@ -5161,6 +5166,15 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, RUN
|
|
|
5161
5166
|
* @deprecated Use `onStepStart` instead.
|
|
5162
5167
|
*/
|
|
5163
5168
|
experimental_onStepStart?: GenerateTextOnStepStartCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>, NoInfer<OUTPUT>>;
|
|
5169
|
+
/**
|
|
5170
|
+
* Callback that is called immediately before the provider model call begins.
|
|
5171
|
+
*/
|
|
5172
|
+
onLanguageModelCallStart?: OnLanguageModelCallStartCallback;
|
|
5173
|
+
/**
|
|
5174
|
+
* Callback that is called after the model response has been normalized and parsed,
|
|
5175
|
+
* but before any client-side tool execution begins.
|
|
5176
|
+
*/
|
|
5177
|
+
onLanguageModelCallEnd?: OnLanguageModelCallEndCallback<NoInfer<TOOLS>>;
|
|
5164
5178
|
/**
|
|
5165
5179
|
* Callback that is called before each tool execution begins.
|
|
5166
5180
|
*/
|
|
@@ -6844,6 +6858,156 @@ declare class MissingToolResultsError extends AISDKError {
|
|
|
6844
6858
|
static isInstance(error: unknown): error is MissingToolResultsError;
|
|
6845
6859
|
}
|
|
6846
6860
|
|
|
6861
|
+
type ActiveToolSubset<TOOLS extends ToolSet | undefined, ACTIVE_TOOL_NAMES extends ActiveTools<NonNullable<TOOLS>>> = TOOLS extends undefined ? undefined : [ACTIVE_TOOL_NAMES] extends [NonNullable<ActiveTools<NonNullable<TOOLS>>>] ? Pick<NonNullable<TOOLS>, ACTIVE_TOOL_NAMES[number]> : TOOLS;
|
|
6862
|
+
/**
|
|
6863
|
+
* Filters the tools to only include the active tools.
|
|
6864
|
+
* When activeTools is provided, we only include the tools that are in the list.
|
|
6865
|
+
*
|
|
6866
|
+
* @param tools - The tools to filter.
|
|
6867
|
+
* @param activeTools - The active tools to include.
|
|
6868
|
+
* @returns The filtered tools.
|
|
6869
|
+
*/
|
|
6870
|
+
declare function filterActiveTools<TOOLS extends ToolSet | undefined, ACTIVE_TOOL_NAMES extends ActiveTools<NonNullable<TOOLS>>>({ tools, activeTools, }: {
|
|
6871
|
+
tools: TOOLS;
|
|
6872
|
+
activeTools: ACTIVE_TOOL_NAMES;
|
|
6873
|
+
}): ActiveToolSubset<TOOLS, ACTIVE_TOOL_NAMES>;
|
|
6874
|
+
|
|
6875
|
+
/**
|
|
6876
|
+
* Prunes model messages from a list of model messages.
|
|
6877
|
+
*
|
|
6878
|
+
* @param messages - The list of model messages to prune.
|
|
6879
|
+
* @param reasoning - How to remove reasoning content from assistant messages. Default is `'none'`.
|
|
6880
|
+
* @param toolCalls - How to prune tool call/results/approval content. Default is `[]`.
|
|
6881
|
+
* @param emptyMessages - Whether to keep or remove messages whose content is empty after pruning. Default is `'remove'`.
|
|
6882
|
+
*
|
|
6883
|
+
* @returns The pruned list of model messages.
|
|
6884
|
+
*/
|
|
6885
|
+
declare function pruneMessages({ messages, reasoning, toolCalls, emptyMessages, }: {
|
|
6886
|
+
messages: ModelMessage[];
|
|
6887
|
+
reasoning?: 'all' | 'before-last-message' | 'none';
|
|
6888
|
+
toolCalls?: 'all' | 'before-last-message' | `before-last-${number}-messages` | 'none' | Array<{
|
|
6889
|
+
type: 'all' | 'before-last-message' | `before-last-${number}-messages`;
|
|
6890
|
+
tools?: string[];
|
|
6891
|
+
}>;
|
|
6892
|
+
emptyMessages?: 'keep' | 'remove';
|
|
6893
|
+
}): ModelMessage[];
|
|
6894
|
+
|
|
6895
|
+
/**
|
|
6896
|
+
* Detects the first chunk in a buffer.
|
|
6897
|
+
*
|
|
6898
|
+
* @param buffer - The buffer to detect the first chunk in.
|
|
6899
|
+
*
|
|
6900
|
+
* @returns The first detected chunk, or `undefined` if no chunk was detected.
|
|
6901
|
+
*/
|
|
6902
|
+
type ChunkDetector = (buffer: string) => string | undefined | null;
|
|
6903
|
+
/**
|
|
6904
|
+
* Smooths text and reasoning streaming output.
|
|
6905
|
+
*
|
|
6906
|
+
* @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay. The delay is skipped while the document is hidden (e.g. browser background tabs), where timer throttling would otherwise stall the stream.
|
|
6907
|
+
* @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, provide a custom RegExp pattern that does not match the empty string for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
|
|
6908
|
+
*
|
|
6909
|
+
* @returns A transform stream that smooths text streaming output.
|
|
6910
|
+
*/
|
|
6911
|
+
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
|
6912
|
+
delayInMs?: number | null;
|
|
6913
|
+
chunking?: 'word' | 'line' | RegExp | ChunkDetector | Intl.Segmenter;
|
|
6914
|
+
/**
|
|
6915
|
+
* Internal. For test use only. May change without notice.
|
|
6916
|
+
*/
|
|
6917
|
+
_internal?: {
|
|
6918
|
+
delay?: (delayInMs: number | null) => Promise<void>;
|
|
6919
|
+
};
|
|
6920
|
+
}): (options: {
|
|
6921
|
+
tools: TOOLS;
|
|
6922
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
6923
|
+
|
|
6924
|
+
/**
|
|
6925
|
+
* Fingerprint the server-controlled, security-relevant fields of each tool in a
|
|
6926
|
+
* `ToolSet`: `description` (string form only), the resolved input JSON schema,
|
|
6927
|
+
* and `title`. Returns a map of tool name to a stable digest.
|
|
6928
|
+
*
|
|
6929
|
+
* Capture a baseline at trust time (first connect, human-reviewed) and compare
|
|
6930
|
+
* later fetches with {@link detectToolDrift} to catch MCP tool-definition drift
|
|
6931
|
+
* ("rug pull"). Baseline storage and the drift response are the app's concern.
|
|
6932
|
+
*/
|
|
6933
|
+
declare function fingerprintTools(tools: ToolSet): Promise<Record<string, string>>;
|
|
6934
|
+
/**
|
|
6935
|
+
* Pure diff of two fingerprint maps produced by {@link fingerprintTools}.
|
|
6936
|
+
* `added`/`removed` are tools present in only one map; `changed` are tools whose
|
|
6937
|
+
* pinned definition differs. Uses own-property lookups so a tool literally named
|
|
6938
|
+
* `constructor` or `toString` diffs correctly.
|
|
6939
|
+
*/
|
|
6940
|
+
declare function detectToolDrift(current: Record<string, string>, baseline: Record<string, string>): {
|
|
6941
|
+
added: string[];
|
|
6942
|
+
removed: string[];
|
|
6943
|
+
changed: string[];
|
|
6944
|
+
};
|
|
6945
|
+
|
|
6946
|
+
/**
|
|
6947
|
+
* The result of one underlying image model call.
|
|
6948
|
+
*/
|
|
6949
|
+
interface GenerateImageCall {
|
|
6950
|
+
/**
|
|
6951
|
+
* The images generated by this call.
|
|
6952
|
+
*/
|
|
6953
|
+
readonly images: Array<GeneratedFile>;
|
|
6954
|
+
/**
|
|
6955
|
+
* Provider-specific metadata for this call.
|
|
6956
|
+
*/
|
|
6957
|
+
readonly providerMetadata?: ImageModelV4ProviderMetadata;
|
|
6958
|
+
/**
|
|
6959
|
+
* Response metadata from the provider.
|
|
6960
|
+
*/
|
|
6961
|
+
readonly response: ImageModelResponseMetadata;
|
|
6962
|
+
/**
|
|
6963
|
+
* Warnings for this call, e.g. unsupported settings.
|
|
6964
|
+
*/
|
|
6965
|
+
readonly warnings: Array<Warning>;
|
|
6966
|
+
/**
|
|
6967
|
+
* Token usage for this call, if reported by the provider.
|
|
6968
|
+
*/
|
|
6969
|
+
readonly usage?: ImageModelUsage;
|
|
6970
|
+
}
|
|
6971
|
+
/**
|
|
6972
|
+
* The result of a `generateImage` call.
|
|
6973
|
+
* It contains the images and additional information.
|
|
6974
|
+
*/
|
|
6975
|
+
interface GenerateImageResult {
|
|
6976
|
+
/**
|
|
6977
|
+
* The first image that was generated.
|
|
6978
|
+
*/
|
|
6979
|
+
readonly image: GeneratedFile;
|
|
6980
|
+
/**
|
|
6981
|
+
* The images that were generated.
|
|
6982
|
+
*/
|
|
6983
|
+
readonly images: Array<GeneratedFile>;
|
|
6984
|
+
/**
|
|
6985
|
+
* The results of the underlying image model calls.
|
|
6986
|
+
*/
|
|
6987
|
+
readonly calls: Array<GenerateImageCall>;
|
|
6988
|
+
/**
|
|
6989
|
+
* Warnings for the call, e.g. unsupported settings.
|
|
6990
|
+
*/
|
|
6991
|
+
readonly warnings: Array<Warning>;
|
|
6992
|
+
/**
|
|
6993
|
+
* Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
|
6994
|
+
*
|
|
6995
|
+
* @deprecated Use `calls` to preserve each response with its corresponding images, metadata, warnings, and usage.
|
|
6996
|
+
*/
|
|
6997
|
+
readonly responses: Array<ImageModelResponseMetadata>;
|
|
6998
|
+
/**
|
|
6999
|
+
* Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
|
|
7000
|
+
* results that can be fully encapsulated in the provider.
|
|
7001
|
+
*
|
|
7002
|
+
* @deprecated Use the provider metadata in `calls` or on individual `images` to preserve its scope.
|
|
7003
|
+
*/
|
|
7004
|
+
readonly providerMetadata: ImageModelProviderMetadata;
|
|
7005
|
+
/**
|
|
7006
|
+
* Combined token usage across all underlying provider calls for this image generation.
|
|
7007
|
+
*/
|
|
7008
|
+
readonly usage: ImageModelUsage;
|
|
7009
|
+
}
|
|
7010
|
+
|
|
6847
7011
|
declare const symbol$f: unique symbol;
|
|
6848
7012
|
/**
|
|
6849
7013
|
* Thrown when no image could be generated. This can have multiple causes:
|
|
@@ -6853,13 +7017,18 @@ declare const symbol$f: unique symbol;
|
|
|
6853
7017
|
*/
|
|
6854
7018
|
declare class NoImageGeneratedError extends AISDKError {
|
|
6855
7019
|
private readonly [symbol$f];
|
|
7020
|
+
/**
|
|
7021
|
+
* The results of the underlying image model calls.
|
|
7022
|
+
*/
|
|
7023
|
+
readonly calls: Array<GenerateImageCall> | undefined;
|
|
6856
7024
|
/**
|
|
6857
7025
|
* The response metadata for each call.
|
|
6858
7026
|
*/
|
|
6859
7027
|
readonly responses: Array<ImageModelResponseMetadata> | undefined;
|
|
6860
|
-
constructor({ message, cause, responses, }: {
|
|
7028
|
+
constructor({ message, cause, calls, responses, }: {
|
|
6861
7029
|
message?: string;
|
|
6862
7030
|
cause?: Error;
|
|
7031
|
+
calls?: Array<GenerateImageCall>;
|
|
6863
7032
|
responses?: Array<ImageModelResponseMetadata>;
|
|
6864
7033
|
});
|
|
6865
7034
|
static isInstance(error: unknown): error is NoImageGeneratedError;
|
|
@@ -7217,156 +7386,6 @@ declare class RetryError extends AISDKError {
|
|
|
7217
7386
|
static isInstance(error: unknown): error is RetryError;
|
|
7218
7387
|
}
|
|
7219
7388
|
|
|
7220
|
-
type ActiveToolSubset<TOOLS extends ToolSet | undefined, ACTIVE_TOOL_NAMES extends ActiveTools<NonNullable<TOOLS>>> = TOOLS extends undefined ? undefined : [ACTIVE_TOOL_NAMES] extends [NonNullable<ActiveTools<NonNullable<TOOLS>>>] ? Pick<NonNullable<TOOLS>, ACTIVE_TOOL_NAMES[number]> : TOOLS;
|
|
7221
|
-
/**
|
|
7222
|
-
* Filters the tools to only include the active tools.
|
|
7223
|
-
* When activeTools is provided, we only include the tools that are in the list.
|
|
7224
|
-
*
|
|
7225
|
-
* @param tools - The tools to filter.
|
|
7226
|
-
* @param activeTools - The active tools to include.
|
|
7227
|
-
* @returns The filtered tools.
|
|
7228
|
-
*/
|
|
7229
|
-
declare function filterActiveTools<TOOLS extends ToolSet | undefined, ACTIVE_TOOL_NAMES extends ActiveTools<NonNullable<TOOLS>>>({ tools, activeTools, }: {
|
|
7230
|
-
tools: TOOLS;
|
|
7231
|
-
activeTools: ACTIVE_TOOL_NAMES;
|
|
7232
|
-
}): ActiveToolSubset<TOOLS, ACTIVE_TOOL_NAMES>;
|
|
7233
|
-
|
|
7234
|
-
/**
|
|
7235
|
-
* Prunes model messages from a list of model messages.
|
|
7236
|
-
*
|
|
7237
|
-
* @param messages - The list of model messages to prune.
|
|
7238
|
-
* @param reasoning - How to remove reasoning content from assistant messages. Default is `'none'`.
|
|
7239
|
-
* @param toolCalls - How to prune tool call/results/approval content. Default is `[]`.
|
|
7240
|
-
* @param emptyMessages - Whether to keep or remove messages whose content is empty after pruning. Default is `'remove'`.
|
|
7241
|
-
*
|
|
7242
|
-
* @returns The pruned list of model messages.
|
|
7243
|
-
*/
|
|
7244
|
-
declare function pruneMessages({ messages, reasoning, toolCalls, emptyMessages, }: {
|
|
7245
|
-
messages: ModelMessage[];
|
|
7246
|
-
reasoning?: 'all' | 'before-last-message' | 'none';
|
|
7247
|
-
toolCalls?: 'all' | 'before-last-message' | `before-last-${number}-messages` | 'none' | Array<{
|
|
7248
|
-
type: 'all' | 'before-last-message' | `before-last-${number}-messages`;
|
|
7249
|
-
tools?: string[];
|
|
7250
|
-
}>;
|
|
7251
|
-
emptyMessages?: 'keep' | 'remove';
|
|
7252
|
-
}): ModelMessage[];
|
|
7253
|
-
|
|
7254
|
-
/**
|
|
7255
|
-
* Detects the first chunk in a buffer.
|
|
7256
|
-
*
|
|
7257
|
-
* @param buffer - The buffer to detect the first chunk in.
|
|
7258
|
-
*
|
|
7259
|
-
* @returns The first detected chunk, or `undefined` if no chunk was detected.
|
|
7260
|
-
*/
|
|
7261
|
-
type ChunkDetector = (buffer: string) => string | undefined | null;
|
|
7262
|
-
/**
|
|
7263
|
-
* Smooths text and reasoning streaming output.
|
|
7264
|
-
*
|
|
7265
|
-
* @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
|
|
7266
|
-
* @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, provide a custom RegExp pattern that does not match the empty string for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
|
|
7267
|
-
*
|
|
7268
|
-
* @returns A transform stream that smooths text streaming output.
|
|
7269
|
-
*/
|
|
7270
|
-
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
|
7271
|
-
delayInMs?: number | null;
|
|
7272
|
-
chunking?: 'word' | 'line' | RegExp | ChunkDetector | Intl.Segmenter;
|
|
7273
|
-
/**
|
|
7274
|
-
* Internal. For test use only. May change without notice.
|
|
7275
|
-
*/
|
|
7276
|
-
_internal?: {
|
|
7277
|
-
delay?: (delayInMs: number | null) => Promise<void>;
|
|
7278
|
-
};
|
|
7279
|
-
}): (options: {
|
|
7280
|
-
tools: TOOLS;
|
|
7281
|
-
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
|
7282
|
-
|
|
7283
|
-
/**
|
|
7284
|
-
* Fingerprint the server-controlled, security-relevant fields of each tool in a
|
|
7285
|
-
* `ToolSet`: `description` (string form only), the resolved input JSON schema,
|
|
7286
|
-
* and `title`. Returns a map of tool name to a stable digest.
|
|
7287
|
-
*
|
|
7288
|
-
* Capture a baseline at trust time (first connect, human-reviewed) and compare
|
|
7289
|
-
* later fetches with {@link detectToolDrift} to catch MCP tool-definition drift
|
|
7290
|
-
* ("rug pull"). Baseline storage and the drift response are the app's concern.
|
|
7291
|
-
*/
|
|
7292
|
-
declare function fingerprintTools(tools: ToolSet): Promise<Record<string, string>>;
|
|
7293
|
-
/**
|
|
7294
|
-
* Pure diff of two fingerprint maps produced by {@link fingerprintTools}.
|
|
7295
|
-
* `added`/`removed` are tools present in only one map; `changed` are tools whose
|
|
7296
|
-
* pinned definition differs. Uses own-property lookups so a tool literally named
|
|
7297
|
-
* `constructor` or `toString` diffs correctly.
|
|
7298
|
-
*/
|
|
7299
|
-
declare function detectToolDrift(current: Record<string, string>, baseline: Record<string, string>): {
|
|
7300
|
-
added: string[];
|
|
7301
|
-
removed: string[];
|
|
7302
|
-
changed: string[];
|
|
7303
|
-
};
|
|
7304
|
-
|
|
7305
|
-
/**
|
|
7306
|
-
* The result of one underlying image model call.
|
|
7307
|
-
*/
|
|
7308
|
-
interface GenerateImageCall {
|
|
7309
|
-
/**
|
|
7310
|
-
* The images generated by this call.
|
|
7311
|
-
*/
|
|
7312
|
-
readonly images: Array<GeneratedFile>;
|
|
7313
|
-
/**
|
|
7314
|
-
* Provider-specific metadata for this call.
|
|
7315
|
-
*/
|
|
7316
|
-
readonly providerMetadata?: ImageModelV4ProviderMetadata;
|
|
7317
|
-
/**
|
|
7318
|
-
* Response metadata from the provider.
|
|
7319
|
-
*/
|
|
7320
|
-
readonly response: ImageModelResponseMetadata;
|
|
7321
|
-
/**
|
|
7322
|
-
* Warnings for this call, e.g. unsupported settings.
|
|
7323
|
-
*/
|
|
7324
|
-
readonly warnings: Array<Warning>;
|
|
7325
|
-
/**
|
|
7326
|
-
* Token usage for this call, if reported by the provider.
|
|
7327
|
-
*/
|
|
7328
|
-
readonly usage?: ImageModelUsage;
|
|
7329
|
-
}
|
|
7330
|
-
/**
|
|
7331
|
-
* The result of a `generateImage` call.
|
|
7332
|
-
* It contains the images and additional information.
|
|
7333
|
-
*/
|
|
7334
|
-
interface GenerateImageResult {
|
|
7335
|
-
/**
|
|
7336
|
-
* The first image that was generated.
|
|
7337
|
-
*/
|
|
7338
|
-
readonly image: GeneratedFile;
|
|
7339
|
-
/**
|
|
7340
|
-
* The images that were generated.
|
|
7341
|
-
*/
|
|
7342
|
-
readonly images: Array<GeneratedFile>;
|
|
7343
|
-
/**
|
|
7344
|
-
* The results of the underlying image model calls.
|
|
7345
|
-
*/
|
|
7346
|
-
readonly calls: Array<GenerateImageCall>;
|
|
7347
|
-
/**
|
|
7348
|
-
* Warnings for the call, e.g. unsupported settings.
|
|
7349
|
-
*/
|
|
7350
|
-
readonly warnings: Array<Warning>;
|
|
7351
|
-
/**
|
|
7352
|
-
* Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
|
7353
|
-
*
|
|
7354
|
-
* @deprecated Use `calls` to preserve each response with its corresponding images, metadata, warnings, and usage.
|
|
7355
|
-
*/
|
|
7356
|
-
readonly responses: Array<ImageModelResponseMetadata>;
|
|
7357
|
-
/**
|
|
7358
|
-
* Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
|
|
7359
|
-
* results that can be fully encapsulated in the provider.
|
|
7360
|
-
*
|
|
7361
|
-
* @deprecated Use the provider metadata in `calls` or on individual `images` to preserve its scope.
|
|
7362
|
-
*/
|
|
7363
|
-
readonly providerMetadata: ImageModelProviderMetadata;
|
|
7364
|
-
/**
|
|
7365
|
-
* Combined token usage across all underlying provider calls for this image generation.
|
|
7366
|
-
*/
|
|
7367
|
-
readonly usage: ImageModelUsage;
|
|
7368
|
-
}
|
|
7369
|
-
|
|
7370
7389
|
type GenerateImagePrompt = string | {
|
|
7371
7390
|
images: Array<DataContent>;
|
|
7372
7391
|
text?: string;
|