@openbeam/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.js ADDED
@@ -0,0 +1,497 @@
1
+ //#region src/errors.ts
2
+ var OpenBeamError = class extends Error {
3
+ status;
4
+ code;
5
+ constructor(message, status, code) {
6
+ super(message);
7
+ this.name = "OpenBeamError";
8
+ this.status = status;
9
+ this.code = code;
10
+ }
11
+ };
12
+ var AuthenticationError = class extends OpenBeamError {
13
+ constructor(message = "Invalid or missing API key") {
14
+ super(message, 401, "authentication_error");
15
+ this.name = "AuthenticationError";
16
+ }
17
+ };
18
+ var PermissionError = class extends OpenBeamError {
19
+ constructor(message = "Insufficient permissions") {
20
+ super(message, 403, "permission_error");
21
+ this.name = "PermissionError";
22
+ }
23
+ };
24
+ var NotFoundError = class extends OpenBeamError {
25
+ constructor(message = "Resource not found") {
26
+ super(message, 404, "not_found");
27
+ this.name = "NotFoundError";
28
+ }
29
+ };
30
+ var RateLimitError = class extends OpenBeamError {
31
+ retryAfter;
32
+ constructor(message = "Rate limit exceeded", retryAfter = null) {
33
+ super(message, 429, "rate_limit_error");
34
+ this.name = "RateLimitError";
35
+ this.retryAfter = retryAfter;
36
+ }
37
+ };
38
+ var ServerError = class extends OpenBeamError {
39
+ constructor(message = "Internal server error") {
40
+ super(message, 500, "server_error");
41
+ this.name = "ServerError";
42
+ }
43
+ };
44
+ var ToolError = class extends OpenBeamError {
45
+ constructor(message) {
46
+ super(message, 422, "tool_error");
47
+ this.name = "ToolError";
48
+ }
49
+ };
50
+
51
+ //#endregion
52
+ //#region src/client.ts
53
+ const DEFAULT_BASE_URL = "https://api.openbeam.work";
54
+ const DEFAULT_TIMEOUT = 3e4;
55
+ const DEFAULT_MAX_RETRIES = 2;
56
+ const RETRY_STATUS_CODES = new Set([
57
+ 408,
58
+ 429,
59
+ 500,
60
+ 502,
61
+ 503,
62
+ 504
63
+ ]);
64
+ const INITIAL_RETRY_DELAY = 500;
65
+ const TRAILING_SLASHES = /\/+$/;
66
+ var HttpClient = class {
67
+ apiKey;
68
+ baseUrl;
69
+ timeout;
70
+ maxRetries;
71
+ requestId = 0;
72
+ constructor(config) {
73
+ if (!config.apiKey) throw new AuthenticationError("apiKey is required");
74
+ this.apiKey = config.apiKey;
75
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(TRAILING_SLASHES, "");
76
+ this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
77
+ this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
78
+ }
79
+ async callTool(toolName, args, options) {
80
+ const body = {
81
+ jsonrpc: "2.0",
82
+ id: this.nextId(),
83
+ method: "tools/call",
84
+ params: {
85
+ name: toolName,
86
+ arguments: args
87
+ }
88
+ };
89
+ const response = await this.fetchWithRetry(`${this.baseUrl}/mcp`, {
90
+ method: "POST",
91
+ headers: {
92
+ "Content-Type": "application/json",
93
+ Accept: "application/json, text/event-stream",
94
+ Authorization: `Bearer ${this.apiKey}`
95
+ },
96
+ body: JSON.stringify(body),
97
+ signal: this.buildSignal(options)
98
+ }, 0);
99
+ await this.handleHttpError(response);
100
+ const json = await response.json();
101
+ if (json.error) throw new OpenBeamError(json.error.message, json.error.code, "mcp_error");
102
+ if (json.result?.isError) throw new ToolError(json.result.content[0]?.text ?? "Tool execution failed");
103
+ return json.result?.structuredContent ?? json.result;
104
+ }
105
+ nextId() {
106
+ this.requestId += 1;
107
+ return this.requestId;
108
+ }
109
+ buildSignal(options) {
110
+ const timeout = options?.timeout ?? this.timeout;
111
+ const signals = [AbortSignal.timeout(timeout)];
112
+ if (options?.signal) signals.push(options.signal);
113
+ return AbortSignal.any(signals);
114
+ }
115
+ async fetchWithRetry(url, init, attempt) {
116
+ try {
117
+ const response = await fetch(url, init);
118
+ if (RETRY_STATUS_CODES.has(response.status) && attempt < this.maxRetries) {
119
+ await sleep(this.retryDelay(attempt, response));
120
+ return this.fetchWithRetry(url, init, attempt + 1);
121
+ }
122
+ return response;
123
+ } catch (error) {
124
+ if (attempt < this.maxRetries && isRetryableError(error)) {
125
+ await sleep(INITIAL_RETRY_DELAY * 2 ** attempt);
126
+ return this.fetchWithRetry(url, init, attempt + 1);
127
+ }
128
+ throw error;
129
+ }
130
+ }
131
+ retryDelay(attempt, response) {
132
+ const retryAfter = response.headers.get("Retry-After");
133
+ if (retryAfter) {
134
+ const seconds = Number.parseInt(retryAfter, 10);
135
+ if (!Number.isNaN(seconds)) return seconds * 1e3;
136
+ }
137
+ return INITIAL_RETRY_DELAY * 2 ** attempt;
138
+ }
139
+ async handleHttpError(response) {
140
+ if (response.ok) return;
141
+ let message;
142
+ try {
143
+ const body = await response.json();
144
+ message = body.error_description ?? body.error ?? response.statusText;
145
+ } catch {
146
+ message = response.statusText;
147
+ }
148
+ switch (response.status) {
149
+ case 401: throw new AuthenticationError(message);
150
+ case 403: throw new PermissionError(message);
151
+ case 404: throw new NotFoundError(message);
152
+ case 429: {
153
+ const retryAfter = response.headers.get("Retry-After");
154
+ const seconds = retryAfter ? Number.parseInt(retryAfter, 10) : null;
155
+ throw new RateLimitError(message, Number.isNaN(seconds) ? null : seconds);
156
+ }
157
+ default:
158
+ if (response.status >= 500) throw new ServerError(message);
159
+ throw new OpenBeamError(message, response.status, "api_error");
160
+ }
161
+ }
162
+ };
163
+ function sleep(ms) {
164
+ return new Promise((resolve) => {
165
+ setTimeout(resolve, ms);
166
+ });
167
+ }
168
+ function isRetryableError(error) {
169
+ if (error instanceof Error) return error.name === "TypeError" || error.message.includes("fetch failed") || error.message.includes("ECONNRESET");
170
+ return false;
171
+ }
172
+
173
+ //#endregion
174
+ //#region src/resources/actions.ts
175
+ var ActionsResource = class {
176
+ client;
177
+ constructor(client) {
178
+ this.client = client;
179
+ }
180
+ async list(options) {
181
+ return await this.client.callTool("connector_actions_list", {
182
+ connectorType: options?.connectorType,
183
+ category: options?.category
184
+ }, options);
185
+ }
186
+ async execute(connectorId, actionId, params, options) {
187
+ return await this.client.callTool("connector_action_execute", {
188
+ connectorId,
189
+ actionId,
190
+ params
191
+ }, options);
192
+ }
193
+ };
194
+
195
+ //#endregion
196
+ //#region src/resources/agents.ts
197
+ var AgentsResource = class {
198
+ client;
199
+ constructor(client) {
200
+ this.client = client;
201
+ }
202
+ async list(options) {
203
+ return await this.client.callTool("agent_list", { category: options?.category }, options);
204
+ }
205
+ async run(agentName, input, options) {
206
+ return await this.client.callTool("agent_run", {
207
+ agentName,
208
+ input,
209
+ maxSources: options?.maxSources
210
+ }, options);
211
+ }
212
+ async ask(question, options) {
213
+ return await this.client.callTool("ask_question", {
214
+ question,
215
+ connectorTypes: options?.connectorTypes,
216
+ maxSources: options?.maxSources
217
+ }, options);
218
+ }
219
+ async contextSearch(query, options) {
220
+ return await this.client.callTool("context_search", {
221
+ query,
222
+ contextType: options?.contextType,
223
+ category: options?.category,
224
+ limit: options?.limit
225
+ }, options);
226
+ }
227
+ async contextRead(uri, options) {
228
+ return await this.client.callTool("context_read", {
229
+ uri,
230
+ level: options?.level
231
+ }, options);
232
+ }
233
+ };
234
+
235
+ //#endregion
236
+ //#region src/resources/apikeys.ts
237
+ var ApiKeysResource = class {
238
+ client;
239
+ constructor(client) {
240
+ this.client = client;
241
+ }
242
+ async list(options) {
243
+ return (await this.client.callTool("apikey_list", {}, options)).keys ?? [];
244
+ }
245
+ async create(name, scopes, options) {
246
+ return await this.client.callTool("apikey_create", {
247
+ name,
248
+ ...scopes ? { scopes } : {}
249
+ }, options);
250
+ }
251
+ async revoke(apiKeyId, options) {
252
+ return await this.client.callTool("apikey_revoke", { apiKeyId }, options);
253
+ }
254
+ };
255
+
256
+ //#endregion
257
+ //#region src/resources/connectors.ts
258
+ var ConnectorsResource = class {
259
+ client;
260
+ constructor(client) {
261
+ this.client = client;
262
+ }
263
+ async list(options) {
264
+ return await this.client.callTool("connector_list", {
265
+ status: options?.status,
266
+ type: options?.type,
267
+ cursor: options?.cursor,
268
+ pageSize: options?.pageSize
269
+ }, options);
270
+ }
271
+ async get(id, options) {
272
+ return await this.client.callTool("connector_get", { id }, options);
273
+ }
274
+ async health(id, options) {
275
+ return await this.client.callTool("connector_health", { id }, options);
276
+ }
277
+ async available(options) {
278
+ return await this.client.callTool("connector_available", {
279
+ authType: options?.authType,
280
+ category: options?.category
281
+ }, options);
282
+ }
283
+ async disconnect(connectorId, options) {
284
+ return await this.client.callTool("connector_disconnect", { connectorId }, options);
285
+ }
286
+ };
287
+
288
+ //#endregion
289
+ //#region src/resources/knowledge.ts
290
+ var KnowledgeResource = class {
291
+ client;
292
+ constructor(client) {
293
+ this.client = client;
294
+ }
295
+ async searchEntities(query, options) {
296
+ return await this.client.callTool("entity_search", {
297
+ query,
298
+ type: options?.type,
299
+ limit: options?.limit
300
+ }, options);
301
+ }
302
+ async getEntity(entityId, options) {
303
+ return await this.client.callTool("entity_get", { entityId }, options);
304
+ }
305
+ async getRelations(entityId, opts) {
306
+ return await this.client.callTool("entity_relations", {
307
+ entityId,
308
+ direction: opts?.direction,
309
+ relationType: opts?.relationType,
310
+ limit: opts?.limit
311
+ }, opts);
312
+ }
313
+ async topicExperts(topicId, options) {
314
+ return await this.client.callTool("topic_experts", {
315
+ topicId,
316
+ limit: options?.limit
317
+ }, options);
318
+ }
319
+ async personExpertise(personId, options) {
320
+ return await this.client.callTool("person_expertise", {
321
+ personId,
322
+ limit: options?.limit
323
+ }, options);
324
+ }
325
+ async topics(options) {
326
+ return await this.client.callTool("topic_list", {
327
+ parentId: options?.parentId,
328
+ limit: options?.limit
329
+ }, options);
330
+ }
331
+ };
332
+
333
+ //#endregion
334
+ //#region src/resources/search.ts
335
+ var SearchResource = class {
336
+ client;
337
+ constructor(client) {
338
+ this.client = client;
339
+ }
340
+ async documents(query, options) {
341
+ return await this.client.callTool("search_documents", {
342
+ query,
343
+ limit: options?.limit,
344
+ cursor: options?.cursor,
345
+ connectorTypes: options?.connectorTypes,
346
+ documentTypes: options?.documentTypes,
347
+ authorIds: options?.authorIds,
348
+ ranking: options?.ranking,
349
+ dateFrom: options?.dateFrom,
350
+ dateTo: options?.dateTo
351
+ }, options);
352
+ }
353
+ async people(query, options) {
354
+ return await this.client.callTool("search_people", {
355
+ query,
356
+ limit: options?.limit,
357
+ connectorTypes: options?.connectorTypes
358
+ }, options);
359
+ }
360
+ async recent(options) {
361
+ return await this.client.callTool("search_recent", {
362
+ hours: options?.hours,
363
+ connectorTypes: options?.connectorTypes,
364
+ limit: options?.limit
365
+ }, options);
366
+ }
367
+ async semantic(query, options) {
368
+ return await this.client.callTool("search_semantic", {
369
+ query,
370
+ limit: options?.limit,
371
+ connectorTypes: options?.connectorTypes
372
+ }, options);
373
+ }
374
+ async similar(documentId, options) {
375
+ return await this.client.callTool("search_similar", {
376
+ documentId,
377
+ limit: options?.limit
378
+ }, options);
379
+ }
380
+ async byAuthor(authorId, options) {
381
+ return await this.client.callTool("search_by_author", {
382
+ authorId,
383
+ query: options?.query,
384
+ limit: options?.limit
385
+ }, options);
386
+ }
387
+ };
388
+
389
+ //#endregion
390
+ //#region src/resources/sync.ts
391
+ var SyncResource = class {
392
+ client;
393
+ constructor(client) {
394
+ this.client = client;
395
+ }
396
+ async trigger(connectorId, type = "incremental", options) {
397
+ return await this.client.callTool("sync_trigger", {
398
+ connectorId,
399
+ type
400
+ }, options);
401
+ }
402
+ async triggerAll(options) {
403
+ return await this.client.callTool("sync_trigger_all", {
404
+ type: options?.type,
405
+ connectorTypes: options?.connectorTypes
406
+ }, options);
407
+ }
408
+ async status(connectorId, options) {
409
+ return await this.client.callTool("sync_status", { connectorId }, options);
410
+ }
411
+ async history(connectorId, options) {
412
+ return await this.client.callTool("sync_history", {
413
+ connectorId,
414
+ limit: options?.limit,
415
+ offset: options?.offset
416
+ }, options);
417
+ }
418
+ async progress(connectorId, options) {
419
+ return await this.client.callTool("sync_progress", { connectorId }, options);
420
+ }
421
+ async health(options) {
422
+ return await this.client.callTool("sync_health", {}, options);
423
+ }
424
+ async errors(options) {
425
+ return await this.client.callTool("sync_errors", {
426
+ connectorId: options?.connectorId,
427
+ limit: options?.limit
428
+ }, options);
429
+ }
430
+ async cancel(connectorId, options) {
431
+ return await this.client.callTool("sync_cancel", { connectorId }, options);
432
+ }
433
+ async pause(connectorId, options) {
434
+ return await this.client.callTool("sync_pause", { connectorId }, options);
435
+ }
436
+ async resume(connectorId, options) {
437
+ return await this.client.callTool("sync_resume", { connectorId }, options);
438
+ }
439
+ };
440
+
441
+ //#endregion
442
+ //#region src/resources/team.ts
443
+ var TeamResource = class {
444
+ client;
445
+ constructor(client) {
446
+ this.client = client;
447
+ }
448
+ async info(options) {
449
+ return await this.client.callTool("team_info", {}, options);
450
+ }
451
+ async members(options) {
452
+ return await this.client.callTool("team_members", {}, options);
453
+ }
454
+ async inviteMember(email, role = "MEMBER", options) {
455
+ return await this.client.callTool("team_invite_member", {
456
+ email,
457
+ role
458
+ }, options);
459
+ }
460
+ async removeMember(userId, options) {
461
+ return await this.client.callTool("team_remove_member", { userId }, options);
462
+ }
463
+ async updateRole(userId, role, options) {
464
+ return await this.client.callTool("team_update_role", {
465
+ userId,
466
+ role
467
+ }, options);
468
+ }
469
+ };
470
+
471
+ //#endregion
472
+ //#region src/index.ts
473
+ var OpenBeam = class {
474
+ search;
475
+ connectors;
476
+ sync;
477
+ actions;
478
+ team;
479
+ knowledge;
480
+ agents;
481
+ apiKeys;
482
+ constructor(config) {
483
+ const client = new HttpClient(config);
484
+ this.search = new SearchResource(client);
485
+ this.connectors = new ConnectorsResource(client);
486
+ this.sync = new SyncResource(client);
487
+ this.actions = new ActionsResource(client);
488
+ this.team = new TeamResource(client);
489
+ this.knowledge = new KnowledgeResource(client);
490
+ this.agents = new AgentsResource(client);
491
+ this.apiKeys = new ApiKeysResource(client);
492
+ }
493
+ };
494
+ var src_default = OpenBeam;
495
+
496
+ //#endregion
497
+ export { AuthenticationError, NotFoundError, OpenBeam, OpenBeamError, PermissionError, RateLimitError, ServerError, ToolError, src_default as default };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@openbeam/sdk",
3
+ "version": "0.1.0",
4
+ "description": "OpenBeam TypeScript SDK — enterprise search, knowledge graph, and AI agents across 103+ connectors",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsdown src/index.ts --format esm --dts --clean",
22
+ "typecheck": "tsc --noEmit"
23
+ },
24
+ "keywords": [
25
+ "openbeam",
26
+ "enterprise-search",
27
+ "knowledge-graph",
28
+ "ai-agents",
29
+ "rag",
30
+ "mcp",
31
+ "connectors",
32
+ "sdk",
33
+ "typescript"
34
+ ],
35
+ "license": "Apache-2.0",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/nicholasgriffintn/openbeam.git",
39
+ "directory": "packages/sdk"
40
+ },
41
+ "homepage": "https://openbeam.work",
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "sideEffects": false
46
+ }