@dolfinhos/studio 0.1.0 → 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/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  KnowledgeBase: () => KnowledgeBase,
30
30
  MemoryBrowser: () => MemoryBrowser,
31
31
  MyMemory: () => MyMemory,
32
+ ProviderKeys: () => ProviderKeys,
32
33
  StudioError: () => StudioError,
33
34
  StudioProvider: () => StudioProvider,
34
35
  UsageReport: () => UsageReport,
@@ -36,7 +37,7 @@ __export(index_exports, {
36
37
  useStudio: () => useStudio
37
38
  });
38
39
  module.exports = __toCommonJS(index_exports);
39
- var import_react11 = require("react");
40
+ var import_react12 = require("react");
40
41
 
41
42
  // src/api.ts
42
43
  var import_react = require("react");
@@ -98,7 +99,10 @@ function createStudioClient(options = {}) {
98
99
  searchKnowledge: (query, audience) => request("GET", `/knowledge/search${q({ q: query, audience })}`),
99
100
  factSubjects: (type) => request("GET", `/facts${q({ type })}`),
100
101
  facts: (subject) => request("GET", `/facts${q({ type: subject.type, id: subject.id })}`),
101
- forget: (id) => request("DELETE", `/facts/${encodeURIComponent(id)}`)
102
+ forget: (id) => request("DELETE", `/facts/${encodeURIComponent(id)}`),
103
+ credentials: () => request("GET", "/credentials"),
104
+ saveCredential: (name, value) => request("PUT", `/credentials/${encodeURIComponent(name)}`, { value }),
105
+ removeCredential: (name) => request("DELETE", `/credentials/${encodeURIComponent(name)}`)
102
106
  };
103
107
  }
104
108
  var StudioContext = (0, import_react.createContext)(null);
@@ -713,20 +717,131 @@ function BehaviorSettings({ currency }) {
713
717
  ] });
714
718
  }
715
719
 
716
- // src/Knowledge.tsx
720
+ // src/Keys.tsx
717
721
  var import_react7 = require("react");
718
722
  var import_jsx_runtime6 = require("react/jsx-runtime");
