siluzan-cso-cli 1.1.30-beta.1 → 1.1.30-beta.3

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
@@ -54,7 +54,7 @@ siluzan-cso init -d /path/to/skills # 写入自定义目录
54
54
  siluzan-cso init --force # 强制覆盖已存在文件
55
55
  ```
56
56
 
57
- > **注意**:当前为测试版(1.1.30-beta.1),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-cso-cli`。
57
+ > **注意**:当前为测试版(1.1.30-beta.3),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-cso-cli`。
58
58
 
59
59
  | 助手 | 建议 `--ai` |
60
60
  | ----------------------- | ------------------------------------ |
package/dist/index.js CHANGED
@@ -2099,6 +2099,62 @@ function validateBaseUrl(raw) {
2099
2099
  }
2100
2100
  return null;
2101
2101
  }
2102
+ function hasSiluzanAgentCredentials() {
2103
+ const apiKey = process.env.SILUZAN_API_KEY?.trim();
2104
+ const authToken = process.env.SILUZAN_AUTH_TOKEN?.trim();
2105
+ return Boolean(apiKey || authToken);
2106
+ }
2107
+ function isSiluzanAgentEnv() {
2108
+ const raw = process.env.IS_SILUZAN_AGENT_ENV?.trim().toLowerCase();
2109
+ return raw === "true" || raw === "1";
2110
+ }
2111
+ function skipAuthSetupInAgentEnv(commandLabel) {
2112
+ if (!isSiluzanAgentEnv()) return false;
2113
+ if (hasSiluzanAgentCredentials()) {
2114
+ console.log(
2115
+ `
2116
+ \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\uFF0C\u51ED\u636E\u5DF2\u7531\u6C99\u7BB1\u6CE8\u5165\uFF0C\u65E0\u9700\u6267\u884C ${commandLabel}\u3002
2117
+ `
2118
+ );
2119
+ } else {
2120
+ console.log(
2121
+ `
2122
+ \u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\u3002
2123
+ ${commandLabel} \u5DF2\u8DF3\u8FC7\uFF1B\u8BF7\u7531 Agent \u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY \u6216 SILUZAN_AUTH_TOKEN\u3002
2124
+ `
2125
+ );
2126
+ }
2127
+ return true;
2128
+ }
2129
+ function trimOrUndefined(value) {
2130
+ const trimmed = value?.trim();
2131
+ return trimmed ? trimmed : void 0;
2132
+ }
2133
+ function resolveAgentEnvCredentials() {
2134
+ const envToken = trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN);
2135
+ if (envToken) return { authToken: envToken, apiKey: void 0 };
2136
+ const envApiKey = trimOrUndefined(process.env.SILUZAN_API_KEY);
2137
+ if (envApiKey) return { authToken: "", apiKey: envApiKey };
2138
+ return { authToken: "", apiKey: void 0 };
2139
+ }
2140
+ function resolveSiluzanCredentials(opts) {
2141
+ if (isSiluzanAgentEnv()) {
2142
+ return resolveAgentEnvCredentials();
2143
+ }
2144
+ const apiKey = trimOrUndefined(process.env.SILUZAN_API_KEY) ?? trimOrUndefined(opts.configApiKey);
2145
+ const authToken = trimOrUndefined(opts.tokenArg) ?? trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN) ?? trimOrUndefined(opts.configAuthToken) ?? "";
2146
+ return { authToken, apiKey };
2147
+ }
2148
+ function resolveRequestAuth(config) {
2149
+ if (isSiluzanAgentEnv()) {
2150
+ return resolveAgentEnvCredentials();
2151
+ }
2152
+ return { authToken: config.authToken, apiKey: config.apiKey };
2153
+ }
2154
+ function buildSiluzanAuthHeaders(config) {
2155
+ const auth = resolveRequestAuth(config);
2156
+ return auth.apiKey ? { "x-api-key": auth.apiKey } : { Authorization: `Bearer ${auth.authToken}` };
2157
+ }
2102
2158
  var DEFAULT_TIMEOUT_MS = 10 * 60 * 1e3;
2103
2159
  var MAX_RESPONSE_BYTES = 50 * 1024 * 1024;
2104
2160
  var httpsAgent = new https.Agent({
@@ -2261,15 +2317,17 @@ function redactSensitive(input) {
2261
2317
  );
2262
2318
  return output;
2263
2319
  }
2320
+ function buildAuthHeaders(config) {
2321
+ return buildSiluzanAuthHeaders(config);
2322
+ }
2264
2323
  async function apiFetch(url, config, options = {}, verbose = false) {
2265
2324
  const method = options.method ?? "GET";
2266
- const authHeaders = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
2267
2325
  const reqHeaders = {
2268
2326
  "Content-Type": "application/json",
2269
2327
  "Accept-Language": "zh-CN",
2270
2328
  // 声明支持 gzip/deflate/br;服务端不支持则按 identity 返回,rawRequest 会原样收取
2271
2329
  "Accept-Encoding": "gzip, deflate, br",
2272
- ...authHeaders,
2330
+ ...buildAuthHeaders(config),
2273
2331
  // dataPermission 仅 TSO 使用;CSO 未设置时为空字符串,服务端忽略该头
2274
2332
  Datapermission: config.dataPermission ?? "",
2275
2333
  ...options.headers ?? {}
@@ -2799,6 +2857,12 @@ function installProcessHandlers() {
2799
2857
  });
2800
2858
  }
2801
2859
  function printAuthMissingHelp(binName) {
2860
+ if (isSiluzanAgentEnv()) {
2861
+ console.error(
2862
+ "\n\u274C Siluzan Agent \u73AF\u5883\u4E2D\u672A\u627E\u5230\u8BA4\u8BC1\u51ED\u636E\u3002\n\nAgent \u6C99\u7BB1\u5E94\u901A\u8FC7\u73AF\u5883\u53D8\u91CF\u6CE8\u5165\u4EE5\u4E0B\u4EFB\u610F\u4E00\u79CD\uFF08\u65E0\u9700 login\uFF09\uFF1A\n SILUZAN_API_KEY=<YOUR_API_KEY>\n SILUZAN_AUTH_TOKEN=<YOUR_TOKEN>\n\n\u8BF7\u68C0\u67E5 Agent \u8FD0\u884C\u65F6\u662F\u5426\u5DF2\u8BBE\u7F6E IS_SILUZAN_AGENT_ENV=true \u5E76\u5B8C\u6210\u51ED\u636E\u6CE8\u5165\u3002\n"
2863
+ );
2864
+ process.exit(1);
2865
+ }
2802
2866
  console.error(
2803
2867
  `
