@apotech-os/support-kit 5.0.1 → 6.1.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
@@ -1211,6 +1211,23 @@ var GENERATED_RESPONSE_STATUSES = [
1211
1211
  function isGeneratedResponseStatus(value) {
1212
1212
  return typeof value === "string" && GENERATED_RESPONSE_STATUSES.includes(value);
1213
1213
  }
1214
+ var ALLOWED_TRANSITIONS = {
1215
+ pending: ["ready", "failed", "no_reply_needed", "sending", "invalidated"],
1216
+ ready: ["sending", "invalidated", "expired"],
1217
+ sending: ["sent", "ready"],
1218
+ sent: [],
1219
+ failed: [],
1220
+ no_reply_needed: [],
1221
+ invalidated: [],
1222
+ expired: []
1223
+ };
1224
+ function canTransition(from, to) {
1225
+ if (!isGeneratedResponseStatus(from) || !isGeneratedResponseStatus(to)) return false;
1226
+ return ALLOWED_TRANSITIONS[from].includes(to);
1227
+ }
1228
+ function isInvalidatableStatus(status) {
1229
+ return canTransition(status, "invalidated");
1230
+ }
1214
1231
 
1215
1232
  // src/ui/tickets/ticket-outcome.ts
1216
1233
  var NO_JOB = { label: "Aucune r\xE9ponse g\xE9n\xE9r\xE9e", variant: "neutral" };
@@ -1411,10 +1428,14 @@ function noResponseCause(decision) {
1411
1428
  return "La cat\xE9gorie n'a pas la r\xE9ponse rapide activ\xE9e, ou n'a pas d'agent r\xE9dacteur.";
1412
1429
  }
1413
1430
  function TimelinePanel(props) {
1414
- const { decision, job, comparisons, conversation, conversationLoading, categoryName, onClose } = props;
1431
+ const { decision, job, comparisons, conversation, conversationLoading, categoryName, onClose, onInvalidate, isInvalidating } = props;
1415
1432
  const steps = buildTimeline({ decision, job, comparisons, conversation, conversationLoading });
1416
- return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.SidePanel, { open: true, onClose, title: `Ticket ${decision.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 text-sm", children: [
1417
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "pb-3", children: /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl, label: "Ouvrir le ticket dans Gorgias" }) }),
1433
+ const canInvalidate = job !== void 0 && isGeneratedResponseStatus(job.status) && isInvalidatableStatus(job.status);
1434
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.SidePanel, { open: true, onClose, title: `Ticket ${decision.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-h-0 flex-1 space-y-1 overflow-y-auto text-sm", children: [
1435
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 pb-3", children: [
1436
+ /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl, label: "Ouvrir le ticket dans Gorgias" }),
1437
+ onInvalidate && canInvalidate && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onInvalidate, disabled: isInvalidating, children: isInvalidating ? "Invalidation\u2026" : "Invalider la r\xE9ponse" })
1438
+ ] }),
1418
1439
  steps.map((step2, index) => /* @__PURE__ */ jsxRuntime.jsx(StepBlock, { step: step2, index, last: index === steps.length - 1, children: step2.reached ? renderStep(step2.key, props) : null }, step2.key))
1419
1440
  ] }) });
1420
1441
  }
@@ -1662,6 +1683,7 @@ function TicketsPage() {
1662
1683
  const [correctedFilter, setCorrectedFilter] = react.useState("");
1663
1684
  const [detailDecision, setDetailDecision] = react.useState(null);
1664
1685
  const [isTriaging, setIsTriaging] = react.useState(false);
1686
+ const [isInvalidating, setIsInvalidating] = react.useState(false);
1665
1687
  const [triageInFlight] = react.useState(() => ({ current: false }));
1666
1688
  const periodKey = JSON.stringify(period);
1667
1689
  const bounds = react.useMemo(() => periodBoundsOf(JSON.parse(periodKey)).current, [periodKey]);
@@ -1799,6 +1821,18 @@ function TicketsPage() {
1799
1821
  setIsTriaging(false);
1800
1822
  }
1801
1823
  }
1824
+ async function invalidateResponse(generatedResponseId) {
1825
+ setIsInvalidating(true);
1826
+ try {
1827
+ await api.invoke("invalidate-response", { generatedResponseId });
1828
+ toast({ title: "R\xE9ponse invalid\xE9e \u2014 le ticket pourra \xEAtre retrait\xE9 de z\xE9ro.", variant: "success" });
1829
+ await refreshAll();
1830
+ } catch (err) {
1831
+ toast({ title: "\xC9chec de l'invalidation", description: describeInvokeError(err), variant: "error" });
1832
+ } finally {
1833
+ setIsInvalidating(false);
1834
+ }
1835
+ }
1802
1836
  const columns = [
1803
1837
  { key: "ticketId", header: "Ticket", cell: ({ decision }) => /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl }) },
1804
1838
  { key: "category", header: "Cat\xE9gorie", cell: ({ decision }) => decision.categoryId && categoryNames.get(decision.categoryId) || "\u2014" },
@@ -1935,7 +1969,9 @@ function TicketsPage() {
1935
1969
  categoryName: detailDecision.categoryId && categoryNames.get(detailDecision.categoryId) || "\u2014",
1936
1970
  agentName: detailRow?.job?.agentId && agentNames.get(detailRow.job.agentId) || "\u2014",
1937
1971
  langfuseConfig,
1938
- onClose: () => setDetailDecision(null)
1972
+ onClose: () => setDetailDecision(null),
1973
+ onInvalidate: canWrite && detailRow?.job ? () => void invalidateResponse(detailRow.job.id) : void 0,
1974
+ isInvalidating
1939
1975
  }
1940
1976
  )
1941
1977
  ] });
@@ -2315,6 +2351,131 @@ function ConfirmModal({
2315
2351
  ] })
2316
2352
  ] }) });
2317
2353
  }
