@apotech-os/support-kit 2.10.0 → 3.0.1

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
@@ -863,14 +863,14 @@ ${trimmed}` : null;
863
863
 
864
864
  // src/graph/revise.ts
865
865
  async function reviseDraft(params) {
866
- const { profile, llm, budget, draft: draft2, verdict, messages, label, model, promptRef } = params;
866
+ const { profile, llm, budget, draft: draft2, verdict, messages, label, promptRef } = params;
867
867
  const node = profile.nodes.revise;
868
868
  if (!node) return draft2;
869
869
  let result;
870
870
  try {
871
871
  result = await llm.complete({
872
872
  label,
873
- model: model ?? node.model,
873
+ model: node.model,
874
874
  reasoning: node.reasoning,
875
875
  messages: [...messages, ...buildRevisionTurn(draft2, verdict)],
876
876
  tools: [],
@@ -910,7 +910,6 @@ var revise = async (state, deps) => {
910
910
  if (!node || !state.conversation || !state.draft || !state.verdict) return {};
911
911
  const draftPrompt = await deps.ports.prompt.resolve(profile.prompts.draft);
912
912
  const messages = buildDraftMessages(state.conversation, writerSystemPrompt(draftPrompt.text, state.conversation));
913
- const revisePrompt = await deps.ports.prompt.resolve(profile.prompts.revise);
914
913
  const revised = await reviseDraft({
915
914
  profile,
916
915
  llm: deps.ports.llm,
@@ -919,8 +918,7 @@ var revise = async (state, deps) => {
919
918
  verdict: state.verdict,
920
919
  messages,
921
920
  label: "revise",
922
- model: revisePrompt.config?.model ?? node.model,
923
- promptRef: { name: revisePrompt.name, version: revisePrompt.version, resolve: false }
921
+ promptRef: { name: draftPrompt.name, version: draftPrompt.version, resolve: false }
924
922
  });
925
923
  return { draft: revised, reviseCount: 1 };
926
924
  };
@@ -1286,9 +1284,6 @@ var PROMPT_SLOTS = [
1286
1284
  function resolvePromptName(slot, config) {
1287
1285
  return config.promptNames?.[slot] ?? `${config.promptPrefix}${slot}`;
1288
1286
  }
1289
- function resolveReviseName(config) {
1290
- return config.promptNames?.revise ?? `${config.promptPrefix}revise`;
1291
- }
1292
1287
 
1293
1288
  // src/records/ids.ts
1294
1289
  var CATEGORY_OBJECT_UID = "8a1c8de3-c288-40a5-9294-a883e1c89784";
@@ -2543,7 +2538,7 @@ function validateSettings(settings) {
2543
2538
  function isNonEmptyString(value) {
2544
2539
  return typeof value === "string" && value.length > 0;
2545
2540
  }
2546
- var STEPS_REQUIRING_PROMPT = ["triage", "escalate", "evaluate", "revise"];
2541
+ var STEPS_REQUIRING_PROMPT = ["triage", "escalate", "evaluate"];
2547
2542
  function stepsMissingPrompt(nodes) {
2548
2543
  if (typeof nodes !== "object" || nodes === null) return [];
2549
2544
  const byStep = nodes;
@@ -3163,6 +3158,12 @@ function draftPromptRefFor(agent, config) {
3163
3158
  ...agent.systemPromptSnapshot ? { fallback: agent.systemPromptSnapshot } : {}
3164
3159
  };
3165
3160
  }
3161
+ function draftRebinder(api, categories, config) {
3162
+ return async (classification) => {
3163
+ const category = classification ? findCategoryByTag(categories, classification.category) : null;
3164
+ return draftPromptRefFor(await resolveDraftAgent(api, category?.agentId ?? null), config);
3165
+ };
3166
+ }
3166
3167
  function buildPromptsTable(config, draft2, nodes) {
3167
3168
  const DEFAULT_LABEL = "production";
3168
3169
  const refFor = (node, derivedName, fallback2) => ({
@@ -3175,7 +3176,6 @@ function buildPromptsTable(config, draft2, nodes) {
3175
3176
  triage: refFor(nodes.triage, resolvePromptName("triage", config), prompts?.triage),
3176
3177
  escalate: refFor(nodes.escalate, resolvePromptName("escalation", config), prompts?.escalation),
3177
3178
  evaluate: refFor(nodes.evaluate, resolvePromptName("evaluation", config), prompts?.evaluation),
3178
- revise: refFor(nodes.revise, resolveReviseName(config), prompts?.revise),
3179
3179
  draft: draft2
3180
3180
  };
3181
3181
  }
@@ -4030,7 +4030,15 @@ async function previewTriageHandler(ctx, config, input) {
4030
4030
 
4031
4031
  // src/functions/graph-dry-run-core.ts
4032
4032
  var DRY_RUN_DEADLINE_MS = 3 * 60 * 1e3;
4033
- async function runGraphDryRun({ base, api, resume }) {
4033
+ async function runFromTriage(deps, rebindDraft) {
4034
+ if (!rebindDraft) return runTicket(deps);
4035
+ const triaged = await runTicket(deps, { until: "triage" });
4036
+ if (triaged.outcome) return triaged;
4037
+ const draft2 = await rebindDraft(triaged.classification);
4038
+ const rebound = { ...deps, profile: { ...deps.profile, prompts: { ...deps.profile.prompts, draft: draft2 } } };
4039
+ return runTicket(rebound, { resume: { classification: triaged.classification, escalated: triaged.escalated } });
4040
+ }
4041
+ async function runGraphDryRun({ base, api, resume, rebindDraft }) {
4034
4042
  const recordingReply = createRecordingReplyPort();
4035
4043
  const recordingState = createRecordingStatePort(api);
4036
4044
  const recordingSend = createRecordingSendPort();
@@ -4052,7 +4060,7 @@ async function runGraphDryRun({ base, api, resume }) {
4052
4060
  let result = null;
4053
4061
  let error;
4054
4062
  try {
4055
- result = await runTicket(deps, resume ? { resume } : void 0);
4063
+ result = resume ? await runTicket(deps, { resume }) : await runFromTriage(deps, rebindDraft);
4056
4064
  } catch (err) {
4057
4065
  error = err instanceof Error ? err.message : String(err);
4058
4066
  }
@@ -4220,7 +4228,8 @@ async function graphDryRunHandler(ctx, config, input) {
4220
4228
  // overridden unconditionally by `runGraphDryRun`
4221
4229
  };
4222
4230
  const resume = forcedCategory ? { classification: forcedClassification(forcedCategory.tagName), escalated: false } : void 0;
4223
- return runGraphDryRun({ base, api: ctx.api, resume });
4231
+ const rebindDraft = input.agentId || forcedCategory ? void 0 : draftRebinder(ctx.api, categories, config);
4232
+ return runGraphDryRun({ base, api: ctx.api, resume, ...rebindDraft ? { rebindDraft } : {} });
4224
4233
  }
4225
4234
  var DEFAULT_LIMIT = 20;
4226
4235
  var MAX_LIMIT = 100;
@@ -4255,6 +4264,7 @@ async function testAgentsHandler(ctx, config, input) {
4255
4264
  const categories = await listCategories(ctx.api);
4256
4265
  const agent = input.agentId ? toAgent(await ctx.api.get("agent", input.agentId)) : await resolveDraftAgent(ctx.api, null);
4257
4266
  const profile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes));
4267
+ const rebindDraft = input.agentId ? void 0 : draftRebinder(ctx.api, categories, config);
4258
4268
  const realPorts = buildTicketPorts(ctx);
4259
4269
  const refs = explicitIds.length ? explicitIds.slice(0, limit).map((id) => ({ id, channel: "gorgias" })) : await realPorts.conversation.listPending({ viewOrTag: viewId }, limit);
4260
4270
  const deadline = AbortSignal.timeout(DRY_RUN_DEADLINE_MS);
@@ -4281,7 +4291,7 @@ async function testAgentsHandler(ctx, config, input) {
4281
4291
  send: { mode: "none" }
4282
4292
  // overridden unconditionally by `runGraphDryRun`
4283
4293
  };
4284
- results.push(await runGraphDryRun({ base, api: ctx.api }));
4294
+ results.push(await runGraphDryRun({ base, api: ctx.api, ...rebindDraft ? { rebindDraft } : {} }));
4285
4295
  }
4286
4296
  return { results, autoReplyForced: true };
4287
4297
  }
@@ -5818,7 +5828,6 @@ exports.promptCacheRecord = promptCacheRecord;
5818
5828
  exports.reclaimStalledSend = reclaimStalledSend;
5819
5829
  exports.requiresFollowup = requiresFollowup;
5820
5830
  exports.resolvePromptName = resolvePromptName;
5821
- exports.resolveReviseName = resolveReviseName;
5822
5831
  exports.runGuardrails = runGuardrails;
5823
5832
  exports.runTicket = runTicket;
5824
5833
  exports.settingsToProfile = settingsToProfile;