@apotech-os/support-kit 2.9.1 → 2.10.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/ui/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { GENERATED_RESPONSE_STATUSES, EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, toTriageDecision, toAgent, toGeneratedResponse, isGeneratedResponseStatus, toCategoryGroup, toResponseComparison, toDiffAnalysis, NODE_NAMES, settingsToProfile, hasNoDraftNode, guardrailBucket, computeWordDiff, DEFAULT_LLM_PROVIDER, isSendableVerdict, DEFAULT_MAX_TOOL_CALLS, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED } from '../chunk-CVYJU4SV.js';
1
+ import { GENERATED_RESPONSE_STATUSES, EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, toTriageDecision, toAgent, toGeneratedResponse, isGeneratedResponseStatus, toCategoryGroup, toResponseComparison, toDiffAnalysis, NODE_NAMES, settingsToProfile, hasNoDraftNode, guardrailBucket, DEFAULT_LLM_PROVIDER, computeWordDiff, isSendableVerdict, DEFAULT_MAX_TOOL_CALLS, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED } from '../chunk-CVYJU4SV.js';
2
2
  import { useState, useMemo, useRef, useEffect, useCallback, useId } from 'react';
3
3
  import { useAppContext, useAppSettings, Card, CardContent, Button, Link, KpiCard, BarChart, StackedBarChart, DataTable, Select, useAppApi, useToast, Badge, FunnelChart, Spinner, LineChart, Input, Switch, Checkbox, Textarea, cn, SidePanel, CopyButton, Modal, Tooltip, AppInvokeError } from '@apotech-os/ui-sdk';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -1391,6 +1391,226 @@ function PipelinePage() {
1391
1391
  )
1392
1392
  ] });
1393
1393
  }
