@the_ro_show/agent-ads-sdk 0.11.0 → 0.13.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/README.md +249 -0
- package/dist/index.d.mts +133 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +113 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -454,6 +454,60 @@ var AttentionMarketClient = class {
|
|
|
454
454
|
const platform = params.platform || "web";
|
|
455
455
|
const placementType = params.placement || "sponsored_suggestion";
|
|
456
456
|
const taxonomy = params.suggestedCategory || this.inferTaxonomy(params.userMessage);
|
|
457
|
+
if (params.minQualityScore !== void 0) {
|
|
458
|
+
if (typeof params.minQualityScore !== "number" || params.minQualityScore < 0 || params.minQualityScore > 1) {
|
|
459
|
+
throw new Error("minQualityScore must be a number between 0.0 and 1.0");
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (params.allowedCategories !== void 0) {
|
|
463
|
+
if (!Array.isArray(params.allowedCategories)) {
|
|
464
|
+
throw new Error("allowedCategories must be an array");
|
|
465
|
+
}
|
|
466
|
+
if (params.allowedCategories.length === 0) {
|
|
467
|
+
throw new Error("allowedCategories cannot be empty (would block all ads). Use blockedCategories to exclude specific categories, or omit to allow all.");
|
|
468
|
+
}
|
|
469
|
+
for (const cat of params.allowedCategories) {
|
|
470
|
+
if (typeof cat !== "string" && typeof cat !== "number") {
|
|
471
|
+
throw new Error(`allowedCategories must contain strings or numbers, found: ${typeof cat}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (params.blockedCategories !== void 0) {
|
|
476
|
+
if (!Array.isArray(params.blockedCategories)) {
|
|
477
|
+
throw new Error("blockedCategories must be an array");
|
|
478
|
+
}
|
|
479
|
+
for (const cat of params.blockedCategories) {
|
|
480
|
+
if (typeof cat !== "string" && typeof cat !== "number") {
|
|
481
|
+
throw new Error(`blockedCategories must contain strings or numbers, found: ${typeof cat}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (params.allowedCategories && params.allowedCategories.length > 0) {
|
|
485
|
+
console.warn("[AttentionMarket] Both allowedCategories and blockedCategories specified. blockedCategories will be ignored.");
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (params.blockedAdvertisers !== void 0) {
|
|
489
|
+
if (!Array.isArray(params.blockedAdvertisers)) {
|
|
490
|
+
throw new Error("blockedAdvertisers must be an array");
|
|
491
|
+
}
|
|
492
|
+
for (const id of params.blockedAdvertisers) {
|
|
493
|
+
if (typeof id !== "string" || id.trim().length === 0) {
|
|
494
|
+
throw new Error("blockedAdvertisers must contain non-empty strings (advertiser IDs)");
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (params.minCPC !== void 0) {
|
|
499
|
+
if (typeof params.minCPC !== "number" || params.minCPC < 0) {
|
|
500
|
+
throw new Error("minCPC must be a non-negative number (cost-per-click in cents)");
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (params.minRelevanceScore !== void 0) {
|
|
504
|
+
if (typeof params.minRelevanceScore !== "number" || params.minRelevanceScore < 0 || params.minRelevanceScore > 1) {
|
|
505
|
+
throw new Error("minRelevanceScore must be a number between 0.0 and 1.0");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (params.optimizeFor && params.optimizeFor !== "revenue" && params.optimizeFor !== "relevance") {
|
|
509
|
+
throw new Error('optimizeFor must be either "revenue" or "relevance"');
|
|
510
|
+
}
|
|
457
511
|
const request = {
|
|
458
512
|
request_id: generateUUID(),
|
|
459
513
|
agent_id: this.agentId,
|
|
@@ -480,7 +534,16 @@ var AttentionMarketClient = class {
|
|
|
480
534
|
}
|
|
481
535
|
},
|
|
482
536
|
context,
|
|
483
|
-
user_intent: params.userMessage
|
|
537
|
+
user_intent: params.userMessage,
|
|
538
|
+
// Developer controls (Phase 1: Quality & Brand Safety)
|
|
539
|
+
...params.minQualityScore !== void 0 && { minQualityScore: params.minQualityScore },
|
|
540
|
+
...params.allowedCategories && { allowedCategories: params.allowedCategories },
|
|
541
|
+
...params.blockedCategories && { blockedCategories: params.blockedCategories },
|
|
542
|
+
...params.blockedAdvertisers && { blockedAdvertisers: params.blockedAdvertisers },
|
|
543
|
+
// Developer controls (Phase 2: Revenue Optimization)
|
|
544
|
+
...params.minCPC !== void 0 && { minCPC: params.minCPC },
|
|
545
|
+
...params.minRelevanceScore !== void 0 && { minRelevanceScore: params.minRelevanceScore },
|
|
546
|
+
...params.optimizeFor && { optimizeFor: params.optimizeFor }
|
|
484
547
|
};
|
|
485
548
|
const response = await this.decideRaw(request, options);
|
|
486
549
|
if (response.status === "no_fill" || response.units.length === 0) {
|
|
@@ -1107,6 +1170,55 @@ var AttentionMarketClient = class {
|
|
|
1107
1170
|
{ body: params }
|
|
1108
1171
|
);
|
|
1109
1172
|
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Get IAB Content Taxonomy categories.
|
|
1175
|
+
*
|
|
1176
|
+
* Returns the complete IAB Content Taxonomy 3.0 (704 categories across 38 top-level categories).
|
|
1177
|
+
* Supports filtering by tier level, parent category, or search term.
|
|
1178
|
+
*
|
|
1179
|
+
* Use this to discover available categories for `allowedCategories` and `blockedCategories` parameters.
|
|
1180
|
+
*
|
|
1181
|
+
* @param params - Optional filters (tier, parent_id, search)
|
|
1182
|
+
* @returns The IAB Content Taxonomy with categories
|
|
1183
|
+
*
|
|
1184
|
+
* @example Get all Tier 1 categories (38 top-level categories)
|
|
1185
|
+
* ```typescript
|
|
1186
|
+
* const tier1 = await client.getCategories({ tier: 1 });
|
|
1187
|
+
* console.log(`${tier1.total} top-level categories`);
|
|
1188
|
+
* tier1.categories.forEach(cat => console.log(`${cat.id}: ${cat.name}`));
|
|
1189
|
+
* ```
|
|
1190
|
+
*
|
|
1191
|
+
* @example Get all subcategories of "Automotive" (ID: 1)
|
|
1192
|
+
* ```typescript
|
|
1193
|
+
* const automotiveCategories = await client.getCategories({ parent_id: 1 });
|
|
1194
|
+
* console.log(`Found ${automotiveCategories.total} automotive subcategories`);
|
|
1195
|
+
* ```
|
|
1196
|
+
*
|
|
1197
|
+
* @example Search for insurance-related categories
|
|
1198
|
+
* ```typescript
|
|
1199
|
+
* const insuranceCategories = await client.getCategories({ search: 'insurance' });
|
|
1200
|
+
* insuranceCategories.categories.forEach(cat => {
|
|
1201
|
+
* console.log(`${cat.id}: ${cat.full_path}`);
|
|
1202
|
+
* });
|
|
1203
|
+
* ```
|
|
1204
|
+
*/
|
|
1205
|
+
async getCategories(params) {
|
|
1206
|
+
const queryParams = new URLSearchParams();
|
|
1207
|
+
if (params?.tier) {
|
|
1208
|
+
queryParams.append("tier", params.tier.toString());
|
|
1209
|
+
}
|
|
1210
|
+
if (params?.parent_id) {
|
|
1211
|
+
queryParams.append("parent_id", params.parent_id.toString());
|
|
1212
|
+
}
|
|
1213
|
+
if (params?.search) {
|
|
1214
|
+
queryParams.append("search", params.search);
|
|
1215
|
+
}
|
|
1216
|
+
const url = `/v1/categories${queryParams.toString() ? "?" + queryParams.toString() : ""}`;
|
|
1217
|
+
return await this.http.request(
|
|
1218
|
+
"GET",
|
|
1219
|
+
url
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1110
1222
|
};
|
|
1111
1223
|
|
|
1112
1224
|
// src/mock-client.ts
|