@apotech-os/support-kit 2.8.0 → 2.9.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
@@ -990,6 +990,7 @@ function idempotencyKeyFor(operation, payload) {
990
990
  var SETTINGS_ISSUE_LABELS = {
991
991
  sourceViewId: "Vue Gorgias source requise \u2014 choisissez la vue que cette app poss\xE8de.",
992
992
  nodes: "nodes.triage doit \xEAtre configur\xE9 \u2014 une \xE9tape de triage \xE0 null ne triagerait rien.",
993
+ nodePrompt: "Chaque \xE9tape active doit d\xE9signer un prompt Langfuse \u2014 sans prompt, l'\xE9tape n'a rien \xE0 dire au mod\xE8le.",
993
994
  senderEmail: "Adresse d'envoi requise quand l'envoi automatique est actif (sauf en mode WhatsApp \xAB auto_reply \xBB)."
994
995
  };
995
996
  function settingsIssueLabel(key, fallback) {
@@ -3178,6 +3179,13 @@ function validateSettings(settings) {
3178
3179
  message: "nodes.triage must be configured \u2014 a null triage step would triage nothing."
3179
3180
  });
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
+ }
3181
3189
  const autoSendEnabled = settings.autoSendEnabled === true;
3182
3190
  const isWhatsappAutoReply = settings.whatsappMode === "auto_reply";
3183
3191
  if (autoSendEnabled && !isWhatsappAutoReply && !isNonEmptyString(settings.senderEmail)) {
@@ -3191,6 +3199,20 @@ function validateSettings(settings) {
3191
3199
  function isNonEmptyString(value) {
3192
3200
  return typeof value === "string" && value.length > 0;
3193
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
+ }
3194
3216
  function isConfiguredNode(nodes) {
3195
3217
  if (typeof nodes !== "object" || nodes === null) return false;
3196
3218
  const triage = nodes.triage;
@@ -3523,6 +3545,25 @@ function stepBoolean(step, field2, fallback) {
3523
3545
  const value = step?.[field2];
3524
3546
  return typeof value === "boolean" ? value : fallback;
3525
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
+ }
3526
3567
  function stepReasoning(step) {
3527
3568
  const value = step?.reasoning;
3528
3569
  return REASONING_EFFORTS.some((effort) => effort.value === value) ? value : "off";
@@ -3602,7 +3643,14 @@ function applyPreset(value, preset, restore) {
3602
3643
  return next;
3603
3644
  }
3604
3645
  var PERCENT = 100;
3605
- function PipelineNodesForm({ value, onChange, canWrite, issueMessage }) {
3646
+ function PipelineNodesForm({
3647
+ value,
3648
+ onChange,
3649
+ canWrite,
3650
+ issueMessage,
3651
+ prompts,
3652
+ promptsLoading = false
3653
+ }) {
3606
3654
  const [remembered, setRemembered] = react.useState({});
3607
3655
  react.useEffect(() => {
3608
3656
  setRemembered((prev) => {
@@ -3647,6 +3695,8 @@ function PipelineNodesForm({ value, onChange, canWrite, issueMessage }) {
3647
3695
  value,
3648
3696
  canWrite,
3649
3697
  issueMessage: step.key === "triage" ? issueMessage : null,
3698
+ prompts,
3699
+ promptsLoading,
3650
3700
  onToggle: (on) => toggleStep(step.key, on),
3651
3701
  onPatch: (patch) => onChange(withStepFields(value, step.key, patch))
3652
3702
  },
@@ -3663,11 +3713,14 @@ function StepRow({
3663
3713
  value,
3664
3714
  canWrite,
3665
3715
  issueMessage,
3716
+ prompts,
3717
+ promptsLoading,
3666
3718
  onToggle,
3667
3719
  onPatch
3668
3720
  }) {
3669
3721
  const enabled = isStepEnabled(value, step.key);
3670
3722
  const blockedReason = stepBlockedReason(value, step.key);
3723
+ const promptFieldId = react.useId();
3671
3724
  const triageLocked = step.key === "triage" && enabled;
3672
3725
  const editable = canWrite && !blockedReason && !triageLocked;
3673
3726
  const toggle = /* @__PURE__ */ jsxRuntime.jsx(
@@ -3692,6 +3745,21 @@ function StepRow({
3692
3745
  ] }),
3693
3746
  blockedReason && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: blockedReason }),
3694
3747
  issueMessage && !enabled && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: issueMessage }),
3748
+ enabled && // In the row itself, NOT behind « Options »: this is the one field
3749
+ // without which the step cannot run at all, so it is stated where the
3750
+ // step is, next to its own switch.
3751
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md bg-muted/40 p-3", children: /* @__PURE__ */ jsxRuntime.jsx(
3752
+ StepPromptField,
3753
+ {
3754
+ step,
3755
+ settings: readStep(value, step.key),
3756
+ disabled: !canWrite || blockedReason !== null,
3757
+ prompts,
3758
+ promptsLoading,
3759
+ id: promptFieldId,
3760
+ onPatch
3761
+ }
3762
+ ) }),
3695
3763
  enabled && /* @__PURE__ */ jsxRuntime.jsxs("details", { children: [
3696
3764
  /* @__PURE__ */ jsxRuntime.jsx("summary", { className: "cursor-pointer text-sm text-muted-foreground", children: "Options" }),
3697
3765
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 grid gap-4 rounded-md bg-muted/40 p-3 sm:grid-cols-2", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -3830,6 +3898,63 @@ function StepOptions({
3830
3898
  ] })
3831
3899
  ] });
3832
3900
  }
