@the_ro_show/agent-ads-sdk 0.4.1 → 0.4.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 +10 -1
- package/SIMPLE_INTEGRATION_GUIDE.md +11 -16
- package/dist/index.d.mts +183 -1
- package/dist/index.d.ts +183 -1
- package/dist/index.js +192 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# AttentionMarket Agent Ads SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@the_ro_show/agent-ads-sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
**The first ad network built for AI agents.** Monetize your AI agent with contextual, high-intent sponsored suggestions. Open source, transparent, developer-first.
|
|
8
|
+
|
|
9
|
+
- 🚀 **5-minute integration** - npm install + 5 lines of code
|
|
10
|
+
- 💰 **70% revenue share** - You keep the majority, we only win when you do
|
|
11
|
+
- 🎯 **10-15% CTR** - High-intent placements, not banner ads
|
|
12
|
+
- 🔓 **100% Open Source** - Audit every line, full transparency
|
|
4
13
|
|
|
5
14
|
## Quick Start
|
|
6
15
|
|
|
@@ -7,26 +7,19 @@ Your bot answers user questions. Sometimes those answers could include a helpful
|
|
|
7
7
|
|
|
8
8
|
## Step-by-Step Guide
|
|
9
9
|
|
|
10
|
-
### **Step 1: Sign Up for API Keys** (One-time,
|
|
10
|
+
### **Step 1: Sign Up for API Keys** (One-time, 30 seconds)
|
|
11
11
|
|
|
12
12
|
You need permission to request ads. Think of this like getting a key to a vending machine.
|
|
13
13
|
|
|
14
14
|
**How to do it:**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-H 'Content-Type: application/json' \
|
|
19
|
-
-d '{
|
|
20
|
-
"owner_email": "your-email@example.com",
|
|
21
|
-
"agent_name": "My Cool Bot",
|
|
22
|
-
"sdk_type": "typescript"
|
|
23
|
-
}'
|
|
24
|
-
```
|
|
15
|
+
1. Go to **[attentionmarket.com/signup](https://attentionmarket.com/signup)**
|
|
16
|
+
2. Enter your email and agent name
|
|
17
|
+
3. Click "Generate API Keys"
|
|
25
18
|
|
|
26
19
|
**You'll get back:**
|
|
27
|
-
- An **Agent ID** (like `agt_abc123`) - your username
|
|
28
20
|
- A **Test Key** (like `am_test_xyz789`) - for testing
|
|
29
21
|
- A **Live Key** (like `am_live_xyz789`) - for when you go live
|
|
22
|
+
- An **Agent ID** (you'll use this for tracking)
|
|
30
23
|
|
|
31
24
|
**Write these down!** You'll need them.
|
|
32
25
|
|
|
@@ -96,7 +89,7 @@ async function handleUserMessage(userMessage) {
|
|
|
96
89
|
surface: 'chat'
|
|
97
90
|
},
|
|
98
91
|
opportunity: createOpportunity({
|
|
99
|
-
taxonomy: '
|
|
92
|
+
taxonomy: 'business.ecommerce.platform.trial', // E-commerce platforms
|
|
100
93
|
country: 'US',
|
|
101
94
|
language: 'en',
|
|
102
95
|
platform: 'web',
|
|
@@ -204,8 +197,10 @@ await adClient.trackClick({
|
|
|
204
197
|
|
|
205
198
|
### **Taxonomy** = Topic Category
|
|
206
199
|
When you request an ad, you tell us what the user is asking about:
|
|
207
|
-
- `
|
|
208
|
-
- `
|
|
200
|
+
- `business.ecommerce.platform.trial` = Online store questions
|
|
201
|
+
- `home_services.moving.local.quote` = Moving company questions
|
|
202
|
+
- `insurance.auto.full_coverage.quote` = Car insurance questions
|
|
203
|
+
- `legal.family.divorce.consultation` = Divorce lawyer questions
|
|
209
204
|
- `business.productivity.tools` = Productivity software questions
|
|
210
205
|
|
|
211
206
|
**You pick the taxonomy** based on what the user asked.
|
|
@@ -255,7 +250,7 @@ async function handleMessage(userMessage) {
|
|
|
255
250
|
agent_id: process.env.ATTENTIONMARKET_AGENT_ID,
|
|
256
251
|
placement: { type: 'sponsored_suggestion', surface: 'chat' },
|
|
257
252
|
opportunity: createOpportunity({
|
|
258
|
-
taxonomy: '
|
|
253
|
+
taxonomy: 'business.ecommerce.platform.trial',
|
|
259
254
|
country: 'US',
|
|
260
255
|
language: 'en',
|
|
261
256
|
platform: 'web',
|
package/dist/index.d.mts
CHANGED
|
@@ -21,6 +21,48 @@ interface DecideRequest {
|
|
|
21
21
|
agent_id: string;
|
|
22
22
|
placement: Placement;
|
|
23
23
|
opportunity: Opportunity;
|
|
24
|
+
/** Full conversation context for semantic matching (optional) */
|
|
25
|
+
context?: string;
|
|
26
|
+
/** Detected or inferred user intent for semantic matching (optional) */
|
|
27
|
+
user_intent?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Simplified request for semantic context-based ad matching.
|
|
31
|
+
* Uses conversation context instead of manual taxonomy selection.
|
|
32
|
+
*
|
|
33
|
+
* The SDK automatically limits conversationHistory to the last 5 messages
|
|
34
|
+
* to avoid token overflow. Only userMessage is required.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const ad = await client.decideFromContext({
|
|
39
|
+
* userMessage: "I need help with estate planning",
|
|
40
|
+
* conversationHistory: ["User: My father passed away recently"],
|
|
41
|
+
* placement: 'sponsored_suggestion'
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
interface DecideFromContextRequest {
|
|
46
|
+
/** The user's current message (required) */
|
|
47
|
+
userMessage: string;
|
|
48
|
+
/**
|
|
49
|
+
* Optional conversation history (last few messages for context).
|
|
50
|
+
* SDK automatically limits to last 5 messages to avoid token overflow.
|
|
51
|
+
*/
|
|
52
|
+
conversationHistory?: string[];
|
|
53
|
+
/** Ad placement type. Default: 'sponsored_suggestion' */
|
|
54
|
+
placement?: PlacementType;
|
|
55
|
+
/**
|
|
56
|
+
* Optional category hint (e.g., 'legal', 'insurance', 'travel').
|
|
57
|
+
* Used as fallback if semantic matching fails.
|
|
58
|
+
*/
|
|
59
|
+
suggestedCategory?: string;
|
|
60
|
+
/** User's country code. Default: 'US' */
|
|
61
|
+
country?: string;
|
|
62
|
+
/** User's language code. Default: 'en' */
|
|
63
|
+
language?: string;
|
|
64
|
+
/** User's platform. Default: 'web' */
|
|
65
|
+
platform?: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
|
|
24
66
|
}
|
|
25
67
|
interface DecideResponse {
|
|
26
68
|
request_id: string;
|
|
@@ -154,6 +196,7 @@ interface APIError {
|
|
|
154
196
|
}
|
|
155
197
|
interface SDKConfig {
|
|
156
198
|
apiKey: string;
|
|
199
|
+
agentId?: string;
|
|
157
200
|
supabaseAnonKey?: string;
|
|
158
201
|
baseUrl?: string;
|
|
159
202
|
timeoutMs?: number;
|
|
@@ -313,6 +356,7 @@ declare function sanitizeURL(url: string | null | undefined, options?: SanitizeU
|
|
|
313
356
|
|
|
314
357
|
declare class AttentionMarketClient {
|
|
315
358
|
private http;
|
|
359
|
+
private agentId;
|
|
316
360
|
constructor(config: SDKConfig);
|
|
317
361
|
/**
|
|
318
362
|
* Validate SDK configuration for security
|
|
@@ -332,6 +376,23 @@ declare class AttentionMarketClient {
|
|
|
332
376
|
decide(request: DecideRequest, options?: {
|
|
333
377
|
idempotencyKey?: string;
|
|
334
378
|
}): Promise<AdUnit | null>;
|
|
379
|
+
/**
|
|
380
|
+
* Simplified ad matching using conversation context and semantic search.
|
|
381
|
+
* Automatically handles request construction, taxonomy fallback, and defaults.
|
|
382
|
+
*
|
|
383
|
+
* Requires: agentId in SDKConfig constructor
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* const ad = await client.decideFromContext({
|
|
387
|
+
* userMessage: "My father passed away and I need help organizing his estate",
|
|
388
|
+
* placement: 'sponsored_suggestion'
|
|
389
|
+
* });
|
|
390
|
+
*
|
|
391
|
+
* @throws {Error} If agentId was not provided in SDKConfig
|
|
392
|
+
*/
|
|
393
|
+
decideFromContext(params: DecideFromContextRequest, options?: {
|
|
394
|
+
idempotencyKey?: string;
|
|
395
|
+
}): Promise<AdUnit | null>;
|
|
335
396
|
/**
|
|
336
397
|
* Report an event (impression, click, action, conversion, feedback).
|
|
337
398
|
*/
|
|
@@ -487,6 +548,127 @@ declare class TimeoutError extends AttentionMarketError {
|
|
|
487
548
|
constructor(message?: string);
|
|
488
549
|
}
|
|
489
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Natural ad formatting utilities
|
|
553
|
+
*
|
|
554
|
+
* Transforms ad copy to feel more conversational while preserving
|
|
555
|
+
* all tracking data and disclosure requirements.
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
interface NaturalFormatOptions {
|
|
559
|
+
/**
|
|
560
|
+
* Tone/style for the formatted text
|
|
561
|
+
* - 'conversational': Friendly, natural language
|
|
562
|
+
* - 'helpful': Informative assistant tone
|
|
563
|
+
* - 'direct': Clear and concise
|
|
564
|
+
*/
|
|
565
|
+
style?: 'conversational' | 'helpful' | 'direct';
|
|
566
|
+
/**
|
|
567
|
+
* Optional user context to make formatting more relevant
|
|
568
|
+
* Example: "User is looking for estate planning help"
|
|
569
|
+
*/
|
|
570
|
+
userContext?: string;
|
|
571
|
+
/**
|
|
572
|
+
* Maximum length for formatted text (characters)
|
|
573
|
+
* Will truncate gracefully if needed
|
|
574
|
+
*/
|
|
575
|
+
maxLength?: number;
|
|
576
|
+
/**
|
|
577
|
+
* Whether to include the disclosure inline
|
|
578
|
+
* Default: true (always show sponsored label)
|
|
579
|
+
*/
|
|
580
|
+
includeDisclosure?: boolean;
|
|
581
|
+
}
|
|
582
|
+
interface FormattedAd {
|
|
583
|
+
/**
|
|
584
|
+
* Naturally formatted text suitable for conversation
|
|
585
|
+
*/
|
|
586
|
+
text: string;
|
|
587
|
+
/**
|
|
588
|
+
* Call-to-action text
|
|
589
|
+
*/
|
|
590
|
+
cta: string;
|
|
591
|
+
/**
|
|
592
|
+
* Action URL (preserved from original ad)
|
|
593
|
+
*/
|
|
594
|
+
actionUrl: string;
|
|
595
|
+
/**
|
|
596
|
+
* Tracking data (preserved from original ad)
|
|
597
|
+
* IMPORTANT: Pass this to trackClick() when user clicks
|
|
598
|
+
*/
|
|
599
|
+
tracking: {
|
|
600
|
+
eventId: string;
|
|
601
|
+
trackingToken: string;
|
|
602
|
+
decisionId: string;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Disclosure information (preserved from original ad)
|
|
606
|
+
*/
|
|
607
|
+
disclosure: {
|
|
608
|
+
label: string;
|
|
609
|
+
sponsorName: string;
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Format an ad unit into natural conversational text.
|
|
614
|
+
* Preserves all tracking data and disclosure requirements.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* const ad = await client.decide({...});
|
|
619
|
+
* const formatted = formatNatural(ad, {
|
|
620
|
+
* style: 'conversational',
|
|
621
|
+
* userContext: "User needs estate planning help"
|
|
622
|
+
* });
|
|
623
|
+
*
|
|
624
|
+
* console.log(formatted.text);
|
|
625
|
+
* // "I found a service that might help: [Title]. [Body]"
|
|
626
|
+
*
|
|
627
|
+
* // When user clicks, tracking still works:
|
|
628
|
+
* await client.trackClick({
|
|
629
|
+
* event_id: formatted.tracking.eventId,
|
|
630
|
+
* tracking_token: formatted.tracking.trackingToken
|
|
631
|
+
* });
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
declare function formatNatural(ad: AdUnit, options?: NaturalFormatOptions): FormattedAd;
|
|
635
|
+
/**
|
|
636
|
+
* Extract just the essential info from an ad for inline mentions.
|
|
637
|
+
* Useful when you want to reference an ad without showing the full text.
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```typescript
|
|
641
|
+
* const mention = formatInlineMention(ad);
|
|
642
|
+
* console.log(`You might want to check out ${mention.text}`);
|
|
643
|
+
* // "You might want to check out Estate Planning Services (Sponsored)"
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
declare function formatInlineMention(ad: AdUnit): FormattedAd;
|
|
647
|
+
/**
|
|
648
|
+
* Validate that an ad fits within UI constraints.
|
|
649
|
+
* Helps developers check if ad will display correctly before showing it.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const validation = validateAdFits(ad, {
|
|
654
|
+
* maxTitleChars: 60,
|
|
655
|
+
* maxBodyChars: 200
|
|
656
|
+
* });
|
|
657
|
+
*
|
|
658
|
+
* if (!validation.fits) {
|
|
659
|
+
* console.log('Ad too long:', validation.violations);
|
|
660
|
+
* }
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
declare function validateAdFits(ad: AdUnit, constraints: {
|
|
664
|
+
maxTitleChars?: number;
|
|
665
|
+
maxBodyChars?: number;
|
|
666
|
+
maxCtaChars?: number;
|
|
667
|
+
}): {
|
|
668
|
+
fits: boolean;
|
|
669
|
+
violations: string[];
|
|
670
|
+
};
|
|
671
|
+
|
|
490
672
|
/**
|
|
491
673
|
* Taxonomy helper utilities for AttentionMarket SDK
|
|
492
674
|
* Helps with building, validating, and working with the 4-tier taxonomy system
|
|
@@ -644,4 +826,4 @@ declare function getVertical(taxonomy: string): string | null;
|
|
|
644
826
|
*/
|
|
645
827
|
declare function suggestTaxonomies(query: string): string[];
|
|
646
828
|
|
|
647
|
-
export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type Intent, MockAttentionMarketClient, type MockClientConfig, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies };
|
|
829
|
+
export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideFromContextRequest, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type FormattedAd, type Intent, MockAttentionMarketClient, type MockClientConfig, type NaturalFormatOptions, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, formatInlineMention, formatNatural, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies, validateAdFits };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,48 @@ interface DecideRequest {
|
|
|
21
21
|
agent_id: string;
|
|
22
22
|
placement: Placement;
|
|
23
23
|
opportunity: Opportunity;
|
|
24
|
+
/** Full conversation context for semantic matching (optional) */
|
|
25
|
+
context?: string;
|
|
26
|
+
/** Detected or inferred user intent for semantic matching (optional) */
|
|
27
|
+
user_intent?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Simplified request for semantic context-based ad matching.
|
|
31
|
+
* Uses conversation context instead of manual taxonomy selection.
|
|
32
|
+
*
|
|
33
|
+
* The SDK automatically limits conversationHistory to the last 5 messages
|
|
34
|
+
* to avoid token overflow. Only userMessage is required.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const ad = await client.decideFromContext({
|
|
39
|
+
* userMessage: "I need help with estate planning",
|
|
40
|
+
* conversationHistory: ["User: My father passed away recently"],
|
|
41
|
+
* placement: 'sponsored_suggestion'
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
interface DecideFromContextRequest {
|
|
46
|
+
/** The user's current message (required) */
|
|
47
|
+
userMessage: string;
|
|
48
|
+
/**
|
|
49
|
+
* Optional conversation history (last few messages for context).
|
|
50
|
+
* SDK automatically limits to last 5 messages to avoid token overflow.
|
|
51
|
+
*/
|
|
52
|
+
conversationHistory?: string[];
|
|
53
|
+
/** Ad placement type. Default: 'sponsored_suggestion' */
|
|
54
|
+
placement?: PlacementType;
|
|
55
|
+
/**
|
|
56
|
+
* Optional category hint (e.g., 'legal', 'insurance', 'travel').
|
|
57
|
+
* Used as fallback if semantic matching fails.
|
|
58
|
+
*/
|
|
59
|
+
suggestedCategory?: string;
|
|
60
|
+
/** User's country code. Default: 'US' */
|
|
61
|
+
country?: string;
|
|
62
|
+
/** User's language code. Default: 'en' */
|
|
63
|
+
language?: string;
|
|
64
|
+
/** User's platform. Default: 'web' */
|
|
65
|
+
platform?: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
|
|
24
66
|
}
|
|
25
67
|
interface DecideResponse {
|
|
26
68
|
request_id: string;
|
|
@@ -154,6 +196,7 @@ interface APIError {
|
|
|
154
196
|
}
|
|
155
197
|
interface SDKConfig {
|
|
156
198
|
apiKey: string;
|
|
199
|
+
agentId?: string;
|
|
157
200
|
supabaseAnonKey?: string;
|
|
158
201
|
baseUrl?: string;
|
|
159
202
|
timeoutMs?: number;
|
|
@@ -313,6 +356,7 @@ declare function sanitizeURL(url: string | null | undefined, options?: SanitizeU
|
|
|
313
356
|
|
|
314
357
|
declare class AttentionMarketClient {
|
|
315
358
|
private http;
|
|
359
|
+
private agentId;
|
|
316
360
|
constructor(config: SDKConfig);
|
|
317
361
|
/**
|
|
318
362
|
* Validate SDK configuration for security
|
|
@@ -332,6 +376,23 @@ declare class AttentionMarketClient {
|
|
|
332
376
|
decide(request: DecideRequest, options?: {
|
|
333
377
|
idempotencyKey?: string;
|
|
334
378
|
}): Promise<AdUnit | null>;
|
|
379
|
+
/**
|
|
380
|
+
* Simplified ad matching using conversation context and semantic search.
|
|
381
|
+
* Automatically handles request construction, taxonomy fallback, and defaults.
|
|
382
|
+
*
|
|
383
|
+
* Requires: agentId in SDKConfig constructor
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* const ad = await client.decideFromContext({
|
|
387
|
+
* userMessage: "My father passed away and I need help organizing his estate",
|
|
388
|
+
* placement: 'sponsored_suggestion'
|
|
389
|
+
* });
|
|
390
|
+
*
|
|
391
|
+
* @throws {Error} If agentId was not provided in SDKConfig
|
|
392
|
+
*/
|
|
393
|
+
decideFromContext(params: DecideFromContextRequest, options?: {
|
|
394
|
+
idempotencyKey?: string;
|
|
395
|
+
}): Promise<AdUnit | null>;
|
|
335
396
|
/**
|
|
336
397
|
* Report an event (impression, click, action, conversion, feedback).
|
|
337
398
|
*/
|
|
@@ -487,6 +548,127 @@ declare class TimeoutError extends AttentionMarketError {
|
|
|
487
548
|
constructor(message?: string);
|
|
488
549
|
}
|
|
489
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Natural ad formatting utilities
|
|
553
|
+
*
|
|
554
|
+
* Transforms ad copy to feel more conversational while preserving
|
|
555
|
+
* all tracking data and disclosure requirements.
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
interface NaturalFormatOptions {
|
|
559
|
+
/**
|
|
560
|
+
* Tone/style for the formatted text
|
|
561
|
+
* - 'conversational': Friendly, natural language
|
|
562
|
+
* - 'helpful': Informative assistant tone
|
|
563
|
+
* - 'direct': Clear and concise
|
|
564
|
+
*/
|
|
565
|
+
style?: 'conversational' | 'helpful' | 'direct';
|
|
566
|
+
/**
|
|
567
|
+
* Optional user context to make formatting more relevant
|
|
568
|
+
* Example: "User is looking for estate planning help"
|
|
569
|
+
*/
|
|
570
|
+
userContext?: string;
|
|
571
|
+
/**
|
|
572
|
+
* Maximum length for formatted text (characters)
|
|
573
|
+
* Will truncate gracefully if needed
|
|
574
|
+
*/
|
|
575
|
+
maxLength?: number;
|
|
576
|
+
/**
|
|
577
|
+
* Whether to include the disclosure inline
|
|
578
|
+
* Default: true (always show sponsored label)
|
|
579
|
+
*/
|
|
580
|
+
includeDisclosure?: boolean;
|
|
581
|
+
}
|
|
582
|
+
interface FormattedAd {
|
|
583
|
+
/**
|
|
584
|
+
* Naturally formatted text suitable for conversation
|
|
585
|
+
*/
|
|
586
|
+
text: string;
|
|
587
|
+
/**
|
|
588
|
+
* Call-to-action text
|
|
589
|
+
*/
|
|
590
|
+
cta: string;
|
|
591
|
+
/**
|
|
592
|
+
* Action URL (preserved from original ad)
|
|
593
|
+
*/
|
|
594
|
+
actionUrl: string;
|
|
595
|
+
/**
|
|
596
|
+
* Tracking data (preserved from original ad)
|
|
597
|
+
* IMPORTANT: Pass this to trackClick() when user clicks
|
|
598
|
+
*/
|
|
599
|
+
tracking: {
|
|
600
|
+
eventId: string;
|
|
601
|
+
trackingToken: string;
|
|
602
|
+
decisionId: string;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Disclosure information (preserved from original ad)
|
|
606
|
+
*/
|
|
607
|
+
disclosure: {
|
|
608
|
+
label: string;
|
|
609
|
+
sponsorName: string;
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Format an ad unit into natural conversational text.
|
|
614
|
+
* Preserves all tracking data and disclosure requirements.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* const ad = await client.decide({...});
|
|
619
|
+
* const formatted = formatNatural(ad, {
|
|
620
|
+
* style: 'conversational',
|
|
621
|
+
* userContext: "User needs estate planning help"
|
|
622
|
+
* });
|
|
623
|
+
*
|
|
624
|
+
* console.log(formatted.text);
|
|
625
|
+
* // "I found a service that might help: [Title]. [Body]"
|
|
626
|
+
*
|
|
627
|
+
* // When user clicks, tracking still works:
|
|
628
|
+
* await client.trackClick({
|
|
629
|
+
* event_id: formatted.tracking.eventId,
|
|
630
|
+
* tracking_token: formatted.tracking.trackingToken
|
|
631
|
+
* });
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
declare function formatNatural(ad: AdUnit, options?: NaturalFormatOptions): FormattedAd;
|
|
635
|
+
/**
|
|
636
|
+
* Extract just the essential info from an ad for inline mentions.
|
|
637
|
+
* Useful when you want to reference an ad without showing the full text.
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```typescript
|
|
641
|
+
* const mention = formatInlineMention(ad);
|
|
642
|
+
* console.log(`You might want to check out ${mention.text}`);
|
|
643
|
+
* // "You might want to check out Estate Planning Services (Sponsored)"
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
declare function formatInlineMention(ad: AdUnit): FormattedAd;
|
|
647
|
+
/**
|
|
648
|
+
* Validate that an ad fits within UI constraints.
|
|
649
|
+
* Helps developers check if ad will display correctly before showing it.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const validation = validateAdFits(ad, {
|
|
654
|
+
* maxTitleChars: 60,
|
|
655
|
+
* maxBodyChars: 200
|
|
656
|
+
* });
|
|
657
|
+
*
|
|
658
|
+
* if (!validation.fits) {
|
|
659
|
+
* console.log('Ad too long:', validation.violations);
|
|
660
|
+
* }
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
declare function validateAdFits(ad: AdUnit, constraints: {
|
|
664
|
+
maxTitleChars?: number;
|
|
665
|
+
maxBodyChars?: number;
|
|
666
|
+
maxCtaChars?: number;
|
|
667
|
+
}): {
|
|
668
|
+
fits: boolean;
|
|
669
|
+
violations: string[];
|
|
670
|
+
};
|
|
671
|
+
|
|
490
672
|
/**
|
|
491
673
|
* Taxonomy helper utilities for AttentionMarket SDK
|
|
492
674
|
* Helps with building, validating, and working with the 4-tier taxonomy system
|
|
@@ -644,4 +826,4 @@ declare function getVertical(taxonomy: string): string | null;
|
|
|
644
826
|
*/
|
|
645
827
|
declare function suggestTaxonomies(query: string): string[];
|
|
646
828
|
|
|
647
|
-
export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type Intent, MockAttentionMarketClient, type MockClientConfig, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies };
|
|
829
|
+
export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideFromContextRequest, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type FormattedAd, type Intent, MockAttentionMarketClient, type MockClientConfig, type NaturalFormatOptions, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, formatInlineMention, formatNatural, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies, validateAdFits };
|