ali-skills 0.0.26 → 0.0.27

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.
@@ -2340,7 +2340,7 @@ function logSkillParseFailures(failures) {
2340
2340
  if (f.hint) M.message(import_picocolors.default.yellow(` 提示: ${f.hint}`));
2341
2341
  }
2342
2342
  }
2343
- var version$1 = "2.0.27";
2343
+ var version$1 = "2.0.28";
2344
2344
  const isCancelled$1 = (value) => typeof value === "symbol";
2345
2345
  function redactSensitiveText(text) {
2346
2346
  return text.replace(/(https?:\/\/)([^/\s:@]+)(?::([^@/\s]*))?@/gi, "$1").replace(/([?&](?:private_token|access_token|token|api_key|access_key|secret|password)=)[^&\s]+/gi, "$1***");
@@ -5643,6 +5643,12 @@ function getAuthModeDescription(mode) {
5643
5643
  default: return "Auto";
5644
5644
  }
5645
5645
  }
5646
+ function maskCredential(value) {
5647
+ const trimmed = value.trim();
5648
+ if (!trimmed) return "(empty)";
5649
+ if (trimmed.length <= 8) return "******";
5650
+ return `${trimmed.slice(0, 4)}...${trimmed.slice(-4)}`;
5651
+ }
5646
5652
  const O2_CREDENTIALS_BASE64 = "eyJhY2Nlc3NLZXlJZCI6IlNZS2NFNWtrbHhtT1M3WjJYYXRObiIsImFjY2Vzc0tleVNlY3JldCI6IjQ2NGNhYTc0MmNiYTk2NzFkZjM5NzJkYzdhNWI3MmQ1Nzk5ZTc2NTQyYzRiZGFjM2M3YTk5N2QzMDM3YTIyNzAifQ==";
