@sellable/mcp 0.1.510 → 0.1.512

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.
@@ -0,0 +1,196 @@
1
+ import * as path from "node:path";
2
+ import { getApi } from "../api.js";
3
+ import { appendIndexLine, appendJournalEvent, createRunJournal, renderBootstrapSection, renderPlanSection, renderTerminalSection, } from "../refill-journal.js";
4
+ import { readRefillWorkspaceState } from "../refill-local-state.js";
5
+ import { normalizeExplicitWorkspaceId, workspaceRequestOptions, } from "./workspace-context.js";
6
+ const KNOWN_TOP_LEVEL_FIELDS = [
7
+ "readOnly",
8
+ "generatedAt",
9
+ "bootstrap",
10
+ "plans",
11
+ "globalActionQueue",
12
+ "evergreen",
13
+ "planRevision",
14
+ "stateRevision",
15
+ "packet",
16
+ "sideEffects",
17
+ "warnings",
18
+ ];
19
+ // MCP mirror maintenance note:
20
+ // Evergreen rung vocabulary restatements track canonical EVERGREEN_RUNG_ORDER in
21
+ // src/lib/workflow-tables/refill-target-plan.ts. pr1 token checks track
22
+ // PR1_TOKEN_REGEX in src/lib/workflow-tables/plan-revision.ts.
23
+ function isRecord(value) {
24
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
25
+ }
26
+ function deepClone(value) {
27
+ return JSON.parse(JSON.stringify(value));
28
+ }
29
+ export function sanitizeEvergreenRefillPlanResult(value) {
30
+ if (!isRecord(value))
31
+ return {};
32
+ const sanitized = {};
33
+ for (const key of KNOWN_TOP_LEVEL_FIELDS) {
34
+ if (value[key] !== undefined)
35
+ sanitized[key] = deepClone(value[key]);
36
+ }
37
+ return sanitized;
38
+ }
39
+ function buildRunStateFromLocalHints(workspaceId) {
40
+ const state = readRefillWorkspaceState(workspaceId);
41
+ return {
42
+ version: 1,
43
+ senderCursors: [],
44
+ laneCooldowns: state?.laneMemory ?? [],
45
+ passRates: state?.passRates ?? [],
46
+ };
47
+ }
48
+ async function postEvergreenRefillPlan(body, workspaceId) {
49
+ const api = getApi();
50
+ const requestOptions = workspaceRequestOptions(workspaceId);
51
+ return requestOptions
52
+ ? api.post("/api/v3/mcp/evergreen-refill-plan", body, requestOptions)
53
+ : api.post("/api/v3/mcp/evergreen-refill-plan", body);
54
+ }
55
+ function planSummaryLines(result) {
56
+ const plans = Array.isArray(result.plans) ? result.plans : [];
57
+ return plans.flatMap((plan) => {
58
+ if (!isRecord(plan))
59
+ return [];
60
+ const itinerary = isRecord(plan.itinerary) ? plan.itinerary : null;
61
+ const chosen = isRecord(itinerary?.chosen) ? itinerary?.chosen : null;
62
+ const fallback = isRecord(itinerary?.fallback) ? itinerary?.fallback : null;
63
+ return [
64
+ `${String(plan.senderId ?? "unknown")}: ${String(chosen?.summary ?? "no chosen rung")}`,
65
+ fallback ? `fallback: ${String(fallback.trigger ?? "")}` : null,
66
+ ].filter((line) => Boolean(line));
67
+ });
68
+ }
69
+ function writeDryRunJournal(params) {
70
+ const created = createRunJournal({
71
+ workspaceId: params.workspaceId,
72
+ dryRun: true,
73
+ });
74
+ const bootstrap = isRecord(params.result.bootstrap)
75
+ ? params.result.bootstrap
76
+ : {};
77
+ appendJournalEvent(created.filePath, renderBootstrapSection({
78
+ summary: "Evergreen refill dry-run bootstrap",
79
+ senderSummary: JSON.stringify(bootstrap.senders ?? []),
80
+ laneSummary: JSON.stringify(bootstrap.laneOrder ?? []),
81
+ targetSummary: JSON.stringify(bootstrap.target ?? []),
82
+ creditSummary: JSON.stringify(bootstrap.paidCredit ?? []),
83
+ }));
84
+ const plans = Array.isArray(params.result.plans) ? params.result.plans : [];
85
+ for (const plan of plans) {
86
+ if (!isRecord(plan))
87
+ continue;
88
+ const itinerary = isRecord(plan.itinerary) ? plan.itinerary : {};
89
+ const chosen = isRecord(itinerary.chosen) ? itinerary.chosen : {};
90
+ const projected = Array.isArray(itinerary.projected)
91
+ ? itinerary.projected
92
+ : [];
93
+ const fallback = isRecord(itinerary.fallback) ? itinerary.fallback : {};
94
+ appendJournalEvent(created.filePath, renderPlanSection({
95
+ chosenSummary: String(chosen.summary ?? "No chosen rung"),
96
+ itinerarySummaries: projected
97
+ .filter(isRecord)
98
+ .map((entry) => String(entry.summary ?? "")),
99
+ fallbackSummary: String(fallback.trigger ?? ""),
100
+ }));
101
+ }
102
+ appendJournalEvent(created.filePath, renderTerminalSection({
103
+ summary: [
104
+ `planRevision=${String(params.result.planRevision ?? "")}`,
105
+ `stateRevision=${String(params.result.stateRevision ?? "")}`,
106
+ params.journalNote ?? null,
107
+ ]
108
+ .filter(Boolean)
109
+ .join(" "),
110
+ }));
111
+ appendIndexLine({
112
+ runId: created.runId,
113
+ fileName: path.basename(created.filePath),
114
+ workspaceId: params.workspaceId,
115
+ dryRun: true,
116
+ summary: "evergreen refill dry-run",
117
+ });
118
+ return created.filePath;
119
+ }
120
+ export const evergreenRefillPlanToolDefinitions = [
121
+ {
122
+ name: "get_evergreen_refill_plan",
123
+ description: "Read-only evergreen refill dry-run planner. It performs no mutations, does not schedule, send, approve, prepare, or refresh credits, and writes a local dry-run journal file unless journal:false is passed.",
124
+ inputSchema: {
125
+ type: "object",
126
+ properties: {
127
+ workspaceId: {
128
+ type: "string",
129
+ description: "Explicit request-scoped workspace id.",
130
+ },
131
+ senderIds: {
132
+ type: "array",
133
+ items: { type: "string" },
134
+ },
135
+ runState: {
136
+ type: "object",
137
+ description: "Optional synthetic v1 run state. When provided, replaces local lane-memory hints.",
138
+ },
139
+ journal: {
140
+ type: "boolean",
141
+ description: "Set false to skip the local dry-run journal write.",
142
+ },
143
+ journalNote: {
144
+ type: "string",
145
+ description: "Optional note appended to the terminal journal section.",
146
+ },
147
+ },
148
+ required: ["workspaceId"],
149
+ additionalProperties: false,
150
+ },
151
+ },
152
+ ];
153
+ export async function getEvergreenRefillPlan(input) {
154
+ const workspaceId = normalizeExplicitWorkspaceId(input.workspaceId);
155
+ if (!workspaceId) {
156
+ throw new Error("workspaceId is required for get_evergreen_refill_plan.");
157
+ }
158
+ const runState = input.runState !== undefined
159
+ ? input.runState
160
+ : buildRunStateFromLocalHints(workspaceId);
161
+ const raw = await postEvergreenRefillPlan({
162
+ workspaceId,
163
+ senderIds: input.senderIds,
164
+ runState,
165
+ }, workspaceId);
166
+ const sanitized = sanitizeEvergreenRefillPlanResult(raw);
167
+ const warnings = Array.isArray(sanitized.warnings)
168
+ ? [...sanitized.warnings]
169
+ : [];
170
+ let journalPath = null;
171
+ if (input.journal !== false) {
172
+ try {
173
+ journalPath = writeDryRunJournal({
174
+ workspaceId,
175
+ result: sanitized,
176
+ journalNote: input.journalNote,
177
+ });
178
+ }
179
+ catch {
180
+ warnings.push("journalWriteFailed");
181
+ }
182
+ }
183
+ const summary = [
184
+ "Evergreen refill dry-run plan:",
185
+ ...planSummaryLines(sanitized),
186
+ journalPath ? `Journal: ${journalPath}` : "Journal: not written",
187
+ ].join("\n");
188
+ return {
189
+ ...sanitized,
190
+ warnings,
191
+ journalPath,
192
+ text: summary,
193
+ workspaceId,
194
+ workspaceResolution: "explicit",
195
+ };
196
+ }
@@ -70,6 +70,7 @@ export type SalesNavSearchInput = {
70
70
  };
