@okx_ai/okx-trade-cli 1.2.8-beta.2 → 1.2.8-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/dist/index.js CHANGED
@@ -6975,6 +6975,22 @@ function isNewerVersion(current, latest) {
6975
6975
  if (lMin !== cMin) return lMin > cMin;
6976
6976
  return lPat > cPat;
6977
6977
  }
6978
+ async function fetchDistTags(packageName) {
6979
+ try {
6980
+ const controller = new AbortController();
6981
+ const timeout = setTimeout(() => controller.abort(), 3e3);
6982
+ const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(packageName)}`, {
6983
+ signal: controller.signal,
6984
+ headers: { accept: "application/json" }
6985
+ });
6986
+ clearTimeout(timeout);
6987
+ if (!res.ok) return null;
6988
+ const data = await res.json();
6989
+ return data["dist-tags"] ?? null;
6990
+ } catch {
6991
+ return null;
6992
+ }
6993
+ }
6978
6994
  async function fetchLatestVersion(packageName) {
6979
6995
  try {
6980
6996
  const controller = new AbortController();
@@ -7776,7 +7792,7 @@ async function cmdDiagnoseMcp(options = {}) {
7776
7792
 
7777
7793
  // src/commands/diagnose.ts
7778
7794
  var CLI_VERSION = readCliVersion();
7779
- var GIT_HASH = true ? "f9ea608" : "dev";
7795
+ var GIT_HASH = true ? "43f321d" : "dev";
7780
7796
  function maskKey2(key) {
7781
7797
  if (!key) return "(not set)";
7782
7798
  if (key.length <= 8) return "****";
@@ -8071,6 +8087,109 @@ async function runCliChecks(config, profile, outputPath) {
8071
8087
  writeReportIfRequested(report, outputPath);
8072
8088
  }
8073
8089
 
8090
+ // src/commands/upgrade.ts
8091
+ import { spawnSync as spawnSync2 } from "child_process";
8092
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4 } from "fs";
8093
+ import { dirname as dirname3, join as join4 } from "path";
8094
+ import { homedir as homedir4 } from "os";
8095
+ var PACKAGES = ["@okx_ai/okx-trade-mcp", "@okx_ai/okx-trade-cli"];
8096
+ var CACHE_FILE2 = join4(homedir4(), ".okx", "last_check");
8097
+ var THROTTLE_MS = 12 * 60 * 60 * 1e3;
8098
+ var NPM_BIN = join4(dirname3(process.execPath), process.platform === "win32" ? "npm.cmd" : "npm");
8099
+ function readLastCheck() {
8100
+ try {
8101
+ return parseInt(readFileSync4(CACHE_FILE2, "utf-8").trim(), 10) || 0;
8102
+ } catch {
8103
+ return 0;
8104
+ }
8105
+ }
8106
+ function writeLastCheck() {
8107
+ try {
8108
+ mkdirSync4(join4(homedir4(), ".okx"), { recursive: true });
8109
+ writeFileSync4(CACHE_FILE2, String(Math.floor(Date.now() / 1e3)), "utf-8");
8110
+ } catch {
8111
+ }
8112
+ }
8113
+ function printResult(result, json) {
8114
+ if (json) {
8115
+ process.stdout.write(JSON.stringify(result) + "\n");
8116
+ } else {
8117
+ switch (result.status) {
8118
+ case "up-to-date":
8119
+ process.stderr.write(`[ok] Already up to date: ${result.currentVersion}
8120
+ `);
8121
+ break;
8122
+ case "update-available":
8123
+ process.stderr.write(
8124
+ `[info] Update available: ${result.currentVersion} \u2192 ${result.latestVersion}
8125
+ Run: okx upgrade
8126
+ `
8127
+ );
8128
+ break;
8129
+ case "updated":
8130
+ process.stderr.write(`[ok] Upgraded: ${result.currentVersion} \u2192 ${result.latestVersion}
8131
+ `);
8132
+ break;
8133
+ case "error":
8134
+ process.stderr.write(`[error] Failed to fetch latest version from npm registry
8135
+ `);
8136
+ break;
8137
+ }
8138
+ }
8139
+ }
8140
+ function isThrottled(options) {
8141
+ if (options.force || options.check) return false;
8142
+ return Date.now() - readLastCheck() * 1e3 < THROTTLE_MS;
8143
+ }
8144
+ async function resolveLatestVersion(beta) {
8145
+ if (beta) {
8146
+ const tags = await fetchDistTags("@okx_ai/okx-trade-cli");
8147
+ return tags?.["next"] ?? tags?.["latest"] ?? null;
8148
+ }
8149
+ return fetchLatestVersion("@okx_ai/okx-trade-cli");
8150
+ }
8151
+ function runNpmInstall(json) {
8152
+ const result = spawnSync2(NPM_BIN, ["install", "-g", ...PACKAGES], {
8153
+ stdio: json ? ["inherit", "ignore", process.stderr] : "inherit",
8154
+ shell: false
8155
+ });
8156
+ return result.status === 0;
8157
+ }
8158
+ async function cmdUpgrade(currentVersion, options, json) {
8159
+ if (isThrottled(options)) {
8160
+ if (json) {
8161
+ process.stdout.write(
8162
+ JSON.stringify({ currentVersion, latestVersion: currentVersion, status: "up-to-date", updated: false }) + "\n"
8163
+ );
8164
+ }
8165
+ return;
8166
+ }
8167
+ const latestVersion = await resolveLatestVersion(options.beta ?? false);
8168
+ if (!latestVersion) {
8169
+ printResult({ currentVersion, latestVersion: "unknown", status: "error", updated: false }, json);
8170
+ process.exitCode = 1;
8171
+ return;
8172
+ }
8173
+ const stableCurrentVersion = currentVersion.split(/[-+]/)[0] ?? currentVersion;
8174
+ const needsUpdate = options.force || isNewerVersion(stableCurrentVersion, latestVersion);
8175
+ if (!needsUpdate) {
8176
+ if (!options.check) writeLastCheck();
8177
+ printResult({ currentVersion, latestVersion, status: "up-to-date", updated: false }, json);
8178
+ return;
8179
+ }
8180
+ if (options.check) {
8181
+ printResult({ currentVersion, latestVersion, status: "update-available", updated: false }, json);
8182
+ return;
8183
+ }
8184
+ if (runNpmInstall(json)) {
8185
+ writeLastCheck();
8186
+ printResult({ currentVersion, latestVersion, status: "updated", updated: true }, json);
8187
+ } else {
8188
+ printResult({ currentVersion, latestVersion, status: "error", updated: false }, json);
8189
+ process.exitCode = 1;
8190
+ }
8191
+ }
8192
+
8074
8193
  // src/config/loader.ts
8075
8194
  function loadProfileConfig(opts) {
8076
8195
  return loadConfig({
@@ -8673,6 +8792,10 @@ var HELP_TREE = {
8673
8792
  diagnose: {
8674
8793
  description: "Run network / MCP server diagnostics",
8675
8794
  usage: "okx diagnose [--cli | --mcp | --all] [--profile <name>] [--demo] [--output <file>]"
8795
+ },
8796
+ upgrade: {
8797
+ description: "Upgrade okx CLI and MCP server to the latest stable version",
8798
+ usage: "okx upgrade [--check] [--beta] [--force] [--json]"
8676
8799
  }
8677
8800
  };
8678
8801
  function printGlobalHelp() {
@@ -8922,6 +9045,9 @@ var CLI_OPTIONS = {
8922
9045
  // audit
8923
9046
  since: { type: "string" },
8924
9047
  tool: { type: "string" },
9048
+ // upgrade
9049
+ beta: { type: "boolean", default: false },
9050
+ check: { type: "boolean", default: false },
8925
9051
  // config profile
8926
9052
  force: { type: "boolean", default: false },
8927
9053
  // onchain-earn
@@ -10597,7 +10723,7 @@ function writeCliConfig(config) {
10597
10723
 
10598
10724
  // src/commands/config.ts
10599
10725
  import { createInterface } from "readline";
10600
- import { spawnSync as spawnSync2 } from "child_process";
10726
+ import { spawnSync as spawnSync3 } from "child_process";
10601
10727
  var messages = {
10602
10728
  en: {
10603
10729
  title: "OKX Trade CLI \u2014 Configuration Wizard",
@@ -10739,7 +10865,7 @@ function tryOpenUrl(url) {
10739
10865
  } else {
10740
10866
  opener = "xdg-open";
10741
10867
  }
10742
- spawnSync2(opener, [url], { stdio: "ignore", shell: process.platform === "win32" });
10868
+ spawnSync3(opener, [url], { stdio: "ignore", shell: process.platform === "win32" });
10743
10869
  } catch {
10744
10870
  }
10745
10871
  }
@@ -11637,7 +11763,7 @@ async function cmdDcdQuoteAndBuy(run, opts) {
11637
11763
  // src/index.ts
11638
11764
  var _require3 = createRequire3(import.meta.url);
11639
11765
  var CLI_VERSION2 = _require3("../package.json").version;
11640
- var GIT_HASH2 = true ? "f9ea608" : "dev";
11766
+ var GIT_HASH2 = true ? "43f321d" : "dev";
11641
11767
  function handleConfigCommand(action, rest, json, lang, force) {
11642
11768
  if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
11643
11769
  if (action === "show") return cmdConfigShow(json);
@@ -12429,6 +12555,7 @@ async function main() {
12429
12555
  const json = v.json ?? false;
12430
12556
  if (module === "config") return handleConfigCommand(action, rest, json, v.lang, v.force);
12431
12557
  if (module === "setup") return handleSetupCommand(v);
12558
+ if (module === "upgrade") return cmdUpgrade(CLI_VERSION2, { beta: v.beta, check: v.check, force: v.force }, json);
12432
12559
  if (module === "diagnose") {
12433
12560
  let config2;
12434
12561
  try {