@the_ro_show/agent-ads-sdk 0.15.1 → 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/dist/index.mjs CHANGED
@@ -198,31 +198,6 @@ function createImpressionEvent(params) {
198
198
  }
199
199
  return event;
200
200
  }
201
- function createClickEvent(params) {
202
- const event = {
203
- event_id: generateUUID(),
204
- occurred_at: params.occurred_at ?? generateTimestamp(),
205
- agent_id: params.agent_id,
206
- request_id: params.request_id,
207
- decision_id: params.decision_id,
208
- unit_id: params.unit_id,
209
- event_type: "click",
210
- tracking_token: params.tracking_token
211
- };
212
- if (params.metadata !== void 0) {
213
- event.metadata = {
214
- ...params.metadata,
215
- href: params.href,
216
- click_context: params.click_context
217
- };
218
- } else {
219
- event.metadata = {
220
- href: params.href,
221
- click_context: params.click_context
222
- };
223
- }
224
- return event;
225
- }
226
201
  var HTML_ESCAPES = {
227
202
  "&": "&",
228
203
  "<": "&lt;",
@@ -493,59 +468,6 @@ var AttentionMarketClient = class {
493
468
  }
494
469
  this.http = new HTTPClient(httpConfig);
495
470
  }
496
- /**
497
- * Infer taxonomy from user message using keyword matching
498
- * Returns best-guess taxonomy based on common patterns
499
- */
500
- inferTaxonomy(userMessage) {
501
- const msg = userMessage.toLowerCase();
502
- if (msg.match(/\b(ecommerce|e-commerce|online store|shopify|sell products?|product brand)\b/)) {
503
- return "business.ecommerce.platform.trial";
504
- }
505
- if (msg.match(/\b(start.*business|launch.*business|business formation|llc|incorporate)\b/)) {
506
- return "business.ecommerce.platform.trial";
507
- }
508
- if (msg.match(/\b(car insurance|auto insurance|vehicle insurance)\b/)) {
509
- return "insurance.auto.full_coverage.quote";
510
- }
511
- if (msg.match(/\b(health insurance|medical insurance)\b/)) {
512
- return "insurance.health.individual.quote";
513
- }
514
- if (msg.match(/\b(life insurance)\b/)) {
515
- return "insurance.life.term.quote";
516
- }
517
- if (msg.match(/\b(insurance)\b/)) {
518
- return "insurance.auto.full_coverage.quote";
519
- }
520
- if (msg.match(/\b(personal loan|debt consolidation|borrow money)\b/)) {
521
- return "finance.loans.personal.apply";
522
- }
523
- if (msg.match(/\b(credit card)\b/)) {
524
- return "finance.credit_cards.rewards.apply";
525
- }
526
- if (msg.match(/\b(mover?s?|moving|relocat(e|ing))\b/)) {
527
- return "home_services.moving.local.quote";
528
- }
529
- if (msg.match(/\b(plumber|plumbing|leak|pipe)\b/)) {
530
- return "home_services.plumbing.emergency.quote";
531
- }
532
- if (msg.match(/\b(electrician|electrical|wiring)\b/)) {
533
- return "home_services.electrical.repair.quote";
534
- }
535
- if (msg.match(/\b(clean(ing|er)|maid service)\b/)) {
536
- return "home_services.cleaning.regular.book";
537
- }
538
- if (msg.match(/\b(hotel|lodging|accommodation)\b/)) {
539
- return "travel.hotels.luxury.book";
540
- }
541
- if (msg.match(/\b(flight|plane ticket|airfare)\b/)) {
542
- return "travel.flights.domestic.book";
543
- }
544
- if (msg.match(/\b(lawyer|attorney|legal help)\b/)) {
545
- return "legal.general.consultation";
546
- }
547
- return "business.ecommerce.platform.trial";
548
- }
549
471
  /**
550
472
  * Validate SDK configuration for security
551
473
  */
