@q00bs/agent-sdk 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Q00bsAgent.d.ts +112 -5
- package/dist/Q00bsAgent.d.ts.map +1 -1
- package/dist/Q00bsAgent.js +197 -10
- package/dist/Q00bsAgent.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/marketing.d.ts +254 -0
- package/dist/marketing.d.ts.map +1 -0
- package/dist/marketing.js +366 -0
- package/dist/marketing.js.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -21,17 +21,18 @@
|
|
|
21
21
|
*
|
|
22
22
|
* ARCHITECTURE:
|
|
23
23
|
* Q00bsAgent (this file's default export)
|
|
24
|
-
* ├── TrustResolver
|
|
25
|
-
* ├── EscrowManager
|
|
26
|
-
* ├── ConsensusManager
|
|
27
|
-
* ├── AgentDiscovery
|
|
28
|
-
*
|
|
24
|
+
* ├── TrustResolver — trust-path queries
|
|
25
|
+
* ├── EscrowManager — agent-to-agent payments
|
|
26
|
+
* ├── ConsensusManager — multi-agent voting
|
|
27
|
+
* ├── AgentDiscovery — find peer agents
|
|
28
|
+
* ├── ERC8004Manager — cross-platform identity & reputation
|
|
29
|
+
* └── MarketingManager — agent-to-agent marketing (campaigns, bids, referrals)
|
|
29
30
|
*
|
|
30
31
|
* All sub-modules are also exported for advanced use cases.
|
|
31
32
|
*/
|
|
32
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.
|
|
34
|
-
exports.ERC8004_VALIDATION_ABI = exports.ERC8004_REPUTATION_ABI = exports.ERC8004_IDENTITY_ABI = void 0;
|
|
34
|
+
exports.AGENT_ESCROW_ABI = exports.AGENT_REGISTRY_ABI = exports.THE_Q00BS_ABI = exports.Q00B_FACTORY_ABI = exports.ERC8004_NAMESPACE = exports.ERC8004_VALIDATION_REGISTRY_ADDRESS = exports.ERC8004_REPUTATION_REGISTRY_ADDRESS = exports.ERC8004_IDENTITY_REGISTRY_ADDRESS = exports.DEFAULT_MAX_HOPS = exports.PROTOCOL_FEE_BPS = exports.TRUST_DECAY_PER_HOP_PERCENT = exports.MAX_TRUST_SCORE = exports.CONSENSUS_MODULE_ADDRESS = exports.AGENT_ESCROW_ADDRESS = exports.AGENT_REGISTRY_ADDRESS = exports.GENESIS_Q00B_ADDRESS = exports.Q00B_FACTORY_ADDRESS = exports.DEFAULT_RPC_URL = exports.BASE_CHAIN_ID = exports.ERC8004NotConfiguredError = exports.ERC8004RegistryError = exports.ERC8004SelfFeedbackError = exports.ERC8004IdentityNotFoundError = exports.ERC8004Error = exports.PrivyApiError = exports.PrivyPolicyViolationError = exports.PrivyWalletError = exports.ContractCallError = exports.AgentInactiveError = exports.ConsensusRejectedError = exports.ConsensusTimeoutError = exports.EscrowStateError = exports.SpendLimitExceededError = exports.InsufficientTrustError = exports.TrustPathNotFoundError = exports.AgentNotRegisteredError = exports.Q00bsError = exports.ConsensusState = exports.EscrowState = exports.MarketingManager = exports.ERC8004Manager = exports.PrivyWalletManager = exports.createLogger = exports.createPrivyClients = exports.createClients = exports.AgentDiscovery = exports.ConsensusManager = exports.EscrowManager = exports.TrustResolver = exports.Q00bsAgent = void 0;
|
|
35
|
+
exports.ERC8004_VALIDATION_ABI = exports.ERC8004_REPUTATION_ABI = exports.ERC8004_IDENTITY_ABI = exports.CONSENSUS_MODULE_ABI = void 0;
|
|
35
36
|
// ── Main class ────────────────────────────────────────────────
|
|
36
37
|
var Q00bsAgent_1 = require("./Q00bsAgent");
|
|
37
38
|
Object.defineProperty(exports, "Q00bsAgent", { enumerable: true, get: function () { return Q00bsAgent_1.Q00bsAgent; } });
|
|
@@ -55,6 +56,9 @@ Object.defineProperty(exports, "PrivyWalletManager", { enumerable: true, get: fu
|
|
|
55
56
|
// ── ERC-8004 Trustless Agents ─────────────────────────────────
|
|
56
57
|
var erc8004_1 = require("./erc8004");
|
|
57
58
|
Object.defineProperty(exports, "ERC8004Manager", { enumerable: true, get: function () { return erc8004_1.ERC8004Manager; } });
|
|
59
|
+
// ── Agent-to-Agent Marketing ─────────────────────────────────
|
|
60
|
+
var marketing_1 = require("./marketing");
|
|
61
|
+
Object.defineProperty(exports, "MarketingManager", { enumerable: true, get: function () { return marketing_1.MarketingManager; } });
|
|
58
62
|
var types_1 = require("./types");
|
|
59
63
|
Object.defineProperty(exports, "EscrowState", { enumerable: true, get: function () { return types_1.EscrowState; } });
|
|
60
64
|
Object.defineProperty(exports, "ConsensusState", { enumerable: true, get: function () { return types_1.ConsensusState; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;;AAEH,iEAAiE;AACjE,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AAEnB,iEAAiE;AACjE,iCAAwC;AAA/B,sGAAA,aAAa,OAAA;AACtB,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AACtB,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AAEvB,iEAAiE;AACjE,mCAA2E;AAAlE,uGAAA,aAAa,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAAE,sGAAA,YAAY,OAAA;AAGxD,gEAAgE;AAChE,iCAA6C;AAApC,2GAAA,kBAAkB,OAAA;AAE3B,iEAAiE;AACjE,qCAA2C;AAAlC,yGAAA,cAAc,OAAA;AAEvB,gEAAgE;AAChE,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AA0DzB,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A,gBAAgB,OAAA;AACzB,0DAA8D;AAArD,uHAAA,oBAAoB,OAAA;AAE7B,iEAAiE;AACjE,0DAA8D;AAArD,uHAAA,oBAAoB,OAAA;AAC7B,8DAAkE;AAAzD,2HAAA,sBAAsB,OAAA;AAC/B,8DAAkE;AAAzD,2HAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @q00bs/agent-sdk — MarketingManager
|
|
3
|
+
*
|
|
4
|
+
* Agent-to-agent marketing module for the Q00bs trust network.
|
|
5
|
+
* Manages campaigns (service listings), bids (priority discovery),
|
|
6
|
+
* and referrals (agent introductions) — all trust-verified.
|
|
7
|
+
*
|
|
8
|
+
* WHAT THIS MODULE DOES:
|
|
9
|
+
* - Creates marketing campaigns for agent services
|
|
10
|
+
* - Places bids for priority placement in discovery results
|
|
11
|
+
* - Creates and tracks referrals between agents
|
|
12
|
+
* - Queries campaign analytics and referral earnings
|
|
13
|
+
* - Discovers services with trust-weighted + bid-boosted ranking
|
|
14
|
+
*
|
|
15
|
+
* TRUST INTEGRATION:
|
|
16
|
+
* - Only registered agents can create campaigns/bids
|
|
17
|
+
* - Bid weight = bidAmount × (trustScore / 10000) — spam can't outbid trust
|
|
18
|
+
* - Referrals require trust path between referrer and referred agent
|
|
19
|
+
* - Campaign visibility gated by trust floor
|
|
20
|
+
*
|
|
21
|
+
* REVENUE:
|
|
22
|
+
* - 2% protocol fee on campaign impression spend
|
|
23
|
+
* - 2% protocol fee on bid spend
|
|
24
|
+
* - 2% protocol fee on referral commissions (10% of escrow)
|
|
25
|
+
*/
|
|
26
|
+
import type { PublicClient, Chain, Transport } from 'viem';
|
|
27
|
+
import type { Logger } from './types';
|
|
28
|
+
export interface CampaignRecord {
|
|
29
|
+
id: number;
|
|
30
|
+
agentId: number;
|
|
31
|
+
capability: string;
|
|
32
|
+
capabilityHash: string;
|
|
33
|
+
description: string;
|
|
34
|
+
pricePerTask: string;
|
|
35
|
+
dailyBudget: string;
|
|
36
|
+
totalBudget: string;
|
|
37
|
+
spent: string;
|
|
38
|
+
impressions: number;
|
|
39
|
+
conversions: number;
|
|
40
|
+
trustFloor: number;
|
|
41
|
+
active: boolean;
|
|
42
|
+
createdAt: number;
|
|
43
|
+
roi: number;
|
|
44
|
+
}
|
|
45
|
+
export interface CreateCampaignParams {
|
|
46
|
+
capability: string;
|
|
47
|
+
description: string;
|
|
48
|
+
pricePerTask: string;
|
|
49
|
+
dailyBudget: string;
|
|
50
|
+
totalBudget: string;
|
|
51
|
+
trustFloor?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface BidRecord {
|
|
54
|
+
id: number;
|
|
55
|
+
agentId: number;
|
|
56
|
+
capabilitySlot: string;
|
|
57
|
+
bidPerImpression: string;
|
|
58
|
+
maxDaily: string;
|
|
59
|
+
totalDeposit: string;
|
|
60
|
+
totalSpent: string;
|
|
61
|
+
active: boolean;
|
|
62
|
+
effectiveWeight: number;
|
|
63
|
+
createdAt: number;
|
|
64
|
+
}
|
|
65
|
+
export interface PlaceBidParams {
|
|
66
|
+
capabilitySlot: string;
|
|
67
|
+
bidPerImpression: string;
|
|
68
|
+
maxDaily: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ReferralRecord {
|
|
71
|
+
id: number;
|
|
72
|
+
referrerAgentId: number;
|
|
73
|
+
referredAgentId: number;
|
|
74
|
+
clientAgentId: number;
|
|
75
|
+
escrowId: number | null;
|
|
76
|
+
escrowValue: string;
|
|
77
|
+
commission: string;
|
|
78
|
+
settled: boolean;
|
|
79
|
+
createdAt: number;
|
|
80
|
+
}
|
|
81
|
+
export interface CreateReferralParams {
|
|
82
|
+
referredAgentId: number;
|
|
83
|
+
clientAgentId: number;
|
|
84
|
+
reason?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface ReferralEarnings {
|
|
87
|
+
total: string;
|
|
88
|
+
active: number;
|
|
89
|
+
settled: number;
|
|
90
|
+
referrals: ReferralRecord[];
|
|
91
|
+
}
|
|
92
|
+
export interface CampaignStats {
|
|
93
|
+
campaignId: number;
|
|
94
|
+
impressions: number;
|
|
95
|
+
conversions: number;
|
|
96
|
+
spent: string;
|
|
97
|
+
revenue: string;
|
|
98
|
+
roi: number;
|
|
99
|
+
conversionRate: number;
|
|
100
|
+
}
|
|
101
|
+
export interface DiscoverServicesParams {
|
|
102
|
+
capability?: string;
|
|
103
|
+
minTrust?: number;
|
|
104
|
+
maxPrice?: string;
|
|
105
|
+
sortBy?: 'trust_weighted' | 'price' | 'reputation' | 'conversions';
|
|
106
|
+
limit?: number;
|
|
107
|
+
}
|
|
108
|
+
export interface DiscoveredService {
|
|
109
|
+
campaignId: number;
|
|
110
|
+
agentId: number;
|
|
111
|
+
capability: string;
|
|
112
|
+
description: string;
|
|
113
|
+
pricePerTask: string;
|
|
114
|
+
trustScore: number;
|
|
115
|
+
erc8004Rating: number;
|
|
116
|
+
ratingCount: number;
|
|
117
|
+
conversions: number;
|
|
118
|
+
effectiveTrust: number;
|
|
119
|
+
isBidBoosted: boolean;
|
|
120
|
+
}
|
|
121
|
+
export interface MarketRates {
|
|
122
|
+
capability: string;
|
|
123
|
+
avgPrice: string;
|
|
124
|
+
minPrice: string;
|
|
125
|
+
maxPrice: string;
|
|
126
|
+
providerCount: number;
|
|
127
|
+
avgTrustScore: number;
|
|
128
|
+
}
|
|
129
|
+
export declare class MarketingManager {
|
|
130
|
+
private publicClient;
|
|
131
|
+
private logger;
|
|
132
|
+
private trustApiUrl?;
|
|
133
|
+
private walletId?;
|
|
134
|
+
constructor(publicClient: PublicClient<Transport, Chain>, logger: Logger, trustApiUrl?: string, walletId?: string);
|
|
135
|
+
/**
|
|
136
|
+
* Create a marketing campaign for your agent's services.
|
|
137
|
+
*
|
|
138
|
+
* @param agentId - Your registered agent ID.
|
|
139
|
+
* @param params - Campaign parameters.
|
|
140
|
+
* @returns The new campaign ID.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const campaignId = await marketing.createCampaign(myAgentId, {
|
|
145
|
+
* capability: 'data_analysis',
|
|
146
|
+
* description: 'Enterprise-grade dataset analysis',
|
|
147
|
+
* pricePerTask: '0.01',
|
|
148
|
+
* dailyBudget: '0.1',
|
|
149
|
+
* totalBudget: '1.0',
|
|
150
|
+
* trustFloor: 40,
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
createCampaign(agentId: number, params: CreateCampaignParams): Promise<number>;
|
|
155
|
+
/**
|
|
156
|
+
* Get campaign details by ID.
|
|
157
|
+
*/
|
|
158
|
+
getCampaign(campaignId: number): Promise<CampaignRecord>;
|
|
159
|
+
/**
|
|
160
|
+
* Get detailed analytics for a campaign.
|
|
161
|
+
*/
|
|
162
|
+
getCampaignStats(campaignId: number): Promise<CampaignStats>;
|
|
163
|
+
/**
|
|
164
|
+
* Pause an active campaign.
|
|
165
|
+
*/
|
|
166
|
+
pauseCampaign(campaignId: number): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Resume a paused campaign.
|
|
169
|
+
*/
|
|
170
|
+
resumeCampaign(campaignId: number): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Add more budget to an existing campaign.
|
|
173
|
+
*/
|
|
174
|
+
fundCampaign(campaignId: number, amountEth: string): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* List all campaigns for an agent.
|
|
177
|
+
*/
|
|
178
|
+
listMyCampaigns(agentId: number): Promise<CampaignRecord[]>;
|
|
179
|
+
/**
|
|
180
|
+
* Place a bid for priority placement in discovery results.
|
|
181
|
+
* Effective weight = bidAmount × (trustScore / 10000) — trust beats money.
|
|
182
|
+
*
|
|
183
|
+
* @param agentId - Your registered agent ID.
|
|
184
|
+
* @param params - Bid parameters.
|
|
185
|
+
* @returns The new bid ID.
|
|
186
|
+
*/
|
|
187
|
+
placeBid(agentId: number, params: PlaceBidParams): Promise<number>;
|
|
188
|
+
/**
|
|
189
|
+
* Cancel a bid and reclaim remaining escrowed funds.
|
|
190
|
+
*/
|
|
191
|
+
cancelBid(bidId: number): Promise<string>;
|
|
192
|
+
/**
|
|
193
|
+
* Get current bid status and position.
|
|
194
|
+
*/
|
|
195
|
+
getBidStatus(bidId: number): Promise<BidRecord>;
|
|
196
|
+
/**
|
|
197
|
+
* List available bid slots and current top bidders for a capability.
|
|
198
|
+
*/
|
|
199
|
+
listBidSlots(capability: string): Promise<BidRecord[]>;
|
|
200
|
+
/**
|
|
201
|
+
* Create a referral — recommend another agent to a potential client.
|
|
202
|
+
* Earns 10% commission on the resulting escrow (minus 2% protocol fee).
|
|
203
|
+
* Requires a trust path between you and the referred agent.
|
|
204
|
+
*
|
|
205
|
+
* @param agentId - Your registered agent ID (the referrer).
|
|
206
|
+
* @param params - Referral parameters.
|
|
207
|
+
* @returns The new referral ID.
|
|
208
|
+
*/
|
|
209
|
+
createReferral(agentId: number, params: CreateReferralParams): Promise<number>;
|
|
210
|
+
/**
|
|
211
|
+
* Get referral details.
|
|
212
|
+
*/
|
|
213
|
+
getReferral(referralId: number): Promise<ReferralRecord>;
|
|
214
|
+
/**
|
|
215
|
+
* Get total referral earnings for an agent.
|
|
216
|
+
*/
|
|
217
|
+
getReferralEarnings(agentId: number): Promise<ReferralEarnings>;
|
|
218
|
+
/**
|
|
219
|
+
* List all referrals for an agent (as referrer).
|
|
220
|
+
*/
|
|
221
|
+
listMyReferrals(agentId: number): Promise<ReferralRecord[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Discover agent services with trust-weighted + bid-boosted ranking.
|
|
224
|
+
* Results are ranked by: (trustScore × reputationBonus) + bidWeight.
|
|
225
|
+
*
|
|
226
|
+
* @param fromAgentId - Your agent ID (for trust path calculation).
|
|
227
|
+
* @param params - Discovery filters.
|
|
228
|
+
* @returns Ranked list of available services.
|
|
229
|
+
*/
|
|
230
|
+
discoverServices(fromAgentId: number, params?: DiscoverServicesParams): Promise<DiscoveredService[]>;
|
|
231
|
+
/**
|
|
232
|
+
* Get average market rates for a capability across the network.
|
|
233
|
+
*/
|
|
234
|
+
getMarketRates(capability: string): Promise<MarketRates>;
|
|
235
|
+
/**
|
|
236
|
+
* Compare multiple agents side-by-side (trust, reputation, price).
|
|
237
|
+
*/
|
|
238
|
+
compareAgents(fromAgentId: number, targetAgentIds: number[]): Promise<DiscoveredService[]>;
|
|
239
|
+
/**
|
|
240
|
+
* Get network-wide marketing analytics.
|
|
241
|
+
*/
|
|
242
|
+
getNetworkAnalytics(): Promise<{
|
|
243
|
+
totalCampaigns: number;
|
|
244
|
+
activeCampaigns: number;
|
|
245
|
+
totalImpressions: number;
|
|
246
|
+
totalConversions: number;
|
|
247
|
+
totalMktVolume: string;
|
|
248
|
+
totalReferralsPaid: string;
|
|
249
|
+
protocolRevenue: string;
|
|
250
|
+
}>;
|
|
251
|
+
private apiCall;
|
|
252
|
+
private handleResponse;
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=marketing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketing.d.ts","sourceRoot":"","sources":["../src/marketing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAgB,KAAK,EAAE,SAAS,EAAW,MAAM,MAAM,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAMtC,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAA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AAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAY5D;;;;;;;;OAQG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBpF;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAO9D;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAOrE;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAWjE;;;;;;;OAOG;IACG,gBAAgB,CACpB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,sBAAsB,GAC9B,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAU/B;;OAEG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAO9D;;OAEG;IACG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAc/B;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC;QACnC,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;QACzB,gBAAgB,EAAE,MAAM,CAAC;QACzB,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;YAWY,OAAO;YA8CP,cAAc;CAW7B"}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @q00bs/agent-sdk — MarketingManager
|
|
4
|
+
*
|
|
5
|
+
* Agent-to-agent marketing module for the Q00bs trust network.
|
|
6
|
+
* Manages campaigns (service listings), bids (priority discovery),
|
|
7
|
+
* and referrals (agent introductions) — all trust-verified.
|
|
8
|
+
*
|
|
9
|
+
* WHAT THIS MODULE DOES:
|
|
10
|
+
* - Creates marketing campaigns for agent services
|
|
11
|
+
* - Places bids for priority placement in discovery results
|
|
12
|
+
* - Creates and tracks referrals between agents
|
|
13
|
+
* - Queries campaign analytics and referral earnings
|
|
14
|
+
* - Discovers services with trust-weighted + bid-boosted ranking
|
|
15
|
+
*
|
|
16
|
+
* TRUST INTEGRATION:
|
|
17
|
+
* - Only registered agents can create campaigns/bids
|
|
18
|
+
* - Bid weight = bidAmount × (trustScore / 10000) — spam can't outbid trust
|
|
19
|
+
* - Referrals require trust path between referrer and referred agent
|
|
20
|
+
* - Campaign visibility gated by trust floor
|
|
21
|
+
*
|
|
22
|
+
* REVENUE:
|
|
23
|
+
* - 2% protocol fee on campaign impression spend
|
|
24
|
+
* - 2% protocol fee on bid spend
|
|
25
|
+
* - 2% protocol fee on referral commissions (10% of escrow)
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.MarketingManager = void 0;
|
|
29
|
+
const viem_1 = require("viem");
|
|
30
|
+
// ─────────────────────────────────────────────────────────────
|
|
31
|
+
// MARKETING MANAGER
|
|
32
|
+
// ─────────────────────────────────────────────────────────────
|
|
33
|
+
class MarketingManager {
|
|
34
|
+
publicClient;
|
|
35
|
+
logger;
|
|
36
|
+
trustApiUrl;
|
|
37
|
+
walletId;
|
|
38
|
+
constructor(publicClient, logger, trustApiUrl, walletId) {
|
|
39
|
+
this.publicClient = publicClient;
|
|
40
|
+
this.logger = logger;
|
|
41
|
+
this.trustApiUrl = trustApiUrl;
|
|
42
|
+
this.walletId = walletId;
|
|
43
|
+
}
|
|
44
|
+
// ─────────────────────────────────────────────────────────────
|
|
45
|
+
// CAMPAIGNS
|
|
46
|
+
// ─────────────────────────────────────────────────────────────
|
|
47
|
+
/**
|
|
48
|
+
* Create a marketing campaign for your agent's services.
|
|
49
|
+
*
|
|
50
|
+
* @param agentId - Your registered agent ID.
|
|
51
|
+
* @param params - Campaign parameters.
|
|
52
|
+
* @returns The new campaign ID.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const campaignId = await marketing.createCampaign(myAgentId, {
|
|
57
|
+
* capability: 'data_analysis',
|
|
58
|
+
* description: 'Enterprise-grade dataset analysis',
|
|
59
|
+
* pricePerTask: '0.01',
|
|
60
|
+
* dailyBudget: '0.1',
|
|
61
|
+
* totalBudget: '1.0',
|
|
62
|
+
* trustFloor: 40,
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async createCampaign(agentId, params) {
|
|
67
|
+
this.logger.info(`Creating campaign for agent #${agentId}: ${params.capability}`);
|
|
68
|
+
if (this.trustApiUrl) {
|
|
69
|
+
const result = await this.apiCall('POST', '/api/v1/mkt/campaigns', {
|
|
70
|
+
agentId,
|
|
71
|
+
walletId: this.walletId,
|
|
72
|
+
capability: params.capability,
|
|
73
|
+
description: params.description,
|
|
74
|
+
pricePerTask: params.pricePerTask,
|
|
75
|
+
dailyBudget: params.dailyBudget,
|
|
76
|
+
totalBudget: params.totalBudget,
|
|
77
|
+
trustFloor: params.trustFloor || 0,
|
|
78
|
+
});
|
|
79
|
+
this.logger.info(`Campaign #${result.campaignId} created`);
|
|
80
|
+
return result.campaignId;
|
|
81
|
+
}
|
|
82
|
+
throw new Error('Campaign creation requires trustApiUrl');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get campaign details by ID.
|
|
86
|
+
*/
|
|
87
|
+
async getCampaign(campaignId) {
|
|
88
|
+
if (this.trustApiUrl) {
|
|
89
|
+
return this.apiCall('GET', `/api/v1/mkt/campaigns/${campaignId}`);
|
|
90
|
+
}
|
|
91
|
+
throw new Error('getCampaign requires trustApiUrl');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get detailed analytics for a campaign.
|
|
95
|
+
*/
|
|
96
|
+
async getCampaignStats(campaignId) {
|
|
97
|
+
if (this.trustApiUrl) {
|
|
98
|
+
return this.apiCall('GET', `/api/v1/mkt/campaigns/${campaignId}/stats`);
|
|
99
|
+
}
|
|
100
|
+
throw new Error('getCampaignStats requires trustApiUrl');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Pause an active campaign.
|
|
104
|
+
*/
|
|
105
|
+
async pauseCampaign(campaignId) {
|
|
106
|
+
this.logger.info(`Pausing campaign #${campaignId}`);
|
|
107
|
+
if (this.trustApiUrl) {
|
|
108
|
+
await this.apiCall('PUT', `/api/v1/mkt/campaigns/${campaignId}/pause`, {
|
|
109
|
+
walletId: this.walletId,
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
throw new Error('pauseCampaign requires trustApiUrl');
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Resume a paused campaign.
|
|
117
|
+
*/
|
|
118
|
+
async resumeCampaign(campaignId) {
|
|
119
|
+
this.logger.info(`Resuming campaign #${campaignId}`);
|
|
120
|
+
if (this.trustApiUrl) {
|
|
121
|
+
await this.apiCall('PUT', `/api/v1/mkt/campaigns/${campaignId}/resume`, {
|
|
122
|
+
walletId: this.walletId,
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
throw new Error('resumeCampaign requires trustApiUrl');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Add more budget to an existing campaign.
|
|
130
|
+
*/
|
|
131
|
+
async fundCampaign(campaignId, amountEth) {
|
|
132
|
+
this.logger.info(`Funding campaign #${campaignId} with ${amountEth} ETH`);
|
|
133
|
+
if (this.trustApiUrl) {
|
|
134
|
+
await this.apiCall('POST', `/api/v1/mkt/campaigns/${campaignId}/fund`, {
|
|
135
|
+
walletId: this.walletId,
|
|
136
|
+
amount: amountEth,
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
throw new Error('fundCampaign requires trustApiUrl');
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* List all campaigns for an agent.
|
|
144
|
+
*/
|
|
145
|
+
async listMyCampaigns(agentId) {
|
|
146
|
+
if (this.trustApiUrl) {
|
|
147
|
+
return this.apiCall('GET', `/api/v1/mkt/campaigns/agent/${agentId}`);
|
|
148
|
+
}
|
|
149
|
+
throw new Error('listMyCampaigns requires trustApiUrl');
|
|
150
|
+
}
|
|
151
|
+
// ─────────────────────────────────────────────────────────────
|
|
152
|
+
// BIDS
|
|
153
|
+
// ─────────────────────────────────────────────────────────────
|
|
154
|
+
/**
|
|
155
|
+
* Place a bid for priority placement in discovery results.
|
|
156
|
+
* Effective weight = bidAmount × (trustScore / 10000) — trust beats money.
|
|
157
|
+
*
|
|
158
|
+
* @param agentId - Your registered agent ID.
|
|
159
|
+
* @param params - Bid parameters.
|
|
160
|
+
* @returns The new bid ID.
|
|
161
|
+
*/
|
|
162
|
+
async placeBid(agentId, params) {
|
|
163
|
+
this.logger.info(`Placing bid for agent #${agentId} on slot: ${params.capabilitySlot}`);
|
|
164
|
+
if (this.trustApiUrl) {
|
|
165
|
+
const result = await this.apiCall('POST', '/api/v1/mkt/bids', {
|
|
166
|
+
agentId,
|
|
167
|
+
walletId: this.walletId,
|
|
168
|
+
capabilitySlot: params.capabilitySlot,
|
|
169
|
+
bidPerImpression: params.bidPerImpression,
|
|
170
|
+
maxDaily: params.maxDaily,
|
|
171
|
+
});
|
|
172
|
+
this.logger.info(`Bid #${result.bidId} placed (weight: ${result.effectiveWeight})`);
|
|
173
|
+
return result.bidId;
|
|
174
|
+
}
|
|
175
|
+
throw new Error('placeBid requires trustApiUrl');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Cancel a bid and reclaim remaining escrowed funds.
|
|
179
|
+
*/
|
|
180
|
+
async cancelBid(bidId) {
|
|
181
|
+
this.logger.info(`Cancelling bid #${bidId}`);
|
|
182
|
+
if (this.trustApiUrl) {
|
|
183
|
+
const result = await this.apiCall('DELETE', `/api/v1/mkt/bids/${bidId}`, {
|
|
184
|
+
walletId: this.walletId,
|
|
185
|
+
});
|
|
186
|
+
this.logger.info(`Bid #${bidId} cancelled, refund: ${result.refundAmount} ETH`);
|
|
187
|
+
return result.refundAmount;
|
|
188
|
+
}
|
|
189
|
+
throw new Error('cancelBid requires trustApiUrl');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get current bid status and position.
|
|
193
|
+
*/
|
|
194
|
+
async getBidStatus(bidId) {
|
|
195
|
+
if (this.trustApiUrl) {
|
|
196
|
+
return this.apiCall('GET', `/api/v1/mkt/bids/${bidId}`);
|
|
197
|
+
}
|
|
198
|
+
throw new Error('getBidStatus requires trustApiUrl');
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* List available bid slots and current top bidders for a capability.
|
|
202
|
+
*/
|
|
203
|
+
async listBidSlots(capability) {
|
|
204
|
+
if (this.trustApiUrl) {
|
|
205
|
+
const hash = (0, viem_1.keccak256)((0, viem_1.toHex)(capability));
|
|
206
|
+
return this.apiCall('GET', `/api/v1/mkt/bids/slots/${hash}`);
|
|
207
|
+
}
|
|
208
|
+
throw new Error('listBidSlots requires trustApiUrl');
|
|
209
|
+
}
|
|
210
|
+
// ─────────────────────────────────────────────────────────────
|
|
211
|
+
// REFERRALS
|
|
212
|
+
// ─────────────────────────────────────────────────────────────
|
|
213
|
+
/**
|
|
214
|
+
* Create a referral — recommend another agent to a potential client.
|
|
215
|
+
* Earns 10% commission on the resulting escrow (minus 2% protocol fee).
|
|
216
|
+
* Requires a trust path between you and the referred agent.
|
|
217
|
+
*
|
|
218
|
+
* @param agentId - Your registered agent ID (the referrer).
|
|
219
|
+
* @param params - Referral parameters.
|
|
220
|
+
* @returns The new referral ID.
|
|
221
|
+
*/
|
|
222
|
+
async createReferral(agentId, params) {
|
|
223
|
+
this.logger.info(`Creating referral: agent #${agentId} refers agent #${params.referredAgentId} to agent #${params.clientAgentId}`);
|
|
224
|
+
if (this.trustApiUrl) {
|
|
225
|
+
const result = await this.apiCall('POST', '/api/v1/mkt/referrals', {
|
|
226
|
+
referrerAgentId: agentId,
|
|
227
|
+
walletId: this.walletId,
|
|
228
|
+
referredAgentId: params.referredAgentId,
|
|
229
|
+
clientAgentId: params.clientAgentId,
|
|
230
|
+
reason: params.reason,
|
|
231
|
+
});
|
|
232
|
+
this.logger.info(`Referral #${result.referralId} created`);
|
|
233
|
+
return result.referralId;
|
|
234
|
+
}
|
|
235
|
+
throw new Error('createReferral requires trustApiUrl');
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get referral details.
|
|
239
|
+
*/
|
|
240
|
+
async getReferral(referralId) {
|
|
241
|
+
if (this.trustApiUrl) {
|
|
242
|
+
return this.apiCall('GET', `/api/v1/mkt/referrals/${referralId}`);
|
|
243
|
+
}
|
|
244
|
+
throw new Error('getReferral requires trustApiUrl');
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get total referral earnings for an agent.
|
|
248
|
+
*/
|
|
249
|
+
async getReferralEarnings(agentId) {
|
|
250
|
+
if (this.trustApiUrl) {
|
|
251
|
+
return this.apiCall('GET', `/api/v1/mkt/referrals/agent/${agentId}/earnings`);
|
|
252
|
+
}
|
|
253
|
+
throw new Error('getReferralEarnings requires trustApiUrl');
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* List all referrals for an agent (as referrer).
|
|
257
|
+
*/
|
|
258
|
+
async listMyReferrals(agentId) {
|
|
259
|
+
if (this.trustApiUrl) {
|
|
260
|
+
return this.apiCall('GET', `/api/v1/mkt/referrals/agent/${agentId}`);
|
|
261
|
+
}
|
|
262
|
+
throw new Error('listMyReferrals requires trustApiUrl');
|
|
263
|
+
}
|
|
264
|
+
// ─────────────────────────────────────────────────────────────
|
|
265
|
+
// DISCOVERY (Enhanced with MKT signals)
|
|
266
|
+
// ─────────────────────────────────────────────────────────────
|
|
267
|
+
/**
|
|
268
|
+
* Discover agent services with trust-weighted + bid-boosted ranking.
|
|
269
|
+
* Results are ranked by: (trustScore × reputationBonus) + bidWeight.
|
|
270
|
+
*
|
|
271
|
+
* @param fromAgentId - Your agent ID (for trust path calculation).
|
|
272
|
+
* @param params - Discovery filters.
|
|
273
|
+
* @returns Ranked list of available services.
|
|
274
|
+
*/
|
|
275
|
+
async discoverServices(fromAgentId, params) {
|
|
276
|
+
if (this.trustApiUrl) {
|
|
277
|
+
return this.apiCall('GET', '/api/v1/mkt/discover', {
|
|
278
|
+
fromAgentId,
|
|
279
|
+
...params,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
throw new Error('discoverServices requires trustApiUrl');
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get average market rates for a capability across the network.
|
|
286
|
+
*/
|
|
287
|
+
async getMarketRates(capability) {
|
|
288
|
+
if (this.trustApiUrl) {
|
|
289
|
+
return this.apiCall('GET', `/api/v1/mkt/rates/${encodeURIComponent(capability)}`);
|
|
290
|
+
}
|
|
291
|
+
throw new Error('getMarketRates requires trustApiUrl');
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Compare multiple agents side-by-side (trust, reputation, price).
|
|
295
|
+
*/
|
|
296
|
+
async compareAgents(fromAgentId, targetAgentIds) {
|
|
297
|
+
if (this.trustApiUrl) {
|
|
298
|
+
return this.apiCall('POST', '/api/v1/mkt/compare', {
|
|
299
|
+
fromAgentId,
|
|
300
|
+
targetAgentIds,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
throw new Error('compareAgents requires trustApiUrl');
|
|
304
|
+
}
|
|
305
|
+
// ─────────────────────────────────────────────────────────────
|
|
306
|
+
// ANALYTICS
|
|
307
|
+
// ─────────────────────────────────────────────────────────────
|
|
308
|
+
/**
|
|
309
|
+
* Get network-wide marketing analytics.
|
|
310
|
+
*/
|
|
311
|
+
async getNetworkAnalytics() {
|
|
312
|
+
if (this.trustApiUrl) {
|
|
313
|
+
return this.apiCall('GET', '/api/v1/mkt/analytics');
|
|
314
|
+
}
|
|
315
|
+
throw new Error('getNetworkAnalytics requires trustApiUrl');
|
|
316
|
+
}
|
|
317
|
+
// ─────────────────────────────────────────────────────────────
|
|
318
|
+
// INTERNAL
|
|
319
|
+
// ─────────────────────────────────────────────────────────────
|
|
320
|
+
async apiCall(method, path, body) {
|
|
321
|
+
const url = `${this.trustApiUrl}${path}`;
|
|
322
|
+
const headers = {
|
|
323
|
+
'Content-Type': 'application/json',
|
|
324
|
+
};
|
|
325
|
+
this.logger.debug(`MKT API ${method} ${path}`);
|
|
326
|
+
const fetchOptions = {
|
|
327
|
+
method,
|
|
328
|
+
headers,
|
|
329
|
+
};
|
|
330
|
+
// For GET requests, append body as query params
|
|
331
|
+
if (method === 'GET' && body) {
|
|
332
|
+
const params = new URLSearchParams();
|
|
333
|
+
for (const [key, value] of Object.entries(body)) {
|
|
334
|
+
if (value !== undefined && value !== null) {
|
|
335
|
+
if (Array.isArray(value)) {
|
|
336
|
+
params.set(key, value.join(','));
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
params.set(key, String(value));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const queryString = params.toString();
|
|
344
|
+
if (queryString) {
|
|
345
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
346
|
+
const fullUrl = `${url}${separator}${queryString}`;
|
|
347
|
+
const response = await fetch(fullUrl, fetchOptions);
|
|
348
|
+
return this.handleResponse(response, path);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (method !== 'GET' && body) {
|
|
352
|
+
fetchOptions.body = JSON.stringify(body);
|
|
353
|
+
}
|
|
354
|
+
const response = await fetch(url, fetchOptions);
|
|
355
|
+
return this.handleResponse(response, path);
|
|
356
|
+
}
|
|
357
|
+
async handleResponse(response, path) {
|
|
358
|
+
const data = await response.json();
|
|
359
|
+
if (!response.ok) {
|
|
360
|
+
throw new Error(`MKT API error (${response.status}): ${data.message || data.error || JSON.stringify(data)}`);
|
|
361
|
+
}
|
|
362
|
+
return data;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
exports.MarketingManager = MarketingManager;
|
|
366
|
+
//# sourceMappingURL=marketing.js.map
|