Skip to content

Commit cda1e32

Browse files
committed
refactor(tool-bailian-kb): 移除 kb_service_list 工具,统一服务发现方式
- 移除 kb_service_list 相关代码,包括接口定义、服务查询函数和工具定义 - 服务发现改为通过 kscli 命令行工具 `kscli service list` 查询 - 更新文档和注释,删除关于 kb_service_list 的描述和示例 - 删除对服务列表接口路径的引用,保留 kb_search 和 kb_chat 两个工具 - 调整错误处理逻辑,不再附加可用服务信息,错误直接透传 - 修改默认服务 id 提示文本,均改为引用 `kscli service list` 作为服务发现手段 - 移除相关测试内容,包括对 kb_service_list 注册和服务查询测试 - 保持其他功能和接口不变,确保兼容和功能完整性
1 parent 8a09881 commit cda1e32

12 files changed

Lines changed: 36 additions & 234 deletions

File tree

‎packages/tool-bailian-kb/README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dsh-tool-bailian-kb
22

3-
百炼知识库的 dsh 插件本体:在 `ctx.tools` 注册三个模型工具,并在 skills 服务可用时注册管理面 skill。
3+
百炼知识库的 dsh 插件本体:在 `ctx.tools` 注册两个检索模型工具(kb_search、kb_chat),并在 skills 服务可用时注册管理面 skill。服务发现通过 kscli CLI 完成。
44

55
## Config
66

