@apotech-os/support-kit 10.4.0 → 10.5.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/README.md +8 -5
- package/dist/{chunk-ZKFQ3DIY.js → chunk-CHOOLNZW.js} +65 -3
- package/dist/chunk-CHOOLNZW.js.map +1 -0
- package/dist/index.cjs +142 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -1
- package/dist/index.d.ts +73 -1
- package/dist/index.js +88 -29
- package/dist/index.js.map +1 -1
- package/dist/ui/index.cjs +413 -24
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.js +369 -27
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-ZKFQ3DIY.js.map +0 -1
package/dist/ui/index.cjs
CHANGED
|
@@ -2431,6 +2431,49 @@ function describeGuardrail(hits, reconstructed) {
|
|
|
2431
2431
|
function asPercent(ratio) {
|
|
2432
2432
|
return Math.round(ratio * 100);
|
|
2433
2433
|
}
|
|
2434
|
+
|
|
2435
|
+
// src/domain/system-prompts.ts
|
|
2436
|
+
var OPERATOR_MODE_PROMPT_NAME = "shared/mode-operateur";
|
|
2437
|
+
var DEFAULT_OPERATOR_MODE_PROMPT = [
|
|
2438
|
+
"MODE OP\xC9RATEUR",
|
|
2439
|
+
"Tu es en mode op\xE9rateur : un membre de l'\xE9quipe relit ta r\xE9ponse et l'envoie lui-m\xEAme au client.",
|
|
2440
|
+
"* Quand un message commence par \xAB Merci d'utiliser le contexte suivant \xBB, c'est la consigne de l'op\xE9rateur : applique-la.",
|
|
2441
|
+
"* Ses consignes priment sur toutes les limites indiqu\xE9es plus haut, y compris les plafonds de geste commercial.",
|
|
2442
|
+
"* N'\xE9cris jamais qu'un agent ou l'\xE9quipe reviendra vers le client, sauf si l'op\xE9rateur le demande : r\xE9dige la r\xE9ponse compl\xE8te, pr\xEAte \xE0 envoyer.",
|
|
2443
|
+
"* S'il te manque une information, r\xE9dige quand m\xEAme la r\xE9ponse et signale le point \xE0 v\xE9rifier entre crochets, par exemple [\xC0 v\xE9rifier : num\xE9ro de commande]."
|
|
2444
|
+
].join("\n");
|
|
2445
|
+
var SYSTEM_PROMPTS = [
|
|
2446
|
+
{
|
|
2447
|
+
name: OPERATOR_MODE_PROMPT_NAME,
|
|
2448
|
+
description: "Ajout\xE9 \xE0 la fin du prompt de l'agent quand un membre de l'\xE9quipe g\xE9n\xE8re une r\xE9ponse depuis l'extension.",
|
|
2449
|
+
usage: "operator",
|
|
2450
|
+
defaultContent: DEFAULT_OPERATOR_MODE_PROMPT
|
|
2451
|
+
}
|
|
2452
|
+
];
|
|
2453
|
+
function systemPromptOf(name) {
|
|
2454
|
+
return SYSTEM_PROMPTS.find((prompt) => prompt.name === name);
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
// src/domain/prompt-usage.ts
|
|
2458
|
+
var PROMPT_USAGES = ["always", "auto", "operator"];
|
|
2459
|
+
var DEFAULT_PROMPT_USAGE = "always";
|
|
2460
|
+
function isPromptUsage(value) {
|
|
2461
|
+
return typeof value === "string" && PROMPT_USAGES.includes(value);
|
|
2462
|
+
}
|
|
2463
|
+
function toSharedPromptUsages(value) {
|
|
2464
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
|
|
2465
|
+
const usages = {};
|
|
2466
|
+
for (const [name, usage] of Object.entries(value)) {
|
|
2467
|
+
if (isPromptUsage(usage) && usage !== DEFAULT_PROMPT_USAGE) usages[name] = usage;
|
|
2468
|
+
}
|
|
2469
|
+
return usages;
|
|
2470
|
+
}
|
|
2471
|
+
function promptUsageOf(name, usages) {
|
|
2472
|
+
return systemPromptOf(name)?.usage ?? usages[name] ?? DEFAULT_PROMPT_USAGE;
|
|
2473
|
+
}
|
|
2474
|
+
function isPromptUsedIn(mode, usage) {
|
|
2475
|
+
return usage === DEFAULT_PROMPT_USAGE || usage === mode;
|
|
2476
|
+
}
|
|
2434
2477
|
var AGENT_GUARDRAILS = [
|
|
2435
2478
|
"whatsapp",
|
|
2436
2479
|
"whatsapp_stop",
|
|
@@ -3464,29 +3507,258 @@ function ConfirmModal({
|
|
|
3464
3507
|
] })
|
|
3465
3508
|
] }) });
|
|
3466
3509
|
}
|
|
3510
|
+
|
|
3511
|
+
// src/prompts/references.ts
|
|
3512
|
+
var REF_RE = /@@@langfusePrompt:name=([^|@]+)\|(?:version=(\d+)|label=([^@]+))@@@/g;
|
|
3513
|
+
var REFERENCE_TAG_SOURCE = REF_RE.source;
|
|
3514
|
+
|
|
3515
|
+
// src/prompts/syntax.ts
|
|
3516
|
+
var PROMPT_VARIABLES = {
|
|
3517
|
+
agent_name: { replacedBy: "le pr\xE9nom de la personne qui r\xE9pond, vide quand l'agent r\xE9pond seul", allowsSpaces: true },
|
|
3518
|
+
categories: { replacedBy: "la liste des cat\xE9gories, dans le prompt de tri uniquement", allowsSpaces: false },
|
|
3519
|
+
channel_prompt: { replacedBy: null, allowsSpaces: false }
|
|
3520
|
+
};
|
|
3521
|
+
var USAGE_SENTENCES = {
|
|
3522
|
+
always: "Inclus dans toutes les r\xE9ponses.",
|
|
3523
|
+
auto: "R\xE9ponse automatique seulement : ignor\xE9 quand un membre de l'\xE9quipe g\xE9n\xE8re une r\xE9ponse depuis l'extension.",
|
|
3524
|
+
operator: "Op\xE9rateur seulement : ignor\xE9 quand l'agent r\xE9pond seul."
|
|
3525
|
+
};
|
|
3526
|
+
var TAG_PREFIX = "@@@langfusePrompt:";
|
|
3527
|
+
var TAG_EXAMPLE = "@@@langfusePrompt:name=shared/nom|label=production@@@";
|
|
3528
|
+
var VARIABLE_RE = /\{\{([^{}\n]*)\}\}/g;
|
|
3529
|
+
var UNCLOSED_VARIABLE_RE = /\{\{(?![^{}\n]*\}\})[^\n]*/g;
|
|
3530
|
+
function referenceTokens(content, knowledge) {
|
|
3531
|
+
const tokens = [];
|
|
3532
|
+
const wellFormedStarts = /* @__PURE__ */ new Set();
|
|
3533
|
+
for (const match of content.matchAll(new RegExp(REFERENCE_TAG_SOURCE, "g"))) {
|
|
3534
|
+
const [raw, name, version, label] = match;
|
|
3535
|
+
const start = match.index ?? 0;
|
|
3536
|
+
wellFormedStarts.add(start);
|
|
3537
|
+
tokens.push({ start, end: start + raw.length, kind: "reference", ...describeReference(name, version, label, knowledge) });
|
|
3538
|
+
}
|
|
3539
|
+
let from = content.indexOf(TAG_PREFIX);
|
|
3540
|
+
while (from !== -1) {
|
|
3541
|
+
if (!wellFormedStarts.has(from)) {
|
|
3542
|
+
tokens.push({
|
|
3543
|
+
start: from,
|
|
3544
|
+
end: malformedEnd(content, from),
|
|
3545
|
+
kind: "malformed",
|
|
3546
|
+
status: "error",
|
|
3547
|
+
message: `R\xE9f\xE9rence mal form\xE9e, elle sera envoy\xE9e telle quelle au mod\xE8le. Forme attendue : ${TAG_EXAMPLE}`
|
|
3548
|
+
});
|
|
3549
|
+
}
|
|
3550
|
+
from = content.indexOf(TAG_PREFIX, from + TAG_PREFIX.length);
|
|
3551
|
+
}
|
|
3552
|
+
return tokens;
|
|
3553
|
+
}
|
|
3554
|
+
function malformedEnd(content, start) {
|
|
3555
|
+
const lineEnd = content.indexOf("\n", start);
|
|
3556
|
+
const limit = lineEnd === -1 ? content.length : lineEnd;
|
|
3557
|
+
const closing = content.indexOf("@@@", start + TAG_PREFIX.length);
|
|
3558
|
+
return closing !== -1 && closing < limit ? closing + 3 : limit;
|
|
3559
|
+
}
|
|
3560
|
+
function describeReference(name, version, label, knowledge) {
|
|
3561
|
+
const entry = knowledge.catalogue?.find((prompt) => prompt.name === name);
|
|
3562
|
+
if (knowledge.catalogue && !entry) {
|
|
3563
|
+
return { status: "error", message: `Prompt introuvable : \xAB ${name} \xBB n'existe pas ou n'est pas accessible depuis cette app.` };
|
|
3564
|
+
}
|
|
3565
|
+
if (entry && version !== void 0 && Number(version) > entry.latestVersion) {
|
|
3566
|
+
return { status: "error", message: `La version ${version} de \xAB ${name} \xBB n'existe pas (derni\xE8re version : ${entry.latestVersion}).` };
|
|
3567
|
+
}
|
|
3568
|
+
if (entry && label !== void 0 && !entry.labels.includes(label)) {
|
|
3569
|
+
return { status: "error", message: `Aucune version de \xAB ${name} \xBB ne porte le label \xAB ${label} \xBB.` };
|
|
3570
|
+
}
|
|
3571
|
+
const usage = promptUsageOf(name, knowledge.usages);
|
|
3572
|
+
const target = version !== void 0 ? `version ${version}` : `label \xAB ${label} \xBB`;
|
|
3573
|
+
return {
|
|
3574
|
+
status: isPromptUsedIn("auto", usage) && isPromptUsedIn("operator", usage) ? "ok" : "restricted",
|
|
3575
|
+
message: `Prompt \xAB ${name} \xBB, ${target}. ${USAGE_SENTENCES[usage]}`
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
function variableTokens(content) {
|
|
3579
|
+
const tokens = [];
|
|
3580
|
+
for (const match of content.matchAll(VARIABLE_RE)) {
|
|
3581
|
+
const start = match.index ?? 0;
|
|
3582
|
+
const inner = match[1] ?? "";
|
|
3583
|
+
tokens.push({ start, end: start + match[0].length, kind: "variable", ...describeVariable(inner) });
|
|
3584
|
+
}
|
|
3585
|
+
for (const match of content.matchAll(UNCLOSED_VARIABLE_RE)) {
|
|
3586
|
+
const start = match.index ?? 0;
|
|
3587
|
+
tokens.push({
|
|
3588
|
+
start,
|
|
3589
|
+
end: start + match[0].length,
|
|
3590
|
+
kind: "variable",
|
|
3591
|
+
status: "error",
|
|
3592
|
+
message: "Accolades \xAB {{ \xBB sans fermeture \xAB }} \xBB sur la m\xEAme ligne."
|
|
3593
|
+
});
|
|
3594
|
+
}
|
|
3595
|
+
return tokens;
|
|
3596
|
+
}
|
|
3597
|
+
function describeVariable(inner) {
|
|
3598
|
+
const name = inner.trim();
|
|
3599
|
+
const known = PROMPT_VARIABLES[name];
|
|
3600
|
+
if (!known) {
|
|
3601
|
+
return {
|
|
3602
|
+
status: "error",
|
|
3603
|
+
message: `Variable inconnue : \xAB {{${name}}} \xBB ne sera pas remplac\xE9e. Variables disponibles : ${Object.keys(PROMPT_VARIABLES).join(", ")}.`
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
if (known.replacedBy === null) {
|
|
3607
|
+
return { status: "error", message: `\xAB {{${name}}} \xBB n'est pas remplac\xE9e pour l'instant : elle arrive telle quelle au mod\xE8le.` };
|
|
3608
|
+
}
|
|
3609
|
+
if (inner !== name && !known.allowsSpaces) {
|
|
3610
|
+
return { status: "error", message: `\xC9crire \xAB {{${name}}} \xBB sans espaces, sinon la variable n'est pas remplac\xE9e.` };
|
|
3611
|
+
}
|
|
3612
|
+
return { status: "ok", message: `Variable remplac\xE9e par ${known.replacedBy}.` };
|
|
3613
|
+
}
|
|
3614
|
+
function readPromptSyntax(content, knowledge) {
|
|
3615
|
+
const drafts = [...referenceTokens(content, knowledge), ...variableTokens(content)].sort((a, b) => a.start - b.start);
|
|
3616
|
+
const tokens = [];
|
|
3617
|
+
let cursor = 0;
|
|
3618
|
+
let line = 1;
|
|
3619
|
+
let counted = 0;
|
|
3620
|
+
for (const draft of drafts) {
|
|
3621
|
+
if (draft.start < cursor) continue;
|
|
3622
|
+
for (; counted < draft.start; counted += 1) if (content[counted] === "\n") line += 1;
|
|
3623
|
+
tokens.push({ ...draft, line });
|
|
3624
|
+
cursor = draft.end;
|
|
3625
|
+
}
|
|
3626
|
+
return tokens;
|
|
3627
|
+
}
|
|
3628
|
+
var PROMPT_USAGE_LABELS = {
|
|
3629
|
+
always: "Toujours",
|
|
3630
|
+
auto: "R\xE9ponse automatique seulement",
|
|
3631
|
+
operator: "Op\xE9rateur seulement"
|
|
3632
|
+
};
|
|
3633
|
+
var PROMPT_USAGE_HINTS = {
|
|
3634
|
+
always: "Inclus dans toutes les r\xE9ponses.",
|
|
3635
|
+
auto: "Inclus seulement quand l'agent r\xE9pond seul. Ignor\xE9 quand un membre de l'\xE9quipe g\xE9n\xE8re une r\xE9ponse depuis l'extension.",
|
|
3636
|
+
operator: "Inclus seulement quand un membre de l'\xE9quipe g\xE9n\xE8re une r\xE9ponse depuis l'extension. Ignor\xE9 quand l'agent r\xE9pond seul."
|
|
3637
|
+
};
|
|
3638
|
+
var PROMPT_USAGE_OPTIONS = Object.keys(PROMPT_USAGE_LABELS).map((value) => ({
|
|
3639
|
+
value,
|
|
3640
|
+
label: PROMPT_USAGE_LABELS[value]
|
|
3641
|
+
}));
|
|
3642
|
+
function useSharedPromptUsages() {
|
|
3643
|
+
const { settings, error, save, isSaving, saveError } = uiSdk.useAppSettings();
|
|
3644
|
+
const usages = toSharedPromptUsages(settings?.sharedPromptUsages);
|
|
3645
|
+
const isReady = settings !== void 0 && error === void 0;
|
|
3646
|
+
return {
|
|
3647
|
+
usages,
|
|
3648
|
+
usageOf: (name) => promptUsageOf(name, usages),
|
|
3649
|
+
isReady,
|
|
3650
|
+
setUsage: (name, usage) => {
|
|
3651
|
+
if (!isReady) return Promise.resolve();
|
|
3652
|
+
const next = { ...usages };
|
|
3653
|
+
if (usage === DEFAULT_PROMPT_USAGE) delete next[name];
|
|
3654
|
+
else next[name] = usage;
|
|
3655
|
+
return save({ sharedPromptUsages: next });
|
|
3656
|
+
},
|
|
3657
|
+
isSaving,
|
|
3658
|
+
saveError
|
|
3659
|
+
};
|
|
3660
|
+
}
|
|
3467
3661
|
var PROMPT_PANEL_CLASS = "w-[min(92vw,64rem)] max-w-none";
|
|
3468
3662
|
var PRODUCTION_LABEL = "production";
|
|
3663
|
+
var TOKEN_CLASSES = {
|
|
3664
|
+
ok: "rounded-sm bg-status-info/15 text-status-info",
|
|
3665
|
+
restricted: "rounded-sm bg-status-pending/15 text-status-pending underline decoration-dashed underline-offset-2",
|
|
3666
|
+
error: "rounded-sm bg-status-blocked/15 text-status-blocked underline decoration-wavy underline-offset-2"
|
|
3667
|
+
};
|
|
3668
|
+
var EDITOR_BOX = "whitespace-pre-wrap break-words px-3 py-2 font-mono text-xs leading-relaxed [scrollbar-gutter:stable]";
|
|
3469
3669
|
var PromptTextarea = react.forwardRef(
|
|
3470
|
-
function PromptTextarea2({ value, className, rows = 14, ...props }, ref) {
|
|
3670
|
+
function PromptTextarea2({ value, className, rows = 14, onScroll, ...props }, ref) {
|
|
3671
|
+
const knowledge = usePromptSyntaxKnowledge();
|
|
3672
|
+
const tokens = react.useMemo(() => readPromptSyntax(value, knowledge), [value, knowledge]);
|
|
3673
|
+
const layerRef = react.useRef(null);
|
|
3674
|
+
const [hovered, setHovered] = react.useState(null);
|
|
3675
|
+
const errors = tokens.filter((token) => token.status === "error");
|
|
3676
|
+
function hoverAt(event) {
|
|
3677
|
+
const index = document.elementsFromPoint?.(event.clientX, event.clientY).map((el) => el instanceof HTMLElement ? el.dataset.promptToken : void 0).find((found) => found !== void 0);
|
|
3678
|
+
const token = index === void 0 ? void 0 : tokens[Number(index)];
|
|
3679
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
3680
|
+
setHovered(token ? { token, x: event.clientX - box.left, y: event.clientY - box.top } : null);
|
|
3681
|
+
}
|
|
3471
3682
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3472
|
-
/* @__PURE__ */ jsxRuntime.
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3683
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
3684
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3685
|
+
"pre",
|
|
3686
|
+
{
|
|
3687
|
+
ref: layerRef,
|
|
3688
|
+
"aria-hidden": true,
|
|
3689
|
+
"data-testid": "prompt-syntax-layer",
|
|
3690
|
+
className: uiSdk.cn("absolute inset-0 m-0 overflow-hidden border border-transparent text-foreground", EDITOR_BOX),
|
|
3691
|
+
children: [
|
|
3692
|
+
renderSegments(value, tokens),
|
|
3693
|
+
value.endsWith("\n") ? " " : null
|
|
3694
|
+
]
|
|
3695
|
+
}
|
|
3696
|
+
),
|
|
3697
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3698
|
+
uiSdk.Textarea,
|
|
3699
|
+
{
|
|
3700
|
+
ref,
|
|
3701
|
+
value,
|
|
3702
|
+
rows,
|
|
3703
|
+
spellCheck: false,
|
|
3704
|
+
className: uiSdk.cn("relative text-transparent caret-foreground", EDITOR_BOX, className),
|
|
3705
|
+
onScroll: (event) => {
|
|
3706
|
+
if (layerRef.current) layerRef.current.scrollTop = event.currentTarget.scrollTop;
|
|
3707
|
+
setHovered(null);
|
|
3708
|
+
onScroll?.(event);
|
|
3709
|
+
},
|
|
3710
|
+
onMouseMove: hoverAt,
|
|
3711
|
+
onMouseLeave: () => setHovered(null),
|
|
3712
|
+
...props
|
|
3713
|
+
}
|
|
3714
|
+
),
|
|
3715
|
+
hovered && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3716
|
+
"div",
|
|
3717
|
+
{
|
|
3718
|
+
role: "tooltip",
|
|
3719
|
+
className: "pointer-events-none absolute z-50 max-w-sm rounded-md bg-foreground px-2 py-1 text-xs text-background shadow-md",
|
|
3720
|
+
style: { left: hovered.x + 12, top: hovered.y + 16 },
|
|
3721
|
+
children: hovered.token.message
|
|
3722
|
+
}
|
|
3723
|
+
)
|
|
3724
|
+
] }),
|
|
3482
3725
|
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-right text-xs text-muted-foreground", children: [
|
|
3483
3726
|
value.length.toLocaleString("fr-FR"),
|
|
3484
3727
|
" caract\xE8re",
|
|
3485
3728
|
value.length > 1 ? "s" : ""
|
|
3486
|
-
] })
|
|
3729
|
+
] }),
|
|
3730
|
+
errors.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { "aria-label": "Erreurs dans le prompt", className: "mt-1 space-y-1 text-xs", children: errors.map((token) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "flex gap-2", children: [
|
|
3731
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: "text-status-blocked", children: "\u2715" }),
|
|
3732
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [
|
|
3733
|
+
"Ligne ",
|
|
3734
|
+
token.line,
|
|
3735
|
+
" : ",
|
|
3736
|
+
token.message
|
|
3737
|
+
] })
|
|
3738
|
+
] }, `${token.start}-${token.end}`)) })
|
|
3487
3739
|
] });
|
|
3488
3740
|
}
|
|
3489
3741
|
);
|
|
3742
|
+
function renderSegments(value, tokens) {
|
|
3743
|
+
const segments = [];
|
|
3744
|
+
let cursor = 0;
|
|
3745
|
+
tokens.forEach((token, index) => {
|
|
3746
|
+
if (token.start > cursor) segments.push(value.slice(cursor, token.start));
|
|
3747
|
+
segments.push(
|
|
3748
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-prompt-token": index, "data-status": token.status, className: TOKEN_CLASSES[token.status], children: value.slice(token.start, token.end) }, token.start)
|
|
3749
|
+
);
|
|
3750
|
+
cursor = token.end;
|
|
3751
|
+
});
|
|
3752
|
+
if (cursor < value.length) segments.push(value.slice(cursor));
|
|
3753
|
+
return segments;
|
|
3754
|
+
}
|
|
3755
|
+
function usePromptSyntaxKnowledge() {
|
|
3756
|
+
const { prompts, isLoading, error } = usePromptCatalogue();
|
|
3757
|
+
const { usages } = useSharedPromptUsages();
|
|
3758
|
+
const catalogue = isLoading || error !== void 0 ? null : prompts;
|
|
3759
|
+
const usagesKey = JSON.stringify(usages);
|
|
3760
|
+
return react.useMemo(() => ({ catalogue, usages }), [catalogue, usagesKey]);
|
|
3761
|
+
}
|
|
3490
3762
|
function defaultExpandedVersion(versions) {
|
|
3491
3763
|
const production = versions.find((v) => v.labels.includes(PRODUCTION_LABEL));
|
|
3492
3764
|
if (production) return production.version;
|
|
@@ -3541,8 +3813,8 @@ function VersionCard({
|
|
|
3541
3813
|
] })
|
|
3542
3814
|
] });
|
|
3543
3815
|
}
|
|
3544
|
-
function useNewVersionDraft() {
|
|
3545
|
-
const [content, setContent] = react.useState(
|
|
3816
|
+
function useNewVersionDraft(initialContent = "") {
|
|
3817
|
+
const [content, setContent] = react.useState(initialContent);
|
|
3546
3818
|
const [pendingPrefill, setPendingPrefill] = react.useState(null);
|
|
3547
3819
|
const editorRef = react.useRef(null);
|
|
3548
3820
|
function loadIntoEditor(versionContent) {
|
|
@@ -7141,9 +7413,23 @@ function useSharedPrompts() {
|
|
|
7141
7413
|
var SHARED_PREFIX2 = "shared/";
|
|
7142
7414
|
var SLUG_RE = /^[a-z0-9-]{1,64}$/;
|
|
7143
7415
|
var SLUG_ERROR = "Le nom doit contenir 1 \xE0 64 minuscules, chiffres ou tirets.";
|
|
7144
|
-
function VersionsPanel({
|
|
7145
|
-
|
|
7146
|
-
|
|
7416
|
+
function VersionsPanel({
|
|
7417
|
+
name,
|
|
7418
|
+
canWrite,
|
|
7419
|
+
usage,
|
|
7420
|
+
isAdmin,
|
|
7421
|
+
canEditUsage,
|
|
7422
|
+
isSavingUsage,
|
|
7423
|
+
onUsageChange,
|
|
7424
|
+
system,
|
|
7425
|
+
isPublished,
|
|
7426
|
+
servesDefault,
|
|
7427
|
+
onPublished,
|
|
7428
|
+
onClose
|
|
7429
|
+
}) {
|
|
7430
|
+
const [exists, setExists] = react.useState(isPublished);
|
|
7431
|
+
const { versions, error, promote, deleteVersion, refresh } = usePromptVersions(exists ? name : null);
|
|
7432
|
+
const draft = useNewVersionDraft(servesDefault ? system?.defaultContent ?? "" : "");
|
|
7147
7433
|
const [isCreating, setIsCreating] = react.useState(false);
|
|
7148
7434
|
const [createError, setCreateError] = react.useState(null);
|
|
7149
7435
|
const [deletingVersion, setDeletingVersion] = react.useState(null);
|
|
@@ -7153,6 +7439,7 @@ function VersionsPanel({ name, canWrite, onClose }) {
|
|
|
7153
7439
|
const [compareRight, setCompareRight] = react.useState(null);
|
|
7154
7440
|
const newVersionId = react.useId();
|
|
7155
7441
|
const api = uiSdk.useAppApi();
|
|
7442
|
+
const { appSlug } = uiSdk.useAppContext();
|
|
7156
7443
|
const toast = uiSdk.useToast();
|
|
7157
7444
|
const sorted = [...versions].sort((a, b) => b.version - a.version);
|
|
7158
7445
|
const expandedVersion = defaultExpandedVersion(versions);
|
|
@@ -7170,6 +7457,7 @@ function VersionsPanel({ name, canWrite, onClose }) {
|
|
|
7170
7457
|
const version = promotingVersion;
|
|
7171
7458
|
try {
|
|
7172
7459
|
await promote(version);
|
|
7460
|
+
onPublished();
|
|
7173
7461
|
toast({ title: `Version ${version} promue en production.`, variant: "success" });
|
|
7174
7462
|
} catch (err) {
|
|
7175
7463
|
toast({ title: "\xC9chec de la promotion", description: describeApiError(err), variant: "error" });
|
|
@@ -7195,13 +7483,21 @@ function VersionsPanel({ name, canWrite, onClose }) {
|
|
|
7195
7483
|
setCreateError(null);
|
|
7196
7484
|
const payload = { name, content: draft.content };
|
|
7197
7485
|
try {
|
|
7198
|
-
await api.invoke(
|
|
7486
|
+
const result = await api.invoke(
|
|
7199
7487
|
"create-shared-prompt-version",
|
|
7200
7488
|
payload,
|
|
7201
7489
|
{ idempotencyKey: idempotencyKeyFor("create-shared-prompt-version", payload) }
|
|
7202
7490
|
);
|
|
7203
7491
|
draft.setContent("");
|
|
7204
|
-
|
|
7492
|
+
if (exists) {
|
|
7493
|
+
await refresh();
|
|
7494
|
+
} else {
|
|
7495
|
+
await api.post(`/data/apps/${appSlug}/prompts/promote`, { name, version: result.version, label: PRODUCTION_LABEL }).catch(() => {
|
|
7496
|
+
toast({ title: "Version cr\xE9\xE9e, mais pas encore en production", description: "Promouvez-la pour qu'elle soit utilis\xE9e.", variant: "error" });
|
|
7497
|
+
});
|
|
7498
|
+
setExists(true);
|
|
7499
|
+
onPublished();
|
|
7500
|
+
}
|
|
7205
7501
|
} catch (err) {
|
|
7206
7502
|
setCreateError(describeInvokeError(err));
|
|
7207
7503
|
} finally {
|
|
@@ -7211,6 +7507,37 @@ function VersionsPanel({ name, canWrite, onClose }) {
|
|
|
7211
7507
|
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: [
|
|
7212
7508
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { "data-testid": "shared-prompt-versions", className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", children: [
|
|
7213
7509
|
error !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des versions." }),
|
|
7510
|
+
system && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 rounded-md border bg-muted/40 p-3 text-sm", children: [
|
|
7511
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium", children: "Prompt syst\xE8me" }),
|
|
7512
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground", children: [
|
|
7513
|
+
system.description,
|
|
7514
|
+
" Il existe toujours et son nom ne peut pas changer : seul son texte se modifie."
|
|
7515
|
+
] }),
|
|
7516
|
+
(!exists || versions.length > 0 && !hasActiveVersion) && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground", children: [
|
|
7517
|
+
"Aucune version en production : le texte par d\xE9faut est utilis\xE9.",
|
|
7518
|
+
exists ? " Promouvez une version pour la mettre en service." : " Cr\xE9ez une version pour le modifier."
|
|
7519
|
+
] })
|
|
7520
|
+
] }),
|
|
7521
|
+
!system && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
|
|
7522
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "block text-sm font-medium", children: "Utilisation" }),
|
|
7523
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7524
|
+
uiSdk.Select,
|
|
7525
|
+
{
|
|
7526
|
+
"aria-label": "Utilisation",
|
|
7527
|
+
value: usage,
|
|
7528
|
+
onValueChange: (value) => {
|
|
7529
|
+
if (isPromptUsage(value)) onUsageChange(value);
|
|
7530
|
+
},
|
|
7531
|
+
items: PROMPT_USAGE_OPTIONS,
|
|
7532
|
+
disabled: !canEditUsage || isSavingUsage
|
|
7533
|
+
}
|
|
7534
|
+
),
|
|
7535
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
7536
|
+
PROMPT_USAGE_HINTS[usage],
|
|
7537
|
+
" Ce r\xE9glage ne vaut que pour cette app.",
|
|
7538
|
+
!isAdmin && " Seul un administrateur de l'app peut le changer."
|
|
7539
|
+
] })
|
|
7540
|
+
] }),
|
|
7214
7541
|
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." }),
|
|
7215
7542
|
versions.length >= 2 && /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: openCompare, children: "Comparer" }) }),
|
|
7216
7543
|
isComparing && compareLeft !== null && compareRight !== null && /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -7235,7 +7562,7 @@ function VersionsPanel({ name, canWrite, onClose }) {
|
|
|
7235
7562
|
},
|
|
7236
7563
|
v.version
|
|
7237
7564
|
)),
|
|
7238
|
-
sorted.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune version pour l'instant." })
|
|
7565
|
+
sorted.length === 0 && exists && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune version pour l'instant." })
|
|
7239
7566
|
] }),
|
|
7240
7567
|
canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-3", children: [
|
|
7241
7568
|
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: newVersionId, className: "block text-sm font-medium", children: "Nouvelle version" }),
|
|
@@ -7363,16 +7690,61 @@ function SharedPromptsPage() {
|
|
|
7363
7690
|
const { role } = uiSdk.useAppContext();
|
|
7364
7691
|
const canWrite = canWriteForRole(role);
|
|
7365
7692
|
const { prompts, isLoading, error, refresh } = useSharedPrompts();
|
|
7693
|
+
const { usageOf, setUsage, isReady: areUsagesReady, isSaving: isSavingUsage, saveError: usageSaveError } = useSharedPromptUsages();
|
|
7694
|
+
const toast = uiSdk.useToast();
|
|
7366
7695
|
const [selected, setSelected] = react.useState(null);
|
|
7367
7696
|
const [isCreateOpen, setIsCreateOpen] = react.useState(false);
|
|
7697
|
+
const wasSavingUsageRef = react.useRef(false);
|
|
7698
|
+
react.useEffect(() => {
|
|
7699
|
+
if (wasSavingUsageRef.current && !isSavingUsage) {
|
|
7700
|
+
if (usageSaveError === void 0) toast({ title: "Utilisation enregistr\xE9e.", variant: "success" });
|
|
7701
|
+
else toast({ title: "\xC9chec de l'enregistrement", description: describeApiError(usageSaveError), variant: "error" });
|
|
7702
|
+
}
|
|
7703
|
+
wasSavingUsageRef.current = isSavingUsage;
|
|
7704
|
+
}, [isSavingUsage, usageSaveError, toast]);
|
|
7705
|
+
const publishedNames = new Set(prompts.map((prompt) => prompt.name));
|
|
7706
|
+
const rows = isLoading || error ? prompts : [
|
|
7707
|
+
...prompts,
|
|
7708
|
+
...SYSTEM_PROMPTS.filter((system) => !publishedNames.has(system.name)).map((system) => ({
|
|
7709
|
+
name: system.name,
|
|
7710
|
+
labels: [],
|
|
7711
|
+
latestVersion: 0,
|
|
7712
|
+
isUnpublished: true
|
|
7713
|
+
}))
|
|
7714
|
+
].sort((a, b) => a.name.localeCompare(b.name));
|
|
7715
|
+
const selectedSystem = selected ? systemPromptOf(selected) : void 0;
|
|
7368
7716
|
const columns = [
|
|
7369
|
-
{
|
|
7717
|
+
{
|
|
7718
|
+
key: "name",
|
|
7719
|
+
header: "Nom",
|
|
7720
|
+
cell: (row) => systemPromptOf(row.name) ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-2", children: [
|
|
7721
|
+
row.name,
|
|
7722
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { children: "Syst\xE8me" })
|
|
7723
|
+
] }) : row.name
|
|
7724
|
+
},
|
|
7725
|
+
{
|
|
7726
|
+
key: "usage",
|
|
7727
|
+
header: "Utilisation",
|
|
7728
|
+
cell: (row) => {
|
|
7729
|
+
const usage = systemPromptOf(row.name)?.usage ?? usageOf(row.name);
|
|
7730
|
+
return usage === DEFAULT_PROMPT_USAGE ? PROMPT_USAGE_LABELS[usage] : /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "info", children: PROMPT_USAGE_LABELS[usage] });
|
|
7731
|
+
}
|
|
7732
|
+
},
|
|
7370
7733
|
{
|
|
7371
7734
|
key: "labels",
|
|
7372
7735
|
header: "Labels",
|
|
7373
7736
|
cell: (row) => row.labels.length > 0 ? row.labels.map((l) => /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { children: l }, l)) : "\u2014"
|
|
7374
7737
|
},
|
|
7375
|
-
{
|
|
7738
|
+
{
|
|
7739
|
+
key: "latestVersion",
|
|
7740
|
+
header: "Derni\xE8re version",
|
|
7741
|
+
align: "right",
|
|
7742
|
+
cell: (row) => {
|
|
7743
|
+
if (row.isUnpublished) return "Texte par d\xE9faut";
|
|
7744
|
+
const servesDefault = systemPromptOf(row.name) && !row.labels.includes(PRODUCTION_LABEL);
|
|
7745
|
+
return servesDefault ? `v${row.latestVersion} \xB7 texte par d\xE9faut utilis\xE9` : `v${row.latestVersion}`;
|
|
7746
|
+
}
|
|
7747
|
+
}
|
|
7376
7748
|
];
|
|
7377
7749
|
return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
|
|
7378
7750
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -7388,7 +7760,7 @@ function SharedPromptsPage() {
|
|
|
7388
7760
|
uiSdk.DataTable,
|
|
7389
7761
|
{
|
|
7390
7762
|
columns,
|
|
7391
|
-
rows
|
|
7763
|
+
rows,
|
|
7392
7764
|
rowId: (row) => row.name,
|
|
7393
7765
|
manual: true,
|
|
7394
7766
|
loading: isLoading,
|
|
@@ -7400,7 +7772,24 @@ function SharedPromptsPage() {
|
|
|
7400
7772
|
empty: "Aucun prompt \xAB shared/* \xBB accessible depuis cette app."
|
|
7401
7773
|
}
|
|
7402
7774
|
),
|
|
7403
|
-
selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
7775
|
+
selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
7776
|
+
VersionsPanel,
|
|
7777
|
+
{
|
|
7778
|
+
name: selected,
|
|
7779
|
+
canWrite,
|
|
7780
|
+
usage: usageOf(selected),
|
|
7781
|
+
isAdmin: role === "ADMIN",
|
|
7782
|
+
canEditUsage: role === "ADMIN" && areUsagesReady,
|
|
7783
|
+
isSavingUsage,
|
|
7784
|
+
onUsageChange: (usage) => void setUsage(selected, usage),
|
|
7785
|
+
system: selectedSystem,
|
|
7786
|
+
isPublished: !rows.some((row) => row.name === selected && row.isUnpublished),
|
|
7787
|
+
servesDefault: selectedSystem !== void 0 && !rows.some((row) => row.name === selected && row.labels.includes(PRODUCTION_LABEL)),
|
|
7788
|
+
onPublished: () => void refresh(),
|
|
7789
|
+
onClose: () => setSelected(null)
|
|
7790
|
+
},
|
|
7791
|
+
selected
|
|
7792
|
+
),
|
|
7404
7793
|
isCreateOpen && /* @__PURE__ */ jsxRuntime.jsx(
|
|
7405
7794
|
NewSharedPromptModal,
|
|
7406
7795
|
{
|