@apotech-os/support-kit 7.0.1 → 8.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/README.md +19 -16
- package/dist/{chunk-QCRCRNYE.js → chunk-LXHPPWPM.js} +39 -6
- package/dist/chunk-LXHPPWPM.js.map +1 -0
- package/dist/index.cjs +160 -169
- 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 +145 -168
- package/dist/index.js.map +1 -1
- package/dist/ui/index.cjs +332 -174
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.js +301 -175
- package/dist/ui/index.js.map +1 -1
- package/package.json +11 -11
- package/dist/chunk-QCRCRNYE.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1461,7 +1461,7 @@ declare function isAutoSendEligible(state: TicketRunState, deps: Pick<NodeDeps,
|
|
|
1461
1461
|
declare function needsRevision(verdict: Verdict | null, profile: AgentProfile, reviseCount: number): boolean;
|
|
1462
1462
|
|
|
1463
1463
|
/** The `generated-response` record's `status` field (§3.4). */
|
|
1464
|
-
declare const GENERATED_RESPONSE_STATUSES: readonly ["pending", "ready", "sending", "sent", "failed", "no_reply_needed", "invalidated", "expired"];
|
|
1464
|
+
declare const GENERATED_RESPONSE_STATUSES: readonly ["pending", "ready", "sending", "sent", "failed", "no_reply_needed", "invalidated", "expired", "test_draft"];
|
|
1465
1465
|
type GeneratedResponseStatus = (typeof GENERATED_RESPONSE_STATUSES)[number];
|
|
1466
1466
|
/**
|
|
1467
1467
|
* `status` lives in `AppRecord` JSONB (§3.4), so it reaches this module as an
|
package/dist/index.d.ts
CHANGED
|
@@ -1461,7 +1461,7 @@ declare function isAutoSendEligible(state: TicketRunState, deps: Pick<NodeDeps,
|
|
|
1461
1461
|
declare function needsRevision(verdict: Verdict | null, profile: AgentProfile, reviseCount: number): boolean;
|
|
1462
1462
|
|
|
1463
1463
|
/** The `generated-response` record's `status` field (§3.4). */
|
|
1464
|
-
declare const GENERATED_RESPONSE_STATUSES: readonly ["pending", "ready", "sending", "sent", "failed", "no_reply_needed", "invalidated", "expired"];
|
|
1464
|
+
declare const GENERATED_RESPONSE_STATUSES: readonly ["pending", "ready", "sending", "sent", "failed", "no_reply_needed", "invalidated", "expired", "test_draft"];
|
|
1465
1465
|
type GeneratedResponseStatus = (typeof GENERATED_RESPONSE_STATUSES)[number];
|
|
1466
1466
|
/**
|
|
1467
1467
|
* `status` lives in `AppRecord` JSONB (§3.4), so it reaches this module as an
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CATEGORY_GROUP_FIELD_NAME_UID, CATEGORY_GROUP_FIELD_ORDER_UID, PIPELINE_STATE_FIELD_SINGLETON_KEY_UID, PIPELINE_STATE_FIELD_SOURCE_VIEW_ID_UID, PIPELINE_STATE_FIELD_LAST_TRIAGE_AT_UID, PIPELINE_STATE_FIELD_LAST_SWEEP_AT_UID, PROMPT_CACHE_FIELD_PROMPT_KEY_UID, PROMPT_CACHE_FIELD_CONTENT_UID, PROMPT_CACHE_FIELD_VERSION_UID, PROMPT_CACHE_FIELD_LABEL_UID, PROMPT_CACHE_FIELD_CONFIG_UID, CATEGORY_GROUP_INDEX_NAME_UID, CATEGORY_GROUP_OBJECT_UID, PIPELINE_STATE_INDEX_SINGLETON_KEY_UID, PIPELINE_STATE_OBJECT_UID, PROMPT_CACHE_INDEX_PROMPT_KEY_UID, PROMPT_CACHE_OBJECT_UID, CATEGORY_INDEX_TAG_NAME_UID, CATEGORY_INDEX_NAME_UID, CATEGORY_INDEX_ORDER_UID, CATEGORY_FIELD_NAME_UID, CATEGORY_FIELD_TAG_NAME_UID, CATEGORY_FIELD_ORDER_UID, CATEGORY_FIELD_GROUP_ID_UID, CATEGORY_FIELD_AGENT_ID_UID, CATEGORY_FIELD_EXTRA_TAGS_UID, CATEGORY_FIELD_DESCRIPTION_UID, CATEGORY_FIELD_EXAMPLES_UID, CATEGORY_FIELD_FAST_RESPONSE_ENABLED_UID, CATEGORY_FIELD_AUTO_REPLY_ENABLED_UID, CATEGORY_FIELD_FOLLOWUP_FAST_RESPONSE_ENABLED_UID, CATEGORY_FIELD_FOLLOWUP_AUTO_REPLY_ENABLED_UID, CATEGORY_OBJECT_UID, TRIAGE_DECISION_INDEX_TICKET_ID_UID, TRIAGE_DECISION_INDEX_DECIDED_AT_UID, TRIAGE_DECISION_INDEX_ESCALATED_UID, TRIAGE_DECISION_FIELD_TICKET_ID_UID, TRIAGE_DECISION_FIELD_TICKET_URL_UID, TRIAGE_DECISION_FIELD_DECIDED_AT_UID, TRIAGE_DECISION_FIELD_CATEGORY_ID_UID, TRIAGE_DECISION_FIELD_TAG_UID, TRIAGE_DECISION_FIELD_CONFIDENCE_UID, TRIAGE_DECISION_FIELD_REASONING_UID, TRIAGE_DECISION_FIELD_CONVERSATION_OVER_UID, TRIAGE_DECISION_FIELD_ESCALATED_UID, TRIAGE_DECISION_FIELD_ESCALATION_CONFIDENCE_UID, TRIAGE_DECISION_FIELD_ESCALATION_REASONING_UID, TRIAGE_DECISION_FIELD_STATUS_UID, TRIAGE_DECISION_FIELD_ERROR_UID, TRIAGE_DECISION_FIELD_RUN_ID_UID, TRIAGE_DECISION_FIELD_SUBJECT_RENAMED_UID, DEFAULT_DECISION_ORIGIN, ORIGIN_DESCRIPTION, TRIAGE_DECISION_FIELD_ORIGIN_UID, TRIAGE_DECISION_OBJECT_UID, GENERATED_RESPONSE_INDEX_TICKET_ID_UID, GENERATED_RESPONSE_INDEX_OPEN_TICKET_KEY_UID, GENERATED_RESPONSE_INDEX_STATUS_UID, GENERATED_RESPONSE_INDEX_TRIAGE_DECISION_ID_UID, GENERATED_RESPONSE_INDEX_GENERATED_AT_UID, GENERATED_RESPONSE_INDEX_EXPIRES_AT_UID, GENERATED_RESPONSE_FIELD_TICKET_ID_UID, GENERATED_RESPONSE_FIELD_OPEN_TICKET_KEY_UID, GENERATED_RESPONSE_STATUSES, GENERATED_RESPONSE_FIELD_STATUS_UID, GENERATED_RESPONSE_FIELD_TRIAGE_DECISION_ID_UID, GENERATED_RESPONSE_FIELD_CATEGORY_ID_UID, GENERATED_RESPONSE_FIELD_AGENT_ID_UID, GENERATED_RESPONSE_FIELD_CHANNEL_UID, GENERATED_RESPONSE_FIELD_RESPONSE_TEXT_UID, GENERATED_RESPONSE_FIELD_SOURCES_UID, GENERATED_RESPONSE_FIELD_TRACED_INPUT_UID, GENERATED_RESPONSE_FIELD_VERDICT_UID, GENERATED_RESPONSE_FIELD_GUARDRAIL_HITS_UID, OUTCOMES, GENERATED_RESPONSE_FIELD_OUTCOME_UID, GENERATED_RESPONSE_FIELD_AUTO_SEND_DECISION_UID, GENERATED_RESPONSE_FIELD_FOLLOWUP_REQUIRED_UID, GENERATED_RESPONSE_FIELD_SERVED_COUNT_UID, GENERATED_RESPONSE_FIELD_SERVED_TO_UID, GENERATED_RESPONSE_FIELD_GENERATED_AT_UID, GENERATED_RESPONSE_FIELD_EXPIRES_AT_UID, GENERATED_RESPONSE_FIELD_SENT_AT_UID, GENERATED_RESPONSE_FIELD_SENT_MESSAGE_ID_UID, GENERATED_RESPONSE_FIELD_LANGFUSE_TRACE_ID_UID, GENERATED_RESPONSE_FIELD_LANGFUSE_OBSERVATION_ID_UID, GENERATED_RESPONSE_FIELD_PROMPT_NAME_UID, GENERATED_RESPONSE_FIELD_PROMPT_VERSION_UID, GENERATED_RESPONSE_FIELD_ERROR_UID, GENERATED_RESPONSE_FIELD_GENERATED_MESSAGE_COUNT_UID, GENERATED_RESPONSE_FIELD_GENERATED_LAST_MESSAGE_AT_UID, GENERATED_RESPONSE_FIELD_SENDING_AT_UID, GENERATED_RESPONSE_FIELD_ORIGIN_UID, GENERATED_RESPONSE_OBJECT_UID, RESPONSE_COMPARISON_INDEX_CAPTURED_AT_UID, RESPONSE_COMPARISON_INDEX_TICKET_ID_UID, RESPONSE_COMPARISON_FIELD_GENERATED_TEXT_UID, RESPONSE_COMPARISON_FIELD_SENT_TEXT_UID, RESPONSE_COMPARISON_FIELD_CAPTURED_AT_UID, RESPONSE_COMPARISON_FIELD_TICKET_ID_UID, RESPONSE_COMPARISON_FIELD_TICKET_URL_UID, RESPONSE_COMPARISON_FIELD_AGENT_ID_UID, RESPONSE_COMPARISON_FIELD_LANGFUSE_TRACE_ID_UID, RESPONSE_COMPARISON_FIELD_LANGFUSE_OBSERVATION_ID_UID, RESPONSE_COMPARISON_FIELD_PROMPT_NAME_UID, RESPONSE_COMPARISON_FIELD_PROMPT_VERSION_UID, RESPONSE_COMPARISON_FIELD_CONVERSATION_MESSAGES_UID, RESPONSE_COMPARISON_FIELD_DIFF_UID, RESPONSE_COMPARISON_OBJECT_UID, EVALUATION_FIELD_AGENT_ID_UID, EVALUATION_FIELD_SATISFIED_UID, EVALUATION_FIELD_MESSAGES_UID, EVALUATION_FIELD_TICKET_URL_UID, EVALUATION_FIELD_LANGFUSE_TRACE_ID_UID, EVALUATION_FIELD_LANGFUSE_OBSERVATION_ID_UID, EVALUATION_FIELD_SUPPORT_USER_KEY_ID_UID, EVALUATION_OBJECT_UID, DIFF_ANALYSIS_INDEX_UNIQUE_KEY_UID, DIFF_ANALYSIS_FIELD_AGENT_ID_UID, DIFF_ANALYSIS_FIELD_PROMPT_NAME_UID, DIFF_ANALYSIS_FIELD_PROMPT_VERSION_UID, DIFF_ANALYSIS_FIELD_POINTS_UID, DIFF_ANALYSIS_FIELD_UNIQUE_KEY_UID, DIFF_ANALYSIS_OBJECT_UID, agentRecord, SUPPORT_KIT_SETTINGS_FIELDS, MissingPromptError, validateSettings, settingsToProfile, buildPromptsTable, draftPromptRefFor, assertTransition, openTicketKeyFor, act, initialState, applyOutcomeTags, listCategories, resolveDraftAgent, runTicket, toCategoryReferential, toAgent, draftRebinder, resolvePromptName, isGeneratedResponseStatus, isInvalidatableStatus, DEFAULT_LLM_PROVIDER, toCategoryGroup, toCategory, toGeneratedResponse, NODE_NAMES, reclaimStalledSend, applySignature, isEvaluationVerdict, requiresFollowup, computeWordDiff, findCategoryByTag, isWhatsappTicket, hasCustomerAttachment, isTicketClosed, toDecisionOrigin, isConversationOver, isFallbackClassification, hasNoDraftNode, isWhatsappChevronNote, isCustomerTurnWithWords } from './chunk-
|
|
2
|
-
export { AGENT_GUARDRAILS, AGENT_STATUSES, AGENT_TOOLS, ATTACHMENT_MARKER_ONLY, CANDIDATE_MIN_LENGTH, DECISION_ORIGINS, DEFAULT_CHANNEL_PROMPT_EMAIL, DEFAULT_CHANNEL_PROMPT_WHATSAPP, DEFAULT_DECISION_ORIGIN, DEFAULT_LLM_PROVIDER, DEFAULT_PROFILE_KEY, DEFAULT_WHATSAPP_MODE, EVALUATION_VERDICTS, GENERATED_RESPONSE_STATUSES, InvalidStatusTransitionError, MissingPromptError, NODE_NAMES, ORIGIN_DESCRIPTION, OUTCOMES, PROMPT_SLOTS, REASONING_MAX_LEN, STOP_PHRASES, SUPPORT_KIT_SETTINGS_FIELDS, UNCERTAINTY_MARKERS, WHATSAPP_MODES, WHATSAPP_NOTE_CHEVRON, agentRecord, assertTransition, canTransition, channelPreGates, firstCustomerMessage, guardrailBucket, hasCustomerAttachment, initialState, isAutoSendEligible, isAutomatedSenderEmail, isAutomatedSenderTicket, isCustomerTurnWithWords, isDecisionOrigin, isEvaluationVerdict, isGeneratedResponseStatus, isJudgemeConversation, isJudgemeTicket, isOutcome, isSendable, isSendableVerdict, isTerminalStatus, isTicketClosed, isWhatsappChevronNote, isWhatsappTicket, lastCustomerMessage, needsRevision, openTicketKeyFor, reclaimStalledSend, requiresFollowup, resolvePromptName, runGuardrails, runTicket, settingsToProfile, stopOptOut, toDecisionOrigin, validateSettings, verifyReply, whatsappModeFromLegacyBoolean } from './chunk-
|
|
1
|
+
import { CATEGORY_GROUP_FIELD_NAME_UID, CATEGORY_GROUP_FIELD_ORDER_UID, PIPELINE_STATE_FIELD_SINGLETON_KEY_UID, PIPELINE_STATE_FIELD_SOURCE_VIEW_ID_UID, PIPELINE_STATE_FIELD_LAST_TRIAGE_AT_UID, PIPELINE_STATE_FIELD_LAST_SWEEP_AT_UID, PROMPT_CACHE_FIELD_PROMPT_KEY_UID, PROMPT_CACHE_FIELD_CONTENT_UID, PROMPT_CACHE_FIELD_VERSION_UID, PROMPT_CACHE_FIELD_LABEL_UID, PROMPT_CACHE_FIELD_CONFIG_UID, CATEGORY_GROUP_INDEX_NAME_UID, CATEGORY_GROUP_OBJECT_UID, PIPELINE_STATE_INDEX_SINGLETON_KEY_UID, PIPELINE_STATE_OBJECT_UID, PROMPT_CACHE_INDEX_PROMPT_KEY_UID, PROMPT_CACHE_OBJECT_UID, CATEGORY_INDEX_TAG_NAME_UID, CATEGORY_INDEX_NAME_UID, CATEGORY_INDEX_ORDER_UID, CATEGORY_FIELD_NAME_UID, CATEGORY_FIELD_TAG_NAME_UID, CATEGORY_FIELD_ORDER_UID, CATEGORY_FIELD_GROUP_ID_UID, CATEGORY_FIELD_AGENT_ID_UID, CATEGORY_FIELD_EXTRA_TAGS_UID, CATEGORY_FIELD_DESCRIPTION_UID, CATEGORY_FIELD_EXAMPLES_UID, CATEGORY_FIELD_FAST_RESPONSE_ENABLED_UID, CATEGORY_FIELD_AUTO_REPLY_ENABLED_UID, CATEGORY_FIELD_FOLLOWUP_FAST_RESPONSE_ENABLED_UID, CATEGORY_FIELD_FOLLOWUP_AUTO_REPLY_ENABLED_UID, CATEGORY_OBJECT_UID, TRIAGE_DECISION_INDEX_TICKET_ID_UID, TRIAGE_DECISION_INDEX_DECIDED_AT_UID, TRIAGE_DECISION_INDEX_ESCALATED_UID, TRIAGE_DECISION_FIELD_TICKET_ID_UID, TRIAGE_DECISION_FIELD_TICKET_URL_UID, TRIAGE_DECISION_FIELD_DECIDED_AT_UID, TRIAGE_DECISION_FIELD_CATEGORY_ID_UID, TRIAGE_DECISION_FIELD_TAG_UID, TRIAGE_DECISION_FIELD_CONFIDENCE_UID, TRIAGE_DECISION_FIELD_REASONING_UID, TRIAGE_DECISION_FIELD_CONVERSATION_OVER_UID, TRIAGE_DECISION_FIELD_ESCALATED_UID, TRIAGE_DECISION_FIELD_ESCALATION_CONFIDENCE_UID, TRIAGE_DECISION_FIELD_ESCALATION_REASONING_UID, TRIAGE_DECISION_FIELD_STATUS_UID, TRIAGE_DECISION_FIELD_ERROR_UID, TRIAGE_DECISION_FIELD_RUN_ID_UID, TRIAGE_DECISION_FIELD_SUBJECT_RENAMED_UID, DEFAULT_DECISION_ORIGIN, ORIGIN_DESCRIPTION, TRIAGE_DECISION_FIELD_ORIGIN_UID, TRIAGE_DECISION_OBJECT_UID, GENERATED_RESPONSE_INDEX_TICKET_ID_UID, GENERATED_RESPONSE_INDEX_OPEN_TICKET_KEY_UID, GENERATED_RESPONSE_INDEX_STATUS_UID, GENERATED_RESPONSE_INDEX_TRIAGE_DECISION_ID_UID, GENERATED_RESPONSE_INDEX_GENERATED_AT_UID, GENERATED_RESPONSE_INDEX_EXPIRES_AT_UID, GENERATED_RESPONSE_FIELD_TICKET_ID_UID, GENERATED_RESPONSE_FIELD_OPEN_TICKET_KEY_UID, GENERATED_RESPONSE_STATUSES, GENERATED_RESPONSE_FIELD_STATUS_UID, GENERATED_RESPONSE_FIELD_TRIAGE_DECISION_ID_UID, GENERATED_RESPONSE_FIELD_CATEGORY_ID_UID, GENERATED_RESPONSE_FIELD_AGENT_ID_UID, GENERATED_RESPONSE_FIELD_CHANNEL_UID, GENERATED_RESPONSE_FIELD_RESPONSE_TEXT_UID, GENERATED_RESPONSE_FIELD_SOURCES_UID, GENERATED_RESPONSE_FIELD_TRACED_INPUT_UID, GENERATED_RESPONSE_FIELD_VERDICT_UID, GENERATED_RESPONSE_FIELD_GUARDRAIL_HITS_UID, OUTCOMES, GENERATED_RESPONSE_FIELD_OUTCOME_UID, GENERATED_RESPONSE_FIELD_AUTO_SEND_DECISION_UID, GENERATED_RESPONSE_FIELD_FOLLOWUP_REQUIRED_UID, GENERATED_RESPONSE_FIELD_SERVED_COUNT_UID, GENERATED_RESPONSE_FIELD_SERVED_TO_UID, GENERATED_RESPONSE_FIELD_GENERATED_AT_UID, GENERATED_RESPONSE_FIELD_EXPIRES_AT_UID, GENERATED_RESPONSE_FIELD_SENT_AT_UID, GENERATED_RESPONSE_FIELD_SENT_MESSAGE_ID_UID, GENERATED_RESPONSE_FIELD_LANGFUSE_TRACE_ID_UID, GENERATED_RESPONSE_FIELD_LANGFUSE_OBSERVATION_ID_UID, GENERATED_RESPONSE_FIELD_PROMPT_NAME_UID, GENERATED_RESPONSE_FIELD_PROMPT_VERSION_UID, GENERATED_RESPONSE_FIELD_ERROR_UID, GENERATED_RESPONSE_FIELD_GENERATED_MESSAGE_COUNT_UID, GENERATED_RESPONSE_FIELD_GENERATED_LAST_MESSAGE_AT_UID, GENERATED_RESPONSE_FIELD_SENDING_AT_UID, GENERATED_RESPONSE_FIELD_RUN_ID_UID, GENERATED_RESPONSE_FIELD_ORIGIN_UID, GENERATED_RESPONSE_OBJECT_UID, RESPONSE_COMPARISON_INDEX_CAPTURED_AT_UID, RESPONSE_COMPARISON_INDEX_TICKET_ID_UID, RESPONSE_COMPARISON_FIELD_GENERATED_TEXT_UID, RESPONSE_COMPARISON_FIELD_SENT_TEXT_UID, RESPONSE_COMPARISON_FIELD_CAPTURED_AT_UID, RESPONSE_COMPARISON_FIELD_TICKET_ID_UID, RESPONSE_COMPARISON_FIELD_TICKET_URL_UID, RESPONSE_COMPARISON_FIELD_AGENT_ID_UID, RESPONSE_COMPARISON_FIELD_LANGFUSE_TRACE_ID_UID, RESPONSE_COMPARISON_FIELD_LANGFUSE_OBSERVATION_ID_UID, RESPONSE_COMPARISON_FIELD_PROMPT_NAME_UID, RESPONSE_COMPARISON_FIELD_PROMPT_VERSION_UID, RESPONSE_COMPARISON_FIELD_CONVERSATION_MESSAGES_UID, RESPONSE_COMPARISON_FIELD_DIFF_UID, RESPONSE_COMPARISON_OBJECT_UID, EVALUATION_FIELD_AGENT_ID_UID, EVALUATION_FIELD_SATISFIED_UID, EVALUATION_FIELD_MESSAGES_UID, EVALUATION_FIELD_TICKET_URL_UID, EVALUATION_FIELD_LANGFUSE_TRACE_ID_UID, EVALUATION_FIELD_LANGFUSE_OBSERVATION_ID_UID, EVALUATION_FIELD_SUPPORT_USER_KEY_ID_UID, EVALUATION_OBJECT_UID, DIFF_ANALYSIS_INDEX_UNIQUE_KEY_UID, DIFF_ANALYSIS_FIELD_AGENT_ID_UID, DIFF_ANALYSIS_FIELD_PROMPT_NAME_UID, DIFF_ANALYSIS_FIELD_PROMPT_VERSION_UID, DIFF_ANALYSIS_FIELD_POINTS_UID, DIFF_ANALYSIS_FIELD_UNIQUE_KEY_UID, DIFF_ANALYSIS_OBJECT_UID, agentRecord, SUPPORT_KIT_SETTINGS_FIELDS, MissingPromptError, validateSettings, settingsToProfile, buildPromptsTable, draftPromptRefFor, assertTransition, openTicketKeyFor, act, initialState, applyOutcomeTags, listCategories, resolveDraftAgent, runTicket, toCategoryReferential, toAgent, draftRebinder, resolvePromptName, isGeneratedResponseStatus, isInvalidatableStatus, DEFAULT_LLM_PROVIDER, toCategoryGroup, toCategory, toGeneratedResponse, NODE_NAMES, reclaimStalledSend, applySignature, isEvaluationVerdict, requiresFollowup, computeWordDiff, findCategoryByTag, isWhatsappTicket, hasCustomerAttachment, isTicketClosed, toDecisionOrigin, isConversationOver, isFallbackClassification, hasNoDraftNode, isWhatsappChevronNote, isCustomerTurnWithWords } from './chunk-LXHPPWPM.js';
|
|
2
|
+
export { AGENT_GUARDRAILS, AGENT_STATUSES, AGENT_TOOLS, ATTACHMENT_MARKER_ONLY, CANDIDATE_MIN_LENGTH, DECISION_ORIGINS, DEFAULT_CHANNEL_PROMPT_EMAIL, DEFAULT_CHANNEL_PROMPT_WHATSAPP, DEFAULT_DECISION_ORIGIN, DEFAULT_LLM_PROVIDER, DEFAULT_PROFILE_KEY, DEFAULT_WHATSAPP_MODE, EVALUATION_VERDICTS, GENERATED_RESPONSE_STATUSES, InvalidStatusTransitionError, MissingPromptError, NODE_NAMES, ORIGIN_DESCRIPTION, OUTCOMES, PROMPT_SLOTS, REASONING_MAX_LEN, STOP_PHRASES, SUPPORT_KIT_SETTINGS_FIELDS, UNCERTAINTY_MARKERS, WHATSAPP_MODES, WHATSAPP_NOTE_CHEVRON, agentRecord, assertTransition, canTransition, channelPreGates, firstCustomerMessage, guardrailBucket, hasCustomerAttachment, initialState, isAutoSendEligible, isAutomatedSenderEmail, isAutomatedSenderTicket, isCustomerTurnWithWords, isDecisionOrigin, isEvaluationVerdict, isGeneratedResponseStatus, isJudgemeConversation, isJudgemeTicket, isOutcome, isSendable, isSendableVerdict, isTerminalStatus, isTicketClosed, isWhatsappChevronNote, isWhatsappTicket, lastCustomerMessage, needsRevision, openTicketKeyFor, reclaimStalledSend, requiresFollowup, resolvePromptName, runGuardrails, runTicket, settingsToProfile, stopOptOut, toDecisionOrigin, validateSettings, verifyReply, whatsappModeFromLegacyBoolean } from './chunk-LXHPPWPM.js';
|
|
3
3
|
import { FieldType, APPROVAL_DECIDED_EVENT, AppApiError } from '@apotech-os/app-kit';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
|
|
@@ -738,6 +738,14 @@ function buildGeneratedResponseRecord(slug) {
|
|
|
738
738
|
description: "When status became 'sending' \u2014 the sweep's staleness clock (\xA73.5).",
|
|
739
739
|
isNullable: true
|
|
740
740
|
},
|
|
741
|
+
{
|
|
742
|
+
universalIdentifier: GENERATED_RESPONSE_FIELD_RUN_ID_UID,
|
|
743
|
+
name: "runId",
|
|
744
|
+
type: FieldType.TEXT,
|
|
745
|
+
label: "Run id",
|
|
746
|
+
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.",
|
|
747
|
+
isNullable: true
|
|
748
|
+
},
|
|
741
749
|
{
|
|
742
750
|
universalIdentifier: GENERATED_RESPONSE_FIELD_ORIGIN_UID,
|
|
743
751
|
name: "origin",
|
|
@@ -1651,21 +1659,21 @@ async function finalizeNonSent(ctx, id, ticketId, toStatus, extra) {
|
|
|
1651
1659
|
throw err;
|
|
1652
1660
|
}
|
|
1653
1661
|
}
|
|
1654
|
-
async function respondToPendingResponse(ctx, config, recordId) {
|
|
1662
|
+
async function respondToPendingResponse(ctx, config, recordId, options = {}) {
|
|
1655
1663
|
const record = await getOptional(ctx, "generated-response", recordId);
|
|
1656
1664
|
if (!record) {
|
|
1657
1665
|
ctx.logger.info(`respond: generated-response ${recordId} no longer exists, skipping`);
|
|
1658
|
-
return;
|
|
1666
|
+
return null;
|
|
1659
1667
|
}
|
|
1660
1668
|
const data = record.data;
|
|
1661
1669
|
if (data.status !== "pending") {
|
|
1662
1670
|
ctx.logger.info(`respond: generated-response ${recordId} is not pending (status="${String(data.status)}"), skipping \u2014 already handled by another worker`);
|
|
1663
|
-
return;
|
|
1671
|
+
return null;
|
|
1664
1672
|
}
|
|
1665
1673
|
const settings = await ctx.api.settings.get();
|
|
1666
1674
|
if (validateSettings(settings).length > 0) {
|
|
1667
1675
|
ctx.logger.info("respond: settings invalid, skipping");
|
|
1668
|
-
return;
|
|
1676
|
+
return null;
|
|
1669
1677
|
}
|
|
1670
1678
|
const ticketId = data.ticketId;
|
|
1671
1679
|
const ref = { id: ticketId, channel: "gorgias" };
|
|
@@ -1673,7 +1681,7 @@ async function respondToPendingResponse(ctx, config, recordId) {
|
|
|
1673
1681
|
if (!decision) {
|
|
1674
1682
|
ctx.logger.error(`respond: generated-response ${recordId} has no resolvable triage-decision, marking failed`);
|
|
1675
1683
|
await finalizeNonSent(ctx, recordId, ticketId, "failed", { error: "triage-decision not found" });
|
|
1676
|
-
return;
|
|
1684
|
+
return null;
|
|
1677
1685
|
}
|
|
1678
1686
|
const classification = classificationFromDecision(decision);
|
|
1679
1687
|
const escalated = decision.data.escalated === true;
|
|
@@ -1686,7 +1694,8 @@ async function respondToPendingResponse(ctx, config, recordId) {
|
|
|
1686
1694
|
settingsToProfile(settings, buildPromptsTable(config, draftPromptRefFor(agent, config), settings.nodes)),
|
|
1687
1695
|
origin
|
|
1688
1696
|
);
|
|
1689
|
-
const
|
|
1697
|
+
const testRun = options.testRun === true;
|
|
1698
|
+
const dryRun = settings.dryRun === true || testRun;
|
|
1690
1699
|
const trace = { sessionId: ticketId, tags: [`app:${config.slug}`] };
|
|
1691
1700
|
const ports = dryRun ? withRecordingWritePorts(buildTicketPorts(ctx, trace), ctx.api) : buildTicketPorts(ctx, trace);
|
|
1692
1701
|
const { clock } = ports;
|
|
@@ -1740,26 +1749,30 @@ async function respondToPendingResponse(ctx, config, recordId) {
|
|
|
1740
1749
|
// sent reply and a held one are read by the same timeline.
|
|
1741
1750
|
tracedInput: toTracedInput(result.draft?.messages ?? []),
|
|
1742
1751
|
verdict: result.verdict ?? null,
|
|
1743
|
-
|
|
1744
|
-
|
|
1752
|
+
// Omitted on a test run — see `RespondOptions.testRun`, consequence THREE.
|
|
1753
|
+
...testRun ? {} : {
|
|
1754
|
+
generatedMessageCount: conversationSnapshot.messageCount,
|
|
1755
|
+
generatedLastMessageAt: conversationSnapshot.lastMessageAt
|
|
1756
|
+
},
|
|
1745
1757
|
...attributionFields(result.draft?.attribution)
|
|
1746
1758
|
};
|
|
1759
|
+
const restingStatus = testRun ? "test_draft" : "ready";
|
|
1747
1760
|
switch (result.outcome) {
|
|
1748
1761
|
case "sent":
|
|
1749
1762
|
if (dryRun) {
|
|
1750
|
-
await finalizeNonSent(ctx, recordId, ticketId,
|
|
1751
|
-
return;
|
|
1763
|
+
await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
1764
|
+
return result.outcome;
|
|
1752
1765
|
}
|
|
1753
|
-
return;
|
|
1766
|
+
return result.outcome;
|
|
1754
1767
|
case "ready":
|
|
1755
1768
|
case "guardrail_hold":
|
|
1756
|
-
await finalizeNonSent(ctx, recordId, ticketId,
|
|
1757
|
-
return;
|
|
1769
|
+
await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
1770
|
+
return result.outcome;
|
|
1758
1771
|
case "needs_human":
|
|
1759
|
-
await finalizeNonSent(ctx, recordId, ticketId,
|
|
1760
|
-
return;
|
|
1772
|
+
await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
1773
|
+
return result.outcome;
|
|
1761
1774
|
case "awaiting_approval": {
|
|
1762
|
-
const persisted = await finalizeNonSent(ctx, recordId, ticketId,
|
|
1775
|
+
const persisted = await finalizeNonSent(ctx, recordId, ticketId, restingStatus, draftExtra);
|
|
1763
1776
|
if (persisted && !dryRun) {
|
|
1764
1777
|
await ctx.api.approvals.request({
|
|
1765
1778
|
key: buildApprovalKey(recordId),
|
|
@@ -1767,18 +1780,19 @@ async function respondToPendingResponse(ctx, config, recordId) {
|
|
|
1767
1780
|
entityRef: { appSlug: config.slug, objectKey: "generated-response", id: recordId }
|
|
1768
1781
|
});
|
|
1769
1782
|
}
|
|
1770
|
-
return;
|
|
1783
|
+
return result.outcome;
|
|
1771
1784
|
}
|
|
1772
1785
|
case "escalated":
|
|
1773
1786
|
case "triaged_only":
|
|
1774
1787
|
case "no_reply_needed":
|
|
1775
|
-
await finalizeNonSent(ctx, recordId, ticketId, "no_reply_needed", draftExtra);
|
|
1776
|
-
return;
|
|
1788
|
+
await finalizeNonSent(ctx, recordId, ticketId, testRun ? restingStatus : "no_reply_needed", draftExtra);
|
|
1789
|
+
return result.outcome;
|
|
1777
1790
|
case "failed":
|
|
1778
1791
|
await finalizeNonSent(ctx, recordId, ticketId, "failed", { ...draftExtra, error: "runTicket outcome: failed" });
|
|
1779
|
-
return;
|
|
1792
|
+
return result.outcome;
|
|
1780
1793
|
default:
|
|
1781
1794
|
ctx.logger.error(`respond: generated-response ${recordId} resumed run ended with no outcome`);
|
|
1795
|
+
return null;
|
|
1782
1796
|
}
|
|
1783
1797
|
}
|
|
1784
1798
|
async function transitionGeneratedResponse(api, params) {
|
|
@@ -4044,14 +4058,19 @@ function skippedFollowupGates(gates) {
|
|
|
4044
4058
|
detail: "Non \xE9valu\xE9 : un gate pr\xE9c\xE9dent a arr\xEAt\xE9 le traitement."
|
|
4045
4059
|
}));
|
|
4046
4060
|
}
|
|
4061
|
+
function completeFollowupLadder(results) {
|
|
4062
|
+
const evaluated = new Set(results.map((result) => result.gate));
|
|
4063
|
+
const missing = ALL_FOLLOWUP_GATES.filter((gate) => !evaluated.has(gate));
|
|
4064
|
+
return missing.length === 0 ? results : [...results, ...skippedFollowupGates(missing)];
|
|
4065
|
+
}
|
|
4047
4066
|
var FRESH_READ_GATES = ["G5", "G6", "G7", "G8"];
|
|
4048
4067
|
var ALL_FOLLOWUP_GATES = ["G1", "G2", ...FRESH_READ_GATES];
|
|
4049
4068
|
function evaluateTicketGates(input) {
|
|
4050
|
-
const { settings, tags, categories, conversation, anchor } = input;
|
|
4069
|
+
const { settings, tags, categories, conversation, anchor, ignoreCategoryOptIn = false } = input;
|
|
4051
4070
|
const trace = newTrace(FRESH_READ_GATES);
|
|
4052
4071
|
trace.record(scopeTagOnTicket(settings, tags));
|
|
4053
4072
|
trace.record(noHumanTakeover(settings, tags));
|
|
4054
|
-
const match = trace.record(categoryGate(categories, tags));
|
|
4073
|
+
const match = trace.record(categoryGate(categories, tags, ignoreCategoryOptIn));
|
|
4055
4074
|
if (match) trace.category = match;
|
|
4056
4075
|
trace.record(newCustomerMessage(conversation, anchor));
|
|
4057
4076
|
return trace.done();
|
|
@@ -4068,7 +4087,7 @@ function evaluatePayloadGates(input) {
|
|
|
4068
4087
|
} else {
|
|
4069
4088
|
trace.record(scopeTagOnTicket(settings, tags));
|
|
4070
4089
|
trace.record(noHumanTakeover(settings, tags));
|
|
4071
|
-
trace.record(
|
|
4090
|
+
trace.record(anyCategoryMatch(categories, tags));
|
|
4072
4091
|
}
|
|
4073
4092
|
trace.record(payloadNewCustomerMessage(body, anchor));
|
|
4074
4093
|
return trace.done();
|
|
@@ -4081,25 +4100,37 @@ function noHumanTakeover(settings, tags) {
|
|
|
4081
4100
|
const present = humanTakeoverTags(settings).filter((tag) => tags.includes(tag));
|
|
4082
4101
|
return present.length === 0 ? passed("G6", "Aucun tag de reprise humaine sur le ticket.") : stopped("G6", `Un humain a repris le fil (tag ${present.join(", ")}) : aucune r\xE9ponse automatique.`);
|
|
4083
4102
|
}
|
|
4084
|
-
function categoryGate(categories, tags) {
|
|
4085
|
-
const
|
|
4086
|
-
if (
|
|
4087
|
-
const
|
|
4088
|
-
if (
|
|
4089
|
-
|
|
4090
|
-
}
|
|
4091
|
-
|
|
4092
|
-
|
|
4103
|
+
function categoryGate(categories, tags, ignoreOptIn) {
|
|
4104
|
+
const matches = matchingCategories(categories, tags);
|
|
4105
|
+
if (matches.length === 0) return noMatchingCategory();
|
|
4106
|
+
const eligible = matches.filter((category2) => (ignoreOptIn || category2.followupFastResponseEnabled) && category2.agentId).sort((a, b) => a.order - b.order || a.id.localeCompare(b.id));
|
|
4107
|
+
if (eligible.length === 0) return noEligibleCategory(matches, ignoreOptIn);
|
|
4108
|
+
const category = eligible[0];
|
|
4109
|
+
const detail = matches.length === 1 ? `Cat\xE9gorie \xAB ${category.name} \xBB (tag \xAB ${category.tagName} \xBB).` : `Cat\xE9gorie \xAB ${category.name} \xBB (tag \xAB ${category.tagName} \xBB), retenue parmi ${matches.length} cat\xE9gories correspondantes (${tagList(matches)}).`;
|
|
4110
|
+
return { ...passed("G7", detail), category };
|
|
4111
|
+
}
|
|
4112
|
+
function noEligibleCategory(matches, ignoreOptIn) {
|
|
4113
|
+
if (ignoreOptIn) {
|
|
4114
|
+
return matches.length > 1 ? stopped("G7", `Aucune des ${matches.length} cat\xE9gories correspondantes (${tagList(matches)}) n\u2019a d\u2019agent : personne pour r\xE9diger.`) : stopped("G7", `La cat\xE9gorie \xAB ${matches[0].name} \xBB n\u2019a aucun agent : personne pour r\xE9diger.`);
|
|
4115
|
+
}
|
|
4116
|
+
if (matches.length > 1) {
|
|
4117
|
+
return stopped(
|
|
4118
|
+
"G7",
|
|
4119
|
+
`Aucune des ${matches.length} cat\xE9gories correspondantes (${tagList(matches)}) n\u2019a activ\xE9 les r\xE9ponses aux messages suivants avec un agent pour r\xE9diger.`
|
|
4120
|
+
);
|
|
4093
4121
|
}
|
|
4094
|
-
|
|
4122
|
+
const category = matches[0];
|
|
4123
|
+
return category.followupFastResponseEnabled ? stopped("G7", `La cat\xE9gorie \xAB ${category.name} \xBB n\u2019a aucun agent : personne pour r\xE9diger.`) : stopped("G7", `La cat\xE9gorie \xAB ${category.name} \xBB n\u2019a pas activ\xE9 les r\xE9ponses aux messages suivants.`);
|
|
4095
4124
|
}
|
|
4096
|
-
function
|
|
4125
|
+
function tagList(categories) {
|
|
4126
|
+
return categories.map((category) => category.tagName).join(", ");
|
|
4127
|
+
}
|
|
4128
|
+
function anyCategoryMatch(categories, tags) {
|
|
4097
4129
|
const matches = matchingCategories(categories, tags);
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
);
|
|
4130
|
+
return matches.length === 0 ? noMatchingCategory() : passed("G7", `Cat\xE9gorie \xAB ${matches[0].name} \xBB.`);
|
|
4131
|
+
}
|
|
4132
|
+
function noMatchingCategory() {
|
|
4133
|
+
return stopped("G7", "Aucune cat\xE9gorie ne correspond \xE0 un tag du ticket : la d\xE9cision de triage est illisible.");
|
|
4103
4134
|
}
|
|
4104
4135
|
function matchingCategories(categories, tags) {
|
|
4105
4136
|
return categories.filter((category) => tags.includes(category.tagName));
|
|
@@ -4293,54 +4324,83 @@ function createGorgiasWebhookHandler(config) {
|
|
|
4293
4324
|
function createGorgiasFollowupRunHandler(config) {
|
|
4294
4325
|
return (ctx, payload) => {
|
|
4295
4326
|
const event = payload ?? {};
|
|
4296
|
-
return executeFollowupRun(ctx, config, event.body, event.runId ?? null
|
|
4327
|
+
return executeFollowupRun(ctx, config, event.body, event.runId ?? null, {
|
|
4328
|
+
generateOnly: event.generateOnly === true
|
|
4329
|
+
});
|
|
4297
4330
|
};
|
|
4298
4331
|
}
|
|
4299
|
-
async function executeFollowupRun(ctx, config, rawBody, existingRunId) {
|
|
4332
|
+
async function executeFollowupRun(ctx, config, rawBody, existingRunId, options = {}) {
|
|
4300
4333
|
const run = { id: existingRunId };
|
|
4301
4334
|
try {
|
|
4302
|
-
const result = await runFollowupPass(ctx, config, rawBody, run);
|
|
4335
|
+
const result = await runFollowupPass(ctx, config, rawBody, run, options.generateOnly === true);
|
|
4303
4336
|
if (run.id) await ctx.api.runs.succeed(run.id, { ...result });
|
|
4304
4337
|
} catch (err) {
|
|
4305
4338
|
if (run.id) await ctx.api.runs.fail(run.id, { message: err instanceof Error ? err.message : String(err) });
|
|
4306
4339
|
throw err;
|
|
4307
4340
|
}
|
|
4308
4341
|
}
|
|
4309
|
-
async function runFollowupPass(ctx, config, rawBody, run) {
|
|
4342
|
+
async function runFollowupPass(ctx, config, rawBody, run, generateOnly) {
|
|
4310
4343
|
const body = parseFollowupWebhookBody(rawBody);
|
|
4344
|
+
const ladder = [];
|
|
4311
4345
|
const ticketIdGate = evaluateTicketIdGate(body.ticketId);
|
|
4312
|
-
|
|
4346
|
+
ladder.push(ticketIdGate);
|
|
4347
|
+
if (!body.ticketId) return stop(ctx, null, ticketIdGate.gate, ticketIdGate.detail, ladder);
|
|
4313
4348
|
const ticketId = body.ticketId;
|
|
4314
4349
|
const settings = await ctx.api.settings.get();
|
|
4315
4350
|
const issues = validateSettings(settings);
|
|
4316
4351
|
if (issues.length > 0) {
|
|
4317
|
-
return stop(ctx, ticketId, "settings", `r\xE9glages invalides : ${issues.map((issue) => issue.message).join(" ")}
|
|
4352
|
+
return stop(ctx, ticketId, "settings", `r\xE9glages invalides : ${issues.map((issue) => issue.message).join(" ")}`, ladder);
|
|
4318
4353
|
}
|
|
4319
4354
|
const scope = evaluateScopeGate(settings);
|
|
4320
|
-
|
|
4355
|
+
ladder.push(scope);
|
|
4356
|
+
if (scope.status === "stopped") return stopAt(ctx, ticketId, scope, ladder);
|
|
4321
4357
|
const { anchor, hasOpenResponse } = await readFollowupAnchor(ctx, ticketId);
|
|
4322
4358
|
const categories = await listCategories(ctx.api);
|
|
4323
4359
|
const preGates = evaluatePayloadGates({ settings, body, categories, anchor });
|
|
4324
|
-
if (preGates.stop)
|
|
4360
|
+
if (preGates.stop) {
|
|
4361
|
+
ladder.push(...preGates.results);
|
|
4362
|
+
return stopAt(ctx, ticketId, preGates.stop, ladder, "pr\xE9-gate");
|
|
4363
|
+
}
|
|
4325
4364
|
const ref = { id: ticketId, channel: "gorgias" };
|
|
4326
4365
|
const ticket = await ctx.api.integrations.run("gorgias", "getTicketWithContext", { ticketId });
|
|
4327
4366
|
const raw = ticket?.ticket ?? {};
|
|
4328
4367
|
const conversation = toConversation(ref, raw, ticket?.context ?? { messages: [], customerContext: null });
|
|
4329
|
-
const gates = evaluateTicketGates({
|
|
4368
|
+
const gates = evaluateTicketGates({
|
|
4369
|
+
settings,
|
|
4370
|
+
tags: ticketTagNames(raw),
|
|
4371
|
+
categories,
|
|
4372
|
+
conversation,
|
|
4373
|
+
anchor,
|
|
4374
|
+
ignoreCategoryOptIn: generateOnly
|
|
4375
|
+
});
|
|
4376
|
+
ladder.push(...gates.results);
|
|
4330
4377
|
if (gates.stop || !gates.category) {
|
|
4331
|
-
return stopAt(ctx, ticketId, gates.stop ?? unresolvedCategory());
|
|
4378
|
+
return stopAt(ctx, ticketId, gates.stop ?? unresolvedCategory(), ladder);
|
|
4332
4379
|
}
|
|
4333
4380
|
const category = gates.category;
|
|
4334
|
-
if (hasOpenResponse) return stop(ctx, ticketId, "G9", "une r\xE9ponse est d\xE9j\xE0 ouverte sur ce ticket");
|
|
4381
|
+
if (hasOpenResponse) return stop(ctx, ticketId, "G9", "une r\xE9ponse est d\xE9j\xE0 ouverte sur ce ticket", ladder);
|
|
4335
4382
|
run.id ??= (await ctx.api.runs.start({
|
|
4336
4383
|
kind: FOLLOWUP_RUN_KIND,
|
|
4337
4384
|
message: `Message suivant \u2014 ticket ${ticketId}`,
|
|
4338
|
-
metadata: { ticketId, categoryTag: category.tagName, channel: body.channel }
|
|
4385
|
+
metadata: { ticketId, categoryTag: category.tagName, channel: body.channel, generateOnly }
|
|
4339
4386
|
})).id;
|
|
4340
4387
|
const created = await openFollowupResponse(ctx, { ticketId, category, conversation, settings, runId: run.id });
|
|
4341
|
-
if (!created) return stop(ctx, ticketId, "G9", "une autre ex\xE9cution a ouvert la r\xE9ponse en premier");
|
|
4342
|
-
await respondToPendingResponse(ctx, config, created.id);
|
|
4343
|
-
return {
|
|
4388
|
+
if (!created) return stop(ctx, ticketId, "G9", "une autre ex\xE9cution a ouvert la r\xE9ponse en premier", ladder);
|
|
4389
|
+
const outcome = await respondToPendingResponse(ctx, config, created.id, { testRun: generateOnly });
|
|
4390
|
+
return {
|
|
4391
|
+
ticketId,
|
|
4392
|
+
stoppedAt: null,
|
|
4393
|
+
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)`,
|
|
4394
|
+
gates: completeFollowupLadder(ladder),
|
|
4395
|
+
categoryId: category.id,
|
|
4396
|
+
categoryName: category.name,
|
|
4397
|
+
// Off the ROW, not off the category: `openFollowupResponse` resolves a
|
|
4398
|
+
// default agent when the category names none, and the row records who
|
|
4399
|
+
// actually wrote.
|
|
4400
|
+
agentId: created.data.agentId ?? null,
|
|
4401
|
+
outcome,
|
|
4402
|
+
responseId: created.id
|
|
4403
|
+
};
|
|
4344
4404
|
}
|
|
4345
4405
|
async function readFollowupAnchor(ctx, ticketId) {
|
|
4346
4406
|
const page = await ctx.api.list("generated-response", { filter: { ticketId }, limit: ANCHOR_LOOKUP_LIMIT });
|
|
@@ -4431,7 +4491,8 @@ async function openFollowupResponse(ctx, input) {
|
|
|
4431
4491
|
servedTo: [],
|
|
4432
4492
|
servedCount: 0,
|
|
4433
4493
|
followupRequired: false,
|
|
4434
|
-
origin: "followup"
|
|
4494
|
+
origin: "followup",
|
|
4495
|
+
runId
|
|
4435
4496
|
});
|
|
4436
4497
|
} catch (err) {
|
|
4437
4498
|
if (err instanceof AppApiError && err.status === 409) return null;
|
|
@@ -4446,85 +4507,23 @@ function unresolvedCategory() {
|
|
|
4446
4507
|
detail: "Aucune cat\xE9gorie r\xE9solue."
|
|
4447
4508
|
};
|
|
4448
4509
|
}
|
|
4449
|
-
function stopAt(ctx, ticketId, result, kind = "gate") {
|
|
4450
|
-
return stop(ctx, ticketId, `${result.gate}${kind === "gate" ? "" : ` (${kind})`}`, result.detail);
|
|
4510
|
+
function stopAt(ctx, ticketId, result, ladder, kind = "gate") {
|
|
4511
|
+
return stop(ctx, ticketId, `${result.gate}${kind === "gate" ? "" : ` (${kind})`}`, result.detail, ladder);
|
|
4451
4512
|
}
|
|
4452
|
-
function stop(ctx, ticketId, gate, reason) {
|
|
4513
|
+
function stop(ctx, ticketId, gate, reason, ladder) {
|
|
4453
4514
|
ctx.logger.info(`gorgias-webhook: stop at ${gate} for ticket ${ticketId ?? "?"} \u2014 ${reason}`);
|
|
4454
|
-
return { ticketId, stoppedAt: gate, reason };
|
|
4455
|
-
}
|
|
4456
|
-
|
|
4457
|
-
// src/functions/setup-gorgias-webhook.ts
|
|
4458
|
-
var GORGIAS_CALLBACK_APP_KEY_VARIABLE = "GORGIAS_CALLBACK_APP_KEY";
|
|
4459
|
-
var APP_API_KEY_PREFIX = "wopilo_app_";
|
|
4460
|
-
var FOLLOWUP_WEBHOOK_FORM = {
|
|
4461
|
-
ticket_id: "{{ticket.id}}",
|
|
4462
|
-
channel: "{{ticket.channel}}",
|
|
4463
|
-
last_message_datetime: "{{ticket.last_message_datetime}}",
|
|
4464
|
-
status: "{{ticket.status}}",
|
|
4465
|
-
tags: "{{ticket.tags}}",
|
|
4466
|
-
last_message_from_agent: "{{ticket.messages[-1].from_agent}}",
|
|
4467
|
-
last_message_public: "{{ticket.messages[-1].public}}"
|
|
4468
|
-
};
|
|
4469
|
-
var FOLLOWUP_WEBHOOK_TRIGGERS = { "ticket-message-created": true };
|
|
4470
|
-
function followupIntegrationName(slug) {
|
|
4471
|
-
return `Wopilo \u2014 R\xE9ponses aux messages suivants (${slug})`;
|
|
4472
|
-
}
|
|
4473
|
-
function buildSetupGorgiasWebhookFunctionDef(config) {
|
|
4474
4515
|
return {
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
const key = readCallbackKey(ctx);
|
|
4485
|
-
const name = followupIntegrationName(config.slug);
|
|
4486
|
-
const url = `${publicOrigin(ctx)}/api/s/${config.slug}/gorgias/webhook`;
|
|
4487
|
-
const result = await ctx.api.integrations.run("gorgias", "upsertHttpIntegration", {
|
|
4488
|
-
name,
|
|
4489
|
-
description: "Rappelle Wopilo \xE0 chaque nouveau message de ticket, pour r\xE9pondre aux messages suivants.",
|
|
4490
|
-
url,
|
|
4491
|
-
method: "POST",
|
|
4492
|
-
headers: { Authorization: `Bearer ${key}` },
|
|
4493
|
-
form: FOLLOWUP_WEBHOOK_FORM,
|
|
4494
|
-
triggers: FOLLOWUP_WEBHOOK_TRIGGERS
|
|
4495
|
-
});
|
|
4496
|
-
ctx.logger.info(`setup-gorgias-webhook: int\xE9gration \xAB ${name} \xBB pos\xE9e sur ${url}`);
|
|
4497
|
-
return {
|
|
4498
|
-
integrationId: String(result?.id ?? ""),
|
|
4499
|
-
created: result?.created === true,
|
|
4500
|
-
name,
|
|
4501
|
-
url
|
|
4516
|
+
ticketId,
|
|
4517
|
+
stoppedAt: gate,
|
|
4518
|
+
reason,
|
|
4519
|
+
gates: completeFollowupLadder(ladder),
|
|
4520
|
+
categoryId: null,
|
|
4521
|
+
categoryName: null,
|
|
4522
|
+
agentId: null,
|
|
4523
|
+
outcome: null,
|
|
4524
|
+
responseId: null
|
|
4502
4525
|
};
|
|
4503
4526
|
}
|
|
4504
|
-
function readCallbackKey(ctx) {
|
|
4505
|
-
const raw = ctx.variables[GORGIAS_CALLBACK_APP_KEY_VARIABLE];
|
|
4506
|
-
const key = typeof raw === "string" ? raw.trim() : "";
|
|
4507
|
-
if (!key) {
|
|
4508
|
-
throw new ctx.NonRetriableError(
|
|
4509
|
-
`La variable serveur ${GORGIAS_CALLBACK_APP_KEY_VARIABLE} n'est pas renseign\xE9e : Gorgias n'aurait aucun moyen de s'authentifier aupr\xE8s de cette app.`
|
|
4510
|
-
);
|
|
4511
|
-
}
|
|
4512
|
-
if (!key.startsWith(APP_API_KEY_PREFIX)) {
|
|
4513
|
-
throw new ctx.NonRetriableError(
|
|
4514
|
-
`La variable serveur ${GORGIAS_CALLBACK_APP_KEY_VARIABLE} ne contient pas une cl\xE9 d'application : elle doit commencer par \xAB ${APP_API_KEY_PREFIX} \xBB.`
|
|
4515
|
-
);
|
|
4516
|
-
}
|
|
4517
|
-
return key;
|
|
4518
|
-
}
|
|
4519
|
-
function publicOrigin(ctx) {
|
|
4520
|
-
const base = process.env.PUBLIC_BASE_URL?.trim().replace(/\/+$/, "");
|
|
4521
|
-
if (!base) {
|
|
4522
|
-
throw new ctx.NonRetriableError(
|
|
4523
|
-
"La variable d'instance PUBLIC_BASE_URL n'est pas d\xE9finie : impossible de construire une URL de rappel que Gorgias puisse joindre."
|
|
4524
|
-
);
|
|
4525
|
-
}
|
|
4526
|
-
return base;
|
|
4527
|
-
}
|
|
4528
4527
|
function buildTestGorgiasWebhookFunctionDef(config) {
|
|
4529
4528
|
return {
|
|
4530
4529
|
universalIdentifier: identifierFor(config, "test-gorgias-webhook"),
|
|
@@ -4544,7 +4543,7 @@ function buildTestGorgiasWebhookFunctionDef(config) {
|
|
|
4544
4543
|
name: "mode",
|
|
4545
4544
|
type: FieldType.TEXT,
|
|
4546
4545
|
label: "Mode",
|
|
4547
|
-
description: "'diagnostic' (d\xE9faut) \xE9value les gates sans aucun effet de bord ; 'run' d\xE9clenche le vrai traitement, envoi compris si la cat\xE9gorie est en auto.",
|
|
4546
|
+
description: "'diagnostic' (d\xE9faut) \xE9value les gates sans aucun effet de bord ; 'generate' g\xE9n\xE8re la r\xE9ponse sans jamais l'envoyer, m\xEAme si la cat\xE9gorie n'a pas opt\xE9 ; 'run' d\xE9clenche le vrai traitement, envoi compris si la cat\xE9gorie est en auto.",
|
|
4548
4547
|
isNullable: true
|
|
4549
4548
|
}
|
|
4550
4549
|
]
|
|
@@ -4556,12 +4555,10 @@ function createTestGorgiasWebhookHandler(_config) {
|
|
|
4556
4555
|
var NUMERIC2 = /^\d+$/;
|
|
4557
4556
|
async function testGorgiasWebhookHandler(ctx, input) {
|
|
4558
4557
|
const ticketId = typeof input.ticketId === "string" && NUMERIC2.test(input.ticketId.trim()) ? input.ticketId.trim() : null;
|
|
4559
|
-
const mode = input.mode === "run" ? "run" : "diagnostic";
|
|
4560
|
-
if (mode === "
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
}
|
|
4564
|
-
return diagnose(ctx, ticketId);
|
|
4558
|
+
const mode = input.mode === "run" ? "run" : input.mode === "generate" ? "generate" : "diagnostic";
|
|
4559
|
+
if (mode === "diagnostic") return diagnose(ctx, ticketId);
|
|
4560
|
+
if (!ticketId) throw new ctx.NonRetriableError("L'identifiant du ticket doit \xEAtre une suite de chiffres.");
|
|
4561
|
+
return triggerRun(ctx, ticketId, mode);
|
|
4565
4562
|
}
|
|
4566
4563
|
async function diagnose(ctx, ticketId) {
|
|
4567
4564
|
const gates = [];
|
|
@@ -4587,9 +4584,7 @@ async function diagnose(ctx, ticketId) {
|
|
|
4587
4584
|
return finish(gates, ticketId);
|
|
4588
4585
|
}
|
|
4589
4586
|
function finish(gates, ticketId) {
|
|
4590
|
-
const
|
|
4591
|
-
const missing = ALL_FOLLOWUP_GATES.filter((gate) => !evaluated.has(gate));
|
|
4592
|
-
const full = [...gates, ...skippedFollowupGates(missing)];
|
|
4587
|
+
const full = completeFollowupLadder(gates);
|
|
4593
4588
|
return {
|
|
4594
4589
|
mode: "diagnostic",
|
|
4595
4590
|
ticketId,
|
|
@@ -4597,23 +4592,25 @@ function finish(gates, ticketId) {
|
|
|
4597
4592
|
gates: full
|
|
4598
4593
|
};
|
|
4599
4594
|
}
|
|
4600
|
-
async function
|
|
4595
|
+
async function triggerRun(ctx, ticketId, mode) {
|
|
4596
|
+
const generateOnly = mode === "generate";
|
|
4601
4597
|
const run = await ctx.api.runs.start({
|
|
4602
4598
|
kind: FOLLOWUP_RUN_KIND,
|
|
4603
|
-
message: `Test webhook \u2014 ticket ${ticketId}`,
|
|
4604
|
-
metadata: { ticketId, triggeredFrom: "test-gorgias-webhook" }
|
|
4599
|
+
message: generateOnly ? `Test webhook sans envoi \u2014 ticket ${ticketId}` : `Test webhook \u2014 ticket ${ticketId}`,
|
|
4600
|
+
metadata: { ticketId, triggeredFrom: "test-gorgias-webhook", generateOnly }
|
|
4605
4601
|
});
|
|
4606
4602
|
try {
|
|
4607
4603
|
await ctx.api.events.send(FOLLOWUP_RUN_REQUESTED_EVENT, {
|
|
4608
4604
|
_key: run.id,
|
|
4609
4605
|
runId: run.id,
|
|
4610
|
-
body: { ticket_id: ticketId }
|
|
4606
|
+
body: { ticket_id: ticketId },
|
|
4607
|
+
generateOnly
|
|
4611
4608
|
});
|
|
4612
4609
|
} catch (err) {
|
|
4613
4610
|
await ctx.api.runs.fail(run.id, { message: err instanceof Error ? err.message : String(err) });
|
|
4614
4611
|
throw err;
|
|
4615
4612
|
}
|
|
4616
|
-
return { mode
|
|
4613
|
+
return { mode, ticketId, runId: run.id };
|
|
4617
4614
|
}
|
|
4618
4615
|
|
|
4619
4616
|
// src/pages/manifest.ts
|
|
@@ -4639,24 +4636,9 @@ var SUPPORT_KIT_GORGIAS_SCOPES = [
|
|
|
4639
4636
|
"read_tickets",
|
|
4640
4637
|
"read_views",
|
|
4641
4638
|
"write_tags",
|
|
4642
|
-
"write_tickets"
|
|
4643
|
-
// What `upsertHttpIntegration` demands (its own `scopes`, in
|
|
4644
|
-
// `packages/gorgias-client/src/sidebar-widget.ts`). The name says "widgets"
|
|
4645
|
-
// because that action's sibling posts one; this kit posts no widget, only
|
|
4646
|
-
// the HTTP integration the same scope governs. Requesting it makes the
|
|
4647
|
-
// consent modal state, honestly, that the app may write an integration on
|
|
4648
|
-
// the account.
|
|
4649
|
-
"write_widgets"
|
|
4650
|
-
];
|
|
4651
|
-
var SUPPORT_KIT_SERVER_VARIABLES = [
|
|
4652
|
-
{
|
|
4653
|
-
universalIdentifier: "4dd02108-ba4c-441e-9ea3-ec86f8bf3a1f",
|
|
4654
|
-
name: GORGIAS_CALLBACK_APP_KEY_VARIABLE,
|
|
4655
|
-
description: "Cl\xE9 d'application (wopilo_app_\u2026) que Gorgias pr\xE9sente en rappelant la route des messages suivants. Saisie par app ; elle porte le r\xF4le manifeste complet de l'app (voir docs/app-platform/gorgias-callback-authentication.md \xA75).",
|
|
4656
|
-
type: "STRING",
|
|
4657
|
-
isRequired: false
|
|
4658
|
-
}
|
|
4639
|
+
"write_tickets"
|
|
4659
4640
|
];
|
|
4641
|
+
var SUPPORT_KIT_SERVER_VARIABLES = [];
|
|
4660
4642
|
var SUPPORT_KIT_INTEGRATIONS = [
|
|
4661
4643
|
{ provider: "gorgias", scopes: [...SUPPORT_KIT_GORGIAS_SCOPES] }
|
|
4662
4644
|
];
|
|
@@ -4767,11 +4749,6 @@ var FUNCTION_ASSEMBLY = [
|
|
|
4767
4749
|
build: buildGorgiasFollowupRunFunctionDef,
|
|
4768
4750
|
createHandler: createGorgiasFollowupRunHandler
|
|
4769
4751
|
},
|
|
4770
|
-
{
|
|
4771
|
-
key: "setup-gorgias-webhook",
|
|
4772
|
-
build: buildSetupGorgiasWebhookFunctionDef,
|
|
4773
|
-
createHandler: createSetupGorgiasWebhookHandler
|
|
4774
|
-
},
|
|
4775
4752
|
{
|
|
4776
4753
|
key: "test-gorgias-webhook",
|
|
4777
4754
|
build: buildTestGorgiasWebhookFunctionDef,
|