@apotech-os/support-kit 3.0.1 → 3.1.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
@@ -1338,6 +1338,7 @@ var TRIAGE_DECISION_FIELD_STATUS_UID = "7583d228-4449-40ef-9e7e-44e34897e020";
1338
1338
  var TRIAGE_DECISION_FIELD_ERROR_UID = "b271362b-a1b3-4110-a197-0b7a2ec6b152";
1339
1339
  var TRIAGE_DECISION_FIELD_RUN_ID_UID = "a1e244d6-8f4f-4cd5-8794-14f6e419b64e";
1340
1340
  var TRIAGE_DECISION_FIELD_SUBJECT_RENAMED_UID = "449f1960-be88-4e42-96ee-43cd90f36f4c";
1341
+ var TRIAGE_DECISION_FIELD_TICKET_URL_UID = "727a775a-ea93-460f-9d08-16b05424c453";
1341
1342
  var TRIAGE_DECISION_INDEX_TICKET_ID_UID = "20433066-e029-4faf-8033-c205cf5de0fb";
1342
1343
  var TRIAGE_DECISION_INDEX_DECIDED_AT_UID = "94040f6d-1d55-498f-8db8-abe5aed17c0a";
1343
1344
  var TRIAGE_DECISION_INDEX_ESCALATED_UID = "1c0ac4c3-9a48-4858-bbbf-0c689bbb5be5";
@@ -1663,6 +1664,14 @@ function buildTriageDecisionRecord(slug) {
1663
1664
  label: "Ticket id",
1664
1665
  isNullable: false
1665
1666
  },
1667
+ {
1668
+ universalIdentifier: TRIAGE_DECISION_FIELD_TICKET_URL_UID,
1669
+ name: "ticketUrl",
1670
+ type: appKit.FieldType.TEXT,
1671
+ label: "Ticket url",
1672
+ description: "Deep link to the ticket in the helpdesk, resolved once per batch and frozen on the decision. Null on a decision written before this field existed, or when the connection exposes no public url (mock).",
1673
+ isNullable: true
1674
+ },
1666
1675
  {
1667
1676
  universalIdentifier: TRIAGE_DECISION_FIELD_DECIDED_AT_UID,
1668
1677
  name: "decidedAt",
@@ -2439,12 +2448,11 @@ var SUPPORT_KIT_SETTINGS_FIELDS = [
2439
2448
  // `validateSettings` refuses to run until `nodes.triage` is configured.
2440
2449
  { key: "nodes", type: "json", label: "Graph node overrides" },
2441
2450
  // Audit tags
2442
- { key: "unknownTag", type: "string", label: "Unknown tag", default: "wai-tag/unknown" },
2443
- { key: "handledTag", type: "string", label: "Handled tag", default: "wai-tag/triaged" },
2444
- { key: "escalationTag", type: "string", label: "Escalation tag", default: "wai/human-required" },
2445
- { key: "needsHumanTag", type: "string", label: "Needs-human tag", default: "wai/needs-human" },
2451
+ { key: "unknownTag", type: "string", label: "Unknown tag", default: "wai/unknown" },
2452
+ { key: "handledTag", type: "string", label: "Handled tag", default: "wai/triaged" },
2453
+ { key: "escalationTag", type: "string", label: "Escalation tag", default: "wai/escalated" },
2446
2454
  { key: "autoRepliedTag", type: "string", label: "Auto-replied tag", default: "wai/auto-replied" },
2447
- { key: "needsReviewTag", type: "string", label: "Needs-review tag", default: "wai/needs-review" },
2455
+ { key: "needsReviewTag", type: "string", label: "Review-before-send tag", default: "wai/escalated" },
2448
2456
  { key: "followupTag", type: "string", label: "Followup tag", default: "wai/followup-required" },
2449
2457
  // Sending
2450
2458
  { key: "autoSendEnabled", type: "boolean", label: "Auto-send enabled", default: false },
@@ -3042,9 +3050,26 @@ async function readPipelineState(api) {
3042
3050
  return page.items[0] ?? null;
3043
3051
  }
3044
3052
  async function upsertPipelineState(api, patch) {
3045
- await api.upsert("pipeline-state", [{ data: { singletonKey: PIPELINE_STATE_SINGLETON_KEY, ...patch } }], {
3046
- uniqueBy: ["singletonKey"]
3047
- });
3053
+ const current = await readPipelineState(api);
3054
+ if (current) {
3055
+ await api.update("pipeline-state", current.id, patch);
3056
+ return;
3057
+ }
3058
+ await api.upsert(
3059
+ "pipeline-state",
3060
+ [
3061
+ {
3062
+ data: {
3063
+ singletonKey: PIPELINE_STATE_SINGLETON_KEY,
3064
+ sourceViewId: null,
3065
+ lastTriageAt: null,
3066
+ lastSweepAt: null,
3067
+ ...patch
3068
+ }
3069
+ }
3070
+ ],
3071
+ { uniqueBy: ["singletonKey"] }
3072
+ );
3048
3073
  }
3049
3074
 
3050
3075
  // src/functions/records.ts
@@ -3222,12 +3247,34 @@ async function triageTickHandler(ctx, config) {
3222
3247
  }
3223
3248
  await runTriageBatch(ctx, config, settings);
3224
3249
  }
3250
+ async function resolveTicketUrlBase(ctx) {
3251
+ try {
3252
+ const connections = await ctx.api.integrations.list("gorgias");
3253
+ const connection = connections.find((candidate) => candidate.isDefault) ?? connections[0];
3254
+ const result = await ctx.api.integrations.run(
3255
+ "gorgias",
3256
+ "getTicketUrlBase",
3257
+ {},
3258
+ connection ? { connectionId: connection.id } : void 0
3259
+ );
3260
+ return typeof result?.base === "string" && result.base !== "" ? result.base : null;
3261
+ } catch (err) {
3262
+ ctx.logger.warn("triage-tick: could not resolve the Gorgias ticket url base, decisions will carry no deep link", {
3263
+ error: err instanceof Error ? err.message : String(err)
3264
+ });
3265
+ return null;
3266
+ }
3267
+ }
3268
+ function ticketUrlFor(base, ticketId) {
3269
+ return base ? `${base}/${encodeURIComponent(ticketId)}` : null;
3270
+ }
3225
3271
  async function runTriageBatch(ctx, config, settings) {
3226
3272
  const dryRun = settings.dryRun === true;
3227
3273
  const ports = dryRun ? withRecordingWritePorts(buildTicketPorts(ctx), ctx.api) : buildTicketPorts(ctx);
3228
3274
  const categories = await listCategories(ctx.api);
3229
3275
  const batchDefaultAgent = await resolveDraftAgent(ctx.api, null);
3230
3276
  const profile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(batchDefaultAgent, config), settings.nodes));
