outbound-sdk 0.6.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.
- package/dist/alerts/check-schema.d.ts +1 -1
- package/dist/alerts/index.js +6 -6
- package/dist/audit/index.js +2 -2
- package/dist/benchmarks/index.js +4 -4
- package/dist/budget/index.js +2 -2
- package/dist/cards/index.js +54 -44
- package/dist/chunks/{chunk-BLCJHP5H.js → chunk-45TXPJW7.js} +1 -0
- package/dist/chunks/chunk-4AVYRVN5.js +239 -0
- package/dist/chunks/{chunk-YYCT3NGV.js → chunk-65YAGEWZ.js} +24 -7
- package/dist/chunks/{chunk-W22SDX6S.js → chunk-7I3EPR23.js} +3 -3
- package/dist/chunks/{chunk-MGR6HREO.js → chunk-BNDHEDHD.js} +2 -2
- package/dist/chunks/chunk-DNPNTD5W.js +81 -0
- package/dist/chunks/{chunk-53DCVFUB.js → chunk-FALWG5U3.js} +1 -0
- package/dist/chunks/{chunk-OLPMBRXM.js → chunk-GL7BABF2.js} +2 -2
- package/dist/chunks/{chunk-ZOAG2C6V.js → chunk-HIAK2GCI.js} +9 -2
- package/dist/chunks/{chunk-SXGCKCAR.js → chunk-I7DXXGNZ.js} +40 -9
- package/dist/chunks/{chunk-BK5SLY32.js → chunk-JRL3QRBS.js} +264 -76
- package/dist/chunks/{chunk-PHNQ3WC2.js → chunk-KTYTE2BU.js} +4 -3
- package/dist/chunks/{chunk-JWGSB7PT.js → chunk-LD6F46UT.js} +2 -2
- package/dist/chunks/{chunk-2D42TQFU.js → chunk-LVZGIKNF.js} +2 -2
- package/dist/chunks/{chunk-PQSTQKRD.js → chunk-M2VXGLLZ.js} +35 -2
- package/dist/chunks/{chunk-UWUPUMM2.js → chunk-MW4C6LTN.js} +2 -2
- package/dist/chunks/chunk-OK3GAZMT.js +51 -0
- package/dist/chunks/{chunk-BOWXGMN3.js → chunk-POBAY3TI.js} +80 -4
- package/dist/chunks/{chunk-J7DDZ4C2.js → chunk-QFC4ZHD3.js} +1 -1
- package/dist/chunks/{chunk-GFDNRWR3.js → chunk-UFQ4WMLU.js} +1 -1
- package/dist/chunks/{chunk-TFICTGM2.js → chunk-Y7KECJAV.js} +1 -1
- package/dist/chunks/{chunk-QAKJ76HB.js → chunk-YW6FFVSZ.js} +1 -1
- package/dist/chunks/{chunk-3JOC5DGD.js → chunk-ZJCVLBAE.js} +424 -117
- package/dist/cli/bin.js +14 -14
- package/dist/cli/by-name.d.ts +28 -0
- package/dist/cli/commands.d.ts +2 -1
- package/dist/cli/config.d.ts +3 -2
- package/dist/cli/envelope.d.ts +50 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +13 -13
- package/dist/cli/listing.d.ts +13 -0
- package/dist/cli/native.d.ts +4 -0
- package/dist/cli/options.d.ts +88 -0
- package/dist/cli/output.d.ts +13 -1
- package/dist/cli/suggest.d.ts +10 -0
- package/dist/clients/index.js +6 -6
- package/dist/combine/index.js +7 -7
- package/dist/emailbison/capabilities.d.ts +1 -0
- package/dist/emailbison/index.js +38 -14
- package/dist/emailbison/map-stats.d.ts +10 -0
- package/dist/exporter/index.js +2 -2
- package/dist/failover/index.js +2 -2
- package/dist/fixtures/index.js +4 -4
- package/dist/heyreach/capabilities.d.ts +3 -0
- package/dist/heyreach/index.js +34 -12
- package/dist/heyreach/map-account.d.ts +2 -2
- package/dist/identity/index.js +2 -2
- package/dist/index.js +9 -7
- package/dist/insights/copy/audit-samples.d.ts +24 -0
- package/dist/insights/copy/audit-variant.d.ts +34 -0
- package/dist/insights/copy/copy-audit.d.ts +26 -12
- package/dist/insights/copy/copy-preview.d.ts +16 -3
- package/dist/insights/copy/index.d.ts +6 -0
- package/dist/insights/copy/reply-timing.d.ts +4 -0
- package/dist/insights/copy/shared.d.ts +4 -1
- package/dist/insights/copy/step-funnel.d.ts +20 -6
- package/dist/insights/copy/variant-test.d.ts +2 -3
- package/dist/insights/index.js +1138 -589
- package/dist/insights/inputs.generated.d.ts +47 -11
- package/dist/insights/ops/campaign-diagnosis.d.ts +2 -0
- package/dist/insights/ops/diagnosis-checks.d.ts +20 -1
- package/dist/insights/ops/index.d.ts +2 -0
- package/dist/insights/ops/pipeline-forecast.d.ts +17 -6
- package/dist/insights/people/account-summary.d.ts +14 -1
- package/dist/insights/people/auto-replies.d.ts +14 -0
- package/dist/insights/people/dropped-replies.d.ts +1 -1
- package/dist/insights/people/hot-leads.d.ts +5 -1
- package/dist/insights/people/index.d.ts +4 -0
- package/dist/insights/people/lead-collisions.d.ts +11 -2
- package/dist/insights/people/person-summary.d.ts +19 -3
- package/dist/insights/people/personalization-gaps.d.ts +14 -8
- package/dist/insights/people/suppression-check.d.ts +9 -0
- package/dist/insights/registry.d.ts +12 -0
- package/dist/insights/step.d.ts +15 -0
- package/dist/insights/variables.d.ts +2 -0
- package/dist/instantly/capabilities.d.ts +4 -0
- package/dist/instantly/index.js +263 -53
- package/dist/instantly/map-stats.d.ts +4 -0
- package/dist/instantly/stats-tracking.d.ts +19 -0
- package/dist/instantly/thread.d.ts +9 -0
- package/dist/internal/adapter.d.ts +5 -0
- package/dist/internal/auto-reply.d.ts +20 -0
- package/dist/internal/capabilities.d.ts +2 -0
- package/dist/internal/entities-account.d.ts +1 -0
- package/dist/internal/entities.d.ts +79 -2
- package/dist/internal/fields.d.ts +37 -1
- package/dist/internal/metrics.d.ts +23 -1
- package/dist/internal/outbound/api.d.ts +2 -0
- package/dist/internal/records.d.ts +2 -2
- package/dist/internal/reply-people.d.ts +37 -0
- package/dist/internal/runway.d.ts +42 -0
- package/dist/internal/sender-screen.d.ts +9 -0
- package/dist/internal/tracking.d.ts +33 -0
- package/dist/loader/index.js +4 -4
- package/dist/memory/data.d.ts +2 -1
- package/dist/memory/index.js +23 -12
- package/dist/redact/index.js +3 -3
- package/dist/smartlead/capabilities.d.ts +4 -0
- package/dist/smartlead/index.js +152 -38
- package/dist/smartlead/map-account.d.ts +3 -0
- package/dist/smartlead/stats-tracking.d.ts +22 -0
- package/dist/sync/index.js +2 -2
- package/dist/tools/ai-sdk.js +8 -7
- package/dist/tools/by-name.d.ts +18 -0
- package/dist/tools/campaign-tools.d.ts +6 -2
- package/dist/tools/claude-agent.js +8 -7
- package/dist/tools/index.js +9 -8
- package/dist/tools/shared.d.ts +7 -0
- package/dist/tracing/index.js +2 -2
- package/dist/webhooks/index.js +12 -11
- package/package.json +1 -1
- package/dist/chunks/chunk-HWHI4LFY.js +0 -102
package/dist/insights/index.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SCREENED_AT_MOST,
|
|
2
3
|
capNext,
|
|
3
4
|
failure,
|
|
4
|
-
inputProblem
|
|
5
|
-
|
|
5
|
+
inputProblem,
|
|
6
|
+
leadsToStart,
|
|
7
|
+
namesCampaign,
|
|
8
|
+
newLeadsPerDay,
|
|
9
|
+
paceWindow,
|
|
10
|
+
runwayDays,
|
|
11
|
+
splitActive,
|
|
12
|
+
warmupAtZero,
|
|
13
|
+
withCampaign
|
|
14
|
+
} from "../chunks/chunk-4AVYRVN5.js";
|
|
6
15
|
import {
|
|
7
16
|
count,
|
|
8
17
|
percentOf,
|
|
@@ -23,10 +32,15 @@ import {
|
|
|
23
32
|
import {
|
|
24
33
|
htmlToText,
|
|
25
34
|
looksLikeHtml
|
|
26
|
-
} from "../chunks/chunk-
|
|
35
|
+
} from "../chunks/chunk-FALWG5U3.js";
|
|
27
36
|
import {
|
|
28
|
-
|
|
29
|
-
} from "../chunks/chunk-
|
|
37
|
+
leadStatusSchema
|
|
38
|
+
} from "../chunks/chunk-POBAY3TI.js";
|
|
39
|
+
import {
|
|
40
|
+
CONTACTED_LEADS_LIMIT,
|
|
41
|
+
contactedBeyondLeads,
|
|
42
|
+
sumMeasured
|
|
43
|
+
} from "../chunks/chunk-M2VXGLLZ.js";
|
|
30
44
|
import {
|
|
31
45
|
campaignStatusSchema,
|
|
32
46
|
replyCategorySchema
|
|
@@ -34,18 +48,18 @@ import {
|
|
|
34
48
|
import {
|
|
35
49
|
makeRef,
|
|
36
50
|
parseRef
|
|
37
|
-
} from "../chunks/chunk-
|
|
51
|
+
} from "../chunks/chunk-YW6FFVSZ.js";
|
|
38
52
|
import {
|
|
39
53
|
profileSlug
|
|
40
54
|
} from "../chunks/chunk-NAWZ73QS.js";
|
|
41
55
|
import {
|
|
42
56
|
OutboundError
|
|
43
|
-
} from "../chunks/chunk-
|
|
57
|
+
} from "../chunks/chunk-QFC4ZHD3.js";
|
|
44
58
|
import {
|
|
45
59
|
jsonInput,
|
|
46
60
|
toJson,
|
|
47
61
|
unknownKey
|
|
48
|
-
} from "../chunks/chunk-
|
|
62
|
+
} from "../chunks/chunk-45TXPJW7.js";
|
|
49
63
|
|
|
50
64
|
// src/insights/plugin.ts
|
|
51
65
|
import { z as z31 } from "zod";
|
|
@@ -181,7 +195,7 @@ var fitting = (outbound, cost, input28, name, room, found) => {
|
|
|
181
195
|
};
|
|
182
196
|
|
|
183
197
|
// src/insights/copy/copy-audit.ts
|
|
184
|
-
import { z } from "zod";
|
|
198
|
+
import { z as z4 } from "zod";
|
|
185
199
|
|
|
186
200
|
// src/insights/run-cap.ts
|
|
187
201
|
var capFor = (outbound, name, max, options) => {
|
|
@@ -361,12 +375,29 @@ var prepare = (outbound, spec, input28) => {
|
|
|
361
375
|
}
|
|
362
376
|
return parsed.data;
|
|
363
377
|
};
|
|
378
|
+
var NAMED_AMONG = 1e3;
|
|
379
|
+
var priced = (outbound, spec, input28) => {
|
|
380
|
+
const { cost } = spec;
|
|
381
|
+
return cost === void 0 || !namesCampaign(outbound, input28) ? spec : {
|
|
382
|
+
...spec,
|
|
383
|
+
cost: (values, price) => cost(values, price) + price.list("campaigns.list", NAMED_AMONG)
|
|
384
|
+
};
|
|
385
|
+
};
|
|
364
386
|
var execute = async (outbound, spec, input28, options = {}) => {
|
|
365
387
|
const checked = prepare(outbound, spec, input28);
|
|
366
|
-
const cap = runCap(
|
|
388
|
+
const cap = runCap(
|
|
389
|
+
outbound,
|
|
390
|
+
priced(outbound, spec, checked),
|
|
391
|
+
checked,
|
|
392
|
+
options
|
|
393
|
+
);
|
|
367
394
|
const now = options.now ?? Date.now();
|
|
368
395
|
const tracker = track(cap.outbound, now, cap.campaignsFound);
|
|
369
|
-
const data = await
|
|
396
|
+
const data = await withCampaign(
|
|
397
|
+
tracker.context.outbound,
|
|
398
|
+
checked,
|
|
399
|
+
(walk) => tracker.context.all(walk)
|
|
400
|
+
).then((resolved) => spec.run(tracker.context, resolved)).catch(cap.failed);
|
|
370
401
|
const short = cap.shortNote();
|
|
371
402
|
if (short !== void 0) {
|
|
372
403
|
tracker.context.partial(short);
|
|
@@ -393,6 +424,243 @@ var runInsight = (outbound, definition, input28, options = {}) => (
|
|
|
393
424
|
execute(outbound, definition, input28, options)
|
|
394
425
|
);
|
|
395
426
|
|
|
427
|
+
// src/insights/people/read.ts
|
|
428
|
+
import { z as z2 } from "zod";
|
|
429
|
+
|
|
430
|
+
// src/insights/capped.ts
|
|
431
|
+
var readCapped = async (context, open, cap, room = cap.max) => {
|
|
432
|
+
if (room >= 1) {
|
|
433
|
+
const walk = open(room);
|
|
434
|
+
const items = await context.all(walk, cap);
|
|
435
|
+
return { capped: walk.truncated, items };
|
|
436
|
+
}
|
|
437
|
+
const probe = open(1);
|
|
438
|
+
const left = await context.all(probe, cap);
|
|
439
|
+
if (left.length > 0 && !probe.truncated) {
|
|
440
|
+
context.partial(capNote(cap));
|
|
441
|
+
}
|
|
442
|
+
return { capped: left.length > 0, items: [] };
|
|
443
|
+
};
|
|
444
|
+
var campaignsReadOf = (read) => ({
|
|
445
|
+
campaignsRead: read.items.length,
|
|
446
|
+
moreCampaignsExist: read.capped
|
|
447
|
+
});
|
|
448
|
+
var readCampaignsIn = async (context, statuses, max, input28 = "max_campaigns") => {
|
|
449
|
+
const { campaigns } = context.outbound;
|
|
450
|
+
const wanted = [...new Set(statuses)];
|
|
451
|
+
const cap = { input: input28, max, what: "campaigns" };
|
|
452
|
+
if (context.outbound.capabilities["campaigns.status"] === false) {
|
|
453
|
+
const every = await readCapped(
|
|
454
|
+
context,
|
|
455
|
+
(room) => campaigns.listAll({ max: room }),
|
|
456
|
+
cap
|
|
457
|
+
);
|
|
458
|
+
const items = every.items.filter(
|
|
459
|
+
(campaign) => wanted.includes(campaign.status)
|
|
460
|
+
);
|
|
461
|
+
context.campaignsFound(items.length);
|
|
462
|
+
return { capped: every.capped, items };
|
|
463
|
+
}
|
|
464
|
+
const found = [];
|
|
465
|
+
let capped2 = false;
|
|
466
|
+
for (const status of wanted) {
|
|
467
|
+
const listed2 = await readCapped(
|
|
468
|
+
context,
|
|
469
|
+
(room) => campaigns.listAll({ max: room, status }),
|
|
470
|
+
cap,
|
|
471
|
+
max - found.length
|
|
472
|
+
);
|
|
473
|
+
found.push(...listed2.items);
|
|
474
|
+
capped2 ||= listed2.capped;
|
|
475
|
+
}
|
|
476
|
+
context.campaignsFound(found.length);
|
|
477
|
+
return { capped: capped2, items: found };
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// src/insights/fields.ts
|
|
481
|
+
import { z } from "zod";
|
|
482
|
+
var rangeFields = {
|
|
483
|
+
from: z.iso.date().nullable().default(null).describe("First day counted, YYYY-MM-DD. null for the whole history."),
|
|
484
|
+
to: z.iso.date().nullable().default(null).describe("Last day counted, YYYY-MM-DD. null for up to today.")
|
|
485
|
+
};
|
|
486
|
+
var statusesInput = (fallback) => z.array(campaignStatusSchema).min(1).default([...fallback]).describe(
|
|
487
|
+
"Only campaigns in one of these states are read: active, paused, completed, draft, archived or unknown"
|
|
488
|
+
);
|
|
489
|
+
|
|
490
|
+
// src/insights/people/read.ts
|
|
491
|
+
var readCappedFlag = (context, open, max, what, input28) => readCapped(context, open, { input: input28, max, what });
|
|
492
|
+
var readByRef = async (context, refs, read, what, effect) => {
|
|
493
|
+
if (refs.length === 0) {
|
|
494
|
+
return /* @__PURE__ */ new Map();
|
|
495
|
+
}
|
|
496
|
+
const found = await read(refs);
|
|
497
|
+
if (found.errors.length > 0) {
|
|
498
|
+
context.note(
|
|
499
|
+
`${plural(found.errors.length, ...what)} could not be read, so ${noun(found.errors.length, "its", "their")} ${effect}.`
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
const [costliest] = found.results.toSorted(
|
|
503
|
+
(left, right) => right.value.meta.requests - left.value.meta.requests
|
|
504
|
+
);
|
|
505
|
+
if (costliest !== void 0) {
|
|
506
|
+
context.one(costliest.value);
|
|
507
|
+
}
|
|
508
|
+
return new Map(found.results.map(({ id, value }) => [id, value]));
|
|
509
|
+
};
|
|
510
|
+
var statusesField = statusesInput(["active"]);
|
|
511
|
+
var campaignsIn = async (context, statuses, max) => {
|
|
512
|
+
const { items } = await readCampaignsIn(context, statuses, max);
|
|
513
|
+
return items;
|
|
514
|
+
};
|
|
515
|
+
var leadsOf = async (context, campaign, max, input28) => {
|
|
516
|
+
const { items } = await readCappedFlag(
|
|
517
|
+
context,
|
|
518
|
+
(cap) => context.outbound.campaign(campaign).leads.listAll({ max: cap }),
|
|
519
|
+
max,
|
|
520
|
+
"leads of a campaign",
|
|
521
|
+
input28
|
|
522
|
+
);
|
|
523
|
+
return items;
|
|
524
|
+
};
|
|
525
|
+
var nameOf = (lead) => {
|
|
526
|
+
const name = [lead.firstName, lead.lastName].flatMap((part) => part === null || part.trim() === "" ? [] : [part]).join(" ");
|
|
527
|
+
return name === "" ? null : name;
|
|
528
|
+
};
|
|
529
|
+
var domainOf = (email) => {
|
|
530
|
+
const domain = email?.split("@").at(-1) ?? "";
|
|
531
|
+
return email === null || !email.includes("@") || domain === "" ? null : domain;
|
|
532
|
+
};
|
|
533
|
+
var DEFAULT_POSITIVE_LABELS = [
|
|
534
|
+
"Interested",
|
|
535
|
+
"Meeting Booked",
|
|
536
|
+
"Meeting Completed"
|
|
537
|
+
];
|
|
538
|
+
var positiveLabelsField = z2.array(z2.string().min(1)).default(DEFAULT_POSITIVE_LABELS).describe(
|
|
539
|
+
"Vendor interest labels that count as interested, matched without regard to case"
|
|
540
|
+
);
|
|
541
|
+
var isPositive = (label, labels) => label === null ? null : labels.some(
|
|
542
|
+
(each) => each.trim().toLowerCase() === label.trim().toLowerCase()
|
|
543
|
+
);
|
|
544
|
+
var hasReplied = (lead) => lead.replied === true || (lead.engagement?.replies ?? 0) > 0 || (lead.engagement?.lastRepliedAt ?? null) !== null;
|
|
545
|
+
var OUT_OF_OFFICE = /\bout[\s-]+of[\s-]+(?:the\s+)?office\b/iu;
|
|
546
|
+
var AUTOMATIC = /* @__PURE__ */ new Set([
|
|
547
|
+
"bounce",
|
|
548
|
+
"ooo"
|
|
549
|
+
]);
|
|
550
|
+
var isAutoReplied = (lead) => lead.interestCategory !== null && AUTOMATIC.has(lead.interestCategory) || // A label the vendor did not map to a category is read by a fixed rule.
|
|
551
|
+
lead.interestCategory === null && OUT_OF_OFFICE.test(lead.interest ?? "");
|
|
552
|
+
var hasHumanReply = (lead) => hasReplied(lead) && !isAutoReplied(lead);
|
|
553
|
+
var NEGATIVE_CATEGORIES = /* @__PURE__ */ new Set(["negative", "unsubscribe"]);
|
|
554
|
+
var NEGATIVE_LABEL = /\b(?:not[\s-]+interested|wrong[\s-]+person|unsubscribed?|do[\s-]+not[\s-]+contact)\b/iu;
|
|
555
|
+
var isNegative = (lead) => lead.interestCategory !== null && NEGATIVE_CATEGORIES.has(lead.interestCategory) || lead.interestCategory === null && NEGATIVE_LABEL.test(lead.interest ?? "");
|
|
556
|
+
var COUNTS = "no per-lead open, click or reply counts";
|
|
557
|
+
var noteEngagement = (context, leads, effect) => {
|
|
558
|
+
const { outbound } = context;
|
|
559
|
+
if (outbound.capabilities["leads.engagement"]) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (leads.every((lead) => lead.provider === outbound.provider)) {
|
|
563
|
+
context.note(`This tool reports ${COUNTS}, so ${effect}.`);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const reporting = new Set(
|
|
567
|
+
leads.flatMap((lead) => lead.engagement === null ? [] : [lead.provider])
|
|
568
|
+
);
|
|
569
|
+
const lacking = [...new Set(leads.map((lead) => lead.provider))].filter((provider) => !reporting.has(provider)).toSorted();
|
|
570
|
+
if (lacking.length > 0) {
|
|
571
|
+
context.note(
|
|
572
|
+
`${lacking.join(", ")} ${lacking.length === 1 ? "reports" : "report"} ${COUNTS}, so ${effect} for ${lacking.length === 1 ? "its" : "their"} records. Records from the other tools carry what their vendor reports.`
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
// src/insights/variables.ts
|
|
578
|
+
var PATTERNS = [
|
|
579
|
+
/\{\{\s*(?<name>[^{}|]+?)\s*(?<fallback>\|[^{}]*)?\}\}/gu,
|
|
580
|
+
/(?<!\{)\{(?<name>[A-Za-z_][\w .-]*)\}(?!\})/gu,
|
|
581
|
+
/%(?<name>[A-Za-z_][\w-]*)%/gu
|
|
582
|
+
];
|
|
583
|
+
var keyOf = (name) => name.toLowerCase().replaceAll(/[\s_-]/gu, "");
|
|
584
|
+
var BUILTINS = /* @__PURE__ */ new Map([
|
|
585
|
+
["company", (lead) => lead.company],
|
|
586
|
+
["companyname", (lead) => lead.company],
|
|
587
|
+
["email", (lead) => lead.email],
|
|
588
|
+
["firstname", (lead) => lead.firstName],
|
|
589
|
+
["jobtitle", (lead) => lead.title],
|
|
590
|
+
["lastname", (lead) => lead.lastName],
|
|
591
|
+
["title", (lead) => lead.title]
|
|
592
|
+
]);
|
|
593
|
+
var isBuiltin = (key) => BUILTINS.has(key);
|
|
594
|
+
var SENDER = /* @__PURE__ */ new Map([
|
|
595
|
+
[
|
|
596
|
+
"instantly",
|
|
597
|
+
/* @__PURE__ */ new Set([
|
|
598
|
+
"accountsignature",
|
|
599
|
+
"sendingaccountemail",
|
|
600
|
+
"sendingaccountfirstname",
|
|
601
|
+
"sendingaccountname"
|
|
602
|
+
])
|
|
603
|
+
]
|
|
604
|
+
]);
|
|
605
|
+
var isSender = (provider, key) => SENDER.get(provider)?.has(key) ?? false;
|
|
606
|
+
var variablesIn = (text) => PATTERNS.flatMap(
|
|
607
|
+
(pattern) => [...text.matchAll(pattern)].map((match) => {
|
|
608
|
+
const fallback = match.groups?.fallback;
|
|
609
|
+
return {
|
|
610
|
+
fallback: fallback === void 0 ? null : fallback.slice(1).trim(),
|
|
611
|
+
index: match.index,
|
|
612
|
+
name: match.groups?.name ?? "",
|
|
613
|
+
raw: match[0]
|
|
614
|
+
};
|
|
615
|
+
})
|
|
616
|
+
);
|
|
617
|
+
var filled = (value) => value !== null && value !== void 0 && value.trim() !== "";
|
|
618
|
+
var valueOf = (lead, key) => {
|
|
619
|
+
const builtin = BUILTINS.get(key)?.(lead);
|
|
620
|
+
if (filled(builtin)) {
|
|
621
|
+
return builtin;
|
|
622
|
+
}
|
|
623
|
+
const custom = Object.entries(lead.custom).find(
|
|
624
|
+
([name, value]) => keyOf(name) === key && filled(value)
|
|
625
|
+
);
|
|
626
|
+
return custom?.[1] ?? null;
|
|
627
|
+
};
|
|
628
|
+
var keysWithValue = (lead) => /* @__PURE__ */ new Set([
|
|
629
|
+
...[...BUILTINS].flatMap(
|
|
630
|
+
([key, read]) => filled(read(lead)) ? [key] : []
|
|
631
|
+
),
|
|
632
|
+
...Object.entries(lead.custom).flatMap(
|
|
633
|
+
([key, value]) => filled(value) ? [keyOf(key)] : []
|
|
634
|
+
)
|
|
635
|
+
]);
|
|
636
|
+
var fillVariables = (text, lead) => {
|
|
637
|
+
const matches = variablesIn(text).toSorted(
|
|
638
|
+
(left, right) => left.index - right.index
|
|
639
|
+
);
|
|
640
|
+
const unfilled = [];
|
|
641
|
+
let out = "";
|
|
642
|
+
let at = 0;
|
|
643
|
+
for (const match of matches) {
|
|
644
|
+
if (match.index >= at) {
|
|
645
|
+
const value = valueOf(lead, keyOf(match.name)) ?? match.fallback;
|
|
646
|
+
if (value === null && !unfilled.includes(match.name)) {
|
|
647
|
+
unfilled.push(match.name);
|
|
648
|
+
}
|
|
649
|
+
out += text.slice(at, match.index) + (value ?? match.raw);
|
|
650
|
+
at = match.index + match.raw.length;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return { text: out + text.slice(at), unfilled };
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// src/insights/step.ts
|
|
657
|
+
var stepAt = (index) => ({
|
|
658
|
+
step: index,
|
|
659
|
+
stepIndex: index,
|
|
660
|
+
stepNumber: index + 1
|
|
661
|
+
});
|
|
662
|
+
var stepLabel = (index, of = null) => of === null || of < index + 1 ? `step ${index + 1}` : `step ${index + 1} (of ${of})`;
|
|
663
|
+
|
|
396
664
|
// src/insights/copy/copy-checks.ts
|
|
397
665
|
var CHECKS = {
|
|
398
666
|
all_caps: "low",
|
|
@@ -532,36 +800,7 @@ var connectionTooLong = (body, limits) => body.length > limits.maxConnectionChar
|
|
|
532
800
|
text: clip(body)
|
|
533
801
|
} : null;
|
|
534
802
|
|
|
535
|
-
// src/insights/copy/
|
|
536
|
-
var limit = (fallback, description) => z.number().int().min(0).default(fallback).describe(description);
|
|
537
|
-
var input = z.object({
|
|
538
|
-
campaign: z.string().min(1).describe("The campaign's ref, for example `instantly:acme:abc123`"),
|
|
539
|
-
max_body_words: limit(150, "The most words a body may have."),
|
|
540
|
-
max_caps_words: limit(
|
|
541
|
-
1,
|
|
542
|
-
"How many words of four or more letters may be in capitals, so one acronym is not a finding."
|
|
543
|
-
),
|
|
544
|
-
max_connection_chars: limit(
|
|
545
|
-
300,
|
|
546
|
-
"The most characters a LinkedIn connection request may have."
|
|
547
|
-
),
|
|
548
|
-
max_exclamations: limit(1, "How many exclamation marks a message may have."),
|
|
549
|
-
max_links: limit(1, "The most links an email body may have."),
|
|
550
|
-
max_subject_chars: limit(60, "The most characters a subject may have."),
|
|
551
|
-
spam_words: z.array(z.string().min(1)).default([...DEFAULT_SPAM_WORDS]).describe(
|
|
552
|
-
"Words and phrases to flag in email copy, matched whole and without case. Replaces the default list."
|
|
553
|
-
)
|
|
554
|
-
});
|
|
555
|
-
var RANK2 = { high: 0, low: 2, medium: 1 };
|
|
556
|
-
var EMAIL_ONLY = [
|
|
557
|
-
"image",
|
|
558
|
-
"missing_subject",
|
|
559
|
-
"spam_words",
|
|
560
|
-
"subject_breaks_thread",
|
|
561
|
-
"subject_too_long",
|
|
562
|
-
"too_many_links"
|
|
563
|
-
];
|
|
564
|
-
var LINKEDIN_ONLY = ["connection_request_too_long"];
|
|
803
|
+
// src/insights/copy/audit-variant.ts
|
|
565
804
|
var emailChecks = (step, variant, limits, thread) => {
|
|
566
805
|
const subject = variant.subject?.trim() ?? "";
|
|
567
806
|
const body = variant.body ?? "";
|
|
@@ -580,7 +819,7 @@ ${body}`, limits),
|
|
|
580
819
|
text: ""
|
|
581
820
|
});
|
|
582
821
|
}
|
|
583
|
-
if (step.index !== thread.first && key !== "" && !thread.subjects.has(key)) {
|
|
822
|
+
if (step.index !== thread.first && key !== "" && thread.subjects !== null && !thread.subjects.has(key)) {
|
|
584
823
|
problems.push({
|
|
585
824
|
check: "subject_breaks_thread",
|
|
586
825
|
finding: "This follow-up has a subject that differs from the first email's, so it starts a new thread instead of continuing the first.",
|
|
@@ -590,7 +829,7 @@ ${body}`, limits),
|
|
|
590
829
|
return problems;
|
|
591
830
|
};
|
|
592
831
|
var linkedinChecks = (step, variant, limits) => step.action.toLowerCase().includes("connect") && variant.body !== null ? [connectionTooLong(variant.body, limits)] : [];
|
|
593
|
-
var auditVariant = (step, variant, limits, thread) => {
|
|
832
|
+
var auditVariant = (step, variant, limits, thread, lead) => {
|
|
594
833
|
const body = variant.body ?? "";
|
|
595
834
|
const whole = `${variant.subject ?? ""}
|
|
596
835
|
${body}`;
|
|
@@ -606,328 +845,46 @@ ${body}`;
|
|
|
606
845
|
{
|
|
607
846
|
...problem,
|
|
608
847
|
action: step.action,
|
|
848
|
+
lead,
|
|
609
849
|
severity: CHECKS[problem.check],
|
|
610
|
-
step
|
|
850
|
+
...stepAt(step.index),
|
|
611
851
|
variantKey: variant.variantKey
|
|
612
852
|
}
|
|
613
853
|
]
|
|
614
854
|
);
|
|
615
855
|
};
|
|
616
|
-
var threadOf = (steps) => {
|
|
856
|
+
var threadOf = (steps, perLead2) => {
|
|
617
857
|
const [first] = steps.toSorted((left, right) => left.index - right.index);
|
|
858
|
+
const variants = first?.variants ?? [];
|
|
618
859
|
return {
|
|
619
860
|
first: first?.index ?? null,
|
|
620
|
-
subjects: new Set(
|
|
621
|
-
|
|
861
|
+
subjects: first !== void 0 && variants.some((variant) => perLead2(variant)) ? null : new Set(
|
|
862
|
+
variants.flatMap((variant) => {
|
|
622
863
|
const key = threadKey(variant.subject);
|
|
623
864
|
return key === "" ? [] : [key];
|
|
624
865
|
})
|
|
625
866
|
)
|
|
626
867
|
};
|
|
627
868
|
};
|
|
628
|
-
var CHECK_NAMES = Object.keys(CHECKS);
|
|
629
|
-
var countsOf = (findings, isEmail) => CHECK_NAMES.filter(
|
|
630
|
-
(check) => !(isEmail ? LINKEDIN_ONLY : EMAIL_ONLY).includes(check)
|
|
631
|
-
).map((check) => ({
|
|
632
|
-
check,
|
|
633
|
-
count: findings.filter((finding) => finding.check === check).length,
|
|
634
|
-
severity: CHECKS[check]
|
|
635
|
-
})).toSorted(
|
|
636
|
-
(left, right) => right.count - left.count || RANK2[left.severity] - RANK2[right.severity] || left.check.localeCompare(right.check)
|
|
637
|
-
);
|
|
638
|
-
var copyAudit = defineInsight({
|
|
639
|
-
description: "Problems in a campaign's copy before it sends. Checks every step and variant for a long subject, a long body, too many links, spam words, unbalanced or empty {{ }} variables, words in capitals, repeated exclamation marks, an image or tracking pixel, a missing subject on the first email, and a follow-up whose subject breaks the thread; a LinkedIn campaign skips the email-only checks and flags a connection request over the character limit. Returns each finding with a severity and the text that triggered it, and a count per check. Costs 2 requests. Fixed rules only, no model. A variant whose body the vendor does not return is counted, not judged.",
|
|
640
|
-
inputSchema: input,
|
|
641
|
-
key: "copyAudit",
|
|
642
|
-
cost: (_input, price) => price.one("campaigns.get") + price.one("sequence.get"),
|
|
643
|
-
name: "copy_audit",
|
|
644
|
-
needs: ["sequence"],
|
|
645
|
-
next: "Use step_funnel to see whether the steps with findings are also the ones with few replies.",
|
|
646
|
-
run: async (context, args) => {
|
|
647
|
-
const handle = context.outbound.campaign(args.campaign);
|
|
648
|
-
const campaign = context.one(await handle.get());
|
|
649
|
-
const sequence2 = context.one(await handle.sequence());
|
|
650
|
-
const isEmail = campaign.channel === "email";
|
|
651
|
-
const limits = {
|
|
652
|
-
maxBodyWords: args.max_body_words,
|
|
653
|
-
maxCapsWords: args.max_caps_words,
|
|
654
|
-
maxConnectionChars: args.max_connection_chars,
|
|
655
|
-
maxExclamations: args.max_exclamations,
|
|
656
|
-
maxLinks: args.max_links,
|
|
657
|
-
maxSubjectChars: args.max_subject_chars,
|
|
658
|
-
spamWords: args.spam_words
|
|
659
|
-
};
|
|
660
|
-
const thread = isEmail ? threadOf(sequence2.steps) : null;
|
|
661
|
-
const variants = sequence2.steps.flatMap(
|
|
662
|
-
(step) => step.variants.map((variant) => ({ step, variant }))
|
|
663
|
-
);
|
|
664
|
-
const findings = variants.flatMap(
|
|
665
|
-
({ step, variant }) => auditVariant(step, variant, limits, thread)
|
|
666
|
-
).toSorted(
|
|
667
|
-
(left, right) => RANK2[left.severity] - RANK2[right.severity] || left.step - right.step || left.variantKey.localeCompare(right.variantKey) || left.check.localeCompare(right.check)
|
|
668
|
-
);
|
|
669
|
-
const withoutBody = variants.filter(
|
|
670
|
-
({ variant }) => variant.body === null
|
|
671
|
-
).length;
|
|
672
|
-
if (withoutBody > 0) {
|
|
673
|
-
context.note(
|
|
674
|
-
withoutBody === 1 ? "1 variant has no body in the vendor's answer, so its body checks were skipped." : `${withoutBody} variants have no body in the vendor's answer, so their body checks were skipped.`
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
const severity = (level) => findings.filter((finding) => finding.severity === level).length;
|
|
678
|
-
const audit2 = {
|
|
679
|
-
byCheck: countsOf(findings, isEmail),
|
|
680
|
-
bySeverity: {
|
|
681
|
-
high: severity("high"),
|
|
682
|
-
low: severity("low"),
|
|
683
|
-
medium: severity("medium")
|
|
684
|
-
},
|
|
685
|
-
campaign: campaign.ref,
|
|
686
|
-
campaignName: campaign.name,
|
|
687
|
-
channel: campaign.channel,
|
|
688
|
-
clean: findings.length === 0,
|
|
689
|
-
findings,
|
|
690
|
-
stepsChecked: sequence2.steps.length,
|
|
691
|
-
variantsChecked: variants.length,
|
|
692
|
-
variantsWithoutBody: withoutBody
|
|
693
|
-
};
|
|
694
|
-
return audit2;
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
869
|
|
|
698
870
|
// src/insights/copy/copy-preview.ts
|
|
699
|
-
import { z as z4 } from "zod";
|
|
700
|
-
|
|
701
|
-
// src/insights/people/read.ts
|
|
702
871
|
import { z as z3 } from "zod";
|
|
703
872
|
|
|
704
|
-
// src/insights/capped.ts
|
|
705
|
-
var readCapped = async (context, open, cap, room = cap.max) => {
|
|
706
|
-
if (room >= 1) {
|
|
707
|
-
const walk = open(room);
|
|
708
|
-
const items = await context.all(walk, cap);
|
|
709
|
-
return { capped: walk.truncated, items };
|
|
710
|
-
}
|
|
711
|
-
const probe = open(1);
|
|
712
|
-
const left = await context.all(probe, cap);
|
|
713
|
-
if (left.length > 0 && !probe.truncated) {
|
|
714
|
-
context.partial(capNote(cap));
|
|
715
|
-
}
|
|
716
|
-
return { capped: left.length > 0, items: [] };
|
|
717
|
-
};
|
|
718
|
-
var campaignsReadOf = (read) => ({
|
|
719
|
-
campaignsRead: read.items.length,
|
|
720
|
-
moreCampaignsExist: read.capped
|
|
721
|
-
});
|
|
722
|
-
var readCampaignsIn = async (context, statuses, max, input28 = "max_campaigns") => {
|
|
723
|
-
const { campaigns } = context.outbound;
|
|
724
|
-
const wanted = [...new Set(statuses)];
|
|
725
|
-
const cap = { input: input28, max, what: "campaigns" };
|
|
726
|
-
if (context.outbound.capabilities["campaigns.status"] === false) {
|
|
727
|
-
const every = await readCapped(
|
|
728
|
-
context,
|
|
729
|
-
(room) => campaigns.listAll({ max: room }),
|
|
730
|
-
cap
|
|
731
|
-
);
|
|
732
|
-
const items = every.items.filter(
|
|
733
|
-
(campaign) => wanted.includes(campaign.status)
|
|
734
|
-
);
|
|
735
|
-
context.campaignsFound(items.length);
|
|
736
|
-
return { capped: every.capped, items };
|
|
737
|
-
}
|
|
738
|
-
const found = [];
|
|
739
|
-
let capped2 = false;
|
|
740
|
-
for (const status of wanted) {
|
|
741
|
-
const listed = await readCapped(
|
|
742
|
-
context,
|
|
743
|
-
(room) => campaigns.listAll({ max: room, status }),
|
|
744
|
-
cap,
|
|
745
|
-
max - found.length
|
|
746
|
-
);
|
|
747
|
-
found.push(...listed.items);
|
|
748
|
-
capped2 ||= listed.capped;
|
|
749
|
-
}
|
|
750
|
-
context.campaignsFound(found.length);
|
|
751
|
-
return { capped: capped2, items: found };
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
// src/insights/fields.ts
|
|
755
|
-
import { z as z2 } from "zod";
|
|
756
|
-
var rangeFields = {
|
|
757
|
-
from: z2.iso.date().nullable().default(null).describe("First day counted, YYYY-MM-DD. null for the whole history."),
|
|
758
|
-
to: z2.iso.date().nullable().default(null).describe("Last day counted, YYYY-MM-DD. null for up to today.")
|
|
759
|
-
};
|
|
760
|
-
var statusesInput = (fallback) => z2.array(campaignStatusSchema).min(1).default([...fallback]).describe(
|
|
761
|
-
"Only campaigns in one of these states are read: active, paused, completed, draft, archived or unknown"
|
|
762
|
-
);
|
|
763
|
-
|
|
764
|
-
// src/insights/people/read.ts
|
|
765
|
-
var readCappedFlag = (context, open, max, what, input28) => readCapped(context, open, { input: input28, max, what });
|
|
766
|
-
var readByRef = async (context, refs, read, what, effect) => {
|
|
767
|
-
if (refs.length === 0) {
|
|
768
|
-
return /* @__PURE__ */ new Map();
|
|
769
|
-
}
|
|
770
|
-
const found = await read(refs);
|
|
771
|
-
if (found.errors.length > 0) {
|
|
772
|
-
context.note(
|
|
773
|
-
`${plural(found.errors.length, ...what)} could not be read, so ${noun(found.errors.length, "its", "their")} ${effect}.`
|
|
774
|
-
);
|
|
775
|
-
}
|
|
776
|
-
const [costliest] = found.results.toSorted(
|
|
777
|
-
(left, right) => right.value.meta.requests - left.value.meta.requests
|
|
778
|
-
);
|
|
779
|
-
if (costliest !== void 0) {
|
|
780
|
-
context.one(costliest.value);
|
|
781
|
-
}
|
|
782
|
-
return new Map(found.results.map(({ id, value }) => [id, value]));
|
|
783
|
-
};
|
|
784
|
-
var statusesField = statusesInput(["active"]);
|
|
785
|
-
var campaignsIn = async (context, statuses, max) => {
|
|
786
|
-
const { items } = await readCampaignsIn(context, statuses, max);
|
|
787
|
-
return items;
|
|
788
|
-
};
|
|
789
|
-
var leadsOf = async (context, campaign, max, input28) => {
|
|
790
|
-
const { items } = await readCappedFlag(
|
|
791
|
-
context,
|
|
792
|
-
(cap) => context.outbound.campaign(campaign).leads.listAll({ max: cap }),
|
|
793
|
-
max,
|
|
794
|
-
"leads of a campaign",
|
|
795
|
-
input28
|
|
796
|
-
);
|
|
797
|
-
return items;
|
|
798
|
-
};
|
|
799
|
-
var nameOf = (lead) => {
|
|
800
|
-
const name = [lead.firstName, lead.lastName].flatMap((part) => part === null || part.trim() === "" ? [] : [part]).join(" ");
|
|
801
|
-
return name === "" ? null : name;
|
|
802
|
-
};
|
|
803
|
-
var domainOf = (email) => {
|
|
804
|
-
const domain = email?.split("@").at(-1) ?? "";
|
|
805
|
-
return email === null || !email.includes("@") || domain === "" ? null : domain;
|
|
806
|
-
};
|
|
807
|
-
var DEFAULT_POSITIVE_LABELS = [
|
|
808
|
-
"Interested",
|
|
809
|
-
"Meeting Booked",
|
|
810
|
-
"Meeting Completed"
|
|
811
|
-
];
|
|
812
|
-
var positiveLabelsField = z3.array(z3.string().min(1)).default(DEFAULT_POSITIVE_LABELS).describe(
|
|
813
|
-
"Vendor interest labels that count as interested, matched without regard to case"
|
|
814
|
-
);
|
|
815
|
-
var isPositive = (label, labels) => label === null ? null : labels.some(
|
|
816
|
-
(each) => each.trim().toLowerCase() === label.trim().toLowerCase()
|
|
817
|
-
);
|
|
818
|
-
var hasReplied = (lead) => lead.replied === true || (lead.engagement?.replies ?? 0) > 0 || (lead.engagement?.lastRepliedAt ?? null) !== null;
|
|
819
|
-
var OUT_OF_OFFICE = /\bout[\s-]+of[\s-]+(?:the\s+)?office\b/iu;
|
|
820
|
-
var AUTOMATIC = /* @__PURE__ */ new Set([
|
|
821
|
-
"bounce",
|
|
822
|
-
"ooo"
|
|
823
|
-
]);
|
|
824
|
-
var isAutoReplied = (lead) => lead.interestCategory !== null && AUTOMATIC.has(lead.interestCategory) || // A label the vendor did not map to a category is read by a fixed rule.
|
|
825
|
-
lead.interestCategory === null && OUT_OF_OFFICE.test(lead.interest ?? "");
|
|
826
|
-
var hasHumanReply = (lead) => hasReplied(lead) && !isAutoReplied(lead);
|
|
827
|
-
var NEGATIVE_CATEGORIES = /* @__PURE__ */ new Set(["negative", "unsubscribe"]);
|
|
828
|
-
var NEGATIVE_LABEL = /\b(?:not[\s-]+interested|wrong[\s-]+person|unsubscribed?|do[\s-]+not[\s-]+contact)\b/iu;
|
|
829
|
-
var isNegative = (lead) => lead.interestCategory !== null && NEGATIVE_CATEGORIES.has(lead.interestCategory) || lead.interestCategory === null && NEGATIVE_LABEL.test(lead.interest ?? "");
|
|
830
|
-
var COUNTS = "no per-lead open, click or reply counts";
|
|
831
|
-
var noteEngagement = (context, leads, effect) => {
|
|
832
|
-
const { outbound } = context;
|
|
833
|
-
if (outbound.capabilities["leads.engagement"]) {
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
if (leads.every((lead) => lead.provider === outbound.provider)) {
|
|
837
|
-
context.note(`This tool reports ${COUNTS}, so ${effect}.`);
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
const reporting = new Set(
|
|
841
|
-
leads.flatMap((lead) => lead.engagement === null ? [] : [lead.provider])
|
|
842
|
-
);
|
|
843
|
-
const lacking = [...new Set(leads.map((lead) => lead.provider))].filter((provider) => !reporting.has(provider)).toSorted();
|
|
844
|
-
if (lacking.length > 0) {
|
|
845
|
-
context.note(
|
|
846
|
-
`${lacking.join(", ")} ${lacking.length === 1 ? "reports" : "report"} ${COUNTS}, so ${effect} for ${lacking.length === 1 ? "its" : "their"} records. Records from the other tools carry what their vendor reports.`
|
|
847
|
-
);
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
|
|
851
873
|
// src/insights/ref.ts
|
|
852
874
|
var refOf = (outbound, id) => {
|
|
853
875
|
const provider = parseRef(id)?.provider;
|
|
854
876
|
return provider === outbound.provider || provider !== void 0 && outbound.provider === "combined" ? id : makeRef(outbound.provider, outbound.workspaceId, id);
|
|
855
877
|
};
|
|
856
878
|
|
|
857
|
-
// src/insights/variables.ts
|
|
858
|
-
var PATTERNS = [
|
|
859
|
-
/\{\{\s*(?<name>[^{}|]+?)\s*(?<fallback>\|[^{}]*)?\}\}/gu,
|
|
860
|
-
/(?<!\{)\{(?<name>[A-Za-z_][\w .-]*)\}(?!\})/gu,
|
|
861
|
-
/%(?<name>[A-Za-z_][\w-]*)%/gu
|
|
862
|
-
];
|
|
863
|
-
var keyOf = (name) => name.toLowerCase().replaceAll(/[\s_-]/gu, "");
|
|
864
|
-
var BUILTINS = /* @__PURE__ */ new Map([
|
|
865
|
-
["company", (lead) => lead.company],
|
|
866
|
-
["companyname", (lead) => lead.company],
|
|
867
|
-
["email", (lead) => lead.email],
|
|
868
|
-
["firstname", (lead) => lead.firstName],
|
|
869
|
-
["jobtitle", (lead) => lead.title],
|
|
870
|
-
["lastname", (lead) => lead.lastName],
|
|
871
|
-
["title", (lead) => lead.title]
|
|
872
|
-
]);
|
|
873
|
-
var isBuiltin = (key) => BUILTINS.has(key);
|
|
874
|
-
var variablesIn = (text) => PATTERNS.flatMap(
|
|
875
|
-
(pattern) => [...text.matchAll(pattern)].map((match) => {
|
|
876
|
-
const fallback = match.groups?.fallback;
|
|
877
|
-
return {
|
|
878
|
-
fallback: fallback === void 0 ? null : fallback.slice(1).trim(),
|
|
879
|
-
index: match.index,
|
|
880
|
-
name: match.groups?.name ?? "",
|
|
881
|
-
raw: match[0]
|
|
882
|
-
};
|
|
883
|
-
})
|
|
884
|
-
);
|
|
885
|
-
var filled = (value) => value !== null && value !== void 0 && value.trim() !== "";
|
|
886
|
-
var valueOf = (lead, key) => {
|
|
887
|
-
const builtin = BUILTINS.get(key)?.(lead);
|
|
888
|
-
if (filled(builtin)) {
|
|
889
|
-
return builtin;
|
|
890
|
-
}
|
|
891
|
-
const custom = Object.entries(lead.custom).find(
|
|
892
|
-
([name, value]) => keyOf(name) === key && filled(value)
|
|
893
|
-
);
|
|
894
|
-
return custom?.[1] ?? null;
|
|
895
|
-
};
|
|
896
|
-
var keysWithValue = (lead) => /* @__PURE__ */ new Set([
|
|
897
|
-
...[...BUILTINS].flatMap(
|
|
898
|
-
([key, read]) => filled(read(lead)) ? [key] : []
|
|
899
|
-
),
|
|
900
|
-
...Object.entries(lead.custom).flatMap(
|
|
901
|
-
([key, value]) => filled(value) ? [keyOf(key)] : []
|
|
902
|
-
)
|
|
903
|
-
]);
|
|
904
|
-
var fillVariables = (text, lead) => {
|
|
905
|
-
const matches = variablesIn(text).toSorted(
|
|
906
|
-
(left, right) => left.index - right.index
|
|
907
|
-
);
|
|
908
|
-
const unfilled = [];
|
|
909
|
-
let out = "";
|
|
910
|
-
let at = 0;
|
|
911
|
-
for (const match of matches) {
|
|
912
|
-
if (match.index >= at) {
|
|
913
|
-
const value = valueOf(lead, keyOf(match.name)) ?? match.fallback;
|
|
914
|
-
if (value === null && !unfilled.includes(match.name)) {
|
|
915
|
-
unfilled.push(match.name);
|
|
916
|
-
}
|
|
917
|
-
out += text.slice(at, match.index) + (value ?? match.raw);
|
|
918
|
-
at = match.index + match.raw.length;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
return { text: out + text.slice(at), unfilled };
|
|
922
|
-
};
|
|
923
|
-
|
|
924
879
|
// src/insights/copy/copy-preview.ts
|
|
925
|
-
var
|
|
926
|
-
campaign:
|
|
927
|
-
|
|
880
|
+
var input = z3.object({
|
|
881
|
+
campaign: z3.string().min(1).describe(
|
|
882
|
+
"The campaign's ref, for example `instantly:acme:abc123`, or its name"
|
|
883
|
+
),
|
|
884
|
+
lead: z3.string().min(1).nullable().default(null).describe(
|
|
928
885
|
"The lead's ref to render the copy for. null picks the lead read with the most variables filled."
|
|
929
886
|
),
|
|
930
|
-
max_leads:
|
|
887
|
+
max_leads: z3.number().int().min(1).max(1e3).default(100).describe(
|
|
931
888
|
"The most leads to read when picking one. Ignored when `lead` is given."
|
|
932
889
|
)
|
|
933
890
|
});
|
|
@@ -941,17 +898,10 @@ var keysIn = (sequence2) => new Set(
|
|
|
941
898
|
)
|
|
942
899
|
)
|
|
943
900
|
);
|
|
944
|
-
var
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
const score = [...keys].filter((key) => has.has(key)).length;
|
|
949
|
-
if (best === void 0 || score > best.score) {
|
|
950
|
-
best = { lead, score };
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return best?.lead;
|
|
954
|
-
};
|
|
901
|
+
var rankLeads = (leads, keys) => leads.map((lead) => {
|
|
902
|
+
const has = keysWithValue(lead);
|
|
903
|
+
return { lead, score: [...keys].filter((key) => has.has(key)).length };
|
|
904
|
+
}).toSorted((left, right) => right.score - left.score).map(({ lead }) => lead);
|
|
955
905
|
var render = (text, lead, unfilled) => {
|
|
956
906
|
if (text === null) {
|
|
957
907
|
return null;
|
|
@@ -974,86 +924,327 @@ var plain = (body) => {
|
|
|
974
924
|
if (body === null) {
|
|
975
925
|
return null;
|
|
976
926
|
}
|
|
977
|
-
return looksLikeHtml(body) ? htmlToText(body) : body.trim();
|
|
927
|
+
return looksLikeHtml(body) ? htmlToText(body) : body.trim();
|
|
928
|
+
};
|
|
929
|
+
var renderVariant = (variant, lead) => {
|
|
930
|
+
const unfilled = /* @__PURE__ */ new Set();
|
|
931
|
+
const subject = render(variant.subject, lead, unfilled);
|
|
932
|
+
const body = render(variant.body, lead, unfilled);
|
|
933
|
+
return { body, subject, unfilled: [...unfilled] };
|
|
934
|
+
};
|
|
935
|
+
var previewStep = (step, lead) => ({
|
|
936
|
+
action: step.action,
|
|
937
|
+
delayDays: step.delayDays,
|
|
938
|
+
...stepAt(step.index),
|
|
939
|
+
variants: step.variants.map((variant) => {
|
|
940
|
+
const { body, subject, unfilled } = renderVariant(variant, lead);
|
|
941
|
+
return {
|
|
942
|
+
rendered: { body, bodyText: plain(body), subject },
|
|
943
|
+
template: { body: variant.body, subject: variant.subject },
|
|
944
|
+
unfilled,
|
|
945
|
+
variantKey: variant.variantKey
|
|
946
|
+
};
|
|
947
|
+
})
|
|
948
|
+
});
|
|
949
|
+
var copyPreview = defineInsight({
|
|
950
|
+
description: "A campaign's copy as written and as one real lead receives it. Returns every step and variant with its subject and body exactly as stored, the same copy with the lead's values put into each {{variable}}, {variable} and %variable%, and the rendered body as plain text. Use it to read copy that is all or partly templated, such as {{subject1}} and {{content1}} filled from custom fields. Values come from first name, last name, company, title, email, or a custom field of the same name without regard to case, spaces, underscores or hyphens; a missing value falls back to the copy's own fallback, such as {{firstName|there}}, and otherwise the variable is left as written and listed as unfilled. Pass a lead's ref to choose the lead, or leave it out to use the lead read with the most variables filled. A sender signature or other variable the tool fills itself at send time stays as written. Spintax is not resolved. Costs one request for the sequence plus one for a given lead, or one per page of leads read.",
|
|
951
|
+
inputSchema: input,
|
|
952
|
+
key: "copyPreview",
|
|
953
|
+
cost: (values, price) => price.one("sequence.get") + (values.lead === null ? price.upTo(1) * price.list("leads.list", values.max_leads) : price.one("leads.get")),
|
|
954
|
+
scales: "max_leads",
|
|
955
|
+
name: "copy_preview",
|
|
956
|
+
needs: ["sequence", "leads.byCampaign"],
|
|
957
|
+
next: "Use personalization_gaps to find every lead who would get a variable left as written.",
|
|
958
|
+
run: async (context, values) => {
|
|
959
|
+
const sequence2 = context.one(
|
|
960
|
+
await context.outbound.campaign(values.campaign).sequence()
|
|
961
|
+
);
|
|
962
|
+
const keys = keysIn(sequence2);
|
|
963
|
+
let lead;
|
|
964
|
+
if (values.lead !== null) {
|
|
965
|
+
lead = context.one(await context.outbound.lead(values.lead).get());
|
|
966
|
+
} else if (keys.size === 0) {
|
|
967
|
+
context.note("The copy uses no variables, so no lead was read.");
|
|
968
|
+
} else {
|
|
969
|
+
[lead] = rankLeads(
|
|
970
|
+
await leadsOf(context, values.campaign, values.max_leads, "max_leads"),
|
|
971
|
+
keys
|
|
972
|
+
);
|
|
973
|
+
if (lead === void 0) {
|
|
974
|
+
context.note(
|
|
975
|
+
"The campaign has no leads, so the copy is shown as written."
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
const masked = maskingOf(context.outbound)?.fields.some(
|
|
980
|
+
(field) => LEAD_FIELDS.has(field)
|
|
981
|
+
);
|
|
982
|
+
if (lead !== void 0 && masked === true) {
|
|
983
|
+
context.note(
|
|
984
|
+
"The redact plugin masks the lead's fields, so the rendered copy shows them masked. Read it without redact to see the values."
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
const steps = sequence2.steps.map((step) => previewStep(step, lead));
|
|
988
|
+
const unfilled = new Set(
|
|
989
|
+
steps.flatMap(
|
|
990
|
+
(step) => step.variants.flatMap((variant) => variant.unfilled.map(keyOf))
|
|
991
|
+
)
|
|
992
|
+
);
|
|
993
|
+
const has = lead === void 0 ? null : keysWithValue(lead);
|
|
994
|
+
const answer = {
|
|
995
|
+
campaign: refOf(context.outbound, values.campaign),
|
|
996
|
+
lead: lead === void 0 || has === null ? null : {
|
|
997
|
+
email: lead.email,
|
|
998
|
+
lead: lead.ref,
|
|
999
|
+
linkedinUrl: lead.linkedinUrl,
|
|
1000
|
+
variablesFilled: [...keys].filter((key) => has.has(key)).length
|
|
1001
|
+
},
|
|
1002
|
+
steps,
|
|
1003
|
+
totals: {
|
|
1004
|
+
steps: steps.length,
|
|
1005
|
+
unfilled: unfilled.size,
|
|
1006
|
+
variables: keys.size,
|
|
1007
|
+
variants: steps.reduce((sum, step) => sum + step.variants.length, 0)
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
return answer;
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
// src/insights/copy/audit-samples.ts
|
|
1015
|
+
var PER_LEAD_SHARE = 0.8;
|
|
1016
|
+
var variableShare = (text) => {
|
|
1017
|
+
if (text === null) {
|
|
1018
|
+
return 0;
|
|
1019
|
+
}
|
|
1020
|
+
const plain2 = (looksLikeHtml(text) ? htmlToText(text) : text).replaceAll(
|
|
1021
|
+
/\s/gu,
|
|
1022
|
+
""
|
|
1023
|
+
);
|
|
1024
|
+
if (plain2 === "") {
|
|
1025
|
+
return 0;
|
|
1026
|
+
}
|
|
1027
|
+
const inVariables = variablesIn(plain2).reduce(
|
|
1028
|
+
(sum, match) => sum + match.raw.length,
|
|
1029
|
+
0
|
|
1030
|
+
);
|
|
1031
|
+
return inVariables / plain2.length;
|
|
1032
|
+
};
|
|
1033
|
+
var writtenPerLead = (variant) => variableShare(variant.subject) > PER_LEAD_SHARE || variableShare(variant.body) > PER_LEAD_SHARE;
|
|
1034
|
+
var perLeadKeys = (steps) => new Set(
|
|
1035
|
+
steps.flatMap(
|
|
1036
|
+
(step) => step.variants.filter(writtenPerLead).flatMap(
|
|
1037
|
+
(variant) => [variant.subject ?? "", variant.body ?? ""].flatMap(
|
|
1038
|
+
(text) => variablesIn(text).map((match) => keyOf(match.name))
|
|
1039
|
+
)
|
|
1040
|
+
)
|
|
1041
|
+
)
|
|
1042
|
+
);
|
|
1043
|
+
var pickSamples = (leads, keys, samples) => rankLeads(leads, keys).slice(0, samples);
|
|
1044
|
+
var renderSteps = (steps, lead) => steps.map((step) => ({
|
|
1045
|
+
...step,
|
|
1046
|
+
variants: step.variants.map((variant) => {
|
|
1047
|
+
const { body, subject } = renderVariant(variant, lead);
|
|
1048
|
+
return { ...variant, body, subject };
|
|
1049
|
+
})
|
|
1050
|
+
}));
|
|
1051
|
+
var auditSamples = (steps, leads, limits, isEmail) => {
|
|
1052
|
+
const audited = /* @__PURE__ */ new Set();
|
|
1053
|
+
const findings = [];
|
|
1054
|
+
const refs = [];
|
|
1055
|
+
for (const lead of leads) {
|
|
1056
|
+
const rendered = renderSteps(steps, lead);
|
|
1057
|
+
const thread = isEmail ? threadOf(rendered, writtenPerLead) : null;
|
|
1058
|
+
let any = false;
|
|
1059
|
+
for (const [at, step] of rendered.entries()) {
|
|
1060
|
+
for (const [index, variant] of step.variants.entries()) {
|
|
1061
|
+
const template = steps[at]?.variants[index];
|
|
1062
|
+
if (template !== void 0 && writtenPerLead(template) && !writtenPerLead(variant)) {
|
|
1063
|
+
any = true;
|
|
1064
|
+
audited.add(`${step.index}:${variant.variantKey}`);
|
|
1065
|
+
findings.push(
|
|
1066
|
+
...auditVariant(step, variant, limits, thread, lead.ref)
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (any) {
|
|
1072
|
+
refs.push(lead.ref);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
const perLead2 = steps.reduce(
|
|
1076
|
+
(sum, step) => sum + step.variants.filter(writtenPerLead).length,
|
|
1077
|
+
0
|
|
1078
|
+
);
|
|
1079
|
+
return { findings, leads: refs, unaudited: perLead2 - audited.size };
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
// src/insights/copy/copy-audit.ts
|
|
1083
|
+
var limit = (fallback, description) => z4.number().int().min(0).default(fallback).describe(description);
|
|
1084
|
+
var input2 = z4.object({
|
|
1085
|
+
campaign: z4.string().min(1).describe(
|
|
1086
|
+
"The campaign's ref, for example `instantly:acme:abc123`, or its name"
|
|
1087
|
+
),
|
|
1088
|
+
max_body_words: limit(150, "The most words a body may have."),
|
|
1089
|
+
max_caps_words: limit(
|
|
1090
|
+
1,
|
|
1091
|
+
"How many words of four or more letters may be in capitals, so one acronym is not a finding."
|
|
1092
|
+
),
|
|
1093
|
+
max_connection_chars: limit(
|
|
1094
|
+
300,
|
|
1095
|
+
"The most characters a LinkedIn connection request may have."
|
|
1096
|
+
),
|
|
1097
|
+
max_exclamations: limit(1, "How many exclamation marks a message may have."),
|
|
1098
|
+
max_links: limit(1, "The most links an email body may have."),
|
|
1099
|
+
max_leads: z4.number().int().min(1).max(1e3).default(100).describe(
|
|
1100
|
+
"The most leads to read when picking the samples. Read only when copy is written per lead."
|
|
1101
|
+
),
|
|
1102
|
+
max_subject_chars: limit(60, "The most characters a subject may have."),
|
|
1103
|
+
samples: z4.number().int().min(0).max(20).default(3).describe(
|
|
1104
|
+
"How many leads' rendered copy to audit when a subject or body is mostly variables, such as {{body_1}} filled from a custom field. The leads that fill the most of those variables are used. 0 audits the copy as stored only."
|
|
1105
|
+
),
|
|
1106
|
+
spam_words: z4.array(z4.string().min(1)).default([...DEFAULT_SPAM_WORDS]).describe(
|
|
1107
|
+
"Words and phrases to flag in email copy, matched whole and without case. Replaces the default list."
|
|
1108
|
+
)
|
|
1109
|
+
});
|
|
1110
|
+
var RANK2 = { high: 0, low: 2, medium: 1 };
|
|
1111
|
+
var EMAIL_ONLY = [
|
|
1112
|
+
"image",
|
|
1113
|
+
"missing_subject",
|
|
1114
|
+
"spam_words",
|
|
1115
|
+
"subject_breaks_thread",
|
|
1116
|
+
"subject_too_long",
|
|
1117
|
+
"too_many_links"
|
|
1118
|
+
];
|
|
1119
|
+
var LINKEDIN_ONLY = ["connection_request_too_long"];
|
|
1120
|
+
var cleanOf = (findings, unaudited) => findings === 0 && unaudited === 0;
|
|
1121
|
+
var CHECK_NAMES = Object.keys(CHECKS);
|
|
1122
|
+
var countsOf = (findings, isEmail) => CHECK_NAMES.filter(
|
|
1123
|
+
(check) => !(isEmail ? LINKEDIN_ONLY : EMAIL_ONLY).includes(check)
|
|
1124
|
+
).map((check) => ({
|
|
1125
|
+
check,
|
|
1126
|
+
count: findings.filter((finding) => finding.check === check).length,
|
|
1127
|
+
severity: CHECKS[check]
|
|
1128
|
+
})).toSorted(
|
|
1129
|
+
(left, right) => right.count - left.count || RANK2[left.severity] - RANK2[right.severity] || left.check.localeCompare(right.check)
|
|
1130
|
+
);
|
|
1131
|
+
var readSamples = async (context, args, sequence2) => {
|
|
1132
|
+
if (!sequence2.steps.some((step) => step.variants.some(writtenPerLead))) {
|
|
1133
|
+
return { leads: [], reason: null };
|
|
1134
|
+
}
|
|
1135
|
+
if (args.samples === 0) {
|
|
1136
|
+
return { leads: [], reason: "samples is 0" };
|
|
1137
|
+
}
|
|
1138
|
+
if (context.outbound.capabilities["leads.byCampaign"] === false) {
|
|
1139
|
+
return { leads: [], reason: "this tool does not list a campaign's leads" };
|
|
1140
|
+
}
|
|
1141
|
+
const leads = await leadsOf(
|
|
1142
|
+
context,
|
|
1143
|
+
args.campaign,
|
|
1144
|
+
args.max_leads,
|
|
1145
|
+
"max_leads"
|
|
1146
|
+
);
|
|
1147
|
+
return leads.length === 0 ? { leads: [], reason: "the campaign has no leads" } : {
|
|
1148
|
+
leads: pickSamples(leads, perLeadKeys(sequence2.steps), args.samples),
|
|
1149
|
+
reason: null
|
|
1150
|
+
};
|
|
1151
|
+
};
|
|
1152
|
+
var noteSamples = (context, perLead2, samples, audit2) => {
|
|
1153
|
+
if (perLead2 === 0) {
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
const variants = plural(perLead2, "variant");
|
|
1157
|
+
const reason = samples.reason ?? "no lead read has values for their variables";
|
|
1158
|
+
if (audit2.leads.length === 0) {
|
|
1159
|
+
context.note(
|
|
1160
|
+
`${variants} ${perLead2 === 1 ? "is" : "are"} written per lead in variables, and the copy could not be audited as any lead receives it: ${reason}.`
|
|
1161
|
+
);
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
context.note(
|
|
1165
|
+
`${variants} ${perLead2 === 1 ? "is" : "are"} written per lead in variables, so the rendered copy of ${plural(audit2.leads.length, "sample lead")} was audited; each finding names its lead.`
|
|
1166
|
+
);
|
|
1167
|
+
if (audit2.unaudited > 0) {
|
|
1168
|
+
context.note(
|
|
1169
|
+
`${plural(audit2.unaudited, "variant")} written per lead could not be audited: no sample lead has values for ${audit2.unaudited === 1 ? "its" : "their"} variables.`
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
978
1172
|
};
|
|
979
|
-
var
|
|
980
|
-
|
|
981
|
-
delayDays: step.delayDays,
|
|
982
|
-
step: step.index,
|
|
983
|
-
variants: step.variants.map((variant) => {
|
|
984
|
-
const unfilled = /* @__PURE__ */ new Set();
|
|
985
|
-
const subject = render(variant.subject, lead, unfilled);
|
|
986
|
-
const body = render(variant.body, lead, unfilled);
|
|
987
|
-
return {
|
|
988
|
-
rendered: { body, bodyText: plain(body), subject },
|
|
989
|
-
template: { body: variant.body, subject: variant.subject },
|
|
990
|
-
unfilled: [...unfilled],
|
|
991
|
-
variantKey: variant.variantKey
|
|
992
|
-
};
|
|
993
|
-
})
|
|
994
|
-
});
|
|
995
|
-
var copyPreview = defineInsight({
|
|
996
|
-
description: "A campaign's copy as written and as one real lead receives it. Returns every step and variant with its subject and body exactly as stored, the same copy with the lead's values put into each {{variable}}, {variable} and %variable%, and the rendered body as plain text. Use it to read copy that is all or partly templated, such as {{subject1}} and {{content1}} filled from custom fields. Values come from first name, last name, company, title, email, or a custom field of the same name without regard to case, spaces, underscores or hyphens; a missing value falls back to the copy's own fallback, such as {{firstName|there}}, and otherwise the variable is left as written and listed as unfilled. Pass a lead's ref to choose the lead, or leave it out to use the lead read with the most variables filled. A sender signature or other variable the tool fills itself at send time stays as written. Spintax is not resolved. Costs one request for the sequence plus one for a given lead, or one per page of leads read.",
|
|
1173
|
+
var copyAudit = defineInsight({
|
|
1174
|
+
description: "Problems in a campaign's copy before it sends. Checks every step and variant for a long subject, a long body, too many links, spam words, unbalanced or empty {{ }} variables, words in capitals, repeated exclamation marks, an image or tracking pixel, a missing subject on the first email, and a follow-up whose subject breaks the thread; a LinkedIn campaign skips the email-only checks and flags a connection request over the character limit. Returns each finding with a severity and the text that triggered it, and a count per check. When a subject or body is mostly variables, such as {{body_1}} filled from a custom field, that variant is audited as sample leads receive it, rendered as copy_preview renders it, and each such finding names its lead; when a variant cannot be rendered for any sample lead, clean is false and variantsNotAudited counts it, never a bare clean true. Costs 2 requests, plus one per page of leads read when copy is written per lead. Fixed rules only, no model. A variant whose body the vendor does not return is counted, not judged.",
|
|
997
1175
|
inputSchema: input2,
|
|
998
|
-
key: "
|
|
999
|
-
cost: (values, price) => price.one("sequence.get") + (values.
|
|
1176
|
+
key: "copyAudit",
|
|
1177
|
+
cost: (values, price) => price.one("campaigns.get") + price.one("sequence.get") + (values.samples === 0 ? 0 : price.upTo(1) * price.list("leads.list", values.max_leads)),
|
|
1000
1178
|
scales: "max_leads",
|
|
1001
|
-
name: "
|
|
1002
|
-
needs: ["sequence"
|
|
1003
|
-
next: "Use
|
|
1004
|
-
run: async (context,
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1179
|
+
name: "copy_audit",
|
|
1180
|
+
needs: ["sequence"],
|
|
1181
|
+
next: "Use step_funnel to see whether the steps with findings are also the ones with few replies.",
|
|
1182
|
+
run: async (context, args) => {
|
|
1183
|
+
const handle = context.outbound.campaign(args.campaign);
|
|
1184
|
+
const campaign = context.one(await handle.get());
|
|
1185
|
+
const sequence2 = context.one(await handle.sequence());
|
|
1186
|
+
const isEmail = campaign.channel === "email";
|
|
1187
|
+
const limits = {
|
|
1188
|
+
maxBodyWords: args.max_body_words,
|
|
1189
|
+
maxCapsWords: args.max_caps_words,
|
|
1190
|
+
maxConnectionChars: args.max_connection_chars,
|
|
1191
|
+
maxExclamations: args.max_exclamations,
|
|
1192
|
+
maxLinks: args.max_links,
|
|
1193
|
+
maxSubjectChars: args.max_subject_chars,
|
|
1194
|
+
spamWords: args.spam_words
|
|
1195
|
+
};
|
|
1196
|
+
const thread = isEmail ? threadOf(sequence2.steps, writtenPerLead) : null;
|
|
1197
|
+
const variants = sequence2.steps.flatMap(
|
|
1198
|
+
(step) => step.variants.map((variant) => ({ step, variant }))
|
|
1007
1199
|
);
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
keys
|
|
1018
|
-
);
|
|
1019
|
-
if (lead === void 0) {
|
|
1020
|
-
context.note(
|
|
1021
|
-
"The campaign has no leads, so the copy is shown as written."
|
|
1022
|
-
);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
const masked = maskingOf(context.outbound)?.fields.some(
|
|
1026
|
-
(field) => LEAD_FIELDS.has(field)
|
|
1200
|
+
const perLead2 = variants.filter(
|
|
1201
|
+
({ variant }) => writtenPerLead(variant)
|
|
1202
|
+
).length;
|
|
1203
|
+
const samples = await readSamples(context, args, sequence2);
|
|
1204
|
+
const sampled = auditSamples(
|
|
1205
|
+
sequence2.steps,
|
|
1206
|
+
samples.leads,
|
|
1207
|
+
limits,
|
|
1208
|
+
isEmail
|
|
1027
1209
|
);
|
|
1028
|
-
|
|
1210
|
+
const findings = [
|
|
1211
|
+
...variants.flatMap(
|
|
1212
|
+
({ step, variant }) => writtenPerLead(variant) ? [] : auditVariant(step, variant, limits, thread, null)
|
|
1213
|
+
),
|
|
1214
|
+
...sampled.findings
|
|
1215
|
+
].toSorted(
|
|
1216
|
+
(left, right) => RANK2[left.severity] - RANK2[right.severity] || left.stepIndex - right.stepIndex || left.variantKey.localeCompare(right.variantKey) || left.check.localeCompare(right.check) || (left.lead ?? "").localeCompare(right.lead ?? "")
|
|
1217
|
+
);
|
|
1218
|
+
const withoutBody = variants.filter(
|
|
1219
|
+
({ variant }) => variant.body === null
|
|
1220
|
+
).length;
|
|
1221
|
+
if (withoutBody > 0) {
|
|
1029
1222
|
context.note(
|
|
1030
|
-
"
|
|
1223
|
+
withoutBody === 1 ? "1 variant has no body in the vendor's answer, so its body checks were skipped." : `${withoutBody} variants have no body in the vendor's answer, so their body checks were skipped.`
|
|
1031
1224
|
);
|
|
1032
1225
|
}
|
|
1033
|
-
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
campaign: refOf(context.outbound, values.campaign),
|
|
1042
|
-
lead: lead === void 0 || has === null ? null : {
|
|
1043
|
-
email: lead.email,
|
|
1044
|
-
lead: lead.ref,
|
|
1045
|
-
linkedinUrl: lead.linkedinUrl,
|
|
1046
|
-
variablesFilled: [...keys].filter((key) => has.has(key)).length
|
|
1226
|
+
noteSamples(context, perLead2, samples, sampled);
|
|
1227
|
+
const severity = (level) => findings.filter((finding) => finding.severity === level).length;
|
|
1228
|
+
const audit2 = {
|
|
1229
|
+
byCheck: countsOf(findings, isEmail),
|
|
1230
|
+
bySeverity: {
|
|
1231
|
+
high: severity("high"),
|
|
1232
|
+
low: severity("low"),
|
|
1233
|
+
medium: severity("medium")
|
|
1047
1234
|
},
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1235
|
+
campaign: campaign.ref,
|
|
1236
|
+
campaignName: campaign.name,
|
|
1237
|
+
channel: campaign.channel,
|
|
1238
|
+
clean: cleanOf(findings.length, sampled.unaudited),
|
|
1239
|
+
findings,
|
|
1240
|
+
stepsChecked: sequence2.steps.length,
|
|
1241
|
+
variantsChecked: variants.length,
|
|
1242
|
+
leadsAudited: sampled.leads,
|
|
1243
|
+
variantsWithoutBody: withoutBody,
|
|
1244
|
+
variantsNotAudited: sampled.unaudited,
|
|
1245
|
+
variantsWrittenPerLead: perLead2
|
|
1055
1246
|
};
|
|
1056
|
-
return
|
|
1247
|
+
return audit2;
|
|
1057
1248
|
}
|
|
1058
1249
|
});
|
|
1059
1250
|
|
|
@@ -1191,7 +1382,7 @@ var BASIS_WORDS = {
|
|
|
1191
1382
|
delivered: "per message delivered",
|
|
1192
1383
|
sent: "per message sent"
|
|
1193
1384
|
};
|
|
1194
|
-
var basesInWords = (
|
|
1385
|
+
var basesInWords = (named4) => named4.map(
|
|
1195
1386
|
({ basis, name }) => `${name} ${basis === null ? "with no base" : BASIS_WORDS[basis]}`
|
|
1196
1387
|
).join(", ");
|
|
1197
1388
|
var measure = (count2, base) => {
|
|
@@ -1221,7 +1412,7 @@ var replyRateOf = (measured2) => measured2 === null ? NO_RATE : {
|
|
|
1221
1412
|
of: measured2.of,
|
|
1222
1413
|
rate: measured2.rate
|
|
1223
1414
|
};
|
|
1224
|
-
var sumRows = (rows) =>
|
|
1415
|
+
var sumRows = (rows) => sumMeasured(rows);
|
|
1225
1416
|
var groupBy = (values, keyOf2) => {
|
|
1226
1417
|
const groups = /* @__PURE__ */ new Map();
|
|
1227
1418
|
for (const value of values) {
|
|
@@ -1432,8 +1623,8 @@ var copyReuse = defineInsight({
|
|
|
1432
1623
|
needs: ["sequence", "stats.byStep"],
|
|
1433
1624
|
next: "Use step_funnel on the campaign where the copy does worst, or variant_test where the copy runs against another variant.",
|
|
1434
1625
|
run: async (context, { max_campaigns, min_sent, statuses }) => {
|
|
1435
|
-
const
|
|
1436
|
-
const campaigns =
|
|
1626
|
+
const listed2 = await readCampaignsIn(context, statuses, max_campaigns);
|
|
1627
|
+
const campaigns = listed2.items;
|
|
1437
1628
|
const placements = await readPlacements(context, campaigns);
|
|
1438
1629
|
const without = placements.filter((each) => each.counts === null).length;
|
|
1439
1630
|
if (without > 0) {
|
|
@@ -1465,7 +1656,7 @@ var copyReuse = defineInsight({
|
|
|
1465
1656
|
basis,
|
|
1466
1657
|
bestCopy: bestCopy ?? null,
|
|
1467
1658
|
campaignsRead: campaigns.length,
|
|
1468
|
-
moreCampaignsExist:
|
|
1659
|
+
moreCampaignsExist: listed2.capped,
|
|
1469
1660
|
piecesOfCopy: pieces.length,
|
|
1470
1661
|
reused,
|
|
1471
1662
|
variantsWithoutStats: without
|
|
@@ -1491,6 +1682,9 @@ var input4 = z6.object({
|
|
|
1491
1682
|
campaign: z6.string().min(1).nullable().default(null).describe(
|
|
1492
1683
|
"A campaign's ref to look at one campaign; an unknown one is refused with NotFound. null looks at every campaign."
|
|
1493
1684
|
),
|
|
1685
|
+
include_auto: z6.boolean().default(false).describe(
|
|
1686
|
+
"Count replies flagged automatic (isAuto true), such as out-of-office messages and autoresponders. false leaves them out of every figure and counts them in counts.autoReplies."
|
|
1687
|
+
),
|
|
1494
1688
|
max_messages: z6.number().int().min(1).max(5e4).default(2e3).describe(
|
|
1495
1689
|
"The most messages to read, sent and received together. A page of messages costs 1 request."
|
|
1496
1690
|
),
|
|
@@ -1602,21 +1796,28 @@ var readMessages = async (context, campaign, since, max) => {
|
|
|
1602
1796
|
(message) => message.sentAt === null || message.sentAt >= since
|
|
1603
1797
|
);
|
|
1604
1798
|
};
|
|
1605
|
-
var noteGaps = (context, unpaired, received) => {
|
|
1606
|
-
const share2 = rate(unpaired, received);
|
|
1799
|
+
var noteGaps = (context, unpaired, received, includeAuto) => {
|
|
1800
|
+
const share2 = rate(unpaired, received.length);
|
|
1607
1801
|
if (share2 !== null && share2 > MAX_UNPAIRED_SHARE) {
|
|
1608
1802
|
context.partial(
|
|
1609
|
-
`${unpaired} of ${received} replies (${percent(share2)}) were not paired with a send, often because the send went out before since. Time to reply leaves them out, so it may look faster than it is; set since earlier to pair more.`
|
|
1803
|
+
`${unpaired} of ${received.length} replies (${percent(share2)}) were not paired with a send, often because the send went out before since. Time to reply leaves them out, so it may look faster than it is; set since earlier to pair more.`
|
|
1610
1804
|
);
|
|
1611
1805
|
}
|
|
1612
|
-
|
|
1806
|
+
const unflagged = received.filter(
|
|
1807
|
+
(message) => message.isAuto === null || message.isAuto === void 0
|
|
1808
|
+
).length;
|
|
1809
|
+
if (includeAuto && received.length > 0) {
|
|
1810
|
+
context.note(
|
|
1811
|
+
"Automatic replies such as out-of-office messages are counted as replies (include_auto). A fast median can be auto-replies."
|
|
1812
|
+
);
|
|
1813
|
+
} else if (unflagged > 0) {
|
|
1613
1814
|
context.note(
|
|
1614
|
-
|
|
1815
|
+
`${unflagged} of ${received.length} replies carry no auto flag, so an automatic one among them is counted as a reply. A fast median can be auto-replies.`
|
|
1615
1816
|
);
|
|
1616
1817
|
}
|
|
1617
1818
|
};
|
|
1618
1819
|
var replyTiming = defineInsight({
|
|
1619
|
-
description: "How fast people reply and when. Pairs each received message with the last message sent before it in the same thread (or to the same lead) and returns the median, 75th and 90th percentile of hours to reply, the share of replies within 1, 24 and 72 hours, replies by weekday and by hour of day, the weekday and hour of the sends that drew replies, and how many replies could not be paired; over a quarter unpaired, the answer is marked partial, since a reply to a send from before `since` cannot pair and those are the slow ones. Use it to choose follow-up delays and sending hours. Costs 1 request per page of messages, up to max_messages. A null figure means no reply could be paired
|
|
1820
|
+
description: "How fast people reply and when. Pairs each received message with the last message sent before it in the same thread (or to the same lead) and returns the median, 75th and 90th percentile of hours to reply, the share of replies within 1, 24 and 72 hours, replies by weekday and by hour of day, the weekday and hour of the sends that drew replies, and how many replies could not be paired; over a quarter unpaired, the answer is marked partial, since a reply to a send from before `since` cannot pair and those are the slow ones. Use it to choose follow-up delays and sending hours. Costs 1 request per page of messages, up to max_messages. A null figure means no reply could be paired. A received message flagged automatic (isAuto true: the vendor's flag, or a fixed rule on the sender, subject, canned phrases or a reply within a minute of the send) is left out and counted in counts.autoReplies unless include_auto is true; a message with no flag is counted as a reply.",
|
|
1620
1821
|
inputSchema: input4,
|
|
1621
1822
|
key: "replyTiming",
|
|
1622
1823
|
cost: (values, price) => price.list("messages.list", values.max_messages) + (values.campaign === null ? 0 : price.upTo(1) * price.one("campaigns.get")),
|
|
@@ -1626,24 +1827,28 @@ var replyTiming = defineInsight({
|
|
|
1626
1827
|
next: "Use step_funnel to see which step the replies answer, then set follow-up delays near the median time to reply.",
|
|
1627
1828
|
run: async (context, args) => {
|
|
1628
1829
|
const since = args.since === null ? new Date(context.now - 30 * DAY_MS).toISOString() : new Date(args.since).toISOString();
|
|
1629
|
-
const
|
|
1830
|
+
const read = await readMessages(
|
|
1630
1831
|
context,
|
|
1631
1832
|
args.campaign,
|
|
1632
1833
|
since,
|
|
1633
1834
|
args.max_messages
|
|
1634
1835
|
);
|
|
1836
|
+
const messages = args.include_auto ? read : read.filter(
|
|
1837
|
+
(message) => message.direction === "out" || message.isAuto !== true
|
|
1838
|
+
);
|
|
1635
1839
|
const paired = pair(messages);
|
|
1636
1840
|
const hours = paired.pairs.map((each) => (each.at - each.sentAt) / HOUR_MS);
|
|
1637
1841
|
const within = (limit2) => rate(hours.filter((value) => value <= limit2).length, hours.length);
|
|
1638
1842
|
const received = messages.filter((message) => message.direction === "in");
|
|
1639
1843
|
const untimed = received.length - paired.replyTimes.length;
|
|
1640
1844
|
const unpaired = paired.unpaired + untimed;
|
|
1641
|
-
noteGaps(context, unpaired, received.
|
|
1845
|
+
noteGaps(context, unpaired, received, args.include_auto);
|
|
1642
1846
|
const timing = {
|
|
1643
1847
|
campaign: args.campaign === null ? null : refOf(context.outbound, args.campaign),
|
|
1644
1848
|
counts: {
|
|
1849
|
+
autoReplies: read.length - messages.length,
|
|
1645
1850
|
followOnReplies: paired.followOn,
|
|
1646
|
-
messagesRead:
|
|
1851
|
+
messagesRead: read.length,
|
|
1647
1852
|
paired: paired.pairs.length,
|
|
1648
1853
|
received: received.length,
|
|
1649
1854
|
sent: messages.length - received.length,
|
|
@@ -1673,11 +1878,14 @@ var replyTiming = defineInsight({
|
|
|
1673
1878
|
|
|
1674
1879
|
// src/insights/copy/step-funnel.ts
|
|
1675
1880
|
import { z as z7 } from "zod";
|
|
1881
|
+
var MIN_REPLIES = 5;
|
|
1676
1882
|
var input5 = z7.object({
|
|
1677
|
-
campaign: z7.string().min(1).describe(
|
|
1883
|
+
campaign: z7.string().min(1).describe(
|
|
1884
|
+
"The campaign's ref, for example `instantly:acme:abc123`, or its name"
|
|
1885
|
+
),
|
|
1678
1886
|
...rangeFields,
|
|
1679
1887
|
min_reply_rate: z7.number().min(0).max(1).default(0).describe(
|
|
1680
|
-
|
|
1888
|
+
`A step earns its place when the low end of its reply rate interval is above this and it has at least ${MIN_REPLIES} replies. 0 asks only that the rate is reliably above zero.`
|
|
1681
1889
|
)
|
|
1682
1890
|
});
|
|
1683
1891
|
var variantsOf = (stats, step) => [...stats?.variants ?? []].map(([variantKey, counts]) => {
|
|
@@ -1690,24 +1898,33 @@ var variantsOf = (stats, step) => [...stats?.variants ?? []].map(([variantKey, c
|
|
|
1690
1898
|
variantKey
|
|
1691
1899
|
};
|
|
1692
1900
|
});
|
|
1901
|
+
var earnsPlaceOf = (low, counts, minReplyRate) => {
|
|
1902
|
+
if (low === null) {
|
|
1903
|
+
return null;
|
|
1904
|
+
}
|
|
1905
|
+
if (low <= minReplyRate) {
|
|
1906
|
+
return false;
|
|
1907
|
+
}
|
|
1908
|
+
return (counts?.replied ?? 0) >= MIN_REPLIES ? true : null;
|
|
1909
|
+
};
|
|
1693
1910
|
var draftOf = (index, step, stats, minReplyRate) => {
|
|
1694
1911
|
const counts = stats?.total ?? null;
|
|
1695
1912
|
const measured2 = counts === null ? null : measure(counts.replied, perLead(counts));
|
|
1696
1913
|
return {
|
|
1697
1914
|
action: step?.action ?? null,
|
|
1698
1915
|
delayDays: step?.delayDays ?? null,
|
|
1699
|
-
earnsPlace: measured2
|
|
1916
|
+
earnsPlace: earnsPlaceOf(measured2?.low ?? null, counts, minReplyRate),
|
|
1700
1917
|
inSequence: step !== void 0,
|
|
1701
1918
|
parent: step === void 0 ? null : step.parentIndex,
|
|
1702
1919
|
rates: { replyRate: replyRateOf(measured2) },
|
|
1703
1920
|
replies: counts?.replied ?? null,
|
|
1704
1921
|
sent: counts?.sent ?? null,
|
|
1705
|
-
|
|
1922
|
+
...stepAt(index),
|
|
1706
1923
|
variants: variantsOf(stats, step)
|
|
1707
1924
|
};
|
|
1708
1925
|
};
|
|
1709
1926
|
var finish = (drafts, allReplies) => drafts.map(({ parent, ...draft }, position) => {
|
|
1710
|
-
const before = draft.inSequence ? drafts.find((other) => other.
|
|
1927
|
+
const before = draft.inSequence ? drafts.find((other) => other.stepIndex === parent) : drafts[position - 1];
|
|
1711
1928
|
const drop = before === void 0 || before.sent === null || draft.sent === null ? null : before.sent - draft.sent;
|
|
1712
1929
|
return {
|
|
1713
1930
|
...draft,
|
|
@@ -1725,6 +1942,7 @@ var topOf2 = (steps) => {
|
|
|
1725
1942
|
}
|
|
1726
1943
|
return top;
|
|
1727
1944
|
};
|
|
1945
|
+
var sentence = (text) => `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
1728
1946
|
var describe = (steps, top, last, allReplies) => {
|
|
1729
1947
|
if (steps.every((step) => step.sent === null)) {
|
|
1730
1948
|
return "No step has stats yet, so there is nothing to compare.";
|
|
@@ -1732,21 +1950,25 @@ var describe = (steps, top, last, allReplies) => {
|
|
|
1732
1950
|
if (top === null) {
|
|
1733
1951
|
return "No step has a reply in this range.";
|
|
1734
1952
|
}
|
|
1735
|
-
const
|
|
1953
|
+
const length = steps.filter((step) => step.inSequence).length || null;
|
|
1954
|
+
const lead = `${sentence(stepLabel(top.stepIndex, length))} brings the most replies: ${top.replies} of ${allReplies}.`;
|
|
1736
1955
|
if (last === null) {
|
|
1737
|
-
|
|
1956
|
+
const tooFew = steps.some(
|
|
1957
|
+
(step) => step.earnsPlace === null && step.rates.replyRate.low !== null
|
|
1958
|
+
);
|
|
1959
|
+
return tooFew ? `${lead} Too few replies to tell whether any step's reply rate is reliably above the bar: a step needs at least ${MIN_REPLIES}.` : `${lead} No step's reply rate is reliably above the bar yet.`;
|
|
1738
1960
|
}
|
|
1739
1961
|
const later = steps.filter(
|
|
1740
|
-
(step) => step.
|
|
1962
|
+
(step) => step.stepIndex > last.stepIndex && step.sent !== null
|
|
1741
1963
|
);
|
|
1742
|
-
return later.length === 0 ? `${lead} Every step up to
|
|
1964
|
+
return later.length === 0 ? `${lead} Every step up to ${stepLabel(last.stepIndex, length)} still earns its place.` : `${lead} ${sentence(stepLabel(last.stepIndex, length))} is the last whose reply rate is reliably above the bar; the ${later.length === 1 ? "1 later step" : `${later.length} later steps`} sent ${total(later.map((step) => step.sent))} messages for ${total(later.map((step) => step.replies)) ?? "an unknown number of"} replies.`;
|
|
1743
1965
|
};
|
|
1744
1966
|
var unattributedOf = (rows) => {
|
|
1745
1967
|
const counts = sumRows(rows);
|
|
1746
1968
|
return { replies: counts.replied, rows: rows.length, sent: counts.sent };
|
|
1747
1969
|
};
|
|
1748
1970
|
var stepFunnel = defineInsight({
|
|
1749
|
-
description: "Where a campaign's replies come from: one row per sequence step with its action, delay, sends, replies, reply rate with a 95% interval, its share of all replies and how far sends fell from the step before, plus rows per variant when the vendor splits them. Names the step with the most replies and the last step that still earns its place. Use it to decide whether to cut or rewrite follow-ups. Costs 2 requests. A null count means the vendor does not report it; it is never 0.",
|
|
1971
|
+
description: "Where a campaign's replies come from: one row per sequence step with its action, delay, sends, replies, reply rate with a 95% interval, its share of all replies and how far sends fell from the step before, plus rows per variant when the vendor splits them. Each step has stepIndex (counted from 0) and stepNumber (counted from 1, as a person counts); step is a deprecated copy of stepIndex. Names the step with the most replies and the last step that still earns its place; a step needs at least 5 replies to earn it. Use it to decide whether to cut or rewrite follow-ups. Costs 2 requests. A null count means the vendor does not report it; it is never 0.",
|
|
1750
1972
|
inputSchema: input5,
|
|
1751
1973
|
key: "stepFunnel",
|
|
1752
1974
|
cost: (_input, price) => price.one("sequence.get") + price.one("stats"),
|
|
@@ -1790,9 +2012,13 @@ var stepFunnel = defineInsight({
|
|
|
1790
2012
|
const funnel = {
|
|
1791
2013
|
campaign: refOf(context.outbound, campaign),
|
|
1792
2014
|
finding: describe(steps, top, last, allReplies),
|
|
1793
|
-
lastStepEarningPlace: last?.
|
|
2015
|
+
lastStepEarningPlace: last?.stepIndex ?? null,
|
|
2016
|
+
lastStepEarningPlaceIndex: last?.stepIndex ?? null,
|
|
2017
|
+
lastStepEarningPlaceNumber: last?.stepNumber ?? null,
|
|
1794
2018
|
steps,
|
|
1795
|
-
topStep: top?.
|
|
2019
|
+
topStep: top?.stepIndex ?? null,
|
|
2020
|
+
topStepIndex: top?.stepIndex ?? null,
|
|
2021
|
+
topStepNumber: top?.stepNumber ?? null,
|
|
1796
2022
|
totals: {
|
|
1797
2023
|
replies: allReplies,
|
|
1798
2024
|
sent: total([...drafts.map((draft) => draft.sent), unattributed.sent])
|
|
@@ -1810,7 +2036,9 @@ var input6 = z8.object({
|
|
|
1810
2036
|
alpha: z8.number().gt(0).max(0.5).default(0.05).describe(
|
|
1811
2037
|
"The chance of calling a winner that is not one. A difference with a p-value under this is a winner."
|
|
1812
2038
|
),
|
|
1813
|
-
campaign: z8.string().min(1).describe(
|
|
2039
|
+
campaign: z8.string().min(1).describe(
|
|
2040
|
+
"The campaign's ref, for example `instantly:acme:abc123`, or its name"
|
|
2041
|
+
),
|
|
1814
2042
|
...rangeFields,
|
|
1815
2043
|
metric: z8.enum(METRICS).default("replied").describe(
|
|
1816
2044
|
"What a variant is judged on. Replies and positive replies are divided by leads contacted (or sends); opens and clicks by messages delivered (or sends)."
|
|
@@ -1861,7 +2089,7 @@ var tooLittle = (step, candidates, settings, comparable) => ({
|
|
|
1861
2089
|
moreSendsNeeded: comparable ? shortfall(candidates, settings.minSent) : null,
|
|
1862
2090
|
pValue: null,
|
|
1863
2091
|
reason: reasonFor(candidates, settings, comparable),
|
|
1864
|
-
step,
|
|
2092
|
+
...stepAt(step),
|
|
1865
2093
|
variants: candidates.map((each) => ({ ...each, pValueVsLeader: null })),
|
|
1866
2094
|
verdict: "too_little_data"
|
|
1867
2095
|
});
|
|
@@ -1900,7 +2128,7 @@ var testStep = (step, candidates, settings, comparable) => {
|
|
|
1900
2128
|
moreSendsNeeded: null,
|
|
1901
2129
|
pValue: closest?.pValue ?? null,
|
|
1902
2130
|
reason: `Variant ${leader.variantKey} (${percent(leader.rate)}) beats every other variant by more than chance at alpha ${settings.alpha}.${aside}`,
|
|
1903
|
-
step,
|
|
2131
|
+
...stepAt(step),
|
|
1904
2132
|
variants,
|
|
1905
2133
|
verdict: "winner"
|
|
1906
2134
|
};
|
|
@@ -1914,7 +2142,7 @@ var testStep = (step, candidates, settings, comparable) => {
|
|
|
1914
2142
|
),
|
|
1915
2143
|
pValue: closest?.pValue ?? null,
|
|
1916
2144
|
reason: `Variant ${leader.variantKey} (${percent(leader.rate)}) leads variant ${rival.variantKey} (${percent(rival.rate)}), but a gap this size could be chance.${aside}`,
|
|
1917
|
-
step,
|
|
2145
|
+
...stepAt(step),
|
|
1918
2146
|
variants,
|
|
1919
2147
|
verdict: "no_difference_yet"
|
|
1920
2148
|
};
|
|
@@ -1969,7 +2197,7 @@ var variantTest = defineInsight({
|
|
|
1969
2197
|
const steps = [...split.steps].flatMap(
|
|
1970
2198
|
([step, stats]) => stats.variants.size < 2 ? [] : [stepTest(step, stats.variants, settings)]
|
|
1971
2199
|
).toSorted(
|
|
1972
|
-
(left, right) => ORDER2[left.verdict] - ORDER2[right.verdict] || left.
|
|
2200
|
+
(left, right) => ORDER2[left.verdict] - ORDER2[right.verdict] || left.stepIndex - right.stepIndex
|
|
1973
2201
|
);
|
|
1974
2202
|
const reported = variantsReported(context, rows);
|
|
1975
2203
|
const result = {
|
|
@@ -2100,7 +2328,7 @@ var descending = (left, right) => {
|
|
|
2100
2328
|
}
|
|
2101
2329
|
return right - left;
|
|
2102
2330
|
};
|
|
2103
|
-
var readTotals = async (context, campaign, range) =>
|
|
2331
|
+
var readTotals = async (context, campaign, range) => sumMeasured(
|
|
2104
2332
|
context.rows(
|
|
2105
2333
|
await context.outbound.campaign(campaign).stats({ from: range.from ?? void 0, to: range.to ?? void 0 })
|
|
2106
2334
|
)
|
|
@@ -2124,16 +2352,16 @@ var readAllTotals = async (context, range) => {
|
|
|
2124
2352
|
]);
|
|
2125
2353
|
}
|
|
2126
2354
|
return new Map(
|
|
2127
|
-
[...byCampaign].map(([ref, counts]) => [ref,
|
|
2355
|
+
[...byCampaign].map(([ref, counts]) => [ref, sumMeasured(counts)])
|
|
2128
2356
|
);
|
|
2129
2357
|
};
|
|
2130
2358
|
var readCampaignTotals = async (context, input28) => {
|
|
2131
|
-
const
|
|
2359
|
+
const listed2 = await readCampaignsIn(
|
|
2132
2360
|
context,
|
|
2133
2361
|
input28.statuses,
|
|
2134
2362
|
input28.max_campaigns
|
|
2135
2363
|
);
|
|
2136
|
-
const campaigns =
|
|
2364
|
+
const campaigns = listed2.items;
|
|
2137
2365
|
const reported = campaigns.length > 1 ? await readAllTotals(context, input28) : void 0;
|
|
2138
2366
|
const entries = await mapConcurrent(
|
|
2139
2367
|
campaigns,
|
|
@@ -2142,7 +2370,7 @@ var readCampaignTotals = async (context, input28) => {
|
|
|
2142
2370
|
counts: reported?.get(campaign.ref) ?? await readTotals(context, campaign.ref, input28)
|
|
2143
2371
|
})
|
|
2144
2372
|
);
|
|
2145
|
-
return { entries, read: campaignsReadOf(
|
|
2373
|
+
return { entries, read: campaignsReadOf(listed2) };
|
|
2146
2374
|
};
|
|
2147
2375
|
var readDaily = async (context, campaign, range) => {
|
|
2148
2376
|
const options = { by: "day", from: range.from, to: range.to };
|
|
@@ -2155,7 +2383,7 @@ var readDaily = async (context, campaign, range) => {
|
|
|
2155
2383
|
days.set(row.date, [...days.get(row.date) ?? [], row]);
|
|
2156
2384
|
}
|
|
2157
2385
|
}
|
|
2158
|
-
return [...days].map(([date, group]) => ({ counts:
|
|
2386
|
+
return [...days].map(([date, group]) => ({ counts: sumMeasured(group), date })).toSorted((left, right) => left.date.localeCompare(right.date));
|
|
2159
2387
|
};
|
|
2160
2388
|
|
|
2161
2389
|
// src/insights/ops/anomalies.ts
|
|
@@ -2358,11 +2586,48 @@ var positives = (facts, limits) => {
|
|
|
2358
2586
|
}
|
|
2359
2587
|
];
|
|
2360
2588
|
};
|
|
2361
|
-
var
|
|
2362
|
-
|
|
2589
|
+
var RUNNING_OUT_DAYS = 1;
|
|
2590
|
+
var dropOf = (recent) => recent.sent === null || recent.before === null || recent.before <= 0 ? null : round(1 - recent.sent / recent.before);
|
|
2591
|
+
var sendsFellOrStopped = (campaign, recent, limits) => {
|
|
2363
2592
|
if (recent === null) {
|
|
2593
|
+
return false;
|
|
2594
|
+
}
|
|
2595
|
+
if (recent.sent === null || recent.sent === 0) {
|
|
2596
|
+
return campaign.status === "active";
|
|
2597
|
+
}
|
|
2598
|
+
const drop = dropOf(recent);
|
|
2599
|
+
return drop !== null && drop > limits.maxSendDrop;
|
|
2600
|
+
};
|
|
2601
|
+
var runningOut = (leads) => leads !== null && leads.daysLeft !== null && leads.daysLeft < RUNNING_OUT_DAYS;
|
|
2602
|
+
var outOfLeads = (recent, leads) => {
|
|
2603
|
+
const left = leads.toStart === 0 ? "no lead is left to start" : `only ${plural(leads.toStart, "lead")} ${noun(leads.toStart, "is", "are")} left to start, under a day at the recent pace of ${spoken(recent.startedPerDay)} new ${noun(recent.startedPerDay ?? 0, "lead", "leads")} a day`;
|
|
2604
|
+
const fell = recent.sent === null || recent.sent === 0 ? `The vendor reports no sends in the last ${recent.days} days` : `Sends fell from ${recent.before} to ${recent.sent} over the last ${recent.days} days against the ${recent.days} before`;
|
|
2605
|
+
const finishing = leads.inSequence === null || leads.inSequence === 0 ? "" : ` ${plural(leads.inSequence, "lead")} ${noun(leads.inSequence, "is", "are")} still finishing the sequence.`;
|
|
2606
|
+
return {
|
|
2607
|
+
code: "out_of_leads",
|
|
2608
|
+
finding: `${fell} because the campaign is running out of leads: ${left}.${finishing} This is lead runout, not a sending fault.`,
|
|
2609
|
+
next: "Add leads to keep the campaign sending; pipeline_forecast shows what the leads left should produce.",
|
|
2610
|
+
numbers: {
|
|
2611
|
+
activeLeads: leads.active,
|
|
2612
|
+
before: recent.before,
|
|
2613
|
+
daysLeft: leads.daysLeft,
|
|
2614
|
+
drop: dropOf(recent),
|
|
2615
|
+
inSequence: leads.inSequence,
|
|
2616
|
+
leadsToStart: leads.toStart,
|
|
2617
|
+
newLeadsPerDay: recent.startedPerDay,
|
|
2618
|
+
sent: recent.sent
|
|
2619
|
+
},
|
|
2620
|
+
severity: "high"
|
|
2621
|
+
};
|
|
2622
|
+
};
|
|
2623
|
+
var recentSends = (facts, limits) => {
|
|
2624
|
+
const { leads, recent } = facts;
|
|
2625
|
+
if (recent === null || !sendsFellOrStopped(facts.campaign, recent, limits)) {
|
|
2364
2626
|
return [];
|
|
2365
2627
|
}
|
|
2628
|
+
if (runningOut(leads)) {
|
|
2629
|
+
return [outOfLeads(recent, leads)];
|
|
2630
|
+
}
|
|
2366
2631
|
if (recent.sent === null || recent.sent === 0) {
|
|
2367
2632
|
return facts.campaign.status === "active" ? [
|
|
2368
2633
|
{
|
|
@@ -2374,8 +2639,8 @@ var recentSends = (facts, limits) => {
|
|
|
2374
2639
|
}
|
|
2375
2640
|
] : [];
|
|
2376
2641
|
}
|
|
2377
|
-
const drop =
|
|
2378
|
-
return
|
|
2642
|
+
const drop = dropOf(recent);
|
|
2643
|
+
return [
|
|
2379
2644
|
{
|
|
2380
2645
|
code: "falling_sends",
|
|
2381
2646
|
finding: `Sends fell from ${recent.before} to ${recent.sent} over the last ${recent.days} days against the ${recent.days} before, a drop of ${percent(drop)}.`,
|
|
@@ -2394,30 +2659,72 @@ var sequence = ({ steps }) => steps === null || steps < 1 || steps > 2 ? [] : [
|
|
|
2394
2659
|
severity: "medium"
|
|
2395
2660
|
}
|
|
2396
2661
|
];
|
|
2662
|
+
var senderProblems = (sender) => [
|
|
2663
|
+
...sender.status === "active" ? [] : [sender.status],
|
|
2664
|
+
...warmupAtZero(sender) ? ["warmup score 0"] : []
|
|
2665
|
+
];
|
|
2397
2666
|
var senders = (facts) => {
|
|
2398
2667
|
const all = facts.senders ?? [];
|
|
2399
|
-
const
|
|
2400
|
-
|
|
2668
|
+
const flagged = all.flatMap((sender) => {
|
|
2669
|
+
const problems = senderProblems(sender);
|
|
2670
|
+
return problems.length === 0 ? [] : [{ problems, sender }];
|
|
2671
|
+
});
|
|
2672
|
+
const inactive = flagged.filter(({ sender }) => sender.status !== "active");
|
|
2673
|
+
const warmupZero = all.filter(warmupAtZero).length;
|
|
2674
|
+
const what = warmupZero === 0 ? "not active" : "not fit to send";
|
|
2675
|
+
return flagged.length === 0 ? [] : [
|
|
2401
2676
|
{
|
|
2402
2677
|
code: "inactive_sender",
|
|
2403
|
-
finding: `${
|
|
2404
|
-
(sender) => `${sender.address ?? sender.name ?? sender.ref} (${
|
|
2678
|
+
finding: `${flagged.length} of ${plural(all.length, "sender")} ${noun(flagged.length, "is", "are")} ${what}: ${flagged.map(
|
|
2679
|
+
({ problems, sender }) => `${sender.address ?? sender.name ?? sender.ref} (${problems.join(", ")})`
|
|
2405
2680
|
).join(", ")}.`,
|
|
2406
2681
|
next: "Reconnect or replace them; warmup_readiness shows which mailboxes are fit to send.",
|
|
2407
|
-
numbers: {
|
|
2682
|
+
numbers: {
|
|
2683
|
+
inactive: inactive.length,
|
|
2684
|
+
senders: all.length,
|
|
2685
|
+
warmupZero
|
|
2686
|
+
},
|
|
2408
2687
|
severity: "high"
|
|
2409
2688
|
}
|
|
2410
2689
|
];
|
|
2411
2690
|
};
|
|
2412
|
-
var
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2691
|
+
var TRACKING_OFF = {
|
|
2692
|
+
both: [
|
|
2693
|
+
"Open and click tracking are off, so missing open and click counts are expected and not a fault.",
|
|
2694
|
+
"Judge this campaign on replies, not opens or clicks."
|
|
2695
|
+
],
|
|
2696
|
+
clicks: [
|
|
2697
|
+
"Click tracking is off, so no link click is counted; that is expected and not a fault.",
|
|
2698
|
+
"Judge this campaign on replies, not clicks."
|
|
2699
|
+
],
|
|
2700
|
+
opens: [
|
|
2701
|
+
"Open tracking is off, so the missing open count is expected and not a fault.",
|
|
2702
|
+
"Judge this campaign on replies, not opens."
|
|
2703
|
+
]
|
|
2704
|
+
};
|
|
2705
|
+
var offWhich = (opens, clicks) => {
|
|
2706
|
+
if (opens && clicks) {
|
|
2707
|
+
return "both";
|
|
2708
|
+
}
|
|
2709
|
+
return opens ? "opens" : "clicks";
|
|
2710
|
+
};
|
|
2711
|
+
var tracking = ({ opened, settings }) => {
|
|
2712
|
+
const opens = settings?.tracking.opens === false && (opened ?? 0) === 0;
|
|
2713
|
+
const clicks = settings?.tracking.clicks === false;
|
|
2714
|
+
if (!opens && !clicks) {
|
|
2715
|
+
return [];
|
|
2419
2716
|
}
|
|
2420
|
-
]
|
|
2717
|
+
const [finding, next] = TRACKING_OFF[offWhich(opens, clicks)];
|
|
2718
|
+
return [
|
|
2719
|
+
{
|
|
2720
|
+
code: "tracking_off",
|
|
2721
|
+
finding,
|
|
2722
|
+
next,
|
|
2723
|
+
numbers: { opened },
|
|
2724
|
+
severity: "low"
|
|
2725
|
+
}
|
|
2726
|
+
];
|
|
2727
|
+
};
|
|
2421
2728
|
var minutesOf = (clock) => {
|
|
2422
2729
|
const [hours, minutes] = (clock ?? "").split(":").map(Number);
|
|
2423
2730
|
return hours === void 0 || minutes === void 0 ? null : hours * 60 + minutes;
|
|
@@ -2462,7 +2769,20 @@ var schedule = ({ recent, settings }, limits) => {
|
|
|
2462
2769
|
}
|
|
2463
2770
|
];
|
|
2464
2771
|
};
|
|
2772
|
+
var contactedLeads = ({
|
|
2773
|
+
campaignLeads: leads,
|
|
2774
|
+
totals: { contacted }
|
|
2775
|
+
}) => contacted !== null && leads !== null && contactedBeyondLeads(contacted, leads) ? [
|
|
2776
|
+
{
|
|
2777
|
+
code: "contacted_exceeds_leads",
|
|
2778
|
+
finding: `The vendor reports ${contacted} leads contacted against ${plural(leads, "lead")} in the campaign, more than ${CONTACTED_LEADS_LIMIT} times as many. Leads contacted cannot be that far over the leads, so that count is not unique leads and the per-lead rates are not to be trusted.`,
|
|
2779
|
+
next: "Report it as an adapter fault, and judge the campaign on sends until it is fixed.",
|
|
2780
|
+
numbers: { contacted, leads, limit: CONTACTED_LEADS_LIMIT },
|
|
2781
|
+
severity: "high"
|
|
2782
|
+
}
|
|
2783
|
+
] : [];
|
|
2465
2784
|
var CHECKS2 = [
|
|
2785
|
+
contactedLeads,
|
|
2466
2786
|
bounces,
|
|
2467
2787
|
recentSends,
|
|
2468
2788
|
senders,
|
|
@@ -2487,7 +2807,7 @@ var unknownRates = (facts) => [
|
|
|
2487
2807
|
var share = (fallback, text) => z11.number().min(0).max(1).default(fallback).describe(text);
|
|
2488
2808
|
var input8 = z11.object({
|
|
2489
2809
|
...rangeFields,
|
|
2490
|
-
campaign: z11.string().min(3).describe("The campaign's ref"),
|
|
2810
|
+
campaign: z11.string().min(3).describe("The campaign's ref or name"),
|
|
2491
2811
|
days: z11.number().int().min(1).max(30).default(7).describe(
|
|
2492
2812
|
"The days, ending yesterday, held against the same number before"
|
|
2493
2813
|
),
|
|
@@ -2500,7 +2820,12 @@ var input8 = z11.object({
|
|
|
2500
2820
|
0.3,
|
|
2501
2821
|
"A fall in sends, recent days against the days before, over this share is a finding"
|
|
2502
2822
|
),
|
|
2503
|
-
|
|
2823
|
+
max_leads: z11.number().int().min(1).max(5e4).default(2e3).describe(
|
|
2824
|
+
"The most leads to read when sends fell or stopped, to tell lead runout from a fault. A page of leads is one request."
|
|
2825
|
+
),
|
|
2826
|
+
max_senders: z11.number().int().min(1).max(SCREENED_AT_MOST).default(SCREENED_AT_MOST).describe(
|
|
2827
|
+
"The most of the campaign's own senders to read and screen for a status that is not active or a warmup score of 0"
|
|
2828
|
+
),
|
|
2504
2829
|
min_positive_share: share(
|
|
2505
2830
|
0.2,
|
|
2506
2831
|
"A share of replies that are positive under this is a finding"
|
|
@@ -2520,11 +2845,42 @@ var readRecent = async (context, campaign, days) => {
|
|
|
2520
2845
|
(day) => day.date >= from && day.date <= to ? [day.counts.sent] : []
|
|
2521
2846
|
);
|
|
2522
2847
|
const sends = sentIn(recent.from, recent.to);
|
|
2848
|
+
const started = newLeadsPerDay(
|
|
2849
|
+
series.flatMap(
|
|
2850
|
+
(day) => day.date >= recent.from && day.date <= recent.to ? [day.counts] : []
|
|
2851
|
+
),
|
|
2852
|
+
days
|
|
2853
|
+
);
|
|
2523
2854
|
return {
|
|
2524
2855
|
before: total(sentIn(before.from, before.to)),
|
|
2525
2856
|
days,
|
|
2526
2857
|
daysWithData: sends.filter((value) => value !== null).length,
|
|
2527
|
-
sent: total(sends)
|
|
2858
|
+
sent: total(sends),
|
|
2859
|
+
startedPerDay: started
|
|
2860
|
+
};
|
|
2861
|
+
};
|
|
2862
|
+
var readLeadsLeft = async (context, campaign, recent, maxLeads) => {
|
|
2863
|
+
if (!context.outbound.capabilities["leads.byCampaign"]) {
|
|
2864
|
+
context.note(
|
|
2865
|
+
"Lead runout: the adapter cannot list a campaign's leads, so a fall in sends was not checked against the leads left."
|
|
2866
|
+
);
|
|
2867
|
+
return null;
|
|
2868
|
+
}
|
|
2869
|
+
const { capped: capped2, items: leads } = await readCapped(
|
|
2870
|
+
context,
|
|
2871
|
+
(max) => context.outbound.campaign(campaign).leads.listAll({ max }),
|
|
2872
|
+
{ input: "max_leads", max: maxLeads, what: "leads" }
|
|
2873
|
+
);
|
|
2874
|
+
if (capped2 || leads.length === 0) {
|
|
2875
|
+
return null;
|
|
2876
|
+
}
|
|
2877
|
+
const split = splitActive(leads);
|
|
2878
|
+
const unknown = leads.filter((lead) => lead.status === "unknown").length;
|
|
2879
|
+
return {
|
|
2880
|
+
active: split.active,
|
|
2881
|
+
daysLeft: runwayDays(split, { unknown }, true, recent.startedPerDay),
|
|
2882
|
+
inSequence: split.inSequence,
|
|
2883
|
+
toStart: leadsToStart(split)
|
|
2528
2884
|
};
|
|
2529
2885
|
};
|
|
2530
2886
|
var readExtras = async (context, campaign, options) => {
|
|
@@ -2554,11 +2910,16 @@ var readExtras = async (context, campaign, options) => {
|
|
|
2554
2910
|
max: options.maxSenders,
|
|
2555
2911
|
what: "senders"
|
|
2556
2912
|
}) : null;
|
|
2913
|
+
const campaignLeads = unless(
|
|
2914
|
+
!capabilities["campaigns.progress"],
|
|
2915
|
+
"Leads contacted against the campaign's leads: the adapter does not serve campaign progress."
|
|
2916
|
+
) ? context.one(await handle.progress()).leads : null;
|
|
2557
2917
|
const recent = unless(
|
|
2558
2918
|
capabilities["stats.byDay"] === false,
|
|
2559
2919
|
"Recent sending trend: the adapter has no stats by day."
|
|
2560
2920
|
) ? await readRecent(context, campaign, options.recentDays) : null;
|
|
2561
2921
|
return {
|
|
2922
|
+
campaignLeads,
|
|
2562
2923
|
notChecked,
|
|
2563
2924
|
recent,
|
|
2564
2925
|
senders: senders2?.items ?? null,
|
|
@@ -2566,17 +2927,19 @@ var readExtras = async (context, campaign, options) => {
|
|
|
2566
2927
|
steps
|
|
2567
2928
|
};
|
|
2568
2929
|
};
|
|
2930
|
+
var leadsIfSendsFell = async (context, campaign, recent, options) => recent !== null && sendsFellOrStopped(campaign, recent, { maxSendDrop: options.maxSendDrop }) ? await readLeadsLeft(context, campaign.ref, recent, options.maxLeads) : null;
|
|
2569
2931
|
var summarize = (findings) => {
|
|
2570
2932
|
const [first] = findings;
|
|
2571
2933
|
return first === void 0 ? "No problem was found in what could be checked." : `${findings.length} ${findings.length === 1 ? "finding" : "findings"}. Most serious: ${first.finding}`;
|
|
2572
2934
|
};
|
|
2573
2935
|
var campaignDiagnosis = defineInsight({
|
|
2574
|
-
description: "Why one campaign is underperforming: a list of findings, most serious first, each with a code, a plain-language finding, the numbers behind it and what to look at next. It checks for too little volume to judge, a low reply rate (with its 95% interval), a high bounce rate, few positive replies among replies, sends falling or stopped over the last days, a one or two step sequence,
|
|
2936
|
+
description: "Why one campaign is underperforming: a list of findings, most serious first, each with a code, a plain-language finding, the numbers behind it and what to look at next. It checks for too little volume to judge, a low reply rate (with its 95% interval), a high bounce rate, few positive replies among replies, sends falling or stopped over the last days, told apart from the campaign running out of leads (under a day of new leads left to start at the recent pace, the pace lead_runway uses), a one or two step sequence, any of the campaign's own senders (up to 500) that is not active or has a warmup score of 0, open or click tracking being off, a schedule or daily limit that holds volume back, and a count of leads contacted more than twice the campaign's leads, which means the count is wrong. Also returns what could not be checked; an empty list means nothing was found, not that all is well. Costs up to 7 requests, plus one per page of the campaign's senders and, only when sends fell or stopped, one per page of its leads.",
|
|
2575
2937
|
inputSchema: input8,
|
|
2576
2938
|
key: "campaignDiagnosis",
|
|
2577
2939
|
cost: (values, price) => {
|
|
2578
2940
|
const { capabilities } = price;
|
|
2579
|
-
return price.one("campaigns.get") + price.one("stats") + (capabilities["campaigns.settings"] === false ? 0 : price.one("campaigns.settings")) + (capabilities.sequence === false ? 0 : price.one("sequence.get")) + (capabilities["senders.byCampaign"] === false ? 0 : price.list("senders.list", values.max_senders)) + (capabilities["stats.byDay"] === false ? 0 : price.one("stats"))
|
|
2941
|
+
return price.one("campaigns.get") + price.one("stats") + (capabilities["campaigns.settings"] === false ? 0 : price.one("campaigns.settings")) + (capabilities["campaigns.progress"] === false ? 0 : price.one("campaigns.progress")) + (capabilities.sequence === false ? 0 : price.one("sequence.get")) + (capabilities["senders.byCampaign"] === false ? 0 : price.list("senders.list", values.max_senders)) + (capabilities["stats.byDay"] === false ? 0 : price.one("stats")) + // The leads are read only when sends fell or stopped, which the data decides.
|
|
2942
|
+
(capabilities["stats.byDay"] === false || capabilities["leads.byCampaign"] === false ? 0 : price.upTo(1) * price.list("leads.list", values.max_leads));
|
|
2580
2943
|
},
|
|
2581
2944
|
scales: "max_senders",
|
|
2582
2945
|
name: "campaign_diagnosis",
|
|
@@ -2591,9 +2954,14 @@ var campaignDiagnosis = defineInsight({
|
|
|
2591
2954
|
maxSenders: options.max_senders,
|
|
2592
2955
|
recentDays: options.days
|
|
2593
2956
|
});
|
|
2957
|
+
const leads = await leadsIfSendsFell(context, campaign, extras.recent, {
|
|
2958
|
+
maxLeads: options.max_leads,
|
|
2959
|
+
maxSendDrop: options.max_send_drop
|
|
2960
|
+
});
|
|
2594
2961
|
const facts = {
|
|
2595
2962
|
...extras,
|
|
2596
2963
|
campaign,
|
|
2964
|
+
leads,
|
|
2597
2965
|
opened: counts.opened,
|
|
2598
2966
|
rates: ratesOf(counts),
|
|
2599
2967
|
totals: totalsOf(counts)
|
|
@@ -2728,7 +3096,7 @@ var groupOf = (channel, entries) => {
|
|
|
2728
3096
|
);
|
|
2729
3097
|
return {
|
|
2730
3098
|
group: {
|
|
2731
|
-
...totalsOf(
|
|
3099
|
+
...totalsOf(sumMeasured(counts)),
|
|
2732
3100
|
acceptance: channel === "linkedin" ? acceptance.measured : null,
|
|
2733
3101
|
campaigns: entries.length,
|
|
2734
3102
|
channel,
|
|
@@ -2903,7 +3271,7 @@ var comparePeriods = (current, previous, alpha) => {
|
|
|
2903
3271
|
);
|
|
2904
3272
|
};
|
|
2905
3273
|
var compareAcross = (current, previous, alpha) => {
|
|
2906
|
-
const counts = [
|
|
3274
|
+
const counts = [sumMeasured(current), sumMeasured(previous)];
|
|
2907
3275
|
const basis = periodBasis(...counts);
|
|
2908
3276
|
const now = ratesAcross(current, baseIn2(basis));
|
|
2909
3277
|
const before = ratesAcross(previous, baseIn2(basis));
|
|
@@ -2923,13 +3291,13 @@ var compareAcross = (current, previous, alpha) => {
|
|
|
2923
3291
|
var readPeriods = async (context, options) => {
|
|
2924
3292
|
const current = lastDays(context.now, options.days);
|
|
2925
3293
|
const previous = lastDays(context.now, options.days, 1);
|
|
2926
|
-
const
|
|
3294
|
+
const listed2 = await readCampaignsIn(
|
|
2927
3295
|
context,
|
|
2928
3296
|
options.statuses,
|
|
2929
3297
|
options.max_campaigns
|
|
2930
3298
|
);
|
|
2931
3299
|
const campaigns = await mapConcurrent(
|
|
2932
|
-
|
|
3300
|
+
listed2.items,
|
|
2933
3301
|
async (campaign) => {
|
|
2934
3302
|
const [now, before] = await Promise.all([
|
|
2935
3303
|
readTotals(context, campaign.ref, current),
|
|
@@ -2938,7 +3306,7 @@ var readPeriods = async (context, options) => {
|
|
|
2938
3306
|
return { campaign, current: now, previous: before };
|
|
2939
3307
|
}
|
|
2940
3308
|
);
|
|
2941
|
-
return { campaigns, current, previous, read: campaignsReadOf(
|
|
3309
|
+
return { campaigns, current, previous, read: campaignsReadOf(listed2) };
|
|
2942
3310
|
};
|
|
2943
3311
|
var totalOf = (campaigns, alpha) => compareAcross(
|
|
2944
3312
|
campaigns.map((entry) => entry.current),
|
|
@@ -3022,7 +3390,7 @@ var periodComparison = defineInsight({
|
|
|
3022
3390
|
// src/insights/ops/pipeline-forecast.ts
|
|
3023
3391
|
import { z as z15 } from "zod";
|
|
3024
3392
|
var input12 = z15.object({
|
|
3025
|
-
campaign: z15.string().min(3).describe("The campaign's ref"),
|
|
3393
|
+
campaign: z15.string().min(3).describe("The campaign's ref or name"),
|
|
3026
3394
|
days: z15.number().int().min(1).max(60).default(7).describe("How many complete days, ending yesterday, set the daily pace"),
|
|
3027
3395
|
max_leads: z15.number().int().min(1).max(5e4).default(2e3).describe("The most leads to read. A page of leads is one request.")
|
|
3028
3396
|
});
|
|
@@ -3033,6 +3401,7 @@ var countStatuses = (leads) => {
|
|
|
3033
3401
|
completed: 0,
|
|
3034
3402
|
paused: 0,
|
|
3035
3403
|
replied: 0,
|
|
3404
|
+
skipped: 0,
|
|
3036
3405
|
unknown: 0,
|
|
3037
3406
|
unsubscribed: 0
|
|
3038
3407
|
};
|
|
@@ -3057,26 +3426,21 @@ var paceOf = async (context, campaign, days) => {
|
|
|
3057
3426
|
const series = await readDaily(
|
|
3058
3427
|
context,
|
|
3059
3428
|
campaign,
|
|
3060
|
-
|
|
3429
|
+
paceWindow(context.now, days)
|
|
3430
|
+
);
|
|
3431
|
+
return newLeadsPerDay(
|
|
3432
|
+
series.map((day) => day.counts),
|
|
3433
|
+
days
|
|
3061
3434
|
);
|
|
3062
|
-
const contacted = total(series.map((day) => day.counts.contacted));
|
|
3063
|
-
return contacted === null ? null : round(contacted / days);
|
|
3064
3435
|
};
|
|
3065
3436
|
var ASSUMPTIONS = [
|
|
3066
3437
|
"Every remaining lead is contacted.",
|
|
3067
3438
|
"Remaining leads reply at the rate the campaign has had so far; leads already partway through the sequence may reply less.",
|
|
3068
|
-
"The daily pace stays what it was over the recent days. Days with no report count as
|
|
3439
|
+
"The daily pace of new leads started stays what it was over the recent days. Days with no report count as none started."
|
|
3069
3440
|
];
|
|
3070
|
-
var
|
|
3071
|
-
const remaining = byStatus.active;
|
|
3072
|
-
if (remaining === 0) {
|
|
3073
|
-
return complete && byStatus.unknown === 0 ? 0 : null;
|
|
3074
|
-
}
|
|
3075
|
-
return pace === null || pace <= 0 ? null : round(remaining / pace);
|
|
3076
|
-
};
|
|
3077
|
-
var describe2 = ({ complete, daysLeft, remaining }, forecast) => {
|
|
3441
|
+
var describe2 = ({ complete, daysLeft, inSequence, remaining }, forecast) => {
|
|
3078
3442
|
if (daysLeft === 0) {
|
|
3079
|
-
return "No leads are left to contact; add leads to keep the campaign sending.";
|
|
3443
|
+
return remaining === 0 ? "No leads are left to contact; add leads to keep the campaign sending." : `No new leads are left to start; ${plural(inSequence ?? remaining, "lead")} ${noun(inSequence ?? remaining, "is", "are")} finishing the sequence. Add leads to keep the campaign starting new ones.`;
|
|
3080
3444
|
}
|
|
3081
3445
|
const leads = `${complete ? "" : "At least "}${plural(remaining, "lead")} ${noun(remaining, "remains", "remain")}`;
|
|
3082
3446
|
if (forecast.expected === null) {
|
|
@@ -3107,9 +3471,10 @@ var forecastCampaign = async (context, campaign, options) => {
|
|
|
3107
3471
|
const rates = ratesOf(
|
|
3108
3472
|
await readTotals(context, campaign.ref, { from: null, to: null })
|
|
3109
3473
|
);
|
|
3474
|
+
const split = splitActive(leads);
|
|
3110
3475
|
const pace = await paceOf(context, campaign.ref, options.days);
|
|
3111
3476
|
const expectedReplies = project(remaining, rates.replyRate);
|
|
3112
|
-
const daysLeft =
|
|
3477
|
+
const daysLeft = runwayDays(split, byStatus, complete, pace);
|
|
3113
3478
|
return {
|
|
3114
3479
|
...labelOf(campaign),
|
|
3115
3480
|
assumptions: [
|
|
@@ -3122,16 +3487,21 @@ var forecastCampaign = async (context, campaign, options) => {
|
|
|
3122
3487
|
estimate: true,
|
|
3123
3488
|
expectedPositive: project(remaining, rates.positiveRate),
|
|
3124
3489
|
expectedReplies,
|
|
3125
|
-
finding: describe2(
|
|
3490
|
+
finding: describe2(
|
|
3491
|
+
{ complete, daysLeft, inSequence: split.inSequence, remaining },
|
|
3492
|
+
expectedReplies
|
|
3493
|
+
),
|
|
3494
|
+
inSequence: split.inSequence,
|
|
3126
3495
|
leadsComplete: complete,
|
|
3127
3496
|
leadsRead: leads.length,
|
|
3497
|
+
notStarted: split.notStarted,
|
|
3128
3498
|
positiveRate: rates.positiveRate,
|
|
3129
3499
|
remaining,
|
|
3130
3500
|
replyRate: rates.replyRate
|
|
3131
3501
|
};
|
|
3132
3502
|
};
|
|
3133
3503
|
var pipelineForecast = defineInsight({
|
|
3134
|
-
description: "The leads one campaign has left and what they should produce: leads counted by status, the leads still active, the days
|
|
3504
|
+
description: "The leads one campaign has left and what they should produce: leads counted by status, the leads still active, split into those not yet started and those partway through the sequence, the days until no lead is left to start at the recent pace of new leads started per day (the same figure lead_runway gives), and the replies and positive replies to expect from the remaining leads at the campaign's reply rate so far, each with a low and a high figure from the 95% interval. Use it to decide when to load more leads. It is an estimate and lists what it assumes; a null means the vendor does not report the count behind it. Costs one request per page of leads, plus two stats requests.",
|
|
3135
3505
|
inputSchema: input12,
|
|
3136
3506
|
key: "pipelineForecast",
|
|
3137
3507
|
cost: (values, price) => price.one("campaigns.get") + price.list("leads.list", values.max_leads) + price.one("stats") + (price.capabilities["stats.byDay"] === false ? 0 : price.one("stats")),
|
|
@@ -3360,7 +3730,7 @@ var groupOf2 = (tag, entries) => {
|
|
|
3360
3730
|
const { partial, rates } = ratesAcross(counts);
|
|
3361
3731
|
return {
|
|
3362
3732
|
group: {
|
|
3363
|
-
...totalsOf(
|
|
3733
|
+
...totalsOf(sumMeasured(counts)),
|
|
3364
3734
|
...rates,
|
|
3365
3735
|
campaigns: entries.length,
|
|
3366
3736
|
tag
|
|
@@ -3477,7 +3847,24 @@ var parseDomain = (text, provider) => {
|
|
|
3477
3847
|
}
|
|
3478
3848
|
return host;
|
|
3479
3849
|
};
|
|
3480
|
-
var readLeads = async (context, { max_campaigns: maxCampaigns, max_leads: maxLeads }) => {
|
|
3850
|
+
var readLeads = async (context, domain, { max_campaigns: maxCampaigns, max_leads: maxLeads }) => {
|
|
3851
|
+
const { outbound } = context;
|
|
3852
|
+
if (outbound.capabilities["leads.byDomain"]) {
|
|
3853
|
+
const found = await readCappedFlag(
|
|
3854
|
+
context,
|
|
3855
|
+
(cap) => outbound.leads.listAll({ domain, max: cap }),
|
|
3856
|
+
maxLeads,
|
|
3857
|
+
"leads at the domain",
|
|
3858
|
+
"max_leads"
|
|
3859
|
+
);
|
|
3860
|
+
return { ...found, foundBy: "search" };
|
|
3861
|
+
}
|
|
3862
|
+
return {
|
|
3863
|
+
...await scanLeads(context, maxCampaigns, maxLeads),
|
|
3864
|
+
foundBy: "scan"
|
|
3865
|
+
};
|
|
3866
|
+
};
|
|
3867
|
+
var scanLeads = async (context, maxCampaigns, maxLeads) => {
|
|
3481
3868
|
const { outbound } = context;
|
|
3482
3869
|
if (outbound.capabilities["leads.list"]) {
|
|
3483
3870
|
return await readCappedFlag(
|
|
@@ -3491,7 +3878,7 @@ var readLeads = async (context, { max_campaigns: maxCampaigns, max_leads: maxLea
|
|
|
3491
3878
|
if (!outbound.capabilities["leads.byCampaign"]) {
|
|
3492
3879
|
throw new OutboundError(
|
|
3493
3880
|
"Unsupported",
|
|
3494
|
-
`account_summary is not available: the ${outbound.provider} adapter supports
|
|
3881
|
+
`account_summary is not available: the ${outbound.provider} adapter supports none of leads.byDomain, leads.list and leads.byCampaign`,
|
|
3495
3882
|
{ provider: outbound.provider }
|
|
3496
3883
|
);
|
|
3497
3884
|
}
|
|
@@ -3564,6 +3951,18 @@ var toPerson = (email, leads, labels) => {
|
|
|
3564
3951
|
title: pick((lead) => lead.title)
|
|
3565
3952
|
};
|
|
3566
3953
|
};
|
|
3954
|
+
var findingOf = (domain, people, read) => {
|
|
3955
|
+
const replied = people.filter((person) => person.replied).length;
|
|
3956
|
+
const found = `${plural(people.length, "person", "people")} at ${domain}; ${count(replied)} replied`;
|
|
3957
|
+
if (!read.capped) {
|
|
3958
|
+
if (people.length > 0) {
|
|
3959
|
+
return `${found}.`;
|
|
3960
|
+
}
|
|
3961
|
+
return read.foundBy === "search" ? `No lead at ${domain} was found.` : `Checked all ${plural(read.leadsRead, "lead")}; none is at ${domain}.`;
|
|
3962
|
+
}
|
|
3963
|
+
const checked = read.foundBy === "search" ? `Read ${plural(read.leadsRead, "lead")} at ${domain} (max_leads) and more exist` : `Checked the first ${plural(read.leadsRead, "lead")} and more exist`;
|
|
3964
|
+
return people.length === 0 ? `${checked}; none matched. This does not mean nobody at ${domain} is in a campaign.` : `${found} in the leads read. ${checked}, so others at ${domain} may be missing.`;
|
|
3965
|
+
};
|
|
3567
3966
|
var byLastReply = (left, right) => (right.lastRepliedAt ?? "").localeCompare(left.lastRepliedAt ?? "") || Number(right.replied) - Number(left.replied) || left.email.localeCompare(right.email);
|
|
3568
3967
|
var lastReplyOf = (people) => {
|
|
3569
3968
|
const [person] = people;
|
|
@@ -3578,7 +3977,7 @@ var lastReplyOf = (people) => {
|
|
|
3578
3977
|
};
|
|
3579
3978
|
};
|
|
3580
3979
|
var accountSummary = defineInsight({
|
|
3581
|
-
description: "Everyone at one company across campaigns and tools, from the company's domain or any email address at it: each person with their name, title, campaigns, status, interest label and open, click and reply counts, plus totals and who replied most recently. People are matched by exact email domain, so a lead with only a LinkedIn profile is not found, and an email provider domain such as gmail.com is refused unless allow_free_domains is true. A record the vendor labels out-of-office or bounced is marked autoReplied and its replies do not count as the person replying. Costs one request per page of leads read (max_leads sets the ceiling); totals.moreLeadsExist is true when that ceiling left leads unread. A count the vendor does not report is null.",
|
|
3980
|
+
description: "Everyone at one company across campaigns and tools, from the company's domain or any email address at it: each person with their name, title, campaigns, status, interest label and open, click and reply counts, plus totals and who replied most recently. Where the tool can search leads by domain (leads.byDomain) it finds them wherever they are; otherwise it reads leads in order up to max_leads, and finding says when that left the company possibly unread. People are matched by exact email domain, so a lead with only a LinkedIn profile is not found, and an email provider domain such as gmail.com is refused unless allow_free_domains is true. A record the vendor labels out-of-office or bounced is marked autoReplied and its replies do not count as the person replying. Costs one request per page of leads read (max_leads sets the ceiling); totals.moreLeadsExist is true when that ceiling left leads unread. A count the vendor does not report is null.",
|
|
3582
3981
|
inputSchema: input15,
|
|
3583
3982
|
key: "accountSummary",
|
|
3584
3983
|
// Every address is masked, so no lead's domain can be read. A hash keeps
|
|
@@ -3589,7 +3988,7 @@ var accountSummary = defineInsight({
|
|
|
3589
3988
|
}
|
|
3590
3989
|
return strategy === "hash" ? 'email addresses, whose domain it matches people by (under strategy "hash" too: a hashed address keeps no domain)' : "email addresses, whose domain it matches people by";
|
|
3591
3990
|
},
|
|
3592
|
-
cost: (values, price) => price.capabilities["leads.list"] === false ? price.list("campaigns.list", values.max_campaigns) + price.upTo(values.max_campaigns - 1) * price.list("leads.list", 1) + price.upTo(1) * price.list("leads.list", values.max_leads) : price.list("leads.list", values.max_leads),
|
|
3991
|
+
cost: (values, price) => price.capabilities["leads.list"] === false && !price.capabilities["leads.byDomain"] ? price.list("campaigns.list", values.max_campaigns) + price.upTo(values.max_campaigns - 1) * price.list("leads.list", 1) + price.upTo(1) * price.list("leads.list", values.max_leads) : price.list("leads.list", values.max_leads),
|
|
3593
3992
|
scales: "max_leads",
|
|
3594
3993
|
name: "account_summary",
|
|
3595
3994
|
needs: [],
|
|
@@ -3603,7 +4002,7 @@ var accountSummary = defineInsight({
|
|
|
3603
4002
|
{ provider: context.outbound.provider }
|
|
3604
4003
|
);
|
|
3605
4004
|
}
|
|
3606
|
-
const read = await readLeads(context, values);
|
|
4005
|
+
const read = await readLeads(context, domain, values);
|
|
3607
4006
|
const leads = read.items;
|
|
3608
4007
|
noteEngagement(context, leads, "those are null");
|
|
3609
4008
|
const byEmail = /* @__PURE__ */ new Map();
|
|
@@ -3617,6 +4016,12 @@ var accountSummary = defineInsight({
|
|
|
3617
4016
|
).toSorted(byLastReply);
|
|
3618
4017
|
const summary = {
|
|
3619
4018
|
domain,
|
|
4019
|
+
finding: findingOf(domain, people, {
|
|
4020
|
+
capped: read.capped,
|
|
4021
|
+
foundBy: read.foundBy,
|
|
4022
|
+
leadsRead: leads.length
|
|
4023
|
+
}),
|
|
4024
|
+
foundBy: read.foundBy,
|
|
3620
4025
|
lastReply: lastReplyOf(people),
|
|
3621
4026
|
people,
|
|
3622
4027
|
totals: {
|
|
@@ -3645,7 +4050,7 @@ var input16 = z19.object({
|
|
|
3645
4050
|
"Reply categories that need an answer. Out-of-office, bounce, unsubscribe and negative replies are left out by default."
|
|
3646
4051
|
),
|
|
3647
4052
|
include_auto: z19.boolean().default(false).describe(
|
|
3648
|
-
"Set to true to also check replies the vendor
|
|
4053
|
+
"Set to true to also check replies flagged automatic, by the vendor or by a fixed rule"
|
|
3649
4054
|
),
|
|
3650
4055
|
max_replies: z19.number().int().min(1).max(1e3).default(50).describe(
|
|
3651
4056
|
"The most replies to read. Each conversation among them costs one more request to check."
|
|
@@ -3804,8 +4209,8 @@ var droppedReplies = defineInsight({
|
|
|
3804
4209
|
"This tool can read neither a conversation nor a lead's timeline, so no reply could be checked."
|
|
3805
4210
|
);
|
|
3806
4211
|
}
|
|
3807
|
-
const
|
|
3808
|
-
const read =
|
|
4212
|
+
const listed2 = await readReplies(context, since, values.max_replies);
|
|
4213
|
+
const read = listed2.items;
|
|
3809
4214
|
const replies2 = read.filter(
|
|
3810
4215
|
(reply) => reply.sentAt === null || Date.parse(reply.sentAt) >= Date.parse(since)
|
|
3811
4216
|
);
|
|
@@ -3853,7 +4258,7 @@ var droppedReplies = defineInsight({
|
|
|
3853
4258
|
answered,
|
|
3854
4259
|
conversations: conversations.length,
|
|
3855
4260
|
dropped: dropped.length,
|
|
3856
|
-
moreRepliesExist:
|
|
4261
|
+
moreRepliesExist: listed2.capped,
|
|
3857
4262
|
repliesRead: read.length,
|
|
3858
4263
|
skippedAuto: wanted.length - kept.length,
|
|
3859
4264
|
skippedByCategory: replies2.length - wanted.length,
|
|
@@ -3867,6 +4272,42 @@ var droppedReplies = defineInsight({
|
|
|
3867
4272
|
|
|
3868
4273
|
// src/insights/people/hot-leads.ts
|
|
3869
4274
|
import { z as z20 } from "zod";
|
|
4275
|
+
|
|
4276
|
+
// src/insights/people/auto-replies.ts
|
|
4277
|
+
var AUTO_CHECK_REPLIES = 200;
|
|
4278
|
+
var refsOf2 = (lead) => lead.email === null ? [lead.ref] : [lead.ref, makeRef(lead.provider, lead.workspaceId, lead.email)];
|
|
4279
|
+
var autoOnlyRefs = async (context, campaign, leads) => {
|
|
4280
|
+
const { outbound } = context;
|
|
4281
|
+
const replied = leads.filter(
|
|
4282
|
+
(lead) => (lead.engagement?.replies ?? 0) > 0 || lead.replied === true
|
|
4283
|
+
);
|
|
4284
|
+
if (replied.length === 0 || !outbound.capabilities["replies.list"]) {
|
|
4285
|
+
return /* @__PURE__ */ new Set();
|
|
4286
|
+
}
|
|
4287
|
+
const replies2 = await context.all(
|
|
4288
|
+
campaign === null ? outbound.replies.listAll({ max: AUTO_CHECK_REPLIES }) : outbound.campaign(campaign).replies.listAll({ max: AUTO_CHECK_REPLIES }),
|
|
4289
|
+
{
|
|
4290
|
+
input: null,
|
|
4291
|
+
max: AUTO_CHECK_REPLIES,
|
|
4292
|
+
what: "replies read to tell automatic replies from people"
|
|
4293
|
+
}
|
|
4294
|
+
);
|
|
4295
|
+
const automatic = /* @__PURE__ */ new Set();
|
|
4296
|
+
const human = /* @__PURE__ */ new Set();
|
|
4297
|
+
for (const reply of replies2) {
|
|
4298
|
+
if (reply.leadRef !== null) {
|
|
4299
|
+
(reply.isAuto === true ? automatic : human).add(reply.leadRef);
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
return new Set(
|
|
4303
|
+
replied.flatMap((lead) => {
|
|
4304
|
+
const refs = refsOf2(lead);
|
|
4305
|
+
return refs.some((ref) => automatic.has(ref)) && !refs.some((ref) => human.has(ref)) ? refs : [];
|
|
4306
|
+
})
|
|
4307
|
+
);
|
|
4308
|
+
};
|
|
4309
|
+
|
|
4310
|
+
// src/insights/people/hot-leads.ts
|
|
3870
4311
|
var DAY2 = 864e5;
|
|
3871
4312
|
var RECENT_REPLIES = 100;
|
|
3872
4313
|
var NOT_ENGAGED = /* @__PURE__ */ new Set([
|
|
@@ -3897,10 +4338,10 @@ var input17 = z20.object({
|
|
|
3897
4338
|
weight_reply: weight(10, "Points for each reply, up to count_cap")
|
|
3898
4339
|
});
|
|
3899
4340
|
var capped = (count2, points, cap) => count2 === null ? null : Math.min(count2, cap) * points;
|
|
3900
|
-
var saidNo = (lead,
|
|
3901
|
-
var repliesDiscounted = (lead,
|
|
4341
|
+
var saidNo = (lead, values) => !values.automatic(lead) && isNegative(lead) && isPositive(lead.interest, values.positive_labels) !== true;
|
|
4342
|
+
var repliesDiscounted = (lead, values) => values.automatic(lead) || saidNo(lead, values);
|
|
3902
4343
|
var engagementParts = (lead, values) => {
|
|
3903
|
-
const unwanted = saidNo(lead, values
|
|
4344
|
+
const unwanted = saidNo(lead, values);
|
|
3904
4345
|
return {
|
|
3905
4346
|
clicks: capped(
|
|
3906
4347
|
lead.engagement?.clicks ?? null,
|
|
@@ -3917,7 +4358,7 @@ var engagementParts = (lead, values) => {
|
|
|
3917
4358
|
var partsOf = (lead, values, now) => {
|
|
3918
4359
|
const engagement = lead.engagement ?? null;
|
|
3919
4360
|
const positive = isPositive(lead.interest, values.positive_labels);
|
|
3920
|
-
const automatic = repliesDiscounted(lead, values
|
|
4361
|
+
const automatic = repliesDiscounted(lead, values);
|
|
3921
4362
|
const counted2 = engagement?.replies ?? (lead.replied === true ? 1 : null);
|
|
3922
4363
|
const replies2 = automatic && counted2 !== null ? 0 : counted2;
|
|
3923
4364
|
const repliedAt = automatic ? null : engagement?.lastRepliedAt ?? null;
|
|
@@ -3932,15 +4373,20 @@ var partsOf = (lead, values, now) => {
|
|
|
3932
4373
|
replies: capped(replies2, values.weight_reply, values.count_cap)
|
|
3933
4374
|
};
|
|
3934
4375
|
};
|
|
3935
|
-
var discountedReason = (lead) =>
|
|
4376
|
+
var discountedReason = (lead, values) => {
|
|
4377
|
+
if (isAutoReplied(lead)) {
|
|
4378
|
+
return `marked ${lead.interest ?? "out of office"}, so replies earn nothing`;
|
|
4379
|
+
}
|
|
4380
|
+
return values.automatic(lead) ? "every reply read was automatic, so replies earn nothing" : `marked ${lead.interest ?? "not interested"}, so it earns no points`;
|
|
4381
|
+
};
|
|
3936
4382
|
var counted = (points, amount, what) => (points ?? 0) > 0 ? plural(amount ?? 0, what) : null;
|
|
3937
|
-
var reasonOf = (lead, parts, now,
|
|
4383
|
+
var reasonOf = (lead, parts, now, values) => {
|
|
3938
4384
|
const engagement = lead.engagement ?? null;
|
|
3939
|
-
const automatic = repliesDiscounted(lead,
|
|
4385
|
+
const automatic = repliesDiscounted(lead, values);
|
|
3940
4386
|
const repliedAt = automatic ? null : engagement?.lastRepliedAt ?? null;
|
|
3941
4387
|
const facts = [
|
|
3942
4388
|
(parts.interest ?? 0) > 0 ? `marked ${lead.interest}` : null,
|
|
3943
|
-
automatic ? discountedReason(lead) : null,
|
|
4389
|
+
automatic ? discountedReason(lead, values) : null,
|
|
3944
4390
|
(parts.replies ?? 0) > 0 ? `replied ${plural(engagement?.replies ?? 1, "time")}` : null,
|
|
3945
4391
|
repliedAt === null ? null : `last reply ${plural(Math.floor(Math.max(0, now - Date.parse(repliedAt)) / DAY2), "day")} ago`,
|
|
3946
4392
|
counted(parts.clicks, engagement?.clicks, "click"),
|
|
@@ -3964,7 +4410,7 @@ var toHotLead = (lead, values, now) => {
|
|
|
3964
4410
|
name: nameOf(lead),
|
|
3965
4411
|
opens: lead.engagement?.opens ?? null,
|
|
3966
4412
|
parts,
|
|
3967
|
-
reason: reasonOf(lead, parts, now, values
|
|
4413
|
+
reason: reasonOf(lead, parts, now, values),
|
|
3968
4414
|
replies: lead.engagement?.replies ?? null,
|
|
3969
4415
|
score: round(score) ?? 0,
|
|
3970
4416
|
status: lead.status,
|
|
@@ -4011,13 +4457,13 @@ var repliedPastCap = async (context, values, read) => {
|
|
|
4011
4457
|
what: "recent replies looked through for leads past max_leads"
|
|
4012
4458
|
}
|
|
4013
4459
|
);
|
|
4014
|
-
const
|
|
4460
|
+
const listed2 = new Set(read.flatMap((lead) => refsOf2(lead)));
|
|
4015
4461
|
const refs = replies2.filter(
|
|
4016
4462
|
(reply) => reply.isAuto !== true && !NOT_ENGAGED.has(reply.category) && reply.sentAt !== null && Date.parse(reply.sentAt) >= since && (values.campaign === null || reply.campaignRef === values.campaign)
|
|
4017
4463
|
).toSorted(
|
|
4018
4464
|
(left, right) => (right.sentAt ?? "").localeCompare(left.sentAt ?? "")
|
|
4019
4465
|
).flatMap(
|
|
4020
|
-
(reply) => reply.leadRef === null ||
|
|
4466
|
+
(reply) => reply.leadRef === null || listed2.has(reply.leadRef) ? [] : [reply.leadRef]
|
|
4021
4467
|
);
|
|
4022
4468
|
const found = await readByRef(
|
|
4023
4469
|
context,
|
|
@@ -4031,18 +4477,18 @@ var repliedPastCap = async (context, values, read) => {
|
|
|
4031
4477
|
var repliesOf = (lead) => lead.engagement?.replies ?? (lead.replied === true ? 1 : 0);
|
|
4032
4478
|
var hottestFirst = (left, right) => right.score - left.score || (right.lastRepliedAt ?? "").localeCompare(left.lastRepliedAt ?? "") || left.lead.localeCompare(right.lead);
|
|
4033
4479
|
var hotLeads = defineInsight({
|
|
4034
|
-
description: "Who to call first: leads ranked by a score built from what the vendor reports, namely a positive interest label, replies, clicks, opens and how recent the last reply is. Every score comes with its parts, and the weights are inputs. A lead with no label and no engagement data is left out and counted in totals.withoutData, never scored 0; unsubscribed and bounced leads are left out too. Give a campaign ref to rank one campaign (an unknown one is refused with NotFound), or none to rank every lead the tool lists. A lead the vendor labels out-of-office or bounced (its interest category, or a label reading out of office) earns no reply or recency points, since a vendor's reply count may include automatic replies; a lead it labels negative (the negative or unsubscribe category, or a label reading not interested, wrong person, unsubscribed or do not contact) earns no points at all, from clicks and opens either, and is listed after every lead with a score above 0 while limit leaves room; its reason names the label. Costs one request per page of leads read (max_leads sets the ceiling). When max_leads stops the listing with more leads left, totals.moreLeadsExist is true and it also reads up to 100 replies from the last recency_days days and one request per replied lead the listing missed, at most limit of them, so engaged leads past the cap are still ranked. A part that is null means the vendor does not report that signal.",
|
|
4480
|
+
description: "Who to call first: leads ranked by a score built from what the vendor reports, namely a positive interest label, replies, clicks, opens and how recent the last reply is. Every score comes with its parts, and the weights are inputs. A lead with no label and no engagement data is left out and counted in totals.withoutData, never scored 0; unsubscribed and bounced leads are left out too. Give a campaign ref to rank one campaign (an unknown one is refused with NotFound), or none to rank every lead the tool lists. A lead the vendor labels out-of-office or bounced (its interest category, or a label reading out of office) earns no reply or recency points, since a vendor's reply count may include automatic replies, and so does a lead whose every reply read is flagged automatic (isAuto, from the vendor or a fixed rule), for which it reads up to 200 of the newest replies, the campaign's when one is given, once a lead has replies; both are counted in totals.autoReplied; a lead it labels negative (the negative or unsubscribe category, or a label reading not interested, wrong person, unsubscribed or do not contact) earns no points at all, from clicks and opens either, and is listed after every lead with a score above 0 while limit leaves room; its reason names the label. Costs one request per page of leads read (max_leads sets the ceiling). When max_leads stops the listing with more leads left, totals.moreLeadsExist is true and it also reads up to 100 replies from the last recency_days days and one request per replied lead the listing missed, at most limit of them, so engaged leads past the cap are still ranked. A part that is null means the vendor does not report that signal.",
|
|
4035
4481
|
inputSchema: input17,
|
|
4036
4482
|
key: "hotLeads",
|
|
4037
|
-
cost: (values, price) => price.list("leads.list", values.max_leads) + (values.campaign === null ? 0 : price.upTo(1) * price.one("campaigns.get")) + (price.capabilities["replies.list"] === false || price.capabilities["leads.get"] === false ? 0 : price.upTo(1) * (price.list("replies.list", 100) + price.upTo(values.limit) * price.one("leads.get"))),
|
|
4483
|
+
cost: (values, price) => price.list("leads.list", values.max_leads) + (values.campaign === null ? 0 : price.upTo(1) * price.one("campaigns.get")) + (price.capabilities["replies.list"] === false ? 0 : price.upTo(1) * price.list("replies.list", AUTO_CHECK_REPLIES)) + (price.capabilities["replies.list"] === false || price.capabilities["leads.get"] === false ? 0 : price.upTo(1) * (price.list("replies.list", 100) + price.upTo(values.limit) * price.one("leads.get"))),
|
|
4038
4484
|
scales: "max_leads",
|
|
4039
4485
|
name: "hot_leads",
|
|
4040
4486
|
needs: [],
|
|
4041
4487
|
next: "Use person_summary with a lead's ref, email address or LinkedIn profile to read the conversation before calling.",
|
|
4042
4488
|
run: async (context, values) => {
|
|
4043
|
-
const
|
|
4044
|
-
const extra =
|
|
4045
|
-
const leads = [...
|
|
4489
|
+
const listed2 = await listLeads(context, values);
|
|
4490
|
+
const extra = listed2.capped ? await repliedPastCap(context, values, listed2.leads) : [];
|
|
4491
|
+
const leads = [...listed2.leads, ...extra];
|
|
4046
4492
|
noteEngagement(
|
|
4047
4493
|
context,
|
|
4048
4494
|
leads,
|
|
@@ -4051,23 +4497,32 @@ var hotLeads = defineInsight({
|
|
|
4051
4497
|
const open = leads.filter(
|
|
4052
4498
|
(lead) => lead.unsubscribed !== true && lead.bounced !== true
|
|
4053
4499
|
);
|
|
4054
|
-
const
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
(lead) =>
|
|
4500
|
+
const autoOnly = await autoOnlyRefs(
|
|
4501
|
+
context,
|
|
4502
|
+
values.campaign,
|
|
4503
|
+
open.filter((lead) => !isAutoReplied(lead))
|
|
4504
|
+
);
|
|
4505
|
+
const scoring = {
|
|
4506
|
+
...values,
|
|
4507
|
+
automatic: (lead) => isAutoReplied(lead) || autoOnly.has(lead.ref)
|
|
4508
|
+
};
|
|
4509
|
+
const scored = open.flatMap(
|
|
4510
|
+
(lead) => toHotLead(lead, scoring, context.now)
|
|
4058
4511
|
);
|
|
4512
|
+
const hot = scored.filter((lead) => lead.score > 0).toSorted(hottestFirst);
|
|
4513
|
+
const negative = open.filter((lead) => saidNo(lead, scoring));
|
|
4059
4514
|
const refused = new Set(negative.map((lead) => lead.ref));
|
|
4060
4515
|
const after = scored.filter((lead) => lead.score <= 0 && refused.has(lead.lead)).toSorted(hottestFirst);
|
|
4061
4516
|
const answer = {
|
|
4062
4517
|
leads: [...hot, ...after].slice(0, values.limit),
|
|
4063
4518
|
totals: {
|
|
4064
4519
|
autoReplied: open.filter(
|
|
4065
|
-
(lead) =>
|
|
4520
|
+
(lead) => scoring.automatic(lead) && repliesOf(lead) > 0
|
|
4066
4521
|
).length,
|
|
4067
4522
|
excluded: leads.length - open.length,
|
|
4068
4523
|
fromReplies: extra.length,
|
|
4069
4524
|
hot: hot.length,
|
|
4070
|
-
moreLeadsExist:
|
|
4525
|
+
moreLeadsExist: listed2.capped,
|
|
4071
4526
|
negative: negative.length,
|
|
4072
4527
|
leadsRead: leads.length,
|
|
4073
4528
|
scored: scored.length,
|
|
@@ -4082,13 +4537,23 @@ var hotLeads = defineInsight({
|
|
|
4082
4537
|
import { z as z21 } from "zod";
|
|
4083
4538
|
|
|
4084
4539
|
// src/insights/people/find.ts
|
|
4540
|
+
var EMAIL = /^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/u;
|
|
4541
|
+
var DOMAIN2 = /^@?[^\s@/:]+(?:\.[^\s@/:.]+)+$/u;
|
|
4542
|
+
var bare = (identifier) => identifier.trim().replace(/^mailto:/iu, "");
|
|
4085
4543
|
var personKey = (identifier) => {
|
|
4086
|
-
const value = identifier
|
|
4544
|
+
const value = bare(identifier);
|
|
4087
4545
|
const slug = profileSlug(value);
|
|
4088
4546
|
if (slug !== null) {
|
|
4089
4547
|
return `linkedin:${slug}`;
|
|
4090
4548
|
}
|
|
4091
|
-
return
|
|
4549
|
+
return EMAIL.test(value) ? `email:${value.toLowerCase()}` : null;
|
|
4550
|
+
};
|
|
4551
|
+
var notAPerson = (identifier) => {
|
|
4552
|
+
const value = bare(identifier);
|
|
4553
|
+
if (DOMAIN2.test(value)) {
|
|
4554
|
+
return `"${value}" is a company domain, not a person. Use account_summary for a company domain`;
|
|
4555
|
+
}
|
|
4556
|
+
return value.includes("@") ? `"${value}" is not a valid email address` : "Give an email address, a LinkedIn profile URL or a lead ref";
|
|
4092
4557
|
};
|
|
4093
4558
|
var keysOfLead = (lead) => {
|
|
4094
4559
|
const slug = profileSlug(lead.linkedinUrl);
|
|
@@ -4156,11 +4621,9 @@ var startFrom = async (context, identifier, { hash, masked }) => {
|
|
|
4156
4621
|
};
|
|
4157
4622
|
}
|
|
4158
4623
|
if (!isLeadRef(identifier)) {
|
|
4159
|
-
throw new OutboundError(
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
{ provider: outbound.provider }
|
|
4163
|
-
);
|
|
4624
|
+
throw new OutboundError("Invalid", notAPerson(identifier), {
|
|
4625
|
+
provider: outbound.provider
|
|
4626
|
+
});
|
|
4164
4627
|
}
|
|
4165
4628
|
const instead = hash === void 0 ? null : "a lead's identifiers are hashed on its record, so give the email address or LinkedIn profile URL instead";
|
|
4166
4629
|
if (masked.length === 2) {
|
|
@@ -4193,10 +4656,18 @@ var carries = (lead, key, start) => {
|
|
|
4193
4656
|
}
|
|
4194
4657
|
return keysOfLead(lead).includes(key);
|
|
4195
4658
|
};
|
|
4659
|
+
var noteNoProfiles = (context, keys) => {
|
|
4660
|
+
if (context.outbound.fields.lead?.linkedinUrl === false && keys.some((key) => kindOf(key) === "linkedin")) {
|
|
4661
|
+
context.note(
|
|
4662
|
+
`${context.outbound.provider} leads have no LinkedIn field, so a LinkedIn profile finds no one there; search by email instead.`
|
|
4663
|
+
);
|
|
4664
|
+
}
|
|
4665
|
+
};
|
|
4196
4666
|
var findPerson = async (context, identifier, maxRecords) => {
|
|
4197
4667
|
const lookup = lookupOf(context.outbound);
|
|
4198
4668
|
const { masked } = lookup;
|
|
4199
4669
|
const start = await startFrom(context, identifier, lookup);
|
|
4670
|
+
noteNoProfiles(context, start.keys);
|
|
4200
4671
|
if (masked.length > 0) {
|
|
4201
4672
|
context.partial(
|
|
4202
4673
|
`The redact plugin masks ${maskedWords(masked)}, so records found only under that identifier were not linked.`
|
|
@@ -4248,6 +4719,9 @@ var findPerson = async (context, identifier, maxRecords) => {
|
|
|
4248
4719
|
|
|
4249
4720
|
// src/insights/people/lead-collisions.ts
|
|
4250
4721
|
var input18 = z21.object({
|
|
4722
|
+
include_past: z21.boolean().default(false).describe(
|
|
4723
|
+
"Also report a person in two or more campaigns of whom fewer than two memberships are still active, for example one who completed one campaign and is now in another. By default only people active in two or more campaigns at once are reported."
|
|
4724
|
+
),
|
|
4251
4725
|
max_campaigns: z21.number().int().min(1).max(200).default(20).describe(
|
|
4252
4726
|
"The most campaigns to read. Each costs one request per page of its leads."
|
|
4253
4727
|
),
|
|
@@ -4291,22 +4765,41 @@ var toCollision = (group) => {
|
|
|
4291
4765
|
const channels = [...new Set(campaigns.map((each) => each.channel))];
|
|
4292
4766
|
const scope = providers.length > 1 ? "across_tools" : "within_tool";
|
|
4293
4767
|
const identifiers = [...group.keys].toSorted();
|
|
4768
|
+
const active = campaigns.filter((each) => each.leadStatus === "active");
|
|
4294
4769
|
return [
|
|
4295
4770
|
{
|
|
4296
4771
|
campaignCount: campaigns.length,
|
|
4297
4772
|
campaigns,
|
|
4298
4773
|
channels,
|
|
4299
|
-
finding:
|
|
4774
|
+
finding: findingOf2(shownKey(identifiers[0] ?? ""), campaigns, {
|
|
4775
|
+
channels,
|
|
4776
|
+
providers
|
|
4777
|
+
}),
|
|
4300
4778
|
identifiers,
|
|
4301
4779
|
providers,
|
|
4302
4780
|
scope,
|
|
4303
|
-
stillActive:
|
|
4781
|
+
stillActive: active.length
|
|
4304
4782
|
}
|
|
4305
4783
|
];
|
|
4306
4784
|
};
|
|
4307
|
-
var
|
|
4785
|
+
var listed = (parts) => parts.length < 2 ? parts[0] ?? "" : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`;
|
|
4786
|
+
var named3 = (campaigns) => listed(campaigns.map((each) => `"${each.campaignName}"`));
|
|
4787
|
+
var withStatus = (campaigns) => listed(
|
|
4788
|
+
campaigns.map((each) => `"${each.campaignName}" (${each.leadStatus})`)
|
|
4789
|
+
);
|
|
4790
|
+
var findingOf2 = (who, campaigns, tools) => {
|
|
4791
|
+
const active = campaigns.filter((each) => each.leadStatus === "active");
|
|
4792
|
+
const past = campaigns.filter((each) => each.leadStatus !== "active");
|
|
4793
|
+
if (active.length >= 2) {
|
|
4794
|
+
const where = tools.providers.length > 1 ? `campaigns across ${tools.providers.join(" and ")} (${tools.channels.join(" and ")})` : `${tools.providers[0]} campaigns`;
|
|
4795
|
+
const also = past.length === 0 ? "" : `, and was in ${withStatus(past)}`;
|
|
4796
|
+
return `${who} is in ${active.length} ${where} at once${also}.`;
|
|
4797
|
+
}
|
|
4798
|
+
return active.length === 0 ? `${who} was in ${withStatus(past)}, and is active in none of them now.` : `${who} was in ${withStatus(past)} and is now active in ${named3(active)}.`;
|
|
4799
|
+
};
|
|
4800
|
+
var worstFirst = (left, right) => right.stillActive - left.stillActive || right.campaignCount - left.campaignCount || left.scope.localeCompare(right.scope) || (left.identifiers[0] ?? "").localeCompare(right.identifiers[0] ?? "");
|
|
4308
4801
|
var leadCollisions = defineInsight({
|
|
4309
|
-
description: "People who are in two or more campaigns at once, so they get overlapping outreach. Reads the campaigns in the given statuses (active by default) and their leads, matches people by exact email address or LinkedIn profile, and returns each person with their campaigns, channel and tool, most campaigns first. A collision across tools (for example email in one and LinkedIn in another) is marked across_tools; one inside a tool is within_tool. Costs one request per page of campaigns plus one per page of each campaign's leads; the caps make the answer incomplete rather than slow.",
|
|
4802
|
+
description: "People who are in two or more campaigns at once, so they get overlapping outreach. Reads the campaigns in the given statuses (active by default) and their leads, matches people by exact email address or LinkedIn profile, and returns each person with their campaigns, channel and tool, most active campaigns first. By default a person counts only when their own status is active in two or more of the campaigns; include_past also reports people who finished, replied to or left one campaign and are in another, counted in totals.pastOverlaps either way. A collision across tools (for example email in one and LinkedIn in another) is marked across_tools; one inside a tool is within_tool. Costs one request per page of campaigns plus one per page of each campaign's leads; the caps make the answer incomplete rather than slow.",
|
|
4310
4803
|
inputSchema: input18,
|
|
4311
4804
|
key: "leadCollisions",
|
|
4312
4805
|
// A masked address is the same text for every lead, so every lead would
|
|
@@ -4338,7 +4831,9 @@ var leadCollisions = defineInsight({
|
|
|
4338
4831
|
return leads.map((lead) => ({ campaign, lead }));
|
|
4339
4832
|
});
|
|
4340
4833
|
const entries = perCampaign.flat();
|
|
4341
|
-
const
|
|
4834
|
+
const overlaps = groupPeople(entries).flatMap(toCollision);
|
|
4835
|
+
const pastOverlaps = overlaps.filter((each) => each.stillActive < 2).length;
|
|
4836
|
+
const collisions = overlaps.filter((each) => values.include_past || each.stillActive >= 2).toSorted(worstFirst);
|
|
4342
4837
|
const acrossTools = collisions.filter(
|
|
4343
4838
|
(each) => each.scope === "across_tools"
|
|
4344
4839
|
).length;
|
|
@@ -4348,10 +4843,12 @@ var leadCollisions = defineInsight({
|
|
|
4348
4843
|
acrossTools,
|
|
4349
4844
|
campaignsRead: campaigns.length,
|
|
4350
4845
|
collisions: collisions.length,
|
|
4846
|
+
concurrent: collisions.filter((each) => each.stillActive >= 2).length,
|
|
4351
4847
|
leadsRead: entries.length,
|
|
4352
4848
|
leadsWithoutIdentifier: entries.filter(
|
|
4353
4849
|
(entry) => keysOfLead(entry.lead).length === 0
|
|
4354
4850
|
).length,
|
|
4851
|
+
pastOverlaps,
|
|
4355
4852
|
withinTool: collisions.length - acrossTools
|
|
4356
4853
|
}
|
|
4357
4854
|
};
|
|
@@ -4370,6 +4867,7 @@ var input19 = z22.object({
|
|
|
4370
4867
|
var times2 = (messages, direction) => messages.flatMap(
|
|
4371
4868
|
(message) => message.direction === direction && message.sentAt !== null ? [message.sentAt] : []
|
|
4372
4869
|
);
|
|
4870
|
+
var isAutoMessage = (message) => message.direction === "in" && message.isAuto === true;
|
|
4373
4871
|
var repliedSteps = (lead, messages) => {
|
|
4374
4872
|
const steps = /* @__PURE__ */ new Set();
|
|
4375
4873
|
let lastSent = null;
|
|
@@ -4380,15 +4878,19 @@ var repliedSteps = (lead, messages) => {
|
|
|
4380
4878
|
steps.add(message.stepIndex ?? lastSent ?? 0);
|
|
4381
4879
|
}
|
|
4382
4880
|
}
|
|
4383
|
-
const
|
|
4384
|
-
if (
|
|
4385
|
-
steps.add(
|
|
4881
|
+
const named4 = lead.engagement?.repliedStepIndex ?? null;
|
|
4882
|
+
if (named4 !== null) {
|
|
4883
|
+
steps.add(named4);
|
|
4386
4884
|
}
|
|
4387
4885
|
return [...steps].toSorted((left, right) => left - right);
|
|
4388
4886
|
};
|
|
4389
4887
|
var activityOf = (lead, messages) => {
|
|
4390
4888
|
const sent = times2(messages, "out");
|
|
4391
|
-
const received = times2(
|
|
4889
|
+
const received = times2(
|
|
4890
|
+
messages.filter((message) => !isAutoMessage(message)),
|
|
4891
|
+
"in"
|
|
4892
|
+
);
|
|
4893
|
+
const automatic = messages.filter(isAutoMessage).length;
|
|
4392
4894
|
const counted2 = lead.engagement;
|
|
4393
4895
|
return {
|
|
4394
4896
|
firstContactedAt: sent[0] ?? null,
|
|
@@ -4400,11 +4902,26 @@ var activityOf = (lead, messages) => {
|
|
|
4400
4902
|
// A vendor's thread can hold fewer messages than were sent; the last
|
|
4401
4903
|
// step sent (counted from 0) is then the better count.
|
|
4402
4904
|
messagesSent: Math.max(sent.length, (counted2?.stepIndex ?? -1) + 1),
|
|
4403
|
-
|
|
4404
|
-
|
|
4905
|
+
automatic,
|
|
4906
|
+
// A vendor that keeps no thread still counts replies on the lead, and
|
|
4907
|
+
// that count can include the automatic replies the thread holds.
|
|
4908
|
+
replies: Math.max(received.length, (counted2?.replies ?? 0) - automatic),
|
|
4405
4909
|
threadIsShort: sent.length < (counted2?.stepIndex ?? -1) + 1
|
|
4406
4910
|
};
|
|
4407
4911
|
};
|
|
4912
|
+
var noteAutomatic = (context, lead, replies2, flagged) => {
|
|
4913
|
+
if (isAutoReplied(lead)) {
|
|
4914
|
+
if (replies2 > 0) {
|
|
4915
|
+
context.note(
|
|
4916
|
+
"A record the vendor labels out-of-office or bounced had replies; they were automatic, so they are not counted as replies."
|
|
4917
|
+
);
|
|
4918
|
+
}
|
|
4919
|
+
} else if (flagged > 0) {
|
|
4920
|
+
context.note(
|
|
4921
|
+
"A record's thread held replies flagged automatic, by the vendor or by a fixed rule; they are not counted as replies."
|
|
4922
|
+
);
|
|
4923
|
+
}
|
|
4924
|
+
};
|
|
4408
4925
|
var timelineOf = async (context, timelines, lead) => {
|
|
4409
4926
|
let all = timelines.get(lead.ref);
|
|
4410
4927
|
if (all === void 0) {
|
|
@@ -4422,19 +4939,19 @@ var summarize2 = async (context, timelines, lead) => {
|
|
|
4422
4939
|
timelineOf(context, timelines, lead),
|
|
4423
4940
|
lead.campaignRef === null ? null : outbound.campaigns.get(lead.campaignRef).then(context.one)
|
|
4424
4941
|
]);
|
|
4425
|
-
const { threadIsShort, ...counted2 } = activityOf(lead, messages);
|
|
4426
|
-
const autoReplied = isAutoReplied(lead);
|
|
4942
|
+
const { automatic, threadIsShort, ...counted2 } = activityOf(lead, messages);
|
|
4943
|
+
const autoReplied = isAutoReplied(lead) || automatic > 0 && counted2.replies === 0;
|
|
4427
4944
|
const activity = autoReplied ? { ...counted2, lastRepliedAt: null, replies: 0 } : counted2;
|
|
4428
|
-
|
|
4429
|
-
context.note(
|
|
4430
|
-
"A record the vendor labels out-of-office or bounced had replies; they were automatic, so they are not counted as replies."
|
|
4431
|
-
);
|
|
4432
|
-
}
|
|
4945
|
+
noteAutomatic(context, lead, counted2.replies + automatic, automatic);
|
|
4433
4946
|
if (threadIsShort) {
|
|
4434
4947
|
context.note(
|
|
4435
4948
|
"A thread held fewer sent messages than the lead's last step, so messages sent is counted from the last step."
|
|
4436
4949
|
);
|
|
4437
4950
|
}
|
|
4951
|
+
const steps = autoReplied ? [] : repliedSteps(
|
|
4952
|
+
lead,
|
|
4953
|
+
messages.filter((message) => !isAutoMessage(message))
|
|
4954
|
+
);
|
|
4438
4955
|
return {
|
|
4439
4956
|
...activity,
|
|
4440
4957
|
campaign: lead.campaignRef,
|
|
@@ -4443,11 +4960,17 @@ var summarize2 = async (context, timelines, lead) => {
|
|
|
4443
4960
|
channel: campaign?.channel ?? (lead.email === null ? "linkedin" : "email"),
|
|
4444
4961
|
interest: lead.interest,
|
|
4445
4962
|
lead: lead.ref,
|
|
4446
|
-
|
|
4963
|
+
// The vendor's "replied" can count an out-of-office; the person did not reply.
|
|
4964
|
+
leadStatus: autoReplied && lead.status === "replied" ? lead.progress : lead.status,
|
|
4447
4965
|
provider: lead.provider,
|
|
4448
4966
|
autoReplied,
|
|
4449
4967
|
replied: !autoReplied && (activity.replies > 0 || lead.replied === true),
|
|
4450
|
-
|
|
4968
|
+
lastStepIndex: activity.lastStep,
|
|
4969
|
+
lastStepNumber: activity.lastStep === null ? null : activity.lastStep + 1,
|
|
4970
|
+
repliedStepIndexes: steps,
|
|
4971
|
+
repliedStepNumbers: steps.map((index) => index + 1),
|
|
4972
|
+
repliedSteps: steps,
|
|
4973
|
+
vendorLeadStatus: lead.status
|
|
4451
4974
|
};
|
|
4452
4975
|
};
|
|
4453
4976
|
var byChannel2 = (campaigns) => {
|
|
@@ -4465,7 +4988,7 @@ var byChannel2 = (campaigns) => {
|
|
|
4465
4988
|
return channels;
|
|
4466
4989
|
};
|
|
4467
4990
|
var personSummary = defineInsight({
|
|
4468
|
-
description: "Everything about one person across campaigns and channels, from their email address, LinkedIn profile or a lead ref: each campaign they are in, how many messages they were sent, whether and how often they replied, which steps they replied to, their interest label, and totals by channel. Records are linked by exact identifier only, so an email finds a LinkedIn record only when a tool holds both for that person. A record the vendor labels out-of-office or bounced counts no replies, since they were automatic. Costs one lookup per identifier, one request to read a lead ref, then up to 2 requests per campaign.",
|
|
4991
|
+
description: "Everything about one person across campaigns and channels, from their email address, LinkedIn profile or a lead ref: each campaign they are in, how many messages they were sent, whether and how often they replied, which steps they replied to, their interest label, and totals by channel. Records are linked by exact identifier only, so an email finds a LinkedIn record only when a tool holds both for that person. A record the vendor labels out-of-office or bounced counts no replies, since they were automatic, and a reply in the thread flagged automatic (isAuto, from the vendor or a fixed rule) is not counted either. Costs one lookup per identifier, one request to read a lead ref, then up to 2 requests per campaign.",
|
|
4469
4992
|
inputSchema: input19,
|
|
4470
4993
|
key: "personSummary",
|
|
4471
4994
|
cost: (values, price) => (isLeadRef(values.person) ? price.one("leads.get") + price.upTo(2) * price.lookup(values.max_campaigns) : price.lookup(values.max_campaigns) + price.upTo(1) * price.lookup(values.max_campaigns)) + price.upTo(values.max_campaigns) * (price.one("campaigns.get") + price.walk("messages.list")),
|
|
@@ -4513,7 +5036,7 @@ var personSummary = defineInsight({
|
|
|
4513
5036
|
// src/insights/people/personalization-gaps.ts
|
|
4514
5037
|
import { z as z23 } from "zod";
|
|
4515
5038
|
var input20 = z23.object({
|
|
4516
|
-
campaign: z23.string().min(1).describe("The campaign's ref (provider:workspace:id)"),
|
|
5039
|
+
campaign: z23.string().min(1).describe("The campaign's ref (provider:workspace:id) or name"),
|
|
4517
5040
|
limit: z23.number().int().min(1).max(5e3).default(100).describe("How many affected leads to list. The counts cover all of them."),
|
|
4518
5041
|
max_leads: z23.number().int().min(1).max(2e4).default(500).describe(
|
|
4519
5042
|
"The most leads to check. A vendor request returns about 50 to 100 leads."
|
|
@@ -4526,16 +5049,21 @@ var findVariables = (sequence2) => {
|
|
|
4526
5049
|
(step) => step.variants.flatMap(
|
|
4527
5050
|
(variant) => FIELDS.map((field) => ({
|
|
4528
5051
|
field,
|
|
4529
|
-
|
|
5052
|
+
stepIndex: step.index,
|
|
4530
5053
|
text: variant[field] ?? "",
|
|
4531
5054
|
variant: variant.variantKey
|
|
4532
5055
|
}))
|
|
4533
5056
|
)
|
|
4534
5057
|
);
|
|
4535
|
-
for (const { field,
|
|
5058
|
+
for (const { field, stepIndex, text, variant } of texts) {
|
|
4536
5059
|
for (const { fallback, name } of variablesIn(text)) {
|
|
4537
5060
|
const entry = found.get(keyOf(name)) ?? { name, uses: [] };
|
|
4538
|
-
entry.uses.push({
|
|
5061
|
+
entry.uses.push({
|
|
5062
|
+
...stepAt(stepIndex),
|
|
5063
|
+
fallback: fallback !== null,
|
|
5064
|
+
field,
|
|
5065
|
+
variant
|
|
5066
|
+
});
|
|
4539
5067
|
found.set(keyOf(name), entry);
|
|
4540
5068
|
}
|
|
4541
5069
|
}
|
|
@@ -4547,20 +5075,23 @@ var sourceOf = (key, customKeys) => {
|
|
|
4547
5075
|
}
|
|
4548
5076
|
return customKeys.has(key) ? "custom" : "unknown";
|
|
4549
5077
|
};
|
|
4550
|
-
var toVariable = (key, { name, uses }, leads, customKeys) => {
|
|
4551
|
-
const
|
|
5078
|
+
var toVariable = (provider, key, { name, uses }, leads, customKeys) => {
|
|
5079
|
+
const sender = isSender(provider, key);
|
|
5080
|
+
const source = sender ? "unknown" : sourceOf(key, customKeys);
|
|
4552
5081
|
const known2 = source !== "unknown";
|
|
4553
5082
|
const needed = uses.some((use) => !use.fallback);
|
|
4554
5083
|
const without = leads.filter((values) => !values.has(key)).length;
|
|
5084
|
+
const affected = known2 ? Number(needed) * without : null;
|
|
4555
5085
|
return {
|
|
4556
5086
|
key,
|
|
4557
5087
|
variable: {
|
|
4558
|
-
gap:
|
|
4559
|
-
leadsAffected:
|
|
5088
|
+
gap: affected !== null && affected > 0,
|
|
5089
|
+
leadsAffected: affected,
|
|
4560
5090
|
leadsWithoutValue: known2 ? without : null,
|
|
4561
5091
|
name,
|
|
5092
|
+
sender,
|
|
4562
5093
|
source,
|
|
4563
|
-
steps: [...new Set(uses.map((use) => use.
|
|
5094
|
+
steps: [...new Set(uses.map((use) => use.stepIndex))].toSorted(
|
|
4564
5095
|
(left, right) => left - right
|
|
4565
5096
|
),
|
|
4566
5097
|
uses
|
|
@@ -4582,7 +5113,7 @@ var missingOf = (lead, values, gaps) => {
|
|
|
4582
5113
|
];
|
|
4583
5114
|
};
|
|
4584
5115
|
var personalizationGaps = defineInsight({
|
|
4585
|
-
description: "Leads in one campaign who will get broken copy because a merge variable has no value for them. Reads the campaign's sequence, finds every {{variable}}, {variable} and %variable% in subjects and bodies, and checks each lead for a value: first name, last name, company, title, email, or a custom field of the same name without regard to case, spaces, underscores or hyphens. Returns the variables with the steps that use them, how many leads each one affects, and the leads missing at least one. A variable with a fallback such as {{firstName|there}} is not a gap. A variable
|
|
5116
|
+
description: "Leads in one campaign who will get broken copy because a merge variable has no value for them. Reads the campaign's sequence, finds every {{variable}}, {variable} and %variable% in subjects and bodies, and checks each lead for a value: first name, last name, company, title, email, or a custom field of the same name without regard to case, spaces, underscores or hyphens. Returns the variables with the steps that use them, how many leads each one affects, and the leads missing at least one. A variable with a fallback such as {{firstName|there}} is not a gap. A variable the tool fills from the sending account, such as Instantly's {{accountSignature}}, is marked sender: true and left out of unknownVariables; any other variable no lead has is listed as unknown. Neither is counted against leads. Costs one request for the sequence plus one per page of leads.",
|
|
4586
5117
|
inputSchema: input20,
|
|
4587
5118
|
key: "personalizationGaps",
|
|
4588
5119
|
cost: (values, price) => price.one("sequence.get") + price.upTo(1) * price.list("leads.list", values.max_leads),
|
|
@@ -4608,7 +5139,13 @@ var personalizationGaps = defineInsight({
|
|
|
4608
5139
|
leads.flatMap((lead) => Object.keys(lead.custom).map(keyOf))
|
|
4609
5140
|
);
|
|
4610
5141
|
const keyed = [...found].map(
|
|
4611
|
-
([key, entry]) => toVariable(
|
|
5142
|
+
([key, entry]) => toVariable(
|
|
5143
|
+
sequence2.provider,
|
|
5144
|
+
key,
|
|
5145
|
+
entry,
|
|
5146
|
+
leads.map(keysWithValue),
|
|
5147
|
+
customKeys
|
|
5148
|
+
)
|
|
4612
5149
|
);
|
|
4613
5150
|
const variables = keyed.map((each) => each.variable).toSorted(
|
|
4614
5151
|
(left, right) => (right.leadsAffected ?? -1) - (left.leadsAffected ?? -1) || left.name.localeCompare(right.name)
|
|
@@ -4628,7 +5165,7 @@ var personalizationGaps = defineInsight({
|
|
|
4628
5165
|
variables: variables.length
|
|
4629
5166
|
},
|
|
4630
5167
|
unknownVariables: variables.flatMap(
|
|
4631
|
-
(each) => each.source === "unknown" ? [each.name] : []
|
|
5168
|
+
(each) => each.source === "unknown" && each.sender !== true ? [each.name] : []
|
|
4632
5169
|
),
|
|
4633
5170
|
variables
|
|
4634
5171
|
};
|
|
@@ -4638,7 +5175,15 @@ var personalizationGaps = defineInsight({
|
|
|
4638
5175
|
|
|
4639
5176
|
// src/insights/people/suppression-check.ts
|
|
4640
5177
|
import { z as z24 } from "zod";
|
|
5178
|
+
var SENDABLE = [
|
|
5179
|
+
"active",
|
|
5180
|
+
"paused",
|
|
5181
|
+
"unknown"
|
|
5182
|
+
];
|
|
4641
5183
|
var input21 = z24.object({
|
|
5184
|
+
lead_statuses: z24.array(leadStatusSchema).min(1).default([...SENDABLE]).describe(
|
|
5185
|
+
"Only a matching lead in one of these states is a violation: active, paused, unknown (not yet started, or the tool does not say), completed, skipped (the tool decided never to send), replied, bounced or unsubscribed. Other matches are counted in totals.alreadyStopped. Defaults to the leads still being sent to."
|
|
5186
|
+
),
|
|
4642
5187
|
max_block_entries: z24.number().int().min(1).max(1e5).default(2e3).describe(
|
|
4643
5188
|
"The most block list entries to read. A vendor request returns about 50 to 100."
|
|
4644
5189
|
),
|
|
@@ -4713,7 +5258,7 @@ var maskNote = (outbound) => {
|
|
|
4713
5258
|
};
|
|
4714
5259
|
var activeFirst = (left, right) => Number(right.leadStatus === "active") - Number(left.leadStatus === "active") || left.campaign.localeCompare(right.campaign) || left.lead.localeCompare(right.lead);
|
|
4715
5260
|
var suppressionCheck = defineInsight({
|
|
4716
|
-
description: "Leads sitting in campaigns although they are on the block list. Reads the block list, then the leads of each campaign in the given statuses (active by default), and matches a lead by exact email address, by email domain against domain entries, and by LinkedIn profile against profile entries. Returns each violation with the lead, the campaign, the entry and how it matched, counts per campaign, and how many block entries were read; totals.moreBlockEntriesExist is true when max_block_entries left entries unread, which were not checked. On several tools an entry on one tool's list is also matched against the other tools' leads and marked sameTool false. Costs one request per page of block entries plus one per page of each campaign's leads.",
|
|
5261
|
+
description: "Leads sitting in campaigns although they are on the block list. Reads the block list, then the leads of each campaign in the given statuses (active by default), and matches a lead by exact email address, by email domain against domain entries, and by LinkedIn profile against profile entries. A match is a violation only when the lead's own status is in lead_statuses (active, paused or unknown by default, the leads still being sent to); a lead that already unsubscribed, bounced, replied or completed is counted in totals.alreadyStopped instead. Returns each violation with the lead, the campaign, the entry and how it matched, counts per campaign, and how many block entries were read; totals.moreBlockEntriesExist is true when max_block_entries left entries unread, which were not checked. On several tools an entry on one tool's list is also matched against the other tools' leads and marked sameTool false. Costs one request per page of block entries plus one per page of each campaign's leads.",
|
|
4717
5262
|
inputSchema: input21,
|
|
4718
5263
|
key: "suppressionCheck",
|
|
4719
5264
|
// A masked address is the same text for every lead, so nothing can match.
|
|
@@ -4725,14 +5270,14 @@ var suppressionCheck = defineInsight({
|
|
|
4725
5270
|
needs: ["blocklist", "leads.byCampaign"],
|
|
4726
5271
|
next: "Use person_summary with a violating lead's ref or email address to see what they were already sent.",
|
|
4727
5272
|
run: async (context, values) => {
|
|
4728
|
-
const
|
|
5273
|
+
const listed2 = await readCappedFlag(
|
|
4729
5274
|
context,
|
|
4730
5275
|
(cap) => context.outbound.blocklist.listAll({ max: cap }),
|
|
4731
5276
|
values.max_block_entries,
|
|
4732
5277
|
"block list entries",
|
|
4733
5278
|
"max_block_entries"
|
|
4734
5279
|
);
|
|
4735
|
-
const entries =
|
|
5280
|
+
const entries = listed2.items;
|
|
4736
5281
|
const blocked = indexEntries(entries);
|
|
4737
5282
|
const unmatched = maskNote(context.outbound);
|
|
4738
5283
|
if (unmatched !== null) {
|
|
@@ -4743,8 +5288,10 @@ var suppressionCheck = defineInsight({
|
|
|
4743
5288
|
values.statuses,
|
|
4744
5289
|
values.max_campaigns
|
|
4745
5290
|
);
|
|
5291
|
+
const sendable = new Set(values.lead_statuses);
|
|
4746
5292
|
const violations = [];
|
|
4747
5293
|
const byCampaign = [];
|
|
5294
|
+
let alreadyStopped = 0;
|
|
4748
5295
|
const read = await mapConcurrent(campaigns, async (campaign) => ({
|
|
4749
5296
|
campaign,
|
|
4750
5297
|
...await readCappedFlag(
|
|
@@ -4756,10 +5303,12 @@ var suppressionCheck = defineInsight({
|
|
|
4756
5303
|
)
|
|
4757
5304
|
}));
|
|
4758
5305
|
for (const { campaign, items: leads } of read) {
|
|
4759
|
-
const
|
|
5306
|
+
const matched = leads.flatMap((lead) => {
|
|
4760
5307
|
const hit = matchLead(lead, blocked);
|
|
4761
5308
|
return hit === null ? [] : [toViolation(lead, campaign, hit)];
|
|
4762
5309
|
});
|
|
5310
|
+
const found = matched.filter((each) => sendable.has(each.leadStatus));
|
|
5311
|
+
alreadyStopped += matched.length - found.length;
|
|
4763
5312
|
violations.push(...found);
|
|
4764
5313
|
byCampaign.push({
|
|
4765
5314
|
campaign: campaign.ref,
|
|
@@ -4774,7 +5323,8 @@ var suppressionCheck = defineInsight({
|
|
|
4774
5323
|
(left, right) => right.violations - left.violations || left.campaign.localeCompare(right.campaign)
|
|
4775
5324
|
),
|
|
4776
5325
|
totals: {
|
|
4777
|
-
|
|
5326
|
+
alreadyStopped,
|
|
5327
|
+
blockEntriesNotChecked: listed2.capped ? null : blocked.notChecked,
|
|
4778
5328
|
blockEntriesRead: entries.length,
|
|
4779
5329
|
byMatch: {
|
|
4780
5330
|
domain: matches.get("domain") ?? 0,
|
|
@@ -4783,7 +5333,7 @@ var suppressionCheck = defineInsight({
|
|
|
4783
5333
|
},
|
|
4784
5334
|
campaignsRead: campaigns.length,
|
|
4785
5335
|
leadsRead: byCampaign.reduce((sum, each) => sum + each.leadsRead, 0),
|
|
4786
|
-
moreBlockEntriesExist:
|
|
5336
|
+
moreBlockEntriesExist: listed2.capped,
|
|
4787
5337
|
moreLeadsExist: read.some((each) => each.capped),
|
|
4788
5338
|
violations: violations.length
|
|
4789
5339
|
},
|
|
@@ -5385,7 +5935,7 @@ var askOf = (reads) => {
|
|
|
5385
5935
|
withoutLimit: reads.length - withLimit
|
|
5386
5936
|
};
|
|
5387
5937
|
};
|
|
5388
|
-
var
|
|
5938
|
+
var findingOf3 = (capacity, ask, sends) => {
|
|
5389
5939
|
if (capacity.daily === null) {
|
|
5390
5940
|
return "No active sender reports a daily limit, so capacity is unknown.";
|
|
5391
5941
|
}
|
|
@@ -5427,8 +5977,8 @@ var senderCapacity = defineInsight({
|
|
|
5427
5977
|
}) => {
|
|
5428
5978
|
const { outbound } = context;
|
|
5429
5979
|
const { capabilities } = outbound;
|
|
5430
|
-
const
|
|
5431
|
-
const senders2 =
|
|
5980
|
+
const listed2 = await readSenders(context, maxSenders);
|
|
5981
|
+
const senders2 = listed2.items;
|
|
5432
5982
|
const campaigns = await readCampaigns(context, ["active"], maxCampaigns);
|
|
5433
5983
|
const reads = await mapConcurrent(
|
|
5434
5984
|
campaigns,
|
|
@@ -5447,13 +5997,13 @@ var senderCapacity = defineInsight({
|
|
|
5447
5997
|
}
|
|
5448
5998
|
const capacity = capacityOf(senders2);
|
|
5449
5999
|
const ask = hasSettings ? askOf(reads) : null;
|
|
5450
|
-
const sends = await readSends(context, campaigns, days,
|
|
6000
|
+
const sends = await readSends(context, campaigns, days, listed2, split);
|
|
5451
6001
|
const shortfalls = reads.map(shortfallOf);
|
|
5452
6002
|
const answer = {
|
|
5453
6003
|
ask,
|
|
5454
6004
|
askRatio: rate(ask?.daily ?? null, capacity.daily),
|
|
5455
6005
|
capacity,
|
|
5456
|
-
finding:
|
|
6006
|
+
finding: findingOf3(capacity, ask, sends),
|
|
5457
6007
|
sends,
|
|
5458
6008
|
shortCampaigns: canCompare ? shortfalls.flatMap(
|
|
5459
6009
|
(each) => each === null || each === "unchecked" ? [] : [each]
|
|
@@ -5994,11 +6544,12 @@ var insights = () => ({
|
|
|
5994
6544
|
import { z as z32 } from "zod";
|
|
5995
6545
|
var INSIGHT_TOOL_CEILING = 500;
|
|
5996
6546
|
var NEXT_FALLBACK = "Pick another of the listed tools to go further.";
|
|
6547
|
+
var ANSWER_NOTE = "The answer is in data, in camelCase like every insight's answer. meta.complete: false means it covers part of the data, and meta.notes says why.";
|
|
5997
6548
|
var hintFor = (next, offered) => {
|
|
5998
6549
|
const hidden = ENTRIES.flatMap(
|
|
5999
6550
|
(entry) => offered.has(entry.name) ? [] : [entry.name]
|
|
6000
6551
|
);
|
|
6001
|
-
const kept = next.split(/(?<=\.)\s+/u).filter((
|
|
6552
|
+
const kept = next.split(/(?<=\.)\s+/u).filter((sentence2) => !hidden.some((name) => sentence2.includes(name)));
|
|
6002
6553
|
return kept.length === 0 ? NEXT_FALLBACK : kept.join(" ");
|
|
6003
6554
|
};
|
|
6004
6555
|
var toTool = (outbound, definition, next, perCall) => ({
|
|
@@ -6021,13 +6572,11 @@ var toTool = (outbound, definition, next, perCall) => ({
|
|
|
6021
6572
|
} : { capSetting: "maxRequestsPerToolCall", maxRequests: set }
|
|
6022
6573
|
);
|
|
6023
6574
|
return {
|
|
6024
|
-
data:
|
|
6025
|
-
complete: result.meta.complete,
|
|
6026
|
-
notes: [...result.meta.notes],
|
|
6027
|
-
result: result.data
|
|
6028
|
-
},
|
|
6575
|
+
data: result.data,
|
|
6029
6576
|
meta: {
|
|
6577
|
+
complete: result.meta.complete,
|
|
6030
6578
|
evidence: result.meta.evidence,
|
|
6579
|
+
notes: [...result.meta.notes],
|
|
6031
6580
|
provider: result.meta.provider,
|
|
6032
6581
|
requests: result.meta.requests
|
|
6033
6582
|
},
|
|
@@ -6050,7 +6599,7 @@ var toTool = (outbound, definition, next, perCall) => ({
|
|
|
6050
6599
|
);
|
|
6051
6600
|
}
|
|
6052
6601
|
},
|
|
6053
|
-
description: definition.description
|
|
6602
|
+
description: `${definition.description} ${ANSWER_NOTE}`,
|
|
6054
6603
|
fields: definition.inputSchema.shape,
|
|
6055
6604
|
name: definition.name,
|
|
6056
6605
|
needs: [...definition.needs],
|