@babav/knowledge-core-client 0.6.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 CHANGED
@@ -73,7 +73,6 @@ export interface QueryResponse {
73
73
  groundedness: Groundedness | null;
74
74
  usage: Record<string, number | null>;
75
75
  standalone_query: string | null;
76
- hops: string[];
77
76
  }
78
77
  export interface Citation {
79
78
  quote: string;
@@ -241,12 +240,6 @@ declare class HttpBase {
241
240
  protected pageAll<T>(path: string, query?: RequestOpts["query"]): Promise<T[]>;
242
241
  }
243
242
  export interface StreamHandlers {
244
- onHop?: (d: {
245
- n: number;
246
- subquery: string;
247
- status: string;
248
- retrieval_contents?: number;
249
- }) => void;
250
243
  onSources?: (d: {
251
244
  retrieval_contents: RetrievalContent[];
252
245
  }) => void;
@@ -301,9 +294,11 @@ export declare class KnowledgeCoreClient extends HttpBase {
301
294
  limit?: number;
302
295
  cursor?: string;
303
296
  }) => Promise<Page<Document>>;
304
- /** Upload a file and ingest it ASYNCHRONOUSLY — resolves with the created
305
- * document at status `pending` (HTTP 202); track via documents.get() polling
306
- * the status to `indexed`/`failed`, or the tenant result webhook. */
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. */
307
302
  ingestDocument: (id: UUID, a: {
308
303
  file: FileData;
309
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
- /** Upload a file and ingest it ASYNCHRONOUSLY — resolves with the created
207
- * document at status `pending` (HTTP 202); track via documents.get() polling
208
- * the status to `indexed`/`failed`, or the tenant result webhook. */
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)
@@ -354,9 +368,6 @@ function dispatchSse(frame, h) {
354
368
  const data = safeJson(dataLines.join("\n"));
355
369
  h.onEvent?.(event, data);
356
370
  switch (event) {
357
- case "hop":
358
- h.onHop?.(data);
359
- break;
360
371
  case "retrieval_contents":
361
372
  h.onSources?.(data);
362
373
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.6.0",
3
+ "version": "0.8.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
@@ -85,7 +85,6 @@ export interface QueryResponse {
85
85
  groundedness: Groundedness | null;
86
86
  usage: Record<string, number | null>;
87
87
  standalone_query: string | null;
88
- hops: string[];
89
88
  }
90
89
 
91
90
  export interface Citation {
@@ -364,11 +363,20 @@ function toBlob(data: FileData, contentType?: string): Blob {
364
363
  return new Blob([data as BlobPart], { type: contentType ?? "application/octet-stream" });
365
364
  }
366
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
+
367
376
  // ---------------------------------------------------------------------------
368
377
  // SSE handlers
369
378
  // ---------------------------------------------------------------------------
370
379
  export interface StreamHandlers {
371
- onHop?: (d: { n: number; subquery: string; status: string; retrieval_contents?: number }) => void;
372
380
  onSources?: (d: { retrieval_contents: RetrievalContent[] }) => void;
373
381
  onToken?: (text: string) => void;
374
382
  onFinal?: (d: QueryResponse) => void;
@@ -440,10 +448,13 @@ export class KnowledgeCoreClient extends HttpBase {
440
448
  /** Documents in the corpus whose filename contains `q` (case-insensitive), paginated. */
441
449
  searchDocuments: (id: UUID, q: string, opts?: { limit?: number; cursor?: string }) =>
442
450
  this.request<Page<Document>>("GET", `/v1/corpora/${id}/documents/search`, { query: { q, ...opts } }),
443
- /** Upload a file and ingest it ASYNCHRONOUSLY — resolves with the created
444
- * document at status `pending` (HTTP 202); track via documents.get() polling
445
- * the status to `indexed`/`failed`, or the tenant result webhook. */
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. */
446
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);
447
458
  const fd = new FormData();
448
459
  fd.append("file", toBlob(a.file, a.content_type), a.filename);
449
460
  if (a.custom_metadata) fd.append("custom_metadata", JSON.stringify(a.custom_metadata));
@@ -612,7 +623,6 @@ function dispatchSse(frame: string, h: StreamHandlers): void {
612
623
  const data = safeJson(dataLines.join("\n"));
613
624
  h.onEvent?.(event, data);
614
625
  switch (event) {
615
- case "hop": h.onHop?.(data as never); break;
616
626
  case "retrieval_contents": h.onSources?.(data as never); break;
617
627
  case "token": h.onToken?.((data as { text: string }).text); break;
618
628
  case "final": h.onFinal?.(data as QueryResponse); break;