@brad-frost-web/eddie-render 0.65.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/README.md +127 -0
- package/cdn/eddie-render.js +947 -0
- package/cdn/eddie-render.js.map +1 -0
- package/dist/composer/index.d.ts +75 -0
- package/dist/composer/index.d.ts.map +1 -0
- package/dist/composer/index.js +292 -0
- package/dist/composer/index.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +92 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +457 -0
- package/dist/render.js.map +1 -0
- package/dist/serialize.d.ts +29 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +128 -0
- package/dist/serialize.js.map +1 -0
- package/dist/spec.d.ts +59 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +364 -0
- package/dist/spec.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/validate/anti-pattern-selector.d.ts +75 -0
- package/dist/validate/anti-pattern-selector.d.ts.map +1 -0
- package/dist/validate/anti-pattern-selector.js +254 -0
- package/dist/validate/anti-pattern-selector.js.map +1 -0
- package/dist/validate/index.d.ts +36 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +334 -0
- package/dist/validate/index.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composer kit (#1900): the server half every product kept rewriting.
|
|
3
|
+
*
|
|
4
|
+
* Given a catalog profile and a transcript, ask the model for SpecStream
|
|
5
|
+
* patches against the canonical spec, apply them as they stream, validate
|
|
6
|
+
* the result strictly, and re-prompt once with the errors before calling a
|
|
7
|
+
* turn refused. The system block is the catalog digest, generated from the
|
|
8
|
+
* served document at runtime and sent with an ephemeral cache breakpoint,
|
|
9
|
+
* so the ~30k-token prompt is billed once per cache window (realtime-ui #7).
|
|
10
|
+
*
|
|
11
|
+
* Node only (uses `fetch` against the Messages API, no SDK — zero
|
|
12
|
+
* dependencies, like everything else in this package). The renderer never
|
|
13
|
+
* imports this module.
|
|
14
|
+
*/
|
|
15
|
+
import { applyPatchOp, cloneSpec, createSpecStreamCompiler, emptySpec } from '../spec.js';
|
|
16
|
+
import { TEXT_NODE } from '../types.js';
|
|
17
|
+
import { validateSpec } from '../validate/index.js';
|
|
18
|
+
const DEFAULT_MODEL = 'claude-haiku-4-5-20251001';
|
|
19
|
+
const DEFAULT_ENDPOINT = 'https://api.anthropic.com/v1/messages';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// The digest — the cached system block, generated from the catalog
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
function propLine(name, schema) {
|
|
24
|
+
const type = Array.isArray(schema.enum) ? `one of ${schema.enum.map((v) => JSON.stringify(v)).join(' | ')}` : String(schema.type ?? 'any');
|
|
25
|
+
return `${name} (${type})`;
|
|
26
|
+
}
|
|
27
|
+
function nodeLine(name, def) {
|
|
28
|
+
const props = Object.entries(def.properties ?? {})
|
|
29
|
+
.filter(([k]) => k !== 'component' && k !== 'children' && k !== 'slots')
|
|
30
|
+
.map(([k, s]) => propLine(k, s))
|
|
31
|
+
.join(', ');
|
|
32
|
+
const slots = Object.keys(def.properties?.slots?.properties ?? {});
|
|
33
|
+
const parts = [`- **${name}** — ${def.description ?? ''}`.trim()];
|
|
34
|
+
if (props)
|
|
35
|
+
parts.push(` props: ${props}`);
|
|
36
|
+
if (slots.length)
|
|
37
|
+
parts.push(` slots: ${slots.join(', ')}`);
|
|
38
|
+
// The default slot's description is the one line that says what goes INSIDE a node ("the primary value —
|
|
39
|
+
// typically a large number"); without it a composer sets a `value` prop that does not exist.
|
|
40
|
+
if (def.properties?.children)
|
|
41
|
+
parts.push(` children: ${def.properties.children.description ?? 'yes'}`);
|
|
42
|
+
if (def.allowedChildren)
|
|
43
|
+
parts.push(` allowedChildren: ${def.allowedChildren.join(', ')}`);
|
|
44
|
+
if (def.allowedParents)
|
|
45
|
+
parts.push(` allowedParents: ${def.allowedParents.join(', ')}`);
|
|
46
|
+
return parts.join('\n');
|
|
47
|
+
}
|
|
48
|
+
/** The system prompt for a catalog: its instructions, its nodes, and the output contract. */
|
|
49
|
+
export function buildDigest(catalog, extra) {
|
|
50
|
+
const entries = Object.entries(catalog.components);
|
|
51
|
+
const roots = entries.filter(([, d]) => d.metadata.extensions.eddie_kind === 'composition');
|
|
52
|
+
const leaves = entries.filter(([, d]) => d.metadata.extensions.eddie_kind !== 'composition');
|
|
53
|
+
const sections = [
|
|
54
|
+
catalog.instructions ?? '',
|
|
55
|
+
'## Page shapes (roots)',
|
|
56
|
+
roots.map(([n, d]) => nodeLine(n, d)).join('\n') || '(none — any node may be the root)',
|
|
57
|
+
'## Nodes',
|
|
58
|
+
leaves.map(([n, d]) => nodeLine(n, d)).join('\n'),
|
|
59
|
+
`## Output format
|
|
60
|
+
|
|
61
|
+
You emit SpecStream: one RFC 6902 JSON Patch line per change against the spec, and NOTHING else — no prose, no fences, no explanations.
|
|
62
|
+
The spec is { "root": id, "elements": { id: { "component": Name, ...props, "children": [ids], "slots": { slotName: [ids] } } }, "dataModel": {} }.
|
|
63
|
+
Ids are short kebab-case strings you choose ("hero", "stat-revenue"). Every child id must be emitted as an element.
|
|
64
|
+
Text inside a container is a **${TEXT_NODE}** element: { "component": "${TEXT_NODE}", "text": "…", "tagName": "p" }
|
|
65
|
+
(tagName optional: p, span, strong, em, li).
|
|
66
|
+
|
|
67
|
+
First compose (empty spec) — parents before children, one line per element,
|
|
68
|
+
every allowedChildren rule and anti-pattern respected (a Grid holds GridItems, a GridItem holds the card, the card's value is a Text child):
|
|
69
|
+
{"op":"add","path":"/root","value":"page"}
|
|
70
|
+
{"op":"add","path":"/elements/page","value":{"component":"DashboardPage","siteName":"Castle","heading":"Castle P&L","children":["stats"]}}
|
|
71
|
+
{"op":"add","path":"/elements/stats","value":{"component":"Grid","variant":"3up","children":["s1"]}}
|
|
72
|
+
{"op":"add","path":"/elements/s1","value":{"component":"GridItem","children":["revenue"]}}
|
|
73
|
+
{"op":"add","path":"/elements/revenue","value":{"component":"StatCard","label":"Revenue","meta":"YTD","children":["revenue-value"]}}
|
|
74
|
+
{"op":"add","path":"/elements/revenue-value","value":{"component":"${TEXT_NODE}","text":"$487,920"}}
|
|
75
|
+
|
|
76
|
+
Update (the spec is given): emit only the ops for what changed —
|
|
77
|
+
{"op":"replace","path":"/elements/hero/heading","value":"…"},
|
|
78
|
+
{"op":"add","path":"/elements/new-id","value":{…}} plus the parent's children update,
|
|
79
|
+
{"op":"remove","path":"/elements/old-id"} plus the parent's children update.
|
|
80
|
+
Never re-emit unchanged elements.
|
|
81
|
+
If the transcript carries no new instruction, emit exactly one line: {"op":"noop"}.`,
|
|
82
|
+
extra ?? '',
|
|
83
|
+
];
|
|
84
|
+
return sections.filter(Boolean).join('\n\n');
|
|
85
|
+
}
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// The turn
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
function userTurn(spec, transcript, note) {
|
|
90
|
+
const isCompose = !spec.root;
|
|
91
|
+
const parts = [
|
|
92
|
+
isCompose
|
|
93
|
+
? 'The spec is empty. Compose the page the transcript describes.'
|
|
94
|
+
: `Here is the current spec:\n<spec>\n${JSON.stringify(spec)}\n</spec>\nUpdate it to reflect the latest state of the conversation.`,
|
|
95
|
+
`<transcript>\n${transcript}\n</transcript>`,
|
|
96
|
+
note ?? '',
|
|
97
|
+
'Reply with SpecStream lines only.',
|
|
98
|
+
];
|
|
99
|
+
return parts.filter(Boolean).join('\n\n');
|
|
100
|
+
}
|
|
101
|
+
function repairTurn(issues) {
|
|
102
|
+
const lines = issues
|
|
103
|
+
.filter((i) => i.severity === 'error')
|
|
104
|
+
.map((i) => `- ${i.code}${i.id ? ` (${i.id})` : ''}: ${i.message}${i.fix ? ` ${i.fix}` : ''}`);
|
|
105
|
+
return (`Your patches were refused by the catalog:\n${lines.join('\n')}\n\n` +
|
|
106
|
+
'Emit corrected SpecStream lines against the ORIGINAL spec above (not against your refused patches). SpecStream lines only.');
|
|
107
|
+
}
|
|
108
|
+
async function streamMessages(opts, system, messages, handlers, signal) {
|
|
109
|
+
const res = await opts.fetch(opts.endpoint, {
|
|
110
|
+
method: 'POST',
|
|
111
|
+
headers: { 'content-type': 'application/json', 'x-api-key': opts.apiKey, 'anthropic-version': '2023-06-01' },
|
|
112
|
+
body: JSON.stringify({
|
|
113
|
+
model: opts.model,
|
|
114
|
+
max_tokens: opts.maxTokens,
|
|
115
|
+
stream: true,
|
|
116
|
+
system: [{ type: 'text', text: system, cache_control: { type: 'ephemeral' } }],
|
|
117
|
+
messages,
|
|
118
|
+
}),
|
|
119
|
+
signal,
|
|
120
|
+
});
|
|
121
|
+
if (!res.ok || !res.body) {
|
|
122
|
+
const text = await res.text().catch(() => '');
|
|
123
|
+
throw new Error(`Messages API ${res.status}: ${text.slice(0, 300)}`);
|
|
124
|
+
}
|
|
125
|
+
const reader = res.body.getReader();
|
|
126
|
+
const decoder = new TextDecoder();
|
|
127
|
+
let buffer = '';
|
|
128
|
+
const handleEvent = (data) => {
|
|
129
|
+
if (!data || data === '[DONE]')
|
|
130
|
+
return;
|
|
131
|
+
let ev;
|
|
132
|
+
try {
|
|
133
|
+
ev = JSON.parse(data);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const type = ev.type;
|
|
139
|
+
if (type === 'content_block_delta') {
|
|
140
|
+
const delta = ev.delta;
|
|
141
|
+
if (delta?.type === 'text_delta' && typeof delta.text === 'string')
|
|
142
|
+
handlers.onText(delta.text);
|
|
143
|
+
}
|
|
144
|
+
else if (type === 'message_start') {
|
|
145
|
+
const usage = ev.message?.usage ?? {};
|
|
146
|
+
handlers.onUsage({
|
|
147
|
+
inputTokens: usage.input_tokens ?? 0,
|
|
148
|
+
cacheReadTokens: usage.cache_read_input_tokens ?? 0,
|
|
149
|
+
cacheWriteTokens: usage.cache_creation_input_tokens ?? 0,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else if (type === 'message_delta') {
|
|
153
|
+
const usage = ev.usage ?? {};
|
|
154
|
+
if (typeof usage.output_tokens === 'number')
|
|
155
|
+
handlers.onUsage({ outputTokens: usage.output_tokens });
|
|
156
|
+
}
|
|
157
|
+
else if (type === 'error') {
|
|
158
|
+
throw new Error(`Messages API stream error: ${JSON.stringify(ev.error).slice(0, 300)}`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
for (;;) {
|
|
162
|
+
const { value, done } = await reader.read();
|
|
163
|
+
if (done)
|
|
164
|
+
break;
|
|
165
|
+
buffer += decoder.decode(value, { stream: true });
|
|
166
|
+
let idx;
|
|
167
|
+
while ((idx = buffer.indexOf('\n\n')) !== -1) {
|
|
168
|
+
const frame = buffer.slice(0, idx);
|
|
169
|
+
buffer = buffer.slice(idx + 2);
|
|
170
|
+
for (const line of frame.split('\n'))
|
|
171
|
+
if (line.startsWith('data:'))
|
|
172
|
+
handleEvent(line.slice(5).trim());
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (buffer.trim())
|
|
176
|
+
for (const line of buffer.split('\n'))
|
|
177
|
+
if (line.startsWith('data:'))
|
|
178
|
+
handleEvent(line.slice(5).trim());
|
|
179
|
+
}
|
|
180
|
+
export function createComposer(options) {
|
|
181
|
+
const catalog = options.catalog;
|
|
182
|
+
const digest = buildDigest(catalog, options.instructions);
|
|
183
|
+
const api = {
|
|
184
|
+
apiKey: options.apiKey,
|
|
185
|
+
model: options.model ?? DEFAULT_MODEL,
|
|
186
|
+
maxTokens: options.maxTokens ?? 4096,
|
|
187
|
+
endpoint: options.endpoint ?? DEFAULT_ENDPOINT,
|
|
188
|
+
fetch: options.fetch ?? globalThis.fetch,
|
|
189
|
+
};
|
|
190
|
+
const maxRepairs = options.maxRepairs ?? 1;
|
|
191
|
+
const log = options.log ?? (() => { });
|
|
192
|
+
async function* compose(input) {
|
|
193
|
+
const started = Date.now();
|
|
194
|
+
const original = cloneSpec(input.spec ?? emptySpec());
|
|
195
|
+
const usage = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
196
|
+
const messages = [
|
|
197
|
+
{ role: 'user', content: userTurn(original, input.transcript, input.note) },
|
|
198
|
+
];
|
|
199
|
+
const dropped = [];
|
|
200
|
+
let attempt = 0;
|
|
201
|
+
let lastIssues = [];
|
|
202
|
+
while (attempt <= maxRepairs) {
|
|
203
|
+
attempt++;
|
|
204
|
+
const working = cloneSpec(original);
|
|
205
|
+
const compiler = createSpecStreamCompiler();
|
|
206
|
+
const queue = [];
|
|
207
|
+
let assistantText = '';
|
|
208
|
+
let sawNoop = false;
|
|
209
|
+
let applied = 0;
|
|
210
|
+
const take = (ops) => {
|
|
211
|
+
for (const op of ops) {
|
|
212
|
+
if (op.op === 'noop') {
|
|
213
|
+
sawNoop = true;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
applyPatchOp(working, op);
|
|
218
|
+
applied++;
|
|
219
|
+
queue.push(op);
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
lastIssues.push({
|
|
223
|
+
code: 'VALIDATION_FAILED',
|
|
224
|
+
severity: 'error',
|
|
225
|
+
message: `Patch could not be applied: ${err instanceof Error ? err.message : String(err)} (${JSON.stringify(op).slice(0, 120)})`,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
lastIssues = [];
|
|
231
|
+
// Stream in a background task; yield ops as they land.
|
|
232
|
+
let streamError = null;
|
|
233
|
+
const streaming = streamMessages(api, digest, messages, {
|
|
234
|
+
onText: (text) => {
|
|
235
|
+
assistantText += text;
|
|
236
|
+
take(compiler.push(text));
|
|
237
|
+
},
|
|
238
|
+
onUsage: (u) => Object.assign(usage, Object.fromEntries(Object.entries(u).map(([k, v]) => [k, usage[k] + v]))),
|
|
239
|
+
}, input.signal).catch((err) => {
|
|
240
|
+
streamError = err;
|
|
241
|
+
});
|
|
242
|
+
// Drain the queue while the stream runs.
|
|
243
|
+
while (true) {
|
|
244
|
+
while (queue.length) {
|
|
245
|
+
const op = queue.shift();
|
|
246
|
+
yield { type: 'patch', op, line: JSON.stringify(op), attempt };
|
|
247
|
+
}
|
|
248
|
+
const settled = await Promise.race([streaming.then(() => true), new Promise((r) => setTimeout(() => r(false), 15))]);
|
|
249
|
+
if (settled)
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
take(compiler.end());
|
|
253
|
+
while (queue.length) {
|
|
254
|
+
const op = queue.shift();
|
|
255
|
+
yield { type: 'patch', op, line: JSON.stringify(op), attempt };
|
|
256
|
+
}
|
|
257
|
+
dropped.push(...compiler.dropped);
|
|
258
|
+
if (streamError)
|
|
259
|
+
throw streamError;
|
|
260
|
+
if (applied === 0 && sawNoop) {
|
|
261
|
+
log(`turn ${attempt}: noop`);
|
|
262
|
+
yield { type: 'done', spec: original, mode: 'noop', usage, latencyMs: Date.now() - started, attempts: attempt, dropped, issues: [] };
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const result = validateSpec(working, catalog);
|
|
266
|
+
const issues = [...lastIssues, ...result.issues];
|
|
267
|
+
if (result.ok && lastIssues.length === 0) {
|
|
268
|
+
yield {
|
|
269
|
+
type: 'done',
|
|
270
|
+
spec: working,
|
|
271
|
+
mode: original.root ? 'update' : 'compose',
|
|
272
|
+
usage,
|
|
273
|
+
latencyMs: Date.now() - started,
|
|
274
|
+
attempts: attempt,
|
|
275
|
+
dropped,
|
|
276
|
+
issues,
|
|
277
|
+
};
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
log(`turn ${attempt}: refused (${issues.filter((i) => i.severity === 'error').length} errors)`);
|
|
281
|
+
yield { type: 'refusal', issues, attempt };
|
|
282
|
+
lastIssues = issues;
|
|
283
|
+
if (attempt <= maxRepairs) {
|
|
284
|
+
yield { type: 'reset', attempt };
|
|
285
|
+
messages.push({ role: 'assistant', content: assistantText || '{"op":"noop"}' }, { role: 'user', content: repairTurn(issues) });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
yield { type: 'done', spec: original, mode: 'refused', usage, latencyMs: Date.now() - started, attempts: attempt, dropped, issues: lastIssues };
|
|
289
|
+
}
|
|
290
|
+
return { digest, compose };
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/composer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAsF,MAAM,aAAa,CAAC;AAC5H,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAkDpD,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,MAAM,gBAAgB,GAAG,uCAAuC,CAAC;AAEjE,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,IAAY,EAAE,MAA4E;IAC1G,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;IAE3I,OAAO,GAAG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,EAAE,aAAa,IAAI,eAAe,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACjI,CAAC;QACH,CAAC;QACD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAClJ,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brad-frost-web/eddie-render — the browser half of Eddie's generative-UI
|
|
3
|
+
* layer (#1898): a surface host that turns `a2ui-eddie/1.0` messages and
|
|
4
|
+
* SpecStream patches into Eddie DOM, refuses what the catalog does not
|
|
5
|
+
* allow, and keeps every untouched node's element across updates.
|
|
6
|
+
*
|
|
7
|
+
* Zero runtime dependencies. Safe to import in Node (nothing touches
|
|
8
|
+
* `document` until a host is created), so SSR checks and the composer can
|
|
9
|
+
* share the spec code.
|
|
10
|
+
*
|
|
11
|
+
* import { createSurfaceHost } from '@brad-frost-web/eddie-render';
|
|
12
|
+
* const host = createSurfaceHost(document.getElementById('surface'), {
|
|
13
|
+
* catalog: 'https://ds.bradfrost.com/catalog.json?profile=realtime',
|
|
14
|
+
* scripts: false, // the page already loads Eddie
|
|
15
|
+
* });
|
|
16
|
+
* await host.ready;
|
|
17
|
+
* host.apply({ version: 'v1.0', createSurface: { surfaceId: 'main', components: [...] } });
|
|
18
|
+
*
|
|
19
|
+
* Wire format: docs/A2UI-EDDIE.md. Strategy: docs/GENERATIVE-UI-STRATEGY.md §4.3.
|
|
20
|
+
*/
|
|
21
|
+
export { SurfaceHost, createSurfaceHost, type SurfaceHostOptions, type Turn, type TurnResult } from './render.js';
|
|
22
|
+
export { applyMessage, applyPatchLines, applyPatchOp, cloneSpec, createSpecStreamCompiler, emptySpec, getAtPointer, healJsonLine, normaliseWireComponent, parsePatchLine, parsePointer, reachableIds, setAtPointer, } from './spec.js';
|
|
23
|
+
export { serializeSpec, expand, resolveValue } from './serialize.js';
|
|
24
|
+
export { validateSpec, toA2uiErrors } from './validate/index.js';
|
|
25
|
+
export * from './types.js';
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAClH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,SAAS,EACT,wBAAwB,EACxB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACjE,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brad-frost-web/eddie-render — the browser half of Eddie's generative-UI
|
|
3
|
+
* layer (#1898): a surface host that turns `a2ui-eddie/1.0` messages and
|
|
4
|
+
* SpecStream patches into Eddie DOM, refuses what the catalog does not
|
|
5
|
+
* allow, and keeps every untouched node's element across updates.
|
|
6
|
+
*
|
|
7
|
+
* Zero runtime dependencies. Safe to import in Node (nothing touches
|
|
8
|
+
* `document` until a host is created), so SSR checks and the composer can
|
|
9
|
+
* share the spec code.
|
|
10
|
+
*
|
|
11
|
+
* import { createSurfaceHost } from '@brad-frost-web/eddie-render';
|
|
12
|
+
* const host = createSurfaceHost(document.getElementById('surface'), {
|
|
13
|
+
* catalog: 'https://ds.bradfrost.com/catalog.json?profile=realtime',
|
|
14
|
+
* scripts: false, // the page already loads Eddie
|
|
15
|
+
* });
|
|
16
|
+
* await host.ready;
|
|
17
|
+
* host.apply({ version: 'v1.0', createSurface: { surfaceId: 'main', components: [...] } });
|
|
18
|
+
*
|
|
19
|
+
* Wire format: docs/A2UI-EDDIE.md. Strategy: docs/GENERATIVE-UI-STRATEGY.md §4.3.
|
|
20
|
+
*/
|
|
21
|
+
export { SurfaceHost, createSurfaceHost } from './render.js';
|
|
22
|
+
export { applyMessage, applyPatchLines, applyPatchOp, cloneSpec, createSpecStreamCompiler, emptySpec, getAtPointer, healJsonLine, normaliseWireComponent, parsePatchLine, parsePointer, reachableIds, setAtPointer, } from './spec.js';
|
|
23
|
+
export { serializeSpec, expand, resolveValue } from './serialize.js';
|
|
24
|
+
export { validateSpec, toA2uiErrors } from './validate/index.js';
|
|
25
|
+
export * from './types.js';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAuD,MAAM,aAAa,CAAC;AAClH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,SAAS,EACT,wBAAwB,EACxB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACjE,cAAc,YAAY,CAAC"}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The surface host (#1898): applies `a2ui-eddie/1.0` messages and SpecStream
|
|
3
|
+
* patches to a canonical spec, validates, and renders Eddie DOM by node id.
|
|
4
|
+
*
|
|
5
|
+
* Rendering is reconciliation, not innerHTML: every spec element owns one DOM
|
|
6
|
+
* element, keyed by its resolved props; a changed node re-renders in place and
|
|
7
|
+
* untouched nodes keep their element, scroll position, and open state. That is
|
|
8
|
+
* realtime-ui PR #9 (section patching by id) generalised from HTML strings to
|
|
9
|
+
* catalog nodes, which is the whole reason the wire carries ids.
|
|
10
|
+
*
|
|
11
|
+
* Refusal is a first-class outcome. A turn that fails strict validation never
|
|
12
|
+
* reaches the committed spec: the previous surface stays on screen, a refusal
|
|
13
|
+
* renders in the host's refusal region, and a `refusal` event carries the
|
|
14
|
+
* issues (A2UI error codes included) so a composer can self-correct.
|
|
15
|
+
*/
|
|
16
|
+
import { type A2uiMessage, type Catalog, type PatchOp, type Spec, type ValidationResult } from './types.js';
|
|
17
|
+
export interface SurfaceHostOptions {
|
|
18
|
+
/** The catalog document, or a URL to fetch it from. */
|
|
19
|
+
catalog: Catalog | string;
|
|
20
|
+
/** Inject the `eddie_scriptTag` loaders the surface needs, once. Default true; pass false when the page already loads Eddie. */
|
|
21
|
+
scripts?: boolean;
|
|
22
|
+
/** Resolves `{ bind: "client" }` data-model values at render time. */
|
|
23
|
+
bind?: (path: string) => unknown;
|
|
24
|
+
surfaceId?: string;
|
|
25
|
+
/** Where refusals render. Default: a region the host creates before the surface. */
|
|
26
|
+
refusalRegion?: Element | null;
|
|
27
|
+
/** Show at most this many refusals at once. Default 3. */
|
|
28
|
+
maxRefusals?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface TurnResult extends ValidationResult {
|
|
31
|
+
/** `committed` — rendered and now canonical; `refused` — reverted to the previous spec. */
|
|
32
|
+
outcome: 'committed' | 'refused';
|
|
33
|
+
/** Ids whose element was (re)created or moved by this turn. */
|
|
34
|
+
touched: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface Turn {
|
|
37
|
+
/** Apply SpecStream lines to the working spec and render provisionally (pending children are placeholders). */
|
|
38
|
+
push(lines: string | string[]): PatchOp[];
|
|
39
|
+
/** Apply a patch op directly. */
|
|
40
|
+
pushOp(op: PatchOp): void;
|
|
41
|
+
/** Apply A2UI messages to the working spec. */
|
|
42
|
+
message(messages: A2uiMessage | A2uiMessage[]): void;
|
|
43
|
+
/** Strict-validate the working spec; commit and render, or revert and refuse. */
|
|
44
|
+
end(): TurnResult;
|
|
45
|
+
/** Abandon the turn: revert to the committed spec without recording a refusal. */
|
|
46
|
+
abort(): void;
|
|
47
|
+
readonly working: Spec;
|
|
48
|
+
}
|
|
49
|
+
export declare class SurfaceHost extends EventTarget {
|
|
50
|
+
readonly element: Element;
|
|
51
|
+
readonly surfaceId: string;
|
|
52
|
+
readonly ready: Promise<void>;
|
|
53
|
+
private catalog;
|
|
54
|
+
private committed;
|
|
55
|
+
private mounted;
|
|
56
|
+
private surfaceRoot;
|
|
57
|
+
private refusalRegion;
|
|
58
|
+
private readonly opts;
|
|
59
|
+
private loadedScripts;
|
|
60
|
+
constructor(element: Element, opts: SurfaceHostOptions);
|
|
61
|
+
/** The committed (rendered, canonical) spec. A copy; mutate through a turn. */
|
|
62
|
+
get spec(): Spec;
|
|
63
|
+
get catalogDocument(): Catalog | null;
|
|
64
|
+
/** Validate a spec against this host's catalog without touching the surface. */
|
|
65
|
+
validate(spec: Spec): ValidationResult;
|
|
66
|
+
/** Apply messages as one turn: validate strictly, then commit or refuse. */
|
|
67
|
+
apply(messages: A2uiMessage | A2uiMessage[]): TurnResult;
|
|
68
|
+
/** Apply SpecStream lines as one turn. */
|
|
69
|
+
applyPatchLines(lines: string | string[]): TurnResult;
|
|
70
|
+
/** Clear the surface (a `deleteSurface`). */
|
|
71
|
+
reset(): void;
|
|
72
|
+
beginTurn(): Turn;
|
|
73
|
+
/** Render a spec into the this. Returns the ids whose elements were created or replaced. */
|
|
74
|
+
private render;
|
|
75
|
+
private keyFor;
|
|
76
|
+
private create;
|
|
77
|
+
private resolvedProps;
|
|
78
|
+
private applyCommon;
|
|
79
|
+
/** Put `desired` under `host` (before `anchor` when there is one) in order, removing nothing that is not ours. */
|
|
80
|
+
private syncChildren;
|
|
81
|
+
private createRefusalRegion;
|
|
82
|
+
private showRefusals;
|
|
83
|
+
private clearRefusals;
|
|
84
|
+
private onActivate;
|
|
85
|
+
private ensureScripts;
|
|
86
|
+
private loadCatalog;
|
|
87
|
+
private requireCatalog;
|
|
88
|
+
/** The committed surface as markup (what the validator's anti-pattern pass sees). */
|
|
89
|
+
toMarkup(): string;
|
|
90
|
+
}
|
|
91
|
+
export declare function createSurfaceHost(element: Element, opts: SurfaceHostOptions): SurfaceHost;
|
|
92
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAGL,KAAK,WAAW,EAEhB,KAAK,OAAO,EAEZ,KAAK,OAAO,EACZ,KAAK,IAAI,EAGT,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,gIAAgI;IAChI,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sEAAsE;IACtE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,aAAa,CAAC,EAAE,OAAO,GAAG,IA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