@sellable/mcp 0.1.793 → 0.1.794

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.
Files changed (54) hide show
  1. package/dist/agent-tool-names.d.ts +2 -2
  2. package/dist/agent-tool-names.js +14 -0
  3. package/dist/scheduler-envelope.d.ts +190 -0
  4. package/dist/scheduler-envelope.js +412 -0
  5. package/dist/server.js +28 -2
  6. package/dist/tools/campaign-message-preparation.d.ts +25 -0
  7. package/dist/tools/campaign-message-preparation.js +37 -0
  8. package/dist/tools/campaign-processing.d.ts +74 -1
  9. package/dist/tools/campaign-processing.js +57 -1
  10. package/dist/tools/prompts.d.ts +15 -3
  11. package/dist/tools/prompts.js +25 -0
  12. package/dist/tools/refill-executors.d.ts +43 -70
  13. package/dist/tools/refill-executors.js +201 -273
  14. package/dist/tools/refill-sends.d.ts +3 -3
  15. package/dist/tools/refill-sends.js +1 -1
  16. package/dist/tools/refill-target-plan.js +1 -1
  17. package/dist/tools/refill-v3-advance-contract.d.ts +618 -0
  18. package/dist/tools/refill-v3-advance-contract.js +920 -0
  19. package/dist/tools/refill-v3-advance.d.ts +397 -0
  20. package/dist/tools/refill-v3-advance.js +75 -0
  21. package/dist/tools/refill-v3-attention-packet-contract.d.ts +608 -0
  22. package/dist/tools/refill-v3-attention-packet-contract.js +911 -0
  23. package/dist/tools/refill-v3-campaign-work.d.ts +324 -0
  24. package/dist/tools/refill-v3-campaign-work.js +1015 -0
  25. package/dist/tools/refill-v3-continue-contract.d.ts +433 -0
  26. package/dist/tools/refill-v3-continue-contract.js +112 -0
  27. package/dist/tools/refill-v3-continue.d.ts +501 -0
  28. package/dist/tools/refill-v3-continue.js +654 -0
  29. package/dist/tools/refill-v3-edit-selected-campaign-contract.d.ts +208 -0
  30. package/dist/tools/refill-v3-edit-selected-campaign-contract.js +351 -0
  31. package/dist/tools/refill-v3-edit-selected-campaign.d.ts +232 -0
  32. package/dist/tools/refill-v3-edit-selected-campaign.js +147 -0
  33. package/dist/tools/refill-v3-fill-ready-contract.d.ts +198 -0
  34. package/dist/tools/refill-v3-fill-ready-contract.js +324 -0
  35. package/dist/tools/refill-v3-fill-ready.d.ts +199 -0
  36. package/dist/tools/refill-v3-fill-ready.js +136 -0
  37. package/dist/tools/refill-v3-source-family-dispatch.d.ts +249 -0
  38. package/dist/tools/refill-v3-source-family-dispatch.js +514 -0
  39. package/dist/tools/refill-v3-waterfall-contract.d.ts +156 -0
  40. package/dist/tools/refill-v3-waterfall-contract.js +181 -0
  41. package/dist/tools/refill-v3-waterfall.d.ts +136 -0
  42. package/dist/tools/refill-v3-waterfall.js +161 -0
  43. package/dist/tools/refill-v3-world-state-contract.d.ts +666 -0
  44. package/dist/tools/refill-v3-world-state-contract.js +790 -0
  45. package/dist/tools/refill-v3-world-state.d.ts +592 -0
  46. package/dist/tools/refill-v3-world-state.js +137 -0
  47. package/dist/tools/registry.d.ts +1710 -3
  48. package/dist/tools/registry.js +19 -0
  49. package/package.json +1 -1
  50. package/skills/refill-sends/SKILL.md +89 -4
  51. package/skills/refill-sends-waterfall-order/SKILL.md +174 -0
  52. package/skills/refill-sends-work-campaign/SKILL.md +253 -0
  53. package/skills/refill-sends-workflow/SKILL.md +112 -5
  54. package/skills/refill-sends-workflow/core/flow.v3.json +209 -0
