outbound-sdk 0.7.0 → 0.8.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 (121) hide show
  1. package/dist/alerts/index.js +3 -3
  2. package/dist/audit/index.js +1 -1
  3. package/dist/benchmarks/index.js +3 -3
  4. package/dist/budget/index.d.ts +7 -0
  5. package/dist/budget/index.js +3 -3
  6. package/dist/cache/index.js +2 -2
  7. package/dist/cards/index.js +17 -5
  8. package/dist/chunks/{chunk-ZJCVLBAE.js → chunk-4GK56PRO.js} +667 -363
  9. package/dist/chunks/{chunk-MW4C6LTN.js → chunk-7TASUWPC.js} +2 -2
  10. package/dist/chunks/{chunk-M2VXGLLZ.js → chunk-CPACP4YD.js} +1 -1
  11. package/dist/chunks/{chunk-4AVYRVN5.js → chunk-FTK4JS65.js} +31 -10
  12. package/dist/chunks/{chunk-YW6FFVSZ.js → chunk-HXB2IOJJ.js} +1 -1
  13. package/dist/chunks/{chunk-Y7KECJAV.js → chunk-IKKCMWBK.js} +1 -1
  14. package/dist/chunks/{chunk-FHKSLCVW.js → chunk-KVAG5GM2.js} +19 -0
  15. package/dist/chunks/{chunk-7I3EPR23.js → chunk-MPE6VLLY.js} +3 -3
  16. package/dist/chunks/{chunk-UFQ4WMLU.js → chunk-NFWWA7MI.js} +1 -1
  17. package/dist/chunks/{chunk-GL7BABF2.js → chunk-OMCDMELK.js} +1 -1
  18. package/dist/chunks/{chunk-JRL3QRBS.js → chunk-OVTYA3IB.js} +88 -28
  19. package/dist/chunks/{chunk-HIAK2GCI.js → chunk-RMAHQ2OZ.js} +5 -1
  20. package/dist/chunks/{chunk-65YAGEWZ.js → chunk-RQLOPMMR.js} +153 -39
  21. package/dist/chunks/{chunk-OK3GAZMT.js → chunk-SYUMA3CP.js} +12 -0
  22. package/dist/chunks/{chunk-LVZGIKNF.js → chunk-U5AK6OJM.js} +1 -1
  23. package/dist/chunks/{chunk-KTYTE2BU.js → chunk-UAHYPASH.js} +20 -11
  24. package/dist/chunks/{chunk-BNDHEDHD.js → chunk-UOJG4VYF.js} +3 -3
  25. package/dist/chunks/{chunk-LD6F46UT.js → chunk-UWD65SK7.js} +2 -2
  26. package/dist/chunks/{chunk-I7DXXGNZ.js → chunk-UZLFZZ2U.js} +5 -5
  27. package/dist/chunks/{chunk-DNPNTD5W.js → chunk-VVDBCQLK.js} +1 -1
  28. package/dist/chunks/{chunk-IVH3NMQZ.js → chunk-WROJO6XB.js} +1 -1
  29. package/dist/chunks/chunk-XMCNRU4H.js +7279 -0
  30. package/dist/chunks/{chunk-QFC4ZHD3.js → chunk-XYHM4KHC.js} +1 -1
  31. package/dist/chunks/{chunk-NAWZ73QS.js → chunk-YFJ3OQZS.js} +8 -1
  32. package/dist/chunks/tools-II7GXAOM.js +23 -0
  33. package/dist/cli/args.d.ts +48 -0
  34. package/dist/cli/bin.js +14 -14
  35. package/dist/cli/commands.d.ts +0 -7
  36. package/dist/cli/config.d.ts +31 -2
  37. package/dist/cli/envelope.d.ts +2 -0
  38. package/dist/cli/index.d.ts +6 -0
  39. package/dist/cli/index.js +19 -15
  40. package/dist/cli/listing.d.ts +5 -2
  41. package/dist/cli/mcp.d.ts +9 -0
  42. package/dist/cli/offered.d.ts +10 -0
  43. package/dist/cli/options.d.ts +6 -0
  44. package/dist/cli/progress.d.ts +27 -0
  45. package/dist/cli/serve.d.ts +17 -0
  46. package/dist/cli/update.d.ts +25 -2
  47. package/dist/clients/index.js +3 -3
  48. package/dist/combine/index.js +154 -35
  49. package/dist/combine/newest.d.ts +18 -0
  50. package/dist/combine/route.d.ts +19 -5
  51. package/dist/emailbison/index.js +22 -14
  52. package/dist/emailbison/map-sequence.d.ts +2 -1
  53. package/dist/exporter/index.js +1 -1
  54. package/dist/failover/index.js +3 -3
  55. package/dist/fixtures/index.js +4 -4
  56. package/dist/heyreach/capabilities.d.ts +4 -0
  57. package/dist/heyreach/conversations.d.ts +23 -0
  58. package/dist/heyreach/inbox.d.ts +0 -1
  59. package/dist/heyreach/index.js +251 -92
  60. package/dist/identity/index.js +2 -2
  61. package/dist/index.js +7 -7
  62. package/dist/insights/capped.d.ts +6 -6
  63. package/dist/insights/copy/index.d.ts +2 -0
  64. package/dist/insights/copy/reply-timing.d.ts +4 -0
  65. package/dist/insights/cost.d.ts +11 -1
  66. package/dist/insights/define.d.ts +25 -16
  67. package/dist/insights/inbox.d.ts +12 -0
  68. package/dist/insights/index.js +42 -6578
  69. package/dist/insights/inputs.generated.d.ts +60 -24
  70. package/dist/insights/ops/anomalies.d.ts +9 -0
  71. package/dist/insights/ops/index.d.ts +2 -0
  72. package/dist/insights/ops/period-comparison.d.ts +7 -8
  73. package/dist/insights/ops/pipeline-forecast.d.ts +10 -0
  74. package/dist/insights/ops/shared.d.ts +6 -1
  75. package/dist/insights/people/auto-replies.d.ts +11 -7
  76. package/dist/insights/people/dropped-replies.d.ts +13 -4
  77. package/dist/insights/people/hot-leads-read.d.ts +31 -0
  78. package/dist/insights/people/hot-leads.d.ts +15 -3
  79. package/dist/insights/people/index.d.ts +10 -2
  80. package/dist/insights/people/read.d.ts +1 -1
  81. package/dist/insights/registry.d.ts +14 -2
  82. package/dist/insights/run-cap.d.ts +10 -0
  83. package/dist/insights/senders/read.d.ts +0 -3
  84. package/dist/insights/tools.d.ts +12 -0
  85. package/dist/insights/tracked-reads.d.ts +53 -0
  86. package/dist/instantly/capabilities.d.ts +13 -1
  87. package/dist/instantly/index.js +122 -46
  88. package/dist/instantly/map-account.d.ts +2 -1
  89. package/dist/instantly/map-lead.d.ts +1 -0
  90. package/dist/instantly/map.d.ts +4 -3
  91. package/dist/internal/adapter.d.ts +17 -0
  92. package/dist/internal/capabilities.d.ts +13 -0
  93. package/dist/internal/engine/budget.d.ts +9 -1
  94. package/dist/internal/engine/engine.d.ts +2 -1
  95. package/dist/internal/engine/request.d.ts +2 -0
  96. package/dist/internal/errors.d.ts +5 -0
  97. package/dist/internal/hooks.d.ts +11 -0
  98. package/dist/internal/notes.d.ts +16 -0
  99. package/dist/internal/outbound/api.d.ts +14 -0
  100. package/dist/internal/outbound/core.d.ts +4 -1
  101. package/dist/internal/outbound/operation-shared.d.ts +2 -0
  102. package/dist/internal/sha256.d.ts +2 -0
  103. package/dist/internal/url.d.ts +1 -0
  104. package/dist/loader/index.js +3 -3
  105. package/dist/memory/index.js +6 -6
  106. package/dist/redact/index.d.ts +1 -1
  107. package/dist/redact/index.js +107 -19
  108. package/dist/redact/plugin.d.ts +26 -3
  109. package/dist/smartlead/index.js +22 -13
  110. package/dist/smartlead/map.d.ts +3 -2
  111. package/dist/sync/index.js +2 -2
  112. package/dist/tools/ai-sdk.js +5 -5
  113. package/dist/tools/by-name.d.ts +9 -1
  114. package/dist/tools/campaign-tools.d.ts +3 -1
  115. package/dist/tools/claude-agent.js +5 -5
  116. package/dist/tools/index.js +6 -6
  117. package/dist/tools/registry.d.ts +6 -0
  118. package/dist/tools/shared.d.ts +5 -1
  119. package/dist/tracing/index.js +1 -1
  120. package/dist/webhooks/index.js +11 -11
  121. package/package.json +1 -1
