@bitbitpress/client 0.1.3 → 0.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 +213 -28
- package/dist/client.d.ts +10 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -1
- package/dist/client.js.map +1 -1
- package/dist/examples/basic-usage.d.ts +2 -1
- package/dist/examples/basic-usage.d.ts.map +1 -1
- package/dist/examples/basic-usage.js +57 -17
- package/dist/examples/basic-usage.js.map +1 -1
- package/dist/generated/openapi.d.ts +237 -28
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/user/index.d.ts +27 -4
- package/dist/user/index.d.ts.map +1 -1
- package/dist/user/index.js +13 -5
- package/dist/user/index.js.map +1 -1
- package/dist/user/profile.d.ts +11 -0
- package/dist/user/profile.d.ts.map +1 -0
- package/dist/user/profile.js +21 -0
- package/dist/user/profile.js.map +1 -0
- package/dist/user/report.d.ts +13 -0
- package/dist/user/report.d.ts.map +1 -0
- package/dist/user/report.js +23 -0
- package/dist/user/report.js.map +1 -0
- package/dist/user/signal-batch-manager.d.ts +22 -0
- package/dist/user/signal-batch-manager.d.ts.map +1 -0
- package/dist/user/signal-batch-manager.js +73 -0
- package/dist/user/signal-batch-manager.js.map +1 -0
- package/dist/user/signal.d.ts +3 -2
- package/dist/user/signal.d.ts.map +1 -1
- package/dist/user/signal.js +2 -2
- package/dist/user/signal.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,8 +43,11 @@ More details can also be found in your control room's API docs @ https://your-co
|
|
|
43
43
|
- [User Methods](#user-methods)
|
|
44
44
|
- [authenticate](#authenticate)
|
|
45
45
|
- [token](#token)
|
|
46
|
+
- [profile](#profile)
|
|
46
47
|
- [recommendations](#recommendations)
|
|
48
|
+
- [report](#report)
|
|
47
49
|
- [signal](#signal)
|
|
50
|
+
- [signalItem](#signalitem)
|
|
48
51
|
- [synthesizeItem](#synthesizeitem)
|
|
49
52
|
- [synthesize](#synthesize)
|
|
50
53
|
- [Types](#types)
|
|
@@ -66,6 +69,7 @@ new BitBitPressClient(options: BitBitPressClientOptions)
|
|
|
66
69
|
- `options.headers` (optional): Additional headers to include in all requests
|
|
67
70
|
- `options.timeout` (optional): Request timeout in milliseconds (default: `30000`)
|
|
68
71
|
- `options.synthesizeBatchTimeout` (optional): Batch timeout for `synthesizeItem` in milliseconds (default: `250`)
|
|
72
|
+
- `options.signalBatchTimeout` (optional): Batch timeout for `signalItem` in milliseconds (default: `250`)
|
|
69
73
|
|
|
70
74
|
##### Example
|
|
71
75
|
|
|
@@ -74,6 +78,7 @@ const client = new BitBitPressClient({
|
|
|
74
78
|
baseUrl: 'https://your-control-room.api.dev.bitbitpress.com',
|
|
75
79
|
timeout: 30000,
|
|
76
80
|
synthesizeBatchTimeout: 250,
|
|
81
|
+
signalBatchTimeout: 250,
|
|
77
82
|
});
|
|
78
83
|
```
|
|
79
84
|
|
|
@@ -151,6 +156,32 @@ console.log('Access token:', tokenResponse.accessToken);
|
|
|
151
156
|
|
|
152
157
|
---
|
|
153
158
|
|
|
159
|
+
#### profile
|
|
160
|
+
|
|
161
|
+
Get user profile information, including suggested interest topics.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
client.user.profile(): Promise<ProfileResponse>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
##### Returns
|
|
168
|
+
|
|
169
|
+
- `Promise<ProfileResponse>`: Response containing:
|
|
170
|
+
- `suggestedInterestTopics?: string[]`: Suggested interest topics for the user
|
|
171
|
+
|
|
172
|
+
##### Example
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const profile = await client.user.profile();
|
|
176
|
+
console.log('Suggested topics:', profile.suggestedInterestTopics);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
##### Throws
|
|
180
|
+
|
|
181
|
+
- `Error`: If the request fails or no data is returned
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
154
185
|
#### recommendations
|
|
155
186
|
|
|
156
187
|
Get recommended articles for the authenticated user.
|
|
@@ -163,6 +194,7 @@ client.user.recommendations(options?: RecommendationsRequest): Promise<Recommend
|
|
|
163
194
|
|
|
164
195
|
- `options.limit` (optional): Maximum number of recommendations to return
|
|
165
196
|
- `options.cursor` (optional): Cursor from previous response to fetch the next page
|
|
197
|
+
- `options.fields` (optional): Asset fields to return (dot or bracket notation, e.g. `tags[0]`, `images[1].src`). Allowed: `title`, `tags`, `images`, `videos`, `publishedAt`, `externalId` (your content id), `externalData` and subfields. Returned as JSON string in `fields`.
|
|
166
198
|
|
|
167
199
|
##### Returns
|
|
168
200
|
|
|
@@ -172,12 +204,23 @@ client.user.recommendations(options?: RecommendationsRequest): Promise<Recommend
|
|
|
172
204
|
|
|
173
205
|
##### RecommendationItem
|
|
174
206
|
|
|
175
|
-
- `id?: string`: Your article ID
|
|
176
207
|
- `assetId?: string`: BitBitPress's ID
|
|
177
|
-
- `title?: string`: Article title
|
|
178
|
-
- `content?: string`: Article content
|
|
179
|
-
- `publishedAt?: string`: Publication date (e.g., "2021-01-01")
|
|
180
208
|
- `score?: number`: Recommendation score (e.g., 0.95)
|
|
209
|
+
- `fields?: string`: JSON string of requested asset fields (when `fields` provided in request)
|
|
210
|
+
|
|
211
|
+
##### Available Fields
|
|
212
|
+
|
|
213
|
+
Use dot or bracket notation (e.g. `tags[0]`, `images[1].src`). Requested values are returned as a JSON string in each item's `fields` property.
|
|
214
|
+
|
|
215
|
+
| Field | Type | Structure |
|
|
216
|
+
|-------|------|-----------|
|
|
217
|
+
| `title` | string | Title |
|
|
218
|
+
| `tags` | string[] | Array of strings (auto-extracted or manual tags) |
|
|
219
|
+
| `images` | array | Each item: `{ src, externalId, alt, width, height, credit }` |
|
|
220
|
+
| `videos` | array | Each item: `{ sources: [{ mimeType, src }], externalId, alt, credit, posterUrl, caption, width, height }` |
|
|
221
|
+
| `publishedAt` | string | ISO date when the article was originally published |
|
|
222
|
+
| `externalId` | string | unique identifier from source (your content id) |
|
|
223
|
+
| `externalData` | any | data unique to your content (you must extract subfields that you need from your article data type) |
|
|
181
224
|
|
|
182
225
|
##### Example
|
|
183
226
|
|
|
@@ -185,10 +228,54 @@ client.user.recommendations(options?: RecommendationsRequest): Promise<Recommend
|
|
|
185
228
|
const recommendations = await client.user.recommendations({
|
|
186
229
|
limit: 10,
|
|
187
230
|
cursor: 'optional-cursor-from-previous-response',
|
|
231
|
+
fields: ['title', 'tags', 'images[0].src', 'publishedAt'],
|
|
188
232
|
});
|
|
189
233
|
|
|
190
234
|
console.log('Recommendations:', recommendations.items);
|
|
191
235
|
console.log('Next cursor:', recommendations.cursor);
|
|
236
|
+
|
|
237
|
+
// Access requested fields from the fields JSON string
|
|
238
|
+
if (recommendations.items) {
|
|
239
|
+
for (const item of recommendations.items) {
|
|
240
|
+
if (item.fields) {
|
|
241
|
+
const fields = JSON.parse(item.fields);
|
|
242
|
+
console.log('Title:', fields.title);
|
|
243
|
+
console.log('Tags:', fields.tags);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
##### Throws
|
|
250
|
+
|
|
251
|
+
- `Error`: If the request fails or no data is returned
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
#### report
|
|
256
|
+
|
|
257
|
+
Report a bit (create a user-provided bit to be ingested into the system). This may include news or any other content that the user wants to share.
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
client.user.report(options: ReportRequest): Promise<ReportResponse>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
##### Parameters
|
|
264
|
+
|
|
265
|
+
- `options.title` (optional): Title of the reported content
|
|
266
|
+
- `options.content` (required): Content body of the report
|
|
267
|
+
|
|
268
|
+
##### Returns
|
|
269
|
+
|
|
270
|
+
- `Promise<ReportResponse>`: Response containing the report data
|
|
271
|
+
|
|
272
|
+
##### Example
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
await client.user.report({
|
|
276
|
+
title: 'Breaking News: Important Update',
|
|
277
|
+
content: 'This is the content of the news article or bit that the user wants to share.',
|
|
278
|
+
});
|
|
192
279
|
```
|
|
193
280
|
|
|
194
281
|
##### Throws
|
|
@@ -199,7 +286,7 @@ console.log('Next cursor:', recommendations.cursor);
|
|
|
199
286
|
|
|
200
287
|
#### signal
|
|
201
288
|
|
|
202
|
-
Record
|
|
289
|
+
Record user signals (e.g., clicked topic, read article) to inform profile interests. Signals are used to power a user's recommendations.
|
|
203
290
|
|
|
204
291
|
```typescript
|
|
205
292
|
client.user.signal(options: SignalRequest): Promise<SignalResponse>
|
|
@@ -207,25 +294,88 @@ client.user.signal(options: SignalRequest): Promise<SignalResponse>
|
|
|
207
294
|
|
|
208
295
|
##### Parameters
|
|
209
296
|
|
|
210
|
-
- `options.
|
|
211
|
-
- `
|
|
212
|
-
- `"active"
|
|
213
|
-
|
|
214
|
-
- `
|
|
215
|
-
- `
|
|
216
|
-
- `
|
|
217
|
-
|
|
297
|
+
- `options.signals` (required): Array of signals to record. Each signal object contains:
|
|
298
|
+
- `signal` (required): User action with the text associated with the interaction (e.g., `'searched for \"best restaurants\"'`)
|
|
299
|
+
- `type` (required): Signal type - `"active"` or `"passive"`
|
|
300
|
+
- `"active"`: Explicit intent (click, search, subscribe)
|
|
301
|
+
- `"passive"`: Implicit intent (read, scroll, dwell)
|
|
302
|
+
- `negative` (optional): When `true`, indicates the signal is negative (e.g., dislike, unfollow). Defaults to `false`. Use sparingly.
|
|
303
|
+
- `contentContext` (optional): Context about the content that triggered this signal
|
|
304
|
+
- `contentId` (required): The ID of the content (e.g., your article ID)
|
|
305
|
+
- `contentType` (required): The type of content (currently only `"article"`)
|
|
218
306
|
|
|
219
307
|
##### Returns
|
|
220
308
|
|
|
221
309
|
- `Promise<SignalResponse>`: Response containing:
|
|
222
|
-
- `recorded?: boolean`: Whether the
|
|
310
|
+
- `recorded?: boolean`: Whether the signals were recorded (false if no user or no valid signals)
|
|
223
311
|
|
|
224
312
|
##### Example
|
|
225
313
|
|
|
226
314
|
```typescript
|
|
227
|
-
//
|
|
315
|
+
// Record multiple signals at once
|
|
228
316
|
await client.user.signal({
|
|
317
|
+
signals: [
|
|
318
|
+
{
|
|
319
|
+
signal: 'searched "best restaurants"',
|
|
320
|
+
type: 'active',
|
|
321
|
+
contentContext: {
|
|
322
|
+
contentId: 'article-123',
|
|
323
|
+
contentType: 'article',
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
signal: 'read article about NBA trades',
|
|
328
|
+
type: 'passive',
|
|
329
|
+
contentContext: {
|
|
330
|
+
contentId: 'article-456',
|
|
331
|
+
contentType: 'article',
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
signal: 'unfollowed topic "Politics"',
|
|
336
|
+
type: 'active',
|
|
337
|
+
negative: true,
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
##### Throws
|
|
344
|
+
|
|
345
|
+
- `Error`: If the request fails or no data is returned
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
#### signalItem
|
|
350
|
+
|
|
351
|
+
Record a single signal (batched). Signals are automatically batched and sent together after the configured timeout.
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
client.user.signalItem(signal: Signal): Promise<SignalResponse>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
##### Parameters
|
|
358
|
+
|
|
359
|
+
- `signal` (required): A single signal object (same format as items in the `signals` array for `signal`)
|
|
360
|
+
|
|
361
|
+
##### Returns
|
|
362
|
+
|
|
363
|
+
- `Promise<SignalResponse>`: Response containing:
|
|
364
|
+
- `recorded?: boolean`: Whether the signal was recorded (false if no user or no valid signals)
|
|
365
|
+
|
|
366
|
+
##### Behavior
|
|
367
|
+
|
|
368
|
+
- Signals added within the batch timeout window (default: 250ms) are grouped together and sent in a single request
|
|
369
|
+
- Each signal's promise resolves with the batch response when the request completes
|
|
370
|
+
- The batching happens in the background - promises resolve as soon as the batch request completes
|
|
371
|
+
- The batch timeout can be configured when creating the client via `signalBatchTimeout`
|
|
372
|
+
|
|
373
|
+
##### Example
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
// Signals are automatically batched and sent together after the timeout
|
|
377
|
+
// Each promise resolves with the batch response
|
|
378
|
+
const response1 = await client.user.signalItem({
|
|
229
379
|
signal: 'searched "best restaurants"',
|
|
230
380
|
type: 'active',
|
|
231
381
|
contentContext: {
|
|
@@ -234,8 +384,7 @@ await client.user.signal({
|
|
|
234
384
|
},
|
|
235
385
|
});
|
|
236
386
|
|
|
237
|
-
|
|
238
|
-
await client.user.signal({
|
|
387
|
+
const response2 = await client.user.signalItem({
|
|
239
388
|
signal: 'read article about NBA trades',
|
|
240
389
|
type: 'passive',
|
|
241
390
|
contentContext: {
|
|
@@ -244,12 +393,10 @@ await client.user.signal({
|
|
|
244
393
|
},
|
|
245
394
|
});
|
|
246
395
|
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
negative: true,
|
|
252
|
-
});
|
|
396
|
+
// Both signals are sent together in a single batch request
|
|
397
|
+
// Each promise resolves when the batch request completes
|
|
398
|
+
console.log('Signal 1 recorded:', response1.recorded);
|
|
399
|
+
console.log('Signal 2 recorded:', response2.recorded);
|
|
253
400
|
```
|
|
254
401
|
|
|
255
402
|
##### Throws
|
|
@@ -330,6 +477,7 @@ client.user.synthesize(items: SynthesizeRequest['items']): Promise<AsyncIterable
|
|
|
330
477
|
|
|
331
478
|
- `fieldName` (required): Name of the field
|
|
332
479
|
- `fieldDescription` (required): A prompt describing the value of the field
|
|
480
|
+
- `fieldCharacterLimit` (optional): The maximum number of characters that can be returned for this field
|
|
333
481
|
|
|
334
482
|
##### ContentContext (required for CUSTOM items)
|
|
335
483
|
|
|
@@ -400,6 +548,7 @@ interface BitBitPressClientConfig {
|
|
|
400
548
|
headers?: Record<string, string>;
|
|
401
549
|
timeout?: number;
|
|
402
550
|
synthesizeBatchTimeout?: number;
|
|
551
|
+
signalBatchTimeout?: number;
|
|
403
552
|
}
|
|
404
553
|
```
|
|
405
554
|
|
|
@@ -428,6 +577,15 @@ type TokenResponse = {
|
|
|
428
577
|
type RecommendationsRequest = {
|
|
429
578
|
limit?: number;
|
|
430
579
|
cursor?: string;
|
|
580
|
+
fields?: string[];
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
#### ProfileResponse
|
|
585
|
+
|
|
586
|
+
```typescript
|
|
587
|
+
type ProfileResponse = {
|
|
588
|
+
suggestedInterestTopics?: string[];
|
|
431
589
|
}
|
|
432
590
|
```
|
|
433
591
|
|
|
@@ -436,22 +594,49 @@ type RecommendationsRequest = {
|
|
|
436
594
|
```typescript
|
|
437
595
|
type RecommendationsResponse = {
|
|
438
596
|
items?: Array<{
|
|
439
|
-
id?: string;
|
|
440
597
|
assetId?: string;
|
|
441
|
-
title?: string;
|
|
442
|
-
summary?: string;
|
|
443
|
-
content?: string;
|
|
444
|
-
publishedAt?: string;
|
|
445
598
|
score?: number;
|
|
599
|
+
fields?: string; // JSON string of requested asset fields
|
|
446
600
|
}>;
|
|
447
601
|
cursor?: string;
|
|
448
602
|
}
|
|
449
603
|
```
|
|
450
604
|
|
|
605
|
+
#### ReportRequest
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
type ReportRequest = {
|
|
609
|
+
title?: string;
|
|
610
|
+
content: string;
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
#### ReportResponse
|
|
615
|
+
|
|
616
|
+
```typescript
|
|
617
|
+
type ReportResponse = unknown;
|
|
618
|
+
```
|
|
619
|
+
|
|
451
620
|
#### SignalRequest
|
|
452
621
|
|
|
453
622
|
```typescript
|
|
454
623
|
type SignalRequest = {
|
|
624
|
+
signals: Array<{
|
|
625
|
+
signal: string;
|
|
626
|
+
type: 'active' | 'passive';
|
|
627
|
+
negative?: boolean;
|
|
628
|
+
contentContext?: {
|
|
629
|
+
contentId: string;
|
|
630
|
+
contentType: 'article';
|
|
631
|
+
};
|
|
632
|
+
}>;
|
|
633
|
+
}
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
#### Signal
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
type Signal = {
|
|
455
640
|
signal: string;
|
|
456
641
|
type: 'active' | 'passive';
|
|
457
642
|
negative?: boolean;
|
package/dist/client.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export interface BitBitPressClientConfig {
|
|
|
26
26
|
* @default 250
|
|
27
27
|
*/
|
|
28
28
|
synthesizeBatchTimeout?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Batch timeout for signalItem in milliseconds
|
|
31
|
+
* Signals will be batched and sent after this delay
|
|
32
|
+
* @default 250
|
|
33
|
+
*/
|
|
34
|
+
signalBatchTimeout?: number;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Options for creating a BitBitPress client instance
|
|
@@ -54,6 +60,10 @@ export declare class BitBitPressClient {
|
|
|
54
60
|
* Get synthesize batch timeout configuration
|
|
55
61
|
*/
|
|
56
62
|
private getSynthesizeBatchTimeout;
|
|
63
|
+
/**
|
|
64
|
+
* Get signal batch timeout configuration
|
|
65
|
+
*/
|
|
66
|
+
private getSignalBatchTimeout;
|
|
57
67
|
/**
|
|
58
68
|
* User-related API methods
|
|
59
69
|
* Provides type-safe access to user endpoints like signal, recommendations, synthesize, etc.
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,uBAAuB;CAAG;AAE5E;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CACyF;IACvG,OAAO,CAAC,mBAAmB,CAAC,CAAc;gBAE9B,OAAO,EAAE,wBAAwB;IAsB7C;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMjC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IASxB;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAIjC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;;OAGG;IACH,IAAI,IAAI,IAAI,WAAW,CAStB;CACF"}
|
package/dist/client.js
CHANGED
|
@@ -19,6 +19,7 @@ class BitBitPressClient {
|
|
|
19
19
|
baseUrl: options.baseUrl,
|
|
20
20
|
timeout: options.timeout ?? 30000,
|
|
21
21
|
synthesizeBatchTimeout: options.synthesizeBatchTimeout,
|
|
22
|
+
signalBatchTimeout: options.signalBatchTimeout,
|
|
22
23
|
fetch: options.fetch ?? (typeof globalThis !== 'undefined' ? globalThis.fetch : undefined),
|
|
23
24
|
headers: options.headers,
|
|
24
25
|
};
|
|
@@ -52,13 +53,19 @@ class BitBitPressClient {
|
|
|
52
53
|
getSynthesizeBatchTimeout() {
|
|
53
54
|
return this.config.synthesizeBatchTimeout;
|
|
54
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Get signal batch timeout configuration
|
|
58
|
+
*/
|
|
59
|
+
getSignalBatchTimeout() {
|
|
60
|
+
return this.config.signalBatchTimeout;
|
|
61
|
+
}
|
|
55
62
|
/**
|
|
56
63
|
* User-related API methods
|
|
57
64
|
* Provides type-safe access to user endpoints like signal, recommendations, synthesize, etc.
|
|
58
65
|
*/
|
|
59
66
|
get user() {
|
|
60
67
|
if (!this.userMethodsInstance) {
|
|
61
|
-
this.userMethodsInstance = (0, index_js_1.createUserMethods)(this.getRequestConfig(), this.getSynthesizeBatchTimeout());
|
|
68
|
+
this.userMethodsInstance = (0, index_js_1.createUserMethods)(this.getRequestConfig(), this.getSynthesizeBatchTimeout(), this.getSignalBatchTimeout());
|
|
62
69
|
}
|
|
63
70
|
return this.userMethodsInstance;
|
|
64
71
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,8CAAsE;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,8CAAsE;AA+CtE;;;;;GAKG;AACH,MAAa,iBAAiB;IACpB,MAAM,CACyF;IAC/F,mBAAmB,CAAe;IAE1C,YAAY,OAAiC;QAC3C,IAAI,C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;;OAGG;IACH,IAAI,IAAI;QACN,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC9B,IAAI,CAAC,mBAAmB,GAAG,IAAA,4BAAiB,EAC1C,IAAI,CAAC,gBAAgB,EAAE,EACvB,IAAI,CAAC,yBAAyB,EAAE,EAChC,IAAI,CAAC,qBAAqB,EAAE,CAC7B,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;CACF;AA5ED,8CA4EC"}
|
|
@@ -7,5 +7,6 @@ declare function basicExample(): Promise<void>;
|
|
|
7
7
|
declare function streamingExample(): Promise<void>;
|
|
8
8
|
declare function batchedSynthesisExample(): Promise<void>;
|
|
9
9
|
declare function signalExample(): Promise<void>;
|
|
10
|
-
|
|
10
|
+
declare function batchedSignalExample(): Promise<void>;
|
|
11
|
+
export { basicExample, streamingExample, batchedSynthesisExample, signalExample, batchedSignalExample };
|
|
11
12
|
//# sourceMappingURL=basic-usage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basic-usage.d.ts","sourceRoot":"","sources":["../../src/examples/basic-usage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,iBAAe,YAAY,
|
|
1
|
+
{"version":3,"file":"basic-usage.d.ts","sourceRoot":"","sources":["../../src/examples/basic-usage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,iBAAe,YAAY,kBA4B1B;AAGD,iBAAe,gBAAgB,kBAyC9B;AAGD,iBAAe,uBAAuB,kBA4BrC;AAGD,iBAAe,aAAa,kBAqC3B;AAGD,iBAAe,oBAAoB,kBAiClC;AAED,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,aAAa,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -16,14 +16,18 @@ async function basicExample() {
|
|
|
16
16
|
limit: 10,
|
|
17
17
|
});
|
|
18
18
|
console.log('Recommendations:', recommendations.items);
|
|
19
|
-
// Record
|
|
19
|
+
// Record user signals (e.g., user clicked on an article)
|
|
20
20
|
const signalResult = await client.user.signal({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
signals: [
|
|
22
|
+
{
|
|
23
|
+
signal: 'searched "best restaurants"',
|
|
24
|
+
type: 'active',
|
|
25
|
+
contentContext: {
|
|
26
|
+
contentId: 'article-123',
|
|
27
|
+
contentType: 'article',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
27
31
|
});
|
|
28
32
|
console.log('Signal recorded:', signalResult.recorded);
|
|
29
33
|
}
|
|
@@ -100,8 +104,47 @@ async function signalExample() {
|
|
|
100
104
|
});
|
|
101
105
|
// Authenticate first
|
|
102
106
|
await client.user.authenticate("your-user's-auth-sso-token");
|
|
103
|
-
// Record
|
|
107
|
+
// Record multiple signals at once
|
|
104
108
|
await client.user.signal({
|
|
109
|
+
signals: [
|
|
110
|
+
// Active signal (explicit intent like click, search, subscribe)
|
|
111
|
+
{
|
|
112
|
+
signal: 'clicked "Warriors intend to keep Jimmy Butler despite season-ending injury"',
|
|
113
|
+
type: 'active',
|
|
114
|
+
contentContext: {
|
|
115
|
+
contentId: 'article-123',
|
|
116
|
+
contentType: 'article',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
// Passive signal (implicit like read, scroll, dwell)
|
|
120
|
+
{
|
|
121
|
+
signal: 'read about NBA trades',
|
|
122
|
+
type: 'passive',
|
|
123
|
+
contentContext: {
|
|
124
|
+
contentId: 'article-456',
|
|
125
|
+
contentType: 'article',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
// Negative signal (e.g., dislike, unfollow) - use sparingly
|
|
129
|
+
{
|
|
130
|
+
signal: 'unfollowed topic "Politics"',
|
|
131
|
+
type: 'active',
|
|
132
|
+
negative: true,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// Example 5: Batched signals with signalItem
|
|
138
|
+
async function batchedSignalExample() {
|
|
139
|
+
const client = new BitBitPressClient({
|
|
140
|
+
baseUrl: 'https://your-control-room.api.dev.bitbitpress.com',
|
|
141
|
+
signalBatchTimeout: 250, // Optional: customize batch timeout
|
|
142
|
+
});
|
|
143
|
+
// Authenticate first
|
|
144
|
+
await client.user.authenticate("your-user's-auth-sso-token");
|
|
145
|
+
// Signals are automatically batched and sent together after the timeout
|
|
146
|
+
// Each promise resolves with the batch response
|
|
147
|
+
const response1 = await client.user.signalItem({
|
|
105
148
|
signal: 'clicked "Warriors intend to keep Jimmy Butler despite season-ending injury"',
|
|
106
149
|
type: 'active',
|
|
107
150
|
contentContext: {
|
|
@@ -109,8 +152,7 @@ async function signalExample() {
|
|
|
109
152
|
contentType: 'article',
|
|
110
153
|
},
|
|
111
154
|
});
|
|
112
|
-
|
|
113
|
-
await client.user.signal({
|
|
155
|
+
const response2 = await client.user.signalItem({
|
|
114
156
|
signal: 'read about NBA trades',
|
|
115
157
|
type: 'passive',
|
|
116
158
|
contentContext: {
|
|
@@ -118,12 +160,10 @@ async function signalExample() {
|
|
|
118
160
|
contentType: 'article',
|
|
119
161
|
},
|
|
120
162
|
});
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
negative: true,
|
|
126
|
-
});
|
|
163
|
+
// Both signals are sent together in a single batch request
|
|
164
|
+
// Each promise resolves when the batch request completes
|
|
165
|
+
console.log('Signal 1 recorded:', response1.recorded);
|
|
166
|
+
console.log('Signal 2 recorded:', response2.recorded);
|
|
127
167
|
}
|
|
128
|
-
export { basicExample, streamingExample, batchedSynthesisExample, signalExample };
|
|
168
|
+
export { basicExample, streamingExample, batchedSynthesisExample, signalExample, batchedSignalExample };
|
|
129
169
|
//# sourceMappingURL=basic-usage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basic-usage.js","sourceRoot":"","sources":["../../src/examples/basic-usage.ts"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