723
+ function ProviderKey({ provider, onChanged }) {
724
+ const { client, locale } = useStudio();
725
+ const id = (0, import_react7.useId)();
726
+ const [editing, setEditing] = (0, import_react7.useState)(!provider.configured);
727
+ const [value, setValue] = (0, import_react7.useState)("");
728
+ const [busy, setBusy] = (0, import_react7.useState)(null);
729
+ const [message, setMessage] = (0, import_react7.useState)(null);
730
+ async function save() {
731
+ setBusy("save");
732
+ setMessage(null);
733
+ try {
734
+ await client.saveCredential(provider.name, value.trim());
735
+ setValue("");
736
+ setEditing(false);
737
+ setMessage({ tone: "success", text: "Chave testada e salva. A partir de agora o uso de IA desta empresa vai para esta conta." });
738
+ await onChanged();
739
+ } catch (e) {
740
+ setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
741
+ } finally {
742
+ setBusy(null);
743
+ }
744
+ }
745
+ async function remove() {
746
+ if (!window.confirm(`Remover a chave da ${provider.label}? O assistente e o bot deixam de usar esta conta.${provider.whenMissing ? ` ${provider.whenMissing}` : ""}`)) return;
747
+ setBusy("remove");
748
+ setMessage(null);
749
+ try {
750
+ await client.removeCredential(provider.name);
751
+ setEditing(true);
752
+ setMessage({ tone: "success", text: "Chave removida." });
753
+ await onChanged();
754
+ } catch (e) {
755
+ setMessage({ tone: "error", text: e instanceof Error ? e.message : String(e) });
756
+ } finally {
757
+ setBusy(null);
758
+ }
759
+ }
760
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "dlf-item", children: [
761
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-item-row", children: [
762
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { minWidth: 0 }, children: [
763
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dlf-item-title", children: provider.label }),
764
+ provider.configured && provider.updatedAt ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "dlf-item-meta", children: [
765
+ "Chave terminada em ",
766
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { translate: "no", style: { fontVariantNumeric: "tabular-nums" }, children: [
767
+ "\u2026",
768
+ provider.last4
769
+ ] }),
770
+ " \xB7 salva em",
771
+ " ",
772
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: provider.updatedAt, children: formatDateTime(provider.updatedAt, locale) })
773
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
774
+ provider.description && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dlf-item-meta", children: provider.description }),
775
+ provider.whenMissing && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dlf-item-meta", children: provider.whenMissing })
776
+ ] })
777
+ ] }),
778
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-actions", children: [
779
+ provider.configured ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "success", children: "Configurada" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { children: "Sem chave" }),
780
+ provider.configured && !editing && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
781
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", disabled: !!busy, onClick: () => setEditing(true), children: "Trocar" }),
782
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", loading: busy === "remove", disabled: !!busy, onClick: remove, children: "Remover" })
783
+ ] })
784
+ ] })
785
+ ] }),
786
+ message && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Notice, { tone: message.tone, children: message.text }),
787
+ editing && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
788
+ "form",
789
+ {
790
+ className: "dlf-field",
791
+ style: { gap: "0.75rem", maxWidth: "32rem" },
792
+ onSubmit: (e) => {
793
+ e.preventDefault();
794
+ void save();
795
+ },
796
+ children: [
797
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(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__ */ (0, import_jsx_runtime6.jsx)(
798
+ "input",
799
+ {
800
+ id: `${id}-chave`,
801
+ className: "dlf-input",
802
+ type: "password",
803
+ autoComplete: "off",
804
+ spellCheck: false,
805
+ maxLength: 500,
806
+ placeholder: "sk-\u2026",
807
+ value,
808
+ onChange: (e) => setValue(e.target.value)
809
+ }
810
+ ) }),
811
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-actions", children: [
812
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { type: "submit", variant: "primary", loading: busy === "save", disabled: value.trim().length < 8, children: "Testar e salvar" }),
813
+ provider.configured && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", onClick: () => setEditing(false), children: "Cancelar" })
814
+ ] })
815
+ ]
816
+ }
817
+ )
818
+ ] });
819
+ }
820
+ function ProviderKeys() {
821
+ const { client } = useStudio();
822
+ const list = useResource(() => client.credentials(), [client]);
823
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(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: [
824
+ list.error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Notice, { tone: "error", children: list.error }),
825
+ list.loading && !list.data && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Loading, {}),
826
+ list.data && !list.data.length && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Empty, { title: "A aplica\xE7\xE3o n\xE3o usa chaves por empresa" }),
827
+ !!list.data?.length && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "dlf-list", children: list.data.map((p) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ProviderKey, { provider: p, onChanged: list.reload }, p.name)) })
828
+ ] });
829
+ }
830
+
831
+ // src/Knowledge.tsx
832
+ var import_react8 = require("react");
833
+ var import_jsx_runtime7 = require("react/jsx-runtime");
719
834
  function KnowledgeBase() {
720
835
  const { client, locale } = useStudio();
721
- const ids = (0, import_react7.useId)();
836
+ const ids = (0, import_react8.useId)();
722
837
  const docs = useResource(() => client.knowledge(), [client]);
723
- const [draft, setDraft] = (0, import_react7.useState)(null);
724
- const [saving, setSaving] = (0, import_react7.useState)(null);
725
- const [message, setMessage] = (0, import_react7.useState)(null);
726
- const [query, setQuery] = (0, import_react7.useState)("");
727
- const [queryAudience, setQueryAudience] = (0, import_react7.useState)("all");
728
- const [hits, setHits] = (0, import_react7.useState)(null);
729
- const [searching, setSearching] = (0, import_react7.useState)(false);
838
+ const [draft, setDraft] = (0, import_react8.useState)(null);
839
+ const [saving, setSaving] = (0, import_react8.useState)(null);
840
+ const [message, setMessage] = (0, import_react8.useState)(null);
841
+ const [query, setQuery] = (0, import_react8.useState)("");
842
+ const [queryAudience, setQueryAudience] = (0, import_react8.useState)("all");
843
+ const [hits, setHits] = (0, import_react8.useState)(null);
844
+ const [searching, setSearching] = (0, import_react8.useState)(false);
730
845
  async function save() {
731
846
  if (!draft) return;
732
847
  setSaving("form");
@@ -767,34 +882,34 @@ function KnowledgeBase() {
767
882
  setSearching(false);
768
883
  }
769
884
  }
770
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-stack", children: [
771
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
885
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dlf-stack", children: [
886
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
772
887
  Section,
773
888
  {
774
889
  title: "Base de conhecimento",
775
890
  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.",
776
- actions: !draft && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { onClick: () => setDraft({ title: "", content: "", audience: "internal", tags: [] }), disabled: !!saving, children: "Novo documento" }),
891
+ actions: !draft && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { onClick: () => setDraft({ title: "", content: "", audience: "internal", tags: [] }), disabled: !!saving, children: "Novo documento" }),
777
892
  children: [
778
- message && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Notice, { tone: message.tone, children: message.text }),
779
- docs.error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Notice, { tone: "error", children: docs.error }),
780
- docs.loading && !docs.data && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Loading, {}),
781
- docs.data && !docs.data.length && !draft && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Empty, { title: "Nenhum documento", children: "Comece pelas perguntas que os clientes mais fazem e pela pol\xEDtica de trocas e pagamentos." }),
782
- !!docs.data?.length && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "dlf-list", children: docs.data.map((doc) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("li", { className: "dlf-item", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-item-row", children: [
783
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { minWidth: 0 }, children: [
784
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dlf-item-title", children: doc.title }),
785
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "dlf-item-meta", children: [
893
+ message && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: message.tone, children: message.text }),
894
+ docs.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: "error", children: docs.error }),
895
+ docs.loading && !docs.data && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Loading, {}),
896
+ docs.data && !docs.data.length && !draft && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Empty, { title: "Nenhum documento", children: "Comece pelas perguntas que os clientes mais fazem e pela pol\xEDtica de trocas e pagamentos." }),
897
+ !!docs.data?.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "dlf-list", children: docs.data.map((doc) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { className: "dlf-item", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dlf-item-row", children: [
898
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { minWidth: 0 }, children: [
899
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dlf-item-title", children: doc.title }),
900
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "dlf-item-meta", children: [
786
901
  doc.content.length.toLocaleString(locale),
787
902
  " caracteres \xB7 atualizado em ",
788
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: doc.updatedAt, children: formatDateTime(doc.updatedAt, locale) })
903
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: doc.updatedAt, children: formatDateTime(doc.updatedAt, locale) })
789
904
  ] })
