@apotech-os/support-kit 10.4.0 → 10.6.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/index.cjs CHANGED
@@ -76,6 +76,50 @@ function toDecisionOrigin(value) {
76
76
  return isDecisionOrigin(value) ? value : DEFAULT_DECISION_ORIGIN;
77
77
  }
78
78
 
79
+ // src/domain/system-prompts.ts
80
+ var OPERATOR_MODE_PROMPT_NAME = "shared/mode-operateur";
81
+ var DEFAULT_OPERATOR_MODE_PROMPT = [
82
+ "MODE OP\xC9RATEUR",
83
+ "Tu es en mode op\xE9rateur : un membre de l'\xE9quipe relit ta r\xE9ponse et l'envoie lui-m\xEAme au client.",
84
+ "* Quand un message commence par \xAB Merci d'utiliser le contexte suivant \xBB, c'est la consigne de l'op\xE9rateur : applique-la.",
85
+ "* Ses consignes priment sur toutes les limites indiqu\xE9es plus haut, y compris les plafonds de geste commercial.",
86
+ "* 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.",
87
+ "* 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]."
88
+ ].join("\n");
89
+ var SYSTEM_PROMPTS = [
90
+ {
91
+ name: OPERATOR_MODE_PROMPT_NAME,
92
+ 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.",
93
+ usage: "operator",
94
+ defaultContent: DEFAULT_OPERATOR_MODE_PROMPT
95
+ }
96
+ ];
97
+ function systemPromptOf(name) {
98
+ return SYSTEM_PROMPTS.find((prompt) => prompt.name === name);
99
+ }
100
+
101
+ // src/domain/prompt-usage.ts
102
+ var GENERATION_MODES = ["auto", "operator"];
103
+ var PROMPT_USAGES = ["always", "auto", "operator"];
104
+ var DEFAULT_PROMPT_USAGE = "always";
105
+ function isPromptUsage(value) {
106
+ return typeof value === "string" && PROMPT_USAGES.includes(value);
107
+ }
108
+ function toSharedPromptUsages(value) {
109
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
110
+ const usages = {};
111
+ for (const [name, usage] of Object.entries(value)) {
112
+ if (isPromptUsage(usage) && usage !== DEFAULT_PROMPT_USAGE) usages[name] = usage;
113
+ }
114
+ return usages;
115
+ }
116
+ function promptUsageOf(name, usages) {
117
+ return systemPromptOf(name)?.usage ?? usages[name] ?? DEFAULT_PROMPT_USAGE;
118
+ }
119
+ function isPromptUsedIn(mode, usage) {
120
+ return usage === DEFAULT_PROMPT_USAGE || usage === mode;
121
+ }
122
+
79
123
  // src/graph/state.ts
