@babav/knowledge-core-client 0.43.0 → 0.45.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/README.md CHANGED
@@ -39,15 +39,15 @@ const kc = new KnowledgeCoreClient({
39
39
  });
40
40
 
41
41
  // One-shot grounded query
42
- const r = await kc.query(agentId, { corpus_ids: [corpusId], query: "..." });
42
+ const r = await kc.query(profileId, { corpus_ids: [corpusId], query: "..." });
43
43
  console.log(r.answer, r.retrieval_contents, r.citations, r.groundedness);
44
44
 
45
45
  // Conversational (persisted, history-aware)
46
46
  const convo = await kc.conversations.create({ title: "Contract review", custom_metadata: { account_id } });
47
- const turn = await kc.query(agentId, { corpus_ids: [corpusId], query: "...", conversation_id: convo.id });
47
+ const turn = await kc.query(profileId, { corpus_ids: [corpusId], query: "...", conversation_id: convo.id });
48
48
 
49
49
  // Streaming (SSE)
50
- await kc.queryStream(agentId, { corpus_ids: [corpusId], query: "..." }, {
50
+ await kc.queryStream(profileId, { corpus_ids: [corpusId], query: "..." }, {
51
51
  onSources: (s) => render(s.retrieval_contents),
52
52
  onToken: (t) => append(t),
53
53
  onFinal: (f) => done(f),
@@ -57,7 +57,7 @@ await kc.queryStream(agentId, { corpus_ids: [corpusId], query: "..." }, {
57
57
  // Attachment-backed review
58
58
  const att = await kc.attachments.upload(convo.id, { filename: "c.pdf", content_type: "application/pdf", data: bytes });
59
59
  await kc.attachments.waitReady(convo.id, att.id);
60
- const review = await kc.query(agentId, { corpus_ids: [corpusId], conversation_id: convo.id, query: "Review the attached contract." });
60
+ const review = await kc.query(profileId, { corpus_ids: [corpusId], conversation_id: convo.id, query: "Review the attached contract." });
61
61
 
62
62
  // View/download a stored doc (signed URL)
63
63
  const { content_url, content_type } = await kc.documents.contentUrl(documentId, "inline");
@@ -65,7 +65,7 @@ const { content_url, content_type } = await kc.documents.contentUrl(documentId,
65
65
 
66
66
  ### Error handling (structured guards)
67
67
  ```ts
68
- try { await kc.query(agentId, body); }
68
+ try { await kc.query(profileId, body); }
69
69
  catch (e) {
70
70
  if (e instanceof KnowledgeCoreError) {
71
71
  if (e.code === "attachments_pending") { /* a document is still parsing */ }
@@ -75,7 +75,7 @@ catch (e) {
75
75
  }
76
76
  ```
77
77
 
78
- ## Admin client (tenant + key + agent management — ADMIN key)
78
+ ## Admin client (tenant + key + profile management — ADMIN key)
79
79
  ```ts
80
80
  import { AdminClient } from "@babav/knowledge-core-client";
81
81
  const admin = new AdminClient({ baseUrl, apiKey: ADMIN_KEY });
@@ -90,5 +90,5 @@ const created = await admin.tenants.createApiKey(tenantId, "label"); // created.
90
90
  - `conversations` (CRUD, search, listMessages)
91
91
  - `attachments` (upload, list, get, contentUrl, delete, waitReady)
92
92
  - `messages` (get, createFeedback, listFeedback), `feedback` (get, delete)
93
- - `parseJobs` (list, get), `agents` (list, get)
94
- - `AdminClient`: `tenants` (CRUD + api-keys), `agents` (create/update/delete)
93
+ - `parseJobs` (list, get), `profiles` (list, get)
94
+ - `AdminClient`: `tenants` (CRUD + api-keys), `profiles` (create/update/delete)
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * Auth: every call carries an X-API-Key. Use KnowledgeCoreClient with a TENANT
12
12
  * key for all data ops; use AdminClient with the ADMIN key for tenant / API-key /
13
- * agent management. The key is server-side only — never ship it to a browser.
13
+ * profile management. The key is server-side only — never ship it to a browser.
14
14
  *
15
15
  * Configuration — the CALLER supplies credentials at construction; the SDK never reads
16
16
  * the environment or defaults/derives a key itself:
@@ -44,6 +44,7 @@ export interface RetrievalContent {
44
44
  parent_id: string;
45
45
  document_id: string;
46
46
  corpus_id: string;
47
+ chunk_id?: string | null;
47
48
  source_type: "corpus" | "conversation_attachment";
48
49
  visibility: Visibility | string;
49
50
  metadata: Record<string, unknown>;
@@ -77,7 +78,7 @@ export interface VisualOverrides {
77
78
  claims_check_model?: string;
78
79
  vision_judge_model?: string;
79
80
  }
80
- /** Per-request visual control. Absent => mode resolves from the agent default. All visual
81
+ /** Per-request visual control. Absent => mode resolves from the profile default. All visual
81
82
  * PROCESSING is server-side; the client only displays the result. */
82
83
  export interface VisualRequest {
83
84
  mode?: "off" | "on";
@@ -539,13 +540,13 @@ export interface QueryProfile {
539
540
  visual_combine_generation_and_concept: boolean | null;
540
541
  concept_model_mode: string | null;
541
542
  }
542
- /** Fields settable when creating/updating an agent. All optional except `name` on create
543
+ /** Fields settable when creating/updating a query profile. All optional except `name` on create
543
544
  * (null/omit => server default); model fields must be one of
544
- * `agents.modelOptions().fields[field].supported`. The owning tenant is the caller's key —
545
+ * `profiles.modelOptions().fields[field].supported`. The owning tenant is the caller's key —
545
546
  * it is never part of the body. */
546
547
  export type QueryProfileWrite = Partial<Omit<QueryProfile, "id" | "tenant_id">>;
547
548
  /** Model catalog for the query-profile-config UI (GET /v1/query-profiles/model-options). `models` maps id → its
548
- * capabilities; `fields` gives each agent model-field its supported ids + default (+ usage metadata);
549
+ * capabilities; `fields` gives each profile model-field its supported ids + default (+ usage metadata);
549
550
  * `modes` says which model field governs each mode (reasoning is valid only if that model's
550
551
  * supports_reasoning is true). KC provides the data; the UI decides presentation. */
551
552
  export interface ModelOptions {
@@ -778,6 +779,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
778
779
  visibility?: Visibility;
779
780
  folder_id?: UUID;
780
781
  custom_metadata?: Record<string, unknown>;
782
+ profile_id?: UUID;
781
783
  }) => Promise<Document>;
782
784
  /** Mint a signed PUT URL to upload a large file straight to GCS (bypasses the
783
785
  * ~32 MB request limit). PUT the bytes to upload_url, then ingestFromUpload. */
@@ -794,6 +796,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
794
796
  visibility?: Visibility;
795
797
  folder_id?: UUID;
796
798
  custom_metadata?: Record<string, unknown>;
799
+ profile_id?: UUID;
797
800
  }) => Promise<Document>;
798
801
  /** Convenience for LARGE files: uploadUrl → PUT the bytes to GCS → ingestFromUpload.
799
802
  * Use this instead of ingestDocument when the file may exceed ~32 MB. */
@@ -804,6 +807,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
804
807
  visibility?: Visibility;
805
808
  folder_id?: UUID;
806
809
  custom_metadata?: Record<string, unknown>;
810
+ profile_id?: UUID;
807
811
  }) => Promise<Document>;
808
812
  /** Ingest MANY files in ONE go — any size, no 429, no client backoff. Mints all signed URLs in
809
813
  * one request, PUTs the bytes straight to GCS (bounded concurrency; never touches the KC), then
@@ -819,6 +823,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
819
823
  visibility?: Visibility;
820
824
  custom_metadata?: Record<string, unknown>;
821
825
  concurrency?: number;
826
+ profile_id?: UUID;
822
827
  }) => Promise<Document[]>;
823
828
  /** (server-side) Mint one RESUMABLE GCS upload session per file. Return only the sessions to the
824
829
  * browser; the browser PUTs bytes to each `upload_url` and needs NO KC/tenant credential (the
@@ -845,6 +850,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
845
850
  folder_id?: UUID;
846
851
  visibility?: Visibility;
847
852
  custom_metadata?: Record<string, unknown>;
853
+ profile_id?: UUID;
848
854
  }) => Promise<{
849
855
  results: FinalizeResult[];
850
856
  }>;
@@ -1003,7 +1009,7 @@ export declare class KnowledgeCoreClient extends HttpBase {
1003
1009
  modelOptions: () => Promise<ModelOptions>;
1004
1010
  };
1005
1011
  /** Ingestion profiles — the build-side config object (counterpart to query profiles): a tenant-owned,
1006
- * named bundle of pipeline config (chunking + embedding + sparse + quant). Unlike an agent
1012
+ * named bundle of pipeline config (chunking + embedding + sparse + quant). Unlike a query profile
1007
1013
  * (chosen per query), a profile binds at the TENANT/COLLECTION level — the tenant's one
1008
1014
  * `is_default` profile governs how ALL its documents are ingested; swapping it re-indexes.
1009
1015
  * A corpus's content is a RESULT of ingestion, so a corpus never selects a profile. */
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * Auth: every call carries an X-API-Key. Use KnowledgeCoreClient with a TENANT
12
12
  * key for all data ops; use AdminClient with the ADMIN key for tenant / API-key /
13
- * agent management. The key is server-side only — never ship it to a browser.
13
+ * profile management. The key is server-side only — never ship it to a browser.
14
14
  *
15
15
  * Configuration — the CALLER supplies credentials at construction; the SDK never reads
16
16
  * the environment or defaults/derives a key itself:
@@ -303,6 +303,7 @@ export class KnowledgeCoreClient extends HttpBase {
303
303
  return this.corpora.ingestFromUpload(id, {
304
304
  document_id: u.document_id, filename: a.filename, content_type: a.content_type,
305
305
  visibility: a.visibility, folder_id: a.folder_id, custom_metadata: a.custom_metadata,
306
+ profile_id: a.profile_id,
306
307
  });
307
308
  },
308
309
  /** Ingest MANY files in ONE go — any size, no 429, no client backoff. Mints all signed URLs in
@@ -328,6 +329,7 @@ export class KnowledgeCoreClient extends HttpBase {
328
329
  });
329
330
  const res = await this.request("POST", `/v1/corpora/${id}/documents/batch`, { json: {
330
331
  folder_id: opts?.folder_id, visibility: opts?.visibility, custom_metadata: opts?.custom_metadata,
332
+ profile_id: opts?.profile_id,
331
333
  items: items.map((it) => ({ document_id: it.document_id, filename: it.filename })),
332
334
  } });
333
335
  return res.documents;
@@ -353,7 +355,7 @@ export class KnowledgeCoreClient extends HttpBase {
353
355
  * items. `document_id` is stable from createUploadSessions, so documents.events (SSE) tracks it. */
354
356
  finalizeUploads: (id, items, opts) => this.request("POST", `/v1/corpora/${id}/documents/finalize`, { json: {
355
357
  items, folder_id: opts?.folder_id, visibility: opts?.visibility,
356
- custom_metadata: opts?.custom_metadata,
358
+ custom_metadata: opts?.custom_metadata, profile_id: opts?.profile_id,
357
359
  } }),
358
360
  /** (server-side) Cancel upload sessions the browser gave up on (idempotent cleanup). Pass the
359
361
  * `upload_url` from createUploadSessions so the resumable session is dropped; any pending row is
@@ -468,7 +470,7 @@ export class KnowledgeCoreClient extends HttpBase {
468
470
  modelOptions: () => this.request("GET", "/v1/query-profiles/model-options"),
469
471
  };
470
472
  /** Ingestion profiles — the build-side config object (counterpart to query profiles): a tenant-owned,
471
- * named bundle of pipeline config (chunking + embedding + sparse + quant). Unlike an agent
473
+ * named bundle of pipeline config (chunking + embedding + sparse + quant). Unlike a query profile
472
474
  * (chosen per query), a profile binds at the TENANT/COLLECTION level — the tenant's one
473
475
  * `is_default` profile governs how ALL its documents are ingested; swapping it re-indexes.
474
476
  * A corpus's content is a RESULT of ingestion, so a corpus never selects a profile. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps). Includes the babav.visual grammar TYPES at the ./visual subpath (types only; all visual rendering is server-side).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * Auth: every call carries an X-API-Key. Use KnowledgeCoreClient with a TENANT
12
12
  * key for all data ops; use AdminClient with the ADMIN key for tenant / API-key /
13
- * agent management. The key is server-side only — never ship it to a browser.
13
+ * profile management. The key is server-side only — never ship it to a browser.
14
14
  *
15
15
  * Configuration — the CALLER supplies credentials at construction; the SDK never reads
16
16
  * the environment or defaults/derives a key itself:
@@ -64,6 +64,7 @@ export interface RetrievalContent {
64
64
  parent_id: string;
65
65
  document_id: string;
66
66
  corpus_id: string;
67
+ chunk_id?: string | null; // Qdrant point id of the best-matching child chunk ("{document_id}::{seq}")
67
68
  source_type: "corpus" | "conversation_attachment";
68
69
  visibility: Visibility | string;
69
70
  metadata: Record<string, unknown>;
@@ -100,7 +101,7 @@ export interface VisualOverrides {
100
101
  vision_judge_model?: string;
101
102
  }
102
103
 
103
- /** Per-request visual control. Absent => mode resolves from the agent default. All visual
104
+ /** Per-request visual control. Absent => mode resolves from the profile default. All visual
104
105
  * PROCESSING is server-side; the client only displays the result. */
105
106
  export interface VisualRequest {
106
107
  mode?: "off" | "on";
@@ -474,12 +475,12 @@ export interface Feedback {
474
475
  }
475
476
  export interface QueryProfile {
476
477
  id: UUID;
477
- tenant_id: UUID; // the owning tenant (every agent belongs to exactly one; no globals)
478
+ tenant_id: UUID; // the owning tenant (every profile belongs to exactly one; no globals)
478
479
  name: string;
479
480
  identity_prompt: string | null; // answer-system: who/purpose (null => server default)
480
481
  response_prompt: string | null; // answer-system: output guidelines (null => server default)
481
482
  generation_model: string | null;
482
- generation_model_mode: string | null; // "reasoning" (adaptive thinking) | "standard"; per-agent
483
+ generation_model_mode: string | null; // "reasoning" (adaptive thinking) | "standard"; per-profile
483
484
  max_response_tokens: number | null;
484
485
  top_k_retrieved_chunks: number | null;
485
486
  top_k_reranked_chunks: number | null;
@@ -507,14 +508,14 @@ export interface QueryProfile {
507
508
  concept_model_mode: string | null; // "reasoning" | "standard"; overrules gen mode when combining
508
509
  }
509
510
 
510
- /** Fields settable when creating/updating an agent. All optional except `name` on create
511
+ /** Fields settable when creating/updating a query profile. All optional except `name` on create
511
512
  * (null/omit => server default); model fields must be one of
512
- * `agents.modelOptions().fields[field].supported`. The owning tenant is the caller's key —
513
+ * `profiles.modelOptions().fields[field].supported`. The owning tenant is the caller's key —
513
514
  * it is never part of the body. */
514
515
  export type QueryProfileWrite = Partial<Omit<QueryProfile, "id" | "tenant_id">>;
515
516
 
516
517
  /** Model catalog for the query-profile-config UI (GET /v1/query-profiles/model-options). `models` maps id → its
517
- * capabilities; `fields` gives each agent model-field its supported ids + default (+ usage metadata);
518
+ * capabilities; `fields` gives each profile model-field its supported ids + default (+ usage metadata);
518
519
  * `modes` says which model field governs each mode (reasoning is valid only if that model's
519
520
  * supports_reasoning is true). KC provides the data; the UI decides presentation. */
520
521
  export interface ModelOptions {
@@ -893,7 +894,7 @@ export class KnowledgeCoreClient extends HttpBase {
893
894
  * `pending` (HTTP 202); track via documents.events()/get() or the tenant webhook.
894
895
  * ALWAYS uploads the bytes straight to GCS via a signed URL (uploadUrl → PUT → ingestFromUpload),
895
896
  * regardless of size — so there is NO request-size cap, ever. One method, any size. */
896
- ingestDocument: (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }) =>
897
+ ingestDocument: (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown>; profile_id?: UUID }) =>
897
898
  this.corpora.uploadDocument(id, a),
898
899
  /** Mint a signed PUT URL to upload a large file straight to GCS (bypasses the
899
900
  * ~32 MB request limit). PUT the bytes to upload_url, then ingestFromUpload. */
@@ -901,11 +902,11 @@ export class KnowledgeCoreClient extends HttpBase {
901
902
  this.request<UploadUrl>("POST", `/v1/corpora/${id}/documents/upload-url`, { json: a }),
902
903
  /** Ingest a file already PUT to GCS via uploadUrl. Resolves with the `pending`
903
904
  * document (202); track via documents.get() / webhook. */
904
- ingestFromUpload: (id: UUID, a: { document_id: UUID; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }) =>
905
+ ingestFromUpload: (id: UUID, a: { document_id: UUID; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown>; profile_id?: UUID }) =>
905
906
  this.request<Document>("POST", `/v1/corpora/${id}/documents/from-upload`, { json: a }),
906
907
  /** Convenience for LARGE files: uploadUrl → PUT the bytes to GCS → ingestFromUpload.
907
908
  * Use this instead of ingestDocument when the file may exceed ~32 MB. */
908
- uploadDocument: async (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown> }): Promise<Document> => {
909
+ uploadDocument: async (id: UUID, a: { file: FileData; filename: string; content_type?: string; visibility?: Visibility; folder_id?: UUID; custom_metadata?: Record<string, unknown>; profile_id?: UUID }): Promise<Document> => {
909
910
  const u = await this.corpora.uploadUrl(id, { filename: a.filename, content_type: a.content_type });
910
911
  const put = await this._fetch(u.upload_url, {
911
912
  method: "PUT",
@@ -918,6 +919,7 @@ export class KnowledgeCoreClient extends HttpBase {
918
919
  return this.corpora.ingestFromUpload(id, {
919
920
  document_id: u.document_id, filename: a.filename, content_type: a.content_type,
920
921
  visibility: a.visibility, folder_id: a.folder_id, custom_metadata: a.custom_metadata,
922
+ profile_id: a.profile_id,
921
923
  });
922
924
  },
923
925
  /** Ingest MANY files in ONE go — any size, no 429, no client backoff. Mints all signed URLs in
@@ -928,7 +930,7 @@ export class KnowledgeCoreClient extends HttpBase {
928
930
  uploadMany: async (
929
931
  id: UUID,
930
932
  files: Array<{ file: FileData; filename: string; content_type?: string }>,
931
- opts?: { folder_id?: UUID; visibility?: Visibility; custom_metadata?: Record<string, unknown>; concurrency?: number },
933
+ opts?: { folder_id?: UUID; visibility?: Visibility; custom_metadata?: Record<string, unknown>; concurrency?: number; profile_id?: UUID },
932
934
  ): Promise<Document[]> => {
933
935
  if (files.length === 0) return [];
934
936
  const urls = await this.request<BatchUploadUrls>(
@@ -950,6 +952,7 @@ export class KnowledgeCoreClient extends HttpBase {
950
952
  "POST", `/v1/corpora/${id}/documents/batch`,
951
953
  { json: {
952
954
  folder_id: opts?.folder_id, visibility: opts?.visibility, custom_metadata: opts?.custom_metadata,
955
+ profile_id: opts?.profile_id,
953
956
  items: items.map((it) => ({ document_id: it.document_id, filename: it.filename })),
954
957
  } },
955
958
  );
@@ -988,13 +991,13 @@ export class KnowledgeCoreClient extends HttpBase {
988
991
  finalizeUploads: (
989
992
  id: UUID,
990
993
  items: Array<{ document_id: UUID; filename: string; content_type?: string }>,
991
- opts?: { folder_id?: UUID; visibility?: Visibility; custom_metadata?: Record<string, unknown> },
994
+ opts?: { folder_id?: UUID; visibility?: Visibility; custom_metadata?: Record<string, unknown>; profile_id?: UUID },
992
995
  ): Promise<{ results: FinalizeResult[] }> =>
993
996
  this.request<{ results: FinalizeResult[] }>(
994
997
  "POST", `/v1/corpora/${id}/documents/finalize`,
995
998
  { json: {
996
999
  items, folder_id: opts?.folder_id, visibility: opts?.visibility,
997
- custom_metadata: opts?.custom_metadata,
1000
+ custom_metadata: opts?.custom_metadata, profile_id: opts?.profile_id,
998
1001
  } },
999
1002
  ),
1000
1003
 
@@ -1142,7 +1145,7 @@ export class KnowledgeCoreClient extends HttpBase {
1142
1145
  };
1143
1146
 
1144
1147
  /** Ingestion profiles — the build-side config object (counterpart to query profiles): a tenant-owned,
1145
- * named bundle of pipeline config (chunking + embedding + sparse + quant). Unlike an agent
1148
+ * named bundle of pipeline config (chunking + embedding + sparse + quant). Unlike a query profile
1146
1149
  * (chosen per query), a profile binds at the TENANT/COLLECTION level — the tenant's one
1147
1150
  * `is_default` profile governs how ALL its documents are ingested; swapping it re-indexes.
1148
1151
  * A corpus's content is a RESULT of ingestion, so a corpus never selects a profile. */