@voltro/ui 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/dist/index.js ADDED
@@ -0,0 +1,960 @@
1
+ import { createContext as e, useContext as t, useId as n, useMemo as r, useState as i } from "react";
2
+ import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
3
+ import { useAgentChat as c, useDataCopilot as l, useDataTable as u, useFormBinding as d, useFormSkeleton as f, useQueryField as p, useQueryFilters as m, useRecord as h, useTableSkeleton as g, useWorkflowRunState as _ } from "@voltro/client";
4
+ //#region src/widgets.tsx
5
+ var v = (e) => e == null ? "" : String(e), y = (e) => /* @__PURE__ */ s("div", {
6
+ "data-voltro-field": !0,
7
+ children: [
8
+ /* @__PURE__ */ s("label", {
9
+ htmlFor: e.id,
10
+ children: [e.label, e.required ? " *" : ""]
11
+ }),
12
+ e.children,
13
+ e.error === void 0 ? null : /* @__PURE__ */ o("p", {
14
+ id: `${e.id}-error`,
15
+ role: "alert",
16
+ children: e.error
17
+ })
18
+ ]
19
+ }), b = (e, t) => t === void 0 ? void 0 : `${e}-error`, x = (e, t) => (r) => {
20
+ let i = n();
21
+ return /* @__PURE__ */ o(y, {
22
+ id: i,
23
+ label: r.label,
24
+ required: r.required,
25
+ error: r.error,
26
+ children: /* @__PURE__ */ o("input", {
27
+ id: i,
28
+ type: e,
29
+ name: r.name,
30
+ value: v(r.value),
31
+ onChange: (e) => r.onChange(t(e.target.value)),
32
+ disabled: r.disabled,
33
+ required: r.required,
34
+ "aria-invalid": r.error !== void 0,
35
+ "aria-describedby": b(i, r.error)
36
+ })
37
+ });
38
+ }, ee = (e) => {
39
+ let t = n();
40
+ return /* @__PURE__ */ o(y, {
41
+ id: t,
42
+ label: e.label,
43
+ required: e.required,
44
+ error: e.error,
45
+ children: /* @__PURE__ */ o("textarea", {
46
+ id: t,
47
+ name: e.name,
48
+ value: v(e.value),
49
+ onChange: (t) => e.onChange(t.target.value),
50
+ disabled: e.disabled,
51
+ required: e.required,
52
+ "aria-invalid": e.error !== void 0,
53
+ "aria-describedby": b(t, e.error)
54
+ })
55
+ });
56
+ }, S = (e) => {
57
+ let t = n();
58
+ return /* @__PURE__ */ o(y, {
59
+ id: t,
60
+ label: e.label,
61
+ required: e.required,
62
+ error: e.error,
63
+ children: /* @__PURE__ */ o("input", {
64
+ id: t,
65
+ type: "checkbox",
66
+ name: e.name,
67
+ checked: e.value === !0,
68
+ onChange: (t) => e.onChange(t.target.checked),
69
+ disabled: e.disabled,
70
+ "aria-invalid": e.error !== void 0,
71
+ "aria-describedby": b(t, e.error)
72
+ })
73
+ });
74
+ }, C = {
75
+ text: x("text", (e) => e),
76
+ number: x("number", (e) => e === "" ? void 0 : Number(e)),
77
+ date: x("date", (e) => e),
78
+ datetime: x("datetime-local", (e) => e),
79
+ daterange: x("text", (e) => e),
80
+ file: (e) => {
81
+ let t = n();
82
+ return /* @__PURE__ */ o(y, {
83
+ id: t,
84
+ label: e.label,
85
+ required: e.required,
86
+ error: e.error,
87
+ children: /* @__PURE__ */ o("input", {
88
+ id: t,
89
+ type: "file",
90
+ name: e.name,
91
+ onChange: (t) => e.onChange(t.target.files?.[0] ?? null),
92
+ disabled: e.disabled,
93
+ required: e.required,
94
+ "aria-invalid": e.error !== void 0,
95
+ "aria-describedby": b(t, e.error)
96
+ })
97
+ });
98
+ },
99
+ "async-select": x("text", (e) => e),
100
+ textarea: ee,
101
+ checkbox: S,
102
+ switch: S,
103
+ select: (e) => {
104
+ let t = n();
105
+ return /* @__PURE__ */ o(y, {
106
+ id: t,
107
+ label: e.label,
108
+ required: e.required,
109
+ error: e.error,
110
+ children: /* @__PURE__ */ s("select", {
111
+ id: t,
112
+ name: e.name,
113
+ value: v(e.value),
114
+ onChange: (t) => e.onChange(t.target.value),
115
+ disabled: e.disabled,
116
+ required: e.required,
117
+ "aria-invalid": e.error !== void 0,
118
+ "aria-describedby": b(t, e.error),
119
+ children: [/* @__PURE__ */ o("option", {
120
+ value: "",
121
+ children: "—"
122
+ }), (e.options ?? []).map((e) => /* @__PURE__ */ o("option", {
123
+ value: e.value,
124
+ children: e.label
125
+ }, e.value))]
126
+ })
127
+ });
128
+ },
129
+ radio: (e) => {
130
+ let t = n();
131
+ return /* @__PURE__ */ s("fieldset", {
132
+ "data-voltro-field": !0,
133
+ "aria-invalid": e.error !== void 0,
134
+ children: [
135
+ /* @__PURE__ */ s("legend", { children: [e.label, e.required ? " *" : ""] }),
136
+ (e.options ?? []).map((n) => {
137
+ let r = `${t}-${n.value}`;
138
+ return /* @__PURE__ */ s("span", { children: [/* @__PURE__ */ o("input", {
139
+ id: r,
140
+ type: "radio",
141
+ name: e.name,
142
+ value: n.value,
143
+ checked: v(e.value) === n.value,
144
+ onChange: () => e.onChange(n.value),
145
+ disabled: e.disabled
146
+ }), /* @__PURE__ */ o("label", {
147
+ htmlFor: r,
148
+ children: n.label
149
+ })] }, n.value);
150
+ }),
151
+ e.error === void 0 ? null : /* @__PURE__ */ o("p", {
152
+ role: "alert",
153
+ children: e.error
154
+ })
155
+ ]
156
+ });
157
+ },
158
+ "multi-select": (e) => {
159
+ let t = n(), r = Array.isArray(e.value) ? e.value.map(String) : [];
160
+ return /* @__PURE__ */ o(y, {
161
+ id: t,
162
+ label: e.label,
163
+ required: e.required,
164
+ error: e.error,
165
+ children: /* @__PURE__ */ o("select", {
166
+ id: t,
167
+ name: e.name,
168
+ multiple: !0,
169
+ value: r,
170
+ onChange: (t) => e.onChange(Array.from(t.target.selectedOptions, (e) => e.value)),
171
+ disabled: e.disabled,
172
+ "aria-invalid": e.error !== void 0,
173
+ "aria-describedby": b(t, e.error),
174
+ children: (e.options ?? []).map((e) => /* @__PURE__ */ o("option", {
175
+ value: e.value,
176
+ children: e.label
177
+ }, e.value))
178
+ })
179
+ });
180
+ },
181
+ hidden: (e) => /* @__PURE__ */ o("input", {
182
+ type: "hidden",
183
+ name: e.name,
184
+ value: v(e.value),
185
+ readOnly: !0
186
+ }),
187
+ custom: (e) => /* @__PURE__ */ s("div", {
188
+ "data-voltro-field": !0,
189
+ "data-voltro-custom": !0,
190
+ children: [/* @__PURE__ */ s("label", { children: [e.label, e.required ? " *" : ""] }), /* @__PURE__ */ o("p", {
191
+ role: "note",
192
+ children: `No default widget for "${e.name}" — provide a render-prop via <Field>.`
193
+ })]
194
+ })
195
+ }, w = e({}), T = (e) => {
196
+ let n = t(w), i = r(() => ({
197
+ ...n,
198
+ ...e.widgets
199
+ }), [n, e.widgets]);
200
+ return /* @__PURE__ */ o(w.Provider, {
201
+ value: i,
202
+ children: e.children
203
+ });
204
+ }, E = (e) => t(w)[e] ?? C[e] ?? C.custom, D = e(null), te = () => {
205
+ let e = t(D);
206
+ if (e === null) throw Error("<Field> must be rendered inside <AutoForm>");
207
+ return e;
208
+ }, ne = (e, t) => {
209
+ let n = e.errors[t.name];
210
+ return {
211
+ name: t.name,
212
+ label: t.label,
213
+ value: e.values[t.name],
214
+ onChange: (n) => e.setValue(t.name, n),
215
+ required: t.required,
216
+ disabled: e.pending,
217
+ ...n === void 0 ? {} : { error: n },
218
+ ...t.options ? { options: t.options } : {}
219
+ };
220
+ }, O = ({ name: e, children: t }) => {
221
+ let n = te(), r = n.fields.find((t) => t.name === e), i = E(r?.widget ?? "custom");
222
+ if (r === void 0) return null;
223
+ let a = ne(n, r);
224
+ return t ? t(a) : /* @__PURE__ */ o(i, { ...a });
225
+ };
226
+ function k(e) {
227
+ let t = d(e.api, e.mutation, {
228
+ ...e.schema ? { schema: e.schema } : {},
229
+ ...e.defaults ? { defaults: e.defaults } : {}
230
+ });
231
+ return /* @__PURE__ */ o(D.Provider, {
232
+ value: t,
233
+ children: /* @__PURE__ */ s("form", {
234
+ onSubmit: (n) => {
235
+ n.preventDefault(), t.submit().then((t) => {
236
+ t !== void 0 && e.onSuccess && e.onSuccess(t);
237
+ });
238
+ },
239
+ noValidate: !0,
240
+ "data-voltro-autoform": e.mutation,
241
+ children: [e.children ? e.children(t) : t.fields.map((e) => /* @__PURE__ */ o(O, { name: e.name }, e.name)), /* @__PURE__ */ o("button", {
242
+ type: "submit",
243
+ disabled: t.pending,
244
+ children: e.submitLabel ?? "Submit"
245
+ })]
246
+ })
247
+ });
248
+ }
249
+ //#endregion
250
+ //#region src/strings.tsx
251
+ var A = {
252
+ filters: {
253
+ clear: "Clear",
254
+ filtersLabel: "Filters",
255
+ anyOption: (e) => `Any ${e}`,
256
+ resultCount: (e) => `${e} results`
257
+ },
258
+ asyncSelect: {
259
+ searchPlaceholder: "Search…",
260
+ searchLabel: (e) => `Search ${e}`,
261
+ loading: "Loading…",
262
+ empty: "—"
263
+ },
264
+ dataTable: { actions: "Actions" },
265
+ workflow: {
266
+ status: {
267
+ running: "Running",
268
+ succeeded: "Succeeded",
269
+ failed: "Failed",
270
+ cancelled: "Cancelled",
271
+ suspended: "Waiting"
272
+ },
273
+ attempt: (e) => `attempt ${e}`,
274
+ loading: "Loading…",
275
+ empty: "No steps yet."
276
+ },
277
+ agentChat: {
278
+ reasoning: "Reasoning",
279
+ messagePlaceholder: "Message…",
280
+ messageLabel: "Message",
281
+ send: "Send"
282
+ },
283
+ appAgent: {
284
+ toolsSummary: (e) => `${e} tools · acts as you`,
285
+ needsConfirm: "needs confirm"
286
+ },
287
+ presence: {
288
+ moreOverflow: (e) => `${e} more`,
289
+ onlineCount: (e) => `${e} online`,
290
+ editingOne: (e, t) => `${e} is ${t}`,
291
+ editingTwo: (e, t, n) => `${e} and ${t} are ${n}`,
292
+ editingMany: (e, t, n) => `${e} and ${t} others are ${n}`
293
+ },
294
+ recordView: { emptyRelation: (e) => `No ${e}.` }
295
+ }, j = e(A), M = (e, t) => ({
296
+ filters: {
297
+ ...e.filters,
298
+ ...t.filters
299
+ },
300
+ asyncSelect: {
301
+ ...e.asyncSelect,
302
+ ...t.asyncSelect
303
+ },
304
+ dataTable: {
305
+ ...e.dataTable,
306
+ ...t.dataTable
307
+ },
308
+ workflow: {
309
+ ...e.workflow,
310
+ ...t.workflow,
311
+ status: {
312
+ ...e.workflow.status,
313
+ ...t.workflow?.status
314
+ }
315
+ },
316
+ agentChat: {
317
+ ...e.agentChat,
318
+ ...t.agentChat
319
+ },
320
+ appAgent: {
321
+ ...e.appAgent,
322
+ ...t.appAgent
323
+ },
324
+ presence: {
325
+ ...e.presence,
326
+ ...t.presence
327
+ },
328
+ recordView: {
329
+ ...e.recordView,
330
+ ...t.recordView
331
+ }
332
+ });
333
+ function N(e) {
334
+ let n = t(j), i = r(() => M(n, e.strings), [n, e.strings]);
335
+ return /* @__PURE__ */ o(j.Provider, {
336
+ value: i,
337
+ children: e.children
338
+ });
339
+ }
340
+ var P = () => t(j), F = (e) => {
341
+ let t = p(e.api, e.source, {
342
+ skipUntilTerm: !0,
343
+ ...e.labelField === void 0 ? {} : { labelField: e.labelField },
344
+ ...e.valueField === void 0 ? {} : { valueField: e.valueField },
345
+ ...e.input === void 0 ? {} : { input: e.input },
346
+ ...e.debounceMs === void 0 ? {} : { debounceMs: e.debounceMs }
347
+ }), r = P().asyncSelect, i = n(), a = e.value === void 0 || e.value === null ? "" : String(e.value), c = a !== "" && t.options.some((e) => e.value === a), l = `${i}-error`;
348
+ return /* @__PURE__ */ s("div", {
349
+ "data-voltro-field": !0,
350
+ "data-voltro-async-select": !0,
351
+ children: [
352
+ /* @__PURE__ */ s("label", {
353
+ htmlFor: i,
354
+ children: [e.label, e.required ? " *" : ""]
355
+ }),
356
+ /* @__PURE__ */ o("input", {
357
+ type: "search",
358
+ "aria-label": r.searchLabel(e.label),
359
+ placeholder: r.searchPlaceholder,
360
+ onChange: (e) => t.search(e.target.value),
361
+ disabled: e.disabled
362
+ }),
363
+ /* @__PURE__ */ s("select", {
364
+ id: i,
365
+ name: e.name,
366
+ value: a,
367
+ onChange: (t) => e.onChange(t.target.value),
368
+ disabled: e.disabled,
369
+ required: e.required,
370
+ "aria-invalid": e.error !== void 0,
371
+ "aria-describedby": e.error === void 0 ? void 0 : l,
372
+ "aria-busy": t.loading,
373
+ children: [
374
+ /* @__PURE__ */ o("option", {
375
+ value: "",
376
+ children: t.loading ? r.loading : r.empty
377
+ }),
378
+ a !== "" && !c ? /* @__PURE__ */ o("option", {
379
+ value: a,
380
+ children: a
381
+ }) : null,
382
+ t.options.map((e) => /* @__PURE__ */ o("option", {
383
+ value: e.value,
384
+ children: e.label
385
+ }, e.value))
386
+ ]
387
+ }),
388
+ e.error === void 0 ? null : /* @__PURE__ */ o("p", {
389
+ id: l,
390
+ role: "alert",
391
+ children: e.error
392
+ })
393
+ ]
394
+ });
395
+ }, I = (e) => e == null ? "" : typeof e == "boolean" ? e ? "✓" : "✗" : String(e), re = (e, t) => e ? t === "asc" ? "ascending" : "descending" : "none";
396
+ function ie(e) {
397
+ let { api: t, query: n, emptyText: r, loadingText: i, loadMoreText: c, renderCell: l, rowActions: d, rowKey: f, ...p } = e, m = P().dataTable, h = u(t, n, p);
398
+ return h.loading ? /* @__PURE__ */ o("p", {
399
+ "data-voltro-datatable-loading": !0,
400
+ "aria-busy": "true",
401
+ children: i ?? "Loading…"
402
+ }) : h.rows.length === 0 ? /* @__PURE__ */ o("p", {
403
+ "data-voltro-datatable-empty": !0,
404
+ children: r ?? "No rows."
405
+ }) : /* @__PURE__ */ s(a, { children: [/* @__PURE__ */ s("table", {
406
+ "data-voltro-datatable": n,
407
+ children: [/* @__PURE__ */ o("thead", { children: /* @__PURE__ */ s("tr", { children: [h.columns.map((e) => {
408
+ let t = h.sort?.column === e.name, n = h.sort?.direction ?? "asc";
409
+ return /* @__PURE__ */ o("th", {
410
+ "aria-sort": re(t, n),
411
+ scope: "col",
412
+ children: /* @__PURE__ */ s("button", {
413
+ type: "button",
414
+ onClick: () => h.toggleSort(e.name),
415
+ children: [e.label, t ? n === "asc" ? " ▲" : " ▼" : ""]
416
+ })
417
+ }, e.name);
418
+ }), d ? /* @__PURE__ */ o("th", {
419
+ scope: "col",
420
+ children: m.actions
421
+ }) : null] }) }), /* @__PURE__ */ o("tbody", { children: h.rows.map((e, t) => /* @__PURE__ */ s("tr", { children: [h.columns.map((t) => /* @__PURE__ */ o("td", {
422
+ "data-column": t.name,
423
+ children: l ? l(e, t) : I(e[t.name])
424
+ }, t.name)), d ? /* @__PURE__ */ o("td", { children: d(e) }) : null] }, f ? f(e) : String(e.id ?? t))) })]
425
+ }), h.hasMore ? /* @__PURE__ */ o("button", {
426
+ type: "button",
427
+ "data-voltro-datatable-more": !0,
428
+ onClick: () => h.loadMore(),
429
+ children: c ?? "Load more"
430
+ }) : null] });
431
+ }
432
+ //#endregion
433
+ //#region src/workflow.tsx
434
+ var ae = (e) => e === "succeeded" ? "✓" : e === "failed" ? "✗" : "…";
435
+ function oe(e) {
436
+ let { api: t, runId: n, loadingText: r, emptyText: i } = e, a = P().workflow, c = _(t, n);
437
+ return c.loading ? /* @__PURE__ */ o("p", {
438
+ "data-voltro-workflow-loading": !0,
439
+ "aria-busy": "true",
440
+ children: r ?? a.loading
441
+ }) : c.steps.length === 0 ? /* @__PURE__ */ o("p", {
442
+ "data-voltro-workflow-empty": !0,
443
+ children: i ?? a.empty
444
+ }) : /* @__PURE__ */ o("ol", {
445
+ "data-voltro-workflow-progress": n,
446
+ "aria-busy": c.status === "running" ? "true" : void 0,
447
+ children: c.steps.map((e) => {
448
+ let t = c.currentStep?.id === e.id;
449
+ return /* @__PURE__ */ s("li", {
450
+ "data-step": e.stepName,
451
+ "data-status": e.status,
452
+ "aria-current": t ? "step" : void 0,
453
+ children: [
454
+ /* @__PURE__ */ o("span", {
455
+ "aria-hidden": "true",
456
+ children: ae(e.status)
457
+ }),
458
+ " ",
459
+ e.stepName,
460
+ e.attempt > 1 ? /* @__PURE__ */ s("span", {
461
+ "data-attempts": !0,
462
+ children: [" · ", a.attempt(e.attempt)]
463
+ }) : null,
464
+ e.durationMs === null ? null : /* @__PURE__ */ s("span", {
465
+ "data-duration": !0,
466
+ children: [
467
+ " · ",
468
+ e.durationMs,
469
+ "ms"
470
+ ]
471
+ }),
472
+ e.status === "failed" && e.errorMessage ? /* @__PURE__ */ s("span", {
473
+ "data-step-error": !0,
474
+ children: [" · ", e.errorMessage]
475
+ }) : null
476
+ ]
477
+ }, e.id);
478
+ })
479
+ });
480
+ }
481
+ function se(e) {
482
+ let { api: t, runId: n } = e, r = P().workflow, i = _(t, n);
483
+ if (i.loading || i.status === void 0) return /* @__PURE__ */ o("span", {
484
+ "data-voltro-workflow-badge": !0,
485
+ "data-status": "loading",
486
+ children: "…"
487
+ });
488
+ let a = i.status === "suspended" && i.waitingFor ? `${r.status.suspended} · ${i.waitingFor.name}` : r.status[i.status];
489
+ return /* @__PURE__ */ s("span", {
490
+ "data-voltro-workflow-badge": !0,
491
+ "data-status": i.status,
492
+ role: "status",
493
+ children: [a, i.error ? /* @__PURE__ */ s("span", {
494
+ "data-error-detail": !0,
495
+ children: [i.error.step ? ` · ${i.error.step}` : "", i.traceId ? ` · voltro logs --trace ${i.traceId}` : ""]
496
+ }) : null]
497
+ });
498
+ }
499
+ function ce(e) {
500
+ let { when: t, onApprove: n, onReject: r, approveLabel: i, rejectLabel: a, pending: c } = e;
501
+ return t ? /* @__PURE__ */ s("div", {
502
+ "data-voltro-approval-controls": !0,
503
+ role: "group",
504
+ "aria-label": "Approval",
505
+ children: [/* @__PURE__ */ o("button", {
506
+ type: "button",
507
+ "data-approve": !0,
508
+ onClick: n,
509
+ disabled: c,
510
+ children: i ?? "Approve"
511
+ }), /* @__PURE__ */ o("button", {
512
+ type: "button",
513
+ "data-reject": !0,
514
+ onClick: r,
515
+ disabled: c,
516
+ children: a ?? "Reject"
517
+ })]
518
+ }) : null;
519
+ }
520
+ //#endregion
521
+ //#region src/presence.tsx
522
+ var L = (e, t) => {
523
+ let n = e.meta?.[t];
524
+ return typeof n == "string" ? n : void 0;
525
+ }, R = (e) => L(e, "name") ?? L(e, "displayName") ?? e.key, z = (e) => {
526
+ let t = e.trim().split(/\s+/).filter(Boolean);
527
+ return t.length === 0 ? "?" : t.length === 1 ? t[0].slice(0, 2).toUpperCase() : (t[0][0] + t[t.length - 1][0]).toUpperCase();
528
+ };
529
+ function B(e) {
530
+ let { members: t, max: n = 5, nameOf: r = R, renderAvatar: i } = e, a = P().presence, c = t.slice(0, n), l = t.length - c.length;
531
+ return /* @__PURE__ */ s("div", {
532
+ "data-voltro-presence-avatars": !0,
533
+ role: "group",
534
+ "aria-label": a.onlineCount(t.length),
535
+ children: [c.map((e) => {
536
+ let t = r(e);
537
+ return i ? /* @__PURE__ */ o("span", { children: i(e, t) }, e.key) : /* @__PURE__ */ o("span", {
538
+ "data-avatar": !0,
539
+ title: t,
540
+ "aria-label": t,
541
+ children: z(t)
542
+ }, e.key);
543
+ }), l > 0 ? /* @__PURE__ */ s("span", {
544
+ "data-avatar-overflow": !0,
545
+ "aria-label": a.moreOverflow(l),
546
+ children: ["+", l]
547
+ }) : null]
548
+ });
549
+ }
550
+ var V = (e, t, n = A.presence) => e.length === 0 ? "" : e.length === 1 ? n.editingOne(e[0], t) : e.length === 2 ? n.editingTwo(e[0], e[1], t) : n.editingMany(e[0], e.length - 1, t);
551
+ function H(e) {
552
+ let { members: t, selfKey: n, field: r, verb: i = "editing", nameOf: a = R } = e, s = P().presence, c = t.filter((e) => !(n !== void 0 && e.key === n || r !== void 0 && L(e, "field") !== r));
553
+ return c.length === 0 ? null : /* @__PURE__ */ o("span", {
554
+ "data-voltro-editing-indicator": !0,
555
+ "data-field": r,
556
+ role: "status",
557
+ children: V(c.map(a), i, s)
558
+ });
559
+ }
560
+ //#endregion
561
+ //#region src/agentChat.tsx
562
+ var U = (e) => typeof e.text == "string" ? e.text : "";
563
+ function W({ text: e }) {
564
+ let t = P().agentChat;
565
+ return /* @__PURE__ */ s("details", {
566
+ "data-part": "reasoning",
567
+ children: [/* @__PURE__ */ o("summary", { children: t.reasoning }), /* @__PURE__ */ o("span", { children: e })]
568
+ });
569
+ }
570
+ function G({ part: e }) {
571
+ switch (e.type) {
572
+ case "text": return /* @__PURE__ */ o("span", {
573
+ "data-part": "text",
574
+ children: U(e)
575
+ });
576
+ case "reasoning": return /* @__PURE__ */ o(W, { text: U(e) });
577
+ case "tool": {
578
+ let t = e;
579
+ return /* @__PURE__ */ s("span", {
580
+ "data-part": "tool",
581
+ "data-tool": t.toolName,
582
+ "data-state": t.state,
583
+ children: ["🔧 ", t.toolName]
584
+ });
585
+ }
586
+ case "source": {
587
+ let t = e;
588
+ return t.url ? /* @__PURE__ */ o("a", {
589
+ "data-part": "source",
590
+ href: t.url,
591
+ rel: "noreferrer",
592
+ children: t.title ?? t.url
593
+ }) : /* @__PURE__ */ o("span", {
594
+ "data-part": "source",
595
+ children: t.title ?? t.id ?? "source"
596
+ });
597
+ }
598
+ case "file": {
599
+ let t = e;
600
+ return t.mediaType.startsWith("image/") ? /* @__PURE__ */ o("img", {
601
+ "data-part": "file",
602
+ alt: "",
603
+ src: `data:${t.mediaType};base64,${t.data}`
604
+ }) : /* @__PURE__ */ s("span", {
605
+ "data-part": "file",
606
+ "data-media": t.mediaType,
607
+ children: ["📎 ", t.mediaType]
608
+ });
609
+ }
610
+ default: return /* @__PURE__ */ o("span", {
611
+ "data-part": e.type,
612
+ children: JSON.stringify(e)
613
+ });
614
+ }
615
+ }
616
+ function K({ message: e }) {
617
+ let t = e.parts ?? [];
618
+ return /* @__PURE__ */ s("div", {
619
+ "data-voltro-agent-message": !0,
620
+ "data-role": e.role,
621
+ "data-streaming": e.streaming ? "true" : void 0,
622
+ "aria-busy": e.streaming ? "true" : void 0,
623
+ children: [t.length > 0 ? t.map((e, t) => /* @__PURE__ */ o(G, { part: e }, t)) : /* @__PURE__ */ o("span", {
624
+ "data-part": "text",
625
+ children: e.content
626
+ }), e.streaming ? /* @__PURE__ */ o("span", {
627
+ "data-cursor": !0,
628
+ "aria-hidden": "true",
629
+ children: "▍"
630
+ }) : null]
631
+ });
632
+ }
633
+ function q(e) {
634
+ let { api: t, agent: n, threadId: r, placeholder: a, sendLabel: l, emptyText: u } = e, d = P().agentChat, f = c(t, n, { threadId: r }), [p, m] = i(""), h = () => {
635
+ let e = p.trim();
636
+ e.length === 0 || f.sending || (m(""), f.send(e));
637
+ };
638
+ return /* @__PURE__ */ s("div", {
639
+ "data-voltro-agent-chat": n,
640
+ children: [/* @__PURE__ */ o("div", {
641
+ "data-messages": !0,
642
+ role: "log",
643
+ "aria-live": "polite",
644
+ "aria-busy": f.streaming ? "true" : void 0,
645
+ children: f.messages.length === 0 && !f.loading ? /* @__PURE__ */ o("p", {
646
+ "data-empty": !0,
647
+ children: u ?? "No messages yet."
648
+ }) : f.messages.map((e) => /* @__PURE__ */ o(K, { message: e }, e.id))
649
+ }), /* @__PURE__ */ s("form", {
650
+ "data-composer": !0,
651
+ onSubmit: (e) => {
652
+ e.preventDefault(), h();
653
+ },
654
+ children: [/* @__PURE__ */ o("input", {
655
+ value: p,
656
+ onChange: (e) => m(e.target.value),
657
+ placeholder: a ?? d.messagePlaceholder,
658
+ "aria-label": d.messageLabel,
659
+ disabled: f.sending
660
+ }), /* @__PURE__ */ o("button", {
661
+ type: "submit",
662
+ disabled: f.sending || p.trim().length === 0,
663
+ children: l ?? d.send
664
+ })]
665
+ })]
666
+ });
667
+ }
668
+ function le(e) {
669
+ let t = c(e.api, e.agent, { threadId: e.threadId });
670
+ return e.children(t);
671
+ }
672
+ //#endregion
673
+ //#region src/appAgent.tsx
674
+ function ue(e) {
675
+ let { tools: t, showTools: n, ...r } = e, i = P().appAgent, a = (n ?? (t !== void 0 && t.length > 0)) && t && t.length > 0;
676
+ return /* @__PURE__ */ s("div", {
677
+ "data-voltro-app-agent": r.agent,
678
+ children: [a ? /* @__PURE__ */ s("details", {
679
+ "data-agent-tools": !0,
680
+ children: [/* @__PURE__ */ o("summary", { children: i.toolsSummary(t.length) }), /* @__PURE__ */ o("ul", { children: t.map((e) => /* @__PURE__ */ s("li", {
681
+ "data-tool": e.name,
682
+ "data-write": e.write ? "true" : void 0,
683
+ children: [
684
+ /* @__PURE__ */ o("code", { children: e.name }),
685
+ e.confirm ? /* @__PURE__ */ s("span", {
686
+ "data-confirm": !0,
687
+ children: [" · ", i.needsConfirm]
688
+ }) : null,
689
+ e.description ? /* @__PURE__ */ s("span", {
690
+ "data-desc": !0,
691
+ children: [" — ", e.description]
692
+ }) : null
693
+ ]
694
+ }, e.name)) })]
695
+ }) : null, /* @__PURE__ */ o(q, { ...r })]
696
+ });
697
+ }
698
+ //#endregion
699
+ //#region src/dataCopilot.tsx
700
+ var de = (e) => e == null ? "" : typeof e == "boolean" ? e ? "✓" : "✗" : typeof e == "object" ? JSON.stringify(e) : String(e), fe = (e) => {
701
+ let t = /* @__PURE__ */ new Set(), n = [];
702
+ for (let r of e) for (let e of Object.keys(r)) t.has(e) || (t.add(e), n.push(e));
703
+ return n;
704
+ };
705
+ function J(e) {
706
+ let { answer: t, emptyText: n } = e;
707
+ if (t === void 0) return null;
708
+ if (!t.ok) return /* @__PURE__ */ o("p", {
709
+ "data-voltro-data-copilot-refused": !0,
710
+ role: "status",
711
+ children: t.reason
712
+ });
713
+ if (t.rows.length === 0) return /* @__PURE__ */ o("p", {
714
+ "data-voltro-data-copilot-empty": !0,
715
+ children: n ?? "No rows."
716
+ });
717
+ let r = fe(t.rows);
718
+ return /* @__PURE__ */ s("table", {
719
+ "data-voltro-data-copilot-results": !0,
720
+ children: [/* @__PURE__ */ o("thead", { children: /* @__PURE__ */ o("tr", { children: r.map((e) => /* @__PURE__ */ o("th", {
721
+ scope: "col",
722
+ children: e
723
+ }, e)) }) }), /* @__PURE__ */ o("tbody", { children: t.rows.map((e, t) => /* @__PURE__ */ o("tr", { children: r.map((t) => /* @__PURE__ */ o("td", {
724
+ "data-column": t,
725
+ children: de(e[t])
726
+ }, t)) }, String(e.id ?? t))) })]
727
+ });
728
+ }
729
+ function pe(e) {
730
+ let { api: t, action: n, placeholder: r, askLabel: a, emptyText: c } = e, u = l(t, n), [d, f] = i(""), p = () => {
731
+ let e = d.trim();
732
+ e.length === 0 || u.pending || u.ask(e);
733
+ };
734
+ return /* @__PURE__ */ s("div", {
735
+ "data-voltro-data-copilot": n,
736
+ children: [/* @__PURE__ */ s("form", {
737
+ "data-composer": !0,
738
+ onSubmit: (e) => {
739
+ e.preventDefault(), p();
740
+ },
741
+ children: [/* @__PURE__ */ o("input", {
742
+ value: d,
743
+ onChange: (e) => f(e.target.value),
744
+ placeholder: r ?? "Ask about your data…",
745
+ "aria-label": "Ask about your data",
746
+ disabled: u.pending
747
+ }), /* @__PURE__ */ o("button", {
748
+ type: "submit",
749
+ disabled: u.pending || d.trim().length === 0,
750
+ children: a ?? "Ask"
751
+ })]
752
+ }), /* @__PURE__ */ o("div", {
753
+ "data-answer": !0,
754
+ "aria-live": "polite",
755
+ "aria-busy": u.pending ? "true" : void 0,
756
+ children: u.error === void 0 ? /* @__PURE__ */ o(J, {
757
+ answer: u.answer,
758
+ ...c === void 0 ? {} : { emptyText: c }
759
+ }) : /* @__PURE__ */ o("p", {
760
+ "data-voltro-data-copilot-error": !0,
761
+ role: "alert",
762
+ children: u.error instanceof Error ? u.error.message : String(u.error)
763
+ })
764
+ })]
765
+ });
766
+ }
767
+ function me(e) {
768
+ let t = l(e.api, e.action);
769
+ return e.children(t);
770
+ }
771
+ //#endregion
772
+ //#region src/skeleton.tsx
773
+ var Y = ({ w: e }) => /* @__PURE__ */ o("span", {
774
+ "data-skeleton-bar": !0,
775
+ style: {
776
+ display: "inline-block",
777
+ width: e ?? "100%",
778
+ height: "1em",
779
+ borderRadius: 4
780
+ },
781
+ "aria-hidden": "true"
782
+ });
783
+ function he(e) {
784
+ let t = f(e.api, e.mutation), n = t.length > 0 ? t.length : e.fallbackFields ?? 3, r = t.length > 0 ? t.map((e) => e.name) : Array.from({ length: n }, (e, t) => `f${t}`);
785
+ return /* @__PURE__ */ o("div", {
786
+ "data-voltro-form-skeleton": e.mutation,
787
+ "aria-busy": "true",
788
+ "aria-hidden": "true",
789
+ children: r.map((e) => /* @__PURE__ */ s("div", {
790
+ "data-skeleton-field": !0,
791
+ children: [/* @__PURE__ */ o(Y, { w: "30%" }), /* @__PURE__ */ o(Y, {})]
792
+ }, e))
793
+ });
794
+ }
795
+ function ge(e) {
796
+ let t = g(e.api, e.query), n = t.length > 0 ? t.length : e.fallbackColumns ?? 4, r = t.length > 0 ? t.map((e) => e.name) : Array.from({ length: n }, (e, t) => `c${t}`), i = e.rows ?? 5;
797
+ return /* @__PURE__ */ s("table", {
798
+ "data-voltro-table-skeleton": e.query,
799
+ "aria-busy": "true",
800
+ "aria-hidden": "true",
801
+ children: [/* @__PURE__ */ o("thead", { children: /* @__PURE__ */ o("tr", { children: r.map((e) => /* @__PURE__ */ o("th", {
802
+ scope: "col",
803
+ children: /* @__PURE__ */ o(Y, { w: "60%" })
804
+ }, e)) }) }), /* @__PURE__ */ o("tbody", { children: Array.from({ length: i }, (e, t) => /* @__PURE__ */ o("tr", {
805
+ "data-skeleton-row": !0,
806
+ children: r.map((e) => /* @__PURE__ */ o("td", { children: /* @__PURE__ */ o(Y, {}) }, e))
807
+ }, t)) })]
808
+ });
809
+ }
810
+ //#endregion
811
+ //#region src/filters.tsx
812
+ var X = (e) => e == null ? "" : String(e);
813
+ function _e(e) {
814
+ let { filter: t, value: n, onChange: r } = e, i = P().filters, a = {
815
+ "data-filter": t.name,
816
+ "aria-label": t.label
817
+ };
818
+ switch (t.kind) {
819
+ case "select": return /* @__PURE__ */ s("select", {
820
+ ...a,
821
+ value: X(n),
822
+ onChange: (e) => r(e.target.value || void 0),
823
+ children: [/* @__PURE__ */ o("option", {
824
+ value: "",
825
+ children: i.anyOption(t.label)
826
+ }), (t.options ?? []).map((e) => /* @__PURE__ */ o("option", {
827
+ value: e.value,
828
+ children: e.label
829
+ }, e.value))]
830
+ });
831
+ case "multi-select": return /* @__PURE__ */ o("select", {
832
+ ...a,
833
+ multiple: !0,
834
+ value: Array.isArray(n) ? n : [],
835
+ onChange: (e) => r(Array.from(e.target.selectedOptions, (e) => e.value)),
836
+ children: (t.options ?? []).map((e) => /* @__PURE__ */ o("option", {
837
+ value: e.value,
838
+ children: e.label
839
+ }, e.value))
840
+ });
841
+ case "boolean": return /* @__PURE__ */ o("input", {
842
+ ...a,
843
+ type: "checkbox",
844
+ checked: n === !0,
845
+ onChange: (e) => r(e.target.checked ? !0 : void 0)
846
+ });
847
+ case "number-range":
848
+ case "date-range": {
849
+ let e = t.kind === "number-range" ? "number" : "date", i = n ?? {};
850
+ return /* @__PURE__ */ s("span", {
851
+ "data-filter": t.name,
852
+ "data-range": t.kind,
853
+ children: [/* @__PURE__ */ o("input", {
854
+ "aria-label": `${t.label} from`,
855
+ type: e,
856
+ value: X(i.gte),
857
+ onChange: (e) => r({
858
+ ...i,
859
+ gte: e.target.value || void 0
860
+ })
861
+ }), /* @__PURE__ */ o("input", {
862
+ "aria-label": `${t.label} to`,
863
+ type: e,
864
+ value: X(i.lte),
865
+ onChange: (e) => r({
866
+ ...i,
867
+ lte: e.target.value || void 0
868
+ })
869
+ })]
870
+ });
871
+ }
872
+ default: return /* @__PURE__ */ o("input", {
873
+ ...a,
874
+ type: "text",
875
+ value: X(n),
876
+ onChange: (e) => r(e.target.value || void 0)
877
+ });
878
+ }
879
+ }
880
+ function ve(e) {
881
+ let t = m(e.api, e.query, e.initial ? { initial: e.initial } : {}), n = P().filters;
882
+ return /* @__PURE__ */ s("div", {
883
+ "data-voltro-query-filters": e.query,
884
+ children: [/* @__PURE__ */ s("div", {
885
+ "data-filter-controls": !0,
886
+ role: "group",
887
+ "aria-label": n.filtersLabel,
888
+ children: [
889
+ t.filters.map((e) => /* @__PURE__ */ s("label", {
890
+ "data-filter-label": !0,
891
+ children: [/* @__PURE__ */ o("span", { children: e.label }), /* @__PURE__ */ o(_e, {
892
+ filter: e,
893
+ value: t.values[e.name],
894
+ onChange: (n) => t.setFilter(e.name, n)
895
+ })]
896
+ }, e.name)),
897
+ /* @__PURE__ */ o("button", {
898
+ type: "button",
899
+ "data-filter-clear": !0,
900
+ onClick: () => t.clear(),
901
+ children: n.clear
902
+ }),
903
+ e.showCount ?? !0 ? /* @__PURE__ */ o("span", {
904
+ "data-filter-count": !0,
905
+ children: n.resultCount(t.count ?? "…")
906
+ }) : null
907
+ ]
908
+ }), e.children ? e.children(t) : null]
909
+ });
910
+ }
911
+ //#endregion
912
+ //#region src/recordView.tsx
913
+ var Z = (e) => e.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/^./, (e) => e.toUpperCase()), Q = (e) => Array.isArray(e) && e.every((e) => typeof e == "object" && !!e), $ = (e) => e == null ? "—" : typeof e == "boolean" ? e ? "✓" : "✗" : String(e);
914
+ function ye({ name: e, items: t }) {
915
+ let n = P().recordView;
916
+ if (t.length === 0) return /* @__PURE__ */ o("p", {
917
+ "data-relation": e,
918
+ "data-empty": !0,
919
+ children: n.emptyRelation(Z(e).toLowerCase())
920
+ });
921
+ let r = Object.keys(t[0]);
922
+ return /* @__PURE__ */ s("table", {
923
+ "data-relation": e,
924
+ children: [/* @__PURE__ */ o("thead", { children: /* @__PURE__ */ o("tr", { children: r.map((e) => /* @__PURE__ */ o("th", {
925
+ scope: "col",
926
+ children: Z(e)
927
+ }, e)) }) }), /* @__PURE__ */ o("tbody", { children: t.map((e, t) => /* @__PURE__ */ o("tr", { children: r.map((t) => /* @__PURE__ */ o("td", { children: $(e[t]) }, t)) }, String(e.id ?? t))) })]
928
+ });
929
+ }
930
+ function be(e) {
931
+ let { api: t, query: n, input: r, fields: i, renderField: a, renderRelation: c, loadingText: l, emptyText: u } = e, { record: d, loading: f } = h(t, n, r ?? {});
932
+ if (f) return /* @__PURE__ */ o("p", {
933
+ "data-voltro-record-loading": !0,
934
+ "aria-busy": "true",
935
+ children: l ?? "Loading…"
936
+ });
937
+ if (d == null) return /* @__PURE__ */ o("p", {
938
+ "data-voltro-record-empty": !0,
939
+ children: u ?? "Not found."
940
+ });
941
+ let p = Object.entries(d), m = p.filter(([e, t]) => !Q(t) && (i === void 0 || i.includes(e))), g = p.filter(([, e]) => Q(e));
942
+ return /* @__PURE__ */ s("div", {
943
+ "data-voltro-record-view": n,
944
+ children: [/* @__PURE__ */ o("dl", {
945
+ "data-record-fields": !0,
946
+ children: (i === void 0 ? m : i.map((e) => [e, d[e]]).filter(([, e]) => !Q(e))).map(([e, t]) => /* @__PURE__ */ s("div", {
947
+ "data-field": e,
948
+ children: [/* @__PURE__ */ o("dt", { children: Z(e) }), /* @__PURE__ */ o("dd", { children: a ? a(e, t, d) : $(t) })]
949
+ }, e))
950
+ }), g.map(([e, t]) => /* @__PURE__ */ s("section", {
951
+ "data-record-relation": e,
952
+ children: [/* @__PURE__ */ o("h3", { children: Z(e) }), c ? c(e, t, d) : /* @__PURE__ */ o(ye, {
953
+ name: e,
954
+ items: t
955
+ })]
956
+ }, e))]
957
+ });
958
+ }
959
+ //#endregion
960
+ export { q as AgentChat, K as AgentMessageView, G as AgentPartView, le as AgentStream, ue as AppAgent, ce as ApprovalControls, F as AsyncSelect, k as AutoForm, pe as DataCopilot, J as DataCopilotAnswer, me as DataCopilotStream, ie as DataTable, H as EditingIndicator, O as Field, he as FormSkeleton, B as PresenceAvatars, ve as QueryFilters, be as RecordView, ge as TableSkeleton, N as UiStringsProvider, T as WidgetRegistryProvider, oe as WorkflowProgress, se as WorkflowStatusBadge, A as defaultUiStrings, C as defaultWidgets, z as initials, V as summarizeEditors, P as useUiStrings, E as useWidget };