@the_ro_show/agent-ads-sdk 0.1.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/LICENSE +21 -0
- package/README.md +376 -0
- package/SECURITY.md +50 -0
- package/dist/index.d.mts +300 -0
- package/dist/index.d.ts +300 -0
- package/dist/index.js +351 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +315 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +54 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types mirroring the AttentionMarket OpenAPI specification.
|
|
3
|
+
* These types are the source of truth for the SDK API surface.
|
|
4
|
+
*/
|
|
5
|
+
interface AgentSignupRequest {
|
|
6
|
+
owner_email: string;
|
|
7
|
+
agent_name: string;
|
|
8
|
+
sdk?: 'typescript' | 'python' | 'other';
|
|
9
|
+
environment?: 'test' | 'live';
|
|
10
|
+
declared_placements?: PlacementType[];
|
|
11
|
+
declared_capabilities?: string[];
|
|
12
|
+
}
|
|
13
|
+
interface AgentSignupResponse {
|
|
14
|
+
agent_id: string;
|
|
15
|
+
api_key: string;
|
|
16
|
+
test_api_key: string;
|
|
17
|
+
created_at: string;
|
|
18
|
+
}
|
|
19
|
+
interface DecideRequest {
|
|
20
|
+
request_id: string;
|
|
21
|
+
agent_id: string;
|
|
22
|
+
placement: Placement;
|
|
23
|
+
opportunity: Opportunity;
|
|
24
|
+
}
|
|
25
|
+
interface DecideResponse {
|
|
26
|
+
request_id: string;
|
|
27
|
+
decision_id: string;
|
|
28
|
+
status: 'filled' | 'no_fill';
|
|
29
|
+
ttl_ms: number;
|
|
30
|
+
units: AdUnit[];
|
|
31
|
+
}
|
|
32
|
+
type PlacementType = 'sponsored_suggestion' | 'sponsored_block' | 'sponsored_tool';
|
|
33
|
+
interface Placement {
|
|
34
|
+
type: PlacementType;
|
|
35
|
+
surface: string;
|
|
36
|
+
}
|
|
37
|
+
interface Opportunity {
|
|
38
|
+
intent: Intent;
|
|
39
|
+
context: Context;
|
|
40
|
+
constraints: Constraints;
|
|
41
|
+
privacy: Privacy;
|
|
42
|
+
}
|
|
43
|
+
interface Intent {
|
|
44
|
+
taxonomy: string;
|
|
45
|
+
query?: string;
|
|
46
|
+
}
|
|
47
|
+
interface Context {
|
|
48
|
+
country: string;
|
|
49
|
+
language: string;
|
|
50
|
+
platform: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
|
|
51
|
+
region?: string;
|
|
52
|
+
city?: string;
|
|
53
|
+
}
|
|
54
|
+
interface Constraints {
|
|
55
|
+
max_units: number;
|
|
56
|
+
allowed_unit_types: PlacementType[];
|
|
57
|
+
blocked_categories?: string[];
|
|
58
|
+
max_title_chars?: number;
|
|
59
|
+
max_body_chars?: number;
|
|
60
|
+
}
|
|
61
|
+
interface Privacy {
|
|
62
|
+
data_policy: 'coarse_only' | 'none' | 'extended';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* AdUnit is a discriminated union enforcing the OpenAPI oneOf constraint.
|
|
66
|
+
* Either suggestion OR tool is required based on unit_type.
|
|
67
|
+
*/
|
|
68
|
+
type AdUnit = {
|
|
69
|
+
unit_id: string;
|
|
70
|
+
unit_type: 'sponsored_suggestion';
|
|
71
|
+
disclosure: Disclosure;
|
|
72
|
+
tracking: Tracking;
|
|
73
|
+
suggestion: SponsoredSuggestion;
|
|
74
|
+
} | {
|
|
75
|
+
unit_id: string;
|
|
76
|
+
unit_type: 'sponsored_tool';
|
|
77
|
+
disclosure: Disclosure;
|
|
78
|
+
tracking: Tracking;
|
|
79
|
+
tool: SponsoredTool;
|
|
80
|
+
};
|
|
81
|
+
interface Disclosure {
|
|
82
|
+
label: string;
|
|
83
|
+
explanation: string;
|
|
84
|
+
sponsor_name: string;
|
|
85
|
+
}
|
|
86
|
+
interface Tracking {
|
|
87
|
+
token: string;
|
|
88
|
+
impression_url?: string;
|
|
89
|
+
click_url?: string;
|
|
90
|
+
}
|
|
91
|
+
interface SponsoredSuggestion {
|
|
92
|
+
title: string;
|
|
93
|
+
body: string;
|
|
94
|
+
cta: string;
|
|
95
|
+
action_url: string;
|
|
96
|
+
}
|
|
97
|
+
interface SponsoredTool {
|
|
98
|
+
tool_name: string;
|
|
99
|
+
description: string;
|
|
100
|
+
input_schema: Record<string, unknown>;
|
|
101
|
+
call: ToolCall;
|
|
102
|
+
}
|
|
103
|
+
interface ToolCall {
|
|
104
|
+
method: 'GET' | 'POST';
|
|
105
|
+
url: string;
|
|
106
|
+
headers?: Record<string, string>;
|
|
107
|
+
}
|
|
108
|
+
type EventType = 'impression' | 'click' | 'action' | 'conversion' | 'dismiss' | 'hide_advertiser' | 'report';
|
|
109
|
+
interface EventIngestRequest {
|
|
110
|
+
event_id: string;
|
|
111
|
+
occurred_at: string;
|
|
112
|
+
agent_id: string;
|
|
113
|
+
request_id: string;
|
|
114
|
+
decision_id: string;
|
|
115
|
+
unit_id: string;
|
|
116
|
+
event_type: EventType;
|
|
117
|
+
tracking_token: string;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface EventIngestResponse {
|
|
121
|
+
accepted: boolean;
|
|
122
|
+
}
|
|
123
|
+
interface PolicyResponse {
|
|
124
|
+
version: string;
|
|
125
|
+
disclosure: {
|
|
126
|
+
required: boolean;
|
|
127
|
+
label: string;
|
|
128
|
+
require_sponsor_name: boolean;
|
|
129
|
+
};
|
|
130
|
+
defaults: {
|
|
131
|
+
max_units_per_response: number;
|
|
132
|
+
blocked_categories: string[];
|
|
133
|
+
};
|
|
134
|
+
unit_rules: Record<string, unknown>;
|
|
135
|
+
}
|
|
136
|
+
interface APIError {
|
|
137
|
+
error: string;
|
|
138
|
+
message: string;
|
|
139
|
+
request_id: string;
|
|
140
|
+
details?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
interface SDKConfig {
|
|
143
|
+
apiKey: string;
|
|
144
|
+
baseUrl?: string;
|
|
145
|
+
timeoutMs?: number;
|
|
146
|
+
maxRetries?: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Utility functions for the AttentionMarket SDK.
|
|
151
|
+
* Includes UUID generation, opportunity helpers, and event builders.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Generate a UUID v4 for use as event_id, request_id, etc.
|
|
156
|
+
*/
|
|
157
|
+
declare function generateUUID(): string;
|
|
158
|
+
/**
|
|
159
|
+
* Generate an ISO 8601 timestamp for the current moment.
|
|
160
|
+
*/
|
|
161
|
+
declare function generateTimestamp(): string;
|
|
162
|
+
interface CreateOpportunityParams {
|
|
163
|
+
taxonomy: string;
|
|
164
|
+
country: string;
|
|
165
|
+
language: string;
|
|
166
|
+
platform: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
|
|
167
|
+
query?: string;
|
|
168
|
+
region?: string;
|
|
169
|
+
city?: string;
|
|
170
|
+
constraints?: {
|
|
171
|
+
max_units?: number;
|
|
172
|
+
allowed_unit_types?: ('sponsored_suggestion' | 'sponsored_block' | 'sponsored_tool')[];
|
|
173
|
+
blocked_categories?: string[];
|
|
174
|
+
max_title_chars?: number;
|
|
175
|
+
max_body_chars?: number;
|
|
176
|
+
};
|
|
177
|
+
privacy?: {
|
|
178
|
+
data_policy?: 'coarse_only' | 'none' | 'extended';
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Create a valid Opportunity object with safe defaults.
|
|
183
|
+
*
|
|
184
|
+
* Defaults:
|
|
185
|
+
* - constraints.max_units = 1
|
|
186
|
+
* - constraints.allowed_unit_types = ['sponsored_suggestion']
|
|
187
|
+
* - privacy.data_policy = 'coarse_only'
|
|
188
|
+
*/
|
|
189
|
+
declare function createOpportunity(params: CreateOpportunityParams): Opportunity;
|
|
190
|
+
interface CreateImpressionEventParams {
|
|
191
|
+
agent_id: string;
|
|
192
|
+
request_id: string;
|
|
193
|
+
decision_id: string;
|
|
194
|
+
unit_id: string;
|
|
195
|
+
tracking_token: string;
|
|
196
|
+
occurred_at?: string;
|
|
197
|
+
metadata?: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Helper to create an impression event payload.
|
|
201
|
+
*
|
|
202
|
+
* @param params - Event parameters (snake_case to match API)
|
|
203
|
+
* @returns EventIngestRequest ready to pass to client.track()
|
|
204
|
+
*/
|
|
205
|
+
declare function createImpressionEvent(params: CreateImpressionEventParams): EventIngestRequest;
|
|
206
|
+
interface CreateClickEventParams {
|
|
207
|
+
agent_id: string;
|
|
208
|
+
request_id: string;
|
|
209
|
+
decision_id: string;
|
|
210
|
+
unit_id: string;
|
|
211
|
+
tracking_token: string;
|
|
212
|
+
href: string;
|
|
213
|
+
occurred_at?: string;
|
|
214
|
+
metadata?: Record<string, unknown>;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Helper to create a click event payload.
|
|
218
|
+
*
|
|
219
|
+
* @param params - Event parameters (snake_case to match API)
|
|
220
|
+
* @returns EventIngestRequest ready to pass to client.track()
|
|
221
|
+
*/
|
|
222
|
+
declare function createClickEvent(params: CreateClickEventParams): EventIngestRequest;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Main SDK client for AttentionMarket Agent Ads API.
|
|
226
|
+
* Provides public methods: decide(), decideRaw(), track(), getPolicy(), signupAgent()
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
declare class AttentionMarketClient {
|
|
230
|
+
private http;
|
|
231
|
+
constructor(config: SDKConfig);
|
|
232
|
+
/**
|
|
233
|
+
* Request a sponsored unit decision for an agent opportunity.
|
|
234
|
+
* Returns the full DecideResponse including status, ttl_ms, and all units.
|
|
235
|
+
*/
|
|
236
|
+
decideRaw(request: DecideRequest, options?: {
|
|
237
|
+
idempotencyKey?: string;
|
|
238
|
+
}): Promise<DecideResponse>;
|
|
239
|
+
/**
|
|
240
|
+
* Convenience wrapper around decideRaw().
|
|
241
|
+
* Returns null if status is no_fill, otherwise returns the first ad unit.
|
|
242
|
+
*/
|
|
243
|
+
decide(request: DecideRequest, options?: {
|
|
244
|
+
idempotencyKey?: string;
|
|
245
|
+
}): Promise<AdUnit | null>;
|
|
246
|
+
/**
|
|
247
|
+
* Report an event (impression, click, action, conversion, feedback).
|
|
248
|
+
*/
|
|
249
|
+
track(event: EventIngestRequest): Promise<EventIngestResponse>;
|
|
250
|
+
/**
|
|
251
|
+
* Convenience method to track an impression event.
|
|
252
|
+
* Creates an impression event using createImpressionEvent() and calls track().
|
|
253
|
+
*/
|
|
254
|
+
trackImpression(params: Omit<CreateImpressionEventParams, 'occurred_at'> & {
|
|
255
|
+
occurred_at?: string;
|
|
256
|
+
}): Promise<EventIngestResponse>;
|
|
257
|
+
/**
|
|
258
|
+
* Convenience method to track a click event.
|
|
259
|
+
* Creates a click event using createClickEvent() and calls track().
|
|
260
|
+
*/
|
|
261
|
+
trackClick(params: Omit<CreateClickEventParams, 'occurred_at'> & {
|
|
262
|
+
occurred_at?: string;
|
|
263
|
+
}): Promise<EventIngestResponse>;
|
|
264
|
+
/**
|
|
265
|
+
* Fetch default policy constraints and formatting requirements.
|
|
266
|
+
*/
|
|
267
|
+
getPolicy(): Promise<PolicyResponse>;
|
|
268
|
+
/**
|
|
269
|
+
* Create or register an agent (optional helper).
|
|
270
|
+
* Note: This endpoint is unauthenticated in v1.
|
|
271
|
+
*/
|
|
272
|
+
static signupAgent(request: AgentSignupRequest, options?: {
|
|
273
|
+
baseUrl?: string;
|
|
274
|
+
}): Promise<AgentSignupResponse>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Error classes for AttentionMarket SDK.
|
|
279
|
+
* Surfaces HTTP status, API error codes, messages, and request_id.
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
declare class AttentionMarketError extends Error {
|
|
283
|
+
constructor(message: string);
|
|
284
|
+
}
|
|
285
|
+
declare class APIRequestError extends AttentionMarketError {
|
|
286
|
+
readonly statusCode: number;
|
|
287
|
+
readonly errorCode: string;
|
|
288
|
+
readonly requestId?: string;
|
|
289
|
+
readonly details?: Record<string, unknown>;
|
|
290
|
+
constructor(statusCode: number, apiError: APIError);
|
|
291
|
+
}
|
|
292
|
+
declare class NetworkError extends AttentionMarketError {
|
|
293
|
+
readonly cause?: Error;
|
|
294
|
+
constructor(message: string, cause?: Error);
|
|
295
|
+
}
|
|
296
|
+
declare class TimeoutError extends AttentionMarketError {
|
|
297
|
+
constructor(message?: string);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export { type APIError, APIRequestError, 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, NetworkError, type Opportunity, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SponsoredSuggestion, type SponsoredTool, TimeoutError, type ToolCall, type Tracking, createClickEvent, createImpressionEvent, createOpportunity, generateTimestamp, generateUUID };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types mirroring the AttentionMarket OpenAPI specification.
|
|
3
|
+
* These types are the source of truth for the SDK API surface.
|
|
4
|
+
*/
|
|
5
|
+
interface AgentSignupRequest {
|
|
6
|
+
owner_email: string;
|
|
7
|
+
agent_name: string;
|
|
8
|
+
sdk?: 'typescript' | 'python' | 'other';
|
|
9
|
+
environment?: 'test' | 'live';
|
|
10
|
+
declared_placements?: PlacementType[];
|
|
11
|
+
declared_capabilities?: string[];
|
|
12
|
+
}
|
|
13
|
+
interface AgentSignupResponse {
|
|
14
|
+
agent_id: string;
|
|
15
|
+
api_key: string;
|
|
16
|
+
test_api_key: string;
|
|
17
|
+
created_at: string;
|
|
18
|
+
}
|
|
19
|
+
interface DecideRequest {
|
|
20
|
+
request_id: string;
|
|
21
|
+
agent_id: string;
|
|
22
|
+
placement: Placement;
|
|
23
|
+
opportunity: Opportunity;
|
|
24
|
+
}
|
|
25
|
+
interface DecideResponse {
|
|
26
|
+
request_id: string;
|
|
27
|
+
decision_id: string;
|
|
28
|
+
status: 'filled' | 'no_fill';
|
|
29
|
+
ttl_ms: number;
|
|
30
|
+
units: AdUnit[];
|
|
31
|
+
}
|
|
32
|
+
type PlacementType = 'sponsored_suggestion' | 'sponsored_block' | 'sponsored_tool';
|
|
33
|
+
interface Placement {
|
|
34
|
+
type: PlacementType;
|
|
35
|
+
surface: string;
|
|
36
|
+
}
|
|
37
|
+
interface Opportunity {
|
|
38
|
+
intent: Intent;
|
|
39
|
+
context: Context;
|
|
40
|
+
constraints: Constraints;
|
|
41
|
+
privacy: Privacy;
|
|
42
|
+
}
|
|
43
|
+
interface Intent {
|
|
44
|
+
taxonomy: string;
|
|
45
|
+
query?: string;
|
|
46
|
+
}
|
|
47
|
+
interface Context {
|
|
48
|
+
country: string;
|
|
49
|
+
language: string;
|
|
50
|
+
platform: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
|
|
51
|
+
region?: string;
|
|
52
|
+
city?: string;
|
|
53
|
+
}
|
|
54
|
+
interface Constraints {
|
|
55
|
+
max_units: number;
|
|
56
|
+
allowed_unit_types: PlacementType[];
|
|
57
|
+
blocked_categories?: string[];
|
|
58
|
+
max_title_chars?: number;
|
|
59
|
+
max_body_chars?: number;
|
|
60
|
+
}
|
|
61
|
+
interface Privacy {
|
|
62
|
+
data_policy: 'coarse_only' | 'none' | 'extended';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* AdUnit is a discriminated union enforcing the OpenAPI oneOf constraint.
|
|
66
|
+
* Either suggestion OR tool is required based on unit_type.
|
|
67
|
+
*/
|
|
68
|
+
type AdUnit = {
|
|
69
|
+
unit_id: string;
|
|
70
|
+
unit_type: 'sponsored_suggestion';
|
|
71
|
+
disclosure: Disclosure;
|
|
72
|
+
tracking: Tracking;
|
|
73
|
+
suggestion: SponsoredSuggestion;
|
|
74
|
+
} | {
|
|
75
|
+
unit_id: string;
|
|
76
|
+
unit_type: 'sponsored_tool';
|
|
77
|
+
disclosure: Disclosure;
|
|
78
|
+
tracking: Tracking;
|
|
79
|
+
tool: SponsoredTool;
|
|
80
|
+
};
|
|
81
|
+
interface Disclosure {
|
|
82
|
+
label: string;
|
|
83
|
+
explanation: string;
|
|
84
|
+
sponsor_name: string;
|
|
85
|
+
}
|
|
86
|
+
interface Tracking {
|
|
87
|
+
token: string;
|
|
88
|
+
impression_url?: string;
|
|
89
|
+
click_url?: string;
|
|
90
|
+
}
|
|
91
|
+
interface SponsoredSuggestion {
|
|
92
|
+
title: string;
|
|
93
|
+
body: string;
|
|
94
|
+
cta: string;
|
|
95
|
+
action_url: string;
|
|
96
|
+
}
|
|
97
|
+
interface SponsoredTool {
|
|
98
|
+
tool_name: string;
|
|
99
|
+
description: string;
|
|
100
|
+
input_schema: Record<string, unknown>;
|
|
101
|
+
call: ToolCall;
|
|
102
|
+
}
|
|
103
|
+
interface ToolCall {
|
|
104
|
+
method: 'GET' | 'POST';
|
|
105
|
+
url: string;
|
|
106
|
+
headers?: Record<string, string>;
|
|
107
|
+
}
|
|
108
|
+
type EventType = 'impression' | 'click' | 'action' | 'conversion' | 'dismiss' | 'hide_advertiser' | 'report';
|
|
109
|
+
interface EventIngestRequest {
|
|
110
|
+
event_id: string;
|
|
111
|
+
occurred_at: string;
|
|
112
|
+
agent_id: string;
|
|
113
|
+
request_id: string;
|
|
114
|
+
decision_id: string;
|
|
115
|
+
unit_id: string;
|
|
116
|
+
event_type: EventType;
|
|
117
|
+
tracking_token: string;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface EventIngestResponse {
|
|
121
|
+
accepted: boolean;
|
|
122
|
+
}
|
|
123
|
+
interface PolicyResponse {
|
|
124
|
+
version: string;
|
|
125
|
+
disclosure: {
|
|
126
|
+
required: boolean;
|
|
127
|
+
label: string;
|
|
128
|
+
require_sponsor_name: boolean;
|
|
129
|
+
};
|
|
130
|
+
defaults: {
|
|
131
|
+
max_units_per_response: number;
|
|
132
|
+
blocked_categories: string[];
|
|
133
|
+
};
|
|
134
|
+
unit_rules: Record<string, unknown>;
|
|
135
|
+
}
|
|
136
|
+
interface APIError {
|
|
137
|
+
error: string;
|
|
138
|
+
message: string;
|
|
139
|
+
request_id: string;
|
|
140
|
+
details?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
interface SDKConfig {
|
|
143
|
+
apiKey: string;
|
|
144
|
+
baseUrl?: string;
|
|
145
|
+
timeoutMs?: number;
|
|
146
|
+
maxRetries?: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Utility functions for the AttentionMarket SDK.
|
|
151
|
+
* Includes UUID generation, opportunity helpers, and event builders.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Generate a UUID v4 for use as event_id, request_id, etc.
|
|
156
|
+
*/
|
|
157
|
+
declare function generateUUID(): string;
|
|
158
|
+
/**
|
|
159
|
+
* Generate an ISO 8601 timestamp for the current moment.
|
|
160
|
+
*/
|
|
161
|
+
declare function generateTimestamp(): string;
|
|
162
|
+
interface CreateOpportunityParams {
|
|
163
|
+
taxonomy: string;
|
|
164
|
+
country: string;
|
|
165
|
+
language: string;
|
|
166
|
+
platform: 'web' | 'ios' | 'android' | 'desktop' | 'voice' | 'other';
|
|
167
|
+
query?: string;
|
|
168
|
+
region?: string;
|
|
169
|
+
city?: string;
|
|
170
|
+
constraints?: {
|
|
171
|
+
max_units?: number;
|
|
172
|
+
allowed_unit_types?: ('sponsored_suggestion' | 'sponsored_block' | 'sponsored_tool')[];
|
|
173
|
+
blocked_categories?: string[];
|
|
174
|
+
max_title_chars?: number;
|
|
175
|
+
max_body_chars?: number;
|
|
176
|
+
};
|
|
177
|
+
privacy?: {
|
|
178
|
+
data_policy?: 'coarse_only' | 'none' | 'extended';
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Create a valid Opportunity object with safe defaults.
|
|
183
|
+
*
|
|
184
|
+
* Defaults:
|
|
185
|
+
* - constraints.max_units = 1
|
|
186
|
+
* - constraints.allowed_unit_types = ['sponsored_suggestion']
|
|
187
|
+
* - privacy.data_policy = 'coarse_only'
|
|
188
|
+
*/
|
|
189
|
+
declare function createOpportunity(params: CreateOpportunityParams): Opportunity;
|
|
190
|
+
interface CreateImpressionEventParams {
|
|
191
|
+
agent_id: string;
|
|
192
|
+
request_id: string;
|
|
193
|
+
decision_id: string;
|
|
194
|
+
unit_id: string;
|
|
195
|
+
tracking_token: string;
|
|
196
|
+
occurred_at?: string;
|
|
197
|
+
metadata?: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Helper to create an impression event payload.
|
|
201
|
+
*
|
|
202
|
+
* @param params - Event parameters (snake_case to match API)
|
|
203
|
+
* @returns EventIngestRequest ready to pass to client.track()
|
|
204
|
+
*/
|
|
205
|
+
declare function createImpressionEvent(params: CreateImpressionEventParams): EventIngestRequest;
|
|
206
|
+
interface CreateClickEventParams {
|
|
207
|
+
agent_id: string;
|
|
208
|
+
request_id: string;
|
|
209
|
+
decision_id: string;
|
|
210
|
+
unit_id: string;
|
|
211
|
+
tracking_token: string;
|
|
212
|
+
href: string;
|
|
213
|
+
occurred_at?: string;
|
|
214
|
+
metadata?: Record<string, unknown>;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Helper to create a click event payload.
|
|
218
|
+
*
|
|
219
|
+
* @param params - Event parameters (snake_case to match API)
|
|
220
|
+
* @returns EventIngestRequest ready to pass to client.track()
|
|
221
|
+
*/
|
|
222
|
+
declare function createClickEvent(params: CreateClickEventParams): EventIngestRequest;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Main SDK client for AttentionMarket Agent Ads API.
|
|
226
|
+
* Provides public methods: decide(), decideRaw(), track(), getPolicy(), signupAgent()
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
declare class AttentionMarketClient {
|
|
230
|
+
private http;
|
|
231
|
+
constructor(config: SDKConfig);
|
|
232
|
+
/**
|
|
233
|
+
* Request a sponsored unit decision for an agent opportunity.
|
|
234
|
+
* Returns the full DecideResponse including status, ttl_ms, and all units.
|
|
235
|
+
*/
|
|
236
|
+
decideRaw(request: DecideRequest, options?: {
|
|
237
|
+
idempotencyKey?: string;
|
|
238
|
+
}): Promise<DecideResponse>;
|
|
239
|
+
/**
|
|
240
|
+
* Convenience wrapper around decideRaw().
|
|
241
|
+
* Returns null if status is no_fill, otherwise returns the first ad unit.
|
|
242
|
+
*/
|
|
243
|
+
decide(request: DecideRequest, options?: {
|
|
244
|
+
idempotencyKey?: string;
|
|
245
|
+
}): Promise<AdUnit | null>;
|
|
246
|
+
/**
|
|
247
|
+
* Report an event (impression, click, action, conversion, feedback).
|
|
248
|
+
*/
|
|
249
|
+
track(event: EventIngestRequest): Promise<EventIngestResponse>;
|
|
250
|
+
/**
|
|
251
|
+
* Convenience method to track an impression event.
|
|
252
|
+
* Creates an impression event using createImpressionEvent() and calls track().
|
|
253
|
+
*/
|
|
254
|
+
trackImpression(params: Omit<CreateImpressionEventParams, 'occurred_at'> & {
|
|
255
|
+
occurred_at?: string;
|
|
256
|
+
}): Promise<EventIngestResponse>;
|
|
257
|
+
/**
|
|
258
|
+
* Convenience method to track a click event.
|
|
259
|
+
* Creates a click event using createClickEvent() and calls track().
|
|
260
|
+
*/
|
|
261
|
+
trackClick(params: Omit<CreateClickEventParams, 'occurred_at'> & {
|
|
262
|
+
occurred_at?: string;
|
|
263
|
+
}): Promise<EventIngestResponse>;
|
|
264
|
+
/**
|
|
265
|
+
* Fetch default policy constraints and formatting requirements.
|
|
266
|
+
*/
|
|
267
|
+
getPolicy(): Promise<PolicyResponse>;
|
|
268
|
+
/**
|
|
269
|
+
* Create or register an agent (optional helper).
|
|
270
|
+
* Note: This endpoint is unauthenticated in v1.
|
|
271
|
+
*/
|
|
272
|
+
static signupAgent(request: AgentSignupRequest, options?: {
|
|
273
|
+
baseUrl?: string;
|
|
274
|
+
}): Promise<AgentSignupResponse>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Error classes for AttentionMarket SDK.
|
|
279
|
+
* Surfaces HTTP status, API error codes, messages, and request_id.
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
declare class AttentionMarketError extends Error {
|
|
283
|
+
constructor(message: string);
|
|
284
|
+
}
|
|
285
|
+
declare class APIRequestError extends AttentionMarketError {
|
|
286
|
+
readonly statusCode: number;
|
|
287
|
+
readonly errorCode: string;
|
|
288
|
+
readonly requestId?: string;
|
|
289
|
+
readonly details?: Record<string, unknown>;
|
|
290
|
+
constructor(statusCode: number, apiError: APIError);
|
|
291
|
+
}
|
|
292
|
+
declare class NetworkError extends AttentionMarketError {
|
|
293
|
+
readonly cause?: Error;
|
|
294
|
+
constructor(message: string, cause?: Error);
|
|
295
|
+
}
|
|
296
|
+
declare class TimeoutError extends AttentionMarketError {
|
|
297
|
+
constructor(message?: string);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export { type APIError, APIRequestError, 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, NetworkError, type Opportunity, type Placement, type PlacementType, type PolicyResponse, type Privacy, type SDKConfig, type SponsoredSuggestion, type SponsoredTool, TimeoutError, type ToolCall, type Tracking, createClickEvent, createImpressionEvent, createOpportunity, generateTimestamp, generateUUID };
|