tyc-cli 0.3.6 → 0.3.7

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/README.md CHANGED
@@ -78,9 +78,8 @@ tyc init --authorization "YOUR_API_TOKEN" --no-verify
78
78
  > `~/.tyc/config.json`。后续业务命令会在 access token 临期时自动刷新;
79
79
  > 如果服务端返回 401,会强制刷新一次并重试当前请求。
80
80
  > `tyc login --no-open --no-block` 会打印授权 URL 后立即退出,并把一次性 PKCE 上下文
81
- > 保存到 `~/.tyc/oauth_pending.json`;完成浏览器授权后,复制回调 URL 中的 `code`
82
- > 参数或完整 callback URL,执行
83
- > `tyc login --callback-token "<...>"` 完成换 token。
81
+ > 保存到 `~/.tyc/oauth_pending.json`;完成浏览器授权后,页面会跳转到天眼查 CLI
82
+ > 回调页并展示可复制命令,执行 `tyc login --callback-token "<...>"` 完成换 token。
84
83
  > `tyc init` 保存配置后会立即校验 shared core endpoint;失败则退出码 1 并提示连通性问题。
85
84
  > 加 `--no-verify` 可跳过校验。
86
85
 
@@ -123,7 +122,7 @@ tyc executive personnel-dishonest "..." --humanName "张三"
123
122
  | 命令 | 说明 |
124
123
  |------|------|
125
124
  | `tyc login` | 浏览器 OAuth 登录;自动发现 metadata、使用 PKCE 获取 access token / refresh token 并写入配置 |
126
- | `tyc login --no-open --no-block` | 打印 OAuth 授权 URL 并立即退出,等待后续手动完成 |
125
+ | `tyc login --no-open --no-block` | 打印 OAuth 授权 URL 并立即退出,授权完成后按天眼查 CLI 回调页提示继续 |
127
126
  | `tyc login --callback-token <code-or-url>` | 使用上一步保存的 PKCE 上下文,把回调 code 换成 access token |
128
127
  | `tyc login --url <url>` | 对指定 MCP endpoint 发起 OAuth 登录 |
129
128
  | `tyc init --authorization <token>` | 写入 `headers.Authorization`;保存后会立即校验 shared core 连通性 |
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_MCP_URL, applyOAuthTokenToConfig, defaultCoreURL, loadConfig, resolveConfig, saveConfig, } from "../config.js";
2
2
  import { verifyCoreAuthEndpoint } from "../coreClient.js";
3
- import { buildAuthorizationURL, createPKCE, discoverAuthorizationServer, discoverProtectedResourceMetadata, exchangeAuthorizationCode, knownOAuthDefaultsForMcpURL, openBrowser, parseAuthorizationCallbackCode, randomState, registerDynamicOAuthClient, startCallbackServer, } from "../oauth.js";
3
+ import { buildAuthorizationURL, buildCliCallbackRedirectUri, createPKCE, discoverAuthorizationServer, discoverProtectedResourceMetadata, exchangeAuthorizationCode, knownOAuthDefaultsForMcpURL, openBrowser, parseAuthorizationCallbackCode, randomState, registerDynamicOAuthClient, startCallbackServer, } from "../oauth.js";
4
4
  import { clearPendingOAuthLogin, loadPendingOAuthLogin, savePendingOAuthLogin, } from "../oauthPending.js";
5
5
  import { printLoginSuccessBanner } from "../logo.js";
6
6
  function parsePort(raw) {
@@ -16,12 +16,6 @@ function normalizeCallbackPath(raw) {
16
16
  const path = raw || "/oauth/callback";
17
17
  return path.startsWith("/") ? path : `/${path}`;
18
18
  }
19
- function buildLoopbackRedirectUri(host, port, path) {
20
- if (port === 0) {
21
- throw new Error("--no-block 不能与 --redirect-port 0 同时使用,请指定固定回调端口。");
22
- }
23
- return `http://${host}:${port}${path}`;
24
- }
25
19
  function pickCallbackToken(opts) {
26
20
  if (opts.callbackToken && opts.token) {
27
21
  throw new Error("--callback-token 和 --token 只能指定一个。");
@@ -185,7 +179,7 @@ export function registerLoginCommand(program) {
185
179
  const pkce = createPKCE();
186
180
  let callback;
187
181
  const redirectUri = noBlock
188
- ? buildLoopbackRedirectUri(redirectHost, redirectPort, callbackPath)
182
+ ? buildCliCallbackRedirectUri(issuer)
189
183
  : (callback = await startCallbackServer({
190
184
  host: redirectHost,
191
185
  port: redirectPort,
@@ -249,9 +243,9 @@ export function registerLoginCommand(program) {
249
243
  console.error("请在浏览器打开以下 URL 完成登录:");
250
244
  console.error(authorizationURL);
251
245
  console.error("");
252
- console.error("完成授权后,复制回调 URL 中的 code 参数,然后运行:");
253
- console.error("tyc login --callback-token <code_or_callback_url>");
254
- console.error("也可以传完整 callback URL:tyc login --callback-token \"http://localhost:7078/oauth/callback?code=...&state=...\"");
246
+ console.error("完成授权后,浏览器会打开天眼查 CLI 回调页。请按页面提示复制命令到终端执行。");
247
+ console.error("也可以复制完整回调 URL 后运行:");
248
+ console.error(`tyc login --callback-token "${redirectUri}?code=...&state=..."`);
255
249
  return;
256
250
  }
257
251
  if (opts.open === false) {
package/dist/oauth.js CHANGED
@@ -172,6 +172,10 @@ export function createPKCE() {
172
172
  export function randomState() {
173
173
  return randomBytes(24).toString("base64url");
174
174
  }
175
+ export function buildCliCallbackRedirectUri(issuer) {
176
+ const url = new URL(issuer);
177
+ return `${trimRightSlash(url.toString())}/cli/callback`;
178
+ }
175
179
  function callbackHTML(title, body) {
176
180
  return `<!doctype html>
177
181
  <meta charset="utf-8">
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "tyc-cli",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "天眼查 AI CLI — 162 个业务语义聚合工具 · 默认 Shared Core 调用 · 兼容 MCP transport",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
- "tyc": "./dist/index.js"
7
+ "tyc": "dist/index.js"
8
8
  },
9
9
  "scripts": {
10
10
  "build": "tsc && cp src/catalog.json dist/catalog.json",