@fayz-ai/plugin-automations 0.13.0 → 0.13.2

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.d.ts CHANGED
@@ -25,4 +25,5 @@ export { createFayzTemplateStore } from './data/fayz';
25
25
  export type { MessageTemplateStore };
26
26
  export { loadProviderTemplates, providerTemplateFor, PROVIDER_TEMPLATES_TABLE, type ProviderTemplateRow, type ProviderTemplateStatus, } from './data/provider-templates';
27
27
  export { providerApprovalFor, type ProviderApproval } from './views/ProviderTemplateStatus';
28
+ export { FlowsPage as CadenceFlowsSurface } from './views/FlowsPage';
28
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAK5E,OAAO,EAAE,2BAA2B,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAsBzF,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAA;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,UAAU,CAAA;IAC9B,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,cAAc,CAgJ1F;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAA;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,YAAY,EAAE,oBAAoB,EAAE,CAAA;AA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AmB,CAAA"}
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import * as React4 from 'react';
2
2
  import React4__default, { useState, useCallback, useRef, useEffect, useMemo } from 'react';
3
- import { getSupabaseClientOptional, startEventLog, getMessageDefaults, normalizeMessageActions, useTranslation, errorMessage, usePluginRuntimeOptional, resolveMessages, resolveMessage, renderMessageTemplate, loadEventRuns, getActiveTenantId } from '@fayz-ai/core';
4
- import { resolveFayzAgentConnection, registerRailPage, getFayzSupabaseClientOptional, PageActions, useConnectors, useAgentSurface, askAI, SettingsTabs, adminNavigateTo, RightRailPage, AskAIButton, useOrganizationStore, connectorRoute, ConnectorMark, ConnectorDeliveries } from '@fayz-ai/admin';
3
+ import { getSupabaseClientOptional, useTranslation, errorMessage, startEventLog, getMessageDefaults, normalizeMessageActions, usePluginRuntimeOptional, resolveMessages, resolveMessage, renderMessageTemplate, loadEventRuns, getActiveTenantId } from '@fayz-ai/core';
4
+ import { PageActions, resolveFayzAgentConnection, registerRailPage, getFayzSupabaseClientOptional, useConnectors, useAgentSurface, askAI, SettingsTabs, adminNavigateTo, RightRailPage, AskAIButton, useOrganizationStore, connectorRoute, ConnectorMark, ConnectorDeliveries } from '@fayz-ai/admin';
5
5
  import * as LucideIcons from 'lucide-react';
6
- import { Loader2, Plus, ChevronRight, WandSparkles, Zap, Receipt, Megaphone, MessageSquare, Smartphone, Mail, RotateCcw, Check, Clock, Monitor, ListChecks, Trash2, RefreshCw, History, Send, AlertTriangle, CircleCheck, CircleSlash } from 'lucide-react';
7
- import { toast, PageHeaderActions, Card, Switch, DataTable, PageTabs, WhatsAppIcon, SubpageHeader, Button, Badge, Hint, HeaderTabs, PhoneField } from '@fayz-ai/ui';
6
+ import { Plus, ChevronRight, ListChecks, MessageSquare, Clock, Trash2, Workflow, WandSparkles, Zap, Receipt, Megaphone, Smartphone, Mail, RotateCcw, Check, Monitor, RefreshCw, History, Send, AlertTriangle, CircleCheck, CircleSlash } from 'lucide-react';
7
+ import { toast, Card, PageHeaderActions, Switch, DataTable, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, ModalFooter, Button, PageTabs, WhatsAppIcon, SubpageHeader, Badge, Hint, HeaderTabs, PhoneField } from '@fayz-ai/ui';
8
8
  import { createFayzAutomationsClient, FayzAutomationsError } from '@fayz-ai/sdk/automations';
9
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
9
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
 
11
11
  // src/index.ts
12
12
  var PREFLIGHT_FUNCTION = "tyxter-payment-preflight";
@@ -1527,6 +1527,78 @@ function createSupabaseTemplateStore() {
1527
1527
  }
1528
1528
  };
1529
1529
  }
