@apotech-os/support-kit 10.5.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
@@ -967,6 +967,7 @@ async function draftWithTools(params) {
967
967
  label,
968
968
  model: node.model,
969
969
  reasoning: node.reasoning,
970
+ ...node.agent ? { agent: node.agent } : {},
970
971
  messages: conversation,
971
972
  tools,
972
973
  signal: budget.signal,
@@ -1146,6 +1147,7 @@ async function reviseDraft(params) {
1146
1147
  label,
1147
1148
  model: node.model,
1148
1149
  reasoning: node.reasoning,
1150
+ ...node.agent ? { agent: node.agent } : {},
1149
1151
  messages: [...messages, ...buildRevisionTurn(draft2, verdict)],
1150
1152
  tools: [],
1151
1153
  // tool-free by design (§6.4)
@@ -3821,12 +3823,16 @@ function createPlatformLlmPort(api, trace) {
3821
3823
  );
3822
3824
  }
3823
3825
  const baseTrace = req.trace ?? trace;
3824
- const runTrace = baseTrace && req.promptRef?.name ? {
3826
+ const runTrace = baseTrace ? {
3825
3827
  ...baseTrace,
3826
3828
  metadata: {
3827
3829
  ...baseTrace.metadata,
3828
- prompt_name: req.promptRef.name,
3829
- ...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
+ } : {}
3830
3836
  }
3831
3837
  } : baseTrace;
3832
3838
  const result = await api.llm.complete({
@@ -3843,7 +3849,8 @@ function createPlatformLlmPort(api, trace) {
3843
3849
  // `CompletionRequest.promptRef` has.
3844
3850
  ...req.promptRef ? { promptRef: req.promptRef } : {},
3845
3851
  ...req.promptVariables ? { promptVariables: req.promptVariables } : {},
3846
- ...runTrace ? { trace: runTrace } : {}
3852
+ ...runTrace ? { trace: runTrace } : {},
3853
+ ...req.agent ? { agent: req.agent } : {}
3847
3854
  });
3848
3855
  return {
3849
3856
  text: result.text ?? null,
@@ -4361,6 +4368,13 @@ function cap(content) {
4361
4368
  }
4362
4369
 
4363
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
+ }
4364
4378
  function toAgent(record) {
4365
4379
  const data = record.data;
4366
4380
  return {
@@ -4372,7 +4386,8 @@ function toAgent(record) {
4372
4386
  promptName: data.promptName ?? "",
4373
4387
  promptLabel: data.promptLabel ?? null,
4374
4388
  promptVersion: data.promptVersion ?? null,
4375
- systemPromptSnapshot: data.systemPromptSnapshot ?? null
4389
+ systemPromptSnapshot: data.systemPromptSnapshot ?? null,
4390
+ reasoningEffort: toReasoningEffort(data.reasoningEffort)
4376
4391
  };
4377
4392
  }
4378
4393
  function toCategory(record) {
@@ -4580,11 +4595,27 @@ function draftPromptRefFor(agent, config) {
4580
4595
  };
4581
4596
  }
4582
4597
  function draftRebinder(api, categories, config) {
4583
- return async (classification) => {
4598
+ return async (classification, profile) => {
4584
4599
  const category = classification ? findCategoryByTag(categories, classification.category) : null;
4585
- return draftPromptRefFor(await resolveDraftAgent(api, category?.agentId ?? null), config);
4600
+ return bindDraftAgent(profile, await resolveDraftAgent(api, category?.agentId ?? null), config);
4586
4601
  };
4587
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
+ }
4588
4619
  function buildPromptsTable(config, draft2, nodes) {
4589
4620
  const prompts = config.defaults?.prompts;
4590
4621
  return {
@@ -4690,7 +4721,7 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
4690
4721
  const agentRecord2 = data.agentId ? await getOptional(ctx.api, "agent", data.agentId) : null;
4691
4722
  const agent = agentRecord2 ? toAgent(agentRecord2) : await resolveDraftAgent(ctx.api, null);
4692
4723
  const profile = applyFollowupSendPolicy(
4693
- settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes)),
4724
+ withAgentModel(settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes)), agent),
4694
4725
  origin
4695
4726
  );
4696
4727
  const testRun = options.testRun === true;
@@ -4702,7 +4733,7 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
4702
4733
  metadata: {
4703
4734
  ticket_id: ticketId,
4704
4735
  ...typeof decisionTicketUrl === "string" && decisionTicketUrl !== "" ? { conversation_url: decisionTicketUrl } : {},
4705
- ...agent ? { model: agent.name, model_id: agent.modelId } : {},
4736
+ ...agent ? { model: agent.name } : {},
4706
4737
  ...category ? { category: category.tagName } : {},
4707
4738
  origin
4708
4739
  }
@@ -5446,6 +5477,7 @@ var CREATE_AGENT_INPUT_PROVIDER_UID = "0dd94db4-f31a-4cd2-b030-1b1a4da5b43e";
5446
5477
  var CREATE_AGENT_INPUT_SYSTEM_PROMPT_SNAPSHOT_UID = "d50f3810-b6fe-4c90-b69b-3e36ba502cdb";
5447
5478
  var CREATE_AGENT_INPUT_PROMPT_NAME_UID = "102d412a-3299-42a2-ac62-6f7c4155508d";
5448
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";
5449
5481
  var SET_DEFAULT_AGENT_INPUT_AGENT_ID_UID = "0686c615-63f8-49a1-b3c7-3542bac76cd6";
5450
5482
  var EXT_CHAT_INPUT_MESSAGES_UID = "874e4408-74c0-4188-b923-a0791da4d096";
5451
5483
  var EXT_CHAT_INPUT_MODEL_ID_UID = "d63f05b1-165d-45e0-9300-cabe5e22fa42";
@@ -5725,8 +5757,7 @@ async function runFromTriage(deps, rebindDraft) {
5725
5757
  if (!rebindDraft) return runTicket(deps);
5726
5758
  const triaged = await runTicket(deps, { until: "triage" });
5727
5759
  if (triaged.outcome) return triaged;
5728
- const draft2 = await rebindDraft(triaged.classification);
5729
- const rebound = { ...deps, profile: { ...deps.profile, prompts: { ...deps.profile.prompts, draft: draft2 } } };
5760
+ const rebound = { ...deps, profile: await rebindDraft(triaged.classification, deps.profile) };
5730
5761
  return runTicket(rebound, { resume: { classification: triaged.classification, escalated: triaged.escalated } });
5731
5762
  }
5732
5763
  async function runGraphDryRun({ base, api, resume, rebindDraft }) {
@@ -5894,8 +5925,10 @@ async function graphDryRunHandler(ctx, config, input) {
5894
5925
  const forcedCategory = input.categoryId ? categories.find((c) => c.id === input.categoryId) ?? null : null;
5895
5926
  if (input.categoryId && !forcedCategory) throw new ctx.NonRetriableError(`Category "${input.categoryId}" not found`);
5896
5927
  const agent = input.agentId ? toAgent(await ctx.api.get("agent", input.agentId)) : await resolveDraftAgent(ctx.api, forcedCategory?.agentId ?? null);
5897
- const baseProfile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
5898
- 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);
5899
5932
  const realPorts = buildTicketPorts(ctx);
5900
5933
  const ref = { id: inlineTicket ? INLINE_TICKET_ID : ticketId, channel: "gorgias" };
5901
5934
  const budget = createBudget({ signal: AbortSignal.timeout(DRY_RUN_DEADLINE_MS), maxToolCalls: profile.nodes.draft?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS2 });
@@ -5923,7 +5956,6 @@ async function graphDryRunHandler(ctx, config, input) {
5923
5956
  // overridden unconditionally by `runGraphDryRun`
5924
5957
  };
5925
5958
  const resume = forcedCategory ? { classification: forcedClassification(forcedCategory.tagName), escalated: false } : void 0;
5926
- const rebindDraft = input.agentId || forcedCategory ? void 0 : draftRebinder(ctx.api, categories, config);
5927
5959
  return runGraphDryRun({ base, api: ctx.api, resume, ...rebindDraft ? { rebindDraft } : {} });
5928
5960
  }
5929
5961
  var DEFAULT_LIMIT = 20;
@@ -5958,8 +5990,9 @@ async function testAgentsHandler(ctx, config, input) {
5958
5990
  const limit = Math.min(input?.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
5959
5991
  const categories = await listCategories(ctx.api);
5960
5992
  const agent = input.agentId ? toAgent(await ctx.api.get("agent", input.agentId)) : await resolveDraftAgent(ctx.api, null);
5961
- const profile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
5962
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);
5963
5996
  const realPorts = buildTicketPorts(ctx);
5964
5997
  const refs = explicitIds.length ? explicitIds.slice(0, limit).map((id) => ({ id, channel: "gorgias" })) : await realPorts.conversation.listPending({ viewOrTag: viewId }, limit);
5965
5998
  const deadline = AbortSignal.timeout(DRY_RUN_DEADLINE_MS);
@@ -6407,6 +6440,13 @@ function buildCreateAgentFunctionDef(config) {
6407
6440
  type: appKit.FieldType.TEXT,
6408
6441
  label: "Prompt label",
6409
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
6410
6450
  }
6411
6451
  ]
6412
6452
  };
@@ -6425,7 +6465,8 @@ async function createAgentHandler(ctx, input) {
6425
6465
  provider: input.provider?.trim() || DEFAULT_LLM_PROVIDER,
6426
6466
  status: "available",
6427
6467
  ...input.systemPromptSnapshot?.trim() ? { systemPromptSnapshot: input.systemPromptSnapshot.trim() } : {},
6428
- ...input.promptLabel?.trim() ? { promptLabel: input.promptLabel.trim() } : {}
6468
+ ...input.promptLabel?.trim() ? { promptLabel: input.promptLabel.trim() } : {},
6469
+ ...isReasoningEffort(input.reasoningEffort) ? { reasoningEffort: input.reasoningEffort } : {}
6429
6470
  };
6430
6471
  const promptName = input.promptName?.trim();
6431
6472
  if (promptName) {
@@ -6760,11 +6801,16 @@ async function executeChat(ctx, userId, input) {
6760
6801
  input.agentName ?? null
6761
6802
  );
6762
6803
  const chatMessages = systemContent ? [{ role: "system", content: systemContent }, ...contextMessages] : contextMessages;
6804
+ const reasoningEffort = agent.reasoningEffort ?? await draftStepEffort(ctx);
6763
6805
  const result = await ctx.api.llm.complete({
6764
6806
  messages: chatMessages,
6765
6807
  // The agent's modelId stored in the OS wins; the prompt's Langfuse
6766
6808
  // config is ignored, like every graph node (`draft.ts`, `triage.ts`, …).
6767
- 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,
6768
6814
  // Link-only (D-LF follow-up, option (b)): this function already resolved
6769
6815
  // its own prompt two lines above via `PromptPort` — `resolve: false`
6770
6816
  // links the completion to it in Langfuse WITHOUT re-triggering the
@@ -6862,6 +6908,15 @@ function toWireChatMessage(raw) {
6862
6908
  }
6863
6909
  return { role, content: typeof raw.content === "string" ? raw.content : "" };
6864
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
+ }
6865
6920
  async function resolveAgent(ctx, modelId) {
6866
6921
  if (modelId) {
6867
6922
  const record2 = await getOptional(ctx.api, "agent", modelId);