2354
+ var PROMPT_PANEL_CLASS = "w-[min(92vw,64rem)] max-w-none";
2355
+ var PRODUCTION_LABEL = "production";
2356
+ var PromptTextarea = react.forwardRef(
2357
+ function PromptTextarea2({ value, className, rows = 14, ...props }, ref) {
2358
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2359
+ /* @__PURE__ */ jsxRuntime.jsx(
2360
+ uiSdk.Textarea,
2361
+ {
2362
+ ref,
2363
+ value,
2364
+ rows,
2365
+ className: uiSdk.cn("font-mono text-xs leading-relaxed", className),
2366
+ ...props
2367
+ }
2368
+ ),
2369
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-right text-xs text-muted-foreground", children: [
2370
+ value.length.toLocaleString("fr-FR"),
2371
+ " caract\xE8re",
2372
+ value.length > 1 ? "s" : ""
2373
+ ] })
2374
+ ] });
2375
+ }
2376
+ );
2377
+ function defaultExpandedVersion(versions) {
2378
+ const production = versions.find((v) => v.labels.includes(PRODUCTION_LABEL));
2379
+ if (production) return production.version;
2380
+ return versions.reduce(
2381
+ (max, v) => max === null || v.version > max ? v.version : max,
2382
+ null
2383
+ );
2384
+ }
2385
+ function excerptOf(content) {
2386
+ return content.slice(0, 1e3).split("\n").find((line) => line.trim() !== "") ?? "";
2387
+ }
2388
+ function VersionCard({
2389
+ version,
2390
+ defaultOpen,
2391
+ onEditFrom,
2392
+ onPromote,
2393
+ onDelete
2394
+ }) {
2395
+ const [isOpen, setIsOpen] = react.useState(defaultOpen);
2396
+ const hasActions = onEditFrom !== void 0 || onPromote !== void 0 || onDelete !== void 0;
2397
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border", children: [
2398
+ /* @__PURE__ */ jsxRuntime.jsxs(
2399
+ "button",
2400
+ {
2401
+ type: "button",
2402
+ "aria-expanded": isOpen,
2403
+ onClick: () => setIsOpen((open) => !open),
2404
+ className: "flex w-full items-center gap-3 rounded-md p-3 text-left hover:bg-accent/50",
2405
+ children: [
2406
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-2", children: [
2407
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "shrink-0 text-sm font-medium", children: [
2408
+ "v",
2409
+ version.version
2410
+ ] }),
2411
+ version.label && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "brand", children: version.label }),
2412
+ !isOpen && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate font-mono text-xs text-muted-foreground", children: excerptOf(version.content) })
2413
+ ] }),
2414
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "shrink-0 text-xs text-muted-foreground", children: [
2415
+ "Cr\xE9\xE9e le ",
2416
+ formatDate(version.createdAt)
2417
+ ] })
2418
+ ]
2419
+ }
2420
+ ),
2421
+ isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t p-3", children: [
2422
+ hasActions && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [
2423
+ onEditFrom && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onEditFrom, children: "Modifier cette version" }),
2424
+ onPromote && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onPromote, children: "Promouvoir" }),
2425
+ onDelete && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onDelete, children: "Supprimer la version" })
2426
+ ] }),
2427
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap font-mono text-xs text-muted-foreground", children: version.content })
2428
+ ] })
2429
+ ] });
2430
+ }
2431
+ function useNewVersionDraft() {
2432
+ const [content, setContent] = react.useState("");
2433
+ const [pendingPrefill, setPendingPrefill] = react.useState(null);
2434
+ const editorRef = react.useRef(null);
2435
+ function loadIntoEditor(versionContent) {
2436
+ setContent(versionContent);
2437
+ setTimeout(() => {
2438
+ editorRef.current?.focus();
2439
+ editorRef.current?.scrollIntoView?.({ block: "center" });
2440
+ }, 0);
2441
+ }
2442
+ function prefill(versionContent) {
2443
+ if (content.trim() !== "" && content !== versionContent) {
2444
+ setPendingPrefill(versionContent);
2445
+ return;
2446
+ }
2447
+ loadIntoEditor(versionContent);
2448
+ }
2449
+ function confirmPrefill() {
2450
+ if (pendingPrefill !== null) loadIntoEditor(pendingPrefill);
2451
+ setPendingPrefill(null);
2452
+ }
2453
+ return {
2454
+ content,
2455
+ setContent,
2456
+ editorRef,
2457
+ prefill,
2458
+ pendingPrefill,
2459
+ confirmPrefill,
2460
+ cancelPrefill: () => setPendingPrefill(null)
2461
+ };
2462
+ }
2463
+ function ReplaceDraftConfirmModal({
2464
+ onConfirm,
2465
+ onCancel
2466
+ }) {
2467
+ return /* @__PURE__ */ jsxRuntime.jsx(
2468
+ ConfirmModal,
2469
+ {
2470
+ title: "Remplacer le brouillon ?",
2471
+ description: "Le texte d\xE9j\xE0 saisi dans \xAB Nouvelle version \xBB sera remplac\xE9 par le contenu de cette version.",
2472
+ confirmLabel: "Remplacer",
2473
+ busyLabel: "Remplacement\u2026",
2474
+ onConfirm,
2475
+ onCancel
2476
+ }
2477
+ );
2478
+ }
2318
2479
  function usePromptVersions(promptName) {
2319
2480
  const { appSlug } = uiSdk.useAppContext();
2320
2481
  const api = uiSdk.useAppApi();
@@ -2472,7 +2633,7 @@ function formFromAgent(agent) {
2472
2633
  var DERIVED_PROMPT_VALUE = "__derived__";
2473
2634
  var CUSTOM_PROMPT_VALUE = "__custom-prompt__";
2474
2635
  var DEFAULT_LABEL_VALUE = "__production__";
2475
- function AgentFormModal({
2636
+ function AgentFormPanel({
2476
2637
  agent,
2477
2638
  prompts,
2478
2639
  promptsLoading,
@@ -2496,13 +2657,17 @@ function AgentFormModal({
2496
2657
  const knownPrompt = prompts.find((entry) => entry.name === form.promptName);
2497
2658
  const showPromptFreeText = freeTextPrompt || agent !== "new" && form.promptName !== "" && !knownPrompt && !promptsLoading;
2498
2659
  const promptLabels = knownPrompt?.labels ?? [];
2660
+ const previewName = agent === "new" && !showPromptFreeText && form.promptName !== "" ? form.promptName : null;
2661
+ const { versions: previewVersions } = usePromptVersions(previewName);
2662
+ const previewContent = previewVersions.find((v) => v.version === defaultExpandedVersion(previewVersions))?.content ?? "";
2663
+ const effectiveSnapshot = previewName !== null ? previewContent : form.systemPromptSnapshot;
2499
2664
  const isValid = form.name.trim() !== "" && form.modelId.trim() !== "" && (agent === "new" || form.promptName.trim() !== "");
2500
2665
  async function submit(event) {
2501
2666
  event.preventDefault();
2502
2667
  if (isSaving || !isValid) return;
2503
2668
  setIsSaving(true);
2504
2669
  try {
2505
- await onSave(form);
2670
+ await onSave({ ...form, systemPromptSnapshot: effectiveSnapshot });
2506
2671
  } finally {
2507
2672
  setIsSaving(false);
2508
2673
  }
@@ -2516,161 +2681,170 @@ function AgentFormModal({
2516
2681
  setForm({ ...form, promptName: next === DERIVED_PROMPT_VALUE ? "" : next, promptLabel: "" });
2517
2682
  }
2518
2683
  return /* @__PURE__ */ jsxRuntime.jsx(
2519
- uiSdk.Modal,
2684
+ uiSdk.SidePanel,
2520
2685
  {
2521
2686
  open: true,
2522
2687
  onClose,
2523
2688
  title: agent === "new" ? "Nouvel agent" : `Modifier ${form.name}`,
2524
- children: /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "space-y-3", onSubmit: (e) => void submit(e), children: [
2525
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2526
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
2527
- /* @__PURE__ */ jsxRuntime.jsx(
2528
- uiSdk.Input,
2529
- {
2530
- id: nameId,
2531
- value: form.name,
2532
- onChange: (e) => setForm({ ...form, name: e.target.value })
2533
- }
2534
- )
2535
- ] }),
2536
- agent !== "new" && agent.status !== "default" && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2537
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Statut" }),
2538
- /* @__PURE__ */ jsxRuntime.jsx(
2539
- uiSdk.Select,
2540
- {
2541
- "aria-label": "Statut",
2542
- value: form.status,
2543
- onValueChange: (next) => setForm({ ...form, status: next }),
2544
- items: [
2545
- { value: "available", label: STATUS_LABELS.available },
2546
- { value: "archived", label: STATUS_LABELS.archived }
2547
- ]
2548
- }
2549
- )
2550
- ] }),
2551
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2552
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Mod\xE8le" }),
2553
- /* @__PURE__ */ jsxRuntime.jsx(
2554
- uiSdk.Select,
2555
- {
2556
- "aria-label": "Mod\xE8le",
2557
- value: showModelFreeText ? CUSTOM_MODEL_VALUE : form.modelId,
2558
- onValueChange: (next) => {
2559
- if (next === CUSTOM_MODEL_VALUE) {
2560
- setFreeTextModel(true);
2561
- return;
2562
- }
2563
- setFreeTextModel(false);
2564
- setForm({ ...form, modelId: next, provider: DEFAULT_STEP_PROVIDER });
2565
- },
2566
- items: [
2567
- // The stored model, listed so the trigger can print it while the
2568
- // provider's own list is still loading.
2569
- ...!showModelFreeText && form.modelId !== "" && !knownModel ? [{ value: form.modelId, label: form.modelId }] : [],
2570
- ...models.map((name) => ({ value: name, label: name })),
2571
- { value: CUSTOM_MODEL_VALUE, label: "Autre \u2014 saisir un identifiant de mod\xE8le" }
2572
- ],
2573
- disabled: modelsLoading
2574
- }
2575
- ),
2576
- showModelFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 space-y-2", children: [
2577
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: modelInputId, className: "mb-1 block text-sm font-medium", children: "Identifiant de mod\xE8le" }),
2578
- /* @__PURE__ */ jsxRuntime.jsx(
2579
- uiSdk.Input,
2580
- {
2581
- id: modelInputId,
2582
- value: form.modelId,
2583
- onChange: (e) => setForm({ ...form, modelId: e.target.value })
2584
- }
2585
- ),
2586
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: providerInputId, className: "mb-1 block text-sm font-medium", children: "Fournisseur" }),
2689
+ className: PROMPT_PANEL_CLASS,
2690
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto pr-1", children: [
2691
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "space-y-3", onSubmit: (e) => void submit(e), children: [
2692
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2693
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
2587
2694
  /* @__PURE__ */ jsxRuntime.jsx(
2588
2695
  uiSdk.Input,
2589
2696
  {
2590
- id: providerInputId,
2591
- value: form.provider,
2592
- onChange: (e) => setForm({ ...form, provider: e.target.value })
2697
+ id: nameId,
2698
+ value: form.name,
2699
+ onChange: (e) => setForm({ ...form, name: e.target.value })
2593
2700
  }
2594
2701
  )
2595
- ] })
2596
- ] }),
2597
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2598
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Prompt Langfuse" }),
2599
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
2702
+ ] }),
2703
+ agent !== "new" && agent.status !== "default" && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2704
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Statut" }),
2600
2705
  /* @__PURE__ */ jsxRuntime.jsx(
2601
2706
  uiSdk.Select,
2602
2707
  {
2603
- "aria-label": "Prompt Langfuse",
2604
- value: showPromptFreeText ? CUSTOM_PROMPT_VALUE : agent === "new" && form.promptName === "" ? DERIVED_PROMPT_VALUE : form.promptName,
2605
- onValueChange: pickPrompt,
2708
+ "aria-label": "Statut",
2709
+ value: form.status,
2710
+ onValueChange: (next) => setForm({ ...form, status: next }),
2606
2711
  items: [
2607
- ...agent === "new" ? [
2608
- {
2609
- value: DERIVED_PROMPT_VALUE,
2610
- label: "Nouveau prompt \u2014 agent/<g\xE9n\xE9r\xE9 automatiquement>"
2611
- }
2612
- ] : [],
2613
- // The agent's stored prompt, listed so the trigger can print it
2614
- // while the catalogue is still loading.
2615
- ...!showPromptFreeText && form.promptName !== "" && !knownPrompt ? [{ value: form.promptName, label: form.promptName }] : [],
2616
- ...prompts.map((entry) => ({ value: entry.name, label: entry.name })),
2617
- { value: CUSTOM_PROMPT_VALUE, label: "Autre \u2014 saisir un nom de prompt" }
2618
- ],
2619
- disabled: promptsLoading
2712
+ { value: "available", label: STATUS_LABELS.available },
2713
+ { value: "archived", label: STATUS_LABELS.archived }
2714
+ ]
2620
2715
  }
