@the_ro_show/agent-ads-sdk 0.13.2 → 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/README.md CHANGED
@@ -95,7 +95,8 @@ const client = new AttentionMarketClient({
95
95
  const client = new AttentionMarketClient({
96
96
  apiKey: 'am_live_YOUR_KEY', // Required
97
97
  agentId: 'agt_YOUR_AGENT_ID', // Required for decideFromContext()
98
- baseUrl: 'https://peruwnbrqkvmrldhpoom.supabase.co/functions/v1', // Optional: defaults to production
98
+ // baseUrl defaults to production Supabase endpoint
99
+ // Only override if self-hosting or using different environment
99
100
  timeoutMs: 4000, // Optional: request timeout in milliseconds
100
101
  maxRetries: 2 // Optional: automatic retry count
101
102
  });
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
@@ -457,7 +457,7 @@ var AttentionMarketClient = class {
457
457
  if (options?.idempotencyKey !== void 0) {
458
458
  requestOptions.idempotencyKey = options.idempotencyKey;
459
459
  }
460
- return await this.http.request("POST", "/v1/decide", requestOptions);
460
+ return await this.http.request("POST", "/decide", requestOptions);
461
461
  }
462
462
  /**
463
463
  * Convenience wrapper around decideRaw().
@@ -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];
@@ -648,7 +686,7 @@ var AttentionMarketClient = class {
648
686
  * Report an event (impression, click, action, conversion, feedback).
649
687
  */
650
688
  async track(event) {
651
- return await this.http.request("POST", "/v1/event", {
689
+ return await this.http.request("POST", "/event", {
652
690
  body: event
653
691
  });
654
692
  }
@@ -738,13 +776,13 @@ var AttentionMarketClient = class {
738
776
  * ```
739
777
  */
740
778
  async sendFeedback(request) {
741
- return await this.http.request("POST", "/v1/feedback", { body: request });
779
+ return await this.http.request("POST", "/feedback", { body: request });
742
780
  }
743
781
  /**
744
782
  * Fetch default policy constraints and formatting requirements.
745
783
  */
746
784
  async getPolicy() {
747
- return await this.http.request("GET", "/v1/policy");
785
+ return await this.http.request("GET", "/policy");
748
786
  }
749
787
  /**
750
788
  * Create or register an agent (optional helper).
@@ -756,7 +794,7 @@ var AttentionMarketClient = class {
756
794
  timeoutMs: DEFAULT_TIMEOUT_MS,
757
795
  maxRetries: DEFAULT_MAX_RETRIES
758
796
  });
759
- return await http.request("POST", "/v1/agent-signup", {
797
+ return await http.request("POST", "/agent-signup", {
760
798
  body: request
761
799
  });
762
800
  }
@@ -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];
@@ -1215,7 +1253,7 @@ var AttentionMarketClient = class {
1215
1253
  async logServiceResult(params) {
1216
1254
  return await this.http.request(
1217
1255
  "POST",
1218
- "/v1/service-result",
1256
+ "/service-result",
1219
1257
  { body: params }
1220
1258
  );
1221
1259
  }
@@ -1262,7 +1300,7 @@ var AttentionMarketClient = class {
1262
1300
  if (params?.search) {
1263
1301
  queryParams.append("search", params.search);
1264
1302
  }
1265
- const url = `/v1/categories${queryParams.toString() ? "?" + queryParams.toString() : ""}`;
1303
+ const url = `/categories${queryParams.toString() ? "?" + queryParams.toString() : ""}`;
1266
1304
  return await this.http.request(
1267
1305
  "GET",
1268
1306
  url
@@ -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;