@luckydraw/cumulus 0.31.66 → 1.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.
- package/CHANGELOG.md +12 -556
- package/LICENSE +150 -0
- package/README.md +27 -8
- package/dist/gateway/adapters/webchat.d.ts +15 -0
- package/dist/gateway/adapters/webchat.d.ts.map +1 -1
- package/dist/gateway/adapters/webchat.js +78 -5
- package/dist/gateway/adapters/webchat.js.map +1 -1
- package/dist/gateway/config.d.ts +17 -2
- package/dist/gateway/config.d.ts.map +1 -1
- package/dist/gateway/config.js +10 -3
- package/dist/gateway/config.js.map +1 -1
- package/dist/gateway/daemon.d.ts +3 -1
- package/dist/gateway/daemon.d.ts.map +1 -1
- package/dist/gateway/daemon.js +128 -39
- package/dist/gateway/daemon.js.map +1 -1
- package/dist/gateway/namespaces.d.ts +34 -0
- package/dist/gateway/namespaces.d.ts.map +1 -1
- package/dist/gateway/namespaces.js +58 -0
- package/dist/gateway/namespaces.js.map +1 -1
- package/dist/gateway/server.d.ts +8 -0
- package/dist/gateway/server.d.ts.map +1 -1
- package/dist/gateway/server.js +150 -41
- package/dist/gateway/server.js.map +1 -1
- package/dist/gateway/setup.d.ts +32 -0
- package/dist/gateway/setup.d.ts.map +1 -1
- package/dist/gateway/setup.js +23 -3
- package/dist/gateway/setup.js.map +1 -1
- package/dist/gateway/static/blex-render.js +341 -0
- package/dist/gateway/static/chat.html +1 -0
- package/dist/gateway/static/widget.js +1009 -738
- package/dist/lib/gateway.d.ts +30 -8
- package/dist/lib/gateway.d.ts.map +1 -1
- package/dist/lib/gateway.js +36 -11
- package/dist/lib/gateway.js.map +1 -1
- package/dist/lib/history.d.ts +22 -0
- package/dist/lib/history.d.ts.map +1 -1
- package/dist/lib/history.js +59 -21
- package/dist/lib/history.js.map +1 -1
- package/dist/lib/huggingface-provider.d.ts.map +1 -1
- package/dist/lib/huggingface-provider.js +11 -3
- package/dist/lib/huggingface-provider.js.map +1 -1
- package/dist/lib/license.d.ts +76 -0
- package/dist/lib/license.d.ts.map +1 -0
- package/dist/lib/license.js +141 -0
- package/dist/lib/license.js.map +1 -0
- package/docs/agentic-harness-primer.md +283 -0
- package/docs/conditional-continuation.md +167 -0
- package/docs/web-app-agent-guide.md +559 -0
- package/examples/web-app-agent/README.md +334 -0
- package/examples/web-app-agent/agent/mcp-shim.js +105 -0
- package/examples/web-app-agent/gateway.config.example.json +70 -0
- package/examples/web-app-agent/package.json +13 -0
- package/examples/web-app-agent/public/agent/blex-mount.js +136 -0
- package/examples/web-app-agent/public/agent/bridge-mount.js +91 -0
- package/examples/web-app-agent/public/agent/chat-client.js +104 -0
- package/examples/web-app-agent/public/agent/commands.js +256 -0
- package/examples/web-app-agent/public/agent/device-thread.js +48 -0
- package/examples/web-app-agent/public/agent/panel.css +113 -0
- package/examples/web-app-agent/public/agent/panel.js +392 -0
- package/examples/web-app-agent/public/app.js +250 -0
- package/examples/web-app-agent/public/index.html +126 -0
- package/examples/web-app-agent/server.js +379 -0
- package/package.json +7 -3
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cumulus shared blex renderer (task 131, item 3).
|
|
3
|
+
*
|
|
4
|
+
* ONE renderer, many surfaces. The standalone chat widget and any embedding app
|
|
5
|
+
* (the web-app-agent kit, kalendeer, …) drive this same file through an injected
|
|
6
|
+
* adapter, rather than each re-deriving a port of it. Copying the port is what
|
|
7
|
+
* guarantees drift in every consumer at once.
|
|
8
|
+
*
|
|
9
|
+
* Served by the gateway at /blex-render.js. It is plain ES5-compatible script —
|
|
10
|
+
* no modules, no build step — so a browser can load it directly, cross-origin.
|
|
11
|
+
*
|
|
12
|
+
* ── Adapter contract ────────────────────────────────────────────────────────
|
|
13
|
+
* Required:
|
|
14
|
+
* allowType(type) -> boolean. Which block types this surface renders.
|
|
15
|
+
* getInput() -> the text input element, or null.
|
|
16
|
+
* getSendButton() -> the send button element, or null.
|
|
17
|
+
* Optional (default to no-ops, which is what makes a surface render-only):
|
|
18
|
+
* addChip(interaction, handle, sourceId)
|
|
19
|
+
* readPersisted(storeKey) -> previously stored interaction value
|
|
20
|
+
* persist(storeKey, value)
|
|
21
|
+
* onRendered(container, storeKey)
|
|
22
|
+
*
|
|
23
|
+
* A surface that supplies only the three required members gets render-only
|
|
24
|
+
* behaviour for free: interactions that complete locally still work, and
|
|
25
|
+
* deferred ones land in a no-op instead of a dead button.
|
|
26
|
+
*/
|
|
27
|
+
(function (global) {
|
|
28
|
+
'use strict';
|
|
29
|
+
|
|
30
|
+
// ── Fenced-code spans ──────────────────────────────────────────────────────
|
|
31
|
+
//
|
|
32
|
+
// Held as a source string, not a shared RegExp object — a /g regex carries
|
|
33
|
+
// lastIndex state, and these call sites must not be able to affect each other.
|
|
34
|
+
var CODE_FENCE_SRC = '```([^\\n`]*)\\n([\\s\\S]*?)```';
|
|
35
|
+
var BLEX_FENCE_SRC = '~~~blex:(\\w[\\w-]*)\\n([\\s\\S]*?)\\n~~~';
|
|
36
|
+
|
|
37
|
+
function codeFenceRe() {
|
|
38
|
+
return new RegExp(CODE_FENCE_SRC, 'g');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function findCodeFenceSpans(text) {
|
|
42
|
+
var spans = [];
|
|
43
|
+
var re = codeFenceRe();
|
|
44
|
+
var m;
|
|
45
|
+
while ((m = re.exec(text)) !== null) {
|
|
46
|
+
spans.push([m.index, m.index + m[0].length]);
|
|
47
|
+
}
|
|
48
|
+
return spans;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Replace ~~~blex fences with \x00BLEX_n\x00 tokens.
|
|
53
|
+
*
|
|
54
|
+
* A fence INSIDE a code block is an example being displayed, not a block to
|
|
55
|
+
* render — extracting it would delete it from the code block that exists to
|
|
56
|
+
* show it. String.replace reports offsets into the original string, so one
|
|
57
|
+
* pass over precomputed spans is enough.
|
|
58
|
+
*/
|
|
59
|
+
function extractBlocks(text) {
|
|
60
|
+
var blocks = [];
|
|
61
|
+
var protectedSpans = findCodeFenceSpans(text);
|
|
62
|
+
var replaced = text.replace(
|
|
63
|
+
new RegExp(BLEX_FENCE_SRC, 'g'),
|
|
64
|
+
function (match, type, json, offset) {
|
|
65
|
+
for (var i = 0; i < protectedSpans.length; i++) {
|
|
66
|
+
if (offset >= protectedSpans[i][0] && offset < protectedSpans[i][1]) return match;
|
|
67
|
+
}
|
|
68
|
+
var idx = blocks.length;
|
|
69
|
+
blocks.push({ type: type, json: json.trim(), idx: idx });
|
|
70
|
+
return '\x00BLEX_' + idx + '\x00';
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
return { text: replaced, blocks: blocks };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function escapeHtml(text) {
|
|
77
|
+
var div = document.createElement('div');
|
|
78
|
+
div.textContent = text;
|
|
79
|
+
return div.innerHTML;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The original fence text, reconstructed for display. */
|
|
83
|
+
function fenceSource(block) {
|
|
84
|
+
return '~~~blex:' + block.type + '\n' + block.json + '\n~~~';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* HTML for one placeholder container.
|
|
89
|
+
*
|
|
90
|
+
* The container carries the raw fence as its body. `render()` clears it before
|
|
91
|
+
* rendering, so a CLAIMED container is unchanged — but an unclaimed one shows
|
|
92
|
+
* what the author actually wrote instead of a blank rectangle. Containers go
|
|
93
|
+
* unclaimed on several real paths: user messages and changelog entries (which
|
|
94
|
+
* render markdown but never call render()), any page where blex.min.js failed
|
|
95
|
+
* to fetch, and — deliberately — any block type the adapter denies.
|
|
96
|
+
*
|
|
97
|
+
* opts.streaming suppresses the fallback: a completed-but-not-yet-rendered
|
|
98
|
+
* fence would otherwise flash its JSON before flipping to the rendered block.
|
|
99
|
+
*/
|
|
100
|
+
function placeholderHtml(idx, block, opts) {
|
|
101
|
+
var streaming = !!(opts && opts.streaming);
|
|
102
|
+
var body =
|
|
103
|
+
streaming || !block
|
|
104
|
+
? ''
|
|
105
|
+
: '<pre class="blex-fallback">' + escapeHtml(fenceSource(block)) + '</pre>';
|
|
106
|
+
return '<div class="blex-block-container" data-blex-idx="' + idx + '">' + body + '</div>';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Replace every \x00BLEX_n\x00 token in rendered HTML with its placeholder. */
|
|
110
|
+
function insertPlaceholders(html, blocks, opts) {
|
|
111
|
+
// The NUL is a deliberate in-band sentinel: it cannot occur in model output,
|
|
112
|
+
// so a token can never be forged by message content.
|
|
113
|
+
// eslint-disable-next-line no-control-regex
|
|
114
|
+
return html.replace(/\x00BLEX_(\d+)\x00/g, function (_, idx) {
|
|
115
|
+
return placeholderHtml(idx, blocks[parseInt(idx, 10)], opts);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── The render-only allow set ──────────────────────────────────────────────
|
|
120
|
+
//
|
|
121
|
+
// Derived, not argued. A type may render on a non-interactive surface iff every
|
|
122
|
+
// affordance it draws either completes locally or is purely visual:
|
|
123
|
+
//
|
|
124
|
+
// table / code / file-tree / timeline / image — selection is a highlight.
|
|
125
|
+
// Nothing is labelled with a verb; an emit landing in a no-op is invisible.
|
|
126
|
+
// terminal / svg — labelled buttons, but clipboard write and the object-URL
|
|
127
|
+
// download both run BEFORE the emit. The emit is a receipt, not the mechanism.
|
|
128
|
+
// chart / status / metric / progress / gallery / kanban / calendar /
|
|
129
|
+
// branch / layout — no clickable affordances at all.
|
|
130
|
+
//
|
|
131
|
+
// Excluded, and the reason each is excluded rather than merely unwired:
|
|
132
|
+
// confirm / poll / form — interaction is the entire point.
|
|
133
|
+
// diff — Apply/Reject have no local half. The emit IS the mechanism, so on a
|
|
134
|
+
// render-only surface they are guaranteed dead buttons that read as
|
|
135
|
+
// "click to apply" — worse than not rendering, because a dead button looks
|
|
136
|
+
// alive in a way raw JSON does not.
|
|
137
|
+
// mermaid — excluded on a DIFFERENT axis from the rest, and the distinction
|
|
138
|
+
// matters: it draws no affordance at all, so the local-completion test
|
|
139
|
+
// above would admit it. It cannot LOAD. Its renderer is the one real dynamic
|
|
140
|
+
// import in the 340KB bundle — `await import("mermaid")`, a bare specifier
|
|
141
|
+
// with no resolution in a classic script and no import map on any cumulus
|
|
142
|
+
// page. Upstream catches the throw and paints the literal string
|
|
143
|
+
// "Mermaid render error", so allowing it ships a guaranteed error box.
|
|
144
|
+
// Upstream ships a companion global bundle for `chart` (whose loader
|
|
145
|
+
// resolves in-bundle) and none for mermaid, so this is not a wiring
|
|
146
|
+
// oversight on our side. Measured by @cdda, re-verified against our own
|
|
147
|
+
// dist/gateway/static/blex.min.js.
|
|
148
|
+
var RENDER_ONLY_TYPES = [
|
|
149
|
+
'table',
|
|
150
|
+
'status',
|
|
151
|
+
'metric',
|
|
152
|
+
'progress',
|
|
153
|
+
'code',
|
|
154
|
+
'timeline',
|
|
155
|
+
'svg',
|
|
156
|
+
'image',
|
|
157
|
+
'gallery',
|
|
158
|
+
'file-tree',
|
|
159
|
+
'terminal',
|
|
160
|
+
'chart',
|
|
161
|
+
'kanban',
|
|
162
|
+
'calendar',
|
|
163
|
+
'branch',
|
|
164
|
+
'layout',
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
var INTERACTIVE_TYPES = ['confirm', 'poll', 'form', 'diff'];
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* An adapter for a surface that has an input but no chip tray.
|
|
171
|
+
*
|
|
172
|
+
* Denied types are NOT routed to a library fallback renderer: the global blex
|
|
173
|
+
* bundle exports BaseRenderer, getPluginInfo, getRegisteredTypes, hasBlockType,
|
|
174
|
+
* registerBlockType, registerLazyBlockType, registerPlugin, renderBlock,
|
|
175
|
+
* renderPlaceholder, unregisterBlockType, unregisterPlugin — and no fallback
|
|
176
|
+
* renderer among them. Leaving the container unclaimed reuses the raw-fence
|
|
177
|
+
* body above, which is honest and costs nothing.
|
|
178
|
+
*
|
|
179
|
+
* Deny is a per-render gate on purpose. Do NOT implement it with
|
|
180
|
+
* unregisterBlockType: the registry is module-global, so unregistering
|
|
181
|
+
* `confirm` removes it for every surface sharing that module instance.
|
|
182
|
+
*/
|
|
183
|
+
function renderOnlyAdapter(overrides) {
|
|
184
|
+
var base = {
|
|
185
|
+
allowType: function (type) {
|
|
186
|
+
return RENDER_ONLY_TYPES.indexOf(type) !== -1;
|
|
187
|
+
},
|
|
188
|
+
getInput: function () {
|
|
189
|
+
return null;
|
|
190
|
+
},
|
|
191
|
+
getSendButton: function () {
|
|
192
|
+
return null;
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
if (overrides) {
|
|
196
|
+
for (var k in overrides) {
|
|
197
|
+
if (Object.prototype.hasOwnProperty.call(overrides, k)) base[k] = overrides[k];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return base;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ── Handle lifecycle ───────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
var handleMap = typeof WeakMap !== 'undefined' ? new WeakMap() : null;
|
|
206
|
+
|
|
207
|
+
function trackHandle(el, handle) {
|
|
208
|
+
if (!handleMap) return;
|
|
209
|
+
var existing = handleMap.get(el) || [];
|
|
210
|
+
existing.push(handle);
|
|
211
|
+
handleMap.set(el, existing);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function destroy(el) {
|
|
215
|
+
if (!handleMap) return;
|
|
216
|
+
var handles = handleMap.get(el);
|
|
217
|
+
if (!handles) return;
|
|
218
|
+
handles.forEach(function (h) {
|
|
219
|
+
try {
|
|
220
|
+
h.destroy();
|
|
221
|
+
} catch {
|
|
222
|
+
/* a renderer that cannot tear down must not block the rest */
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
handleMap.delete(el);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function errorBox(message) {
|
|
229
|
+
return (
|
|
230
|
+
'<pre style="color:#f66;font-size:0.85em;padding:0.5em;">' + escapeHtml(message) + '</pre>'
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function callOptional(adapter, name, args) {
|
|
235
|
+
if (adapter && typeof adapter[name] === 'function') {
|
|
236
|
+
return adapter[name].apply(adapter, args);
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Render extracted blocks into the placeholder containers inside `el`.
|
|
243
|
+
*
|
|
244
|
+
* opts: { msgKey, streaming, keyPrefix }
|
|
245
|
+
*/
|
|
246
|
+
function render(el, blocks, adapter, opts) {
|
|
247
|
+
if (!blocks || blocks.length === 0) return;
|
|
248
|
+
// Contract violation, checked before the library guard: an adapter without
|
|
249
|
+
// allowType is a programming error and must surface whether or not blex
|
|
250
|
+
// happened to load, otherwise it hides until the first page that has blex.
|
|
251
|
+
if (!adapter || typeof adapter.allowType !== 'function') {
|
|
252
|
+
throw new Error('[blex] render() requires an adapter with allowType()');
|
|
253
|
+
}
|
|
254
|
+
if (typeof global.Blex === 'undefined') {
|
|
255
|
+
// The raw-fence fallback is already in the DOM, so the reader sees the
|
|
256
|
+
// payload rather than a blank box. warn, not error: some embedders fail
|
|
257
|
+
// their build gate on any console error.
|
|
258
|
+
console.warn('[blex] library not loaded — leaving raw fences in place');
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
var options = opts || {};
|
|
262
|
+
var streaming = !!options.streaming;
|
|
263
|
+
var msgKey = options.msgKey;
|
|
264
|
+
|
|
265
|
+
var containers = el.querySelectorAll('.blex-block-container');
|
|
266
|
+
Array.prototype.forEach.call(containers, function (container) {
|
|
267
|
+
var idx = parseInt(container.getAttribute('data-blex-idx'), 10);
|
|
268
|
+
if (isNaN(idx) || idx >= blocks.length) return;
|
|
269
|
+
var block = blocks[idx];
|
|
270
|
+
if (!adapter.allowType(block.type)) {
|
|
271
|
+
// Deliberately unclaimed — the raw fence stays visible.
|
|
272
|
+
console.warn('[blex] type not rendered on this surface: ' + block.type);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
var storeKey = msgKey ? msgKey + ':' + idx : null;
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
var data = JSON.parse(block.json);
|
|
279
|
+
var blockObj = { type: block.type, id: block.type + '-' + idx, data: data };
|
|
280
|
+
|
|
281
|
+
// Claim the container: drop the raw-fence fallback. Bad JSON throws
|
|
282
|
+
// before this line and is reported by the catch below, which names the
|
|
283
|
+
// problem — better than either the fallback or a blank box.
|
|
284
|
+
container.innerHTML = '';
|
|
285
|
+
|
|
286
|
+
if (streaming) {
|
|
287
|
+
global.Blex.renderPlaceholder(block.type, container);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
var renderOpts = {};
|
|
292
|
+
var previous = callOptional(adapter, 'readPersisted', [storeKey]);
|
|
293
|
+
if (previous !== undefined) renderOpts.previousValue = previous;
|
|
294
|
+
|
|
295
|
+
global.Blex.renderBlock(blockObj, container, renderOpts)
|
|
296
|
+
.then(function (handle) {
|
|
297
|
+
trackHandle(el, handle);
|
|
298
|
+
callOptional(adapter, 'onRendered', [container, storeKey]);
|
|
299
|
+
if (!handle || !handle.onInteraction) return;
|
|
300
|
+
handle.onInteraction(function (interaction) {
|
|
301
|
+
if (storeKey && interaction.value !== undefined) {
|
|
302
|
+
callOptional(adapter, 'persist', [storeKey, interaction.value]);
|
|
303
|
+
}
|
|
304
|
+
if (!interaction.serialized) return;
|
|
305
|
+
var inputEl = adapter.getInput();
|
|
306
|
+
if (!inputEl) return;
|
|
307
|
+
if (interaction.immediate) {
|
|
308
|
+
var existingText = (inputEl.value || '').trim();
|
|
309
|
+
inputEl.value = existingText
|
|
310
|
+
? existingText + '\n\n' + interaction.serialized
|
|
311
|
+
: interaction.serialized;
|
|
312
|
+
inputEl.dispatchEvent(new Event('input', { bubbles: true }));
|
|
313
|
+
var sendBtn = adapter.getSendButton();
|
|
314
|
+
if (sendBtn) sendBtn.click();
|
|
315
|
+
} else {
|
|
316
|
+
callOptional(adapter, 'addChip', [interaction, handle, block.type + '-' + idx]);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
})
|
|
320
|
+
.catch(function (err) {
|
|
321
|
+
container.innerHTML = errorBox('Blex error: ' + (err.message || err));
|
|
322
|
+
});
|
|
323
|
+
} catch (e) {
|
|
324
|
+
container.innerHTML = errorBox('Invalid blex JSON: ' + e.message);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
global.CumulusBlexRender = {
|
|
330
|
+
extractBlocks: extractBlocks,
|
|
331
|
+
placeholderHtml: placeholderHtml,
|
|
332
|
+
insertPlaceholders: insertPlaceholders,
|
|
333
|
+
fenceSource: fenceSource,
|
|
334
|
+
render: render,
|
|
335
|
+
destroy: destroy,
|
|
336
|
+
renderOnlyAdapter: renderOnlyAdapter,
|
|
337
|
+
RENDER_ONLY_TYPES: RENDER_ONLY_TYPES,
|
|
338
|
+
INTERACTIVE_TYPES: INTERACTIVE_TYPES,
|
|
339
|
+
CODE_FENCE_SRC: CODE_FENCE_SRC,
|
|
340
|
+
};
|
|
341
|
+
})(typeof window !== 'undefined' ? window : globalThis);
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
</head>
|
|
25
25
|
<body>
|
|
26
26
|
<script src="/blex.min.js" onload="console.log('[blex] blex.min.js loaded, Blex:', typeof Blex)" onerror="console.error('[blex] FAILED to load blex.min.js')"></script>
|
|
27
|
+
<script src="/blex-render.js"></script>
|
|
27
28
|
<script src="/widget.js" data-standalone="true" data-api-key=""></script>
|
|
28
29
|
</body>
|
|
29
30
|
</html>
|