@apotech-os/support-kit 6.2.0 → 6.3.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
@@ -29,6 +29,28 @@ function requiresFollowup(verdict) {
29
29
  }
30
30
 
31
31
  // src/graph/state.ts
32
+ var OUTCOMES = [
33
+ "sent",
34
+ // reply posted to the customer
35
+ "ready",
36
+ // servable to the extension, NO tag (nominal path)
37
+ "needs_human",
38
+ // unsendable verdict → ready + needs-review tag
39
+ "guardrail_hold",
40
+ // a guardrail fired → ready + escalation tag
41
+ "awaiting_approval",
42
+ // an action awaits human sign-off (P3)
43
+ "escalated",
44
+ // escalated upstream, no generation happened
45
+ "triaged_only",
46
+ // tenant/ticket has no draft step to run
47
+ "no_reply_needed",
48
+ // triage read the thread as already closed → NO tag, like 'ready' (whatsapp spec §5.2)
49
+ "failed"
50
+ ];
51
+ function isOutcome(value) {
52
+ return typeof value === "string" && OUTCOMES.includes(value);
53
+ }
32
54
  function initialState() {
33
55
  return {
34
56
  conversation: null,
@@ -1017,13 +1039,16 @@ async function step(name, node, state, deps) {
1017
1039
  throw err;
1018
1040
  }
1019
1041
  }
1042
+ function outcomeTags(outcome2, verdict, audit) {
1043
+ if (outcome2 === "needs_human") return [audit.needsHumanTag];
1044
+ if (outcome2 === "guardrail_hold") return [audit.escalationTag];
1045
+ if (outcome2 !== "sent") return [];
1046
+ return requiresFollowup(verdict?.verdict ?? null) ? [audit.sentTag, audit.followupTag] : [audit.sentTag];
1047
+ }
1020
1048
  async function applyOutcomeTags(outcome2, verdict, deps) {
1021
1049
  const { ports, ref, audit } = deps;
1022
- if (outcome2 === "needs_human") await ports.state.flag(ref, audit.needsHumanTag);
1023
- if (outcome2 === "guardrail_hold") await ports.state.flag(ref, audit.escalationTag);
1024
- if (outcome2 === "sent") {
1025
- await ports.state.flag(ref, audit.sentTag);
1026
- if (requiresFollowup(verdict?.verdict ?? null)) await ports.state.flag(ref, audit.followupTag);
1050
+ for (const tag of outcomeTags(outcome2, verdict, audit)) {
1051
+ await ports.state.flag(ref, tag);
1027
1052
  }
1028
1053
  }
1029
1054
  async function finish2(state, deps, outcome2) {
@@ -1385,6 +1410,7 @@ var GENERATED_RESPONSE_FIELD_ERROR_UID = "40994b59-75f0-4c84-8a8a-a8d3c6cc2b09";
1385
1410
  var GENERATED_RESPONSE_FIELD_GENERATED_MESSAGE_COUNT_UID = "33a282d3-7a1c-45a3-945e-a39ea459c5f8";
1386
1411
  var GENERATED_RESPONSE_FIELD_GENERATED_LAST_MESSAGE_AT_UID = "94c4594f-4ad0-4e3b-8a0b-76402b437434";
1387
1412
  var GENERATED_RESPONSE_FIELD_SENDING_AT_UID = "2ae9634b-79bb-42d2-a949-8b0f1ac9c763";
1413
+ var GENERATED_RESPONSE_FIELD_OUTCOME_UID = "8834b334-8f91-46f7-9bb9-96b69092d0ae";
1388
1414
  var GENERATED_RESPONSE_INDEX_TICKET_ID_UID = "a4534d26-8f43-4510-9c03-0b28c3d3f8e2";
1389
1415
  var GENERATED_RESPONSE_INDEX_OPEN_TICKET_KEY_UID = "3d430166-07a2-43c2-911b-89ec25d13f64";
1390
1416
  var GENERATED_RESPONSE_INDEX_STATUS_UID = "f5c4e5d4-0810-424d-8a14-617e9555a7f3";
@@ -1918,6 +1944,15 @@ function buildGeneratedResponseRecord(slug) {
1918
1944
  isNullable: false,
1919
1945
  defaultValue: []
1920
1946
  },
1947
+ {
1948
+ universalIdentifier: GENERATED_RESPONSE_FIELD_OUTCOME_UID,
1949
+ name: "outcome",
1950
+ type: appKit.FieldType.SELECT,
1951
+ label: "Outcome",
1952
+ description: "Which exit runTicket took. Nullable: rows written before 21/09/2026 carry none, and inventing one would be a stored lie.",
1953
+ isNullable: true,
1954
+ options: [...OUTCOMES]
1955
+ },
1921
1956
  {
1922
1957
  universalIdentifier: GENERATED_RESPONSE_FIELD_AUTO_SEND_DECISION_UID,
1923
1958
  name: "autoSendDecision",
@@ -2584,6 +2619,16 @@ function isConfiguredNode(nodes) {
2584
2619
  // src/settings/to-profile.ts
2585
2620
  var DEFAULT_REASONING = "off";
2586
2621
  var DEFAULT_MAX_TOOL_CALLS = 5;
2622
+ function toAuditTags(settings) {
2623
+ return {
2624
+ unknownTag: settings.unknownTag,
2625
+ handledTag: settings.handledTag,
2626
+ escalationTag: settings.escalationTag,
2627
+ sentTag: settings.autoRepliedTag,
2628
+ needsHumanTag: settings.needsReviewTag,
2629
+ followupTag: settings.followupTag
2630
+ };
2631
+ }
2587
2632
  var DEFAULT_MIN_CONFIDENCE = 0.8;
2588
2633
  var DEFAULT_ESCALATION_ENABLED = false;
2589
2634
  var JUDGEME_ESCALATE_ONLY = true;
@@ -2642,14 +2687,7 @@ function settingsToProfile(settings, prompts) {
2642
2687
  // belongs to P3's per-role policy, which needs a runtime context this
2643
2688
  // pure mapper does not have.
2644
2689
  authorization: { send_reply: settings.autoSendEnabled ? "auto" : "needs_approval" },
2645
- audit: {
2646
- unknownTag: settings.unknownTag,
2647
- handledTag: settings.handledTag,
2648
- escalationTag: settings.escalationTag,
2649
- sentTag: settings.autoRepliedTag,
2650
- needsHumanTag: settings.needsReviewTag,
2651
- followupTag: settings.followupTag
2652
- },
2690
+ audit: toAuditTags(settings),
2653
2691
  autoSend: {
2654
2692
  enabled: settings.autoSendEnabled,
2655
2693
  senderEmail: settings.senderEmail === "" ? null : settings.senderEmail,
@@ -3116,6 +3154,11 @@ function buildSendSeam(params) {
3116
3154
  id,
3117
3155
  {
3118
3156
  status: "sent",
3157
+ // The ONE place a reply becomes sent, whichever caller got it here
3158
+ // (`act` through `process-response`, or `handle-approval`'s direct
3159
+ // send) — so stamping the outcome here covers both without either
3160
+ // needing to remember to.
3161
+ outcome: "sent",
3119
3162
  sentAt: clock.now(),
3120
3163
  sentMessageId: messageId,
3121
3164
  openTicketKey: openTicketKeyFor("sent", ticketId)
@@ -3222,6 +3265,7 @@ function toGeneratedResponse(record) {
3222
3265
  sources: Array.isArray(data.sources) ? data.sources : [],
3223
3266
  verdict: toVerdict(data.verdict),
3224
3267
  guardrailHits: data.guardrailHits ?? [],
3268
+ outcome: isOutcome(data.outcome) ? data.outcome : null,
3225
3269
  triageDecisionId: data.triageDecisionId ?? null,
3226
3270
  channel: data.channel ?? null,
3227
3271
  autoSendDecision: data.autoSendDecision ?? null,
@@ -3393,6 +3437,13 @@ async function respondToPendingResponse(ctx, config, recordId) {
3393
3437
  { resume: { classification, escalated } }
3394
3438
  );
3395
3439
  const draftExtra = {
3440
+ // Stamped once for every branch of the switch below rather than per
3441
+ // case: `status` cannot carry it (four of these outcomes all persist as
3442
+ // `ready`), and a per-case literal is a list that drifts the first time
3443
+ // a case is added. A dry run records the outcome the graph REACHED —
3444
+ // `outcome: 'sent'` on a `ready` row is exactly what "would have been
3445
+ // sent, wasn't" looks like, and the timeline reads it that way.
3446
+ outcome: result.outcome,
3396
3447
  responseText: result.draft?.text ?? null,
3397
3448
  sources: result.draft?.sources ?? [],
3398
3449
  // The rendered system prompt and the customer's own turns, which nothing
@@ -5976,6 +6027,7 @@ exports.GENERATED_RESPONSE_STATUSES = GENERATED_RESPONSE_STATUSES;
5976
6027
  exports.InvalidStatusTransitionError = InvalidStatusTransitionError;
5977
6028
  exports.MissingPromptError = MissingPromptError;
5978
6029
  exports.NODE_NAMES = NODE_NAMES;
6030
+ exports.OUTCOMES = OUTCOMES;
5979
6031
  exports.PROMPT_SLOTS = PROMPT_SLOTS;
5980
6032
  exports.REASONING_MAX_LEN = REASONING_MAX_LEN;
5981
6033
  exports.STOP_PHRASES = STOP_PHRASES;
@@ -6011,6 +6063,7 @@ exports.isEvaluationVerdict = isEvaluationVerdict;
6011
6063
  exports.isGeneratedResponseStatus = isGeneratedResponseStatus;
6012
6064
  exports.isJudgemeConversation = isJudgemeConversation;
6013
6065
  exports.isJudgemeTicket = isJudgemeTicket;
6066
+ exports.isOutcome = isOutcome;
6014
6067
  exports.isSendable = isSendable;
6015
6068
  exports.isSendableVerdict = isSendableVerdict;
6016
6069
  exports.isTerminalStatus = isTerminalStatus;