@apotech-os/support-kit 2.9.1 → 3.0.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.cjs CHANGED
@@ -1568,6 +1568,321 @@ function PipelinePage() {
1568
1568
  )
1569
1569
  ] });
1570
1570
  }
1571
+ var AGENT_FIELD_NAME_UID = "e9cfec6f-15c6-4d02-8f79-0667f64b9eb5";
1572
+ var AGENT_FIELD_PROVIDER_UID = "e522b809-e8a7-4439-a2df-936158d04389";
1573
+ var AGENT_FIELD_MODEL_ID_UID = "d95977ba-362c-44d6-a2f0-24156c76cf8a";
1574
+ var AGENT_FIELD_STATUS_UID = "348725a0-a896-4f8d-8a56-86f4193234a8";
1575
+ var AGENT_FIELD_DEFAULT_KEY_UID = "0134491a-c969-4c42-894c-36ad4880fed3";
1576
+ var AGENT_FIELD_PROMPT_NAME_UID = "32e7f234-00bb-44d2-917b-be28f32f7214";
1577
+ var AGENT_FIELD_PROMPT_LABEL_UID = "bdee53ff-571a-4df6-91ec-00b513a70fe0";
1578
+ var AGENT_FIELD_PROMPT_VERSION_UID = "e7c66f99-e1e0-4fc2-9f9e-3bafe3af8e88";
1579
+ var AGENT_FIELD_SYSTEM_PROMPT_SNAPSHOT_UID = "710b73c6-929b-48b7-abc0-792849adf1c2";
1580
+ var AGENT_FIELD_REASONING_EFFORT_UID = "aa57fc6e-c989-47d3-9fc8-e04184b1e67c";
1581
+ var AGENT_FIELD_MAX_TOOL_CALLS_UID = "6948a5ca-48ef-45d7-9118-c7ab195343a3";
1582
+
1583
+ // src/records/agent.ts
1584
+ var AGENT_STATUSES = ["default", "available", "archived"];
1585
+ var REASONING_EFFORT_OPTIONS = ["off", "low", "medium", "high"];
1586
+ var DEFAULT_LLM_PROVIDER = "openai";
1587
+ ({
1588
+ fields: [
1589
+ {
1590
+ universalIdentifier: AGENT_FIELD_NAME_UID,
1591
+ name: "name",
1592
+ type: appKit.FieldType.TEXT,
1593
+ label: "Name",
1594
+ isNullable: false
1595
+ },
1596
+ {
1597
+ universalIdentifier: AGENT_FIELD_PROVIDER_UID,
1598
+ name: "provider",
1599
+ type: appKit.FieldType.TEXT,
1600
+ label: "Provider",
1601
+ description: "Free text (spec \xA73.4) \u2014 a new provider must not need a kit release.",
1602
+ isNullable: false,
1603
+ defaultValue: DEFAULT_LLM_PROVIDER
1604
+ },
1605
+ {
1606
+ universalIdentifier: AGENT_FIELD_MODEL_ID_UID,
1607
+ name: "modelId",
1608
+ type: appKit.FieldType.TEXT,
1609
+ label: "Model id",
1610
+ isNullable: false
1611
+ },
1612
+ {
1613
+ universalIdentifier: AGENT_FIELD_STATUS_UID,
1614
+ name: "status",
1615
+ type: appKit.FieldType.SELECT,
1616
+ label: "Status",
1617
+ isNullable: false,
1618
+ options: [...AGENT_STATUSES],
1619
+ defaultValue: "available"
1620
+ },
1621
+ {
1622
+ universalIdentifier: AGENT_FIELD_DEFAULT_KEY_UID,
1623
+ name: "defaultKey",
1624
+ type: appKit.FieldType.TEXT,
1625
+ label: "Default key",
1626
+ description: "Equals 'default' when status='default', absent otherwise. Unique.",
1627
+ isNullable: true
1628
+ },
1629
+ {
1630
+ universalIdentifier: AGENT_FIELD_PROMPT_NAME_UID,
1631
+ name: "promptName",
1632
+ type: appKit.FieldType.TEXT,
1633
+ label: "Prompt name",
1634
+ description: "Free Langfuse prompt name (ETL keeps legacy agent/<old id> names).",
1635
+ isNullable: false
1636
+ },
1637
+ {
1638
+ universalIdentifier: AGENT_FIELD_PROMPT_LABEL_UID,
1639
+ name: "promptLabel",
1640
+ type: appKit.FieldType.TEXT,
1641
+ label: "Prompt label",
1642
+ isNullable: true
1643
+ },
1644
+ {
1645
+ universalIdentifier: AGENT_FIELD_PROMPT_VERSION_UID,
1646
+ name: "promptVersion",
1647
+ type: appKit.FieldType.NUMBER,
1648
+ label: "Prompt version",
1649
+ description: 'Pinning; absent means "follow the label".',
1650
+ isNullable: true
1651
+ },
1652
+ {
1653
+ universalIdentifier: AGENT_FIELD_SYSTEM_PROMPT_SNAPSHOT_UID,
1654
+ name: "systemPromptSnapshot",
1655
+ type: appKit.FieldType.TEXT,
1656
+ label: "System prompt snapshot",
1657
+ description: "Level-3 fallback of the prompt ladder (\xA73.7).",
1658
+ isNullable: true
1659
+ },
1660
+ {
1661
+ universalIdentifier: AGENT_FIELD_REASONING_EFFORT_UID,
1662
+ name: "reasoningEffort",
1663
+ type: appKit.FieldType.SELECT,
1664
+ label: "Reasoning effort",
1665
+ isNullable: true,
1666
+ options: [...REASONING_EFFORT_OPTIONS]
1667
+ },
1668
+ {
1669
+ universalIdentifier: AGENT_FIELD_MAX_TOOL_CALLS_UID,
1670
+ name: "maxToolCalls",
1671
+ type: appKit.FieldType.NUMBER,
1672
+ label: "Max tool calls",
1673
+ isNullable: true
1674
+ }
1675
+ ]});
1676
+
1677
+ // src/ui/settings/pipeline-nodes.ts
1678
+ var PIPELINE_STEP_KEYS = ["triage", "escalate", "draft", "evaluate", "revise"];
1679
+ var PIPELINE_STEPS = [
1680
+ {
1681
+ key: "triage",
1682
+ label: "Triage",
1683
+ description: "comprend et classe chaque demande entrante",
1684
+ requires: null,
1685
+ blockedReason: null
1686
+ },
1687
+ {
1688
+ key: "escalate",
1689
+ label: "Escalade",
1690
+ description: "passe la main \xE0 un humain",
1691
+ requires: null,
1692
+ blockedReason: null
1693
+ },
1694
+ {
1695
+ key: "draft",
1696
+ label: "R\xE9daction",
1697
+ description: "pr\xE9pare un projet de r\xE9ponse",
1698
+ requires: null,
1699
+ blockedReason: null
1700
+ },
1701
+ {
1702
+ key: "evaluate",
1703
+ label: "\xC9valuation",
1704
+ description: "relit la r\xE9ponse avant envoi",
1705
+ requires: "draft",
1706
+ blockedReason: "Il n'y a rien \xE0 \xE9valuer sans r\xE9daction."
1707
+ },
1708
+ {
1709
+ key: "revise",
1710
+ label: "R\xE9vision",
1711
+ description: "r\xE9\xE9crit la r\xE9ponse si l'\xE9valuation la juge insuffisante",
1712
+ requires: "evaluate",
1713
+ blockedReason: "Sans \xE9valuation, rien ne d\xE9clenche une r\xE9vision."
1714
+ }
1715
+ ];
1716
+ var TRIAGE_LOCK_REASON = "Sans triage l'app ne traite rien.";
1717
+ var STEP_BY_KEY = new Map(PIPELINE_STEPS.map((step) => [step.key, step]));
1718
+ function pipelineStep(key) {
1719
+ const step = STEP_BY_KEY.get(key);
1720
+ if (!step) throw new Error(`unknown pipeline step: ${key}`);
1721
+ return step;
1722
+ }
1723
+ function readNodes(value) {
1724
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
1725
+ return value;
1726
+ }
1727
+ function readStep(value, key) {
1728
+ const step = readNodes(value)[key];
1729
+ if (typeof step !== "object" || step === null || Array.isArray(step)) return null;
1730
+ return step;
1731
+ }
1732
+ function isStepEnabled(value, key) {
1733
+ return readStep(value, key) !== null;
1734
+ }
1735
+ function stepBlockedReason(value, key) {
1736
+ const { requires, blockedReason } = pipelineStep(key);
1737
+ if (!requires) return null;
1738
+ return isStepActive(value, requires) ? null : blockedReason;
1739
+ }
1740
+ function isStepActive(value, key) {
1741
+ return isStepEnabled(value, key) && stepBlockedReason(value, key) === null;
1742
+ }
1743
+ function withStep(value, key, step) {
1744
+ return { ...readNodes(value), [key]: step };
1745
+ }
1746
+ function withStepFields(value, key, patch) {
1747
+ const step = readStep(value, key);
1748
+ if (!step) return readNodes(value);
1749
+ const next = { ...step };
1750
+ for (const [field2, fieldValue] of Object.entries(patch)) {
1751
+ if (fieldValue === void 0) delete next[field2];
1752
+ else next[field2] = fieldValue;
1753
+ }
1754
+ return withStep(value, key, next);
1755
+ }
1756
+ function stepString(step, field2) {
1757
+ const value = step?.[field2];
1758
+ return typeof value === "string" ? value : "";
1759
+ }
1760
+ function stepNumber(step, field2, fallback) {
1761
+ const value = step?.[field2];
1762
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
1763
+ }
1764
+ function stepBoolean(step, field2, fallback) {
1765
+ const value = step?.[field2];
1766
+ return typeof value === "boolean" ? value : fallback;
1767
+ }
1768
+ function stepUsesAgentPrompt(key) {
1769
+ return key === "draft" || key === "revise";
1770
+ }
1771
+ var DEFAULT_PROMPT_LABEL = "production";
1772
+ function stepPromptName(step) {
1773
+ return readPromptField(step, "name");
1774
+ }
1775
+ function stepPromptLabel(step) {
1776
+ return readPromptField(step, "label") || DEFAULT_PROMPT_LABEL;
1777
+ }
1778
+ function readPromptField(step, field2) {
1779
+ const prompt = step?.prompt;
1780
+ if (typeof prompt !== "object" || prompt === null) return "";
1781
+ const value = prompt[field2];
1782
+ return typeof value === "string" ? value : "";
1783
+ }
1784
+ function promptPatch(name, label) {
1785
+ return { prompt: { name, label } };
1786
+ }
1787
+ function stepReasoning(step) {
1788
+ const value = step?.reasoning;
1789
+ return REASONING_EFFORTS.some((effort) => effort.value === value) ? value : "off";
1790
+ }
1791
+ var REASONING_EFFORTS = [
1792
+ { value: "off", label: "Aucun" },
1793
+ { value: "low", label: "L\xE9ger" },
1794
+ { value: "medium", label: "Moyen" },
1795
+ { value: "high", label: "Pouss\xE9" }
1796
+ ];
1797
+ var CUSTOM_MODEL_VALUE = "__custom__";
1798
+ var DEFAULT_STEP_MODEL = "gpt-4o-mini";
1799
+ var DEFAULT_STEP_PROVIDER = "openai";
1800
+ function defaultStep() {
1801
+ return { model: DEFAULT_STEP_MODEL, provider: DEFAULT_STEP_PROVIDER, reasoning: "off" };
1802
+ }
1803
+ var PIPELINE_PRESETS = [
1804
+ {
1805
+ id: "triage-only",
1806
+ label: "D\xE9marrage prudent \u2014 triage seul",
1807
+ description: "Les demandes sont comprises et class\xE9es. Aucune r\xE9ponse n\u2019est pr\xE9par\xE9e.",
1808
+ enabled: ["triage"]
1809
+ },
1810
+ {
1811
+ id: "assisted",
1812
+ label: "R\xE9ponse assist\xE9e",
1813
+ 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.",
1814
+ enabled: ["triage", "escalate", "draft"]
1815
+ }
1816
+ ];
1817
+ function applyPreset(value, preset, restore) {
1818
+ let next = readNodes(value);
1819
+ for (const key of PIPELINE_STEP_KEYS) {
1820
+ const on = preset.enabled.includes(key);
1821
+ next = withStep(next, key, on ? readStep(next, key) ?? restore(key) : null);
1822
+ }
1823
+ return next;
1824
+ }
1825
+ function usePromptCatalogue() {
1826
+ const { appSlug } = uiSdk.useAppContext();
1827
+ const api = uiSdk.useAppApi();
1828
+ const [prompts, setPrompts] = react.useState([]);
1829
+ const [isLoading, setIsLoading] = react.useState(true);
1830
+ const [error, setError] = react.useState(void 0);
1831
+ const clientRef = react.useRef(api);
1832
+ clientRef.current = api;
1833
+ const requestIdRef = react.useRef(0);
1834
+ const isMountedRef = react.useRef(true);
1835
+ react.useEffect(() => {
1836
+ isMountedRef.current = true;
1837
+ const requestId = ++requestIdRef.current;
1838
+ setIsLoading(true);
1839
+ void clientRef.current.get(`/data/apps/${appSlug}/prompts`).then((catalogue) => {
1840
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1841
+ setPrompts(catalogue);
1842
+ setError(void 0);
1843
+ }).catch((err) => {
1844
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1845
+ setError(err);
1846
+ }).finally(() => {
1847
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1848
+ setIsLoading(false);
1849
+ });
1850
+ return () => {
1851
+ isMountedRef.current = false;
1852
+ };
1853
+ }, [appSlug]);
1854
+ return { prompts, isLoading, error };
1855
+ }
1856
+ function useModelCatalogue() {
1857
+ const api = uiSdk.useAppApi();
1858
+ const [models, setModels] = react.useState([]);
1859
+ const [isLoading, setIsLoading] = react.useState(true);
1860
+ const [error, setError] = react.useState(void 0);
1861
+ const clientRef = react.useRef(api);
1862
+ clientRef.current = api;
1863
+ const requestIdRef = react.useRef(0);
1864
+ const isMountedRef = react.useRef(true);
1865
+ react.useEffect(() => {
1866
+ isMountedRef.current = true;
1867
+ const requestId = ++requestIdRef.current;
1868
+ setIsLoading(true);
1869
+ void clientRef.current.get("/data/llm/models").then((catalogue) => {
1870
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1871
+ setModels(catalogue.models);
1872
+ setError(void 0);
1873
+ }).catch((err) => {
1874
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1875
+ setError(err);
1876
+ }).finally(() => {
1877
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
1878
+ setIsLoading(false);
1879
+ });
1880
+ return () => {
1881
+ isMountedRef.current = false;
1882
+ };
1883
+ }, []);
1884
+ return { models, isLoading, error };
1885
+ }
1571
1886
  function ConfirmModal({
1572
1887
  title,
1573
1888
  description,
@@ -1771,18 +2086,34 @@ var STATUS_VARIANT = {
1771
2086
  archived: "outline"
1772
2087
  };
1773
2088
  function emptyForm() {
1774
- return { name: "", modelId: "", provider: "openai", systemPromptSnapshot: "" };
2089
+ return {
2090
+ name: "",
2091
+ modelId: "",
2092
+ provider: DEFAULT_LLM_PROVIDER,
2093
+ status: "available",
2094
+ promptName: "",
2095
+ promptLabel: "",
2096
+ systemPromptSnapshot: ""
2097
+ };
1775
2098
  }
1776
2099
  function formFromAgent(agent) {
1777
2100
  return {
1778
2101
  name: agent.name,
1779
2102
  modelId: agent.modelId,
1780
2103
  provider: agent.provider,
2104
+ status: agent.status,
2105
+ promptName: agent.promptName,
2106
+ promptLabel: agent.promptLabel ?? "",
1781
2107
  systemPromptSnapshot: agent.systemPromptSnapshot ?? ""
1782
2108
  };
1783
2109
  }
2110
+ var DERIVED_PROMPT_VALUE = "__derived__";
2111
+ var CUSTOM_PROMPT_VALUE = "__custom-prompt__";
2112
+ var DEFAULT_LABEL_VALUE = "__production__";
1784
2113
  function AgentFormModal({
1785
2114
  agent,
2115
+ prompts,
2116
+ promptsLoading,
1786
2117
  onClose,
1787
2118
  onSave
1788
2119
  }) {
@@ -1790,10 +2121,20 @@ function AgentFormModal({
1790
2121
  agent === "new" ? emptyForm() : formFromAgent(agent)
1791
2122
  );
1792
2123
  const [isSaving, setIsSaving] = react.useState(false);
2124
+ const [freeTextModel, setFreeTextModel] = react.useState(false);
2125
+ const [freeTextPrompt, setFreeTextPrompt] = react.useState(false);
1793
2126
  const nameId = react.useId();
1794
- const modelId = react.useId();
2127
+ const modelInputId = react.useId();
2128
+ const providerInputId = react.useId();
2129
+ const promptInputId = react.useId();
1795
2130
  const snapshotId = react.useId();
1796
- const isValid = form.name.trim() !== "" && form.modelId.trim() !== "";
2131
+ const { models, isLoading: modelsLoading } = useModelCatalogue();
2132
+ const knownModel = models.includes(form.modelId);
2133
+ const showModelFreeText = freeTextModel || form.modelId !== "" && !knownModel && !modelsLoading;
2134
+ const knownPrompt = prompts.find((entry) => entry.name === form.promptName);
2135
+ const showPromptFreeText = freeTextPrompt || agent !== "new" && form.promptName !== "" && !knownPrompt && !promptsLoading;
2136
+ const promptLabels = knownPrompt?.labels ?? [];
2137
+ const isValid = form.name.trim() !== "" && form.modelId.trim() !== "" && (agent === "new" || form.promptName.trim() !== "");
1797
2138
  async function submit(event) {
1798
2139
  event.preventDefault();
1799
2140
  if (isSaving || !isValid) return;
@@ -1804,6 +2145,14 @@ function AgentFormModal({
1804
2145
  setIsSaving(false);
1805
2146
  }
1806
2147
  }
2148
+ function pickPrompt(next) {
2149
+ if (next === CUSTOM_PROMPT_VALUE) {
2150
+ setFreeTextPrompt(true);
2151
+ return;
2152
+ }
2153
+ setFreeTextPrompt(false);
2154
+ setForm({ ...form, promptName: next === DERIVED_PROMPT_VALUE ? "" : next, promptLabel: "" });
2155
+ }
1807
2156
  return /* @__PURE__ */ jsxRuntime.jsx(
1808
2157
  uiSdk.Modal,
1809
2158
  {
@@ -1815,24 +2164,109 @@ function AgentFormModal({
1815
2164
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
1816
2165
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Input, { id: nameId, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) })
1817
2166
  ] }),
1818
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1819
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: modelId, className: "mb-1 block text-sm font-medium", children: "Mod\xE8le" }),
2167
+ agent !== "new" && agent.status !== "default" && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2168
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Statut" }),
1820
2169
  /* @__PURE__ */ jsxRuntime.jsx(
1821
- uiSdk.Input,
2170
+ uiSdk.Select,
1822
2171
  {
1823
- id: modelId,
1824
- value: form.modelId,
1825
- onChange: (e) => setForm({ ...form, modelId: e.target.value })
2172
+ "aria-label": "Statut",
2173
+ value: form.status,
2174
+ onValueChange: (next) => setForm({ ...form, status: next }),
2175
+ items: [
2176
+ { value: "available", label: STATUS_LABELS.available },
2177
+ { value: "archived", label: STATUS_LABELS.archived }
2178
+ ]
1826
2179
  }
1827
2180
  )
1828
2181
  ] }),
