@json-render/svelte 0.6.1
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/LICENSE +201 -0
- package/dist/CatalogRenderer.svelte +55 -0
- package/dist/CatalogRenderer.svelte.d.ts +20 -0
- package/dist/CatalogRenderer.svelte.d.ts.map +1 -0
- package/dist/ConfirmDialog.svelte +98 -0
- package/dist/ConfirmDialog.svelte.d.ts +10 -0
- package/dist/ConfirmDialog.svelte.d.ts.map +1 -0
- package/dist/ConfirmDialogManager.svelte +15 -0
- package/dist/ConfirmDialogManager.svelte.d.ts +4 -0
- package/dist/ConfirmDialogManager.svelte.d.ts.map +1 -0
- package/dist/ElementRenderer.svelte +147 -0
- package/dist/ElementRenderer.svelte.d.ts +13 -0
- package/dist/ElementRenderer.svelte.d.ts.map +1 -0
- package/dist/JsonUIProvider.svelte +68 -0
- package/dist/JsonUIProvider.svelte.d.ts +37 -0
- package/dist/JsonUIProvider.svelte.d.ts.map +1 -0
- package/dist/Renderer.svelte +34 -0
- package/dist/Renderer.svelte.d.ts +19 -0
- package/dist/Renderer.svelte.d.ts.map +1 -0
- package/dist/RendererWithProvider.test.svelte +37 -0
- package/dist/RendererWithProvider.test.svelte.d.ts +14 -0
- package/dist/RendererWithProvider.test.svelte.d.ts.map +1 -0
- package/dist/RepeatChildren.svelte +50 -0
- package/dist/RepeatChildren.svelte.d.ts +13 -0
- package/dist/RepeatChildren.svelte.d.ts.map +1 -0
- package/dist/TestButton.svelte +11 -0
- package/dist/TestButton.svelte.d.ts +9 -0
- package/dist/TestButton.svelte.d.ts.map +1 -0
- package/dist/TestContainer.svelte +19 -0
- package/dist/TestContainer.svelte.d.ts +11 -0
- package/dist/TestContainer.svelte.d.ts.map +1 -0
- package/dist/TestText.svelte +9 -0
- package/dist/TestText.svelte.d.ts +9 -0
- package/dist/TestText.svelte.d.ts.map +1 -0
- package/dist/catalog-types.d.ts +63 -0
- package/dist/catalog-types.d.ts.map +1 -0
- package/dist/catalog-types.js +1 -0
- package/dist/contexts/ActionProvider.svelte +344 -0
- package/dist/contexts/ActionProvider.svelte.d.ts +62 -0
- package/dist/contexts/ActionProvider.svelte.d.ts.map +1 -0
- package/dist/contexts/FunctionsContextProvider.svelte +44 -0
- package/dist/contexts/FunctionsContextProvider.svelte.d.ts +21 -0
- package/dist/contexts/FunctionsContextProvider.svelte.d.ts.map +1 -0
- package/dist/contexts/RepeatScopeProvider.svelte +49 -0
- package/dist/contexts/RepeatScopeProvider.svelte.d.ts +26 -0
- package/dist/contexts/RepeatScopeProvider.svelte.d.ts.map +1 -0
- package/dist/contexts/StateProvider.svelte +182 -0
- package/dist/contexts/StateProvider.svelte.d.ts +47 -0
- package/dist/contexts/StateProvider.svelte.d.ts.map +1 -0
- package/dist/contexts/ValidationProvider.svelte +198 -0
- package/dist/contexts/ValidationProvider.svelte.d.ts +57 -0
- package/dist/contexts/ValidationProvider.svelte.d.ts.map +1 -0
- package/dist/contexts/VisibilityProvider.svelte +82 -0
- package/dist/contexts/VisibilityProvider.svelte.d.ts +29 -0
- package/dist/contexts/VisibilityProvider.svelte.d.ts.map +1 -0
- package/dist/contexts/actions.test.js +156 -0
- package/dist/contexts/state.test.js +118 -0
- package/dist/contexts/visibility.test.js +71 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/renderer.d.ts +128 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +124 -0
- package/dist/renderer.test.js +168 -0
- package/dist/schema.d.ts +57 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +81 -0
- package/dist/streaming.svelte.d.ts +75 -0
- package/dist/streaming.svelte.d.ts.map +1 -0
- package/dist/streaming.svelte.js +404 -0
- package/dist/utils.svelte.d.ts +26 -0
- package/dist/utils.svelte.d.ts.map +1 -0
- package/dist/utils.svelte.js +92 -0
- package/dist/utils.test.js +307 -0
- package/package.json +70 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
+
import { render, cleanup } from "@testing-library/svelte";
|
|
3
|
+
import RendererWithProvider from "./RendererWithProvider.test.svelte";
|
|
4
|
+
import TestContainer from "./TestContainer.svelte";
|
|
5
|
+
import TestText from "./TestText.svelte";
|
|
6
|
+
import TestButton from "./TestButton.svelte";
|
|
7
|
+
import { defineRegistry } from "./renderer.js";
|
|
8
|
+
describe("Renderer", () => {
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
cleanup();
|
|
11
|
+
});
|
|
12
|
+
const { registry } = defineRegistry(null, {
|
|
13
|
+
components: {
|
|
14
|
+
Container: TestContainer,
|
|
15
|
+
Text: TestText,
|
|
16
|
+
Button: TestButton,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
function mountRenderer(spec, options = {}) {
|
|
20
|
+
return render(RendererWithProvider, {
|
|
21
|
+
props: {
|
|
22
|
+
spec,
|
|
23
|
+
registry,
|
|
24
|
+
loading: options.loading ?? false,
|
|
25
|
+
initialState: spec?.state ?? {},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
it("renders nothing for null spec", () => {
|
|
30
|
+
const { container } = mountRenderer(null);
|
|
31
|
+
// Should have no content rendered from Renderer
|
|
32
|
+
expect(container.querySelector(".test-container")).toBeNull();
|
|
33
|
+
expect(container.querySelector(".test-text")).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
it("renders nothing for spec with empty root", () => {
|
|
36
|
+
const spec = { root: "", elements: {} };
|
|
37
|
+
const { container } = mountRenderer(spec);
|
|
38
|
+
expect(container.querySelector(".test-container")).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
it("renders a single element", () => {
|
|
41
|
+
const spec = {
|
|
42
|
+
root: "text1",
|
|
43
|
+
elements: {
|
|
44
|
+
text1: {
|
|
45
|
+
type: "Text",
|
|
46
|
+
props: { text: "Hello World" },
|
|
47
|
+
children: [],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const { container } = mountRenderer(spec);
|
|
52
|
+
const textEl = container.querySelector(".test-text");
|
|
53
|
+
expect(textEl).not.toBeNull();
|
|
54
|
+
expect(textEl?.textContent).toBe("Hello World");
|
|
55
|
+
});
|
|
56
|
+
it("renders nested elements", () => {
|
|
57
|
+
const spec = {
|
|
58
|
+
root: "container",
|
|
59
|
+
elements: {
|
|
60
|
+
container: {
|
|
61
|
+
type: "Container",
|
|
62
|
+
props: { title: "My Container" },
|
|
63
|
+
children: ["text1", "text2"],
|
|
64
|
+
},
|
|
65
|
+
text1: {
|
|
66
|
+
type: "Text",
|
|
67
|
+
props: { text: "First" },
|
|
68
|
+
children: [],
|
|
69
|
+
},
|
|
70
|
+
text2: {
|
|
71
|
+
type: "Text",
|
|
72
|
+
props: { text: "Second" },
|
|
73
|
+
children: [],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const { container } = mountRenderer(spec);
|
|
78
|
+
const containerEl = container.querySelector(".test-container");
|
|
79
|
+
expect(containerEl).not.toBeNull();
|
|
80
|
+
expect(containerEl?.querySelector("h2")?.textContent).toBe("My Container");
|
|
81
|
+
const texts = container.querySelectorAll(".test-text");
|
|
82
|
+
expect(texts).toHaveLength(2);
|
|
83
|
+
expect(texts[0]?.textContent).toBe("First");
|
|
84
|
+
expect(texts[1]?.textContent).toBe("Second");
|
|
85
|
+
});
|
|
86
|
+
it("renders deeply nested elements", () => {
|
|
87
|
+
const spec = {
|
|
88
|
+
root: "outer",
|
|
89
|
+
elements: {
|
|
90
|
+
outer: {
|
|
91
|
+
type: "Container",
|
|
92
|
+
props: { title: "Outer" },
|
|
93
|
+
children: ["inner"],
|
|
94
|
+
},
|
|
95
|
+
inner: {
|
|
96
|
+
type: "Container",
|
|
97
|
+
props: { title: "Inner" },
|
|
98
|
+
children: ["text"],
|
|
99
|
+
},
|
|
100
|
+
text: {
|
|
101
|
+
type: "Text",
|
|
102
|
+
props: { text: "Deep text" },
|
|
103
|
+
children: [],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const { container } = mountRenderer(spec);
|
|
108
|
+
const containers = container.querySelectorAll(".test-container");
|
|
109
|
+
expect(containers).toHaveLength(2);
|
|
110
|
+
const text = container.querySelector(".test-text");
|
|
111
|
+
expect(text?.textContent).toBe("Deep text");
|
|
112
|
+
});
|
|
113
|
+
it("passes loading prop to components", () => {
|
|
114
|
+
const spec = {
|
|
115
|
+
root: "container",
|
|
116
|
+
elements: {
|
|
117
|
+
container: {
|
|
118
|
+
type: "Container",
|
|
119
|
+
props: {},
|
|
120
|
+
children: [],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const { container } = mountRenderer(spec, { loading: true });
|
|
125
|
+
const containerEl = container.querySelector(".test-container");
|
|
126
|
+
expect(containerEl?.getAttribute("data-loading")).toBe("true");
|
|
127
|
+
});
|
|
128
|
+
it("renders nothing for unknown component types without fallback", () => {
|
|
129
|
+
const spec = {
|
|
130
|
+
root: "unknown",
|
|
131
|
+
elements: {
|
|
132
|
+
unknown: {
|
|
133
|
+
type: "UnknownType",
|
|
134
|
+
props: {},
|
|
135
|
+
children: [],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const { container } = mountRenderer(spec);
|
|
140
|
+
// No elements should be rendered for unknown type
|
|
141
|
+
expect(container.querySelector(".test-container")).toBeNull();
|
|
142
|
+
expect(container.querySelector(".test-text")).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
it("skips missing child elements gracefully", () => {
|
|
145
|
+
const spec = {
|
|
146
|
+
root: "container",
|
|
147
|
+
elements: {
|
|
148
|
+
container: {
|
|
149
|
+
type: "Container",
|
|
150
|
+
props: { title: "Parent" },
|
|
151
|
+
children: ["existing", "missing"],
|
|
152
|
+
},
|
|
153
|
+
existing: {
|
|
154
|
+
type: "Text",
|
|
155
|
+
props: { text: "I exist" },
|
|
156
|
+
children: [],
|
|
157
|
+
},
|
|
158
|
+
// "missing" element is not defined
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
const { container } = mountRenderer(spec);
|
|
162
|
+
const containerEl = container.querySelector(".test-container");
|
|
163
|
+
expect(containerEl).not.toBeNull();
|
|
164
|
+
const texts = container.querySelectorAll(".test-text");
|
|
165
|
+
expect(texts).toHaveLength(1);
|
|
166
|
+
expect(texts[0]?.textContent).toBe("I exist");
|
|
167
|
+
});
|
|
168
|
+
});
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema for @json-render/svelte
|
|
3
|
+
*
|
|
4
|
+
* Defines:
|
|
5
|
+
* - Spec: A flat tree of elements with keys, types, props, and children references
|
|
6
|
+
* - Catalog: Components with props schemas, and optional actions
|
|
7
|
+
*/
|
|
8
|
+
export declare const schema: import("@json-render/core").Schema<{
|
|
9
|
+
spec: import("@json-render/core").SchemaType<"object", {
|
|
10
|
+
/** Root element key */
|
|
11
|
+
root: import("@json-render/core").SchemaType<"string", unknown>;
|
|
12
|
+
/** Flat map of elements by key */
|
|
13
|
+
elements: import("@json-render/core").SchemaType<"record", import("@json-render/core").SchemaType<"object", {
|
|
14
|
+
/** Component type from catalog */
|
|
15
|
+
type: import("@json-render/core").SchemaType<"ref", string>;
|
|
16
|
+
/** Component props */
|
|
17
|
+
props: import("@json-render/core").SchemaType<"propsOf", string>;
|
|
18
|
+
/** Child element keys (flat reference) */
|
|
19
|
+
children: import("@json-render/core").SchemaType<"array", import("@json-render/core").SchemaType<"string", unknown>>;
|
|
20
|
+
/** Visibility condition */
|
|
21
|
+
visible: import("@json-render/core").SchemaType<"any", unknown>;
|
|
22
|
+
}>>;
|
|
23
|
+
}>;
|
|
24
|
+
catalog: import("@json-render/core").SchemaType<"object", {
|
|
25
|
+
/** Component definitions */
|
|
26
|
+
components: import("@json-render/core").SchemaType<"map", {
|
|
27
|
+
/** Zod schema for component props */
|
|
28
|
+
props: import("@json-render/core").SchemaType<"zod", unknown>;
|
|
29
|
+
/** Slots for this component. Use ['default'] for children, or named slots like ['header', 'footer'] */
|
|
30
|
+
slots: import("@json-render/core").SchemaType<"array", import("@json-render/core").SchemaType<"string", unknown>>;
|
|
31
|
+
/** Description for AI generation hints */
|
|
32
|
+
description: import("@json-render/core").SchemaType<"string", unknown>;
|
|
33
|
+
/** Example prop values used in prompt examples (auto-generated from Zod schema if omitted) */
|
|
34
|
+
example: import("@json-render/core").SchemaType<"any", unknown>;
|
|
35
|
+
}>;
|
|
36
|
+
/** Action definitions (optional) */
|
|
37
|
+
actions: import("@json-render/core").SchemaType<"map", {
|
|
38
|
+
/** Zod schema for action params */
|
|
39
|
+
params: import("@json-render/core").SchemaType<"zod", unknown>;
|
|
40
|
+
/** Description for AI generation hints */
|
|
41
|
+
description: import("@json-render/core").SchemaType<"string", unknown>;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Type for the Svelte schema
|
|
47
|
+
*/
|
|
48
|
+
export type SvelteSchema = typeof schema;
|
|
49
|
+
/**
|
|
50
|
+
* Infer the spec type from a catalog
|
|
51
|
+
*/
|
|
52
|
+
export type SvelteSpec<TCatalog> = typeof schema extends {
|
|
53
|
+
createCatalog: (catalog: TCatalog) => {
|
|
54
|
+
_specType: infer S;
|
|
55
|
+
};
|
|
56
|
+
} ? S : never;
|
|
57
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;;QAIb,uBAAuB;;QAEvB,kCAAkC;;YAG9B,kCAAkC;;YAElC,sBAAsB;;YAEtB,0CAA0C;;YAE1C,2BAA2B;;;;;QAQ/B,4BAA4B;;YAE1B,qCAAqC;;YAErC,uGAAuG;;YAEvG,0CAA0C;;YAE1C,8FAA8F;;;QAGhG,oCAAoC;;YAElC,mCAAmC;;YAEnC,0CAA0C;;;;EA+CjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,MAAM,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,IAAI,OAAO,MAAM,SAAS;IACvD,aAAa,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK;QAAE,SAAS,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CAC9D,GACG,CAAC,GACD,KAAK,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { defineSchema } from "@json-render/core";
|
|
2
|
+
/**
|
|
3
|
+
* The schema for @json-render/svelte
|
|
4
|
+
*
|
|
5
|
+
* Defines:
|
|
6
|
+
* - Spec: A flat tree of elements with keys, types, props, and children references
|
|
7
|
+
* - Catalog: Components with props schemas, and optional actions
|
|
8
|
+
*/
|
|
9
|
+
export const schema = defineSchema((s) => ({
|
|
10
|
+
// What the AI-generated SPEC looks like
|
|
11
|
+
spec: s.object({
|
|
12
|
+
/** Root element key */
|
|
13
|
+
root: s.string(),
|
|
14
|
+
/** Flat map of elements by key */
|
|
15
|
+
elements: s.record(s.object({
|
|
16
|
+
/** Component type from catalog */
|
|
17
|
+
type: s.ref("catalog.components"),
|
|
18
|
+
/** Component props */
|
|
19
|
+
props: s.propsOf("catalog.components"),
|
|
20
|
+
/** Child element keys (flat reference) */
|
|
21
|
+
children: s.array(s.string()),
|
|
22
|
+
/** Visibility condition */
|
|
23
|
+
visible: s.any(),
|
|
24
|
+
})),
|
|
25
|
+
}),
|
|
26
|
+
// What the CATALOG must provide
|
|
27
|
+
catalog: s.object({
|
|
28
|
+
/** Component definitions */
|
|
29
|
+
components: s.map({
|
|
30
|
+
/** Zod schema for component props */
|
|
31
|
+
props: s.zod(),
|
|
32
|
+
/** Slots for this component. Use ['default'] for children, or named slots like ['header', 'footer'] */
|
|
33
|
+
slots: s.array(s.string()),
|
|
34
|
+
/** Description for AI generation hints */
|
|
35
|
+
description: s.string(),
|
|
36
|
+
/** Example prop values used in prompt examples (auto-generated from Zod schema if omitted) */
|
|
37
|
+
example: s.any(),
|
|
38
|
+
}),
|
|
39
|
+
/** Action definitions (optional) */
|
|
40
|
+
actions: s.map({
|
|
41
|
+
/** Zod schema for action params */
|
|
42
|
+
params: s.zod(),
|
|
43
|
+
/** Description for AI generation hints */
|
|
44
|
+
description: s.string(),
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
}), {
|
|
48
|
+
builtInActions: [
|
|
49
|
+
{
|
|
50
|
+
name: "setState",
|
|
51
|
+
description: "Update a value in the state model at the given statePath. Params: { statePath: string, value: any }",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "pushState",
|
|
55
|
+
description: 'Append an item to an array in state. Params: { statePath: string, value: any, clearStatePath?: string }. Value can contain {"$state":"/path"} refs and "$id" for auto IDs.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "removeState",
|
|
59
|
+
description: "Remove an item from an array in state by index. Params: { statePath: string, index: number }",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "validateForm",
|
|
63
|
+
description: "Validate all registered form fields and write the result to state. Params: { statePath?: string }. Defaults to /formValidation. Result: { valid: boolean, errors: Record<string, string[]> }.",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
defaultRules: [
|
|
67
|
+
// Element integrity
|
|
68
|
+
"CRITICAL INTEGRITY CHECK: Before outputting ANY element that references children, you MUST have already output (or will output) each child as its own element. If an element has children: ['a', 'b'], then elements 'a' and 'b' MUST exist. A missing child element causes that entire branch of the UI to be invisible.",
|
|
69
|
+
"SELF-CHECK: After generating all elements, mentally walk the tree from root. Every key in every children array must resolve to a defined element. If you find a gap, output the missing element immediately.",
|
|
70
|
+
// Field placement
|
|
71
|
+
'CRITICAL: The "visible" field goes on the ELEMENT object, NOT inside "props". Correct: {"type":"<ComponentName>","props":{},"visible":{"$state":"/tab","eq":"home"},"children":[...]}.',
|
|
72
|
+
'CRITICAL: The "on" field goes on the ELEMENT object, NOT inside "props". Use on.press, on.change, on.submit etc. NEVER put action/actionParams inside props.',
|
|
73
|
+
// State and data
|
|
74
|
+
"When the user asks for a UI that displays data (e.g. blog posts, products, users), ALWAYS include a state field with realistic sample data. The state field is a top-level field on the spec (sibling of root/elements).",
|
|
75
|
+
'When building repeating content backed by a state array (e.g. posts, products, items), use the "repeat" field on a container element. Example: { "type": "<ContainerComponent>", "props": {}, "repeat": { "statePath": "/posts", "key": "id" }, "children": ["post-card"] }. Replace <ContainerComponent> with an appropriate component from the AVAILABLE COMPONENTS list. Inside repeated children, use { "$item": "field" } to read a field from the current item, and { "$index": true } for the current array index. For two-way binding to an item field use { "$bindItem": "completed" }. Do NOT hardcode individual elements for each array item.',
|
|
76
|
+
// Design quality
|
|
77
|
+
"Design with visual hierarchy: use container components to group content, heading components for section titles, proper spacing, and status indicators. ONLY use components from the AVAILABLE COMPONENTS list.",
|
|
78
|
+
"For data-rich UIs, use multi-column layout components if available. For forms and single-column content, use vertical layout components. ONLY use components from the AVAILABLE COMPONENTS list.",
|
|
79
|
+
"Always include realistic, professional-looking sample data. For blogs include 3-4 posts with varied titles, authors, dates, categories. For products include names, prices, images. Never leave data empty.",
|
|
80
|
+
],
|
|
81
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Spec } from "@json-render/core";
|
|
2
|
+
/**
|
|
3
|
+
* Token usage metadata from AI generation
|
|
4
|
+
*/
|
|
5
|
+
export interface TokenUsage {
|
|
6
|
+
promptTokens: number;
|
|
7
|
+
completionTokens: number;
|
|
8
|
+
totalTokens: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* UI Stream state
|
|
12
|
+
*/
|
|
13
|
+
export interface UIStreamState {
|
|
14
|
+
spec: Spec | null;
|
|
15
|
+
isStreaming: boolean;
|
|
16
|
+
error: Error | null;
|
|
17
|
+
usage: TokenUsage | null;
|
|
18
|
+
rawLines: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* UI Stream return type
|
|
22
|
+
*/
|
|
23
|
+
export interface UIStreamReturn {
|
|
24
|
+
readonly spec: Spec | null;
|
|
25
|
+
readonly isStreaming: boolean;
|
|
26
|
+
readonly error: Error | null;
|
|
27
|
+
readonly usage: TokenUsage | null;
|
|
28
|
+
readonly rawLines: string[];
|
|
29
|
+
send: (prompt: string, context?: Record<string, unknown>) => Promise<void>;
|
|
30
|
+
clear: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for createUIStream
|
|
34
|
+
*/
|
|
35
|
+
export interface UIStreamOptions {
|
|
36
|
+
api: string;
|
|
37
|
+
onComplete?: (spec: Spec) => void;
|
|
38
|
+
onError?: (error: Error) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a streaming UI generator using Svelte 5 $state
|
|
42
|
+
*/
|
|
43
|
+
export declare function createUIStream({ api, onComplete, onError, }: UIStreamOptions): UIStreamReturn;
|
|
44
|
+
/**
|
|
45
|
+
* Chat message type
|
|
46
|
+
*/
|
|
47
|
+
export interface ChatMessage {
|
|
48
|
+
id: string;
|
|
49
|
+
role: "user" | "assistant";
|
|
50
|
+
text: string;
|
|
51
|
+
spec: Spec | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Chat UI options
|
|
55
|
+
*/
|
|
56
|
+
export interface ChatUIOptions {
|
|
57
|
+
api: string;
|
|
58
|
+
onComplete?: (message: ChatMessage) => void;
|
|
59
|
+
onError?: (error: Error) => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Chat UI return type
|
|
63
|
+
*/
|
|
64
|
+
export interface ChatUIReturn {
|
|
65
|
+
readonly messages: ChatMessage[];
|
|
66
|
+
readonly isStreaming: boolean;
|
|
67
|
+
readonly error: Error | null;
|
|
68
|
+
send: (text: string) => Promise<void>;
|
|
69
|
+
clear: () => void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a chat UI with streaming support
|
|
73
|
+
*/
|
|
74
|
+
export declare function createChatUI({ api, onComplete, onError, }: ChatUIOptions): ChatUIReturn;
|
|
75
|
+
//# sourceMappingURL=streaming.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.svelte.d.ts","sourceRoot":"","sources":["../src/streaming.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAa,MAAM,mBAAmB,CAAC;AASzD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AA4JD;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAC7B,GAAG,EACH,UAAU,EACV,OAAO,GACR,EAAE,eAAe,GAAG,cAAc,CA+HlC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC5C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAcD;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,UAAU,EACV,OAAO,GACR,EAAE,aAAa,GAAG,YAAY,CA8I9B"}
|