@@ -21,13 +21,14 @@ Config 同时注册为 `bailian-kb` settings namespace(`installSettingsSection
2121

2222
| 工具 | 参数 | 返回 |
2323
|---|---|---|
24-
| `kb_service_list` | `scene?`(chat\|search,省略查双场景合并)、`name_filter?` | 服务清单(agent_id、名称、scene、status、绑定知识库)+ total + truncated;分页内部消化(单 scene 100 条上限) |
2524
| `kb_search` | `query`、`agent_id`(见 defaultRetrieveAgentId)、`top_k?`(默认 5,**客户端截断**——服务端无此参数)、`images?` | chunks(text/score/来源)+ total |
2625
| `kb_chat` | `message`、`agent_id`(见 defaultChatAgentId) | 完整答案(内部消费 SSE 流缓冲返回)+ request_id |
2726

27+
服务发现(`kb_service_list` 已移除):通过 `kscli service list` CLI 命令查询可用检索/对话服务及其 agent_id。
28+
2829
## 错误语义
2930

30-
- HTTP 错误(除 401/403 鉴权类):错误信息**附当前服务清单**,模型可一步纠正无效 `agent_id`(5xx 也附,但通常代表服务端异常);
31+
- HTTP 错误:原始错误透传,模型可通过 `kscli service list` 发现可用服务以纠正无效 `agent_id`;
3132
- 凭证缺失:指向 `~/.dsh/.env` / `.credentials.yaml` 配置方式与控制台取 key 页面;
3233
- chat 超时:说明服务端多轮检索特性,建议重试或改用 `kb_search`;
3334
- 服务端错误体截断至 500 字符进入错误信息(优先 `code: message`)。

‎packages/tool-bailian-kb/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dsh-tool-bailian-kb",
33
"version": "0.1.0",
4-
"description": "Bailian knowledge-base tools for DeepSeek Harness: kb_service_list, kb_search, kb_chat over the DashScope RAG API, plus the kscli management skill.",
4+
"description": "Bailian knowledge-base tools for DeepSeek Harness: kb_search and kb_chat over the DashScope RAG API, plus the kscli management skill.",
55
"type": "module",
66
"main": "lib/index.js",
77
"types": "lib/index.d.ts",

‎packages/tool-bailian-kb/skills/bailian-kb-management/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kscli doc status --kb-id <kb-id> --doc-id <doc-id> # 3. 轮
2222
kscli service create ... && kscli service deploy ... # 4. 建/部署检索服务 → 得到 agent_id
2323
```
2424

25-
部署完成后用 `kb_service_list` 确认服务可见,再用 `kb_search` 带该 `agent_id` 验证检索。
25+
部署完成后用 `kscli service list` 确认服务可见,再用 `kb_search` 带该 `agent_id` 验证检索。
2626

2727
## 命令组速查
2828

‎packages/tool-bailian-kb/src/api-types.ts‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
/** Request/response fields of the three DashScope knowledge endpoints, mirrored from the verified kscli types. */
2-
3-
export interface ServiceListRequest {
4-
agent_scene: 'chat' | 'search'
5-
agent_name?: string
6-
page_number: number
7-
page_size: number
8-
}
9-
10-
export interface ServiceListRow {
11-
agent_id?: string
12-
agent_name?: string
13-
agent_scene?: string
14-
agent_status?: string
15-
pipeline_list?: { pipeline_id?: string; pipeline_name?: string }[]
16-
}
17-
18-
export interface ServiceListResponse {
19-
code?: string
20-
message?: string
21-
data?: { total_count?: number; rows?: ServiceListRow[] }
22-
}
1+
/** Request/response fields of the DashScope search and chat endpoints, mirrored from the verified kscli types. */
232

243
export interface SearchRequest {
254
query: string

‎packages/tool-bailian-kb/src/endpoints.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/** Protocol path constants and the workspace-subdomain URL builder (external API spec; not configurable). */
22

3-
/** DashScope knowledge API paths, mirrored from the verified kscli endpoint table. */
3+
/** DashScope knowledge API paths for the two native tools (search, chat); service listing is handled by kscli. */
44
export const KB_PATHS = {
5-
serviceList: '/api/v1/indices/rag/app/list',
65
search: '/api/v1/indices/knowledge/search',
76
chat: '/api/v2/apps/knowledge/chat',
87
} as const

‎packages/tool-bailian-kb/src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Bailian knowledge-base consumer plugin: registers kb_service_list, kb_search,
3-
* and kb_chat over the DashScope RAG API, plus the kscli management skill.
2+
* Bailian knowledge-base consumer plugin: registers kb_search and kb_chat over the DashScope RAG API,
3+
* plus the kscli management skill.
44
* @module dsh-tool-bailian-kb
55
*/
66

‎packages/tool-bailian-kb/src/services.ts‎

Lines changed: 0 additions & 59 deletions
This file was deleted.

‎packages/tool-bailian-kb/src/tools.ts‎

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* The three model-facing knowledge tools. agent_id stays optional in the schema
2+
* The two model-facing knowledge tools (kb_search, kb_chat). agent_id stays optional in the schema
33
* regardless of deployment: the default services (patch config or credential)
44
* can change at runtime through the credentials domain, so the fallback runs
55
* per call and a missing default surfaces as an executable error instead of a
@@ -11,7 +11,6 @@ import type { SearchRequest, SearchResponse } from './api-types.js'
1111
import { KbApiError, type KbClient } from './client.js'
1212
import { consumeChatStream } from './chat.js'
1313
import { KB_PATHS } from './endpoints.js'
14-
import { listServices } from './services.js'
1514

1615
/** Client-side chunk cap applied when the model omits top_k. */
1716
const DEFAULT_TOP_K = 5
@@ -26,32 +25,17 @@ export interface KbToolDeps {
2625
chatTimeoutMs: number
2726
}
2827

29-
/** Format one service list into the error-hint / result text form. */
30-
function formatServices(services: { agent_id: string; name: string; scene: string; status: string }[]): string {
31-
return services.map(s => `${s.agent_id} (${s.name}, scene=${s.scene}, ${s.status})`).join('; ')
32-
}
33-
3428
/**
35-
* Append the current service list to a client error so the model can correct
36-
* an invalid agent_id in one step. Auth failures (401/403) keep their own message.
37-
* @param client - the shared knowledge API client used for best-effort discovery.
38-
* @param err - the failure being enriched; always rethrown.
39-
* @returns never; the original or enriched error is thrown.
29+
* Forward the original tool error unchanged; service discovery now lives
30+
* in the kscli management skill (`kscli service list`), so the tool no
31+
* longer makes a best-effort API round-trip to enrich the message.
4032
*/
41-
async function withServiceHint(client: KbClient, err: unknown): Promise<never> {
42-
if (err instanceof KbApiError && err.status !== undefined && err.status >= 400 && err.status !== 401 && err.status !== 403) {
43-
let hint: string | undefined
44-
try {
45-
const { services } = await listServices(client, {})
46-
if (services.length > 0) hint = formatServices(services)
47-
} catch { /* discovery is best-effort; the original error already carries the failure */ }
48-
if (hint !== undefined) throw new KbApiError(`${err.message}. Available services: ${hint}`, err.status)
49-
}
33+
async function withServiceHint(_client: KbClient, err: unknown): Promise<never> {
5034
throw err
5135
}
5236

5337
/**
54-
* Build the three tool definitions over one shared client.
38+
* Build the two tool definitions over one shared client.
5539
* @param deps - client plus the deployment's explicit pinning and timeout choices.
5640
* @returns definitions ready for `ctx.tools.register()`.
5741
*/
@@ -61,77 +45,25 @@ export function createKbTools(deps: KbToolDeps) {
6145
const { client, resolveDefaultRetrieveAgentId, resolveDefaultChatAgentId } = deps
6246
const agentIdParam = {
6347
type: 'string' as const,
64-
description: 'Retrieval/Q&A service id; omit to use the default service when this deployment configures one (find ids via kb_service_list).',
48+
description: 'Retrieval/Q&A service id; omit to use the default service when this deployment configures one (find ids via `kscli service list`).',
6549
}
6650
const resolveRetrieveAgentId = async (supplied: string | undefined): Promise<string> => {
6751
if (supplied !== undefined) return supplied
6852
const defaultId = resolveDefaultRetrieveAgentId === undefined ? undefined : await resolveDefaultRetrieveAgentId()
6953
if (defaultId === undefined) {
70-
throw new Error('agent_id is required: no default retrieval service is configured; discover services with kb_service_list')
54+
throw new Error('agent_id is required: no default retrieval service is configured; discover services with `kscli service list`')
7155
}
7256
return defaultId
7357
}
7458
const resolveChatAgentId = async (supplied: string | undefined): Promise<string> => {
7559
if (supplied !== undefined) return supplied
7660
const defaultId = resolveDefaultChatAgentId === undefined ? undefined : await resolveDefaultChatAgentId()
7761
if (defaultId === undefined) {
78-
throw new Error('agent_id is required: no default chat service is configured; discover services with kb_service_list')
62+
throw new Error('agent_id is required: no default chat service is configured; discover services with `kscli service list`')
7963
}
8064
return defaultId
8165
}
8266

83-
const serviceList = defineTool({
84-
name: 'kb_service_list',
85-
description:
86-
'List the Bailian knowledge retrieval/Q&A services available in this workspace. '
87-
+ 'Each entry names the service id (agent_id) to pass to kb_search (scene=search) or kb_chat (scene=chat), '
88-
+ 'its bound knowledge bases, and its status (prefer deployed). '
89-
+ 'Omit scene to see both kinds; narrow large workspaces with name_filter.',
90-
parameters: {
91-
scene: { type: 'string', enum: ['chat', 'search'], description: 'Only list services for this scene; omitted lists both.' },
92-
name_filter: { type: 'string', description: 'Fuzzy match on the service name.' },
93-
},
94-
output: {
95-
schema: {
96-
type: 'object',
97-
additionalProperties: false,
98-
properties: {
99-
services: {
100-
type: 'array',
101-
required: true,
102-
items: {
103-
type: 'object',
104-
additionalProperties: false,
105-
properties: {
106-
agent_id: { type: 'string', required: true },
107-
name: { type: 'string', required: true },
108-
scene: { type: 'string', required: true },
109-
status: { type: 'string', required: true },
110-
knowledge_bases: { type: 'array', required: true, items: { type: 'string' } },
111-
},
112-
},
113-
},
114-
total: { type: 'integer', required: true },
115-
truncated: { type: 'boolean', required: true },
116-
},
117-
},
118-
render: (_args, value) => [{
119-
type: 'text',
120-
text: value.services.length === 0
121-
? 'No knowledge services found.'
122-
: `${value.services.length} service(s): ${formatServices(value.services)}`
123-
+ (value.truncated ? ` — listed first ${value.services.length} of ${value.total}; narrow with name_filter.` : ''),
124-
}],
125-
},
126-
async execute(args) {
127-
return await listServices(client, {
128-
...(args.scene === 'chat' || args.scene === 'search' ? { scene: args.scene } : {}),
129-
...(args.name_filter ? { nameFilter: args.name_filter } : {}),
130-
})
131-
},
132-
presentCall: args => ({ card: 'generic', title: 'List knowledge services', kind: 'other', rawInput: args }),
133-
})
134-
13567
const search = defineTool({
13668
name: 'kb_search',
13769
description:
@@ -251,5 +183,5 @@ export function createKbTools(deps: KbToolDeps) {
251183
presentCall: args => ({ card: 'generic', title: 'Ask knowledge base (may take a few minutes)', kind: 'fetch', rawInput: args }),
252184
})
253185

254-
return [serviceList, search, chat]
186+
return [search, chat]
255187
}

‎packages/tool-bailian-kb/src/web/locales.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export const en: Record<BailianKbLocaleKey, string> = {
3434
workspaceIdSet: 'A workspace is configured.',
3535
workspaceIdUnset: 'No workspace is configured; knowledge tools fail until one is.',
3636
retrieveAgentId: 'Default retrieval service id',
37-
retrieveAgentIdHint: 'agent_id of the default retrieval service (kb_search); when unset, every call must name one (kb_service_list discovers ids). Stored in the settings document.',
38-
retrieveAgentIdHintFallback: 'agent_id of the default retrieval service (kb_search); when unset, every call must name one (kb_service_list discovers ids). Leave blank to keep the current one.',
37+
retrieveAgentIdHint: 'agent_id of the default retrieval service (kb_search); when unset, every call must name one (`kscli service list` discovers ids). Stored in the settings document.',
38+
retrieveAgentIdHintFallback: 'agent_id of the default retrieval service (kb_search); when unset, every call must name one (`kscli service list` discovers ids). Leave blank to keep the current one.',
3939
retrieveAgentIdSet: 'A default retrieval service is configured.',
4040
retrieveAgentIdUnset: 'No default retrieval service; every kb_search call must name one.',
4141
chatAgentId: 'Default chat service id',
42-
chatAgentIdHint: 'agent_id of the default Q&A service (kb_chat); when unset, every call must name one (kb_service_list discovers ids). Stored in the settings document.',
43-
chatAgentIdHintFallback: 'agent_id of the default Q&A service (kb_chat); when unset, every call must name one (kb_service_list discovers ids). Leave blank to keep the current one.',
42+
chatAgentIdHint: 'agent_id of the default Q&A service (kb_chat); when unset, every call must name one (`kscli service list` discovers ids). Stored in the settings document.',
43+
chatAgentIdHintFallback: 'agent_id of the default Q&A service (kb_chat); when unset, every call must name one (`kscli service list` discovers ids). Leave blank to keep the current one.',
4444
chatAgentIdSet: 'A default chat service is configured.',
4545
chatAgentIdUnset: 'No default chat service; every kb_chat call must name one.',
4646
fromEnv: 'Set by the environment (read-only here)',
@@ -70,13 +70,13 @@ export const zh: Record<BailianKbLocaleKey, string> = {
7070
workspaceIdSet: '已配置工作空间。',
7171
workspaceIdUnset: '未配置工作空间;配置前知识库工具不可用。',
7272
retrieveAgentId: '默认检索服务 ID',
73-
retrieveAgentIdHint: '默认检索服务(kb_search)的 agent_id;未设置时每次调用都需显式指定(可用 kb_service_list 发现 id)。存入设置文档。',
74-
retrieveAgentIdHintFallback: '默认检索服务(kb_search)的 agent_id;未设置时每次调用都需显式指定(可用 kb_service_list 发现 id)。留空表示保持当前值。',
73+
retrieveAgentIdHint: '默认检索服务(kb_search)的 agent_id;未设置时每次调用都需显式指定(可用 `kscli service list` 发现 id)。存入设置文档。',
74+
retrieveAgentIdHintFallback: '默认检索服务(kb_search)的 agent_id;未设置时每次调用都需显式指定(可用 `kscli service list` 发现 id)。留空表示保持当前值。',
7575
retrieveAgentIdSet: '已配置默认检索服务。',
7676
retrieveAgentIdUnset: '未配置默认检索服务;每次 kb_search 调用需显式指定。',
7777
chatAgentId: '默认对话服务 ID',
78-
chatAgentIdHint: '默认对话服务(kb_chat)的 agent_id;未设置时每次调用都需显式指定(可用 kb_service_list 发现 id)。存入设置文档。',
79-
chatAgentIdHintFallback: '默认对话服务(kb_chat)的 agent_id;未设置时每次调用都需显式指定(可用 kb_service_list 发现 id)。留空表示保持当前值。',
78+
chatAgentIdHint: '默认对话服务(kb_chat)的 agent_id;未设置时每次调用都需显式指定(可用 `kscli service list` 发现 id)。存入设置文档。',
79+
chatAgentIdHintFallback: '默认对话服务(kb_chat)的 agent_id;未设置时每次调用都需显式指定(可用 `kscli service list` 发现 id)。留空表示保持当前值。',
8080
chatAgentIdSet: '已配置默认对话服务。',
8181
chatAgentIdUnset: '未配置默认对话服务;每次 kb_chat 调用需显式指定。',
8282
fromEnv: '来自环境变量(此处只读)',

‎packages/tool-bailian-kb/tests/endpoints.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ describe('kbEndpoint', () => {
99

1010
it('keeps protocol paths as constants', () => {
1111
expect(KB_PATHS.chat).toBe('/api/v2/apps/knowledge/chat')
12-
expect(KB_PATHS.serviceList).toBe('/api/v1/indices/rag/app/list')
12+
expect(KB_PATHS.search).toBe('/api/v1/indices/knowledge/search')
1313
})
1414
})

0 commit comments

Comments
 (0)