ali-skills 0.0.23 → 0.0.24

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.
@@ -2205,7 +2205,7 @@ function logSkillParseFailures(failures) {
2205
2205
  if (f.hint) M.message(import_picocolors.default.yellow(` 提示: ${f.hint}`));
2206
2206
  }
2207
2207
  }
2208
- var version$1 = "2.0.23";
2208
+ var version$1 = "2.0.24";
2209
2209
  const isCancelled$1 = (value) => typeof value === "symbol";
2210
2210
  function redactSensitiveText(text) {
2211
2211
  return text.replace(/(https?:\/\/)([^/\s:@]+)(?::([^@/\s]*))?@/gi, "$1").replace(/([?&](?:private_token|access_token|token|api_key|access_key|secret|password)=)[^&\s]+/gi, "$1***");
@@ -5381,6 +5381,17 @@ const REDIRECT_STATUS_CODES = new Set([
5381
5381
  308
5382
5382
  ]);
5383
5383
  const MAX_REDIRECTS = 5;
5384
+ function normalizeEscapedUrlInput(rawUrl) {
5385
+ if (!rawUrl.includes("\\")) return {
5386
+ normalizedUrl: rawUrl,
5387
+ changed: false
5388
+ };
5389
+ const normalizedUrl = rawUrl.replace(/\\([?&=#])/g, "$1");
5390
+ return {
5391
+ normalizedUrl,
5392
+ changed: normalizedUrl !== rawUrl
5393
+ };
5394
+ }
5384
5395
  function detectAuthMode(platformKey, platform, hostname) {
5385
5396
  if (platform.authType === "private_token") return "private_token";
5386
5397
  if (platformKey === "o2") return "auto";
@@ -5709,7 +5720,7 @@ async function sendSsoTicketDirectRequest(targetUrl, options) {
5709
5720
  } else console.log(outputBody);
5710
5721
  if (!response.ok) process.exit(1);
5711
5722
  }
5712
- async function sendPlainDirectRequest(targetUrl, options) {
5723
+ async function sendPlainDirectRequest(targetUrl, options, allowSsoCookieFallback = false) {
5713
5724
  const requestHeaders = { "User-Agent": "ali-skills-cli/1.0" };
5714
5725
  if (options.headers) Object.entries(options.headers).forEach(([key, value]) => {
5715
5726
  requestHeaders[key] = value;
@@ -5723,11 +5734,19 @@ async function sendPlainDirectRequest(targetUrl, options) {
5723
5734
  console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5724
5735
  console.log(`${DIM$2}→ 直接请求 (No Auth)${RESET$2}`);
5725
5736
  }
5726
- const controller = new AbortController();
5727
5737
  const timeout = options.timeout || 3e4;
5728
- const timeoutId = setTimeout(() => controller.abort(), timeout);
5729
- const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5730
- clearTimeout(timeoutId);
5738
+ const { response, responseBody, sawAlibabaLoginRedirect } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5739
+ if (allowSsoCookieFallback && sawAlibabaLoginRedirect) {
5740
+ if (!options.quiet) {
5741
+ console.log(`${YELLOW$2}检测到请求被重定向到 login.alibaba-inc.com,目标接口可能需要登录鉴权${RESET$2}`);
5742
+ console.log(`${DIM$2}将自动使用 --auth sso_cookie 重试原始接口;如不符合预期,请显式指定 --auth${RESET$2}`);
5743
+ }
5744
+ await sendSsoCookieDirectRequest(targetUrl, {
5745
+ ...options,
5746
+ authMode: "sso_cookie"
5747
+ });
5748
+ return;
5749
+ }
5731
5750
  if (!options.quiet) {
5732
5751
  const statusColor = response.ok ? GREEN$1 : RED$2;
5733
5752
  console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
@@ -5757,6 +5776,7 @@ async function fetchWithRedirects(initialUrl, method, headers, body, timeout, qu
5757
5776
  const timeoutId = setTimeout(() => controller.abort(), timeout);
5758
5777
  let currentUrl = initialUrl;
5759
5778
  let redirects = 0;
5779
+ let sawAlibabaLoginRedirect = false;
5760
5780
  try {
5761
5781
  while (true) {
5762
5782
  const response = await fetch(currentUrl, {
@@ -5768,15 +5788,18 @@ async function fetchWithRedirects(initialUrl, method, headers, body, timeout, qu
5768
5788
  });
5769
5789
  if (!REDIRECT_STATUS_CODES.has(response.status)) return {
5770
5790
  response,
5771
- responseBody: await response.text()
5791
+ responseBody: await response.text(),
5792
+ sawAlibabaLoginRedirect
5772
5793
  };
5773
5794
  const location = response.headers.get("location");
5774
5795
  if (!location) return {
5775
5796
  response,
5776
- responseBody: await response.text()
5797
+ responseBody: await response.text(),
5798
+ sawAlibabaLoginRedirect
5777
5799
  };
5778
5800
  if (redirects >= MAX_REDIRECTS) throw new Error(`重定向次数超过上限(${MAX_REDIRECTS})`);
5779
5801
  const nextUrl = new URL(location, currentUrl).toString();
5802
+ if (new URL(nextUrl).hostname === "login.alibaba-inc.com") sawAlibabaLoginRedirect = true;
5780
5803
  redirects += 1;
5781
5804
  if (!quiet) console.log(`${DIM$2}↪ 重定向 ${redirects}: ${response.status} ${response.statusText} -> ${nextUrl}${RESET$2}`);
5782
5805
  currentUrl = nextUrl;
@@ -5863,8 +5886,9 @@ async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "g
5863
5886
  }
5864
5887
  async function proxyRequest(targetUrl, options) {
5865
5888
  let url;
5889
+ const { normalizedUrl, changed: urlInputNormalized } = normalizeEscapedUrlInput(targetUrl);
5866
5890
  try {
5867
- url = new URL(targetUrl);
5891
+ url = new URL(normalizedUrl);
5868
5892
  } catch {
5869
5893
  console.error(`${RED$2}Error: URL 必须是绝对地址,收到 "${targetUrl}"${RESET$2}`);
5870
5894
  console.log(`${DIM$2}未传 platform 时,请使用完整 URL(包含协议和域名)${RESET$2}`);
@@ -5885,12 +5909,17 @@ async function proxyRequest(targetUrl, options) {
5885
5909
  ssoType: "refresh_token"
5886
5910
  };
5887
5911
  try {
5912
+ if (urlInputNormalized && !options.quiet) {
5913
+ console.log(`${DIM$2}检测到 URL 中包含转义分隔符,已自动还原后请求${RESET$2}`);
5914
+ console.log(`${DIM$2}原始: ${targetUrl}${RESET$2}`);
5915
+ console.log(`${DIM$2}还原: ${normalizedUrl}${RESET$2}`);
5916
+ }
5888
5917
  if (!isKnownPlatform && !hasExplicitAuthMode) {
5889
5918
  if (!options.quiet) {
5890
5919
  console.log(`${DIM$2}平台: Custom Host${RESET$2}`);
5891
5920
  console.log(`${DIM$2}认证方式: Auto (未知平台默认直连,无鉴权)${RESET$2}`);
5892
5921
  }
5893
- await sendPlainDirectRequest(targetUrl, options);
5922
+ await sendPlainDirectRequest(normalizedUrl, options, true);
5894
5923
  return;
5895
5924
  }
5896
5925
  if (!options.quiet) console.log(`${DIM$2}平台: ${platform.name}${RESET$2}`);
@@ -5902,7 +5931,7 @@ async function proxyRequest(targetUrl, options) {
5902
5931
  console.error(`${RED$2}Error: o2 仅支持 --auth auto 或 --auth sso_ticket${RESET$2}`);
5903
5932
  process.exit(1);
5904
5933
  }
5905
- await sendO2SdkRequest(targetUrl, options, authMode === "sso_ticket");
5934
+ await sendO2SdkRequest(normalizedUrl, options, authMode === "sso_ticket");
5906
5935
  return;
5907
5936
  }
5908
5937
  switch (authMode) {
@@ -5921,17 +5950,17 @@ async function proxyRequest(targetUrl, options) {
5921
5950
  process.exit(1);
5922
5951
  }
5923
5952
  }
5924
- await sendDirectRequest(targetUrl, platform, token, options);
5953
+ await sendDirectRequest(normalizedUrl, platform, token, options);
5925
5954
  return;
5926
5955
  }
5927
5956
  case "sso_cookie":
5928
- await sendSsoCookieDirectRequest(targetUrl, options);
5957
+ await sendSsoCookieDirectRequest(normalizedUrl, options);
5929
5958
  return;
5930
5959
  case "sso_ticket":
5931
- await sendSsoTicketDirectRequest(targetUrl, options);
5960
+ await sendSsoTicketDirectRequest(normalizedUrl, options);
5932
5961
  return;
5933
5962
  case "gateway":
5934
- await sendGatewayRequest(targetUrl, platformKey, options, "gateway");
5963
+ await sendGatewayRequest(normalizedUrl, platformKey, options, "gateway");
5935
5964
  return;
5936
5965
  default: break;
5937
5966
  }
@@ -5941,12 +5970,12 @@ async function proxyRequest(targetUrl, options) {
5941
5970
  console.error(`${RED$2}Error: o2 仅支持 --auth auto 或 --auth sso_ticket${RESET$2}`);
5942
5971
  process.exit(1);
5943
5972
  }
5944
- await sendO2SdkRequest(targetUrl, options, authMode === "sso_ticket");
5973
+ await sendO2SdkRequest(normalizedUrl, options, authMode === "sso_ticket");
5945
5974
  return;
5946
5975
  }
5947
5976
  switch (authMode) {
5948
5977
  case "private_token": {
5949
- let token = getPlatformPrivateToken(platformKey, options.token, targetUrl);
5978
+ let token = getPlatformPrivateToken(platformKey, options.token, normalizedUrl);
5950
5979
  if (!token) {
5951
5980
  token = await promptConfigureToken(platformKey, platform);
5952
5981
  if (!token) {
@@ -5960,19 +5989,19 @@ async function proxyRequest(targetUrl, options) {
5960
5989
  process.exit(1);
5961
5990
  }
5962
5991
  }
5963
- await sendDirectRequest(targetUrl, platform, token, options);
5992
+ await sendDirectRequest(normalizedUrl, platform, token, options);
5964
5993
  break;
5965
5994
  }
5966
5995
  case "sso_ticket":
5967
5996
  case "gateway":
5968
- await sendGatewayRequest(targetUrl, platformKey, options, authMode);
5997
+ await sendGatewayRequest(normalizedUrl, platformKey, options, authMode);
5969
5998
  break;
5970
5999
  case "sso_cookie":
5971
- await sendSsoCookieDirectRequest(targetUrl, options);
6000
+ await sendSsoCookieDirectRequest(normalizedUrl, options);
5972
6001
  break;
5973
6002
  default: if (platform.authType === "private_token") {
5974
- const token = getPlatformPrivateToken(platformKey, options.token, targetUrl);
5975
- if (token) await sendDirectRequest(targetUrl, platform, token, options);
6003
+ const token = getPlatformPrivateToken(platformKey, options.token, normalizedUrl);
6004
+ if (token) await sendDirectRequest(normalizedUrl, platform, token, options);
5976
6005
  else {
5977
6006
  console.error(`${RED$2}Error: ${platform.name} 需要配置 Private Token${RESET$2}`);
5978
6007
  console.log(`${DIM$2}您可以通过以下方式配置:${RESET$2}`);
@@ -5983,8 +6012,8 @@ async function proxyRequest(targetUrl, options) {
5983
6012
  console.log(` 参数: --token <your_token>`);
5984
6013
  process.exit(1);
5985
6014
  }
5986
- } else if (isAlibabaIncRootDomain) await sendSsoCookieDirectRequest(targetUrl, options);
5987
- else await sendGatewayRequest(targetUrl, platformKey, options, "sso_ticket");
6015
+ } else if (isAlibabaIncRootDomain) await sendSsoCookieDirectRequest(normalizedUrl, options);
6016
+ else await sendGatewayRequest(normalizedUrl, platformKey, options, "sso_ticket");
5988
6017
  }
5989
6018
  } catch (error) {
5990
6019
  if (error instanceof Error) if (error.name === "AbortError") console.error(`${RED$2}Error: 请求超时${RESET$2}`);
@@ -6452,19 +6481,20 @@ ${BOLD}Gateway Commands:${RESET}
6452
6481
  request [platform] <url|path> Send HTTP request (supports platform + path shorthand)
6453
6482
  req [platform] <url|path> Alias for request, recommended
6454
6483
 
6484
+ ${BOLD}Platform Values:${RESET}
6485
+ ${platformKeysForHelp}
6486
+
6455
6487
  ${BOLD}Yuque Commands:${RESET}
6456
6488
  login yuque [group] Configure/switch specified Yuque group directly
6457
6489
  logout yuque [group] [--all] Choose one/many Yuque groups to clear, or clear all
6458
6490
  status yuque [group] [--show|-s] [--pretty] Show Yuque group/all config JSON
6459
6491
 
6460
- ${BOLD}Platform Values:${RESET}
6461
- ${platformKeysForHelp}
6462
-
6463
6492
  ${BOLD}Request Options:${RESET}
6464
6493
  -X, --method <method> HTTP method (default: GET)
6465
6494
  -b, --body <body> Request body (JSON string or @file)
6466
6495
  -h, --header <header> Custom header (can be used multiple times)
6467
6496
  --auth, --auth-mode <mode> Auth mode: auto/private_token/sso_cookie/sso_ticket
6497
+ --sso <cookie|ticket> Shortcut for --auth sso_cookie/sso_ticket
6468
6498
  --token <token> Explicit token for private_token mode
6469
6499
  -o, --output <file> Save response to file
6470
6500
  -i, --include-headers Include response headers in output
@@ -6473,46 +6503,104 @@ ${BOLD}Request Options:${RESET}
6473
6503
  --raw Raw output without formatting
6474
6504
  -q, --quiet Quiet mode, only output response body
6475
6505
 
6476
- ${BOLD}Environment:${RESET}
6477
- ALI_SKILLS_YUQUE_GROUP Yuque team slug when multiple teams have tokens in config
6478
- O2_API_ENV O2 SDK env override (default online; set pre for pre env)
6479
- ALI_SKILLS_DEBUG_GATEWAY Enable gateway auth debug logs (1/true/on)
6480
-
6481
6506
  ${BOLD}Examples:${RESET}
6482
6507
  ${DIM}$${RESET} ali-skills login
6483
6508
  ${DIM}$${RESET} ali-skills login code
6484
6509
  ${DIM}$${RESET} ali-skills login yuque
6485
- ${DIM}$${RESET} ali-skills login yuque fliggy
6510
+ ${DIM}$${RESET} ali-skills login yuque group
6486
6511
  ${DIM}$${RESET} ali-skills status --all
6512
+ ${DIM}$${RESET} ali-skills status
6487
6513
  ${DIM}$${RESET} ali-skills status code
6488
- ${DIM}$${RESET} ali-skills status -s
6489
- ${DIM}$${RESET} ali-skills status -s --pretty
6514
+ ${DIM}$${RESET} ali-skills status yuque
6515
+ ${DIM}$${RESET} ali-skills status yuque group
6516
+ ${DIM}$${RESET} ali-skills status o2
6517
+ ${DIM}$${RESET} ali-skills status --show
6490
6518
  ${DIM}$${RESET} ali-skills status code --show
6491
6519
  ${DIM}$${RESET} ali-skills status yuque --show
6492
- ${DIM}$${RESET} ali-skills status yuque fliggy
6493
6520
  ${DIM}$${RESET} ali-skills status yuque fliggy --show
6521
+ ${DIM}$${RESET} ali-skills logout
6494
6522
  ${DIM}$${RESET} ali-skills logout code
6495
6523
  ${DIM}$${RESET} ali-skills logout yuque
6496
6524
  ${DIM}$${RESET} ali-skills logout yuque my-team
6497
6525
  ${DIM}$${RESET} ali-skills logout yuque --all
6498
- ${DIM}$${RESET} ali-skills req o2 /v1.0/work/apps
6499
- ${DIM}$${RESET} ali-skills req o2 /v1.0/work/aone/issues/search -X POST -b '{"keyword":"auth"}'
6500
- ${DIM}$${RESET} ali-skills req o2 /v1.0/work/issues/123 --auth sso_ticket
6501
- ${DIM}$${RESET} ali-skills req https://code.alibaba-inc.com/api/v4/projects -X GET
6502
- ${DIM}$${RESET} ali-skills req https://yuque-api.antfin-inc.com/api/v2/repos -o repos.json
6503
- ${DIM}$${RESET} ali-skills req yuque "/api/v2/search?q=buc&type=doc"
6504
- ${DIM}$${RESET} ali-skills req yuque "/api/v2/search?q=buc&type=doc&scope=fliggyfe-infra"
6505
- ${DIM}$${RESET} ali-skills logout
6526
+ ${DIM}$${RESET} ali-skills req 'https://subdomain.alibaba-inc.com/path?q=v'
6527
+ ${DIM}$${RESET} ali-skills req 'https://subdomain.alibaba-inc.com/path?q=v' --auth sso_cookie
6528
+ ${DIM}$${RESET} ali-skills req 'https://subdomain.alibaba-inc.com/path?q=v' --auth sso_cookie -X POST -b '{"k": "v"}' -h 'X-Custom-Header: value'
6529
+ ${DIM}$${RESET} ali-skills req 'https://support-buc-sso-ticket-site/path?q=v' --auth sso_ticket
6530
+ ${DIM}$${RESET} ali-skills req code '/api/v3/project?path=clam-ng/clam'
6531
+ ${DIM}$${RESET} ali-skills req yuque '/api/v2/repos/fliggyfe-infra/ali-skills-dev/docs/mll9xim6y6lcnvyg'
6532
+ ${DIM}$${RESET} ali-skills req yuque '/api/v2/search?q=buc&type=doc&scope=fliggyfe-infra'
6533
+ ${DIM}$${RESET} ali-skills req o2 '/v1.0/work/apps/rxpi%252Fmtop/trunk'
6534
+ ${DIM}$${RESET} ali-skills req o2 '/v1.0/work/apps/rxpi%252Fmtop/detail' --auth sso_ticket
6506
6535
  `);
6507
6536
  }
6508
6537
  function parseRequestOptions(args) {
6509
6538
  let url = "";
6510
6539
  const options = { method: "GET" };
6511
6540
  const headers = {};
6541
+ const parseSsoShortcut = (raw) => {
6542
+ if (!raw) return void 0;
6543
+ const normalized = raw.trim().toLowerCase();
6544
+ if (normalized === "cookie") return "sso_cookie";
6545
+ if (normalized === "ticket") return "sso_ticket";
6546
+ };
6512
6547
  for (let i = 0; i < args.length; i++) {
6513
6548
  const arg = args[i];
6549
+ const parseLongOptionValue = (name) => {
6550
+ const prefix = `--${name}=`;
6551
+ if (!arg?.startsWith(prefix)) return void 0;
6552
+ return arg.slice(prefix.length);
6553
+ };
6554
+ const methodValue = parseLongOptionValue("method");
6555
+ if (methodValue !== void 0) {
6556
+ options.method = methodValue || "GET";
6557
+ continue;
6558
+ }
6559
+ const bodyValue = parseLongOptionValue("body");
6560
+ if (bodyValue !== void 0) {
6561
+ options.body = bodyValue;
6562
+ continue;
6563
+ }
6564
+ const headerValue = parseLongOptionValue("header");
6565
+ if (headerValue !== void 0) {
6566
+ const [key, ...valueParts] = headerValue.split(":");
6567
+ if (key && valueParts.length > 0) headers[key.trim()] = valueParts.join(":").trim();
6568
+ continue;
6569
+ }
6570
+ const outputValue = parseLongOptionValue("output");
6571
+ if (outputValue !== void 0) {
6572
+ options.output = outputValue;
6573
+ continue;
6574
+ }
6575
+ const timeoutValue = parseLongOptionValue("timeout");
6576
+ if (timeoutValue !== void 0) {
6577
+ if (timeoutValue) options.timeout = parseInt(timeoutValue, 10);
6578
+ continue;
6579
+ }
6580
+ const authModeValue = parseLongOptionValue("auth-mode") ?? parseLongOptionValue("auth");
6581
+ if (authModeValue !== void 0) {
6582
+ options.authMode = authModeValue || "auto";
6583
+ continue;
6584
+ }
6585
+ const tokenValue = parseLongOptionValue("token");
6586
+ if (tokenValue !== void 0) {
6587
+ options.token = tokenValue;
6588
+ continue;
6589
+ }
6590
+ const ssoValue = parseLongOptionValue("sso");
6591
+ if (ssoValue !== void 0) {
6592
+ const mapped = parseSsoShortcut(ssoValue);
6593
+ if (!mapped) {
6594
+ console.error(`Unknown value for --sso: ${ssoValue}, expected cookie or ticket`);
6595
+ process.exit(1);
6596
+ }
6597
+ options.authMode = mapped;
6598
+ continue;
6599
+ }
6514
6600
  switch (arg) {
6515
6601
  case "-m":
6602
+ case "-x":
6603
+ case "-X":
6516
6604
  case "--method":
6517
6605
  options.method = args[++i] || "GET";
6518
6606
  break;
@@ -6556,6 +6644,15 @@ function parseRequestOptions(args) {
6556
6644
  case "--token":
6557
6645
  options.token = args[++i];
6558
6646
  break;
6647
+ case "--sso": {
6648
+ const mode = parseSsoShortcut(args[++i]);
6649
+ if (!mode) {
6650
+ console.error("Unknown value for --sso, expected cookie or ticket");
6651
+ process.exit(1);
6652
+ }
6653
+ options.authMode = mode;
6654
+ break;
6655
+ }
6559
6656
  case "-q":
6560
6657
  case "--quiet":
6561
6658
  options.quiet = true;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ali/cli-skills",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
4
4
  "description": "The open agent skills ecosystem",
5
5
  "type": "module",
6
6
  "bin": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ali-skills",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "The open agent skills ecosystem",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,7 +31,7 @@
31
31
  "author": "",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@ali/cli-skills": "^2.0.23"
34
+ "@ali/cli-skills": "^2.0.24"
35
35
  },
36
36
  "bundleDependencies": [
37
37
  "@ali/cli-skills"