790
905
  ] }),
791
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-actions", children: [
792
- doc.audience === "all" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "accent", children: "Equipe e clientes" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { children: "S\xF3 a equipe" }),
793
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", disabled: !!saving, onClick: () => setDraft({ id: doc.id, title: doc.title, content: doc.content, audience: doc.audience, tags: doc.tags }), children: "Editar" }),
794
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", loading: saving === doc.id, disabled: !!saving, onClick: () => remove(doc), children: "Excluir" })
906
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dlf-actions", children: [
907
+ doc.audience === "all" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: "accent", children: "Equipe e clientes" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { children: "S\xF3 a equipe" }),
908
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", disabled: !!saving, onClick: () => setDraft({ id: doc.id, title: doc.title, content: doc.content, audience: doc.audience, tags: doc.tags }), children: "Editar" }),
909
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", loading: saving === doc.id, disabled: !!saving, onClick: () => remove(doc), children: "Excluir" })
795
910
  ] })
796
911
  ] }) }, doc.id)) }),
797
- draft && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
912
+ draft && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
798
913
  "form",
799
914
  {
800
915
  className: "dlf-form",
@@ -804,28 +919,28 @@ function KnowledgeBase() {
804
919
  void save();
805
920
  },
806
921
  children: [
807
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Field, { label: "T\xEDtulo", htmlFor: `${ids}-titulo`, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("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 }) }) }),
808
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Field, { label: "Conte\xFAdo", htmlFor: `${ids}-conteudo`, hint: "Texto simples. Separe assuntos em par\xE1grafos: a busca devolve o trecho mais relevante.", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("textarea", { id: `${ids}-conteudo`, className: "dlf-textarea", required: true, rows: 12, maxLength: 1e5, value: draft.content, onChange: (e) => setDraft({ ...draft, content: e.target.value }) }) }),
809
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("fieldset", { className: "dlf-field", style: { border: 0, padding: 0, margin: 0 }, children: [
810
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("legend", { className: "dlf-label", children: "Quem pode ler" }),
811
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "dlf-choice", children: [
812
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "internal", onChange: () => setDraft({ ...draft, audience: "internal" }) }),
813
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
922
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "T\xEDtulo", htmlFor: `${ids}-titulo`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("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 }) }) }),
923
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "Conte\xFAdo", htmlFor: `${ids}-conteudo`, hint: "Texto simples. Separe assuntos em par\xE1grafos: a busca devolve o trecho mais relevante.", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("textarea", { id: `${ids}-conteudo`, className: "dlf-textarea", required: true, rows: 12, maxLength: 1e5, value: draft.content, onChange: (e) => setDraft({ ...draft, content: e.target.value }) }) }),
924
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("fieldset", { className: "dlf-field", style: { border: 0, padding: 0, margin: 0 }, children: [
925
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("legend", { className: "dlf-label", children: "Quem pode ler" }),
926
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "dlf-choice", children: [
927
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "internal", onChange: () => setDraft({ ...draft, audience: "internal" }) }),
928
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
814
929
  "S\xF3 a equipe ",
815
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "dlf-muted", children: "(o assistente do painel)" })
930
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dlf-muted", children: "(o assistente do painel)" })
816
931
  ] })
817
932
  ] }),
818
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "dlf-choice", children: [
819
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "all", onChange: () => setDraft({ ...draft, audience: "all" }) }),
820
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
933
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "dlf-choice", children: [
934
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("input", { type: "radio", name: `${ids}-publico`, checked: draft.audience === "all", onChange: () => setDraft({ ...draft, audience: "all" }) }),
935
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
821
936
  "Equipe e clientes ",
822
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "dlf-muted", children: "(o bot de atendimento tamb\xE9m usa nas respostas)" })
937
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dlf-muted", children: "(o bot de atendimento tamb\xE9m usa nas respostas)" })
823
938
  ] })
824
939
  ] })
825
940
  ] }),
826
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dlf-actions", children: [
827
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { type: "submit", variant: "primary", loading: saving === "form", disabled: !draft.title.trim() || !draft.content.trim(), children: "Salvar documento" }),
828
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", onClick: () => setDraft(null), children: "Cancelar" })
941
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dlf-actions", children: [
942
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { type: "submit", variant: "primary", loading: saving === "form", disabled: !draft.title.trim() || !draft.content.trim(), children: "Salvar documento" }),
943
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", onClick: () => setDraft(null), children: "Cancelar" })
829
944
  ] })