1829
2182
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1830
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Fournisseur" }),
1831
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
1832
- form.provider,
1833
- " \u2014 non modifiable ici ; le fournisseur r\xE9ellement appel\xE9 est celui des Param\xE8tres."
2183
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Mod\xE8le" }),
2184
+ /* @__PURE__ */ jsxRuntime.jsx(
2185
+ uiSdk.Select,
2186
+ {
2187
+ "aria-label": "Mod\xE8le",
2188
+ value: showModelFreeText ? CUSTOM_MODEL_VALUE : knownModel ? form.modelId : void 0,
2189
+ onValueChange: (next) => {
2190
+ if (next === CUSTOM_MODEL_VALUE) {
2191
+ setFreeTextModel(true);
2192
+ return;
2193
+ }
2194
+ setFreeTextModel(false);
2195
+ setForm({ ...form, modelId: next, provider: DEFAULT_STEP_PROVIDER });
2196
+ },
2197
+ items: [
2198
+ ...models.map((name) => ({ value: name, label: name })),
2199
+ { value: CUSTOM_MODEL_VALUE, label: "Autre \u2014 saisir un identifiant de mod\xE8le" }
2200
+ ],
2201
+ disabled: modelsLoading
2202
+ }
2203
+ ),
2204
+ showModelFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 space-y-2", children: [
2205
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: modelInputId, className: "mb-1 block text-sm font-medium", children: "Identifiant de mod\xE8le" }),
2206
+ /* @__PURE__ */ jsxRuntime.jsx(
2207
+ uiSdk.Input,
2208
+ {
2209
+ id: modelInputId,
2210
+ value: form.modelId,
2211
+ onChange: (e) => setForm({ ...form, modelId: e.target.value })
2212
+ }
2213
+ ),
2214
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: providerInputId, className: "mb-1 block text-sm font-medium", children: "Fournisseur" }),
2215
+ /* @__PURE__ */ jsxRuntime.jsx(
2216
+ uiSdk.Input,
2217
+ {
2218
+ id: providerInputId,
2219
+ value: form.provider,
2220
+ onChange: (e) => setForm({ ...form, provider: e.target.value })
2221
+ }
2222
+ )
1834
2223
  ] })