2621
- ),
2716
+ )
2717
+ ] }),
2718
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2719
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Mod\xE8le" }),
2622
2720
  /* @__PURE__ */ jsxRuntime.jsx(
2623
2721
  uiSdk.Select,
2624
2722
  {
2625
- "aria-label": "Tag du prompt",
2626
- value: form.promptLabel === "" ? DEFAULT_LABEL_VALUE : form.promptLabel,
2627
- onValueChange: (next) => setForm({ ...form, promptLabel: next === DEFAULT_LABEL_VALUE ? "" : next }),
2723
+ "aria-label": "Mod\xE8le",
2724
+ value: showModelFreeText ? CUSTOM_MODEL_VALUE : form.modelId,
2725
+ onValueChange: (next) => {
2726
+ if (next === CUSTOM_MODEL_VALUE) {
2727
+ setFreeTextModel(true);
2728
+ return;
2729
+ }
2730
+ setFreeTextModel(false);
2731
+ setForm({ ...form, modelId: next, provider: DEFAULT_STEP_PROVIDER });
2732
+ },
2628
2733
  items: [
2629
- { value: DEFAULT_LABEL_VALUE, label: "production (par d\xE9faut)" },
2630
- ...promptLabels.filter((label) => label !== DEFAULT_PROMPT_LABEL).map((label) => ({ value: label, label })),
2631
- ...form.promptLabel !== "" && !promptLabels.includes(form.promptLabel) ? [{ value: form.promptLabel, label: form.promptLabel }] : []
2734
+ // The stored model, listed so the trigger can print it while the
2735
+ // provider's own list is still loading.
2736
+ ...!showModelFreeText && form.modelId !== "" && !knownModel ? [{ value: form.modelId, label: form.modelId }] : [],
2737
+ ...models.map((name) => ({ value: name, label: name })),
2738
+ { value: CUSTOM_MODEL_VALUE, label: "Autre \u2014 saisir un identifiant de mod\xE8le" }
2632
2739
  ],
2633
- disabled: promptsLoading || form.promptName === "" && !showPromptFreeText
2740
+ disabled: modelsLoading
2634
2741
  }
2635
- )
2742
+ ),
2743
+ showModelFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2 space-y-2", children: [
2744
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: modelInputId, className: "mb-1 block text-sm font-medium", children: "Identifiant de mod\xE8le" }),
2745
+ /* @__PURE__ */ jsxRuntime.jsx(
2746
+ uiSdk.Input,
2747
+ {
2748
+ id: modelInputId,
2749
+ value: form.modelId,
2750
+ onChange: (e) => setForm({ ...form, modelId: e.target.value })
2751
+ }
2752
+ ),
2753
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: providerInputId, className: "mb-1 block text-sm font-medium", children: "Fournisseur" }),
2754
+ /* @__PURE__ */ jsxRuntime.jsx(
2755
+ uiSdk.Input,
2756
+ {
2757
+ id: providerInputId,
2758
+ value: form.provider,
2759
+ onChange: (e) => setForm({ ...form, provider: e.target.value })
2760
+ }
2761
+ )
2762
+ ] })
2763
+ ] }),
2764
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2765
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Prompt Langfuse" }),
2766
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
2767
+ /* @__PURE__ */ jsxRuntime.jsx(
2768
+ uiSdk.Select,
2769
+ {
2770
+ "aria-label": "Prompt Langfuse",
2771
+ value: showPromptFreeText ? CUSTOM_PROMPT_VALUE : agent === "new" && form.promptName === "" ? DERIVED_PROMPT_VALUE : form.promptName,
2772
+ onValueChange: pickPrompt,
2773
+ items: [
2774
+ ...agent === "new" ? [
2775
+ {
2776
+ value: DERIVED_PROMPT_VALUE,
2777
+ label: "Nouveau prompt \u2014 agent/<g\xE9n\xE9r\xE9 automatiquement>"
2778
+ }
2779
+ ] : [],
2780
+ // The agent's stored prompt, listed so the trigger can print it
2781
+ // while the catalogue is still loading.
2782
+ ...!showPromptFreeText && form.promptName !== "" && !knownPrompt ? [{ value: form.promptName, label: form.promptName }] : [],
2783
+ ...prompts.map((entry) => ({ value: entry.name, label: entry.name })),
2784
+ { value: CUSTOM_PROMPT_VALUE, label: "Autre \u2014 saisir un nom de prompt" }
2785
+ ],
2786
+ disabled: promptsLoading
2787
+ }
2788
+ ),
2789
+ /* @__PURE__ */ jsxRuntime.jsx(
2790
+ uiSdk.Select,
2791
+ {
2792
+ "aria-label": "Tag du prompt",
2793
+ value: form.promptLabel === "" ? DEFAULT_LABEL_VALUE : form.promptLabel,
2794
+ onValueChange: (next) => setForm({ ...form, promptLabel: next === DEFAULT_LABEL_VALUE ? "" : next }),
2795
+ items: [
2796
+ { value: DEFAULT_LABEL_VALUE, label: "production (par d\xE9faut)" },
2797
+ ...promptLabels.filter((label) => label !== DEFAULT_PROMPT_LABEL).map((label) => ({ value: label, label })),
2798
+ ...form.promptLabel !== "" && !promptLabels.includes(form.promptLabel) ? [{ value: form.promptLabel, label: form.promptLabel }] : []
2799
+ ],
2800
+ disabled: promptsLoading || form.promptName === "" && !showPromptFreeText
2801
+ }
2802
+ )
2803
+ ] }),
2804
+ showPromptFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2", children: [
2805
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: promptInputId, className: "mb-1 block text-sm font-medium", children: "Nom du prompt Langfuse" }),
2806
+ /* @__PURE__ */ jsxRuntime.jsx(
2807
+ uiSdk.Input,
2808
+ {
2809
+ id: promptInputId,
2810
+ value: form.promptName,
2811
+ onChange: (e) => setForm({ ...form, promptName: e.target.value })
2812
+ }
2813
+ )
2814
+ ] }),
2815
+ /* @__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." })
2636
2816
  ] }),
2637
- showPromptFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2", children: [
2638
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: promptInputId, className: "mb-1 block text-sm font-medium", children: "Nom du prompt Langfuse" }),
2817
+ agent === "new" && !showPromptFreeText && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2818
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: snapshotId, className: "mb-1 block text-sm font-medium", children: "Prompt de l'agent" }),
2639
2819
  /* @__PURE__ */ jsxRuntime.jsx(
2640
- uiSdk.Input,
2820
+ PromptTextarea,
2641
2821
  {
2642
- id: promptInputId,
2643
- value: form.promptName,
2644
- onChange: (e) => setForm({ ...form, promptName: e.target.value })
2822
+ id: snapshotId,
2823
+ value: effectiveSnapshot,
2824
+ onChange: (e) => setForm({ ...form, systemPromptSnapshot: e.target.value }),
2825
+ readOnly: previewName !== null,
2826
+ className: "min-h-[40vh]"
2645
2827
  }
2646
- )
2828
+ ),
2829
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: previewName !== null ? "Contenu actuel du prompt s\xE9lectionn\xE9 \u2014 l\u2019agent l\u2019utilisera tel quel ; ses versions se g\xE8rent apr\xE8s la cr\xE9ation." : "Devient la premi\xE8re version du nouveau prompt Langfuse, promue en production \xE0 la cr\xE9ation." })
2647
2830
  ] }),