@@ -18,7 +18,7 @@ import {
18
18
  senderHealthSchema,
19
19
  tagSchema,
20
20
  webhookSubscriptionSchema
21
- } from "./chunk-HIAK2GCI.js";
21
+ } from "./chunk-RMAHQ2OZ.js";
22
22
  import {
23
23
  plural
24
24
  } from "./chunk-PTZO4QXR.js";
@@ -34,17 +34,17 @@ import {
34
34
  } from "./chunk-POBAY3TI.js";
35
35
  import {
36
36
  sourceIdFor
37
- } from "./chunk-YW6FFVSZ.js";
37
+ } from "./chunk-HXB2IOJJ.js";
38
38
  import {
39
39
  buildUrl
40
- } from "./chunk-NAWZ73QS.js";
40
+ } from "./chunk-YFJ3OQZS.js";
41
41
  import {
42
42
  sha256Hex
43
- } from "./chunk-FHKSLCVW.js";
43
+ } from "./chunk-KVAG5GM2.js";
44
44
  import {
45
45
  OutboundError,
46
46
  redactUrl
47
- } from "./chunk-QFC4ZHD3.js";
47
+ } from "./chunk-XYHM4KHC.js";
48
48
  import {
49
49
  count,
50
50
  field,
@@ -200,16 +200,20 @@ var sleep = (runtime, ms, provider, signal) => (
200
200
  var DEFAULT_LANE = "default";
201
201
  var MIN_FACTOR = 0.1;
202
202
  var RECOVERY_STEP = 0.05;
203
+ var MIN_VENDOR_PAUSE_MS = 1e3;
203
204
  var Budget = class {
204
205
  #options;
205
206
  #waiting = [];
207
+ /** Per lane, until when the vendor's last 429 asked it to wait. */
208
+ #vendorPausedUntil = /* @__PURE__ */ new Map();
206
209
  #inFlight = 0;
207
210
  /** Drops to slow down after a 429, then recovers toward 1. */
208
211
  #factor = 1;
209
212
  constructor(options) {
210
213
  this.#options = options;
211
214
  }
212
- #windows(lane) {
215
+ /** The windows a request on `lane` must fit, after `share` and any slowdown. */
216
+ windows(lane) {
213
217
  const { limits, share } = this.#options;
214
218
  const declared = lane === DEFAULT_LANE ? limits.windows : limits.lanes?.[lane] ?? [];
215
219
  return declared.map((window) => scaleWindow(window, share * this.#factor));
@@ -222,7 +226,7 @@ var Budget = class {
222
226
  if (lane !== DEFAULT_LANE) {
223
227
  const laneWait = await store.reserve(
224
228
  this.#storeKey(lane),
225
- this.#windows(lane),
229
+ this.windows(lane),
226
230
  now
227
231
  );
228
232
  if (laneWait > 0) {
@@ -231,7 +235,7 @@ var Budget = class {
231
235
  }
232
236
  return await store.reserve(
233
237
  this.#options.key,
234
- this.#windows(DEFAULT_LANE),
238
+ this.windows(DEFAULT_LANE),
235
239
  now
236
240
  );
237
241
  }
@@ -288,7 +292,13 @@ var Budget = class {
288
292
  }
289
293
  );
290
294
  }
291
- fire(hooks.onThrottle, { lane, provider, waitMs });
295
+ fire(hooks.onThrottle, {
296
+ cause: now < (this.#vendorPausedUntil.get(lane) ?? 0) ? "vendor" : "budget",
297
+ lane,
298
+ provider,
299
+ waitMs,
300
+ windows: this.windows(lane)
301
+ });
292
302
  await sleep(runtime, waitMs, provider, signal);
293
303
  waited += waitMs;
294
304
  }
@@ -305,9 +315,23 @@ var Budget = class {
305
315
  resume();
306
316
  }
307
317
  }
318
+ /**
319
+ * How long to pause a lane after a 429 that names no wait: the spacing of
320
+ * its tightest published window, at least a second. For a limit of 20 a
321
+ * minute that is 3 s, the time one more request takes to fit.
322
+ */
323
+ vendorPauseMs(lane) {
324
+ const { limits } = this.#options;
325
+ const declared = lane === DEFAULT_LANE ? limits.windows : limits.lanes?.[lane] ?? [];
326
+ return Math.max(
327
+ MIN_VENDOR_PAUSE_MS,
328
+ ...declared.map((window) => Math.ceil(window.perMs / window.requests))
329
+ );
330
+ }
308
331
  /** Called on a 429: pause the lane and halve the rate. */
309
332
  async rateLimited(lane, retryAfterMs, now) {
310
333
  this.#factor = Math.max(MIN_FACTOR, this.#factor / 2);
334
+ this.#vendorPausedUntil.set(lane, now + retryAfterMs);
311
335
  await this.#options.store.pause(this.#storeKey(lane), now + retryAfterMs);
312
336
  }
313
337
  /** Called when the vendor's headers say the window is spent. */
@@ -325,7 +349,7 @@ var Budget = class {
325
349
  ];
326
350
  const perLane = await Promise.all(
327
351
  lanes.map(async (lane) => {
328
- const windows = this.#windows(lane);
352
+ const windows = this.windows(lane);
329
353
  const used = await this.#options.store.usage(
330
354
  this.#storeKey(lane),
331
355
  windows,
@@ -407,11 +431,10 @@ var failureFor = async (response, body, spec, environment) => {
407
431
  const failure = { body, retryAfterMs, status: response.status };
408
432
  const error = adapter.mapError(failure);
409
433
  if (response.status === 429) {
410
- await budget.rateLimited(
411
- spec.lane ?? DEFAULT_LANE,
412
- retryAfterMs ?? 1e3,
413
- now
414
- );
434
+ const lane = spec.lane ?? DEFAULT_LANE;
435
+ const vendorWaitMs = retryAfterMs ?? budget.vendorPauseMs(lane);
436
+ await budget.rateLimited(lane, vendorWaitMs, now);
437
+ return { error, kind: "retry", vendorWaitMs };
415
438
  }
416
439
  if (!isRetryableStatus(response.status)) {
417
440
  throw error;
@@ -496,6 +519,7 @@ var assertRequestBudget = (environment) => {
496
519
  var exhausted = (error, timedOut) => timedOut ? new OutboundError(error.code, error.message, {
497
520
  cause: error.cause,
498
521
  limit: error.limit,
522
+ permanent: error.permanent,
499
523
  provider: error.provider,
500
524
  retryAfterMs: error.retryAfterMs,
501
525
  status: error.status,
@@ -513,7 +537,10 @@ var execute = async (spec, environment) => {
513
537
  throw result.error;
514
538
  }
515
539
  const backoff = state.retry.backoff(attemptNumber, runtime.random());
516
- const delayMs = Math.max(result.retryAfterMs ?? 0, backoff);
540
+ const delayMs = Math.max(
541
+ result.vendorWaitMs ?? result.retryAfterMs ?? 0,
542
+ backoff
543
+ );
517
544
  if (state.deadlineAt !== void 0 && runtime.now() + delayMs > state.deadlineAt) {
518
545
  throw exhausted(result.error, true);
519
546
  }
@@ -524,6 +551,17 @@ var execute = async (spec, environment) => {
524
551
  reason: result.error.message,
525
552
  url: redactUrl(spec.url, adapter.secrets)
526
553
  });
554
+ if (result.vendorWaitMs !== void 0) {
555
+ const lane = spec.lane ?? DEFAULT_LANE;
556
+ state.throttledMs += delayMs;
557
+ fire(hooks.onThrottle, {
558
+ cause: "vendor",
559
+ lane,
560
+ provider: adapter.name,
561
+ waitMs: delayMs,
562
+ windows: environment.budget.windows(lane)
563
+ });
564
+ }
527
565
  await sleep(runtime, delayMs, adapter.name, state.signal);
528
566
  }
529
567
  };
@@ -589,6 +627,7 @@ var RequestEngine = class {
589
627
  beforeRequest: void 0,
590
628
  deadlineAt: merged.deadline === void 0 ? void 0 : this.now() + merged.deadline,
591
629
  maxRequests: merged.maxRequests,
630
+ notes: [],
592
631
  // A cap from the instance is named by the option that set it there.
593
632
  maxRequestsSetBy: options.maxRequests === void 0 && this.#defaults.maxRequests !== void 0 ? "maxRequestsPerCall" : void 0,
594
633
  requests: 0,
@@ -598,9 +637,15 @@ var RequestEngine = class {
598
637
  timeoutMs: merged.timeout ?? DEFAULT_TIMEOUT_MS
599
638
  };
600
639
  }
601
- contextFor(adapter, state) {
640
+ /** `notes` collects what the adapter says it left out; the call's own by default. */
641
+ contextFor(adapter, state, notes = state.notes) {
602
642
  return {
603
- forAdapter: (other) => this.contextFor(other, state),
643
+ forAdapter: (other) => this.contextFor(other, state, notes),
644
+ note: (text) => {
645
+ if (!notes.includes(text)) {
646
+ notes.push(text);
647
+ }
648
+ },
604
649
  request: (spec) => execute(spec, {
605
650
  adapter,
606
651
  budget: this.#budget(adapter),
@@ -706,16 +751,24 @@ var perform = async (core, action, options, body, shared, isAnswer) => {
706
751
  throw mapped;
707
752
  }
708
753
  };
709
- var metaFor = (core, state, input) => ({
710
- complete: input.complete,
711
- evidence: input.evidence,
712
- fetchedAt: input.fetchedAt ?? new Date(core.engine.now()).toISOString(),
713
- provider: core.adapter.name,
714
- requests: state.requests,
715
- stale: input.stale ?? false,
716
- throttledMs: state.throttledMs,
717
- workspaceId: core.adapter.workspaceId
718
- });
754
+ var metaFor = (core, state, input) => {
755
+ for (const text of input.notes ?? []) {
756
+ if (!state.notes.includes(text)) {
757
+ state.notes.push(text);
758
+ }
759
+ }
760
+ return {
761
+ complete: input.complete,
762
+ evidence: input.evidence,
763
+ fetchedAt: input.fetchedAt ?? new Date(core.engine.now()).toISOString(),
764
+ notes: [...state.notes],
765
+ provider: core.adapter.name,
766
+ requests: state.requests,
767
+ stale: input.stale ?? false,
768
+ throttledMs: state.throttledMs,
769
+ workspaceId: core.adapter.workspaceId
770
+ };
771
+ };
719
772
  var matches = (schema, record) => schema.safeParse(record).success;
720
773
  var checked = (core, schema, records, action) => {
721
774
  const items = [];
@@ -726,7 +779,7 @@ var checked = (core, schema, records, action) => {
726
779
  throw new OutboundError(
727
780
  "Provider",
728
781
  `The ${core.adapter.name} adapter returned an invalid record for ${action}${where}`,
729
- { provider: core.adapter.name }
782
+ { permanent: true, provider: core.adapter.name }
730
783
  );
731
784
  }
732
785
  items.push(record);
@@ -857,6 +910,7 @@ var PageWalker = class {
857
910
  aborted: error.aborted,
858
911
  cause: error,
859
912
  limit: error.limit,
913
+ permanent: error.permanent,
860
914
  partial: {
861
915
  cursor: this.#cursor,
862
916
  items,
@@ -921,6 +975,7 @@ var fetchPage = (core, spec, request, options, shared) => perform(
921
975
  complete,
922
976
  evidence: output2.evidence,
923
977
  fetchedAt: output2.fetchedAt,
978
+ notes: output2.notes,
924
979
  stale: output2.stale
925
980
  })
926
981
  };
@@ -982,6 +1037,7 @@ var getOne = (core, spec, id, options, shared, missingIsAnswer = false) => perfo
982
1037
  complete: true,
983
1038
  evidence: output2.evidence,
984
1039
  fetchedAt: output2.fetchedAt,
1040
+ notes: output2.notes,
985
1041
  stale: output2.stale
986
1042
  })
987
1043
  };
@@ -1271,12 +1327,48 @@ var senderGet = (core) => ({
1271
1327
  toOperation: (id) => ({ id, kind: "senders.get" }),
1272
1328
  what: "Sender"
1273
1329
  });
1330
+ var manyAddresses = (core, given) => {
1331
+ if (given === void 0) {
1332
+ return void 0;
1333
+ }
1334
+ requireCapability(
1335
+ core.gate,
1336
+ "leads.lookupMany",
1337
+ "Finding the leads of many email addresses at once"
1338
+ );
1339
+ const emails = given.map((each) => each.trim().toLowerCase());
1340
+ if (emails.length === 0 || emails.some((each) => !each.includes("@"))) {
1341
+ throw new OutboundError(
1342
+ "Invalid",
1343
+ "emails must list at least one email address, and only addresses"
1344
+ );
1345
+ }
1346
+ return emails;
1347
+ };
1348
+ var checkInterest = (core, interest) => {
1349
+ if (interest === void 0) {
1350
+ return;
1351
+ }
1352
+ requireCapability(
1353
+ core.gate,
1354
+ "leads.byInterest",
1355
+ "Listing only the leads labelled positive"
1356
+ );
1357
+ if (interest !== "positive") {
1358
+ throw new OutboundError(
1359
+ "Invalid",
1360
+ `interest takes "positive", not "${interest}"`
1361
+ );
1362
+ }
1363
+ };
1274
1364
  var leadList = (core) => ({
1275
1365
  action: "leads.list",
1276
1366
  takes: {
1277
1367
  campaignId: true,
1278
1368
  domain: true,
1279
1369
  email: true,
1370
+ emails: true,
1371
+ interest: true,
1280
1372
  linkedinUrl: true,
1281
1373
  listId: true,
1282
1374
  since: true,
@@ -1285,7 +1377,7 @@ var leadList = (core) => ({
1285
1377
  // A lookup returns one record per campaign the person is in. On a vendor
1286
1378
  // whose lead id is the same in every campaign those records share a ref,
1287
1379
  // so the campaign is part of what tells them apart.
1288
- keyOf: (lead, filters) => filters.email === void 0 && filters.linkedinUrl === void 0 && filters.domain === void 0 ? lead.ref : `${lead.ref} ${lead.campaignRef ?? ""}`,
1380
+ keyOf: (lead, filters) => filters.email === void 0 && filters.emails === void 0 && filters.linkedinUrl === void 0 && filters.domain === void 0 ? lead.ref : `${lead.ref} ${lead.campaignRef ?? ""}`,
1289
1381
  prepare: (filters) => {
1290
1382
  if (filters.campaignId !== void 0 && filters.listId !== void 0) {
1291
1383
  throw new OutboundError(
@@ -1301,6 +1393,8 @@ var leadList = (core) => ({
1301
1393
  "Finding a lead by email or LinkedIn profile"
1302
1394
  );
1303
1395
  }
1396
+ const emails = manyAddresses(core, filters.emails);
1397
+ checkInterest(core, filters.interest);
1304
1398
  const domain = filters.domain?.trim().toLowerCase();
1305
1399
  if (domain !== void 0) {
1306
1400
  requireCapability(
@@ -1323,7 +1417,7 @@ var leadList = (core) => ({
1323
1417
  "leads.byCampaign",
1324
1418
  "Listing a campaign's leads"
1325
1419
  );
1326
- } else if (!lookup2 && domain === void 0) {
1420
+ } else if (!lookup2 && domain === void 0 && emails === void 0) {
1327
1421
  requireCapability(core.gate, "leads.list", "Listing leads");
1328
1422
  }
1329
1423
  if (hasRange(filters)) {
@@ -1333,6 +1427,8 @@ var leadList = (core) => ({
1333
1427
  campaignId: filters.campaignId,
1334
1428
  domain,
1335
1429
  email: filters.email?.trim().toLowerCase(),
1430
+ emails: emails === void 0 ? void 0 : [...new Set(emails)],
1431
+ interest: filters.interest,
1336
1432
  linkedinUrl: filters.linkedinUrl?.trim(),
1337
1433
  listId: filters.listId,
1338
1434
  ...normalizeRange(filters)
@@ -1356,6 +1452,7 @@ var leadGet = (core) => ({
1356
1452
  var messageList = (core) => ({
1357
1453
  action: "messages.list",
1358
1454
  takes: {
1455
+ byHand: true,
1359
1456
  campaignId: true,
1360
1457
  include: true,
1361
1458
  leadId: true,
@@ -1366,6 +1463,13 @@ var messageList = (core) => ({
1366
1463
  keyOf: refOf2,
1367
1464
  prepare: (filters) => {
1368
1465
  requireCapability(core.gate, "messages.list", "Listing messages");
1466
+ if (filters.byHand !== void 0) {
1467
+ requireCapability(
1468
+ core.gate,
1469
+ "messages.byHand",
1470
+ "Listing only the messages sent by hand"
1471
+ );
1472
+ }
1369
1473
  if (filters.threadId !== void 0) {
1370
1474
  requireCapability(
1371
1475
  core.gate,
@@ -1384,6 +1488,7 @@ var messageList = (core) => ({
1384
1488
  );
1385
1489
  }
1386
1490
  return {
1491
+ byHand: filters.byHand,
1387
1492
  campaignId: filters.campaignId,
1388
1493
  include: filters.include,
1389
1494
  leadId: filters.leadId,
@@ -1395,6 +1500,7 @@ var messageList = (core) => ({
1395
1500
  toOperation: (filters, page) => ({
1396
1501
  kind: "messages.list",
1397
1502
  query: {
1503
+ byHand: filters.byHand,
1398
1504
  campaignId: filters.campaignId,
1399
1505
  includeBody: wantsBody(filters.include),
1400
1506
  leadId: filters.leadId,
@@ -1411,6 +1517,7 @@ var replyList = (core) => ({
1411
1517
  campaignId: true,
1412
1518
  category: true,
1413
1519
  include: true,
1520
+ includeInbox: true,
1414
1521
  since: true,
1415
1522
  unread: true,
1416
1523
  until: true
@@ -1446,6 +1553,7 @@ var replyList = (core) => ({
1446
1553
  campaignId: filters.campaignId,
1447
1554
  category: filters.category,
1448
1555
  include: filters.include,
1556
+ includeInbox: filters.includeInbox,
1449
1557
  unread: filters.unread,
1450
1558
  ...normalizeRange(filters)
1451
1559
  };
@@ -1457,6 +1565,7 @@ var replyList = (core) => ({
1457
1565
  campaignId: filters.campaignId,
1458
1566
  category: filters.category,
1459
1567
  includeBody: wantsBody(filters.include),
1568
+ includeInbox: filters.includeInbox,
1460
1569
  since: filters.since,
1461
1570
  unread: filters.unread,
1462
1571
  until: filters.until,
@@ -1519,6 +1628,7 @@ var readStats = async (core, options = {}) => {
1519
1628
  complete: true,
1520
1629
  evidence: output2.evidence,
1521
1630
  fetchedAt: output2.fetchedAt,
1631
+ notes: output2.notes,
1522
1632
  stale: output2.stale
1523
1633
  }),
1524
1634
  rows: checked(core, metricRowSchema, output2.items, "stats")
@@ -2295,14 +2405,18 @@ var Outbound = class _Outbound {
2295
2405
  const narrowed = narrowCapabilities(declared, plugins);
2296
2406
  const run = composeOperations(
2297
2407
  [...plugins, ...layers],
2298
- (operation, info) => dispatch(
2299
- {
2300
- adapter,
2301
- capabilities: declared,
2302
- ctx: engine.contextFor(adapter, info.state)
2303
- },
2304
- operation
2305
- )
2408
+ async (operation, info) => {
2409
+ const notes = [];
2410
+ const output2 = await dispatch(
2411
+ {
2412
+ adapter,
2413
+ capabilities: declared,
2414
+ ctx: engine.contextFor(adapter, info.state, notes)
2415
+ },
2416
+ operation
2417
+ );
2418
+ return notes.length === 0 ? output2 : { ...output2, notes };
2419
+ }
2306
2420
  );
2307
2421
  this.#options = options;
2308
2422
  this.#plugins = plugins;
@@ -4,6 +4,17 @@ import {
4
4
  stripQuotedHistory
5
5
  } from "./chunk-FALWG5U3.js";
6
6
 
7
+ // src/internal/notes.ts
8
+ var notNegative = (value, { note, unit, vendor, what }) => {
9
+ if (value === null || value >= 0) {
10
+ return value;
11
+ }
12
+ note(
13
+ `${what} is negative in ${vendor} (${value}${unit === void 0 ? "" : ` ${unit}`}); left out.`
14
+ );
15
+ return null;
16
+ };
17
+
7
18
  // src/internal/auto-reply.ts
8
19
  var AUTO_REPLY_WITHIN_MS = 6e4;
9
20
  var MACHINE_SENDER = /^[^@]*(?:no-?reply|do-?not-?reply|auto-?respon|auto-?reply|mailer-daemon|postmaster)[^@]*@/iu;
@@ -46,6 +57,7 @@ var answeredAtOnce = (sentAt, repliedAt) => {
46
57
  };
47
58
 
48
59
  export {
60
+ notNegative,
49
61
  detectAutoReply,
50
62
  answeredAtOnce
51
63
  };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-QGRZDTX4.js";
4
4
  import {
5
5
  makeRef
6
- } from "./chunk-YW6FFVSZ.js";
6
+ } from "./chunk-HXB2IOJJ.js";
7
7
  import {
8
8
  compactObject
9
9
  } from "./chunk-45TXPJW7.js";
@@ -1,21 +1,24 @@
1
+ import {
2
+ notNegative
3
+ } from "./chunk-SYUMA3CP.js";
1
4
  import {
2
5
  fromOne,
3
6
  leadStanding,
4
7
  toVariant,
5
8
  variantKey
6
- } from "./chunk-BNDHEDHD.js";
9
+ } from "./chunk-UOJG4VYF.js";
7
10
  import {
8
11
  eventData,
9
12
  recordBase,
10
13
  refTo
11
- } from "./chunk-LVZGIKNF.js";
14
+ } from "./chunk-U5AK6OJM.js";
12
15
  import {
13
16
  SCHEMA_VERSION
14
17
  } from "./chunk-QGRZDTX4.js";
15
18
  import {
16
19
  sha256,
17
20
  stableId
18
- } from "./chunk-FHKSLCVW.js";
21
+ } from "./chunk-KVAG5GM2.js";
19
22
  import {
20
23
  count,
21
24
  emailAddress,
@@ -90,35 +93,41 @@ var variantOf = (raw, index) => toVariant(
90
93
  text(raw.variant_label) ?? variantKey(index)
91
94
  );
92
95
  var delayDays = (step) => count(field(step.seq_delay_details, "delay_in_days")) ?? count(field(step.seq_delay_details, "delayInDays"));
93
- var toStep = (step, position) => {
96
+ var toStep = (step, position, note) => {
94
97
  const variants = objects(step.sequence_variants).filter(
95
98
  (variant) => flag(variant.is_deleted) !== true
96
99
  );
100
+ const index = fromOne(step.seq_number) ?? position;
97
101
  return {
98
102
  action: "email",
99
103
  branch: null,
100
- delayDays: delayDays(step),
101
- index: fromOne(step.seq_number) ?? position,
104
+ delayDays: notNegative(delayDays(step), {
105
+ note,
106
+ unit: "days",
107
+ vendor: "Smartlead",
108
+ what: `Step ${index + 1}'s delay`
109
+ }),
110
+ index,
102
111
  parentIndex: null,
103
112
  // With no variants the copy is on the step itself.
104
113
  variants: (variants.length === 0 ? [step] : variants).map(variantOf)
105
114
  };
106
115
  };
107
- var toSteps = (steps) => objects(steps).map(toStep).toSorted((left, right) => left.index - right.index).map((step, position, sorted) => ({
116
+ var toSteps = (steps, note) => objects(steps).map((step, position) => toStep(step, position, note)).toSorted((left, right) => left.index - right.index).map((step, position, sorted) => ({
108
117
  ...step,
109
118
  parentIndex: sorted[position - 1]?.index ?? null
110
119
  }));
111
- var toSequence = (identity, campaignId, body) => {
120
+ var toSequence = (identity, campaignId, body, note) => {
112
121
  const steps = unwrap(body);
113
122
  return {
114
123
  ...recordBase(identity, campaignId, steps ?? null),
115
124
  campaignRef: refTo(identity, campaignId) ?? "",
116
125
  kind: "main",
117
126
  name: null,
118
- steps: toSteps(steps)
127
+ steps: toSteps(steps, note)
119
128
  };
120
129
  };
121
- var toSubsequence = (identity, parentId, campaign, body) => {
130
+ var toSubsequence = (identity, parentId, campaign, body, note) => {
122
131
  const steps = unwrap(body);
123
132
  return {
124
133
  ...recordBase(identity, text(campaign.id) ?? "", {
@@ -128,7 +137,7 @@ var toSubsequence = (identity, parentId, campaign, body) => {
128
137
  campaignRef: refTo(identity, parentId) ?? "",
129
138
  kind: "subsequence",
130
139
  name: text(campaign.name),
131
- steps: toSteps(steps)
140
+ steps: toSteps(steps, note)
132
141
  };
133
142
  };
134
143
  var senderStatus = (raw) => {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  buildUrl
3
- } from "./chunk-NAWZ73QS.js";
3
+ } from "./chunk-YFJ3OQZS.js";
4
4
  import {
5
5
  stableId
6
- } from "./chunk-FHKSLCVW.js";
6
+ } from "./chunk-KVAG5GM2.js";
7
7
  import {
8
8
  OutboundError
9
- } from "./chunk-QFC4ZHD3.js";
9
+ } from "./chunk-XYHM4KHC.js";
10
10
  import {
11
11
  count,
12
12
  isJsonArray,
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  eventData,
3
3
  refTo
4
- } from "./chunk-LVZGIKNF.js";
4
+ } from "./chunk-U5AK6OJM.js";
5
5
  import {
6
6
  SCHEMA_VERSION
7
7
  } from "./chunk-QGRZDTX4.js";
8
8
  import {
9
9
  stableId
10
- } from "./chunk-FHKSLCVW.js";
10
+ } from "./chunk-KVAG5GM2.js";
11
11
  import {
12
12
  compactObject,
13
13
  emailAddress,
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  detectAutoReply
3
- } from "./chunk-OK3GAZMT.js";
3
+ } from "./chunk-SYUMA3CP.js";
4
4
  import {
5
5
  createVendorClient,
6
6
  leadStanding,
7
7
  listIn
8
- } from "./chunk-BNDHEDHD.js";
8
+ } from "./chunk-UOJG4VYF.js";
9
9
  import {
10
10
  normalizeBody
11
11
  } from "./chunk-FALWG5U3.js";
@@ -14,16 +14,16 @@ import {
14
14
  eventTypesOf,
15
15
  recordBase,
16
16
  refTo
17
- } from "./chunk-LVZGIKNF.js";
17
+ } from "./chunk-U5AK6OJM.js";
18
18
  import {
19
19
  SCHEMA_VERSION
20
20
  } from "./chunk-QGRZDTX4.js";
21
21
  import {
22
22
  stableId
23
- } from "./chunk-FHKSLCVW.js";
23
+ } from "./chunk-KVAG5GM2.js";
24
24
  import {
25
25
  requireObject
26
- } from "./chunk-QFC4ZHD3.js";
26
+ } from "./chunk-XYHM4KHC.js";
27
27
  import {
28
28
  count,
29
29
  emailAddress,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  OutboundError
3
- } from "./chunk-QFC4ZHD3.js";
3
+ } from "./chunk-XYHM4KHC.js";
4
4
 
5
5
  // src/internal/tracking.ts
6
6
  var recorded = (campaign, metric) => (metric === "opens" ? campaign.opened : campaign.clicked) ?? 0;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  stableId
3
- } from "./chunk-FHKSLCVW.js";
3
+ } from "./chunk-KVAG5GM2.js";
4
4
 
5
5
  // src/cache/index.ts
6
6
  var memoryCacheStore = (maxEntries = 500) => {