@babav/knowledge-core-client 0.16.0 → 0.18.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
@@ -31,9 +31,11 @@ import { KnowledgeCoreClient } from "npm:@babav/knowledge-core-client";
31
31
  ## Usage
32
32
 
33
33
  ```ts
34
+ // You supply baseUrl + your tenant key at construction (from wherever your app keeps
35
+ // its config/secrets). The SDK never reads the environment or defaults a key itself.
34
36
  const kc = new KnowledgeCoreClient({
35
- baseUrl: "https://babav-kc-api-gmtvlr3vta-uc.a.run.app",
36
- apiKey: Deno.env.get("BABAV_KC_TENANT_KEY")!, // or process.env on Node
37
+ baseUrl: "https://knowledgecore.babav.ai",
38
+ apiKey: myTenantKey, // your tenant key, provided by your app
37
39
  });
38
40
 
39
41
  // One-shot grounded query
package/dist/index.d.ts CHANGED
@@ -12,13 +12,12 @@
12
12
  * key for all data ops; use AdminClient with the ADMIN key for tenant / API-key /
13
13
  * agent management. The key is server-side only — never ship it to a browser.
14
14
  *
15
- * Configuration — environment variables (Node `process.env` or Deno `Deno.env`):
16
- * `new KnowledgeCoreClient()` reads BABAV_KC_BASE_URL + BABAV_KC_TENANT_KEY
17
- * `new AdminClient()` reads BABAV_KC_BASE_URL + BABAV_KC_ADMIN_KEY
18
- * Passing { baseUrl } / { apiKey } explicitly overrides the env var for that field
19
- * (the app is then responsible for supplying it). A missing value (no param AND no
20
- * env var) throws at construction with a clear message. In Deno, env access needs
21
- * `--allow-env` (without it, pass the values explicitly).
15
+ * Configuration — the CALLER supplies credentials at construction; the SDK never reads
16
+ * the environment or defaults/derives a key itself:
17
+ * new KnowledgeCoreClient({ baseUrl, apiKey }) // apiKey = a TENANT key
18
+ * new AdminClient({ baseUrl, apiKey }) // apiKey = the ADMIN key
19
+ * The app decides where its key comes from (its own env/secret store) and passes it in.
20
+ * A missing baseUrl or apiKey throws at construction with a clear message.
22
21
  */
23
22
  export type UUID = string;
24
23
  export interface Page<T> {
@@ -56,8 +55,10 @@ export interface QueryOverrides {
56
55
  top_k_reranked_chunks?: number;
57
56
  sibling_window?: number;
58
57
  rerank_instruction?: string;
59
- max_hops?: number;
58
+ max_subqueries?: number;
59
+ max_reasoning_rounds?: number;
60
60
  decomposition_model?: string;
61
+ reasoning_inspect_model?: string;
61
62
  groundedness_verifier_model?: string;
62
63
  groundedness_threshold?: number;
63
64
  grounding_enabled?: boolean;
@@ -209,8 +210,10 @@ export interface Agent {
209
210
  top_k_reranked_chunks: number | null;
210
211
  sibling_window: number | null;
211
212
  rerank_instruction: string | null;
212
- max_hops: number | null;
213
+ max_subqueries: number | null;
214
+ max_reasoning_rounds: number | null;
213
215
  decomposition_model: string | null;
216
+ reasoning_inspect_model: string | null;
214
217
  groundedness_verifier_model: string | null;
215
218
  groundedness_threshold: number | null;
216
219
  grounding_enabled: boolean | null;
@@ -247,11 +250,11 @@ export declare class KnowledgeCoreError extends Error {
247
250
  get code(): string | undefined;
248
251
  }
249
252
  export interface ClientOptions {
250
- /** API base URL. Defaults to env BABAV_KC_BASE_URL when omitted. */
251
- baseUrl?: string;
252
- /** Tenant key (KnowledgeCoreClient) or admin key (AdminClient). Defaults to env
253
- * BABAV_KC_TENANT_KEY / BABAV_KC_ADMIN_KEY respectively when omitted. */
254
- apiKey?: string;
253
+ /** API base URL REQUIRED, supplied by the caller. */
254
+ baseUrl: string;
255
+ /** API key REQUIRED, supplied by the caller (a TENANT key for KnowledgeCoreClient,
256
+ * the ADMIN key for AdminClient). The SDK never reads it from the environment. */
257
+ apiKey: string;
255
258
  /** Optional default fetch timeout (ms). Streaming ignores this. */
256
259
  timeoutMs?: number;
257
260
  fetch?: typeof fetch;
@@ -268,7 +271,7 @@ declare class HttpBase {
268
271
  protected readonly apiKey: string;
269
272
  protected readonly timeoutMs?: number;
270
273
  protected readonly _fetch: typeof fetch;
271
- constructor(opts?: ClientOptions, keyEnvVar?: string);
274
+ constructor(opts: ClientOptions);
272
275
  protected url(path: string, query?: RequestOpts["query"]): string;
273
276
  protected raw(method: string, path: string, opts?: RequestOpts): Promise<Response>;
274
277
  protected request<T>(method: string, path: string, opts?: RequestOpts): Promise<T>;
@@ -293,8 +296,8 @@ export interface StreamHandlers {
293
296
  onEvent?: (event: string, data: unknown) => void;
294
297
  }
295
298
  export declare class KnowledgeCoreClient extends HttpBase {
296
- /** Defaults to env BABAV_KC_BASE_URL + BABAV_KC_TENANT_KEY when not passed. */
297
- constructor(opts?: ClientOptions);
299
+ /** @param opts.apiKey a TENANT key, supplied by the caller. */
300
+ constructor(opts: ClientOptions);
298
301
  query(agentId: UUID, body: QueryRequest): Promise<QueryResponse>;
299
302
  /** Streaming query (SSE). Resolves when the stream ends. */
300
303
  queryStream(agentId: UUID, body: QueryRequest, handlers: StreamHandlers, signal?: AbortSignal): Promise<void>;
@@ -480,8 +483,8 @@ export declare class KnowledgeCoreClient extends HttpBase {
480
483
  };
481
484
  }
482
485
  export declare class AdminClient extends HttpBase {
483
- /** Defaults to env BABAV_KC_BASE_URL + BABAV_KC_ADMIN_KEY when not passed. */
484
- constructor(opts?: ClientOptions);
486
+ /** @param opts.apiKey the ADMIN key, supplied by the caller. */
487
+ constructor(opts: ClientOptions);
485
488
  tenants: {
486
489
  create: (b: Partial<Tenant> & {
487
490
  name: string;
@@ -512,8 +515,10 @@ export declare class AdminClient extends HttpBase {
512
515
  top_k_reranked_chunks?: number;
513
516
  sibling_window?: number;
514
517
  rerank_instruction?: string;
515
- max_hops?: number;
518
+ max_subqueries?: number;
519
+ max_reasoning_rounds?: number;
516
520
  decomposition_model?: string;
521
+ reasoning_inspect_model?: string;
517
522
  groundedness_verifier_model?: string;
518
523
  groundedness_threshold?: number;
519
524
  grounding_enabled?: boolean;
package/dist/index.js CHANGED
@@ -12,13 +12,12 @@
12
12
  * key for all data ops; use AdminClient with the ADMIN key for tenant / API-key /
13
13
  * agent management. The key is server-side only — never ship it to a browser.
14
14
  *
15
- * Configuration — environment variables (Node `process.env` or Deno `Deno.env`):
16
- * `new KnowledgeCoreClient()` reads BABAV_KC_BASE_URL + BABAV_KC_TENANT_KEY
17
- * `new AdminClient()` reads BABAV_KC_BASE_URL + BABAV_KC_ADMIN_KEY
18
- * Passing { baseUrl } / { apiKey } explicitly overrides the env var for that field
19
- * (the app is then responsible for supplying it). A missing value (no param AND no
20
- * env var) throws at construction with a clear message. In Deno, env access needs
21
- * `--allow-env` (without it, pass the values explicitly).
15
+ * Configuration — the CALLER supplies credentials at construction; the SDK never reads
16
+ * the environment or defaults/derives a key itself:
17
+ * new KnowledgeCoreClient({ baseUrl, apiKey }) // apiKey = a TENANT key
18
+ * new AdminClient({ baseUrl, apiKey }) // apiKey = the ADMIN key
19
+ * The app decides where its key comes from (its own env/secret store) and passes it in.
20
+ * A missing baseUrl or apiKey throws at construction with a clear message.
22
21
  */
23
22
  // ---------------------------------------------------------------------------
24
23
  // Errors
@@ -43,37 +42,19 @@ export class KnowledgeCoreError extends Error {
43
42
  return d?.detail?.error ?? d?.error;
44
43
  }
45
44
  }
46
- /** Read an env var under Node (process.env) or Deno (Deno.env); undefined if unset
47
- * or inaccessible (e.g. Deno without --allow-env). */
48
- function readEnv(name) {
49
- const g = globalThis;
50
- const fromNode = g.process?.env?.[name];
51
- if (fromNode)
52
- return fromNode;
53
- try {
54
- const fromDeno = g.Deno?.env?.get?.(name);
55
- if (fromDeno)
56
- return fromDeno;
57
- }
58
- catch {
59
- /* Deno env access denied (no --allow-env) — treat as unset */
60
- }
61
- return undefined;
62
- }
63
45
  class HttpBase {
64
46
  baseUrl;
65
47
  apiKey;
66
48
  timeoutMs;
67
49
  _fetch;
68
- constructor(opts = {}, keyEnvVar = "BABAV_KC_TENANT_KEY") {
69
- const baseUrl = opts.baseUrl ?? readEnv("BABAV_KC_BASE_URL");
70
- const apiKey = opts.apiKey ?? readEnv(keyEnvVar);
71
- if (!baseUrl)
72
- throw new Error("KnowledgeCore: no base URL — pass { baseUrl } or set BABAV_KC_BASE_URL");
73
- if (!apiKey)
74
- throw new Error(`KnowledgeCore: no API key — pass { apiKey } or set ${keyEnvVar}`);
75
- this.baseUrl = baseUrl.replace(/\/+$/, "");
76
- this.apiKey = apiKey;
50
+ constructor(opts) {
51
+ // Credentials come from the CALLER at init — the SDK never sources a key itself.
52
+ if (!opts?.baseUrl)
53
+ throw new Error("KnowledgeCore: { baseUrl } is required");
54
+ if (!opts?.apiKey)
55
+ throw new Error("KnowledgeCore: { apiKey } is required — the caller must supply the key at init");
56
+ this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
57
+ this.apiKey = opts.apiKey;
77
58
  this.timeoutMs = opts.timeoutMs;
78
59
  this._fetch = opts.fetch ?? fetch;
79
60
  }
@@ -162,9 +143,9 @@ const MULTIPART_MAX_BYTES = 30 * 1024 * 1024;
162
143
  // Tenant client (data ops) — use a TENANT key
163
144
  // ---------------------------------------------------------------------------
164
145
  export class KnowledgeCoreClient extends HttpBase {
165
- /** Defaults to env BABAV_KC_BASE_URL + BABAV_KC_TENANT_KEY when not passed. */
166
- constructor(opts = {}) {
167
- super(opts, "BABAV_KC_TENANT_KEY");
146
+ /** @param opts.apiKey a TENANT key, supplied by the caller. */
147
+ constructor(opts) {
148
+ super(opts);
168
149
  }
169
150
  // --- query (agent-anchored) ---
170
151
  query(agentId, body) {
@@ -329,9 +310,9 @@ export class KnowledgeCoreClient extends HttpBase {
329
310
  // Admin client (tenant + key + agent management) — use the ADMIN key
330
311
  // ---------------------------------------------------------------------------
331
312
  export class AdminClient extends HttpBase {
332
- /** Defaults to env BABAV_KC_BASE_URL + BABAV_KC_ADMIN_KEY when not passed. */
333
- constructor(opts = {}) {
334
- super(opts, "BABAV_KC_ADMIN_KEY");
313
+ /** @param opts.apiKey the ADMIN key, supplied by the caller. */
314
+ constructor(opts) {
315
+ super(opts);
335
316
  }
336
317
  tenants = {
337
318
  create: (b) => this.request("POST", "/v1/tenants", { json: b }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.16.0",
3
+ "version": "0.18.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",
@@ -11,7 +11,10 @@
11
11
  "import": "./dist/index.js"
12
12
  }
13
13
  },
14
- "files": ["dist", "src"],
14
+ "files": [
15
+ "dist",
16
+ "src"
17
+ ],
15
18
  "publishConfig": {
16
19
  "access": "public",
17
20
  "registry": "https://registry.npmjs.org/"
@@ -23,12 +26,15 @@
23
26
  },
24
27
  "scripts": {
25
28
  "build": "tsc -p tsconfig.json",
26
- "typecheck": "tsc -p tsconfig.json --noEmit"
29
+ "typecheck": "tsc -p tsconfig.json --noEmit",
30
+ "test": "npm run build && node --test test/"
27
31
  },
28
32
  "devDependencies": {
29
33
  "typescript": "^5.6.0"
30
34
  },
31
- "engines": { "node": ">=18" },
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
32
38
  "sideEffects": false,
33
39
  "private": false,
34
40
  "license": "UNLICENSED"
package/src/index.ts CHANGED
@@ -12,13 +12,12 @@
12
12
  * key for all data ops; use AdminClient with the ADMIN key for tenant / API-key /
13
13
  * agent management. The key is server-side only — never ship it to a browser.
14
14
  *
15
- * Configuration — environment variables (Node `process.env` or Deno `Deno.env`):
16
- * `new KnowledgeCoreClient()` reads BABAV_KC_BASE_URL + BABAV_KC_TENANT_KEY
17
- * `new AdminClient()` reads BABAV_KC_BASE_URL + BABAV_KC_ADMIN_KEY
18
- * Passing { baseUrl } / { apiKey } explicitly overrides the env var for that field
19
- * (the app is then responsible for supplying it). A missing value (no param AND no
20
- * env var) throws at construction with a clear message. In Deno, env access needs
21
- * `--allow-env` (without it, pass the values explicitly).
15
+ * Configuration — the CALLER supplies credentials at construction; the SDK never reads
16
+ * the environment or defaults/derives a key itself:
17
+ * new KnowledgeCoreClient({ baseUrl, apiKey }) // apiKey = a TENANT key
18
+ * new AdminClient({ baseUrl, apiKey }) // apiKey = the ADMIN key
19
+ * The app decides where its key comes from (its own env/secret store) and passes it in.
20
+ * A missing baseUrl or apiKey throws at construction with a clear message.
22
21
  */
23
22
 
24
23
  // ---------------------------------------------------------------------------
@@ -66,8 +65,10 @@ export interface QueryOverrides {
66
65
  top_k_reranked_chunks?: number; // sections kept after rerank -> the LLM
67
66
  sibling_window?: number; // adjacent sections fetched each side of a hit
68
67
  rerank_instruction?: string;
69
- max_hops?: number;
68
+ max_subqueries?: number; // parallel decompose-and-merge breadth per retrieval step
69
+ max_reasoning_rounds?: number; // iterative agentic-loop ceiling (1 = single pass; early-stops)
70
70
  decomposition_model?: string; // model for query decomposition
71
+ reasoning_inspect_model?: string; // model for the per-round sufficiency / next-query decision
71
72
  groundedness_verifier_model?: string; // model for the groundedness LLM judge
72
73
  groundedness_threshold?: number;
73
74
  grounding_enabled?: boolean; // groundedness score (default off)
@@ -222,8 +223,10 @@ export interface Agent {
222
223
  top_k_reranked_chunks: number | null;
223
224
  sibling_window: number | null;
224
225
  rerank_instruction: string | null;
225
- max_hops: number | null;
226
+ max_subqueries: number | null;
227
+ max_reasoning_rounds: number | null;
226
228
  decomposition_model: string | null;
229
+ reasoning_inspect_model: string | null;
227
230
  groundedness_verifier_model: string | null;
228
231
  groundedness_threshold: number | null;
229
232
  grounding_enabled: boolean | null;
@@ -275,34 +278,16 @@ export class KnowledgeCoreError extends Error {
275
278
  // Base HTTP
276
279
  // ---------------------------------------------------------------------------
277
280
  export interface ClientOptions {
278
- /** API base URL. Defaults to env BABAV_KC_BASE_URL when omitted. */
279
- baseUrl?: string;
280
- /** Tenant key (KnowledgeCoreClient) or admin key (AdminClient). Defaults to env
281
- * BABAV_KC_TENANT_KEY / BABAV_KC_ADMIN_KEY respectively when omitted. */
282
- apiKey?: string;
281
+ /** API base URL REQUIRED, supplied by the caller. */
282
+ baseUrl: string;
283
+ /** API key REQUIRED, supplied by the caller (a TENANT key for KnowledgeCoreClient,
284
+ * the ADMIN key for AdminClient). The SDK never reads it from the environment. */
285
+ apiKey: string;
283
286
  /** Optional default fetch timeout (ms). Streaming ignores this. */
284
287
  timeoutMs?: number;
285
288
  fetch?: typeof fetch; // override for tests
286
289
  }
287
290
 
288
- /** Read an env var under Node (process.env) or Deno (Deno.env); undefined if unset
289
- * or inaccessible (e.g. Deno without --allow-env). */
290
- function readEnv(name: string): string | undefined {
291
- const g = globalThis as {
292
- process?: { env?: Record<string, string | undefined> };
293
- Deno?: { env?: { get?: (n: string) => string | undefined } };
294
- };
295
- const fromNode = g.process?.env?.[name];
296
- if (fromNode) return fromNode;
297
- try {
298
- const fromDeno = g.Deno?.env?.get?.(name);
299
- if (fromDeno) return fromDeno;
300
- } catch {
301
- /* Deno env access denied (no --allow-env) — treat as unset */
302
- }
303
- return undefined;
304
- }
305
-
306
291
  interface RequestOpts {
307
292
  query?: Record<string, string | number | boolean | undefined>;
308
293
  json?: unknown;
@@ -317,13 +302,12 @@ class HttpBase {
317
302
  protected readonly timeoutMs?: number;
318
303
  protected readonly _fetch: typeof fetch;
319
304
 
320
- constructor(opts: ClientOptions = {}, keyEnvVar = "BABAV_KC_TENANT_KEY") {
321
- const baseUrl = opts.baseUrl ?? readEnv("BABAV_KC_BASE_URL");
322
- const apiKey = opts.apiKey ?? readEnv(keyEnvVar);
323
- if (!baseUrl) throw new Error("KnowledgeCore: no base URLpass { baseUrl } or set BABAV_KC_BASE_URL");
324
- if (!apiKey) throw new Error(`KnowledgeCore: no API key — pass { apiKey } or set ${keyEnvVar}`);
325
- this.baseUrl = baseUrl.replace(/\/+$/, "");
326
- this.apiKey = apiKey;
305
+ constructor(opts: ClientOptions) {
306
+ // Credentials come from the CALLER at init — the SDK never sources a key itself.
307
+ if (!opts?.baseUrl) throw new Error("KnowledgeCore: { baseUrl } is required");
308
+ if (!opts?.apiKey) throw new Error("KnowledgeCore: { apiKey } is required the caller must supply the key at init");
309
+ this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
310
+ this.apiKey = opts.apiKey;
327
311
  this.timeoutMs = opts.timeoutMs;
328
312
  this._fetch = opts.fetch ?? fetch;
329
313
  }
@@ -431,9 +415,9 @@ export interface StreamHandlers {
431
415
  // Tenant client (data ops) — use a TENANT key
432
416
  // ---------------------------------------------------------------------------
433
417
  export class KnowledgeCoreClient extends HttpBase {
434
- /** Defaults to env BABAV_KC_BASE_URL + BABAV_KC_TENANT_KEY when not passed. */
435
- constructor(opts: ClientOptions = {}) {
436
- super(opts, "BABAV_KC_TENANT_KEY");
418
+ /** @param opts.apiKey a TENANT key, supplied by the caller. */
419
+ constructor(opts: ClientOptions) {
420
+ super(opts);
437
421
  }
438
422
 
439
423
  // --- query (agent-anchored) ---
@@ -623,9 +607,9 @@ export class KnowledgeCoreClient extends HttpBase {
623
607
  // Admin client (tenant + key + agent management) — use the ADMIN key
624
608
  // ---------------------------------------------------------------------------
625
609
  export class AdminClient extends HttpBase {
626
- /** Defaults to env BABAV_KC_BASE_URL + BABAV_KC_ADMIN_KEY when not passed. */
627
- constructor(opts: ClientOptions = {}) {
628
- super(opts, "BABAV_KC_ADMIN_KEY");
610
+ /** @param opts.apiKey the ADMIN key, supplied by the caller. */
611
+ constructor(opts: ClientOptions) {
612
+ super(opts);
629
613
  }
630
614
 
631
615
  tenants = {
@@ -642,7 +626,7 @@ export class AdminClient extends HttpBase {
642
626
 
643
627
  // Agents are query agents, global for now.
644
628
  agents = {
645
- create: (b: { name: string; identity_prompt?: string; response_prompt?: string; generation_model?: string; max_response_tokens?: number; top_k_retrieved_chunks?: number; top_k_reranked_chunks?: number; sibling_window?: number; rerank_instruction?: string; max_hops?: number; decomposition_model?: string; groundedness_verifier_model?: string; groundedness_threshold?: number; grounding_enabled?: boolean; citations_enabled?: boolean }) =>
629
+ create: (b: { name: string; identity_prompt?: string; response_prompt?: string; generation_model?: string; max_response_tokens?: number; top_k_retrieved_chunks?: number; top_k_reranked_chunks?: number; sibling_window?: number; rerank_instruction?: string; max_subqueries?: number; max_reasoning_rounds?: number; decomposition_model?: string; reasoning_inspect_model?: string; groundedness_verifier_model?: string; groundedness_threshold?: number; grounding_enabled?: boolean; citations_enabled?: boolean }) =>
646
630
  this.request<Agent>("POST", "/v1/agents", { json: b }),
647
631
  update: (id: UUID, b: Partial<Omit<Agent, "id">>) =>
648
632
  this.request<Agent>("PATCH", `/v1/agents/${id}`, { json: b }),