Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ bl auth login --console

Use `--console-site international` for the international console.

The CLI always prints the login URL. To choose a browser yourself, keep the command running and open the URL on the **same machine**:

```bash
bl auth login --console --no-browser --console-site international
```

If the browser blocks the local callback, check the console site's local-network permission or try Firefox. The PNA compatibility header does not bypass Chrome's local-network permission or Safari's mixed-content restrictions. No callback within 15 minutes is a failure (exit code 5), not a successful login.

If you already have a valid console access token, import it via stdin without a browser or local callback server. Specify the token's actual region and site; for example, in a POSIX shell:

```bash
bl auth login --console --token-stdin --console-site international --console-region ap-southeast-1 < /path/to/console-token.txt
```

Input must be one raw token (up to 64 KiB), not JSON or `Bearer ...`; interactive terminal input is rejected to avoid echoing secrets. Use a protected file or trusted pipe, never put the token in command arguments or shell history, and remove temporary secret files after use. The CLI validates the token before saving; failure leaves existing credentials and the active Profile unchanged. Add `--config <name>` to save and activate a specific Profile on success. This imports only the console session, not a model API key.

### API Key

To use an existing ordinary API key or a Token Plan subscription key, run the same command:
Expand Down
16 changes: 16 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ bl auth login --console

国际站请使用 `--console-site international`。

CLI 始终打印登录地址。若要自行选择浏览器,请保持命令运行,并在**同一台机器**的浏览器中打开地址:

```bash
bl auth login --console --no-browser --console-site international
```

浏览器拦截本地回调时,请检查控制台站点的本地网络权限,或尝试 Firefox。PNA 兼容响应头不能绕过 Chrome 的本地网络权限或 Safari 的混合内容限制。15 分钟内未收到回调会登录失败(退出码 5),不会视为成功。

如果已有有效的控制台 access token,可通过 stdin 导入,无需浏览器或本地回调服务。必须指定 token 实际所属的地域与站点;以下为 POSIX shell 示例:

```bash
bl auth login --console --token-stdin --console-site international --console-region ap-southeast-1 < /path/to/console-token.txt
```

输入只能是一个原始 token(不超过 64 KiB),不接受 JSON 或 `Bearer ...`;为避免凭证回显,不接受终端交互输入。请使用受保护的文件或可信管道,不要把 token 放进命令参数或 shell 历史,使用后清理临时凭证文件。CLI 校验通过才保存;失败时保留原凭证和激活的 Profile。加上 `--config <name>` 可在成功后写入并激活指定 Profile。此方式仅导入控制台会话,不创建模型 API Key。

### API Key

使用已有的普通 API Key 或 Token Plan 订阅 Key,都执行同一条命令:
Expand Down
18 changes: 16 additions & 2 deletions docs/agents/auth-change.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx
- `bl auth login --api-key ...` 先通过只读 `GET /models` 校验 Key,校验成功后才原子写入 `api_key` 与实际匹配的 `base_url`。显式 `--base-url` 只校验该站点,不自动改写;未显式指定时,普通 `sk-*` / `sk-ws-*` 按“当前 Profile 已保存的同类站点 → 基于 `workspace_id` 构造的各地域 Workspace 专属站点 → 公共地域”顺序选择首个成功结果,`sk-sp-*` 并行探测国内站与新加坡 Token Plan,其他格式同时尝试两类候选。所有候选明确拒绝时返回 `AUTH`;网络、超时、非 JSON 或 5xx 视为校验无法确定并透传原错误。任一失败都不落盘、不激活 Profile
- 未显式传 `--config` 时,`sk-sp-*` 自动写入并激活 `token-plan`;普通 `sk-*` / `sk-ws-*` 仅在当前为 `token-plan` 时改写并激活 `default`,否则保留当前 Profile;其他格式不自动切换。显式 `--config` 始终优先。`sk-sp-*` 无论写入哪个 Profile 都会携带 Token Plan 的预设默认模型,并在保留已有项的基础上补齐 `api_key_capabilities`,不自动删除任何已有能力。登录仍不得删除其他鉴权域的凭证
- `bl auth login --console` 更新 `access_token` 以及回调携带的 console 作用域字段;若所选 Profile 没有模型 API Key,会要求控制台页面创建并回传一个普通 API Key 与 Base URL 一并保存。该回调结果不重复执行 `/models` 校验,且不会创建或配置 Token Plan
- `bl auth login --open-api ...` 更新 `access_key_id` / `access_key_secret`,同时会调用 OpenAPI 生成 CLI `access_token` 并一并写入;即一次 `--open-api` 登录同时产生 `openapi` 与 `console` 域凭证
- `bl auth login --open-api ...` 调用 OpenAPI 生成 CLI `access_token`,通过目标 Console 网关的只读 `loginInfo` 校验后,才一并写入 `access_key_id` / `access_key_secret` / `access_token` 和实际 `console_region` / `console_site`;失败不覆盖原凭证、不激活 Profile。一次成功登录同时产生 `openapi` 与 `console` 域凭证
- `bl auth logout --console` 只清 `access_token`
- `bl auth logout --open-api` 只清 `access_key_id` / `access_key_secret` / `security_token`
- `bl auth logout` 清 `api_key` + `base_url` + `access_token` + `access_key_*`
Expand All @@ -58,6 +58,20 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx

命令不要直接解析 token、env 或 config。业务请求统一走 `ctx.client`;登录/配置命令通过 `ctx.authStore` / `ctx.configStore` 的窄接口操作落盘。

### Console 浏览器回调与人工导入

- 浏览器回调只监听 `127.0.0.1`,校验随机 `state`,只对本次控制台 Origin 返回 CORS 头;仅可信 Origin 明确请求 PNA 时返回 `Access-Control-Allow-Private-Network: true`。错误响应也必须可被可信页面读取,不能返回通配 Origin。
- 登录地址始终输出;`--no-browser` 只禁止自动打开浏览器,仍等待本机回调。必须在打开浏览器前注册完成事件,浏览器启动失败或挂起不阻止回调完成。无 token 的回调不能视为成功;15 分钟未收到凭证返回 `TIMEOUT`,保存失败返回错误,保存期间客户端断开也必须完成清理。
- `--console --token-stdin` 与 `--no-browser` 互斥,必须显式指定 `--console-region`;只接受非 TTY stdin 的单个原始 token(最多 64 KiB),拒绝空输入、JSON、Bearer 前缀及多 token 输入。此分支不启动浏览器或回调服务,经目标网关 `loginInfo` 验证成功才保存 token/site/region 并激活指定 Profile;保留其他凭证,失败和 dry-run 不写入、不激活,dry-run 不读取 stdin。
- PNA 响应头只是兼容措施,不能宣称绕过 Chrome LNA 权限或 Safari 混合内容限制。回归覆盖真实 loopback 请求、超时、浏览器启动竞态、stdin 失败不改配置及输出不泄漏 token。

### Console token 签发与刷新

- `resolveCLIAccessTokenTarget()` 优先采用有效 `consoleRegion`;地域缺省时识别国内/新加坡 DashScope 和对应 `*.maas.aliyuncs.com` 域名(含 Token Plan、Workspace)。未知或不支持的地域报错,不静默回退北京;`consoleSite` 与地域独立,不能把新加坡自动等同国际站。
- `Client.console()` 收到 `NotLogined` 后,以本次实际 Console credential 的 region/site/switchAgent 签发并重试一次。只有原请求重试成功才保存新 token,并更新 Client 内存凭证;失败保留磁盘旧 token。
- `refreshAccessToken()` 独立调用时默认用只读 `loginInfo` 验证;调用方提供 `validateToken` 时由其完成验证或原请求重试,回调成功后才落盘。缺少当前 Profile 的 AK/SK 返回 `null`,不跨 Profile 借用凭证。
- `auth generate-access-token` 只签发并输出,不做 Console 验证、不持久化;首次登录的校验直接走 `callConsoleGateway`,不得递归进入刷新流程。

### 例外:agent 命令的分层鉴权与 SDK 凭证内存注入

`bl managed-agent *` 按调用链分两层:
Expand Down Expand Up @@ -143,7 +157,7 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx

### E. 测试

