@gravity-ai/api 1.1.3 → 1.1.5
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 +270 -5
- package/dist/chunk-EBO3CZXG.mjs +15 -0
- package/dist/index.d.mts +148 -217
- package/dist/index.d.ts +148 -217
- package/dist/index.js +318 -3
- package/dist/index.mjs +314 -2
- package/dist/opentui.d.mts +183 -0
- package/dist/opentui.d.ts +183 -0
- package/dist/opentui.js +338 -0
- package/dist/opentui.mjs +316 -0
- package/dist/types-DYbti_CZ.d.mts +249 -0
- package/dist/types-DYbti_CZ.d.ts +249 -0
- package/package.json +17 -3
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role type for conversation messages
|
|
3
|
+
* @description Indicates whether a message is from the user or the AI assistant
|
|
4
|
+
*/
|
|
5
|
+
type Role = 'user' | 'assistant';
|
|
6
|
+
/**
|
|
7
|
+
* Gender type for user targeting
|
|
8
|
+
* @description Used for demographic targeting of advertisements
|
|
9
|
+
*/
|
|
10
|
+
type Gender = 'male' | 'female' | 'other';
|
|
11
|
+
/**
|
|
12
|
+
* Placement positions for ad rendering
|
|
13
|
+
* @description Specifies where ads should appear relative to the AI response
|
|
14
|
+
*/
|
|
15
|
+
type Placement = 'above_response' | 'below_response' | 'inline_response' | 'left_response' | 'right_response';
|
|
16
|
+
/**
|
|
17
|
+
* Individual ad placement specification
|
|
18
|
+
* @description Defines a single ad slot with its position and optional tracking ID
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const placement: PlacementObject = {
|
|
22
|
+
* placement: 'below_response',
|
|
23
|
+
* placement_id: 'sidebar-1'
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface PlacementObject {
|
|
28
|
+
/** Position where the ad should appear (required) */
|
|
29
|
+
placement: Placement;
|
|
30
|
+
/** Tracking ID for this specific ad slot (required) */
|
|
31
|
+
placement_id: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Represents a single message in a conversation
|
|
35
|
+
* @description Used to provide conversation context for contextual ad targeting
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const message: MessageObject = {
|
|
39
|
+
* role: 'user',
|
|
40
|
+
* content: 'I need help finding a new laptop.'
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
interface MessageObject {
|
|
45
|
+
/** The role of the message sender - either 'user' or 'assistant' */
|
|
46
|
+
role: Role;
|
|
47
|
+
/** The text content of the message */
|
|
48
|
+
content: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Device and location information for ad targeting
|
|
52
|
+
* @description Provides device-level context for better ad relevance and compliance
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const device: DeviceObject = {
|
|
56
|
+
* ip: '192.168.1.1',
|
|
57
|
+
* country: 'US',
|
|
58
|
+
* ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...',
|
|
59
|
+
* os: 'macOS'
|
|
60
|
+
* };
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
interface DeviceObject {
|
|
64
|
+
/** User's IP address for geo-targeting (required) */
|
|
65
|
+
ip: string;
|
|
66
|
+
/** Browser user-agent string (optional for non-web publishers like IDEs, CLIs, mobile apps) */
|
|
67
|
+
ua?: string;
|
|
68
|
+
/** ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB', 'DE') */
|
|
69
|
+
country?: string;
|
|
70
|
+
/** Operating system name (e.g., 'macOS', 'Windows', 'iOS', 'Android') */
|
|
71
|
+
os?: string;
|
|
72
|
+
/** Identifier for Advertisers (mobile advertising ID) */
|
|
73
|
+
ifa?: string;
|
|
74
|
+
/** Additional device properties (timezone, locale, browser, device_type, screen dimensions, etc.) */
|
|
75
|
+
[key: string]: string | number | boolean | undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* User profile information for ad targeting
|
|
79
|
+
* @description Demographic and interest data for personalized ad delivery
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const user: UserObject = {
|
|
83
|
+
* uid: 'user-123',
|
|
84
|
+
* gender: 'male',
|
|
85
|
+
* age: '25-34',
|
|
86
|
+
* keywords: 'technology,programming,gaming'
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
interface UserObject {
|
|
91
|
+
/** Unique user identifier for improving ad relevance */
|
|
92
|
+
uid?: string;
|
|
93
|
+
/** User's gender for demographic targeting */
|
|
94
|
+
gender?: Gender;
|
|
95
|
+
/** Age range string (e.g., '18-24', '25-34', '35-44', '45-54', '55-64', '65+') */
|
|
96
|
+
age?: string;
|
|
97
|
+
/** Comma-separated keywords representing user interests */
|
|
98
|
+
keywords?: string;
|
|
99
|
+
/** Additional user properties (email, subscription_tier, user_interests, company_size, etc.) */
|
|
100
|
+
[key: string]: string | string[] | number | boolean | Gender | undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated Use `Gravity.getAds()` or `gravityAds()` instead, which accept
|
|
104
|
+
* standard request objects and auto-extract context from `gravityContext()`.
|
|
105
|
+
*/
|
|
106
|
+
interface AdParams {
|
|
107
|
+
/** Array of conversation messages for contextual targeting (required) */
|
|
108
|
+
messages: MessageObject[];
|
|
109
|
+
/** Session identifier for ad relevance (required) */
|
|
110
|
+
sessionId: string;
|
|
111
|
+
/** Ad placement specifications (required). Array of 1-10 placements. */
|
|
112
|
+
placements: PlacementObject[];
|
|
113
|
+
/** Unique user identifier */
|
|
114
|
+
userId?: string;
|
|
115
|
+
/** Device and location information */
|
|
116
|
+
device?: DeviceObject;
|
|
117
|
+
/** User demographic and interest data */
|
|
118
|
+
user?: UserObject;
|
|
119
|
+
/** Topics to exclude from ad matching (e.g., ['politics', 'religion']) */
|
|
120
|
+
excludedTopics?: string[];
|
|
121
|
+
/** Minimum relevancy score threshold (0-1). Higher = more relevant but fewer ads */
|
|
122
|
+
relevancy?: number | null;
|
|
123
|
+
/** Returns a test ad when true (no billing, for integration testing) */
|
|
124
|
+
testAd?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Additional custom fields for publisher-specific targeting
|
|
127
|
+
* @description Any additional key-value pairs will be passed to the API
|
|
128
|
+
*/
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Single ad object in responses.
|
|
133
|
+
* @description Contains ad creative and tracking data. Returned as a flat array from v1 API.
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const ad: Ad = {
|
|
137
|
+
* adText: 'Check out our amazing laptops!',
|
|
138
|
+
* title: 'Dell XPS 15',
|
|
139
|
+
* cta: 'Shop Now',
|
|
140
|
+
* brandName: 'Dell',
|
|
141
|
+
* url: 'https://dell.com/xps',
|
|
142
|
+
* impUrl: 'https://tracking.example.com/imp?id=123',
|
|
143
|
+
* clickUrl: 'https://tracking.example.com/click?id=123'
|
|
144
|
+
* };
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
interface Ad {
|
|
148
|
+
/** The advertisement copy text */
|
|
149
|
+
adText: string;
|
|
150
|
+
/** Ad title */
|
|
151
|
+
title?: string;
|
|
152
|
+
/** Call-to-action text (e.g., 'Learn More', 'Shop Now') */
|
|
153
|
+
cta?: string;
|
|
154
|
+
/** Brand/advertiser name */
|
|
155
|
+
brandName?: string;
|
|
156
|
+
/** Landing page URL */
|
|
157
|
+
url?: string;
|
|
158
|
+
/** Favicon URL */
|
|
159
|
+
favicon?: string;
|
|
160
|
+
/** Impression tracking URL - fire this when ad is displayed */
|
|
161
|
+
impUrl?: string;
|
|
162
|
+
/** Click-through tracking URL - use this as href for ad clicks */
|
|
163
|
+
clickUrl?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Error response structure from the Gravity API
|
|
167
|
+
* @description Returned when the API encounters an error processing the request
|
|
168
|
+
*/
|
|
169
|
+
interface ApiErrorResponse {
|
|
170
|
+
/** Error code or type identifier */
|
|
171
|
+
error: string;
|
|
172
|
+
/** Human-readable error description */
|
|
173
|
+
message?: string;
|
|
174
|
+
/** HTTP status code */
|
|
175
|
+
statusCode?: number;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Overrides passed to `gravityContext()`.
|
|
179
|
+
* `sessionId` and `user.userId` are required; everything else is auto-detected.
|
|
180
|
+
*/
|
|
181
|
+
interface GravityContextOverrides {
|
|
182
|
+
/** Your chat/conversation session ID (required) */
|
|
183
|
+
sessionId: string;
|
|
184
|
+
/** User info — `userId` is required */
|
|
185
|
+
user: {
|
|
186
|
+
userId: string;
|
|
187
|
+
} & Record<string, unknown>;
|
|
188
|
+
/** Device field overrides (timezone, locale, etc.) */
|
|
189
|
+
device?: Record<string, unknown>;
|
|
190
|
+
}
|
|
191
|
+
/** The context object returned by `gravityContext()` and sent in the request body. */
|
|
192
|
+
interface GravityContext {
|
|
193
|
+
sessionId: string;
|
|
194
|
+
user: {
|
|
195
|
+
id: string;
|
|
196
|
+
} & Record<string, unknown>;
|
|
197
|
+
device: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
/** Options for `gravityAds()`. */
|
|
200
|
+
interface GravityAdsOptions {
|
|
201
|
+
/** Gravity API key. Defaults to `process.env.GRAVITY_API_KEY`. */
|
|
202
|
+
apiKey?: string;
|
|
203
|
+
/** Gravity ad endpoint URL. Defaults to production. */
|
|
204
|
+
gravityApi?: string;
|
|
205
|
+
/** Abort after this many ms. Default: `3000`. */
|
|
206
|
+
timeoutMs?: number;
|
|
207
|
+
/** Minimum relevancy threshold (0-1). Default: `0.2`. */
|
|
208
|
+
relevancy?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Serve real ads when `true`. Defaults to `false` (test ads, no billing).
|
|
211
|
+
* Pass `production: true` when you're ready to go live.
|
|
212
|
+
*/
|
|
213
|
+
production?: boolean;
|
|
214
|
+
/** Topics to exclude from ad matching. */
|
|
215
|
+
excludedTopics?: string[];
|
|
216
|
+
}
|
|
217
|
+
/** Result returned by `gravityAds()`. Never throws. */
|
|
218
|
+
interface GravityAdsResult {
|
|
219
|
+
/** Matched ads (empty array on failure or no-fill). */
|
|
220
|
+
ads: Ad[];
|
|
221
|
+
/** HTTP status from the Gravity API. `0` = network error or missing API key. */
|
|
222
|
+
status: number;
|
|
223
|
+
/** Round-trip time in ms (string for easy logging). */
|
|
224
|
+
elapsed: string;
|
|
225
|
+
/** The full request body sent to Gravity (useful for debugging). */
|
|
226
|
+
requestBody: Record<string, unknown> | null;
|
|
227
|
+
/** Error message, only present on failure. */
|
|
228
|
+
error?: string;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Minimal server request shape that `gravityAds()` can read.
|
|
232
|
+
* Compatible with Express, Fastify, Node http (with body-parser), Next.js, etc.
|
|
233
|
+
*/
|
|
234
|
+
interface IncomingAdRequest {
|
|
235
|
+
body?: {
|
|
236
|
+
gravity_context?: GravityContext;
|
|
237
|
+
[key: string]: unknown;
|
|
238
|
+
};
|
|
239
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
240
|
+
socket?: {
|
|
241
|
+
remoteAddress?: string;
|
|
242
|
+
};
|
|
243
|
+
connection?: {
|
|
244
|
+
remoteAddress?: string;
|
|
245
|
+
};
|
|
246
|
+
ip?: string;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export type { AdParams as A, DeviceObject as D, GravityAdsOptions as G, IncomingAdRequest as I, MessageObject as M, PlacementObject as P, Role as R, UserObject as U, GravityAdsResult as a, GravityContextOverrides as b, GravityContext as c, Ad as d, ApiErrorResponse as e, Placement as f, Gender as g };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ai/api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Gravity JS SDK for retrieving targeted advertisements",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,12 +13,17 @@
|
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"require": "./dist/index.js",
|
|
15
15
|
"import": "./dist/index.mjs"
|
|
16
|
+
},
|
|
17
|
+
"./opentui": {
|
|
18
|
+
"types": "./dist/opentui.d.ts",
|
|
19
|
+
"require": "./dist/opentui.js",
|
|
20
|
+
"import": "./dist/opentui.mjs"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"scripts": {
|
|
19
|
-
"build": "tsup index.ts --format cjs,esm --dts",
|
|
24
|
+
"build": "tsup index.ts opentui.ts --format cjs,esm --dts",
|
|
20
25
|
"clean": "rm -rf dist",
|
|
21
|
-
"dev": "tsup index.ts --format cjs,esm --watch --dts",
|
|
26
|
+
"dev": "tsup index.ts opentui.ts --format cjs,esm --watch --dts",
|
|
22
27
|
"lint": "tsc --noEmit",
|
|
23
28
|
"test": "vitest run",
|
|
24
29
|
"prepublishOnly": "npm run clean && npm run build",
|
|
@@ -56,10 +61,19 @@
|
|
|
56
61
|
"engines": {
|
|
57
62
|
"node": ">=18.0.0"
|
|
58
63
|
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@opentui/core": ">=0.1.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"@opentui/core": {
|
|
69
|
+
"optional": true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
59
72
|
"dependencies": {
|
|
60
73
|
"axios": "^1.13.2"
|
|
61
74
|
},
|
|
62
75
|
"devDependencies": {
|
|
76
|
+
"@opentui/core": "^0.1.80",
|
|
63
77
|
"tsup": "^8.0.1",
|
|
64
78
|
"typescript": "^5.3.3",
|
|
65
79
|
"vitest": "^1.2.1"
|