71
71
  export type ProspeoSearchInput = {
72
72
  filters: Record<string, unknown>;
73
+ workspaceId?: string;
73
74
  page?: number;
74
75
  searchId?: string;
75
76
  campaignOfferId?: string;
@@ -127,7 +128,6 @@ export type LookupSalesNavFilterInput = {
127
128
  };
128
129
  export type SignalSearchInput = {
129
130
  type?: "keywords" | "profile" | "post" | "company";
130
- workspaceId?: string;
131
131
  keywords?: Array<{
132
132
  keyword: string;
133
133
  id?: string;
@@ -167,6 +167,7 @@ export type ImportLeadsInput = {
167
167
  };
168
168
  export type CancelLeadImportInput = {
169
169
  campaignOfferId: string;
170
+ workspaceId?: string;
170
171
  tableId: string;
171
172
  provider: "apollo" | "prospeo" | "sales-nav";
172
173
  };
@@ -193,7 +194,6 @@ export type ConfirmLeadListInput = {
193
194
  };
194
195
  export type SelectPromisingPostsInput = {
195
196
  campaignOfferId: string;
196
- workspaceId?: string;
197
197
  selections: Array<{
198
198
  postId: string;
199
199
  reason: string;
@@ -280,6 +280,7 @@ export declare const leadToolDefinitions: ({
280
280
  previewOnly?: undefined;
281
281
  companySearchToken?: undefined;
282
282
  selectedCompanyIds?: undefined;
283
+ workspaceId?: undefined;
283
284
  domainFilterId?: undefined;
284
285
  type?: undefined;
285
286
  profileUrl?: undefined;
@@ -476,6 +477,7 @@ export declare const leadToolDefinitions: ({
476
477
  previewOnly?: undefined;
477
478
  companySearchToken?: undefined;
478
479
  selectedCompanyIds?: undefined;
480
+ workspaceId?: undefined;
479
481
  domainFilterId?: undefined;
480
482
  type?: undefined;
481
483
  profileUrl?: undefined;
@@ -571,6 +573,7 @@ export declare const leadToolDefinitions: ({
571
573
  previewOnly?: undefined;
572
574
  companySearchToken?: undefined;
573
575
  selectedCompanyIds?: undefined;
576
+ workspaceId?: undefined;
574
577
  domainFilterId?: undefined;
575
578
  type?: undefined;
576
579
  profileUrl?: undefined;
@@ -738,6 +741,7 @@ export declare const leadToolDefinitions: ({
738
741
  previewOnly?: undefined;
739
742
  companySearchToken?: undefined;
740
743
  selectedCompanyIds?: undefined;
744
+ workspaceId?: undefined;
741
745
  domainFilterId?: undefined;
742
746
  type?: undefined;
743
747
  profileUrl?: undefined;
@@ -847,6 +851,7 @@ export declare const leadToolDefinitions: ({
847
851
  previewOnly?: undefined;
848
852
  companySearchToken?: undefined;
849
853
  selectedCompanyIds?: undefined;
854
+ workspaceId?: undefined;
850
855
  domainFilterId?: undefined;
851
856
  type?: undefined;
852
857
  profileUrl?: undefined;
@@ -965,6 +970,7 @@ export declare const leadToolDefinitions: ({
965
970
  previewOnly?: undefined;
966
971
  companySearchToken?: undefined;
967
972
  selectedCompanyIds?: undefined;
973
+ workspaceId?: undefined;
968
974
  domainFilterId?: undefined;
969
975
  type?: undefined;
970
976
  profileUrl?: undefined;
@@ -1072,6 +1078,7 @@ export declare const leadToolDefinitions: ({
1072
1078
  previewOnly?: undefined;
1073
1079
  companySearchToken?: undefined;
1074
1080
  selectedCompanyIds?: undefined;
1081
+ workspaceId?: undefined;
1075
1082
  domainFilterId?: undefined;
1076
1083
  type?: undefined;
1077
1084
  profileUrl?: undefined;
@@ -1184,6 +1191,7 @@ export declare const leadToolDefinitions: ({
1184
1191
  previewOnly?: undefined;
1185
1192
  companySearchToken?: undefined;
1186
1193
  selectedCompanyIds?: undefined;
1194
+ workspaceId?: undefined;
1187
1195
  domainFilterId?: undefined;
1188
1196
  type?: undefined;
1189
1197
  profileUrl?: undefined;
@@ -1284,6 +1292,7 @@ export declare const leadToolDefinitions: ({
1284
1292
  previewOnly?: undefined;
1285
1293
  companySearchToken?: undefined;
1286
1294
  selectedCompanyIds?: undefined;
1295
+ workspaceId?: undefined;
1287
1296
  domainFilterId?: undefined;
1288
1297
  type?: undefined;
1289
1298
  profileUrl?: undefined;
@@ -2176,6 +2185,7 @@ export declare const leadToolDefinitions: ({
2176
2185
  exclude?: undefined;
2177
2186
  companySearchToken?: undefined;
2178
2187
  selectedCompanyIds?: undefined;
2188
+ workspaceId?: undefined;
2179
2189
  domainFilterId?: undefined;
2180
2190
  type?: undefined;
2181
2191
  profileUrl?: undefined;
@@ -2285,6 +2295,7 @@ export declare const leadToolDefinitions: ({
2285
2295
  seedDomains?: undefined;
2286
2296
  sort?: undefined;
2287
2297
  previewOnly?: undefined;
2298
+ workspaceId?: undefined;
2288
2299
  domainFilterId?: undefined;
2289
2300
  type?: undefined;
2290
2301
  profileUrl?: undefined;
@@ -3271,6 +3282,10 @@ export declare const leadToolDefinitions: ({
3271
3282
  type: string;
3272
3283
  description: string;
3273
3284
  };
3285
+ workspaceId: {
3286
+ type: string;
3287
+ description: string;
3288
+ };
3274
3289
  searchName: {
3275
3290
  type: string;
3276
3291
  description: string;
@@ -3495,6 +3510,7 @@ export declare const leadToolDefinitions: ({
3495
3510
  previewOnly?: undefined;
3496
3511
  companySearchToken?: undefined;
3497
3512
  selectedCompanyIds?: undefined;
3513
+ workspaceId?: undefined;
3498
3514
  domainFilterId?: undefined;
3499
3515
  sourceLeadListId?: undefined;
3500
3516
  targetLeadCount?: undefined;
@@ -3527,6 +3543,10 @@ export declare const leadToolDefinitions: ({
3527
3543
  type: string;
3528
3544
  description: string;
3529
3545
  };
3546
+ workspaceId: {
3547
+ type: string;
3548
+ description: string;
3549
+ };
3530
3550
  provider: {
3531
3551
  type: string;
3532
3552
  enum: string[];
@@ -3670,6 +3690,10 @@ export declare const leadToolDefinitions: ({
3670
3690
  type: string;
3671
3691
  description: string;
3672
3692
  };
3693
+ workspaceId: {
3694
+ type: string;
3695
+ description: string;
3696
+ };
3673
3697
  tableId: {
3674
3698
  type: string;
3675
3699
  description: string;
@@ -3768,6 +3792,10 @@ export declare const leadToolDefinitions: ({
3768
3792
  type: string;
3769
3793
  description: string;
3770
3794
  };
3795
+ workspaceId: {
3796
+ type: string;
3797
+ description: string;
3798
+ };
3771
3799
  sourceLeadListId: {
3772
3800
  type: string;
3773
3801
  description: string;
@@ -4000,6 +4028,7 @@ export declare const leadToolDefinitions: ({
4000
4028
  previewOnly?: undefined;
4001
4029
  companySearchToken?: undefined;
4002
4030
  selectedCompanyIds?: undefined;
4031
+ workspaceId?: undefined;
4003
4032
  domainFilterId?: undefined;
4004
4033
  type?: undefined;
4005
4034
  profileUrl?: undefined;
@@ -4097,6 +4126,7 @@ export declare const leadToolDefinitions: ({
4097
4126
  previewOnly?: undefined;
4098
4127
  companySearchToken?: undefined;
4099
4128
  selectedCompanyIds?: undefined;
4129
+ workspaceId?: undefined;
4100
4130
  domainFilterId?: undefined;
4101
4131
  type?: undefined;
4102
4132
  profileUrl?: undefined;
@@ -4556,6 +4586,7 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4556
4586
  targetLeadCount?: undefined;
4557
4587
  existingCount?: undefined;
4558
4588
  createdLeadList?: undefined;
4589
+ selectedLeadListIdUpdated?: undefined;
4559
4590
  jobResult?: undefined;
4560
4591
  } | {
4561
4592
  error: string;
@@ -4605,6 +4636,7 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4605
4636
  targetLeadCount?: undefined;
4606
4637
  existingCount?: undefined;
4607
4638
  createdLeadList?: undefined;
4639
+ selectedLeadListIdUpdated?: undefined;
4608
4640
  jobResult?: undefined;
4609
4641
  } | {
4610
4642
  provider: "signal-discovery" | "sales-nav" | "prospeo";
@@ -4654,6 +4686,7 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4654
4686
  targetLeadCount?: undefined;
4655
4687
  existingCount?: undefined;
4656
4688
  createdLeadList?: undefined;
4689
+ selectedLeadListIdUpdated?: undefined;
4657
4690
  jobResult?: undefined;
4658
4691
  } | {
4659
4692
  provider: string;
@@ -4689,6 +4722,7 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4689
4722
  targetLeadCount?: undefined;
4690
4723
  existingCount?: undefined;
4691
4724
  createdLeadList?: undefined;
4725
+ selectedLeadListIdUpdated?: undefined;
4692
4726
  jobResult?: undefined;
4693
4727
  } | {
4694
4728
  provider: string;
@@ -4744,6 +4778,7 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4744
4778
  targetLeadCount?: undefined;
4745
4779
  existingCount?: undefined;
4746
4780
  createdLeadList?: undefined;
4781
+ selectedLeadListIdUpdated?: undefined;
4747
4782
  jobResult?: undefined;
4748
4783
  } | {
4749
4784
  provider: string;
@@ -4773,6 +4808,7 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4773
4808
  needsInvalidPostConfirmation?: undefined;
4774
4809
  existingCount?: undefined;
4775
4810
  createdLeadList?: undefined;
4811
+ selectedLeadListIdUpdated?: undefined;
4776
4812
  jobResult?: undefined;
4777
4813
  } | {
4778
4814
  provider: "sales-nav" | "prospeo";
@@ -4822,11 +4858,13 @@ export declare function importLeads(input: ImportLeadsInput): Promise<{
4822
4858
  warnings?: undefined;
4823
4859
  targetLeadCount?: undefined;
4824
4860
  createdLeadList?: undefined;
4861
+ selectedLeadListIdUpdated?: undefined;
4825
4862
  jobResult?: undefined;
4826
4863
  } | {
4827
4864
  provider: "sales-nav" | "prospeo";
4828
4865
  leadListId: string;
4829
4866
  createdLeadList: any;
4867
+ selectedLeadListIdUpdated: boolean;
4830
4868
  jobResult: any;
4831
4869
  jobId: string | undefined;
4832
4870
  targetLeadCount: number | null;