@zhama/a2ui-core 0.1.0 → 0.3.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 +95 -22
- package/dist/builders/index.cjs +3 -496
- package/dist/builders/index.d.cts +8 -13
- package/dist/builders/index.d.ts +8 -13
- package/dist/builders/index.js +3 -445
- package/dist/index.cjs +3 -869
- package/dist/index.d.cts +3 -41
- package/dist/index.d.ts +3 -41
- package/dist/index.js +3 -802
- package/dist/primitives-nmkVz-tB.d.cts +80 -0
- package/dist/primitives-nmkVz-tB.d.ts +80 -0
- package/dist/types/index.cjs +2 -22
- package/dist/types/index.d.cts +3 -79
- package/dist/types/index.d.ts +3 -79
- package/dist/types/index.js +2 -15
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/index.d.cts +40 -0
- package/dist/utils/index.d.ts +40 -0
- package/dist/utils/index.js +1 -0
- package/dist/validators/index.cjs +1 -313
- package/dist/validators/index.d.cts +1 -0
- package/dist/validators/index.d.ts +1 -0
- package/dist/validators/index.js +1 -308
- package/package.json +81 -54
- package/dist/builders/index.cjs.map +0 -1
- package/dist/builders/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/validators/index.cjs.map +0 -1
- package/dist/validators/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,869 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function isV09Message(message) {
|
|
5
|
-
return "createSurface" in message || "updateComponents" in message || "updateDataModel" in message;
|
|
6
|
-
}
|
|
7
|
-
function isV08Message(message) {
|
|
8
|
-
return "beginRendering" in message || "surfaceUpdate" in message || "dataModelUpdate" in message;
|
|
9
|
-
}
|
|
10
|
-
var STANDARD_CATALOG_ID = "https://a2ui.dev/specification/0.9/standard_catalog_definition.json";
|
|
11
|
-
var A2UI_EXTENSION_URI_V08 = "https://a2ui.org/a2a-extension/a2ui/v0.8";
|
|
12
|
-
var A2UI_EXTENSION_URI = "https://a2ui.dev/specification/0.9";
|
|
13
|
-
var A2UI_MIME_TYPE = "application/json+a2ui";
|
|
14
|
-
|
|
15
|
-
// src/builders/id-generator.ts
|
|
16
|
-
var componentIdCounter = 0;
|
|
17
|
-
function generateId(prefix = "comp") {
|
|
18
|
-
return `${prefix}_${Date.now()}_${componentIdCounter++}`;
|
|
19
|
-
}
|
|
20
|
-
function resetIdCounter() {
|
|
21
|
-
componentIdCounter = 0;
|
|
22
|
-
}
|
|
23
|
-
function getIdCounter() {
|
|
24
|
-
return componentIdCounter;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/builders/component-builder.ts
|
|
28
|
-
function text(content, options = {}) {
|
|
29
|
-
const { id = generateId("text"), weight, usageHint } = options;
|
|
30
|
-
return {
|
|
31
|
-
id,
|
|
32
|
-
component: "Text",
|
|
33
|
-
text: content,
|
|
34
|
-
...weight !== void 0 && { weight },
|
|
35
|
-
...usageHint && { usageHint }
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function image(url, options = {}) {
|
|
39
|
-
const { id = generateId("image"), weight, fit, usageHint } = options;
|
|
40
|
-
return {
|
|
41
|
-
id,
|
|
42
|
-
component: "Image",
|
|
43
|
-
url,
|
|
44
|
-
...weight !== void 0 && { weight },
|
|
45
|
-
...fit && { fit },
|
|
46
|
-
...usageHint && { usageHint }
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function icon(name, options = {}) {
|
|
50
|
-
const { id = generateId("icon"), weight } = options;
|
|
51
|
-
return {
|
|
52
|
-
id,
|
|
53
|
-
component: "Icon",
|
|
54
|
-
name,
|
|
55
|
-
...weight !== void 0 && { weight }
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function video(url, options = {}) {
|
|
59
|
-
const { id = generateId("video"), weight } = options;
|
|
60
|
-
return {
|
|
61
|
-
id,
|
|
62
|
-
component: "Video",
|
|
63
|
-
url,
|
|
64
|
-
...weight !== void 0 && { weight }
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function audioPlayer(url, options = {}) {
|
|
68
|
-
const { id = generateId("audio"), weight, description } = options;
|
|
69
|
-
return {
|
|
70
|
-
id,
|
|
71
|
-
component: "AudioPlayer",
|
|
72
|
-
url,
|
|
73
|
-
...weight !== void 0 && { weight },
|
|
74
|
-
...description && { description }
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function row(children, options = {}) {
|
|
78
|
-
const { id = generateId("row"), weight, alignment, distribution } = options;
|
|
79
|
-
return {
|
|
80
|
-
id,
|
|
81
|
-
component: "Row",
|
|
82
|
-
children,
|
|
83
|
-
...weight !== void 0 && { weight },
|
|
84
|
-
...alignment && { alignment },
|
|
85
|
-
...distribution && { distribution }
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function column(children, options = {}) {
|
|
89
|
-
const { id = generateId("column"), weight, alignment, distribution } = options;
|
|
90
|
-
return {
|
|
91
|
-
id,
|
|
92
|
-
component: "Column",
|
|
93
|
-
children,
|
|
94
|
-
...weight !== void 0 && { weight },
|
|
95
|
-
...alignment && { alignment },
|
|
96
|
-
...distribution && { distribution }
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function list(children, options = {}) {
|
|
100
|
-
const { id = generateId("list"), weight, direction, alignment } = options;
|
|
101
|
-
return {
|
|
102
|
-
id,
|
|
103
|
-
component: "List",
|
|
104
|
-
children,
|
|
105
|
-
...weight !== void 0 && { weight },
|
|
106
|
-
...direction && { direction },
|
|
107
|
-
...alignment && { alignment }
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function card(childId, options = {}) {
|
|
111
|
-
const { id = generateId("card"), weight } = options;
|
|
112
|
-
return {
|
|
113
|
-
id,
|
|
114
|
-
component: "Card",
|
|
115
|
-
child: childId,
|
|
116
|
-
...weight !== void 0 && { weight }
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function tabs(items, options = {}) {
|
|
120
|
-
const { id = generateId("tabs"), weight } = options;
|
|
121
|
-
return {
|
|
122
|
-
id,
|
|
123
|
-
component: "Tabs",
|
|
124
|
-
tabItems: items.map((item) => ({
|
|
125
|
-
title: item.title,
|
|
126
|
-
child: item.childId
|
|
127
|
-
})),
|
|
128
|
-
...weight !== void 0 && { weight }
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function divider(options = {}) {
|
|
132
|
-
const { id = generateId("divider"), weight, axis } = options;
|
|
133
|
-
return {
|
|
134
|
-
id,
|
|
135
|
-
component: "Divider",
|
|
136
|
-
...weight !== void 0 && { weight },
|
|
137
|
-
...axis && { axis }
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
function modal(entryPointChildId, contentChildId, options = {}) {
|
|
141
|
-
const { id = generateId("modal"), weight } = options;
|
|
142
|
-
return {
|
|
143
|
-
id,
|
|
144
|
-
component: "Modal",
|
|
145
|
-
entryPointChild: entryPointChildId,
|
|
146
|
-
contentChild: contentChildId,
|
|
147
|
-
...weight !== void 0 && { weight }
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function button(childId, action, options = {}) {
|
|
151
|
-
const { id = generateId("button"), weight, primary } = options;
|
|
152
|
-
return {
|
|
153
|
-
id,
|
|
154
|
-
component: "Button",
|
|
155
|
-
child: childId,
|
|
156
|
-
action,
|
|
157
|
-
...weight !== void 0 && { weight },
|
|
158
|
-
...primary !== void 0 && { primary }
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function checkbox(label, value, options = {}) {
|
|
162
|
-
const { id = generateId("checkbox"), weight } = options;
|
|
163
|
-
return {
|
|
164
|
-
id,
|
|
165
|
-
component: "CheckBox",
|
|
166
|
-
label,
|
|
167
|
-
value,
|
|
168
|
-
...weight !== void 0 && { weight }
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
function textField(label, textValue, options = {}) {
|
|
172
|
-
const { id = generateId("textfield"), weight, usageHint, validationRegexp } = options;
|
|
173
|
-
return {
|
|
174
|
-
id,
|
|
175
|
-
component: "TextField",
|
|
176
|
-
label,
|
|
177
|
-
...textValue !== void 0 && { text: textValue },
|
|
178
|
-
...weight !== void 0 && { weight },
|
|
179
|
-
...usageHint && { usageHint },
|
|
180
|
-
...validationRegexp && { validationRegexp }
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function dateTimeInput(value, options = {}) {
|
|
184
|
-
const { id = generateId("datetime"), weight, enableDate, enableTime, outputFormat, label } = options;
|
|
185
|
-
return {
|
|
186
|
-
id,
|
|
187
|
-
component: "DateTimeInput",
|
|
188
|
-
value,
|
|
189
|
-
...weight !== void 0 && { weight },
|
|
190
|
-
...enableDate !== void 0 && { enableDate },
|
|
191
|
-
...enableTime !== void 0 && { enableTime },
|
|
192
|
-
...outputFormat && { outputFormat },
|
|
193
|
-
...label && { label }
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function choicePicker(optionsList, value, usageHint, options = {}) {
|
|
197
|
-
const { id = generateId("choice"), weight, label } = options;
|
|
198
|
-
return {
|
|
199
|
-
id,
|
|
200
|
-
component: "ChoicePicker",
|
|
201
|
-
options: optionsList,
|
|
202
|
-
value,
|
|
203
|
-
usageHint,
|
|
204
|
-
...weight !== void 0 && { weight },
|
|
205
|
-
...label && { label }
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function slider(value, options = {}) {
|
|
209
|
-
const { id = generateId("slider"), weight, label, min, max } = options;
|
|
210
|
-
return {
|
|
211
|
-
id,
|
|
212
|
-
component: "Slider",
|
|
213
|
-
value,
|
|
214
|
-
...weight !== void 0 && { weight },
|
|
215
|
-
...label && { label },
|
|
216
|
-
...min !== void 0 && { min },
|
|
217
|
-
...max !== void 0 && { max }
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function textButton(buttonText, action, options = {}) {
|
|
221
|
-
const textId = options.textId ?? generateId("btn_text");
|
|
222
|
-
const textComp = text(buttonText, { id: textId });
|
|
223
|
-
const buttonComp = button(textId, action, options);
|
|
224
|
-
return [textComp, buttonComp];
|
|
225
|
-
}
|
|
226
|
-
function h1(content, options = {}) {
|
|
227
|
-
return text(content, { ...options, usageHint: "h1" });
|
|
228
|
-
}
|
|
229
|
-
function h2(content, options = {}) {
|
|
230
|
-
return text(content, { ...options, usageHint: "h2" });
|
|
231
|
-
}
|
|
232
|
-
function h3(content, options = {}) {
|
|
233
|
-
return text(content, { ...options, usageHint: "h3" });
|
|
234
|
-
}
|
|
235
|
-
function h4(content, options = {}) {
|
|
236
|
-
return text(content, { ...options, usageHint: "h4" });
|
|
237
|
-
}
|
|
238
|
-
function h5(content, options = {}) {
|
|
239
|
-
return text(content, { ...options, usageHint: "h5" });
|
|
240
|
-
}
|
|
241
|
-
function caption(content, options = {}) {
|
|
242
|
-
return text(content, { ...options, usageHint: "caption" });
|
|
243
|
-
}
|
|
244
|
-
function body(content, options = {}) {
|
|
245
|
-
return text(content, { ...options, usageHint: "body" });
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// src/builders/data-model-builder.ts
|
|
249
|
-
var DEFAULT_PATH_MAPPINGS = {};
|
|
250
|
-
function objectToValueMap(obj, prefix = "") {
|
|
251
|
-
const entries = [];
|
|
252
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
253
|
-
const fullKey = prefix ? `${prefix}/${key}` : `/${key}`;
|
|
254
|
-
entries.push(valueToValueMap(fullKey, value));
|
|
255
|
-
}
|
|
256
|
-
return entries;
|
|
257
|
-
}
|
|
258
|
-
function valueToValueMap(key, value) {
|
|
259
|
-
if (value === null || value === void 0) {
|
|
260
|
-
return { key, valueString: "" };
|
|
261
|
-
}
|
|
262
|
-
if (typeof value === "string") {
|
|
263
|
-
return { key, valueString: value };
|
|
264
|
-
}
|
|
265
|
-
if (typeof value === "number") {
|
|
266
|
-
return { key, valueNumber: value };
|
|
267
|
-
}
|
|
268
|
-
if (typeof value === "boolean") {
|
|
269
|
-
return { key, valueBoolean: value };
|
|
270
|
-
}
|
|
271
|
-
if (Array.isArray(value)) {
|
|
272
|
-
return {
|
|
273
|
-
key,
|
|
274
|
-
valueMap: value.map((item, index) => valueToValueMap(String(index), item))
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (typeof value === "object") {
|
|
278
|
-
const nestedMaps = [];
|
|
279
|
-
for (const [k, v] of Object.entries(value)) {
|
|
280
|
-
nestedMaps.push(valueToValueMap(k, v));
|
|
281
|
-
}
|
|
282
|
-
return { key, valueMap: nestedMaps };
|
|
283
|
-
}
|
|
284
|
-
return { key, valueString: String(value) };
|
|
285
|
-
}
|
|
286
|
-
function normalizePath(path2, pathMappings = {}) {
|
|
287
|
-
let normalizedPath = path2.replace(/\./g, "/");
|
|
288
|
-
if (!normalizedPath.startsWith("/")) {
|
|
289
|
-
normalizedPath = `/${normalizedPath}`;
|
|
290
|
-
}
|
|
291
|
-
for (const [from, to] of Object.entries(pathMappings)) {
|
|
292
|
-
const fromPattern = new RegExp(`^/${from}(/|$)`);
|
|
293
|
-
if (fromPattern.test(normalizedPath)) {
|
|
294
|
-
normalizedPath = normalizedPath.replace(fromPattern, `/${to}$1`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return normalizedPath;
|
|
298
|
-
}
|
|
299
|
-
function updatesToValueMap(updates, basePath = "", pathMappings = DEFAULT_PATH_MAPPINGS) {
|
|
300
|
-
const entries = [];
|
|
301
|
-
for (const update of updates) {
|
|
302
|
-
const rawPath = update.path.startsWith("/") ? update.path : `${basePath}/${update.path}`;
|
|
303
|
-
const normalizedPath = normalizePath(rawPath, pathMappings);
|
|
304
|
-
if (update.value !== null && typeof update.value === "object" && !Array.isArray(update.value)) {
|
|
305
|
-
const flattenedEntries = flattenObjectToValueMap(
|
|
306
|
-
update.value,
|
|
307
|
-
normalizedPath
|
|
308
|
-
);
|
|
309
|
-
entries.push(...flattenedEntries);
|
|
310
|
-
} else {
|
|
311
|
-
entries.push(valueToValueMap(normalizedPath, update.value));
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return entries;
|
|
315
|
-
}
|
|
316
|
-
function flattenObjectToValueMap(obj, basePath) {
|
|
317
|
-
const entries = [];
|
|
318
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
319
|
-
const fullPath = `${basePath}/${key}`;
|
|
320
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
321
|
-
const nestedEntries = flattenObjectToValueMap(value, fullPath);
|
|
322
|
-
entries.push(...nestedEntries);
|
|
323
|
-
} else {
|
|
324
|
-
entries.push(valueToValueMap(fullPath, value));
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return entries;
|
|
328
|
-
}
|
|
329
|
-
function valueMapToObject(valueMaps) {
|
|
330
|
-
const result = {};
|
|
331
|
-
for (const valueMap of valueMaps) {
|
|
332
|
-
const key = valueMap.key.startsWith("/") ? valueMap.key.slice(1) : valueMap.key;
|
|
333
|
-
if (valueMap.valueString !== void 0) {
|
|
334
|
-
result[key] = valueMap.valueString;
|
|
335
|
-
} else if (valueMap.valueNumber !== void 0) {
|
|
336
|
-
result[key] = valueMap.valueNumber;
|
|
337
|
-
} else if (valueMap.valueBoolean !== void 0) {
|
|
338
|
-
result[key] = valueMap.valueBoolean;
|
|
339
|
-
} else if (valueMap.valueMap !== void 0) {
|
|
340
|
-
result[key] = valueMapToObject(valueMap.valueMap);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return result;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// src/builders/message-builder.ts
|
|
347
|
-
function createSurface(surfaceId, catalogId = STANDARD_CATALOG_ID) {
|
|
348
|
-
return {
|
|
349
|
-
createSurface: {
|
|
350
|
-
surfaceId,
|
|
351
|
-
catalogId
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function updateComponents(surfaceId, components) {
|
|
356
|
-
return {
|
|
357
|
-
updateComponents: {
|
|
358
|
-
surfaceId,
|
|
359
|
-
components
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function updateDataModel(surfaceId, value, path2, op = "replace") {
|
|
364
|
-
return {
|
|
365
|
-
updateDataModel: {
|
|
366
|
-
surfaceId,
|
|
367
|
-
...path2 && { path: path2 },
|
|
368
|
-
op,
|
|
369
|
-
...op !== "remove" && { value }
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
function deleteSurface(surfaceId) {
|
|
374
|
-
return {
|
|
375
|
-
deleteSurface: {
|
|
376
|
-
surfaceId
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
function createV09Messages(options) {
|
|
381
|
-
const { surfaceId, catalogId = STANDARD_CATALOG_ID, components, dataModel } = options;
|
|
382
|
-
const messages = [
|
|
383
|
-
createSurface(surfaceId, catalogId),
|
|
384
|
-
updateComponents(surfaceId, components)
|
|
385
|
-
];
|
|
386
|
-
if (dataModel) {
|
|
387
|
-
messages.push(updateDataModel(surfaceId, dataModel));
|
|
388
|
-
}
|
|
389
|
-
return messages;
|
|
390
|
-
}
|
|
391
|
-
function beginRendering(rootId, surfaceId = "@default", styles) {
|
|
392
|
-
return {
|
|
393
|
-
beginRendering: {
|
|
394
|
-
surfaceId,
|
|
395
|
-
root: rootId,
|
|
396
|
-
...styles && { styles }
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
function surfaceUpdate(components, surfaceId = "@default") {
|
|
401
|
-
return {
|
|
402
|
-
surfaceUpdate: {
|
|
403
|
-
surfaceId,
|
|
404
|
-
components
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
function dataModelUpdate(contents, surfaceId = "@default", path2) {
|
|
409
|
-
return {
|
|
410
|
-
dataModelUpdate: {
|
|
411
|
-
surfaceId,
|
|
412
|
-
contents,
|
|
413
|
-
...path2 && { path: path2 }
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
function dataModelInit(data, surfaceId = "@default") {
|
|
418
|
-
return dataModelUpdate(objectToValueMap(data), surfaceId);
|
|
419
|
-
}
|
|
420
|
-
function pathUpdate(path2, value, surfaceId = "@default") {
|
|
421
|
-
return {
|
|
422
|
-
dataModelUpdate: {
|
|
423
|
-
surfaceId,
|
|
424
|
-
path: path2,
|
|
425
|
-
contents: [valueToValueMap("", value)]
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
function deleteSurfaceV08(surfaceId) {
|
|
430
|
-
return {
|
|
431
|
-
deleteSurface: {
|
|
432
|
-
surfaceId
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
function createV08Messages(options) {
|
|
437
|
-
const { rootId, components, dataModel, surfaceId = "@default", styles } = options;
|
|
438
|
-
const messages = [
|
|
439
|
-
surfaceUpdate(components, surfaceId)
|
|
440
|
-
];
|
|
441
|
-
if (dataModel) {
|
|
442
|
-
messages.push(dataModelInit(dataModel, surfaceId));
|
|
443
|
-
}
|
|
444
|
-
messages.push(beginRendering(rootId, surfaceId, styles));
|
|
445
|
-
return messages;
|
|
446
|
-
}
|
|
447
|
-
function messagesToJsonl(messages) {
|
|
448
|
-
return messages.map((msg) => JSON.stringify(msg)).join("\n");
|
|
449
|
-
}
|
|
450
|
-
function jsonlToMessages(jsonl) {
|
|
451
|
-
return jsonl.split("\n").filter((line) => line.trim()).map((line) => JSON.parse(line));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// src/validators/message-validator.ts
|
|
455
|
-
var STANDARD_COMPONENT_TYPES = [
|
|
456
|
-
"Text",
|
|
457
|
-
"Image",
|
|
458
|
-
"Icon",
|
|
459
|
-
"Video",
|
|
460
|
-
"AudioPlayer",
|
|
461
|
-
"Row",
|
|
462
|
-
"Column",
|
|
463
|
-
"List",
|
|
464
|
-
"Card",
|
|
465
|
-
"Tabs",
|
|
466
|
-
"Divider",
|
|
467
|
-
"Modal",
|
|
468
|
-
"Button",
|
|
469
|
-
"CheckBox",
|
|
470
|
-
"TextField",
|
|
471
|
-
"DateTimeInput",
|
|
472
|
-
"ChoicePicker",
|
|
473
|
-
"Slider"
|
|
474
|
-
];
|
|
475
|
-
function validateV09Message(message, options = {}) {
|
|
476
|
-
const errors = [];
|
|
477
|
-
const warnings = [];
|
|
478
|
-
if ("createSurface" in message) {
|
|
479
|
-
const { createSurface: createSurface2 } = message;
|
|
480
|
-
if (!createSurface2.surfaceId) {
|
|
481
|
-
errors.push({
|
|
482
|
-
code: "MISSING_SURFACE_ID",
|
|
483
|
-
message: "createSurface.surfaceId is required",
|
|
484
|
-
path: "createSurface.surfaceId"
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
if (!createSurface2.catalogId) {
|
|
488
|
-
errors.push({
|
|
489
|
-
code: "MISSING_CATALOG_ID",
|
|
490
|
-
message: "createSurface.catalogId is required",
|
|
491
|
-
path: "createSurface.catalogId"
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
} else if ("updateComponents" in message) {
|
|
495
|
-
const { updateComponents: updateComponents2 } = message;
|
|
496
|
-
if (!updateComponents2.surfaceId) {
|
|
497
|
-
errors.push({
|
|
498
|
-
code: "MISSING_SURFACE_ID",
|
|
499
|
-
message: "updateComponents.surfaceId is required",
|
|
500
|
-
path: "updateComponents.surfaceId"
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
if (!updateComponents2.components || !Array.isArray(updateComponents2.components)) {
|
|
504
|
-
errors.push({
|
|
505
|
-
code: "INVALID_COMPONENTS",
|
|
506
|
-
message: "updateComponents.components must be an array",
|
|
507
|
-
path: "updateComponents.components"
|
|
508
|
-
});
|
|
509
|
-
} else {
|
|
510
|
-
validateComponentsV09(updateComponents2.components, errors, warnings, options);
|
|
511
|
-
}
|
|
512
|
-
} else if ("updateDataModel" in message) {
|
|
513
|
-
const { updateDataModel: updateDataModel2 } = message;
|
|
514
|
-
if (!updateDataModel2.surfaceId) {
|
|
515
|
-
errors.push({
|
|
516
|
-
code: "MISSING_SURFACE_ID",
|
|
517
|
-
message: "updateDataModel.surfaceId is required",
|
|
518
|
-
path: "updateDataModel.surfaceId"
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
} else if ("deleteSurface" in message) {
|
|
522
|
-
const { deleteSurface: deleteSurface2 } = message;
|
|
523
|
-
if (!deleteSurface2.surfaceId) {
|
|
524
|
-
errors.push({
|
|
525
|
-
code: "MISSING_SURFACE_ID",
|
|
526
|
-
message: "deleteSurface.surfaceId is required",
|
|
527
|
-
path: "deleteSurface.surfaceId"
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
} else {
|
|
531
|
-
errors.push({
|
|
532
|
-
code: "INVALID_MESSAGE_TYPE",
|
|
533
|
-
message: "Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
valid: errors.length === 0,
|
|
538
|
-
errors,
|
|
539
|
-
warnings
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
function validateV08Message(message, options = {}) {
|
|
543
|
-
const errors = [];
|
|
544
|
-
const warnings = [];
|
|
545
|
-
if ("beginRendering" in message) {
|
|
546
|
-
const { beginRendering: beginRendering2 } = message;
|
|
547
|
-
if (!beginRendering2.surfaceId) {
|
|
548
|
-
errors.push({
|
|
549
|
-
code: "MISSING_SURFACE_ID",
|
|
550
|
-
message: "beginRendering.surfaceId is required",
|
|
551
|
-
path: "beginRendering.surfaceId"
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
if (!beginRendering2.root) {
|
|
555
|
-
errors.push({
|
|
556
|
-
code: "MISSING_ROOT",
|
|
557
|
-
message: "beginRendering.root is required",
|
|
558
|
-
path: "beginRendering.root"
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
} else if ("surfaceUpdate" in message) {
|
|
562
|
-
const { surfaceUpdate: surfaceUpdate2 } = message;
|
|
563
|
-
if (!surfaceUpdate2.surfaceId) {
|
|
564
|
-
errors.push({
|
|
565
|
-
code: "MISSING_SURFACE_ID",
|
|
566
|
-
message: "surfaceUpdate.surfaceId is required",
|
|
567
|
-
path: "surfaceUpdate.surfaceId"
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
if (!surfaceUpdate2.components || !Array.isArray(surfaceUpdate2.components)) {
|
|
571
|
-
errors.push({
|
|
572
|
-
code: "INVALID_COMPONENTS",
|
|
573
|
-
message: "surfaceUpdate.components must be an array",
|
|
574
|
-
path: "surfaceUpdate.components"
|
|
575
|
-
});
|
|
576
|
-
} else {
|
|
577
|
-
validateComponentsV08(surfaceUpdate2.components, errors, warnings, options);
|
|
578
|
-
}
|
|
579
|
-
} else if ("dataModelUpdate" in message) {
|
|
580
|
-
const { dataModelUpdate: dataModelUpdate2 } = message;
|
|
581
|
-
if (!dataModelUpdate2.surfaceId) {
|
|
582
|
-
errors.push({
|
|
583
|
-
code: "MISSING_SURFACE_ID",
|
|
584
|
-
message: "dataModelUpdate.surfaceId is required",
|
|
585
|
-
path: "dataModelUpdate.surfaceId"
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
if (!dataModelUpdate2.contents || !Array.isArray(dataModelUpdate2.contents)) {
|
|
589
|
-
errors.push({
|
|
590
|
-
code: "INVALID_CONTENTS",
|
|
591
|
-
message: "dataModelUpdate.contents must be an array",
|
|
592
|
-
path: "dataModelUpdate.contents"
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
} else if ("deleteSurface" in message) {
|
|
596
|
-
const { deleteSurface: deleteSurface2 } = message;
|
|
597
|
-
if (!deleteSurface2.surfaceId) {
|
|
598
|
-
errors.push({
|
|
599
|
-
code: "MISSING_SURFACE_ID",
|
|
600
|
-
message: "deleteSurface.surfaceId is required",
|
|
601
|
-
path: "deleteSurface.surfaceId"
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
} else {
|
|
605
|
-
errors.push({
|
|
606
|
-
code: "INVALID_MESSAGE_TYPE",
|
|
607
|
-
message: "Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
valid: errors.length === 0,
|
|
612
|
-
errors,
|
|
613
|
-
warnings
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
function validateMessage(message, options = {}) {
|
|
617
|
-
if ("createSurface" in message || "updateComponents" in message || "updateDataModel" in message) {
|
|
618
|
-
return validateV09Message(message, options);
|
|
619
|
-
}
|
|
620
|
-
if ("beginRendering" in message || "surfaceUpdate" in message || "dataModelUpdate" in message) {
|
|
621
|
-
return validateV08Message(message, options);
|
|
622
|
-
}
|
|
623
|
-
if ("deleteSurface" in message) {
|
|
624
|
-
if (!message.deleteSurface.surfaceId) {
|
|
625
|
-
return {
|
|
626
|
-
valid: false,
|
|
627
|
-
errors: [{
|
|
628
|
-
code: "MISSING_SURFACE_ID",
|
|
629
|
-
message: "deleteSurface.surfaceId is required",
|
|
630
|
-
path: "deleteSurface.surfaceId"
|
|
631
|
-
}],
|
|
632
|
-
warnings: []
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
return { valid: true, errors: [], warnings: [] };
|
|
636
|
-
}
|
|
637
|
-
return {
|
|
638
|
-
valid: false,
|
|
639
|
-
errors: [{
|
|
640
|
-
code: "UNKNOWN_MESSAGE_TYPE",
|
|
641
|
-
message: "Unknown message type"
|
|
642
|
-
}],
|
|
643
|
-
warnings: []
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
function validateMessages(messages, options = {}) {
|
|
647
|
-
const errors = [];
|
|
648
|
-
const warnings = [];
|
|
649
|
-
for (let i = 0; i < messages.length; i++) {
|
|
650
|
-
const result = validateMessage(messages[i], options);
|
|
651
|
-
for (const error of result.errors) {
|
|
652
|
-
errors.push({
|
|
653
|
-
...error,
|
|
654
|
-
path: `messages[${i}].${error.path || ""}`
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
for (const warning of result.warnings) {
|
|
658
|
-
warnings.push({
|
|
659
|
-
...warning,
|
|
660
|
-
path: `messages[${i}].${warning.path || ""}`
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
return {
|
|
665
|
-
valid: errors.length === 0,
|
|
666
|
-
errors,
|
|
667
|
-
warnings
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
function validateComponentsV09(components, errors, warnings, options) {
|
|
671
|
-
const componentIds = /* @__PURE__ */ new Set();
|
|
672
|
-
let hasRoot = false;
|
|
673
|
-
for (let i = 0; i < components.length; i++) {
|
|
674
|
-
const comp = components[i];
|
|
675
|
-
const path2 = `updateComponents.components[${i}]`;
|
|
676
|
-
if (!comp.id) {
|
|
677
|
-
errors.push({
|
|
678
|
-
code: "MISSING_COMPONENT_ID",
|
|
679
|
-
message: "Component id is required",
|
|
680
|
-
path: `${path2}.id`
|
|
681
|
-
});
|
|
682
|
-
} else {
|
|
683
|
-
if (componentIds.has(comp.id)) {
|
|
684
|
-
errors.push({
|
|
685
|
-
code: "DUPLICATE_COMPONENT_ID",
|
|
686
|
-
message: `Duplicate component id: ${comp.id}`,
|
|
687
|
-
path: `${path2}.id`
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
componentIds.add(comp.id);
|
|
691
|
-
if (comp.id === "root") {
|
|
692
|
-
hasRoot = true;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
if (!comp.component) {
|
|
696
|
-
errors.push({
|
|
697
|
-
code: "MISSING_COMPONENT_TYPE",
|
|
698
|
-
message: "Component type is required",
|
|
699
|
-
path: `${path2}.component`
|
|
700
|
-
});
|
|
701
|
-
} else if (options.strict && options.allowedComponents) {
|
|
702
|
-
if (!options.allowedComponents.includes(comp.component)) {
|
|
703
|
-
warnings.push({
|
|
704
|
-
code: "UNKNOWN_COMPONENT_TYPE",
|
|
705
|
-
message: `Unknown component type: ${comp.component}`,
|
|
706
|
-
path: `${path2}.component`
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
if (!hasRoot && options.strict) {
|
|
712
|
-
warnings.push({
|
|
713
|
-
code: "MISSING_ROOT_COMPONENT",
|
|
714
|
-
message: 'No component with id "root" found',
|
|
715
|
-
path: "updateComponents.components"
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
function validateComponentsV08(components, errors, warnings, options) {
|
|
720
|
-
const componentIds = /* @__PURE__ */ new Set();
|
|
721
|
-
for (let i = 0; i < components.length; i++) {
|
|
722
|
-
const comp = components[i];
|
|
723
|
-
const path2 = `surfaceUpdate.components[${i}]`;
|
|
724
|
-
if (!comp.id) {
|
|
725
|
-
errors.push({
|
|
726
|
-
code: "MISSING_COMPONENT_ID",
|
|
727
|
-
message: "Component id is required",
|
|
728
|
-
path: `${path2}.id`
|
|
729
|
-
});
|
|
730
|
-
} else {
|
|
731
|
-
if (componentIds.has(comp.id)) {
|
|
732
|
-
errors.push({
|
|
733
|
-
code: "DUPLICATE_COMPONENT_ID",
|
|
734
|
-
message: `Duplicate component id: ${comp.id}`,
|
|
735
|
-
path: `${path2}.id`
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
componentIds.add(comp.id);
|
|
739
|
-
}
|
|
740
|
-
if (!comp.component || typeof comp.component !== "object") {
|
|
741
|
-
errors.push({
|
|
742
|
-
code: "MISSING_COMPONENT",
|
|
743
|
-
message: "Component definition is required",
|
|
744
|
-
path: `${path2}.component`
|
|
745
|
-
});
|
|
746
|
-
} else {
|
|
747
|
-
const componentType = Object.keys(comp.component)[0];
|
|
748
|
-
if (options.strict && !STANDARD_COMPONENT_TYPES.includes(componentType)) {
|
|
749
|
-
warnings.push({
|
|
750
|
-
code: "UNKNOWN_COMPONENT_TYPE",
|
|
751
|
-
message: `Unknown component type: ${componentType}`,
|
|
752
|
-
path: `${path2}.component`
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// src/utils/index.ts
|
|
760
|
-
function isPathBinding(value) {
|
|
761
|
-
return typeof value === "object" && value !== null && "path" in value;
|
|
762
|
-
}
|
|
763
|
-
function getLiteralValue(value) {
|
|
764
|
-
if (isPathBinding(value)) {
|
|
765
|
-
return void 0;
|
|
766
|
-
}
|
|
767
|
-
return value;
|
|
768
|
-
}
|
|
769
|
-
function getPathValue(value) {
|
|
770
|
-
if (isPathBinding(value)) {
|
|
771
|
-
return value.path;
|
|
772
|
-
}
|
|
773
|
-
return void 0;
|
|
774
|
-
}
|
|
775
|
-
function path(dataPath) {
|
|
776
|
-
return { path: dataPath };
|
|
777
|
-
}
|
|
778
|
-
function deepMerge(target, source) {
|
|
779
|
-
const result = { ...target };
|
|
780
|
-
for (const key of Object.keys(source)) {
|
|
781
|
-
const sourceValue = source[key];
|
|
782
|
-
const targetValue = result[key];
|
|
783
|
-
if (sourceValue !== void 0 && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
|
|
784
|
-
result[key] = deepMerge(
|
|
785
|
-
targetValue,
|
|
786
|
-
sourceValue
|
|
787
|
-
);
|
|
788
|
-
} else if (sourceValue !== void 0) {
|
|
789
|
-
result[key] = sourceValue;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return result;
|
|
793
|
-
}
|
|
794
|
-
function uuid() {
|
|
795
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
796
|
-
const r = Math.random() * 16 | 0;
|
|
797
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
798
|
-
return v.toString(16);
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
exports.A2UI_EXTENSION_URI = A2UI_EXTENSION_URI;
|
|
803
|
-
exports.A2UI_EXTENSION_URI_V08 = A2UI_EXTENSION_URI_V08;
|
|
804
|
-
exports.A2UI_MIME_TYPE = A2UI_MIME_TYPE;
|
|
805
|
-
exports.DEFAULT_PATH_MAPPINGS = DEFAULT_PATH_MAPPINGS;
|
|
806
|
-
exports.STANDARD_CATALOG_ID = STANDARD_CATALOG_ID;
|
|
807
|
-
exports.audioPlayer = audioPlayer;
|
|
808
|
-
exports.beginRendering = beginRendering;
|
|
809
|
-
exports.body = body;
|
|
810
|
-
exports.button = button;
|
|
811
|
-
exports.caption = caption;
|
|
812
|
-
exports.card = card;
|
|
813
|
-
exports.checkbox = checkbox;
|
|
814
|
-
exports.choicePicker = choicePicker;
|
|
815
|
-
exports.column = column;
|
|
816
|
-
exports.createSurface = createSurface;
|
|
817
|
-
exports.createV08Messages = createV08Messages;
|
|
818
|
-
exports.createV09Messages = createV09Messages;
|
|
819
|
-
exports.dataModelInit = dataModelInit;
|
|
820
|
-
exports.dataModelUpdate = dataModelUpdate;
|
|
821
|
-
exports.dateTimeInput = dateTimeInput;
|
|
822
|
-
exports.deepMerge = deepMerge;
|
|
823
|
-
exports.deleteSurface = deleteSurface;
|
|
824
|
-
exports.deleteSurfaceV08 = deleteSurfaceV08;
|
|
825
|
-
exports.divider = divider;
|
|
826
|
-
exports.flattenObjectToValueMap = flattenObjectToValueMap;
|
|
827
|
-
exports.generateId = generateId;
|
|
828
|
-
exports.getIdCounter = getIdCounter;
|
|
829
|
-
exports.getLiteralValue = getLiteralValue;
|
|
830
|
-
exports.getPathValue = getPathValue;
|
|
831
|
-
exports.h1 = h1;
|
|
832
|
-
exports.h2 = h2;
|
|
833
|
-
exports.h3 = h3;
|
|
834
|
-
exports.h4 = h4;
|
|
835
|
-
exports.h5 = h5;
|
|
836
|
-
exports.icon = icon;
|
|
837
|
-
exports.image = image;
|
|
838
|
-
exports.isPathBinding = isPathBinding;
|
|
839
|
-
exports.isV08Message = isV08Message;
|
|
840
|
-
exports.isV09Message = isV09Message;
|
|
841
|
-
exports.jsonlToMessages = jsonlToMessages;
|
|
842
|
-
exports.list = list;
|
|
843
|
-
exports.messagesToJsonl = messagesToJsonl;
|
|
844
|
-
exports.modal = modal;
|
|
845
|
-
exports.normalizePath = normalizePath;
|
|
846
|
-
exports.objectToValueMap = objectToValueMap;
|
|
847
|
-
exports.path = path;
|
|
848
|
-
exports.pathUpdate = pathUpdate;
|
|
849
|
-
exports.resetIdCounter = resetIdCounter;
|
|
850
|
-
exports.row = row;
|
|
851
|
-
exports.slider = slider;
|
|
852
|
-
exports.surfaceUpdate = surfaceUpdate;
|
|
853
|
-
exports.tabs = tabs;
|
|
854
|
-
exports.text = text;
|
|
855
|
-
exports.textButton = textButton;
|
|
856
|
-
exports.textField = textField;
|
|
857
|
-
exports.updateComponents = updateComponents;
|
|
858
|
-
exports.updateDataModel = updateDataModel;
|
|
859
|
-
exports.updatesToValueMap = updatesToValueMap;
|
|
860
|
-
exports.uuid = uuid;
|
|
861
|
-
exports.validateMessage = validateMessage;
|
|
862
|
-
exports.validateMessages = validateMessages;
|
|
863
|
-
exports.validateV08Message = validateV08Message;
|
|
864
|
-
exports.validateV09Message = validateV09Message;
|
|
865
|
-
exports.valueMapToObject = valueMapToObject;
|
|
866
|
-
exports.valueToValueMap = valueToValueMap;
|
|
867
|
-
exports.video = video;
|
|
868
|
-
//# sourceMappingURL=index.cjs.map
|
|
869
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';function U(e){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e}function N(e){return "beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e}var l="https://a2ui.dev/specification/0.9/standard_catalog_definition.json",_="https://a2ui.org/a2a-extension/a2ui/v0.8",E="https://a2ui.dev/specification/0.9",R="application/json+a2ui";var f=0;function p(e="comp"){return `${e}_${Date.now()}_${f++}`}function w(){f=0;}function k(){return f}function d(e,t={}){let{id:n=p("text"),weight:a,usageHint:o}=t;return {id:n,component:"Text",text:e,...a!==void 0&&{weight:a},...o&&{usageHint:o}}}function j(e,t={}){let{id:n=p("image"),weight:a,fit:o,usageHint:r}=t;return {id:n,component:"Image",url:e,...a!==void 0&&{weight:a},...o&&{fit:o},...r&&{usageHint:r}}}function B(e,t={}){let{id:n=p("icon"),weight:a}=t;return {id:n,component:"Icon",name:e,...a!==void 0&&{weight:a}}}function L(e,t={}){let{id:n=p("video"),weight:a}=t;return {id:n,component:"Video",url:e,...a!==void 0&&{weight:a}}}function $(e,t={}){let{id:n=p("audio"),weight:a,description:o}=t;return {id:n,component:"AudioPlayer",url:e,...a!==void 0&&{weight:a},...o&&{description:o}}}function F(e,t={}){let{id:n=p("row"),weight:a,alignment:o,distribution:r}=t;return {id:n,component:"Row",children:e,...a!==void 0&&{weight:a},...o&&{alignment:o},...r&&{distribution:r}}}function G(e,t={}){let{id:n=p("column"),weight:a,alignment:o,distribution:r}=t;return {id:n,component:"Column",children:e,...a!==void 0&&{weight:a},...o&&{alignment:o},...r&&{distribution:r}}}function H(e,t={}){let{id:n=p("list"),weight:a,direction:o,alignment:r}=t;return {id:n,component:"List",children:e,...a!==void 0&&{weight:a},...o&&{direction:o},...r&&{alignment:r}}}function q(e,t={}){let{id:n=p("card"),weight:a}=t;return {id:n,component:"Card",child:e,...a!==void 0&&{weight:a}}}function W(e,t={}){let{id:n=p("tabs"),weight:a}=t;return {id:n,component:"Tabs",tabItems:e.map(o=>({title:o.title,child:o.childId})),...a!==void 0&&{weight:a}}}function Y(e={}){let{id:t=p("divider"),weight:n,axis:a}=e;return {id:t,component:"Divider",...n!==void 0&&{weight:n},...a&&{axis:a}}}function X(e,t,n={}){let{id:a=p("modal"),weight:o}=n;return {id:a,component:"Modal",entryPointChild:e,contentChild:t,...o!==void 0&&{weight:o}}}function C(e,t,n={}){let{id:a=p("button"),weight:o,primary:r}=n;return {id:a,component:"Button",child:e,action:t,...o!==void 0&&{weight:o},...r!==void 0&&{primary:r}}}function z(e,t,n={}){let{id:a=p("checkbox"),weight:o}=n;return {id:a,component:"CheckBox",label:e,value:t,...o!==void 0&&{weight:o}}}function J(e,t,n={}){let{id:a=p("textfield"),weight:o,usageHint:r,validationRegexp:i}=n;return {id:a,component:"TextField",label:e,...t!==void 0&&{text:t},...o!==void 0&&{weight:o},...r&&{usageHint:r},...i&&{validationRegexp:i}}}function K(e,t={}){let{id:n=p("datetime"),weight:a,enableDate:o,enableTime:r,outputFormat:i,label:s}=t;return {id:n,component:"DateTimeInput",value:e,...a!==void 0&&{weight:a},...o!==void 0&&{enableDate:o},...r!==void 0&&{enableTime:r},...i&&{outputFormat:i},...s&&{label:s}}}function Q(e,t,n,a={}){let{id:o=p("choice"),weight:r,label:i}=a;return {id:o,component:"ChoicePicker",options:e,value:t,usageHint:n,...r!==void 0&&{weight:r},...i&&{label:i}}}function Z(e,t={}){let{id:n=p("slider"),weight:a,label:o,min:r,max:i}=t;return {id:n,component:"Slider",value:e,...a!==void 0&&{weight:a},...o&&{label:o},...r!==void 0&&{min:r},...i!==void 0&&{max:i}}}function ee(e,t,n={}){let a=n.textId??p("btn_text"),o=d(e,{id:a}),r=C(a,t,n);return [o,r]}function te(e,t={}){return d(e,{...t,usageHint:"h1"})}function ne(e,t={}){return d(e,{...t,usageHint:"h2"})}function oe(e,t={}){return d(e,{...t,usageHint:"h3"})}function ae(e,t={}){return d(e,{...t,usageHint:"h4"})}function re(e,t={}){return d(e,{...t,usageHint:"h5"})}function ie(e,t={}){return d(e,{...t,usageHint:"caption"})}function se(e,t={}){return d(e,{...t,usageHint:"body"})}var M={};function g(e,t=""){let n=[];for(let[a,o]of Object.entries(e)){let r=t?`${t}/${a}`:`/${a}`;n.push(c(r,o));}return n}function c(e,t){if(t==null)return {key:e,valueString:""};if(typeof t=="string")return {key:e,valueString:t};if(typeof t=="number")return {key:e,valueNumber:t};if(typeof t=="boolean")return {key:e,valueBoolean:t};if(Array.isArray(t))return {key:e,valueMap:t.map((n,a)=>c(String(a),n))};if(typeof t=="object"){let n=[];for(let[a,o]of Object.entries(t))n.push(c(a,o));return {key:e,valueMap:n}}return {key:e,valueString:String(t)}}function I(e,t={}){let n=e.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[a,o]of Object.entries(t)){let r=new RegExp(`^/${a}(/|$)`);r.test(n)&&(n=n.replace(r,`/${o}$1`));}return n}function pe(e,t="",n=M){let a=[];for(let o of e){let r=o.path.startsWith("/")?o.path:`${t}/${o.path}`,i=I(r,n);if(o.value!==null&&typeof o.value=="object"&&!Array.isArray(o.value)){let s=m(o.value,i);a.push(...s);}else a.push(c(i,o.value));}return a}function m(e,t){let n=[];for(let[a,o]of Object.entries(e)){let r=`${t}/${a}`;if(o!==null&&typeof o=="object"&&!Array.isArray(o)){let i=m(o,r);n.push(...i);}else n.push(c(r,o));}return n}function h(e){let t={};for(let n of e){let a=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?t[a]=n.valueString:n.valueNumber!==void 0?t[a]=n.valueNumber:n.valueBoolean!==void 0?t[a]=n.valueBoolean:n.valueMap!==void 0&&(t[a]=h(n.valueMap));}return t}function x(e,t=l){return {createSurface:{surfaceId:e,catalogId:t}}}function O(e,t){return {updateComponents:{surfaceId:e,components:t}}}function S(e,t,n,a="replace"){return {updateDataModel:{surfaceId:e,...n&&{path:n},op:a,...a!=="remove"&&{value:t}}}}function de(e){return {deleteSurface:{surfaceId:e}}}function ce(e){let{surfaceId:t,catalogId:n=l,components:a,dataModel:o}=e,r=[x(t,n),O(t,a)];return o&&r.push(S(t,o)),r}function T(e,t="@default",n){return {beginRendering:{surfaceId:t,root:e,...n&&{styles:n}}}}function y(e,t="@default"){return {surfaceUpdate:{surfaceId:t,components:e}}}function V(e,t="@default",n){return {dataModelUpdate:{surfaceId:t,contents:e,...n&&{path:n}}}}function D(e,t="@default"){return V(g(e),t)}function ue(e,t,n="@default"){return {dataModelUpdate:{surfaceId:n,path:e,contents:[c("",t)]}}}function le(e){return {deleteSurface:{surfaceId:e}}}function ge(e){let{rootId:t,components:n,dataModel:a,surfaceId:o="@default",styles:r}=e,i=[y(n,o)];return a&&i.push(D(a,o)),i.push(T(t,o,r)),i}function me(e){return e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}function fe(e){return e.split(`
|
|
3
|
+
`).filter(t=>t.trim()).map(t=>JSON.parse(t))}var Ie=["Text","Image","Icon","Video","AudioPlayer","Row","Column","List","Card","Tabs","Divider","Modal","Button","CheckBox","TextField","DateTimeInput","ChoicePicker","Slider"];function b(e,t={}){let n=[],a=[];if("createSurface"in e){let{createSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"createSurface.surfaceId is required",path:"createSurface.surfaceId"}),o.catalogId||n.push({code:"MISSING_CATALOG_ID",message:"createSurface.catalogId is required",path:"createSurface.catalogId"});}else if("updateComponents"in e){let{updateComponents:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateComponents.surfaceId is required",path:"updateComponents.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"updateComponents.components must be an array",path:"updateComponents.components"}):he(o.components,n,a,t);}else if("updateDataModel"in e){let{updateDataModel:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"updateDataModel.surfaceId is required",path:"updateDataModel.surfaceId"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: createSurface, updateComponents, updateDataModel, deleteSurface"});return {valid:n.length===0,errors:n,warnings:a}}function P(e,t={}){let n=[],a=[];if("beginRendering"in e){let{beginRendering:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"beginRendering.surfaceId is required",path:"beginRendering.surfaceId"}),o.root||n.push({code:"MISSING_ROOT",message:"beginRendering.root is required",path:"beginRendering.root"});}else if("surfaceUpdate"in e){let{surfaceUpdate:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"surfaceUpdate.surfaceId is required",path:"surfaceUpdate.surfaceId"}),!o.components||!Array.isArray(o.components)?n.push({code:"INVALID_COMPONENTS",message:"surfaceUpdate.components must be an array",path:"surfaceUpdate.components"}):xe(o.components,n,a,t);}else if("dataModelUpdate"in e){let{dataModelUpdate:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"dataModelUpdate.surfaceId is required",path:"dataModelUpdate.surfaceId"}),(!o.contents||!Array.isArray(o.contents))&&n.push({code:"INVALID_CONTENTS",message:"dataModelUpdate.contents must be an array",path:"dataModelUpdate.contents"});}else if("deleteSurface"in e){let{deleteSurface:o}=e;o.surfaceId||n.push({code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"});}else n.push({code:"INVALID_MESSAGE_TYPE",message:"Message must contain one of: beginRendering, surfaceUpdate, dataModelUpdate, deleteSurface"});return {valid:n.length===0,errors:n,warnings:a}}function v(e,t={}){return "createSurface"in e||"updateComponents"in e||"updateDataModel"in e?b(e,t):"beginRendering"in e||"surfaceUpdate"in e||"dataModelUpdate"in e?P(e,t):"deleteSurface"in e?e.deleteSurface.surfaceId?{valid:true,errors:[],warnings:[]}:{valid:false,errors:[{code:"MISSING_SURFACE_ID",message:"deleteSurface.surfaceId is required",path:"deleteSurface.surfaceId"}],warnings:[]}:{valid:false,errors:[{code:"UNKNOWN_MESSAGE_TYPE",message:"Unknown message type"}],warnings:[]}}function Ce(e,t={}){let n=[],a=[];for(let o=0;o<e.length;o++){let r=e[o];if(!r)continue;let i=v(r,t);for(let s of i.errors)n.push({...s,path:`messages[${o}].${s.path??""}`});for(let s of i.warnings)a.push({...s,path:`messages[${o}].${s.path??""}`});}return {valid:n.length===0,errors:n,warnings:a}}function he(e,t,n,a){let o=new Set,r=false;for(let i=0;i<e.length;i++){let s=e[i];if(!s)continue;let u=`updateComponents.components[${i}]`;s.id?(o.has(s.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${s.id}`,path:`${u}.id`}),o.add(s.id),s.id==="root"&&(r=true)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${u}.id`}),s.component?a.strict&&a.allowedComponents&&(a.allowedComponents.includes(s.component)||n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${s.component}`,path:`${u}.component`})):t.push({code:"MISSING_COMPONENT_TYPE",message:"Component type is required",path:`${u}.component`});}!r&&a.strict&&n.push({code:"MISSING_ROOT_COMPONENT",message:'No component with id "root" found',path:"updateComponents.components"});}function xe(e,t,n,a){let o=new Set;for(let r=0;r<e.length;r++){let i=e[r];if(!i)continue;let s=`surfaceUpdate.components[${r}]`;if(i.id?(o.has(i.id)&&t.push({code:"DUPLICATE_COMPONENT_ID",message:`Duplicate component id: ${i.id}`,path:`${s}.id`}),o.add(i.id)):t.push({code:"MISSING_COMPONENT_ID",message:"Component id is required",path:`${s}.id`}),!i.component||typeof i.component!="object")t.push({code:"MISSING_COMPONENT",message:"Component definition is required",path:`${s}.component`});else {let u=Object.keys(i.component)[0];u&&a.strict&&!Ie.includes(u)&&n.push({code:"UNKNOWN_COMPONENT_TYPE",message:`Unknown component type: ${u}`,path:`${s}.component`});}}}function A(e){return typeof e=="object"&&e!==null&&"path"in e}function Oe(e){if(!A(e))return e}function Se(e){if(A(e))return e.path}function Te(e){return {path:e}}function Me(e,t){let n={...e};for(let a of Object.keys(t)){let o=t[a],r=n[a];o!==void 0&&typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?n[a]=Me(r,o):o!==void 0&&(n[a]=o);}return n}function ye(){return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return (e==="x"?t:t&3|8).toString(16)})}exports.A2UI_EXTENSION_URI=E;exports.A2UI_EXTENSION_URI_V08=_;exports.A2UI_MIME_TYPE=R;exports.DEFAULT_PATH_MAPPINGS=M;exports.STANDARD_CATALOG_ID=l;exports.audioPlayer=$;exports.beginRendering=T;exports.body=se;exports.button=C;exports.caption=ie;exports.card=q;exports.checkbox=z;exports.choicePicker=Q;exports.column=G;exports.createSurface=x;exports.createV08Messages=ge;exports.createV09Messages=ce;exports.dataModelInit=D;exports.dataModelUpdate=V;exports.dateTimeInput=K;exports.deepMerge=Me;exports.deleteSurface=de;exports.deleteSurfaceV08=le;exports.divider=Y;exports.flattenObjectToValueMap=m;exports.generateId=p;exports.getIdCounter=k;exports.getLiteralValue=Oe;exports.getPathValue=Se;exports.h1=te;exports.h2=ne;exports.h3=oe;exports.h4=ae;exports.h5=re;exports.icon=B;exports.image=j;exports.isPathBinding=A;exports.isV08Message=N;exports.isV09Message=U;exports.jsonlToMessages=fe;exports.list=H;exports.messagesToJsonl=me;exports.modal=X;exports.normalizePath=I;exports.objectToValueMap=g;exports.path=Te;exports.pathUpdate=ue;exports.resetIdCounter=w;exports.row=F;exports.slider=Z;exports.surfaceUpdate=y;exports.tabs=W;exports.text=d;exports.textButton=ee;exports.textField=J;exports.updateComponents=O;exports.updateDataModel=S;exports.updatesToValueMap=pe;exports.uuid=ye;exports.validateMessage=v;exports.validateMessages=Ce;exports.validateV08Message=P;exports.validateV09Message=b;exports.valueMapToObject=h;exports.valueToValueMap=c;exports.video=L;
|