@kweaver-ai/kweaver-sdk 0.6.10 → 0.7.2
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 +35 -5
- package/README.zh.md +34 -4
- package/dist/api/context-loader.d.ts +45 -10
- package/dist/api/context-loader.js +43 -8
- package/dist/api/semantic-search.d.ts +9 -0
- package/dist/api/semantic-search.js +19 -0
- package/dist/api/skills.js +10 -8
- package/dist/api/toolboxes.d.ts +12 -0
- package/dist/api/toolboxes.js +43 -1
- package/dist/cli.js +67 -28
- package/dist/commands/auth.js +43 -3
- package/dist/commands/bkn-ops.d.ts +4 -0
- package/dist/commands/bkn-ops.js +136 -62
- package/dist/commands/bkn-query.js +7 -2
- package/dist/commands/config.js +8 -0
- package/dist/commands/context-loader.js +340 -36
- package/dist/commands/ds.d.ts +23 -0
- package/dist/commands/ds.js +116 -18
- package/dist/commands/skill.js +26 -6
- package/dist/commands/toolbox.d.ts +15 -0
- package/dist/commands/toolbox.js +131 -1
- package/dist/config/stateless.d.ts +13 -0
- package/dist/config/stateless.js +20 -0
- package/dist/config/store.js +7 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/resources/bkn.d.ts +2 -1
- package/dist/resources/bkn.js +19 -7
- package/dist/resources/context-loader.d.ts +4 -3
- package/dist/resources/context-loader.js +8 -5
- package/dist/resources/toolboxes.d.ts +15 -0
- package/dist/resources/toolboxes.js +15 -1
- package/dist/utils/skill-bundle.d.ts +5 -0
- package/dist/utils/skill-bundle.js +74 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ export KWEAVER_BASE_URL=https://your-kweaver-instance.com
|
|
|
31
31
|
export KWEAVER_TOKEN=your-token
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
With both set, API commands use that token even if you never ran `auth login`. You can also run **`kweaver auth status`**, **`kweaver auth whoami`** (supports `--json`), and **`kweaver config show`** when there is **no** current platform in `~/.kweaver/`. In env-token mode, `whoami` resolves the bound identity from EACP `/api/eacp/v1/user/get` and prints `Type` (user/app), `User ID`, `Account` and `Name`; this works for both opaque and JWT tokens. If EACP is unreachable, the CLI falls back to local JWT decode and prints a short hint when the token is opaque.
|
|
34
|
+
With both set, API commands use that token even if you never ran `auth login`. The same applies to **`kweaver --base-url <url> --token <access-token> <command>`** (stateless flag mode; see [Stateless token mode](#stateless-token-mode)). You can also run **`kweaver auth status`**, **`kweaver auth whoami`** (supports `--json`), and **`kweaver config show`** when there is **no** current platform in `~/.kweaver/`. In env-token mode, `whoami` resolves the bound identity from EACP `/api/eacp/v1/user/get` and prints `Type` (user/app), `User ID`, `Account` and `Name`; this works for both opaque and JWT tokens. If EACP is unreachable, the CLI falls back to local JWT decode and prints a short hint when the token is opaque.
|
|
35
35
|
|
|
36
36
|
`kweaver config list-bd` lists business domains for the current user. App (service) tokens are not bound to an end-user — when the backend rejects the call with `401 invalid user_id`, the CLI re-checks the token type via EACP and, if confirmed `type:"app"`, replaces the cryptic backend body with `This command does not support app accounts.`. Use a user token (interactive `auth login`) for user-bound endpoints.
|
|
37
37
|
|
|
@@ -143,15 +143,20 @@ const rows = await client.vega.sqlQuery(
|
|
|
143
143
|
JSON.stringify({ query: "SELECT * FROM {{res-1}} LIMIT 5", resource_type: "mysql" }),
|
|
144
144
|
);
|
|
145
145
|
|
|
146
|
-
// Context Loader (
|
|
146
|
+
// Context Loader (MCP search_schema plus generic tools/call)
|
|
147
147
|
const cl = client.contextLoader(mcpUrl, "bkn-id");
|
|
148
|
-
const
|
|
148
|
+
const schema = await cl.searchSchema({ query: "hypertension treatment" });
|
|
149
|
+
const rawTool = await cl.callTool("search_schema", { query: "hypertension treatment" });
|
|
149
150
|
|
|
150
151
|
// Skills (registry + market + progressive read)
|
|
151
152
|
const skills = await client.skills.market({ name: "kweaver" });
|
|
152
153
|
const skillMd = await client.skills.fetchContent("skill-id");
|
|
153
154
|
```
|
|
154
155
|
|
|
156
|
+
`searchSchema()` is the typed wrapper for the Context Loader MCP `search_schema` tool. It defaults `response_format` to `json` and accepts `query`, `response_format`, `search_scope`, `max_concepts`, `schema_brief`, and `enable_rerank`. The parsed response may contain `object_types`, `relation_types`, `action_types`, and `metric_types`.
|
|
157
|
+
|
|
158
|
+
Use `callTool(name, args)` when you need native MCP `tools/call` access for newly added server tools before the SDK adds a typed wrapper. Arguments are passed through unchanged.
|
|
159
|
+
|
|
155
160
|
## CLI Reference
|
|
156
161
|
|
|
157
162
|
```
|
|
@@ -183,8 +188,10 @@ kweaver bkn action-log list/get/cancel
|
|
|
183
188
|
kweaver agent list/get/create/update/delete/chat/sessions/history/publish/unpublish
|
|
184
189
|
kweaver skill list/market/get/register/status/delete/content/read-file/download/install
|
|
185
190
|
kweaver vega health/stats/inspect/sql/catalog/resource/connector-type
|
|
186
|
-
kweaver context-loader
|
|
187
|
-
kweaver context-loader kn-search
|
|
191
|
+
kweaver context-loader tools|resources|templates|prompts <kn-id>
|
|
192
|
+
kweaver context-loader search-schema|tool-call|kn-search|kn-schema-search <kn-id> <query|name> [...]
|
|
193
|
+
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
194
|
+
kweaver context-loader config set/use/list/show (deprecated; <kn-id> may be omitted to fall back to saved config)
|
|
188
195
|
kweaver toolbox create/list/publish/unpublish/delete
|
|
189
196
|
kweaver tool upload/list/enable/disable
|
|
190
197
|
kweaver call <path> [-X METHOD] [-d BODY] [-H header] [-F key=value]
|
|
@@ -246,10 +253,33 @@ kweaver tool enable --toolbox <BOX_ID> <TOOL_ID>
|
|
|
246
253
|
| `KWEAVER_BASE_URL` | KWeaver instance URL |
|
|
247
254
|
| `KWEAVER_BUSINESS_DOMAIN` | Business domain identifier |
|
|
248
255
|
| `KWEAVER_TOKEN` | Access token |
|
|
256
|
+
| `KWEAVER_TOKEN_SOURCE` | Internal sentinel set by the CLI when `--token` is passed; do not set manually |
|
|
249
257
|
| `KWEAVER_NO_AUTH` | Set to `1`/`true`/`yes` to use no-auth sentinel when `KWEAVER_TOKEN` is unset (with `KWEAVER_BASE_URL` or active platform) |
|
|
250
258
|
| `KWEAVER_TLS_INSECURE` | Set to `1` or `true` to skip TLS certificate verification for all HTTPS in the process (dev only; prefer `kweaver auth … --insecure` which saves per platform) |
|
|
251
259
|
| `NODE_TLS_REJECT_UNAUTHORIZED` | Node.js built-in TLS switch: set to `0` to skip certificate verification for HTTPS in this process. The `kweaver` CLI sets this when `KWEAVER_TLS_INSECURE` is set or the saved token has insecure TLS (same scope as above; dev only). |
|
|
252
260
|
|
|
261
|
+
### Stateless token mode
|
|
262
|
+
|
|
263
|
+
Pass an access token via `--token` for fully stateless invocations (no read or write of `~/.kweaver/` for that token):
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
kweaver --base-url https://platform.example.com --token "$TOK" bkn list
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Resolution order:
|
|
270
|
+
|
|
271
|
+
| Source | base-url | token |
|
|
272
|
+
|--------|----------|-------|
|
|
273
|
+
| flag | `--base-url` | `--token` |
|
|
274
|
+
| env | `KWEAVER_BASE_URL` | `KWEAVER_TOKEN` |
|
|
275
|
+
| disk | active platform | OAuth session (refreshable) |
|
|
276
|
+
|
|
277
|
+
When `--token` is used, write-disk commands (`auth login` / `logout` / `use` / `delete` / `switch`, `config set-bd`, the entire `context-loader config` group) error out — drop `--token` or use `kweaver auth login` for a saved session.
|
|
278
|
+
|
|
279
|
+
`auth whoami` / `auth status` distinguish the two stateless modes: `Source: CLI (flag: --token)` for flag mode, `env (KWEAVER_TOKEN)` for env mode (`whoami --json` uses `"source": "flag"` vs `"source": "env"`).
|
|
280
|
+
|
|
281
|
+
`kweaver context-loader` runtime subcommands accept `<kn-id>` as the first positional (e.g. `kweaver context-loader tools <kn-id>`) or via the global `--kn-id <id>` / `-k <id>` flag, so they work in stateless mode without any saved config. The `context-loader config set|use|list|remove|show` management group is deprecated, prints a warning on use, and is disabled in its entirety under `--token`.
|
|
282
|
+
|
|
253
283
|
### TLS Certificate Troubleshooting
|
|
254
284
|
|
|
255
285
|
If you encounter errors like `fetch failed`, `self-signed certificate`, or `UNABLE_TO_GET_ISSUER_CERT`, the target server likely uses a self-signed certificate or Kubernetes Ingress default fake certificate. Try the following in order of preference:
|
package/README.zh.md
CHANGED
|
@@ -136,15 +136,20 @@ const rows = await client.vega.sqlQuery(
|
|
|
136
136
|
JSON.stringify({ query: "SELECT * FROM {{res-1}} LIMIT 5", resource_type: "mysql" }),
|
|
137
137
|
);
|
|
138
138
|
|
|
139
|
-
// Context Loader
|
|
139
|
+
// Context Loader(MCP search_schema + 通用 tools/call)
|
|
140
140
|
const cl = client.contextLoader(mcpUrl, "bkn-id");
|
|
141
|
-
const
|
|
141
|
+
const schema = await cl.searchSchema({ query: "高血压 治疗" });
|
|
142
|
+
const rawTool = await cl.callTool("search_schema", { query: "高血压 治疗" });
|
|
142
143
|
|
|
143
144
|
// Skill(注册表/市场/渐进式读取)
|
|
144
145
|
const skills = await client.skills.market({ name: "kweaver" });
|
|
145
146
|
const skillMd = await client.skills.fetchContent("skill-id");
|
|
146
147
|
```
|
|
147
148
|
|
|
149
|
+
`searchSchema()` 是 Context Loader MCP `search_schema` 的类型化封装,默认 `response_format` 为 `json`,支持 `query`、`response_format`、`search_scope`、`max_concepts`、`schema_brief`、`enable_rerank`。解析后的返回结果可能包含 `object_types`、`relation_types`、`action_types`、`metric_types`。
|
|
150
|
+
|
|
151
|
+
需要直接使用 MCP 原生 `tools/call` 时,使用 `callTool(name, args)`。这适用于服务端新增工具但 SDK 尚未提供类型化封装的场景,参数会原样透传。
|
|
152
|
+
|
|
148
153
|
## 命令速查
|
|
149
154
|
|
|
150
155
|
```
|
|
@@ -171,8 +176,10 @@ kweaver bkn action-log list/get/cancel
|
|
|
171
176
|
kweaver agent list/get/chat/sessions/history
|
|
172
177
|
kweaver skill list/market/get/register/status/delete/content/read-file/download/install
|
|
173
178
|
kweaver vega health|stats|inspect|sql|catalog|resource|connector-type
|
|
174
|
-
kweaver context-loader
|
|
175
|
-
kweaver context-loader kn-search
|
|
179
|
+
kweaver context-loader tools|resources|templates|prompts <kn-id>
|
|
180
|
+
kweaver context-loader search-schema|tool-call|kn-search|kn-schema-search <kn-id> <query|name> [...]
|
|
181
|
+
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
182
|
+
kweaver context-loader config set/use/list/show (deprecated;省略 <kn-id> 时回退到已保存配置)
|
|
176
183
|
kweaver call <path> [-X METHOD] [-d BODY] [-H header]
|
|
177
184
|
```
|
|
178
185
|
|
|
@@ -213,10 +220,33 @@ kweaver vega sql -d '{"resource_type":"mysql","query":"SELECT * FROM {{res-1}} L
|
|
|
213
220
|
| `KWEAVER_BASE_URL` | KWeaver 实例地址 |
|
|
214
221
|
| `KWEAVER_BUSINESS_DOMAIN` | 业务域标识 |
|
|
215
222
|
| `KWEAVER_TOKEN` | 访问令牌 |
|
|
223
|
+
| `KWEAVER_TOKEN_SOURCE` | CLI 传入 `--token` 时由程序设置的内部标记;请勿手动设置 |
|
|
216
224
|
| `KWEAVER_NO_AUTH` | 设为 `1`/`true`/`yes` 且未设置 `KWEAVER_TOKEN` 时使用 no-auth 占位(需 `KWEAVER_BASE_URL` 或已选平台) |
|
|
217
225
|
| `KWEAVER_TLS_INSECURE` | 设为 `1` 或 `true` 时跳过 TLS 证书校验(仅开发;更推荐 `kweaver auth … --insecure` 以按平台持久化) |
|
|
218
226
|
| `NODE_TLS_REJECT_UNAUTHORIZED` | Node.js 内置 TLS 开关:设为 `0` 时在本进程内跳过 HTTPS 证书校验。`kweaver` 在 `KWEAVER_TLS_INSECURE` 生效或已保存 token 为不安全 TLS 时会设置此项(范围同上;仅开发)。 |
|
|
219
227
|
|
|
228
|
+
### Stateless token 模式
|
|
229
|
+
|
|
230
|
+
通过 `--token` 传入访问令牌,该次调用对该 token 路径既不读也不写 `~/.kweaver/`:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
kweaver --base-url https://platform.example.com --token "$TOK" bkn list
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
来源优先级:
|
|
237
|
+
|
|
238
|
+
| 来源 | base-url | token |
|
|
239
|
+
|------|----------|-------|
|
|
240
|
+
| flag | `--base-url` | `--token` |
|
|
241
|
+
| env | `KWEAVER_BASE_URL` | `KWEAVER_TOKEN` |
|
|
242
|
+
| 磁盘 | active platform | OAuth 会话(可 refresh) |
|
|
243
|
+
|
|
244
|
+
`--token` 模式下会禁用写盘命令:`auth login` / `logout` / `use` / `delete` / `switch`、`config set-bd`、整个 `context-loader config` 子命令组 ——去掉 `--token` 或改用 `kweaver auth login`。
|
|
245
|
+
|
|
246
|
+
`auth whoami` / `auth status` 通过文案区分来源:flag 模式为 `CLI (flag: --token)`,env 模式为 `env (KWEAVER_TOKEN)`(`whoami --json` 为 `"source": "flag"` 与 `"source": "env"`)。
|
|
247
|
+
|
|
248
|
+
`kweaver context-loader` 运行时子命令将 `<kn-id>` 作为第一个位置参数(如 `kweaver context-loader tools <kn-id>`),也支持全局 `--kn-id <id>` / `-k <id>` flag,因此在 stateless 模式下可直接使用,无需任何持久化配置。`context-loader config set|use|list|remove|show` 管理子命令已被标记为 deprecated(每次调用打印警告),且在 `--token` 下整组被禁用。
|
|
249
|
+
|
|
220
250
|
### TLS 证书问题排查
|
|
221
251
|
|
|
222
252
|
如果遇到 `fetch failed`、`self-signed certificate`、`UNABLE_TO_GET_ISSUER_CERT` 等 TLS 相关错误,通常是目标服务器使用了自签名证书或 Kubernetes Ingress 默认假证书。可按优先级尝试以下方案:
|
|
@@ -4,15 +4,28 @@ export interface ContextLoaderCallOptions {
|
|
|
4
4
|
knId: string;
|
|
5
5
|
accessToken: string;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export interface SearchSchemaScope {
|
|
8
|
+
include_object_types?: boolean;
|
|
9
|
+
include_relation_types?: boolean;
|
|
10
|
+
include_action_types?: boolean;
|
|
11
|
+
include_metric_types?: boolean;
|
|
11
12
|
}
|
|
12
|
-
/** Layer 1:
|
|
13
|
-
export interface
|
|
13
|
+
/** Layer 1: search_schema arguments. */
|
|
14
|
+
export interface SearchSchemaArgs {
|
|
14
15
|
query: string;
|
|
16
|
+
response_format?: "json" | "toon";
|
|
17
|
+
search_scope?: SearchSchemaScope;
|
|
15
18
|
max_concepts?: number;
|
|
19
|
+
schema_brief?: boolean;
|
|
20
|
+
enable_rerank?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Layer 1: search_schema result. */
|
|
23
|
+
export interface SearchSchemaResult {
|
|
24
|
+
object_types?: unknown[];
|
|
25
|
+
relation_types?: unknown[];
|
|
26
|
+
action_types?: unknown[];
|
|
27
|
+
metric_types?: unknown[];
|
|
28
|
+
raw?: string;
|
|
16
29
|
}
|
|
17
30
|
/** Condition for query_object_instance and query_instance_subgraph. */
|
|
18
31
|
export interface ConditionSpec {
|
|
@@ -60,6 +73,24 @@ export interface GetActionInfoArgs {
|
|
|
60
73
|
at_id: string;
|
|
61
74
|
_instance_identity: Record<string, string>;
|
|
62
75
|
}
|
|
76
|
+
/** Layer 3: find_skills arguments (object_type_id is required). */
|
|
77
|
+
export interface FindSkillsArgs {
|
|
78
|
+
object_type_id: string;
|
|
79
|
+
response_format?: "json" | "toon";
|
|
80
|
+
instance_identities?: Record<string, unknown>[];
|
|
81
|
+
skill_query?: string;
|
|
82
|
+
/** 1..20, default 10 on the server side. */
|
|
83
|
+
top_k?: number;
|
|
84
|
+
}
|
|
85
|
+
/** Layer 3: find_skills result. */
|
|
86
|
+
export interface FindSkillsResult {
|
|
87
|
+
entries: Array<{
|
|
88
|
+
skill_id: string;
|
|
89
|
+
name: string;
|
|
90
|
+
description?: string;
|
|
91
|
+
}>;
|
|
92
|
+
message?: string;
|
|
93
|
+
}
|
|
63
94
|
/** Error when get_logic_properties_values returns MISSING_INPUT_PARAMS. */
|
|
64
95
|
export interface MissingInputParamsError {
|
|
65
96
|
error_code: "MISSING_INPUT_PARAMS";
|
|
@@ -81,10 +112,9 @@ export declare function validateCondition(condition: unknown): void;
|
|
|
81
112
|
export declare function validateInstanceIdentity(v: unknown, label: string): void;
|
|
82
113
|
/** Guardrail: _instance_identities must be array of plain objects from Layer 2. */
|
|
83
114
|
export declare function validateInstanceIdentities(v: unknown): void;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export declare function knSchemaSearch(options: ContextLoaderCallOptions, args: KnSchemaSearchArgs): Promise<unknown>;
|
|
115
|
+
export declare function callTool(options: ContextLoaderCallOptions, toolName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
116
|
+
/** Layer 1: search_schema. Returns object_types, relation_types, action_types, metric_types. */
|
|
117
|
+
export declare function searchSchema(options: ContextLoaderCallOptions, args: SearchSchemaArgs): Promise<SearchSchemaResult>;
|
|
88
118
|
/** Layer 2: query_object_instance. Returns datas with _instance_identity. */
|
|
89
119
|
export declare function queryObjectInstance(options: ContextLoaderCallOptions, args: QueryObjectInstanceArgs): Promise<unknown>;
|
|
90
120
|
/** Layer 2: query_instance_subgraph. Returns entries with nested _instance_identity. */
|
|
@@ -93,6 +123,11 @@ export declare function queryInstanceSubgraph(options: ContextLoaderCallOptions,
|
|
|
93
123
|
export declare function getLogicPropertiesValues(options: ContextLoaderCallOptions, args: GetLogicPropertiesValuesArgs): Promise<unknown>;
|
|
94
124
|
/** Layer 3: get_action_info. Returns _dynamic_tools. */
|
|
95
125
|
export declare function getActionInfo(options: ContextLoaderCallOptions, args: GetActionInfoArgs): Promise<unknown>;
|
|
126
|
+
/**
|
|
127
|
+
* Layer 3: find_skills. Recall skills attached to an object type or
|
|
128
|
+
* (optionally) narrowed to specific instances.
|
|
129
|
+
*/
|
|
130
|
+
export declare function findSkills(options: ContextLoaderCallOptions, args: FindSkillsArgs): Promise<FindSkillsResult>;
|
|
96
131
|
/** MCP tools/list. Returns list of available tools. */
|
|
97
132
|
export declare function listTools(options: ContextLoaderCallOptions, params?: {
|
|
98
133
|
cursor?: string;
|
|
@@ -149,7 +149,7 @@ async function callMcpMethod(options, method, params = {}) {
|
|
|
149
149
|
}
|
|
150
150
|
throw new Error("Context-loader returned no result");
|
|
151
151
|
}
|
|
152
|
-
async function callTool(options, toolName, args) {
|
|
152
|
+
export async function callTool(options, toolName, args) {
|
|
153
153
|
const sessionId = await ensureSession(options);
|
|
154
154
|
const id = (requestId += 1);
|
|
155
155
|
const body = JSON.stringify({
|
|
@@ -208,13 +208,21 @@ async function callTool(options, toolName, args) {
|
|
|
208
208
|
}
|
|
209
209
|
throw new Error("Context-loader returned no result");
|
|
210
210
|
}
|
|
211
|
-
/** Layer 1:
|
|
212
|
-
export async function
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
/** Layer 1: search_schema. Returns object_types, relation_types, action_types, metric_types. */
|
|
212
|
+
export async function searchSchema(options, args) {
|
|
213
|
+
const toolArgs = {
|
|
214
|
+
query: args.query,
|
|
215
|
+
response_format: args.response_format ?? "json",
|
|
216
|
+
};
|
|
217
|
+
if (args.search_scope !== undefined)
|
|
218
|
+
toolArgs.search_scope = args.search_scope;
|
|
219
|
+
if (args.max_concepts !== undefined)
|
|
220
|
+
toolArgs.max_concepts = args.max_concepts;
|
|
221
|
+
if (args.schema_brief !== undefined)
|
|
222
|
+
toolArgs.schema_brief = args.schema_brief;
|
|
223
|
+
if (args.enable_rerank !== undefined)
|
|
224
|
+
toolArgs.enable_rerank = args.enable_rerank;
|
|
225
|
+
return (await callTool(options, "search_schema", toolArgs));
|
|
218
226
|
}
|
|
219
227
|
/** Layer 2: query_object_instance. Returns datas with _instance_identity. */
|
|
220
228
|
export async function queryObjectInstance(options, args) {
|
|
@@ -240,6 +248,33 @@ export async function getActionInfo(options, args) {
|
|
|
240
248
|
validateInstanceIdentity(args._instance_identity, "_instance_identity");
|
|
241
249
|
return callTool(options, "get_action_info", { ...args });
|
|
242
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Layer 3: find_skills. Recall skills attached to an object type or
|
|
253
|
+
* (optionally) narrowed to specific instances.
|
|
254
|
+
*/
|
|
255
|
+
export async function findSkills(options, args) {
|
|
256
|
+
if (!args.object_type_id || typeof args.object_type_id !== "string") {
|
|
257
|
+
throw new Error("find_skills: object_type_id is required.");
|
|
258
|
+
}
|
|
259
|
+
if (args.top_k !== undefined && (args.top_k < 1 || args.top_k > 20)) {
|
|
260
|
+
throw new Error("find_skills: top_k must be between 1 and 20.");
|
|
261
|
+
}
|
|
262
|
+
if (args.instance_identities !== undefined) {
|
|
263
|
+
validateInstanceIdentities(args.instance_identities);
|
|
264
|
+
}
|
|
265
|
+
const toolArgs = {
|
|
266
|
+
object_type_id: args.object_type_id,
|
|
267
|
+
};
|
|
268
|
+
if (args.response_format !== undefined)
|
|
269
|
+
toolArgs.response_format = args.response_format;
|
|
270
|
+
if (args.instance_identities !== undefined)
|
|
271
|
+
toolArgs.instance_identities = args.instance_identities;
|
|
272
|
+
if (args.skill_query !== undefined)
|
|
273
|
+
toolArgs.skill_query = args.skill_query;
|
|
274
|
+
if (args.top_k !== undefined)
|
|
275
|
+
toolArgs.top_k = args.top_k;
|
|
276
|
+
return (await callTool(options, "find_skills", toolArgs));
|
|
277
|
+
}
|
|
243
278
|
/** MCP tools/list. Returns list of available tools. */
|
|
244
279
|
export async function listTools(options, params) {
|
|
245
280
|
return callMcpMethod(options, "tools/list", params ? { cursor: params.cursor } : {});
|
|
@@ -10,3 +10,12 @@ export interface SemanticSearchOptions {
|
|
|
10
10
|
returnQueryUnderstanding?: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare function semanticSearch(options: SemanticSearchOptions): Promise<string>;
|
|
13
|
+
export interface KnSearchHttpOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
accessToken: string;
|
|
16
|
+
knId: string;
|
|
17
|
+
query: string;
|
|
18
|
+
businessDomain?: string;
|
|
19
|
+
onlySchema?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function knSearchHttp(options: KnSearchHttpOptions): Promise<string>;
|
|
@@ -22,3 +22,22 @@ export async function semanticSearch(options) {
|
|
|
22
22
|
}
|
|
23
23
|
return body;
|
|
24
24
|
}
|
|
25
|
+
export async function knSearchHttp(options) {
|
|
26
|
+
const { baseUrl, accessToken, knId, query, businessDomain = "bd_public", onlySchema = false, } = options;
|
|
27
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
28
|
+
const url = `${base}/api/agent-retrieval/v1/kn/kn_search`;
|
|
29
|
+
const response = await fetch(url, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: { ...buildHeaders(accessToken, businessDomain), "content-type": "application/json" },
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
kn_id: knId,
|
|
34
|
+
query,
|
|
35
|
+
only_schema: onlySchema,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
const body = await response.text();
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new HttpError(response.status, response.statusText, body);
|
|
41
|
+
}
|
|
42
|
+
return body;
|
|
43
|
+
}
|
package/dist/api/skills.js
CHANGED
|
@@ -103,18 +103,20 @@ export async function updateSkillStatus(options) {
|
|
|
103
103
|
}
|
|
104
104
|
export async function registerSkillContent(options) {
|
|
105
105
|
const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills`);
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
const form = new FormData();
|
|
107
|
+
form.set("file_type", "content");
|
|
108
|
+
// Backend's gin form-binder rejects plain string field for `file`
|
|
109
|
+
// (typed json.RawMessage); needs an actual multipart file part with
|
|
110
|
+
// filename. See utils/gin.go GetBindMultipartFormRaw.
|
|
111
|
+
form.set("file", new Blob([options.content], { type: "text/markdown" }), "SKILL.md");
|
|
110
112
|
if (options.source)
|
|
111
|
-
|
|
113
|
+
form.set("source", options.source);
|
|
112
114
|
if (options.extendInfo)
|
|
113
|
-
|
|
115
|
+
form.set("extend_info", JSON.stringify(options.extendInfo));
|
|
114
116
|
const { body } = await fetchTextOrThrow(url, {
|
|
115
117
|
method: "POST",
|
|
116
|
-
headers:
|
|
117
|
-
body:
|
|
118
|
+
headers: baseHeaders(options),
|
|
119
|
+
body: form,
|
|
118
120
|
});
|
|
119
121
|
return normalizeSkillId(unwrapEnvelope(body));
|
|
120
122
|
}
|
package/dist/api/toolboxes.d.ts
CHANGED
|
@@ -44,6 +44,18 @@ export interface ListToolsOptions extends BaseOpts {
|
|
|
44
44
|
boxId: string;
|
|
45
45
|
}
|
|
46
46
|
export declare function listTools(opts: ListToolsOptions): Promise<string>;
|
|
47
|
+
export type ImpexType = "toolbox" | "mcp" | "operator";
|
|
48
|
+
export interface ExportConfigOptions extends BaseOpts {
|
|
49
|
+
id: string;
|
|
50
|
+
type?: ImpexType;
|
|
51
|
+
}
|
|
52
|
+
export declare function exportConfig(opts: ExportConfigOptions): Promise<Uint8Array>;
|
|
53
|
+
export interface ImportConfigOptions extends BaseOpts {
|
|
54
|
+
/** Path to a previously exported `.adp` JSON file. */
|
|
55
|
+
filePath: string;
|
|
56
|
+
type?: ImpexType;
|
|
57
|
+
}
|
|
58
|
+
export declare function importConfig(opts: ImportConfigOptions): Promise<string>;
|
|
47
59
|
export interface InvokeToolOptions extends BaseOpts {
|
|
48
60
|
boxId: string;
|
|
49
61
|
toolId: string;
|
package/dist/api/toolboxes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { basename } from "node:path";
|
|
3
|
-
import { fetchTextOrThrow } from "../utils/http.js";
|
|
3
|
+
import { HttpError, fetchTextOrThrow, fetchWithRetry } from "../utils/http.js";
|
|
4
4
|
import { buildHeaders } from "./headers.js";
|
|
5
5
|
// Backend endpoints under /api/agent-operator-integration/v1/tool-box.
|
|
6
6
|
//
|
|
@@ -97,6 +97,48 @@ export async function listTools(opts) {
|
|
|
97
97
|
});
|
|
98
98
|
return body;
|
|
99
99
|
}
|
|
100
|
+
// ── impex (export / import) ──────────────────────────────────────────────────
|
|
101
|
+
//
|
|
102
|
+
// Backend mounts the impex endpoints on the same service but under a different
|
|
103
|
+
// path:
|
|
104
|
+
//
|
|
105
|
+
// GET /api/agent-operator-integration/v1/impex/export/{type}/{id}
|
|
106
|
+
// POST /api/agent-operator-integration/v1/impex/import/{type} (multipart, field "data")
|
|
107
|
+
//
|
|
108
|
+
// Supported {type} values today: "toolbox" | "mcp" | "operator".
|
|
109
|
+
//
|
|
110
|
+
// Export response is the raw JSON config (Content-Type: application/json) plus
|
|
111
|
+
// a `Content-Disposition: attachment; filename=<type>_export_<ts>.adp` header.
|
|
112
|
+
const IMPEX_PATH = "/api/agent-operator-integration/v1/impex";
|
|
113
|
+
export async function exportConfig(opts) {
|
|
114
|
+
const t = opts.type ?? "toolbox";
|
|
115
|
+
const target = `${opts.baseUrl.replace(/\/+$/, "")}${IMPEX_PATH}/export/${encodeURIComponent(t)}/${encodeURIComponent(opts.id)}`;
|
|
116
|
+
// Use raw bytes (not text) so we never lose precision on non-ASCII payloads
|
|
117
|
+
// and stay symmetric with the Python SDK's `export_config -> bytes`.
|
|
118
|
+
const response = await fetchWithRetry(target, {
|
|
119
|
+
method: "GET",
|
|
120
|
+
headers: buildHeaders(opts.accessToken, opts.businessDomain ?? "bd_public"),
|
|
121
|
+
});
|
|
122
|
+
const buf = new Uint8Array(await response.arrayBuffer());
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
const text = new TextDecoder("utf-8").decode(buf);
|
|
125
|
+
throw new HttpError(response.status, response.statusText, text);
|
|
126
|
+
}
|
|
127
|
+
return buf;
|
|
128
|
+
}
|
|
129
|
+
export async function importConfig(opts) {
|
|
130
|
+
const buf = await readFile(opts.filePath);
|
|
131
|
+
const t = opts.type ?? "toolbox";
|
|
132
|
+
const form = new FormData();
|
|
133
|
+
form.append("data", new Blob([buf]), basename(opts.filePath));
|
|
134
|
+
const target = `${opts.baseUrl.replace(/\/+$/, "")}${IMPEX_PATH}/import/${encodeURIComponent(t)}`;
|
|
135
|
+
const { body } = await fetchTextOrThrow(target, {
|
|
136
|
+
method: "POST",
|
|
137
|
+
headers: buildHeaders(opts.accessToken, opts.businessDomain ?? "bd_public"),
|
|
138
|
+
body: form,
|
|
139
|
+
});
|
|
140
|
+
return body;
|
|
141
|
+
}
|
|
100
142
|
function buildEnvelope(opts) {
|
|
101
143
|
const envelope = {};
|
|
102
144
|
if (opts.timeout !== undefined)
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ function printHelp() {
|
|
|
19
19
|
console.log(`kweaver
|
|
20
20
|
|
|
21
21
|
Usage:
|
|
22
|
-
kweaver [--user <userId|username>] <command> [options]
|
|
22
|
+
kweaver [--base-url <url>] [--token <access-token>] [--user <userId|username>] <command> [options]
|
|
23
23
|
kweaver --version | -V
|
|
24
24
|
kweaver --help | -h
|
|
25
25
|
|
|
@@ -39,42 +39,43 @@ Usage:
|
|
|
39
39
|
kweaver token
|
|
40
40
|
|
|
41
41
|
kweaver call <url> [-X METHOD] [-H "Name: value"] [-d BODY] [--data-raw BODY]
|
|
42
|
-
[--url URL] [--
|
|
42
|
+
[--url URL] [--verbose] [-bd value]
|
|
43
43
|
(alias: kweaver curl ...)
|
|
44
44
|
|
|
45
45
|
kweaver agent chat <agent_id> [-m "message"] [--version value] [--conversation-id id]
|
|
46
46
|
[--stream] [--no-stream] [--verbose] [-bd value]
|
|
47
|
-
kweaver agent list [--name X] [--limit N] [--offset N] [-bd value]
|
|
48
|
-
kweaver agent get <agent_id> [-bd value]
|
|
49
|
-
kweaver agent get-by-key <key> [-bd value]
|
|
50
|
-
kweaver agent sessions <agent_id> [-bd value] [--limit N]
|
|
51
|
-
kweaver agent history <conversation_id> [-bd value] [--limit N]
|
|
47
|
+
kweaver agent list [--name X] [--limit N] [--offset N] [-bd value]
|
|
48
|
+
kweaver agent get <agent_id> [-bd value]
|
|
49
|
+
kweaver agent get-by-key <key> [-bd value]
|
|
50
|
+
kweaver agent sessions <agent_id> [-bd value] [--limit N]
|
|
51
|
+
kweaver agent history <conversation_id> [-bd value] [--limit N]
|
|
52
52
|
kweaver agent create [options]
|
|
53
53
|
kweaver agent update <agent_id> [options]
|
|
54
54
|
kweaver agent delete <agent_id> [-bd value]
|
|
55
55
|
kweaver agent publish <agent_id> [-bd value]
|
|
56
56
|
kweaver agent unpublish <agent_id> [-bd value]
|
|
57
57
|
|
|
58
|
-
kweaver ds list [--keyword X] [--type T] [-bd value]
|
|
58
|
+
kweaver ds list [--keyword X] [--type T] [-bd value]
|
|
59
59
|
kweaver ds get <id>
|
|
60
60
|
kweaver ds delete <id> [-y]
|
|
61
|
-
kweaver ds tables <id> [--keyword X]
|
|
61
|
+
kweaver ds tables <id> [--keyword X]
|
|
62
62
|
kweaver ds connect <db_type> <host> <port> <database> --account X --password Y [--schema S] [--name N]
|
|
63
|
+
[--reuse-existing|--force-new]
|
|
63
64
|
|
|
64
65
|
kweaver dataflow list [-bd value]
|
|
65
66
|
kweaver dataflow run <dagId> (--file <path> | --url <remote-url> --name <filename>) [-bd value]
|
|
66
67
|
kweaver dataflow runs <dagId> [--since <date-like>] [-bd value]
|
|
67
68
|
kweaver dataflow logs <dagId> <instanceId> [--detail] [-bd value]
|
|
68
69
|
|
|
69
|
-
kweaver dataview list [--datasource-id id] [--type atomic|custom] [--limit n] [-bd value]
|
|
70
|
-
kweaver dataview find --name <name> [--exact] [--datasource-id id] [--wait] [--timeout ms] [-bd value]
|
|
71
|
-
kweaver dataview get <id> [-bd value]
|
|
72
|
-
kweaver dataview query <id> [--sql sql] [--limit n] [--offset n] [--need-total] [--raw-sql] [-bd value]
|
|
70
|
+
kweaver dataview list [--datasource-id id] [--type atomic|custom] [--limit n] [-bd value]
|
|
71
|
+
kweaver dataview find --name <name> [--exact] [--datasource-id id] [--wait] [--timeout ms] [-bd value]
|
|
72
|
+
kweaver dataview get <id> [-bd value]
|
|
73
|
+
kweaver dataview query <id> [--sql sql] [--limit n] [--offset n] [--need-total] [--raw-sql] [-bd value]
|
|
73
74
|
kweaver dataview delete <id> [-y] [-bd value]
|
|
74
75
|
|
|
75
76
|
kweaver bkn list [options]
|
|
76
77
|
kweaver bkn get <kn-id> [options]
|
|
77
|
-
kweaver bkn search <kn-id> <query> [--max-concepts N] [--mode M] [
|
|
78
|
+
kweaver bkn search <kn-id> <query> [--max-concepts N] [--mode M] [-bd value]
|
|
78
79
|
kweaver bkn create [options]
|
|
79
80
|
kweaver bkn create-from-ds [options]
|
|
80
81
|
kweaver bkn update <kn-id> [options]
|
|
@@ -107,6 +108,8 @@ Usage:
|
|
|
107
108
|
kweaver toolbox list [--keyword X] [--limit N] [--offset N] [-bd value]
|
|
108
109
|
kweaver toolbox publish|unpublish <box-id> [-bd value]
|
|
109
110
|
kweaver toolbox delete <box-id> [-y] [-bd value]
|
|
111
|
+
kweaver toolbox export <box-id> [-o <file>|-] [--type toolbox|mcp|operator]
|
|
112
|
+
kweaver toolbox import <file> [--type toolbox|mcp|operator]
|
|
110
113
|
|
|
111
114
|
kweaver tool upload --toolbox <box-id> <openapi-spec-path> [--metadata-type openapi]
|
|
112
115
|
kweaver tool list --toolbox <box-id> [-bd value]
|
|
@@ -121,17 +124,25 @@ Usage:
|
|
|
121
124
|
kweaver vega query execute|sql [options]
|
|
122
125
|
kweaver vega connector-type list|get [options]
|
|
123
126
|
|
|
124
|
-
kweaver context-loader config set|use|list|remove|show [options]
|
|
125
|
-
kweaver context-loader tools|resources|templates|prompts [--cursor]
|
|
126
|
-
kweaver context-loader resource <uri>
|
|
127
|
-
kweaver context-loader prompt <name> [--args json]
|
|
128
|
-
kweaver context-loader kn-
|
|
129
|
-
kweaver context-loader kn-
|
|
130
|
-
kweaver context-loader
|
|
127
|
+
kweaver context-loader config set|use|list|remove|show [options] (deprecated; not supported with --token)
|
|
128
|
+
kweaver context-loader tools|resources|templates|prompts <kn-id> [--cursor]
|
|
129
|
+
kweaver context-loader resource <kn-id> <uri>
|
|
130
|
+
kweaver context-loader prompt <kn-id> <name> [--args json]
|
|
131
|
+
kweaver context-loader search-schema <kn-id> <query> [--scope object,relation,action,metric] [--max N]
|
|
132
|
+
kweaver context-loader tool-call <kn-id> <name> --args '<json>'
|
|
133
|
+
kweaver context-loader kn-search <kn-id> <query> [--only-schema] (compat HTTP)
|
|
134
|
+
kweaver context-loader kn-schema-search <kn-id> <query> [--max N] (compat HTTP)
|
|
135
|
+
kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info|find-skills <kn-id> ...
|
|
136
|
+
(omit <kn-id> to fall back to deprecated saved config)
|
|
131
137
|
(alias: kweaver context ...)
|
|
132
138
|
|
|
133
139
|
Global options:
|
|
140
|
+
--base-url <url> Override platform base URL for this command (env: KWEAVER_BASE_URL)
|
|
141
|
+
--token <value> Override access token for this command (env: KWEAVER_TOKEN; disables write-to-disk commands)
|
|
134
142
|
--user <id|name> Use a specific user's credentials for this command (env: KWEAVER_USER)
|
|
143
|
+
--pretty / --compact
|
|
144
|
+
Toggle pretty-printed JSON output. Supported by every
|
|
145
|
+
command that prints a JSON payload (default: pretty).
|
|
135
146
|
|
|
136
147
|
Commands:
|
|
137
148
|
auth Login, list, inspect, and switch saved platform auth profiles
|
|
@@ -145,10 +156,10 @@ Commands:
|
|
|
145
156
|
object-type, relation-type, subgraph, action-type, action-execution, action-log)
|
|
146
157
|
config Per-platform configuration (business domain)
|
|
147
158
|
skill Skill registry and market (register, search, progressive read, download/install)
|
|
148
|
-
toolbox Agent toolbox lifecycle (create, list, publish, delete)
|
|
159
|
+
toolbox Agent toolbox lifecycle (create, list, publish, delete, export, import)
|
|
149
160
|
tool Tools inside a toolbox (upload OpenAPI spec, list, enable/disable)
|
|
150
161
|
vega Vega observability (catalog, resource, query/sql, connector-type, health/stats/inspect)
|
|
151
|
-
context-loader Context-loader MCP (config, tools, resources,
|
|
162
|
+
context-loader Context-loader MCP/HTTP (config, tools, resources, search-schema, tool-call, query-*, etc.)
|
|
152
163
|
help Show this message`);
|
|
153
164
|
}
|
|
154
165
|
export async function run(argv) {
|
|
@@ -158,12 +169,40 @@ export async function run(argv) {
|
|
|
158
169
|
!process.env.KWEAVER_TOKEN) {
|
|
159
170
|
process.env.KWEAVER_TOKEN = NO_AUTH_TOKEN;
|
|
160
171
|
}
|
|
161
|
-
// Global
|
|
162
|
-
|
|
172
|
+
// Global flags consumed before subcommand dispatch.
|
|
173
|
+
// Pattern follows --user (legacy): each flag, if present, is removed from argv
|
|
174
|
+
// and projected into a process.env value that downstream resolvers already read.
|
|
163
175
|
let filteredArgv = argv;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
176
|
+
function consumeFlag(flag) {
|
|
177
|
+
const idx = filteredArgv.indexOf(flag);
|
|
178
|
+
if (idx === -1 || idx + 1 >= filteredArgv.length)
|
|
179
|
+
return undefined;
|
|
180
|
+
const value = filteredArgv[idx + 1];
|
|
181
|
+
filteredArgv = [...filteredArgv.slice(0, idx), ...filteredArgv.slice(idx + 2)];
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
const userVal = consumeFlag("--user");
|
|
185
|
+
if (userVal)
|
|
186
|
+
process.env.KWEAVER_USER = userVal;
|
|
187
|
+
const tokenVal = consumeFlag("--token");
|
|
188
|
+
const baseUrlVal = consumeFlag("--base-url");
|
|
189
|
+
if (tokenVal) {
|
|
190
|
+
process.env.KWEAVER_TOKEN = tokenVal;
|
|
191
|
+
process.env.KWEAVER_TOKEN_SOURCE = "flag";
|
|
192
|
+
}
|
|
193
|
+
if (baseUrlVal) {
|
|
194
|
+
process.env.KWEAVER_BASE_URL = baseUrlVal;
|
|
195
|
+
}
|
|
196
|
+
// --token requires a base URL from somewhere; fail fast with guidance.
|
|
197
|
+
if (tokenVal && !process.env.KWEAVER_BASE_URL) {
|
|
198
|
+
const { getCurrentPlatform } = await import("./config/store.js");
|
|
199
|
+
if (!getCurrentPlatform()) {
|
|
200
|
+
console.error("--token requires a base URL. Provide one of:\n" +
|
|
201
|
+
" --base-url <url>\n" +
|
|
202
|
+
" export KWEAVER_BASE_URL=<url>\n" +
|
|
203
|
+
" kweaver auth login <url> (save once, reuse later)");
|
|
204
|
+
return 1;
|
|
205
|
+
}
|
|
167
206
|
}
|
|
168
207
|
const [command, ...rest] = filteredArgv;
|
|
169
208
|
if (command === "--version" || command === "-V" || command === "version") {
|