@apotech-os/support-kit 3.4.0 → 4.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.d.cts CHANGED
@@ -105,67 +105,6 @@ interface Classification {
105
105
  conversationOver?: boolean;
106
106
  }
107
107
 
108
- /**
109
- * One tool invocation made while drafting, kept for provenance display and
110
- * audit — not replayed. `observation` is the tool's result as handed back
111
- * to the model, already serialised to text. Field names mirror
112
- * `ToolCallRequest` (`graph/ports.ts`) rather than a `tool`/`args` pair, so a
113
- * record can be built directly from the request it answers.
114
- */
115
- interface ToolCallRecord {
116
- name: string;
117
- arguments: Record<string, unknown>;
118
- observation: string;
119
- }
120
- /**
121
- * Langfuse attribution of the completion that produced the draft's text, and
122
- * of the prompt version that produced its system message (I17, §3.4's
123
- * `langfuseTraceId`/`langfuseObservationId`/`promptName`/`promptVersion`).
124
- *
125
- * Carried on the draft rather than read back off the LLM port afterwards: a
126
- * run makes several completions (a tool round, then the answer, then maybe a
127
- * revision) and only the one that actually wrote the served text is the one
128
- * the quality loop must score. Legacy convention, kept: the LAST completion
129
- * to produce text wins — a revised draft is attributed to `revise`, not to
130
- * the draft it replaced.
131
- */
132
- interface DraftAttribution {
133
- traceId: string | null;
134
- observationId: string | null;
135
- promptName: string | null;
136
- /** The version `PromptPort` actually served — `0` on the in-code fallback (§3.7 level 3). */
137
- promptVersion: number | null;
138
- }
139
- interface Draft {
140
- text: string;
141
- sources: ToolCallRecord[];
142
- /** True once `revise` has produced this text (at most one pass). */
143
- revised: boolean;
144
- /**
145
- * Absent when the text came from something other than a traced completion
146
- * (a fake gateway, tracing off, a draft rebuilt from a stored record) —
147
- * never a placeholder: an id that names no real generation is worse for
148
- * the quality loop than no id at all.
149
- */
150
- attribution?: DraftAttribution;
151
- }
152
-
153
- declare const EVALUATION_VERDICTS: readonly ["send", "send_and_escalate", "hold"];
154
- type EvaluationVerdict = (typeof EVALUATION_VERDICTS)[number];
155
- declare function isEvaluationVerdict(value: unknown): value is EvaluationVerdict;
156
- /** Verdicts whose reply may go out — the follow-up one included (spec §4.3). */
157
- declare function isSendableVerdict(verdict: EvaluationVerdict | null): boolean;
158
- /** True when the reply is sendable but owes the customer a human follow-up. */
159
- declare function requiresFollowup(verdict: EvaluationVerdict | null): boolean;
160
-
161
- interface Verdict {
162
- verdict: EvaluationVerdict | null;
163
- /** [0, 1]. */
164
- confidence: number | null;
165
- reason: string;
166
- status: 'success' | 'error';
167
- }
168
-
169
108
  type ActionDecision = 'auto' | 'needs_approval' | 'forbidden';
