ali-skills 0.0.22 → 0.0.23

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.23";
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,14 @@ 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;
5376
5384
  function detectAuthMode(platformKey, platform, hostname) {
5377
5385
  if (platform.authType === "private_token") return "private_token";
5378
5386
  if (platformKey === "o2") return "auto";
@@ -5561,14 +5569,8 @@ async function sendDirectRequest(targetUrl, platform, token, options) {
5561
5569
  const controller = new AbortController();
5562
5570
  const timeout = options.timeout || 3e4;
5563
5571
  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
- });
5572
+ const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5570
5573
  clearTimeout(timeoutId);
5571
- const responseBody = await response.text();
5572
5574
  if (!options.quiet) {
5573
5575
  const statusColor = response.ok ? GREEN$1 : RED$2;
5574
5576
  console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
@@ -5630,15 +5632,8 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5630
5632
  const controller = new AbortController();
5631
5633
  const timeout = options.timeout || 3e4;
5632
5634
  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
- });
5635
+ const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5640
5636
  clearTimeout(timeoutId);
5641
- const responseBody = await response.text();
5642
5637
  if (!options.quiet) {
5643
5638
  const statusColor = response.ok ? GREEN$1 : RED$2;
5644
5639
  console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
@@ -5663,6 +5658,133 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5663
5658
  } else console.log(outputBody);
5664
5659
  if (!response.ok) process.exit(1);
5665
5660
  }