830
945
  ]
831
946
  }
@@ -833,8 +948,8 @@ function KnowledgeBase() {
833
948
  ]
834
949
  }
835
950
  ),
836
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Section, { title: "Testar a busca", description: "Veja o que o assistente encontra para uma pergunta.", children: [
837
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
951
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Section, { title: "Testar a busca", description: "Veja o que o assistente encontra para uma pergunta.", children: [
952
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
838
953
  "form",
839
954
  {
840
955
  className: "dlf-row",
@@ -844,32 +959,32 @@ function KnowledgeBase() {
844
959
  void search();
845
960
  },
846
961
  children: [
847
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Field, { label: "Pergunta", htmlFor: `${ids}-busca`, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("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) }) }),
848
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Field, { label: "Como", htmlFor: `${ids}-como`, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("select", { id: `${ids}-como`, className: "dlf-select", value: queryAudience, onChange: (e) => setQueryAudience(e.target.value), children: [
849
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "all", children: "O bot de atendimento veria" }),
850
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "internal", children: "O assistente da equipe veria" })
962
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "Pergunta", htmlFor: `${ids}-busca`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("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) }) }),
963
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "Como", htmlFor: `${ids}-como`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("select", { id: `${ids}-como`, className: "dlf-select", value: queryAudience, onChange: (e) => setQueryAudience(e.target.value), children: [
964
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "all", children: "O bot de atendimento veria" }),
965
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "internal", children: "O assistente da equipe veria" })
851
966
  ] }) }),
852
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { type: "submit", loading: searching, disabled: !query.trim(), children: "Buscar" }) })
967
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { type: "submit", loading: searching, disabled: !query.trim(), children: "Buscar" }) })
853
968
  ]
854
969
  }
855
970
  ),
856
- hits && !hits.length && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Empty, { title: "Nada encontrado", children: "Nesse caso o assistente diz que vai verificar, em vez de inventar." }),
857
- !!hits?.length && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "dlf-list", "aria-live": "polite", children: hits.map((h) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "dlf-item", children: [
858
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dlf-item-title", children: h.title }),
859
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dlf-item-meta dlf-measure", style: { whiteSpace: "pre-line" }, children: h.excerpt.length > 600 ? `${h.excerpt.slice(0, 600)}\u2026` : h.excerpt })
971
+ hits && !hits.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Empty, { title: "Nada encontrado", children: "Nesse caso o assistente diz que vai verificar, em vez de inventar." }),
972
+ !!hits?.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "dlf-list", "aria-live": "polite", children: hits.map((h) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { className: "dlf-item", children: [
973
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dlf-item-title", children: h.title }),
974
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dlf-item-meta dlf-measure", style: { whiteSpace: "pre-line" }, children: h.excerpt.length > 600 ? `${h.excerpt.slice(0, 600)}\u2026` : h.excerpt })
860
975
  ] }, h.docId)) })
861
976
  ] })
862
977
  ] });
863
978
  }
864
979
 
865
980
  // src/Memory.tsx
866
- var import_react8 = require("react");
867
- var import_jsx_runtime7 = require("react/jsx-runtime");
981
+ var import_react9 = require("react");
982
+ var import_jsx_runtime8 = require("react/jsx-runtime");
868
983
  function FactList({ subject, emptyText }) {
869
984
  const { client, locale } = useStudio();
870
985
  const facts = useResource(() => client.facts(subject), [client, subject.type, subject.id]);
871
- const [removing, setRemoving] = (0, import_react8.useState)(null);
872
- const [error, setError] = (0, import_react8.useState)(null);
986
+ const [removing, setRemoving] = (0, import_react9.useState)(null);
987
+ const [error, setError] = (0, import_react9.useState)(null);
873
988
  async function forget(fact) {
874
989
  if (!window.confirm(`Esquecer \u201C${fact.text}\u201D? O assistente deixa de usar isso nas pr\xF3ximas conversas.`)) return;
875
990
  setRemoving(fact.id);
@@ -883,35 +998,35 @@ function FactList({ subject, emptyText }) {
883
998
  setRemoving(null);
884
999
  }
885
1000
  }
886
- if (facts.error) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: "error", children: facts.error });
887
- if (!facts.data) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Loading, {});
888
- if (!facts.data.length) return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Empty, { title: "Nada guardado", children: emptyText });
889
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
890
- error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: "error", children: error }),
891
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "dlf-list", children: facts.data.map((f) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("li", { className: "dlf-item", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dlf-item-row", children: [
892
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { minWidth: 0 }, children: [
893
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dlf-item-title", style: { fontWeight: 400 }, children: f.text }),
894
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "dlf-item-meta", children: [
895
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: f.createdAt, children: formatDateTime(f.createdAt, locale) }),
1001
+ if (facts.error) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Notice, { tone: "error", children: facts.error });
1002
+ if (!facts.data) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Loading, {});
1003
+ if (!facts.data.length) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Empty, { title: "Nada guardado", children: emptyText });
1004
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1005
+ error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Notice, { tone: "error", children: error }),
1006
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "dlf-list", children: facts.data.map((f) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("li", { className: "dlf-item", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dlf-item-row", children: [
1007
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { minWidth: 0 }, children: [
1008
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "dlf-item-title", style: { fontWeight: 400 }, children: f.text }),
1009
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "dlf-item-meta", children: [
1010
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: f.createdAt, children: formatDateTime(f.createdAt, locale) }),
896
1011
  f.createdBy?.name ? ` \xB7 por ${f.createdBy.name}` : f.createdBy?.type === "service" ? " \xB7 pelo bot" : ""
897
1012
  ] })