2648
- /* @__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." })
2649
- ] }),
2650
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2651
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: snapshotId, className: "mb-1 block text-sm font-medium", children: "Prompt de secours (niveau 3)" }),
2652
- /* @__PURE__ */ jsxRuntime.jsx(
2653
- uiSdk.Textarea,
2654
- {
2655
- id: snapshotId,
2656
- value: form.systemPromptSnapshot,
2657
- onChange: (e) => setForm({ ...form, systemPromptSnapshot: e.target.value })
2658
- }
2659
- )
2831
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2 border-t pt-3", children: [
2832
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: onClose, children: "Annuler" }),
2833
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "submit", disabled: isSaving || !isValid, children: isSaving ? "Enregistrement\u2026" : "Enregistrer" })
2834
+ ] })
2660
2835
  ] }),
2661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2 pt-2", children: [
2662
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: onClose, children: "Annuler" }),
2663
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "submit", disabled: isSaving || !isValid, children: isSaving ? "Enregistrement\u2026" : "Enregistrer" })
2836
+ agent !== "new" && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "mt-6 space-y-4 border-t pt-4", children: [
2837
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2838
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold", children: "Versions du prompt Langfuse" }),
2839
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: agent.promptName })
2840
+ ] }),
2841
+ /* @__PURE__ */ jsxRuntime.jsx(PromptVersionsSection, { agent, canWrite: true })
2664
2842
  ] })
