@the_ro_show/agent-ads-sdk 0.16.0 → 0.16.1
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 +14 -8
- package/dist/index.d.mts +2 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +18 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -176,17 +176,16 @@ const client = new AttentionMarketClient({
|
|
|
176
176
|
|
|
177
177
|
```typescript
|
|
178
178
|
const client = new AttentionMarketClient({
|
|
179
|
-
apiKey: 'am_live_YOUR_KEY',
|
|
180
|
-
agentId: 'agt_YOUR_AGENT_ID',
|
|
181
|
-
supabaseAnonKey: 'YOUR_ANON_KEY', // Required: Get from dashboard
|
|
179
|
+
apiKey: 'am_live_YOUR_KEY', // Required: Your AttentionMarket API key
|
|
180
|
+
agentId: 'agt_YOUR_AGENT_ID', // Required for decideFromContext()
|
|
182
181
|
// baseUrl defaults to production Supabase endpoint
|
|
183
182
|
// Only override if self-hosting or using different environment
|
|
184
|
-
timeoutMs: 4000,
|
|
185
|
-
maxRetries: 2
|
|
183
|
+
timeoutMs: 4000, // Optional: request timeout in milliseconds
|
|
184
|
+
maxRetries: 2 // Optional: automatic retry count
|
|
186
185
|
});
|
|
187
186
|
```
|
|
188
187
|
|
|
189
|
-
**Note:**
|
|
188
|
+
**Note:** Get your API key and agent ID from your [developer dashboard](https://api.attentionmarket.ai).
|
|
190
189
|
|
|
191
190
|
## Core Concepts
|
|
192
191
|
|
|
@@ -550,13 +549,20 @@ Clicks are automatically and securely tracked when users visit the `click_url`.
|
|
|
550
549
|
**Important:** Always use the provided `click_url` or `tracking_url` for click tracking. These URLs contain HMAC-signed tokens that prevent click fraud and ensure accurate attribution.
|
|
551
550
|
|
|
552
551
|
```typescript
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
import { sanitizeURL } from '@the_ro_show/agent-ads-sdk';
|
|
553
|
+
|
|
554
|
+
// When user clicks the ad, sanitize URL for security
|
|
555
|
+
const safeURL = sanitizeURL(ad.click_url);
|
|
556
|
+
if (safeURL) {
|
|
557
|
+
window.location.href = safeURL;
|
|
558
|
+
}
|
|
555
559
|
|
|
556
560
|
// Or in a chat/messaging context, share:
|
|
557
561
|
const shareableLink = ad.tracking_url;
|
|
558
562
|
```
|
|
559
563
|
|
|
564
|
+
**Security Note:** While our backend validates all URLs, it's recommended to use the `sanitizeURL()` helper to protect against potential XSS attacks if the backend is ever compromised or misconfigured.
|
|
565
|
+
|
|
560
566
|
Manual click tracking has been removed for security reasons. All clicks must go through the redirect URLs to ensure fraud prevention and accurate tracking.
|
|
561
567
|
|
|
562
568
|
### Conversion Tracking
|
package/dist/index.d.mts
CHANGED
|
@@ -82,7 +82,8 @@ interface DecideFromContextRequest {
|
|
|
82
82
|
placement?: PlacementType;
|
|
83
83
|
/**
|
|
84
84
|
* Optional category hint (e.g., 'legal', 'insurance', 'travel').
|
|
85
|
-
*
|
|
85
|
+
* Defaults to 'general.query'. Only used as fallback - semantic matching
|
|
86
|
+
* uses conversation context, not taxonomy.
|
|
86
87
|
*/
|
|
87
88
|
suggestedCategory?: string;
|
|
88
89
|
/** User's country code. Default: 'US' */
|
|
@@ -850,11 +851,6 @@ declare class AttentionMarketClient {
|
|
|
850
851
|
private agentId;
|
|
851
852
|
private appId;
|
|
852
853
|
constructor(config: SDKConfig);
|
|
853
|
-
/**
|
|
854
|
-
* Infer taxonomy from user message using keyword matching
|
|
855
|
-
* Returns best-guess taxonomy based on common patterns
|
|
856
|
-
*/
|
|
857
|
-
private inferTaxonomy;
|
|
858
854
|
/**
|
|
859
855
|
* Validate SDK configuration for security
|
|
860
856
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -82,7 +82,8 @@ interface DecideFromContextRequest {
|
|
|
82
82
|
placement?: PlacementType;
|
|
83
83
|
/**
|
|
84
84
|
* Optional category hint (e.g., 'legal', 'insurance', 'travel').
|
|
85
|
-
*
|
|
85
|
+
* Defaults to 'general.query'. Only used as fallback - semantic matching
|
|
86
|
+
* uses conversation context, not taxonomy.
|
|
86
87
|
*/
|
|
87
88
|
suggestedCategory?: string;
|
|
88
89
|
/** User's country code. Default: 'US' */
|
|
@@ -850,11 +851,6 @@ declare class AttentionMarketClient {
|
|
|
850
851
|
private agentId;
|
|
851
852
|
private appId;
|
|
852
853
|
constructor(config: SDKConfig);
|
|
853
|
-
/**
|
|
854
|
-
* Infer taxonomy from user message using keyword matching
|
|
855
|
-
* Returns best-guess taxonomy based on common patterns
|
|
856
|
-
*/
|
|
857
|
-
private inferTaxonomy;
|
|
858
854
|
/**
|
|
859
855
|
* Validate SDK configuration for security
|
|
860
856
|
*/
|
package/dist/index.js
CHANGED
|
@@ -516,59 +516,6 @@ var AttentionMarketClient = class {
|
|
|
516
516
|
}
|
|
517
517
|
this.http = new HTTPClient(httpConfig);
|
|
518
518
|
}
|
|
519
|
-
/**
|
|
520
|
-
* Infer taxonomy from user message using keyword matching
|
|
521
|
-
* Returns best-guess taxonomy based on common patterns
|
|
522
|
-
*/
|
|
523
|
-
inferTaxonomy(userMessage) {
|
|
524
|
-
const msg = userMessage.toLowerCase();
|
|
525
|
-
if (msg.match(/\b(ecommerce|e-commerce|online store|shopify|sell products?|product brand)\b/)) {
|
|
526
|
-
return "business.ecommerce.platform.trial";
|
|
527
|
-
}
|
|
528
|
-
if (msg.match(/\b(start.*business|launch.*business|business formation|llc|incorporate)\b/)) {
|
|
529
|
-
return "business.ecommerce.platform.trial";
|
|
530
|
-
}
|
|
531
|
-
if (msg.match(/\b(car insurance|auto insurance|vehicle insurance)\b/)) {
|
|
532
|
-
return "insurance.auto.full_coverage.quote";
|
|
533
|
-
}
|
|
534
|
-
if (msg.match(/\b(health insurance|medical insurance)\b/)) {
|
|
535
|
-
return "insurance.health.individual.quote";
|
|
536
|
-
}
|
|
537
|
-
if (msg.match(/\b(life insurance)\b/)) {
|
|
538
|
-
return "insurance.life.term.quote";
|
|
539
|
-
}
|
|
540
|
-
if (msg.match(/\b(insurance)\b/)) {
|
|
541
|
-
return "insurance.auto.full_coverage.quote";
|
|
542
|
-
}
|
|
543
|
-
if (msg.match(/\b(personal loan|debt consolidation|borrow money)\b/)) {
|
|
544
|
-
return "finance.loans.personal.apply";
|
|
545
|
-
}
|
|
546
|
-
if (msg.match(/\b(credit card)\b/)) {
|
|
547
|
-
return "finance.credit_cards.rewards.apply";
|
|
548
|
-
}
|
|
549
|
-
if (msg.match(/\b(mover?s?|moving|relocat(e|ing))\b/)) {
|
|
550
|
-
return "home_services.moving.local.quote";
|
|
551
|
-
}
|
|
552
|
-
if (msg.match(/\b(plumber|plumbing|leak|pipe)\b/)) {
|
|
553
|
-
return "home_services.plumbing.emergency.quote";
|
|
554
|
-
}
|
|
555
|
-
if (msg.match(/\b(electrician|electrical|wiring)\b/)) {
|
|
556
|
-
return "home_services.electrical.repair.quote";
|
|
557
|
-
}
|
|
558
|
-
if (msg.match(/\b(clean(ing|er)|maid service)\b/)) {
|
|
559
|
-
return "home_services.cleaning.regular.book";
|
|
560
|
-
}
|
|
561
|
-
if (msg.match(/\b(hotel|lodging|accommodation)\b/)) {
|
|
562
|
-
return "travel.hotels.luxury.book";
|
|
563
|
-
}
|
|
564
|
-
if (msg.match(/\b(flight|plane ticket|airfare)\b/)) {
|
|
565
|
-
return "travel.flights.domestic.book";
|
|
566
|
-
}
|
|
567
|
-
if (msg.match(/\b(lawyer|attorney|legal help)\b/)) {
|
|
568
|
-
return "legal.general.consultation";
|
|
569
|
-
}
|
|
570
|
-
return "business.ecommerce.platform.trial";
|
|
571
|
-
}
|
|
572
519
|
/**
|
|
573
520
|
* Validate SDK configuration for security
|
|
574
521
|
*/
|
|
@@ -652,7 +599,7 @@ var AttentionMarketClient = class {
|
|
|
652
599
|
const language = params.language || "en";
|
|
653
600
|
const platform = params.platform || "web";
|
|
654
601
|
const placementType = params.placement || "sponsored_suggestion";
|
|
655
|
-
const taxonomy = params.suggestedCategory ||
|
|
602
|
+
const taxonomy = params.suggestedCategory || "general.query";
|
|
656
603
|
if (params.minQualityScore !== void 0) {
|
|
657
604
|
if (typeof params.minQualityScore !== "number" || params.minQualityScore < 0 || params.minQualityScore > 1) {
|
|
658
605
|
throw new Error("minQualityScore must be a number between 0.0 and 1.0");
|
|
@@ -707,6 +654,11 @@ var AttentionMarketClient = class {
|
|
|
707
654
|
if (params.optimizeFor && params.optimizeFor !== "revenue" && params.optimizeFor !== "relevance") {
|
|
708
655
|
throw new Error('optimizeFor must be either "revenue" or "relevance"');
|
|
709
656
|
}
|
|
657
|
+
const validFormats = ["minimal", "standard", "verbose"];
|
|
658
|
+
const responseFormat = params.response_format || "minimal";
|
|
659
|
+
if (!validFormats.includes(responseFormat)) {
|
|
660
|
+
throw new Error(`response_format must be one of: ${validFormats.join(", ")}. Got: ${responseFormat}`);
|
|
661
|
+
}
|
|
710
662
|
const request = {
|
|
711
663
|
request_id: generateUUID(),
|
|
712
664
|
agent_id: this.agentId,
|
|
@@ -735,7 +687,7 @@ var AttentionMarketClient = class {
|
|
|
735
687
|
context,
|
|
736
688
|
user_intent: params.userMessage,
|
|
737
689
|
// Use minimal response format by default for better performance
|
|
738
|
-
response_format:
|
|
690
|
+
response_format: responseFormat,
|
|
739
691
|
// === Smart Context Fields (v0.15.0) ===
|
|
740
692
|
// Include user context if we have any data
|
|
741
693
|
...(interests.length > 0 || recentTopics.length > 0 || purchaseIntent) && {
|
|
@@ -778,7 +730,11 @@ var AttentionMarketClient = class {
|
|
|
778
730
|
tracking_token: response.tracking_token
|
|
779
731
|
});
|
|
780
732
|
} catch (error) {
|
|
781
|
-
console.
|
|
733
|
+
console.error("[AttentionMarket] REVENUE RISK: Failed to auto-track impression. Clicks without impressions will NOT earn revenue.", {
|
|
734
|
+
error: error instanceof Error ? error.message : String(error),
|
|
735
|
+
tracking_token: response.tracking_token,
|
|
736
|
+
unit_id: response["_meta"]?.["unit_id"]
|
|
737
|
+
});
|
|
782
738
|
}
|
|
783
739
|
}
|
|
784
740
|
const adResponse2 = {
|
|
@@ -823,7 +779,11 @@ var AttentionMarketClient = class {
|
|
|
823
779
|
tracking_token: adUnit.tracking.token
|
|
824
780
|
});
|
|
825
781
|
} catch (error) {
|
|
826
|
-
console.
|
|
782
|
+
console.error("[AttentionMarket] REVENUE RISK: Failed to auto-track impression. Clicks without impressions will NOT earn revenue.", {
|
|
783
|
+
error: error instanceof Error ? error.message : String(error),
|
|
784
|
+
tracking_token: adUnit.tracking.token,
|
|
785
|
+
unit_id: adUnit.unit_id
|
|
786
|
+
});
|
|
827
787
|
}
|
|
828
788
|
const adResponse = {
|
|
829
789
|
request_id: response.request_id,
|
|
@@ -1173,7 +1133,7 @@ var AttentionMarketClient = class {
|
|
|
1173
1133
|
const context = contextParts.join("\n");
|
|
1174
1134
|
const country = params.context?.geo?.country || "US";
|
|
1175
1135
|
const language = this.normalizeLocale(params.context?.locale);
|
|
1176
|
-
const taxonomy = params.suggestedCategory || "
|
|
1136
|
+
const taxonomy = params.suggestedCategory || "general.query";
|
|
1177
1137
|
const idempotencyKey = options?.idempotencyKey || generateUUID();
|
|
1178
1138
|
const request = {
|
|
1179
1139
|
request_id: idempotencyKey,
|