@babav/knowledge-core-client 0.17.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 +4 -2
- package/dist/index.d.ts +16 -17
- package/dist/index.js +20 -39
- package/package.json +10 -4
- package/src/index.ts +23 -43
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
|
|
36
|
-
apiKey:
|
|
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 —
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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> {
|
|
@@ -251,11 +250,11 @@ export declare class KnowledgeCoreError extends Error {
|
|
|
251
250
|
get code(): string | undefined;
|
|
252
251
|
}
|
|
253
252
|
export interface ClientOptions {
|
|
254
|
-
/** API base URL
|
|
255
|
-
baseUrl
|
|
256
|
-
/**
|
|
257
|
-
*
|
|
258
|
-
apiKey
|
|
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;
|
|
259
258
|
/** Optional default fetch timeout (ms). Streaming ignores this. */
|
|
260
259
|
timeoutMs?: number;
|
|
261
260
|
fetch?: typeof fetch;
|
|
@@ -272,7 +271,7 @@ declare class HttpBase {
|
|
|
272
271
|
protected readonly apiKey: string;
|
|
273
272
|
protected readonly timeoutMs?: number;
|
|
274
273
|
protected readonly _fetch: typeof fetch;
|
|
275
|
-
constructor(opts
|
|
274
|
+
constructor(opts: ClientOptions);
|
|
276
275
|
protected url(path: string, query?: RequestOpts["query"]): string;
|
|
277
276
|
protected raw(method: string, path: string, opts?: RequestOpts): Promise<Response>;
|
|
278
277
|
protected request<T>(method: string, path: string, opts?: RequestOpts): Promise<T>;
|
|
@@ -297,8 +296,8 @@ export interface StreamHandlers {
|
|
|
297
296
|
onEvent?: (event: string, data: unknown) => void;
|
|
298
297
|
}
|
|
299
298
|
export declare class KnowledgeCoreClient extends HttpBase {
|
|
300
|
-
/**
|
|
301
|
-
constructor(opts
|
|
299
|
+
/** @param opts.apiKey a TENANT key, supplied by the caller. */
|
|
300
|
+
constructor(opts: ClientOptions);
|
|
302
301
|
query(agentId: UUID, body: QueryRequest): Promise<QueryResponse>;
|
|
303
302
|
/** Streaming query (SSE). Resolves when the stream ends. */
|
|
304
303
|
queryStream(agentId: UUID, body: QueryRequest, handlers: StreamHandlers, signal?: AbortSignal): Promise<void>;
|
|
@@ -484,8 +483,8 @@ export declare class KnowledgeCoreClient extends HttpBase {
|
|
|
484
483
|
};
|
|
485
484
|
}
|
|
486
485
|
export declare class AdminClient extends HttpBase {
|
|
487
|
-
/**
|
|
488
|
-
constructor(opts
|
|
486
|
+
/** @param opts.apiKey the ADMIN key, supplied by the caller. */
|
|
487
|
+
constructor(opts: ClientOptions);
|
|
489
488
|
tenants: {
|
|
490
489
|
create: (b: Partial<Tenant> & {
|
|
491
490
|
name: string;
|
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 —
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.
|
|
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
|
-
/**
|
|
166
|
-
constructor(opts
|
|
167
|
-
super(opts
|
|
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
|
-
/**
|
|
333
|
-
constructor(opts
|
|
334
|
-
super(opts
|
|
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.
|
|
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": [
|
|
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": {
|
|
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 —
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
// ---------------------------------------------------------------------------
|
|
@@ -279,34 +278,16 @@ export class KnowledgeCoreError extends Error {
|
|
|
279
278
|
// Base HTTP
|
|
280
279
|
// ---------------------------------------------------------------------------
|
|
281
280
|
export interface ClientOptions {
|
|
282
|
-
/** API base URL
|
|
283
|
-
baseUrl
|
|
284
|
-
/**
|
|
285
|
-
*
|
|
286
|
-
apiKey
|
|
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;
|
|
287
286
|
/** Optional default fetch timeout (ms). Streaming ignores this. */
|
|
288
287
|
timeoutMs?: number;
|
|
289
288
|
fetch?: typeof fetch; // override for tests
|
|
290
289
|
}
|
|
291
290
|
|
|
292
|
-
/** Read an env var under Node (process.env) or Deno (Deno.env); undefined if unset
|
|
293
|
-
* or inaccessible (e.g. Deno without --allow-env). */
|
|
294
|
-
function readEnv(name: string): string | undefined {
|
|
295
|
-
const g = globalThis as {
|
|
296
|
-
process?: { env?: Record<string, string | undefined> };
|
|
297
|
-
Deno?: { env?: { get?: (n: string) => string | undefined } };
|
|
298
|
-
};
|
|
299
|
-
const fromNode = g.process?.env?.[name];
|
|
300
|
-
if (fromNode) return fromNode;
|
|
301
|
-
try {
|
|
302
|
-
const fromDeno = g.Deno?.env?.get?.(name);
|
|
303
|
-
if (fromDeno) return fromDeno;
|
|
304
|
-
} catch {
|
|
305
|
-
/* Deno env access denied (no --allow-env) — treat as unset */
|
|
306
|
-
}
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
291
|
interface RequestOpts {
|
|
311
292
|
query?: Record<string, string | number | boolean | undefined>;
|
|
312
293
|
json?: unknown;
|
|
@@ -321,13 +302,12 @@ class HttpBase {
|
|
|
321
302
|
protected readonly timeoutMs?: number;
|
|
322
303
|
protected readonly _fetch: typeof fetch;
|
|
323
304
|
|
|
324
|
-
constructor(opts: ClientOptions
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (!
|
|
328
|
-
|
|
329
|
-
this.
|
|
330
|
-
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;
|
|
331
311
|
this.timeoutMs = opts.timeoutMs;
|
|
332
312
|
this._fetch = opts.fetch ?? fetch;
|
|
333
313
|
}
|
|
@@ -435,9 +415,9 @@ export interface StreamHandlers {
|
|
|
435
415
|
// Tenant client (data ops) — use a TENANT key
|
|
436
416
|
// ---------------------------------------------------------------------------
|
|
437
417
|
export class KnowledgeCoreClient extends HttpBase {
|
|
438
|
-
/**
|
|
439
|
-
constructor(opts: ClientOptions
|
|
440
|
-
super(opts
|
|
418
|
+
/** @param opts.apiKey a TENANT key, supplied by the caller. */
|
|
419
|
+
constructor(opts: ClientOptions) {
|
|
420
|
+
super(opts);
|
|
441
421
|
}
|
|
442
422
|
|
|
443
423
|
// --- query (agent-anchored) ---
|
|
@@ -627,9 +607,9 @@ export class KnowledgeCoreClient extends HttpBase {
|
|
|
627
607
|
// Admin client (tenant + key + agent management) — use the ADMIN key
|
|
628
608
|
// ---------------------------------------------------------------------------
|
|
629
609
|
export class AdminClient extends HttpBase {
|
|
630
|
-
/**
|
|
631
|
-
constructor(opts: ClientOptions
|
|
632
|
-
super(opts
|
|
610
|
+
/** @param opts.apiKey the ADMIN key, supplied by the caller. */
|
|
611
|
+
constructor(opts: ClientOptions) {
|
|
612
|
+
super(opts);
|
|
633
613
|
}
|
|
634
614
|
|
|
635
615
|
tenants = {
|