5647
5653
  function getO2Credentials() {
5648
5654
  const accessKeyId = process.env.O2_ACCESS_KEY_ID?.trim();
@@ -5681,8 +5687,14 @@ async function sendO2SdkRequest(targetUrl, options, withSsoTicket) {
5681
5687
  const path = parsed.pathname;
5682
5688
  const query = searchParamsToObject(parsed.searchParams);
5683
5689
  const headers = { ...options.headers ?? {} };
5690
+ let ssoTicketSource = null;
5684
5691
  if (withSsoTicket) {
5685
- const ssoTicket = await ensureSsoTicket();
5692
+ let ssoTicket = options.ssoTicket?.trim() || null;
5693
+ if (ssoTicket) ssoTicketSource = "arg";
5694
+ else {
5695
+ ssoTicket = await ensureSsoTicket();
5696
+ if (ssoTicket) ssoTicketSource = "gateway";
5697
+ }
5686
5698
  if (!ssoTicket) throw new Error("无法获取 SSO_TICKET,请重新登录后重试");
5687
5699
  headers.SSO_TICKET = ssoTicket;
5688
5700
  }
@@ -5707,6 +5719,10 @@ async function sendO2SdkRequest(targetUrl, options, withSsoTicket) {
5707
5719
  if (!options.quiet) {
5708
5720
  console.log(`${DIM$2}${method} ${parsed.toString()}${RESET$2}`);
5709
5721
  console.log(`${DIM$2}→ O2 SDK 直连${withSsoTicket ? " (携带 SSO_TICKET)" : ""}${RESET$2}`);
5722
+ if (withSsoTicket && ssoTicketSource) {
5723
+ const sourceText = ssoTicketSource === "arg" ? "参数传入(--sso-ticket)" : "登录态获取";
5724
+ console.log(`${DIM$2}→ SSO_TICKET 来源: ${sourceText}${RESET$2}`);
5725
+ }
5710
5726
  if (o2Env) console.log(`${DIM$2}→ O2 SDK Env: ${o2Env}${RESET$2}`);
5711
5727
  }
5712
5728
  let responseData;
@@ -5850,8 +5866,10 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5850
5866
  log(`${TEXT$2}请先执行: npx ali-skills login --reauth(刷新 SSO_REFRESH_TOKEN)${RESET$2}`);
5851
5867
  log(`${TEXT$2}刷新后请重新发起当前请求${RESET$2}`);
5852
5868
  };
5853
- let ssoRefreshToken = null;
5854
- try {
5869
+ const explicitSsoCookie = options.ssoCookie?.trim() || "";
5870
+ let ssoRefreshToken = explicitSsoCookie || null;
5871
+ const ssoCookieSource = explicitSsoCookie ? "arg" : "gateway";
5872
+ if (!ssoRefreshToken) try {
5855
5873
  await ensureLogin();
5856
5874
  ssoRefreshToken = await ensureSsoRefreshToken();
5857
5875
  } catch (error) {
@@ -5867,8 +5885,10 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5867
5885
  console.log(`${TEXT$2}建议执行: npx ali-skills login${RESET$2}`);
5868
5886
  process.exit(1);
5869
5887
  }
5870
- const authForRt = readAuth();
5871
- if (authForRt) exitIfSsoRefreshCookieExpired(authForRt, { quiet: options.quiet });
5888
+ if (!explicitSsoCookie) {
5889
+ const authForRt = readAuth();
5890
+ if (authForRt) exitIfSsoRefreshCookieExpired(authForRt, { quiet: options.quiet });
5891
+ }
5872
5892
  const requestHeaders = {
5873
5893
  "User-Agent": "ali-skills-cli/1.0",
5874
5894
  Cookie: `SSO_REFRESH_TOKEN=${ssoRefreshToken}`
@@ -5884,6 +5904,8 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5884
5904
  if (!options.quiet) {
5885
5905
  console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5886
5906
  console.log(`${DIM$2}→ 直接请求 (Cookie: SSO_REFRESH_TOKEN)${RESET$2}`);
5907
+ console.log(`${DIM$2}→ SSO_REFRESH_TOKEN 来源: ${ssoCookieSource === "arg" ? "参数传入(--sso-refresh-token)" : "登录态获取"}${RESET$2}`);
5908
+ if (ssoCookieSource === "arg") console.log(`${DIM$2}→ SSO_REFRESH_TOKEN: ${maskCredential(explicitSsoCookie)}${RESET$2}`);
5887
5909
  }
5888
5910
  const controller = new AbortController();
5889
5911
  const timeout = options.timeout || 3e4;
@@ -5930,8 +5952,10 @@ async function sendSsoCookieDirectRequest(targetUrl, options) {
5930
5952
  if (!response.ok) process.exit(1);
5931
5953
  }
5932
5954
  async function sendSsoTicketDirectRequest(targetUrl, options) {
5933
- let ssoTicket = null;
5934
- try {
5955
+ const explicitSsoTicket = options.ssoTicket?.trim() || "";
5956
+ let ssoTicket = explicitSsoTicket || null;
5957
+ const ssoTicketSource = explicitSsoTicket ? "arg" : "gateway";
5958
+ if (!ssoTicket) try {
5935
5959
  await ensureLogin();
5936
5960
  ssoTicket = await ensureSsoTicket();
5937
5961
  } catch (error) {
@@ -5958,6 +5982,8 @@ async function sendSsoTicketDirectRequest(targetUrl, options) {
5958
5982
  if (!options.quiet) {
5959
5983
  console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
5960
5984
  console.log(`${DIM$2}→ 直接请求 (Header: SSO_TICKET)${RESET$2}`);
5985
+ console.log(`${DIM$2}→ SSO_TICKET 来源: ${ssoTicketSource === "arg" ? "参数传入(--sso-ticket)" : "登录态获取"}${RESET$2}`);
5986
+ if (ssoTicketSource === "arg") console.log(`${DIM$2}→ SSO_TICKET: ${maskCredential(explicitSsoTicket)}${RESET$2}`);
5961
5987
  }
5962
5988
  const controller = new AbortController();
5963
5989
  const timeout = options.timeout || 3e4;
@@ -6038,7 +6064,7 @@ async function fetchWithRedirects(initialUrl, method, headers, body, timeout, qu
6038
6064
  let redirects = 0;
6039
6065
  let sawAlibabaLoginRedirect = false;
6040
6066
  try {
6041
- while (true) {
6067
+ while (redirects <= MAX_REDIRECTS) {
6042
6068
  const response = await fetch(currentUrl, {
6043
6069
  method,
6044
6070
  headers,
@@ -6072,6 +6098,7 @@ async function fetchWithRedirects(initialUrl, method, headers, body, timeout, qu
6072
6098
  if (!quiet) console.log(`${DIM$2}↪ 重定向 ${redirects}: ${response.status} ${response.statusText} -> ${nextUrl}${RESET$2}`);
6073
6099
  currentUrl = nextUrl;
6074
6100
  }
6101
+ throw new Error(`重定向次数超过上限(${MAX_REDIRECTS})`);
6075
6102
  } finally {
6076
6103
  clearTimeout(timeoutId);
6077
6104
  }
@@ -6085,6 +6112,8 @@ async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "g
6085
6112
  process.exit(1);
6086
6113
  }
6087
6114
  const proxyUrl = `${getGatewayUrl()}/api/gateway/proxy`;
6115
+ const explicitSsoCookie = options.ssoCookie?.trim() || "";
6116
+ const explicitSsoTicket = options.ssoTicket?.trim() || "";
6088
6117
  const requestHeaders = {
6089
6118
  Authorization: `Bearer ${credentials.privateToken}`,
6090
6119
  "X-Private-Token": credentials.privateToken,
@@ -6093,6 +6122,8 @@ async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "g
6093
6122
  "X-Platform": platformKey,
6094
6123
  "X-Auth-Mode": authMode
6095
6124
  };
6125
+ if (explicitSsoCookie) requestHeaders["X-SSO-Refresh-Token"] = explicitSsoCookie;
6126
+ if (explicitSsoTicket) requestHeaders["X-SSO-Ticket"] = explicitSsoTicket;
6096
6127
  if (options.headers) Object.entries(options.headers).forEach(([key, value]) => {
6097
6128
  requestHeaders[key] = value;
6098
6129
  });
@@ -6104,6 +6135,14 @@ async function sendGatewayRequest(targetUrl, platformKey, options, authMode = "g
6104
6135
  if (!options.quiet) {
6105
6136
  console.log(`${DIM$2}${options.method.toUpperCase()} ${targetUrl}${RESET$2}`);
6106
6137
  console.log(`${DIM$2}→ Gateway: ${proxyUrl}${RESET$2}`);
6138
+ if (explicitSsoCookie) {
6139
+ console.log(`${DIM$2}→ SSO_REFRESH_TOKEN 来源: 参数传入(--sso-refresh-token)${RESET$2}`);
6140
+ console.log(`${DIM$2}→ SSO_REFRESH_TOKEN: ${maskCredential(explicitSsoCookie)}${RESET$2}`);
6141
+ }
6142
+ if (explicitSsoTicket) {
6143
+ console.log(`${DIM$2}→ SSO_TICKET 来源: 参数传入(--sso-ticket)${RESET$2}`);
6144
+ console.log(`${DIM$2}→ SSO_TICKET: ${maskCredential(explicitSsoTicket)}${RESET$2}`);
6145
+ }
6107
6146
  }
6108
6147
  const controller = new AbortController();
6109
6148
  const timeout = options.timeout || 3e4;
@@ -6752,6 +6791,8 @@ ${BOLD}Request Options:${RESET}
6752
6791
  --auth, --auth-mode <mode> Auth mode: auto/private_token/sso_cookie/sso_ticket
6753
6792
  --sso <cookie|ticket> Shortcut for --auth sso_cookie/sso_ticket
6754
6793
  --token <token> Explicit token for private_token mode
6794
+ --sso-refresh-token <token> Explicit SSO_REFRESH_TOKEN for sso_cookie mode
6795
+ --sso-ticket <ticket> Explicit SSO_TICKET for sso_ticket mode
6755
6796
  -o, --output <file> Save response to file
6756
6797
  -i, --include-headers Include response headers in output
6757
6798
  -t, --timeout <ms> Request timeout (default: 30000)
@@ -6782,8 +6823,10 @@ ${BOLD}Examples:${RESET}
6782
6823
  ${DIM}$${RESET} ali-skills logout yuque --all
6783
6824
  ${DIM}$${RESET} ali-skills req 'https://subdomain.alibaba-inc.com/path?q=v'
6784
6825
  ${DIM}$${RESET} ali-skills req 'https://subdomain.alibaba-inc.com/path?q=v' --auth sso_cookie
6826
+ ${DIM}$${RESET} ali-skills req 'https://subdomain.alibaba-inc.com/path?q=v' --auth sso_cookie --sso-refresh-token '<SSO_REFRESH_TOKEN>'
6785
6827
  ${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'
6786
6828
  ${DIM}$${RESET} ali-skills req 'https://support-buc-sso-ticket-site/path?q=v' --auth sso_ticket
6829
+ ${DIM}$${RESET} ali-skills req 'https://support-buc-sso-ticket-site/path?q=v' --auth sso_ticket --sso-ticket '<SSO_TICKET>'
6787
6830
  ${DIM}$${RESET} ali-skills req code '/api/v3/project?path=clam-ng/clam'
6788
6831
  ${DIM}$${RESET} ali-skills req yuque '/api/v2/repos/fliggyfe-infra/ali-skills-dev/docs/mll9xim6y6lcnvyg'
6789
6832
  ${DIM}$${RESET} ali-skills req yuque '/api/v2/search?q=buc&type=doc&scope=fliggyfe-infra'
@@ -6854,6 +6897,16 @@ function parseRequestOptions(args) {
6854
6897
  options.authMode = mapped;
6855
6898
  continue;
6856
6899
  }
6900
+ const ssoCookieValue = parseLongOptionValue("sso-refresh-token") ?? parseLongOptionValue("sso-cookie");
6901
+ if (ssoCookieValue !== void 0) {
6902
+ options.ssoCookie = ssoCookieValue;
6903
+ continue;
6904
+ }
6905
+ const ssoTicketValue = parseLongOptionValue("sso-ticket");
6906
+ if (ssoTicketValue !== void 0) {
6907
+ options.ssoTicket = ssoTicketValue;
6908
+ continue;
6909
+ }
6857
6910
  switch (arg) {
6858
6911
  case "-m":
6859
6912
  case "-x":
@@ -6910,6 +6963,13 @@ function parseRequestOptions(args) {
6910
6963
  options.authMode = mode;
6911
6964
  break;
6912
6965
  }
6966
+ case "--sso-refresh-token":
6967
+ case "--sso-cookie":
6968
+ options.ssoCookie = args[++i];
6969
+ break;
6970
+ case "--sso-ticket":
6971
+ options.ssoTicket = args[++i];
6972
+ break;
6913
6973
  case "-q":
6914
6974
  case "--quiet":
6915
6975
  options.quiet = true;
@@ -6938,6 +6998,13 @@ function expandRequestShorthand(args) {
6938
6998
  const normalizedPath = pathArg.startsWith("/") ? pathArg : `/${pathArg}`;
6939
6999
  return [`https://${platform.key === "yuque" ? "yuque-api.antfin-inc.com" : platform.config.host}${normalizedPath}`, ...args.slice(2)];
6940
7000
  }
7001
+ function getHostFromUrl(rawUrl) {
7002
+ try {
7003
+ return new URL(rawUrl).hostname;
7004
+ } catch {
7005
+ return "";
7006
+ }
7007
+ }
6941
7008
  function parseStatusArgs(args) {
6942
7009
  const showPrivateTokenFlags = new Set(["--show", "-s"]);
6943
7010
  const positionals = [];
@@ -7077,6 +7144,12 @@ async function runGatewayCommand(args) {
7077
7144
  process.exit(1);
7078
7145
  }
7079
7146
  await proxyRequest(url, options);
7147
+ track({
7148
+ event: "req",
7149
+ source: getHostFromUrl(url),
7150
+ sourceType: options.authMode ?? "auto",
7151
+ query: options.method.toUpperCase()
7152
+ });
7080
7153
  break;
7081
7154
  }
7082
7155
  case "--help":
@@ -7767,6 +7840,12 @@ async function main() {
7767
7840
  process.exit(1);
7768
7841
  }
7769
7842
  await proxyRequest(url, options);
7843
+ track({
7844
+ event: "req",
7845
+ source: getHostFromUrl(url),
7846
+ sourceType: options.authMode ?? "auto",
7847
+ query: options.method.toUpperCase()
7848
+ });
7770
7849
  break;
7771
7850
  }
7772
7851
  case "gateway":
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ali/cli-skills",
3
- "version": "2.0.27",
3
+ "version": "2.0.28",
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.26",
3
+ "version": "0.0.27",
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.27"
34
+ "@ali/cli-skills": "^2.0.28"
35
35
  },
36
36
  "bundleDependencies": [
37
37
  "@ali/cli-skills"