2665
2843
  ] })
2666
2844
  }
2667
2845
  );
2668
2846
  }
2669
- function PromptVersionsPanel({
2670
- agent,
2671
- canWrite,
2672
- onClose
2673
- }) {
2847
+ function PromptVersionsSection({ agent, canWrite }) {
2674
2848
  const { appSlug } = uiSdk.useAppContext();
2675
2849
  const { versions, error, refresh, promote, deleteVersion, createVersion } = usePromptVersions(
2676
2850
  agent.promptName
@@ -2678,7 +2852,7 @@ function PromptVersionsPanel({
2678
2852
  const [suggestMessage, setSuggestMessage] = react.useState(null);
2679
2853
  const [isSuggesting, setIsSuggesting] = react.useState(false);
2680
2854
  const isSuggestingRef = react.useRef(false);
2681
- const [newVersionContent, setNewVersionContent] = react.useState("");
2855
+ const draft = useNewVersionDraft();
2682
2856
  const [isCreatingVersion, setIsCreatingVersion] = react.useState(false);
2683
2857
  const [deletingVersion, setDeletingVersion] = react.useState(null);
2684
2858
  const [isComparing, setIsComparing] = react.useState(false);
@@ -2687,6 +2861,7 @@ function PromptVersionsPanel({
2687
2861
  const newVersionId = react.useId();
2688
2862
  const api = uiSdk.useAppApi();
2689
2863
  const toast = uiSdk.useToast();
2864
+ const expandedVersion = defaultExpandedVersion(versions);
2690
2865
  function openCompare() {
2691
2866
  const sorted = [...versions].sort((a, b) => a.version - b.version);
2692
2867
  setCompareLeft(sorted[0]?.version ?? null);
@@ -2727,8 +2902,8 @@ function PromptVersionsPanel({
2727
2902
  async function runCreateVersion() {
2728
2903
  setIsCreatingVersion(true);
2729
2904
  try {
2730
- await createVersion(newVersionContent);
2731
- setNewVersionContent("");
2905
+ await createVersion(draft.content);
2906
+ draft.setContent("");
2732
2907
  toast({ title: "Nouvelle version cr\xE9\xE9e.", variant: "success" });
2733
2908
  } catch (err) {
2734
2909
  toast({
@@ -2756,94 +2931,93 @@ function PromptVersionsPanel({
2756
2931
  setDeletingVersion(null);
2757
2932
  }
2758
2933
  }
2759
- return /* @__PURE__ */ jsxRuntime.jsxs(
2934
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2935
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
2936
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
2937
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: qualityHref(appSlug, agent), children: "Voir dans Qualit\xE9" }),
2938
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
2939
+ versions.length >= 2 && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", onClick: openCompare, children: "Comparer" }),
2940
+ canWrite && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", onClick: () => void suggest(), disabled: isSuggesting, children: isSuggesting ? "Suggestion en cours\u2026" : "Sugg\xE9rer une am\xE9lioration" })
2941
+ ] })
2942
+ ] }),
2943
+ suggestMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: suggestMessage }),
2944
+ error !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des versions." }),
2945
+ versions.length > 0 && !versions.some((v) => v.labels.includes(PRODUCTION_LABEL)) && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-2 text-sm text-status-warning", children: "Aucune version active \u2014 aucune version ne porte le label \xAB production \xBB. Promouvez-en une pour que l'agent l'utilise." }),
2946
+ isComparing && compareLeft !== null && compareRight !== null && /* @__PURE__ */ jsxRuntime.jsx(
2947
+ VersionCompareView,
2948
+ {
2949
+ versions,
2950
+ leftVersion: compareLeft,
2951
+ rightVersion: compareRight,
2952
+ onSelectLeft: setCompareLeft,
2953
+ onSelectRight: setCompareRight
2954
+ }
2955
+ ),
2956
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: versions.map((v) => /* @__PURE__ */ jsxRuntime.jsx(
2957
+ VersionCard,
2958
+ {
2959
+ version: v,
2960
+ defaultOpen: v.version === expandedVersion,
2961
+ onEditFrom: canWrite ? () => draft.prefill(v.content) : void 0,
2962
+ onPromote: canWrite ? () => void runPromote(v.version) : void 0,
2963
+ onDelete: canWrite ? () => setDeletingVersion(v.version) : void 0
2964
+ },
2965
+ v.version
2966
+ )) }),
2967
+ canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-3", children: [
2968
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: newVersionId, className: "block text-sm font-medium", children: "Nouvelle version" }),
2969
+ /* @__PURE__ */ jsxRuntime.jsx(
2970
+ PromptTextarea,
2971
+ {
2972
+ id: newVersionId,
2973
+ ref: draft.editorRef,
2974
+ value: draft.content,
2975
+ onChange: (e) => draft.setContent(e.target.value)
2976
+ }
2977
+ ),
2978
+ /* @__PURE__ */ jsxRuntime.jsx(
2979
+ uiSdk.Button,
2980
+ {
2981
+ onClick: () => void runCreateVersion(),
2982
+ disabled: draft.content.trim() === "" || isCreatingVersion,
2983
+ children: isCreatingVersion ? "Cr\xE9ation\u2026" : "Cr\xE9er la version"
2984
+ }
2985
+ )
2986
+ ] })
2987
+ ] }),
2988
+ draft.pendingPrefill !== null && /* @__PURE__ */ jsxRuntime.jsx(ReplaceDraftConfirmModal, { onConfirm: draft.confirmPrefill, onCancel: draft.cancelPrefill }),
2989
+ deletingVersion !== null && /* @__PURE__ */ jsxRuntime.jsx(
2990
+ ConfirmModal,
2991
+ {
2992
+ title: "Supprimer la version ?",
2993
+ description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2994
+ "La version ",
2995
+ deletingVersion,
2996
+ " de ",
2997
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: agent.promptName }),
2998
+ " sera supprim\xE9e d\xE9finitivement. Impossible si elle porte le label \xAB production \xBB ou s'il s'agit de la derni\xE8re version restante."
2999
+ ] }),
3000
+ confirmLabel: "Supprimer la version",
3001
+ onConfirm: confirmDeleteVersion,
3002
+ onCancel: () => setDeletingVersion(null)
3003
+ }
3004
+ )
3005
+ ] });
3006
+ }
3007
+ function PromptVersionsPanel({
3008
+ agent,
3009
+ canWrite,
3010
+ onClose
3011
+ }) {
3012
+ return /* @__PURE__ */ jsxRuntime.jsx(
2760
3013
  uiSdk.SidePanel,
2761
3014
  {
2762
3015
  open: true,
2763
3016
  onClose,
2764
3017
  title: `Versions du prompt \u2014 ${agent.name}`,
2765
3018
  description: agent.promptName,
2766
- children: [
2767
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", children: [
2768
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
2769
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: qualityHref(appSlug, agent), children: "Voir dans Qualit\xE9" }),
2770
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
2771
- versions.length >= 2 && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", onClick: openCompare, children: "Comparer" }),
2772
- canWrite && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", onClick: () => void suggest(), disabled: isSuggesting, children: isSuggesting ? "Suggestion en cours\u2026" : "Sugg\xE9rer une am\xE9lioration" })
2773
- ] })
2774
- ] }),
2775
- suggestMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: suggestMessage }),
2776
- error !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des versions." }),
2777
- isComparing && compareLeft !== null && compareRight !== null && /* @__PURE__ */ jsxRuntime.jsx(
2778
- VersionCompareView,
2779
- {
2780
- versions,
2781
- leftVersion: compareLeft,
2782
- rightVersion: compareRight,
2783
- onSelectLeft: setCompareLeft,
2784
- onSelectRight: setCompareRight
2785
- }
2786
- ),
2787
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: versions.map((v) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border p-3", children: [
2788
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
2789
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium", children: [
2790
- "v",
2791
- v.version,
2792
- " ",
2793
- v.label && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "brand", children: v.label })
2794
- ] }),
2795
- canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
2796
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: () => void runPromote(v.version), children: "Promouvoir" }),
2797
- /* @__PURE__ */ jsxRuntime.jsx(
2798
- uiSdk.Button,
2799
- {
2800
- variant: "outline",
2801
- size: "sm",
2802
- onClick: () => setDeletingVersion(v.version),
2803
- children: "Supprimer la version"
2804
- }
2805
- )
2806
- ] })
2807
- ] }),
2808
- /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-2 whitespace-pre-wrap text-xs text-muted-foreground", children: v.content })
2809
- ] }, v.version)) }),
2810
- canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-3", children: [
2811
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: newVersionId, className: "block text-sm font-medium", children: "Nouvelle version" }),
2812
- /* @__PURE__ */ jsxRuntime.jsx(
2813
- uiSdk.Textarea,
2814
- {
2815
- id: newVersionId,
2816
- value: newVersionContent,
2817
- onChange: (e) => setNewVersionContent(e.target.value)
2818
- }
2819
- ),
2820
- /* @__PURE__ */ jsxRuntime.jsx(
2821
- uiSdk.Button,
2822
- {
2823
- onClick: () => void runCreateVersion(),
2824
- disabled: newVersionContent.trim() === "" || isCreatingVersion,
2825
- children: isCreatingVersion ? "Cr\xE9ation\u2026" : "Cr\xE9er la version"
2826
- }
2827
- )
2828
- ] })
2829
- ] }),
2830
- deletingVersion !== null && /* @__PURE__ */ jsxRuntime.jsx(
2831
- ConfirmModal,
2832
- {
2833
- title: "Supprimer la version ?",
2834
- description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2835
- "La version ",
2836
- deletingVersion,
2837
- " de ",
2838
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: agent.promptName }),
2839
- " sera supprim\xE9e d\xE9finitivement. Impossible si elle porte le label \xAB production \xBB ou s'il s'agit de la derni\xE8re version restante."
2840
- ] }),
2841
- confirmLabel: "Supprimer la version",
2842
- onConfirm: confirmDeleteVersion,
2843
- onCancel: () => setDeletingVersion(null)
2844
- }
2845
- )
2846
- ]
3019
+ className: PROMPT_PANEL_CLASS,
3020
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(PromptVersionsSection, { agent, canWrite }) })
2847
3021
  }
