@babav/knowledge-core-client 0.7.0 → 0.9.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
@@ -169,6 +169,8 @@ export interface Feedback {
169
169
  export interface Agent {
170
170
  id: UUID;
171
171
  name: string;
172
+ identity_prompt: string | null;
173
+ response_prompt: string | null;
172
174
  generation_model: string | null;
173
175
  top_k: number | null;
174
176
  rerank_instruction: string | null;
@@ -294,9 +296,11 @@ export declare class KnowledgeCoreClient extends HttpBase {
294
296
  limit?: number;
295
297
  cursor?: string;
296
298
  }) => Promise<Page<Document>>;
297
- /** Upload a file and ingest it ASYNCHRONOUSLY — resolves with the created
298
- * document at status `pending` (HTTP 202); track via documents.get() polling
299
- * the status to `indexed`/`failed`, or the tenant result webhook. */
299
+ /** Ingest a document ASYNCHRONOUSLY — resolves with the created document at
300
+ * status `pending` (HTTP 202); track via documents.get() polling to
301
+ * `indexed`/`failed`, or the tenant result webhook. Auto-routes by size: files
302
+ * over ~30 MB go via the signed-URL upload path (Cloud Run caps requests at
303
+ * ~32 MB), smaller files via one multipart request. One method, any size. */
300
304
  ingestDocument: (id: UUID, a: {
301
305
  file: FileData;
302
306
  filename: string;
@@ -459,6 +463,8 @@ export declare class AdminClient extends HttpBase {
459
463
  agents: {
460
464
  create: (b: {
461
465
  name: string;
466
+ identity_prompt?: string;
467
+ response_prompt?: string;
462
468
  generation_model?: string;
463
469
  top_k?: number;
464
470
  rerank_instruction?: 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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.7.0",
3
+ "version": "0.9.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
@@ -183,6 +183,8 @@ export interface Feedback {
183
183
  export interface Agent {
184
184
  id: UUID;
185
185
  name: string;
186
+ identity_prompt: string | null; // answer-system: who/purpose (null => server default)
187
+ response_prompt: string | null; // answer-system: output guidelines (null => server default)
186
188
  generation_model: string | null;
187
189
  top_k: number | null;
188
190
  rerank_instruction: string | null;
@@ -363,6 +365,16 @@ function toBlob(data: FileData, contentType?: string): Blob {
363
365
  return new Blob([data as BlobPart], { type: contentType ?? "application/octet-stream" });
364
366
  }
365
367
 
368
+ function fileSize(data: FileData): number {
369
+ if (data instanceof Blob) return data.size;
370
+ if (data instanceof ArrayBuffer) return data.byteLength;
371
+ return (data as Uint8Array).byteLength;
372
+ }
373
+
374
+ // Cloud Run caps request bodies at ~32 MB; over this, ingestDocument auto-routes to
375
+ // the signed-URL upload path instead of a single multipart request.
376
+ const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
377
+
366
378
  // ---------------------------------------------------------------------------
367
379
  // SSE handlers
368
380
  // ---------------------------------------------------------------------------
@@ -438,10 +450,13 @@ export class KnowledgeCoreClient extends HttpBase {
438
450
  /** Documents in the corpus whose filename contains `q` (case-insensitive), paginated. */
439
451
  searchDocuments: (id: UUID, q: string, opts?: { limit?: number; cursor?: string }) =>
440
452
  this.request<Page<Document>>("GET", `/v1/corpora/${id}/documents/search`, { query: { q, ...opts } }),
441
- /** Upload a file and ingest it ASYNCHRONOUSLY — resolves with the created
442
- * document at status `pending` (HTTP 202); track via documents.get() polling
443
- * the status to `indexed`/`failed`, or the tenant result webhook. */
453
+ /** Ingest a document ASYNCHRONOUSLY — resolves with the created document at
454
+ * status `pending` (HTTP 202); track via documents.get() polling to
455
+ * `indexed`/`failed`, or the tenant result webhook. Auto-routes by size: files
456
+ * over ~30 MB go via the signed-URL upload path (Cloud Run caps requests at
457
+ * ~32 MB), smaller files via one multipart request. One method, any size. */
444
458
  ingestDocument: (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }) => {
459
+ if (fileSize(a.file) > MULTIPART_MAX_BYTES) return this.corpora.uploadDocument(id, a);
445
460
  const fd = new FormData();
446
461
  fd.append("file", toBlob(a.file, a.content_type), a.filename);
447
462
  if (a.custom_metadata) fd.append("custom_metadata", JSON.stringify(a.custom_metadata));
@@ -588,7 +603,7 @@ export class AdminClient extends HttpBase {
588
603
 
589
604
  // Agents are query agents, global for now.
590
605
  agents = {
591
- create: (b: { name: string; generation_model?: string; top_k?: number; rerank_instruction?: string; max_hops?: number; groundedness_threshold?: number; grounding_enabled?: boolean }) =>
606
+ create: (b: { name: string; identity_prompt?: string; response_prompt?: string; generation_model?: string; top_k?: number; rerank_instruction?: string; max_hops?: number; groundedness_threshold?: number; grounding_enabled?: boolean }) =>
592
607
  this.request<Agent>("POST", "/v1/agents", { json: b }),
593
608
  update: (id: UUID, b: Partial<Omit<Agent, "id">>) =>
594
609
  this.request<Agent>("PATCH", `/v1/agents/${id}`, { json: b }),