outbound-sdk 0.4.0 → 0.5.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.
Files changed (90) hide show
  1. package/README.md +2 -2
  2. package/dist/alerts/check-evaluate.d.ts +53 -0
  3. package/dist/alerts/check-measure.d.ts +100 -0
  4. package/dist/alerts/check-schema.d.ts +184 -0
  5. package/dist/alerts/check-validate.d.ts +18 -0
  6. package/dist/alerts/index.d.ts +7 -0
  7. package/dist/alerts/index.js +635 -2
  8. package/dist/budget/index.d.ts +2 -0
  9. package/dist/budget/index.js +1 -0
  10. package/dist/cards/index.js +2 -1
  11. package/dist/chunks/{chunk-5CFO3CXG.js → chunk-3S32R2MH.js} +33 -67
  12. package/dist/chunks/{chunk-ZFVHM5JI.js → chunk-5J7GGV62.js} +11 -4
  13. package/dist/chunks/chunk-6TKFISG4.js +676 -0
  14. package/dist/chunks/{chunk-E6DSDCPI.js → chunk-BK5SLY32.js} +92 -101
  15. package/dist/chunks/{chunk-A6WVOCA4.js → chunk-BN6WCAWX.js} +4 -4
  16. package/dist/chunks/{chunk-IZFTTMJP.js → chunk-EHSJGQ5K.js} +5 -5
  17. package/dist/chunks/chunk-HPNGSG5E.js +51 -0
  18. package/dist/chunks/chunk-HWHI4LFY.js +102 -0
  19. package/dist/chunks/{chunk-Y5RAJ6PZ.js → chunk-OLPMBRXM.js} +3 -2
  20. package/dist/chunks/chunk-WGW3ROLY.js +18 -0
  21. package/dist/chunks/{chunk-7ZDS6SZD.js → chunk-WH6V3YNN.js} +25 -0
  22. package/dist/chunks/{chunk-7LNJJ2RO.js → chunk-X4RDBD4J.js} +102 -11
  23. package/dist/chunks/chunk-XL6LJVHJ.js +71 -0
  24. package/dist/chunks/{chunk-5FVKRIEJ.js → chunk-YYCT3NGV.js} +35 -11
  25. package/dist/cli/bin.js +13 -28
  26. package/dist/cli/index.d.ts +3 -0
  27. package/dist/cli/index.js +12 -11
  28. package/dist/cli/update.d.ts +15 -0
  29. package/dist/emailbison/account.d.ts +7 -0
  30. package/dist/emailbison/adapter.d.ts +5 -0
  31. package/dist/emailbison/capabilities.d.ts +78 -0
  32. package/dist/emailbison/client.d.ts +29 -0
  33. package/dist/emailbison/index.d.ts +30 -0
  34. package/dist/emailbison/index.js +1017 -0
  35. package/dist/emailbison/mail.d.ts +5 -0
  36. package/dist/emailbison/map-mail.d.ts +13 -0
  37. package/dist/emailbison/map-sequence.d.ts +12 -0
  38. package/dist/emailbison/map-stats.d.ts +47 -0
  39. package/dist/emailbison/map.d.ts +24 -0
  40. package/dist/emailbison/native-params.d.ts +5 -0
  41. package/dist/emailbison/native-workspace.d.ts +167 -0
  42. package/dist/emailbison/native.d.ts +327 -0
  43. package/dist/emailbison/stats.d.ts +4 -0
  44. package/dist/emailbison/webhooks.d.ts +2 -0
  45. package/dist/fixtures/index.js +6 -6
  46. package/dist/heyreach/capabilities.d.ts +3 -0
  47. package/dist/heyreach/index.js +20 -20
  48. package/dist/index.js +19 -18
  49. package/dist/insights/copy/copy-reuse.d.ts +6 -6
  50. package/dist/insights/copy/shared.d.ts +2 -2
  51. package/dist/insights/copy/step-funnel.d.ts +5 -5
  52. package/dist/insights/copy/variant-test.d.ts +2 -2
  53. package/dist/insights/cost.d.ts +91 -0
  54. package/dist/insights/define.d.ts +22 -1
  55. package/dist/insights/index.d.ts +4 -3
  56. package/dist/insights/index.js +331 -27
  57. package/dist/insights/inputs.generated.d.ts +4 -4
  58. package/dist/insights/ops/campaign-ranking.d.ts +3 -3
  59. package/dist/insights/ops/index.d.ts +2 -2
  60. package/dist/insights/ops/shared.d.ts +11 -1
  61. package/dist/insights/plugin.d.ts +19 -0
  62. package/dist/insights/registry.d.ts +2 -2
  63. package/dist/insights/run-cap.d.ts +35 -0
  64. package/dist/insights/senders/bounce-watch.d.ts +4 -4
  65. package/dist/insights/senders/domain-health.d.ts +2 -2
  66. package/dist/insights/senders/sender-load.d.ts +1 -1
  67. package/dist/insights/tools.d.ts +10 -0
  68. package/dist/instantly/capabilities.d.ts +13 -0
  69. package/dist/instantly/index.js +41 -28
  70. package/dist/internal/adapter.d.ts +12 -0
  71. package/dist/internal/outbound/outbound.d.ts +5 -1
  72. package/dist/internal/request-cap.d.ts +35 -0
  73. package/dist/loader/index.js +2 -2
  74. package/dist/memory/index.js +10 -10
  75. package/dist/providers/index.d.ts +21 -1
  76. package/dist/providers/index.js +1 -1
  77. package/dist/redact/index.js +4 -4
  78. package/dist/smartlead/capabilities.d.ts +5 -0
  79. package/dist/smartlead/index.js +24 -24
  80. package/dist/tools/ai-sdk.js +5 -3
  81. package/dist/tools/claude-agent.js +5 -3
  82. package/dist/tools/index.d.ts +2 -2
  83. package/dist/tools/index.js +11 -6
  84. package/dist/tools/registry.d.ts +20 -1
  85. package/dist/tools/shared.d.ts +20 -1
  86. package/dist/webhooks/index.js +16 -7
  87. package/package.json +8 -2
  88. package/dist/chunks/chunk-K4USHN4C.js +0 -40
  89. package/dist/chunks/chunk-LVQUSKEX.js +0 -17
  90. package/dist/chunks/{chunk-C4LS2HNV.js → chunk-JWGSB7PT.js} +3 -3
