@tanstack/ai 0.35.0 → 0.36.0
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/package.json +2 -2
- package/skills/ai-core/tool-calling/SKILL.md +26 -1
- package/src/activities/chat/index.ts +8 -0
- package/src/activities/chat/tools/lazy-tool-manager.ts +12 -4
- package/src/activities/chat/tools/lazy-tools.ts +33 -0
- package/src/index.ts +5 -0
- package/src/types.ts +23 -1
- package/dist/esm/activities/chat/adapter.d.ts +0 -163
- package/dist/esm/activities/chat/adapter.js +0 -17
- package/dist/esm/activities/chat/adapter.js.map +0 -1
- package/dist/esm/activities/chat/agent-loop-strategies.d.ts +0 -59
- package/dist/esm/activities/chat/agent-loop-strategies.js +0 -23
- package/dist/esm/activities/chat/agent-loop-strategies.js.map +0 -1
- package/dist/esm/activities/chat/index.d.ts +0 -264
- package/dist/esm/activities/chat/index.js +0 -1723
- package/dist/esm/activities/chat/index.js.map +0 -1
- package/dist/esm/activities/chat/mcp/manager.d.ts +0 -25
- package/dist/esm/activities/chat/mcp/manager.js +0 -71
- package/dist/esm/activities/chat/mcp/manager.js.map +0 -1
- package/dist/esm/activities/chat/mcp/types.d.ts +0 -56
- package/dist/esm/activities/chat/messages.d.ts +0 -78
- package/dist/esm/activities/chat/messages.js +0 -374
- package/dist/esm/activities/chat/messages.js.map +0 -1
- package/dist/esm/activities/chat/middleware/builder.d.ts +0 -46
- package/dist/esm/activities/chat/middleware/builder.js +0 -17
- package/dist/esm/activities/chat/middleware/builder.js.map +0 -1
- package/dist/esm/activities/chat/middleware/capabilities.d.ts +0 -93
- package/dist/esm/activities/chat/middleware/capabilities.js +0 -45
- package/dist/esm/activities/chat/middleware/capabilities.js.map +0 -1
- package/dist/esm/activities/chat/middleware/compose.d.ts +0 -87
- package/dist/esm/activities/chat/middleware/compose.js +0 -510
- package/dist/esm/activities/chat/middleware/compose.js.map +0 -1
- package/dist/esm/activities/chat/middleware/define.d.ts +0 -20
- package/dist/esm/activities/chat/middleware/define.js +0 -7
- package/dist/esm/activities/chat/middleware/define.js.map +0 -1
- package/dist/esm/activities/chat/middleware/index.d.ts +0 -10
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.d.ts +0 -89
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.js +0 -76
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.js.map +0 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +0 -405
- package/dist/esm/activities/chat/middleware/validate.d.ts +0 -19
- package/dist/esm/activities/chat/middleware/validate.js +0 -30
- package/dist/esm/activities/chat/middleware/validate.js.map +0 -1
- package/dist/esm/activities/chat/runtime-context-types.d.ts +0 -43
- package/dist/esm/activities/chat/stream/index.d.ts +0 -11
- package/dist/esm/activities/chat/stream/json-parser.d.ts +0 -38
- package/dist/esm/activities/chat/stream/json-parser.js +0 -28
- package/dist/esm/activities/chat/stream/json-parser.js.map +0 -1
- package/dist/esm/activities/chat/stream/message-updaters.d.ts +0 -81
- package/dist/esm/activities/chat/stream/message-updaters.js +0 -253
- package/dist/esm/activities/chat/stream/message-updaters.js.map +0 -1
- package/dist/esm/activities/chat/stream/processor.d.ts +0 -439
- package/dist/esm/activities/chat/stream/processor.js +0 -1426
- package/dist/esm/activities/chat/stream/processor.js.map +0 -1
- package/dist/esm/activities/chat/stream/strategies.d.ts +0 -43
- package/dist/esm/activities/chat/stream/strategies.js +0 -54
- package/dist/esm/activities/chat/stream/strategies.js.map +0 -1
- package/dist/esm/activities/chat/stream/types.d.ts +0 -90
- package/dist/esm/activities/chat/tools/lazy-tool-manager.d.ts +0 -81
- package/dist/esm/activities/chat/tools/lazy-tool-manager.js +0 -188
- package/dist/esm/activities/chat/tools/lazy-tool-manager.js.map +0 -1
- package/dist/esm/activities/chat/tools/schema-converter.d.ts +0 -140
- package/dist/esm/activities/chat/tools/schema-converter.js +0 -167
- package/dist/esm/activities/chat/tools/schema-converter.js.map +0 -1
- package/dist/esm/activities/chat/tools/tool-calls.d.ts +0 -140
- package/dist/esm/activities/chat/tools/tool-calls.js +0 -512
- package/dist/esm/activities/chat/tools/tool-calls.js.map +0 -1
- package/dist/esm/activities/chat/tools/tool-definition.d.ts +0 -135
- package/dist/esm/activities/chat/tools/tool-definition.js +0 -25
- package/dist/esm/activities/chat/tools/tool-definition.js.map +0 -1
- package/dist/esm/activities/error-payload.d.ts +0 -30
- package/dist/esm/activities/error-payload.js +0 -54
- package/dist/esm/activities/error-payload.js.map +0 -1
- package/dist/esm/activities/generateAudio/adapter.d.ts +0 -62
- package/dist/esm/activities/generateAudio/adapter.js +0 -16
- package/dist/esm/activities/generateAudio/adapter.js.map +0 -1
- package/dist/esm/activities/generateAudio/index.d.ts +0 -85
- package/dist/esm/activities/generateAudio/index.js +0 -114
- package/dist/esm/activities/generateAudio/index.js.map +0 -1
- package/dist/esm/activities/generateImage/adapter.d.ts +0 -78
- package/dist/esm/activities/generateImage/adapter.js +0 -16
- package/dist/esm/activities/generateImage/adapter.js.map +0 -1
- package/dist/esm/activities/generateImage/index.d.ts +0 -134
- package/dist/esm/activities/generateImage/index.js +0 -121
- package/dist/esm/activities/generateImage/index.js.map +0 -1
- package/dist/esm/activities/generateSpeech/adapter.d.ts +0 -62
- package/dist/esm/activities/generateSpeech/adapter.js +0 -16
- package/dist/esm/activities/generateSpeech/adapter.js.map +0 -1
- package/dist/esm/activities/generateSpeech/index.d.ts +0 -96
- package/dist/esm/activities/generateSpeech/index.js +0 -119
- package/dist/esm/activities/generateSpeech/index.js.map +0 -1
- package/dist/esm/activities/generateTranscription/adapter.d.ts +0 -62
- package/dist/esm/activities/generateTranscription/adapter.js +0 -16
- package/dist/esm/activities/generateTranscription/adapter.js.map +0 -1
- package/dist/esm/activities/generateTranscription/index.d.ts +0 -109
- package/dist/esm/activities/generateTranscription/index.js +0 -109
- package/dist/esm/activities/generateTranscription/index.js.map +0 -1
- package/dist/esm/activities/generateVideo/adapter.d.ts +0 -145
- package/dist/esm/activities/generateVideo/adapter.js +0 -30
- package/dist/esm/activities/generateVideo/adapter.js.map +0 -1
- package/dist/esm/activities/generateVideo/index.d.ts +0 -223
- package/dist/esm/activities/generateVideo/index.js +0 -295
- package/dist/esm/activities/generateVideo/index.js.map +0 -1
- package/dist/esm/activities/generateVideo/snap.d.ts +0 -14
- package/dist/esm/activities/generateVideo/snap.js +0 -54
- package/dist/esm/activities/generateVideo/snap.js.map +0 -1
- package/dist/esm/activities/index.d.ts +0 -27
- package/dist/esm/activities/index.js +0 -43
- package/dist/esm/activities/index.js.map +0 -1
- package/dist/esm/activities/middleware/index.d.ts +0 -2
- package/dist/esm/activities/middleware/run.d.ts +0 -20
- package/dist/esm/activities/middleware/run.js +0 -42
- package/dist/esm/activities/middleware/run.js.map +0 -1
- package/dist/esm/activities/middleware/types.d.ts +0 -118
- package/dist/esm/activities/stream-generation-result.d.ts +0 -15
- package/dist/esm/activities/stream-generation-result.js +0 -49
- package/dist/esm/activities/stream-generation-result.js.map +0 -1
- package/dist/esm/activities/summarize/adapter.d.ts +0 -74
- package/dist/esm/activities/summarize/adapter.js +0 -16
- package/dist/esm/activities/summarize/adapter.js.map +0 -1
- package/dist/esm/activities/summarize/chat-stream-summarize.d.ts +0 -45
- package/dist/esm/activities/summarize/chat-stream-summarize.js +0 -212
- package/dist/esm/activities/summarize/chat-stream-summarize.js.map +0 -1
- package/dist/esm/activities/summarize/index.d.ts +0 -108
- package/dist/esm/activities/summarize/index.js +0 -113
- package/dist/esm/activities/summarize/index.js.map +0 -1
- package/dist/esm/adapter-internals.d.ts +0 -5
- package/dist/esm/adapter-internals.js +0 -10
- package/dist/esm/adapter-internals.js.map +0 -1
- package/dist/esm/client.d.ts +0 -44
- package/dist/esm/client.js +0 -67
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/extend-adapter.d.ts +0 -152
- package/dist/esm/extend-adapter.js +0 -21
- package/dist/esm/extend-adapter.js.map +0 -1
- package/dist/esm/index.d.ts +0 -44
- package/dist/esm/index.js +0 -106
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/logger/console-logger.d.ts +0 -29
- package/dist/esm/logger/console-logger.js +0 -83
- package/dist/esm/logger/console-logger.js.map +0 -1
- package/dist/esm/logger/internal-logger.d.ts +0 -41
- package/dist/esm/logger/internal-logger.js +0 -86
- package/dist/esm/logger/internal-logger.js.map +0 -1
- package/dist/esm/logger/resolve.d.ts +0 -14
- package/dist/esm/logger/resolve.js +0 -54
- package/dist/esm/logger/resolve.js.map +0 -1
- package/dist/esm/logger/types.d.ts +0 -75
- package/dist/esm/middlewares/content-guard.d.ts +0 -77
- package/dist/esm/middlewares/content-guard.js +0 -156
- package/dist/esm/middlewares/content-guard.js.map +0 -1
- package/dist/esm/middlewares/index.d.ts +0 -2
- package/dist/esm/middlewares/index.js +0 -7
- package/dist/esm/middlewares/index.js.map +0 -1
- package/dist/esm/middlewares/otel.d.ts +0 -81
- package/dist/esm/middlewares/otel.js +0 -745
- package/dist/esm/middlewares/otel.js.map +0 -1
- package/dist/esm/middlewares/tool-cache.d.ts +0 -1
- package/dist/esm/middlewares/usage-attributes.d.ts +0 -24
- package/dist/esm/middlewares/usage-attributes.js +0 -43
- package/dist/esm/middlewares/usage-attributes.js.map +0 -1
- package/dist/esm/realtime/index.d.ts +0 -28
- package/dist/esm/realtime/index.js +0 -8
- package/dist/esm/realtime/index.js.map +0 -1
- package/dist/esm/realtime/types.d.ts +0 -282
- package/dist/esm/stream-to-response.d.ts +0 -102
- package/dist/esm/stream-to-response.js +0 -121
- package/dist/esm/stream-to-response.js.map +0 -1
- package/dist/esm/strip-to-spec-middleware.d.ts +0 -18
- package/dist/esm/strip-to-spec-middleware.js +0 -20
- package/dist/esm/strip-to-spec-middleware.js.map +0 -1
- package/dist/esm/system-prompts.d.ts +0 -66
- package/dist/esm/system-prompts.js +0 -23
- package/dist/esm/system-prompts.js.map +0 -1
- package/dist/esm/tool-registry.d.ts +0 -81
- package/dist/esm/tool-registry.js +0 -49
- package/dist/esm/tool-registry.js.map +0 -1
- package/dist/esm/tools/provider-tool.d.ts +0 -30
- package/dist/esm/tools/provider-tool.js +0 -7
- package/dist/esm/tools/provider-tool.js.map +0 -1
- package/dist/esm/types.d.ts +0 -1573
- package/dist/esm/utilities/ag-ui-wire.d.ts +0 -44
- package/dist/esm/utilities/ag-ui-wire.js +0 -107
- package/dist/esm/utilities/ag-ui-wire.js.map +0 -1
- package/dist/esm/utilities/chat-params.d.ts +0 -85
- package/dist/esm/utilities/chat-params.js +0 -100
- package/dist/esm/utilities/chat-params.js.map +0 -1
- package/dist/esm/utilities/errors.d.ts +0 -13
- package/dist/esm/utilities/errors.js +0 -22
- package/dist/esm/utilities/errors.js.map +0 -1
- package/dist/esm/utilities/media-prompt.d.ts +0 -35
- package/dist/esm/utilities/media-prompt.js +0 -43
- package/dist/esm/utilities/media-prompt.js.map +0 -1
- package/dist/esm/utilities/numbers.d.ts +0 -8
- package/dist/esm/utilities/numbers.js +0 -12
- package/dist/esm/utilities/numbers.js.map +0 -1
- package/dist/esm/utilities/sampling-keys.d.ts +0 -20
- package/dist/esm/utilities/sampling-keys.js +0 -20
- package/dist/esm/utilities/sampling-keys.js.map +0 -1
- package/dist/esm/utilities/tool-result.d.ts +0 -21
- package/dist/esm/utilities/tool-result.js +0 -37
- package/dist/esm/utilities/tool-result.js.map +0 -1
- package/dist/esm/utilities/usage.d.ts +0 -31
- package/dist/esm/utilities/usage.js +0 -11
- package/dist/esm/utilities/usage.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -17
- package/dist/esm/utils.js +0 -20
- package/dist/esm/utils.js.map +0 -1
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { AnyTextAdapter } from './adapter.js';
|
|
2
|
-
import { AnyTool, ConstrainedModelMessage, InferSchemaType, ModelMessage, SchemaInput, StreamChunk, StructuredOutputStream, TextOptions, UIMessage } from '../../types.js';
|
|
3
|
-
import { AnyChatMiddleware, ChatMiddleware } from './middleware/types.js';
|
|
4
|
-
import { CheckCoverage } from './middleware/builder.js';
|
|
5
|
-
import { SystemPrompt } from '../../system-prompts.js';
|
|
6
|
-
import { DebugOption } from '../../logger/types.js';
|
|
7
|
-
import { ProviderTool } from '../../tools/provider-tool.js';
|
|
8
|
-
import { ContextFromMiddleware, ContextFromTool, DefinedContext, MergeContext, UnionToIntersection } from './runtime-context-types.js';
|
|
9
|
-
import { ChatMCPOptions } from './mcp/types.js';
|
|
10
|
-
/** The adapter kind this activity handles */
|
|
11
|
-
export declare const kind: "text";
|
|
12
|
-
type AnyRuntimeTool = AnyTool;
|
|
13
|
-
type ContextFromConsumer<T> = ContextFromTool<T> | ContextFromMiddleware<T>;
|
|
14
|
-
type RequiredContextFromConsumerUnion<T> = T extends unknown ? undefined extends ContextFromConsumer<T> ? never : ContextFromConsumer<T> : never;
|
|
15
|
-
type ContextFromConsumerUnion<T> = [
|
|
16
|
-
UnionToIntersection<DefinedContext<ContextFromConsumer<T>>>
|
|
17
|
-
] extends [never] ? never : [RequiredContextFromConsumerUnion<T>] extends [never] ? UnionToIntersection<DefinedContext<ContextFromConsumer<T>>> | undefined : UnionToIntersection<DefinedContext<ContextFromConsumer<T>>>;
|
|
18
|
-
type ContextFromArray<T> = T extends readonly [infer THead, ...infer TTail] ? MergeContext<ContextFromConsumer<THead>, ContextFromArray<TTail>> : T extends ReadonlyArray<infer TItem> ? ContextFromConsumerUnion<TItem> : never;
|
|
19
|
-
type ContextFromInputs<TTools, TMiddleware> = MergeContext<ContextFromArray<NonNullable<TTools>>, ContextFromArray<NonNullable<TMiddleware>>>;
|
|
20
|
-
type InferredContext<TTools, TMiddleware> = [
|
|
21
|
-
ContextFromInputs<TTools, TMiddleware>
|
|
22
|
-
] extends [never] ? unknown : ContextFromInputs<TTools, TMiddleware>;
|
|
23
|
-
type RequiredContextFromInputs<TTools, TMiddleware> = [
|
|
24
|
-
ContextFromInputs<TTools, TMiddleware>
|
|
25
|
-
] extends [never] ? {
|
|
26
|
-
context?: unknown;
|
|
27
|
-
} : undefined extends ContextFromInputs<TTools, TMiddleware> ? {
|
|
28
|
-
context?: ContextFromInputs<TTools, TMiddleware>;
|
|
29
|
-
} : {
|
|
30
|
-
context: ContextFromInputs<TTools, TMiddleware>;
|
|
31
|
-
};
|
|
32
|
-
type TextActivityOptionsWithContext<TAdapter extends AnyTextAdapter, TSchema extends SchemaInput | undefined, TStream extends boolean, TTools extends TextActivityOptions<TAdapter, TSchema, TStream, any>['tools'], TMiddleware extends TextActivityOptions<TAdapter, TSchema, TStream, any>['middleware']> = Omit<TextActivityOptions<TAdapter, TSchema, TStream, any>, 'tools' | 'middleware' | 'context'> & {
|
|
33
|
-
tools?: TTools;
|
|
34
|
-
middleware?: TMiddleware & CheckCoverage<Extract<TMiddleware, ReadonlyArray<AnyChatMiddleware>>>;
|
|
35
|
-
} & RequiredContextFromInputs<TTools, TMiddleware>;
|
|
36
|
-
/**
|
|
37
|
-
* Options for the text activity.
|
|
38
|
-
* Types are extracted directly from the adapter (which has pre-resolved generics).
|
|
39
|
-
*
|
|
40
|
-
* @template TAdapter - The text adapter type (created by a provider function)
|
|
41
|
-
* @template TSchema - Optional Standard Schema for structured output
|
|
42
|
-
* @template TStream - Whether to stream the output (default: true)
|
|
43
|
-
*/
|
|
44
|
-
export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema extends SchemaInput | undefined, TStream extends boolean, TContext = unknown> {
|
|
45
|
-
/** The text adapter to use (created by a provider function like openaiText('gpt-4o')) */
|
|
46
|
-
adapter: TAdapter;
|
|
47
|
-
/**
|
|
48
|
-
* Conversation messages. Accepts:
|
|
49
|
-
* - `ConstrainedModelMessage` — content types constrained by the adapter's input modalities.
|
|
50
|
-
* - `ModelMessage` — unconstrained model message (e.g., forwarded from an AG-UI wire payload).
|
|
51
|
-
* - `UIMessage` — parts-based UI representation; converted internally via `convertMessagesToModelMessages`.
|
|
52
|
-
*
|
|
53
|
-
* The three shapes can be mixed in a single array (e.g., when forwarding a wire payload that includes both anchor UIMessages and AG-UI fan-out ModelMessages).
|
|
54
|
-
*/
|
|
55
|
-
messages?: Array<UIMessage | ModelMessage | ConstrainedModelMessage<{
|
|
56
|
-
inputModalities: TAdapter['~types']['inputModalities'];
|
|
57
|
-
messageMetadataByModality: TAdapter['~types']['messageMetadataByModality'];
|
|
58
|
-
}>> | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* System prompts to prepend to the conversation.
|
|
61
|
-
*
|
|
62
|
-
* Accepts plain strings or `{ content, metadata }` objects. The `metadata`
|
|
63
|
-
* field is typed by the adapter — Anthropic narrows it to
|
|
64
|
-
* `AnthropicSystemPromptMetadata` (with `cache_control` for prompt
|
|
65
|
-
* caching), providers without per-prompt metadata reject the field
|
|
66
|
-
* entirely.
|
|
67
|
-
*/
|
|
68
|
-
systemPrompts?: Array<SystemPrompt<TAdapter['~types']['systemPromptMetadata']>> | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Tools for function calling (auto-executed when called).
|
|
71
|
-
*
|
|
72
|
-
* Accepts two shapes:
|
|
73
|
-
* - User-defined tools via `toolDefinition()` — plain `Tool`, always assignable.
|
|
74
|
-
* - Provider tools from `@tanstack/ai-<provider>/tools` (e.g. `webSearchTool`)
|
|
75
|
-
* — branded and type-checked against the selected model's
|
|
76
|
-
* `supports.tools` list. Passing an unsupported tool produces a
|
|
77
|
-
* compile-time error on the array element.
|
|
78
|
-
*/
|
|
79
|
-
tools?: Array<(AnyRuntimeTool & {
|
|
80
|
-
readonly '~toolKind'?: never;
|
|
81
|
-
}) | ProviderTool<string, TAdapter['~types']['toolCapabilities'][number]>> | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* Hand MCP clients/pools to chat(): their tools are discovered at run start
|
|
84
|
-
* and merged into the run; `connection` controls whether chat() closes them
|
|
85
|
-
* when the run ends. See docs/tools/mcp.md "Managing MCP clients with chat()".
|
|
86
|
-
*/
|
|
87
|
-
mcp?: ChatMCPOptions;
|
|
88
|
-
/** Additional metadata to attach to the request. */
|
|
89
|
-
metadata?: TextOptions['metadata'];
|
|
90
|
-
/** Model-specific provider options (type comes from adapter) */
|
|
91
|
-
modelOptions?: TAdapter['~types']['providerOptions'];
|
|
92
|
-
/** AbortController for cancellation */
|
|
93
|
-
abortController?: TextOptions['abortController'];
|
|
94
|
-
/** Strategy for controlling the agent loop */
|
|
95
|
-
agentLoopStrategy?: TextOptions['agentLoopStrategy'];
|
|
96
|
-
/** Unique conversation identifier for tracking */
|
|
97
|
-
conversationId?: TextOptions['conversationId'];
|
|
98
|
-
/** Thread/conversation ID for AG-UI protocol. Auto-generated if not provided. */
|
|
99
|
-
threadId?: TextOptions['threadId'];
|
|
100
|
-
/** Run ID override for AG-UI protocol. Auto-generated by adapter if not provided. */
|
|
101
|
-
runId?: TextOptions['runId'];
|
|
102
|
-
/** Parent run ID for AG-UI protocol nested run correlation. */
|
|
103
|
-
parentRunId?: TextOptions['parentRunId'];
|
|
104
|
-
/**
|
|
105
|
-
* Optional Standard Schema for structured output.
|
|
106
|
-
* When provided, the activity will:
|
|
107
|
-
* 1. Run the full agentic loop (executing tools as needed)
|
|
108
|
-
* 2. Once complete, return a Promise with the parsed output matching the schema
|
|
109
|
-
*
|
|
110
|
-
* Supports any Standard Schema compliant library (Zod v4+, ArkType, Valibot, etc.)
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```ts
|
|
114
|
-
* const result = await chat({
|
|
115
|
-
* adapter: openaiText('gpt-4o'),
|
|
116
|
-
* messages: [{ role: 'user', content: 'Generate a person' }],
|
|
117
|
-
* outputSchema: z.object({ name: z.string(), age: z.number() })
|
|
118
|
-
* })
|
|
119
|
-
* // result is { name: string, age: number }
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
outputSchema?: TSchema;
|
|
123
|
-
/**
|
|
124
|
-
* Whether to stream the text result.
|
|
125
|
-
* When true (default), returns an AsyncIterable<StreamChunk> for streaming output.
|
|
126
|
-
* When false, returns a Promise<string> with the collected text content.
|
|
127
|
-
*
|
|
128
|
-
* Note: If outputSchema is provided, this option is ignored and the result
|
|
129
|
-
* is always a Promise<InferSchemaType<TSchema>>.
|
|
130
|
-
*
|
|
131
|
-
* @default true
|
|
132
|
-
*
|
|
133
|
-
* @example Non-streaming text
|
|
134
|
-
* ```ts
|
|
135
|
-
* const text = await chat({
|
|
136
|
-
* adapter: openaiText('gpt-4o'),
|
|
137
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
138
|
-
* stream: false
|
|
139
|
-
* })
|
|
140
|
-
* // text is a string with the full response
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
stream?: TStream;
|
|
144
|
-
/**
|
|
145
|
-
* Optional middleware array for observing/transforming chat behavior.
|
|
146
|
-
* Middleware hooks are called in array order. See {@link ChatMiddleware} for available hooks.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```ts
|
|
150
|
-
* const stream = chat({
|
|
151
|
-
* adapter: openaiText('gpt-4o'),
|
|
152
|
-
* messages: [...],
|
|
153
|
-
* middleware: [loggingMiddleware, redactionMiddleware],
|
|
154
|
-
* })
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
middleware?: Array<ChatMiddleware<TContext>>;
|
|
158
|
-
/**
|
|
159
|
-
* Runtime context value passed to middleware hooks and server tools.
|
|
160
|
-
*/
|
|
161
|
-
context?: TContext;
|
|
162
|
-
/**
|
|
163
|
-
* Enable debug logging. Pass `true` to enable all categories with the default
|
|
164
|
-
* console logger, `false` to silence everything, or a `DebugConfig` object for
|
|
165
|
-
* granular control and/or a custom `Logger`. Defaults to `undefined`, which
|
|
166
|
-
* means only the `errors` category is active.
|
|
167
|
-
*/
|
|
168
|
-
debug?: DebugOption;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Create typed options for the chat() function without executing.
|
|
172
|
-
* This is useful for pre-defining configurations with full type inference.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* const chatOptions = createChatOptions({
|
|
177
|
-
* adapter: anthropicText('claude-sonnet-4-5'),
|
|
178
|
-
* })
|
|
179
|
-
*
|
|
180
|
-
* const stream = chat({ ...chatOptions, messages })
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
export declare function createChatOptions<TAdapter extends AnyTextAdapter, TSchema extends SchemaInput | undefined = undefined, TStream extends boolean = true, const TTools extends TextActivityOptions<TAdapter, TSchema, TStream, any>['tools'] = TextActivityOptions<TAdapter, TSchema, TStream, any>['tools'], const TMiddleware extends TextActivityOptions<TAdapter, TSchema, TStream, any>['middleware'] = TextActivityOptions<TAdapter, TSchema, TStream, any>['middleware']>(options: TextActivityOptionsWithContext<TAdapter, TSchema, TStream, TTools, TMiddleware>): TextActivityOptions<TAdapter, TSchema, TStream, InferredContext<TTools, TMiddleware>>;
|
|
184
|
-
/**
|
|
185
|
-
* Result type for the text activity.
|
|
186
|
-
* - If outputSchema is provided AND stream is explicitly true:
|
|
187
|
-
* StructuredOutputStream<InferSchemaType<TSchema>> — yields raw JSON deltas
|
|
188
|
-
* via TEXT_MESSAGE_CONTENT plus a terminal StructuredOutputCompleteEvent
|
|
189
|
-
* carrying the validated object.
|
|
190
|
-
* - If outputSchema is provided without explicit stream:true:
|
|
191
|
-
* Promise<InferSchemaType<TSchema>>.
|
|
192
|
-
* - If stream is explicitly false (no schema): Promise<string>.
|
|
193
|
-
* - Otherwise (default): AsyncIterable<StreamChunk>.
|
|
194
|
-
*
|
|
195
|
-
* `[TStream] extends [true]` is used (not `TStream extends true`) so that the
|
|
196
|
-
* default `boolean` value of `TStream` does *not* match the streaming branch.
|
|
197
|
-
* Without this, plain `chat({ outputSchema })` would type as a stream while
|
|
198
|
-
* the runtime returns a Promise — see issue #526.
|
|
199
|
-
*/
|
|
200
|
-
export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream extends boolean = boolean> = TSchema extends SchemaInput ? [TStream] extends [true] ? StructuredOutputStream<InferSchemaType<TSchema>> : Promise<InferSchemaType<TSchema>> : [TStream] extends [false] ? Promise<string> : AsyncIterable<StreamChunk>;
|
|
201
|
-
/**
|
|
202
|
-
* Text activity - handles agentic text generation, one-shot text generation, and agentic structured output.
|
|
203
|
-
*
|
|
204
|
-
* This activity supports four modes:
|
|
205
|
-
* 1. **Streaming agentic text**: Stream responses with automatic tool execution
|
|
206
|
-
* 2. **Streaming one-shot text**: Simple streaming request/response without tools
|
|
207
|
-
* 3. **Non-streaming text**: Returns collected text as a string (stream: false)
|
|
208
|
-
* 4. **Agentic structured output**: Run tools, then return structured data
|
|
209
|
-
*
|
|
210
|
-
* @example Full agentic text (streaming with tools)
|
|
211
|
-
* ```ts
|
|
212
|
-
* import { chat } from '@tanstack/ai'
|
|
213
|
-
* import { openaiText } from '@tanstack/ai-openai'
|
|
214
|
-
*
|
|
215
|
-
* for await (const chunk of chat({
|
|
216
|
-
* adapter: openaiText('gpt-4o'),
|
|
217
|
-
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
218
|
-
* tools: [weatherTool]
|
|
219
|
-
* })) {
|
|
220
|
-
* if (chunk.type === 'TEXT_MESSAGE_CONTENT') {
|
|
221
|
-
* console.log(chunk.delta)
|
|
222
|
-
* }
|
|
223
|
-
* }
|
|
224
|
-
* ```
|
|
225
|
-
*
|
|
226
|
-
* @example One-shot text (streaming without tools)
|
|
227
|
-
* ```ts
|
|
228
|
-
* for await (const chunk of chat({
|
|
229
|
-
* adapter: openaiText('gpt-4o'),
|
|
230
|
-
* messages: [{ role: 'user', content: 'Hello!' }]
|
|
231
|
-
* })) {
|
|
232
|
-
* console.log(chunk)
|
|
233
|
-
* }
|
|
234
|
-
* ```
|
|
235
|
-
*
|
|
236
|
-
* @example Non-streaming text (stream: false)
|
|
237
|
-
* ```ts
|
|
238
|
-
* const text = await chat({
|
|
239
|
-
* adapter: openaiText('gpt-4o'),
|
|
240
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
241
|
-
* stream: false
|
|
242
|
-
* })
|
|
243
|
-
* // text is a string with the full response
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* @example Agentic structured output (tools + structured response)
|
|
247
|
-
* ```ts
|
|
248
|
-
* import { z } from 'zod'
|
|
249
|
-
*
|
|
250
|
-
* const result = await chat({
|
|
251
|
-
* adapter: openaiText('gpt-4o'),
|
|
252
|
-
* messages: [{ role: 'user', content: 'Research and summarize the topic' }],
|
|
253
|
-
* tools: [researchTool, analyzeTool],
|
|
254
|
-
* outputSchema: z.object({
|
|
255
|
-
* summary: z.string(),
|
|
256
|
-
* keyPoints: z.array(z.string())
|
|
257
|
-
* })
|
|
258
|
-
* })
|
|
259
|
-
* // result is { summary: string, keyPoints: string[] }
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
export declare function chat<TAdapter extends AnyTextAdapter, TSchema extends SchemaInput | undefined = undefined, TStream extends boolean = boolean, const TTools extends TextActivityOptions<TAdapter, TSchema, TStream, any>['tools'] = TextActivityOptions<TAdapter, TSchema, TStream, any>['tools'], const TMiddleware extends TextActivityOptions<TAdapter, TSchema, TStream, any>['middleware'] = TextActivityOptions<TAdapter, TSchema, TStream, any>['middleware']>(options: TextActivityOptionsWithContext<TAdapter, TSchema, TStream, TTools, TMiddleware>): TextActivityResult<TSchema, TStream>;
|
|
263
|
-
export type { TextAdapter, TextAdapterConfig, StructuredOutputOptions, StructuredOutputResult, } from './adapter.js';
|
|
264
|
-
export { BaseTextAdapter } from './adapter.js';
|