1530
+ function CadenceComposer({ open, onClose, onCreate }) {
1531
+ const t = useTranslation();
1532
+ const runtime = usePluginRuntimeOptional();
1533
+ const events = runtime?.events ?? [];
1534
+ const [name, setName] = React4__default.useState("");
1535
+ const [entryEvent, setEntryEvent] = React4__default.useState("");
1536
+ const [exitEvent, setExitEvent] = React4__default.useState("");
1537
+ const [saving, setSaving] = React4__default.useState(false);
1538
+ React4__default.useEffect(() => {
1539
+ if (!open) return;
1540
+ setName("");
1541
+ setExitEvent("");
1542
+ setEntryEvent(events.find((e) => e.name === "crm.lead_created")?.name ?? events[0]?.name ?? "");
1543
+ }, [open]);
1544
+ const entry = events.find((e) => e.name === entryEvent);
1545
+ async function submit() {
1546
+ if (!name.trim() || !entryEvent || saving) return;
1547
+ setSaving(true);
1548
+ try {
1549
+ await onCreate({
1550
+ name: name.trim(),
1551
+ entryEvent,
1552
+ exitEvents: exitEvent ? [exitEvent] : []
1553
+ });
1554
+ onClose();
1555
+ } catch (e) {
1556
+ toast.error(errorMessage(e));
1557
+ } finally {
1558
+ setSaving(false);
1559
+ }
1560
+ }
1561
+ return /* @__PURE__ */ jsx(Modal, { open, onOpenChange: (o) => {
1562
+ if (!o) onClose();
1563
+ }, children: /* @__PURE__ */ jsxs(ModalContent, { size: "md", children: [
1564
+ /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(ModalTitle, { children: t("automations.flow.newTitle") }) }),
1565
+ /* @__PURE__ */ jsxs(ModalBody, { className: "space-y-4", children: [
1566
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1.5", children: [
1567
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-foreground", children: t("automations.flow.nameLabel") }),
1568
+ /* @__PURE__ */ jsx(Input, { value: name, onChange: (e) => setName(e.target.value), placeholder: t("automations.flow.namePlaceholder") })
1569
+ ] }),
1570
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1.5", children: [
1571
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-foreground", children: t("automations.flow.entryLabel") }),
1572
+ events.length > 0 ? /* @__PURE__ */ jsxs(Select, { value: entryEvent, onValueChange: setEntryEvent, children: [
1573
+ /* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("automations.flow.entryPlaceholder") }) }),
1574
+ /* @__PURE__ */ jsx(SelectContent, { children: events.map((e) => /* @__PURE__ */ jsx(SelectItem, { value: e.name, children: e.title ?? e.name }, e.name)) })
1575
+ ] }) : /* @__PURE__ */ jsx("p", { className: "rounded-lg border border-dashed px-3 py-2 text-xs text-muted-foreground", children: t("automations.flow.noEvents") }),
1576
+ entry?.trigger && /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: entry.trigger })
1577
+ ] }),
1578
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1.5", children: [
1579
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-foreground", children: t("automations.flow.exitLabel") }),
1580
+ /* @__PURE__ */ jsxs(Select, { value: exitEvent || "__none__", onValueChange: (v) => setExitEvent(v === "__none__" ? "" : v), children: [
1581
+ /* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }),
1582
+ /* @__PURE__ */ jsxs(SelectContent, { children: [
1583
+ /* @__PURE__ */ jsx(SelectItem, { value: "__none__", children: t("automations.flow.exitNone") }),
1584
+ events.filter((e) => e.name !== entryEvent).map((e) => /* @__PURE__ */ jsx(SelectItem, { value: e.name, children: e.title ?? e.name }, e.name))
1585
+ ] })
1586
+ ] }),
1587
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: t("automations.flow.exitHint") })
1588
+ ] }),
1589
+ /* @__PURE__ */ jsxs("p", { className: "flex items-start gap-2 rounded-lg bg-muted/40 px-3 py-2 text-[11px] text-muted-foreground", children: [
1590
+ /* @__PURE__ */ jsx(Workflow, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
1591
+ t("automations.flow.bornOffHint")
1592
+ ] })
1593
+ ] }),
1594
+ /* @__PURE__ */ jsxs(ModalFooter, { children: [
1595
+ /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onClose, children: t("common.cancel") }),
1596
+ /* @__PURE__ */ jsx(Button, { onClick: () => {
1597
+ void submit();
1598
+ }, disabled: saving || !name.trim() || !entryEvent, children: t("automations.flow.create") })
1599
+ ] })
1600
+ ] }) });
1601
+ }
1530
1602
  var FLOWS = "plg_automations_flows";