@@ -0,0 +1,324 @@
1
+ /**
2
+ * Refill V3 selected-campaign traversal RUNTIME (Phase 146.5 Plan 09 T1,
3
+ * RV3PRM-001).
4
+ *
5
+ * This is AI seam #2's OWNED RUNTIME HOME (`A09-AI-SEAM-RUNTIME-HOME`). The
6
+ * markdown subskill supplies the model's judgment; this module is the
7
+ * deterministic authority that stands between that judgment and every product
8
+ * effect. It:
9
+ *
10
+ * 1. decodes the model's output into AT MOST ONE action drawn from the shared
11
+ * `REFILL_V3_CAMPAIGN_ATTENTION_ACTIONS` constant — never a local list;
12
+ * 2. refuses connection-health evidence before any prompt work;
13
+ * 3. gates every action behind live-job absence with a BOUNDED wait;
14
+ * 4. enforces enrich-before-rubric structurally (incident 112k);
15
+ * 5. consumes the canonical diagnostic order VERBATIM so an enriched island
16
+ * can never truncate traversal;
17
+ * 6. loads exactly ONE matching active provider prompt for a new provider
18
+ * search and exactly ZERO on a drain;
19
+ * 7. falsifies an AI exhaustion claim through the shared exhaustion predicate;
20
+ * 8. dispatches EXACTLY ONE authority, validates its receipt, and forces the
21
+ * exact sender/date two-lane re-observation before the iteration ends.
22
+ *
23
+ * The AI seam NEVER mutates. Every effect crosses `dispatchAuthority`, which the
24
+ * caller binds to an existing owner, and a second mutation from the same
25
+ * evidence packet is a closed typed failure.
26
+ *
27
+ * Package constraints (`A02-NO-ZOD`): no app `src/**` import, no validation
28
+ * library, hand-rolled guards only.
29
+ */
30
+ import { type RefillV3ActiveJob, type RefillV3CampaignAttentionAction, type RefillV3CampaignAttentionPacket, type RefillV3CampaignAttentionResult, type RefillV3ExhaustionInput, type RefillV3ExhaustionVerdict, type RefillV3LeadSourceFamily } from "./refill-v3-attention-packet-contract.js";
31
+ /**
32
+ * The single closed taxonomy for "the model's output cannot be trusted".
33
+ * `refill-v3-waterfall.ts` IMPORTS this constant rather than forking a second
34
+ * AI-output framework (`A09-AI-SEAM-RUNTIME-HOME`, disposition D7).
35
+ *
36
+ * Every member is a VALUE, never a throw: a recoverable model error must not
37
+ * take the row down.
38
+ */
39
+ export declare const REFILL_V3_AI_OUTPUT_FAILURES: readonly ["malformed_output", "zero_actions", "multiple_actions", "duplicate_action", "unsupported_action", "stale_evidence", "model_timeout", "delegated_tool_timeout", "receipt_incomplete", "second_mutation_forbidden"];
40
+ export type RefillV3AiOutputFailure = (typeof REFILL_V3_AI_OUTPUT_FAILURES)[number];
41
+ /** Deterministic REFUSALS that are about the world, not the model's syntax. */
42
+ export declare const REFILL_V3_CAMPAIGN_WORK_REFUSALS: readonly ["foreign_scope", "health_recheck_required", "live_job_blocks_action", "rubric_before_enrichment", "rubric_before_viable_repair", "provider_prompt_missing", "provider_prompt_mismatch", "provider_prompt_forbidden_on_drain", "exhaustion_falsified", "negative_set_replay", "diagnostic_order_not_consumed", "cohort_arithmetic_forbidden", "template_meaning_requires_approval"];
43
+ export type RefillV3CampaignWorkRefusal = (typeof REFILL_V3_CAMPAIGN_WORK_REFUSALS)[number];
44
+ /**
45
+ * TRANSPORT MIRROR of the app-owned diagnostic scan-termination union
46
+ * (`src/lib/workflow-tables/campaign-cell-selectors.ts`). The published package
47
+ * may not import app source, so the mirror is declared here and DRIFT IS
48
+ * PINNED: `tests/mcp/refill-v3/campaign-work-validator.test.ts` asserts this
49
+ * tuple equals the app-owned union member-for-member.
50
+ *
51
+ * ONLY `frontier_exhausted` is exhaustion evidence (incident 112t).
52
+ */
53
+ export declare const REFILL_V3_DIAGNOSTIC_TERMINATIONS: readonly ["frontier_exhausted", "scan_budget_exhausted", "limit_reached"];
54
+ export type RefillV3DiagnosticTermination = (typeof REFILL_V3_DIAGNOSTIC_TERMINATIONS)[number];
55
+ /** Connection-health reason codes Plan 10 must intercept BEFORE this seam. */
56
+ export declare const REFILL_V3_HEALTH_REASON_CODES: readonly ["paid_inmail_connection_health_recheck_required", "missing_balance", "sender_connection_connecting", "sender_connection_credentials", "sender_disconnected", "sales_nav_disconnected"];
57
+ export type RefillV3HealthReasonCode = (typeof REFILL_V3_HEALTH_REASON_CODES)[number];
58
+ /** The bounded source modes. A drain loads NO provider prompt. */
59
+ export declare const REFILL_V3_SOURCE_COMMAND_MODES: readonly ["new_provider_search", "drain_imported", "post_engager_continuation"];
60
+ export type RefillV3SourceCommandMode = (typeof REFILL_V3_SOURCE_COMMAND_MODES)[number];
61
+ /**
62
+ * Cohort/batch keys the model may NEVER name. Sizing belongs to the existing
63
+ * `campaign-message-preparation` adaptive worker; a batch size in the model's
64
+ * command is a second selector by another name.
65
+ */
66
+ export declare const REFILL_V3_FORBIDDEN_COMMAND_KEYS: readonly ["batchSize", "cohortSize", "limit", "offset", "rangeStart", "rangeEnd", "targetCount", "retryCount", "attempts", "cursor"];
67
+ /** The SEVEN reuse points a preparation delegation receipt must carry. */
68
+ export declare const REFILL_V3_PREPARATION_REUSE_POINTS: readonly ["frontier", "remainingGapPassEvidence", "serialBatchCap", "totalRowBudget", "replayKey", "lowPassGuard", "reclaimBehavior"];
69
+ export type RefillV3PreparationReusePoint = (typeof REFILL_V3_PREPARATION_REUSE_POINTS)[number];
70
+ /** Actions that may only be chosen once the bounded sample is ENRICHED. */
71
+ export declare const REFILL_V3_ENRICHMENT_GATED_ACTIONS: readonly ["request_rubric_trial", "broaden_source_family", "record_source_frontier_exhausted"];
72
+ /** Actions that OUTRANK rubric relaxation and source broadening. */
73
+ export declare const REFILL_V3_REPAIR_FIRST_ACTIONS: readonly ["rerun_errored_cells", "repair_campaign_config", "enrich_bounded_sample", "regenerate_stale_messages", "patch_filter_criteria", "patch_source_criteria"];
74
+ /** Row-scoped actions whose exact cohort is owned by the diagnostic authority. */
75
+ export declare const REFILL_V3_ROW_SCOPED_ACTIONS: readonly ["rerun_errored_cells", "enrich_bounded_sample", "regenerate_stale_messages"];
76
+ /** Actions that carry a bounded source command. */
77
+ export declare const REFILL_V3_SOURCE_ACTIONS: readonly ["broaden_source_family", "patch_source_criteria"];
78
+ /** One deterministic result per chosen action. */
79
+ export declare const REFILL_V3_ACTION_RESULTS: Readonly<Record<RefillV3CampaignAttentionAction, RefillV3CampaignAttentionResult>>;
80
+ /**
81
+ * Posts-search sub-mechanics the MODEL must respect. They live here because the
82
+ * prompt and the decoder are the two surfaces the model touches; the source
83
+ * dispatcher IMPORTS them rather than restating them.
84
+ */
85
+ export declare const REFILL_V3_POSTS_KEYWORD_BATCH_SIZE = 5;
86
+ export declare const REFILL_V3_POSTS_MAX_SELECTED = 5;
87
+ export declare const REFILL_V3_POSTS_ROUND_BUDGET = 3;
88
+ /** Finite wait guidance so a stuck job can never hold a campaign forever. */
89
+ export declare const REFILL_V3_ACTIVE_JOB_WAIT_MS = 30000;
90
+ export type RefillV3CandidateVerdict = {
91
+ candidateId: string;
92
+ verdict: "pass" | "fail";
93
+ rubricBasis: string;
94
+ };
95
+ export type RefillV3SourceCommand = {
96
+ family: RefillV3LeadSourceFamily;
97
+ mode: RefillV3SourceCommandMode;
98
+ provider: string | null;
99
+ requestFingerprint: string;
100
+ query: string | null;
101
+ filterDelta: Record<string, unknown> | null;
102
+ keywordBatch: readonly string[] | null;
103
+ selectedPostIds: readonly string[] | null;
104
+ postRationales: readonly {
105
+ postId: string;
106
+ expectedYieldBasis: string;
107
+ }[] | null;
108
+ };
109
+ export type RefillV3CampaignWorkAction = {
110
+ action: RefillV3CampaignAttentionAction;
111
+ rationale: string;
112
+ rowIds: readonly string[] | null;
113
+ sourceCommand: RefillV3SourceCommand | null;
114
+ candidateVerdicts: readonly RefillV3CandidateVerdict[] | null;
115
+ templateFingerprint: string | null;
116
+ templateMeaningChanged: boolean;
117
+ exhaustionEvidence: RefillV3ExhaustionInput | null;
118
+ providerPromptRef: {
119
+ provider: string;
120
+ campaignOfferId: string;
121
+ } | null;
122
+ };
123
+ /**
124
+ * The model answers with an ARRAY so zero, multiple, and duplicate choices are
125
+ * all DETECTABLE rather than silently collapsed into "the first one".
126
+ */
127
+ export type RefillV3CampaignWorkOutput = {
128
+ scopeEcho: {
129
+ campaignId: string;
130
+ tableId: string;
131
+ campaignVersion: number;
132
+ evidenceFingerprint: string;
133
+ };
134
+ actions: readonly RefillV3CampaignWorkAction[];
135
+ consumedDiagnosticRowIds: readonly string[] | null;
136
+ };
137
+ export type RefillV3CampaignWorkDecodeResult = {
138
+ ok: true;
139
+ value: RefillV3CampaignWorkOutput;
140
+ } | {
141
+ ok: false;
142
+ failure: RefillV3AiOutputFailure;
143
+ detail: string;
144
+ };
145
+ export type RefillV3DiagnosticSample = {
146
+ limit: number;
147
+ /** Canonical `(position, id)` order. CONSUMED VERBATIM, never re-windowed. */
148
+ orderedRowIds: readonly string[];
149
+ unenrichedRowIds: readonly string[];
150
+ failedRowIds: readonly string[];
151
+ failureEvidence: readonly {
152
+ rowId: string;
153
+ error: string | null;
154
+ statusReason: string | null;
155
+ }[];
156
+ termination: {
157
+ reason: RefillV3DiagnosticTermination;
158
+ rowsChecked: number;
159
+ rowsRemaining: number | null;
160
+ hasMore: boolean;
161
+ };
162
+ };
163
+ export type RefillV3ProviderPromptFact = {
164
+ provider: string;
165
+ campaignOfferId: string;
166
+ promptPackage: string;
167
+ promptVersion: string;
168
+ };
169
+ export type RefillV3AuthorityRequest = {
170
+ action: RefillV3CampaignAttentionAction;
171
+ scope: {
172
+ workspaceId: string;
173
+ campaignId: string;
174
+ tableId: string;
175
+ campaignVersion: number;
176
+ evidenceFingerprint: string;
177
+ senderId: string;
178
+ date: string;
179
+ };
180
+ /**
181
+ * Duplicate-work identity is keyed to the TABLE FRONTIER, never to the
182
+ * enrolled sender: two senders sharing one table share one frontier
183
+ * (incident 112ak).
184
+ */
185
+ frontierKey: string;
186
+ idempotencyKey: string;
187
+ rowIds: readonly string[] | null;
188
+ sourceCommand: RefillV3SourceCommand | null;
189
+ candidateVerdicts: readonly RefillV3CandidateVerdict[] | null;
190
+ providerPrompt: RefillV3ProviderPromptFact | null;
191
+ exhaustionVerdict: RefillV3ExhaustionVerdict | null;
192
+ };
193
+ export type RefillV3AuthorityReceipt = {
194
+ outcome: "applied" | "no_effect" | "refused" | "uncertain";
195
+ result: RefillV3CampaignAttentionResult;
196
+ scopeEcho: string;
197
+ idempotencyKey: string;
198
+ beforeFingerprint: string | null;
199
+ afterFingerprint: string | null;
200
+ changedFields: readonly string[];
201
+ effectKey: string | null;
202
+ rollback: {
203
+ available: boolean;
204
+ input: unknown;
205
+ result: unknown;
206
+ } | null;
207
+ reobserveRequired: boolean;
208
+ preparationDelegation: Readonly<Partial<Record<RefillV3PreparationReusePoint, unknown>>> | null;
209
+ systemicError: boolean;
210
+ lowPass: boolean;
211
+ refusalReason: string | null;
212
+ };
213
+ export type RefillV3ReobservationFact = {
214
+ observed: true;
215
+ senderId: string;
216
+ date: string;
217
+ lanes: readonly string[];
218
+ evidenceFingerprint: string;
219
+ };
220
+ export type RefillV3CampaignWorkDependencies = {
221
+ loadDiagnosticSample(input: {
222
+ workspaceId: string;
223
+ campaignId: string;
224
+ tableId: string;
225
+ limit: number;
226
+ }): Promise<RefillV3DiagnosticSample>;
227
+ loadProviderPrompt(input: {
228
+ provider: string;
229
+ campaignOfferId: string;
230
+ }): Promise<RefillV3ProviderPromptFact | null>;
231
+ readLiveTableJob(input: {
232
+ tableId: string;
233
+ }): Promise<RefillV3ActiveJob | null>;
234
+ dispatchAuthority(request: RefillV3AuthorityRequest): Promise<RefillV3AuthorityReceipt>;
235
+ reobserveExactSenderDates(input: {
236
+ workspaceId: string;
237
+ senderId: string;
238
+ date: string;
239
+ }): Promise<RefillV3ReobservationFact>;
240
+ };
241
+ export type RefillV3CampaignWorkCallStep = "diagnose" | "load_provider_prompt" | "authority" | "await_active_job" | "reobserve";
242
+ export type RefillV3CampaignWorkCall = {
243
+ step: RefillV3CampaignWorkCallStep;
244
+ detail: string;
245
+ };
246
+ export type RefillV3CampaignWorkWait = {
247
+ activeJob: RefillV3ActiveJob;
248
+ waitMs: number;
249
+ reobserveRequired: true;
250
+ resumeGuidance: string;
251
+ };
252
+ export type RefillV3CampaignWorkOutcome = {
253
+ ok: true;
254
+ action: RefillV3CampaignAttentionAction;
255
+ result: RefillV3CampaignAttentionResult;
256
+ receipt: RefillV3AuthorityReceipt;
257
+ reobservation: RefillV3ReobservationFact;
258
+ wait: RefillV3CampaignWorkWait | null;
259
+ nextCohortCap: number | null;
260
+ callLog: readonly RefillV3CampaignWorkCall[];
261
+ } | {
262
+ ok: false;
263
+ failure: RefillV3AiOutputFailure | RefillV3CampaignWorkRefusal;
264
+ detail: string;
265
+ result: RefillV3CampaignAttentionResult | null;
266
+ callLog: readonly RefillV3CampaignWorkCall[];
267
+ };
268
+ export type RefillV3CampaignWorkInput = {
269
+ packet: RefillV3CampaignAttentionPacket;
270
+ output: unknown;
271
+ dependencies: RefillV3CampaignWorkDependencies;
272
+ /** Canonical health evidence Plan 10 should already have intercepted. */
273
+ healthEvidence?: readonly string[];
274
+ /** Task-local guard so one evidence packet can never mutate twice. */
275
+ taskScope?: RefillV3CampaignWorkTaskScope;
276
+ /** Per-request replay identity. */
277
+ idempotencyKey?: string;
278
+ };
279
+ /**
280
+ * TASK-LOCAL mutation ledger. It is a plain in-memory value with no durable
281
+ * storage, no cursor, and no attempt counter: its only job is to make a second
282
+ * mutation from ONE evidence packet impossible inside one task.
283
+ */
284
+ export type RefillV3CampaignWorkTaskScope = {
285
+ readonly mutatedEvidenceFingerprints: Set<string>;
286
+ };
287
+ export declare function createRefillV3CampaignWorkTaskScope(): RefillV3CampaignWorkTaskScope;
288
+ /**
289
+ * DEEP scan for cohort/retry bookkeeping anywhere in the model's raw output.
290
+ *
291
+ * It runs BEFORE decoding so a batch size buried inside a nested command can
292
+ * never reach a dependency. Sizing belongs to the existing adaptive worker and a
293
+ * model-supplied cap is a second selector by another name.
294
+ */
295
+ export declare function findRefillV3ForbiddenCommandKey(value: unknown): string | null;
296
+ /**
297
+ * SOLE decoder for the traversal's model output.
298
+ *
299
+ * The model answers with an ARRAY so zero, multiple, and duplicate choices each
300
+ * get their OWN typed failure instead of being silently collapsed into "the
301
+ * first one" — which is how a model that hedged two actions gets read as having
302
+ * decided one.
303
+ */
304
+ export declare function decodeRefillV3CampaignWorkOutput(value: unknown): RefillV3CampaignWorkDecodeResult;
305
+ /**
306
+ * Run ONE selected-campaign attention iteration.
307
+ *
308
+ * Ordering is load-bearing and every early refusal makes ZERO dependency calls:
309
+ *
310
+ * health → cohort bookkeeping → decode → exact scope → task-local replay →
311
+ * bounded diagnose → live-job gate → canonical order → repair-first →
312
+ * enrich-before-rubric → template meaning → provider prompt → negative set →
313
+ * exhaustion falsification → ONE authority → receipt → ONE re-observation.
314
+ */
315
+ export declare function runRefillV3CampaignWork(input: RefillV3CampaignWorkInput): Promise<RefillV3CampaignWorkOutcome>;
316
+ /**
317
+ * Exported so the falsification path can never be restated: the AI's exhaustion
318
+ * claim is answered by the SHARED predicate, not by a local truth table.
319
+ */
320
+ export declare function falsifyRefillV3ExhaustionClaim(evidence: RefillV3ExhaustionInput): RefillV3ExhaustionVerdict;
321
+ /** The bounded sample cap, re-exported so no consumer computes a cohort. */
322
+ export declare const REFILL_V3_CAMPAIGN_WORK_SAMPLE_CAP = 10;
323
+ /** Guard used by the decoder and by the source dispatcher's boundary pins. */
324
+ export declare function isRefillV3CampaignAttentionAction(value: unknown): value is RefillV3CampaignAttentionAction;