outbound-sdk 0.7.1 → 0.9.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.
- package/dist/alerts/index.js +3 -3
- package/dist/audit/index.js +1 -1
- package/dist/benchmarks/index.js +3 -3
- package/dist/budget/index.d.ts +7 -0
- package/dist/budget/index.js +3 -3
- package/dist/cache/index.js +2 -2
- package/dist/cards/index.js +17 -5
- package/dist/chunks/{chunk-6NSCPTOY.js → chunk-4BH5LRCS.js} +691 -441
- package/dist/chunks/{chunk-MW4C6LTN.js → chunk-5XLR6XVV.js} +2 -2
- package/dist/chunks/{chunk-HIAK2GCI.js → chunk-A7DLJUA6.js} +6 -1
- package/dist/chunks/{chunk-M2VXGLLZ.js → chunk-CPACP4YD.js} +1 -1
- package/dist/chunks/{chunk-4AVYRVN5.js → chunk-FTK4JS65.js} +31 -10
- package/dist/chunks/{chunk-YW6FFVSZ.js → chunk-HXB2IOJJ.js} +1 -1
- package/dist/chunks/{chunk-FHKSLCVW.js → chunk-KVAG5GM2.js} +19 -0
- package/dist/chunks/{chunk-65YAGEWZ.js → chunk-MEEJIIIA.js} +178 -39
- package/dist/chunks/{chunk-7I3EPR23.js → chunk-MPE6VLLY.js} +3 -3
- package/dist/chunks/{chunk-UFQ4WMLU.js → chunk-NFWWA7MI.js} +1 -1
- package/dist/chunks/{chunk-GL7BABF2.js → chunk-OMCDMELK.js} +1 -1
- package/dist/chunks/{chunk-JRL3QRBS.js → chunk-OVTYA3IB.js} +88 -28
- package/dist/chunks/{chunk-T5MJMW3R.js → chunk-QTWJ5FO7.js} +1 -1
- package/dist/chunks/chunk-REDFBY74.js +7285 -0
- package/dist/chunks/{chunk-OK3GAZMT.js → chunk-SYUMA3CP.js} +12 -0
- package/dist/chunks/{chunk-LVZGIKNF.js → chunk-U5AK6OJM.js} +1 -1
- package/dist/chunks/{chunk-KTYTE2BU.js → chunk-UAHYPASH.js} +20 -11
- package/dist/chunks/{chunk-BNDHEDHD.js → chunk-UOJG4VYF.js} +3 -3
- package/dist/chunks/{chunk-LD6F46UT.js → chunk-UWD65SK7.js} +2 -2
- package/dist/chunks/{chunk-I7DXXGNZ.js → chunk-UZLFZZ2U.js} +5 -5
- package/dist/chunks/{chunk-DNPNTD5W.js → chunk-VVDBCQLK.js} +1 -1
- package/dist/chunks/{chunk-IVH3NMQZ.js → chunk-WROJO6XB.js} +1 -1
- package/dist/chunks/{chunk-QFC4ZHD3.js → chunk-XYHM4KHC.js} +1 -1
- package/dist/chunks/{chunk-NAWZ73QS.js → chunk-YFJ3OQZS.js} +8 -1
- package/dist/chunks/tools-ATY622UC.js +23 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/bin.js +14 -14
- package/dist/cli/commands.d.ts +0 -7
- package/dist/cli/config.d.ts +31 -2
- package/dist/cli/envelope.d.ts +2 -0
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.js +19 -15
- package/dist/cli/listing.d.ts +5 -2
- package/dist/cli/mcp.d.ts +9 -0
- package/dist/cli/offered.d.ts +10 -0
- package/dist/cli/options.d.ts +6 -0
- package/dist/cli/progress.d.ts +27 -0
- package/dist/cli/serve.d.ts +17 -0
- package/dist/clients/index.js +3 -3
- package/dist/combine/index.js +154 -35
- package/dist/combine/newest.d.ts +18 -0
- package/dist/combine/route.d.ts +19 -5
- package/dist/emailbison/index.js +22 -14
- package/dist/emailbison/map-sequence.d.ts +2 -1
- package/dist/exporter/index.js +1 -1
- package/dist/failover/index.js +3 -3
- package/dist/fixtures/index.js +4 -4
- package/dist/heyreach/capabilities.d.ts +4 -0
- package/dist/heyreach/conversations.d.ts +23 -0
- package/dist/heyreach/inbox.d.ts +0 -1
- package/dist/heyreach/index.js +251 -92
- package/dist/identity/index.js +2 -2
- package/dist/index.js +7 -7
- package/dist/insights/capped.d.ts +6 -6
- package/dist/insights/copy/index.d.ts +2 -0
- package/dist/insights/copy/reply-timing.d.ts +4 -0
- package/dist/insights/cost.d.ts +11 -1
- package/dist/insights/define.d.ts +25 -16
- package/dist/insights/inbox.d.ts +12 -0
- package/dist/insights/index.js +42 -6578
- package/dist/insights/inputs.generated.d.ts +62 -26
- package/dist/insights/ops/anomalies.d.ts +9 -0
- package/dist/insights/ops/index.d.ts +2 -0
- package/dist/insights/ops/period-comparison.d.ts +7 -8
- package/dist/insights/ops/pipeline-forecast.d.ts +16 -0
- package/dist/insights/ops/shared.d.ts +6 -1
- package/dist/insights/people/auto-replies.d.ts +11 -7
- package/dist/insights/people/dropped-replies.d.ts +13 -4
- package/dist/insights/people/hot-leads-read.d.ts +31 -0
- package/dist/insights/people/hot-leads.d.ts +15 -3
- package/dist/insights/people/index.d.ts +10 -2
- package/dist/insights/people/read.d.ts +1 -1
- package/dist/insights/registry.d.ts +14 -2
- package/dist/insights/run-cap.d.ts +10 -0
- package/dist/insights/senders/read.d.ts +0 -3
- package/dist/insights/tools.d.ts +12 -0
- package/dist/insights/tracked-reads.d.ts +53 -0
- package/dist/instantly/capabilities.d.ts +13 -1
- package/dist/instantly/index.js +128 -46
- package/dist/instantly/map-account.d.ts +2 -1
- package/dist/instantly/map-lead.d.ts +1 -0
- package/dist/instantly/map.d.ts +4 -3
- package/dist/internal/adapter.d.ts +19 -0
- package/dist/internal/capabilities.d.ts +15 -0
- package/dist/internal/engine/budget.d.ts +9 -1
- package/dist/internal/engine/engine.d.ts +2 -1
- package/dist/internal/engine/request.d.ts +2 -0
- package/dist/internal/errors.d.ts +5 -0
- package/dist/internal/hooks.d.ts +11 -0
- package/dist/internal/notes.d.ts +16 -0
- package/dist/internal/outbound/api.d.ts +16 -0
- package/dist/internal/outbound/core.d.ts +4 -1
- package/dist/internal/outbound/operation-shared.d.ts +2 -0
- package/dist/internal/sha256.d.ts +2 -0
- package/dist/internal/url.d.ts +1 -0
- package/dist/loader/index.js +3 -3
- package/dist/memory/index.js +11 -16
- package/dist/redact/index.d.ts +1 -1
- package/dist/redact/index.js +107 -19
- package/dist/redact/plugin.d.ts +26 -3
- package/dist/smartlead/index.js +22 -13
- package/dist/smartlead/map.d.ts +3 -2
- package/dist/sync/index.js +2 -2
- package/dist/tools/ai-sdk.js +5 -5
- package/dist/tools/by-name.d.ts +9 -1
- package/dist/tools/campaign-tools.d.ts +3 -1
- package/dist/tools/claude-agent.js +5 -5
- package/dist/tools/index.js +6 -6
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/shared.d.ts +5 -1
- package/dist/tracing/index.js +1 -1
- package/dist/webhooks/index.js +11 -11
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "./chunk-POBAY3TI.js";
|
|
15
15
|
import {
|
|
16
16
|
OutboundError
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-XYHM4KHC.js";
|
|
18
18
|
|
|
19
19
|
// src/internal/capabilities.ts
|
|
20
20
|
var NO_CAPABILITIES = {
|
|
@@ -28,16 +28,20 @@ var NO_CAPABILITIES = {
|
|
|
28
28
|
"events.verify": false,
|
|
29
29
|
"leads.byCampaign": false,
|
|
30
30
|
"leads.byDomain": false,
|
|
31
|
+
"leads.byInterest": false,
|
|
32
|
+
"leads.byStatus": false,
|
|
31
33
|
"leads.engagement": false,
|
|
32
34
|
"leads.get": false,
|
|
33
35
|
"leads.list": false,
|
|
34
36
|
"leads.lookup": false,
|
|
37
|
+
"leads.lookupMany": false,
|
|
35
38
|
"leads.since": false,
|
|
36
39
|
"leads.timeline": false,
|
|
37
40
|
"lists.get": false,
|
|
38
41
|
"lists.leads": false,
|
|
39
42
|
"lists.list": false,
|
|
40
43
|
"messages.body": false,
|
|
44
|
+
"messages.byHand": false,
|
|
41
45
|
"messages.byThread": false,
|
|
42
46
|
"messages.list": false,
|
|
43
47
|
"messages.since": false,
|
|
@@ -45,6 +49,7 @@ var NO_CAPABILITIES = {
|
|
|
45
49
|
"placementTests.list": false,
|
|
46
50
|
"replies.category": false,
|
|
47
51
|
"replies.list": false,
|
|
52
|
+
"replies.inbox": false,
|
|
48
53
|
"replies.since": false,
|
|
49
54
|
"replies.unread": false,
|
|
50
55
|
"senders.byCampaign": false,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
computeRates
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CPACP4YD.js";
|
|
4
4
|
import {
|
|
5
5
|
parseRef
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-HXB2IOJJ.js";
|
|
7
7
|
import {
|
|
8
8
|
OutboundError
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XYHM4KHC.js";
|
|
10
10
|
import {
|
|
11
11
|
isJsonObject
|
|
12
12
|
} from "./chunk-45TXPJW7.js";
|
|
@@ -52,8 +52,8 @@ var weakest = (all) => {
|
|
|
52
52
|
return all.includes("sampled") ? "sampled" : "exact";
|
|
53
53
|
};
|
|
54
54
|
var DEFAULT_TOOL_REQUESTS = 100;
|
|
55
|
-
var capNext = (cap, isDefault, lower) => {
|
|
56
|
-
const ask = `the user to raise
|
|
55
|
+
var capNext = (cap, isDefault, lower, setting = "maxRequestsPerToolCall") => {
|
|
56
|
+
const ask = `the user to raise ${setting} (${isDefault ? "default" : "set to"} ${cap} here)`;
|
|
57
57
|
return `Do not call again with the same input. ${lower === void 0 ? `Ask ${ask}` : `Lower ${lower.input} to ${lower.to}${lower.sure ? "" : " or less"}, or ask ${ask}`}.`;
|
|
58
58
|
};
|
|
59
59
|
var nextFor = (cause, code) => {
|
|
@@ -63,6 +63,9 @@ var nextFor = (cause, code) => {
|
|
|
63
63
|
if (OutboundError.is(cause) && code === "RateLimited") {
|
|
64
64
|
return cause.permanent ? "A request cap the user set was reached; the message says which. Do not call again with the same input." : "The vendor's rate limit was reached. Wait a minute before calling again.";
|
|
65
65
|
}
|
|
66
|
+
if (OutboundError.is(cause) && code === "Provider" && cause.permanent && !cause.aborted) {
|
|
67
|
+
return "The vendor returned data the SDK cannot read, and it returns the same data on every call. Do not call again with the same input. Try another campaign, or report the field the message names.";
|
|
68
|
+
}
|
|
66
69
|
return "Check the input and try again.";
|
|
67
70
|
};
|
|
68
71
|
var failure = (cause, requests, next) => {
|
|
@@ -82,6 +85,7 @@ var failure = (cause, requests, next) => {
|
|
|
82
85
|
|
|
83
86
|
// src/tools/by-name.ts
|
|
84
87
|
import { z as z2 } from "zod";
|
|
88
|
+
var COMBINED = "combined";
|
|
85
89
|
var UUID = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
|
|
86
90
|
var DIGITS = /^\d+$/u;
|
|
87
91
|
var ID_FORMS = /* @__PURE__ */ new Map([
|
|
@@ -94,6 +98,9 @@ var isIdentifier = (outbound, value) => {
|
|
|
94
98
|
if (parseRef(value) !== null) {
|
|
95
99
|
return true;
|
|
96
100
|
}
|
|
101
|
+
if (outbound.provider === COMBINED) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
97
104
|
const form = ID_FORMS.get(outbound.provider);
|
|
98
105
|
return form === void 0 ? !/\s/u.test(value) : form.test(value);
|
|
99
106
|
};
|
|
@@ -103,13 +110,11 @@ var listed = (matches) => {
|
|
|
103
110
|
return matches.length > SHOWN ? `${shown} and ${matches.length - SHOWN} more` : shown;
|
|
104
111
|
};
|
|
105
112
|
var pick = (records, value, what) => {
|
|
106
|
-
if (records.some((record) => record.sourceId === value)) {
|
|
107
|
-
return value;
|
|
108
|
-
}
|
|
109
113
|
const wanted = value.trim().toLowerCase();
|
|
110
114
|
const nameOf = (record) => (record.name ?? "").trim().toLowerCase();
|
|
115
|
+
const byId = records.filter((record) => record.sourceId === value);
|
|
111
116
|
const exact = records.filter((record) => nameOf(record) === wanted);
|
|
112
|
-
const matches = exact.length > 0
|
|
117
|
+
const matches = [byId, exact].find((found) => found.length > 0) ?? records.filter((record) => nameOf(record).includes(wanted));
|
|
113
118
|
if (matches.length > 1) {
|
|
114
119
|
throw new OutboundError(
|
|
115
120
|
"Invalid",
|
|
@@ -127,7 +132,7 @@ var resolve = async (outbound, value, what, records) => {
|
|
|
127
132
|
if (found !== void 0) {
|
|
128
133
|
return found;
|
|
129
134
|
}
|
|
130
|
-
if (ID_FORMS.has(outbound.provider) || outbound.provider ===
|
|
135
|
+
if (ID_FORMS.has(outbound.provider) || outbound.provider === COMBINED) {
|
|
131
136
|
throw new OutboundError(
|
|
132
137
|
"NotFound",
|
|
133
138
|
`No ${what} has the id or name "${value}". Give its ref or id, or list the ${what}s to find it`
|
|
@@ -147,6 +152,21 @@ var namesCampaign = (outbound, input) => {
|
|
|
147
152
|
const parsed = withCampaignField.safeParse(input);
|
|
148
153
|
return parsed.success && !isIdentifier(outbound, parsed.data.campaign);
|
|
149
154
|
};
|
|
155
|
+
var routedByCampaign = (outbound, input) => {
|
|
156
|
+
const parsed = withCampaignField.safeParse(input);
|
|
157
|
+
const parts = parsed.success ? parseRef(parsed.data.campaign) : null;
|
|
158
|
+
if (outbound.provider !== COMBINED || parts === null) {
|
|
159
|
+
return outbound;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
return outbound.workspace(`${parts.provider}:${parts.workspaceId}`);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (OutboundError.is(error) && error.code === "NotFound") {
|
|
165
|
+
return outbound;
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
150
170
|
var withCampaign = async (outbound, input, read = toArray) => {
|
|
151
171
|
const parsed = withCampaignField.safeParse(input);
|
|
152
172
|
if (!parsed.success) {
|
|
@@ -229,6 +249,7 @@ export {
|
|
|
229
249
|
resolveCampaign,
|
|
230
250
|
resolveList,
|
|
231
251
|
namesCampaign,
|
|
252
|
+
routedByCampaign,
|
|
232
253
|
withCampaign,
|
|
233
254
|
inputProblem,
|
|
234
255
|
paceWindow,
|
|
@@ -142,6 +142,24 @@ var sha256Hex = (input) => Array.from(
|
|
|
142
142
|
sha256(new TextEncoder().encode(input)),
|
|
143
143
|
(byte) => byte.toString(16).padStart(2, "0")
|
|
144
144
|
).join("");
|
|
145
|
+
var BLOCK = 64;
|
|
146
|
+
var hmacSha256Hex = (key, message) => {
|
|
147
|
+
const block = new Uint8Array(BLOCK);
|
|
148
|
+
block.set(key.length > BLOCK ? sha256(key) : key);
|
|
149
|
+
const text = new TextEncoder().encode(message);
|
|
150
|
+
const inner = new Uint8Array(BLOCK + text.length);
|
|
151
|
+
const outer = new Uint8Array(BLOCK + 32);
|
|
152
|
+
for (const [index, byte] of block.entries()) {
|
|
153
|
+
inner[index] = byte ^ 54;
|
|
154
|
+
outer[index] = byte ^ 92;
|
|
155
|
+
}
|
|
156
|
+
inner.set(text, BLOCK);
|
|
157
|
+
outer.set(sha256(inner), BLOCK);
|
|
158
|
+
return Array.from(
|
|
159
|
+
sha256(outer),
|
|
160
|
+
(byte) => byte.toString(16).padStart(2, "0")
|
|
161
|
+
).join("");
|
|
162
|
+
};
|
|
145
163
|
var stableId = (...parts) => sha256Hex(parts.map((part) => String(part ?? "")).join("")).slice(
|
|
146
164
|
0,
|
|
147
165
|
32
|
|
@@ -150,5 +168,6 @@ var stableId = (...parts) => sha256Hex(parts.map((part) => String(part ?? "")).j
|
|
|
150
168
|
export {
|
|
151
169
|
sha256,
|
|
152
170
|
sha256Hex,
|
|
171
|
+
hmacSha256Hex,
|
|
153
172
|
stableId
|
|
154
173
|
};
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
senderHealthSchema,
|
|
19
19
|
tagSchema,
|
|
20
20
|
webhookSubscriptionSchema
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-A7DLJUA6.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-
|
|
37
|
+
} from "./chunk-HXB2IOJJ.js";
|
|
38
38
|
import {
|
|
39
39
|
buildUrl
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-YFJ3OQZS.js";
|
|
41
41
|
import {
|
|
42
42
|
sha256Hex
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-KVAG5GM2.js";
|
|
44
44
|
import {
|
|
45
45
|
OutboundError,
|
|
46
46
|
redactUrl
|
|
47
|
-
} from "./chunk-
|
|
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
|
-
|
|
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
|
|
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
|
|
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, {
|
|
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
|
|
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
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
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,21 +1327,80 @@ 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
|
+
};
|
|
1364
|
+
var checkStatus = (core, filters) => {
|
|
1365
|
+
if (filters.status === void 0) {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
requireCapability(
|
|
1369
|
+
core.gate,
|
|
1370
|
+
"leads.byStatus",
|
|
1371
|
+
"Listing only the active leads"
|
|
1372
|
+
);
|
|
1373
|
+
if (filters.status !== "active") {
|
|
1374
|
+
throw new OutboundError(
|
|
1375
|
+
"Invalid",
|
|
1376
|
+
`status takes "active", not "${String(filters.status)}"`
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
if (filters.interest !== void 0) {
|
|
1380
|
+
throw new OutboundError(
|
|
1381
|
+
"Invalid",
|
|
1382
|
+
"Leads can be listed by interest or by status, not both at once"
|
|
1383
|
+
);
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1274
1386
|
var leadList = (core) => ({
|
|
1275
1387
|
action: "leads.list",
|
|
1276
1388
|
takes: {
|
|
1277
1389
|
campaignId: true,
|
|
1278
1390
|
domain: true,
|
|
1279
1391
|
email: true,
|
|
1392
|
+
emails: true,
|
|
1393
|
+
interest: true,
|
|
1280
1394
|
linkedinUrl: true,
|
|
1281
1395
|
listId: true,
|
|
1282
1396
|
since: true,
|
|
1397
|
+
status: true,
|
|
1283
1398
|
until: true
|
|
1284
1399
|
},
|
|
1285
1400
|
// A lookup returns one record per campaign the person is in. On a vendor
|
|
1286
1401
|
// whose lead id is the same in every campaign those records share a ref,
|
|
1287
1402
|
// 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 ?? ""}`,
|
|
1403
|
+
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
1404
|
prepare: (filters) => {
|
|
1290
1405
|
if (filters.campaignId !== void 0 && filters.listId !== void 0) {
|
|
1291
1406
|
throw new OutboundError(
|
|
@@ -1301,6 +1416,9 @@ var leadList = (core) => ({
|
|
|
1301
1416
|
"Finding a lead by email or LinkedIn profile"
|
|
1302
1417
|
);
|
|
1303
1418
|
}
|
|
1419
|
+
const emails = manyAddresses(core, filters.emails);
|
|
1420
|
+
checkInterest(core, filters.interest);
|
|
1421
|
+
checkStatus(core, filters);
|
|
1304
1422
|
const domain = filters.domain?.trim().toLowerCase();
|
|
1305
1423
|
if (domain !== void 0) {
|
|
1306
1424
|
requireCapability(
|
|
@@ -1323,7 +1441,7 @@ var leadList = (core) => ({
|
|
|
1323
1441
|
"leads.byCampaign",
|
|
1324
1442
|
"Listing a campaign's leads"
|
|
1325
1443
|
);
|
|
1326
|
-
} else if (!lookup2 && domain === void 0) {
|
|
1444
|
+
} else if (!lookup2 && domain === void 0 && emails === void 0) {
|
|
1327
1445
|
requireCapability(core.gate, "leads.list", "Listing leads");
|
|
1328
1446
|
}
|
|
1329
1447
|
if (hasRange(filters)) {
|
|
@@ -1333,8 +1451,11 @@ var leadList = (core) => ({
|
|
|
1333
1451
|
campaignId: filters.campaignId,
|
|
1334
1452
|
domain,
|
|
1335
1453
|
email: filters.email?.trim().toLowerCase(),
|
|
1454
|
+
emails: emails === void 0 ? void 0 : [...new Set(emails)],
|
|
1455
|
+
interest: filters.interest,
|
|
1336
1456
|
linkedinUrl: filters.linkedinUrl?.trim(),
|
|
1337
1457
|
listId: filters.listId,
|
|
1458
|
+
status: filters.status,
|
|
1338
1459
|
...normalizeRange(filters)
|
|
1339
1460
|
};
|
|
1340
1461
|
},
|
|
@@ -1356,6 +1477,7 @@ var leadGet = (core) => ({
|
|
|
1356
1477
|
var messageList = (core) => ({
|
|
1357
1478
|
action: "messages.list",
|
|
1358
1479
|
takes: {
|
|
1480
|
+
byHand: true,
|
|
1359
1481
|
campaignId: true,
|
|
1360
1482
|
include: true,
|
|
1361
1483
|
leadId: true,
|
|
@@ -1366,6 +1488,13 @@ var messageList = (core) => ({
|
|
|
1366
1488
|
keyOf: refOf2,
|
|
1367
1489
|
prepare: (filters) => {
|
|
1368
1490
|
requireCapability(core.gate, "messages.list", "Listing messages");
|
|
1491
|
+
if (filters.byHand !== void 0) {
|
|
1492
|
+
requireCapability(
|
|
1493
|
+
core.gate,
|
|
1494
|
+
"messages.byHand",
|
|
1495
|
+
"Listing only the messages sent by hand"
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1369
1498
|
if (filters.threadId !== void 0) {
|
|
1370
1499
|
requireCapability(
|
|
1371
1500
|
core.gate,
|
|
@@ -1384,6 +1513,7 @@ var messageList = (core) => ({
|
|
|
1384
1513
|
);
|
|
1385
1514
|
}
|
|
1386
1515
|
return {
|
|
1516
|
+
byHand: filters.byHand,
|
|
1387
1517
|
campaignId: filters.campaignId,
|
|
1388
1518
|
include: filters.include,
|
|
1389
1519
|
leadId: filters.leadId,
|
|
@@ -1395,6 +1525,7 @@ var messageList = (core) => ({
|
|
|
1395
1525
|
toOperation: (filters, page) => ({
|
|
1396
1526
|
kind: "messages.list",
|
|
1397
1527
|
query: {
|
|
1528
|
+
byHand: filters.byHand,
|
|
1398
1529
|
campaignId: filters.campaignId,
|
|
1399
1530
|
includeBody: wantsBody(filters.include),
|
|
1400
1531
|
leadId: filters.leadId,
|
|
@@ -1411,6 +1542,7 @@ var replyList = (core) => ({
|
|
|
1411
1542
|
campaignId: true,
|
|
1412
1543
|
category: true,
|
|
1413
1544
|
include: true,
|
|
1545
|
+
includeInbox: true,
|
|
1414
1546
|
since: true,
|
|
1415
1547
|
unread: true,
|
|
1416
1548
|
until: true
|
|
@@ -1446,6 +1578,7 @@ var replyList = (core) => ({
|
|
|
1446
1578
|
campaignId: filters.campaignId,
|
|
1447
1579
|
category: filters.category,
|
|
1448
1580
|
include: filters.include,
|
|
1581
|
+
includeInbox: filters.includeInbox,
|
|
1449
1582
|
unread: filters.unread,
|
|
1450
1583
|
...normalizeRange(filters)
|
|
1451
1584
|
};
|
|
@@ -1457,6 +1590,7 @@ var replyList = (core) => ({
|
|
|
1457
1590
|
campaignId: filters.campaignId,
|
|
1458
1591
|
category: filters.category,
|
|
1459
1592
|
includeBody: wantsBody(filters.include),
|
|
1593
|
+
includeInbox: filters.includeInbox,
|
|
1460
1594
|
since: filters.since,
|
|
1461
1595
|
unread: filters.unread,
|
|
1462
1596
|
until: filters.until,
|
|
@@ -1519,6 +1653,7 @@ var readStats = async (core, options = {}) => {
|
|
|
1519
1653
|
complete: true,
|
|
1520
1654
|
evidence: output2.evidence,
|
|
1521
1655
|
fetchedAt: output2.fetchedAt,
|
|
1656
|
+
notes: output2.notes,
|
|
1522
1657
|
stale: output2.stale
|
|
1523
1658
|
}),
|
|
1524
1659
|
rows: checked(core, metricRowSchema, output2.items, "stats")
|
|
@@ -2295,14 +2430,18 @@ var Outbound = class _Outbound {
|
|
|
2295
2430
|
const narrowed = narrowCapabilities(declared, plugins);
|
|
2296
2431
|
const run = composeOperations(
|
|
2297
2432
|
[...plugins, ...layers],
|
|
2298
|
-
(operation, info) =>
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2433
|
+
async (operation, info) => {
|
|
2434
|
+
const notes = [];
|
|
2435
|
+
const output2 = await dispatch(
|
|
2436
|
+
{
|
|
2437
|
+
adapter,
|
|
2438
|
+
capabilities: declared,
|
|
2439
|
+
ctx: engine.contextFor(adapter, info.state, notes)
|
|
2440
|
+
},
|
|
2441
|
+
operation
|
|
2442
|
+
);
|
|
2443
|
+
return notes.length === 0 ? output2 : { ...output2, notes };
|
|
2444
|
+
}
|
|
2306
2445
|
);
|
|
2307
2446
|
this.#options = options;
|
|
2308
2447
|
this.#plugins = plugins;
|