bailian-kb-dsh 0.1.18 → 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/LICENSE +202 -0
- package/README.md +78 -124
- package/README.zh.md +123 -0
- 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 +184 -370
- 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 +36 -3
- package/dist/service-catalog.js +96 -8
- package/dist/service-context.d.ts +12 -0
- package/dist/service-context.js +13 -9
- package/dist/tools.d.ts +9 -3
- package/dist/tools.js +18 -15
- package/dist/web/client.js +679 -922
- package/dist/web/client.js.map +1 -1
- package/package.json +48 -45
- package/skills/bailian-kb/SKILL.md +13 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Aliyun Model Studio (DashScope) AI Platform
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,169 +1,123 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Bailian Knowledge Base for DeepSeek Harness
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Knowledge-base retrieval tools for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness), backed by Aliyun Model Studio (Bailian).**
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/bailian-kb-dsh)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
[](https://www.typescriptlang.org)
|
|
10
|
+
[](LICENSE)
|
|
10
11
|
|
|
11
|
-
|
|
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/)
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
BAILIAN_WORKSPACE_ID=ws-xxx # 必填:百炼工作空间 id
|
|
15
|
-
DASHSCOPE_API_KEY=sk-xxx # 必填:也可放 ~/.dsh/.credentials.yaml,或用设置页的“自动获取”
|
|
16
|
-
```
|
|
14
|
+
</div>
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
## What is this?
|
|
19
17
|
|
|
20
|
-
|
|
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).
|
|
21
19
|
|
|
22
|
-
|
|
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.
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
pnpm --filter bailian-kb-dsh run build # tsc 出 dist/ + tsdown 出 dist/web/client.js
|
|
26
|
-
pnpm --filter bailian-kb-dsh run typecheck # node 半 + web 半两套 tsconfig
|
|
27
|
-
pnpm --filter bailian-kb-dsh run test
|
|
28
|
-
```
|
|
22
|
+
## Features
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
- **Two model-facing tools** — `kb_search` returns scored chunks with source references; `kb_chat` returns a complete grounded answer
|
|
25
|
+
- **Service awareness** — the workspace's deployed retrieval services are injected into the conversation, so the model knows what it can look up instead of guessing service ids
|
|
26
|
+
- **Low-friction setup** — sign in to the Bailian console from the settings page to fill in the API key and workspace id; an existing `bl` CLI login is adopted automatically
|
|
27
|
+
- **Settings page** — a "Bailian KB" section in the web UI for credentials, default services, and service-cache inspection
|
|
28
|
+
- **Management skill** — bundled `bailian-kb` skill teaching the agent the `bl` CLI workflow for creating knowledge bases, ingesting documents, and deploying services
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
dsh plugin --profile dev add <本仓库>/packages/bailian-kb-dsh
|
|
34
|
-
```
|
|
30
|
+
## Requirements
|
|
35
31
|
|
|
36
|
-
|
|
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/?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
|
+
- 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
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
## Installation
|
|
39
38
|
|
|
40
|
-
```
|
|
41
|
-
-
|
|
42
|
-
- id: tool-bailian-kb
|
|
43
|
-
name: "bailian-kb-dsh"
|
|
44
|
-
config:
|
|
45
|
-
workspaceId: !!js process.env.BAILIAN_WORKSPACE_ID
|
|
39
|
+
```sh
|
|
40
|
+
dsh plugin --profile web add bailian-kb-dsh
|
|
46
41
|
```
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### 四个值的解析链
|
|
51
|
-
|
|
52
|
-
| 值 | 1️⃣ settings 用户层(设置页可编辑、回显) | 2️⃣ entry config(本 patch 或用户覆盖,作 base 层) | 3️⃣ credential(`~/.dsh/.credentials.yaml` / env) | 4️⃣ 都缺失时 |
|
|
53
|
-
| ----------------------------------- | ---------------------------------------- | -------------------------------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
54
|
-
| `DASHSCOPE_API_KEY` | —(无 settings 面) | —(无 config 面) | ✅ | 工具调用报错并引导配置 |
|
|
55
|
-
| `BAILIAN_WORKSPACE_ID` | ✅ `workspaceId` | ✅ `workspaceId` | ✅ | 工具调用报错并引导配置 |
|
|
56
|
-
| `BAILIAN_DEFAULT_RETRIEVE_AGENT_ID` | ✅ `defaultRetrieveAgentId` | ✅ `defaultRetrieveAgentId` | ✅ | `kb_search` 无 `agent_id` 的**程序化**调用报错并附配置指引(模型侧 schema 恒必填) |
|
|
57
|
-
| `BAILIAN_DEFAULT_CHAT_AGENT_ID` | ✅ `defaultChatAgentId` | ✅ `defaultChatAgentId` | ✅ | `kb_chat` 无 `agent_id` 的**程序化**调用报错并附配置指引(模型侧 schema 恒必填) |
|
|
58
|
-
|
|
59
|
-
行为参数(`endpointHost`/`agentVersion`/`chatTimeoutMs`)在 config/settings 层(设置文档可改,实时生效)。
|
|
60
|
-
|
|
61
|
-
### Web UI 配置页
|
|
43
|
+
The CLI adds the bundle to the profile's layer stack; no manual YAML editing required. To remove it:
|
|
62
44
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- **DashScope API Key** — write-only,`type=password` 遮罩输入草稿,仅显示 configured/来自环境变量 徽标;写 `~/.dsh/.credentials.yaml`
|
|
66
|
-
- **Bailian Workspace ID / 默认检索服务 ID / 默认对话服务 ID** — 回显:读写 `bailian-kb` settings 用户层,预填当前解析值;清空保存 = 移除用户层,回退 entry config → credential
|
|
67
|
-
- **自动获取** — 按钮调 Host 桥接路由 `/bailian-kb/autofill`:Host 在宿主机拉起浏览器登录百炼控制台(不经 `bl` 命令),回调落到本机 loopback 端口后直接把 API 密钥写入凭据存储、工作空间 ID 写入 settings,明文 key 不过浏览器;面板轮询到完成后自动刷新(无需再次点击)。登录 URL 始终请求签发新 key,因此每次都与当前账号配对,切换账号直接点一次即可。
|
|
68
|
-
|
|
69
|
-
首次接入 seed:启动时若 API key / workspaceId 从未被设置过(settings、credential、env 均无值),自动从 `~/.bailian/config.json` 采纳一次;`seededFields` 字段(settings 文档内,面板不可编辑)记账已消费/已由用户管理的字段,用户主动清空的值永不会被重新填回。
|
|
70
|
-
|
|
71
|
-
降级:远程浏览器(非 loopback,settings RPC 不可达)或未组合 settings 服务时,ID 字段退回旧的 write-only credential 控件,页面顶部显示提示。
|
|
72
|
-
|
|
73
|
-
### 用户覆盖
|
|
74
|
-
|
|
75
|
-
用户 patch 层在本 bundle 之上,按 id 覆盖时**替换整个 config(无 deep-merge)**:
|
|
76
|
-
|
|
77
|
-
```yaml
|
|
78
|
-
# ~/.dsh/cordis.patch.yml 或 profile 的 cordis.patch.yml
|
|
79
|
-
- id: tool-bailian-kb
|
|
80
|
-
config:
|
|
81
|
-
defaultRetrieveAgentId: aid-search-service
|
|
82
|
-
defaultChatAgentId: aid-chat-service
|
|
83
|
-
chatTimeoutMs: 600000
|
|
45
|
+
```sh
|
|
46
|
+
dsh plugin --profile web remove bailian-kb-dsh
|
|
84
47
|
```
|
|
85
48
|
|
|
86
|
-
|
|
49
|
+
Verify the plugin is composed — `dsh --profile web --dump-config` should list a `tool-bailian-kb` row.
|
|
87
50
|
|
|
88
|
-
##
|
|
51
|
+
## Configuration
|
|
89
52
|
|
|
90
|
-
|
|
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:
|
|
91
54
|
|
|
92
|
-
|
|
|
93
|
-
| ------------------------ |
|
|
94
|
-
| `workspaceId` |
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
99
|
-
| `chatTimeoutMs` | number | 300000 | kb_chat 超时;服务端是分钟级 agentic loop |
|
|
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 |
|
|
100
62
|
|
|
101
|
-
|
|
63
|
+
The endpoint is fixed to `cn-beijing.maas.aliyuncs.com`. There is no endpoint setting. Settings page edits apply to the next call.
|
|
102
64
|
|
|
103
|
-
|
|
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.
|
|
104
66
|
|
|
105
|
-
|
|
106
|
-
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
107
|
-
| `kb_search` | `query`、`agent_id`(**必填**;程序化省略时回退 defaultRetrieveAgentId)、`top_k?`(默认 5,**客户端截断**——服务端无此参数)、`images?` | chunks(text/score/来源)+ total |
|
|
108
|
-
| `kb_chat` | `message`、`agent_id`(**必填**;程序化省略时回退 defaultChatAgentId) | 完整答案(内部消费 SSE 流缓冲返回)+ request_id |
|
|
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.
|
|
109
68
|
|
|
110
|
-
|
|
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.
|
|
111
70
|
|
|
112
|
-
|
|
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.
|
|
113
72
|
|
|
114
|
-
|
|
73
|
+
## Tools
|
|
115
74
|
|
|
116
|
-
|
|
75
|
+
| Tool | Parameters | Returns |
|
|
76
|
+
| ----------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
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 |
|
|
78
|
+
| `kb_chat` | `message`, `agent_id` (required) | The complete answer plus a `request_id` |
|
|
79
|
+
| `kb_manage` | `args` | Knowledge management using dsh configuration |
|
|
117
80
|
|
|
118
|
-
|
|
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.
|
|
119
82
|
|
|
120
|
-
|
|
121
|
-
2. **重注册工具会废掉 prompt 前缀缓存**(从第一个变化的 schema token 起)。走上下文消息则让 schema 永久稳定。
|
|
83
|
+
The list of deployed services — id, name, and scene — is injected into the conversation as a context message, refreshed periodically and whenever a `bl knowledge service` command changes the inventory. Long lists are truncated with the total stated, so the model never mistakes a partial list for the full inventory.
|
|
122
84
|
|
|
123
|
-
|
|
85
|
+
## Errors
|
|
124
86
|
|
|
125
|
-
|
|
87
|
+
- **HTTP 4xx** — most often an `agent_id` that no longer exists, so the service list is refreshed and appended to the error message for immediate recovery
|
|
88
|
+
- **HTTP 5xx** — passed through unchanged
|
|
89
|
+
- **Missing credentials** — the message names the configuration paths (`~/.dsh/.env`, `~/.dsh/.credentials.yaml`, the settings page) and links to the console key page
|
|
90
|
+
- **`kb_chat` timeout** — the message explains the server-side multi-turn retrieval and suggests retrying or switching to `kb_search`
|
|
126
91
|
|
|
127
|
-
|
|
128
|
-
| ------------------------ | ----------------------------------------------------- |
|
|
129
|
-
| 配了默认服务 | 只列该服务 + "另有 N 个" 提示 |
|
|
130
|
-
| 未配默认,deployed ≤ 10 | 全量 `agent_id` + 名称 |
|
|
131
|
-
| 未配默认,deployed > 10 | 按 `modify_time` 倒序取 10 条,**显式标明截断**与总数 |
|
|
132
|
-
| 0 个 / 拉取失败 / 无缓存 | 不注入(工具仍可用) |
|
|
92
|
+
## Known limitations
|
|
133
93
|
|
|
134
|
-
|
|
94
|
+
- `kb_chat` buffers the server stream, so there is no progress output while it runs.
|
|
95
|
+
- `top_k` is a client-side cut: the request body carries no such parameter, and how many chunks the server returns is decided by the service configuration.
|
|
96
|
+
- **Service names carry the routing signal.** The service list API does not return a description field yet, so the model judges what a service covers from its name alone. Name your services after their content (`Product docs retrieval`, not `Service 1`).
|
|
97
|
+
- At most two pages per scene are fetched; beyond that the injected list is marked as truncated.
|
|
135
98
|
|
|
136
|
-
|
|
99
|
+
## Development
|
|
137
100
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
| --------------------------------------------------------- | ------------------------------------ |
|
|
144
|
-
| pre-step 间隔调度(超 TTL 30 分钟,后台异步,**不阻塞**) | 下一步 |
|
|
145
|
-
| 控制台登录成功(`/bailian-kb/autofill` 回调) | 下一步 |
|
|
146
|
-
| 调用撞 4xx(agent_id 已失效) | **本步**,刷新后的列表追加进错误消息 |
|
|
147
|
-
| workspaceId / apiKey 变更 | 下一步 |
|
|
101
|
+
```sh
|
|
102
|
+
pnpm --filter bailian-kb-dsh run build # tsc → dist/ (node half) + tsdown → dist/web/client.js (browser half)
|
|
103
|
+
pnpm --filter bailian-kb-dsh run typecheck # node and web tsconfigs
|
|
104
|
+
pnpm --filter bailian-kb-dsh run test
|
|
105
|
+
```
|
|
148
106
|
|
|
149
|
-
|
|
107
|
+
For local integration, add the working copy to a dev profile (the patch file is watched by HMR):
|
|
150
108
|
|
|
151
|
-
|
|
109
|
+
```sh
|
|
110
|
+
dsh plugin --profile dev add <this-repo>/packages/bailian-kb-dsh
|
|
111
|
+
```
|
|
152
112
|
|
|
153
|
-
|
|
154
|
-
- 凭证缺失:指向 `~/.dsh/.env` / `.credentials.yaml` 配置方式与控制台取 key 页面;
|
|
155
|
-
- chat 超时:说明服务端多轮检索特性,建议重试或改用 `kb_search`;
|
|
156
|
-
- 服务端错误体截断至 500 字符进入错误信息(优先 `code: message`)。
|
|
113
|
+
Maintenance checklist: [docs/agents/dsh-plugin.md](https://github.com/modelstudioai/cli/blob/main/docs/agents/dsh-plugin.md).
|
|
157
114
|
|
|
158
|
-
##
|
|
115
|
+
## Contributing
|
|
159
116
|
|
|
160
|
-
|
|
117
|
+
Bug reports, feature requests, and PRs are welcome. See [CONTRIBUTING.md](https://github.com/modelstudioai/cli/blob/main/CONTRIBUTING.md) for developer setup and the contribution workflow.
|
|
161
118
|
|
|
162
|
-
|
|
119
|
+
## License
|
|
163
120
|
|
|
164
|
-
|
|
121
|
+
[Apache 2.0](LICENSE)
|
|
165
122
|
|
|
166
|
-
-
|
|
167
|
-
- `top_k` 是客户端截断:请求体不含该参数,服务端返回条数由检索服务配置决定,截断只影响进入模型上下文的量。
|
|
168
|
-
- **服务画像的质量上限取决于服务名**:`service list` 接口当前不返回描述字段,所以模型只能靠 `agent_name` 判断一个服务能查什么。名字模糊的部署引导能力接近于零。列表接口补齐描述字段后只需改三处(`api-types` 补字段名 → `services.ts` 解析 → `buildServiceCatalog` 追加并截断到 200 字符),缓存已预留 `description` 键,无需迁移。
|
|
169
|
-
- 拉取每个 scene 最多 2 页,超出时标 `truncated` 并在清单里告知。
|
|
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
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 百炼知识库 for DeepSeek Harness
|
|
4
|
+
|
|
5
|
+
**基于阿里云百炼(Aliyun Model Studio)的知识库检索工具,供 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 使用。**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/bailian-kb-dsh)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
[](https://www.typescriptlang.org)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
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
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## 这是什么?
|
|
17
|
+
|
|
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
|
+
|
|
20
|
+
检索经由你在百炼上部署的**检索服务**完成:一个服务把一个或多个知识库绑定到指定的向量 / 排序配置上,通过 `agent_id` 寻址。插件会把已部署服务的清单持续呈现给模型,让它能判断用户的问题是否落在你的知识范围内。
|
|
21
|
+
|
|
22
|
+
## 功能特性
|
|
23
|
+
|
|
24
|
+
- **两个面向模型的工具** — `kb_search` 返回带分数和来源的知识切片;`kb_chat` 返回基于知识的完整答案
|
|
25
|
+
- **服务感知** — 工作空间里已部署的检索服务会注入到会话上下文,模型据此知道自己能查什么,不必猜 `agent_id`
|
|
26
|
+
- **低门槛配置** — 在设置页登录百炼控制台即可自动填入 API 密钥与工作空间 ID;已有的 `bl` CLI 登录会被自动采纳
|
|
27
|
+
- **设置页** — Web UI 中的"百炼知识库"页,管理凭据、默认服务,并可查看服务缓存状态
|
|
28
|
+
- **管理 skill** — 随包分发的 `bailian-kb` skill,教 agent 用 `bl` CLI 完成建库、文档导入、服务部署
|
|
29
|
+
|
|
30
|
+
## 环境要求
|
|
31
|
+
|
|
32
|
+
- DeepSeek Harness 及其插件运行时(`@deepseek-ai/dsh-*`),Node.js >= 22.12
|
|
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
|
+
- 管理面的事(建库、导入文档、部署服务)需要 [`bl` CLI](https://www.npmjs.com/package/bailian-cli)(`npm install -g bailian-cli`)。检索本身直连 API、从不起子进程,所以 `kb_search` / `kb_chat` 不装也能用
|
|
36
|
+
|
|
37
|
+
## 安装
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
dsh plugin --profile web add bailian-kb-dsh
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
CLI 会自动把 bundle 加入 profile 的层栈,无需手改 YAML。卸载:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
dsh plugin --profile web remove bailian-kb-dsh
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
验证插件已装配:`dsh --profile web --dump-config` 应能看到 `tool-bailian-kb` row。
|
|
50
|
+
|
|
51
|
+
## 配置
|
|
52
|
+
|
|
53
|
+
通过 dsh 插件设置页配置。API Key 独立使用 dsh credentials 中的 `BAILIAN_KB_API_KEY`(通常为 `~/.dsh/.credentials.yaml`,实际路径由宿主决定)。所有业务设置只保存到本插件的 dsh 配置:
|
|
54
|
+
|
|
55
|
+
| 字段 | 含义 | 默认值 |
|
|
56
|
+
| ------------------------ | ------------------------------ | ---------- |
|
|
57
|
+
| `workspaceId` | 所有知识库调用使用的 Workspace | 必填 |
|
|
58
|
+
| `defaultRetrieveAgentId` | 默认检索服务 | 未设置 |
|
|
59
|
+
| `defaultChatAgentId` | 默认问答服务 | 未设置 |
|
|
60
|
+
| `agentVersion` | 草稿 `beta` 或已发布服务版本 | 最新发布版 |
|
|
61
|
+
| `chatTimeoutMs` | 问答超时,毫秒 | 300000 |
|
|
62
|
+
|
|
63
|
+
端点固定为 `cn-beijing.maas.aliyuncs.com`,不提供端点配置。在设置页保存后,下一次调用即生效。
|
|
64
|
+
|
|
65
|
+
启动时,缺失的 API Key 可以从 `~/.bailian/config.json` 当前激活的 Profile 导入。首次配置迁移时,缺失的 Workspace 和默认服务从旧 dsh 凭据导入,Workspace 再以 bl Profile 作为初始默认值;已有 dsh 设置优先。内部 `configInitialized` 标记确保清空的设置不会被再次填入。缺失的 API Key 仍允许在后续启动时补入。
|
|
66
|
+
|
|
67
|
+
初始化完成后,业务字段只读 dsh 插件配置,不再读取 bl 或旧凭据字段。清空 Workspace 后,调用会报缺配置。控制台登录把 Key 保存到 dsh credentials,把 Workspace 保存到 dsh 设置。kb 不创建 `personal-kb/config.json`。
|
|
68
|
+
|
|
69
|
+
连接区域支持在密码输入框中填写新 API Key,留空表示保留当前 Key。点击**验证并保存**会先验证 Key 与 Workspace 的组合,再保存;验证失败不修改配置,设置写入失败时尝试恢复原配置。旧 Key 不回显,保存成功后清空输入框。知识库和记忆插件各自使用独立的 Key 与 Workspace,修改互不影响。来自启动环境的 Key 需要在启动环境中修改。
|
|
70
|
+
|
|
71
|
+
管理操作使用 `kb_manage`,参数为 `bl knowledge` 之后的数组,例如 `{"args":["service","list","--scene","search"]}`。宿主内部执行已安装的 bl,使用临时隔离配置目录,并注入与原生工具相同的当前 Key 和 Workspace;不允许通过参数覆盖连接配置。密钥只通过子进程环境传递,不进入工具参数。直接在 shell 中运行 bl 仍是独立 CLI,不是插件管理入口。
|
|
72
|
+
|
|
73
|
+
## 工具
|
|
74
|
+
|
|
75
|
+
| 工具 | 参数 | 返回 |
|
|
76
|
+
| ----------- | ---------------------------------------------------------------------------------------- | ------------------------------ |
|
|
77
|
+
| `kb_search` | `query`、`agent_id`(必填)、`top_k?`(默认 5,客户端截断)、`images?`(多模态图片 URL) | 带来源引用的评分切片,以及总数 |
|
|
78
|
+
| `kb_chat` | `message`、`agent_id`(必填) | 完整答案,以及 `request_id` |
|
|
79
|
+
| `kb_manage` | `args` | 使用 dsh 配置执行知识库管理 |
|
|
80
|
+
|
|
81
|
+
两个工具的 schema 中 `agent_id` 均为必填:schema 无法告诉模型这套部署是否配了默认服务,而"调用时才发现没有默认值"会白费一轮。配置的默认服务仍对省略该参数的程序化调用生效。
|
|
82
|
+
|
|
83
|
+
已部署服务的清单(ID、名称、场景)以上下文消息的形式注入会话,周期性刷新,`bl knowledge service` 命令改动服务清单时也会刷新。清单过长时会截断并注明总数,避免模型把部分清单当成全部。
|
|
84
|
+
|
|
85
|
+
## 错误处理
|
|
86
|
+
|
|
87
|
+
- **HTTP 4xx** — 多数情况是 `agent_id` 已失效,因此会刷新服务清单并追加到错误信息里,便于立即纠正
|
|
88
|
+
- **HTTP 5xx** — 原样透传
|
|
89
|
+
- **凭据缺失** — 错误信息指出配置路径(`~/.dsh/.env`、`~/.dsh/.credentials.yaml`、设置页)并给出控制台取密钥的链接
|
|
90
|
+
- **`kb_chat` 超时** — 错误信息说明服务端多轮检索的特性,建议重试或改用 `kb_search`
|
|
91
|
+
|
|
92
|
+
## 已知限制
|
|
93
|
+
|
|
94
|
+
- `kb_chat` 会缓冲服务端流式输出,执行期间没有进展显示。
|
|
95
|
+
- `top_k` 是客户端截断:请求体不含该参数,服务端返回多少切片由检索服务配置决定。
|
|
96
|
+
- **服务名承载了路由信号。** 服务列表接口目前不返回描述字段,模型只能靠服务名判断一个服务能查什么。请按内容命名(`产品文档检索`,而不是`检索服务1`)。
|
|
97
|
+
- 每个场景最多拉取两页,超出时注入的清单会标明已截断。
|
|
98
|
+
|
|
99
|
+
## 开发
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
pnpm --filter bailian-kb-dsh run build # tsc 出 dist/(node 半)+ tsdown 出 dist/web/client.js(浏览器半)
|
|
103
|
+
pnpm --filter bailian-kb-dsh run typecheck # node 与 web 两套 tsconfig
|
|
104
|
+
pnpm --filter bailian-kb-dsh run test
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
本地联调时把工作副本装进 dev profile(patch 文件受 HMR 监听):
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
dsh plugin --profile dev add <本仓库>/packages/bailian-kb-dsh
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
维护清单见 [docs/agents/dsh-plugin.md](https://github.com/modelstudioai/cli/blob/main/docs/agents/dsh-plugin.md)。
|
|
114
|
+
|
|
115
|
+
## 参与贡献
|
|
116
|
+
|
|
117
|
+
欢迎提交 Bug 报告、功能建议和 PR。开发环境搭建与贡献流程见 [CONTRIBUTING.md](https://github.com/modelstudioai/cli/blob/main/CONTRIBUTING.md)。
|
|
118
|
+
|
|
119
|
+
## 许可证
|
|
120
|
+
|
|
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: {}
|