@wcomp/elementum 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +266 -2
- package/custom-elements.json +3613 -0
- package/mcp/server.js +408 -0
- package/package.json +72 -4
- package/skills/elementum-break-ui/CATALOG.md +11 -0
- package/skills/elementum-break-ui/SKILL.md +16 -0
- package/skills/elementum-mobile/SKILL.md +18 -0
- package/skills/elementum-motion/SKILL.md +18 -0
- package/skills/elementum-motion/STANDARDS.md +15 -0
- package/skills/elementum-penpot/SKILL.md +45 -0
- package/skills/elementum-ui/CATALOG.md +14 -0
- package/skills/elementum-ui/SKILL.md +21 -0
- package/src/ag-ui.js +474 -0
- package/src/components/el-accordion.js +201 -0
- package/src/components/el-alert-dialog.js +186 -0
- package/src/components/el-alert.js +254 -0
- package/src/components/el-aspect-ratio.js +73 -0
- package/src/components/el-autocomplete.js +775 -0
- package/src/components/el-avatar.js +271 -0
- package/src/components/el-badge.js +131 -0
- package/src/components/el-border-beam.js +135 -0
- package/src/components/el-breadcrumb.js +203 -0
- package/src/components/el-button.js +220 -0
- package/src/components/el-calendar.js +413 -0
- package/src/components/el-callout.js +158 -0
- package/src/components/el-card.js +298 -0
- package/src/components/el-carousel.js +308 -0
- package/src/components/el-chart.js +632 -0
- package/src/components/el-checkbox-card.js +221 -0
- package/src/components/el-checkbox.js +208 -0
- package/src/components/el-chip.js +276 -0
- package/src/components/el-code-block.js +228 -0
- package/src/components/el-collapsible.js +124 -0
- package/src/components/el-command.js +556 -0
- package/src/components/el-context-menu.js +328 -0
- package/src/components/el-data-list.js +210 -0
- package/src/components/el-datepicker.js +192 -0
- package/src/components/el-dialog.js +272 -0
- package/src/components/el-diff-viewer.js +441 -0
- package/src/components/el-drawer.js +782 -0
- package/src/components/el-dropdown.js +182 -0
- package/src/components/el-dropzone.js +242 -0
- package/src/components/el-empty-state.js +130 -0
- package/src/components/el-field.js +394 -0
- package/src/components/el-form.js +185 -0
- package/src/components/el-input.js +212 -0
- package/src/components/el-inset.js +90 -0
- package/src/components/el-insight-card.js +263 -0
- package/src/components/el-kbd.js +151 -0
- package/src/components/el-menubar.js +254 -0
- package/src/components/el-meter.js +182 -0
- package/src/components/el-navbar.js +294 -0
- package/src/components/el-navigation-menu.js +327 -0
- package/src/components/el-number-field.js +510 -0
- package/src/components/el-number-flow.js +153 -0
- package/src/components/el-otp-input.js +266 -0
- package/src/components/el-pagination.js +229 -0
- package/src/components/el-popover.js +288 -0
- package/src/components/el-preview-card.js +202 -0
- package/src/components/el-progress.js +179 -0
- package/src/components/el-prompt-input.js +383 -0
- package/src/components/el-radio-card.js +360 -0
- package/src/components/el-radio.js +257 -0
- package/src/components/el-rating.js +165 -0
- package/src/components/el-reasoning-card.js +293 -0
- package/src/components/el-resizable.js +324 -0
- package/src/components/el-router.js +305 -0
- package/src/components/el-scroll-area.js +150 -0
- package/src/components/el-segmented-control.js +282 -0
- package/src/components/el-select.js +219 -0
- package/src/components/el-separator.js +85 -0
- package/src/components/el-sidebar.js +386 -0
- package/src/components/el-skeleton.js +156 -0
- package/src/components/el-slider.js +351 -0
- package/src/components/el-sources.js +288 -0
- package/src/components/el-spinner.js +159 -0
- package/src/components/el-streaming-text.js +199 -0
- package/src/components/el-switch.js +221 -0
- package/src/components/el-table.js +397 -0
- package/src/components/el-tabs.js +235 -0
- package/src/components/el-task-list.js +230 -0
- package/src/components/el-textarea.js +175 -0
- package/src/components/el-theme-switch.js +120 -0
- package/src/components/el-timeline.js +254 -0
- package/src/components/el-toast.js +778 -0
- package/src/components/el-toggle.js +311 -0
- package/src/components/el-tool-call.js +386 -0
- package/src/components/el-toolbar.js +183 -0
- package/src/components/el-tooltip.js +172 -0
- package/src/components/el-tree-view.js +261 -0
- package/src/components/el-visually-hidden.js +32 -0
- package/src/elementum.js +485 -0
- package/src/index.d.ts +1007 -0
- package/src/index.js +99 -0
- package/src/signal.js +194 -0
- package/src/ssr.js +136 -0
- package/src/template.js +321 -0
- package/src/tokens.css +416 -0
- package/tokens/figma-tokens.json +69 -0
- package/tokens/penpot-tokens.json +98 -0
package/src/ag-ui.js
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AG-UI (Agent-User Interaction Protocol) Adapter for @wcomp/elementum
|
|
3
|
+
* Bridges streaming AG-UI events (RUN_*, STEP_*, TEXT_MESSAGE_*, TOOL_CALL_*, STATE_*)
|
|
4
|
+
* into fine-grained Elementum micro-signals and Web Component properties.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { signal, isSignal } from './signal.js';
|
|
8
|
+
|
|
9
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
10
|
+
|
|
11
|
+
function cloneValue(val) {
|
|
12
|
+
if (val === null || typeof val !== 'object') return val;
|
|
13
|
+
if (typeof structuredClone === 'function') {
|
|
14
|
+
return structuredClone(val);
|
|
15
|
+
}
|
|
16
|
+
return JSON.parse(JSON.stringify(val));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function decodePointerToken(token) {
|
|
20
|
+
return String(token).replace(/~1/g, '/').replace(/~0/g, '~');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parsePointer(pointer) {
|
|
24
|
+
if (!pointer || pointer === '/') return pointer === '/' ? [''] : [];
|
|
25
|
+
const raw = String(pointer);
|
|
26
|
+
const parts = (raw.startsWith('/') ? raw.slice(1) : raw).split('/');
|
|
27
|
+
return parts.map(decodePointerToken);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve an RFC 6901 JSON Pointer against an object.
|
|
32
|
+
*/
|
|
33
|
+
export function getByPointer(obj, pointer) {
|
|
34
|
+
if (!pointer) return obj;
|
|
35
|
+
const tokens = parsePointer(pointer);
|
|
36
|
+
let cur = obj;
|
|
37
|
+
for (const key of tokens) {
|
|
38
|
+
if (cur === null || typeof cur !== 'object' || FORBIDDEN_KEYS.has(key)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
cur = cur[key];
|
|
42
|
+
}
|
|
43
|
+
return cur;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Apply an array of RFC 6902 JSON Patch operations immutably to a target object.
|
|
48
|
+
*/
|
|
49
|
+
export function applyJsonPatch(target, patch = []) {
|
|
50
|
+
let root = cloneValue(target ?? {});
|
|
51
|
+
if (!Array.isArray(patch) || patch.length === 0) return root;
|
|
52
|
+
|
|
53
|
+
for (const operation of patch) {
|
|
54
|
+
if (!operation || !operation.op) continue;
|
|
55
|
+
const tokens = parsePointer(operation.path);
|
|
56
|
+
if (tokens.length === 0) {
|
|
57
|
+
if (operation.op === 'replace' || operation.op === 'add') {
|
|
58
|
+
root = cloneValue(operation.value);
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (tokens.some((t) => FORBIDDEN_KEYS.has(t))) continue;
|
|
64
|
+
|
|
65
|
+
let parent = root;
|
|
66
|
+
for (let i = 0; i < tokens.length - 1; i++) {
|
|
67
|
+
const seg = tokens[i];
|
|
68
|
+
if (parent[seg] === undefined || parent[seg] === null || typeof parent[seg] !== 'object') {
|
|
69
|
+
parent[seg] = Number.isInteger(Number(tokens[i + 1])) ? [] : {};
|
|
70
|
+
}
|
|
71
|
+
parent = parent[seg];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const last = tokens[tokens.length - 1];
|
|
75
|
+
const op = operation.op;
|
|
76
|
+
|
|
77
|
+
if (op === 'remove') {
|
|
78
|
+
if (Array.isArray(parent)) {
|
|
79
|
+
const idx = Number(last);
|
|
80
|
+
if (Number.isInteger(idx) && idx >= 0 && idx < parent.length) {
|
|
81
|
+
parent.splice(idx, 1);
|
|
82
|
+
}
|
|
83
|
+
} else if (parent && typeof parent === 'object') {
|
|
84
|
+
delete parent[last];
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (op === 'add' || op === 'replace') {
|
|
90
|
+
const nextVal = cloneValue(operation.value);
|
|
91
|
+
if (Array.isArray(parent)) {
|
|
92
|
+
if (last === '-') {
|
|
93
|
+
parent.push(nextVal);
|
|
94
|
+
} else {
|
|
95
|
+
const idx = Number(last);
|
|
96
|
+
if (Number.isInteger(idx) && idx >= 0) {
|
|
97
|
+
if (op === 'add' && idx <= parent.length) {
|
|
98
|
+
parent.splice(idx, 0, nextVal);
|
|
99
|
+
} else {
|
|
100
|
+
parent[idx] = nextVal;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else if (parent && typeof parent === 'object') {
|
|
105
|
+
parent[last] = nextVal;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return root;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function setElementProp(el, prop, value) {
|
|
114
|
+
if (!el) return;
|
|
115
|
+
const targetProp = el[prop];
|
|
116
|
+
if (isSignal(targetProp)) {
|
|
117
|
+
targetProp.value = value;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const attrName = prop.replace(/[A-Z]/g, (ch) => `-${ch.toLowerCase()}`);
|
|
121
|
+
if (typeof value === 'boolean') {
|
|
122
|
+
if (value) el.setAttribute(attrName, '');
|
|
123
|
+
else el.removeAttribute(attrName);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
el[prop] = value;
|
|
127
|
+
if (typeof value !== 'object' && value !== null && value !== undefined) {
|
|
128
|
+
el.setAttribute(attrName, String(value));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Create a reactive Elementum signal store for an AG-UI session.
|
|
134
|
+
*/
|
|
135
|
+
export function createAgUiStore(initialState = {}) {
|
|
136
|
+
const state = signal(cloneValue(initialState));
|
|
137
|
+
const status = signal('idle');
|
|
138
|
+
const runId = signal('');
|
|
139
|
+
const stepName = signal('');
|
|
140
|
+
const thinking = signal(false);
|
|
141
|
+
const thinkingText = signal('');
|
|
142
|
+
const currentText = signal('');
|
|
143
|
+
const messages = signal([]);
|
|
144
|
+
const toolCalls = signal([]);
|
|
145
|
+
const error = signal(null);
|
|
146
|
+
const events = signal([]);
|
|
147
|
+
|
|
148
|
+
const listeners = new Set();
|
|
149
|
+
|
|
150
|
+
function upsertToolCall(callId, updater) {
|
|
151
|
+
const list = [...toolCalls.peek()];
|
|
152
|
+
const idx = list.findIndex((tc) => tc.id === callId);
|
|
153
|
+
if (idx === -1) {
|
|
154
|
+
list.push(updater({ id: callId, name: 'tool_call', args: '', result: '', status: 'running', approval: false }));
|
|
155
|
+
} else {
|
|
156
|
+
list[idx] = updater({ ...list[idx] });
|
|
157
|
+
}
|
|
158
|
+
toolCalls.value = list;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function dispatch(event) {
|
|
162
|
+
if (!event || !event.type) return;
|
|
163
|
+
events.value = [...events.peek(), event];
|
|
164
|
+
|
|
165
|
+
switch (event.type) {
|
|
166
|
+
case 'RUN_STARTED':
|
|
167
|
+
status.value = 'running';
|
|
168
|
+
runId.value = event.runId || '';
|
|
169
|
+
error.value = null;
|
|
170
|
+
break;
|
|
171
|
+
|
|
172
|
+
case 'RUN_FINISHED':
|
|
173
|
+
status.value = 'finished';
|
|
174
|
+
thinking.value = false;
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case 'RUN_ERROR':
|
|
178
|
+
status.value = 'error';
|
|
179
|
+
error.value = event.message || 'AG-UI run error';
|
|
180
|
+
thinking.value = false;
|
|
181
|
+
break;
|
|
182
|
+
|
|
183
|
+
case 'STEP_STARTED':
|
|
184
|
+
case 'THINKING_START':
|
|
185
|
+
thinking.value = true;
|
|
186
|
+
if (event.stepName || event.title) {
|
|
187
|
+
stepName.value = event.stepName || event.title;
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
|
|
191
|
+
case 'THINKING_TEXT_MESSAGE_CONTENT':
|
|
192
|
+
thinkingText.value = thinkingText.peek() + (event.delta || '');
|
|
193
|
+
break;
|
|
194
|
+
|
|
195
|
+
case 'STEP_FINISHED':
|
|
196
|
+
case 'THINKING_END':
|
|
197
|
+
thinking.value = false;
|
|
198
|
+
break;
|
|
199
|
+
|
|
200
|
+
case 'TEXT_MESSAGE_START': {
|
|
201
|
+
const msgId = event.messageId || `msg-${Date.now()}`;
|
|
202
|
+
currentText.value = '';
|
|
203
|
+
messages.value = [
|
|
204
|
+
...messages.peek(),
|
|
205
|
+
{ id: msgId, role: event.role || 'assistant', content: '' },
|
|
206
|
+
];
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
case 'TEXT_MESSAGE_CONTENT': {
|
|
211
|
+
const delta = event.delta || '';
|
|
212
|
+
const nextText = currentText.peek() + delta;
|
|
213
|
+
currentText.value = nextText;
|
|
214
|
+
|
|
215
|
+
const list = [...messages.peek()];
|
|
216
|
+
const msgId = event.messageId;
|
|
217
|
+
let idx = msgId ? list.findIndex((m) => m.id === msgId) : list.length - 1;
|
|
218
|
+
if (idx === -1) {
|
|
219
|
+
list.push({ id: msgId || `msg-${Date.now()}`, role: 'assistant', content: nextText });
|
|
220
|
+
} else {
|
|
221
|
+
list[idx] = { ...list[idx], content: (list[idx].content || '') + delta };
|
|
222
|
+
}
|
|
223
|
+
messages.value = list;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
case 'TEXT_MESSAGE_END':
|
|
228
|
+
break;
|
|
229
|
+
|
|
230
|
+
case 'TOOL_CALL_START': {
|
|
231
|
+
const callId = event.toolCallId || `tc-${toolCalls.peek().length + 1}`;
|
|
232
|
+
const requiresApproval = Boolean(event.requiresApproval);
|
|
233
|
+
upsertToolCall(callId, (prev) => ({
|
|
234
|
+
...prev,
|
|
235
|
+
name: event.toolCallName || event.name || prev.name,
|
|
236
|
+
args: '',
|
|
237
|
+
result: '',
|
|
238
|
+
approval: requiresApproval,
|
|
239
|
+
status: requiresApproval ? 'awaiting-approval' : 'running',
|
|
240
|
+
}));
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
case 'TOOL_CALL_ARGS': {
|
|
245
|
+
const callId = event.toolCallId || toolCalls.peek().at(-1)?.id || 'tc-1';
|
|
246
|
+
upsertToolCall(callId, (prev) => ({
|
|
247
|
+
...prev,
|
|
248
|
+
args: (prev.args || '') + (event.delta || ''),
|
|
249
|
+
}));
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
case 'TOOL_CALL_END': {
|
|
254
|
+
const callId = event.toolCallId || toolCalls.peek().at(-1)?.id || 'tc-1';
|
|
255
|
+
upsertToolCall(callId, (prev) => ({
|
|
256
|
+
...prev,
|
|
257
|
+
status: prev.approval ? 'awaiting-approval' : (event.status || 'completed'),
|
|
258
|
+
}));
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
case 'TOOL_CALL_RESULT': {
|
|
263
|
+
const callId = event.toolCallId || toolCalls.peek().at(-1)?.id || 'tc-1';
|
|
264
|
+
const resVal = typeof event.result === 'string' ? event.result : JSON.stringify(event.result ?? '', null, 2);
|
|
265
|
+
upsertToolCall(callId, (prev) => ({
|
|
266
|
+
...prev,
|
|
267
|
+
result: resVal,
|
|
268
|
+
approval: false,
|
|
269
|
+
status: event.status || 'completed',
|
|
270
|
+
}));
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
case 'STATE_SNAPSHOT':
|
|
275
|
+
state.value = cloneValue(event.snapshot || {});
|
|
276
|
+
break;
|
|
277
|
+
|
|
278
|
+
case 'STATE_DELTA':
|
|
279
|
+
state.value = applyJsonPatch(state.peek(), event.delta || []);
|
|
280
|
+
break;
|
|
281
|
+
|
|
282
|
+
case 'MESSAGES_SNAPSHOT':
|
|
283
|
+
messages.value = Array.isArray(event.messages) ? cloneValue(event.messages) : [];
|
|
284
|
+
break;
|
|
285
|
+
|
|
286
|
+
default:
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
for (const fn of listeners) {
|
|
291
|
+
fn(event);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function pathSignal(pointer, fallback = undefined) {
|
|
296
|
+
const initial = getByPointer(state.peek(), pointer);
|
|
297
|
+
const derived = signal(initial !== undefined ? initial : fallback);
|
|
298
|
+
state.subscribe((nextState) => {
|
|
299
|
+
const val = getByPointer(nextState, pointer);
|
|
300
|
+
derived.value = val !== undefined ? val : fallback;
|
|
301
|
+
});
|
|
302
|
+
return derived;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function onEvent(listener) {
|
|
306
|
+
listeners.add(listener);
|
|
307
|
+
return () => listeners.delete(listener);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function bindComponents({
|
|
311
|
+
promptInput = null,
|
|
312
|
+
streamingText = null,
|
|
313
|
+
reasoningCard = null,
|
|
314
|
+
toolCallCard = null,
|
|
315
|
+
stateBindings = {},
|
|
316
|
+
} = {}) {
|
|
317
|
+
const unsubs = [];
|
|
318
|
+
|
|
319
|
+
if (promptInput) {
|
|
320
|
+
unsubs.push(
|
|
321
|
+
status.subscribe((st) => {
|
|
322
|
+
setElementProp(promptInput, 'loading', st === 'running');
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (streamingText) {
|
|
328
|
+
unsubs.push(
|
|
329
|
+
status.subscribe((st) => {
|
|
330
|
+
if (st !== 'running') {
|
|
331
|
+
if (isSignal(streamingText.isStreaming)) streamingText.isStreaming.value = false;
|
|
332
|
+
if (currentText.peek() && isSignal(streamingText.isComplete)) streamingText.isComplete.value = true;
|
|
333
|
+
}
|
|
334
|
+
}),
|
|
335
|
+
currentText.subscribe((txt) => {
|
|
336
|
+
if (isSignal(streamingText.text)) {
|
|
337
|
+
streamingText.text.value = txt;
|
|
338
|
+
} else {
|
|
339
|
+
streamingText.setAttribute?.('text', txt);
|
|
340
|
+
}
|
|
341
|
+
if (isSignal(streamingText.displayedText)) {
|
|
342
|
+
streamingText.displayedText.value = txt;
|
|
343
|
+
}
|
|
344
|
+
if (isSignal(streamingText.isStreaming)) {
|
|
345
|
+
streamingText.isStreaming.value = status.peek() === 'running';
|
|
346
|
+
}
|
|
347
|
+
if (isSignal(streamingText.isComplete)) {
|
|
348
|
+
streamingText.isComplete.value = status.peek() !== 'running' && Boolean(txt);
|
|
349
|
+
}
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (reasoningCard) {
|
|
355
|
+
unsubs.push(
|
|
356
|
+
thinking.subscribe((isThinking) => {
|
|
357
|
+
setElementProp(reasoningCard, 'thinking', isThinking);
|
|
358
|
+
}),
|
|
359
|
+
stepName.subscribe((summary) => {
|
|
360
|
+
if (summary) setElementProp(reasoningCard, 'summary', summary);
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (toolCallCard) {
|
|
366
|
+
unsubs.push(
|
|
367
|
+
toolCalls.subscribe((list) => {
|
|
368
|
+
const latest = list.at(-1);
|
|
369
|
+
if (!latest) return;
|
|
370
|
+
setElementProp(toolCallCard, 'callId', latest.id);
|
|
371
|
+
setElementProp(toolCallCard, 'name', latest.name);
|
|
372
|
+
setElementProp(toolCallCard, 'status', latest.status);
|
|
373
|
+
setElementProp(toolCallCard, 'args', latest.args);
|
|
374
|
+
setElementProp(toolCallCard, 'result', latest.result);
|
|
375
|
+
setElementProp(toolCallCard, 'approval', Boolean(latest.approval));
|
|
376
|
+
})
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
for (const [pointer, binding] of Object.entries(stateBindings)) {
|
|
381
|
+
if (!binding) continue;
|
|
382
|
+
const [el, propName = 'value'] = Array.isArray(binding) ? binding : [binding.element, binding.prop || 'value'];
|
|
383
|
+
if (!el) continue;
|
|
384
|
+
const pSig = pathSignal(pointer);
|
|
385
|
+
unsubs.push(
|
|
386
|
+
pSig.subscribe((val) => {
|
|
387
|
+
if (val !== undefined) {
|
|
388
|
+
setElementProp(el, propName, val);
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return () => {
|
|
395
|
+
for (const unsub of unsubs) unsub();
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async function connectSSE(source) {
|
|
400
|
+
if (!source) return;
|
|
401
|
+
|
|
402
|
+
// 1. Fetch Response or ReadableStream of bytes
|
|
403
|
+
const stream = typeof source.getReader === 'function'
|
|
404
|
+
? source
|
|
405
|
+
: (source.body && typeof source.body.getReader === 'function' ? source.body : null);
|
|
406
|
+
|
|
407
|
+
if (stream) {
|
|
408
|
+
const reader = stream.getReader();
|
|
409
|
+
const decoder = new TextDecoder();
|
|
410
|
+
let buffer = '';
|
|
411
|
+
|
|
412
|
+
while (true) {
|
|
413
|
+
const { done, value } = await reader.read();
|
|
414
|
+
if (done) break;
|
|
415
|
+
buffer += typeof value === 'string' ? value : decoder.decode(value, { stream: true });
|
|
416
|
+
const lines = buffer.split(/\r?\n/);
|
|
417
|
+
buffer = lines.pop() ?? '';
|
|
418
|
+
for (const line of lines) {
|
|
419
|
+
const trimmed = line.trim();
|
|
420
|
+
if (trimmed.startsWith('data:')) {
|
|
421
|
+
const payload = trimmed.slice(5).trim();
|
|
422
|
+
if (payload && payload !== '[DONE]') {
|
|
423
|
+
dispatch(JSON.parse(payload));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (buffer.trim().startsWith('data:')) {
|
|
430
|
+
const payload = buffer.trim().slice(5).trim();
|
|
431
|
+
if (payload && payload !== '[DONE]') {
|
|
432
|
+
dispatch(JSON.parse(payload));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 2. Async or sync iterable of AG-UI event objects or SSE strings
|
|
439
|
+
for await (const chunk of source) {
|
|
440
|
+
if (typeof chunk === 'string') {
|
|
441
|
+
for (const line of chunk.split(/\r?\n/)) {
|
|
442
|
+
const trimmed = line.trim();
|
|
443
|
+
if (trimmed.startsWith('data:')) {
|
|
444
|
+
const payload = trimmed.slice(5).trim();
|
|
445
|
+
if (payload && payload !== '[DONE]') {
|
|
446
|
+
dispatch(JSON.parse(payload));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
} else if (chunk && typeof chunk === 'object') {
|
|
451
|
+
dispatch(chunk);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return {
|
|
457
|
+
state,
|
|
458
|
+
status,
|
|
459
|
+
runId,
|
|
460
|
+
stepName,
|
|
461
|
+
thinking,
|
|
462
|
+
thinkingText,
|
|
463
|
+
currentText,
|
|
464
|
+
messages,
|
|
465
|
+
toolCalls,
|
|
466
|
+
error,
|
|
467
|
+
events,
|
|
468
|
+
dispatch,
|
|
469
|
+
pathSignal,
|
|
470
|
+
onEvent,
|
|
471
|
+
bindComponents,
|
|
472
|
+
connectSSE,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <el-accordion> and <el-accordion-item>
|
|
3
|
+
* Accessible disclosure/accordion components following W3C patterns.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Elementum } from '../elementum.js';
|
|
7
|
+
import { html, css } from '../template.js';
|
|
8
|
+
import { signal } from '../signal.js';
|
|
9
|
+
|
|
10
|
+
let nextItemId = 0;
|
|
11
|
+
|
|
12
|
+
export class ElAccordionItem extends Elementum {
|
|
13
|
+
static observedAttributes = ['title', 'heading', 'value', 'open', 'disabled'];
|
|
14
|
+
|
|
15
|
+
itemTitle = signal('');
|
|
16
|
+
value = signal('');
|
|
17
|
+
isOpen = signal(false);
|
|
18
|
+
disabled = signal(false);
|
|
19
|
+
|
|
20
|
+
#id = `el-acc-item-${++nextItemId}`;
|
|
21
|
+
|
|
22
|
+
static styles = css`
|
|
23
|
+
:host {
|
|
24
|
+
display: block;
|
|
25
|
+
border-bottom: 1px solid var(--el-surface-border, #e5e7eb);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:host(:last-of-type) {
|
|
29
|
+
border-bottom: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.header-btn {
|
|
33
|
+
width: 100%;
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: space-between;
|
|
37
|
+
padding: var(--el-spacing-md, 16px) 0;
|
|
38
|
+
background: none;
|
|
39
|
+
border: none;
|
|
40
|
+
font-family: inherit;
|
|
41
|
+
font-size: 1rem;
|
|
42
|
+
font-weight: 600;
|
|
43
|
+
color: var(--el-text-base, #111827);
|
|
44
|
+
text-align: left;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
outline: none;
|
|
47
|
+
transition: color 0.15s ease;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.header-btn:hover:not(:disabled) {
|
|
51
|
+
color: var(--el-color-primary, #2563eb);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.header-btn:focus-visible {
|
|
55
|
+
outline: 2px solid var(--el-color-primary, #2563eb);
|
|
56
|
+
outline-offset: 2px;
|
|
57
|
+
border-radius: var(--el-radius-sm, 4px);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.header-btn:disabled {
|
|
61
|
+
cursor: not-allowed;
|
|
62
|
+
opacity: 0.5;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.chevron {
|
|
66
|
+
font-size: 0.75rem;
|
|
67
|
+
transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
68
|
+
color: var(--el-text-muted, #6b7280);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.chevron.open {
|
|
72
|
+
transform: rotate(180deg);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.panel {
|
|
76
|
+
display: none;
|
|
77
|
+
padding-bottom: var(--el-spacing-md, 16px);
|
|
78
|
+
color: var(--el-text-base, #374151);
|
|
79
|
+
font-size: 0.9375rem;
|
|
80
|
+
line-height: 1.6;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.panel.open {
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
connected() {
|
|
89
|
+
this.itemTitle.value = this.getAttribute('title') || this.getAttribute('heading') || '';
|
|
90
|
+
this.value.value = this.getAttribute('value') || this.#id;
|
|
91
|
+
this.isOpen.value = this.hasAttribute('open');
|
|
92
|
+
this.disabled.value = this.hasAttribute('disabled');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
attributeChanged(name, oldValue, newValue) {
|
|
96
|
+
if (name === 'open') {
|
|
97
|
+
this.isOpen.value = newValue !== null && newValue !== 'false';
|
|
98
|
+
} else if (name === 'title' || name === 'heading') {
|
|
99
|
+
this.itemTitle.value = newValue || '';
|
|
100
|
+
} else if (name === 'disabled') {
|
|
101
|
+
this.disabled.value = newValue !== null && newValue !== 'false';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
toggle() {
|
|
106
|
+
if (this.disabled.value) return;
|
|
107
|
+
this.isOpen.value = !this.isOpen.value;
|
|
108
|
+
if (this.isOpen.value) {
|
|
109
|
+
this.setAttribute('open', '');
|
|
110
|
+
} else {
|
|
111
|
+
this.removeAttribute('open');
|
|
112
|
+
}
|
|
113
|
+
this.emit('toggle', { value: this.value.value, open: this.isOpen.value });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
render() {
|
|
117
|
+
const buttonId = `${this.#id}-btn`;
|
|
118
|
+
const panelId = `${this.#id}-panel`;
|
|
119
|
+
|
|
120
|
+
return html`
|
|
121
|
+
<button
|
|
122
|
+
type="button"
|
|
123
|
+
id=${buttonId}
|
|
124
|
+
class="header-btn"
|
|
125
|
+
part="header"
|
|
126
|
+
?disabled=${this.disabled}
|
|
127
|
+
aria-expanded=${() => (this.isOpen.value ? 'true' : 'false')}
|
|
128
|
+
aria-controls=${panelId}
|
|
129
|
+
@click=${() => this.toggle()}
|
|
130
|
+
>
|
|
131
|
+
<span part="title"><slot name="title">${this.itemTitle}</slot></span>
|
|
132
|
+
<span class=${() => `chevron ${this.isOpen.value ? 'open' : ''}`} part="chevron">▼</span>
|
|
133
|
+
</button>
|
|
134
|
+
<div
|
|
135
|
+
id=${panelId}
|
|
136
|
+
role="region"
|
|
137
|
+
aria-labelledby=${buttonId}
|
|
138
|
+
class=${() => `panel ${this.isOpen.value ? 'open' : ''}`}
|
|
139
|
+
part="panel"
|
|
140
|
+
>
|
|
141
|
+
<slot></slot>
|
|
142
|
+
</div>
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-accordion-item')) {
|
|
148
|
+
customElements.define('el-accordion-item', ElAccordionItem);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class ElAccordion extends Elementum {
|
|
152
|
+
static observedAttributes = ['multiple'];
|
|
153
|
+
|
|
154
|
+
multiple = signal(false);
|
|
155
|
+
|
|
156
|
+
static styles = css`
|
|
157
|
+
:host {
|
|
158
|
+
display: block;
|
|
159
|
+
border: 1px solid var(--el-surface-border, #e5e7eb);
|
|
160
|
+
border-radius: var(--el-radius-md, 8px);
|
|
161
|
+
padding: 0 var(--el-spacing-md, 16px);
|
|
162
|
+
background: var(--el-surface-base, #ffffff);
|
|
163
|
+
}
|
|
164
|
+
`;
|
|
165
|
+
|
|
166
|
+
connected() {
|
|
167
|
+
this.multiple.value = this.hasAttribute('multiple');
|
|
168
|
+
this.addEventListener('toggle', this.#onItemToggle);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
attributeChanged(name, oldValue, newValue) {
|
|
172
|
+
if (name === 'multiple') {
|
|
173
|
+
this.multiple.value = newValue !== null && newValue !== 'false';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
#onItemToggle = (e) => {
|
|
178
|
+
// If not multiple and this item opened, close all other items
|
|
179
|
+
if (!this.multiple.value && e.detail.open) {
|
|
180
|
+
const items = this.querySelectorAll('el-accordion-item');
|
|
181
|
+
for (const item of items) {
|
|
182
|
+
if (item !== e.target && item.isOpen.value) {
|
|
183
|
+
item.isOpen.value = false;
|
|
184
|
+
item.removeAttribute('open');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
this.emit('change', {
|
|
189
|
+
value: e.detail.value,
|
|
190
|
+
open: e.detail.open,
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
render() {
|
|
195
|
+
return html`<slot></slot>`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (typeof customElements !== 'undefined' && !customElements.get('el-accordion')) {
|
|
200
|
+
customElements.define('el-accordion', ElAccordion);
|
|
201
|
+
}
|