2848
3022
  );
2849
3023
  }
@@ -2933,7 +3107,6 @@ function AgentsPage() {
2933
3107
  name: form.name,
2934
3108
  modelId: form.modelId,
2935
3109
  provider: form.provider,
2936
- systemPromptSnapshot: form.systemPromptSnapshot,
2937
3110
  promptName: form.promptName.trim(),
2938
3111
  promptLabel: form.promptLabel.trim() || null,
2939
3112
  ...formAgent.status !== "default" ? { status: form.status } : {}
@@ -3012,14 +3185,15 @@ function AgentsPage() {
3012
3185
  }
3013
3186
  ),
3014
3187
  formAgent && /* @__PURE__ */ jsxRuntime.jsx(
3015
- AgentFormModal,
3188
+ AgentFormPanel,
3016
3189
  {
3017
3190
  agent: formAgent,
3018
3191
  prompts,
3019
3192
  promptsLoading,
3020
3193
  onClose: () => setFormAgent(null),
3021
3194
  onSave: save
3022
- }
3195
+ },
3196
+ formAgent === "new" ? "new" : formAgent.id
3023
3197
  ),
3024
3198
  versionsAgent && /* @__PURE__ */ jsxRuntime.jsx(
3025
3199
  PromptVersionsPanel,
@@ -3027,7 +3201,8 @@ function AgentsPage() {
3027
3201
  agent: versionsAgent,
3028
3202
  canWrite,
3029
3203
  onClose: () => setVersionsAgent(null)
3030
- }
3204
+ },
3205
+ versionsAgent.promptName
3031
3206
  ),
