@dolfinhos/studio 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +468 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -3
- package/dist/index.d.ts +67 -3
- package/dist/index.js +464 -153
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -63,7 +63,14 @@ function createStudioClient(options = {}) {
|
|
|
63
63
|
searchKnowledge: (query, audience) => request("GET", `/knowledge/search${q({ q: query, audience })}`),
|
|
64
64
|
factSubjects: (type) => request("GET", `/facts${q({ type })}`),
|
|
65
65
|
facts: (subject) => request("GET", `/facts${q({ type: subject.type, id: subject.id })}`),
|
|
66
|
-
forget: (id) => request("DELETE", `/facts/${encodeURIComponent(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
|
+
models: () => request("GET", "/models"),
|
|
71
|
+
availableModels: (provider) => request("GET", `/models/${encodeURIComponent(provider)}/available`),
|
|
72
|
+
chooseModels: (choice) => request("PUT", "/models", choice),
|
|
73
|
+
resetModels: () => request("DELETE", "/models")
|
|
67
74
|
};
|
|
68
75
|
}
|
|
69
76
|
var StudioContext = createContext(null);
|
|
@@ -678,20 +685,320 @@ function BehaviorSettings({ currency }) {
|
|
|
678
685
|
] });
|
|
679
686
|
}
|
|
680
687
|
|
|
681
|
-
// src/
|
|
688
|
+
// src/Keys.tsx
|
|
682
689
|
import { useId as useId4, useState as useState6 } from "react";
|
|
683
|
-
import {
|
|
690
|
+
import { useEffect as useEffect6 } from "react";
|
|
691
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
692
|
+
function ProviderKey({
|
|
693
|
+
provider,
|
|
694
|
+
onChanged,
|
|
695
|
+
children,
|
|
696
|
+
compact
|
|
697
|
+
}) {
|
|
698
|
+
const { client, locale } = useStudio();
|
|
699
|
+
const id = useId4();
|
|
700
|
+
const [editing, setEditing] = useState6(!provider.configured);
|
|
701
|
+
const [value, setValue] = useState6("");
|
|
702
|
+
const [busy, setBusy] = useState6(null);
|
|
703
|
+
const [message, setMessage] = useState6(null);
|
|
704
|
+
async function save() {
|
|
705
|
+
setBusy("save");
|
|
706
|
+
setMessage(null);
|
|
707
|
+
try {
|
|
708
|
+
await client.saveCredential(provider.name, value.trim());
|
|
709
|
+
setValue("");
|
|
710
|
+
setEditing(false);
|
|
711
|
+
setMessage({ tone: "success", text: "Chave testada e salva." });
|
|
712
|
+
await onChanged("saved");
|
|
713
|
+
} catch (e) {
|
|
714
|
+
setMessage({
|
|
715
|
+
tone: "error",
|
|
716
|
+
text: e instanceof Error ? e.message : String(e)
|
|
717
|
+
});
|
|
718
|
+
} finally {
|
|
719
|
+
setBusy(null);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
async function remove() {
|
|
723
|
+
if (!window.confirm(`Remover a chave da ${provider.label}? O assistente e o bot deixam de usar esta conta.${provider.whenMissing ? ` ${provider.whenMissing}` : ""}`)) return;
|
|
724
|
+
setBusy("remove");
|
|
725
|
+
setMessage(null);
|
|
726
|
+
try {
|
|
727
|
+
await client.removeCredential(provider.name);
|
|
728
|
+
setEditing(true);
|
|
729
|
+
setMessage({ tone: "success", text: "Chave removida." });
|
|
730
|
+
await onChanged("removed");
|
|
731
|
+
} catch (e) {
|
|
732
|
+
setMessage({
|
|
733
|
+
tone: "error",
|
|
734
|
+
text: e instanceof Error ? e.message : String(e)
|
|
735
|
+
});
|
|
736
|
+
} finally {
|
|
737
|
+
setBusy(null);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return /* @__PURE__ */ jsxs6("li", { className: "dlf-item", children: [
|
|
741
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-item-row", children: [
|
|
742
|
+
/* @__PURE__ */ jsxs6("div", { style: { minWidth: 0 }, children: [
|
|
743
|
+
/* @__PURE__ */ jsx6("p", { className: "dlf-item-title", children: provider.label }),
|
|
744
|
+
provider.configured && provider.updatedAt ? /* @__PURE__ */ jsxs6("p", { className: "dlf-item-meta", children: [
|
|
745
|
+
"Chave terminada em",
|
|
746
|
+
" ",
|
|
747
|
+
/* @__PURE__ */ jsxs6("span", { translate: "no", style: { fontVariantNumeric: "tabular-nums" }, children: [
|
|
748
|
+
"\u2026",
|
|
749
|
+
provider.last4
|
|
750
|
+
] }),
|
|
751
|
+
" ",
|
|
752
|
+
"\xB7 salva em ",
|
|
753
|
+
/* @__PURE__ */ jsx6("time", { dateTime: provider.updatedAt, children: formatDateTime(provider.updatedAt, locale) })
|
|
754
|
+
] }) : /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
755
|
+
provider.description && /* @__PURE__ */ jsx6("p", { className: "dlf-item-meta", children: provider.description }),
|
|
756
|
+
provider.whenMissing && !compact && /* @__PURE__ */ jsx6("p", { className: "dlf-item-meta", children: provider.whenMissing })
|
|
757
|
+
] })
|
|
758
|
+
] }),
|
|
759
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-actions", children: [
|
|
760
|
+
provider.configured ? /* @__PURE__ */ jsx6(Badge, { tone: "success", children: "Configurada" }) : /* @__PURE__ */ jsx6(Badge, { children: "Sem chave" }),
|
|
761
|
+
provider.configured && !editing && /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
762
|
+
/* @__PURE__ */ jsx6(Button, { variant: "ghost", disabled: !!busy, onClick: () => setEditing(true), children: "Trocar" }),
|
|
763
|
+
/* @__PURE__ */ jsx6(Button, { variant: "ghost", loading: busy === "remove", disabled: !!busy, onClick: remove, children: "Remover" })
|
|
764
|
+
] })
|
|
765
|
+
] })
|
|
766
|
+
] }),
|
|
767
|
+
message && /* @__PURE__ */ jsx6(Notice, { tone: message.tone, children: message.text }),
|
|
768
|
+
editing && /* @__PURE__ */ jsxs6(
|
|
769
|
+
"form",
|
|
770
|
+
{
|
|
771
|
+
className: "dlf-field",
|
|
772
|
+
style: { gap: "0.75rem", maxWidth: "32rem" },
|
|
773
|
+
onSubmit: (e) => {
|
|
774
|
+
e.preventDefault();
|
|
775
|
+
void save();
|
|
776
|
+
},
|
|
777
|
+
children: [
|
|
778
|
+
/* @__PURE__ */ jsx6(
|
|
779
|
+
Field,
|
|
780
|
+
{
|
|
781
|
+
label: provider.configured ? "Nova chave" : "Chave de API",
|
|
782
|
+
htmlFor: `${id}-chave`,
|
|
783
|
+
hint: "A chave \xE9 testada no provedor antes de salvar e fica criptografada. Ningu\xE9m consegue v\xEA-la depois, nem aqui.",
|
|
784
|
+
children: /* @__PURE__ */ jsx6(
|
|
785
|
+
"input",
|
|
786
|
+
{
|
|
787
|
+
id: `${id}-chave`,
|
|
788
|
+
className: "dlf-input",
|
|
789
|
+
type: "password",
|
|
790
|
+
autoComplete: "off",
|
|
791
|
+
spellCheck: false,
|
|
792
|
+
maxLength: 500,
|
|
793
|
+
placeholder: "sk-\u2026",
|
|
794
|
+
value,
|
|
795
|
+
onChange: (e) => setValue(e.target.value)
|
|
796
|
+
}
|
|
797
|
+
)
|
|
798
|
+
}
|
|
799
|
+
),
|
|
800
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-actions", children: [
|
|
801
|
+
/* @__PURE__ */ jsx6(Button, { type: "submit", variant: "primary", loading: busy === "save", disabled: value.trim().length < 8, children: "Testar e salvar" }),
|
|
802
|
+
provider.configured && /* @__PURE__ */ jsx6(Button, { variant: "ghost", onClick: () => setEditing(false), children: "Cancelar" })
|
|
803
|
+
] })
|
|
804
|
+
]
|
|
805
|
+
}
|
|
806
|
+
),
|
|
807
|
+
children
|
|
808
|
+
] });
|
|
809
|
+
}
|
|
810
|
+
function ProviderKeys() {
|
|
811
|
+
const { client } = useStudio();
|
|
812
|
+
const list = useResource(() => client.credentials(), [client]);
|
|
813
|
+
return /* @__PURE__ */ jsxs6(
|
|
814
|
+
Section,
|
|
815
|
+
{
|
|
816
|
+
title: "Chave de IA",
|
|
817
|
+
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.",
|
|
818
|
+
children: [
|
|
819
|
+
list.error && /* @__PURE__ */ jsx6(Notice, { tone: "error", children: list.error }),
|
|
820
|
+
list.loading && !list.data && /* @__PURE__ */ jsx6(Loading, {}),
|
|
821
|
+
list.data && !list.data.length && /* @__PURE__ */ jsx6(Empty, { title: "A aplica\xE7\xE3o n\xE3o usa chaves por empresa" }),
|
|
822
|
+
!!list.data?.length && /* @__PURE__ */ jsx6("ul", { className: "dlf-list", children: list.data.map((p) => /* @__PURE__ */ jsx6(ProviderKey, { provider: p, onChanged: () => list.reload() }, p.name)) })
|
|
823
|
+
]
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
function ModelChooser({ overview, provider, onSaved, onCancel }) {
|
|
828
|
+
const { client } = useStudio();
|
|
829
|
+
const id = useId4();
|
|
830
|
+
const label = overview.providers.find((p) => p.name === provider)?.label ?? provider;
|
|
831
|
+
const list = useResource(() => client.availableModels(provider), [client, provider]);
|
|
832
|
+
const suggested = overview.providers.find((p) => p.name === provider)?.defaults ?? {};
|
|
833
|
+
const start = overview.chosen?.provider === provider ? overview.chosen.models : overview.active?.provider === provider ? overview.active.models : suggested;
|
|
834
|
+
const [models, setModels] = useState6(start);
|
|
835
|
+
const [saving, setSaving] = useState6(false);
|
|
836
|
+
const [error, setError] = useState6(null);
|
|
837
|
+
useEffect6(() => {
|
|
838
|
+
if (!list.data?.length) return;
|
|
839
|
+
const inList = (id2) => !!id2 && list.data.some((m) => m.id === id2);
|
|
840
|
+
setModels(
|
|
841
|
+
(current) => Object.fromEntries(overview.roles.map((r) => [r.name, inList(current[r.name]) ? current[r.name] : inList(suggested[r.name]) ? suggested[r.name] : list.data[0].id]))
|
|
842
|
+
);
|
|
843
|
+
}, [list.data, overview.roles]);
|
|
844
|
+
async function save() {
|
|
845
|
+
setSaving(true);
|
|
846
|
+
setError(null);
|
|
847
|
+
try {
|
|
848
|
+
await client.chooseModels({ provider, models });
|
|
849
|
+
await onSaved();
|
|
850
|
+
} catch (e) {
|
|
851
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
852
|
+
} finally {
|
|
853
|
+
setSaving(false);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return /* @__PURE__ */ jsxs6(
|
|
857
|
+
"form",
|
|
858
|
+
{
|
|
859
|
+
className: "dlf-form",
|
|
860
|
+
"aria-label": `Modelos do ${label}`,
|
|
861
|
+
onSubmit: (e) => {
|
|
862
|
+
e.preventDefault();
|
|
863
|
+
void save();
|
|
864
|
+
},
|
|
865
|
+
children: [
|
|
866
|
+
/* @__PURE__ */ jsxs6("p", { className: "dlf-item-title", children: [
|
|
867
|
+
"Usar ",
|
|
868
|
+
label
|
|
869
|
+
] }),
|
|
870
|
+
list.error && /* @__PURE__ */ jsx6(Notice, { tone: "error", children: list.error }),
|
|
871
|
+
list.loading && !list.data && /* @__PURE__ */ jsx6(Loading, { label: "Buscando os modelos desta chave\u2026" }),
|
|
872
|
+
list.data && !list.data.length && /* @__PURE__ */ jsx6(Notice, { tone: "error", children: "A chave n\xE3o enxerga nenhum modelo de texto neste provedor." }),
|
|
873
|
+
!!list.data?.length && /* @__PURE__ */ jsx6("div", { className: "dlf-row", children: overview.roles.map((role) => /* @__PURE__ */ jsx6(Field, { label: role.label, htmlFor: `${id}-${role.name}`, hint: role.description, children: /* @__PURE__ */ jsx6("select", { id: `${id}-${role.name}`, className: "dlf-select", value: models[role.name] ?? "", onChange: (e) => setModels({ ...models, [role.name]: e.target.value }), children: list.data.map((m) => /* @__PURE__ */ jsx6("option", { value: m.id, children: m.label ? `${m.label} (${m.id})` : m.id }, m.id)) }) }, role.name)) }),
|
|
874
|
+
error && /* @__PURE__ */ jsx6(Notice, { tone: "error", children: error }),
|
|
875
|
+
/* @__PURE__ */ jsxs6("div", { className: "dlf-actions", children: [
|
|
876
|
+
/* @__PURE__ */ jsx6(Button, { type: "submit", variant: "primary", loading: saving, disabled: !list.data?.length, children: "Usar estes modelos" }),
|
|
877
|
+
/* @__PURE__ */ jsx6(Button, { variant: "ghost", onClick: onCancel, children: "Cancelar" })
|
|
878
|
+
] })
|
|
879
|
+
]
|
|
880
|
+
}
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
function ModelSettings() {
|
|
884
|
+
const { client } = useStudio();
|
|
885
|
+
const overview = useResource(() => client.models(), [client]);
|
|
886
|
+
const keys = useResource(() => client.credentials(), [client]);
|
|
887
|
+
const [choosing, setChoosing] = useState6(null);
|
|
888
|
+
const [message, setMessage] = useState6(null);
|
|
889
|
+
const refresh = async () => {
|
|
890
|
+
await Promise.all([overview.reload(), keys.reload()]);
|
|
891
|
+
};
|
|
892
|
+
const o = overview.data;
|
|
893
|
+
const labelOf = (name) => o?.providers.find((p) => p.name === name)?.label ?? name;
|
|
894
|
+
const roleLabel = (name) => o?.roles.find((r) => r.name === name)?.label ?? name;
|
|
895
|
+
async function reset() {
|
|
896
|
+
if (!window.confirm("Voltar ao autom\xE1tico? A empresa passa a usar a primeira chave cadastrada com os modelos sugeridos, ou a conta da plataforma.")) return;
|
|
897
|
+
try {
|
|
898
|
+
await client.resetModels();
|
|
899
|
+
setMessage({ tone: "success", text: "Voltou ao autom\xE1tico." });
|
|
900
|
+
await refresh();
|
|
901
|
+
} catch (e) {
|
|
902
|
+
setMessage({
|
|
903
|
+
tone: "error",
|
|
904
|
+
text: e instanceof Error ? e.message : String(e)
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (!o || !keys.data) {
|
|
909
|
+
const failure = overview.error ?? keys.error;
|
|
910
|
+
return failure ? /* @__PURE__ */ jsx6(Notice, { tone: "error", children: failure }) : /* @__PURE__ */ jsx6(Loading, {});
|
|
911
|
+
}
|
|
912
|
+
const whenMissing = keys.data.find((k) => k.whenMissing)?.whenMissing;
|
|
913
|
+
const chosenKeySaved = !!o.chosen && !!keys.data.find((k) => k.name === o.chosen.provider)?.configured;
|
|
914
|
+
return /* @__PURE__ */ jsxs6("div", { className: "dlf-stack", children: [
|
|
915
|
+
/* @__PURE__ */ jsxs6(
|
|
916
|
+
Section,
|
|
917
|
+
{
|
|
918
|
+
title: "Modelo de IA",
|
|
919
|
+
description: "Qual provedor de IA esta empresa usa, com a chave dela, e o modelo de cada parte do assistente. O gasto vai para a conta do provedor, e a aba Custos mostra quanto.",
|
|
920
|
+
children: [
|
|
921
|
+
message && /* @__PURE__ */ jsx6(Notice, { tone: message.tone, children: message.text }),
|
|
922
|
+
o.active ? /* @__PURE__ */ jsxs6("div", { className: "dlf-notice", children: [
|
|
923
|
+
/* @__PURE__ */ jsxs6("p", { className: "dlf-item-title", children: [
|
|
924
|
+
"Em uso: ",
|
|
925
|
+
labelOf(o.active.provider),
|
|
926
|
+
" ",
|
|
927
|
+
o.active.source === "empresa" ? "(chave da empresa)" : "(conta de IA da plataforma)"
|
|
928
|
+
] }),
|
|
929
|
+
/* @__PURE__ */ jsx6("dl", { className: "dlf-dl", children: Object.entries(o.active.models).map(([role, model]) => /* @__PURE__ */ jsxs6("div", { style: { display: "contents" }, children: [
|
|
930
|
+
/* @__PURE__ */ jsx6("dt", { children: roleLabel(role) }),
|
|
931
|
+
/* @__PURE__ */ jsx6("dd", { translate: "no", children: model })
|
|
932
|
+
] }, role)) }),
|
|
933
|
+
o.chosen && /* @__PURE__ */ jsx6("div", { className: "dlf-actions", style: { marginTop: "0.75rem" }, children: /* @__PURE__ */ jsx6(Button, { variant: "ghost", onClick: reset, children: "Voltar ao autom\xE1tico" }) })
|
|
934
|
+
] }) : /* @__PURE__ */ jsx6(Notice, { tone: "error", children: "Esta empresa est\xE1 sem IA: cadastre a chave de um provedor abaixo." }),
|
|
935
|
+
o.active?.source === "plataforma" && whenMissing && /* @__PURE__ */ jsx6("p", { className: "dlf-muted dlf-measure", children: whenMissing }),
|
|
936
|
+
o.chosen && !chosenKeySaved && /* @__PURE__ */ jsxs6(Notice, { tone: "error", children: [
|
|
937
|
+
"A chave do ",
|
|
938
|
+
labelOf(o.chosen.provider),
|
|
939
|
+
" foi removida: a empresa voltou para o que est\xE1 em uso acima."
|
|
940
|
+
] })
|
|
941
|
+
]
|
|
942
|
+
}
|
|
943
|
+
),
|
|
944
|
+
/* @__PURE__ */ jsxs6(Section, { title: "Provedores", description: "Cadastre a chave de um ou mais provedores e escolha qual usar.", children: [
|
|
945
|
+
!keys.data.length && /* @__PURE__ */ jsx6(Empty, { title: "A aplica\xE7\xE3o n\xE3o usa chaves por empresa" }),
|
|
946
|
+
!!keys.data.length && /* @__PURE__ */ jsx6("ul", { className: "dlf-list", children: keys.data.map((p) => {
|
|
947
|
+
const inUse = o.active?.source === "empresa" && o.active.provider === p.name;
|
|
948
|
+
return /* @__PURE__ */ jsxs6(
|
|
949
|
+
ProviderKey,
|
|
950
|
+
{
|
|
951
|
+
provider: p,
|
|
952
|
+
compact: true,
|
|
953
|
+
onChanged: async (change) => {
|
|
954
|
+
await refresh();
|
|
955
|
+
if (change === "saved" && !inUse) setChoosing(p.name);
|
|
956
|
+
if (change === "removed" && choosing === p.name) setChoosing(null);
|
|
957
|
+
},
|
|
958
|
+
children: [
|
|
959
|
+
p.configured && choosing !== p.name && /* @__PURE__ */ jsxs6("div", { className: "dlf-actions", children: [
|
|
960
|
+
inUse && /* @__PURE__ */ jsx6(Badge, { tone: "accent", children: "Em uso" }),
|
|
961
|
+
/* @__PURE__ */ jsx6(Button, { variant: inUse ? "ghost" : "secondary", onClick: () => setChoosing(p.name), children: inUse ? "Trocar os modelos" : `Usar ${p.label}` })
|
|
962
|
+
] }),
|
|
963
|
+
choosing === p.name && /* @__PURE__ */ jsx6(
|
|
964
|
+
ModelChooser,
|
|
965
|
+
{
|
|
966
|
+
overview: o,
|
|
967
|
+
provider: p.name,
|
|
968
|
+
onCancel: () => setChoosing(null),
|
|
969
|
+
onSaved: async () => {
|
|
970
|
+
setChoosing(null);
|
|
971
|
+
setMessage({
|
|
972
|
+
tone: "success",
|
|
973
|
+
text: `Pronto: esta empresa agora usa ${p.label}.`
|
|
974
|
+
});
|
|
975
|
+
await refresh();
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
)
|
|
979
|
+
]
|
|
980
|
+
},
|
|
981
|
+
p.name
|
|
982
|
+
);
|
|
983
|
+
}) })
|
|
984
|
+
] })
|
|
985
|
+
] });
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// src/Knowledge.tsx
|
|
989
|
+
import { useId as useId5, useState as useState7 } from "react";
|
|
990
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
684
991
|
function KnowledgeBase() {
|
|
685
992
|
const { client, locale } = useStudio();
|
|
686
|
-
const ids =
|
|
993
|
+
const ids = useId5();
|
|
687
994
|
const docs = useResource(() => client.knowledge(), [client]);
|
|
688
|
-
const [draft, setDraft] =
|
|
689
|
-
const [saving, setSaving] =
|
|
690
|
-
const [message, setMessage] =
|
|
691
|
-
const [query, setQuery] =
|
|
692
|
-
const [queryAudience, setQueryAudience] =
|
|
693
|
-
const [hits, setHits] =
|
|
694
|
-
const [searching, setSearching] =
|
|
995
|
+
const [draft, setDraft] = useState7(null);
|
|
996
|
+
const [saving, setSaving] = useState7(null);
|
|
997
|
+
const [message, setMessage] = useState7(null);
|
|
998
|
+
const [query, setQuery] = useState7("");
|
|
999
|
+
const [queryAudience, setQueryAudience] = useState7("all");
|
|
1000
|
+
const [hits, setHits] = useState7(null);
|
|
1001
|
+
const [searching, setSearching] = useState7(false);
|
|
695
1002
|
async function save() {
|
|
696
1003
|
if (!draft) return;
|
|
697
1004
|
setSaving("form");
|
|
@@ -732,34 +1039,34 @@ function KnowledgeBase() {
|
|
|
732
1039
|
setSearching(false);
|
|
733
1040
|
}
|
|
734
1041
|
}
|
|
735
|
-
return /* @__PURE__ */
|
|
736
|
-
/* @__PURE__ */
|
|
1042
|
+
return /* @__PURE__ */ jsxs7("div", { className: "dlf-stack", children: [
|
|
1043
|
+
/* @__PURE__ */ jsxs7(
|
|
737
1044
|
Section,
|
|
738
1045
|
{
|
|
739
1046
|
title: "Base de conhecimento",
|
|
740
1047
|
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.",
|
|
741
|
-
actions: !draft && /* @__PURE__ */
|
|
1048
|
+
actions: !draft && /* @__PURE__ */ jsx7(Button, { onClick: () => setDraft({ title: "", content: "", audience: "internal", tags: [] }), disabled: !!saving, children: "Novo documento" }),
|
|
742
1049
|
children: [
|
|
743
|
-
message && /* @__PURE__ */
|
|
744
|
-
docs.error && /* @__PURE__ */
|
|
745
|
-
docs.loading && !docs.data && /* @__PURE__ */
|
|
746
|
-
docs.data && !docs.data.length && !draft && /* @__PURE__ */
|
|
747
|
-
!!docs.data?.length && /* @__PURE__ */
|
|
748
|
-
/* @__PURE__ */
|
|
749
|
-
/* @__PURE__ */
|
|
750
|
-
/* @__PURE__ */
|
|
1050
|
+
message && /* @__PURE__ */ jsx7(Notice, { tone: message.tone, children: message.text }),
|
|
1051
|
+
docs.error && /* @__PURE__ */ jsx7(Notice, { tone: "error", children: docs.error }),
|
|
1052
|
+
docs.loading && !docs.data && /* @__PURE__ */ jsx7(Loading, {}),
|
|
1053
|
+
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." }),
|
|
1054
|
+
!!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: [
|
|
1055
|
+
/* @__PURE__ */ jsxs7("div", { style: { minWidth: 0 }, children: [
|
|
1056
|
+
/* @__PURE__ */ jsx7("p", { className: "dlf-item-title", children: doc.title }),
|
|
1057
|
+
/* @__PURE__ */ jsxs7("p", { className: "dlf-item-meta", children: [
|
|
751
1058
|
doc.content.length.toLocaleString(locale),
|
|
752
1059
|
" caracteres \xB7 atualizado em ",
|
|
753
|
-
/* @__PURE__ */
|
|
1060
|
+
/* @__PURE__ */ jsx7("time", { dateTime: doc.updatedAt, children: formatDateTime(doc.updatedAt, locale) })
|
|
754
1061
|
] })
|
|
755
1062
|
] }),
|
|
756
|
-
/* @__PURE__ */
|
|
757
|
-
doc.audience === "all" ? /* @__PURE__ */
|
|
758
|
-
/* @__PURE__ */
|
|
759
|
-
/* @__PURE__ */
|
|
1063
|
+
/* @__PURE__ */ jsxs7("div", { className: "dlf-actions", children: [
|
|
1064
|
+
doc.audience === "all" ? /* @__PURE__ */ jsx7(Badge, { tone: "accent", children: "Equipe e clientes" }) : /* @__PURE__ */ jsx7(Badge, { children: "S\xF3 a equipe" }),
|
|
1065
|
+
/* @__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" }),
|
|
1066
|
+
/* @__PURE__ */ jsx7(Button, { variant: "ghost", loading: saving === doc.id, disabled: !!saving, onClick: () => remove(doc), children: "Excluir" })
|
|
760
1067
|
] })
|
|
761
1068
|
] }) }, doc.id)) }),
|
|
762
|
-
draft && /* @__PURE__ */
|
|
1069
|
+
draft && /* @__PURE__ */ jsxs7(
|
|
763
1070
|
"form",
|
|
764
1071
|
{
|
|
765
1072
|
className: "dlf-form",
|
|
@@ -769,28 +1076,28 @@ function KnowledgeBase() {
|
|
|
769
1076
|
void save();
|
|
770
1077
|
},
|
|
771
1078
|
children: [
|
|
772
|
-
/* @__PURE__ */
|
|
773
|
-
/* @__PURE__ */
|
|
774
|
-
/* @__PURE__ */
|
|
775
|
-
/* @__PURE__ */
|
|
776
|
-
/* @__PURE__ */
|
|
777
|
-
/* @__PURE__ */
|
|
778
|
-
/* @__PURE__ */
|
|
1079
|
+
/* @__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 }) }) }),
|
|
1080
|
+
/* @__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 }) }) }),
|
|
1081
|
+
/* @__PURE__ */ jsxs7("fieldset", { className: "dlf-field", style: { border: 0, padding: 0, margin: 0 }, children: [
|
|
1082
|
+
/* @__PURE__ */ jsx7("legend", { className: "dlf-label", children: "Quem pode ler" }),
|
|
1083
|
+
/* @__PURE__ */ jsxs7("label", { className: "dlf-choice", children: [
|
|
1084
|
+
/* @__PURE__ */ jsx7("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "internal", onChange: () => setDraft({ ...draft, audience: "internal" }) }),
|
|
1085
|
+
/* @__PURE__ */ jsxs7("span", { children: [
|
|
779
1086
|
"S\xF3 a equipe ",
|
|
780
|
-
/* @__PURE__ */
|
|
1087
|
+
/* @__PURE__ */ jsx7("span", { className: "dlf-muted", children: "(o assistente do painel)" })
|
|
781
1088
|
] })
|
|
782
1089
|
] }),
|
|
783
|
-
/* @__PURE__ */
|
|
784
|
-
/* @__PURE__ */
|
|
785
|
-
/* @__PURE__ */
|
|
1090
|
+
/* @__PURE__ */ jsxs7("label", { className: "dlf-choice", children: [
|
|
1091
|
+
/* @__PURE__ */ jsx7("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "all", onChange: () => setDraft({ ...draft, audience: "all" }) }),
|
|
1092
|
+
/* @__PURE__ */ jsxs7("span", { children: [
|
|
786
1093
|
"Equipe e clientes ",
|
|
787
|
-
/* @__PURE__ */
|
|
1094
|
+
/* @__PURE__ */ jsx7("span", { className: "dlf-muted", children: "(o bot de atendimento tamb\xE9m usa nas respostas)" })
|
|
788
1095
|
] })
|
|
789
1096
|
] })
|
|
790
1097
|
] }),
|
|
791
|
-
/* @__PURE__ */
|
|
792
|
-
/* @__PURE__ */
|
|
793
|
-
/* @__PURE__ */
|
|
1098
|
+
/* @__PURE__ */ jsxs7("div", { className: "dlf-actions", children: [
|
|
1099
|
+
/* @__PURE__ */ jsx7(Button, { type: "submit", variant: "primary", loading: saving === "form", disabled: !draft.title.trim() || !draft.content.trim(), children: "Salvar documento" }),
|
|
1100
|
+
/* @__PURE__ */ jsx7(Button, { variant: "ghost", onClick: () => setDraft(null), children: "Cancelar" })
|
|
794
1101
|
] })
|
|
795
1102
|
]
|
|
796
1103
|
}
|
|
@@ -798,8 +1105,8 @@ function KnowledgeBase() {
|
|
|
798
1105
|
]
|
|
799
1106
|
}
|
|
800
1107
|
),
|
|
801
|
-
/* @__PURE__ */
|
|
802
|
-
/* @__PURE__ */
|
|
1108
|
+
/* @__PURE__ */ jsxs7(Section, { title: "Testar a busca", description: "Veja o que o assistente encontra para uma pergunta.", children: [
|
|
1109
|
+
/* @__PURE__ */ jsxs7(
|
|
803
1110
|
"form",
|
|
804
1111
|
{
|
|
805
1112
|
className: "dlf-row",
|
|
@@ -809,32 +1116,32 @@ function KnowledgeBase() {
|
|
|
809
1116
|
void search();
|
|
810
1117
|
},
|
|
811
1118
|
children: [
|
|
812
|
-
/* @__PURE__ */
|
|
813
|
-
/* @__PURE__ */
|
|
814
|
-
/* @__PURE__ */
|
|
815
|
-
/* @__PURE__ */
|
|
1119
|
+
/* @__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) }) }),
|
|
1120
|
+
/* @__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: [
|
|
1121
|
+
/* @__PURE__ */ jsx7("option", { value: "all", children: "O bot de atendimento veria" }),
|
|
1122
|
+
/* @__PURE__ */ jsx7("option", { value: "internal", children: "O assistente da equipe veria" })
|
|
816
1123
|
] }) }),
|
|
817
|
-
/* @__PURE__ */
|
|
1124
|
+
/* @__PURE__ */ jsx7("div", { children: /* @__PURE__ */ jsx7(Button, { type: "submit", loading: searching, disabled: !query.trim(), children: "Buscar" }) })
|
|
818
1125
|
]
|
|
819
1126
|
}
|
|
820
1127
|
),
|
|
821
|
-
hits && !hits.length && /* @__PURE__ */
|
|
822
|
-
!!hits?.length && /* @__PURE__ */
|
|
823
|
-
/* @__PURE__ */
|
|
824
|
-
/* @__PURE__ */
|
|
1128
|
+
hits && !hits.length && /* @__PURE__ */ jsx7(Empty, { title: "Nada encontrado", children: "Nesse caso o assistente diz que vai verificar, em vez de inventar." }),
|
|
1129
|
+
!!hits?.length && /* @__PURE__ */ jsx7("ul", { className: "dlf-list", "aria-live": "polite", children: hits.map((h) => /* @__PURE__ */ jsxs7("li", { className: "dlf-item", children: [
|
|
1130
|
+
/* @__PURE__ */ jsx7("p", { className: "dlf-item-title", children: h.title }),
|
|
1131
|
+
/* @__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 })
|
|
825
1132
|
] }, h.docId)) })
|
|
826
1133
|
] })
|
|
827
1134
|
] });
|
|
828
1135
|
}
|
|
829
1136
|
|
|
830
1137
|
// src/Memory.tsx
|
|
831
|
-
import { useState as
|
|
832
|
-
import { Fragment as
|
|
1138
|
+
import { useState as useState8 } from "react";
|
|
1139
|
+
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
833
1140
|
function FactList({ subject, emptyText }) {
|
|
834
1141
|
const { client, locale } = useStudio();
|
|
835
1142
|
const facts = useResource(() => client.facts(subject), [client, subject.type, subject.id]);
|
|
836
|
-
const [removing, setRemoving] =
|
|
837
|
-
const [error, setError] =
|
|
1143
|
+
const [removing, setRemoving] = useState8(null);
|
|
1144
|
+
const [error, setError] = useState8(null);
|
|
838
1145
|
async function forget(fact) {
|
|
839
1146
|
if (!window.confirm(`Esquecer \u201C${fact.text}\u201D? O assistente deixa de usar isso nas pr\xF3ximas conversas.`)) return;
|
|
840
1147
|
setRemoving(fact.id);
|
|
@@ -848,35 +1155,35 @@ function FactList({ subject, emptyText }) {
|
|
|
848
1155
|
setRemoving(null);
|
|
849
1156
|
}
|
|
850
1157
|
}
|
|
851
|
-
if (facts.error) return /* @__PURE__ */
|
|
852
|
-
if (!facts.data) return /* @__PURE__ */
|
|
853
|
-
if (!facts.data.length) return /* @__PURE__ */
|
|
854
|
-
return /* @__PURE__ */
|
|
855
|
-
error && /* @__PURE__ */
|
|
856
|
-
/* @__PURE__ */
|
|
857
|
-
/* @__PURE__ */
|
|
858
|
-
/* @__PURE__ */
|
|
859
|
-
/* @__PURE__ */
|
|
860
|
-
/* @__PURE__ */
|
|
1158
|
+
if (facts.error) return /* @__PURE__ */ jsx8(Notice, { tone: "error", children: facts.error });
|
|
1159
|
+
if (!facts.data) return /* @__PURE__ */ jsx8(Loading, {});
|
|
1160
|
+
if (!facts.data.length) return /* @__PURE__ */ jsx8(Empty, { title: "Nada guardado", children: emptyText });
|
|
1161
|
+
return /* @__PURE__ */ jsxs8(Fragment3, { children: [
|
|
1162
|
+
error && /* @__PURE__ */ jsx8(Notice, { tone: "error", children: error }),
|
|
1163
|
+
/* @__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: [
|
|
1164
|
+
/* @__PURE__ */ jsxs8("div", { style: { minWidth: 0 }, children: [
|
|
1165
|
+
/* @__PURE__ */ jsx8("p", { className: "dlf-item-title", style: { fontWeight: 400 }, children: f.text }),
|
|
1166
|
+
/* @__PURE__ */ jsxs8("p", { className: "dlf-item-meta", children: [
|
|
1167
|
+
/* @__PURE__ */ jsx8("time", { dateTime: f.createdAt, children: formatDateTime(f.createdAt, locale) }),
|
|
861
1168
|
f.createdBy?.name ? ` \xB7 por ${f.createdBy.name}` : f.createdBy?.type === "service" ? " \xB7 pelo bot" : ""
|
|
862
1169
|
] })
|
|
863
1170
|
] }),
|
|
864
|
-
/* @__PURE__ */
|
|
1171
|
+
/* @__PURE__ */ jsx8(Button, { variant: "ghost", loading: removing === f.id, disabled: !!removing, onClick: () => forget(f), "aria-label": `Esquecer: ${f.text}`, children: "Esquecer" })
|
|
865
1172
|
] }) }, f.id)) })
|
|
866
1173
|
] });
|
|
867
1174
|
}
|
|
868
1175
|
function MemoryBrowser() {
|
|
869
1176
|
const { client, labels, locale } = useStudio();
|
|
870
1177
|
const subjects = useResource(() => client.factSubjects(), [client]);
|
|
871
|
-
const [open, setOpen] =
|
|
1178
|
+
const [open, setOpen] = useState8(null);
|
|
872
1179
|
const typeLabel = (type) => labels.subjects?.[type] ?? type;
|
|
873
1180
|
if (open) {
|
|
874
|
-
return /* @__PURE__ */
|
|
1181
|
+
return /* @__PURE__ */ jsx8(
|
|
875
1182
|
Section,
|
|
876
1183
|
{
|
|
877
1184
|
title: open.label ?? open.id,
|
|
878
1185
|
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.`,
|
|
879
|
-
actions: /* @__PURE__ */
|
|
1186
|
+
actions: /* @__PURE__ */ jsx8(
|
|
880
1187
|
Button,
|
|
881
1188
|
{
|
|
882
1189
|
variant: "ghost",
|
|
@@ -887,40 +1194,40 @@ function MemoryBrowser() {
|
|
|
887
1194
|
children: "Voltar para a lista"
|
|
888
1195
|
}
|
|
889
1196
|
),
|
|
890
|
-
children: /* @__PURE__ */
|
|
1197
|
+
children: /* @__PURE__ */ jsx8(FactList, { subject: open, emptyText: "Tudo foi esquecido." })
|
|
891
1198
|
}
|
|
892
1199
|
);
|
|
893
1200
|
}
|
|
894
|
-
return /* @__PURE__ */
|
|
895
|
-
subjects.error && /* @__PURE__ */
|
|
896
|
-
subjects.loading && !subjects.data && /* @__PURE__ */
|
|
897
|
-
subjects.data && !subjects.data.length && /* @__PURE__ */
|
|
898
|
-
!!subjects.data?.length && /* @__PURE__ */
|
|
899
|
-
/* @__PURE__ */
|
|
900
|
-
/* @__PURE__ */
|
|
901
|
-
/* @__PURE__ */
|
|
902
|
-
/* @__PURE__ */
|
|
903
|
-
/* @__PURE__ */
|
|
1201
|
+
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: [
|
|
1202
|
+
subjects.error && /* @__PURE__ */ jsx8(Notice, { tone: "error", children: subjects.error }),
|
|
1203
|
+
subjects.loading && !subjects.data && /* @__PURE__ */ jsx8(Loading, {}),
|
|
1204
|
+
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." }),
|
|
1205
|
+
!!subjects.data?.length && /* @__PURE__ */ jsx8("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ jsxs8("table", { className: "dlf-table", children: [
|
|
1206
|
+
/* @__PURE__ */ jsx8("thead", { children: /* @__PURE__ */ jsxs8("tr", { children: [
|
|
1207
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", children: "Sobre" }),
|
|
1208
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", children: "Tipo" }),
|
|
1209
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", className: "dlf-num", children: "Fatos" }),
|
|
1210
|
+
/* @__PURE__ */ jsx8("th", { scope: "col", children: "\xDAltimo" })
|
|
904
1211
|
] }) }),
|
|
905
|
-
/* @__PURE__ */
|
|
906
|
-
/* @__PURE__ */
|
|
907
|
-
/* @__PURE__ */
|
|
908
|
-
/* @__PURE__ */
|
|
909
|
-
/* @__PURE__ */
|
|
1212
|
+
/* @__PURE__ */ jsx8("tbody", { children: subjects.data.map((s) => /* @__PURE__ */ jsxs8("tr", { children: [
|
|
1213
|
+
/* @__PURE__ */ jsx8("td", { children: /* @__PURE__ */ jsx8("button", { type: "button", className: "dlf-link-button", onClick: () => setOpen(s), children: s.label ?? s.id }) }),
|
|
1214
|
+
/* @__PURE__ */ jsx8("td", { children: typeLabel(s.type) }),
|
|
1215
|
+
/* @__PURE__ */ jsx8("td", { className: "dlf-num", children: s.count }),
|
|
1216
|
+
/* @__PURE__ */ jsx8("td", { children: /* @__PURE__ */ jsx8("time", { dateTime: s.lastAt, children: formatDateTime(s.lastAt, locale) }) })
|
|
910
1217
|
] }, `${s.type}:${s.id}`)) })
|
|
911
1218
|
] }) })
|
|
912
1219
|
] });
|
|
913
1220
|
}
|
|
914
1221
|
function MyMemory({ subject }) {
|
|
915
|
-
return /* @__PURE__ */
|
|
1222
|
+
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".' }) });
|
|
916
1223
|
}
|
|
917
1224
|
|
|
918
1225
|
// src/Studio.tsx
|
|
919
|
-
import { useState as
|
|
1226
|
+
import { useState as useState10 } from "react";
|
|
920
1227
|
|
|
921
1228
|
// src/Usage.tsx
|
|
922
|
-
import { useId as
|
|
923
|
-
import { Fragment as
|
|
1229
|
+
import { useId as useId6, useState as useState9 } from "react";
|
|
1230
|
+
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
924
1231
|
var periodRange = (period) => {
|
|
925
1232
|
const now = /* @__PURE__ */ new Date();
|
|
926
1233
|
const monthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
@@ -930,8 +1237,8 @@ var periodRange = (period) => {
|
|
|
930
1237
|
};
|
|
931
1238
|
function UsageReport() {
|
|
932
1239
|
const { client, labels, locale } = useStudio();
|
|
933
|
-
const ids =
|
|
934
|
-
const [period, setPeriod] =
|
|
1240
|
+
const ids = useId6();
|
|
1241
|
+
const [period, setPeriod] = useState9("month");
|
|
935
1242
|
const usage = useResource(() => client.usage(periodRange(period)), [client, period]);
|
|
936
1243
|
const data = usage.data;
|
|
937
1244
|
const money = (n) => formatMoney(n, data?.currency ?? null, locale);
|
|
@@ -939,41 +1246,41 @@ function UsageReport() {
|
|
|
939
1246
|
const channelLabel = (c) => labels.channels?.[c] ?? c;
|
|
940
1247
|
const maxDay = Math.max(...data?.byDay.map((d) => data.currency ? d.cost : d.inputTokens + d.outputTokens) ?? [0], 0);
|
|
941
1248
|
const used = data?.budget && period === "month" ? data.total.cost / data.budget.monthly : null;
|
|
942
|
-
return /* @__PURE__ */
|
|
1249
|
+
return /* @__PURE__ */ jsxs9(
|
|
943
1250
|
Section,
|
|
944
1251
|
{
|
|
945
1252
|
title: "Uso e custos",
|
|
946
1253
|
description: "Quanto o assistente, o bot e as automa\xE7\xF5es gastaram com IA.",
|
|
947
|
-
actions: /* @__PURE__ */
|
|
948
|
-
/* @__PURE__ */
|
|
949
|
-
/* @__PURE__ */
|
|
950
|
-
/* @__PURE__ */
|
|
1254
|
+
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: [
|
|
1255
|
+
/* @__PURE__ */ jsx9("option", { value: "month", children: "Este m\xEAs" }),
|
|
1256
|
+
/* @__PURE__ */ jsx9("option", { value: "last-month", children: "M\xEAs passado" }),
|
|
1257
|
+
/* @__PURE__ */ jsx9("option", { value: "7d", children: "\xDAltimos 7 dias" })
|
|
951
1258
|
] }) }),
|
|
952
1259
|
children: [
|
|
953
|
-
usage.error && /* @__PURE__ */
|
|
954
|
-
usage.loading && !data && /* @__PURE__ */
|
|
955
|
-
data && /* @__PURE__ */
|
|
956
|
-
/* @__PURE__ */
|
|
957
|
-
/* @__PURE__ */
|
|
958
|
-
/* @__PURE__ */
|
|
959
|
-
/* @__PURE__ */
|
|
1260
|
+
usage.error && /* @__PURE__ */ jsx9(Notice, { tone: "error", children: usage.error }),
|
|
1261
|
+
usage.loading && !data && /* @__PURE__ */ jsx9(Loading, {}),
|
|
1262
|
+
data && /* @__PURE__ */ jsxs9(Fragment4, { children: [
|
|
1263
|
+
/* @__PURE__ */ jsxs9("dl", { className: "dlf-stats", children: [
|
|
1264
|
+
/* @__PURE__ */ jsxs9("div", { className: "dlf-stat", children: [
|
|
1265
|
+
/* @__PURE__ */ jsx9("dt", { children: "Custo" }),
|
|
1266
|
+
/* @__PURE__ */ jsx9("dd", { children: data.currency ? money(data.total.cost) : "\u2014" })
|
|
960
1267
|
] }),
|
|
961
|
-
/* @__PURE__ */
|
|
962
|
-
/* @__PURE__ */
|
|
963
|
-
/* @__PURE__ */
|
|
1268
|
+
/* @__PURE__ */ jsxs9("div", { className: "dlf-stat", children: [
|
|
1269
|
+
/* @__PURE__ */ jsx9("dt", { children: "Conversas e tarefas" }),
|
|
1270
|
+
/* @__PURE__ */ jsx9("dd", { children: formatNumber(data.total.runs, locale) })
|
|
964
1271
|
] }),
|
|
965
|
-
/* @__PURE__ */
|
|
966
|
-
/* @__PURE__ */
|
|
967
|
-
/* @__PURE__ */
|
|
1272
|
+
/* @__PURE__ */ jsxs9("div", { className: "dlf-stat", children: [
|
|
1273
|
+
/* @__PURE__ */ jsx9("dt", { children: "Tokens" }),
|
|
1274
|
+
/* @__PURE__ */ jsx9("dd", { children: tokens(data.total) })
|
|
968
1275
|
] })
|
|
969
1276
|
] }),
|
|
970
|
-
!data.currency && /* @__PURE__ */
|
|
971
|
-
data.total.unpricedCalls > 0 && data.currency && /* @__PURE__ */
|
|
1277
|
+
!data.currency && /* @__PURE__ */ jsx9("p", { className: "dlf-muted", children: "Sem tabela de pre\xE7os configurada na aplica\xE7\xE3o: s\xF3 os tokens aparecem." }),
|
|
1278
|
+
data.total.unpricedCalls > 0 && data.currency && /* @__PURE__ */ jsxs9("p", { className: "dlf-muted", children: [
|
|
972
1279
|
formatNumber(data.total.unpricedCalls, locale),
|
|
973
1280
|
" chamadas usaram modelos sem pre\xE7o configurado e n\xE3o entram no custo."
|
|
974
1281
|
] }),
|
|
975
|
-
used !== null && data.budget && /* @__PURE__ */
|
|
976
|
-
/* @__PURE__ */
|
|
1282
|
+
used !== null && data.budget && /* @__PURE__ */ jsxs9("div", { className: "dlf-field", children: [
|
|
1283
|
+
/* @__PURE__ */ jsxs9("p", { className: "dlf-muted", id: `${ids}-limite`, children: [
|
|
977
1284
|
money(data.total.cost),
|
|
978
1285
|
" de ",
|
|
979
1286
|
money(data.budget.monthly),
|
|
@@ -982,7 +1289,7 @@ function UsageReport() {
|
|
|
982
1289
|
"%)",
|
|
983
1290
|
used >= 1 ? ". Limite atingido: o assistente est\xE1 parado at\xE9 o m\xEAs virar ou o limite subir." : ""
|
|
984
1291
|
] }),
|
|
985
|
-
/* @__PURE__ */
|
|
1292
|
+
/* @__PURE__ */ jsx9(
|
|
986
1293
|
"div",
|
|
987
1294
|
{
|
|
988
1295
|
className: used >= 1 ? "dlf-meter dlf-meter--over" : "dlf-meter",
|
|
@@ -991,38 +1298,38 @@ function UsageReport() {
|
|
|
991
1298
|
"aria-valuemin": 0,
|
|
992
1299
|
"aria-valuemax": 100,
|
|
993
1300
|
"aria-valuenow": Math.min(100, Math.round(used * 100)),
|
|
994
|
-
children: /* @__PURE__ */
|
|
1301
|
+
children: /* @__PURE__ */ jsx9("span", { style: { width: `${Math.min(100, used * 100)}%` } })
|
|
995
1302
|
}
|
|
996
1303
|
)
|
|
997
1304
|
] }),
|
|
998
|
-
!data.byDay.length ? /* @__PURE__ */
|
|
999
|
-
/* @__PURE__ */
|
|
1000
|
-
/* @__PURE__ */
|
|
1001
|
-
/* @__PURE__ */
|
|
1305
|
+
!data.byDay.length ? /* @__PURE__ */ jsx9(Empty, { title: "Nenhum uso no per\xEDodo" }) : /* @__PURE__ */ jsxs9(Fragment4, { children: [
|
|
1306
|
+
/* @__PURE__ */ jsxs9("div", { children: [
|
|
1307
|
+
/* @__PURE__ */ jsx9("h3", { className: "dlf-h3", style: { marginBottom: "0.5rem" }, children: "Por dia" }),
|
|
1308
|
+
/* @__PURE__ */ jsx9("div", { className: "dlf-bars", children: data.byDay.map((d) => {
|
|
1002
1309
|
const value = data.currency ? d.cost : d.inputTokens + d.outputTokens;
|
|
1003
|
-
return /* @__PURE__ */
|
|
1004
|
-
/* @__PURE__ */
|
|
1005
|
-
/* @__PURE__ */
|
|
1006
|
-
/* @__PURE__ */
|
|
1310
|
+
return /* @__PURE__ */ jsxs9("div", { style: { display: "contents" }, children: [
|
|
1311
|
+
/* @__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`)) }),
|
|
1312
|
+
/* @__PURE__ */ jsx9("span", { className: "dlf-bar", style: { width: `${maxDay ? value / maxDay * 100 : 0}%` }, "aria-hidden": true }),
|
|
1313
|
+
/* @__PURE__ */ jsx9("span", { className: "dlf-num", children: data.currency ? money(d.cost) : tokens(d) })
|
|
1007
1314
|
] }, d.day);
|
|
1008
1315
|
}) })
|
|
1009
1316
|
] }),
|
|
1010
1317
|
[
|
|
1011
1318
|
["Por canal", data.byChannel.map((c) => ({ key: c.channel, label: channelLabel(c.channel), t: c }))],
|
|
1012
1319
|
["Por modelo", data.byModel.map((m) => ({ key: m.model, label: m.model.slice(m.model.indexOf(":") + 1), t: m }))]
|
|
1013
|
-
].map(([title, rows]) => /* @__PURE__ */
|
|
1014
|
-
/* @__PURE__ */
|
|
1015
|
-
/* @__PURE__ */
|
|
1016
|
-
/* @__PURE__ */
|
|
1017
|
-
/* @__PURE__ */
|
|
1018
|
-
/* @__PURE__ */
|
|
1019
|
-
data.currency && /* @__PURE__ */
|
|
1320
|
+
].map(([title, rows]) => /* @__PURE__ */ jsx9("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ jsxs9("table", { className: "dlf-table", children: [
|
|
1321
|
+
/* @__PURE__ */ jsx9("caption", { className: "dlf-sr-only", children: title }),
|
|
1322
|
+
/* @__PURE__ */ jsx9("thead", { children: /* @__PURE__ */ jsxs9("tr", { children: [
|
|
1323
|
+
/* @__PURE__ */ jsx9("th", { scope: "col", children: title }),
|
|
1324
|
+
/* @__PURE__ */ jsx9("th", { scope: "col", className: "dlf-num", children: "Execu\xE7\xF5es" }),
|
|
1325
|
+
/* @__PURE__ */ jsx9("th", { scope: "col", className: "dlf-num", children: "Tokens" }),
|
|
1326
|
+
data.currency && /* @__PURE__ */ jsx9("th", { scope: "col", className: "dlf-num", children: "Custo" })
|
|
1020
1327
|
] }) }),
|
|
1021
|
-
/* @__PURE__ */
|
|
1022
|
-
/* @__PURE__ */
|
|
1023
|
-
/* @__PURE__ */
|
|
1024
|
-
/* @__PURE__ */
|
|
1025
|
-
data.currency && /* @__PURE__ */
|
|
1328
|
+
/* @__PURE__ */ jsx9("tbody", { children: rows.map((r) => /* @__PURE__ */ jsxs9("tr", { children: [
|
|
1329
|
+
/* @__PURE__ */ jsx9("td", { children: r.label }),
|
|
1330
|
+
/* @__PURE__ */ jsx9("td", { className: "dlf-num", children: formatNumber(r.t.runs, locale) }),
|
|
1331
|
+
/* @__PURE__ */ jsx9("td", { className: "dlf-num", children: tokens(r.t) }),
|
|
1332
|
+
data.currency && /* @__PURE__ */ jsx9("td", { className: "dlf-num", children: money(r.t.cost) })
|
|
1026
1333
|
] }, r.key)) })
|
|
1027
1334
|
] }) }, title))
|
|
1028
1335
|
] })
|
|
@@ -1033,7 +1340,7 @@ function UsageReport() {
|
|
|
1033
1340
|
}
|
|
1034
1341
|
|
|
1035
1342
|
// src/Studio.tsx
|
|
1036
|
-
import { jsx as
|
|
1343
|
+
import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1037
1344
|
var LABELS = {
|
|
1038
1345
|
approvals: "Aprova\xE7\xF5es",
|
|
1039
1346
|
behavior: "Regras",
|
|
@@ -1041,12 +1348,13 @@ var LABELS = {
|
|
|
1041
1348
|
knowledge: "Conhecimento",
|
|
1042
1349
|
memory: "Mem\xF3ria",
|
|
1043
1350
|
usage: "Custos",
|
|
1351
|
+
keys: "Modelo de IA",
|
|
1044
1352
|
audit: "Auditoria"
|
|
1045
1353
|
};
|
|
1046
1354
|
function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, currency, pendingApprovals, onPendingApprovalsChange }) {
|
|
1047
1355
|
const visible = sections ?? Object.keys(LABELS);
|
|
1048
|
-
const [own, setOwn] =
|
|
1049
|
-
const [pending, setPending] =
|
|
1356
|
+
const [own, setOwn] = useState10(defaultSection ?? visible[0]);
|
|
1357
|
+
const [pending, setPending] = useState10(pendingApprovals);
|
|
1050
1358
|
const current = section ?? own;
|
|
1051
1359
|
const select = (s) => {
|
|
1052
1360
|
setOwn(s);
|
|
@@ -1057,16 +1365,17 @@ function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, c
|
|
|
1057
1365
|
onPendingApprovalsChange?.(n);
|
|
1058
1366
|
};
|
|
1059
1367
|
const panels = {
|
|
1060
|
-
approvals: () => /* @__PURE__ */
|
|
1061
|
-
behavior: () => /* @__PURE__ */
|
|
1062
|
-
automations: () => /* @__PURE__ */
|
|
1063
|
-
knowledge: () => /* @__PURE__ */
|
|
1064
|
-
memory: () => /* @__PURE__ */
|
|
1065
|
-
usage: () => /* @__PURE__ */
|
|
1066
|
-
|
|
1368
|
+
approvals: () => /* @__PURE__ */ jsx10(ApprovalsInbox, { onCount }),
|
|
1369
|
+
behavior: () => /* @__PURE__ */ jsx10(BehaviorSettings, { currency: currency ?? null }),
|
|
1370
|
+
automations: () => /* @__PURE__ */ jsx10(AutomationsEditor, {}),
|
|
1371
|
+
knowledge: () => /* @__PURE__ */ jsx10(KnowledgeBase, {}),
|
|
1372
|
+
memory: () => /* @__PURE__ */ jsx10(MemoryBrowser, {}),
|
|
1373
|
+
usage: () => /* @__PURE__ */ jsx10(UsageReport, {}),
|
|
1374
|
+
keys: () => /* @__PURE__ */ jsx10(ModelSettings, {}),
|
|
1375
|
+
audit: () => /* @__PURE__ */ jsx10(AuditLog, {})
|
|
1067
1376
|
};
|
|
1068
|
-
return /* @__PURE__ */
|
|
1069
|
-
/* @__PURE__ */
|
|
1377
|
+
return /* @__PURE__ */ jsxs10("div", { className: "dlf dlf-studio", children: [
|
|
1378
|
+
/* @__PURE__ */ jsx10(
|
|
1070
1379
|
Tabs,
|
|
1071
1380
|
{
|
|
1072
1381
|
label: "\xC1reas do assistente de IA",
|
|
@@ -1075,12 +1384,12 @@ function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, c
|
|
|
1075
1384
|
tabs: visible.map((id) => ({ id, label: LABELS[id], ...id === "approvals" ? { count: pendingApprovals ?? pending ?? 0 } : {} }))
|
|
1076
1385
|
}
|
|
1077
1386
|
),
|
|
1078
|
-
/* @__PURE__ */
|
|
1387
|
+
/* @__PURE__ */ jsx10("div", { role: "tabpanel", id: `dlf-panel-${current}`, "aria-labelledby": `dlf-tab-${current}`, tabIndex: 0, style: { outlineOffset: 4 }, children: panels[current]() })
|
|
1079
1388
|
] });
|
|
1080
1389
|
}
|
|
1081
1390
|
|
|
1082
1391
|
// src/index.tsx
|
|
1083
|
-
import { jsx as
|
|
1392
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1084
1393
|
function StudioProvider({ children, endpoint, headers, fetch: fetch2, labels, locale = "pt-BR", navigate }) {
|
|
1085
1394
|
const client = useMemo(
|
|
1086
1395
|
() => createStudioClient({ ...endpoint ? { endpoint } : {}, ...headers ? { headers } : {}, ...fetch2 ? { fetch: fetch2 } : {} }),
|
|
@@ -1088,7 +1397,7 @@ function StudioProvider({ children, endpoint, headers, fetch: fetch2, labels, lo
|
|
|
1088
1397
|
[endpoint]
|
|
1089
1398
|
);
|
|
1090
1399
|
const value = useMemo(() => ({ client, labels: labels ?? {}, locale, ...navigate ? { navigate } : {} }), [client, labels, locale, navigate]);
|
|
1091
|
-
return /* @__PURE__ */
|
|
1400
|
+
return /* @__PURE__ */ jsx11(StudioContextProvider, { value, children });
|
|
1092
1401
|
}
|
|
1093
1402
|
export {
|
|
1094
1403
|
ApprovalsInbox,
|
|
@@ -1098,7 +1407,9 @@ export {
|
|
|
1098
1407
|
DolfinhosStudio,
|
|
1099
1408
|
KnowledgeBase,
|
|
1100
1409
|
MemoryBrowser,
|
|
1410
|
+
ModelSettings,
|
|
1101
1411
|
MyMemory,
|
|
1412
|
+
ProviderKeys,
|
|
1102
1413
|
StudioError,
|
|
1103
1414
|
StudioProvider,
|
|
1104
1415
|
UsageReport,
|