ali-skills 0.0.22 → 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.22";
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***");
@@ -5373,6 +5373,25 @@ function openBrowser$1(url) {
5373
5373
  stdio: "ignore"
5374
5374
  });
5375
5375
  }
5376
+ const REDIRECT_STATUS_CODES = new Set([
5377
+ 301,
5378
+ 302,
5379
+ 303,
5380
+ 307,
5381
+ 308
5382
+ ]);
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
+ }
5376
5395
  function detectAuthMode(platformKey, platform, hostname) {
5377
5396
  if (platform.authType === "private_token") return "private_token";
5378
5397
  if (platformKey === "o2") return "auto";
@@ -5561,14 +5580,8 @@ async function sendDirectRequest(targetUrl, platform, token, options) {
5561
5580
  const controller = new AbortController();
5562
5581
  const timeout = options.timeout || 3e4;
5563
5582
  const timeoutId = setTimeout(() => controller.abort(), timeout);
5564
- const response = await fetch(targetUrl, {
5565
- method: options.method.toUpperCase(),
5566
- headers: requestHeaders,
5567
- body: body || void 0,
5568
- signal: controller.signal
5569
- });
5583
+ const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5570
5584
  clearTimeout(timeoutId);
5571
- const responseBody = await response.text();
5572
5585
  if (!options.quiet) {
5573
5586
  const statusColor = response.ok ? GREEN$1 : RED$2;
5574
5587
  console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
@@ -5630,15 +5643,8 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5630
5643
  const controller = new AbortController();
5631
5644
  const timeout = options.timeout || 3e4;
5632
5645
  const timeoutId = setTimeout(() => controller.abort(), timeout);
5633
- const response = await fetch(targetUrl, {
5634
- method: options.method.toUpperCase(),
5635
- headers: requestHeaders,
5636
- body: body || void 0,
5637
- signal: controller.signal,
5638
- redirect: "manual"
5639
- });
5646
+ const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5640
5647
  clearTimeout(timeoutId);
5641
- const responseBody = await response.text();
5642
5648
  if (!options.quiet) {
5643
5649
  const statusColor = response.ok ? GREEN$1 : RED$2;
5644
5650
  console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
@@ -5663,6 +5669,145 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5663
5669
  } else console.log(outputBody);
5664
5670
  if (!response.ok) process.exit(1);
5665
5671
  }
5672
+ async function sendSsoTicketDirectRequest(targetUrl, options) {
5673
+ let ssoTicket = null;
5674
+ try {
5675
+ await ensureLogin();
5676
+ ssoTicket = await ensureSsoTicket();
5677
+ } catch (error) {
5678
+ console.error(`${RED$2}Error: ${error.message}${RESET$2}`);
5679
+ process.exit(1);
5680
+ }
5681
+ if (!ssoTicket) {
5682
+ console.error(`${RED$2}Error: 缺少 SSO_TICKET,无法进行直连请求${RESET$2}`);
5683
+ console.log(`${TEXT$2}建议执行: npx ali-skills login${RESET$2}`);
5684
+ process.exit(1);
5685
+ }
5686
+ const requestHeaders = {
5687
+ "User-Agent": "ali-skills-cli/1.0",
5688
+ SSO_TICKET: ssoTicket
5689
+ };
5690
+ if (options.headers) Object.entries(options.headers).forEach(([key, value]) => {
5691
+ if (key.toLowerCase() !== "sso_ticket") requestHeaders[key] = value;
5692
+ });
5693
+ let body;
5694
+ if (options.body) {
5695
+ body = options.body;
5696
+ if (!requestHeaders["Content-Type"]) requestHeaders["Content-Type"] = "application/json";
5697
+ }
5698
+ if (!options.quiet) {
5699
+ console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5700
+ console.log(`${DIM$2}→ 直接请求 (Header: SSO_TICKET)${RESET$2}`);
5701
+ }
5702
+ const controller = new AbortController();
5703
+ const timeout = options.timeout || 3e4;
5704
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
5705
+ const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5706
+ clearTimeout(timeoutId);
5707
+ if (!options.quiet) {
5708
+ const statusColor = response.ok ? GREEN$1 : RED$2;
5709
+ console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
5710
+ }
5711
+ let outputBody = responseBody;
5712
+ if (!options.raw && options.pretty !== false) try {
5713
+ const json = JSON.parse(responseBody);
5714
+ outputBody = JSON.stringify(json, null, 2);
5715
+ } catch {}
5716
+ if (options.output) {
5717
+ const { writeFileSync } = __require("fs");
5718
+ writeFileSync(options.output, outputBody);
5719
+ console.log(`${GREEN$1}✓ 已保存到 ${options.output}${RESET$2}`);
5720
+ } else console.log(outputBody);
5721
+ if (!response.ok) process.exit(1);
5722
+ }
5723
+ async function sendPlainDirectRequest(targetUrl, options, allowSsoCookieFallback = false) {
5724
+ const requestHeaders = { "User-Agent": "ali-skills-cli/1.0" };
5725
+ if (options.headers) Object.entries(options.headers).forEach(([key, value]) => {
5726
+ requestHeaders[key] = value;
5727
+ });
5728
+ let body;
5729
+ if (options.body) {
5730
+ body = options.body;
5731
+ if (!requestHeaders["Content-Type"]) requestHeaders["Content-Type"] = "application/json";
5732
+ }
5733
+ if (!options.quiet) {
5734
+ console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5735
+ console.log(`${DIM$2}→ 直接请求 (No Auth)${RESET$2}`);
5736
+ }
5737
+ const timeout = options.timeout || 3e4;
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
+ }
5750
+ if (!options.quiet) {
5751
+ const statusColor = response.ok ? GREEN$1 : RED$2;
5752
+ console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
5753
+ if (options.includeHeaders) {
5754
+ console.log();
5755
+ console.log(`${TEXT$2}Response Headers:${RESET$2}`);
5756
+ response.headers.forEach((value, key) => {
5757
+ console.log(` ${key}: ${value}`);
5758
+ });
5759
+ console.log();
5760
+ }
5761
+ }
5762
+ let outputBody = responseBody;
5763
+ if (!options.raw && options.pretty !== false) try {
5764
+ const json = JSON.parse(responseBody);
5765
+ outputBody = JSON.stringify(json, null, 2);
5766
+ } catch {}
5767
+ if (options.output) {
5768
+ const { writeFileSync } = __require("fs");
5769
+ writeFileSync(options.output, outputBody);
5770
+ console.log(`${GREEN$1}✓ 已保存到 ${options.output}${RESET$2}`);
5771
+ } else console.log(outputBody);
5772
+ if (!response.ok) process.exit(1);
5773
+ }
5774
+ async function fetchWithRedirects(initialUrl, method, headers, body, timeout, quiet) {
5775
+ const controller = new AbortController();
5776
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
5777
+ let currentUrl = initialUrl;
5778
+ let redirects = 0;
5779
+ let sawAlibabaLoginRedirect = false;
5780
+ try {
5781
+ while (true) {
5782
+ const response = await fetch(currentUrl, {
5783
+ method,
5784
+ headers,
5785
+ body: body || void 0,
5786
+ signal: controller.signal,
5787
+ redirect: "manual"
5788
+ });
5789
+ if (!REDIRECT_STATUS_CODES.has(response.status)) return {
5790
+ response,
5791
+ responseBody: await response.text(),
5792
+ sawAlibabaLoginRedirect
5793
+ };
5794
+ const location = response.headers.get("location");
5795
+ if (!location) return {
5796
+ response,
5797
+ responseBody: await response.text(),
5798
+ sawAlibabaLoginRedirect
5799
+ };
5800
+ if (redirects >= MAX_REDIRECTS) throw new Error(`重定向次数超过上限(${MAX_REDIRECTS})`);
5801
+ const nextUrl = new URL(location, currentUrl).toString();
5802
+ if (new URL(nextUrl).hostname === "login.alibaba-inc.com") sawAlibabaLoginRedirect = true;
5803
+ redirects += 1;
5804
+ if (!quiet) console.log(`${DIM$2}↪ 重定向 ${redirects}: ${response.status} ${response.statusText} -> ${nextUrl}${RESET$2}`);
5805
+ currentUrl = nextUrl;
5806
+ }
5807
+ } finally {
5808
+ clearTimeout(timeoutId);
5809
+ }
5810
+ }
5666
5811
  async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "gateway") {
5667
5812
  let credentials;
5668
5813
  try {
@@ -5741,45 +5886,96 @@ async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "g
5741
5886
  }
5742
5887
  async function proxyRequest(targetUrl, options) {
5743
5888
  let url;
5889
+ const { normalizedUrl, changed: urlInputNormalized } = normalizeEscapedUrlInput(targetUrl);
5744
5890
  try {
5745
- url = new URL(targetUrl);
5891
+ url = new URL(normalizedUrl);
5746
5892
  } catch {
5747
- console.error(`${RED$2}Error: 无效的 URL "${targetUrl}"${RESET$2}`);
5893
+ console.error(`${RED$2}Error: URL 必须是绝对地址,收到 "${targetUrl}"${RESET$2}`);
5894
+ console.log(`${DIM$2}未传 platform 时,请使用完整 URL(包含协议和域名)${RESET$2}`);
5895
+ console.log(`${DIM$2}示例:${RESET$2}`);
5896
+ console.log(`${DIM$2} npx ali-skills req "https://jarvis.alitrip.com/api/xxx" --auth sso_cookie${RESET$2}`);
5897
+ console.log(`${DIM$2} npx ali-skills req o2 /v1.0/work/apps${RESET$2}`);
5748
5898
  process.exit(1);
5749
5899
  }
5750
5900
  const platformResult = detectPlatformWithKey(url.hostname);
5901
+ const hasExplicitAuthMode = Boolean(options.authMode && options.authMode !== "auto");
5751
5902
  const isAlibabaIncRootDomain = url.hostname.endsWith(".alibaba-inc.com") || url.hostname === "alibaba-inc.com";
5752
- if (!platformResult && !isAlibabaIncRootDomain) {
5753
- console.error(`${RED$2}Error: 无法识别平台 "${url.hostname}"${RESET$2}`);
5754
- console.log(`${DIM$2}支持的平台:${RESET$2}`);
5755
- console.log(`${DIM$2} - code.alibaba-inc.com (GitLab)${RESET$2}`);
5756
- console.log(`${DIM$2} - aliyuque.antfin.com (语雀)${RESET$2}`);
5757
- console.log(`${DIM$2} - o2.alibaba-inc.com${RESET$2}`);
5758
- console.log(`${DIM$2} - aone.alibaba-inc.com${RESET$2}`);
5759
- process.exit(1);
5760
- }
5761
- const platformKey = platformResult?.key || "alibaba-inc";
5903
+ const isKnownPlatform = Boolean(platformResult) || isAlibabaIncRootDomain;
5904
+ const platformKey = platformResult?.key || (isAlibabaIncRootDomain ? "alibaba-inc" : url.hostname);
5762
5905
  const platform = platformResult?.config || {
5763
- name: "Alibaba Inc Domain",
5764
- host: "alibaba-inc.com",
5906
+ name: isAlibabaIncRootDomain ? "Alibaba Inc Domain" : "Custom Host",
5907
+ host: isAlibabaIncRootDomain ? "alibaba-inc.com" : url.hostname,
5765
5908
  authType: "buc_sso_refresh",
5766
5909
  ssoType: "refresh_token"
5767
5910
  };
5768
- if (!options.quiet) console.log(`${DIM$2}平台: ${platform.name}${RESET$2}`);
5769
- const authMode = options.authMode === "auto" || !options.authMode ? detectAuthMode(platformKey, platform, url.hostname) : options.authMode;
5770
- if (!options.quiet && authMode !== "auto") console.log(`${DIM$2}认证方式: ${getAuthModeDescription(authMode)}${RESET$2}`);
5771
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
+ }
5917
+ if (!isKnownPlatform && !hasExplicitAuthMode) {
5918
+ if (!options.quiet) {
5919
+ console.log(`${DIM$2}平台: Custom Host${RESET$2}`);
5920
+ console.log(`${DIM$2}认证方式: Auto (未知平台默认直连,无鉴权)${RESET$2}`);
5921
+ }
5922
+ await sendPlainDirectRequest(normalizedUrl, options, true);
5923
+ return;
5924
+ }
5925
+ if (!options.quiet) console.log(`${DIM$2}平台: ${platform.name}${RESET$2}`);
5926
+ const authMode = options.authMode === "auto" || !options.authMode ? detectAuthMode(platformKey, platform, url.hostname) : options.authMode;
5927
+ if (!options.quiet && authMode !== "auto") console.log(`${DIM$2}认证方式: ${getAuthModeDescription(authMode)}${RESET$2}`);
5928
+ if (hasExplicitAuthMode) {
5929
+ if (platformKey === "o2") {
5930
+ if (authMode !== "auto" && authMode !== "sso_ticket") {
5931
+ console.error(`${RED$2}Error: o2 仅支持 --auth auto 或 --auth sso_ticket${RESET$2}`);
5932
+ process.exit(1);
5933
+ }
5934
+ await sendO2SdkRequest(normalizedUrl, options, authMode === "sso_ticket");
5935
+ return;
5936
+ }
5937
+ switch (authMode) {
5938
+ case "private_token": {
5939
+ let token = getPlatformPrivateToken(platformKey, options.token, targetUrl);
5940
+ if (!token) {
5941
+ token = await promptConfigureToken(platformKey, platform);
5942
+ if (!token) {
5943
+ console.error(`${RED$2}Error: ${platform.name} 需要配置 Private Token 才能访问${RESET$2}`);
5944
+ console.log(`${DIM$2}您可以通过以下方式配置:${RESET$2}`);
5945
+ console.log(`${DIM$2} 【推荐】一次配置,持续使用:${RESET$2}`);
5946
+ console.log(` npx ali-skills login ${platformKey}`);
5947
+ console.log(`${DIM$2} 【临时】请求时传入:${RESET$2}`);
5948
+ console.log(` 环境变量: ALI_SKILLS_${platformKey.toUpperCase()}_TOKEN=<your_token>`);
5949
+ console.log(` 参数: --token <your_token>`);
5950
+ process.exit(1);
5951
+ }
5952
+ }
5953
+ await sendDirectRequest(normalizedUrl, platform, token, options);
5954
+ return;
5955
+ }
5956
+ case "sso_cookie":
5957
+ await sendSsoCookieDirectRequest(normalizedUrl, options);
5958
+ return;
5959
+ case "sso_ticket":
5960
+ await sendSsoTicketDirectRequest(normalizedUrl, options);
5961
+ return;
5962
+ case "gateway":
5963
+ await sendGatewayRequest(normalizedUrl, platformKey, options, "gateway");
5964
+ return;
5965
+ default: break;
5966
+ }
5967
+ }
5772
5968
  if (platformKey === "o2") {
5773
5969
  if (authMode !== "auto" && authMode !== "sso_ticket") {
5774
5970
  console.error(`${RED$2}Error: o2 仅支持 --auth auto 或 --auth sso_ticket${RESET$2}`);
5775
5971
  process.exit(1);
5776
5972
  }
5777
- await sendO2SdkRequest(targetUrl, options, authMode === "sso_ticket");
5973
+ await sendO2SdkRequest(normalizedUrl, options, authMode === "sso_ticket");
5778
5974
  return;
5779
5975
  }
5780
5976
  switch (authMode) {
5781
5977
  case "private_token": {
5782
- let token = getPlatformPrivateToken(platformKey, options.token, targetUrl);
5978
+ let token = getPlatformPrivateToken(platformKey, options.token, normalizedUrl);
5783
5979
  if (!token) {
5784
5980
  token = await promptConfigureToken(platformKey, platform);
5785
5981
  if (!token) {
@@ -5793,19 +5989,19 @@ async function proxyRequest(targetUrl, options) {
5793
5989
  process.exit(1);
5794
5990
  }
5795
5991
  }
5796
- await sendDirectRequest(targetUrl, platform, token, options);
5992
+ await sendDirectRequest(normalizedUrl, platform, token, options);
5797
5993
  break;
5798
5994
  }
5799
5995
  case "sso_ticket":
5800
5996
  case "gateway":
5801
- await sendGatewayRequest(targetUrl, platformKey, options, authMode);
5997
+ await sendGatewayRequest(normalizedUrl, platformKey, options, authMode);
5802
5998
  break;
5803
5999
  case "sso_cookie":
5804
- await sendSsoCookieDirectRequest(targetUrl, options);
6000
+ await sendSsoCookieDirectRequest(normalizedUrl, options);
5805
6001
  break;
5806
6002
  default: if (platform.authType === "private_token") {
5807
- const token = getPlatformPrivateToken(platformKey, options.token, targetUrl);
5808
- 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);
5809
6005
  else {
5810
6006
  console.error(`${RED$2}Error: ${platform.name} 需要配置 Private Token${RESET$2}`);
5811
6007
  console.log(`${DIM$2}您可以通过以下方式配置:${RESET$2}`);
@@ -5816,8 +6012,8 @@ async function proxyRequest(targetUrl, options) {
5816
6012
  console.log(` 参数: --token <your_token>`);
5817
6013
  process.exit(1);
5818
6014
  }
5819
- } else if (isAlibabaIncRootDomain) await sendSsoCookieDirectRequest(targetUrl, options);
5820
- 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");
5821
6017
  }
5822
6018
  } catch (error) {
5823
6019
  if (error instanceof Error) if (error.name === "AbortError") console.error(`${RED$2}Error: 请求超时${RESET$2}`);
@@ -6285,19 +6481,20 @@ ${BOLD}Gateway Commands:${RESET}
6285
6481
  request [platform] <url|path> Send HTTP request (supports platform + path shorthand)
6286
6482
  req [platform] <url|path> Alias for request, recommended
6287
6483
 
6484
+ ${BOLD}Platform Values:${RESET}
6485
+ ${platformKeysForHelp}
6486
+
6288
6487
  ${BOLD}Yuque Commands:${RESET}
6289
6488
  login yuque [group] Configure/switch specified Yuque group directly
6290
6489
  logout yuque [group] [--all] Choose one/many Yuque groups to clear, or clear all
6291
6490
  status yuque [group] [--show|-s] [--pretty] Show Yuque group/all config JSON
6292
6491
 
6293
- ${BOLD}Platform Values:${RESET}
6294
- ${platformKeysForHelp}
6295
-
6296
6492
  ${BOLD}Request Options:${RESET}
6297
6493
  -X, --method <method> HTTP method (default: GET)
6298
6494
  -b, --body <body> Request body (JSON string or @file)
6299
6495
  -h, --header <header> Custom header (can be used multiple times)
6300
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
6301
6498
  --token <token> Explicit token for private_token mode
6302
6499
  -o, --output <file> Save response to file
6303
6500
  -i, --include-headers Include response headers in output
@@ -6306,46 +6503,104 @@ ${BOLD}Request Options:${RESET}
6306
6503
  --raw Raw output without formatting
6307
6504
  -q, --quiet Quiet mode, only output response body
6308
6505
 
6309
- ${BOLD}Environment:${RESET}
6310
- ALI_SKILLS_YUQUE_GROUP Yuque team slug when multiple teams have tokens in config
6311
- O2_API_ENV O2 SDK env override (default online; set pre for pre env)
6312
- ALI_SKILLS_DEBUG_GATEWAY Enable gateway auth debug logs (1/true/on)
6313
-
6314
6506
  ${BOLD}Examples:${RESET}
6315
6507
  ${DIM}$${RESET} ali-skills login
6316
6508
  ${DIM}$${RESET} ali-skills login code
6317
6509
  ${DIM}$${RESET} ali-skills login yuque
6318
- ${DIM}$${RESET} ali-skills login yuque fliggy
6510
+ ${DIM}$${RESET} ali-skills login yuque group
6319
6511
  ${DIM}$${RESET} ali-skills status --all
6512
+ ${DIM}$${RESET} ali-skills status
6320
6513
  ${DIM}$${RESET} ali-skills status code
6321
- ${DIM}$${RESET} ali-skills status -s
6322
- ${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
6323
6518
  ${DIM}$${RESET} ali-skills status code --show
6324
6519
  ${DIM}$${RESET} ali-skills status yuque --show
6325
- ${DIM}$${RESET} ali-skills status yuque fliggy
6326
6520
  ${DIM}$${RESET} ali-skills status yuque fliggy --show
6521
+ ${DIM}$${RESET} ali-skills logout
6327
6522
  ${DIM}$${RESET} ali-skills logout code
6328
6523
  ${DIM}$${RESET} ali-skills logout yuque
6329
6524
  ${DIM}$${RESET} ali-skills logout yuque my-team
6330
6525
  ${DIM}$${RESET} ali-skills logout yuque --all
6331
- ${DIM}$${RESET} ali-skills req o2 /v1.0/work/apps
6332
- ${DIM}$${RESET} ali-skills req o2 /v1.0/work/aone/issues/search -X POST -b '{"keyword":"auth"}'
6333
- ${DIM}$${RESET} ali-skills req o2 /v1.0/work/issues/123 --auth sso_ticket
6334
- ${DIM}$${RESET} ali-skills req https://code.alibaba-inc.com/api/v4/projects -X GET
6335
- ${DIM}$${RESET} ali-skills req https://yuque-api.antfin-inc.com/api/v2/repos -o repos.json
6336
- ${DIM}$${RESET} ali-skills req yuque "/api/v2/search?q=buc&type=doc"
6337
- ${DIM}$${RESET} ali-skills req yuque "/api/v2/search?q=buc&type=doc&scope=fliggyfe-infra"
6338
- ${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
6339
6535
  `);
6340
6536
  }
6341
6537
  function parseRequestOptions(args) {
6342
6538
  let url = "";
6343
6539
  const options = { method: "GET" };
6344
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
+ };
6345
6547
  for (let i = 0; i < args.length; i++) {
6346
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
+ }
6347
6600
  switch (arg) {
6348
6601
  case "-m":
6602
+ case "-x":
6603
+ case "-X":
6349
6604
  case "--method":
6350
6605
  options.method = args[++i] || "GET";
6351
6606
  break;
@@ -6389,6 +6644,15 @@ function parseRequestOptions(args) {
6389
6644
  case "--token":
6390
6645
  options.token = args[++i];
6391
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
+ }
6392
6656
  case "-q":
6393
6657
  case "--quiet":
6394
6658
  options.quiet = true;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ali/cli-skills",
3
- "version": "2.0.22",
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.22",
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.22"
34
+ "@ali/cli-skills": "^2.0.24"
35
35
  },
36
36
  "bundleDependencies": [
37
37
  "@ali/cli-skills"