1835
2224
  ] }),
2225
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2226
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Prompt Langfuse" }),
2227
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
2228
+ /* @__PURE__ */ jsxRuntime.jsx(
2229
+ uiSdk.Select,
2230
+ {
2231
+ "aria-label": "Prompt Langfuse",
2232
+ value: showPromptFreeText ? CUSTOM_PROMPT_VALUE : knownPrompt ? form.promptName : agent === "new" ? DERIVED_PROMPT_VALUE : void 0,
2233
+ onValueChange: pickPrompt,
2234
+ items: [
2235
+ ...agent === "new" ? [{ value: DERIVED_PROMPT_VALUE, label: "Nouveau prompt \u2014 agent/<g\xE9n\xE9r\xE9 automatiquement>" }] : [],
2236
+ ...prompts.map((entry) => ({ value: entry.name, label: entry.name })),
2237
+ { value: CUSTOM_PROMPT_VALUE, label: "Autre \u2014 saisir un nom de prompt" }
2238
+ ],
2239
+ disabled: promptsLoading
2240
+ }
2241
+ ),
2242
+ /* @__PURE__ */ jsxRuntime.jsx(
2243
+ uiSdk.Select,
2244
+ {
2245
+ "aria-label": "Tag du prompt",
2246
+ value: form.promptLabel === "" ? DEFAULT_LABEL_VALUE : form.promptLabel,
2247
+ onValueChange: (next) => setForm({ ...form, promptLabel: next === DEFAULT_LABEL_VALUE ? "" : next }),
2248
+ items: [
2249
+ { value: DEFAULT_LABEL_VALUE, label: "production (par d\xE9faut)" },
2250
+ ...promptLabels.filter((label) => label !== DEFAULT_PROMPT_LABEL).map((label) => ({ value: label, label })),
2251
+ ...form.promptLabel !== "" && !promptLabels.includes(form.promptLabel) ? [{ value: form.promptLabel, label: form.promptLabel }] : []
2252
+ ],
2253
+ disabled: promptsLoading || form.promptName === "" && !showPromptFreeText
2254
+ }
2255
+ )
2256
+ ] }),
2257
+ showPromptFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2", children: [
2258
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: promptInputId, className: "mb-1 block text-sm font-medium", children: "Nom du prompt Langfuse" }),
2259
+ /* @__PURE__ */ jsxRuntime.jsx(
2260
+ uiSdk.Input,
2261
+ {
2262
+ id: promptInputId,
2263
+ value: form.promptName,
2264
+ onChange: (e) => setForm({ ...form, promptName: e.target.value })
2265
+ }
2266
+ )
2267
+ ] }),
2268
+ /* @__PURE__ */ jsxRuntime.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." })
2269
+ ] }),
1836
2270
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1837
2271
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: snapshotId, className: "mb-1 block text-sm font-medium", children: "Prompt de secours (niveau 3)" }),
1838
2272
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -2032,6 +2466,8 @@ function AgentsPage() {
2032
2466
  const [formAgent, setFormAgent] = react.useState(null);
2033
2467
  const [versionsAgent, setVersionsAgent] = react.useState(null);
2034
2468
  const [deletingAgent, setDeletingAgent] = react.useState(null);
2469
+ const { prompts, isLoading: promptsLoading, error: promptsError } = usePromptCatalogue();
2470
+ const promptExists = (name) => promptsLoading || promptsError !== void 0 || prompts.some((entry) => entry.name === name);
2035
2471
  const recordPath = (id) => `/data/apps/${appSlug}/records/agent/${id}`;
2036
2472
  async function patchStatus(agent, status) {
2037
2473
  try {
@@ -2067,12 +2503,30 @@ function AgentsPage() {
2067
2503
  if (formAgent === "new") {
2068
2504
  await api.invoke(
2069
2505
  "create-agent",
2070
- { name: form.name, modelId: form.modelId, provider: form.provider, systemPromptSnapshot: form.systemPromptSnapshot },
2506
+ {
2507
+ name: form.name,
2508
+ modelId: form.modelId,
2509
+ provider: form.provider,
2510
+ systemPromptSnapshot: form.systemPromptSnapshot,
2511
+ // Verbatim (trim only) — empty means "derive agent/<id>", and an
2512
+ // empty label means "follow production" (stored null, never the
2513
+ // literal string).
2514
+ promptName: form.promptName.trim(),
2515
+ promptLabel: form.promptLabel.trim()
2516
+ },
2071
2517
  { idempotencyKey: crypto.randomUUID() }
2072
2518
  );
2073
2519
  } else if (formAgent) {
2074
2520
  await api.patch(recordPath(formAgent.id), {
2075
- data: { name: form.name, modelId: form.modelId, systemPromptSnapshot: form.systemPromptSnapshot }
2521
+ data: {
2522
+ name: form.name,
2523
+ modelId: form.modelId,
2524
+ provider: form.provider,
2525
+ systemPromptSnapshot: form.systemPromptSnapshot,
2526
+ promptName: form.promptName.trim(),
2527
+ promptLabel: form.promptLabel.trim() || null,
2528
+ ...formAgent.status !== "default" ? { status: form.status } : {}
2529
+ }
2076
2530
  });
2077
2531
  }
2078
2532
  setFormAgent(null);
@@ -2093,7 +2547,14 @@ function AgentsPage() {
2093
2547
  header: "Statut",
2094
2548
  cell: (row) => /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: STATUS_VARIANT[row.status] ?? "neutral", children: STATUS_LABELS[row.status] ?? row.status })
2095
2549
  },
2096
- { key: "promptName", header: "Prompt", cell: (row) => row.promptName },
2550
+ {
2551
+ key: "promptName",
2552
+ header: "Prompt",
2553
+ cell: (row) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-2", children: [
2554
+ row.promptName,
2555
+ !promptExists(row.promptName) && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "warning", children: "prompt introuvable chez Langfuse" })
2556
+ ] })
2557
+ },
2097
2558
  {
2098
2559
  key: "actions",
2099
2560
  header: "",
@@ -2139,7 +2600,16 @@ function AgentsPage() {
2139
2600
  empty: "Aucun agent configur\xE9."
2140
2601
  }
2141
2602
  ),
