You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When logging in with --open-api, call the GenerateCLIAccessToken API
using the provided AK/SK to obtain an access token and persist it
alongside the credentials in config.json.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…otLogined
Move the GenerateCLIAccessToken API call logic into core/auth/refresh-token.ts
so it can be reused across packages. Add refreshAccessToken() which reads
AK/SK from config, calls the API, and persists the new access_token.
Client.console() now catches NotLogined errors and automatically retries
with a refreshed token when AK/SK are available in config.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- add the built-in Token Plan profile preset
- validate and persist model API keys atomically
- materialize the default Base URL and models on login
- preserve flag > env > config precedence
- persist the active profile in config.json
- resolve config with --config > active_config > default
- add config list and config use commands
- make auth and config writes target the selected profile
- reset activation to default when deleting the active profile
- update config UI with profile activation controls
- keep token refresh and pipeline execution profile-aware
- add loader, UI, auth, and CLI interaction coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
在此之前,控制台域(console)鉴权只能靠浏览器登录拿到
access_token,token 过期后命令会直接报NotLogined,需要用户手动重新登录;OpenAPI AK/SK 只能签名调用模型接口,无法换取控制台 token;同一台机器也只能维护一套凭证。本 PR 打通「AK/SK → 控制台 token」链路,补齐开通流程自动化、多套凭证隔离,并提供可视化管理配置的本地 WebUI。同时合并了最新main(含feat/recommend-new,移除了 intent-detect-v3 独立 base URL 机制)。新增功能
1. CLI Access Token 生成与自动刷新(核心)
generateCLIAccessToken():调用 ModelStudio OpenAPIGenerateCLIAccessToken,按 baseUrl 自动选 cn/intl 区域 host。bl auth generate-access-token:用--access-key-id/--access-key-secret(必填)+--security-token(可选)换取cliAccessToken。bl auth login --open-api增强:保存 AK/SK 的同时自动换取access_token一并落盘,登录一步到位。Client.console()捕获NotLogined后用本地 AK/SK 静默刷新 token 并重试一次;无 AK/SK 时按原错误抛出。2.
bl bootstrap—— 一键初始化工作空间并开通后付费服务串联 6 步控制台流程:检查登录/工作空间状态 → 初始化工作空间 → 创建控制台账号用户 → 轮询下单结果 → 查询商品激活状态 → 对未开通商品发起后付费开通并轮询至激活(超时抛
TIMEOUT)。支持--dry-run只打印计划、auth: "console"复用鉴权域 flag。3. 多命名配置
--config <name>在同一个
~/.bailian/config.json内维护多套互相隔离的凭证 profile:默认配置写顶层字段,命名配置写独立 block,读写互不干扰;normalizeConfigName()校验命名;auth login/logout/status、config set/show全部按当前--config作用域读写并标注config/config_file。4. STS Security Token 支持
新增
--security-tokenflag、ALIBABA_CLOUD_SECURITY_TOKEN环境变量、config 字段security_token;解析优先级 flag → env → config;签名注入x-acs-security-token头。5. 可观测性与错误透传增强
console gateway
--verbose打印结构化请求/响应;BailianError新增rawResponse字段,把原始响应与可读 message 分离;国内站 gateway 增加switchUserType: 3。6.
bl config ui—— 可视化管理配置的本地 WebUI(新增)启动绑定
127.0.0.1的本地 HTTP server + 内嵌单页 HTML(原生 JS,无新依赖、无构建步骤),可视化查看/新建/切换/删除全部命名 profile 并编辑其键值与凭证。readConfigProfiles()(分离 default 与各命名 profile)、deleteConfigProfile(name)。node:http+127.0.0.1随机端口 +openInBrowser模式(抽到commands/shared/local-server.ts共用);抽出commands/config/shared.ts统一config set与 WebUI 的键校验。?token=(不匹配 401)与Host头为 loopback(防 DNS rebinding,否则 403)。--port <port>(默认随机空闲端口)、--no-open(不自动开浏览器)、--dry-run(只打印计划);--config <name>决定 UI 初始聚焦的 profile。验证方法
自动化(无需真实凭证)
关键用例:
packages/commands/tests/bootstrap.test.ts、packages/commands/tests/config-ui.test.ts(server 集成:401/403 鉴权、GET/POST/DELETE、timeout 强转、空串清除、明文往返)、packages/cli/tests/e2e/config-profile.e2e.test.ts、packages/commands/tests/e2e/config.e2e.test.ts(含config ui --dry-run)、packages/core/tests/config-store.test.ts(含readConfigProfiles/deleteConfigProfile)。手工(需真实 AK/SK 或控制台账号,建议加
--config test隔离)bl auth generate-access-token --access-key-id <AK> --access-key-secret <SK>→ 输出含cliAccessTokenbl auth login --open-api ... --config test后bl auth status --config test→ openapi 与 console 均已配置testblock 的access_token改为无效值,执行任意 console 命令 → 自动刷新成功而非报NotLoginedbl bootstrap --dry-run看计划;bl bootstrap --config test --verbose→ 最终status: readybl config set api_key sk-a --config a/--config b,bl config show --config a与默认互不影响bl config ui(可选--port/--no-open/--config <name>)→ 浏览器打开带 token 的本地页面,管理各 profile;bl config ui --dry-run只打印监听计划与路由兼容性
--config时行为与旧版一致,已有单套凭证的config.json无需迁移。main时对齐移除了 intent-detect 独立 base URL 的所有引用;skills/bailian-cli/reference/已重新生成。已知事项
packages/commands/tests/e2e/auth.e2e.test.ts里auth login --open-api用例会触发真实GenerateCLIAccessToken网络调用,离线环境(占位 AK/SK)必然失败;该失败在本 PR 的 WebUI 改动之前即存在,属于 open-api-token 特性的既有问题,与本次改动无关。