@niscorp/nova 0.1.0
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/ACTION_DOCS.md +552 -0
- package/ADAPTER.md +170 -0
- package/DESIGN.md +719 -0
- package/I18N_DOCS.md +224 -0
- package/LAYOUT_DOCS.md +505 -0
- package/LICENSE +202 -0
- package/REACT_DOCS.md +562 -0
- package/README.md +379 -0
- package/SHELL_DOCS.md +615 -0
- package/TERMINAL_DOCS.md +124 -0
- package/dist/adapters/dom/components/index.cjs +473 -0
- package/dist/adapters/dom/components/index.cjs.map +1 -0
- package/dist/adapters/dom/components/index.d.cts +48 -0
- package/dist/adapters/dom/components/index.d.ts +48 -0
- package/dist/adapters/dom/components/index.js +420 -0
- package/dist/adapters/dom/components/index.js.map +1 -0
- package/dist/adapters/dom/index.cjs +171 -0
- package/dist/adapters/dom/index.cjs.map +1 -0
- package/dist/adapters/dom/index.d.cts +29 -0
- package/dist/adapters/dom/index.d.ts +29 -0
- package/dist/adapters/dom/index.js +15 -0
- package/dist/adapters/dom/index.js.map +1 -0
- package/dist/adapters/dom/server.cjs +129 -0
- package/dist/adapters/dom/server.cjs.map +1 -0
- package/dist/adapters/dom/server.d.cts +15 -0
- package/dist/adapters/dom/server.d.ts +15 -0
- package/dist/adapters/dom/server.js +37 -0
- package/dist/adapters/dom/server.js.map +1 -0
- package/dist/adapters/ink/index.d.ts +75 -0
- package/dist/adapters/ink/index.js +472 -0
- package/dist/adapters/ink/index.js.map +1 -0
- package/dist/adapters/react/components/index.cjs +552 -0
- package/dist/adapters/react/components/index.cjs.map +1 -0
- package/dist/adapters/react/components/index.d.cts +30 -0
- package/dist/adapters/react/components/index.d.ts +30 -0
- package/dist/adapters/react/components/index.js +12 -0
- package/dist/adapters/react/components/index.js.map +1 -0
- package/dist/adapters/react/index.cjs +1526 -0
- package/dist/adapters/react/index.cjs.map +1 -0
- package/dist/adapters/react/index.d.cts +149 -0
- package/dist/adapters/react/index.d.ts +149 -0
- package/dist/adapters/react/index.js +12 -0
- package/dist/adapters/react/index.js.map +1 -0
- package/dist/adapters/tty/components/index.cjs +255 -0
- package/dist/adapters/tty/components/index.cjs.map +1 -0
- package/dist/adapters/tty/components/index.d.cts +40 -0
- package/dist/adapters/tty/components/index.d.ts +40 -0
- package/dist/adapters/tty/components/index.js +187 -0
- package/dist/adapters/tty/components/index.js.map +1 -0
- package/dist/adapters/tty/index.cjs +76 -0
- package/dist/adapters/tty/index.cjs.map +1 -0
- package/dist/adapters/tty/index.d.cts +47 -0
- package/dist/adapters/tty/index.d.ts +47 -0
- package/dist/adapters/tty/index.js +76 -0
- package/dist/adapters/tty/index.js.map +1 -0
- package/dist/adapters/vue/components/index.cjs +619 -0
- package/dist/adapters/vue/components/index.cjs.map +1 -0
- package/dist/adapters/vue/components/index.d.cts +224 -0
- package/dist/adapters/vue/components/index.d.ts +224 -0
- package/dist/adapters/vue/components/index.js +12 -0
- package/dist/adapters/vue/components/index.js.map +1 -0
- package/dist/adapters/vue/index.cjs +747 -0
- package/dist/adapters/vue/index.cjs.map +1 -0
- package/dist/adapters/vue/index.d.cts +98 -0
- package/dist/adapters/vue/index.d.ts +98 -0
- package/dist/adapters/vue/index.js +127 -0
- package/dist/adapters/vue/index.js.map +1 -0
- package/dist/agent/index.cjs +178 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +28 -0
- package/dist/agent/index.d.ts +28 -0
- package/dist/agent/index.js +30 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-2MNLEL45.js +47 -0
- package/dist/chunk-2MNLEL45.js.map +1 -0
- package/dist/chunk-3HGE3VWK.js +753 -0
- package/dist/chunk-3HGE3VWK.js.map +1 -0
- package/dist/chunk-4ZID7UX5.js +549 -0
- package/dist/chunk-4ZID7UX5.js.map +1 -0
- package/dist/chunk-7B3RDENH.js +1982 -0
- package/dist/chunk-7B3RDENH.js.map +1 -0
- package/dist/chunk-7S5BNPUS.js +54 -0
- package/dist/chunk-7S5BNPUS.js.map +1 -0
- package/dist/chunk-7TS3YVQR.js +114 -0
- package/dist/chunk-7TS3YVQR.js.map +1 -0
- package/dist/chunk-EG2RUXJN.js +266 -0
- package/dist/chunk-EG2RUXJN.js.map +1 -0
- package/dist/chunk-GVBBL36G.js +429 -0
- package/dist/chunk-GVBBL36G.js.map +1 -0
- package/dist/chunk-I5D2R5UA.js +753 -0
- package/dist/chunk-I5D2R5UA.js.map +1 -0
- package/dist/chunk-IGLCWXQ3.js +304 -0
- package/dist/chunk-IGLCWXQ3.js.map +1 -0
- package/dist/chunk-JI7ZRESP.js +64 -0
- package/dist/chunk-JI7ZRESP.js.map +1 -0
- package/dist/chunk-L5223LLX.js +31 -0
- package/dist/chunk-L5223LLX.js.map +1 -0
- package/dist/chunk-LA3BSEMX.js +1905 -0
- package/dist/chunk-LA3BSEMX.js.map +1 -0
- package/dist/chunk-OAMC6R6E.js +121 -0
- package/dist/chunk-OAMC6R6E.js.map +1 -0
- package/dist/chunk-OGD5CCMZ.js +62 -0
- package/dist/chunk-OGD5CCMZ.js.map +1 -0
- package/dist/chunk-PF4OJTYU.js +199 -0
- package/dist/chunk-PF4OJTYU.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-RBU5PHN4.js +8 -0
- package/dist/chunk-RBU5PHN4.js.map +1 -0
- package/dist/chunk-RQB4PRPV.js +285 -0
- package/dist/chunk-RQB4PRPV.js.map +1 -0
- package/dist/chunk-V32EVEVM.js +464 -0
- package/dist/chunk-V32EVEVM.js.map +1 -0
- package/dist/chunk-ZITHBBF3.js +85 -0
- package/dist/chunk-ZITHBBF3.js.map +1 -0
- package/dist/devtools/index.cjs +1088 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +33 -0
- package/dist/devtools/index.d.ts +33 -0
- package/dist/devtools/index.js +399 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/effects-CndX9K7D.d.cts +123 -0
- package/dist/effects-CndX9K7D.d.ts +123 -0
- package/dist/endpoints-CD-6Jl-H.d.ts +36 -0
- package/dist/endpoints-Dem-EdRx.d.cts +36 -0
- package/dist/i18n/index.cjs +299 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.cts +28 -0
- package/dist/i18n/index.d.ts +28 -0
- package/dist/i18n/index.js +180 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index-CNfzSBe2.d.ts +93 -0
- package/dist/index-caZoXSwr.d.cts +93 -0
- package/dist/index.cjs +3723 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +144 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/index.cjs +635 -0
- package/dist/migrations/index.cjs.map +1 -0
- package/dist/migrations/index.d.cts +97 -0
- package/dist/migrations/index.d.ts +97 -0
- package/dist/migrations/index.js +50 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/palette-CP0wd3bE.d.ts +15 -0
- package/dist/palette-lm0bU9i5.d.cts +15 -0
- package/dist/primitive-props-BH_EJWIe.d.cts +100 -0
- package/dist/primitive-props-BH_EJWIe.d.ts +100 -0
- package/dist/primitive-props-CGoJvmcH.d.cts +100 -0
- package/dist/primitive-props-CGoJvmcH.d.ts +100 -0
- package/dist/reflect/index.cjs +998 -0
- package/dist/reflect/index.cjs.map +1 -0
- package/dist/reflect/index.d.cts +125 -0
- package/dist/reflect/index.d.ts +125 -0
- package/dist/reflect/index.js +13 -0
- package/dist/reflect/index.js.map +1 -0
- package/dist/schemas-DPdeFlCT.d.cts +38 -0
- package/dist/schemas-DPdeFlCT.d.ts +38 -0
- package/dist/schemas-pMyyuXV7.d.cts +47 -0
- package/dist/schemas-pMyyuXV7.d.ts +47 -0
- package/dist/types-Boh9ckdG.d.ts +194 -0
- package/dist/types-Brc7v_pS.d.ts +198 -0
- package/dist/types-ByNSwtUV.d.cts +20 -0
- package/dist/types-DdltMfw7.d.ts +20 -0
- package/dist/types-De0KpxfI.d.cts +198 -0
- package/dist/types-DhHL0twe.d.ts +20 -0
- package/dist/types-Dv6JLmgo.d.cts +194 -0
- package/dist/types-Q80YtOQt.d.cts +20 -0
- package/package.json +237 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cortex = require('@niscorp/cortex');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
// src/agent/layout.agent.ts
|
|
7
|
+
zod.z.object({
|
|
8
|
+
$if: zod.z.unknown().describe("Condition \u2014 resolved recursively, then checked for truthiness."),
|
|
9
|
+
$then: zod.z.unknown().describe("Value when condition is truthy \u2014 resolved recursively."),
|
|
10
|
+
$else: zod.z.unknown().optional().describe("Value when condition is falsy \u2014 resolved recursively.")
|
|
11
|
+
}).strict().describe("Conditional value directive. Resolved at bind time.");
|
|
12
|
+
var ResolvableSchema = zod.z.unknown().describe(
|
|
13
|
+
'Any value. Strings support {{}} templates and bare $-paths. The data ROOT is "$." \u2014 a data key is ALWAYS "$.key" ("{{$.rows.length}} found", "$.loading"); "$key" without the dot is INVALID. Loop variables (a `for` directive\'s `as`) are "$<name>.field" ("{{$row.title}}"). Objects may be directives like {$if,$then,$else}. Arrays and nested objects are walked recursively. Everything else is literal.'
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// src/layout/schemas.ts
|
|
17
|
+
var LayoutPrimitiveSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]).describe("A primitive layout value rendered as text.");
|
|
18
|
+
var ComponentNodeSchema = zod.z.lazy(
|
|
19
|
+
() => zod.z.object({
|
|
20
|
+
component: zod.z.string().describe("The registry name of the component to render."),
|
|
21
|
+
props: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Component props; values may be bindings to be resolved at render time."),
|
|
22
|
+
children: zod.z.union([LayoutNodeSchema, zod.z.array(LayoutNodeSchema)]).optional().describe("Child layout content (a single node or an array of nodes)."),
|
|
23
|
+
ref: zod.z.string().optional().describe("A stable identifier used to target this component from event handlers."),
|
|
24
|
+
model: zod.z.string().optional().describe('A two-way binding path, e.g. "$.name".'),
|
|
25
|
+
events: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Map of event name to event configuration handled by the action runtime.")
|
|
26
|
+
}).strict().describe("A node that instantiates a component from the registry.")
|
|
27
|
+
);
|
|
28
|
+
var ConditionalNodeSchema = zod.z.lazy(
|
|
29
|
+
() => zod.z.object({
|
|
30
|
+
if: ResolvableSchema.describe("Resolvable value evaluated for truthiness."),
|
|
31
|
+
then: LayoutNodeSchema.describe("Layout to render when condition is truthy."),
|
|
32
|
+
else: LayoutNodeSchema.optional().describe("Layout to render when condition is falsy.")
|
|
33
|
+
}).strict().describe("A node that conditionally renders one of two branches.")
|
|
34
|
+
);
|
|
35
|
+
var LoopNodeSchema = zod.z.lazy(
|
|
36
|
+
() => zod.z.object({
|
|
37
|
+
for: ResolvableSchema.describe("Resolvable value that resolves to an iterable array."),
|
|
38
|
+
as: zod.z.string().describe("Name to bind each iterated item under in the inner scope."),
|
|
39
|
+
key: zod.z.string().optional().describe("Optional key path on each item used for stable identity."),
|
|
40
|
+
do: LayoutNodeSchema.describe("Layout rendered once per iterated item.")
|
|
41
|
+
}).strict().describe("A node that iterates an array binding and renders a layout for each item.")
|
|
42
|
+
);
|
|
43
|
+
var LayoutRefNodeSchema = zod.z.object({
|
|
44
|
+
ref: zod.z.string().describe("Identifier of a layout stored in the layout store to inline at this position.")
|
|
45
|
+
}).strict().describe("A reference to a stored layout, inlined during render.");
|
|
46
|
+
var SlotNodeSchema = zod.z.object({
|
|
47
|
+
slot: zod.z.string().describe(
|
|
48
|
+
"Name of a slot placeholder. When an ActionFragment is composed with an action (a push/replace `with`), the fragment's `{ slot: \"body\" }` node is replaced by the composing action's own layout. An unfilled slot renders nothing."
|
|
49
|
+
)
|
|
50
|
+
}).strict().describe(
|
|
51
|
+
"A placeholder that a fragment-merge fills with a composing action's layout. Only meaningful inside an ActionFragment's layout."
|
|
52
|
+
);
|
|
53
|
+
var LayoutNodeSchema = zod.z.lazy(
|
|
54
|
+
() => zod.z.union([
|
|
55
|
+
ComponentNodeSchema,
|
|
56
|
+
ConditionalNodeSchema,
|
|
57
|
+
LoopNodeSchema,
|
|
58
|
+
LayoutRefNodeSchema,
|
|
59
|
+
SlotNodeSchema,
|
|
60
|
+
zod.z.array(LayoutNodeSchema),
|
|
61
|
+
LayoutPrimitiveSchema
|
|
62
|
+
]).describe("Any layout node: component, conditional, loop, layout ref, slot, array of nodes, or a primitive text value.")
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// src/agent/layout.agent.ts
|
|
66
|
+
var INSTRUCTIONS = `You are the Nova layout agent. Given an intent, a component palette, and a data example, produce a Nova LayoutNode that renders the data as a UI.
|
|
67
|
+
|
|
68
|
+
Your input:
|
|
69
|
+
- intent: what UI to produce.
|
|
70
|
+
- palette: the ONLY components you may use. Each is { name, description, propsSchema }. Every "component" field in your output MUST be one of these names, and its props MUST fit that component's propsSchema. Set ONLY props that appear in the schema \u2014 there is no other styling; components render in their own default style.
|
|
71
|
+
- dataShape: a JSON example of the data the layout binds against. The data is the binding ROOT \u2014 reference it with "$": an array \u2192 a Table's "rows": "$" or a loop { "for": "$", "as": "row", "do": \u2026 } binding "{{$row.field}}"; an object \u2192 "$.field"; a scalar \u2192 "$".
|
|
72
|
+
- styleGuide (optional): house style rules \u2014 follow them.
|
|
73
|
+
- base (optional): an existing layout to work from. If given, keep its structure and component choices, adapting the bindings to this intent + data \u2014 use it to match a prior layout or to revise it.
|
|
74
|
+
|
|
75
|
+
Your envelope's \`data\` is the LayoutNode; \`reasoning\` is a one-sentence explanation. The layout MUST validate against the OUTPUT SCHEMA below.
|
|
76
|
+
|
|
77
|
+
Worked example (illustrative \u2014 read the schema + palette for the real details):
|
|
78
|
+
INPUT { "intent": "list each name on its own line", "palette": [{"name":"Stack","description":"Vertical container for children."},{"name":"Text","description":"Renders text; children is the string."}], "dataShape": [{ "name": "" }] }
|
|
79
|
+
data { "component": "Stack", "children": { "for": "$", "as": "row", "do": { "component": "Text", "children": "{{$row.name}}" } } }`;
|
|
80
|
+
var layoutAgent = cortex.defineAgent({
|
|
81
|
+
id: "nova.layout",
|
|
82
|
+
description: "Generates a Nova LayoutNode from an intent, a component palette, and a data example.",
|
|
83
|
+
instructions: INSTRUCTIONS,
|
|
84
|
+
output: { schema: LayoutNodeSchema }
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// src/agent/palette.ts
|
|
88
|
+
var stripProps = (schema, omit) => {
|
|
89
|
+
const s = schema;
|
|
90
|
+
if (s.properties === void 0) return schema;
|
|
91
|
+
const properties = { ...s.properties };
|
|
92
|
+
for (const p of omit) delete properties[p];
|
|
93
|
+
const required = s.required?.filter((r) => !omit.includes(r));
|
|
94
|
+
return { ...s, properties, ...required !== void 0 ? { required } : {} };
|
|
95
|
+
};
|
|
96
|
+
var paletteEntryOf = (name, meta, omitProps) => {
|
|
97
|
+
let propsSchema;
|
|
98
|
+
if (meta.propsSchema !== void 0) {
|
|
99
|
+
const js = meta.propsSchema["~standard"].jsonSchema.output({ target: "draft-07" });
|
|
100
|
+
propsSchema = omitProps !== void 0 && omitProps.length > 0 ? stripProps(js, omitProps) : js;
|
|
101
|
+
}
|
|
102
|
+
return { name, description: meta.description ?? "", ...propsSchema === void 0 ? {} : { propsSchema } };
|
|
103
|
+
};
|
|
104
|
+
var paletteFromRegistry = (registry, options = {}) => {
|
|
105
|
+
const names = options.include ?? registry.list();
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const name of names) {
|
|
108
|
+
const entry = registry.get(name);
|
|
109
|
+
if (entry === void 0) continue;
|
|
110
|
+
out.push(paletteEntryOf(name, entry.meta, options.omitProps));
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/agent/affordances.ts
|
|
116
|
+
var KEY_PATTERN = /\$\.([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
117
|
+
var VAR_PATTERN = /\$([A-Za-z_][A-Za-z0-9_]*)\./g;
|
|
118
|
+
var collectInteractive = (layout) => {
|
|
119
|
+
const refs = [];
|
|
120
|
+
const models = [];
|
|
121
|
+
const boundKeys = /* @__PURE__ */ new Set();
|
|
122
|
+
const suspects = /* @__PURE__ */ new Set();
|
|
123
|
+
let componentCount = 0;
|
|
124
|
+
const scanString = (value, scope) => {
|
|
125
|
+
for (const match of value.matchAll(KEY_PATTERN)) {
|
|
126
|
+
const key = match[1];
|
|
127
|
+
if (key !== void 0) boundKeys.add(key);
|
|
128
|
+
}
|
|
129
|
+
for (const match of value.matchAll(VAR_PATTERN)) {
|
|
130
|
+
const name = match[1];
|
|
131
|
+
if (name !== void 0 && !scope.has(name)) suspects.add(`$${name}.`);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const walk = (node, scope) => {
|
|
135
|
+
if (typeof node === "string") return scanString(node, scope);
|
|
136
|
+
if (Array.isArray(node)) {
|
|
137
|
+
for (const child of node) walk(child, scope);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (node === null || typeof node !== "object") return;
|
|
141
|
+
const record = node;
|
|
142
|
+
const loopVar = record["for"] !== void 0 && typeof record["as"] === "string" ? record["as"] : void 0;
|
|
143
|
+
const childScope = loopVar !== void 0 ? /* @__PURE__ */ new Set([...scope, loopVar]) : scope;
|
|
144
|
+
const component = typeof record["component"] === "string" ? record["component"] : void 0;
|
|
145
|
+
if (component !== void 0) {
|
|
146
|
+
componentCount += 1;
|
|
147
|
+
if (typeof record["ref"] === "string" && record["ref"].length > 0) {
|
|
148
|
+
refs.push({ ref: record["ref"], component, via: "ref" });
|
|
149
|
+
}
|
|
150
|
+
if (typeof record["model"] === "string" && record["model"].length > 0) {
|
|
151
|
+
models.push({ path: record["model"], component });
|
|
152
|
+
}
|
|
153
|
+
const props = record["props"];
|
|
154
|
+
if (props !== null && typeof props === "object" && !Array.isArray(props)) {
|
|
155
|
+
for (const [key, value] of Object.entries(props)) {
|
|
156
|
+
if (key.endsWith("Ref") && typeof value === "string" && value.length > 0) {
|
|
157
|
+
refs.push({ ref: value, component, via: key });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const value of Object.values(record)) walk(value, childScope);
|
|
163
|
+
};
|
|
164
|
+
walk(layout, /* @__PURE__ */ new Set());
|
|
165
|
+
return {
|
|
166
|
+
refs,
|
|
167
|
+
models,
|
|
168
|
+
boundKeys: [...boundKeys].sort(),
|
|
169
|
+
suspectBindings: [...suspects].sort(),
|
|
170
|
+
componentCount
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
exports.collectInteractive = collectInteractive;
|
|
175
|
+
exports.layoutAgent = layoutAgent;
|
|
176
|
+
exports.paletteFromRegistry = paletteFromRegistry;
|
|
177
|
+
//# sourceMappingURL=index.cjs.map
|
|
178
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/bindings/schemas.ts","../../src/layout/schemas.ts","../../src/agent/layout.agent.ts","../../src/agent/palette.ts","../../src/agent/affordances.ts"],"names":["z","defineAgent"],"mappings":";;;;;;AAEiCA,MAC9B,MAAA,CAAO;AAAA,EACN,GAAA,EAAKA,KAAA,CAAE,OAAA,EAAQ,CAAE,SAAS,qEAAgE,CAAA;AAAA,EAC1F,KAAA,EAAOA,KAAA,CAAE,OAAA,EAAQ,CAAE,SAAS,6DAAwD,CAAA;AAAA,EACpF,OAAOA,KAAA,CACJ,OAAA,GACA,QAAA,EAAS,CACT,SAAS,4DAAuD;AACrE,CAAC,CAAA,CACA,MAAA,EAAO,CACP,QAAA,CAAS,qDAAqD;AAI1D,IAAM,gBAAA,GAAmBA,KAAA,CAC7B,OAAA,EAAQ,CACR,QAAA;AAAA,EACC;AAMF,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AW,CAAC,GAAG,SAAS,EAAE,IAAA,EAAK;AAAA,IAC/B,eAAA,EAAiB,CAAC,GAAG,QAAQ,EAAE,IAAA,EAAK;AAAA,IACpC;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import { z } from 'zod';\n\nexport const IfDirectiveSchema = z\n .object({\n $if: z.unknown().describe('Condition — resolved recursively, then checked for truthiness.'),\n $then: z.unknown().describe('Value when condition is truthy — resolved recursively.'),\n $else: z\n .unknown()\n .optional()\n .describe('Value when condition is falsy — resolved recursively.'),\n })\n .strict()\n .describe('Conditional value directive. Resolved at bind time.');\n\nexport type IfDirective = z.infer<typeof IfDirectiveSchema>;\n\nexport const ResolvableSchema = z\n .unknown()\n .describe(\n 'Any value. Strings support {{}} templates and bare $-paths. The data ROOT is '\n + '\"$.\" — a data key is ALWAYS \"$.key\" (\"{{$.rows.length}} found\", \"$.loading\"); '\n + '\"$key\" without the dot is INVALID. Loop variables (a `for` directive\\'s `as`) '\n + 'are \"$<name>.field\" (\"{{$row.title}}\"). Objects may be directives like '\n + '{$if,$then,$else}. Arrays and nested objects are walked recursively. '\n + 'Everything else is literal.',\n );\n","import { z } from 'zod';\nimport { ResolvableSchema } from '../shared/bindings/schemas';\n\n// ═══════════════════════════════════════════════════════════\n// Layout node schemas\n// ═══════════════════════════════════════════════════════════\n\nexport const LayoutPrimitiveSchema = z\n .union([z.string(), z.number(), z.boolean(), z.null()])\n .describe('A primitive layout value rendered as text.');\n\nexport type LayoutPrimitive = z.infer<typeof LayoutPrimitiveSchema>;\n\nexport type ComponentNode = {\n component: string;\n props?: Record<string, unknown>;\n children?: LayoutNode | LayoutNode[];\n ref?: string;\n model?: string;\n events?: Record<string, unknown>;\n};\n\nexport const ComponentNodeSchema: z.ZodType<ComponentNode> = z.lazy(() =>\n z\n .object({\n component: z.string().describe('The registry name of the component to render.'),\n props: z\n .record(z.string(), z.unknown())\n .optional()\n .describe('Component props; values may be bindings to be resolved at render time.'),\n children: z\n .union([LayoutNodeSchema, z.array(LayoutNodeSchema)])\n .optional()\n .describe('Child layout content (a single node or an array of nodes).'),\n ref: z.string().optional().describe('A stable identifier used to target this component from event handlers.'),\n model: z.string().optional().describe('A two-way binding path, e.g. \"$.name\".'),\n events: z\n .record(z.string(), z.unknown())\n .optional()\n .describe('Map of event name to event configuration handled by the action runtime.'),\n })\n .strict()\n .describe('A node that instantiates a component from the registry.'),\n);\n\nexport type ConditionalNode = {\n if: unknown;\n then: LayoutNode;\n else?: LayoutNode;\n};\n\nexport const ConditionalNodeSchema: z.ZodType<ConditionalNode> = z.lazy(() =>\n z\n .object({\n if: ResolvableSchema.describe('Resolvable value evaluated for truthiness.'),\n then: LayoutNodeSchema.describe('Layout to render when condition is truthy.'),\n else: LayoutNodeSchema.optional().describe('Layout to render when condition is falsy.'),\n })\n .strict()\n .describe('A node that conditionally renders one of two branches.'),\n);\n\nexport type LoopNode = {\n for: unknown;\n as: string;\n key?: string;\n do: LayoutNode;\n};\n\nexport const LoopNodeSchema: z.ZodType<LoopNode> = z.lazy(() =>\n z\n .object({\n for: ResolvableSchema.describe('Resolvable value that resolves to an iterable array.'),\n as: z.string().describe('Name to bind each iterated item under in the inner scope.'),\n key: z.string().optional().describe('Optional key path on each item used for stable identity.'),\n do: LayoutNodeSchema.describe('Layout rendered once per iterated item.'),\n })\n .strict()\n .describe('A node that iterates an array binding and renders a layout for each item.'),\n);\n\nexport const LayoutRefNodeSchema = z\n .object({\n ref: z.string().describe('Identifier of a layout stored in the layout store to inline at this position.'),\n })\n .strict()\n .describe('A reference to a stored layout, inlined during render.');\n\nexport type LayoutRefNode = z.infer<typeof LayoutRefNodeSchema>;\n\nexport const SlotNodeSchema = z\n .object({\n slot: z\n .string()\n .describe(\n 'Name of a slot placeholder. When an ActionFragment is composed with an action ' +\n '(a push/replace `with`), the fragment\\'s `{ slot: \"body\" }` node is replaced by ' +\n 'the composing action\\'s own layout. An unfilled slot renders nothing.',\n ),\n })\n .strict()\n .describe(\n 'A placeholder that a fragment-merge fills with a composing action\\'s layout. ' +\n 'Only meaningful inside an ActionFragment\\'s layout.',\n );\n\nexport type SlotNode = z.infer<typeof SlotNodeSchema>;\n\nexport type LayoutNode =\n | ComponentNode\n | ConditionalNode\n | LoopNode\n | LayoutRefNode\n | SlotNode\n | LayoutNode[]\n | LayoutPrimitive;\n\nexport const LayoutNodeSchema: z.ZodType<LayoutNode> = z.lazy(() =>\n z\n .union([\n ComponentNodeSchema,\n ConditionalNodeSchema,\n LoopNodeSchema,\n LayoutRefNodeSchema,\n SlotNodeSchema,\n z.array(LayoutNodeSchema),\n LayoutPrimitiveSchema,\n ])\n .describe('Any layout node: component, conditional, loop, layout ref, slot, array of nodes, or a primitive text value.'),\n);\n","// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/agent — Nova layout agent\n// ═══════════════════════════════════════════════════════════\n//\n// Given an intent, a component palette, and a data example, produces a Nova\n// LayoutNode — a tree of components, conditionals, loops and bindings that\n// renders the data as a UI.\n//\n// Same pattern as @niscorp/prism/agent and @niscorp/vex/agent: one exported\n// `const`, the canonical schema as the payload (cortex validates the whole\n// recursive tree and feeds failures back in-loop), and the variable inputs\n// (intent, palette, dataShape) passed at call time. Cortex is an optional\n// peer dep — the rest of @niscorp/nova does not need it.\n//\n// import { layoutAgent, paletteFromRegistry } from '@niscorp/nova/agent';\n//\n// const result = await layoutAgent.run({\n// intent: 'a table of company and value',\n// palette: paletteFromRegistry(registry, { include: ['Table'] }),\n// dataShape: [{ company: '', value: 0 }],\n// }, { llm }).result;\n// if (result.ok) render(result.output.data, rows);\n//\n// The LayoutNode schema is NOT embedded in this prompt — cortex injects\n// it (output.doc 'auto') because the recursive tree can't ride the\n// respond tool's params. Node types, binding syntax and directives all\n// live in the schema's .describe() calls; fixes go there, not here.\n\nimport { defineAgent, type AgentDefinition } from '@niscorp/cortex';\n\nimport { LayoutNodeSchema } from '../layout/schemas';\nimport type { LayoutNode } from '../layout/schemas';\n\n// The agent's payload IS the LayoutNode; the model's one-line why\n// rides the envelope's `reasoning` field.\nexport type LayoutAgentOutput = LayoutNode;\n\nconst INSTRUCTIONS = `You are the Nova layout agent. Given an intent, a component palette, and a data example, produce a Nova LayoutNode that renders the data as a UI.\n\nYour input:\n - intent: what UI to produce.\n - palette: the ONLY components you may use. Each is { name, description, propsSchema }. Every \"component\" field in your output MUST be one of these names, and its props MUST fit that component's propsSchema. Set ONLY props that appear in the schema — there is no other styling; components render in their own default style.\n - dataShape: a JSON example of the data the layout binds against. The data is the binding ROOT — reference it with \"$\": an array → a Table's \"rows\": \"$\" or a loop { \"for\": \"$\", \"as\": \"row\", \"do\": … } binding \"{{$row.field}}\"; an object → \"$.field\"; a scalar → \"$\".\n - styleGuide (optional): house style rules — follow them.\n - base (optional): an existing layout to work from. If given, keep its structure and component choices, adapting the bindings to this intent + data — use it to match a prior layout or to revise it.\n\nYour envelope's \\`data\\` is the LayoutNode; \\`reasoning\\` is a one-sentence explanation. The layout MUST validate against the OUTPUT SCHEMA below.\n\nWorked example (illustrative — read the schema + palette for the real details):\nINPUT { \"intent\": \"list each name on its own line\", \"palette\": [{\"name\":\"Stack\",\"description\":\"Vertical container for children.\"},{\"name\":\"Text\",\"description\":\"Renders text; children is the string.\"}], \"dataShape\": [{ \"name\": \"\" }] }\ndata { \"component\": \"Stack\", \"children\": { \"for\": \"$\", \"as\": \"row\", \"do\": { \"component\": \"Text\", \"children\": \"{{$row.name}}\" } } }`;\n\nexport const layoutAgent: AgentDefinition<LayoutNode> = defineAgent<LayoutNode>({\n id: 'nova.layout',\n description: 'Generates a Nova LayoutNode from an intent, a component palette, and a data example.',\n instructions: INSTRUCTIONS,\n output: { schema: LayoutNodeSchema },\n});\n","import type { ComponentRegistry, ComponentMeta } from '../layout/types';\n\n// ───────────────────────────────────────────────────────────\n// Derive a layout-agent palette from a ComponentRegistry.\n//\n// Reads each component's `meta.description` + `meta.propsSchema` straight off the\n// registry and hands the agent a JSON Schema derived from the same Zod schema the\n// renderer validates against — no drift. Component authors put what the agent\n// needs on the source schema via `.describe()`; fixes go there, not here.\n// ───────────────────────────────────────────────────────────\n\nexport type LayoutPaletteEntry = { name: string; description: string; propsSchema?: object };\n\nexport type PaletteFromRegistryOptions = {\n // Optional allowlist of component names. When omitted, every registered\n // component appears — pass a curated subset to keep the agent's vocabulary\n // tight (e.g. exclude shell slots / nav chrome).\n include?: readonly string[];\n // Prop names to strip from every component's schema. Use it to hide props the\n // agent must not set — e.g. presentational knobs (`bg`, `class`, `pad`) — so the\n // components can only render in their default style.\n omitProps?: readonly string[];\n};\n\n// Drop `omit` keys from a JSON Schema's `properties` (and `required`), so the\n// agent never sees them.\nconst stripProps = (schema: object, omit: readonly string[]): object => {\n const s = schema as { properties?: Record<string, unknown>; required?: string[] };\n if (s.properties === undefined) return schema;\n const properties = { ...s.properties };\n for (const p of omit) delete properties[p];\n const required = s.required?.filter((r) => !omit.includes(r));\n return { ...s, properties, ...(required !== undefined ? { required } : {}) };\n};\n\n// ONE PALETTE ENTRY, from a component's meta — the conversion at the heart of a\n// palette, factored out so a second caller derives an author's props from the\n// SAME Zod schema and the SAME JSON-Schema target, never a fork that drifts.\n// moss's integration contract calls this to answer \"what may I build against\"\n// for a person, which is the same question the layout agent asks of the palette;\n// `omitProps` and binding-awareness stay the caller's concern. A component with\n// no schema yields name + description alone, exactly as a bare registration does.\nexport const paletteEntryOf = (name: string, meta: ComponentMeta, omitProps?: readonly string[]): LayoutPaletteEntry => {\n let propsSchema: object | undefined;\n if (meta.propsSchema !== undefined) {\n // The app's schema converts itself (Standard JSON Schema): it may come from\n // the app's zod copy, and ours would read that copy's metadata through our registry.\n const js = meta.propsSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n propsSchema = omitProps !== undefined && omitProps.length > 0 ? stripProps(js, omitProps) : js;\n }\n return { name, description: meta.description ?? '', ...(propsSchema === undefined ? {} : { propsSchema }) };\n};\n\nexport const paletteFromRegistry = (\n registry: ComponentRegistry,\n options: PaletteFromRegistryOptions = {},\n): LayoutPaletteEntry[] => {\n const names = options.include ?? registry.list();\n const out: LayoutPaletteEntry[] = [];\n for (const name of names) {\n const entry = registry.get(name);\n if (entry === undefined) continue;\n out.push(paletteEntryOf(name, entry.meta, options.omitProps));\n }\n return out;\n};\n","// ═══════════════════════════════════════════════════════════\n// Affordance collection — the deterministic half of the action/layout seam.\n//\n// A layout's interactive surface is fully present in its tree: `ref` (event\n// sources), `*Ref` props (component-specific event sources, e.g. a Table's\n// sortRef), `model` (two-way input bindings), and every `$.key` binding it\n// reads. A director agent that wires triggers against a layout it never sees\n// needs that surface as data — so it is DERIVED here by walking the tree,\n// never self-reported by the layout model. A receipt computed from the\n// artifact cannot lie about the artifact.\n// ═══════════════════════════════════════════════════════════\n\nexport type InteractiveRef = {\n ref: string;\n component: string;\n // How the ref is attached: the node's own `ref` field, or a `*Ref` prop name.\n via: string;\n};\n\nexport type InteractiveModel = {\n // The bound data path, e.g. '$.search'.\n path: string;\n component: string;\n};\n\nexport type InteractiveSurface = {\n refs: InteractiveRef[];\n models: InteractiveModel[];\n // Distinct top-level data keys the layout reads anywhere ('$.rows' → 'rows').\n boundKeys: string[];\n // Malformed-looking bindings: `$ident.…` where `ident` is neither the data\n // root (`$.`) nor a loop variable declared by an enclosing `for`/`as` —\n // e.g. `{{$kpi.count}}` (missing dot) renders literally and passes every\n // other check. Collected scope-aware so `{{$row.title}}` inside its loop\n // stays legal.\n suspectBindings: string[];\n componentCount: number;\n};\n\nconst KEY_PATTERN = /\\$\\.([A-Za-z_][A-Za-z0-9_]*)/g;\nconst VAR_PATTERN = /\\$([A-Za-z_][A-Za-z0-9_]*)\\./g;\n\nexport const collectInteractive = (layout: unknown): InteractiveSurface => {\n const refs: InteractiveRef[] = [];\n const models: InteractiveModel[] = [];\n const boundKeys = new Set<string>();\n const suspects = new Set<string>();\n let componentCount = 0;\n\n const scanString = (value: string, scope: ReadonlySet<string>): void => {\n for (const match of value.matchAll(KEY_PATTERN)) {\n const key = match[1];\n if (key !== undefined) boundKeys.add(key);\n }\n for (const match of value.matchAll(VAR_PATTERN)) {\n const name = match[1];\n if (name !== undefined && !scope.has(name)) suspects.add(`$${name}.`);\n }\n };\n\n const walk = (node: unknown, scope: ReadonlySet<string>): void => {\n if (typeof node === 'string') return scanString(node, scope);\n if (Array.isArray(node)) {\n for (const child of node) walk(child, scope);\n return;\n }\n if (node === null || typeof node !== 'object') return;\n const record = node as Record<string, unknown>;\n\n // A `for` directive declares its loop variable for everything beneath.\n const loopVar = record['for'] !== undefined && typeof record['as'] === 'string' ? record['as'] : undefined;\n const childScope = loopVar !== undefined ? new Set([...scope, loopVar]) : scope;\n\n const component = typeof record['component'] === 'string' ? record['component'] : undefined;\n if (component !== undefined) {\n componentCount += 1;\n if (typeof record['ref'] === 'string' && record['ref'].length > 0) {\n refs.push({ ref: record['ref'], component, via: 'ref' });\n }\n if (typeof record['model'] === 'string' && record['model'].length > 0) {\n models.push({ path: record['model'], component });\n }\n const props = record['props'];\n if (props !== null && typeof props === 'object' && !Array.isArray(props)) {\n for (const [key, value] of Object.entries(props as Record<string, unknown>)) {\n if (key.endsWith('Ref') && typeof value === 'string' && value.length > 0) {\n refs.push({ ref: value, component, via: key });\n }\n }\n }\n }\n // Generic descent: directives (`if`/`for`), props, children, column cell\n // specs — every nested node and binding is reached without schema-specific\n // cases. Strings are scanned for `$.key` bindings on the way.\n for (const value of Object.values(record)) walk(value, childScope);\n };\n\n walk(layout, new Set());\n return {\n refs,\n models,\n boundKeys: [...boundKeys].sort(),\n suspectBindings: [...suspects].sort(),\n componentCount,\n };\n};\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AgentDefinition } from '@niscorp/cortex';
|
|
2
|
+
import { L as LayoutNode } from '../schemas-DPdeFlCT.cjs';
|
|
3
|
+
export { L as LayoutPaletteEntry, P as PaletteFromRegistryOptions, a as paletteFromRegistry } from '../palette-lm0bU9i5.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '../types-De0KpxfI.cjs';
|
|
6
|
+
|
|
7
|
+
type LayoutAgentOutput = LayoutNode;
|
|
8
|
+
declare const layoutAgent: AgentDefinition<LayoutNode>;
|
|
9
|
+
|
|
10
|
+
type InteractiveRef = {
|
|
11
|
+
ref: string;
|
|
12
|
+
component: string;
|
|
13
|
+
via: string;
|
|
14
|
+
};
|
|
15
|
+
type InteractiveModel = {
|
|
16
|
+
path: string;
|
|
17
|
+
component: string;
|
|
18
|
+
};
|
|
19
|
+
type InteractiveSurface = {
|
|
20
|
+
refs: InteractiveRef[];
|
|
21
|
+
models: InteractiveModel[];
|
|
22
|
+
boundKeys: string[];
|
|
23
|
+
suspectBindings: string[];
|
|
24
|
+
componentCount: number;
|
|
25
|
+
};
|
|
26
|
+
declare const collectInteractive: (layout: unknown) => InteractiveSurface;
|
|
27
|
+
|
|
28
|
+
export { type InteractiveModel, type InteractiveRef, type InteractiveSurface, type LayoutAgentOutput, collectInteractive, layoutAgent };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AgentDefinition } from '@niscorp/cortex';
|
|
2
|
+
import { L as LayoutNode } from '../schemas-DPdeFlCT.js';
|
|
3
|
+
export { L as LayoutPaletteEntry, P as PaletteFromRegistryOptions, a as paletteFromRegistry } from '../palette-CP0wd3bE.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '../types-Brc7v_pS.js';
|
|
6
|
+
|
|
7
|
+
type LayoutAgentOutput = LayoutNode;
|
|
8
|
+
declare const layoutAgent: AgentDefinition<LayoutNode>;
|
|
9
|
+
|
|
10
|
+
type InteractiveRef = {
|
|
11
|
+
ref: string;
|
|
12
|
+
component: string;
|
|
13
|
+
via: string;
|
|
14
|
+
};
|
|
15
|
+
type InteractiveModel = {
|
|
16
|
+
path: string;
|
|
17
|
+
component: string;
|
|
18
|
+
};
|
|
19
|
+
type InteractiveSurface = {
|
|
20
|
+
refs: InteractiveRef[];
|
|
21
|
+
models: InteractiveModel[];
|
|
22
|
+
boundKeys: string[];
|
|
23
|
+
suspectBindings: string[];
|
|
24
|
+
componentCount: number;
|
|
25
|
+
};
|
|
26
|
+
declare const collectInteractive: (layout: unknown) => InteractiveSurface;
|
|
27
|
+
|
|
28
|
+
export { type InteractiveModel, type InteractiveRef, type InteractiveSurface, type LayoutAgentOutput, collectInteractive, layoutAgent };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { paletteFromRegistry } from '../chunk-L5223LLX.js';
|
|
2
|
+
export { collectInteractive } from '../chunk-OGD5CCMZ.js';
|
|
3
|
+
import { LayoutNodeSchema } from '../chunk-JI7ZRESP.js';
|
|
4
|
+
import '../chunk-PZ5AY32C.js';
|
|
5
|
+
import { defineAgent } from '@niscorp/cortex';
|
|
6
|
+
|
|
7
|
+
var INSTRUCTIONS = `You are the Nova layout agent. Given an intent, a component palette, and a data example, produce a Nova LayoutNode that renders the data as a UI.
|
|
8
|
+
|
|
9
|
+
Your input:
|
|
10
|
+
- intent: what UI to produce.
|
|
11
|
+
- palette: the ONLY components you may use. Each is { name, description, propsSchema }. Every "component" field in your output MUST be one of these names, and its props MUST fit that component's propsSchema. Set ONLY props that appear in the schema \u2014 there is no other styling; components render in their own default style.
|
|
12
|
+
- dataShape: a JSON example of the data the layout binds against. The data is the binding ROOT \u2014 reference it with "$": an array \u2192 a Table's "rows": "$" or a loop { "for": "$", "as": "row", "do": \u2026 } binding "{{$row.field}}"; an object \u2192 "$.field"; a scalar \u2192 "$".
|
|
13
|
+
- styleGuide (optional): house style rules \u2014 follow them.
|
|
14
|
+
- base (optional): an existing layout to work from. If given, keep its structure and component choices, adapting the bindings to this intent + data \u2014 use it to match a prior layout or to revise it.
|
|
15
|
+
|
|
16
|
+
Your envelope's \`data\` is the LayoutNode; \`reasoning\` is a one-sentence explanation. The layout MUST validate against the OUTPUT SCHEMA below.
|
|
17
|
+
|
|
18
|
+
Worked example (illustrative \u2014 read the schema + palette for the real details):
|
|
19
|
+
INPUT { "intent": "list each name on its own line", "palette": [{"name":"Stack","description":"Vertical container for children."},{"name":"Text","description":"Renders text; children is the string."}], "dataShape": [{ "name": "" }] }
|
|
20
|
+
data { "component": "Stack", "children": { "for": "$", "as": "row", "do": { "component": "Text", "children": "{{$row.name}}" } } }`;
|
|
21
|
+
var layoutAgent = defineAgent({
|
|
22
|
+
id: "nova.layout",
|
|
23
|
+
description: "Generates a Nova LayoutNode from an intent, a component palette, and a data example.",
|
|
24
|
+
instructions: INSTRUCTIONS,
|
|
25
|
+
output: { schema: LayoutNodeSchema }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { layoutAgent };
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/agent/layout.agent.ts"],"names":[],"mappings":";;;;;;AAqCA,IAAM,YAAA,GAAe,CAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA,oIAAA,CAAA;AAed,IAAM,cAA2C,WAAA,CAAwB;AAAA,EAC9E,EAAA,EAAI,aAAA;AAAA,EACJ,WAAA,EAAa,sFAAA;AAAA,EACb,YAAA,EAAc,YAAA;AAAA,EACd,MAAA,EAAQ,EAAE,MAAA,EAAQ,gBAAA;AACpB,CAAC","file":"index.js","sourcesContent":["// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/agent — Nova layout agent\n// ═══════════════════════════════════════════════════════════\n//\n// Given an intent, a component palette, and a data example, produces a Nova\n// LayoutNode — a tree of components, conditionals, loops and bindings that\n// renders the data as a UI.\n//\n// Same pattern as @niscorp/prism/agent and @niscorp/vex/agent: one exported\n// `const`, the canonical schema as the payload (cortex validates the whole\n// recursive tree and feeds failures back in-loop), and the variable inputs\n// (intent, palette, dataShape) passed at call time. Cortex is an optional\n// peer dep — the rest of @niscorp/nova does not need it.\n//\n// import { layoutAgent, paletteFromRegistry } from '@niscorp/nova/agent';\n//\n// const result = await layoutAgent.run({\n// intent: 'a table of company and value',\n// palette: paletteFromRegistry(registry, { include: ['Table'] }),\n// dataShape: [{ company: '', value: 0 }],\n// }, { llm }).result;\n// if (result.ok) render(result.output.data, rows);\n//\n// The LayoutNode schema is NOT embedded in this prompt — cortex injects\n// it (output.doc 'auto') because the recursive tree can't ride the\n// respond tool's params. Node types, binding syntax and directives all\n// live in the schema's .describe() calls; fixes go there, not here.\n\nimport { defineAgent, type AgentDefinition } from '@niscorp/cortex';\n\nimport { LayoutNodeSchema } from '../layout/schemas';\nimport type { LayoutNode } from '../layout/schemas';\n\n// The agent's payload IS the LayoutNode; the model's one-line why\n// rides the envelope's `reasoning` field.\nexport type LayoutAgentOutput = LayoutNode;\n\nconst INSTRUCTIONS = `You are the Nova layout agent. Given an intent, a component palette, and a data example, produce a Nova LayoutNode that renders the data as a UI.\n\nYour input:\n - intent: what UI to produce.\n - palette: the ONLY components you may use. Each is { name, description, propsSchema }. Every \"component\" field in your output MUST be one of these names, and its props MUST fit that component's propsSchema. Set ONLY props that appear in the schema — there is no other styling; components render in their own default style.\n - dataShape: a JSON example of the data the layout binds against. The data is the binding ROOT — reference it with \"$\": an array → a Table's \"rows\": \"$\" or a loop { \"for\": \"$\", \"as\": \"row\", \"do\": … } binding \"{{$row.field}}\"; an object → \"$.field\"; a scalar → \"$\".\n - styleGuide (optional): house style rules — follow them.\n - base (optional): an existing layout to work from. If given, keep its structure and component choices, adapting the bindings to this intent + data — use it to match a prior layout or to revise it.\n\nYour envelope's \\`data\\` is the LayoutNode; \\`reasoning\\` is a one-sentence explanation. The layout MUST validate against the OUTPUT SCHEMA below.\n\nWorked example (illustrative — read the schema + palette for the real details):\nINPUT { \"intent\": \"list each name on its own line\", \"palette\": [{\"name\":\"Stack\",\"description\":\"Vertical container for children.\"},{\"name\":\"Text\",\"description\":\"Renders text; children is the string.\"}], \"dataShape\": [{ \"name\": \"\" }] }\ndata { \"component\": \"Stack\", \"children\": { \"for\": \"$\", \"as\": \"row\", \"do\": { \"component\": \"Text\", \"children\": \"{{$row.name}}\" } } }`;\n\nexport const layoutAgent: AgentDefinition<LayoutNode> = defineAgent<LayoutNode>({\n id: 'nova.layout',\n description: 'Generates a Nova LayoutNode from an intent, a component palette, and a data example.',\n instructions: INSTRUCTIONS,\n output: { schema: LayoutNodeSchema },\n});\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/layout/registry.ts
|
|
2
|
+
var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
3
|
+
var isComponentMeta = (value) => {
|
|
4
|
+
if (typeof value !== "object" || value === null) return false;
|
|
5
|
+
return true;
|
|
6
|
+
};
|
|
7
|
+
var extractStaticMeta = (component) => {
|
|
8
|
+
if (typeof component !== "function" && (typeof component !== "object" || component === null)) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
const host = component;
|
|
12
|
+
if (!hasOwn(host, "meta")) return void 0;
|
|
13
|
+
const candidate = host.meta;
|
|
14
|
+
if (!isComponentMeta(candidate)) return void 0;
|
|
15
|
+
return candidate;
|
|
16
|
+
};
|
|
17
|
+
var isEntryShape = (value) => {
|
|
18
|
+
if (typeof value !== "object" || value === null) return false;
|
|
19
|
+
return hasOwn(value, "component");
|
|
20
|
+
};
|
|
21
|
+
var createComponentRegistry = () => {
|
|
22
|
+
const entries = /* @__PURE__ */ new Map();
|
|
23
|
+
const register = (name, component, meta) => {
|
|
24
|
+
const staticMeta = extractStaticMeta(component);
|
|
25
|
+
const merged = { ...staticMeta ?? {}, ...meta ?? {} };
|
|
26
|
+
entries.set(name, { component, meta: merged });
|
|
27
|
+
};
|
|
28
|
+
const registerAll = (batch) => {
|
|
29
|
+
for (const name of Object.keys(batch)) {
|
|
30
|
+
const input = batch[name];
|
|
31
|
+
if (input === void 0) continue;
|
|
32
|
+
if (isEntryShape(input)) {
|
|
33
|
+
register(name, input.component, input.meta);
|
|
34
|
+
} else {
|
|
35
|
+
register(name, input);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const get = (name) => entries.get(name);
|
|
40
|
+
const has = (name) => entries.has(name);
|
|
41
|
+
const list = () => Array.from(entries.keys());
|
|
42
|
+
return { register, registerAll, get, has, list };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { createComponentRegistry };
|
|
46
|
+
//# sourceMappingURL=chunk-2MNLEL45.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-2MNLEL45.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/layout/registry.ts"],"names":[],"mappings":";AAgBA,IAAM,MAAA,GAAS,CAAC,KAAA,EAAe,GAAA,KAC7B,OAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,KAAA,EAAO,GAAG,CAAA;AAEjD,IAAM,eAAA,GAAkB,CAAC,KAAA,KAA2C;AAClE,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AAExD,EAAA,OAAO,IAAA;AACT,CAAA;AAEA,IAAM,iBAAA,GAAoB,CAAa,SAAA,KAAqD;AAC1F,EAAA,IAAI,OAAO,SAAA,KAAc,UAAA,KAAe,OAAO,SAAA,KAAc,QAAA,IAAY,cAAc,IAAA,CAAA,EAAO;AAC5F,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,IAAA,GAAe,SAAA;AACrB,EAAA,IAAI,CAAC,MAAA,CAAO,IAAA,EAAM,MAAM,GAAG,OAAO,MAAA;AAClC,EAAA,MAAM,YAAa,IAAA,CAA2B,IAAA;AAC9C,EAAA,IAAI,CAAC,eAAA,CAAgB,SAAS,CAAA,EAAG,OAAO,MAAA;AACxC,EAAA,OAAO,SAAA;AACT,CAAA;AAEA,IAAM,YAAA,GAAe,CACnB,KAAA,KAC6D;AAC7D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,OAAO,MAAA,CAAO,OAAO,WAAW,CAAA;AAClC,CAA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ntry,\n ComponentMeta,\n ComponentRegistry,\n RegistrationInput,\n} from './types';\n\n// ═══════════════════════════════════════════════════════════\n// Component registry\n//\n// Stores `{component, meta}` entries keyed by name. Components\n// can carry a static `.meta` property; `registerAll` picks it up\n// automatically. Explicit meta passed to `register`/`registerAll`\n// wins over a component's static meta.\n// ═══════════════════════════════════════════════════════════\n\nconst hasOwn = (value: object, key: string): boolean =>\n Object.prototype.hasOwnProperty.call(value, key);\n\nconst isComponentMeta = (value: unknown): value is ComponentMeta => {\n if (typeof value !== 'object' || value === null) return false;\n // Meta is an open bag with optional fields; any plain object qualifies.\n return true;\n};\n\nconst extractStaticMeta = <TComponent>(component: TComponent): ComponentMeta | undefined => {\n if (typeof component !== 'function' && (typeof component !== 'object' || component === null)) {\n return undefined;\n }\n const host: object = component;\n if (!hasOwn(host, 'meta')) return undefined;\n const candidate = (host as { meta: unknown }).meta;\n if (!isComponentMeta(candidate)) return undefined;\n return candidate;\n};\n\nconst isEntryShape = <TComponent>(\n value: RegistrationInput<TComponent>,\n): value is { component: TComponent; meta?: ComponentMeta } => {\n if (typeof value !== 'object' || value === null) return false;\n return hasOwn(value, 'component');\n};\n\nexport const createComponentRegistry = <TComponent = unknown>(): ComponentRegistry<TComponent> => {\n const entries = new Map<string, ComponentEntry<TComponent>>();\n\n const register = (name: string, component: TComponent, meta?: ComponentMeta): void => {\n const staticMeta = extractStaticMeta(component);\n const merged: ComponentMeta = { ...(staticMeta ?? {}), ...(meta ?? {}) };\n entries.set(name, { component, meta: merged });\n };\n\n const registerAll = (batch: Record<string, RegistrationInput<TComponent>>): void => {\n for (const name of Object.keys(batch)) {\n const input = batch[name];\n if (input === undefined) continue;\n if (isEntryShape<TComponent>(input)) {\n register(name, input.component, input.meta);\n } else {\n register(name, input);\n }\n }\n };\n\n const get = (name: string): ComponentEntry<TComponent> | undefined => entries.get(name);\n\n const has = (name: string): boolean => entries.has(name);\n\n const list = (): string[] => Array.from(entries.keys());\n\n return { register, registerAll, get, has, list };\n};\n"]}
|