@nebutra/outreach-engine 0.1.2 → 0.1.4
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/CHANGELOG.md +28 -0
- package/LICENSE +21 -676
- package/dist/{chunk-IY3N4YTP.js → chunk-XD3Y5BKC.js} +2 -2
- package/dist/chunk-XD3Y5BKC.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +21 -11
- package/.nebutra/debug/content-store.jsonl +0 -3
- package/.nebutra/debug/event-log.jsonl +0 -1
- package/.nebutra/debug/outreach-engine.jsonl +0 -1
- package/.turbo/turbo-build.log +0 -22
- package/.turbo/turbo-test.log +0 -15
- package/.turbo/turbo-typecheck.log +0 -4
- package/dist/chunk-IY3N4YTP.js.map +0 -1
- package/examples/compliance.ts +0 -18
- package/examples/icp.ts +0 -9
- package/examples/quickstart.ts +0 -30
- package/plays/outreach_campaign/SKILL.md +0 -44
- package/src/cli.ts +0 -49
- package/src/index.test.ts +0 -120
- package/src/index.ts +0 -314
- package/tsconfig.json +0 -9
- package/tsup.config.ts +0 -11
package/src/index.ts
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { mkdir } from "node:fs/promises";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { requireCapabilityTenant } from "@nebutra/capability-kit";
|
|
4
|
-
import { appendCapabilityDebug, readCapabilityDebug } from "@nebutra/capability-kit/debug";
|
|
5
|
-
import { ContentStore } from "@nebutra/content-store";
|
|
6
|
-
import { CapabilityError } from "@nebutra/errors";
|
|
7
|
-
import { EventLog } from "@nebutra/event-log";
|
|
8
|
-
import { assetId } from "@nebutra/generation-context";
|
|
9
|
-
|
|
10
|
-
export interface IcpDefinition {
|
|
11
|
-
readonly industries: readonly string[];
|
|
12
|
-
readonly companySize: { readonly min: number; readonly max: number };
|
|
13
|
-
readonly titles: readonly string[];
|
|
14
|
-
readonly geo: readonly string[];
|
|
15
|
-
readonly techStack: readonly string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ComplianceProfile {
|
|
19
|
-
readonly physicalAddress: string;
|
|
20
|
-
readonly unsubscribeUrl: string;
|
|
21
|
-
readonly gdprBasis?: "legitimate_interest" | "consent" | "existing_customer";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface EmailVariant {
|
|
25
|
-
readonly step: number;
|
|
26
|
-
readonly subject: string;
|
|
27
|
-
readonly body: string;
|
|
28
|
-
readonly daysAfterPrevious: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ComplianceReport {
|
|
32
|
-
readonly ok: boolean;
|
|
33
|
-
readonly checks: {
|
|
34
|
-
readonly hasUnsubscribeLink: boolean;
|
|
35
|
-
readonly hasPhysicalAddress: boolean;
|
|
36
|
-
readonly hasClearSubject: boolean;
|
|
37
|
-
readonly gdprBasisDocumented: boolean;
|
|
38
|
-
};
|
|
39
|
-
readonly suggestion?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface CampaignInput {
|
|
43
|
-
readonly tenantId?: string;
|
|
44
|
-
readonly icpDescription: string;
|
|
45
|
-
readonly targetCount: number;
|
|
46
|
-
readonly product: string;
|
|
47
|
-
readonly sequenceLength: number;
|
|
48
|
-
readonly sendPerDay: number;
|
|
49
|
-
readonly senderEmails: readonly string[];
|
|
50
|
-
readonly complianceProfile: ComplianceProfile;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface Lead {
|
|
54
|
-
readonly id: string;
|
|
55
|
-
readonly company: string;
|
|
56
|
-
readonly title: string;
|
|
57
|
-
readonly source: "local-plan";
|
|
58
|
-
readonly confidence: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface CampaignPackage {
|
|
62
|
-
readonly tenantId: string;
|
|
63
|
-
readonly play: "outreach_campaign";
|
|
64
|
-
readonly id: string;
|
|
65
|
-
readonly status: "draft";
|
|
66
|
-
readonly icp: IcpDefinition;
|
|
67
|
-
readonly leads: readonly Lead[];
|
|
68
|
-
readonly sequence: readonly EmailVariant[];
|
|
69
|
-
readonly compliance: ComplianceReport;
|
|
70
|
-
readonly schedule: {
|
|
71
|
-
readonly dailyLimit: number;
|
|
72
|
-
readonly senderEmails: readonly string[];
|
|
73
|
-
readonly requiresApprovalBeforeSend: true;
|
|
74
|
-
};
|
|
75
|
-
readonly artifactPath: string;
|
|
76
|
-
readonly eventId: string;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface SequenceInput {
|
|
80
|
-
readonly product: string;
|
|
81
|
-
readonly sequenceLength: number;
|
|
82
|
-
readonly brandVoice?: readonly string[];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface OutreachDoctorReport {
|
|
86
|
-
readonly capability: "outreach-engine";
|
|
87
|
-
readonly ok: boolean;
|
|
88
|
-
readonly checkedAt: string;
|
|
89
|
-
readonly plays: readonly string[];
|
|
90
|
-
readonly sendMode: "draft-only";
|
|
91
|
-
readonly adapters: readonly { readonly provider: string; readonly ok: boolean }[];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface OutreachEngineOptions {
|
|
95
|
-
readonly tenantId?: string;
|
|
96
|
-
readonly root?: string;
|
|
97
|
-
readonly debugRoot?: string;
|
|
98
|
-
readonly contentStore?: ContentStore;
|
|
99
|
-
readonly eventLog?: EventLog;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function slug(value: string): string {
|
|
103
|
-
return value
|
|
104
|
-
.toLowerCase()
|
|
105
|
-
.replace(/[^a-z0-9]+/g, "_")
|
|
106
|
-
.replace(/^_+|_+$/g, "")
|
|
107
|
-
.slice(0, 48);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function defineIcp(description: string): IcpDefinition {
|
|
111
|
-
const text = description.toLowerCase();
|
|
112
|
-
const industries =
|
|
113
|
-
text.includes("e-commerce") || text.includes("d2c")
|
|
114
|
-
? ["e-commerce", "D2C"]
|
|
115
|
-
: text.includes("saas")
|
|
116
|
-
? ["SaaS"]
|
|
117
|
-
: ["startup"];
|
|
118
|
-
const titles = text.includes("cto")
|
|
119
|
-
? ["CTO", "VP Engineering", "Head of Engineering"]
|
|
120
|
-
: ["VP Marketing", "Head of Growth", "CMO"];
|
|
121
|
-
const companySize =
|
|
122
|
-
text.includes("mid-size") || text.includes("medium")
|
|
123
|
-
? { min: 50, max: 500 }
|
|
124
|
-
: { min: 1, max: 50 };
|
|
125
|
-
const geo = text.includes("eu") ? ["EU"] : text.includes("us") ? ["US"] : ["US", "EU"];
|
|
126
|
-
const techStack = text.includes("shopify") ? ["Shopify"] : [];
|
|
127
|
-
return { industries, companySize, titles, geo, techStack };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function buildEmailSequence(input: SequenceInput): readonly EmailVariant[] {
|
|
131
|
-
const length = Math.max(1, Math.min(5, input.sequenceLength));
|
|
132
|
-
const voice = input.brandVoice?.join(", ") ?? "clear, useful";
|
|
133
|
-
return Array.from({ length }, (_, index) => {
|
|
134
|
-
const step = index + 1;
|
|
135
|
-
return {
|
|
136
|
-
step,
|
|
137
|
-
subject: step === 1 ? "Quick question" : `Following up ${step}`,
|
|
138
|
-
body: [
|
|
139
|
-
`Hi {{first_name}},`,
|
|
140
|
-
"",
|
|
141
|
-
step === 1
|
|
142
|
-
? `I noticed {{company}} may care about ${input.product}.`
|
|
143
|
-
: `Sharing one more angle on ${input.product}.`,
|
|
144
|
-
`Tone: ${voice}.`,
|
|
145
|
-
"",
|
|
146
|
-
"If this is not useful, unsubscribe here: {{unsubscribe_url}}.",
|
|
147
|
-
"{{physical_address}}",
|
|
148
|
-
].join("\n"),
|
|
149
|
-
daysAfterPrevious: step === 1 ? 0 : step + 1,
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function checkEmailCompliance(
|
|
155
|
-
email: EmailVariant | undefined,
|
|
156
|
-
profile: ComplianceProfile,
|
|
157
|
-
): ComplianceReport {
|
|
158
|
-
const body = email?.body ?? "";
|
|
159
|
-
const checks = {
|
|
160
|
-
hasUnsubscribeLink: body.includes("unsubscribe") && profile.unsubscribeUrl.startsWith("http"),
|
|
161
|
-
hasPhysicalAddress: profile.physicalAddress.trim().length > 4,
|
|
162
|
-
hasClearSubject: Boolean(email?.subject.trim()),
|
|
163
|
-
gdprBasisDocumented: Boolean(profile.gdprBasis),
|
|
164
|
-
};
|
|
165
|
-
const ok = Object.values(checks).every(Boolean);
|
|
166
|
-
return {
|
|
167
|
-
ok,
|
|
168
|
-
checks,
|
|
169
|
-
...(!ok
|
|
170
|
-
? {
|
|
171
|
-
suggestion:
|
|
172
|
-
"Add unsubscribe URL, physical address, clear subject, and GDPR basis before any send adapter can run.",
|
|
173
|
-
}
|
|
174
|
-
: {}),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function plannedLeads(icp: IcpDefinition, count: number): readonly Lead[] {
|
|
179
|
-
const size = Math.max(1, Math.min(250, count));
|
|
180
|
-
return Array.from({ length: size }, (_, index) => ({
|
|
181
|
-
id: `lead_${String(index + 1).padStart(3, "0")}`,
|
|
182
|
-
company: `${icp.industries[0] ?? "startup"} account ${index + 1}`,
|
|
183
|
-
title: icp.titles[index % icp.titles.length] ?? "Founder",
|
|
184
|
-
source: "local-plan",
|
|
185
|
-
confidence: 0.72,
|
|
186
|
-
}));
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export class OutreachEngine {
|
|
190
|
-
readonly #tenantId: string | undefined;
|
|
191
|
-
readonly #debugRoot: string;
|
|
192
|
-
readonly #contentStore: ContentStore;
|
|
193
|
-
readonly #eventLog: EventLog;
|
|
194
|
-
|
|
195
|
-
private constructor(
|
|
196
|
-
options: OutreachEngineOptions & { contentStore: ContentStore; eventLog: EventLog },
|
|
197
|
-
) {
|
|
198
|
-
this.#tenantId = options.tenantId;
|
|
199
|
-
this.#debugRoot = options.debugRoot ?? process.cwd();
|
|
200
|
-
this.#contentStore = options.contentStore;
|
|
201
|
-
this.#eventLog = options.eventLog;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
static async open(
|
|
205
|
-
root = ".nebutra/outreach-engine",
|
|
206
|
-
options: Omit<OutreachEngineOptions, "root" | "contentStore" | "eventLog"> = {},
|
|
207
|
-
): Promise<OutreachEngine> {
|
|
208
|
-
const tenantId = options.tenantId ?? "local";
|
|
209
|
-
await mkdir(root, { recursive: true });
|
|
210
|
-
const contentStore = await ContentStore.open(join(root, "content"), { tenantId });
|
|
211
|
-
const eventLog = await EventLog.open(join(root, "event-log"), { tenantId });
|
|
212
|
-
return new OutreachEngine({ ...options, tenantId, root, contentStore, eventLog });
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async createCampaign(input: CampaignInput): Promise<CampaignPackage> {
|
|
216
|
-
const tenantId = requireCapabilityTenant({
|
|
217
|
-
explicit: input.tenantId,
|
|
218
|
-
fallback: this.#tenantId,
|
|
219
|
-
onMissing: () =>
|
|
220
|
-
new CapabilityError("outreach-engine", "Outreach Engine requires tenant context", {
|
|
221
|
-
suggestion: "Pass tenantId before creating or persisting a campaign.",
|
|
222
|
-
statusCode: 400,
|
|
223
|
-
}),
|
|
224
|
-
});
|
|
225
|
-
const icp = defineIcp(input.icpDescription);
|
|
226
|
-
const sequence = buildEmailSequence({
|
|
227
|
-
product: input.product,
|
|
228
|
-
sequenceLength: input.sequenceLength,
|
|
229
|
-
brandVoice: ["specific", "useful", "respectful"],
|
|
230
|
-
});
|
|
231
|
-
const compliance = checkEmailCompliance(sequence[0], input.complianceProfile);
|
|
232
|
-
if (!compliance.ok) {
|
|
233
|
-
throw new CapabilityError("outreach-engine", "Campaign failed compliance checks", {
|
|
234
|
-
suggestion:
|
|
235
|
-
compliance.suggestion ??
|
|
236
|
-
"Add unsubscribe URL, physical address, clear subject, and GDPR basis.",
|
|
237
|
-
statusCode: 400,
|
|
238
|
-
metadata: compliance.checks,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
const id = assetId("outreach_campaign", slug(input.icpDescription));
|
|
242
|
-
const leads = plannedLeads(icp, input.targetCount);
|
|
243
|
-
const artifactPath = `outreach/${id}.json`;
|
|
244
|
-
const draft = {
|
|
245
|
-
id,
|
|
246
|
-
status: "draft",
|
|
247
|
-
icp,
|
|
248
|
-
leads,
|
|
249
|
-
sequence,
|
|
250
|
-
schedule: {
|
|
251
|
-
dailyLimit: Math.max(1, Math.min(30, input.sendPerDay)),
|
|
252
|
-
senderEmails: input.senderEmails,
|
|
253
|
-
requiresApprovalBeforeSend: true,
|
|
254
|
-
} as const,
|
|
255
|
-
};
|
|
256
|
-
const content = `${JSON.stringify(draft, null, 2)}\n`;
|
|
257
|
-
await this.#contentStore.write(artifactPath, content);
|
|
258
|
-
const eventId = await this.#eventLog.commit({
|
|
259
|
-
traceId: id,
|
|
260
|
-
kind: "content_write",
|
|
261
|
-
affected: [artifactPath],
|
|
262
|
-
parent: null,
|
|
263
|
-
snapshot: { [artifactPath]: content },
|
|
264
|
-
});
|
|
265
|
-
const campaign: CampaignPackage = {
|
|
266
|
-
tenantId,
|
|
267
|
-
play: "outreach_campaign",
|
|
268
|
-
id,
|
|
269
|
-
status: "draft",
|
|
270
|
-
icp,
|
|
271
|
-
leads,
|
|
272
|
-
sequence,
|
|
273
|
-
compliance,
|
|
274
|
-
schedule: draft.schedule,
|
|
275
|
-
artifactPath,
|
|
276
|
-
eventId,
|
|
277
|
-
};
|
|
278
|
-
await this.#debug({ type: "campaign_draft", tenantId, campaignId: id, eventId });
|
|
279
|
-
return campaign;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
async doctor(): Promise<OutreachDoctorReport> {
|
|
283
|
-
return {
|
|
284
|
-
capability: "outreach-engine",
|
|
285
|
-
ok: true,
|
|
286
|
-
checkedAt: new Date().toISOString(),
|
|
287
|
-
plays: ["outreach_campaign"],
|
|
288
|
-
sendMode: "draft-only",
|
|
289
|
-
adapters: [
|
|
290
|
-
{ provider: "local-plan", ok: true },
|
|
291
|
-
{ provider: "integration-vault-email", ok: false },
|
|
292
|
-
{ provider: "crm-sync", ok: false },
|
|
293
|
-
],
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async close(): Promise<void> {
|
|
298
|
-
await this.#contentStore.close();
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
async #debug(entry: Record<string, unknown>): Promise<void> {
|
|
302
|
-
await mkdir(dirname(join(this.#debugRoot, ".nebutra", "debug", "outreach-engine.jsonl")), {
|
|
303
|
-
recursive: true,
|
|
304
|
-
});
|
|
305
|
-
await appendCapabilityDebug("outreach-engine", entry, { root: this.#debugRoot });
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export async function readOutreachEngineDebug(
|
|
310
|
-
root = process.cwd(),
|
|
311
|
-
limit = 20,
|
|
312
|
-
): Promise<unknown[]> {
|
|
313
|
-
return readCapabilityDebug("outreach-engine", { root, limit });
|
|
314
|
-
}
|
package/tsconfig.json
DELETED
package/tsup.config.ts
DELETED