2142
- formAgent && /* @__PURE__ */ jsxRuntime.jsx(AgentFormModal, { agent: formAgent, onClose: () => setFormAgent(null), onSave: save }),
2603
+ formAgent && /* @__PURE__ */ jsxRuntime.jsx(
2604
+ AgentFormModal,
2605
+ {
2606
+ agent: formAgent,
2607
+ prompts,
2608
+ promptsLoading,
2609
+ onClose: () => setFormAgent(null),
2610
+ onSave: save
2611
+ }
2612
+ ),
2143
2613
  versionsAgent && /* @__PURE__ */ jsxRuntime.jsx(PromptVersionsPanel, { agent: versionsAgent, canWrite, onClose: () => setVersionsAgent(null) }),
2144
2614
  deletingAgent && /* @__PURE__ */ jsxRuntime.jsx(
2145
2615
  ConfirmModal,
@@ -3153,176 +3623,71 @@ function CorrectionsPage() {
3153
3623
  ),
3154
3624
  pendingDeleteAll && /* @__PURE__ */ jsxRuntime.jsx(
3155
3625
  ConfirmModal,
3156
- {
3157
- title: "Supprimer toutes les comparaisons de cet agent ?",
3158
- description: `Toutes les comparaisons de \xAB ${selectedAgent?.name ?? agentFilter} \xBB sur cette page seront supprim\xE9es. Cette action est irr\xE9versible.`,
3159
- confirmLabel: "Tout supprimer",
3160
- onConfirm: confirmDeleteAll,
3161
- onCancel: () => setPendingDeleteAll(false)
3162
- }
3163
- )
3164
- ] });
3165
- }
3166
-
3167
- // src/settings/validate.ts
3168
- function validateSettings(settings) {
3169
- const issues = [];
3170
- if (!isNonEmptyString(settings.sourceViewId)) {
3171
- issues.push({
3172
- key: "sourceViewId",
3173
- message: "sourceViewId is required \u2014 pick the Gorgias view this app owns."
3174
- });
3175
- }
3176
- if (!isConfiguredNode(settings.nodes)) {
3177
- issues.push({
3178
- key: "nodes",
3179
- message: "nodes.triage must be configured \u2014 a null triage step would triage nothing."
3180
- });
3181
- }
3182
- const stepsWithoutPrompt = stepsMissingPrompt(settings.nodes);
3183
- if (stepsWithoutPrompt.length > 0) {
3184
- issues.push({
3185
- key: "nodePrompt",
3186
- message: `Every active step needs a Langfuse prompt \u2014 missing on: ${stepsWithoutPrompt.join(", ")}.`
3187
- });
3188
- }
3189
- const autoSendEnabled = settings.autoSendEnabled === true;
3190
- const isWhatsappAutoReply = settings.whatsappMode === "auto_reply";
3191
- if (autoSendEnabled && !isWhatsappAutoReply && !isNonEmptyString(settings.senderEmail)) {
3192
- issues.push({
3193
- key: "senderEmail",
3194
- message: "senderEmail is required when autoSendEnabled is on, unless whatsappMode is 'auto_reply'."
3195
- });
3196
- }
3197
- return issues;
3198
- }
3199
- function isNonEmptyString(value) {
3200
- return typeof value === "string" && value.length > 0;
3201
- }
3202
- var STEPS_REQUIRING_PROMPT = ["triage", "escalate", "evaluate", "revise"];
3203
- function stepsMissingPrompt(nodes) {
3204
- if (typeof nodes !== "object" || nodes === null) return [];
3205
- const byStep = nodes;
3206
- return STEPS_REQUIRING_PROMPT.filter((step) => {
3207
- const node = byStep[step];
3208
- if (typeof node !== "object" || node === null) return false;
3209
- return !isNonEmptyString(promptNameOf(node));
3210
- });
3211
- }
3212
- function promptNameOf(node) {
3213
- const prompt = node.prompt;
3214
- return typeof prompt === "object" && prompt !== null ? prompt.name : void 0;
3215
- }
3216
- function isConfiguredNode(nodes) {
3217
- if (typeof nodes !== "object" || nodes === null) return false;
3218
- const triage = nodes.triage;
3219
- return typeof triage === "object" && triage !== null;
3220
- }
3221
- var AGENT_FIELD_NAME_UID = "e9cfec6f-15c6-4d02-8f79-0667f64b9eb5";
3222
- var AGENT_FIELD_PROVIDER_UID = "e522b809-e8a7-4439-a2df-936158d04389";
3223
- var AGENT_FIELD_MODEL_ID_UID = "d95977ba-362c-44d6-a2f0-24156c76cf8a";
3224
- var AGENT_FIELD_STATUS_UID = "348725a0-a896-4f8d-8a56-86f4193234a8";
3225
- var AGENT_FIELD_DEFAULT_KEY_UID = "0134491a-c969-4c42-894c-36ad4880fed3";
3226
- var AGENT_FIELD_PROMPT_NAME_UID = "32e7f234-00bb-44d2-917b-be28f32f7214";
3227
- var AGENT_FIELD_PROMPT_LABEL_UID = "bdee53ff-571a-4df6-91ec-00b513a70fe0";
3228
- var AGENT_FIELD_PROMPT_VERSION_UID = "e7c66f99-e1e0-4fc2-9f9e-3bafe3af8e88";
3229
- var AGENT_FIELD_SYSTEM_PROMPT_SNAPSHOT_UID = "710b73c6-929b-48b7-abc0-792849adf1c2";
3230
- var AGENT_FIELD_REASONING_EFFORT_UID = "aa57fc6e-c989-47d3-9fc8-e04184b1e67c";
3231
- var AGENT_FIELD_MAX_TOOL_CALLS_UID = "6948a5ca-48ef-45d7-9118-c7ab195343a3";
3232
-
3233
- // src/records/agent.ts
3234
- var AGENT_STATUSES = ["default", "available", "archived"];
3235
- var REASONING_EFFORT_OPTIONS = ["off", "low", "medium", "high"];
3236
- var DEFAULT_LLM_PROVIDER = "openai";
3237
- ({
3238
- fields: [
3239
- {
3240
- universalIdentifier: AGENT_FIELD_NAME_UID,
3241
- name: "name",
3242
- type: appKit.FieldType.TEXT,
3243
- label: "Name",
3244
- isNullable: false
3245
- },
3246
- {
3247
- universalIdentifier: AGENT_FIELD_PROVIDER_UID,
3248
- name: "provider",
3249
- type: appKit.FieldType.TEXT,
3250
- label: "Provider",
3251
- description: "Free text (spec \xA73.4) \u2014 a new provider must not need a kit release.",
3252
- isNullable: false,
3253
- defaultValue: DEFAULT_LLM_PROVIDER
3254
- },
3255
- {
3256
- universalIdentifier: AGENT_FIELD_MODEL_ID_UID,
3257
- name: "modelId",
3258
- type: appKit.FieldType.TEXT,
3259
- label: "Model id",
3260
- isNullable: false
3261
- },
3262
- {
3263
- universalIdentifier: AGENT_FIELD_STATUS_UID,
3264
- name: "status",
3265
- type: appKit.FieldType.SELECT,
3266
- label: "Status",
3267
- isNullable: false,
3268
- options: [...AGENT_STATUSES],
3269
- defaultValue: "available"
3270
- },
3271
- {
3272
- universalIdentifier: AGENT_FIELD_DEFAULT_KEY_UID,
3273
- name: "defaultKey",
3274
- type: appKit.FieldType.TEXT,
3275
- label: "Default key",
3276
- description: "Equals 'default' when status='default', absent otherwise. Unique.",
3277
- isNullable: true
3278
- },
3279
- {
3280
- universalIdentifier: AGENT_FIELD_PROMPT_NAME_UID,
3281
- name: "promptName",
3282
- type: appKit.FieldType.TEXT,
3283
- label: "Prompt name",
3284
- description: "Free Langfuse prompt name (ETL keeps legacy agent/<old id> names).",
3285
- isNullable: false
3286
- },
3287
- {
3288
- universalIdentifier: AGENT_FIELD_PROMPT_LABEL_UID,
3289
- name: "promptLabel",
3290
- type: appKit.FieldType.TEXT,
3291
- label: "Prompt label",
3292
- isNullable: true
3293
- },
3294
- {
3295
- universalIdentifier: AGENT_FIELD_PROMPT_VERSION_UID,
3296
- name: "promptVersion",
3297
- type: appKit.FieldType.NUMBER,
3298
- label: "Prompt version",
3299
- description: 'Pinning; absent means "follow the label".',
3300
- isNullable: true
3301
- },
3302
- {
3303
- universalIdentifier: AGENT_FIELD_SYSTEM_PROMPT_SNAPSHOT_UID,
3304
- name: "systemPromptSnapshot",
3305
- type: appKit.FieldType.TEXT,
3306
- label: "System prompt snapshot",
3307
- description: "Level-3 fallback of the prompt ladder (\xA73.7).",
3308
- isNullable: true
3309
- },
3310
- {
3311
- universalIdentifier: AGENT_FIELD_REASONING_EFFORT_UID,
3312
- name: "reasoningEffort",
3313
- type: appKit.FieldType.SELECT,
3314
- label: "Reasoning effort",
3315
- isNullable: true,
3316
- options: [...REASONING_EFFORT_OPTIONS]
3317
- },
3318
- {
3319
- universalIdentifier: AGENT_FIELD_MAX_TOOL_CALLS_UID,
3320
- name: "maxToolCalls",
3321
- type: appKit.FieldType.NUMBER,
3322
- label: "Max tool calls",
3323
- isNullable: true
3324
- }
3325
- ]});
3626
+ {
3627
+ title: "Supprimer toutes les comparaisons de cet agent ?",
3628
+ description: `Toutes les comparaisons de \xAB ${selectedAgent?.name ?? agentFilter} \xBB sur cette page seront supprim\xE9es. Cette action est irr\xE9versible.`,
3629
+ confirmLabel: "Tout supprimer",
3630
+ onConfirm: confirmDeleteAll,
3631
+ onCancel: () => setPendingDeleteAll(false)
3632
+ }
3633
+ )
3634
+ ] });
3635
+ }
3636
+
3637
+ // src/settings/validate.ts
3638
+ function validateSettings(settings) {
3639
+ const issues = [];
3640
+ if (!isNonEmptyString(settings.sourceViewId)) {
3641
+ issues.push({
3642
+ key: "sourceViewId",
3643
+ message: "sourceViewId is required \u2014 pick the Gorgias view this app owns."
3644
+ });
3645
+ }
3646
+ if (!isConfiguredNode(settings.nodes)) {
3647
+ issues.push({
3648
+ key: "nodes",
3649
+ message: "nodes.triage must be configured \u2014 a null triage step would triage nothing."
3650
+ });
3651
+ }
3652
+ const stepsWithoutPrompt = stepsMissingPrompt(settings.nodes);
3653
+ if (stepsWithoutPrompt.length > 0) {
3654
+ issues.push({
3655
+ key: "nodePrompt",
3656
+ message: `Every active step needs a Langfuse prompt \u2014 missing on: ${stepsWithoutPrompt.join(", ")}.`
3657
+ });
3658
+ }
3659
+ const autoSendEnabled = settings.autoSendEnabled === true;
3660
+ const isWhatsappAutoReply = settings.whatsappMode === "auto_reply";
3661
+ if (autoSendEnabled && !isWhatsappAutoReply && !isNonEmptyString(settings.senderEmail)) {
3662
+ issues.push({
3663
+ key: "senderEmail",
3664
+ message: "senderEmail is required when autoSendEnabled is on, unless whatsappMode is 'auto_reply'."
3665
+ });
3666
+ }
3667
+ return issues;
3668
+ }
3669
+ function isNonEmptyString(value) {
3670
+ return typeof value === "string" && value.length > 0;
3671
+ }
3672
+ var STEPS_REQUIRING_PROMPT = ["triage", "escalate", "evaluate"];
3673
+ function stepsMissingPrompt(nodes) {
3674
+ if (typeof nodes !== "object" || nodes === null) return [];
3675
+ const byStep = nodes;
3676
+ return STEPS_REQUIRING_PROMPT.filter((step) => {
3677
+ const node = byStep[step];
3678
+ if (typeof node !== "object" || node === null) return false;
3679
+ return !isNonEmptyString(promptNameOf(node));
3680
+ });
3681
+ }
3682
+ function promptNameOf(node) {
3683
+ const prompt = node.prompt;
3684
+ return typeof prompt === "object" && prompt !== null ? prompt.name : void 0;
3685
+ }
3686
+ function isConfiguredNode(nodes) {
3687
+ if (typeof nodes !== "object" || nodes === null) return false;
3688
+ const triage = nodes.triage;
3689
+ return typeof triage === "object" && triage !== null;
3690
+ }
3326
3691
 
