outbound-sdk 0.5.0 → 0.7.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 (130) hide show
  1. package/dist/alerts/check-schema.d.ts +1 -1
  2. package/dist/alerts/index.js +6 -6
  3. package/dist/audit/index.js +2 -2
  4. package/dist/benchmarks/index.js +4 -4
  5. package/dist/budget/index.js +2 -2
  6. package/dist/cards/format.d.ts +1 -1
  7. package/dist/cards/index.js +101 -62
  8. package/dist/cards/parts.d.ts +1 -6
  9. package/dist/chunks/{chunk-BLCJHP5H.js → chunk-45TXPJW7.js} +1 -0
  10. package/dist/chunks/chunk-4AVYRVN5.js +239 -0
  11. package/dist/chunks/{chunk-YYCT3NGV.js → chunk-65YAGEWZ.js} +24 -7
  12. package/dist/chunks/{chunk-BN6WCAWX.js → chunk-7I3EPR23.js} +3 -3
  13. package/dist/chunks/{chunk-3S32R2MH.js → chunk-BNDHEDHD.js} +2 -53
  14. package/dist/chunks/chunk-DNPNTD5W.js +81 -0
  15. package/dist/chunks/chunk-FALWG5U3.js +56 -0
  16. package/dist/chunks/{chunk-OLPMBRXM.js → chunk-GL7BABF2.js} +2 -2
  17. package/dist/chunks/{chunk-ZOAG2C6V.js → chunk-HIAK2GCI.js} +9 -2
  18. package/dist/chunks/{chunk-6TKFISG4.js → chunk-I7DXXGNZ.js} +42 -9
  19. package/dist/chunks/{chunk-BK5SLY32.js → chunk-JRL3QRBS.js} +264 -76
  20. package/dist/chunks/{chunk-EHSJGQ5K.js → chunk-KTYTE2BU.js} +4 -3
  21. package/dist/chunks/{chunk-JWGSB7PT.js → chunk-LD6F46UT.js} +2 -2
  22. package/dist/chunks/{chunk-2D42TQFU.js → chunk-LVZGIKNF.js} +2 -2
  23. package/dist/chunks/{chunk-PQSTQKRD.js → chunk-M2VXGLLZ.js} +35 -2
  24. package/dist/chunks/{chunk-5J7GGV62.js → chunk-MW4C6LTN.js} +2 -2
  25. package/dist/chunks/chunk-OK3GAZMT.js +51 -0
  26. package/dist/chunks/{chunk-BOWXGMN3.js → chunk-POBAY3TI.js} +80 -4
  27. package/dist/chunks/{chunk-J7DDZ4C2.js → chunk-QFC4ZHD3.js} +1 -1
  28. package/dist/chunks/{chunk-GFDNRWR3.js → chunk-UFQ4WMLU.js} +1 -1
  29. package/dist/chunks/{chunk-WGW3ROLY.js → chunk-Y7KECJAV.js} +1 -1
  30. package/dist/chunks/{chunk-QAKJ76HB.js → chunk-YW6FFVSZ.js} +1 -1
  31. package/dist/chunks/{chunk-X4RDBD4J.js → chunk-ZJCVLBAE.js} +445 -119
  32. package/dist/cli/bin.js +14 -14
  33. package/dist/cli/by-name.d.ts +28 -0
  34. package/dist/cli/commands.d.ts +2 -1
  35. package/dist/cli/config.d.ts +3 -2
  36. package/dist/cli/envelope.d.ts +50 -0
  37. package/dist/cli/index.d.ts +3 -0
  38. package/dist/cli/index.js +13 -13
  39. package/dist/cli/listing.d.ts +13 -0
  40. package/dist/cli/native.d.ts +4 -0
  41. package/dist/cli/options.d.ts +88 -0
  42. package/dist/cli/output.d.ts +21 -0
  43. package/dist/cli/suggest.d.ts +10 -0
  44. package/dist/clients/index.js +6 -6
  45. package/dist/combine/index.js +7 -7
  46. package/dist/emailbison/capabilities.d.ts +1 -0
  47. package/dist/emailbison/index.js +38 -13
  48. package/dist/emailbison/map-stats.d.ts +10 -0
  49. package/dist/exporter/index.js +2 -2
  50. package/dist/failover/index.js +2 -2
  51. package/dist/fixtures/index.js +4 -4
  52. package/dist/heyreach/capabilities.d.ts +3 -0
  53. package/dist/heyreach/index.js +36 -12
  54. package/dist/heyreach/map-account.d.ts +2 -2
  55. package/dist/identity/index.js +2 -2
  56. package/dist/index.js +9 -7
  57. package/dist/insights/copy/audit-samples.d.ts +24 -0
  58. package/dist/insights/copy/audit-variant.d.ts +34 -0
  59. package/dist/insights/copy/copy-audit.d.ts +26 -12
  60. package/dist/insights/copy/copy-preview.d.ts +71 -0
  61. package/dist/insights/copy/copy-reuse.d.ts +0 -13
  62. package/dist/insights/copy/index.d.ts +15 -0
  63. package/dist/insights/copy/reply-timing.d.ts +4 -0
  64. package/dist/insights/copy/reuse-base.d.ts +0 -2
  65. package/dist/insights/copy/shared.d.ts +7 -9
  66. package/dist/insights/copy/step-funnel.d.ts +21 -18
  67. package/dist/insights/copy/variant-test.d.ts +2 -8
  68. package/dist/insights/index.js +1357 -717
  69. package/dist/insights/inputs.generated.d.ts +67 -34
  70. package/dist/insights/ops/campaign-diagnosis.d.ts +2 -2
  71. package/dist/insights/ops/client-report.d.ts +0 -2
  72. package/dist/insights/ops/diagnosis-checks.d.ts +20 -1
  73. package/dist/insights/ops/index.d.ts +2 -4
  74. package/dist/insights/ops/pipeline-forecast.d.ts +17 -6
  75. package/dist/insights/ops/shared.d.ts +0 -2
  76. package/dist/insights/people/account-summary.d.ts +14 -1
  77. package/dist/insights/people/auto-replies.d.ts +14 -0
  78. package/dist/insights/people/dropped-replies.d.ts +1 -1
  79. package/dist/insights/people/hot-leads.d.ts +5 -1
  80. package/dist/insights/people/index.d.ts +4 -0
  81. package/dist/insights/people/lead-collisions.d.ts +11 -2
  82. package/dist/insights/people/person-summary.d.ts +19 -3
  83. package/dist/insights/people/personalization-gaps.d.ts +14 -8
  84. package/dist/insights/people/suppression-check.d.ts +9 -0
  85. package/dist/insights/registry.d.ts +20 -8
  86. package/dist/insights/senders/bounce-watch.d.ts +0 -11
  87. package/dist/insights/senders/domain-health.d.ts +0 -7
  88. package/dist/insights/senders/index.d.ts +0 -4
  89. package/dist/insights/senders/sender-load.d.ts +0 -2
  90. package/dist/insights/step.d.ts +15 -0
  91. package/dist/insights/types.d.ts +1 -1
  92. package/dist/insights/variables.d.ts +35 -0
  93. package/dist/instantly/capabilities.d.ts +4 -0
  94. package/dist/instantly/index.js +265 -53
  95. package/dist/instantly/map-stats.d.ts +4 -0
  96. package/dist/instantly/stats-tracking.d.ts +19 -0
  97. package/dist/instantly/thread.d.ts +9 -0
  98. package/dist/internal/adapter.d.ts +5 -0
  99. package/dist/internal/auto-reply.d.ts +20 -0
  100. package/dist/internal/capabilities.d.ts +2 -0
  101. package/dist/internal/entities-account.d.ts +1 -0
  102. package/dist/internal/entities.d.ts +79 -2
  103. package/dist/internal/fields.d.ts +37 -1
  104. package/dist/internal/metrics.d.ts +23 -1
  105. package/dist/internal/outbound/api.d.ts +2 -0
  106. package/dist/internal/records.d.ts +2 -2
  107. package/dist/internal/reply-people.d.ts +37 -0
  108. package/dist/internal/runway.d.ts +42 -0
  109. package/dist/internal/sender-screen.d.ts +9 -0
  110. package/dist/internal/tracking.d.ts +33 -0
  111. package/dist/loader/index.js +4 -4
  112. package/dist/memory/data.d.ts +2 -1
  113. package/dist/memory/index.js +23 -12
  114. package/dist/redact/index.js +3 -3
  115. package/dist/smartlead/capabilities.d.ts +4 -0
  116. package/dist/smartlead/index.js +154 -38
  117. package/dist/smartlead/map-account.d.ts +3 -0
  118. package/dist/smartlead/stats-tracking.d.ts +22 -0
  119. package/dist/sync/index.js +2 -2
  120. package/dist/tools/ai-sdk.js +8 -7
  121. package/dist/tools/by-name.d.ts +18 -0
  122. package/dist/tools/campaign-tools.d.ts +6 -2
  123. package/dist/tools/claude-agent.js +8 -7
  124. package/dist/tools/index.js +9 -8
  125. package/dist/tools/shared.d.ts +7 -0
  126. package/dist/tracing/index.js +2 -2
  127. package/dist/webhooks/index.js +12 -10
  128. package/package.json +1 -1
  129. package/dist/chunks/chunk-HWHI4LFY.js +0 -102
  130. package/dist/internal/renamed.d.ts +0 -28
