@realtimex/sdk 1.6.0 → 1.7.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.
@@ -0,0 +1,828 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/v1/index.ts
21
+ var v1_exports = {};
22
+ __export(v1_exports, {
23
+ AuthenticationError: () => AuthenticationError,
24
+ DeveloperApiClient: () => DeveloperApiClient,
25
+ DeveloperApiError: () => DeveloperApiError,
26
+ NotFoundError: () => NotFoundError,
27
+ ServerError: () => ServerError,
28
+ V1AdminModule: () => V1AdminModule,
29
+ V1ApiNamespace: () => V1ApiNamespace,
30
+ V1AuthModule: () => V1AuthModule,
31
+ V1DocumentModule: () => V1DocumentModule,
32
+ V1EmbedModule: () => V1EmbedModule,
33
+ V1OpenAIModule: () => V1OpenAIModule,
34
+ V1SystemModule: () => V1SystemModule,
35
+ V1ThreadModule: () => V1ThreadModule,
36
+ V1UsersModule: () => V1UsersModule,
37
+ V1WorkspaceModule: () => V1WorkspaceModule,
38
+ ValidationError: () => ValidationError,
39
+ streamThreadChat: () => streamThreadChat,
40
+ streamWorkspaceChat: () => streamWorkspaceChat,
41
+ uploadFile: () => uploadFile,
42
+ uploadFileToFolder: () => uploadFileToFolder
43
+ });
44
+ module.exports = __toCommonJS(v1_exports);
45
+
46
+ // src/v1/errors.ts
47
+ var DeveloperApiError = class extends Error {
48
+ constructor(status, code, message) {
49
+ super(message);
50
+ this.status = status;
51
+ this.code = code;
52
+ this.name = "DeveloperApiError";
53
+ }
54
+ };
55
+ var AuthenticationError = class extends DeveloperApiError {
56
+ constructor(message = "Invalid or missing API key") {
57
+ super(403, "AUTHENTICATION_ERROR", message);
58
+ this.name = "AuthenticationError";
59
+ }
60
+ };
61
+ var NotFoundError = class extends DeveloperApiError {
62
+ constructor(message = "Resource not found") {
63
+ super(404, "NOT_FOUND", message);
64
+ this.name = "NotFoundError";
65
+ }
66
+ };
67
+ var ValidationError = class extends DeveloperApiError {
68
+ constructor(message) {
69
+ super(400, "VALIDATION_ERROR", message);
70
+ this.name = "ValidationError";
71
+ }
72
+ };
73
+ var ServerError = class extends DeveloperApiError {
74
+ constructor(message = "Internal server error") {
75
+ super(500, "SERVER_ERROR", message);
76
+ this.name = "ServerError";
77
+ }
78
+ };
79
+
80
+ // src/v1/client.ts
81
+ var DeveloperApiClient = class {
82
+ constructor(baseUrl, apiKey, appId) {
83
+ this.baseUrl = baseUrl.replace(/\/$/, "");
84
+ this.apiKey = apiKey;
85
+ this.appId = appId;
86
+ }
87
+ getHeaders(extra) {
88
+ const headers = {
89
+ "Content-Type": "application/json",
90
+ "Authorization": `Bearer ${this.apiKey}`
91
+ };
92
+ if (this.appId) headers["x-app-id"] = this.appId;
93
+ return { ...headers, ...extra };
94
+ }
95
+ async handleResponse(response) {
96
+ let data;
97
+ try {
98
+ data = await response.json();
99
+ } catch {
100
+ data = {};
101
+ }
102
+ if (response.ok) return data;
103
+ const message = data?.message || data?.error || response.statusText || "Request failed";
104
+ switch (response.status) {
105
+ case 400:
106
+ throw new ValidationError(message);
107
+ case 401:
108
+ case 403:
109
+ throw new AuthenticationError(message);
110
+ case 404:
111
+ throw new NotFoundError(message);
112
+ case 500:
113
+ case 502:
114
+ case 503:
115
+ throw new ServerError(message);
116
+ default:
117
+ throw new DeveloperApiError(response.status, "API_ERROR", message);
118
+ }
119
+ }
120
+ /**
121
+ * Make a JSON request to the v1 API.
122
+ */
123
+ async request(method, path, body) {
124
+ const url = `${this.baseUrl}/api${path}`;
125
+ const response = await fetch(url, {
126
+ method,
127
+ headers: this.getHeaders(),
128
+ body: body !== void 0 ? JSON.stringify(body) : void 0
129
+ });
130
+ return this.handleResponse(response);
131
+ }
132
+ /**
133
+ * Make a multipart/form-data request (e.g. file uploads).
134
+ * Do NOT set Content-Type — browser/fetch will set it with the boundary.
135
+ */
136
+ async requestMultipart(method, path, form) {
137
+ const url = `${this.baseUrl}/api${path}`;
138
+ const authHeaders = { "Authorization": `Bearer ${this.apiKey}` };
139
+ if (this.appId) authHeaders["x-app-id"] = this.appId;
140
+ const response = await fetch(url, {
141
+ method,
142
+ headers: authHeaders,
143
+ body: form
144
+ });
145
+ return this.handleResponse(response);
146
+ }
147
+ /**
148
+ * Make a raw request and return the Response object directly.
149
+ * Used for streaming (SSE) endpoints.
150
+ */
151
+ async requestRaw(method, path, body) {
152
+ const url = `${this.baseUrl}/api${path}`;
153
+ return fetch(url, {
154
+ method,
155
+ headers: this.getHeaders(),
156
+ body: body !== void 0 ? JSON.stringify(body) : void 0
157
+ });
158
+ }
159
+ };
160
+
161
+ // src/v1/modules/v1Auth.ts
162
+ var V1AuthModule = class {
163
+ constructor(client) {
164
+ this.client = client;
165
+ }
166
+ /**
167
+ * Verify the attached Authentication header contains a valid API token.
168
+ * @see GET /v1/auth
169
+ */
170
+ async getAuth() {
171
+ return this.client.request("GET", `/v1/auth`);
172
+ }
173
+ };
174
+
175
+ // src/v1/modules/v1Admin.ts
176
+ var V1AdminModule = class {
177
+ constructor(client) {
178
+ this.client = client;
179
+ }
180
+ /**
181
+ * Check to see if the instance is in multi-user-mode first. Methods are disabled until multi user mode is enabled via the UI.
182
+ * @see GET /v1/admin/is-multi-user-mode
183
+ */
184
+ async getIsMultiUserMode() {
185
+ return this.client.request("GET", `/v1/admin/is-multi-user-mode`);
186
+ }
187
+ /**
188
+ * Check to see if the instance is in multi-user-mode first. Methods are disabled until multi user mode is enabled via the UI.
189
+ * @see GET /v1/admin/users
190
+ */
191
+ async listUsers() {
192
+ return this.client.request("GET", `/v1/admin/users`);
193
+ }
194
+ /**
195
+ * Create a new user with username and password. Methods are disabled until multi user mode is enabled via the UI.
196
+ * @see POST /v1/admin/users/new
197
+ */
198
+ async createUser(body) {
199
+ return this.client.request("POST", `/v1/admin/users/new`, body);
200
+ }
201
+ /**
202
+ * Update existing user settings. Methods are disabled until multi user mode is enabled via the UI.
203
+ * @see POST /v1/admin/users/{id}
204
+ */
205
+ async updateUser(id, body) {
206
+ return this.client.request("POST", `/v1/admin/users/${id}`, body);
207
+ }
208
+ /**
209
+ * Delete existing user by id. Methods are disabled until multi user mode is enabled via the UI.
210
+ * @see DELETE /v1/admin/users/{id}
211
+ */
212
+ async deleteUser(id) {
213
+ return this.client.request("DELETE", `/v1/admin/users/${id}`);
214
+ }
215
+ /**
216
+ * List all existing invitations to instance regardless of status. Methods are disabled until multi user mode is enabled via the UI.
217
+ * @see GET /v1/admin/invites
218
+ */
219
+ async listInvites() {
220
+ return this.client.request("GET", `/v1/admin/invites`);
221
+ }
222
+ /**
223
+ * Create a new invite code for someone to use to register with instance. Methods are disabled until multi user mode is enabled via the UI.
224
+ * @see POST /v1/admin/invite/new
225
+ */
226
+ async createInvite(body) {
227
+ return this.client.request("POST", `/v1/admin/invite/new`, body);
228
+ }
229
+ /**
230
+ * Deactivates (soft-delete) invite by id. Methods are disabled until multi user mode is enabled via the UI.
231
+ * @see DELETE /v1/admin/invite/{id}
232
+ */
233
+ async deleteInvite(id) {
234
+ return this.client.request("DELETE", `/v1/admin/invite/${id}`);
235
+ }
236
+ /**
237
+ * Retrieve a list of users with permissions to access the specified workspace.
238
+ * @see GET /v1/admin/workspaces/{workspaceId}/users
239
+ */
240
+ async listWorkspaceUsers(workspaceId) {
241
+ return this.client.request("GET", `/v1/admin/workspaces/${workspaceId}/users`);
242
+ }
243
+ /**
244
+ * Overwrite workspace permissions to only be accessible by the given user ids and admins. Methods are disabled until multi user mode is enabled via the UI.
245
+ * @see POST /v1/admin/workspaces/{workspaceId}/update-users
246
+ */
247
+ async updateUsers(workspaceId, body) {
248
+ return this.client.request("POST", `/v1/admin/workspaces/${workspaceId}/update-users`, body);
249
+ }
250
+ /**
251
+ * Set workspace permissions to be accessible by the given user ids and admins. Methods are disabled until multi user mode is enabled via the UI.
252
+ * @see POST /v1/admin/workspaces/{workspaceSlug}/manage-users
253
+ */
254
+ async workspacesManageUsers(workspaceSlug, body) {
255
+ return this.client.request("POST", `/v1/admin/workspaces/${workspaceSlug}/manage-users`, body);
256
+ }
257
+ /**
258
+ * All chats in the system ordered by most recent. Methods are disabled until multi user mode is enabled via the UI.
259
+ * @see POST /v1/admin/workspace-chats
260
+ */
261
+ async workspaceChats(body) {
262
+ return this.client.request("POST", `/v1/admin/workspace-chats`, body);
263
+ }
264
+ /**
265
+ * Update multi-user preferences for instance. Methods are disabled until multi user mode is enabled via the UI.
266
+ * @see POST /v1/admin/preferences
267
+ */
268
+ async createPreference(body) {
269
+ return this.client.request("POST", `/v1/admin/preferences`, body);
270
+ }
271
+ };
272
+
273
+ // src/v1/modules/v1Document.ts
274
+ var V1DocumentModule = class {
275
+ constructor(client) {
276
+ this.client = client;
277
+ }
278
+ /**
279
+ * Upload a new file to RealTimeX to be parsed and prepared for embedding.
280
+ * @see POST /v1/document/upload
281
+ */
282
+ // @upload-stub — multipart upload; wire form manually or use helper
283
+ async upload(form) {
284
+ return this.client.requestMultipart("POST", `/v1/document/upload`, form);
285
+ }
286
+ /**
287
+ * Upload a new file to a specific folder in RealTimeX to be parsed and prepared for embedding. If the folder does not exist, it will be created.
288
+ * @see POST /v1/document/upload/{folderName}
289
+ */
290
+ // @upload-stub — multipart upload; wire form manually or use helper
291
+ async uploadFolder(folderName, form) {
292
+ return this.client.requestMultipart("POST", `/v1/document/upload/${folderName}`, form);
293
+ }
294
+ /**
295
+ * Upload a valid URL for RealTimeX to scrape and prepare for embedding. Optionally, specify a comma-separated list of workspace slugs to embed the document into post-upload.
296
+ * @see POST /v1/document/upload-link
297
+ */
298
+ async uploadLink(body) {
299
+ return this.client.request("POST", `/v1/document/upload-link`, body);
300
+ }
301
+ /**
302
+ * Upload a file by specifying its raw text content and metadata values without having to upload a file.
303
+ * @see POST /v1/document/raw-text
304
+ */
305
+ async rawText(body) {
306
+ return this.client.request("POST", `/v1/document/raw-text`, body);
307
+ }
308
+ /**
309
+ * List of all locally-stored documents in instance
310
+ * @see GET /v1/documents
311
+ */
312
+ async listDocuments() {
313
+ return this.client.request("GET", `/v1/documents`);
314
+ }
315
+ /**
316
+ * Get all documents stored in a specific folder.
317
+ * @see GET /v1/documents/folder/{folderName}
318
+ */
319
+ async getFolder(folderName) {
320
+ return this.client.request("GET", `/v1/documents/folder/${folderName}`);
321
+ }
322
+ /**
323
+ * Check available filetypes and MIMEs that can be uploaded.
324
+ * @see GET /v1/document/accepted-file-types
325
+ */
326
+ async listAcceptedFileTypes() {
327
+ return this.client.request("GET", `/v1/document/accepted-file-types`);
328
+ }
329
+ /**
330
+ * Get the known available metadata schema for when doing a raw-text upload and the acceptable type of value for each key.
331
+ * @see GET /v1/document/metadata-schema
332
+ */
333
+ async getMetadataSchema() {
334
+ return this.client.request("GET", `/v1/document/metadata-schema`);
335
+ }
336
+ /**
337
+ * Get a single document by its unique RealTimeX document name
338
+ * @see GET /v1/document/{docName}
339
+ */
340
+ async getDocument(docName) {
341
+ return this.client.request("GET", `/v1/document/${docName}`);
342
+ }
343
+ /**
344
+ * Create a new folder inside the documents storage directory.
345
+ * @see POST /v1/document/create-folder
346
+ */
347
+ async createFolder(body) {
348
+ return this.client.request("POST", `/v1/document/create-folder`, body);
349
+ }
350
+ /**
351
+ * Remove a folder and all its contents from the documents storage directory.
352
+ * @see DELETE /v1/document/remove-folder
353
+ */
354
+ async deleteRemoveFolder() {
355
+ return this.client.request("DELETE", `/v1/document/remove-folder`);
356
+ }
357
+ /**
358
+ * Move files within the documents storage directory.
359
+ * @see POST /v1/document/move-files
360
+ */
361
+ async moveFiles(body) {
362
+ return this.client.request("POST", `/v1/document/move-files`, body);
363
+ }
364
+ };
365
+
366
+ // src/v1/modules/v1Workspace.ts
367
+ var V1WorkspaceModule = class {
368
+ constructor(client) {
369
+ this.client = client;
370
+ }
371
+ /**
372
+ * Create a new workspace
373
+ * @see POST /v1/workspace/new
374
+ */
375
+ async createWorkspace(body) {
376
+ return this.client.request("POST", `/v1/workspace/new`, body);
377
+ }
378
+ /**
379
+ * List all current workspaces
380
+ * @see GET /v1/workspaces
381
+ */
382
+ async listWorkspaces() {
383
+ return this.client.request("GET", `/v1/workspaces`);
384
+ }
385
+ /**
386
+ * Get a workspace by its unique slug.
387
+ * @see GET /v1/workspace/{slug}
388
+ */
389
+ async getWorkspace(slug) {
390
+ return this.client.request("GET", `/v1/workspace/${slug}`);
391
+ }
392
+ /**
393
+ * Deletes a workspace by its slug.
394
+ * @see DELETE /v1/workspace/{slug}
395
+ */
396
+ async deleteWorkspace(slug) {
397
+ return this.client.request("DELETE", `/v1/workspace/${slug}`);
398
+ }
399
+ /**
400
+ * Update workspace settings by its unique slug.
401
+ * @see POST /v1/workspace/{slug}/update
402
+ */
403
+ async updateWorkspace(slug, body) {
404
+ return this.client.request("POST", `/v1/workspace/${slug}/update`, body);
405
+ }
406
+ /**
407
+ * Get a workspaces chats regardless of user by its unique slug.
408
+ * @see GET /v1/workspace/{slug}/chats
409
+ */
410
+ async listChats(slug) {
411
+ return this.client.request("GET", `/v1/workspace/${slug}/chats`);
412
+ }
413
+ /**
414
+ * Add or remove documents from a workspace by its unique slug.
415
+ * @see POST /v1/workspace/{slug}/update-embeddings
416
+ */
417
+ async updateEmbeddings(slug, body) {
418
+ return this.client.request("POST", `/v1/workspace/${slug}/update-embeddings`, body);
419
+ }
420
+ /**
421
+ * Add or remove pin from a document in a workspace by its unique slug.
422
+ * @see POST /v1/workspace/{slug}/update-pin
423
+ */
424
+ async updatePin(slug, body) {
425
+ return this.client.request("POST", `/v1/workspace/${slug}/update-pin`, body);
426
+ }
427
+ /**
428
+ * Execute a chat with a workspace
429
+ * @see POST /v1/workspace/{slug}/chat
430
+ */
431
+ async chat(slug, body) {
432
+ return this.client.request("POST", `/v1/workspace/${slug}/chat`, body);
433
+ }
434
+ /**
435
+ * Execute a streamable chat with a workspace
436
+ * @see POST /v1/workspace/{slug}/stream-chat
437
+ */
438
+ // @streaming-stub — implement SSE parsing in overrides/v1WorkspaceStreaming.ts
439
+ async streamChat(slug, body) {
440
+ return this.client.requestRaw("POST", `/v1/workspace/${slug}/stream-chat`, body);
441
+ }
442
+ /**
443
+ * Perform a vector similarity search in a workspace
444
+ * @see POST /v1/workspace/{slug}/vector-search
445
+ */
446
+ async vectorSearch(slug, body) {
447
+ return this.client.request("POST", `/v1/workspace/${slug}/vector-search`, body);
448
+ }
449
+ };
450
+
451
+ // src/v1/modules/v1System.ts
452
+ var V1SystemModule = class {
453
+ constructor(client) {
454
+ this.client = client;
455
+ }
456
+ /**
457
+ * Dump all settings to file storage
458
+ * @see GET /v1/system/env-dump
459
+ */
460
+ async getEnvDump() {
461
+ return this.client.request("GET", `/v1/system/env-dump`);
462
+ }
463
+ /**
464
+ * Get all current system settings that are defined.
465
+ * @see GET /v1/system
466
+ */
467
+ async getSystem() {
468
+ return this.client.request("GET", `/v1/system`);
469
+ }
470
+ /**
471
+ * Number of all vectors in connected vector database
472
+ * @see GET /v1/system/vector-count
473
+ */
474
+ async getVectorCount() {
475
+ return this.client.request("GET", `/v1/system/vector-count`);
476
+ }
477
+ /**
478
+ * Update a system setting or preference.
479
+ * @see POST /v1/system/update-env
480
+ */
481
+ async updateEnv(body) {
482
+ return this.client.request("POST", `/v1/system/update-env`, body);
483
+ }
484
+ /**
485
+ * Export all of the chats from the system in a known format. Output depends on the type sent. Will be send with the correct header for the output.
486
+ * @see GET /v1/system/export-chats
487
+ */
488
+ async listExportChats() {
489
+ return this.client.request("GET", `/v1/system/export-chats`);
490
+ }
491
+ /**
492
+ * Permanently remove documents from the system.
493
+ * @see DELETE /v1/system/remove-documents
494
+ */
495
+ async deleteRemoveDocument() {
496
+ return this.client.request("DELETE", `/v1/system/remove-documents`);
497
+ }
498
+ /**
499
+ * Returns a health check object with server uptime and version.
500
+ * @see GET /v1/system/health
501
+ */
502
+ async getHealth() {
503
+ return this.client.request("GET", `/v1/system/health`);
504
+ }
505
+ /**
506
+ * Returns a health check object with server uptime and version.
507
+ * @see GET /v1/system/health-version-2
508
+ */
509
+ async getHealthVersion2() {
510
+ return this.client.request("GET", `/v1/system/health-version-2`);
511
+ }
512
+ /**
513
+ * Returns a health check object with server uptime and version.
514
+ * @see GET /v1/system/health-version-3
515
+ */
516
+ async getHealthVersion3() {
517
+ return this.client.request("GET", `/v1/system/health-version-3`);
518
+ }
519
+ };
520
+
521
+ // src/v1/modules/v1Thread.ts
522
+ var V1ThreadModule = class {
523
+ constructor(client) {
524
+ this.client = client;
525
+ }
526
+ /**
527
+ * Create a new workspace thread
528
+ * @see POST /v1/workspace/{slug}/thread/new
529
+ */
530
+ async createThread(slug, body) {
531
+ return this.client.request("POST", `/v1/workspace/${slug}/thread/new`, body);
532
+ }
533
+ /**
534
+ * Update thread settings by its unique slug.
535
+ * @see POST /v1/workspace/{slug}/thread/{threadSlug}/update
536
+ */
537
+ async updateThread(slug, threadSlug, body) {
538
+ return this.client.request("POST", `/v1/workspace/${slug}/thread/${threadSlug}/update`, body);
539
+ }
540
+ /**
541
+ * Delete a workspace thread
542
+ * @see DELETE /v1/workspace/{slug}/thread/{threadSlug}
543
+ */
544
+ async deleteThread(slug, threadSlug) {
545
+ return this.client.request("DELETE", `/v1/workspace/${slug}/thread/${threadSlug}`);
546
+ }
547
+ /**
548
+ * Get chats for a workspace thread
549
+ * @see GET /v1/workspace/{slug}/thread/{threadSlug}/chats
550
+ */
551
+ async listChats(slug, threadSlug) {
552
+ return this.client.request("GET", `/v1/workspace/${slug}/thread/${threadSlug}/chats`);
553
+ }
554
+ /**
555
+ * Chat with a workspace thread
556
+ * @see POST /v1/workspace/{slug}/thread/{threadSlug}/chat
557
+ */
558
+ async chat(slug, threadSlug, body) {
559
+ return this.client.request("POST", `/v1/workspace/${slug}/thread/${threadSlug}/chat`, body);
560
+ }
561
+ /**
562
+ * Stream chat with a workspace thread
563
+ * @see POST /v1/workspace/{slug}/thread/{threadSlug}/stream-chat
564
+ */
565
+ // @streaming-stub — implement SSE parsing in overrides/v1ThreadStreaming.ts
566
+ async streamChat(slug, threadSlug, body) {
567
+ return this.client.requestRaw("POST", `/v1/workspace/${slug}/thread/${threadSlug}/stream-chat`, body);
568
+ }
569
+ };
570
+
571
+ // src/v1/modules/v1Users.ts
572
+ var V1UsersModule = class {
573
+ constructor(client) {
574
+ this.client = client;
575
+ }
576
+ /**
577
+ * List all users
578
+ * @see GET /v1/users
579
+ */
580
+ async listUsers() {
581
+ return this.client.request("GET", `/v1/users`);
582
+ }
583
+ /**
584
+ * Issue a temporary auth token for a user
585
+ * @see GET /v1/users/{id}/issue-auth-token
586
+ */
587
+ async getIssueAuthToken(id) {
588
+ return this.client.request("GET", `/v1/users/${id}/issue-auth-token`);
589
+ }
590
+ };
591
+
592
+ // src/v1/modules/v1OpenAI.ts
593
+ var V1OpenAIModule = class {
594
+ constructor(client) {
595
+ this.client = client;
596
+ }
597
+ /**
598
+ * Get all available "models" which are workspaces you can use for chatting.
599
+ * @see GET /v1/openai/models
600
+ */
601
+ async listModels() {
602
+ return this.client.request("GET", `/v1/openai/models`);
603
+ }
604
+ /**
605
+ * Execute a chat with a workspace with OpenAI compatibility. Supports streaming as well. Model must be a workspace slug from /models.
606
+ * @see POST /v1/openai/chat/completions
607
+ */
608
+ async chatCompletions(body) {
609
+ return this.client.request("POST", `/v1/openai/chat/completions`, body);
610
+ }
611
+ /**
612
+ * Get the embeddings of any arbitrary text string. This will use the embedder provider set in the system. Please ensure the token length of each string fits within the context of your embedder model.
613
+ * @see POST /v1/openai/embeddings
614
+ */
615
+ async createEmbedding(body) {
616
+ return this.client.request("POST", `/v1/openai/embeddings`, body);
617
+ }
618
+ /**
619
+ * List all the vector database collections connected to RealTimeX. These are essentially workspaces but return their unique vector db identifier - this is the same as the workspace slug.
620
+ * @see GET /v1/openai/vector_stores
621
+ */
622
+ async listVectorStores() {
623
+ return this.client.request("GET", `/v1/openai/vector_stores`);
624
+ }
625
+ };
626
+
627
+ // src/v1/modules/v1Embed.ts
628
+ var V1EmbedModule = class {
629
+ constructor(client) {
630
+ this.client = client;
631
+ }
632
+ /**
633
+ * List all active embeds
634
+ * @see GET /v1/embed
635
+ */
636
+ async getEmbed() {
637
+ return this.client.request("GET", `/v1/embed`);
638
+ }
639
+ /**
640
+ * Get all chats for a specific embed
641
+ * @see GET /v1/embed/{embedUuid}/chats
642
+ */
643
+ async listChats(embedUuid) {
644
+ return this.client.request("GET", `/v1/embed/${embedUuid}/chats`);
645
+ }
646
+ /**
647
+ * Get chats for a specific embed and session
648
+ * @see GET /v1/embed/{embedUuid}/chats/{sessionUuid}
649
+ */
650
+ async getChat(embedUuid, sessionUuid) {
651
+ return this.client.request("GET", `/v1/embed/${embedUuid}/chats/${sessionUuid}`);
652
+ }
653
+ /**
654
+ * Create a new embed configuration
655
+ * @see POST /v1/embed/new
656
+ */
657
+ async createEmbed(body) {
658
+ return this.client.request("POST", `/v1/embed/new`, body);
659
+ }
660
+ /**
661
+ * Update an existing embed configuration
662
+ * @see POST /v1/embed/{embedUuid}
663
+ */
664
+ async updateEmbed(embedUuid, body) {
665
+ return this.client.request("POST", `/v1/embed/${embedUuid}`, body);
666
+ }
667
+ /**
668
+ * Delete an existing embed configuration
669
+ * @see DELETE /v1/embed/{embedUuid}
670
+ */
671
+ async deleteEmbed(embedUuid) {
672
+ return this.client.request("DELETE", `/v1/embed/${embedUuid}`);
673
+ }
674
+ };
675
+
676
+ // src/v1/namespace.ts
677
+ var V1ApiNamespace = class {
678
+ // [GENERATED-PROPS-END]
679
+ constructor(baseUrl, apiKey, appId) {
680
+ this._client = new DeveloperApiClient(baseUrl, apiKey, appId);
681
+ this.auth = new V1AuthModule(this._client);
682
+ this.admin = new V1AdminModule(this._client);
683
+ this.document = new V1DocumentModule(this._client);
684
+ this.workspace = new V1WorkspaceModule(this._client);
685
+ this.system = new V1SystemModule(this._client);
686
+ this.thread = new V1ThreadModule(this._client);
687
+ this.users = new V1UsersModule(this._client);
688
+ this.openai = new V1OpenAIModule(this._client);
689
+ this.embed = new V1EmbedModule(this._client);
690
+ }
691
+ };
692
+
693
+ // src/v1/overrides/v1WorkspaceStreaming.ts
694
+ async function* streamWorkspaceChat(client, slug, body) {
695
+ const response = await client.requestRaw("POST", `/v1/workspace/${slug}/stream-chat`, body);
696
+ if (!response.body) {
697
+ throw new Error("Response body is null \u2014 streaming is not supported in this environment");
698
+ }
699
+ const reader = response.body.getReader();
700
+ const decoder = new TextDecoder();
701
+ let buffer = "";
702
+ let isErrorEvent = false;
703
+ try {
704
+ while (true) {
705
+ const { done, value } = await reader.read();
706
+ if (done) break;
707
+ buffer += decoder.decode(value, { stream: true });
708
+ const lines = buffer.split("\n");
709
+ buffer = lines.pop() ?? "";
710
+ for (const line of lines) {
711
+ if (line.startsWith("event: error")) {
712
+ isErrorEvent = true;
713
+ continue;
714
+ }
715
+ if (line.startsWith("data: ")) {
716
+ const jsonStr = line.slice(6).trim();
717
+ if (jsonStr === "[DONE]") {
718
+ isErrorEvent = false;
719
+ continue;
720
+ }
721
+ let data;
722
+ try {
723
+ data = JSON.parse(jsonStr);
724
+ } catch {
725
+ continue;
726
+ }
727
+ if (isErrorEvent) {
728
+ throw new Error(data.error ?? "Unknown streaming error from server");
729
+ }
730
+ yield data;
731
+ }
732
+ }
733
+ }
734
+ } finally {
735
+ reader.releaseLock();
736
+ }
737
+ }
738
+
739
+ // src/v1/overrides/v1ThreadStreaming.ts
740
+ async function* streamThreadChat(client, slug, threadSlug, body) {
741
+ const response = await client.requestRaw(
742
+ "POST",
743
+ `/v1/workspace/${slug}/thread/${threadSlug}/stream-chat`,
744
+ body
745
+ );
746
+ if (!response.body) {
747
+ throw new Error("Response body is null \u2014 streaming is not supported in this environment");
748
+ }
749
+ const reader = response.body.getReader();
750
+ const decoder = new TextDecoder();
751
+ let buffer = "";
752
+ let isErrorEvent = false;
753
+ try {
754
+ while (true) {
755
+ const { done, value } = await reader.read();
756
+ if (done) break;
757
+ buffer += decoder.decode(value, { stream: true });
758
+ const lines = buffer.split("\n");
759
+ buffer = lines.pop() ?? "";
760
+ for (const line of lines) {
761
+ if (line.startsWith("event: error")) {
762
+ isErrorEvent = true;
763
+ continue;
764
+ }
765
+ if (line.startsWith("data: ")) {
766
+ const jsonStr = line.slice(6).trim();
767
+ if (jsonStr === "[DONE]") {
768
+ isErrorEvent = false;
769
+ continue;
770
+ }
771
+ let data;
772
+ try {
773
+ data = JSON.parse(jsonStr);
774
+ } catch {
775
+ continue;
776
+ }
777
+ if (isErrorEvent) {
778
+ throw new Error(data.error ?? "Unknown streaming error from server");
779
+ }
780
+ yield data;
781
+ }
782
+ }
783
+ }
784
+ } finally {
785
+ reader.releaseLock();
786
+ }
787
+ }
788
+
789
+ // src/v1/overrides/v1DocumentUpload.ts
790
+ async function uploadFile(client, file, options = {}) {
791
+ const form = new FormData();
792
+ const filename = options.filename ?? (file instanceof File ? file.name : "upload");
793
+ form.append("file", file, filename);
794
+ return client.requestMultipart("POST", `/v1/document/upload`, form);
795
+ }
796
+ async function uploadFileToFolder(client, file, folderName, options = {}) {
797
+ const form = new FormData();
798
+ const filename = options.filename ?? (file instanceof File ? file.name : "upload");
799
+ form.append("file", file, filename);
800
+ return client.requestMultipart(
801
+ "POST",
802
+ `/v1/document/upload/${encodeURIComponent(folderName)}`,
803
+ form
804
+ );
805
+ }
806
+ // Annotate the CommonJS export names for ESM import in node:
807
+ 0 && (module.exports = {
808
+ AuthenticationError,
809
+ DeveloperApiClient,
810
+ DeveloperApiError,
811
+ NotFoundError,
812
+ ServerError,
813
+ V1AdminModule,
814
+ V1ApiNamespace,
815
+ V1AuthModule,
816
+ V1DocumentModule,
817
+ V1EmbedModule,
818
+ V1OpenAIModule,
819
+ V1SystemModule,
820
+ V1ThreadModule,
821
+ V1UsersModule,
822
+ V1WorkspaceModule,
823
+ ValidationError,
824
+ streamThreadChat,
825
+ streamWorkspaceChat,
826
+ uploadFile,
827
+ uploadFileToFolder
828
+ });