@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.d.mts CHANGED
@@ -25,6 +25,9 @@ interface DecideRequest {
25
25
  context?: string;
26
26
  /** Detected or inferred user intent for semantic matching (optional) */
27
27
  user_intent?: string;
28
+ /** Response format: 'minimal' | 'standard' | 'verbose' (default: 'minimal') */
29
+ response_format?: string;
30
+ [key: string]: any;
28
31
  }
29
32
  /**
30
33
  * Simplified request for semantic context-based ad matching.
@@ -127,11 +130,27 @@ interface DecideFromContextRequest {
127
130
  optimizeFor?: 'revenue' | 'relevance';
128
131
  }
129
132
  interface DecideResponse {
130
- request_id: string;
131
- decision_id: string;
132
- status: 'filled' | 'no_fill';
133
- ttl_ms: number;
134
- units: AdUnit[];
133
+ request_id?: string;
134
+ decision_id?: string;
135
+ status?: 'filled' | 'no_fill';
136
+ ttl_ms?: number;
137
+ units?: AdUnit[];
138
+ creative?: {
139
+ title: string;
140
+ body: string;
141
+ cta: string;
142
+ };
143
+ click_url?: string;
144
+ tracking_token?: string;
145
+ advertiser_id?: string;
146
+ payout?: number;
147
+ disclosure?: {
148
+ label: string;
149
+ explanation: string;
150
+ sponsor_name: string;
151
+ };
152
+ relevance_score?: number;
153
+ [key: string]: any;
135
154
  }
136
155
  type PlacementType = 'sponsored_suggestion' | 'sponsored_block' | 'sponsored_tool';
137
156
  interface Placement {
package/dist/index.d.ts CHANGED
@@ -25,6 +25,9 @@ interface DecideRequest {
25
25
  context?: string;
26
26
  /** Detected or inferred user intent for semantic matching (optional) */
27
27
  user_intent?: string;
28
+ /** Response format: 'minimal' | 'standard' | 'verbose' (default: 'minimal') */
29
+ response_format?: string;
30
+ [key: string]: any;
28
31
  }
29
32
  /**
30
33
  * Simplified request for semantic context-based ad matching.
@@ -127,11 +130,27 @@ interface DecideFromContextRequest {
127
130
  optimizeFor?: 'revenue' | 'relevance';
128
131
  }
129
132
  interface DecideResponse {
130
- request_id: string;
131
- decision_id: string;
132
- status: 'filled' | 'no_fill';
133
- ttl_ms: number;
134
- units: AdUnit[];
133
+ request_id?: string;
134
+ decision_id?: string;
135
+ status?: 'filled' | 'no_fill';
136
+ ttl_ms?: number;
137
+ units?: AdUnit[];
138
+ creative?: {
139
+ title: string;
140
+ body: string;
141
+ cta: string;
142
+ };
143
+ click_url?: string;
144
+ tracking_token?: string;
145
+ advertiser_id?: string;
146
+ payout?: number;
147
+ disclosure?: {
148
+ label: string;
149
+ explanation: string;
150
+ sponsor_name: string;
151
+ };
152
+ relevance_score?: number;
153
+ [key: string]: any;
135
154
  }
136
155
  type PlacementType = 'sponsored_suggestion' | 'sponsored_block' | 'sponsored_tool';
137
156
  interface Placement {
package/dist/index.js CHANGED
@@ -468,7 +468,7 @@ var AttentionMarketClient = class {
468
468
  if (response.status === "no_fill") {
469
469
  return null;
470
470
  }
471
- return response.units[0] ?? null;
471
+ return response.units?.[0] ?? null;
472
472
  }
473
473
  /**
474
474
  * Simplified ad matching using conversation context and semantic search.
@@ -584,6 +584,8 @@ var AttentionMarketClient = class {
584
584
  },
585
585
  context,
586
586
  user_intent: params.userMessage,
587
+ // Use minimal response format by default for better performance
588
+ response_format: "minimal",
587
589
  // Developer controls (Phase 1: Quality & Brand Safety)
588
590
  ...params.minQualityScore !== void 0 && { minQualityScore: params.minQualityScore },
589
591
  ...params.allowedCategories && { allowedCategories: params.allowedCategories },
@@ -595,7 +597,43 @@ var AttentionMarketClient = class {
595
597
  ...params.optimizeFor && { optimizeFor: params.optimizeFor }
596
598
  };
597
599
  const response = await this.decideRaw(request, options);
598
- if (response.status === "no_fill" || response.units.length === 0) {
600
+ if (response.creative) {
601
+ try {
602
+ await this.track({
603
+ event_id: `evt_${generateUUID()}`,
604
+ event_type: "impression",
605
+ occurred_at: (/* @__PURE__ */ new Date()).toISOString(),
606
+ agent_id: this.agentId,
607
+ tracking_token: response.tracking_token
608
+ });
609
+ } catch (error) {
610
+ console.warn("[AttentionMarket] Failed to auto-track impression:", error);
611
+ }
612
+ const adResponse2 = {
613
+ request_id: request.request_id,
614
+ decision_id: `dec_${generateUUID()}`,
615
+ advertiser_id: response.advertiser_id || "",
616
+ ad_type: "link",
617
+ payout: response.payout || 0,
618
+ creative: response.creative,
619
+ click_url: response.click_url || "",
620
+ tracking_url: response.click_url || "",
621
+ // Same as click_url
622
+ tracking_token: response.tracking_token || "",
623
+ disclosure: response.disclosure || {
624
+ label: "Sponsored",
625
+ explanation: "This is a paid advertisement",
626
+ sponsor_name: "Advertiser"
627
+ },
628
+ // Internal fields preserved for backward compatibility
629
+ _ad: {
630
+ unit_id: "",
631
+ tracking: { token: response.tracking_token || "" }
632
+ }
633
+ };
634
+ return adResponse2;
635
+ }
636
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
599
637
  return null;
