bailian-kb-dsh 0.1.19 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -57
- package/README.zh.md +21 -57
- package/cordis.patch.yml +3 -10
- package/dist/bl-cli.d.ts +2 -2
- package/dist/bl-cli.js +10 -2
- package/dist/client.d.ts +1 -1
- package/dist/configuration.d.ts +18 -0
- package/dist/configuration.js +27 -0
- package/dist/console-login.d.ts +10 -0
- package/dist/console-login.js +34 -4
- package/dist/credentials.d.ts +16 -0
- package/dist/credentials.js +39 -0
- package/dist/index.d.ts +24 -35
- package/dist/index.js +182 -358
- package/dist/management.d.ts +19 -0
- package/dist/management.js +94 -0
- package/dist/service-cache.d.ts +2 -0
- package/dist/service-cache.js +6 -0
- package/dist/service-catalog.d.ts +2 -2
- package/dist/service-catalog.js +3 -3
- package/dist/service-context.d.ts +12 -0
- package/dist/service-context.js +5 -5
- package/dist/tools.d.ts +3 -3
- package/dist/tools.js +7 -9
- package/dist/web/client.js +679 -922
- package/dist/web/client.js.map +1 -1
- package/package.json +37 -34
- package/skills/bailian-kb/SKILL.md +13 -12
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
[](https://www.typescriptlang.org)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
|
|
12
|
-
[Bailian Console](https://bailian.console.aliyun.com
|
|
12
|
+
[Bailian Console](https://bailian.console.aliyun.com/?spm=a2ty07.github) · [中文文档](README.zh.md) · [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) · [API Documentation](https://help.aliyun.com/zh/model-studio/)
|
|
13
13
|
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
16
|
## What is this?
|
|
17
17
|
|
|
18
|
-
`bailian-kb-dsh` is a plugin (and dsh bundle) that gives a DeepSeek Harness agent access to knowledge bases hosted on [Aliyun Model Studio](https://bailian.console.aliyun.com
|
|
18
|
+
`bailian-kb-dsh` is a plugin (and dsh bundle) that gives a DeepSeek Harness agent access to knowledge bases hosted on [Aliyun Model Studio](https://bailian.console.aliyun.com/?spm=a2ty07.github) (Bailian). It registers two model-facing tools — `kb_search` for raw evidence and `kb_chat` for grounded answers — and ships a settings page plus a management skill for the [`bl` CLI](https://www.npmjs.com/package/bailian-cli).
|
|
19
19
|
|
|
20
20
|
Retrieval happens through **retrieval services** you deploy on Bailian: a service binds one or more knowledge bases to an embedding/rerank configuration and is addressed by its `agent_id`. The plugin keeps the list of deployed services in front of the model, so it can decide whether the question is answerable from your knowledge at all.
|
|
21
21
|
|
|
@@ -30,8 +30,8 @@ Retrieval happens through **retrieval services** you deploy on Bailian: a servic
|
|
|
30
30
|
## Requirements
|
|
31
31
|
|
|
32
32
|
- DeepSeek Harness with its plugin runtime (`@deepseek-ai/dsh-*`), Node.js >= 22.12
|
|
33
|
-
- An Aliyun Model Studio account: a **workspace id** and a **DashScope API key** ([get one](https://bailian.console.aliyun.com/?tab=app#/api-key))
|
|
34
|
-
- At least one **deployed** retrieval or Q&A service in that workspace — create one in the [console](https://bailian.console.aliyun.com
|
|
33
|
+
- An Aliyun Model Studio account: a **workspace id** and a **DashScope API key** ([get one](https://bailian.console.aliyun.com/?spm=a2ty07.github&tab=app#/api-key))
|
|
34
|
+
- At least one **deployed** retrieval or Q&A service in that workspace — create one in the [console](https://bailian.console.aliyun.com/?spm=a2ty07.github) or with `bl knowledge service create` / `bl knowledge service deploy`
|
|
35
35
|
- The [`bl` CLI](https://www.npmjs.com/package/bailian-cli) (`npm install -g bailian-cli`) for anything on the management side — creating knowledge bases, ingesting documents, deploying services. Retrieval itself calls the API directly and never shells out, so `kb_search` / `kb_chat` work without it
|
|
36
36
|
|
|
37
37
|
## Installation
|
|
@@ -50,64 +50,25 @@ Verify the plugin is composed — `dsh --profile web --dump-config` should list
|
|
|
50
50
|
|
|
51
51
|
## Configuration
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Configure the plugin from its dsh settings page. The API key belongs only to this plugin in dsh credentials (`BAILIAN_KB_API_KEY`, normally `~/.dsh/.credentials.yaml`; the host owns the actual path). All business settings belong exclusively to this plugin's dsh configuration:
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
| Field | Meaning | Default |
|
|
56
|
+
| ------------------------ | ----------------------------------------- | ---------------- |
|
|
57
|
+
| `workspaceId` | Workspace for all knowledge calls | Required |
|
|
58
|
+
| `defaultRetrieveAgentId` | Default retrieval service | Unset |
|
|
59
|
+
| `defaultChatAgentId` | Default Q&A service | Unset |
|
|
60
|
+
| `agentVersion` | Draft `beta` or published service version | Latest published |
|
|
61
|
+
| `chatTimeoutMs` | Chat timeout in milliseconds | 300000 |
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
- **API key** — write-only: the stored value is never echoed back, only reported as configured or not.
|
|
59
|
-
- **Workspace id / default retrieval service / default Q&A service** — editable with echo; the service ids can be picked from the cached service list. Clearing a value falls back to the layers below.
|
|
60
|
-
- **Retrieval service cache** — shows when the injected service list was last fetched, how many services it holds, and offers a manual refresh for a service you just created.
|
|
63
|
+
The endpoint is fixed to `cn-beijing.maas.aliyuncs.com`. There is no endpoint setting. Settings page edits apply to the next call.
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
At startup, a missing API key may be imported from the active profile in `~/.bailian/config.json`. On the first configuration migration, missing workspace/default-service fields are imported from legacy dsh credentials, with the bl profile as the workspace default. Explicit dsh settings win. The internal `configInitialized` marker prevents cleared settings from being imported again. A missing API key can still be seeded on subsequent startups.
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
After initialization, business fields are read only from dsh plugin settings, never from bl or legacy credential fields. Clearing Workspace makes calls fail until it is configured again. Console login saves the key in dsh credentials and Workspace in dsh settings. KB does not create a `personal-kb/config.json` file.
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
# ~/.dsh/.env, or the credential store at ~/.dsh/.credentials.yaml
|
|
68
|
-
DASHSCOPE_API_KEY=sk-xxx # required
|
|
69
|
-
BAILIAN_WORKSPACE_ID=ws-xxx # required
|
|
70
|
-
BAILIAN_DEFAULT_RETRIEVE_AGENT_ID=aid-xxx # optional
|
|
71
|
-
BAILIAN_DEFAULT_CHAT_AGENT_ID=aid-xxx # optional
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Option 3 — Profile patch
|
|
75
|
-
|
|
76
|
-
The bundle inserts its own entry into the profile; you can override it by id in `~/.dsh/cordis.patch.yml` or the profile's patch file. An override **replaces the whole config object** (no deep merge):
|
|
77
|
-
|
|
78
|
-
```yaml
|
|
79
|
-
- id: tool-bailian-kb
|
|
80
|
-
config:
|
|
81
|
-
defaultRetrieveAgentId: aid-search-service
|
|
82
|
-
defaultChatAgentId: aid-chat-service
|
|
83
|
-
chatTimeoutMs: 600000
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Disable the plugin with `- id: tool-bailian-kb` plus `disabled: true`.
|
|
69
|
+
The connection panel also accepts a new API key in a password field. Leave it blank to retain the current key, then use **Verify and save** to validate the key/Workspace pair before saving. Failed validation changes neither value; a settings-write failure attempts to restore the previous pair. The key is never read back and the input is cleared after success. Each plugin keeps its own API key and Workspace; editing one plugin does not affect the other. A key supplied by the launch environment must be changed there.
|
|
87
70
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
The config doubles as the `bailian-kb` settings section, so edits in the settings page or settings document apply to the next call without a restart.
|
|
91
|
-
|
|
92
|
-
| Field | Type | Default | Meaning |
|
|
93
|
-
| ------------------------ | ------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
94
|
-
| `workspaceId` | string? | — | Bailian workspace id; the API host is the workspace subdomain `https://<workspaceId>.<endpointHost>` |
|
|
95
|
-
| `endpointHost` | string | `cn-beijing.maas.aliyuncs.com` | Host suffix; replace for another region or a private deployment |
|
|
96
|
-
| `defaultRetrieveAgentId` | string? | — | Service `kb_search` falls back to when the caller omits `agent_id` |
|
|
97
|
-
| `defaultChatAgentId` | string? | — | Service `kb_chat` falls back to when the caller omits `agent_id` |
|
|
98
|
-
| `agentVersion` | string? | — | `beta` (draft) or a published version number; defaults to the latest published version. Not exposed to the model |
|
|
99
|
-
| `chatTimeoutMs` | number | `300000` | `kb_chat` timeout — the server side is a minutes-scale agentic loop |
|
|
100
|
-
|
|
101
|
-
### Resolution order
|
|
102
|
-
|
|
103
|
-
| Value | Settings layer (settings page) | Entry config (profile patch) | Credential store / env |
|
|
104
|
-
| ------------------------- | ------------------------------ | ---------------------------- | ----------------------------------- |
|
|
105
|
-
| `DASHSCOPE_API_KEY` | write-only control | — | `DASHSCOPE_API_KEY` |
|
|
106
|
-
| workspace id | ✅ `workspaceId` | ✅ `workspaceId` | `BAILIAN_WORKSPACE_ID` |
|
|
107
|
-
| default retrieval service | ✅ `defaultRetrieveAgentId` | ✅ `defaultRetrieveAgentId` | `BAILIAN_DEFAULT_RETRIEVE_AGENT_ID` |
|
|
108
|
-
| default Q&A service | ✅ `defaultChatAgentId` | ✅ `defaultChatAgentId` | `BAILIAN_DEFAULT_CHAT_AGENT_ID` |
|
|
109
|
-
|
|
110
|
-
Every value is re-read per call, so a rotated key or a switched workspace takes effect immediately. The API key and workspace id are mandatory: without them the tools fail with a message pointing at these configuration paths. Default services are optional — when the workspace has exactly one deployed service for a scene, that one is used.
|
|
71
|
+
Management uses `kb_manage` with arguments after `bl knowledge`, for example `{"args":["service","list","--scene","search"]}`. The host executes the installed `bl` executable with a temporary isolated config directory and the same current key/Workspace as the native tools. Connection override flags are rejected. Secrets are passed through the child environment, never tool arguments. Direct shell invocation of bl remains independent and is not the plugin management path.
|
|
111
72
|
|
|
112
73
|
## Tools
|
|
113
74
|
|
|
@@ -115,6 +76,7 @@ Every value is re-read per call, so a rotated key or a switched workspace takes
|
|
|
115
76
|
| ----------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
116
77
|
| `kb_search` | `query`, `agent_id` (required), `top_k?` (default 5, applied client-side), `images?` (image URLs for multimodal) | Scored chunks with source references, plus a total |
|
|
117
78
|
| `kb_chat` | `message`, `agent_id` (required) | The complete answer plus a `request_id` |
|
|
79
|
+
| `kb_manage` | `args` | Knowledge management using dsh configuration |
|
|
118
80
|
|
|
119
81
|
`agent_id` is required in both schemas: the schema cannot tell the model whether this deployment pins a default, and discovering a missing default at call time wastes a round-trip. The configured default is still honoured for programmatic calls that omit it.
|
|
120
82
|
|
|
@@ -148,7 +110,7 @@ For local integration, add the working copy to a dev profile (the patch file is
|
|
|
148
110
|
dsh plugin --profile dev add <this-repo>/packages/bailian-kb-dsh
|
|
149
111
|
```
|
|
150
112
|
|
|
151
|
-
|
|
113
|
+
Maintenance checklist: [docs/agents/dsh-plugin.md](https://github.com/modelstudioai/cli/blob/main/docs/agents/dsh-plugin.md).
|
|
152
114
|
|
|
153
115
|
## Contributing
|
|
154
116
|
|
|
@@ -157,3 +119,5 @@ Bug reports, feature requests, and PRs are welcome. See [CONTRIBUTING.md](https:
|
|
|
157
119
|
## License
|
|
158
120
|
|
|
159
121
|
[Apache 2.0](LICENSE)
|
|
122
|
+
|
|
123
|
+
The former shared `DASHSCOPE_API_KEY` is no longer read, modified, or deleted. If the plugin-specific key is absent and bl has no default to import, save a key on each plugin’s page.
|
package/README.zh.md
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
[](https://www.typescriptlang.org)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
|
|
12
|
-
[百炼控制台](https://bailian.console.aliyun.com
|
|
12
|
+
[百炼控制台](https://bailian.console.aliyun.com/?spm=a2ty07.github) · [English](README.md) · [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) · [API 文档](https://help.aliyun.com/zh/model-studio/)
|
|
13
13
|
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
16
|
## 这是什么?
|
|
17
17
|
|
|
18
|
-
`bailian-kb-dsh` 是一个 DeepSeek Harness 插件(同时是 dsh bundle),让 agent 能检索托管在[阿里云百炼](https://bailian.console.aliyun.com
|
|
18
|
+
`bailian-kb-dsh` 是一个 DeepSeek Harness 插件(同时是 dsh bundle),让 agent 能检索托管在[阿里云百炼](https://bailian.console.aliyun.com/?spm=a2ty07.github)上的知识库。它注册两个面向模型的工具 —— `kb_search` 取原始证据、`kb_chat` 出成品答案 —— 并附带一个设置页和一份面向 [`bl` CLI](https://www.npmjs.com/package/bailian-cli) 的管理 skill。
|
|
19
19
|
|
|
20
20
|
检索经由你在百炼上部署的**检索服务**完成:一个服务把一个或多个知识库绑定到指定的向量 / 排序配置上,通过 `agent_id` 寻址。插件会把已部署服务的清单持续呈现给模型,让它能判断用户的问题是否落在你的知识范围内。
|
|
21
21
|
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
## 环境要求
|
|
31
31
|
|
|
32
32
|
- DeepSeek Harness 及其插件运行时(`@deepseek-ai/dsh-*`),Node.js >= 22.12
|
|
33
|
-
- 阿里云百炼账号:一个**工作空间 ID** 和一个 **DashScope API 密钥**([去获取](https://bailian.console.aliyun.com/?tab=app#/api-key))
|
|
34
|
-
- 该工作空间下至少有一个**已部署**的检索或问答服务 —— 可在[控制台](https://bailian.console.aliyun.com
|
|
33
|
+
- 阿里云百炼账号:一个**工作空间 ID** 和一个 **DashScope API 密钥**([去获取](https://bailian.console.aliyun.com/?spm=a2ty07.github&tab=app#/api-key))
|
|
34
|
+
- 该工作空间下至少有一个**已部署**的检索或问答服务 —— 可在[控制台](https://bailian.console.aliyun.com/?spm=a2ty07.github)创建,或用 `bl knowledge service create` / `bl knowledge service deploy`
|
|
35
35
|
- 管理面的事(建库、导入文档、部署服务)需要 [`bl` CLI](https://www.npmjs.com/package/bailian-cli)(`npm install -g bailian-cli`)。检索本身直连 API、从不起子进程,所以 `kb_search` / `kb_chat` 不装也能用
|
|
36
36
|
|
|
37
37
|
## 安装
|
|
@@ -50,64 +50,25 @@ dsh plugin --profile web remove bailian-kb-dsh
|
|
|
50
50
|
|
|
51
51
|
## 配置
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
通过 dsh 插件设置页配置。API Key 独立使用 dsh credentials 中的 `BAILIAN_KB_API_KEY`(通常为 `~/.dsh/.credentials.yaml`,实际路径由宿主决定)。所有业务设置只保存到本插件的 dsh 配置:
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
| 字段 | 含义 | 默认值 |
|
|
56
|
+
| ------------------------ | ------------------------------ | ---------- |
|
|
57
|
+
| `workspaceId` | 所有知识库调用使用的 Workspace | 必填 |
|
|
58
|
+
| `defaultRetrieveAgentId` | 默认检索服务 | 未设置 |
|
|
59
|
+
| `defaultChatAgentId` | 默认问答服务 | 未设置 |
|
|
60
|
+
| `agentVersion` | 草稿 `beta` 或已发布服务版本 | 最新发布版 |
|
|
61
|
+
| `chatTimeoutMs` | 问答超时,毫秒 | 300000 |
|
|
56
62
|
|
|
57
|
-
-
|
|
58
|
-
- **API 密钥** — 只写不回显:存下的值不会再次显示,只显示"已配置 / 未配置"。
|
|
59
|
-
- **工作空间 ID / 默认检索服务 / 默认对话服务** — 可编辑且回显;两个服务 ID 可从缓存的服务清单里选。清空保存则回退到下层来源。
|
|
60
|
-
- **检索服务缓存** — 展示注入清单的上次拉取时间、各场景服务条数、是否被截断,并提供手动刷新(刚新建完服务想立刻生效时用)。
|
|
63
|
+
端点固定为 `cn-beijing.maas.aliyuncs.com`,不提供端点配置。在设置页保存后,下一次调用即生效。
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
启动时,缺失的 API Key 可以从 `~/.bailian/config.json` 当前激活的 Profile 导入。首次配置迁移时,缺失的 Workspace 和默认服务从旧 dsh 凭据导入,Workspace 再以 bl Profile 作为初始默认值;已有 dsh 设置优先。内部 `configInitialized` 标记确保清空的设置不会被再次填入。缺失的 API Key 仍允许在后续启动时补入。
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
初始化完成后,业务字段只读 dsh 插件配置,不再读取 bl 或旧凭据字段。清空 Workspace 后,调用会报缺配置。控制台登录把 Key 保存到 dsh credentials,把 Workspace 保存到 dsh 设置。kb 不创建 `personal-kb/config.json`。
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
# ~/.dsh/.env,或凭据存储 ~/.dsh/.credentials.yaml
|
|
68
|
-
DASHSCOPE_API_KEY=sk-xxx # 必填
|
|
69
|
-
BAILIAN_WORKSPACE_ID=ws-xxx # 必填
|
|
70
|
-
BAILIAN_DEFAULT_RETRIEVE_AGENT_ID=aid-xxx # 选填
|
|
71
|
-
BAILIAN_DEFAULT_CHAT_AGENT_ID=aid-xxx # 选填
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 方式三 — Profile patch
|
|
75
|
-
|
|
76
|
-
bundle 会向 profile 插入自己的 entry,你可以在 `~/.dsh/cordis.patch.yml` 或 profile 的 patch 文件里按 id 覆盖。覆盖时**替换整个 config 对象(无 deep-merge)**:
|
|
77
|
-
|
|
78
|
-
```yaml
|
|
79
|
-
- id: tool-bailian-kb
|
|
80
|
-
config:
|
|
81
|
-
defaultRetrieveAgentId: aid-search-service
|
|
82
|
-
defaultChatAgentId: aid-chat-service
|
|
83
|
-
chatTimeoutMs: 600000
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
禁用插件:`- id: tool-bailian-kb` 加 `disabled: true`。
|
|
69
|
+
连接区域支持在密码输入框中填写新 API Key,留空表示保留当前 Key。点击**验证并保存**会先验证 Key 与 Workspace 的组合,再保存;验证失败不修改配置,设置写入失败时尝试恢复原配置。旧 Key 不回显,保存成功后清空输入框。知识库和记忆插件各自使用独立的 Key 与 Workspace,修改互不影响。来自启动环境的 Key 需要在启动环境中修改。
|
|
87
70
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Config 同时注册为 `bailian-kb` settings section,因此在设置页或设置文档里的修改会在下一次调用生效,无需重启。
|
|
91
|
-
|
|
92
|
-
| 字段 | 类型 | 默认值 | 语义 |
|
|
93
|
-
| ------------------------ | ------- | ------------------------------ | --------------------------------------------------------------------------------- |
|
|
94
|
-
| `workspaceId` | string? | — | 百炼工作空间 ID;API host 为工作空间子域名 `https://<workspaceId>.<endpointHost>` |
|
|
95
|
-
| `endpointHost` | string | `cn-beijing.maas.aliyuncs.com` | host 后缀,其他 region 或私有化部署时替换 |
|
|
96
|
-
| `defaultRetrieveAgentId` | string? | — | 调用方省略 `agent_id` 时 `kb_search` 使用的服务 |
|
|
97
|
-
| `defaultChatAgentId` | string? | — | 调用方省略 `agent_id` 时 `kb_chat` 使用的服务 |
|
|
98
|
-
| `agentVersion` | string? | — | `beta`(草稿调试)或已发布版本号;默认调用最新发布版本。不暴露给模型 |
|
|
99
|
-
| `chatTimeoutMs` | number | `300000` | `kb_chat` 超时时间 —— 服务端是分钟级的多轮检索循环 |
|
|
100
|
-
|
|
101
|
-
### 解析优先级
|
|
102
|
-
|
|
103
|
-
| 值 | settings 用户层(设置页) | entry config(profile patch) | 凭据存储 / 环境变量 |
|
|
104
|
-
| ------------------- | --------------------------- | ----------------------------- | ----------------------------------- |
|
|
105
|
-
| `DASHSCOPE_API_KEY` | 只写控件 | — | `DASHSCOPE_API_KEY` |
|
|
106
|
-
| 工作空间 ID | ✅ `workspaceId` | ✅ `workspaceId` | `BAILIAN_WORKSPACE_ID` |
|
|
107
|
-
| 默认检索服务 | ✅ `defaultRetrieveAgentId` | ✅ `defaultRetrieveAgentId` | `BAILIAN_DEFAULT_RETRIEVE_AGENT_ID` |
|
|
108
|
-
| 默认对话服务 | ✅ `defaultChatAgentId` | ✅ `defaultChatAgentId` | `BAILIAN_DEFAULT_CHAT_AGENT_ID` |
|
|
109
|
-
|
|
110
|
-
所有值每次调用重新解析,因此轮换密钥或切换工作空间即时生效。API 密钥与工作空间 ID 是必填项:缺失时工具调用会报错并指出上述配置路径。默认服务是选填的 —— 当某个场景下工作空间只有一个已部署服务时,直接用它。
|
|
71
|
+
管理操作使用 `kb_manage`,参数为 `bl knowledge` 之后的数组,例如 `{"args":["service","list","--scene","search"]}`。宿主内部执行已安装的 bl,使用临时隔离配置目录,并注入与原生工具相同的当前 Key 和 Workspace;不允许通过参数覆盖连接配置。密钥只通过子进程环境传递,不进入工具参数。直接在 shell 中运行 bl 仍是独立 CLI,不是插件管理入口。
|
|
111
72
|
|
|
112
73
|
## 工具
|
|
113
74
|
|
|
@@ -115,6 +76,7 @@ Config 同时注册为 `bailian-kb` settings section,因此在设置页或设
|
|
|
115
76
|
| ----------- | ---------------------------------------------------------------------------------------- | ------------------------------ |
|
|
116
77
|
| `kb_search` | `query`、`agent_id`(必填)、`top_k?`(默认 5,客户端截断)、`images?`(多模态图片 URL) | 带来源引用的评分切片,以及总数 |
|
|
117
78
|
| `kb_chat` | `message`、`agent_id`(必填) | 完整答案,以及 `request_id` |
|
|
79
|
+
| `kb_manage` | `args` | 使用 dsh 配置执行知识库管理 |
|
|
118
80
|
|
|
119
81
|
两个工具的 schema 中 `agent_id` 均为必填:schema 无法告诉模型这套部署是否配了默认服务,而"调用时才发现没有默认值"会白费一轮。配置的默认服务仍对省略该参数的程序化调用生效。
|
|
120
82
|
|
|
@@ -148,7 +110,7 @@ pnpm --filter bailian-kb-dsh run test
|
|
|
148
110
|
dsh plugin --profile dev add <本仓库>/packages/bailian-kb-dsh
|
|
149
111
|
```
|
|
150
112
|
|
|
151
|
-
|
|
113
|
+
维护清单见 [docs/agents/dsh-plugin.md](https://github.com/modelstudioai/cli/blob/main/docs/agents/dsh-plugin.md)。
|
|
152
114
|
|
|
153
115
|
## 参与贡献
|
|
154
116
|
|
|
@@ -157,3 +119,5 @@ dsh plugin --profile dev add <本仓库>/packages/bailian-kb-dsh
|
|
|
157
119
|
## 许可证
|
|
158
120
|
|
|
159
121
|
[Apache 2.0](LICENSE)
|
|
122
|
+
|
|
123
|
+
升级后不再读取原来共用的 `DASHSCOPE_API_KEY`,也不会修改或删除它。若插件专属 Key 尚未配置且 bl 没有可导入的默认值,请在各插件页面分别保存 Key。
|
package/cordis.patch.yml
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
# (this env read included) wins per call; when it is unset the plugin resolves
|
|
4
|
-
# the BAILIAN_WORKSPACE_ID credential instead (web UI card or
|
|
5
|
-
# ~/.dsh/.credentials.yaml). The same fallback covers defaultRetrieveAgentId
|
|
6
|
-
# via BAILIAN_DEFAULT_RETRIEVE_AGENT_ID, defaultChatAgentId via
|
|
7
|
-
# BAILIAN_DEFAULT_CHAT_AGENT_ID, and the API key via DASHSCOPE_API_KEY.
|
|
8
|
-
|
|
1
|
+
# API key: shared dsh credentials. Business fields: dsh plugin settings only.
|
|
2
|
+
# Legacy environment/credential values are imported once at startup.
|
|
9
3
|
- insert:
|
|
10
4
|
- id: tool-bailian-kb
|
|
11
5
|
name: "bailian-kb-dsh"
|
|
12
|
-
config:
|
|
13
|
-
workspaceId: !!js process.env.BAILIAN_WORKSPACE_ID
|
|
6
|
+
config: {}
|
package/dist/bl-cli.d.ts
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
/** The two values this plugin can adopt from the bl CLI credential file. */
|
|
13
13
|
export interface BlCliConfig {
|
|
14
|
-
/** DashScope api key (`api_key`,
|
|
14
|
+
/** DashScope api key (`api_key`, active profile). */
|
|
15
15
|
apiKey?: string;
|
|
16
16
|
/** Bailian workspace id (`workspace_id`), present when the console login callback carried one. */
|
|
17
17
|
workspaceId?: string;
|
|
18
18
|
}
|
|
19
|
-
/** Default location of the bl CLI credential file (
|
|
19
|
+
/** Default location of the bl CLI credential file (named profiles are root-level blocks). */
|
|
20
20
|
export declare function blCliConfigPath(): string;
|
|
21
21
|
/**
|
|
22
22
|
* Read the api key and workspace id from the bl CLI credential file.
|
package/dist/bl-cli.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { readFileSync } from "node:fs";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { join } from "node:path";
|
|
15
|
-
/** Default location of the bl CLI credential file (
|
|
15
|
+
/** Default location of the bl CLI credential file (named profiles are root-level blocks). */
|
|
16
16
|
export function blCliConfigPath() {
|
|
17
17
|
return join(homedir(), ".bailian", "config.json");
|
|
18
18
|
}
|
|
@@ -28,7 +28,15 @@ export function readBlCliConfig(configPath = blCliConfigPath()) {
|
|
|
28
28
|
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
29
29
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
30
30
|
return {};
|
|
31
|
-
const
|
|
31
|
+
const root = parsed;
|
|
32
|
+
const selected = typeof root.active_config === "string" &&
|
|
33
|
+
root.active_config !== "" &&
|
|
34
|
+
root.active_config !== "default"
|
|
35
|
+
? root[root.active_config]
|
|
36
|
+
: root;
|
|
37
|
+
if (typeof selected !== "object" || selected === null || Array.isArray(selected))
|
|
38
|
+
return {};
|
|
39
|
+
const record = selected;
|
|
32
40
|
const apiKey = typeof record.api_key === "string" && record.api_key.trim() !== ""
|
|
33
41
|
? record.api_key.trim()
|
|
34
42
|
: undefined;
|
package/dist/client.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface KbClientOptions {
|
|
|
10
10
|
endpointHost: string;
|
|
11
11
|
/** Service version forwarded on search/chat when set (deployment debug choice). */
|
|
12
12
|
agentVersion?: string;
|
|
13
|
-
/** Resolves the current
|
|
13
|
+
/** Resolves the current BAILIAN_KB_API_KEY per call; throws with guidance when unconfigured. */
|
|
14
14
|
resolveApiKey: () => Promise<string>;
|
|
15
15
|
/** Test seam; defaults to global fetch. */
|
|
16
16
|
fetchImpl?: typeof fetch;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BlCliConfig } from "./bl-cli.js";
|
|
2
|
+
interface Configuration {
|
|
3
|
+
configInitialized?: boolean;
|
|
4
|
+
workspaceId?: string;
|
|
5
|
+
defaultRetrieveAgentId?: string;
|
|
6
|
+
defaultChatAgentId?: string;
|
|
7
|
+
}
|
|
8
|
+
interface InitializationDependencies {
|
|
9
|
+
read: () => Configuration;
|
|
10
|
+
readSeed: () => BlCliConfig;
|
|
11
|
+
resolve: (reference: string) => Promise<string | undefined>;
|
|
12
|
+
set: (reference: string, value: string) => Promise<void>;
|
|
13
|
+
update: (patch: Partial<Configuration>) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/** Import legacy values once; runtime consumers only read the dsh settings. */
|
|
16
|
+
export declare function initializeConfiguration(deps: InitializationDependencies): Promise<void>;
|
|
17
|
+
export declare function requireWorkspace(value: string | undefined): string;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Import legacy values once; runtime consumers only read the dsh settings. */
|
|
2
|
+
export async function initializeConfiguration(deps) {
|
|
3
|
+
const current = deps.read();
|
|
4
|
+
const apiKey = await deps.resolve("BAILIAN_KB_API_KEY");
|
|
5
|
+
const seed = !apiKey || !current.configInitialized ? deps.readSeed() : {};
|
|
6
|
+
if (!apiKey && seed.apiKey)
|
|
7
|
+
await deps.set("BAILIAN_KB_API_KEY", seed.apiKey);
|
|
8
|
+
if (current.configInitialized)
|
|
9
|
+
return;
|
|
10
|
+
const patch = { configInitialized: true };
|
|
11
|
+
if (current.workspaceId === undefined) {
|
|
12
|
+
patch.workspaceId = (await deps.resolve("BAILIAN_WORKSPACE_ID")) ?? seed.workspaceId ?? "";
|
|
13
|
+
}
|
|
14
|
+
if (current.defaultRetrieveAgentId === undefined) {
|
|
15
|
+
patch.defaultRetrieveAgentId = (await deps.resolve("BAILIAN_DEFAULT_RETRIEVE_AGENT_ID")) ?? "";
|
|
16
|
+
}
|
|
17
|
+
if (current.defaultChatAgentId === undefined) {
|
|
18
|
+
patch.defaultChatAgentId = (await deps.resolve("BAILIAN_DEFAULT_CHAT_AGENT_ID")) ?? "";
|
|
19
|
+
}
|
|
20
|
+
await deps.update(patch);
|
|
21
|
+
}
|
|
22
|
+
export function requireWorkspace(value) {
|
|
23
|
+
const workspace = value?.trim();
|
|
24
|
+
if (!workspace)
|
|
25
|
+
throw new Error("Workspace is not configured in dsh settings. / 请在 dsh 插件设置中配置 Workspace。");
|
|
26
|
+
return workspace;
|
|
27
|
+
}
|
package/dist/console-login.d.ts
CHANGED
|
@@ -53,6 +53,16 @@ export declare function parseCallbackBody(raw: string): Record<string, unknown>;
|
|
|
53
53
|
* @returns the credentials found; fields are absent rather than blank.
|
|
54
54
|
*/
|
|
55
55
|
export declare function pickCallbackCredentials(query: Record<string, unknown>, body: Record<string, unknown>): ConsoleLoginCredentials;
|
|
56
|
+
/**
|
|
57
|
+
* Command that opens `target` with the OS default handler.
|
|
58
|
+
* On Windows, `cmd.exe` splits an unquoted `&`, so `needapikey=true` never
|
|
59
|
+
* reaches the browser. See `buildOpenInvocation` in the commands package.
|
|
60
|
+
*/
|
|
61
|
+
export declare function buildOpenInvocation(target: string, platform?: NodeJS.Platform): {
|
|
62
|
+
command: string;
|
|
63
|
+
args: string[];
|
|
64
|
+
windowsVerbatimArguments?: boolean;
|
|
65
|
+
};
|
|
56
66
|
/** Outcome of asking the host to start a console login. */
|
|
57
67
|
export type ConsoleLoginStart = {
|
|
58
68
|
status: "started";
|
package/dist/console-login.js
CHANGED
|
@@ -126,12 +126,42 @@ async function extractCredentials(req, url) {
|
|
|
126
126
|
: {};
|
|
127
127
|
return pickCallbackCredentials(Object.fromEntries(url.searchParams), body);
|
|
128
128
|
}
|
|
129
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Quote a value for `cmd /c`. An embedded `"` is written as `""`.
|
|
131
|
+
* Do not double `%`: that substitution only happens inside batch files, and
|
|
132
|
+
* `cmd /c` would otherwise open a target that still contains `%%`.
|
|
133
|
+
* Keep in sync with `buildOpenInvocation` in
|
|
134
|
+
* `packages/commands/src/commands/shared/local-server.ts`.
|
|
135
|
+
*/
|
|
136
|
+
function quoteForCmd(value) {
|
|
137
|
+
return `"${value.replaceAll('"', '""')}"`;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Command that opens `target` with the OS default handler.
|
|
141
|
+
* On Windows, `cmd.exe` splits an unquoted `&`, so `needapikey=true` never
|
|
142
|
+
* reaches the browser. See `buildOpenInvocation` in the commands package.
|
|
143
|
+
*/
|
|
144
|
+
export function buildOpenInvocation(target, platform = process.platform) {
|
|
145
|
+
if (platform === "win32") {
|
|
146
|
+
const inner = `start "" ${quoteForCmd(target)}`;
|
|
147
|
+
return {
|
|
148
|
+
command: "cmd",
|
|
149
|
+
args: ["/d", "/v:off", "/s", "/c", `"${inner}"`],
|
|
150
|
+
windowsVerbatimArguments: true,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (platform === "darwin")
|
|
154
|
+
return { command: "open", args: [target] };
|
|
155
|
+
return { command: "xdg-open", args: [target] };
|
|
156
|
+
}
|
|
157
|
+
/** Open a URL with the OS default handler. */
|
|
130
158
|
function openInBrowser(url) {
|
|
131
|
-
const
|
|
132
|
-
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
159
|
+
const invocation = buildOpenInvocation(url);
|
|
133
160
|
return new Promise((resolve, reject) => {
|
|
134
|
-
execFile(
|
|
161
|
+
execFile(invocation.command, invocation.args, {
|
|
162
|
+
windowsHide: true,
|
|
163
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments,
|
|
164
|
+
}, (err) => {
|
|
135
165
|
if (err)
|
|
136
166
|
reject(err);
|
|
137
167
|
else
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface ConnectionDependencies {
|
|
2
|
+
describe: () => Promise<{
|
|
3
|
+
writable: boolean;
|
|
4
|
+
}>;
|
|
5
|
+
resolve: () => Promise<string | undefined>;
|
|
6
|
+
readWorkspace: () => string | undefined;
|
|
7
|
+
writeKey: (value: string) => Promise<void>;
|
|
8
|
+
unsetKey: () => Promise<void>;
|
|
9
|
+
writeWorkspace: (value: string) => Promise<void>;
|
|
10
|
+
verify: (apiKey: string, workspaceId: string) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function saveConnection(input: {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
workspaceId?: string;
|
|
15
|
+
}, deps: ConnectionDependencies): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Write-only connection updates; validate a candidate pair before publishing it. */
|
|
2
|
+
import { requireWorkspace } from "./configuration.js";
|
|
3
|
+
export async function saveConnection(input, deps) {
|
|
4
|
+
const workspace = requireWorkspace(input.workspaceId);
|
|
5
|
+
const replacement = input.apiKey?.trim();
|
|
6
|
+
const previousKey = await deps.resolve();
|
|
7
|
+
const key = replacement || previousKey;
|
|
8
|
+
if (!key)
|
|
9
|
+
throw new Error("API Key is required. / 请填写 API Key。");
|
|
10
|
+
if (replacement && !(await deps.describe()).writable) {
|
|
11
|
+
throw new Error("The launch environment owns this API Key; update it there and restart dsh. / API Key 来自启动环境,请在启动环境中修改并重启 dsh。");
|
|
12
|
+
}
|
|
13
|
+
let keyWritten = false;
|
|
14
|
+
const previousWorkspace = deps.readWorkspace();
|
|
15
|
+
let workspaceWritten = false;
|
|
16
|
+
try {
|
|
17
|
+
await deps.verify(key, workspace);
|
|
18
|
+
if (replacement) {
|
|
19
|
+
await deps.writeKey(replacement);
|
|
20
|
+
keyWritten = true;
|
|
21
|
+
if ((await deps.resolve()) !== replacement)
|
|
22
|
+
throw new Error("The new API Key is not effective. / 新 API Key 未生效。");
|
|
23
|
+
}
|
|
24
|
+
workspaceWritten = true;
|
|
25
|
+
await deps.writeWorkspace(workspace);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (workspaceWritten)
|
|
29
|
+
await deps.writeWorkspace(previousWorkspace ?? "").catch(() => undefined);
|
|
30
|
+
if (keyWritten) {
|
|
31
|
+
await (previousKey ? deps.writeKey(previousKey) : deps.unsetKey()).catch(() => undefined);
|
|
32
|
+
}
|
|
33
|
+
let message = error instanceof Error ? error.message : "Connection update failed. / 连接配置保存失败。";
|
|
34
|
+
for (const secret of [key, previousKey])
|
|
35
|
+
if (secret)
|
|
36
|
+
message = message.split(secret).join("[redacted]");
|
|
37
|
+
throw new Error(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bailian knowledge-base consumer plugin: registers kb_search and kb_chat over the DashScope RAG API,
|
|
3
|
-
* plus
|
|
3
|
+
* plus isolated CLI management and its skill.
|
|
4
4
|
* @module dsh-tool-bailian-kb
|
|
5
5
|
*/
|
|
6
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
6
|
+
import type { Context, Volatile } from "@deepseek-ai/cordis";
|
|
7
7
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
8
8
|
import z from "@deepseek-ai/schemastery";
|
|
9
9
|
/** Minimal webServer route shape (declared inline to avoid a host-package dependency). */
|
|
@@ -12,54 +12,43 @@ interface WebRoute {
|
|
|
12
12
|
path: string;
|
|
13
13
|
handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
|
|
14
14
|
}
|
|
15
|
-
/** Shell-environment registration shape (declared inline to avoid a host-package dependency). */
|
|
16
|
-
interface ShellEnvRegistration {
|
|
17
|
-
name: string;
|
|
18
|
-
variables: Record<string, {
|
|
19
|
-
description: string;
|
|
20
|
-
}>;
|
|
21
|
-
resolve: () => Record<string, string | undefined>;
|
|
22
|
-
}
|
|
23
15
|
declare module "@deepseek-ai/cordis" {
|
|
24
16
|
interface Context {
|
|
25
17
|
webServer: {
|
|
26
18
|
register(route: WebRoute): () => void;
|
|
27
19
|
};
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
connection: {
|
|
21
|
+
requestRejection(request: {
|
|
22
|
+
readonly headers: IncomingMessage["headers"];
|
|
23
|
+
}): 401 | 403 | undefined;
|
|
30
24
|
};
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
27
|
export declare const name = "tool-bailian-kb";
|
|
34
28
|
export declare const inject: string[];
|
|
35
|
-
/**
|
|
29
|
+
/** Loader entry id. Settings forms address the plugin by this id. */
|
|
30
|
+
export declare const KB_SETTINGS_NAMESPACE = "tool-bailian-kb";
|
|
31
|
+
/** Bailian knowledge-base plugin configuration. Page fields are volatile. */
|
|
36
32
|
export interface Config {
|
|
37
|
-
/**
|
|
38
|
-
workspaceId
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
/** Retrieval-service id
|
|
42
|
-
defaultRetrieveAgentId
|
|
43
|
-
/** Q&A-service id
|
|
44
|
-
defaultChatAgentId
|
|
45
|
-
/** Service version
|
|
46
|
-
agentVersion
|
|
47
|
-
/** kb_chat timeout in milliseconds
|
|
48
|
-
chatTimeoutMs: number
|
|
49
|
-
/** Consumed-once ledger of {@link seedFromBlCli}: fields listed here are never auto-seeded again, so a deliberately cleared value stays cleared. Maintained by the host; not editable from the panel. */
|
|
50
|
-
seededFields?: string[];
|
|
33
|
+
/** Workspace id stored only in dsh plugin settings. */
|
|
34
|
+
workspaceId: Volatile<string | undefined>;
|
|
35
|
+
/** Internal migration marker: cleared fields must not be imported again. */
|
|
36
|
+
configInitialized: Volatile<boolean>;
|
|
37
|
+
/** Retrieval-service id. Stored in dsh settings. */
|
|
38
|
+
defaultRetrieveAgentId: Volatile<string | undefined>;
|
|
39
|
+
/** Q&A-service id. Stored in dsh settings. */
|
|
40
|
+
defaultChatAgentId: Volatile<string | undefined>;
|
|
41
|
+
/** Service version: `beta` or a published number. Never model-visible. */
|
|
42
|
+
agentVersion: Volatile<string | undefined>;
|
|
43
|
+
/** kb_chat timeout in milliseconds. */
|
|
44
|
+
chatTimeoutMs: Volatile<number>;
|
|
51
45
|
}
|
|
52
|
-
/** Schemastery validation for {@link Config}; workspaceId and default agent ids are optional — both resolve per call with a credentials fallback. */
|
|
53
46
|
export declare const Config: z<Config>;
|
|
54
47
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* the `bailian-kb` settings section (entry config as the base layer), so
|
|
58
|
-
* every value is read through the live source thunk per call — tool schemas
|
|
59
|
-
* are static (agent_id stays required regardless), so a settings edit needs
|
|
60
|
-
* no re-registration.
|
|
48
|
+
* Activate knowledge tools and isolated management after startup migration. Visible settings are
|
|
49
|
+
* volatile plugin config, so a saved edit applies on the next call.
|
|
61
50
|
* @param ctx - registrant context carrying tools and credentials.
|
|
62
|
-
* @param config - deployment
|
|
51
|
+
* @param config - deployment workspace, pinning, and timeout choices.
|
|
63
52
|
*/
|
|
64
53
|
export declare function apply(ctx: Context, config: Config): void;
|
|
65
54
|
export {};
|