@embed-ai/sdk 0.1.3 → 0.1.4
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/package.json +12 -3
- package/src/search/namespace.d.ts +65 -1
- package/src/search/namespace.js +73 -1
- package/src/search/post.d.ts +45 -0
- package/src/search/post.js +70 -0
- package/src/search/item.d.ts +0 -2
- package/src/search/item.js +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embed-ai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"description": "The typescript sdk package for embed AI APIs.",
|
|
@@ -26,11 +26,20 @@
|
|
|
26
26
|
"build-annotate": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
|
|
27
27
|
"fix-deps": "bun scripts/fix-deps.js",
|
|
28
28
|
"check": "tsc -b tsconfig.json",
|
|
29
|
-
"test": "
|
|
29
|
+
"test": "echo '⚠️ No unit tests available - SDK tests require API keys' && echo ' Run test:integration instead'",
|
|
30
|
+
"test:integration": "vitest run --reporter=verbose",
|
|
31
|
+
"test:ui": "vitest --ui",
|
|
32
|
+
"test:posts": "vitest run test/search-posts.test.ts",
|
|
33
|
+
"test:users": "vitest run test/search-users.test.ts",
|
|
34
|
+
"test:feed": "vitest run test/feed.test.ts",
|
|
30
35
|
"coverage": "vitest --coverage"
|
|
31
36
|
},
|
|
32
37
|
"dependencies": {
|
|
33
|
-
"@embed-ai/types": "^0.1.
|
|
38
|
+
"@embed-ai/types": "^0.1.3"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@effect/vitest": "latest",
|
|
42
|
+
"vitest": "latest"
|
|
34
43
|
},
|
|
35
44
|
"peerDependencies": {
|
|
36
45
|
"effect": ">=3.0.0"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { AllLabels, LabelCategories, UserLabelsResponse, UserSemanticSearchResponse, UserSimilarityResponse, UserTopByLabelResponse } from "@embed-ai/types";
|
|
1
|
+
import type { AllLabels, LabelCategories, PostLabelsResponse, PostSemanticSearchResponse, UserLabelsResponse, UserSemanticSearchResponse, UserSimilarityResponse, UserTopByLabelResponse } from "@embed-ai/types";
|
|
2
2
|
import type { IHttpClient } from "../interfaces/index.js";
|
|
3
|
+
import type { PostLabelsOptions, PostSemanticSearchOptions } from "./post.js";
|
|
3
4
|
import type { UserLabelsOptions, UserSemanticSearchOptions, UserSimilarOptions, UserTopByLabelOptions } from "./user.js";
|
|
4
5
|
/**
|
|
5
6
|
* Users namespace containing all user search operations
|
|
@@ -98,6 +99,64 @@ export declare class UsersNamespace {
|
|
|
98
99
|
*/
|
|
99
100
|
getLabels(userList: Array<string>, labelCategory?: LabelCategories, options?: UserLabelsOptions): Promise<UserLabelsResponse>;
|
|
100
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Posts namespace containing all post search operations
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const client = getClient('your-api-key')
|
|
108
|
+
*
|
|
109
|
+
* // Get labels for posts
|
|
110
|
+
* const postLabels = await client.search.posts.getLabels(['0x123...', '0x456...'])
|
|
111
|
+
*
|
|
112
|
+
* // Search posts by query
|
|
113
|
+
* const posts = await client.search.posts.byQuery('web3 developments')
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare class PostsNamespace {
|
|
117
|
+
private http;
|
|
118
|
+
constructor(http: IHttpClient);
|
|
119
|
+
/**
|
|
120
|
+
* Get AI labels for a list of casts
|
|
121
|
+
*
|
|
122
|
+
* @param itemsList - Array of cast IDs to get labels for
|
|
123
|
+
* @param labelCategory - The category of labels to retrieve (default: "all")
|
|
124
|
+
* @param options - Optional configuration
|
|
125
|
+
* @returns Promise<PostLabelsResponse> - Array of casts with their AI labels
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const client = getClient("your-api-key")
|
|
130
|
+
* const postLabels = await client.search.posts.getLabels([
|
|
131
|
+
* "0x4888649440c8cfd3ef6e28f2096a201d20253176",
|
|
132
|
+
* "0x0ecf95b73aa54d583877821ece241e94de701404"
|
|
133
|
+
* ], "moderation")
|
|
134
|
+
* console.log(postLabels[0].moderation[0].label) // "sexual"
|
|
135
|
+
* console.log(postLabels[0].moderation[0].score) // 0.0006675918
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
getLabels(itemsList: Array<string>, labelCategory?: LabelCategories, options?: PostLabelsOptions): Promise<PostLabelsResponse>;
|
|
139
|
+
/**
|
|
140
|
+
* Search for casts by semantic query
|
|
141
|
+
*
|
|
142
|
+
* @param query - The text query to search for similar casts
|
|
143
|
+
* @param options - Optional configuration with top_k (default: 10, max: 100), return_ai_labels, return_metadata, and filters
|
|
144
|
+
* @returns Promise<PostSemanticSearchResponse> - Array of posts with item_id and scores
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const client = getClient("your-api-key")
|
|
149
|
+
* const posts = await client.search.posts.byQuery("web3 developments", {
|
|
150
|
+
* top_k: 10,
|
|
151
|
+
* return_ai_labels: true,
|
|
152
|
+
* return_metadata: true
|
|
153
|
+
* })
|
|
154
|
+
* console.log(posts[0].item_id) // "0x4c8e2e329dc481f4c445ff8c367a1df4a8694317"
|
|
155
|
+
* console.log(posts[0].score) // 0.864244163
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
byQuery(query: string, options?: PostSemanticSearchOptions): Promise<PostSemanticSearchResponse>;
|
|
159
|
+
}
|
|
101
160
|
/**
|
|
102
161
|
* Search namespace containing all search-related operations
|
|
103
162
|
*
|
|
@@ -108,11 +167,16 @@ export declare class UsersNamespace {
|
|
|
108
167
|
* // Access user search methods
|
|
109
168
|
* const similarUsers = await client.search.users.similar('16085')
|
|
110
169
|
* const searchResults = await client.search.users.byQuery('web3 developers')
|
|
170
|
+
*
|
|
171
|
+
* // Access post search methods
|
|
172
|
+
* const posts = await client.search.posts.byQuery('web3 developments')
|
|
173
|
+
* const postLabels = await client.search.posts.getLabels(['0x123...'])
|
|
111
174
|
* ```
|
|
112
175
|
*/
|
|
113
176
|
export declare class SearchNamespace {
|
|
114
177
|
private http;
|
|
115
178
|
readonly users: UsersNamespace;
|
|
179
|
+
readonly posts: PostsNamespace;
|
|
116
180
|
constructor(http: IHttpClient);
|
|
117
181
|
}
|
|
118
182
|
//# sourceMappingURL=namespace.d.ts.map
|
package/src/search/namespace.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.SearchNamespace = exports.UsersNamespace = void 0;
|
|
6
|
+
exports.SearchNamespace = exports.PostsNamespace = exports.UsersNamespace = void 0;
|
|
7
|
+
const post_js_1 = /*#__PURE__*/require("./post.js");
|
|
7
8
|
const user_js_1 = /*#__PURE__*/require("./user.js");
|
|
8
9
|
/**
|
|
9
10
|
* Users namespace containing all user search operations
|
|
@@ -113,6 +114,71 @@ class UsersNamespace {
|
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
exports.UsersNamespace = UsersNamespace;
|
|
117
|
+
/**
|
|
118
|
+
* Posts namespace containing all post search operations
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const client = getClient('your-api-key')
|
|
123
|
+
*
|
|
124
|
+
* // Get labels for posts
|
|
125
|
+
* const postLabels = await client.search.posts.getLabels(['0x123...', '0x456...'])
|
|
126
|
+
*
|
|
127
|
+
* // Search posts by query
|
|
128
|
+
* const posts = await client.search.posts.byQuery('web3 developments')
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
class PostsNamespace {
|
|
132
|
+
http;
|
|
133
|
+
constructor(http) {
|
|
134
|
+
this.http = http;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get AI labels for a list of casts
|
|
138
|
+
*
|
|
139
|
+
* @param itemsList - Array of cast IDs to get labels for
|
|
140
|
+
* @param labelCategory - The category of labels to retrieve (default: "all")
|
|
141
|
+
* @param options - Optional configuration
|
|
142
|
+
* @returns Promise<PostLabelsResponse> - Array of casts with their AI labels
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const client = getClient("your-api-key")
|
|
147
|
+
* const postLabels = await client.search.posts.getLabels([
|
|
148
|
+
* "0x4888649440c8cfd3ef6e28f2096a201d20253176",
|
|
149
|
+
* "0x0ecf95b73aa54d583877821ece241e94de701404"
|
|
150
|
+
* ], "moderation")
|
|
151
|
+
* console.log(postLabels[0].moderation[0].label) // "sexual"
|
|
152
|
+
* console.log(postLabels[0].moderation[0].score) // 0.0006675918
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
async getLabels(itemsList, labelCategory = "all", options) {
|
|
156
|
+
return (0, post_js_1.getLabels)(this.http, itemsList, labelCategory, options);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Search for casts by semantic query
|
|
160
|
+
*
|
|
161
|
+
* @param query - The text query to search for similar casts
|
|
162
|
+
* @param options - Optional configuration with top_k (default: 10, max: 100), return_ai_labels, return_metadata, and filters
|
|
163
|
+
* @returns Promise<PostSemanticSearchResponse> - Array of posts with item_id and scores
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const client = getClient("your-api-key")
|
|
168
|
+
* const posts = await client.search.posts.byQuery("web3 developments", {
|
|
169
|
+
* top_k: 10,
|
|
170
|
+
* return_ai_labels: true,
|
|
171
|
+
* return_metadata: true
|
|
172
|
+
* })
|
|
173
|
+
* console.log(posts[0].item_id) // "0x4c8e2e329dc481f4c445ff8c367a1df4a8694317"
|
|
174
|
+
* console.log(posts[0].score) // 0.864244163
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
async byQuery(query, options) {
|
|
178
|
+
return (0, post_js_1.byQuery)(this.http, query, options);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.PostsNamespace = PostsNamespace;
|
|
116
182
|
/**
|
|
117
183
|
* Search namespace containing all search-related operations
|
|
118
184
|
*
|
|
@@ -123,14 +189,20 @@ exports.UsersNamespace = UsersNamespace;
|
|
|
123
189
|
* // Access user search methods
|
|
124
190
|
* const similarUsers = await client.search.users.similar('16085')
|
|
125
191
|
* const searchResults = await client.search.users.byQuery('web3 developers')
|
|
192
|
+
*
|
|
193
|
+
* // Access post search methods
|
|
194
|
+
* const posts = await client.search.posts.byQuery('web3 developments')
|
|
195
|
+
* const postLabels = await client.search.posts.getLabels(['0x123...'])
|
|
126
196
|
* ```
|
|
127
197
|
*/
|
|
128
198
|
class SearchNamespace {
|
|
129
199
|
http;
|
|
130
200
|
users;
|
|
201
|
+
posts;
|
|
131
202
|
constructor(http) {
|
|
132
203
|
this.http = http;
|
|
133
204
|
this.users = new UsersNamespace(this.http);
|
|
205
|
+
this.posts = new PostsNamespace(this.http);
|
|
134
206
|
}
|
|
135
207
|
}
|
|
136
208
|
exports.SearchNamespace = SearchNamespace;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LabelCategories, LabelsForItems, PostLabelsResponse, PostSemanticSearchResponse, SemanticSearch } from "@embed-ai/types";
|
|
2
|
+
import type { IHttpClient } from "../interfaces/index.js";
|
|
3
|
+
export type PostLabelsOptions = Omit<LabelsForItems, "items_list" | "label_category">;
|
|
4
|
+
export type PostSemanticSearchOptions = Omit<SemanticSearch, "query">;
|
|
5
|
+
/**
|
|
6
|
+
* Get AI labels for a list of casts
|
|
7
|
+
*
|
|
8
|
+
* @param httpClient - HTTP client instance
|
|
9
|
+
* @param itemsList - Array of cast IDs to get labels for
|
|
10
|
+
* @param labelCategory - The category of labels to retrieve (default: "all")
|
|
11
|
+
* @param options - Optional configuration
|
|
12
|
+
* @returns Promise<PostLabelsResponse> - Array of casts with their AI labels
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const postLabels = await client.search.posts.getLabels([
|
|
17
|
+
* "0x4888649440c8cfd3ef6e28f2096a201d20253176",
|
|
18
|
+
* "0x0ecf95b73aa54d583877821ece241e94de701404"
|
|
19
|
+
* ], "moderation")
|
|
20
|
+
* console.log(postLabels[0].moderation[0].label) // "sexual"
|
|
21
|
+
* console.log(postLabels[0].moderation[0].score) // 0.0006675918
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function getLabels(httpClient: IHttpClient, itemsList: Array<string>, labelCategory?: LabelCategories, options?: PostLabelsOptions): Promise<PostLabelsResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Search for casts by semantic query
|
|
27
|
+
*
|
|
28
|
+
* @param httpClient - HTTP client instance
|
|
29
|
+
* @param query - The text query to search for similar casts
|
|
30
|
+
* @param options - Optional configuration with top_k (default: 10, max: 100), return_ai_labels, return_metadata, and filters
|
|
31
|
+
* @returns Promise<PostSemanticSearchResponse> - Object with items_list containing cast IDs and scores
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const posts = await client.search.posts.byQuery("web3 developments", {
|
|
36
|
+
* top_k: 10,
|
|
37
|
+
* return_ai_labels: true,
|
|
38
|
+
* return_metadata: true
|
|
39
|
+
* })
|
|
40
|
+
* console.log(posts.items_list[0].item_id) // "0x4c8e2e329dc481f4c445ff8c367a1df4a8694317"
|
|
41
|
+
* console.log(posts.items_list[0].score) // 0.864244163
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function byQuery(httpClient: IHttpClient, query: string, options?: PostSemanticSearchOptions): Promise<PostSemanticSearchResponse>;
|
|
45
|
+
//# sourceMappingURL=post.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getLabels = getLabels;
|
|
7
|
+
exports.byQuery = byQuery;
|
|
8
|
+
/**
|
|
9
|
+
* Get AI labels for a list of casts
|
|
10
|
+
*
|
|
11
|
+
* @param httpClient - HTTP client instance
|
|
12
|
+
* @param itemsList - Array of cast IDs to get labels for
|
|
13
|
+
* @param labelCategory - The category of labels to retrieve (default: "all")
|
|
14
|
+
* @param options - Optional configuration
|
|
15
|
+
* @returns Promise<PostLabelsResponse> - Array of casts with their AI labels
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const postLabels = await client.search.posts.getLabels([
|
|
20
|
+
* "0x4888649440c8cfd3ef6e28f2096a201d20253176",
|
|
21
|
+
* "0x0ecf95b73aa54d583877821ece241e94de701404"
|
|
22
|
+
* ], "moderation")
|
|
23
|
+
* console.log(postLabels[0].moderation[0].label) // "sexual"
|
|
24
|
+
* console.log(postLabels[0].moderation[0].score) // 0.0006675918
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async function getLabels(httpClient, itemsList, labelCategory = "all", options) {
|
|
28
|
+
const params = {
|
|
29
|
+
items_list: itemsList,
|
|
30
|
+
label_category: labelCategory,
|
|
31
|
+
...options
|
|
32
|
+
};
|
|
33
|
+
const response = await httpClient.post("/v2/farcaster/casts/labels/for-items", params);
|
|
34
|
+
return response.body;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Search for casts by semantic query
|
|
38
|
+
*
|
|
39
|
+
* @param httpClient - HTTP client instance
|
|
40
|
+
* @param query - The text query to search for similar casts
|
|
41
|
+
* @param options - Optional configuration with top_k (default: 10, max: 100), return_ai_labels, return_metadata, and filters
|
|
42
|
+
* @returns Promise<PostSemanticSearchResponse> - Object with items_list containing cast IDs and scores
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const posts = await client.search.posts.byQuery("web3 developments", {
|
|
47
|
+
* top_k: 10,
|
|
48
|
+
* return_ai_labels: true,
|
|
49
|
+
* return_metadata: true
|
|
50
|
+
* })
|
|
51
|
+
* console.log(posts.items_list[0].item_id) // "0x4c8e2e329dc481f4c445ff8c367a1df4a8694317"
|
|
52
|
+
* console.log(posts.items_list[0].score) // 0.864244163
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
async function byQuery(httpClient, query, options) {
|
|
56
|
+
const top_k = options?.top_k ?? 10;
|
|
57
|
+
const params = {
|
|
58
|
+
query,
|
|
59
|
+
top_k,
|
|
60
|
+
...options
|
|
61
|
+
};
|
|
62
|
+
const response = await httpClient.post("/v2/farcaster/casts/search/semantic", params);
|
|
63
|
+
// Handle both response formats - sometimes it's a direct array, sometimes it's wrapped in items_list
|
|
64
|
+
if (Array.isArray(response.body)) {
|
|
65
|
+
return response.body;
|
|
66
|
+
} else {
|
|
67
|
+
return response.body.items_list;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=post.js.map
|
package/src/search/item.d.ts
DELETED