3032
3207
  deletingAgent && /* @__PURE__ */ jsxRuntime.jsx(
3033
3208
  ConfirmModal,
@@ -5646,13 +5821,12 @@ function useSharedPrompts() {
5646
5821
  }, [load]);
5647
5822
  return { prompts, isLoading, error, refresh: load };
5648
5823
  }
5649
- var PRODUCTION_LABEL = "production";
5650
5824
  var SHARED_PREFIX2 = "shared/";
5651
5825
  var SLUG_RE = /^[a-z0-9-]{1,64}$/;
5652
5826
  var SLUG_ERROR = "Le nom doit contenir 1 \xE0 64 minuscules, chiffres ou tirets.";
5653
5827
  function VersionsPanel({ name, canWrite, onClose }) {
5654
5828
  const { versions, error, promote, deleteVersion, refresh } = usePromptVersions(name);
5655
- const [newContent, setNewContent] = react.useState("");
5829
+ const draft = useNewVersionDraft();
5656
5830
  const [isCreating, setIsCreating] = react.useState(false);
5657
5831
  const [createError, setCreateError] = react.useState(null);
5658
5832
  const [deletingVersion, setDeletingVersion] = react.useState(null);
@@ -5664,6 +5838,7 @@ function VersionsPanel({ name, canWrite, onClose }) {
5664
5838
  const api = uiSdk.useAppApi();
5665
5839
  const toast = uiSdk.useToast();
5666
5840
  const sorted = [...versions].sort((a, b) => b.version - a.version);
5841
+ const expandedVersion = defaultExpandedVersion(versions);
5667
5842
  const hasActiveVersion = versions.some((v) => v.labels.includes(PRODUCTION_LABEL));
5668
5843
  function openCompare() {
5669
5844
  const byVersionAsc = [...versions].sort((a, b) => a.version - b.version);
@@ -5701,14 +5876,14 @@ function VersionsPanel({ name, canWrite, onClose }) {
5701
5876
  async function runCreateVersion() {
5702
5877
  setIsCreating(true);
5703
5878
  setCreateError(null);
5704
- const payload = { name, content: newContent };
5879
+ const payload = { name, content: draft.content };
5705
5880
  try {
5706
5881
  await api.invoke(
5707
5882
  "create-shared-prompt-version",
5708
5883
  payload,
5709
5884
  { idempotencyKey: idempotencyKeyFor("create-shared-prompt-version", payload) }
5710
5885
  );
5711
- setNewContent("");
5886
+ draft.setContent("");
5712
5887
  await refresh();
5713
5888
  } catch (err) {
5714
5889
  setCreateError(describeInvokeError(err));
@@ -5716,7 +5891,7 @@ function VersionsPanel({ name, canWrite, onClose }) {
5716
5891
  setIsCreating(false);
5717
5892
  }
5718
5893
  }
5719
- return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.SidePanel, { open: true, onClose, title: name, description: "Ressource commune \xE0 l'entreprise \u2014 toute nouvelle version s'applique \xE0 toutes les apps qui utilisent ce prompt.", children: [
5894
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.SidePanel, { open: true, onClose, title: name, description: "Ressource commune \xE0 l'entreprise \u2014 toute nouvelle version s'applique \xE0 toutes les apps qui utilisent ce prompt.", className: PROMPT_PANEL_CLASS, children: [
5720
5895
  /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-testid": "shared-prompt-versions", className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", children: [
5721
5896
  error !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des versions." }),
5722
5897
  versions.length > 0 && !hasActiveVersion && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-2 text-sm text-status-warning", children: "Aucune version active \u2014 aucune version ne porte le label \xAB production \xBB." }),
@@ -5732,34 +5907,35 @@ function VersionsPanel({ name, canWrite, onClose }) {
5732
5907
  }
5733
5908
  ),
5734
5909
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
5735
- sorted.map((v) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border p-3", children: [
5736
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
5737
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-medium", children: [
5738
- "v",
5739
- v.version,
5740
- " ",
5741
- v.label && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "brand", children: v.label })
5742
- ] }),
5743
- canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
5744
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: () => setPromotingVersion(v.version), children: "Promouvoir" }),
5745
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: () => setDeletingVersion(v.version), children: "Supprimer la version" })
5746
- ] })
5747
- ] }),
5748
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
5749
- "Cr\xE9\xE9e le ",
5750
- formatDate(v.createdAt)
5751
- ] }),
5752
- /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-2 whitespace-pre-wrap text-xs text-muted-foreground", children: v.content })
5753
- ] }, v.version)),
5910
+ sorted.map((v) => /* @__PURE__ */ jsxRuntime.jsx(
5911
+ VersionCard,
5912
+ {
5913
+ version: v,
5914
+ defaultOpen: v.version === expandedVersion,
5915
+ onEditFrom: canWrite ? () => draft.prefill(v.content) : void 0,
5916
+ onPromote: canWrite ? () => setPromotingVersion(v.version) : void 0,
5917
+ onDelete: canWrite ? () => setDeletingVersion(v.version) : void 0
5918
+ },
5919
+ v.version
5920
+ )),
5754
5921
  sorted.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune version pour l'instant." })