898
1013
  ] }),
899
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", loading: removing === f.id, disabled: !!removing, onClick: () => forget(f), "aria-label": `Esquecer: ${f.text}`, children: "Esquecer" })
1014
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Button, { variant: "ghost", loading: removing === f.id, disabled: !!removing, onClick: () => forget(f), "aria-label": `Esquecer: ${f.text}`, children: "Esquecer" })
900
1015
  ] }) }, f.id)) })
901
1016
  ] });
902
1017
  }
903
1018
  function MemoryBrowser() {
904
1019
  const { client, labels, locale } = useStudio();
905
1020
  const subjects = useResource(() => client.factSubjects(), [client]);
906
- const [open, setOpen] = (0, import_react8.useState)(null);
1021
+ const [open, setOpen] = (0, import_react9.useState)(null);
907
1022
  const typeLabel = (type) => labels.subjects?.[type] ?? type;
908
1023
  if (open) {
909
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1024
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
910
1025
  Section,
911
1026
  {
912
1027
  title: open.label ?? open.id,
913
1028
  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.`,
914
- actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1029
+ actions: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
915
1030
  Button,
916
1031
  {
917
1032
  variant: "ghost",
@@ -922,40 +1037,40 @@ function MemoryBrowser() {
922
1037
  children: "Voltar para a lista"
923
1038
  }
924
1039
  ),
925
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FactList, { subject: open, emptyText: "Tudo foi esquecido." })
1040
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FactList, { subject: open, emptyText: "Tudo foi esquecido." })
926
1041
  }
927
1042
  );
928
1043
  }
929
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Section, { title: "Mem\xF3ria", description: "O que o assistente e o bot guardaram sobre clientes e pessoas da equipe, de conversas anteriores.", children: [
930
- subjects.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: "error", children: subjects.error }),
931
- subjects.loading && !subjects.data && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Loading, {}),
932
- subjects.data && !subjects.data.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(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." }),
933
- !!subjects.data?.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("table", { className: "dlf-table", children: [
934
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("tr", { children: [
935
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { scope: "col", children: "Sobre" }),
936
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { scope: "col", children: "Tipo" }),
937
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { scope: "col", className: "dlf-num", children: "Fatos" }),
938
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { scope: "col", children: "\xDAltimo" })
1044
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Section, { title: "Mem\xF3ria", description: "O que o assistente e o bot guardaram sobre clientes e pessoas da equipe, de conversas anteriores.", children: [
1045
+ subjects.error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Notice, { tone: "error", children: subjects.error }),
1046
+ subjects.loading && !subjects.data && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Loading, {}),
1047
+ subjects.data && !subjects.data.length && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(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." }),
1048
+ !!subjects.data?.length && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("table", { className: "dlf-table", children: [
1049
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("tr", { children: [
1050
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", children: "Sobre" }),
1051
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", children: "Tipo" }),
1052
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", className: "dlf-num", children: "Fatos" }),
1053
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", children: "\xDAltimo" })
939
1054
  ] }) }),
940
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tbody", { children: subjects.data.map((s) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("tr", { children: [
941
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "dlf-link-button", onClick: () => setOpen(s), children: s.label ?? s.id }) }),
942
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { children: typeLabel(s.type) }),
943
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { className: "dlf-num", children: s.count }),
944
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("time", { dateTime: s.lastAt, children: formatDateTime(s.lastAt, locale) }) })
1055
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tbody", { children: subjects.data.map((s) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("tr", { children: [
1056
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "dlf-link-button", onClick: () => setOpen(s), children: s.label ?? s.id }) }),
1057
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { children: typeLabel(s.type) }),
1058
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { className: "dlf-num", children: s.count }),
1059
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("time", { dateTime: s.lastAt, children: formatDateTime(s.lastAt, locale) }) })
945
1060
  ] }, `${s.type}:${s.id}`)) })
946
1061
  ] }) })
947
1062
  ] });
948
1063
  }
949
1064
  function MyMemory({ subject }) {
950
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(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__ */ (0, import_jsx_runtime7.jsx)(FactList, { subject, emptyText: 'Pe\xE7a ao assistente, por exemplo: "lembre que prefiro respostas curtas".' }) });
1065
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(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__ */ (0, import_jsx_runtime8.jsx)(FactList, { subject, emptyText: 'Pe\xE7a ao assistente, por exemplo: "lembre que prefiro respostas curtas".' }) });
951
1066
  }
952
1067
 
953
1068
  // src/Studio.tsx
954
- var import_react10 = require("react");
1069
+ var import_react11 = require("react");
955
1070
 
956
1071
  // src/Usage.tsx
957
- var import_react9 = require("react");
958
- var import_jsx_runtime8 = require("react/jsx-runtime");
1072
+ var import_react10 = require("react");
1073
+ var import_jsx_runtime9 = require("react/jsx-runtime");
959
1074
  var periodRange = (period) => {
960
1075
  const now = /* @__PURE__ */ new Date();
961
1076
  const monthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
@@ -965,8 +1080,8 @@ var periodRange = (period) => {
965
1080
  };
966
1081
  function UsageReport() {
967
1082
  const { client, labels, locale } = useStudio();
968
- const ids = (0, import_react9.useId)();
969
- const [period, setPeriod] = (0, import_react9.useState)("month");
1083
+ const ids = (0, import_react10.useId)();
1084
+ const [period, setPeriod] = (0, import_react10.useState)("month");
970
1085
  const usage = useResource(() => client.usage(periodRange(period)), [client, period]);
971
1086
  const data = usage.data;
972
1087
  const money = (n) => formatMoney(n, data?.currency ?? null, locale);
@@ -974,41 +1089,41 @@ function UsageReport() {
974
1089
  const channelLabel = (c) => labels.channels?.[c] ?? c;
975
1090
  const maxDay = Math.max(...data?.byDay.map((d) => data.currency ? d.cost : d.inputTokens + d.outputTokens) ?? [0], 0);
976
1091
  const used = data?.budget && period === "month" ? data.total.cost / data.budget.monthly : null;
977
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1092
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
978
1093
  Section,
979
1094
  {
980
1095
  title: "Uso e custos",
981
1096
  description: "Quanto o assistente, o bot e as automa\xE7\xF5es gastaram com IA.",
982
- actions: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Field, { label: "Per\xEDodo", htmlFor: `${ids}-periodo`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("select", { id: `${ids}-periodo`, className: "dlf-select", value: period, onChange: (e) => setPeriod(e.target.value), children: [
983
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("option", { value: "month", children: "Este m\xEAs" }),
984
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("option", { value: "last-month", children: "M\xEAs passado" }),
985
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("option", { value: "7d", children: "\xDAltimos 7 dias" })
1097
+ actions: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Field, { label: "Per\xEDodo", htmlFor: `${ids}-periodo`, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("select", { id: `${ids}-periodo`, className: "dlf-select", value: period, onChange: (e) => setPeriod(e.target.value), children: [
1098
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: "month", children: "Este m\xEAs" }),
1099
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: "last-month", children: "M\xEAs passado" }),
1100
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("option", { value: "7d", children: "\xDAltimos 7 dias" })
986
1101
  ] }) }),
987
1102
  children: [
988
- usage.error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Notice, { tone: "error", children: usage.error }),
989
- usage.loading && !data && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Loading, {}),
990
- data && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
991
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("dl", { className: "dlf-stats", children: [
992
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dlf-stat", children: [
993
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("dt", { children: "Custo" }),
994
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("dd", { children: data.currency ? money(data.total.cost) : "\u2014" })
1103
+ usage.error && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Notice, { tone: "error", children: usage.error }),
1104
+ usage.loading && !data && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Loading, {}),
1105
+ data && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1106
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("dl", { className: "dlf-stats", children: [
1107
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "dlf-stat", children: [
1108
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("dt", { children: "Custo" }),
1109
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("dd", { children: data.currency ? money(data.total.cost) : "\u2014" })
995
1110
  ] }),
996
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dlf-stat", children: [
997
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("dt", { children: "Conversas e tarefas" }),
998
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("dd", { children: formatNumber(data.total.runs, locale) })
1111
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "dlf-stat", children: [
1112
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("dt", { children: "Conversas e tarefas" }),
1113
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("dd", { children: formatNumber(data.total.runs, locale) })
999
1114
  ] }),
1000
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dlf-stat", children: [
1001
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("dt", { children: "Tokens" }),
1002
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("dd", { children: tokens(data.total) })
1115
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "dlf-stat", children: [
1116
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("dt", { children: "Tokens" }),
1117
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("dd", { children: tokens(data.total) })
1003
1118
  ] })
1004
1119
  ] }),
1005
- !data.currency && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "dlf-muted", children: "Sem tabela de pre\xE7os configurada na aplica\xE7\xE3o: s\xF3 os tokens aparecem." }),
1006
- data.total.unpricedCalls > 0 && data.currency && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "dlf-muted", children: [
1120
+ !data.currency && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "dlf-muted", children: "Sem tabela de pre\xE7os configurada na aplica\xE7\xE3o: s\xF3 os tokens aparecem." }),
1121
+ data.total.unpricedCalls > 0 && data.currency && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("p", { className: "dlf-muted", children: [
1007
1122
  formatNumber(data.total.unpricedCalls, locale),
1008
1123
  " chamadas usaram modelos sem pre\xE7o configurado e n\xE3o entram no custo."
1009
1124
  ] }),
1010
- used !== null && data.budget && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dlf-field", children: [
1011
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "dlf-muted", id: `${ids}-limite`, children: [
1125
+ used !== null && data.budget && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "dlf-field", children: [
1126
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("p", { className: "dlf-muted", id: `${ids}-limite`, children: [
1012
1127
  money(data.total.cost),
1013
1128
  " de ",
1014
1129
  money(data.budget.monthly),
@@ -1017,7 +1132,7 @@ function UsageReport() {
1017
1132
  "%)",
1018
1133
  used >= 1 ? ". Limite atingido: o assistente est\xE1 parado at\xE9 o m\xEAs virar ou o limite subir." : ""
1019
1134
  ] }),
1020
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1135
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1021
1136
  "div",
1022
1137
  {
1023
1138
  className: used >= 1 ? "dlf-meter dlf-meter--over" : "dlf-meter",
@@ -1026,38 +1141,38 @@ function UsageReport() {
1026
1141
  "aria-valuemin": 0,
1027
1142
  "aria-valuemax": 100,
1028
1143
  "aria-valuenow": Math.min(100, Math.round(used * 100)),
1029
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { style: { width: `${Math.min(100, used * 100)}%` } })
1144
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { style: { width: `${Math.min(100, used * 100)}%` } })
1030
1145
  }
1031
1146
  )
1032
1147
  ] }),
1033
- !data.byDay.length ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Empty, { title: "Nenhum uso no per\xEDodo" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1034
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
1035
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h3", { className: "dlf-h3", style: { marginBottom: "0.5rem" }, children: "Por dia" }),
1036
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "dlf-bars", children: data.byDay.map((d) => {
1148
+ !data.byDay.length ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Empty, { title: "Nenhum uso no per\xEDodo" }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
1149
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { children: [
1150
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("h3", { className: "dlf-h3", style: { marginBottom: "0.5rem" }, children: "Por dia" }),
1151
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "dlf-bars", children: data.byDay.map((d) => {
1037
1152
  const value = data.currency ? d.cost : d.inputTokens + d.outputTokens;
1038
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { display: "contents" }, children: [
1039
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("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`)) }),
1040
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "dlf-bar", style: { width: `${maxDay ? value / maxDay * 100 : 0}%` }, "aria-hidden": true }),
1041
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "dlf-num", children: data.currency ? money(d.cost) : tokens(d) })
1153
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { display: "contents" }, children: [
1154
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("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`)) }),
1155
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "dlf-bar", style: { width: `${maxDay ? value / maxDay * 100 : 0}%` }, "aria-hidden": true }),
1156
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "dlf-num", children: data.currency ? money(d.cost) : tokens(d) })
1042
1157
  ] }, d.day);
