@ai-sdk/svelte
Version:
[Svelte](https://svelte.dev/) UI components for the [AI SDK](https://ai-sdk.dev/docs):
28 lines (24 loc) • 733 B
text/typescript
import type { DeepPartial } from 'ai';
import { createContext, KeyedStore } from './utils.svelte.js';
export class StructuredObjectStore<RESULT> {
object = $state<DeepPartial<RESULT>>();
loading = $state(false);
error = $state<Error>();
}
export class KeyedStructuredObjectStore extends KeyedStore<
StructuredObjectStore<unknown>
> {
constructor(
value?:
| Iterable<readonly [string, StructuredObjectStore<unknown>]>
| null
| undefined,
) {
super(StructuredObjectStore, value);
}
}
export const {
hasContext: hasStructuredObjectContext,
getContext: getStructuredObjectContext,
setContext: setStructuredObjectContext,
} = createContext<KeyedStructuredObjectStore>('StructuredObject');