@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,397 @@
1
+ /**
2
+ * Refill V3 advance PUBLIC MCP projection (Phase 146.5 Plan 10, RV3FLOW-001).
3
+ *
4
+ * A THIN projection over this plan's package-root contract and nothing else:
5
+ *
6
+ * 1. it mirrors the closed three-key request vocabulary so a protocol-level
7
+ * validator refuses drift — including every progress-carrying key — before
8
+ * the handler runs;
9
+ * 2. it applies the ONE shared explicit-workspace guard, because a bounded
10
+ * mutation must name its target workspace instead of switching the shared
11
+ * active workspace;
12
+ * 3. it posts the caller's exact values once to the authenticated route, whose
13
+ * `parseRefillV3AdvanceInput` is the SOLE runtime authority; and
14
+ * 4. it returns only what the SOLE closed decoder produced.
15
+ *
16
+ * It holds no queue, campaign, health, source, retry, or terminal policy: every
17
+ * decision belongs to `computeNextRefillV3Action` on the backend. A typed
18
+ * business result — including `blocked` — is a successful response VALUE and
19
+ * passes through VERBATIM through the central `toMcpToolResult`. Transport
20
+ * failure is the ONLY source of an error result (error law 6).
21
+ *
22
+ * The declarative input schema is IMPORTED from the package contract rather than
23
+ * re-declared, because the contract already lives inside this package and a
24
+ * second mirror would be a vocabulary owned twice.
25
+ */
26
+ import { type RefillV3AdvanceResult } from "./refill-v3-advance-contract.js";
27
+ /** The one authenticated backend boundary this projection may reach. */
28
+ export declare const REFILL_V3_ADVANCE_ROUTE = "/api/v3/mcp/refill-v3/advance";
29
+ export declare const REFILL_V3_ADVANCE_TOOL_NAME: "refill_v3_advance";
30
+ export declare const refillV3AdvanceToolDefinitions: {
31
+ name: "refill_v3_advance";
32
+ description: string;
33
+ inputSchema: Readonly<{
34
+ readonly type: "object";
35
+ readonly additionalProperties: false;
36
+ readonly required: readonly ["workspaceId", "scope"];
37
+ readonly properties: {
38
+ readonly workspaceId: {
39
+ readonly type: "string";
40
+ readonly minLength: 1;
41
+ readonly description: "Explicit request-scoped workspace id. Pass this instead of switching the shared active workspace.";
42
+ };
43
+ readonly scope: {
44
+ readonly description: "Either a 1-3 day sender-local horizon or an exact sender/date set. There is no lane input, no row input, and no mode input.";
45
+ readonly oneOf: readonly [{
46
+ readonly type: "object";
47
+ readonly additionalProperties: false;
48
+ readonly required: readonly ["kind", "days"];
49
+ readonly properties: {
50
+ readonly kind: {
51
+ readonly type: "string";
52
+ readonly const: "sender_local_horizon";
53
+ };
54
+ readonly days: {
55
+ readonly type: "integer";
56
+ readonly minimum: 1;
57
+ readonly maximum: 3;
58
+ };
59
+ readonly senderIds: {
60
+ readonly type: "array";
61
+ readonly items: {
62
+ readonly type: "string";
63
+ readonly minLength: 1;
64
+ };
65
+ readonly minItems: 1;
66
+ };
67
+ };
68
+ }, {
69
+ readonly type: "object";
70
+ readonly additionalProperties: false;
71
+ readonly required: readonly ["kind", "senderDates"];
72
+ readonly properties: {
73
+ readonly kind: {
74
+ readonly type: "string";
75
+ readonly const: "exact_sender_dates";
76
+ };
77
+ readonly senderDates: {
78
+ readonly type: "array";
79
+ readonly minItems: 1;
80
+ readonly items: {
81
+ readonly type: "object";
82
+ readonly additionalProperties: false;
83
+ readonly required: readonly ["senderId", "dates"];
84
+ readonly properties: {
85
+ readonly senderId: {
86
+ readonly type: "string";
87
+ readonly minLength: 1;
88
+ };
89
+ readonly dates: {
90
+ readonly type: "array";
91
+ readonly minItems: 1;
92
+ readonly items: {
93
+ readonly type: "string";
94
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
95
+ };
96
+ };
97
+ };
98
+ };
99
+ };
100
+ };
101
+ }];
102
+ };
103
+ readonly yolo: {
104
+ readonly type: "boolean";
105
+ readonly description: "The operator's AUTONOMY GRANT, true only when the operator actually asked for --yolo. It is not a mode and selects nothing: WHICH campaign may start is derived from the workspace's own campaigns. It authorizes exactly one thing this call could not otherwise do — starting one already-eligible PAUSED derived-evergreen campaign once every active campaign for a row is exhausted. Omit it, or pass false, for a conservative run that reports that exhaustion instead of acting on it.";
106
+ };
107
+ };
108
+ }>;
109
+ outputSchema: Readonly<{
110
+ readonly type: "object";
111
+ readonly required: readonly ["kind", "scope"];
112
+ readonly properties: {
113
+ readonly schemaVersion: {
114
+ readonly type: "string";
115
+ };
116
+ readonly kind: {
117
+ readonly type: "string";
118
+ readonly enum: readonly ["advanced", "campaign_attention_required", "awaiting_external_change", "complete", "blocked"];
119
+ };
120
+ readonly scope: {
121
+ readonly type: "object";
122
+ readonly additionalProperties: false;
123
+ readonly required: readonly ["workspaceId", "scopeKind", "scopeFingerprint"];
124
+ readonly properties: {
125
+ readonly workspaceId: {
126
+ readonly type: "string";
127
+ readonly minLength: 1;
128
+ };
129
+ readonly scopeKind: {
130
+ readonly type: "string";
131
+ readonly enum: readonly ["sender_local_horizon", "exact_sender_dates"];
132
+ };
133
+ readonly scopeFingerprint: {
134
+ readonly type: "string";
135
+ readonly minLength: 1;
136
+ };
137
+ };
138
+ };
139
+ readonly action: {
140
+ readonly type: "object";
141
+ readonly additionalProperties: false;
142
+ readonly required: readonly ["kind", "actionKey", "authority", "senderId", "date", "lane", "campaignId", "evidenceFingerprint"];
143
+ readonly properties: {
144
+ readonly evidenceFingerprint: {
145
+ readonly type: "string";
146
+ readonly minLength: 1;
147
+ };
148
+ readonly senderId: {
149
+ readonly type: "string";
150
+ readonly minLength: 1;
151
+ };
152
+ readonly date: {
153
+ readonly type: "string";
154
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
155
+ };
156
+ readonly lane: {
157
+ readonly type: "string";
158
+ readonly enum: readonly ["connection_invite", "paid_inmail"];
159
+ };
160
+ readonly campaignId: {
161
+ readonly type: readonly ["string", "null"];
162
+ };
163
+ readonly kind: {
164
+ readonly type: "string";
165
+ readonly enum: readonly ["refresh_paid_credit_fact", "recheck_sender_connection", "fill_ready", "start_evergreen_campaign"];
166
+ };
167
+ readonly actionKey: {
168
+ readonly type: "string";
169
+ readonly minLength: 1;
170
+ };
171
+ readonly authority: {
172
+ readonly type: "string";
173
+ readonly enum: ("getOrRefreshPaidInmailCreditFact" | "recheckRefillV3SenderConnection" | "fillRefillV3Ready" | "startRefillV3EvergreenCampaign")[];
174
+ };
175
+ };
176
+ };
177
+ readonly receipt: {
178
+ readonly type: "object";
179
+ readonly additionalProperties: false;
180
+ readonly required: readonly ["actionKey", "status", "effectFingerprint", "productStateDelta", "reasonCode"];
181
+ readonly properties: {
182
+ readonly actionKey: {
183
+ readonly type: "string";
184
+ readonly minLength: 1;
185
+ };
186
+ readonly status: {
187
+ readonly type: "string";
188
+ readonly enum: readonly ["executed", "attached", "failed", "indeterminate"];
189
+ };
190
+ readonly effectFingerprint: {
191
+ readonly type: "string";
192
+ readonly minLength: 1;
193
+ };
194
+ readonly productStateDelta: {
195
+ readonly type: "boolean";
196
+ };
197
+ readonly reasonCode: {
198
+ readonly type: readonly ["string", "null"];
199
+ readonly enum: readonly ["global_cooldown", "connection_cooldown", "paid_inmail_cooldown", "endpoint_temporarily_unavailable", "date_in_past", "no_sending_hours", "sender_disconnected", "sender_limit_reached", "daily_target_met", "no_eligible_campaign", "no_ready_supply", "sales_nav_disconnected", "insufficient_paid_credits", "paid_inmail_connection_health_recheck_required", "paid_inmail_credit_refresh_failed", "invalid_paid_configuration", "campaign_table_missing", "campaign_sequence_invalid", "source_family_unresolved", "campaign_work_in_flight", "zero_requested_count", "idempotency_scope_mismatch", "uncertain_outcome", "placed_under_other_sender", "placed_off_target_date", "paid_inmail_credit_receipt_invalid", "awaiting_external_change", "approval_authority_invalid", "approval_authority_in_flight", "approval_dispatch_incomplete", "ready_cells_unavailable", "sender_affinity_conflict", "scheduler_target_omitted", "scheduler_failed", "receipt_readback_mismatch", "account_identity_missing", "no_progress_refused", "retryable_paid_attempts_exhausted", "unknown_transport_vocabulary", "forged_authority_receipt_facts", "authority_failure_uncertain", "sender_scope_unresolved", "campaign_supply_unclaimed", "lane_campaigns_exhausted", "missing_balance", "blocked", "workspace_membership_revoked", null];
200
+ };
201
+ };
202
+ };
203
+ readonly packet: {
204
+ readonly properties: {
205
+ readonly schemaVersion: {
206
+ readonly type: "string";
207
+ };
208
+ };
209
+ readonly type: "object";
210
+ readonly additionalProperties: false;
211
+ readonly required: readonly ["scope", "evidence"];
212
+ };
213
+ readonly deferral: {
214
+ readonly type: "object";
215
+ readonly additionalProperties: false;
216
+ readonly required: readonly ["senderId", "date", "lane", "campaignId", "code", "message", "resumeAt", "receiptRef"];
217
+ readonly properties: {
218
+ readonly code: {
219
+ readonly type: "string";
220
+ readonly enum: readonly ["global_cooldown", "connection_cooldown", "paid_inmail_cooldown", "endpoint_temporarily_unavailable", "date_in_past", "no_sending_hours", "sender_disconnected", "sender_limit_reached", "daily_target_met", "no_eligible_campaign", "no_ready_supply", "sales_nav_disconnected", "insufficient_paid_credits", "paid_inmail_connection_health_recheck_required", "paid_inmail_credit_refresh_failed", "invalid_paid_configuration", "campaign_table_missing", "campaign_sequence_invalid", "source_family_unresolved", "campaign_work_in_flight", "zero_requested_count", "idempotency_scope_mismatch", "uncertain_outcome", "placed_under_other_sender", "placed_off_target_date", "paid_inmail_credit_receipt_invalid", "awaiting_external_change", "approval_authority_invalid", "approval_authority_in_flight", "approval_dispatch_incomplete", "ready_cells_unavailable", "sender_affinity_conflict", "scheduler_target_omitted", "scheduler_failed", "receipt_readback_mismatch", "account_identity_missing", "no_progress_refused", "retryable_paid_attempts_exhausted", "unknown_transport_vocabulary", "forged_authority_receipt_facts", "authority_failure_uncertain", "sender_scope_unresolved", "campaign_supply_unclaimed", "lane_campaigns_exhausted", "missing_balance", "blocked", "workspace_membership_revoked"];
221
+ };
222
+ readonly message: {
223
+ readonly type: "string";
224
+ };
225
+ readonly resumeAt: {
226
+ readonly type: readonly ["string", "null"];
227
+ };
228
+ readonly receiptRef: {
229
+ readonly type: readonly ["string", "null"];
230
+ };
231
+ readonly senderId: {
232
+ readonly type: "string";
233
+ readonly minLength: 1;
234
+ };
235
+ readonly date: {
236
+ readonly type: "string";
237
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
238
+ };
239
+ readonly lane: {
240
+ readonly type: "string";
241
+ readonly enum: readonly ["connection_invite", "paid_inmail"];
242
+ };
243
+ readonly campaignId: {
244
+ readonly type: readonly ["string", "null"];
245
+ };
246
+ };
247
+ };
248
+ readonly blocker: {
249
+ readonly type: "object";
250
+ readonly additionalProperties: false;
251
+ readonly required: readonly ["senderId", "date", "lane", "campaignId", "code", "message", "permanent", "field"];
252
+ readonly properties: {
253
+ readonly code: {
254
+ readonly type: "string";
255
+ readonly enum: readonly ["global_cooldown", "connection_cooldown", "paid_inmail_cooldown", "endpoint_temporarily_unavailable", "date_in_past", "no_sending_hours", "sender_disconnected", "sender_limit_reached", "daily_target_met", "no_eligible_campaign", "no_ready_supply", "sales_nav_disconnected", "insufficient_paid_credits", "paid_inmail_connection_health_recheck_required", "paid_inmail_credit_refresh_failed", "invalid_paid_configuration", "campaign_table_missing", "campaign_sequence_invalid", "source_family_unresolved", "campaign_work_in_flight", "zero_requested_count", "idempotency_scope_mismatch", "uncertain_outcome", "placed_under_other_sender", "placed_off_target_date", "paid_inmail_credit_receipt_invalid", "awaiting_external_change", "approval_authority_invalid", "approval_authority_in_flight", "approval_dispatch_incomplete", "ready_cells_unavailable", "sender_affinity_conflict", "scheduler_target_omitted", "scheduler_failed", "receipt_readback_mismatch", "account_identity_missing", "no_progress_refused", "retryable_paid_attempts_exhausted", "unknown_transport_vocabulary", "forged_authority_receipt_facts", "authority_failure_uncertain", "sender_scope_unresolved", "campaign_supply_unclaimed", "lane_campaigns_exhausted", "missing_balance", "blocked", "workspace_membership_revoked"];
256
+ };
257
+ readonly message: {
258
+ readonly type: "string";
259
+ };
260
+ readonly permanent: {
261
+ readonly type: "boolean";
262
+ };
263
+ readonly field: {
264
+ readonly type: readonly ["string", "null"];
265
+ };
266
+ readonly senderId: {
267
+ readonly type: "string";
268
+ readonly minLength: 1;
269
+ };
270
+ readonly date: {
271
+ readonly type: "string";
272
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
273
+ };
274
+ readonly lane: {
275
+ readonly type: "string";
276
+ readonly enum: readonly ["connection_invite", "paid_inmail"];
277
+ };
278
+ readonly campaignId: {
279
+ readonly type: readonly ["string", "null"];
280
+ };
281
+ };
282
+ };
283
+ readonly terminal: {
284
+ readonly type: "string";
285
+ readonly enum: readonly ["active_campaigns_exhausted", "no_eligible_campaigns", "campaign_supply_unclaimed_defect", "daily_targets_met", "scope_unresolved"];
286
+ };
287
+ readonly observation: {
288
+ readonly type: "object";
289
+ readonly additionalProperties: false;
290
+ readonly required: readonly ["observationFingerprint", "senderCount", "rowCount", "dates", "availableSlots", "supply"];
291
+ readonly properties: {
292
+ readonly observationFingerprint: {
293
+ readonly type: "string";
294
+ readonly minLength: 1;
295
+ };
296
+ readonly senderCount: {
297
+ readonly type: "integer";
298
+ readonly minimum: 0;
299
+ };
300
+ readonly rowCount: {
301
+ readonly type: "integer";
302
+ readonly minimum: 0;
303
+ };
304
+ readonly dates: {
305
+ readonly type: "array";
306
+ readonly items: {
307
+ readonly type: "string";
308
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
309
+ };
310
+ };
311
+ readonly availableSlots: {
312
+ readonly type: "integer";
313
+ readonly minimum: 0;
314
+ };
315
+ readonly supply: {
316
+ readonly type: "object";
317
+ readonly additionalProperties: false;
318
+ readonly required: readonly ["readyToSchedule", "readyForApproval", "readyForMessageGeneration", "needsEnrichment"];
319
+ readonly properties: {
320
+ [k: string]: {
321
+ type: string;
322
+ minimum: number;
323
+ };
324
+ };
325
+ };
326
+ };
327
+ };
328
+ readonly replacementObservation: {
329
+ readonly type: "object";
330
+ readonly additionalProperties: false;
331
+ readonly required: readonly ["observationFingerprint", "senderCount", "rowCount", "dates", "availableSlots", "supply"];
332
+ readonly properties: {
333
+ readonly observationFingerprint: {
334
+ readonly type: "string";
335
+ readonly minLength: 1;
336
+ };
337
+ readonly senderCount: {
338
+ readonly type: "integer";
339
+ readonly minimum: 0;
340
+ };
341
+ readonly rowCount: {
342
+ readonly type: "integer";
343
+ readonly minimum: 0;
344
+ };
345
+ readonly dates: {
346
+ readonly type: "array";
347
+ readonly items: {
348
+ readonly type: "string";
349
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
350
+ };
351
+ };
352
+ readonly availableSlots: {
353
+ readonly type: "integer";
354
+ readonly minimum: 0;
355
+ };
356
+ readonly supply: {
357
+ readonly type: "object";
358
+ readonly additionalProperties: false;
359
+ readonly required: readonly ["readyToSchedule", "readyForApproval", "readyForMessageGeneration", "needsEnrichment"];
360
+ readonly properties: {
361
+ [k: string]: {
362
+ type: string;
363
+ minimum: number;
364
+ };
365
+ };
366
+ };
367
+ };
368
+ };
369
+ };
370
+ }>;
371
+ annotations: {
372
+ title: string;
373
+ readOnlyHint: boolean;
374
+ destructiveHint: boolean;
375
+ idempotentHint: boolean;
376
+ openWorldHint: boolean;
377
+ };
378
+ }[];
379
+ export type RefillV3AdvanceToolInput = {
380
+ workspaceId?: string;
381
+ scope?: unknown;
382
+ /**
383
+ * The operator's autonomy grant, forwarded verbatim. It is NOT defaulted here
384
+ * — an omitted grant stays omitted so the backend parser, which is the single
385
+ * owner of the conservative default, is the only place that decides.
386
+ */
387
+ yolo?: boolean;
388
+ };
389
+ /**
390
+ * Advance one explicit workspace scope by exactly one step.
391
+ *
392
+ * The returned value is the plain canonical business result. Every failure that
393
+ * is NOT a decoded business fact — a refused request, an authorization refusal,
394
+ * an infrastructure failure, or a response the sole decoder rejects — propagates
395
+ * as a thrown transport error and can never become a plausible receipt.
396
+ */
397
+ export declare function advanceRefillV3Tool(input: RefillV3AdvanceToolInput): Promise<RefillV3AdvanceResult>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Refill V3 advance PUBLIC MCP projection (Phase 146.5 Plan 10, RV3FLOW-001).
3
+ *
4
+ * A THIN projection over this plan's package-root contract and nothing else:
5
+ *
6
+ * 1. it mirrors the closed three-key request vocabulary so a protocol-level
7
+ * validator refuses drift — including every progress-carrying key — before
8
+ * the handler runs;
9
+ * 2. it applies the ONE shared explicit-workspace guard, because a bounded
10
+ * mutation must name its target workspace instead of switching the shared
11
+ * active workspace;
12
+ * 3. it posts the caller's exact values once to the authenticated route, whose
13
+ * `parseRefillV3AdvanceInput` is the SOLE runtime authority; and
14
+ * 4. it returns only what the SOLE closed decoder produced.
15
+ *
16
+ * It holds no queue, campaign, health, source, retry, or terminal policy: every
17
+ * decision belongs to `computeNextRefillV3Action` on the backend. A typed
18
+ * business result — including `blocked` — is a successful response VALUE and
19
+ * passes through VERBATIM through the central `toMcpToolResult`. Transport
20
+ * failure is the ONLY source of an error result (error law 6).
21
+ *
22
+ * The declarative input schema is IMPORTED from the package contract rather than
23
+ * re-declared, because the contract already lives inside this package and a
24
+ * second mirror would be a vocabulary owned twice.
25
+ */
26
+ import { getApi } from "../api.js";
27
+ import { REFILL_V3_ADVANCE_INPUT_SCHEMA, REFILL_V3_ADVANCE_OUTPUT_SCHEMA, decodeRefillV3AdvanceResult, } from "./refill-v3-advance-contract.js";
28
+ import { normalizeExplicitWorkspaceId, workspaceRequestOptions, } from "./workspace-context.js";
29
+ /** The one authenticated backend boundary this projection may reach. */
30
+ export const REFILL_V3_ADVANCE_ROUTE = "/api/v3/mcp/refill-v3/advance";
31
+ export const REFILL_V3_ADVANCE_TOOL_NAME = "refill_v3_advance";
32
+ export const refillV3AdvanceToolDefinitions = [
33
+ {
34
+ name: REFILL_V3_ADVANCE_TOOL_NAME,
35
+ description: "THE DEFAULT REFILL ENTRY POINT. Whenever this tool is exposed, every ordinary request to refill, top up, fill, max out, load up, or otherwise add sends for a workspace, a sender, or a day routes HERE, and `refill_sends` is the superseded V1 fallback that applies only to servers which do NOT expose this tool. Start here: do not open the refill ladder with `get_refill_target_plan` or `refill_sends`, and do not infer the route from a workspace flag, a campaign field, a tool result, or the operator's wording. Advance a Refill V3 refill by exactly ONE deterministic step for one workspace and one scope. Each call performs one fresh world-state observation, chooses one exact action from canonical date -> sender -> lane -> campaign ordering, executes at most that one existing authority, and rereads the exact affected scope. It MUTATES product state when the chosen action is a paid-credit refresh, a connection health recheck, a ready placement, or the one derived-evergreen campaign start this workspace's own campaigns authorize. It never chains a second transition, never runs a plan, and never loops inside one call. Pass {workspaceId, scope} plus, ONLY when the operator actually asked for --yolo, yolo:true: there is no mode, continuation, task receipt, retry counter, cursor, row, or action input, and a call that supplies one is refused. yolo is the operator's AUTONOMY GRANT, not a mode and not a campaign selector — it authorizes exactly one thing, starting one already-eligible PAUSED derived-evergreen campaign once a row's active campaigns are exhausted, and WHICH campaign that is stays derived from the workspace's own campaigns. Omit it for a conservative run: that run does everything else identically and REPORTS the exhaustion instead of starting anything. Never set it because a workspace looks idle, because a previous call said complete, or to make a run finish; set it only from the operator's own words. workspaceId must be an EXACT id. When the operator names a workspace, resolve that name with `list_workspaces` FIRST and pass the matching id here; use the configured or active workspace ONLY when the operator named none. If no accessible workspace matches the named one, or more than one does, STOP and say so rather than falling back to the configured workspace, and never mutate the active workspace to steer this automation. Expect one closed result of advanced, campaign_attention_required, awaiting_external_change, complete, or blocked. An advanced result is ALREADY EXECUTED — surface its receipt and replacement observation and do not call its authority again. Only campaign_attention_required needs a caller: route its ONE selected campaign to the refill-sends-work-campaign subskill and return its chosen closed action to refill_v3_edit_selected_campaign. Call this repeatedly until it answers complete, awaiting_external_change, or blocked.",
36
+ inputSchema: REFILL_V3_ADVANCE_INPUT_SCHEMA,
37
+ outputSchema: REFILL_V3_ADVANCE_OUTPUT_SCHEMA,
38
+ annotations: {
39
+ title: "Refill V3 Advance",
40
+ readOnlyHint: false,
41
+ // Destructive in the PRODUCT-STATE sense: approval, scheduling, credit
42
+ // bookkeeping, and campaign activation change durable customer state a
43
+ // caller cannot undo from this tool.
44
+ destructiveHint: true,
45
+ idempotentHint: true,
46
+ openWorldHint: false,
47
+ },
48
+ },
49
+ ];
50
+ /**
51
+ * Advance one explicit workspace scope by exactly one step.
52
+ *
53
+ * The returned value is the plain canonical business result. Every failure that
54
+ * is NOT a decoded business fact — a refused request, an authorization refusal,
55
+ * an infrastructure failure, or a response the sole decoder rejects — propagates
56
+ * as a thrown transport error and can never become a plausible receipt.
57
+ */
58
+ export async function advanceRefillV3Tool(input) {
59
+ const workspaceId = normalizeExplicitWorkspaceId(input.workspaceId);
60
+ if (!workspaceId) {
61
+ throw new Error("Explicit workspaceId is required for refill_v3_advance. Name the target workspace instead of switching the shared active workspace.");
62
+ }
63
+ const raw = await getApi().post(REFILL_V3_ADVANCE_ROUTE, {
64
+ workspaceId,
65
+ scope: input.scope,
66
+ // Forwarded only when the caller actually supplied it, so an absent grant
67
+ // is absent on the wire rather than an explicit `false` this layer made up.
68
+ ...(input.yolo === undefined ? {} : { yolo: input.yolo }),
69
+ }, workspaceRequestOptions(workspaceId));
70
+ const decoded = decodeRefillV3AdvanceResult(raw);
71
+ if (decoded === null) {
72
+ throw new Error("The Refill V3 advance response failed the published result contract.");
73
+ }
74
+ return decoded;
75
+ }