ai 7.0.142 → 7.0.143
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 +12 -0
- package/dist/index.d.ts +248 -203
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +203 -122
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +26 -16
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-ai-sdk-core/17-mcp-events.mdx +50 -0
- package/docs/03-ai-sdk-core/32-decisions.mdx +2 -1
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/02-stream-text-low-memory.mdx +107 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +6 -0
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +1 -1
- package/package.json +12 -12
- package/src/agent/tool-loop-agent.ts +7 -4
- package/src/decide/decision-result.ts +6 -1
- package/src/decide/validate-decision.ts +21 -1
- package/src/generate-text/stream-language-model-call.ts +32 -16
- package/src/generate-text/stream-text-single-consumer-result.ts +75 -0
- package/src/generate-text/stream-text.ts +250 -37
- package/src/ui/chat.ts +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.143
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8a5233b: Generate default chat IDs on first access so `useChat()` can prerender without reading a random value when the ID is not used during rendering.
|
|
8
|
+
- 894e130: fix(ai): add `experimental_lowMemory: true` to `streamText` for single-consumer streaming without a replay buffer or retained final-content results, reducing memory retention.
|
|
9
|
+
- 0957554: Add `box` decision question type with image bounds for TypeSafe AI.
|
|
10
|
+
- Updated dependencies [0957554]
|
|
11
|
+
- @ai-sdk/provider@4.0.29
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.62
|
|
13
|
+
- @ai-sdk/gateway@4.0.116
|
|
14
|
+
|
|
3
15
|
## 7.0.142
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -572,6 +572,16 @@ type DecisionAnswer<QUESTION extends Experimental_DecisionModelV4Question> = QUE
|
|
|
572
572
|
type: 'score';
|
|
573
573
|
score: number;
|
|
574
574
|
probabilities?: Record<string, number>;
|
|
575
|
+
} : QUESTION extends {
|
|
576
|
+
type: 'box';
|
|
577
|
+
} ? {
|
|
578
|
+
type: 'box';
|
|
579
|
+
box: {
|
|
580
|
+
top: number;
|
|
581
|
+
bottom: number;
|
|
582
|
+
left: number;
|
|
583
|
+
right: number;
|
|
584
|
+
};
|
|
575
585
|
} : {
|
|
576
586
|
type: 'boolean';
|
|
577
587
|
probability: number;
|
|
@@ -1794,205 +1804,6 @@ type OnLanguageModelCallStartCallback = Callback<LanguageModelCallStartEvent>;
|
|
|
1794
1804
|
*/
|
|
1795
1805
|
type OnLanguageModelCallEndCallback<TOOLS extends ToolSet$1 = ToolSet$1> = Callback<LanguageModelCallEndEvent<TOOLS>>;
|
|
1796
1806
|
//#endregion
|
|
1797
|
-
//#region src/generate-text/output-utils.d.ts
|
|
1798
|
-
/**
|
|
1799
|
-
* Infers the complete output type from the output specification.
|
|
1800
|
-
*/
|
|
1801
|
-
type InferCompleteOutput<OUTPUT extends Output> = OUTPUT extends Output<infer COMPLETE_OUTPUT, any, any> ? COMPLETE_OUTPUT : never;
|
|
1802
|
-
/**
|
|
1803
|
-
* Infers the partial output type from the output specification.
|
|
1804
|
-
*/
|
|
1805
|
-
type InferPartialOutput<OUTPUT extends Output> = OUTPUT extends Output<any, infer PARTIAL_OUTPUT, any> ? PARTIAL_OUTPUT : never;
|
|
1806
|
-
/**
|
|
1807
|
-
* Infers the element type from an array output specification.
|
|
1808
|
-
*/
|
|
1809
|
-
type InferElementOutput<OUTPUT extends Output> = OUTPUT extends Output<any, any, infer ELEMENT> ? ELEMENT : never;
|
|
1810
|
-
//#endregion
|
|
1811
|
-
//#region src/generate-text/tool-order.d.ts
|
|
1812
|
-
/**
|
|
1813
|
-
* Tool names that define the order in which tools are sent to the provider.
|
|
1814
|
-
*
|
|
1815
|
-
* Tool names are object keys at runtime, so the type is restricted to the
|
|
1816
|
-
* string keys of the configured tool set. The list can be partial; tools not
|
|
1817
|
-
* listed in `toolOrder` are sent after the listed tools, sorted alphabetically.
|
|
1818
|
-
*/
|
|
1819
|
-
type ToolOrder<TOOLS extends ToolSet$1> = ReadonlyArray<keyof TOOLS & string> | undefined;
|
|
1820
|
-
//#endregion
|
|
1821
|
-
//#region src/generate-text/prepare-step.d.ts
|
|
1822
|
-
/**
|
|
1823
|
-
* Function that you can use to provide different settings for a step.
|
|
1824
|
-
*
|
|
1825
|
-
* @param options - The options for the step.
|
|
1826
|
-
* @param options.steps - The steps that have been executed so far.
|
|
1827
|
-
* @param options.stepNumber - The number of the step that is being executed.
|
|
1828
|
-
* @param options.model - The model that is being used.
|
|
1829
|
-
* @param options.instructions - The instructions that will be sent to the model for the current step.
|
|
1830
|
-
* @param options.initialInstructions - The initial instructions that were passed into generateText or streamText.
|
|
1831
|
-
* @param options.messages - The messages that will be sent to the model for the current step. If you return a `messages` override, those messages carry forward to later steps.
|
|
1832
|
-
* @param options.initialMessages - The initial messages that were passed into generateText or streamText.
|
|
1833
|
-
* @param options.responseMessages - The response messages that have been accumulated from previous steps.
|
|
1834
|
-
* @param options.runtimeContext - The user-defined runtime context.
|
|
1835
|
-
*
|
|
1836
|
-
* @returns An object that contains the settings for the step.
|
|
1837
|
-
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1838
|
-
*/
|
|
1839
|
-
type PrepareStepFunction<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context> = (options: {
|
|
1840
|
-
/**
|
|
1841
|
-
* The steps that have been executed so far.
|
|
1842
|
-
*/
|
|
1843
|
-
steps: Array<StepResult<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>>;
|
|
1844
|
-
/**
|
|
1845
|
-
* The number of the step that is being executed.
|
|
1846
|
-
*/
|
|
1847
|
-
stepNumber: number;
|
|
1848
|
-
/**
|
|
1849
|
-
* The model instance that is being used for this step.
|
|
1850
|
-
*/
|
|
1851
|
-
model: LanguageModel;
|
|
1852
|
-
/**
|
|
1853
|
-
* The instructions that will be sent to the model for the current step.
|
|
1854
|
-
*/
|
|
1855
|
-
instructions: Instructions | undefined;
|
|
1856
|
-
/**
|
|
1857
|
-
* The initial instructions that were passed into generateText or streamText.
|
|
1858
|
-
*/
|
|
1859
|
-
initialInstructions: Instructions | undefined;
|
|
1860
|
-
/**
|
|
1861
|
-
* The messages that will be sent to the model for the current step.
|
|
1862
|
-
* If you return a `messages` override, those messages carry forward to later steps.
|
|
1863
|
-
*/
|
|
1864
|
-
messages: Array<ModelMessage$1>;
|
|
1865
|
-
/**
|
|
1866
|
-
* The initial messages that were passed into generateText or streamText.
|
|
1867
|
-
*/
|
|
1868
|
-
initialMessages: Array<ModelMessage$1>;
|
|
1869
|
-
/**
|
|
1870
|
-
* The response messages that have been accumulated from all previous steps.
|
|
1871
|
-
*/
|
|
1872
|
-
responseMessages: Array<ResponseMessage>;
|
|
1873
|
-
/**
|
|
1874
|
-
* Tool context.
|
|
1875
|
-
*/
|
|
1876
|
-
toolsContext: InferToolSetContext<TOOLS>;
|
|
1877
|
-
/**
|
|
1878
|
-
* User-defined runtime context.
|
|
1879
|
-
*/
|
|
1880
|
-
runtimeContext: RUNTIME_CONTEXT;
|
|
1881
|
-
/**
|
|
1882
|
-
* The sandbox environment that the step is operating in.
|
|
1883
|
-
*/
|
|
1884
|
-
experimental_sandbox?: Experimental_SandboxSession$1;
|
|
1885
|
-
}) => PromiseLike<PrepareStepResult<TOOLS, RUNTIME_CONTEXT>> | PrepareStepResult<TOOLS, RUNTIME_CONTEXT>;
|
|
1886
|
-
/**
|
|
1887
|
-
* The result type returned by a {@link PrepareStepFunction},
|
|
1888
|
-
* allowing per-step overrides of model call settings, model, tools,
|
|
1889
|
-
* instructions, or messages.
|
|
1890
|
-
*
|
|
1891
|
-
* Model call setting overrides apply only to the current step. Undefined
|
|
1892
|
-
* settings fall back to the outer call settings.
|
|
1893
|
-
*/
|
|
1894
|
-
type PrepareStepResult<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context> = ({
|
|
1895
|
-
/**
|
|
1896
|
-
* Optionally override which LanguageModel instance is used for this step.
|
|
1897
|
-
*/
|
|
1898
|
-
model?: LanguageModel;
|
|
1899
|
-
/**
|
|
1900
|
-
* Optionally set which tool the model must call, or provide tool call configuration
|
|
1901
|
-
* for this step.
|
|
1902
|
-
*/
|
|
1903
|
-
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
1904
|
-
/**
|
|
1905
|
-
* If provided, only these tools are enabled/available for this step.
|
|
1906
|
-
*/
|
|
1907
|
-
activeTools?: ActiveTools<NoInfer<TOOLS>>;
|
|
1908
|
-
/**
|
|
1909
|
-
* Optionally override the order in which tools are sent to the provider
|
|
1910
|
-
* for this step.
|
|
1911
|
-
*/
|
|
1912
|
-
toolOrder?: ToolOrder<NoInfer<TOOLS>>;
|
|
1913
|
-
/**
|
|
1914
|
-
* Optionally override the instructions sent to the model for this step.
|
|
1915
|
-
* The override carries forward to later steps.
|
|
1916
|
-
*/
|
|
1917
|
-
instructions?: Instructions;
|
|
1918
|
-
/**
|
|
1919
|
-
* Optionally override the instructions sent to the model for this step.
|
|
1920
|
-
*
|
|
1921
|
-
* @deprecated Use `instructions` instead.
|
|
1922
|
-
*/
|
|
1923
|
-
system?: Instructions;
|
|
1924
|
-
/**
|
|
1925
|
-
* Optionally override the full set of messages sent to the model
|
|
1926
|
-
* for this step. The override carries forward to later steps.
|
|
1927
|
-
*/
|
|
1928
|
-
messages?: Array<ModelMessage$1>;
|
|
1929
|
-
/**
|
|
1930
|
-
* Tool context.
|
|
1931
|
-
*
|
|
1932
|
-
* Changing the toolsContext will affect the toolsContext in this step
|
|
1933
|
-
* and all subsequent steps.
|
|
1934
|
-
*
|
|
1935
|
-
* The toolsContext is passed into tool execution.
|
|
1936
|
-
*/
|
|
1937
|
-
toolsContext?: InferToolSetContext<TOOLS>;
|
|
1938
|
-
/**
|
|
1939
|
-
* Runtime context.
|
|
1940
|
-
*
|
|
1941
|
-
* Changing the runtimeContext will affect the runtimeContext in this step
|
|
1942
|
-
* and all subsequent steps.
|
|
1943
|
-
*/
|
|
1944
|
-
runtimeContext?: RUNTIME_CONTEXT;
|
|
1945
|
-
/**
|
|
1946
|
-
* The sandbox environment that the step is operating in.
|
|
1947
|
-
*
|
|
1948
|
-
* Changing the sandbox will affect tool execution in this step only.
|
|
1949
|
-
*/
|
|
1950
|
-
experimental_sandbox?: Experimental_SandboxSession$1;
|
|
1951
|
-
/**
|
|
1952
|
-
* Additional provider-specific options for this step.
|
|
1953
|
-
*
|
|
1954
|
-
* Can be used to pass provider-specific configuration such as
|
|
1955
|
-
* container IDs for Anthropic's code execution.
|
|
1956
|
-
*/
|
|
1957
|
-
providerOptions?: ProviderOptions;
|
|
1958
|
-
} & LanguageModelCallOptions) | undefined;
|
|
1959
|
-
//#endregion
|
|
1960
|
-
//#region src/generate-text/stop-condition.d.ts
|
|
1961
|
-
/**
|
|
1962
|
-
* A predicate that decides whether a tool-calling loop should stop after the
|
|
1963
|
-
* current step.
|
|
1964
|
-
*
|
|
1965
|
-
* A tool calling loop continues until one of the following conditions is met:
|
|
1966
|
-
* - The model returns a finish reason other than `tool-calls`
|
|
1967
|
-
* - A tool without an execute function is called
|
|
1968
|
-
* - A tool call needs approval
|
|
1969
|
-
* - One of the provided stop conditions returns `true`
|
|
1970
|
-
*/
|
|
1971
|
-
type StopCondition<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context> = (options: {
|
|
1972
|
-
steps: Array<StepResult<TOOLS, RUNTIME_CONTEXT>>;
|
|
1973
|
-
}) => PromiseLike<boolean> | boolean;
|
|
1974
|
-
/**
|
|
1975
|
-
* Creates a stop condition that returns `true` when the number of completed
|
|
1976
|
-
* steps equals `stepCount`.
|
|
1977
|
-
*
|
|
1978
|
-
* @param stepCount - The number of steps to allow before stopping.
|
|
1979
|
-
*/
|
|
1980
|
-
export declare function isStepCount(stepCount: number): StopCondition<any, any>;
|
|
1981
|
-
/**
|
|
1982
|
-
* Creates a stop condition that never returns `true`.
|
|
1983
|
-
*
|
|
1984
|
-
* This lets the tool-calling loop continue until it reaches one of its
|
|
1985
|
-
* natural termination conditions.
|
|
1986
|
-
*/
|
|
1987
|
-
export declare function isLoopFinished(): StopCondition<any, any>;
|
|
1988
|
-
/**
|
|
1989
|
-
* Creates a stop condition that returns `true` when the most recent step
|
|
1990
|
-
* contains a tool call with any of the specified names.
|
|
1991
|
-
*
|
|
1992
|
-
* @param toolName - The names of the tools that should stop the loop.
|
|
1993
|
-
*/
|
|
1994
|
-
export declare function hasToolCall<TOOLS extends ToolSet$1>(...toolName: Array<keyof TOOLS | (string & {})>): StopCondition<TOOLS, any>;
|
|
1995
|
-
//#endregion
|
|
1996
1807
|
//#region src/ui/ui-messages.d.ts
|
|
1997
1808
|
/**
|
|
1998
1809
|
* The data types that can be used in the UI message for the UI message data parts.
|
|
@@ -2826,6 +2637,20 @@ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
|
|
2826
2637
|
//#region src/util/error-handler.d.ts
|
|
2827
2638
|
type ErrorHandler = (error: unknown) => void;
|
|
2828
2639
|
//#endregion
|
|
2640
|
+
//#region src/generate-text/output-utils.d.ts
|
|
2641
|
+
/**
|
|
2642
|
+
* Infers the complete output type from the output specification.
|
|
2643
|
+
*/
|
|
2644
|
+
type InferCompleteOutput<OUTPUT extends Output> = OUTPUT extends Output<infer COMPLETE_OUTPUT, any, any> ? COMPLETE_OUTPUT : never;
|
|
2645
|
+
/**
|
|
2646
|
+
* Infers the partial output type from the output specification.
|
|
2647
|
+
*/
|
|
2648
|
+
type InferPartialOutput<OUTPUT extends Output> = OUTPUT extends Output<any, infer PARTIAL_OUTPUT, any> ? PARTIAL_OUTPUT : never;
|
|
2649
|
+
/**
|
|
2650
|
+
* Infers the element type from an array output specification.
|
|
2651
|
+
*/
|
|
2652
|
+
type InferElementOutput<OUTPUT extends Output> = OUTPUT extends Output<any, any, infer ELEMENT> ? ELEMENT : never;
|
|
2653
|
+
//#endregion
|
|
2829
2654
|
//#region src/generate-text/tool-output-denied.d.ts
|
|
2830
2655
|
/**
|
|
2831
2656
|
* Tool output when the tool execution has been denied (for static tools).
|
|
@@ -3302,6 +3127,195 @@ type TextStreamRawPart = {
|
|
|
3302
3127
|
};
|
|
3303
3128
|
type TextStreamPart<TOOLS extends ToolSet$1> = TextStreamTextStartPart | TextStreamTextEndPart | TextStreamTextDeltaPart | TextStreamReasoningStartPart | TextStreamReasoningEndPart | TextStreamReasoningDeltaPart | TextStreamCustomPart | TextStreamToolInputStartPart | TextStreamToolInputEndPart | TextStreamToolInputDeltaPart | TextStreamSourcePart | TextStreamFilePart | TextStreamReasoningFilePart | TextStreamToolCallPart<TOOLS> | TextStreamToolResultPart<TOOLS> | TextStreamToolErrorPart<TOOLS> | TextStreamToolOutputDeniedPart<TOOLS> | TextStreamToolApprovalRequestPart<TOOLS> | TextStreamToolApprovalResponsePart<TOOLS> | TextStreamStartStepPart | TextStreamFinishStepPart | TextStreamStartPart | TextStreamFinishPart | TextStreamAbortPart | TextStreamErrorPart | TextStreamRawPart;
|
|
3304
3129
|
//#endregion
|
|
3130
|
+
//#region src/generate-text/stream-text-single-consumer-result.d.ts
|
|
3131
|
+
/** A single-consumer view of a text generation, without replay or final content getters. */
|
|
3132
|
+
type StreamTextSingleConsumerResult<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context, OUTPUT extends Output> = Pick<StreamTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>, 'textStream' | 'stream' | 'fullStream' | 'partialOutputStream' | 'elementStream' | 'totalUsage' | 'usage' | 'finishReason' | 'rawFinishReason' | 'consumeStream' | 'toUIMessageStream' | 'toUIMessageStreamResponse' | 'toTextStreamResponse' | 'pipeUIMessageStreamToResponse' | 'pipeTextStreamToResponse'>;
|
|
3133
|
+
//#endregion
|
|
3134
|
+
//#region src/generate-text/tool-order.d.ts
|
|
3135
|
+
/**
|
|
3136
|
+
* Tool names that define the order in which tools are sent to the provider.
|
|
3137
|
+
*
|
|
3138
|
+
* Tool names are object keys at runtime, so the type is restricted to the
|
|
3139
|
+
* string keys of the configured tool set. The list can be partial; tools not
|
|
3140
|
+
* listed in `toolOrder` are sent after the listed tools, sorted alphabetically.
|
|
3141
|
+
*/
|
|
3142
|
+
type ToolOrder<TOOLS extends ToolSet$1> = ReadonlyArray<keyof TOOLS & string> | undefined;
|
|
3143
|
+
//#endregion
|
|
3144
|
+
//#region src/generate-text/prepare-step.d.ts
|
|
3145
|
+
/**
|
|
3146
|
+
* Function that you can use to provide different settings for a step.
|
|
3147
|
+
*
|
|
3148
|
+
* @param options - The options for the step.
|
|
3149
|
+
* @param options.steps - The steps that have been executed so far.
|
|
3150
|
+
* @param options.stepNumber - The number of the step that is being executed.
|
|
3151
|
+
* @param options.model - The model that is being used.
|
|
3152
|
+
* @param options.instructions - The instructions that will be sent to the model for the current step.
|
|
3153
|
+
* @param options.initialInstructions - The initial instructions that were passed into generateText or streamText.
|
|
3154
|
+
* @param options.messages - The messages that will be sent to the model for the current step. If you return a `messages` override, those messages carry forward to later steps.
|
|
3155
|
+
* @param options.initialMessages - The initial messages that were passed into generateText or streamText.
|
|
3156
|
+
* @param options.responseMessages - The response messages that have been accumulated from previous steps.
|
|
3157
|
+
* @param options.runtimeContext - The user-defined runtime context.
|
|
3158
|
+
*
|
|
3159
|
+
* @returns An object that contains the settings for the step.
|
|
3160
|
+
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
3161
|
+
*/
|
|
3162
|
+
type PrepareStepFunction<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context> = (options: {
|
|
3163
|
+
/**
|
|
3164
|
+
* The steps that have been executed so far.
|
|
3165
|
+
*/
|
|
3166
|
+
steps: Array<StepResult<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>>;
|
|
3167
|
+
/**
|
|
3168
|
+
* The number of the step that is being executed.
|
|
3169
|
+
*/
|
|
3170
|
+
stepNumber: number;
|
|
3171
|
+
/**
|
|
3172
|
+
* The model instance that is being used for this step.
|
|
3173
|
+
*/
|
|
3174
|
+
model: LanguageModel;
|
|
3175
|
+
/**
|
|
3176
|
+
* The instructions that will be sent to the model for the current step.
|
|
3177
|
+
*/
|
|
3178
|
+
instructions: Instructions | undefined;
|
|
3179
|
+
/**
|
|
3180
|
+
* The initial instructions that were passed into generateText or streamText.
|
|
3181
|
+
*/
|
|
3182
|
+
initialInstructions: Instructions | undefined;
|
|
3183
|
+
/**
|
|
3184
|
+
* The messages that will be sent to the model for the current step.
|
|
3185
|
+
* If you return a `messages` override, those messages carry forward to later steps.
|
|
3186
|
+
*/
|
|
3187
|
+
messages: Array<ModelMessage$1>;
|
|
3188
|
+
/**
|
|
3189
|
+
* The initial messages that were passed into generateText or streamText.
|
|
3190
|
+
*/
|
|
3191
|
+
initialMessages: Array<ModelMessage$1>;
|
|
3192
|
+
/**
|
|
3193
|
+
* The response messages that have been accumulated from all previous steps.
|
|
3194
|
+
*/
|
|
3195
|
+
responseMessages: Array<ResponseMessage>;
|
|
3196
|
+
/**
|
|
3197
|
+
* Tool context.
|
|
3198
|
+
*/
|
|
3199
|
+
toolsContext: InferToolSetContext<TOOLS>;
|
|
3200
|
+
/**
|
|
3201
|
+
* User-defined runtime context.
|
|
3202
|
+
*/
|
|
3203
|
+
runtimeContext: RUNTIME_CONTEXT;
|
|
3204
|
+
/**
|
|
3205
|
+
* The sandbox environment that the step is operating in.
|
|
3206
|
+
*/
|
|
3207
|
+
experimental_sandbox?: Experimental_SandboxSession$1;
|
|
3208
|
+
}) => PromiseLike<PrepareStepResult<TOOLS, RUNTIME_CONTEXT>> | PrepareStepResult<TOOLS, RUNTIME_CONTEXT>;
|
|
3209
|
+
/**
|
|
3210
|
+
* The result type returned by a {@link PrepareStepFunction},
|
|
3211
|
+
* allowing per-step overrides of model call settings, model, tools,
|
|
3212
|
+
* instructions, or messages.
|
|
3213
|
+
*
|
|
3214
|
+
* Model call setting overrides apply only to the current step. Undefined
|
|
3215
|
+
* settings fall back to the outer call settings.
|
|
3216
|
+
*/
|
|
3217
|
+
type PrepareStepResult<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context> = ({
|
|
3218
|
+
/**
|
|
3219
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
3220
|
+
*/
|
|
3221
|
+
model?: LanguageModel;
|
|
3222
|
+
/**
|
|
3223
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
3224
|
+
* for this step.
|
|
3225
|
+
*/
|
|
3226
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
3227
|
+
/**
|
|
3228
|
+
* If provided, only these tools are enabled/available for this step.
|
|
3229
|
+
*/
|
|
3230
|
+
activeTools?: ActiveTools<NoInfer<TOOLS>>;
|
|
3231
|
+
/**
|
|
3232
|
+
* Optionally override the order in which tools are sent to the provider
|
|
3233
|
+
* for this step.
|
|
3234
|
+
*/
|
|
3235
|
+
toolOrder?: ToolOrder<NoInfer<TOOLS>>;
|
|
3236
|
+
/**
|
|
3237
|
+
* Optionally override the instructions sent to the model for this step.
|
|
3238
|
+
* The override carries forward to later steps.
|
|
3239
|
+
*/
|
|
3240
|
+
instructions?: Instructions;
|
|
3241
|
+
/**
|
|
3242
|
+
* Optionally override the instructions sent to the model for this step.
|
|
3243
|
+
*
|
|
3244
|
+
* @deprecated Use `instructions` instead.
|
|
3245
|
+
*/
|
|
3246
|
+
system?: Instructions;
|
|
3247
|
+
/**
|
|
3248
|
+
* Optionally override the full set of messages sent to the model
|
|
3249
|
+
* for this step. The override carries forward to later steps.
|
|
3250
|
+
*/
|
|
3251
|
+
messages?: Array<ModelMessage$1>;
|
|
3252
|
+
/**
|
|
3253
|
+
* Tool context.
|
|
3254
|
+
*
|
|
3255
|
+
* Changing the toolsContext will affect the toolsContext in this step
|
|
3256
|
+
* and all subsequent steps.
|
|
3257
|
+
*
|
|
3258
|
+
* The toolsContext is passed into tool execution.
|
|
3259
|
+
*/
|
|
3260
|
+
toolsContext?: InferToolSetContext<TOOLS>;
|
|
3261
|
+
/**
|
|
3262
|
+
* Runtime context.
|
|
3263
|
+
*
|
|
3264
|
+
* Changing the runtimeContext will affect the runtimeContext in this step
|
|
3265
|
+
* and all subsequent steps.
|
|
3266
|
+
*/
|
|
3267
|
+
runtimeContext?: RUNTIME_CONTEXT;
|
|
3268
|
+
/**
|
|
3269
|
+
* The sandbox environment that the step is operating in.
|
|
3270
|
+
*
|
|
3271
|
+
* Changing the sandbox will affect tool execution in this step only.
|
|
3272
|
+
*/
|
|
3273
|
+
experimental_sandbox?: Experimental_SandboxSession$1;
|
|
3274
|
+
/**
|
|
3275
|
+
* Additional provider-specific options for this step.
|
|
3276
|
+
*
|
|
3277
|
+
* Can be used to pass provider-specific configuration such as
|
|
3278
|
+
* container IDs for Anthropic's code execution.
|
|
3279
|
+
*/
|
|
3280
|
+
providerOptions?: ProviderOptions;
|
|
3281
|
+
} & LanguageModelCallOptions) | undefined;
|
|
3282
|
+
//#endregion
|
|
3283
|
+
//#region src/generate-text/stop-condition.d.ts
|
|
3284
|
+
/**
|
|
3285
|
+
* A predicate that decides whether a tool-calling loop should stop after the
|
|
3286
|
+
* current step.
|
|
3287
|
+
*
|
|
3288
|
+
* A tool calling loop continues until one of the following conditions is met:
|
|
3289
|
+
* - The model returns a finish reason other than `tool-calls`
|
|
3290
|
+
* - A tool without an execute function is called
|
|
3291
|
+
* - A tool call needs approval
|
|
3292
|
+
* - One of the provided stop conditions returns `true`
|
|
3293
|
+
*/
|
|
3294
|
+
type StopCondition<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context> = (options: {
|
|
3295
|
+
steps: Array<StepResult<TOOLS, RUNTIME_CONTEXT>>;
|
|
3296
|
+
}) => PromiseLike<boolean> | boolean;
|
|
3297
|
+
/**
|
|
3298
|
+
* Creates a stop condition that returns `true` when the number of completed
|
|
3299
|
+
* steps equals `stepCount`.
|
|
3300
|
+
*
|
|
3301
|
+
* @param stepCount - The number of steps to allow before stopping.
|
|
3302
|
+
*/
|
|
3303
|
+
export declare function isStepCount(stepCount: number): StopCondition<any, any>;
|
|
3304
|
+
/**
|
|
3305
|
+
* Creates a stop condition that never returns `true`.
|
|
3306
|
+
*
|
|
3307
|
+
* This lets the tool-calling loop continue until it reaches one of its
|
|
3308
|
+
* natural termination conditions.
|
|
3309
|
+
*/
|
|
3310
|
+
export declare function isLoopFinished(): StopCondition<any, any>;
|
|
3311
|
+
/**
|
|
3312
|
+
* Creates a stop condition that returns `true` when the most recent step
|
|
3313
|
+
* contains a tool call with any of the specified names.
|
|
3314
|
+
*
|
|
3315
|
+
* @param toolName - The names of the tools that should stop the loop.
|
|
3316
|
+
*/
|
|
3317
|
+
export declare function hasToolCall<TOOLS extends ToolSet$1>(...toolName: Array<keyof TOOLS | (string & {})>): StopCondition<TOOLS, any>;
|
|
3318
|
+
//#endregion
|
|
3305
3319
|
//#region src/generate-text/tool-approval-configuration.d.ts
|
|
3306
3320
|
/**
|
|
3307
3321
|
* The approval status of a tool configuration. This can be one of the following:
|
|
@@ -3617,6 +3631,13 @@ type ToolsContextParameter<TOOLS extends ToolSet$1> = {
|
|
|
3617
3631
|
} & ToolsContextSettings<TOOLS>;
|
|
3618
3632
|
//#endregion
|
|
3619
3633
|
//#region src/generate-text/stream-text.d.ts
|
|
3634
|
+
/** Internal policy, fixed before the model request starts. */
|
|
3635
|
+
type StreamTextRetention = {
|
|
3636
|
+
/** Keep a replay branch for independently consumed stream projections. */
|
|
3637
|
+
replay: boolean;
|
|
3638
|
+
/** Collect complete content for results, callbacks, or subsequent steps. */
|
|
3639
|
+
collectContent: boolean;
|
|
3640
|
+
};
|
|
3620
3641
|
type StreamTextInclude = {
|
|
3621
3642
|
/**
|
|
3622
3643
|
* Whether to retain the request body in step results.
|
|
@@ -3700,6 +3721,16 @@ type StreamTextOnEndCallback<TOOLS extends ToolSet$1 = ToolSet$1, RUNTIME_CONTEX
|
|
|
3700
3721
|
* @param event - The event that is passed to the callback.
|
|
3701
3722
|
*/
|
|
3702
3723
|
type StreamTextOnAbortCallback<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context> = Callback<GenerateTextAbortEvent<TOOLS, RUNTIME_CONTEXT>>;
|
|
3724
|
+
type StreamTextOptions<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context, OUTPUT extends Output> = Parameters<typeof streamTextInternal<TOOLS, RUNTIME_CONTEXT, OUTPUT>>[0] & {
|
|
3725
|
+
/**
|
|
3726
|
+
* Consume the stream once without replay or final-content getters.
|
|
3727
|
+
* Content is collected only when required by tools, output parsing,
|
|
3728
|
+
* full-content callbacks, or telemetry integrations.
|
|
3729
|
+
*
|
|
3730
|
+
* @default false
|
|
3731
|
+
*/
|
|
3732
|
+
experimental_lowMemory?: boolean;
|
|
3733
|
+
};
|
|
3703
3734
|
/**
|
|
3704
3735
|
* Generate a text and call tools for a given prompt using a language model.
|
|
3705
3736
|
*
|
|
@@ -3746,6 +3777,8 @@ type StreamTextOnAbortCallback<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends
|
|
|
3746
3777
|
* @param runtimeContext - User-defined runtime context that flows through the entire generation lifecycle.
|
|
3747
3778
|
* @param experimental_refineToolInput - Optional mapping of tool names to functions that refine parsed tool inputs before tools are executed and before outputs, callbacks, and telemetry are recorded.
|
|
3748
3779
|
*
|
|
3780
|
+
* @param experimental_lowMemory - Consume the stream once without replay or final-content getters. Default: false.
|
|
3781
|
+
*
|
|
3749
3782
|
* @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
|
3750
3783
|
* @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
|
3751
3784
|
* @param onStart - Callback invoked when generation begins, before any LLM calls.
|
|
@@ -3768,7 +3801,14 @@ type StreamTextOnAbortCallback<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends
|
|
|
3768
3801
|
* @returns
|
|
3769
3802
|
* A result object for accessing different stream types and additional information.
|
|
3770
3803
|
*/
|
|
3771
|
-
export declare function streamText<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output<string, string, never>>(
|
|
3804
|
+
export declare function streamText<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output<string, string, never>>(options: StreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT> & {
|
|
3805
|
+
experimental_lowMemory?: false;
|
|
3806
|
+
}): StreamTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
3807
|
+
export declare function streamText<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output<string, string, never>>(options: StreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT> & {
|
|
3808
|
+
experimental_lowMemory: true;
|
|
3809
|
+
}): StreamTextSingleConsumerResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
3810
|
+
export declare function streamText<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output<string, string, never>>(options: StreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT>): StreamTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT> | StreamTextSingleConsumerResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
3811
|
+
declare function streamTextInternal<TOOLS extends ToolSet$1, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output<string, string, never>>({ model, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries, streamRetries, abortSignal, timeout, headers, stopWhen, experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry, prepareStep, providerOptions, activeTools, toolOrder, toolCallConcurrency, experimental_repairToolCall, repairToolCall, experimental_refineToolInput: refineToolInput, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError: onErrorArg, onFinish, onEnd, onAbort, onStepEnd, onStepFinish, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, runtimeContext, toolsContext, experimental_include, include, _internal: { now, generateId, generateCallId, retention }, ...settings }: LanguageModelCallOptions & RequestOptions<TOOLS> & Prompt & ToolsContextParameter<TOOLS> & {
|
|
3772
3812
|
/**
|
|
3773
3813
|
* The language model to use.
|
|
3774
3814
|
*/
|
|
@@ -4046,6 +4086,8 @@ export declare function streamText<TOOLS extends ToolSet$1, RUNTIME_CONTEXT exte
|
|
|
4046
4086
|
now?: () => number;
|
|
4047
4087
|
generateId?: IdGenerator$1;
|
|
4048
4088
|
generateCallId?: IdGenerator$1;
|
|
4089
|
+
/** Internal policy used by the streaming-only facade. */
|
|
4090
|
+
retention?: StreamTextRetention;
|
|
4049
4091
|
};
|
|
4050
4092
|
}): StreamTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>;
|
|
4051
4093
|
type EnrichedStreamPart<TOOLS extends ToolSet$1, PARTIAL_OUTPUT> = {
|
|
@@ -6050,7 +6092,7 @@ type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
|
|
6050
6092
|
interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
6051
6093
|
/**
|
|
6052
6094
|
* A unique identifier for the chat. If not provided, a random one will be
|
|
6053
|
-
* generated.
|
|
6095
|
+
* generated when first accessed.
|
|
6054
6096
|
*/
|
|
6055
6097
|
id?: string;
|
|
6056
6098
|
messageMetadataSchema?: FlexibleSchema$1<UI_MESSAGE['metadata']>;
|
|
@@ -6093,7 +6135,8 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
|
6093
6135
|
}) => boolean | PromiseLike<boolean>;
|
|
6094
6136
|
}
|
|
6095
6137
|
export declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
6096
|
-
|
|
6138
|
+
private _id;
|
|
6139
|
+
get id(): string;
|
|
6097
6140
|
readonly generateId: IdGenerator$1;
|
|
6098
6141
|
protected state: ChatState<UI_MESSAGE>;
|
|
6099
6142
|
private messageMetadataSchema;
|
|
@@ -7137,7 +7180,7 @@ type LanguageModelStreamPart<TOOLS extends ToolSet$1 = ToolSet$1> = Exclude<Text
|
|
|
7137
7180
|
*
|
|
7138
7181
|
* @returns A stream of model call parts together with request and response metadata when available.
|
|
7139
7182
|
*/
|
|
7140
|
-
declare function streamLanguageModelCall<TOOLS extends ToolSet$1, OUTPUT extends Output = Output>({ model, tools, toolOrder, output, toolChoice, prompt, system, instructions, messages, allowSystemInMessages, download, abortSignal, headers, includeRawChunks, providerOptions, repairToolCall, refineToolInput, executeLanguageModelCallInTelemetryContext, callId, toolsContext, experimental_sandbox: sandbox, _internal: { generateId, generateCallId, now }, onStart, onLanguageModelCallStart, onLanguageModelCallEnd, ...callSettings }: {
|
|
7183
|
+
declare function streamLanguageModelCall<TOOLS extends ToolSet$1, OUTPUT extends Output = Output>({ model, tools, toolOrder, output, toolChoice, prompt, system, instructions, messages, allowSystemInMessages, download, abortSignal, headers, includeRawChunks, providerOptions, repairToolCall, refineToolInput, executeLanguageModelCallInTelemetryContext, callId, toolsContext, experimental_sandbox: sandbox, _internal: { generateId, generateCallId, now, collectContent }, onStart, onLanguageModelCallStart, onLanguageModelCallEnd, ...callSettings }: {
|
|
7141
7184
|
model: LanguageModel;
|
|
7142
7185
|
tools?: TOOLS;
|
|
7143
7186
|
toolOrder?: ToolOrder<TOOLS>;
|
|
@@ -7165,6 +7208,8 @@ declare function streamLanguageModelCall<TOOLS extends ToolSet$1, OUTPUT extends
|
|
|
7165
7208
|
generateId?: IdGenerator$1;
|
|
7166
7209
|
generateCallId?: IdGenerator$1;
|
|
7167
7210
|
now?: () => number;
|
|
7211
|
+
/** Internal: content is only needed by collectors and full-content callbacks. */
|
|
7212
|
+
collectContent?: boolean;
|
|
7168
7213
|
};
|
|
7169
7214
|
onLanguageModelCallStart?: Arrayable<OnLanguageModelCallStartCallback>;
|
|
7170
7215
|
onLanguageModelCallEnd?: Arrayable<OnLanguageModelCallEndCallback<TOOLS>>;
|