@apotech-os/support-kit 8.0.0 → 8.2.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/{chunk-2UHFKGMI.js → chunk-LXHPPWPM.js} +20 -6
- package/dist/chunk-LXHPPWPM.js.map +1 -0
- package/dist/index.cjs +146 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +131 -62
- package/dist/index.js.map +1 -1
- package/dist/ui/index.cjs +299 -52
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.js +286 -52
- package/dist/ui/index.js.map +1 -1
- package/package.json +11 -11
- package/dist/chunk-2UHFKGMI.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1128,20 +1128,33 @@ var GENERATED_RESPONSE_STATUSES = [
|
|
|
1128
1128
|
"failed",
|
|
1129
1129
|
"no_reply_needed",
|
|
1130
1130
|
"invalidated",
|
|
1131
|
-
"expired"
|
|
1131
|
+
"expired",
|
|
1132
|
+
// 24/09/2026 — where "générer sans envoyer" rests its draft. It used to
|
|
1133
|
+
// finalize as `invalidated`, which the ticket page and the dashboard both
|
|
1134
|
+
// read as "an agent had already answered": the test artefact was stored,
|
|
1135
|
+
// but disguised as a human intervention. Terminal on purpose — nothing may
|
|
1136
|
+
// serve, send or revive a test draft — and terminal is also what frees the
|
|
1137
|
+
// `openTicketKey` (see `openTicketKeyFor`), so an essay can never hold the
|
|
1138
|
+
// real webhook at G9.
|
|
1139
|
+
"test_draft"
|
|
1132
1140
|
];
|
|
1133
1141
|
function isGeneratedResponseStatus(value) {
|
|
1134
1142
|
return typeof value === "string" && GENERATED_RESPONSE_STATUSES.includes(value);
|
|
1135
1143
|
}
|
|
1136
1144
|
var ALLOWED_TRANSITIONS = {
|
|
1137
|
-
pending:
|
|
1145
|
+
// `pending -> test_draft` is the ONLY way in: the test pass finalizes the
|
|
1146
|
+
// very `pending` row it opened, and no other status can become a test
|
|
1147
|
+
// draft after the fact — an operator invalidating a real `ready` draft is
|
|
1148
|
+
// expressing "discard this", not "this was an essay".
|
|
1149
|
+
pending: ["ready", "failed", "no_reply_needed", "sending", "invalidated", "test_draft"],
|
|
1138
1150
|
ready: ["sending", "invalidated", "expired"],
|
|
1139
1151
|
sending: ["sent", "ready"],
|
|
1140
1152
|
sent: [],
|
|
1141
1153
|
failed: [],
|
|
1142
1154
|
no_reply_needed: [],
|
|
1143
1155
|
invalidated: [],
|
|
1144
|
-
expired: []
|
|
1156
|
+
expired: [],
|
|
1157
|
+
test_draft: []
|
|
1145
1158
|
};
|
|
1146
1159
|
function canTransition(from, to) {
|
|
1147
1160
|
if (!isGeneratedResponseStatus(from) || !isGeneratedResponseStatus(to)) return false;
|
|
@@ -1426,6 +1439,7 @@ var GENERATED_RESPONSE_FIELD_GENERATED_LAST_MESSAGE_AT_UID = "94c4594f-4ad0-4e3b
|
|
|
1426
1439
|
var GENERATED_RESPONSE_FIELD_SENDING_AT_UID = "2ae9634b-79bb-42d2-a949-8b0f1ac9c763";
|
|
1427
1440
|
var GENERATED_RESPONSE_FIELD_OUTCOME_UID = "8834b334-8f91-46f7-9bb9-96b69092d0ae";
|
|
1428
1441
|
var GENERATED_RESPONSE_FIELD_ORIGIN_UID = "e75034d3-ee7f-40e7-b4fe-8be7b4322bdc";
|
|
1442
|
+
var GENERATED_RESPONSE_FIELD_RUN_ID_UID = "f3448bca-9c59-418f-9509-ce0e43eb8768";
|
|
1429
1443
|
var GENERATED_RESPONSE_INDEX_TICKET_ID_UID = "a4534d26-8f43-4510-9c03-0b28c3d3f8e2";
|
|
1430
1444
|
var GENERATED_RESPONSE_INDEX_OPEN_TICKET_KEY_UID = "3d430166-07a2-43c2-911b-89ec25d13f64";
|
|
1431
1445
|
var GENERATED_RESPONSE_INDEX_STATUS_UID = "f5c4e5d4-0810-424d-8a14-617e9555a7f3";
|
|
@@ -2117,6 +2131,14 @@ function buildGeneratedResponseRecord(slug) {
|
|
|
2117
2131
|
description: "When status became 'sending' \u2014 the sweep's staleness clock (\xA73.5).",
|
|
2118
2132
|
isNullable: true
|
|
2119
2133
|
},
|
|
2134
|
+
{
|
|
2135
|
+
universalIdentifier: GENERATED_RESPONSE_FIELD_RUN_ID_UID,
|
|
2136
|
+
name: "runId",
|
|
2137
|
+
type: appKit.FieldType.TEXT,
|
|
2138
|
+
label: "Run id",
|
|
2139
|
+
description: "Applicative run this row was written under \u2014 `triage-decision.runId`'s twin, set by the follow-up pass (openFollowupResponse). Nullable: triage-tick's own creations predate their run linkage.",
|
|
2140
|
+
isNullable: true
|
|
2141
|
+
},
|
|
2120
2142
|
{
|
|
2121
2143
|
universalIdentifier: GENERATED_RESPONSE_FIELD_ORIGIN_UID,
|
|
2122
2144
|
name: "origin",
|
|
@@ -2954,7 +2976,15 @@ function createPlatformLlmPort(api, trace) {
|
|
|
2954
2976
|
"createPlatformLlmPort: ctx.api.llm.complete v2 has no tool-calling surface (no `tools` parameter, no `role: 'tool'` message) \u2014 cannot honour CompletionRequest.tools."
|
|
2955
2977
|
);
|
|
2956
2978
|
}
|
|
2957
|
-
const
|
|
2979
|
+
const baseTrace = req.trace ?? trace;
|
|
2980
|
+
const runTrace = baseTrace && req.promptRef?.name ? {
|
|
2981
|
+
...baseTrace,
|
|
2982
|
+
metadata: {
|
|
2983
|
+
...baseTrace.metadata,
|
|
2984
|
+
prompt_name: req.promptRef.name,
|
|
2985
|
+
...typeof req.promptRef.version === "number" ? { prompt_version: String(req.promptRef.version) } : {}
|
|
2986
|
+
}
|
|
2987
|
+
} : baseTrace;
|
|
2958
2988
|
const result = await api.llm.complete({
|
|
2959
2989
|
messages: req.messages.map(toPlatformMessage),
|
|
2960
2990
|
options: {
|
|
@@ -3442,17 +3472,17 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
|
|
|
3442
3472
|
const record = await getOptional(ctx, "generated-response", recordId);
|
|
3443
3473
|
if (!record) {
|
|
3444
3474
|
ctx.logger.info(`respond: generated-response ${recordId} no longer exists, skipping`);
|
|
3445
|
-
return;
|
|
3475
|
+
return null;
|
|
3446
3476
|
}
|
|
3447
3477
|
const data = record.data;
|
|
3448
3478
|
if (data.status !== "pending") {
|
|
3449
3479
|
ctx.logger.info(`respond: generated-response ${recordId} is not pending (status="${String(data.status)}"), skipping \u2014 already handled by another worker`);
|
|
3450
|
-
return;
|
|
3480
|
+
return null;
|
|
3451
3481
|
}
|
|
3452
3482
|
const settings = await ctx.api.settings.get();
|
|
3453
3483
|
if (validateSettings(settings).length > 0) {
|
|
3454
3484
|
ctx.logger.info("respond: settings invalid, skipping");
|
|
3455
|
-
return;
|
|
3485
|
+
return null;
|
|
3456
3486
|
}
|
|
3457
3487
|
const ticketId = data.ticketId;
|
|
3458
3488
|
const ref = { id: ticketId, channel: "gorgias" };
|
|
@@ -3460,7 +3490,7 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
|
|
|
3460
3490
|
if (!decision) {
|
|
3461
3491
|
ctx.logger.error(`respond: generated-response ${recordId} has no resolvable triage-decision, marking failed`);
|
|
3462
3492
|
await finalizeNonSent(ctx, recordId, ticketId, "failed", { error: "triage-decision not found" });
|
|
3463
|
-
return;
|
|
3493
|
+
return null;
|
|
3464
3494
|
}
|
|
3465
3495
|
const classification = classificationFromDecision(decision);
|
|
3466
3496
|
const escalated = decision.data.escalated === true;
|
|
@@ -3475,7 +3505,18 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
|
|
|
3475
3505
|
);
|
|
3476
3506
|
const testRun = options.testRun === true;
|
|
3477
3507
|
const dryRun = settings.dryRun === true || testRun;
|
|
3478
|
-
const
|
|
3508
|
+
const decisionTicketUrl = decision.data.ticketUrl;
|
|
3509
|
+
const trace = {
|
|
3510
|
+
sessionId: ticketId,
|
|
3511
|
+
tags: [`app:${config.slug}`, ...agent ? [`agent:${agent.name}`] : []],
|
|
3512
|
+
metadata: {
|
|
3513
|
+
ticket_id: ticketId,
|
|
3514
|
+
...typeof decisionTicketUrl === "string" && decisionTicketUrl !== "" ? { conversation_url: decisionTicketUrl } : {},
|
|
3515
|
+
...agent ? { model: agent.name, model_id: agent.modelId } : {},
|
|
3516
|
+
...category ? { category: category.tagName } : {},
|
|
3517
|
+
origin
|
|
3518
|
+
}
|
|
3519
|
+
};
|
|
3479
3520
|
const ports = dryRun ? withRecordingWritePorts(buildTicketPorts(ctx, trace), ctx.api) : buildTicketPorts(ctx, trace);
|
|
3480
3521
|
const { clock } = ports;
|
|
3481
3522
|
const conversationSnapshot = await ports.conversation.read(ref);
|
|
@@ -3535,21 +3576,21 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
|
|
|
3535
3576
|
},
|
|
3536
3577
|
...attributionFields(result.draft?.attribution)
|
|
3537
3578
|
};
|
|
3538
|
-
const restingStatus = testRun ? "
|
|
3579
|
+
const restingStatus = testRun ? "test_draft" : "ready";
|
|
3539
3580
|
switch (result.outcome) {
|
|
3540
3581
|
case "sent":
|
|
3541
3582
|
if (dryRun) {
|
|
3542
3583
|
await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
3543
|
-
return;
|
|
3584
|
+
return result.outcome;
|
|
3544
3585
|
}
|
|
3545
|
-
return;
|
|
3586
|
+
return result.outcome;
|
|
3546
3587
|
case "ready":
|
|
3547
3588
|
case "guardrail_hold":
|
|
3548
3589
|
await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
3549
|
-
return;
|
|
3590
|
+
return result.outcome;
|
|
3550
3591
|
case "needs_human":
|
|
3551
3592
|
await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
3552
|
-
return;
|
|
3593
|
+
return result.outcome;
|
|
3553
3594
|
case "awaiting_approval": {
|
|
3554
3595
|
const persisted = await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
3555
3596
|
if (persisted && !dryRun) {
|
|
@@ -3559,18 +3600,19 @@ async function respondToPendingResponse(ctx, config, recordId, options = {}) {
|
|
|
3559
3600
|
entityRef: { appSlug: config.slug, objectKey: "generated-response", id: recordId }
|
|
3560
3601
|
});
|
|
3561
3602
|
}
|
|
3562
|
-
return;
|
|
3603
|
+
return result.outcome;
|
|
3563
3604
|
}
|
|
3564
3605
|
case "escalated":
|
|
3565
3606
|
case "triaged_only":
|
|
3566
3607
|
case "no_reply_needed":
|
|
3567
|
-
await finalizeNonSent(ctx, recordId, ticketId, "no_reply_needed", draftExtra);
|
|
3568
|
-
return;
|
|
3608
|
+
await finalizeNonSent(ctx, recordId, ticketId, testRun ? restingStatus : "no_reply_needed", draftExtra);
|
|
3609
|
+
return result.outcome;
|
|
3569
3610
|
case "failed":
|
|
3570
3611
|
await finalizeNonSent(ctx, recordId, ticketId, "failed", { ...draftExtra, error: "runTicket outcome: failed" });
|
|
3571
|
-
return;
|
|
3612
|
+
return result.outcome;
|
|
3572
3613
|
default:
|
|
3573
3614
|
ctx.logger.error(`respond: generated-response ${recordId} resumed run ended with no outcome`);
|
|
3615
|
+
return null;
|
|
3574
3616
|
}
|
|
3575
3617
|
}
|
|
3576
3618
|
async function transitionGeneratedResponse(api, params) {
|
|
@@ -3590,6 +3632,29 @@ async function transitionGeneratedResponse(api, params) {
|
|
|
3590
3632
|
}
|
|
3591
3633
|
}
|
|
3592
3634
|
|
|
3635
|
+
// src/functions/ticket-url.ts
|
|
3636
|
+
async function resolveTicketUrlBase(ctx) {
|
|
3637
|
+
try {
|
|
3638
|
+
const connections = await ctx.api.integrations.list("gorgias");
|
|
3639
|
+
const connection = connections.find((candidate) => candidate.isDefault) ?? connections[0];
|
|
3640
|
+
const result = await ctx.api.integrations.run(
|
|
3641
|
+
"gorgias",
|
|
3642
|
+
"getTicketUrlBase",
|
|
3643
|
+
{},
|
|
3644
|
+
connection ? { connectionId: connection.id } : void 0
|
|
3645
|
+
);
|
|
3646
|
+
return typeof result?.base === "string" && result.base !== "" ? result.base : null;
|
|
3647
|
+
} catch (err) {
|
|
3648
|
+
ctx.logger.warn("ticket-url: could not resolve the Gorgias ticket url base, rows will carry no deep link", {
|
|
3649
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3650
|
+
});
|
|
3651
|
+
return null;
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
function ticketUrlFor(base, ticketId) {
|
|
3655
|
+
return base ? `${base}/${encodeURIComponent(ticketId)}` : null;
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3593
3658
|
// src/functions/triage-tick.ts
|
|
3594
3659
|
function buildTriageTickFunctionDef(config) {
|
|
3595
3660
|
return {
|
|
@@ -3632,30 +3697,10 @@ async function triageTickHandler(ctx, config) {
|
|
|
3632
3697
|
}
|
|
3633
3698
|
await runTriageBatch(ctx, config, settings);
|
|
3634
3699
|
}
|
|
3635
|
-
async function resolveTicketUrlBase(ctx) {
|
|
3636
|
-
try {
|
|
3637
|
-
const connections = await ctx.api.integrations.list("gorgias");
|
|
3638
|
-
const connection = connections.find((candidate) => candidate.isDefault) ?? connections[0];
|
|
3639
|
-
const result = await ctx.api.integrations.run(
|
|
3640
|
-
"gorgias",
|
|
3641
|
-
"getTicketUrlBase",
|
|
3642
|
-
{},
|
|
3643
|
-
connection ? { connectionId: connection.id } : void 0
|
|
3644
|
-
);
|
|
3645
|
-
return typeof result?.base === "string" && result.base !== "" ? result.base : null;
|
|
3646
|
-
} catch (err) {
|
|
3647
|
-
ctx.logger.warn("triage-tick: could not resolve the Gorgias ticket url base, decisions will carry no deep link", {
|
|
3648
|
-
error: err instanceof Error ? err.message : String(err)
|
|
3649
|
-
});
|
|
3650
|
-
return null;
|
|
3651
|
-
}
|
|
3652
|
-
}
|
|
3653
|
-
function ticketUrlFor(base, ticketId) {
|
|
3654
|
-
return base ? `${base}/${encodeURIComponent(ticketId)}` : null;
|
|
3655
|
-
}
|
|
3656
3700
|
async function runTriageBatch(ctx, config, settings) {
|
|
3657
3701
|
const dryRun = settings.dryRun === true;
|
|
3658
|
-
const
|
|
3702
|
+
const batchTrace = { tags: [`app:${config.slug}`] };
|
|
3703
|
+
const ports = dryRun ? withRecordingWritePorts(buildTicketPorts(ctx, batchTrace), ctx.api) : buildTicketPorts(ctx, batchTrace);
|
|
3659
3704
|
const categories = await listCategories(ctx.api);
|
|
3660
3705
|
const batchDefaultAgent = await resolveDraftAgent(ctx.api, null);
|
|
3661
3706
|
const profile = settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(batchDefaultAgent, config), settings.nodes));
|
|
@@ -4005,7 +4050,11 @@ async function handleApprovalHandler(ctx, config) {
|
|
|
4005
4050
|
}
|
|
4006
4051
|
return;
|
|
4007
4052
|
}
|
|
4008
|
-
const ports = buildTicketPorts(ctx
|
|
4053
|
+
const ports = buildTicketPorts(ctx, {
|
|
4054
|
+
sessionId: ticketId,
|
|
4055
|
+
tags: [`app:${config.slug}`],
|
|
4056
|
+
metadata: { ticket_id: ticketId }
|
|
4057
|
+
});
|
|
4009
4058
|
const { clock, state: statePort } = ports;
|
|
4010
4059
|
const conversation = {
|
|
4011
4060
|
ref: { id: ticketId, channel: "gorgias" },
|
|
@@ -5868,6 +5917,11 @@ function skippedFollowupGates(gates) {
|
|
|
5868
5917
|
detail: "Non \xE9valu\xE9 : un gate pr\xE9c\xE9dent a arr\xEAt\xE9 le traitement."
|
|
5869
5918
|
}));
|
|
5870
5919
|
}
|
|
5920
|
+
function completeFollowupLadder(results) {
|
|
5921
|
+
const evaluated = new Set(results.map((result) => result.gate));
|
|
5922
|
+
const missing = ALL_FOLLOWUP_GATES.filter((gate) => !evaluated.has(gate));
|
|
5923
|
+
return missing.length === 0 ? results : [...results, ...skippedFollowupGates(missing)];
|
|
5924
|
+
}
|
|
5871
5925
|
var FRESH_READ_GATES = ["G5", "G6", "G7", "G8"];
|
|
5872
5926
|
var ALL_FOLLOWUP_GATES = ["G1", "G2", ...FRESH_READ_GATES];
|
|
5873
5927
|
function evaluateTicketGates(input) {
|
|
@@ -6146,20 +6200,26 @@ async function executeFollowupRun(ctx, config, rawBody, existingRunId, options =
|
|
|
6146
6200
|
}
|
|
6147
6201
|
async function runFollowupPass(ctx, config, rawBody, run, generateOnly) {
|
|
6148
6202
|
const body = parseFollowupWebhookBody(rawBody);
|
|
6203
|
+
const ladder = [];
|
|
6149
6204
|
const ticketIdGate = evaluateTicketIdGate(body.ticketId);
|
|
6150
|
-
|
|
6205
|
+
ladder.push(ticketIdGate);
|
|
6206
|
+
if (!body.ticketId) return stop(ctx, null, ticketIdGate.gate, ticketIdGate.detail, ladder);
|
|
6151
6207
|
const ticketId = body.ticketId;
|
|
6152
6208
|
const settings = await ctx.api.settings.get();
|
|
6153
6209
|
const issues = validateSettings(settings);
|
|
6154
6210
|
if (issues.length > 0) {
|
|
6155
|
-
return stop(ctx, ticketId, "settings", `r\xE9glages invalides : ${issues.map((issue) => issue.message).join(" ")}
|
|
6211
|
+
return stop(ctx, ticketId, "settings", `r\xE9glages invalides : ${issues.map((issue) => issue.message).join(" ")}`, ladder);
|
|
6156
6212
|
}
|
|
6157
6213
|
const scope = evaluateScopeGate(settings);
|
|
6158
|
-
|
|
6214
|
+
ladder.push(scope);
|
|
6215
|
+
if (scope.status === "stopped") return stopAt(ctx, ticketId, scope, ladder);
|
|
6159
6216
|
const { anchor, hasOpenResponse } = await readFollowupAnchor(ctx, ticketId);
|
|
6160
6217
|
const categories = await listCategories(ctx.api);
|
|
6161
6218
|
const preGates = evaluatePayloadGates({ settings, body, categories, anchor });
|
|
6162
|
-
if (preGates.stop)
|
|
6219
|
+
if (preGates.stop) {
|
|
6220
|
+
ladder.push(...preGates.results);
|
|
6221
|
+
return stopAt(ctx, ticketId, preGates.stop, ladder, "pr\xE9-gate");
|
|
6222
|
+
}
|
|
6163
6223
|
const ref = { id: ticketId, channel: "gorgias" };
|
|
6164
6224
|
const ticket = await ctx.api.integrations.run("gorgias", "getTicketWithContext", { ticketId });
|
|
6165
6225
|
const raw = ticket?.ticket ?? {};
|
|
@@ -6172,23 +6232,35 @@ async function runFollowupPass(ctx, config, rawBody, run, generateOnly) {
|
|
|
6172
6232
|
anchor,
|
|
6173
6233
|
ignoreCategoryOptIn: generateOnly
|
|
6174
6234
|
});
|
|
6235
|
+
ladder.push(...gates.results);
|
|
6175
6236
|
if (gates.stop || !gates.category) {
|
|
6176
|
-
return stopAt(ctx, ticketId, gates.stop ?? unresolvedCategory());
|
|
6237
|
+
return stopAt(ctx, ticketId, gates.stop ?? unresolvedCategory(), ladder);
|
|
6177
6238
|
}
|
|
6178
6239
|
const category = gates.category;
|
|
6179
|
-
if (hasOpenResponse) return stop(ctx, ticketId, "G9", "une r\xE9ponse est d\xE9j\xE0 ouverte sur ce ticket");
|
|
6240
|
+
if (hasOpenResponse) return stop(ctx, ticketId, "G9", "une r\xE9ponse est d\xE9j\xE0 ouverte sur ce ticket", ladder);
|
|
6180
6241
|
run.id ??= (await ctx.api.runs.start({
|
|
6181
6242
|
kind: FOLLOWUP_RUN_KIND,
|
|
6182
6243
|
message: `Message suivant \u2014 ticket ${ticketId}`,
|
|
6183
6244
|
metadata: { ticketId, categoryTag: category.tagName, channel: body.channel, generateOnly }
|
|
6184
6245
|
})).id;
|
|
6185
|
-
const
|
|
6186
|
-
|
|
6187
|
-
|
|
6246
|
+
const ticketUrl = ticketUrlFor(await resolveTicketUrlBase(ctx), ticketId);
|
|
6247
|
+
const created = await openFollowupResponse(ctx, { ticketId, category, conversation, settings, runId: run.id, ticketUrl });
|
|
6248
|
+
if (!created) return stop(ctx, ticketId, "G9", "une autre ex\xE9cution a ouvert la r\xE9ponse en premier", ladder);
|
|
6249
|
+
const outcome2 = await respondToPendingResponse(ctx, config, created.id, { testRun: generateOnly });
|
|
6188
6250
|
return {
|
|
6189
6251
|
ticketId,
|
|
6252
|
+
ticketUrl,
|
|
6190
6253
|
stoppedAt: null,
|
|
6191
|
-
reason: generateOnly ? `r\xE9ponse de suite g\xE9n\xE9r\xE9e sans envoi (cat\xE9gorie \xAB ${category.name} \xBB)` : `r\xE9ponse de suite g\xE9n\xE9r\xE9e (cat\xE9gorie \xAB ${category.name} \xBB)
|
|
6254
|
+
reason: generateOnly ? `r\xE9ponse de suite g\xE9n\xE9r\xE9e sans envoi (cat\xE9gorie \xAB ${category.name} \xBB)` : `r\xE9ponse de suite g\xE9n\xE9r\xE9e (cat\xE9gorie \xAB ${category.name} \xBB)`,
|
|
6255
|
+
gates: completeFollowupLadder(ladder),
|
|
6256
|
+
categoryId: category.id,
|
|
6257
|
+
categoryName: category.name,
|
|
6258
|
+
// Off the ROW, not off the category: `openFollowupResponse` resolves a
|
|
6259
|
+
// default agent when the category names none, and the row records who
|
|
6260
|
+
// actually wrote.
|
|
6261
|
+
agentId: created.data.agentId ?? null,
|
|
6262
|
+
outcome: outcome2,
|
|
6263
|
+
responseId: created.id
|
|
6192
6264
|
};
|
|
6193
6265
|
}
|
|
6194
6266
|
async function readFollowupAnchor(ctx, ticketId) {
|
|
@@ -6232,10 +6304,11 @@ async function openFollowupResponse(ctx, input) {
|
|
|
6232
6304
|
const { ticketId, category, conversation, settings, runId } = input;
|
|
6233
6305
|
const decision = await ctx.api.create("triage-decision", {
|
|
6234
6306
|
ticketId,
|
|
6235
|
-
//
|
|
6236
|
-
//
|
|
6237
|
-
//
|
|
6238
|
-
|
|
6307
|
+
// Resolved by the caller AFTER every gate (`ticket-url.ts`), so a
|
|
6308
|
+
// refused message — the common case on an account-wide event stream —
|
|
6309
|
+
// never pays the extra Gorgias call. Still nullable: resolution
|
|
6310
|
+
// degrades to `null` rather than failing the pass.
|
|
6311
|
+
ticketUrl: input.ticketUrl,
|
|
6239
6312
|
decidedAt: /* @__PURE__ */ new Date(),
|
|
6240
6313
|
categoryId: category.id,
|
|
6241
6314
|
tag: category.tagName,
|
|
@@ -6280,7 +6353,8 @@ async function openFollowupResponse(ctx, input) {
|
|
|
6280
6353
|
servedTo: [],
|
|
6281
6354
|
servedCount: 0,
|
|
6282
6355
|
followupRequired: false,
|
|
6283
|
-
origin: "followup"
|
|
6356
|
+
origin: "followup",
|
|
6357
|
+
runId
|
|
6284
6358
|
});
|
|
6285
6359
|
} catch (err) {
|
|
6286
6360
|
if (err instanceof appKit.AppApiError && err.status === 409) return null;
|
|
@@ -6295,12 +6369,23 @@ function unresolvedCategory() {
|
|
|
6295
6369
|
detail: "Aucune cat\xE9gorie r\xE9solue."
|
|
6296
6370
|
};
|
|
6297
6371
|
}
|
|
6298
|
-
function stopAt(ctx, ticketId, result, kind = "gate") {
|
|
6299
|
-
return stop(ctx, ticketId, `${result.gate}${kind === "gate" ? "" : ` (${kind})`}`, result.detail);
|
|
6372
|
+
function stopAt(ctx, ticketId, result, ladder, kind = "gate") {
|
|
6373
|
+
return stop(ctx, ticketId, `${result.gate}${kind === "gate" ? "" : ` (${kind})`}`, result.detail, ladder);
|
|
6300
6374
|
}
|
|
6301
|
-
function stop(ctx, ticketId, gate, reason) {
|
|
6375
|
+
function stop(ctx, ticketId, gate, reason, ladder) {
|
|
6302
6376
|
ctx.logger.info(`gorgias-webhook: stop at ${gate} for ticket ${ticketId ?? "?"} \u2014 ${reason}`);
|
|
6303
|
-
return {
|
|
6377
|
+
return {
|
|
6378
|
+
ticketId,
|
|
6379
|
+
stoppedAt: gate,
|
|
6380
|
+
reason,
|
|
6381
|
+
gates: completeFollowupLadder(ladder),
|
|
6382
|
+
categoryId: null,
|
|
6383
|
+
categoryName: null,
|
|
6384
|
+
agentId: null,
|
|
6385
|
+
outcome: null,
|
|
6386
|
+
responseId: null,
|
|
6387
|
+
ticketUrl: null
|
|
6388
|
+
};
|
|
6304
6389
|
}
|
|
6305
6390
|
function buildTestGorgiasWebhookFunctionDef(config) {
|
|
6306
6391
|
return {
|
|
@@ -6362,9 +6447,7 @@ async function diagnose(ctx, ticketId) {
|
|
|
6362
6447
|
return finish3(gates, ticketId);
|
|
6363
6448
|
}
|
|
6364
6449
|
function finish3(gates, ticketId) {
|
|
6365
|
-
const
|
|
6366
|
-
const missing = ALL_FOLLOWUP_GATES.filter((gate) => !evaluated.has(gate));
|
|
6367
|
-
const full = [...gates, ...skippedFollowupGates(missing)];
|
|
6450
|
+
const full = completeFollowupLadder(gates);
|
|
6368
6451
|
return {
|
|
6369
6452
|
mode: "diagnostic",
|
|
6370
6453
|
ticketId,
|