outbound-sdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +119 -2
- package/dist/alerts/index.d.ts +2 -0
- package/dist/alerts/index.js +140 -0
- package/dist/alerts/plugin.d.ts +58 -0
- package/dist/audit/index.d.ts +33 -0
- package/dist/audit/index.js +60 -0
- package/dist/benchmarks/index.d.ts +29 -0
- package/dist/benchmarks/index.js +72 -0
- package/dist/budget/index.d.ts +21 -0
- package/dist/budget/index.js +71 -0
- package/dist/cache/index.d.ts +31 -0
- package/dist/cache/index.js +11 -0
- package/dist/cards/content.d.ts +43 -0
- package/dist/cards/copy-cards.d.ts +2 -0
- package/dist/cards/format.d.ts +39 -0
- package/dist/cards/index.d.ts +9 -0
- package/dist/cards/index.js +2070 -0
- package/dist/cards/notify-cards.d.ts +14 -0
- package/dist/cards/ops-cards.d.ts +2 -0
- package/dist/cards/parts.d.ts +22 -0
- package/dist/cards/people-cards.d.ts +2 -0
- package/dist/cards/render.d.ts +28 -0
- package/dist/cards/sender-cards.d.ts +2 -0
- package/dist/cards/slack-rich.d.ts +19 -0
- package/dist/cards/slack-text.d.ts +10 -0
- package/dist/cards/slack.d.ts +21 -0
- package/dist/cards/spec.d.ts +86 -0
- package/dist/cards/tool-cards.d.ts +4 -0
- package/dist/chunks/chunk-4O2HRTTI.js +75 -0
- package/dist/chunks/chunk-4PSO6JEK.js +357 -0
- package/dist/chunks/chunk-6CVZOUHB.js +152 -0
- package/dist/chunks/chunk-AFU5E5QB.js +714 -0
- package/dist/chunks/chunk-DJ2IUQEU.js +111 -0
- package/dist/chunks/chunk-E7JHLNLG.js +187 -0
- package/dist/chunks/chunk-FHKSLCVW.js +154 -0
- package/dist/chunks/chunk-FKH5N47I.js +40 -0
- package/dist/chunks/chunk-HZCTYL22.js +29 -0
- package/dist/chunks/chunk-IPUYZD4O.js +25 -0
- package/dist/chunks/chunk-IVH3NMQZ.js +61 -0
- package/dist/chunks/chunk-LVYG7XZJ.js +45 -0
- package/dist/chunks/chunk-NAKXLBA6.js +30 -0
- package/dist/chunks/chunk-NAWZ73QS.js +22 -0
- package/dist/chunks/chunk-PMSSUWD7.js +636 -0
- package/dist/chunks/chunk-PURHK3JU.js +432 -0
- package/dist/chunks/chunk-R3Y56YVF.js +43 -0
- package/dist/chunks/chunk-RCZ7ZZFU.js +92 -0
- package/dist/chunks/chunk-SBIZDCRY.js +106 -0
- package/dist/chunks/chunk-U2D34ARZ.js +41 -0
- package/dist/chunks/chunk-UAT3JSJZ.js +331 -0
- package/dist/chunks/chunk-VQSCHOBV.js +111 -0
- package/dist/chunks/chunk-XC6CZP73.js +80 -0
- package/dist/chunks/chunk-XNFESPZH.js +2307 -0
- package/dist/chunks/chunk-YOTW5ESM.js +118 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +35 -0
- package/dist/cli/commands.d.ts +19 -0
- package/dist/cli/config.d.ts +22 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.js +30 -0
- package/dist/cli/mcp.d.ts +14 -0
- package/dist/cli/stdio.d.ts +9 -0
- package/dist/clients/index.d.ts +2 -0
- package/dist/clients/index.js +117 -0
- package/dist/clients/plugin.d.ts +42 -0
- package/dist/combine/account.d.ts +4 -0
- package/dist/combine/adapter.d.ts +9 -0
- package/dist/combine/index.d.ts +2 -0
- package/dist/combine/index.js +420 -0
- package/dist/combine/route.d.ts +24 -0
- package/dist/exporter/index.d.ts +29 -0
- package/dist/exporter/index.js +77 -0
- package/dist/failover/index.d.ts +11 -0
- package/dist/failover/index.js +45 -0
- package/dist/fixtures/index.d.ts +27 -0
- package/dist/fixtures/index.js +260 -0
- package/dist/fixtures/scrub.d.ts +5 -0
- package/dist/heyreach/account.d.ts +11 -0
- package/dist/heyreach/adapter.d.ts +5 -0
- package/dist/heyreach/capabilities.d.ts +70 -0
- package/dist/heyreach/client.d.ts +18 -0
- package/dist/heyreach/inbox.d.ts +7 -0
- package/dist/heyreach/index.d.ts +25 -0
- package/dist/heyreach/index.js +1931 -0
- package/dist/heyreach/leads.d.ts +4 -0
- package/dist/heyreach/lookup.d.ts +15 -0
- package/dist/heyreach/map-account.d.ts +31 -0
- package/dist/heyreach/map-sequence.d.ts +5 -0
- package/dist/heyreach/map-stats.d.ts +13 -0
- package/dist/heyreach/map.d.ts +37 -0
- package/dist/heyreach/native-organization.d.ts +128 -0
- package/dist/heyreach/native-voice.d.ts +106 -0
- package/dist/heyreach/native.d.ts +496 -0
- package/dist/heyreach/paging.d.ts +7 -0
- package/dist/heyreach/webhooks.d.ts +3 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +159 -0
- package/dist/identity/keys.d.ts +9 -0
- package/dist/identity/plugin.d.ts +34 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +131 -0
- package/dist/insights/copy/copy-audit.d.ts +55 -0
- package/dist/insights/copy/copy-checks.d.ts +44 -0
- package/dist/insights/copy/copy-reuse.d.ts +59 -0
- package/dist/insights/copy/index.d.ts +67 -0
- package/dist/insights/copy/reply-timing.d.ts +63 -0
- package/dist/insights/copy/shared.d.ts +53 -0
- package/dist/insights/copy/step-funnel.d.ts +66 -0
- package/dist/insights/copy/variant-test.d.ts +64 -0
- package/dist/insights/define.d.ts +98 -0
- package/dist/insights/index.d.ts +10 -0
- package/dist/insights/index.js +4937 -0
- package/dist/insights/ops/anomalies.d.ts +80 -0
- package/dist/insights/ops/campaign-diagnosis.d.ts +39 -0
- package/dist/insights/ops/campaign-ranking.d.ts +56 -0
- package/dist/insights/ops/channel-mix.d.ts +44 -0
- package/dist/insights/ops/client-report.d.ts +76 -0
- package/dist/insights/ops/diagnosis-checks.d.ts +48 -0
- package/dist/insights/ops/index.d.ts +135 -0
- package/dist/insights/ops/period-comparison.d.ts +86 -0
- package/dist/insights/ops/pipeline-forecast.d.ts +44 -0
- package/dist/insights/ops/shared.d.ts +155 -0
- package/dist/insights/ops/tag-rollup.d.ts +32 -0
- package/dist/insights/people/account-summary.d.ts +68 -0
- package/dist/insights/people/dropped-replies.d.ts +51 -0
- package/dist/insights/people/find.d.ts +18 -0
- package/dist/insights/people/hot-leads.d.ts +67 -0
- package/dist/insights/people/index.d.ts +88 -0
- package/dist/insights/people/lead-collisions.d.ts +43 -0
- package/dist/insights/people/person-summary.d.ts +46 -0
- package/dist/insights/people/personalization-gaps.d.ts +60 -0
- package/dist/insights/people/read.d.ts +40 -0
- package/dist/insights/people/suppression-check.d.ts +53 -0
- package/dist/insights/plugin.d.ts +40 -0
- package/dist/insights/registry.d.ts +335 -0
- package/dist/insights/senders/bounce-watch.d.ts +70 -0
- package/dist/insights/senders/domain-health.d.ts +69 -0
- package/dist/insights/senders/index.d.ts +74 -0
- package/dist/insights/senders/read.d.ts +37 -0
- package/dist/insights/senders/sender-capacity.d.ts +67 -0
- package/dist/insights/senders/sender-load.d.ts +52 -0
- package/dist/insights/senders/settings-audit.d.ts +48 -0
- package/dist/insights/senders/warmup-readiness.d.ts +39 -0
- package/dist/insights/stats.d.ts +45 -0
- package/dist/insights/tools.d.ts +16 -0
- package/dist/insights/types.d.ts +4 -0
- package/dist/instantly/adapter-account.d.ts +5 -0
- package/dist/instantly/adapter-mail.d.ts +3 -0
- package/dist/instantly/adapter.d.ts +7 -0
- package/dist/instantly/capabilities.d.ts +85 -0
- package/dist/instantly/client.d.ts +24 -0
- package/dist/instantly/index.d.ts +27 -0
- package/dist/instantly/index.js +2627 -0
- package/dist/instantly/map-account.d.ts +38 -0
- package/dist/instantly/map-lead.d.ts +18 -0
- package/dist/instantly/map-stats.d.ts +25 -0
- package/dist/instantly/map.d.ts +22 -0
- package/dist/instantly/native-agents-sales.d.ts +161 -0
- package/dist/instantly/native-agents.d.ts +156 -0
- package/dist/instantly/native-campaigns.d.ts +101 -0
- package/dist/instantly/native-leads.d.ts +93 -0
- package/dist/instantly/native-params.d.ts +7 -0
- package/dist/instantly/native-search.d.ts +82 -0
- package/dist/instantly/native-senders.d.ts +182 -0
- package/dist/instantly/native-supersearch.d.ts +149 -0
- package/dist/instantly/native-workspace.d.ts +170 -0
- package/dist/instantly/native.d.ts +1081 -0
- package/dist/instantly/pages.d.ts +29 -0
- package/dist/instantly/stats.d.ts +5 -0
- package/dist/instantly/webhooks.d.ts +3 -0
- package/dist/internal/adapter.d.ts +211 -0
- package/dist/internal/capabilities.d.ts +104 -0
- package/dist/internal/client.d.ts +15 -0
- package/dist/internal/concurrency.d.ts +8 -0
- package/dist/internal/cursor.d.ts +10 -0
- package/dist/internal/engine/budget.d.ts +44 -0
- package/dist/internal/engine/engine.d.ts +45 -0
- package/dist/internal/engine/rate-store.d.ts +25 -0
- package/dist/internal/engine/request.d.ts +34 -0
- package/dist/internal/engine/retry.d.ts +21 -0
- package/dist/internal/engine/runtime.d.ts +13 -0
- package/dist/internal/entities-account.d.ts +205 -0
- package/dist/internal/entities.d.ts +493 -0
- package/dist/internal/env.d.ts +4 -0
- package/dist/internal/errors.d.ts +62 -0
- package/dist/internal/fields.d.ts +462 -0
- package/dist/internal/hooks.d.ts +55 -0
- package/dist/internal/json.d.ts +49 -0
- package/dist/internal/lead-fields.d.ts +21 -0
- package/dist/internal/lead-status.d.ts +13 -0
- package/dist/internal/limits.d.ts +34 -0
- package/dist/internal/metrics.d.ts +64 -0
- package/dist/internal/native.d.ts +81 -0
- package/dist/internal/outbound/api.d.ts +292 -0
- package/dist/internal/outbound/collections.d.ts +31 -0
- package/dist/internal/outbound/core.d.ts +36 -0
- package/dist/internal/outbound/create.d.ts +16 -0
- package/dist/internal/outbound/handles.d.ts +7 -0
- package/dist/internal/outbound/native.d.ts +4 -0
- package/dist/internal/outbound/operation-shared.d.ts +28 -0
- package/dist/internal/outbound/operations-account.d.ts +41 -0
- package/dist/internal/outbound/operations.d.ts +42 -0
- package/dist/internal/outbound/outbound.d.ts +67 -0
- package/dist/internal/outbound/plugins.d.ts +40 -0
- package/dist/internal/outbound/raw.d.ts +9 -0
- package/dist/internal/outbound/specs-account.d.ts +20 -0
- package/dist/internal/outbound/specs.d.ts +14 -0
- package/dist/internal/outbound/stats.d.ts +7 -0
- package/dist/internal/outbound/validate.d.ts +5 -0
- package/dist/internal/outbound/walker.d.ts +22 -0
- package/dist/internal/page.d.ts +14 -0
- package/dist/internal/record.d.ts +36 -0
- package/dist/internal/records.d.ts +7 -0
- package/dist/internal/redact.d.ts +18 -0
- package/dist/internal/ref.d.ts +16 -0
- package/dist/internal/sequence.d.ts +14 -0
- package/dist/internal/sha256.d.ts +6 -0
- package/dist/internal/text.d.ts +11 -0
- package/dist/internal/url.d.ts +9 -0
- package/dist/loader/index.d.ts +24 -0
- package/dist/loader/index.js +16 -0
- package/dist/memory/account-reads.d.ts +5 -0
- package/dist/memory/account.d.ts +81 -0
- package/dist/memory/adapter.d.ts +16 -0
- package/dist/memory/data.d.ts +137 -0
- package/dist/memory/demo.d.ts +7 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.js +867 -0
- package/dist/memory/stats.d.ts +6 -0
- package/dist/memory/store.d.ts +18 -0
- package/dist/providers/index.d.ts +22 -0
- package/dist/providers/index.js +10 -0
- package/dist/reconcile/index.d.ts +2 -0
- package/dist/reconcile/index.js +72 -0
- package/dist/reconcile/plugin.d.ts +55 -0
- package/dist/redact/index.d.ts +2 -0
- package/dist/redact/index.js +197 -0
- package/dist/redact/plugin.d.ts +22 -0
- package/dist/redis/index.d.ts +41 -0
- package/dist/redis/index.js +114 -0
- package/dist/smartlead/account.d.ts +5 -0
- package/dist/smartlead/adapter.d.ts +5 -0
- package/dist/smartlead/capabilities.d.ts +87 -0
- package/dist/smartlead/client.d.ts +18 -0
- package/dist/smartlead/hmac.d.ts +7 -0
- package/dist/smartlead/index.d.ts +24 -0
- package/dist/smartlead/index.js +2329 -0
- package/dist/smartlead/leads.d.ts +9 -0
- package/dist/smartlead/lookup.d.ts +8 -0
- package/dist/smartlead/mail.d.ts +5 -0
- package/dist/smartlead/map-account.d.ts +34 -0
- package/dist/smartlead/map-messages.d.ts +31 -0
- package/dist/smartlead/map-stats.d.ts +36 -0
- package/dist/smartlead/map.d.ts +62 -0
- package/dist/smartlead/native-analytics.d.ts +242 -0
- package/dist/smartlead/native-campaigns.d.ts +211 -0
- package/dist/smartlead/native-inbox.d.ts +141 -0
- package/dist/smartlead/native-params.d.ts +12 -0
- package/dist/smartlead/native-services.d.ts +204 -0
- package/dist/smartlead/native.d.ts +785 -0
- package/dist/smartlead/shared.d.ts +29 -0
- package/dist/smartlead/stats.d.ts +5 -0
- package/dist/smartlead/webhooks.d.ts +3 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +158 -0
- package/dist/sync/plugin.d.ts +58 -0
- package/dist/tools/account-tools.d.ts +21 -0
- package/dist/tools/ai-sdk.d.ts +8 -0
- package/dist/tools/ai-sdk.js +28 -0
- package/dist/tools/campaign-tools.d.ts +59 -0
- package/dist/tools/claude-agent.d.ts +18 -0
- package/dist/tools/claude-agent.js +42 -0
- package/dist/tools/index.d.ts +28 -0
- package/dist/tools/index.js +22 -0
- package/dist/tools/people-tools.d.ts +19 -0
- package/dist/tools/registry.d.ts +34 -0
- package/dist/tools/shared.d.ts +75 -0
- package/dist/tracing/index.d.ts +25 -0
- package/dist/tracing/index.js +69 -0
- package/dist/webhooks/index.d.ts +3 -0
- package/dist/webhooks/index.js +227 -0
- package/dist/webhooks/parse.d.ts +41 -0
- package/dist/webhooks/secret.d.ts +4 -0
- package/package.json +181 -4
|
@@ -0,0 +1,4937 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mapConcurrent
|
|
3
|
+
} from "../chunks/chunk-HZCTYL22.js";
|
|
4
|
+
import {
|
|
5
|
+
sumCounts
|
|
6
|
+
} from "../chunks/chunk-YOTW5ESM.js";
|
|
7
|
+
import {
|
|
8
|
+
profileSlug
|
|
9
|
+
} from "../chunks/chunk-NAWZ73QS.js";
|
|
10
|
+
import {
|
|
11
|
+
campaignStatusSchema,
|
|
12
|
+
replyCategorySchema
|
|
13
|
+
} from "../chunks/chunk-4PSO6JEK.js";
|
|
14
|
+
import "../chunks/chunk-LVYG7XZJ.js";
|
|
15
|
+
import {
|
|
16
|
+
OutboundError
|
|
17
|
+
} from "../chunks/chunk-E7JHLNLG.js";
|
|
18
|
+
import {
|
|
19
|
+
toJson,
|
|
20
|
+
unknownKey
|
|
21
|
+
} from "../chunks/chunk-VQSCHOBV.js";
|
|
22
|
+
|
|
23
|
+
// src/insights/plugin.ts
|
|
24
|
+
import { z as z31 } from "zod";
|
|
25
|
+
|
|
26
|
+
// src/insights/copy/copy-audit.ts
|
|
27
|
+
import { z } from "zod";
|
|
28
|
+
|
|
29
|
+
// src/insights/define.ts
|
|
30
|
+
var RANK = {
|
|
31
|
+
derived: 2,
|
|
32
|
+
exact: 0,
|
|
33
|
+
sampled: 1
|
|
34
|
+
};
|
|
35
|
+
var track = (outbound, now) => {
|
|
36
|
+
const notes = [];
|
|
37
|
+
let requests = 0;
|
|
38
|
+
let evidence = "exact";
|
|
39
|
+
let complete = true;
|
|
40
|
+
const seen = (meta) => {
|
|
41
|
+
if (meta === void 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
requests += meta.requests;
|
|
45
|
+
evidence = RANK[meta.evidence] > RANK[evidence] ? meta.evidence : evidence;
|
|
46
|
+
};
|
|
47
|
+
const note = (text) => {
|
|
48
|
+
if (!notes.includes(text)) {
|
|
49
|
+
notes.push(text);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const partial = (reason) => {
|
|
53
|
+
complete = false;
|
|
54
|
+
note(reason);
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
context: {
|
|
58
|
+
all: async (walk, cap) => {
|
|
59
|
+
const items = await walk.toArray();
|
|
60
|
+
seen(walk.meta);
|
|
61
|
+
if (walk.truncated) {
|
|
62
|
+
partial(
|
|
63
|
+
cap === void 0 ? "A listing was cut off at its cap; more records exist." : `Stopped at ${cap}; more exist.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return items;
|
|
67
|
+
},
|
|
68
|
+
note,
|
|
69
|
+
now,
|
|
70
|
+
one: (item) => {
|
|
71
|
+
seen(item.meta);
|
|
72
|
+
return item;
|
|
73
|
+
},
|
|
74
|
+
outbound,
|
|
75
|
+
page: (page) => {
|
|
76
|
+
seen(page.meta);
|
|
77
|
+
if (!page.complete) {
|
|
78
|
+
partial("Only the first page of a listing was read.");
|
|
79
|
+
}
|
|
80
|
+
return page.items;
|
|
81
|
+
},
|
|
82
|
+
partial,
|
|
83
|
+
rows: (stats) => {
|
|
84
|
+
seen(stats.meta);
|
|
85
|
+
return stats.rows;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
meta: () => ({ complete, evidence, notes: [...notes], requests })
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var missing = (outbound, needs) => needs.filter((key) => outbound.capabilities[key] === false);
|
|
92
|
+
var prepare = (outbound, spec, input27) => {
|
|
93
|
+
const stray = unknownKey(Object.keys(spec.inputSchema.shape), input27);
|
|
94
|
+
if (stray !== void 0) {
|
|
95
|
+
throw new OutboundError("Invalid", `${spec.name}: ${stray}`, {
|
|
96
|
+
provider: outbound.provider
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const parsed = spec.inputSchema.safeParse(input27 ?? {});
|
|
100
|
+
if (!parsed.success) {
|
|
101
|
+
const [issue] = parsed.error.issues;
|
|
102
|
+
throw new OutboundError(
|
|
103
|
+
"Invalid",
|
|
104
|
+
`${spec.name}: ${issue?.path.join(".") || "input"} ${issue?.message ?? "is invalid"}`,
|
|
105
|
+
{ provider: outbound.provider }
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
const absent = missing(outbound, spec.needs);
|
|
109
|
+
const forInput = missing(outbound, spec.needsFor?.(parsed.data) ?? []);
|
|
110
|
+
if (absent.length > 0 || forInput.length > 0) {
|
|
111
|
+
throw new OutboundError(
|
|
112
|
+
"Unsupported",
|
|
113
|
+
`${spec.name} is not available${absent.length > 0 ? "" : " for this input"}: the ${outbound.provider} adapter does not support ${[.../* @__PURE__ */ new Set([...absent, ...forInput])].join(", ")}`,
|
|
114
|
+
{ provider: outbound.provider }
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return parsed.data;
|
|
118
|
+
};
|
|
119
|
+
var execute = async (outbound, spec, input27, options = {}) => {
|
|
120
|
+
const checked = prepare(outbound, spec, input27);
|
|
121
|
+
const now = options.now ?? Date.now();
|
|
122
|
+
const tracker = track(outbound, now);
|
|
123
|
+
const data = await spec.run(tracker.context, checked);
|
|
124
|
+
return {
|
|
125
|
+
data,
|
|
126
|
+
insight: spec.name,
|
|
127
|
+
meta: {
|
|
128
|
+
...tracker.meta(),
|
|
129
|
+
computedAt: new Date(now).toISOString(),
|
|
130
|
+
provider: outbound.provider
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
var defineInsight = (spec) => ({
|
|
135
|
+
...spec,
|
|
136
|
+
execute: async (outbound, input27, options) => {
|
|
137
|
+
const result = await execute(outbound, spec, input27, options);
|
|
138
|
+
return { ...result, data: toJson(result.data) };
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
var runInsight = (outbound, definition, input27, options = {}) => (
|
|
142
|
+
// SAFETY: an insight's input is a plain object of JSON values, and it is parsed before use.
|
|
143
|
+
execute(outbound, definition, input27, options)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// src/insights/copy/copy-checks.ts
|
|
147
|
+
var CHECKS = {
|
|
148
|
+
all_caps: "low",
|
|
149
|
+
body_too_long: "low",
|
|
150
|
+
connection_request_too_long: "high",
|
|
151
|
+
exclamation_marks: "low",
|
|
152
|
+
image: "medium",
|
|
153
|
+
malformed_variable: "high",
|
|
154
|
+
missing_subject: "high",
|
|
155
|
+
spam_words: "medium",
|
|
156
|
+
subject_breaks_thread: "medium",
|
|
157
|
+
subject_too_long: "low",
|
|
158
|
+
too_many_links: "medium"
|
|
159
|
+
};
|
|
160
|
+
var DEFAULT_SPAM_WORDS = [
|
|
161
|
+
"100% free",
|
|
162
|
+
"act now",
|
|
163
|
+
"buy now",
|
|
164
|
+
"cash bonus",
|
|
165
|
+
"click here",
|
|
166
|
+
"double your",
|
|
167
|
+
"earn money",
|
|
168
|
+
"free trial",
|
|
169
|
+
"guarantee",
|
|
170
|
+
"limited time",
|
|
171
|
+
"no obligation",
|
|
172
|
+
"risk-free",
|
|
173
|
+
"urgent",
|
|
174
|
+
"winner"
|
|
175
|
+
];
|
|
176
|
+
var TAG = /<[^>]+>/gu;
|
|
177
|
+
var IMAGE = /<img\b[^>]*>/giu;
|
|
178
|
+
var VARIABLE = /\{\{[^{}]*\}\}/gu;
|
|
179
|
+
var LINK = /\b(?:https?:\/\/|www\.)[^\s"'<>)]+/giu;
|
|
180
|
+
var CAPS_WORD = /\b[A-Z]{4,}\b/gu;
|
|
181
|
+
var PIXEL = /(?:width|height)\s*[=:]\s*["']?[01](?:px)?\b|pixel|track/iu;
|
|
182
|
+
var REPLY_PREFIX = /^(?:re|fwd?)\s*:\s*/iu;
|
|
183
|
+
var SNIPPET = 80;
|
|
184
|
+
var clip = (text) => text.length > SNIPPET ? `${text.slice(0, SNIPPET)}\u2026` : text;
|
|
185
|
+
var visible = (text) => text.replaceAll(TAG, " ").replaceAll(VARIABLE, " variable ");
|
|
186
|
+
var wordsOf = (text) => visible(text).split(/\s+/u).filter((word) => word !== "");
|
|
187
|
+
var escape = (text) => text.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`);
|
|
188
|
+
var subjectTooLong = (subject, limits) => subject.length > limits.maxSubjectChars ? {
|
|
189
|
+
check: "subject_too_long",
|
|
190
|
+
finding: `The subject is ${subject.length} characters; the limit is ${limits.maxSubjectChars}.`,
|
|
191
|
+
text: clip(subject)
|
|
192
|
+
} : null;
|
|
193
|
+
var bodyTooLong = (body, limits) => {
|
|
194
|
+
const words = wordsOf(body);
|
|
195
|
+
return words.length > limits.maxBodyWords ? {
|
|
196
|
+
check: "body_too_long",
|
|
197
|
+
finding: `The body is ${words.length} words; the limit is ${limits.maxBodyWords}.`,
|
|
198
|
+
text: clip(words.slice(0, 12).join(" "))
|
|
199
|
+
} : null;
|
|
200
|
+
};
|
|
201
|
+
var tooManyLinks = (body, limits) => {
|
|
202
|
+
const links = body.replaceAll(IMAGE, " ").match(LINK) ?? [];
|
|
203
|
+
return links.length > limits.maxLinks ? {
|
|
204
|
+
check: "too_many_links",
|
|
205
|
+
finding: `The body has ${links.length} links; the limit is ${limits.maxLinks}.`,
|
|
206
|
+
text: clip(links.join(" "))
|
|
207
|
+
} : null;
|
|
208
|
+
};
|
|
209
|
+
var spamWords = (text, limits) => {
|
|
210
|
+
const plain = visible(text);
|
|
211
|
+
const hits = limits.spamWords.filter(
|
|
212
|
+
(word) => word.trim() !== "" && new RegExp(
|
|
213
|
+
String.raw`(?<![\w])${escape(word.trim())}(?![\w])`,
|
|
214
|
+
"iu"
|
|
215
|
+
).test(plain)
|
|
216
|
+
);
|
|
217
|
+
return hits.length > 0 ? {
|
|
218
|
+
check: "spam_words",
|
|
219
|
+
finding: `The copy uses ${hits.length} word(s) or phrase(s) that spam filters weigh.`,
|
|
220
|
+
text: hits.join(", ")
|
|
221
|
+
} : null;
|
|
222
|
+
};
|
|
223
|
+
var malformedVariable = (text) => {
|
|
224
|
+
const empty = (text.match(VARIABLE) ?? []).filter(
|
|
225
|
+
(token) => token.slice(2, -2).trim() === ""
|
|
226
|
+
);
|
|
227
|
+
const rest = text.replaceAll(VARIABLE, "");
|
|
228
|
+
const stray = /\{\{|\}\}/u.exec(rest);
|
|
229
|
+
if (stray === null && empty.length === 0) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
check: "malformed_variable",
|
|
234
|
+
finding: stray === null ? "A variable has no name between its braces, so it sends as blank or as raw braces." : "A variable's braces are not balanced, so it sends as raw text.",
|
|
235
|
+
text: stray === null ? empty[0] ?? "" : clip(
|
|
236
|
+
rest.slice(Math.max(0, stray.index - 20), stray.index + 30).trim()
|
|
237
|
+
)
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
var allCaps = (text, limits) => {
|
|
241
|
+
const words = text.replaceAll(TAG, " ").replaceAll(VARIABLE, " ").match(CAPS_WORD);
|
|
242
|
+
const found = words ?? [];
|
|
243
|
+
return found.length > limits.maxCapsWords ? {
|
|
244
|
+
check: "all_caps",
|
|
245
|
+
finding: `${found.length} word(s) of four or more letters are in capitals; the limit is ${limits.maxCapsWords}.`,
|
|
246
|
+
text: clip(found.join(" "))
|
|
247
|
+
} : null;
|
|
248
|
+
};
|
|
249
|
+
var exclamationMarks = (text, limits) => {
|
|
250
|
+
const marks = visible(text).split("!").length - 1;
|
|
251
|
+
return marks > limits.maxExclamations ? {
|
|
252
|
+
check: "exclamation_marks",
|
|
253
|
+
finding: `The copy has ${marks} exclamation marks; the limit is ${limits.maxExclamations}.`,
|
|
254
|
+
text: "!".repeat(marks)
|
|
255
|
+
} : null;
|
|
256
|
+
};
|
|
257
|
+
var image = (body) => {
|
|
258
|
+
const [first] = body.match(IMAGE) ?? [];
|
|
259
|
+
if (first === void 0) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
check: "image",
|
|
264
|
+
finding: PIXEL.test(first) ? "The body holds a tracking pixel, which spam filters and privacy tools flag." : "The body holds an image, which cold email filters weigh against.",
|
|
265
|
+
text: clip(first)
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
var threadKey = (subject) => (subject ?? "").trim().replace(REPLY_PREFIX, "").trim().toLowerCase();
|
|
269
|
+
var connectionTooLong = (body, limits) => body.length > limits.maxConnectionChars ? {
|
|
270
|
+
check: "connection_request_too_long",
|
|
271
|
+
finding: `The connection request is ${body.length} characters; LinkedIn cuts it at ${limits.maxConnectionChars}.`,
|
|
272
|
+
text: clip(body)
|
|
273
|
+
} : null;
|
|
274
|
+
|
|
275
|
+
// src/insights/copy/copy-audit.ts
|
|
276
|
+
var limit = (fallback, description) => z.number().int().min(0).default(fallback).describe(description);
|
|
277
|
+
var input = z.object({
|
|
278
|
+
campaign: z.string().min(1).describe("The campaign's ref, for example `instantly:acme:abc123`"),
|
|
279
|
+
max_body_words: limit(150, "The most words a body may have."),
|
|
280
|
+
max_caps_words: limit(
|
|
281
|
+
1,
|
|
282
|
+
"How many words of four or more letters may be in capitals, so one acronym is not a finding."
|
|
283
|
+
),
|
|
284
|
+
max_connection_chars: limit(
|
|
285
|
+
300,
|
|
286
|
+
"The most characters a LinkedIn connection request may have."
|
|
287
|
+
),
|
|
288
|
+
max_exclamations: limit(1, "How many exclamation marks a message may have."),
|
|
289
|
+
max_links: limit(1, "The most links an email body may have."),
|
|
290
|
+
max_subject_chars: limit(60, "The most characters a subject may have."),
|
|
291
|
+
spam_words: z.array(z.string().min(1)).default([...DEFAULT_SPAM_WORDS]).describe(
|
|
292
|
+
"Words and phrases to flag in email copy, matched whole and without case. Replaces the default list."
|
|
293
|
+
)
|
|
294
|
+
});
|
|
295
|
+
var RANK2 = { high: 0, low: 2, medium: 1 };
|
|
296
|
+
var EMAIL_ONLY = [
|
|
297
|
+
"image",
|
|
298
|
+
"missing_subject",
|
|
299
|
+
"spam_words",
|
|
300
|
+
"subject_breaks_thread",
|
|
301
|
+
"subject_too_long",
|
|
302
|
+
"too_many_links"
|
|
303
|
+
];
|
|
304
|
+
var LINKEDIN_ONLY = ["connection_request_too_long"];
|
|
305
|
+
var emailChecks = (step, variant, limits, thread) => {
|
|
306
|
+
const subject = variant.subject?.trim() ?? "";
|
|
307
|
+
const body = variant.body ?? "";
|
|
308
|
+
const key = threadKey(subject);
|
|
309
|
+
const problems = [
|
|
310
|
+
subject === "" ? null : subjectTooLong(subject, limits),
|
|
311
|
+
spamWords(`${subject}
|
|
312
|
+
${body}`, limits),
|
|
313
|
+
tooManyLinks(body, limits),
|
|
314
|
+
image(body)
|
|
315
|
+
];
|
|
316
|
+
if (step.index === thread.first && subject === "") {
|
|
317
|
+
problems.push({
|
|
318
|
+
check: "missing_subject",
|
|
319
|
+
finding: "The first email has no subject.",
|
|
320
|
+
text: ""
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (step.index !== thread.first && key !== "" && !thread.subjects.has(key)) {
|
|
324
|
+
problems.push({
|
|
325
|
+
check: "subject_breaks_thread",
|
|
326
|
+
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.",
|
|
327
|
+
text: subject
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return problems;
|
|
331
|
+
};
|
|
332
|
+
var linkedinChecks = (step, variant, limits) => step.action.toLowerCase().includes("connect") && variant.body !== null ? [connectionTooLong(variant.body, limits)] : [];
|
|
333
|
+
var auditVariant = (step, variant, limits, thread) => {
|
|
334
|
+
const body = variant.body ?? "";
|
|
335
|
+
const whole = `${variant.subject ?? ""}
|
|
336
|
+
${body}`;
|
|
337
|
+
const problems = [
|
|
338
|
+
malformedVariable(whole),
|
|
339
|
+
bodyTooLong(body, limits),
|
|
340
|
+
allCaps(whole, limits),
|
|
341
|
+
exclamationMarks(whole, limits),
|
|
342
|
+
...thread === null ? linkedinChecks(step, variant, limits) : emailChecks(step, variant, limits, thread)
|
|
343
|
+
];
|
|
344
|
+
return problems.flatMap(
|
|
345
|
+
(problem) => problem === null ? [] : [
|
|
346
|
+
{
|
|
347
|
+
...problem,
|
|
348
|
+
action: step.action,
|
|
349
|
+
severity: CHECKS[problem.check],
|
|
350
|
+
step: step.index,
|
|
351
|
+
variantKey: variant.variantKey
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
);
|
|
355
|
+
};
|
|
356
|
+
var threadOf = (steps) => {
|
|
357
|
+
const [first] = steps.toSorted((left, right) => left.index - right.index);
|
|
358
|
+
return {
|
|
359
|
+
first: first?.index ?? null,
|
|
360
|
+
subjects: new Set(
|
|
361
|
+
(first?.variants ?? []).flatMap((variant) => {
|
|
362
|
+
const key = threadKey(variant.subject);
|
|
363
|
+
return key === "" ? [] : [key];
|
|
364
|
+
})
|
|
365
|
+
)
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
var CHECK_NAMES = Object.keys(CHECKS);
|
|
369
|
+
var countsOf = (findings, isEmail) => CHECK_NAMES.filter(
|
|
370
|
+
(check) => !(isEmail ? LINKEDIN_ONLY : EMAIL_ONLY).includes(check)
|
|
371
|
+
).map((check) => ({
|
|
372
|
+
check,
|
|
373
|
+
count: findings.filter((finding) => finding.check === check).length,
|
|
374
|
+
severity: CHECKS[check]
|
|
375
|
+
})).toSorted(
|
|
376
|
+
(left, right) => right.count - left.count || RANK2[left.severity] - RANK2[right.severity] || left.check.localeCompare(right.check)
|
|
377
|
+
);
|
|
378
|
+
var copyAudit = defineInsight({
|
|
379
|
+
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.",
|
|
380
|
+
inputSchema: input,
|
|
381
|
+
key: "copyAudit",
|
|
382
|
+
name: "copy_audit",
|
|
383
|
+
needs: ["sequence"],
|
|
384
|
+
next: "Use step_funnel to see whether the steps with findings are also the ones with few replies.",
|
|
385
|
+
run: async (context, args) => {
|
|
386
|
+
const handle = context.outbound.campaign(args.campaign);
|
|
387
|
+
const campaign = context.one(await handle.get());
|
|
388
|
+
const sequence2 = context.one(await handle.sequence());
|
|
389
|
+
const isEmail = campaign.channel === "email";
|
|
390
|
+
const limits = {
|
|
391
|
+
maxBodyWords: args.max_body_words,
|
|
392
|
+
maxCapsWords: args.max_caps_words,
|
|
393
|
+
maxConnectionChars: args.max_connection_chars,
|
|
394
|
+
maxExclamations: args.max_exclamations,
|
|
395
|
+
maxLinks: args.max_links,
|
|
396
|
+
maxSubjectChars: args.max_subject_chars,
|
|
397
|
+
spamWords: args.spam_words
|
|
398
|
+
};
|
|
399
|
+
const thread = isEmail ? threadOf(sequence2.steps) : null;
|
|
400
|
+
const variants = sequence2.steps.flatMap(
|
|
401
|
+
(step) => step.variants.map((variant) => ({ step, variant }))
|
|
402
|
+
);
|
|
403
|
+
const findings = variants.flatMap(
|
|
404
|
+
({ step, variant }) => auditVariant(step, variant, limits, thread)
|
|
405
|
+
).toSorted(
|
|
406
|
+
(left, right) => RANK2[left.severity] - RANK2[right.severity] || left.step - right.step || left.variantKey.localeCompare(right.variantKey) || left.check.localeCompare(right.check)
|
|
407
|
+
);
|
|
408
|
+
const withoutBody = variants.filter(
|
|
409
|
+
({ variant }) => variant.body === null
|
|
410
|
+
).length;
|
|
411
|
+
if (withoutBody > 0) {
|
|
412
|
+
context.note(
|
|
413
|
+
`${withoutBody} variant(s) have no body in the vendor's answer, so their body checks were skipped.`
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
const severity = (level) => findings.filter((finding) => finding.severity === level).length;
|
|
417
|
+
const audit2 = {
|
|
418
|
+
byCheck: countsOf(findings, isEmail),
|
|
419
|
+
bySeverity: {
|
|
420
|
+
high: severity("high"),
|
|
421
|
+
low: severity("low"),
|
|
422
|
+
medium: severity("medium")
|
|
423
|
+
},
|
|
424
|
+
campaign: args.campaign,
|
|
425
|
+
channel: campaign.channel,
|
|
426
|
+
clean: findings.length === 0,
|
|
427
|
+
findings,
|
|
428
|
+
stepsChecked: sequence2.steps.length,
|
|
429
|
+
variantsChecked: variants.length,
|
|
430
|
+
variantsWithoutBody: withoutBody
|
|
431
|
+
};
|
|
432
|
+
return audit2;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// src/insights/copy/copy-reuse.ts
|
|
437
|
+
import { z as z3 } from "zod";
|
|
438
|
+
|
|
439
|
+
// src/insights/stats.ts
|
|
440
|
+
var PLACES = 1e4;
|
|
441
|
+
var round = (value) => value === null || !Number.isFinite(value) ? null : Math.round(value * PLACES) / PLACES;
|
|
442
|
+
var rate = (part, whole) => part === null || whole === null || whole <= 0 ? null : round(part / whole);
|
|
443
|
+
var total = (values) => {
|
|
444
|
+
const known2 = values.filter((value) => value !== null);
|
|
445
|
+
return known2.length === 0 ? null : known2.reduce((sum, value) => sum + value, 0);
|
|
446
|
+
};
|
|
447
|
+
var mean = (values) => values.length === 0 ? null : values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
448
|
+
var percentile = (values, fraction) => {
|
|
449
|
+
if (values.length === 0) {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
const sorted = values.toSorted((left, right) => left - right);
|
|
453
|
+
const position = (sorted.length - 1) * Math.min(Math.max(fraction, 0), 1);
|
|
454
|
+
const below = Math.floor(position);
|
|
455
|
+
const low = sorted[below] ?? 0;
|
|
456
|
+
const high = sorted[Math.ceil(position)] ?? low;
|
|
457
|
+
return low + (high - low) * (position - below);
|
|
458
|
+
};
|
|
459
|
+
var median = (values) => percentile(values, 0.5);
|
|
460
|
+
var deviation = (values) => {
|
|
461
|
+
const center = mean(values);
|
|
462
|
+
if (center === null || values.length < 2) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
const squares = values.reduce((sum, value) => sum + (value - center) ** 2, 0);
|
|
466
|
+
return Math.sqrt(squares / (values.length - 1));
|
|
467
|
+
};
|
|
468
|
+
var zScore = (value, history) => {
|
|
469
|
+
const center = mean(history);
|
|
470
|
+
const spread = deviation(history);
|
|
471
|
+
return center === null || spread === null || spread === 0 ? null : (value - center) / spread;
|
|
472
|
+
};
|
|
473
|
+
var Z_95 = 1.96;
|
|
474
|
+
var wilson = (successes, trials) => {
|
|
475
|
+
if (successes === null || trials === null || trials <= 0) {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
const share2 = Math.min(successes / trials, 1);
|
|
479
|
+
const square = Z_95 ** 2;
|
|
480
|
+
const denominator = 1 + square / trials;
|
|
481
|
+
const center = share2 + square / (2 * trials);
|
|
482
|
+
const margin = Z_95 * Math.sqrt(share2 * (1 - share2) / trials + square / (4 * trials ** 2));
|
|
483
|
+
return {
|
|
484
|
+
high: round(Math.min(1, (center + margin) / denominator)) ?? 1,
|
|
485
|
+
low: round(Math.max(0, (center - margin) / denominator)) ?? 0
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
var erf = (value) => {
|
|
489
|
+
const sign = value < 0 ? -1 : 1;
|
|
490
|
+
const x = Math.abs(value);
|
|
491
|
+
const t = 1 / (1 + 0.3275911 * x);
|
|
492
|
+
const polynomial = ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t;
|
|
493
|
+
return sign * (1 - polynomial * Math.exp(-x * x));
|
|
494
|
+
};
|
|
495
|
+
var compareRates = (first, second, alpha = 0.05) => {
|
|
496
|
+
if (first.successes === null || first.trials === null || second.successes === null || second.trials === null || first.trials <= 0 || second.trials <= 0) {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
const pooled2 = (first.successes + second.successes) / (first.trials + second.trials);
|
|
500
|
+
const error = Math.sqrt(
|
|
501
|
+
pooled2 * (1 - pooled2) * (1 / first.trials + 1 / second.trials)
|
|
502
|
+
);
|
|
503
|
+
if (error === 0) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
const z33 = (first.successes / first.trials - second.successes / second.trials) / error;
|
|
507
|
+
const pValue = 1 - erf(Math.abs(z33) / Math.SQRT2);
|
|
508
|
+
return {
|
|
509
|
+
pValue: round(pValue) ?? 0,
|
|
510
|
+
significant: pValue < alpha,
|
|
511
|
+
z: round(z33) ?? 0
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
var pText = (pValue) => pValue < 1 / PLACES ? `p < ${1 / PLACES}` : `p = ${pValue}`;
|
|
515
|
+
var tally = (values) => {
|
|
516
|
+
const counts = /* @__PURE__ */ new Map();
|
|
517
|
+
for (const value of values) {
|
|
518
|
+
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
519
|
+
}
|
|
520
|
+
return counts;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// src/insights/copy/shared.ts
|
|
524
|
+
import { z as z2 } from "zod";
|
|
525
|
+
var dayInput = (description) => z2.string().regex(/^\d{4}-\d{2}-\d{2}$/u, "must be YYYY-MM-DD").nullable().default(null).describe(description);
|
|
526
|
+
var rangeOf = (from, to) => ({
|
|
527
|
+
from: from ?? void 0,
|
|
528
|
+
to: to ?? void 0
|
|
529
|
+
});
|
|
530
|
+
var readCapped = (context, walk, max) => context.all(walk(max));
|
|
531
|
+
var campaignsIn = async (context, statuses, max) => {
|
|
532
|
+
const { outbound } = context;
|
|
533
|
+
if (outbound.capabilities["campaigns.status"] === false) {
|
|
534
|
+
const every = await readCapped(
|
|
535
|
+
context,
|
|
536
|
+
(cap) => outbound.campaigns.listAll({ max: cap }),
|
|
537
|
+
max
|
|
538
|
+
);
|
|
539
|
+
return every.filter((campaign) => statuses.includes(campaign.status));
|
|
540
|
+
}
|
|
541
|
+
const found = [];
|
|
542
|
+
for (const status of new Set(statuses)) {
|
|
543
|
+
const page = await readCapped(
|
|
544
|
+
context,
|
|
545
|
+
(cap) => outbound.campaigns.listAll({ max: cap, status }),
|
|
546
|
+
max - found.length
|
|
547
|
+
);
|
|
548
|
+
found.push(...page);
|
|
549
|
+
}
|
|
550
|
+
return found;
|
|
551
|
+
};
|
|
552
|
+
var firstKnown = (candidates) => {
|
|
553
|
+
for (const [basis, value] of candidates) {
|
|
554
|
+
if (value !== null && value > 0) {
|
|
555
|
+
return { basis, trials: value };
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return { basis: null, trials: null };
|
|
559
|
+
};
|
|
560
|
+
var perLead = (counts) => firstKnown([
|
|
561
|
+
["contacted", counts.contacted],
|
|
562
|
+
["sent", counts.sent]
|
|
563
|
+
]);
|
|
564
|
+
var perMessage = (counts) => firstKnown([
|
|
565
|
+
["delivered", counts.delivered],
|
|
566
|
+
["sent", counts.sent]
|
|
567
|
+
]);
|
|
568
|
+
var measure = (count, base) => ({
|
|
569
|
+
basis: base.basis,
|
|
570
|
+
count,
|
|
571
|
+
interval: wilson(count, base.trials),
|
|
572
|
+
rate: rate(count, base.trials),
|
|
573
|
+
trials: base.trials
|
|
574
|
+
});
|
|
575
|
+
var sumRows = (rows) => sumCounts(rows);
|
|
576
|
+
var groupBy = (values, keyOf2) => {
|
|
577
|
+
const groups = /* @__PURE__ */ new Map();
|
|
578
|
+
for (const value of values) {
|
|
579
|
+
const key = keyOf2(value);
|
|
580
|
+
const group = groups.get(key);
|
|
581
|
+
if (group === void 0) {
|
|
582
|
+
groups.set(key, [value]);
|
|
583
|
+
} else {
|
|
584
|
+
group.push(value);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return groups;
|
|
588
|
+
};
|
|
589
|
+
var stepStats = (rows) => {
|
|
590
|
+
const whole = rows.filter((row) => row.variantKey === null);
|
|
591
|
+
const variants = new Map(
|
|
592
|
+
[...groupBy(rows, (row) => row.variantKey)].flatMap(
|
|
593
|
+
([key, group]) => key === null ? [] : [[key, sumRows(group)]]
|
|
594
|
+
)
|
|
595
|
+
);
|
|
596
|
+
return {
|
|
597
|
+
total: sumRows(whole.length > 0 ? whole : rows),
|
|
598
|
+
variants
|
|
599
|
+
};
|
|
600
|
+
};
|
|
601
|
+
var splitStats = (rows) => {
|
|
602
|
+
const byStep = groupBy(rows, (row) => row.stepIndex);
|
|
603
|
+
const steps = new Map(
|
|
604
|
+
[...byStep].flatMap(
|
|
605
|
+
([index, group]) => index === null ? [] : [[index, stepStats(group)]]
|
|
606
|
+
)
|
|
607
|
+
);
|
|
608
|
+
return { steps, unattributed: byStep.get(null) ?? [] };
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
// src/insights/copy/copy-reuse.ts
|
|
612
|
+
var input2 = z3.object({
|
|
613
|
+
max_campaigns: z3.number().int().min(1).max(200).default(20).describe(
|
|
614
|
+
"The most campaigns to read. Each costs 2 requests: its sequence and its step stats."
|
|
615
|
+
),
|
|
616
|
+
min_sent: z3.number().int().min(1).default(100).describe(
|
|
617
|
+
"The smallest base (sends, or leads contacted when the vendor counts those) a campaign needs to count in the spread, and a piece of copy needs to be named the best."
|
|
618
|
+
),
|
|
619
|
+
statuses: z3.array(campaignStatusSchema).min(1).default(["active", "paused", "completed"]).describe("The campaign statuses to read.")
|
|
620
|
+
});
|
|
621
|
+
var PREVIEW = 120;
|
|
622
|
+
var placementsOf = (campaign, sequence2, stats) => sequence2.steps.flatMap((step) => {
|
|
623
|
+
const found = stats.steps.get(step.index);
|
|
624
|
+
return step.variants.flatMap((variant) => {
|
|
625
|
+
if ((variant.subject ?? "") === "" && (variant.body ?? "") === "") {
|
|
626
|
+
return [];
|
|
627
|
+
}
|
|
628
|
+
const whole = step.variants.length === 1 ? found?.total ?? null : null;
|
|
629
|
+
return [
|
|
630
|
+
{
|
|
631
|
+
body: variant.body,
|
|
632
|
+
campaign,
|
|
633
|
+
contentHash: variant.contentHash,
|
|
634
|
+
counts: found?.variants.get(variant.variantKey) ?? whole,
|
|
635
|
+
place: `${step.index}:${variant.variantKey}`,
|
|
636
|
+
subject: variant.subject
|
|
637
|
+
}
|
|
638
|
+
];
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
var pooled = (counts) => {
|
|
642
|
+
const measured2 = counts.flatMap((each) => {
|
|
643
|
+
const one = each === null ? null : measure(each.replied, perLead(each));
|
|
644
|
+
return one === null || one.rate === null ? [] : [one];
|
|
645
|
+
});
|
|
646
|
+
const replies2 = total(measured2.map((each) => each.count));
|
|
647
|
+
const trials = total(measured2.map((each) => each.trials));
|
|
648
|
+
return {
|
|
649
|
+
...measure(replies2, { basis: null, trials }),
|
|
650
|
+
sent: total(counts.map((each) => each?.sent ?? null))
|
|
651
|
+
};
|
|
652
|
+
};
|
|
653
|
+
var useOf = (placements) => {
|
|
654
|
+
const [first] = placements;
|
|
655
|
+
if (first === void 0) {
|
|
656
|
+
return [];
|
|
657
|
+
}
|
|
658
|
+
const sum = pooled(placements.map((placement) => placement.counts));
|
|
659
|
+
return [
|
|
660
|
+
{
|
|
661
|
+
campaign: first.campaign.ref,
|
|
662
|
+
campaignName: first.campaign.name,
|
|
663
|
+
places: placements.map((placement) => placement.place),
|
|
664
|
+
provider: first.campaign.provider,
|
|
665
|
+
replies: sum.count,
|
|
666
|
+
replyRate: sum.rate,
|
|
667
|
+
replyRateInterval: sum.interval,
|
|
668
|
+
sent: sum.sent,
|
|
669
|
+
trials: sum.trials
|
|
670
|
+
}
|
|
671
|
+
];
|
|
672
|
+
};
|
|
673
|
+
var pieceOf = (placements, uses) => {
|
|
674
|
+
const [first] = placements;
|
|
675
|
+
if (first === void 0) {
|
|
676
|
+
return [];
|
|
677
|
+
}
|
|
678
|
+
const sum = pooled(placements.map((placement) => placement.counts));
|
|
679
|
+
return [
|
|
680
|
+
{
|
|
681
|
+
bodyPreview: first.body?.slice(0, PREVIEW) ?? null,
|
|
682
|
+
campaigns: uses.length,
|
|
683
|
+
contentHash: first.contentHash,
|
|
684
|
+
replies: sum.count,
|
|
685
|
+
replyRate: sum.rate,
|
|
686
|
+
replyRateInterval: sum.interval,
|
|
687
|
+
sent: sum.sent,
|
|
688
|
+
subject: first.subject,
|
|
689
|
+
trials: sum.trials
|
|
690
|
+
}
|
|
691
|
+
];
|
|
692
|
+
};
|
|
693
|
+
var byRate = (left, right) => (right.replyRate ?? -1) - (left.replyRate ?? -1) || (right.trials ?? 0) - (left.trials ?? 0);
|
|
694
|
+
var spreadOf = (uses, minSent) => {
|
|
695
|
+
const judged = uses.filter(
|
|
696
|
+
(use) => use.replyRate !== null && (use.trials ?? 0) >= minSent
|
|
697
|
+
);
|
|
698
|
+
const [best] = judged;
|
|
699
|
+
const worst = judged.at(-1);
|
|
700
|
+
if (best === void 0 || worst === void 0 || judged.length < 2) {
|
|
701
|
+
return {
|
|
702
|
+
best: null,
|
|
703
|
+
finding: `Fewer than two campaigns have a base of ${minSent}, so the spread is not judged.`,
|
|
704
|
+
spread: null,
|
|
705
|
+
spreadIsReal: null,
|
|
706
|
+
spreadPValue: null,
|
|
707
|
+
worst: null
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
const test = compareRates(
|
|
711
|
+
{ successes: best.replies, trials: best.trials },
|
|
712
|
+
{ successes: worst.replies, trials: worst.trials }
|
|
713
|
+
);
|
|
714
|
+
const real = test?.significant ?? false;
|
|
715
|
+
return {
|
|
716
|
+
best: best.campaign,
|
|
717
|
+
finding: real ? `The same copy gets ${best.replyRate} in ${best.campaignName} and ${worst.replyRate} in ${worst.campaignName}; the gap is more than chance, so the audience or the sender differs, not the copy.` : `The same copy gets ${best.replyRate} in ${best.campaignName} and ${worst.replyRate} in ${worst.campaignName}; a gap this size could be chance.`,
|
|
718
|
+
spread: round((best.replyRate ?? 0) - (worst.replyRate ?? 0)),
|
|
719
|
+
spreadIsReal: real,
|
|
720
|
+
spreadPValue: test?.pValue ?? null,
|
|
721
|
+
worst: worst.campaign
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
var readPlacements = async (context, campaigns) => {
|
|
725
|
+
const perCampaign = await mapConcurrent(campaigns, async (campaign) => {
|
|
726
|
+
const handle = context.outbound.campaign(campaign.ref);
|
|
727
|
+
const [sequence2, stats] = await Promise.all([
|
|
728
|
+
handle.sequence(),
|
|
729
|
+
handle.stats({ scope: "step" })
|
|
730
|
+
]);
|
|
731
|
+
return placementsOf(
|
|
732
|
+
campaign,
|
|
733
|
+
context.one(sequence2),
|
|
734
|
+
splitStats(context.rows(stats))
|
|
735
|
+
);
|
|
736
|
+
});
|
|
737
|
+
return perCampaign.flat();
|
|
738
|
+
};
|
|
739
|
+
var copyReuse = defineInsight({
|
|
740
|
+
description: "How the same piece of copy performs in different campaigns. Reads each campaign's sequence and step stats, matches variants by the hash of their subject and body, and returns every piece of copy used in two or more campaigns with its totals, its reply rate per campaign and the spread between its best and worst campaign, plus the copy with the highest pooled reply rate. Use it to tell a copy problem from an audience problem. Costs 2 requests per campaign plus the campaign listing. A null count means the vendor does not report it for that variant; it is never 0.",
|
|
741
|
+
inputSchema: input2,
|
|
742
|
+
key: "copyReuse",
|
|
743
|
+
name: "copy_reuse",
|
|
744
|
+
needs: ["sequence", "stats.byStep"],
|
|
745
|
+
next: "Use step_funnel on the campaign where the copy does worst, or variant_test where the copy runs against another variant.",
|
|
746
|
+
run: async (context, { max_campaigns, min_sent, statuses }) => {
|
|
747
|
+
const campaigns = await campaignsIn(context, statuses, max_campaigns);
|
|
748
|
+
const placements = await readPlacements(context, campaigns);
|
|
749
|
+
const without = placements.filter((each) => each.counts === null).length;
|
|
750
|
+
if (without > 0) {
|
|
751
|
+
context.note(
|
|
752
|
+
`${without} variant(s) have no counts of their own: the vendor reports their step as a whole, or not at all. Their copy is listed without numbers.`
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
const pieces = [...groupBy(placements, (each) => each.contentHash)].flatMap(
|
|
756
|
+
([, group]) => {
|
|
757
|
+
const uses = [...groupBy(group, (each) => each.campaign.ref).values()].flatMap(useOf).toSorted(byRate);
|
|
758
|
+
return pieceOf(group, uses).map((piece) => ({ piece, uses }));
|
|
759
|
+
}
|
|
760
|
+
);
|
|
761
|
+
const reused = pieces.flatMap(
|
|
762
|
+
({ piece, uses }) => uses.length < 2 ? [] : [{ ...piece, ...spreadOf(uses, min_sent), uses }]
|
|
763
|
+
).toSorted(
|
|
764
|
+
(left, right) => (right.spread ?? -1) - (left.spread ?? -1) || (right.sent ?? 0) - (left.sent ?? 0)
|
|
765
|
+
);
|
|
766
|
+
const [bestCopy] = pieces.flatMap(
|
|
767
|
+
({ piece }) => piece.replyRate !== null && (piece.trials ?? 0) >= min_sent ? [piece] : []
|
|
768
|
+
).toSorted(byRate);
|
|
769
|
+
const result = {
|
|
770
|
+
bestCopy: bestCopy ?? null,
|
|
771
|
+
campaignsRead: campaigns.length,
|
|
772
|
+
piecesOfCopy: pieces.length,
|
|
773
|
+
reused,
|
|
774
|
+
variantsWithoutStats: without
|
|
775
|
+
};
|
|
776
|
+
return result;
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
// src/insights/copy/reply-timing.ts
|
|
781
|
+
import { z as z4 } from "zod";
|
|
782
|
+
var DAY_MS = 864e5;
|
|
783
|
+
var HOUR_MS = 36e5;
|
|
784
|
+
var MINUTE_MS = 6e4;
|
|
785
|
+
var input3 = z4.object({
|
|
786
|
+
campaign: z4.string().min(1).nullable().default(null).describe(
|
|
787
|
+
"A campaign's ref to look at one campaign. null looks at every campaign."
|
|
788
|
+
),
|
|
789
|
+
max_messages: z4.number().int().min(1).max(5e4).default(2e3).describe(
|
|
790
|
+
"The most messages to read, sent and received together. A page of messages costs 1 request."
|
|
791
|
+
),
|
|
792
|
+
since: z4.iso.datetime({ offset: true }).nullable().default(null).describe(
|
|
793
|
+
"Only messages from this time on, ISO 8601. null means 30 days before now."
|
|
794
|
+
),
|
|
795
|
+
timezone_offset_minutes: z4.number().int().min(-720).max(840).default(0).describe(
|
|
796
|
+
"Minutes to add to UTC for the weekday and hour tables, for example -300 for New York in winter."
|
|
797
|
+
)
|
|
798
|
+
});
|
|
799
|
+
var WEEKDAYS = [
|
|
800
|
+
"Sunday",
|
|
801
|
+
"Monday",
|
|
802
|
+
"Tuesday",
|
|
803
|
+
"Wednesday",
|
|
804
|
+
"Thursday",
|
|
805
|
+
"Friday",
|
|
806
|
+
"Saturday"
|
|
807
|
+
];
|
|
808
|
+
var timeOf = (message) => message.sentAt === null ? null : Date.parse(message.sentAt);
|
|
809
|
+
var pair = (messages) => {
|
|
810
|
+
const byThread = /* @__PURE__ */ new Map();
|
|
811
|
+
const byLead = /* @__PURE__ */ new Map();
|
|
812
|
+
const pairs = [];
|
|
813
|
+
const replyTimes = [];
|
|
814
|
+
let followOn = 0;
|
|
815
|
+
let unpaired = 0;
|
|
816
|
+
const timed = messages.flatMap((message) => {
|
|
817
|
+
const at = timeOf(message);
|
|
818
|
+
return at === null ? [] : [{ at, message }];
|
|
819
|
+
}).toSorted((left, right) => left.at - right.at);
|
|
820
|
+
for (const { at, message } of timed) {
|
|
821
|
+
const { leadRef } = message;
|
|
822
|
+
const threadId = message.threadId === null ? null : `${message.provider}:${message.workspaceId}:${message.threadId}`;
|
|
823
|
+
if (message.direction === "out") {
|
|
824
|
+
const sent = { answered: false, at };
|
|
825
|
+
if (threadId !== null) {
|
|
826
|
+
byThread.set(threadId, sent);
|
|
827
|
+
}
|
|
828
|
+
if (leadRef !== null) {
|
|
829
|
+
byLead.set(leadRef, sent);
|
|
830
|
+
}
|
|
831
|
+
} else {
|
|
832
|
+
replyTimes.push(at);
|
|
833
|
+
const sent = (threadId === null ? void 0 : byThread.get(threadId)) ?? (leadRef === null ? void 0 : byLead.get(leadRef));
|
|
834
|
+
if (sent === void 0) {
|
|
835
|
+
unpaired += 1;
|
|
836
|
+
} else if (sent.answered) {
|
|
837
|
+
followOn += 1;
|
|
838
|
+
} else {
|
|
839
|
+
sent.answered = true;
|
|
840
|
+
pairs.push({ at, sentAt: sent.at });
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return { followOn, pairs, replyTimes, unpaired };
|
|
845
|
+
};
|
|
846
|
+
var topOf = (entries) => {
|
|
847
|
+
let top = null;
|
|
848
|
+
for (const entry of entries) {
|
|
849
|
+
if (entry.count > (top?.count ?? 0)) {
|
|
850
|
+
top = entry;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return top;
|
|
854
|
+
};
|
|
855
|
+
var tableOf = (times3, offsetMinutes) => {
|
|
856
|
+
const days = Array.from({ length: 7 }, () => 0);
|
|
857
|
+
const hours = Array.from({ length: 24 }, () => 0);
|
|
858
|
+
for (const time of times3) {
|
|
859
|
+
const local = new Date(time + offsetMinutes * MINUTE_MS);
|
|
860
|
+
days[local.getUTCDay()] = (days[local.getUTCDay()] ?? 0) + 1;
|
|
861
|
+
hours[local.getUTCHours()] = (hours[local.getUTCHours()] ?? 0) + 1;
|
|
862
|
+
}
|
|
863
|
+
const byWeekday = [1, 2, 3, 4, 5, 6, 0].map((day) => ({
|
|
864
|
+
count: days[day] ?? 0,
|
|
865
|
+
share: rate(days[day] ?? 0, times3.length),
|
|
866
|
+
weekday: WEEKDAYS[day] ?? "Sunday"
|
|
867
|
+
}));
|
|
868
|
+
const byHour = hours.map((count, hour) => ({
|
|
869
|
+
count,
|
|
870
|
+
hour,
|
|
871
|
+
share: rate(count, times3.length)
|
|
872
|
+
}));
|
|
873
|
+
return {
|
|
874
|
+
byHour,
|
|
875
|
+
byWeekday,
|
|
876
|
+
topHour: topOf(byHour)?.hour ?? null,
|
|
877
|
+
topWeekday: topOf(byWeekday)?.weekday ?? null
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
var readMessages = async (context, campaign, since, max) => {
|
|
881
|
+
const { outbound } = context;
|
|
882
|
+
const filters = outbound.capabilities["messages.since"] === false ? {} : { since };
|
|
883
|
+
const messages = await readCapped(
|
|
884
|
+
context,
|
|
885
|
+
(cap) => campaign === null ? outbound.messages.listAll({ ...filters, max: cap }) : outbound.campaign(campaign).messages.listAll({ ...filters, max: cap }),
|
|
886
|
+
max
|
|
887
|
+
);
|
|
888
|
+
if (outbound.capabilities["messages.since"] === false) {
|
|
889
|
+
context.note(
|
|
890
|
+
"This tool cannot filter messages by date, so the cap applies to all messages and older ones were dropped after reading."
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
return messages.filter(
|
|
894
|
+
(message) => message.sentAt === null || message.sentAt >= since
|
|
895
|
+
);
|
|
896
|
+
};
|
|
897
|
+
var replyTiming = defineInsight({
|
|
898
|
+
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. Use it to choose follow-up delays and sending hours. Costs 1 request per page of messages, up to max_messages. A null figure means no reply could be paired; auto-replies are not separated, because messages carry no auto flag.",
|
|
899
|
+
inputSchema: input3,
|
|
900
|
+
key: "replyTiming",
|
|
901
|
+
name: "reply_timing",
|
|
902
|
+
needs: ["messages.list"],
|
|
903
|
+
next: "Use step_funnel to see which step the replies answer, then set follow-up delays near the median time to reply.",
|
|
904
|
+
run: async (context, args) => {
|
|
905
|
+
const since = args.since === null ? new Date(context.now - 30 * DAY_MS).toISOString() : new Date(args.since).toISOString();
|
|
906
|
+
const messages = await readMessages(
|
|
907
|
+
context,
|
|
908
|
+
args.campaign,
|
|
909
|
+
since,
|
|
910
|
+
args.max_messages
|
|
911
|
+
);
|
|
912
|
+
const paired = pair(messages);
|
|
913
|
+
const hours = paired.pairs.map((each) => (each.at - each.sentAt) / HOUR_MS);
|
|
914
|
+
const within = (limit2) => rate(hours.filter((value) => value <= limit2).length, hours.length);
|
|
915
|
+
const received = messages.filter((message) => message.direction === "in");
|
|
916
|
+
const untimed = received.length - paired.replyTimes.length;
|
|
917
|
+
const timing = {
|
|
918
|
+
campaign: args.campaign,
|
|
919
|
+
counts: {
|
|
920
|
+
followOnReplies: paired.followOn,
|
|
921
|
+
messagesRead: messages.length,
|
|
922
|
+
paired: paired.pairs.length,
|
|
923
|
+
received: received.length,
|
|
924
|
+
sent: messages.length - received.length,
|
|
925
|
+
unpaired: paired.unpaired + untimed
|
|
926
|
+
},
|
|
927
|
+
replies: tableOf(paired.replyTimes, args.timezone_offset_minutes),
|
|
928
|
+
sendsThatDrewReplies: tableOf(
|
|
929
|
+
paired.pairs.map((each) => each.sentAt),
|
|
930
|
+
args.timezone_offset_minutes
|
|
931
|
+
),
|
|
932
|
+
since,
|
|
933
|
+
timeToReply: {
|
|
934
|
+
medianHours: round(median(hours)),
|
|
935
|
+
p75Hours: round(percentile(hours, 0.75)),
|
|
936
|
+
p90Hours: round(percentile(hours, 0.9)),
|
|
937
|
+
sample: paired.pairs.length,
|
|
938
|
+
within1Hour: within(1),
|
|
939
|
+
within24Hours: within(24),
|
|
940
|
+
within72Hours: within(72)
|
|
941
|
+
},
|
|
942
|
+
timezoneOffsetMinutes: args.timezone_offset_minutes
|
|
943
|
+
};
|
|
944
|
+
return timing;
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
// src/insights/copy/step-funnel.ts
|
|
949
|
+
import { z as z5 } from "zod";
|
|
950
|
+
var input4 = z5.object({
|
|
951
|
+
campaign: z5.string().min(1).describe("The campaign's ref, for example `instantly:acme:abc123`"),
|
|
952
|
+
from: dayInput("First day to count, YYYY-MM-DD. null counts from the start."),
|
|
953
|
+
min_reply_rate: z5.number().min(0).max(1).default(0).describe(
|
|
954
|
+
"A step earns its place when the low end of its reply rate interval is above this. 0 asks only that the rate is reliably above zero."
|
|
955
|
+
),
|
|
956
|
+
to: dayInput("Last day to count, YYYY-MM-DD. null counts to today.")
|
|
957
|
+
});
|
|
958
|
+
var variantsOf = (stats, step) => [...stats?.variants ?? []].map(([variantKey, counts]) => {
|
|
959
|
+
const measured2 = measure(counts.replied, perLead(counts));
|
|
960
|
+
return {
|
|
961
|
+
contentHash: step?.variants.find((variant) => variant.variantKey === variantKey)?.contentHash ?? null,
|
|
962
|
+
replies: counts.replied,
|
|
963
|
+
replyRate: measured2.rate,
|
|
964
|
+
replyRateInterval: measured2.interval,
|
|
965
|
+
sent: counts.sent,
|
|
966
|
+
variantKey
|
|
967
|
+
};
|
|
968
|
+
});
|
|
969
|
+
var draftOf = (index, step, stats, minReplyRate) => {
|
|
970
|
+
const counts = stats?.total ?? null;
|
|
971
|
+
const measured2 = counts === null ? null : measure(counts.replied, perLead(counts));
|
|
972
|
+
const interval = measured2?.interval ?? null;
|
|
973
|
+
return {
|
|
974
|
+
action: step?.action ?? null,
|
|
975
|
+
delayDays: step?.delayDays ?? null,
|
|
976
|
+
earnsPlace: interval === null ? null : interval.low > minReplyRate,
|
|
977
|
+
inSequence: step !== void 0,
|
|
978
|
+
parent: step === void 0 ? null : step.parentIndex,
|
|
979
|
+
replies: counts?.replied ?? null,
|
|
980
|
+
replyRate: measured2?.rate ?? null,
|
|
981
|
+
replyRateBasis: measured2?.basis ?? null,
|
|
982
|
+
replyRateInterval: interval,
|
|
983
|
+
sent: counts?.sent ?? null,
|
|
984
|
+
step: index,
|
|
985
|
+
variants: variantsOf(stats, step)
|
|
986
|
+
};
|
|
987
|
+
};
|
|
988
|
+
var finish = (drafts, allReplies) => drafts.map(({ parent, ...draft }, position) => {
|
|
989
|
+
const before = draft.inSequence ? drafts.find((other) => other.step === parent) : drafts[position - 1];
|
|
990
|
+
const drop = before === void 0 || before.sent === null || draft.sent === null ? null : before.sent - draft.sent;
|
|
991
|
+
return {
|
|
992
|
+
...draft,
|
|
993
|
+
sentDrop: drop,
|
|
994
|
+
sentDropRate: rate(drop, before?.sent ?? null),
|
|
995
|
+
shareOfReplies: rate(draft.replies, allReplies)
|
|
996
|
+
};
|
|
997
|
+
});
|
|
998
|
+
var topOf2 = (steps) => {
|
|
999
|
+
let top = null;
|
|
1000
|
+
for (const step of steps) {
|
|
1001
|
+
if ((step.replies ?? 0) > (top?.replies ?? 0)) {
|
|
1002
|
+
top = step;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return top;
|
|
1006
|
+
};
|
|
1007
|
+
var describe = (steps, top, last, allReplies) => {
|
|
1008
|
+
if (steps.every((step) => step.sent === null)) {
|
|
1009
|
+
return "No step has stats yet, so there is nothing to compare.";
|
|
1010
|
+
}
|
|
1011
|
+
if (top === null) {
|
|
1012
|
+
return "No step has a reply in this range.";
|
|
1013
|
+
}
|
|
1014
|
+
const lead = `Step ${top.step} (counted from 0) brings the most replies: ${top.replies} of ${allReplies}.`;
|
|
1015
|
+
if (last === null) {
|
|
1016
|
+
return `${lead} No step's reply rate is reliably above the bar yet.`;
|
|
1017
|
+
}
|
|
1018
|
+
const later = steps.filter(
|
|
1019
|
+
(step) => step.step > last.step && step.sent !== null
|
|
1020
|
+
);
|
|
1021
|
+
return later.length === 0 ? `${lead} Every step up to step ${last.step} still earns its place.` : `${lead} Step ${last.step} is the last whose reply rate is reliably above the bar; the ${later.length} later step(s) sent ${total(later.map((step) => step.sent))} messages for ${total(later.map((step) => step.replies)) ?? "an unknown number of"} replies.`;
|
|
1022
|
+
};
|
|
1023
|
+
var unattributedOf = (rows) => {
|
|
1024
|
+
const counts = sumRows(rows);
|
|
1025
|
+
return { replies: counts.replied, rows: rows.length, sent: counts.sent };
|
|
1026
|
+
};
|
|
1027
|
+
var stepFunnel = defineInsight({
|
|
1028
|
+
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.",
|
|
1029
|
+
inputSchema: input4,
|
|
1030
|
+
key: "stepFunnel",
|
|
1031
|
+
name: "step_funnel",
|
|
1032
|
+
needs: ["sequence", "stats.byStep"],
|
|
1033
|
+
next: "Use variant_test on the same campaign to see whether a step's A/B winner is real, or copy_audit to check the copy of a weak step.",
|
|
1034
|
+
run: async (context, { campaign, from, min_reply_rate: bar, to }) => {
|
|
1035
|
+
const handle = context.outbound.campaign(campaign);
|
|
1036
|
+
const sequence2 = context.one(await handle.sequence());
|
|
1037
|
+
const rows = context.rows(
|
|
1038
|
+
await handle.stats({ ...rangeOf(from, to), scope: "step" })
|
|
1039
|
+
);
|
|
1040
|
+
const split = splitStats(rows);
|
|
1041
|
+
const indexes = [
|
|
1042
|
+
.../* @__PURE__ */ new Set([
|
|
1043
|
+
...sequence2.steps.map((step) => step.index),
|
|
1044
|
+
...split.steps.keys()
|
|
1045
|
+
])
|
|
1046
|
+
].toSorted((left, right) => left - right);
|
|
1047
|
+
const drafts = indexes.map(
|
|
1048
|
+
(index) => draftOf(
|
|
1049
|
+
index,
|
|
1050
|
+
sequence2.steps.find((step) => step.index === index),
|
|
1051
|
+
split.steps.get(index),
|
|
1052
|
+
bar
|
|
1053
|
+
)
|
|
1054
|
+
);
|
|
1055
|
+
const unattributed = unattributedOf(split.unattributed);
|
|
1056
|
+
const allReplies = total([
|
|
1057
|
+
...drafts.map((draft) => draft.replies),
|
|
1058
|
+
unattributed.replies
|
|
1059
|
+
]);
|
|
1060
|
+
const steps = finish(drafts, allReplies);
|
|
1061
|
+
const top = topOf2(steps);
|
|
1062
|
+
const last = steps.findLast((step) => step.earnsPlace === true) ?? null;
|
|
1063
|
+
if (unattributed.rows > 0) {
|
|
1064
|
+
context.note(
|
|
1065
|
+
"Some counts are tied to no step by the vendor; they are reported as unattributed and are in no step's row."
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
const funnel = {
|
|
1069
|
+
campaign,
|
|
1070
|
+
finding: describe(steps, top, last, allReplies),
|
|
1071
|
+
lastStepEarningPlace: last?.step ?? null,
|
|
1072
|
+
steps,
|
|
1073
|
+
topStep: top?.step ?? null,
|
|
1074
|
+
totals: {
|
|
1075
|
+
replies: allReplies,
|
|
1076
|
+
sent: total([...drafts.map((draft) => draft.sent), unattributed.sent])
|
|
1077
|
+
},
|
|
1078
|
+
unattributed
|
|
1079
|
+
};
|
|
1080
|
+
return funnel;
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
// src/insights/copy/variant-test.ts
|
|
1085
|
+
import { z as z6 } from "zod";
|
|
1086
|
+
var METRICS = ["replied", "positive", "opened", "clicked"];
|
|
1087
|
+
var input5 = z6.object({
|
|
1088
|
+
alpha: z6.number().gt(0).max(0.5).default(0.05).describe(
|
|
1089
|
+
"The chance of calling a winner that is not one. A difference with a p-value under this is a winner."
|
|
1090
|
+
),
|
|
1091
|
+
campaign: z6.string().min(1).describe("The campaign's ref, for example `instantly:acme:abc123`"),
|
|
1092
|
+
from: dayInput("First day to count, YYYY-MM-DD. null counts from the start."),
|
|
1093
|
+
metric: z6.enum(METRICS).default("replied").describe(
|
|
1094
|
+
"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)."
|
|
1095
|
+
),
|
|
1096
|
+
min_sent: z6.number().int().min(1).default(100).describe(
|
|
1097
|
+
"A variant with a smaller base than this (sends, or leads contacted when the vendor counts those) is not compared."
|
|
1098
|
+
),
|
|
1099
|
+
to: dayInput("Last day to count, YYYY-MM-DD. null counts to today.")
|
|
1100
|
+
});
|
|
1101
|
+
var ORDER = {
|
|
1102
|
+
no_difference_yet: 1,
|
|
1103
|
+
too_little_data: 2,
|
|
1104
|
+
winner: 0
|
|
1105
|
+
};
|
|
1106
|
+
var quantile = (tail) => {
|
|
1107
|
+
const t = Math.sqrt(-2 * Math.log(tail));
|
|
1108
|
+
return t - (2.515517 + 0.802853 * t + 0.010328 * t ** 2) / (1 + 1.432788 * t + 0.189269 * t ** 2 + 1308e-6 * t ** 3);
|
|
1109
|
+
};
|
|
1110
|
+
var sendsToSignificance = (score, trials, alpha) => score === 0 ? null : Math.max(0, Math.ceil(((quantile(alpha / 2) / score) ** 2 - 1) * trials));
|
|
1111
|
+
var candidateOf = (variantKey, counts, metric, minSent) => {
|
|
1112
|
+
const base = metric === "replied" || metric === "positive" ? perLead(counts) : perMessage(counts);
|
|
1113
|
+
const measured2 = measure(counts[metric], base);
|
|
1114
|
+
return {
|
|
1115
|
+
...measured2,
|
|
1116
|
+
enoughData: measured2.rate !== null && measured2.trials !== null && measured2.trials >= minSent,
|
|
1117
|
+
sent: counts.sent,
|
|
1118
|
+
variantKey
|
|
1119
|
+
};
|
|
1120
|
+
};
|
|
1121
|
+
var shortfall = (candidates, minSent) => {
|
|
1122
|
+
if (candidates.some((each) => each.count === null)) {
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
return candidates.reduce(
|
|
1126
|
+
(sum, each) => sum + Math.max(0, minSent - (each.trials ?? 0)),
|
|
1127
|
+
0
|
|
1128
|
+
);
|
|
1129
|
+
};
|
|
1130
|
+
var tooLittle = (step, candidates, settings) => {
|
|
1131
|
+
const unreported = candidates.some((each) => each.count === null);
|
|
1132
|
+
return {
|
|
1133
|
+
leader: null,
|
|
1134
|
+
moreSendsNeeded: shortfall(candidates, settings.minSent),
|
|
1135
|
+
pValue: null,
|
|
1136
|
+
reason: unreported ? `The vendor does not report ${settings.metric} for every variant of this step, so they cannot be compared.` : `Fewer than two variants have a base of ${settings.minSent}, so no comparison is made.`,
|
|
1137
|
+
step,
|
|
1138
|
+
variants: candidates.map((each) => ({ ...each, pValueVsLeader: null })),
|
|
1139
|
+
verdict: "too_little_data"
|
|
1140
|
+
};
|
|
1141
|
+
};
|
|
1142
|
+
var testStep = (step, candidates, settings) => {
|
|
1143
|
+
const ready = candidates.filter((each) => each.enoughData).toSorted(
|
|
1144
|
+
(left, right) => (right.rate ?? 0) - (left.rate ?? 0) || (right.trials ?? 0) - (left.trials ?? 0)
|
|
1145
|
+
);
|
|
1146
|
+
const [leader, rival] = ready;
|
|
1147
|
+
if (leader === void 0 || rival === void 0) {
|
|
1148
|
+
return tooLittle(step, candidates, settings);
|
|
1149
|
+
}
|
|
1150
|
+
const tests = new Map(
|
|
1151
|
+
ready.slice(1).map((other) => [
|
|
1152
|
+
other.variantKey,
|
|
1153
|
+
compareRates(
|
|
1154
|
+
{ successes: leader.count, trials: leader.trials },
|
|
1155
|
+
{ successes: other.count, trials: other.trials },
|
|
1156
|
+
settings.alpha
|
|
1157
|
+
)
|
|
1158
|
+
])
|
|
1159
|
+
);
|
|
1160
|
+
const closest = tests.get(rival.variantKey) ?? null;
|
|
1161
|
+
const beatsAll = [...tests.values()].every((test) => test?.significant);
|
|
1162
|
+
const skipped = candidates.length - ready.length;
|
|
1163
|
+
const aside = skipped === 0 ? "" : ` ${skipped} variant(s) with too little data were left out.`;
|
|
1164
|
+
const variants = candidates.map((each) => ({
|
|
1165
|
+
...each,
|
|
1166
|
+
pValueVsLeader: tests.get(each.variantKey)?.pValue ?? null
|
|
1167
|
+
}));
|
|
1168
|
+
if (beatsAll) {
|
|
1169
|
+
return {
|
|
1170
|
+
leader: leader.variantKey,
|
|
1171
|
+
moreSendsNeeded: null,
|
|
1172
|
+
pValue: closest?.pValue ?? null,
|
|
1173
|
+
reason: `Variant ${leader.variantKey} (${leader.rate}) beats every other variant by more than chance at alpha ${settings.alpha}.${aside}`,
|
|
1174
|
+
step,
|
|
1175
|
+
variants,
|
|
1176
|
+
verdict: "winner"
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
return {
|
|
1180
|
+
leader: leader.variantKey,
|
|
1181
|
+
moreSendsNeeded: closest === null ? null : sendsToSignificance(
|
|
1182
|
+
closest.z,
|
|
1183
|
+
(leader.trials ?? 0) + (rival.trials ?? 0),
|
|
1184
|
+
settings.alpha
|
|
1185
|
+
),
|
|
1186
|
+
pValue: closest?.pValue ?? null,
|
|
1187
|
+
reason: `Variant ${leader.variantKey} (${leader.rate}) leads variant ${rival.variantKey} (${rival.rate}), but a gap this size could be chance.${aside}`,
|
|
1188
|
+
step,
|
|
1189
|
+
variants,
|
|
1190
|
+
verdict: "no_difference_yet"
|
|
1191
|
+
};
|
|
1192
|
+
};
|
|
1193
|
+
var countOf = (steps, verdict) => steps.filter((step) => step.verdict === verdict).length;
|
|
1194
|
+
var variantTest = defineInsight({
|
|
1195
|
+
description: "Whether a campaign's A/B winner is real. For each step with two or more variants, compares every variant with the leader by a two-proportion test and returns the variants with rates and 95% intervals, the leader, and a verdict: winner, no_difference_yet or too_little_data, with the p-value and a rough number of sends still needed when there is no verdict. Use it before pausing a variant. Costs 1 request. A null count or rate means the vendor does not report it; an empty list means the vendor does not split step stats by variant.",
|
|
1196
|
+
inputSchema: input5,
|
|
1197
|
+
key: "variantTest",
|
|
1198
|
+
name: "variant_test",
|
|
1199
|
+
needs: ["stats.byStep"],
|
|
1200
|
+
next: "Use step_funnel to see how much of the campaign's replies the tested step brings, or copy_audit to check the losing variant's copy.",
|
|
1201
|
+
run: async (context, { alpha, campaign, from, metric, min_sent, to }) => {
|
|
1202
|
+
const rows = context.rows(
|
|
1203
|
+
await context.outbound.campaign(campaign).stats({ ...rangeOf(from, to), scope: "step" })
|
|
1204
|
+
);
|
|
1205
|
+
const split = splitStats(rows);
|
|
1206
|
+
const settings = { alpha, metric, minSent: min_sent };
|
|
1207
|
+
const steps = [...split.steps].flatMap(
|
|
1208
|
+
([step, stats]) => stats.variants.size < 2 ? [] : [
|
|
1209
|
+
testStep(
|
|
1210
|
+
step,
|
|
1211
|
+
[...stats.variants].map(
|
|
1212
|
+
([key, counts]) => candidateOf(key, counts, metric, min_sent)
|
|
1213
|
+
),
|
|
1214
|
+
settings
|
|
1215
|
+
)
|
|
1216
|
+
]
|
|
1217
|
+
).toSorted(
|
|
1218
|
+
(left, right) => ORDER[left.verdict] - ORDER[right.verdict] || left.step - right.step
|
|
1219
|
+
);
|
|
1220
|
+
const reported = rows.some((row) => row.variantKey !== null);
|
|
1221
|
+
if (!reported) {
|
|
1222
|
+
context.note(
|
|
1223
|
+
"The step stats carry no variant rows, so there is nothing to compare."
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
const result = {
|
|
1227
|
+
alpha,
|
|
1228
|
+
campaign,
|
|
1229
|
+
metric,
|
|
1230
|
+
steps,
|
|
1231
|
+
totals: {
|
|
1232
|
+
noDifferenceYet: countOf(steps, "no_difference_yet"),
|
|
1233
|
+
stepsTested: steps.length,
|
|
1234
|
+
tooLittleData: countOf(steps, "too_little_data"),
|
|
1235
|
+
winners: countOf(steps, "winner")
|
|
1236
|
+
},
|
|
1237
|
+
variantStatsReported: reported
|
|
1238
|
+
};
|
|
1239
|
+
return result;
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
// src/insights/copy/index.ts
|
|
1244
|
+
var COPY_INSIGHTS = [
|
|
1245
|
+
stepFunnel,
|
|
1246
|
+
variantTest,
|
|
1247
|
+
copyAudit,
|
|
1248
|
+
copyReuse,
|
|
1249
|
+
replyTiming
|
|
1250
|
+
];
|
|
1251
|
+
|
|
1252
|
+
// src/insights/ops/anomalies.ts
|
|
1253
|
+
import { z as z8 } from "zod";
|
|
1254
|
+
|
|
1255
|
+
// src/insights/ops/shared.ts
|
|
1256
|
+
import { z as z7 } from "zod";
|
|
1257
|
+
var DAY_MS2 = 864e5;
|
|
1258
|
+
var dayOf = (time) => new Date(time).toISOString().slice(0, 10);
|
|
1259
|
+
var shiftDay = (day, days) => dayOf(Date.parse(`${day}T00:00:00.000Z`) + days * DAY_MS2);
|
|
1260
|
+
var lastDays = (now, days, back = 0) => ({
|
|
1261
|
+
from: dayOf(now - days * (back + 1) * DAY_MS2),
|
|
1262
|
+
to: dayOf(now - (days * back + 1) * DAY_MS2)
|
|
1263
|
+
});
|
|
1264
|
+
var listFields = (costPerCampaign) => ({
|
|
1265
|
+
max_campaigns: z7.number().int().min(1).max(200).default(25).describe(`The most campaigns to read. Each costs ${costPerCampaign}.`),
|
|
1266
|
+
statuses: z7.array(campaignStatusSchema).min(1).default(["active", "paused", "completed"]).describe("Only campaigns in one of these states are read")
|
|
1267
|
+
});
|
|
1268
|
+
var rangeFields = {
|
|
1269
|
+
from: z7.iso.date().nullable().default(null).describe("First day counted, YYYY-MM-DD. null for the whole history."),
|
|
1270
|
+
to: z7.iso.date().nullable().default(null).describe("Last day counted, YYYY-MM-DD. null for up to today.")
|
|
1271
|
+
};
|
|
1272
|
+
var labelOf = (campaign) => ({
|
|
1273
|
+
campaign: campaign.ref,
|
|
1274
|
+
channel: campaign.channel,
|
|
1275
|
+
name: campaign.name,
|
|
1276
|
+
provider: campaign.provider,
|
|
1277
|
+
status: campaign.status
|
|
1278
|
+
});
|
|
1279
|
+
var totalsOf = (counts) => ({
|
|
1280
|
+
bounced: counts.bounced,
|
|
1281
|
+
contacted: counts.contacted,
|
|
1282
|
+
positive: counts.positive,
|
|
1283
|
+
replied: counts.replied,
|
|
1284
|
+
sent: counts.sent
|
|
1285
|
+
});
|
|
1286
|
+
var measure2 = (count, of) => {
|
|
1287
|
+
const interval = wilson(count, of);
|
|
1288
|
+
return {
|
|
1289
|
+
count,
|
|
1290
|
+
high: interval?.high ?? null,
|
|
1291
|
+
low: interval?.low ?? null,
|
|
1292
|
+
of,
|
|
1293
|
+
rate: rate(count, of)
|
|
1294
|
+
};
|
|
1295
|
+
};
|
|
1296
|
+
var perLeadBase = (counts) => counts.contacted !== null && counts.contacted > 0 ? counts.contacted : counts.sent;
|
|
1297
|
+
var ratesOf = (counts) => ({
|
|
1298
|
+
bounceRate: measure2(counts.bounced, counts.sent),
|
|
1299
|
+
positiveRate: measure2(counts.positive, perLeadBase(counts)),
|
|
1300
|
+
replyRate: measure2(counts.replied, perLeadBase(counts))
|
|
1301
|
+
});
|
|
1302
|
+
var measureAcross = (rows, countOf3, baseOf) => {
|
|
1303
|
+
const sides = rows.map((row) => ({ base: baseOf(row), count: countOf3(row) }));
|
|
1304
|
+
const pairs = sides.flatMap(
|
|
1305
|
+
({ base, count }) => count === null || base === null ? [] : [{ base, count }]
|
|
1306
|
+
);
|
|
1307
|
+
return {
|
|
1308
|
+
counted: pairs.length,
|
|
1309
|
+
measured: pairs.length === 0 ? measure2(total(sides.map((side) => side.count)), null) : measure2(
|
|
1310
|
+
total(pairs.map((pair2) => pair2.count)),
|
|
1311
|
+
total(pairs.map((pair2) => pair2.base))
|
|
1312
|
+
),
|
|
1313
|
+
of: sides.filter((side) => side.base !== null || side.count !== null).length
|
|
1314
|
+
};
|
|
1315
|
+
};
|
|
1316
|
+
var partialRate = (name, across) => across.counted > 0 && across.counted < across.of ? [`${name} (${across.counted} of ${across.of})`] : [];
|
|
1317
|
+
var ratesAcross = (rows) => {
|
|
1318
|
+
const reply = measureAcross(rows, (row) => row.replied, perLeadBase);
|
|
1319
|
+
const positive = measureAcross(rows, (row) => row.positive, perLeadBase);
|
|
1320
|
+
const bounce = measureAcross(
|
|
1321
|
+
rows,
|
|
1322
|
+
(row) => row.bounced,
|
|
1323
|
+
(row) => row.sent
|
|
1324
|
+
);
|
|
1325
|
+
return {
|
|
1326
|
+
partial: [
|
|
1327
|
+
...partialRate("reply rate", reply),
|
|
1328
|
+
...partialRate("positive reply rate", positive),
|
|
1329
|
+
...partialRate("bounce rate", bounce)
|
|
1330
|
+
],
|
|
1331
|
+
rates: {
|
|
1332
|
+
bounceRate: bounce.measured,
|
|
1333
|
+
positiveRate: positive.measured,
|
|
1334
|
+
replyRate: reply.measured
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
};
|
|
1338
|
+
var partialNote = (where, partial, rows = "campaigns") => `${where}: ${partial.join(", ")} ${partial.length === 1 ? "counts" : "count"} only the ${rows} that report both the count and what it is divided by. The others are left out of the rate, not counted as 0.`;
|
|
1339
|
+
var volumeOf = (counts) => counts.sent ?? counts.contacted;
|
|
1340
|
+
var percent = (value) => value === null ? "unknown" : `${Math.round(value * 1e3) / 10}%`;
|
|
1341
|
+
var descending = (left, right) => {
|
|
1342
|
+
if (left === null || right === null) {
|
|
1343
|
+
return Number(left === null) - Number(right === null);
|
|
1344
|
+
}
|
|
1345
|
+
return right - left;
|
|
1346
|
+
};
|
|
1347
|
+
var readUpTo = async (context, list, max) => {
|
|
1348
|
+
const walk = list(max);
|
|
1349
|
+
const items = await context.all(walk);
|
|
1350
|
+
return { complete: !walk.truncated, items };
|
|
1351
|
+
};
|
|
1352
|
+
var readCampaigns = async (context, statuses, max) => {
|
|
1353
|
+
const { campaigns } = context.outbound;
|
|
1354
|
+
const wanted = [...new Set(statuses)];
|
|
1355
|
+
if (context.outbound.capabilities["campaigns.status"] === false) {
|
|
1356
|
+
const every = await readUpTo(
|
|
1357
|
+
context,
|
|
1358
|
+
(cap) => campaigns.listAll({ max: cap }),
|
|
1359
|
+
max
|
|
1360
|
+
);
|
|
1361
|
+
return every.items.filter((campaign) => wanted.includes(campaign.status));
|
|
1362
|
+
}
|
|
1363
|
+
const found = [];
|
|
1364
|
+
for (const status of wanted) {
|
|
1365
|
+
const listed = await readUpTo(
|
|
1366
|
+
context,
|
|
1367
|
+
(cap) => campaigns.listAll({ max: cap, status }),
|
|
1368
|
+
max - found.length
|
|
1369
|
+
);
|
|
1370
|
+
found.push(...listed.items);
|
|
1371
|
+
}
|
|
1372
|
+
return found;
|
|
1373
|
+
};
|
|
1374
|
+
var readTotals = async (context, campaign, range) => sumCounts(
|
|
1375
|
+
context.rows(
|
|
1376
|
+
await context.outbound.campaign(campaign).stats({ from: range.from ?? void 0, to: range.to ?? void 0 })
|
|
1377
|
+
)
|
|
1378
|
+
);
|
|
1379
|
+
var readAllTotals = async (context, range) => {
|
|
1380
|
+
if (context.outbound.capabilities["stats.allCampaigns"] !== "full") {
|
|
1381
|
+
return void 0;
|
|
1382
|
+
}
|
|
1383
|
+
const rows = context.rows(
|
|
1384
|
+
await context.outbound.stats({
|
|
1385
|
+
from: range.from ?? void 0,
|
|
1386
|
+
scope: "campaign",
|
|
1387
|
+
to: range.to ?? void 0
|
|
1388
|
+
})
|
|
1389
|
+
);
|
|
1390
|
+
const byCampaign = /* @__PURE__ */ new Map();
|
|
1391
|
+
for (const row of rows) {
|
|
1392
|
+
byCampaign.set(row.scopeRef, [
|
|
1393
|
+
...byCampaign.get(row.scopeRef) ?? [],
|
|
1394
|
+
row
|
|
1395
|
+
]);
|
|
1396
|
+
}
|
|
1397
|
+
return new Map(
|
|
1398
|
+
[...byCampaign].map(([ref, counts]) => [ref, sumCounts(counts)])
|
|
1399
|
+
);
|
|
1400
|
+
};
|
|
1401
|
+
var readCampaignTotals = async (context, input27) => {
|
|
1402
|
+
const campaigns = await readCampaigns(
|
|
1403
|
+
context,
|
|
1404
|
+
input27.statuses,
|
|
1405
|
+
input27.max_campaigns
|
|
1406
|
+
);
|
|
1407
|
+
const reported = campaigns.length > 1 ? await readAllTotals(context, input27) : void 0;
|
|
1408
|
+
return await mapConcurrent(
|
|
1409
|
+
campaigns,
|
|
1410
|
+
async (campaign) => ({
|
|
1411
|
+
campaign,
|
|
1412
|
+
counts: reported?.get(campaign.ref) ?? await readTotals(context, campaign.ref, input27)
|
|
1413
|
+
})
|
|
1414
|
+
);
|
|
1415
|
+
};
|
|
1416
|
+
var readDaily = async (context, campaign, range) => {
|
|
1417
|
+
const options = { by: "day", from: range.from, to: range.to };
|
|
1418
|
+
const rows = context.rows(
|
|
1419
|
+
campaign === null ? await context.outbound.stats(options) : await context.outbound.campaign(campaign).stats(options)
|
|
1420
|
+
);
|
|
1421
|
+
const days = /* @__PURE__ */ new Map();
|
|
1422
|
+
for (const row of rows) {
|
|
1423
|
+
if (row.date !== null) {
|
|
1424
|
+
days.set(row.date, [...days.get(row.date) ?? [], row]);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return [...days].map(([date, group]) => ({ counts: sumCounts(group), date })).toSorted((left, right) => left.date.localeCompare(right.date));
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
// src/insights/ops/anomalies.ts
|
|
1431
|
+
var metricSchema = z8.enum([
|
|
1432
|
+
"sent",
|
|
1433
|
+
"contacted",
|
|
1434
|
+
"replied",
|
|
1435
|
+
"positive",
|
|
1436
|
+
"bounced",
|
|
1437
|
+
"opened",
|
|
1438
|
+
"clicked",
|
|
1439
|
+
"unsubscribed"
|
|
1440
|
+
]);
|
|
1441
|
+
var input6 = z8.object({
|
|
1442
|
+
baseline_days: z8.number().int().min(5).max(60).default(14).describe("How many days before a day form the baseline it is held to"),
|
|
1443
|
+
campaign: z8.string().min(3).nullable().default(null).describe("A campaign ref. null checks the whole workspace."),
|
|
1444
|
+
days: z8.number().int().min(1).max(90).default(30).describe("How many complete days, ending yesterday, are checked"),
|
|
1445
|
+
metrics: z8.array(metricSchema).min(1).default(["sent", "replied", "bounced"]).describe("The daily counts to check"),
|
|
1446
|
+
min_baseline_points: z8.number().int().min(2).default(5).describe("The fewest baseline days with data a day needs to be tested"),
|
|
1447
|
+
threshold: z8.number().positive().default(2.5).describe("How many standard deviations from the baseline mean is unusual")
|
|
1448
|
+
});
|
|
1449
|
+
var reasonFor = (metric, daysWithData) => daysWithData === 0 ? `The vendor reports no ${metric} count for these days.` : "Too few earlier days with data to form a baseline.";
|
|
1450
|
+
var judge = (metric, point, baseline, threshold) => {
|
|
1451
|
+
const center = round(mean(baseline)) ?? 0;
|
|
1452
|
+
const score = zScore(point.value, baseline);
|
|
1453
|
+
const shared = {
|
|
1454
|
+
baselineMean: center,
|
|
1455
|
+
baselinePoints: baseline.length,
|
|
1456
|
+
date: point.date,
|
|
1457
|
+
direction: point.value > center ? "above" : "below",
|
|
1458
|
+
metric,
|
|
1459
|
+
value: point.value
|
|
1460
|
+
};
|
|
1461
|
+
if (score === null) {
|
|
1462
|
+
return point.value === baseline[0] ? null : {
|
|
1463
|
+
...shared,
|
|
1464
|
+
finding: `${metric} was ${point.value} on ${point.date}, against ${center} on each of the ${baseline.length} days with data before it (a flat baseline has no z-score: any other count is flagged).`,
|
|
1465
|
+
judgedBy: "flat_baseline",
|
|
1466
|
+
zScore: null
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
return Math.abs(score) < threshold ? null : {
|
|
1470
|
+
...shared,
|
|
1471
|
+
finding: `${metric} was ${point.value} on ${point.date}, against an average of ${center} over the ${baseline.length} days with data before it (z = ${round(score)}).`,
|
|
1472
|
+
judgedBy: "z_score",
|
|
1473
|
+
zScore: round(score) ?? 0
|
|
1474
|
+
};
|
|
1475
|
+
};
|
|
1476
|
+
var scanMetric = (series, metric, options) => {
|
|
1477
|
+
const points = series.flatMap((day) => {
|
|
1478
|
+
const value = day.counts[metric];
|
|
1479
|
+
return value === null ? [] : [{ date: day.date, value }];
|
|
1480
|
+
});
|
|
1481
|
+
const checked = points.filter((point) => point.date >= options.firstDay);
|
|
1482
|
+
const anomalies2 = [];
|
|
1483
|
+
let tested = 0;
|
|
1484
|
+
for (const point of checked) {
|
|
1485
|
+
const start = shiftDay(point.date, -options.baselineDays);
|
|
1486
|
+
const baseline = points.flatMap(
|
|
1487
|
+
(other) => other.date >= start && other.date < point.date ? [other.value] : []
|
|
1488
|
+
);
|
|
1489
|
+
if (baseline.length >= options.minBaselinePoints) {
|
|
1490
|
+
tested += 1;
|
|
1491
|
+
const anomaly = judge(metric, point, baseline, options.threshold);
|
|
1492
|
+
if (anomaly !== null) {
|
|
1493
|
+
anomalies2.push(anomaly);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
anomalies: anomalies2,
|
|
1499
|
+
coverage: {
|
|
1500
|
+
daysTested: tested,
|
|
1501
|
+
daysWithData: checked.length,
|
|
1502
|
+
metric,
|
|
1503
|
+
reason: tested > 0 ? null : reasonFor(metric, checked.length),
|
|
1504
|
+
testable: tested > 0
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
};
|
|
1508
|
+
var sizeOf = (anomaly) => anomaly.zScore === null ? Number.POSITIVE_INFINITY : Math.abs(anomaly.zScore);
|
|
1509
|
+
var findAnomalies = (series, options) => {
|
|
1510
|
+
const scans = [...new Set(options.metrics)].map(
|
|
1511
|
+
(metric) => scanMetric(series, metric, options)
|
|
1512
|
+
);
|
|
1513
|
+
return {
|
|
1514
|
+
anomalies: scans.flatMap((scan) => scan.anomalies).toSorted(
|
|
1515
|
+
(left, right) => right.date.localeCompare(left.date) || descending(sizeOf(left), sizeOf(right))
|
|
1516
|
+
),
|
|
1517
|
+
metrics: scans.map((scan) => scan.coverage)
|
|
1518
|
+
};
|
|
1519
|
+
};
|
|
1520
|
+
var anomalies = defineInsight({
|
|
1521
|
+
description: "Days that broke from trend, for one campaign or the whole workspace: each of the last `days` complete days is held to the `baseline_days` before it, and a daily count `threshold` standard deviations or more from that baseline's mean is returned, newest first, with the metric, the value, the baseline mean, the z-score, the direction and how it was judged. When every baseline day has the same count there is no standard deviation: a day with another count is returned with a null z-score and judgedBy flat_baseline. Use it to spot a sending outage, a bounce spike or a reply surge. Days the vendor has no count for are skipped, never read as zero. With no campaign it reads workspace stats, so it then also needs stats.workspace. Costs one stats request.",
|
|
1522
|
+
inputSchema: input6,
|
|
1523
|
+
key: "anomalies",
|
|
1524
|
+
name: "anomalies",
|
|
1525
|
+
needs: ["stats.byDay"],
|
|
1526
|
+
// The whole workspace is read from workspace stats, a campaign from its own.
|
|
1527
|
+
needsFor: (options) => options.campaign === null ? ["stats.workspace"] : ["stats.campaign"],
|
|
1528
|
+
next: "Use campaign_diagnosis on the campaign, or bounce_watch when the break is in bounces.",
|
|
1529
|
+
run: async (context, options) => {
|
|
1530
|
+
const period = lastDays(context.now, options.days);
|
|
1531
|
+
const series = await readDaily(context, options.campaign, {
|
|
1532
|
+
from: shiftDay(period.from, -options.baseline_days),
|
|
1533
|
+
to: period.to
|
|
1534
|
+
});
|
|
1535
|
+
const answer = {
|
|
1536
|
+
...findAnomalies(series, {
|
|
1537
|
+
baselineDays: options.baseline_days,
|
|
1538
|
+
firstDay: period.from,
|
|
1539
|
+
metrics: options.metrics,
|
|
1540
|
+
minBaselinePoints: options.min_baseline_points,
|
|
1541
|
+
threshold: options.threshold
|
|
1542
|
+
}),
|
|
1543
|
+
period,
|
|
1544
|
+
scope: options.campaign ?? "workspace",
|
|
1545
|
+
threshold: options.threshold
|
|
1546
|
+
};
|
|
1547
|
+
return answer;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
|
|
1551
|
+
// src/insights/ops/campaign-diagnosis.ts
|
|
1552
|
+
import { z as z9 } from "zod";
|
|
1553
|
+
|
|
1554
|
+
// src/insights/ops/diagnosis-checks.ts
|
|
1555
|
+
var enough = (facts, limits) => (volumeOf(facts.totals) ?? -1) >= limits.minSent;
|
|
1556
|
+
var volume = (facts, limits) => {
|
|
1557
|
+
const sent = volumeOf(facts.totals);
|
|
1558
|
+
return enough(facts, limits) ? [] : [
|
|
1559
|
+
{
|
|
1560
|
+
code: "too_little_volume",
|
|
1561
|
+
finding: sent === null ? "The vendor reports no sends for this period, so no rate can be judged." : `Only ${sent} sends, under the ${limits.minSent} needed to judge a rate; reply and bounce rates are not assessed.`,
|
|
1562
|
+
next: "Let the campaign run longer, or widen the date range.",
|
|
1563
|
+
numbers: { minSent: limits.minSent, sent },
|
|
1564
|
+
severity: "medium"
|
|
1565
|
+
}
|
|
1566
|
+
];
|
|
1567
|
+
};
|
|
1568
|
+
var bounces = (facts, limits) => {
|
|
1569
|
+
const { count, high, low, of, rate: rate2 } = facts.rates.bounceRate;
|
|
1570
|
+
return !enough(facts, limits) || rate2 === null || rate2 <= limits.maxBounceRate ? [] : [
|
|
1571
|
+
{
|
|
1572
|
+
code: "high_bounce_rate",
|
|
1573
|
+
finding: `Bounce rate is ${percent(rate2)} (${count} of ${of} sends), over the ${percent(limits.maxBounceRate)} limit.`,
|
|
1574
|
+
next: "Use bounce_watch to find the senders behind it, and verify the lead list.",
|
|
1575
|
+
numbers: {
|
|
1576
|
+
bounced: count,
|
|
1577
|
+
high,
|
|
1578
|
+
limit: limits.maxBounceRate,
|
|
1579
|
+
low,
|
|
1580
|
+
rate: rate2,
|
|
1581
|
+
sent: of
|
|
1582
|
+
},
|
|
1583
|
+
severity: "high"
|
|
1584
|
+
}
|
|
1585
|
+
];
|
|
1586
|
+
};
|
|
1587
|
+
var replies = (facts, limits) => {
|
|
1588
|
+
const { count, high, low, of, rate: rate2 } = facts.rates.replyRate;
|
|
1589
|
+
if (!enough(facts, limits) || rate2 === null || rate2 >= limits.minReplyRate) {
|
|
1590
|
+
return [];
|
|
1591
|
+
}
|
|
1592
|
+
const clearly = high !== null && high < limits.minReplyRate;
|
|
1593
|
+
return [
|
|
1594
|
+
{
|
|
1595
|
+
code: "low_reply_rate",
|
|
1596
|
+
finding: `Reply rate is ${percent(rate2)} (${count} of ${of}), under the ${percent(limits.minReplyRate)} floor. The 95% interval is ${percent(low)} to ${percent(high)}, ${clearly ? "so it is below the floor beyond chance" : "which still reaches the floor, so more sends are needed to be sure"}.`,
|
|
1597
|
+
next: "Use step_funnel and copy_audit to see where replies are lost.",
|
|
1598
|
+
numbers: {
|
|
1599
|
+
floor: limits.minReplyRate,
|
|
1600
|
+
high,
|
|
1601
|
+
low,
|
|
1602
|
+
rate: rate2,
|
|
1603
|
+
replied: count,
|
|
1604
|
+
sample: of
|
|
1605
|
+
},
|
|
1606
|
+
severity: clearly ? "high" : "medium"
|
|
1607
|
+
}
|
|
1608
|
+
];
|
|
1609
|
+
};
|
|
1610
|
+
var positives = (facts, limits) => {
|
|
1611
|
+
const share2 = measure2(facts.totals.positive, facts.totals.replied);
|
|
1612
|
+
return !enough(facts, limits) || share2.rate === null || share2.rate >= limits.minPositiveShare ? [] : [
|
|
1613
|
+
{
|
|
1614
|
+
code: "few_positive_replies",
|
|
1615
|
+
finding: `Only ${share2.count} of ${share2.of} replies (${percent(share2.rate)}) are positive, under the ${percent(limits.minPositiveShare)} expected. With ${share2.of} replies the 95% interval is ${percent(share2.low)} to ${percent(share2.high)}.`,
|
|
1616
|
+
next: "Read the replies: the offer or the audience may be off.",
|
|
1617
|
+
numbers: {
|
|
1618
|
+
high: share2.high,
|
|
1619
|
+
limit: limits.minPositiveShare,
|
|
1620
|
+
low: share2.low,
|
|
1621
|
+
positive: share2.count,
|
|
1622
|
+
sample: share2.of,
|
|
1623
|
+
share: share2.rate
|
|
1624
|
+
},
|
|
1625
|
+
severity: "medium"
|
|
1626
|
+
}
|
|
1627
|
+
];
|
|
1628
|
+
};
|
|
1629
|
+
var recentSends = (facts, limits) => {
|
|
1630
|
+
const { recent } = facts;
|
|
1631
|
+
if (recent === null) {
|
|
1632
|
+
return [];
|
|
1633
|
+
}
|
|
1634
|
+
if (recent.sent === null || recent.sent === 0) {
|
|
1635
|
+
return facts.campaign.status === "active" ? [
|
|
1636
|
+
{
|
|
1637
|
+
code: "no_recent_sends",
|
|
1638
|
+
finding: `The campaign is active but the vendor reports no sends in the last ${recent.days} days.`,
|
|
1639
|
+
next: "Check its senders and schedule, and whether leads remain (pipeline_forecast).",
|
|
1640
|
+
numbers: { days: recent.days, sent: recent.sent },
|
|
1641
|
+
severity: "high"
|
|
1642
|
+
}
|
|
1643
|
+
] : [];
|
|
1644
|
+
}
|
|
1645
|
+
const drop = recent.before === null || recent.before <= 0 ? null : round(1 - recent.sent / recent.before);
|
|
1646
|
+
return drop === null || drop <= limits.maxSendDrop ? [] : [
|
|
1647
|
+
{
|
|
1648
|
+
code: "falling_sends",
|
|
1649
|
+
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)}.`,
|
|
1650
|
+
next: "Use pipeline_forecast to check the leads left, and sender_capacity for the mailboxes.",
|
|
1651
|
+
numbers: { before: recent.before, drop, sent: recent.sent },
|
|
1652
|
+
severity: "medium"
|
|
1653
|
+
}
|
|
1654
|
+
];
|
|
1655
|
+
};
|
|
1656
|
+
var sequence = ({ steps }) => steps === null || steps < 1 || steps > 2 ? [] : [
|
|
1657
|
+
{
|
|
1658
|
+
code: "short_sequence",
|
|
1659
|
+
finding: `The sequence has ${steps} ${steps === 1 ? "step" : "steps"}; follow-ups usually bring a large share of the replies.`,
|
|
1660
|
+
next: "Add follow-up steps; step_funnel shows what each step earns.",
|
|
1661
|
+
numbers: { steps },
|
|
1662
|
+
severity: "medium"
|
|
1663
|
+
}
|
|
1664
|
+
];
|
|
1665
|
+
var senders = (facts) => {
|
|
1666
|
+
const all = facts.senders ?? [];
|
|
1667
|
+
const inactive = all.filter((sender) => sender.status !== "active");
|
|
1668
|
+
return inactive.length === 0 ? [] : [
|
|
1669
|
+
{
|
|
1670
|
+
code: "inactive_sender",
|
|
1671
|
+
finding: `${inactive.length} of ${all.length} senders are not active: ${inactive.map(
|
|
1672
|
+
(sender) => `${sender.address ?? sender.name ?? sender.ref} (${sender.status})`
|
|
1673
|
+
).join(", ")}.`,
|
|
1674
|
+
next: "Reconnect or replace them; warmup_readiness shows which mailboxes are fit to send.",
|
|
1675
|
+
numbers: { inactive: inactive.length, senders: all.length },
|
|
1676
|
+
severity: "high"
|
|
1677
|
+
}
|
|
1678
|
+
];
|
|
1679
|
+
};
|
|
1680
|
+
var tracking = ({ opened, settings }) => settings?.tracking.opens === false && (opened ?? 0) === 0 ? [
|
|
1681
|
+
{
|
|
1682
|
+
code: "tracking_off",
|
|
1683
|
+
finding: "Open tracking is off, so the missing open count is expected and not a fault.",
|
|
1684
|
+
next: "Judge this campaign on replies, not opens.",
|
|
1685
|
+
numbers: { opened },
|
|
1686
|
+
severity: "low"
|
|
1687
|
+
}
|
|
1688
|
+
] : [];
|
|
1689
|
+
var minutesOf = (clock) => {
|
|
1690
|
+
const [hours, minutes] = (clock ?? "").split(":").map(Number);
|
|
1691
|
+
return hours === void 0 || minutes === void 0 ? null : hours * 60 + minutes;
|
|
1692
|
+
};
|
|
1693
|
+
var weeklyHours = (settings) => {
|
|
1694
|
+
let minutes = 0;
|
|
1695
|
+
for (const window of settings.schedule) {
|
|
1696
|
+
const from = minutesOf(window.from);
|
|
1697
|
+
const to = minutesOf(window.to);
|
|
1698
|
+
if (from === null || to === null || to <= from) {
|
|
1699
|
+
return null;
|
|
1700
|
+
}
|
|
1701
|
+
minutes += (to - from) * window.days.length;
|
|
1702
|
+
}
|
|
1703
|
+
return settings.schedule.length === 0 ? null : round(minutes / 60);
|
|
1704
|
+
};
|
|
1705
|
+
var schedule = ({ recent, settings }, limits) => {
|
|
1706
|
+
if (settings === null) {
|
|
1707
|
+
return [];
|
|
1708
|
+
}
|
|
1709
|
+
const hours = weeklyHours(settings);
|
|
1710
|
+
const average = recent === null || recent.sent === null || recent.daysWithData === 0 ? null : round(recent.sent / recent.daysWithData);
|
|
1711
|
+
const reasons = [
|
|
1712
|
+
...hours !== null && hours < limits.minWeeklyHours ? [
|
|
1713
|
+
`The sending windows are open ${hours} hours a week, under ${limits.minWeeklyHours}.`
|
|
1714
|
+
] : [],
|
|
1715
|
+
...settings.dailyLimit !== null && average !== null && average >= settings.dailyLimit * limits.dailyLimitShare ? [
|
|
1716
|
+
`Recent sending days average ${average} sends against a daily limit of ${settings.dailyLimit}, so the limit is what holds volume back.`
|
|
1717
|
+
] : []
|
|
1718
|
+
];
|
|
1719
|
+
return reasons.length === 0 ? [] : [
|
|
1720
|
+
{
|
|
1721
|
+
code: "schedule_limits_volume",
|
|
1722
|
+
finding: reasons.join(" "),
|
|
1723
|
+
next: "Use settings_audit to review the schedule and the limits.",
|
|
1724
|
+
numbers: {
|
|
1725
|
+
averageDailySent: average,
|
|
1726
|
+
dailyLimit: settings.dailyLimit,
|
|
1727
|
+
weeklyHours: hours
|
|
1728
|
+
},
|
|
1729
|
+
severity: "low"
|
|
1730
|
+
}
|
|
1731
|
+
];
|
|
1732
|
+
};
|
|
1733
|
+
var CHECKS2 = [
|
|
1734
|
+
bounces,
|
|
1735
|
+
recentSends,
|
|
1736
|
+
senders,
|
|
1737
|
+
replies,
|
|
1738
|
+
volume,
|
|
1739
|
+
positives,
|
|
1740
|
+
sequence,
|
|
1741
|
+
schedule,
|
|
1742
|
+
tracking
|
|
1743
|
+
];
|
|
1744
|
+
var SEVERITY = { high: 0, low: 2, medium: 1 };
|
|
1745
|
+
var diagnose = (facts, limits) => CHECKS2.flatMap((check) => check(facts, limits)).toSorted(
|
|
1746
|
+
(left, right) => SEVERITY[left.severity] - SEVERITY[right.severity]
|
|
1747
|
+
);
|
|
1748
|
+
var unknownRates = (facts) => [
|
|
1749
|
+
...facts.rates.replyRate.rate === null ? ["Reply rate: the vendor reports no reply or volume count."] : [],
|
|
1750
|
+
...facts.rates.bounceRate.rate === null ? ["Bounce rate: the vendor reports no bounce or send count."] : [],
|
|
1751
|
+
...facts.totals.positive === null ? ["Positive replies: the vendor reports no positive reply count."] : []
|
|
1752
|
+
];
|
|
1753
|
+
|
|
1754
|
+
// src/insights/ops/campaign-diagnosis.ts
|
|
1755
|
+
var share = (fallback, text) => z9.number().min(0).max(1).default(fallback).describe(text);
|
|
1756
|
+
var input7 = z9.object({
|
|
1757
|
+
...rangeFields,
|
|
1758
|
+
campaign: z9.string().min(3).describe("The campaign's ref"),
|
|
1759
|
+
daily_limit_share: share(
|
|
1760
|
+
0.9,
|
|
1761
|
+
"Average daily sends at or over this share of the daily limit mean the limit holds volume back"
|
|
1762
|
+
),
|
|
1763
|
+
max_bounce_rate: share(0.03, "A bounce rate over this is a finding"),
|
|
1764
|
+
max_send_drop: share(
|
|
1765
|
+
0.3,
|
|
1766
|
+
"A fall in sends, recent days against the days before, over this share is a finding"
|
|
1767
|
+
),
|
|
1768
|
+
max_senders: z9.number().int().min(1).max(500).default(50).describe("The most senders of the campaign to read"),
|
|
1769
|
+
min_positive_share: share(
|
|
1770
|
+
0.2,
|
|
1771
|
+
"A share of replies that are positive under this is a finding"
|
|
1772
|
+
),
|
|
1773
|
+
min_reply_rate: share(0.01, "A reply rate under this is a finding"),
|
|
1774
|
+
min_sent: z9.number().int().min(0).default(100).describe("Under this many sends, rates are not judged"),
|
|
1775
|
+
min_weekly_hours: z9.number().min(0).max(168).default(20).describe("Sending windows open fewer hours a week than this limit volume"),
|
|
1776
|
+
recent_days: z9.number().int().min(1).max(30).default(7).describe(
|
|
1777
|
+
"The days, ending yesterday, held against the same number before"
|
|
1778
|
+
)
|
|
1779
|
+
});
|
|
1780
|
+
var readRecent = async (context, campaign, days) => {
|
|
1781
|
+
const recent = lastDays(context.now, days);
|
|
1782
|
+
const before = lastDays(context.now, days, 1);
|
|
1783
|
+
const series = await readDaily(context, campaign, {
|
|
1784
|
+
from: before.from,
|
|
1785
|
+
to: recent.to
|
|
1786
|
+
});
|
|
1787
|
+
const sentIn = (from, to) => series.flatMap(
|
|
1788
|
+
(day) => day.date >= from && day.date <= to ? [day.counts.sent] : []
|
|
1789
|
+
);
|
|
1790
|
+
const sends = sentIn(recent.from, recent.to);
|
|
1791
|
+
return {
|
|
1792
|
+
before: total(sentIn(before.from, before.to)),
|
|
1793
|
+
days,
|
|
1794
|
+
daysWithData: sends.filter((value) => value !== null).length,
|
|
1795
|
+
sent: total(sends)
|
|
1796
|
+
};
|
|
1797
|
+
};
|
|
1798
|
+
var readExtras = async (context, campaign, options) => {
|
|
1799
|
+
const { capabilities } = context.outbound;
|
|
1800
|
+
const handle = context.outbound.campaign(campaign);
|
|
1801
|
+
const notChecked = [];
|
|
1802
|
+
const unless = (missing2, what) => {
|
|
1803
|
+
if (missing2) {
|
|
1804
|
+
notChecked.push(what);
|
|
1805
|
+
context.note(what);
|
|
1806
|
+
}
|
|
1807
|
+
return !missing2;
|
|
1808
|
+
};
|
|
1809
|
+
const settings = unless(
|
|
1810
|
+
!capabilities["campaigns.settings"],
|
|
1811
|
+
"Schedule and tracking: the adapter does not serve campaign settings."
|
|
1812
|
+
) ? context.one(await handle.settings()) : null;
|
|
1813
|
+
const steps = unless(
|
|
1814
|
+
!capabilities.sequence,
|
|
1815
|
+
"Sequence length: the adapter does not serve sequences."
|
|
1816
|
+
) ? context.one(await handle.sequence()).steps.length : null;
|
|
1817
|
+
const senders2 = unless(
|
|
1818
|
+
!capabilities["senders.byCampaign"],
|
|
1819
|
+
"Sender status: the adapter cannot list a campaign's senders."
|
|
1820
|
+
) ? await readUpTo(
|
|
1821
|
+
context,
|
|
1822
|
+
(max) => handle.senders.listAll({ max }),
|
|
1823
|
+
options.maxSenders
|
|
1824
|
+
) : null;
|
|
1825
|
+
const recent = unless(
|
|
1826
|
+
capabilities["stats.byDay"] === false,
|
|
1827
|
+
"Recent sending trend: the adapter has no stats by day."
|
|
1828
|
+
) ? await readRecent(context, campaign, options.recentDays) : null;
|
|
1829
|
+
return {
|
|
1830
|
+
notChecked,
|
|
1831
|
+
recent,
|
|
1832
|
+
senders: senders2?.items ?? null,
|
|
1833
|
+
settings,
|
|
1834
|
+
steps
|
|
1835
|
+
};
|
|
1836
|
+
};
|
|
1837
|
+
var summarize = (findings) => {
|
|
1838
|
+
const [first] = findings;
|
|
1839
|
+
return first === void 0 ? "No problem was found in what could be checked." : `${findings.length} ${findings.length === 1 ? "finding" : "findings"}. Most serious: ${first.finding}`;
|
|
1840
|
+
};
|
|
1841
|
+
var campaignDiagnosis = defineInsight({
|
|
1842
|
+
description: "Why one campaign is underperforming: a list of findings, most serious first, each with a code, a plain-language finding, the numbers behind it and what to look at next. It checks for too little volume to judge, a low reply rate (with its 95% interval), a high bounce rate, few positive replies among replies, sends falling or stopped over the last days, a one or two step sequence, a sender that is not active, open tracking being off, and a schedule or daily limit that holds volume back. Also returns what could not be checked; an empty list means nothing was found, not that all is well. Costs up to 7 requests.",
|
|
1843
|
+
inputSchema: input7,
|
|
1844
|
+
key: "campaignDiagnosis",
|
|
1845
|
+
name: "campaign_diagnosis",
|
|
1846
|
+
needs: ["stats.campaign"],
|
|
1847
|
+
next: "Follow the `next` of the first finding, for example bounce_watch, step_funnel or pipeline_forecast.",
|
|
1848
|
+
run: async (context, options) => {
|
|
1849
|
+
const campaign = context.one(
|
|
1850
|
+
await context.outbound.campaigns.get(options.campaign)
|
|
1851
|
+
);
|
|
1852
|
+
const counts = await readTotals(context, campaign.ref, options);
|
|
1853
|
+
const extras = await readExtras(context, campaign.ref, {
|
|
1854
|
+
maxSenders: options.max_senders,
|
|
1855
|
+
recentDays: options.recent_days
|
|
1856
|
+
});
|
|
1857
|
+
const facts = {
|
|
1858
|
+
...extras,
|
|
1859
|
+
campaign,
|
|
1860
|
+
opened: counts.opened,
|
|
1861
|
+
rates: ratesOf(counts),
|
|
1862
|
+
totals: totalsOf(counts)
|
|
1863
|
+
};
|
|
1864
|
+
const findings = diagnose(facts, {
|
|
1865
|
+
dailyLimitShare: options.daily_limit_share,
|
|
1866
|
+
maxBounceRate: options.max_bounce_rate,
|
|
1867
|
+
maxSendDrop: options.max_send_drop,
|
|
1868
|
+
minPositiveShare: options.min_positive_share,
|
|
1869
|
+
minReplyRate: options.min_reply_rate,
|
|
1870
|
+
minSent: options.min_sent,
|
|
1871
|
+
minWeeklyHours: options.min_weekly_hours
|
|
1872
|
+
});
|
|
1873
|
+
const diagnosis = {
|
|
1874
|
+
...labelOf(campaign),
|
|
1875
|
+
findings,
|
|
1876
|
+
notChecked: [...extras.notChecked, ...unknownRates(facts)],
|
|
1877
|
+
period: { from: options.from, to: options.to },
|
|
1878
|
+
rates: facts.rates,
|
|
1879
|
+
summary: summarize(findings),
|
|
1880
|
+
totals: facts.totals
|
|
1881
|
+
};
|
|
1882
|
+
return diagnosis;
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
|
|
1886
|
+
// src/insights/ops/campaign-ranking.ts
|
|
1887
|
+
import { z as z10 } from "zod";
|
|
1888
|
+
var metricSchema2 = z10.enum([
|
|
1889
|
+
"reply_rate",
|
|
1890
|
+
"positive_reply_rate",
|
|
1891
|
+
"bounce_rate"
|
|
1892
|
+
]);
|
|
1893
|
+
var input8 = z10.object({
|
|
1894
|
+
...rangeFields,
|
|
1895
|
+
...listFields("one stats request"),
|
|
1896
|
+
metric: metricSchema2.default("reply_rate").describe("The rate to rank by. For bounce_rate, lower is better."),
|
|
1897
|
+
min_sent: z10.number().int().min(0).default(50).describe("Campaigns with fewer sends than this are left out of the rank")
|
|
1898
|
+
});
|
|
1899
|
+
var measured = (counts, metric) => {
|
|
1900
|
+
const rates = ratesOf(counts);
|
|
1901
|
+
if (metric === "bounce_rate") {
|
|
1902
|
+
return rates.bounceRate;
|
|
1903
|
+
}
|
|
1904
|
+
return metric === "reply_rate" ? rates.replyRate : rates.positiveRate;
|
|
1905
|
+
};
|
|
1906
|
+
var order = (metric) => (left, right) => (metric === "bounce_rate" ? descending(right.high, left.high) || descending(right.rate, left.rate) : descending(left.low, right.low) || descending(left.rate, right.rate)) || left.name.localeCompare(right.name);
|
|
1907
|
+
var rankCampaigns = (entries, metric, minSent) => {
|
|
1908
|
+
const scored = [];
|
|
1909
|
+
const tooFewSends = [];
|
|
1910
|
+
const unknown = [];
|
|
1911
|
+
for (const { campaign, counts } of entries) {
|
|
1912
|
+
const label = labelOf(campaign);
|
|
1913
|
+
const volume2 = volumeOf(counts);
|
|
1914
|
+
const result = measured(counts, metric);
|
|
1915
|
+
if (volume2 === null) {
|
|
1916
|
+
unknown.push({
|
|
1917
|
+
...label,
|
|
1918
|
+
reason: "The vendor reports no sends for this period.",
|
|
1919
|
+
sent: null
|
|
1920
|
+
});
|
|
1921
|
+
} else if (volume2 < minSent) {
|
|
1922
|
+
tooFewSends.push({
|
|
1923
|
+
...label,
|
|
1924
|
+
reason: `${volume2} sends, under the ${minSent} needed to rank.`,
|
|
1925
|
+
sent: volume2
|
|
1926
|
+
});
|
|
1927
|
+
} else if (result.rate === null) {
|
|
1928
|
+
unknown.push({
|
|
1929
|
+
...label,
|
|
1930
|
+
reason: "The vendor does not report the count behind this rate.",
|
|
1931
|
+
sent: volume2
|
|
1932
|
+
});
|
|
1933
|
+
} else {
|
|
1934
|
+
scored.push({ ...label, ...result, sent: volume2 });
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
const ranked = scored.toSorted(order(metric)).map((entry, index) => ({ ...entry, rank: index + 1 }));
|
|
1938
|
+
const top = ranked[0]?.rate ?? null;
|
|
1939
|
+
const middle = median(ranked.flatMap((entry) => entry.rate ?? []));
|
|
1940
|
+
return {
|
|
1941
|
+
gap: {
|
|
1942
|
+
difference: top === null || middle === null ? null : round(top - middle),
|
|
1943
|
+
median: round(middle),
|
|
1944
|
+
top
|
|
1945
|
+
},
|
|
1946
|
+
ranked,
|
|
1947
|
+
tooFewSends,
|
|
1948
|
+
unknown
|
|
1949
|
+
};
|
|
1950
|
+
};
|
|
1951
|
+
var campaignRanking = defineInsight({
|
|
1952
|
+
description: "Which campaigns are best, ranked fairly: by the low end of the 95% Wilson interval of the reply rate (or positive reply rate; for bounce rate, by the high end, lowest first), so 2 replies from 10 sends cannot outrank 150 from 1,000. Use it to pick winners and losers across a workspace. Returns each campaign with its count, rate, interval and rank, the campaigns left out for too few sends, those whose count the vendor does not report (a null rate is unknown, not zero), and the gap between the top and the median. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
|
|
1953
|
+
inputSchema: input8,
|
|
1954
|
+
key: "campaignRanking",
|
|
1955
|
+
name: "campaign_ranking",
|
|
1956
|
+
needs: ["stats.campaign"],
|
|
1957
|
+
next: "Use campaign_diagnosis on the campaign ranked last to see why it is behind.",
|
|
1958
|
+
run: async (context, options) => {
|
|
1959
|
+
const entries = await readCampaignTotals(context, options);
|
|
1960
|
+
const ranking = {
|
|
1961
|
+
...rankCampaigns(entries, options.metric, options.min_sent),
|
|
1962
|
+
better: options.metric === "bounce_rate" ? "lower" : "higher",
|
|
1963
|
+
metric: options.metric,
|
|
1964
|
+
period: { from: options.from, to: options.to }
|
|
1965
|
+
};
|
|
1966
|
+
return ranking;
|
|
1967
|
+
}
|
|
1968
|
+
});
|
|
1969
|
+
|
|
1970
|
+
// src/insights/ops/channel-mix.ts
|
|
1971
|
+
import { z as z11 } from "zod";
|
|
1972
|
+
var input9 = z11.object({
|
|
1973
|
+
...rangeFields,
|
|
1974
|
+
...listFields("one stats request"),
|
|
1975
|
+
alpha: z11.number().gt(0).lt(1).default(0.05).describe(
|
|
1976
|
+
"The p-value under which a difference counts as more than chance"
|
|
1977
|
+
)
|
|
1978
|
+
});
|
|
1979
|
+
var groupOf = (channel, entries) => {
|
|
1980
|
+
const counts = entries.map((entry) => entry.counts);
|
|
1981
|
+
const reply = measureAcross(counts, (row) => row.replied, perLeadBase);
|
|
1982
|
+
const positive = measureAcross(counts, (row) => row.positive, perLeadBase);
|
|
1983
|
+
const acceptance = measureAcross(
|
|
1984
|
+
counts,
|
|
1985
|
+
(row) => row.connectionsAccepted,
|
|
1986
|
+
(row) => row.connectionsSent
|
|
1987
|
+
);
|
|
1988
|
+
return {
|
|
1989
|
+
group: {
|
|
1990
|
+
...totalsOf(sumCounts(counts)),
|
|
1991
|
+
acceptance: channel === "linkedin" ? acceptance.measured : null,
|
|
1992
|
+
campaigns: entries.length,
|
|
1993
|
+
channel,
|
|
1994
|
+
positiveRate: positive.measured,
|
|
1995
|
+
replyRate: reply.measured
|
|
1996
|
+
},
|
|
1997
|
+
partial: [
|
|
1998
|
+
...partialRate("reply rate", reply),
|
|
1999
|
+
...partialRate("positive reply rate", positive),
|
|
2000
|
+
...channel === "linkedin" ? partialRate("acceptance rate", acceptance) : []
|
|
2001
|
+
]
|
|
2002
|
+
};
|
|
2003
|
+
};
|
|
2004
|
+
var CHANNELS = ["email", "linkedin"];
|
|
2005
|
+
var byChannel = (entries) => CHANNELS.flatMap((channel) => {
|
|
2006
|
+
const members = entries.filter(
|
|
2007
|
+
(entry) => entry.campaign.channel === channel
|
|
2008
|
+
);
|
|
2009
|
+
return members.length === 0 ? [] : [groupOf(channel, members)];
|
|
2010
|
+
});
|
|
2011
|
+
var byProvider = (entries) => [...new Set(entries.map((entry) => entry.campaign.provider))].toSorted().flatMap(
|
|
2012
|
+
(provider) => byChannel(
|
|
2013
|
+
entries.filter((entry) => entry.campaign.provider === provider)
|
|
2014
|
+
).map(({ group, partial }) => ({
|
|
2015
|
+
group: { ...group, provider },
|
|
2016
|
+
partial
|
|
2017
|
+
}))
|
|
2018
|
+
);
|
|
2019
|
+
var NAMES = { email: "email", linkedin: "LinkedIn" };
|
|
2020
|
+
var compare = (groups, alpha) => {
|
|
2021
|
+
const [first, second] = groups;
|
|
2022
|
+
if (first === void 0) {
|
|
2023
|
+
return {
|
|
2024
|
+
comparison: null,
|
|
2025
|
+
finding: "No campaigns were found, so there is nothing to compare."
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
if (second === void 0) {
|
|
2029
|
+
return {
|
|
2030
|
+
comparison: null,
|
|
2031
|
+
finding: `Only ${NAMES[first.channel]} campaigns were found, so there is nothing to compare.`
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
const test = compareRates(
|
|
2035
|
+
{ successes: first.replyRate.count, trials: first.replyRate.of },
|
|
2036
|
+
{ successes: second.replyRate.count, trials: second.replyRate.of },
|
|
2037
|
+
alpha
|
|
2038
|
+
);
|
|
2039
|
+
if (test === null) {
|
|
2040
|
+
return {
|
|
2041
|
+
comparison: null,
|
|
2042
|
+
finding: "Reply rates cannot be compared: a channel has no reply or volume counts, or neither has a reply."
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
const [higher, lower] = test.z >= 0 ? [first, second] : [second, first];
|
|
2046
|
+
return {
|
|
2047
|
+
comparison: {
|
|
2048
|
+
difference: round((higher.replyRate.rate ?? 0) - (lower.replyRate.rate ?? 0)) ?? 0,
|
|
2049
|
+
higher: higher.channel,
|
|
2050
|
+
test
|
|
2051
|
+
},
|
|
2052
|
+
finding: `The reply rate is ${percent(higher.replyRate.rate)} on ${NAMES[higher.channel]} against ${percent(lower.replyRate.rate)} on ${NAMES[lower.channel]}; ${test.significant ? "the difference is more than chance" : "the difference could be chance"} (${pText(test.pValue)}).`
|
|
2053
|
+
};
|
|
2054
|
+
};
|
|
2055
|
+
var channelMix = defineInsight({
|
|
2056
|
+
description: "Email against LinkedIn: campaign totals added up per channel, with campaigns, leads contacted, messages sent, replies, positive replies, the reply rate with its 95% interval and, for LinkedIn, the connection acceptance rate; whether the difference in reply rate is more than chance (a two-proportion test); and the same numbers per tool. Use it to decide where to put volume. With one channel present it returns that channel and says there is nothing to compare. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a group whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
|
|
2057
|
+
inputSchema: input9,
|
|
2058
|
+
key: "channelMix",
|
|
2059
|
+
name: "channel_mix",
|
|
2060
|
+
needs: ["stats.campaign"],
|
|
2061
|
+
next: "Use campaign_ranking to see which campaigns carry the better channel.",
|
|
2062
|
+
run: async (context, options) => {
|
|
2063
|
+
const entries = await readCampaignTotals(context, options);
|
|
2064
|
+
const channels = byChannel(entries);
|
|
2065
|
+
const providers = byProvider(entries);
|
|
2066
|
+
for (const { group, partial } of channels) {
|
|
2067
|
+
if (partial.length > 0) {
|
|
2068
|
+
context.note(partialNote(`Channel ${group.channel}`, partial));
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
for (const { group, partial } of providers) {
|
|
2072
|
+
if (partial.length > 0) {
|
|
2073
|
+
context.note(
|
|
2074
|
+
partialNote(`${group.provider} ${group.channel}`, partial)
|
|
2075
|
+
);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
const mix = {
|
|
2079
|
+
...compare(
|
|
2080
|
+
channels.map((each) => each.group),
|
|
2081
|
+
options.alpha
|
|
2082
|
+
),
|
|
2083
|
+
byProvider: providers.map((each) => each.group),
|
|
2084
|
+
channels: channels.map((each) => each.group),
|
|
2085
|
+
period: { from: options.from, to: options.to }
|
|
2086
|
+
};
|
|
2087
|
+
return mix;
|
|
2088
|
+
}
|
|
2089
|
+
});
|
|
2090
|
+
|
|
2091
|
+
// src/insights/ops/client-report.ts
|
|
2092
|
+
import { z as z14 } from "zod";
|
|
2093
|
+
|
|
2094
|
+
// src/insights/ops/period-comparison.ts
|
|
2095
|
+
import { z as z12 } from "zod";
|
|
2096
|
+
var input10 = z12.object({
|
|
2097
|
+
...listFields("two stats requests"),
|
|
2098
|
+
alpha: z12.number().gt(0).lt(1).default(0.05).describe("The p-value under which a change counts as more than chance"),
|
|
2099
|
+
days: z12.number().int().min(1).max(90).default(7).describe("The length of each period, in complete days ending yesterday"),
|
|
2100
|
+
min_sent: z12.number().int().min(0).default(50).describe(
|
|
2101
|
+
"A campaign under this many sends in either period is listed apart"
|
|
2102
|
+
)
|
|
2103
|
+
});
|
|
2104
|
+
var numbersOf = (counts, rates) => ({
|
|
2105
|
+
...totalsOf(counts),
|
|
2106
|
+
bounceRate: rates.bounceRate.rate,
|
|
2107
|
+
positiveRate: rates.positiveRate.rate,
|
|
2108
|
+
replyRate: rates.replyRate.rate
|
|
2109
|
+
});
|
|
2110
|
+
var minus = (current, previous) => current === null || previous === null ? null : round(current - previous);
|
|
2111
|
+
var changeOf = (current, previous) => ({
|
|
2112
|
+
bounceRate: minus(current.bounceRate, previous.bounceRate),
|
|
2113
|
+
bounced: minus(current.bounced, previous.bounced),
|
|
2114
|
+
contacted: minus(current.contacted, previous.contacted),
|
|
2115
|
+
positive: minus(current.positive, previous.positive),
|
|
2116
|
+
positiveRate: minus(current.positiveRate, previous.positiveRate),
|
|
2117
|
+
replied: minus(current.replied, previous.replied),
|
|
2118
|
+
replyRate: minus(current.replyRate, previous.replyRate),
|
|
2119
|
+
sent: minus(current.sent, previous.sent)
|
|
2120
|
+
});
|
|
2121
|
+
var verdictOf = (test) => {
|
|
2122
|
+
if (test === null) {
|
|
2123
|
+
return "unknown";
|
|
2124
|
+
}
|
|
2125
|
+
if (!test.significant) {
|
|
2126
|
+
return "no_real_change";
|
|
2127
|
+
}
|
|
2128
|
+
return test.z > 0 ? "up" : "down";
|
|
2129
|
+
};
|
|
2130
|
+
var compare2 = (current, previous, alpha) => {
|
|
2131
|
+
const now = current.rates.replyRate;
|
|
2132
|
+
const before = previous.rates.replyRate;
|
|
2133
|
+
const test = compareRates(
|
|
2134
|
+
{ successes: now.count, trials: now.of },
|
|
2135
|
+
{ successes: before.count, trials: before.of },
|
|
2136
|
+
alpha
|
|
2137
|
+
);
|
|
2138
|
+
const moved = `Reply rate went from ${percent(before.rate)} to ${percent(now.rate)}`;
|
|
2139
|
+
const numbers = numbersOf(current.counts, current.rates);
|
|
2140
|
+
const earlier = numbersOf(previous.counts, previous.rates);
|
|
2141
|
+
return {
|
|
2142
|
+
change: changeOf(numbers, earlier),
|
|
2143
|
+
current: numbers,
|
|
2144
|
+
finding: test === null ? "Reply rate cannot be compared: a period has no reply or volume counts, or neither has a reply." : `${moved}; ${test.significant ? "more than chance" : "within what chance would give"} (${pText(test.pValue)}).`,
|
|
2145
|
+
previous: earlier,
|
|
2146
|
+
replyRateTest: test,
|
|
2147
|
+
verdict: verdictOf(test)
|
|
2148
|
+
};
|
|
2149
|
+
};
|
|
2150
|
+
var comparePeriods = (current, previous, alpha) => compare2(
|
|
2151
|
+
{ counts: current, rates: ratesOf(current) },
|
|
2152
|
+
{ counts: previous, rates: ratesOf(previous) },
|
|
2153
|
+
alpha
|
|
2154
|
+
);
|
|
2155
|
+
var compareAcross = (current, previous, alpha) => {
|
|
2156
|
+
const now = ratesAcross(current);
|
|
2157
|
+
const before = ratesAcross(previous);
|
|
2158
|
+
return {
|
|
2159
|
+
comparison: compare2(
|
|
2160
|
+
{ counts: sumCounts(current), rates: now.rates },
|
|
2161
|
+
{ counts: sumCounts(previous), rates: before.rates },
|
|
2162
|
+
alpha
|
|
2163
|
+
),
|
|
2164
|
+
partial: [
|
|
2165
|
+
...now.partial.map((each) => `this period's ${each}`),
|
|
2166
|
+
...before.partial.map((each) => `the earlier period's ${each}`)
|
|
2167
|
+
]
|
|
2168
|
+
};
|
|
2169
|
+
};
|
|
2170
|
+
var readPeriods = async (context, options) => {
|
|
2171
|
+
const current = lastDays(context.now, options.days);
|
|
2172
|
+
const previous = lastDays(context.now, options.days, 1);
|
|
2173
|
+
const found = await readCampaigns(
|
|
2174
|
+
context,
|
|
2175
|
+
options.statuses,
|
|
2176
|
+
options.max_campaigns
|
|
2177
|
+
);
|
|
2178
|
+
const campaigns = await mapConcurrent(
|
|
2179
|
+
found,
|
|
2180
|
+
async (campaign) => {
|
|
2181
|
+
const [now, before] = await Promise.all([
|
|
2182
|
+
readTotals(context, campaign.ref, current),
|
|
2183
|
+
readTotals(context, campaign.ref, previous)
|
|
2184
|
+
]);
|
|
2185
|
+
return { campaign, current: now, previous: before };
|
|
2186
|
+
}
|
|
2187
|
+
);
|
|
2188
|
+
return { campaigns, current, previous };
|
|
2189
|
+
};
|
|
2190
|
+
var totalOf = (campaigns, alpha) => compareAcross(
|
|
2191
|
+
campaigns.map((entry) => entry.current),
|
|
2192
|
+
campaigns.map((entry) => entry.previous),
|
|
2193
|
+
alpha
|
|
2194
|
+
);
|
|
2195
|
+
var noted = (context, where, across, rows) => {
|
|
2196
|
+
if (across.partial.length > 0) {
|
|
2197
|
+
context.note(partialNote(where, across.partial, rows));
|
|
2198
|
+
}
|
|
2199
|
+
return across.comparison;
|
|
2200
|
+
};
|
|
2201
|
+
var workspaceOf = async (context, periods, alpha) => {
|
|
2202
|
+
const { outbound } = context;
|
|
2203
|
+
if (outbound.capabilities["stats.workspace"] === false) {
|
|
2204
|
+
context.note(
|
|
2205
|
+
"Workspace totals were left out: the adapter has no workspace stats. `total` adds up the campaigns read."
|
|
2206
|
+
);
|
|
2207
|
+
return null;
|
|
2208
|
+
}
|
|
2209
|
+
const current = context.rows(await outbound.stats(periods.current));
|
|
2210
|
+
const previous = context.rows(await outbound.stats(periods.previous));
|
|
2211
|
+
return noted(
|
|
2212
|
+
context,
|
|
2213
|
+
"Workspace totals",
|
|
2214
|
+
compareAcross(current, previous, alpha),
|
|
2215
|
+
"tools"
|
|
2216
|
+
);
|
|
2217
|
+
};
|
|
2218
|
+
var periodComparison = defineInsight({
|
|
2219
|
+
description: "This period against the last: for each campaign, counts and rates for the last `days` complete days and for the `days` before, the change in each, and whether the change in reply rate is more than chance (a two-proportion test), with the campaigns sorted by the size of that change. Also the same for every campaign added together and, where the adapter has them, for the vendor's workspace totals. Use it for a weekly review. Campaigns under min_sent sends in either period are listed apart; a null is a count the vendor does not report, and a rate of a total counts only the campaigns that report both its count and what it divides by (a note says when some are left out). Costs two stats requests per campaign plus two for the workspace.",
|
|
2220
|
+
inputSchema: input10,
|
|
2221
|
+
key: "periodComparison",
|
|
2222
|
+
name: "period_comparison",
|
|
2223
|
+
needs: ["stats.campaign"],
|
|
2224
|
+
next: "Use campaign_diagnosis on the campaign whose reply rate fell the most.",
|
|
2225
|
+
run: async (context, options) => {
|
|
2226
|
+
const periods = await readPeriods(context, options);
|
|
2227
|
+
const campaigns = [];
|
|
2228
|
+
const tooFewSends = [];
|
|
2229
|
+
for (const { campaign, current, previous } of periods.campaigns) {
|
|
2230
|
+
const sent = [volumeOf(current), volumeOf(previous)];
|
|
2231
|
+
if (sent.some((volume2) => (volume2 ?? -1) < options.min_sent)) {
|
|
2232
|
+
tooFewSends.push({
|
|
2233
|
+
...labelOf(campaign),
|
|
2234
|
+
currentSent: sent[0],
|
|
2235
|
+
previousSent: sent[1]
|
|
2236
|
+
});
|
|
2237
|
+
} else {
|
|
2238
|
+
campaigns.push({
|
|
2239
|
+
...labelOf(campaign),
|
|
2240
|
+
...comparePeriods(current, previous, options.alpha)
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
const comparison = {
|
|
2245
|
+
campaigns: campaigns.toSorted(
|
|
2246
|
+
(left, right) => descending(
|
|
2247
|
+
left.change.replyRate === null ? null : Math.abs(left.change.replyRate),
|
|
2248
|
+
right.change.replyRate === null ? null : Math.abs(right.change.replyRate)
|
|
2249
|
+
) || left.name.localeCompare(right.name)
|
|
2250
|
+
),
|
|
2251
|
+
current: periods.current,
|
|
2252
|
+
days: options.days,
|
|
2253
|
+
previous: periods.previous,
|
|
2254
|
+
tooFewSends,
|
|
2255
|
+
total: noted(
|
|
2256
|
+
context,
|
|
2257
|
+
"Every campaign added together",
|
|
2258
|
+
totalOf(periods.campaigns, options.alpha)
|
|
2259
|
+
),
|
|
2260
|
+
workspace: await workspaceOf(context, periods, options.alpha)
|
|
2261
|
+
};
|
|
2262
|
+
return comparison;
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2265
|
+
|
|
2266
|
+
// src/insights/ops/pipeline-forecast.ts
|
|
2267
|
+
import { z as z13 } from "zod";
|
|
2268
|
+
var input11 = z13.object({
|
|
2269
|
+
campaign: z13.string().min(3).describe("The campaign's ref"),
|
|
2270
|
+
days: z13.number().int().min(1).max(60).default(7).describe("How many complete days, ending yesterday, set the daily pace"),
|
|
2271
|
+
max_leads: z13.number().int().min(1).max(5e4).default(2e3).describe("The most leads to read. A page of leads is one request.")
|
|
2272
|
+
});
|
|
2273
|
+
var countStatuses = (leads) => {
|
|
2274
|
+
const counts = {
|
|
2275
|
+
active: 0,
|
|
2276
|
+
bounced: 0,
|
|
2277
|
+
completed: 0,
|
|
2278
|
+
paused: 0,
|
|
2279
|
+
replied: 0,
|
|
2280
|
+
unknown: 0,
|
|
2281
|
+
unsubscribed: 0
|
|
2282
|
+
};
|
|
2283
|
+
for (const lead of leads) {
|
|
2284
|
+
counts[lead.status] += 1;
|
|
2285
|
+
}
|
|
2286
|
+
return counts;
|
|
2287
|
+
};
|
|
2288
|
+
var times = (leads, share2) => share2 === null ? null : round(leads * share2);
|
|
2289
|
+
var project = (leads, measured2) => ({
|
|
2290
|
+
expected: times(leads, measured2.rate),
|
|
2291
|
+
high: times(leads, measured2.high),
|
|
2292
|
+
low: times(leads, measured2.low)
|
|
2293
|
+
});
|
|
2294
|
+
var paceOf = async (context, campaign, days) => {
|
|
2295
|
+
if (context.outbound.capabilities["stats.byDay"] === false) {
|
|
2296
|
+
context.note(
|
|
2297
|
+
"Days of sending left were not estimated: the adapter has no stats by day."
|
|
2298
|
+
);
|
|
2299
|
+
return null;
|
|
2300
|
+
}
|
|
2301
|
+
const series = await readDaily(
|
|
2302
|
+
context,
|
|
2303
|
+
campaign,
|
|
2304
|
+
lastDays(context.now, days)
|
|
2305
|
+
);
|
|
2306
|
+
const contacted = total(series.map((day) => day.counts.contacted));
|
|
2307
|
+
return contacted === null ? null : round(contacted / days);
|
|
2308
|
+
};
|
|
2309
|
+
var ASSUMPTIONS = [
|
|
2310
|
+
"Every remaining lead is contacted.",
|
|
2311
|
+
"Remaining leads reply at the rate the campaign has had so far; leads already partway through the sequence may reply less.",
|
|
2312
|
+
"The daily pace stays what it was over the recent days. Days with no report count as no sends."
|
|
2313
|
+
];
|
|
2314
|
+
var describe2 = (remaining, complete, forecast) => {
|
|
2315
|
+
const leads = `${complete ? "" : "At least "}${remaining} leads remain`;
|
|
2316
|
+
return forecast.expected === null ? `${leads}; replies cannot be estimated because the vendor reports no reply rate yet.` : `${leads}; expect about ${forecast.expected} replies (between ${forecast.low} and ${forecast.high}). This is an estimate.`;
|
|
2317
|
+
};
|
|
2318
|
+
var forecastCampaign = async (context, campaign, options) => {
|
|
2319
|
+
const handle = context.outbound.campaign(campaign.ref);
|
|
2320
|
+
const { complete, items: leads } = await readUpTo(
|
|
2321
|
+
context,
|
|
2322
|
+
(max) => handle.leads.listAll({ max }),
|
|
2323
|
+
options.maxLeads
|
|
2324
|
+
);
|
|
2325
|
+
const byStatus = countStatuses(leads);
|
|
2326
|
+
const remaining = byStatus.active;
|
|
2327
|
+
const rates = ratesOf(
|
|
2328
|
+
await readTotals(context, campaign.ref, { from: null, to: null })
|
|
2329
|
+
);
|
|
2330
|
+
const pace = await paceOf(context, campaign.ref, options.days);
|
|
2331
|
+
const expectedReplies = project(remaining, rates.replyRate);
|
|
2332
|
+
return {
|
|
2333
|
+
...labelOf(campaign),
|
|
2334
|
+
assumptions: [
|
|
2335
|
+
...ASSUMPTIONS,
|
|
2336
|
+
`The reply rate so far is ${percent(rates.replyRate.rate)}, from ${rates.replyRate.count ?? "unknown"} replies over ${rates.replyRate.of ?? "unknown"}.`
|
|
2337
|
+
],
|
|
2338
|
+
byStatus,
|
|
2339
|
+
dailyContactRate: pace,
|
|
2340
|
+
daysLeft: pace === null || pace <= 0 ? null : round(remaining / pace),
|
|
2341
|
+
estimate: true,
|
|
2342
|
+
expectedPositive: project(remaining, rates.positiveRate),
|
|
2343
|
+
expectedReplies,
|
|
2344
|
+
finding: describe2(remaining, complete, expectedReplies),
|
|
2345
|
+
leadsComplete: complete,
|
|
2346
|
+
leadsRead: leads.length,
|
|
2347
|
+
positiveRate: rates.positiveRate,
|
|
2348
|
+
remaining,
|
|
2349
|
+
replyRate: rates.replyRate
|
|
2350
|
+
};
|
|
2351
|
+
};
|
|
2352
|
+
var pipelineForecast = defineInsight({
|
|
2353
|
+
description: "The leads one campaign has left and what they should produce: leads counted by status, the leads still active, the days of sending left at the recent daily contact rate, and the replies and positive replies to expect from the remaining leads at the campaign's reply rate so far, each with a low and a high figure from the 95% interval. Use it to decide when to load more leads. It is an estimate and lists what it assumes; a null means the vendor does not report the count behind it. Costs one request per page of leads, plus two stats requests.",
|
|
2354
|
+
inputSchema: input11,
|
|
2355
|
+
key: "pipelineForecast",
|
|
2356
|
+
name: "pipeline_forecast",
|
|
2357
|
+
needs: ["leads.byCampaign", "stats.campaign"],
|
|
2358
|
+
next: "Use client_report to see every campaign that is running out of leads.",
|
|
2359
|
+
run: async (context, options) => {
|
|
2360
|
+
const campaign = context.one(
|
|
2361
|
+
await context.outbound.campaigns.get(options.campaign)
|
|
2362
|
+
);
|
|
2363
|
+
return await forecastCampaign(context, campaign, {
|
|
2364
|
+
days: options.days,
|
|
2365
|
+
maxLeads: options.max_leads
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
|
|
2370
|
+
// src/insights/ops/client-report.ts
|
|
2371
|
+
var input12 = z14.object({
|
|
2372
|
+
...listFields(
|
|
2373
|
+
"two stats requests, and three more plus its leads when active"
|
|
2374
|
+
),
|
|
2375
|
+
alpha: z14.number().gt(0).lt(1).default(0.05).describe("The p-value under which a change counts as more than chance"),
|
|
2376
|
+
anomaly_threshold: z14.number().positive().default(2.5).describe("Standard deviations from the baseline that make a day unusual"),
|
|
2377
|
+
baseline_days: z14.number().int().min(5).max(60).default(14).describe("Days before the period that form the anomaly baseline"),
|
|
2378
|
+
days: z14.number().int().min(1).max(90).default(7).describe("The length of the period, in complete days ending yesterday"),
|
|
2379
|
+
max_bounce_rate: z14.number().min(0).max(1).default(0.03).describe("A campaign bounce rate over this is a bounce problem"),
|
|
2380
|
+
max_leads_per_campaign: z14.number().int().min(1).max(5e4).default(500).describe("The most leads to read per active campaign, for leads left"),
|
|
2381
|
+
min_baseline_points: z14.number().int().min(2).default(5).describe("The fewest baseline days with data a day needs to be tested"),
|
|
2382
|
+
min_sent: z14.number().int().min(0).default(50).describe("Campaigns under this many sends in the period are not judged"),
|
|
2383
|
+
runway_days: z14.number().min(0).default(7).describe(
|
|
2384
|
+
"A campaign with this many days of leads left or fewer is flagged"
|
|
2385
|
+
),
|
|
2386
|
+
top: z14.number().int().min(1).max(20).default(3).describe("How many best and worst campaigns to show")
|
|
2387
|
+
});
|
|
2388
|
+
var bounceProblems = (campaigns, options) => campaigns.flatMap(({ campaign, current }) => {
|
|
2389
|
+
const { count, high, low, of, rate: rate2 } = ratesOf(current).bounceRate;
|
|
2390
|
+
return rate2 !== null && rate2 > options.max_bounce_rate && (volumeOf(current) ?? -1) >= options.min_sent ? [{ ...labelOf(campaign), bounced: count, high, low, rate: rate2, sent: of }] : [];
|
|
2391
|
+
}).toSorted((left, right) => right.rate - left.rate);
|
|
2392
|
+
var readAnomalies = async (context, period, options) => {
|
|
2393
|
+
const { capabilities } = context.outbound;
|
|
2394
|
+
if (capabilities["stats.byDay"] === false || capabilities["stats.workspace"] === false) {
|
|
2395
|
+
return null;
|
|
2396
|
+
}
|
|
2397
|
+
const series = await readDaily(context, null, {
|
|
2398
|
+
from: shiftDay(period.from, -options.baseline_days),
|
|
2399
|
+
to: period.to
|
|
2400
|
+
});
|
|
2401
|
+
return [
|
|
2402
|
+
...findAnomalies(series, {
|
|
2403
|
+
baselineDays: options.baseline_days,
|
|
2404
|
+
firstDay: period.from,
|
|
2405
|
+
metrics: ["sent", "replied", "bounced"],
|
|
2406
|
+
minBaselinePoints: options.min_baseline_points,
|
|
2407
|
+
threshold: options.anomaly_threshold
|
|
2408
|
+
}).anomalies
|
|
2409
|
+
];
|
|
2410
|
+
};
|
|
2411
|
+
var readRunways = async (context, campaigns, options) => {
|
|
2412
|
+
const { capabilities } = context.outbound;
|
|
2413
|
+
if (!capabilities["leads.byCampaign"] || capabilities["stats.byDay"] === false) {
|
|
2414
|
+
return null;
|
|
2415
|
+
}
|
|
2416
|
+
const active = campaigns.flatMap(
|
|
2417
|
+
({ campaign }) => campaign.status === "active" ? [campaign] : []
|
|
2418
|
+
);
|
|
2419
|
+
const forecasts = await mapConcurrent(active, async (campaign) => ({
|
|
2420
|
+
campaign,
|
|
2421
|
+
forecast: await forecastCampaign(context, campaign, {
|
|
2422
|
+
days: options.days,
|
|
2423
|
+
maxLeads: options.max_leads_per_campaign
|
|
2424
|
+
})
|
|
2425
|
+
}));
|
|
2426
|
+
const runways = forecasts.flatMap(
|
|
2427
|
+
({ campaign, forecast }) => forecast.leadsComplete && forecast.daysLeft !== null && forecast.daysLeft <= options.runway_days ? [
|
|
2428
|
+
{
|
|
2429
|
+
...labelOf(campaign),
|
|
2430
|
+
dailyContactRate: forecast.dailyContactRate,
|
|
2431
|
+
daysLeft: forecast.daysLeft,
|
|
2432
|
+
remaining: forecast.remaining
|
|
2433
|
+
}
|
|
2434
|
+
] : []
|
|
2435
|
+
);
|
|
2436
|
+
return runways.toSorted((left, right) => left.daysLeft - right.daysLeft);
|
|
2437
|
+
};
|
|
2438
|
+
var actionsOf = (report) => {
|
|
2439
|
+
const [worst] = report.bottom;
|
|
2440
|
+
const { current, previous } = report.totals;
|
|
2441
|
+
return [
|
|
2442
|
+
...report.bounceProblems.map((problem) => ({
|
|
2443
|
+
action: `Fix the bounces of ${problem.name}: its bounce rate is ${percent(problem.rate)} (${problem.bounced} of ${problem.sent} sends).`,
|
|
2444
|
+
campaign: problem.campaign,
|
|
2445
|
+
campaignName: problem.name,
|
|
2446
|
+
kind: "fix_bounces",
|
|
2447
|
+
number: problem.rate
|
|
2448
|
+
})),
|
|
2449
|
+
...(report.runningOutOfLeads ?? []).map((runway) => ({
|
|
2450
|
+
action: `Add leads to ${runway.name}: ${runway.remaining} leads remain, about ${runway.daysLeft} days of sending.`,
|
|
2451
|
+
campaign: runway.campaign,
|
|
2452
|
+
campaignName: runway.name,
|
|
2453
|
+
kind: "add_leads",
|
|
2454
|
+
number: runway.daysLeft
|
|
2455
|
+
})),
|
|
2456
|
+
...report.totals.verdict === "down" ? [
|
|
2457
|
+
{
|
|
2458
|
+
action: `Find out what changed: the reply rate fell from ${percent(previous.replyRate)} to ${percent(current.replyRate)}, more than chance would give.`,
|
|
2459
|
+
campaign: null,
|
|
2460
|
+
campaignName: null,
|
|
2461
|
+
kind: "reply_rate_fell",
|
|
2462
|
+
number: report.totals.change.replyRate
|
|
2463
|
+
}
|
|
2464
|
+
] : [],
|
|
2465
|
+
...worst === void 0 ? [] : [
|
|
2466
|
+
{
|
|
2467
|
+
action: `Review the copy and the audience of ${worst.name}: it has the weakest reply rate, ${percent(worst.rate)} (${worst.count} of ${worst.of}).`,
|
|
2468
|
+
campaign: worst.campaign,
|
|
2469
|
+
campaignName: worst.name,
|
|
2470
|
+
kind: "review_campaign",
|
|
2471
|
+
number: worst.rate
|
|
2472
|
+
}
|
|
2473
|
+
],
|
|
2474
|
+
...(report.anomalies ?? []).map((anomaly) => ({
|
|
2475
|
+
action: `Check what happened on ${anomaly.date}: ${anomaly.finding}`,
|
|
2476
|
+
campaign: null,
|
|
2477
|
+
campaignName: null,
|
|
2478
|
+
kind: "check_anomaly",
|
|
2479
|
+
number: anomaly.value
|
|
2480
|
+
}))
|
|
2481
|
+
];
|
|
2482
|
+
};
|
|
2483
|
+
var clientReport = defineInsight({
|
|
2484
|
+
description: "One report for one client or workspace over the last `days` complete days: totals and the change from the period before, the best and worst campaigns by the low end of the reply rate interval, campaigns with a bounce problem, unusual days, active campaigns running out of leads, and a short list of action items in plain language, each naming the campaign and the number behind it. Use it for a weekly client update. A section the adapter cannot serve is null and named in `leftOut`, and a null count is one the vendor does not report. Costs two stats requests per campaign, one for the workspace, and for each active campaign two more plus its pages of leads.",
|
|
2485
|
+
inputSchema: input12,
|
|
2486
|
+
key: "clientReport",
|
|
2487
|
+
name: "client_report",
|
|
2488
|
+
needs: ["stats.campaign"],
|
|
2489
|
+
next: "Use campaign_diagnosis on a campaign an action item names, or period_comparison for every campaign's change.",
|
|
2490
|
+
run: async (context, options) => {
|
|
2491
|
+
const periods = await readPeriods(context, options);
|
|
2492
|
+
const ranking = rankCampaigns(
|
|
2493
|
+
periods.campaigns.map((entry) => ({
|
|
2494
|
+
campaign: entry.campaign,
|
|
2495
|
+
counts: entry.current
|
|
2496
|
+
})),
|
|
2497
|
+
"reply_rate",
|
|
2498
|
+
options.min_sent
|
|
2499
|
+
);
|
|
2500
|
+
const sections = {
|
|
2501
|
+
anomalies: await readAnomalies(context, periods.current, options),
|
|
2502
|
+
bottom: ranking.ranked.slice(options.top).slice(-options.top).toReversed(),
|
|
2503
|
+
bounceProblems: bounceProblems(periods.campaigns, options),
|
|
2504
|
+
runningOutOfLeads: await readRunways(context, periods.campaigns, options),
|
|
2505
|
+
totals: noted(
|
|
2506
|
+
context,
|
|
2507
|
+
"Totals",
|
|
2508
|
+
totalOf(periods.campaigns, options.alpha)
|
|
2509
|
+
)
|
|
2510
|
+
};
|
|
2511
|
+
const leftOut = [
|
|
2512
|
+
...sections.anomalies === null ? ["Unusual days: the adapter has no workspace stats by day."] : [],
|
|
2513
|
+
...sections.runningOutOfLeads === null ? [
|
|
2514
|
+
"Campaigns running out of leads: the adapter cannot list a campaign's leads or has no stats by day."
|
|
2515
|
+
] : []
|
|
2516
|
+
];
|
|
2517
|
+
for (const section of leftOut) {
|
|
2518
|
+
context.note(`Left out. ${section}`);
|
|
2519
|
+
}
|
|
2520
|
+
const report = {
|
|
2521
|
+
...sections,
|
|
2522
|
+
actions: actionsOf(sections),
|
|
2523
|
+
campaigns: periods.campaigns.length,
|
|
2524
|
+
days: options.days,
|
|
2525
|
+
leftOut,
|
|
2526
|
+
period: periods.current,
|
|
2527
|
+
previousPeriod: periods.previous,
|
|
2528
|
+
top: ranking.ranked.slice(0, options.top)
|
|
2529
|
+
};
|
|
2530
|
+
return report;
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
|
|
2534
|
+
// src/insights/ops/tag-rollup.ts
|
|
2535
|
+
import { z as z15 } from "zod";
|
|
2536
|
+
var input13 = z15.object({
|
|
2537
|
+
...rangeFields,
|
|
2538
|
+
...listFields("one stats request"),
|
|
2539
|
+
min_sent: z15.number().int().min(0).default(50).describe("Tags with fewer sends than this are listed apart, unsorted")
|
|
2540
|
+
});
|
|
2541
|
+
var groupOf2 = (tag, entries) => {
|
|
2542
|
+
const counts = entries.map((entry) => entry.counts);
|
|
2543
|
+
const { partial, rates } = ratesAcross(counts);
|
|
2544
|
+
return {
|
|
2545
|
+
group: {
|
|
2546
|
+
...totalsOf(sumCounts(counts)),
|
|
2547
|
+
...rates,
|
|
2548
|
+
campaigns: entries.length,
|
|
2549
|
+
tag
|
|
2550
|
+
},
|
|
2551
|
+
partial
|
|
2552
|
+
};
|
|
2553
|
+
};
|
|
2554
|
+
var named = (group) => group.tag ?? "";
|
|
2555
|
+
var tagRollup = defineInsight({
|
|
2556
|
+
description: "Results by campaign tag (for example one tag per client, offer or audience): for each tag the campaigns, messages sent, leads contacted, replies, positive replies and bounces, with reply, positive reply and bounce rates and their 95% intervals, sorted by the low end of the reply rate interval. A campaign with two tags counts in both; campaigns with none are grouped under a null tag. Tags under min_sent sends are listed apart. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a tag whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
|
|
2557
|
+
inputSchema: input13,
|
|
2558
|
+
key: "tagRollup",
|
|
2559
|
+
name: "tag_rollup",
|
|
2560
|
+
needs: ["stats.campaign"],
|
|
2561
|
+
next: "Use campaign_ranking to see the campaigns inside the best and the worst tag.",
|
|
2562
|
+
run: async (context, options) => {
|
|
2563
|
+
const entries = await readCampaignTotals(context, options);
|
|
2564
|
+
const members = /* @__PURE__ */ new Map();
|
|
2565
|
+
for (const entry of entries) {
|
|
2566
|
+
const tags = entry.campaign.tags.length === 0 ? [null] : entry.campaign.tags;
|
|
2567
|
+
for (const tag of new Set(tags)) {
|
|
2568
|
+
members.set(tag, [...members.get(tag) ?? [], entry]);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
const grouped = [...members].map(([tag, group]) => groupOf2(tag, group));
|
|
2572
|
+
for (const { group, partial } of grouped) {
|
|
2573
|
+
if (partial.length > 0) {
|
|
2574
|
+
context.note(
|
|
2575
|
+
partialNote(
|
|
2576
|
+
group.tag === null ? "Untagged campaigns" : `Tag ${group.tag}`,
|
|
2577
|
+
partial
|
|
2578
|
+
)
|
|
2579
|
+
);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
const groups = grouped.map((each) => each.group).toSorted(
|
|
2583
|
+
(left, right) => descending(left.replyRate.low, right.replyRate.low) || named(left).localeCompare(named(right))
|
|
2584
|
+
);
|
|
2585
|
+
const enough2 = (group) => (volumeOf(group) ?? 0) >= options.min_sent;
|
|
2586
|
+
const rollup = {
|
|
2587
|
+
campaigns: entries.length,
|
|
2588
|
+
period: { from: options.from, to: options.to },
|
|
2589
|
+
tags: groups.filter(enough2),
|
|
2590
|
+
tooFewSends: groups.filter((group) => !enough2(group))
|
|
2591
|
+
};
|
|
2592
|
+
return rollup;
|
|
2593
|
+
}
|
|
2594
|
+
});
|
|
2595
|
+
|
|
2596
|
+
// src/insights/ops/index.ts
|
|
2597
|
+
var OPS_INSIGHTS = [
|
|
2598
|
+
campaignDiagnosis,
|
|
2599
|
+
pipelineForecast,
|
|
2600
|
+
anomalies,
|
|
2601
|
+
periodComparison,
|
|
2602
|
+
campaignRanking,
|
|
2603
|
+
channelMix,
|
|
2604
|
+
tagRollup,
|
|
2605
|
+
clientReport
|
|
2606
|
+
];
|
|
2607
|
+
|
|
2608
|
+
// src/insights/people/account-summary.ts
|
|
2609
|
+
import { z as z17 } from "zod";
|
|
2610
|
+
|
|
2611
|
+
// src/insights/people/read.ts
|
|
2612
|
+
import { z as z16 } from "zod";
|
|
2613
|
+
var readCapped2 = (context, open, max, what) => context.all(open(max), `${max} ${what}`);
|
|
2614
|
+
var statusesField = z16.array(campaignStatusSchema).min(1).default(["active"]).describe("Campaign statuses to consider, for example active or paused");
|
|
2615
|
+
var campaignsIn2 = async (context, statuses, max) => {
|
|
2616
|
+
const { outbound } = context;
|
|
2617
|
+
const wanted = [...new Set(statuses)];
|
|
2618
|
+
if (outbound.capabilities["campaigns.status"] === false) {
|
|
2619
|
+
const every = await readCapped2(
|
|
2620
|
+
context,
|
|
2621
|
+
(cap) => outbound.campaigns.listAll({ max: cap }),
|
|
2622
|
+
max,
|
|
2623
|
+
"campaigns"
|
|
2624
|
+
);
|
|
2625
|
+
return every.filter((campaign) => wanted.includes(campaign.status));
|
|
2626
|
+
}
|
|
2627
|
+
const campaigns = [];
|
|
2628
|
+
for (const status of wanted) {
|
|
2629
|
+
const room = max - campaigns.length;
|
|
2630
|
+
if (room <= 0) {
|
|
2631
|
+
context.partial(`Stopped at ${max} campaigns; more may exist.`);
|
|
2632
|
+
break;
|
|
2633
|
+
}
|
|
2634
|
+
const found = await readCapped2(
|
|
2635
|
+
context,
|
|
2636
|
+
(cap) => outbound.campaigns.listAll({ max: cap, status }),
|
|
2637
|
+
room,
|
|
2638
|
+
"campaigns"
|
|
2639
|
+
);
|
|
2640
|
+
campaigns.push(...found);
|
|
2641
|
+
}
|
|
2642
|
+
return campaigns;
|
|
2643
|
+
};
|
|
2644
|
+
var leadsOf = (context, campaign, max) => readCapped2(
|
|
2645
|
+
context,
|
|
2646
|
+
(cap) => context.outbound.campaign(campaign).leads.listAll({ max: cap }),
|
|
2647
|
+
max,
|
|
2648
|
+
"leads of a campaign"
|
|
2649
|
+
);
|
|
2650
|
+
var nameOf = (lead) => {
|
|
2651
|
+
const name = [lead.firstName, lead.lastName].flatMap((part) => part === null || part.trim() === "" ? [] : [part]).join(" ");
|
|
2652
|
+
return name === "" ? null : name;
|
|
2653
|
+
};
|
|
2654
|
+
var domainOf = (email) => {
|
|
2655
|
+
const domain = email?.split("@").at(-1) ?? "";
|
|
2656
|
+
return email === null || !email.includes("@") || domain === "" ? null : domain;
|
|
2657
|
+
};
|
|
2658
|
+
var DEFAULT_POSITIVE_LABELS = [
|
|
2659
|
+
"Interested",
|
|
2660
|
+
"Meeting Booked",
|
|
2661
|
+
"Meeting Completed"
|
|
2662
|
+
];
|
|
2663
|
+
var positiveLabelsField = z16.array(z16.string().min(1)).default(DEFAULT_POSITIVE_LABELS).describe(
|
|
2664
|
+
"Vendor interest labels that count as interested, matched without regard to case"
|
|
2665
|
+
);
|
|
2666
|
+
var isPositive = (label, labels) => label === null ? null : labels.some(
|
|
2667
|
+
(each) => each.trim().toLowerCase() === label.trim().toLowerCase()
|
|
2668
|
+
);
|
|
2669
|
+
var hasReplied = (lead) => lead.replied === true || (lead.engagement?.replies ?? 0) > 0 || (lead.engagement?.lastRepliedAt ?? null) !== null;
|
|
2670
|
+
var COUNTS = "no per-lead open, click or reply counts";
|
|
2671
|
+
var noteEngagement = (context, leads, effect) => {
|
|
2672
|
+
const { outbound } = context;
|
|
2673
|
+
if (outbound.capabilities["leads.engagement"]) {
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
if (leads.every((lead) => lead.provider === outbound.provider)) {
|
|
2677
|
+
context.note(`This tool reports ${COUNTS}, so ${effect}.`);
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
const reporting = new Set(
|
|
2681
|
+
leads.flatMap((lead) => lead.engagement === null ? [] : [lead.provider])
|
|
2682
|
+
);
|
|
2683
|
+
const lacking = [...new Set(leads.map((lead) => lead.provider))].filter((provider) => !reporting.has(provider)).toSorted();
|
|
2684
|
+
if (lacking.length > 0) {
|
|
2685
|
+
context.note(
|
|
2686
|
+
`${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.`
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
|
|
2691
|
+
// src/insights/people/account-summary.ts
|
|
2692
|
+
var input14 = z17.object({
|
|
2693
|
+
allow_free_domains: z17.boolean().default(false).describe(
|
|
2694
|
+
"Set to true to accept an email provider domain such as gmail.com, which is not one company"
|
|
2695
|
+
),
|
|
2696
|
+
domain: z17.string().min(3).describe(
|
|
2697
|
+
"The company's domain, for example acme.com, or an email address whose domain is used"
|
|
2698
|
+
),
|
|
2699
|
+
max_campaigns: z17.number().int().min(1).max(200).default(20).describe(
|
|
2700
|
+
"The most campaigns to read leads from when the tool cannot list every lead at once"
|
|
2701
|
+
),
|
|
2702
|
+
max_leads: z17.number().int().min(1).max(2e4).default(1e3).describe(
|
|
2703
|
+
"The most leads to read in all. A vendor request returns about 50 to 100 leads."
|
|
2704
|
+
),
|
|
2705
|
+
positive_labels: positiveLabelsField
|
|
2706
|
+
});
|
|
2707
|
+
var FREE_DOMAINS = /* @__PURE__ */ new Set([
|
|
2708
|
+
"aol.com",
|
|
2709
|
+
"gmail.com",
|
|
2710
|
+
"gmx.com",
|
|
2711
|
+
"googlemail.com",
|
|
2712
|
+
"hotmail.com",
|
|
2713
|
+
"icloud.com",
|
|
2714
|
+
"live.com",
|
|
2715
|
+
"mail.com",
|
|
2716
|
+
"me.com",
|
|
2717
|
+
"msn.com",
|
|
2718
|
+
"outlook.com",
|
|
2719
|
+
"proton.me",
|
|
2720
|
+
"protonmail.com",
|
|
2721
|
+
"yahoo.com",
|
|
2722
|
+
"yandex.com",
|
|
2723
|
+
"zoho.com"
|
|
2724
|
+
]);
|
|
2725
|
+
var DOMAIN = /^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/u;
|
|
2726
|
+
var parseDomain = (text, provider) => {
|
|
2727
|
+
const value = text.trim().toLowerCase();
|
|
2728
|
+
const host = value.includes("@") ? value.split("@").at(-1) ?? "" : value.replace(/^[a-z]+:\/\//u, "").replace(/^www\./u, "").split(/[/?#]/u)[0] ?? "";
|
|
2729
|
+
if (!DOMAIN.test(host)) {
|
|
2730
|
+
throw new OutboundError(
|
|
2731
|
+
"Invalid",
|
|
2732
|
+
`"${text}" is not a domain or an email address`,
|
|
2733
|
+
{ provider }
|
|
2734
|
+
);
|
|
2735
|
+
}
|
|
2736
|
+
return host;
|
|
2737
|
+
};
|
|
2738
|
+
var readLeads = async (context, { max_campaigns: maxCampaigns, max_leads: maxLeads }) => {
|
|
2739
|
+
const { outbound } = context;
|
|
2740
|
+
if (outbound.capabilities["leads.list"]) {
|
|
2741
|
+
return await readCapped2(
|
|
2742
|
+
context,
|
|
2743
|
+
(cap) => outbound.leads.listAll({ max: cap }),
|
|
2744
|
+
maxLeads,
|
|
2745
|
+
"leads"
|
|
2746
|
+
);
|
|
2747
|
+
}
|
|
2748
|
+
if (!outbound.capabilities["leads.byCampaign"]) {
|
|
2749
|
+
throw new OutboundError(
|
|
2750
|
+
"Unsupported",
|
|
2751
|
+
`account_summary is not available: the ${outbound.provider} adapter supports neither leads.list nor leads.byCampaign`,
|
|
2752
|
+
{ provider: outbound.provider }
|
|
2753
|
+
);
|
|
2754
|
+
}
|
|
2755
|
+
const campaigns = await readCapped2(
|
|
2756
|
+
context,
|
|
2757
|
+
(cap) => outbound.campaigns.listAll({ max: cap }),
|
|
2758
|
+
maxCampaigns,
|
|
2759
|
+
"campaigns"
|
|
2760
|
+
);
|
|
2761
|
+
const leads = [];
|
|
2762
|
+
for (const campaign of campaigns) {
|
|
2763
|
+
if (leads.length >= maxLeads) {
|
|
2764
|
+
context.partial(`Stopped at ${maxLeads} leads; more campaigns remain.`);
|
|
2765
|
+
break;
|
|
2766
|
+
}
|
|
2767
|
+
const found = await leadsOf(context, campaign.ref, maxLeads - leads.length);
|
|
2768
|
+
leads.push(...found);
|
|
2769
|
+
}
|
|
2770
|
+
return leads;
|
|
2771
|
+
};
|
|
2772
|
+
var toRecord = (lead) => ({
|
|
2773
|
+
campaign: lead.campaignRef,
|
|
2774
|
+
clicks: lead.engagement?.clicks ?? null,
|
|
2775
|
+
interest: lead.interest,
|
|
2776
|
+
lastContactedAt: lead.engagement?.lastContactedAt ?? null,
|
|
2777
|
+
lastRepliedAt: lead.engagement?.lastRepliedAt ?? null,
|
|
2778
|
+
lead: lead.ref,
|
|
2779
|
+
opens: lead.engagement?.opens ?? null,
|
|
2780
|
+
provider: lead.provider,
|
|
2781
|
+
replies: lead.engagement?.replies ?? null,
|
|
2782
|
+
status: lead.status
|
|
2783
|
+
});
|
|
2784
|
+
var latest = (times3) => times3.flatMap((time) => time === null ? [] : [time]).toSorted().at(-1) ?? null;
|
|
2785
|
+
var toPerson = (email, leads, labels) => {
|
|
2786
|
+
const records = leads.map(toRecord);
|
|
2787
|
+
const verdicts = leads.map((lead) => isPositive(lead.interest, labels));
|
|
2788
|
+
const pick = (read) => leads.map(read).find((value) => value !== null) ?? null;
|
|
2789
|
+
return {
|
|
2790
|
+
campaigns: [
|
|
2791
|
+
...new Set(
|
|
2792
|
+
records.flatMap(
|
|
2793
|
+
(record) => record.campaign === null ? [] : [record.campaign]
|
|
2794
|
+
)
|
|
2795
|
+
)
|
|
2796
|
+
],
|
|
2797
|
+
clicks: total(records.map((record) => record.clicks)),
|
|
2798
|
+
company: pick((lead) => lead.company),
|
|
2799
|
+
email,
|
|
2800
|
+
interested: verdicts.includes(true) ? true : verdicts.find((verdict) => verdict !== null) ?? null,
|
|
2801
|
+
lastRepliedAt: latest(records.map((record) => record.lastRepliedAt)),
|
|
2802
|
+
name: pick(nameOf),
|
|
2803
|
+
opens: total(records.map((record) => record.opens)),
|
|
2804
|
+
records,
|
|
2805
|
+
replied: leads.some(hasReplied),
|
|
2806
|
+
replies: total(records.map((record) => record.replies)),
|
|
2807
|
+
title: pick((lead) => lead.title)
|
|
2808
|
+
};
|
|
2809
|
+
};
|
|
2810
|
+
var byLastReply = (left, right) => (right.lastRepliedAt ?? "").localeCompare(left.lastRepliedAt ?? "") || Number(right.replied) - Number(left.replied) || left.email.localeCompare(right.email);
|
|
2811
|
+
var lastReplyOf = (people) => {
|
|
2812
|
+
const [person] = people;
|
|
2813
|
+
const at = person?.lastRepliedAt ?? null;
|
|
2814
|
+
const record = person?.records.find((each) => each.lastRepliedAt === at);
|
|
2815
|
+
return person === void 0 || record === void 0 || at === null ? null : {
|
|
2816
|
+
at,
|
|
2817
|
+
campaign: record.campaign,
|
|
2818
|
+
email: person.email,
|
|
2819
|
+
lead: record.lead,
|
|
2820
|
+
name: person.name
|
|
2821
|
+
};
|
|
2822
|
+
};
|
|
2823
|
+
var accountSummary = defineInsight({
|
|
2824
|
+
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. Costs one request per page of leads read (max_leads sets the ceiling); a count the vendor does not report is null.",
|
|
2825
|
+
inputSchema: input14,
|
|
2826
|
+
key: "accountSummary",
|
|
2827
|
+
name: "account_summary",
|
|
2828
|
+
needs: [],
|
|
2829
|
+
next: "Use person_summary with one person's email address for their full history, message by message.",
|
|
2830
|
+
run: async (context, values) => {
|
|
2831
|
+
const domain = parseDomain(values.domain, context.outbound.provider);
|
|
2832
|
+
if (FREE_DOMAINS.has(domain) && !values.allow_free_domains) {
|
|
2833
|
+
throw new OutboundError(
|
|
2834
|
+
"Invalid",
|
|
2835
|
+
`${domain} is an email provider, not one company. Pass allow_free_domains: true to read it anyway.`,
|
|
2836
|
+
{ provider: context.outbound.provider }
|
|
2837
|
+
);
|
|
2838
|
+
}
|
|
2839
|
+
const leads = await readLeads(context, values);
|
|
2840
|
+
noteEngagement(context, leads, "those are null");
|
|
2841
|
+
const byEmail = /* @__PURE__ */ new Map();
|
|
2842
|
+
for (const lead of leads) {
|
|
2843
|
+
if (lead.email !== null && domainOf(lead.email) === domain) {
|
|
2844
|
+
byEmail.set(lead.email, [...byEmail.get(lead.email) ?? [], lead]);
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
const people = [...byEmail].map(
|
|
2848
|
+
([email, records]) => toPerson(email, records, values.positive_labels)
|
|
2849
|
+
).toSorted(byLastReply);
|
|
2850
|
+
const summary = {
|
|
2851
|
+
domain,
|
|
2852
|
+
lastReply: lastReplyOf(people),
|
|
2853
|
+
people,
|
|
2854
|
+
totals: {
|
|
2855
|
+
campaigns: new Set(people.flatMap((person) => person.campaigns)).size,
|
|
2856
|
+
interested: people.filter((person) => person.interested === true).length,
|
|
2857
|
+
leadsRead: leads.length,
|
|
2858
|
+
leadsWithoutEmail: leads.filter((lead) => lead.email === null).length,
|
|
2859
|
+
people: people.length,
|
|
2860
|
+
records: people.reduce((sum, each) => sum + each.records.length, 0),
|
|
2861
|
+
replied: people.filter((person) => person.replied).length
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
return summary;
|
|
2865
|
+
}
|
|
2866
|
+
});
|
|
2867
|
+
|
|
2868
|
+
// src/insights/people/dropped-replies.ts
|
|
2869
|
+
import { z as z18 } from "zod";
|
|
2870
|
+
var HOUR = 36e5;
|
|
2871
|
+
var DAY = 24 * HOUR;
|
|
2872
|
+
var DEFAULT_DAYS = 14;
|
|
2873
|
+
var input15 = z18.object({
|
|
2874
|
+
categories: z18.array(replyCategorySchema).min(1).default(["positive", "neutral", "unknown"]).describe(
|
|
2875
|
+
"Reply categories that need an answer. Out-of-office, bounce, unsubscribe and negative replies are left out by default."
|
|
2876
|
+
),
|
|
2877
|
+
include_auto: z18.boolean().default(false).describe(
|
|
2878
|
+
"Set to true to also check replies the vendor marks as automatic"
|
|
2879
|
+
),
|
|
2880
|
+
max_replies: z18.number().int().min(1).max(1e3).default(50).describe(
|
|
2881
|
+
"The most replies to read. Each conversation among them costs one more request to check."
|
|
2882
|
+
),
|
|
2883
|
+
older_than_hours: z18.number().min(0).default(24).describe(
|
|
2884
|
+
"A reply counts as dropped only after waiting this many hours without an answer"
|
|
2885
|
+
),
|
|
2886
|
+
since: z18.union([z18.iso.datetime({ offset: true }), z18.iso.date()]).nullable().default(null).describe(
|
|
2887
|
+
"Only replies received at or after this ISO 8601 time. Null means 14 days before now."
|
|
2888
|
+
)
|
|
2889
|
+
});
|
|
2890
|
+
var readersOf = (context) => {
|
|
2891
|
+
const { capabilities } = context.outbound;
|
|
2892
|
+
const messages = capabilities["messages.list"];
|
|
2893
|
+
return {
|
|
2894
|
+
thread: messages && capabilities["messages.byThread"],
|
|
2895
|
+
timeline: messages && capabilities["leads.timeline"]
|
|
2896
|
+
};
|
|
2897
|
+
};
|
|
2898
|
+
var conversationsOf = (replies2, readers) => {
|
|
2899
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2900
|
+
for (const reply of replies2) {
|
|
2901
|
+
const thread = readers.thread ? reply.threadId : null;
|
|
2902
|
+
const lead = readers.timeline ? reply.leadRef : null;
|
|
2903
|
+
const by = thread === null ? "timeline" : "thread";
|
|
2904
|
+
const id = thread ?? lead;
|
|
2905
|
+
const key = id === null ? `none:${reply.ref}` : `${by}:${id}`;
|
|
2906
|
+
const group = groups.get(key) ?? {
|
|
2907
|
+
by: id === null ? null : by,
|
|
2908
|
+
id: id ?? reply.ref,
|
|
2909
|
+
replies: []
|
|
2910
|
+
};
|
|
2911
|
+
group.replies.push(reply);
|
|
2912
|
+
groups.set(key, group);
|
|
2913
|
+
}
|
|
2914
|
+
return [...groups.values()];
|
|
2915
|
+
};
|
|
2916
|
+
var unanswered = (replies2, messages) => {
|
|
2917
|
+
const lastSent = Math.max(
|
|
2918
|
+
Number.NEGATIVE_INFINITY,
|
|
2919
|
+
...messages.flatMap(
|
|
2920
|
+
(message) => message.direction === "out" && message.sentAt !== null ? [Date.parse(message.sentAt)] : []
|
|
2921
|
+
)
|
|
2922
|
+
);
|
|
2923
|
+
return replies2.filter(
|
|
2924
|
+
(reply) => reply.sentAt !== null && Date.parse(reply.sentAt) > lastSent
|
|
2925
|
+
).toSorted(
|
|
2926
|
+
(left, right) => (left.sentAt ?? "").localeCompare(right.sentAt ?? "")
|
|
2927
|
+
);
|
|
2928
|
+
};
|
|
2929
|
+
var toDropped = (open, by, now) => {
|
|
2930
|
+
const [first] = open;
|
|
2931
|
+
if (first === void 0 || first.sentAt === null) {
|
|
2932
|
+
return [];
|
|
2933
|
+
}
|
|
2934
|
+
const hoursWaiting = round((now - Date.parse(first.sentAt)) / HOUR) ?? 0;
|
|
2935
|
+
return [
|
|
2936
|
+
{
|
|
2937
|
+
campaign: first.campaignRef,
|
|
2938
|
+
category: first.category,
|
|
2939
|
+
channel: first.channel,
|
|
2940
|
+
checkedBy: by,
|
|
2941
|
+
finding: `${/^[aeiou]/u.test(first.category) ? "An" : "A"} ${first.category} reply has waited ${Math.floor(hoursWaiting)} hours with nothing sent after it.`,
|
|
2942
|
+
hoursWaiting,
|
|
2943
|
+
lead: first.leadRef,
|
|
2944
|
+
provider: first.provider,
|
|
2945
|
+
receivedAt: first.sentAt,
|
|
2946
|
+
reply: first.ref,
|
|
2947
|
+
subject: first.subject,
|
|
2948
|
+
unansweredReplies: open.length
|
|
2949
|
+
}
|
|
2950
|
+
];
|
|
2951
|
+
};
|
|
2952
|
+
var readReplies = (context, since, max) => {
|
|
2953
|
+
const { outbound } = context;
|
|
2954
|
+
const filtered = outbound.capabilities["replies.since"] !== false;
|
|
2955
|
+
if (!filtered) {
|
|
2956
|
+
context.note(
|
|
2957
|
+
"This tool cannot filter replies by date, so the newest replies were read and filtered here."
|
|
2958
|
+
);
|
|
2959
|
+
}
|
|
2960
|
+
return readCapped2(
|
|
2961
|
+
context,
|
|
2962
|
+
(cap) => outbound.replies.listAll(filtered ? { max: cap, since } : { max: cap }),
|
|
2963
|
+
max,
|
|
2964
|
+
"replies"
|
|
2965
|
+
);
|
|
2966
|
+
};
|
|
2967
|
+
var droppedReplies = defineInsight({
|
|
2968
|
+
description: "Replies from prospects that nobody answered. Reads the replies since a date (14 days before now by default), keeps the categories that need an answer, and for each conversation reads its thread, or the lead's timeline when there is no thread, and reports it as dropped when nothing was sent after the reply and it has waited longer than older_than_hours. Returns the dropped replies longest waiting first with hours waiting, category, campaign and lead. A reply that could not be checked is counted in totals.unchecked, never reported as dropped. Costs one request per page of replies plus one per conversation checked, so at most about max_replies requests.",
|
|
2969
|
+
inputSchema: input15,
|
|
2970
|
+
key: "droppedReplies",
|
|
2971
|
+
name: "dropped_replies",
|
|
2972
|
+
needs: ["replies.list"],
|
|
2973
|
+
next: "Use person_summary with the lead's email address to read what was sent before answering, or hot_leads to see who else to contact first.",
|
|
2974
|
+
run: async (context, values) => {
|
|
2975
|
+
const since = new Date(
|
|
2976
|
+
values.since === null ? context.now - DEFAULT_DAYS * DAY : Date.parse(values.since)
|
|
2977
|
+
).toISOString();
|
|
2978
|
+
const readers = readersOf(context);
|
|
2979
|
+
if (!(readers.thread || readers.timeline)) {
|
|
2980
|
+
context.note(
|
|
2981
|
+
"This tool can read neither a conversation nor a lead's timeline, so no reply could be checked."
|
|
2982
|
+
);
|
|
2983
|
+
}
|
|
2984
|
+
const read = await readReplies(context, since, values.max_replies);
|
|
2985
|
+
const replies2 = read.filter(
|
|
2986
|
+
(reply) => reply.sentAt === null || Date.parse(reply.sentAt) >= Date.parse(since)
|
|
2987
|
+
);
|
|
2988
|
+
const wanted = replies2.filter(
|
|
2989
|
+
(reply) => values.categories.includes(reply.category)
|
|
2990
|
+
);
|
|
2991
|
+
const kept = wanted.filter(
|
|
2992
|
+
(reply) => values.include_auto || reply.isAuto !== true
|
|
2993
|
+
);
|
|
2994
|
+
const conversations = conversationsOf(kept, readers);
|
|
2995
|
+
const dropped = [];
|
|
2996
|
+
let answered = 0;
|
|
2997
|
+
let tooRecent = 0;
|
|
2998
|
+
const checkable = conversations.flatMap(
|
|
2999
|
+
(conversation) => conversation.by !== null && conversation.replies.some((each) => each.sentAt !== null) ? [{ ...conversation, by: conversation.by }] : []
|
|
3000
|
+
);
|
|
3001
|
+
const unchecked = conversations.length - checkable.length;
|
|
3002
|
+
const threads = await mapConcurrent(checkable, async (conversation) => ({
|
|
3003
|
+
conversation,
|
|
3004
|
+
messages: context.page(
|
|
3005
|
+
await (conversation.by === "thread" ? context.outbound.thread(conversation.id).messages() : context.outbound.lead(conversation.id).timeline())
|
|
3006
|
+
)
|
|
3007
|
+
}));
|
|
3008
|
+
for (const { conversation, messages } of threads) {
|
|
3009
|
+
const found = toDropped(
|
|
3010
|
+
unanswered(conversation.replies, messages),
|
|
3011
|
+
conversation.by,
|
|
3012
|
+
context.now
|
|
3013
|
+
);
|
|
3014
|
+
const old = found.filter(
|
|
3015
|
+
(each) => each.hoursWaiting >= values.older_than_hours
|
|
3016
|
+
);
|
|
3017
|
+
dropped.push(...old);
|
|
3018
|
+
answered += found.length === 0 ? 1 : 0;
|
|
3019
|
+
tooRecent += found.length - old.length;
|
|
3020
|
+
}
|
|
3021
|
+
const answer = {
|
|
3022
|
+
dropped: dropped.toSorted(
|
|
3023
|
+
(left, right) => right.hoursWaiting - left.hoursWaiting || left.reply.localeCompare(right.reply)
|
|
3024
|
+
),
|
|
3025
|
+
olderThanHours: values.older_than_hours,
|
|
3026
|
+
since,
|
|
3027
|
+
totals: {
|
|
3028
|
+
answered,
|
|
3029
|
+
conversations: conversations.length,
|
|
3030
|
+
dropped: dropped.length,
|
|
3031
|
+
repliesRead: read.length,
|
|
3032
|
+
skippedAuto: wanted.length - kept.length,
|
|
3033
|
+
skippedByCategory: replies2.length - wanted.length,
|
|
3034
|
+
tooRecent,
|
|
3035
|
+
unchecked
|
|
3036
|
+
}
|
|
3037
|
+
};
|
|
3038
|
+
return answer;
|
|
3039
|
+
}
|
|
3040
|
+
});
|
|
3041
|
+
|
|
3042
|
+
// src/insights/people/hot-leads.ts
|
|
3043
|
+
import { z as z19 } from "zod";
|
|
3044
|
+
var DAY2 = 864e5;
|
|
3045
|
+
var weight = (value, what) => z19.number().min(0).default(value).describe(what);
|
|
3046
|
+
var input16 = z19.object({
|
|
3047
|
+
campaign: z19.string().min(1).nullable().default(null).describe(
|
|
3048
|
+
"A campaign ref (provider:workspace:id) to rank the leads of. Null ranks every lead the tool lists."
|
|
3049
|
+
),
|
|
3050
|
+
count_cap: z19.number().int().min(1).default(5).describe(
|
|
3051
|
+
"The most replies, clicks or opens that earn points, so 40 opens do not outrank a reply"
|
|
3052
|
+
),
|
|
3053
|
+
limit: z19.number().int().min(1).max(500).default(20).describe("How many leads to return"),
|
|
3054
|
+
max_leads: z19.number().int().min(1).max(2e4).default(500).describe(
|
|
3055
|
+
"The most leads to read and score. A vendor request returns about 50 to 100 leads."
|
|
3056
|
+
),
|
|
3057
|
+
positive_labels: positiveLabelsField,
|
|
3058
|
+
recency_days: z19.number().min(1).default(14).describe(
|
|
3059
|
+
"A reply today earns the full recency points, fading evenly to none after this many days"
|
|
3060
|
+
),
|
|
3061
|
+
weight_click: weight(5, "Points for each click, up to count_cap"),
|
|
3062
|
+
weight_interest: weight(50, "Points for carrying a positive interest label"),
|
|
3063
|
+
weight_open: weight(1, "Points for each open, up to count_cap"),
|
|
3064
|
+
weight_recency: weight(20, "Points for a reply received right now"),
|
|
3065
|
+
weight_reply: weight(10, "Points for each reply, up to count_cap")
|
|
3066
|
+
});
|
|
3067
|
+
var capped = (count, points, cap) => count === null ? null : Math.min(count, cap) * points;
|
|
3068
|
+
var partsOf = (lead, values, now) => {
|
|
3069
|
+
const engagement = lead.engagement ?? null;
|
|
3070
|
+
const positive = isPositive(lead.interest, values.positive_labels);
|
|
3071
|
+
const replies2 = engagement?.replies ?? (lead.replied === true ? 1 : null);
|
|
3072
|
+
const repliedAt = engagement?.lastRepliedAt ?? null;
|
|
3073
|
+
const age = repliedAt === null ? null : Math.max(0, now - Date.parse(repliedAt)) / DAY2 / values.recency_days;
|
|
3074
|
+
return {
|
|
3075
|
+
clicks: capped(
|
|
3076
|
+
engagement?.clicks ?? null,
|
|
3077
|
+
values.weight_click,
|
|
3078
|
+
values.count_cap
|
|
3079
|
+
),
|
|
3080
|
+
interest: positive === null ? null : Number(positive) * values.weight_interest,
|
|
3081
|
+
opens: capped(
|
|
3082
|
+
engagement?.opens ?? null,
|
|
3083
|
+
values.weight_open,
|
|
3084
|
+
values.count_cap
|
|
3085
|
+
),
|
|
3086
|
+
recency: age === null ? null : round(Math.max(0, 1 - age) * values.weight_recency),
|
|
3087
|
+
replies: capped(replies2, values.weight_reply, values.count_cap)
|
|
3088
|
+
};
|
|
3089
|
+
};
|
|
3090
|
+
var reasonOf = (lead, parts, now) => {
|
|
3091
|
+
const engagement = lead.engagement ?? null;
|
|
3092
|
+
const repliedAt = engagement?.lastRepliedAt ?? null;
|
|
3093
|
+
const facts = [
|
|
3094
|
+
(parts.interest ?? 0) > 0 ? `marked ${lead.interest}` : null,
|
|
3095
|
+
(parts.replies ?? 0) > 0 ? `replied ${engagement?.replies ?? 1} time(s)` : null,
|
|
3096
|
+
repliedAt === null ? null : `last reply ${Math.floor(Math.max(0, now - Date.parse(repliedAt)) / DAY2)} day(s) ago`,
|
|
3097
|
+
(parts.clicks ?? 0) > 0 ? `${engagement?.clicks} click(s)` : null,
|
|
3098
|
+
(parts.opens ?? 0) > 0 ? `${engagement?.opens} open(s)` : null
|
|
3099
|
+
].flatMap((fact) => fact === null ? [] : [fact]);
|
|
3100
|
+
return `${facts.join(", ")}.`;
|
|
3101
|
+
};
|
|
3102
|
+
var toHotLead = (lead, values, now) => {
|
|
3103
|
+
const parts = partsOf(lead, values, now);
|
|
3104
|
+
const score = total(Object.values(parts));
|
|
3105
|
+
return score === null ? [] : [
|
|
3106
|
+
{
|
|
3107
|
+
campaign: lead.campaignRef,
|
|
3108
|
+
clicks: lead.engagement?.clicks ?? null,
|
|
3109
|
+
company: lead.company,
|
|
3110
|
+
email: lead.email,
|
|
3111
|
+
interest: lead.interest,
|
|
3112
|
+
lastRepliedAt: lead.engagement?.lastRepliedAt ?? null,
|
|
3113
|
+
lead: lead.ref,
|
|
3114
|
+
linkedinUrl: lead.linkedinUrl,
|
|
3115
|
+
name: nameOf(lead),
|
|
3116
|
+
opens: lead.engagement?.opens ?? null,
|
|
3117
|
+
parts,
|
|
3118
|
+
reason: reasonOf(lead, parts, now),
|
|
3119
|
+
replies: lead.engagement?.replies ?? null,
|
|
3120
|
+
score: round(score) ?? 0,
|
|
3121
|
+
status: lead.status,
|
|
3122
|
+
title: lead.title
|
|
3123
|
+
}
|
|
3124
|
+
];
|
|
3125
|
+
};
|
|
3126
|
+
var readLeads2 = (context, { campaign, max_leads: maxLeads }) => {
|
|
3127
|
+
const { outbound } = context;
|
|
3128
|
+
if (campaign !== null) {
|
|
3129
|
+
return leadsOf(context, campaign, maxLeads);
|
|
3130
|
+
}
|
|
3131
|
+
if (!outbound.capabilities["leads.list"]) {
|
|
3132
|
+
throw new OutboundError(
|
|
3133
|
+
"Unsupported",
|
|
3134
|
+
`hot_leads needs a campaign here: the ${outbound.provider} adapter cannot list every lead (leads.list)`,
|
|
3135
|
+
{ provider: outbound.provider }
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
return readCapped2(
|
|
3139
|
+
context,
|
|
3140
|
+
(cap) => outbound.leads.listAll({ max: cap }),
|
|
3141
|
+
maxLeads,
|
|
3142
|
+
"leads"
|
|
3143
|
+
);
|
|
3144
|
+
};
|
|
3145
|
+
var hottestFirst = (left, right) => right.score - left.score || (right.lastRepliedAt ?? "").localeCompare(left.lastRepliedAt ?? "") || left.lead.localeCompare(right.lead);
|
|
3146
|
+
var hotLeads = defineInsight({
|
|
3147
|
+
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, or none to rank every lead the tool lists. Costs one request per page of leads read (max_leads sets the ceiling). A part that is null means the vendor does not report that signal.",
|
|
3148
|
+
inputSchema: input16,
|
|
3149
|
+
key: "hotLeads",
|
|
3150
|
+
name: "hot_leads",
|
|
3151
|
+
needs: [],
|
|
3152
|
+
next: "Use person_summary with a lead's email address or LinkedIn profile to read the conversation before calling.",
|
|
3153
|
+
run: async (context, values) => {
|
|
3154
|
+
const leads = await readLeads2(context, values);
|
|
3155
|
+
noteEngagement(
|
|
3156
|
+
context,
|
|
3157
|
+
leads,
|
|
3158
|
+
"scores rest on the interest label and the lead's status"
|
|
3159
|
+
);
|
|
3160
|
+
const open = leads.filter(
|
|
3161
|
+
(lead) => lead.unsubscribed !== true && lead.bounced !== true
|
|
3162
|
+
);
|
|
3163
|
+
const scored = open.flatMap((lead) => toHotLead(lead, values, context.now));
|
|
3164
|
+
const hot = scored.filter((lead) => lead.score > 0).toSorted(hottestFirst);
|
|
3165
|
+
const answer = {
|
|
3166
|
+
leads: hot.slice(0, values.limit),
|
|
3167
|
+
totals: {
|
|
3168
|
+
excluded: leads.length - open.length,
|
|
3169
|
+
hot: hot.length,
|
|
3170
|
+
leadsRead: leads.length,
|
|
3171
|
+
scored: scored.length,
|
|
3172
|
+
withoutData: open.length - scored.length
|
|
3173
|
+
}
|
|
3174
|
+
};
|
|
3175
|
+
return answer;
|
|
3176
|
+
}
|
|
3177
|
+
});
|
|
3178
|
+
|
|
3179
|
+
// src/insights/people/lead-collisions.ts
|
|
3180
|
+
import { z as z20 } from "zod";
|
|
3181
|
+
|
|
3182
|
+
// src/insights/people/find.ts
|
|
3183
|
+
var personKey = (identifier) => {
|
|
3184
|
+
const value = identifier.trim();
|
|
3185
|
+
const slug = profileSlug(value);
|
|
3186
|
+
if (slug !== null) {
|
|
3187
|
+
return `linkedin:${slug}`;
|
|
3188
|
+
}
|
|
3189
|
+
return value.includes("@") && !value.includes(" ") ? `email:${value.toLowerCase()}` : null;
|
|
3190
|
+
};
|
|
3191
|
+
var keysOfLead = (lead) => {
|
|
3192
|
+
const slug = profileSlug(lead.linkedinUrl);
|
|
3193
|
+
return [
|
|
3194
|
+
...lead.email === null ? [] : [`email:${lead.email}`],
|
|
3195
|
+
...slug === null ? [] : [`linkedin:${slug}`]
|
|
3196
|
+
];
|
|
3197
|
+
};
|
|
3198
|
+
var filterFor = (key) => key.startsWith("email:") ? { email: key.slice("email:".length) } : {
|
|
3199
|
+
linkedinUrl: `https://www.linkedin.com/in/${key.slice("linkedin:".length)}`
|
|
3200
|
+
};
|
|
3201
|
+
var isRedacted = (outbound) => "redacted" in outbound;
|
|
3202
|
+
var maskedIdentifiers = (outbound) => isRedacted(outbound) ? outbound.redacted.fields.filter(
|
|
3203
|
+
(field) => field === "email" || field === "linkedin"
|
|
3204
|
+
) : [];
|
|
3205
|
+
var findPerson = async (context, identifier, maxRecords) => {
|
|
3206
|
+
const first = personKey(identifier);
|
|
3207
|
+
if (first === null) {
|
|
3208
|
+
throw new OutboundError(
|
|
3209
|
+
"Invalid",
|
|
3210
|
+
"Give an email address or a LinkedIn profile URL",
|
|
3211
|
+
{ provider: context.outbound.provider }
|
|
3212
|
+
);
|
|
3213
|
+
}
|
|
3214
|
+
const masked = maskedIdentifiers(context.outbound);
|
|
3215
|
+
if (masked.length > 0) {
|
|
3216
|
+
throw new OutboundError(
|
|
3217
|
+
"Unsupported",
|
|
3218
|
+
`A person cannot be looked up while the redact plugin masks ${masked.join(" and ")}: the records could not be matched to the identifier`,
|
|
3219
|
+
{ provider: context.outbound.provider }
|
|
3220
|
+
);
|
|
3221
|
+
}
|
|
3222
|
+
const keys = /* @__PURE__ */ new Set([first]);
|
|
3223
|
+
const asked = /* @__PURE__ */ new Set();
|
|
3224
|
+
const records = /* @__PURE__ */ new Map();
|
|
3225
|
+
for (let round2 = [...keys].filter((key) => !asked.has(key)); round2.length > 0; round2 = [...keys].filter((key) => !asked.has(key))) {
|
|
3226
|
+
for (const key of round2) {
|
|
3227
|
+
asked.add(key);
|
|
3228
|
+
}
|
|
3229
|
+
const answers = await mapConcurrent(
|
|
3230
|
+
round2,
|
|
3231
|
+
(key) => context.all(
|
|
3232
|
+
context.outbound.leads.listAll({ ...filterFor(key), max: maxRecords }),
|
|
3233
|
+
`${maxRecords} records of the person`
|
|
3234
|
+
)
|
|
3235
|
+
);
|
|
3236
|
+
for (const [index, leads] of answers.entries()) {
|
|
3237
|
+
const asking = round2[index];
|
|
3238
|
+
for (const lead of leads) {
|
|
3239
|
+
const leadKeys = keysOfLead(lead);
|
|
3240
|
+
if (asking !== void 0 && leadKeys.includes(asking)) {
|
|
3241
|
+
records.set(`${lead.ref} ${lead.campaignRef ?? ""}`, lead);
|
|
3242
|
+
for (const key of leadKeys) {
|
|
3243
|
+
keys.add(key);
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
return {
|
|
3250
|
+
keys: [...keys].toSorted(),
|
|
3251
|
+
records: [...records.values()].slice(0, maxRecords)
|
|
3252
|
+
};
|
|
3253
|
+
};
|
|
3254
|
+
|
|
3255
|
+
// src/insights/people/lead-collisions.ts
|
|
3256
|
+
var input17 = z20.object({
|
|
3257
|
+
max_campaigns: z20.number().int().min(1).max(200).default(20).describe(
|
|
3258
|
+
"The most campaigns to read. Each costs one request per page of its leads."
|
|
3259
|
+
),
|
|
3260
|
+
max_leads_per_campaign: z20.number().int().min(1).max(2e4).default(500).describe("The most leads to read from each campaign"),
|
|
3261
|
+
statuses: statusesField
|
|
3262
|
+
});
|
|
3263
|
+
var groupPeople = (entries) => {
|
|
3264
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
3265
|
+
for (const entry of entries) {
|
|
3266
|
+
const keys = keysOfLead(entry.lead);
|
|
3267
|
+
const found = new Set(keys.flatMap((key) => byKey.get(key) ?? []));
|
|
3268
|
+
const group = { entries: [entry], keys: new Set(keys) };
|
|
3269
|
+
for (const other of found) {
|
|
3270
|
+
group.entries.unshift(...other.entries);
|
|
3271
|
+
for (const key of other.keys) {
|
|
3272
|
+
group.keys.add(key);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
for (const key of group.keys) {
|
|
3276
|
+
byKey.set(key, group);
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
return [...new Set(byKey.values())];
|
|
3280
|
+
};
|
|
3281
|
+
var toCollision = (group) => {
|
|
3282
|
+
const perCampaign = new Map(
|
|
3283
|
+
group.entries.map((entry) => [entry.campaign.ref, entry])
|
|
3284
|
+
);
|
|
3285
|
+
if (perCampaign.size < 2) {
|
|
3286
|
+
return [];
|
|
3287
|
+
}
|
|
3288
|
+
const campaigns = [...perCampaign.values()].map(({ campaign, lead }) => ({
|
|
3289
|
+
campaign: campaign.ref,
|
|
3290
|
+
campaignName: campaign.name,
|
|
3291
|
+
channel: campaign.channel,
|
|
3292
|
+
lead: lead.ref,
|
|
3293
|
+
leadStatus: lead.status,
|
|
3294
|
+
provider: campaign.provider
|
|
3295
|
+
}));
|
|
3296
|
+
const providers = [...new Set(campaigns.map((each) => each.provider))];
|
|
3297
|
+
const channels = [...new Set(campaigns.map((each) => each.channel))];
|
|
3298
|
+
const scope = providers.length > 1 ? "across_tools" : "within_tool";
|
|
3299
|
+
const identifiers = [...group.keys].toSorted();
|
|
3300
|
+
return [
|
|
3301
|
+
{
|
|
3302
|
+
campaignCount: campaigns.length,
|
|
3303
|
+
campaigns,
|
|
3304
|
+
channels,
|
|
3305
|
+
finding: scope === "across_tools" ? `${identifiers[0]} is in ${campaigns.length} campaigns across ${providers.join(" and ")} (${channels.join(" and ")}).` : `${identifiers[0]} is in ${campaigns.length} ${providers[0]} campaigns at once.`,
|
|
3306
|
+
identifiers,
|
|
3307
|
+
providers,
|
|
3308
|
+
scope,
|
|
3309
|
+
stillActive: campaigns.filter((each) => each.leadStatus === "active").length
|
|
3310
|
+
}
|
|
3311
|
+
];
|
|
3312
|
+
};
|
|
3313
|
+
var worstFirst = (left, right) => right.campaignCount - left.campaignCount || left.scope.localeCompare(right.scope) || (left.identifiers[0] ?? "").localeCompare(right.identifiers[0] ?? "");
|
|
3314
|
+
var leadCollisions = defineInsight({
|
|
3315
|
+
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.",
|
|
3316
|
+
inputSchema: input17,
|
|
3317
|
+
key: "leadCollisions",
|
|
3318
|
+
name: "lead_collisions",
|
|
3319
|
+
needs: ["leads.byCampaign"],
|
|
3320
|
+
next: "Use person_summary with one of the identifiers to see what that person was sent and whether they replied.",
|
|
3321
|
+
run: async (context, values) => {
|
|
3322
|
+
const campaigns = await campaignsIn2(
|
|
3323
|
+
context,
|
|
3324
|
+
values.statuses,
|
|
3325
|
+
values.max_campaigns
|
|
3326
|
+
);
|
|
3327
|
+
const perCampaign = await mapConcurrent(campaigns, async (campaign) => {
|
|
3328
|
+
const leads = await leadsOf(
|
|
3329
|
+
context,
|
|
3330
|
+
campaign.ref,
|
|
3331
|
+
values.max_leads_per_campaign
|
|
3332
|
+
);
|
|
3333
|
+
return leads.map((lead) => ({ campaign, lead }));
|
|
3334
|
+
});
|
|
3335
|
+
const entries = perCampaign.flat();
|
|
3336
|
+
const collisions = groupPeople(entries).flatMap(toCollision).toSorted(worstFirst);
|
|
3337
|
+
const acrossTools = collisions.filter(
|
|
3338
|
+
(each) => each.scope === "across_tools"
|
|
3339
|
+
).length;
|
|
3340
|
+
const answer = {
|
|
3341
|
+
collisions,
|
|
3342
|
+
totals: {
|
|
3343
|
+
acrossTools,
|
|
3344
|
+
campaignsRead: campaigns.length,
|
|
3345
|
+
collisions: collisions.length,
|
|
3346
|
+
leadsRead: entries.length,
|
|
3347
|
+
leadsWithoutIdentifier: entries.filter(
|
|
3348
|
+
(entry) => keysOfLead(entry.lead).length === 0
|
|
3349
|
+
).length,
|
|
3350
|
+
withinTool: collisions.length - acrossTools
|
|
3351
|
+
}
|
|
3352
|
+
};
|
|
3353
|
+
return answer;
|
|
3354
|
+
}
|
|
3355
|
+
});
|
|
3356
|
+
|
|
3357
|
+
// src/insights/people/person-summary.ts
|
|
3358
|
+
import { z as z21 } from "zod";
|
|
3359
|
+
var input18 = z21.object({
|
|
3360
|
+
max_campaigns: z21.number().int().min(1).max(50).default(20).describe("The most campaigns to report on. Each costs up to 2 requests."),
|
|
3361
|
+
person: z21.string().min(3).describe("The person's email address or LinkedIn profile URL")
|
|
3362
|
+
});
|
|
3363
|
+
var times2 = (messages, direction) => messages.flatMap(
|
|
3364
|
+
(message) => message.direction === direction && message.sentAt !== null ? [message.sentAt] : []
|
|
3365
|
+
);
|
|
3366
|
+
var repliedSteps = (lead, messages) => {
|
|
3367
|
+
const steps = /* @__PURE__ */ new Set();
|
|
3368
|
+
let lastSent = null;
|
|
3369
|
+
for (const message of messages) {
|
|
3370
|
+
if (message.direction === "out") {
|
|
3371
|
+
lastSent = message.stepIndex ?? lastSent;
|
|
3372
|
+
} else if ((message.stepIndex ?? lastSent) !== null) {
|
|
3373
|
+
steps.add(message.stepIndex ?? lastSent ?? 0);
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
const named2 = lead.engagement?.repliedStepIndex ?? null;
|
|
3377
|
+
if (named2 !== null) {
|
|
3378
|
+
steps.add(named2);
|
|
3379
|
+
}
|
|
3380
|
+
return [...steps].toSorted((left, right) => left - right);
|
|
3381
|
+
};
|
|
3382
|
+
var activityOf = (lead, messages) => {
|
|
3383
|
+
const sent = times2(messages, "out");
|
|
3384
|
+
const received = times2(messages, "in");
|
|
3385
|
+
const counted = lead.engagement;
|
|
3386
|
+
return {
|
|
3387
|
+
firstContactedAt: sent[0] ?? null,
|
|
3388
|
+
lastContactedAt: sent.at(-1) ?? counted?.lastContactedAt ?? null,
|
|
3389
|
+
lastRepliedAt: received.at(-1) ?? counted?.lastRepliedAt ?? null,
|
|
3390
|
+
lastStep: counted?.stepIndex ?? messages.findLast(
|
|
3391
|
+
(message) => message.direction === "out" && message.stepIndex !== null
|
|
3392
|
+
)?.stepIndex ?? null,
|
|
3393
|
+
// A vendor's thread can hold fewer messages than were sent; the last
|
|
3394
|
+
// step sent (counted from 0) is then the better count.
|
|
3395
|
+
messagesSent: Math.max(sent.length, (counted?.stepIndex ?? -1) + 1),
|
|
3396
|
+
// A vendor that keeps no thread still counts replies on the lead.
|
|
3397
|
+
replies: Math.max(received.length, counted?.replies ?? 0),
|
|
3398
|
+
threadIsShort: sent.length < (counted?.stepIndex ?? -1) + 1
|
|
3399
|
+
};
|
|
3400
|
+
};
|
|
3401
|
+
var timelineOf = async (context, timelines, lead) => {
|
|
3402
|
+
let all = timelines.get(lead.ref);
|
|
3403
|
+
if (all === void 0) {
|
|
3404
|
+
all = context.outbound.lead(lead.ref).timeline().then((page) => context.page(page));
|
|
3405
|
+
timelines.set(lead.ref, all);
|
|
3406
|
+
}
|
|
3407
|
+
const messages = await all;
|
|
3408
|
+
return messages.filter(
|
|
3409
|
+
(message) => message.campaignRef === null || lead.campaignRef === null || message.campaignRef === lead.campaignRef
|
|
3410
|
+
);
|
|
3411
|
+
};
|
|
3412
|
+
var summarize2 = async (context, timelines, lead) => {
|
|
3413
|
+
const { outbound } = context;
|
|
3414
|
+
const [messages, campaign] = await Promise.all([
|
|
3415
|
+
timelineOf(context, timelines, lead),
|
|
3416
|
+
lead.campaignRef === null ? null : outbound.campaigns.get(lead.campaignRef).then(context.one)
|
|
3417
|
+
]);
|
|
3418
|
+
const { threadIsShort, ...activity } = activityOf(lead, messages);
|
|
3419
|
+
if (threadIsShort) {
|
|
3420
|
+
context.note(
|
|
3421
|
+
"A thread held fewer sent messages than the lead's last step, so messages sent is counted from the last step."
|
|
3422
|
+
);
|
|
3423
|
+
}
|
|
3424
|
+
return {
|
|
3425
|
+
...activity,
|
|
3426
|
+
campaign: lead.campaignRef,
|
|
3427
|
+
campaignName: campaign?.name ?? null,
|
|
3428
|
+
campaignStatus: campaign?.status ?? null,
|
|
3429
|
+
channel: campaign?.channel ?? (lead.email === null ? "linkedin" : "email"),
|
|
3430
|
+
interest: lead.interest,
|
|
3431
|
+
lead: lead.ref,
|
|
3432
|
+
leadStatus: lead.status,
|
|
3433
|
+
provider: lead.provider,
|
|
3434
|
+
replied: activity.replies > 0 || lead.replied === true,
|
|
3435
|
+
repliedSteps: repliedSteps(lead, messages)
|
|
3436
|
+
};
|
|
3437
|
+
};
|
|
3438
|
+
var byChannel2 = (campaigns) => {
|
|
3439
|
+
const channels = {};
|
|
3440
|
+
for (const campaign of campaigns) {
|
|
3441
|
+
const before = channels[campaign.channel] ?? {
|
|
3442
|
+
messagesSent: 0,
|
|
3443
|
+
replies: 0
|
|
3444
|
+
};
|
|
3445
|
+
channels[campaign.channel] = {
|
|
3446
|
+
messagesSent: before.messagesSent + campaign.messagesSent,
|
|
3447
|
+
replies: before.replies + campaign.replies
|
|
3448
|
+
};
|
|
3449
|
+
}
|
|
3450
|
+
return channels;
|
|
3451
|
+
};
|
|
3452
|
+
var personSummary = defineInsight({
|
|
3453
|
+
description: "Everything about one person across campaigns and channels, from their email address or LinkedIn profile: 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. Costs one lookup per identifier, then up to 2 requests per campaign.",
|
|
3454
|
+
inputSchema: input18,
|
|
3455
|
+
key: "personSummary",
|
|
3456
|
+
name: "person_summary",
|
|
3457
|
+
needs: ["leads.lookup", "leads.timeline"],
|
|
3458
|
+
next: "Use account_summary with their email domain to see everyone at the same company.",
|
|
3459
|
+
run: async (context, { max_campaigns: maxCampaigns, person }) => {
|
|
3460
|
+
const found = await findPerson(context, person, maxCampaigns);
|
|
3461
|
+
const timelines = /* @__PURE__ */ new Map();
|
|
3462
|
+
const campaigns = await mapConcurrent(
|
|
3463
|
+
found.records,
|
|
3464
|
+
(lead) => summarize2(context, timelines, lead)
|
|
3465
|
+
);
|
|
3466
|
+
const contacted = campaigns.filter((entry) => entry.messagesSent > 0);
|
|
3467
|
+
const replied = campaigns.filter((entry) => entry.replied);
|
|
3468
|
+
const summary = {
|
|
3469
|
+
campaigns,
|
|
3470
|
+
found: campaigns.length > 0,
|
|
3471
|
+
identifiers: found.keys,
|
|
3472
|
+
totals: {
|
|
3473
|
+
byChannel: byChannel2(campaigns),
|
|
3474
|
+
campaignReplyRate: rate(
|
|
3475
|
+
contacted.filter((entry) => entry.replied).length,
|
|
3476
|
+
contacted.length
|
|
3477
|
+
),
|
|
3478
|
+
campaigns: campaigns.length,
|
|
3479
|
+
campaignsReplied: replied.length,
|
|
3480
|
+
messagesSent: campaigns.reduce(
|
|
3481
|
+
(sum, entry) => sum + entry.messagesSent,
|
|
3482
|
+
0
|
|
3483
|
+
),
|
|
3484
|
+
replies: campaigns.reduce((sum, entry) => sum + entry.replies, 0)
|
|
3485
|
+
}
|
|
3486
|
+
};
|
|
3487
|
+
return summary;
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
|
|
3491
|
+
// src/insights/people/personalization-gaps.ts
|
|
3492
|
+
import { z as z22 } from "zod";
|
|
3493
|
+
var input19 = z22.object({
|
|
3494
|
+
campaign: z22.string().min(1).describe("The campaign's ref (provider:workspace:id)"),
|
|
3495
|
+
limit: z22.number().int().min(1).max(5e3).default(100).describe("How many affected leads to list. The counts cover all of them."),
|
|
3496
|
+
max_leads: z22.number().int().min(1).max(2e4).default(500).describe(
|
|
3497
|
+
"The most leads to check. A vendor request returns about 50 to 100 leads."
|
|
3498
|
+
)
|
|
3499
|
+
});
|
|
3500
|
+
var PATTERNS = [
|
|
3501
|
+
/\{\{\s*(?<name>[^{}|]+?)\s*(?<fallback>\|[^{}]*)?\}\}/gu,
|
|
3502
|
+
/(?<!\{)\{(?<name>[A-Za-z_][\w .-]*)\}(?!\})/gu,
|
|
3503
|
+
/%(?<name>[A-Za-z_][\w-]*)%/gu
|
|
3504
|
+
];
|
|
3505
|
+
var keyOf = (name) => name.toLowerCase().replaceAll(/[\s_-]/gu, "");
|
|
3506
|
+
var BUILTINS = /* @__PURE__ */ new Map([
|
|
3507
|
+
["company", (lead) => lead.company],
|
|
3508
|
+
["companyname", (lead) => lead.company],
|
|
3509
|
+
["email", (lead) => lead.email],
|
|
3510
|
+
["firstname", (lead) => lead.firstName],
|
|
3511
|
+
["jobtitle", (lead) => lead.title],
|
|
3512
|
+
["lastname", (lead) => lead.lastName],
|
|
3513
|
+
["title", (lead) => lead.title]
|
|
3514
|
+
]);
|
|
3515
|
+
var FIELDS = ["subject", "body"];
|
|
3516
|
+
var variablesIn = (text) => PATTERNS.flatMap(
|
|
3517
|
+
(pattern) => [...text.matchAll(pattern)].map((match) => ({
|
|
3518
|
+
fallback: match.groups?.fallback !== void 0,
|
|
3519
|
+
name: match.groups?.name ?? ""
|
|
3520
|
+
}))
|
|
3521
|
+
);
|
|
3522
|
+
var findVariables = (sequence2) => {
|
|
3523
|
+
const found = /* @__PURE__ */ new Map();
|
|
3524
|
+
const texts = sequence2.steps.flatMap(
|
|
3525
|
+
(step) => step.variants.flatMap(
|
|
3526
|
+
(variant) => FIELDS.map((field) => ({
|
|
3527
|
+
field,
|
|
3528
|
+
step: step.index,
|
|
3529
|
+
text: variant[field] ?? "",
|
|
3530
|
+
variant: variant.variantKey
|
|
3531
|
+
}))
|
|
3532
|
+
)
|
|
3533
|
+
);
|
|
3534
|
+
for (const { field, step, text, variant } of texts) {
|
|
3535
|
+
for (const { fallback, name } of variablesIn(text)) {
|
|
3536
|
+
const entry = found.get(keyOf(name)) ?? { name, uses: [] };
|
|
3537
|
+
entry.uses.push({ fallback, field, step, variant });
|
|
3538
|
+
found.set(keyOf(name), entry);
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
return found;
|
|
3542
|
+
};
|
|
3543
|
+
var filled = (value) => value !== null && value.trim() !== "";
|
|
3544
|
+
var valuesOf = (lead) => /* @__PURE__ */ new Set([
|
|
3545
|
+
...[...BUILTINS].flatMap(
|
|
3546
|
+
([key, read]) => filled(read(lead)) ? [key] : []
|
|
3547
|
+
),
|
|
3548
|
+
...Object.entries(lead.custom).flatMap(
|
|
3549
|
+
([key, value]) => filled(value) ? [keyOf(key)] : []
|
|
3550
|
+
)
|
|
3551
|
+
]);
|
|
3552
|
+
var sourceOf = (key, customKeys) => {
|
|
3553
|
+
if (BUILTINS.has(key)) {
|
|
3554
|
+
return "builtin";
|
|
3555
|
+
}
|
|
3556
|
+
return customKeys.has(key) ? "custom" : "unknown";
|
|
3557
|
+
};
|
|
3558
|
+
var toVariable = (key, { name, uses }, leads, customKeys) => {
|
|
3559
|
+
const source = sourceOf(key, customKeys);
|
|
3560
|
+
const known2 = source !== "unknown";
|
|
3561
|
+
const needed = uses.some((use) => !use.fallback);
|
|
3562
|
+
const without = leads.filter((values) => !values.has(key)).length;
|
|
3563
|
+
return {
|
|
3564
|
+
key,
|
|
3565
|
+
variable: {
|
|
3566
|
+
gap: known2 && needed,
|
|
3567
|
+
leadsAffected: known2 ? Number(needed) * without : null,
|
|
3568
|
+
leadsWithoutValue: known2 ? without : null,
|
|
3569
|
+
name,
|
|
3570
|
+
source,
|
|
3571
|
+
steps: [...new Set(uses.map((use) => use.step))].toSorted(
|
|
3572
|
+
(left, right) => left - right
|
|
3573
|
+
),
|
|
3574
|
+
uses
|
|
3575
|
+
}
|
|
3576
|
+
};
|
|
3577
|
+
};
|
|
3578
|
+
var missingOf = (lead, values, gaps) => {
|
|
3579
|
+
const missing2 = gaps.flatMap(
|
|
3580
|
+
(gap) => values.has(gap.key) ? [] : [gap.variable.name]
|
|
3581
|
+
);
|
|
3582
|
+
return missing2.length === 0 ? [] : [
|
|
3583
|
+
{
|
|
3584
|
+
email: lead.email,
|
|
3585
|
+
lead: lead.ref,
|
|
3586
|
+
linkedinUrl: lead.linkedinUrl,
|
|
3587
|
+
missing: missing2,
|
|
3588
|
+
status: lead.status
|
|
3589
|
+
}
|
|
3590
|
+
];
|
|
3591
|
+
};
|
|
3592
|
+
var personalizationGaps = defineInsight({
|
|
3593
|
+
description: "Leads in one campaign who will get broken copy because a merge variable has no value for them. Reads the campaign's sequence, finds every {{variable}}, {variable} and %variable% in subjects and bodies, and checks each lead for a value: first name, last name, company, title, email, or a custom field of the same name without regard to case, spaces, underscores or hyphens. Returns the variables with the steps that use them, how many leads each one affects, and the leads missing at least one. A variable with a fallback such as {{firstName|there}} is not a gap. A variable no lead has, such as a sender signature the tool fills in, is listed as unknown, not counted against leads. Costs one request for the sequence plus one per page of leads.",
|
|
3594
|
+
inputSchema: input19,
|
|
3595
|
+
key: "personalizationGaps",
|
|
3596
|
+
name: "personalization_gaps",
|
|
3597
|
+
needs: ["sequence", "leads.byCampaign"],
|
|
3598
|
+
next: "Fix the leads' fields or add a fallback in the tool, then use lead_collisions to check the same leads are not in another campaign.",
|
|
3599
|
+
run: async (context, values) => {
|
|
3600
|
+
const sequence2 = context.one(
|
|
3601
|
+
await context.outbound.campaign(values.campaign).sequence()
|
|
3602
|
+
);
|
|
3603
|
+
const found = findVariables(sequence2);
|
|
3604
|
+
const leads = found.size === 0 ? [] : await leadsOf(context, values.campaign, values.max_leads);
|
|
3605
|
+
if (found.size === 0) {
|
|
3606
|
+
context.note("The sequence uses no variables, so no lead was read.");
|
|
3607
|
+
}
|
|
3608
|
+
const customKeys = new Set(
|
|
3609
|
+
leads.flatMap((lead) => Object.keys(lead.custom).map(keyOf))
|
|
3610
|
+
);
|
|
3611
|
+
const keyed = [...found].map(
|
|
3612
|
+
([key, entry]) => toVariable(key, entry, leads.map(valuesOf), customKeys)
|
|
3613
|
+
);
|
|
3614
|
+
const variables = keyed.map((each) => each.variable).toSorted(
|
|
3615
|
+
(left, right) => (right.leadsAffected ?? -1) - (left.leadsAffected ?? -1) || left.name.localeCompare(right.name)
|
|
3616
|
+
);
|
|
3617
|
+
const gaps = keyed.filter((each) => each.variable.gap);
|
|
3618
|
+
const affected = leads.flatMap((lead) => missingOf(lead, valuesOf(lead), gaps)).toSorted(
|
|
3619
|
+
(left, right) => right.missing.length - left.missing.length || left.lead.localeCompare(right.lead)
|
|
3620
|
+
);
|
|
3621
|
+
const answer = {
|
|
3622
|
+
campaign: values.campaign,
|
|
3623
|
+
leads: affected.slice(0, values.limit),
|
|
3624
|
+
totals: {
|
|
3625
|
+
affectedRate: rate(affected.length, leads.length),
|
|
3626
|
+
leadsAffected: affected.length,
|
|
3627
|
+
leadsRead: leads.length,
|
|
3628
|
+
steps: sequence2.steps.length,
|
|
3629
|
+
variables: variables.length
|
|
3630
|
+
},
|
|
3631
|
+
unknownVariables: variables.flatMap(
|
|
3632
|
+
(each) => each.source === "unknown" ? [each.name] : []
|
|
3633
|
+
),
|
|
3634
|
+
variables
|
|
3635
|
+
};
|
|
3636
|
+
return answer;
|
|
3637
|
+
}
|
|
3638
|
+
});
|
|
3639
|
+
|
|
3640
|
+
// src/insights/people/suppression-check.ts
|
|
3641
|
+
import { z as z23 } from "zod";
|
|
3642
|
+
var input20 = z23.object({
|
|
3643
|
+
max_block_entries: z23.number().int().min(1).max(1e5).default(2e3).describe(
|
|
3644
|
+
"The most block list entries to read. A vendor request returns about 50 to 100."
|
|
3645
|
+
),
|
|
3646
|
+
max_campaigns: z23.number().int().min(1).max(200).default(20).describe(
|
|
3647
|
+
"The most campaigns to check. Each costs one request per page of its leads."
|
|
3648
|
+
),
|
|
3649
|
+
max_leads_per_campaign: z23.number().int().min(1).max(2e4).default(500).describe("The most leads to read from each campaign"),
|
|
3650
|
+
statuses: statusesField
|
|
3651
|
+
});
|
|
3652
|
+
var slugOfEntry = (value) => profileSlug(value) ?? value.trim().replaceAll(/^\/+|\/+$/gu, "").toLowerCase();
|
|
3653
|
+
var indexEntries = (entries) => {
|
|
3654
|
+
const blocked = {
|
|
3655
|
+
domain: /* @__PURE__ */ new Map(),
|
|
3656
|
+
email: /* @__PURE__ */ new Map(),
|
|
3657
|
+
linkedin: /* @__PURE__ */ new Map(),
|
|
3658
|
+
notChecked: entries.filter(
|
|
3659
|
+
(entry) => entry.kind === "company" || entry.kind === "other"
|
|
3660
|
+
).length
|
|
3661
|
+
};
|
|
3662
|
+
for (const entry of entries) {
|
|
3663
|
+
if (entry.kind === "email") {
|
|
3664
|
+
blocked.email.set(entry.value.trim().toLowerCase(), entry);
|
|
3665
|
+
} else if (entry.kind === "domain") {
|
|
3666
|
+
blocked.domain.set(
|
|
3667
|
+
entry.value.trim().toLowerCase().replace(/^@/u, ""),
|
|
3668
|
+
entry
|
|
3669
|
+
);
|
|
3670
|
+
} else if (entry.kind === "linkedin") {
|
|
3671
|
+
blocked.linkedin.set(slugOfEntry(entry.value), entry);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
return blocked;
|
|
3675
|
+
};
|
|
3676
|
+
var matchLead = (lead, blocked) => {
|
|
3677
|
+
const slug = profileSlug(lead.linkedinUrl);
|
|
3678
|
+
const candidates = [
|
|
3679
|
+
["email", blocked.email.get(lead.email ?? "")],
|
|
3680
|
+
["linkedin", blocked.linkedin.get(slug ?? "")],
|
|
3681
|
+
["domain", blocked.domain.get(domainOf(lead.email) ?? "")]
|
|
3682
|
+
];
|
|
3683
|
+
const hits = candidates.flatMap(
|
|
3684
|
+
([matchedBy, entry]) => entry === void 0 ? [] : [{ entry, matchedBy }]
|
|
3685
|
+
);
|
|
3686
|
+
return hits[0] ?? null;
|
|
3687
|
+
};
|
|
3688
|
+
var toViolation = (lead, campaign, { entry, matchedBy }) => ({
|
|
3689
|
+
campaign: campaign.ref,
|
|
3690
|
+
campaignName: campaign.name,
|
|
3691
|
+
email: lead.email,
|
|
3692
|
+
entry: entry.ref,
|
|
3693
|
+
entryValue: entry.value,
|
|
3694
|
+
finding: `${lead.email ?? lead.linkedinUrl ?? lead.ref} is in "${campaign.name}" but the block list holds the ${matchedBy} ${entry.value}.`,
|
|
3695
|
+
lead: lead.ref,
|
|
3696
|
+
leadStatus: lead.status,
|
|
3697
|
+
linkedinUrl: lead.linkedinUrl,
|
|
3698
|
+
matchedBy,
|
|
3699
|
+
sameTool: entry.provider === lead.provider && entry.workspaceId === lead.workspaceId
|
|
3700
|
+
});
|
|
3701
|
+
var activeFirst = (left, right) => Number(right.leadStatus === "active") - Number(left.leadStatus === "active") || left.campaign.localeCompare(right.campaign) || left.lead.localeCompare(right.lead);
|
|
3702
|
+
var suppressionCheck = defineInsight({
|
|
3703
|
+
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. 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.",
|
|
3704
|
+
inputSchema: input20,
|
|
3705
|
+
key: "suppressionCheck",
|
|
3706
|
+
name: "suppression_check",
|
|
3707
|
+
needs: ["blocklist", "leads.byCampaign"],
|
|
3708
|
+
next: "Use person_summary with a violating lead's email address to see what they were already sent.",
|
|
3709
|
+
run: async (context, values) => {
|
|
3710
|
+
const entries = await readCapped2(
|
|
3711
|
+
context,
|
|
3712
|
+
(cap) => context.outbound.blocklist.listAll({ max: cap }),
|
|
3713
|
+
values.max_block_entries,
|
|
3714
|
+
"block list entries"
|
|
3715
|
+
);
|
|
3716
|
+
const blocked = indexEntries(entries);
|
|
3717
|
+
const campaigns = await campaignsIn2(
|
|
3718
|
+
context,
|
|
3719
|
+
values.statuses,
|
|
3720
|
+
values.max_campaigns
|
|
3721
|
+
);
|
|
3722
|
+
const violations = [];
|
|
3723
|
+
const byCampaign = [];
|
|
3724
|
+
const read = await mapConcurrent(campaigns, async (campaign) => ({
|
|
3725
|
+
campaign,
|
|
3726
|
+
leads: await leadsOf(
|
|
3727
|
+
context,
|
|
3728
|
+
campaign.ref,
|
|
3729
|
+
values.max_leads_per_campaign
|
|
3730
|
+
)
|
|
3731
|
+
}));
|
|
3732
|
+
for (const { campaign, leads } of read) {
|
|
3733
|
+
const found = leads.flatMap((lead) => {
|
|
3734
|
+
const hit = matchLead(lead, blocked);
|
|
3735
|
+
return hit === null ? [] : [toViolation(lead, campaign, hit)];
|
|
3736
|
+
});
|
|
3737
|
+
violations.push(...found);
|
|
3738
|
+
byCampaign.push({
|
|
3739
|
+
campaign: campaign.ref,
|
|
3740
|
+
campaignName: campaign.name,
|
|
3741
|
+
leadsRead: leads.length,
|
|
3742
|
+
violations: found.length
|
|
3743
|
+
});
|
|
3744
|
+
}
|
|
3745
|
+
const matches = tally(violations.map((each) => each.matchedBy));
|
|
3746
|
+
const answer = {
|
|
3747
|
+
byCampaign: byCampaign.toSorted(
|
|
3748
|
+
(left, right) => right.violations - left.violations || left.campaign.localeCompare(right.campaign)
|
|
3749
|
+
),
|
|
3750
|
+
totals: {
|
|
3751
|
+
blockEntriesNotChecked: blocked.notChecked,
|
|
3752
|
+
blockEntriesRead: entries.length,
|
|
3753
|
+
byMatch: {
|
|
3754
|
+
domain: matches.get("domain") ?? 0,
|
|
3755
|
+
email: matches.get("email") ?? 0,
|
|
3756
|
+
linkedin: matches.get("linkedin") ?? 0
|
|
3757
|
+
},
|
|
3758
|
+
campaignsRead: campaigns.length,
|
|
3759
|
+
leadsRead: byCampaign.reduce((sum, each) => sum + each.leadsRead, 0),
|
|
3760
|
+
violations: violations.length
|
|
3761
|
+
},
|
|
3762
|
+
violations: violations.toSorted(activeFirst)
|
|
3763
|
+
};
|
|
3764
|
+
return answer;
|
|
3765
|
+
}
|
|
3766
|
+
});
|
|
3767
|
+
|
|
3768
|
+
// src/insights/people/index.ts
|
|
3769
|
+
var PEOPLE_INSIGHTS = [
|
|
3770
|
+
personSummary,
|
|
3771
|
+
accountSummary,
|
|
3772
|
+
leadCollisions,
|
|
3773
|
+
suppressionCheck,
|
|
3774
|
+
droppedReplies,
|
|
3775
|
+
hotLeads,
|
|
3776
|
+
personalizationGaps
|
|
3777
|
+
];
|
|
3778
|
+
|
|
3779
|
+
// src/insights/senders/bounce-watch.ts
|
|
3780
|
+
import { z as z25 } from "zod";
|
|
3781
|
+
|
|
3782
|
+
// src/insights/senders/read.ts
|
|
3783
|
+
import { z as z24 } from "zod";
|
|
3784
|
+
var statusesInput = z24.array(campaignStatusSchema).min(1).default(["active"]).describe(
|
|
3785
|
+
"Campaign statuses to look at: active, paused, draft, completed, archived or unknown"
|
|
3786
|
+
);
|
|
3787
|
+
var dayInput2 = (what) => z24.string().regex(/^\d{4}-\d{2}-\d{2}$/u).optional().describe(
|
|
3788
|
+
`${what}, as YYYY-MM-DD. Leave out for the vendor's whole history.`
|
|
3789
|
+
);
|
|
3790
|
+
var readCapped3 = (context, walk, max, what) => context.all(walk(max), `${max} ${what}`);
|
|
3791
|
+
var readCampaigns2 = async (context, statuses, max) => {
|
|
3792
|
+
const { outbound } = context;
|
|
3793
|
+
if (outbound.capabilities["campaigns.status"] === false) {
|
|
3794
|
+
const every = await readCapped3(
|
|
3795
|
+
context,
|
|
3796
|
+
(cap) => outbound.campaigns.listAll({ max: cap }),
|
|
3797
|
+
max,
|
|
3798
|
+
"campaigns"
|
|
3799
|
+
);
|
|
3800
|
+
return every.filter((campaign) => statuses.includes(campaign.status));
|
|
3801
|
+
}
|
|
3802
|
+
const found = [];
|
|
3803
|
+
for (const status of new Set(statuses)) {
|
|
3804
|
+
const room = max - found.length;
|
|
3805
|
+
if (room <= 0) {
|
|
3806
|
+
context.partial(
|
|
3807
|
+
`The cap of ${max} campaigns was reached before ${status} campaigns were read.`
|
|
3808
|
+
);
|
|
3809
|
+
break;
|
|
3810
|
+
}
|
|
3811
|
+
found.push(
|
|
3812
|
+
...await readCapped3(
|
|
3813
|
+
context,
|
|
3814
|
+
(cap) => outbound.campaigns.listAll({ max: cap, status }),
|
|
3815
|
+
room,
|
|
3816
|
+
"campaigns"
|
|
3817
|
+
)
|
|
3818
|
+
);
|
|
3819
|
+
}
|
|
3820
|
+
return found;
|
|
3821
|
+
};
|
|
3822
|
+
var readCampaignSenders = (context, campaign, max) => readCapped3(
|
|
3823
|
+
context,
|
|
3824
|
+
(cap) => context.outbound.campaign(campaign.ref).senders.listAll({ max: cap }),
|
|
3825
|
+
max,
|
|
3826
|
+
`senders of campaign ${campaign.name}`
|
|
3827
|
+
);
|
|
3828
|
+
var domainOf2 = (address) => {
|
|
3829
|
+
const domain = address?.split("@")[1]?.trim().toLowerCase() ?? "";
|
|
3830
|
+
return domain === "" ? null : domain;
|
|
3831
|
+
};
|
|
3832
|
+
var DNS_RECORDS = ["spf", "dkim", "dmarc", "mx"];
|
|
3833
|
+
var failingDns = (health) => DNS_RECORDS.filter((record) => health.dns[record] === false);
|
|
3834
|
+
var unknownDns = (health) => DNS_RECORDS.filter((record) => health.dns[record] === null);
|
|
3835
|
+
var warmupSpam = (health) => {
|
|
3836
|
+
const { warmup } = health;
|
|
3837
|
+
if (warmup === null || warmup.spam === null) {
|
|
3838
|
+
return null;
|
|
3839
|
+
}
|
|
3840
|
+
const sent = warmup.sent ?? (warmup.inbox === null ? null : warmup.inbox + warmup.spam);
|
|
3841
|
+
return sent === null ? null : { sent, spam: warmup.spam };
|
|
3842
|
+
};
|
|
3843
|
+
var dayFrom = (now, offsetDays) => new Date(now + offsetDays * 864e5).toISOString().slice(0, 10);
|
|
3844
|
+
|
|
3845
|
+
// src/insights/senders/bounce-watch.ts
|
|
3846
|
+
var input21 = z25.object({
|
|
3847
|
+
from: dayInput2("First day to count"),
|
|
3848
|
+
include_senders: z25.boolean().default(true).describe(
|
|
3849
|
+
"Also check the senders of each campaign over the threshold. Costs 1 listing per such campaign and 1 request per sender."
|
|
3850
|
+
),
|
|
3851
|
+
max_campaigns: z25.number().int().min(1).max(500).default(50).describe("The most campaigns to check. Each costs 1 request."),
|
|
3852
|
+
max_senders_per_campaign: z25.number().int().min(1).max(200).default(10).describe("The most senders to check for one campaign over the threshold"),
|
|
3853
|
+
min_sent: z25.number().int().min(0).default(100).describe("A campaign with fewer sends than this is too small to judge"),
|
|
3854
|
+
threshold: z25.number().min(0).max(1).default(0.03).describe("The bounce rate, bounced divided by sent, that is too high"),
|
|
3855
|
+
to: dayInput2("Last day to count")
|
|
3856
|
+
});
|
|
3857
|
+
var countsOf2 = (bounced, sent) => ({
|
|
3858
|
+
bounced,
|
|
3859
|
+
interval: wilson(bounced, sent),
|
|
3860
|
+
rate: rate(bounced, sent),
|
|
3861
|
+
sent
|
|
3862
|
+
});
|
|
3863
|
+
var known = (row) => row === void 0 || row.sent === null || row.bounced === null ? null : countsOf2(row.bounced, row.sent);
|
|
3864
|
+
var isOver = (counts, threshold) => counts.rate !== null && counts.rate > threshold;
|
|
3865
|
+
var whyUnknown = (row) => {
|
|
3866
|
+
if (row === void 0) {
|
|
3867
|
+
return "The vendor returned no stats for the period.";
|
|
3868
|
+
}
|
|
3869
|
+
return row.sent === null ? "The vendor does not report a sent count." : "The vendor does not report a bounce count.";
|
|
3870
|
+
};
|
|
3871
|
+
var senderReader = (context, range) => {
|
|
3872
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3873
|
+
return (ref) => {
|
|
3874
|
+
let counts = seen.get(ref);
|
|
3875
|
+
if (counts === void 0) {
|
|
3876
|
+
counts = context.outbound.sender(ref).stats(range).then((stats) => known(context.rows(stats)[0]));
|
|
3877
|
+
seen.set(ref, counts);
|
|
3878
|
+
}
|
|
3879
|
+
return counts;
|
|
3880
|
+
};
|
|
3881
|
+
};
|
|
3882
|
+
var sendersOver = async (context, campaign, options) => {
|
|
3883
|
+
const senders2 = await readCampaignSenders(context, campaign, options.max);
|
|
3884
|
+
const read = await mapConcurrent(senders2, async (sender) => ({
|
|
3885
|
+
counts: await options.read(sender.ref),
|
|
3886
|
+
sender
|
|
3887
|
+
}));
|
|
3888
|
+
const over = read.flatMap(
|
|
3889
|
+
({ counts, sender }) => counts !== null && isOver(counts, options.threshold) ? [
|
|
3890
|
+
{
|
|
3891
|
+
...counts,
|
|
3892
|
+
address: sender.address,
|
|
3893
|
+
name: sender.name,
|
|
3894
|
+
sender: sender.ref
|
|
3895
|
+
}
|
|
3896
|
+
] : []
|
|
3897
|
+
);
|
|
3898
|
+
return over.toSorted((left, right) => (right.rate ?? 0) - (left.rate ?? 0));
|
|
3899
|
+
};
|
|
3900
|
+
var canCheckSenders = (context, wanted) => {
|
|
3901
|
+
const { capabilities } = context.outbound;
|
|
3902
|
+
if (!wanted) {
|
|
3903
|
+
return false;
|
|
3904
|
+
}
|
|
3905
|
+
if (capabilities["stats.bySender"] === false || !capabilities["senders.byCampaign"]) {
|
|
3906
|
+
context.note(
|
|
3907
|
+
"Senders were not checked: the adapter needs stats per sender and the list of a campaign's senders."
|
|
3908
|
+
);
|
|
3909
|
+
return false;
|
|
3910
|
+
}
|
|
3911
|
+
return true;
|
|
3912
|
+
};
|
|
3913
|
+
var bounceWatch = defineInsight({
|
|
3914
|
+
description: "Where bounces are too high: the campaigns whose bounce rate (bounced divided by sent) is over a threshold, worst first, each with bounced, sent, the rate and its Wilson interval, and the senders of each such campaign that are themselves over the threshold. Campaigns with too few sends to judge and campaigns with no reported bounce count are listed apart, never as clean. Use it daily, or when a domain's reputation is in doubt. Costs one listing of campaigns and 1 request per campaign, plus 1 listing and up to 1 request per sender for each campaign over the threshold. A null rate means nothing was sent.",
|
|
3915
|
+
inputSchema: input21,
|
|
3916
|
+
key: "bounceWatch",
|
|
3917
|
+
name: "bounce_watch",
|
|
3918
|
+
needs: ["stats.campaign"],
|
|
3919
|
+
next: "Use domain_health on the senders named here, and settings_audit on the campaigns over the threshold.",
|
|
3920
|
+
run: async (context, options) => {
|
|
3921
|
+
const { outbound } = context;
|
|
3922
|
+
const { min_sent: minSent, threshold } = options;
|
|
3923
|
+
const range = { from: options.from, to: options.to };
|
|
3924
|
+
const campaigns = await readCapped3(
|
|
3925
|
+
context,
|
|
3926
|
+
(cap) => outbound.campaigns.listAll({ max: cap }),
|
|
3927
|
+
options.max_campaigns,
|
|
3928
|
+
"campaigns"
|
|
3929
|
+
);
|
|
3930
|
+
const withSenders = campaigns.length > 0 && canCheckSenders(context, options.include_senders);
|
|
3931
|
+
const read = senderReader(context, range);
|
|
3932
|
+
const overBy = [];
|
|
3933
|
+
const tooFewSends = [];
|
|
3934
|
+
const unknown = [];
|
|
3935
|
+
const counted = [];
|
|
3936
|
+
const rows = await mapConcurrent(campaigns, async (campaign) => ({
|
|
3937
|
+
campaign,
|
|
3938
|
+
row: context.rows(await outbound.campaign(campaign.ref).stats(range))[0]
|
|
3939
|
+
}));
|
|
3940
|
+
for (const { campaign, row } of rows) {
|
|
3941
|
+
const counts = known(row);
|
|
3942
|
+
const entry = {
|
|
3943
|
+
campaign: campaign.ref,
|
|
3944
|
+
name: campaign.name,
|
|
3945
|
+
status: campaign.status
|
|
3946
|
+
};
|
|
3947
|
+
if (counts === null) {
|
|
3948
|
+
unknown.push({ ...entry, reason: whyUnknown(row) });
|
|
3949
|
+
} else if (counts.sent < minSent || counts.sent === 0) {
|
|
3950
|
+
counted.push(counts);
|
|
3951
|
+
tooFewSends.push({
|
|
3952
|
+
...entry,
|
|
3953
|
+
...counts,
|
|
3954
|
+
finding: `${counts.bounced} of ${counts.sent} sends bounced; under ${minSent} sends is too few to judge.`,
|
|
3955
|
+
senders: null
|
|
3956
|
+
});
|
|
3957
|
+
} else {
|
|
3958
|
+
counted.push(counts);
|
|
3959
|
+
if (isOver(counts, threshold)) {
|
|
3960
|
+
overBy.push({
|
|
3961
|
+
campaign,
|
|
3962
|
+
entry: {
|
|
3963
|
+
...entry,
|
|
3964
|
+
...counts,
|
|
3965
|
+
finding: `${counts.bounced} of ${counts.sent} sends bounced (${counts.rate}), over the ${threshold} threshold.`,
|
|
3966
|
+
senders: null
|
|
3967
|
+
}
|
|
3968
|
+
});
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
const over = await mapConcurrent(
|
|
3973
|
+
overBy,
|
|
3974
|
+
async ({ campaign, entry }) => withSenders ? {
|
|
3975
|
+
...entry,
|
|
3976
|
+
senders: await sendersOver(context, campaign, {
|
|
3977
|
+
max: options.max_senders_per_campaign,
|
|
3978
|
+
read,
|
|
3979
|
+
threshold
|
|
3980
|
+
})
|
|
3981
|
+
} : entry
|
|
3982
|
+
);
|
|
3983
|
+
const bounced = total(counted.map((each) => each.bounced));
|
|
3984
|
+
const sent = total(counted.map((each) => each.sent));
|
|
3985
|
+
const byRate2 = (left, right) => (right.rate ?? -1) - (left.rate ?? -1);
|
|
3986
|
+
const answer = {
|
|
3987
|
+
minSent,
|
|
3988
|
+
over: over.toSorted(byRate2),
|
|
3989
|
+
threshold,
|
|
3990
|
+
tooFewSends: tooFewSends.toSorted(byRate2),
|
|
3991
|
+
totals: {
|
|
3992
|
+
bounced,
|
|
3993
|
+
campaigns: campaigns.length,
|
|
3994
|
+
clean: counted.length - over.length - tooFewSends.length,
|
|
3995
|
+
over: over.length,
|
|
3996
|
+
rate: rate(bounced, sent),
|
|
3997
|
+
sent,
|
|
3998
|
+
tooFewSends: tooFewSends.length,
|
|
3999
|
+
unknown: unknown.length
|
|
4000
|
+
},
|
|
4001
|
+
unknown
|
|
4002
|
+
};
|
|
4003
|
+
return answer;
|
|
4004
|
+
}
|
|
4005
|
+
});
|
|
4006
|
+
|
|
4007
|
+
// src/insights/senders/domain-health.ts
|
|
4008
|
+
import { z as z26 } from "zod";
|
|
4009
|
+
var input22 = z26.object({
|
|
4010
|
+
max_senders: z26.number().int().min(1).max(500).default(50).describe("The most senders to check. Each costs 1 request."),
|
|
4011
|
+
spam_rate_threshold: z26.number().min(0).max(1).default(0.1).describe(
|
|
4012
|
+
"A domain whose warmup emails land in spam more often than this share is high risk"
|
|
4013
|
+
)
|
|
4014
|
+
});
|
|
4015
|
+
var RISK_ORDER = ["high", "medium", "low", "unknown"];
|
|
4016
|
+
var pooledWarmup = (checked) => {
|
|
4017
|
+
const reported = checked.flatMap(({ health }) => {
|
|
4018
|
+
const spam2 = warmupSpam(health);
|
|
4019
|
+
return spam2 === null ? [] : [spam2];
|
|
4020
|
+
});
|
|
4021
|
+
if (reported.length === 0) {
|
|
4022
|
+
return {
|
|
4023
|
+
interval: null,
|
|
4024
|
+
mailboxes: 0,
|
|
4025
|
+
sent: null,
|
|
4026
|
+
spam: null,
|
|
4027
|
+
spamRate: null
|
|
4028
|
+
};
|
|
4029
|
+
}
|
|
4030
|
+
const sent = reported.reduce((sum, each) => sum + each.sent, 0);
|
|
4031
|
+
const spam = reported.reduce((sum, each) => sum + each.spam, 0);
|
|
4032
|
+
return {
|
|
4033
|
+
interval: wilson(spam, sent),
|
|
4034
|
+
mailboxes: reported.length,
|
|
4035
|
+
sent,
|
|
4036
|
+
spam,
|
|
4037
|
+
spamRate: rate(spam, sent)
|
|
4038
|
+
};
|
|
4039
|
+
};
|
|
4040
|
+
var missingChecks = (checked, warmup) => [
|
|
4041
|
+
...DNS_RECORDS.filter(
|
|
4042
|
+
(record) => checked.every(({ health }) => unknownDns(health).includes(record))
|
|
4043
|
+
),
|
|
4044
|
+
...checked.every(({ health }) => health.connected === null) ? ["connection"] : [],
|
|
4045
|
+
...checked.every(({ health }) => health.blacklisted === null) ? ["blocklist"] : [],
|
|
4046
|
+
...warmup.mailboxes === 0 ? ["warmup"] : []
|
|
4047
|
+
];
|
|
4048
|
+
var CHECKS3 = DNS_RECORDS.length + 3;
|
|
4049
|
+
var reportFor = (domain, checked, threshold) => {
|
|
4050
|
+
const failing = DNS_RECORDS.filter(
|
|
4051
|
+
(record) => checked.some(({ health }) => health.dns[record] === false)
|
|
4052
|
+
);
|
|
4053
|
+
const blacklisted = checked.filter(
|
|
4054
|
+
({ health }) => health.blacklisted === true
|
|
4055
|
+
).length;
|
|
4056
|
+
const disconnected = checked.filter(
|
|
4057
|
+
({ health }) => health.connected === false
|
|
4058
|
+
).length;
|
|
4059
|
+
const warmup = pooledWarmup(checked);
|
|
4060
|
+
const authFailing = failing.filter((record) => record !== "dmarc");
|
|
4061
|
+
const spamHigh = warmup.spamRate !== null && warmup.spamRate > threshold;
|
|
4062
|
+
const high = [
|
|
4063
|
+
...blacklisted > 0 ? [`${blacklisted} of ${checked.length} mailboxes are on a block list`] : [],
|
|
4064
|
+
...authFailing.length > 0 ? [`${authFailing.join(", ").toUpperCase()} failing`] : [],
|
|
4065
|
+
...spamHigh ? [
|
|
4066
|
+
`${warmup.spam} of ${warmup.sent} warmup emails landed in spam (${warmup.spamRate}, over ${threshold})`
|
|
4067
|
+
] : []
|
|
4068
|
+
];
|
|
4069
|
+
const medium = [
|
|
4070
|
+
...failing.includes("dmarc") ? ["DMARC failing"] : [],
|
|
4071
|
+
...disconnected > 0 ? [`${disconnected} of ${checked.length} mailboxes are disconnected`] : []
|
|
4072
|
+
];
|
|
4073
|
+
const notReported = missingChecks(checked, warmup);
|
|
4074
|
+
const calm = notReported.length === CHECKS3 ? "unknown" : "low";
|
|
4075
|
+
const lesser = medium.length > 0 ? "medium" : calm;
|
|
4076
|
+
return {
|
|
4077
|
+
blacklisted,
|
|
4078
|
+
disconnected,
|
|
4079
|
+
domain,
|
|
4080
|
+
failingDns: failing,
|
|
4081
|
+
mailboxes: checked.map(({ health, sender }) => ({
|
|
4082
|
+
address: sender.address,
|
|
4083
|
+
blacklisted: health.blacklisted,
|
|
4084
|
+
connected: health.connected,
|
|
4085
|
+
failingDns: failingDns(health),
|
|
4086
|
+
issues: health.issues,
|
|
4087
|
+
sender: sender.ref,
|
|
4088
|
+
status: sender.status
|
|
4089
|
+
})),
|
|
4090
|
+
notReported,
|
|
4091
|
+
reasons: [...high, ...medium],
|
|
4092
|
+
risk: high.length > 0 ? "high" : lesser,
|
|
4093
|
+
warmup
|
|
4094
|
+
};
|
|
4095
|
+
};
|
|
4096
|
+
var worstFirst2 = (left, right) => RISK_ORDER.indexOf(left.risk) - RISK_ORDER.indexOf(right.risk) || right.reasons.length - left.reasons.length || (right.warmup.spamRate ?? -1) - (left.warmup.spamRate ?? -1) || left.domain.localeCompare(right.domain);
|
|
4097
|
+
var seatRank = (seat) => {
|
|
4098
|
+
if (seat.connected === false) {
|
|
4099
|
+
return 0;
|
|
4100
|
+
}
|
|
4101
|
+
return seat.connected === null ? 1 : 2;
|
|
4102
|
+
};
|
|
4103
|
+
var domainHealth = defineInsight({
|
|
4104
|
+
description: "Deliverability per sending domain: for each domain its mailboxes, which DNS records (SPF, DKIM, DMARC, MX) fail, how many mailboxes are disconnected or on a block list, the share of warmup emails landing in spam pooled over its mailboxes, and a risk level with the reasons, worst domain first. LinkedIn seats are listed apart with their connection state. Use it before scaling volume or when replies drop. Costs one listing of senders plus 1 request per sender. A null count or rate means the vendor does not report it; a domain with nothing reported has the risk `unknown`, not `low`.",
|
|
4105
|
+
inputSchema: input22,
|
|
4106
|
+
key: "domainHealth",
|
|
4107
|
+
name: "domain_health",
|
|
4108
|
+
needs: ["senders.list", "senders.health"],
|
|
4109
|
+
next: "Use warmup_readiness to see which mailboxes of a risky domain are not ready, or bounce_watch to see whether bounces already rose.",
|
|
4110
|
+
run: async (context, { max_senders: maxSenders, spam_rate_threshold: threshold }) => {
|
|
4111
|
+
const { outbound } = context;
|
|
4112
|
+
const senders2 = await readCapped3(
|
|
4113
|
+
context,
|
|
4114
|
+
(cap) => outbound.senders.listAll({ max: cap }),
|
|
4115
|
+
maxSenders,
|
|
4116
|
+
"senders"
|
|
4117
|
+
);
|
|
4118
|
+
const byDomain = /* @__PURE__ */ new Map();
|
|
4119
|
+
const linkedinSeats = [];
|
|
4120
|
+
const mailboxesWithoutDomain = [];
|
|
4121
|
+
const checks = await mapConcurrent(senders2, async (sender) => ({
|
|
4122
|
+
health: context.one(await outbound.sender(sender.ref).health()),
|
|
4123
|
+
sender
|
|
4124
|
+
}));
|
|
4125
|
+
for (const { health, sender } of checks) {
|
|
4126
|
+
const domain = health.domain ?? domainOf2(sender.address);
|
|
4127
|
+
if (sender.kind === "linkedin") {
|
|
4128
|
+
linkedinSeats.push({
|
|
4129
|
+
connected: health.connected,
|
|
4130
|
+
issues: health.issues,
|
|
4131
|
+
linkedinUrl: sender.linkedinUrl,
|
|
4132
|
+
name: sender.name,
|
|
4133
|
+
sender: sender.ref,
|
|
4134
|
+
status: sender.status
|
|
4135
|
+
});
|
|
4136
|
+
} else if (domain === null) {
|
|
4137
|
+
mailboxesWithoutDomain.push(sender.ref);
|
|
4138
|
+
} else {
|
|
4139
|
+
byDomain.set(domain, [
|
|
4140
|
+
...byDomain.get(domain) ?? [],
|
|
4141
|
+
{ health, sender }
|
|
4142
|
+
]);
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
const domains = [...byDomain].map(([domain, checked]) => reportFor(domain, checked, threshold)).toSorted(worstFirst2);
|
|
4146
|
+
const count = (risk) => domains.filter((domain) => domain.risk === risk).length;
|
|
4147
|
+
const answer = {
|
|
4148
|
+
domains,
|
|
4149
|
+
linkedinSeats: linkedinSeats.toSorted(
|
|
4150
|
+
(left, right) => seatRank(left) - seatRank(right)
|
|
4151
|
+
),
|
|
4152
|
+
mailboxesWithoutDomain,
|
|
4153
|
+
totals: {
|
|
4154
|
+
domains: domains.length,
|
|
4155
|
+
high: count("high"),
|
|
4156
|
+
linkedinSeats: linkedinSeats.length,
|
|
4157
|
+
low: count("low"),
|
|
4158
|
+
medium: count("medium"),
|
|
4159
|
+
senders: senders2.length,
|
|
4160
|
+
unknown: count("unknown")
|
|
4161
|
+
}
|
|
4162
|
+
};
|
|
4163
|
+
return answer;
|
|
4164
|
+
}
|
|
4165
|
+
});
|
|
4166
|
+
|
|
4167
|
+
// src/insights/senders/sender-capacity.ts
|
|
4168
|
+
import { z as z27 } from "zod";
|
|
4169
|
+
var input23 = z27.object({
|
|
4170
|
+
days: z27.number().int().min(1).max(90).default(7).describe("How many full days before today to average the sends over"),
|
|
4171
|
+
max_campaigns: z27.number().int().min(1).max(200).default(25).describe(
|
|
4172
|
+
"The most active campaigns to read. Each costs up to 2 requests, or 3 when the vendor has no workspace totals."
|
|
4173
|
+
),
|
|
4174
|
+
max_senders: z27.number().int().min(1).max(1e3).default(200).describe(
|
|
4175
|
+
"The most senders to read for the workspace, and for each campaign"
|
|
4176
|
+
)
|
|
4177
|
+
});
|
|
4178
|
+
var limitsOf = (senders2) => senders2.map((sender) => sender.dailyLimit);
|
|
4179
|
+
var capacityOf = (senders2) => {
|
|
4180
|
+
const active = senders2.filter((sender) => sender.status === "active");
|
|
4181
|
+
const withLimit = active.filter((sender) => sender.dailyLimit !== null);
|
|
4182
|
+
const ofKind = (kind) => total(limitsOf(active.filter((sender) => sender.kind === kind)));
|
|
4183
|
+
return {
|
|
4184
|
+
activeSenders: active.length,
|
|
4185
|
+
daily: total(limitsOf(active)),
|
|
4186
|
+
inactiveSenders: senders2.length - active.length,
|
|
4187
|
+
linkedinDaily: ofKind("linkedin"),
|
|
4188
|
+
mailboxDaily: ofKind("mailbox"),
|
|
4189
|
+
withLimit: withLimit.length,
|
|
4190
|
+
withoutLimit: active.length - withLimit.length
|
|
4191
|
+
};
|
|
4192
|
+
};
|
|
4193
|
+
var readOne = async (context, campaign, maxSenders) => {
|
|
4194
|
+
const { capabilities } = context.outbound;
|
|
4195
|
+
const settings = capabilities["campaigns.settings"] ? context.one(await context.outbound.campaign(campaign.ref).settings()) : null;
|
|
4196
|
+
return {
|
|
4197
|
+
campaign,
|
|
4198
|
+
dailyLimit: settings?.dailyLimit ?? null,
|
|
4199
|
+
// The senders are only compared with the campaign's own limit.
|
|
4200
|
+
senders: settings !== null && capabilities["senders.byCampaign"] ? await readCampaignSenders(context, campaign, maxSenders) : null
|
|
4201
|
+
};
|
|
4202
|
+
};
|
|
4203
|
+
var dailyRows = async (context, campaigns, range) => {
|
|
4204
|
+
const { outbound } = context;
|
|
4205
|
+
const { capabilities } = outbound;
|
|
4206
|
+
if (capabilities["stats.byDay"] === false) {
|
|
4207
|
+
context.note(
|
|
4208
|
+
"Average daily sends left out: the adapter has no daily stats."
|
|
4209
|
+
);
|
|
4210
|
+
return null;
|
|
4211
|
+
}
|
|
4212
|
+
if (capabilities["stats.workspace"] !== false) {
|
|
4213
|
+
return {
|
|
4214
|
+
rows: [...context.rows(await outbound.stats({ ...range, by: "day" }))],
|
|
4215
|
+
scope: "workspace"
|
|
4216
|
+
};
|
|
4217
|
+
}
|
|
4218
|
+
if (capabilities["stats.campaign"] === false) {
|
|
4219
|
+
context.note(
|
|
4220
|
+
"Average daily sends left out: the adapter has no workspace or campaign stats."
|
|
4221
|
+
);
|
|
4222
|
+
return null;
|
|
4223
|
+
}
|
|
4224
|
+
const perCampaign = await mapConcurrent(
|
|
4225
|
+
campaigns,
|
|
4226
|
+
async (campaign) => context.rows(
|
|
4227
|
+
await outbound.campaign(campaign.ref).stats({ ...range, by: "day" })
|
|
4228
|
+
)
|
|
4229
|
+
);
|
|
4230
|
+
const rows = perCampaign.flat();
|
|
4231
|
+
context.note(
|
|
4232
|
+
"Average daily sends cover the active campaigns read, not the whole workspace."
|
|
4233
|
+
);
|
|
4234
|
+
return { rows, scope: "campaigns" };
|
|
4235
|
+
};
|
|
4236
|
+
var readSends = async (context, campaigns, days) => {
|
|
4237
|
+
const range = {
|
|
4238
|
+
from: dayFrom(context.now, -days),
|
|
4239
|
+
to: dayFrom(context.now, -1)
|
|
4240
|
+
};
|
|
4241
|
+
const read = await dailyRows(context, campaigns, range);
|
|
4242
|
+
if (read === null) {
|
|
4243
|
+
return null;
|
|
4244
|
+
}
|
|
4245
|
+
const sent = total(read.rows.map((row) => row.sent));
|
|
4246
|
+
const reported = read.rows.flatMap(
|
|
4247
|
+
(row) => row.date === null || row.sent === null ? [] : [row.date]
|
|
4248
|
+
);
|
|
4249
|
+
return {
|
|
4250
|
+
...range,
|
|
4251
|
+
averageDaily: sent === null ? null : round(sent / days),
|
|
4252
|
+
days,
|
|
4253
|
+
daysWithData: new Set(reported).size,
|
|
4254
|
+
scope: read.scope,
|
|
4255
|
+
total: sent
|
|
4256
|
+
};
|
|
4257
|
+
};
|
|
4258
|
+
var shortfallOf = (read) => {
|
|
4259
|
+
const active = (read.senders ?? []).filter(
|
|
4260
|
+
(sender) => sender.status === "active"
|
|
4261
|
+
);
|
|
4262
|
+
if (read.dailyLimit === null || active.some((sender) => sender.dailyLimit === null)) {
|
|
4263
|
+
return "unchecked";
|
|
4264
|
+
}
|
|
4265
|
+
const senderCapacity2 = total(limitsOf(active)) ?? 0;
|
|
4266
|
+
if (senderCapacity2 >= read.dailyLimit) {
|
|
4267
|
+
return null;
|
|
4268
|
+
}
|
|
4269
|
+
return {
|
|
4270
|
+
activeSenders: active.length,
|
|
4271
|
+
campaign: read.campaign.ref,
|
|
4272
|
+
dailyLimit: read.dailyLimit,
|
|
4273
|
+
finding: `${read.campaign.name} asks for ${read.dailyLimit} a day but its ${active.length} active senders can send ${senderCapacity2}.`,
|
|
4274
|
+
name: read.campaign.name,
|
|
4275
|
+
senderCapacity: senderCapacity2,
|
|
4276
|
+
senders: read.senders?.length ?? 0,
|
|
4277
|
+
shortBy: read.dailyLimit - senderCapacity2
|
|
4278
|
+
};
|
|
4279
|
+
};
|
|
4280
|
+
var askOf = (reads) => {
|
|
4281
|
+
const limits = reads.map((read) => read.dailyLimit);
|
|
4282
|
+
const withLimit = limits.filter((limit2) => limit2 !== null).length;
|
|
4283
|
+
return {
|
|
4284
|
+
campaigns: reads.length,
|
|
4285
|
+
daily: total(limits),
|
|
4286
|
+
withLimit,
|
|
4287
|
+
withoutLimit: reads.length - withLimit
|
|
4288
|
+
};
|
|
4289
|
+
};
|
|
4290
|
+
var findingOf = (capacity, ask, sends) => {
|
|
4291
|
+
if (capacity.daily === null) {
|
|
4292
|
+
return "No active sender reports a daily limit, so capacity is unknown.";
|
|
4293
|
+
}
|
|
4294
|
+
const senders2 = `active ${capacity.withLimit === 1 ? "sender" : "senders"}`;
|
|
4295
|
+
const parts = [
|
|
4296
|
+
capacity.withoutLimit === 0 ? `${capacity.withLimit} ${senders2} can send ${capacity.daily} a day.` : `The ${capacity.withLimit} ${senders2} that ${capacity.withLimit === 1 ? "reports" : "report"} a daily limit can send ${capacity.daily} a day; ${capacity.withoutLimit} more ${capacity.withoutLimit === 1 ? "reports" : "report"} no limit and ${capacity.withoutLimit === 1 ? "is" : "are"} not counted.`
|
|
4297
|
+
];
|
|
4298
|
+
if (ask !== null && ask.daily !== null) {
|
|
4299
|
+
parts.push(
|
|
4300
|
+
ask.daily > capacity.daily ? `Active campaigns ask for ${ask.daily}, which is ${ask.daily - capacity.daily} more than that.` : `Active campaigns ask for ${ask.daily}, which fits.`
|
|
4301
|
+
);
|
|
4302
|
+
}
|
|
4303
|
+
if (sends !== null && sends.averageDaily !== null) {
|
|
4304
|
+
parts.push(
|
|
4305
|
+
`${sends.averageDaily} a day were sent on average over the last ${sends.days} days.`
|
|
4306
|
+
);
|
|
4307
|
+
}
|
|
4308
|
+
return parts.join(" ");
|
|
4309
|
+
};
|
|
4310
|
+
var senderCapacity = defineInsight({
|
|
4311
|
+
description: "Whether the senders can send what the campaigns ask: total daily capacity (the daily limits of active senders added up), the total daily ask of active campaigns, the average messages sent per day over the last days, utilization, and the campaigns whose own senders cannot cover their daily limit. Use it before adding campaigns or when sends fall short. Costs one listing of senders and of active campaigns, then up to 2 requests per campaign and 1 for daily stats. A null means the vendor does not report the number; a sender or campaign with no reported limit is counted apart, never as 0.",
|
|
4312
|
+
inputSchema: input23,
|
|
4313
|
+
key: "senderCapacity",
|
|
4314
|
+
name: "sender_capacity",
|
|
4315
|
+
needs: ["senders.list"],
|
|
4316
|
+
next: "Use sender_load to see which senders are shared by too many campaigns, or warmup_readiness before raising a sender's limit.",
|
|
4317
|
+
run: async (context, { days, max_campaigns: maxCampaigns, max_senders: maxSenders }) => {
|
|
4318
|
+
const { outbound } = context;
|
|
4319
|
+
const { capabilities } = outbound;
|
|
4320
|
+
const senders2 = await readCapped3(
|
|
4321
|
+
context,
|
|
4322
|
+
(cap) => outbound.senders.listAll({ max: cap }),
|
|
4323
|
+
maxSenders,
|
|
4324
|
+
"senders"
|
|
4325
|
+
);
|
|
4326
|
+
const campaigns = await readCampaigns2(context, ["active"], maxCampaigns);
|
|
4327
|
+
const reads = await mapConcurrent(
|
|
4328
|
+
campaigns,
|
|
4329
|
+
(campaign) => readOne(context, campaign, maxSenders)
|
|
4330
|
+
);
|
|
4331
|
+
const hasSettings = capabilities["campaigns.settings"];
|
|
4332
|
+
const canCompare = hasSettings && capabilities["senders.byCampaign"];
|
|
4333
|
+
if (!hasSettings) {
|
|
4334
|
+
context.note(
|
|
4335
|
+
"The daily ask and the campaigns short of senders were left out: the adapter cannot read campaign settings."
|
|
4336
|
+
);
|
|
4337
|
+
} else if (!canCompare) {
|
|
4338
|
+
context.note(
|
|
4339
|
+
"The campaigns short of senders were left out: the adapter cannot list a campaign's senders."
|
|
4340
|
+
);
|
|
4341
|
+
}
|
|
4342
|
+
const capacity = capacityOf(senders2);
|
|
4343
|
+
const ask = hasSettings ? askOf(reads) : null;
|
|
4344
|
+
const sends = await readSends(context, campaigns, days);
|
|
4345
|
+
const shortfalls = reads.map(shortfallOf);
|
|
4346
|
+
const answer = {
|
|
4347
|
+
ask,
|
|
4348
|
+
askRatio: rate(ask?.daily ?? null, capacity.daily),
|
|
4349
|
+
capacity,
|
|
4350
|
+
finding: findingOf(capacity, ask, sends),
|
|
4351
|
+
sends,
|
|
4352
|
+
shortCampaigns: canCompare ? shortfalls.flatMap(
|
|
4353
|
+
(each) => each === null || each === "unchecked" ? [] : [each]
|
|
4354
|
+
).toSorted((left, right) => right.shortBy - left.shortBy) : null,
|
|
4355
|
+
uncheckedCampaigns: canCompare ? shortfalls.filter((each) => each === "unchecked").length : null,
|
|
4356
|
+
utilization: rate(sends?.averageDaily ?? null, capacity.daily)
|
|
4357
|
+
};
|
|
4358
|
+
return answer;
|
|
4359
|
+
}
|
|
4360
|
+
});
|
|
4361
|
+
|
|
4362
|
+
// src/insights/senders/sender-load.ts
|
|
4363
|
+
import { z as z28 } from "zod";
|
|
4364
|
+
var input24 = z28.object({
|
|
4365
|
+
max_campaigns: z28.number().int().min(1).max(200).default(25).describe("The most campaigns to read. Each costs 1 request."),
|
|
4366
|
+
max_campaigns_per_sender: z28.number().int().min(1).default(3).describe("A sender attached to more campaigns than this is overused"),
|
|
4367
|
+
max_senders: z28.number().int().min(1).max(1e3).default(200).describe(
|
|
4368
|
+
"The most senders to read for the workspace, and for each campaign"
|
|
4369
|
+
),
|
|
4370
|
+
statuses: statusesInput
|
|
4371
|
+
});
|
|
4372
|
+
var loaded = (sender) => ({
|
|
4373
|
+
address: sender.address,
|
|
4374
|
+
dailyLimit: sender.dailyLimit,
|
|
4375
|
+
name: sender.name,
|
|
4376
|
+
sender: sender.ref,
|
|
4377
|
+
status: sender.status
|
|
4378
|
+
});
|
|
4379
|
+
var riskOf = (campaign, senders2) => {
|
|
4380
|
+
const inactive = senders2.filter((sender) => sender.status !== "active");
|
|
4381
|
+
const issues = [
|
|
4382
|
+
...senders2.length === 0 ? ["no_sender"] : [],
|
|
4383
|
+
...senders2.length === 1 ? ["single_sender"] : [],
|
|
4384
|
+
...inactive.length > 0 ? ["inactive_sender"] : []
|
|
4385
|
+
];
|
|
4386
|
+
if (issues.length === 0) {
|
|
4387
|
+
return null;
|
|
4388
|
+
}
|
|
4389
|
+
const count = senders2.length === 1 ? "1 sender" : `${senders2.length} senders`;
|
|
4390
|
+
return {
|
|
4391
|
+
campaign: campaign.ref,
|
|
4392
|
+
finding: inactive.length > 0 ? `${campaign.name} has ${count}, ${inactive.length} of them not active.` : `${campaign.name} has ${count}.`,
|
|
4393
|
+
inactive: inactive.map(loaded),
|
|
4394
|
+
issues,
|
|
4395
|
+
name: campaign.name,
|
|
4396
|
+
senders: senders2.length
|
|
4397
|
+
};
|
|
4398
|
+
};
|
|
4399
|
+
var senderLoad = defineInsight({
|
|
4400
|
+
description: "Senders that are overused or unused: the senders attached to more campaigns than allowed, the active senders attached to no campaign, and the campaigns that run on a single sender, on none, or on a sender that is not active. Use it when sends are uneven or before adding a campaign. Costs one listing of senders and of campaigns, then 1 request per campaign. Only campaigns in the given statuses are counted, so a sender used only by a paused campaign shows as unused unless paused is included.",
|
|
4401
|
+
inputSchema: input24,
|
|
4402
|
+
key: "senderLoad",
|
|
4403
|
+
name: "sender_load",
|
|
4404
|
+
needs: ["senders.list", "senders.byCampaign"],
|
|
4405
|
+
next: "Use sender_capacity to see whether the senders can cover the campaigns' daily limits, or warmup_readiness for the senders that are not active.",
|
|
4406
|
+
run: async (context, options) => {
|
|
4407
|
+
const { outbound } = context;
|
|
4408
|
+
const allowed = options.max_campaigns_per_sender;
|
|
4409
|
+
const senders2 = await readCapped3(
|
|
4410
|
+
context,
|
|
4411
|
+
(cap) => outbound.senders.listAll({ max: cap }),
|
|
4412
|
+
options.max_senders,
|
|
4413
|
+
"senders"
|
|
4414
|
+
);
|
|
4415
|
+
const campaigns = await readCampaigns2(
|
|
4416
|
+
context,
|
|
4417
|
+
options.statuses,
|
|
4418
|
+
options.max_campaigns
|
|
4419
|
+
);
|
|
4420
|
+
const known2 = new Map(senders2.map((sender) => [sender.ref, sender]));
|
|
4421
|
+
const attached = /* @__PURE__ */ new Map();
|
|
4422
|
+
const risks = [];
|
|
4423
|
+
const read = await mapConcurrent(campaigns, async (campaign) => ({
|
|
4424
|
+
campaign,
|
|
4425
|
+
own: await readCampaignSenders(context, campaign, options.max_senders)
|
|
4426
|
+
}));
|
|
4427
|
+
for (const { campaign, own } of read) {
|
|
4428
|
+
const risk = riskOf(campaign, own);
|
|
4429
|
+
if (risk !== null) {
|
|
4430
|
+
risks.push(risk);
|
|
4431
|
+
}
|
|
4432
|
+
for (const sender of own) {
|
|
4433
|
+
known2.set(sender.ref, sender);
|
|
4434
|
+
attached.set(sender.ref, [
|
|
4435
|
+
...attached.get(sender.ref) ?? [],
|
|
4436
|
+
campaign.ref
|
|
4437
|
+
]);
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
const overused = [...attached].flatMap(([ref, refs]) => {
|
|
4441
|
+
const sender = known2.get(ref);
|
|
4442
|
+
return sender === void 0 || refs.length <= allowed ? [] : [
|
|
4443
|
+
{
|
|
4444
|
+
...loaded(sender),
|
|
4445
|
+
campaignRefs: refs,
|
|
4446
|
+
campaigns: refs.length,
|
|
4447
|
+
finding: `${sender.address ?? sender.name ?? ref} is attached to ${refs.length} campaigns, ${refs.length - allowed} over the limit of ${allowed}.`,
|
|
4448
|
+
over: refs.length - allowed
|
|
4449
|
+
}
|
|
4450
|
+
];
|
|
4451
|
+
}).toSorted((left, right) => right.campaigns - left.campaigns);
|
|
4452
|
+
const active = senders2.filter((sender) => sender.status === "active");
|
|
4453
|
+
const unused = active.filter((sender) => !attached.has(sender.ref));
|
|
4454
|
+
const answer = {
|
|
4455
|
+
campaigns: risks.toSorted(
|
|
4456
|
+
(left, right) => right.issues.length - left.issues.length
|
|
4457
|
+
),
|
|
4458
|
+
maxCampaignsPerSender: allowed,
|
|
4459
|
+
overused,
|
|
4460
|
+
totals: {
|
|
4461
|
+
activeSenders: active.length,
|
|
4462
|
+
campaigns: campaigns.length,
|
|
4463
|
+
campaignsAtRisk: risks.length,
|
|
4464
|
+
overused: overused.length,
|
|
4465
|
+
senders: senders2.length,
|
|
4466
|
+
unused: unused.length
|
|
4467
|
+
},
|
|
4468
|
+
unused: unused.map(loaded)
|
|
4469
|
+
};
|
|
4470
|
+
return answer;
|
|
4471
|
+
}
|
|
4472
|
+
});
|
|
4473
|
+
|
|
4474
|
+
// src/insights/senders/settings-audit.ts
|
|
4475
|
+
import { z as z29 } from "zod";
|
|
4476
|
+
var input25 = z29.object({
|
|
4477
|
+
max_campaigns: z29.number().int().min(1).max(200).default(25).describe(
|
|
4478
|
+
"The most campaigns to audit. Each costs 1 request, or 2 when its senders can be listed."
|
|
4479
|
+
),
|
|
4480
|
+
max_daily_limit_per_sender: z29.number().min(1).default(50).describe(
|
|
4481
|
+
"A campaign's daily limit should not exceed this many sends per attached sender"
|
|
4482
|
+
),
|
|
4483
|
+
max_senders_per_campaign: z29.number().int().min(1).max(1e3).default(100).describe("The most senders to count for one campaign"),
|
|
4484
|
+
max_window_hours: z29.number().min(1).max(24).default(12).describe("A sending window longer than this many hours is flagged"),
|
|
4485
|
+
min_gap_minutes: z29.number().min(0).default(5).describe("A wait between two sends shorter than this is flagged"),
|
|
4486
|
+
min_window_hours: z29.number().min(0).max(24).default(2).describe("A sending window shorter than this many hours is flagged"),
|
|
4487
|
+
statuses: statusesInput
|
|
4488
|
+
});
|
|
4489
|
+
var SEVERITY2 = {
|
|
4490
|
+
click_tracking: "medium",
|
|
4491
|
+
end_date_passed: "high",
|
|
4492
|
+
gap_short: "medium",
|
|
4493
|
+
limit_over_senders: "high",
|
|
4494
|
+
no_daily_limit: "medium",
|
|
4495
|
+
no_timezone: "low",
|
|
4496
|
+
no_window: "medium",
|
|
4497
|
+
open_tracking: "medium",
|
|
4498
|
+
reply_does_not_stop: "high",
|
|
4499
|
+
weekend: "low",
|
|
4500
|
+
window_long: "medium",
|
|
4501
|
+
window_short: "low"
|
|
4502
|
+
};
|
|
4503
|
+
var ORDER2 = ["high", "medium", "low"];
|
|
4504
|
+
var when = (hit, check, finding, value = null) => hit ? [{ check, finding, severity: SEVERITY2[check], value }] : [];
|
|
4505
|
+
var minutesOf2 = (clock) => Number(clock.slice(0, 2)) * 60 + Number(clock.slice(3));
|
|
4506
|
+
var hoursOf = (window) => {
|
|
4507
|
+
if (window.from === null || window.to === null) {
|
|
4508
|
+
return null;
|
|
4509
|
+
}
|
|
4510
|
+
const minutes = minutesOf2(window.to) - minutesOf2(window.from);
|
|
4511
|
+
return Math.round((minutes > 0 ? minutes : minutes + 1440) / 60 * 100) / 100;
|
|
4512
|
+
};
|
|
4513
|
+
var scheduleFindings = ({ bars, settings }) => {
|
|
4514
|
+
const { schedule: schedule2 } = settings;
|
|
4515
|
+
if (schedule2.length === 0) {
|
|
4516
|
+
return when(
|
|
4517
|
+
true,
|
|
4518
|
+
"no_window",
|
|
4519
|
+
"No sending window is set or reported, so it can send at any hour."
|
|
4520
|
+
);
|
|
4521
|
+
}
|
|
4522
|
+
const hours = schedule2.flatMap((window) => hoursOf(window) ?? []);
|
|
4523
|
+
const longest = Math.max(...hours);
|
|
4524
|
+
const shortest = Math.min(...hours);
|
|
4525
|
+
const weekend = schedule2.find(
|
|
4526
|
+
(window) => window.days.includes(0) || window.days.includes(6)
|
|
4527
|
+
);
|
|
4528
|
+
return [
|
|
4529
|
+
...when(
|
|
4530
|
+
weekend !== void 0,
|
|
4531
|
+
"weekend",
|
|
4532
|
+
"A sending window includes Saturday or Sunday.",
|
|
4533
|
+
weekend?.days.join(",")
|
|
4534
|
+
),
|
|
4535
|
+
...when(
|
|
4536
|
+
longest > bars.maxWindowHours,
|
|
4537
|
+
"window_long",
|
|
4538
|
+
`A sending window is ${longest} hours long, over ${bars.maxWindowHours}.`,
|
|
4539
|
+
longest
|
|
4540
|
+
),
|
|
4541
|
+
...when(
|
|
4542
|
+
shortest < bars.minWindowHours,
|
|
4543
|
+
"window_short",
|
|
4544
|
+
`A sending window is ${shortest} hours long, under ${bars.minWindowHours}.`,
|
|
4545
|
+
shortest
|
|
4546
|
+
),
|
|
4547
|
+
...when(
|
|
4548
|
+
schedule2.some((window) => window.timezone === null),
|
|
4549
|
+
"no_timezone",
|
|
4550
|
+
"A sending window has no timezone."
|
|
4551
|
+
)
|
|
4552
|
+
];
|
|
4553
|
+
};
|
|
4554
|
+
var limitFindings = (audit2) => {
|
|
4555
|
+
const { bars, campaign, senders: senders2, settings, today } = audit2;
|
|
4556
|
+
const { dailyLimit, endDate, gapMinutes } = settings;
|
|
4557
|
+
const allowed = (senders2 ?? 0) * bars.maxPerSender;
|
|
4558
|
+
return [
|
|
4559
|
+
...when(
|
|
4560
|
+
dailyLimit === null,
|
|
4561
|
+
"no_daily_limit",
|
|
4562
|
+
"No daily limit is set or reported."
|
|
4563
|
+
),
|
|
4564
|
+
...when(
|
|
4565
|
+
dailyLimit !== null && allowed > 0 && dailyLimit > allowed,
|
|
4566
|
+
"limit_over_senders",
|
|
4567
|
+
`The daily limit of ${dailyLimit} is over ${bars.maxPerSender} a day for each of its ${senders2} senders (${allowed}).`,
|
|
4568
|
+
dailyLimit
|
|
4569
|
+
),
|
|
4570
|
+
...when(
|
|
4571
|
+
gapMinutes !== null && gapMinutes < bars.minGapMinutes,
|
|
4572
|
+
"gap_short",
|
|
4573
|
+
`Sends are ${gapMinutes} minutes apart, under ${bars.minGapMinutes}.`,
|
|
4574
|
+
gapMinutes
|
|
4575
|
+
),
|
|
4576
|
+
...when(
|
|
4577
|
+
campaign.status === "active" && endDate !== null && endDate < today,
|
|
4578
|
+
"end_date_passed",
|
|
4579
|
+
`The campaign is active but its end date ${endDate} has passed.`,
|
|
4580
|
+
endDate
|
|
4581
|
+
)
|
|
4582
|
+
];
|
|
4583
|
+
};
|
|
4584
|
+
var ruleFindings = ({ settings }) => [
|
|
4585
|
+
...when(
|
|
4586
|
+
settings.stopOnReply === false,
|
|
4587
|
+
"reply_does_not_stop",
|
|
4588
|
+
"A lead who replies keeps getting the next steps."
|
|
4589
|
+
),
|
|
4590
|
+
...when(
|
|
4591
|
+
settings.tracking.opens === true,
|
|
4592
|
+
"open_tracking",
|
|
4593
|
+
"Open tracking is on, a deliverability risk."
|
|
4594
|
+
),
|
|
4595
|
+
...when(
|
|
4596
|
+
settings.tracking.clicks === true,
|
|
4597
|
+
"click_tracking",
|
|
4598
|
+
"Click tracking is on; it rewrites links, a deliverability risk."
|
|
4599
|
+
)
|
|
4600
|
+
];
|
|
4601
|
+
var audit = (subject) => ({
|
|
4602
|
+
campaign: subject.campaign.ref,
|
|
4603
|
+
findings: [
|
|
4604
|
+
...scheduleFindings(subject),
|
|
4605
|
+
...limitFindings(subject),
|
|
4606
|
+
...ruleFindings(subject)
|
|
4607
|
+
].toSorted(
|
|
4608
|
+
(left, right) => ORDER2.indexOf(left.severity) - ORDER2.indexOf(right.severity)
|
|
4609
|
+
),
|
|
4610
|
+
name: subject.campaign.name,
|
|
4611
|
+
status: subject.campaign.status
|
|
4612
|
+
});
|
|
4613
|
+
var countOf2 = (campaign, severity) => campaign.findings.filter((finding) => finding.severity === severity).length;
|
|
4614
|
+
var worstFirst3 = (left, right) => countOf2(right, "high") - countOf2(left, "high") || countOf2(right, "medium") - countOf2(left, "medium") || right.findings.length - left.findings.length;
|
|
4615
|
+
var countChecks = (campaigns) => {
|
|
4616
|
+
const count = (check) => campaigns.filter(
|
|
4617
|
+
(campaign) => campaign.findings.some((finding) => finding.check === check)
|
|
4618
|
+
).length;
|
|
4619
|
+
return {
|
|
4620
|
+
click_tracking: count("click_tracking"),
|
|
4621
|
+
end_date_passed: count("end_date_passed"),
|
|
4622
|
+
gap_short: count("gap_short"),
|
|
4623
|
+
limit_over_senders: count("limit_over_senders"),
|
|
4624
|
+
no_daily_limit: count("no_daily_limit"),
|
|
4625
|
+
no_timezone: count("no_timezone"),
|
|
4626
|
+
no_window: count("no_window"),
|
|
4627
|
+
open_tracking: count("open_tracking"),
|
|
4628
|
+
reply_does_not_stop: count("reply_does_not_stop"),
|
|
4629
|
+
weekend: count("weekend"),
|
|
4630
|
+
window_long: count("window_long"),
|
|
4631
|
+
window_short: count("window_short")
|
|
4632
|
+
};
|
|
4633
|
+
};
|
|
4634
|
+
var settingsAudit = defineInsight({
|
|
4635
|
+
description: "Risky campaign settings, per campaign and by severity: no sending window, a window that includes the weekend or is too long or too short, no timezone, open or click tracking on, a reply that does not stop the sequence, no daily limit, sends too close together, an end date in the past on an active campaign, and a daily limit too high for the number of senders. Returns the findings per campaign, worst first, and a count per check. Use it before launching a campaign or when deliverability drops. Costs one listing of campaigns, then 1 request per campaign, or 2 when its senders can be listed. A setting the vendor reports nothing for is skipped, except a missing window, timezone or daily limit, which the vendor cannot tell apart from one that is not set.",
|
|
4636
|
+
inputSchema: input25,
|
|
4637
|
+
key: "settingsAudit",
|
|
4638
|
+
name: "settings_audit",
|
|
4639
|
+
needs: ["campaigns.settings"],
|
|
4640
|
+
next: "Use sender_capacity to size a daily limit against the senders, or bounce_watch to see whether a flagged campaign already bounces.",
|
|
4641
|
+
run: async (context, options) => {
|
|
4642
|
+
const { outbound } = context;
|
|
4643
|
+
const countSenders = outbound.capabilities["senders.byCampaign"];
|
|
4644
|
+
const bars = {
|
|
4645
|
+
maxPerSender: options.max_daily_limit_per_sender,
|
|
4646
|
+
maxWindowHours: options.max_window_hours,
|
|
4647
|
+
minGapMinutes: options.min_gap_minutes,
|
|
4648
|
+
minWindowHours: options.min_window_hours
|
|
4649
|
+
};
|
|
4650
|
+
const campaigns = await readCampaigns2(
|
|
4651
|
+
context,
|
|
4652
|
+
options.statuses,
|
|
4653
|
+
options.max_campaigns
|
|
4654
|
+
);
|
|
4655
|
+
if (!countSenders) {
|
|
4656
|
+
context.note(
|
|
4657
|
+
"The daily limit was not compared with the sender count: the adapter cannot list a campaign's senders."
|
|
4658
|
+
);
|
|
4659
|
+
}
|
|
4660
|
+
const audited = await mapConcurrent(
|
|
4661
|
+
campaigns,
|
|
4662
|
+
async (campaign) => {
|
|
4663
|
+
const [settings, senders2] = await Promise.all([
|
|
4664
|
+
outbound.campaign(campaign.ref).settings(),
|
|
4665
|
+
countSenders ? readCampaignSenders(
|
|
4666
|
+
context,
|
|
4667
|
+
campaign,
|
|
4668
|
+
options.max_senders_per_campaign
|
|
4669
|
+
) : null
|
|
4670
|
+
]);
|
|
4671
|
+
return audit({
|
|
4672
|
+
bars,
|
|
4673
|
+
campaign,
|
|
4674
|
+
senders: senders2?.length ?? null,
|
|
4675
|
+
settings: context.one(settings),
|
|
4676
|
+
today: dayFrom(context.now, 0)
|
|
4677
|
+
});
|
|
4678
|
+
}
|
|
4679
|
+
);
|
|
4680
|
+
const flagged = audited.filter((campaign) => campaign.findings.length > 0).toSorted(worstFirst3);
|
|
4681
|
+
const sum = (severity) => flagged.reduce((all, campaign) => all + countOf2(campaign, severity), 0);
|
|
4682
|
+
const answer = {
|
|
4683
|
+
byCheck: countChecks(flagged),
|
|
4684
|
+
campaigns: flagged,
|
|
4685
|
+
totals: {
|
|
4686
|
+
campaigns: audited.length,
|
|
4687
|
+
clean: audited.length - flagged.length,
|
|
4688
|
+
high: sum("high"),
|
|
4689
|
+
low: sum("low"),
|
|
4690
|
+
medium: sum("medium"),
|
|
4691
|
+
withFindings: flagged.length
|
|
4692
|
+
}
|
|
4693
|
+
};
|
|
4694
|
+
return answer;
|
|
4695
|
+
}
|
|
4696
|
+
});
|
|
4697
|
+
|
|
4698
|
+
// src/insights/senders/warmup-readiness.ts
|
|
4699
|
+
import { z as z30 } from "zod";
|
|
4700
|
+
var input26 = z30.object({
|
|
4701
|
+
check_health: z30.boolean().default(false).describe(
|
|
4702
|
+
"Also check each mailbox's DNS records and warmup spam. Costs 1 more request per mailbox."
|
|
4703
|
+
),
|
|
4704
|
+
max_senders: z30.number().int().min(1).max(1e3).default(100).describe("The most senders to check"),
|
|
4705
|
+
max_spam_rate: z30.number().min(0).max(1).default(0.1).describe(
|
|
4706
|
+
"With check_health, a mailbox whose warmup emails land in spam more often than this share is not ready"
|
|
4707
|
+
),
|
|
4708
|
+
min_score: z30.number().min(0).max(100).default(90).describe("The warmup score a mailbox needs to be ready")
|
|
4709
|
+
});
|
|
4710
|
+
var healthReasons = (health, bars) => {
|
|
4711
|
+
const failing = failingDns(health);
|
|
4712
|
+
const spam = warmupSpam(health);
|
|
4713
|
+
const spamRate = spam === null ? null : rate(spam.spam, spam.sent);
|
|
4714
|
+
return [
|
|
4715
|
+
...failing.length > 0 ? [
|
|
4716
|
+
[
|
|
4717
|
+
"dns_failing",
|
|
4718
|
+
`${failing.join(", ").toUpperCase()} failing`
|
|
4719
|
+
]
|
|
4720
|
+
] : [],
|
|
4721
|
+
...spam !== null && spamRate !== null && spamRate > bars.maxSpamRate ? [
|
|
4722
|
+
[
|
|
4723
|
+
"warmup_spam_high",
|
|
4724
|
+
`${spam.spam} of ${spam.sent} warmup emails landed in spam (${spamRate}, over ${bars.maxSpamRate})`
|
|
4725
|
+
]
|
|
4726
|
+
] : []
|
|
4727
|
+
];
|
|
4728
|
+
};
|
|
4729
|
+
var mailboxReasons = (sender, score, bars) => [
|
|
4730
|
+
...sender.warmup?.enabled === false ? [["warmup_off", "Warmup is off"]] : [],
|
|
4731
|
+
...score !== null && score < bars.minScore ? [
|
|
4732
|
+
[
|
|
4733
|
+
"score_low",
|
|
4734
|
+
`Warmup score ${score} is under ${bars.minScore}`
|
|
4735
|
+
]
|
|
4736
|
+
] : [],
|
|
4737
|
+
...score === null ? [["score_unknown", "The vendor reports no warmup score"]] : [],
|
|
4738
|
+
...sender.dailyLimit === null ? [["no_daily_limit", "No daily limit is set or reported"]] : []
|
|
4739
|
+
];
|
|
4740
|
+
var judge2 = (sender, health, bars) => {
|
|
4741
|
+
const score = sender.warmup?.score ?? health?.warmup?.score ?? null;
|
|
4742
|
+
const reasons = [
|
|
4743
|
+
...sender.status === "active" ? [] : [["not_active", `Status is ${sender.status}`]],
|
|
4744
|
+
...sender.kind === "mailbox" ? mailboxReasons(sender, score, bars) : [],
|
|
4745
|
+
...health === null ? [] : healthReasons(health, bars)
|
|
4746
|
+
];
|
|
4747
|
+
return {
|
|
4748
|
+
address: sender.address,
|
|
4749
|
+
dailyLimit: sender.dailyLimit,
|
|
4750
|
+
findings: reasons.map(([, finding]) => finding),
|
|
4751
|
+
kind: sender.kind,
|
|
4752
|
+
name: sender.name,
|
|
4753
|
+
reasons: reasons.map(([reason]) => reason),
|
|
4754
|
+
score,
|
|
4755
|
+
sender: sender.ref,
|
|
4756
|
+
status: sender.status,
|
|
4757
|
+
warmupEnabled: sender.warmup?.enabled ?? null
|
|
4758
|
+
};
|
|
4759
|
+
};
|
|
4760
|
+
var countReasons = (judged) => {
|
|
4761
|
+
const count = (reason) => judged.filter((sender) => sender.reasons.includes(reason)).length;
|
|
4762
|
+
return {
|
|
4763
|
+
dns_failing: count("dns_failing"),
|
|
4764
|
+
no_daily_limit: count("no_daily_limit"),
|
|
4765
|
+
not_active: count("not_active"),
|
|
4766
|
+
score_low: count("score_low"),
|
|
4767
|
+
score_unknown: count("score_unknown"),
|
|
4768
|
+
warmup_off: count("warmup_off"),
|
|
4769
|
+
warmup_spam_high: count("warmup_spam_high")
|
|
4770
|
+
};
|
|
4771
|
+
};
|
|
4772
|
+
var warmupReadiness = defineInsight({
|
|
4773
|
+
description: "Which senders are not ready to send, each with its reasons: warmup off, warmup score under the bar or not reported, status not active, no daily limit and, with check_health, failing DNS records or too many warmup emails in spam. Returns counts by reason and how many are ready. A LinkedIn seat is judged on its status only. Use it before attaching mailboxes to a campaign or raising their limits. Costs one listing of senders, plus 1 request per mailbox with check_health. A null score means the vendor does not report one, which counts as not ready, not as 0.",
|
|
4774
|
+
inputSchema: input26,
|
|
4775
|
+
key: "warmupReadiness",
|
|
4776
|
+
name: "warmup_readiness",
|
|
4777
|
+
needs: ["senders.list"],
|
|
4778
|
+
next: "Use domain_health for the domains of the mailboxes that are not ready, or sender_capacity to see what the ready ones can send.",
|
|
4779
|
+
run: async (context, options) => {
|
|
4780
|
+
const { outbound } = context;
|
|
4781
|
+
const bars = {
|
|
4782
|
+
maxSpamRate: options.max_spam_rate,
|
|
4783
|
+
minScore: options.min_score
|
|
4784
|
+
};
|
|
4785
|
+
const senders2 = await readCapped3(
|
|
4786
|
+
context,
|
|
4787
|
+
(cap) => outbound.senders.listAll({ max: cap }),
|
|
4788
|
+
options.max_senders,
|
|
4789
|
+
"senders"
|
|
4790
|
+
);
|
|
4791
|
+
const healthChecked = options.check_health && outbound.capabilities["senders.health"];
|
|
4792
|
+
if (options.check_health && !healthChecked) {
|
|
4793
|
+
context.note(
|
|
4794
|
+
"DNS records and warmup spam were not checked: the adapter cannot read a sender's health."
|
|
4795
|
+
);
|
|
4796
|
+
}
|
|
4797
|
+
const judged = await mapConcurrent(
|
|
4798
|
+
senders2,
|
|
4799
|
+
async (sender) => {
|
|
4800
|
+
const health = healthChecked && sender.kind === "mailbox" ? context.one(await outbound.sender(sender.ref).health()) : null;
|
|
4801
|
+
return judge2(sender, health, bars);
|
|
4802
|
+
}
|
|
4803
|
+
);
|
|
4804
|
+
const notReady = judged.filter((sender) => sender.reasons.length > 0).toSorted((left, right) => right.reasons.length - left.reasons.length);
|
|
4805
|
+
const answer = {
|
|
4806
|
+
byReason: countReasons(notReady),
|
|
4807
|
+
healthChecked,
|
|
4808
|
+
linkedinSeats: senders2.filter((sender) => sender.kind === "linkedin").length,
|
|
4809
|
+
notReady,
|
|
4810
|
+
ready: judged.length - notReady.length,
|
|
4811
|
+
total: judged.length
|
|
4812
|
+
};
|
|
4813
|
+
return answer;
|
|
4814
|
+
}
|
|
4815
|
+
});
|
|
4816
|
+
|
|
4817
|
+
// src/insights/senders/index.ts
|
|
4818
|
+
var SENDERS_INSIGHTS = [
|
|
4819
|
+
domainHealth,
|
|
4820
|
+
senderCapacity,
|
|
4821
|
+
bounceWatch,
|
|
4822
|
+
warmupReadiness,
|
|
4823
|
+
senderLoad,
|
|
4824
|
+
settingsAudit
|
|
4825
|
+
];
|
|
4826
|
+
|
|
4827
|
+
// src/insights/registry.ts
|
|
4828
|
+
var INSIGHTS = [
|
|
4829
|
+
...PEOPLE_INSIGHTS,
|
|
4830
|
+
...COPY_INSIGHTS,
|
|
4831
|
+
...SENDERS_INSIGHTS,
|
|
4832
|
+
...OPS_INSIGHTS
|
|
4833
|
+
];
|
|
4834
|
+
var ENTRIES = INSIGHTS;
|
|
4835
|
+
|
|
4836
|
+
// src/insights/plugin.ts
|
|
4837
|
+
var runInsightByName = async (outbound, name, input27 = {}, options = {}) => {
|
|
4838
|
+
const entry = ENTRIES.find(
|
|
4839
|
+
(candidate) => candidate.name === name || candidate.key === name
|
|
4840
|
+
);
|
|
4841
|
+
if (entry === void 0) {
|
|
4842
|
+
throw new OutboundError(
|
|
4843
|
+
"Invalid",
|
|
4844
|
+
`There is no insight "${name}". Known: ${ENTRIES.map((each) => each.name).join(", ")}`,
|
|
4845
|
+
{ provider: outbound.provider }
|
|
4846
|
+
);
|
|
4847
|
+
}
|
|
4848
|
+
return await entry.execute(outbound, input27, options);
|
|
4849
|
+
};
|
|
4850
|
+
var listInsights = () => ENTRIES.map((entry) => ({
|
|
4851
|
+
description: entry.description,
|
|
4852
|
+
key: entry.key,
|
|
4853
|
+
name: entry.name,
|
|
4854
|
+
needs: [...entry.needs],
|
|
4855
|
+
// SAFETY: a JSON Schema document is JSON by definition.
|
|
4856
|
+
parameters: z31.toJSONSchema(entry.inputSchema, { io: "input" })
|
|
4857
|
+
}));
|
|
4858
|
+
var insights = () => ({
|
|
4859
|
+
extend: (outbound) => {
|
|
4860
|
+
const methods = {};
|
|
4861
|
+
for (const entry of ENTRIES) {
|
|
4862
|
+
methods[entry.key] = (input27, options) => (
|
|
4863
|
+
// SAFETY: the answer is the entry's own, typed per key by Insights.
|
|
4864
|
+
entry.execute(outbound, input27, options)
|
|
4865
|
+
);
|
|
4866
|
+
}
|
|
4867
|
+
return { insights: methods };
|
|
4868
|
+
},
|
|
4869
|
+
name: "insights"
|
|
4870
|
+
});
|
|
4871
|
+
|
|
4872
|
+
// src/insights/tools.ts
|
|
4873
|
+
import { z as z32 } from "zod";
|
|
4874
|
+
var toTool = (outbound, definition) => ({
|
|
4875
|
+
call: async (input27) => {
|
|
4876
|
+
try {
|
|
4877
|
+
const result = await definition.execute(outbound, input27);
|
|
4878
|
+
return {
|
|
4879
|
+
data: {
|
|
4880
|
+
complete: result.meta.complete,
|
|
4881
|
+
notes: [...result.meta.notes],
|
|
4882
|
+
result: result.data
|
|
4883
|
+
},
|
|
4884
|
+
meta: {
|
|
4885
|
+
evidence: result.meta.evidence,
|
|
4886
|
+
provider: result.meta.provider,
|
|
4887
|
+
requests: result.meta.requests
|
|
4888
|
+
},
|
|
4889
|
+
next: definition.next,
|
|
4890
|
+
ok: true
|
|
4891
|
+
};
|
|
4892
|
+
} catch (error) {
|
|
4893
|
+
const known2 = OutboundError.is(error);
|
|
4894
|
+
return {
|
|
4895
|
+
error: {
|
|
4896
|
+
code: known2 ? error.code : "Provider",
|
|
4897
|
+
message: error instanceof Error ? error.message : String(error)
|
|
4898
|
+
},
|
|
4899
|
+
next: known2 && error.code === "Unsupported" ? "This insight is not available with the current adapter. Try another tool." : "Check the input and try again.",
|
|
4900
|
+
ok: false
|
|
4901
|
+
};
|
|
4902
|
+
}
|
|
4903
|
+
},
|
|
4904
|
+
description: definition.description,
|
|
4905
|
+
fields: definition.inputSchema.shape,
|
|
4906
|
+
name: definition.name,
|
|
4907
|
+
needs: [...definition.needs],
|
|
4908
|
+
// SAFETY: a JSON Schema document is JSON by definition.
|
|
4909
|
+
parameters: z32.toJSONSchema(definition.inputSchema, { io: "input" })
|
|
4910
|
+
});
|
|
4911
|
+
var insightTools = (outbound, options = {}) => {
|
|
4912
|
+
const wanted = options.only === void 0 ? void 0 : new Set(options.only);
|
|
4913
|
+
return ENTRIES.flatMap((definition) => {
|
|
4914
|
+
const offered = (wanted === void 0 || wanted.has(definition.name)) && definition.needs.every((key) => outbound.capabilities[key] !== false);
|
|
4915
|
+
return offered ? [toTool(outbound, definition)] : [];
|
|
4916
|
+
});
|
|
4917
|
+
};
|
|
4918
|
+
export {
|
|
4919
|
+
INSIGHTS,
|
|
4920
|
+
compareRates,
|
|
4921
|
+
defineInsight,
|
|
4922
|
+
deviation,
|
|
4923
|
+
insightTools,
|
|
4924
|
+
insights,
|
|
4925
|
+
listInsights,
|
|
4926
|
+
mean,
|
|
4927
|
+
median,
|
|
4928
|
+
percentile,
|
|
4929
|
+
rate,
|
|
4930
|
+
round,
|
|
4931
|
+
runInsight,
|
|
4932
|
+
runInsightByName,
|
|
4933
|
+
tally,
|
|
4934
|
+
total,
|
|
4935
|
+
wilson,
|
|
4936
|
+
zScore
|
|
4937
|
+
};
|