- [ ] `packages/cli/tests/e2e/auth.e2e.test.ts` 增加新方式的 happy / failure 路径
- [ ] `packages/commands/tests/e2e/auth.e2e.test.ts` 增加新方式的 happy / failure 路径;浏览器回调契约在 `packages/commands/tests/login-console.test.ts` 覆盖
- [ ] mask token 的输出格式不变(避免泄漏)
- [ ] 如调整 resolver 优先级,补 core/runtime 单测覆盖 flag > env > file

Expand Down
2 changes: 1 addition & 1 deletion packages/bailian-kb-dsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-kb-dsh",
"version": "2.5.0",
"version": "2.5.1",
"description": "Bailian knowledge-base tools for DeepSeek Harness: kb_search and kb_chat over the DashScope RAG API, plus the bl CLI management skill.",
"keywords": [
"alibaba-cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/bailian-memo-dsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-memo-dsh",
"version": "2.5.0",
"version": "2.5.1",
"description": "Bailian personal memory for DeepSeek Harness: automatic recall, silent curation, and user-controlled remember/forget.",
"keywords": [
"alibaba-cloud",
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ bl auth login --console

Use `--console-site international` for the international console.

The CLI always prints the login URL. To choose a browser yourself, keep the command running and open the URL on the **same machine**:

```bash
bl auth login --console --no-browser --console-site international
```

If the browser blocks the local callback, check the console site's local-network permission or try Firefox. The PNA compatibility header does not bypass Chrome's local-network permission or Safari's mixed-content restrictions. No callback within 15 minutes is a failure (exit code 5), not a successful login.

If you already have a valid console access token, import it via stdin without a browser or local callback server. Specify the token's actual region and site; for example, in a POSIX shell:

```bash
bl auth login --console --token-stdin --console-site international --console-region ap-southeast-1 < /path/to/console-token.txt
```

Input must be one raw token (up to 64 KiB), not JSON or `Bearer ...`; interactive terminal input is rejected to avoid echoing secrets. Use a protected file or trusted pipe, never put the token in command arguments or shell history, and remove temporary secret files after use. The CLI validates the token before saving; failure leaves existing credentials and the active Profile unchanged. Add `--config <name>` to save and activate a specific Profile on success. This imports only the console session, not a model API key.

### API Key

To use an existing ordinary API key or a Token Plan subscription key, run the same command:
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ bl auth login --console

国际站请使用 `--console-site international`。

CLI 始终打印登录地址。若要自行选择浏览器,请保持命令运行,并在**同一台机器**的浏览器中打开地址:

```bash
bl auth login --console --no-browser --console-site international
```

浏览器拦截本地回调时,请检查控制台站点的本地网络权限,或尝试 Firefox。PNA 兼容响应头不能绕过 Chrome 的本地网络权限或 Safari 的混合内容限制。15 分钟内未收到回调会登录失败(退出码 5),不会视为成功。

如果已有有效的控制台 access token,可通过 stdin 导入,无需浏览器或本地回调服务。必须指定 token 实际所属的地域与站点;以下为 POSIX shell 示例:

```bash
bl auth login --console --token-stdin --console-site international --console-region ap-southeast-1 < /path/to/console-token.txt
```

输入只能是一个原始 token(不超过 64 KiB),不接受 JSON 或 `Bearer ...`;为避免凭证回显,不接受终端交互输入。请使用受保护的文件或可信管道,不要把 token 放进命令参数或 shell 历史,使用后清理临时凭证文件。CLI 校验通过才保存;失败时保留原凭证和激活的 Profile。加上 `--config <name>` 可在成功后写入并激活指定 Profile。此方式仅导入控制台会话,不创建模型 API Key。

### API Key

使用已有的普通 API Key 或 Token Plan 订阅 Key,都执行同一条命令:
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli",
"version": "2.5.0",
"version": "2.5.1",
"description": "CLI for Aliyun Model Studio (DashScope) AI Platform.",
"keywords": [
"agent",
Expand Down
2 changes: 1 addition & 1 deletion packages/commands/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli-commands",
"version": "2.5.0",
"version": "2.5.1",
"description": "Command library for bailian-cli products (knowledge, memory, media, …). See https://www.npmjs.com/package/bailian-cli for usage.",
"homepage": "https://bailian.console.aliyun.com/cli",
"bugs": {
Expand Down
Loading
Loading