3277
+ const ticketUrlBase = await resolveTicketUrlBase(ctx);
3231
3278
  const refs = await ports.conversation.listPending({ viewOrTag: settings.sourceViewId }, settings.batchLimit);
3232
3279
  const run = await ctx.api.runs.start({
3233
3280
  kind: "triage-tick",
@@ -3242,7 +3289,8 @@ async function runTriageBatch(ctx, config, settings) {
3242
3289
  profile,
3243
3290
  categories,
3244
3291
  ports,
3245
- runId: run.id
3292
+ runId: run.id,
3293
+ ticketUrlBase
3246
3294
  });
3247
3295
  } catch (err) {
3248
3296
  failureCount += 1;
@@ -3251,6 +3299,7 @@ async function runTriageBatch(ctx, config, settings) {
3251
3299
  try {
3252
3300
  await ctx.api.create("triage-decision", {
3253
3301
  ticketId: ref.id,
3302
+ ticketUrl: ticketUrlFor(ticketUrlBase, ref.id),
3254
3303
  decidedAt: ports.clock.now(),
3255
3304
  status: "error",
3256
3305
  error: message,
@@ -3275,7 +3324,7 @@ async function runTriageBatch(ctx, config, settings) {
3275
3324
  return { ticketCount: refs.length, failureCount };
3276
3325
  }
3277
3326
  async function processOneTicket(ctx, ref, deps) {
3278
- const { profile, categories, ports, runId } = deps;
3327
+ const { profile, categories, ports, runId, ticketUrlBase } = deps;
3279
3328
  let subjectRenamed = false;
3280
3329
  if (profile.rename) {
3281
3330
  const conversation2 = await ports.conversation.read(ref);
@@ -3306,6 +3355,7 @@ async function processOneTicket(ctx, ref, deps) {
3306
3355
  if (!state.classification) {
3307
3356
  await ctx.api.create("triage-decision", {
3308
3357
  ticketId: ref.id,
3358
+ ticketUrl: ticketUrlFor(ticketUrlBase, ref.id),
3309
3359
  decidedAt: ports.clock.now(),
3310
3360
  status: "error",
3311
3361
  error: "triage produced no classification",
@@ -3319,6 +3369,7 @@ async function processOneTicket(ctx, ref, deps) {
3319
3369
  const category = findCategoryByTag(categories, classification.category);
3320
3370
  const decision = await ctx.api.create("triage-decision", {
3321
3371
  ticketId: ref.id,
3372
+ ticketUrl: ticketUrlFor(ticketUrlBase, ref.id),
3322
3373
  decidedAt: ports.clock.now(),
3323
3374
  categoryId: category?.id ?? null,
3324
3375
  tag: classification.category,
@@ -5612,13 +5663,20 @@ var SUPPORT_KIT_GORGIAS_ACTIONS = [
5612
5663
  "buildTicketContext",
5613
5664
  "fetchTicketsFromView",
5614
5665
  "getRawTicket",
5666
+ "getTicketUrlBase",
5615
5667
  "getTicketWithContext",
5616
5668
  "listViews",
5617
5669
  "postWhatsappNote",
5618
5670
  "renameTicket",
5619
5671
  "replyEmail"
5620
5672
  ];
5621
- var SUPPORT_KIT_CAPABILITIES = ["runs", "inbox", "approvals", "prompts", "langfuse"];
5673
+ var SUPPORT_KIT_CAPABILITIES = [
5674
+ "runs",
5675
+ "inbox",
5676
+ "approvals",
5677
+ "prompts",
5678
+ "langfuse"
5679
+ ];
5622
5680
  var SUPPORT_KIT_ACTIONS = [
5623
5681
  ...SUPPORT_KIT_GORGIAS_ACTIONS.map((action) => ({ provider: "gorgias", action })),
5624
5682
  { provider: "llm", action: "complete" }
@@ -5626,18 +5684,58 @@ var SUPPORT_KIT_ACTIONS = [
5626
5684
  var SUPPORT_KIT_EMITS = [TRIAGE_RUN_REQUESTED_EVENT];
5627
5685
  var FUNCTION_ASSEMBLY = [
5628
5686
  { key: "triage-tick", build: buildTriageTickFunctionDef, createHandler: createTriageTickHandler },
5629
- { key: "process-response", build: buildProcessResponseFunctionDef, createHandler: createProcessResponseHandler },
5687
+ {
5688
+ key: "process-response",
5689
+ build: buildProcessResponseFunctionDef,
5690
+ createHandler: createProcessResponseHandler
5691
+ },
5630
5692
  { key: "sweep", build: buildSweepFunctionDef, createHandler: () => createSweepHandler() },
5631
- { key: "handle-approval", build: buildHandleApprovalFunctionDef, createHandler: createHandleApprovalHandler },
5632
- { key: "run-triage-now", build: buildRunTriageNowFunctionDef, createHandler: createRunTriageNowHandler },
5633
- { key: "run-triage-batch", build: buildRunTriageBatchFunctionDef, createHandler: createRunTriageBatchHandler },
5634
- { key: "preview-triage", build: buildPreviewTriageFunctionDef, createHandler: createPreviewTriageHandler },
5635
- { key: "graph-dry-run", build: buildGraphDryRunFunctionDef, createHandler: createGraphDryRunHandler },
5693
+ {
5694
+ key: "handle-approval",
5695
+ build: buildHandleApprovalFunctionDef,
5696
+ createHandler: createHandleApprovalHandler
5697
+ },
5698
+ {
5699
+ key: "run-triage-now",
5700
+ build: buildRunTriageNowFunctionDef,
5701
+ createHandler: createRunTriageNowHandler
5702
+ },
5703
+ {
5704
+ key: "run-triage-batch",
5705
+ build: buildRunTriageBatchFunctionDef,
5706
+ createHandler: createRunTriageBatchHandler
5707
+ },
5708
+ {
5709
+ key: "preview-triage",
5710
+ build: buildPreviewTriageFunctionDef,
5711
+ createHandler: createPreviewTriageHandler
5712
+ },
5713
+ {
5714
+ key: "graph-dry-run",
5715
+ build: buildGraphDryRunFunctionDef,
5716
+ createHandler: createGraphDryRunHandler
5717
+ },
5636
5718
  { key: "test-agents", build: buildTestAgentsFunctionDef, createHandler: createTestAgentsHandler },
5637
- { key: "suggest-prompt", build: buildSuggestPromptFunctionDef, createHandler: createSuggestPromptHandler },
5638
- { key: "run-diff-analysis", build: buildRunDiffAnalysisFunctionDef, createHandler: createRunDiffAnalysisHandler },
5639
- { key: "list-gorgias-views", build: buildListGorgiasViewsFunctionDef, createHandler: createListGorgiasViewsHandler },
5640
- { key: "create-agent", build: buildCreateAgentFunctionDef, createHandler: () => createCreateAgentHandler() },
5719
+ {
5720
+ key: "suggest-prompt",
5721
+ build: buildSuggestPromptFunctionDef,
5722
+ createHandler: createSuggestPromptHandler
5723
+ },
5724
+ {
5725
+ key: "run-diff-analysis",
5726
+ build: buildRunDiffAnalysisFunctionDef,
5727
+ createHandler: createRunDiffAnalysisHandler
5728
+ },
5729
+ {
5730
+ key: "list-gorgias-views",
5731
+ build: buildListGorgiasViewsFunctionDef,
5732
+ createHandler: createListGorgiasViewsHandler
5733
+ },
5734
+ {
5735
+ key: "create-agent",
5736
+ build: buildCreateAgentFunctionDef,
5737
+ createHandler: () => createCreateAgentHandler()
5738
+ },
5641
5739
  {
5642
5740
  key: "set-default-agent",
5643
5741
  build: buildSetDefaultAgentFunctionDef,
@@ -5653,15 +5751,27 @@ var FUNCTION_ASSEMBLY = [
5653
5751
  build: buildSyncAgentPromptSnapshotFunctionDef,
5654
5752
  createHandler: () => createSyncAgentPromptSnapshotHandler()
5655
5753
  },
5656
- { key: "ext-models", build: buildExtModelsFunctionDef, createHandler: () => createExtModelsHandler() },
5657
- { key: "ext-categories", build: buildExtCategoriesFunctionDef, createHandler: () => createExtCategoriesHandler() },
5754
+ {
5755
+ key: "ext-models",
5756
+ build: buildExtModelsFunctionDef,
5757
+ createHandler: () => createExtModelsHandler()
5758
+ },
5759
+ {
5760
+ key: "ext-categories",
5761
+ build: buildExtCategoriesFunctionDef,
5762
+ createHandler: () => createExtCategoriesHandler()
5763
+ },
5658
5764
  { key: "ext-chat", build: buildExtChatFunctionDef, createHandler: () => createExtChatHandler() },
5659
5765
  {
5660
5766
  key: "ext-fast-response-check",
5661
5767
  build: buildExtFastResponseCheckFunctionDef,
5662
5768
  createHandler: () => createExtFastResponseCheckHandler()
5663
5769
  },
5664
- { key: "ext-evaluation", build: buildExtEvaluationFunctionDef, createHandler: () => createExtEvaluationHandler() },
5770
+ {
5771
+ key: "ext-evaluation",
5772
+ build: buildExtEvaluationFunctionDef,
5773
+ createHandler: () => createExtEvaluationHandler()
5774
+ },
5665
5775
  {
5666
5776
  key: "ext-response-comparison",
5667
5777
  build: buildExtResponseComparisonFunctionDef,
@@ -5705,8 +5815,14 @@ var KIT_PAGES = [
5705
5815
  { key: "escalations-page", path: "escalations", title: "Escalades", icon: "alert-triangle" },
5706
5816
  { key: "corrections-page", path: "corrections", title: "Corrections", icon: "git-compare" },
5707
5817
  { key: "graph-canvas-page", path: "graph-canvas", title: "Graphe", icon: "workflow" },
5708
- { key: "shared-prompts-page", path: "shared-prompts", title: "Prompts partag\xE9s", icon: "library" },
5709
- { key: "test-page", path: "test", title: "Banc de test", icon: "flask-conical" }
5818
+ {
5819
+ key: "shared-prompts-page",
5820
+ path: "shared-prompts",
5821
+ title: "Prompts partag\xE9s",
5822
+ icon: "library"
5823
+ },
5824
+ { key: "test-page", path: "test", title: "Banc de test", icon: "flask-conical" },
5825
+ { key: "quality-page", path: "quality", title: "Qualit\xE9", icon: "flask-conical" }
5710
5826
  ];
5711
5827
  function buildPages(config) {
5712
5828
  return KIT_PAGES.map(({ key, path, title, icon }) => ({