siluzan-tso-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 +1 -1
- package/dist/index.js +94 -13
- package/dist/skill/_meta.json +2 -2
- package/dist/skill/scripts/install.ps1 +8 -5
- package/dist/skill/scripts/install.sh +8 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ siluzan-tso init -d /path/to/skills # 写入自定义目录
|
|
|
51
51
|
siluzan-tso init --force # 强制覆盖已存在文件
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
> **注意**:当前为测试版(1.1.30-beta.
|
|
54
|
+
> **注意**:当前为测试版(1.1.30-beta.3),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
|
|
55
55
|
|
|
56
56
|
| 助手 | 建议 `--ai` |
|
|
57
57
|
| ----------------------- | ------------------------------------ |
|
package/dist/index.js
CHANGED
|
@@ -2119,6 +2119,62 @@ function validateBaseUrl(raw) {
|
|
|
2119
2119
|
}
|
|
2120
2120
|
return null;
|
|
2121
2121
|
}
|
|
2122
|
+
function hasSiluzanAgentCredentials() {
|
|
2123
|
+
const apiKey = process.env.SILUZAN_API_KEY?.trim();
|
|
2124
|
+
const authToken = process.env.SILUZAN_AUTH_TOKEN?.trim();
|
|
2125
|
+
return Boolean(apiKey || authToken);
|
|
2126
|
+
}
|
|
2127
|
+
function isSiluzanAgentEnv() {
|
|
2128
|
+
const raw = process.env.IS_SILUZAN_AGENT_ENV?.trim().toLowerCase();
|
|
2129
|
+
return raw === "true" || raw === "1";
|
|
2130
|
+
}
|
|
2131
|
+
function skipAuthSetupInAgentEnv(commandLabel) {
|
|
2132
|
+
if (!isSiluzanAgentEnv()) return false;
|
|
2133
|
+
if (hasSiluzanAgentCredentials()) {
|
|
2134
|
+
console.log(
|
|
2135
|
+
`
|
|
2136
|
+
\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
|
|
2137
|
+
`
|
|
2138
|
+
);
|
|
2139
|
+
} else {
|
|
2140
|
+
console.log(
|
|
2141
|
+
`
|
|
2142
|
+
\u2139\uFE0F \u68C0\u6D4B\u5230 Siluzan Agent \u73AF\u5883\uFF08IS_SILUZAN_AGENT_ENV=true\uFF09\u3002
|
|
2143
|
+
${commandLabel} \u5DF2\u8DF3\u8FC7\uFF1B\u8BF7\u7531 Agent \u6C99\u7BB1\u6CE8\u5165 SILUZAN_API_KEY \u6216 SILUZAN_AUTH_TOKEN\u3002
|
|
2144
|
+
`
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
return true;
|
|
2148
|
+
}
|
|
2149
|
+
function trimOrUndefined(value) {
|
|
2150
|
+
const trimmed = value?.trim();
|
|
2151
|
+
return trimmed ? trimmed : void 0;
|
|
2152
|
+
}
|
|
2153
|
+
function resolveAgentEnvCredentials() {
|
|
2154
|
+
const envToken = trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN);
|
|
2155
|
+
if (envToken) return { authToken: envToken, apiKey: void 0 };
|
|
2156
|
+
const envApiKey = trimOrUndefined(process.env.SILUZAN_API_KEY);
|
|
2157
|
+
if (envApiKey) return { authToken: "", apiKey: envApiKey };
|
|
2158
|
+
return { authToken: "", apiKey: void 0 };
|
|
2159
|
+
}
|
|
2160
|
+
function resolveSiluzanCredentials(opts) {
|
|
2161
|
+
if (isSiluzanAgentEnv()) {
|
|
2162
|
+
return resolveAgentEnvCredentials();
|
|
2163
|
+
}
|
|
2164
|
+
const apiKey = trimOrUndefined(process.env.SILUZAN_API_KEY) ?? trimOrUndefined(opts.configApiKey);
|
|
2165
|
+
const authToken = trimOrUndefined(opts.tokenArg) ?? trimOrUndefined(process.env.SILUZAN_AUTH_TOKEN) ?? trimOrUndefined(opts.configAuthToken) ?? "";
|
|
2166
|
+
return { authToken, apiKey };
|
|
2167
|
+
}
|
|
2168
|
+
function resolveRequestAuth(config) {
|
|
2169
|
+
if (isSiluzanAgentEnv()) {
|
|
2170
|
+
return resolveAgentEnvCredentials();
|
|
2171
|
+
}
|
|
2172
|
+
return { authToken: config.authToken, apiKey: config.apiKey };
|
|
2173
|
+
}
|
|
2174
|
+
function buildSiluzanAuthHeaders(config) {
|
|
2175
|
+
const auth = resolveRequestAuth(config);
|
|
2176
|
+
return auth.apiKey ? { "x-api-key": auth.apiKey } : { Authorization: `Bearer ${auth.authToken}` };
|
|
2177
|
+
}
|
|
2122
2178
|
function isPerfEnabled() {
|
|
2123
2179
|
const v = process.env.SILUZAN_HTTP_PERF;
|
|
2124
2180
|
return v === "1" || v === "true";
|
|
@@ -2264,15 +2320,17 @@ function redactSensitive(input) {
|
|
|
2264
2320
|
);
|
|
2265
2321
|
return output;
|
|
2266
2322
|
}
|
|
2323
|
+
function buildAuthHeaders(config) {
|
|
2324
|
+
return buildSiluzanAuthHeaders(config);
|
|
2325
|
+
}
|
|
2267
2326
|
async function apiFetch(url, config, options = {}, verbose = false) {
|
|
2268
2327
|
const method = options.method ?? "GET";
|
|
2269
|
-
const authHeaders2 = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
|
|
2270
2328
|
const reqHeaders = {
|
|
2271
2329
|
"Content-Type": "application/json",
|
|
2272
2330
|
"Accept-Language": "zh-CN",
|
|
2273
2331
|
// 声明支持 gzip/deflate/br;服务端不支持则按 identity 返回,rawRequest 会原样收取
|
|
2274
2332
|
"Accept-Encoding": "gzip, deflate, br",
|
|
2275
|
-
...
|
|
2333
|
+
...buildAuthHeaders(config),
|
|
2276
2334
|
// dataPermission 仅 TSO 使用;CSO 未设置时为空字符串,服务端忽略该头
|
|
2277
2335
|
Datapermission: config.dataPermission ?? "",
|
|
2278
2336
|
...options.headers ?? {}
|
|
@@ -2300,12 +2358,11 @@ async function apiFetch(url, config, options = {}, verbose = false) {
|
|
|
2300
2358
|
}
|
|
2301
2359
|
async function apiFetchWithHeaders(url, config, options = {}, verbose = false) {
|
|
2302
2360
|
const method = options.method ?? "GET";
|
|
2303
|
-
const authHeaders2 = config.apiKey ? { "x-api-key": config.apiKey } : { Authorization: `Bearer ${config.authToken}` };
|
|
2304
2361
|
const reqHeaders = {
|
|
2305
2362
|
"Content-Type": "application/json",
|
|
2306
2363
|
"Accept-Language": "zh-CN",
|
|
2307
2364
|
"Accept-Encoding": "gzip, deflate, br",
|
|
2308
|
-
...
|
|
2365
|
+
...buildAuthHeaders(config),
|
|
2309
2366
|
Datapermission: config.dataPermission ?? "",
|
|
2310
2367
|
...options.headers ?? {}
|
|
2311
2368
|
};
|
|
@@ -2821,6 +2878,12 @@ function installProcessHandlers() {
|
|
|
2821
2878
|
});
|
|
2822
2879
|
}
|
|
2823
2880
|
function printAuthMissingHelp(binName) {
|
|
2881
|
+
if (isSiluzanAgentEnv()) {
|
|
2882
|
+
console.error(
|
|
2883
|
+
"\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"
|
|
2884
|
+
);
|
|
2885
|
+
process.exit(1);
|
|
2886
|
+
}
|
|
2824
2887
|
console.error(
|
|
2825
2888
|
`
|
|
2826
2889
|
\u274C \u672A\u627E\u5230\u8BA4\u8BC1\u51ED\u636E\u3002\u8BF7\u9009\u62E9\u4EE5\u4E0B\u4EFB\u610F\u4E00\u79CD\u65B9\u5F0F\uFF1A
|
|
@@ -2890,7 +2953,7 @@ function parseMeResponse(text) {
|
|
|
2890
2953
|
async function fetchSiluzanCurrentUser(apiBase, config) {
|
|
2891
2954
|
const mainOrigin = deriveMainApiOrigin(apiBase);
|
|
2892
2955
|
const meUrl = `${mainOrigin.replace(/\/$/, "")}/query/account/me`;
|
|
2893
|
-
const authHeaders2 = config
|
|
2956
|
+
const authHeaders2 = buildSiluzanAuthHeaders(config);
|
|
2894
2957
|
try {
|
|
2895
2958
|
const res = await rawRequest(meUrl, {
|
|
2896
2959
|
method: "GET",
|
|
@@ -3671,7 +3734,7 @@ async function fetchDataPermission(mainApiUrl, auth) {
|
|
|
3671
3734
|
const headers = {
|
|
3672
3735
|
"Content-Type": "application/json",
|
|
3673
3736
|
"Accept-Language": "zh-CN",
|
|
3674
|
-
...auth
|
|
3737
|
+
...buildSiluzanAuthHeaders(auth)
|
|
3675
3738
|
};
|
|
3676
3739
|
try {
|
|
3677
3740
|
const res = await fetch(url, { headers });
|
|
@@ -3952,7 +4015,7 @@ async function apiDeleteRaw(url, config, options = {}) {
|
|
|
3952
4015
|
"Content-Type": "application/json; charset=utf-8",
|
|
3953
4016
|
Accept: "application/json, text/plain, */*",
|
|
3954
4017
|
"Accept-Language": "zh-CN",
|
|
3955
|
-
...config
|
|
4018
|
+
...buildSiluzanAuthHeaders(config),
|
|
3956
4019
|
Datapermission: config.dataPermission ?? "",
|
|
3957
4020
|
"Content-Length": String(Buffer.byteLength(bodyStr, "utf8"))
|
|
3958
4021
|
};
|
|
@@ -3991,8 +4054,11 @@ var init_fetch_wrapper = __esm({
|
|
|
3991
4054
|
// src/utils/auth.ts
|
|
3992
4055
|
function loadConfig(tokenArg) {
|
|
3993
4056
|
const shared = readSharedConfig();
|
|
3994
|
-
const
|
|
3995
|
-
|
|
4057
|
+
const { authToken, apiKey } = resolveSiluzanCredentials({
|
|
4058
|
+
tokenArg,
|
|
4059
|
+
configApiKey: shared.apiKey,
|
|
4060
|
+
configAuthToken: shared.authToken
|
|
4061
|
+
});
|
|
3996
4062
|
if (!apiKey && !authToken) {
|
|
3997
4063
|
printAuthMissingHelp("siluzan-tso");
|
|
3998
4064
|
}
|
|
@@ -102958,6 +103024,7 @@ function normalizeBearerTokenInput(raw) {
|
|
|
102958
103024
|
|
|
102959
103025
|
// src/commands/login/send-code.ts
|
|
102960
103026
|
async function runSendLoginCode(opts) {
|
|
103027
|
+
if (skipAuthSetupInAgentEnv("siluzan-tso send-login-code")) return;
|
|
102961
103028
|
const phone = validateAndNormalizePhone(opts.phone);
|
|
102962
103029
|
const tsoApiBase = process.env.SILUZAN_TSO_API_BASE ?? DEFAULT_API_BASE;
|
|
102963
103030
|
const ssoBaseUrl = deriveSsoBaseUrl(tsoApiBase);
|
|
@@ -103257,6 +103324,7 @@ async function runLoginMethodMenu(menuOpts) {
|
|
|
103257
103324
|
await runInteractivePhoneLogin(menuOpts);
|
|
103258
103325
|
}
|
|
103259
103326
|
async function runLogin(opts = {}) {
|
|
103327
|
+
if (skipAuthSetupInAgentEnv("siluzan-tso login")) return;
|
|
103260
103328
|
if (opts.apiKey !== void 0) {
|
|
103261
103329
|
const key = opts.apiKey.trim();
|
|
103262
103330
|
if (!key) {
|
|
@@ -103346,30 +103414,42 @@ function buildTsoPageWebUrl(webUrl, tsoSubRoute, extraQuery) {
|
|
|
103346
103414
|
}
|
|
103347
103415
|
function cmdConfigShow() {
|
|
103348
103416
|
const shared = readSharedConfig();
|
|
103417
|
+
const { authToken: effectiveAuthToken, apiKey: effectiveApiKeyRaw } = resolveSiluzanCredentials({
|
|
103418
|
+
configApiKey: shared.apiKey,
|
|
103419
|
+
configAuthToken: shared.authToken
|
|
103420
|
+
});
|
|
103421
|
+
const effectiveApiKey = effectiveApiKeyRaw ?? "";
|
|
103349
103422
|
const envApiKey = process.env.SILUZAN_API_KEY;
|
|
103350
103423
|
const envAuthToken = process.env.SILUZAN_AUTH_TOKEN;
|
|
103351
|
-
const effectiveApiKey = envApiKey ?? shared.apiKey ?? "";
|
|
103352
|
-
const effectiveAuthToken = envAuthToken ?? shared.authToken ?? "";
|
|
103353
103424
|
const apiBaseUrl = process.env.SILUZAN_TSO_API_BASE ?? DEFAULT_API_BASE;
|
|
103354
103425
|
const googleApiUrl = process.env.SILUZAN_GOOGLE_API ?? deriveGoogleApiUrl(apiBaseUrl);
|
|
103355
103426
|
const webUrl = deriveWebUrl(apiBaseUrl);
|
|
103356
103427
|
if (!effectiveApiKey && !effectiveAuthToken) {
|
|
103428
|
+
if (isSiluzanAgentEnv()) {
|
|
103429
|
+
console.log(
|
|
103430
|
+
"\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"
|
|
103431
|
+
);
|
|
103432
|
+
return;
|
|
103433
|
+
}
|
|
103357
103434
|
console.log(
|
|
103358
103435
|
"\n\u5C1A\u672A\u914D\u7F6E\u8BA4\u8BC1\u51ED\u636E\u3002\n\n \u65B9\u5F0F\u4E00\uFF08\u63A8\u8350\uFF09\uFF1AAPI Key\n siluzan-tso login --api-key <YOUR_API_KEY>\n\n \u65B9\u5F0F\u4E8C\uFF1AJWT Token\n siluzan-tso login\n\n \u4E5F\u53EF\u901A\u8FC7\u73AF\u5883\u53D8\u91CF\u4F20\u5165\uFF08CI/CD \u63A8\u8350\uFF09\uFF1A\n export SILUZAN_API_KEY=<YOUR_API_KEY>\n export SILUZAN_AUTH_TOKEN=<YOUR_TOKEN>\n"
|
|
103359
103436
|
);
|
|
103360
103437
|
return;
|
|
103361
103438
|
}
|
|
103362
103439
|
console.log("\n\u5F53\u524D\u914D\u7F6E\uFF1A");
|
|
103440
|
+
if (isSiluzanAgentEnv()) {
|
|
103441
|
+
console.log(" agentEnv : IS_SILUZAN_AGENT_ENV=true \u2190 Siluzan Agent \u6C99\u7BB1");
|
|
103442
|
+
}
|
|
103363
103443
|
console.log(` tsoApiBaseUrl : ${apiBaseUrl}`);
|
|
103364
103444
|
console.log(` googleApiUrl : ${googleApiUrl}`);
|
|
103365
103445
|
console.log(` webUrl : ${webUrl}`);
|
|
103366
103446
|
if (effectiveApiKey) {
|
|
103367
|
-
const src = envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
|
|
103447
|
+
const src = isSiluzanAgentEnv() ? "env:SILUZAN_API_KEY (agent)" : envApiKey ? "env:SILUZAN_API_KEY" : "config.json";
|
|
103368
103448
|
const active = " \u2190 \u5F53\u524D\u751F\u6548\uFF08X-Api-Key \u9274\u6743\uFF09";
|
|
103369
103449
|
console.log(` apiKey : ${maskSecret(effectiveApiKey)} [${src}]${active}`);
|
|
103370
103450
|
}
|
|
103371
103451
|
if (effectiveAuthToken) {
|
|
103372
|
-
const src = envAuthToken ? "env:SILUZAN_AUTH_TOKEN" : "config.json";
|
|
103452
|
+
const src = isSiluzanAgentEnv() ? "env:SILUZAN_AUTH_TOKEN (agent)" : envAuthToken ? "env:SILUZAN_AUTH_TOKEN" : "config.json";
|
|
103373
103453
|
const note = effectiveApiKey ? " \uFF08\u5DF2\u88AB apiKey \u8986\u76D6\uFF09" : " \u2190 \u5F53\u524D\u751F\u6548\uFF08Bearer \u9274\u6743\uFF09";
|
|
103374
103454
|
console.log(` authToken : ${maskSecret(effectiveAuthToken)} [${src}]${note}`);
|
|
103375
103455
|
}
|
|
@@ -103385,6 +103465,7 @@ function cmdConfigShow() {
|
|
|
103385
103465
|
console.log();
|
|
103386
103466
|
}
|
|
103387
103467
|
function cmdConfigSet(opts) {
|
|
103468
|
+
if (skipAuthSetupInAgentEnv("siluzan-tso config set")) return;
|
|
103388
103469
|
if (!opts.token && !opts.apiKey) {
|
|
103389
103470
|
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");
|
|
103390
103471
|
process.exit(1);
|
package/dist/skill/_meta.json
CHANGED
|
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
|
|
|
9
9
|
# -- Package info (injected at build time) ------------------------------------
|
|
10
10
|
$PKG_NAME = 'siluzan-tso-cli'
|
|
11
11
|
# PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
|
|
12
|
-
$PKG_VERSION = '1.1.30-beta.
|
|
12
|
+
$PKG_VERSION = '1.1.30-beta.3'
|
|
13
13
|
$CLI_BIN = 'siluzan-tso'
|
|
14
14
|
$SKILL_LABEL = 'Siluzan TSO'
|
|
15
15
|
$INSTALL_CMD = 'npm install -g siluzan-tso-cli@beta'
|
|
@@ -242,10 +242,13 @@ function Main {
|
|
|
242
242
|
Write-Info 'Registering Skill to all AI platform global directories...'
|
|
243
243
|
& $CLI_BIN init --global --force
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
if ($CLI_BIN -eq 'siluzan-seo') {
|
|
246
|
+
Write-Info 'siluzan-seo does not require login; skipping API Key setup.'
|
|
247
|
+
} else {
|
|
248
|
+
Write-Step 'Step 3/4: Configure API Key'
|
|
249
|
+
Write-Host ''
|
|
250
|
+
& $CLI_BIN login
|
|
251
|
+
}
|
|
249
252
|
|
|
250
253
|
# Step 4: Done
|
|
251
254
|
Write-Step 'Step 4/4: Complete'
|
|
@@ -9,7 +9,7 @@ set -euo pipefail
|
|
|
9
9
|
# -- Package info (injected at build time) ------------------------------------
|
|
10
10
|
readonly PKG_NAME="siluzan-tso-cli"
|
|
11
11
|
# PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
|
|
12
|
-
readonly PKG_VERSION="1.1.30-beta.
|
|
12
|
+
readonly PKG_VERSION="1.1.30-beta.3"
|
|
13
13
|
readonly CLI_BIN="siluzan-tso"
|
|
14
14
|
readonly SKILL_LABEL="Siluzan TSO"
|
|
15
15
|
readonly INSTALL_CMD="npm install -g siluzan-tso-cli@beta"
|
|
@@ -152,10 +152,13 @@ main() {
|
|
|
152
152
|
info "Registering Skill to all AI platform global directories..."
|
|
153
153
|
${CLI_BIN} init --global --force
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
if [ "${CLI_BIN}" = "siluzan-seo" ]; then
|
|
156
|
+
info "siluzan-seo does not require login; skipping API Key setup."
|
|
157
|
+
else
|
|
158
|
+
step "Step 3/4: Configure API Key"
|
|
159
|
+
echo ""
|
|
160
|
+
${CLI_BIN} login
|
|
161
|
+
fi
|
|
159
162
|
|
|
160
163
|
# Step 4: Done
|
|
161
164
|
step "Step 4/4: Complete"
|