@tanstack/ai 0.11.1 → 0.13.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/dist/esm/activities/chat/adapter.d.ts +12 -4
- package/dist/esm/activities/chat/adapter.js.map +1 -1
- package/dist/esm/activities/chat/index.d.ts +23 -3
- package/dist/esm/activities/chat/index.js +78 -17
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/middleware/compose.d.ts +3 -1
- package/dist/esm/activities/chat/middleware/compose.js +79 -1
- package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
- package/dist/esm/activities/generateImage/index.d.ts +7 -0
- package/dist/esm/activities/generateImage/index.js +19 -3
- package/dist/esm/activities/generateImage/index.js.map +1 -1
- package/dist/esm/activities/generateSpeech/index.d.ts +7 -0
- package/dist/esm/activities/generateSpeech/index.js +21 -3
- package/dist/esm/activities/generateSpeech/index.js.map +1 -1
- package/dist/esm/activities/generateTranscription/index.d.ts +7 -0
- package/dist/esm/activities/generateTranscription/index.js +32 -13
- package/dist/esm/activities/generateTranscription/index.js.map +1 -1
- package/dist/esm/activities/generateVideo/index.d.ts +7 -0
- package/dist/esm/activities/generateVideo/index.js +49 -7
- package/dist/esm/activities/generateVideo/index.js.map +1 -1
- package/dist/esm/activities/summarize/index.d.ts +7 -0
- package/dist/esm/activities/summarize/index.js +54 -19
- package/dist/esm/activities/summarize/index.js.map +1 -1
- package/dist/esm/adapter-internals.d.ts +3 -0
- package/dist/esm/adapter-internals.js +7 -0
- package/dist/esm/adapter-internals.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger/console-logger.d.ts +11 -0
- package/dist/esm/logger/console-logger.js +27 -0
- package/dist/esm/logger/console-logger.js.map +1 -0
- package/dist/esm/logger/internal-logger.d.ts +33 -0
- package/dist/esm/logger/internal-logger.js +69 -0
- package/dist/esm/logger/internal-logger.js.map +1 -0
- package/dist/esm/logger/resolve.d.ts +14 -0
- package/dist/esm/logger/resolve.js +54 -0
- package/dist/esm/logger/resolve.js.map +1 -0
- package/dist/esm/logger/types.d.ts +75 -0
- package/dist/esm/tools/provider-tool.d.ts +21 -0
- package/dist/esm/types.d.ts +34 -0
- package/package.json +6 -2
- package/skills/ai-core/SKILL.md +5 -3
- package/skills/ai-core/debug-logging/SKILL.md +263 -0
- package/src/activities/chat/adapter.ts +14 -3
- package/src/activities/chat/index.ts +119 -24
- package/src/activities/chat/middleware/compose.ts +84 -1
- package/src/activities/generateImage/index.ts +29 -3
- package/src/activities/generateSpeech/index.ts +35 -3
- package/src/activities/generateTranscription/index.ts +45 -13
- package/src/activities/generateVideo/index.ts +65 -6
- package/src/activities/summarize/index.ts +66 -20
- package/src/adapter-internals.ts +7 -0
- package/src/index.ts +12 -0
- package/src/logger/console-logger.ts +49 -0
- package/src/logger/internal-logger.ts +107 -0
- package/src/logger/resolve.ts +72 -0
- package/src/logger/types.ts +78 -0
- package/src/tools/provider-tool.ts +25 -0
- package/src/types.ts +36 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable logger interface consumed by every `@tanstack/ai` activity when `debug` is enabled. Supply a custom implementation via `debug: { logger }` on `chat()`, `summarize()`, `generateImage()`, etc. The four methods correspond to log levels: use `debug` for chunk-level diagnostic output, `info`/`warn` for notable events, `error` for caught exceptions.
|
|
3
|
+
*/
|
|
4
|
+
export interface Logger {
|
|
5
|
+
/**
|
|
6
|
+
* Called for chunk-level diagnostic output (raw provider chunks, per-chunk output, agent-loop iteration markers).
|
|
7
|
+
* @param meta Structured data forwarded to the underlying logger. Loggers like pino will preserve this as a structured record; console-based loggers pass it as the second argument to `console.<level>`.
|
|
8
|
+
*/
|
|
9
|
+
debug: (message: string, meta?: Record<string, unknown>) => void
|
|
10
|
+
/**
|
|
11
|
+
* Called for notable informational events (outgoing requests, tool invocations, middleware transitions).
|
|
12
|
+
* @param meta Structured data forwarded to the underlying logger. Loggers like pino will preserve this as a structured record; console-based loggers pass it as the second argument to `console.<level>`.
|
|
13
|
+
*/
|
|
14
|
+
info: (message: string, meta?: Record<string, unknown>) => void
|
|
15
|
+
/**
|
|
16
|
+
* Called for notable warnings that don't halt execution (deprecations, recoverable anomalies).
|
|
17
|
+
* @param meta Structured data forwarded to the underlying logger. Loggers like pino will preserve this as a structured record; console-based loggers pass it as the second argument to `console.<level>`.
|
|
18
|
+
*/
|
|
19
|
+
warn: (message: string, meta?: Record<string, unknown>) => void
|
|
20
|
+
/**
|
|
21
|
+
* Called for caught exceptions throughout the pipeline.
|
|
22
|
+
* @param meta Structured data forwarded to the underlying logger. Loggers like pino will preserve this as a structured record; console-based loggers pass it as the second argument to `console.<level>`.
|
|
23
|
+
*/
|
|
24
|
+
error: (message: string, meta?: Record<string, unknown>) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Per-category toggles for debug logging. Each flag enables or disables one class of log message. Unspecified flags default to `true` when `DebugConfig` is partially specified; `undefined` on the `debug` option defaults all flags to `false` except `errors`.
|
|
29
|
+
*/
|
|
30
|
+
export interface DebugCategories {
|
|
31
|
+
/**
|
|
32
|
+
* Raw chunks/frames received from a provider SDK (OpenAI, Anthropic, Gemini, Ollama, Grok, Groq, OpenRouter, fal, ElevenLabs). Emitted inside every streaming adapter's chunk loop.
|
|
33
|
+
*/
|
|
34
|
+
provider?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* Chunks/results yielded to the consumer after all middleware. For streaming activities this fires per chunk; for non-streaming activities it fires once per result.
|
|
37
|
+
*/
|
|
38
|
+
output?: boolean
|
|
39
|
+
/**
|
|
40
|
+
* Inputs and outputs around each middleware hook invocation. Chat-only.
|
|
41
|
+
*/
|
|
42
|
+
middleware?: boolean
|
|
43
|
+
/**
|
|
44
|
+
* Before/after tool-call execution in the chat agent loop. Chat-only.
|
|
45
|
+
*/
|
|
46
|
+
tools?: boolean
|
|
47
|
+
/**
|
|
48
|
+
* Iteration markers and phase transitions in the chat agent loop. Chat-only.
|
|
49
|
+
*/
|
|
50
|
+
agentLoop?: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Config transforms returned by middleware `onConfig` hooks. Chat-only.
|
|
53
|
+
*/
|
|
54
|
+
config?: boolean
|
|
55
|
+
/**
|
|
56
|
+
* Caught errors throughout the pipeline. Unlike other categories, defaults to `true` even when `debug` is unspecified. Explicitly set `errors: false` or `debug: false` to silence.
|
|
57
|
+
*/
|
|
58
|
+
errors?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* Outgoing call metadata (provider, model, message/tool counts) emitted before each adapter SDK call.
|
|
61
|
+
*/
|
|
62
|
+
request?: boolean
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Granular debug configuration combining per-category toggles with an optional custom logger. Any unspecified category flag defaults to `true`.
|
|
67
|
+
*/
|
|
68
|
+
export interface DebugConfig extends DebugCategories {
|
|
69
|
+
/**
|
|
70
|
+
* Custom `Logger` implementation. When omitted, a default `ConsoleLogger` routes output to `console.debug`/`info`/`warn`/`error`.
|
|
71
|
+
*/
|
|
72
|
+
logger?: Logger
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The shape accepted by the `debug` option on every `@tanstack/ai` activity. Pass `true` to enable all categories with the default console logger; `false` to silence everything including errors; an object for granular control.
|
|
77
|
+
*/
|
|
78
|
+
export type DebugOption = boolean | DebugConfig
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Tool } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A provider-specific tool produced by an adapter-package factory
|
|
5
|
+
* (e.g. `webSearchTool` from `@tanstack/ai-anthropic/tools`).
|
|
6
|
+
*
|
|
7
|
+
* The two `~`-prefixed fields are type-only phantom brands — they are never
|
|
8
|
+
* assigned at runtime. They allow the core type system to match a factory's
|
|
9
|
+
* output against the selected model's `supports.tools` list and surface a
|
|
10
|
+
* compile-time error when the combination is unsupported.
|
|
11
|
+
*
|
|
12
|
+
* User-defined tools (via `toolDefinition()`) remain plain `Tool` and stay
|
|
13
|
+
* assignable to any model.
|
|
14
|
+
*
|
|
15
|
+
* @template TProvider - Provider identifier (e.g. `'anthropic'`, `'openai'`).
|
|
16
|
+
* @template TKind - Canonical tool-kind string matching the provider's
|
|
17
|
+
* `supports.tools` entries (e.g. `'web_search'`, `'code_execution'`).
|
|
18
|
+
*/
|
|
19
|
+
export interface ProviderTool<
|
|
20
|
+
TProvider extends string,
|
|
21
|
+
TKind extends string,
|
|
22
|
+
> extends Tool {
|
|
23
|
+
readonly '~provider': TProvider
|
|
24
|
+
readonly '~toolKind': TKind
|
|
25
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StandardJSONSchemaV1 } from '@standard-schema/spec'
|
|
2
|
+
import type { InternalLogger } from './logger/internal-logger'
|
|
2
3
|
import type {
|
|
3
4
|
BaseEvent as AGUIBaseEvent,
|
|
4
5
|
CustomEvent as AGUICustomEvent,
|
|
@@ -738,6 +739,14 @@ export interface TextOptions<
|
|
|
738
739
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController
|
|
739
740
|
*/
|
|
740
741
|
abortController?: AbortController
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Internal logger threaded from the chat entry point. Adapter implementations
|
|
745
|
+
* must call `logger.request()` before SDK calls, `logger.provider()` for each
|
|
746
|
+
* chunk received, and `logger.errors()` in catch blocks.
|
|
747
|
+
*/
|
|
748
|
+
logger: InternalLogger
|
|
749
|
+
|
|
741
750
|
/**
|
|
742
751
|
* Thread ID for AG-UI protocol run correlation.
|
|
743
752
|
* When provided, this will be used in RunStartedEvent and RunFinishedEvent.
|
|
@@ -1163,6 +1172,11 @@ export interface SummarizationOptions {
|
|
|
1163
1172
|
maxLength?: number
|
|
1164
1173
|
style?: 'bullet-points' | 'paragraph' | 'concise'
|
|
1165
1174
|
focus?: Array<string>
|
|
1175
|
+
/**
|
|
1176
|
+
* Internal logger threaded from the summarize() entry point. Adapters must
|
|
1177
|
+
* call logger.request() before the SDK call and logger.errors() in catch blocks.
|
|
1178
|
+
*/
|
|
1179
|
+
logger: InternalLogger
|
|
1166
1180
|
}
|
|
1167
1181
|
|
|
1168
1182
|
export interface SummarizationResult {
|
|
@@ -1198,6 +1212,11 @@ export interface ImageGenerationOptions<
|
|
|
1198
1212
|
size?: TSize
|
|
1199
1213
|
/** Model-specific options for image generation */
|
|
1200
1214
|
modelOptions?: TProviderOptions
|
|
1215
|
+
/**
|
|
1216
|
+
* Internal logger threaded from the generateImage() entry point. Adapters must
|
|
1217
|
+
* call logger.request() before the SDK call and logger.errors() in catch blocks.
|
|
1218
|
+
*/
|
|
1219
|
+
logger: InternalLogger
|
|
1201
1220
|
}
|
|
1202
1221
|
|
|
1203
1222
|
/**
|
|
@@ -1254,6 +1273,11 @@ export interface VideoGenerationOptions<
|
|
|
1254
1273
|
duration?: number
|
|
1255
1274
|
/** Model-specific options for video generation */
|
|
1256
1275
|
modelOptions?: TProviderOptions
|
|
1276
|
+
/**
|
|
1277
|
+
* Internal logger threaded from the generateVideo() entry point. Adapters must
|
|
1278
|
+
* call logger.request() before the SDK call and logger.errors() in catch blocks.
|
|
1279
|
+
*/
|
|
1280
|
+
logger: InternalLogger
|
|
1257
1281
|
}
|
|
1258
1282
|
|
|
1259
1283
|
/**
|
|
@@ -1319,6 +1343,12 @@ export interface TTSOptions<TProviderOptions extends object = object> {
|
|
|
1319
1343
|
speed?: number
|
|
1320
1344
|
/** Model-specific options for TTS generation */
|
|
1321
1345
|
modelOptions?: TProviderOptions
|
|
1346
|
+
/**
|
|
1347
|
+
* Internal logger threaded from the generateSpeech() entry point. Adapters
|
|
1348
|
+
* must call logger.request() before the SDK call and logger.errors() in
|
|
1349
|
+
* catch blocks.
|
|
1350
|
+
*/
|
|
1351
|
+
logger: InternalLogger
|
|
1322
1352
|
}
|
|
1323
1353
|
|
|
1324
1354
|
/**
|
|
@@ -1362,6 +1392,12 @@ export interface TranscriptionOptions<
|
|
|
1362
1392
|
responseFormat?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt'
|
|
1363
1393
|
/** Model-specific options for transcription */
|
|
1364
1394
|
modelOptions?: TProviderOptions
|
|
1395
|
+
/**
|
|
1396
|
+
* Internal logger threaded from the generateTranscription() entry point.
|
|
1397
|
+
* Adapters must call logger.request() before the SDK call and logger.errors()
|
|
1398
|
+
* in catch blocks.
|
|
1399
|
+
*/
|
|
1400
|
+
logger: InternalLogger
|
|
1365
1401
|
}
|
|
1366
1402
|
|
|
1367
1403
|
/**
|