2804
2868
  \u274C \u672A\u627E\u5230\u8BA4\u8BC1\u51ED\u636E\u3002\u8BF7\u9009\u62E9\u4EE5\u4E0B\u4EFB\u610F\u4E00\u79CD\u65B9\u5F0F\uFF1A
@@ -2907,7 +2971,7 @@ function parseMeResponse(text) {
2907
2971
  async function fetchSiluzanCurrentUser(apiBase, config) {
2908
2972
  const mainOrigin = deriveMainApiOrigin(apiBase);
2909
2973
  const meUrl = `${mainOrigin.replace(/\/$/, "")}/query/account/me`;
2910
- const authHeaders = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
2974
+ const authHeaders = buildSiluzanAuthHeaders(config);
2911
2975
  try {
2912
2976
  const res = await rawRequest(meUrl, {
2913
2977
  method: "GET",
@@ -3398,6 +3462,7 @@ function resolveSsoCsoBase() {
3398
3462
  return { ssoBaseUrl, csoBaseUrl };
3399
3463
  }
3400
3464
  async function runSendLoginCode(opts) {
3465
+ if (skipAuthSetupInAgentEnv("siluzan-cso send-login-code")) return;
3401
3466
  const phone = validateAndNormalizePhone(opts.phone);
3402
3467
  const { ssoBaseUrl } = resolveSsoCsoBase();
3403
3468
  console.log("\n\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
@@ -3511,6 +3576,7 @@ async function runPhoneLogin(opts) {
3511
3576
  }
3512
3577
  }
3513
3578
  async function runLogin(opts = {}) {
3579
+ if (skipAuthSetupInAgentEnv("siluzan-cso login")) return;
3514
3580
  if (opts.token !== void 0) {
3515
3581
  const token = opts.token.trim();
3516
3582
  if (!token) {
@@ -3736,8 +3802,11 @@ async function runUpdate(options) {
3736
3802
  // src/utils/auth.ts
3737
3803
  function loadConfig(tokenArg) {
3738
3804
  const shared = readSharedConfig();
3739
- const apiKey = process.env.SILUZAN_API_KEY ?? (shared.apiKey ? shared.apiKey : void 0);
3740
- const authToken = tokenArg ?? process.env.SILUZAN_AUTH_TOKEN ?? shared.authToken ?? "";
3805
+ const { authToken, apiKey } = resolveSiluzanCredentials({
3806
+ tokenArg,
3807
+ configApiKey: shared.apiKey,
3808
+ configAuthToken: shared.authToken
3809
+ });
3741
3810
  if (!apiKey && !authToken) {
3742
3811
  printAuthMissingHelp("siluzan-cso");
3743
3812
  }
@@ -8090,11 +8159,20 @@ async function runRagList(options) {
8090
8159
  import * as fs16 from "fs";
8091
8160
  function cmdConfigShow() {
8092
8161
  const shared = readSharedConfig();
8162
+ const { authToken: effectiveAuthToken, apiKey: effectiveApiKeyRaw } = resolveSiluzanCredentials({
8163
+ configApiKey: shared.apiKey,
8164
+ configAuthToken: shared.authToken
8165
+ });
8166
+ const effectiveApiKey = effectiveApiKeyRaw ?? "";
8093
8167
  const envApiKey = process.env.SILUZAN_API_KEY;
8094
8168
  const envAuthToken = process.env.SILUZAN_AUTH_TOKEN;
8095
- const effectiveApiKey = envApiKey ?? shared.apiKey ?? "";
8096
- const effectiveAuthToken = envAuthToken ?? shared.authToken ?? "";
8097
8169
  if (!effectiveApiKey && !effectiveAuthToken) {
8170
+ if (isSiluzanAgentEnv()) {
8171
+ console.log(
8172
+ "\nSiluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\u3002\n\u51ED\u636E\u5E94\u7531\u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY \u6216 SILUZAN_AUTH_TOKEN\uFF0C\u65E0\u9700 login\u3002\n"
8173
+ );
8174
+ return;
8175
+ }
8098
8176
  console.log(
8099
8177
  `
8100
8178
  \u5C1A\u672A\u914D\u7F6E\u51ED\u636E\u3002
@@ -8115,15 +8193,18 @@ function cmdConfigShow() {
8115
8193
  const apiBaseUrl = process.env.SILUZAN_CSO_API_BASE ?? DEFAULT_API_BASE;
8116
8194
  const csoBaseUrl = DEFAULT_CSO_BASE;
8117
8195
  console.log("\n\u5F53\u524D\u914D\u7F6E\uFF1A");
8196
+ if (isSiluzanAgentEnv()) {
8197
+ console.log(" agentEnv : IS_SILUZAN_AGENT_ENV=true \u2190 Siluzan Agent \u6C99\u7BB1");
8198
+ }
8118
8199
  console.log(` apiBaseUrl : ${apiBaseUrl}`);
8119
8200
  console.log(` csoBaseUrl : ${csoBaseUrl}`);
8120
8201
  if (effectiveApiKey) {
8121
- const src = envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
8202
+ const src = isSiluzanAgentEnv() ? "env:SILUZAN_API_KEY (agent)" : envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
8122
8203
  const active = " \u2190 \u5F53\u524D\u751F\u6548\uFF08X-Api-Key \u9274\u6743\uFF09";
8123
8204
  console.log(` apiKey : ${maskSecret(effectiveApiKey)} [${src}]${active}`);
8124
8205
  }
8125
8206
  if (effectiveAuthToken) {
8126
- const src = envAuthToken ? "env:SILUZAN_AUTH_TOKEN" : "config.json";
8207
+ const src = isSiluzanAgentEnv() ? "env:SILUZAN_AUTH_TOKEN (agent)" : envAuthToken ? "env:SILUZAN_AUTH_TOKEN" : "config.json";
8127
8208
  const note = effectiveApiKey ? " \uFF08\u5DF2\u88AB apiKey \u8986\u76D6\uFF09" : " \u2190 \u5F53\u524D\u751F\u6548\uFF08Bearer \u9274\u6743\uFF09";
8128
8209
  console.log(` authToken : ${maskSecret(effectiveAuthToken)} [${src}]${note}`);
8129
8210
  }
@@ -8138,6 +8219,7 @@ function cmdConfigShow() {
8138
8219
  console.log();
8139
8220
  }
8140
8221
  function cmdConfigSet(opts) {
8222
+ if (skipAuthSetupInAgentEnv("siluzan-cso config set")) return;
8141
8223
  if (!opts.apiKey && !opts.token) {
8142
8224
  console.error("\n\u274C \u8BF7\u81F3\u5C11\u63D0\u4F9B\u4E00\u4E2A\u8981\u66F4\u65B0\u7684\u914D\u7F6E\u9879\uFF08--api-key \u6216 --token\uFF09\n");
8143
8225
  process.exit(1);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "slug": "siluzan-cso",
3
- "version": "1.1.30-beta.1",
4
- "publishedAt": 1782285640143,
3
+ "version": "1.1.30-beta.3",
4
+ "publishedAt": 1782294306585,
5
5
  "homepage": "https://www.siluzan.com",
6
6
  "source": "https://dev.azure.com/jack4it/Sammamish/_git/siluzan-skill",
7
7
  "requiredBinaries": [
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
9
9
  # -- Package info (injected at build time) ------------------------------------
10
10
  $PKG_NAME = 'siluzan-cso-cli'
11
11
  # PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
12
- $PKG_VERSION = '1.1.30-beta.1'
12
+ $PKG_VERSION = '1.1.30-beta.3'
13
13
  $CLI_BIN = 'siluzan-cso'
14
14
  $SKILL_LABEL = 'Siluzan CSO'
15
15
  $INSTALL_CMD = 'npm install -g siluzan-cso-cli@beta'
@@ -9,7 +9,7 @@ set -euo pipefail
9
9
  # -- Package info (injected at build time) ------------------------------------
10
10
  readonly PKG_NAME="siluzan-cso-cli"
11
11
  # PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
12
- readonly PKG_VERSION="1.1.30-beta.1"
12
+ readonly PKG_VERSION="1.1.30-beta.3"
13
13
  readonly CLI_BIN="siluzan-cso"
14
14
  readonly SKILL_LABEL="Siluzan CSO"
15
15
  readonly INSTALL_CMD="npm install -g siluzan-cso-cli@beta"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siluzan-cso-cli",
3
- "version": "1.1.30-beta.1",
3
+ "version": "1.1.30-beta.3",
4
4
  "description": "Siluzan platform AI Skill CLI — multi-platform content publishing (video/image-text) for Cursor, Claude Code, and OpenClaw.",
5
5
  "keywords": [
6
6
  "ai-skill",