@tanstack/ai-angular 0.1.10 → 0.2.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/README.md +158 -0
- package/dist/fesm2022/tanstack-ai-angular.mjs +532 -0
- package/dist/fesm2022/tanstack-ai-angular.mjs.map +1 -0
- package/dist/types/tanstack-ai-angular.d.ts +357 -0
- package/package.json +4 -4
- package/src/index.ts +7 -0
- package/src/inject-audio-recorder.ts +96 -0
- package/src/inject-generate-audio.ts +5 -8
- package/src/inject-generate-image.ts +5 -8
- package/src/inject-generate-speech.ts +7 -7
- package/src/inject-generate-video.ts +17 -9
- package/src/inject-generation.ts +19 -6
- package/src/inject-summarize.ts +10 -11
- package/src/inject-transcription.ts +5 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack-ai-angular.mjs","sources":["../../src/internal/to-reactive.ts","../../src/inject-chat.ts","../../src/inject-generation.ts","../../src/inject-generate-image.ts","../../src/inject-generate-audio.ts","../../src/inject-generate-speech.ts","../../src/inject-transcription.ts","../../src/inject-audio-recorder.ts","../../src/inject-summarize.ts","../../src/inject-generate-video.ts","../../src/index.ts","../../src/tanstack-ai-angular.ts"],"sourcesContent":["import { computed, isSignal } from '@angular/core'\nimport type { Signal } from '@angular/core'\n\n/**\n * A value that may be supplied to `injectChat` either as a static value, an\n * Angular `Signal`, or a zero-arg getter. The getter form lets callers read\n * other signals so the option stays reactive.\n */\nexport type ReactiveOption<T> = T | Signal<T> | (() => T)\n\n/**\n * Normalize a {@link ReactiveOption} into a `Signal`-like getter `() => T`.\n *\n * - A `Signal` is returned as-is (already a getter that tracks reads).\n * - A zero-arg function is wrapped in `computed` so reads inside it are tracked.\n * - A plain value becomes a constant non-reactive fn (never re-fires).\n */\nexport function toReactive<T>(value: ReactiveOption<T>): () => T {\n if (isSignal(value)) {\n return value\n }\n if (typeof value === 'function') {\n return computed(value as () => T)\n }\n return () => value\n}\n","import { ChatClient } from '@tanstack/ai-client'\nimport { createChatDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n DestroyRef,\n Injector,\n afterNextRender,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport { toReactive } from './internal/to-reactive'\nimport type {\n AnyClientTool,\n InferSchemaType,\n ModelMessage,\n SchemaInput,\n StreamChunk,\n} from '@tanstack/ai'\nimport type {\n ChatClientState,\n ConnectionStatus,\n InferredClientContext,\n StructuredOutputPart,\n} from '@tanstack/ai-client'\nimport type {\n DeepPartial,\n InjectChatOptions,\n InjectChatResult,\n MultimodalContent,\n UIMessage,\n} from './types'\n\nlet nextId = 0\n\nexport function injectChat<\n TTools extends ReadonlyArray<AnyClientTool> = any,\n TSchema extends SchemaInput | undefined = undefined,\n TContext = InferredClientContext<TTools>,\n>(\n options: InjectChatOptions<\n TTools,\n TSchema,\n TContext\n > = {} as InjectChatOptions<TTools, TSchema, TContext>,\n): InjectChatResult<TTools, TSchema> {\n assertInInjectionContext(injectChat)\n\n type Partial = DeepPartial<InferSchemaType<NonNullable<TSchema>>>\n type Final = InferSchemaType<NonNullable<TSchema>>\n\n const destroyRef = inject(DestroyRef)\n const injector = inject(Injector)\n const clientId = options.id || `injectChat-${nextId++}`\n\n const messages = signal<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const isLoading = signal(false)\n const error = signal<Error | undefined>(undefined)\n const status = signal<ChatClientState>('ready')\n const isSubscribed = signal(false)\n const connectionStatus = signal<ConnectionStatus>('disconnected')\n const sessionGenerating = signal(false)\n\n // Reactive option sources. Plain values become constant computeds.\n const bodySource =\n options.body !== undefined ? toReactive(options.body) : undefined\n const forwardedPropsSource =\n options.forwardedProps !== undefined\n ? toReactive(options.forwardedProps)\n : undefined\n const contextSource =\n options.context !== undefined ? toReactive(options.context) : undefined\n const liveSource =\n options.live !== undefined ? toReactive(options.live) : undefined\n\n const transport = options.connection\n ? { connection: options.connection }\n : { fetcher: options.fetcher }\n\n const client = new ChatClient<TTools, TContext>({\n devtoolsBridgeFactory: createChatDevtoolsBridge,\n ...transport,\n id: clientId,\n ...(options.initialMessages !== undefined && {\n initialMessages: options.initialMessages,\n }),\n ...(options.persistence !== undefined && {\n persistence: options.persistence,\n }),\n ...(bodySource !== undefined && { body: bodySource() }),\n ...(options.threadId !== undefined && { threadId: options.threadId }),\n ...(forwardedPropsSource !== undefined && {\n forwardedProps: forwardedPropsSource(),\n }),\n ...(contextSource !== undefined && { context: contextSource() }),\n devtools: {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectChat',\n outputKind: options.outputSchema ? 'structured' : 'chat',\n },\n onResponse: (response) => options.onResponse?.(response),\n onChunk: (chunk: StreamChunk) => options.onChunk?.(chunk),\n onFinish: (message) => options.onFinish?.(message),\n onError: (err) => options.onError?.(err),\n tools: options.tools,\n onCustomEvent: (eventType, data, context) =>\n options.onCustomEvent?.(eventType, data, context),\n ...(options.streamProcessor !== undefined && {\n streamProcessor: options.streamProcessor,\n }),\n onMessagesChange: (m: Array<UIMessage<TTools>>) => messages.set(m),\n onLoadingChange: (v: boolean) => isLoading.set(v),\n onStatusChange: (v: ChatClientState) => status.set(v),\n onErrorChange: (v: Error | undefined) => error.set(v),\n onSubscriptionChange: (v: boolean) => isSubscribed.set(v),\n onConnectionStatusChange: (v: ConnectionStatus) => connectionStatus.set(v),\n onSessionGeneratingChange: (v: boolean) => sessionGenerating.set(v),\n })\n\n messages.set(client.getMessages())\n\n // Sync reactive body / forwardedProps / context to the client.\n if (bodySource || forwardedPropsSource || contextSource) {\n effect(\n () => {\n const newBody = bodySource?.()\n const newForwardedProps = forwardedPropsSource?.()\n const newContext = contextSource?.()\n client.updateOptions({\n ...(newBody !== undefined && { body: newBody }),\n ...(newForwardedProps !== undefined && {\n forwardedProps: newForwardedProps,\n }),\n ...(newContext !== undefined && { context: newContext }),\n })\n },\n { injector },\n )\n }\n\n // Subscribe / unsubscribe based on reactive `live`.\n if (liveSource) {\n effect(\n () => {\n if (liveSource()) {\n client.subscribe()\n } else {\n client.unsubscribe()\n }\n },\n { injector },\n )\n }\n\n afterNextRender(() => client.mountDevtools(), { injector })\n\n destroyRef.onDestroy(() => {\n if (liveSource?.()) {\n client.unsubscribe()\n } else {\n client.stop()\n }\n client.dispose()\n })\n\n // Active structured-output part = the one on the assistant message after the\n // latest user message. Ported from ai-vue/src/use-chat.ts.\n const activeStructuredPart = computed<StructuredOutputPart | null>(() => {\n const list = messages()\n let lastUserIndex = -1\n for (let i = list.length - 1; i >= 0; i--) {\n if (list[i]?.role === 'user') {\n lastUserIndex = i\n break\n }\n }\n if (lastUserIndex === -1) return null\n for (let i = list.length - 1; i > lastUserIndex; i--) {\n const m = list[i]\n if (m?.role !== 'assistant') continue\n const part = m.parts.find(\n (p): p is StructuredOutputPart => p.type === 'structured-output',\n )\n if (part) return part\n }\n return null\n })\n\n const partial = computed<Partial>(() => {\n const part = activeStructuredPart()\n if (!part) return {} as Partial\n const v = part.partial ?? part.data\n return (v ?? {}) as Partial\n })\n\n const final = computed<Final | null>(() => {\n const part = activeStructuredPart()\n if (!part || part.status !== 'complete') return null\n return part.data as Final\n })\n\n const sendMessage = async (content: string | MultimodalContent) => {\n await client.sendMessage(content)\n }\n const append = async (message: ModelMessage | UIMessage<TTools>) => {\n await client.append(message)\n }\n const reload = async () => {\n await client.reload()\n }\n const stop = () => client.stop()\n const clear = () => client.clear()\n const setMessages = (m: Array<UIMessage<TTools>>) =>\n client.setMessagesManually(m)\n const addToolResult = async (result: {\n toolCallId: string\n tool: string\n output: any\n state?: 'output-available' | 'output-error'\n errorText?: string\n }) => {\n await client.addToolResult(result)\n }\n const addToolApprovalResponse = async (response: {\n id: string\n approved: boolean\n }) => {\n await client.addToolApprovalResponse(response)\n }\n\n // eslint-disable-next-line no-restricted-syntax -- return shape diverges from conditional InjectChatResult<TTools, TSchema>; TS can't structurally narrow the TSchema-gated partial/final signals\n return {\n messages: messages.asReadonly(),\n sendMessage,\n append,\n reload,\n stop,\n isLoading: isLoading.asReadonly(),\n error: error.asReadonly(),\n status: status.asReadonly(),\n isSubscribed: isSubscribed.asReadonly(),\n connectionStatus: connectionStatus.asReadonly(),\n sessionGenerating: sessionGenerating.asReadonly(),\n setMessages,\n clear,\n addToolResult,\n addToolApprovalResponse,\n partial,\n final,\n } as unknown as InjectChatResult<TTools, TSchema>\n}\n","import { GenerationClient } from '@tanstack/ai-client'\nimport { createGenerationDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n DestroyRef,\n Injector,\n afterNextRender,\n assertInInjectionContext,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport { toReactive } from './internal/to-reactive'\nimport type { Signal } from '@angular/core'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientOptions,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutputFromReturn,\n} from '@tanstack/ai-client'\nimport type { ReactiveOption } from './internal/to-reactive'\n\nlet nextId = 0\n\nexport interface InjectGenerationOptions<TInput, TResult, TOutput = TResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for one-shot generation (no streaming protocol needed) */\n fetcher?: GenerationFetcher<TInput, TResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional request body params. Reactive. */\n body?: ReactiveOption<Record<string, any>>\n /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\n /**\n * Callback when a result is received. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: TResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\nexport interface InjectGenerationResult<TOutput> {\n /** Trigger a generation request */\n generate: (input: Record<string, any>) => Promise<void>\n /** The generation result, or null if not yet generated */\n result: Signal<TOutput | null>\n /** Whether a generation is currently in progress */\n isLoading: Signal<boolean>\n /** Current error, if any */\n error: Signal<Error | undefined>\n /** Current state of the generation client */\n status: Signal<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n// `TTransformed` infers from the `onResult` return position (a covariant\n// inference site that works even for an optional nested property), which types\n// the callback parameter as `TResult` and narrows `result`. Inferring the\n// whole callback as a defaulted type parameter instead collapses to the\n// default, leaving the parameter `any` — a hard error under `strict`. See\n// issue #848.\nexport function injectGeneration<\n TInput extends Record<string, any>,\n TResult,\n TTransformed = void,\n>(\n options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {\n onResult?: (result: TResult) => TTransformed\n },\n): InjectGenerationResult<\n InferGenerationOutputFromReturn<TResult, TTransformed>\n> {\n assertInInjectionContext(injectGeneration)\n\n type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>\n\n const destroyRef = inject(DestroyRef)\n const injector = inject(Injector)\n const clientId = options.id || `injectGeneration-${nextId++}`\n\n const result = signal<TOutput | null>(null)\n const isLoading = signal(false)\n const error = signal<Error | undefined>(undefined)\n const status = signal<GenerationClientState>('idle')\n\n const bodySource =\n options.body !== undefined ? toReactive(options.body) : undefined\n\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n ...(bodySource !== undefined && { body: bodySource() }),\n devtoolsBridgeFactory: createGenerationDevtoolsBridge,\n devtools: {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectGeneration',\n },\n // The transform's raw return type (`TTransformed`) and the stored output\n // (`TOutput`, with null/void/undefined stripped) are identical at runtime;\n // the cast bridges the relationship that the conditional type hides.\n onResult: ((r: TResult) => options.onResult?.(r)) as (\n result: TResult,\n ) => TOutput | null | void,\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onResultChange: (r: TOutput | null) => result.set(r),\n onLoadingChange: (l: boolean) => isLoading.set(l),\n onErrorChange: (e: Error | undefined) => error.set(e),\n onStatusChange: (s: GenerationClientState) => status.set(s),\n }\n\n let client: GenerationClient<TInput, TResult, TOutput>\n if (options.connection) {\n client = new GenerationClient({\n ...clientOptions,\n connection: options.connection,\n })\n } else if (options.fetcher) {\n client = new GenerationClient({\n ...clientOptions,\n fetcher: options.fetcher,\n })\n } else {\n throw new Error(\n 'injectGeneration requires either a connection or fetcher option',\n )\n }\n\n if (bodySource) {\n effect(\n () => {\n client.updateOptions({ body: bodySource() })\n },\n { injector },\n )\n }\n\n afterNextRender(() => client.mountDevtools(), { injector })\n destroyRef.onDestroy(() => client.dispose())\n\n return {\n generate: ((input: TInput) => client.generate(input)) as (\n input: Record<string, any>,\n ) => Promise<void>,\n result: result.asReadonly(),\n isLoading: isLoading.asReadonly(),\n error: error.asReadonly(),\n status: status.asReadonly(),\n stop: () => client.stop(),\n reset: () => client.reset(),\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { ImageGenerationResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n ImageGenerateInput,\n InferGenerationOutputFromReturn,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectGenerateImageOptions<TOutput = ImageGenerationResult> = Omit<\n InjectGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>,\n 'onResult'\n> & {\n onResult?: (result: ImageGenerationResult) => TOutput | null | void\n}\n\nexport interface InjectGenerateImageResult<TOutput = ImageGenerationResult> {\n generate: (input: ImageGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectGenerateImage<TTransformed = void>(\n options: Omit<InjectGenerateImageOptions, 'onResult'> & {\n onResult?: (result: ImageGenerationResult) => TTransformed\n },\n): InjectGenerateImageResult<\n InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectGenerateImage',\n outputKind: 'image' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<ImageGenerateInput, ImageGenerationResult, TTransformed>({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: ImageGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { AudioGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\n AudioGenerateInput,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutputFromReturn,\n} from '@tanstack/ai-client'\nimport type { Signal } from '@angular/core'\nimport type { ReactiveOption } from './internal/to-reactive'\n\n/**\n * Options for the injectGenerateAudio injectable.\n *\n * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)\n */\nexport interface InjectGenerateAudioOptions<TOutput = AudioGenerationResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for audio generation */\n fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with connect-based adapter requests. Reactive. */\n body?: ReactiveOption<Record<string, any>>\n /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\n /**\n * Callback when audio is generated. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: AudioGenerationResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the injectGenerateAudio injectable.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> {\n /** Trigger audio generation */\n generate: (input: AudioGenerateInput) => Promise<void>\n /** The generation result containing audio, or null */\n result: Signal<TOutput | null>\n /** Whether generation is in progress */\n isLoading: Signal<boolean>\n /** Current error, if any */\n error: Signal<Error | undefined>\n /** Current state of the generation */\n status: Signal<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Angular injectable for generating audio (music, sound effects) using AI models.\n *\n * @example\n * ```typescript\n * import { Component } from '@angular/core'\n * import { injectGenerateAudio } from '@tanstack/ai-angular'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * @Component({\n * selector: 'app-audio',\n * template: `\n * <button (click)=\"generate({ prompt: 'An upbeat electronic track', duration: 10 })\">\n * Generate\n * </button>\n * @if (result()) {\n * <audio [src]=\"result()!.audio.url\" controls></audio>\n * }\n * `,\n * })\n * export class AudioComponent {\n * private gen = injectGenerateAudio({\n * connection: fetchServerSentEvents('/api/generate/audio'),\n * })\n *\n * generate = this.gen.generate\n * result = this.gen.result\n * isLoading = this.gen.isLoading\n * }\n * ```\n */\nexport function injectGenerateAudio<TTransformed = void>(\n options: Omit<InjectGenerateAudioOptions, 'onResult'> & {\n onResult?: (result: AudioGenerationResult) => TTransformed\n },\n): InjectGenerateAudioResult<\n InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectGenerateAudio',\n outputKind: 'audio' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<AudioGenerateInput, AudioGenerationResult, TTransformed>({\n ...options,\n devtools,\n })\n\n return {\n generate: generate as (input: AudioGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { TTSResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n InferGenerationOutputFromReturn,\n SpeechGenerateInput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectGenerateSpeechOptions<TOutput = TTSResult> = Omit<\n InjectGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>,\n 'onResult'\n> & {\n onResult?: (result: TTSResult) => TOutput | null | void\n}\n\nexport interface InjectGenerateSpeechResult<TOutput = TTSResult> {\n generate: (input: SpeechGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectGenerateSpeech<TTransformed = void>(\n options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {\n onResult?: (result: TTSResult) => TTransformed\n },\n): InjectGenerateSpeechResult<\n InferGenerationOutputFromReturn<TTSResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectGenerateSpeech',\n outputKind: 'audio' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<SpeechGenerateInput, TTSResult, TTransformed>({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: SpeechGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { TranscriptionResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n InferGenerationOutputFromReturn,\n TranscriptionGenerateInput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectTranscriptionOptions<TOutput = TranscriptionResult> = Omit<\n InjectGenerationOptions<\n TranscriptionGenerateInput,\n TranscriptionResult,\n TOutput\n >,\n 'onResult'\n> & {\n onResult?: (result: TranscriptionResult) => TOutput | null | void\n}\n\nexport interface InjectTranscriptionResult<TOutput = TranscriptionResult> {\n generate: (input: TranscriptionGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectTranscription<TTransformed = void>(\n options: Omit<InjectTranscriptionOptions, 'onResult'> & {\n onResult?: (result: TranscriptionResult) => TTransformed\n },\n): InjectTranscriptionResult<\n InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectTranscription',\n outputKind: 'text' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<\n TranscriptionGenerateInput,\n TranscriptionResult,\n TTransformed\n >({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: TranscriptionGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import {\n DestroyRef,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport { AudioRecorder } from '@tanstack/ai-client'\nimport type { Signal } from '@angular/core'\nimport type {\n AudioRecorderOptions,\n AudioRecording,\n InferAudioRecordingOutput,\n} from '@tanstack/ai-client'\n\nexport type InjectAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {\n /**\n * Optional transform applied to the recording when `stop()` resolves. Its\n * (awaited) return value becomes `recording` and the resolved value of\n * `stop()`. Return nothing to keep the raw `AudioRecording`.\n */\n onComplete?: TOnComplete\n}\n\nexport interface InjectAudioRecorderResult<TOutput> {\n /** Reactive: latest recording (transformed if `onComplete` provided), or null. */\n recording: Signal<TOutput | null>\n /** Reactive: true while actively capturing audio. */\n isRecording: Signal<boolean>\n /** Whether the browser supports recording. */\n isSupported: boolean\n start: () => Promise<void>\n /** Stop and resolve with the completed recording (transformed if `onComplete` provided). */\n stop: () => Promise<TOutput>\n /** Discard the in-progress recording and release the mic. */\n cancel: () => void\n}\n\n/**\n * Angular injectable for recording an audio message. The resolved recording\n * carries `.part` (for `injectChat`'s `sendMessage`) and `.base64` (for the\n * generation injectables). Must be called in an injection context.\n *\n * Errors are delivered via `onError`. `start()` and `stop()` also reject on\n * failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs\n * while a stop is in flight, e.g. on destroy) — handle one channel, not both.\n */\nexport function injectAudioRecorder<\n TOnComplete extends (recording: AudioRecording) => unknown,\n>(\n options: InjectAudioRecorderOptions<TOnComplete>,\n): InjectAudioRecorderResult<InferAudioRecordingOutput<TOnComplete>>\nexport function injectAudioRecorder(\n options?: InjectAudioRecorderOptions<undefined>,\n): InjectAudioRecorderResult<AudioRecording>\nexport function injectAudioRecorder(\n options: InjectAudioRecorderOptions<\n (recording: AudioRecording) => unknown\n > = {},\n): InjectAudioRecorderResult<unknown> {\n assertInInjectionContext(injectAudioRecorder)\n const destroyRef = inject(DestroyRef)\n const recorder = new AudioRecorder({\n ...(options.audio !== undefined && { audio: options.audio }),\n ...(options.mimeType !== undefined && { mimeType: options.mimeType }),\n ...(options.onError !== undefined && { onError: options.onError }),\n })\n const isRecording = signal(false)\n const recording = signal<unknown>(null)\n\n const unsubscribe = recorder.subscribe((state) => {\n isRecording.set(state === 'recording')\n })\n destroyRef.onDestroy(() => {\n unsubscribe()\n recorder.cancel()\n })\n\n const stop = async (): Promise<unknown> => {\n const rawRecording = await recorder.stop()\n const transformed = await options.onComplete?.(rawRecording)\n // Only `undefined` (returning nothing) keeps the raw recording; a returned\n // null is a real value, matching the inferred output type.\n const output = transformed === undefined ? rawRecording : transformed\n recording.set(output)\n return output\n }\n\n return {\n recording: recording.asReadonly(),\n isRecording: isRecording.asReadonly(),\n isSupported: AudioRecorder.isSupported(),\n start: () => recorder.start(),\n stop,\n cancel: () => recorder.cancel(),\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { SummarizationResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n InferGenerationOutputFromReturn,\n SummarizeGenerateInput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectSummarizeOptions<TOutput = SummarizationResult> = Omit<\n InjectGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>,\n 'onResult'\n> & {\n onResult?: (result: SummarizationResult) => TOutput | null | void\n}\n\nexport interface InjectSummarizeResult<TOutput = SummarizationResult> {\n generate: (input: SummarizeGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectSummarize<TTransformed = void>(\n options: Omit<InjectSummarizeOptions, 'onResult'> & {\n onResult?: (result: SummarizationResult) => TTransformed\n },\n): InjectSummarizeResult<\n InferGenerationOutputFromReturn<SummarizationResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectSummarize',\n outputKind: 'text' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<SummarizeGenerateInput, SummarizationResult, TTransformed>(\n {\n ...options,\n devtools,\n },\n )\n return {\n generate: generate as (input: SummarizeGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { VideoGenerationClient } from '@tanstack/ai-client'\nimport { createVideoDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n DestroyRef,\n Injector,\n afterNextRender,\n assertInInjectionContext,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport { toReactive } from './internal/to-reactive'\nimport type { Signal } from '@angular/core'\nimport type { ReactiveOption } from './internal/to-reactive'\nimport type {\n AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutputFromReturn,\n VideoGenerateInput,\n VideoGenerateResult,\n VideoStatusInfo,\n} from '@tanstack/ai-client'\nimport type { StreamChunk } from '@tanstack/ai'\n\nlet nextId = 0\n\nexport interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {\n connection?: ConnectConnectionAdapter\n fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>\n id?: string\n body?: ReactiveOption<Record<string, any>>\n devtools?: AIDevtoolsDisplayOptions\n onResult?: (result: VideoGenerateResult) => TOutput | null | void\n onError?: (error: Error) => void\n onProgress?: (progress: number, message?: string) => void\n onJobCreated?: (jobId: string) => void\n onStatusUpdate?: (status: VideoStatusInfo) => void\n onChunk?: (chunk: StreamChunk) => void\n}\n\nexport interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {\n generate: (input: VideoGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n jobId: Signal<string | null>\n videoStatus: Signal<VideoStatusInfo | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\n// `TTransformed` infers from the `onResult` return position so the callback\n// parameter is typed as `VideoGenerateResult` and `result` narrows to the\n// transform's return. See issue #848.\nexport function injectGenerateVideo<TTransformed = void>(\n options: Omit<InjectGenerateVideoOptions, 'onResult'> & {\n onResult?: (result: VideoGenerateResult) => TTransformed\n },\n): InjectGenerateVideoResult<\n InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>\n> {\n assertInInjectionContext(injectGenerateVideo)\n\n type TOutput = InferGenerationOutputFromReturn<\n VideoGenerateResult,\n TTransformed\n >\n\n const destroyRef = inject(DestroyRef)\n const injector = inject(Injector)\n const clientId = options.id || `injectGenerateVideo-${nextId++}`\n\n const result = signal<TOutput | null>(null)\n const jobId = signal<string | null>(null)\n const videoStatus = signal<VideoStatusInfo | null>(null)\n const isLoading = signal(false)\n const error = signal<Error | undefined>(undefined)\n const status = signal<GenerationClientState>('idle')\n\n const bodySource =\n options.body !== undefined ? toReactive(options.body) : undefined\n\n const baseOptions = {\n id: clientId,\n ...(bodySource !== undefined && { body: bodySource() }),\n devtoolsBridgeFactory: createVideoDevtoolsBridge,\n devtools: {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectGenerateVideo',\n outputKind: 'video' as const,\n },\n // The transform's raw return type (`TTransformed`) and the stored output\n // (`TOutput`, with null/void/undefined stripped) are identical at runtime;\n // the cast bridges the relationship that the conditional type hides.\n onResult: ((r: VideoGenerateResult) => options.onResult?.(r)) as (\n result: VideoGenerateResult,\n ) => TOutput | null | void,\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onJobCreated: (id: string) => options.onJobCreated?.(id),\n onStatusUpdate: (s: VideoStatusInfo) => options.onStatusUpdate?.(s),\n onResultChange: (r: TOutput | null) => result.set(r),\n onLoadingChange: (l: boolean) => isLoading.set(l),\n onErrorChange: (e: Error | undefined) => error.set(e),\n onStatusChange: (s: GenerationClientState) => status.set(s),\n onJobIdChange: (id: string | null) => jobId.set(id),\n onVideoStatusChange: (s: VideoStatusInfo | null) => videoStatus.set(s),\n }\n\n let client: VideoGenerationClient<TOutput>\n if (options.connection) {\n client = new VideoGenerationClient({\n ...baseOptions,\n connection: options.connection,\n })\n } else if (options.fetcher) {\n client = new VideoGenerationClient({\n ...baseOptions,\n fetcher: options.fetcher,\n })\n } else {\n throw new Error(\n 'injectGenerateVideo requires either a connection or fetcher option',\n )\n }\n\n if (bodySource) {\n effect(\n () => {\n client.updateOptions({ body: bodySource() })\n },\n { injector },\n )\n }\n\n afterNextRender(() => client.mountDevtools(), { injector })\n destroyRef.onDestroy(() => client.dispose())\n\n return {\n generate: (input: VideoGenerateInput) => client.generate(input),\n result: result.asReadonly(),\n jobId: jobId.asReadonly(),\n videoStatus: videoStatus.asReadonly(),\n isLoading: isLoading.asReadonly(),\n error: error.asReadonly(),\n status: status.asReadonly(),\n stop: () => client.stop(),\n reset: () => client.reset(),\n }\n}\n","// Chat\nexport { injectChat } from './inject-chat'\n\n// Generation\nexport { injectGeneration } from './inject-generation'\nexport type {\n InjectGenerationOptions,\n InjectGenerationResult,\n} from './inject-generation'\n\n// Generate Image\nexport { injectGenerateImage } from './inject-generate-image'\nexport type {\n InjectGenerateImageOptions,\n InjectGenerateImageResult,\n} from './inject-generate-image'\n\n// Generate Audio\nexport { injectGenerateAudio } from './inject-generate-audio'\nexport type {\n InjectGenerateAudioOptions,\n InjectGenerateAudioResult,\n} from './inject-generate-audio'\n\n// Generate Speech\nexport { injectGenerateSpeech } from './inject-generate-speech'\nexport type {\n InjectGenerateSpeechOptions,\n InjectGenerateSpeechResult,\n} from './inject-generate-speech'\n\n// Transcription\nexport { injectTranscription } from './inject-transcription'\nexport type {\n InjectTranscriptionOptions,\n InjectTranscriptionResult,\n} from './inject-transcription'\n\n// Audio Recorder\nexport { injectAudioRecorder } from './inject-audio-recorder'\nexport type {\n InjectAudioRecorderOptions,\n InjectAudioRecorderResult,\n} from './inject-audio-recorder'\n\n// Summarize\nexport { injectSummarize } from './inject-summarize'\nexport type {\n InjectSummarizeOptions,\n InjectSummarizeResult,\n} from './inject-summarize'\n\n// Generate Video\nexport { injectGenerateVideo } from './inject-generate-video'\nexport type {\n InjectGenerateVideoOptions,\n InjectGenerateVideoResult,\n} from './inject-generate-video'\n\n// Types from ./types\nexport type {\n DeepPartial,\n InjectChatOptions,\n InjectChatResult,\n UIMessage,\n ChatRequestBody,\n MultimodalContent,\n ReactiveOption,\n} from './types'\n\n// Re-export from @tanstack/ai-client for convenience\nexport {\n fetchServerSentEvents,\n fetchHttpStream,\n xhrServerSentEvents,\n xhrHttpStream,\n stream,\n rpcStream,\n createChatClientOptions,\n type ConnectionAdapter,\n type ConnectConnectionAdapter,\n type SubscribeConnectionAdapter,\n type RunAgentInputContext,\n type FetchConnectionOptions,\n type XhrConnectionOptions,\n type InferChatMessages,\n type GenerationClientState,\n type ImageGenerateInput,\n type AudioGenerateInput,\n type SpeechGenerateInput,\n type TranscriptionGenerateInput,\n type SummarizeGenerateInput,\n type VideoGenerateInput,\n type VideoGenerateResult,\n type VideoStatusInfo,\n} from '@tanstack/ai-client'\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["nextId"],"mappings":";;;;;AAUA;;;;;;AAMG;AACG,SAAU,UAAU,CAAI,KAAwB,EAAA;AACpD,IAAA,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;AACnB,QAAA,OAAO,KAAK;IACd;AACA,IAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,QAAA,OAAO,QAAQ,CAAC,KAAgB,CAAC;IACnC;AACA,IAAA,OAAO,MAAM,KAAK;AACpB;;ACSA,IAAIA,QAAM,GAAG,CAAC;AAER,SAAU,UAAU,CAKxB,OAAA,GAII,EAAkD,EAAA;IAEtD,wBAAwB,CAAC,UAAU,CAAC;AAKpC,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;AACrC,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,IAAI,CAAA,WAAA,EAAcA,QAAM,EAAE,CAAA,CAAE;IAEvD,MAAM,QAAQ,GAAG,MAAM,CACrB,OAAO,CAAC,eAAe,IAAI,EAAE,EAAA,IAAA,SAAA,GAAA,CAAA,EAAA,SAAA,EAAA,UAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAC9B;AACD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,gFAAC;AAC/B,IAAA,MAAM,KAAK,GAAG,MAAM,CAAoB,SAAS,4EAAC;AAClD,IAAA,MAAM,MAAM,GAAG,MAAM,CAAkB,OAAO,6EAAC;AAC/C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,mFAAC;AAClC,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAmB,cAAc,uFAAC;AACjE,IAAA,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,wFAAC;;IAGvC,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D,UAAU,CAAC,SAAS,CAAC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAE5C,OAAO;QACL,QAAQ,EAAE,CAAC,KAAyB,KAAK,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC/D,QAAA,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE;AAC3B,QAAA,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE;AACzB,QAAA,WAAW,EAAE,WAAW,CAAC,UAAU,EAAE;AACrC,QAAA,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE;AACjC,QAAA,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE;AACzB,QAAA,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE;AAC3B,QAAA,IAAI,EAAE,MAAM,MAAM,CAAC,IAAI,EAAE;AACzB,QAAA,KAAK,EAAE,MAAM,MAAM,CAAC,KAAK,EAAE;KAC5B;AACH;;AC1JA;;ACAA;;AAEG;;;;"}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { AnyClientTool, SchemaInput, ModelMessage, InferSchemaType, StreamChunk, ImageGenerationResult, AudioGenerationResult, TTSResult, TranscriptionResult, SummarizationResult } from '@tanstack/ai';
|
|
2
|
+
import { InferredClientContext, DistributedOmit, ChatClientOptions, AIDevtoolsDisplayOptions, ClientContextOptionFromTools, UIMessage, MultimodalContent, ChatClientState, ConnectionStatus, ConnectConnectionAdapter, GenerationFetcher, GenerationClientState, InferGenerationOutputFromReturn, ImageGenerateInput, AudioGenerateInput, SpeechGenerateInput, TranscriptionGenerateInput, AudioRecorderOptions, AudioRecording, InferAudioRecordingOutput, SummarizeGenerateInput, VideoGenerateResult, VideoGenerateInput, VideoStatusInfo } from '@tanstack/ai-client';
|
|
3
|
+
export { AudioGenerateInput, ChatRequestBody, ConnectConnectionAdapter, ConnectionAdapter, FetchConnectionOptions, GenerationClientState, ImageGenerateInput, InferChatMessages, MultimodalContent, RunAgentInputContext, SpeechGenerateInput, SubscribeConnectionAdapter, SummarizeGenerateInput, TranscriptionGenerateInput, UIMessage, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo, XhrConnectionOptions, createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, xhrHttpStream, xhrServerSentEvents } from '@tanstack/ai-client';
|
|
4
|
+
import { Signal } from '@angular/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A value that may be supplied to `injectChat` either as a static value, an
|
|
8
|
+
* Angular `Signal`, or a zero-arg getter. The getter form lets callers read
|
|
9
|
+
* other signals so the option stays reactive.
|
|
10
|
+
*/
|
|
11
|
+
type ReactiveOption<T> = T | Signal<T> | (() => T);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Recursive partial — every property and every nested array element is optional.
|
|
15
|
+
* Used to type the in-flight `partial` value while a structured-output stream
|
|
16
|
+
* is still arriving.
|
|
17
|
+
*/
|
|
18
|
+
type DeepPartial<T> = T extends ReadonlyArray<infer U> ? Array<DeepPartial<U>> : T extends object ? {
|
|
19
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
20
|
+
} : T;
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link injectChat}.
|
|
23
|
+
*
|
|
24
|
+
* Mirrors the Vue `useChat` options, except:
|
|
25
|
+
* - State-change callbacks are managed internally and exposed as signals.
|
|
26
|
+
* - `body`, `forwardedProps`, and `live` accept a {@link ReactiveOption} so
|
|
27
|
+
* they can be a static value, a `Signal`, or a getter and stay reactive.
|
|
28
|
+
*/
|
|
29
|
+
type InjectChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>> = DistributedOmit<ChatClientOptions<TTools, TContext>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'context' | 'devtools' | 'body' | 'forwardedProps'> & {
|
|
30
|
+
/** Display options for TanStack AI Devtools. */
|
|
31
|
+
devtools?: AIDevtoolsDisplayOptions;
|
|
32
|
+
/** Additional request body params. Reactive. */
|
|
33
|
+
body?: ReactiveOption<Record<string, any>>;
|
|
34
|
+
/** Forwarded request props (preferred over `body`). Reactive. */
|
|
35
|
+
forwardedProps?: ReactiveOption<Record<string, any>>;
|
|
36
|
+
/** Whether to keep a live subscription open. Reactive. */
|
|
37
|
+
live?: ReactiveOption<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Standard-schema-compatible schema (Zod, Valibot, ArkType, or JSON Schema).
|
|
40
|
+
* Used to infer the shape of `partial` and `final`.
|
|
41
|
+
*/
|
|
42
|
+
outputSchema?: TSchema;
|
|
43
|
+
} & ClientContextOptionFromTools<TTools, ReactiveOption<TContext>>;
|
|
44
|
+
/**
|
|
45
|
+
* Return shape of {@link injectChat}. When `outputSchema` is supplied, adds
|
|
46
|
+
* typed `partial` / `final` signals; otherwise the return is unchanged.
|
|
47
|
+
*/
|
|
48
|
+
type InjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined> = BaseInjectChatResult<TTools, TSchema extends SchemaInput ? InferSchemaType<TSchema> : unknown> & (TSchema extends SchemaInput ? {
|
|
49
|
+
/** Live progressively-parsed structured output. */
|
|
50
|
+
partial: Signal<DeepPartial<InferSchemaType<TSchema>>>;
|
|
51
|
+
/** Final, schema-validated structured output. `null` until complete. */
|
|
52
|
+
final: Signal<InferSchemaType<TSchema> | null>;
|
|
53
|
+
} : Record<never, never>);
|
|
54
|
+
interface BaseInjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any, TData = unknown> {
|
|
55
|
+
/** Current messages in the conversation. */
|
|
56
|
+
messages: Signal<Array<UIMessage<TTools, TData>>>;
|
|
57
|
+
/** Send a message (string or multimodal content). */
|
|
58
|
+
sendMessage: (content: string | MultimodalContent) => Promise<void>;
|
|
59
|
+
/** Append a message to the conversation. */
|
|
60
|
+
append: (message: ModelMessage | UIMessage<TTools, TData>) => Promise<void>;
|
|
61
|
+
/** Add the result of a client-side tool execution. */
|
|
62
|
+
addToolResult: (result: {
|
|
63
|
+
toolCallId: string;
|
|
64
|
+
tool: string;
|
|
65
|
+
output: any;
|
|
66
|
+
state?: 'output-available' | 'output-error';
|
|
67
|
+
errorText?: string;
|
|
68
|
+
}) => Promise<void>;
|
|
69
|
+
/** Respond to a tool approval request. */
|
|
70
|
+
addToolApprovalResponse: (response: {
|
|
71
|
+
id: string;
|
|
72
|
+
approved: boolean;
|
|
73
|
+
}) => Promise<void>;
|
|
74
|
+
/** Reload the last assistant message. */
|
|
75
|
+
reload: () => Promise<void>;
|
|
76
|
+
/** Stop the current response generation. */
|
|
77
|
+
stop: () => void;
|
|
78
|
+
/** Whether a response is currently being generated. */
|
|
79
|
+
isLoading: Signal<boolean>;
|
|
80
|
+
/** Current error, if any. */
|
|
81
|
+
error: Signal<Error | undefined>;
|
|
82
|
+
/** Set messages manually. */
|
|
83
|
+
setMessages: (messages: Array<UIMessage<TTools, TData>>) => void;
|
|
84
|
+
/** Clear all messages. */
|
|
85
|
+
clear: () => void;
|
|
86
|
+
/** Current generation status. */
|
|
87
|
+
status: Signal<ChatClientState>;
|
|
88
|
+
/** Whether the subscription loop is active. */
|
|
89
|
+
isSubscribed: Signal<boolean>;
|
|
90
|
+
/** Current connection lifecycle status. */
|
|
91
|
+
connectionStatus: Signal<ConnectionStatus>;
|
|
92
|
+
/** Whether the shared session is actively generating. */
|
|
93
|
+
sessionGenerating: Signal<boolean>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare function injectChat<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>>(options?: InjectChatOptions<TTools, TSchema, TContext>): InjectChatResult<TTools, TSchema>;
|
|
97
|
+
|
|
98
|
+
interface InjectGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
99
|
+
/** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
|
|
100
|
+
connection?: ConnectConnectionAdapter;
|
|
101
|
+
/** Direct async function for one-shot generation (no streaming protocol needed) */
|
|
102
|
+
fetcher?: GenerationFetcher<TInput, TResult>;
|
|
103
|
+
/** Unique identifier for this generation instance */
|
|
104
|
+
id?: string;
|
|
105
|
+
/** Additional request body params. Reactive. */
|
|
106
|
+
body?: ReactiveOption<Record<string, any>>;
|
|
107
|
+
/** Display options for TanStack AI Devtools. */
|
|
108
|
+
devtools?: AIDevtoolsDisplayOptions;
|
|
109
|
+
/**
|
|
110
|
+
* Callback when a result is received. Can optionally return a transformed value.
|
|
111
|
+
*
|
|
112
|
+
* - Return a non-null value to transform and store it as the result
|
|
113
|
+
* - Return `null` to keep the previous result unchanged
|
|
114
|
+
* - Return nothing (`void`) to store the raw result as-is
|
|
115
|
+
*/
|
|
116
|
+
onResult?: (result: TResult) => TOutput | null | void;
|
|
117
|
+
/** Callback when an error occurs */
|
|
118
|
+
onError?: (error: Error) => void;
|
|
119
|
+
/** Callback when progress is reported (0-100) */
|
|
120
|
+
onProgress?: (progress: number, message?: string) => void;
|
|
121
|
+
/** Callback for each stream chunk (connect-based adapter mode only) */
|
|
122
|
+
onChunk?: (chunk: StreamChunk) => void;
|
|
123
|
+
}
|
|
124
|
+
interface InjectGenerationResult<TOutput> {
|
|
125
|
+
/** Trigger a generation request */
|
|
126
|
+
generate: (input: Record<string, any>) => Promise<void>;
|
|
127
|
+
/** The generation result, or null if not yet generated */
|
|
128
|
+
result: Signal<TOutput | null>;
|
|
129
|
+
/** Whether a generation is currently in progress */
|
|
130
|
+
isLoading: Signal<boolean>;
|
|
131
|
+
/** Current error, if any */
|
|
132
|
+
error: Signal<Error | undefined>;
|
|
133
|
+
/** Current state of the generation client */
|
|
134
|
+
status: Signal<GenerationClientState>;
|
|
135
|
+
/** Abort the current generation */
|
|
136
|
+
stop: () => void;
|
|
137
|
+
/** Clear result, error, and return to idle */
|
|
138
|
+
reset: () => void;
|
|
139
|
+
}
|
|
140
|
+
declare function injectGeneration<TInput extends Record<string, any>, TResult, TTransformed = void>(options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {
|
|
141
|
+
onResult?: (result: TResult) => TTransformed;
|
|
142
|
+
}): InjectGenerationResult<InferGenerationOutputFromReturn<TResult, TTransformed>>;
|
|
143
|
+
|
|
144
|
+
type InjectGenerateImageOptions<TOutput = ImageGenerationResult> = Omit<InjectGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>, 'onResult'> & {
|
|
145
|
+
onResult?: (result: ImageGenerationResult) => TOutput | null | void;
|
|
146
|
+
};
|
|
147
|
+
interface InjectGenerateImageResult<TOutput = ImageGenerationResult> {
|
|
148
|
+
generate: (input: ImageGenerateInput) => Promise<void>;
|
|
149
|
+
result: Signal<TOutput | null>;
|
|
150
|
+
isLoading: Signal<boolean>;
|
|
151
|
+
error: Signal<Error | undefined>;
|
|
152
|
+
status: Signal<GenerationClientState>;
|
|
153
|
+
stop: () => void;
|
|
154
|
+
reset: () => void;
|
|
155
|
+
}
|
|
156
|
+
declare function injectGenerateImage<TTransformed = void>(options: Omit<InjectGenerateImageOptions, 'onResult'> & {
|
|
157
|
+
onResult?: (result: ImageGenerationResult) => TTransformed;
|
|
158
|
+
}): InjectGenerateImageResult<InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Options for the injectGenerateAudio injectable.
|
|
162
|
+
*
|
|
163
|
+
* @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)
|
|
164
|
+
*/
|
|
165
|
+
interface InjectGenerateAudioOptions<TOutput = AudioGenerationResult> {
|
|
166
|
+
/** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
|
|
167
|
+
connection?: ConnectConnectionAdapter;
|
|
168
|
+
/** Direct async function for audio generation */
|
|
169
|
+
fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>;
|
|
170
|
+
/** Unique identifier for this generation instance */
|
|
171
|
+
id?: string;
|
|
172
|
+
/** Additional body parameters to send with connect-based adapter requests. Reactive. */
|
|
173
|
+
body?: ReactiveOption<Record<string, any>>;
|
|
174
|
+
/** Display options for TanStack AI Devtools. */
|
|
175
|
+
devtools?: AIDevtoolsDisplayOptions;
|
|
176
|
+
/**
|
|
177
|
+
* Callback when audio is generated. Can optionally return a transformed value.
|
|
178
|
+
*
|
|
179
|
+
* - Return a non-null value to transform and store it as the result
|
|
180
|
+
* - Return `null` to keep the previous result unchanged
|
|
181
|
+
* - Return nothing (`void`) to store the raw result as-is
|
|
182
|
+
*/
|
|
183
|
+
onResult?: (result: AudioGenerationResult) => TOutput | null | void;
|
|
184
|
+
/** Callback when an error occurs */
|
|
185
|
+
onError?: (error: Error) => void;
|
|
186
|
+
/** Callback when progress is reported (0-100) */
|
|
187
|
+
onProgress?: (progress: number, message?: string) => void;
|
|
188
|
+
/** Callback for each stream chunk (connect-based adapter mode only) */
|
|
189
|
+
onChunk?: (chunk: StreamChunk) => void;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Return type for the injectGenerateAudio injectable.
|
|
193
|
+
*
|
|
194
|
+
* @template TOutput - The output type (after optional transform)
|
|
195
|
+
*/
|
|
196
|
+
interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> {
|
|
197
|
+
/** Trigger audio generation */
|
|
198
|
+
generate: (input: AudioGenerateInput) => Promise<void>;
|
|
199
|
+
/** The generation result containing audio, or null */
|
|
200
|
+
result: Signal<TOutput | null>;
|
|
201
|
+
/** Whether generation is in progress */
|
|
202
|
+
isLoading: Signal<boolean>;
|
|
203
|
+
/** Current error, if any */
|
|
204
|
+
error: Signal<Error | undefined>;
|
|
205
|
+
/** Current state of the generation */
|
|
206
|
+
status: Signal<GenerationClientState>;
|
|
207
|
+
/** Abort the current generation */
|
|
208
|
+
stop: () => void;
|
|
209
|
+
/** Clear result, error, and return to idle */
|
|
210
|
+
reset: () => void;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Angular injectable for generating audio (music, sound effects) using AI models.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* import { Component } from '@angular/core'
|
|
218
|
+
* import { injectGenerateAudio } from '@tanstack/ai-angular'
|
|
219
|
+
* import { fetchServerSentEvents } from '@tanstack/ai-client'
|
|
220
|
+
*
|
|
221
|
+
* @Component({
|
|
222
|
+
* selector: 'app-audio',
|
|
223
|
+
* template: `
|
|
224
|
+
* <button (click)="generate({ prompt: 'An upbeat electronic track', duration: 10 })">
|
|
225
|
+
* Generate
|
|
226
|
+
* </button>
|
|
227
|
+
* @if (result()) {
|
|
228
|
+
* <audio [src]="result()!.audio.url" controls></audio>
|
|
229
|
+
* }
|
|
230
|
+
* `,
|
|
231
|
+
* })
|
|
232
|
+
* export class AudioComponent {
|
|
233
|
+
* private gen = injectGenerateAudio({
|
|
234
|
+
* connection: fetchServerSentEvents('/api/generate/audio'),
|
|
235
|
+
* })
|
|
236
|
+
*
|
|
237
|
+
* generate = this.gen.generate
|
|
238
|
+
* result = this.gen.result
|
|
239
|
+
* isLoading = this.gen.isLoading
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
declare function injectGenerateAudio<TTransformed = void>(options: Omit<InjectGenerateAudioOptions, 'onResult'> & {
|
|
244
|
+
onResult?: (result: AudioGenerationResult) => TTransformed;
|
|
245
|
+
}): InjectGenerateAudioResult<InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>>;
|
|
246
|
+
|
|
247
|
+
type InjectGenerateSpeechOptions<TOutput = TTSResult> = Omit<InjectGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>, 'onResult'> & {
|
|
248
|
+
onResult?: (result: TTSResult) => TOutput | null | void;
|
|
249
|
+
};
|
|
250
|
+
interface InjectGenerateSpeechResult<TOutput = TTSResult> {
|
|
251
|
+
generate: (input: SpeechGenerateInput) => Promise<void>;
|
|
252
|
+
result: Signal<TOutput | null>;
|
|
253
|
+
isLoading: Signal<boolean>;
|
|
254
|
+
error: Signal<Error | undefined>;
|
|
255
|
+
status: Signal<GenerationClientState>;
|
|
256
|
+
stop: () => void;
|
|
257
|
+
reset: () => void;
|
|
258
|
+
}
|
|
259
|
+
declare function injectGenerateSpeech<TTransformed = void>(options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {
|
|
260
|
+
onResult?: (result: TTSResult) => TTransformed;
|
|
261
|
+
}): InjectGenerateSpeechResult<InferGenerationOutputFromReturn<TTSResult, TTransformed>>;
|
|
262
|
+
|
|
263
|
+
type InjectTranscriptionOptions<TOutput = TranscriptionResult> = Omit<InjectGenerationOptions<TranscriptionGenerateInput, TranscriptionResult, TOutput>, 'onResult'> & {
|
|
264
|
+
onResult?: (result: TranscriptionResult) => TOutput | null | void;
|
|
265
|
+
};
|
|
266
|
+
interface InjectTranscriptionResult<TOutput = TranscriptionResult> {
|
|
267
|
+
generate: (input: TranscriptionGenerateInput) => Promise<void>;
|
|
268
|
+
result: Signal<TOutput | null>;
|
|
269
|
+
isLoading: Signal<boolean>;
|
|
270
|
+
error: Signal<Error | undefined>;
|
|
271
|
+
status: Signal<GenerationClientState>;
|
|
272
|
+
stop: () => void;
|
|
273
|
+
reset: () => void;
|
|
274
|
+
}
|
|
275
|
+
declare function injectTranscription<TTransformed = void>(options: Omit<InjectTranscriptionOptions, 'onResult'> & {
|
|
276
|
+
onResult?: (result: TranscriptionResult) => TTransformed;
|
|
277
|
+
}): InjectTranscriptionResult<InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>>;
|
|
278
|
+
|
|
279
|
+
type InjectAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {
|
|
280
|
+
/**
|
|
281
|
+
* Optional transform applied to the recording when `stop()` resolves. Its
|
|
282
|
+
* (awaited) return value becomes `recording` and the resolved value of
|
|
283
|
+
* `stop()`. Return nothing to keep the raw `AudioRecording`.
|
|
284
|
+
*/
|
|
285
|
+
onComplete?: TOnComplete;
|
|
286
|
+
};
|
|
287
|
+
interface InjectAudioRecorderResult<TOutput> {
|
|
288
|
+
/** Reactive: latest recording (transformed if `onComplete` provided), or null. */
|
|
289
|
+
recording: Signal<TOutput | null>;
|
|
290
|
+
/** Reactive: true while actively capturing audio. */
|
|
291
|
+
isRecording: Signal<boolean>;
|
|
292
|
+
/** Whether the browser supports recording. */
|
|
293
|
+
isSupported: boolean;
|
|
294
|
+
start: () => Promise<void>;
|
|
295
|
+
/** Stop and resolve with the completed recording (transformed if `onComplete` provided). */
|
|
296
|
+
stop: () => Promise<TOutput>;
|
|
297
|
+
/** Discard the in-progress recording and release the mic. */
|
|
298
|
+
cancel: () => void;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Angular injectable for recording an audio message. The resolved recording
|
|
302
|
+
* carries `.part` (for `injectChat`'s `sendMessage`) and `.base64` (for the
|
|
303
|
+
* generation injectables). Must be called in an injection context.
|
|
304
|
+
*
|
|
305
|
+
* Errors are delivered via `onError`. `start()` and `stop()` also reject on
|
|
306
|
+
* failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs
|
|
307
|
+
* while a stop is in flight, e.g. on destroy) — handle one channel, not both.
|
|
308
|
+
*/
|
|
309
|
+
declare function injectAudioRecorder<TOnComplete extends (recording: AudioRecording) => unknown>(options: InjectAudioRecorderOptions<TOnComplete>): InjectAudioRecorderResult<InferAudioRecordingOutput<TOnComplete>>;
|
|
310
|
+
declare function injectAudioRecorder(options?: InjectAudioRecorderOptions<undefined>): InjectAudioRecorderResult<AudioRecording>;
|
|
311
|
+
|
|
312
|
+
type InjectSummarizeOptions<TOutput = SummarizationResult> = Omit<InjectGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>, 'onResult'> & {
|
|
313
|
+
onResult?: (result: SummarizationResult) => TOutput | null | void;
|
|
314
|
+
};
|
|
315
|
+
interface InjectSummarizeResult<TOutput = SummarizationResult> {
|
|
316
|
+
generate: (input: SummarizeGenerateInput) => Promise<void>;
|
|
317
|
+
result: Signal<TOutput | null>;
|
|
318
|
+
isLoading: Signal<boolean>;
|
|
319
|
+
error: Signal<Error | undefined>;
|
|
320
|
+
status: Signal<GenerationClientState>;
|
|
321
|
+
stop: () => void;
|
|
322
|
+
reset: () => void;
|
|
323
|
+
}
|
|
324
|
+
declare function injectSummarize<TTransformed = void>(options: Omit<InjectSummarizeOptions, 'onResult'> & {
|
|
325
|
+
onResult?: (result: SummarizationResult) => TTransformed;
|
|
326
|
+
}): InjectSummarizeResult<InferGenerationOutputFromReturn<SummarizationResult, TTransformed>>;
|
|
327
|
+
|
|
328
|
+
interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {
|
|
329
|
+
connection?: ConnectConnectionAdapter;
|
|
330
|
+
fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>;
|
|
331
|
+
id?: string;
|
|
332
|
+
body?: ReactiveOption<Record<string, any>>;
|
|
333
|
+
devtools?: AIDevtoolsDisplayOptions;
|
|
334
|
+
onResult?: (result: VideoGenerateResult) => TOutput | null | void;
|
|
335
|
+
onError?: (error: Error) => void;
|
|
336
|
+
onProgress?: (progress: number, message?: string) => void;
|
|
337
|
+
onJobCreated?: (jobId: string) => void;
|
|
338
|
+
onStatusUpdate?: (status: VideoStatusInfo) => void;
|
|
339
|
+
onChunk?: (chunk: StreamChunk) => void;
|
|
340
|
+
}
|
|
341
|
+
interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {
|
|
342
|
+
generate: (input: VideoGenerateInput) => Promise<void>;
|
|
343
|
+
result: Signal<TOutput | null>;
|
|
344
|
+
jobId: Signal<string | null>;
|
|
345
|
+
videoStatus: Signal<VideoStatusInfo | null>;
|
|
346
|
+
isLoading: Signal<boolean>;
|
|
347
|
+
error: Signal<Error | undefined>;
|
|
348
|
+
status: Signal<GenerationClientState>;
|
|
349
|
+
stop: () => void;
|
|
350
|
+
reset: () => void;
|
|
351
|
+
}
|
|
352
|
+
declare function injectGenerateVideo<TTransformed = void>(options: Omit<InjectGenerateVideoOptions, 'onResult'> & {
|
|
353
|
+
onResult?: (result: VideoGenerateResult) => TTransformed;
|
|
354
|
+
}): InjectGenerateVideoResult<InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>>;
|
|
355
|
+
|
|
356
|
+
export { injectAudioRecorder, injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectSummarize, injectTranscription };
|
|
357
|
+
export type { DeepPartial, InjectAudioRecorderOptions, InjectAudioRecorderResult, InjectChatOptions, InjectChatResult, InjectGenerateAudioOptions, InjectGenerateAudioResult, InjectGenerateImageOptions, InjectGenerateImageResult, InjectGenerateSpeechOptions, InjectGenerateSpeechResult, InjectGenerateVideoOptions, InjectGenerateVideoResult, InjectGenerationOptions, InjectGenerationResult, 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": "0.2.0",
|
|
4
4
|
"description": "Angular signals integration for TanStack AI streaming chat, structured outputs, and media generation.",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"tslib": "^2.8.1",
|
|
48
|
-
"@tanstack/ai-client": "0.
|
|
48
|
+
"@tanstack/ai-client": "0.19.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@angular/core": ">=21.0.0",
|
|
52
|
-
"@tanstack/ai": "^0.
|
|
52
|
+
"@tanstack/ai": "^0.38.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@analogjs/vite-plugin-angular": "^1.10.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"vitest": "^4.0.14",
|
|
67
67
|
"zod": "^4.2.0",
|
|
68
68
|
"zone.js": "^0.15.0",
|
|
69
|
-
"@tanstack/ai": "0.
|
|
69
|
+
"@tanstack/ai": "0.38.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"clean": "premove ./build ./dist",
|
package/src/index.ts
CHANGED
|
@@ -36,6 +36,13 @@ export type {
|
|
|
36
36
|
InjectTranscriptionResult,
|
|
37
37
|
} from './inject-transcription'
|
|
38
38
|
|
|
39
|
+
// Audio Recorder
|
|
40
|
+
export { injectAudioRecorder } from './inject-audio-recorder'
|
|
41
|
+
export type {
|
|
42
|
+
InjectAudioRecorderOptions,
|
|
43
|
+
InjectAudioRecorderResult,
|
|
44
|
+
} from './inject-audio-recorder'
|
|
45
|
+
|
|
39
46
|
// Summarize
|
|
40
47
|
export { injectSummarize } from './inject-summarize'
|
|
41
48
|
export type {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DestroyRef,
|
|
3
|
+
assertInInjectionContext,
|
|
4
|
+
inject,
|
|
5
|
+
signal,
|
|
6
|
+
} from '@angular/core'
|
|
7
|
+
import { AudioRecorder } from '@tanstack/ai-client'
|
|
8
|
+
import type { Signal } from '@angular/core'
|
|
9
|
+
import type {
|
|
10
|
+
AudioRecorderOptions,
|
|
11
|
+
AudioRecording,
|
|
12
|
+
InferAudioRecordingOutput,
|
|
13
|
+
} from '@tanstack/ai-client'
|
|
14
|
+
|
|
15
|
+
export type InjectAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {
|
|
16
|
+
/**
|
|
17
|
+
* Optional transform applied to the recording when `stop()` resolves. Its
|
|
18
|
+
* (awaited) return value becomes `recording` and the resolved value of
|
|
19
|
+
* `stop()`. Return nothing to keep the raw `AudioRecording`.
|
|
20
|
+
*/
|
|
21
|
+
onComplete?: TOnComplete
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface InjectAudioRecorderResult<TOutput> {
|
|
25
|
+
/** Reactive: latest recording (transformed if `onComplete` provided), or null. */
|
|
26
|
+
recording: Signal<TOutput | null>
|
|
27
|
+
/** Reactive: true while actively capturing audio. */
|
|
28
|
+
isRecording: Signal<boolean>
|
|
29
|
+
/** Whether the browser supports recording. */
|
|
30
|
+
isSupported: boolean
|
|
31
|
+
start: () => Promise<void>
|
|
32
|
+
/** Stop and resolve with the completed recording (transformed if `onComplete` provided). */
|
|
33
|
+
stop: () => Promise<TOutput>
|
|
34
|
+
/** Discard the in-progress recording and release the mic. */
|
|
35
|
+
cancel: () => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Angular injectable for recording an audio message. The resolved recording
|
|
40
|
+
* carries `.part` (for `injectChat`'s `sendMessage`) and `.base64` (for the
|
|
41
|
+
* generation injectables). Must be called in an injection context.
|
|
42
|
+
*
|
|
43
|
+
* Errors are delivered via `onError`. `start()` and `stop()` also reject on
|
|
44
|
+
* failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs
|
|
45
|
+
* while a stop is in flight, e.g. on destroy) — handle one channel, not both.
|
|
46
|
+
*/
|
|
47
|
+
export function injectAudioRecorder<
|
|
48
|
+
TOnComplete extends (recording: AudioRecording) => unknown,
|
|
49
|
+
>(
|
|
50
|
+
options: InjectAudioRecorderOptions<TOnComplete>,
|
|
51
|
+
): InjectAudioRecorderResult<InferAudioRecordingOutput<TOnComplete>>
|
|
52
|
+
export function injectAudioRecorder(
|
|
53
|
+
options?: InjectAudioRecorderOptions<undefined>,
|
|
54
|
+
): InjectAudioRecorderResult<AudioRecording>
|
|
55
|
+
export function injectAudioRecorder(
|
|
56
|
+
options: InjectAudioRecorderOptions<
|
|
57
|
+
(recording: AudioRecording) => unknown
|
|
58
|
+
> = {},
|
|
59
|
+
): InjectAudioRecorderResult<unknown> {
|
|
60
|
+
assertInInjectionContext(injectAudioRecorder)
|
|
61
|
+
const destroyRef = inject(DestroyRef)
|
|
62
|
+
const recorder = new AudioRecorder({
|
|
63
|
+
...(options.audio !== undefined && { audio: options.audio }),
|
|
64
|
+
...(options.mimeType !== undefined && { mimeType: options.mimeType }),
|
|
65
|
+
...(options.onError !== undefined && { onError: options.onError }),
|
|
66
|
+
})
|
|
67
|
+
const isRecording = signal(false)
|
|
68
|
+
const recording = signal<unknown>(null)
|
|
69
|
+
|
|
70
|
+
const unsubscribe = recorder.subscribe((state) => {
|
|
71
|
+
isRecording.set(state === 'recording')
|
|
72
|
+
})
|
|
73
|
+
destroyRef.onDestroy(() => {
|
|
74
|
+
unsubscribe()
|
|
75
|
+
recorder.cancel()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const stop = async (): Promise<unknown> => {
|
|
79
|
+
const rawRecording = await recorder.stop()
|
|
80
|
+
const transformed = await options.onComplete?.(rawRecording)
|
|
81
|
+
// Only `undefined` (returning nothing) keeps the raw recording; a returned
|
|
82
|
+
// null is a real value, matching the inferred output type.
|
|
83
|
+
const output = transformed === undefined ? rawRecording : transformed
|
|
84
|
+
recording.set(output)
|
|
85
|
+
return output
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
recording: recording.asReadonly(),
|
|
90
|
+
isRecording: isRecording.asReadonly(),
|
|
91
|
+
isSupported: AudioRecorder.isSupported(),
|
|
92
|
+
start: () => recorder.start(),
|
|
93
|
+
stop,
|
|
94
|
+
cancel: () => recorder.cancel(),
|
|
95
|
+
}
|
|
96
|
+
}
|