1394
+
1395
+ // src/ui/settings/pipeline-nodes.ts
1396
+ var PIPELINE_STEP_KEYS = ["triage", "escalate", "draft", "evaluate", "revise"];
1397
+ var PIPELINE_STEPS = [
1398
+ {
1399
+ key: "triage",
1400
+ label: "Triage",
1401
+ description: "comprend et classe chaque demande entrante",
1402
+ requires: null,
1403
+ blockedReason: null
1404
+ },
1405
+ {
1406
+ key: "escalate",
1407
+ label: "Escalade",
1408
+ description: "passe la main \xE0 un humain",
1409
+ requires: null,
1410
+ blockedReason: null
1411
+ },
1412
+ {
1413
+ key: "draft",
1414
+ label: "R\xE9daction",
1415
+ description: "pr\xE9pare un projet de r\xE9ponse",
1416
+ requires: null,
1417
+ blockedReason: null
1418
+ },
1419
+ {
1420
+ key: "evaluate",
1421
+ label: "\xC9valuation",
1422
+ description: "relit la r\xE9ponse avant envoi",
1423
+ requires: "draft",
1424
+ blockedReason: "Il n'y a rien \xE0 \xE9valuer sans r\xE9daction."
1425
+ },
1426
+ {
1427
+ key: "revise",
1428
+ label: "R\xE9vision",
1429
+ description: "r\xE9\xE9crit la r\xE9ponse si l'\xE9valuation la juge insuffisante",
1430
+ requires: "evaluate",
1431
+ blockedReason: "Sans \xE9valuation, rien ne d\xE9clenche une r\xE9vision."
1432
+ }
1433
+ ];
1434
+ var TRIAGE_LOCK_REASON = "Sans triage l'app ne traite rien.";
1435
+ var STEP_BY_KEY = new Map(PIPELINE_STEPS.map((step) => [step.key, step]));
1436
+ function pipelineStep(key) {
1437
+ const step = STEP_BY_KEY.get(key);
1438
+ if (!step) throw new Error(`unknown pipeline step: ${key}`);
1439
+ return step;
1440
+ }
1441
+ function readNodes(value) {
1442
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
1443
+ return value;
1444
+ }
1445
+ function readStep(value, key) {
1446
+ const step = readNodes(value)[key];
1447
+ if (typeof step !== "object" || step === null || Array.isArray(step)) return null;
1448
+ return step;
1449
+ }
1450
+ function isStepEnabled(value, key) {
1451
+ return readStep(value, key) !== null;
1452
+ }
1453
+ function stepBlockedReason(value, key) {
1454
+ const { requires, blockedReason } = pipelineStep(key);
1455
+ if (!requires) return null;
1456
+ return isStepActive(value, requires) ? null : blockedReason;
1457
+ }
1458
+ function isStepActive(value, key) {
1459
+ return isStepEnabled(value, key) && stepBlockedReason(value, key) === null;
1460
+ }
1461
+ function withStep(value, key, step) {
1462
+ return { ...readNodes(value), [key]: step };
1463
+ }
1464
+ function withStepFields(value, key, patch) {
1465
+ const step = readStep(value, key);
1466
+ if (!step) return readNodes(value);
1467
+ const next = { ...step };
1468
+ for (const [field2, fieldValue] of Object.entries(patch)) {
1469
+ if (fieldValue === void 0) delete next[field2];
1470
+ else next[field2] = fieldValue;
1471
+ }
1472
+ return withStep(value, key, next);
1473
+ }
1474
+ function stepString(step, field2) {
1475
+ const value = step?.[field2];
1476
+ return typeof value === "string" ? value : "";
1477
+ }
1478
+ function stepNumber(step, field2, fallback) {
1479
+ const value = step?.[field2];
1480
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
1481
+ }
1482
+ function stepBoolean(step, field2, fallback) {
1483
+ const value = step?.[field2];
1484
+ return typeof value === "boolean" ? value : fallback;
1485
+ }
1486
+ function stepUsesAgentPrompt(key) {
1487
+ return key === "draft";
1488
+ }
1489
+ var DEFAULT_PROMPT_LABEL = "production";
1490
+ function stepPromptName(step) {
1491
+ return readPromptField(step, "name");
1492
+ }
1493
+ function stepPromptLabel(step) {
1494
+ return readPromptField(step, "label") || DEFAULT_PROMPT_LABEL;
1495
+ }
1496
+ function readPromptField(step, field2) {
1497
+ const prompt = step?.prompt;
1498
+ if (typeof prompt !== "object" || prompt === null) return "";
1499
+ const value = prompt[field2];
1500
+ return typeof value === "string" ? value : "";
1501
+ }
1502
+ function promptPatch(name, label) {
1503
+ return { prompt: { name, label } };
1504
+ }
1505
+ function stepReasoning(step) {
1506
+ const value = step?.reasoning;
1507
+ return REASONING_EFFORTS.some((effort) => effort.value === value) ? value : "off";
1508
+ }
1509
+ var REASONING_EFFORTS = [
1510
+ { value: "off", label: "Aucun" },
1511
+ { value: "low", label: "L\xE9ger" },
1512
+ { value: "medium", label: "Moyen" },
1513
+ { value: "high", label: "Pouss\xE9" }
1514
+ ];
1515
+ var KNOWN_MODELS = [
1516
+ {
1517
+ provider: "openai",
1518
+ model: "gpt-4o-mini",
1519
+ label: "GPT-4o mini",
1520
+ hint: "Le moins cher, tr\xE8s rapide \u2014 suffisant pour classer"
1521
+ },
1522
+ {
1523
+ provider: "openai",
1524
+ model: "gpt-5-mini",
1525
+ label: "GPT-5 mini",
1526
+ hint: "Rapide, bon march\xE9, meilleur raisonnement"
1527
+ },
1528
+ {
1529
+ provider: "openai",
1530
+ model: "gpt-4.1",
1531
+ label: "GPT-4.1",
1532
+ hint: "Co\xFBt moyen \u2014 r\xE9daction soign\xE9e"
1533
+ },
1534
+ {
1535
+ provider: "openai",
1536
+ model: "gpt-5",
1537
+ label: "GPT-5",
1538
+ hint: "Le plus capable \u2014 le plus lent et le plus cher"
1539
+ },
1540
+ {
1541
+ provider: "anthropic",
1542
+ model: "claude-3-5-haiku-latest",
1543
+ label: "Claude 3.5 Haiku",
1544
+ hint: "Rapide et bon march\xE9"
1545
+ },
1546
+ {
1547
+ provider: "anthropic",
1548
+ model: "claude-3-5-sonnet-latest",
1549
+ label: "Claude 3.5 Sonnet",
1550
+ hint: "Co\xFBt moyen \u2014 r\xE9daction soign\xE9e"
1551
+ }
1552
+ ];
1553
+ var CUSTOM_MODEL_VALUE = "__custom__";
1554
+ function findModelOption(model) {
1555
+ return KNOWN_MODELS.find((option) => option.model === model);
1556
+ }
1557
+ function defaultStep() {
1558
+ const [first] = KNOWN_MODELS;
1559
+ return { model: first.model, provider: first.provider, reasoning: "off" };
1560
+ }
1561
+ var PIPELINE_PRESETS = [
1562
+ {
1563
+ id: "triage-only",
1564
+ label: "D\xE9marrage prudent \u2014 triage seul",
1565
+ description: "Les demandes sont comprises et class\xE9es. Aucune r\xE9ponse n\u2019est pr\xE9par\xE9e.",
1566
+ enabled: ["triage"]
1567
+ },
1568
+ {
1569
+ id: "assisted",
1570
+ label: "R\xE9ponse assist\xE9e",
1571
+ description: "Triage, escalade et r\xE9daction : un projet de r\xE9ponse est pr\xE9par\xE9 pour un humain. L\u2019envoi automatique reste d\xE9sactiv\xE9.",
1572
+ enabled: ["triage", "escalate", "draft"]
1573
+ }
1574
+ ];
1575
+ function applyPreset(value, preset, restore) {
1576
+ let next = readNodes(value);
1577
+ for (const key of PIPELINE_STEP_KEYS) {
1578
+ const on = preset.enabled.includes(key);
1579
+ next = withStep(next, key, on ? readStep(next, key) ?? restore(key) : null);
1580
+ }
1581
+ return next;
1582
+ }
1583
+ function usePromptCatalogue() {
1584
+ const { appSlug } = useAppContext();
1585
+ const api = useAppApi();
1586
+ const [prompts, setPrompts] = useState([]);
1587
+ const [isLoading, setIsLoading] = useState(true);
1588
+ const [error, setError] = useState(void 0);
1589
+ const clientRef = useRef(api);
1590
+ clientRef.current = api;
1591
+ const requestIdRef = useRef(0);
1592
+ const isMountedRef = useRef(true);
1593
+ useEffect(() => {
1594
+ isMountedRef.current = true;
1595
+ const requestId = ++requestIdRef.current;
1596
+ setIsLoading(true);
1597
+ void clientRef.current.get(`/data/apps/${appSlug}/prompts`).then((catalogue) => {
1598
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1599
+ setPrompts(catalogue);
1600
+ setError(void 0);
1601
+ }).catch((err) => {
1602
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1603
+ setError(err);
1604
+ }).finally(() => {
1605
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1606
+ setIsLoading(false);
1607
+ });
1608
+ return () => {
1609
+ isMountedRef.current = false;
1610
+ };
1611
+ }, [appSlug]);
1612
+ return { prompts, isLoading, error };
1613
+ }
1394
1614
  function ConfirmModal({
1395
1615
  title,
1396
1616
  description,
@@ -1560,18 +1780,34 @@ var STATUS_VARIANT = {
1560
1780
  archived: "outline"
1561
1781
  };
1562
1782
  function emptyForm() {
1563
- return { name: "", modelId: "", provider: "openai", systemPromptSnapshot: "" };
1783
+ return {
1784
+ name: "",
1785
+ modelId: "",
1786
+ provider: DEFAULT_LLM_PROVIDER,
1787
+ status: "available",
1788
+ promptName: "",
1789
+ promptLabel: "",
1790
+ systemPromptSnapshot: ""
1791
+ };
1564
1792
  }
1565
1793
  function formFromAgent(agent) {
1566
1794
  return {
1567
1795
  name: agent.name,
1568
1796
  modelId: agent.modelId,
1569
1797
  provider: agent.provider,
1798
+ status: agent.status,
1799
+ promptName: agent.promptName,
1800
+ promptLabel: agent.promptLabel ?? "",
1570
1801
  systemPromptSnapshot: agent.systemPromptSnapshot ?? ""
1571
1802
  };
1572
1803
  }
1804
+ var DERIVED_PROMPT_VALUE = "__derived__";
1805
+ var CUSTOM_PROMPT_VALUE = "__custom-prompt__";
1806
+ var DEFAULT_LABEL_VALUE = "__production__";
1573
1807
  function AgentFormModal({
1574
1808
  agent,
1809
+ prompts,
1810
+ promptsLoading,
1575
1811
  onClose,
1576
1812
  onSave
1577
1813
  }) {
@@ -1579,10 +1815,19 @@ function AgentFormModal({
1579
1815
  agent === "new" ? emptyForm() : formFromAgent(agent)
1580
1816
  );
1581
1817
  const [isSaving, setIsSaving] = useState(false);
1818
+ const [freeTextModel, setFreeTextModel] = useState(false);
1819
+ const [freeTextPrompt, setFreeTextPrompt] = useState(false);
1582
1820
  const nameId = useId();
1583
- const modelId = useId();
1821
+ const modelInputId = useId();
1822
+ const providerInputId = useId();
1823
+ const promptInputId = useId();
1584
1824
  const snapshotId = useId();
1585
- const isValid = form.name.trim() !== "" && form.modelId.trim() !== "";
1825
+ const knownModel = findModelOption(form.modelId);
1826
+ const showModelFreeText = freeTextModel || form.modelId !== "" && !knownModel;
1827
+ const knownPrompt = prompts.find((entry) => entry.name === form.promptName);
1828
+ const showPromptFreeText = freeTextPrompt || agent !== "new" && form.promptName !== "" && !knownPrompt && !promptsLoading;
1829
+ const promptLabels = knownPrompt?.labels ?? [];
1830
+ const isValid = form.name.trim() !== "" && form.modelId.trim() !== "" && (agent === "new" || form.promptName.trim() !== "");
1586
1831
  async function submit(event) {
1587
1832
  event.preventDefault();
1588
1833
  if (isSaving || !isValid) return;
@@ -1593,6 +1838,14 @@ function AgentFormModal({
1593
1838
  setIsSaving(false);
1594
1839
  }
1595
1840
  }
1841
+ function pickPrompt(next) {
1842
+ if (next === CUSTOM_PROMPT_VALUE) {
1843
+ setFreeTextPrompt(true);
1844
+ return;
1845
+ }
1846
+ setFreeTextPrompt(false);
1847
+ setForm({ ...form, promptName: next === DERIVED_PROMPT_VALUE ? "" : next, promptLabel: "" });
1848
+ }
1596
1849
  return /* @__PURE__ */ jsx(
1597
1850
  Modal,
1598
1851
  {
@@ -1604,24 +1857,113 @@ function AgentFormModal({
1604
1857
  /* @__PURE__ */ jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
1605
1858
  /* @__PURE__ */ jsx(Input, { id: nameId, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) })
1606
1859
  ] }),
1607
- /* @__PURE__ */ jsxs("div", { children: [
1608
- /* @__PURE__ */ jsx("label", { htmlFor: modelId, className: "mb-1 block text-sm font-medium", children: "Mod\xE8le" }),
1860
+ agent !== "new" && agent.status !== "default" && /* @__PURE__ */ jsxs("div", { children: [
1861
+ /* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Statut" }),
1609
1862
  /* @__PURE__ */ jsx(
1610
- Input,
1863
+ Select,
1611
1864
  {
1612
- id: modelId,
1613
- value: form.modelId,
1614
- onChange: (e) => setForm({ ...form, modelId: e.target.value })
1865
+ "aria-label": "Statut",
1866
+ value: form.status,
1867
+ onValueChange: (next) => setForm({ ...form, status: next }),
1868
+ items: [
1869
+ { value: "available", label: STATUS_LABELS.available },
1870
+ { value: "archived", label: STATUS_LABELS.archived }
1871
+ ]
1615
1872
  }
1616
1873
  )
1617
1874
  ] }),
1618
1875
  /* @__PURE__ */ jsxs("div", { children: [
1619
- /* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Fournisseur" }),
1620
- /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", children: [
1621
- form.provider,
1622
- " \u2014 non modifiable ici ; le fournisseur r\xE9ellement appel\xE9 est celui des Param\xE8tres."
1876
+ /* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Mod\xE8le" }),
1877
+ /* @__PURE__ */ jsx(
1878
+ Select,
1879
+ {
1880
+ "aria-label": "Mod\xE8le",
1881
+ value: showModelFreeText ? CUSTOM_MODEL_VALUE : knownModel?.model ?? void 0,
1882
+ onValueChange: (next) => {
1883
+ if (next === CUSTOM_MODEL_VALUE) {
1884
+ setFreeTextModel(true);
1885
+ return;
1886
+ }
1887
+ setFreeTextModel(false);
1888
+ const option = findModelOption(next);
1889
+ if (!option) return;
1890
+ setForm({ ...form, modelId: option.model, provider: option.provider });
1891
+ },
1892
+ items: [
1893
+ ...KNOWN_MODELS.map((option) => ({
1894
+ value: option.model,
1895
+ label: `${option.label} \u2014 ${option.hint}`
1896
+ })),
1897
+ { value: CUSTOM_MODEL_VALUE, label: "Autre \u2014 saisir un identifiant de mod\xE8le" }
1898
+ ]
1899
+ }
1900
+ ),
1901
+ showModelFreeText && /* @__PURE__ */ jsxs("div", { className: "mt-2 space-y-2", children: [
1902
+ /* @__PURE__ */ jsx("label", { htmlFor: modelInputId, className: "mb-1 block text-sm font-medium", children: "Identifiant de mod\xE8le" }),
1903
+ /* @__PURE__ */ jsx(
1904
+ Input,
1905
+ {
1906
+ id: modelInputId,
1907
+ value: form.modelId,
1908
+ onChange: (e) => setForm({ ...form, modelId: e.target.value })
1909
+ }
1910
+ ),
1911
+ /* @__PURE__ */ jsx("label", { htmlFor: providerInputId, className: "mb-1 block text-sm font-medium", children: "Fournisseur" }),
1912
+ /* @__PURE__ */ jsx(
1913
+ Input,
1914
+ {
1915
+ id: providerInputId,
1916
+ value: form.provider,
1917
+ onChange: (e) => setForm({ ...form, provider: e.target.value })
1918
+ }
1919
+ )
1623
1920
  ] })
1624
1921
  ] }),
1922
+ /* @__PURE__ */ jsxs("div", { children: [
1923
+ /* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Prompt Langfuse" }),
1924
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
1925
+ /* @__PURE__ */ jsx(
1926
+ Select,
1927
+ {
1928
+ "aria-label": "Prompt Langfuse",
1929
+ value: showPromptFreeText ? CUSTOM_PROMPT_VALUE : knownPrompt ? form.promptName : agent === "new" ? DERIVED_PROMPT_VALUE : void 0,
1930
+ onValueChange: pickPrompt,
1931
+ items: [
1932
+ ...agent === "new" ? [{ value: DERIVED_PROMPT_VALUE, label: "Nouveau prompt \u2014 agent/<g\xE9n\xE9r\xE9 automatiquement>" }] : [],
1933
+ ...prompts.map((entry) => ({ value: entry.name, label: entry.name })),
1934
+ { value: CUSTOM_PROMPT_VALUE, label: "Autre \u2014 saisir un nom de prompt" }
1935
+ ],
1936
+ disabled: promptsLoading
1937
+ }
1938
+ ),
1939
+ /* @__PURE__ */ jsx(
1940
+ Select,
1941
+ {
1942
+ "aria-label": "Tag du prompt",
1943
+ value: form.promptLabel === "" ? DEFAULT_LABEL_VALUE : form.promptLabel,
1944
+ onValueChange: (next) => setForm({ ...form, promptLabel: next === DEFAULT_LABEL_VALUE ? "" : next }),
1945
+ items: [
1946
+ { value: DEFAULT_LABEL_VALUE, label: "production (par d\xE9faut)" },
1947
+ ...promptLabels.filter((label) => label !== DEFAULT_PROMPT_LABEL).map((label) => ({ value: label, label })),
1948
+ ...form.promptLabel !== "" && !promptLabels.includes(form.promptLabel) ? [{ value: form.promptLabel, label: form.promptLabel }] : []
1949
+ ],
1950
+ disabled: promptsLoading || form.promptName === "" && !showPromptFreeText
1951
+ }
1952
+ )
1953
+ ] }),
1954
+ showPromptFreeText && /* @__PURE__ */ jsxs("div", { className: "mt-2", children: [
1955
+ /* @__PURE__ */ jsx("label", { htmlFor: promptInputId, className: "mb-1 block text-sm font-medium", children: "Nom du prompt Langfuse" }),
1956
+ /* @__PURE__ */ jsx(
1957
+ Input,
1958
+ {
1959
+ id: promptInputId,
1960
+ value: form.promptName,
1961
+ onChange: (e) => setForm({ ...form, promptName: e.target.value })
1962
+ }
1963
+ )
1964
+ ] }),
1965
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: "Laisser sur \xAB Nouveau prompt \xBB pour en cr\xE9er un ; choisir un prompt existant pour y rattacher l'agent. Le nom est \xE9crit tel quel, sans normalisation." })
1966
+ ] }),
1625
1967
  /* @__PURE__ */ jsxs("div", { children: [
1626
1968
  /* @__PURE__ */ jsx("label", { htmlFor: snapshotId, className: "mb-1 block text-sm font-medium", children: "Prompt de secours (niveau 3)" }),
1627
1969
  /* @__PURE__ */ jsx(
@@ -1821,6 +2163,8 @@ function AgentsPage() {
1821
2163
  const [formAgent, setFormAgent] = useState(null);
1822
2164
  const [versionsAgent, setVersionsAgent] = useState(null);
1823
2165
  const [deletingAgent, setDeletingAgent] = useState(null);
2166
+ const { prompts, isLoading: promptsLoading, error: promptsError } = usePromptCatalogue();
2167
+ const promptExists = (name) => promptsLoading || promptsError !== void 0 || prompts.some((entry) => entry.name === name);
1824
2168
  const recordPath = (id) => `/data/apps/${appSlug}/records/agent/${id}`;
1825
2169
  async function patchStatus(agent, status) {
1826
2170
  try {
@@ -1856,12 +2200,30 @@ function AgentsPage() {
1856
2200
  if (formAgent === "new") {
1857
2201
  await api.invoke(
1858
2202
  "create-agent",
1859
- { name: form.name, modelId: form.modelId, provider: form.provider, systemPromptSnapshot: form.systemPromptSnapshot },
2203
+ {
2204
+ name: form.name,
2205
+ modelId: form.modelId,
2206
+ provider: form.provider,
2207
+ systemPromptSnapshot: form.systemPromptSnapshot,
2208
+ // Verbatim (trim only) — empty means "derive agent/<id>", and an
2209
+ // empty label means "follow production" (stored null, never the
2210
+ // literal string).
2211
+ promptName: form.promptName.trim(),
2212
+ promptLabel: form.promptLabel.trim()
2213
+ },
1860
2214
  { idempotencyKey: crypto.randomUUID() }
1861
2215
  );
1862
2216
  } else if (formAgent) {
1863
2217
  await api.patch(recordPath(formAgent.id), {
1864
- data: { name: form.name, modelId: form.modelId, systemPromptSnapshot: form.systemPromptSnapshot }
2218
+ data: {
2219
+ name: form.name,
2220
+ modelId: form.modelId,
2221
+ provider: form.provider,
2222
+ systemPromptSnapshot: form.systemPromptSnapshot,
2223
+ promptName: form.promptName.trim(),
2224
+ promptLabel: form.promptLabel.trim() || null,
2225
+ ...formAgent.status !== "default" ? { status: form.status } : {}
2226
+ }
1865
2227
  });
1866
2228
  }
1867
2229
  setFormAgent(null);
@@ -1882,7 +2244,14 @@ function AgentsPage() {
1882
2244
  header: "Statut",
1883
2245
  cell: (row) => /* @__PURE__ */ jsx(Badge, { variant: STATUS_VARIANT[row.status] ?? "neutral", children: STATUS_LABELS[row.status] ?? row.status })
1884
2246
  },
1885
- { key: "promptName", header: "Prompt", cell: (row) => row.promptName },
2247
+ {
2248
+ key: "promptName",
2249
+ header: "Prompt",
2250
+ cell: (row) => /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-2", children: [
2251
+ row.promptName,
2252
+ !promptExists(row.promptName) && /* @__PURE__ */ jsx(Badge, { variant: "warning", children: "prompt introuvable chez Langfuse" })
2253
+ ] })
2254
+ },
1886
2255
  {
1887
2256
  key: "actions",
1888
2257
  header: "",
@@ -1928,7 +2297,16 @@ function AgentsPage() {
1928
2297
  empty: "Aucun agent configur\xE9."
1929
2298
  }
1930
2299
  ),
1931
- formAgent && /* @__PURE__ */ jsx(AgentFormModal, { agent: formAgent, onClose: () => setFormAgent(null), onSave: save }),
2300
+ formAgent && /* @__PURE__ */ jsx(
2301
+ AgentFormModal,
2302
+ {
2303
+ agent: formAgent,
2304
+ prompts,
2305
+ promptsLoading,
2306
+ onClose: () => setFormAgent(null),
2307
+ onSave: save
2308
+ }
2309
+ ),
1932
2310
  versionsAgent && /* @__PURE__ */ jsx(PromptVersionsPanel, { agent: versionsAgent, canWrite, onClose: () => setVersionsAgent(null) }),
1933
2311
  deletingAgent && /* @__PURE__ */ jsx(
1934
2312
  ConfirmModal,
@@ -2977,195 +3355,6 @@ function NumberField({ id, label, value, onChange, disabled, min, max, integer,
2977
3355
  hint && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: hint })
2978
3356
  ] });
2979
3357
  }
2980
-
2981
- // src/ui/settings/pipeline-nodes.ts
2982
- var PIPELINE_STEP_KEYS = ["triage", "escalate", "draft", "evaluate", "revise"];
2983
- var PIPELINE_STEPS = [
2984
- {
2985
- key: "triage",
2986
- label: "Triage",
2987
- description: "comprend et classe chaque demande entrante",
2988
- requires: null,
2989
- blockedReason: null
2990
- },
2991
- {
2992
- key: "escalate",
2993
- label: "Escalade",
2994
- description: "passe la main \xE0 un humain",
2995
- requires: null,
2996
- blockedReason: null
2997
- },
2998
- {
2999
- key: "draft",
3000
- label: "R\xE9daction",
3001
- description: "pr\xE9pare un projet de r\xE9ponse",
3002
- requires: null,
3003
- blockedReason: null
3004
- },
3005
- {
3006
- key: "evaluate",
3007
- label: "\xC9valuation",
3008
- description: "relit la r\xE9ponse avant envoi",
3009
- requires: "draft",
3010
- blockedReason: "Il n'y a rien \xE0 \xE9valuer sans r\xE9daction."
3011
- },
3012
- {
3013
- key: "revise",
3014
- label: "R\xE9vision",
3015
- description: "r\xE9\xE9crit la r\xE9ponse si l'\xE9valuation la juge insuffisante",
3016
- requires: "evaluate",
3017
- blockedReason: "Sans \xE9valuation, rien ne d\xE9clenche une r\xE9vision."
3018
- }
3019
- ];
3020
- var TRIAGE_LOCK_REASON = "Sans triage l'app ne traite rien.";
3021
- var STEP_BY_KEY = new Map(PIPELINE_STEPS.map((step) => [step.key, step]));
3022
- function pipelineStep(key) {
3023
- const step = STEP_BY_KEY.get(key);
3024
- if (!step) throw new Error(`unknown pipeline step: ${key}`);
3025
- return step;
3026
- }
3027
- function readNodes(value) {
3028
- if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
3029
- return value;
3030
- }
3031
- function readStep(value, key) {
3032
- const step = readNodes(value)[key];
3033
- if (typeof step !== "object" || step === null || Array.isArray(step)) return null;
3034
- return step;
3035
- }
3036
- function isStepEnabled(value, key) {
3037
- return readStep(value, key) !== null;
3038
- }
3039
- function stepBlockedReason(value, key) {
3040
- const { requires, blockedReason } = pipelineStep(key);
3041
- if (!requires) return null;
3042
- return isStepActive(value, requires) ? null : blockedReason;
3043
- }
3044
- function isStepActive(value, key) {
3045
- return isStepEnabled(value, key) && stepBlockedReason(value, key) === null;
3046
- }
3047
- function withStep(value, key, step) {
3048
- return { ...readNodes(value), [key]: step };
3049
- }
3050
- function withStepFields(value, key, patch) {
3051
- const step = readStep(value, key);
3052
- if (!step) return readNodes(value);
3053
- const next = { ...step };
3054
- for (const [field2, fieldValue] of Object.entries(patch)) {
3055
- if (fieldValue === void 0) delete next[field2];
3056
- else next[field2] = fieldValue;
3057
- }
3058
- return withStep(value, key, next);
3059
- }
3060
- function stepString(step, field2) {
3061
- const value = step?.[field2];
3062
- return typeof value === "string" ? value : "";
3063
- }
3064
- function stepNumber(step, field2, fallback) {
3065
- const value = step?.[field2];
3066
- return typeof value === "number" && Number.isFinite(value) ? value : fallback;
3067
- }
3068
- function stepBoolean(step, field2, fallback) {
3069
- const value = step?.[field2];
3070
- return typeof value === "boolean" ? value : fallback;
3071
- }
3072
- function stepUsesAgentPrompt(key) {
3073
- return key === "draft";
3074
- }
3075
- var DEFAULT_PROMPT_LABEL = "production";
3076
- function stepPromptName(step) {
3077
- return readPromptField(step, "name");
3078
- }
3079
- function stepPromptLabel(step) {
3080
- return readPromptField(step, "label") || DEFAULT_PROMPT_LABEL;
3081
- }
3082
- function readPromptField(step, field2) {
3083
- const prompt = step?.prompt;
3084
- if (typeof prompt !== "object" || prompt === null) return "";
3085
- const value = prompt[field2];
3086
- return typeof value === "string" ? value : "";
3087
- }
3088
- function promptPatch(name, label) {
3089
- return { prompt: { name, label } };
3090
- }
3091
- function stepReasoning(step) {
3092
- const value = step?.reasoning;
3093
- return REASONING_EFFORTS.some((effort) => effort.value === value) ? value : "off";
3094
- }
3095
- var REASONING_EFFORTS = [
3096
- { value: "off", label: "Aucun" },
3097
- { value: "low", label: "L\xE9ger" },
3098
- { value: "medium", label: "Moyen" },
3099
- { value: "high", label: "Pouss\xE9" }
3100
- ];
3101
- var KNOWN_MODELS = [
3102
- {
3103
- provider: "openai",
3104
- model: "gpt-4o-mini",
3105
- label: "GPT-4o mini",
3106
- hint: "Le moins cher, tr\xE8s rapide \u2014 suffisant pour classer"
3107
- },
3108
- {
3109
- provider: "openai",
3110
- model: "gpt-5-mini",
3111
- label: "GPT-5 mini",
3112
- hint: "Rapide, bon march\xE9, meilleur raisonnement"
3113
- },
3114
- {
3115
- provider: "openai",
3116
- model: "gpt-4.1",
3117
- label: "GPT-4.1",
3118
- hint: "Co\xFBt moyen \u2014 r\xE9daction soign\xE9e"
3119
- },
3120
- {
3121
- provider: "openai",
3122
- model: "gpt-5",
3123
- label: "GPT-5",
3124
- hint: "Le plus capable \u2014 le plus lent et le plus cher"
3125
- },
3126
- {
3127
- provider: "anthropic",
3128
- model: "claude-3-5-haiku-latest",
3129
- label: "Claude 3.5 Haiku",
3130
- hint: "Rapide et bon march\xE9"
3131
- },
3132
- {
3133
- provider: "anthropic",
3134
- model: "claude-3-5-sonnet-latest",
3135
- label: "Claude 3.5 Sonnet",
3136
- hint: "Co\xFBt moyen \u2014 r\xE9daction soign\xE9e"
3137
- }
3138
- ];
3139
- var CUSTOM_MODEL_VALUE = "__custom__";
3140
- function findModelOption(model) {
3141
- return KNOWN_MODELS.find((option) => option.model === model);
3142
- }
3143
- function defaultStep() {
3144
- const [first] = KNOWN_MODELS;
3145
- return { model: first.model, provider: first.provider, reasoning: "off" };
3146
- }
3147
- var PIPELINE_PRESETS = [
3148
- {
3149
- id: "triage-only",
3150
- label: "D\xE9marrage prudent \u2014 triage seul",
3151
- description: "Les demandes sont comprises et class\xE9es. Aucune r\xE9ponse n\u2019est pr\xE9par\xE9e.",
3152
- enabled: ["triage"]
3153
- },
3154
- {
3155
- id: "assisted",
3156
- label: "R\xE9ponse assist\xE9e",
3157
- description: "Triage, escalade et r\xE9daction : un projet de r\xE9ponse est pr\xE9par\xE9 pour un humain. L\u2019envoi automatique reste d\xE9sactiv\xE9.",
3158
- enabled: ["triage", "escalate", "draft"]
3159
- }
3160
- ];
3161
- function applyPreset(value, preset, restore) {
3162
- let next = readNodes(value);
3163
- for (const key of PIPELINE_STEP_KEYS) {
3164
- const on = preset.enabled.includes(key);
3165
- next = withStep(next, key, on ? readStep(next, key) ?? restore(key) : null);
3166
- }
3167
- return next;
3168
- }
3169
3358
  var PERCENT = 100;
3170
3359
  function PipelineNodesForm({
3171
3360
  value,
@@ -3485,37 +3674,6 @@ function useIds(stepKey) {
3485
3674
  minConfidence: `${base2}-${stepKey}-min-confidence`
3486
3675
  };
3487
3676
  }
3488
- function usePromptCatalogue() {
3489
- const { appSlug } = useAppContext();
3490
- const api = useAppApi();
3491
- const [prompts, setPrompts] = useState([]);
3492
- const [isLoading, setIsLoading] = useState(true);
3493
- const [error, setError] = useState(void 0);
3494
- const clientRef = useRef(api);
3495
- clientRef.current = api;
3496
- const requestIdRef = useRef(0);
3497
- const isMountedRef = useRef(true);
3498
- useEffect(() => {
3499
- isMountedRef.current = true;
3500
- const requestId = ++requestIdRef.current;
3501
- setIsLoading(true);
3502
- void clientRef.current.get(`/data/apps/${appSlug}/prompts`).then((catalogue) => {
3503
- if (requestId !== requestIdRef.current || !isMountedRef.current) return;
3504
- setPrompts(catalogue);
3505
- setError(void 0);
3506
- }).catch((err) => {
3507
- if (requestId !== requestIdRef.current || !isMountedRef.current) return;
3508
- setError(err);
3509
- }).finally(() => {
3510
- if (requestId !== requestIdRef.current || !isMountedRef.current) return;
3511
- setIsLoading(false);
3512
- });
3513
- return () => {
3514
- isMountedRef.current = false;
3515
- };
3516
- }, [appSlug]);
3517
- return { prompts, isLoading, error };
3518
- }
3519
3677
  var WHATSAPP_MODE_LABELS = {
3520
3678
  escalate_only: "Escalade uniquement",
3521
3679
  draft_only: "Brouillon uniquement",