@babav/knowledge-core-client 0.5.0 → 0.6.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.d.ts CHANGED
@@ -124,6 +124,14 @@ export interface DocumentCount {
124
124
  in_flight: number;
125
125
  failed: number;
126
126
  }
127
+ /** A signed PUT URL for uploading a large file straight to GCS + the pre-allocated
128
+ * document id to reference on from-upload. */
129
+ export interface UploadUrl {
130
+ upload_url: string;
131
+ document_id: UUID;
132
+ gcs_uri: string;
133
+ expires_in: number;
134
+ }
127
135
  export interface Conversation {
128
136
  id: UUID;
129
137
  title: string | null;
@@ -304,6 +312,32 @@ export declare class KnowledgeCoreClient extends HttpBase {
304
312
  folder_id?: UUID;
305
313
  custom_metadata?: Record<string, unknown>;
306
314
  }) => Promise<Document>;
315
+ /** Mint a signed PUT URL to upload a large file straight to GCS (bypasses the
316
+ * ~32 MB request limit). PUT the bytes to upload_url, then ingestFromUpload. */
317
+ uploadUrl: (id: UUID, a: {
318
+ filename: string;
319
+ content_type?: string;
320
+ }) => Promise<UploadUrl>;
321
+ /** Ingest a file already PUT to GCS via uploadUrl. Resolves with the `pending`
322
+ * document (202); track via documents.get() / webhook. */
323
+ ingestFromUpload: (id: UUID, a: {
324
+ document_id: UUID;
325
+ filename: string;
326
+ content_type?: string;
327
+ visibility?: Visibility;
328
+ folder_id?: UUID;
329
+ custom_metadata?: Record<string, unknown>;
330
+ }) => Promise<Document>;
331
+ /** Convenience for LARGE files: uploadUrl → PUT the bytes to GCS → ingestFromUpload.
332
+ * Use this instead of ingestDocument when the file may exceed ~32 MB. */
333
+ uploadDocument: (id: UUID, a: {
334
+ file: FileData;
335
+ filename: string;
336
+ content_type?: string;
337
+ visibility?: Visibility;
338
+ folder_id?: UUID;
339
+ custom_metadata?: Record<string, unknown>;
340
+ }) => Promise<Document>;
307
341
  };
308
342
  parse(a: {
309
343
  file: FileData;
package/dist/index.js CHANGED
@@ -217,6 +217,29 @@ export class KnowledgeCoreClient extends HttpBase {
217
217
  fd.append("folder_id", a.folder_id);
218
218
  return this.request("POST", `/v1/corpora/${id}/documents`, { body: fd });
219
219
  },
220
+ /** Mint a signed PUT URL to upload a large file straight to GCS (bypasses the
221
+ * ~32 MB request limit). PUT the bytes to upload_url, then ingestFromUpload. */
222
+ uploadUrl: (id, a) => this.request("POST", `/v1/corpora/${id}/documents/upload-url`, { json: a }),
223
+ /** Ingest a file already PUT to GCS via uploadUrl. Resolves with the `pending`
224
+ * document (202); track via documents.get() / webhook. */
225
+ ingestFromUpload: (id, a) => this.request("POST", `/v1/corpora/${id}/documents/from-upload`, { json: a }),
226
+ /** Convenience for LARGE files: uploadUrl → PUT the bytes to GCS → ingestFromUpload.
227
+ * Use this instead of ingestDocument when the file may exceed ~32 MB. */
228
+ uploadDocument: async (id, a) => {
229
+ const u = await this.corpora.uploadUrl(id, { filename: a.filename, content_type: a.content_type });
230
+ const put = await this._fetch(u.upload_url, {
231
+ method: "PUT",
232
+ body: toBlob(a.file, a.content_type),
233
+ headers: a.content_type ? { "content-type": a.content_type } : {},
234
+ });
235
+ if (!put.ok) {
236
+ throw new KnowledgeCoreError(put.status, safeJson(await put.text()), u.upload_url);
237
+ }
238
+ return this.corpora.ingestFromUpload(id, {
239
+ document_id: u.document_id, filename: a.filename, content_type: a.content_type,
240
+ visibility: a.visibility, folder_id: a.folder_id, custom_metadata: a.custom_metadata,
241
+ });
242
+ },
220
243
  };
221
244
  // --- parsing (utility: file -> text, stores nothing) ---
222
245
  parse(a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -138,6 +138,14 @@ export interface DocumentCount {
138
138
  in_flight: number;
139
139
  failed: number;
140
140
  }
141
+ /** A signed PUT URL for uploading a large file straight to GCS + the pre-allocated
142
+ * document id to reference on from-upload. */
143
+ export interface UploadUrl {
144
+ upload_url: string;
145
+ document_id: UUID;
146
+ gcs_uri: string;
147
+ expires_in: number;
148
+ }
141
149
  export interface Conversation {
142
150
  id: UUID;
143
151
  title: string | null;
@@ -443,6 +451,31 @@ export class KnowledgeCoreClient extends HttpBase {
443
451
  if (a.folder_id) fd.append("folder_id", a.folder_id);
444
452
  return this.request<Document>("POST", `/v1/corpora/${id}/documents`, { body: fd });
445
453
  },
454
+ /** Mint a signed PUT URL to upload a large file straight to GCS (bypasses the
455
+ * ~32 MB request limit). PUT the bytes to upload_url, then ingestFromUpload. */
456
+ uploadUrl: (id: UUID, a: { filename: string; content_type?: string }) =>
457
+ this.request<UploadUrl>("POST", `/v1/corpora/${id}/documents/upload-url`, { json: a }),
458
+ /** Ingest a file already PUT to GCS via uploadUrl. Resolves with the `pending`
459
+ * document (202); track via documents.get() / webhook. */
460
+ ingestFromUpload: (id: UUID, a: { document_id: UUID; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }) =>
461
+ this.request<Document>("POST", `/v1/corpora/${id}/documents/from-upload`, { json: a }),
462
+ /** Convenience for LARGE files: uploadUrl → PUT the bytes to GCS → ingestFromUpload.
463
+ * Use this instead of ingestDocument when the file may exceed ~32 MB. */
464
+ uploadDocument: async (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }): Promise<Document> => {
465
+ const u = await this.corpora.uploadUrl(id, { filename: a.filename, content_type: a.content_type });
466
+ const put = await this._fetch(u.upload_url, {
467
+ method: "PUT",
468
+ body: toBlob(a.file, a.content_type),
469
+ headers: a.content_type ? { "content-type": a.content_type } : {},
470
+ });
471
+ if (!put.ok) {
472
+ throw new KnowledgeCoreError(put.status, safeJson(await put.text()), u.upload_url);
473
+ }
474
+ return this.corpora.ingestFromUpload(id, {
475
+ document_id: u.document_id, filename: a.filename, content_type: a.content_type,
476
+ visibility: a.visibility, folder_id: a.folder_id, custom_metadata: a.custom_metadata,
477
+ });
478
+ },
446
479
  };
447
480
 
448
481
  // --- parsing (utility: file -> text, stores nothing) ---