Skip to content

Commit 589e3a4

Browse files
committed
chore(deps): 更新 TypeScript 类型检查脚本及依赖锁定文件
- 修改 package.json 中 typecheck 脚本,新增对 tsconfig.web.json 的检查 - 更新 pnpm-lock.yaml 文件,增加多个依赖项和绑定包的版本信息及平台支持 - 新增 react、lightningcss 等多种平台及架构的预编译绑定库 - 添加多种类型定义依赖,提升类型覆盖范围 - 升级部分工具包及插件版本,优化构建和开发体验
1 parent 50b59f8 commit 589e3a4

21 files changed

Lines changed: 1894 additions & 62 deletions

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "pnpm -r run build",
77
"test": "vitest run",
8-
"typecheck": "tsc -b packages/tool-bailian-kb"
8+
"typecheck": "tsc -b packages/tool-bailian-kb && tsc -p packages/tool-bailian-kb/tsconfig.web.json"
99
},
1010
"devDependencies": {
1111
"typescript": "^5.7.2",

‎packages/bundle/README.md‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bailian-kb-dsh(分发包)
22

3-
dsh bundle 分发面:`package.json` 的 `dsh.bundle.patch` 声明 + [`cordis.patch.yml`](cordis.patch.yml),向 profile 插入 `tool-bailian-kb` row。
3+
dsh bundle 分发面:`package.json` 的 `dsh.bundle.patch` 声明 + [`cordis.patch.yml`](cordis.patch.yml),向 profile 插入 `tool-bailian-kb` row,并随包分发浏览器端配置卡片(`dsh.client` → `lib/client.js`)。
44

55
## Patch row
66

@@ -12,25 +12,53 @@ dsh bundle 分发面:`package.json` 的 `dsh.bundle.patch` 声明 + [`cordis.p
1212
workspaceId: !!js process.env.BAILIAN_WORKSPACE_ID
1313
```
1414
15-
`workspaceId` 默认从环境变量读取(`~/.dsh/.env` 写 `BAILIAN_WORKSPACE_ID=ws-xxx` 即可运行);未设置时插件加载期 fail loud。
15+
`workspaceId` 只是解析链的一层,不是唯一来源:config 显式值(含此环境变量读取)per-call 优先;未设置时回退到 `BAILIAN_WORKSPACE_ID` credential。同样回退覆盖 `defaultAgentId`(`BAILIAN_DEFAULT_AGENT_ID`)与 API key(`DASHSCOPE_API_KEY`)。
16+
17+
## 三个值的解析链
18+
19+
| 值 | 1️⃣ config 显式值(本 patch 或用户覆盖) | 2️⃣ credential(UI 卡片 / `~/.dsh/.credentials.yaml`) | 3️⃣ 都缺失时 |
20+
|---|---|---|---|
21+
| `DASHSCOPE_API_KEY` | —(无 config 面) | ✅ | 工具调用报错并引导配置 |
22+
| `BAILIAN_WORKSPACE_ID` | `workspaceId` | ✅ | 工具调用报错并引导配置 |
23+
| `BAILIAN_DEFAULT_AGENT_ID` | `defaultAgentId` | ✅ | `agent_id` 参数变必填(schema 恒 optional,运行时校验) |
24+
25+
行为参数(`endpointHost`/`agentVersion`/`chatTimeoutMs`)只在 config 层,见 [tool-bailian-kb README](../tool-bailian-kb/README.md)。
26+
27+
## Web UI 配置卡片
28+
29+
装进 profile 后,Settings → Plugins 出现“百炼知识库”卡片,可配置三个 credential(写 `~/.dsh/.credentials.yaml`):
30+
31+
- **DashScope API Key** — write-only,`type=password` 遮罩输入草稿
32+
- **Bailian Workspace ID** — 明文(便于粘贴核对 workspace id)
33+
- **默认服务 ID(agent_id)** — 明文,附独立“清除”按钮(留空保存 = 不写,清除须显式 unset)
34+
35+
值永不回显:字段始终空白起步,仅显示 configured/来自环境变量 徽标;来自 shell export 或 `~/.dsh/.env` 的值只读(继承环境层),输入框禁用。
1636

1737
## 用户覆盖
1838

19-
用户 patch 层在本 bundle 之上,按 id 覆盖时**替换整个 config(无 deep-merge),必须连 workspaceId 一起重述**:
39+
用户 patch 层在本 bundle 之上,按 id 覆盖时**替换整个 config(无 deep-merge)**。`workspaceId`/`defaultAgentId` 均为可选,只需重述想显式固定的字段:
2040

2141
```yaml
2242
# ~/.dsh/cordis.patch.yml 或 profile 的 cordis.patch.yml
2343
- id: tool-bailian-kb
2444
config:
25-
workspaceId: ws-xxx
26-
defaultAgentId: aid-customer-service # 场景固定式部署
45+
defaultAgentId: aid-customer-service # 场景固定式部署;省略 workspaceId 走 credential
2746
chatTimeoutMs: 600000
2847
```
2948

3049
禁用:`- id: tool-bailian-kb` + `disabled: true`。
3150

51+
## 安装(本地 checkout 链接)
52+
53+
bundle 是 `dsh.bundle` 声明层,真正的插件包 `dsh-tool-bailian-kb` 是它的依赖;`link:` 安装不携带传递依赖,**两个包都要 add**(第二个无 bundle 声明,dsh 会以 plain dependency 装入,CLI 的 warning 即预期行为):
54+
55+
```sh
56+
dsh plugin --profile web add /path/to/bailian-kb-dsh/packages/bundle
57+
dsh plugin --profile web add /path/to/bailian-kb-dsh/packages/tool-bailian-kb
58+
```
59+
3260
## 卸载
3361

3462
```sh
35-
dsh plugin --profile <name> remove bailian-kb-dsh
63+
dsh plugin --profile <name> remove bailian-kb-dsh dsh-tool-bailian-kb
3664
```

‎packages/bundle/cordis.patch.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# bailian-kb-dsh: inserts the Bailian knowledge-base consumer over dsh-base.
2-
# workspaceId reads BAILIAN_WORKSPACE_ID from the environment (~/.dsh/.env) so a
3-
# user patch is only needed to pin defaultAgentId or override the host/timeout.
4-
# An id-targeted user patch replaces this whole config: restate workspaceId too.
2+
# workspaceId here is one resolution layer, not the only one: a config value
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 defaultAgentId via
6+
# BAILIAN_DEFAULT_AGENT_ID, and the API key via DASHSCOPE_API_KEY.
57

68
- insert:
79
- id: tool-bailian-kb

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,55 @@
77
"types": "lib/index.d.ts",
88
"exports": {
99
".": { "types": "./lib/index.d.ts", "default": "./lib/index.js" },
10+
"./client": { "default": "./lib/web/client.js" },
1011
"./package.json": "./package.json"
1112
},
13+
"dsh": {
14+
"client": {
15+
"inject": [
16+
"@deepseek-ai/dsh-client-connection",
17+
"@deepseek-ai/dsh-client-locale",
18+
"@deepseek-ai/dsh-client-runtime",
19+
"@deepseek-ai/dsh-api-remotes",
20+
"@deepseek-ai/dsh-client-ui-settings-plugins"
21+
],
22+
"platform": "web"
23+
}
24+
},
1225
"files": ["lib", "skills"],
13-
"scripts": { "build": "tsc -b" },
26+
"scripts": { "build": "tsc -b && tsdown" },
1427
"peerDependencies": {
1528
"@deepseek-ai/cordis": "^4.0.1",
1629
"@deepseek-ai/dsh-tools": "*",
1730
"@deepseek-ai/dsh-credentials": "*",
1831
"@deepseek-ai/dsh-skill": "*",
19-
"@deepseek-ai/schemastery": "^3.18.1"
32+
"@deepseek-ai/schemastery": "^3.18.1",
33+
"@deepseek-ai/dsh-api-remotes": "*",
34+
"@deepseek-ai/dsh-client-connection": "*",
35+
"@deepseek-ai/dsh-client-locale": "*",
36+
"@deepseek-ai/dsh-client-runtime": "*",
37+
"@deepseek-ai/dsh-client-ui-settings-plugins": "*",
38+
"@deepseek-ai/dsh-client-ui-primitives": "*",
39+
"@deepseek-ai/dsh-client-ui-slots": "*",
40+
"react": "^18.2.0"
2041
},
2142
"devDependencies": {
2243
"@deepseek-ai/cordis": "link:../../../deepseek-harness/vendor/cordis",
2344
"@deepseek-ai/dsh-tools": "link:../../../deepseek-harness/packages/core/tools",
2445
"@deepseek-ai/dsh-credentials": "link:../../../deepseek-harness/packages/credentials/credentials",
2546
"@deepseek-ai/dsh-skill": "link:../../../deepseek-harness/packages/skill/skill",
2647
"@deepseek-ai/schemastery": "link:../../../deepseek-harness/vendor/schemastery",
27-
"@types/node": "^22.0.0"
48+
"@deepseek-ai/dsh-api-remotes": "link:../../../deepseek-harness/packages/api/remotes",
49+
"@deepseek-ai/dsh-client-connection": "link:../../../deepseek-harness/packages/client/connection",
50+
"@deepseek-ai/dsh-client-locale": "link:../../../deepseek-harness/packages/client/locale",
51+
"@deepseek-ai/dsh-client-runtime": "link:../../../deepseek-harness/packages/client/runtime",
52+
"@deepseek-ai/dsh-client-ui-settings-plugins": "link:../../../deepseek-harness/packages/client/ui-settings-plugins",
53+
"@deepseek-ai/dsh-client-ui-primitives": "link:../../../deepseek-harness/packages/client/ui-primitives",
54+
"@deepseek-ai/dsh-client-ui-slots": "link:../../../deepseek-harness/packages/client/ui-slots",
55+
"@types/node": "^22.0.0",
56+
"@types/react": "~18.3.1",
57+
"lightningcss": "^1.32.0",
58+
"react": "^18.2.0",
59+
"tsdown": "^0.22.2"
2860
}
2961
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export class KbApiError extends Error {
1414
}
1515

1616
export interface KbClientOptions {
17-
workspaceId: string
17+
/** Resolves the current workspace id per call (patch config or credential); throws with guidance when unconfigured. */
18+
resolveWorkspaceId: () => Promise<string>
1819
endpointHost: string
1920
/** Service version forwarded on search/chat when set (deployment debug choice). */
2021
agentVersion?: string
@@ -33,9 +34,9 @@ export class KbClient {
3334
}
3435

3536
private async post(path: string, body: unknown, accept: string, signal?: AbortSignal): Promise<Response> {
36-
const apiKey = await this.opts.resolveApiKey()
37+
const [apiKey, workspaceId] = await Promise.all([this.opts.resolveApiKey(), this.opts.resolveWorkspaceId()])
3738
const fetchImpl = this.opts.fetchImpl ?? fetch
38-
const url = kbEndpoint(this.opts.endpointHost, this.opts.workspaceId, path)
39+
const url = kbEndpoint(this.opts.endpointHost, workspaceId, path)
3940
const res = await fetchImpl(url, {
4041
method: 'POST',
4142
headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json', 'Accept': accept },

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ export const inject = ['tools', 'credentials']
1616

1717
/** Bailian knowledge-base plugin configuration. */
1818
export interface Config {
19-
/** Bailian workspace id; the API host is the workspace subdomain `https://<workspaceId>.<endpointHost>`. */
20-
workspaceId: string
19+
/** Bailian workspace id; the API host is the workspace subdomain `https://<workspaceId>.<endpointHost>`. Optional here: an unset value falls back per call to the BAILIAN_WORKSPACE_ID credential (Settings → Plugins card or ~/.dsh/.credentials.yaml). */
20+
workspaceId?: string
2121
/** API host suffix; replace for other regions or private deployments. */
2222
endpointHost: string
23-
/** Retrieval-service id pinned by this deployment; when set, the tools' agent_id parameter becomes optional. */
23+
/** Retrieval-service id pinned by this deployment; when unset, the per-call fallback reads the BAILIAN_DEFAULT_AGENT_ID credential. */
2424
defaultAgentId?: string
2525
/** Service version to call: `beta` (draft) or a published number; defaults to the latest published version. Never model-visible. */
2626
agentVersion?: string
2727
/** kb_chat timeout in milliseconds; the server side is a minutes-scale agentic loop. */
2828
chatTimeoutMs: number
2929
}
3030

31-
/** Schemastery validation for {@link Config}; a missing workspaceId fails at load. */
31+
/** Schemastery validation for {@link Config}; workspaceId and defaultAgentId are optional — both resolve per call with a credentials fallback. */
3232
export const Config: z<Config> = z.object({
33-
workspaceId: z.string().required(),
33+
workspaceId: z.string(),
3434
endpointHost: z.string().default('cn-beijing.maas.aliyuncs.com'),
3535
defaultAgentId: z.string(),
3636
agentVersion: z.string(),
@@ -44,24 +44,42 @@ export const Config: z<Config> = z.object({
4444
* @param config - deployment's workspace, host, pinning, and timeout choices.
4545
*/
4646
export function apply(ctx: Context, config: Config): void {
47+
const pinnedWorkspaceId = config.workspaceId
48+
const pinnedAgentId = config.defaultAgentId
4749
const client = new KbClient({
48-
workspaceId: config.workspaceId,
50+
resolveWorkspaceId: pinnedWorkspaceId === undefined
51+
? async () => {
52+
const resolved = await ctx.credentials.resolve(credentialRef('BAILIAN_WORKSPACE_ID'))
53+
if (!resolved) {
54+
throw new Error(
55+
'BAILIAN_WORKSPACE_ID is not configured. Set it in the web UI (Settings → Plugins → Bailian knowledge base) '
56+
+ 'or in ~/.dsh/.credentials.yaml; the workspace id appears as the subdomain of your Bailian endpoints.',
57+
)
58+
}
59+
return resolved.value
60+
}
61+
: async () => pinnedWorkspaceId,
4962
endpointHost: config.endpointHost,
5063
...(config.agentVersion ? { agentVersion: config.agentVersion } : {}),
5164
resolveApiKey: async () => {
5265
const resolved = await ctx.credentials.resolve(credentialRef('DASHSCOPE_API_KEY'))
5366
if (!resolved) {
5467
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).',
68+
'DASHSCOPE_API_KEY is not configured. Set it in the web UI (Settings → Plugins → Bailian knowledge base) '
69+
+ 'or in ~/.dsh/.credentials.yaml (create a key at https://bailian.console.aliyun.com/?tab=app#/api-key).',
5770
)
5871
}
5972
return resolved.value
6073
},
6174
})
6275
for (const tool of createKbTools({
6376
client,
64-
...(config.defaultAgentId ? { defaultAgentId: config.defaultAgentId } : {}),
77+
resolveDefaultAgentId: pinnedAgentId !== undefined
78+
? async () => pinnedAgentId
79+
: async () => {
80+
const resolved = await ctx.credentials.resolve(credentialRef('BAILIAN_DEFAULT_AGENT_ID'))
81+
return resolved?.value
82+
},
6583
chatTimeoutMs: config.chatTimeoutMs,
6684
})) {
6785
ctx.tools.register(tool)

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
2-
* The three model-facing knowledge tools. Schemas are static per deployment: a configured
3-
* defaultAgentId downgrades agent_id to optional at build time (never a runtime fallback chain).
2+
* The three model-facing knowledge tools. agent_id stays optional in the schema
3+
* regardless of deployment: the default service (patch config or credential)
4+
* can change at runtime through the credentials domain, so the fallback runs
5+
* per call and a missing default surfaces as an executable error instead of a
6+
* load-time schema difference.
47
*/
58

69
import { defineTool } from '@deepseek-ai/dsh-tools'
@@ -15,7 +18,8 @@ const DEFAULT_TOP_K = 5
1518

1619
export interface KbToolDeps {
1720
client: KbClient
18-
defaultAgentId?: string
21+
/** Resolves the default agent id per call (patch config or credential); omitted means no default. */
22+
resolveDefaultAgentId?: () => Promise<string | undefined>
1923
chatTimeoutMs: number
2024
}
2125

@@ -49,18 +53,18 @@ async function withServiceHint(client: KbClient, err: unknown): Promise<never> {
4953
* @returns definitions ready for `ctx.tools.register()`.
5054
*/
5155
export function createKbTools(deps: KbToolDeps) {
52-
const { client, defaultAgentId, chatTimeoutMs } = deps
56+
const { client, resolveDefaultAgentId, chatTimeoutMs } = deps
5357
const agentIdParam = {
5458
type: 'string' as const,
55-
...(defaultAgentId === undefined ? { required: true as const } : {}),
56-
description: defaultAgentId === undefined
57-
? 'Retrieval/Q&A service id (find one via kb_service_list).'
58-
: 'Retrieval/Q&A service id; omit to use this deployment\'s default service.',
59+
description: 'Retrieval/Q&A service id; omit to use the default service when this deployment configures one (find ids via kb_service_list).',
5960
}
60-
const resolveAgentId = (supplied: string | undefined): string => {
61-
const agentId = supplied ?? defaultAgentId
62-
if (agentId === undefined) throw new Error('agent_id is required: discover services with kb_service_list')
63-
return agentId
61+
const resolveAgentId = async (supplied: string | undefined): Promise<string> => {
62+
if (supplied !== undefined) return supplied
63+
const defaultId = resolveDefaultAgentId === undefined ? undefined : await resolveDefaultAgentId()
64+
if (defaultId === undefined) {
65+
throw new Error('agent_id is required: no default service is configured; discover services with kb_service_list')
66+
}
67+
return defaultId
6468
}
6569

6670
const serviceList = defineTool({
@@ -163,7 +167,7 @@ export function createKbTools(deps: KbToolDeps) {
163167
const topK = args.top_k ?? DEFAULT_TOP_K
164168
const body: SearchRequest = {
165169
query: args.query,
166-
agent_id: resolveAgentId(args.agent_id),
170+
agent_id: await resolveAgentId(args.agent_id),
167171
...(client.agentVersion ? { agent_version: client.agentVersion } : {}),
168172
...(args.images && args.images.length > 0 ? { images: args.images } : {}),
169173
}
@@ -210,7 +214,7 @@ export function createKbTools(deps: KbToolDeps) {
210214
const body = {
211215
input: { messages: [{ role: 'user' as const, content: args.message }] },
212216
parameters: { agent_options: {
213-
agent_id: resolveAgentId(args.agent_id),
217+
agent_id: await resolveAgentId(args.agent_id),
214218
...(client.agentVersion ? { agent_version: client.agentVersion } : {}),
215219
} },
216220
stream: true as const,

0 commit comments

Comments
 (0)