@kweaver-ai/kweaver-sdk 0.8.2 → 0.8.3
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 +26 -52
- package/README.zh.md +27 -46
- package/dist/api/resources.d.ts +94 -0
- package/dist/api/resources.js +166 -0
- package/dist/cli.js +102 -10
- package/dist/client.d.ts +3 -3
- package/dist/client.js +5 -5
- package/dist/commands/agent-members.js +27 -11
- package/dist/commands/agent.js +383 -272
- package/dist/commands/auth.js +184 -71
- package/dist/commands/bkn-metric.js +37 -16
- package/dist/commands/bkn-ops.js +164 -86
- package/dist/commands/bkn-query.js +99 -31
- package/dist/commands/bkn-schema.d.ts +3 -3
- package/dist/commands/bkn-schema.js +127 -86
- package/dist/commands/bkn.js +153 -114
- package/dist/commands/call.js +23 -13
- package/dist/commands/config.js +22 -12
- package/dist/commands/context-loader.js +98 -92
- package/dist/commands/dataflow.js +14 -6
- package/dist/commands/ds.js +52 -30
- package/dist/commands/explore.js +18 -15
- package/dist/commands/model.js +53 -42
- package/dist/commands/resource.d.ts +1 -0
- package/dist/commands/{dataview.js → resource.js} +62 -84
- package/dist/commands/skill.js +201 -65
- package/dist/commands/token.js +11 -0
- package/dist/commands/tool.js +46 -29
- package/dist/commands/toolbox.js +31 -15
- package/dist/commands/vega.js +466 -250
- package/dist/help/format.d.ts +65 -0
- package/dist/help/format.js +141 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/resources/{dataviews.d.ts → resources.d.ts} +10 -11
- package/dist/resources/{dataviews.js → resources.js} +12 -13
- package/package.json +1 -1
- package/dist/api/dataviews.d.ts +0 -117
- package/dist/api/dataviews.js +0 -265
- package/dist/commands/dataview.d.ts +0 -8
package/README.md
CHANGED
|
@@ -126,23 +126,19 @@ const graph = await client.bkn.querySubgraph("bkn-id", { /* path spec */ });
|
|
|
126
126
|
await client.bkn.executeAction("bkn-id", "at-id", { /* params */ });
|
|
127
127
|
const logs = await client.bkn.listActionLogs("bkn-id");
|
|
128
128
|
|
|
129
|
-
// Data sources &
|
|
129
|
+
// Data sources & vega-backend resources
|
|
130
130
|
const dsList = await client.datasources.list();
|
|
131
131
|
const tables = await client.datasources.listTables("ds-id");
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const fuzzy
|
|
135
|
-
const exact
|
|
132
|
+
const resId = await client.resources.create({ name: "v", datasourceId: "ds-id", table: "orders" });
|
|
133
|
+
const resList = await client.resources.list({ datasourceId: "ds-id" });
|
|
134
|
+
const fuzzy = await client.resources.find("BOM", { wait: false });
|
|
135
|
+
const exact = await client.resources.find("orders", {
|
|
136
136
|
datasourceId: "ds-id",
|
|
137
137
|
exact: true,
|
|
138
138
|
wait: true,
|
|
139
139
|
});
|
|
140
|
-
const
|
|
141
|
-
const queryRows = await client.
|
|
142
|
-
sql: "SELECT id, name FROM orders LIMIT 10",
|
|
143
|
-
limit: 10,
|
|
144
|
-
needTotal: true,
|
|
145
|
-
});
|
|
140
|
+
const res = await client.resources.get(resId);
|
|
141
|
+
const queryRows = await client.resources.query(resId, { limit: 10, needTotal: true });
|
|
146
142
|
|
|
147
143
|
// Dataflow automation (CSV import pipeline, etc.)
|
|
148
144
|
const result = await client.dataflows.execute({
|
|
@@ -190,50 +186,28 @@ Use `callTool(name, args)` when you need native MCP `tools/call` access for newl
|
|
|
190
186
|
|
|
191
187
|
## CLI Reference
|
|
192
188
|
|
|
189
|
+
`kweaver` follows a `gh`-style help layout (see [docs/cli_conventions.md §8](../../docs/cli_conventions.md#8-help-文本格式must)):
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
kweaver [--help|-h] # gh-style top-level overview
|
|
193
|
+
kweaver help <command> # forward to <command> --help
|
|
194
|
+
kweaver help all # full per-action signatures (migration fallback)
|
|
195
|
+
kweaver <command> [--help|-h] # subcommand overview + actions
|
|
196
|
+
kweaver <command> <subcommand> [--help|-h] # action-level flags + examples
|
|
193
197
|
```
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
kweaver config show / list-bd / set-bd <value> # platform business domain — show/list-bd work with KWEAVER_BASE_URL (+ KWEAVER_TOKEN for list-bd)
|
|
204
|
-
kweaver token
|
|
205
|
-
kweaver ds list/get/delete/tables/connect
|
|
206
|
-
kweaver ds import-csv <ds_id> --files <glob> [--table-prefix <p>] [--batch-size 500] [--recreate]
|
|
207
|
-
kweaver dataflow list/run/runs/logs
|
|
208
|
-
kweaver model llm list/get/add/edit/delete/test/chat/--template
|
|
209
|
-
kweaver model small list/get/add/edit/delete/test/embeddings/rerank/--template
|
|
210
|
-
kweaver dataview list/find/get/query/delete
|
|
211
|
-
kweaver bkn list/get/stats/export/create/update/delete
|
|
212
|
-
kweaver bkn create-from-ds <ds_id> --name <name> [--tables t1,t2] [--build]
|
|
213
|
-
kweaver bkn create-from-csv <ds_id> --files <glob> --name <name> [--build]
|
|
214
|
-
kweaver bkn validate/push/pull
|
|
215
|
-
kweaver bkn object-type list/get/create/update/delete/query/properties
|
|
216
|
-
kweaver bkn metric list/get/create/search/validate/update/delete/query/dry-run
|
|
217
|
-
kweaver bkn relation-type list/get/create/update/delete
|
|
218
|
-
kweaver bkn action-type list/query/execute
|
|
219
|
-
kweaver bkn subgraph / search
|
|
220
|
-
kweaver bkn action-execution get
|
|
221
|
-
kweaver bkn action-log list/get/cancel
|
|
222
|
-
kweaver agent list/get/create/update/delete/chat/sessions/history/publish/unpublish
|
|
223
|
-
kweaver skill list/market/get/market-get/register/status/delete/update-metadata/update-package/history/republish/publish-history/content/read-file/download/install/management-content/management-read-file/management-download
|
|
224
|
-
kweaver vega health/stats/inspect/sql/catalog/resource/connector-type
|
|
225
|
-
kweaver context-loader help <subcommand>
|
|
226
|
-
kweaver context-loader tools|resources|templates|prompts <kn-id>
|
|
227
|
-
kweaver context-loader search-schema <kn-id> <query> [--scope object,relation,action,metric] [--concept-groups ids]
|
|
228
|
-
kweaver context-loader tool-call <kn-id> <name> --args '<json>'
|
|
229
|
-
kweaver context-loader kn-search|kn-schema-search <kn-id> <query> [...] (deprecated; use search-schema)
|
|
230
|
-
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
231
|
-
kweaver context-loader config set/use/list/show (deprecated; <kn-id> may be omitted to fall back to saved config)
|
|
232
|
-
kweaver toolbox create/list/publish/unpublish/delete
|
|
233
|
-
kweaver tool upload/list/enable/disable/execute/debug (execute and debug accept --path for OpenAPI path params)
|
|
234
|
-
kweaver call <path> [-X METHOD] [-d BODY] [-H header] [-F key=value]
|
|
198
|
+
|
|
199
|
+
Top-level command groups:
|
|
200
|
+
|
|
201
|
+
```text
|
|
202
|
+
AUTHENTICATION & CONFIG auth · token · config
|
|
203
|
+
DECISION AGENT agent · toolbox · tool
|
|
204
|
+
AI DATA PLATFORM bkn · ds · resource · dataflow · vega · context-loader
|
|
205
|
+
TRACE AI trace
|
|
206
|
+
FOUNDATION call · explore · model · skill · help
|
|
235
207
|
```
|
|
236
208
|
|
|
209
|
+
For a structured browsable index of every action and flag, run `kweaver help all`.
|
|
210
|
+
|
|
237
211
|
### Dataflow CLI examples
|
|
238
212
|
|
|
239
213
|
```bash
|
package/README.zh.md
CHANGED
|
@@ -124,22 +124,18 @@ const graph = await client.bkn.querySubgraph("bkn-id", { /* 路径规格 */
|
|
|
124
124
|
await client.bkn.executeAction("bkn-id", "at-id", { /* 参数 */ });
|
|
125
125
|
const logs = await client.bkn.listActionLogs("bkn-id");
|
|
126
126
|
|
|
127
|
-
//
|
|
128
|
-
const dsList
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const fuzzy
|
|
132
|
-
const exact
|
|
127
|
+
// 数据源 & vega-backend 资源
|
|
128
|
+
const dsList = await client.datasources.list();
|
|
129
|
+
const resId = await client.resources.create({ name: "v", datasourceId: "ds-id", table: "orders" });
|
|
130
|
+
const resList = await client.resources.list({ datasourceId: "ds-id" });
|
|
131
|
+
const fuzzy = await client.resources.find("BOM", { wait: false });
|
|
132
|
+
const exact = await client.resources.find("orders", {
|
|
133
133
|
datasourceId: "ds-id",
|
|
134
134
|
exact: true,
|
|
135
135
|
wait: true,
|
|
136
136
|
});
|
|
137
|
-
const
|
|
138
|
-
const queryRows = await client.
|
|
139
|
-
sql: "SELECT id, name FROM orders LIMIT 10",
|
|
140
|
-
limit: 10,
|
|
141
|
-
needTotal: true,
|
|
142
|
-
});
|
|
137
|
+
const res = await client.resources.get(resId);
|
|
138
|
+
const queryRows = await client.resources.query(resId, { limit: 10, needTotal: true });
|
|
143
139
|
|
|
144
140
|
// Vega — 可观测性与查询
|
|
145
141
|
const catalogs = await client.vega.listCatalogs();
|
|
@@ -181,43 +177,28 @@ const history = await client.skills.history("skill-id");
|
|
|
181
177
|
|
|
182
178
|
## 命令速查
|
|
183
179
|
|
|
180
|
+
`kweaver` 采用 `gh` 风格 help 布局(详见 [docs/cli_conventions.md §8](../../docs/cli_conventions.md#8-help-文本格式must)):
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
kweaver --help # gh 风格顶层概览
|
|
184
|
+
kweaver help <command> # 转发到 `<command> --help`
|
|
185
|
+
kweaver help all # 完整 per-action 签名(迁移期兜底)
|
|
186
|
+
kweaver <command> --help # 子命令概览 + 动作列表
|
|
187
|
+
kweaver <command> <subcommand> --help # 动作级 flag + 示例
|
|
184
188
|
```
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
kweaver token
|
|
195
|
-
kweaver ds list/get/delete/tables/connect
|
|
196
|
-
kweaver dataflow list/run/runs/logs
|
|
197
|
-
kweaver model llm list/get/add/edit/delete/test/chat/--template
|
|
198
|
-
kweaver model small list/get/add/edit/delete/test/embeddings/rerank/--template
|
|
199
|
-
kweaver dataview list/find/get/query/delete
|
|
200
|
-
kweaver bkn list/get/stats/export/create/update/delete
|
|
201
|
-
kweaver bkn object-type list/get/create/update/delete/query/properties
|
|
202
|
-
kweaver bkn metric list/get/create/search/validate/update/delete/query/dry-run
|
|
203
|
-
kweaver bkn relation-type list/get/create/update/delete
|
|
204
|
-
kweaver bkn action-type list/query/execute
|
|
205
|
-
kweaver bkn subgraph
|
|
206
|
-
kweaver bkn action-execution get
|
|
207
|
-
kweaver bkn action-log list/get/cancel
|
|
208
|
-
kweaver agent list/get/chat/sessions/history
|
|
209
|
-
kweaver skill list/market/get/market-get/register/status/delete/update-metadata/update-package/history/republish/publish-history/content/read-file/download/install/management-content/management-read-file/management-download
|
|
210
|
-
kweaver vega health|stats|inspect|sql|catalog|resource|connector-type
|
|
211
|
-
kweaver context-loader help <subcommand>
|
|
212
|
-
kweaver context-loader tools|resources|templates|prompts <kn-id>
|
|
213
|
-
kweaver context-loader search-schema <kn-id> <query> [--scope object,relation,action,metric] [--concept-groups ids]
|
|
214
|
-
kweaver context-loader tool-call <kn-id> <name> --args '<json>'
|
|
215
|
-
kweaver context-loader kn-search|kn-schema-search <kn-id> <query> [...] (deprecated;请使用 search-schema)
|
|
216
|
-
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
217
|
-
kweaver context-loader config set/use/list/show (deprecated;省略 <kn-id> 时回退到已保存配置)
|
|
218
|
-
kweaver call <path> [-X METHOD] [-d BODY] [-H header]
|
|
189
|
+
|
|
190
|
+
顶层命令分组:
|
|
191
|
+
|
|
192
|
+
```text
|
|
193
|
+
AUTHENTICATION & CONFIG auth · token · config
|
|
194
|
+
DECISION AGENT agent · toolbox · tool
|
|
195
|
+
AI DATA PLATFORM bkn · ds · resource · dataflow · vega · context-loader
|
|
196
|
+
TRACE AI trace
|
|
197
|
+
FOUNDATION call · explore · model · skill · help
|
|
219
198
|
```
|
|
220
199
|
|
|
200
|
+
需要查阅每个动作的完整签名(可浏览 / 可 grep)时,运行 `kweaver help all`。
|
|
201
|
+
|
|
221
202
|
### Dataflow CLI 示例
|
|
222
203
|
|
|
223
204
|
```bash
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export declare const RESOURCE_LIST_DEFAULT_LIMIT = 30;
|
|
2
|
+
/** Field metadata for a resource schema. */
|
|
3
|
+
export interface ViewField {
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
display_name?: string;
|
|
7
|
+
comment?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Normalized vega-backend Resource model. */
|
|
10
|
+
export interface Resource {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
catalog_id: string;
|
|
14
|
+
category: string;
|
|
15
|
+
source_identifier?: string;
|
|
16
|
+
status?: string;
|
|
17
|
+
schema_definition?: ViewField[];
|
|
18
|
+
logic_definition?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseResource(raw: Record<string, unknown>): Resource;
|
|
21
|
+
export interface CreateResourceOptions {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
accessToken: string;
|
|
24
|
+
name: string;
|
|
25
|
+
datasourceId: string;
|
|
26
|
+
table: string;
|
|
27
|
+
fields?: Array<{
|
|
28
|
+
name: string;
|
|
29
|
+
type: string;
|
|
30
|
+
}>;
|
|
31
|
+
businessDomain?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function createResource(options: CreateResourceOptions): Promise<string>;
|
|
34
|
+
export interface ListResourcesOptions {
|
|
35
|
+
baseUrl: string;
|
|
36
|
+
accessToken: string;
|
|
37
|
+
businessDomain?: string;
|
|
38
|
+
/** Filter by catalog (data source) id. */
|
|
39
|
+
datasourceId?: string;
|
|
40
|
+
/** Server-side name filter. */
|
|
41
|
+
name?: string;
|
|
42
|
+
/** Category filter (e.g. "table", "logicview"). */
|
|
43
|
+
category?: string;
|
|
44
|
+
/** Max items; ignored when <= 0. */
|
|
45
|
+
limit?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function listResources(options: ListResourcesOptions): Promise<Resource[]>;
|
|
48
|
+
export interface DeleteResourceOptions {
|
|
49
|
+
baseUrl: string;
|
|
50
|
+
accessToken: string;
|
|
51
|
+
id: string;
|
|
52
|
+
businessDomain?: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function deleteResource(options: DeleteResourceOptions): Promise<void>;
|
|
55
|
+
export interface GetResourceOptions {
|
|
56
|
+
baseUrl: string;
|
|
57
|
+
accessToken: string;
|
|
58
|
+
id: string;
|
|
59
|
+
businessDomain?: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function getResource(options: GetResourceOptions): Promise<Resource>;
|
|
62
|
+
export interface FindResourceOptions {
|
|
63
|
+
baseUrl: string;
|
|
64
|
+
accessToken: string;
|
|
65
|
+
businessDomain?: string;
|
|
66
|
+
/** Resource name to search for. */
|
|
67
|
+
name: string;
|
|
68
|
+
/** Filter by catalog (data source) id. */
|
|
69
|
+
datasourceId?: string;
|
|
70
|
+
/** When true, apply client-side exact name match after server filter (default false). */
|
|
71
|
+
exact?: boolean;
|
|
72
|
+
/** When true, poll until a result appears or timeout (default false). */
|
|
73
|
+
wait?: boolean;
|
|
74
|
+
/** Total wait budget in ms (default 30000). Only used when wait is true. */
|
|
75
|
+
timeoutMs?: number;
|
|
76
|
+
}
|
|
77
|
+
export declare function findResource(options: FindResourceOptions): Promise<Resource[]>;
|
|
78
|
+
export interface QueryResourceOptions {
|
|
79
|
+
baseUrl: string;
|
|
80
|
+
accessToken: string;
|
|
81
|
+
id: string;
|
|
82
|
+
offset?: number;
|
|
83
|
+
limit?: number;
|
|
84
|
+
needTotal?: boolean;
|
|
85
|
+
filterCondition?: unknown;
|
|
86
|
+
sort?: string;
|
|
87
|
+
direction?: "asc" | "desc";
|
|
88
|
+
businessDomain?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ResourceQueryResult {
|
|
91
|
+
entries?: unknown;
|
|
92
|
+
total_count?: number;
|
|
93
|
+
}
|
|
94
|
+
export declare function queryResource(options: QueryResourceOptions): Promise<ResourceQueryResult>;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { HttpError } from "../utils/http.js";
|
|
2
|
+
import { buildHeaders } from "./headers.js";
|
|
3
|
+
export const RESOURCE_LIST_DEFAULT_LIMIT = 30;
|
|
4
|
+
export function parseResource(raw) {
|
|
5
|
+
const res = {
|
|
6
|
+
id: String(raw.id ?? ""),
|
|
7
|
+
name: String(raw.name ?? ""),
|
|
8
|
+
catalog_id: String(raw.catalog_id ?? ""),
|
|
9
|
+
category: String(raw.category ?? ""),
|
|
10
|
+
};
|
|
11
|
+
if (raw.source_identifier != null)
|
|
12
|
+
res.source_identifier = String(raw.source_identifier);
|
|
13
|
+
if (raw.status != null)
|
|
14
|
+
res.status = String(raw.status);
|
|
15
|
+
if (Array.isArray(raw.schema_definition) && raw.schema_definition.length > 0) {
|
|
16
|
+
res.schema_definition = raw.schema_definition.map((f) => ({
|
|
17
|
+
name: String(f.name ?? ""),
|
|
18
|
+
type: String(f.type ?? "varchar"),
|
|
19
|
+
display_name: f.display_name != null ? String(f.display_name) : undefined,
|
|
20
|
+
comment: f.comment != null ? String(f.comment) : undefined,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
if (raw.logic_definition !== undefined)
|
|
24
|
+
res.logic_definition = raw.logic_definition;
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
function extractListPayload(data) {
|
|
28
|
+
if (Array.isArray(data))
|
|
29
|
+
return data;
|
|
30
|
+
if (data && typeof data === "object") {
|
|
31
|
+
const obj = data;
|
|
32
|
+
const items = obj.entries ?? obj.data;
|
|
33
|
+
if (Array.isArray(items))
|
|
34
|
+
return items;
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
export async function createResource(options) {
|
|
39
|
+
const { baseUrl, accessToken, name, datasourceId, table, fields = [], businessDomain = "bd_public", } = options;
|
|
40
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
41
|
+
const url = `${base}/api/vega-backend/v1/resources`;
|
|
42
|
+
const body = {
|
|
43
|
+
name,
|
|
44
|
+
catalog_id: datasourceId,
|
|
45
|
+
category: "table",
|
|
46
|
+
source_identifier: table,
|
|
47
|
+
};
|
|
48
|
+
if (fields.length > 0)
|
|
49
|
+
body.schema_definition = fields;
|
|
50
|
+
const response = await fetch(url, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
...buildHeaders(accessToken, businessDomain),
|
|
54
|
+
"content-type": "application/json",
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
});
|
|
58
|
+
const responseBody = await response.text();
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
throw new HttpError(response.status, response.statusText, responseBody);
|
|
61
|
+
}
|
|
62
|
+
const data = JSON.parse(responseBody);
|
|
63
|
+
return String(data.id ?? "");
|
|
64
|
+
}
|
|
65
|
+
export async function listResources(options) {
|
|
66
|
+
const { baseUrl, accessToken, businessDomain = "bd_public", datasourceId, name, category, limit = RESOURCE_LIST_DEFAULT_LIMIT, } = options;
|
|
67
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
68
|
+
const url = new URL(`${base}/api/vega-backend/v1/resources`);
|
|
69
|
+
if (datasourceId)
|
|
70
|
+
url.searchParams.set("catalog_id", datasourceId);
|
|
71
|
+
if (name)
|
|
72
|
+
url.searchParams.set("name", name);
|
|
73
|
+
if (category)
|
|
74
|
+
url.searchParams.set("category", category);
|
|
75
|
+
if (limit && limit > 0)
|
|
76
|
+
url.searchParams.set("limit", String(limit));
|
|
77
|
+
const response = await fetch(url.toString(), {
|
|
78
|
+
method: "GET",
|
|
79
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
80
|
+
});
|
|
81
|
+
const bodyText = await response.text();
|
|
82
|
+
if (!response.ok)
|
|
83
|
+
throw new HttpError(response.status, response.statusText, bodyText);
|
|
84
|
+
const parsed = JSON.parse(bodyText);
|
|
85
|
+
const items = extractListPayload(parsed);
|
|
86
|
+
return items
|
|
87
|
+
.filter((item) => item != null && typeof item === "object")
|
|
88
|
+
.map(parseResource);
|
|
89
|
+
}
|
|
90
|
+
export async function deleteResource(options) {
|
|
91
|
+
const { baseUrl, accessToken, id, businessDomain = "bd_public" } = options;
|
|
92
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
93
|
+
const url = `${base}/api/vega-backend/v1/resources/${encodeURIComponent(id)}`;
|
|
94
|
+
const response = await fetch(url, {
|
|
95
|
+
method: "DELETE",
|
|
96
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
97
|
+
});
|
|
98
|
+
const bodyText = await response.text();
|
|
99
|
+
if (!response.ok)
|
|
100
|
+
throw new HttpError(response.status, response.statusText, bodyText);
|
|
101
|
+
}
|
|
102
|
+
export async function getResource(options) {
|
|
103
|
+
const { baseUrl, accessToken, id, businessDomain = "bd_public" } = options;
|
|
104
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
105
|
+
const url = `${base}/api/vega-backend/v1/resources/${encodeURIComponent(id)}`;
|
|
106
|
+
const response = await fetch(url, {
|
|
107
|
+
method: "GET",
|
|
108
|
+
headers: buildHeaders(accessToken, businessDomain),
|
|
109
|
+
});
|
|
110
|
+
const body = await response.text();
|
|
111
|
+
if (!response.ok)
|
|
112
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
113
|
+
const parsed = JSON.parse(body);
|
|
114
|
+
// vega-backend GET /:id returns { entries: [...] } (supports comma-separated ids)
|
|
115
|
+
const items = extractListPayload(parsed);
|
|
116
|
+
const raw = items.length > 0 ? items[0] : (parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null);
|
|
117
|
+
if (!raw || typeof raw !== "object")
|
|
118
|
+
throw new HttpError(500, "Invalid response", body);
|
|
119
|
+
return parseResource(raw);
|
|
120
|
+
}
|
|
121
|
+
function sleepMs(ms) {
|
|
122
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
123
|
+
}
|
|
124
|
+
export async function findResource(options) {
|
|
125
|
+
const { baseUrl, accessToken, businessDomain = "bd_public", name, datasourceId, exact = false, wait = false, timeoutMs = 30_000, } = options;
|
|
126
|
+
const deadline = Date.now() + timeoutMs;
|
|
127
|
+
let attempt = 0;
|
|
128
|
+
while (true) {
|
|
129
|
+
const list = await listResources({ baseUrl, accessToken, businessDomain, datasourceId, name });
|
|
130
|
+
const results = exact ? list.filter((v) => v.name === name) : list;
|
|
131
|
+
if (results.length > 0 || !wait || Date.now() >= deadline)
|
|
132
|
+
return results;
|
|
133
|
+
const delayMs = Math.min(5000, 1000 * 2 ** attempt);
|
|
134
|
+
attempt += 1;
|
|
135
|
+
await sleepMs(delayMs);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function queryResource(options) {
|
|
139
|
+
const { baseUrl, accessToken, id, offset = 0, limit = 50, needTotal = false, filterCondition, sort, direction, businessDomain = "bd_public", } = options;
|
|
140
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
141
|
+
const url = `${base}/api/vega-backend/v1/resources/${encodeURIComponent(id)}/data`;
|
|
142
|
+
const body = { offset, limit, need_total: needTotal };
|
|
143
|
+
if (filterCondition !== undefined)
|
|
144
|
+
body.filter_condition = filterCondition;
|
|
145
|
+
if (sort !== undefined)
|
|
146
|
+
body.sort = sort;
|
|
147
|
+
if (direction !== undefined)
|
|
148
|
+
body.direction = direction;
|
|
149
|
+
const response = await fetch(url, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
headers: {
|
|
152
|
+
...buildHeaders(accessToken, businessDomain),
|
|
153
|
+
"content-type": "application/json",
|
|
154
|
+
"x-http-method-override": "GET",
|
|
155
|
+
},
|
|
156
|
+
body: JSON.stringify(body),
|
|
157
|
+
});
|
|
158
|
+
const bodyText = await response.text();
|
|
159
|
+
if (!response.ok)
|
|
160
|
+
throw new HttpError(response.status, response.statusText, bodyText);
|
|
161
|
+
const parsed = JSON.parse(bodyText);
|
|
162
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
163
|
+
return parsed;
|
|
164
|
+
}
|
|
165
|
+
return {};
|
|
166
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -9,14 +9,93 @@ import { runContextLoaderCommand } from "./commands/context-loader.js";
|
|
|
9
9
|
import { runDataflowCommand } from "./commands/dataflow.js";
|
|
10
10
|
import { runDsCommand } from "./commands/ds.js";
|
|
11
11
|
import { runExploreCommand } from "./commands/explore.js";
|
|
12
|
-
import {
|
|
12
|
+
import { runResourceCommand } from "./commands/resource.js";
|
|
13
13
|
import { runModelCommand } from "./commands/model.js";
|
|
14
14
|
import { runSkillCommand } from "./commands/skill.js";
|
|
15
15
|
import { runTokenCommand } from "./commands/token.js";
|
|
16
16
|
import { runToolboxCommand } from "./commands/toolbox.js";
|
|
17
17
|
import { runToolCommand } from "./commands/tool.js";
|
|
18
18
|
import { runVegaCommand } from "./commands/vega.js";
|
|
19
|
+
import { renderHelp } from "./help/format.js";
|
|
19
20
|
function printHelp() {
|
|
21
|
+
console.log(renderHelp({
|
|
22
|
+
tagline: "KWeaver SDK — operate KWeaver platform from CLI",
|
|
23
|
+
usage: [
|
|
24
|
+
"kweaver [global flags] <command> <subcommand> [flags]",
|
|
25
|
+
"kweaver --version | -V",
|
|
26
|
+
"kweaver --help | -h",
|
|
27
|
+
],
|
|
28
|
+
sections: [
|
|
29
|
+
{
|
|
30
|
+
title: "AUTHENTICATION & CONFIG",
|
|
31
|
+
items: [
|
|
32
|
+
{ name: "auth", desc: "Login / switch / list saved platform credentials" },
|
|
33
|
+
{ name: "token", desc: "Print current access token (auto-refresh)" },
|
|
34
|
+
{ name: "config", desc: "Per-platform business-domain config" },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: "DECISION AGENT",
|
|
39
|
+
items: [
|
|
40
|
+
{ name: "agent", desc: "Agent CRUD, chat, sessions, publish" },
|
|
41
|
+
{ name: "toolbox", desc: "Agent toolbox lifecycle" },
|
|
42
|
+
{ name: "tool", desc: "Tools inside toolbox" },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
title: "AI DATA PLATFORM",
|
|
47
|
+
items: [
|
|
48
|
+
{ name: "bkn", desc: "Knowledge network — build, query, action, metric" },
|
|
49
|
+
{ name: "ds", desc: "Datasource (list, get, connect, tables)" },
|
|
50
|
+
{ name: "resource (res)", desc: "Resources — list, find, get, query, delete" },
|
|
51
|
+
{ name: "dataflow", desc: "Dataflow document workflows (run, runs, logs)" },
|
|
52
|
+
{ name: "vega", desc: "Vega observability — catalog, resource, query" },
|
|
53
|
+
{ name: "context-loader (context)", desc: "MCP/HTTP context loader (reads BKN schema/instances)" },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: "TRACE AI",
|
|
58
|
+
items: [
|
|
59
|
+
{ name: "trace", desc: "Diagnose conversations / build eval-sets / schema validate" },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: "FOUNDATION",
|
|
64
|
+
items: [
|
|
65
|
+
{ name: "call (curl)", desc: "curl-style API call with auto-injected auth headers" },
|
|
66
|
+
{ name: "explore", desc: "Interactive web UI" },
|
|
67
|
+
{ name: "model", desc: "Model factory — LLM / small-model CRUD + chat" },
|
|
68
|
+
{ name: "skill", desc: "Skill registry / market" },
|
|
69
|
+
{ name: "help", desc: "Show help — use `help all` for full signatures" },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
flags: [
|
|
74
|
+
{ name: "--base-url <url>", desc: "Override platform URL (env: KWEAVER_BASE_URL)" },
|
|
75
|
+
{ name: "--token <value>", desc: "Override access token (env: KWEAVER_TOKEN; disables write commands)" },
|
|
76
|
+
{ name: "--user <id|name>", desc: "Use specific user credentials (env: KWEAVER_USER)" },
|
|
77
|
+
{ name: "--pretty", desc: "Pretty-print JSON output (default)" },
|
|
78
|
+
{ name: "--compact", desc: "Compact JSON output (pipeline-friendly)" },
|
|
79
|
+
{ name: "--help, -h", desc: "Show help" },
|
|
80
|
+
{ name: "--version, -V", desc: "Show version" },
|
|
81
|
+
],
|
|
82
|
+
environment: [
|
|
83
|
+
{ name: "KWEAVER_PROFILE", desc: "Isolate active-platform/user state per shell" },
|
|
84
|
+
{ name: "KWEAVERC_CONFIG_DIR", desc: "Override config root (~/.kweaver)" },
|
|
85
|
+
],
|
|
86
|
+
examples: [
|
|
87
|
+
"kweaver auth https://platform.example.com",
|
|
88
|
+
"kweaver agent chat <agent_id> -m \"hello\"",
|
|
89
|
+
"kweaver bkn build <kn-id> --wait",
|
|
90
|
+
],
|
|
91
|
+
learnMore: [
|
|
92
|
+
"Use `kweaver <command> --help` for command-specific help",
|
|
93
|
+
"Use `kweaver help all` for full command signatures (migration fallback)",
|
|
94
|
+
"For agents/multi-terminal: prefer `--user <id>` over `auth switch`",
|
|
95
|
+
],
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
function printHelpFull() {
|
|
20
99
|
console.log(`kweaver
|
|
21
100
|
|
|
22
101
|
Usage:
|
|
@@ -76,11 +155,11 @@ Usage:
|
|
|
76
155
|
kweaver model small list|get|add|edit|delete|test|embeddings|rerank|--template ...
|
|
77
156
|
kweaver model --help
|
|
78
157
|
|
|
79
|
-
kweaver
|
|
80
|
-
kweaver
|
|
81
|
-
kweaver
|
|
82
|
-
kweaver
|
|
83
|
-
kweaver
|
|
158
|
+
kweaver resource list [--datasource-id id] [--type table|logicview] [--limit n] [-bd value]
|
|
159
|
+
kweaver resource find --name <name> [--exact] [--datasource-id id] [--wait] [--timeout ms] [-bd value]
|
|
160
|
+
kweaver resource get <id> [-bd value]
|
|
161
|
+
kweaver resource query <id> [--limit n] [--offset n] [--need-total] [-bd value]
|
|
162
|
+
kweaver resource delete <id> [-y] [-bd value]
|
|
84
163
|
|
|
85
164
|
kweaver bkn list [options]
|
|
86
165
|
kweaver bkn get <kn-id> [options]
|
|
@@ -176,7 +255,7 @@ Commands:
|
|
|
176
255
|
ds Manage datasources (list, get, delete, tables, connect)
|
|
177
256
|
dataflow Dataflow document workflows (list, run, runs, logs)
|
|
178
257
|
model Model factory: LLM/small-model CRUD (manager) and llm chat (OpenAI-compatible API)
|
|
179
|
-
|
|
258
|
+
resource|res List, find, get, query, delete vega-backend resources (table / logicview)
|
|
180
259
|
bkn Knowledge network (CRUD, build, validate, export, stats, push/pull,
|
|
181
260
|
object-type, relation-type, subgraph, action-type, action-execution, action-log)
|
|
182
261
|
config Per-platform configuration (business domain)
|
|
@@ -238,10 +317,23 @@ export async function run(argv) {
|
|
|
238
317
|
console.log(pkg.version);
|
|
239
318
|
return 0;
|
|
240
319
|
}
|
|
241
|
-
if (argv.length === 0 || !command || command === "--help" || command === "-h"
|
|
320
|
+
if (argv.length === 0 || !command || command === "--help" || command === "-h") {
|
|
242
321
|
printHelp();
|
|
243
322
|
return 0;
|
|
244
323
|
}
|
|
324
|
+
if (command === "help") {
|
|
325
|
+
const topic = rest[0];
|
|
326
|
+
if (!topic) {
|
|
327
|
+
printHelp();
|
|
328
|
+
return 0;
|
|
329
|
+
}
|
|
330
|
+
if (topic === "all") {
|
|
331
|
+
printHelpFull();
|
|
332
|
+
return 0;
|
|
333
|
+
}
|
|
334
|
+
// `help <command>` → forward to `<command> --help`
|
|
335
|
+
return run([...rest, "--help"]);
|
|
336
|
+
}
|
|
245
337
|
if (command === "auth") {
|
|
246
338
|
return runAuthCommand(rest);
|
|
247
339
|
}
|
|
@@ -257,8 +349,8 @@ export async function run(argv) {
|
|
|
257
349
|
if (command === "model") {
|
|
258
350
|
return runModelCommand(rest);
|
|
259
351
|
}
|
|
260
|
-
if (command === "
|
|
261
|
-
return
|
|
352
|
+
if (command === "resource" || command === "res") {
|
|
353
|
+
return runResourceCommand(rest);
|
|
262
354
|
}
|
|
263
355
|
if (command === "token") {
|
|
264
356
|
return runTokenCommand(rest);
|
package/dist/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ConversationsResource } from "./resources/conversations.js";
|
|
|
3
3
|
import { ContextLoaderResource } from "./resources/context-loader.js";
|
|
4
4
|
import { DataflowsResource } from "./resources/dataflows.js";
|
|
5
5
|
import { DataSourcesResource } from "./resources/datasources.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ResourcesResource } from "./resources/resources.js";
|
|
7
7
|
import { KnowledgeNetworksResource } from "./resources/knowledge-networks.js";
|
|
8
8
|
import { BknResource } from "./resources/bkn.js";
|
|
9
9
|
import { SkillsResource } from "./resources/skills.js";
|
|
@@ -98,8 +98,8 @@ export declare class KWeaverClient implements ClientContext {
|
|
|
98
98
|
readonly dataflows: DataflowsResource;
|
|
99
99
|
/** Data source management (connect, test, list tables). */
|
|
100
100
|
readonly datasources: DataSourcesResource;
|
|
101
|
-
/**
|
|
102
|
-
readonly
|
|
101
|
+
/** Vega-backend resource management (table/logicview resources under a catalog). */
|
|
102
|
+
readonly resources: ResourcesResource;
|
|
103
103
|
/** Vega observability platform (catalogs, resources, connector types). */
|
|
104
104
|
readonly vega: VegaResource;
|
|
105
105
|
/** ADP/KWeaver skill registry, market, progressive read, and install helpers. */
|