@@ -1,30 +1,42 @@
1
1
  import {
2
- createTools
3
- } from "./chunk-BK5SLY32.js";
2
+ countReplies,
3
+ createTools,
4
+ describeReplyCounts,
5
+ repliesByPerson
6
+ } from "./chunk-JRL3QRBS.js";
4
7
  import {
5
- plural
8
+ resolveCampaign,
9
+ resolveList
10
+ } from "./chunk-4AVYRVN5.js";
11
+ import {
12
+ plural as plural2
6
13
  } from "./chunk-4PA526S7.js";
7
14
  import {
8
15
  createOutbound
9
- } from "./chunk-YYCT3NGV.js";
16
+ } from "./chunk-65YAGEWZ.js";
17
+ import {
18
+ plural
19
+ } from "./chunk-PTZO4QXR.js";
10
20
  import {
11
21
  campaignStatusSchema,
12
22
  replyCategorySchema
13
23
  } from "./chunk-QGRZDTX4.js";
14
24
  import {
15
25
  fromEnv
16
- } from "./chunk-5J7GGV62.js";
26
+ } from "./chunk-MW4C6LTN.js";
17
27
  import {
18
28
  OutboundError
19
- } from "./chunk-J7DDZ4C2.js";
29
+ } from "./chunk-QFC4ZHD3.js";
20
30
  import {
21
31
  field,
32
+ isBoolean,
33
+ isJsonArray,
22
34
  isJsonObject,
23
35
  isNumber,
24
36
  isString,
25
37
  parseJson,
26
38
  toJson
27
- } from "./chunk-BLCJHP5H.js";
39
+ } from "./chunk-45TXPJW7.js";
28
40
  import {
29
41
  providers
30
42
  } from "./chunk-WH6V3YNN.js";