5661
+ async function sendSsoTicketDirectRequest(targetUrl, options) {
5662
+ let ssoTicket = null;
5663
+ try {
5664
+ await ensureLogin();
5665
+ ssoTicket = await ensureSsoTicket();
5666
+ } catch (error) {
5667
+ console.error(`${RED$2}Error: ${error.message}${RESET$2}`);
5668
+ process.exit(1);
5669
+ }
5670
+ if (!ssoTicket) {
5671
+ console.error(`${RED$2}Error: 缺少 SSO_TICKET,无法进行直连请求${RESET$2}`);
5672
+ console.log(`${TEXT$2}建议执行: npx ali-skills login${RESET$2}`);
5673
+ process.exit(1);
5674
+ }
5675
+ const requestHeaders = {
5676
+ "User-Agent": "ali-skills-cli/1.0",
5677
+ SSO_TICKET: ssoTicket
5678
+ };
5679
+ if (options.headers) Object.entries(options.headers).forEach(([key, value]) => {
5680
+ if (key.toLowerCase() !== "sso_ticket") requestHeaders[key] = value;
5681
+ });
5682
+ let body;
5683
+ if (options.body) {
5684
+ body = options.body;
5685
+ if (!requestHeaders["Content-Type"]) requestHeaders["Content-Type"] = "application/json";
5686
+ }
5687
+ if (!options.quiet) {
5688
+ console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5689
+ console.log(`${DIM$2}→ 直接请求 (Header: SSO_TICKET)${RESET$2}`);
5690
+ }
5691
+ const controller = new AbortController();
5692
+ const timeout = options.timeout || 3e4;
5693
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
5694
+ const { response, responseBody } = await fetchWithRedirects(targetUrl, options.method.toUpperCase(), requestHeaders, body, timeout, options.quiet);
5695
+ clearTimeout(timeoutId);
5696
+ if (!options.quiet) {
5697
+ const statusColor = response.ok ? GREEN$1 : RED$2;
5698
+ console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
5699
+ }
5700
+ let outputBody = responseBody;
5701
+ if (!options.raw && options.pretty !== false) try {
5702
+ const json = JSON.parse(responseBody);
5703
+ outputBody = JSON.stringify(json, null, 2);
5704
+ } catch {}
5705
+ if (options.output) {
5706
+ const { writeFileSync } = __require("fs");
5707
+ writeFileSync(options.output, outputBody);
5708
+ console.log(`${GREEN$1}✓ 已保存到 ${options.output}${RESET$2}`);
5709
+ } else console.log(outputBody);
5710
+ if (!response.ok) process.exit(1);
5711
+ }
5712
+ async function sendPlainDirectRequest(targetUrl, options) {
5713
+ const requestHeaders = { "User-Agent": "ali-skills-cli/1.0" };
5714
+ if (options.headers) Object.entries(options.headers).forEach(([key, value]) => {
5715
+ requestHeaders[key] = value;
5716
+ });
5717
+ let body;
5718
+ if (options.body) {
5719
+ body = options.body;
5720
+ if (!requestHeaders["Content-Type"]) requestHeaders["Content-Type"] = "application/json";
5721
+ }
5722
+ if (!options.quiet) {
5723
+ console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5724
+ console.log(`${DIM$2}→ 直接请求 (No Auth)${RESET$2}`);
5725
+ }
5726
+ const controller = new AbortController();
5727
+ 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);
5731
+ if (!options.quiet) {
5732
+ const statusColor = response.ok ? GREEN$1 : RED$2;
5733
+ console.log(`${statusColor}${response.status} ${response.statusText}${RESET$2}`);
5734
+ if (options.includeHeaders) {
5735
+ console.log();
5736
+ console.log(`${TEXT$2}Response Headers:${RESET$2}`);
5737
+ response.headers.forEach((value, key) => {
5738
+ console.log(` ${key}: ${value}`);
5739
+ });
5740
+ console.log();
5741
+ }
5742
+ }
5743
+ let outputBody = responseBody;
5744
+ if (!options.raw && options.pretty !== false) try {
5745
+ const json = JSON.parse(responseBody);
5746
+ outputBody = JSON.stringify(json, null, 2);
5747
+ } catch {}
5748
+ if (options.output) {
5749
+ const { writeFileSync } = __require("fs");
5750
+ writeFileSync(options.output, outputBody);
5751
+ console.log(`${GREEN$1}✓ 已保存到 ${options.output}${RESET$2}`);
5752
+ } else console.log(outputBody);
5753
+ if (!response.ok) process.exit(1);
5754
+ }
5755
+ async function fetchWithRedirects(initialUrl, method, headers, body, timeout, quiet) {
5756
+ const controller = new AbortController();
5757
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
5758
+ let currentUrl = initialUrl;
5759
+ let redirects = 0;
5760
+ try {
5761
+ while (true) {
5762
+ const response = await fetch(currentUrl, {
5763
+ method,
5764
+ headers,
5765
+ body: body || void 0,
5766
+ signal: controller.signal,
5767
+ redirect: "manual"
5768
+ });
5769
+ if (!REDIRECT_STATUS_CODES.has(response.status)) return {
5770
+ response,
5771
+ responseBody: await response.text()
5772
+ };
5773
+ const location = response.headers.get("location");
5774
+ if (!location) return {
5775
+ response,
5776
+ responseBody: await response.text()
5777
+ };
5778
+ if (redirects >= MAX_REDIRECTS) throw new Error(`重定向次数超过上限(${MAX_REDIRECTS})`);
5779
+ const nextUrl = new URL(location, currentUrl).toString();
5780
+ redirects += 1;
5781
+ if (!quiet) console.log(`${DIM$2}↪ 重定向 ${redirects}: ${response.status} ${response.statusText} -> ${nextUrl}${RESET$2}`);
5782
+ currentUrl = nextUrl;
5783
+ }
5784
+ } finally {
5785
+ clearTimeout(timeoutId);
5786
+ }
5787
+ }
5666
5788
  async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "gateway") {
5667
5789
  let credentials;
5668
5790
  try {
@@ -5744,31 +5866,76 @@ async function proxyRequest(targetUrl, options) {
5744
5866
  try {
5745
5867
  url = new URL(targetUrl);
5746
5868
  } catch {
5747
- console.error(`${RED$2}Error: 无效的 URL "${targetUrl}"${RESET$2}`);
5869
+ console.error(`${RED$2}Error: URL 必须是绝对地址,收到 "${targetUrl}"${RESET$2}`);
5870
+ console.log(`${DIM$2}未传 platform 时,请使用完整 URL(包含协议和域名)${RESET$2}`);
5871
+ console.log(`${DIM$2}示例:${RESET$2}`);
5872
+ console.log(`${DIM$2} npx ali-skills req "https://jarvis.alitrip.com/api/xxx" --auth sso_cookie${RESET$2}`);
5873
+ console.log(`${DIM$2} npx ali-skills req o2 /v1.0/work/apps${RESET$2}`);
5748
5874
  process.exit(1);
5749
5875
  }
5750
5876
  const platformResult = detectPlatformWithKey(url.hostname);
5877
+ const hasExplicitAuthMode = Boolean(options.authMode && options.authMode !== "auto");
5751
5878
  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";
5879
+ const isKnownPlatform = Boolean(platformResult) || isAlibabaIncRootDomain;
5880
+ const platformKey = platformResult?.key || (isAlibabaIncRootDomain ? "alibaba-inc" : url.hostname);
5762
5881
  const platform = platformResult?.config || {
5763
- name: "Alibaba Inc Domain",
5764
- host: "alibaba-inc.com",
5882
+ name: isAlibabaIncRootDomain ? "Alibaba Inc Domain" : "Custom Host",
5883
+ host: isAlibabaIncRootDomain ? "alibaba-inc.com" : url.hostname,
5765
5884
  authType: "buc_sso_refresh",
5766
5885
  ssoType: "refresh_token"
5767
5886
  };
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
5887
  try {
5888
+ if (!isKnownPlatform && !hasExplicitAuthMode) {
5889
+ if (!options.quiet) {
5890
+ console.log(`${DIM$2}平台: Custom Host${RESET$2}`);
5891
+ console.log(`${DIM$2}认证方式: Auto (未知平台默认直连,无鉴权)${RESET$2}`);
5892
+ }
5893
+ await sendPlainDirectRequest(targetUrl, options);
5894
+ return;
5895
+ }
5896
+ if (!options.quiet) console.log(`${DIM$2}平台: ${platform.name}${RESET$2}`);
5897
+ const authMode = options.authMode === "auto" || !options.authMode ? detectAuthMode(platformKey, platform, url.hostname) : options.authMode;
5898
+ if (!options.quiet && authMode !== "auto") console.log(`${DIM$2}认证方式: ${getAuthModeDescription(authMode)}${RESET$2}`);
5899
+ if (hasExplicitAuthMode) {
5900
+ if (platformKey === "o2") {
5901
+ if (authMode !== "auto" && authMode !== "sso_ticket") {
5902
+ console.error(`${RED$2}Error: o2 仅支持 --auth auto 或 --auth sso_ticket${RESET$2}`);
5903
+ process.exit(1);
5904
+ }
5905
+ await sendO2SdkRequest(targetUrl, options, authMode === "sso_ticket");
5906
+ return;
5907
+ }
5908
+ switch (authMode) {
5909
+ case "private_token": {
5910
+ let token = getPlatformPrivateToken(platformKey, options.token, targetUrl);
5911
+ if (!token) {
5912
+ token = await promptConfigureToken(platformKey, platform);
5913
+ if (!token) {
5914
+ console.error(`${RED$2}Error: ${platform.name} 需要配置 Private Token 才能访问${RESET$2}`);
5915
+ console.log(`${DIM$2}您可以通过以下方式配置:${RESET$2}`);
5916
+ console.log(`${DIM$2} 【推荐】一次配置,持续使用:${RESET$2}`);
5917
+ console.log(` npx ali-skills login ${platformKey}`);
5918
+ console.log(`${DIM$2} 【临时】请求时传入:${RESET$2}`);
5919
+ console.log(` 环境变量: ALI_SKILLS_${platformKey.toUpperCase()}_TOKEN=<your_token>`);
5920
+ console.log(` 参数: --token <your_token>`);
5921
+ process.exit(1);
5922
+ }
5923
+ }
5924
+ await sendDirectRequest(targetUrl, platform, token, options);
5925
+ return;
5926
+ }
5927
+ case "sso_cookie":
5928
+ await sendSsoCookieDirectRequest(targetUrl, options);
5929
+ return;
5930
+ case "sso_ticket":
5931
+ await sendSsoTicketDirectRequest(targetUrl, options);
5932
+ return;
5933
+ case "gateway":
5934
+ await sendGatewayRequest(targetUrl, platformKey, options, "gateway");
5935
+ return;
5936
+ default: break;
5937
+ }
5938
+ }
5772
5939
  if (platformKey === "o2") {
5773
5940
  if (authMode !== "auto" && authMode !== "sso_ticket") {
5774
5941
  console.error(`${RED$2}Error: o2 仅支持 --auth auto 或 --auth sso_ticket${RESET$2}`);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ali/cli-skills",
3
- "version": "2.0.22",
3
+ "version": "2.0.23",
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.23",
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.23"
35
35
  },
36
36
  "bundleDependencies": [
37
37
  "@ali/cli-skills"