1043
1158
  }) })
1044
1159
  ] }),
1045
1160
  [
1046
1161
  ["Por canal", data.byChannel.map((c) => ({ key: c.channel, label: channelLabel(c.channel), t: c }))],
1047
1162
  ["Por modelo", data.byModel.map((m) => ({ key: m.model, label: m.model.slice(m.model.indexOf(":") + 1), t: m }))]
1048
- ].map(([title, rows]) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("table", { className: "dlf-table", children: [
1049
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("caption", { className: "dlf-sr-only", children: title }),
1050
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("tr", { children: [
1051
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", children: title }),
1052
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", className: "dlf-num", children: "Execu\xE7\xF5es" }),
1053
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", className: "dlf-num", children: "Tokens" }),
1054
- data.currency && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("th", { scope: "col", className: "dlf-num", children: "Custo" })
1163
+ ].map(([title, rows]) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "dlf-table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("table", { className: "dlf-table", children: [
1164
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("caption", { className: "dlf-sr-only", children: title }),
1165
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("tr", { children: [
1166
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("th", { scope: "col", children: title }),
1167
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("th", { scope: "col", className: "dlf-num", children: "Execu\xE7\xF5es" }),
1168
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("th", { scope: "col", className: "dlf-num", children: "Tokens" }),
1169
+ data.currency && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("th", { scope: "col", className: "dlf-num", children: "Custo" })
1055
1170
  ] }) }),
1056
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tbody", { children: rows.map((r) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("tr", { children: [
1057
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { children: r.label }),
1058
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { className: "dlf-num", children: formatNumber(r.t.runs, locale) }),
1059
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { className: "dlf-num", children: tokens(r.t) }),
1060
- data.currency && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("td", { className: "dlf-num", children: money(r.t.cost) })
1171
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("tbody", { children: rows.map((r) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("tr", { children: [
1172
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { children: r.label }),
1173
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { className: "dlf-num", children: formatNumber(r.t.runs, locale) }),
1174
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { className: "dlf-num", children: tokens(r.t) }),
1175
+ data.currency && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { className: "dlf-num", children: money(r.t.cost) })
1061
1176
  ] }, r.key)) })