3327
3692
  // src/settings/to-profile.ts
3328
3693
  var DEFAULT_REASONING = "off";
@@ -3453,195 +3818,6 @@ function NumberField({ id, label, value, onChange, disabled, min, max, integer,
3453
3818
  hint && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: hint })
3454
3819
  ] });
3455
3820
  }
3456
-
3457
- // src/ui/settings/pipeline-nodes.ts
3458
- var PIPELINE_STEP_KEYS = ["triage", "escalate", "draft", "evaluate", "revise"];
3459
- var PIPELINE_STEPS = [
3460
- {
3461
- key: "triage",
3462
- label: "Triage",
3463
- description: "comprend et classe chaque demande entrante",
3464
- requires: null,
3465
- blockedReason: null
3466
- },
3467
- {
3468
- key: "escalate",
3469
- label: "Escalade",
3470
- description: "passe la main \xE0 un humain",
3471
- requires: null,
3472
- blockedReason: null
3473
- },
3474
- {
3475
- key: "draft",
3476
- label: "R\xE9daction",
3477
- description: "pr\xE9pare un projet de r\xE9ponse",
3478
- requires: null,
3479
- blockedReason: null
3480
- },
3481
- {
3482
- key: "evaluate",
3483
- label: "\xC9valuation",
3484
- description: "relit la r\xE9ponse avant envoi",
3485
- requires: "draft",
3486
- blockedReason: "Il n'y a rien \xE0 \xE9valuer sans r\xE9daction."
3487
- },
3488
- {
3489
- key: "revise",
3490
- label: "R\xE9vision",
3491
- description: "r\xE9\xE9crit la r\xE9ponse si l'\xE9valuation la juge insuffisante",
3492
- requires: "evaluate",
3493
- blockedReason: "Sans \xE9valuation, rien ne d\xE9clenche une r\xE9vision."
3494
- }
3495
- ];
3496
- var TRIAGE_LOCK_REASON = "Sans triage l'app ne traite rien.";
3497
- var STEP_BY_KEY = new Map(PIPELINE_STEPS.map((step) => [step.key, step]));
3498
- function pipelineStep(key) {
3499
- const step = STEP_BY_KEY.get(key);
3500
- if (!step) throw new Error(`unknown pipeline step: ${key}`);
3501
- return step;
3502
- }
3503
- function readNodes(value) {
3504
- if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
3505
- return value;
3506
- }
3507
- function readStep(value, key) {
3508
- const step = readNodes(value)[key];
3509
- if (typeof step !== "object" || step === null || Array.isArray(step)) return null;
3510
- return step;
3511
- }
3512
- function isStepEnabled(value, key) {
3513
- return readStep(value, key) !== null;
3514
- }
3515
- function stepBlockedReason(value, key) {
3516
- const { requires, blockedReason } = pipelineStep(key);
3517
- if (!requires) return null;
3518
- return isStepActive(value, requires) ? null : blockedReason;
3519
- }
3520
- function isStepActive(value, key) {
3521
- return isStepEnabled(value, key) && stepBlockedReason(value, key) === null;
3522
- }
3523
- function withStep(value, key, step) {
3524
- return { ...readNodes(value), [key]: step };
3525
- }
3526
- function withStepFields(value, key, patch) {
3527
- const step = readStep(value, key);
3528
- if (!step) return readNodes(value);
3529
- const next = { ...step };
3530
- for (const [field2, fieldValue] of Object.entries(patch)) {
3531
- if (fieldValue === void 0) delete next[field2];
3532
- else next[field2] = fieldValue;
3533
- }
3534
- return withStep(value, key, next);
3535
- }
3536
- function stepString(step, field2) {
3537
- const value = step?.[field2];
3538
- return typeof value === "string" ? value : "";
3539
- }
3540
- function stepNumber(step, field2, fallback) {
3541
- const value = step?.[field2];
3542
- return typeof value === "number" && Number.isFinite(value) ? value : fallback;
3543
- }
3544
- function stepBoolean(step, field2, fallback) {
3545
- const value = step?.[field2];
3546
- return typeof value === "boolean" ? value : fallback;
3547
- }
3548
- function stepUsesAgentPrompt(key) {
3549
- return key === "draft";
3550
- }
3551
- var DEFAULT_PROMPT_LABEL = "production";
3552
- function stepPromptName(step) {
3553
- return readPromptField(step, "name");
3554
- }
3555
- function stepPromptLabel(step) {
3556
- return readPromptField(step, "label") || DEFAULT_PROMPT_LABEL;
3557
- }
3558
- function readPromptField(step, field2) {
3559
- const prompt = step?.prompt;
3560
- if (typeof prompt !== "object" || prompt === null) return "";
3561
- const value = prompt[field2];
3562
- return typeof value === "string" ? value : "";
3563
- }
3564
- function promptPatch(name, label) {
3565
- return { prompt: { name, label } };
3566
- }
3567
- function stepReasoning(step) {
3568
- const value = step?.reasoning;
3569
- return REASONING_EFFORTS.some((effort) => effort.value === value) ? value : "off";
3570
- }
3571
- var REASONING_EFFORTS = [
3572
- { value: "off", label: "Aucun" },
3573
- { value: "low", label: "L\xE9ger" },
3574
- { value: "medium", label: "Moyen" },
3575
- { value: "high", label: "Pouss\xE9" }
3576
- ];
3577
- var KNOWN_MODELS = [
3578
- {
3579
- provider: "openai",
3580
- model: "gpt-4o-mini",
3581
- label: "GPT-4o mini",
3582
- hint: "Le moins cher, tr\xE8s rapide \u2014 suffisant pour classer"
3583
- },
3584
- {
3585
- provider: "openai",
3586
- model: "gpt-5-mini",
3587
- label: "GPT-5 mini",
3588
- hint: "Rapide, bon march\xE9, meilleur raisonnement"
3589
- },
3590
- {
3591
- provider: "openai",
3592
- model: "gpt-4.1",
3593
- label: "GPT-4.1",
3594
- hint: "Co\xFBt moyen \u2014 r\xE9daction soign\xE9e"
3595
- },
3596
- {
3597
- provider: "openai",
3598
- model: "gpt-5",
3599
- label: "GPT-5",
3600
- hint: "Le plus capable \u2014 le plus lent et le plus cher"
3601
- },
3602
- {
3603
- provider: "anthropic",
3604
- model: "claude-3-5-haiku-latest",
3605
- label: "Claude 3.5 Haiku",
3606
- hint: "Rapide et bon march\xE9"
3607
- },
3608
- {
3609
- provider: "anthropic",
3610
- model: "claude-3-5-sonnet-latest",
3611
- label: "Claude 3.5 Sonnet",
3612
- hint: "Co\xFBt moyen \u2014 r\xE9daction soign\xE9e"
3613
- }
3614
- ];
3615
- var CUSTOM_MODEL_VALUE = "__custom__";
3616
- function findModelOption(model) {
3617
- return KNOWN_MODELS.find((option) => option.model === model);
3618
- }
3619
- function defaultStep() {
3620
- const [first] = KNOWN_MODELS;
3621
- return { model: first.model, provider: first.provider, reasoning: "off" };
3622
- }
3623
- var PIPELINE_PRESETS = [
3624
- {
3625
- id: "triage-only",
3626
- label: "D\xE9marrage prudent \u2014 triage seul",
3627
- description: "Les demandes sont comprises et class\xE9es. Aucune r\xE9ponse n\u2019est pr\xE9par\xE9e.",
3628
- enabled: ["triage"]
3629
- },
3630
- {
3631
- id: "assisted",
3632
- label: "R\xE9ponse assist\xE9e",
3633
- 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.",
3634
- enabled: ["triage", "escalate", "draft"]
3635
- }
3636
- ];
3637
- function applyPreset(value, preset, restore) {
3638
- let next = readNodes(value);
3639
- for (const key of PIPELINE_STEP_KEYS) {
3640
- const on = preset.enabled.includes(key);
3641
- next = withStep(next, key, on ? readStep(next, key) ?? restore(key) : null);
3642
- }
3643
- return next;
3644
- }
3645
3821
  var PERCENT = 100;
