Skip to content

Commit f36e044

Browse files
committed
feat(shellEnv): 注册并导出 Bailian 工作空间 ID 环境变量
- 新增 ShellEnvRegistration 接口定义,避免对主包依赖 - 为上下文添加 shellEnv 注册功能支持 - 在注入阶段注册 Bailian 工作空间 ID 环境变量 - 使管理 CLI 命令可访问解析后的工作空间 ID - 确保子进程环境变量继承设置服务解析结果
1 parent 0ef7c82 commit f36e044

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ interface WebRoute {
1919
path: string
2020
handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>
2121
}
22+
/** Shell-environment registration shape (declared inline to avoid a host-package dependency). */
23+
interface ShellEnvRegistration {
24+
name: string
25+
variables: Record<string, { description: string }>
26+
resolve: () => Record<string, string | undefined>
27+
}
2228
declare module '@deepseek-ai/cordis' {
2329
interface Context {
2430
webServer: {
2531
register(route: WebRoute): () => void
2632
}
33+
shellEnv: {
34+
register(registration: ShellEnvRegistration): void
35+
}
2736
}
2837
}
2938

@@ -184,6 +193,25 @@ export function apply(ctx: Context, config: Config): void {
184193
}
185194
registerSkill(ctx)
186195

196+
// Export the resolved workspace id as a shell environment variable so
197+
// management CLI commands (`bl knowledge list`, `kscli kb list`, etc.)
198+
// running in bash can see the value the settings service resolved.
199+
// Without this, the settings.yaml value is invisible to child processes.
200+
ctx.inject(['shellEnv'], (envCtx) => {
201+
envCtx.shellEnv.register({
202+
name: 'bailian-kb',
203+
variables: {
204+
BAILIAN_WORKSPACE_ID: {
205+
description: 'Bailian workspace id resolved from settings (Settings → 百炼知识库) or credentials.',
206+
},
207+
},
208+
resolve: () => {
209+
const wsId = current().workspaceId
210+
return wsId ? { BAILIAN_WORKSPACE_ID: wsId } : {}
211+
},
212+
})
213+
})
214+
187215
// Bridge routes let the browser settings page read and write the resolved
188216
// section without riding the settings wire (which requires an apiproxy
189217
// allowlist entry the composition does not grant out-of-tree namespaces).

0 commit comments

Comments
 (0)