@@ -1,6 +1,8 @@
1
1
  import {
2
+ capNext,
3
+ failure,
2
4
  inputProblem
3
- } from "../chunks/chunk-LVQUSKEX.js";
5
+ } from "../chunks/chunk-HWHI4LFY.js";
4
6
  import {
5
7
  count,
6
8
  percentOf,
@@ -9,6 +11,11 @@ import {
9
11
  import {
10
12
  mapConcurrent
11
13
  } from "../chunks/chunk-HZCTYL22.js";
14
+ import {
15
+ cappedAccess,
16
+ requestCounter,
17
+ withGuard
18
+ } from "../chunks/chunk-HPNGSG5E.js";
12
19
  import {
13
20
  noun,
14
21
  shownKey
@@ -16,9 +23,6 @@ import {
16
23
  import {
17
24
  sumCounts
18
25
  } from "../chunks/chunk-PQSTQKRD.js";
19
- import {
20
- profileSlug
21
- } from "../chunks/chunk-NAWZ73QS.js";
22
26
  import {
23
27
  campaignStatusSchema,
24
28
  replyCategorySchema
@@ -27,6 +31,9 @@ import {
27
31
  makeRef,
28
32
  parseRef
29
33
  } from "../chunks/chunk-QAKJ76HB.js";
34
+ import {
35
+ profileSlug
36
+ } from "../chunks/chunk-NAWZ73QS.js";
30
37
  import {
31
38
  OutboundError
32
39
  } from "../chunks/chunk-J7DDZ4C2.js";
@@ -40,12 +47,142 @@ import {
40
47
  // src/insights/plugin.ts
41
48
  import { z as z31 } from "zod";
42
49
 
50
+ // src/insights/cost.ts
51
+ var UNKNOWN = /* @__PURE__ */ Symbol("unknown cost");
52
+ var pages = (cost, records) => cost.pageSize === void 0 ? 1 : Math.max(1, Math.ceil(records / cost.pageSize));
53
+ var pricer = (outbound, costs, most, found) => {
54
+ const of = (action) => {
55
+ const cost = costs[action];
56
+ if (cost === void 0) {
57
+ throw UNKNOWN;
58
+ }
59
+ return cost;
60
+ };
61
+ const list = (action, max) => {
62
+ const cost = of(action);
63
+ return most ? pages(cost, max) * (cost.perPageAtMost ?? cost.perPage) + max * (cost.perRecord ?? 0) + (cost.perWalk ?? 0) : cost.perPage;
64
+ };
65
+ const { capabilities } = outbound;
66
+ return {
67
+ campaigns: (max) => {
68
+ if (found !== void 0) {
69
+ return Math.min(found, max);
70
+ }
71
+ return most ? max : 0;
72
+ },
73
+ campaignsIn: (statuses, max) => {
74
+ const cost = of("campaigns.list");
75
+ const filtered = capabilities["campaigns.status"] !== false;
76
+ if (most) {
77
+ return filtered ? (statuses - 1) * list("campaigns.list", 1) + list("campaigns.list", max) : list("campaigns.list", max);
78
+ }
79
+ const read = found === void 0 ? 1 : pages(cost, Math.min(found, max));
80
+ return (filtered ? Math.max(statuses, read) : read) * cost.perPage;
81
+ },
82
+ capabilities,
83
+ list,
84
+ lookup: (max) => list(
85
+ costs["leads.lookup"] === void 0 ? "leads.list" : "leads.lookup",
86
+ max
87
+ ),
88
+ one: (action) => {
89
+ const cost = of(action);
90
+ return most ? cost.perPage + (cost.perWalk ?? 0) : cost.perPage;
91
+ },
92
+ upTo: (max) => most ? max : 0,
93
+ walk: (action) => {
94
+ const cost = of(action);
95
+ return list(action, cost.pageSize ?? 1);
96
+ }
97
+ };
98
+ };
99
+ var boundsOf = (outbound, cost, input27, found) => {
100
+ const costs = cappedAccess(outbound)?.costs;
101
+ if (cost === void 0 || costs === void 0) {
102
+ return null;
103
+ }
104
+ try {
105
+ return {
106
+ max: cost(input27, pricer(outbound, costs, true, found)),
107
+ min: cost(input27, pricer(outbound, costs, false, found))
108
+ };
109
+ } catch (error) {
110
+ if (error === UNKNOWN) {
111
+ return null;
112
+ }
113
+ throw error;
114
+ }
115
+ };
116
+ var defaultCap = (bounds) => bounds === null ? Infinity : Math.ceil(bounds.max * 1.25) + 4;
117
+ var stops = /* @__PURE__ */ new WeakMap();
118
+ var capStopOf = (cause) => OutboundError.is(cause) ? stops.get(cause) : void 0;
119
+ var capWords = (effect) => effect.isDefault ? `its default cap of ${plural(effect.cap, "request")} for this input` : `the cap of ${plural(effect.cap, "request")} (${effect.setting})`;
120
+ var advice = (stop) => {
121
+ const raise = stop.isDefault ? `pass ${stop.setting} to raise it (Infinity removes the default)` : `raise ${stop.setting}`;
122
+ const text = stop.lower === void 0 ? raise : `lower ${stop.lower.input} to ${stop.lower.to}${stop.lower.sure ? "" : " or less"}, or ${raise}`;
123
+ return `${text.charAt(0).toUpperCase()}${text.slice(1)}.`;
124
+ };
125
+ var capError = (message, stop, provider) => {
126
+ const error = new OutboundError("RateLimited", `${message} ${advice(stop)}`, {
127
+ limit: "call",
128
+ provider
129
+ });
130
+ stops.set(error, stop);
131
+ return error;
132
+ };
133
+ var refusal = (name, bounds, room, stop, provider) => {
134
+ const range = bounds.max > bounds.min ? ` (at most ${bounds.max})` : "";
135
+ const cap = stop.isDefault ? `its default cap for this input is ${plural(stop.cap, "request")}` : `its cap is ${plural(stop.cap, "request")} (${stop.setting})`;
136
+ const why = room < stop.cap ? `only ${plural(room, "request")} ${room === 1 ? "is" : "are"} left of budget()'s run` : cap;
137
+ return capError(
138
+ `${name} needs at least ${plural(bounds.min, "request")} for this input${range}, and ${why}. No request was sent${stop.requests > 0 ? ` after the first ${plural(stop.requests, "request")}` : ""}.`,
139
+ stop,
140
+ provider
141
+ );
142
+ };
143
+ var stopped = (name, stop, provider) => capError(
144
+ `${name} stopped after ${plural(stop.requests, "request")}, at ${capWords(stop)}, before it finished; nothing it read is returned.`,
145
+ stop,
146
+ provider
147
+ );
148
+ var fitting = (outbound, cost, input27, name, room, found) => {
149
+ const fields = input27;
150
+ const current = fields[name];
151
+ if (typeof current !== "number" || current <= 1) {
152
+ return void 0;
153
+ }
154
+ const fits = (value, bound) => {
155
+ const lowered = { ...fields, [name]: value };
156
+ const bounds = boundsOf(outbound, cost, lowered, found);
157
+ return bounds !== null && bounds[bound] <= room;
158
+ };
159
+ const largest = (bound) => {
160
+ let low = 0;
161
+ let high = current - 1;
162
+ while (low < high) {
163
+ const middle = Math.ceil((low + high) / 2);
164
+ if (fits(middle, bound)) {
165
+ low = middle;
166
+ } else {
167
+ high = middle - 1;
168
+ }
169
+ }
170
+ return low >= 1 && fits(low, bound) ? low : 0;
171
+ };
172
+ const sure = largest("max");
173
+ if (sure > 0) {
174
+ return { input: name, sure: true, to: sure };
175
+ }
176
+ const maybe = largest("min");
177
+ return maybe > 0 ? { input: name, sure: false, to: maybe } : void 0;
178
+ };
179
+
43
180
  // src/insights/copy/copy-audit.ts
44
181
  import { z as z2 } from "zod";
45
182
 
46
183
  // src/internal/renamed.ts
47
184
  import { z } from "zod";
48
- var REMOVED_IN = "0.5.0";
185
+ var REMOVED_IN = "0.6.0";
49
186
  var renames = z.registry();
50
187
  var renamed = (to, base) => {
51
188
  const field = base.optional().meta({
@@ -85,6 +222,62 @@ var applyRenames = (fields, input27) => {
85
222
  return { input: Object.fromEntries(moved), notes };
86
223
  };
87
224
 
225
+ // src/insights/run-cap.ts
226
+ var capFor = (outbound, name, max, options) => {
227
+ const set = options.maxRequests;
228
+ if (set !== void 0 && set !== Infinity && (!Number.isInteger(set) || set < 1)) {
229
+ throw new OutboundError(
230
+ "Invalid",
231
+ `${name}: maxRequests must be a positive integer, or Infinity for no default cap`,
232
+ { provider: outbound.provider }
233
+ );
234
+ }
235
+ const setting = options.capSetting ?? "maxRequests";
236
+ return set === void 0 ? {
237
+ cap: Math.min(max, options.capCeiling ?? Infinity),
238
+ isDefault: true,
239
+ setting
240
+ } : { cap: set, isDefault: false, setting };
241
+ };
242
+ var hasRunBudget = (outbound) => "requestBudget" in outbound;
243
+ var runBudgetLeft = (outbound) => hasRunBudget(outbound) && outbound.requestBudget.per === "run" ? outbound.requestBudget.remaining() : Infinity;
244
+ var runCap = (outbound, spec, input27, options) => {
245
+ const bounds = boundsOf(outbound, spec.cost, input27);
246
+ const effect = capFor(outbound, spec.name, defaultCap(bounds), options);
247
+ const stop = (room, found) => ({
248
+ ...effect,
249
+ lower: spec.cost === void 0 || spec.scales === void 0 ? void 0 : fitting(outbound, spec.cost, input27, spec.scales, room, found),
250
+ requests: counter.used()
251
+ });
252
+ const counter = requestCounter(
253
+ effect.cap,
254
+ (provider) => stopped(spec.name, stop(effect.cap), provider)
255
+ );
256
+ const check = (found) => {
257
+ const room = Math.min(effect.cap, counter.used() + runBudgetLeft(outbound));
258
+ const least = boundsOf(outbound, spec.cost, input27, found);
259
+ if (least !== null && least.min > room) {
260
+ throw refusal(
261
+ spec.name,
262
+ least,
263
+ room,
264
+ stop(room, found),
265
+ outbound.provider
266
+ );
267
+ }
268
+ };
269
+ check();
270
+ const isStopped = () => counter.stopped();
271
+ return {
272
+ campaignsFound: check,
273
+ failed: (cause) => {
274
+ throw isStopped() ? stopped(spec.name, stop(effect.cap), outbound.provider) : cause;
275
+ },
276
+ outbound: withGuard(outbound, counter),
277
+ shortNote: () => isStopped() ? `Reads past ${counter.used()} requests were stopped at ${effect.isDefault ? "the default cap for this input" : `the cap (${effect.setting})`}; the answer leaves them out.` : void 0
278
+ };
279
+ };
280
+
88
281
  // src/insights/define.ts
89
282
  var isRedacted = (outbound) => "redacted" in outbound;
90
283
  var maskingOf = (outbound) => isRedacted(outbound) ? outbound.redacted : null;
@@ -108,7 +301,7 @@ var RANK = {
108
301
  exact: 0,
109
302
  sampled: 1
110
303
  };
111
- var track = (outbound, now) => {
304
+ var track = (outbound, now, campaignsFound) => {
112
305
  const notes = [];
113
306
  let requests = 0;
114
307
  let evidence = "exact";
@@ -139,6 +332,7 @@ var track = (outbound, now) => {
139
332
  }
140
333
  return items;
141
334
  },
335
+ campaignsFound,
142
336
  note,
143
337
  now,
144
338
  one: (item) => {
@@ -223,12 +417,17 @@ var prepare = (outbound, spec, given) => {
223
417
  };
224
418
  var execute = async (outbound, spec, input27, options = {}) => {
225
419
  const checked = prepare(outbound, spec, input27);
420
+ const cap = runCap(outbound, spec, checked.input, options);
226
421
  const now = options.now ?? Date.now();
227
- const tracker = track(outbound, now);
422
+ const tracker = track(cap.outbound, now, cap.campaignsFound);
228
423
  for (const note of checked.notes) {
229
424
  tracker.context.note(note);
230
425
  }
231
- const data = await spec.run(tracker.context, checked.input);
426
+ const data = await spec.run(tracker.context, checked.input).catch(cap.failed);
427
+ const short = cap.shortNote();
428
+ if (short !== void 0) {
429
+ tracker.context.partial(short);
430
+ }
232
431
  return {
233
432
  data,
234
433
  insight: spec.name,
@@ -497,6 +696,7 @@ var copyAudit = defineInsight({
497
696
  description: "Problems in a campaign's copy before it sends. Checks every step and variant for a long subject, a long body, too many links, spam words, unbalanced or empty {{ }} variables, words in capitals, repeated exclamation marks, an image or tracking pixel, a missing subject on the first email, and a follow-up whose subject breaks the thread; a LinkedIn campaign skips the email-only checks and flags a connection request over the character limit. Returns each finding with a severity and the text that triggered it, and a count per check. Costs 2 requests. Fixed rules only, no model. A variant whose body the vendor does not return is counted, not judged.",
498
697
  inputSchema: input,
499
698
  key: "copyAudit",
699
+ cost: (_input, price) => price.one("campaigns.get") + price.one("sequence.get"),
500
700
  name: "copy_audit",
501
701
  needs: ["sequence"],
502
702
  next: "Use step_funnel to see whether the steps with findings are also the ones with few replies.",
@@ -583,10 +783,11 @@ var readCampaignsIn = async (context, statuses, max, input27 = "max_campaigns")
583
783
  (room) => campaigns.listAll({ max: room }),
584
784
  cap
585
785
  );
586
- return {
587
- capped: every.capped,
588
- items: every.items.filter((campaign) => wanted.includes(campaign.status))
589
- };
786
+ const items = every.items.filter(
787
+ (campaign) => wanted.includes(campaign.status)
788
+ );
789
+ context.campaignsFound(items.length);
790
+ return { capped: every.capped, items };
590
791
  }
591
792
  const found = [];
592
793
  let capped2 = false;
@@ -600,6 +801,7 @@ var readCampaignsIn = async (context, statuses, max, input27 = "max_campaigns")
600
801
  found.push(...listed.items);
601
802
  capped2 ||= listed.capped;
602
803
  }
804
+ context.campaignsFound(found.length);
603
805
  return { capped: capped2, items: found };
604
806
  };
605
807
 
@@ -985,6 +1187,8 @@ var copyReuse = defineInsight({
985
1187
  description: "How the same piece of copy performs in different campaigns. Reads each campaign's sequence and step stats, matches variants by the hash of their subject and body, and returns every piece of copy used in two or more campaigns with its totals, its reply rate per campaign and the spread between its best and worst campaign, plus the copy with the highest pooled reply rate. Use it to tell a copy problem from an audience problem. Every rate is divided by the same base, leads contacted when every campaign counts them and messages sent otherwise; campaigns with no base in common are listed but not compared. Costs 2 requests per campaign plus the campaign listing. A null count means the vendor does not report it for that variant; it is never 0.",
986
1188
  inputSchema: input2,
987
1189
  key: "copyReuse",
1190
+ cost: (values, price) => price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * (price.one("sequence.get") + price.one("stats")),
1191
+ scales: "max_campaigns",
988
1192
  name: "copy_reuse",
989
1193
  needs: ["sequence", "stats.byStep"],
990
1194
  next: "Use step_funnel on the campaign where the copy does worst, or variant_test where the copy runs against another variant.",
@@ -1182,6 +1386,8 @@ var replyTiming = defineInsight({
1182
1386
  description: "How fast people reply and when. Pairs each received message with the last message sent before it in the same thread (or to the same lead) and returns the median, 75th and 90th percentile of hours to reply, the share of replies within 1, 24 and 72 hours, replies by weekday and by hour of day, the weekday and hour of the sends that drew replies, and how many replies could not be paired; over a quarter unpaired, the answer is marked partial, since a reply to a send from before `since` cannot pair and those are the slow ones. Use it to choose follow-up delays and sending hours. Costs 1 request per page of messages, up to max_messages. A null figure means no reply could be paired; auto-replies are not separated, because messages carry no auto flag.",
1183
1387
  inputSchema: input3,
1184
1388
  key: "replyTiming",
1389
+ cost: (values, price) => price.list("messages.list", values.max_messages) + (values.campaign === null ? 0 : price.upTo(1) * price.one("campaigns.get")),
1390
+ scales: "max_messages",
1185
1391
  name: "reply_timing",
1186
1392
  needs: ["messages.list"],
1187
1393
  next: "Use step_funnel to see which step the replies answer, then set follow-up delays near the median time to reply.",
@@ -1316,6 +1522,7 @@ var stepFunnel = defineInsight({
1316
1522
  description: "Where a campaign's replies come from: one row per sequence step with its action, delay, sends, replies, reply rate with a 95% interval, its share of all replies and how far sends fell from the step before, plus rows per variant when the vendor splits them. Names the step with the most replies and the last step that still earns its place. Use it to decide whether to cut or rewrite follow-ups. Costs 2 requests. A null count means the vendor does not report it; it is never 0.",
1317
1523
  inputSchema: input4,
1318
1524
  key: "stepFunnel",
1525
+ cost: (_input, price) => price.one("sequence.get") + price.one("stats"),
1319
1526
  name: "step_funnel",
1320
1527
  needs: ["sequence", "stats.byStep"],
1321
1528
  next: "Use variant_test on the same campaign to see whether a step's A/B winner is real, or copy_audit to check the copy of a weak step.",
@@ -1522,6 +1729,7 @@ var variantTest = defineInsight({
1522
1729
  description: "Whether a campaign's A/B winner is real. For each step with two or more variants, compares every variant with the leader by a two-proportion test and returns the variants with rates and 95% intervals, the leader, and a verdict: winner, no_difference_yet or too_little_data, with the p-value and a rough number of sends still needed when there is no verdict. Use it before pausing a variant. Costs 1 request. A null count or rate means the vendor does not report it; an empty list means the vendor does not split step stats by variant (variantStatsReported false) or reported no step stats in the date range (null). Variants of a step are divided by the same base; variants with no base in common are not compared.",
1523
1730
  inputSchema: input5,
1524
1731
  key: "variantTest",
1732
+ cost: (_input, price) => price.one("stats"),
1525
1733
  name: "variant_test",
1526
1734
  needs: ["stats.byStep"],
1527
1735
  next: "Use step_funnel to see how much of the campaign's replies the tested step brings, or copy_audit to check the losing variant's copy.",
@@ -1575,6 +1783,10 @@ var lastDays = (now, days, back = 0) => ({
1575
1783
  from: dayOf(now - days * (back + 1) * DAY_MS2),
1576
1784
  to: dayOf(now - (days * back + 1) * DAY_MS2)
1577
1785
  });
1786
+ var campaignTotalsCost = (input27, price) => {
1787
+ const campaigns = price.campaigns(input27.max_campaigns);
1788
+ return price.campaignsIn(new Set(input27.statuses).size, input27.max_campaigns) + (price.capabilities["stats.allCampaigns"] === "full" ? price.upTo(1) * price.one("stats") + price.upTo(campaigns) * price.one("stats") : campaigns * price.one("stats"));
1789
+ };
1578
1790
  var listFields = (costPerCampaign) => ({
1579
1791
  max_campaigns: z8.number().int().min(1).max(200).default(25).describe(`The most campaigns to read. Each costs ${costPerCampaign}.`),
1580
1792
  statuses: statusesInput(["active", "paused", "completed"])
@@ -1813,6 +2025,7 @@ var anomalies = defineInsight({
1813
2025
  description: "Days that broke from trend, for one campaign or the whole workspace: each of the last `days` complete days is held to the `baseline_days` before it, and a daily count `threshold` standard deviations or more from that baseline's mean is returned, newest first, with the metric, the value, the baseline mean, the z-score, the direction and how it was judged. When every baseline day has the same count there is no standard deviation: a day with another count is returned with a null z-score and judgedBy flat_baseline. Use it to spot a sending outage, a bounce spike or a reply surge. Days the vendor has no count for are skipped, never read as zero. With no campaign it reads workspace stats, so it then also needs stats.workspace. Costs one stats request.",
1814
2026
  inputSchema: input6,
1815
2027
  key: "anomalies",
2028
+ cost: (_input, price) => price.one("stats"),
1816
2029
  name: "anomalies",
1817
2030
  needs: ["stats.byDay"],
1818
2031
  // The whole workspace is read from workspace stats, a campaign from its own.
@@ -2136,6 +2349,11 @@ var campaignDiagnosis = defineInsight({
2136
2349
  description: "Why one campaign is underperforming: a list of findings, most serious first, each with a code, a plain-language finding, the numbers behind it and what to look at next. It checks for too little volume to judge, a low reply rate (with its 95% interval), a high bounce rate, few positive replies among replies, sends falling or stopped over the last days, a one or two step sequence, a sender that is not active, open tracking being off, and a schedule or daily limit that holds volume back. Also returns what could not be checked; an empty list means nothing was found, not that all is well. Costs up to 7 requests.",
2137
2350
  inputSchema: input7,
2138
2351
  key: "campaignDiagnosis",
2352
+ cost: (values, price) => {
2353
+ const { capabilities } = price;
2354
+ return price.one("campaigns.get") + price.one("stats") + (capabilities["campaigns.settings"] === false ? 0 : price.one("campaigns.settings")) + (capabilities.sequence === false ? 0 : price.one("sequence.get")) + (capabilities["senders.byCampaign"] === false ? 0 : price.list("senders.list", values.max_senders)) + (capabilities["stats.byDay"] === false ? 0 : price.one("stats"));
2355
+ },
2356
+ scales: "max_senders",
2139
2357
  name: "campaign_diagnosis",
2140
2358
  needs: ["stats.campaign"],
2141
2359
  next: "Follow the `next` of the first finding, for example bounce_watch, step_funnel or pipeline_forecast.",
@@ -2247,6 +2465,8 @@ var campaignRanking = defineInsight({
2247
2465
  description: "Which campaigns are best, ranked fairly: by the low end of the 95% Wilson interval of the reply rate (or positive reply rate; for bounce rate, by the high end, lowest first), so 2 replies from 10 sends cannot outrank 150 from 1,000. Use it to pick winners and losers across a workspace. Returns each campaign with its count, rate, interval and rank, the campaigns left out for too few sends, those whose count the vendor does not report (a null rate is unknown, not zero), and the gap between the top and the median. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
2248
2466
  inputSchema: input8,
2249
2467
  key: "campaignRanking",
2468
+ cost: campaignTotalsCost,
2469
+ scales: "max_campaigns",
2250
2470
  name: "campaign_ranking",
2251
2471
  needs: ["stats.campaign"],
2252
2472
  next: "Use campaign_diagnosis on the campaign ranked last to see why it is behind.",
@@ -2352,6 +2572,8 @@ var channelMix = defineInsight({
2352
2572
  description: "Email against LinkedIn: campaign totals added up per channel, with campaigns, leads contacted, messages sent, replies, positive replies, the reply rate with its 95% interval and, for LinkedIn, the connection acceptance rate; whether the difference in reply rate is more than chance (a two-proportion test); and the same numbers per tool. Use it to decide where to put volume. With one channel present it returns that channel and says there is nothing to compare. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a group whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
2353
2573
  inputSchema: input9,
2354
2574
  key: "channelMix",
2575
+ cost: campaignTotalsCost,
2576
+ scales: "max_campaigns",
2355
2577
  name: "channel_mix",
2356
2578
  needs: ["stats.campaign"],
2357
2579
  next: "Use campaign_ranking to see which campaigns carry the better channel.",
@@ -2525,6 +2747,8 @@ var periodComparison = defineInsight({
2525
2747
  description: "This period against the last: for each campaign, counts and rates for the last `days` complete days and for the `days` before, the change in each, and whether the change in the reply rate is more than chance (a two-proportion test), with the campaigns sorted by the size of that change. Also the same for every campaign added together and, where the adapter has them, for the vendor's workspace totals. Reply and positive reply rates divide by messages sent (`replyRateBasis`), since a period's replies also answer leads contacted before it, and by leads contacted for both periods only when a period does not report messages sent. Use it for a weekly review. Campaigns under min_sent sends in either period are listed apart; a null is a count the vendor does not report, and a rate of a total counts only the campaigns that report both its count and what it divides by (a note says when some are left out). Costs two stats requests per campaign plus two for the workspace.",
2526
2748
  inputSchema: input10,
2527
2749
  key: "periodComparison",
2750
+ cost: (values, price) => price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + 2 * price.campaigns(values.max_campaigns) * price.one("stats") + (price.capabilities["stats.workspace"] === false ? 0 : 2 * price.one("stats")),
2751
+ scales: "max_campaigns",
2528
2752
  name: "period_comparison",
2529
2753
  needs: ["stats.campaign"],
2530
2754
  next: "Use campaign_diagnosis on the campaign whose reply rate fell the most.",
@@ -2685,6 +2909,8 @@ var pipelineForecast = defineInsight({
2685
2909
  description: "The leads one campaign has left and what they should produce: leads counted by status, the leads still active, the days of sending left at the recent daily contact rate, and the replies and positive replies to expect from the remaining leads at the campaign's reply rate so far, each with a low and a high figure from the 95% interval. Use it to decide when to load more leads. It is an estimate and lists what it assumes; a null means the vendor does not report the count behind it. Costs one request per page of leads, plus two stats requests.",
2686
2910
  inputSchema: input11,
2687
2911
  key: "pipelineForecast",
2912
+ cost: (values, price) => price.one("campaigns.get") + price.list("leads.list", values.max_leads) + price.one("stats") + (price.capabilities["stats.byDay"] === false ? 0 : price.one("stats")),
2913
+ scales: "max_leads",
2688
2914
  name: "pipeline_forecast",
2689
2915
  needs: ["leads.byCampaign", "stats.campaign"],
2690
2916
  next: "Use client_report to see every campaign that is running out of leads.",
@@ -2841,6 +3067,13 @@ var clientReport = defineInsight({
2841
3067
  description: "One report for one client or workspace over the last `days` complete days: totals and the change from the period before, the best and worst campaigns by the low end of the interval of the reply rate, campaigns with a bounce problem, unusual days, active campaigns running out of leads, and a short list of action items in plain language, each naming the campaign and the number behind it. Reply rates divide by messages sent (`replyRateBasis`), since a period's replies also answer leads contacted before it, and by leads contacted for both periods only when a period does not report messages sent. Use it for a weekly client update. A section the adapter cannot serve is null and named in `leftOut`, and a null count is one the vendor does not report. Costs two stats requests per campaign, one for the workspace, and for each active campaign two more plus its pages of leads.",
2842
3068
  inputSchema: input12,
2843
3069
  key: "clientReport",
3070
+ cost: (values, price) => {
3071
+ const { capabilities } = price;
3072
+ const campaigns = price.campaigns(values.max_campaigns);
3073
+ const byDay = capabilities["stats.byDay"] !== false;
3074
+ return price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + 2 * campaigns * price.one("stats") + (byDay && capabilities["stats.workspace"] !== false ? price.one("stats") : 0) + (byDay && capabilities["leads.byCampaign"] !== false ? price.upTo(campaigns) * (price.list("leads.list", values.max_leads_per_campaign) + 2 * price.one("stats")) : 0);
3075
+ },
3076
+ scales: "max_campaigns",
2844
3077
  name: "client_report",
2845
3078
  needs: ["stats.campaign"],
2846
3079
  next: "Use campaign_diagnosis on a campaign an action item names, with from and to set to this report's `period`, or period_comparison for every campaign's change.",
@@ -2921,6 +3154,8 @@ var tagRollup = defineInsight({
2921
3154
  // null tag, which reads as an answer. On a combined instance one tool with
2922
3155
  // tags is enough.
2923
3156
  lacks: (outbound) => outbound.fields.campaign["tags"] === false ? "campaign tags" : null,
3157
+ cost: campaignTotalsCost,
3158
+ scales: "max_campaigns",
2924
3159
  name: "tag_rollup",
2925
3160
  needs: ["stats.campaign"],
2926
3161
  next: "Use campaign_ranking to see the campaigns inside the best and the worst tag.",
@@ -3221,6 +3456,8 @@ var accountSummary = defineInsight({
3221
3456
  }
3222
3457
  return strategy === "hash" ? 'email addresses, whose domain it matches people by (under strategy "hash" too: a hashed address keeps no domain)' : "email addresses, whose domain it matches people by";
3223
3458
  },
3459
+ cost: (values, price) => price.capabilities["leads.list"] === false ? price.list("campaigns.list", values.max_campaigns) + price.upTo(values.max_campaigns - 1) * price.list("leads.list", 1) + price.upTo(1) * price.list("leads.list", values.max_leads) : price.list("leads.list", values.max_leads),
3460
+ scales: "max_leads",
3224
3461
  name: "account_summary",
3225
3462
  needs: [],
3226
3463
  next: "Use person_summary with one person's email address or lead ref for their full history, message by message.",
@@ -3419,6 +3656,8 @@ var droppedReplies = defineInsight({
3419
3656
  description: "Replies from prospects that nobody answered. Reads the replies since a date (14 days before now by default), keeps the categories that need an answer, and for each conversation reads its thread, or the lead's timeline when there is no thread, and reports it as dropped when nothing was sent after the reply and it has waited longer than older_than_hours. Returns the dropped replies longest waiting first with hours waiting, category, the campaign and its name, and the lead with their name, email and LinkedIn profile. A reply that could not be checked is counted in totals.unchecked, never reported as dropped. Costs one request per page of replies, one per conversation checked, and one per lead and per campaign among the dropped replies to name them, so at most about three times max_replies requests. totals.moreRepliesExist is true when max_replies left replies unread.",
3420
3657
  inputSchema: input15,
3421
3658
  key: "droppedReplies",
3659
+ cost: (values, price) => price.list("replies.list", values.max_replies) + price.upTo(values.max_replies) * (price.walk("messages.list") + (price.capabilities["leads.get"] === false ? 0 : price.one("leads.get")) + price.one("campaigns.get")),
3660
+ scales: "max_replies",
3422
3661
  name: "dropped_replies",
3423
3662
  needs: ["replies.list"],
3424
3663
  next: "Use person_summary with the lead's ref or email address to read what was sent before answering. Use hot_leads to see who else to contact first.",
@@ -3662,6 +3901,8 @@ var hotLeads = defineInsight({
3662
3901
  description: "Who to call first: leads ranked by a score built from what the vendor reports, namely a positive interest label, replies, clicks, opens and how recent the last reply is. Every score comes with its parts, and the weights are inputs. A lead with no label and no engagement data is left out and counted in totals.withoutData, never scored 0; unsubscribed and bounced leads are left out too. Give a campaign ref to rank one campaign (an unknown one is refused with NotFound), or none to rank every lead the tool lists. A lead the vendor labels out-of-office or bounced (its interest category, or a label reading out of office) earns no reply or recency points, since a vendor's reply count may include automatic replies; a lead it labels negative (the negative or unsubscribe category, or a label reading not interested, wrong person, unsubscribed or do not contact) earns no points at all, from clicks and opens either, and is listed after every lead with a score above 0 while limit leaves room; its reason names the label. Costs one request per page of leads read (max_leads sets the ceiling). When max_leads stops the listing with more leads left, totals.moreLeadsExist is true and it also reads up to 100 replies from the last recency_days days and one request per replied lead the listing missed, at most limit of them, so engaged leads past the cap are still ranked. A part that is null means the vendor does not report that signal.",
3663
3902
  inputSchema: input16,
3664
3903
  key: "hotLeads",
3904
+ cost: (values, price) => price.list("leads.list", values.max_leads) + (values.campaign === null ? 0 : price.upTo(1) * price.one("campaigns.get")) + (price.capabilities["replies.list"] === false || price.capabilities["leads.get"] === false ? 0 : price.upTo(1) * (price.list("replies.list", 100) + price.upTo(values.limit) * price.one("leads.get"))),
3905
+ scales: "max_leads",
3665
3906
  name: "hot_leads",
3666
3907
  needs: [],
3667
3908
  next: "Use person_summary with a lead's ref, email address or LinkedIn profile to read the conversation before calling.",
@@ -3938,6 +4179,8 @@ var leadCollisions = defineInsight({
3938
4179
  // A masked address is the same text for every lead, so every lead would
3939
4180
  // collide with every other. A hashed one still tells people apart.
3940
4181
  maskedOut: ({ fields, strategy }) => fields.includes("email") && strategy === "mask" ? "email addresses, which it matches people by" : null,
4182
+ cost: (values, price) => price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * price.list("leads.list", values.max_leads_per_campaign),
4183
+ scales: "max_campaigns",
3941
4184
  name: "lead_collisions",
3942
4185
  needs: ["leads.byCampaign"],
3943
4186
  next: "Use person_summary with one of the identifiers or lead refs to see what that person was sent and whether they replied.",
@@ -4092,6 +4335,8 @@ var personSummary = defineInsight({
4092
4335
  description: "Everything about one person across campaigns and channels, from their email address, LinkedIn profile or a lead ref: each campaign they are in, how many messages they were sent, whether and how often they replied, which steps they replied to, their interest label, and totals by channel. Records are linked by exact identifier only, so an email finds a LinkedIn record only when a tool holds both for that person. A record the vendor labels out-of-office or bounced counts no replies, since they were automatic. Costs one lookup per identifier, one request to read a lead ref, then up to 2 requests per campaign.",
4093
4336
  inputSchema: input18,
4094
4337
  key: "personSummary",
4338
+ cost: (values, price) => (isLeadRef(values.person) ? price.one("leads.get") + price.upTo(2) * price.lookup(values.max_campaigns) : price.lookup(values.max_campaigns) + price.upTo(1) * price.lookup(values.max_campaigns)) + price.upTo(values.max_campaigns) * (price.one("campaigns.get") + price.walk("messages.list")),
4339
+ scales: "max_campaigns",
4095
4340
  name: "person_summary",
4096
4341
  maskedOut: (masking) => {
4097
4342
  const masked = new Set(masking.fields);
@@ -4237,6 +4482,8 @@ var personalizationGaps = defineInsight({
4237
4482
  description: "Leads in one campaign who will get broken copy because a merge variable has no value for them. Reads the campaign's sequence, finds every {{variable}}, {variable} and %variable% in subjects and bodies, and checks each lead for a value: first name, last name, company, title, email, or a custom field of the same name without regard to case, spaces, underscores or hyphens. Returns the variables with the steps that use them, how many leads each one affects, and the leads missing at least one. A variable with a fallback such as {{firstName|there}} is not a gap. A variable no lead has, such as a sender signature the tool fills in, is listed as unknown, not counted against leads. Costs one request for the sequence plus one per page of leads.",
4238
4483
  inputSchema: input19,
4239
4484
  key: "personalizationGaps",
4485
+ cost: (values, price) => price.one("sequence.get") + price.upTo(1) * price.list("leads.list", values.max_leads),
4486
+ scales: "max_leads",
4240
4487
  name: "personalization_gaps",
4241
4488
  needs: ["sequence", "leads.byCampaign"],
4242
4489
  next: "Fix the leads' fields or add a fallback in the tool, then use lead_collisions to check the same leads are not in another campaign.",
@@ -4369,6 +4616,8 @@ var suppressionCheck = defineInsight({
4369
4616
  // A masked address is the same text for every lead, so nothing can match.
4370
4617
  // A hashed one still matches the same address on the list.
4371
4618
  maskedOut: ({ fields, strategy }) => fields.includes("email") && strategy === "mask" ? "email addresses, which it matches leads to the block list by" : null,
4619
+ cost: (values, price) => price.list("blocklist.list", values.max_block_entries) + price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * price.list("leads.list", values.max_leads_per_campaign),
4620
+ scales: "max_campaigns",
4372
4621
  name: "suppression_check",
4373
4622
  needs: ["blocklist", "leads.byCampaign"],
4374
4623
  next: "Use person_summary with a violating lead's ref or email address to see what they were already sent.",
@@ -4596,6 +4845,12 @@ var bounceWatch = defineInsight({
4596
4845
  description: "Where bounces are too high: the campaigns whose bounce rate (bounced divided by sent) is over a threshold, worst first, each with bounced, sent, the rate and its Wilson interval, and the senders of each such campaign that are themselves over the threshold. Campaigns with too few sends to judge and campaigns with no reported bounce count are listed apart, never as clean. Use it daily, or when a domain's reputation is in doubt. Costs one listing of campaigns and 1 request per campaign, plus 1 listing and up to 1 request per sender for each campaign over the threshold. A null rate means nothing was sent.",
4597
4846
  inputSchema: input21,
4598
4847
  key: "bounceWatch",
4848
+ cost: (values, price) => {
4849
+ const campaigns = price.campaigns(values.max_campaigns);
4850
+ const bySender = values.include_senders && price.capabilities["stats.bySender"] !== false && price.capabilities["senders.byCampaign"] !== false;
4851
+ return price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + campaigns * price.one("stats") + (bySender ? price.upTo(campaigns) * (price.list("senders.list", values.max_senders_per_campaign) + values.max_senders_per_campaign * price.one("stats")) : 0);
4852
+ },
4853
+ scales: "max_campaigns",
4599
4854
  name: "bounce_watch",
4600
4855
  needs: ["stats.campaign"],
4601
4856
  next: "Use domain_health on the senders named here, and settings_audit on the campaigns over the threshold.",
@@ -4804,6 +5059,8 @@ var domainHealth = defineInsight({
4804
5059
  description: "Deliverability per sending domain: for each domain its mailboxes, which DNS records (SPF, DKIM, DMARC, MX) fail, how many mailboxes are disconnected or on a block list, the share of warmup emails landing in spam pooled over its mailboxes, and a risk level with the reasons, worst domain first. LinkedIn seats are listed apart with their connection state. Use it before scaling volume or when replies drop. Costs one listing of senders plus 1 request per sender. A null count or rate means the vendor does not report it; a domain with no DNS record reported has the risk `unknown`, not `low`.",
4805
5060
  inputSchema: input22,
4806
5061
  key: "domainHealth",
5062
+ cost: (values, price) => price.list("senders.list", values.max_senders) + price.upTo(values.max_senders) * price.one("senders.health"),
5063
+ scales: "max_senders",
4807
5064
  name: "domain_health",
4808
5065
  needs: ["senders.list", "senders.health"],
4809
5066
  next: "Use warmup_readiness to see which mailboxes of a risky domain are not ready, or bounce_watch to see whether bounces already rose.",
@@ -5060,6 +5317,13 @@ var senderCapacity = defineInsight({
5060
5317
  description: "Whether the senders can send what the campaigns ask: total daily capacity (the daily limits of active senders added up), the total daily ask of active campaigns, the average messages sent per day over the last days, utilization, and the campaigns whose own senders cannot cover their daily limit. Use it before adding campaigns or when sends fall short. Costs one listing of senders and of active campaigns, then up to 2 requests per campaign and 1 for daily stats, plus 1 per inactive or unlimited sender with split_uncounted. Utilization counts only the sends of the senders in capacity. A null means the vendor does not report the number; a sender or campaign with no reported limit is counted apart, never as 0.",
5061
5318
  inputSchema: input23,
5062
5319
  key: "senderCapacity",
5320
+ cost: (values, price) => {
5321
+ const { capabilities } = price;
5322
+ const campaigns = price.campaigns(values.max_campaigns);
5323
+ const sends = capabilities["stats.workspace"] === false ? campaigns * price.one("stats") : price.one("stats") + (values.split_uncounted && capabilities["stats.bySender"] !== false ? price.upTo(values.max_senders) * price.one("stats") : 0);
5324
+ return price.list("senders.list", values.max_senders) + price.campaignsIn(1, values.max_campaigns) + (capabilities["campaigns.settings"] === false ? 0 : campaigns * (price.one("campaigns.settings") + (capabilities["senders.byCampaign"] === false ? 0 : price.list("senders.list", values.max_senders)))) + (capabilities["stats.byDay"] === false ? 0 : sends);
5325
+ },
5326
+ scales: "max_campaigns",
5063
5327
  name: "sender_capacity",
5064
5328
  needs: ["senders.list"],
5065
5329
  next: "Use sender_load to see which senders are shared by too many campaigns, or warmup_readiness before raising a sender's limit.",
@@ -5154,6 +5418,8 @@ var senderLoad = defineInsight({
5154
5418
  description: "Senders that are overused or unused: the senders attached to more campaigns than allowed, the active senders attached to no campaign, and the campaigns that run on a single sender, on none, or on a sender that is not active. Use it when sends are uneven or before adding a campaign. Costs one listing of senders and of campaigns, then 1 request per campaign. Only campaigns in the given statuses are counted, so a sender used only by a paused campaign shows as unused unless paused is included.",
5155
5419
  inputSchema: input24,
5156
5420
  key: "senderLoad",
5421
+ cost: (values, price) => price.list("senders.list", values.max_senders) + price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * price.list("senders.list", values.max_senders),
5422
+ scales: "max_campaigns",
5157
5423
  name: "sender_load",
5158
5424
  needs: ["senders.list", "senders.byCampaign"],
5159
5425
  next: "Use sender_capacity to see whether the senders can cover the campaigns' daily limits, or warmup_readiness for the senders that are not active.",
@@ -5378,6 +5644,8 @@ var settingsAudit = defineInsight({
5378
5644
  description: "Risky campaign settings, per campaign and by severity: no sending window, a window that includes the weekend or is too long or too short, no timezone, open or click tracking on, a reply that does not stop the sequence, no daily limit, sends too close together, an end date in the past on an active campaign, and a daily limit too high for the number of senders. Returns the findings per campaign, worst first, and a count per check. Use it before launching a campaign or when deliverability drops. Costs one listing of campaigns, then 1 request per campaign, or 2 when its senders can be listed. A setting the vendor reports nothing for is skipped, except a missing window, timezone or daily limit, which the vendor cannot tell apart from one that is not set.",
5379
5645
  inputSchema: input25,
5380
5646
  key: "settingsAudit",
5647
+ cost: (values, price) => price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * (price.one("campaigns.settings") + (price.capabilities["senders.byCampaign"] === false ? 0 : price.list("senders.list", values.max_senders_per_campaign))),
5648
+ scales: "max_campaigns",
5381
5649
  name: "settings_audit",
5382
5650
  needs: ["campaigns.settings"],
5383
5651
  next: "Use sender_capacity to size a daily limit against the senders, or bounce_watch to see whether a flagged campaign already bounces.",
@@ -5518,6 +5786,8 @@ var warmupReadiness = defineInsight({
5518
5786
  description: "Which senders are not ready to send, each with its reasons: warmup off, warmup score under the bar or not reported, status not active, no daily limit and, with check_health, failing DNS records or too many warmup emails in spam. Returns counts by reason and how many are ready. A LinkedIn seat is judged on its status only. Use it before attaching mailboxes to a campaign or raising their limits. Costs one listing of senders, plus 1 request per mailbox with check_health. A null score means the vendor does not report one, which counts as not ready, not as 0.",
5519
5787
  inputSchema: input26,
5520
5788
  key: "warmupReadiness",
5789
+ cost: (values, price) => price.list("senders.list", values.max_senders) + (values.check_health && price.capabilities["senders.health"] !== false ? price.upTo(values.max_senders) * price.one("senders.health") : 0),
5790
+ scales: "max_senders",
5521
5791
  name: "warmup_readiness",
5522
5792
  needs: ["senders.list"],
5523
5793
  next: "Use domain_health for the domains of the mailboxes that are not ready, or sender_capacity to see what the ready ones can send.",
@@ -5580,7 +5850,7 @@ var INSIGHTS = [
5580
5850
  var ENTRIES = INSIGHTS;
5581
5851
 
5582
5852
  // src/insights/plugin.ts
5583
- var runInsightByName = async (outbound, name, input27 = {}, options = {}) => {
5853
+ var entryNamed = (outbound, name) => {
5584
5854
  const entry = ENTRIES.find(
5585
5855
  (candidate) => candidate.name === name || candidate.key === name
5586
5856
  );
@@ -5591,7 +5861,21 @@ var runInsightByName = async (outbound, name, input27 = {}, options = {}) => {
5591
5861
  { provider: outbound.provider }
5592
5862
  );
5593
5863
  }
5594
- return await entry.execute(outbound, input27, options);
5864
+ return entry;
5865
+ };
5866
+ var runInsightByName = async (outbound, name, input27 = {}, options = {}) => await entryNamed(outbound, name).execute(outbound, input27, options);
5867
+ var insightCost = (outbound, name, input27 = {}) => {
5868
+ const entry = entryNamed(outbound, name);
5869
+ const parsed = entry.inputSchema.safeParse(input27);
5870
+ if (!parsed.success) {
5871
+ throw new OutboundError(
5872
+ "Invalid",
5873
+ `${entry.name}: ${parsed.error.issues[0]?.message ?? "the input is not valid"}`,
5874
+ { provider: outbound.provider }
5875
+ );
5876
+ }
5877
+ const bounds = boundsOf(outbound, entry.cost, parsed.data);
5878
+ return bounds === null ? null : { ...bounds, defaultCap: defaultCap(bounds) };
5595
5879
  };
5596
5880
  var listInsights = () => ENTRIES.map((entry) => ({
5597
5881
  description: entry.description,
@@ -5617,6 +5901,7 @@ var insights = () => ({
5617
5901
 
5618
5902
  // src/insights/tools.ts
5619
5903
  import { z as z32 } from "zod";
5904
+ var INSIGHT_TOOL_CEILING = 500;
5620
5905
  var NEXT_FALLBACK = "Pick another of the listed tools to go further.";
5621
5906
  var hintFor = (next, offered) => {
5622
5907
  const hidden = ENTRIES.flatMap(
@@ -5625,8 +5910,9 @@ var hintFor = (next, offered) => {
5625
5910
  const kept = next.split(/(?<=\.)\s+/u).filter((sentence) => !hidden.some((name) => sentence.includes(name)));
5626
5911
  return kept.length === 0 ? NEXT_FALLBACK : kept.join(" ");
5627
5912
  };
5628
- var toTool = (outbound, definition, next) => ({
5629
- call: async (given) => {
5913
+ var toTool = (outbound, definition, next, perCall) => ({
5914
+ call: async (given, callOptions) => {
5915
+ const set = callOptions?.maxRequests ?? perCall;
5630
5916
  try {
5631
5917
  const input27 = jsonInput(given);
5632
5918
  if (input27 === void 0) {
@@ -5635,7 +5921,14 @@ var toTool = (outbound, definition, next) => ({
5635
5921
  `${definition.name}: the input is not JSON`
5636
5922
  );
5637
5923
  }
5638
- const result = await definition.execute(outbound, input27);
5924
+ const result = await definition.execute(
5925
+ outbound,
5926
+ input27,
5927
+ set === void 0 ? {
5928
+ capCeiling: INSIGHT_TOOL_CEILING,
5929
+ capSetting: "maxRequestsPerToolCall"
5930
+ } : { capSetting: "maxRequestsPerToolCall", maxRequests: set }
5931
+ );
5639
5932
  return {
5640
5933
  data: {
5641
5934
  complete: result.meta.complete,
@@ -5651,15 +5944,19 @@ var toTool = (outbound, definition, next) => ({
5651
5944
  ok: true
5652
5945
  };
5653
5946
  } catch (error) {
5654
- const known2 = OutboundError.is(error);
5655
- return {
5656
- error: {
5657
- code: known2 ? error.code : "Provider",
5658
- message: error instanceof Error ? error.message : String(error)
5659
- },
5660
- next: known2 && error.code === "Unsupported" ? "This insight cannot answer here; the message says why. Try another tool." : "Check the input and try again.",
5661
- ok: false
5662
- };
5947
+ const stop = capStopOf(error);
5948
+ if (stop !== void 0) {
5949
+ return failure(
5950
+ error,
5951
+ stop.requests,
5952
+ capNext(stop.cap, stop.isDefault, stop.lower)
5953
+ );
5954
+ }
5955
+ return failure(
5956
+ error,
5957
+ void 0,
5958
+ OutboundError.is(error) && error.code === "Unsupported" ? "This insight cannot answer here; the message says why. Try another tool." : void 0
5959
+ );
5663
5960
  }
5664
5961
  },
5665
5962
  description: definition.description,
@@ -5676,14 +5973,21 @@ var insightTools = (outbound, options = {}) => {
5676
5973
  );
5677
5974
  const names = new Set(offered.map((definition) => definition.name));
5678
5975
  return offered.map(
5679
- (definition) => toTool(outbound, definition, hintFor(definition.next, names))
5976
+ (definition) => toTool(
5977
+ outbound,
5978
+ definition,
5979
+ hintFor(definition.next, names),
5980
+ options.maxRequestsPerToolCall
5981
+ )
5680
5982
  );
5681
5983
  };
5682
5984
  export {
5683
5985
  INSIGHTS,
5986
+ INSIGHT_TOOL_CEILING,
5684
5987
  compareRates,
5685
5988
  defineInsight,
5686
5989
  deviation,
5990
+ insightCost,
5687
5991
  insightTools,
5688
5992
  insights,
5689
5993
  listInsights,