44 * @module dsh-tool-bailian-kb
55 */
66
7+ import type { Context } from '@deepseek-ai/cordis'
78import 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
914export const name = 'tool-bailian-kb'
1015export 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+ }
0 commit comments