Skip to content

Commit b4129c6

Browse files
committed
feat: plugin apply wiring with credential-backed client and skill registration
1 parent f2a3775 commit b4129c6

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: bailian-kb-management
3+
description: 管理阿里云百炼知识库(建库、上传文档、部署检索服务、Chunk 运维)。当用户要创建/更新/删除知识库、上传或导入文档、部署检索服务、管理数据中心文件时使用 kscli。检索与问答不走本 skill——用原生工具 kb_search / kb_chat。
4+
---
5+
6+
# 百炼知识库管理(kscli)
7+
8+
检索面与管理面的分工:**查知识用 `kb_search`(取证据)/ `kb_chat`(成品问答)原生工具;本 skill 只覆盖管理长尾**——知识库全生命周期、文档、检索服务、Chunk、数据中心。
9+
10+
## 前置检查
11+
12+
1. `kscli --version` —— 未安装则运行 `npm install -g knowledge-studio-cli`(需 Node.js ≥ 18.17);安装失败时把错误原样报告给用户,不要静默跳过。
13+
2. 鉴权:需要 `DASHSCOPE_API_KEY`(环境变量,或 `kscli config set --key api_key --value sk-xxx`)。
14+
3. workspace 解析优先级:`--workspace-id` 参数 > 环境变量 `BAILIAN_WORKSPACE_ID` > `kscli config set --key workspace_id --value ws-xxx`。
15+
16+
## 常用工作流:建库到可检索
17+
18+
```bash
19+
kscli kb create --name "my-kb" --embedding-model text-embedding-v3 # 1. 建库
20+
kscli doc upload --kb-id <kb-id> --file ./docs.pdf # 2. 上传本地文档
21+
kscli doc status --kb-id <kb-id> --doc-id <doc-id> # 3. 轮询至 COMPLETED
22+
kscli service create ... && kscli service deploy ... # 4. 建/部署检索服务 → 得到 agent_id
23+
```
24+
25+
部署完成后用 `kb_service_list` 确认服务可见,再用 `kb_search` 带该 `agent_id` 验证检索。
26+
27+
## 命令组速查
28+
29+
`kb`(list/info/create/update/delete/stats)· `doc`(list/upload/status/delete/tag/import-oss)· `service`(list/get/create/update/deploy/delete/copy)· `chunk`(add/list/update/delete)· `file` / `collection` / `category`(数据中心)。全部命令支持 `--output json`(结构化输出)、`--dry-run`(预览请求)、`--quiet`。完整手册:https://github.com/modelstudioai/cli/blob/main/docs/knowledge-cli-guide.md
30+
31+
## 最佳实践
32+
33+
- 用户反复使用同一检索服务时,建议其把 agent_id 写入项目指令(如 AGENTS.md)或让 agent 记住,后续 kb_search / kb_chat 直接携带。
34+
- 服务有 draft/deployed 两种状态:只有 deployed 可被默认版本调用;draft 调试用 `--agent-version beta`。

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
* @module dsh-tool-bailian-kb
55
*/
66

7+
import type { Context } from '@deepseek-ai/cordis'
78
import z from '@deepseek-ai/schemastery'
9+
import { credentialRef } from '@deepseek-ai/dsh-credentials'
10+
import { KbClient } from './client.js'
11+
import { registerSkill } from './skill.js'
12+
import { createKbTools } from './tools.js'
813

914
export const name = 'tool-bailian-kb'
1015
export const inject = ['tools', 'credentials']
@@ -31,3 +36,35 @@ export const Config: z<Config> = z.object({
3136
agentVersion: z.string(),
3237
chatTimeoutMs: z.number().default(300_000),
3338
})
39+
40+
/**
41+
* Register the three knowledge tools over one shared client, plus the
42+
* management skill when a skills registry is composed.
43+
* @param ctx - registrant context carrying tools and credentials.
44+
* @param config - deployment's workspace, host, pinning, and timeout choices.
45+
*/
46+
export function apply(ctx: Context, config: Config): void {
47+
const client = new KbClient({
48+
workspaceId: config.workspaceId,
49+
endpointHost: config.endpointHost,
50+
...(config.agentVersion ? { agentVersion: config.agentVersion } : {}),
51+
resolveApiKey: async () => {
52+
const resolved = await ctx.credentials.resolve(credentialRef('DASHSCOPE_API_KEY'))
53+
if (!resolved) {
54+
throw new Error(
55+
'DASHSCOPE_API_KEY is not configured. Set it in ~/.dsh/.env or .credentials.yaml '
56+
+ '(create a key at https://bailian.console.aliyun.com/?tab=app#/api-key).',
57+
)
58+
}
59+
return resolved.value
60+
},
61+
})
62+
for (const tool of createKbTools({
63+
client,
64+
...(config.defaultAgentId ? { defaultAgentId: config.defaultAgentId } : {}),
65+
chatTimeoutMs: config.chatTimeoutMs,
66+
})) {
67+
ctx.tools.register(tool)
68+
}
69+
registerSkill(ctx)
70+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** Runtime skill registration: the packaged kscli-management SKILL.md joins the catalog when a skills registry is composed. */
2+
3+
import { readFileSync } from 'node:fs'
4+
import { join } from 'node:path'
5+
import { fileURLToPath } from 'node:url'
6+
import type { Context } from '@deepseek-ai/cordis'
7+
// Type-only: resolves ctx.skills for the optional inject below.
8+
import type {} from '@deepseek-ai/dsh-skill'
9+
10+
const SKILL_DIR = fileURLToPath(new URL('../skills/bailian-kb-management/', import.meta.url))
11+
12+
/**
13+
* Register the management skill when the skills registry is composed; headless
14+
* assemblies without the seam stay unaffected.
15+
* @param ctx - the plugin context.
16+
*/
17+
export function registerSkill(ctx: Context): void {
18+
ctx.inject(['skills'], (skillCtx) => {
19+
const content = readFileSync(join(SKILL_DIR, 'SKILL.md'), 'utf8')
20+
skillCtx.skills.register({
21+
name: 'bailian-kb-management',
22+
description:
23+
'Manage Bailian knowledge bases with the kscli CLI: create/update KBs, upload documents, deploy '
24+
+ 'retrieval services, and maintain chunks. Retrieval itself uses the native kb_search/kb_chat tools.',
25+
content,
26+
source: 'bundled',
27+
resourceBase: { kind: 'directory', path: SKILL_DIR },
28+
})
29+
})
30+
}

0 commit comments

Comments
 (0)