bailian-cli-commands 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +2 -5
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -2726,13 +2726,10 @@ Omni output voices:
|
|
|
2726
2726
|
`),t.dryRun){A({agent:r,label:l.label,base_url:s,api_key:Qt(c),model:i},u);return}let d={baseUrl:s,apiKey:c,model:i,contextWindow:a,wireApi:o,localize:e.localize},f=l.write(d);if(!t.quiet){k(`${l.label} configured successfully.`);for(let e of f.paths)k(` Written: ${e}`);k(` ${f.nextStep}`);for(let e of f.warnings??[])process.stderr.write(`Warning: ${e}\n`)}}});const Td=`bl skill update`;function Ed(e){process.stderr.write(`
|
|
2727
2727
|
Updating agent skill...
|
|
2728
2728
|
`);try{Bi(Td,{stdio:`inherit`}),process.stderr.write(`${e.green(`✓ Agent skill updated.`)}\n`)}catch{process.stderr.write(`${e.yellow(`Agent skill update skipped. Run manually: ${Td}`)}\n`)}}function Dd(e){try{let t=vi(dt(),`update-state.json`);mi(t,JSON.stringify({lastChecked:Date.now(),latestVersion:e}))}catch{}}async function Od(e,t){return e===`binary`?await Ir(`latest`,5e3)??await Lr(5e3,t):Lr(5e3,t)}function kd(){return process.platform===`win32`?` irm ${s} | iex\n`:` curl -fsSL ${c} | bash\n`}var Ad=w({description:{"en-US":`Update the CLI to the latest or a specified version`,"zh-CN":`将 CLI 更新到最新版本或指定版本`},auth:`none`,usageArgs:`[--to <version>]`,flags:{to:{type:`string`,valueHint:`<version>`,description:{"en-US":`Install this exact version instead of the latest`,"zh-CN":`安装指定版本,而不是最新版本`}}},exampleArgs:[``,`--to 0.1.14`],validate(e){if(e.to!==void 0){if(!e.to.trim())return`--to requires a non-empty version`;if(!Hr(e.to))return`--to must be a semver version (e.g. 1.13.0, v1.13.0, 0.0.0-beta-<sha>-<YYYYMMDDHHMM>), got: ${e.to.trim()}`}},async run(e){let{identity:t}=e,r=t.npmPackage,i=t.binName,a=t.version,o=O(process.stderr),s=St(t),c=e.flags.to?.trim(),l=c?Wr(c):void 0;if(process.stderr.write(`Current version: ${o.yellow(a)}\n`),process.stderr.write(`Install method: ${o.dim(s)}\n`),l?process.stderr.write(`Target version: ${o.green(l)}\n`):process.stderr.write(`Checking for updates...
|
|
2729
|
-
`),s===`brew`||s===`winget`){let e=s===`brew`?`brew upgrade bailian-cli`:`winget upgrade Aliyun.BailianCLI`;process.stderr.write(`${o.yellow(`This CLI was installed via ${s}. Update with:`)}\n ${e}\n`),l&&process.stderr.write(`${o.dim(`Note: --to is not supported for ${s} installs.`)}\n`);return}let u=l??await Od(s,r);if(!u)
|
|
2729
|
+
`),s===`brew`||s===`winget`){let e=s===`brew`?`brew upgrade bailian-cli`:`winget upgrade Aliyun.BailianCLI`;process.stderr.write(`${o.yellow(`This CLI was installed via ${s}. Update with:`)}\n ${e}\n`),l&&process.stderr.write(`${o.dim(`Note: --to is not supported for ${s} installs.`)}\n`);return}let u=l??await Od(s,r);if(!u)throw new n(`Could not determine the latest version.`,f.GENERAL,`Check network access, or pass --to <version>.`);if(u===a){let e=l?`\u2713 Already at ${a}.`:`\u2713 Already up to date (${a}).`;process.stderr.write(`${o.green(e)}\n`),s===`npm`&&Ed(o);return}if(l?process.stderr.write(`
|
|
2730
2730
|
`):process.stderr.write(`Latest version: ${o.green(u)}\n\n`),s===`binary`){process.stderr.write(`Updating via binary channel...
|
|
2731
2731
|
|
|
2732
|
-
`);try{let e=await Gr(u);process.stderr.write(`\n${o.green(`\u2713 Update complete: ${a} \u2192 ${e}`)}\n`),Dd(e),Ed(o)}catch(e){let t=e instanceof
|
|
2733
|
-
`),process.stderr.write(` ${r}\n\n`)}return}let d=`npm install -g ${l?`${r}@${l}`:`${r}@latest`}`;process.stderr.write(`Updating ${r} via npm...\n\n`);try{Bi(d,{stdio:`inherit`});try{let e=Bi(`${i} --version 2>/dev/null`,{encoding:`utf-8`}).trim().replace(RegExp(`^${i}\\s+`),``);process.stderr.write(`\n${o.green(`\u2713 Update complete: ${a} \u2192 ${e}`)}\n`),Dd(e)}catch{process.stderr.write(`\n${o.green(`✓ Update complete.`)}\n`)}Ed(o)}catch{process.stderr.write(`
|
|
2734
|
-
Automatic update failed. Please run manually:
|
|
2735
|
-
`),process.stderr.write(` ${d}\n\n`)}}}),jd=w({description:{"en-US":`Call a Bailian application (agent or workflow)`,"zh-CN":`调用百炼应用(智能体或工作流)`},auth:`apiKey`,usageArgs:`--app-id <id> --prompt <text> [flags]`,flags:{appId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Application ID (required)`,"zh-CN":`应用 ID(必填)`},required:!0},prompt:{type:`string`,valueHint:`<text>`,description:{"en-US":`Input prompt text`,"zh-CN":`输入提示词文本`},required:!0},image:{type:`array`,valueHint:`<url>`,description:{"en-US":`Image URL(s) to pass to the app (repeatable)`,"zh-CN":`传给应用的图片 URL(可重复)`}},fileId:{type:`array`,valueHint:`<id>`,description:{"en-US":`Pre-uploaded file ID(s) (repeatable)`,"zh-CN":`已上传的文件 ID(可重复)`}},sessionId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Session ID for multi-turn conversation`,"zh-CN":`多轮对话的 Session ID`}},stream:{type:`switch`,description:{"en-US":`Stream response (default: on in TTY)`,"zh-CN":`流式输出响应(TTY 中默认开启)`}},pipelineIds:{type:`string`,valueHint:`<ids>`,description:{"en-US":`Knowledge base pipeline IDs (comma-separated)`,"zh-CN":`知识库 Pipeline ID(以逗号分隔)`}},memoryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory ID for long-term memory`,"zh-CN":`长期记忆使用的 Memory ID`}},bizParams:{type:`string`,valueHint:`<json>`,description:{"en-US":`Business parameters JSON (workflow variables)`,"zh-CN":`业务参数 JSON(工作流变量)`}},hasThoughts:{type:`switch`,description:{"en-US":`Show agent thinking process`,"zh-CN":`显示智能体思考过程`}}},exampleArgs:[{"en-US":`--app-id abc123 --prompt "Hello"`,"zh-CN":`--app-id abc123 --prompt "你好"`},{"en-US":`--app-id abc123 --prompt "Describe this image" --image https://example.com/photo.jpg`,"zh-CN":`--app-id abc123 --prompt "描述这张图片" --image https://example.com/photo.jpg`},{"en-US":`--app-id abc123 --prompt "Analyze the image" --image img1.jpg --image img2.jpg`,"zh-CN":`--app-id abc123 --prompt "分析这些图片" --image img1.jpg --image img2.jpg`},{"en-US":`--app-id abc123 --prompt "Continue" --session-id sess_xxx --stream`,"zh-CN":`--app-id abc123 --prompt "继续" --session-id sess_xxx --stream`},{"en-US":`--app-id abc123 --prompt "Search for materials" --pipeline-ids pipe1,pipe2`,"zh-CN":`--app-id abc123 --prompt "搜索资料" --pipeline-ids pipe1,pipe2`},{"en-US":`--app-id abc123 --prompt "Start" --biz-params '{"key":"value"}'`,"zh-CN":`--app-id abc123 --prompt "开始" --biz-params '{"key":"value"}'`}],async run(e){let{settings:t,flags:n}=e,r=n.appId,i=n.prompt,a=n.stream||process.stdout.isTTY,o=T(t.output),s={input:{prompt:i},parameters:{incremental_output:a}};n.sessionId&&(s.input.session_id=n.sessionId);let c=n.image;c&&c.length>0&&(s.input.image_list=c);let l=n.fileId;if(l&&l.length>0&&(s.input.file_ids=l),n.hasThoughts&&(s.parameters.has_thoughts=!0),n.pipelineIds){let e=n.pipelineIds.split(`,`).map(e=>e.trim()).filter(Boolean);s.parameters.rag_options={pipeline_ids:e}}if(n.memoryId&&(s.parameters.memory_id=n.memoryId),n.bizParams)try{s.input.biz_params=JSON.parse(n.bizParams)}catch{throw new C(`--biz-params must be valid JSON`)}if(t.dryRun){A({endpoint:e.client.url(se(r)),request:s},o);return}if(a){let i=await e.client.request({path:se(r),method:`POST`,body:s,headers:{"X-DashScope-SSE":`enable`},stream:!0}),a=``,c=``,l=o===`text`,u=O(process.stderr);for await(let e of mn(i)){if(e.data===`[DONE]`)break;try{let t=JSON.parse(e.data),r=t.output?.text;if(r&&(l&&process.stdout.write(r),a+=r),t.output?.session_id&&(c=t.output.session_id),t.output?.thoughts&&n.hasThoughts)for(let e of t.output.thoughts)e.thought&&process.stderr.write(`${u.dim(`[Thinking] ${e.thought}`)}\n`),e.action_name&&process.stderr.write(`${u.dim(`[Action] ${e.action_name}: ${e.action_input||``}`)}\n`),e.observation&&process.stderr.write(`${u.dim(`[Observation] ${e.observation}`)}\n`)}catch{}}c&&!t.quiet&&process.stderr.write(`${u.dim(`Session ID: ${c}`)}\n`),o===`json`?A({text:a,session_id:c},o):process.stdout.write(`
|
|
2732
|
+
`);try{let e=await Gr(u);process.stderr.write(`\n${o.green(`\u2713 Update complete: ${a} \u2192 ${e}`)}\n`),Dd(e),Ed(o)}catch(e){let t=e instanceof n&&e.hint?e.hint.replace(/^Re-run:\s*/i,``):kd().trim();throw new n(`Automatic binary update failed.`,f.GENERAL,`Re-run the install script:\n ${t}`,{cause:e})}return}let d=`npm install -g ${l?`${r}@${l}`:`${r}@latest`}`;process.stderr.write(`Updating ${r} via npm...\n\n`);try{Bi(d,{stdio:`inherit`});try{let e=Bi(`${i} --version 2>/dev/null`,{encoding:`utf-8`}).trim().replace(RegExp(`^${i}\\s+`),``);process.stderr.write(`\n${o.green(`\u2713 Update complete: ${a} \u2192 ${e}`)}\n`),Dd(e)}catch{process.stderr.write(`\n${o.green(`✓ Update complete.`)}\n`)}Ed(o)}catch(e){throw new n(`Automatic update failed.`,f.GENERAL,`Please run manually:\n ${d}`,{cause:e})}}}),jd=w({description:{"en-US":`Call a Bailian application (agent or workflow)`,"zh-CN":`调用百炼应用(智能体或工作流)`},auth:`apiKey`,usageArgs:`--app-id <id> --prompt <text> [flags]`,flags:{appId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Application ID (required)`,"zh-CN":`应用 ID(必填)`},required:!0},prompt:{type:`string`,valueHint:`<text>`,description:{"en-US":`Input prompt text`,"zh-CN":`输入提示词文本`},required:!0},image:{type:`array`,valueHint:`<url>`,description:{"en-US":`Image URL(s) to pass to the app (repeatable)`,"zh-CN":`传给应用的图片 URL(可重复)`}},fileId:{type:`array`,valueHint:`<id>`,description:{"en-US":`Pre-uploaded file ID(s) (repeatable)`,"zh-CN":`已上传的文件 ID(可重复)`}},sessionId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Session ID for multi-turn conversation`,"zh-CN":`多轮对话的 Session ID`}},stream:{type:`switch`,description:{"en-US":`Stream response (default: on in TTY)`,"zh-CN":`流式输出响应(TTY 中默认开启)`}},pipelineIds:{type:`string`,valueHint:`<ids>`,description:{"en-US":`Knowledge base pipeline IDs (comma-separated)`,"zh-CN":`知识库 Pipeline ID(以逗号分隔)`}},memoryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory ID for long-term memory`,"zh-CN":`长期记忆使用的 Memory ID`}},bizParams:{type:`string`,valueHint:`<json>`,description:{"en-US":`Business parameters JSON (workflow variables)`,"zh-CN":`业务参数 JSON(工作流变量)`}},hasThoughts:{type:`switch`,description:{"en-US":`Show agent thinking process`,"zh-CN":`显示智能体思考过程`}}},exampleArgs:[{"en-US":`--app-id abc123 --prompt "Hello"`,"zh-CN":`--app-id abc123 --prompt "你好"`},{"en-US":`--app-id abc123 --prompt "Describe this image" --image https://example.com/photo.jpg`,"zh-CN":`--app-id abc123 --prompt "描述这张图片" --image https://example.com/photo.jpg`},{"en-US":`--app-id abc123 --prompt "Analyze the image" --image img1.jpg --image img2.jpg`,"zh-CN":`--app-id abc123 --prompt "分析这些图片" --image img1.jpg --image img2.jpg`},{"en-US":`--app-id abc123 --prompt "Continue" --session-id sess_xxx --stream`,"zh-CN":`--app-id abc123 --prompt "继续" --session-id sess_xxx --stream`},{"en-US":`--app-id abc123 --prompt "Search for materials" --pipeline-ids pipe1,pipe2`,"zh-CN":`--app-id abc123 --prompt "搜索资料" --pipeline-ids pipe1,pipe2`},{"en-US":`--app-id abc123 --prompt "Start" --biz-params '{"key":"value"}'`,"zh-CN":`--app-id abc123 --prompt "开始" --biz-params '{"key":"value"}'`}],async run(e){let{settings:t,flags:n}=e,r=n.appId,i=n.prompt,a=n.stream||process.stdout.isTTY,o=T(t.output),s={input:{prompt:i},parameters:{incremental_output:a}};n.sessionId&&(s.input.session_id=n.sessionId);let c=n.image;c&&c.length>0&&(s.input.image_list=c);let l=n.fileId;if(l&&l.length>0&&(s.input.file_ids=l),n.hasThoughts&&(s.parameters.has_thoughts=!0),n.pipelineIds){let e=n.pipelineIds.split(`,`).map(e=>e.trim()).filter(Boolean);s.parameters.rag_options={pipeline_ids:e}}if(n.memoryId&&(s.parameters.memory_id=n.memoryId),n.bizParams)try{s.input.biz_params=JSON.parse(n.bizParams)}catch{throw new C(`--biz-params must be valid JSON`)}if(t.dryRun){A({endpoint:e.client.url(se(r)),request:s},o);return}if(a){let i=await e.client.request({path:se(r),method:`POST`,body:s,headers:{"X-DashScope-SSE":`enable`},stream:!0}),a=``,c=``,l=o===`text`,u=O(process.stderr);for await(let e of mn(i)){if(e.data===`[DONE]`)break;try{let t=JSON.parse(e.data),r=t.output?.text;if(r&&(l&&process.stdout.write(r),a+=r),t.output?.session_id&&(c=t.output.session_id),t.output?.thoughts&&n.hasThoughts)for(let e of t.output.thoughts)e.thought&&process.stderr.write(`${u.dim(`[Thinking] ${e.thought}`)}\n`),e.action_name&&process.stderr.write(`${u.dim(`[Action] ${e.action_name}: ${e.action_input||``}`)}\n`),e.observation&&process.stderr.write(`${u.dim(`[Observation] ${e.observation}`)}\n`)}catch{}}c&&!t.quiet&&process.stderr.write(`${u.dim(`Session ID: ${c}`)}\n`),o===`json`?A({text:a,session_id:c},o):process.stdout.write(`
|
|
2736
2733
|
`)}else{let n=await e.client.requestJson({path:se(r),method:`POST`,body:s}),i=n.output?.text??``;t.quiet||o===`text`?k(i):A(n,o)}}});const Md=`zeldaEasy.broadscope-bailian.app-control.list`;var Nd=w({description:{"en-US":`List Bailian applications`,"zh-CN":`列出百炼应用`},auth:`console`,usageArgs:`[flags]`,flags:{name:{type:`string`,valueHint:`<name>`,description:{"en-US":`Filter by app name (keyword search)`,"zh-CN":`按应用名称筛选(关键词搜索)`}},page:{type:`number`,valueHint:`<n>`,description:{"en-US":`Page number (default: 1)`,"zh-CN":`页码(默认:1)`}},pageSize:{type:`number`,valueHint:`<n>`,description:{"en-US":`Results per page (default: 30)`,"zh-CN":`每页结果数(默认:30)`}}},exampleArgs:[``,{"en-US":`--name customer service`,"zh-CN":`--name 客户服务`},`--page 2 --page-size 10`,`--output json`],async run(e){let{settings:t,flags:n}=e,r=n.name||``,i=n.page||1,a=n.pageSize||30,o=T(t.output),s={reqDTO:{name:r,notInTypes:[10],type:5,statuses:[1,4],page_no:i,page_size:a}};if(t.dryRun){A({api:Md,data:s},o);return}let c=await e.client.console(Md,s),l=c?.data?.DataV2?.data?.data?.list??[],u=c?.data?.DataV2?.data?.data?.total??0,d=l.map(e=>({code:e.code,name:e.name,user_prompt_params:e.config?.user_prompt_params??[]}));A({total:u,apps:d},o)}}),Pd=w({description:{"en-US":`Add memory from messages or custom content`,"zh-CN":`从消息或自定义内容添加记忆`},auth:`apiKey`,usageArgs:`--user-id <id> [--messages <json>] [--content <text>] [flags]`,flags:{userId:{type:`string`,valueHint:`<id>`,description:{"en-US":`User ID (required)`,"zh-CN":`用户 ID(必填)`},required:!0},messages:{type:`string`,valueHint:`<json>`,description:{"en-US":`Messages JSON array: [{"role":"user","content":"..."},...]`,"zh-CN":`消息 JSON 数组:[{"role":"user","content":"..."},...]`}},content:{type:`string`,valueHint:`<text>`,description:{"en-US":`Custom content text to memorize`,"zh-CN":`要记忆的自定义内容文本`}},profileSchema:{type:`string`,valueHint:`<id>`,description:{"en-US":`Profile schema ID for user profiling`,"zh-CN":`用于用户画像的 Profile Schema ID`}},memoryLibraryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory library ID (isolate memory space)`,"zh-CN":`记忆库 ID(用于隔离记忆空间)`}}},exampleArgs:[{"en-US":`--user-id user1 --content "The user likes Python programming"`,"zh-CN":`--user-id user1 --content "用户喜欢使用 Python 编程"`},{"en-US":`--user-id user1 --messages '[{"role":"user","content":"I like traveling"}]'`,"zh-CN":`--user-id user1 --messages '[{"role":"user","content":"我喜欢旅行"}]'`},{"en-US":`--user-id user1 --content "Lives in Beijing" --profile-schema schema_xxx`,"zh-CN":`--user-id user1 --content "居住在北京" --profile-schema schema_xxx`}],validate:e=>!e.messages&&!e.content?`Provide --messages or --content.`:void 0,async run(e){let{settings:t,flags:n}=e,r={user_id:n.userId};if(n.messages)try{r.messages=JSON.parse(n.messages)}catch{throw new C(`--messages must be valid JSON array`)}n.content&&(r.custom_content=n.content),n.profileSchema&&(r.profile_schema=n.profileSchema),n.memoryLibraryId&&(r.memory_library_id=n.memoryLibraryId);let i=T(t.output);if(t.dryRun){A({endpoint:e.client.url(tn()),request:r},i);return}let a=await e.client.requestJson({path:tn(),method:`POST`,body:r});if(t.quiet||i===`text`){let e=a.memory_ids?.join(`, `)||`none`;k(`Memory added. IDs: ${e}`)}else A(a,i)}}),Fd=w({description:{"en-US":`Search memory nodes by query or messages`,"zh-CN":`通过查询文本或消息搜索记忆节点`},auth:`apiKey`,usageArgs:`--user-id <id> [--query <text>] [flags]`,flags:{userId:{type:`string`,valueHint:`<id>`,description:{"en-US":`User ID (required)`,"zh-CN":`用户 ID(必填)`},required:!0},query:{type:`string`,valueHint:`<text>`,description:{"en-US":`Search query text`,"zh-CN":`搜索查询文本`}},messages:{type:`string`,valueHint:`<json>`,description:{"en-US":`Messages JSON array for context-based search`,"zh-CN":`用于上下文搜索的消息 JSON 数组`}},topK:{type:`number`,valueHint:`<n>`,description:{"en-US":`Number of results to return (default: 10)`,"zh-CN":`返回结果数量(默认:10)`}},memoryLibraryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory library ID`,"zh-CN":`记忆库 ID`}}},exampleArgs:[{"en-US":`--user-id user1 --query "programming preferences"`,"zh-CN":`--user-id user1 --query "编程偏好"`},{"en-US":`--user-id user1 --messages '[{"role":"user","content":"recommend a book"}]' --top-k 5`,"zh-CN":`--user-id user1 --messages '[{"role":"user","content":"推荐一本书"}]' --top-k 5`}],validate:e=>!e.query&&!e.messages?`Provide --query or --messages.`:void 0,async run(e){let{settings:t,flags:n}=e,r={user_id:n.userId};if(n.query&&(r.query=n.query),n.messages)try{r.messages=JSON.parse(n.messages)}catch{throw new C(`--messages must be valid JSON array`)}!r.messages&&r.query&&(r.messages=[{role:`user`,content:r.query}]),n.topK!==void 0&&(r.top_k=n.topK),n.memoryLibraryId&&(r.memory_library_id=n.memoryLibraryId);let i=T(t.output);if(t.dryRun){A({endpoint:e.client.url(an()),request:r},i);return}let a=await e.client.requestJson({path:an(),method:`POST`,body:r});if(t.quiet||i===`text`){if(!a.memory_nodes||a.memory_nodes.length===0)k(`No memory nodes found.`);else for(let e of a.memory_nodes)k(`[${e.memory_node_id}] ${e.content}`)}else A(a,i)}}),Id=w({description:{"en-US":`List memory nodes for a user`,"zh-CN":`列出用户的记忆节点`},auth:`apiKey`,usageArgs:`--user-id <id> [flags]`,flags:{userId:{type:`string`,valueHint:`<id>`,description:{"en-US":`User ID (required)`,"zh-CN":`用户 ID(必填)`},required:!0},pageSize:{type:`number`,valueHint:`<n>`,description:{"en-US":`Results per page (default: 10)`,"zh-CN":`每页结果数(默认:10)`}},page:{type:`number`,valueHint:`<n>`,description:{"en-US":`Page number (default: 1)`,"zh-CN":`页码(默认:1)`}},memoryLibraryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory library ID`,"zh-CN":`记忆库 ID`}}},exampleArgs:[`--user-id user1`,`--user-id user1 --page-size 20 --page 2`],async run(e){let{settings:t,flags:n}=e,r=n.userId,i=T(t.output),a=new URLSearchParams;a.set(`user_id`,r),n.pageSize!==void 0&&a.set(`page_size`,String(n.pageSize)),n.page!==void 0&&a.set(`page_num`,String(n.page)),n.memoryLibraryId&&a.set(`memory_library_id`,n.memoryLibraryId);let o=`${nn()}?${a.toString()}`;if(t.dryRun){A({endpoint:e.client.url(o),method:`GET`},i);return}let s=await e.client.requestJson({path:o,method:`GET`});if(t.quiet||i===`text`){if(!s.memory_nodes||s.memory_nodes.length===0)k(`No memory nodes found.`);else{for(let e of s.memory_nodes)k(`[${e.memory_node_id}] ${e.content}`);s.total!==void 0&&k(`\nTotal: ${s.total}`)}}else A(s,i)}}),Ld=w({description:{"en-US":`Update a memory node content`,"zh-CN":`更新记忆节点内容`},auth:`apiKey`,usageArgs:`--node-id <id> --user-id <id> --content <text>`,flags:{nodeId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory node ID (required)`,"zh-CN":`记忆节点 ID(必填)`},required:!0},userId:{type:`string`,valueHint:`<id>`,description:{"en-US":`User ID (required)`,"zh-CN":`用户 ID(必填)`},required:!0},content:{type:`string`,valueHint:`<text>`,description:{"en-US":`New content for the memory node (required)`,"zh-CN":`记忆节点的新内容(必填)`},required:!0},memoryLibraryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory library ID (non-default library)`,"zh-CN":`记忆库 ID(非默认记忆库)`}}},exampleArgs:[{"en-US":`--node-id node_xxx --user-id user1 --content "updated memory content"`,"zh-CN":`--node-id node_xxx --user-id user1 --content "更新后的记忆内容"`}],async run(e){let{settings:t,flags:n}=e,r=n.nodeId,i={user_id:n.userId,custom_content:n.content};n.memoryLibraryId&&(i.memory_library_id=n.memoryLibraryId);let a=T(t.output);if(t.dryRun){A({endpoint:e.client.url(rn(r)),method:`PATCH`,request:i},a);return}let o=await e.client.requestJson({path:rn(r),method:`PATCH`,body:i});t.quiet||a===`text`?k(`Memory node ${r} updated.`):A(o,a)}}),Rd=w({description:{"en-US":`Delete a memory node`,"zh-CN":`删除记忆节点`},auth:`apiKey`,usageArgs:`--node-id <id> --user-id <id>`,flags:{nodeId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory node ID (required)`,"zh-CN":`记忆节点 ID(必填)`},required:!0},userId:{type:`string`,valueHint:`<id>`,description:{"en-US":`User ID (required)`,"zh-CN":`用户 ID(必填)`},required:!0},memoryLibraryId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Memory library ID (non-default library)`,"zh-CN":`记忆库 ID(非默认记忆库)`}}},exampleArgs:[`--node-id node_xxx --user-id user1`],async run(e){let{settings:t,flags:n}=e,r=n.nodeId,i=n.userId,a=T(t.output),o=new URLSearchParams({user_id:i});n.memoryLibraryId&&o.set(`memory_library_id`,n.memoryLibraryId);let s=`${rn(r)}?${o.toString()}`;if(t.dryRun){A({endpoint:e.client.url(s),method:`DELETE`},a);return}let c=await e.client.requestJson({path:s,method:`DELETE`});t.quiet||a===`text`?k(`Memory node ${r} deleted.`):A(c,a)}}),zd=w({description:{"en-US":`Create a user profile schema for memory profiling`,"zh-CN":`创建用于记忆画像的用户 Profile Schema`},auth:`apiKey`,usageArgs:`--name <name> --attributes <json> [flags]`,flags:{name:{type:`string`,valueHint:`<name>`,description:{"en-US":`Schema name (required)`,"zh-CN":`Schema 名称(必填)`},required:!0},description:{type:`string`,valueHint:`<text>`,description:{"en-US":`Schema description`,"zh-CN":`Schema 描述`}},attributes:{type:`string`,valueHint:`<json>`,description:{"en-US":`Attributes JSON array: [{"name":"age","description":"age"}]`,"zh-CN":`属性 JSON 数组:[{"name":"age","description":"age"}]`},required:!0}},exampleArgs:[{"en-US":`--name "user_basic" --attributes '[{"name":"age","description":"age"},{"name":"hobby","description":"hobby"}]'`,"zh-CN":`--name "user_basic" --attributes '[{"name":"age","description":"年龄"},{"name":"hobby","description":"爱好"}]'`}],async run(e){let{settings:t,flags:n}=e,r=n.name,i=n.attributes,a;try{a=JSON.parse(i)}catch{throw new C(`--attributes must be valid JSON array`)}let o={name:r,attributes:a};n.description&&(o.description=n.description);let s=T(t.output);if(t.dryRun){A({endpoint:e.client.url(bn()),request:o},s);return}let c=await e.client.requestJson({path:bn(),method:`POST`,body:o});t.quiet||s===`text`?k(`Profile schema created: ${c.profile_schema_id}`):A(c,s)}}),Bd=w({description:{"en-US":`Get user profile by schema ID and user ID`,"zh-CN":`通过 Schema ID 和用户 ID 获取用户画像`},auth:`apiKey`,usageArgs:`--schema-id <id> --user-id <id>`,flags:{schemaId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Profile schema ID (required)`,"zh-CN":`Profile Schema ID(必填)`},required:!0},userId:{type:`string`,valueHint:`<id>`,description:{"en-US":`User ID (required)`,"zh-CN":`用户 ID(必填)`},required:!0}},exampleArgs:[`--schema-id schema_xxx --user-id user1`],async run(e){let{settings:t,flags:n}=e,r=n.schemaId,i=n.userId,a=T(t.output),o=new URLSearchParams({user_id:i}),s=`${mr(r)}?${o.toString()}`;if(t.dryRun){A({endpoint:e.client.url(s),method:`GET`},a);return}let c=await e.client.requestJson({path:s,method:`GET`});if(t.quiet||a===`text`){if(c.profile?.attributes)for(let e of c.profile.attributes)k(`${e.name}: ${e.value??`(empty)`}`);else k(`No profile data found.`)}else A(c,a)}}),Vd=w({description:{"en-US":"Retrieve from a Bailian knowledge base (deprecated, use `search` instead)","zh-CN":"从百炼知识库检索(已废弃,请改用 `search`)"},auth:`apiKey`,usageArgs:`--index-id <id> --query <text> [flags]`,flags:{indexId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Knowledge base index ID (required)`,"zh-CN":`知识库索引 ID(必填)`},required:!0},query:{type:`string`,valueHint:`<text>`,description:{"en-US":`Search query (required)`,"zh-CN":`搜索查询(必填)`},required:!0},denseSimilarityTopK:{type:`number`,valueHint:`<n>`,description:{"en-US":`Dense retrieval top K`,"zh-CN":`稠密检索 Top K`}},sparseSimilarityTopK:{type:`number`,valueHint:`<n>`,description:{"en-US":`Sparse retrieval top K`,"zh-CN":`稀疏检索 Top K`}},rerank:{type:`switch`,description:{"en-US":`Enable reranking`,"zh-CN":`启用重排序`}},rerankTopN:{type:`number`,valueHint:`<n>`,description:{"en-US":`Rerank top N results`,"zh-CN":`重排序前 N 个结果`}},rerankModel:{type:`string`,valueHint:`<name>`,description:{"en-US":`Rerank model, e.g. qwen3-rerank-hybrid`,"zh-CN":`重排序模型,例如 qwen3-rerank-hybrid`}},rerankMode:{type:`string`,valueHint:`<mode>`,description:{"en-US":`Rerank mode: qa, similar, or custom`,"zh-CN":`重排序模式:qa、similar 或 custom`}},rerankInstruct:{type:`string`,valueHint:`<text>`,description:{"en-US":`Custom rerank instruction, when mode=custom`,"zh-CN":`自定义重排序指令,仅在 mode=custom 时使用`}},topK:{type:`number`,valueHint:`<n>`,description:{"en-US":`Number of results (deprecated, use --rerank-top-n)`,"zh-CN":`结果数量(已废弃,请使用 --rerank-top-n)`}}},notes:[{"en-US":`--rerank-model requires the target knowledge base to already have a rerank model configured; otherwise every value is rejected.`,"zh-CN":`--rerank-model 要求目标知识库已配置重排序模型,否则任何取值都会被拒绝。`}],exampleArgs:[{"en-US":`--index-id idx_xxx --query "How to use Alibaba Cloud Bailian"`,"zh-CN":`--index-id idx_xxx --query "如何使用阿里云百炼"`},{"en-US":`--index-id idx_xxx --query "RAG retrieval" --rerank --rerank-model qwen3-rerank-hybrid`,"zh-CN":`--index-id idx_xxx --query "RAG 检索" --rerank --rerank-model qwen3-rerank-hybrid`}],async run(e){let{settings:t,flags:n}=e,r=T(t.output);n.topK!==void 0&&n.rerankTopN===void 0&&(process.stderr.write(`Warning: --top-k is deprecated. Use --rerank-top-n instead.
|
|
2737
2734
|
`),n.rerankTopN=n.topK);let i={index_id:n.indexId,query:n.query,search_filters:[]};if(n.denseSimilarityTopK!==void 0&&(i.dense_similarity_top_k=n.denseSimilarityTopK),n.sparseSimilarityTopK!==void 0&&(i.sparse_similarity_top_k=n.sparseSimilarityTopK),n.rerank&&(i.enable_reranking=!0),n.rerankTopN!==void 0&&(i.rerank_top_n=n.rerankTopN),n.rerankModel){let e={model_name:n.rerankModel};n.rerankMode&&(e.rerank_mode=n.rerankMode),n.rerankInstruct&&(e.rerank_instruct=n.rerankInstruct),i.rerank=[e]}if(t.dryRun){A({endpoint:e.client.url(It()),request:i},r);return}let a=await e.client.requestJson({path:It(),method:`POST`,body:i}),o=a.data?.nodes||[];t.quiet||r===`text`?Hd(o.map(e=>({text:e.text,score:e.score}))):A(a,r)}});function Hd(e){if(e.length===0)k(`No results found.`);else for(let t=0;t<e.length;t++){let n=e[t];k(`[${t+1}] (score: ${n.score.toFixed(4)})`),k(n.text),k(``)}}const z={workspaceId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Workspace ID for API endpoint URL (or set BAILIAN_WORKSPACE_ID)`,"zh-CN":`API Endpoint URL 使用的 Workspace ID(也可设置 BAILIAN_WORKSPACE_ID)`}}},Ud={pageNumber:{type:`number`,valueHint:`<n>`,description:{"en-US":`Page number (default: 1)`,"zh-CN":`页码(默认:1)`}},pageSize:{type:`number`,valueHint:`<n>`,description:{"en-US":`Page size per request`,"zh-CN":`每次请求的分页大小`}}};function B(e){let t=e.flags.workspaceId||e.settings.workspaceId;if(!t)throw new n(`Workspace ID is required.`,f.USAGE,`Pass --workspace-id, set BAILIAN_WORKSPACE_ID env, or configure: ${e.identity.binName} config set workspace_id <id>`);return t}function Wd(e){if(!process.stdout.isTTY)return e;let t=process.stdout.columns??120;return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function Gd(e){return e.data?.ingestion_status??`UNKNOWN`}function Kd(e){return(e.data?.rows??[]).filter(e=>[e.code,e.status].some(e=>typeof e==`string`&&e.includes(`FAILED`)))}function qd(e){let t=e.data?.rows??[];if(t.length===0)return!1;let n=e.data?.total_count;return typeof n==`number`&&t.length<n?!1:t.every(e=>{let t=e.code??e.status??``;return t===`FINISH`||t.includes(`FAILED`)})}function Jd(e,t){let n=e.data?.rows??[],r=Kd(e),i=new Set(r.map(e=>e.doc_id)),a=n.filter(e=>!i.has(e.doc_id)),o=r.map(e=>`${e.doc_name??e.doc_id??`?`}: ${e.message??e.code??`unknown`}`).join(`; `),s=a.map(e=>e.doc_name??e.doc_id??`?`).join(`, `),c=[];return o&&c.push(`failed: ${o}`),s&&c.push(`succeeded: ${s}`),c.length>0?`${t} (${c.join(`; `)})`:t}function Yd(e,t,n){let r=new URL(D(e,y.indexJobStatus));return r.searchParams.set(`index_id`,t),r.searchParams.set(`job_id`,n),r}async function Xd(e,t,n){return Kr(e,t,{url:n.statusUrl,intervalSec:n.intervalSec,timeoutSec:t.timeout,isComplete:e=>{let t=e;return Gd(t)===`COMPLETED`||qd(t)},isFailed:()=>!1,getStatus:e=>{let t=e,n=Gd(t),r=Kd(t).length,i=t.data?.total_count;return typeof i==`number`&&i>0?`${n} (${r}/${i} failed)`:r>0?`${n} (${r} failed)`:n}})}function Zd(e,t){return!(e instanceof n)||e.hint?e:new n(e.message,e.exitCode,t,{cause:e,api:e.api,rawResponse:e.rawResponse})}function Qd(e,t){let n=e.data?.[t];if(typeof n==`string`)return n;let r=e[t];return typeof r==`string`?r:void 0}const $d={query:{type:`string`,valueHint:`<text>`,description:{"en-US":`Search query text (required, cannot be empty)`,"zh-CN":`搜索查询文本(必填且不能为空)`},required:!0},agentId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Retrieval service ID (find in console knowledge retrieval page)`,"zh-CN":`检索服务 ID(可在控制台知识库检索页面查看)`},required:!0},...z,agentVersion:{type:`string`,valueHint:`<version>`,description:{"en-US":`Service version to call: beta (draft for debugging) or a published number; default is the latest published version`,"zh-CN":`要调用的服务版本:beta(用于调试的草稿)或已发布版本号;默认使用最新发布版本`}},image:{type:`array`,valueHint:`<url>`,description:{"en-US":`Image URL for multimodal retrieval (repeatable)`,"zh-CN":`多模态检索使用的图片 URL(可重复)`}}};var ef=w({description:{"en-US":`Search a Bailian knowledge base (RAG semantic retrieval)`,"zh-CN":`搜索百炼知识库(RAG 语义检索)`},auth:`apiKey`,usageArgs:`--query <text> --agent-id <id> [flags]`,flags:$d,notes:[{"en-US":`Retrieval scope and strategy (multi-index weighting, routing, reranking, etc.) are driven by the agent_id service config. Only query and agent_id are required.`,"zh-CN":`检索范围与策略(多索引权重、路由、重排序等)由 agent_id 服务配置决定。仅 query 和 agent_id 必填。`},{"en-US":`Auth: uses DashScope API Key (Bearer token). Get yours from the console API Key page.`,"zh-CN":`鉴权:使用 DashScope API Key(Bearer Token)。可在控制台 API Key 页面获取。`},{"en-US":"`--workspace-id` can be set via BAILIAN_WORKSPACE_ID env or `kscli config set workspace_id <id>`.","zh-CN":"`--workspace-id` 可通过 BAILIAN_WORKSPACE_ID 环境变量或 `kscli config set workspace_id <id>` 设置。"},{"en-US":"`--agent-version beta` calls the draft config for debugging before it is deployed.","zh-CN":"`--agent-version beta` 会调用尚未部署的草稿配置,便于发布前调试。"}],exampleArgs:[{"en-US":`--query "What is RAG?" --agent-id aid-xxx --workspace-id ws-xxx`,"zh-CN":`--query "什么是 RAG?" --agent-id aid-xxx --workspace-id ws-xxx`},{"en-US":`--api-key $DASHSCOPE_API_KEY --query "test search" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg`,"zh-CN":`--api-key $DASHSCOPE_API_KEY --query "测试搜索" --agent-id aid-xxx --workspace-id ws-xxx --image https://example.com/img.jpg`}],async run(e){let{settings:t,flags:n}=e,r=B(e),i=T(t.output),a={query:n.query,agent_id:n.agentId};n.agentVersion&&(a.agent_version=n.agentVersion),n.image&&n.image.length>0&&(a.images=n.image);let o=Lt(r);if(t.dryRun){A({endpoint:o,request:a},i);return}let s=await e.client.requestJson({path:o,method:`POST`,body:a}),c=s.data?.nodes||[];if(t.quiet||i===`text`){if(c.length===0)k(`No results found.`);else for(let e=0;e<c.length;e++){let t=c[e];k(`[${e+1}] (score: ${t.score.toFixed(4)})`),k(t.text),k(``)}}else A(s,i)}});const tf={message:{type:`array`,valueHint:`<text>`,description:{"en-US":`Message text (repeatable). Supports role:content prefix to set role (e.g. user:hello), defaults to user. Follows OpenAI message format`,"zh-CN":`消息文本(可重复)。支持使用 role:content 前缀指定角色(例如 user:hello),默认为 user。遵循 OpenAI 消息格式`}},agentId:{type:`string`,valueHint:`<id>`,description:{"en-US":`Q&A service ID (find in console knowledge Q&A page)`,"zh-CN":`问答服务 ID(可在控制台知识库问答页面查看)`},required:!0},...z,agentVersion:{type:`string`,valueHint:`<version>`,description:{"en-US":`Service version to call: beta (draft for debugging) or a published number; default is the latest published version`,"zh-CN":`要调用的服务版本:beta(用于调试的草稿)或已发布版本号;默认使用最新发布版本`}},image:{type:`array`,valueHint:`<url>`,description:{"en-US":`Image URL (repeatable). Attached to the last user message as multimodal content`,"zh-CN":`图片 URL(可重复)。将作为多模态内容附加到最后一条用户消息`}}};function nf(e){let t=[];if(e.message){let n=/* @__PURE__ */ new Set([`user`,`assistant`]);for(let r of e.message){if(r.startsWith(`{`))try{let e=JSON.parse(r);if(e.role&&n.has(e.role)&&e.content!==void 0){t.push(e);continue}}catch{}let e=r.indexOf(`:`),i=e===-1?``:r.slice(0,e);n.has(i)?t.push({role:i,content:r.slice(e+1)}):t.push({role:`user`,content:r})}}return t}function rf(e){for(let t of e)if(Array.isArray(t.content)&&t.content.some(e=>e.type===`image_url`))return!0;return!1}function af(e,t){let n=-1;for(let t=e.length-1;t>=0;t--)if(e[t].role===`user`){n=t;break}n===-1&&(e.push({role:`user`,content:``}),n=e.length-1);let r=e[n],i=[];typeof r.content==`string`?i.push({type:`text`,text:r.content}):i.push(...r.content);for(let e of t)i.push({type:`image_url`,image_url:{url:e}});r.content=i}const of={tool_calling:`🔍 Retrieving...`,plan_start:`🤔 Planning...`,generation_start:`✍️ Generating...`};var sf=w({description:{"en-US":`Chat with a Bailian knowledge base (RAG Q&A with streaming)`,"zh-CN":`与百炼知识库对话(支持流式输出的 RAG 问答)`},auth:`apiKey`,usageArgs:`--message <text> --agent-id <id> [flags]`,flags:tf,notes:[{"en-US":`Response is returned as SSE stream events. Event lifecycle: tool_calling → tool_return → plan_start → planning → plan_end → generation_start → generating → generation_end. tool_calling → tool_return may loop multiple times.`,"zh-CN":`响应以 SSE 流事件返回。事件生命周期:tool_calling → tool_return → plan_start → planning → plan_end → generation_start → generating → generation_end。tool_calling → tool_return 可能循环多次。`},{"en-US":`Auth: uses DashScope API Key (Bearer token). Get yours from the console API Key page.`,"zh-CN":`鉴权:使用 DashScope API Key(Bearer Token)。可在控制台 API Key 页面获取。`},{"en-US":"`--workspace-id` can be set via BAILIAN_WORKSPACE_ID env or `kscli config set workspace_id <id>`.","zh-CN":"`--workspace-id` 可通过 BAILIAN_WORKSPACE_ID 环境变量或 `kscli config set workspace_id <id>` 设置。"},{"en-US":`Multi-turn: use --message "user:..." and --message "assistant:..." to pass conversation history.`,"zh-CN":`多轮对话:使用 --message "user:..." 和 --message "assistant:..." 传入对话历史。`},{"en-US":"`--agent-version beta` calls the draft config for debugging before it is deployed.","zh-CN":"`--agent-version beta` 会调用尚未部署的草稿配置,便于发布前调试。"}],exampleArgs:[{"en-US":`--message "What is RAG?" --agent-id aid-xxx --workspace-id ws-xxx`,"zh-CN":`--message "什么是 RAG?" --agent-id aid-xxx --workspace-id ws-xxx`},{"en-US":`--message "user:What is RAG?" --message "assistant:RAG is..." --message "How does it work?" --agent-id aid-xxx --workspace-id ws-xxx`,"zh-CN":`--message "user:什么是 RAG?" --message "assistant:RAG 是……" --message "它是如何工作的?" --agent-id aid-xxx --workspace-id ws-xxx`},{"en-US":`--message "Describe these images" --image https://example.com/a.png --image https://example.com/b.png --agent-id aid-xxx --workspace-id ws-xxx`,"zh-CN":`--message "描述这些图片" --image https://example.com/a.png --image https://example.com/b.png --agent-id aid-xxx --workspace-id ws-xxx`}],validate:e=>e.message&&e.message.length>0||e.image&&e.image.length>0?void 0:`Provide --message (or --image for a pure image query).`,async run(e){let{settings:t,flags:r}=e,i=nf(r),a=r.image,o=!!a&&a.length>0;i.length===0&&o&&(i=[{role:`user`,content:``}]);let s=B(e),c=T(t.output),l=c===`text`&&!!process.stdout.isTTY;if(o){if(rf(i))throw new n(`Cannot use --image when messages already contain embedded image_url content parts. Use one approach or the other.`,f.USAGE);af(i,a)}let u={input:{messages:i},parameters:{agent_options:{agent_id:r.agentId,...r.agentVersion?{agent_version:r.agentVersion}:{}}},stream:!0},d=Ft(s);if(t.dryRun){A({endpoint:d,request:u},c);return}let p=await e.client.request({path:d,method:`POST`,body:u,stream:!0});if(l){let e=O(process.stdout),r=t.verbose;for await(let t of mn(p)){if(t.data===`[DONE]`)break;if(t.event===`error`){let e=`Chat API error`,r;try{let n=JSON.parse(t.data);e=n.message||e,r=n.code}catch{}throw new n(e,f.GENERAL,r?`API error: ${r}`:void 0)}try{let n=JSON.parse(t.data);for(let t of n.output?.choices??[]){let n=t.message;if(n.extra?.step_change){let t=of[n.extra.step_change];t&&process.stdout.write(`${e.dim(t)}\n`)}if(r&&n.extra?.step_change&&process.stderr.write(O(process.stderr).dim(`[event] step_change=${n.extra.step_change} step=${n.extra?.step??``} group=${n.extra?.group??``}`)+`
|
|
2738
2735
|
`),n.content&&process.stdout.write(n.content),t.finish_reason===`stop`)break}}catch{}}process.stdout.write(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bailian-cli-commands",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Command library for bailian-cli products (knowledge, memory, media, …). See https://www.npmjs.com/package/bailian-cli for usage.",
|
|
5
5
|
"homepage": "https://bailian.console.aliyun.com/cli",
|
|
6
6
|
"bugs": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"chalk": "^5.6.2",
|
|
33
33
|
"smol-toml": "^1.4.2",
|
|
34
34
|
"yaml": "^2.8.3",
|
|
35
|
-
"bailian-cli-core": "2.3.
|
|
36
|
-
"bailian-cli-runtime": "2.3.
|
|
35
|
+
"bailian-cli-core": "2.3.2",
|
|
36
|
+
"bailian-cli-runtime": "2.3.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^24",
|