@voltro/ui 0.85.0 → 0.87.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.
@@ -0,0 +1,29 @@
1
+ //#region src/achievementStrings.ts
2
+ var e = {
3
+ en: {
4
+ title: "Achievements",
5
+ loading: "Loading achievements…",
6
+ empty: "No visible achievements.",
7
+ unavailable: "Achievements could not be loaded. Reconnect to try again.",
8
+ invalid: "Achievement data is invalid. Reconnect to request it again.",
9
+ locked: "In progress",
10
+ unlocked: "Unlocked",
11
+ tier: (e) => `Tier ${e}`,
12
+ progress: (e, t, n) => `${e}: ${t} of ${n}`,
13
+ unlockedDate: (e) => `Unlocked ${e}`
14
+ },
15
+ de: {
16
+ title: "Achievements",
17
+ loading: "Achievements werden geladen…",
18
+ empty: "Keine sichtbaren Achievements.",
19
+ unavailable: "Achievements konnten nicht geladen werden. Erneut verbinden und wieder versuchen.",
20
+ invalid: "Die Achievement-Daten sind ungültig. Erneut verbinden fordert sie neu an.",
21
+ locked: "In Arbeit",
22
+ unlocked: "Freigeschaltet",
23
+ tier: (e) => `Stufe ${e}`,
24
+ progress: (e, t, n) => `${e}: ${t} von ${n}`,
25
+ unlockedDate: (e) => `Freigeschaltet ${e}`
26
+ }
27
+ };
28
+ //#endregion
29
+ export { e as achievementUiStrings };
@@ -0,0 +1,117 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { useState as t } from "react";
3
+ import { useAgentChat as n } from "@voltro/client";
4
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
5
+ //#region src/agentChat.tsx
6
+ var a = (e) => typeof e.text == "string" ? e.text : "";
7
+ function o({ text: t }) {
8
+ let n = e().agentChat;
9
+ return /* @__PURE__ */ i("details", {
10
+ "data-part": "reasoning",
11
+ children: [/* @__PURE__ */ r("summary", { children: n.reasoning }), /* @__PURE__ */ r("span", { children: t })]
12
+ });
13
+ }
14
+ function s({ part: e }) {
15
+ switch (e.type) {
16
+ case "text": return /* @__PURE__ */ r("span", {
17
+ "data-part": "text",
18
+ children: a(e)
19
+ });
20
+ case "reasoning": return /* @__PURE__ */ r(o, { text: a(e) });
21
+ case "tool": {
22
+ let t = e;
23
+ return /* @__PURE__ */ i("span", {
24
+ "data-part": "tool",
25
+ "data-tool": t.toolName,
26
+ "data-state": t.state,
27
+ children: ["🔧 ", t.toolName]
28
+ });
29
+ }
30
+ case "source": {
31
+ let t = e;
32
+ return t.url ? /* @__PURE__ */ r("a", {
33
+ "data-part": "source",
34
+ href: t.url,
35
+ rel: "noreferrer",
36
+ children: t.title ?? t.url
37
+ }) : /* @__PURE__ */ r("span", {
38
+ "data-part": "source",
39
+ children: t.title ?? t.id ?? "source"
40
+ });
41
+ }
42
+ case "file": {
43
+ let t = e;
44
+ return t.mediaType.startsWith("image/") ? /* @__PURE__ */ r("img", {
45
+ "data-part": "file",
46
+ alt: "",
47
+ src: `data:${t.mediaType};base64,${t.data}`
48
+ }) : /* @__PURE__ */ i("span", {
49
+ "data-part": "file",
50
+ "data-media": t.mediaType,
51
+ children: ["📎 ", t.mediaType]
52
+ });
53
+ }
54
+ default: return /* @__PURE__ */ r("span", {
55
+ "data-part": e.type,
56
+ children: JSON.stringify(e)
57
+ });
58
+ }
59
+ }
60
+ function c({ message: e }) {
61
+ let t = e.parts ?? [];
62
+ return /* @__PURE__ */ i("div", {
63
+ "data-voltro-agent-message": !0,
64
+ "data-role": e.role,
65
+ "data-streaming": e.streaming ? "true" : void 0,
66
+ "aria-busy": e.streaming ? "true" : void 0,
67
+ children: [t.length > 0 ? t.map((e, t) => /* @__PURE__ */ r(s, { part: e }, t)) : /* @__PURE__ */ r("span", {
68
+ "data-part": "text",
69
+ children: e.content
70
+ }), e.streaming ? /* @__PURE__ */ r("span", {
71
+ "data-cursor": !0,
72
+ "aria-hidden": "true",
73
+ children: "▍"
74
+ }) : null]
75
+ });
76
+ }
77
+ function l(a) {
78
+ let { api: o, agent: s, threadId: l, placeholder: u, sendLabel: d, emptyText: f } = a, p = e().agentChat, m = n(o, s, { threadId: l }), [h, g] = t(""), _ = () => {
79
+ let e = h.trim();
80
+ e.length === 0 || m.sending || (g(""), m.send(e));
81
+ };
82
+ return /* @__PURE__ */ i("div", {
83
+ "data-voltro-agent-chat": s,
84
+ children: [/* @__PURE__ */ r("div", {
85
+ "data-messages": !0,
86
+ role: "log",
87
+ "aria-live": "polite",
88
+ "aria-busy": m.streaming ? "true" : void 0,
89
+ children: m.messages.length === 0 && !m.loading ? /* @__PURE__ */ r("p", {
90
+ "data-empty": !0,
91
+ children: f ?? "No messages yet."
92
+ }) : m.messages.map((e) => /* @__PURE__ */ r(c, { message: e }, e.id))
93
+ }), /* @__PURE__ */ i("form", {
94
+ "data-composer": !0,
95
+ onSubmit: (e) => {
96
+ e.preventDefault(), _();
97
+ },
98
+ children: [/* @__PURE__ */ r("input", {
99
+ value: h,
100
+ onChange: (e) => g(e.target.value),
101
+ placeholder: u ?? p.messagePlaceholder,
102
+ "aria-label": p.messageLabel,
103
+ disabled: m.sending
104
+ }), /* @__PURE__ */ r("button", {
105
+ type: "submit",
106
+ disabled: m.sending || h.trim().length === 0,
107
+ children: d ?? p.send
108
+ })]
109
+ })]
110
+ });
111
+ }
112
+ function u(e) {
113
+ let t = n(e.api, e.agent, { threadId: e.threadId });
114
+ return e.children(t);
115
+ }
116
+ //#endregion
117
+ export { l as AgentChat, c as AgentMessageView, s as AgentPartView, u as AgentStream };
@@ -0,0 +1,30 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { AgentChat as t } from "./agentChat.js";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ //#region src/appAgent.tsx
5
+ function i(i) {
6
+ let { tools: a, showTools: o, ...s } = i, c = e().appAgent, l = (o ?? (a !== void 0 && a.length > 0)) && a && a.length > 0;
7
+ return /* @__PURE__ */ r("div", {
8
+ "data-voltro-app-agent": s.agent,
9
+ children: [l ? /* @__PURE__ */ r("details", {
10
+ "data-agent-tools": !0,
11
+ children: [/* @__PURE__ */ n("summary", { children: c.toolsSummary(a.length) }), /* @__PURE__ */ n("ul", { children: a.map((e) => /* @__PURE__ */ r("li", {
12
+ "data-tool": e.name,
13
+ "data-write": e.write ? "true" : void 0,
14
+ children: [
15
+ /* @__PURE__ */ n("code", { children: e.name }),
16
+ e.confirm ? /* @__PURE__ */ r("span", {
17
+ "data-confirm": !0,
18
+ children: [" · ", c.needsConfirm]
19
+ }) : null,
20
+ e.description ? /* @__PURE__ */ r("span", {
21
+ "data-desc": !0,
22
+ children: [" — ", e.description]
23
+ }) : null
24
+ ]
25
+ }, e.name)) })]
26
+ }) : null, /* @__PURE__ */ n(t, { ...s })]
27
+ });
28
+ }
29
+ //#endregion
30
+ export { i as AppAgent };
@@ -0,0 +1,63 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { useId as t } from "react";
3
+ import { useQueryField as n } from "@voltro/client";
4
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
5
+ //#region src/asyncSelect.tsx
6
+ var a = (a) => {
7
+ let o = n(a.api, a.source, {
8
+ skipUntilTerm: !0,
9
+ ...a.labelField === void 0 ? {} : { labelField: a.labelField },
10
+ ...a.valueField === void 0 ? {} : { valueField: a.valueField },
11
+ ...a.input === void 0 ? {} : { input: a.input },
12
+ ...a.debounceMs === void 0 ? {} : { debounceMs: a.debounceMs }
13
+ }), s = e().asyncSelect, c = t(), l = a.value === void 0 || a.value === null ? "" : String(a.value), u = l !== "" && o.options.some((e) => e.value === l), d = `${c}-error`;
14
+ return /* @__PURE__ */ i("div", {
15
+ "data-voltro-field": !0,
16
+ "data-voltro-async-select": !0,
17
+ children: [
18
+ /* @__PURE__ */ i("label", {
19
+ htmlFor: c,
20
+ children: [a.label, a.required ? " *" : ""]
21
+ }),
22
+ /* @__PURE__ */ r("input", {
23
+ type: "search",
24
+ "aria-label": s.searchLabel(a.label),
25
+ placeholder: s.searchPlaceholder,
26
+ onChange: (e) => o.search(e.target.value),
27
+ disabled: a.disabled
28
+ }),
29
+ /* @__PURE__ */ i("select", {
30
+ id: c,
31
+ name: a.name,
32
+ value: l,
33
+ onChange: (e) => a.onChange(e.target.value),
34
+ disabled: a.disabled,
35
+ required: a.required,
36
+ "aria-invalid": a.error !== void 0,
37
+ "aria-describedby": a.error === void 0 ? void 0 : d,
38
+ "aria-busy": o.loading,
39
+ children: [
40
+ /* @__PURE__ */ r("option", {
41
+ value: "",
42
+ children: o.loading ? s.loading : s.empty
43
+ }),
44
+ l !== "" && !u ? /* @__PURE__ */ r("option", {
45
+ value: l,
46
+ children: l
47
+ }) : null,
48
+ o.options.map((e) => /* @__PURE__ */ r("option", {
49
+ value: e.value,
50
+ children: e.label
51
+ }, e.value))
52
+ ]
53
+ }),
54
+ a.error === void 0 ? null : /* @__PURE__ */ r("p", {
55
+ id: d,
56
+ role: "alert",
57
+ children: a.error
58
+ })
59
+ ]
60
+ });
61
+ };
62
+ //#endregion
63
+ export { a as AsyncSelect };
@@ -0,0 +1,104 @@
1
+ import { useWidget as e } from "./widgets.js";
2
+ import { createContext as t, useContext as n, useMemo as r } from "react";
3
+ import { FORM_CAPTURE_FIELD as i, FORM_KEY_FIELD as a, FORM_REDIRECT_FIELD as o, FORM_SOURCE_FIELD as s, FormBindingProvider as c, formActionPath as l, formSections as u, useFormBinding as d, useFormCapture as f, useFormFlash as p, useServerRequest as m } from "@voltro/client";
4
+ import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
5
+ //#region src/autoForm.tsx
6
+ var v = t(null), y = () => {
7
+ let e = n(v);
8
+ if (e === null) throw Error("<Field> must be rendered inside <AutoForm>");
9
+ return e;
10
+ }, b = (e, t) => {
11
+ let n = e.field(t.name);
12
+ return {
13
+ name: t.name,
14
+ label: t.label,
15
+ value: n.value,
16
+ onChange: n.setValue,
17
+ onBlur: n.onBlur,
18
+ required: t.required,
19
+ disabled: e.pending,
20
+ ...n.error === void 0 ? {} : { error: n.error },
21
+ ...t.options ? { options: t.options } : {},
22
+ ...n.description === void 0 ? {} : { description: n.description },
23
+ ...t.reference === void 0 ? {} : { reference: t.reference }
24
+ };
25
+ }, x = ({ name: t, children: n }) => {
26
+ let { binding: r, fields: i } = y(), a = i.get(t), o = e(a?.widget ?? "custom");
27
+ if (a === void 0) return null;
28
+ let s = b(r, a);
29
+ return n ? n(s) : /* @__PURE__ */ g(o, { ...s });
30
+ };
31
+ function S(e) {
32
+ let t = e.formKey ?? e.mutation, n = p(t), y = f(), b = m()?.url ?? (typeof window > "u" ? "" : window.location.pathname + window.location.search), S = n?.sourcePath ?? (y === void 0 ? b.includes("?") ? "" : b.split("#")[0] : b.split(/[?#]/)[0]), C = d(e.api, e.mutation, {
33
+ formKey: t,
34
+ ...e.schema ? { schema: e.schema } : {},
35
+ ...e.defaults ? { defaults: e.defaults } : {},
36
+ ...n === void 0 ? {} : { flash: n }
37
+ }), w = r(() => {
38
+ let e = /* @__PURE__ */ new Map();
39
+ for (let t of C.fields) e.has(t.name) || e.set(t.name, t);
40
+ return e;
41
+ }, [C.fields]), T = r(() => ({
42
+ binding: C,
43
+ fields: w
44
+ }), [C, w]), E = (t) => {
45
+ t.preventDefault(), C.submit().then((t) => {
46
+ t !== void 0 && e.onSuccess && e.onSuccess(t);
47
+ });
48
+ };
49
+ return /* @__PURE__ */ g(c, {
50
+ binding: C,
51
+ children: /* @__PURE__ */ g(v.Provider, {
52
+ value: T,
53
+ children: /* @__PURE__ */ _("form", {
54
+ ...e.action === !1 ? {} : {
55
+ action: l(e.mutation),
56
+ method: "post"
57
+ },
58
+ onSubmit: E,
59
+ noValidate: !0,
60
+ "data-voltro-autoform": e.mutation,
61
+ children: [
62
+ e.action === !1 ? null : /* @__PURE__ */ _(h, { children: [
63
+ /* @__PURE__ */ g("input", {
64
+ type: "hidden",
65
+ name: a,
66
+ value: t
67
+ }),
68
+ y === void 0 ? null : /* @__PURE__ */ g("input", {
69
+ type: "hidden",
70
+ name: i,
71
+ value: y
72
+ }),
73
+ /* @__PURE__ */ g("input", {
74
+ type: "hidden",
75
+ name: s,
76
+ value: S
77
+ })
78
+ ] }),
79
+ e.action === !1 || e.redirectTo === void 0 ? null : /* @__PURE__ */ g("input", {
80
+ type: "hidden",
81
+ name: o,
82
+ value: e.redirectTo
83
+ }),
84
+ e.children ? e.children(C) : u(C.fields).map((e, t) => e.name === void 0 ? e.fields.map((e) => /* @__PURE__ */ g(x, { name: e.name }, e.name)) : /* @__PURE__ */ _("fieldset", {
85
+ "data-voltro-section": e.name,
86
+ children: [/* @__PURE__ */ g("legend", { children: e.label ?? e.name }), e.fields.map((e) => /* @__PURE__ */ g(x, { name: e.name }, e.name))]
87
+ }, e.name)),
88
+ C.formError === void 0 ? null : /* @__PURE__ */ g("p", {
89
+ role: "alert",
90
+ "data-voltro-form-error": "",
91
+ children: C.formError
92
+ }),
93
+ /* @__PURE__ */ g("button", {
94
+ type: "submit",
95
+ disabled: C.pending,
96
+ children: e.submitLabel ?? "Submit"
97
+ })
98
+ ]
99
+ })
100
+ })
101
+ });
102
+ }
103
+ //#endregion
104
+ export { S as AutoForm, x as Field };
@@ -0,0 +1,163 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { useState as t } from "react";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ import { useComments as i } from "@voltro/plugin-comments/web";
5
+ //#region src/commentsThread.tsx
6
+ var a = (e) => [...e.matchAll(/@([\w.-]+)/g)].map((e) => e[1]);
7
+ function o({ comment: i, onReact: a, onRemove: o, onEdit: s }) {
8
+ let c = e().comments, [l, u] = t(!1), [d, f] = t(i.body);
9
+ return /* @__PURE__ */ r("li", {
10
+ "data-comment": i.id,
11
+ "data-author": i.authorSubjectId,
12
+ children: [
13
+ /* @__PURE__ */ n("span", {
14
+ "data-comment-author": !0,
15
+ children: i.authorSubjectId
16
+ }),
17
+ l ? /* @__PURE__ */ r("form", {
18
+ "data-comment-edit": !0,
19
+ onSubmit: (e) => {
20
+ e.preventDefault(), s(d), u(!1);
21
+ },
22
+ children: [/* @__PURE__ */ n("input", {
23
+ value: d,
24
+ onChange: (e) => f(e.target.value),
25
+ "aria-label": c.editLabel
26
+ }), /* @__PURE__ */ n("button", {
27
+ type: "submit",
28
+ children: c.save
29
+ })]
30
+ }) : /* @__PURE__ */ r("p", {
31
+ "data-comment-body": !0,
32
+ children: [i.body, i.editedAt ? /* @__PURE__ */ r("em", {
33
+ "data-comment-edited": !0,
34
+ children: [
35
+ " (",
36
+ c.edited,
37
+ ")"
38
+ ]
39
+ }) : null]
40
+ }),
41
+ /* @__PURE__ */ r("span", {
42
+ "data-comment-reactions": !0,
43
+ children: [i.reactions.map((e) => /* @__PURE__ */ r("button", {
44
+ type: "button",
45
+ "data-reaction": e.emoji,
46
+ "data-mine": e.mine || void 0,
47
+ onClick: () => a(e.emoji),
48
+ children: [
49
+ e.emoji,
50
+ " ",
51
+ e.count
52
+ ]
53
+ }, e.emoji)), /* @__PURE__ */ n("button", {
54
+ type: "button",
55
+ "data-reaction-add": !0,
56
+ onClick: () => a("👍"),
57
+ "aria-label": c.react,
58
+ children: "+👍"
59
+ })]
60
+ }),
61
+ /* @__PURE__ */ r("span", {
62
+ "data-comment-actions": !0,
63
+ children: [/* @__PURE__ */ n("button", {
64
+ type: "button",
65
+ onClick: () => u((e) => !e),
66
+ children: c.edit
67
+ }), /* @__PURE__ */ n("button", {
68
+ type: "button",
69
+ onClick: o,
70
+ children: c.remove
71
+ })]
72
+ })
73
+ ]
74
+ });
75
+ }
76
+ function s({ thread: i, api: s }) {
77
+ let c = e().comments, [l, u] = t("");
78
+ return /* @__PURE__ */ r("section", {
79
+ "data-thread": i.id,
80
+ "data-status": i.status,
81
+ children: [
82
+ /* @__PURE__ */ r("header", {
83
+ "data-thread-header": !0,
84
+ children: [
85
+ i.unreadCount > 0 ? /* @__PURE__ */ n("span", {
86
+ "data-thread-unread": !0,
87
+ children: i.unreadCount
88
+ }) : null,
89
+ /* @__PURE__ */ n("button", {
90
+ type: "button",
91
+ "data-thread-resolve": !0,
92
+ onClick: () => void s.resolve(i.id, i.status !== "resolved"),
93
+ children: i.status === "resolved" ? c.reopen : c.resolve
94
+ }),
95
+ /* @__PURE__ */ n("button", {
96
+ type: "button",
97
+ "data-thread-markread": !0,
98
+ onClick: () => void s.markRead(i.id),
99
+ children: c.markRead
100
+ })
101
+ ]
102
+ }),
103
+ i.quote === null ? null : /* @__PURE__ */ n("blockquote", {
104
+ "data-thread-quote": !0,
105
+ children: i.quote.exact
106
+ }),
107
+ /* @__PURE__ */ n("ul", {
108
+ "data-thread-comments": !0,
109
+ children: i.comments.map((e) => /* @__PURE__ */ n(o, {
110
+ comment: e,
111
+ onReact: (t) => void s.react(e.id, t),
112
+ onRemove: () => void s.remove(e.id),
113
+ onEdit: (t) => void s.edit(e.id, t)
114
+ }, e.id))
115
+ }),
116
+ /* @__PURE__ */ r("form", {
117
+ "data-thread-reply": !0,
118
+ onSubmit: (e) => {
119
+ e.preventDefault(), l.trim() !== "" && (s.create(l, {
120
+ threadId: i.id,
121
+ mentions: a(l)
122
+ }), u(""));
123
+ },
124
+ children: [/* @__PURE__ */ n("input", {
125
+ value: l,
126
+ onChange: (e) => u(e.target.value),
127
+ placeholder: c.replyPlaceholder,
128
+ "aria-label": c.replyLabel
129
+ }), /* @__PURE__ */ n("button", {
130
+ type: "submit",
131
+ children: c.reply
132
+ })]
133
+ })
134
+ ]
135
+ });
136
+ }
137
+ function c({ anchor: o, api: c = "app" }) {
138
+ let l = e().comments, u = i(o, c), [d, f] = t("");
139
+ return /* @__PURE__ */ r("div", {
140
+ "data-comments": !0,
141
+ "data-anchor": o,
142
+ children: [u.threads.map((e) => /* @__PURE__ */ n(s, {
143
+ thread: e,
144
+ api: u
145
+ }, e.id)), /* @__PURE__ */ r("form", {
146
+ "data-comments-new": !0,
147
+ onSubmit: (e) => {
148
+ e.preventDefault(), d.trim() !== "" && (u.create(d, { mentions: a(d) }), f(""));
149
+ },
150
+ children: [/* @__PURE__ */ n("input", {
151
+ value: d,
152
+ onChange: (e) => f(e.target.value),
153
+ placeholder: l.newPlaceholder,
154
+ "aria-label": l.newLabel
155
+ }), /* @__PURE__ */ n("button", {
156
+ type: "submit",
157
+ children: l.comment
158
+ })]
159
+ })]
160
+ });
161
+ }
162
+ //#endregion
163
+ export { c as CommentsThread };
@@ -0,0 +1,99 @@
1
+ import { useUiStrings as e } from "./strings.js";
2
+ import { useState as t } from "react";
3
+ import { useConnection as n } from "@voltro/client";
4
+ import { Fragment as r, jsx as i, jsxs as a } from "react/jsx-runtime";
5
+ //#region src/connectAccount.tsx
6
+ var o = (e, t) => {
7
+ switch (e.status) {
8
+ case "connected": return e.accountLabel === null ? t.connected : t.connectedAs(e.accountLabel);
9
+ case "expired": return t.expired;
10
+ case "revoked": return t.revoked;
11
+ case "error": return t.errored;
12
+ default: return t.notConnected;
13
+ }
14
+ }, s = ({ api: e, connectionId: t, ...r }) => {
15
+ let a = n(e, t);
16
+ return /* @__PURE__ */ i(c, {
17
+ connection: a,
18
+ loading: a.loading,
19
+ ...r
20
+ });
21
+ }, c = ({ connection: n, instructionsUrl: s, loading: c = !1, children: l, className: u }) => {
22
+ let d = e().connectAccount, [f, p] = t("");
23
+ if (l !== void 0) return l(n);
24
+ if (c) return /* @__PURE__ */ i("div", {
25
+ className: u,
26
+ "data-voltro-connect": n.connectionId,
27
+ children: d.loading
28
+ });
29
+ let m = async (e) => {
30
+ e.preventDefault(), f.trim() !== "" && (await n.submitToken(f), p(""));
31
+ };
32
+ return /* @__PURE__ */ a("div", {
33
+ className: u,
34
+ "data-voltro-connect": n.connectionId,
35
+ "data-status": n.status,
36
+ children: [/* @__PURE__ */ a("div", { children: [
37
+ /* @__PURE__ */ i("strong", { children: n.label }),
38
+ " — ",
39
+ /* @__PURE__ */ i("span", {
40
+ role: n.needsAttention ? "alert" : void 0,
41
+ children: o(n, d)
42
+ })
43
+ ] }), n.connected || n.needsAttention ? /* @__PURE__ */ a(r, { children: [n.needsAttention && n.kind === "oauth2" && /* @__PURE__ */ i("button", {
44
+ type: "button",
45
+ disabled: n.pending,
46
+ onClick: () => {
47
+ n.connect();
48
+ },
49
+ children: d.reconnect
50
+ }), /* @__PURE__ */ i("button", {
51
+ type: "button",
52
+ disabled: n.pending,
53
+ onClick: () => {
54
+ n.disconnect();
55
+ },
56
+ children: d.disconnect
57
+ })] }) : n.kind === "oauth2" ? /* @__PURE__ */ i("button", {
58
+ type: "button",
59
+ disabled: n.pending,
60
+ onClick: () => {
61
+ n.connect();
62
+ },
63
+ children: d.connect(n.label)
64
+ }) : /* @__PURE__ */ a("form", {
65
+ onSubmit: (e) => {
66
+ m(e);
67
+ },
68
+ children: [
69
+ /* @__PURE__ */ i("label", {
70
+ htmlFor: `voltro-connect-${n.connectionId}`,
71
+ children: d.tokenLabel(n.label)
72
+ }),
73
+ /* @__PURE__ */ i("input", {
74
+ id: `voltro-connect-${n.connectionId}`,
75
+ type: "password",
76
+ autoComplete: "off",
77
+ value: f,
78
+ placeholder: d.tokenPlaceholder,
79
+ onChange: (e) => {
80
+ p(e.target.value);
81
+ }
82
+ }),
83
+ /* @__PURE__ */ i("button", {
84
+ type: "submit",
85
+ disabled: n.pending || f.trim() === "",
86
+ children: d.save
87
+ }),
88
+ s !== void 0 && /* @__PURE__ */ i("a", {
89
+ href: s,
90
+ target: "_blank",
91
+ rel: "noreferrer noopener",
92
+ children: d.howToGetToken
93
+ })
94
+ ]
95
+ })]
96
+ });
97
+ };
98
+ //#endregion
99
+ export { c as ConnectAccount, s as ConnectAccountFor };
@@ -0,0 +1,77 @@
1
+ import { useState as e } from "react";
2
+ import { useDataCopilot as t } from "@voltro/client";
3
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
4
+ //#region src/dataCopilot.tsx
5
+ var i = (e) => e == null ? "" : typeof e == "boolean" ? e ? "✓" : "✗" : typeof e == "object" ? JSON.stringify(e) : String(e), a = (e) => {
6
+ let t = /* @__PURE__ */ new Set(), n = [];
7
+ for (let r of e) for (let e of Object.keys(r)) t.has(e) || (t.add(e), n.push(e));
8
+ return n;
9
+ };
10
+ function o(e) {
11
+ let { answer: t, emptyText: o } = e;
12
+ if (t === void 0) return null;
13
+ if (!t.ok) return /* @__PURE__ */ n("p", {
14
+ "data-voltro-data-copilot-refused": !0,
15
+ role: "status",
16
+ children: t.reason
17
+ });
18
+ if (t.rows.length === 0) return /* @__PURE__ */ n("p", {
19
+ "data-voltro-data-copilot-empty": !0,
20
+ children: o ?? "No rows."
21
+ });
22
+ let s = a(t.rows);
23
+ return /* @__PURE__ */ r("table", {
24
+ "data-voltro-data-copilot-results": !0,
25
+ children: [/* @__PURE__ */ n("thead", { children: /* @__PURE__ */ n("tr", { children: s.map((e) => /* @__PURE__ */ n("th", {
26
+ scope: "col",
27
+ children: e
28
+ }, e)) }) }), /* @__PURE__ */ n("tbody", { children: t.rows.map((e, t) => /* @__PURE__ */ n("tr", { children: s.map((t) => /* @__PURE__ */ n("td", {
29
+ "data-column": t,
30
+ children: i(e[t])
31
+ }, t)) }, String(e.id ?? t))) })]
32
+ });
33
+ }
34
+ function s(i) {
35
+ let { api: a, action: s, placeholder: c, askLabel: l, emptyText: u } = i, d = t(a, s), [f, p] = e(""), m = () => {
36
+ let e = f.trim();
37
+ e.length === 0 || d.pending || d.ask(e);
38
+ };
39
+ return /* @__PURE__ */ r("div", {
40
+ "data-voltro-data-copilot": s,
41
+ children: [/* @__PURE__ */ r("form", {
42
+ "data-composer": !0,
43
+ onSubmit: (e) => {
44
+ e.preventDefault(), m();
45
+ },
46
+ children: [/* @__PURE__ */ n("input", {
47
+ value: f,
48
+ onChange: (e) => p(e.target.value),
49
+ placeholder: c ?? "Ask about your data…",
50
+ "aria-label": "Ask about your data",
51
+ disabled: d.pending
52
+ }), /* @__PURE__ */ n("button", {
53
+ type: "submit",
54
+ disabled: d.pending || f.trim().length === 0,
55
+ children: l ?? "Ask"
56
+ })]
57
+ }), /* @__PURE__ */ n("div", {
58
+ "data-answer": !0,
59
+ "aria-live": "polite",
60
+ "aria-busy": d.pending ? "true" : void 0,
61
+ children: d.error === void 0 ? /* @__PURE__ */ n(o, {
62
+ answer: d.answer,
63
+ ...u === void 0 ? {} : { emptyText: u }
64
+ }) : /* @__PURE__ */ n("p", {
65
+ "data-voltro-data-copilot-error": !0,
66
+ role: "alert",
67
+ children: d.error instanceof Error ? d.error.message : String(d.error)
68
+ })
69
+ })]
70
+ });
71
+ }
72
+ function c(e) {
73
+ let n = t(e.api, e.action);
74
+ return e.children(n);
75
+ }
76
+ //#endregion
77
+ export { s as DataCopilot, o as DataCopilotAnswer, c as DataCopilotStream };