600
638
  }
601
639
  const adUnit = response.units[0];
@@ -908,7 +946,7 @@ var AttentionMarketClient = class {
908
946
  user_intent: params.intentKey
909
947
  };
910
948
  const response = await this.decideRaw(request, { idempotencyKey });
911
- if (response.status === "no_fill" || response.units.length === 0) {
949
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
912
950
  return null;
913
951
  }
914
952
  const adUnit = response.units[0];
@@ -919,7 +957,7 @@ var AttentionMarketClient = class {
919
957
  const matchMethod = semanticContext ? "hybrid" : "semantic";
920
958
  return {
921
959
  offer_id: adUnit.unit_id,
922
- request_id: response.request_id,
960
+ request_id: response.request_id || "",
923
961
  impression_id: impressionId,
924
962
  // LIMITATION: Backend doesn't return campaign_id yet - use unit_id as placeholder
925
963
  campaign_id: adUnit.unit_id,
@@ -950,7 +988,7 @@ var AttentionMarketClient = class {
950
988
  ...params.revenueSharePct !== void 0 ? { source_agent_pct: params.revenueSharePct } : {}
951
989
  }
952
990
  } : {},
953
- ttl_ms: response.ttl_ms
991
+ ttl_ms: response.ttl_ms || 3e5
954
992
  };
955
993
  }
956
994
  /**
@@ -1041,7 +1079,7 @@ var AttentionMarketClient = class {
1041
1079
  user_intent: params.userMessage
1042
1080
  };
1043
1081
  const response = await this.decideRaw(request, { idempotencyKey });
1044
- if (response.status === "no_fill" || response.units.length === 0) {
1082
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
1045
1083
  return null;
1046
1084
  }
1047
1085
  const adUnit = response.units[0];
@@ -1052,7 +1090,7 @@ var AttentionMarketClient = class {
1052
1090
  const similarity = adUnit._score?.relevance;
1053
1091
  return {
1054
1092
  offer_id: adUnit.unit_id,
1055
- request_id: response.request_id,
1093
+ request_id: response.request_id || "",
1056
1094
  impression_id: impressionId,
1057
1095
  // LIMITATION: Backend doesn't return campaign_id yet - use unit_id as placeholder
1058
1096
  campaign_id: adUnit.unit_id,
@@ -1083,7 +1121,7 @@ var AttentionMarketClient = class {
1083
1121
  ...params.revenueSharePct !== void 0 ? { source_agent_pct: params.revenueSharePct } : {}
1084
1122
  }
1085
1123
  } : {},
1086
- ttl_ms: response.ttl_ms
1124
+ ttl_ms: response.ttl_ms || 3e5
1087
1125
  };
1088
1126
  }
1089
1127
  // ============================================================================
@@ -1169,7 +1207,7 @@ var AttentionMarketClient = class {
1169
1207
  user_intent: params.taskDescription
1170
1208
  };
1171
1209
  const response = await this.decideRaw(request);
1172
- if (response.status === "no_fill" || response.units.length === 0) {
1210
+ if (response.status === "no_fill" || !response.units || response.units.length === 0) {
1173
1211
  return null;
1174
1212
  }
1175
1213
  const adUnit = response.units[0];
@@ -1430,7 +1468,7 @@ var MockAttentionMarketClient = class {
1430
1468
  */
1431
1469
  async decide(request) {
1432
1470
  const response = await this.decideRaw(request);
1433
- if (response.status === "filled" && response.units.length > 0) {
1471
+ if (response.status === "filled" && response.units && response.units.length > 0) {
1434
1472
  return response.units[0] || null;
1435
1473
  }
1436
1474
  return null;