170
109
  interface ProposedAction {
171
110
  /** 'send_reply' | 'refund' | … — the write-side actions introduced in P3. */
@@ -176,13 +115,6 @@ interface ProposedAction {
176
115
  decision?: ActionDecision;
177
116
  }
178
117
 
179
- /**
180
- * Maps to the LLM provider's native reasoning-effort parameter. An invalid
181
- * (model, effort) pair is rejected at profile-load time, never silently
182
- * ignored — this type only carries the vocabulary, not the validation.
183
- */
184
- type ReasoningEffort = 'off' | 'low' | 'medium' | 'high';
185
-
186
118
  /**
187
119
  * The key set of the LLM nodes — exactly the steps a profile's `nodes` and
188
120
  * `prompts` carry a config for. Not every node runs on every ticket
@@ -212,6 +144,13 @@ interface NodeCost extends Usage {
212
144
  /** Per-node cost breakdown for one ticket run (I15). Only ran nodes are keyed. */
213
145
  type CostLedger = Partial<Record<NodeKey, NodeCost>>;
214
146
 
147
+ /**
148
+ * Maps to the LLM provider's native reasoning-effort parameter. An invalid
149
+ * (model, effort) pair is rejected at profile-load time, never silently
150
+ * ignored — this type only carries the vocabulary, not the validation.
151
+ */
152
+ type ReasoningEffort = 'off' | 'low' | 'medium' | 'high';
153
+
215
154
  /**
216
155
  * Key of the single tenant that exists before any second profile is created.
217
156
  * Named once here so every scoped collection shares one source of truth
@@ -410,33 +349,6 @@ interface AgentProfile {
410
349
  };
411
350
  }
412
351
 
413
- /**
414
- * Run budget: bounds a run in TOOL CALLS and TIME only, never in money —
415
- * cost is measured (`charge`, I15) and watched separately, not capped here.
416
- * Every method is a no-throw no-op past the allowance: exhausting the
417
- * budget must never fail a ticket (§6.3).
418
- */
419
- interface Budget {
420
- /** The run's deadline signal, forwarded unchanged to every LLM call. */
421
- signal: AbortSignal;
422
- consumeToolCall(): void;
423
- /** True once `maxToolCalls` is spent OR the run signal aborted. */
424
- exhausted(): boolean;
425
- /** Accumulates usage/cost for one node. Reasoning stays out of `output` (§6.3). */
426
- charge(node: NodeKey, usage: Usage, cost: {
427
- usd: number;
428
- pricingMissing: boolean;
429
- }): void;
430
- /** Per-node breakdown for the ticket's provenance trail. */
431
- ledger(): CostLedger;
432
- /** Whole-run total — the per-ticket cost watched downstream. */
433
- total(): NodeCost;
434
- }
435
- declare function createBudget({ signal, maxToolCalls }: {
436
- signal: AbortSignal;
437
- maxToolCalls: number;
438
- }): Budget;
439
-
440
352
  interface SourceDescriptor {
441
353
  viewOrTag: string;
442
354
  }
@@ -776,6 +688,124 @@ interface SimilarTicket {
776
688
  resolution?: string | null;
777
689
  }
778
690
 
691
+ /**
692
+ * One tool invocation made while drafting, kept for provenance display and
693
+ * audit — not replayed. `observation` is the tool's result as handed back
694
+ * to the model, already serialised to text. Field names mirror
695
+ * `ToolCallRequest` (`graph/ports.ts`) rather than a `tool`/`args` pair, so a
696
+ * record can be built directly from the request it answers.
697
+ */
698
+ interface ToolCallRecord {
699
+ name: string;
700
+ arguments: Record<string, unknown>;
701
+ observation: string;
702
+ }
703
+ /**
704
+ * Langfuse attribution of the completion that produced the draft's text, and
705
+ * of the prompt version that produced its system message (I17, §3.4's
706
+ * `langfuseTraceId`/`langfuseObservationId`/`promptName`/`promptVersion`).
707
+ *
708
+ * Carried on the draft rather than read back off the LLM port afterwards: a
709
+ * run makes several completions (a tool round, then the answer, then maybe a
710
+ * revision) and only the one that actually wrote the served text is the one
711
+ * the quality loop must score. Legacy convention, kept: the LAST completion
712
+ * to produce text wins — a revised draft is attributed to `revise`, not to
713
+ * the draft it replaced.
714
+ */
715
+ interface DraftAttribution {
716
+ traceId: string | null;
717
+ observationId: string | null;
718
+ promptName: string | null;
719
+ /** The version `PromptPort` actually served — `0` on the in-code fallback (§3.7 level 3). */
720
+ promptVersion: number | null;
721
+ }
722
+ interface Draft {
723
+ text: string;
724
+ sources: ToolCallRecord[];
725
+ /**
726
+ * The messages the drafting completion was GIVEN — the rendered system
727
+ * prompt first, then the customer's own turns. The only place either
728
+ * survives the run: the conversation is read live from Gorgias and thrown
729
+ * away, and the prompt is rendered from a Langfuse version that can move.
730
+ * `process-response` writes this to `generated-response.tracedInput`, which
731
+ * the ticket timeline reads for its "Reçu" and "Prompt envoyé" steps
732
+ * (spec-vue-tickets-unifiee-v1 §4.1).
733
+ *
734
+ * The ORIGINAL messages, not the conversation the tool loop grows: the tool
735
+ * rounds are already recorded, in a shape built for reading, on `sources`.
736
+ */
737
+ messages: ChatMessage[];
738
+ /** True once `revise` has produced this text (at most one pass). */
739
+ revised: boolean;
740
+ /**
741
+ * Absent when the text came from something other than a traced completion
742
+ * (a fake gateway, tracing off, a draft rebuilt from a stored record) —
743
+ * never a placeholder: an id that names no real generation is worse for
744
+ * the quality loop than no id at all.
745
+ */
746
+ attribution?: DraftAttribution;
747
+ }
748
+
749
+ declare const EVALUATION_VERDICTS: readonly ["send", "send_and_escalate", "hold"];
750
+ type EvaluationVerdict = (typeof EVALUATION_VERDICTS)[number];
751
+ declare function isEvaluationVerdict(value: unknown): value is EvaluationVerdict;
752
+ /** Verdicts whose reply may go out — the follow-up one included (spec §4.3). */
753
+ declare function isSendableVerdict(verdict: EvaluationVerdict | null): boolean;
754
+ /** True when the reply is sendable but owes the customer a human follow-up. */
755
+ declare function requiresFollowup(verdict: EvaluationVerdict | null): boolean;
756
+
757
+ interface Verdict {
758
+ verdict: EvaluationVerdict | null;
759
+ /** [0, 1]. */
760
+ confidence: number | null;
761
+ reason: string;
762
+ status: 'success' | 'error';
763
+ /**
764
+ * Langfuse observation of the JUDGING completion — `null` when the gateway
765
+ * traced nothing, or on a verdict written before this was captured.
766
+ *
767
+ * Lives here rather than on a record field of its own because
768
+ * `generated-response.langfuseObservationId` already holds the DRAFT's, and
769
+ * §3.4 freezes that record's columns: the "Trace évaluation" link built
770
+ * from it pointed at the generation, not the evaluation
771
+ * (spec-vue-tickets-unifiee-v1 §4.3). `verdict` is a JSON column, so
772
+ * carrying it inside costs no migration.
773
+ *
774
+ * OPTIONAL, not merely nullable: a verdict read back from a row written
775
+ * before this capture existed carries no such key at all, and every caller
776
+ * that builds a verdict by hand (the policy layer, the test bench) is
777
+ * describing a decision, not a traced call.
778
+ */
779
+ observationId?: string | null;
780
+ }
781
+
782
+ /**
783
+ * Run budget: bounds a run in TOOL CALLS and TIME only, never in money —
784
+ * cost is measured (`charge`, I15) and watched separately, not capped here.
785
+ * Every method is a no-throw no-op past the allowance: exhausting the
786
+ * budget must never fail a ticket (§6.3).
787
+ */
788
+ interface Budget {
789
+ /** The run's deadline signal, forwarded unchanged to every LLM call. */
790
+ signal: AbortSignal;
791
+ consumeToolCall(): void;
792
+ /** True once `maxToolCalls` is spent OR the run signal aborted. */
793
+ exhausted(): boolean;
794
+ /** Accumulates usage/cost for one node. Reasoning stays out of `output` (§6.3). */
795
+ charge(node: NodeKey, usage: Usage, cost: {
796
+ usd: number;
797
+ pricingMissing: boolean;
798
+ }): void;
799
+ /** Per-node breakdown for the ticket's provenance trail. */
800
+ ledger(): CostLedger;
801
+ /** Whole-run total — the per-ticket cost watched downstream. */
802
+ total(): NodeCost;
803
+ }
804
+ declare function createBudget({ signal, maxToolCalls }: {
805
+ signal: AbortSignal;
806
+ maxToolCalls: number;
807
+ }): Budget;
808
+
779
809
  type Outcome = 'sent' | 'ready' | 'needs_human' | 'guardrail_hold' | 'awaiting_approval' | 'escalated' | 'triaged_only' | 'no_reply_needed' | 'failed' | null;
780
810
  interface TicketRunState {
781
811
  conversation: Conversation | null;
package/dist/index.d.ts CHANGED
@@ -105,67 +105,6 @@ interface Classification {
105
105
  conversationOver?: boolean;
106
106
  }
107
107
 
108
- /**
109
- * One tool invocation made while drafting, kept for provenance display and
110
- * audit — not replayed. `observation` is the tool's result as handed back
111
- * to the model, already serialised to text. Field names mirror
112
- * `ToolCallRequest` (`graph/ports.ts`) rather than a `tool`/`args` pair, so a
113
- * record can be built directly from the request it answers.
114
- */
115
- interface ToolCallRecord {
116
- name: string;
117
- arguments: Record<string, unknown>;
118
- observation: string;
119
- }
120
- /**
121
- * Langfuse attribution of the completion that produced the draft's text, and
122
- * of the prompt version that produced its system message (I17, §3.4's
123
- * `langfuseTraceId`/`langfuseObservationId`/`promptName`/`promptVersion`).
124
- *
125
- * Carried on the draft rather than read back off the LLM port afterwards: a
126
- * run makes several completions (a tool round, then the answer, then maybe a
127
- * revision) and only the one that actually wrote the served text is the one
128
- * the quality loop must score. Legacy convention, kept: the LAST completion
129
- * to produce text wins — a revised draft is attributed to `revise`, not to
130
- * the draft it replaced.
131
- */
132
- interface DraftAttribution {
133
- traceId: string | null;
134
- observationId: string | null;
135
- promptName: string | null;
136
- /** The version `PromptPort` actually served — `0` on the in-code fallback (§3.7 level 3). */
137
- promptVersion: number | null;
138
- }
139
- interface Draft {
140
- text: string;
141
- sources: ToolCallRecord[];
142
- /** True once `revise` has produced this text (at most one pass). */
143
- revised: boolean;
144
- /**
145
- * Absent when the text came from something other than a traced completion
146
- * (a fake gateway, tracing off, a draft rebuilt from a stored record) —
147
- * never a placeholder: an id that names no real generation is worse for
148
- * the quality loop than no id at all.
149
- */
150
- attribution?: DraftAttribution;
151
- }
152
-
153
- declare const EVALUATION_VERDICTS: readonly ["send", "send_and_escalate", "hold"];
154
- type EvaluationVerdict = (typeof EVALUATION_VERDICTS)[number];
155
- declare function isEvaluationVerdict(value: unknown): value is EvaluationVerdict;
156
- /** Verdicts whose reply may go out — the follow-up one included (spec §4.3). */
157
- declare function isSendableVerdict(verdict: EvaluationVerdict | null): boolean;
158
- /** True when the reply is sendable but owes the customer a human follow-up. */
159
- declare function requiresFollowup(verdict: EvaluationVerdict | null): boolean;
160
-
161
- interface Verdict {
162
- verdict: EvaluationVerdict | null;
163
- /** [0, 1]. */
164
- confidence: number | null;
165
- reason: string;
166
- status: 'success' | 'error';
167
- }
168
-
169
108
  type ActionDecision = 'auto' | 'needs_approval' | 'forbidden';
170
109
  interface ProposedAction {
171
110
  /** 'send_reply' | 'refund' | … — the write-side actions introduced in P3. */
@@ -176,13 +115,6 @@ interface ProposedAction {
176
115
  decision?: ActionDecision;
177
116
  }
178
117
 
179
- /**
180
- * Maps to the LLM provider's native reasoning-effort parameter. An invalid
181
- * (model, effort) pair is rejected at profile-load time, never silently
182
- * ignored — this type only carries the vocabulary, not the validation.
183
- */
184
- type ReasoningEffort = 'off' | 'low' | 'medium' | 'high';
185
-
186
118
  /**
187
119
  * The key set of the LLM nodes — exactly the steps a profile's `nodes` and
188
120
  * `prompts` carry a config for. Not every node runs on every ticket
@@ -212,6 +144,13 @@ interface NodeCost extends Usage {
212
144
  /** Per-node cost breakdown for one ticket run (I15). Only ran nodes are keyed. */
213
145
  type CostLedger = Partial<Record<NodeKey, NodeCost>>;
214
146
 
147
+ /**
148
+ * Maps to the LLM provider's native reasoning-effort parameter. An invalid
149
+ * (model, effort) pair is rejected at profile-load time, never silently
150
+ * ignored — this type only carries the vocabulary, not the validation.
151
+ */
152
+ type ReasoningEffort = 'off' | 'low' | 'medium' | 'high';
153
+
215
154
  /**
216
155
  * Key of the single tenant that exists before any second profile is created.
217
156
  * Named once here so every scoped collection shares one source of truth
@@ -410,33 +349,6 @@ interface AgentProfile {
410
349
  };
411
350
  }
412
351
 
413
- /**
414
- * Run budget: bounds a run in TOOL CALLS and TIME only, never in money —
415
- * cost is measured (`charge`, I15) and watched separately, not capped here.
416
- * Every method is a no-throw no-op past the allowance: exhausting the
417
- * budget must never fail a ticket (§6.3).
418
- */
419
- interface Budget {
420
- /** The run's deadline signal, forwarded unchanged to every LLM call. */
421
- signal: AbortSignal;
422
- consumeToolCall(): void;
423
- /** True once `maxToolCalls` is spent OR the run signal aborted. */
424
- exhausted(): boolean;
425
- /** Accumulates usage/cost for one node. Reasoning stays out of `output` (§6.3). */
426
- charge(node: NodeKey, usage: Usage, cost: {
427
- usd: number;
428
- pricingMissing: boolean;
429
- }): void;
430
- /** Per-node breakdown for the ticket's provenance trail. */
431
- ledger(): CostLedger;
432
- /** Whole-run total — the per-ticket cost watched downstream. */
433
- total(): NodeCost;
434
- }
435
- declare function createBudget({ signal, maxToolCalls }: {
436
- signal: AbortSignal;
437
- maxToolCalls: number;
438
- }): Budget;
439
-
440
352
  interface SourceDescriptor {
441
353
  viewOrTag: string;
442
354
  }
@@ -776,6 +688,124 @@ interface SimilarTicket {
776
688
  resolution?: string | null;
777
689
  }
778
690
 
691
+ /**
692
+ * One tool invocation made while drafting, kept for provenance display and
693
+ * audit — not replayed. `observation` is the tool's result as handed back
694
+ * to the model, already serialised to text. Field names mirror
695
+ * `ToolCallRequest` (`graph/ports.ts`) rather than a `tool`/`args` pair, so a
696
+ * record can be built directly from the request it answers.
697
+ */
698
+ interface ToolCallRecord {
699
+ name: string;
700
+ arguments: Record<string, unknown>;
701
+ observation: string;
702
+ }
703
+ /**
704
+ * Langfuse attribution of the completion that produced the draft's text, and
705
+ * of the prompt version that produced its system message (I17, §3.4's
706
+ * `langfuseTraceId`/`langfuseObservationId`/`promptName`/`promptVersion`).
707
+ *
708
+ * Carried on the draft rather than read back off the LLM port afterwards: a
709
+ * run makes several completions (a tool round, then the answer, then maybe a
710
+ * revision) and only the one that actually wrote the served text is the one
711
+ * the quality loop must score. Legacy convention, kept: the LAST completion
712
+ * to produce text wins — a revised draft is attributed to `revise`, not to
713
+ * the draft it replaced.
714
+ */
715
+ interface DraftAttribution {
716
+ traceId: string | null;
717
+ observationId: string | null;
718
+ promptName: string | null;
719
+ /** The version `PromptPort` actually served — `0` on the in-code fallback (§3.7 level 3). */
720
+ promptVersion: number | null;
721
+ }
722
+ interface Draft {
723
+ text: string;
724
+ sources: ToolCallRecord[];
725
+ /**
726
+ * The messages the drafting completion was GIVEN — the rendered system
727
+ * prompt first, then the customer's own turns. The only place either
728
+ * survives the run: the conversation is read live from Gorgias and thrown
729
+ * away, and the prompt is rendered from a Langfuse version that can move.
730
+ * `process-response` writes this to `generated-response.tracedInput`, which
731
+ * the ticket timeline reads for its "Reçu" and "Prompt envoyé" steps
732
+ * (spec-vue-tickets-unifiee-v1 §4.1).
733
+ *
734
+ * The ORIGINAL messages, not the conversation the tool loop grows: the tool
735
+ * rounds are already recorded, in a shape built for reading, on `sources`.
736
+ */
737
+ messages: ChatMessage[];
738
+ /** True once `revise` has produced this text (at most one pass). */
739
+ revised: boolean;
740
+ /**
741
+ * Absent when the text came from something other than a traced completion
742
+ * (a fake gateway, tracing off, a draft rebuilt from a stored record) —
743
+ * never a placeholder: an id that names no real generation is worse for
744
+ * the quality loop than no id at all.
745
+ */
746
+ attribution?: DraftAttribution;
747
+ }
748
+
749
+ declare const EVALUATION_VERDICTS: readonly ["send", "send_and_escalate", "hold"];
750
+ type EvaluationVerdict = (typeof EVALUATION_VERDICTS)[number];
751
+ declare function isEvaluationVerdict(value: unknown): value is EvaluationVerdict;
752
+ /** Verdicts whose reply may go out — the follow-up one included (spec §4.3). */
753
+ declare function isSendableVerdict(verdict: EvaluationVerdict | null): boolean;
754
+ /** True when the reply is sendable but owes the customer a human follow-up. */
755
+ declare function requiresFollowup(verdict: EvaluationVerdict | null): boolean;
756
+
757
+ interface Verdict {
758
+ verdict: EvaluationVerdict | null;
759
+ /** [0, 1]. */
760
+ confidence: number | null;
761
+ reason: string;
762
+ status: 'success' | 'error';
763
+ /**
764
+ * Langfuse observation of the JUDGING completion — `null` when the gateway
765
+ * traced nothing, or on a verdict written before this was captured.
766
+ *
767
+ * Lives here rather than on a record field of its own because
768
+ * `generated-response.langfuseObservationId` already holds the DRAFT's, and
769
+ * §3.4 freezes that record's columns: the "Trace évaluation" link built
770
+ * from it pointed at the generation, not the evaluation
771
+ * (spec-vue-tickets-unifiee-v1 §4.3). `verdict` is a JSON column, so
772
+ * carrying it inside costs no migration.
773
+ *
774
+ * OPTIONAL, not merely nullable: a verdict read back from a row written
775
+ * before this capture existed carries no such key at all, and every caller
776
+ * that builds a verdict by hand (the policy layer, the test bench) is
777
+ * describing a decision, not a traced call.
778
+ */
779
+ observationId?: string | null;
780
+ }
781
+
782
+ /**
783
+ * Run budget: bounds a run in TOOL CALLS and TIME only, never in money —
784
+ * cost is measured (`charge`, I15) and watched separately, not capped here.
785
+ * Every method is a no-throw no-op past the allowance: exhausting the
786
+ * budget must never fail a ticket (§6.3).
787
+ */
788
+ interface Budget {
789
+ /** The run's deadline signal, forwarded unchanged to every LLM call. */
790
+ signal: AbortSignal;
791
+ consumeToolCall(): void;
792
+ /** True once `maxToolCalls` is spent OR the run signal aborted. */
793
+ exhausted(): boolean;
794
+ /** Accumulates usage/cost for one node. Reasoning stays out of `output` (§6.3). */
795
+ charge(node: NodeKey, usage: Usage, cost: {
796
+ usd: number;
797
+ pricingMissing: boolean;
798
+ }): void;
799
+ /** Per-node breakdown for the ticket's provenance trail. */
800
+ ledger(): CostLedger;
801
+ /** Whole-run total — the per-ticket cost watched downstream. */
802
+ total(): NodeCost;
803
+ }
804
+ declare function createBudget({ signal, maxToolCalls }: {
805
+ signal: AbortSignal;
806
+ maxToolCalls: number;
807
+ }): Budget;
808
+
779
809
  type Outcome = 'sent' | 'ready' | 'needs_human' | 'guardrail_hold' | 'awaiting_approval' | 'escalated' | 'triaged_only' | 'no_reply_needed' | 'failed' | null;
780
810
  interface TicketRunState {
781
811
  conversation: Conversation | null;