@embed-ai/sdk 0.1.1 → 0.1.3
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 +10 -2
- package/package.json +12 -4
- package/src/client.d.ts +15 -1
- package/src/client.js +43 -26
- package/src/feed/feed.d.ts +3 -3
- package/src/feed/feed.js +4 -2
- package/src/feed/index.js +22 -33
- package/src/feed/management.d.ts +4 -3
- package/src/feed/management.js +6 -10
- package/src/feed/namespace.d.ts +18 -16
- package/src/feed/namespace.js +24 -22
- package/src/index.js +21 -16
- package/src/interfaces/index.js +20 -11
- package/src/search/index.d.ts +2 -0
- package/src/search/index.js +14 -0
- package/src/search/item.d.ts +2 -0
- package/src/search/item.js +6 -0
- package/src/search/namespace.d.ts +118 -0
- package/src/search/namespace.js +137 -0
- package/src/search/user.d.ts +80 -0
- package/src/search/user.js +124 -0
- package/src/client.d.ts.map +0 -1
- package/src/client.js.map +0 -1
- package/src/feed/feed.d.ts.map +0 -1
- package/src/feed/feed.js.map +0 -1
- package/src/feed/index.d.ts.map +0 -1
- package/src/feed/index.js.map +0 -1
- package/src/feed/management.d.ts.map +0 -1
- package/src/feed/management.js.map +0 -1
- package/src/feed/namespace.d.ts.map +0 -1
- package/src/feed/namespace.js.map +0 -1
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/interfaces/http.d.ts.map +0 -1
- package/src/interfaces/http.js.map +0 -1
- package/src/interfaces/index.d.ts.map +0 -1
- package/src/interfaces/index.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.src.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -13,6 +13,14 @@ The core TypeScript package for embed APIs, featuring an Effect-based HTTP clien
|
|
|
13
13
|
- 📊 **Built-in logging** of failed requests and retries
|
|
14
14
|
- 🎯 **Selective retry logic** for different error types
|
|
15
15
|
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bun install @embed-ai/sdk effect
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> **Note:** `effect` is a peer dependency and must be installed alongside `@embed-ai/sdk`
|
|
23
|
+
|
|
16
24
|
## Quick Start
|
|
17
25
|
|
|
18
26
|
### Basic Usage
|
|
@@ -264,10 +272,10 @@ function getUserFriendlyError(error: unknown): string {
|
|
|
264
272
|
}
|
|
265
273
|
```
|
|
266
274
|
|
|
267
|
-
#### 3. **Implement
|
|
275
|
+
#### 3. **Implement Cache Strategies**
|
|
268
276
|
|
|
269
277
|
```typescript
|
|
270
|
-
async function
|
|
278
|
+
async function getFeedWithCache(userId: string) {
|
|
271
279
|
try {
|
|
272
280
|
return await client.feed.byUserId(userId)
|
|
273
281
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embed-ai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"main": "src/index.js",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"description": "The typescript sdk package for embed AI APIs.",
|
|
7
7
|
"repository": {
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
"url": "https://github.com/ZKAI-Network/embed-sdk/",
|
|
10
10
|
"directory": "packages/sdk"
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src/**/*.js",
|
|
14
|
+
"src/**/*.d.ts",
|
|
15
|
+
"!src/**/*.map",
|
|
16
|
+
"!**/*.tsbuildinfo"
|
|
17
|
+
],
|
|
12
18
|
"publishConfig": {
|
|
13
19
|
"access": "public",
|
|
14
20
|
"directory": "dist"
|
|
@@ -24,8 +30,10 @@
|
|
|
24
30
|
"coverage": "vitest --coverage"
|
|
25
31
|
},
|
|
26
32
|
"dependencies": {
|
|
27
|
-
"@embed-ai/types": "^0.1.
|
|
28
|
-
|
|
33
|
+
"@embed-ai/types": "^0.1.2"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"effect": ">=3.0.0"
|
|
29
37
|
},
|
|
30
38
|
"types": "src/index.d.ts"
|
|
31
39
|
}
|
package/src/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FeedNamespace } from "./feed/namespace.js";
|
|
2
|
+
import { SearchNamespace } from "./search/namespace.js";
|
|
2
3
|
declare const NetworkError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
3
4
|
readonly _tag: "NetworkError";
|
|
4
5
|
} & Readonly<A>;
|
|
@@ -105,7 +106,7 @@ export interface mbdClientConfig {
|
|
|
105
106
|
readonly retry?: RetryConfig;
|
|
106
107
|
}
|
|
107
108
|
/**
|
|
108
|
-
* Main Embed API client providing access to personalized feeds
|
|
109
|
+
* Main Embed API client providing access to personalized feeds, feed management, and search
|
|
109
110
|
*
|
|
110
111
|
* @example
|
|
111
112
|
* ```typescript
|
|
@@ -121,11 +122,18 @@ export interface mbdClientConfig {
|
|
|
121
122
|
* name: 'My Custom Feed',
|
|
122
123
|
* description: 'A feed for my app'
|
|
123
124
|
* })
|
|
125
|
+
*
|
|
126
|
+
* // Search for similar users
|
|
127
|
+
* const similarUsers = await client.search.users.similar('16085')
|
|
128
|
+
*
|
|
129
|
+
* // Search users by query
|
|
130
|
+
* const users = await client.search.users.byQuery('web3 developers')
|
|
124
131
|
* ```
|
|
125
132
|
*/
|
|
126
133
|
export declare class mbdClient {
|
|
127
134
|
private http;
|
|
128
135
|
readonly feed: FeedNamespace;
|
|
136
|
+
readonly search: SearchNamespace;
|
|
129
137
|
constructor(token?: string, options?: mbdClientConfig);
|
|
130
138
|
}
|
|
131
139
|
/**
|
|
@@ -151,6 +159,12 @@ export declare class mbdClient {
|
|
|
151
159
|
* description: 'A feed for my app'
|
|
152
160
|
* })
|
|
153
161
|
*
|
|
162
|
+
* // Search for similar users
|
|
163
|
+
* const similarUsers = await client.search.users.similar('16085')
|
|
164
|
+
*
|
|
165
|
+
* // Search users by query
|
|
166
|
+
* const users = await client.search.users.byQuery('web3 developers')
|
|
167
|
+
*
|
|
154
168
|
* // With configuration
|
|
155
169
|
* const client = getClient('your-api-key', {
|
|
156
170
|
* retry: {
|
package/src/client.js
CHANGED
|
@@ -3,37 +3,40 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TimeoutError = exports.ParseError = exports.
|
|
6
|
+
exports.mbdClient = exports.TimeoutError = exports.ParseError = exports.HttpRequestError = exports.NetworkError = void 0;
|
|
7
7
|
exports.getClient = getClient;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const effect_1 = /*#__PURE__*/require("effect");
|
|
9
|
+
const Data = /*#__PURE__*/require("effect/Data");
|
|
10
|
+
const Effect = /*#__PURE__*/require("effect/Effect");
|
|
11
|
+
const Schedule = /*#__PURE__*/require("effect/Schedule");
|
|
12
|
+
const namespace_js_1 = /*#__PURE__*/require("./feed/namespace.js");
|
|
13
|
+
const namespace_js_2 = /*#__PURE__*/require("./search/namespace.js");
|
|
11
14
|
// ============================================================================
|
|
12
15
|
// ERROR TYPES
|
|
13
16
|
// ============================================================================
|
|
14
17
|
/**
|
|
15
18
|
* Network-related errors (connection issues, DNS failures, etc.)
|
|
16
19
|
*/
|
|
17
|
-
class NetworkError extends
|
|
20
|
+
class NetworkError extends Data.TaggedError("NetworkError") {}
|
|
21
|
+
exports.NetworkError = NetworkError;
|
|
18
22
|
/**
|
|
19
23
|
* HTTP response errors (4xx, 5xx status codes)
|
|
20
24
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
class HttpRequestError extends Data.TaggedError("HttpRequestError") {}
|
|
26
|
+
exports.HttpRequestError = HttpRequestError;
|
|
23
27
|
/**
|
|
24
28
|
* JSON parsing errors
|
|
25
29
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
class ParseError extends Data.TaggedError("ParseError") {}
|
|
31
|
+
exports.ParseError = ParseError;
|
|
28
32
|
/**
|
|
29
33
|
* Timeout errors
|
|
30
34
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
class TimeoutError extends Data.TaggedError("TimeoutError") {}
|
|
36
|
+
exports.TimeoutError = TimeoutError;
|
|
33
37
|
/**
|
|
34
38
|
* Default retry configuration
|
|
35
39
|
*/
|
|
36
|
-
exports.TimeoutError = TimeoutError;
|
|
37
40
|
const DEFAULT_RETRY_CONFIG = {
|
|
38
41
|
exponentialBackoff: true,
|
|
39
42
|
initialDelay: 1000,
|
|
@@ -73,7 +76,7 @@ class HttpClient {
|
|
|
73
76
|
* Create a timeout effect that fails after the specified duration
|
|
74
77
|
*/
|
|
75
78
|
createTimeoutEffect(timeoutMs) {
|
|
76
|
-
return (0,
|
|
79
|
+
return (0, effect_1.pipe)(Effect.sleep(`${timeoutMs} millis`), Effect.flatMap(() => Effect.fail(new TimeoutError({
|
|
77
80
|
message: `Request timed out after ${timeoutMs}ms`,
|
|
78
81
|
timeoutMs
|
|
79
82
|
}))));
|
|
@@ -100,7 +103,7 @@ class HttpClient {
|
|
|
100
103
|
*/
|
|
101
104
|
performFetch(endpoint, method, baseUrl, body, queryParams, useBasicAuth) {
|
|
102
105
|
const url = this.buildUrl(endpoint, baseUrl, queryParams);
|
|
103
|
-
return
|
|
106
|
+
return Effect.tryPromise({
|
|
104
107
|
try: async () => {
|
|
105
108
|
const requestOptions = {
|
|
106
109
|
method,
|
|
@@ -166,12 +169,12 @@ class HttpClient {
|
|
|
166
169
|
} = this.config.retry;
|
|
167
170
|
let baseSchedule;
|
|
168
171
|
if (exponentialBackoff) {
|
|
169
|
-
baseSchedule = (0,
|
|
172
|
+
baseSchedule = (0, effect_1.pipe)(Schedule.exponential(`${initialDelay} millis`), Schedule.either(Schedule.spaced(`${maxDelay} millis`)), Schedule.compose(Schedule.recurs(maxRetries)));
|
|
170
173
|
} else {
|
|
171
|
-
baseSchedule = (0,
|
|
174
|
+
baseSchedule = (0, effect_1.pipe)(Schedule.spaced(`${initialDelay} millis`), Schedule.compose(Schedule.recurs(maxRetries)));
|
|
172
175
|
}
|
|
173
176
|
// Only retry on specific errors
|
|
174
|
-
return (0,
|
|
177
|
+
return (0, effect_1.pipe)(baseSchedule, Schedule.whileInput(error => {
|
|
175
178
|
switch (error._tag) {
|
|
176
179
|
case "NetworkError":
|
|
177
180
|
return true;
|
|
@@ -196,45 +199,45 @@ class HttpClient {
|
|
|
196
199
|
const fetchEffect = this.performFetch(endpoint, method, baseUrl, body, queryParams, useBasicAuth);
|
|
197
200
|
const timeoutEffect = this.createTimeoutEffect(this.config.retry.timeoutMs);
|
|
198
201
|
// Race fetch against timeout
|
|
199
|
-
const requestWithTimeout =
|
|
202
|
+
const requestWithTimeout = Effect.race(fetchEffect, timeoutEffect);
|
|
200
203
|
// Apply retry logic
|
|
201
204
|
const retrySchedule = this.createRetrySchedule();
|
|
202
|
-
return (0,
|
|
205
|
+
return (0, effect_1.pipe)(requestWithTimeout, Effect.retry(retrySchedule), Effect.tapError(error => Effect.logError("HTTP request failed after retries", error)));
|
|
203
206
|
}
|
|
204
207
|
/**
|
|
205
208
|
* Make a POST request to the API with Effect-based error handling and retries
|
|
206
209
|
*/
|
|
207
210
|
async post(endpoint, body) {
|
|
208
211
|
const effect = this.executeRequestWithRetries(endpoint, "POST", undefined, body);
|
|
209
|
-
return
|
|
212
|
+
return Effect.runPromise(effect);
|
|
210
213
|
}
|
|
211
214
|
/**
|
|
212
215
|
* Make a GET request to the API with Effect-based error handling and retries
|
|
213
216
|
*/
|
|
214
217
|
async get(endpoint, queryParams) {
|
|
215
218
|
const effect = this.executeRequestWithRetries(endpoint, "GET", undefined, undefined, queryParams);
|
|
216
|
-
return
|
|
219
|
+
return Effect.runPromise(effect);
|
|
217
220
|
}
|
|
218
221
|
/**
|
|
219
222
|
* Make a PATCH request to the API with Effect-based error handling and retries
|
|
220
223
|
*/
|
|
221
224
|
async patch(endpoint, body) {
|
|
222
225
|
const effect = this.executeRequestWithRetries(endpoint, "PATCH", undefined, body);
|
|
223
|
-
return
|
|
226
|
+
return Effect.runPromise(effect);
|
|
224
227
|
}
|
|
225
228
|
/**
|
|
226
229
|
* Make a request to a custom base URL
|
|
227
230
|
*/
|
|
228
231
|
async requestWithCustomBaseUrl(method, baseUrl, endpoint, body, queryParams, useBasicAuth) {
|
|
229
232
|
const effect = this.executeRequestWithRetries(endpoint, method, baseUrl, body, queryParams, useBasicAuth);
|
|
230
|
-
return
|
|
233
|
+
return Effect.runPromise(effect);
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
// ============================================================================
|
|
234
237
|
// MAIN CLIENT
|
|
235
238
|
// ============================================================================
|
|
236
239
|
/**
|
|
237
|
-
* Main Embed API client providing access to personalized feeds
|
|
240
|
+
* Main Embed API client providing access to personalized feeds, feed management, and search
|
|
238
241
|
*
|
|
239
242
|
* @example
|
|
240
243
|
* ```typescript
|
|
@@ -250,11 +253,18 @@ class HttpClient {
|
|
|
250
253
|
* name: 'My Custom Feed',
|
|
251
254
|
* description: 'A feed for my app'
|
|
252
255
|
* })
|
|
256
|
+
*
|
|
257
|
+
* // Search for similar users
|
|
258
|
+
* const similarUsers = await client.search.users.similar('16085')
|
|
259
|
+
*
|
|
260
|
+
* // Search users by query
|
|
261
|
+
* const users = await client.search.users.byQuery('web3 developers')
|
|
253
262
|
* ```
|
|
254
263
|
*/
|
|
255
264
|
class mbdClient {
|
|
256
265
|
http;
|
|
257
266
|
feed;
|
|
267
|
+
search;
|
|
258
268
|
constructor(token, options) {
|
|
259
269
|
if (!token && !options?.token) {
|
|
260
270
|
throw new Error("Token is required");
|
|
@@ -264,9 +274,11 @@ class mbdClient {
|
|
|
264
274
|
...options
|
|
265
275
|
};
|
|
266
276
|
this.http = new HttpClient(config);
|
|
267
|
-
this.feed = new
|
|
277
|
+
this.feed = new namespace_js_1.FeedNamespace(this.http);
|
|
278
|
+
this.search = new namespace_js_2.SearchNamespace(this.http);
|
|
268
279
|
}
|
|
269
280
|
}
|
|
281
|
+
exports.mbdClient = mbdClient;
|
|
270
282
|
/**
|
|
271
283
|
* Get a new Embed Client instance
|
|
272
284
|
*
|
|
@@ -290,6 +302,12 @@ class mbdClient {
|
|
|
290
302
|
* description: 'A feed for my app'
|
|
291
303
|
* })
|
|
292
304
|
*
|
|
305
|
+
* // Search for similar users
|
|
306
|
+
* const similarUsers = await client.search.users.similar('16085')
|
|
307
|
+
*
|
|
308
|
+
* // Search users by query
|
|
309
|
+
* const users = await client.search.users.byQuery('web3 developers')
|
|
310
|
+
*
|
|
293
311
|
* // With configuration
|
|
294
312
|
* const client = getClient('your-api-key', {
|
|
295
313
|
* retry: {
|
|
@@ -299,7 +317,6 @@ class mbdClient {
|
|
|
299
317
|
* })
|
|
300
318
|
* ```
|
|
301
319
|
*/
|
|
302
|
-
exports.mbdClient = mbdClient;
|
|
303
320
|
function getClient(token, options) {
|
|
304
321
|
return new mbdClient(token, options);
|
|
305
322
|
}
|
package/src/feed/feed.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ForYou as ForYouParams, ForYouResponse } from "@embed-ai/types";
|
|
2
2
|
import type { IHttpClient } from "../interfaces/index.js";
|
|
3
|
-
export type FeedOptions = Omit<ForYouParams, "wallet_address" | "user_id">;
|
|
4
|
-
export declare function byUserId(httpClient: IHttpClient, userId: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
5
|
-
export declare function byWalletAddress(httpClient: IHttpClient, walletAddress: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
3
|
+
export type FeedOptions = Omit<ForYouParams, "wallet_address" | "user_id" | "feed_id">;
|
|
4
|
+
export declare function byUserId(httpClient: IHttpClient, userId: string, feedId?: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
5
|
+
export declare function byWalletAddress(httpClient: IHttpClient, walletAddress: string, feedId?: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
6
6
|
//# sourceMappingURL=feed.d.ts.map
|
package/src/feed/feed.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.byUserId = byUserId;
|
|
7
7
|
exports.byWalletAddress = byWalletAddress;
|
|
8
|
-
async function byUserId(httpClient, userId, options) {
|
|
8
|
+
async function byUserId(httpClient, userId, feedId, options) {
|
|
9
9
|
const top_k = options?.top_k ?? 25;
|
|
10
10
|
const impression_count = options?.impression_count ?? top_k;
|
|
11
11
|
const params = {
|
|
@@ -13,12 +13,13 @@ async function byUserId(httpClient, userId, options) {
|
|
|
13
13
|
return_metadata: true,
|
|
14
14
|
top_k,
|
|
15
15
|
impression_count,
|
|
16
|
+
feed_id: feedId,
|
|
16
17
|
...options
|
|
17
18
|
};
|
|
18
19
|
const response = await httpClient.post("/v2/farcaster/casts/feed/for-you", params);
|
|
19
20
|
return [...response.body];
|
|
20
21
|
}
|
|
21
|
-
async function byWalletAddress(httpClient, walletAddress, options) {
|
|
22
|
+
async function byWalletAddress(httpClient, walletAddress, feedId, options) {
|
|
22
23
|
const top_k = options?.top_k ?? 25;
|
|
23
24
|
const impression_count = options?.impression_count ?? top_k;
|
|
24
25
|
const params = {
|
|
@@ -26,6 +27,7 @@ async function byWalletAddress(httpClient, walletAddress, options) {
|
|
|
26
27
|
return_metadata: true,
|
|
27
28
|
top_k,
|
|
28
29
|
impression_count,
|
|
30
|
+
feed_id: feedId,
|
|
29
31
|
...options
|
|
30
32
|
};
|
|
31
33
|
const response = await httpClient.post("/v2/farcaster/casts/feed/for-you", params);
|
package/src/feed/index.js
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
3
22
|
Object.defineProperty(exports, "__esModule", {
|
|
4
23
|
value: true
|
|
5
24
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (key in exports && exports[key] === _feed[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _feed[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _management = require("./management.js");
|
|
18
|
-
Object.keys(_management).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _management[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _management[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _namespace = require("./namespace.js");
|
|
29
|
-
Object.keys(_namespace).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _namespace[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _namespace[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
25
|
+
__exportStar(require("./feed.js"), exports);
|
|
26
|
+
__exportStar(require("./management.js"), exports);
|
|
27
|
+
__exportStar(require("./namespace.js"), exports);
|
|
39
28
|
//# sourceMappingURL=index.js.map
|
package/src/feed/management.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { CreateFeedOptions, FeedCreateUpdateResponse, FeedGetResponse, ListFeedsResponse, UpdateFeedOptions } from "@embed-ai/types";
|
|
2
2
|
import type { IHttpClient } from "../interfaces/index.js";
|
|
3
|
+
export type UpdateFeedParams = Omit<UpdateFeedOptions, "config_id">;
|
|
3
4
|
export declare function createConfig(httpClient: IHttpClient, options: CreateFeedOptions): Promise<FeedCreateUpdateResponse>;
|
|
4
|
-
export declare function getConfig(httpClient: IHttpClient,
|
|
5
|
-
export declare function listConfigs(httpClient: IHttpClient, visibility?: "private" | "public"): Promise<ListFeedsResponse>;
|
|
6
|
-
export declare function updateConfig(httpClient: IHttpClient, options:
|
|
5
|
+
export declare function getConfig(httpClient: IHttpClient, feedId: string): Promise<FeedGetResponse>;
|
|
6
|
+
export declare function listConfigs(httpClient: IHttpClient, visibility?: "private" | "template" | "public"): Promise<ListFeedsResponse>;
|
|
7
|
+
export declare function updateConfig(httpClient: IHttpClient, feedId: string, options: UpdateFeedParams): Promise<void>;
|
|
7
8
|
//# sourceMappingURL=management.d.ts.map
|
package/src/feed/management.js
CHANGED
|
@@ -40,9 +40,9 @@ async function createConfig(httpClient, options) {
|
|
|
40
40
|
);
|
|
41
41
|
return response.data;
|
|
42
42
|
}
|
|
43
|
-
async function getConfig(httpClient,
|
|
43
|
+
async function getConfig(httpClient, feedId) {
|
|
44
44
|
const response = await httpClient.requestWithCustomBaseUrl("GET", CONSOLE_API_BASE_URL, "/api/feed/config", undefined, {
|
|
45
|
-
config_id:
|
|
45
|
+
config_id: feedId
|
|
46
46
|
}, true // Use Basic auth
|
|
47
47
|
);
|
|
48
48
|
return response.data;
|
|
@@ -55,20 +55,16 @@ async function listConfigs(httpClient, visibility = "private") {
|
|
|
55
55
|
);
|
|
56
56
|
return [...response.data];
|
|
57
57
|
}
|
|
58
|
-
async function updateConfig(httpClient, options) {
|
|
58
|
+
async function updateConfig(httpClient, feedId, options) {
|
|
59
59
|
// First get the current feed configuration
|
|
60
|
-
const currentFeed = await getConfig(httpClient,
|
|
61
|
-
const {
|
|
62
|
-
config_id: _config_id,
|
|
63
|
-
...updateOptions
|
|
64
|
-
} = options;
|
|
60
|
+
const currentFeed = await getConfig(httpClient, feedId);
|
|
65
61
|
// Merge the current configuration with the updates
|
|
66
62
|
const updatedConfig = {
|
|
67
63
|
...currentFeed,
|
|
68
|
-
...
|
|
64
|
+
...options,
|
|
69
65
|
config: {
|
|
70
66
|
...currentFeed.config,
|
|
71
|
-
...
|
|
67
|
+
...options.config
|
|
72
68
|
}
|
|
73
69
|
};
|
|
74
70
|
await httpClient.requestWithCustomBaseUrl("PATCH", CONSOLE_API_BASE_URL, "/api/feed/config", updatedConfig, undefined, true // Use Basic auth
|
package/src/feed/namespace.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateFeedOptions, FeedCreateUpdateResponse, FeedGetResponse, ForYouResponse, ListFeedsResponse
|
|
1
|
+
import type { CreateFeedOptions, FeedCreateUpdateResponse, FeedGetResponse, ForYouResponse, ListFeedsResponse } from "@embed-ai/types";
|
|
2
2
|
import type { IHttpClient } from "../interfaces/index.js";
|
|
3
3
|
import type { FeedOptions } from "./feed.js";
|
|
4
4
|
/**
|
|
@@ -8,8 +8,8 @@ import type { FeedOptions } from "./feed.js";
|
|
|
8
8
|
* ```typescript
|
|
9
9
|
* const client = getClient('your-api-key')
|
|
10
10
|
*
|
|
11
|
-
* // Get personalized feed
|
|
12
|
-
* const feed = await client.feed.byUserId('16085')
|
|
11
|
+
* // Get personalized feed based on the For-You template
|
|
12
|
+
* const feed = await client.feed.byUserId('16085', 'feed_390')
|
|
13
13
|
*
|
|
14
14
|
* // Create a custom feed
|
|
15
15
|
* const customFeed = await client.feed.createConfig({
|
|
@@ -25,13 +25,14 @@ export declare class FeedNamespace {
|
|
|
25
25
|
* Get personalized "For You" feed by user ID
|
|
26
26
|
*
|
|
27
27
|
* @param userId - The Farcaster user ID to get personalized feed for
|
|
28
|
+
* @param feedId - The feed ID to use for the request
|
|
28
29
|
* @param options - Optional configuration for feed generation
|
|
29
30
|
* @returns Promise<ForYouFeedItem[]> - Array of personalized feed items
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
32
33
|
* ```typescript
|
|
33
34
|
* const client = getClient("your-api-key")
|
|
34
|
-
* const feed = await client.feed.byUserId("16085", {
|
|
35
|
+
* const feed = await client.feed.byUserId("16085", "feed_390", {
|
|
35
36
|
* top_k: 10,
|
|
36
37
|
* return_metadata: true
|
|
37
38
|
* })
|
|
@@ -39,25 +40,26 @@ export declare class FeedNamespace {
|
|
|
39
40
|
* console.log(feed[0].metadata?.author.username) // Access author username
|
|
40
41
|
* ```
|
|
41
42
|
*/
|
|
42
|
-
byUserId(userId: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
43
|
+
byUserId(userId: string, feedId?: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
43
44
|
/**
|
|
44
45
|
* Get personalized "For You" feed by wallet address
|
|
45
46
|
*
|
|
46
47
|
* @param walletAddress - The user's wallet address to get personalized feed for
|
|
48
|
+
* @param feedId - The feed ID to use for the request
|
|
47
49
|
* @param options - Optional configuration for feed generation
|
|
48
50
|
* @returns Promise<ForYouFeedItem[]> - Array of personalized feed items
|
|
49
51
|
*
|
|
50
52
|
* @example
|
|
51
53
|
* ```typescript
|
|
52
54
|
* const client = getClient("your-api-key")
|
|
53
|
-
* const feed = await client.feed.byWalletAddress("0x1234...", {
|
|
55
|
+
* const feed = await client.feed.byWalletAddress("0x1234...", "feed_390", {
|
|
54
56
|
* top_k: 15,
|
|
55
57
|
* })
|
|
56
58
|
* console.log(feed[0].metadata?.author.username) // Access author username
|
|
57
59
|
* console.log(feed[0].score) // Access recommendation score
|
|
58
60
|
* ```
|
|
59
61
|
*/
|
|
60
|
-
byWalletAddress(walletAddress: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
62
|
+
byWalletAddress(walletAddress: string, feedId?: string, options?: FeedOptions): Promise<ForYouResponse>;
|
|
61
63
|
/**
|
|
62
64
|
* Create a new feed configuration
|
|
63
65
|
*
|
|
@@ -83,9 +85,9 @@ export declare class FeedNamespace {
|
|
|
83
85
|
*/
|
|
84
86
|
createConfig(options: CreateFeedOptions): Promise<FeedCreateUpdateResponse>;
|
|
85
87
|
/**
|
|
86
|
-
* Get a feed configuration by
|
|
88
|
+
* Get a feed configuration by feedId
|
|
87
89
|
*
|
|
88
|
-
* @param
|
|
90
|
+
* @param feedId - The feedId for which to get the configuration
|
|
89
91
|
* @returns Promise<FeedConfigurationResponse> - The feed configuration details
|
|
90
92
|
*
|
|
91
93
|
* @example
|
|
@@ -96,11 +98,11 @@ export declare class FeedNamespace {
|
|
|
96
98
|
* console.log(feed.config.filters) // Access feed filters
|
|
97
99
|
* ```
|
|
98
100
|
*/
|
|
99
|
-
getConfig(
|
|
101
|
+
getConfig(feedId: string): Promise<FeedGetResponse>;
|
|
100
102
|
/**
|
|
101
103
|
* List all feed configurations for the account
|
|
102
104
|
*
|
|
103
|
-
* @param visibility - Filter by visibility (private/public), defaults to "private"
|
|
105
|
+
* @param visibility - Filter by visibility (private/template/public), defaults to "private"
|
|
104
106
|
* @returns Promise<FeedConfigurationResponse[]> - Array of feed configurations
|
|
105
107
|
*
|
|
106
108
|
* @example
|
|
@@ -111,18 +113,18 @@ export declare class FeedNamespace {
|
|
|
111
113
|
* feeds.forEach(feed => console.log(feed.name))
|
|
112
114
|
* ```
|
|
113
115
|
*/
|
|
114
|
-
listConfigs(visibility?: "private" | "public"): Promise<ListFeedsResponse>;
|
|
116
|
+
listConfigs(visibility?: "private" | "template" | "public"): Promise<ListFeedsResponse>;
|
|
115
117
|
/**
|
|
116
118
|
* Update an existing feed configuration
|
|
117
119
|
*
|
|
118
|
-
* @param
|
|
120
|
+
* @param feedId - The feedId for which to update the configuration
|
|
121
|
+
* @param options - Feed update options
|
|
119
122
|
* @returns Promise<void> - Resolves when the feed is successfully updated
|
|
120
123
|
*
|
|
121
124
|
* @example
|
|
122
125
|
* ```typescript
|
|
123
126
|
* const client = getClient("your-api-key")
|
|
124
|
-
* await client.feed.updateConfig({
|
|
125
|
-
* config_id: "feed_123",
|
|
127
|
+
* await client.feed.updateConfig("feed_123", {
|
|
126
128
|
* name: "Updated Feed Name",
|
|
127
129
|
* config: {
|
|
128
130
|
* filters: {
|
|
@@ -133,6 +135,6 @@ export declare class FeedNamespace {
|
|
|
133
135
|
* console.log("Feed updated successfully")
|
|
134
136
|
* ```
|
|
135
137
|
*/
|
|
136
|
-
updateConfig(options:
|
|
138
|
+
updateConfig(feedId: string, options: CreateFeedOptions): Promise<void>;
|
|
137
139
|
}
|
|
138
140
|
//# sourceMappingURL=namespace.d.ts.map
|