1531
1603
  var STEPS = "plg_automations_flow_steps";
1532
1604
  var ENROLLMENTS = "plg_automations_enrollments";
@@ -1803,6 +1875,7 @@ function FlowsPage() {
1803
1875
  const [selectedId, setSelectedId] = useState(null);
1804
1876
  const [steps, setSteps] = useState([]);
1805
1877
  const [counts, setCounts] = useState(null);
1878
+ const [composerOpen, setComposerOpen] = useState(false);
1806
1879
  const load = useCallback(async () => {
1807
1880
  setLoading(true);
1808
1881
  try {
@@ -1845,19 +1918,11 @@ function FlowsPage() {
1845
1918
  if (selectedId) void loadDetail(selectedId);
1846
1919
  }, [selectedId, loadDetail]);
1847
1920
  flows.find((f) => f.id === selectedId) ?? null;
1848
- async function createFlow() {
1849
- const name = window.prompt(t("automations.flow.namePrompt"));
1850
- if (!name?.trim()) return;
1851
- const entryEvent = window.prompt(t("automations.flow.entryPrompt"), "crm.lead_created");
1852
- if (!entryEvent?.trim()) return;
1853
- try {
1854
- const flow = await store.saveFlow({ name: name.trim(), entryEvent: entryEvent.trim() });
1855
- await load();
1856
- setSelectedId(flow.id);
1857
- toast.success(t("automations.flow.created"));
1858
- } catch (e) {
1859
- toast.error(errorMessage(e));
1860
- }
1921
+ async function createFlow(input) {
1922
+ const flow = await store.saveFlow(input);
1923
+ await load();
1924
+ setSelectedId(flow.id);
1925
+ toast.success(t("automations.flow.created"));
1861
1926
  }
1862
1927
  async function toggleActive(flow) {
1863
1928
  if (!flow.isActive) {
@@ -1875,10 +1940,12 @@ function FlowsPage() {
1875
1940
  }
1876
1941
  }
1877
1942
  if (loading) {
1878
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 p-6 text-sm text-muted-foreground", children: [
1879
- /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
1880
- t("automations.flow.loading")
1881
- ] });
1943
+ return /* @__PURE__ */ jsx("div", { className: "space-y-2", "aria-busy": "true", "aria-label": t("automations.flow.loading"), children: [0, 1, 2].map((i) => /* @__PURE__ */ jsx(Card, { className: "p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
1944
+ /* @__PURE__ */ jsx("div", { className: "h-4 w-4 shrink-0 animate-pulse rounded bg-muted/40" }),
1945
+ /* @__PURE__ */ jsx("div", { className: "h-3.5 animate-pulse rounded bg-muted/40", style: { width: `${34 - i * 6}%` } }),
1946
+ /* @__PURE__ */ jsx("div", { className: "h-4 w-28 animate-pulse rounded-full bg-muted/30" }),
1947
+ /* @__PURE__ */ jsx("div", { className: "ml-auto h-5 w-9 animate-pulse rounded-full bg-muted/30" })
1948
+ ] }) }, i)) });
1882
1949
  }
1883
1950
  return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
1884
1951
  /* @__PURE__ */ jsx(PageHeaderActions, { children: /* @__PURE__ */ jsx(
@@ -1890,12 +1957,18 @@ function FlowsPage() {
1890
1957
  icon: Plus,
1891
1958
  intent: "primary",
1892
1959
  creates: true,
1893
- onSelect: () => {
1894
- void createFlow();
1895
- }
1960
+ onSelect: () => setComposerOpen(true)
1896
1961
  }]
1897
1962
  }
1898
1963
  ) }),
