@sybil-studio-devs/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/dist/index.mjs ADDED
@@ -0,0 +1,259 @@
1
+ // src/client.ts
2
+ var DEFAULT_BASE_URL = "https://app.sybil.ai/api/sdk/v1";
3
+ var DEFAULT_TIMEOUT = 3e4;
4
+ var SybilSDK = class {
5
+ constructor(config) {
6
+ if (typeof config === "string") {
7
+ this.apiKey = config;
8
+ this.baseUrl = DEFAULT_BASE_URL;
9
+ this.timeout = DEFAULT_TIMEOUT;
10
+ } else {
11
+ this.apiKey = config.apiKey;
12
+ this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
13
+ this.timeout = config.timeout || DEFAULT_TIMEOUT;
14
+ }
15
+ if (!this.apiKey) {
16
+ throw new Error("API key is required");
17
+ }
18
+ if (!this.apiKey.startsWith("sk_live_") && !this.apiKey.startsWith("sk_test_")) {
19
+ throw new Error("Invalid API key format. Must start with sk_live_ or sk_test_");
20
+ }
21
+ this.pages = new PagesAPI(this);
22
+ this.documents = new DocumentsAPI(this);
23
+ this.youtube = new YouTubeAPI(this);
24
+ this.chat = new ChatAPI(this);
25
+ this.analyze = new AnalyzeAPI(this);
26
+ }
27
+ async request(endpoint, options = {}) {
28
+ const url = `${this.baseUrl}${endpoint}`;
29
+ const headers = {
30
+ "x-api-key": this.apiKey,
31
+ ...options.headers
32
+ };
33
+ if (options.body && typeof options.body === "string") {
34
+ headers["Content-Type"] = "application/json";
35
+ }
36
+ const controller = new AbortController();
37
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
38
+ try {
39
+ const response = await fetch(url, {
40
+ ...options,
41
+ headers,
42
+ signal: controller.signal
43
+ });
44
+ clearTimeout(timeoutId);
45
+ if (!response.ok) {
46
+ const errorData = await response.json().catch(() => ({}));
47
+ const message = errorData.error?.message || `Request failed with status ${response.status}`;
48
+ throw new SybilError(message, response.status, errorData.error?.code);
49
+ }
50
+ return response.json();
51
+ } catch (error) {
52
+ clearTimeout(timeoutId);
53
+ if (error instanceof SybilError) {
54
+ throw error;
55
+ }
56
+ if (error instanceof Error && error.name === "AbortError") {
57
+ throw new SybilError("Request timeout", 408, "TIMEOUT");
58
+ }
59
+ throw new SybilError(
60
+ error instanceof Error ? error.message : "Unknown error",
61
+ 500,
62
+ "UNKNOWN"
63
+ );
64
+ }
65
+ }
66
+ };
67
+ var SybilError = class extends Error {
68
+ constructor(message, status, code) {
69
+ super(message);
70
+ this.name = "SybilError";
71
+ this.status = status;
72
+ this.code = code;
73
+ }
74
+ };
75
+ var PagesAPI = class {
76
+ constructor(client) {
77
+ this.client = client;
78
+ }
79
+ async list(params = {}) {
80
+ const searchParams = new URLSearchParams();
81
+ if (params.limit) searchParams.set("limit", params.limit.toString());
82
+ if (params.offset) searchParams.set("offset", params.offset.toString());
83
+ if (params.parent_id) searchParams.set("parent_id", params.parent_id);
84
+ if (params.is_published !== void 0) searchParams.set("is_published", params.is_published.toString());
85
+ const query = searchParams.toString();
86
+ return this.client.request(`/pages${query ? `?${query}` : ""}`);
87
+ }
88
+ async get(pageId) {
89
+ return this.client.request(`/pages/${pageId}`);
90
+ }
91
+ async create(params = {}) {
92
+ return this.client.request("/pages", {
93
+ method: "POST",
94
+ body: JSON.stringify(params)
95
+ });
96
+ }
97
+ async update(pageId, params) {
98
+ return this.client.request(`/pages/${pageId}`, {
99
+ method: "PUT",
100
+ body: JSON.stringify(params)
101
+ });
102
+ }
103
+ async delete(pageId) {
104
+ return this.client.request(`/pages/${pageId}`, {
105
+ method: "DELETE"
106
+ });
107
+ }
108
+ async upload(file, fileName) {
109
+ const formData = new FormData();
110
+ formData.append("file", file, fileName);
111
+ return this.client.request("/pages/upload", {
112
+ method: "POST",
113
+ body: formData
114
+ });
115
+ }
116
+ async deleteFile(filePath) {
117
+ return this.client.request("/pages/upload", {
118
+ method: "DELETE",
119
+ body: JSON.stringify({ filePath })
120
+ });
121
+ }
122
+ };
123
+ var DocumentsAPI = class {
124
+ constructor(client) {
125
+ this.client = client;
126
+ }
127
+ async list(params = {}) {
128
+ const searchParams = new URLSearchParams();
129
+ if (params.limit) searchParams.set("limit", params.limit.toString());
130
+ if (params.offset) searchParams.set("offset", params.offset.toString());
131
+ if (params.status) searchParams.set("status", params.status);
132
+ if (params.fileType) searchParams.set("fileType", params.fileType);
133
+ if (params.search) searchParams.set("search", params.search);
134
+ const query = searchParams.toString();
135
+ return this.client.request(`/documents${query ? `?${query}` : ""}`);
136
+ }
137
+ async get(documentId, params = {}) {
138
+ const searchParams = new URLSearchParams();
139
+ if (params.includeContent) searchParams.set("includeContent", "true");
140
+ if (params.includeInsights === false) searchParams.set("includeInsights", "false");
141
+ if (params.includeMetadata === false) searchParams.set("includeMetadata", "false");
142
+ const query = searchParams.toString();
143
+ return this.client.request(`/documents/${documentId}${query ? `?${query}` : ""}`);
144
+ }
145
+ async process(file, options = {}) {
146
+ const formData = new FormData();
147
+ formData.append("file", file, options.fileName);
148
+ if (options.metadata) {
149
+ formData.append("metadata", JSON.stringify(options.metadata));
150
+ }
151
+ if (options.collectionId) {
152
+ formData.append("collectionId", options.collectionId);
153
+ }
154
+ return this.client.request("/documents", {
155
+ method: "POST",
156
+ body: formData
157
+ });
158
+ }
159
+ async status(documentId) {
160
+ return this.client.request(`/documents/${documentId}/status`);
161
+ }
162
+ async insights(documentId, type) {
163
+ const query = type ? `?type=${type}` : "";
164
+ return this.client.request(`/documents/${documentId}/insights${query}`);
165
+ }
166
+ async delete(documentId) {
167
+ return this.client.request(`/documents/${documentId}`, {
168
+ method: "DELETE"
169
+ });
170
+ }
171
+ async waitForProcessing(documentId, options = {}) {
172
+ const maxAttempts = options.maxAttempts || 60;
173
+ const interval = options.interval || 3e3;
174
+ for (let i = 0; i < maxAttempts; i++) {
175
+ const status = await this.status(documentId);
176
+ if (status.status === "processed" || status.status === "completed") {
177
+ const { document } = await this.get(documentId);
178
+ return document;
179
+ }
180
+ if (status.status === "failed") {
181
+ throw new SybilError(status.error?.message || "Processing failed", 500, "PROCESSING_FAILED");
182
+ }
183
+ await new Promise((resolve) => setTimeout(resolve, interval));
184
+ }
185
+ throw new SybilError("Processing timeout", 408, "TIMEOUT");
186
+ }
187
+ };
188
+ var YouTubeAPI = class {
189
+ constructor(client) {
190
+ this.client = client;
191
+ }
192
+ async list(params = {}) {
193
+ const searchParams = new URLSearchParams();
194
+ if (params.limit) searchParams.set("limit", params.limit.toString());
195
+ if (params.offset) searchParams.set("offset", params.offset.toString());
196
+ const query = searchParams.toString();
197
+ return this.client.request(`/youtube${query ? `?${query}` : ""}`);
198
+ }
199
+ async process(url, collectionId) {
200
+ return this.client.request("/youtube", {
201
+ method: "POST",
202
+ body: JSON.stringify({ url, collectionId })
203
+ });
204
+ }
205
+ async get(videoId, params = {}) {
206
+ const searchParams = new URLSearchParams();
207
+ if (params.includeTranscript) searchParams.set("includeTranscript", "true");
208
+ if (params.includeChunks) searchParams.set("includeChunks", "true");
209
+ if (params.includeInsights === false) searchParams.set("includeInsights", "false");
210
+ const query = searchParams.toString();
211
+ return this.client.request(`/youtube/${videoId}${query ? `?${query}` : ""}`);
212
+ }
213
+ async delete(videoId) {
214
+ return this.client.request(`/youtube/${videoId}`, {
215
+ method: "DELETE"
216
+ });
217
+ }
218
+ };
219
+ var ChatAPI = class {
220
+ constructor(client) {
221
+ this.client = client;
222
+ }
223
+ async send(paramsOrDocId, query) {
224
+ const params = typeof paramsOrDocId === "string" ? { documentId: paramsOrDocId, query } : paramsOrDocId;
225
+ return this.client.request("/chat", {
226
+ method: "POST",
227
+ body: JSON.stringify(params)
228
+ });
229
+ }
230
+ async history(documentId, limit) {
231
+ const searchParams = new URLSearchParams();
232
+ searchParams.set("documentId", documentId);
233
+ if (limit) searchParams.set("limit", limit.toString());
234
+ return this.client.request(`/chat?${searchParams.toString()}`);
235
+ }
236
+ };
237
+ var AnalyzeAPI = class {
238
+ constructor(client) {
239
+ this.client = client;
240
+ }
241
+ async run(paramsOrDocId, forceRefresh) {
242
+ const params = typeof paramsOrDocId === "string" ? { documentId: paramsOrDocId, forceRefresh } : paramsOrDocId;
243
+ return this.client.request("/analyze", {
244
+ method: "POST",
245
+ body: JSON.stringify(params)
246
+ });
247
+ }
248
+ async get(documentId) {
249
+ return this.client.request(`/analyze?documentId=${documentId}`);
250
+ }
251
+ };
252
+
253
+ // src/index.ts
254
+ var index_default = SybilSDK;
255
+ export {
256
+ SybilError,
257
+ SybilSDK,
258
+ index_default as default
259
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@sybil-studio-devs/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official SDK for Sybil AI - Document processing, YouTube analysis, and AI-powered knowledge management",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
21
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
+ "lint": "eslint src/",
23
+ "typecheck": "tsc --noEmit",
24
+ "prepublishOnly": "pnpm build"
25
+ },
26
+ "keywords": [
27
+ "sybil",
28
+ "ai",
29
+ "sdk",
30
+ "document-processing",
31
+ "youtube",
32
+ "rag",
33
+ "knowledge-management"
34
+ ],
35
+ "author": "Sybil Studio",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/sybil-studio/sdk"
40
+ },
41
+ "homepage": "https://docs.sybil.ai/sdk",
42
+ "devDependencies": {
43
+ "@types/node": "^20.0.0",
44
+ "tsup": "^8.0.0",
45
+ "typescript": "^5.0.0"
46
+ },
47
+ "peerDependencies": {
48
+ "typescript": ">=4.7.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "typescript": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "engines": {
56
+ "node": ">=18.0.0"
57
+ }
58
+ }