@@ -32,6 +44,230 @@ import {
32
44
  // src/cli/index.ts
33
45
  import { parseArgs } from "node:util";
34
46
 
47
+ // src/cli/by-name.ts
48
+ var campaignOption = (outbound, value) => value === void 0 ? Promise.resolve(void 0) : resolveCampaign(outbound, value);
49
+ var listOption = (outbound, value) => value === void 0 ? Promise.resolve(void 0) : resolveList(outbound, value);
50
+ var confirmScope = async (outbound, scope, found) => {
51
+ if (found > 0) {
52
+ return;
53
+ }
54
+ if (scope.campaignId !== void 0) {
55
+ await outbound.campaign(scope.campaignId).get();
56
+ }
57
+ if (scope.listId !== void 0 && outbound.capabilities["lists.get"]) {
58
+ await outbound.list(scope.listId).get();
59
+ }
60
+ };
61
+ var searchCampaigns = async (outbound, { max, note, search, status }) => {
62
+ const wanted = search.trim().toLowerCase();
63
+ const all = await outbound.campaigns.listAll({ status }).toArray();
64
+ const matches = all.filter(
65
+ (campaign) => campaign.name.toLowerCase().includes(wanted)
66
+ );
67
+ if (matches.length > max) {
68
+ note(
69
+ `Stopped at ${plural(max, "campaign")} of ${matches.length} that match. Pass --limit to read more.`
70
+ );
71
+ }
72
+ return matches.slice(0, max);
73
+ };
74
+
75
+ // src/cli/envelope.ts
76
+ var Answer = class {
77
+ value;
78
+ coverage;
79
+ /** `true` for a list, which the envelope puts in `data.items`. */
80
+ list;
81
+ constructor(value, coverage, list = false) {
82
+ this.value = value;
83
+ this.coverage = coverage;
84
+ this.list = list;
85
+ }
86
+ /** How many records a list holds; 0 for an answer that is not a list. */
87
+ get size() {
88
+ return this.list && isJsonArray(this.value) ? this.value.length : 0;
89
+ }
90
+ };
91
+ var valueOf = (printed) => printed instanceof Answer ? printed.value : printed;
92
+ var notesOf = (value) => isJsonArray(value) ? value.filter(isString) : [];
93
+ var isToolResult = (value) => isJsonObject(value) && isBoolean(value.ok) && isString(value.next) && ("data" in value || "error" in value);
94
+ var coverageOf = (printed) => {
95
+ if (printed instanceof Answer) {
96
+ return printed.coverage;
97
+ }
98
+ const meta = isJsonObject(printed) ? printed.meta : void 0;
99
+ const stated = isJsonObject(meta) ? meta.complete : void 0;
100
+ if (isBoolean(stated)) {
101
+ return { complete: stated, notes: notesOf(field(meta, "notes")) };
102
+ }
103
+ if (isToolResult(printed)) {
104
+ return { complete: false, notes: [] };
105
+ }
106
+ return { complete: true, notes: [] };
107
+ };
108
+ var sections = (entries) => {
109
+ const all = entries.map(([, printed]) => coverageOf(printed));
110
+ const complete = all.every((each) => each.complete);
111
+ return new Answer(
112
+ Object.fromEntries(
113
+ entries.map(([name, printed]) => [name, valueOf(printed)])
114
+ ),
115
+ { complete, notes: all.flatMap((each) => each.notes) }
116
+ );
117
+ };
118
+ var requestCounter = () => {
119
+ let sent = 0;
120
+ return {
121
+ hooks: {
122
+ onRequest: () => {
123
+ sent += 1;
124
+ }
125
+ },
126
+ name: "cli-request-count",
127
+ sent: () => sent
128
+ };
129
+ };
130
+ var WRAPPER_KEYS = /* @__PURE__ */ new Set(["data", "insight", "meta"]);
131
+ var isWrapper = (value) => "data" in value && "meta" in value && Object.keys(value).every((key) => WRAPPER_KEYS.has(key));
132
+ var withoutMeta = (value) => Object.fromEntries(Object.entries(value).filter(([key]) => key !== "meta"));
133
+ var dataOf = (printed) => {
134
+ const value = valueOf(printed);
135
+ if (printed instanceof Answer && printed.list || isJsonArray(value)) {
136
+ return { items: value };
137
+ }
138
+ if (!isJsonObject(value)) {
139
+ return value;
140
+ }
141
+ if (isWrapper(value)) {
142
+ return value.data ?? null;
143
+ }
144
+ return withoutMeta(value);
145
+ };
146
+ var envelope = (printed, facts) => {
147
+ const value = valueOf(printed);
148
+ const { complete, notes } = coverageOf(printed);
149
+ const own = field(value, "meta");
150
+ const insight = field(value, "insight");
151
+ const meta = {
152
+ ...isJsonObject(own) ? own : void 0,
153
+ complete,
154
+ notes: [...notes],
155
+ provider: facts.provider ?? field(own, "provider") ?? null,
156
+ requests: facts.requests
157
+ };
158
+ if (isString(insight)) {
159
+ meta.insight = insight;
160
+ }
161
+ if (isToolResult(value)) {
162
+ const ok = value.ok === true;
163
+ const wrapped = {
164
+ data: ok ? value.data ?? null : null,
165
+ meta,
166
+ next: value.next ?? null,
167
+ ok
168
+ };
169
+ if (!ok) {
170
+ wrapped.error = value.error ?? null;
171
+ }
172
+ return wrapped;
173
+ }
174
+ return { data: dataOf(printed), meta, ok: true };
175
+ };
176
+ var failedEnvelope = (failure2, facts) => ({
177
+ data: null,
178
+ error: { code: failure2.code, message: failure2.message },
179
+ meta: {
180
+ complete: false,
181
+ notes: [],
182
+ provider: facts.provider,
183
+ requests: facts.requests
184
+ },
185
+ ok: false
186
+ });
187
+
188
+ // src/cli/listing.ts
189
+ var listed = async (walk, input, one, many) => {
190
+ const items = await walk.toArray();
191
+ if (!walk.truncated) {
192
+ return {
193
+ coverage: { complete: walk.meta?.complete ?? true, notes: [] },
194
+ items
195
+ };
196
+ }
197
+ const note = `Stopped at ${plural2(items.length, one, many)}; more exist. Pass --limit to read more.`;
198
+ input.note(note);
199
+ return { coverage: { complete: false, notes: [note] }, items };
200
+ };
201
+ var listing = async (walk, input, one, many) => {
202
+ const { coverage, items } = await listed(walk, input, one, many);
203
+ return new Answer(toJson(items), coverage, true);
204
+ };
205
+ var listedReplies = async (walk, input, byPerson) => {
206
+ const { coverage, items } = await listed(walk, input, "reply", "replies");
207
+ const counted = `${describeReplyCounts(countReplies(items))}.`;
208
+ input.note(counted);
209
+ return new Answer(
210
+ toJson(byPerson ? repliesByPerson(items) : items),
211
+ { ...coverage, notes: [...coverage.notes, counted] },
212
+ true
213
+ );
214
+ };
215
+
216
+ // src/cli/suggest.ts
217
+ var distance = (from, to) => {
218
+ const rows = Array.from(
219
+ { length: from.length + 1 },
220
+ (_row, row) => Array.from(
221
+ { length: to.length + 1 },
222
+ (_cell, column) => row === 0 || column === 0 ? row + column : 0
223
+ )
224
+ );
225
+ const at = (row, column) => rows[row]?.[column] ?? Infinity;
226
+ for (let row = 1; row <= from.length; row += 1) {
227
+ for (let column = 1; column <= to.length; column += 1) {
228
+ const cost = from[row - 1] === to[column - 1] ? 0 : 1;
229
+ const swapped = row > 1 && column > 1 && from[row - 1] === to[column - 2] && from[row - 2] === to[column - 1];
230
+ const best = Math.min(
231
+ at(row - 1, column) + 1,
232
+ at(row, column - 1) + 1,
233
+ at(row - 1, column - 1) + cost,
234
+ swapped ? at(row - 2, column - 2) + 1 : Infinity
235
+ );
236
+ const line = rows[row];
237
+ if (line !== void 0) {
238
+ line[column] = best;
239
+ }
240
+ }
241
+ }
242
+ return at(from.length, to.length);
243
+ };
244
+ var MAX_EDITS = 2;
245
+ var SHOWN = 3;
246
+ var closest = (typed, known) => [...new Set(known)].flatMap((word) => {
247
+ const edits = distance(typed, word);
248
+ return edits <= MAX_EDITS ? [{ edits, word }] : [];
249
+ }).toSorted((one, other) => one.edits - other.edits).slice(0, SHOWN).map(({ word }) => word);
250
+ var didYouMean = (typed, known, prefix = "") => {
251
+ const near = closest(typed, known).map((word) => `"${prefix}${word}"`);
252
+ return near.length === 0 ? "" : ` Did you mean ${near.join(" or ")}?`;
253
+ };
254
+
255
+ // src/cli/native.ts
256
+ var readNative = async (outbound, name, params) => {
257
+ const known = Object.keys(outbound.native.catalog);
258
+ if (outbound.capabilities.native && !known.includes(name)) {
259
+ throw new OutboundError(
260
+ "Invalid",
261
+ `${outbound.provider} has no native read "${name}".${didYouMean(name, known)} Run "outbound native" to list them`
262
+ );
263
+ }
264
+ const given = params();
265
+ if (!isJsonObject(given)) {
266
+ throw new OutboundError("Invalid", "--input must be a JSON object");
267
+ }
268
+ return toJson(await outbound.native.read(name, given));
269
+ };
270
+
35
271
  // src/cli/commands.ts
36
272
  var text = (input, name) => {
37
273
  const value = input.flags[name];
@@ -60,6 +296,7 @@ var choice = (input, name, allowed) => {
60
296
  return match;
61
297
  };
62
298
  var BY = ["day", "total"];
299
+ var REPLIES_BY = ["person"];
63
300
  var parseInput = (source) => {
64
301
  const parsed = source === void 0 ? {} : parseJson(source);
65
302
  if (parsed === void 0) {
@@ -83,15 +320,6 @@ var fieldExceptions = (outbound) => Object.fromEntries(
83
320
  return stated.length === 0 ? [] : [[record, Object.fromEntries(stated)]];
84
321
  })
85
322
  );
86
- var listing = async (walk, input, one, many) => {
87
- const items = await walk.toArray();
88
- if (walk.truncated) {
89
- input.note(
90
- `Stopped at ${plural(items.length, one, many)}; more exist. Pass --limit to read more.`
91
- );
92
- }
93
- return asJson(items);
94
- };
95
323
  var wantsCard = (input) => input.flags.slack === true || input.flags.card === true;
96
324
  var drawn = async (name, result2, input) => {
97
325
  if (!wantsCard(input)) {
@@ -99,12 +327,24 @@ var drawn = async (name, result2, input) => {
99
327
  }
100
328
  const { cardFor, toSlackMessage } = await import("../cards/index.js");
101
329
  const card = cardFor(name, result2);
102
- return asJson(input.flags.slack === true ? toSlackMessage(card) : card);
330
+ return new Answer(
331
+ asJson(input.flags.slack === true ? toSlackMessage(card) : card),
332
+ coverageOf(asJson(result2))
333
+ );
103
334
  };
104
335
  var offeredTools = async (outbound) => {
105
336
  const { insightTools } = await import("../insights/index.js");
106
337
  return createTools(outbound, { extra: insightTools(outbound) });
107
338
  };
339
+ var describeTool = (tool) => ({
340
+ description: tool.description,
341
+ name: tool.name,
342
+ parameters: tool.parameters
343
+ });
344
+ var requiresInput = (tool) => {
345
+ const { parameters } = tool;
346
+ return isJsonObject(parameters) && Array.isArray(parameters.required) && parameters.required.length > 0;
347
+ };
108
348
  var runInsight = async (outbound, input) => {
109
349
  const { insightTools, listInsights, runInsightByName } = await import("../insights/index.js");
110
350
  const [name] = input.positionals;
@@ -123,6 +363,7 @@ var GLOBAL_FLAGS = [
123
363
  "max-requests",
124
364
  "no-redact",
125
365
  "provider",
366
+ "raw",
126
367
  "redact"
127
368
  ];
128
369
  var checkFlags = (name, flags, given) => {
@@ -130,9 +371,10 @@ var checkFlags = (name, flags, given) => {
130
371
  (flag) => !GLOBAL_FLAGS.includes(flag) && !flags.includes(flag)
131
372
  );
132
373
  if (stray !== void 0) {
374
+ const hint = didYouMean(stray, [...flags, ...GLOBAL_FLAGS], "--");
133
375
  throw new OutboundError(
134
376
  "Invalid",
135
- `--${stray} is not an option of ${name}`
377
+ `--${stray} is not an option of ${name}${hint === "" ? "" : `.${hint}`}`
136
378
  );
137
379
  }
138
380
  };
@@ -158,9 +400,14 @@ var COMMAND_TABLE = {
158
400
  "subsequences",
159
401
  "to"
160
402
  ],
161
- help: "campaign <id> [--stats] [--sequence] [--subsequences] [--settings] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--by day|total]",
403
+ help: "campaign <id or name> [--stats] [--sequence] [--subsequences] [--settings] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--by day|total]",
162
404
  run: async (outbound, input) => {
163
- const campaign = outbound.campaign(required(input, 0, "a campaign id"));
405
+ const campaign = outbound.campaign(
406
+ await resolveCampaign(
407
+ outbound,
408
+ required(input, 0, "a campaign id or name")
409
+ )
410
+ );
164
411
  const by = choice(input, "by", BY);
165
412
  const read = {
166
413
  sequence: async () => asJson(await campaign.sequence()),
@@ -183,20 +430,28 @@ var COMMAND_TABLE = {
183
430
  const answers = await Promise.all(
184
431
  wanted.map(async (section) => [section, await read[section]()])
185
432
  );
186
- return answers.length === 1 ? answers[0]?.[1] ?? null : Object.fromEntries(answers);
433
+ return answers.length === 1 ? answers[0]?.[1] ?? null : sections(answers);
187
434
  }
188
435
  },
189
436
  campaigns: {
190
- flags: ["limit", "status"],
191
- help: "campaigns [--status active|paused|draft|completed|archived] [--limit N]",
192
- run: (outbound, input) => listing(
193
- outbound.campaigns.listAll({
437
+ flags: ["limit", "search", "status"],
438
+ help: "campaigns [--status active|paused|draft|completed|archived] [--search TEXT] [--limit N]",
439
+ run: (outbound, input) => {
440
+ const search = text(input, "search");
441
+ return search === void 0 ? listing(
442
+ outbound.campaigns.listAll({
443
+ max: count(input, "limit", 50),
444
+ status: choice(input, "status", campaignStatusSchema.options)
445
+ }),
446
+ input,
447
+ "campaign"
448
+ ) : searchCampaigns(outbound, {
194
449
  max: count(input, "limit", 50),
450
+ note: input.note,
451
+ search,
195
452
  status: choice(input, "status", campaignStatusSchema.options)
196
- }),
197
- input,
198
- "campaign"
199
- )
453
+ }).then(asJson);
454
+ }
200
455
  },
201
456
  capabilities: {
202
457
  flags: [],
@@ -222,16 +477,20 @@ var COMMAND_TABLE = {
222
477
  },
223
478
  leads: {
224
479
  flags: ["campaign", "limit", "list"],
225
- help: "leads [--campaign ID | --list ID] [--limit N]",
226
- run: (outbound, input) => listing(
227
- outbound.leads.listAll({
228
- campaignId: text(input, "campaign"),
229
- listId: text(input, "list"),
480
+ help: "leads [--campaign ID|NAME | --list ID|NAME] [--limit N]",
481
+ run: async (outbound, input) => {
482
+ const scope = {
483
+ campaignId: await campaignOption(outbound, text(input, "campaign")),
484
+ listId: await listOption(outbound, text(input, "list"))
485
+ };
486
+ const walk = outbound.leads.listAll({
487
+ ...scope,
230
488
  max: count(input, "limit", 50)
231
- }),
232
- input,
233
- "lead"
234
- )
489
+ });
490
+ const answer = await listing(walk, input, "lead");
491
+ await confirmScope(outbound, scope, answer.size);
492
+ return answer;
493
+ }
235
494
  },
236
495
  lists: {
237
496
  flags: ["limit"],
@@ -250,16 +509,9 @@ var COMMAND_TABLE = {
250
509
  native: {
251
510
  flags: ["input"],
252
511
  help: "native [name] [--input JSON] the vendor's own reads; no name lists them",
253
- run: async (outbound, input) => {
512
+ run: (outbound, input) => {
254
513
  const [name] = input.positionals;
255
- if (name === void 0) {
256
- return asJson(outbound.native.catalog);
257
- }
258
- const params = parseInput(text(input, "input"));
259
- if (!isJsonObject(params)) {
260
- throw new OutboundError("Invalid", "--input must be a JSON object");
261
- }
262
- return asJson(await outbound.native.read(name, params));
514
+ return name === void 0 ? Promise.resolve(asJson(outbound.native.catalog)) : readNative(outbound, name, () => parseInput(text(input, "input")));
263
515
  }
264
516
  },
265
517
  person: {
@@ -279,20 +531,19 @@ var COMMAND_TABLE = {
279
531
  })
280
532
  },
281
533
  replies: {
282
- flags: ["bodies", "campaign", "category", "limit", "since"],
283
- help: "replies [--campaign ID] [--category positive|negative|neutral|ooo|...] [--since ISO] [--limit N] [--bodies]",
284
- run: (outbound, input) => listing(
285
- outbound.replies.listAll({
286
- campaignId: text(input, "campaign"),
534
+ flags: ["bodies", "by", "campaign", "category", "limit", "since"],
535
+ help: "replies [--campaign ID|NAME] [--category positive|negative|neutral|ooo|...] [--since ISO] [--limit N] [--bodies] [--by person] one record per message; --by person gives one row per person",
536
+ run: async (outbound, input) => {
537
+ const by = choice(input, "by", REPLIES_BY);
538
+ const walk = outbound.replies.listAll({
539
+ campaignId: await campaignOption(outbound, text(input, "campaign")),
287
540
  category: choice(input, "category", replyCategorySchema.options),
288
541
  include: input.flags.bodies === true ? ["body"] : void 0,
289
542
  max: count(input, "limit", 50),
290
543
  since: text(input, "since")
291
- }),
292
- input,
293
- "reply",
294
- "replies"
295
- )
544
+ });
545
+ return listedReplies(walk, input, by === "person");
546
+ }
296
547
  },
297
548
  senders: {
298
549
  flags: ["limit"],
@@ -326,15 +577,29 @@ var COMMAND_TABLE = {
326
577
  thread: {
327
578
  flags: ["bodies"],
328
579
  help: "thread <id> [--bodies]",
329
- run: async (outbound, input) => asJson(
330
- await outbound.thread(required(input, 0, "a thread id")).messages({
580
+ run: async (outbound, input) => {
581
+ const id = required(input, 0, "a thread id");
582
+ const thread = await outbound.thread(id).messages({
331
583
  include: input.flags.bodies === true ? ["body"] : void 0
332
- })
333
- )
584
+ });
585
+ if (thread.items.length === 0) {
586
+ throw new OutboundError(
587
+ "NotFound",
588
+ `No thread ${id}, or it has no messages`
589
+ );
590
+ }
591
+ return new Answer(
592
+ asJson(thread.items),
593
+ coverageOf(
594
+ asJson({ meta: { ...thread.meta, complete: thread.complete } })
595
+ ),
596
+ true
597
+ );
598
+ }
334
599
  },
335
600
  tool: {
336
601
  flags: ["card", "input", "slack"],
337
- help: "tool <name> [--input JSON] [--card | --slack]",
602
+ help: "tool <name> [--input JSON] [--card | --slack] without --input, a tool that needs input prints what it takes",
338
603
  run: async (outbound, input) => {
339
604
  const name = required(input, 0, "a tool name");
340
605
  const offered = await offeredTools(outbound);
@@ -342,14 +607,17 @@ var COMMAND_TABLE = {
342
607
  if (tool === void 0) {
343
608
  throw new OutboundError(
344
609
  "Invalid",
345
- `Unknown tool "${name}". Run "outbound tools" to list them`
610
+ `Unknown tool "${name}".${didYouMean(
611
+ name,
612
+ offered.map((each) => each.name)
613
+ )} Run "outbound tools" to list them`
346
614
  );
347
615
  }
348
- return drawn(
349
- name,
350
- await tool.call(parseInput(text(input, "input"))),
351
- input
352
- );
616
+ const given = text(input, "input");
617
+ if (given === void 0 && requiresInput(tool)) {
618
+ return describeTool(tool);
619
+ }
620
+ return drawn(name, await tool.call(parseInput(given)), input);
353
621
  }
354
622
  },
355
623
  tools: {
@@ -357,18 +625,15 @@ var COMMAND_TABLE = {
357
625
  help: "tools",
358
626
  run: async (outbound) => {
359
627
  const offered = await offeredTools(outbound);
360
- return offered.map((tool) => ({
361
- description: tool.description,
362
- name: tool.name
363
- }));
628
+ return offered.map(describeTool);
364
629
  }
365
630
  },
366
631
  webhooks: {
367
632
  flags: ["campaign", "limit"],
368
- help: "webhooks [--campaign ID] [--limit N]",
369
- run: (outbound, input) => listing(
633
+ help: "webhooks [--campaign ID|NAME] [--limit N]",
634
+ run: async (outbound, input) => listing(
370
635
  outbound.webhooks.listAll({
371
- campaignId: text(input, "campaign"),
636
+ campaignId: await campaignOption(outbound, text(input, "campaign")),
372
637
  max: count(input, "limit", 50)
373
638
  }),
374
639
  input,
@@ -394,10 +659,11 @@ var GLOBAL_HELP = [
394
659
  "Options:",
395
660
  " --provider <id> the adapter to use, or all for every provider whose key is set (default: OUTBOUND_SDK_PROVIDER)",
396
661
  " --compact print JSON on one line",
662
+ " --raw keep each record's raw vendor payload (left out by default)",
397
663
  " --config <file> load plugins from a file whose default export is defineConfig({ plugins })",
398
664
  " --redact mask personal fields (on by default for mcp)",
399
665
  " --no-redact do not mask personal fields, even for mcp",
400
- " --cache <seconds> reuse an answer for this long",
666
+ " --cache <seconds> reuse an answer for this long, within this process (for mcp; use a config-file store to persist)",
401
667
  " --max-requests <n> the most vendor requests one command, or one MCP tool call, may make",
402
668
  "",
403
669
  "Each adapter reads its own key from the environment, for example INSTANTLY_API_KEY."
@@ -478,7 +744,7 @@ var wantsRedact = (flags, fromConfig, mcp) => {
478
744
  }
479
745
  return !fromConfig && (flags.redact === true || mcp);
480
746
  };
481
- var pluginsFor = async (flags, mcp) => {
747
+ var pluginsFor = async (flags, mcp, note) => {
482
748
  const configured = flags.config === void 0 ? [] : await loadConfig(flags.config);
483
749
  const fromConfig = configured.some((plugin) => plugin.name === "redact");
484
750
  const plugins = [];
@@ -491,6 +757,11 @@ var pluginsFor = async (flags, mcp) => {
491
757
  const ttl = positiveInteger("cache", flags.cache);
492
758
  const { cache } = await import("../cache/index.js");
493
759
  plugins.push(cache({ ttl }));
760
+ if (!mcp) {
761
+ note(
762
+ "--cache lasts one process, so the next run reads from the vendor again. It helps outbound mcp; to persist, list cache({ ttl, store }) in a --config file."
763
+ );
764
+ }
494
765
  }
495
766
  if (flags["max-requests"] !== void 0) {
496
767
  const maxRequests = positiveInteger("max-requests", flags["max-requests"]);
@@ -523,6 +794,17 @@ var describePlugins = (outbound) => {
523
794
  const masked = names.includes("redact") ? ` redact masks personal fields such as emails and names${outbound.capabilities["messages.body"] ? "" : ", and reply text is not available"}.` : " Personal fields such as emails and names are not masked.";
524
795
  return `Plugins on: ${names.join(", ")}.${masked}`;
525
796
  };
797
+ var describeLeftOut = (outbound, leftOut) => {
798
+ const names = Object.keys(leftOut ?? {});
799
+ if (names.length === 0) {
800
+ return "";
801
+ }
802
+ if (!outbound.plugins.some((plugin) => plugin.name === "redact")) {
803
+ return ` Left out of this server: ${names.join(", ")}. A call to one returns the reason.`;
804
+ }
805
+ const native = names.includes("vendor_read") ? " (vendor_read returns unmasked vendor payloads)" : "";
806
+ return ` Left out while redact is on: ${names.join(", ")}. They match people by email or LinkedIn profile, which redact masks${native}. Start the server with --no-redact to offer them; personal fields are then not masked.`;
807
+ };
526
808
  var hasRequestBudget = (value) => "requestBudget" in value && typeof value.requestBudget === "object" && value.requestBudget !== null && "reset" in value.requestBudget && typeof value.requestBudget.reset === "function";
527
809
  var budgetOf = (outbound) => hasRequestBudget(outbound) ? outbound.requestBudget : void 0;
528
810
  var result = (id, value) => ({
@@ -542,7 +824,7 @@ var idOf = (message) => {
542
824
  var createMcpServer = (outbound, options = {}) => {
543
825
  const tools = createTools(outbound, options);
544
826
  const byName = new Map(tools.map((tool) => [tool.name, tool]));
545
- const instructions = `${INSTRUCTIONS} ${describePlugins(outbound)}`;
827
+ const instructions = `${INSTRUCTIONS} ${describePlugins(outbound)}${describeLeftOut(outbound, options.leftOut)}`;
546
828
  const budget = budgetOf(outbound);
547
829
  const initialize = (id, params) => {
548
830
  const requested = field(params, "protocolVersion");
@@ -626,6 +908,73 @@ var createMcpServer = (outbound, options = {}) => {
626
908
  };
627
909
  };
628
910
 
911
+ // src/cli/options.ts
912
+ var OPTIONS = {
913
+ bodies: { type: "boolean" },
914
+ by: { type: "string" },
915
+ cache: { type: "string" },
916
+ campaign: { type: "string" },
917
+ card: { type: "boolean" },
918
+ category: { type: "string" },
919
+ compact: { type: "boolean" },
920
+ config: { type: "string" },
921
+ from: { type: "string" },
922
+ help: { short: "h", type: "boolean" },
923
+ input: { type: "string" },
924
+ limit: { type: "string" },
925
+ list: { type: "string" },
926
+ "max-requests": { type: "string" },
927
+ "no-redact": { type: "boolean" },
928
+ provider: { type: "string" },
929
+ raw: { type: "boolean" },
930
+ redact: { type: "boolean" },
931
+ search: { type: "string" },
932
+ sequence: { type: "boolean" },
933
+ settings: { type: "boolean" },
934
+ since: { type: "string" },
935
+ slack: { type: "boolean" },
936
+ stats: { type: "boolean" },
937
+ status: { type: "string" },
938
+ subsequences: { type: "boolean" },
939
+ to: { type: "string" },
940
+ version: { short: "v", type: "boolean" }
941
+ };
942
+
943
+ // src/cli/output.ts
944
+ var isRecord = (value) => isJsonObject(value) && "ref" in value && "schemaVersion" in value;
945
+ var withoutRaw = (value) => {
946
+ if (Array.isArray(value)) {
947
+ return value.map(withoutRaw);
948
+ }
949
+ if (!isJsonObject(value)) {
950
+ return value;
951
+ }
952
+ return Object.fromEntries(
953
+ Object.entries(value).filter(([key]) => !(key === "raw" && isRecord(value))).map(([key, item]) => [key, withoutRaw(item)])
954
+ );
955
+ };
956
+ var printJson = (write, value, options) => {
957
+ const shown = options.raw === true ? value : withoutRaw(value);
958
+ write(
959
+ options.compact === true ? JSON.stringify(shown) : JSON.stringify(shown, null, 2)
960
+ );
961
+ };
962
+ var printAnswer = (write, printed, options, facts) => {
963
+ printJson(write, envelope(printed, facts), options);
964
+ };
965
+ var TEXT_COMMANDS = /* @__PURE__ */ new Set([
966
+ "mcp",
967
+ "update",
968
+ "version"
969
+ ]);
970
+ var printFailure = (write, run2, failure2, facts) => {
971
+ if (!TEXT_COMMANDS.has(run2.name ?? "")) {
972
+ printJson(write, failedEnvelope(failure2, facts), {
973
+ compact: run2.argv.includes("--compact")
974
+ });
975
+ }
976
+ };
977
+
629
978
  // src/cli/stdio.ts
630
979
  import process from "node:process";
631
980
  import { createInterface } from "node:readline";
@@ -742,34 +1091,6 @@ var runSelf = async (name, flags, npm, say) => {
742
1091
  };
743
1092
 
744
1093
  // src/cli/index.ts
745
- var OPTIONS = {
746
- bodies: { type: "boolean" },
747
- by: { type: "string" },
748
- cache: { type: "string" },
749
- campaign: { type: "string" },
750
- card: { type: "boolean" },
751
- category: { type: "string" },
752
- compact: { type: "boolean" },
753
- config: { type: "string" },
754
- from: { type: "string" },
755
- help: { short: "h", type: "boolean" },
756
- input: { type: "string" },
757
- limit: { type: "string" },
758
- list: { type: "string" },
759
- "max-requests": { type: "string" },
760
- "no-redact": { type: "boolean" },
761
- provider: { type: "string" },
762
- redact: { type: "boolean" },
763
- sequence: { type: "boolean" },
764
- settings: { type: "boolean" },
765
- since: { type: "string" },
766
- slack: { type: "boolean" },
767
- stats: { type: "boolean" },
768
- status: { type: "string" },
769
- subsequences: { type: "boolean" },
770
- to: { type: "string" },
771
- version: { short: "v", type: "boolean" }
772
- };
773
1094
  var serve = async (outbound, io, unmasked) => {
774
1095
  const { insightTools } = await import("../insights/index.js");
775
1096
  const offered = (instance) => createTools(instance, { extra: insightTools(instance) }).map(
@@ -789,9 +1110,6 @@ var serve = async (outbound, io, unmasked) => {
789
1110
  });
790
1111
  await serveStdio(server, { input: io.stdin?.() ?? [], write: io.stdout });
791
1112
  };
792
- var print = (io, value, compact) => {
793
- io.stdout(compact ? JSON.stringify(value) : JSON.stringify(value, null, 2));
794
- };
795
1113
  var parseStrict = (argv) => parseArgs({ allowPositionals: true, args: [...argv], options: OPTIONS });
796
1114
  var helpFor = (name, asked) => {
797
1115
  const command = name === void 0 ? void 0 : COMMANDS.get(name);
@@ -814,7 +1132,7 @@ var parse = (argv) => {
814
1132
  if (named && !command && !STANDALONE.has(name)) {
815
1133
  throw new OutboundError(
816
1134
  "Invalid",
817
- `Unknown command "${name}". Run "outbound help"`
1135
+ `Unknown command "${name}".${didYouMean(name, [...COMMANDS.keys(), ...STANDALONE.keys(), "help", "providers"])} Run "outbound help"`
818
1136
  );
819
1137
  }
820
1138
  if (named) {
@@ -835,9 +1153,13 @@ var parse = (argv) => {
835
1153
  };
836
1154
  };
837
1155
  var run = async (argv, io) => {
1156
+ const counter = requestCounter();
1157
+ let provider = null;
1158
+ const facts = () => ({ provider, requests: counter.sent() });
1159
+ let named;
838
1160
  try {
839
1161
  const { help, name, rest, values } = parse(argv);
840
- const compact = values.compact === true;
1162
+ named = name;
841
1163
  if (await runSelf(name, values, io.npm ?? runNpm, io.stdout)) {
842
1164
  return 0;
843
1165
  }
@@ -846,13 +1168,17 @@ var run = async (argv, io) => {
846
1168
  return 0;
847
1169
  }
848
1170
  if (name === "providers") {
849
- print(io, listProviders(), compact);
1171
+ printAnswer(io.stdout, listProviders(), values, facts());
850
1172
  return 0;
851
1173
  }
852
1174
  const command = name === void 0 ? void 0 : COMMANDS.get(name);
853
1175
  const adapter = io.adapter ?? await fromEnv({ provider: values.provider });
854
- const plugins = await pluginsFor(values, command === void 0);
855
- const outbound = createOutbound({ adapter, plugins });
1176
+ const plugins = await pluginsFor(values, command === void 0, io.stderr);
1177
+ if (command !== void 0) {
1178
+ plugins.push(counter);
1179
+ }
1180
+ const outbound = createOutbound({ adapter, fetch: io.fetch, plugins });
1181
+ ({ provider } = outbound);
856
1182
  if (command === void 0) {
857
1183
  const unmasked = plugins.some((plugin) => plugin.name === "redact") ? createOutbound({
858
1184
  adapter,
@@ -866,13 +1192,13 @@ var run = async (argv, io) => {
866
1192
  note: io.stderr,
867
1193
  positionals: rest
868
1194
  });
869
- print(io, answer, compact);
870
- return name === "tool" && field(answer, "ok") === false ? 1 : 0;
1195
+ printAnswer(io.stdout, answer, values, facts());
1196
+ return name === "tool" && field(valueOf(answer), "ok") === false ? 1 : 0;
871
1197
  } catch (error) {
872
1198
  const code = OutboundError.is(error) ? error.code : "Error";
873
- io.stderr(
874
- `${code}: ${error instanceof Error ? error.message : String(error)}`
875
- );
1199
+ const message = error instanceof Error ? error.message : String(error);
1200
+ printFailure(io.stdout, { argv, name: named }, { code, message }, facts());
1201
+ io.stderr(`${code}: ${message}`);
876
1202
  return 1;
877
1203
  }
878
1204
  };