@babav/knowledge-core-client 0.7.0 → 0.8.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 +5 -3
- package/dist/index.js +17 -3
- package/package.json +1 -1
- package/src/index.ts +16 -3
package/dist/index.d.ts
CHANGED
|
@@ -294,9 +294,11 @@ export declare class KnowledgeCoreClient extends HttpBase {
|
|
|
294
294
|
limit?: number;
|
|
295
295
|
cursor?: string;
|
|
296
296
|
}) => Promise<Page<Document>>;
|
|
297
|
-
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
297
|
+
/** Ingest a document ASYNCHRONOUSLY — resolves with the created document at
|
|
298
|
+
* status `pending` (HTTP 202); track via documents.get() polling to
|
|
299
|
+
* `indexed`/`failed`, or the tenant result webhook. Auto-routes by size: files
|
|
300
|
+
* over ~30 MB go via the signed-URL upload path (Cloud Run caps requests at
|
|
301
|
+
* ~32 MB), smaller files via one multipart request. One method, any size. */
|
|
300
302
|
ingestDocument: (id: UUID, a: {
|
|
301
303
|
file: FileData;
|
|
302
304
|
filename: string;
|
package/dist/index.js
CHANGED
|
@@ -148,6 +148,16 @@ function toBlob(data, contentType) {
|
|
|
148
148
|
return data;
|
|
149
149
|
return new Blob([data], { type: contentType ?? "application/octet-stream" });
|
|
150
150
|
}
|
|
151
|
+
function fileSize(data) {
|
|
152
|
+
if (data instanceof Blob)
|
|
153
|
+
return data.size;
|
|
154
|
+
if (data instanceof ArrayBuffer)
|
|
155
|
+
return data.byteLength;
|
|
156
|
+
return data.byteLength;
|
|
157
|
+
}
|
|
158
|
+
// Cloud Run caps request bodies at ~32 MB; over this, ingestDocument auto-routes to
|
|
159
|
+
// the signed-URL upload path instead of a single multipart request.
|
|
160
|
+
const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
|
|
151
161
|
// ---------------------------------------------------------------------------
|
|
152
162
|
// Tenant client (data ops) — use a TENANT key
|
|
153
163
|
// ---------------------------------------------------------------------------
|
|
@@ -203,10 +213,14 @@ export class KnowledgeCoreClient extends HttpBase {
|
|
|
203
213
|
countDocuments: (id) => this.request("GET", `/v1/corpora/${id}/documents/count`),
|
|
204
214
|
/** Documents in the corpus whose filename contains `q` (case-insensitive), paginated. */
|
|
205
215
|
searchDocuments: (id, q, opts) => this.request("GET", `/v1/corpora/${id}/documents/search`, { query: { q, ...opts } }),
|
|
206
|
-
/**
|
|
207
|
-
*
|
|
208
|
-
*
|
|
216
|
+
/** Ingest a document ASYNCHRONOUSLY — resolves with the created document at
|
|
217
|
+
* status `pending` (HTTP 202); track via documents.get() polling to
|
|
218
|
+
* `indexed`/`failed`, or the tenant result webhook. Auto-routes by size: files
|
|
219
|
+
* over ~30 MB go via the signed-URL upload path (Cloud Run caps requests at
|
|
220
|
+
* ~32 MB), smaller files via one multipart request. One method, any size. */
|
|
209
221
|
ingestDocument: (id, a) => {
|
|
222
|
+
if (fileSize(a.file) > MULTIPART_MAX_BYTES)
|
|
223
|
+
return this.corpora.uploadDocument(id, a);
|
|
210
224
|
const fd = new FormData();
|
|
211
225
|
fd.append("file", toBlob(a.file, a.content_type), a.filename);
|
|
212
226
|
if (a.custom_metadata)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -363,6 +363,16 @@ function toBlob(data: FileData, contentType?: string): Blob {
|
|
|
363
363
|
return new Blob([data as BlobPart], { type: contentType ?? "application/octet-stream" });
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
function fileSize(data: FileData): number {
|
|
367
|
+
if (data instanceof Blob) return data.size;
|
|
368
|
+
if (data instanceof ArrayBuffer) return data.byteLength;
|
|
369
|
+
return (data as Uint8Array).byteLength;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Cloud Run caps request bodies at ~32 MB; over this, ingestDocument auto-routes to
|
|
373
|
+
// the signed-URL upload path instead of a single multipart request.
|
|
374
|
+
const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
|
|
375
|
+
|
|
366
376
|
// ---------------------------------------------------------------------------
|
|
367
377
|
// SSE handlers
|
|
368
378
|
// ---------------------------------------------------------------------------
|
|
@@ -438,10 +448,13 @@ export class KnowledgeCoreClient extends HttpBase {
|
|
|
438
448
|
/** Documents in the corpus whose filename contains `q` (case-insensitive), paginated. */
|
|
439
449
|
searchDocuments: (id: UUID, q: string, opts?: { limit?: number; cursor?: string }) =>
|
|
440
450
|
this.request<Page<Document>>("GET", `/v1/corpora/${id}/documents/search`, { query: { q, ...opts } }),
|
|
441
|
-
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
451
|
+
/** Ingest a document ASYNCHRONOUSLY — resolves with the created document at
|
|
452
|
+
* status `pending` (HTTP 202); track via documents.get() polling to
|
|
453
|
+
* `indexed`/`failed`, or the tenant result webhook. Auto-routes by size: files
|
|
454
|
+
* over ~30 MB go via the signed-URL upload path (Cloud Run caps requests at
|
|
455
|
+
* ~32 MB), smaller files via one multipart request. One method, any size. */
|
|
444
456
|
ingestDocument: (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }) => {
|
|
457
|
+
if (fileSize(a.file) > MULTIPART_MAX_BYTES) return this.corpora.uploadDocument(id, a);
|
|
445
458
|
const fd = new FormData();
|
|
446
459
|
fd.append("file", toBlob(a.file, a.content_type), a.filename);
|
|
447
460
|
if (a.custom_metadata) fd.append("custom_metadata", JSON.stringify(a.custom_metadata));
|