80
124
  var OUTCOMES = [
81
125
  "sent",
@@ -923,6 +967,7 @@ async function draftWithTools(params) {
923
967
  label,
924
968
  model: node.model,
925
969
  reasoning: node.reasoning,
970
+ ...node.agent ? { agent: node.agent } : {},
926
971
  messages: conversation,
927
972
  tools,
928
973
  signal: budget.signal,
@@ -1102,6 +1147,7 @@ async function reviseDraft(params) {
1102
1147
  label,
1103
1148
  model: node.model,
1104
1149
  reasoning: node.reasoning,
1150
+ ...node.agent ? { agent: node.agent } : {},
1105
1151
  messages: [...messages, ...buildRevisionTurn(draft2, verdict)],
1106
1152
  tools: [],
1107
1153
  // tool-free by design (§6.4)
@@ -1479,6 +1525,7 @@ async function readComposed(name, opts, ctx, visited, depth) {
1479
1525
  return entry;
1480
1526
  }
1481
1527
  async function resolveOneReference(ref, ctx, visited, depth) {
1528
+ if (!ctx.isActive(ref.name)) return "";
1482
1529
  if (visited.has(ref.name)) {
1483
1530
  ctx.onDegraded?.({ stage: "composition-cycle", name: ref.name, reason: "cyclic composition reference" });
1484
1531
  return "";
@@ -1525,9 +1572,29 @@ function createPromptResolver(deps) {
1525
1572
  const ttlMs = deps.ttlMs ?? DEFAULT_TTL_MS;
1526
1573
  const now = deps.now ?? Date.now;
1527
1574
  const memory = /* @__PURE__ */ new Map();
1528
- const composeCtx = { platform: deps.platform, memory, ttlMs, now, onDegraded: deps.onDegraded };
1575
+ const composeCtx = {
1576
+ platform: deps.platform,
1577
+ memory,
1578
+ ttlMs,
1579
+ now,
1580
+ onDegraded: deps.onDegraded,
1581
+ isActive: () => true
1582
+ };
1583
+ let cacheScope;
1584
+ let filterLoad = null;
1585
+ function loadFilter() {
1586
+ if (!deps.referenceFilter) return Promise.resolve();
1587
+ filterLoad ??= deps.referenceFilter().then((filter) => {
1588
+ composeCtx.isActive = filter.isActive;
1589
+ cacheScope = filter.cacheScope;
1590
+ });
1591
+ return filterLoad;
1592
+ }
1593
+ function persistKeyFor(name, label) {
1594
+ return cacheScope ? `${name}${label}${cacheScope}` : cacheKey(name, label);
1595
+ }
1529
1596
  async function resolveFromCacheOrFallback(name, label, ref, vars) {
1530
- const cached = await deps.cache.read(cacheKey(name, label)).catch((err) => {
1597
+ const cached = await deps.cache.read(persistKeyFor(name, label)).catch((err) => {
1531
1598
  deps.onDegraded?.({ stage: "cache-unavailable", name, reason: reasonOf(err) });
1532
1599
  return null;
1533
1600
  });
@@ -1550,7 +1617,8 @@ function createPromptResolver(deps) {
1550
1617
  return {
1551
1618
  async resolve(ref, vars) {
1552
1619
  const label = ref.label?.trim() || PRODUCTION_LABEL;
1553
- const persistKey = cacheKey(ref.name, label);
1620
+ await loadFilter();
1621
+ const persistKey = persistKeyFor(ref.name, label);
1554
1622
  let resolved;
1555
1623
  try {
1556
1624
  resolved = await readComposed(ref.name, { label }, composeCtx, /* @__PURE__ */ new Set([ref.name]), 0);
@@ -3377,6 +3445,10 @@ var SUPPORT_KIT_SETTINGS_FIELDS = [
3377
3445
  label: "WhatsApp style prompt",
3378
3446
  default: DEFAULT_CHANNEL_PROMPT_WHATSAPP
3379
3447
  },
3448
+ // Shared prompt name → 'auto' | 'operator', for the ones not composed in
3449
+ // both generation modes (`domain/prompt-usage.ts`). Edited from the shared
3450
+ // prompts page, not from the settings form.
3451
+ { key: "sharedPromptUsages", type: "json", label: "Shared prompt usages", default: {} },
3380
3452
  // Misc
3381
3453
  { key: "renameEnabled", type: "boolean", label: "Rename enabled", default: false },
3382
3454
  // §3.6 lists a single `renameTemplate`, but the legacy rename carries TWO
@@ -3751,12 +3823,16 @@ function createPlatformLlmPort(api, trace) {
3751
3823
  );
3752
3824
  }
3753
3825
  const baseTrace = req.trace ?? trace;
3754
- const runTrace = baseTrace && req.promptRef?.name ? {
3826
+ const runTrace = baseTrace ? {
3755
3827
  ...baseTrace,
3756
3828
  metadata: {
3757
3829
  ...baseTrace.metadata,
3758
- prompt_name: req.promptRef.name,
3759
- ...typeof req.promptRef.version === "number" ? { prompt_version: String(req.promptRef.version) } : {}
3830
+ model_id: req.model,
3831
+ reasoning_effort: req.reasoning,
3832
+ ...req.promptRef?.name ? {
3833
+ prompt_name: req.promptRef.name,
3834
+ ...typeof req.promptRef.version === "number" ? { prompt_version: String(req.promptRef.version) } : {}
3835
+ } : {}
3760
3836
  }
3761
3837
  } : baseTrace;
3762
3838
  const result = await api.llm.complete({
@@ -3773,7 +3849,8 @@ function createPlatformLlmPort(api, trace) {
3773
3849
  // `CompletionRequest.promptRef` has.
3774
3850
  ...req.promptRef ? { promptRef: req.promptRef } : {},
3775
3851
  ...req.promptVariables ? { promptVariables: req.promptVariables } : {},
3776
- ...runTrace ? { trace: runTrace } : {}
3852
+ ...runTrace ? { trace: runTrace } : {},
3853
+ ...req.agent ? { agent: req.agent } : {}
3777
3854
  });
3778
3855
  return {
3779
3856
  text: result.text ?? null,
@@ -3811,13 +3888,37 @@ function createRecordPromptCachePort(api) {
3811
3888
  }
3812
3889
  };
3813
3890
  }
3814
- function createPlatformPromptPort(api, log) {
3891
+ function createPlatformPromptPort(api, log, mode = "auto") {
3815
3892
  return createPromptResolver({
3816
3893
  platform: createPlatformPromptReader(api),
3817
3894
  cache: createRecordPromptCachePort(api),
3818
- onDegraded: (event) => log(`prompt resolution degraded [${event.stage}] ${event.name}: ${event.reason}`)
3895
+ onDegraded: (event) => log(`prompt resolution degraded [${event.stage}] ${event.name}: ${event.reason}`),
3896
+ referenceFilter: async () => {
3897
+ const usages = await readSharedPromptUsages(api, log);
3898
+ const left = Object.keys(usages).filter((name) => !isPromptUsedIn(mode, promptUsageOf(name, usages))).sort();
3899
+ return {
3900
+ // Asked per name, not read off `left`: a system prompt has a usage
3901
+ // without being listed in the setting. Its usage never changes, so it
3902
+ // has no place in the cache scope either.
3903
+ isActive: (name) => isPromptUsedIn(mode, promptUsageOf(name, usages)),
3904
+ // Names the prompts left out, so a change of usage reads a different
3905
+ // mirror entry instead of the text composed before it. `auto` with
3906
+ // nothing left out keeps the historical keys: it composes exactly
3907
+ // what this port always composed.
3908
+ cacheScope: mode === "auto" && left.length === 0 ? void 0 : `${mode}:${left.join(",")}`
3909
+ };
3910
+ }
3819
3911
  });
3820
3912
  }
3913
+ async function readSharedPromptUsages(api, log) {
3914
+ try {
3915
+ const settings = await api.settings.get();
3916
+ return toSharedPromptUsages(settings?.sharedPromptUsages);
3917
+ } catch (err) {
3918
+ log(`shared prompt usages unreadable, composing every shared prompt: ${err instanceof Error ? err.message : String(err)}`);
3919
+ return {};
3920
+ }
3921
+ }
3821
3922
  function createRealClock() {
3822
3923
  return { now: () => /* @__PURE__ */ new Date() };
3823
3924
  }
@@ -4267,6 +4368,13 @@ function cap(content) {
4267
4368
  }
4268
4369
 
4269
4370
  // src/functions/records.ts
4371
+ var REASONING_EFFORTS = ["off", "low", "medium", "high"];
4372
+ function isReasoningEffort(value) {
4373
+ return REASONING_EFFORTS.includes(value);
4374
+ }
4375
+ function toReasoningEffort(value) {
4376
+ return isReasoningEffort(value) ? value : null;
4377
+ }
4270
4378
  function toAgent(record) {
4271
4379
  const data = record.data;
4272
4380
  return {
@@ -4278,7 +4386,8 @@ function toAgent(record) {
4278
4386
  promptName: data.promptName ?? "",
4279
4387
  promptLabel: data.promptLabel ?? null,
4280
4388
  promptVersion: data.promptVersion ?? null,
4281
- systemPromptSnapshot: data.systemPromptSnapshot ?? null
4389
+ systemPromptSnapshot: data.systemPromptSnapshot ?? null,
4390
+ reasoningEffort: toReasoningEffort(data.reasoningEffort)
4282
4391
  };
4283
4392
  }
4284
4393
  function toCategory(record) {
@@ -4486,11 +4595,27 @@ function draftPromptRefFor(agent, config) {
4486
4595
  };
4487
4596
  }
4488
4597
  function draftRebinder(api, categories, config) {
4489
- return async (classification) => {
4598
+ return async (classification, profile) => {
4490
4599
  const category = classification ? findCategoryByTag(categories, classification.category) : null;
4491
- return draftPromptRefFor(await resolveDraftAgent(api, category?.agentId ?? null), config);
4600
+ return bindDraftAgent(profile, await resolveDraftAgent(api, category?.agentId ?? null), config);
4492
4601
  };
4493
4602
  }
4603
+ function withAgentModel(profile, agent) {
4604
+ if (!agent) return profile;
4605
+ const onPlatformProvider = (agent.provider.trim() || DEFAULT_LLM_PROVIDER) === DEFAULT_LLM_PROVIDER;
4606
+ const model = onPlatformProvider ? agent.modelId.trim() : "";
4607
+ const effort = agent.reasoningEffort;
4608
+ const apply = (node) => node ? {
4609
+ ...node,
4610
+ ...model ? { model, provider: DEFAULT_LLM_PROVIDER } : {},
4611
+ ...effort ? { reasoning: effort } : {},
4612
+ agent: agent.id
4613
+ } : null;
4614
+ return { ...profile, nodes: { ...profile.nodes, draft: apply(profile.nodes.draft), revise: apply(profile.nodes.revise) } };
4615
+ }
4616
+ function bindDraftAgent(profile, agent, config) {
4617
+ return withAgentModel({ ...profile, prompts: { ...profile.prompts, draft: draftPromptRefFor(agent, config) } }, agent);
4618
+ }
4494
4619
  function buildPromptsTable(config, draft2, nodes) {
4495
4620
  const prompts = config.defaults?.prompts;
4496
4621
  return {
@@ -4596,7 +4721,7 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
4596
4721
  const agentRecord2 = data.agentId ? await getOptional(ctx.api, "agent", data.agentId) : null;
4597
4722
  const agent = agentRecord2 ? toAgent(agentRecord2) : await resolveDraftAgent(ctx.api, null);
4598
4723
  const profile = applyFollowupSendPolicy(
4599
- settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes)),
4724
+ withAgentModel(settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes)), agent),
4600
4725
  origin
4601
4726
  );
4602
4727
  const testRun = options.testRun === true;
@@ -4608,7 +4733,7 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
4608
4733
  metadata: {
4609
4734
  ticket_id: ticketId,
4610
4735
  ...typeof decisionTicketUrl === "string" && decisionTicketUrl !== "" ? { conversation_url: decisionTicketUrl } : {},
4611
- ...agent ? { model: agent.name, model_id: agent.modelId } : {},
4736
+ ...agent ? { model: agent.name } : {},
4612
4737
  ...category ? { category: category.tagName } : {},
4613
4738
  origin
4614
4739
  }
@@ -5352,6 +5477,7 @@ var CREATE_AGENT_INPUT_PROVIDER_UID = "0dd94db4-f31a-4cd2-b030-1b1a4da5b43e";
5352
5477
  var CREATE_AGENT_INPUT_SYSTEM_PROMPT_SNAPSHOT_UID = "d50f3810-b6fe-4c90-b69b-3e36ba502cdb";
5353
5478
  var CREATE_AGENT_INPUT_PROMPT_NAME_UID = "102d412a-3299-42a2-ac62-6f7c4155508d";
5354
5479
  var CREATE_AGENT_INPUT_PROMPT_LABEL_UID = "04f8eeba-2d0b-4814-8009-a4a3d1530760";
5480
+ var CREATE_AGENT_INPUT_REASONING_EFFORT_UID = "4f791f9d-b11f-4369-ae89-2f457deaab04";
5355
5481
  var SET_DEFAULT_AGENT_INPUT_AGENT_ID_UID = "0686c615-63f8-49a1-b3c7-3542bac76cd6";
5356
5482
  var EXT_CHAT_INPUT_MESSAGES_UID = "874e4408-74c0-4188-b923-a0791da4d096";
5357
5483
  var EXT_CHAT_INPUT_MODEL_ID_UID = "d63f05b1-165d-45e0-9300-cabe5e22fa42";
@@ -5631,8 +5757,7 @@ async function runFromTriage(deps, rebindDraft) {
5631
5757
  if (!rebindDraft) return runTicket(deps);
5632
5758
  const triaged = await runTicket(deps, { until: "triage" });
5633
5759
  if (triaged.outcome) return triaged;
5634
- const draft2 = await rebindDraft(triaged.classification);
5635
- const rebound = { ...deps, profile: { ...deps.profile, prompts: { ...deps.profile.prompts, draft: draft2 } } };
5760
+ const rebound = { ...deps, profile: await rebindDraft(triaged.classification, deps.profile) };
5636
5761
  return runTicket(rebound, { resume: { classification: triaged.classification, escalated: triaged.escalated } });
5637
5762
  }
5638
5763
  async function runGraphDryRun({ base, api, resume, rebindDraft }) {
@@ -5800,8 +5925,10 @@ async function graphDryRunHandler(ctx, config, input) {
5800
5925
  const forcedCategory = input.categoryId ? categories.find((c) => c.id === input.categoryId) ?? null : null;
5801
5926
  if (input.categoryId && !forcedCategory) throw new ctx.NonRetriableError(`Category "${input.categoryId}" not found`);
5802
5927
  const agent = input.agentId ? toAgent(await ctx.api.get("agent", input.agentId)) : await resolveDraftAgent(ctx.api, forcedCategory?.agentId ?? null);
5803
- const baseProfile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
5804
- const profile = applyOverrides(baseProfile, input.overrides ?? {});
5928
+ const rebindDraft = input.agentId || forcedCategory ? void 0 : draftRebinder(ctx.api, categories, config);
5929
+ const settingsProfile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
5930
+ const withOverrides = applyOverrides(settingsProfile, input.overrides ?? {});
5931
+ const profile = rebindDraft ? withOverrides : withAgentModel(withOverrides, agent);
5805
5932
  const realPorts = buildTicketPorts(ctx);
5806
5933
  const ref = { id: inlineTicket ? INLINE_TICKET_ID : ticketId, channel: "gorgias" };
5807
5934
  const budget = createBudget({ signal: AbortSignal.timeout(DRY_RUN_DEADLINE_MS), maxToolCalls: profile.nodes.draft?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS2 });
@@ -5829,7 +5956,6 @@ async function graphDryRunHandler(ctx, config, input) {
5829
5956
  // overridden unconditionally by `runGraphDryRun`
5830
5957
  };
5831
5958
  const resume = forcedCategory ? { classification: forcedClassification(forcedCategory.tagName), escalated: false } : void 0;
5832
- const rebindDraft = input.agentId || forcedCategory ? void 0 : draftRebinder(ctx.api, categories, config);
5833
5959
  return runGraphDryRun({ base, api: ctx.api, resume, ...rebindDraft ? { rebindDraft } : {} });
5834
5960
  }
5835
5961
  var DEFAULT_LIMIT = 20;
@@ -5864,8 +5990,9 @@ async function testAgentsHandler(ctx, config, input) {
5864
5990
  const limit = Math.min(input?.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
5865
5991
  const categories = await listCategories(ctx.api);
5866
5992
  const agent = input.agentId ? toAgent(await ctx.api.get("agent", input.agentId)) : await resolveDraftAgent(ctx.api, null);
5867
- const profile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
5868
5993
  const rebindDraft = input.agentId ? void 0 : draftRebinder(ctx.api, categories, config);
5994
+ const settingsProfile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
5995
+ const profile = rebindDraft ? settingsProfile : withAgentModel(settingsProfile, agent);
5869
5996
  const realPorts = buildTicketPorts(ctx);
5870
5997
  const refs = explicitIds.length ? explicitIds.slice(0, limit).map((id) => ({ id, channel: "gorgias" })) : await realPorts.conversation.listPending({ viewOrTag: viewId }, limit);
5871
5998
  const deadline = AbortSignal.timeout(DRY_RUN_DEADLINE_MS);
@@ -6313,6 +6440,13 @@ function buildCreateAgentFunctionDef(config) {
6313
6440
  type: appKit.FieldType.TEXT,
6314
6441
  label: "Prompt label",
6315
6442
  isNullable: true
6443
+ },
6444
+ {
6445
+ universalIdentifier: CREATE_AGENT_INPUT_REASONING_EFFORT_UID,
6446
+ name: "reasoningEffort",
6447
+ type: appKit.FieldType.TEXT,
6448
+ label: "Reasoning effort",
6449
+ isNullable: true
6316
6450
  }
6317
6451
  ]
6318
6452
  };
@@ -6331,7 +6465,8 @@ async function createAgentHandler(ctx, input) {
6331
6465
  provider: input.provider?.trim() || DEFAULT_LLM_PROVIDER,
6332
6466
  status: "available",
6333
6467
  ...input.systemPromptSnapshot?.trim() ? { systemPromptSnapshot: input.systemPromptSnapshot.trim() } : {},
6334
- ...input.promptLabel?.trim() ? { promptLabel: input.promptLabel.trim() } : {}
6468
+ ...input.promptLabel?.trim() ? { promptLabel: input.promptLabel.trim() } : {},
6469
+ ...isReasoningEffort(input.reasoningEffort) ? { reasoningEffort: input.reasoningEffort } : {}
6335
6470
  };
6336
6471
  const promptName = input.promptName?.trim();
6337
6472
  if (promptName) {
@@ -6654,16 +6789,28 @@ async function probeChatOwnership(ctx, modelId) {
6654
6789
  async function executeChat(ctx, userId, input) {
6655
6790
  const contextMessages = await resolveMessages(ctx, input);
6656
6791
  const agent = await resolveAgent(ctx, input.modelId ?? null);
6657
- const promptPort = createPlatformPromptPort(ctx.api, (message) => ctx.logger.warn(message));
6792
+ const promptPort = createPlatformPromptPort(ctx.api, (message) => ctx.logger.warn(message), "operator");
6658
6793
  const promptRef = draftPromptRefFor(agent, { promptPrefix: "" });
6659
- const resolvedPrompt = await promptPort.resolve(promptRef);
6660
- const systemContent = applySignature(resolvedPrompt.text, input.agentName ?? void 0);
6794
+ const [resolvedPrompt, operatorMode] = await Promise.all([
6795
+ promptPort.resolve(promptRef),
6796
+ resolveOperatorMode(promptPort, (message) => ctx.logger.warn(message))
6797
+ ]);
6798
+ const systemContent = withOperatorMode(
6799
+ applySignature(resolvedPrompt.text, input.agentName ?? void 0),
6800
+ operatorMode,
6801
+ input.agentName ?? null
6802
+ );
6661
6803
  const chatMessages = systemContent ? [{ role: "system", content: systemContent }, ...contextMessages] : contextMessages;
6804
+ const reasoningEffort = agent.reasoningEffort ?? await draftStepEffort(ctx);
6662
6805
  const result = await ctx.api.llm.complete({
6663
6806
  messages: chatMessages,
6664
6807
  // The agent's modelId stored in the OS wins; the prompt's Langfuse
6665
6808
  // config is ignored, like every graph node (`draft.ts`, `triage.ts`, …).
6666
- options: { model: agent.modelId },
6809
+ // Its effort too, else the Rédaction step's — the rule the pipeline's
6810
+ // own drafting follows (`withAgentModel`, #355).
6811
+ options: { model: agent.modelId, ...reasoningEffort ? { reasoningEffort } : {} },
6812
+ // Charges the spend to the agent in Paramètres › IA (#355).
6813
+ agent: agent.id,
6667
6814
  // Link-only (D-LF follow-up, option (b)): this function already resolved
6668
6815
  // its own prompt two lines above via `PromptPort` — `resolve: false`
6669
6816
  // links the completion to it in Langfuse WITHOUT re-triggering the
@@ -6704,6 +6851,28 @@ async function executeChat(ctx, userId, input) {
6704
6851
  prompt_version: resolvedPrompt.version
6705
6852
  };
6706
6853
  }
6854
+ async function resolveOperatorMode(promptPort, warn) {
6855
+ try {
6856
+ const resolved = await promptPort.resolve({
6857
+ name: OPERATOR_MODE_PROMPT_NAME,
6858
+ label: "production",
6859
+ fallback: DEFAULT_OPERATOR_MODE_PROMPT
6860
+ });
6861
+ return resolved.text.trim() || DEFAULT_OPERATOR_MODE_PROMPT;
6862
+ } catch (err) {
6863
+ warn(`ext-chat: ${OPERATOR_MODE_PROMPT_NAME} could not be read, serving the default text (${err instanceof Error ? err.message : String(err)})`);
6864
+ return DEFAULT_OPERATOR_MODE_PROMPT;
6865
+ }
6866
+ }
6867
+ function withOperatorMode(systemPrompt, operatorMode, agentName) {
6868
+ const name = agentName?.trim().slice(0, 200);
6869
+ const signature = name ? `
6870
+ * Signe la r\xE9ponse du pr\xE9nom de l'op\xE9rateur, \xAB ${name} \xBB, jamais au nom de l'\xE9quipe.` : "";
6871
+ const block = `${operatorMode}${signature}`;
6872
+ return systemPrompt ? `${systemPrompt}
6873
+
6874
+ ${block}` : block;
6875
+ }
6707
6876
  async function resolveMessages(ctx, input) {
6708
6877
  if (input.gorgiasTicketId) {
6709
6878
  const raw = await runBuildTicketContext(ctx, input.gorgiasTicketId);
@@ -6739,6 +6908,15 @@ function toWireChatMessage(raw) {
6739
6908
  }
6740
6909
  return { role, content: typeof raw.content === "string" ? raw.content : "" };
6741
6910
  }
6911
+ async function draftStepEffort(ctx) {
6912
+ try {
6913
+ const settings = await ctx.api.settings.get();
6914
+ const effort = settings?.nodes?.draft?.reasoning;
6915
+ return isReasoningEffort(effort) ? effort : null;
6916
+ } catch {
6917
+ return null;
6918
+ }
6919
+ }
6742
6920
  async function resolveAgent(ctx, modelId) {
6743
6921
  if (modelId) {
6744
6922
  const record2 = await getOptional(ctx.api, "agent", modelId);
@@ -9354,20 +9532,26 @@ exports.DEFAULT_CHANNEL_PROMPT_WHATSAPP = DEFAULT_CHANNEL_PROMPT_WHATSAPP;
9354
9532
  exports.DEFAULT_CONVERSATION_END_TAG = DEFAULT_CONVERSATION_END_TAG;
9355
9533
  exports.DEFAULT_DECISION_ORIGIN = DEFAULT_DECISION_ORIGIN;
9356
9534
  exports.DEFAULT_LLM_PROVIDER = DEFAULT_LLM_PROVIDER;
9535
+ exports.DEFAULT_OPERATOR_MODE_PROMPT = DEFAULT_OPERATOR_MODE_PROMPT;
9357
9536
  exports.DEFAULT_PROFILE_KEY = DEFAULT_PROFILE_KEY;
9537
+ exports.DEFAULT_PROMPT_USAGE = DEFAULT_PROMPT_USAGE;
9358
9538
  exports.DEFAULT_WHATSAPP_MODE = DEFAULT_WHATSAPP_MODE;
9359
9539
  exports.EVALUATION_VERDICTS = EVALUATION_VERDICTS;
9360
9540
  exports.GENERATED_RESPONSE_STATUSES = GENERATED_RESPONSE_STATUSES;
9541
+ exports.GENERATION_MODES = GENERATION_MODES;
9361
9542
  exports.InvalidStatusTransitionError = InvalidStatusTransitionError;
9362
9543
  exports.MissingPromptError = MissingPromptError;
9363
9544
  exports.NODE_NAMES = NODE_NAMES;
9545
+ exports.OPERATOR_MODE_PROMPT_NAME = OPERATOR_MODE_PROMPT_NAME;
9364
9546
  exports.ORIGIN_DESCRIPTION = ORIGIN_DESCRIPTION;
9365
9547
  exports.OUTCOMES = OUTCOMES;
9366
9548
  exports.PROMPT_SLOTS = PROMPT_SLOTS;
9549
+ exports.PROMPT_USAGES = PROMPT_USAGES;
9367
9550
  exports.REASONING_MAX_LEN = REASONING_MAX_LEN;
9368
9551
  exports.STOP_PHRASES = STOP_PHRASES;
9369
9552
  exports.SUPPORT_CHANNELS = SUPPORT_CHANNELS;
9370
9553
  exports.SUPPORT_KIT_SETTINGS_FIELDS = SUPPORT_KIT_SETTINGS_FIELDS;
9554
+ exports.SYSTEM_PROMPTS = SYSTEM_PROMPTS;
9371
9555
  exports.UNCERTAINTY_MARKERS = UNCERTAINTY_MARKERS;
9372
9556
  exports.WHATSAPP_MODES = WHATSAPP_MODES;
9373
9557
  exports.WHATSAPP_NOTE_CHEVRON = WHATSAPP_NOTE_CHEVRON;
@@ -9407,6 +9591,8 @@ exports.isGeneratedResponseStatus = isGeneratedResponseStatus;
9407
9591
  exports.isJudgemeConversation = isJudgemeConversation;
9408
9592
  exports.isJudgemeTicket = isJudgemeTicket;
9409
9593
  exports.isOutcome = isOutcome;
9594
+ exports.isPromptUsage = isPromptUsage;
9595
+ exports.isPromptUsedIn = isPromptUsedIn;
9410
9596
  exports.isSendable = isSendable;
9411
9597
  exports.isSendableVerdict = isSendableVerdict;
9412
9598
  exports.isTerminalStatus = isTerminalStatus;
@@ -9419,6 +9605,7 @@ exports.openTicketKeyFor = openTicketKeyFor;
9419
9605
  exports.parseReferences = parseReferences;
9420
9606
  exports.pipelineStateRecord = pipelineStateRecord;
9421
9607
  exports.promptCacheRecord = promptCacheRecord;
9608
+ exports.promptUsageOf = promptUsageOf;
9422
9609
  exports.publicationMode = publicationMode;
9423
9610
  exports.rawTicketFactsAt = rawTicketFactsAt;
9424
9611
  exports.readConversationEnd = readConversationEnd;
@@ -9431,9 +9618,11 @@ exports.runTicket = runTicket;
9431
9618
  exports.settingsToProfile = settingsToProfile;
9432
9619
  exports.settingsWarnings = settingsWarnings;
9433
9620
  exports.stopOptOut = stopOptOut;
9621
+ exports.systemPromptOf = systemPromptOf;
9434
9622
  exports.targetRefFor = targetRefFor;
9435
9623
  exports.toConversationEnd = toConversationEnd;
9436
9624
  exports.toDecisionOrigin = toDecisionOrigin;
9625
+ exports.toSharedPromptUsages = toSharedPromptUsages;
9437
9626
  exports.validateSettings = validateSettings;
9438
9627
  exports.verifyReply = verifyReply;
9439
9628
  exports.whatsappModeFromLegacyBoolean = whatsappModeFromLegacyBoolean;