@tanstack/ai-solid 0.18.1 → 0.18.2
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.
|
@@ -30,7 +30,9 @@ interface UseAudioRecorderReturn<TOutput> {
|
|
|
30
30
|
* failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs
|
|
31
31
|
* while a stop is in flight, e.g. on unmount) — handle one channel, not both.
|
|
32
32
|
*/
|
|
33
|
-
declare function useAudioRecorder<TOnComplete extends (recording: AudioRecording) => unknown>(options: UseAudioRecorderOptions<TOnComplete>
|
|
33
|
+
declare function useAudioRecorder<TOnComplete extends (recording: AudioRecording) => unknown>(options: UseAudioRecorderOptions<TOnComplete> & {
|
|
34
|
+
onComplete: TOnComplete;
|
|
35
|
+
}): UseAudioRecorderReturn<InferAudioRecordingOutput<TOnComplete>>;
|
|
34
36
|
declare function useAudioRecorder(options?: UseAudioRecorderOptions<undefined>): UseAudioRecorderReturn<AudioRecording>;
|
|
35
37
|
//#endregion
|
|
36
38
|
export { UseAudioRecorderOptions, UseAudioRecorderReturn, useAudioRecorder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-audio-recorder.js","names":[],"sources":["../src/use-audio-recorder.ts"],"sourcesContent":["import { createSignal, onCleanup } from 'solid-js'\nimport { AudioRecorder } from '@tanstack/ai-client'\nimport type {\n AudioRecorderOptions,\n AudioRecording,\n InferAudioRecordingOutput,\n} from '@tanstack/ai-client'\n\nexport type UseAudioRecorderOptions<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 UseAudioRecorderReturn<TOutput> {\n /** Solid accessor: latest recording (transformed if `onComplete` provided), or null. */\n recording: () => TOutput | null\n /** Solid accessor: true while actively capturing audio. */\n isRecording: () => 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 * Solid hook for recording an audio message. The resolved recording carries\n * `.part` (for `useChat.sendMessage`) and `.base64` (for generation hooks).\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 unmount) — handle one channel, not both.\n */\nexport function useAudioRecorder<\n TOnComplete extends (recording: AudioRecording) => unknown,\n>(\n options: UseAudioRecorderOptions<TOnComplete
|
|
1
|
+
{"version":3,"file":"use-audio-recorder.js","names":[],"sources":["../src/use-audio-recorder.ts"],"sourcesContent":["import { createSignal, onCleanup } from 'solid-js'\nimport { AudioRecorder } from '@tanstack/ai-client'\nimport type {\n AudioRecorderOptions,\n AudioRecording,\n InferAudioRecordingOutput,\n} from '@tanstack/ai-client'\n\nexport type UseAudioRecorderOptions<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 UseAudioRecorderReturn<TOutput> {\n /** Solid accessor: latest recording (transformed if `onComplete` provided), or null. */\n recording: () => TOutput | null\n /** Solid accessor: true while actively capturing audio. */\n isRecording: () => 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 * Solid hook for recording an audio message. The resolved recording carries\n * `.part` (for `useChat.sendMessage`) and `.base64` (for generation hooks).\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 unmount) — handle one channel, not both.\n */\n// The transforming overload requires `onComplete`. Without that constraint an\n// options object carrying only unrelated keys (`useAudioRecorder({ onError })`)\n// still matches it, `TOnComplete` infers as `unknown`, and `recording`/`stop()`\n// collapse to `unknown` — so passing any option would silently cost you the\n// `AudioRecording` type. Requiring it here sends those calls to the second\n// overload instead (issue #1001).\nexport function useAudioRecorder<\n TOnComplete extends (recording: AudioRecording) => unknown,\n>(\n options: UseAudioRecorderOptions<TOnComplete> & { onComplete: TOnComplete },\n): UseAudioRecorderReturn<InferAudioRecordingOutput<TOnComplete>>\nexport function useAudioRecorder(\n options?: UseAudioRecorderOptions<undefined>,\n): UseAudioRecorderReturn<AudioRecording>\nexport function useAudioRecorder(\n options: UseAudioRecorderOptions<(recording: AudioRecording) => unknown> = {},\n): UseAudioRecorderReturn<unknown> {\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, setIsRecording] = createSignal(false)\n const [recording, setRecording] = createSignal<unknown>(null)\n\n const unsubscribe = recorder.subscribe((state) => {\n setIsRecording(state === 'recording')\n })\n\n onCleanup(() => {\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 // Store via updater so a function-valued transform result isn't invoked.\n setRecording(() => output)\n return output\n }\n\n return {\n recording,\n isRecording,\n isSupported: AudioRecorder.isSupported(),\n start: () => recorder.start(),\n stop,\n cancel: () => recorder.cancel(),\n }\n}\n"],"mappings":";;;;AAqDA,SAAgB,iBACd,UAA2E,EAAE,EAC5C;CACjC,MAAM,WAAW,IAAI,cAAc;EACjC,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,OAAO;EAC3D,GAAI,QAAQ,aAAa,UAAa,EAAE,UAAU,QAAQ,UAAU;EACpE,GAAI,QAAQ,YAAY,UAAa,EAAE,SAAS,QAAQ,SAAS;EAClE,CAAC;CACF,MAAM,CAAC,aAAa,kBAAkB,aAAa,MAAM;CACzD,MAAM,CAAC,WAAW,gBAAgB,aAAsB,KAAK;CAE7D,MAAM,cAAc,SAAS,WAAW,UAAU;AAChD,iBAAe,UAAU,YAAY;GACrC;AAEF,iBAAgB;AACd,eAAa;AACb,WAAS,QAAQ;GACjB;CAEF,MAAM,OAAO,YAA8B;EACzC,MAAM,eAAe,MAAM,SAAS,MAAM;EAC1C,MAAM,cAAc,MAAM,QAAQ,aAAa,aAAa;EAG5D,MAAM,SAAS,gBAAgB,SAAY,eAAe;AAE1D,qBAAmB,OAAO;AAC1B,SAAO;;AAGT,QAAO;EACL;EACA;EACA,aAAa,cAAc,aAAa;EACxC,aAAa,SAAS,OAAO;EAC7B;EACA,cAAc,SAAS,QAAQ;EAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-solid",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Solid hooks for TanStack AI streaming chat, structured outputs, and media generation.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"media-generation"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@tanstack/ai-client": "^0.25.
|
|
48
|
+
"@tanstack/ai-client": "^0.25.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"solid-js": ">=1.9.10",
|
|
52
|
-
"@tanstack/ai": "^0.47.
|
|
52
|
+
"@tanstack/ai": "^0.47.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@solidjs/testing-library": "^0.8.10",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"tsdown": "^0.17.0-beta.6",
|
|
62
62
|
"typescript": "5.9.3",
|
|
63
63
|
"vitest": "^4.1.10",
|
|
64
|
-
"@tanstack/ai": "0.47.
|
|
64
|
+
"@tanstack/ai": "0.47.3"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"clean": "premove ./build ./dist",
|
|
@@ -37,10 +37,16 @@ export interface UseAudioRecorderReturn<TOutput> {
|
|
|
37
37
|
* failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs
|
|
38
38
|
* while a stop is in flight, e.g. on unmount) — handle one channel, not both.
|
|
39
39
|
*/
|
|
40
|
+
// The transforming overload requires `onComplete`. Without that constraint an
|
|
41
|
+
// options object carrying only unrelated keys (`useAudioRecorder({ onError })`)
|
|
42
|
+
// still matches it, `TOnComplete` infers as `unknown`, and `recording`/`stop()`
|
|
43
|
+
// collapse to `unknown` — so passing any option would silently cost you the
|
|
44
|
+
// `AudioRecording` type. Requiring it here sends those calls to the second
|
|
45
|
+
// overload instead (issue #1001).
|
|
40
46
|
export function useAudioRecorder<
|
|
41
47
|
TOnComplete extends (recording: AudioRecording) => unknown,
|
|
42
48
|
>(
|
|
43
|
-
options: UseAudioRecorderOptions<TOnComplete
|
|
49
|
+
options: UseAudioRecorderOptions<TOnComplete> & { onComplete: TOnComplete },
|
|
44
50
|
): UseAudioRecorderReturn<InferAudioRecordingOutput<TOnComplete>>
|
|
45
51
|
export function useAudioRecorder(
|
|
46
52
|
options?: UseAudioRecorderOptions<undefined>,
|