5755
5922
  ] }),
5756
5923
  canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-3", children: [
5757
5924
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: newVersionId, className: "block text-sm font-medium", children: "Nouvelle version" }),
5758
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Textarea, { id: newVersionId, value: newContent, onChange: (e) => setNewContent(e.target.value), rows: 8 }),
5925
+ /* @__PURE__ */ jsxRuntime.jsx(
5926
+ PromptTextarea,
5927
+ {
5928
+ id: newVersionId,
5929
+ ref: draft.editorRef,
5930
+ value: draft.content,
5931
+ onChange: (e) => draft.setContent(e.target.value)
5932
+ }
5933
+ ),
5759
5934
  createError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: createError }),
5760
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { onClick: () => void runCreateVersion(), disabled: newContent.trim() === "" || isCreating, children: isCreating ? "Cr\xE9ation\u2026" : "Cr\xE9er la version" })
5935
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { onClick: () => void runCreateVersion(), disabled: draft.content.trim() === "" || isCreating, children: isCreating ? "Cr\xE9ation\u2026" : "Cr\xE9er la version" })
5761
5936
  ] })
5762
5937
  ] }),
5938
+ draft.pendingPrefill !== null && /* @__PURE__ */ jsxRuntime.jsx(ReplaceDraftConfirmModal, { onConfirm: draft.confirmPrefill, onCancel: draft.cancelPrefill }),
5763
5939
  promotingVersion !== null && /* @__PURE__ */ jsxRuntime.jsx(
5764
5940
  ConfirmModal,
5765
5941
  {
@@ -5844,7 +6020,7 @@ function NewSharedPromptModal({ onClose, onCreated }) {
5844
6020
  setIsCreating(false);
5845
6021
  }
5846
6022
  }
5847
- return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Modal, { open: true, onClose, title: "Nouveau prompt partag\xE9", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "space-y-3", onSubmit: (e) => void handleSubmit(e), children: [
6023
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Modal, { open: true, onClose, title: "Nouveau prompt partag\xE9", className: "max-h-[85vh] max-w-2xl overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "space-y-3", onSubmit: (e) => void handleSubmit(e), children: [
5848
6024
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5849
6025
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
5850
6026
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Input, { id: nameId, value: slug, onChange: (e) => handleSlugChange(e.target.value), placeholder: "tone-of-voice" }),
@@ -5856,7 +6032,7 @@ function NewSharedPromptModal({ onClose, onCreated }) {
5856
6032
  ] }),
5857
6033
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5858
6034
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: contentId, className: "mb-1 block text-sm font-medium", children: "Contenu" }),
5859
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Textarea, { id: contentId, value: content, onChange: (e) => setContent(e.target.value), rows: 8 })
6035
+ /* @__PURE__ */ jsxRuntime.jsx(PromptTextarea, { id: contentId, value: content, onChange: (e) => setContent(e.target.value), rows: 12 })
5860
6036
  ] }),
5861
6037
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "La premi\xE8re version est activ\xE9e imm\xE9diatement (production)." }),
5862
6038
  error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: error }),
@@ -5907,7 +6083,7 @@ function SharedPromptsPage() {
5907
6083
  empty: "Aucun prompt \xAB shared/* \xBB accessible depuis cette app."
5908
6084
  }
5909
6085
  ),
5910
- selected && /* @__PURE__ */ jsxRuntime.jsx(VersionsPanel, { name: selected, canWrite, onClose: () => setSelected(null) }),
6086
+ selected && /* @__PURE__ */ jsxRuntime.jsx(VersionsPanel, { name: selected, canWrite, onClose: () => setSelected(null) }, selected),
5911
6087
  isCreateOpen && /* @__PURE__ */ jsxRuntime.jsx(
5912
6088
  NewSharedPromptModal,
5913
6089
  {