@the_ro_show/agent-ads-sdk 0.13.3 → 0.14.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/index.mjs CHANGED
@@ -419,7 +419,7 @@ var AttentionMarketClient = class {
419
419
  if (response.status === "no_fill") {
420
420
  return null;
421
421
  }
422
- return response.units[0] ?? null;
422
+ return response.units?.[0] ?? null;
423
423
  }
424
424
  /**
425
425
  * Simplified ad matching using conversation context and semantic search.
@@ -535,6 +535,8 @@ var AttentionMarketClient = class {
535
535
  },
536
536
  context,
537
537
  user_intent: params.userMessage,
538
+ // Use minimal response format by default for better performance
539
+ response_format: "minimal",
538
540
  // Developer controls (Phase 1: Quality & Brand Safety)
539
541
  ...params.minQualityScore !== void 0 && { minQualityScore: params.minQualityScore },
540
542
  ...params.allowedCategories && { allowedCategories: params.allowedCategories },
@@ -546,7 +548,43 @@ var AttentionMarketClient = class {
546
548
  ...params.optimizeFor && { optimizeFor: params.optimizeFor }
547
549
  };
548
550
  const response = await this.decideRaw(request, options);
549
- if (response.status === "no_fill" || response.units.length === 0) {
551
+ if (response.creative) {
552
+ try {
553
+ await this.track({
554
+ event_id: `evt_${generateUUID()}`,
555
+ event_type: "impression",
556
+ occurred_at: (/* @__PURE__ */ new Date()).toISOString(),
557
+ agent_id: this.agentId,
558
+ tracking_token: response.tracking_token
559
+ });
560
+ } catch (error) {
561
+ console.warn("[AttentionMarket] Failed to auto-track impression:", error);
562
+ }
563
+ const adResponse2 = {
564
+ request_id: request.request_id,
565
+ decision_id: `dec_${generateUUID()}`,
566
+ advertiser_id: response.advertiser_id || "",
567
+ ad_type: "link",
568
+ payout: response.payout || 0,
569
+ creative: response.creative,
570
+ click_url: response.click_url || "",
571
+ tracking_url: response.click_url || "",
572
+ // Same as click_url
573
+ tracking_token: response.tracking_token || "",
574
+ disclosure: response.disclosure || {
575
+ label: "Sponsored",
576
+ explanation: "This is a paid advertisement",
577
+ sponsor_name: "Advertiser"
578
+ },
579
+ // Internal fields preserved for backward compatibility
580
+ _ad: {
581
+ unit_id: "",
582
+ tracking: { token: response.tracking_token || "" }
583
+ }
584
+ };
585
+ return adResponse2;
586
+ }
587
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
550
588
  return null;
551
589
  }
552
590
  const adUnit = response.units[0];
@@ -859,7 +897,7 @@ var AttentionMarketClient = class {
859
897
  user_intent: params.intentKey
860
898
  };
861
899
  const response = await this.decideRaw(request, { idempotencyKey });
862
- if (response.status === "no_fill" || response.units.length === 0) {
900
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
863
901
  return null;
864
902
  }
865
903
  const adUnit = response.units[0];
@@ -870,7 +908,7 @@ var AttentionMarketClient = class {
870
908
  const matchMethod = semanticContext ? "hybrid" : "semantic";
871
909
  return {
872
910
  offer_id: adUnit.unit_id,
873
- request_id: response.request_id,
911
+ request_id: response.request_id || "",
874
912
  impression_id: impressionId,
875
913
  // LIMITATION: Backend doesn't return campaign_id yet - use unit_id as placeholder
876
914
  campaign_id: adUnit.unit_id,
@@ -901,7 +939,7 @@ var AttentionMarketClient = class {
901
939
  ...params.revenueSharePct !== void 0 ? { source_agent_pct: params.revenueSharePct } : {}
902
940
  }
903
941
  } : {},
904
- ttl_ms: response.ttl_ms
942
+ ttl_ms: response.ttl_ms || 3e5
905
943
  };
906
944
  }
907
945
  /**
@@ -992,7 +1030,7 @@ var AttentionMarketClient = class {
992
1030
  user_intent: params.userMessage
993
1031
  };
994
1032
  const response = await this.decideRaw(request, { idempotencyKey });
995
- if (response.status === "no_fill" || response.units.length === 0) {
1033
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
996
1034
  return null;
997
1035
  }
998
1036
  const adUnit = response.units[0];
@@ -1003,7 +1041,7 @@ var AttentionMarketClient = class {
1003
1041
  const similarity = adUnit._score?.relevance;
1004
1042
  return {
1005
1043
  offer_id: adUnit.unit_id,
1006
- request_id: response.request_id,
1044
+ request_id: response.request_id || "",
1007
1045
  impression_id: impressionId,
1008
1046
  // LIMITATION: Backend doesn't return campaign_id yet - use unit_id as placeholder
1009
1047
  campaign_id: adUnit.unit_id,
@@ -1034,7 +1072,7 @@ var AttentionMarketClient = class {
1034
1072
  ...params.revenueSharePct !== void 0 ? { source_agent_pct: params.revenueSharePct } : {}
1035
1073
  }
1036
1074
  } : {},
1037
- ttl_ms: response.ttl_ms
1075
+ ttl_ms: response.ttl_ms || 3e5
1038
1076
  };
1039
1077
  }
1040
1078
  // ============================================================================
@@ -1120,7 +1158,7 @@ var AttentionMarketClient = class {
1120
1158
  user_intent: params.taskDescription
1121
1159
  };
1122
1160
  const response = await this.decideRaw(request);
1123
- if (response.status === "no_fill" || response.units.length === 0) {
1161
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
1124
1162
  return null;
1125
1163
  }
1126
1164
  const adUnit = response.units[0];
@@ -1381,7 +1419,7 @@ var MockAttentionMarketClient = class {
1381
1419
  */
1382
1420
  async decide(request) {
1383
1421
  const response = await this.decideRaw(request);
1384
- if (response.status === "filled" && response.units.length > 0) {
1422
+ if (response.status === "filled" && response.units && response.units.length > 0) {
1385
1423
  return response.units[0] || null;
1386
1424
  }
1387
1425
  return null;