1964
+ /* @__PURE__ */ jsx(
1965
+ CadenceComposer,
1966
+ {
1967
+ open: composerOpen,
1968
+ onClose: () => setComposerOpen(false),
1969
+ onCreate: createFlow
1970
+ }
1971
+ ),
1899
1972
  flows.length === 0 ? /* @__PURE__ */ jsxs(Card, { className: "flex flex-col items-center gap-1 border-dashed py-12 text-center", children: [
1900
1973
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("automations.flow.emptyTitle") }),
1901
1974
  /* @__PURE__ */ jsx("p", { className: "max-w-md text-xs text-muted-foreground", children: t("automations.flow.emptyHint") })
@@ -1966,6 +2039,17 @@ function FlowsPage() {
1966
2039
 
1967
2040
  // src/locales/en.ts
1968
2041
  var en = {
2042
+ "automations.flow.newTitle": "New cadence",
2043
+ "automations.flow.nameLabel": "Name",
2044
+ "automations.flow.namePlaceholder": "e.g. New lead sequence",
2045
+ "automations.flow.entryLabel": "Who enters",
2046
+ "automations.flow.entryPlaceholder": "Pick the fact that puts somebody in",
2047
+ "automations.flow.exitLabel": "Who leaves",
2048
+ "automations.flow.exitNone": "Only leaves when the steps run out",
2049
+ "automations.flow.exitHint": "The fact that stops the sequence. Without it, someone who already replied still gets the day-5 message.",
2050
+ "automations.flow.bornOffHint": "A cadence is born off and empty. Add the steps below and switch it on when it is ready.",
2051
+ "automations.flow.noEvents": "No active module announces facts in this app \u2014 no trigger, no cadence.",
2052
+ "automations.flow.create": "Create cadence",
1969
2053
  "automations.flow.new": "New flow",
1970
2054
  "automations.flow.loading": "Loading flows\u2026",
1971
2055
  "automations.flow.emptyTitle": "No cadence flows yet",
@@ -1999,6 +2083,17 @@ var en = {
1999
2083
 
2000
2084
  // src/locales/pt-BR.ts
2001
2085
  var ptBR = {
2086
+ "automations.flow.newTitle": "Nova cad\xEAncia",
2087
+ "automations.flow.nameLabel": "Nome",
2088
+ "automations.flow.namePlaceholder": "ex.: R\xE9gua do lead novo",
2089
+ "automations.flow.entryLabel": "Quem entra",
2090
+ "automations.flow.entryPlaceholder": "Escolha o fato que coloca algu\xE9m na r\xE9gua",
2091
+ "automations.flow.exitLabel": "Quem sai",
2092
+ "automations.flow.exitNone": "S\xF3 sai quando os passos acabam",
2093
+ "automations.flow.exitHint": "O fato que faz a pessoa parar de receber. Sem ele, quem j\xE1 respondeu continua recebendo a mensagem do dia 5.",
2094
+ "automations.flow.bornOffHint": "A cad\xEAncia nasce desligada e sem passos. Monte os passos abaixo e ligue quando estiver pronta.",
2095
+ "automations.flow.noEvents": "Nenhum m\xF3dulo ativo anuncia fatos neste app \u2014 sem gatilho n\xE3o h\xE1 cad\xEAncia.",
2096
+ "automations.flow.create": "Criar cad\xEAncia",
2002
2097
  "automations.flow.new": "Novo fluxo",
2003
2098
  "automations.flow.loading": "Carregando fluxos\u2026",
2004
2099
  "automations.flow.emptyTitle": "Nenhum fluxo de cad\xEAncia ainda",
@@ -3120,6 +3215,6 @@ function createAutomationsPlugin(options) {
3120
3215
  };
3121
3216
  }
3122
3217
 
3123
- export { PROVIDER_TEMPLATES_TABLE, createAutomationsPlugin, createFayzTemplateStore, createSupabaseTemplateStore, loadProviderTemplates, providerApprovalFor, providerTemplateFor };
3218
+ export { FlowsPage as CadenceFlowsSurface, PROVIDER_TEMPLATES_TABLE, createAutomationsPlugin, createFayzTemplateStore, createSupabaseTemplateStore, loadProviderTemplates, providerApprovalFor, providerTemplateFor };
3124
3219
  //# sourceMappingURL=index.js.map
3125
3220
  //# sourceMappingURL=index.js.map