@tanstack/ai 0.42.0 → 0.43.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/README.md +15 -1
- package/dist/esm/activities/chat/adapter.js +23 -16
- package/dist/esm/activities/chat/adapter.js.map +1 -1
- package/dist/esm/activities/chat/agent-loop-strategies.d.ts +5 -36
- package/dist/esm/activities/chat/agent-loop-strategies.js +75 -21
- package/dist/esm/activities/chat/agent-loop-strategies.js.map +1 -1
- package/dist/esm/activities/chat/cancel.d.ts +40 -0
- package/dist/esm/activities/chat/cancel.js +54 -0
- package/dist/esm/activities/chat/cancel.js.map +1 -0
- package/dist/esm/activities/chat/index.d.ts +28 -21
- package/dist/esm/activities/chat/index.js +2100 -1813
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/mcp/manager.d.ts +2 -2
- package/dist/esm/activities/chat/mcp/manager.js +90 -77
- package/dist/esm/activities/chat/mcp/manager.js.map +1 -1
- package/dist/esm/activities/chat/mcp/types.d.ts +2 -2
- package/dist/esm/activities/chat/messages.js +397 -346
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/middleware/builder.js +17 -15
- package/dist/esm/activities/chat/middleware/builder.js.map +1 -1
- package/dist/esm/activities/chat/middleware/capabilities.js +78 -43
- package/dist/esm/activities/chat/middleware/capabilities.js.map +1 -1
- package/dist/esm/activities/chat/middleware/compose.d.ts +94 -1
- package/dist/esm/activities/chat/middleware/compose.js +623 -531
- package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
- package/dist/esm/activities/chat/middleware/define.js +12 -5
- package/dist/esm/activities/chat/middleware/define.js.map +1 -1
- package/dist/esm/activities/chat/middleware/index.d.ts +5 -1
- package/dist/esm/activities/chat/middleware/locks.d.ts +50 -0
- package/dist/esm/activities/chat/middleware/locks.js +71 -0
- package/dist/esm/activities/chat/middleware/locks.js.map +1 -0
- package/dist/esm/activities/chat/middleware/pending-turn.d.ts +15 -0
- package/dist/esm/activities/chat/middleware/pending-turn.js +35 -0
- package/dist/esm/activities/chat/middleware/pending-turn.js.map +1 -0
- package/dist/esm/activities/chat/middleware/run-disconnect.d.ts +23 -0
- package/dist/esm/activities/chat/middleware/run-disconnect.js +42 -0
- package/dist/esm/activities/chat/middleware/run-disconnect.js.map +1 -0
- package/dist/esm/activities/chat/middleware/run-store.d.ts +283 -0
- package/dist/esm/activities/chat/middleware/run-store.js +176 -0
- package/dist/esm/activities/chat/middleware/run-store.js.map +1 -0
- package/dist/esm/activities/chat/middleware/sandbox-runtime.js +14 -8
- package/dist/esm/activities/chat/middleware/sandbox-runtime.js.map +1 -1
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.js +79 -70
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.js.map +1 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +59 -2
- package/dist/esm/activities/chat/middleware/validate.js +23 -28
- package/dist/esm/activities/chat/middleware/validate.js.map +1 -1
- package/dist/esm/activities/chat/stream/json-parser.js +39 -25
- package/dist/esm/activities/chat/stream/json-parser.js.map +1 -1
- package/dist/esm/activities/chat/stream/message-updaters.js +275 -234
- package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -1
- package/dist/esm/activities/chat/stream/processor.d.ts +24 -4
- package/dist/esm/activities/chat/stream/processor.js +1341 -1542
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/activities/chat/stream/strategies.js +69 -53
- package/dist/esm/activities/chat/stream/strategies.js.map +1 -1
- package/dist/esm/activities/chat/tools/approval-schema.d.ts +19 -0
- package/dist/esm/activities/chat/tools/approval-schema.js +117 -0
- package/dist/esm/activities/chat/tools/approval-schema.js.map +1 -0
- package/dist/esm/activities/chat/tools/lazy-tool-manager.js +164 -191
- package/dist/esm/activities/chat/tools/lazy-tool-manager.js.map +1 -1
- package/dist/esm/activities/chat/tools/lazy-tools.js +24 -12
- package/dist/esm/activities/chat/tools/lazy-tools.js.map +1 -1
- package/dist/esm/activities/chat/tools/schema-converter.js +293 -146
- package/dist/esm/activities/chat/tools/schema-converter.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-calls.d.ts +18 -2
- package/dist/esm/activities/chat/tools/tool-calls.js +522 -531
- package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-definition.d.ts +75 -16
- package/dist/esm/activities/chat/tools/tool-definition.js +95 -23
- package/dist/esm/activities/chat/tools/tool-definition.js.map +1 -1
- package/dist/esm/activities/error-payload.js +85 -47
- package/dist/esm/activities/error-payload.js.map +1 -1
- package/dist/esm/activities/generateAudio/adapter.js +22 -15
- package/dist/esm/activities/generateAudio/adapter.js.map +1 -1
- package/dist/esm/activities/generateAudio/index.d.ts +4 -0
- package/dist/esm/activities/generateAudio/index.js +141 -105
- package/dist/esm/activities/generateAudio/index.js.map +1 -1
- package/dist/esm/activities/generateImage/adapter.js +22 -15
- package/dist/esm/activities/generateImage/adapter.js.map +1 -1
- package/dist/esm/activities/generateImage/index.d.ts +4 -0
- package/dist/esm/activities/generateImage/index.js +155 -111
- package/dist/esm/activities/generateImage/index.js.map +1 -1
- package/dist/esm/activities/generateSpeech/adapter.js +22 -15
- package/dist/esm/activities/generateSpeech/adapter.js.map +1 -1
- package/dist/esm/activities/generateSpeech/index.d.ts +4 -0
- package/dist/esm/activities/generateSpeech/index.js +159 -110
- package/dist/esm/activities/generateSpeech/index.js.map +1 -1
- package/dist/esm/activities/generateTranscription/adapter.js +22 -15
- package/dist/esm/activities/generateTranscription/adapter.js.map +1 -1
- package/dist/esm/activities/generateTranscription/index.d.ts +4 -0
- package/dist/esm/activities/generateTranscription/index.js +159 -100
- package/dist/esm/activities/generateTranscription/index.js.map +1 -1
- package/dist/esm/activities/generateVideo/adapter.js +36 -29
- package/dist/esm/activities/generateVideo/adapter.js.map +1 -1
- package/dist/esm/activities/generateVideo/index.d.ts +143 -19
- package/dist/esm/activities/generateVideo/index.js +456 -279
- package/dist/esm/activities/generateVideo/index.js.map +1 -1
- package/dist/esm/activities/generateVideo/snap.js +60 -48
- package/dist/esm/activities/generateVideo/snap.js.map +1 -1
- package/dist/esm/activities/index.js +8 -34
- package/dist/esm/activities/middleware/index.d.ts +1 -1
- package/dist/esm/activities/middleware/run.d.ts +10 -0
- package/dist/esm/activities/middleware/run.js +53 -29
- package/dist/esm/activities/middleware/run.js.map +1 -1
- package/dist/esm/activities/middleware/types.d.ts +44 -6
- package/dist/esm/activities/stream-generation-result.d.ts +4 -1
- package/dist/esm/activities/stream-generation-result.js +79 -44
- package/dist/esm/activities/stream-generation-result.js.map +1 -1
- package/dist/esm/activities/summarize/adapter.js +22 -15
- package/dist/esm/activities/summarize/adapter.js.map +1 -1
- package/dist/esm/activities/summarize/chat-stream-summarize.js +252 -202
- package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
- package/dist/esm/activities/summarize/index.d.ts +27 -0
- package/dist/esm/activities/summarize/index.js +268 -102
- package/dist/esm/activities/summarize/index.js.map +1 -1
- package/dist/esm/adapter-internals.d.ts +2 -1
- package/dist/esm/adapter-internals.js +4 -11
- package/dist/esm/client.d.ts +25 -3
- package/dist/esm/client.js +131 -64
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/custom-events.d.ts +76 -0
- package/dist/esm/custom-events.js +37 -0
- package/dist/esm/custom-events.js.map +1 -0
- package/dist/esm/delivery-detach.d.ts +50 -0
- package/dist/esm/delivery-detach.js +71 -0
- package/dist/esm/delivery-detach.js.map +1 -0
- package/dist/esm/delivery-disconnect.d.ts +62 -0
- package/dist/esm/delivery-disconnect.js +81 -0
- package/dist/esm/delivery-disconnect.js.map +1 -0
- package/dist/esm/extend-adapter.js +19 -17
- package/dist/esm/extend-adapter.js.map +1 -1
- package/dist/esm/index.d.ts +24 -6
- package/dist/esm/index.js +30 -98
- package/dist/esm/interrupt-resume.d.ts +71 -0
- package/dist/esm/interrupt-resume.js +438 -0
- package/dist/esm/interrupt-resume.js.map +1 -0
- package/dist/esm/interrupt-serialization.d.ts +12 -0
- package/dist/esm/interrupt-serialization.js +178 -0
- package/dist/esm/interrupt-serialization.js.map +1 -0
- package/dist/esm/interrupts.d.ts +84 -0
- package/dist/esm/interrupts.js +31 -0
- package/dist/esm/interrupts.js.map +1 -0
- package/dist/esm/locks.d.ts +10 -0
- package/dist/esm/locks.js +2 -0
- package/dist/esm/logger/console-logger.js +101 -78
- package/dist/esm/logger/console-logger.js.map +1 -1
- package/dist/esm/logger/internal-logger.js +104 -89
- package/dist/esm/logger/internal-logger.js.map +1 -1
- package/dist/esm/logger/resolve.js +54 -49
- package/dist/esm/logger/resolve.js.map +1 -1
- package/dist/esm/logger/types.d.ts +1 -1
- package/dist/esm/middlewares/content-guard.js +142 -148
- package/dist/esm/middlewares/content-guard.js.map +1 -1
- package/dist/esm/middlewares/index.js +2 -6
- package/dist/esm/middlewares/otel.js +598 -732
- package/dist/esm/middlewares/otel.js.map +1 -1
- package/dist/esm/middlewares/usage-attributes.js +47 -40
- package/dist/esm/middlewares/usage-attributes.js.map +1 -1
- package/dist/esm/realtime/event-emitter.js +24 -25
- package/dist/esm/realtime/event-emitter.js.map +1 -1
- package/dist/esm/realtime/index.d.ts +5 -9
- package/dist/esm/realtime/index.js +29 -6
- package/dist/esm/realtime/index.js.map +1 -1
- package/dist/esm/scope.d.ts +47 -0
- package/dist/esm/stream-durability.d.ts +171 -0
- package/dist/esm/stream-durability.js +295 -0
- package/dist/esm/stream-durability.js.map +1 -0
- package/dist/esm/stream-to-response.d.ts +178 -13
- package/dist/esm/stream-to-response.js +663 -115
- package/dist/esm/stream-to-response.js.map +1 -1
- package/dist/esm/strip-to-spec-middleware.js +30 -16
- package/dist/esm/strip-to-spec-middleware.js.map +1 -1
- package/dist/esm/system-prompts.js +27 -21
- package/dist/esm/system-prompts.js.map +1 -1
- package/dist/esm/tool-registry.js +72 -45
- package/dist/esm/tool-registry.js.map +1 -1
- package/dist/esm/tools/provider-tool.js +14 -5
- package/dist/esm/tools/provider-tool.js.map +1 -1
- package/dist/esm/types.d.ts +321 -42
- package/dist/esm/types.js +2 -0
- package/dist/esm/utilities/ag-ui-wire.js +79 -93
- package/dist/esm/utilities/ag-ui-wire.js.map +1 -1
- package/dist/esm/utilities/chat-params.d.ts +26 -4
- package/dist/esm/utilities/chat-params.js +218 -92
- package/dist/esm/utilities/chat-params.js.map +1 -1
- package/dist/esm/utilities/errors.js +28 -18
- package/dist/esm/utilities/errors.js.map +1 -1
- package/dist/esm/utilities/media-prompt.js +46 -41
- package/dist/esm/utilities/media-prompt.js.map +1 -1
- package/dist/esm/utilities/numbers.js +13 -10
- package/dist/esm/utilities/numbers.js.map +1 -1
- package/dist/esm/utilities/provider-executed.js +20 -11
- package/dist/esm/utilities/provider-executed.js.map +1 -1
- package/dist/esm/utilities/sampling-keys.js +31 -19
- package/dist/esm/utilities/sampling-keys.js.map +1 -1
- package/dist/esm/utilities/tool-result.js +42 -30
- package/dist/esm/utilities/tool-result.js.map +1 -1
- package/dist/esm/utilities/usage.js +27 -9
- package/dist/esm/utilities/usage.js.map +1 -1
- package/dist/esm/utils.js +26 -18
- package/dist/esm/utils.js.map +1 -1
- package/package.json +10 -6
- package/skills/ai-core/SKILL.md +69 -18
- package/skills/ai-core/adapter-configuration/SKILL.md +44 -21
- package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +1 -3
- package/skills/ai-core/adapter-configuration/references/byteplus-adapter.md +148 -0
- package/skills/ai-core/adapter-configuration/references/gemini-adapter.md +2 -6
- package/skills/ai-core/adapter-configuration/references/groq-adapter.md +2 -6
- package/skills/ai-core/adapter-configuration/references/openai-adapter.md +1 -3
- package/skills/ai-core/ag-ui-protocol/SKILL.md +1 -1
- package/skills/ai-core/chat-experience/SKILL.md +98 -11
- package/skills/ai-core/client-persistence/SKILL.md +277 -0
- package/skills/ai-core/custom-backend-integration/SKILL.md +1 -1
- package/skills/ai-core/debug-logging/SKILL.md +1 -1
- package/skills/ai-core/locks/SKILL.md +143 -0
- package/skills/ai-core/media-generation/SKILL.md +144 -12
- package/skills/ai-core/middleware/SKILL.md +258 -33
- package/skills/ai-core/structured-outputs/SKILL.md +1 -1
- package/skills/ai-core/tool-calling/SKILL.md +54 -61
- package/src/activities/chat/agent-loop-strategies.ts +5 -39
- package/src/activities/chat/cancel.ts +81 -0
- package/src/activities/chat/index.ts +1091 -200
- package/src/activities/chat/mcp/manager.ts +4 -4
- package/src/activities/chat/mcp/types.ts +2 -2
- package/src/activities/chat/messages.ts +5 -3
- package/src/activities/chat/middleware/builder.ts +1 -1
- package/src/activities/chat/middleware/compose.ts +186 -9
- package/src/activities/chat/middleware/index.ts +26 -0
- package/src/activities/chat/middleware/locks.ts +102 -0
- package/src/activities/chat/middleware/pending-turn.ts +47 -0
- package/src/activities/chat/middleware/run-disconnect.ts +62 -0
- package/src/activities/chat/middleware/run-store.ts +412 -0
- package/src/activities/chat/middleware/types.ts +62 -1
- package/src/activities/chat/stream/processor.ts +189 -5
- package/src/activities/chat/tools/approval-schema.ts +205 -0
- package/src/activities/chat/tools/tool-calls.ts +106 -13
- package/src/activities/chat/tools/tool-definition.ts +210 -39
- package/src/activities/generateAudio/index.ts +20 -3
- package/src/activities/generateImage/index.ts +20 -3
- package/src/activities/generateSpeech/index.ts +25 -3
- package/src/activities/generateTranscription/index.ts +26 -3
- package/src/activities/generateVideo/index.ts +345 -82
- package/src/activities/middleware/index.ts +2 -0
- package/src/activities/middleware/run.ts +31 -0
- package/src/activities/middleware/types.ts +49 -5
- package/src/activities/stream-generation-result.ts +30 -2
- package/src/activities/summarize/chat-stream-summarize.ts +5 -0
- package/src/activities/summarize/index.ts +200 -10
- package/src/adapter-internals.ts +10 -1
- package/src/client.ts +244 -0
- package/src/custom-events.ts +107 -0
- package/src/delivery-detach.ts +72 -0
- package/src/delivery-disconnect.ts +84 -0
- package/src/index.ts +138 -1
- package/src/interrupt-resume.ts +824 -0
- package/src/interrupt-serialization.ts +183 -0
- package/src/interrupts.ts +146 -0
- package/src/locks.ts +17 -0
- package/src/logger/types.ts +1 -1
- package/src/middlewares/otel.ts +1 -0
- package/src/realtime/index.ts +5 -9
- package/src/scope.ts +47 -0
- package/src/stream-durability.ts +598 -0
- package/src/stream-to-response.ts +1051 -95
- package/src/strip-to-spec-middleware.ts +3 -3
- package/src/types.ts +405 -45
- package/src/utilities/chat-params.ts +245 -55
- package/dist/esm/activities/index.js.map +0 -1
- package/dist/esm/adapter-internals.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/middlewares/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
2
|
+
<picture>
|
|
3
|
+
<source
|
|
4
|
+
media="(prefers-color-scheme: dark)"
|
|
5
|
+
srcset="https://tanstack.com/api/readme/ai.png?theme=dark"
|
|
6
|
+
/>
|
|
7
|
+
<source
|
|
8
|
+
media="(prefers-color-scheme: light)"
|
|
9
|
+
srcset="https://tanstack.com/api/readme/ai.png"
|
|
10
|
+
/>
|
|
11
|
+
<img
|
|
12
|
+
src="https://tanstack.com/api/readme/ai.png"
|
|
13
|
+
alt="TanStack AI"
|
|
14
|
+
width="900"
|
|
15
|
+
/>
|
|
16
|
+
</picture>
|
|
3
17
|
</div>
|
|
4
18
|
|
|
5
19
|
<br />
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
//#region src/activities/chat/adapter.ts
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for text adapters.
|
|
4
|
+
* Extend this class to implement a text adapter for a specific provider.
|
|
5
|
+
*
|
|
6
|
+
* Generic parameters match TextAdapter - all pre-resolved by the provider function.
|
|
7
|
+
*/
|
|
8
|
+
var BaseTextAdapter = class {
|
|
9
|
+
kind = "text";
|
|
10
|
+
model;
|
|
11
|
+
requires = void 0;
|
|
12
|
+
config;
|
|
13
|
+
constructor(config = {}, model) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.model = model;
|
|
16
|
+
}
|
|
17
|
+
generateId() {
|
|
18
|
+
return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
19
|
+
}
|
|
16
20
|
};
|
|
17
|
-
//#
|
|
21
|
+
//#endregion
|
|
22
|
+
export { BaseTextAdapter };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sources":["../../../../src/activities/chat/adapter.ts"],"sourcesContent":["import type {\n DefaultMessageMetadataByModality,\n JSONSchema,\n Modality,\n StreamChunk,\n TextOptions,\n TokenUsage,\n} from '../../types'\nimport type { CapabilityHandle } from './middleware/capabilities'\n\n/**\n * Configuration for adapter instances\n */\nexport interface TextAdapterConfig {\n apiKey?: string\n baseUrl?: string\n timeout?: number\n maxRetries?: number\n headers?: Record<string, string>\n}\n\n/**\n * Options for structured output generation.\n *\n * The internal logger is threaded through `chatOptions.logger` (inherited from\n * `TextOptions`). Adapter implementations must call `logger.request()` before\n * SDK calls, `logger.provider()` for each chunk received, and `logger.errors()`\n * in catch blocks.\n */\nexport interface StructuredOutputOptions<TProviderOptions extends object> {\n /** Text options for the request */\n chatOptions: TextOptions<TProviderOptions>\n /** JSON Schema for structured output - already converted from Zod in the ai layer */\n outputSchema: JSONSchema\n}\n\n/**\n * Result from structured output generation\n */\nexport interface StructuredOutputResult<T = unknown> {\n /** The parsed data conforming to the schema */\n data: T\n /** The raw text response from the model before parsing */\n rawText: string\n /** Token usage information (if provided by the adapter) */\n usage?: TokenUsage\n}\n\n/**\n * Text adapter interface with pre-resolved generics.\n *\n * An adapter is created by a provider function: `provider('model')` → `adapter`\n * All type resolution happens at the provider call site, not in this interface.\n *\n * Generic parameters:\n * - TModel: The specific model name (e.g., 'gpt-4o')\n * - TProviderOptions: Provider-specific options for this model (already resolved)\n * - TInputModalities: Supported input modalities for this model (already resolved)\n * - TMessageMetadata: Metadata types for content parts (already resolved)\n * - TToolCapabilities: Tuple of tool-kind strings supported by this model, resolved from `supports.tools`\n * - TToolCallMetadata: Metadata type that round-trips with tool calls (e.g. Gemini's `thoughtSignature`)\n * - TSystemPromptMetadata: Provider-typed metadata accepted on each\n * `systemPrompts[i]` entry (e.g. Anthropic `cache_control`). Defaults to\n * `never` — adapters without per-prompt metadata reject the `metadata`\n * field at the call site.\n */\nexport interface TextAdapter<\n TModel extends string,\n TProviderOptions extends Record<string, any>,\n TInputModalities extends ReadonlyArray<Modality>,\n TMessageMetadataByModality extends DefaultMessageMetadataByModality,\n TToolCapabilities extends ReadonlyArray<string> = ReadonlyArray<string>,\n TToolCallMetadata = unknown,\n TSystemPromptMetadata = never,\n> {\n /** Discriminator for adapter kind */\n readonly kind: 'text'\n /** Provider name identifier (e.g., 'openai', 'anthropic') */\n readonly name: string\n /** The model this adapter is configured for */\n readonly model: TModel\n\n /**\n * Capabilities this adapter requires at runtime. `chat()` validates that the\n * configured middleware provides each one. Model adapters omit this; harness\n * adapters (e.g. a future `claudeCode()`) declare e.g. `[sandboxCapability]`.\n * Runtime access to capabilities from inside the adapter is not yet wired —\n * this is the declaration/validation surface only.\n */\n readonly requires?: ReadonlyArray<CapabilityHandle>\n\n /**\n * @internal Type-only properties for inference. Not assigned at runtime.\n */\n '~types': {\n providerOptions: TProviderOptions\n inputModalities: TInputModalities\n messageMetadataByModality: TMessageMetadataByModality\n toolCapabilities: TToolCapabilities\n toolCallMetadata: TToolCallMetadata\n systemPromptMetadata: TSystemPromptMetadata\n }\n\n /**\n * Stream text completions from the model\n */\n chatStream: (\n options: TextOptions<TProviderOptions>,\n ) => AsyncIterable<StreamChunk>\n\n /**\n * Generate structured output using the provider's native structured output API.\n * This method uses stream: false and sends the JSON schema to the provider\n * to ensure the response conforms to the expected structure.\n *\n * @param options - Structured output options containing chat options and JSON schema\n * @returns Promise with the raw data (validation is done in the chat function)\n */\n structuredOutput: (\n options: StructuredOutputOptions<TProviderOptions>,\n ) => Promise<StructuredOutputResult<unknown>>\n\n /**\n * Stream structured output using the provider's native streaming structured\n * output API (stream + response_format json_schema in a single request).\n *\n * Optional — adapters without native streaming JSON omit this method and the\n * activity layer synthesizes a stream around the non-streaming\n * `structuredOutput` call.\n *\n * Implementations must emit standard AG-UI lifecycle events (RUN_STARTED,\n * TEXT_MESSAGE_*, RUN_FINISHED) carrying raw JSON text deltas, plus a final\n * `CUSTOM` event named `structured-output.complete` whose `value` is\n * `{ object, raw, reasoning? }`.\n */\n structuredOutputStream?: (\n options: StructuredOutputOptions<TProviderOptions>,\n ) => AsyncIterable<StreamChunk>\n\n /**\n * Declares whether the adapter supports combining `tools` and a\n * schema-constrained final answer in a single streaming request.\n *\n * When `true`, the engine wires `outputSchema` into the regular\n * `chatStream()` call and skips the separate `runStructuredFinalization`\n * round-trip. The model's natural final turn carries the\n * schema-constrained JSON text and the engine harvests it from the agent\n * loop's accumulated content.\n *\n * When `false`, `undefined`, or the method is omitted, the engine runs\n * the agent loop without `outputSchema` and then issues a separate\n * `structuredOutput` / `structuredOutputStream` call against the JSON\n * schema for finalization (the legacy path).\n *\n * The method receives the per-call `modelOptions` so providers whose\n * support depends on the resolved upstream model (e.g. OpenRouter) can\n * answer per-request. Most adapters can return a constant.\n */\n supportsCombinedToolsAndSchema?: (\n modelOptions?: TProviderOptions | undefined,\n ) => boolean\n}\n\n/**\n * A TextAdapter with any/unknown type parameters.\n * Useful as a constraint in generic functions and interfaces.\n */\nexport type AnyTextAdapter = TextAdapter<any, any, any, any, any, any, any>\n\n/**\n * Abstract base class for text adapters.\n * Extend this class to implement a text adapter for a specific provider.\n *\n * Generic parameters match TextAdapter - all pre-resolved by the provider function.\n */\nexport abstract class BaseTextAdapter<\n TModel extends string,\n TProviderOptions extends Record<string, any>,\n TInputModalities extends ReadonlyArray<Modality>,\n TMessageMetadataByModality extends DefaultMessageMetadataByModality,\n TToolCapabilities extends ReadonlyArray<string> = ReadonlyArray<string>,\n TToolCallMetadata = unknown,\n TSystemPromptMetadata = never,\n> implements TextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n TMessageMetadataByModality,\n TToolCapabilities,\n TToolCallMetadata,\n TSystemPromptMetadata\n> {\n readonly kind = 'text' as const\n abstract readonly name: string\n readonly model: TModel\n readonly requires?: ReadonlyArray<CapabilityHandle> = undefined\n\n // Type-only property - never assigned at runtime\n declare '~types': {\n providerOptions: TProviderOptions\n inputModalities: TInputModalities\n messageMetadataByModality: TMessageMetadataByModality\n toolCapabilities: TToolCapabilities\n toolCallMetadata: TToolCallMetadata\n systemPromptMetadata: TSystemPromptMetadata\n }\n\n protected config: TextAdapterConfig\n\n constructor(config: TextAdapterConfig = {}, model: TModel) {\n this.config = config\n this.model = model\n }\n\n abstract chatStream(\n options: TextOptions<TProviderOptions>,\n ): AsyncIterable<StreamChunk>\n\n /**\n * Generate structured output using the provider's native structured output API.\n * Concrete implementations should override this to use provider-specific structured output.\n */\n abstract structuredOutput(\n options: StructuredOutputOptions<TProviderOptions>,\n ): Promise<StructuredOutputResult<unknown>>\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"adapter.js","names":[],"sources":["../../../../src/activities/chat/adapter.ts"],"sourcesContent":["import type {\n DefaultMessageMetadataByModality,\n JSONSchema,\n Modality,\n StreamChunk,\n TextOptions,\n TokenUsage,\n} from '../../types'\nimport type { CapabilityHandle } from './middleware/capabilities'\n\n/**\n * Configuration for adapter instances\n */\nexport interface TextAdapterConfig {\n apiKey?: string\n baseUrl?: string\n timeout?: number\n maxRetries?: number\n headers?: Record<string, string>\n}\n\n/**\n * Options for structured output generation.\n *\n * The internal logger is threaded through `chatOptions.logger` (inherited from\n * `TextOptions`). Adapter implementations must call `logger.request()` before\n * SDK calls, `logger.provider()` for each chunk received, and `logger.errors()`\n * in catch blocks.\n */\nexport interface StructuredOutputOptions<TProviderOptions extends object> {\n /** Text options for the request */\n chatOptions: TextOptions<TProviderOptions>\n /** JSON Schema for structured output - already converted from Zod in the ai layer */\n outputSchema: JSONSchema\n}\n\n/**\n * Result from structured output generation\n */\nexport interface StructuredOutputResult<T = unknown> {\n /** The parsed data conforming to the schema */\n data: T\n /** The raw text response from the model before parsing */\n rawText: string\n /** Token usage information (if provided by the adapter) */\n usage?: TokenUsage\n}\n\n/**\n * Text adapter interface with pre-resolved generics.\n *\n * An adapter is created by a provider function: `provider('model')` → `adapter`\n * All type resolution happens at the provider call site, not in this interface.\n *\n * Generic parameters:\n * - TModel: The specific model name (e.g., 'gpt-4o')\n * - TProviderOptions: Provider-specific options for this model (already resolved)\n * - TInputModalities: Supported input modalities for this model (already resolved)\n * - TMessageMetadata: Metadata types for content parts (already resolved)\n * - TToolCapabilities: Tuple of tool-kind strings supported by this model, resolved from `supports.tools`\n * - TToolCallMetadata: Metadata type that round-trips with tool calls (e.g. Gemini's `thoughtSignature`)\n * - TSystemPromptMetadata: Provider-typed metadata accepted on each\n * `systemPrompts[i]` entry (e.g. Anthropic `cache_control`). Defaults to\n * `never` — adapters without per-prompt metadata reject the `metadata`\n * field at the call site.\n */\nexport interface TextAdapter<\n TModel extends string,\n TProviderOptions extends Record<string, any>,\n TInputModalities extends ReadonlyArray<Modality>,\n TMessageMetadataByModality extends DefaultMessageMetadataByModality,\n TToolCapabilities extends ReadonlyArray<string> = ReadonlyArray<string>,\n TToolCallMetadata = unknown,\n TSystemPromptMetadata = never,\n> {\n /** Discriminator for adapter kind */\n readonly kind: 'text'\n /** Provider name identifier (e.g., 'openai', 'anthropic') */\n readonly name: string\n /** The model this adapter is configured for */\n readonly model: TModel\n\n /**\n * Capabilities this adapter requires at runtime. `chat()` validates that the\n * configured middleware provides each one. Model adapters omit this; harness\n * adapters (e.g. a future `claudeCode()`) declare e.g. `[sandboxCapability]`.\n * Runtime access to capabilities from inside the adapter is not yet wired —\n * this is the declaration/validation surface only.\n */\n readonly requires?: ReadonlyArray<CapabilityHandle>\n\n /**\n * @internal Type-only properties for inference. Not assigned at runtime.\n */\n '~types': {\n providerOptions: TProviderOptions\n inputModalities: TInputModalities\n messageMetadataByModality: TMessageMetadataByModality\n toolCapabilities: TToolCapabilities\n toolCallMetadata: TToolCallMetadata\n systemPromptMetadata: TSystemPromptMetadata\n }\n\n /**\n * Stream text completions from the model\n */\n chatStream: (\n options: TextOptions<TProviderOptions>,\n ) => AsyncIterable<StreamChunk>\n\n /**\n * Generate structured output using the provider's native structured output API.\n * This method uses stream: false and sends the JSON schema to the provider\n * to ensure the response conforms to the expected structure.\n *\n * @param options - Structured output options containing chat options and JSON schema\n * @returns Promise with the raw data (validation is done in the chat function)\n */\n structuredOutput: (\n options: StructuredOutputOptions<TProviderOptions>,\n ) => Promise<StructuredOutputResult<unknown>>\n\n /**\n * Stream structured output using the provider's native streaming structured\n * output API (stream + response_format json_schema in a single request).\n *\n * Optional — adapters without native streaming JSON omit this method and the\n * activity layer synthesizes a stream around the non-streaming\n * `structuredOutput` call.\n *\n * Implementations must emit standard AG-UI lifecycle events (RUN_STARTED,\n * TEXT_MESSAGE_*, RUN_FINISHED) carrying raw JSON text deltas, plus a final\n * `CUSTOM` event named `structured-output.complete` whose `value` is\n * `{ object, raw, reasoning? }`.\n */\n structuredOutputStream?: (\n options: StructuredOutputOptions<TProviderOptions>,\n ) => AsyncIterable<StreamChunk>\n\n /**\n * Declares whether the adapter supports combining `tools` and a\n * schema-constrained final answer in a single streaming request.\n *\n * When `true`, the engine wires `outputSchema` into the regular\n * `chatStream()` call and skips the separate `runStructuredFinalization`\n * round-trip. The model's natural final turn carries the\n * schema-constrained JSON text and the engine harvests it from the agent\n * loop's accumulated content.\n *\n * When `false`, `undefined`, or the method is omitted, the engine runs\n * the agent loop without `outputSchema` and then issues a separate\n * `structuredOutput` / `structuredOutputStream` call against the JSON\n * schema for finalization (the legacy path).\n *\n * The method receives the per-call `modelOptions` so providers whose\n * support depends on the resolved upstream model (e.g. OpenRouter) can\n * answer per-request. Most adapters can return a constant.\n */\n supportsCombinedToolsAndSchema?: (\n modelOptions?: TProviderOptions | undefined,\n ) => boolean\n}\n\n/**\n * A TextAdapter with any/unknown type parameters.\n * Useful as a constraint in generic functions and interfaces.\n */\nexport type AnyTextAdapter = TextAdapter<any, any, any, any, any, any, any>\n\n/**\n * Abstract base class for text adapters.\n * Extend this class to implement a text adapter for a specific provider.\n *\n * Generic parameters match TextAdapter - all pre-resolved by the provider function.\n */\nexport abstract class BaseTextAdapter<\n TModel extends string,\n TProviderOptions extends Record<string, any>,\n TInputModalities extends ReadonlyArray<Modality>,\n TMessageMetadataByModality extends DefaultMessageMetadataByModality,\n TToolCapabilities extends ReadonlyArray<string> = ReadonlyArray<string>,\n TToolCallMetadata = unknown,\n TSystemPromptMetadata = never,\n> implements TextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n TMessageMetadataByModality,\n TToolCapabilities,\n TToolCallMetadata,\n TSystemPromptMetadata\n> {\n readonly kind = 'text' as const\n abstract readonly name: string\n readonly model: TModel\n readonly requires?: ReadonlyArray<CapabilityHandle> = undefined\n\n // Type-only property - never assigned at runtime\n declare '~types': {\n providerOptions: TProviderOptions\n inputModalities: TInputModalities\n messageMetadataByModality: TMessageMetadataByModality\n toolCapabilities: TToolCapabilities\n toolCallMetadata: TToolCallMetadata\n systemPromptMetadata: TSystemPromptMetadata\n }\n\n protected config: TextAdapterConfig\n\n constructor(config: TextAdapterConfig = {}, model: TModel) {\n this.config = config\n this.model = model\n }\n\n abstract chatStream(\n options: TextOptions<TProviderOptions>,\n ): AsyncIterable<StreamChunk>\n\n /**\n * Generate structured output using the provider's native structured output API.\n * Concrete implementations should override this to use provider-specific structured output.\n */\n abstract structuredOutput(\n options: StructuredOutputOptions<TProviderOptions>,\n ): Promise<StructuredOutputResult<unknown>>\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"mappings":";;;;;;;AA+KA,IAAsB,kBAAtB,MAgBE;CACA,OAAgB;CAEhB;CACA,WAAsD,KAAA;CAYtD;CAEA,YAAY,SAA4B,CAAC,GAAG,OAAe;EACzD,KAAK,SAAS;EACd,KAAK,QAAQ;CACf;CAcA,aAA+B;EAC7B,OAAO,GAAG,KAAK,KAAK,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC;CAC7E;AACF"}
|
|
@@ -3,9 +3,10 @@ import { AgentLoopStrategy } from '../../types.js';
|
|
|
3
3
|
* Creates a strategy that continues for a maximum number of **model turns**
|
|
4
4
|
* (iterations), not tool calls.
|
|
5
5
|
*
|
|
6
|
-
* One iteration can still emit many parallel tool calls.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* One iteration can still emit many parallel tool calls. For a tool-call
|
|
7
|
+
* budget, use middleware with `onBeforeToolCall` (per-turn cap) and
|
|
8
|
+
* `onShouldContinue` (cumulative run budget) — see the docs recipe under
|
|
9
|
+
* Agentic Cycle.
|
|
9
10
|
*
|
|
10
11
|
* @param max - Maximum number of model turns to allow
|
|
11
12
|
* @returns AgentLoopStrategy that stops after max iterations
|
|
@@ -22,37 +23,6 @@ import { AgentLoopStrategy } from '../../types.js';
|
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
export declare function maxIterations(max: number): AgentLoopStrategy;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a strategy that continues while `toolCallCount < max`.
|
|
27
|
-
*
|
|
28
|
-
* Unlike {@link maxIterations} (which counts model turns), this bounds
|
|
29
|
-
* **emitted** tool calls counted during the run (including ones skipped by
|
|
30
|
-
* `maxToolCallsPerTurn`). Strategies only run between turns, so the turn that
|
|
31
|
-
* crosses `max` is not truncated — the final count (and executions, unless
|
|
32
|
-
* `maxToolCallsPerTurn` is set) may exceed `max`. Pair with
|
|
33
|
-
* `chat({ maxToolCallsPerTurn })` to also cap parallel fan-out inside a single
|
|
34
|
-
* turn.
|
|
35
|
-
*
|
|
36
|
-
* @param max - Maximum cumulative emitted tool calls before stopping further turns
|
|
37
|
-
* @returns AgentLoopStrategy that returns true while `toolCallCount < max`
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* import { chat, combineStrategies, maxIterations, maxToolCalls } from '@tanstack/ai'
|
|
42
|
-
*
|
|
43
|
-
* const stream = chat({
|
|
44
|
-
* adapter: openaiText('gpt-4o'),
|
|
45
|
-
* messages: [...],
|
|
46
|
-
* tools: [weatherTool],
|
|
47
|
-
* maxToolCallsPerTurn: 10,
|
|
48
|
-
* agentLoopStrategy: combineStrategies([
|
|
49
|
-
* maxIterations(20),
|
|
50
|
-
* maxToolCalls(20),
|
|
51
|
-
* ]),
|
|
52
|
-
* })
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare function maxToolCalls(max: number): AgentLoopStrategy;
|
|
56
26
|
/**
|
|
57
27
|
* Creates a strategy that continues until a specific finish reason is encountered
|
|
58
28
|
*
|
|
@@ -76,7 +46,7 @@ export declare function untilFinishReason(stopReasons: Array<string>): AgentLoop
|
|
|
76
46
|
* All strategies must return true to continue
|
|
77
47
|
*
|
|
78
48
|
* @param strategies - Array of strategies to combine
|
|
79
|
-
* @returns AgentLoopStrategy that continues only if all strategies
|
|
49
|
+
* @returns AgentLoopStrategy that continues only if all strategies agree
|
|
80
50
|
*
|
|
81
51
|
* @example
|
|
82
52
|
* ```typescript
|
|
@@ -87,7 +57,6 @@ export declare function untilFinishReason(stopReasons: Array<string>): AgentLoop
|
|
|
87
57
|
* tools: [weatherTool],
|
|
88
58
|
* agentLoopStrategy: combineStrategies([
|
|
89
59
|
* maxIterations(10),
|
|
90
|
-
* maxToolCalls(20),
|
|
91
60
|
* ({ messages }) => messages.length < 100,
|
|
92
61
|
* ]),
|
|
93
62
|
* });
|
|
@@ -1,27 +1,81 @@
|
|
|
1
|
+
//#region src/activities/chat/agent-loop-strategies.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a strategy that continues for a maximum number of **model turns**
|
|
4
|
+
* (iterations), not tool calls.
|
|
5
|
+
*
|
|
6
|
+
* One iteration can still emit many parallel tool calls. For a tool-call
|
|
7
|
+
* budget, use middleware with `onBeforeToolCall` (per-turn cap) and
|
|
8
|
+
* `onShouldContinue` (cumulative run budget) — see the docs recipe under
|
|
9
|
+
* Agentic Cycle.
|
|
10
|
+
*
|
|
11
|
+
* @param max - Maximum number of model turns to allow
|
|
12
|
+
* @returns AgentLoopStrategy that stops after max iterations
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const stream = chat({
|
|
17
|
+
* adapter: openaiText(),
|
|
18
|
+
* model: "gpt-4o",
|
|
19
|
+
* messages: [...],
|
|
20
|
+
* tools: [weatherTool],
|
|
21
|
+
* agentLoopStrategy: maxIterations(3), // Max 3 model turns
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
1
25
|
function maxIterations(max) {
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
function maxToolCalls(max) {
|
|
5
|
-
return ({ toolCallCount }) => toolCallCount < max;
|
|
26
|
+
return ({ iterationCount }) => iterationCount < max;
|
|
6
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a strategy that continues until a specific finish reason is encountered
|
|
30
|
+
*
|
|
31
|
+
* @param stopReasons - Finish reasons that should stop the loop
|
|
32
|
+
* @returns AgentLoopStrategy that stops on specific finish reasons
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const stream = chat({
|
|
37
|
+
* adapter: openaiText(),
|
|
38
|
+
* model: "gpt-4o",
|
|
39
|
+
* messages: [...],
|
|
40
|
+
* tools: [weatherTool],
|
|
41
|
+
* agentLoopStrategy: untilFinishReason(["stop", "length"]),
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
7
45
|
function untilFinishReason(stopReasons) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
46
|
+
return ({ finishReason, iterationCount }) => {
|
|
47
|
+
if (iterationCount === 0) return true;
|
|
48
|
+
if (finishReason && stopReasons.includes(finishReason)) return false;
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
15
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a strategy that combines multiple strategies with AND logic
|
|
54
|
+
* All strategies must return true to continue
|
|
55
|
+
*
|
|
56
|
+
* @param strategies - Array of strategies to combine
|
|
57
|
+
* @returns AgentLoopStrategy that continues only if all strategies agree
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const stream = chat({
|
|
62
|
+
* adapter: openaiText(),
|
|
63
|
+
* model: "gpt-4o",
|
|
64
|
+
* messages: [...],
|
|
65
|
+
* tools: [weatherTool],
|
|
66
|
+
* agentLoopStrategy: combineStrategies([
|
|
67
|
+
* maxIterations(10),
|
|
68
|
+
* ({ messages }) => messages.length < 100,
|
|
69
|
+
* ]),
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
16
73
|
function combineStrategies(strategies) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
74
|
+
return (state) => {
|
|
75
|
+
return strategies.every((strategy) => strategy(state));
|
|
76
|
+
};
|
|
20
77
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
untilFinishReason
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=agent-loop-strategies.js.map
|
|
78
|
+
//#endregion
|
|
79
|
+
export { combineStrategies, maxIterations, untilFinishReason };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=agent-loop-strategies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-loop-strategies.js","sources":["../../../../src/activities/chat/agent-loop-strategies.ts"],"sourcesContent":["import type { AgentLoopStrategy } from '../../types'\n\n/**\n * Creates a strategy that continues for a maximum number of **model turns**\n * (iterations), not tool calls.\n *\n * One iteration can still emit many parallel tool calls.
|
|
1
|
+
{"version":3,"file":"agent-loop-strategies.js","names":[],"sources":["../../../../src/activities/chat/agent-loop-strategies.ts"],"sourcesContent":["import type { AgentLoopStrategy } from '../../types'\n\n/**\n * Creates a strategy that continues for a maximum number of **model turns**\n * (iterations), not tool calls.\n *\n * One iteration can still emit many parallel tool calls. For a tool-call\n * budget, use middleware with `onBeforeToolCall` (per-turn cap) and\n * `onShouldContinue` (cumulative run budget) — see the docs recipe under\n * Agentic Cycle.\n *\n * @param max - Maximum number of model turns to allow\n * @returns AgentLoopStrategy that stops after max iterations\n *\n * @example\n * ```typescript\n * const stream = chat({\n * adapter: openaiText(),\n * model: \"gpt-4o\",\n * messages: [...],\n * tools: [weatherTool],\n * agentLoopStrategy: maxIterations(3), // Max 3 model turns\n * });\n * ```\n */\nexport function maxIterations(max: number): AgentLoopStrategy {\n return ({ iterationCount }) => iterationCount < max\n}\n\n/**\n * Creates a strategy that continues until a specific finish reason is encountered\n *\n * @param stopReasons - Finish reasons that should stop the loop\n * @returns AgentLoopStrategy that stops on specific finish reasons\n *\n * @example\n * ```typescript\n * const stream = chat({\n * adapter: openaiText(),\n * model: \"gpt-4o\",\n * messages: [...],\n * tools: [weatherTool],\n * agentLoopStrategy: untilFinishReason([\"stop\", \"length\"]),\n * });\n * ```\n */\nexport function untilFinishReason(\n stopReasons: Array<string>,\n): AgentLoopStrategy {\n return ({ finishReason, iterationCount }) => {\n // Always allow at least one iteration\n if (iterationCount === 0) return true\n\n // Stop if we hit a stop reason\n if (finishReason && stopReasons.includes(finishReason)) {\n return false\n }\n\n // Otherwise continue\n return true\n }\n}\n\n/**\n * Creates a strategy that combines multiple strategies with AND logic\n * All strategies must return true to continue\n *\n * @param strategies - Array of strategies to combine\n * @returns AgentLoopStrategy that continues only if all strategies agree\n *\n * @example\n * ```typescript\n * const stream = chat({\n * adapter: openaiText(),\n * model: \"gpt-4o\",\n * messages: [...],\n * tools: [weatherTool],\n * agentLoopStrategy: combineStrategies([\n * maxIterations(10),\n * ({ messages }) => messages.length < 100,\n * ]),\n * });\n * ```\n */\nexport function combineStrategies(\n strategies: Array<AgentLoopStrategy>,\n): AgentLoopStrategy {\n return (state) => {\n return strategies.every((strategy) => strategy(state))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,cAAc,KAAgC;CAC5D,QAAQ,EAAE,qBAAqB,iBAAiB;AAClD;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,kBACd,aACmB;CACnB,QAAQ,EAAE,cAAc,qBAAqB;EAE3C,IAAI,mBAAmB,GAAG,OAAO;EAGjC,IAAI,gBAAgB,YAAY,SAAS,YAAY,GACnD,OAAO;EAIT,OAAO;CACT;AACF;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBACd,YACmB;CACnB,QAAQ,UAAU;EAChB,OAAO,WAAW,OAAO,aAAa,SAAS,KAAK,CAAC;CACvD;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RunStore } from './middleware/run-store.js';
|
|
2
|
+
/**
|
|
3
|
+
* Abort reason that marks an abort as an explicit cancellation.
|
|
4
|
+
*
|
|
5
|
+
* Namespaced so an application's own reason string cannot collide with it by
|
|
6
|
+
* accident, and matched with `===` (never a substring test) so an arbitrary
|
|
7
|
+
* provider error message can never be read as a deliberate cancel.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RUN_CANCEL_REASON = "tanstack-ai:cancel-requested";
|
|
10
|
+
/** Whether an abort reason means "the user explicitly cancelled this run". */
|
|
11
|
+
export declare function isCancelRequestedReason(reason: string | undefined): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Record an explicit cancel on the run record.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately does NOT set a status. The driver is the only actor that knows
|
|
16
|
+
* when the agent has actually stopped and the sandbox has been torn down, so it
|
|
17
|
+
* owns the transition to `'aborted'`. Writing a terminal status here would tell
|
|
18
|
+
* every reader the run is over while the agent is still burning tokens.
|
|
19
|
+
*
|
|
20
|
+
* A no-op for an unknown `runId`, inheriting `RunStore.update`'s documented
|
|
21
|
+
* invariant.
|
|
22
|
+
*/
|
|
23
|
+
export declare function requestRunCancel(runs: RunStore, runId: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether an explicit cancel has been recorded for `runId`.
|
|
26
|
+
*
|
|
27
|
+
* Answers `false` rather than throwing when the store cannot be read. Callers
|
|
28
|
+
* are middleware abort hooks, which are already on a teardown path, and a
|
|
29
|
+
* store failure there must not replace the caller's own reason for tearing
|
|
30
|
+
* down with a store error. The cost of a false negative is that a cancel
|
|
31
|
+
* degrades into a detach — the run record gains `detachedSince`/`sandboxKey`
|
|
32
|
+
* instead of transitioning to `'aborted'`. `@tanstack/ai-sandbox`'s
|
|
33
|
+
* `reapDetachedRuns` recovers that run once the `detachedRunTtlMs` the
|
|
34
|
+
* application passes to that sweep has elapsed — nothing derives it from
|
|
35
|
+
* `withSandbox`, which has no TTL option — so the cost is a delayed teardown
|
|
36
|
+
* rather than a lost one, provided the application actually schedules the
|
|
37
|
+
* sweep, which is its job and not the framework's. Still strictly better than
|
|
38
|
+
* failing the teardown.
|
|
39
|
+
*/
|
|
40
|
+
export declare function wasCancelRequested(runs: RunStore, runId: string): Promise<boolean>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/activities/chat/cancel.ts
|
|
2
|
+
/**
|
|
3
|
+
* Abort reason that marks an abort as an explicit cancellation.
|
|
4
|
+
*
|
|
5
|
+
* Namespaced so an application's own reason string cannot collide with it by
|
|
6
|
+
* accident, and matched with `===` (never a substring test) so an arbitrary
|
|
7
|
+
* provider error message can never be read as a deliberate cancel.
|
|
8
|
+
*/
|
|
9
|
+
var RUN_CANCEL_REASON = "tanstack-ai:cancel-requested";
|
|
10
|
+
/** Whether an abort reason means "the user explicitly cancelled this run". */
|
|
11
|
+
function isCancelRequestedReason(reason) {
|
|
12
|
+
return reason === RUN_CANCEL_REASON;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Record an explicit cancel on the run record.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately does NOT set a status. The driver is the only actor that knows
|
|
18
|
+
* when the agent has actually stopped and the sandbox has been torn down, so it
|
|
19
|
+
* owns the transition to `'aborted'`. Writing a terminal status here would tell
|
|
20
|
+
* every reader the run is over while the agent is still burning tokens.
|
|
21
|
+
*
|
|
22
|
+
* A no-op for an unknown `runId`, inheriting `RunStore.update`'s documented
|
|
23
|
+
* invariant.
|
|
24
|
+
*/
|
|
25
|
+
async function requestRunCancel(runs, runId) {
|
|
26
|
+
await runs.update(runId, { cancelRequested: true });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether an explicit cancel has been recorded for `runId`.
|
|
30
|
+
*
|
|
31
|
+
* Answers `false` rather than throwing when the store cannot be read. Callers
|
|
32
|
+
* are middleware abort hooks, which are already on a teardown path, and a
|
|
33
|
+
* store failure there must not replace the caller's own reason for tearing
|
|
34
|
+
* down with a store error. The cost of a false negative is that a cancel
|
|
35
|
+
* degrades into a detach — the run record gains `detachedSince`/`sandboxKey`
|
|
36
|
+
* instead of transitioning to `'aborted'`. `@tanstack/ai-sandbox`'s
|
|
37
|
+
* `reapDetachedRuns` recovers that run once the `detachedRunTtlMs` the
|
|
38
|
+
* application passes to that sweep has elapsed — nothing derives it from
|
|
39
|
+
* `withSandbox`, which has no TTL option — so the cost is a delayed teardown
|
|
40
|
+
* rather than a lost one, provided the application actually schedules the
|
|
41
|
+
* sweep, which is its job and not the framework's. Still strictly better than
|
|
42
|
+
* failing the teardown.
|
|
43
|
+
*/
|
|
44
|
+
async function wasCancelRequested(runs, runId) {
|
|
45
|
+
try {
|
|
46
|
+
return (await runs.get(runId))?.cancelRequested === true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { RUN_CANCEL_REASON, isCancelRequestedReason, requestRunCancel, wasCancelRequested };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=cancel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel.js","names":[],"sources":["../../../../src/activities/chat/cancel.ts"],"sourcesContent":["/**\n * Out-of-band run cancellation.\n *\n * `ChatClient.stop()` only aborts a local `AbortController`; it sends nothing to\n * the server. A user pressing Stop and a user refreshing the page produce the\n * IDENTICAL TCP close, so intent is **not inferable** from a disconnect. It has\n * to arrive out of band, and there are exactly two bands:\n *\n * 1. **Durable** — {@link requestRunCancel} records the intent on the run's\n * `RunRecord`. This is the only channel that works when the run is being\n * driven by a DIFFERENT host than the one the cancel request reached, which\n * is the normal case for a detached run.\n * 2. **In-process** — abort the run's signal with {@link RUN_CANCEL_REASON}.\n * Core reads the reason back when it builds `AbortInfo`, so\n * `AbortInfo.cancelRequested` is `true` for that abort and `false` for a\n * disconnect. This is the fast path when the cancel reaches the driving host.\n *\n * A cancel endpoint SHOULD do both: record it (so a remote driver observes it)\n * and abort locally (so a co-located driver stops immediately).\n */\nimport type { RunStore } from './middleware/run-store'\n\n/**\n * Abort reason that marks an abort as an explicit cancellation.\n *\n * Namespaced so an application's own reason string cannot collide with it by\n * accident, and matched with `===` (never a substring test) so an arbitrary\n * provider error message can never be read as a deliberate cancel.\n */\nexport const RUN_CANCEL_REASON = 'tanstack-ai:cancel-requested'\n\n/** Whether an abort reason means \"the user explicitly cancelled this run\". */\nexport function isCancelRequestedReason(reason: string | undefined): boolean {\n return reason === RUN_CANCEL_REASON\n}\n\n/**\n * Record an explicit cancel on the run record.\n *\n * Deliberately does NOT set a status. The driver is the only actor that knows\n * when the agent has actually stopped and the sandbox has been torn down, so it\n * owns the transition to `'aborted'`. Writing a terminal status here would tell\n * every reader the run is over while the agent is still burning tokens.\n *\n * A no-op for an unknown `runId`, inheriting `RunStore.update`'s documented\n * invariant.\n */\nexport async function requestRunCancel(\n runs: RunStore,\n runId: string,\n): Promise<void> {\n await runs.update(runId, { cancelRequested: true })\n}\n\n/**\n * Whether an explicit cancel has been recorded for `runId`.\n *\n * Answers `false` rather than throwing when the store cannot be read. Callers\n * are middleware abort hooks, which are already on a teardown path, and a\n * store failure there must not replace the caller's own reason for tearing\n * down with a store error. The cost of a false negative is that a cancel\n * degrades into a detach — the run record gains `detachedSince`/`sandboxKey`\n * instead of transitioning to `'aborted'`. `@tanstack/ai-sandbox`'s\n * `reapDetachedRuns` recovers that run once the `detachedRunTtlMs` the\n * application passes to that sweep has elapsed — nothing derives it from\n * `withSandbox`, which has no TTL option — so the cost is a delayed teardown\n * rather than a lost one, provided the application actually schedules the\n * sweep, which is its job and not the framework's. Still strictly better than\n * failing the teardown.\n */\nexport async function wasCancelRequested(\n runs: RunStore,\n runId: string,\n): Promise<boolean> {\n try {\n const record = await runs.get(runId)\n return record?.cancelRequested === true\n } catch {\n return false\n }\n}\n"],"mappings":";;;;;;;;AA6BA,IAAa,oBAAoB;;AAGjC,SAAgB,wBAAwB,QAAqC;CAC3E,OAAO,WAAW;AACpB;;;;;;;;;;;;AAaA,eAAsB,iBACpB,MACA,OACe;CACf,MAAM,KAAK,OAAO,OAAO,EAAE,iBAAiB,KAAK,CAAC;AACpD;;;;;;;;;;;;;;;;;AAkBA,eAAsB,mBACpB,MACA,OACkB;CAClB,IAAI;EAEF,QAAO,MADc,KAAK,IAAI,KAAK,EAAA,EACpB,oBAAoB;CACrC,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AnyTextAdapter } from './adapter.js';
|
|
2
|
-
import { AnyTool,
|
|
2
|
+
import { AnyTool, ConstrainedModelMessage, InferSchemaType, LazyToolsConfig, ModelMessage, ProviderTool, SchemaInput, StructuredOutputStream, TextOptions, TypedStreamChunk, UIMessage } from '../../types.js';
|
|
3
3
|
import { AnyChatMiddleware, ChatMiddleware } from './middleware/types.js';
|
|
4
4
|
import { CheckCoverage } from './middleware/builder.js';
|
|
5
5
|
import { SystemPrompt } from '../../system-prompts.js';
|
|
6
6
|
import { DebugOption } from '../../logger/types.js';
|
|
7
|
-
import { ProviderTool } from '../../tools/provider-tool.js';
|
|
8
7
|
import { ContextFromMiddleware, ContextFromTool, DefinedContext, MergeContext, UnionToIntersection } from './runtime-context-types.js';
|
|
9
8
|
import { ChatMCPOptions } from './mcp/types.js';
|
|
10
9
|
/** The adapter kind this activity handles */
|
|
@@ -40,9 +39,10 @@ type TextActivityOptionsWithContext<TAdapter extends AnyTextAdapter, TSchema ext
|
|
|
40
39
|
* @template TAdapter - The text adapter type (created by a provider function)
|
|
41
40
|
* @template TSchema - Optional Standard Schema for structured output
|
|
42
41
|
* @template TStream - Whether to stream the output (default: true)
|
|
42
|
+
* @template TContext - Runtime context value threaded to middleware hooks and server tools
|
|
43
43
|
*/
|
|
44
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-
|
|
45
|
+
/** The text adapter to use (created by a provider function like openaiText('gpt-5.5')) */
|
|
46
46
|
adapter: TAdapter;
|
|
47
47
|
/**
|
|
48
48
|
* Conversation messages. Accepts:
|
|
@@ -76,7 +76,7 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
76
76
|
* `supports.tools` list. Passing an unsupported tool produces a
|
|
77
77
|
* compile-time error on the array element.
|
|
78
78
|
*/
|
|
79
|
-
tools?:
|
|
79
|
+
tools?: ReadonlyArray<(AnyRuntimeTool & {
|
|
80
80
|
readonly '~toolKind'?: never;
|
|
81
81
|
}) | ProviderTool<string, TAdapter['~types']['toolCapabilities'][number]>> | undefined;
|
|
82
82
|
/**
|
|
@@ -93,11 +93,6 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
93
93
|
abortController?: TextOptions['abortController'];
|
|
94
94
|
/** Strategy for controlling the agent loop */
|
|
95
95
|
agentLoopStrategy?: TextOptions['agentLoopStrategy'];
|
|
96
|
-
/**
|
|
97
|
-
* Cap how many tool calls from a single model turn are executed.
|
|
98
|
-
* Excess calls receive error results. See {@link TextOptions.maxToolCallsPerTurn}.
|
|
99
|
-
*/
|
|
100
|
-
maxToolCallsPerTurn?: TextOptions['maxToolCallsPerTurn'];
|
|
101
96
|
/**
|
|
102
97
|
* Optional configuration for lazy-tool discovery (tools marked `lazy: true`).
|
|
103
98
|
* Tunes how much of each lazy tool's description appears in the discovery
|
|
@@ -112,6 +107,13 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
112
107
|
runId?: TextOptions['runId'];
|
|
113
108
|
/** Parent run ID for AG-UI protocol nested run correlation. */
|
|
114
109
|
parentRunId?: TextOptions['parentRunId'];
|
|
110
|
+
/** Application state mirrored in a STATE_SNAPSHOT before an interrupt terminal. */
|
|
111
|
+
state?: TextOptions['state'];
|
|
112
|
+
/**
|
|
113
|
+
* AG-UI interrupt resume responses. Persistence middleware validates these
|
|
114
|
+
* before accepting new input on a thread with pending interrupts.
|
|
115
|
+
*/
|
|
116
|
+
resume?: TextOptions['resume'];
|
|
115
117
|
/**
|
|
116
118
|
* Optional Standard Schema for structured output.
|
|
117
119
|
* When provided, the activity will:
|
|
@@ -123,7 +125,7 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
123
125
|
* @example
|
|
124
126
|
* ```ts
|
|
125
127
|
* const result = await chat({
|
|
126
|
-
* adapter: openaiText('gpt-
|
|
128
|
+
* adapter: openaiText('gpt-5.5'),
|
|
127
129
|
* messages: [{ role: 'user', content: 'Generate a person' }],
|
|
128
130
|
* outputSchema: z.object({ name: z.string(), age: z.number() })
|
|
129
131
|
* })
|
|
@@ -133,7 +135,7 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
133
135
|
outputSchema?: TSchema;
|
|
134
136
|
/**
|
|
135
137
|
* Whether to stream the text result.
|
|
136
|
-
* When true (default), returns an AsyncIterable<
|
|
138
|
+
* When true (default), returns an AsyncIterable<TypedStreamChunk<TTools>> for streaming output.
|
|
137
139
|
* When false, returns a Promise<string> with the collected text content.
|
|
138
140
|
*
|
|
139
141
|
* Note: If outputSchema is provided, this option is ignored and the result
|
|
@@ -144,7 +146,7 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
144
146
|
* @example Non-streaming text
|
|
145
147
|
* ```ts
|
|
146
148
|
* const text = await chat({
|
|
147
|
-
* adapter: openaiText('gpt-
|
|
149
|
+
* adapter: openaiText('gpt-5.5'),
|
|
148
150
|
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
149
151
|
* stream: false
|
|
150
152
|
* })
|
|
@@ -159,7 +161,7 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
159
161
|
* @example
|
|
160
162
|
* ```ts
|
|
161
163
|
* const stream = chat({
|
|
162
|
-
* adapter: openaiText('gpt-
|
|
164
|
+
* adapter: openaiText('gpt-5.5'),
|
|
163
165
|
* messages: [...],
|
|
164
166
|
* middleware: [loggingMiddleware, redactionMiddleware],
|
|
165
167
|
* })
|
|
@@ -191,7 +193,9 @@ export interface TextActivityOptions<TAdapter extends AnyTextAdapter, TSchema ex
|
|
|
191
193
|
* const stream = chat({ ...chatOptions, messages })
|
|
192
194
|
* ```
|
|
193
195
|
*/
|
|
194
|
-
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
|
|
196
|
+
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>): Omit<TextActivityOptions<TAdapter, TSchema, TStream, InferredContext<TTools, TMiddleware>>, 'tools'> & {
|
|
197
|
+
tools?: TTools;
|
|
198
|
+
};
|
|
195
199
|
/**
|
|
196
200
|
* Result type for the text activity.
|
|
197
201
|
* - If outputSchema is provided AND stream is explicitly true:
|
|
@@ -201,14 +205,17 @@ export declare function createChatOptions<TAdapter extends AnyTextAdapter, TSche
|
|
|
201
205
|
* - If outputSchema is provided without explicit stream:true:
|
|
202
206
|
* Promise<InferSchemaType<TSchema>>.
|
|
203
207
|
* - If stream is explicitly false (no schema): Promise<string>.
|
|
204
|
-
* - Otherwise (default): AsyncIterable<
|
|
208
|
+
* - Otherwise (default): AsyncIterable<TypedStreamChunk<TTools>>.
|
|
209
|
+
*
|
|
210
|
+
* When tools with typed schemas are provided, the stream chunks include
|
|
211
|
+
* type-safe `toolName` and `input` fields on tool call events.
|
|
205
212
|
*
|
|
206
213
|
* `[TStream] extends [true]` is used (not `TStream extends true`) so that the
|
|
207
214
|
* default `boolean` value of `TStream` does *not* match the streaming branch.
|
|
208
215
|
* Without this, plain `chat({ outputSchema })` would type as a stream while
|
|
209
216
|
* the runtime returns a Promise — see issue #526.
|
|
210
217
|
*/
|
|
211
|
-
export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream extends boolean = boolean
|
|
218
|
+
export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream extends boolean = boolean, TTools = ReadonlyArray<AnyTool>> = TSchema extends SchemaInput ? [TStream] extends [true] ? StructuredOutputStream<InferSchemaType<TSchema>> : Promise<InferSchemaType<TSchema>> : [TStream] extends [false] ? Promise<string> : AsyncIterable<TypedStreamChunk<TTools extends ReadonlyArray<AnyTool> ? TTools : ReadonlyArray<AnyTool>>>;
|
|
212
219
|
/**
|
|
213
220
|
* Text activity - handles agentic text generation, one-shot text generation, and agentic structured output.
|
|
214
221
|
*
|
|
@@ -224,7 +231,7 @@ export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream
|
|
|
224
231
|
* import { openaiText } from '@tanstack/ai-openai'
|
|
225
232
|
*
|
|
226
233
|
* for await (const chunk of chat({
|
|
227
|
-
* adapter: openaiText('gpt-
|
|
234
|
+
* adapter: openaiText('gpt-5.5'),
|
|
228
235
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
229
236
|
* tools: [weatherTool]
|
|
230
237
|
* })) {
|
|
@@ -237,7 +244,7 @@ export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream
|
|
|
237
244
|
* @example One-shot text (streaming without tools)
|
|
238
245
|
* ```ts
|
|
239
246
|
* for await (const chunk of chat({
|
|
240
|
-
* adapter: openaiText('gpt-
|
|
247
|
+
* adapter: openaiText('gpt-5.5'),
|
|
241
248
|
* messages: [{ role: 'user', content: 'Hello!' }]
|
|
242
249
|
* })) {
|
|
243
250
|
* console.log(chunk)
|
|
@@ -247,7 +254,7 @@ export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream
|
|
|
247
254
|
* @example Non-streaming text (stream: false)
|
|
248
255
|
* ```ts
|
|
249
256
|
* const text = await chat({
|
|
250
|
-
* adapter: openaiText('gpt-
|
|
257
|
+
* adapter: openaiText('gpt-5.5'),
|
|
251
258
|
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
252
259
|
* stream: false
|
|
253
260
|
* })
|
|
@@ -259,7 +266,7 @@ export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream
|
|
|
259
266
|
* import { z } from 'zod'
|
|
260
267
|
*
|
|
261
268
|
* const result = await chat({
|
|
262
|
-
* adapter: openaiText('gpt-
|
|
269
|
+
* adapter: openaiText('gpt-5.5'),
|
|
263
270
|
* messages: [{ role: 'user', content: 'Research and summarize the topic' }],
|
|
264
271
|
* tools: [researchTool, analyzeTool],
|
|
265
272
|
* outputSchema: z.object({
|
|
@@ -270,6 +277,6 @@ export type TextActivityResult<TSchema extends SchemaInput | undefined, TStream
|
|
|
270
277
|
* // result is { summary: string, keyPoints: string[] }
|
|
271
278
|
* ```
|
|
272
279
|
*/
|
|
273
|
-
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>;
|
|
280
|
+
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, TTools>;
|
|
274
281
|
export type { TextAdapter, TextAdapterConfig, StructuredOutputOptions, StructuredOutputResult, } from './adapter.js';
|
|
275
282
|
export { BaseTextAdapter } from './adapter.js';
|