@tanstack/ai-solid 0.6.3 → 0.6.4
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/index.d.ts +8 -2
- package/dist/index.js +7 -1
- package/dist/use-generate-image.d.ts +94 -0
- package/dist/use-generate-image.js +51 -0
- package/dist/use-generate-image.js.map +1 -0
- package/dist/use-generate-speech.d.ts +88 -0
- package/dist/use-generate-speech.js +45 -0
- package/dist/use-generate-speech.js.map +1 -0
- package/dist/use-generate-video.d.ts +101 -0
- package/dist/use-generate-video.js +105 -0
- package/dist/use-generate-video.js.map +1 -0
- package/dist/use-generation.d.ts +86 -0
- package/dist/use-generation.js +86 -0
- package/dist/use-generation.js.map +1 -0
- package/dist/use-summarize.d.ts +91 -0
- package/dist/use-summarize.js +48 -0
- package/dist/use-summarize.js.map +1 -0
- package/dist/use-transcription.d.ts +97 -0
- package/dist/use-transcription.js +54 -0
- package/dist/use-transcription.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +42 -0
- package/src/use-generate-image.ts +118 -0
- package/src/use-generate-speech.ts +109 -0
- package/src/use-generate-video.ts +207 -0
- package/src/use-generation.ts +179 -0
- package/src/use-summarize.ts +115 -0
- package/src/use-transcription.ts +123 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createEffect, createMemo, createSignal, createUniqueId } from "solid-js";
|
|
2
|
+
import { GenerationClient } from "@tanstack/ai-client";
|
|
3
|
+
|
|
4
|
+
//#region src/use-generation.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generic Solid hook for one-shot generation tasks.
|
|
7
|
+
*
|
|
8
|
+
* This is the base hook used by `useGenerateImage`, `useGenerateSpeech`,
|
|
9
|
+
* `useTranscription`, and `useSummarize`. You can also use it directly
|
|
10
|
+
* for custom generation types.
|
|
11
|
+
*
|
|
12
|
+
* @template TInput - The input type for the generation request
|
|
13
|
+
* @template TResult - The result type returned by the generation
|
|
14
|
+
* @template TOutput - The transformed output type (defaults to TResult)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const { generate, result, isLoading } = useGeneration<MyInput, MyResult>({
|
|
19
|
+
* connection: fetchServerSentEvents('/api/generate/custom'),
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* await generate({ prompt: 'Hello' })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function useGeneration(options) {
|
|
26
|
+
const hookId = createUniqueId();
|
|
27
|
+
const clientId = options.id || hookId;
|
|
28
|
+
const [result, setResult] = createSignal(null);
|
|
29
|
+
const [isLoading, setIsLoading] = createSignal(false);
|
|
30
|
+
const [error, setError] = createSignal(void 0);
|
|
31
|
+
const [status, setStatus] = createSignal("idle");
|
|
32
|
+
const client = createMemo(() => {
|
|
33
|
+
const clientOptions = {
|
|
34
|
+
id: clientId,
|
|
35
|
+
body: options.body,
|
|
36
|
+
onResult: (r) => options.onResult?.(r),
|
|
37
|
+
onError: (e) => options.onError?.(e),
|
|
38
|
+
onProgress: (p, m) => options.onProgress?.(p, m),
|
|
39
|
+
onChunk: (c) => options.onChunk?.(c),
|
|
40
|
+
onResultChange: setResult,
|
|
41
|
+
onLoadingChange: setIsLoading,
|
|
42
|
+
onErrorChange: setError,
|
|
43
|
+
onStatusChange: setStatus
|
|
44
|
+
};
|
|
45
|
+
if (options.connection) return new GenerationClient({
|
|
46
|
+
...clientOptions,
|
|
47
|
+
connection: options.connection
|
|
48
|
+
});
|
|
49
|
+
if (options.fetcher) return new GenerationClient({
|
|
50
|
+
...clientOptions,
|
|
51
|
+
fetcher: options.fetcher
|
|
52
|
+
});
|
|
53
|
+
throw new Error("useGeneration requires either a connection or fetcher option");
|
|
54
|
+
}, [clientId]);
|
|
55
|
+
createEffect(() => {
|
|
56
|
+
const currentBody = options.body;
|
|
57
|
+
client().updateOptions({ body: currentBody });
|
|
58
|
+
});
|
|
59
|
+
createEffect(() => {
|
|
60
|
+
return () => {
|
|
61
|
+
client().stop();
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
const generate = async (input) => {
|
|
65
|
+
await client().generate(input);
|
|
66
|
+
};
|
|
67
|
+
const stop = () => {
|
|
68
|
+
client().stop();
|
|
69
|
+
};
|
|
70
|
+
const reset = () => {
|
|
71
|
+
client().reset();
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
generate,
|
|
75
|
+
result,
|
|
76
|
+
isLoading,
|
|
77
|
+
error,
|
|
78
|
+
status,
|
|
79
|
+
stop,
|
|
80
|
+
reset
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
export { useGeneration };
|
|
86
|
+
//# sourceMappingURL=use-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-generation.js","names":["clientOptions: GenerationClientOptions<TInput, TResult, TOutput>"],"sources":["../src/use-generation.ts"],"sourcesContent":["import { GenerationClient } from '@tanstack/ai-client'\nimport {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n} from 'solid-js'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientOptions,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGeneration hook.\n *\n * Accepts either a `connection` (streaming transport) or a `fetcher` (direct async call).\n *\n * @template TInput - The input type for the generation request\n * @template TResult - The result type returned by the generation\n * @template TOutput - The transformed output type (defaults to TResult)\n */\nexport interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\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 body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\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 (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGeneration hook.\n *\n * @template TOutput - The output type (possibly transformed from the raw result)\n */\nexport interface UseGenerationReturn<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: Accessor<TOutput | null>\n /** Whether a generation is currently in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation client */\n status: Accessor<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Generic Solid hook for one-shot generation tasks.\n *\n * This is the base hook used by `useGenerateImage`, `useGenerateSpeech`,\n * `useTranscription`, and `useSummarize`. You can also use it directly\n * for custom generation types.\n *\n * @template TInput - The input type for the generation request\n * @template TResult - The result type returned by the generation\n * @template TOutput - The transformed output type (defaults to TResult)\n *\n * @example\n * ```tsx\n * const { generate, result, isLoading } = useGeneration<MyInput, MyResult>({\n * connection: fetchServerSentEvents('/api/generate/custom'),\n * })\n *\n * await generate({ prompt: 'Hello' })\n * ```\n */\nexport function useGeneration<\n TInput extends Record<string, any>,\n TResult,\n TOnResult extends ((result: TResult) => any) | undefined = undefined,\n>(\n options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseGenerationReturn<InferGenerationOutput<TResult, TOnResult>> {\n type TOutput = InferGenerationOutput<TResult, TOnResult>\n const hookId = createUniqueId()\n const clientId = options.id || hookId\n\n const [result, setResult] = createSignal<TOutput | null>(null)\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<GenerationClientState>('idle')\n\n const client = createMemo(() => {\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n body: options.body,\n onResult: (r: TResult) => options.onResult?.(r),\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: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n }\n\n if (options.connection) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n connection: options.connection,\n })\n }\n\n if (options.fetcher) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n fetcher: options.fetcher,\n })\n }\n\n throw new Error(\n 'useGeneration requires either a connection or fetcher option',\n )\n }, [clientId])\n\n // Sync body changes without recreating client\n createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\n\n // Cleanup on unmount: stop any in-flight requests\n createEffect(() => {\n return () => {\n client().stop()\n }\n })\n\n const generate = async (input: TInput) => {\n await client().generate(input)\n }\n\n const stop = () => {\n client().stop()\n }\n\n const reset = () => {\n client().reset()\n }\n\n return {\n generate: generate as (input: Record<string, any>) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,cAKd,SAGgE;CAEhE,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,QAAQ,aAAa,aAA6B,KAAK;CAC9D,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAAoC,OAAO;CAEvE,MAAM,SAAS,iBAAiB;EAC9B,MAAMA,gBAAmE;GACvE,IAAI;GACJ,MAAM,QAAQ;GACd,WAAW,MAAe,QAAQ,WAAW,EAAE;GAC/C,UAAU,MAAa,QAAQ,UAAU,EAAE;GAC3C,aAAa,GAAW,MAAe,QAAQ,aAAa,GAAG,EAAE;GACjE,UAAU,MAAmB,QAAQ,UAAU,EAAE;GACjD,gBAAgB;GAChB,iBAAiB;GACjB,eAAe;GACf,gBAAgB;GACjB;AAED,MAAI,QAAQ,WACV,QAAO,IAAI,iBAA2C;GACpD,GAAG;GACH,YAAY,QAAQ;GACrB,CAAC;AAGJ,MAAI,QAAQ,QACV,QAAO,IAAI,iBAA2C;GACpD,GAAG;GACH,SAAS,QAAQ;GAClB,CAAC;AAGJ,QAAM,IAAI,MACR,+DACD;IACA,CAAC,SAAS,CAAC;AAGd,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAGF,oBAAmB;AACjB,eAAa;AACX,WAAQ,CAAC,MAAM;;GAEjB;CAEF,MAAM,WAAW,OAAO,UAAkB;AACxC,QAAM,QAAQ,CAAC,SAAS,MAAM;;CAGhC,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;AAGlB,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SummarizeGenerateInput } from "@tanstack/ai-client";
|
|
3
|
+
import { StreamChunk, SummarizationResult } from "@tanstack/ai";
|
|
4
|
+
|
|
5
|
+
//#region src/use-summarize.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for the useSummarize hook.
|
|
9
|
+
*
|
|
10
|
+
* @template TOutput - The transformed output type (defaults to SummarizationResult)
|
|
11
|
+
*/
|
|
12
|
+
interface UseSummarizeOptions<TOutput = SummarizationResult> {
|
|
13
|
+
/** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
|
|
14
|
+
connection?: ConnectionAdapter;
|
|
15
|
+
/** Direct async function for summarization */
|
|
16
|
+
fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>;
|
|
17
|
+
/** Unique identifier for this generation instance */
|
|
18
|
+
id?: string;
|
|
19
|
+
/** Additional body parameters to send with ConnectionAdapter requests */
|
|
20
|
+
body?: Record<string, any>;
|
|
21
|
+
/**
|
|
22
|
+
* Callback when summarization is complete. Can optionally return a transformed value.
|
|
23
|
+
*
|
|
24
|
+
* - Return a non-null value to transform and store it as the result
|
|
25
|
+
* - Return `null` to keep the previous result unchanged
|
|
26
|
+
* - Return nothing (`void`) to store the raw result as-is
|
|
27
|
+
*/
|
|
28
|
+
onResult?: (result: SummarizationResult) => TOutput | null | void;
|
|
29
|
+
/** Callback when an error occurs */
|
|
30
|
+
onError?: (error: Error) => void;
|
|
31
|
+
/** Callback when progress is reported (0-100) */
|
|
32
|
+
onProgress?: (progress: number, message?: string) => void;
|
|
33
|
+
/** Callback for each stream chunk (ConnectionAdapter mode only) */
|
|
34
|
+
onChunk?: (chunk: StreamChunk) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Return type for the useSummarize hook.
|
|
38
|
+
*
|
|
39
|
+
* @template TOutput - The transformed output type (defaults to SummarizationResult)
|
|
40
|
+
*/
|
|
41
|
+
interface UseSummarizeReturn<TOutput = SummarizationResult> {
|
|
42
|
+
/** Trigger summarization */
|
|
43
|
+
generate: (input: SummarizeGenerateInput) => Promise<void>;
|
|
44
|
+
/** The summarization result, or null */
|
|
45
|
+
result: Accessor<TOutput | null>;
|
|
46
|
+
/** Whether summarization is in progress */
|
|
47
|
+
isLoading: Accessor<boolean>;
|
|
48
|
+
/** Current error, if any */
|
|
49
|
+
error: Accessor<Error | undefined>;
|
|
50
|
+
/** Current state of the generation */
|
|
51
|
+
status: Accessor<GenerationClientState>;
|
|
52
|
+
/** Abort the current summarization */
|
|
53
|
+
stop: () => void;
|
|
54
|
+
/** Clear result, error, and return to idle */
|
|
55
|
+
reset: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Solid hook for summarizing text using AI models.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* import { useSummarize } from '@tanstack/ai-solid'
|
|
63
|
+
* import { fetchServerSentEvents } from '@tanstack/ai-client'
|
|
64
|
+
*
|
|
65
|
+
* function Summarizer() {
|
|
66
|
+
* const { generate, result, isLoading } = useSummarize({
|
|
67
|
+
* connection: fetchServerSentEvents('/api/summarize'),
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* return (
|
|
71
|
+
* <div>
|
|
72
|
+
* <button onClick={() => generate({
|
|
73
|
+
* text: 'Long article text...',
|
|
74
|
+
* style: 'bullet-points',
|
|
75
|
+
* maxLength: 200,
|
|
76
|
+
* })}>
|
|
77
|
+
* Summarize
|
|
78
|
+
* </button>
|
|
79
|
+
* {isLoading() && <p>Summarizing...</p>}
|
|
80
|
+
* {result() && <p>{result()!.summary}</p>}
|
|
81
|
+
* </div>
|
|
82
|
+
* )
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function useSummarize<TOnResult extends ((result: SummarizationResult) => any) | undefined = undefined>(options: Omit<UseSummarizeOptions, 'onResult'> & {
|
|
87
|
+
onResult?: TOnResult;
|
|
88
|
+
}): UseSummarizeReturn<InferGenerationOutput<SummarizationResult, TOnResult>>;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { UseSummarizeOptions, UseSummarizeReturn, useSummarize };
|
|
91
|
+
//# sourceMappingURL=use-summarize.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useGeneration } from "./use-generation.js";
|
|
2
|
+
|
|
3
|
+
//#region src/use-summarize.ts
|
|
4
|
+
/**
|
|
5
|
+
* Solid hook for summarizing text using AI models.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useSummarize } from '@tanstack/ai-solid'
|
|
10
|
+
* import { fetchServerSentEvents } from '@tanstack/ai-client'
|
|
11
|
+
*
|
|
12
|
+
* function Summarizer() {
|
|
13
|
+
* const { generate, result, isLoading } = useSummarize({
|
|
14
|
+
* connection: fetchServerSentEvents('/api/summarize'),
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <div>
|
|
19
|
+
* <button onClick={() => generate({
|
|
20
|
+
* text: 'Long article text...',
|
|
21
|
+
* style: 'bullet-points',
|
|
22
|
+
* maxLength: 200,
|
|
23
|
+
* })}>
|
|
24
|
+
* Summarize
|
|
25
|
+
* </button>
|
|
26
|
+
* {isLoading() && <p>Summarizing...</p>}
|
|
27
|
+
* {result() && <p>{result()!.summary}</p>}
|
|
28
|
+
* </div>
|
|
29
|
+
* )
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function useSummarize(options) {
|
|
34
|
+
const { generate, result, isLoading, error, status, stop, reset } = useGeneration(options);
|
|
35
|
+
return {
|
|
36
|
+
generate,
|
|
37
|
+
result,
|
|
38
|
+
isLoading,
|
|
39
|
+
error,
|
|
40
|
+
status,
|
|
41
|
+
stop,
|
|
42
|
+
reset
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { useSummarize };
|
|
48
|
+
//# sourceMappingURL=use-summarize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-summarize.js","names":[],"sources":["../src/use-summarize.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, SummarizationResult } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n SummarizeGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useSummarize hook.\n *\n * @template TOutput - The transformed output type (defaults to SummarizationResult)\n */\nexport interface UseSummarizeOptions<TOutput = SummarizationResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for summarization */\n fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\n /**\n * Callback when summarization is complete. 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: SummarizationResult) => 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 (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useSummarize hook.\n *\n * @template TOutput - The transformed output type (defaults to SummarizationResult)\n */\nexport interface UseSummarizeReturn<TOutput = SummarizationResult> {\n /** Trigger summarization */\n generate: (input: SummarizeGenerateInput) => Promise<void>\n /** The summarization result, or null */\n result: Accessor<TOutput | null>\n /** Whether summarization is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current summarization */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for summarizing text using AI models.\n *\n * @example\n * ```tsx\n * import { useSummarize } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function Summarizer() {\n * const { generate, result, isLoading } = useSummarize({\n * connection: fetchServerSentEvents('/api/summarize'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({\n * text: 'Long article text...',\n * style: 'bullet-points',\n * maxLength: 200,\n * })}>\n * Summarize\n * </button>\n * {isLoading() && <p>Summarizing...</p>}\n * {result() && <p>{result()!.summary}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useSummarize<\n TOnResult extends ((result: SummarizationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseSummarizeOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseSummarizeReturn<InferGenerationOutput<SummarizationResult, TOnResult>> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<SummarizeGenerateInput, SummarizationResult, TOnResult>(\n options,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,aAId,SAG2E;CAC3E,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cACE,QACD;AAEH,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, TranscriptionGenerateInput } from "@tanstack/ai-client";
|
|
3
|
+
import { StreamChunk, TranscriptionResult } from "@tanstack/ai";
|
|
4
|
+
|
|
5
|
+
//#region src/use-transcription.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for the useTranscription hook.
|
|
9
|
+
*
|
|
10
|
+
* @template TOutput - The transformed output type (defaults to TranscriptionResult)
|
|
11
|
+
*/
|
|
12
|
+
interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
|
|
13
|
+
/** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
|
|
14
|
+
connection?: ConnectionAdapter;
|
|
15
|
+
/** Direct async function for transcription */
|
|
16
|
+
fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>;
|
|
17
|
+
/** Unique identifier for this generation instance */
|
|
18
|
+
id?: string;
|
|
19
|
+
/** Additional body parameters to send with ConnectionAdapter requests */
|
|
20
|
+
body?: Record<string, any>;
|
|
21
|
+
/**
|
|
22
|
+
* Callback when transcription is complete. Can optionally return a transformed value.
|
|
23
|
+
*
|
|
24
|
+
* - Return a non-null value to transform and store it as the result
|
|
25
|
+
* - Return `null` to keep the previous result unchanged
|
|
26
|
+
* - Return nothing (`void`) to store the raw result as-is
|
|
27
|
+
*/
|
|
28
|
+
onResult?: (result: TranscriptionResult) => TOutput | null | void;
|
|
29
|
+
/** Callback when an error occurs */
|
|
30
|
+
onError?: (error: Error) => void;
|
|
31
|
+
/** Callback when progress is reported (0-100) */
|
|
32
|
+
onProgress?: (progress: number, message?: string) => void;
|
|
33
|
+
/** Callback for each stream chunk (ConnectionAdapter mode only) */
|
|
34
|
+
onChunk?: (chunk: StreamChunk) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Return type for the useTranscription hook.
|
|
38
|
+
*
|
|
39
|
+
* @template TOutput - The transformed output type (defaults to TranscriptionResult)
|
|
40
|
+
*/
|
|
41
|
+
interface UseTranscriptionReturn<TOutput = TranscriptionResult> {
|
|
42
|
+
/** Trigger transcription */
|
|
43
|
+
generate: (input: TranscriptionGenerateInput) => Promise<void>;
|
|
44
|
+
/** The transcription result, or null */
|
|
45
|
+
result: Accessor<TOutput | null>;
|
|
46
|
+
/** Whether transcription is in progress */
|
|
47
|
+
isLoading: Accessor<boolean>;
|
|
48
|
+
/** Current error, if any */
|
|
49
|
+
error: Accessor<Error | undefined>;
|
|
50
|
+
/** Current state of the generation */
|
|
51
|
+
status: Accessor<GenerationClientState>;
|
|
52
|
+
/** Abort the current transcription */
|
|
53
|
+
stop: () => void;
|
|
54
|
+
/** Clear result, error, and return to idle */
|
|
55
|
+
reset: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Solid hook for transcribing audio to text using AI models.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* import { useTranscription } from '@tanstack/ai-solid'
|
|
63
|
+
* import { fetchServerSentEvents } from '@tanstack/ai-client'
|
|
64
|
+
*
|
|
65
|
+
* function Transcriber() {
|
|
66
|
+
* const { generate, result, isLoading } = useTranscription({
|
|
67
|
+
* connection: fetchServerSentEvents('/api/transcribe'),
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* const handleFile = (e: Event) => {
|
|
71
|
+
* const input = e.target as HTMLInputElement
|
|
72
|
+
* const file = input.files?.[0]
|
|
73
|
+
* if (file) {
|
|
74
|
+
* const reader = new FileReader()
|
|
75
|
+
* reader.onload = () => {
|
|
76
|
+
* generate({ audio: reader.result as string, language: 'en' })
|
|
77
|
+
* }
|
|
78
|
+
* reader.readAsDataURL(file)
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* return (
|
|
83
|
+
* <div>
|
|
84
|
+
* <input type="file" accept="audio/*" onChange={handleFile} />
|
|
85
|
+
* {isLoading() && <p>Transcribing...</p>}
|
|
86
|
+
* {result() && <p>{result()!.text}</p>}
|
|
87
|
+
* </div>
|
|
88
|
+
* )
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function useTranscription<TOnResult extends ((result: TranscriptionResult) => any) | undefined = undefined>(options: Omit<UseTranscriptionOptions, 'onResult'> & {
|
|
93
|
+
onResult?: TOnResult;
|
|
94
|
+
}): UseTranscriptionReturn<InferGenerationOutput<TranscriptionResult, TOnResult>>;
|
|
95
|
+
//#endregion
|
|
96
|
+
export { UseTranscriptionOptions, UseTranscriptionReturn, useTranscription };
|
|
97
|
+
//# sourceMappingURL=use-transcription.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useGeneration } from "./use-generation.js";
|
|
2
|
+
|
|
3
|
+
//#region src/use-transcription.ts
|
|
4
|
+
/**
|
|
5
|
+
* Solid hook for transcribing audio to text using AI models.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useTranscription } from '@tanstack/ai-solid'
|
|
10
|
+
* import { fetchServerSentEvents } from '@tanstack/ai-client'
|
|
11
|
+
*
|
|
12
|
+
* function Transcriber() {
|
|
13
|
+
* const { generate, result, isLoading } = useTranscription({
|
|
14
|
+
* connection: fetchServerSentEvents('/api/transcribe'),
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* const handleFile = (e: Event) => {
|
|
18
|
+
* const input = e.target as HTMLInputElement
|
|
19
|
+
* const file = input.files?.[0]
|
|
20
|
+
* if (file) {
|
|
21
|
+
* const reader = new FileReader()
|
|
22
|
+
* reader.onload = () => {
|
|
23
|
+
* generate({ audio: reader.result as string, language: 'en' })
|
|
24
|
+
* }
|
|
25
|
+
* reader.readAsDataURL(file)
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* return (
|
|
30
|
+
* <div>
|
|
31
|
+
* <input type="file" accept="audio/*" onChange={handleFile} />
|
|
32
|
+
* {isLoading() && <p>Transcribing...</p>}
|
|
33
|
+
* {result() && <p>{result()!.text}</p>}
|
|
34
|
+
* </div>
|
|
35
|
+
* )
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function useTranscription(options) {
|
|
40
|
+
const { generate, result, isLoading, error, status, stop, reset } = useGeneration(options);
|
|
41
|
+
return {
|
|
42
|
+
generate,
|
|
43
|
+
result,
|
|
44
|
+
isLoading,
|
|
45
|
+
error,
|
|
46
|
+
status,
|
|
47
|
+
stop,
|
|
48
|
+
reset
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { useTranscription };
|
|
54
|
+
//# sourceMappingURL=use-transcription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-transcription.js","names":[],"sources":["../src/use-transcription.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, TranscriptionResult } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n TranscriptionGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useTranscription hook.\n *\n * @template TOutput - The transformed output type (defaults to TranscriptionResult)\n */\nexport interface UseTranscriptionOptions<TOutput = TranscriptionResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for transcription */\n fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\n /**\n * Callback when transcription is complete. 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: TranscriptionResult) => 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 (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useTranscription hook.\n *\n * @template TOutput - The transformed output type (defaults to TranscriptionResult)\n */\nexport interface UseTranscriptionReturn<TOutput = TranscriptionResult> {\n /** Trigger transcription */\n generate: (input: TranscriptionGenerateInput) => Promise<void>\n /** The transcription result, or null */\n result: Accessor<TOutput | null>\n /** Whether transcription is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current transcription */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for transcribing audio to text using AI models.\n *\n * @example\n * ```tsx\n * import { useTranscription } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function Transcriber() {\n * const { generate, result, isLoading } = useTranscription({\n * connection: fetchServerSentEvents('/api/transcribe'),\n * })\n *\n * const handleFile = (e: Event) => {\n * const input = e.target as HTMLInputElement\n * const file = input.files?.[0]\n * if (file) {\n * const reader = new FileReader()\n * reader.onload = () => {\n * generate({ audio: reader.result as string, language: 'en' })\n * }\n * reader.readAsDataURL(file)\n * }\n * }\n *\n * return (\n * <div>\n * <input type=\"file\" accept=\"audio/*\" onChange={handleFile} />\n * {isLoading() && <p>Transcribing...</p>}\n * {result() && <p>{result()!.text}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useTranscription<\n TOnResult extends ((result: TranscriptionResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseTranscriptionOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseTranscriptionReturn<\n InferGenerationOutput<TranscriptionResult, TOnResult>\n> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<TranscriptionGenerateInput, TranscriptionResult, TOnResult>(\n options,\n )\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,iBAId,SAKA;CACA,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cACE,QACD;AAEH,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-solid",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Solid hooks for TanStack AI",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"streaming"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tanstack/ai-client": "0.
|
|
34
|
+
"@tanstack/ai-client": "0.6.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"solid-js": ">=1.9.10",
|
|
38
|
-
"@tanstack/ai": "^0.6.
|
|
38
|
+
"@tanstack/ai": "^0.6.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@solidjs/testing-library": "^0.8.10",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"tsdown": "^0.17.0-beta.6",
|
|
47
47
|
"typescript": "5.9.3",
|
|
48
48
|
"vitest": "^4.0.14",
|
|
49
|
-
"@tanstack/ai": "0.6.
|
|
49
|
+
"@tanstack/ai": "0.6.3"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"clean": "premove ./build ./dist",
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,40 @@ export type {
|
|
|
6
6
|
ChatRequestBody,
|
|
7
7
|
} from './types'
|
|
8
8
|
|
|
9
|
+
// Generation hooks
|
|
10
|
+
export { useGeneration } from './use-generation'
|
|
11
|
+
export type {
|
|
12
|
+
UseGenerationOptions,
|
|
13
|
+
UseGenerationReturn,
|
|
14
|
+
} from './use-generation'
|
|
15
|
+
|
|
16
|
+
export { useGenerateImage } from './use-generate-image'
|
|
17
|
+
export type {
|
|
18
|
+
UseGenerateImageOptions,
|
|
19
|
+
UseGenerateImageReturn,
|
|
20
|
+
} from './use-generate-image'
|
|
21
|
+
|
|
22
|
+
export { useGenerateSpeech } from './use-generate-speech'
|
|
23
|
+
export type {
|
|
24
|
+
UseGenerateSpeechOptions,
|
|
25
|
+
UseGenerateSpeechReturn,
|
|
26
|
+
} from './use-generate-speech'
|
|
27
|
+
|
|
28
|
+
export { useTranscription } from './use-transcription'
|
|
29
|
+
export type {
|
|
30
|
+
UseTranscriptionOptions,
|
|
31
|
+
UseTranscriptionReturn,
|
|
32
|
+
} from './use-transcription'
|
|
33
|
+
|
|
34
|
+
export { useSummarize } from './use-summarize'
|
|
35
|
+
export type { UseSummarizeOptions, UseSummarizeReturn } from './use-summarize'
|
|
36
|
+
|
|
37
|
+
export { useGenerateVideo } from './use-generate-video'
|
|
38
|
+
export type {
|
|
39
|
+
UseGenerateVideoOptions,
|
|
40
|
+
UseGenerateVideoReturn,
|
|
41
|
+
} from './use-generate-video'
|
|
42
|
+
|
|
9
43
|
// Re-export from ai-client for convenience
|
|
10
44
|
export {
|
|
11
45
|
fetchServerSentEvents,
|
|
@@ -15,4 +49,12 @@ export {
|
|
|
15
49
|
type ConnectionAdapter,
|
|
16
50
|
type FetchConnectionOptions,
|
|
17
51
|
type InferChatMessages,
|
|
52
|
+
type GenerationClientState,
|
|
53
|
+
type ImageGenerateInput,
|
|
54
|
+
type SpeechGenerateInput,
|
|
55
|
+
type TranscriptionGenerateInput,
|
|
56
|
+
type SummarizeGenerateInput,
|
|
57
|
+
type VideoGenerateInput,
|
|
58
|
+
type VideoGenerateResult,
|
|
59
|
+
type VideoStatusInfo,
|
|
18
60
|
} from '@tanstack/ai-client'
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useGeneration } from './use-generation'
|
|
2
|
+
import type { ImageGenerationResult, StreamChunk } from '@tanstack/ai'
|
|
3
|
+
import type {
|
|
4
|
+
ConnectionAdapter,
|
|
5
|
+
GenerationClientState,
|
|
6
|
+
GenerationFetcher,
|
|
7
|
+
ImageGenerateInput,
|
|
8
|
+
InferGenerationOutput,
|
|
9
|
+
} from '@tanstack/ai-client'
|
|
10
|
+
import type { Accessor } from 'solid-js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Options for the useGenerateImage hook.
|
|
14
|
+
*
|
|
15
|
+
* @template TOutput - The transformed output type (defaults to ImageGenerationResult)
|
|
16
|
+
*/
|
|
17
|
+
export interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {
|
|
18
|
+
/** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
|
|
19
|
+
connection?: ConnectionAdapter
|
|
20
|
+
/** Direct async function for image generation */
|
|
21
|
+
fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>
|
|
22
|
+
/** Unique identifier for this generation instance */
|
|
23
|
+
id?: string
|
|
24
|
+
/** Additional body parameters to send with ConnectionAdapter requests */
|
|
25
|
+
body?: Record<string, any>
|
|
26
|
+
/**
|
|
27
|
+
* Callback when images are generated. Can optionally return a transformed value.
|
|
28
|
+
*
|
|
29
|
+
* - Return a non-null value to transform and store it as the result
|
|
30
|
+
* - Return `null` to keep the previous result unchanged
|
|
31
|
+
* - Return nothing (`void`) to store the raw result as-is
|
|
32
|
+
*/
|
|
33
|
+
onResult?: (result: ImageGenerationResult) => TOutput | null | void
|
|
34
|
+
/** Callback when an error occurs */
|
|
35
|
+
onError?: (error: Error) => void
|
|
36
|
+
/** Callback when progress is reported (0-100) */
|
|
37
|
+
onProgress?: (progress: number, message?: string) => void
|
|
38
|
+
/** Callback for each stream chunk (ConnectionAdapter mode only) */
|
|
39
|
+
onChunk?: (chunk: StreamChunk) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Return type for the useGenerateImage hook.
|
|
44
|
+
*
|
|
45
|
+
* @template TOutput - The transformed output type (defaults to ImageGenerationResult)
|
|
46
|
+
*/
|
|
47
|
+
export interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {
|
|
48
|
+
/** Trigger image generation */
|
|
49
|
+
generate: (input: ImageGenerateInput) => Promise<void>
|
|
50
|
+
/** The generation result containing images, or null */
|
|
51
|
+
result: Accessor<TOutput | null>
|
|
52
|
+
/** Whether generation is in progress */
|
|
53
|
+
isLoading: Accessor<boolean>
|
|
54
|
+
/** Current error, if any */
|
|
55
|
+
error: Accessor<Error | undefined>
|
|
56
|
+
/** Current state of the generation */
|
|
57
|
+
status: Accessor<GenerationClientState>
|
|
58
|
+
/** Abort the current generation */
|
|
59
|
+
stop: () => void
|
|
60
|
+
/** Clear result, error, and return to idle */
|
|
61
|
+
reset: () => void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Solid hook for generating images using AI models.
|
|
66
|
+
*
|
|
67
|
+
* Supports two transport modes:
|
|
68
|
+
* - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
|
|
69
|
+
* - **Fetcher** -- Direct async function call
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* import { useGenerateImage } from '@tanstack/ai-solid'
|
|
74
|
+
* import { fetchServerSentEvents } from '@tanstack/ai-client'
|
|
75
|
+
*
|
|
76
|
+
* function ImageGenerator() {
|
|
77
|
+
* const { generate, result, isLoading, error, reset } = useGenerateImage({
|
|
78
|
+
* connection: fetchServerSentEvents('/api/generate/image'),
|
|
79
|
+
* })
|
|
80
|
+
*
|
|
81
|
+
* return (
|
|
82
|
+
* <div>
|
|
83
|
+
* <button onClick={() => generate({ prompt: 'A sunset over mountains' })}>
|
|
84
|
+
* Generate
|
|
85
|
+
* </button>
|
|
86
|
+
* {isLoading() && <p>Generating...</p>}
|
|
87
|
+
* {error() && <p>Error: {error()!.message}</p>}
|
|
88
|
+
* {result()?.images.map((img, i) => (
|
|
89
|
+
* <img src={img.url || `data:image/png;base64,${img.b64Json}`} />
|
|
90
|
+
* ))}
|
|
91
|
+
* </div>
|
|
92
|
+
* )
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function useGenerateImage<
|
|
97
|
+
TOnResult extends ((result: ImageGenerationResult) => any) | undefined =
|
|
98
|
+
undefined,
|
|
99
|
+
>(
|
|
100
|
+
options: Omit<UseGenerateImageOptions, 'onResult'> & {
|
|
101
|
+
onResult?: TOnResult
|
|
102
|
+
},
|
|
103
|
+
): UseGenerateImageReturn<
|
|
104
|
+
InferGenerationOutput<ImageGenerationResult, TOnResult>
|
|
105
|
+
> {
|
|
106
|
+
const { generate, result, isLoading, error, status, stop, reset } =
|
|
107
|
+
useGeneration<ImageGenerateInput, ImageGenerationResult, TOnResult>(options)
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
generate: generate as (input: ImageGenerateInput) => Promise<void>,
|
|
111
|
+
result,
|
|
112
|
+
isLoading,
|
|
113
|
+
error,
|
|
114
|
+
status,
|
|
115
|
+
stop,
|
|
116
|
+
reset,
|
|
117
|
+
}
|
|
118
|
+
}
|