@@ -629,7 +551,7 @@ var AttentionMarketClient = class {
629
551
  const language = params.language || "en";
630
552
  const platform = params.platform || "web";
631
553
  const placementType = params.placement || "sponsored_suggestion";
632
- const taxonomy = params.suggestedCategory || this.inferTaxonomy(params.userMessage);
554
+ const taxonomy = params.suggestedCategory || "general.query";
633
555
  if (params.minQualityScore !== void 0) {
634
556
  if (typeof params.minQualityScore !== "number" || params.minQualityScore < 0 || params.minQualityScore > 1) {
635
557
  throw new Error("minQualityScore must be a number between 0.0 and 1.0");
@@ -684,6 +606,11 @@ var AttentionMarketClient = class {
684
606
  if (params.optimizeFor && params.optimizeFor !== "revenue" && params.optimizeFor !== "relevance") {
685
607
  throw new Error('optimizeFor must be either "revenue" or "relevance"');
686
608
  }
609
+ const validFormats = ["minimal", "standard", "verbose"];
610
+ const responseFormat = params.response_format || "minimal";
611
+ if (!validFormats.includes(responseFormat)) {
612
+ throw new Error(`response_format must be one of: ${validFormats.join(", ")}. Got: ${responseFormat}`);
613
+ }
687
614
  const request = {
688
615
  request_id: generateUUID(),
689
616
  agent_id: this.agentId,
@@ -712,7 +639,7 @@ var AttentionMarketClient = class {
712
639
  context,
713
640
  user_intent: params.userMessage,
714
641
  // Use minimal response format by default for better performance
715
- response_format: "minimal",
642
+ response_format: responseFormat,
716
643
  // === Smart Context Fields (v0.15.0) ===
717
644
  // Include user context if we have any data
718
645
  ...(interests.length > 0 || recentTopics.length > 0 || purchaseIntent) && {
@@ -755,7 +682,11 @@ var AttentionMarketClient = class {
755
682
  tracking_token: response.tracking_token
756
683
  });
757
684
  } catch (error) {
758
- console.warn("[AttentionMarket] Failed to auto-track impression:", error);
685
+ console.error("[AttentionMarket] REVENUE RISK: Failed to auto-track impression. Clicks without impressions will NOT earn revenue.", {
686
+ error: error instanceof Error ? error.message : String(error),
687
+ tracking_token: response.tracking_token,
688
+ unit_id: response["_meta"]?.["unit_id"]
689
+ });
759
690
  }
760
691
  }
761
692
  const adResponse2 = {
@@ -800,7 +731,11 @@ var AttentionMarketClient = class {
800
731
  tracking_token: adUnit.tracking.token
801
732
  });
802
733
  } catch (error) {
803
- console.warn("[AttentionMarket] Failed to auto-track impression:", error);
734
+ console.error("[AttentionMarket] REVENUE RISK: Failed to auto-track impression. Clicks without impressions will NOT earn revenue.", {
735
+ error: error instanceof Error ? error.message : String(error),
736
+ tracking_token: adUnit.tracking.token,
737
+ unit_id: adUnit.unit_id
738
+ });
804
739
  }
805
740
  const adResponse = {
806
741
  request_id: response.request_id,
@@ -848,52 +783,6 @@ var AttentionMarketClient = class {
848
783
  const event = createImpressionEvent(params);
849
784
  return await this.track(event);
850
785
  }
851
- /**
852
- * Convenience method to track a click event.
853
- * Creates a click event using createClickEvent() and calls track().
854
- */
855
- async trackClick(params) {
856
- const event = createClickEvent(params);
857
- return await this.track(event);
858
- }
859
- /**
860
- * Ultra-simple method to track a click from an ad returned by decideFromContext().
861
- * Automatically extracts all required fields from the ad object.
862
- *
863
- * @param ad - The ad object returned by decideFromContext()
864
- * @param options - Just click_context (what you showed the user)
865
- *
866
- * @example
867
- * ```typescript
868
- * const ad = await client.decideFromContext({ userMessage: "I need car insurance" });
869
- * if (ad) {
870
- * await client.trackClickFromAd(ad, {
871
- * click_context: "Progressive: Get 20% off - Compare quotes"
872
- * });
873
- * }
874
- * ```
875
- */
876
- async trackClickFromAd(ad, options) {
877
- if (!this.agentId) {
878
- throw new Error("agentId is required for trackClickFromAd(). Set it in the constructor.");
879
- }
880
- const trackParams = {
881
- agent_id: this.agentId,
882
- request_id: ad.request_id,
883
- decision_id: ad.decision_id,
884
- unit_id: ad._ad.unit_id,
885
- tracking_token: ad.tracking_token,
886
- href: ad.click_url,
887
- click_context: options.click_context
888
- };
889
- if (options.metadata) {
890
- trackParams.metadata = options.metadata;
891
- }
892
- if (options.occurred_at) {
893
- trackParams.occurred_at = options.occurred_at;
894
- }
895
- return await this.trackClick(trackParams);
896
- }
897
786
  /**
898
787
  * Send feedback on an ad's performance to earn conversion-validated bonuses.
899
788
  *
@@ -1196,7 +1085,7 @@ var AttentionMarketClient = class {
1196
1085
  const context = contextParts.join("\n");
1197
1086
  const country = params.context?.geo?.country || "US";
1198
1087
  const language = this.normalizeLocale(params.context?.locale);
1199
- const taxonomy = params.suggestedCategory || "unknown";
1088
+ const taxonomy = params.suggestedCategory || "general.query";
1200
1089
  const idempotencyKey = options?.idempotencyKey || generateUUID();
1201
1090
  const request = {
1202
1091
  request_id: idempotencyKey,
@@ -2007,7 +1896,6 @@ export {
2007
1896
  NetworkError,
2008
1897
  TimeoutError,
2009
1898
  buildTaxonomy,
2010
- createClickEvent,
2011
1899
  createImpressionEvent,
2012
1900
  createOpportunity,
2013
1901
  detectIntent,