@tanstack/ai-angular 0.14.1 → 1.0.1
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 +19 -8
- package/dist/README.md +19 -8
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs +4 -6
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs.map +1 -1
- package/dist/fesm2022/tanstack-ai-angular.mjs +13 -54
- package/dist/fesm2022/tanstack-ai-angular.mjs.map +1 -1
- package/dist/types/tanstack-ai-angular-ui.d.ts +2 -3
- package/dist/types/tanstack-ai-angular.d.ts +29 -46
- package/package.json +4 -4
- package/src/index.ts +0 -2
- package/src/inject-chat.ts +6 -34
- package/src/inject-generate-audio.ts +3 -6
- package/src/inject-generate-image.ts +2 -6
- package/src/inject-generate-speech.ts +2 -6
- package/src/inject-generate-video.ts +7 -20
- package/src/inject-generation.ts +8 -28
- package/src/inject-summarize.ts +2 -6
- package/src/inject-transcription.ts +2 -6
- package/src/inject-web-mcp-tools.ts +1 -13
- package/src/types.ts +2 -12
- package/ui/src/create-chat-hook.ts +7 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyClientTool, SchemaInput, InterruptDefinition, ModelMessage, RunAgentResumeItem, InferSchemaType, StreamChunk, ImageGenerationResult, AudioGenerationResult, TTSResult, TranscriptionResult, SummarizationResult } from '@tanstack/ai';
|
|
2
|
-
import { InferredClientContext, DistributedOmit, ChatClientOptions, AIDevtoolsDisplayOptions, ClientContextOptionFromTools, UIMessage, MultimodalContent, SendMessageOptions, QueuedMessage, BoundInterrupts, ChatInterruptState, ResolvableChatInterrupt, ChatResumeState, ChatClientState, ConnectionStatus, SubscribeWebMCPToolsOptions, AnyClientTool as AnyClientTool$1, RegisterWebMCPToolsOptions, ConnectConnectionAdapter, GenerationFetcher, GenerationRestoredResult, GenerationClientState,
|
|
2
|
+
import { InferredClientContext, DistributedOmit, ChatClientOptions, AIDevtoolsDisplayOptions, ClientContextOptionFromTools, UIMessage, MultimodalContent, SendMessageOptions, QueuedMessage, BoundInterrupts, ChatInterruptState, ResolvableChatInterrupt, ChatResumeState, ChatClientState, ConnectionStatus, SubscribeWebMCPToolsOptions, AnyClientTool as AnyClientTool$1, RegisterWebMCPToolsOptions, ConnectConnectionAdapter, GenerationFetcher, GenerationRestoredResult, GenerationClientState, InferGenerationOutputFromReturn, ImageGenerateInput, AudioGenerateInput, SpeechGenerateInput, TranscriptionGenerateInput, AudioRecorderOptions, AudioRecording, InferAudioRecordingOutput, SummarizeGenerateInput, VideoGenerateResult, VideoGenerateInput, VideoStatusInfo } from '@tanstack/ai-client';
|
|
3
3
|
export { AudioGenerateInput, AudioRecorder, BatchStrategy, ChatClient, ChatClientPersistence, ChatPersistedState, ChatPersistenceOption, ChatRequestBody, ChatStorageAdapter, CompositeStrategy, ConnectConnectionAdapter, ConnectionAdapter, CreateMcpAppBridgeOptions, DurableStreamIncompleteError, FetchConnectionOptions, FetchJsonOptions, GENERATION_EVENTS, GenerationClient, GenerationClientState, GetWebMCPToolsOptions, ImageGenerateInput, ImmediateStrategy, IndexedDBPersistenceOptions, InferChatMessages, InterruptManager, McpAppBridge, MultimodalContent, PartialJSONParser, PunctuationStrategy, QueueConfig, QueueOption, QueueStrategy, QueuedMessage, RealtimeClient, RunAgentInputContext, SendMessageOptions, SpeechGenerateInput, StorageUnavailableError, StreamProcessor, StreamReconnectLimitError, StreamTruncatedError, SubscribeConnectionAdapter, SubscribeWebMCPToolsOptions, SummarizeGenerateInput, TranscriptionGenerateInput, UIMessage, UnsupportedResponseStreamError, VideoGenerateInput, VideoGenerateResult, VideoGenerationClient, VideoStatusInfo, WebMCPPageTool, WebSocketConnectionOptions, WebStoragePersistenceOptions, WhenBusy, WordBoundaryStrategy, XhrConnectionOptions, clientTools, convertMessagesToModelMessages, createAIDevtoolsGenerationPreview, createChatClientOptions, createMcpAppBridge, defaultJSONParser, fetchHttpStream, fetchJson, fetchServerSentEvents, generateMessageId, getWebMCPTools, indexedDBPersistence, localStoragePersistence, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, reconstructAudioResult, reconstructImageResult, reconstructSpeechResult, reconstructSummarizeResult, reconstructTranscriptionResult, registerWebMCPTools, rpcStream, sessionStoragePersistence, stream, subscribeWebMCPTools, uiMessageToModelMessages, webSocket, xhrHttpStream, xhrServerSentEvents } from '@tanstack/ai-client';
|
|
4
4
|
import { Signal } from '@angular/core';
|
|
5
5
|
import { ByokClient, ByokSnapshot } from '@tanstack/ai-client/byok';
|
|
@@ -25,17 +25,15 @@ type DeepPartial<T> = T extends ReadonlyArray<infer U> ? Array<DeepPartial<U>> :
|
|
|
25
25
|
*
|
|
26
26
|
* Mirrors the Vue `useChat` options, except:
|
|
27
27
|
* - State-change callbacks are managed internally and exposed as signals.
|
|
28
|
-
* - `tools`, `
|
|
28
|
+
* - `tools`, `forwardedProps`, and `live` accept a {@link ReactiveOption} so
|
|
29
29
|
* they can be a static value, a `Signal`, or a getter and stay reactive.
|
|
30
30
|
*/
|
|
31
|
-
type InjectChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>, TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> = readonly []> = DistributedOmit<ChatClientOptions<TTools, TContext, TInterrupts>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'onHydratingChange' | 'onQueueChange' | 'onResumeStateChange' | 'onRunIdChange' | 'context' | 'devtools' | '
|
|
31
|
+
type InjectChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>, TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> = readonly []> = DistributedOmit<ChatClientOptions<TTools, TContext, TInterrupts>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'onHydratingChange' | 'onQueueChange' | 'onResumeStateChange' | 'onRunIdChange' | 'context' | 'devtools' | 'forwardedProps' | 'tools'> & {
|
|
32
32
|
/** Display options for TanStack AI Devtools. */
|
|
33
33
|
devtools?: AIDevtoolsDisplayOptions;
|
|
34
34
|
/** Client-side tools with execution logic. Reactive. */
|
|
35
35
|
tools?: ReactiveOption<TTools>;
|
|
36
|
-
/**
|
|
37
|
-
body?: ReactiveOption<Record<string, any>>;
|
|
38
|
-
/** Forwarded request props (preferred over `body`). Reactive. */
|
|
36
|
+
/** Forwarded request props. Reactive. */
|
|
39
37
|
forwardedProps?: ReactiveOption<Record<string, any>>;
|
|
40
38
|
/** Whether to keep a live subscription open. Reactive. */
|
|
41
39
|
live?: ReactiveOption<boolean>;
|
|
@@ -78,11 +76,6 @@ interface BaseInjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any
|
|
|
78
76
|
state?: 'output-available' | 'output-error';
|
|
79
77
|
errorText?: string;
|
|
80
78
|
}) => Promise<void>;
|
|
81
|
-
/** Respond to a tool approval request. */
|
|
82
|
-
addToolApprovalResponse: (response: {
|
|
83
|
-
id: string;
|
|
84
|
-
approved: boolean;
|
|
85
|
-
}) => Promise<void>;
|
|
86
79
|
/**
|
|
87
80
|
* The id of the run this client has in flight — one it started or rejoined —
|
|
88
81
|
* or `null` when there is none (including while a run sits paused on an
|
|
@@ -97,8 +90,6 @@ interface BaseInjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any
|
|
|
97
90
|
runId: Signal<string | null>;
|
|
98
91
|
/** Immutable bound interrupts for the current interrupted run. */
|
|
99
92
|
interrupts: Signal<BoundInterrupts<TTools, TInterrupts>>;
|
|
100
|
-
/** @deprecated Use `interrupts`. */
|
|
101
|
-
pendingInterrupts: Signal<BoundInterrupts<TTools, TInterrupts>>;
|
|
102
93
|
/** Batch-level interrupt errors. */
|
|
103
94
|
interruptErrors: Signal<ChatInterruptState<TTools, TInterrupts>['interruptErrors']>;
|
|
104
95
|
/** Whether the client is submitting an interrupt batch. */
|
|
@@ -142,7 +133,7 @@ interface BaseInjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any
|
|
|
142
133
|
isHydrating: Signal<boolean>;
|
|
143
134
|
}
|
|
144
135
|
|
|
145
|
-
declare function injectChat<const TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>, const TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> = readonly []>(options
|
|
136
|
+
declare function injectChat<const TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>, const TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> = readonly []>(options: InjectChatOptions<TTools, TSchema, TContext, TInterrupts>): InjectChatResult<TTools, TSchema, TInterrupts>;
|
|
146
137
|
|
|
147
138
|
declare function injectByok(client: ByokClient): Signal<ByokSnapshot>;
|
|
148
139
|
|
|
@@ -155,8 +146,6 @@ type InjectRegisterWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool
|
|
|
155
146
|
/** Receives asynchronous WebMCP registration errors. */
|
|
156
147
|
onError?: (error: unknown) => void;
|
|
157
148
|
};
|
|
158
|
-
/** @deprecated Use `InjectRegisterWebMCPToolsOptions`. Removed in 1.0.0. */
|
|
159
|
-
type InjectWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool$1>, TContext = InferredClientContext<TTools>> = InjectRegisterWebMCPToolsOptions<TTools, TContext>;
|
|
160
149
|
/**
|
|
161
150
|
* Registers executable client tools with WebMCP for the current Angular owner.
|
|
162
151
|
*
|
|
@@ -174,11 +163,6 @@ type InjectWebMCPToolsOptions<TTools extends ReadonlyArray<AnyClientTool$1>, TCo
|
|
|
174
163
|
* ```
|
|
175
164
|
*/
|
|
176
165
|
declare function injectRegisterWebMCPTools<const TTools extends ReadonlyArray<AnyClientTool$1>, TContext = InferredClientContext<TTools>>(tools: TTools, ...[options]: {} extends InjectRegisterWebMCPToolsOptions<TTools, TContext> ? [options?: InjectRegisterWebMCPToolsOptions<TTools, TContext>] : [options: InjectRegisterWebMCPToolsOptions<TTools, TContext>]): void;
|
|
177
|
-
/**
|
|
178
|
-
* @deprecated Use `injectRegisterWebMCPTools`. Removed in 1.0.0.
|
|
179
|
-
* @alias
|
|
180
|
-
*/
|
|
181
|
-
declare const injectWebMCPTools: typeof injectRegisterWebMCPTools;
|
|
182
166
|
/** Options for {@link injectPageWebMCPTools}. */
|
|
183
167
|
type InjectPageWebMCPToolsOptions = Omit<SubscribeWebMCPToolsOptions, 'signal'>;
|
|
184
168
|
/**
|
|
@@ -195,7 +179,7 @@ type InjectPageWebMCPToolsOptions = Omit<SubscribeWebMCPToolsOptions, 'signal'>;
|
|
|
195
179
|
* pageTools = injectPageWebMCPTools({
|
|
196
180
|
* filter: (tool) => tool.origin === location.origin,
|
|
197
181
|
* })
|
|
198
|
-
* chat = injectChat({ connection, tools: this.pageTools })
|
|
182
|
+
* chat = injectChat({ threadId: 'support-1', connection, tools: this.pageTools })
|
|
199
183
|
* ```
|
|
200
184
|
*/
|
|
201
185
|
declare function injectPageWebMCPTools(options?: InjectPageWebMCPToolsOptions): Signal<Array<AnyClientTool$1>>;
|
|
@@ -231,11 +215,10 @@ interface InjectGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
|
231
215
|
* `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread
|
|
232
216
|
* id on the wire, which the protocol requires.
|
|
233
217
|
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* omitted, the client mints a wire id after mount.
|
|
218
|
+
* Required. A generated id would change on every reload, so persistence
|
|
219
|
+
* would restore nothing.
|
|
237
220
|
*/
|
|
238
|
-
threadId
|
|
221
|
+
threadId: string;
|
|
239
222
|
/**
|
|
240
223
|
* Server-driven hydration handler for `persistence: true` when the
|
|
241
224
|
* connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` /
|
|
@@ -301,9 +284,9 @@ interface InjectGenerationResult<TOutput, TInput extends Record<string, any> = R
|
|
|
301
284
|
*/
|
|
302
285
|
runId: Signal<string | null>;
|
|
303
286
|
}
|
|
304
|
-
declare function injectGeneration<TInput extends Record<string, any>, TResult, TTransformed = void>(options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'
|
|
287
|
+
declare function injectGeneration<TInput extends Record<string, any>, TResult, TTransformed = void>(options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {
|
|
305
288
|
onResult?: (result: TResult) => TTransformed;
|
|
306
|
-
}
|
|
289
|
+
}): InjectGenerationResult<InferGenerationOutputFromReturn<TResult, TTransformed>, TInput>;
|
|
307
290
|
|
|
308
291
|
type InjectGenerateImageOptions<TOutput = ImageGenerationResult> = Omit<InjectGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>, 'onResult' | 'reconstructResult'> & {
|
|
309
292
|
onResult?: (result: ImageGenerationResult) => TOutput | null | void;
|
|
@@ -315,9 +298,9 @@ interface InjectGenerateImageResult<TOutput = ImageGenerationResult> extends Omi
|
|
|
315
298
|
error: Signal<Error | undefined>;
|
|
316
299
|
status: Signal<GenerationClientState>;
|
|
317
300
|
}
|
|
318
|
-
declare function injectGenerateImage<TTransformed = void>(options: Omit<InjectGenerateImageOptions, 'onResult'
|
|
301
|
+
declare function injectGenerateImage<TTransformed = void>(options: Omit<InjectGenerateImageOptions, 'onResult'> & {
|
|
319
302
|
onResult?: (result: ImageGenerationResult) => TTransformed;
|
|
320
|
-
}
|
|
303
|
+
}): InjectGenerateImageResult<InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>>;
|
|
321
304
|
|
|
322
305
|
/**
|
|
323
306
|
* Options for the injectGenerateAudio injectable.
|
|
@@ -387,6 +370,7 @@ interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> extends Omi
|
|
|
387
370
|
* })
|
|
388
371
|
* export class AudioComponent {
|
|
389
372
|
* private gen = injectGenerateAudio({
|
|
373
|
+
* threadId: 'theme-audio',
|
|
390
374
|
* connection: fetchServerSentEvents('/api/generate/audio'),
|
|
391
375
|
* })
|
|
392
376
|
*
|
|
@@ -396,9 +380,9 @@ interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> extends Omi
|
|
|
396
380
|
* }
|
|
397
381
|
* ```
|
|
398
382
|
*/
|
|
399
|
-
declare function injectGenerateAudio<TTransformed = void>(options: Omit<InjectGenerateAudioOptions, 'onResult'
|
|
383
|
+
declare function injectGenerateAudio<TTransformed = void>(options: Omit<InjectGenerateAudioOptions, 'onResult'> & {
|
|
400
384
|
onResult?: (result: AudioGenerationResult) => TTransformed;
|
|
401
|
-
}
|
|
385
|
+
}): InjectGenerateAudioResult<InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>>;
|
|
402
386
|
|
|
403
387
|
type InjectGenerateSpeechOptions<TOutput = TTSResult> = Omit<InjectGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>, 'onResult' | 'reconstructResult'> & {
|
|
404
388
|
onResult?: (result: TTSResult) => TOutput | null | void;
|
|
@@ -410,9 +394,9 @@ interface InjectGenerateSpeechResult<TOutput = TTSResult> extends Omit<InjectGen
|
|
|
410
394
|
error: Signal<Error | undefined>;
|
|
411
395
|
status: Signal<GenerationClientState>;
|
|
412
396
|
}
|
|
413
|
-
declare function injectGenerateSpeech<TTransformed = void>(options: Omit<InjectGenerateSpeechOptions, 'onResult'
|
|
397
|
+
declare function injectGenerateSpeech<TTransformed = void>(options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {
|
|
414
398
|
onResult?: (result: TTSResult) => TTransformed;
|
|
415
|
-
}
|
|
399
|
+
}): InjectGenerateSpeechResult<InferGenerationOutputFromReturn<TTSResult, TTransformed>>;
|
|
416
400
|
|
|
417
401
|
type InjectTranscriptionOptions<TOutput = TranscriptionResult> = Omit<InjectGenerationOptions<TranscriptionGenerateInput, TranscriptionResult, TOutput>, 'onResult' | 'reconstructResult'> & {
|
|
418
402
|
onResult?: (result: TranscriptionResult) => TOutput | null | void;
|
|
@@ -424,9 +408,9 @@ interface InjectTranscriptionResult<TOutput = TranscriptionResult> extends Omit<
|
|
|
424
408
|
error: Signal<Error | undefined>;
|
|
425
409
|
status: Signal<GenerationClientState>;
|
|
426
410
|
}
|
|
427
|
-
declare function injectTranscription<TTransformed = void>(options: Omit<InjectTranscriptionOptions, 'onResult'
|
|
411
|
+
declare function injectTranscription<TTransformed = void>(options: Omit<InjectTranscriptionOptions, 'onResult'> & {
|
|
428
412
|
onResult?: (result: TranscriptionResult) => TTransformed;
|
|
429
|
-
}
|
|
413
|
+
}): InjectTranscriptionResult<InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>>;
|
|
430
414
|
|
|
431
415
|
type InjectAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {
|
|
432
416
|
/**
|
|
@@ -473,9 +457,9 @@ interface InjectSummarizeResult<TOutput = SummarizationResult> extends Omit<Inje
|
|
|
473
457
|
error: Signal<Error | undefined>;
|
|
474
458
|
status: Signal<GenerationClientState>;
|
|
475
459
|
}
|
|
476
|
-
declare function injectSummarize<TTransformed = void>(options: Omit<InjectSummarizeOptions, 'onResult'
|
|
460
|
+
declare function injectSummarize<TTransformed = void>(options: Omit<InjectSummarizeOptions, 'onResult'> & {
|
|
477
461
|
onResult?: (result: SummarizationResult) => TTransformed;
|
|
478
|
-
}
|
|
462
|
+
}): InjectSummarizeResult<InferGenerationOutputFromReturn<SummarizationResult, TTransformed>>;
|
|
479
463
|
|
|
480
464
|
interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {
|
|
481
465
|
connection?: ConnectConnectionAdapter;
|
|
@@ -504,11 +488,10 @@ interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {
|
|
|
504
488
|
* `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread
|
|
505
489
|
* id on the wire, which the protocol requires.
|
|
506
490
|
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
* omitted, the client mints a wire id after mount.
|
|
491
|
+
* Required. A generated id would change on every reload, so persistence
|
|
492
|
+
* would restore nothing.
|
|
510
493
|
*/
|
|
511
|
-
threadId
|
|
494
|
+
threadId: string;
|
|
512
495
|
/**
|
|
513
496
|
* Server-driven hydration handler for `persistence: true` when the
|
|
514
497
|
* connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` /
|
|
@@ -548,9 +531,9 @@ interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {
|
|
|
548
531
|
*/
|
|
549
532
|
runId: Signal<string | null>;
|
|
550
533
|
}
|
|
551
|
-
declare function injectGenerateVideo<TTransformed = void>(options: Omit<InjectGenerateVideoOptions, 'onResult'
|
|
534
|
+
declare function injectGenerateVideo<TTransformed = void>(options: Omit<InjectGenerateVideoOptions, 'onResult'> & {
|
|
552
535
|
onResult?: (result: VideoGenerateResult) => TTransformed;
|
|
553
|
-
}
|
|
536
|
+
}): InjectGenerateVideoResult<InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>>;
|
|
554
537
|
|
|
555
|
-
export { injectAudioRecorder, injectByok, injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectPageWebMCPTools, injectRegisterWebMCPTools, injectSummarize, injectTranscription
|
|
556
|
-
export type { DeepPartial, InjectAudioRecorderOptions, InjectAudioRecorderResult, InjectChatOptions, InjectChatResult, InjectGenerateAudioOptions, InjectGenerateAudioResult, InjectGenerateImageOptions, InjectGenerateImageResult, InjectGenerateSpeechOptions, InjectGenerateSpeechResult, InjectGenerateVideoOptions, InjectGenerateVideoResult, InjectGenerationOptions, InjectGenerationResult, InjectPageWebMCPToolsOptions, InjectRegisterWebMCPToolsOptions, InjectSummarizeOptions, InjectSummarizeResult, InjectTranscriptionOptions, InjectTranscriptionResult,
|
|
538
|
+
export { injectAudioRecorder, injectByok, injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectPageWebMCPTools, injectRegisterWebMCPTools, injectSummarize, injectTranscription };
|
|
539
|
+
export type { DeepPartial, InjectAudioRecorderOptions, InjectAudioRecorderResult, InjectChatOptions, InjectChatResult, InjectGenerateAudioOptions, InjectGenerateAudioResult, InjectGenerateImageOptions, InjectGenerateImageResult, InjectGenerateSpeechOptions, InjectGenerateSpeechResult, InjectGenerateVideoOptions, InjectGenerateVideoResult, InjectGenerationOptions, InjectGenerationResult, InjectPageWebMCPToolsOptions, InjectRegisterWebMCPToolsOptions, InjectSummarizeOptions, InjectSummarizeResult, InjectTranscriptionOptions, InjectTranscriptionResult, ReactiveOption };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Angular signals integration for TanStack AI streaming chat, structured outputs, and media generation.",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"tslib": "^2.8.1",
|
|
57
|
-
"@tanstack/ai-client": "^0.
|
|
57
|
+
"@tanstack/ai-client": "^1.0.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@angular/common": ">=21.0.0",
|
|
61
61
|
"@angular/core": ">=21.0.0",
|
|
62
|
-
"@tanstack/ai": "^0.
|
|
62
|
+
"@tanstack/ai": "^1.0.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@analogjs/vite-plugin-angular": "^2.6.2",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"vitest": "^4.1.10",
|
|
77
77
|
"zod": "^4.2.0",
|
|
78
78
|
"zone.js": "^0.15.0",
|
|
79
|
-
"@tanstack/ai": "0.
|
|
79
|
+
"@tanstack/ai": "1.0.1"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"clean": "premove ./build ./dist",
|
package/src/index.ts
CHANGED
|
@@ -6,12 +6,10 @@ export { injectByok } from './inject-byok'
|
|
|
6
6
|
export {
|
|
7
7
|
injectPageWebMCPTools,
|
|
8
8
|
injectRegisterWebMCPTools,
|
|
9
|
-
injectWebMCPTools,
|
|
10
9
|
} from './inject-web-mcp-tools'
|
|
11
10
|
export type {
|
|
12
11
|
InjectPageWebMCPToolsOptions,
|
|
13
12
|
InjectRegisterWebMCPToolsOptions,
|
|
14
|
-
InjectWebMCPToolsOptions,
|
|
15
13
|
} from './inject-web-mcp-tools'
|
|
16
14
|
|
|
17
15
|
// Generation
|
package/src/inject-chat.ts
CHANGED
|
@@ -43,12 +43,7 @@ export function injectChat<
|
|
|
43
43
|
InterruptDefinition<any, any, any, any>
|
|
44
44
|
> = readonly [],
|
|
45
45
|
>(
|
|
46
|
-
options: InjectChatOptions<
|
|
47
|
-
TTools,
|
|
48
|
-
TSchema,
|
|
49
|
-
TContext,
|
|
50
|
-
TInterrupts
|
|
51
|
-
> = {} as InjectChatOptions<TTools, TSchema, TContext, TInterrupts>,
|
|
46
|
+
options: InjectChatOptions<TTools, TSchema, TContext, TInterrupts>,
|
|
52
47
|
): InjectChatResult<TTools, TSchema, TInterrupts> {
|
|
53
48
|
assertInInjectionContext(injectChat)
|
|
54
49
|
|
|
@@ -59,8 +54,6 @@ export function injectChat<
|
|
|
59
54
|
const injector = inject(Injector)
|
|
60
55
|
|
|
61
56
|
// Reactive option sources. Plain values become constant computeds.
|
|
62
|
-
const bodySource =
|
|
63
|
-
options.body !== undefined ? toReactive(options.body) : undefined
|
|
64
57
|
const forwardedPropsSource =
|
|
65
58
|
options.forwardedProps !== undefined
|
|
66
59
|
? toReactive(options.forwardedProps)
|
|
@@ -82,28 +75,18 @@ export function injectChat<
|
|
|
82
75
|
...(options.initialMessages !== undefined && {
|
|
83
76
|
initialMessages: options.initialMessages,
|
|
84
77
|
}),
|
|
85
|
-
|
|
78
|
+
threadId: options.threadId,
|
|
79
|
+
...(options.persistence === true
|
|
86
80
|
? {
|
|
87
81
|
persistence: true,
|
|
88
|
-
threadId: options.threadId,
|
|
89
82
|
...(options.history !== undefined && {
|
|
90
83
|
history: options.history,
|
|
91
84
|
}),
|
|
92
85
|
}
|
|
93
|
-
:
|
|
94
|
-
? {
|
|
95
|
-
persistence: options.persistence,
|
|
96
|
-
threadId: options.threadId,
|
|
97
|
-
}
|
|
98
|
-
: {
|
|
99
|
-
...(options.threadId !== undefined && {
|
|
100
|
-
threadId: options.threadId,
|
|
101
|
-
}),
|
|
102
|
-
}),
|
|
86
|
+
: { persistence: options.persistence }),
|
|
103
87
|
...(options.initialResumeSnapshot !== undefined && {
|
|
104
88
|
initialResumeSnapshot: options.initialResumeSnapshot,
|
|
105
89
|
}),
|
|
106
|
-
...(bodySource !== undefined && { body: bodySource() }),
|
|
107
90
|
...(forwardedPropsSource !== undefined && {
|
|
108
91
|
forwardedProps: forwardedPropsSource(),
|
|
109
92
|
}),
|
|
@@ -150,15 +133,13 @@ export function injectChat<
|
|
|
150
133
|
// matching `detach`.
|
|
151
134
|
client.attach()
|
|
152
135
|
|
|
153
|
-
// Sync reactive
|
|
154
|
-
if (
|
|
136
|
+
// Sync reactive forwardedProps / context to the client.
|
|
137
|
+
if (forwardedPropsSource || contextSource) {
|
|
155
138
|
effect(
|
|
156
139
|
() => {
|
|
157
|
-
const newBody = bodySource?.()
|
|
158
140
|
const newForwardedProps = forwardedPropsSource?.()
|
|
159
141
|
const newContext = contextSource?.()
|
|
160
142
|
client.updateOptions({
|
|
161
|
-
...(newBody !== undefined && { body: newBody }),
|
|
162
143
|
...(newForwardedProps !== undefined && {
|
|
163
144
|
forwardedProps: newForwardedProps,
|
|
164
145
|
}),
|
|
@@ -275,14 +256,7 @@ export function injectChat<
|
|
|
275
256
|
}) => {
|
|
276
257
|
await client.addToolResult(result)
|
|
277
258
|
}
|
|
278
|
-
const addToolApprovalResponse = async (response: {
|
|
279
|
-
id: string
|
|
280
|
-
approved: boolean
|
|
281
|
-
}) => {
|
|
282
|
-
await client.addToolApprovalResponse(response)
|
|
283
|
-
}
|
|
284
259
|
const interrupts = computed(() => interruptState().interrupts)
|
|
285
|
-
const pendingInterrupts = computed(() => interruptState().interrupts)
|
|
286
260
|
const interruptErrors = computed(() => interruptState().interruptErrors)
|
|
287
261
|
const resuming = computed(() => interruptState().resuming)
|
|
288
262
|
const resolveInterrupts = (
|
|
@@ -326,10 +300,8 @@ export function injectChat<
|
|
|
326
300
|
setMessages,
|
|
327
301
|
clear,
|
|
328
302
|
addToolResult,
|
|
329
|
-
addToolApprovalResponse,
|
|
330
303
|
runId: computed(() => snapshot().runId),
|
|
331
304
|
interrupts,
|
|
332
|
-
pendingInterrupts,
|
|
333
305
|
interruptErrors,
|
|
334
306
|
resuming,
|
|
335
307
|
resolveInterrupts,
|
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
ConnectConnectionAdapter,
|
|
8
8
|
GenerationClientState,
|
|
9
9
|
GenerationFetcher,
|
|
10
|
-
GenerationPersistenceOptions,
|
|
11
10
|
InferGenerationOutputFromReturn,
|
|
12
11
|
} from '@tanstack/ai-client'
|
|
13
12
|
import type { Signal } from '@angular/core'
|
|
@@ -99,6 +98,7 @@ export interface InjectGenerateAudioResult<
|
|
|
99
98
|
* })
|
|
100
99
|
* export class AudioComponent {
|
|
101
100
|
* private gen = injectGenerateAudio({
|
|
101
|
+
* threadId: 'theme-audio',
|
|
102
102
|
* connection: fetchServerSentEvents('/api/generate/audio'),
|
|
103
103
|
* })
|
|
104
104
|
*
|
|
@@ -109,12 +109,9 @@ export interface InjectGenerateAudioResult<
|
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
111
|
export function injectGenerateAudio<TTransformed = void>(
|
|
112
|
-
options: Omit<
|
|
113
|
-
InjectGenerateAudioOptions,
|
|
114
|
-
'onResult' | 'persistence' | 'threadId'
|
|
115
|
-
> & {
|
|
112
|
+
options: Omit<InjectGenerateAudioOptions, 'onResult'> & {
|
|
116
113
|
onResult?: (result: AudioGenerationResult) => TTransformed
|
|
117
|
-
}
|
|
114
|
+
},
|
|
118
115
|
): InjectGenerateAudioResult<
|
|
119
116
|
InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>
|
|
120
117
|
> {
|
|
@@ -4,7 +4,6 @@ import type { Signal } from '@angular/core'
|
|
|
4
4
|
import type { ImageGenerationResult } from '@tanstack/ai'
|
|
5
5
|
import type {
|
|
6
6
|
GenerationClientState,
|
|
7
|
-
GenerationPersistenceOptions,
|
|
8
7
|
ImageGenerateInput,
|
|
9
8
|
InferGenerationOutputFromReturn,
|
|
10
9
|
} from '@tanstack/ai-client'
|
|
@@ -31,12 +30,9 @@ export interface InjectGenerateImageResult<
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export function injectGenerateImage<TTransformed = void>(
|
|
34
|
-
options: Omit<
|
|
35
|
-
InjectGenerateImageOptions,
|
|
36
|
-
'onResult' | 'persistence' | 'threadId'
|
|
37
|
-
> & {
|
|
33
|
+
options: Omit<InjectGenerateImageOptions, 'onResult'> & {
|
|
38
34
|
onResult?: (result: ImageGenerationResult) => TTransformed
|
|
39
|
-
}
|
|
35
|
+
},
|
|
40
36
|
): InjectGenerateImageResult<
|
|
41
37
|
InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>
|
|
42
38
|
> {
|
|
@@ -4,7 +4,6 @@ import type { Signal } from '@angular/core'
|
|
|
4
4
|
import type { TTSResult } from '@tanstack/ai'
|
|
5
5
|
import type {
|
|
6
6
|
GenerationClientState,
|
|
7
|
-
GenerationPersistenceOptions,
|
|
8
7
|
InferGenerationOutputFromReturn,
|
|
9
8
|
SpeechGenerateInput,
|
|
10
9
|
} from '@tanstack/ai-client'
|
|
@@ -32,12 +31,9 @@ export interface InjectGenerateSpeechResult<TOutput = TTSResult> extends Omit<
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export function injectGenerateSpeech<TTransformed = void>(
|
|
35
|
-
options: Omit<
|
|
36
|
-
InjectGenerateSpeechOptions,
|
|
37
|
-
'onResult' | 'persistence' | 'threadId'
|
|
38
|
-
> & {
|
|
34
|
+
options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {
|
|
39
35
|
onResult?: (result: TTSResult) => TTransformed
|
|
40
|
-
}
|
|
36
|
+
},
|
|
41
37
|
): InjectGenerateSpeechResult<
|
|
42
38
|
InferGenerationOutputFromReturn<TTSResult, TTransformed>
|
|
43
39
|
> {
|
|
@@ -17,7 +17,6 @@ import type {
|
|
|
17
17
|
ConnectConnectionAdapter,
|
|
18
18
|
GenerationClientState,
|
|
19
19
|
GenerationFetcher,
|
|
20
|
-
GenerationPersistenceOptions,
|
|
21
20
|
InferGenerationOutputFromReturn,
|
|
22
21
|
VideoGenerateInput,
|
|
23
22
|
VideoGenerateResult,
|
|
@@ -54,11 +53,10 @@ export interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {
|
|
|
54
53
|
* `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread
|
|
55
54
|
* id on the wire, which the protocol requires.
|
|
56
55
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* omitted, the client mints a wire id after mount.
|
|
56
|
+
* Required. A generated id would change on every reload, so persistence
|
|
57
|
+
* would restore nothing.
|
|
60
58
|
*/
|
|
61
|
-
threadId
|
|
59
|
+
threadId: string
|
|
62
60
|
/**
|
|
63
61
|
* Server-driven hydration handler for `persistence: true` when the
|
|
64
62
|
* connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` /
|
|
@@ -104,12 +102,9 @@ export interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {
|
|
|
104
102
|
// parameter is typed as `VideoGenerateResult` and `result` narrows to the
|
|
105
103
|
// transform's return. See issue #848.
|
|
106
104
|
export function injectGenerateVideo<TTransformed = void>(
|
|
107
|
-
options: Omit<
|
|
108
|
-
InjectGenerateVideoOptions,
|
|
109
|
-
'onResult' | 'persistence' | 'threadId'
|
|
110
|
-
> & {
|
|
105
|
+
options: Omit<InjectGenerateVideoOptions, 'onResult'> & {
|
|
111
106
|
onResult?: (result: VideoGenerateResult) => TTransformed
|
|
112
|
-
}
|
|
107
|
+
},
|
|
113
108
|
): InjectGenerateVideoResult<
|
|
114
109
|
InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>
|
|
115
110
|
> {
|
|
@@ -137,16 +132,8 @@ export function injectGenerateVideo<TTransformed = void>(
|
|
|
137
132
|
|
|
138
133
|
const baseOptions = {
|
|
139
134
|
...(bodySource !== undefined && { body: bodySource() }),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
persistence: options.persistence,
|
|
143
|
-
threadId: options.threadId,
|
|
144
|
-
}
|
|
145
|
-
: {
|
|
146
|
-
...(options.threadId !== undefined && {
|
|
147
|
-
threadId: options.threadId,
|
|
148
|
-
}),
|
|
149
|
-
}),
|
|
135
|
+
persistence: options.persistence,
|
|
136
|
+
threadId: options.threadId,
|
|
150
137
|
...(options.hydrateGeneration !== undefined && {
|
|
151
138
|
hydrateGeneration: options.hydrateGeneration,
|
|
152
139
|
}),
|
package/src/inject-generation.ts
CHANGED
|
@@ -18,7 +18,6 @@ import type {
|
|
|
18
18
|
GenerationClientOptions,
|
|
19
19
|
GenerationClientState,
|
|
20
20
|
GenerationFetcher,
|
|
21
|
-
GenerationPersistenceOptions,
|
|
22
21
|
GenerationRestoredResult,
|
|
23
22
|
InferGenerationOutputFromReturn,
|
|
24
23
|
} from '@tanstack/ai-client'
|
|
@@ -57,11 +56,10 @@ export interface InjectGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
|
57
56
|
* `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread
|
|
58
57
|
* id on the wire, which the protocol requires.
|
|
59
58
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* omitted, the client mints a wire id after mount.
|
|
59
|
+
* Required. A generated id would change on every reload, so persistence
|
|
60
|
+
* would restore nothing.
|
|
63
61
|
*/
|
|
64
|
-
threadId
|
|
62
|
+
threadId: string
|
|
65
63
|
/**
|
|
66
64
|
* Server-driven hydration handler for `persistence: true` when the
|
|
67
65
|
* connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` /
|
|
@@ -143,12 +141,9 @@ export function injectGeneration<
|
|
|
143
141
|
TResult,
|
|
144
142
|
TTransformed = void,
|
|
145
143
|
>(
|
|
146
|
-
options: Omit<
|
|
147
|
-
InjectGenerationOptions<TInput, TResult>,
|
|
148
|
-
'onResult' | 'persistence' | 'threadId'
|
|
149
|
-
> & {
|
|
144
|
+
options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {
|
|
150
145
|
onResult?: (result: TResult) => TTransformed
|
|
151
|
-
}
|
|
146
|
+
},
|
|
152
147
|
): InjectGenerationResult<
|
|
153
148
|
InferGenerationOutputFromReturn<TResult, TTransformed>,
|
|
154
149
|
TInput
|
|
@@ -170,10 +165,9 @@ export function injectGeneration<
|
|
|
170
165
|
const bodySource =
|
|
171
166
|
options.body !== undefined ? toReactive(options.body) : undefined
|
|
172
167
|
|
|
173
|
-
const clientOptions:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
> = {
|
|
168
|
+
const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {
|
|
169
|
+
persistence: options.persistence,
|
|
170
|
+
threadId: options.threadId,
|
|
177
171
|
...(bodySource !== undefined && { body: bodySource() }),
|
|
178
172
|
...(options.hydrateGeneration !== undefined && {
|
|
179
173
|
hydrateGeneration: options.hydrateGeneration,
|
|
@@ -207,29 +201,15 @@ export function injectGeneration<
|
|
|
207
201
|
},
|
|
208
202
|
}
|
|
209
203
|
|
|
210
|
-
const persistenceProps =
|
|
211
|
-
typeof options.threadId === 'string' && options.persistence
|
|
212
|
-
? {
|
|
213
|
-
persistence: options.persistence,
|
|
214
|
-
threadId: options.threadId,
|
|
215
|
-
}
|
|
216
|
-
: {
|
|
217
|
-
...(options.threadId !== undefined && {
|
|
218
|
-
threadId: options.threadId,
|
|
219
|
-
}),
|
|
220
|
-
}
|
|
221
|
-
|
|
222
204
|
let client: GenerationClient<TInput, TResult, TOutput>
|
|
223
205
|
if (options.connection) {
|
|
224
206
|
client = new GenerationClient({
|
|
225
207
|
...clientOptions,
|
|
226
|
-
...persistenceProps,
|
|
227
208
|
connection: options.connection,
|
|
228
209
|
})
|
|
229
210
|
} else if (options.fetcher) {
|
|
230
211
|
client = new GenerationClient({
|
|
231
212
|
...clientOptions,
|
|
232
|
-
...persistenceProps,
|
|
233
213
|
fetcher: options.fetcher,
|
|
234
214
|
})
|
|
235
215
|
} else {
|
package/src/inject-summarize.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Signal } from '@angular/core'
|
|
|
4
4
|
import type { SummarizationResult } from '@tanstack/ai'
|
|
5
5
|
import type {
|
|
6
6
|
GenerationClientState,
|
|
7
|
-
GenerationPersistenceOptions,
|
|
8
7
|
InferGenerationOutputFromReturn,
|
|
9
8
|
SummarizeGenerateInput,
|
|
10
9
|
} from '@tanstack/ai-client'
|
|
@@ -31,12 +30,9 @@ export interface InjectSummarizeResult<
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export function injectSummarize<TTransformed = void>(
|
|
34
|
-
options: Omit<
|
|
35
|
-
InjectSummarizeOptions,
|
|
36
|
-
'onResult' | 'persistence' | 'threadId'
|
|
37
|
-
> & {
|
|
33
|
+
options: Omit<InjectSummarizeOptions, 'onResult'> & {
|
|
38
34
|
onResult?: (result: SummarizationResult) => TTransformed
|
|
39
|
-
}
|
|
35
|
+
},
|
|
40
36
|
): InjectSummarizeResult<
|
|
41
37
|
InferGenerationOutputFromReturn<SummarizationResult, TTransformed>
|
|
42
38
|
> {
|
|
@@ -4,7 +4,6 @@ import type { Signal } from '@angular/core'
|
|
|
4
4
|
import type { TranscriptionResult } from '@tanstack/ai'
|
|
5
5
|
import type {
|
|
6
6
|
GenerationClientState,
|
|
7
|
-
GenerationPersistenceOptions,
|
|
8
7
|
InferGenerationOutputFromReturn,
|
|
9
8
|
TranscriptionGenerateInput,
|
|
10
9
|
} from '@tanstack/ai-client'
|
|
@@ -35,12 +34,9 @@ export interface InjectTranscriptionResult<
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export function injectTranscription<TTransformed = void>(
|
|
38
|
-
options: Omit<
|
|
39
|
-
InjectTranscriptionOptions,
|
|
40
|
-
'onResult' | 'persistence' | 'threadId'
|
|
41
|
-
> & {
|
|
37
|
+
options: Omit<InjectTranscriptionOptions, 'onResult'> & {
|
|
42
38
|
onResult?: (result: TranscriptionResult) => TTransformed
|
|
43
|
-
}
|
|
39
|
+
},
|
|
44
40
|
): InjectTranscriptionResult<
|
|
45
41
|
InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>
|
|
46
42
|
> {
|