@uicast/core 0.0.1-beta.1 → 0.0.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +3 -6
  2. package/README.md +120 -1
  3. package/dist/build-elements-by-key.d.ts +13 -0
  4. package/dist/build-elements-by-key.js +39 -0
  5. package/dist/constants.d.ts +2 -0
  6. package/dist/constants.js +4 -0
  7. package/dist/create-component-definition.d.ts +26 -0
  8. package/dist/create-component-definition.js +74 -0
  9. package/dist/entry-error.d.ts +57 -0
  10. package/dist/entry-error.js +85 -0
  11. package/dist/entry-shape.d.ts +7 -0
  12. package/dist/entry-shape.js +88 -0
  13. package/dist/expr/evaluate.d.ts +5 -0
  14. package/dist/expr/evaluate.js +54 -0
  15. package/dist/expr/extract-deps.d.ts +4 -0
  16. package/dist/expr/extract-deps.js +30 -0
  17. package/dist/expr/plan-step-waves.d.ts +8 -0
  18. package/dist/expr/plan-step-waves.js +45 -0
  19. package/dist/index.d.ts +8 -0
  20. package/dist/index.js +6 -0
  21. package/dist/internal.d.ts +12 -0
  22. package/dist/internal.js +13 -0
  23. package/dist/json-schema.d.ts +58 -0
  24. package/dist/json-schema.js +73 -0
  25. package/dist/prompt/format.d.ts +5 -0
  26. package/dist/prompt/format.js +22 -0
  27. package/dist/prompt/get-common-instructions-partial-prompt.d.ts +23 -0
  28. package/dist/prompt/get-common-instructions-partial-prompt.js +16 -0
  29. package/dist/prompt/get-components-partial-prompt.d.ts +27 -0
  30. package/dist/prompt/get-components-partial-prompt.js +133 -0
  31. package/dist/prompt/get-edit-request-prompt.d.ts +23 -0
  32. package/dist/prompt/get-edit-request-prompt.js +15 -0
  33. package/dist/prompt/get-error-recovery-prompt.d.ts +35 -0
  34. package/dist/prompt/get-error-recovery-prompt.js +26 -0
  35. package/dist/prompt/get-expressions-partial-prompt.d.ts +23 -0
  36. package/dist/prompt/get-expressions-partial-prompt.js +17 -0
  37. package/dist/prompt/get-functions-partial-prompt.d.ts +22 -0
  38. package/dist/prompt/get-functions-partial-prompt.js +58 -0
  39. package/dist/prompt/get-scope-partial-prompt.d.ts +24 -0
  40. package/dist/prompt/get-scope-partial-prompt.js +30 -0
  41. package/dist/prompt/index.d.ts +7 -0
  42. package/dist/prompt/index.js +7 -0
  43. package/dist/prompt/json-schema-to-ts.d.ts +6 -0
  44. package/dist/prompt/json-schema-to-ts.js +146 -0
  45. package/dist/prompt/md/EXPRESSIONS.json +1 -0
  46. package/dist/prompt/md/INSTRUCTIONS.json +1 -0
  47. package/dist/prompt/shared-types.d.ts +5 -0
  48. package/dist/prompt/shared-types.js +82 -0
  49. package/dist/scope/create-proxy-scope.d.ts +55 -0
  50. package/dist/scope/create-proxy-scope.js +295 -0
  51. package/dist/scope/parse-scope.d.ts +2 -0
  52. package/dist/scope/parse-scope.js +11 -0
  53. package/dist/scope/parse-set-address.d.ts +16 -0
  54. package/dist/scope/parse-set-address.js +52 -0
  55. package/dist/stream-json-lines.d.ts +14 -0
  56. package/dist/stream-json-lines.js +59 -0
  57. package/dist/types.d.ts +124 -0
  58. package/dist/types.js +19 -0
  59. package/dist/url-policy.d.ts +45 -0
  60. package/dist/url-policy.js +252 -0
  61. package/package.json +27 -18
  62. package/src/def/create-component-definition.ts +0 -21
  63. package/src/entry-error.ts +0 -104
  64. package/src/expr/analyze.ts +0 -190
  65. package/src/expr/ast-utils.ts +0 -28
  66. package/src/expr/evaluate.ts +0 -74
  67. package/src/expr/extract-deps.ts +0 -32
  68. package/src/expr/globals.ts +0 -118
  69. package/src/expr/safer-eval.ts +0 -233
  70. package/src/expr/validate.ts +0 -149
  71. package/src/index.ts +0 -28
  72. package/src/prompt/get-common-instructions-partial-prompt.ts +0 -20
  73. package/src/prompt/get-components-partial-prompt.ts +0 -153
  74. package/src/prompt/get-edit-request-prompt.ts +0 -37
  75. package/src/prompt/get-error-recovery-prompt.ts +0 -37
  76. package/src/prompt/get-expressions-partial-prompt.ts +0 -33
  77. package/src/prompt/get-functions-partial-prompt.ts +0 -62
  78. package/src/prompt/get-scope-partial-prompt.ts +0 -57
  79. package/src/prompt/index.ts +0 -32
  80. package/src/prompt/md/EXPRESSIONS.json +0 -1
  81. package/src/prompt/md/EXPRESSIONS.md +0 -29
  82. package/src/prompt/md/INSTRUCTIONS.json +0 -1
  83. package/src/prompt/md/INSTRUCTIONS.md +0 -172
  84. package/src/prompt-utils/json-schema-to-ts.ts +0 -225
  85. package/src/scope/create-proxy-scope.ts +0 -131
  86. package/src/scope/parse-scope.ts +0 -36
  87. package/src/stream/stream-json-lines.ts +0 -56
  88. package/src/types.ts +0 -124
  89. package/src/utils/utils.ts +0 -64
