@openbkn/bkn-sdk 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/LICENSE +201 -0
- package/README.md +104 -0
- package/README.zh.md +88 -0
- package/dist/chunk-4NXAIG4G.js +4805 -0
- package/dist/chunk-4NXAIG4G.js.map +1 -0
- package/dist/cli.js +2317 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +955 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,955 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Shared types for the SDK surface. No runtime, no side effects. */
|
|
4
|
+
/** Options a caller supplies; any field may be resolved from env/config store. */
|
|
5
|
+
interface ClientOptions {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
/** Specific user credentials (transient); maps to legacy `--user`. */
|
|
9
|
+
user?: string;
|
|
10
|
+
/** Business domain header; defaults to `bd_public`. */
|
|
11
|
+
businessDomain?: string;
|
|
12
|
+
/** Skip TLS verification (dev / self-signed only). */
|
|
13
|
+
insecure?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Fully resolved request context — every field is known. */
|
|
16
|
+
interface RequestContext {
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
token: string;
|
|
19
|
+
businessDomain: string;
|
|
20
|
+
insecure: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare const DEFAULT_BUSINESS_DOMAIN = "bd_public";
|
|
23
|
+
/** Default list/query limits — see AGENTS.md conventions. */
|
|
24
|
+
declare const DEFAULT_LIST_LIMIT = 30;
|
|
25
|
+
declare const DEFAULT_QUERY_LIMIT = 50;
|
|
26
|
+
|
|
27
|
+
interface RawCallOptions {
|
|
28
|
+
method?: string;
|
|
29
|
+
/** Extra headers as raw "Name: value" strings. */
|
|
30
|
+
header?: string[];
|
|
31
|
+
/** Raw request body (string). Mutually exclusive with `form`. */
|
|
32
|
+
data?: string;
|
|
33
|
+
/** Multipart fields: "key=value" or "key=@/path/to/file". */
|
|
34
|
+
form?: string[];
|
|
35
|
+
/** Override business domain for this call. */
|
|
36
|
+
businessDomain?: string;
|
|
37
|
+
verbose?: boolean;
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
}
|
|
40
|
+
interface RawCallResult {
|
|
41
|
+
status: number;
|
|
42
|
+
statusText: string;
|
|
43
|
+
body: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Admin (operator) client — user-management + authorization. Mirrors
|
|
48
|
+
* kweaver-admin. Reads and writes (org/user create/update/delete +
|
|
49
|
+
* reset-password) implemented; org/user detail and writes go through ISFWeb
|
|
50
|
+
* thrift where the REST routes are RegisterPrivate. Passed through as JSON.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
interface AdminListOptions {
|
|
54
|
+
role?: string;
|
|
55
|
+
offset?: number;
|
|
56
|
+
limit?: number;
|
|
57
|
+
name?: string;
|
|
58
|
+
orgId?: string;
|
|
59
|
+
}
|
|
60
|
+
interface ListRolesOptions {
|
|
61
|
+
offset?: number;
|
|
62
|
+
limit?: number;
|
|
63
|
+
keyword?: string;
|
|
64
|
+
}
|
|
65
|
+
interface CreateOrgInput {
|
|
66
|
+
name: string;
|
|
67
|
+
parentId?: string;
|
|
68
|
+
managerID?: string | null;
|
|
69
|
+
code?: string;
|
|
70
|
+
remark?: string;
|
|
71
|
+
status?: number;
|
|
72
|
+
email?: string;
|
|
73
|
+
}
|
|
74
|
+
interface UpdateOrgInput {
|
|
75
|
+
name?: string;
|
|
76
|
+
managerID?: string | null;
|
|
77
|
+
code?: string;
|
|
78
|
+
remark?: string;
|
|
79
|
+
status?: number;
|
|
80
|
+
email?: string;
|
|
81
|
+
}
|
|
82
|
+
interface CreateUserInput {
|
|
83
|
+
loginName: string;
|
|
84
|
+
displayName?: string;
|
|
85
|
+
email?: string;
|
|
86
|
+
departmentIds?: string[];
|
|
87
|
+
code?: string;
|
|
88
|
+
position?: string;
|
|
89
|
+
remark?: string;
|
|
90
|
+
telNumber?: string;
|
|
91
|
+
priority?: number;
|
|
92
|
+
csfLevel?: number;
|
|
93
|
+
}
|
|
94
|
+
interface UpdateUserInput {
|
|
95
|
+
displayName?: string;
|
|
96
|
+
code?: string;
|
|
97
|
+
position?: string;
|
|
98
|
+
remark?: string;
|
|
99
|
+
email?: string;
|
|
100
|
+
telNumber?: string;
|
|
101
|
+
managerID?: string;
|
|
102
|
+
priority?: number;
|
|
103
|
+
csfLevel?: number;
|
|
104
|
+
}
|
|
105
|
+
interface AuditListOptions {
|
|
106
|
+
page?: number;
|
|
107
|
+
size?: number;
|
|
108
|
+
user?: string;
|
|
109
|
+
start?: string;
|
|
110
|
+
end?: string;
|
|
111
|
+
}
|
|
112
|
+
type MemberType = "user" | "department" | "group" | "app";
|
|
113
|
+
|
|
114
|
+
/** Build / render a department hierarchy from flat ISF search entries. */
|
|
115
|
+
|
|
116
|
+
interface OrgNode {
|
|
117
|
+
id: string;
|
|
118
|
+
name: string;
|
|
119
|
+
children: OrgNode[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
declare function admin(ctx: RequestContext): {
|
|
123
|
+
orgList: (opts?: AdminListOptions) => Promise<unknown>;
|
|
124
|
+
orgGet: (deptId: string) => Promise<unknown>;
|
|
125
|
+
orgMembers: (deptId: string, opts?: {
|
|
126
|
+
role?: string;
|
|
127
|
+
offset?: number;
|
|
128
|
+
limit?: number;
|
|
129
|
+
}) => Promise<unknown>;
|
|
130
|
+
orgTree: (role?: string) => Promise<OrgNode[]>;
|
|
131
|
+
orgCreate: (input: CreateOrgInput) => Promise<unknown>;
|
|
132
|
+
orgUpdate: (deptId: string, input: UpdateOrgInput) => Promise<unknown>;
|
|
133
|
+
orgDelete: (deptId: string) => Promise<unknown>;
|
|
134
|
+
userList: (opts?: AdminListOptions) => Promise<unknown>;
|
|
135
|
+
userGet: (userId: string) => Promise<unknown>;
|
|
136
|
+
userRoles: (userId: string) => Promise<unknown>;
|
|
137
|
+
userCreate: (input: CreateUserInput) => Promise<unknown>;
|
|
138
|
+
userUpdate: (userId: string, input: UpdateUserInput) => Promise<unknown>;
|
|
139
|
+
userDelete: (userId: string) => Promise<unknown>;
|
|
140
|
+
userResetPassword: (userId: string, newPassword: string) => Promise<unknown>;
|
|
141
|
+
roleList: (opts?: ListRolesOptions) => Promise<unknown>;
|
|
142
|
+
roleGet: (roleId: string) => Promise<unknown>;
|
|
143
|
+
roleMembers: (roleId: string, opts?: {
|
|
144
|
+
keyword?: string;
|
|
145
|
+
limit?: number;
|
|
146
|
+
}) => Promise<unknown>;
|
|
147
|
+
addRoleMember: (roleId: string, id: string, type?: MemberType) => Promise<unknown>;
|
|
148
|
+
removeRoleMember: (roleId: string, id: string, type?: MemberType) => Promise<unknown>;
|
|
149
|
+
auditList: (opts?: AuditListOptions) => Promise<unknown>;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
interface ChatResult {
|
|
153
|
+
text: string;
|
|
154
|
+
conversationId?: string;
|
|
155
|
+
}
|
|
156
|
+
interface SendChatOptions {
|
|
157
|
+
conversationId?: string;
|
|
158
|
+
stream?: boolean;
|
|
159
|
+
onDelta?: (text: string) => void;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Agent client (agent-factory v3). Read side + published listing, mirroring
|
|
164
|
+
* kweaver-sdk api/agent-list.ts. Responses passed through as parsed JSON.
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
interface ListAgentsOptions {
|
|
168
|
+
name?: string;
|
|
169
|
+
offset?: number;
|
|
170
|
+
limit?: number;
|
|
171
|
+
categoryId?: string;
|
|
172
|
+
customSpaceId?: string;
|
|
173
|
+
isToSquare?: number;
|
|
174
|
+
}
|
|
175
|
+
interface PagingOptions {
|
|
176
|
+
offset?: number;
|
|
177
|
+
limit?: number;
|
|
178
|
+
name?: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
declare function agents(ctx: RequestContext): {
|
|
182
|
+
list: (opts?: ListAgentsOptions) => Promise<unknown>;
|
|
183
|
+
get: (agentId: string) => Promise<unknown>;
|
|
184
|
+
getByKey: (key: string) => Promise<unknown>;
|
|
185
|
+
personalList: (opts?: PagingOptions) => Promise<unknown>;
|
|
186
|
+
templateList: (opts?: PagingOptions) => Promise<unknown>;
|
|
187
|
+
templateGet: (templateId: string) => Promise<unknown>;
|
|
188
|
+
categoryList: () => Promise<unknown>;
|
|
189
|
+
create: (body: unknown) => Promise<unknown>;
|
|
190
|
+
update: (agentId: string, body: unknown) => Promise<unknown>;
|
|
191
|
+
delete: (agentId: string) => Promise<unknown>;
|
|
192
|
+
publish: (agentId: string) => Promise<unknown>;
|
|
193
|
+
unpublish: (agentId: string) => Promise<unknown>;
|
|
194
|
+
sessions: (agentKey: string, opts?: {
|
|
195
|
+
page?: number;
|
|
196
|
+
size?: number;
|
|
197
|
+
}) => Promise<unknown>;
|
|
198
|
+
history: (agentKey: string, conversationId: string) => Promise<unknown>;
|
|
199
|
+
/** List skill ids attached to an agent (config.skills.skills). */
|
|
200
|
+
skillList: (agentId: string) => Promise<string[]>;
|
|
201
|
+
/** Attach skill(s) to an agent (dedup), then persist. */
|
|
202
|
+
skillAdd: (agentId: string, skillIds: string[]) => Promise<unknown>;
|
|
203
|
+
/** Detach skill(s) from an agent, then persist. */
|
|
204
|
+
skillRemove: (agentId: string, skillIds: string[]) => Promise<unknown>;
|
|
205
|
+
/** Send a chat turn to an agent (resolves agent id/key/version first). */
|
|
206
|
+
chat: (agentId: string, query: string, opts?: SendChatOptions & {
|
|
207
|
+
version?: string;
|
|
208
|
+
}) => Promise<ChatResult>;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Context-loader client over the agent-retrieval MCP endpoint (JSON-RPC).
|
|
213
|
+
* Reimplemented slim from kweaver-sdk: initialize → session id →
|
|
214
|
+
* notifications/initialized, then tools/call. Handles plain-JSON and
|
|
215
|
+
* SSE (`data:`) response bodies. Per-process session cache (5 min TTL).
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
interface SearchSchemaOptions {
|
|
219
|
+
searchScope?: string[];
|
|
220
|
+
maxConcepts?: number;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Context-loader resource surface (MCP over agent-retrieval). */
|
|
224
|
+
|
|
225
|
+
declare function context(ctx: RequestContext): {
|
|
226
|
+
searchSchema: (knId: string, query: string, opts?: SearchSchemaOptions) => Promise<unknown>;
|
|
227
|
+
queryObjectInstance: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
228
|
+
findSkills: (knId: string, objectTypeId: string, topK?: number) => Promise<unknown>;
|
|
229
|
+
tools: (knId: string) => Promise<unknown>;
|
|
230
|
+
toolCall: (knId: string, name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
231
|
+
queryInstanceSubgraph: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
232
|
+
logicProperties: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
233
|
+
actionInfo: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
234
|
+
resources: (knId: string) => Promise<unknown>;
|
|
235
|
+
resource: (knId: string, uri: string) => Promise<unknown>;
|
|
236
|
+
templates: (knId: string) => Promise<unknown>;
|
|
237
|
+
prompts: (knId: string) => Promise<unknown>;
|
|
238
|
+
prompt: (knId: string, name: string, args?: Record<string, unknown>) => Promise<unknown>;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
type TemplateType = "dataset" | "bkn" | "dataflow";
|
|
242
|
+
interface TemplateArg {
|
|
243
|
+
name: string;
|
|
244
|
+
required?: boolean;
|
|
245
|
+
description?: string;
|
|
246
|
+
type?: string;
|
|
247
|
+
default?: unknown;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Dataflow backend client (automation v2). Read endpoints (list/runs/logs) are
|
|
252
|
+
* implemented from kweaver-sdk; trigger/create bodies are deferred until the
|
|
253
|
+
* contract is verified on a live env. Responses passed through as parsed JSON.
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
interface ListRunsOptions {
|
|
257
|
+
since?: string;
|
|
258
|
+
}
|
|
259
|
+
interface LogsOptions {
|
|
260
|
+
page?: number;
|
|
261
|
+
limit?: number;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
declare function dataflows(ctx: RequestContext): {
|
|
265
|
+
list: () => Promise<unknown>;
|
|
266
|
+
runs: (dagId: string, opts?: ListRunsOptions) => Promise<unknown>;
|
|
267
|
+
logs: (dagId: string, instanceId: string, opts?: LogsOptions) => Promise<unknown>;
|
|
268
|
+
run: (dagId: string, url: string, name: string) => Promise<unknown>;
|
|
269
|
+
create: (body: unknown) => Promise<unknown>;
|
|
270
|
+
templates: () => {
|
|
271
|
+
type: TemplateType;
|
|
272
|
+
name: string;
|
|
273
|
+
description?: string;
|
|
274
|
+
arguments: TemplateArg[];
|
|
275
|
+
}[];
|
|
276
|
+
/** Instantiate a dataset template → create a vega resource. */
|
|
277
|
+
createDataset: (template: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
278
|
+
/** Instantiate a bkn template → create a knowledge network. */
|
|
279
|
+
createBkn: (template: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Knowledge-network backend client (ontology-manager + agent-retrieval).
|
|
284
|
+
* Endpoints mirror kweaver-sdk; responses are passed through as parsed JSON
|
|
285
|
+
* (shapes vary by backend version — validate at higher layers as needed).
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
interface ListKnOptions {
|
|
289
|
+
offset?: number;
|
|
290
|
+
limit?: number;
|
|
291
|
+
sort?: string;
|
|
292
|
+
direction?: "asc" | "desc";
|
|
293
|
+
namePattern?: string;
|
|
294
|
+
tag?: string;
|
|
295
|
+
}
|
|
296
|
+
interface GetKnOptions {
|
|
297
|
+
/** Return the full export payload. */
|
|
298
|
+
exportMode?: boolean;
|
|
299
|
+
/** Include statistics in the response. */
|
|
300
|
+
stats?: boolean;
|
|
301
|
+
}
|
|
302
|
+
interface CreateKnOptions {
|
|
303
|
+
name: string;
|
|
304
|
+
branch?: string;
|
|
305
|
+
baseBranch?: string;
|
|
306
|
+
}
|
|
307
|
+
interface ActionLogListOptions {
|
|
308
|
+
actionTypeId?: string;
|
|
309
|
+
status?: string;
|
|
310
|
+
triggerType?: string;
|
|
311
|
+
limit?: number;
|
|
312
|
+
needTotal?: boolean;
|
|
313
|
+
}
|
|
314
|
+
interface ListSchemaOptions {
|
|
315
|
+
branch?: string;
|
|
316
|
+
/** -1 = all (backend default). */
|
|
317
|
+
limit?: number;
|
|
318
|
+
}
|
|
319
|
+
interface SemanticSearchOptions {
|
|
320
|
+
mode?: string;
|
|
321
|
+
maxConcepts?: number;
|
|
322
|
+
returnQueryUnderstanding?: boolean;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface CreateFromCatalogOptions {
|
|
326
|
+
catalogId: string;
|
|
327
|
+
name: string;
|
|
328
|
+
tables?: string[];
|
|
329
|
+
pkMap?: Record<string, string>;
|
|
330
|
+
build?: boolean;
|
|
331
|
+
noRollback?: boolean;
|
|
332
|
+
/** Pre-fetched row samples per table (e.g. from a CSV import) for PK detection. */
|
|
333
|
+
sampleRows?: Record<string, Array<Record<string, string | null>>>;
|
|
334
|
+
onProgress?: (msg: string) => void;
|
|
335
|
+
}
|
|
336
|
+
interface CreateFromCsvOptions {
|
|
337
|
+
catalogId: string;
|
|
338
|
+
name: string;
|
|
339
|
+
files: string;
|
|
340
|
+
tablePrefix?: string;
|
|
341
|
+
batchSize?: number;
|
|
342
|
+
tables?: string[];
|
|
343
|
+
pkMap?: Record<string, string>;
|
|
344
|
+
build?: boolean;
|
|
345
|
+
noRollback?: boolean;
|
|
346
|
+
onProgress?: (msg: string) => void;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Knowledge-network resource surface (the exported SDK API). */
|
|
350
|
+
|
|
351
|
+
declare function kn(ctx: RequestContext): {
|
|
352
|
+
list: (opts?: ListKnOptions) => Promise<unknown>;
|
|
353
|
+
get: (knId: string, opts?: GetKnOptions) => Promise<unknown>;
|
|
354
|
+
search: (knId: string, query: string, opts?: SemanticSearchOptions) => Promise<unknown>;
|
|
355
|
+
create: (opts: CreateKnOptions) => Promise<unknown>;
|
|
356
|
+
update: (knId: string, body: unknown) => Promise<unknown>;
|
|
357
|
+
delete: (knId: string) => Promise<unknown>;
|
|
358
|
+
subgraph: (knId: string, body: unknown) => Promise<unknown>;
|
|
359
|
+
actionLogs: (knId: string, opts?: ActionLogListOptions) => Promise<unknown>;
|
|
360
|
+
actionLog: (knId: string, logId: string) => Promise<unknown>;
|
|
361
|
+
cancelActionLog: (knId: string, logId: string) => Promise<unknown>;
|
|
362
|
+
actionExecution: (knId: string, executionId: string) => Promise<unknown>;
|
|
363
|
+
metricQuery: (knId: string, metricId: string, body: unknown) => Promise<unknown>;
|
|
364
|
+
metricDryRun: (knId: string, body: unknown) => Promise<unknown>;
|
|
365
|
+
metricList: (knId: string, opts?: ListSchemaOptions) => Promise<unknown>;
|
|
366
|
+
metricGet: (knId: string, metricId: string) => Promise<unknown>;
|
|
367
|
+
metricCreate: (knId: string, body: unknown) => Promise<unknown>;
|
|
368
|
+
metricUpdate: (knId: string, metricId: string, body: unknown) => Promise<unknown>;
|
|
369
|
+
metricDelete: (knId: string, metricId: string) => Promise<unknown>;
|
|
370
|
+
metricSearch: (knId: string, body: unknown) => Promise<unknown>;
|
|
371
|
+
metricValidate: (knId: string, body: unknown) => Promise<unknown>;
|
|
372
|
+
objectTypes: (knId: string, opts?: ListSchemaOptions) => Promise<unknown>;
|
|
373
|
+
objectTypeQuery: (knId: string, otId: string, body: unknown) => Promise<unknown>;
|
|
374
|
+
objectTypeProperties: (knId: string, otId: string) => Promise<unknown>;
|
|
375
|
+
objectTypeGet: (knId: string, id: string) => Promise<unknown>;
|
|
376
|
+
objectTypeCreate: (knId: string, body: unknown) => Promise<unknown>;
|
|
377
|
+
objectTypeUpdate: (knId: string, id: string, body: unknown) => Promise<unknown>;
|
|
378
|
+
objectTypeDelete: (knId: string, id: string) => Promise<unknown>;
|
|
379
|
+
relationTypes: (knId: string, opts?: ListSchemaOptions) => Promise<unknown>;
|
|
380
|
+
relationTypeGet: (knId: string, id: string) => Promise<unknown>;
|
|
381
|
+
relationTypeCreate: (knId: string, body: unknown) => Promise<unknown>;
|
|
382
|
+
relationTypeUpdate: (knId: string, id: string, body: unknown) => Promise<unknown>;
|
|
383
|
+
relationTypeDelete: (knId: string, id: string) => Promise<unknown>;
|
|
384
|
+
actionTypes: (knId: string, opts?: ListSchemaOptions) => Promise<unknown>;
|
|
385
|
+
actionTypeQuery: (knId: string, atId: string, body: unknown) => Promise<unknown>;
|
|
386
|
+
actionTypeExecute: (knId: string, atId: string, body: unknown) => Promise<unknown>;
|
|
387
|
+
actionTypeInputs: (knId: string, atId: string) => Promise<unknown>;
|
|
388
|
+
actionTypeGet: (knId: string, id: string) => Promise<unknown>;
|
|
389
|
+
conceptGroups: (knId: string) => Promise<unknown>;
|
|
390
|
+
conceptGroup: (knId: string, cgId: string) => Promise<unknown>;
|
|
391
|
+
conceptGroupCreate: (knId: string, body: unknown) => Promise<unknown>;
|
|
392
|
+
conceptGroupUpdate: (knId: string, cgId: string, body: unknown) => Promise<unknown>;
|
|
393
|
+
conceptGroupDelete: (knId: string, cgId: string) => Promise<unknown>;
|
|
394
|
+
conceptGroupAddMembers: (knId: string, cgId: string, body: unknown) => Promise<unknown>;
|
|
395
|
+
conceptGroupRemoveMembers: (knId: string, cgId: string, otIds: string) => Promise<unknown>;
|
|
396
|
+
actionSchedules: (knId: string) => Promise<unknown>;
|
|
397
|
+
actionSchedule: (knId: string, scheduleId: string) => Promise<unknown>;
|
|
398
|
+
actionScheduleCreate: (knId: string, body: unknown) => Promise<unknown>;
|
|
399
|
+
actionScheduleUpdate: (knId: string, scheduleId: string, body: unknown) => Promise<unknown>;
|
|
400
|
+
actionScheduleSetStatus: (knId: string, scheduleId: string, body: unknown) => Promise<unknown>;
|
|
401
|
+
actionScheduleDelete: (knId: string, ids: string) => Promise<unknown>;
|
|
402
|
+
jobs: (knId: string) => Promise<unknown>;
|
|
403
|
+
job: (knId: string, jobId: string) => Promise<unknown>;
|
|
404
|
+
jobTasks: (knId: string, jobId: string) => Promise<unknown>;
|
|
405
|
+
jobDelete: (knId: string, ids: string) => Promise<unknown>;
|
|
406
|
+
relationTypePaths: (knId: string, body: unknown) => Promise<unknown>;
|
|
407
|
+
bknResources: () => Promise<unknown>;
|
|
408
|
+
createFromCatalog: (opts: CreateFromCatalogOptions) => Promise<unknown>;
|
|
409
|
+
createFromCsv: (opts: CreateFromCsvOptions) => Promise<unknown>;
|
|
410
|
+
/** Pack a local BKN directory and upload it as a knowledge network. */
|
|
411
|
+
push: (dir: string, opts?: {
|
|
412
|
+
branch?: string;
|
|
413
|
+
}) => Promise<unknown>;
|
|
414
|
+
/** Download a knowledge network and extract it into a local directory. */
|
|
415
|
+
pull: (knId: string, dir: string, opts?: {
|
|
416
|
+
branch?: string;
|
|
417
|
+
}) => Promise<{
|
|
418
|
+
knId: string;
|
|
419
|
+
dir: string;
|
|
420
|
+
bytes: number;
|
|
421
|
+
}>;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
interface ListModelsOptions {
|
|
425
|
+
page?: number;
|
|
426
|
+
limit?: number;
|
|
427
|
+
name?: string;
|
|
428
|
+
modelType?: string;
|
|
429
|
+
}
|
|
430
|
+
interface ChatMessage {
|
|
431
|
+
role: string;
|
|
432
|
+
content: string;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Model-factory resource surface: management reads + runtime invocation. */
|
|
436
|
+
|
|
437
|
+
declare function models(ctx: RequestContext): {
|
|
438
|
+
llm: {
|
|
439
|
+
list: (opts?: ListModelsOptions) => Promise<unknown>;
|
|
440
|
+
get: (modelId: string) => Promise<unknown>;
|
|
441
|
+
chat: (modelId: string, messages: ChatMessage[]) => Promise<unknown>;
|
|
442
|
+
chatStream: (modelId: string, messages: ChatMessage[], onDelta: (t: string) => void) => Promise<string>;
|
|
443
|
+
add: (body: unknown) => Promise<unknown>;
|
|
444
|
+
edit: (body: unknown) => Promise<unknown>;
|
|
445
|
+
delete: (modelIds: string[]) => Promise<unknown>;
|
|
446
|
+
test: (body: unknown) => Promise<unknown>;
|
|
447
|
+
};
|
|
448
|
+
small: {
|
|
449
|
+
list: (opts?: ListModelsOptions) => Promise<unknown>;
|
|
450
|
+
get: (modelId: string) => Promise<unknown>;
|
|
451
|
+
embeddings: (modelId: string, input: string[]) => Promise<unknown>;
|
|
452
|
+
rerank: (modelId: string, query: string, documents: string[]) => Promise<unknown>;
|
|
453
|
+
add: (body: unknown) => Promise<unknown>;
|
|
454
|
+
edit: (body: unknown) => Promise<unknown>;
|
|
455
|
+
delete: (modelIds: string[]) => Promise<unknown>;
|
|
456
|
+
test: (body: unknown) => Promise<unknown>;
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Vega-backend resource client (list/find/get/query/delete). Endpoints mirror
|
|
462
|
+
* kweaver-sdk `api/resources.ts`. Responses passed through as parsed JSON.
|
|
463
|
+
*/
|
|
464
|
+
|
|
465
|
+
interface ListResourcesOptions {
|
|
466
|
+
datasourceId?: string;
|
|
467
|
+
name?: string;
|
|
468
|
+
/** Resource category, e.g. table | logicview. */
|
|
469
|
+
category?: string;
|
|
470
|
+
limit?: number;
|
|
471
|
+
}
|
|
472
|
+
interface FindResourceOptions {
|
|
473
|
+
datasourceId?: string;
|
|
474
|
+
/** Exact name match instead of fuzzy. */
|
|
475
|
+
exact?: boolean;
|
|
476
|
+
}
|
|
477
|
+
interface QueryResourceOptions {
|
|
478
|
+
limit?: number;
|
|
479
|
+
offset?: number;
|
|
480
|
+
needTotal?: boolean;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Resource surface (the exported SDK API) over vega-backend resources. */
|
|
484
|
+
|
|
485
|
+
declare function resources(ctx: RequestContext): {
|
|
486
|
+
list: (opts?: ListResourcesOptions) => Promise<unknown>;
|
|
487
|
+
get: (id: string) => Promise<unknown>;
|
|
488
|
+
delete: (id: string) => Promise<unknown>;
|
|
489
|
+
find: (name: string, opts?: FindResourceOptions) => Promise<unknown>;
|
|
490
|
+
query: (id: string, opts?: QueryResourceOptions) => Promise<unknown>;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
interface ListSkillsOptions {
|
|
494
|
+
page?: number;
|
|
495
|
+
pageSize?: number;
|
|
496
|
+
name?: string;
|
|
497
|
+
source?: string;
|
|
498
|
+
status?: string;
|
|
499
|
+
createUser?: string;
|
|
500
|
+
}
|
|
501
|
+
type SkillStatus = "unpublish" | "published" | "offline";
|
|
502
|
+
|
|
503
|
+
declare function skills(ctx: RequestContext): {
|
|
504
|
+
list: (opts?: ListSkillsOptions) => Promise<unknown>;
|
|
505
|
+
get: (skillId: string) => Promise<unknown>;
|
|
506
|
+
market: (opts?: ListSkillsOptions) => Promise<unknown>;
|
|
507
|
+
marketGet: (skillId: string) => Promise<unknown>;
|
|
508
|
+
delete: (skillId: string) => Promise<unknown>;
|
|
509
|
+
content: (skillId: string) => Promise<unknown>;
|
|
510
|
+
readFile: (skillId: string, relPath: string) => Promise<unknown>;
|
|
511
|
+
history: (skillId: string) => Promise<unknown>;
|
|
512
|
+
setStatus: (skillId: string, status: SkillStatus) => Promise<unknown>;
|
|
513
|
+
updateMetadata: (skillId: string, body: unknown) => Promise<unknown>;
|
|
514
|
+
republish: (skillId: string, version: string) => Promise<unknown>;
|
|
515
|
+
publishHistory: (skillId: string, version: string) => Promise<unknown>;
|
|
516
|
+
/** Zip a local skill directory and register it. */
|
|
517
|
+
register: (dir: string, opts?: {
|
|
518
|
+
source?: string;
|
|
519
|
+
extendInfo?: unknown;
|
|
520
|
+
}) => Promise<unknown>;
|
|
521
|
+
/** Replace a skill's package from a local directory. */
|
|
522
|
+
updatePackage: (skillId: string, dir: string) => Promise<unknown>;
|
|
523
|
+
/** Download a skill archive to a local .zip file. */
|
|
524
|
+
download: (skillId: string, outPath?: string) => Promise<{
|
|
525
|
+
skillId: string;
|
|
526
|
+
path: string;
|
|
527
|
+
bytes: number;
|
|
528
|
+
}>;
|
|
529
|
+
/** Download a skill archive and extract it into a directory. */
|
|
530
|
+
install: (skillId: string, dir?: string) => Promise<{
|
|
531
|
+
skillId: string;
|
|
532
|
+
dir: string;
|
|
533
|
+
files: number;
|
|
534
|
+
}>;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
type ImpexType = "toolbox" | "mcp" | "operator";
|
|
538
|
+
interface ListToolboxesOptions {
|
|
539
|
+
keyword?: string;
|
|
540
|
+
limit?: number;
|
|
541
|
+
offset?: number;
|
|
542
|
+
}
|
|
543
|
+
interface CreateToolboxOptions {
|
|
544
|
+
name: string;
|
|
545
|
+
serviceUrl: string;
|
|
546
|
+
description?: string;
|
|
547
|
+
source?: string;
|
|
548
|
+
}
|
|
549
|
+
interface ToolInvokeEnvelope {
|
|
550
|
+
header?: Record<string, unknown>;
|
|
551
|
+
query?: Record<string, unknown>;
|
|
552
|
+
path?: Record<string, unknown>;
|
|
553
|
+
body?: unknown;
|
|
554
|
+
timeout?: number;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
declare function toolboxes(ctx: RequestContext): {
|
|
558
|
+
list: (opts?: ListToolboxesOptions) => Promise<unknown>;
|
|
559
|
+
tools: (boxId: string) => Promise<unknown>;
|
|
560
|
+
create: (opts: CreateToolboxOptions) => Promise<unknown>;
|
|
561
|
+
delete: (boxId: string) => Promise<unknown>;
|
|
562
|
+
publish: (boxId: string) => Promise<unknown>;
|
|
563
|
+
unpublish: (boxId: string) => Promise<unknown>;
|
|
564
|
+
setToolStatus: (boxId: string, toolIds: string[], status: "enabled" | "disabled") => Promise<unknown>;
|
|
565
|
+
upload: (boxId: string, filePath: string, metadataType?: string) => Promise<unknown>;
|
|
566
|
+
/** Export a toolbox config to a local `.adp` file. */
|
|
567
|
+
export: (id: string, outPath: string, type?: ImpexType) => Promise<{
|
|
568
|
+
id: string;
|
|
569
|
+
path: string;
|
|
570
|
+
bytes: number;
|
|
571
|
+
}>;
|
|
572
|
+
/** Import a toolbox config from a local `.adp` file. */
|
|
573
|
+
import: (filePath: string, type?: ImpexType) => Promise<unknown>;
|
|
574
|
+
execute: (boxId: string, toolId: string, e?: ToolInvokeEnvelope) => Promise<unknown>;
|
|
575
|
+
debug: (boxId: string, toolId: string, e?: ToolInvokeEnvelope) => Promise<unknown>;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Trace diagnose engine. Fetches a conversation's spans, shapes them into a
|
|
580
|
+
* trace tree, runs deterministic symbolic predicates, and (in hybrid mode) adds
|
|
581
|
+
* gated LLM-judged rubric findings + an LLM synthesized summary. Cross-trace
|
|
582
|
+
* `scan` is the remaining piece (see docs/exec-plans/tech-debt-tracker.md).
|
|
583
|
+
*/
|
|
584
|
+
|
|
585
|
+
interface Finding {
|
|
586
|
+
ruleId: string;
|
|
587
|
+
judgmentKind: "symbolic" | "rubric";
|
|
588
|
+
severity: "low" | "medium" | "high";
|
|
589
|
+
symptom: string;
|
|
590
|
+
evidence: {
|
|
591
|
+
spans: string[];
|
|
592
|
+
excerpt: string;
|
|
593
|
+
};
|
|
594
|
+
suggestedFix: {
|
|
595
|
+
target: string;
|
|
596
|
+
change: string;
|
|
597
|
+
};
|
|
598
|
+
confidence?: "low" | "medium" | "high";
|
|
599
|
+
}
|
|
600
|
+
interface Summary {
|
|
601
|
+
headline: string;
|
|
602
|
+
primaryRootCause: string | null;
|
|
603
|
+
targetForFix: string | null;
|
|
604
|
+
}
|
|
605
|
+
interface DiagnoseReport {
|
|
606
|
+
traceId: string;
|
|
607
|
+
conversationId: string;
|
|
608
|
+
diagnosedAt: string | null;
|
|
609
|
+
mode: "symbolic-only" | "hybrid";
|
|
610
|
+
rulesApplied: string[];
|
|
611
|
+
findingCount: number;
|
|
612
|
+
summary?: Summary;
|
|
613
|
+
findings: Finding[];
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Trace eval-set — build a set of evaluation cases and run them against a live
|
|
618
|
+
* agent. Each case is {query, assertions[]}; `test` runs the query through the
|
|
619
|
+
* agent, fetches the resulting trace, and checks each assertion. Deterministic
|
|
620
|
+
* assertion kinds (contains, regex, tool-call count/order, latency) need no LLM;
|
|
621
|
+
* `semantic_match` reuses the local-claude judge. Builder lifts cases from a
|
|
622
|
+
* queries file (JSON). The diagnosis-report lift + YAML shards + redaction from
|
|
623
|
+
* kweaver-sdk are deferred — see tech-debt.
|
|
624
|
+
*/
|
|
625
|
+
|
|
626
|
+
type AssertionType = "contains" | "not_contains" | "regex" | "tool_call_count" | "tool_call_order" | "latency_ms" | "semantic_match";
|
|
627
|
+
interface EvalAssertion {
|
|
628
|
+
type: AssertionType;
|
|
629
|
+
[key: string]: unknown;
|
|
630
|
+
}
|
|
631
|
+
interface EvalCase {
|
|
632
|
+
query_id: string;
|
|
633
|
+
input: {
|
|
634
|
+
user_message: string;
|
|
635
|
+
};
|
|
636
|
+
reference?: {
|
|
637
|
+
answer: string;
|
|
638
|
+
};
|
|
639
|
+
assertions?: EvalAssertion[];
|
|
640
|
+
tags?: string[];
|
|
641
|
+
}
|
|
642
|
+
interface AssertionResult {
|
|
643
|
+
type: AssertionType;
|
|
644
|
+
verdict: "pass" | "fail" | "skip";
|
|
645
|
+
actual?: unknown;
|
|
646
|
+
reason?: string;
|
|
647
|
+
}
|
|
648
|
+
interface CaseResult {
|
|
649
|
+
queryId: string;
|
|
650
|
+
query: string;
|
|
651
|
+
answer: string;
|
|
652
|
+
conversationId: string | null;
|
|
653
|
+
assertions: AssertionResult[];
|
|
654
|
+
errorCode?: string;
|
|
655
|
+
}
|
|
656
|
+
interface EvalSetResult {
|
|
657
|
+
agentId: string;
|
|
658
|
+
total: number;
|
|
659
|
+
passed: number;
|
|
660
|
+
failed: number;
|
|
661
|
+
skipped: number;
|
|
662
|
+
cases: CaseResult[];
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
declare function trace(ctx: RequestContext): {
|
|
666
|
+
/** Raw trace search (OpenSearch-style body). */
|
|
667
|
+
search: (body: unknown) => Promise<unknown>;
|
|
668
|
+
/** All span source docs for a conversation. */
|
|
669
|
+
spans: (conversationId: string, opts?: {
|
|
670
|
+
maxTraceIds?: number;
|
|
671
|
+
maxSpans?: number;
|
|
672
|
+
}) => Promise<Record<string, unknown>[]>;
|
|
673
|
+
diagnose: (conversationId: string, opts?: {
|
|
674
|
+
llm?: boolean;
|
|
675
|
+
judgeTimeoutMs?: number;
|
|
676
|
+
}) => Promise<DiagnoseReport>;
|
|
677
|
+
/**
|
|
678
|
+
* Scan (batch-diagnose) several conversations and aggregate the findings:
|
|
679
|
+
* per-trace reports + a recurring-rule tally across the batch.
|
|
680
|
+
*/
|
|
681
|
+
scan: (conversationIds: string[], opts?: {
|
|
682
|
+
llm?: boolean;
|
|
683
|
+
judgeTimeoutMs?: number;
|
|
684
|
+
}) => Promise<{
|
|
685
|
+
scanned: number;
|
|
686
|
+
totalFindings: number;
|
|
687
|
+
recurringRules: {
|
|
688
|
+
ruleId: string;
|
|
689
|
+
count: number;
|
|
690
|
+
}[];
|
|
691
|
+
reports: (DiagnoseReport | {
|
|
692
|
+
conversationId: string;
|
|
693
|
+
error: string;
|
|
694
|
+
})[];
|
|
695
|
+
}>;
|
|
696
|
+
/** Build eval cases from a loosely-shaped queries object/array. */
|
|
697
|
+
evalSetBuild: (raw: unknown) => EvalCase[];
|
|
698
|
+
/**
|
|
699
|
+
* Run an eval set against an agent: each case's query is sent to the agent,
|
|
700
|
+
* the resulting trace is fetched, and assertions are checked. `llm` enables
|
|
701
|
+
* `semantic_match` assertions via the local claude judge.
|
|
702
|
+
*/
|
|
703
|
+
evalSetTest: (agentId: string, cases: EvalCase[], opts?: {
|
|
704
|
+
version?: string;
|
|
705
|
+
llm?: boolean;
|
|
706
|
+
}) => Promise<EvalSetResult>;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Vega backend client — catalog/resource reads + BuildTask (index build).
|
|
711
|
+
* Build config lives on the task (CreateBuildTaskRequest), per the platform model.
|
|
712
|
+
*/
|
|
713
|
+
|
|
714
|
+
declare const BuildMode: z.ZodEnum<["batch", "streaming"]>;
|
|
715
|
+
type BuildMode = z.infer<typeof BuildMode>;
|
|
716
|
+
/** POST /build-tasks body. */
|
|
717
|
+
declare const CreateBuildTaskRequest: z.ZodObject<{
|
|
718
|
+
resource_id: z.ZodString;
|
|
719
|
+
mode: z.ZodEnum<["batch", "streaming"]>;
|
|
720
|
+
embedding_fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
721
|
+
build_key_fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
722
|
+
embedding_model: z.ZodOptional<z.ZodString>;
|
|
723
|
+
model_dimensions: z.ZodOptional<z.ZodNumber>;
|
|
724
|
+
}, "strip", z.ZodTypeAny, {
|
|
725
|
+
mode: "batch" | "streaming";
|
|
726
|
+
resource_id: string;
|
|
727
|
+
embedding_fields?: string[] | undefined;
|
|
728
|
+
build_key_fields?: string[] | undefined;
|
|
729
|
+
embedding_model?: string | undefined;
|
|
730
|
+
model_dimensions?: number | undefined;
|
|
731
|
+
}, {
|
|
732
|
+
mode: "batch" | "streaming";
|
|
733
|
+
resource_id: string;
|
|
734
|
+
embedding_fields?: string[] | undefined;
|
|
735
|
+
build_key_fields?: string[] | undefined;
|
|
736
|
+
embedding_model?: string | undefined;
|
|
737
|
+
model_dimensions?: number | undefined;
|
|
738
|
+
}>;
|
|
739
|
+
type CreateBuildTaskRequest = z.infer<typeof CreateBuildTaskRequest>;
|
|
740
|
+
declare const BuildTask: z.ZodObject<{
|
|
741
|
+
id: z.ZodString;
|
|
742
|
+
resource_id: z.ZodString;
|
|
743
|
+
mode: z.ZodEnum<["batch", "streaming"]>;
|
|
744
|
+
state: z.ZodOptional<z.ZodString>;
|
|
745
|
+
synced_count: z.ZodOptional<z.ZodNumber>;
|
|
746
|
+
vectorized_count: z.ZodOptional<z.ZodNumber>;
|
|
747
|
+
}, "strip", z.ZodTypeAny, {
|
|
748
|
+
mode: "batch" | "streaming";
|
|
749
|
+
id: string;
|
|
750
|
+
resource_id: string;
|
|
751
|
+
state?: string | undefined;
|
|
752
|
+
synced_count?: number | undefined;
|
|
753
|
+
vectorized_count?: number | undefined;
|
|
754
|
+
}, {
|
|
755
|
+
mode: "batch" | "streaming";
|
|
756
|
+
id: string;
|
|
757
|
+
resource_id: string;
|
|
758
|
+
state?: string | undefined;
|
|
759
|
+
synced_count?: number | undefined;
|
|
760
|
+
vectorized_count?: number | undefined;
|
|
761
|
+
}>;
|
|
762
|
+
type BuildTask = z.infer<typeof BuildTask>;
|
|
763
|
+
interface ListCatalogsOptions {
|
|
764
|
+
limit?: number;
|
|
765
|
+
offset?: number;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
declare function vega(ctx: RequestContext): {
|
|
769
|
+
catalogs: (opts?: ListCatalogsOptions) => Promise<unknown>;
|
|
770
|
+
getCatalog: (id: string) => Promise<unknown>;
|
|
771
|
+
catalogResources: (id: string, category?: string) => Promise<unknown>;
|
|
772
|
+
catalogHealth: (ids: string[]) => Promise<unknown>;
|
|
773
|
+
connectorTypes: () => Promise<unknown>;
|
|
774
|
+
connectorType: (type: string) => Promise<unknown>;
|
|
775
|
+
/** Build a resource's index. With `wait`, polls until terminal. */
|
|
776
|
+
build: (req: CreateBuildTaskRequest, opts?: {
|
|
777
|
+
wait?: boolean;
|
|
778
|
+
timeoutMs?: number;
|
|
779
|
+
intervalMs?: number;
|
|
780
|
+
}) => Promise<BuildTask>;
|
|
781
|
+
buildStatus: (taskId: string) => Promise<{
|
|
782
|
+
mode: "batch" | "streaming";
|
|
783
|
+
id: string;
|
|
784
|
+
resource_id: string;
|
|
785
|
+
state?: string | undefined;
|
|
786
|
+
synced_count?: number | undefined;
|
|
787
|
+
vectorized_count?: number | undefined;
|
|
788
|
+
}>;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
interface BknClient {
|
|
792
|
+
readonly ctx: RequestContext;
|
|
793
|
+
readonly kn: ReturnType<typeof kn>;
|
|
794
|
+
readonly resource: ReturnType<typeof resources>;
|
|
795
|
+
readonly dataflows: ReturnType<typeof dataflows>;
|
|
796
|
+
readonly agents: ReturnType<typeof agents>;
|
|
797
|
+
readonly context: ReturnType<typeof context>;
|
|
798
|
+
readonly models: ReturnType<typeof models>;
|
|
799
|
+
readonly skills: ReturnType<typeof skills>;
|
|
800
|
+
readonly toolboxes: ReturnType<typeof toolboxes>;
|
|
801
|
+
readonly trace: ReturnType<typeof trace>;
|
|
802
|
+
readonly admin: ReturnType<typeof admin>;
|
|
803
|
+
readonly vega: ReturnType<typeof vega>;
|
|
804
|
+
/** Raw API passthrough (the `call` escape hatch). */
|
|
805
|
+
call(path: string, opts?: RawCallOptions): Promise<RawCallResult>;
|
|
806
|
+
}
|
|
807
|
+
declare function createClient(opts?: ClientOptions): BknClient;
|
|
808
|
+
|
|
809
|
+
/** Typed errors and their mapping to user-facing messages + exit codes. */
|
|
810
|
+
/** Raised when an HTTP request returns a non-2xx status. */
|
|
811
|
+
declare class HttpError extends Error {
|
|
812
|
+
readonly status: number;
|
|
813
|
+
readonly statusText: string;
|
|
814
|
+
readonly body: string;
|
|
815
|
+
constructor(status: number, statusText: string, body: string);
|
|
816
|
+
}
|
|
817
|
+
/** Raised for bad CLI/SDK input before any request is made. */
|
|
818
|
+
declare class InputError extends Error {
|
|
819
|
+
constructor(message: string);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Minimal JWT payload decoder — base64url decode only, NO signature check.
|
|
824
|
+
* Used to surface identity (sub / username / email) from a stored token.
|
|
825
|
+
* Never trust this for authorization decisions; it is display-only.
|
|
826
|
+
*/
|
|
827
|
+
interface JwtClaims {
|
|
828
|
+
sub?: string;
|
|
829
|
+
name?: string;
|
|
830
|
+
preferred_username?: string;
|
|
831
|
+
email?: string;
|
|
832
|
+
exp?: number;
|
|
833
|
+
[key: string]: unknown;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
interface TokenConfig {
|
|
837
|
+
baseUrl: string;
|
|
838
|
+
accessToken: string;
|
|
839
|
+
refreshToken?: string;
|
|
840
|
+
idToken?: string;
|
|
841
|
+
expiresAt?: string;
|
|
842
|
+
/** Skip TLS verification for this platform (saved by `auth login -k`). */
|
|
843
|
+
tlsInsecure?: boolean;
|
|
844
|
+
/** Login name persisted at login time (fallback when JWT lacks claims). */
|
|
845
|
+
username?: string;
|
|
846
|
+
/** Human-readable name from userinfo. */
|
|
847
|
+
displayName?: string;
|
|
848
|
+
}
|
|
849
|
+
/** userId from the token's JWT `sub` (id_token first), else "default". */
|
|
850
|
+
declare function userIdFromToken(token: TokenConfig): string;
|
|
851
|
+
interface PlatformUser {
|
|
852
|
+
userId: string;
|
|
853
|
+
username?: string;
|
|
854
|
+
displayName?: string;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Auth resource — credential store + identity (multi-user, store-backed).
|
|
859
|
+
* Interactive browser/password OAuth lives in `auth/oauth.ts` and is persisted
|
|
860
|
+
* here via `attachToken`.
|
|
861
|
+
*/
|
|
862
|
+
|
|
863
|
+
declare function hostOf(baseUrl: string): string;
|
|
864
|
+
/** Save a token (under its derived user) and make it the active platform/user. */
|
|
865
|
+
declare function attachToken(baseUrl: string, accessToken: string, opts?: {
|
|
866
|
+
refreshToken?: string;
|
|
867
|
+
idToken?: string;
|
|
868
|
+
insecure?: boolean;
|
|
869
|
+
}): {
|
|
870
|
+
baseUrl: string;
|
|
871
|
+
userId: string;
|
|
872
|
+
username?: string;
|
|
873
|
+
};
|
|
874
|
+
interface AuthStatus {
|
|
875
|
+
baseUrl?: string;
|
|
876
|
+
userId?: string;
|
|
877
|
+
hasToken: boolean;
|
|
878
|
+
username?: string;
|
|
879
|
+
expired?: boolean;
|
|
880
|
+
}
|
|
881
|
+
declare function status(): AuthStatus;
|
|
882
|
+
declare function currentToken(): string;
|
|
883
|
+
declare function whoami(): JwtClaims;
|
|
884
|
+
interface PlatformListItem {
|
|
885
|
+
baseUrl: string;
|
|
886
|
+
userId: string;
|
|
887
|
+
username?: string;
|
|
888
|
+
active: boolean;
|
|
889
|
+
}
|
|
890
|
+
/** Flat list of platform/user pairs with a saved session. */
|
|
891
|
+
declare function listPlatforms(): PlatformListItem[];
|
|
892
|
+
/** Switch the active platform (must already have a saved token). */
|
|
893
|
+
declare function use(baseUrl: string): void;
|
|
894
|
+
declare function logout(): boolean;
|
|
895
|
+
declare function deletePlatform(baseUrl: string, userId?: string): boolean;
|
|
896
|
+
/** Switch the active user for a platform (token must already be saved). */
|
|
897
|
+
declare function switchUser(baseUrl: string, userId: string): {
|
|
898
|
+
baseUrl: string;
|
|
899
|
+
userId: string;
|
|
900
|
+
};
|
|
901
|
+
/** List saved user profiles for one platform. */
|
|
902
|
+
declare function usersOf(baseUrl: string): PlatformUser[];
|
|
903
|
+
/** Export the active session's tokens (for seeding a headless host). */
|
|
904
|
+
declare function exportCreds(): {
|
|
905
|
+
baseUrl: string;
|
|
906
|
+
accessToken: string;
|
|
907
|
+
refreshToken?: string;
|
|
908
|
+
idToken?: string;
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
type auth_AuthStatus = AuthStatus;
|
|
912
|
+
type auth_PlatformListItem = PlatformListItem;
|
|
913
|
+
declare const auth_attachToken: typeof attachToken;
|
|
914
|
+
declare const auth_currentToken: typeof currentToken;
|
|
915
|
+
declare const auth_deletePlatform: typeof deletePlatform;
|
|
916
|
+
declare const auth_exportCreds: typeof exportCreds;
|
|
917
|
+
declare const auth_hostOf: typeof hostOf;
|
|
918
|
+
declare const auth_listPlatforms: typeof listPlatforms;
|
|
919
|
+
declare const auth_logout: typeof logout;
|
|
920
|
+
declare const auth_status: typeof status;
|
|
921
|
+
declare const auth_switchUser: typeof switchUser;
|
|
922
|
+
declare const auth_use: typeof use;
|
|
923
|
+
declare const auth_userIdFromToken: typeof userIdFromToken;
|
|
924
|
+
declare const auth_usersOf: typeof usersOf;
|
|
925
|
+
declare const auth_whoami: typeof whoami;
|
|
926
|
+
declare namespace auth {
|
|
927
|
+
export { type auth_AuthStatus as AuthStatus, type auth_PlatformListItem as PlatformListItem, auth_attachToken as attachToken, auth_currentToken as currentToken, auth_deletePlatform as deletePlatform, auth_exportCreds as exportCreds, auth_hostOf as hostOf, auth_listPlatforms as listPlatforms, auth_logout as logout, auth_status as status, auth_switchUser as switchUser, auth_use as use, auth_userIdFromToken as userIdFromToken, auth_usersOf as usersOf, auth_whoami as whoami };
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Thin fetch wrapper: explicit timeout, auth headers, JSON in/out, typed errors.
|
|
932
|
+
* The single choke point for every backend call — resources build on this.
|
|
933
|
+
*/
|
|
934
|
+
|
|
935
|
+
interface RequestInitEx {
|
|
936
|
+
method?: string;
|
|
937
|
+
/** JSON body — serialized and Content-Type set automatically. */
|
|
938
|
+
body?: unknown;
|
|
939
|
+
/** Query params appended to the path. */
|
|
940
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
941
|
+
headers?: Record<string, string>;
|
|
942
|
+
/** Per-request timeout; defaults to 30s. */
|
|
943
|
+
timeoutMs?: number;
|
|
944
|
+
}
|
|
945
|
+
declare function request<T = unknown>(ctx: RequestContext, path: string, init?: RequestInitEx): Promise<T>;
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* Resolve a full RequestContext from explicit options → env → store.
|
|
949
|
+
* Order: caller options win, then env vars, then the active platform/user
|
|
950
|
+
* in `~/.bkn/`.
|
|
951
|
+
*/
|
|
952
|
+
|
|
953
|
+
declare function resolveContext(opts?: ClientOptions): RequestContext;
|
|
954
|
+
|
|
955
|
+
export { type BknClient, BuildMode, BuildTask, type ClientOptions, CreateBuildTaskRequest, DEFAULT_BUSINESS_DOMAIN, DEFAULT_LIST_LIMIT, DEFAULT_QUERY_LIMIT, HttpError, InputError, type RequestContext, admin, agents, auth, context, createClient, dataflows, kn, models, request, resolveContext, resources, skills, toolboxes, trace, vega };
|