3646
3822
  function PipelineNodesForm({
3647
3823
  value,
@@ -3649,7 +3825,9 @@ function PipelineNodesForm({
3649
3825
  canWrite,
3650
3826
  issueMessage,
3651
3827
  prompts,
3652
- promptsLoading = false
3828
+ promptsLoading = false,
3829
+ models,
3830
+ modelsLoading = false
3653
3831
  }) {
3654
3832
  const [remembered, setRemembered] = react.useState({});
3655
3833
  react.useEffect(() => {
@@ -3697,6 +3875,8 @@ function PipelineNodesForm({
3697
3875
  issueMessage: step.key === "triage" ? issueMessage : null,
3698
3876
  prompts,
3699
3877
  promptsLoading,
3878
+ models,
3879
+ modelsLoading,
3700
3880
  onToggle: (on) => toggleStep(step.key, on),
3701
3881
  onPatch: (patch) => onChange(withStepFields(value, step.key, patch))
3702
3882
  },
@@ -3711,6 +3891,8 @@ function StepRow({
3711
3891
  issueMessage,
3712
3892
  prompts,
3713
3893
  promptsLoading,
3894
+ models,
3895
+ modelsLoading,
3714
3896
  onToggle,
3715
3897
  onPatch
3716
3898
  }) {
@@ -3764,6 +3946,8 @@ function StepRow({
3764
3946
  step,
3765
3947
  settings: readStep(value, step.key),
3766
3948
  disabled: !canWrite || blockedReason !== null,
3949
+ models,
3950
+ modelsLoading,
3767
3951
  onPatch
3768
3952
  }
3769
3953
  ) })
@@ -3774,12 +3958,14 @@ function StepOptions({
3774
3958
  step,
3775
3959
  settings,
3776
3960
  disabled,
3961
+ models,
3962
+ modelsLoading,
3777
3963
  onPatch
3778
3964
  }) {
3779
3965
  const model = stepString(settings, "model");
3780
- const known = findModelOption(model);
3966
+ const known = models.includes(model);
3781
3967
  const [freeText, setFreeText] = react.useState(false);
3782
- const showFreeText = freeText || model !== "" && !known;
3968
+ const showFreeText = freeText || model !== "" && !known && !modelsLoading;
3783
3969
  const ids = useIds(step.key);
3784
3970
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3785
3971
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -3788,25 +3974,20 @@ function StepOptions({
3788
3974
  uiSdk.Select,
3789
3975
  {
3790
3976
  "aria-label": `Mod\xE8le \u2014 ${step.label}`,
3791
- value: showFreeText ? CUSTOM_MODEL_VALUE : known?.model ?? void 0,
3977
+ value: showFreeText ? CUSTOM_MODEL_VALUE : known ? model : void 0,
3792
3978
  onValueChange: (next) => {
3793
3979
  if (next === CUSTOM_MODEL_VALUE) {
3794
3980
  setFreeText(true);
3795
3981
  return;
3796
3982
  }
3797
3983
  setFreeText(false);
3798
- const option = findModelOption(next);
3799
- if (!option) return;
3800
- onPatch({ model: option.model, provider: option.provider });
3984
+ onPatch({ model: next, provider: DEFAULT_STEP_PROVIDER });
3801
3985
  },
3802
3986
  items: [
3803
- ...KNOWN_MODELS.map((option) => ({
3804
- value: option.model,
3805
- label: `${option.label} \u2014 ${option.hint}`
3806
- })),
3987
+ ...models.map((name) => ({ value: name, label: name })),
3807
3988
  { value: CUSTOM_MODEL_VALUE, label: "Autre \u2014 saisir un identifiant de mod\xE8le" }
3808
3989
  ],
3809
- disabled
3990
+ disabled: disabled || modelsLoading
3810
3991
  }
3811
3992
  ),
3812
3993
  showFreeText && // The provider travels WITH the model: a free-text id typed after a
@@ -3904,7 +4085,7 @@ function StepPromptField({
3904
4085
  onPatch
3905
4086
  }) {
3906
4087
  if (stepUsesAgentPrompt(step.key)) {
3907
- return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Le prompt de cette \xE9tape est celui de l'agent qui r\xE9dige \u2014 il se choisit sur la page Agents." });
4088
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: step.key === "revise" ? "Cette \xE9tape relance l'agent qui r\xE9dige avec l'objection du relecteur \u2014 elle n'a pas de prompt \xE0 choisir." : "Le prompt de cette \xE9tape est celui de l'agent qui r\xE9dige \u2014 il se choisit sur la page Agents." });
3908
4089
  }
3909
4090
  const name = stepPromptName(settings);
3910
4091
  const label = stepPromptLabel(settings);
@@ -3961,37 +4142,6 @@ function useIds(stepKey) {
3961
4142
  minConfidence: `${base2}-${stepKey}-min-confidence`
3962
4143
  };
3963
4144
  }
3964
- function usePromptCatalogue() {
3965
- const { appSlug } = uiSdk.useAppContext();
3966
- const api = uiSdk.useAppApi();
3967
- const [prompts, setPrompts] = react.useState([]);
3968
- const [isLoading, setIsLoading] = react.useState(true);
3969
- const [error, setError] = react.useState(void 0);
3970
- const clientRef = react.useRef(api);
3971
- clientRef.current = api;
3972
- const requestIdRef = react.useRef(0);
3973
- const isMountedRef = react.useRef(true);
3974
- react.useEffect(() => {
3975
- isMountedRef.current = true;
3976
- const requestId = ++requestIdRef.current;
3977
- setIsLoading(true);
3978
- void clientRef.current.get(`/data/apps/${appSlug}/prompts`).then((catalogue) => {
3979
- if (requestId !== requestIdRef.current || !isMountedRef.current) return;
3980
- setPrompts(catalogue);
3981
- setError(void 0);
3982
- }).catch((err) => {
3983
- if (requestId !== requestIdRef.current || !isMountedRef.current) return;
3984
- setError(err);
3985
- }).finally(() => {
3986
- if (requestId !== requestIdRef.current || !isMountedRef.current) return;
3987
- setIsLoading(false);
3988
- });
3989
- return () => {
3990
- isMountedRef.current = false;
3991
- };
3992
- }, [appSlug]);
3993
- return { prompts, isLoading, error };
3994
- }
3995
4145
  var WHATSAPP_MODE_LABELS = {
3996
4146
  escalate_only: "Escalade uniquement",
3997
4147
  draft_only: "Brouillon uniquement",
@@ -4047,6 +4197,7 @@ function SettingsPage() {
4047
4197
  const [installedAppsUnavailable, setInstalledAppsUnavailable] = react.useState(false);
4048
4198
  const [connections, setConnections] = react.useState(void 0);
4049
4199
  const promptCatalogue = usePromptCatalogue();
4200
+ const modelCatalogue = useModelCatalogue();
4050
4201
  const formInitializedRef = react.useRef(false);
4051
4202
  react.useEffect(() => {
4052
4203
  if (settings && !formInitializedRef.current) {
@@ -4423,9 +4574,15 @@ function SettingsPage() {
4423
4574
  canWrite,
4424
4575
  issueMessage: nodesIssue ? settingsIssueLabel(nodesIssue.key, nodesIssue.message) : null,
4425
4576
  prompts: promptCatalogue.prompts,
4426
- promptsLoading: promptCatalogue.isLoading
4577
+ promptsLoading: promptCatalogue.isLoading,
4578
+ models: modelCatalogue.models,
4579
+ modelsLoading: modelCatalogue.isLoading
4427
4580
  }
4428
4581
  ),
4582
+ modelCatalogue.error !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-destructive", children: [
4583
+ "Liste des mod\xE8les indisponible \u2014 ",
4584
+ describeApiError(modelCatalogue.error)
4585
+ ] }),
4429
4586
  promptCatalogue.error !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-destructive", children: [
4430
4587
  "Catalogue de prompts indisponible \u2014 ",
4431
4588
  describeApiError(promptCatalogue.error)
@@ -4465,7 +4622,7 @@ function hasNoDraftNode(profile) {
4465
4622
  // src/ui/graph-canvas/reachability.ts
4466
4623
  function stubPrompts() {
4467
4624
  const ref = { name: "", label: "production" };
4468
- return { triage: ref, escalate: ref, draft: ref, evaluate: ref, revise: ref };
4625
+ return { triage: ref, escalate: ref, draft: ref, evaluate: ref };
4469
4626
  }
4470
4627
  var PROMPT_403_NODES = /* @__PURE__ */ new Set(["triage", "escalate", "draft", "evaluate", "revise"]);
4471
4628
  var PROMPT_403_NOTE = "promptRef est transmis \xE0 ctx.api.llm.complete, qui r\xE9pond 403 en production tant que manifest.prompts[] reste vide (d\xE9faut D-LF connu, non corrig\xE9 \u2014 voir le journal T24/T25) : ce n\u0153ud peut renvoyer PROMPT_NOT_DECLARED sur un d\xE9ploiement r\xE9el malgr\xE9 un r\xE9glage \xAB Actif \xBB ici.";