@the_ro_show/agent-ads-sdk 0.4.0 → 0.4.2

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.
@@ -7,26 +7,19 @@ Your bot answers user questions. Sometimes those answers could include a helpful
7
7
 
8
8
  ## Step-by-Step Guide
9
9
 
10
- ### **Step 1: Sign Up for API Keys** (One-time, 2 minutes)
10
+ ### **Step 1: Sign Up for API Keys** (One-time, 30 seconds)
11
11
 
12
12
  You need permission to request ads. Think of this like getting a key to a vending machine.
13
13
 
14
14
  **How to do it:**
15
- ```bash
16
- # Run this command once (it's like filling out a registration form)
17
- curl -X POST https://api.attentionmarket.ai/v1/agent-signup \
18
- -H 'Content-Type: application/json' \
19
- -d '{
20
- "owner_email": "your-email@example.com",
21
- "agent_name": "My Cool Bot",
22
- "sdk_type": "typescript"
23
- }'
24
- ```
15
+ 1. Go to **[attentionmarket.com/signup](https://attentionmarket.com/signup)**
16
+ 2. Enter your email and agent name
17
+ 3. Click "Generate API Keys"
25
18
 
26
19
  **You'll get back:**
27
- - An **Agent ID** (like `agt_abc123`) - your username
28
20
  - A **Test Key** (like `am_test_xyz789`) - for testing
29
21
  - A **Live Key** (like `am_live_xyz789`) - for when you go live
22
+ - An **Agent ID** (you'll use this for tracking)
30
23
 
31
24
  **Write these down!** You'll need them.
32
25
 
@@ -96,7 +89,7 @@ async function handleUserMessage(userMessage) {
96
89
  surface: 'chat'
97
90
  },
98
91
  opportunity: createOpportunity({
99
- taxonomy: 'shopping.ecommerce.platform', // This matches Pietra!
92
+ taxonomy: 'business.ecommerce.platform.trial', // E-commerce platforms
100
93
  country: 'US',
101
94
  language: 'en',
102
95
  platform: 'web',
@@ -204,8 +197,10 @@ await adClient.trackClick({
204
197
 
205
198
  ### **Taxonomy** = Topic Category
206
199
  When you request an ad, you tell us what the user is asking about:
207
- - `shopping.ecommerce.platform` = Online store questions
208
- - `local_services.movers.quote` = Moving company questions
200
+ - `business.ecommerce.platform.trial` = Online store questions
201
+ - `home_services.moving.local.quote` = Moving company questions
202
+ - `insurance.auto.full_coverage.quote` = Car insurance questions
203
+ - `legal.family.divorce.consultation` = Divorce lawyer questions
209
204
  - `business.productivity.tools` = Productivity software questions
210
205
 
211
206
  **You pick the taxonomy** based on what the user asked.
@@ -255,7 +250,7 @@ async function handleMessage(userMessage) {
255
250
  agent_id: process.env.ATTENTIONMARKET_AGENT_ID,
256
251
  placement: { type: 'sponsored_suggestion', surface: 'chat' },
257
252
  opportunity: createOpportunity({
258
- taxonomy: 'shopping.ecommerce.platform',
253
+ taxonomy: 'business.ecommerce.platform.trial',
259
254
  country: 'US',
260
255
  language: 'en',
261
256
  platform: 'web',
package/dist/index.d.mts CHANGED
@@ -21,6 +21,48 @@ interface DecideRequest {
21
21
  agent_id: string;
22
22
  placement: Placement;
23
23
  opportunity: Opportunity;
24
+ /** Full conversation context for semantic matching (optional) */
25
+ context?: string;
26
+ /** Detected or inferred user intent for semantic matching (optional) */
27
+ user_intent?: string;
28
+ }
29
+ /**
30
+ * Simplified request for semantic context-based ad matching.
31
+ * Uses conversation context instead of manual taxonomy selection.
32
+ *
33
+ * The SDK automatically limits conversationHistory to the last 5 messages
34
+ * to avoid token overflow. Only userMessage is required.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const ad = await client.decideFromContext({
39
+ * userMessage: "I need help with estate planning",
40
+ * conversationHistory: ["User: My father passed away recently"],
41
+ * placement: 'sponsored_suggestion'
42
+ * });
43
+ * ```
44
+ */
45
+ interface DecideFromContextRequest {
46
+ /** The user's current message (required) */
47
+ userMessage: string;
48
+ /**
49
+ * Optional conversation history (last few messages for context).
50
+ * SDK automatically limits to last 5 messages to avoid token overflow.
51
+ */
52
+ conversationHistory?: string[];
53
+ /** Ad placement type. Default: 'sponsored_suggestion' */
54
+ placement?: PlacementType;
55
+ /**
56
+ * Optional category hint (e.g., 'legal', 'insurance', 'travel').
57
+ * Used as fallback if semantic matching fails.
58
+ */
59
+ suggestedCategory?: string;
60
+ /** User's country code. Default: 'US' */
61
+ country?: string;
62
+ /** User's language code. Default: 'en' */
63
+ language?: string;
64
+ /** User's platform. Default: 'web' */
65
+ platform?: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
24
66
  }
25
67
  interface DecideResponse {
26
68
  request_id: string;
@@ -154,6 +196,7 @@ interface APIError {
154
196
  }
155
197
  interface SDKConfig {
156
198
  apiKey: string;
199
+ agentId?: string;
157
200
  supabaseAnonKey?: string;
158
201
  baseUrl?: string;
159
202
  timeoutMs?: number;
@@ -313,6 +356,7 @@ declare function sanitizeURL(url: string | null | undefined, options?: SanitizeU
313
356
 
314
357
  declare class AttentionMarketClient {
315
358
  private http;
359
+ private agentId;
316
360
  constructor(config: SDKConfig);
317
361
  /**
318
362
  * Validate SDK configuration for security
@@ -332,6 +376,23 @@ declare class AttentionMarketClient {
332
376
  decide(request: DecideRequest, options?: {
333
377
  idempotencyKey?: string;
334
378
  }): Promise<AdUnit | null>;
379
+ /**
380
+ * Simplified ad matching using conversation context and semantic search.
381
+ * Automatically handles request construction, taxonomy fallback, and defaults.
382
+ *
383
+ * Requires: agentId in SDKConfig constructor
384
+ *
385
+ * @example
386
+ * const ad = await client.decideFromContext({
387
+ * userMessage: "My father passed away and I need help organizing his estate",
388
+ * placement: 'sponsored_suggestion'
389
+ * });
390
+ *
391
+ * @throws {Error} If agentId was not provided in SDKConfig
392
+ */
393
+ decideFromContext(params: DecideFromContextRequest, options?: {
394
+ idempotencyKey?: string;
395
+ }): Promise<AdUnit | null>;
335
396
  /**
336
397
  * Report an event (impression, click, action, conversion, feedback).
337
398
  */
@@ -644,4 +705,4 @@ declare function getVertical(taxonomy: string): string | null;
644
705
  */
645
706
  declare function suggestTaxonomies(query: string): string[];
646
707
 
647
- export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type Intent, MockAttentionMarketClient, type MockClientConfig, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies };
708
+ export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideFromContextRequest, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type Intent, MockAttentionMarketClient, type MockClientConfig, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,48 @@ interface DecideRequest {
21
21
  agent_id: string;
22
22
  placement: Placement;
23
23
  opportunity: Opportunity;
24
+ /** Full conversation context for semantic matching (optional) */
25
+ context?: string;
26
+ /** Detected or inferred user intent for semantic matching (optional) */
27
+ user_intent?: string;
28
+ }
29
+ /**
30
+ * Simplified request for semantic context-based ad matching.
31
+ * Uses conversation context instead of manual taxonomy selection.
32
+ *
33
+ * The SDK automatically limits conversationHistory to the last 5 messages
34
+ * to avoid token overflow. Only userMessage is required.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const ad = await client.decideFromContext({
39
+ * userMessage: "I need help with estate planning",
40
+ * conversationHistory: ["User: My father passed away recently"],
41
+ * placement: 'sponsored_suggestion'
42
+ * });
43
+ * ```
44
+ */
45
+ interface DecideFromContextRequest {
46
+ /** The user's current message (required) */
47
+ userMessage: string;
48
+ /**
49
+ * Optional conversation history (last few messages for context).
50
+ * SDK automatically limits to last 5 messages to avoid token overflow.
51
+ */
52
+ conversationHistory?: string[];
53
+ /** Ad placement type. Default: 'sponsored_suggestion' */
54
+ placement?: PlacementType;
55
+ /**
56
+ * Optional category hint (e.g., 'legal', 'insurance', 'travel').
57
+ * Used as fallback if semantic matching fails.
58
+ */
59
+ suggestedCategory?: string;
60
+ /** User's country code. Default: 'US' */
61
+ country?: string;
62
+ /** User's language code. Default: 'en' */
63
+ language?: string;
64
+ /** User's platform. Default: 'web' */
65
+ platform?: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
24
66
  }
25
67
  interface DecideResponse {
26
68
  request_id: string;
@@ -154,6 +196,7 @@ interface APIError {
154
196
  }
155
197
  interface SDKConfig {
156
198
  apiKey: string;
199
+ agentId?: string;
157
200
  supabaseAnonKey?: string;
158
201
  baseUrl?: string;
159
202
  timeoutMs?: number;
@@ -313,6 +356,7 @@ declare function sanitizeURL(url: string | null | undefined, options?: SanitizeU
313
356
 
314
357
  declare class AttentionMarketClient {
315
358
  private http;
359
+ private agentId;
316
360
  constructor(config: SDKConfig);
317
361
  /**
318
362
  * Validate SDK configuration for security
@@ -332,6 +376,23 @@ declare class AttentionMarketClient {
332
376
  decide(request: DecideRequest, options?: {
333
377
  idempotencyKey?: string;
334
378
  }): Promise<AdUnit | null>;
379
+ /**
380
+ * Simplified ad matching using conversation context and semantic search.
381
+ * Automatically handles request construction, taxonomy fallback, and defaults.
382
+ *
383
+ * Requires: agentId in SDKConfig constructor
384
+ *
385
+ * @example
386
+ * const ad = await client.decideFromContext({
387
+ * userMessage: "My father passed away and I need help organizing his estate",
388
+ * placement: 'sponsored_suggestion'
389
+ * });
390
+ *
391
+ * @throws {Error} If agentId was not provided in SDKConfig
392
+ */
393
+ decideFromContext(params: DecideFromContextRequest, options?: {
394
+ idempotencyKey?: string;
395
+ }): Promise<AdUnit | null>;
335
396
  /**
336
397
  * Report an event (impression, click, action, conversion, feedback).
337
398
  */
@@ -644,4 +705,4 @@ declare function getVertical(taxonomy: string): string | null;
644
705
  */
645
706
  declare function suggestTaxonomies(query: string): string[];
646
707
 
647
- export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type Intent, MockAttentionMarketClient, type MockClientConfig, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies };
708
+ export { type APIError, APIRequestError, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateClickEventParams, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideFromContextRequest, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type Intent, MockAttentionMarketClient, type MockClientConfig, NetworkError, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createClickEvent, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies };
package/dist/index.js CHANGED
@@ -354,7 +354,9 @@ var DEFAULT_TIMEOUT_MS = 4e3;
354
354
  var DEFAULT_MAX_RETRIES = 2;
355
355
  var AttentionMarketClient = class {
356
356
  http;
357
+ agentId;
357
358
  constructor(config) {
359
+ this.agentId = config.agentId;
358
360
  this.validateConfig(config);
359
361
  const httpConfig = {
360
362
  apiKey: config.apiKey,
@@ -408,6 +410,66 @@ var AttentionMarketClient = class {
408
410
  }
409
411
  return response.units[0] ?? null;
410
412
  }
413
+ /**
414
+ * Simplified ad matching using conversation context and semantic search.
415
+ * Automatically handles request construction, taxonomy fallback, and defaults.
416
+ *
417
+ * Requires: agentId in SDKConfig constructor
418
+ *
419
+ * @example
420
+ * const ad = await client.decideFromContext({
421
+ * userMessage: "My father passed away and I need help organizing his estate",
422
+ * placement: 'sponsored_suggestion'
423
+ * });
424
+ *
425
+ * @throws {Error} If agentId was not provided in SDKConfig
426
+ */
427
+ async decideFromContext(params, options) {
428
+ if (!this.agentId) {
429
+ throw new Error(
430
+ "decideFromContext() requires agentId to be set in SDKConfig. Either provide agentId in the constructor or use decide() directly."
431
+ );
432
+ }
433
+ const historyLimit = 5;
434
+ const history = params.conversationHistory || [];
435
+ const limitedHistory = history.slice(-historyLimit);
436
+ const contextParts = [...limitedHistory, params.userMessage];
437
+ const context = contextParts.join("\n");
438
+ const country = params.country || "US";
439
+ const language = params.language || "en";
440
+ const platform = params.platform || "web";
441
+ const placementType = params.placement || "sponsored_suggestion";
442
+ const taxonomy = params.suggestedCategory || "unknown";
443
+ const request = {
444
+ request_id: generateUUID(),
445
+ agent_id: this.agentId,
446
+ placement: {
447
+ type: placementType,
448
+ surface: "chat"
449
+ },
450
+ opportunity: {
451
+ intent: {
452
+ taxonomy,
453
+ query: params.userMessage
454
+ },
455
+ context: {
456
+ country,
457
+ language,
458
+ platform
459
+ },
460
+ constraints: {
461
+ max_units: 1,
462
+ allowed_unit_types: [placementType]
463
+ },
464
+ privacy: {
465
+ data_policy: "coarse_only"
466
+ }
467
+ },
468
+ context,
469
+ user_intent: params.userMessage
470
+ };
471
+ return await this.decide(request, options);
472
+ }
411
473
  /**
412
474
  * Report an event (impression, click, action, conversion, feedback).
413
475
  */