1062
1177
  ] }) }, title))
1063
1178
  ] })
@@ -1068,7 +1183,7 @@ function UsageReport() {
1068
1183
  }
1069
1184
 
1070
1185
  // src/Studio.tsx
1071
- var import_jsx_runtime9 = require("react/jsx-runtime");
1186
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1072
1187
  var LABELS = {
1073
1188
  approvals: "Aprova\xE7\xF5es",
1074
1189
  behavior: "Regras",
@@ -1076,12 +1191,13 @@ var LABELS = {
1076
1191
  knowledge: "Conhecimento",
1077
1192
  memory: "Mem\xF3ria",
1078
1193
  usage: "Custos",
1194
+ keys: "Chave de IA",
1079
1195
  audit: "Auditoria"
1080
1196
  };
1081
1197
  function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, currency, pendingApprovals, onPendingApprovalsChange }) {
1082
1198
  const visible = sections ?? Object.keys(LABELS);
1083
- const [own, setOwn] = (0, import_react10.useState)(defaultSection ?? visible[0]);
1084
- const [pending, setPending] = (0, import_react10.useState)(pendingApprovals);
1199
+ const [own, setOwn] = (0, import_react11.useState)(defaultSection ?? visible[0]);
1200
+ const [pending, setPending] = (0, import_react11.useState)(pendingApprovals);
1085
1201
  const current = section ?? own;
1086
1202
  const select = (s) => {
1087
1203
  setOwn(s);
@@ -1092,16 +1208,17 @@ function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, c
1092
1208
  onPendingApprovalsChange?.(n);
1093
1209
  };
1094
1210
  const panels = {
1095
- approvals: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ApprovalsInbox, { onCount }),
1096
- behavior: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BehaviorSettings, { currency: currency ?? null }),
1097
- automations: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutomationsEditor, {}),
1098
- knowledge: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(KnowledgeBase, {}),
1099
- memory: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MemoryBrowser, {}),
1100
- usage: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(UsageReport, {}),
1101
- audit: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AuditLog, {})
1211
+ approvals: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ApprovalsInbox, { onCount }),
1212
+ behavior: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(BehaviorSettings, { currency: currency ?? null }),
1213
+ automations: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AutomationsEditor, {}),
1214
+ knowledge: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(KnowledgeBase, {}),
1215
+ memory: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MemoryBrowser, {}),
1216
+ usage: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(UsageReport, {}),
1217
+ keys: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ProviderKeys, {}),
1218
+ audit: () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(AuditLog, {})
1102
1219
  };
