@beeperbot/sdk 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @beeper/sdk
1
+ # @beeperbot/sdk
2
2
 
3
3
  TypeScript SDK for [beep.works](https://beep.works) — the attention layer on Base.
4
4
 
@@ -7,7 +7,7 @@ Send paid messages (beeps) to Farcaster users. Look up users, check prices, run
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- npm install @beeper/sdk
10
+ npm install @beeperbot/sdk
11
11
  ```
12
12
 
13
13
  ## Quick Start — AI Agent
@@ -15,7 +15,7 @@ npm install @beeper/sdk
15
15
  The `AgentClient` is the simplest way to integrate beeps into your AI agent or bot.
16
16
 
17
17
  ```typescript
18
- import { AgentClient } from '@beeper/sdk';
18
+ import { AgentClient } from '@beeperbot/sdk';
19
19
 
20
20
  const agent = new AgentClient({
21
21
  apiKey: process.env.BEEPER_API_KEY!, // bpk_live_...
@@ -247,7 +247,7 @@ Use filters with `estimate`, `preview`, and `createBulkIntent`.
247
247
  For the full deposit → execute → receipt flow:
248
248
 
249
249
  ```typescript
250
- import { BeeperClient } from '@beeper/sdk';
250
+ import { BeeperClient } from '@beeperbot/sdk';
251
251
 
252
252
  const client = new BeeperClient({
253
253
  apiKey: process.env.BEEPER_API_KEY!,
@@ -282,7 +282,7 @@ const receipt = await client.pollUntilCompleteByQuoteId(quote.id);
282
282
  ## Error Handling
283
283
 
284
284
  ```typescript
285
- import { BeeperError, ErrorCodes } from '@beeper/sdk';
285
+ import { BeeperError, ErrorCodes } from '@beeperbot/sdk';
286
286
 
287
287
  try {
288
288
  await agent.lookup('nonexistent');
@@ -0,0 +1,542 @@
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+
5
+ // src/core/agent/engine.ts
6
+
7
+ // src/core/agent/errors.ts
8
+ var AgentCoreError = class _AgentCoreError extends Error {
9
+ code;
10
+ constructor(code, message) {
11
+ super(message);
12
+ this.name = "AgentCoreError";
13
+ this.code = code;
14
+ }
15
+ static validation(message) {
16
+ return new _AgentCoreError("VALIDATION_ERROR", message);
17
+ }
18
+ static notFound(message) {
19
+ return new _AgentCoreError("NOT_FOUND", message);
20
+ }
21
+ static unsupportedChain(chainId) {
22
+ return new _AgentCoreError("UNSUPPORTED_CHAIN", `Unsupported chain: ${chainId}`);
23
+ }
24
+ static noRecipients(message) {
25
+ return new _AgentCoreError("NO_RECIPIENTS", message);
26
+ }
27
+ };
28
+
29
+ // src/core/agent/filters.ts
30
+ var CHAIN_ID_MAP = {
31
+ base: 8453,
32
+ ethereum: 1,
33
+ mainnet: 1,
34
+ arbitrum: 42161,
35
+ polygon: 137,
36
+ optimism: 10
37
+ };
38
+ function hasSubstantiveFilters(filters) {
39
+ return !!(filters.platform || filters.minFollowers || filters.maxFollowers || filters.fids?.length || filters.userIds?.length || filters.activeInLastDays || filters.countries?.length || filters.neynarScoreMin || filters.tokenHolders?.length || filters.maxAttentionPriceUsd || filters.hasBaseWallet || filters.spamLabel);
40
+ }
41
+ function normalizeAgentFilters(filters) {
42
+ const normalized = { ...filters };
43
+ const defaultsApplied = [];
44
+ const stripEmptyArray = (key) => {
45
+ const value = normalized[key];
46
+ if (Array.isArray(value) && value.length === 0) {
47
+ delete normalized[key];
48
+ }
49
+ };
50
+ const stripZero = (key) => {
51
+ const value = normalized[key];
52
+ if (typeof value === "number" && value === 0) {
53
+ delete normalized[key];
54
+ }
55
+ };
56
+ if (normalized.platform === "all") delete normalized.platform;
57
+ if (normalized.spamLabel === "all") delete normalized.spamLabel;
58
+ stripZero("minFollowers");
59
+ stripZero("maxFollowers");
60
+ stripZero("activeInLastDays");
61
+ stripZero("minBatteryPercentage");
62
+ stripZero("hasRechargedInLastDays");
63
+ stripZero("maxAttentionPriceUsd");
64
+ stripEmptyArray("signalTokens");
65
+ if (Array.isArray(normalized.tokenHolders)) {
66
+ normalized.tokenHolders = normalized.tokenHolders.map((holder) => {
67
+ if (!holder) return null;
68
+ if ("tokenAddress" in holder && "chainId" in holder) return holder;
69
+ const loose = holder;
70
+ if (!loose.contractAddress || loose.chain == null) return null;
71
+ const chainId = typeof loose.chain === "number" ? loose.chain : CHAIN_ID_MAP[String(loose.chain).toLowerCase()] ?? Number(loose.chain);
72
+ if (!Number.isFinite(chainId)) return null;
73
+ return {
74
+ tokenAddress: loose.contractAddress,
75
+ chainId,
76
+ ...loose.minBalance ? { minBalance: loose.minBalance } : {}
77
+ };
78
+ }).filter((holder) => !!holder);
79
+ }
80
+ stripEmptyArray("tokenHolders");
81
+ if (Array.isArray(normalized.countries)) {
82
+ normalized.countries = normalized.countries.map((country) => {
83
+ if (typeof country === "string") return country;
84
+ return country?.code;
85
+ }).filter((country) => typeof country === "string" && country.length > 0).map((country) => country.toUpperCase());
86
+ }
87
+ stripEmptyArray("countries");
88
+ stripEmptyArray("fids");
89
+ stripEmptyArray("userIds");
90
+ if (normalized.neynarScoreMin === 0) delete normalized.neynarScoreMin;
91
+ if (normalized.neynarScoreMax === 1) delete normalized.neynarScoreMax;
92
+ if (normalized.quotientScoreMin === 0) delete normalized.quotientScoreMin;
93
+ if (normalized.quotientScoreMax === 1) delete normalized.quotientScoreMax;
94
+ if (!hasSubstantiveFilters(normalized)) {
95
+ normalized.activeInLastDays = 30;
96
+ normalized.spamLabel = "not_spam_only";
97
+ defaultsApplied.push("activeInLastDays=30", "spamLabel=not_spam_only");
98
+ }
99
+ return { filters: normalized, defaultsApplied };
100
+ }
101
+ function getOrderByOrDefault(filters) {
102
+ return filters.orderBy ?? "attention_price_asc";
103
+ }
104
+ function buildAgentQueryPlan(filters) {
105
+ const normalized = normalizeAgentFilters(filters);
106
+ return {
107
+ inputFilters: { ...filters },
108
+ filters: normalized.filters,
109
+ orderBy: getOrderByOrDefault(normalized.filters),
110
+ defaultsApplied: normalized.defaultsApplied
111
+ };
112
+ }
113
+
114
+ // src/core/agent/costing.ts
115
+ var DEFAULT_MICRO_USD_PER_USD = 1e6;
116
+ var DEFAULT_PLATFORM_FEE_RATE = 0.1;
117
+ var GOAL_BASELINES = {
118
+ max_reach: { payout: 100, bonus: 0 },
119
+ lil_mission: { payout: 80, bonus: 20 },
120
+ hard_mission: { payout: 50, bonus: 50 }
121
+ };
122
+ var SPLIT_ADJUSTMENTS = {
123
+ balanced: 0,
124
+ more_reach: 10,
125
+ more_action: -10
126
+ };
127
+ function computeBudgetSplit(totalUsd, goalType = "max_reach", splitPreset = "balanced", platformFeeRate = DEFAULT_PLATFORM_FEE_RATE) {
128
+ const baseline = GOAL_BASELINES[goalType];
129
+ const adjustment = SPLIT_ADJUSTMENTS[splitPreset];
130
+ let payoutPercent = Math.max(0, Math.min(100, baseline.payout + adjustment));
131
+ let bonusPercent = Math.max(0, Math.min(100, baseline.bonus - adjustment));
132
+ const sum = payoutPercent + bonusPercent;
133
+ if (sum !== 100) {
134
+ payoutPercent = payoutPercent / sum * 100;
135
+ bonusPercent = bonusPercent / sum * 100;
136
+ }
137
+ const payoutUsd = roundToCents(totalUsd * payoutPercent / 100);
138
+ const bonusUsd = roundToCents(totalUsd * bonusPercent / 100);
139
+ const platformFeeUsd = roundToCents(totalUsd * platformFeeRate);
140
+ const userPaysUsd = roundToCents(totalUsd + platformFeeUsd);
141
+ return {
142
+ totalUsd,
143
+ payoutUsd,
144
+ bonusUsd,
145
+ platformFeeUsd,
146
+ userPaysUsd,
147
+ goalType,
148
+ splitPreset,
149
+ payoutPercent: Math.round(payoutPercent),
150
+ bonusPercent: Math.round(bonusPercent)
151
+ };
152
+ }
153
+ function roundToCents(value) {
154
+ return Math.round(value * 100) / 100;
155
+ }
156
+ function parseUsd(value) {
157
+ return parseFloat(value.replace(/^\$/, "").trim());
158
+ }
159
+ function usdToMicroUsd(usd, microUsdPerUsd = DEFAULT_MICRO_USD_PER_USD) {
160
+ return Math.round(usd * microUsdPerUsd);
161
+ }
162
+
163
+ // src/core/agent/engine.ts
164
+ var DEFAULT_CHAIN_INFO = {
165
+ 8453: { name: "Base", usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }
166
+ };
167
+ var AgentCore = class {
168
+ adapter;
169
+ defaultChainId;
170
+ platformFeeRate;
171
+ estimateMaxUsers;
172
+ bulkMaxUsers;
173
+ microUsdPerUsd;
174
+ chainInfo;
175
+ constructor(adapter, config = {}) {
176
+ this.adapter = adapter;
177
+ this.defaultChainId = config.defaultChainId ?? 8453;
178
+ this.platformFeeRate = config.platformFeeRate ?? DEFAULT_PLATFORM_FEE_RATE;
179
+ this.estimateMaxUsers = config.estimateMaxUsers ?? 1e4;
180
+ this.bulkMaxUsers = config.bulkMaxUsers ?? 1e4;
181
+ this.microUsdPerUsd = config.microUsdPerUsd ?? DEFAULT_MICRO_USD_PER_USD;
182
+ this.chainInfo = config.chainInfo ?? DEFAULT_CHAIN_INFO;
183
+ }
184
+ buildQueryPlan(filters) {
185
+ return buildAgentQueryPlan(filters);
186
+ }
187
+ normalizeFilters(filters) {
188
+ return normalizeAgentFilters(filters);
189
+ }
190
+ computeBudgetSplit(totalUsd, goalType = "max_reach", splitPreset = "balanced") {
191
+ return computeBudgetSplit(totalUsd, goalType, splitPreset, this.platformFeeRate);
192
+ }
193
+ async lookup(query) {
194
+ const user = await this.adapter.resolveUser(query);
195
+ if (!user) return null;
196
+ const fid = user.fid ?? await this.adapter.getFidForUser(user.id) ?? void 0;
197
+ const walletAddress = user.walletAddress ?? await this.adapter.getPrimaryWalletAddress(user.id) ?? void 0;
198
+ return {
199
+ id: user.id,
200
+ username: user.username,
201
+ platform: user.platform,
202
+ attentionPriceUsd: (Number(user.attentionPriceMicroUsd) / this.microUsdPerUsd).toFixed(2),
203
+ ...fid !== void 0 ? { fid } : {},
204
+ ...user.displayName ? { displayName: user.displayName } : {},
205
+ ...user.pfpUrl ? { pfpUrl: user.pfpUrl } : {},
206
+ ...walletAddress ? { walletAddress } : {},
207
+ ...user.followerCount !== void 0 ? { followerCount: user.followerCount } : {}
208
+ };
209
+ }
210
+ async getPrice(query) {
211
+ const user = await this.lookup(query);
212
+ if (!user) return null;
213
+ const priceUsdNum = parseFloat(user.attentionPriceUsd);
214
+ return {
215
+ userId: user.id,
216
+ username: user.username,
217
+ priceUsd: user.attentionPriceUsd,
218
+ priceUsdc: usdToMicroUsd(priceUsdNum, this.microUsdPerUsd).toString()
219
+ };
220
+ }
221
+ async prepareBeep(params) {
222
+ const user = await this.lookup(params.to);
223
+ if (!user) {
224
+ return { error: "user_not_found", message: `User not found: ${params.to}` };
225
+ }
226
+ if (!user.walletAddress) {
227
+ return { error: "no_wallet", message: `@${user.username} has no connected wallet` };
228
+ }
229
+ const baseAmount = parseUsd(params.amountUsd);
230
+ if (Number.isNaN(baseAmount) || baseAmount <= 0) {
231
+ return { error: "invalid_amount", message: "Amount must be a positive number" };
232
+ }
233
+ const attentionPrice = parseFloat(user.attentionPriceUsd);
234
+ if (baseAmount < attentionPrice) {
235
+ return {
236
+ error: "below_minimum",
237
+ message: `Amount $${baseAmount.toFixed(2)} is below @${user.username}'s minimum beep price of $${attentionPrice.toFixed(2)}.`,
238
+ minimumUsd: user.attentionPriceUsd,
239
+ requestedUsd: params.amountUsd
240
+ };
241
+ }
242
+ const chainId = params.chainId ?? this.defaultChainId;
243
+ const chain = this.chainInfo[chainId];
244
+ if (!chain) {
245
+ return { error: "unsupported_chain", message: `Chain ${chainId} is not supported` };
246
+ }
247
+ const goalType = params.goalType ?? (params.bonusConfig ? "lil_mission" : "max_reach");
248
+ const hasMissions = goalType !== "max_reach";
249
+ const splitPreset = params.splitPreset ?? "balanced";
250
+ const split = hasMissions ? this.computeBudgetSplit(baseAmount, goalType, splitPreset) : void 0;
251
+ const platformFeeUsd = Math.round(baseAmount * this.platformFeeRate * 100) / 100;
252
+ const totalAmountUsd = baseAmount + platformFeeUsd;
253
+ const result = {
254
+ type: "confirmation",
255
+ recipient: {
256
+ username: user.username,
257
+ walletAddress: user.walletAddress,
258
+ ...user.displayName ? { displayName: user.displayName } : {},
259
+ ...user.pfpUrl ? { pfpUrl: user.pfpUrl } : {},
260
+ ...user.fid !== void 0 ? { fid: user.fid } : {}
261
+ },
262
+ message: params.message,
263
+ baseAmountUsd: baseAmount.toFixed(2),
264
+ platformFeeUsd: platformFeeUsd.toFixed(2),
265
+ totalAmountUsd: totalAmountUsd.toFixed(2),
266
+ feePercentage: this.platformFeeRate * 100,
267
+ chainId,
268
+ chainName: chain.name,
269
+ attentionPriceUsd: user.attentionPriceUsd
270
+ };
271
+ if (hasMissions && split) {
272
+ result.hasMissions = true;
273
+ result.budgetSplit = split;
274
+ if (params.bonusConfig) {
275
+ result.bonusConfig = params.bonusConfig;
276
+ }
277
+ }
278
+ return result;
279
+ }
280
+ async createIntent(params) {
281
+ const user = await this.lookup(params.to);
282
+ if (!user || !user.walletAddress) return null;
283
+ const baseAmountUsd = parseUsd(params.amountUsd);
284
+ if (Number.isNaN(baseAmountUsd) || baseAmountUsd <= 0) {
285
+ throw AgentCoreError.validation("Invalid amount");
286
+ }
287
+ const chainId = params.chainId ?? this.defaultChainId;
288
+ const chain = this.chainInfo[chainId];
289
+ if (!chain) throw AgentCoreError.unsupportedChain(chainId);
290
+ const platformFeeUsd = Math.round(baseAmountUsd * this.platformFeeRate * 100) / 100;
291
+ const totalAmountUsd = baseAmountUsd + platformFeeUsd;
292
+ const amountUsdc = usdToMicroUsd(totalAmountUsd, this.microUsdPerUsd).toString();
293
+ const intentId = `intent_${crypto.randomUUID()}`;
294
+ const shortAddress = `${user.walletAddress.slice(0, 6)}...${user.walletAddress.slice(-4)}`;
295
+ const message = params.message ?? "";
296
+ return {
297
+ intentId,
298
+ recipient: user.walletAddress,
299
+ amount: amountUsdc,
300
+ amountFormatted: `${totalAmountUsd.toFixed(2)} USDC`,
301
+ tokenAddress: chain.usdcAddress,
302
+ tokenSymbol: "USDC",
303
+ chainId,
304
+ chainName: chain.name,
305
+ message,
306
+ recipientInfo: {
307
+ username: user.username,
308
+ ...user.displayName ? { displayName: user.displayName } : {},
309
+ ...user.fid !== void 0 ? { fid: user.fid } : {}
310
+ },
311
+ instruction: `Send ${totalAmountUsd.toFixed(2)} USDC to ${shortAddress} on ${chain.name} (${baseAmountUsd.toFixed(2)} to @${user.username} + ${platformFeeUsd.toFixed(2)} platform fee)`,
312
+ expiresAt: new Date(Date.now() + 60 * 60 * 1e3).toISOString(),
313
+ baseAmountUsd: baseAmountUsd.toFixed(2),
314
+ platformFeeUsd: platformFeeUsd.toFixed(2),
315
+ totalAmountUsd: totalAmountUsd.toFixed(2),
316
+ feePercentage: this.platformFeeRate * 100
317
+ };
318
+ }
319
+ async estimate(params) {
320
+ const budgetUsd = parseUsd(params.budgetUsd);
321
+ if (Number.isNaN(budgetUsd) || budgetUsd <= 0) {
322
+ throw AgentCoreError.validation("Budget must be a positive number");
323
+ }
324
+ const plan = this.buildQueryPlan(params.filters);
325
+ const candidates = await this.adapter.findUsers({
326
+ filters: plan.filters,
327
+ orderBy: plan.orderBy,
328
+ limit: this.estimateMaxUsers
329
+ });
330
+ const budgetMicro = usdToMicroUsd(budgetUsd, this.microUsdPerUsd);
331
+ let totalCost = 0;
332
+ let recipientCount = 0;
333
+ let minPrice = Number.POSITIVE_INFINITY;
334
+ let maxPrice = 0;
335
+ for (const candidate of candidates) {
336
+ const priceMicro = Number(candidate.attentionPriceMicroUsd);
337
+ if (totalCost + priceMicro > budgetMicro) break;
338
+ totalCost += priceMicro;
339
+ recipientCount += 1;
340
+ if (priceMicro < minPrice) minPrice = priceMicro;
341
+ if (priceMicro > maxPrice) maxPrice = priceMicro;
342
+ }
343
+ const avgPrice = recipientCount > 0 ? totalCost / recipientCount : 0;
344
+ return {
345
+ recipientCount,
346
+ totalCostUsd: (totalCost / this.microUsdPerUsd).toFixed(2),
347
+ avgPriceUsd: (avgPrice / this.microUsdPerUsd).toFixed(2),
348
+ minPriceUsd: recipientCount > 0 ? (minPrice / this.microUsdPerUsd).toFixed(2) : "0.00",
349
+ maxPriceUsd: recipientCount > 0 ? (maxPrice / this.microUsdPerUsd).toFixed(2) : "0.00",
350
+ remainingBudgetUsd: ((budgetMicro - totalCost) / this.microUsdPerUsd).toFixed(2),
351
+ budgetSufficient: recipientCount > 0,
352
+ diagnostics: {
353
+ candidateCount: candidates.length,
354
+ budgetMicro,
355
+ appliedDefaults: plan.defaultsApplied
356
+ }
357
+ };
358
+ }
359
+ async preview(params) {
360
+ const limit = Math.min(Math.max(params.limit, 1), 20);
361
+ const plan = this.buildQueryPlan(params.filters);
362
+ const [users, totalCount] = await Promise.all([
363
+ this.adapter.findUsers({
364
+ filters: plan.filters,
365
+ orderBy: plan.orderBy,
366
+ limit,
367
+ includeProfile: true,
368
+ includeReputation: true
369
+ }),
370
+ this.adapter.countUsers(plan.filters)
371
+ ]);
372
+ const userIds = users.map((user) => user.id);
373
+ const fidMap = await this.adapter.getBulkFidsForUsers(userIds);
374
+ return {
375
+ users: users.map((user) => {
376
+ const previewUser = {
377
+ username: user.username,
378
+ priceUsd: (Number(user.attentionPriceMicroUsd) / this.microUsdPerUsd).toFixed(2),
379
+ ...user.displayName ? { displayName: user.displayName } : {},
380
+ ...user.followerCount !== void 0 ? { followerCount: user.followerCount } : {},
381
+ ...user.neynarScore !== void 0 ? { neynarScore: user.neynarScore } : {},
382
+ ...user.pfpUrl ? { pfpUrl: user.pfpUrl } : {}
383
+ };
384
+ const fid = fidMap.get(user.id);
385
+ if (fid !== void 0) {
386
+ return { ...previewUser, fid };
387
+ }
388
+ return previewUser;
389
+ }),
390
+ totalCount,
391
+ hasMore: totalCount > limit
392
+ };
393
+ }
394
+ async createBulkIntent(params) {
395
+ const budgetUsd = parseUsd(params.budgetUsd);
396
+ if (Number.isNaN(budgetUsd) || budgetUsd <= 0) {
397
+ throw AgentCoreError.validation("Budget must be a positive number");
398
+ }
399
+ const chainId = params.chainId ?? this.defaultChainId;
400
+ const chain = this.chainInfo[chainId];
401
+ if (!chain) throw AgentCoreError.unsupportedChain(chainId);
402
+ const plan = this.buildQueryPlan(params.filters);
403
+ const users = await this.adapter.findUsers({
404
+ filters: plan.filters,
405
+ orderBy: "attention_price_asc",
406
+ limit: this.bulkMaxUsers
407
+ });
408
+ const budgetMicro = usdToMicroUsd(budgetUsd, this.microUsdPerUsd);
409
+ let totalAmountMicro = 0;
410
+ const selectedUsers = [];
411
+ for (const user of users) {
412
+ const priceMicro = Number(user.attentionPriceMicroUsd);
413
+ if (totalAmountMicro + priceMicro > budgetMicro) break;
414
+ totalAmountMicro += priceMicro;
415
+ selectedUsers.push({
416
+ id: user.id,
417
+ username: user.username,
418
+ amountMicro: priceMicro
419
+ });
420
+ }
421
+ if (selectedUsers.length === 0) {
422
+ throw AgentCoreError.noRecipients("No eligible recipients within budget");
423
+ }
424
+ const walletMap = await this.adapter.getBulkPrimaryWalletAddresses(selectedUsers.map((u) => u.id));
425
+ const payments = selectedUsers.filter((user) => walletMap.has(user.id)).map((user) => ({
426
+ recipient: walletMap.get(user.id),
427
+ amount: user.amountMicro.toString(),
428
+ username: user.username
429
+ }));
430
+ if (payments.length === 0) {
431
+ throw AgentCoreError.noRecipients("No recipients with valid wallets found");
432
+ }
433
+ const totalAmount = payments.reduce((sum, payment) => sum + BigInt(payment.amount), 0n);
434
+ const totalFormatted = (Number(totalAmount) / this.microUsdPerUsd).toFixed(2);
435
+ return {
436
+ bulkIntentId: `bulk_${crypto.randomUUID()}`,
437
+ recipientCount: payments.length,
438
+ totalAmount: totalAmount.toString(),
439
+ totalAmountFormatted: `${totalFormatted} USDC`,
440
+ payments,
441
+ summary: `Send to ${payments.length} recipients for total ${totalFormatted} USDC on ${chain.name}`,
442
+ chainId,
443
+ chainName: chain.name,
444
+ tokenAddress: chain.usdcAddress,
445
+ tokenSymbol: "USDC",
446
+ expiresAt: new Date(Date.now() + 60 * 60 * 1e3).toISOString()
447
+ };
448
+ }
449
+ async prepareCampaign(params) {
450
+ const totalBudget = parseUsd(params.budgetUsd);
451
+ if (Number.isNaN(totalBudget) || totalBudget <= 0) {
452
+ throw AgentCoreError.validation("Budget must be a positive number");
453
+ }
454
+ const chainId = params.chainId ?? this.defaultChainId;
455
+ const chain = this.chainInfo[chainId];
456
+ if (!chain) throw AgentCoreError.unsupportedChain(chainId);
457
+ const goalType = params.goalType ?? (params.bonusConfig ? "lil_mission" : "max_reach");
458
+ const splitPreset = params.splitPreset ?? "balanced";
459
+ const split = this.computeBudgetSplit(totalBudget, goalType, splitPreset);
460
+ const payoutEstimate = await this.estimate({
461
+ filters: params.filters,
462
+ budgetUsd: split.payoutUsd.toFixed(2),
463
+ ...params.message ? { message: params.message } : {}
464
+ });
465
+ let missionSummary;
466
+ if (params.bonusConfig) {
467
+ const ctaLabels = params.bonusConfig.ctas.map((cta) => {
468
+ switch (cta.type) {
469
+ case "follow_profile":
470
+ return `Follow @${cta.profileUsername || cta.profileFid}`;
471
+ case "like_cast":
472
+ return "Like a cast";
473
+ case "recast":
474
+ return "Recast";
475
+ case "share_cast":
476
+ return "Quote cast";
477
+ case "visit_link":
478
+ return `Visit ${cta.label || cta.url || "link"}`;
479
+ case "quiz":
480
+ return `Quiz (${cta.questions?.length || 0} questions)`;
481
+ case "external_verify":
482
+ return cta.description || "Custom quest";
483
+ case "x_follow":
484
+ return `Follow @${cta.handle} on X`;
485
+ case "x_like":
486
+ return "Like tweet on X";
487
+ case "x_recast":
488
+ return "Repost on X";
489
+ default:
490
+ return cta.type;
491
+ }
492
+ });
493
+ const distributionLabel = params.bonusConfig.type === "lottery" ? "BEEPERY (lottery)" : "FCFS (first come)";
494
+ missionSummary = `${distributionLabel} \u2022 $${split.bonusUsd.toFixed(2)} pool \u2022 ${ctaLabels.join(", ")}`;
495
+ }
496
+ return {
497
+ type: "campaign_confirmation",
498
+ recipientCount: payoutEstimate.recipientCount,
499
+ budgetSplit: split,
500
+ payoutEstimate: {
501
+ recipientCount: payoutEstimate.recipientCount,
502
+ totalPayoutCostUsd: payoutEstimate.totalCostUsd,
503
+ avgPriceUsd: payoutEstimate.avgPriceUsd
504
+ },
505
+ platformFeeUsd: split.platformFeeUsd.toFixed(2),
506
+ userPaysUsd: split.userPaysUsd.toFixed(2),
507
+ chainId,
508
+ chainName: chain.name,
509
+ ...params.bonusConfig ? { bonusConfig: params.bonusConfig } : {},
510
+ ...missionSummary ? { missionSummary } : {},
511
+ ...params.message ? { message: params.message } : {}
512
+ };
513
+ }
514
+ async getBeepHistory(params) {
515
+ return this.adapter.getBeepHistory(params);
516
+ }
517
+ };
518
+ function createAgentCore(adapter, config) {
519
+ return new AgentCore(adapter, config);
520
+ }
521
+ function normalizeFilters(filters) {
522
+ return normalizeAgentFilters(filters);
523
+ }
524
+ function buildQueryPlan(filters) {
525
+ return buildAgentQueryPlan(filters);
526
+ }
527
+ function getDefaultOrderBy(filters) {
528
+ return buildAgentQueryPlan(filters).orderBy;
529
+ }
530
+
531
+ exports.AgentCore = AgentCore;
532
+ exports.AgentCoreError = AgentCoreError;
533
+ exports.buildAgentQueryPlan = buildAgentQueryPlan;
534
+ exports.buildQueryPlan = buildQueryPlan;
535
+ exports.computeBudgetSplit = computeBudgetSplit;
536
+ exports.createAgentCore = createAgentCore;
537
+ exports.getDefaultOrderBy = getDefaultOrderBy;
538
+ exports.getOrderByOrDefault = getOrderByOrDefault;
539
+ exports.normalizeAgentFilters = normalizeAgentFilters;
540
+ exports.normalizeFilters = normalizeFilters;
541
+ //# sourceMappingURL=index.cjs.map
542
+ //# sourceMappingURL=index.cjs.map