@babav/knowledge-core-client 0.1.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 +92 -0
- package/dist/index.d.ts +477 -0
- package/dist/index.js +297 -0
- package/package.json +35 -0
- package/src/index.ts +566 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @babav/knowledge-core-client
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Babav Knowledge Core API. Zero dependencies; runs in
|
|
4
|
+
**Supabase Edge Functions (Deno)** and **Railway (Node 18+)** unchanged (uses the
|
|
5
|
+
global `fetch` + `ReadableStream`). It lives in the `babav-knowledge-core` repo so
|
|
6
|
+
every API change is reflected here 1:1 — wire shapes are snake_case to match the API.
|
|
7
|
+
|
|
8
|
+
> **The API key is server-side only.** Use a TENANT key for data ops; never ship it
|
|
9
|
+
> to a browser. The frontend mediates end-user permissions + visibility.
|
|
10
|
+
|
|
11
|
+
## Install / import
|
|
12
|
+
|
|
13
|
+
Published as a **public** npm package (free; no secrets in it — the API key is held
|
|
14
|
+
server-side by you, never embedded). Use it like any other dependency.
|
|
15
|
+
|
|
16
|
+
**Node / Railway:**
|
|
17
|
+
```bash
|
|
18
|
+
npm install @babav/knowledge-core-client
|
|
19
|
+
```
|
|
20
|
+
```ts
|
|
21
|
+
import { KnowledgeCoreClient, KnowledgeCoreError } from "@babav/knowledge-core-client";
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Deno / Supabase Edge:**
|
|
25
|
+
```ts
|
|
26
|
+
import { KnowledgeCoreClient } from "npm:@babav/knowledge-core-client";
|
|
27
|
+
```
|
|
28
|
+
(or, to avoid the registry entirely, import the single self-contained source file
|
|
29
|
+
`<repo>/clients/typescript/mod.ts` — zero deps.)
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
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
|
+
});
|
|
38
|
+
|
|
39
|
+
// One-shot grounded query
|
|
40
|
+
const r = await kc.query(agentId, { corpus_ids: [corpusId], query: "..." });
|
|
41
|
+
console.log(r.answer, r.retrieval_contents, r.citations, r.groundedness);
|
|
42
|
+
|
|
43
|
+
// Conversational (persisted, history-aware)
|
|
44
|
+
const convo = await kc.conversations.create({ title: "Contract review", custom_metadata: { account_id } });
|
|
45
|
+
const turn = await kc.query(agentId, { corpus_ids: [corpusId], query: "...", conversation_id: convo.id });
|
|
46
|
+
|
|
47
|
+
// Streaming (SSE)
|
|
48
|
+
await kc.queryStream(agentId, { corpus_ids: [corpusId], query: "..." }, {
|
|
49
|
+
onSources: (s) => render(s.retrieval_contents),
|
|
50
|
+
onToken: (t) => append(t),
|
|
51
|
+
onFinal: (f) => done(f),
|
|
52
|
+
onError: (e) => fail(e),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Attachment-backed review
|
|
56
|
+
const att = await kc.attachments.upload(convo.id, { filename: "c.pdf", content_type: "application/pdf", data: bytes });
|
|
57
|
+
await kc.attachments.waitReady(convo.id, att.id);
|
|
58
|
+
const review = await kc.query(agentId, { corpus_ids: [corpusId], conversation_id: convo.id, query: "Review the attached contract." });
|
|
59
|
+
|
|
60
|
+
// View/download a stored doc (signed URL)
|
|
61
|
+
const { content_url, content_type } = await kc.documents.contentUrl(documentId, "inline");
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Error handling (structured guards)
|
|
65
|
+
```ts
|
|
66
|
+
try { await kc.query(agentId, body); }
|
|
67
|
+
catch (e) {
|
|
68
|
+
if (e instanceof KnowledgeCoreError) {
|
|
69
|
+
if (e.code === "attachments_pending") { /* a document is still parsing */ }
|
|
70
|
+
else if (e.code === "attachment_exceeds_context_window") { /* too large; e.detail has sizes */ }
|
|
71
|
+
else if (e.status === 404) { /* not found / not your tenant */ }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Admin client (tenant + key + agent management — ADMIN key)
|
|
77
|
+
```ts
|
|
78
|
+
import { AdminClient } from "@babav/knowledge-core-client";
|
|
79
|
+
const admin = new AdminClient({ baseUrl, apiKey: ADMIN_KEY });
|
|
80
|
+
const created = await admin.tenants.createApiKey(tenantId, "label"); // created.api_key shown ONCE
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Surface
|
|
84
|
+
- `query`, `queryStream`, `retrieve`
|
|
85
|
+
- `corpora` (CRUD, listFolders, listDocuments, createDocument, ingest)
|
|
86
|
+
- `folders` (create, rename, delete, listDocuments)
|
|
87
|
+
- `documents` (get, getMetadata, patchMetadata, update, contentUrl, delete)
|
|
88
|
+
- `conversations` (CRUD, search, listMessages)
|
|
89
|
+
- `attachments` (upload, list, get, contentUrl, delete, waitReady)
|
|
90
|
+
- `messages` (get, createFeedback, listFeedback), `feedback` (get, delete)
|
|
91
|
+
- `parseJobs` (list, get), `agents` (list, get)
|
|
92
|
+
- `AdminClient`: `tenants` (CRUD + api-keys), `agents` (create/update/delete)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Babav Knowledge Core — TypeScript client.
|
|
3
|
+
*
|
|
4
|
+
* Portable: uses the global `fetch` + `ReadableStream`, so it runs unchanged in
|
|
5
|
+
* Supabase Edge Functions (Deno) and Railway (Node 18+). Zero dependencies.
|
|
6
|
+
*
|
|
7
|
+
* Wire shapes are snake_case to mirror the Knowledge Core API 1:1 — so an API
|
|
8
|
+
* change is reflected here with a one-to-one type edit and never drifts.
|
|
9
|
+
*
|
|
10
|
+
* Auth: every call carries an X-API-Key. Use TenantClient with a TENANT key for
|
|
11
|
+
* all data ops; use AdminClient with the ADMIN key for tenant / API-key / agent
|
|
12
|
+
* management. The key is server-side only — never ship it to a browser.
|
|
13
|
+
*/
|
|
14
|
+
export type UUID = string;
|
|
15
|
+
export interface Page<T> {
|
|
16
|
+
items: T[];
|
|
17
|
+
next_cursor: string | null;
|
|
18
|
+
}
|
|
19
|
+
export type Visibility = "downloadable" | "viewable" | "attributable" | "hidden";
|
|
20
|
+
export type FilterOp = "eq" | "ne" | "in" | "nin" | "gt" | "gte" | "lt" | "lte" | "exists";
|
|
21
|
+
export interface FilterClause {
|
|
22
|
+
field: string;
|
|
23
|
+
op: FilterOp;
|
|
24
|
+
value?: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface MetadataFilter {
|
|
27
|
+
op?: "and" | "or";
|
|
28
|
+
clauses: FilterClause[];
|
|
29
|
+
}
|
|
30
|
+
export interface RetrievalContent {
|
|
31
|
+
text: string;
|
|
32
|
+
score: number;
|
|
33
|
+
parent_id: string;
|
|
34
|
+
document_id: string;
|
|
35
|
+
corpus_id: string;
|
|
36
|
+
source_type: "corpus" | "conversation_attachment";
|
|
37
|
+
visibility: Visibility | string;
|
|
38
|
+
metadata: Record<string, unknown>;
|
|
39
|
+
source_url: string | null;
|
|
40
|
+
}
|
|
41
|
+
export interface QueryOverrides {
|
|
42
|
+
generation_model?: string;
|
|
43
|
+
top_k?: number;
|
|
44
|
+
rerank_instruction?: string;
|
|
45
|
+
max_hops?: number;
|
|
46
|
+
groundedness_threshold?: number;
|
|
47
|
+
grounding_enabled?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface QueryRequest {
|
|
50
|
+
corpus_ids: UUID[];
|
|
51
|
+
query: string;
|
|
52
|
+
conversation_id?: UUID | null;
|
|
53
|
+
overrides?: QueryOverrides;
|
|
54
|
+
filter?: MetadataFilter;
|
|
55
|
+
}
|
|
56
|
+
export interface QueryResponse {
|
|
57
|
+
conversation_id: UUID | null;
|
|
58
|
+
message_id: UUID | null;
|
|
59
|
+
answer: string;
|
|
60
|
+
retrieval_contents: RetrievalContent[];
|
|
61
|
+
citations: Citation[];
|
|
62
|
+
groundedness: Groundedness | null;
|
|
63
|
+
usage: Record<string, number | null>;
|
|
64
|
+
standalone_query: string | null;
|
|
65
|
+
hops: string[];
|
|
66
|
+
}
|
|
67
|
+
export interface Citation {
|
|
68
|
+
quote: string;
|
|
69
|
+
text_span: [number, number] | null;
|
|
70
|
+
context_index: number;
|
|
71
|
+
document_id: string;
|
|
72
|
+
source_url: string | null;
|
|
73
|
+
supported: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface Groundedness {
|
|
76
|
+
score: number;
|
|
77
|
+
model: string;
|
|
78
|
+
threshold: number | null;
|
|
79
|
+
passed: boolean | null;
|
|
80
|
+
}
|
|
81
|
+
export interface Corpus {
|
|
82
|
+
id: UUID;
|
|
83
|
+
tenant_id: UUID | null;
|
|
84
|
+
name: string;
|
|
85
|
+
description: string | null;
|
|
86
|
+
embedding_model: string;
|
|
87
|
+
external_ref: string | null;
|
|
88
|
+
created_at: string;
|
|
89
|
+
updated_at: string;
|
|
90
|
+
}
|
|
91
|
+
export interface Folder {
|
|
92
|
+
id: UUID;
|
|
93
|
+
corpus_id: UUID;
|
|
94
|
+
name: string;
|
|
95
|
+
is_default: boolean;
|
|
96
|
+
created_at: string;
|
|
97
|
+
updated_at: string;
|
|
98
|
+
}
|
|
99
|
+
export interface Document {
|
|
100
|
+
id: UUID;
|
|
101
|
+
corpus_id: UUID;
|
|
102
|
+
folder_id: UUID;
|
|
103
|
+
source_uri: string;
|
|
104
|
+
status: string;
|
|
105
|
+
visibility: Visibility;
|
|
106
|
+
content_type: string | null;
|
|
107
|
+
filename: string | null;
|
|
108
|
+
parse_job_id: UUID | null;
|
|
109
|
+
chunk_count: number;
|
|
110
|
+
datapoint_ids: string[];
|
|
111
|
+
custom_metadata: Record<string, unknown>;
|
|
112
|
+
error: string | null;
|
|
113
|
+
created_at: string;
|
|
114
|
+
updated_at: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ContentUrl {
|
|
117
|
+
content_url: string;
|
|
118
|
+
content_type: string;
|
|
119
|
+
filename: string;
|
|
120
|
+
}
|
|
121
|
+
export interface Conversation {
|
|
122
|
+
id: UUID;
|
|
123
|
+
tenant_id: UUID | null;
|
|
124
|
+
title: string | null;
|
|
125
|
+
custom_metadata: Record<string, unknown>;
|
|
126
|
+
ephemeral: boolean;
|
|
127
|
+
last_activity: string;
|
|
128
|
+
created_at: string;
|
|
129
|
+
updated_at: string;
|
|
130
|
+
}
|
|
131
|
+
export interface Message {
|
|
132
|
+
id: UUID;
|
|
133
|
+
conversation_id: UUID;
|
|
134
|
+
agent_id: UUID | null;
|
|
135
|
+
corpus_ids: UUID[] | null;
|
|
136
|
+
query: string;
|
|
137
|
+
answer: string | null;
|
|
138
|
+
citations: Record<string, unknown> | null;
|
|
139
|
+
groundedness: Record<string, unknown> | null;
|
|
140
|
+
retrieval_contents: unknown[] | null;
|
|
141
|
+
retrieval_debug: Record<string, unknown> | null;
|
|
142
|
+
usage: Record<string, unknown> | null;
|
|
143
|
+
created_at: string;
|
|
144
|
+
}
|
|
145
|
+
export interface ConversationDocument {
|
|
146
|
+
id: UUID;
|
|
147
|
+
conversation_id: UUID;
|
|
148
|
+
tenant_id: UUID;
|
|
149
|
+
filename: string | null;
|
|
150
|
+
content_type: string | null;
|
|
151
|
+
byte_size: number | null;
|
|
152
|
+
status: "parsing" | "ready" | "failed";
|
|
153
|
+
custom_metadata: Record<string, unknown> | null;
|
|
154
|
+
error: string | null;
|
|
155
|
+
created_at: string;
|
|
156
|
+
updated_at: string;
|
|
157
|
+
}
|
|
158
|
+
export interface ParseJob {
|
|
159
|
+
id: UUID;
|
|
160
|
+
tenant_id: UUID | null;
|
|
161
|
+
status: string;
|
|
162
|
+
document_count: number;
|
|
163
|
+
completed_count: number;
|
|
164
|
+
failed_count: number;
|
|
165
|
+
documents: unknown[];
|
|
166
|
+
created_at: string;
|
|
167
|
+
updated_at: string;
|
|
168
|
+
}
|
|
169
|
+
export interface Feedback {
|
|
170
|
+
id: UUID;
|
|
171
|
+
message_id: UUID;
|
|
172
|
+
rating: number | null;
|
|
173
|
+
comment: string | null;
|
|
174
|
+
created_at: string;
|
|
175
|
+
updated_at: string;
|
|
176
|
+
}
|
|
177
|
+
export interface Agent {
|
|
178
|
+
id: UUID;
|
|
179
|
+
name: string;
|
|
180
|
+
kind: "query" | "ingestion";
|
|
181
|
+
tenant_id: UUID | null;
|
|
182
|
+
generation_model: string | null;
|
|
183
|
+
top_k: number | null;
|
|
184
|
+
rerank_instruction: string | null;
|
|
185
|
+
max_hops: number | null;
|
|
186
|
+
groundedness_threshold: number | null;
|
|
187
|
+
grounding_enabled: boolean | null;
|
|
188
|
+
created_at: string;
|
|
189
|
+
updated_at: string;
|
|
190
|
+
}
|
|
191
|
+
export interface Tenant {
|
|
192
|
+
id: UUID;
|
|
193
|
+
name: string;
|
|
194
|
+
external_ref: string | null;
|
|
195
|
+
vector_index: string | null;
|
|
196
|
+
source_bucket: string | null;
|
|
197
|
+
artifacts_bucket: string | null;
|
|
198
|
+
query_endpoint: string | null;
|
|
199
|
+
query_public_domain: string | null;
|
|
200
|
+
query_deployed_index_id: string | null;
|
|
201
|
+
created_at: string;
|
|
202
|
+
updated_at: string;
|
|
203
|
+
}
|
|
204
|
+
export interface ApiKeyCreated {
|
|
205
|
+
id: UUID;
|
|
206
|
+
api_key: string;
|
|
207
|
+
prefix: string;
|
|
208
|
+
label: string | null;
|
|
209
|
+
created_at: string;
|
|
210
|
+
}
|
|
211
|
+
export interface ApiKeyInfo {
|
|
212
|
+
id: UUID;
|
|
213
|
+
tenant_id: UUID;
|
|
214
|
+
prefix: string;
|
|
215
|
+
label: string | null;
|
|
216
|
+
last_used_at: string | null;
|
|
217
|
+
revoked_at: string | null;
|
|
218
|
+
created_at: string;
|
|
219
|
+
updated_at: string;
|
|
220
|
+
}
|
|
221
|
+
/** Thrown on any non-2xx response. `detail` is the structured body when present
|
|
222
|
+
* (e.g. {error:"attachments_pending", attachments:[...]} or
|
|
223
|
+
* {error:"attachment_exceeds_context_window", ...}). */
|
|
224
|
+
export declare class KnowledgeCoreError extends Error {
|
|
225
|
+
readonly status: number;
|
|
226
|
+
readonly detail: unknown;
|
|
227
|
+
readonly path: string;
|
|
228
|
+
constructor(status: number, detail: unknown, path: string);
|
|
229
|
+
/** Convenience: the `error` code for structured guard responses. */
|
|
230
|
+
get code(): string | undefined;
|
|
231
|
+
}
|
|
232
|
+
export interface ClientOptions {
|
|
233
|
+
baseUrl: string;
|
|
234
|
+
apiKey: string;
|
|
235
|
+
/** Optional default fetch timeout (ms). Streaming ignores this. */
|
|
236
|
+
timeoutMs?: number;
|
|
237
|
+
fetch?: typeof fetch;
|
|
238
|
+
}
|
|
239
|
+
interface RequestOpts {
|
|
240
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
241
|
+
json?: unknown;
|
|
242
|
+
body?: BodyInit;
|
|
243
|
+
headers?: Record<string, string>;
|
|
244
|
+
signal?: AbortSignal;
|
|
245
|
+
}
|
|
246
|
+
declare class HttpBase {
|
|
247
|
+
protected readonly baseUrl: string;
|
|
248
|
+
protected readonly apiKey: string;
|
|
249
|
+
protected readonly timeoutMs?: number;
|
|
250
|
+
protected readonly _fetch: typeof fetch;
|
|
251
|
+
constructor(opts: ClientOptions);
|
|
252
|
+
protected url(path: string, query?: RequestOpts["query"]): string;
|
|
253
|
+
protected raw(method: string, path: string, opts?: RequestOpts): Promise<Response>;
|
|
254
|
+
protected request<T>(method: string, path: string, opts?: RequestOpts): Promise<T>;
|
|
255
|
+
/** Auto-paginate a list endpoint into a single array. */
|
|
256
|
+
protected pageAll<T>(path: string, query?: RequestOpts["query"]): Promise<T[]>;
|
|
257
|
+
}
|
|
258
|
+
export interface StreamHandlers {
|
|
259
|
+
onHop?: (d: {
|
|
260
|
+
n: number;
|
|
261
|
+
subquery: string;
|
|
262
|
+
status: string;
|
|
263
|
+
retrieval_contents?: number;
|
|
264
|
+
}) => void;
|
|
265
|
+
onSources?: (d: {
|
|
266
|
+
retrieval_contents: RetrievalContent[];
|
|
267
|
+
}) => void;
|
|
268
|
+
onToken?: (text: string) => void;
|
|
269
|
+
onFinal?: (d: QueryResponse) => void;
|
|
270
|
+
onError?: (d: unknown) => void;
|
|
271
|
+
onDone?: () => void;
|
|
272
|
+
/** Catch-all for any event (incl. unknown ones). */
|
|
273
|
+
onEvent?: (event: string, data: unknown) => void;
|
|
274
|
+
}
|
|
275
|
+
export declare class KnowledgeCoreClient extends HttpBase {
|
|
276
|
+
query(agentId: UUID, body: QueryRequest): Promise<QueryResponse>;
|
|
277
|
+
/** Streaming query (SSE). Resolves when the stream ends. */
|
|
278
|
+
queryStream(agentId: UUID, body: QueryRequest, handlers: StreamHandlers, signal?: AbortSignal): Promise<void>;
|
|
279
|
+
retrieve(body: {
|
|
280
|
+
query: string;
|
|
281
|
+
corpus_ids: UUID[];
|
|
282
|
+
top_k?: number;
|
|
283
|
+
rerank?: boolean;
|
|
284
|
+
instruction?: string;
|
|
285
|
+
filter?: MetadataFilter;
|
|
286
|
+
}): Promise<{
|
|
287
|
+
retrieval_contents: RetrievalContent[];
|
|
288
|
+
}>;
|
|
289
|
+
corpora: {
|
|
290
|
+
create: (b: {
|
|
291
|
+
name: string;
|
|
292
|
+
embedding_model: string;
|
|
293
|
+
description?: string;
|
|
294
|
+
external_ref?: string;
|
|
295
|
+
}) => Promise<Corpus>;
|
|
296
|
+
list: (q?: {
|
|
297
|
+
limit?: number;
|
|
298
|
+
cursor?: string;
|
|
299
|
+
}) => Promise<Page<Corpus>>;
|
|
300
|
+
listAll: () => Promise<Corpus[]>;
|
|
301
|
+
get: (id: UUID) => Promise<Corpus>;
|
|
302
|
+
update: (id: UUID, b: {
|
|
303
|
+
name?: string;
|
|
304
|
+
description?: string;
|
|
305
|
+
external_ref?: string;
|
|
306
|
+
}) => Promise<Corpus>;
|
|
307
|
+
delete: (id: UUID, confirmName: string) => Promise<void>;
|
|
308
|
+
listFolders: (id: UUID) => Promise<Folder[]>;
|
|
309
|
+
listDocuments: (id: UUID, q?: {
|
|
310
|
+
limit?: number;
|
|
311
|
+
cursor?: string;
|
|
312
|
+
}) => Promise<Page<Document>>;
|
|
313
|
+
createDocument: (id: UUID, b: {
|
|
314
|
+
source_uri: string;
|
|
315
|
+
folder_id?: UUID;
|
|
316
|
+
visibility?: Visibility;
|
|
317
|
+
status?: string;
|
|
318
|
+
parse_job_id?: UUID;
|
|
319
|
+
custom_metadata?: Record<string, unknown>;
|
|
320
|
+
}) => Promise<Document>;
|
|
321
|
+
ingest: (id: UUID, b: {
|
|
322
|
+
ingestion_agent_id: UUID;
|
|
323
|
+
folder_id?: UUID;
|
|
324
|
+
documents: {
|
|
325
|
+
gcs_uri: string;
|
|
326
|
+
custom_metadata?: Record<string, unknown>;
|
|
327
|
+
visibility?: Visibility;
|
|
328
|
+
}[];
|
|
329
|
+
}) => Promise<{
|
|
330
|
+
parse_job_id: UUID;
|
|
331
|
+
}>;
|
|
332
|
+
};
|
|
333
|
+
folders: {
|
|
334
|
+
create: (corpusId: UUID, name: string) => Promise<Folder>;
|
|
335
|
+
rename: (folderId: UUID, name: string) => Promise<Folder>;
|
|
336
|
+
delete: (folderId: UUID) => Promise<void>;
|
|
337
|
+
listDocuments: (folderId: UUID, q?: {
|
|
338
|
+
limit?: number;
|
|
339
|
+
cursor?: string;
|
|
340
|
+
}) => Promise<Page<Document>>;
|
|
341
|
+
};
|
|
342
|
+
documents: {
|
|
343
|
+
get: (id: UUID) => Promise<Document>;
|
|
344
|
+
getMetadata: (id: UUID) => Promise<{
|
|
345
|
+
document_id: UUID;
|
|
346
|
+
custom_metadata: Record<string, unknown>;
|
|
347
|
+
}>;
|
|
348
|
+
patchMetadata: (id: UUID, custom_metadata: Record<string, unknown>) => Promise<{
|
|
349
|
+
document_id: UUID;
|
|
350
|
+
custom_metadata: Record<string, unknown>;
|
|
351
|
+
}>;
|
|
352
|
+
update: (id: UUID, b: {
|
|
353
|
+
visibility?: Visibility;
|
|
354
|
+
folder_id?: UUID;
|
|
355
|
+
}) => Promise<Document>;
|
|
356
|
+
contentUrl: (id: UUID, disposition?: "inline" | "attachment") => Promise<ContentUrl>;
|
|
357
|
+
delete: (id: UUID) => Promise<void>;
|
|
358
|
+
};
|
|
359
|
+
conversations: {
|
|
360
|
+
create: (b?: {
|
|
361
|
+
title?: string;
|
|
362
|
+
custom_metadata?: Record<string, unknown>;
|
|
363
|
+
ephemeral?: boolean;
|
|
364
|
+
}) => Promise<Conversation>;
|
|
365
|
+
list: (q?: {
|
|
366
|
+
limit?: number;
|
|
367
|
+
cursor?: string;
|
|
368
|
+
}) => Promise<Page<Conversation>>;
|
|
369
|
+
get: (id: UUID) => Promise<Conversation>;
|
|
370
|
+
update: (id: UUID, b: {
|
|
371
|
+
title?: string;
|
|
372
|
+
custom_metadata?: Record<string, unknown>;
|
|
373
|
+
}) => Promise<Conversation>;
|
|
374
|
+
delete: (id: UUID) => Promise<void>;
|
|
375
|
+
/** Filter by custom_metadata using the same metadata filter as documents. */
|
|
376
|
+
search: (b: {
|
|
377
|
+
filter?: MetadataFilter;
|
|
378
|
+
limit?: number;
|
|
379
|
+
cursor?: string;
|
|
380
|
+
}) => Promise<Page<Conversation>>;
|
|
381
|
+
listMessages: (id: UUID, q?: {
|
|
382
|
+
limit?: number;
|
|
383
|
+
cursor?: string;
|
|
384
|
+
}) => Promise<Page<Message>>;
|
|
385
|
+
};
|
|
386
|
+
attachments: {
|
|
387
|
+
/** Upload + attach a document. `data` is the raw file bytes. Returns status=parsing. */
|
|
388
|
+
upload: (conversationId: UUID, a: {
|
|
389
|
+
filename: string;
|
|
390
|
+
content_type: string;
|
|
391
|
+
data: BodyInit;
|
|
392
|
+
custom_metadata?: Record<string, unknown>;
|
|
393
|
+
}) => Promise<ConversationDocument>;
|
|
394
|
+
list: (conversationId: UUID, q?: {
|
|
395
|
+
limit?: number;
|
|
396
|
+
cursor?: string;
|
|
397
|
+
}) => Promise<Page<ConversationDocument>>;
|
|
398
|
+
get: (conversationId: UUID, docId: UUID) => Promise<ConversationDocument>;
|
|
399
|
+
contentUrl: (conversationId: UUID, docId: UUID, disposition?: "inline" | "attachment") => Promise<ContentUrl>;
|
|
400
|
+
delete: (conversationId: UUID, docId: UUID) => Promise<void>;
|
|
401
|
+
/** Poll until the attachment is ready or failed (or timeout). */
|
|
402
|
+
waitReady: (conversationId: UUID, docId: UUID, opts?: {
|
|
403
|
+
intervalMs?: number;
|
|
404
|
+
timeoutMs?: number;
|
|
405
|
+
}) => Promise<ConversationDocument>;
|
|
406
|
+
};
|
|
407
|
+
messages: {
|
|
408
|
+
get: (id: UUID) => Promise<Message>;
|
|
409
|
+
createFeedback: (messageId: UUID, b: {
|
|
410
|
+
rating?: number;
|
|
411
|
+
comment?: string;
|
|
412
|
+
}) => Promise<Feedback>;
|
|
413
|
+
listFeedback: (messageId: UUID, q?: {
|
|
414
|
+
limit?: number;
|
|
415
|
+
cursor?: string;
|
|
416
|
+
}) => Promise<Page<Feedback>>;
|
|
417
|
+
};
|
|
418
|
+
feedback: {
|
|
419
|
+
get: (id: UUID) => Promise<Feedback>;
|
|
420
|
+
delete: (id: UUID) => Promise<void>;
|
|
421
|
+
};
|
|
422
|
+
parseJobs: {
|
|
423
|
+
list: (q?: {
|
|
424
|
+
status_filter?: string;
|
|
425
|
+
limit?: number;
|
|
426
|
+
cursor?: string;
|
|
427
|
+
}) => Promise<Page<ParseJob>>;
|
|
428
|
+
get: (id: UUID) => Promise<ParseJob>;
|
|
429
|
+
};
|
|
430
|
+
agents: {
|
|
431
|
+
list: (q?: {
|
|
432
|
+
kind?: "query" | "ingestion";
|
|
433
|
+
limit?: number;
|
|
434
|
+
cursor?: string;
|
|
435
|
+
}) => Promise<Page<Agent>>;
|
|
436
|
+
listAll: () => Promise<Agent[]>;
|
|
437
|
+
get: (id: UUID) => Promise<Agent>;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
export declare class AdminClient extends HttpBase {
|
|
441
|
+
tenants: {
|
|
442
|
+
create: (b: Partial<Tenant> & {
|
|
443
|
+
name: string;
|
|
444
|
+
}) => Promise<Tenant>;
|
|
445
|
+
list: (q?: {
|
|
446
|
+
limit?: number;
|
|
447
|
+
cursor?: string;
|
|
448
|
+
}) => Promise<Page<Tenant>>;
|
|
449
|
+
get: (id: UUID) => Promise<Tenant>;
|
|
450
|
+
update: (id: UUID, b: Partial<Tenant>) => Promise<Tenant>;
|
|
451
|
+
delete: (id: UUID, confirmName: string) => Promise<void>;
|
|
452
|
+
/** Mint a tenant API key — the raw key is in the response ONCE; store it now. */
|
|
453
|
+
createApiKey: (tenantId: UUID, label?: string) => Promise<ApiKeyCreated>;
|
|
454
|
+
listApiKeys: (tenantId: UUID, q?: {
|
|
455
|
+
limit?: number;
|
|
456
|
+
cursor?: string;
|
|
457
|
+
}) => Promise<Page<ApiKeyInfo>>;
|
|
458
|
+
revokeApiKey: (tenantId: UUID, keyId: UUID) => Promise<void>;
|
|
459
|
+
};
|
|
460
|
+
agents: {
|
|
461
|
+
/** tenant_id explicit, or null for a global/shared agent. */
|
|
462
|
+
create: (b: {
|
|
463
|
+
name: string;
|
|
464
|
+
kind: "query" | "ingestion";
|
|
465
|
+
tenant_id?: UUID | null;
|
|
466
|
+
generation_model?: string;
|
|
467
|
+
top_k?: number;
|
|
468
|
+
rerank_instruction?: string;
|
|
469
|
+
max_hops?: number;
|
|
470
|
+
groundedness_threshold?: number;
|
|
471
|
+
grounding_enabled?: boolean;
|
|
472
|
+
}) => Promise<Agent>;
|
|
473
|
+
update: (id: UUID, b: Partial<Omit<Agent, "id" | "kind" | "tenant_id" | "created_at" | "updated_at">>) => Promise<Agent>;
|
|
474
|
+
delete: (id: UUID) => Promise<void>;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
export {};
|