package/src/types.ts DELETED
@@ -1,124 +0,0 @@
1
- import type {
2
- StandardJSONSchemaV1,
3
- StandardSchemaV1,
4
- } from "@standard-schema/spec";
5
-
6
- // A bare JavaScript expression string, always evaluated as code (no literal
7
- // form). Used by `hidden` and `each`.
8
- export type Expression = string;
9
-
10
- // A dotted path into the reactive `scopes` store — the write target of an
11
- // assignment, e.g. `"scopes.root.users"`. Logically just a string; the alias
12
- // documents intent (mirrors `Expression`). Used by the `set` field below.
13
- export type ScopePath = string;
14
-
15
- // A value: `literal` is any JSON value used as-is (no evaluation); `expr` is
16
- // evaluated as code.
17
- export type ValueSource = { expr: Expression } | { literal: unknown };
18
- export type ValueSourceAssignment = { set: ScopePath } & ValueSource;
19
- export type ConfirmableValueSourceAssignment = {
20
- confirm?: string;
21
- } & ValueSourceAssignment;
22
-
23
- /**
24
- * The uicast entry model. One line of a uicast document is a
25
- * `ComponentEntry`. A `ComponentListEntry` is an entry that repeats: it carries
26
- * `each` (the array to iterate) plus `as` and an optional `keyBy`.
27
- *
28
- * There is no separate "plain entry" type and no
29
- * `ComponentEntry | ComponentListEntry` union: the list fields (`each`, `as`,
30
- * `keyBy`) live on `ComponentEntry` as optional, so one type describes every
31
- * line and a heterogeneous `ComponentEntry[]` can hold list lines directly.
32
- * `ComponentListEntry` is the same shape with `each`/`as` required — narrow
33
- * `ComponentEntry` → `ComponentListEntry` with `isComponentListEntry` (presence
34
- * of `each`).
35
- */
36
- export interface ComponentEntry {
37
- key: string;
38
- component: string;
39
- props?: ValueSource;
40
- seed?: ValueSourceAssignment[];
41
- hidden?: Expression;
42
- callbacks?: Record<string, ConfirmableValueSourceAssignment[]>;
43
- children?: string[];
44
- // List fields — present only when the entry repeats (`each` is the marker).
45
- // Optional here so a heterogeneous `ComponentEntry[]` can hold list lines
46
- // directly; `ComponentListEntry` below is the same shape with `each`/`as`
47
- // required.
48
- each?: Expression;
49
- as?: string;
50
- keyBy?: (string & {}) | "_index" | "_item";
51
- }
52
-
53
- /**
54
- * A list entry repeats — the same shape as `ComponentEntry` with the iteration
55
- * fields required. `each` is the structural marker (its presence is what makes
56
- * an entry a list); `as` names the per-item scope.
57
- */
58
- export interface ComponentListEntry extends ComponentEntry {
59
- each: Expression;
60
- as: string;
61
- }
62
-
63
- /**
64
- * Narrow a `ComponentEntry` to a `ComponentListEntry`. List-ness is the
65
- * presence of `each` — there is no `kind` discriminator, exactly like root-ness
66
- * (derived from an entry being referenced by no other entry's `children`).
67
- */
68
- export function isComponentListEntry(
69
- entry: ComponentEntry,
70
- ): entry is ComponentListEntry {
71
- return entry.each !== undefined;
72
- }
73
-
74
- /**
75
- * Narrow an untrusted parsed value to a `ComponentEntry` — the shape guard for
76
- * model-emitted lines (`streamJsonLines` output, fence bodies, stored JSONL).
77
- */
78
- export function isComponentEntry(value: unknown): value is ComponentEntry {
79
- if (!value || typeof value !== "object") return false;
80
- const entry = value as ComponentEntry;
81
- return (
82
- typeof entry.key === "string" &&
83
- typeof entry.component === "string" &&
84
- // The least-trusted input path: `children` as a string (a plausible LLM
85
- // slip) would be iterated char-by-char downstream into phantom child slots.
86
- (entry.children === undefined || Array.isArray(entry.children))
87
- );
88
- }
89
-
90
- /**
91
- * An interface that combines StandardJSONSchema and StandardSchema.
92
- * */
93
- export type CombinedSpec<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> &
94
- StandardJSONSchemaV1<Input, Output>;
95
-
96
- /**
97
- * The partner module the LLM reads for a component: a props spec plus optional
98
- * callback specs (its `description` + `props` schema are serialized into the
99
- * prompt). Parameterized over the concrete `props` / `callbacks` specs so an
100
- * implementation can recover their exact types — `createComponentImplementation`
101
- * infers `TProps` / `TCallbacks` straight off the `def` it's handed to type its
102
- * `render` callback. Both params default to the widened base, so a bare
103
- * `ComponentDefinition` is the heterogeneous form used in collections
104
- * (`ComponentDefinition[]`, the `allDefinitions` registry, the prompt
105
- * serializer). The `createComponentDefinition` factory (in
106
- * `def/create-component-definition.ts`) is the value-side constructor for this.
107
- */
108
- export type ComponentDefinition<
109
- TProps extends CombinedSpec = CombinedSpec,
110
- TCallbacks extends Record<string, CombinedSpec> = Record<string, CombinedSpec>,
111
- > = {
112
- name: string;
113
- description: string;
114
- props: TProps;
115
- callbacks?: TCallbacks;
116
- /**
117
- * Host-only component. Registered in the renderer registry so entries
118
- * referencing it mount correctly, but filtered out of the LLM-facing
119
- * prompt list in `getComponentsPartialPrompt`. Use for internal infrastructure
120
- * (e.g. RootFragment — the synthetic wrapper used by `Renderer`'s `init`
121
- * prop machinery) that the LLM should never emit.
122
- */
123
- hidden?: boolean;
124
- };
@@ -1,64 +0,0 @@
1
- import type { ComponentEntry } from "../types";
2
-
3
- /**
4
- * Collect all descendant IDs of a given entry (not including the entry itself)
5
- * by walking its children array recursively.
6
- */
7
- function collectDescendantIds(
8
- id: string,
9
- map: Record<string, ComponentEntry>,
10
- ): Set<string> {
11
- const result = new Set<string>();
12
- const stack = [id];
13
- while (stack.length > 0) {
14
- const current = stack.pop()!;
15
- const entry = map[current];
16
- if (entry?.children) {
17
- for (const childId of entry.children) {
18
- if (!result.has(childId)) {
19
- result.add(childId);
20
- stack.push(childId);
21
- }
22
- }
23
- }
24
- }
25
- return result;
26
- }
27
-
28
- /**
29
- * Build an elements-by-key map from the NDJSON lines array.
30
- *
31
- * When an entry with a duplicate key is encountered (i.e. the LLM re-emits a
32
- * entry to correct a mistake), the old subtree is removed before inserting
33
- * the replacement — except old nodes the new `children` array still
34
- * references (directly or through a kept child), which survive with their
35
- * own subtrees. This lets the LLM restructure a parent by re-emitting just
36
- * that entry, keeping existing children by reference, without regenerating
37
- * the entire tree.
38
- */
39
- export function buildElementsById(
40
- lines: ComponentEntry[],
41
- ): Record<string, ComponentEntry> {
42
- const map: Record<string, ComponentEntry> = {};
43
-
44
- for (const line of lines) {
45
- if (map[line.key]) {
46
- const oldDescendants = collectDescendantIds(line.key, map);
47
- const kept = new Set<string>();
48
- const stack = [...(line.children ?? [])];
49
- while (stack.length > 0) {
50
- const id = stack.pop()!;
51
- if (kept.has(id) || !oldDescendants.has(id)) continue;
52
- kept.add(id);
53
- const entry = map[id];
54
- if (entry?.children) stack.push(...entry.children);
55
- }
56
- for (const descId of oldDescendants) {
57
- if (!kept.has(descId)) delete map[descId];
58
- }
59
- }
60
- map[line.key] = line;
61
- }
62
-
63
- return map;
64
- }