3901
+ function StepPromptField({
3902
+ step,
3903
+ settings,
3904
+ disabled,
3905
+ prompts,
3906
+ promptsLoading,
3907
+ id,
3908
+ onPatch
3909
+ }) {
3910
+ if (stepUsesAgentPrompt(step.key)) {
3911
+ 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." });
3912
+ }
3913
+ const name = stepPromptName(settings);
3914
+ const label = stepPromptLabel(settings);
3915
+ const known = prompts.find((entry) => entry.name === name);
3916
+ const orphaned = name !== "" && !known && !promptsLoading;
3917
+ const labels = known?.labels.length ? known.labels : [DEFAULT_PROMPT_LABEL];
3918
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3919
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "mb-1 block text-sm font-medium", children: "Prompt Langfuse" }),
3920
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
3921
+ /* @__PURE__ */ jsxRuntime.jsx(
3922
+ uiSdk.Select,
3923
+ {
3924
+ "aria-label": `Prompt \u2014 ${step.label}`,
3925
+ value: known ? name : void 0,
3926
+ onValueChange: (next) => onPatch(promptPatch(next, DEFAULT_PROMPT_LABEL)),
3927
+ items: [
3928
+ ...orphaned ? [{ value: name, label: `${name} \u2014 introuvable dans Langfuse` }] : [],
3929
+ ...prompts.map((entry) => ({ value: entry.name, label: entry.name }))
3930
+ ],
3931
+ disabled: disabled || promptsLoading
3932
+ }
3933
+ ),
3934
+ /* @__PURE__ */ jsxRuntime.jsx(
3935
+ uiSdk.Select,
3936
+ {
3937
+ "aria-label": `Version du prompt \u2014 ${step.label}`,
3938
+ value: labels.includes(label) ? label : void 0,
3939
+ onValueChange: (next) => onPatch(promptPatch(name, next)),
3940
+ items: labels.map((entry) => ({ value: entry, label: entry })),
3941
+ disabled: disabled || promptsLoading || name === ""
3942
+ }
3943
+ )
3944
+ ] }),
3945
+ name === "" && !promptsLoading && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-destructive", children: "Aucun prompt choisi \u2014 cette \xE9tape ne peut pas s'ex\xE9cuter tant qu'elle n'en d\xE9signe pas un." }),
3946
+ orphaned && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-sm text-destructive", children: [
3947
+ "\xAB ",
3948
+ name,
3949
+ " \xBB n'est pas dans le catalogue de cette app \u2014 le prochain traitement \xE9chouera tant que ce prompt n'est pas r\xE9tabli ou remplac\xE9."
3950
+ ] }),
3951
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
3952
+ "Le label suit les promotions faites dans Langfuse : promouvoir une nouvelle version sous \xAB ",
3953
+ label,
3954
+ " \xBB la met en service sans repasser ici."
3955
+ ] })
3956
+ ] });
3957
+ }
3833
3958
  function useIds(stepKey) {
3834
3959
  const base2 = react.useId();
3835
3960
  return {
@@ -3903,6 +4028,37 @@ function NodesJsonField({
3903
4028
  function stringify(value) {
3904
4029
  return JSON.stringify(value ?? null, null, 2);
3905
4030
  }
4031
+ function usePromptCatalogue() {
4032
+ const { appSlug } = uiSdk.useAppContext();
4033
+ const api = uiSdk.useAppApi();
4034
+ const [prompts, setPrompts] = react.useState([]);
4035
+ const [isLoading, setIsLoading] = react.useState(true);
4036
+ const [error, setError] = react.useState(void 0);
4037
+ const clientRef = react.useRef(api);
4038
+ clientRef.current = api;
4039
+ const requestIdRef = react.useRef(0);
4040
+ const isMountedRef = react.useRef(true);
4041
+ react.useEffect(() => {
4042
+ isMountedRef.current = true;
4043
+ const requestId = ++requestIdRef.current;
4044
+ setIsLoading(true);
4045
+ void clientRef.current.get(`/data/apps/${appSlug}/prompts`).then((catalogue) => {
4046
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
4047
+ setPrompts(catalogue);
4048
+ setError(void 0);
4049
+ }).catch((err) => {
4050
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
4051
+ setError(err);
4052
+ }).finally(() => {
4053
+ if (requestId !== requestIdRef.current || !isMountedRef.current) return;
4054
+ setIsLoading(false);
4055
+ });
4056
+ return () => {
4057
+ isMountedRef.current = false;
4058
+ };
4059
+ }, [appSlug]);
4060
+ return { prompts, isLoading, error };
4061
+ }
3906
4062
  var WHATSAPP_MODE_LABELS = {
3907
4063
  escalate_only: "Escalade uniquement",
3908
4064
  draft_only: "Brouillon uniquement",
@@ -3957,6 +4113,7 @@ function SettingsPage() {
3957
4113
  const [uncheckedAppSlugs, setUncheckedAppSlugs] = react.useState([]);
3958
4114
  const [installedAppsUnavailable, setInstalledAppsUnavailable] = react.useState(false);
3959
4115
  const [connections, setConnections] = react.useState(void 0);
4116
+ const promptCatalogue = usePromptCatalogue();
3960
4117
  const formInitializedRef = react.useRef(false);
3961
4118
  react.useEffect(() => {
3962
4119
  if (settings && !formInitializedRef.current) {
@@ -4324,9 +4481,15 @@ function SettingsPage() {
4324
4481
  value: form.nodes,
4325
4482
  onChange: (v) => set("nodes", v),
4326
4483
  canWrite,
4327
- issueMessage: nodesIssue ? settingsIssueLabel(nodesIssue.key, nodesIssue.message) : null
4484
+ issueMessage: nodesIssue ? settingsIssueLabel(nodesIssue.key, nodesIssue.message) : null,
4485
+ prompts: promptCatalogue.prompts,
4486
+ promptsLoading: promptCatalogue.isLoading
4328
4487
  }
4329
4488
  ),
4489
+ promptCatalogue.error !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-destructive", children: [
4490
+ "Catalogue de prompts indisponible \u2014 ",
4491
+ describeApiError(promptCatalogue.error)
4492
+ ] }),
4330
4493
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: `/espace/${appSlug}/graph-canvas`, children: "Visualiser dans Graphe" })
4331
4494
  ] }) }),
4332
4495
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3 p-4", children: [