1103
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "dlf dlf-studio", children: [
1104
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1220
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "dlf dlf-studio", children: [
1221
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1105
1222
  Tabs,
1106
1223
  {
1107
1224
  label: "\xC1reas do assistente de IA",
@@ -1110,20 +1227,20 @@ function DolfinhosStudio({ sections, section, defaultSection, onSectionChange, c
1110
1227
  tabs: visible.map((id) => ({ id, label: LABELS[id], ...id === "approvals" ? { count: pendingApprovals ?? pending ?? 0 } : {} }))
1111
1228
  }
1112
1229
  ),
1113
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { role: "tabpanel", id: `dlf-panel-${current}`, "aria-labelledby": `dlf-tab-${current}`, tabIndex: 0, style: { outlineOffset: 4 }, children: panels[current]() })
1230
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { role: "tabpanel", id: `dlf-panel-${current}`, "aria-labelledby": `dlf-tab-${current}`, tabIndex: 0, style: { outlineOffset: 4 }, children: panels[current]() })
1114
1231
  ] });
1115
1232
  }
1116
1233
 
1117
1234
  // src/index.tsx
1118
- var import_jsx_runtime10 = require("react/jsx-runtime");
1235
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1119
1236
  function StudioProvider({ children, endpoint, headers, fetch: fetch2, labels, locale = "pt-BR", navigate }) {
1120
- const client = (0, import_react11.useMemo)(
1237
+ const client = (0, import_react12.useMemo)(
1121
1238
  () => createStudioClient({ ...endpoint ? { endpoint } : {}, ...headers ? { headers } : {}, ...fetch2 ? { fetch: fetch2 } : {} }),
1122
1239
  // eslint-disable-next-line react-hooks/exhaustive-deps
1123
1240
  [endpoint]
1124
1241
  );
1125
- const value = (0, import_react11.useMemo)(() => ({ client, labels: labels ?? {}, locale, ...navigate ? { navigate } : {} }), [client, labels, locale, navigate]);
1126
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(StudioContextProvider, { value, children });
1242
+ const value = (0, import_react12.useMemo)(() => ({ client, labels: labels ?? {}, locale, ...navigate ? { navigate } : {} }), [client, labels, locale, navigate]);
1243
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(StudioContextProvider, { value, children });
1127
1244
  }
1128
1245
  // Annotate the CommonJS export names for ESM import in node:
1129
1246
  0 && (module.exports = {
@@ -1135,6 +1252,7 @@ function StudioProvider({ children, endpoint, headers, fetch: fetch2, labels, lo
1135
1252
  KnowledgeBase,
1136
1253
  MemoryBrowser,
1137
1254
  MyMemory,
1255
+ ProviderKeys,
1138
1256
  StudioError,
1139
1257
  StudioProvider,
1140
1258
  UsageReport,