@dolfinhos/studio 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/index.cjs +1262 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +321 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.js +1225 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +592 -0
- package/package.json +65 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1225 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/index.tsx
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
|
|
6
|
+
// src/api.ts
|
|
7
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
8
|
+
var StudioError = class extends Error {
|
|
9
|
+
constructor(message, status) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.name = "StudioError";
|
|
13
|
+
}
|
|
14
|
+
status;
|
|
15
|
+
};
|
|
16
|
+
function createStudioClient(options = {}) {
|
|
17
|
+
const endpoint = (options.endpoint ?? "/dolfinhos").replace(/\/$/, "");
|
|
18
|
+
const doFetch = options.fetch ?? ((...args) => fetch(...args));
|
|
19
|
+
async function request(method, path, body) {
|
|
20
|
+
let res;
|
|
21
|
+
try {
|
|
22
|
+
res = await doFetch(endpoint + path, {
|
|
23
|
+
method,
|
|
24
|
+
headers: { ...body !== void 0 ? { "content-type": "application/json" } : {}, ...await options.headers?.() },
|
|
25
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
26
|
+
});
|
|
27
|
+
} catch {
|
|
28
|
+
throw new StudioError("N\xE3o foi poss\xEDvel falar com o servidor. Confira a conex\xE3o e tente de novo.", 0);
|
|
29
|
+
}
|
|
30
|
+
const data = await res.json().catch(() => null);
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
const message = data?.error?.message ?? data?.message;
|
|
33
|
+
throw new StudioError(
|
|
34
|
+
typeof message === "string" ? message : res.status === 403 ? "Voc\xEA n\xE3o tem permiss\xE3o para isso." : `O servidor respondeu com erro ${res.status}.`,
|
|
35
|
+
res.status
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
const q = (params) => {
|
|
41
|
+
const s = new URLSearchParams(Object.entries(params).filter((e) => !!e[1])).toString();
|
|
42
|
+
return s ? `?${s}` : "";
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
settings: () => request("GET", "/settings"),
|
|
46
|
+
saveSettings: (settings) => {
|
|
47
|
+
const { updatedAt: _a, updatedBy: _b, ...rest } = settings;
|
|
48
|
+
return request("PUT", "/settings", rest);
|
|
49
|
+
},
|
|
50
|
+
capabilities: () => request("GET", "/capabilities"),
|
|
51
|
+
events: () => request("GET", "/events"),
|
|
52
|
+
approvals: () => request("GET", "/approvals"),
|
|
53
|
+
decide: (item, approved, reason) => request("POST", `/approvals/${encodeURIComponent(item.sessionId)}`, {
|
|
54
|
+
executionId: item.pendingApproval.executionId,
|
|
55
|
+
approved,
|
|
56
|
+
...reason ? { reason } : {}
|
|
57
|
+
}),
|
|
58
|
+
audit: (params = {}) => request("GET", `/audit${q({ before: params.before, limit: params.limit?.toString(), sessionId: params.sessionId })}`),
|
|
59
|
+
usage: (params = {}) => request("GET", `/usage${q(params)}`),
|
|
60
|
+
knowledge: () => request("GET", "/knowledge"),
|
|
61
|
+
saveKnowledge: (doc) => request("POST", "/knowledge", doc),
|
|
62
|
+
removeKnowledge: (id) => request("DELETE", `/knowledge/${encodeURIComponent(id)}`),
|
|
63
|
+
searchKnowledge: (query, audience) => request("GET", `/knowledge/search${q({ q: query, audience })}`),
|
|
64
|
+
factSubjects: (type) => request("GET", `/facts${q({ type })}`),
|
|
65
|
+
facts: (subject) => request("GET", `/facts${q({ type: subject.type, id: subject.id })}`),
|
|
66
|
+
forget: (id) => request("DELETE", `/facts/${encodeURIComponent(id)}`),
|
|
67
|
+
credentials: () => request("GET", "/credentials"),
|
|
68
|
+
saveCredential: (name, value) => request("PUT", `/credentials/${encodeURIComponent(name)}`, { value }),
|
|
69
|
+
removeCredential: (name) => request("DELETE", `/credentials/${encodeURIComponent(name)}`)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
var StudioContext = createContext(null);
|
|
73
|
+
var StudioContextProvider = StudioContext.Provider;
|
|
74
|
+
function useStudio() {
|
|
75
|
+
const value = useContext(StudioContext);
|
|
76
|
+
if (!value) throw new Error("Use os componentes do Dolfinhos Studio dentro de <StudioProvider>.");
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function useResource(load, deps) {
|
|
80
|
+
const [state, setState] = useState({ data: null, error: null, loading: true });
|
|
81
|
+
const seq = useRef(0);
|
|
82
|
+
const run = useCallback(load, deps);
|
|
83
|
+
const reload = useCallback(async () => {
|
|
84
|
+
const id = ++seq.current;
|
|
85
|
+
setState((s) => ({ ...s, loading: true, error: null }));
|
|
86
|
+
try {
|
|
87
|
+
const data = await run();
|
|
88
|
+
if (id === seq.current) setState({ data, error: null, loading: false });
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if (id === seq.current) setState((s) => ({ ...s, error: e instanceof Error ? e.message : String(e), loading: false }));
|
|
91
|
+
}
|
|
92
|
+
}, [run]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
void reload();
|
|
95
|
+
}, [reload]);
|
|
96
|
+
return { ...state, reload, setData: (data) => setState((s) => ({ ...s, data })) };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/Approvals.tsx
|
|
100
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
101
|
+
|
|
102
|
+
// src/ui.tsx
|
|
103
|
+
import { useEffect as useEffect2, useId, useRef as useRef2 } from "react";
|
|
104
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
105
|
+
var cx = (...c) => c.filter(Boolean).join(" ");
|
|
106
|
+
function Button({ variant = "secondary", loading, className, children, disabled, ...props }) {
|
|
107
|
+
return /* @__PURE__ */ jsxs("button", { type: "button", ...props, disabled: disabled || loading, "aria-busy": loading || void 0, className: cx("dlf-button", `dlf-button--${variant}`, className), children: [
|
|
108
|
+
loading && /* @__PURE__ */ jsx("span", { className: "dlf-spinner", "aria-hidden": true }),
|
|
109
|
+
children
|
|
110
|
+
] });
|
|
111
|
+
}
|
|
112
|
+
function Field({ label, hint, error, children, htmlFor }) {
|
|
113
|
+
return /* @__PURE__ */ jsxs("div", { className: "dlf-field", children: [
|
|
114
|
+
/* @__PURE__ */ jsx("label", { className: "dlf-label", htmlFor, children: label }),
|
|
115
|
+
children,
|
|
116
|
+
hint && /* @__PURE__ */ jsx("p", { className: "dlf-hint", children: hint }),
|
|
117
|
+
error && /* @__PURE__ */ jsx("p", { className: "dlf-error-text", role: "alert", children: error })
|
|
118
|
+
] });
|
|
119
|
+
}
|
|
120
|
+
function Notice({ tone = "info", children }) {
|
|
121
|
+
return /* @__PURE__ */ jsx("div", { className: cx("dlf-notice", `dlf-notice--${tone}`), role: tone === "error" ? "alert" : "status", children });
|
|
122
|
+
}
|
|
123
|
+
function Empty({ title, children }) {
|
|
124
|
+
return /* @__PURE__ */ jsxs("div", { className: "dlf-empty", children: [
|
|
125
|
+
/* @__PURE__ */ jsx("p", { className: "dlf-empty-title", children: title }),
|
|
126
|
+
children && /* @__PURE__ */ jsx("p", { className: "dlf-muted", children })
|
|
127
|
+
] });
|
|
128
|
+
}
|
|
129
|
+
function Section({ title, description, actions, children, id }) {
|
|
130
|
+
const generated = useId();
|
|
131
|
+
const headingId = `${id ?? generated}-titulo`;
|
|
132
|
+
return /* @__PURE__ */ jsxs("section", { className: "dlf-section", "aria-labelledby": headingId, children: [
|
|
133
|
+
/* @__PURE__ */ jsxs("div", { className: "dlf-section-head", children: [
|
|
134
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
135
|
+
/* @__PURE__ */ jsx("h2", { id: headingId, className: "dlf-h2", children: title }),
|
|
136
|
+
description && /* @__PURE__ */ jsx("p", { className: "dlf-muted dlf-measure", children: description })
|
|
137
|
+
] }),
|
|
138
|
+
actions && /* @__PURE__ */ jsx("div", { className: "dlf-actions", children: actions })
|
|
139
|
+
] }),
|
|
140
|
+
children
|
|
141
|
+
] });
|
|
142
|
+
}
|
|
143
|
+
function Badge({ tone = "neutral", children }) {
|
|
144
|
+
return /* @__PURE__ */ jsx("span", { className: cx("dlf-badge", `dlf-badge--${tone}`), children });
|
|
145
|
+
}
|
|
146
|
+
function Loading({ label = "Carregando\u2026" }) {
|
|
147
|
+
return /* @__PURE__ */ jsxs("p", { className: "dlf-muted dlf-loading", role: "status", children: [
|
|
148
|
+
/* @__PURE__ */ jsx("span", { className: "dlf-spinner", "aria-hidden": true }),
|
|
149
|
+
" ",
|
|
150
|
+
label
|
|
151
|
+
] });
|
|
152
|
+
}
|
|
153
|
+
function Tabs({ tabs, value, onChange, label }) {
|
|
154
|
+
const refs = useRef2([]);
|
|
155
|
+
useEffect2(() => {
|
|
156
|
+
refs.current[tabs.findIndex((t) => t.id === value)]?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
157
|
+
}, [value, tabs]);
|
|
158
|
+
const onKeyDown = (e, index) => {
|
|
159
|
+
const last = tabs.length - 1;
|
|
160
|
+
const next = e.key === "ArrowRight" ? index === last ? 0 : index + 1 : e.key === "ArrowLeft" ? index === 0 ? last : index - 1 : e.key === "Home" ? 0 : e.key === "End" ? last : -1;
|
|
161
|
+
if (next < 0) return;
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
refs.current[next]?.focus();
|
|
164
|
+
onChange(tabs[next].id);
|
|
165
|
+
};
|
|
166
|
+
return /* @__PURE__ */ jsx("div", { className: "dlf-tabs", role: "tablist", "aria-label": label, children: tabs.map((tab, i) => /* @__PURE__ */ jsxs(
|
|
167
|
+
"button",
|
|
168
|
+
{
|
|
169
|
+
ref: (el) => {
|
|
170
|
+
refs.current[i] = el;
|
|
171
|
+
},
|
|
172
|
+
type: "button",
|
|
173
|
+
role: "tab",
|
|
174
|
+
id: `dlf-tab-${tab.id}`,
|
|
175
|
+
"aria-selected": tab.id === value,
|
|
176
|
+
"aria-controls": `dlf-panel-${tab.id}`,
|
|
177
|
+
tabIndex: tab.id === value ? 0 : -1,
|
|
178
|
+
className: "dlf-tab",
|
|
179
|
+
onClick: () => onChange(tab.id),
|
|
180
|
+
onKeyDown: (e) => onKeyDown(e, i),
|
|
181
|
+
children: [
|
|
182
|
+
tab.label,
|
|
183
|
+
!!tab.count && /* @__PURE__ */ jsxs("span", { className: "dlf-tab-count", children: [
|
|
184
|
+
tab.count,
|
|
185
|
+
/* @__PURE__ */ jsx("span", { className: "dlf-sr-only", children: " pendentes" })
|
|
186
|
+
] })
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
tab.id
|
|
190
|
+
)) });
|
|
191
|
+
}
|
|
192
|
+
var formatDateTime = (iso, locale) => new Intl.DateTimeFormat(locale, { day: "2-digit", month: "2-digit", hour: "2-digit", minute: "2-digit" }).format(new Date(iso));
|
|
193
|
+
var formatNumber = (n, locale) => new Intl.NumberFormat(locale).format(n);
|
|
194
|
+
var formatMoney = (n, currency, locale) => currency ? new Intl.NumberFormat(locale, { style: "currency", currency, minimumFractionDigits: 2, maximumFractionDigits: n > 0 && n < 1 ? 4 : 2 }).format(n) : new Intl.NumberFormat(locale, { maximumFractionDigits: 4 }).format(n);
|
|
195
|
+
var showValue = (v) => typeof v === "string" ? v : v === null || v === void 0 ? "\u2014" : JSON.stringify(v);
|
|
196
|
+
|
|
197
|
+
// src/Approvals.tsx
|
|
198
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
199
|
+
function ApprovalsInbox({ refreshMs = 3e4, onDecided, onCount }) {
|
|
200
|
+
const { client, labels, locale, navigate } = useStudio();
|
|
201
|
+
const list = useResource(() => client.approvals(), [client]);
|
|
202
|
+
const [busy, setBusy] = useState2(null);
|
|
203
|
+
const [message, setMessage] = useState2(null);
|
|
204
|
+
useEffect3(() => {
|
|
205
|
+
if (!refreshMs) return;
|
|
206
|
+
const timer = setInterval(() => void list.reload(), refreshMs);
|
|
207
|
+
return () => clearInterval(timer);
|
|
208
|
+
}, [refreshMs, list.reload]);
|
|
209
|
+
useEffect3(() => {
|
|
210
|
+
if (list.data) onCount?.(list.data.length);
|
|
211
|
+
}, [list.data, onCount]);
|
|
212
|
+
const origin = (item) => {
|
|
213
|
+
const meta = item.meta ?? {};
|
|
214
|
+
const channel = labels.channels?.[item.channel ?? ""] ?? (item.channel === "bot" ? "Bot" : "Automa\xE7\xE3o");
|
|
215
|
+
const who = typeof meta.contato === "string" ? `, conversando com ${meta.contato}` : "";
|
|
216
|
+
const what = typeof meta.automation === "string" ? ` \u201C${meta.automation}\u201D` : "";
|
|
217
|
+
return `${channel}${what}${who}`;
|
|
218
|
+
};
|
|
219
|
+
async function decide(item, approved) {
|
|
220
|
+
const key = `${item.sessionId}:${item.pendingApproval.executionId}`;
|
|
221
|
+
setBusy({ key, approved });
|
|
222
|
+
setMessage(null);
|
|
223
|
+
try {
|
|
224
|
+
const result = await client.decide(item, approved);
|
|
225
|
+
const reply = result.text?.trim() ?? "";
|
|
226
|
+
setMessage({ tone: "success", text: `${approved ? "Aprovado e feito." : "Recusado."}${reply && item.channel === "bot" ? ` Resposta enviada ao cliente: \u201C${reply}\u201D` : ""}` });
|
|
227
|
+
onDecided?.({ item, approved, reply });
|
|
228
|
+
} catch (e) {
|
|
229
|
+
const status = e.status;
|
|
230
|
+
setMessage({ tone: "error", text: status === 404 ? "Algu\xE9m da equipe j\xE1 decidiu este pedido." : e instanceof Error ? e.message : String(e) });
|
|
231
|
+
} finally {
|
|
232
|
+
setBusy(null);
|
|
233
|
+
await list.reload();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return /* @__PURE__ */ jsxs2(Section, { title: "Aprova\xE7\xF5es", description: "O que o bot e as automa\xE7\xF5es de IA pediram para fazer. Nada acontece at\xE9 algu\xE9m da equipe aprovar.", children: [
|
|
237
|
+
message && /* @__PURE__ */ jsx2(Notice, { tone: message.tone, children: message.text }),
|
|
238
|
+
list.error && /* @__PURE__ */ jsx2(Notice, { tone: "error", children: list.error }),
|
|
239
|
+
list.loading && !list.data && /* @__PURE__ */ jsx2(Loading, {}),
|
|
240
|
+
list.data && !list.data.length && /* @__PURE__ */ jsx2(Empty, { title: "Nenhum pedido esperando", children: "Quando o bot ou uma automa\xE7\xE3o quiser fazer algo que pede aprova\xE7\xE3o, o pedido aparece aqui." }),
|
|
241
|
+
!!list.data?.length && /* @__PURE__ */ jsx2("ul", { className: "dlf-list", "aria-label": "Pedidos esperando aprova\xE7\xE3o", children: list.data.map((item) => {
|
|
242
|
+
const p = item.pendingApproval;
|
|
243
|
+
const key = `${item.sessionId}:${p.executionId}`;
|
|
244
|
+
const args = p.args && typeof p.args === "object" ? Object.entries(p.args) : [];
|
|
245
|
+
const link = labels.approvalLink?.(item);
|
|
246
|
+
const mine = busy?.key === key;
|
|
247
|
+
return /* @__PURE__ */ jsxs2("li", { className: "dlf-item", children: [
|
|
248
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
249
|
+
/* @__PURE__ */ jsx2("p", { className: "dlf-item-title", children: p.summary ?? p.title ?? p.toolName }),
|
|
250
|
+
/* @__PURE__ */ jsxs2("p", { className: "dlf-item-meta", children: [
|
|
251
|
+
p.summary && p.title ? `${p.title} \xB7 ` : "",
|
|
252
|
+
origin(item),
|
|
253
|
+
" \xB7 ",
|
|
254
|
+
/* @__PURE__ */ jsx2("time", { dateTime: item.updatedAt, children: formatDateTime(item.updatedAt, locale) })
|
|
255
|
+
] })
|
|
256
|
+
] }),
|
|
257
|
+
args.length > 0 && /* @__PURE__ */ jsxs2("details", { className: "dlf-details", children: [
|
|
258
|
+
/* @__PURE__ */ jsx2("summary", { children: "Ver os dados do pedido" }),
|
|
259
|
+
/* @__PURE__ */ jsx2("dl", { className: "dlf-dl", children: args.map(([k, v]) => /* @__PURE__ */ jsxs2("div", { style: { display: "contents" }, children: [
|
|
260
|
+
/* @__PURE__ */ jsx2("dt", { children: k }),
|
|
261
|
+
/* @__PURE__ */ jsx2("dd", { children: showValue(v) })
|
|
262
|
+
] }, k)) })
|
|
263
|
+
] }),
|
|
264
|
+
/* @__PURE__ */ jsxs2("div", { className: "dlf-item-row", children: [
|
|
265
|
+
/* @__PURE__ */ jsxs2("div", { className: "dlf-actions", children: [
|
|
266
|
+
/* @__PURE__ */ jsx2(Button, { variant: "primary", loading: mine && busy.approved, disabled: !!busy, onClick: () => decide(item, true), children: "Aprovar" }),
|
|
267
|
+
/* @__PURE__ */ jsx2(Button, { loading: mine && !busy.approved, disabled: !!busy, onClick: () => decide(item, false), children: "Recusar" })
|
|
268
|
+
] }),
|
|
269
|
+
link && /* @__PURE__ */ jsx2(
|
|
270
|
+
"a",
|
|
271
|
+
{
|
|
272
|
+
className: "dlf-link",
|
|
273
|
+
href: link.href,
|
|
274
|
+
onClick: (e) => {
|
|
275
|
+
if (!navigate || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
navigate(link.href);
|
|
278
|
+
},
|
|
279
|
+
children: link.label
|
|
280
|
+
}
|
|
281
|
+
)
|
|
282
|
+
] })
|
|
283
|
+
] }, key);
|
|
284
|
+
}) })
|
|
285
|
+
] });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/Audit.tsx
|
|
289
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
290
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
291
|
+
var DECISIONS = {
|
|
292
|
+
auto: { label: "Sozinho", tone: "neutral" },
|
|
293
|
+
approved: { label: "Aprovado", tone: "success" },
|
|
294
|
+
rejected: { label: "Recusado", tone: "warning" },
|
|
295
|
+
denied: { label: "Bloqueado", tone: "danger" },
|
|
296
|
+
failed: { label: "Falhou", tone: "danger" }
|
|
297
|
+
};
|
|
298
|
+
var PAGE = 50;
|
|
299
|
+
var humanize = (name) => {
|
|
300
|
+
const text = name.replace(/_/g, " ").trim();
|
|
301
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
302
|
+
};
|
|
303
|
+
function AuditLog() {
|
|
304
|
+
const { client, labels, locale } = useStudio();
|
|
305
|
+
const [records, setRecords] = useState3(null);
|
|
306
|
+
const [error, setError] = useState3(null);
|
|
307
|
+
const [loading, setLoading] = useState3(false);
|
|
308
|
+
const [done, setDone] = useState3(false);
|
|
309
|
+
const capabilities = useResource(() => client.capabilities().catch(() => []), [client]);
|
|
310
|
+
const titles = new Map((capabilities.data ?? []).map((c) => [c.name, c.title]));
|
|
311
|
+
async function load(before) {
|
|
312
|
+
setLoading(true);
|
|
313
|
+
setError(null);
|
|
314
|
+
try {
|
|
315
|
+
const page = await client.audit({ limit: PAGE, ...before ? { before } : {} });
|
|
316
|
+
setRecords((current) => before ? [...current ?? [], ...page] : page);
|
|
317
|
+
setDone(page.length < PAGE);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
320
|
+
} finally {
|
|
321
|
+
setLoading(false);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
useEffect4(() => {
|
|
325
|
+
void load();
|
|
326
|
+
}, [client]);
|
|
327
|
+
const who = (r) => {
|
|
328
|
+
const name = r.actor?.name ?? (r.actor?.type === "service" ? "Assistente" : r.actor?.id ?? "\u2014");
|
|
329
|
+
const channel = r.channel ? labels.channels?.[r.channel] ?? r.channel : null;
|
|
330
|
+
return channel && r.channel !== "app" ? `${name} \xB7 ${channel}` : name;
|
|
331
|
+
};
|
|
332
|
+
return /* @__PURE__ */ jsxs3(Section, { title: "Auditoria", description: "Cada a\xE7\xE3o que muda dados ou fala com algu\xE9m: o que foi pedido, por quem, e quem aprovou.", children: [
|
|
333
|
+
error && /* @__PURE__ */ jsx3(Notice, { tone: "error", children: error }),
|
|
334
|
+
!records && loading && /* @__PURE__ */ jsx3(Loading, {}),
|
|
335
|
+
records && !records.length && /* @__PURE__ */ jsx3(Empty, { title: "Nada registrado ainda" }),
|
|
336
|
+
!!records?.length && /* @__PURE__ */ jsx3("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ jsxs3("table", { className: "dlf-table", children: [
|
|
337
|
+
/* @__PURE__ */ jsx3("thead", { children: /* @__PURE__ */ jsxs3("tr", { children: [
|
|
338
|
+
/* @__PURE__ */ jsx3("th", { scope: "col", children: "Quando" }),
|
|
339
|
+
/* @__PURE__ */ jsx3("th", { scope: "col", children: "Quem" }),
|
|
340
|
+
/* @__PURE__ */ jsx3("th", { scope: "col", children: "O qu\xEA" }),
|
|
341
|
+
/* @__PURE__ */ jsx3("th", { scope: "col", children: "Decis\xE3o" })
|
|
342
|
+
] }) }),
|
|
343
|
+
/* @__PURE__ */ jsx3("tbody", { children: records.map((r) => /* @__PURE__ */ jsxs3("tr", { children: [
|
|
344
|
+
/* @__PURE__ */ jsx3("td", { style: { whiteSpace: "nowrap" }, children: /* @__PURE__ */ jsx3("time", { dateTime: r.at, children: formatDateTime(r.at, locale) }) }),
|
|
345
|
+
/* @__PURE__ */ jsx3("td", { children: who(r) }),
|
|
346
|
+
/* @__PURE__ */ jsx3("td", { style: { minWidth: "14rem" }, children: /* @__PURE__ */ jsxs3("details", { className: "dlf-details", children: [
|
|
347
|
+
/* @__PURE__ */ jsx3("summary", { style: { color: "inherit", fontSize: "inherit" }, children: titles.get(r.capability) ?? humanize(r.capability) }),
|
|
348
|
+
/* @__PURE__ */ jsxs3("dl", { className: "dlf-dl", children: [
|
|
349
|
+
r.input && typeof r.input === "object" ? Object.entries(r.input).map(([k, v]) => /* @__PURE__ */ jsxs3("div", { style: { display: "contents" }, children: [
|
|
350
|
+
/* @__PURE__ */ jsx3("dt", { children: k }),
|
|
351
|
+
/* @__PURE__ */ jsx3("dd", { children: showValue(v) })
|
|
352
|
+
] }, k)) : null,
|
|
353
|
+
/* @__PURE__ */ jsx3("dt", { children: "A\xE7\xE3o" }),
|
|
354
|
+
/* @__PURE__ */ jsx3("dd", { children: r.capability }),
|
|
355
|
+
r.rule && /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
356
|
+
/* @__PURE__ */ jsx3("dt", { children: "Regra" }),
|
|
357
|
+
/* @__PURE__ */ jsx3("dd", { children: r.rule })
|
|
358
|
+
] }),
|
|
359
|
+
r.error && /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
360
|
+
/* @__PURE__ */ jsx3("dt", { children: "Erro" }),
|
|
361
|
+
/* @__PURE__ */ jsx3("dd", { children: r.error })
|
|
362
|
+
] })
|
|
363
|
+
] })
|
|
364
|
+
] }) }),
|
|
365
|
+
/* @__PURE__ */ jsxs3("td", { children: [
|
|
366
|
+
/* @__PURE__ */ jsx3(Badge, { tone: DECISIONS[r.decision].tone, children: DECISIONS[r.decision].label }),
|
|
367
|
+
r.decidedBy && /* @__PURE__ */ jsxs3("p", { className: "dlf-item-meta", children: [
|
|
368
|
+
"por ",
|
|
369
|
+
r.decidedBy.name ?? r.decidedBy.id
|
|
370
|
+
] })
|
|
371
|
+
] })
|
|
372
|
+
] }, r.id)) })
|
|
373
|
+
] }) }),
|
|
374
|
+
!!records?.length && !done && /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3(Button, { loading, onClick: () => load(records.at(-1).at), children: "Carregar mais" }) })
|
|
375
|
+
] });
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/Automations.tsx
|
|
379
|
+
import { useId as useId2, useState as useState4 } from "react";
|
|
380
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
381
|
+
var idFrom = (text) => text.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50) || "automacao";
|
|
382
|
+
function AutomationsEditor() {
|
|
383
|
+
const { client } = useStudio();
|
|
384
|
+
const ids = useId2();
|
|
385
|
+
const settings = useResource(() => client.settings(), [client]);
|
|
386
|
+
const events = useResource(() => client.events(), [client]);
|
|
387
|
+
const [draft, setDraft] = useState4(null);
|
|
388
|
+
const [saving, setSaving] = useState4(null);
|
|
389
|
+
const [message, setMessage] = useState4(null);
|
|
390
|
+
const eventName = (name) => events.data?.find((e) => e.name === name)?.description ?? name;
|
|
391
|
+
async function write(change, key, done) {
|
|
392
|
+
setSaving(key);
|
|
393
|
+
setMessage(null);
|
|
394
|
+
try {
|
|
395
|
+
const fresh = await client.settings();
|
|
396
|
+
const saved = await client.saveSettings({ ...fresh, automations: change(fresh.automations ?? []) });
|
|
397
|
+
settings.setData(saved);
|
|
398
|
+
setMessage({ tone: "success", text: done });
|
|
399
|
+
return true;
|
|
400
|
+
} catch (e) {
|
|
401
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
402
|
+
return false;
|
|
403
|
+
} finally {
|
|
404
|
+
setSaving(null);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async function submit() {
|
|
408
|
+
if (!draft) return;
|
|
409
|
+
const taken = new Set((settings.data?.automations ?? []).map((a) => a.id).filter((id2) => id2 !== draft.originalId));
|
|
410
|
+
let id = draft.originalId ?? idFrom(draft.description || draft.instruction);
|
|
411
|
+
for (let n = 2; taken.has(id); n++) id = `${idFrom(draft.description || draft.instruction).slice(0, 46)}-${n}`;
|
|
412
|
+
const automation = {
|
|
413
|
+
id,
|
|
414
|
+
event: draft.event,
|
|
415
|
+
instruction: draft.instruction.trim(),
|
|
416
|
+
enabled: draft.enabled,
|
|
417
|
+
...draft.description.trim() ? { description: draft.description.trim() } : {}
|
|
418
|
+
};
|
|
419
|
+
const ok = await write(
|
|
420
|
+
(list2) => draft.originalId ? list2.map((a) => a.id === draft.originalId ? automation : a) : [...list2, automation],
|
|
421
|
+
"form",
|
|
422
|
+
draft.originalId ? "Automa\xE7\xE3o atualizada." : "Automa\xE7\xE3o criada. Ela roda na pr\xF3xima vez que o evento acontecer."
|
|
423
|
+
);
|
|
424
|
+
if (ok) setDraft(null);
|
|
425
|
+
}
|
|
426
|
+
const list = settings.data?.automations ?? [];
|
|
427
|
+
const firstEvent = events.data?.[0];
|
|
428
|
+
return /* @__PURE__ */ jsxs4(
|
|
429
|
+
Section,
|
|
430
|
+
{
|
|
431
|
+
title: "Automa\xE7\xF5es",
|
|
432
|
+
description: "Quando algo acontecer, o assistente faz o que voc\xEA escrever. Ele age com as mesmas regras: o que pede aprova\xE7\xE3o espera na caixa de aprova\xE7\xF5es.",
|
|
433
|
+
actions: !draft && !!firstEvent && /* @__PURE__ */ jsx4(Button, { onClick: () => setDraft({ originalId: null, description: "", event: firstEvent.name, instruction: "", enabled: true }), disabled: !!saving, children: "Nova automa\xE7\xE3o" }),
|
|
434
|
+
children: [
|
|
435
|
+
message && /* @__PURE__ */ jsx4(Notice, { tone: message.tone, children: message.text }),
|
|
436
|
+
(settings.error || events.error) && /* @__PURE__ */ jsx4(Notice, { tone: "error", children: settings.error ?? events.error }),
|
|
437
|
+
(settings.loading || events.loading) && !settings.data && /* @__PURE__ */ jsx4(Loading, {}),
|
|
438
|
+
events.data && !events.data.length && /* @__PURE__ */ jsx4(Empty, { title: "A aplica\xE7\xE3o n\xE3o declarou eventos", children: "Sem eventos, n\xE3o h\xE1 quando disparar automa\xE7\xF5es." }),
|
|
439
|
+
settings.data && !!events.data?.length && !list.length && !draft && /* @__PURE__ */ jsx4(Empty, { title: "Nenhuma automa\xE7\xE3o", children: "Ex.: quando um neg\xF3cio entrar em Proposta, anotar o prazo de envio." }),
|
|
440
|
+
!!list.length && /* @__PURE__ */ jsx4("ul", { className: "dlf-list", children: list.map((a) => /* @__PURE__ */ jsxs4("li", { className: "dlf-item", children: [
|
|
441
|
+
/* @__PURE__ */ jsxs4("div", { className: "dlf-item-row", children: [
|
|
442
|
+
/* @__PURE__ */ jsxs4("div", { style: { minWidth: 0 }, children: [
|
|
443
|
+
/* @__PURE__ */ jsx4("p", { className: "dlf-item-title", children: a.description ?? a.instruction.slice(0, 80) }),
|
|
444
|
+
/* @__PURE__ */ jsxs4("p", { className: "dlf-item-meta", children: [
|
|
445
|
+
"Quando: ",
|
|
446
|
+
eventName(a.event)
|
|
447
|
+
] })
|
|
448
|
+
] }),
|
|
449
|
+
/* @__PURE__ */ jsxs4("div", { className: "dlf-actions", children: [
|
|
450
|
+
a.enabled === false ? /* @__PURE__ */ jsx4(Badge, { children: "Pausada" }) : /* @__PURE__ */ jsx4(Badge, { tone: "success", children: "Ativa" }),
|
|
451
|
+
/* @__PURE__ */ jsx4(
|
|
452
|
+
Button,
|
|
453
|
+
{
|
|
454
|
+
variant: "ghost",
|
|
455
|
+
loading: saving === `toggle:${a.id}`,
|
|
456
|
+
disabled: !!saving,
|
|
457
|
+
onClick: () => write((all) => all.map((x) => x.id === a.id ? { ...x, enabled: x.enabled === false } : x), `toggle:${a.id}`, a.enabled === false ? "Automa\xE7\xE3o ativada." : "Automa\xE7\xE3o pausada."),
|
|
458
|
+
children: a.enabled === false ? "Ativar" : "Pausar"
|
|
459
|
+
}
|
|
460
|
+
),
|
|
461
|
+
/* @__PURE__ */ jsx4(Button, { variant: "ghost", disabled: !!saving, onClick: () => setDraft({ originalId: a.id, description: a.description ?? "", event: a.event, instruction: a.instruction, enabled: a.enabled !== false }), children: "Editar" }),
|
|
462
|
+
/* @__PURE__ */ jsx4(
|
|
463
|
+
Button,
|
|
464
|
+
{
|
|
465
|
+
variant: "ghost",
|
|
466
|
+
loading: saving === `remove:${a.id}`,
|
|
467
|
+
disabled: !!saving,
|
|
468
|
+
onClick: () => {
|
|
469
|
+
if (window.confirm(`Excluir a automa\xE7\xE3o \u201C${a.description ?? a.id}\u201D?`)) void write((all) => all.filter((x) => x.id !== a.id), `remove:${a.id}`, "Automa\xE7\xE3o exclu\xEDda.");
|
|
470
|
+
},
|
|
471
|
+
children: "Excluir"
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
] })
|
|
475
|
+
] }),
|
|
476
|
+
/* @__PURE__ */ jsx4("p", { className: "dlf-item-meta dlf-measure", children: a.instruction })
|
|
477
|
+
] }, a.id)) }),
|
|
478
|
+
draft && events.data && /* @__PURE__ */ jsxs4(
|
|
479
|
+
"form",
|
|
480
|
+
{
|
|
481
|
+
className: "dlf-form",
|
|
482
|
+
"aria-label": draft.originalId ? "Editar automa\xE7\xE3o" : "Nova automa\xE7\xE3o",
|
|
483
|
+
onSubmit: (e) => {
|
|
484
|
+
e.preventDefault();
|
|
485
|
+
void submit();
|
|
486
|
+
},
|
|
487
|
+
children: [
|
|
488
|
+
/* @__PURE__ */ jsxs4("div", { className: "dlf-row", children: [
|
|
489
|
+
/* @__PURE__ */ jsx4(Field, { label: "Nome", htmlFor: `${ids}-nome`, hint: "Para achar na lista.", children: /* @__PURE__ */ jsx4("input", { id: `${ids}-nome`, className: "dlf-input", maxLength: 200, autoComplete: "off", placeholder: "Ex.: Prazo da proposta\u2026", value: draft.description, onChange: (e) => setDraft({ ...draft, description: e.target.value }) }) }),
|
|
490
|
+
/* @__PURE__ */ jsx4(Field, { label: "Quando", htmlFor: `${ids}-evento`, children: /* @__PURE__ */ jsx4("select", { id: `${ids}-evento`, className: "dlf-select", value: draft.event, onChange: (e) => setDraft({ ...draft, event: e.target.value }), children: events.data.map((ev) => /* @__PURE__ */ jsx4("option", { value: ev.name, children: ev.description }, ev.name)) }) })
|
|
491
|
+
] }),
|
|
492
|
+
/* @__PURE__ */ jsx4(Field, { label: "O que fazer", htmlFor: `${ids}-instr`, hint: "Escreva como pediria a algu\xE9m da equipe. O assistente recebe os dados do evento (n\xFAmero, fase, processo).", children: /* @__PURE__ */ jsx4(
|
|
493
|
+
"textarea",
|
|
494
|
+
{
|
|
495
|
+
id: `${ids}-instr`,
|
|
496
|
+
className: "dlf-textarea",
|
|
497
|
+
rows: 4,
|
|
498
|
+
required: true,
|
|
499
|
+
minLength: 5,
|
|
500
|
+
maxLength: 2e3,
|
|
501
|
+
placeholder: "Ex.: Se a fase for Proposta, anote no neg\xF3cio: enviar a proposta em at\xE9 24h\u2026",
|
|
502
|
+
value: draft.instruction,
|
|
503
|
+
onChange: (e) => setDraft({ ...draft, instruction: e.target.value })
|
|
504
|
+
}
|
|
505
|
+
) }),
|
|
506
|
+
/* @__PURE__ */ jsxs4("label", { className: "dlf-choice", children: [
|
|
507
|
+
/* @__PURE__ */ jsx4("input", { type: "checkbox", checked: draft.enabled, onChange: (e) => setDraft({ ...draft, enabled: e.target.checked }) }),
|
|
508
|
+
/* @__PURE__ */ jsx4("span", { children: "Ativa" })
|
|
509
|
+
] }),
|
|
510
|
+
/* @__PURE__ */ jsxs4("div", { className: "dlf-actions", children: [
|
|
511
|
+
/* @__PURE__ */ jsx4(Button, { type: "submit", variant: "primary", loading: saving === "form", disabled: draft.instruction.trim().length < 5, children: draft.originalId ? "Salvar automa\xE7\xE3o" : "Criar automa\xE7\xE3o" }),
|
|
512
|
+
/* @__PURE__ */ jsx4(Button, { variant: "ghost", onClick: () => setDraft(null), children: "Cancelar" })
|
|
513
|
+
] })
|
|
514
|
+
]
|
|
515
|
+
}
|
|
516
|
+
)
|
|
517
|
+
]
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/Behavior.tsx
|
|
523
|
+
import { useEffect as useEffect5, useId as useId3, useState as useState5 } from "react";
|
|
524
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
525
|
+
var MODES = {
|
|
526
|
+
auto: { label: "Faz sozinho", tone: "success" },
|
|
527
|
+
ask: { label: "Pergunta antes", tone: "warning" },
|
|
528
|
+
deny: { label: "Nunca faz", tone: "danger" }
|
|
529
|
+
};
|
|
530
|
+
var KIND_LABELS = {
|
|
531
|
+
read: "Consultar",
|
|
532
|
+
create: "Criar",
|
|
533
|
+
update: "Alterar",
|
|
534
|
+
delete: "Excluir",
|
|
535
|
+
action: "A\xE7\xF5es (mover, arquivar\u2026)",
|
|
536
|
+
send: "Enviar mensagens"
|
|
537
|
+
};
|
|
538
|
+
var asList = (v) => v === void 0 ? [] : Array.isArray(v) ? v : [v];
|
|
539
|
+
function describeRule(rule, capabilities) {
|
|
540
|
+
const m = rule.match ?? {};
|
|
541
|
+
const parts = [];
|
|
542
|
+
if (m.actorType) parts.push(m.actorType === "service" ? "Bots e automa\xE7\xF5es" : "Pessoas da equipe");
|
|
543
|
+
if (m.channel) parts.push(`no canal ${asList(m.channel).join(", ")}`);
|
|
544
|
+
if (m.role) parts.push(`papel ${asList(m.role).join(", ")}`);
|
|
545
|
+
const what = [
|
|
546
|
+
...asList(m.capability).map((c) => capabilities.get(c)?.title ?? c),
|
|
547
|
+
...asList(m.kind).map((k) => KIND_LABELS[k] ?? k),
|
|
548
|
+
...asList(m.entity).map((e) => `\xE1rea ${e}`),
|
|
549
|
+
...asList(m.tag).map((t) => `tema ${t}`),
|
|
550
|
+
...asList(m.risk).map((r) => `risco ${r === "high" ? "alto" : r === "medium" ? "m\xE9dio" : "baixo"}`)
|
|
551
|
+
];
|
|
552
|
+
parts.push(what.length ? what.join(", ") : "Qualquer a\xE7\xE3o");
|
|
553
|
+
return parts.join(" \xB7 ");
|
|
554
|
+
}
|
|
555
|
+
var emptyDraft = { target: "kind:create", actorType: "", mode: "ask", description: "" };
|
|
556
|
+
function BehaviorSettings({ currency }) {
|
|
557
|
+
const { client } = useStudio();
|
|
558
|
+
const ids = useId3();
|
|
559
|
+
const settings = useResource(() => client.settings(), [client]);
|
|
560
|
+
const capabilities = useResource(() => client.capabilities().catch(() => []), [client]);
|
|
561
|
+
const [form, setForm] = useState5(null);
|
|
562
|
+
const [draft, setDraft] = useState5(null);
|
|
563
|
+
const [saving, setSaving] = useState5(false);
|
|
564
|
+
const [message, setMessage] = useState5(null);
|
|
565
|
+
useEffect5(() => {
|
|
566
|
+
if (settings.data) setForm(settings.data);
|
|
567
|
+
}, [settings.data]);
|
|
568
|
+
const caps = new Map((capabilities.data ?? []).map((c) => [c.name, c]));
|
|
569
|
+
const dirty = !!form && !!settings.data && JSON.stringify(form) !== JSON.stringify(settings.data);
|
|
570
|
+
async function save(next) {
|
|
571
|
+
setSaving(true);
|
|
572
|
+
setMessage(null);
|
|
573
|
+
try {
|
|
574
|
+
const fresh = await client.settings();
|
|
575
|
+
const saved = await client.saveSettings({
|
|
576
|
+
rules: next.rules,
|
|
577
|
+
...next.instructions?.trim() ? { instructions: next.instructions } : {},
|
|
578
|
+
automations: fresh.automations ?? [],
|
|
579
|
+
...next.budget ? { budget: next.budget } : {}
|
|
580
|
+
});
|
|
581
|
+
settings.setData(saved);
|
|
582
|
+
setForm(saved);
|
|
583
|
+
setMessage({ tone: "success", text: "Salvo. As pr\xF3ximas conversas j\xE1 seguem estas regras." });
|
|
584
|
+
} catch (e) {
|
|
585
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
586
|
+
} finally {
|
|
587
|
+
setSaving(false);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function addRule() {
|
|
591
|
+
if (!draft || !form) return;
|
|
592
|
+
const [type, value] = draft.target.split(/:(.*)/s);
|
|
593
|
+
const rule = {
|
|
594
|
+
mode: draft.mode,
|
|
595
|
+
match: { ...type === "cap" ? { capability: value } : { kind: value }, ...draft.actorType ? { actorType: draft.actorType } : {} },
|
|
596
|
+
...draft.description.trim() ? { description: draft.description.trim() } : {}
|
|
597
|
+
};
|
|
598
|
+
setForm({ ...form, rules: [...form.rules, rule] });
|
|
599
|
+
setDraft(null);
|
|
600
|
+
}
|
|
601
|
+
if (settings.error && !form) return /* @__PURE__ */ jsx5(Notice, { tone: "error", children: settings.error });
|
|
602
|
+
if (!form) return /* @__PURE__ */ jsx5(Loading, {});
|
|
603
|
+
const budgetValue = form.budget?.monthly;
|
|
604
|
+
return /* @__PURE__ */ jsxs5("div", { className: "dlf-stack", children: [
|
|
605
|
+
message && /* @__PURE__ */ jsx5(Notice, { tone: message.tone, children: message.text }),
|
|
606
|
+
/* @__PURE__ */ jsxs5(
|
|
607
|
+
Section,
|
|
608
|
+
{
|
|
609
|
+
title: "Regras",
|
|
610
|
+
description: "O que o assistente faz sozinho, o que pergunta antes e o que nunca faz nesta empresa. Regras fixas da aplica\xE7\xE3o continuam valendo: aqui voc\xEA pode deixar mais restrito, e afrouxar s\xF3 o que a aplica\xE7\xE3o permite.",
|
|
611
|
+
actions: !draft && /* @__PURE__ */ jsx5(Button, { onClick: () => setDraft(emptyDraft), disabled: saving, children: "Nova regra" }),
|
|
612
|
+
children: [
|
|
613
|
+
!form.rules.length && !draft && /* @__PURE__ */ jsx5(Empty, { title: "Sem regras pr\xF3prias", children: "Valem as regras da aplica\xE7\xE3o: consultar \xE9 livre e o que muda dados pergunta antes." }),
|
|
614
|
+
!!form.rules.length && /* @__PURE__ */ jsx5("ul", { className: "dlf-list", children: form.rules.map((rule, i) => /* @__PURE__ */ jsx5("li", { className: "dlf-item", children: /* @__PURE__ */ jsxs5("div", { className: "dlf-item-row", children: [
|
|
615
|
+
/* @__PURE__ */ jsxs5("div", { style: { minWidth: 0 }, children: [
|
|
616
|
+
/* @__PURE__ */ jsx5("p", { className: "dlf-item-title", children: describeRule(rule, caps) }),
|
|
617
|
+
rule.description && /* @__PURE__ */ jsx5("p", { className: "dlf-item-meta", children: rule.description })
|
|
618
|
+
] }),
|
|
619
|
+
/* @__PURE__ */ jsxs5("div", { className: "dlf-actions", children: [
|
|
620
|
+
/* @__PURE__ */ jsx5(Badge, { tone: MODES[rule.mode].tone, children: MODES[rule.mode].label }),
|
|
621
|
+
/* @__PURE__ */ jsx5(Button, { variant: "ghost", onClick: () => setForm({ ...form, rules: form.rules.filter((_, j) => j !== i) }), "aria-label": `Remover a regra: ${describeRule(rule, caps)}`, children: "Remover" })
|
|
622
|
+
] })
|
|
623
|
+
] }) }, i)) }),
|
|
624
|
+
draft && /* @__PURE__ */ jsxs5("div", { className: "dlf-form", role: "group", "aria-label": "Nova regra", children: [
|
|
625
|
+
/* @__PURE__ */ jsxs5("div", { className: "dlf-row", children: [
|
|
626
|
+
/* @__PURE__ */ jsx5(Field, { label: "Para qu\xEA", htmlFor: `${ids}-alvo`, children: /* @__PURE__ */ jsxs5("select", { id: `${ids}-alvo`, className: "dlf-select", value: draft.target, onChange: (e) => setDraft({ ...draft, target: e.target.value }), children: [
|
|
627
|
+
/* @__PURE__ */ jsx5("optgroup", { label: "Tipo de a\xE7\xE3o", children: Object.keys(KIND_LABELS).map((k) => /* @__PURE__ */ jsx5("option", { value: `kind:${k}`, children: KIND_LABELS[k] }, k)) }),
|
|
628
|
+
!!capabilities.data?.length && /* @__PURE__ */ jsx5("optgroup", { label: "Uma a\xE7\xE3o espec\xEDfica", children: [...capabilities.data].sort((a, b) => (a.title ?? a.name).localeCompare(b.title ?? b.name)).map((c) => /* @__PURE__ */ jsx5("option", { value: `cap:${c.name}`, children: c.title ?? c.name }, c.name)) })
|
|
629
|
+
] }) }),
|
|
630
|
+
/* @__PURE__ */ jsx5(Field, { label: "Quem", htmlFor: `${ids}-quem`, children: /* @__PURE__ */ jsxs5("select", { id: `${ids}-quem`, className: "dlf-select", value: draft.actorType, onChange: (e) => setDraft({ ...draft, actorType: e.target.value }), children: [
|
|
631
|
+
/* @__PURE__ */ jsx5("option", { value: "", children: "Todos" }),
|
|
632
|
+
/* @__PURE__ */ jsx5("option", { value: "user", children: "Pessoas da equipe (painel)" }),
|
|
633
|
+
/* @__PURE__ */ jsx5("option", { value: "service", children: "Bots e automa\xE7\xF5es" })
|
|
634
|
+
] }) }),
|
|
635
|
+
/* @__PURE__ */ jsx5(Field, { label: "Decis\xE3o", htmlFor: `${ids}-modo`, children: /* @__PURE__ */ jsx5("select", { id: `${ids}-modo`, className: "dlf-select", value: draft.mode, onChange: (e) => setDraft({ ...draft, mode: e.target.value }), children: Object.keys(MODES).map((m) => /* @__PURE__ */ jsx5("option", { value: m, children: MODES[m].label }, m)) }) })
|
|
636
|
+
] }),
|
|
637
|
+
/* @__PURE__ */ jsx5(Field, { label: "Por qu\xEA (opcional)", htmlFor: `${ids}-desc`, hint: "Aparece na auditoria e para o assistente explicar quando n\xE3o puder fazer algo.", children: /* @__PURE__ */ jsx5("input", { id: `${ids}-desc`, className: "dlf-input", maxLength: 500, autoComplete: "off", placeholder: "Ex.: exclus\xF5es s\xF3 pela equipe\u2026", value: draft.description, onChange: (e) => setDraft({ ...draft, description: e.target.value }) }) }),
|
|
638
|
+
/* @__PURE__ */ jsxs5("div", { className: "dlf-actions", children: [
|
|
639
|
+
/* @__PURE__ */ jsx5(Button, { variant: "primary", onClick: addRule, children: "Adicionar regra" }),
|
|
640
|
+
/* @__PURE__ */ jsx5(Button, { variant: "ghost", onClick: () => setDraft(null), children: "Cancelar" })
|
|
641
|
+
] })
|
|
642
|
+
] })
|
|
643
|
+
]
|
|
644
|
+
}
|
|
645
|
+
),
|
|
646
|
+
/* @__PURE__ */ jsx5(Section, { title: "Prefer\xEAncias", description: "Como o assistente da equipe deve trabalhar aqui: tom, vocabul\xE1rio, o que priorizar. O bot de atendimento usa as instru\xE7\xF5es do pr\xF3prio produto.", children: /* @__PURE__ */ jsx5(Field, { label: "Instru\xE7\xF5es para o assistente", htmlFor: `${ids}-instr`, children: /* @__PURE__ */ jsx5(
|
|
647
|
+
"textarea",
|
|
648
|
+
{
|
|
649
|
+
id: `${ids}-instr`,
|
|
650
|
+
className: "dlf-textarea",
|
|
651
|
+
rows: 5,
|
|
652
|
+
maxLength: 1e4,
|
|
653
|
+
placeholder: "Ex.: Chame neg\xF3cios de oportunidades. Sempre informe valores com centavos\u2026",
|
|
654
|
+
value: form.instructions ?? "",
|
|
655
|
+
onChange: (e) => setForm({ ...form, instructions: e.target.value })
|
|
656
|
+
}
|
|
657
|
+
) }) }),
|
|
658
|
+
/* @__PURE__ */ jsx5(Section, { title: "Limite de gasto", description: "Ao chegar no limite do m\xEAs, o assistente e o bot param de responder at\xE9 o m\xEAs virar ou algu\xE9m aumentar o limite. Em branco: sem limite.", children: /* @__PURE__ */ jsx5(Field, { label: `Limite mensal${currency ? ` (${currency})` : ""}`, htmlFor: `${ids}-budget`, children: /* @__PURE__ */ jsx5(
|
|
659
|
+
"input",
|
|
660
|
+
{
|
|
661
|
+
id: `${ids}-budget`,
|
|
662
|
+
className: "dlf-input",
|
|
663
|
+
style: { maxWidth: "12rem" },
|
|
664
|
+
type: "number",
|
|
665
|
+
inputMode: "decimal",
|
|
666
|
+
min: 0,
|
|
667
|
+
step: "0.01",
|
|
668
|
+
autoComplete: "off",
|
|
669
|
+
value: budgetValue ?? "",
|
|
670
|
+
onChange: (e) => {
|
|
671
|
+
const n = Number(e.target.value);
|
|
672
|
+
const { budget: _b, ...rest } = form;
|
|
673
|
+
setForm(e.target.value === "" || !(n > 0) ? rest : { ...rest, budget: { monthly: n } });
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
) }) }),
|
|
677
|
+
/* @__PURE__ */ jsxs5("div", { className: "dlf-actions", children: [
|
|
678
|
+
/* @__PURE__ */ jsx5(Button, { variant: "primary", loading: saving, disabled: !dirty, onClick: () => save(form), children: "Salvar altera\xE7\xF5es" }),
|
|
679
|
+
dirty && /* @__PURE__ */ jsx5(Button, { variant: "ghost", disabled: saving, onClick: () => setForm(settings.data), children: "Descartar" })
|
|
680
|
+
] })
|
|
681
|
+
] });
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/Keys.tsx
|
|
685
|
+
import { useId as useId4, useState as useState6 } from "react";
|
|
686
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
687
|
+
function ProviderKey({ provider, onChanged }) {
|
|
688
|
+
const { client, locale } = useStudio();
|
|
689
|
+
const id = useId4();
|
|
690
|
+
const [editing, setEditing] = useState6(!provider.configured);
|
|
691
|
+
const [value, setValue] = useState6("");
|
|
692
|
+
const [busy, setBusy] = useState6(null);
|
|
693
|
+
const [message, setMessage] = useState6(null);
|
|
694
|
+
async function save() {
|
|
695
|
+
setBusy("save");
|
|
696
|
+
setMessage(null);
|
|
697
|
+
try {
|
|
698
|
+
await client.saveCredential(provider.name, value.trim());
|
|
699
|
+
setValue("");
|
|
700
|
+
setEditing(false);
|
|
701
|
+
setMessage({ tone: "success", text: "Chave testada e salva. A partir de agora o uso de IA desta empresa vai para esta conta." });
|
|
702
|
+
await onChanged();
|
|
703
|
+
} catch (e) {
|
|
704
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
705
|
+
} finally {
|
|
706
|
+
setBusy(null);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
async function remove() {
|
|
710
|
+
if (!window.confirm(`Remover a chave da ${provider.label}? O assistente e o bot deixam de usar esta conta.${provider.whenMissing ? ` ${provider.whenMissing}` : ""}`)) return;
|
|
711
|
+
setBusy("remove");
|
|
712
|
+
setMessage(null);
|
|
713
|
+
try {
|
|
714
|
+
await client.removeCredential(provider.name);
|
|
715
|
+
setEditing(true);
|
|
716
|
+
setMessage({ tone: "success", text: "Chave removida." });
|
|
717
|
+
await onChanged();
|
|
718
|
+
} catch (e) {
|
|
719
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
720
|
+
} finally {
|
|
721
|
+
setBusy(null);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return /* @__PURE__ */ jsxs6("li", { className: "dlf-item", children: [
|
|
725
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-item-row", children: [
|
|
726
|
+
/* @__PURE__ */ jsxs6("div", { style: { minWidth: 0 }, children: [
|
|
727
|
+
/* @__PURE__ */ jsx6("p", { className: "dlf-item-title", children: provider.label }),
|
|
728
|
+
provider.configured && provider.updatedAt ? /* @__PURE__ */ jsxs6("p", { className: "dlf-item-meta", children: [
|
|
729
|
+
"Chave terminada em ",
|
|
730
|
+
/* @__PURE__ */ jsxs6("span", { translate: "no", style: { fontVariantNumeric: "tabular-nums" }, children: [
|
|
731
|
+
"\u2026",
|
|
732
|
+
provider.last4
|
|
733
|
+
] }),
|
|
734
|
+
" \xB7 salva em",
|
|
735
|
+
" ",
|
|
736
|
+
/* @__PURE__ */ jsx6("time", { dateTime: provider.updatedAt, children: formatDateTime(provider.updatedAt, locale) })
|
|
737
|
+
] }) : /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
738
|
+
provider.description && /* @__PURE__ */ jsx6("p", { className: "dlf-item-meta", children: provider.description }),
|
|
739
|
+
provider.whenMissing && /* @__PURE__ */ jsx6("p", { className: "dlf-item-meta", children: provider.whenMissing })
|
|
740
|
+
] })
|
|
741
|
+
] }),
|
|
742
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-actions", children: [
|
|
743
|
+
provider.configured ? /* @__PURE__ */ jsx6(Badge, { tone: "success", children: "Configurada" }) : /* @__PURE__ */ jsx6(Badge, { children: "Sem chave" }),
|
|
744
|
+
provider.configured && !editing && /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
745
|
+
/* @__PURE__ */ jsx6(Button, { variant: "ghost", disabled: !!busy, onClick: () => setEditing(true), children: "Trocar" }),
|
|
746
|
+
/* @__PURE__ */ jsx6(Button, { variant: "ghost", loading: busy === "remove", disabled: !!busy, onClick: remove, children: "Remover" })
|
|
747
|
+
] })
|
|
748
|
+
] })
|
|
749
|
+
] }),
|
|
750
|
+
message && /* @__PURE__ */ jsx6(Notice, { tone: message.tone, children: message.text }),
|
|
751
|
+
editing && /* @__PURE__ */ jsxs6(
|
|
752
|
+
"form",
|
|
753
|
+
{
|
|
754
|
+
className: "dlf-field",
|
|
755
|
+
style: { gap: "0.75rem", maxWidth: "32rem" },
|
|
756
|
+
onSubmit: (e) => {
|
|
757
|
+
e.preventDefault();
|
|
758
|
+
void save();
|
|
759
|
+
},
|
|
760
|
+
children: [
|
|
761
|
+
/* @__PURE__ */ jsx6(Field, { label: provider.configured ? "Nova chave" : "Chave de API", htmlFor: `${id}-chave`, hint: "A chave \xE9 testada no provedor antes de salvar e fica criptografada. Ningu\xE9m consegue v\xEA-la depois, nem aqui.", children: /* @__PURE__ */ jsx6(
|
|
762
|
+
"input",
|
|
763
|
+
{
|
|
764
|
+
id: `${id}-chave`,
|
|
765
|
+
className: "dlf-input",
|
|
766
|
+
type: "password",
|
|
767
|
+
autoComplete: "off",
|
|
768
|
+
spellCheck: false,
|
|
769
|
+
maxLength: 500,
|
|
770
|
+
placeholder: "sk-\u2026",
|
|
771
|
+
value,
|
|
772
|
+
onChange: (e) => setValue(e.target.value)
|
|
773
|
+
}
|
|
774
|
+
) }),
|
|
775
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-actions", children: [
|
|
776
|
+
/* @__PURE__ */ jsx6(Button, { type: "submit", variant: "primary", loading: busy === "save", disabled: value.trim().length < 8, children: "Testar e salvar" }),
|
|
777
|
+
provider.configured && /* @__PURE__ */ jsx6(Button, { variant: "ghost", onClick: () => setEditing(false), children: "Cancelar" })
|
|
778
|
+
] })
|
|
779
|
+
]
|
|
780
|
+
}
|
|
781
|
+
)
|
|
782
|
+
] });
|
|
783
|
+
}
|
|
784
|
+
function ProviderKeys() {
|
|
785
|
+
const { client } = useStudio();
|
|
786
|
+
const list = useResource(() => client.credentials(), [client]);
|
|
787
|
+
return /* @__PURE__ */ jsxs6(Section, { title: "Chave de IA", description: "A conta do provedor de IA que esta empresa usa. O gasto do assistente, do bot e das automa\xE7\xF5es vai para ela, e a aba Custos mostra quanto.", children: [
|
|
788
|
+
list.error && /* @__PURE__ */ jsx6(Notice, { tone: "error", children: list.error }),
|
|
789
|
+
list.loading && !list.data && /* @__PURE__ */ jsx6(Loading, {}),
|
|
790
|
+
list.data && !list.data.length && /* @__PURE__ */ jsx6(Empty, { title: "A aplica\xE7\xE3o n\xE3o usa chaves por empresa" }),
|
|
791
|
+
!!list.data?.length && /* @__PURE__ */ jsx6("ul", { className: "dlf-list", children: list.data.map((p) => /* @__PURE__ */ jsx6(ProviderKey, { provider: p, onChanged: list.reload }, p.name)) })
|
|
792
|
+
] });
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/Knowledge.tsx
|
|
796
|
+
import { useId as useId5, useState as useState7 } from "react";
|
|
797
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
798
|
+
function KnowledgeBase() {
|
|
799
|
+
const { client, locale } = useStudio();
|
|
800
|
+
const ids = useId5();
|
|
801
|
+
const docs = useResource(() => client.knowledge(), [client]);
|
|
802
|
+
const [draft, setDraft] = useState7(null);
|
|
803
|
+
const [saving, setSaving] = useState7(null);
|
|
804
|
+
const [message, setMessage] = useState7(null);
|
|
805
|
+
const [query, setQuery] = useState7("");
|
|
806
|
+
const [queryAudience, setQueryAudience] = useState7("all");
|
|
807
|
+
const [hits, setHits] = useState7(null);
|
|
808
|
+
const [searching, setSearching] = useState7(false);
|
|
809
|
+
async function save() {
|
|
810
|
+
if (!draft) return;
|
|
811
|
+
setSaving("form");
|
|
812
|
+
setMessage(null);
|
|
813
|
+
try {
|
|
814
|
+
await client.saveKnowledge({ ...draft.id ? { id: draft.id } : {}, title: draft.title.trim(), content: draft.content.trim(), audience: draft.audience, tags: draft.tags });
|
|
815
|
+
setDraft(null);
|
|
816
|
+
setMessage({ tone: "success", text: "Documento salvo. O assistente j\xE1 consulta a vers\xE3o nova." });
|
|
817
|
+
await docs.reload();
|
|
818
|
+
} catch (e) {
|
|
819
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
820
|
+
} finally {
|
|
821
|
+
setSaving(null);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
async function remove(doc) {
|
|
825
|
+
if (!window.confirm(`Excluir o documento \u201C${doc.title}\u201D? O assistente deixa de consult\xE1-lo.`)) return;
|
|
826
|
+
setSaving(doc.id);
|
|
827
|
+
setMessage(null);
|
|
828
|
+
try {
|
|
829
|
+
await client.removeKnowledge(doc.id);
|
|
830
|
+
setMessage({ tone: "success", text: "Documento exclu\xEDdo." });
|
|
831
|
+
await docs.reload();
|
|
832
|
+
} catch (e) {
|
|
833
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
834
|
+
} finally {
|
|
835
|
+
setSaving(null);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
async function search() {
|
|
839
|
+
if (!query.trim()) return;
|
|
840
|
+
setSearching(true);
|
|
841
|
+
try {
|
|
842
|
+
setHits(await client.searchKnowledge(query.trim(), queryAudience));
|
|
843
|
+
} catch (e) {
|
|
844
|
+
setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
|
|
845
|
+
} finally {
|
|
846
|
+
setSearching(false);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return /* @__PURE__ */ jsxs7("div", { className: "dlf-stack", children: [
|
|
850
|
+
/* @__PURE__ */ jsxs7(
|
|
851
|
+
Section,
|
|
852
|
+
{
|
|
853
|
+
title: "Base de conhecimento",
|
|
854
|
+
description: "O que o assistente e o bot consultam antes de responder: perguntas frequentes, pol\xEDticas, explica\xE7\xF5es de produtos. Documentos internos nunca chegam ao bot de atendimento.",
|
|
855
|
+
actions: !draft && /* @__PURE__ */ jsx7(Button, { onClick: () => setDraft({ title: "", content: "", audience: "internal", tags: [] }), disabled: !!saving, children: "Novo documento" }),
|
|
856
|
+
children: [
|
|
857
|
+
message && /* @__PURE__ */ jsx7(Notice, { tone: message.tone, children: message.text }),
|
|
858
|
+
docs.error && /* @__PURE__ */ jsx7(Notice, { tone: "error", children: docs.error }),
|
|
859
|
+
docs.loading && !docs.data && /* @__PURE__ */ jsx7(Loading, {}),
|
|
860
|
+
docs.data && !docs.data.length && !draft && /* @__PURE__ */ jsx7(Empty, { title: "Nenhum documento", children: "Comece pelas perguntas que os clientes mais fazem e pela pol\xEDtica de trocas e pagamentos." }),
|
|
861
|
+
!!docs.data?.length && /* @__PURE__ */ jsx7("ul", { className: "dlf-list", children: docs.data.map((doc) => /* @__PURE__ */ jsx7("li", { className: "dlf-item", children: /* @__PURE__ */ jsxs7("div", { className: "dlf-item-row", children: [
|
|
862
|
+
/* @__PURE__ */ jsxs7("div", { style: { minWidth: 0 }, children: [
|
|
863
|
+
/* @__PURE__ */ jsx7("p", { className: "dlf-item-title", children: doc.title }),
|
|
864
|
+
/* @__PURE__ */ jsxs7("p", { className: "dlf-item-meta", children: [
|
|
865
|
+
doc.content.length.toLocaleString(locale),
|
|
866
|
+
" caracteres \xB7 atualizado em ",
|
|
867
|
+
/* @__PURE__ */ jsx7("time", { dateTime: doc.updatedAt, children: formatDateTime(doc.updatedAt, locale) })
|
|
868
|
+
] })
|
|
869
|
+
] }),
|
|
870
|
+
/* @__PURE__ */ jsxs7("div", { className: "dlf-actions", children: [
|
|
871
|
+
doc.audience === "all" ? /* @__PURE__ */ jsx7(Badge, { tone: "accent", children: "Equipe e clientes" }) : /* @__PURE__ */ jsx7(Badge, { children: "S\xF3 a equipe" }),
|
|
872
|
+
/* @__PURE__ */ jsx7(Button, { variant: "ghost", disabled: !!saving, onClick: () => setDraft({ id: doc.id, title: doc.title, content: doc.content, audience: doc.audience, tags: doc.tags }), children: "Editar" }),
|
|
873
|
+
/* @__PURE__ */ jsx7(Button, { variant: "ghost", loading: saving === doc.id, disabled: !!saving, onClick: () => remove(doc), children: "Excluir" })
|
|
874
|
+
] })
|
|
875
|
+
] }) }, doc.id)) }),
|
|
876
|
+
draft && /* @__PURE__ */ jsxs7(
|
|
877
|
+
"form",
|
|
878
|
+
{
|
|
879
|
+
className: "dlf-form",
|
|
880
|
+
"aria-label": draft.id ? "Editar documento" : "Novo documento",
|
|
881
|
+
onSubmit: (e) => {
|
|
882
|
+
e.preventDefault();
|
|
883
|
+
void save();
|
|
884
|
+
},
|
|
885
|
+
children: [
|
|
886
|
+
/* @__PURE__ */ jsx7(Field, { label: "T\xEDtulo", htmlFor: `${ids}-titulo`, children: /* @__PURE__ */ jsx7("input", { id: `${ids}-titulo`, className: "dlf-input", required: true, maxLength: 200, autoComplete: "off", placeholder: "Ex.: Pol\xEDtica de trocas\u2026", value: draft.title, onChange: (e) => setDraft({ ...draft, title: e.target.value }) }) }),
|
|
887
|
+
/* @__PURE__ */ jsx7(Field, { label: "Conte\xFAdo", htmlFor: `${ids}-conteudo`, hint: "Texto simples. Separe assuntos em par\xE1grafos: a busca devolve o trecho mais relevante.", children: /* @__PURE__ */ jsx7("textarea", { id: `${ids}-conteudo`, className: "dlf-textarea", required: true, rows: 12, maxLength: 1e5, value: draft.content, onChange: (e) => setDraft({ ...draft, content: e.target.value }) }) }),
|
|
888
|
+
/* @__PURE__ */ jsxs7("fieldset", { className: "dlf-field", style: { border: 0, padding: 0, margin: 0 }, children: [
|
|
889
|
+
/* @__PURE__ */ jsx7("legend", { className: "dlf-label", children: "Quem pode ler" }),
|
|
890
|
+
/* @__PURE__ */ jsxs7("label", { className: "dlf-choice", children: [
|
|
891
|
+
/* @__PURE__ */ jsx7("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "internal", onChange: () => setDraft({ ...draft, audience: "internal" }) }),
|
|
892
|
+
/* @__PURE__ */ jsxs7("span", { children: [
|
|
893
|
+
"S\xF3 a equipe ",
|
|
894
|
+
/* @__PURE__ */ jsx7("span", { className: "dlf-muted", children: "(o assistente do painel)" })
|
|
895
|
+
] })
|
|
896
|
+
] }),
|
|
897
|
+
/* @__PURE__ */ jsxs7("label", { className: "dlf-choice", children: [
|
|
898
|
+
/* @__PURE__ */ jsx7("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "all", onChange: () => setDraft({ ...draft, audience: "all" }) }),
|
|
899
|
+
/* @__PURE__ */ jsxs7("span", { children: [
|
|
900
|
+
"Equipe e clientes ",
|
|
901
|
+
/* @__PURE__ */ jsx7("span", { className: "dlf-muted", children: "(o bot de atendimento tamb\xE9m usa nas respostas)" })
|
|
902
|
+
] })
|
|
903
|
+
] })
|
|
904
|
+
] }),
|
|
905
|
+
/* @__PURE__ */ jsxs7("div", { className: "dlf-actions", children: [
|
|
906
|
+
/* @__PURE__ */ jsx7(Button, { type: "submit", variant: "primary", loading: saving === "form", disabled: !draft.title.trim() || !draft.content.trim(), children: "Salvar documento" }),
|
|
907
|
+
/* @__PURE__ */ jsx7(Button, { variant: "ghost", onClick: () => setDraft(null), children: "Cancelar" })
|
|
908
|
+
] })
|
|
909
|
+
]
|
|
910
|
+
}
|
|
911
|
+
)
|
|
912
|
+
]
|
|
913
|
+
}
|
|
914
|
+
),
|
|
915
|
+
/* @__PURE__ */ jsxs7(Section, { title: "Testar a busca", description: "Veja o que o assistente encontra para uma pergunta.", children: [
|
|
916
|
+
/* @__PURE__ */ jsxs7(
|
|
917
|
+
"form",
|
|
918
|
+
{
|
|
919
|
+
className: "dlf-row",
|
|
920
|
+
style: { alignItems: "end" },
|
|
921
|
+
onSubmit: (e) => {
|
|
922
|
+
e.preventDefault();
|
|
923
|
+
void search();
|
|
924
|
+
},
|
|
925
|
+
children: [
|
|
926
|
+
/* @__PURE__ */ jsx7(Field, { label: "Pergunta", htmlFor: `${ids}-busca`, children: /* @__PURE__ */ jsx7("input", { id: `${ids}-busca`, className: "dlf-input", type: "search", autoComplete: "off", maxLength: 300, placeholder: "Ex.: qual o prazo para trocar?\u2026", value: query, onChange: (e) => setQuery(e.target.value) }) }),
|
|
927
|
+
/* @__PURE__ */ jsx7(Field, { label: "Como", htmlFor: `${ids}-como`, children: /* @__PURE__ */ jsxs7("select", { id: `${ids}-como`, className: "dlf-select", value: queryAudience, onChange: (e) => setQueryAudience(e.target.value), children: [
|
|
928
|
+
/* @__PURE__ */ jsx7("option", { value: "all", children: "O bot de atendimento veria" }),
|
|
929
|
+
/* @__PURE__ */ jsx7("option", { value: "internal", children: "O assistente da equipe veria" })
|
|
930
|
+
] }) }),
|
|
931
|
+
/* @__PURE__ */ jsx7("div", { children: /* @__PURE__ */ jsx7(Button, { type: "submit", loading: searching, disabled: !query.trim(), children: "Buscar" }) })
|
|
932
|
+
]
|
|
933
|
+
}
|
|
934
|
+
),
|
|
935
|
+
hits && !hits.length && /* @__PURE__ */ jsx7(Empty, { title: "Nada encontrado", children: "Nesse caso o assistente diz que vai verificar, em vez de inventar." }),
|
|
936
|
+
!!hits?.length && /* @__PURE__ */ jsx7("ul", { className: "dlf-list", "aria-live": "polite", children: hits.map((h) => /* @__PURE__ */ jsxs7("li", { className: "dlf-item", children: [
|
|
937
|
+
/* @__PURE__ */ jsx7("p", { className: "dlf-item-title", children: h.title }),
|
|
938
|
+
/* @__PURE__ */ jsx7("p", { className: "dlf-item-meta dlf-measure", style: { whiteSpace: "pre-line" }, children: h.excerpt.length > 600 ? `${h.excerpt.slice(0, 600)}\u2026` : h.excerpt })
|
|
939
|
+
] }, h.docId)) })
|
|
940
|
+
] })
|
|
941
|
+
] });
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// src/Memory.tsx
|
|
945
|
+
import { useState as useState8 } from "react";
|
|
946
|
+
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
947
|
+
function FactList({ subject, emptyText }) {
|
|
948
|
+
const { client, locale } = useStudio();
|
|
949
|
+
const facts = useResource(() => client.facts(subject), [client, subject.type, subject.id]);
|
|
950
|
+
const [removing, setRemoving] = useState8(null);
|
|
951
|
+
const [error, setError] = useState8(null);
|
|
952
|
+
async function forget(fact) {
|
|
953
|
+
if (!window.confirm(`Esquecer \u201C${fact.text}\u201D? O assistente deixa de usar isso nas pr\xF3ximas conversas.`)) return;
|
|
954
|
+
setRemoving(fact.id);
|
|
955
|
+
setError(null);
|
|
956
|
+
try {
|
|
957
|
+
await client.forget(fact.id);
|
|
958
|
+
await facts.reload();
|
|
959
|
+
} catch (e) {
|
|
960
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
961
|
+
} finally {
|
|
962
|
+
setRemoving(null);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
if (facts.error) return /* @__PURE__ */ jsx8(Notice, { tone: "error", children: facts.error });
|
|
966
|
+
if (!facts.data) return /* @__PURE__ */ jsx8(Loading, {});
|
|
967
|
+
if (!facts.data.length) return /* @__PURE__ */ jsx8(Empty, { title: "Nada guardado", children: emptyText });
|
|
968
|
+
return /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
969
|
+
error && /* @__PURE__ */ jsx8(Notice, { tone: "error", children: error }),
|
|
970
|
+
/* @__PURE__ */ jsx8("ul", { className: "dlf-list", children: facts.data.map((f) => /* @__PURE__ */ jsx8("li", { className: "dlf-item", children: /* @__PURE__ */ jsxs8("div", { className: "dlf-item-row", children: [
|
|
971
|
+
/* @__PURE__ */ jsxs8("div", { style: { minWidth: 0 }, children: [
|
|
972
|
+
/* @__PURE__ */ jsx8("p", { className: "dlf-item-title", style: { fontWeight: 400 }, children: f.text }),
|
|
973
|
+
/* @__PURE__ */ jsxs8("p", { className: "dlf-item-meta", children: [
|
|
974
|
+
/* @__PURE__ */ jsx8("time", { dateTime: f.createdAt, children: formatDateTime(f.createdAt, locale) }),
|
|
975
|
+
f.createdBy?.name ? ` \xB7 por ${f.createdBy.name}` : f.createdBy?.type === "service" ? " \xB7 pelo bot" : ""
|
|
976
|
+
] })
|
|
977
|
+
] }),
|
|
978
|
+
/* @__PURE__ */ jsx8(Button, { variant: "ghost", loading: removing === f.id, disabled: !!removing, onClick: () => forget(f), "aria-label": `Esquecer: ${f.text}`, children: "Esquecer" })
|
|
979
|
+
] }) }, f.id)) })
|
|
980
|
+
] });
|
|
981
|
+
}
|
|
982
|
+
function MemoryBrowser() {
|
|
983
|
+
const { client, labels, locale } = useStudio();
|
|
984
|
+
const subjects = useResource(() => client.factSubjects(), [client]);
|
|
985
|
+
const [open, setOpen] = useState8(null);
|
|
986
|
+
const typeLabel = (type) => labels.subjects?.[type] ?? type;
|
|
987
|
+
if (open) {
|
|
988
|
+
return /* @__PURE__ */ jsx8(
|
|
989
|
+
Section,
|
|
990
|
+
{
|
|
991
|
+
title: open.label ?? open.id,
|
|
992
|
+
description: `${typeLabel(open.type)}. O que o assistente lembra nas pr\xF3ximas conversas. Esque\xE7a o que estiver errado ou n\xE3o deveria ser guardado.`,
|
|
993
|
+
actions: /* @__PURE__ */ jsx8(
|
|
994
|
+
Button,
|
|
995
|
+
{
|
|
996
|
+
variant: "ghost",
|
|
997
|
+
onClick: () => {
|
|
998
|
+
setOpen(null);
|
|
999
|
+
void subjects.reload();
|
|
1000
|
+
},
|
|
1001
|
+
children: "Voltar para a lista"
|
|
1002
|
+
}
|
|
1003
|
+
),
|
|
1004
|
+
children: /* @__PURE__ */ jsx8(FactList, { subject: open, emptyText: "Tudo foi esquecido." })
|
|
1005
|
+
}
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
return /* @__PURE__ */ jsxs8(Section, { title: "Mem\xF3ria", description: "O que o assistente e o bot guardaram sobre clientes e pessoas da equipe, de conversas anteriores.", children: [
|
|
1009
|
+
subjects.error && /* @__PURE__ */ jsx8(Notice, { tone: "error", children: subjects.error }),
|
|
1010
|
+
subjects.loading && !subjects.data && /* @__PURE__ */ jsx8(Loading, {}),
|
|
1011
|
+
subjects.data && !subjects.data.length && /* @__PURE__ */ jsx8(Empty, { title: "Nada guardado ainda", children: "O bot guarda o que o cliente conta (prefer\xEAncias, contexto) e o assistente guarda como cada pessoa gosta de trabalhar." }),
|
|
1012
|
+
!!subjects.data?.length && /* @__PURE__ */ jsx8("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ jsxs8("table", { className: "dlf-table", children: [
|
|
1013
|
+
/* @__PURE__ */ jsx8("thead", { children: /* @__PURE__ */ jsxs8("tr", { children: [
|
|
1014
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", children: "Sobre" }),
|
|
1015
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", children: "Tipo" }),
|
|
1016
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", className: "dlf-num", children: "Fatos" }),
|
|
1017
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", children: "\xDAltimo" })
|
|
1018
|
+
] }) }),
|
|
1019
|
+
/* @__PURE__ */ jsx8("tbody", { children: subjects.data.map((s) => /* @__PURE__ */ jsxs8("tr", { children: [
|
|
1020
|
+
/* @__PURE__ */ jsx8("td", { children: /* @__PURE__ */ jsx8("button", { type: "button", className: "dlf-link-button", onClick: () => setOpen(s), children: s.label ?? s.id }) }),
|
|
1021
|
+
/* @__PURE__ */ jsx8("td", { children: typeLabel(s.type) }),
|
|
1022
|
+
/* @__PURE__ */ jsx8("td", { className: "dlf-num", children: s.count }),
|
|
1023
|
+
/* @__PURE__ */ jsx8("td", { children: /* @__PURE__ */ jsx8("time", { dateTime: s.lastAt, children: formatDateTime(s.lastAt, locale) }) })
|
|
1024
|
+
] }, `${s.type}:${s.id}`)) })
|
|
1025
|
+
] }) })
|
|
1026
|
+
] });
|
|
1027
|
+
}
|
|
1028
|
+
function MyMemory({ subject }) {
|
|
1029
|
+
return /* @__PURE__ */ jsx8(Section, { title: "O que o assistente lembra de voc\xEA", description: "Prefer\xEAncias que voc\xEA pediu para ele guardar. Esque\xE7a o que n\xE3o valer mais.", children: /* @__PURE__ */ jsx8(FactList, { subject, emptyText: 'Pe\xE7a ao assistente, por exemplo: "lembre que prefiro respostas curtas".' }) });
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// src/Studio.tsx
|
|
1033
|
+
import { useState as useState10 } from "react";
|
|
1034
|
+
|
|
1035
|
+
// src/Usage.tsx
|
|
1036
|
+
import { useId as useId6, useState as useState9 } from "react";
|
|
1037
|
+
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1038
|
+
var periodRange = (period) => {
|
|
1039
|
+
const now = /* @__PURE__ */ new Date();
|
|
1040
|
+
const monthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
1041
|
+
if (period === "month") return { from: monthStart.toISOString(), to: new Date(now.getTime() + 6e4).toISOString() };
|
|
1042
|
+
if (period === "last-month") return { from: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 1, 1)).toISOString(), to: monthStart.toISOString() };
|
|
1043
|
+
return { from: new Date(now.getTime() - 7 * 864e5).toISOString(), to: new Date(now.getTime() + 6e4).toISOString() };
|
|
1044
|
+
};
|
|
1045
|
+
function UsageReport() {
|
|
1046
|
+
const { client, labels, locale } = useStudio();
|
|
1047
|
+
const ids = useId6();
|
|
1048
|
+
const [period, setPeriod] = useState9("month");
|
|
1049
|
+
const usage = useResource(() => client.usage(periodRange(period)), [client, period]);
|
|
1050
|
+
const data = usage.data;
|
|
1051
|
+
const money = (n) => formatMoney(n, data?.currency ?? null, locale);
|
|
1052
|
+
const tokens = (t) => formatNumber(t.inputTokens + t.outputTokens, locale);
|
|
1053
|
+
const channelLabel = (c) => labels.channels?.[c] ?? c;
|
|
1054
|
+
const maxDay = Math.max(...data?.byDay.map((d) => data.currency ? d.cost : d.inputTokens + d.outputTokens) ?? [0], 0);
|
|
1055
|
+
const used = data?.budget && period === "month" ? data.total.cost / data.budget.monthly : null;
|
|
1056
|
+
return /* @__PURE__ */ jsxs9(
|
|
1057
|
+
Section,
|
|
1058
|
+
{
|
|
1059
|
+
title: "Uso e custos",
|
|
1060
|
+
description: "Quanto o assistente, o bot e as automa\xE7\xF5es gastaram com IA.",
|
|
1061
|
+
actions: /* @__PURE__ */ jsx9(Field, { label: "Per\xEDodo", htmlFor: `${ids}-periodo`, children: /* @__PURE__ */ jsxs9("select", { id: `${ids}-periodo`, className: "dlf-select", value: period, onChange: (e) => setPeriod(e.target.value), children: [
|
|
1062
|
+
/* @__PURE__ */ jsx9("option", { value: "month", children: "Este m\xEAs" }),
|
|
1063
|
+
/* @__PURE__ */ jsx9("option", { value: "last-month", children: "M\xEAs passado" }),
|
|
1064
|
+
/* @__PURE__ */ jsx9("option", { value: "7d", children: "\xDAltimos 7 dias" })
|
|
1065
|
+
] }) }),
|
|
1066
|
+
children: [
|
|
1067
|
+
usage.error && /* @__PURE__ */ jsx9(Notice, { tone: "error", children: usage.error }),
|
|
1068
|
+
usage.loading && !data && /* @__PURE__ */ jsx9(Loading, {}),
|
|
1069
|
+
data && /* @__PURE__ */ jsxs9(Fragment4, { children: [
|
|
1070
|
+
/* @__PURE__ */ jsxs9("dl", { className: "dlf-stats", children: [
|
|
1071
|
+
/* @__PURE__ */ jsxs9("div", { className: "dlf-stat", children: [
|
|
1072
|
+
/* @__PURE__ */ jsx9("dt", { children: "Custo" }),
|
|
1073
|
+
/* @__PURE__ */ jsx9("dd", { children: data.currency ? money(data.total.cost) : "\u2014" })
|
|
1074
|
+
] }),
|
|
1075
|
+
/* @__PURE__ */ jsxs9("div", { className: "dlf-stat", children: [
|
|
1076
|
+
/* @__PURE__ */ jsx9("dt", { children: "Conversas e tarefas" }),
|
|
1077
|
+
/* @__PURE__ */ jsx9("dd", { children: formatNumber(data.total.runs, locale) })
|
|
1078
|
+
] }),
|
|
1079
|
+
/* @__PURE__ */ jsxs9("div", { className: "dlf-stat", children: [
|
|
1080
|
+
/* @__PURE__ */ jsx9("dt", { children: "Tokens" }),
|
|
1081
|
+
/* @__PURE__ */ jsx9("dd", { children: tokens(data.total) })
|
|
1082
|
+
] })
|
|
1083
|
+
] }),
|
|
1084
|
+
!data.currency && /* @__PURE__ */ jsx9("p", { className: "dlf-muted", children: "Sem tabela de pre\xE7os configurada na aplica\xE7\xE3o: s\xF3 os tokens aparecem." }),
|
|
1085
|
+
data.total.unpricedCalls > 0 && data.currency && /* @__PURE__ */ jsxs9("p", { className: "dlf-muted", children: [
|
|
1086
|
+
formatNumber(data.total.unpricedCalls, locale),
|
|
1087
|
+
" chamadas usaram modelos sem pre\xE7o configurado e n\xE3o entram no custo."
|
|
1088
|
+
] }),
|
|
1089
|
+
used !== null && data.budget && /* @__PURE__ */ jsxs9("div", { className: "dlf-field", children: [
|
|
1090
|
+
/* @__PURE__ */ jsxs9("p", { className: "dlf-muted", id: `${ids}-limite`, children: [
|
|
1091
|
+
money(data.total.cost),
|
|
1092
|
+
" de ",
|
|
1093
|
+
money(data.budget.monthly),
|
|
1094
|
+
" do limite do m\xEAs (",
|
|
1095
|
+
Math.round(used * 100),
|
|
1096
|
+
"%)",
|
|
1097
|
+
used >= 1 ? ". Limite atingido: o assistente est\xE1 parado at\xE9 o m\xEAs virar ou o limite subir." : ""
|
|
1098
|
+
] }),
|
|
1099
|
+
/* @__PURE__ */ jsx9(
|
|
1100
|
+
"div",
|
|
1101
|
+
{
|
|
1102
|
+
className: used >= 1 ? "dlf-meter dlf-meter--over" : "dlf-meter",
|
|
1103
|
+
role: "meter",
|
|
1104
|
+
"aria-labelledby": `${ids}-limite`,
|
|
1105
|
+
"aria-valuemin": 0,
|
|
1106
|
+
"aria-valuemax": 100,
|
|
1107
|
+
"aria-valuenow": Math.min(100, Math.round(used * 100)),
|
|
1108
|
+
children: /* @__PURE__ */ jsx9("span", { style: { width: `${Math.min(100, used * 100)}%` } })
|
|
1109
|
+
}
|
|
1110
|
+
)
|
|
1111
|
+
] }),
|
|
1112
|
+
!data.byDay.length ? /* @__PURE__ */ jsx9(Empty, { title: "Nenhum uso no per\xEDodo" }) : /* @__PURE__ */ jsxs9(Fragment4, { children: [
|
|
1113
|
+
/* @__PURE__ */ jsxs9("div", { children: [
|
|
1114
|
+
/* @__PURE__ */ jsx9("h3", { className: "dlf-h3", style: { marginBottom: "0.5rem" }, children: "Por dia" }),
|
|
1115
|
+
/* @__PURE__ */ jsx9("div", { className: "dlf-bars", children: data.byDay.map((d) => {
|
|
1116
|
+
const value = data.currency ? d.cost : d.inputTokens + d.outputTokens;
|
|
1117
|
+
return /* @__PURE__ */ jsxs9("div", { style: { display: "contents" }, children: [
|
|
1118
|
+
/* @__PURE__ */ jsx9("span", { className: "dlf-muted", children: new Intl.DateTimeFormat(locale, { day: "2-digit", month: "2-digit", timeZone: "UTC" }).format(/* @__PURE__ */ new Date(`${d.day}T00:00:00Z`)) }),
|
|
1119
|
+
/* @__PURE__ */ jsx9("span", { className: "dlf-bar", style: { width: `${maxDay ? value / maxDay * 100 : 0}%` }, "aria-hidden": true }),
|
|
1120
|
+
/* @__PURE__ */ jsx9("span", { className: "dlf-num", children: data.currency ? money(d.cost) : tokens(d) })
|
|
1121
|
+
] }, d.day);
|
|
1122
|
+
}) })
|
|
1123
|
+
] }),
|
|
1124
|
+
[
|
|
1125
|
+
["Por canal", data.byChannel.map((c) => ({ key: c.channel, label: channelLabel(c.channel), t: c }))],
|
|
1126
|
+
["Por modelo", data.byModel.map((m) => ({ key: m.model, label: m.model.slice(m.model.indexOf(":") + 1), t: m }))]
|
|
1127
|
+
].map(([title, rows]) => /* @__PURE__ */ jsx9("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ jsxs9("table", { className: "dlf-table", children: [
|
|
1128
|
+
/* @__PURE__ */ jsx9("caption", { className: "dlf-sr-only", children: title }),
|
|
1129
|
+
/* @__PURE__ */ jsx9("thead", { children: /* @__PURE__ */ jsxs9("tr", { children: [
|
|
1130
|
+
/* @__PURE__ */ jsx9("th", { scope: "col", children: title }),
|
|
1131
|
+
/* @__PURE__ */ jsx9("th", { scope: "col", className: "dlf-num", children: "Execu\xE7\xF5es" }),
|
|
1132
|
+
/* @__PURE__ */ jsx9("th", { scope: "col", className: "dlf-num", children: "Tokens" }),
|
|
1133
|
+
data.currency && /* @__PURE__ */ jsx9("th", { scope: "col", className: "dlf-num", children: "Custo" })
|
|
1134
|
+
] }) }),
|
|
1135
|
+
/* @__PURE__ */ jsx9("tbody", { children: rows.map((r) => /* @__PURE__ */ jsxs9("tr", { children: [
|
|
1136
|
+
/* @__PURE__ */ jsx9("td", { children: r.label }),
|
|
1137
|
+
/* @__PURE__ */ jsx9("td", { className: "dlf-num", children: formatNumber(r.t.runs, locale) }),
|
|
1138
|
+
/* @__PURE__ */ jsx9("td", { className: "dlf-num", children: tokens(r.t) }),
|
|
1139
|
+
data.currency && /* @__PURE__ */ jsx9("td", { className: "dlf-num", children: money(r.t.cost) })
|
|
1140
|
+
] }, r.key)) })
|
|
1141
|
+
] }) }, title))
|
|
1142
|
+
] })
|
|
1143
|
+
] })
|
|
1144
|
+
]
|
|
1145
|
+
}
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// src/Studio.tsx
|
|
1150
|
+
import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1151
|
+
var LABELS = {
|
|
1152
|
+
approvals: "Aprova\xE7\xF5es",
|
|
1153
|
+
behavior: "Regras",
|
|
1154
|
+
automations: "Automa\xE7\xF5es",
|
|
1155
|
+
knowledge: "Conhecimento",
|
|
1156
|
+
memory: "Mem\xF3ria",
|
|
1157
|
+
usage: "Custos",
|
|
1158
|
+
keys: "Chave de IA",
|
|
1159
|
+
audit: "Auditoria"
|
|
1160
|
+
};
|
|
1161
|
+
function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, currency, pendingApprovals, onPendingApprovalsChange }) {
|
|
1162
|
+
const visible = sections ?? Object.keys(LABELS);
|
|
1163
|
+
const [own, setOwn] = useState10(defaultSection ?? visible[0]);
|
|
1164
|
+
const [pending, setPending] = useState10(pendingApprovals);
|
|
1165
|
+
const current = section ?? own;
|
|
1166
|
+
const select = (s) => {
|
|
1167
|
+
setOwn(s);
|
|
1168
|
+
onSectionChange?.(s);
|
|
1169
|
+
};
|
|
1170
|
+
const onCount = (n) => {
|
|
1171
|
+
setPending(n);
|
|
1172
|
+
onPendingApprovalsChange?.(n);
|
|
1173
|
+
};
|
|
1174
|
+
const panels = {
|
|
1175
|
+
approvals: () => /* @__PURE__ */ jsx10(ApprovalsInbox, { onCount }),
|
|
1176
|
+
behavior: () => /* @__PURE__ */ jsx10(BehaviorSettings, { currency: currency ?? null }),
|
|
1177
|
+
automations: () => /* @__PURE__ */ jsx10(AutomationsEditor, {}),
|
|
1178
|
+
knowledge: () => /* @__PURE__ */ jsx10(KnowledgeBase, {}),
|
|
1179
|
+
memory: () => /* @__PURE__ */ jsx10(MemoryBrowser, {}),
|
|
1180
|
+
usage: () => /* @__PURE__ */ jsx10(UsageReport, {}),
|
|
1181
|
+
keys: () => /* @__PURE__ */ jsx10(ProviderKeys, {}),
|
|
1182
|
+
audit: () => /* @__PURE__ */ jsx10(AuditLog, {})
|
|
1183
|
+
};
|
|
1184
|
+
return /* @__PURE__ */ jsxs10("div", { className: "dlf dlf-studio", children: [
|
|
1185
|
+
/* @__PURE__ */ jsx10(
|
|
1186
|
+
Tabs,
|
|
1187
|
+
{
|
|
1188
|
+
label: "\xC1reas do assistente de IA",
|
|
1189
|
+
value: current,
|
|
1190
|
+
onChange: select,
|
|
1191
|
+
tabs: visible.map((id) => ({ id, label: LABELS[id], ...id === "approvals" ? { count: pendingApprovals ?? pending ?? 0 } : {} }))
|
|
1192
|
+
}
|
|
1193
|
+
),
|
|
1194
|
+
/* @__PURE__ */ jsx10("div", { role: "tabpanel", id: `dlf-panel-${current}`, "aria-labelledby": `dlf-tab-${current}`, tabIndex: 0, style: { outlineOffset: 4 }, children: panels[current]() })
|
|
1195
|
+
] });
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// src/index.tsx
|
|
1199
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1200
|
+
function StudioProvider({ children, endpoint, headers, fetch: fetch2, labels, locale = "pt-BR", navigate }) {
|
|
1201
|
+
const client = useMemo(
|
|
1202
|
+
() => createStudioClient({ ...endpoint ? { endpoint } : {}, ...headers ? { headers } : {}, ...fetch2 ? { fetch: fetch2 } : {} }),
|
|
1203
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1204
|
+
[endpoint]
|
|
1205
|
+
);
|
|
1206
|
+
const value = useMemo(() => ({ client, labels: labels ?? {}, locale, ...navigate ? { navigate } : {} }), [client, labels, locale, navigate]);
|
|
1207
|
+
return /* @__PURE__ */ jsx11(StudioContextProvider, { value, children });
|
|
1208
|
+
}
|
|
1209
|
+
export {
|
|
1210
|
+
ApprovalsInbox,
|
|
1211
|
+
AuditLog,
|
|
1212
|
+
AutomationsEditor,
|
|
1213
|
+
BehaviorSettings,
|
|
1214
|
+
DolfinhosStudio,
|
|
1215
|
+
KnowledgeBase,
|
|
1216
|
+
MemoryBrowser,
|
|
1217
|
+
MyMemory,
|
|
1218
|
+
ProviderKeys,
|
|
1219
|
+
StudioError,
|
|
1220
|
+
StudioProvider,
|
|
1221
|
+
UsageReport,
|
|
1222
|
+
createStudioClient,
|
|
1223
|
+
useStudio
|
|
1224
|
+
};
|
|
1225
|
+
//# sourceMappingURL=index.js.map
|