@ai-sdk/svelte 0.0.0-02dba89b-20251009204516
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/CHANGELOG.md +2425 -0
- package/LICENSE +13 -0
- package/README.md +9 -0
- package/dist/chat.svelte.d.ts +6 -0
- package/dist/chat.svelte.d.ts.map +1 -0
- package/dist/chat.svelte.js +30 -0
- package/dist/completion-context.svelte.js +14 -0
- package/dist/completion.svelte.d.ts +30 -0
- package/dist/completion.svelte.d.ts.map +1 -0
- package/dist/completion.svelte.js +93 -0
- package/dist/context-provider.d.ts +2 -0
- package/dist/context-provider.d.ts.map +1 -0
- package/dist/context-provider.js +8 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/structured-object-context.svelte.d.ts +12 -0
- package/dist/structured-object-context.svelte.d.ts.map +1 -0
- package/dist/structured-object-context.svelte.js +12 -0
- package/dist/structured-object.svelte.d.ts +84 -0
- package/dist/structured-object.svelte.d.ts.map +1 -0
- package/dist/structured-object.svelte.js +134 -0
- package/dist/tests/completion-synchronization.svelte +12 -0
- package/dist/tests/completion-synchronization.svelte.d.ts +11 -0
- package/dist/tests/completion-synchronization.svelte.d.ts.map +1 -0
- package/dist/tests/structured-object-synchronization.svelte +22 -0
- package/dist/tests/structured-object-synchronization.svelte.d.ts +28 -0
- package/dist/tests/structured-object-synchronization.svelte.d.ts.map +1 -0
- package/dist/utils.svelte.d.ts +17 -0
- package/dist/utils.svelte.d.ts.map +1 -0
- package/dist/utils.svelte.js +50 -0
- package/package.json +91 -0
- package/src/chat.svelte.ts +51 -0
- package/src/completion-context.svelte.ts +24 -0
- package/src/completion.svelte.ts +116 -0
- package/src/context-provider.ts +16 -0
- package/src/index.ts +7 -0
- package/src/structured-object-context.svelte.ts +27 -0
- package/src/structured-object.svelte.ts +253 -0
- package/src/tests/completion-synchronization.svelte +12 -0
- package/src/tests/structured-object-synchronization.svelte +22 -0
- package/src/utils.svelte.ts +66 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getContext, hasContext, setContext, untrack } from 'svelte';
|
|
2
|
+
import { SvelteMap } from 'svelte/reactivity';
|
|
3
|
+
|
|
4
|
+
export function createContext<T>(name: string) {
|
|
5
|
+
const key = Symbol(name);
|
|
6
|
+
return {
|
|
7
|
+
hasContext: () => {
|
|
8
|
+
// At the time of writing there's no way to determine if we're
|
|
9
|
+
// currently initializing a component without a try-catch
|
|
10
|
+
try {
|
|
11
|
+
return hasContext(key);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (
|
|
14
|
+
typeof e === 'object' &&
|
|
15
|
+
e !== null &&
|
|
16
|
+
'message' in e &&
|
|
17
|
+
typeof e.message === 'string' &&
|
|
18
|
+
e.message?.includes('lifecycle_outside_component')
|
|
19
|
+
) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
getContext: () => getContext<T>(key),
|
|
27
|
+
setContext: (value: T) => setContext(key, value),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function promiseWithResolvers<T>(): {
|
|
32
|
+
promise: Promise<T>;
|
|
33
|
+
resolve: (value: T) => void;
|
|
34
|
+
reject: (reason?: unknown) => void;
|
|
35
|
+
} {
|
|
36
|
+
let resolve: (value: T) => void;
|
|
37
|
+
let reject: (reason?: unknown) => void;
|
|
38
|
+
const promise = new Promise<T>((res, rej) => {
|
|
39
|
+
resolve = res;
|
|
40
|
+
reject = rej;
|
|
41
|
+
});
|
|
42
|
+
return { promise, resolve: resolve!, reject: reject! };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class KeyedStore<T> extends SvelteMap<string, T> {
|
|
46
|
+
#itemConstructor: new () => T;
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
itemConstructor: new () => T,
|
|
50
|
+
value?: Iterable<readonly [string, T]> | null | undefined,
|
|
51
|
+
) {
|
|
52
|
+
super(value);
|
|
53
|
+
this.#itemConstructor = itemConstructor;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get(key: string): T {
|
|
57
|
+
const test =
|
|
58
|
+
super.get(key) ??
|
|
59
|
+
// Untrack here because this is technically a state mutation, meaning
|
|
60
|
+
// deriveds downstream would fail. Because this is idempotent (even
|
|
61
|
+
// though it's not pure), it's safe.
|
|
62
|
+
untrack(() => this.set(key, new this.#itemConstructor())).get(key)!;
|
|
63
|
+
|
|
64
|
+
return test;
|
|
65
|
+
}
|
|
66
|
+
}
|