@docrouter/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,689 @@
1
+ import axios, { isAxiosError } from 'axios';
2
+
3
+ // src/http-client.ts
4
+ var HttpClient = class {
5
+ constructor(config) {
6
+ this.isRefreshing = false;
7
+ this.failedQueue = [];
8
+ this.config = config;
9
+ this.axios = axios.create({
10
+ baseURL: config.baseURL,
11
+ timeout: config.timeout || 3e4,
12
+ headers: {
13
+ "Content-Type": "application/json"
14
+ }
15
+ });
16
+ this.setupInterceptors();
17
+ }
18
+ setupInterceptors() {
19
+ this.axios.interceptors.request.use(
20
+ async (config) => {
21
+ const token = await this.getToken();
22
+ if (token) {
23
+ config.headers.Authorization = `Bearer ${token}`;
24
+ }
25
+ return config;
26
+ },
27
+ (error) => Promise.reject(error)
28
+ );
29
+ this.axios.interceptors.response.use(
30
+ (response) => response,
31
+ async (error) => {
32
+ const originalRequest = error.config;
33
+ if (error.response?.status === 401 && !originalRequest._retry) {
34
+ if (this.isRefreshing) {
35
+ return new Promise((resolve, reject) => {
36
+ this.failedQueue.push({ resolve, reject });
37
+ }).then(() => this.axios(originalRequest)).catch((err) => {
38
+ this.handleAuthError(err);
39
+ return Promise.reject(err);
40
+ });
41
+ }
42
+ originalRequest._retry = true;
43
+ this.isRefreshing = true;
44
+ try {
45
+ const newToken = await this.getToken();
46
+ if (newToken) {
47
+ originalRequest.headers.Authorization = `Bearer ${newToken}`;
48
+ this.processQueue();
49
+ return this.axios(originalRequest);
50
+ } else {
51
+ this.handleAuthError(error);
52
+ return Promise.reject(this.createApiError(error));
53
+ }
54
+ } catch (refreshError) {
55
+ this.processQueue(refreshError instanceof Error ? refreshError : new Error("Token refresh failed"));
56
+ this.handleAuthError(error);
57
+ return Promise.reject(this.createApiError(error));
58
+ } finally {
59
+ this.isRefreshing = false;
60
+ }
61
+ }
62
+ return Promise.reject(this.createApiError(error));
63
+ }
64
+ );
65
+ }
66
+ async getToken() {
67
+ if (this.config.token) {
68
+ return this.config.token;
69
+ }
70
+ if (this.config.tokenProvider) {
71
+ try {
72
+ return await this.config.tokenProvider();
73
+ } catch (error) {
74
+ console.warn("Token provider failed:", error);
75
+ return null;
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+ processQueue(error = null) {
81
+ this.failedQueue.forEach((prom) => {
82
+ if (error) {
83
+ prom.reject(error);
84
+ } else {
85
+ prom.resolve();
86
+ }
87
+ });
88
+ this.failedQueue = [];
89
+ }
90
+ handleAuthError(error) {
91
+ if (this.config.onAuthError) {
92
+ this.config.onAuthError(error instanceof Error ? error : new Error("Authentication failed"));
93
+ }
94
+ }
95
+ createApiError(error) {
96
+ if (isAxiosError(error)) {
97
+ const message = error.response?.data?.detail || error.message || "Request failed";
98
+ const apiError = new Error(message);
99
+ apiError.status = error.response?.status;
100
+ apiError.code = error.code;
101
+ apiError.details = error.response?.data;
102
+ return apiError;
103
+ }
104
+ if (error instanceof Error) {
105
+ const apiError = error;
106
+ return apiError;
107
+ }
108
+ return new Error("Unknown error occurred");
109
+ }
110
+ // Public methods
111
+ async get(url, config) {
112
+ const response = await this.axios.get(url, config);
113
+ return response.data;
114
+ }
115
+ async post(url, data, config) {
116
+ const response = await this.axios.post(url, data, config);
117
+ return response.data;
118
+ }
119
+ async put(url, data, config) {
120
+ const response = await this.axios.put(url, data, config);
121
+ return response.data;
122
+ }
123
+ async delete(url, config) {
124
+ const response = await this.axios.delete(url, config);
125
+ return response.data;
126
+ }
127
+ async request(config) {
128
+ const response = await this.axios.request(config);
129
+ return response.data;
130
+ }
131
+ // For streaming requests
132
+ async stream(url, data, onChunk, onError, abortSignal) {
133
+ try {
134
+ const token = await this.getToken();
135
+ if (!token) {
136
+ throw new Error("No token available for streaming request");
137
+ }
138
+ const response = await fetch(`${this.config.baseURL}${url}`, {
139
+ method: "POST",
140
+ headers: {
141
+ "Content-Type": "application/json",
142
+ "Authorization": `Bearer ${token}`,
143
+ "Accept": "text/plain",
144
+ "Cache-Control": "no-cache"
145
+ },
146
+ body: JSON.stringify(data),
147
+ signal: abortSignal
148
+ });
149
+ if (!response.ok) {
150
+ throw new Error(`HTTP error! status: ${response.status}`);
151
+ }
152
+ if (!response.body) {
153
+ throw new Error("Response body is not available for streaming");
154
+ }
155
+ const reader = response.body.getReader();
156
+ const decoder = new TextDecoder();
157
+ let buffer = "";
158
+ try {
159
+ while (true) {
160
+ const { done, value } = await reader.read();
161
+ if (done) {
162
+ break;
163
+ }
164
+ buffer += decoder.decode(value, { stream: true });
165
+ const lines = buffer.split("\n");
166
+ buffer = lines.pop() || "";
167
+ for (const line of lines) {
168
+ if (line.startsWith("data: ")) {
169
+ try {
170
+ const chunkData = JSON.parse(line.slice(6));
171
+ onChunk(chunkData);
172
+ if (chunkData.done) {
173
+ return;
174
+ }
175
+ } catch (parseError) {
176
+ console.warn("Failed to parse streaming chunk:", parseError);
177
+ }
178
+ }
179
+ }
180
+ }
181
+ } finally {
182
+ reader.releaseLock();
183
+ }
184
+ } catch (error) {
185
+ if (onError) {
186
+ onError(error instanceof Error ? error : new Error("Streaming request failed"));
187
+ } else {
188
+ throw error;
189
+ }
190
+ }
191
+ }
192
+ // Update token
193
+ updateToken(token) {
194
+ this.config.token = token;
195
+ }
196
+ // Update token provider
197
+ updateTokenProvider(provider) {
198
+ this.config.tokenProvider = provider;
199
+ }
200
+ };
201
+
202
+ // src/docrouter-account.ts
203
+ var DocRouterAccount = class {
204
+ constructor(config) {
205
+ this.http = new HttpClient({
206
+ baseURL: config.baseURL,
207
+ token: config.accountToken,
208
+ timeout: config.timeout,
209
+ retries: config.retries,
210
+ onAuthError: config.onAuthError
211
+ });
212
+ }
213
+ /**
214
+ * Update the account token
215
+ */
216
+ updateToken(token) {
217
+ this.http.updateToken(token);
218
+ }
219
+ // --------------- Organizations ---------------
220
+ async listOrganizations(params) {
221
+ const queryParams = new URLSearchParams();
222
+ if (params?.userId) queryParams.append("user_id", params.userId);
223
+ if (params?.organizationId) queryParams.append("organization_id", params.organizationId);
224
+ if (params?.nameSearch) queryParams.append("name_search", params.nameSearch);
225
+ if (params?.memberSearch) queryParams.append("member_search", params.memberSearch);
226
+ if (params?.skip !== void 0) queryParams.append("skip", String(params.skip));
227
+ if (params?.limit !== void 0) queryParams.append("limit", String(params.limit));
228
+ return this.http.get(`/v0/account/organizations?${queryParams.toString()}`);
229
+ }
230
+ async getOrganization(organizationId) {
231
+ const response = await this.listOrganizations({ organizationId });
232
+ return response.organizations[0];
233
+ }
234
+ async createOrganization(organization) {
235
+ const response = await this.http.post(`/v0/account/organizations`, organization);
236
+ return {
237
+ id: response._id || response.id,
238
+ name: response.name,
239
+ members: response.members,
240
+ type: response.type,
241
+ created_at: response.created_at,
242
+ updated_at: response.updated_at
243
+ };
244
+ }
245
+ async updateOrganization(organizationId, update) {
246
+ return this.http.put(`/v0/account/organizations/${organizationId}`, update);
247
+ }
248
+ async deleteOrganization(organizationId) {
249
+ return this.http.delete(`/v0/account/organizations/${organizationId}`);
250
+ }
251
+ // --------------- Tokens ---------------
252
+ async createAccountToken(request) {
253
+ return this.http.post(`/v0/account/access_tokens`, request);
254
+ }
255
+ async getAccountTokens() {
256
+ const resp = await this.http.get(`/v0/account/access_tokens`);
257
+ return Array.isArray(resp) ? resp : resp.access_tokens;
258
+ }
259
+ async deleteAccountToken(tokenId) {
260
+ return this.http.delete(`/v0/account/access_tokens/${tokenId}`);
261
+ }
262
+ async createOrganizationToken(request, organizationId) {
263
+ return this.http.post(`/v0/orgs/${organizationId}/access_tokens`, request);
264
+ }
265
+ async getOrganizationTokens(organizationId) {
266
+ return this.http.get(`/v0/orgs/${organizationId}/access_tokens`);
267
+ }
268
+ async deleteOrganizationToken(tokenId, organizationId) {
269
+ return this.http.delete(`/v0/orgs/${organizationId}/access_tokens/${tokenId}`);
270
+ }
271
+ // --------------- LLM (account-level) ---------------
272
+ async listLLMModels(params) {
273
+ return this.http.get("/v0/account/llm/models", {
274
+ params: {
275
+ provider_name: params.providerName,
276
+ provider_enabled: params.providerEnabled,
277
+ llm_enabled: params.llmEnabled
278
+ }
279
+ });
280
+ }
281
+ async listLLMProviders() {
282
+ return this.http.get("/v0/account/llm/providers");
283
+ }
284
+ async setLLMProviderConfig(providerName, request) {
285
+ return this.http.put(`/v0/account/llm/provider/${providerName}`, request);
286
+ }
287
+ // --------------- Users ---------------
288
+ async listUsers(params) {
289
+ const queryParams = new URLSearchParams();
290
+ if (params?.skip) queryParams.append("skip", String(params.skip));
291
+ if (params?.limit) queryParams.append("limit", String(params.limit));
292
+ if (params?.organization_id) queryParams.append("organization_id", params.organization_id);
293
+ if (params?.user_id) queryParams.append("user_id", params.user_id);
294
+ if (params?.search_name) queryParams.append("search_name", params.search_name);
295
+ return this.http.get(`/v0/account/users?${queryParams.toString()}`);
296
+ }
297
+ async getUser(userId) {
298
+ const response = await this.listUsers({ user_id: userId });
299
+ const user = response.users[0];
300
+ return { user };
301
+ }
302
+ async createUser(user) {
303
+ const created = await this.http.post(
304
+ "/v0/account/users",
305
+ user
306
+ );
307
+ return created.user ? created : { user: created };
308
+ }
309
+ async updateUser(userId, update) {
310
+ const updated = await this.http.put(
311
+ `/v0/account/users/${userId}`,
312
+ update
313
+ );
314
+ return updated.user ? updated : { user: updated };
315
+ }
316
+ async deleteUser(userId) {
317
+ await this.http.delete(`/v0/account/users/${userId}`);
318
+ }
319
+ // --------------- Email Verification ---------------
320
+ async sendVerificationEmail(userId) {
321
+ return this.http.post(`/v0/account/email/verification/send/${userId}`);
322
+ }
323
+ async sendRegistrationVerificationEmail(userId) {
324
+ return this.http.post(`/v0/account/email/verification/register/${userId}`);
325
+ }
326
+ async verifyEmail(token) {
327
+ return this.http.post(`/v0/account/email/verification/${token}`);
328
+ }
329
+ // --------------- AWS Config ---------------
330
+ async createAWSConfig(config) {
331
+ return this.http.post("/v0/account/aws_config", config);
332
+ }
333
+ async getAWSConfig() {
334
+ return this.http.get("/v0/account/aws_config");
335
+ }
336
+ async deleteAWSConfig() {
337
+ return this.http.delete("/v0/account/aws_config");
338
+ }
339
+ /**
340
+ * Get the current HTTP client (for advanced usage)
341
+ */
342
+ getHttpClient() {
343
+ return this.http;
344
+ }
345
+ };
346
+
347
+ // src/docrouter-org.ts
348
+ var DocRouterOrg = class {
349
+ constructor(config) {
350
+ this.organizationId = config.organizationId;
351
+ this.http = new HttpClient({
352
+ baseURL: config.baseURL,
353
+ token: config.orgToken,
354
+ timeout: config.timeout,
355
+ retries: config.retries,
356
+ onAuthError: config.onAuthError
357
+ });
358
+ }
359
+ /**
360
+ * Update the organization token
361
+ */
362
+ updateToken(token) {
363
+ this.http.updateToken(token);
364
+ }
365
+ // ---------------- Documents ----------------
366
+ async uploadDocuments(params) {
367
+ const documentsPayload = params.documents.map((doc) => {
368
+ let base64Content;
369
+ if (doc.content instanceof ArrayBuffer) {
370
+ const buffer = Buffer.from(doc.content);
371
+ base64Content = buffer.toString("base64");
372
+ } else if (doc.content instanceof Buffer) {
373
+ base64Content = doc.content.toString("base64");
374
+ } else if (doc.content instanceof Uint8Array) {
375
+ const buffer = Buffer.from(doc.content);
376
+ base64Content = buffer.toString("base64");
377
+ } else {
378
+ const uint8Array = new Uint8Array(doc.content);
379
+ const buffer = Buffer.from(uint8Array);
380
+ base64Content = buffer.toString("base64");
381
+ }
382
+ const payload = {
383
+ name: doc.name,
384
+ content: base64Content,
385
+ type: doc.type
386
+ };
387
+ if (doc.metadata) payload.metadata = doc.metadata;
388
+ return payload;
389
+ });
390
+ return this.http.post(
391
+ `/v0/orgs/${this.organizationId}/documents`,
392
+ { documents: documentsPayload }
393
+ );
394
+ }
395
+ async listDocuments(params) {
396
+ const queryParams = {
397
+ skip: params?.skip || 0,
398
+ limit: params?.limit || 10
399
+ };
400
+ if (params?.tagIds) queryParams.tag_ids = params.tagIds;
401
+ if (params?.nameSearch) queryParams.name_search = params.nameSearch;
402
+ if (params?.metadataSearch) queryParams.metadata_search = params.metadataSearch;
403
+ return this.http.get(`/v0/orgs/${this.organizationId}/documents`, {
404
+ params: queryParams
405
+ });
406
+ }
407
+ async getDocument(params) {
408
+ const { documentId, fileType } = params;
409
+ const response = await this.http.get(`/v0/orgs/${this.organizationId}/documents/${documentId}?file_type=${fileType}`);
410
+ const binaryContent = atob(response.content);
411
+ const len = binaryContent.length;
412
+ const bytes = new Uint8Array(len);
413
+ for (let i = 0; i < len; i++) {
414
+ bytes[i] = binaryContent.charCodeAt(i);
415
+ }
416
+ return {
417
+ id: response.id,
418
+ pdf_id: response.pdf_id,
419
+ document_name: response.document_name,
420
+ upload_date: response.upload_date,
421
+ uploaded_by: response.uploaded_by,
422
+ state: response.state,
423
+ tag_ids: response.tag_ids,
424
+ type: response.type,
425
+ metadata: response.metadata,
426
+ content: bytes.buffer
427
+ };
428
+ }
429
+ async updateDocument(params) {
430
+ const { documentId, documentName, tagIds, metadata } = params;
431
+ const updateData = {};
432
+ if (documentName !== void 0) updateData.document_name = documentName;
433
+ if (tagIds !== void 0) updateData.tag_ids = tagIds;
434
+ if (metadata !== void 0) updateData.metadata = metadata;
435
+ return this.http.put(`/v0/orgs/${this.organizationId}/documents/${documentId}`, updateData);
436
+ }
437
+ async deleteDocument(params) {
438
+ const { documentId } = params;
439
+ return this.http.delete(`/v0/orgs/${this.organizationId}/documents/${documentId}`);
440
+ }
441
+ // ---------------- OCR ----------------
442
+ async getOCRBlocks(params) {
443
+ const { documentId } = params;
444
+ return this.http.get(`/v0/orgs/${this.organizationId}/ocr/download/blocks/${documentId}`);
445
+ }
446
+ async getOCRText(params) {
447
+ const { documentId, pageNum } = params;
448
+ const url = `/v0/orgs/${this.organizationId}/ocr/download/text/${documentId}${pageNum ? `?page_num=${pageNum}` : ""}`;
449
+ return this.http.get(url);
450
+ }
451
+ async getOCRMetadata(params) {
452
+ const { documentId } = params;
453
+ return this.http.get(`/v0/orgs/${this.organizationId}/ocr/download/metadata/${documentId}`);
454
+ }
455
+ // ---------------- LLM ----------------
456
+ async runLLM(params) {
457
+ const { documentId, promptRevId, force } = params;
458
+ return this.http.post(
459
+ `/v0/orgs/${this.organizationId}/llm/run/${documentId}`,
460
+ {},
461
+ { params: { prompt_revid: promptRevId, force } }
462
+ );
463
+ }
464
+ async getLLMResult(params) {
465
+ const { documentId, promptRevId, fallback } = params;
466
+ return this.http.get(
467
+ `/v0/orgs/${this.organizationId}/llm/result/${documentId}`,
468
+ { params: { prompt_revid: promptRevId, fallback } }
469
+ );
470
+ }
471
+ async updateLLMResult({
472
+ documentId,
473
+ promptId,
474
+ result,
475
+ isVerified = false
476
+ }) {
477
+ const response = await this.http.put(
478
+ `/v0/orgs/${this.organizationId}/llm/result/${documentId}`,
479
+ { updated_llm_result: result, is_verified: isVerified },
480
+ { params: { prompt_revid: promptId } }
481
+ );
482
+ if (response.status !== 200) {
483
+ throw new Error(`Failed to update LLM result for document ${documentId} and prompt ${promptId}: ${response.data}`);
484
+ }
485
+ return response.data;
486
+ }
487
+ async deleteLLMResult(params) {
488
+ const { documentId, promptId } = params;
489
+ return this.http.delete(
490
+ `/v0/orgs/${this.organizationId}/llm/result/${documentId}`,
491
+ { params: { prompt_revid: promptId } }
492
+ );
493
+ }
494
+ async downloadAllLLMResults(params) {
495
+ const { documentId } = params;
496
+ return this.http.get(
497
+ `/v0/orgs/${this.organizationId}/llm/results/${documentId}/download`,
498
+ { responseType: "blob" }
499
+ );
500
+ }
501
+ // ---------------- Tags ----------------
502
+ async createTag(params) {
503
+ const { tag } = params;
504
+ return this.http.post(`/v0/orgs/${this.organizationId}/tags`, tag);
505
+ }
506
+ async getTag({ tagId }) {
507
+ return this.http.get(`/v0/orgs/${this.organizationId}/tags/${tagId}`);
508
+ }
509
+ async listTags(params) {
510
+ const { skip, limit, nameSearch } = params || {};
511
+ return this.http.get(`/v0/orgs/${this.organizationId}/tags`, {
512
+ params: { skip: skip || 0, limit: limit || 10, name_search: nameSearch }
513
+ });
514
+ }
515
+ async updateTag(params) {
516
+ const { tagId, tag } = params;
517
+ return this.http.put(`/v0/orgs/${this.organizationId}/tags/${tagId}`, tag);
518
+ }
519
+ async deleteTag(params) {
520
+ const { tagId } = params;
521
+ return this.http.delete(`/v0/orgs/${this.organizationId}/tags/${tagId}`);
522
+ }
523
+ // ---------------- Forms ----------------
524
+ async createForm(form) {
525
+ const { name, response_format } = form;
526
+ return this.http.post(`/v0/orgs/${this.organizationId}/forms`, { name, response_format });
527
+ }
528
+ async listForms(params) {
529
+ const { skip, limit, tag_ids } = params || {};
530
+ return this.http.get(`/v0/orgs/${this.organizationId}/forms`, {
531
+ params: { skip: skip || 0, limit: limit || 10, tag_ids }
532
+ });
533
+ }
534
+ async getForm(params) {
535
+ const { formRevId } = params;
536
+ return this.http.get(`/v0/orgs/${this.organizationId}/forms/${formRevId}`);
537
+ }
538
+ async updateForm(params) {
539
+ const { formId, form } = params;
540
+ return this.http.put(`/v0/orgs/${this.organizationId}/forms/${formId}`, form);
541
+ }
542
+ async deleteForm(params) {
543
+ const { formId } = params;
544
+ return this.http.delete(`/v0/orgs/${this.organizationId}/forms/${formId}`);
545
+ }
546
+ async submitForm(params) {
547
+ const { documentId, formRevId, submission_data, submitted_by } = params;
548
+ return this.http.post(`/v0/orgs/${this.organizationId}/forms/submissions/${documentId}`, {
549
+ form_revid: formRevId,
550
+ submission_data,
551
+ submitted_by
552
+ });
553
+ }
554
+ async getFormSubmission(params) {
555
+ const { documentId, formRevId } = params;
556
+ return this.http.get(`/v0/orgs/${this.organizationId}/forms/submissions/${documentId}?form_revid=${formRevId}`);
557
+ }
558
+ async deleteFormSubmission(params) {
559
+ const { documentId, formRevId } = params;
560
+ await this.http.delete(`/v0/orgs/${this.organizationId}/forms/submissions/${documentId}`, { params: { form_revid: formRevId } });
561
+ }
562
+ // ---------------- Prompts ----------------
563
+ async createPrompt(params) {
564
+ const { prompt } = params;
565
+ return this.http.post(`/v0/orgs/${this.organizationId}/prompts`, prompt);
566
+ }
567
+ async listPrompts(params) {
568
+ const { skip, limit, document_id, tag_ids, nameSearch } = params || {};
569
+ return this.http.get(`/v0/orgs/${this.organizationId}/prompts`, {
570
+ params: {
571
+ skip: skip || 0,
572
+ limit: limit || 10,
573
+ document_id,
574
+ tag_ids,
575
+ name_search: nameSearch
576
+ }
577
+ });
578
+ }
579
+ async getPrompt(params) {
580
+ const { promptRevId } = params;
581
+ return this.http.get(`/v0/orgs/${this.organizationId}/prompts/${promptRevId}`);
582
+ }
583
+ async updatePrompt(params) {
584
+ const { promptId, prompt } = params;
585
+ return this.http.put(`/v0/orgs/${this.organizationId}/prompts/${promptId}`, prompt);
586
+ }
587
+ async deletePrompt(params) {
588
+ const { promptId } = params;
589
+ return this.http.delete(`/v0/orgs/${this.organizationId}/prompts/${promptId}`);
590
+ }
591
+ // ---------------- Schemas ----------------
592
+ async createSchema(schema) {
593
+ return this.http.post(`/v0/orgs/${this.organizationId}/schemas`, schema);
594
+ }
595
+ async listSchemas(params) {
596
+ const { skip, limit, nameSearch } = params || {};
597
+ return this.http.get(`/v0/orgs/${this.organizationId}/schemas`, {
598
+ params: { skip: skip || 0, limit: limit || 10, name_search: nameSearch }
599
+ });
600
+ }
601
+ async getSchema(params) {
602
+ const { schemaRevId } = params;
603
+ return this.http.get(`/v0/orgs/${this.organizationId}/schemas/${schemaRevId}`);
604
+ }
605
+ async updateSchema(params) {
606
+ const { schemaId, schema } = params;
607
+ return this.http.put(`/v0/orgs/${this.organizationId}/schemas/${schemaId}`, schema);
608
+ }
609
+ async deleteSchema(params) {
610
+ const { schemaId } = params;
611
+ return this.http.delete(`/v0/orgs/${this.organizationId}/schemas/${schemaId}`);
612
+ }
613
+ async validateAgainstSchema(params) {
614
+ const { schemaRevId, data } = params;
615
+ return this.http.post(`/v0/orgs/${this.organizationId}/schemas/${schemaRevId}/validate`, { data });
616
+ }
617
+ // ---------------- Flows ----------------
618
+ async createFlow(params) {
619
+ const { flow } = params;
620
+ return this.http.post(`/v0/orgs/${this.organizationId}/flows`, flow);
621
+ }
622
+ async updateFlow(params) {
623
+ const { flowId, flow } = params;
624
+ return this.http.put(`/v0/orgs/${this.organizationId}/flows/${flowId}`, flow);
625
+ }
626
+ async listFlows(params) {
627
+ const { skip, limit } = params || {};
628
+ return this.http.get(`/v0/orgs/${this.organizationId}/flows`, {
629
+ params: { skip: skip || 0, limit: limit || 10 }
630
+ });
631
+ }
632
+ async getFlow(params) {
633
+ const { flowId } = params;
634
+ return this.http.get(`/v0/orgs/${this.organizationId}/flows/${flowId}`);
635
+ }
636
+ async deleteFlow(params) {
637
+ const { flowId } = params;
638
+ await this.http.delete(`/v0/orgs/${this.organizationId}/flows/${flowId}`);
639
+ }
640
+ // ---------------- Payments ----------------
641
+ async getCustomerPortal() {
642
+ return this.http.post(`/v0/orgs/${this.organizationId}/payments/customer-portal`, {});
643
+ }
644
+ async getSubscription() {
645
+ return this.http.get(`/v0/orgs/${this.organizationId}/payments/subscription`);
646
+ }
647
+ async activateSubscription() {
648
+ return this.http.put(`/v0/orgs/${this.organizationId}/payments/subscription`, {});
649
+ }
650
+ async cancelSubscription() {
651
+ return this.http.delete(`/v0/orgs/${this.organizationId}/payments/subscription`);
652
+ }
653
+ async getCurrentUsage() {
654
+ return this.http.get(`/v0/orgs/${this.organizationId}/payments/usage`);
655
+ }
656
+ async addCredits(amount) {
657
+ return this.http.post(`/v0/orgs/${this.organizationId}/payments/credits/add`, { amount });
658
+ }
659
+ async getCreditConfig() {
660
+ return this.http.get(`/v0/orgs/${this.organizationId}/payments/credits/config`);
661
+ }
662
+ async purchaseCredits(request) {
663
+ return this.http.post(`/v0/orgs/${this.organizationId}/payments/credits/purchase`, request);
664
+ }
665
+ async getUsageRange(request) {
666
+ return this.http.get(`/v0/orgs/${this.organizationId}/payments/usage/range`, { params: request });
667
+ }
668
+ async createCheckoutSession(planId) {
669
+ return this.http.post(`/v0/orgs/${this.organizationId}/payments/checkout-session`, { plan_id: planId });
670
+ }
671
+ // ---------------- LLM Chat (Org) ----------------
672
+ async runLLMChat(request) {
673
+ return this.http.post(`/v0/orgs/${this.organizationId}/llm/run`, request);
674
+ }
675
+ async runLLMChatStream(request, onChunk, onError, abortSignal) {
676
+ const streamingRequest = { ...request, stream: true };
677
+ return this.http.stream(`/v0/orgs/${this.organizationId}/llm/run`, streamingRequest, onChunk, onError, abortSignal);
678
+ }
679
+ /**
680
+ * Get the current HTTP client (for advanced usage)
681
+ */
682
+ getHttpClient() {
683
+ return this.http;
684
+ }
685
+ };
686
+
687
+ export { DocRouterAccount, DocRouterOrg, HttpClient };
688
+ //# sourceMappingURL=index.mjs.map
689
+ //# sourceMappingURL=index.mjs.map