@okxweb3/a2a-node 0.1.3 → 0.1.4-beta-520175e226-260702152522

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/cli.js CHANGED
@@ -472,10 +472,11 @@ ${route.chatId}
472
472
  ${route.threadId ?? ""}`;
473
473
  }
474
474
  function normalizeGatewayRouteChatType(explicit, parsed, threadId) {
475
- if (threadId) {
476
- return "thread";
475
+ const chatType = parsed || explicit;
476
+ if (chatType) {
477
+ return chatType;
477
478
  }
478
- return explicit || parsed || "dm";
479
+ return threadId ? "thread" : "dm";
479
480
  }
480
481
  function matchingGatewayRouteFromSessionKey(sessionKey, expected, provider) {
481
482
  const parsed = parseGatewayRouteSessionKey(sessionKey, provider);
@@ -540,7 +541,8 @@ function parseProviderTelegramRouteSessionKey(provider, platform, scope, rest) {
540
541
  return {
541
542
  platform,
542
543
  chatId: safeDecodeURIComponent(rest[0]),
543
- ...threadId ? { threadId, chatType: "thread" } : { chatType: scope === "group" ? "group" : "dm" }
544
+ ...threadId ? { threadId } : {},
545
+ chatType: scope === "group" ? threadId ? "thread" : "group" : "dm"
544
546
  };
545
547
  }
546
548
  return null;
@@ -1822,15 +1824,15 @@ async function ensureAiWorkspace(paths) {
1822
1824
  return aiWorkingDir;
1823
1825
  }
1824
1826
  async function waitForImmediateExit(child, timeoutMs) {
1825
- return await new Promise((resolve8) => {
1827
+ return await new Promise((resolve9) => {
1826
1828
  let timer;
1827
1829
  const onExit = () => {
1828
1830
  clearTimeout(timer);
1829
- resolve8(true);
1831
+ resolve9(true);
1830
1832
  };
1831
1833
  timer = setTimeout(() => {
1832
1834
  child.off("exit", onExit);
1833
- resolve8(false);
1835
+ resolve9(false);
1834
1836
  }, timeoutMs);
1835
1837
  child.once("exit", onExit);
1836
1838
  });
@@ -1914,6 +1916,9 @@ async function startDaemon(homeDir) {
1914
1916
  const child = (0, import_node_child_process.spawn)(process.execPath, [entry, "run"], {
1915
1917
  cwd: daemonCwd,
1916
1918
  detached: true,
1919
+ // win32: keep the detached daemon from flashing/holding a console window.
1920
+ // Ignored on every non-win32 platform.
1921
+ windowsHide: true,
1917
1922
  env: {
1918
1923
  ...process.env,
1919
1924
  OKX_AGENT_TASK_HOME: paths.homeDir,
@@ -1963,7 +1968,7 @@ async function waitForExit(pid, timeoutMs) {
1963
1968
  if (!isProcessAlive(pid)) {
1964
1969
  return true;
1965
1970
  }
1966
- await new Promise((resolve8) => setTimeout(resolve8, 100));
1971
+ await new Promise((resolve9) => setTimeout(resolve9, 100));
1967
1972
  }
1968
1973
  return !isProcessAlive(pid);
1969
1974
  }
@@ -2136,7 +2141,7 @@ function readReadyTimeoutMs(env) {
2136
2141
  return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_READY_TIMEOUT_MS;
2137
2142
  }
2138
2143
  function sleep(ms) {
2139
- return new Promise((resolve8) => setTimeout(resolve8, ms));
2144
+ return new Promise((resolve9) => setTimeout(resolve9, ms));
2140
2145
  }
2141
2146
  var import_node_fs3, import_promises2, import_node_child_process, import_node_path5, STOP_GRACE_MS, FORCE_KILL_GRACE_MS, START_EXIT_CHECK_MS, DEFAULT_READY_TIMEOUT_MS, READY_POLL_MS, DAEMON_READY_TIMEOUT_ENV;
2142
2147
  var init_daemon = __esm({
@@ -2405,7 +2410,7 @@ var init_command_store = __esm({
2405
2410
  if (result) {
2406
2411
  return result;
2407
2412
  }
2408
- await new Promise((resolve8) => setTimeout(resolve8, 500));
2413
+ await new Promise((resolve9) => setTimeout(resolve9, 500));
2409
2414
  }
2410
2415
  return null;
2411
2416
  }
@@ -2830,25 +2835,164 @@ var init_file_store = __esm({
2830
2835
  }
2831
2836
  });
2832
2837
 
2838
+ // ../core/src/win-compat.ts
2839
+ function toWindowsInvocation(command, args, platform = process.platform, comSpec = process.env.ComSpec ?? process.env.COMSPEC) {
2840
+ if (!shouldRouteThroughWindowsShell(command, platform)) {
2841
+ return { command, args, routedThroughWindowsShell: false };
2842
+ }
2843
+ return {
2844
+ command: comSpec || "cmd.exe",
2845
+ args: ["/d", "/s", "/c", buildWindowsShellCommandLine(command, args)],
2846
+ routedThroughWindowsShell: true
2847
+ };
2848
+ }
2849
+ function shouldRouteThroughWindowsShell(command, platform) {
2850
+ if (platform !== "win32") {
2851
+ return false;
2852
+ }
2853
+ const extension = (0, import_node_path8.extname)(command).toLowerCase();
2854
+ return extension !== ".exe" && extension !== ".com";
2855
+ }
2856
+ function buildWindowsShellCommandLine(command, args) {
2857
+ return [command, ...args].map(quoteWindowsShellArg).join(" ");
2858
+ }
2859
+ function quoteWindowsShellArg(value) {
2860
+ if (/^[A-Za-z0-9_@+=:,./\\-]+$/.test(value)) {
2861
+ return value;
2862
+ }
2863
+ return `"${value.replace(/"/g, '\\"')}"`;
2864
+ }
2865
+ var import_node_path8, WIN_COMPAT_LOG_PREFIX;
2866
+ var init_win_compat = __esm({
2867
+ "../core/src/win-compat.ts"() {
2868
+ "use strict";
2869
+ import_node_path8 = require("node:path");
2870
+ WIN_COMPAT_LOG_PREFIX = "[win-compat]";
2871
+ }
2872
+ });
2873
+
2874
+ // src/win-spawn.ts
2875
+ function spawnCompat(command, args, options = {}) {
2876
+ const invocation = toWindowsInvocation(command, args);
2877
+ logSpawnRoute("spawn", command, args, invocation);
2878
+ return (0, import_node_child_process2.spawn)(invocation.command, invocation.args, { windowsHide: true, ...options });
2879
+ }
2880
+ function spawnSyncCompat(command, args, options = {}) {
2881
+ const invocation = toWindowsInvocation(command, args);
2882
+ logSpawnRoute("spawnSync", command, args, invocation);
2883
+ return (0, import_node_child_process2.spawnSync)(invocation.command, invocation.args, { windowsHide: true, ...options });
2884
+ }
2885
+ function killProcessTree(child, signal = "SIGTERM", platform = process.platform) {
2886
+ if (platform === "win32" && typeof child.pid === "number") {
2887
+ const result = (0, import_node_child_process2.spawnSync)("taskkill", ["/pid", String(child.pid), "/t", "/f"], {
2888
+ windowsHide: true,
2889
+ stdio: "ignore"
2890
+ });
2891
+ if (!result.error) {
2892
+ logWithTimestamp(`${WIN_COMPAT_LOG_PREFIX} taskkill /t /f pid=${child.pid}`);
2893
+ return;
2894
+ }
2895
+ logWithTimestamp(
2896
+ `${WIN_COMPAT_LOG_PREFIX} taskkill failed pid=${child.pid}: ${result.error.message}; falling back to child.kill(${signal})`
2897
+ );
2898
+ }
2899
+ child.kill(signal);
2900
+ }
2901
+ function logSpawnRoute(kind, command, args, invocation) {
2902
+ if (!invocation.routedThroughWindowsShell) {
2903
+ return;
2904
+ }
2905
+ logWithTimestamp(
2906
+ `${WIN_COMPAT_LOG_PREFIX} ${kind} route: [${command} ${args.join(" ")}] -> [${invocation.command} ${invocation.args.join(" ")}]`
2907
+ );
2908
+ }
2909
+ var import_node_child_process2;
2910
+ var init_win_spawn = __esm({
2911
+ "src/win-spawn.ts"() {
2912
+ "use strict";
2913
+ import_node_child_process2 = require("node:child_process");
2914
+ init_log();
2915
+ init_win_compat();
2916
+ init_win_compat();
2917
+ }
2918
+ });
2919
+
2833
2920
  // src/ai-command.ts
2834
- function resolveAiProviderCommand(provider, env = process.env, storedCommand) {
2921
+ function resolveAiProviderCommand(provider, env = process.env, storedCommand, platform = process.platform) {
2835
2922
  const override = env[`OKX_A2A_AI_${provider.toUpperCase()}_COMMAND`];
2836
2923
  if (override) {
2837
2924
  return override;
2838
2925
  }
2839
- if (storedCommand && commandExists(storedCommand, env)) {
2926
+ if (provider === "codex") {
2927
+ const codex = resolveCodexCommandPath(env, storedCommand, platform);
2928
+ if (codex) {
2929
+ return codex;
2930
+ }
2931
+ }
2932
+ if (storedCommand && commandExists(storedCommand, env, platform)) {
2840
2933
  return storedCommand;
2841
2934
  }
2842
- return resolveCommandPath(provider, env) ?? provider;
2935
+ return findExecutable(provider, env, platform) ?? provider;
2843
2936
  }
2844
- function resolveCommandPath(command, env = process.env) {
2845
- return findExecutable(command, env);
2846
- }
2847
- function commandExists(command, env = process.env) {
2937
+ function commandExists(command, env = process.env, platform = process.platform) {
2938
+ if (platform === "win32" && isCodexCommand(command)) {
2939
+ return resolveCodexCommandPath(env, command, platform) !== null;
2940
+ }
2848
2941
  if (isExecutable(command)) {
2849
2942
  return true;
2850
2943
  }
2851
- return !!findExecutable(command, env);
2944
+ return !!findExecutable(command, env, platform);
2945
+ }
2946
+ function resolveCommandPath(command, env = process.env, platform = process.platform) {
2947
+ return findExecutable(command, env, platform);
2948
+ }
2949
+ function resolveCodexCommandPath(env = process.env, storedCommand, platform = process.platform, probe = probeCodexCommand) {
2950
+ if (platform !== "win32") {
2951
+ return storedCommand && commandExists(storedCommand, env, platform) ? storedCommand : findExecutable("codex", env, platform);
2952
+ }
2953
+ for (const candidate of collectCodexCommandCandidates(env, storedCommand, platform)) {
2954
+ const result = probe(candidate, env, platform);
2955
+ if (result.usable) {
2956
+ return candidate;
2957
+ }
2958
+ }
2959
+ return null;
2960
+ }
2961
+ function collectCodexCommandCandidates(env = process.env, storedCommand, platform = process.platform) {
2962
+ const candidates = [];
2963
+ const seen = /* @__PURE__ */ new Set();
2964
+ const add = (candidate) => {
2965
+ if (!candidate || seen.has(candidate)) {
2966
+ return;
2967
+ }
2968
+ seen.add(candidate);
2969
+ candidates.push(candidate);
2970
+ };
2971
+ if (storedCommand && storedCommand !== "codex") {
2972
+ add(storedCommand);
2973
+ }
2974
+ if (platform !== "win32") {
2975
+ add(findExecutable("codex", env, platform));
2976
+ return candidates;
2977
+ }
2978
+ for (const candidate of localAppDataCodexCandidates(env)) {
2979
+ add(candidate);
2980
+ }
2981
+ const pathCandidates = findExecutableCandidatesOnPath("codex", env.PATH, platform);
2982
+ for (const candidate of pathCandidates.filter((candidate2) => !isWindowsAppsPath(candidate2))) {
2983
+ add(candidate);
2984
+ }
2985
+ const fallbackExecutableCandidates = fallbackCandidates("codex", env, platform).filter(isExecutable);
2986
+ for (const candidate of fallbackExecutableCandidates.filter((candidate2) => !isWindowsAppsPath(candidate2))) {
2987
+ add(candidate);
2988
+ }
2989
+ for (const candidate of pathCandidates.filter(isWindowsAppsPath)) {
2990
+ add(candidate);
2991
+ }
2992
+ for (const candidate of fallbackExecutableCandidates.filter(isWindowsAppsPath)) {
2993
+ add(candidate);
2994
+ }
2995
+ return candidates;
2852
2996
  }
2853
2997
  function readAiProviderTimeoutMs(env = process.env) {
2854
2998
  const raw = env.OKX_A2A_AI_PROVIDER_TIMEOUT_MS ?? env.OKX_AGENT_TASK_AI_PROVIDER_TIMEOUT_MS;
@@ -2875,7 +3019,7 @@ function resolveOkxA2aBinForChild(env) {
2875
3019
  }
2876
3020
  const found = findExecutable("okx-a2a", env);
2877
3021
  if (found) {
2878
- return { bin: found, pathDir: (0, import_node_path8.dirname)(found) };
3022
+ return { bin: found, pathDir: (0, import_node_path9.dirname)(found) };
2879
3023
  }
2880
3024
  const entry = process.argv[1];
2881
3025
  if (entry && /(?:^|[\\/])cli\.js$/.test(entry) && fileExists(entry)) {
@@ -2891,72 +3035,76 @@ function fileExists(filePath) {
2891
3035
  return false;
2892
3036
  }
2893
3037
  }
2894
- function findExecutable(command, env) {
2895
- if ((0, import_node_path8.isAbsolute)(command)) {
3038
+ function findExecutable(command, env, platform = process.platform) {
3039
+ if ((0, import_node_path9.isAbsolute)(command)) {
2896
3040
  return isExecutable(command) ? command : null;
2897
3041
  }
2898
- const fromPath = findExecutableOnPath(command, env.PATH);
3042
+ const fromPath = findExecutableOnPath(command, env.PATH, platform);
2899
3043
  if (fromPath) {
2900
3044
  return fromPath;
2901
3045
  }
2902
- for (const candidate of fallbackCandidates(command, env)) {
3046
+ for (const candidate of fallbackCandidates(command, env, platform)) {
2903
3047
  if (isExecutable(candidate)) {
2904
3048
  return candidate;
2905
3049
  }
2906
3050
  }
2907
3051
  return null;
2908
3052
  }
2909
- function findExecutableOnPath(command, pathValue) {
3053
+ function findExecutableOnPath(command, pathValue, platform = process.platform) {
3054
+ return findExecutableCandidatesOnPath(command, pathValue, platform)[0] ?? null;
3055
+ }
3056
+ function findExecutableCandidatesOnPath(command, pathValue, platform) {
2910
3057
  if (!pathValue) {
2911
- return null;
3058
+ return [];
2912
3059
  }
2913
- for (const dir of pathValue.split(import_node_path8.delimiter).filter(Boolean)) {
2914
- for (const candidate of executableNames(command).map((name2) => (0, import_node_path8.join)(dir, name2))) {
3060
+ const candidates = [];
3061
+ for (const dir of pathValue.split(import_node_path9.delimiter).filter(Boolean)) {
3062
+ for (const candidate of executableNames(command, platform).map((name2) => (0, import_node_path9.join)(dir, name2))) {
2915
3063
  if (isExecutable(candidate)) {
2916
- return candidate;
3064
+ candidates.push(candidate);
2917
3065
  }
2918
3066
  }
2919
3067
  }
2920
- return null;
3068
+ return candidates;
2921
3069
  }
2922
- function fallbackCandidates(command, env) {
3070
+ function fallbackCandidates(command, env, platform = process.platform) {
2923
3071
  const home = (0, import_node_os2.homedir)();
2924
3072
  const dirs = [
2925
- (0, import_node_path8.dirname)(process.execPath),
2926
- (0, import_node_path8.join)(home, ".local", "bin"),
2927
- (0, import_node_path8.join)(home, "Library", "pnpm"),
3073
+ (0, import_node_path9.dirname)(process.execPath),
3074
+ (0, import_node_path9.join)(home, ".local", "bin"),
3075
+ (0, import_node_path9.join)(home, "Library", "pnpm"),
2928
3076
  env.PNPM_HOME,
2929
- (0, import_node_path8.join)(home, ".npm-global", "bin"),
2930
- (0, import_node_path8.join)(home, ".asdf", "shims"),
3077
+ (0, import_node_path9.join)(home, ".npm-global", "bin"),
3078
+ (0, import_node_path9.join)(home, ".asdf", "shims"),
2931
3079
  "/opt/homebrew/bin",
2932
3080
  "/usr/local/bin",
2933
- env.LOCALAPPDATA ? (0, import_node_path8.join)(env.LOCALAPPDATA, "pnpm") : void 0,
2934
- env.APPDATA ? (0, import_node_path8.join)(env.APPDATA, "npm") : void 0
3081
+ env.LOCALAPPDATA ? (0, import_node_path9.join)(env.LOCALAPPDATA, "pnpm") : void 0,
3082
+ env.APPDATA ? (0, import_node_path9.join)(env.APPDATA, "npm") : void 0
2935
3083
  ].filter((dir) => !!dir);
2936
- return dirs.flatMap((dir) => executableNames(command).map((name2) => (0, import_node_path8.join)(dir, name2)));
3084
+ return dirs.flatMap((dir) => executableNames(command, platform).map((name2) => (0, import_node_path9.join)(dir, name2)));
2937
3085
  }
2938
3086
  function providerPathDirs(command, env) {
2939
3087
  return [
2940
- (0, import_node_path8.isAbsolute)(command) ? (0, import_node_path8.dirname)(command) : void 0,
2941
- (0, import_node_path8.dirname)(process.execPath),
2942
- (0, import_node_path8.join)((0, import_node_os2.homedir)(), ".local", "bin"),
2943
- (0, import_node_path8.join)((0, import_node_os2.homedir)(), "Library", "pnpm"),
3088
+ (0, import_node_path9.isAbsolute)(command) ? (0, import_node_path9.dirname)(command) : void 0,
3089
+ (0, import_node_path9.dirname)(process.execPath),
3090
+ (0, import_node_path9.join)((0, import_node_os2.homedir)(), ".local", "bin"),
3091
+ (0, import_node_path9.join)((0, import_node_os2.homedir)(), "Library", "pnpm"),
2944
3092
  env.PNPM_HOME
2945
3093
  ].filter((dir) => !!dir);
2946
3094
  }
2947
3095
  function prependPathDirs(pathValue, dirs) {
2948
3096
  const seen = /* @__PURE__ */ new Set();
2949
- const merged = [...dirs, ...pathValue ? pathValue.split(import_node_path8.delimiter) : []].filter(Boolean).filter((dir) => {
3097
+ const merged = [...dirs, ...pathValue ? pathValue.split(import_node_path9.delimiter) : []].filter(Boolean).filter((dir) => {
2950
3098
  if (seen.has(dir)) {
2951
3099
  return false;
2952
3100
  }
2953
3101
  seen.add(dir);
2954
3102
  return true;
2955
3103
  });
2956
- return merged.join(import_node_path8.delimiter);
3104
+ return merged.join(import_node_path9.delimiter);
2957
3105
  }
2958
- function executableNames(command) {
2959
- if (process.platform !== "win32" || /\.[a-z0-9]+$/i.test(command)) {
3106
+ function executableNames(command, platform = process.platform) {
3107
+ if (platform !== "win32" || /\.[a-z0-9]+$/i.test(command)) {
2960
3108
  return [command];
2961
3109
  }
2962
3110
  return [command, `${command}.cmd`, `${command}.exe`, `${command}.bat`];
@@ -2969,14 +3117,64 @@ function isExecutable(filePath) {
2969
3117
  return false;
2970
3118
  }
2971
3119
  }
2972
- var import_node_fs5, import_node_os2, import_node_path8, DEFAULT_AI_PROVIDER_TIMEOUT_MS;
3120
+ function localAppDataCodexCandidates(env) {
3121
+ if (!env.LOCALAPPDATA) {
3122
+ return [];
3123
+ }
3124
+ const baseDir = (0, import_node_path9.join)(env.LOCALAPPDATA, "OpenAI", "Codex", "bin");
3125
+ let entries;
3126
+ try {
3127
+ entries = (0, import_node_fs5.readdirSync)(baseDir, { withFileTypes: true });
3128
+ } catch {
3129
+ return [];
3130
+ }
3131
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => {
3132
+ const filePath = (0, import_node_path9.join)(baseDir, entry.name, "codex.exe");
3133
+ try {
3134
+ const stat3 = (0, import_node_fs5.statSync)(filePath);
3135
+ return stat3.isFile() ? { filePath, mtimeMs: stat3.mtimeMs } : null;
3136
+ } catch {
3137
+ return null;
3138
+ }
3139
+ }).filter((entry) => entry !== null).sort((a, b) => b.mtimeMs - a.mtimeMs).map((entry) => entry.filePath);
3140
+ }
3141
+ function probeCodexCommand(command, env, platform) {
3142
+ if (platform !== "win32") {
3143
+ return { usable: true };
3144
+ }
3145
+ const result = spawnSyncCompat(command, ["login", "status"], {
3146
+ env,
3147
+ encoding: "utf8",
3148
+ stdio: ["ignore", "pipe", "pipe"],
3149
+ timeout: CODEX_PROBE_TIMEOUT_MS,
3150
+ windowsHide: true
3151
+ });
3152
+ if (result.error) {
3153
+ const error = result.error;
3154
+ return {
3155
+ usable: false,
3156
+ errorCode: error.code,
3157
+ message: error.message
3158
+ };
3159
+ }
3160
+ return { usable: true };
3161
+ }
3162
+ function isCodexCommand(command) {
3163
+ return /(?:^|[\\/])codex(?:\.(?:cmd|exe|bat))?$/i.test(command);
3164
+ }
3165
+ function isWindowsAppsPath(commandPath) {
3166
+ return /(?:^|[\\/])WindowsApps(?:[\\/]|$)/i.test(commandPath);
3167
+ }
3168
+ var import_node_fs5, import_node_os2, import_node_path9, DEFAULT_AI_PROVIDER_TIMEOUT_MS, CODEX_PROBE_TIMEOUT_MS;
2973
3169
  var init_ai_command = __esm({
2974
3170
  "src/ai-command.ts"() {
2975
3171
  "use strict";
2976
3172
  import_node_fs5 = require("node:fs");
2977
3173
  import_node_os2 = require("node:os");
2978
- import_node_path8 = require("node:path");
3174
+ import_node_path9 = require("node:path");
3175
+ init_win_spawn();
2979
3176
  DEFAULT_AI_PROVIDER_TIMEOUT_MS = null;
3177
+ CODEX_PROBE_TIMEOUT_MS = 1e4;
2980
3178
  }
2981
3179
  });
2982
3180
 
@@ -3125,11 +3323,17 @@ function hasOpenClawParentProcess(parentPid, readParentProcessCommand2) {
3125
3323
  return false;
3126
3324
  }
3127
3325
  function readParentProcessCommand(pid) {
3128
- const commandResult = (0, import_node_child_process2.spawnSync)("ps", ["-p", String(pid), "-o", "comm="], {
3326
+ return readParentProcessCommandForPlatform(pid, process.platform);
3327
+ }
3328
+ function readParentProcessCommandForPlatform(pid, platform) {
3329
+ if (platform === "win32") {
3330
+ return readWindowsParentProcessCommand(pid);
3331
+ }
3332
+ const commandResult = (0, import_node_child_process3.spawnSync)("ps", ["-p", String(pid), "-o", "comm="], {
3129
3333
  encoding: "utf8",
3130
3334
  stdio: ["ignore", "pipe", "ignore"]
3131
3335
  });
3132
- const parentResult = (0, import_node_child_process2.spawnSync)("ps", ["-p", String(pid), "-o", "ppid="], {
3336
+ const parentResult = (0, import_node_child_process3.spawnSync)("ps", ["-p", String(pid), "-o", "ppid="], {
3133
3337
  encoding: "utf8",
3134
3338
  stdio: ["ignore", "pipe", "ignore"]
3135
3339
  });
@@ -3141,6 +3345,81 @@ function readParentProcessCommand(pid) {
3141
3345
  }
3142
3346
  return { command, parentPid };
3143
3347
  }
3348
+ function buildWindowsParentProcessProbe(pid) {
3349
+ if (!Number.isInteger(pid)) {
3350
+ return null;
3351
+ }
3352
+ return {
3353
+ command: "powershell.exe",
3354
+ args: [
3355
+ "-NoProfile",
3356
+ "-NonInteractive",
3357
+ "-Command",
3358
+ `Get-CimInstance Win32_Process -Filter "ProcessId=${pid}" | Select-Object Name,ParentProcessId | ConvertTo-Json -Compress`
3359
+ ]
3360
+ };
3361
+ }
3362
+ function parseWindowsParentProcessJson(stdout) {
3363
+ const trimmed = stdout.trim();
3364
+ if (!trimmed) {
3365
+ return null;
3366
+ }
3367
+ let parsed;
3368
+ try {
3369
+ parsed = JSON.parse(trimmed);
3370
+ } catch {
3371
+ return null;
3372
+ }
3373
+ const record = Array.isArray(parsed) ? parsed[0] : parsed;
3374
+ if (!record || typeof record !== "object") {
3375
+ return null;
3376
+ }
3377
+ const name2 = record.Name;
3378
+ if (typeof name2 !== "string" || name2.trim() === "") {
3379
+ return null;
3380
+ }
3381
+ const rawParentPid = Number(record.ParentProcessId);
3382
+ const parentPid = Number.isInteger(rawParentPid) && rawParentPid > 0 ? rawParentPid : null;
3383
+ return { command: name2.trim(), parentPid };
3384
+ }
3385
+ function readWindowsParentProcessCommand(pid) {
3386
+ const probe = buildWindowsParentProcessProbe(pid);
3387
+ if (!probe) {
3388
+ errorWithTimestamp(`${WIN_COMPAT_LOG_PREFIX} parent-process probe rejected non-integer pid=${String(pid)}`);
3389
+ return null;
3390
+ }
3391
+ const result = (0, import_node_child_process3.spawnSync)(probe.command, probe.args, {
3392
+ encoding: "utf8",
3393
+ stdio: ["ignore", "pipe", "ignore"],
3394
+ timeout: 5e3,
3395
+ windowsHide: true
3396
+ });
3397
+ if (result.error) {
3398
+ const spawnError = result.error;
3399
+ errorWithTimestamp(
3400
+ `${WIN_COMPAT_LOG_PREFIX} parent-process probe failed pid=${pid} command=${probe.command} errorCode=${spawnError.code ?? "unknown"} error=${spawnError.message}`
3401
+ );
3402
+ return null;
3403
+ }
3404
+ if (result.status !== 0) {
3405
+ errorWithTimestamp(
3406
+ `${WIN_COMPAT_LOG_PREFIX} parent-process probe exited pid=${pid} command=${probe.command} status=${String(result.status)} signal=${String(result.signal)}`
3407
+ );
3408
+ return null;
3409
+ }
3410
+ const stdout = typeof result.stdout === "string" ? result.stdout : "";
3411
+ const parsed = parseWindowsParentProcessJson(stdout);
3412
+ if (!parsed) {
3413
+ errorWithTimestamp(
3414
+ `${WIN_COMPAT_LOG_PREFIX} parent-process probe unparsable output pid=${pid} stdout=${JSON.stringify(stdout.slice(0, 200))}`
3415
+ );
3416
+ return null;
3417
+ }
3418
+ logWithTimestamp(
3419
+ `${WIN_COMPAT_LOG_PREFIX} parent-process probe pid=${pid} -> command=${parsed.command} parentPid=${parsed.parentPid ?? "null"}`
3420
+ );
3421
+ return parsed;
3422
+ }
3144
3423
  async function ensureDefaultAiProvider(options) {
3145
3424
  const env = options.env ?? process.env;
3146
3425
  const commandExists2 = options.commandExists ?? commandExists;
@@ -3684,7 +3963,7 @@ async function promptForAiProviderWithArrows(options) {
3684
3963
  options.stdin.resume();
3685
3964
  options.stdout.write("\x1B[?25l");
3686
3965
  render();
3687
- return await new Promise((resolve8, reject) => {
3966
+ return await new Promise((resolve9, reject) => {
3688
3967
  const cleanup = () => {
3689
3968
  options.stdin.off("keypress", onKeypress);
3690
3969
  options.stdin.setRawMode(false);
@@ -3703,7 +3982,7 @@ async function promptForAiProviderWithArrows(options) {
3703
3982
  clearRendered();
3704
3983
  options.stdout.write(`Selected AI provider: ${provider}
3705
3984
  `);
3706
- resolve8(provider);
3985
+ resolve9(provider);
3707
3986
  };
3708
3987
  const onKeypress = (_str, key) => {
3709
3988
  if (key.ctrl && key.name === "c") {
@@ -3752,14 +4031,16 @@ function parseProviderChoice(answer) {
3752
4031
  return null;
3753
4032
  }
3754
4033
  }
3755
- var import_node_child_process2, import_promises4, import_node_readline, AI_PROVIDERS, UserCancelledAiProviderSelectionError;
4034
+ var import_node_child_process3, import_promises4, import_node_readline, AI_PROVIDERS, UserCancelledAiProviderSelectionError;
3756
4035
  var init_ai_provider = __esm({
3757
4036
  "src/ai-provider.ts"() {
3758
4037
  "use strict";
3759
- import_node_child_process2 = require("node:child_process");
4038
+ import_node_child_process3 = require("node:child_process");
3760
4039
  import_promises4 = require("node:readline/promises");
3761
4040
  import_node_readline = require("node:readline");
3762
4041
  init_ai_command();
4042
+ init_log();
4043
+ init_win_spawn();
3763
4044
  AI_PROVIDERS = ["codex", "claude", "hermes", "openclaw"];
3764
4045
  UserCancelledAiProviderSelectionError = class extends Error {
3765
4046
  constructor() {
@@ -3775,7 +4056,7 @@ function resolveUserAttentionIpcPath(homeDir) {
3775
4056
  if (process.platform === "win32") {
3776
4057
  return "\\\\.\\pipe\\okx-a2a-user-attention";
3777
4058
  }
3778
- return (0, import_node_path9.join)(resolveTaskPaths(homeDir).runDir, "user-attention.sock");
4059
+ return (0, import_node_path10.join)(resolveTaskPaths(homeDir).runDir, "user-attention.sock");
3779
4060
  }
3780
4061
  async function startUserAttentionEventServer(options = {}) {
3781
4062
  const path = resolveUserAttentionIpcPath(options.homeDir);
@@ -3810,7 +4091,7 @@ async function startUserAttentionEventServer(options = {}) {
3810
4091
  });
3811
4092
  server.on("error", (err2) => options.onError?.(err2));
3812
4093
  if (process.platform !== "win32") {
3813
- (0, import_node_fs6.mkdirSync)((0, import_node_path9.dirname)(path), { recursive: true });
4094
+ (0, import_node_fs6.mkdirSync)((0, import_node_path10.dirname)(path), { recursive: true });
3814
4095
  try {
3815
4096
  (0, import_node_fs6.unlinkSync)(path);
3816
4097
  } catch (err2) {
@@ -3820,14 +4101,14 @@ async function startUserAttentionEventServer(options = {}) {
3820
4101
  }
3821
4102
  }
3822
4103
  }
3823
- await new Promise((resolve8, reject) => {
4104
+ await new Promise((resolve9, reject) => {
3824
4105
  const onError = (err2) => {
3825
4106
  server.off("listening", onListening);
3826
4107
  reject(err2);
3827
4108
  };
3828
4109
  const onListening = () => {
3829
4110
  server.off("error", onError);
3830
- resolve8();
4111
+ resolve9();
3831
4112
  };
3832
4113
  server.once("error", onError);
3833
4114
  server.once("listening", onListening);
@@ -3842,7 +4123,7 @@ async function startUserAttentionEventServer(options = {}) {
3842
4123
  for (const socket of sockets) {
3843
4124
  socket.destroy();
3844
4125
  }
3845
- return new Promise((resolve8, reject) => {
4126
+ return new Promise((resolve9, reject) => {
3846
4127
  server.close((err2) => {
3847
4128
  if (process.platform !== "win32") {
3848
4129
  try {
@@ -3853,7 +4134,7 @@ async function startUserAttentionEventServer(options = {}) {
3853
4134
  if (err2) {
3854
4135
  reject(err2);
3855
4136
  } else {
3856
- resolve8();
4137
+ resolve9();
3857
4138
  }
3858
4139
  });
3859
4140
  });
@@ -3862,7 +4143,7 @@ async function startUserAttentionEventServer(options = {}) {
3862
4143
  }
3863
4144
  async function subscribeUserAttentionEvents(options) {
3864
4145
  const path = resolveUserAttentionIpcPath(options.homeDir);
3865
- return new Promise((resolve8) => {
4146
+ return new Promise((resolve9) => {
3866
4147
  const socket = (0, import_node_net.createConnection)(path);
3867
4148
  let settled = false;
3868
4149
  let buffer2 = "";
@@ -3871,7 +4152,7 @@ async function subscribeUserAttentionEvents(options) {
3871
4152
  return;
3872
4153
  }
3873
4154
  settled = true;
3874
- resolve8({
4155
+ resolve9({
3875
4156
  path,
3876
4157
  connected,
3877
4158
  close() {
@@ -3903,7 +4184,7 @@ async function subscribeUserAttentionEvents(options) {
3903
4184
  }
3904
4185
  async function notifyUserAttentionChanged(homeDir) {
3905
4186
  const path = resolveUserAttentionIpcPath(homeDir);
3906
- return new Promise((resolve8) => {
4187
+ return new Promise((resolve9) => {
3907
4188
  const socket = (0, import_node_net.createConnection)(path);
3908
4189
  let done = false;
3909
4190
  const finish = (ok) => {
@@ -3912,7 +4193,7 @@ async function notifyUserAttentionChanged(homeDir) {
3912
4193
  }
3913
4194
  done = true;
3914
4195
  socket.destroy();
3915
- resolve8(ok);
4196
+ resolve9(ok);
3916
4197
  };
3917
4198
  socket.setTimeout(1e3, () => finish(false));
3918
4199
  socket.once("connect", () => {
@@ -3965,13 +4246,13 @@ function isChangedEventLine(line) {
3965
4246
  return false;
3966
4247
  }
3967
4248
  }
3968
- var import_node_fs6, import_node_net, import_node_path9, USER_ATTENTION_CHANGED;
4249
+ var import_node_fs6, import_node_net, import_node_path10, USER_ATTENTION_CHANGED;
3969
4250
  var init_user_attention_ipc = __esm({
3970
4251
  "src/user-attention-ipc.ts"() {
3971
4252
  "use strict";
3972
4253
  import_node_fs6 = require("node:fs");
3973
4254
  import_node_net = require("node:net");
3974
- import_node_path9 = require("node:path");
4255
+ import_node_path10 = require("node:path");
3975
4256
  init_paths();
3976
4257
  USER_ATTENTION_CHANGED = "user_attention.changed";
3977
4258
  }
@@ -3979,7 +4260,7 @@ var init_user_attention_ipc = __esm({
3979
4260
 
3980
4261
  // ../core/src/openclaw-gateway-config.ts
3981
4262
  function resolveOpenClawGatewayConfigPath(homeDir = resolveA2aTaskHome()) {
3982
- return (0, import_node_path10.join)(homeDir, "openclaw-gateway.json");
4263
+ return (0, import_node_path11.join)(homeDir, "openclaw-gateway.json");
3983
4264
  }
3984
4265
  function readSyncedOpenClawGatewayConfig(homeDir = resolveA2aTaskHome()) {
3985
4266
  const filePath = resolveOpenClawGatewayConfigPath(homeDir);
@@ -4000,12 +4281,12 @@ function readSyncedOpenClawGatewayConfig(homeDir = resolveA2aTaskHome()) {
4000
4281
  source: "openclaw-plugin"
4001
4282
  };
4002
4283
  }
4003
- var import_node_fs7, import_node_path10;
4284
+ var import_node_fs7, import_node_path11;
4004
4285
  var init_openclaw_gateway_config = __esm({
4005
4286
  "../core/src/openclaw-gateway-config.ts"() {
4006
4287
  "use strict";
4007
4288
  import_node_fs7 = require("node:fs");
4008
- import_node_path10 = require("node:path");
4289
+ import_node_path11 = require("node:path");
4009
4290
  init_a2a_paths();
4010
4291
  }
4011
4292
  });
@@ -7152,7 +7433,7 @@ var require_stream = __commonJS({
7152
7433
  };
7153
7434
  duplex._final = function(callback) {
7154
7435
  if (ws.readyState === ws.CONNECTING) {
7155
- ws.once("open", function open() {
7436
+ ws.once("open", function open2() {
7156
7437
  duplex._final(callback);
7157
7438
  });
7158
7439
  return;
@@ -7173,7 +7454,7 @@ var require_stream = __commonJS({
7173
7454
  };
7174
7455
  duplex._write = function(chunk, encoding, callback) {
7175
7456
  if (ws.readyState === ws.CONNECTING) {
7176
- ws.once("open", function open() {
7457
+ ws.once("open", function open2() {
7177
7458
  duplex._write(chunk, encoding, callback);
7178
7459
  });
7179
7460
  return;
@@ -7869,7 +8150,7 @@ function isGatewayStartingError(err2) {
7869
8150
  return String(e?.details?.reason ?? "") === "startup-sidecars" || String(e?.message ?? "").toLowerCase().includes("gateway starting");
7870
8151
  }
7871
8152
  async function sleep2(ms) {
7872
- await new Promise((resolve8) => setTimeout(resolve8, ms));
8153
+ await new Promise((resolve9) => setTimeout(resolve9, ms));
7873
8154
  }
7874
8155
  function readSyncedGatewayConfig(env) {
7875
8156
  try {
@@ -7894,7 +8175,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
7894
8175
  client: {
7895
8176
  id: "gateway-client",
7896
8177
  displayName: "okx-a2a-node",
7897
- version: "0.1.3",
8178
+ version: "0.1.4-beta-520175e226-260702152522",
7898
8179
  platform: "node",
7899
8180
  mode: "backend",
7900
8181
  instanceId
@@ -7905,7 +8186,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
7905
8186
  commands: [],
7906
8187
  permissions: {},
7907
8188
  locale: Intl.DateTimeFormat().resolvedOptions().locale || "en-US",
7908
- userAgent: `okx-a2a-node/${"0.1.3"}`,
8189
+ userAgent: `okx-a2a-node/${"0.1.4-beta-520175e226-260702152522"}`,
7909
8190
  auth: {
7910
8191
  ...config.token ? { token: config.token } : {},
7911
8192
  ...config.password ? { password: config.password } : {}
@@ -8011,7 +8292,7 @@ var init_openclaw_gateway = __esm({
8011
8292
  );
8012
8293
  const ws = wsFactory(this.config.url);
8013
8294
  this.ws = ws;
8014
- await new Promise((resolve8, reject) => {
8295
+ await new Promise((resolve9, reject) => {
8015
8296
  let settled = false;
8016
8297
  const timer = setTimeout(() => {
8017
8298
  if (settled) {
@@ -8030,7 +8311,7 @@ var init_openclaw_gateway = __esm({
8030
8311
  }
8031
8312
  settled = true;
8032
8313
  clearTimeout(timer);
8033
- resolve8();
8314
+ resolve9();
8034
8315
  },
8035
8316
  (err2) => {
8036
8317
  if (settled) {
@@ -8082,7 +8363,7 @@ var init_openclaw_gateway = __esm({
8082
8363
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
8083
8364
  const id = `okx-a2a-${++this.requestSeq}-${(0, import_node_crypto3.randomUUID)()}`;
8084
8365
  const frame = { type: "req", id, method, params };
8085
- return new Promise((resolve8, reject) => {
8366
+ return new Promise((resolve9, reject) => {
8086
8367
  const timer = setTimeout(() => {
8087
8368
  this.pending.delete(id);
8088
8369
  reject(Object.assign(new Error(`OpenClaw gateway request timed out method=${method}`), {
@@ -8091,7 +8372,7 @@ var init_openclaw_gateway = __esm({
8091
8372
  }));
8092
8373
  }, timeoutMs);
8093
8374
  timer.unref?.();
8094
- this.pending.set(id, { method, resolve: resolve8, reject, timer });
8375
+ this.pending.set(id, { method, resolve: resolve9, reject, timer });
8095
8376
  try {
8096
8377
  this.ws.send(JSON.stringify(frame));
8097
8378
  } catch (err2) {
@@ -8554,7 +8835,7 @@ function readGatewaySessionKeysEnv(env) {
8554
8835
  return raw.split(",").map((item) => item.trim()).filter(Boolean);
8555
8836
  }
8556
8837
  function readSingleActiveOriginSessionKey(env) {
8557
- const path = (0, import_node_path11.join)(resolveTaskHome2(env), "run", "gateway-route-origins.json");
8838
+ const path = (0, import_node_path12.join)(resolveTaskHome2(env), "run", "gateway-route-origins.json");
8558
8839
  if (!(0, import_node_fs8.existsSync)(path)) {
8559
8840
  return [];
8560
8841
  }
@@ -8584,7 +8865,7 @@ function readSingleActiveOriginSessionKey(env) {
8584
8865
  }
8585
8866
  }
8586
8867
  function resolveTaskHome2(env) {
8587
- return env.OKX_AGENT_TASK_HOME?.trim() || (0, import_node_path11.join)((0, import_node_os3.homedir)(), ".okx-agent-task");
8868
+ return env.OKX_AGENT_TASK_HOME?.trim() || (0, import_node_path12.join)((0, import_node_os3.homedir)(), ".okx-agent-task");
8588
8869
  }
8589
8870
  function logOpenClawRouteSkip(reason, input) {
8590
8871
  if (reason === "missing_gateway_session_key") {
@@ -8625,13 +8906,13 @@ function safeDecode2(value) {
8625
8906
  return value;
8626
8907
  }
8627
8908
  }
8628
- var import_node_fs8, import_node_os3, import_node_path11, CURRENT_GATEWAY_SESSION_KEYS_ENV, NON_DELIVERY_CHANNELS, ACTIVE_ORIGIN_TTL_MS;
8909
+ var import_node_fs8, import_node_os3, import_node_path12, CURRENT_GATEWAY_SESSION_KEYS_ENV, NON_DELIVERY_CHANNELS, ACTIVE_ORIGIN_TTL_MS;
8629
8910
  var init_openclaw_route = __esm({
8630
8911
  "src/openclaw-route.ts"() {
8631
8912
  "use strict";
8632
8913
  import_node_fs8 = require("node:fs");
8633
8914
  import_node_os3 = require("node:os");
8634
- import_node_path11 = require("node:path");
8915
+ import_node_path12 = require("node:path");
8635
8916
  CURRENT_GATEWAY_SESSION_KEYS_ENV = "OKX_A2A_CURRENT_GATEWAY_SESSION_KEYS";
8636
8917
  NON_DELIVERY_CHANNELS = /* @__PURE__ */ new Set(["heartbeat", "cron", "webhook", "voice"]);
8637
8918
  ACTIVE_ORIGIN_TTL_MS = 30 * 6e4;
@@ -10445,7 +10726,7 @@ var require_path = __commonJS({
10445
10726
  const parts = splitPathRe.exec(truncated);
10446
10727
  return parts ? parts.slice(1) : [];
10447
10728
  }
10448
- function resolve8(...args) {
10729
+ function resolve9(...args) {
10449
10730
  let resolvedPath = "";
10450
10731
  let resolvedAbsolute = false;
10451
10732
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
@@ -10481,8 +10762,8 @@ var require_path = __commonJS({
10481
10762
  return arr.slice(start, end - start + 1);
10482
10763
  }
10483
10764
  function relative(from3, to) {
10484
- from3 = resolve8(from3).slice(1);
10485
- to = resolve8(to).slice(1);
10765
+ from3 = resolve9(from3).slice(1);
10766
+ to = resolve9(to).slice(1);
10486
10767
  const fromParts = trim2(from3.split("/"));
10487
10768
  const toParts = trim2(to.split("/"));
10488
10769
  const length2 = Math.min(fromParts.length, toParts.length);
@@ -10518,7 +10799,7 @@ var require_path = __commonJS({
10518
10799
  function isAbsolute2(path) {
10519
10800
  return path.charAt(0) === "/";
10520
10801
  }
10521
- function join23(...args) {
10802
+ function join24(...args) {
10522
10803
  return normalizePath(args.join("/"));
10523
10804
  }
10524
10805
  function dirname6(path) {
@@ -10543,10 +10824,10 @@ var require_path = __commonJS({
10543
10824
  exports2.basename = basename5;
10544
10825
  exports2.dirname = dirname6;
10545
10826
  exports2.isAbsolute = isAbsolute2;
10546
- exports2.join = join23;
10827
+ exports2.join = join24;
10547
10828
  exports2.normalizePath = normalizePath;
10548
10829
  exports2.relative = relative;
10549
- exports2.resolve = resolve8;
10830
+ exports2.resolve = resolve9;
10550
10831
  }
10551
10832
  });
10552
10833
 
@@ -10565,8 +10846,8 @@ var require_syncpromise = __commonJS({
10565
10846
  States2[States2["REJECTED"] = REJECTED] = "REJECTED";
10566
10847
  })(States || (States = {}));
10567
10848
  function resolvedSyncPromise(value) {
10568
- return new SyncPromise((resolve8) => {
10569
- resolve8(value);
10849
+ return new SyncPromise((resolve9) => {
10850
+ resolve9(value);
10570
10851
  });
10571
10852
  }
10572
10853
  function rejectedSyncPromise(reason) {
@@ -10590,15 +10871,15 @@ var require_syncpromise = __commonJS({
10590
10871
  }
10591
10872
  /** JSDoc */
10592
10873
  then(onfulfilled, onrejected) {
10593
- return new _SyncPromise((resolve8, reject) => {
10874
+ return new _SyncPromise((resolve9, reject) => {
10594
10875
  this._handlers.push([
10595
10876
  false,
10596
10877
  (result) => {
10597
10878
  if (!onfulfilled) {
10598
- resolve8(result);
10879
+ resolve9(result);
10599
10880
  } else {
10600
10881
  try {
10601
- resolve8(onfulfilled(result));
10882
+ resolve9(onfulfilled(result));
10602
10883
  } catch (e) {
10603
10884
  reject(e);
10604
10885
  }
@@ -10609,7 +10890,7 @@ var require_syncpromise = __commonJS({
10609
10890
  reject(reason);
10610
10891
  } else {
10611
10892
  try {
10612
- resolve8(onrejected(reason));
10893
+ resolve9(onrejected(reason));
10613
10894
  } catch (e) {
10614
10895
  reject(e);
10615
10896
  }
@@ -10625,7 +10906,7 @@ var require_syncpromise = __commonJS({
10625
10906
  }
10626
10907
  /** JSDoc */
10627
10908
  finally(onfinally) {
10628
- return new _SyncPromise((resolve8, reject) => {
10909
+ return new _SyncPromise((resolve9, reject) => {
10629
10910
  let val;
10630
10911
  let isRejected;
10631
10912
  return this.then(
@@ -10648,7 +10929,7 @@ var require_syncpromise = __commonJS({
10648
10929
  reject(val);
10649
10930
  return;
10650
10931
  }
10651
- resolve8(val);
10932
+ resolve9(val);
10652
10933
  });
10653
10934
  });
10654
10935
  }
@@ -10738,21 +11019,21 @@ var require_promisebuffer = __commonJS({
10738
11019
  return task;
10739
11020
  }
10740
11021
  function drain(timeout) {
10741
- return new syncpromise.SyncPromise((resolve8, reject) => {
11022
+ return new syncpromise.SyncPromise((resolve9, reject) => {
10742
11023
  let counter = buffer2.length;
10743
11024
  if (!counter) {
10744
- return resolve8(true);
11025
+ return resolve9(true);
10745
11026
  }
10746
11027
  const capturedSetTimeout = setTimeout(() => {
10747
11028
  if (timeout && timeout > 0) {
10748
- resolve8(false);
11029
+ resolve9(false);
10749
11030
  }
10750
11031
  }, timeout);
10751
11032
  buffer2.forEach((item) => {
10752
11033
  void syncpromise.resolvedSyncPromise(item).then(() => {
10753
11034
  if (!--counter) {
10754
11035
  clearTimeout(capturedSetTimeout);
10755
- resolve8(true);
11036
+ resolve9(true);
10756
11037
  }
10757
11038
  }, reject);
10758
11039
  });
@@ -11954,17 +12235,17 @@ var require_eventProcessors = __commonJS({
11954
12235
  getGlobalEventProcessors().push(callback);
11955
12236
  }
11956
12237
  function notifyEventProcessors(processors, event, hint, index2 = 0) {
11957
- return new utils.SyncPromise((resolve8, reject) => {
12238
+ return new utils.SyncPromise((resolve9, reject) => {
11958
12239
  const processor = processors[index2];
11959
12240
  if (event === null || typeof processor !== "function") {
11960
- resolve8(event);
12241
+ resolve9(event);
11961
12242
  } else {
11962
12243
  const result = processor({ ...event }, hint);
11963
12244
  (typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && processor.id && result === null && utils.logger.log(`Event processor "${processor.id}" dropped event`);
11964
12245
  if (utils.isThenable(result)) {
11965
- void result.then((final) => notifyEventProcessors(processors, final, hint, index2 + 1).then(resolve8)).then(null, reject);
12246
+ void result.then((final) => notifyEventProcessors(processors, final, hint, index2 + 1).then(resolve9)).then(null, reject);
11966
12247
  } else {
11967
- void notifyEventProcessors(processors, result, hint, index2 + 1).then(resolve8).then(null, reject);
12248
+ void notifyEventProcessors(processors, result, hint, index2 + 1).then(resolve9).then(null, reject);
11968
12249
  }
11969
12250
  }
11970
12251
  });
@@ -15118,18 +15399,18 @@ var require_baseclient = __commonJS({
15118
15399
  * `false` otherwise
15119
15400
  */
15120
15401
  _isClientDoneProcessing(timeout) {
15121
- return new utils.SyncPromise((resolve8) => {
15402
+ return new utils.SyncPromise((resolve9) => {
15122
15403
  let ticked = 0;
15123
15404
  const tick = 1;
15124
15405
  const interval = setInterval(() => {
15125
15406
  if (this._numProcessing == 0) {
15126
15407
  clearInterval(interval);
15127
- resolve8(true);
15408
+ resolve9(true);
15128
15409
  } else {
15129
15410
  ticked += tick;
15130
15411
  if (timeout && ticked >= timeout) {
15131
15412
  clearInterval(interval);
15132
- resolve8(false);
15413
+ resolve9(false);
15133
15414
  }
15134
15415
  }
15135
15416
  }, tick);
@@ -19779,12 +20060,12 @@ var require_promisify = __commonJS({
19779
20060
  Object.defineProperty(exports2, "__esModule", { value: true });
19780
20061
  function promisify3(fn) {
19781
20062
  return function(req, opts) {
19782
- return new Promise((resolve8, reject) => {
20063
+ return new Promise((resolve9, reject) => {
19783
20064
  fn.call(this, req, opts, (err2, rtn) => {
19784
20065
  if (err2) {
19785
20066
  reject(err2);
19786
20067
  } else {
19787
- resolve8(rtn);
20068
+ resolve9(rtn);
19788
20069
  }
19789
20070
  });
19790
20071
  });
@@ -19988,7 +20269,7 @@ var require_parse_proxy_response = __commonJS({
19988
20269
  var debug_1 = __importDefault(require_src());
19989
20270
  var debug = debug_1.default("https-proxy-agent:parse-proxy-response");
19990
20271
  function parseProxyResponse(socket) {
19991
- return new Promise((resolve8, reject) => {
20272
+ return new Promise((resolve9, reject) => {
19992
20273
  let buffersLength = 0;
19993
20274
  const buffers = [];
19994
20275
  function read2() {
@@ -20028,7 +20309,7 @@ var require_parse_proxy_response = __commonJS({
20028
20309
  const firstLine = buffered.toString("ascii", 0, buffered.indexOf("\r\n"));
20029
20310
  const statusCode = +firstLine.split(" ")[1];
20030
20311
  debug("got proxy server response: %o", firstLine);
20031
- resolve8({
20312
+ resolve9({
20032
20313
  statusCode,
20033
20314
  buffered
20034
20315
  });
@@ -20049,11 +20330,11 @@ var require_agent = __commonJS({
20049
20330
  "use strict";
20050
20331
  var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P2, generator) {
20051
20332
  function adopt(value) {
20052
- return value instanceof P2 ? value : new P2(function(resolve8) {
20053
- resolve8(value);
20333
+ return value instanceof P2 ? value : new P2(function(resolve9) {
20334
+ resolve9(value);
20054
20335
  });
20055
20336
  }
20056
- return new (P2 || (P2 = Promise))(function(resolve8, reject) {
20337
+ return new (P2 || (P2 = Promise))(function(resolve9, reject) {
20057
20338
  function fulfilled(value) {
20058
20339
  try {
20059
20340
  step(generator.next(value));
@@ -20069,7 +20350,7 @@ var require_agent = __commonJS({
20069
20350
  }
20070
20351
  }
20071
20352
  function step(result) {
20072
- result.done ? resolve8(result.value) : adopt(result.value).then(fulfilled, rejected);
20353
+ result.done ? resolve9(result.value) : adopt(result.value).then(fulfilled, rejected);
20073
20354
  }
20074
20355
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20075
20356
  });
@@ -20280,7 +20561,7 @@ var require_http = __commonJS({
20280
20561
  function createRequestExecutor(options, httpModule, agent) {
20281
20562
  const { hostname, pathname, port, protocol, search } = new url.URL(options.url);
20282
20563
  return function makeRequest(request) {
20283
- return new Promise((resolve8, reject) => {
20564
+ return new Promise((resolve9, reject) => {
20284
20565
  let body = streamFromBody(request.body);
20285
20566
  const headers = { ...options.headers };
20286
20567
  if (request.body.length > GZIP_THRESHOLD) {
@@ -20306,7 +20587,7 @@ var require_http = __commonJS({
20306
20587
  res.setEncoding("utf8");
20307
20588
  const retryAfterHeader = _nullishCoalesce(res.headers["retry-after"], () => null);
20308
20589
  const rateLimitsHeader = _nullishCoalesce(res.headers["x-sentry-rate-limits"], () => null);
20309
- resolve8({
20590
+ resolve9({
20310
20591
  statusCode: res.statusCode,
20311
20592
  headers: {
20312
20593
  "retry-after": retryAfterHeader,
@@ -20574,7 +20855,7 @@ var require_websocket2 = __commonJS({
20574
20855
  };
20575
20856
  async function createWebSocketClient(rawUrl) {
20576
20857
  const parts = url.parse(rawUrl);
20577
- return new Promise((resolve8, reject) => {
20858
+ return new Promise((resolve9, reject) => {
20578
20859
  const key = crypto3.randomBytes(16).toString("base64");
20579
20860
  const digest2 = createKey(key);
20580
20861
  const req = http2.request({
@@ -20605,7 +20886,7 @@ var require_websocket2 = __commonJS({
20605
20886
  return;
20606
20887
  }
20607
20888
  const client = new WebSocketInterface(socket);
20608
- resolve8(client);
20889
+ resolve9(client);
20609
20890
  });
20610
20891
  req.on("error", (err2) => {
20611
20892
  reject(err2);
@@ -21934,10 +22215,10 @@ var require_contextlines = __commonJS({
21934
22215
  var FILE_CONTENT_CACHE = new lru_map.LRUMap(100);
21935
22216
  var DEFAULT_LINES_OF_CONTEXT = 7;
21936
22217
  function readTextFileAsync(path) {
21937
- return new Promise((resolve8, reject) => {
22218
+ return new Promise((resolve9, reject) => {
21938
22219
  fs.readFile(path, "utf8", (err2, data) => {
21939
22220
  if (err2) reject(err2);
21940
- else resolve8(data);
22221
+ else resolve9(data);
21941
22222
  });
21942
22223
  });
21943
22224
  }
@@ -22247,13 +22528,13 @@ var require_context = __commonJS({
22247
22528
  version: `10.${Number(os.release().split(".")[0]) - 4}`
22248
22529
  };
22249
22530
  try {
22250
- const output4 = await new Promise((resolve8, reject) => {
22531
+ const output4 = await new Promise((resolve9, reject) => {
22251
22532
  child_process.execFile("/usr/bin/sw_vers", (error, stdout) => {
22252
22533
  if (error) {
22253
22534
  reject(error);
22254
22535
  return;
22255
22536
  }
22256
- resolve8(stdout);
22537
+ resolve9(stdout);
22257
22538
  });
22258
22539
  });
22259
22540
  darwinInfo.name = matchFirst(/^ProductName:\s+(.*)$/m, output4);
@@ -25032,7 +25313,7 @@ function writeAiPermissionPresetToConfig(homeDir, preset) {
25032
25313
  return normalized;
25033
25314
  }
25034
25315
  function resolveTaskConfigPath(homeDir) {
25035
- return (0, import_node_path12.join)(homeDir, "config.toml");
25316
+ return (0, import_node_path13.join)(homeDir, "config.toml");
25036
25317
  }
25037
25318
  function normalizeAiPermissionPreset(value, source) {
25038
25319
  const normalized = value.trim().toLowerCase();
@@ -25105,12 +25386,12 @@ function upsertSimpleTomlStringValue(text, section, key, value) {
25105
25386
  function escapeRegExp(value) {
25106
25387
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25107
25388
  }
25108
- var import_node_fs9, import_node_path12, AI_PERMISSION_PRESETS, DEFAULT_AI_PERMISSION_PRESET;
25389
+ var import_node_fs9, import_node_path13, AI_PERMISSION_PRESETS, DEFAULT_AI_PERMISSION_PRESET;
25109
25390
  var init_task_config = __esm({
25110
25391
  "src/task-config.ts"() {
25111
25392
  "use strict";
25112
25393
  import_node_fs9 = require("node:fs");
25113
- import_node_path12 = require("node:path");
25394
+ import_node_path13 = require("node:path");
25114
25395
  init_paths();
25115
25396
  AI_PERMISSION_PRESETS = ["bypass", "auto"];
25116
25397
  DEFAULT_AI_PERMISSION_PRESET = "bypass";
@@ -25125,12 +25406,255 @@ var init_sentry_config = __esm({
25125
25406
  environment = process.env.SENTRY_ENV === "dev" ? "dev" : "prod";
25126
25407
  SENTRY_CONFIG = {
25127
25408
  projectName: "okx/openclaw-okx-a2a-extension",
25128
- release: "0.1.3",
25409
+ release: "0.1.4-beta-520175e226-260702152522",
25129
25410
  environment
25130
25411
  };
25131
25412
  }
25132
25413
  });
25133
25414
 
25415
+ // src/autostart-windows.ts
25416
+ function resolveWindowsAutostartPaths(homeDir) {
25417
+ const resolvedHome = homeDir ?? resolveTaskPaths().homeDir;
25418
+ const autostartDir = (0, import_node_path14.join)(resolvedHome, "autostart");
25419
+ return {
25420
+ autostartDir,
25421
+ vbsPath: (0, import_node_path14.join)(autostartDir, VBS_FILE_NAME),
25422
+ cmdPath: (0, import_node_path14.join)(autostartDir, CMD_FILE_NAME)
25423
+ };
25424
+ }
25425
+ function escapeVbsString(value) {
25426
+ return value.replace(/"/g, '""');
25427
+ }
25428
+ function escapeCmdBatchValue(value) {
25429
+ return value.replace(/%/g, "%%");
25430
+ }
25431
+ function buildAutostartVbs(cmdPath) {
25432
+ const commandLine = `cmd.exe /d /s /c ""${cmdPath}""`;
25433
+ const lines = [
25434
+ "' OKX A2A daemon autostart wrapper: run the launcher .cmd fully hidden.",
25435
+ "Option Explicit",
25436
+ "Dim okxA2aShell",
25437
+ 'Set okxA2aShell = CreateObject("WScript.Shell")',
25438
+ `okxA2aShell.Run "${escapeVbsString(commandLine)}", 0, False`
25439
+ ];
25440
+ return `${lines.join("\r\n")}\r
25441
+ `;
25442
+ }
25443
+ function buildAutostartCmd(options) {
25444
+ const lines = ["@echo off", "chcp 65001 >nul"];
25445
+ const pathValue = options.pathValue?.trim();
25446
+ if (pathValue) {
25447
+ lines.push(`set "PATH=${escapeCmdBatchValue(pathValue)}"`);
25448
+ }
25449
+ lines.push(`set "OKX_AGENT_TASK_HOME=${escapeCmdBatchValue(options.taskHome)}"`);
25450
+ lines.push(
25451
+ `"${escapeCmdBatchValue(options.execPath)}" "${escapeCmdBatchValue(options.cliPath)}" run >> "${escapeCmdBatchValue(options.logPath)}" 2>&1`
25452
+ );
25453
+ return `${lines.join("\r\n")}\r
25454
+ `;
25455
+ }
25456
+ function buildSchtasksCreateArgs(vbsPath, taskName = TASK_NAME) {
25457
+ return [
25458
+ "/Create",
25459
+ "/SC",
25460
+ "ONLOGON",
25461
+ "/TN",
25462
+ taskName,
25463
+ "/TR",
25464
+ `wscript.exe "${vbsPath}"`,
25465
+ "/F"
25466
+ ];
25467
+ }
25468
+ function buildSchtasksDeleteArgs(taskName = TASK_NAME) {
25469
+ return ["/Delete", "/TN", taskName, "/F"];
25470
+ }
25471
+ function buildSchtasksEndArgs(taskName = TASK_NAME) {
25472
+ return ["/End", "/TN", taskName];
25473
+ }
25474
+ function buildSchtasksRunArgs(taskName = TASK_NAME) {
25475
+ return ["/Run", "/TN", taskName];
25476
+ }
25477
+ function buildSchtasksQueryArgs(taskName = TASK_NAME) {
25478
+ return ["/Query", "/TN", taskName, "/FO", "LIST"];
25479
+ }
25480
+ function truncateForLog(value) {
25481
+ const text = String(value ?? "").trim();
25482
+ if (text.length <= LOG_SNIPPET_LIMIT) {
25483
+ return text;
25484
+ }
25485
+ return `${text.slice(0, LOG_SNIPPET_LIMIT)}...(truncated)`;
25486
+ }
25487
+ function resolveWindowsCliPath() {
25488
+ const entry = process.argv[1];
25489
+ if (!entry) {
25490
+ errorWithTimestamp(`${WIN_COMPAT_LOG_PREFIX} autostart: process.argv[1] is empty, cannot resolve okx-a2a CLI path`);
25491
+ throw new Error("Unable to resolve current okx-a2a CLI path");
25492
+ }
25493
+ return (0, import_node_path14.resolve)(entry);
25494
+ }
25495
+ function runSchtasks(operation, args) {
25496
+ const result = (0, import_node_child_process4.spawnSync)(SCHTASKS_BIN, args, {
25497
+ windowsHide: true,
25498
+ encoding: "utf8",
25499
+ timeout: SCHTASKS_TIMEOUT_MS
25500
+ });
25501
+ const stdout = String(result.stdout ?? "");
25502
+ const stderr = String(result.stderr ?? "");
25503
+ const spawnError = result.error;
25504
+ const ok = !spawnError && result.status === 0;
25505
+ const detail = `${WIN_COMPAT_LOG_PREFIX} schtasks ${operation}: args=[${SCHTASKS_BIN} ${args.join(" ")}] exit=${result.status === null ? "null" : result.status} errorCode=${spawnError?.code ?? "none"} stdout=${truncateForLog(stdout)} stderr=${truncateForLog(stderr)}`;
25506
+ if (ok) {
25507
+ logWithTimestamp(detail);
25508
+ } else {
25509
+ errorWithTimestamp(detail);
25510
+ }
25511
+ return {
25512
+ ok,
25513
+ exitCode: result.status,
25514
+ stdout,
25515
+ stderr,
25516
+ ...spawnError ? { errorMessage: spawnError.message } : {}
25517
+ };
25518
+ }
25519
+ function schtasksOutputSummary(result) {
25520
+ return truncateForLog(result.errorMessage || result.stderr || result.stdout);
25521
+ }
25522
+ async function installWindowsAutostart() {
25523
+ const taskPaths = resolveTaskPaths();
25524
+ const paths = resolveWindowsAutostartPaths(taskPaths.homeDir);
25525
+ const execPath = process.execPath;
25526
+ const cliPath = resolveWindowsCliPath();
25527
+ const pathValue = process.env.PATH?.trim() || "";
25528
+ await (0, import_promises6.mkdir)(paths.autostartDir, { recursive: true });
25529
+ await (0, import_promises6.mkdir)(taskPaths.logsDir, { recursive: true });
25530
+ const cmdContent = buildAutostartCmd({
25531
+ execPath,
25532
+ cliPath,
25533
+ taskHome: taskPaths.homeDir,
25534
+ logPath: taskPaths.listenerLogPath,
25535
+ ...pathValue ? { pathValue } : {}
25536
+ });
25537
+ await (0, import_promises6.writeFile)(paths.cmdPath, cmdContent, "utf8");
25538
+ await (0, import_promises6.writeFile)(paths.vbsPath, "\uFEFF" + buildAutostartVbs(paths.cmdPath), "utf16le");
25539
+ logWithTimestamp(
25540
+ `${WIN_COMPAT_LOG_PREFIX} autostart install: wrote cmd=${paths.cmdPath} vbs=${paths.vbsPath} node=${execPath} cli=${cliPath} taskHome=${taskPaths.homeDir} log=${taskPaths.listenerLogPath}`
25541
+ );
25542
+ const create2 = runSchtasks("create", buildSchtasksCreateArgs(paths.vbsPath));
25543
+ if (!create2.ok) {
25544
+ throw new Error(
25545
+ `schtasks /Create failed for task "${TASK_NAME}" (exit=${create2.exitCode}): ${schtasksOutputSummary(create2)}`
25546
+ );
25547
+ }
25548
+ const run = runSchtasks("run", buildSchtasksRunArgs());
25549
+ if (!run.ok) {
25550
+ throw new Error(
25551
+ `schtasks /Run failed for task "${TASK_NAME}" (exit=${run.exitCode}): ${schtasksOutputSummary(run)}`
25552
+ );
25553
+ }
25554
+ return { platform: "windows-schtasks", path: paths.vbsPath };
25555
+ }
25556
+ async function uninstallWindowsAutostart() {
25557
+ const paths = resolveWindowsAutostartPaths();
25558
+ const del = runSchtasks("delete", buildSchtasksDeleteArgs());
25559
+ if (!del.ok) {
25560
+ const query = runSchtasks("query-after-delete-failure", buildSchtasksQueryArgs());
25561
+ if (query.ok) {
25562
+ throw new Error(
25563
+ `schtasks /Delete failed for task "${TASK_NAME}" (exit=${del.exitCode}) and the task still exists: ${schtasksOutputSummary(del)}`
25564
+ );
25565
+ }
25566
+ logWithTimestamp(
25567
+ `${WIN_COMPAT_LOG_PREFIX} autostart uninstall: task "${TASK_NAME}" already absent (delete exit=${del.exitCode}); continuing`
25568
+ );
25569
+ }
25570
+ await (0, import_promises6.rm)(paths.vbsPath, { force: true });
25571
+ await (0, import_promises6.rm)(paths.cmdPath, { force: true });
25572
+ logWithTimestamp(
25573
+ `${WIN_COMPAT_LOG_PREFIX} autostart uninstall: removed ${paths.vbsPath} and ${paths.cmdPath}`
25574
+ );
25575
+ return { platform: "windows-schtasks", path: paths.vbsPath };
25576
+ }
25577
+ async function stopWindowsAutostart() {
25578
+ const paths = resolveWindowsAutostartPaths();
25579
+ const end = runSchtasks("end", buildSchtasksEndArgs());
25580
+ const output4 = schtasksOutputSummary(end);
25581
+ const note = "schtasks /End only stops instances launched by the Task Scheduler; a manually started daemon must be stopped with `okx-a2a daemon stop`.";
25582
+ const message = output4 ? `${note} ${output4}` : note;
25583
+ return {
25584
+ platform: "windows-schtasks",
25585
+ path: paths.vbsPath,
25586
+ stopped: end.ok,
25587
+ message
25588
+ };
25589
+ }
25590
+ async function restartWindowsAutostart() {
25591
+ const paths = resolveWindowsAutostartPaths();
25592
+ const query = runSchtasks("query-before-restart", buildSchtasksQueryArgs());
25593
+ if (!query.ok) {
25594
+ logWithTimestamp(
25595
+ `${WIN_COMPAT_LOG_PREFIX} autostart restart: task "${TASK_NAME}" is not registered (query exit=${query.exitCode}); reinstalling`
25596
+ );
25597
+ const installed = await installWindowsAutostart();
25598
+ const queryOutput = schtasksOutputSummary(query);
25599
+ return {
25600
+ ...installed,
25601
+ restarted: true,
25602
+ message: `scheduled task was not registered; reinstalled autostart.${queryOutput ? ` ${queryOutput}` : ""}`
25603
+ };
25604
+ }
25605
+ runSchtasks("end-before-restart", buildSchtasksEndArgs());
25606
+ const run = runSchtasks("run", buildSchtasksRunArgs());
25607
+ const output4 = schtasksOutputSummary(run);
25608
+ return {
25609
+ platform: "windows-schtasks",
25610
+ path: paths.vbsPath,
25611
+ restarted: run.ok,
25612
+ ...output4 ? { message: output4 } : {}
25613
+ };
25614
+ }
25615
+ function isWindowsAutostartInstalled() {
25616
+ const query = runSchtasks("query", buildSchtasksQueryArgs());
25617
+ return query.ok;
25618
+ }
25619
+ function windowsAutostartStatus() {
25620
+ const taskPaths = resolveTaskPaths();
25621
+ const paths = resolveWindowsAutostartPaths(taskPaths.homeDir);
25622
+ const pathValue = process.env.PATH?.trim() || "";
25623
+ const cmdContent = buildAutostartCmd({
25624
+ execPath: process.execPath,
25625
+ cliPath: resolveWindowsCliPath(),
25626
+ taskHome: taskPaths.homeDir,
25627
+ logPath: taskPaths.listenerLogPath,
25628
+ ...pathValue ? { pathValue } : {}
25629
+ });
25630
+ return [
25631
+ `Task Scheduler task: ${TASK_NAME}`,
25632
+ "",
25633
+ `REM ${paths.cmdPath}`,
25634
+ cmdContent,
25635
+ `' ${paths.vbsPath}`,
25636
+ buildAutostartVbs(paths.cmdPath)
25637
+ ].join("\n");
25638
+ }
25639
+ var import_node_child_process4, import_promises6, import_node_path14, TASK_NAME, VBS_FILE_NAME, CMD_FILE_NAME, SCHTASKS_BIN, SCHTASKS_TIMEOUT_MS, LOG_SNIPPET_LIMIT;
25640
+ var init_autostart_windows = __esm({
25641
+ "src/autostart-windows.ts"() {
25642
+ "use strict";
25643
+ import_node_child_process4 = require("node:child_process");
25644
+ import_promises6 = require("node:fs/promises");
25645
+ import_node_path14 = require("node:path");
25646
+ init_log();
25647
+ init_paths();
25648
+ init_win_spawn();
25649
+ TASK_NAME = "OKX A2A Daemon";
25650
+ VBS_FILE_NAME = "launch-okx-a2a-daemon.vbs";
25651
+ CMD_FILE_NAME = "launch-okx-a2a-daemon.cmd";
25652
+ SCHTASKS_BIN = "schtasks.exe";
25653
+ SCHTASKS_TIMEOUT_MS = 15e3;
25654
+ LOG_SNIPPET_LIMIT = 500;
25655
+ }
25656
+ });
25657
+
25134
25658
  // src/autostart.ts
25135
25659
  var autostart_exports = {};
25136
25660
  __export(autostart_exports, {
@@ -25156,17 +25680,17 @@ __export(autostart_exports, {
25156
25680
  uninstallSystemdAutostart: () => uninstallSystemdAutostart
25157
25681
  });
25158
25682
  function resolveSystemdAutostartPaths(home = (0, import_node_os4.homedir)()) {
25159
- const serviceDir = (0, import_node_path13.join)(home, ".config", "systemd", "user");
25683
+ const serviceDir = (0, import_node_path15.join)(home, ".config", "systemd", "user");
25160
25684
  return {
25161
25685
  serviceDir,
25162
- servicePath: (0, import_node_path13.join)(serviceDir, SERVICE_NAME)
25686
+ servicePath: (0, import_node_path15.join)(serviceDir, SERVICE_NAME)
25163
25687
  };
25164
25688
  }
25165
25689
  function resolveLaunchdAutostartPaths(home = (0, import_node_os4.homedir)()) {
25166
- const agentDir = (0, import_node_path13.join)(home, "Library", "LaunchAgents");
25690
+ const agentDir = (0, import_node_path15.join)(home, "Library", "LaunchAgents");
25167
25691
  return {
25168
25692
  agentDir,
25169
- plistPath: (0, import_node_path13.join)(agentDir, LAUNCHD_PLIST_NAME)
25693
+ plistPath: (0, import_node_path15.join)(agentDir, LAUNCHD_PLIST_NAME)
25170
25694
  };
25171
25695
  }
25172
25696
  function quoteSystemdArg(value) {
@@ -25180,7 +25704,7 @@ function resolveCliPath() {
25180
25704
  if (!entry) {
25181
25705
  throw new Error("Unable to resolve current okx-a2a CLI path");
25182
25706
  }
25183
- return (0, import_node_path13.resolve)(entry);
25707
+ return (0, import_node_path15.resolve)(entry);
25184
25708
  }
25185
25709
  function buildSystemdUserService() {
25186
25710
  const taskHome2 = resolveTaskHome();
@@ -25288,8 +25812,8 @@ function launchdDomain() {
25288
25812
  }
25289
25813
  async function installSystemdAutostart() {
25290
25814
  const paths = resolveSystemdAutostartPaths();
25291
- await (0, import_promises5.mkdir)(paths.serviceDir, { recursive: true });
25292
- await (0, import_promises5.writeFile)(paths.servicePath, buildSystemdUserService(), "utf8");
25815
+ await (0, import_promises7.mkdir)(paths.serviceDir, { recursive: true });
25816
+ await (0, import_promises7.writeFile)(paths.servicePath, buildSystemdUserService(), "utf8");
25293
25817
  await runSystemctl(["daemon-reload"]);
25294
25818
  await runSystemctl(["enable", "--now", SERVICE_NAME]);
25295
25819
  return { platform: "linux-systemd", path: paths.servicePath };
@@ -25304,7 +25828,7 @@ async function uninstallSystemdAutostart() {
25304
25828
  throw err2;
25305
25829
  }
25306
25830
  }
25307
- await (0, import_promises5.rm)(paths.servicePath, { force: true });
25831
+ await (0, import_promises7.rm)(paths.servicePath, { force: true });
25308
25832
  await runSystemctl(["daemon-reload"]);
25309
25833
  return { platform: "linux-systemd", path: paths.servicePath };
25310
25834
  }
@@ -25322,7 +25846,7 @@ async function stopSystemdAutostart() {
25322
25846
  }
25323
25847
  async function restartSystemdAutostart() {
25324
25848
  const paths = resolveSystemdAutostartPaths();
25325
- if (!(0, import_node_fs10.existsSync)(paths.servicePath)) {
25849
+ if (!(0, import_node_fs11.existsSync)(paths.servicePath)) {
25326
25850
  return {
25327
25851
  platform: "linux-systemd",
25328
25852
  path: paths.servicePath,
@@ -25354,9 +25878,9 @@ function printSystemdAutostartUnit() {
25354
25878
  async function installLaunchdAutostart() {
25355
25879
  const paths = resolveLaunchdAutostartPaths();
25356
25880
  const taskPaths = resolveTaskPaths();
25357
- await (0, import_promises5.mkdir)(paths.agentDir, { recursive: true });
25358
- await (0, import_promises5.mkdir)(taskPaths.logsDir, { recursive: true });
25359
- await (0, import_promises5.writeFile)(paths.plistPath, buildLaunchdPlist(), "utf8");
25881
+ await (0, import_promises7.mkdir)(paths.agentDir, { recursive: true });
25882
+ await (0, import_promises7.mkdir)(taskPaths.logsDir, { recursive: true });
25883
+ await (0, import_promises7.writeFile)(paths.plistPath, buildLaunchdPlist(), "utf8");
25360
25884
  const domain = launchdDomain();
25361
25885
  await runLaunchctl(["bootout", domain, paths.plistPath], { tolerateFailure: true });
25362
25886
  await runLaunchctl(["bootstrap", domain, paths.plistPath]);
@@ -25367,7 +25891,7 @@ async function installLaunchdAutostart() {
25367
25891
  async function uninstallLaunchdAutostart() {
25368
25892
  const paths = resolveLaunchdAutostartPaths();
25369
25893
  await runLaunchctl(["bootout", launchdDomain(), paths.plistPath], { tolerateFailure: true });
25370
- await (0, import_promises5.rm)(paths.plistPath, { force: true });
25894
+ await (0, import_promises7.rm)(paths.plistPath, { force: true });
25371
25895
  return { platform: "macos-launchd", path: paths.plistPath };
25372
25896
  }
25373
25897
  async function stopLaunchdAutostart() {
@@ -25384,7 +25908,7 @@ async function stopLaunchdAutostart() {
25384
25908
  }
25385
25909
  async function restartLaunchdAutostart() {
25386
25910
  const paths = resolveLaunchdAutostartPaths();
25387
- if (!(0, import_node_fs10.existsSync)(paths.plistPath)) {
25911
+ if (!(0, import_node_fs11.existsSync)(paths.plistPath)) {
25388
25912
  return {
25389
25913
  platform: "macos-launchd",
25390
25914
  path: paths.plistPath,
@@ -25421,6 +25945,9 @@ async function installAutostart() {
25421
25945
  if (process.platform === "darwin") {
25422
25946
  return installLaunchdAutostart();
25423
25947
  }
25948
+ if (process.platform === "win32") {
25949
+ return installWindowsAutostart();
25950
+ }
25424
25951
  throw new Error(`autostart is not supported on ${process.platform}`);
25425
25952
  }
25426
25953
  async function uninstallAutostart() {
@@ -25430,6 +25957,9 @@ async function uninstallAutostart() {
25430
25957
  if (process.platform === "darwin") {
25431
25958
  return uninstallLaunchdAutostart();
25432
25959
  }
25960
+ if (process.platform === "win32") {
25961
+ return uninstallWindowsAutostart();
25962
+ }
25433
25963
  throw new Error(`autostart is not supported on ${process.platform}`);
25434
25964
  }
25435
25965
  async function stopAutostart() {
@@ -25439,6 +25969,9 @@ async function stopAutostart() {
25439
25969
  if (process.platform === "darwin") {
25440
25970
  return stopLaunchdAutostart();
25441
25971
  }
25972
+ if (process.platform === "win32") {
25973
+ return stopWindowsAutostart();
25974
+ }
25442
25975
  throw new Error(`autostart is not supported on ${process.platform}`);
25443
25976
  }
25444
25977
  async function restartAutostart() {
@@ -25448,14 +25981,20 @@ async function restartAutostart() {
25448
25981
  if (process.platform === "darwin") {
25449
25982
  return restartLaunchdAutostart();
25450
25983
  }
25984
+ if (process.platform === "win32") {
25985
+ return restartWindowsAutostart();
25986
+ }
25451
25987
  throw new Error(`autostart is not supported on ${process.platform}`);
25452
25988
  }
25453
25989
  function isAutostartInstalled() {
25454
25990
  if (process.platform === "linux") {
25455
- return (0, import_node_fs10.existsSync)(resolveSystemdAutostartPaths().servicePath);
25991
+ return (0, import_node_fs11.existsSync)(resolveSystemdAutostartPaths().servicePath);
25456
25992
  }
25457
25993
  if (process.platform === "darwin") {
25458
- return (0, import_node_fs10.existsSync)(resolveLaunchdAutostartPaths().plistPath);
25994
+ return (0, import_node_fs11.existsSync)(resolveLaunchdAutostartPaths().plistPath);
25995
+ }
25996
+ if (process.platform === "win32") {
25997
+ return isWindowsAutostartInstalled();
25459
25998
  }
25460
25999
  return false;
25461
26000
  }
@@ -25466,20 +26005,24 @@ function autostartStatus() {
25466
26005
  if (process.platform === "darwin") {
25467
26006
  return printLaunchdPlist();
25468
26007
  }
26008
+ if (process.platform === "win32") {
26009
+ return windowsAutostartStatus();
26010
+ }
25469
26011
  throw new Error(`autostart is not supported on ${process.platform}`);
25470
26012
  }
25471
- var import_node_child_process3, import_node_fs10, import_promises5, import_node_os4, import_node_path13, import_node_util, execFileAsync, SERVICE_NAME, LAUNCHD_LABEL, LAUNCHD_PLIST_NAME;
26013
+ var import_node_child_process5, import_node_fs11, import_promises7, import_node_os4, import_node_path15, import_node_util, execFileAsync, SERVICE_NAME, LAUNCHD_LABEL, LAUNCHD_PLIST_NAME;
25472
26014
  var init_autostart = __esm({
25473
26015
  "src/autostart.ts"() {
25474
26016
  "use strict";
25475
- import_node_child_process3 = require("node:child_process");
25476
- import_node_fs10 = require("node:fs");
25477
- import_promises5 = require("node:fs/promises");
26017
+ import_node_child_process5 = require("node:child_process");
26018
+ import_node_fs11 = require("node:fs");
26019
+ import_promises7 = require("node:fs/promises");
25478
26020
  import_node_os4 = require("node:os");
25479
- import_node_path13 = require("node:path");
26021
+ import_node_path15 = require("node:path");
25480
26022
  import_node_util = require("node:util");
26023
+ init_autostart_windows();
25481
26024
  init_paths();
25482
- execFileAsync = (0, import_node_util.promisify)(import_node_child_process3.execFile);
26025
+ execFileAsync = (0, import_node_util.promisify)(import_node_child_process5.execFile);
25483
26026
  SERVICE_NAME = "okx-a2a.service";
25484
26027
  LAUNCHD_LABEL = "com.okx.a2a";
25485
26028
  LAUNCHD_PLIST_NAME = `${LAUNCHD_LABEL}.plist`;
@@ -25487,7 +26030,7 @@ var init_autostart = __esm({
25487
26030
  });
25488
26031
 
25489
26032
  // ../core/src/xmtp-sdk/onchainos/bin.ts
25490
- async function resolve3() {
26033
+ async function resolve4() {
25491
26034
  if (resolvedBin) {
25492
26035
  return resolvedBin;
25493
26036
  }
@@ -25497,20 +26040,30 @@ async function resolve3() {
25497
26040
  resolvedBin = envBin;
25498
26041
  return resolvedBin;
25499
26042
  }
25500
- try {
25501
- const shell = process.env.SHELL || "/bin/bash";
25502
- const { stdout } = await execFileAsync2(shell, ["-lc", "command -v onchainos"]);
25503
- const bin = extractExecutablePath(stdout);
25504
- if (bin) {
25505
- logWithTimestamp(`[onchainos] resolved binary via shell: ${bin}`);
25506
- resolvedBin = bin;
26043
+ if (process.platform === "win32") {
26044
+ const winBin = await resolveWin32();
26045
+ if (winBin) {
26046
+ resolvedBin = winBin;
25507
26047
  return resolvedBin;
25508
26048
  }
25509
- } catch (err2) {
25510
- logWithTimestamp(
25511
- "[onchainos] shell resolve failed, will fallback to bare 'onchainos':",
25512
- err2
25513
- );
26049
+ } else {
26050
+ try {
26051
+ const shell = process.env.SHELL || "/bin/bash";
26052
+ const { stdout } = await execFileAsync2(shell, ["-lc", "command -v onchainos"], {
26053
+ windowsHide: true
26054
+ });
26055
+ const bin = extractExecutablePath(stdout);
26056
+ if (bin) {
26057
+ logWithTimestamp(`[onchainos] resolved binary via shell: ${bin}`);
26058
+ resolvedBin = bin;
26059
+ return resolvedBin;
26060
+ }
26061
+ } catch (err2) {
26062
+ logWithTimestamp(
26063
+ "[onchainos] shell resolve failed, will fallback to bare 'onchainos':",
26064
+ err2
26065
+ );
26066
+ }
25514
26067
  }
25515
26068
  logWithTimestamp(
25516
26069
  "[onchainos] could not resolve binary path, falling back to bare 'onchainos'"
@@ -25518,6 +26071,98 @@ async function resolve3() {
25518
26071
  resolvedBin = "onchainos";
25519
26072
  return resolvedBin;
25520
26073
  }
26074
+ async function resolveWin32() {
26075
+ try {
26076
+ const { stdout } = await execFileAsync2("where.exe", ["onchainos"], {
26077
+ windowsHide: true
26078
+ });
26079
+ const lines = stdout.split(/\r?\n/);
26080
+ const nonEmptyLineCount = lines.filter((line) => {
26081
+ return line.trim().length > 0;
26082
+ }).length;
26083
+ logWithTimestamp(
26084
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] where.exe onchainos returned ${nonEmptyLineCount} candidate line(s)`
26085
+ );
26086
+ const picked = pickOnchainosWin32Candidate(lines);
26087
+ if (picked) {
26088
+ logWithTimestamp(
26089
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] resolved binary via where.exe: ${picked}`
26090
+ );
26091
+ return picked;
26092
+ }
26093
+ logWithTimestamp(
26094
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] where.exe returned no usable candidate, falling back to bare 'onchainos'`
26095
+ );
26096
+ } catch (err2) {
26097
+ errorWithTimestamp(
26098
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] where.exe resolve failed (errorCode=${err2?.code ?? ""}), falling back to bare 'onchainos':`,
26099
+ err2
26100
+ );
26101
+ }
26102
+ return null;
26103
+ }
26104
+ function win32CandidatePriority(candidate) {
26105
+ const extension = (0, import_node_path16.extname)(candidate).toLowerCase();
26106
+ if (extension === ".exe") {
26107
+ return 0;
26108
+ }
26109
+ if (extension === ".cmd") {
26110
+ return 1;
26111
+ }
26112
+ if (extension === ".bat") {
26113
+ return 2;
26114
+ }
26115
+ return 3;
26116
+ }
26117
+ function isWindowsAppsAlias(candidate) {
26118
+ return candidate.toLowerCase().includes(WINDOWS_APPS_ALIAS_MARKER);
26119
+ }
26120
+ function win32FileExists(path) {
26121
+ return (0, import_node_fs12.existsSync)(path);
26122
+ }
26123
+ function pickOnchainosWin32Candidate(lines, fileExists2 = win32FileExists) {
26124
+ const candidates = lines.map((line) => {
26125
+ return line.trim();
26126
+ }).filter((line) => {
26127
+ return line.length > 0;
26128
+ });
26129
+ if (candidates.length === 0) {
26130
+ logWithTimestamp(`${WIN_COMPAT_LOG_PREFIX} [onchainos] no candidate lines to rank`);
26131
+ return null;
26132
+ }
26133
+ const ranked = [];
26134
+ candidates.forEach((candidate, order) => {
26135
+ if (!fileExists2(candidate)) {
26136
+ logWithTimestamp(
26137
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] candidate rejected (file not found): ${candidate}`
26138
+ );
26139
+ return;
26140
+ }
26141
+ const priority = win32CandidatePriority(candidate);
26142
+ const windowsAppsAlias = isWindowsAppsAlias(candidate);
26143
+ logWithTimestamp(
26144
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] candidate accepted: ${candidate} (extPriority=${priority}, windowsAppsAlias=${windowsAppsAlias})`
26145
+ );
26146
+ ranked.push({ candidate, order, priority, windowsAppsAlias });
26147
+ });
26148
+ ranked.sort((a, b) => {
26149
+ if (a.windowsAppsAlias !== b.windowsAppsAlias) {
26150
+ return a.windowsAppsAlias ? 1 : -1;
26151
+ }
26152
+ if (a.priority !== b.priority) {
26153
+ return a.priority - b.priority;
26154
+ }
26155
+ return a.order - b.order;
26156
+ });
26157
+ const winner = ranked[0];
26158
+ if (!winner) {
26159
+ return null;
26160
+ }
26161
+ logWithTimestamp(
26162
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] candidate selected: ${winner.candidate}`
26163
+ );
26164
+ return winner.candidate;
26165
+ }
25521
26166
  function extractExecutablePath(stdout) {
25522
26167
  const candidates = stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).reverse();
25523
26168
  for (const candidate of candidates) {
@@ -25529,7 +26174,7 @@ function extractExecutablePath(stdout) {
25529
26174
  }
25530
26175
  function isExecutable2(path) {
25531
26176
  try {
25532
- (0, import_node_fs11.accessSync)(path, import_node_fs11.constants.X_OK);
26177
+ (0, import_node_fs12.accessSync)(path, import_node_fs12.constants.X_OK);
25533
26178
  return true;
25534
26179
  } catch {
25535
26180
  return false;
@@ -25560,17 +26205,28 @@ function commandForLog(bin, args) {
25560
26205
  return `${bin} ${redactArgsForLog(args).join(" ")}`;
25561
26206
  }
25562
26207
  async function exec(args) {
25563
- const bin = await resolve3();
26208
+ const bin = await resolve4();
25564
26209
  const cmd = commandForLog(bin, args);
25565
26210
  logWithTimestamp(`[onchainos] exec: ${cmd}`);
26211
+ const invocation = toWindowsInvocation(bin, args);
26212
+ if (invocation.routedThroughWindowsShell) {
26213
+ logWithTimestamp(
26214
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] exec routed through ${invocation.command} /d /s /c: ${cmd}`
26215
+ );
26216
+ }
25566
26217
  const t0 = Date.now();
25567
26218
  try {
25568
- const result = await execFileAsync2(bin, args);
26219
+ const result = await execFileAsync2(invocation.command, invocation.args, { windowsHide: true });
25569
26220
  logWithTimestamp(
25570
26221
  `[onchainos] exec done: ${cmd} (${Date.now() - t0}ms, stdout=${result.stdout.length}B, stderr=${result.stderr.length}B)`
25571
26222
  );
25572
26223
  return result;
25573
26224
  } catch (err2) {
26225
+ if (invocation.routedThroughWindowsShell) {
26226
+ errorWithTimestamp(
26227
+ `${WIN_COMPAT_LOG_PREFIX} [onchainos] routed exec failed via ${invocation.command}: ${cmd} errorCode=${err2?.code ?? ""} signal=${err2?.signal ?? ""}`
26228
+ );
26229
+ }
25574
26230
  logWithTimestamp(
25575
26231
  `[onchainos] exec error: ${cmd} (${Date.now() - t0}ms) code=${err2.code} signal=${err2.signal} killed=${err2.killed} message=${err2.message}`
25576
26232
  );
@@ -25598,18 +26254,21 @@ async function exec(args) {
25598
26254
  throw err2;
25599
26255
  }
25600
26256
  }
25601
- var import_node_fs11, import_node_child_process4, import_node_util2, execFileAsync2, resolvedBin, REDACTED_VALUE_FLAGS;
26257
+ var import_node_fs12, import_node_child_process6, import_node_path16, import_node_util2, execFileAsync2, resolvedBin, REDACTED_VALUE_FLAGS, WINDOWS_APPS_ALIAS_MARKER;
25602
26258
  var init_bin = __esm({
25603
26259
  "../core/src/xmtp-sdk/onchainos/bin.ts"() {
25604
26260
  "use strict";
25605
26261
  init_log();
25606
- import_node_fs11 = require("node:fs");
25607
- import_node_child_process4 = require("node:child_process");
26262
+ import_node_fs12 = require("node:fs");
26263
+ import_node_child_process6 = require("node:child_process");
26264
+ import_node_path16 = require("node:path");
25608
26265
  import_node_util2 = require("node:util");
25609
26266
  init_sentry_logger();
25610
- execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process4.execFile);
26267
+ init_win_compat();
26268
+ execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process6.execFile);
25611
26269
  resolvedBin = null;
25612
26270
  REDACTED_VALUE_FLAGS = /* @__PURE__ */ new Set(["--message"]);
26271
+ WINDOWS_APPS_ALIAS_MARKER = "\\microsoft\\windowsapps\\";
25613
26272
  }
25614
26273
  });
25615
26274
 
@@ -29140,8 +29799,8 @@ var require_util2 = __commonJS({
29140
29799
  function createDeferredPromise() {
29141
29800
  let res;
29142
29801
  let rej;
29143
- const promise = new Promise((resolve8, reject) => {
29144
- res = resolve8;
29802
+ const promise = new Promise((resolve9, reject) => {
29803
+ res = resolve9;
29145
29804
  rej = reject;
29146
29805
  });
29147
29806
  return { promise, resolve: res, reject: rej };
@@ -30645,8 +31304,8 @@ Content-Type: ${value.type || "application/octet-stream"}\r
30645
31304
  });
30646
31305
  }
30647
31306
  });
30648
- const busboyResolve = new Promise((resolve8, reject) => {
30649
- busboy.on("finish", resolve8);
31307
+ const busboyResolve = new Promise((resolve9, reject) => {
31308
+ busboy.on("finish", resolve9);
30650
31309
  busboy.on("error", (err2) => reject(new TypeError(err2)));
30651
31310
  });
30652
31311
  if (this.body !== null) for await (const chunk of consumeBody(this[kState].body)) busboy.write(chunk);
@@ -31180,9 +31839,9 @@ var require_dispatcher_base = __commonJS({
31180
31839
  }
31181
31840
  close(callback) {
31182
31841
  if (callback === void 0) {
31183
- return new Promise((resolve8, reject) => {
31842
+ return new Promise((resolve9, reject) => {
31184
31843
  this.close((err2, data) => {
31185
- return err2 ? reject(err2) : resolve8(data);
31844
+ return err2 ? reject(err2) : resolve9(data);
31186
31845
  });
31187
31846
  });
31188
31847
  }
@@ -31220,12 +31879,12 @@ var require_dispatcher_base = __commonJS({
31220
31879
  err2 = null;
31221
31880
  }
31222
31881
  if (callback === void 0) {
31223
- return new Promise((resolve8, reject) => {
31882
+ return new Promise((resolve9, reject) => {
31224
31883
  this.destroy(err2, (err3, data) => {
31225
31884
  return err3 ? (
31226
31885
  /* istanbul ignore next: should never error */
31227
31886
  reject(err3)
31228
- ) : resolve8(data);
31887
+ ) : resolve9(data);
31229
31888
  });
31230
31889
  });
31231
31890
  }
@@ -32285,16 +32944,16 @@ var require_client2 = __commonJS({
32285
32944
  return this[kNeedDrain] < 2;
32286
32945
  }
32287
32946
  async [kClose]() {
32288
- return new Promise((resolve8) => {
32947
+ return new Promise((resolve9) => {
32289
32948
  if (!this[kSize]) {
32290
- resolve8(null);
32949
+ resolve9(null);
32291
32950
  } else {
32292
- this[kClosedResolve] = resolve8;
32951
+ this[kClosedResolve] = resolve9;
32293
32952
  }
32294
32953
  });
32295
32954
  }
32296
32955
  async [kDestroy](err2) {
32297
- return new Promise((resolve8) => {
32956
+ return new Promise((resolve9) => {
32298
32957
  const requests = this[kQueue].splice(this[kPendingIdx]);
32299
32958
  for (let i = 0; i < requests.length; i++) {
32300
32959
  const request = requests[i];
@@ -32305,7 +32964,7 @@ var require_client2 = __commonJS({
32305
32964
  this[kClosedResolve]();
32306
32965
  this[kClosedResolve] = null;
32307
32966
  }
32308
- resolve8();
32967
+ resolve9();
32309
32968
  };
32310
32969
  if (this[kHTTP2Session] != null) {
32311
32970
  util.destroy(this[kHTTP2Session], err2);
@@ -32885,7 +33544,7 @@ var require_client2 = __commonJS({
32885
33544
  });
32886
33545
  }
32887
33546
  try {
32888
- const socket = await new Promise((resolve8, reject) => {
33547
+ const socket = await new Promise((resolve9, reject) => {
32889
33548
  client[kConnector]({
32890
33549
  host,
32891
33550
  hostname,
@@ -32897,7 +33556,7 @@ var require_client2 = __commonJS({
32897
33556
  if (err2) {
32898
33557
  reject(err2);
32899
33558
  } else {
32900
- resolve8(socket2);
33559
+ resolve9(socket2);
32901
33560
  }
32902
33561
  });
32903
33562
  });
@@ -33521,12 +34180,12 @@ upgrade: ${upgrade}\r
33521
34180
  cb();
33522
34181
  }
33523
34182
  }
33524
- const waitForDrain = () => new Promise((resolve8, reject) => {
34183
+ const waitForDrain = () => new Promise((resolve9, reject) => {
33525
34184
  assert(callback === null);
33526
34185
  if (socket[kError]) {
33527
34186
  reject(socket[kError]);
33528
34187
  } else {
33529
- callback = resolve8;
34188
+ callback = resolve9;
33530
34189
  }
33531
34190
  });
33532
34191
  if (client[kHTTPConnVersion] === "h2") {
@@ -33871,8 +34530,8 @@ var require_pool_base = __commonJS({
33871
34530
  if (this[kQueue].isEmpty()) {
33872
34531
  return Promise.all(this[kClients].map((c) => c.close()));
33873
34532
  } else {
33874
- return new Promise((resolve8) => {
33875
- this[kClosedResolve] = resolve8;
34533
+ return new Promise((resolve9) => {
34534
+ this[kClosedResolve] = resolve9;
33876
34535
  });
33877
34536
  }
33878
34537
  }
@@ -34450,7 +35109,7 @@ var require_readable = __commonJS({
34450
35109
  if (this.closed) {
34451
35110
  return Promise.resolve(null);
34452
35111
  }
34453
- return new Promise((resolve8, reject) => {
35112
+ return new Promise((resolve9, reject) => {
34454
35113
  const signalListenerCleanup = signal ? util.addAbortListener(signal, () => {
34455
35114
  this.destroy();
34456
35115
  }) : noop;
@@ -34459,7 +35118,7 @@ var require_readable = __commonJS({
34459
35118
  if (signal && signal.aborted) {
34460
35119
  reject(signal.reason || Object.assign(new Error("The operation was aborted"), { name: "AbortError" }));
34461
35120
  } else {
34462
- resolve8(null);
35121
+ resolve9(null);
34463
35122
  }
34464
35123
  }).on("error", noop).on("data", function(chunk) {
34465
35124
  limit -= chunk.length;
@@ -34481,11 +35140,11 @@ var require_readable = __commonJS({
34481
35140
  throw new TypeError("unusable");
34482
35141
  }
34483
35142
  assert(!stream[kConsume]);
34484
- return new Promise((resolve8, reject) => {
35143
+ return new Promise((resolve9, reject) => {
34485
35144
  stream[kConsume] = {
34486
35145
  type,
34487
35146
  stream,
34488
- resolve: resolve8,
35147
+ resolve: resolve9,
34489
35148
  reject,
34490
35149
  length: 0,
34491
35150
  body: []
@@ -34520,12 +35179,12 @@ var require_readable = __commonJS({
34520
35179
  }
34521
35180
  }
34522
35181
  function consumeEnd(consume2) {
34523
- const { type, body, resolve: resolve8, stream, length: length2 } = consume2;
35182
+ const { type, body, resolve: resolve9, stream, length: length2 } = consume2;
34524
35183
  try {
34525
35184
  if (type === "text") {
34526
- resolve8(toUSVString(Buffer.concat(body)));
35185
+ resolve9(toUSVString(Buffer.concat(body)));
34527
35186
  } else if (type === "json") {
34528
- resolve8(JSON.parse(Buffer.concat(body)));
35187
+ resolve9(JSON.parse(Buffer.concat(body)));
34529
35188
  } else if (type === "arrayBuffer") {
34530
35189
  const dst = new Uint8Array(length2);
34531
35190
  let pos = 0;
@@ -34533,12 +35192,12 @@ var require_readable = __commonJS({
34533
35192
  dst.set(buf, pos);
34534
35193
  pos += buf.byteLength;
34535
35194
  }
34536
- resolve8(dst.buffer);
35195
+ resolve9(dst.buffer);
34537
35196
  } else if (type === "blob") {
34538
35197
  if (!Blob2) {
34539
35198
  Blob2 = require("buffer").Blob;
34540
35199
  }
34541
- resolve8(new Blob2(body, { type: stream[kContentType] }));
35200
+ resolve9(new Blob2(body, { type: stream[kContentType] }));
34542
35201
  }
34543
35202
  consumeFinish(consume2);
34544
35203
  } catch (err2) {
@@ -34793,9 +35452,9 @@ var require_api_request = __commonJS({
34793
35452
  };
34794
35453
  function request(opts, callback) {
34795
35454
  if (callback === void 0) {
34796
- return new Promise((resolve8, reject) => {
35455
+ return new Promise((resolve9, reject) => {
34797
35456
  request.call(this, opts, (err2, data) => {
34798
- return err2 ? reject(err2) : resolve8(data);
35457
+ return err2 ? reject(err2) : resolve9(data);
34799
35458
  });
34800
35459
  });
34801
35460
  }
@@ -34968,9 +35627,9 @@ var require_api_stream = __commonJS({
34968
35627
  };
34969
35628
  function stream(opts, factory, callback) {
34970
35629
  if (callback === void 0) {
34971
- return new Promise((resolve8, reject) => {
35630
+ return new Promise((resolve9, reject) => {
34972
35631
  stream.call(this, opts, factory, (err2, data) => {
34973
- return err2 ? reject(err2) : resolve8(data);
35632
+ return err2 ? reject(err2) : resolve9(data);
34974
35633
  });
34975
35634
  });
34976
35635
  }
@@ -35251,9 +35910,9 @@ var require_api_upgrade = __commonJS({
35251
35910
  };
35252
35911
  function upgrade(opts, callback) {
35253
35912
  if (callback === void 0) {
35254
- return new Promise((resolve8, reject) => {
35913
+ return new Promise((resolve9, reject) => {
35255
35914
  upgrade.call(this, opts, (err2, data) => {
35256
- return err2 ? reject(err2) : resolve8(data);
35915
+ return err2 ? reject(err2) : resolve9(data);
35257
35916
  });
35258
35917
  });
35259
35918
  }
@@ -35342,9 +36001,9 @@ var require_api_connect = __commonJS({
35342
36001
  };
35343
36002
  function connect(opts, callback) {
35344
36003
  if (callback === void 0) {
35345
- return new Promise((resolve8, reject) => {
36004
+ return new Promise((resolve9, reject) => {
35346
36005
  connect.call(this, opts, (err2, data) => {
35347
- return err2 ? reject(err2) : resolve8(data);
36006
+ return err2 ? reject(err2) : resolve9(data);
35348
36007
  });
35349
36008
  });
35350
36009
  }
@@ -38966,7 +39625,7 @@ var require_fetch = __commonJS({
38966
39625
  async function dispatch({ body }) {
38967
39626
  const url = requestCurrentURL(request);
38968
39627
  const agent = fetchParams.controller.dispatcher;
38969
- return new Promise((resolve8, reject) => agent.dispatch(
39628
+ return new Promise((resolve9, reject) => agent.dispatch(
38970
39629
  {
38971
39630
  path: url.pathname + url.search,
38972
39631
  origin: url.origin,
@@ -39042,7 +39701,7 @@ var require_fetch = __commonJS({
39042
39701
  }
39043
39702
  }
39044
39703
  }
39045
- resolve8({
39704
+ resolve9({
39046
39705
  status,
39047
39706
  statusText,
39048
39707
  headersList: headers[kHeadersList],
@@ -39085,7 +39744,7 @@ var require_fetch = __commonJS({
39085
39744
  const val = headersList[n + 1].toString("latin1");
39086
39745
  headers[kHeadersList].append(key, val);
39087
39746
  }
39088
- resolve8({
39747
+ resolve9({
39089
39748
  status,
39090
39749
  statusText: STATUS_CODES[status],
39091
39750
  headersList: headers[kHeadersList],
@@ -39491,7 +40150,7 @@ var require_util4 = __commonJS({
39491
40150
  var { DOMException: DOMException2 } = require_constants4();
39492
40151
  var { serializeAMimeType, parseMIMEType } = require_dataURL();
39493
40152
  var { types } = require("util");
39494
- var { StringDecoder } = require("string_decoder");
40153
+ var { StringDecoder: StringDecoder2 } = require("string_decoder");
39495
40154
  var { btoa: btoa2 } = require("buffer");
39496
40155
  var staticPropertyDescriptors = {
39497
40156
  enumerable: true,
@@ -39582,7 +40241,7 @@ var require_util4 = __commonJS({
39582
40241
  dataURL += serializeAMimeType(parsed);
39583
40242
  }
39584
40243
  dataURL += ";base64,";
39585
- const decoder = new StringDecoder("latin1");
40244
+ const decoder = new StringDecoder2("latin1");
39586
40245
  for (const chunk of bytes) {
39587
40246
  dataURL += btoa2(decoder.write(chunk));
39588
40247
  }
@@ -39611,7 +40270,7 @@ var require_util4 = __commonJS({
39611
40270
  }
39612
40271
  case "BinaryString": {
39613
40272
  let binaryString = "";
39614
- const decoder = new StringDecoder("latin1");
40273
+ const decoder = new StringDecoder2("latin1");
39615
40274
  for (const chunk of bytes) {
39616
40275
  binaryString += decoder.write(chunk);
39617
40276
  }
@@ -42412,11 +43071,11 @@ var require_fetch_pb = __commonJS({
42412
43071
  "use strict";
42413
43072
  var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P2, generator) {
42414
43073
  function adopt(value) {
42415
- return value instanceof P2 ? value : new P2(function(resolve8) {
42416
- resolve8(value);
43074
+ return value instanceof P2 ? value : new P2(function(resolve9) {
43075
+ resolve9(value);
42417
43076
  });
42418
43077
  }
42419
- return new (P2 || (P2 = Promise))(function(resolve8, reject) {
43078
+ return new (P2 || (P2 = Promise))(function(resolve9, reject) {
42420
43079
  function fulfilled(value) {
42421
43080
  try {
42422
43081
  step(generator.next(value));
@@ -42432,7 +43091,7 @@ var require_fetch_pb = __commonJS({
42432
43091
  }
42433
43092
  }
42434
43093
  function step(result) {
42435
- result.done ? resolve8(result.value) : adopt(result.value).then(fulfilled, rejected);
43094
+ result.done ? resolve9(result.value) : adopt(result.value).then(fulfilled, rejected);
42436
43095
  }
42437
43096
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42438
43097
  });
@@ -43702,7 +44361,7 @@ var require_aspromise = __commonJS({
43702
44361
  var params = new Array(arguments.length - 1), offset = 0, index2 = 2, pending = true;
43703
44362
  while (index2 < arguments.length)
43704
44363
  params[offset++] = arguments[index2++];
43705
- return new Promise(function executor(resolve8, reject) {
44364
+ return new Promise(function executor(resolve9, reject) {
43706
44365
  params[offset] = function callback(err2) {
43707
44366
  if (pending) {
43708
44367
  pending = false;
@@ -43712,7 +44371,7 @@ var require_aspromise = __commonJS({
43712
44371
  var params2 = new Array(arguments.length - 1), offset2 = 0;
43713
44372
  while (offset2 < params2.length)
43714
44373
  params2[offset2++] = arguments[offset2];
43715
- resolve8.apply(null, params2);
44374
+ resolve9.apply(null, params2);
43716
44375
  }
43717
44376
  }
43718
44377
  };
@@ -53168,7 +53827,7 @@ var require_Observable = __commonJS({
53168
53827
  Observable2.prototype.forEach = function(next, promiseCtor) {
53169
53828
  var _this = this;
53170
53829
  promiseCtor = getPromiseCtor(promiseCtor);
53171
- return new promiseCtor(function(resolve8, reject) {
53830
+ return new promiseCtor(function(resolve9, reject) {
53172
53831
  var subscriber = new Subscriber_1.SafeSubscriber({
53173
53832
  next: function(value) {
53174
53833
  try {
@@ -53179,7 +53838,7 @@ var require_Observable = __commonJS({
53179
53838
  }
53180
53839
  },
53181
53840
  error: reject,
53182
- complete: resolve8
53841
+ complete: resolve9
53183
53842
  });
53184
53843
  _this.subscribe(subscriber);
53185
53844
  });
@@ -53201,14 +53860,14 @@ var require_Observable = __commonJS({
53201
53860
  Observable2.prototype.toPromise = function(promiseCtor) {
53202
53861
  var _this = this;
53203
53862
  promiseCtor = getPromiseCtor(promiseCtor);
53204
- return new promiseCtor(function(resolve8, reject) {
53863
+ return new promiseCtor(function(resolve9, reject) {
53205
53864
  var value;
53206
53865
  _this.subscribe(function(x) {
53207
53866
  return value = x;
53208
53867
  }, function(err2) {
53209
53868
  return reject(err2);
53210
53869
  }, function() {
53211
- return resolve8(value);
53870
+ return resolve9(value);
53212
53871
  });
53213
53872
  });
53214
53873
  };
@@ -53469,11 +54128,11 @@ var require_innerFrom = __commonJS({
53469
54128
  "use strict";
53470
54129
  var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P2, generator) {
53471
54130
  function adopt(value) {
53472
- return value instanceof P2 ? value : new P2(function(resolve8) {
53473
- resolve8(value);
54131
+ return value instanceof P2 ? value : new P2(function(resolve9) {
54132
+ resolve9(value);
53474
54133
  });
53475
54134
  }
53476
- return new (P2 || (P2 = Promise))(function(resolve8, reject) {
54135
+ return new (P2 || (P2 = Promise))(function(resolve9, reject) {
53477
54136
  function fulfilled(value) {
53478
54137
  try {
53479
54138
  step(generator.next(value));
@@ -53489,7 +54148,7 @@ var require_innerFrom = __commonJS({
53489
54148
  }
53490
54149
  }
53491
54150
  function step(result) {
53492
- result.done ? resolve8(result.value) : adopt(result.value).then(fulfilled, rejected);
54151
+ result.done ? resolve9(result.value) : adopt(result.value).then(fulfilled, rejected);
53493
54152
  }
53494
54153
  step((generator = generator.apply(thisArg, _arguments || [])).next());
53495
54154
  });
@@ -53571,14 +54230,14 @@ var require_innerFrom = __commonJS({
53571
54230
  }, i);
53572
54231
  function verb(n) {
53573
54232
  i[n] = o[n] && function(v) {
53574
- return new Promise(function(resolve8, reject) {
53575
- v = o[n](v), settle(resolve8, reject, v.done, v.value);
54233
+ return new Promise(function(resolve9, reject) {
54234
+ v = o[n](v), settle(resolve9, reject, v.done, v.value);
53576
54235
  });
53577
54236
  };
53578
54237
  }
53579
- function settle(resolve8, reject, d, v) {
54238
+ function settle(resolve9, reject, d, v) {
53580
54239
  Promise.resolve(v).then(function(v2) {
53581
- resolve8({ value: v2, done: d });
54240
+ resolve9({ value: v2, done: d });
53582
54241
  }, reject);
53583
54242
  }
53584
54243
  };
@@ -68311,7 +68970,7 @@ function createAsyncStreamProxy(stream) {
68311
68970
  function isHexString(value) {
68312
68971
  return typeof value === "string" && /^0x(?:[0-9a-fA-F]{2})+$/.test(value);
68313
68972
  }
68314
- var import_node_bindings, import_node_bindings2, import_types, import_node_path14, import_node_process, ApiUrls, HistorySyncUrls, DecodedMessage, CodecNotFoundError, InboxReassignError, AccountAlreadyAssociatedError, InvalidGroupMembershipChangeError, MissingContentTypeError, SignerUnavailableError, ClientNotInitializedError, StreamFailedError, StreamInvalidRetryAttemptsError, AsyncStream, usableProperties, isUsableProperty, wait, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_ATTEMPTS, createStream, Conversation, Dm, Group, Conversations, DebugInformation, Preferences, generateInboxId, getInboxIdForIdentifier, createClient, Client;
68973
+ var import_node_bindings, import_node_bindings2, import_types, import_node_path17, import_node_process, ApiUrls, HistorySyncUrls, DecodedMessage, CodecNotFoundError, InboxReassignError, AccountAlreadyAssociatedError, InvalidGroupMembershipChangeError, MissingContentTypeError, SignerUnavailableError, ClientNotInitializedError, StreamFailedError, StreamInvalidRetryAttemptsError, AsyncStream, usableProperties, isUsableProperty, wait, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_ATTEMPTS, createStream, Conversation, Dm, Group, Conversations, DebugInformation, Preferences, generateInboxId, getInboxIdForIdentifier, createClient, Client;
68315
68974
  var init_dist4 = __esm({
68316
68975
  "../../node_modules/@xmtp/node-sdk/dist/index.js"() {
68317
68976
  init_dist2();
@@ -68320,7 +68979,7 @@ var init_dist4 = __esm({
68320
68979
  import_node_bindings2 = require("@xmtp/node-bindings");
68321
68980
  init_dist();
68322
68981
  import_types = require("node:util/types");
68323
- import_node_path14 = require("node:path");
68982
+ import_node_path17 = require("node:path");
68324
68983
  import_node_process = __toESM(require("node:process"), 1);
68325
68984
  ApiUrls = {
68326
68985
  local: "http://localhost:5556",
@@ -68481,8 +69140,8 @@ var init_dist4 = __esm({
68481
69140
  value: this.#queue.shift()
68482
69141
  });
68483
69142
  }
68484
- return new Promise((resolve8) => {
68485
- this.#pendingResolves.push(resolve8);
69143
+ return new Promise((resolve9) => {
69144
+ this.#pendingResolves.push(resolve9);
68486
69145
  });
68487
69146
  };
68488
69147
  return = () => {
@@ -68508,7 +69167,7 @@ var init_dist4 = __esm({
68508
69167
  isUsableProperty = (prop) => {
68509
69168
  return usableProperties.includes(prop);
68510
69169
  };
68511
- wait = (ms) => new Promise((resolve8) => setTimeout(resolve8, ms));
69170
+ wait = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
68512
69171
  DEFAULT_RETRY_DELAY = 6e4;
68513
69172
  DEFAULT_RETRY_ATTEMPTS = 10;
68514
69173
  createStream = async (streamFunction, streamValueMutator, options) => {
@@ -69566,7 +70225,7 @@ var init_dist4 = __esm({
69566
70225
  const inboxId = await getInboxIdForIdentifier(identifier, env, gatewayHost) || generateInboxId(identifier, options?.nonce);
69567
70226
  let dbPath;
69568
70227
  if (options?.dbPath === void 0) {
69569
- dbPath = (0, import_node_path14.join)(import_node_process.default.cwd(), `xmtp-${env}-${inboxId}.db3`);
70228
+ dbPath = (0, import_node_path17.join)(import_node_process.default.cwd(), `xmtp-${env}-${inboxId}.db3`);
69570
70229
  } else if (typeof options.dbPath === "function") {
69571
70230
  dbPath = options.dbPath(inboxId);
69572
70231
  } else {
@@ -78075,7 +78734,7 @@ var init_wait = __esm({
78075
78734
 
78076
78735
  // ../../node_modules/viem/_esm/utils/promise/withRetry.js
78077
78736
  function withRetry(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shouldRetry2 = () => true } = {}) {
78078
- return new Promise((resolve8, reject) => {
78737
+ return new Promise((resolve9, reject) => {
78079
78738
  const attemptRetry = async ({ count = 0 } = {}) => {
78080
78739
  const retry = async ({ error }) => {
78081
78740
  const delay = typeof delay_ === "function" ? delay_({ count, error }) : delay_;
@@ -78085,7 +78744,7 @@ function withRetry(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry: shoul
78085
78744
  };
78086
78745
  try {
78087
78746
  const data = await fn();
78088
- resolve8(data);
78747
+ resolve9(data);
78089
78748
  } catch (err2) {
78090
78749
  if (count < retryCount && await shouldRetry2({ count, error: err2 }))
78091
78750
  return retry({ error: err2 });
@@ -78659,13 +79318,13 @@ var init_transactionRequest = __esm({
78659
79318
 
78660
79319
  // ../../node_modules/viem/_esm/utils/promise/withResolvers.js
78661
79320
  function withResolvers() {
78662
- let resolve8 = () => void 0;
79321
+ let resolve9 = () => void 0;
78663
79322
  let reject = () => void 0;
78664
79323
  const promise = new Promise((resolve_, reject_) => {
78665
- resolve8 = resolve_;
79324
+ resolve9 = resolve_;
78666
79325
  reject = reject_;
78667
79326
  });
78668
- return { promise, resolve: resolve8, reject };
79327
+ return { promise, resolve: resolve9, reject };
78669
79328
  }
78670
79329
  var init_withResolvers = __esm({
78671
79330
  "../../node_modules/viem/_esm/utils/promise/withResolvers.js"() {
@@ -78684,8 +79343,8 @@ function createBatchScheduler({ fn, id, shouldSplitBatch, wait: wait3 = 0, sort
78684
79343
  if (sort && Array.isArray(data))
78685
79344
  data.sort(sort);
78686
79345
  for (let i = 0; i < scheduler.length; i++) {
78687
- const { resolve: resolve8 } = scheduler[i];
78688
- resolve8?.([data[i], data]);
79346
+ const { resolve: resolve9 } = scheduler[i];
79347
+ resolve9?.([data[i], data]);
78689
79348
  }
78690
79349
  }).catch((err2) => {
78691
79350
  for (let i = 0; i < scheduler.length; i++) {
@@ -78701,16 +79360,16 @@ function createBatchScheduler({ fn, id, shouldSplitBatch, wait: wait3 = 0, sort
78701
79360
  return {
78702
79361
  flush: flush2,
78703
79362
  async schedule(args) {
78704
- const { promise, resolve: resolve8, reject } = withResolvers();
79363
+ const { promise, resolve: resolve9, reject } = withResolvers();
78705
79364
  const split2 = shouldSplitBatch?.([...getBatchedArgs(), args]);
78706
79365
  if (split2)
78707
79366
  exec2();
78708
79367
  const hasActiveScheduler = getScheduler().length > 0;
78709
79368
  if (hasActiveScheduler) {
78710
- setScheduler({ args, resolve: resolve8, reject });
79369
+ setScheduler({ args, resolve: resolve9, reject });
78711
79370
  return promise;
78712
79371
  }
78713
- setScheduler({ args, resolve: resolve8, reject });
79372
+ setScheduler({ args, resolve: resolve9, reject });
78714
79373
  setTimeout(exec2, wait3);
78715
79374
  return promise;
78716
79375
  }
@@ -79147,7 +79806,7 @@ var init_getTransactionCount = __esm({
79147
79806
 
79148
79807
  // ../../node_modules/viem/_esm/utils/promise/withTimeout.js
79149
79808
  function withTimeout(fn, { errorInstance = new Error("timed out"), timeout, signal }) {
79150
- return new Promise((resolve8, reject) => {
79809
+ return new Promise((resolve9, reject) => {
79151
79810
  ;
79152
79811
  (async () => {
79153
79812
  let timeoutId;
@@ -79162,7 +79821,7 @@ function withTimeout(fn, { errorInstance = new Error("timed out"), timeout, sign
79162
79821
  }
79163
79822
  }, timeout);
79164
79823
  }
79165
- resolve8(await fn({ signal: controller?.signal || null }));
79824
+ resolve9(await fn({ signal: controller?.signal || null }));
79166
79825
  } catch (err2) {
79167
79826
  if (err2?.name === "AbortError")
79168
79827
  reject(errorInstance);
@@ -81803,7 +82462,7 @@ var init_observe = __esm({
81803
82462
  function poll(fn, { emitOnBegin, initialWaitTime, interval }) {
81804
82463
  let active = true;
81805
82464
  const unwatch = () => active = false;
81806
- const watch = async () => {
82465
+ const watch2 = async () => {
81807
82466
  let data;
81808
82467
  if (emitOnBegin)
81809
82468
  data = await fn({ unpoll: unwatch });
@@ -81818,7 +82477,7 @@ function poll(fn, { emitOnBegin, initialWaitTime, interval }) {
81818
82477
  };
81819
82478
  poll2();
81820
82479
  };
81821
- watch();
82480
+ watch2();
81822
82481
  return unwatch;
81823
82482
  }
81824
82483
  var init_poll = __esm({
@@ -82239,7 +82898,7 @@ async function sendCalls(client, parameters) {
82239
82898
  });
82240
82899
  promises.push(promise);
82241
82900
  if (experimental_fallbackDelay > 0)
82242
- await new Promise((resolve8) => setTimeout(resolve8, experimental_fallbackDelay));
82901
+ await new Promise((resolve9) => setTimeout(resolve9, experimental_fallbackDelay));
82243
82902
  }
82244
82903
  const results = await Promise.allSettled(promises);
82245
82904
  if (results.every((r) => r.status === "rejected"))
@@ -82370,9 +83029,9 @@ async function waitForCallsStatus(client, parameters) {
82370
83029
  throwOnFailure = false
82371
83030
  } = parameters;
82372
83031
  const observerId = stringify(["waitForCallsStatus", client.uid, id]);
82373
- const { promise, resolve: resolve8, reject } = withResolvers();
83032
+ const { promise, resolve: resolve9, reject } = withResolvers();
82374
83033
  let timer;
82375
- const unobserve = observe(observerId, { resolve: resolve8, reject }, (emit) => {
83034
+ const unobserve = observe(observerId, { resolve: resolve9, reject }, (emit) => {
82376
83035
  const unpoll = poll(async () => {
82377
83036
  const done = (fn) => {
82378
83037
  clearTimeout(timer);
@@ -82710,13 +83369,13 @@ async function waitForTransactionReceipt(client, parameters) {
82710
83369
  let retrying = false;
82711
83370
  let _unobserve;
82712
83371
  let _unwatch;
82713
- const { promise, resolve: resolve8, reject } = withResolvers();
83372
+ const { promise, resolve: resolve9, reject } = withResolvers();
82714
83373
  const timer = timeout ? setTimeout(() => {
82715
83374
  _unwatch?.();
82716
83375
  _unobserve?.();
82717
83376
  reject(new WaitForTransactionReceiptTimeoutError({ hash: hash2 }));
82718
83377
  }, timeout) : void 0;
82719
- _unobserve = observe(observerId, { onReplaced, resolve: resolve8, reject }, async (emit) => {
83378
+ _unobserve = observe(observerId, { onReplaced, resolve: resolve9, reject }, async (emit) => {
82720
83379
  receipt = await getAction(client, getTransactionReceipt, "getTransactionReceipt")({ hash: hash2 }).catch(() => void 0);
82721
83380
  if (receipt && confirmations <= 1) {
82722
83381
  clearTimeout(timer);
@@ -84352,7 +85011,7 @@ var init_agent_status = __esm({
84352
85011
 
84353
85012
  // ../core/src/xmtp-sdk/index.ts
84354
85013
  function cachePath(dataDir, fileName) {
84355
- return (0, import_node_path15.join)(dataDir, fileName);
85014
+ return (0, import_node_path18.join)(dataDir, fileName);
84356
85015
  }
84357
85016
  function ensureCacheDir(dataDir) {
84358
85017
  ensureA2aTaskDir(dataDir);
@@ -84375,10 +85034,10 @@ function isSessionExpiredError(err2) {
84375
85034
  function loadSensitiveWordsFromCache(dataDir) {
84376
85035
  try {
84377
85036
  const path = cachePath(dataDir, "sensitive-words.json");
84378
- if (!(0, import_node_fs12.existsSync)(path)) {
85037
+ if (!(0, import_node_fs13.existsSync)(path)) {
84379
85038
  return null;
84380
85039
  }
84381
- const data = JSON.parse((0, import_node_fs12.readFileSync)(path, "utf-8"));
85040
+ const data = JSON.parse((0, import_node_fs13.readFileSync)(path, "utf-8"));
84382
85041
  if (Array.isArray(data)) {
84383
85042
  return data;
84384
85043
  }
@@ -84392,7 +85051,7 @@ function loadSensitiveWordsFromCache(dataDir) {
84392
85051
  function saveSensitiveWordsToCache(dataDir, words) {
84393
85052
  try {
84394
85053
  ensureCacheDir(dataDir);
84395
- (0, import_node_fs12.writeFileSync)(cachePath(dataDir, "sensitive-words.json"), JSON.stringify(words));
85054
+ (0, import_node_fs13.writeFileSync)(cachePath(dataDir, "sensitive-words.json"), JSON.stringify(words));
84396
85055
  } catch (err2) {
84397
85056
  logWithTimestamp(`[xmtp-sdk] failed to write sensitive-words.json:`, err2);
84398
85057
  logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "sensitive-words" });
@@ -84434,10 +85093,10 @@ async function loadSensitiveWordsWith(dataDir, fetcher) {
84434
85093
  function loadSystemConfigFromCache(dataDir) {
84435
85094
  try {
84436
85095
  const path = cachePath(dataDir, "system-config.json");
84437
- if (!(0, import_node_fs12.existsSync)(path)) {
85096
+ if (!(0, import_node_fs13.existsSync)(path)) {
84438
85097
  return null;
84439
85098
  }
84440
- const data = JSON.parse((0, import_node_fs12.readFileSync)(path, "utf-8"));
85099
+ const data = JSON.parse((0, import_node_fs13.readFileSync)(path, "utf-8"));
84441
85100
  if (data && typeof data === "object" && !Array.isArray(data)) {
84442
85101
  return data;
84443
85102
  }
@@ -84451,7 +85110,7 @@ function loadSystemConfigFromCache(dataDir) {
84451
85110
  function saveSystemConfigToCache(dataDir, config) {
84452
85111
  try {
84453
85112
  ensureCacheDir(dataDir);
84454
- (0, import_node_fs12.writeFileSync)(cachePath(dataDir, "system-config.json"), JSON.stringify(config));
85113
+ (0, import_node_fs13.writeFileSync)(cachePath(dataDir, "system-config.json"), JSON.stringify(config));
84455
85114
  } catch (err2) {
84456
85115
  logWithTimestamp(`[xmtp-sdk] failed to write system-config.json:`, err2);
84457
85116
  logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "system-config" });
@@ -84498,10 +85157,10 @@ function loadSyncByAddress(dataDir) {
84498
85157
  const map = /* @__PURE__ */ new Map();
84499
85158
  try {
84500
85159
  const path = cachePath(dataDir, "last-sync.json");
84501
- if (!(0, import_node_fs12.existsSync)(path)) {
85160
+ if (!(0, import_node_fs13.existsSync)(path)) {
84502
85161
  return map;
84503
85162
  }
84504
- const data = JSON.parse((0, import_node_fs12.readFileSync)(path, "utf-8"));
85163
+ const data = JSON.parse((0, import_node_fs13.readFileSync)(path, "utf-8"));
84505
85164
  const obj = data?.syncByAddress;
84506
85165
  if (obj && typeof obj === "object" && !Array.isArray(obj)) {
84507
85166
  for (const [addr, ts] of Object.entries(obj)) {
@@ -84520,9 +85179,9 @@ function saveSyncForAddress(dataDir, address, timestampMs) {
84520
85179
  try {
84521
85180
  let data = {};
84522
85181
  const path = cachePath(dataDir, "last-sync.json");
84523
- if ((0, import_node_fs12.existsSync)(path)) {
85182
+ if ((0, import_node_fs13.existsSync)(path)) {
84524
85183
  try {
84525
- const raw = JSON.parse((0, import_node_fs12.readFileSync)(path, "utf-8"));
85184
+ const raw = JSON.parse((0, import_node_fs13.readFileSync)(path, "utf-8"));
84526
85185
  if (raw && typeof raw === "object" && !Array.isArray(raw)) {
84527
85186
  data = raw;
84528
85187
  }
@@ -84533,7 +85192,7 @@ function saveSyncForAddress(dataDir, address, timestampMs) {
84533
85192
  data.syncByAddress = {};
84534
85193
  }
84535
85194
  data.syncByAddress[address] = timestampMs;
84536
- (0, import_node_fs12.writeFileSync)(path, JSON.stringify(data, null, 2));
85195
+ (0, import_node_fs13.writeFileSync)(path, JSON.stringify(data, null, 2));
84537
85196
  } catch (err2) {
84538
85197
  logWithTimestamp(
84539
85198
  `[xmtp-sdk] failed to write last-sync.json (address=${address}):`,
@@ -84712,13 +85371,13 @@ function createOfflineReplayAddressSummary(address) {
84712
85371
  durationMs: 0
84713
85372
  };
84714
85373
  }
84715
- var import_node_fs12, import_node_path15, DEFAULT_DATA_DIR, SENSITIVE_WORDS_LAZY_RETRY_COOLDOWN_MS, SESSION_EXPIRED_RE, SYSTEM_CONFIG_DEFAULTS, SEMVER_RE, SENDER_BLACKLISTED_MESSAGE, RECIPIENT_BLACKLISTED_MESSAGE, XmtpService;
85374
+ var import_node_fs13, import_node_path18, DEFAULT_DATA_DIR, SENSITIVE_WORDS_LAZY_RETRY_COOLDOWN_MS, SESSION_EXPIRED_RE, SYSTEM_CONFIG_DEFAULTS, SEMVER_RE, SENDER_BLACKLISTED_MESSAGE, RECIPIENT_BLACKLISTED_MESSAGE, XmtpService;
84716
85375
  var init_xmtp_sdk = __esm({
84717
85376
  "../core/src/xmtp-sdk/index.ts"() {
84718
85377
  "use strict";
84719
85378
  init_log();
84720
- import_node_fs12 = require("node:fs");
84721
- import_node_path15 = require("node:path");
85379
+ import_node_fs13 = require("node:fs");
85380
+ import_node_path18 = require("node:path");
84722
85381
  init_dist4();
84723
85382
  init_sentry_logger();
84724
85383
  init_extract_job_id();
@@ -86926,12 +87585,12 @@ function loadSqlite3() {
86926
87585
  process.emitWarning = originalEmitWarning;
86927
87586
  }
86928
87587
  }
86929
- var import_node_fs13, import_node_path16, DatabaseSync3, InvalidXmtpMessageStore;
87588
+ var import_node_fs14, import_node_path19, DatabaseSync3, InvalidXmtpMessageStore;
86930
87589
  var init_invalid_message_store = __esm({
86931
87590
  "src/invalid-message-store.ts"() {
86932
87591
  "use strict";
86933
- import_node_fs13 = require("node:fs");
86934
- import_node_path16 = require("node:path");
87592
+ import_node_fs14 = require("node:fs");
87593
+ import_node_path19 = require("node:path");
86935
87594
  init_paths();
86936
87595
  ({ DatabaseSync: DatabaseSync3 } = loadSqlite3());
86937
87596
  InvalidXmtpMessageStore = class {
@@ -86939,8 +87598,8 @@ var init_invalid_message_store = __esm({
86939
87598
  db;
86940
87599
  constructor(homeDir) {
86941
87600
  const paths = resolveTaskPaths(homeDir);
86942
- this.dbPath = (0, import_node_path16.join)(paths.sqliteDir, "invalid-xmtp-messages.sqlite");
86943
- (0, import_node_fs13.mkdirSync)((0, import_node_path16.dirname)(this.dbPath), { recursive: true });
87601
+ this.dbPath = (0, import_node_path19.join)(paths.sqliteDir, "invalid-xmtp-messages.sqlite");
87602
+ (0, import_node_fs14.mkdirSync)((0, import_node_path19.dirname)(this.dbPath), { recursive: true });
86944
87603
  this.db = new DatabaseSync3(this.dbPath);
86945
87604
  this.ensureReady();
86946
87605
  }
@@ -88238,7 +88897,7 @@ function buildAiAdapterCommand(options) {
88238
88897
  function readCodexAddDirs(env = process.env) {
88239
88898
  const raw = env.OKX_A2A_AI_CODEX_ADD_DIRS ?? env.OKX_AGENT_TASK_CODEX_ADD_DIRS ?? "";
88240
88899
  const seen = /* @__PURE__ */ new Set();
88241
- return raw.split(import_node_path17.delimiter).map((value) => expandHomePath(value.trim())).filter(Boolean).filter((dir) => {
88900
+ return raw.split(import_node_path20.delimiter).map((value) => expandHomePath(value.trim())).filter(Boolean).filter((dir) => {
88242
88901
  if (seen.has(dir)) {
88243
88902
  return false;
88244
88903
  }
@@ -88251,7 +88910,7 @@ function expandHomePath(value) {
88251
88910
  return (0, import_node_os5.homedir)();
88252
88911
  }
88253
88912
  if (value.startsWith("~/")) {
88254
- return (0, import_node_path17.join)((0, import_node_os5.homedir)(), value.slice(2));
88913
+ return (0, import_node_path20.join)((0, import_node_os5.homedir)(), value.slice(2));
88255
88914
  }
88256
88915
  return value;
88257
88916
  }
@@ -88271,7 +88930,7 @@ async function runAiAdapter(options) {
88271
88930
  errorWithTimestamp(
88272
88931
  `[okx-agent-task] AI adapter start provider=${options.provider} command=${built.command} mode=${options.sessionId ? "resume" : "new"} cwd=${options.cwd ?? process.cwd()}`
88273
88932
  );
88274
- const child = (0, import_node_child_process5.spawn)(built.command, built.args, {
88933
+ const child = spawnCompat(built.command, built.args, {
88275
88934
  cwd: options.cwd,
88276
88935
  env: buildAiProviderEnv(built.command, { ...process.env, ...options.env ?? {}, OKX_A2A_IS_CLI: "1" }),
88277
88936
  stdio: ["ignore", "pipe", "pipe"],
@@ -88321,17 +88980,17 @@ async function runAiAdapter(options) {
88321
88980
  const message = `[okx-agent-task] AI adapter timeout provider=${options.provider} timeoutMs=${timeoutMs}; terminating process and preserving partial output
88322
88981
  `;
88323
88982
  stderr += message;
88324
- child.kill("SIGTERM");
88983
+ killProcessTree(child, "SIGTERM");
88325
88984
  setTimeout(() => {
88326
88985
  if (!child.killed || child.exitCode === null) {
88327
- child.kill("SIGKILL");
88986
+ killProcessTree(child, "SIGKILL");
88328
88987
  }
88329
88988
  }, 5e3).unref();
88330
88989
  }, timeoutMs);
88331
88990
  timeout?.unref();
88332
- const exitCode = await new Promise((resolve8, reject) => {
88991
+ const exitCode = await new Promise((resolve9, reject) => {
88333
88992
  child.once("error", reject);
88334
- child.once("close", (code2) => resolve8(code2));
88993
+ child.once("close", (code2) => resolve9(code2));
88335
88994
  });
88336
88995
  if (timeout) {
88337
88996
  clearTimeout(timeout);
@@ -88465,9 +89124,9 @@ function formatOpenClawSessionKey(sessionKey, agentId) {
88465
89124
  function buildClaudeAddDirArgs(homeDir, env) {
88466
89125
  const dirs = [
88467
89126
  homeDir,
88468
- (0, import_node_path17.join)((0, import_node_os5.homedir)(), ".agents"),
88469
- (0, import_node_path17.join)(__dirname, ".."),
88470
- ...env.OKX_A2A_AI_CLAUDE_ADD_DIRS ? env.OKX_A2A_AI_CLAUDE_ADD_DIRS.split(import_node_path17.delimiter).filter(Boolean) : []
89127
+ (0, import_node_path20.join)((0, import_node_os5.homedir)(), ".agents"),
89128
+ (0, import_node_path20.join)(__dirname, ".."),
89129
+ ...env.OKX_A2A_AI_CLAUDE_ADD_DIRS ? env.OKX_A2A_AI_CLAUDE_ADD_DIRS.split(import_node_path20.delimiter).filter(Boolean) : []
88471
89130
  ];
88472
89131
  return ["--add-dir", ...[...new Set(dirs)]];
88473
89132
  }
@@ -88519,22 +89178,22 @@ function applyArgTemplate(template, options) {
88519
89178
  const homeDir = options.homeDir ?? resolveTaskPaths().homeDir;
88520
89179
  const cwd = options.cwd ?? process.cwd();
88521
89180
  return template.map((arg) => {
88522
- return arg.replaceAll("{prompt}", options.prompt).replaceAll("{sessionId}", options.sessionId ?? "").replaceAll("{homeDir}", homeDir).replaceAll("{cwd}", cwd).replaceAll("{repoCli}", (0, import_node_path17.join)(__dirname, "cli.js"));
89181
+ return arg.replaceAll("{prompt}", options.prompt).replaceAll("{sessionId}", options.sessionId ?? "").replaceAll("{homeDir}", homeDir).replaceAll("{cwd}", cwd).replaceAll("{repoCli}", (0, import_node_path20.join)(__dirname, "cli.js"));
88523
89182
  });
88524
89183
  }
88525
- var import_node_child_process5, import_node_os5, import_node_path17, CLAUDE_ALLOWED_TOOLS, CLAUDE_PERMISSION_MODES, CODEX_SANDBOX_MODES, CODEX_APPROVAL_POLICIES;
89184
+ var import_node_os5, import_node_path20, CLAUDE_ALLOWED_TOOLS, CLAUDE_PERMISSION_MODES, CODEX_SANDBOX_MODES, CODEX_APPROVAL_POLICIES;
88526
89185
  var init_ai_adapter = __esm({
88527
89186
  "src/ai-adapter.ts"() {
88528
89187
  "use strict";
88529
89188
  init_log();
88530
- import_node_child_process5 = require("node:child_process");
88531
89189
  import_node_os5 = require("node:os");
88532
- import_node_path17 = require("node:path");
89190
+ import_node_path20 = require("node:path");
88533
89191
  init_ai_command();
88534
89192
  init_paths();
88535
89193
  init_session_store();
88536
89194
  init_task_config();
88537
89195
  init_sentry_logger();
89196
+ init_win_spawn();
88538
89197
  CLAUDE_ALLOWED_TOOLS = [
88539
89198
  "Read",
88540
89199
  "LS",
@@ -88570,7 +89229,7 @@ function aiRunSentryExtra(input) {
88570
89229
  closeSignal: input.closeSignal ?? "",
88571
89230
  timedOut: input.timedOut === void 0 ? "" : String(input.timedOut),
88572
89231
  aiSessionId: input.aiSessionId ?? "",
88573
- aiLogFile: input.logPath ? (0, import_node_path18.basename)(input.logPath) : "",
89232
+ aiLogFile: input.logPath ? (0, import_node_path21.basename)(input.logPath) : "",
88574
89233
  commandPendingMs: input.commandPendingMs ?? "",
88575
89234
  queueWaitMs: input.queueWaitMs ?? "",
88576
89235
  cliMs: input.cliMs ?? "",
@@ -88602,7 +89261,7 @@ function aiRunToolFailureSentryExtra(failure, context) {
88602
89261
  closeSignal: context.closeSignal ?? "",
88603
89262
  timedOut: String(context.timedOut),
88604
89263
  aiSessionId: context.aiSessionId ?? "",
88605
- aiLogFile: (0, import_node_path18.basename)(context.logPath)
89264
+ aiLogFile: (0, import_node_path21.basename)(context.logPath)
88606
89265
  }).filter(([, value]) => value !== "");
88607
89266
  return entries.reduce((out, [key, value]) => {
88608
89267
  out[key] = String(value);
@@ -88625,7 +89284,7 @@ function safeProcessCwd() {
88625
89284
  }
88626
89285
  function isDirectory(path) {
88627
89286
  try {
88628
- return (0, import_node_fs14.statSync)(path).isDirectory();
89287
+ return (0, import_node_fs15.statSync)(path).isDirectory();
88629
89288
  } catch {
88630
89289
  return false;
88631
89290
  }
@@ -88917,9 +89576,9 @@ function getPreferredCodexWritableRoot(target) {
88917
89576
  const expanded = expandHomePath2(target);
88918
89577
  const home = (0, import_node_os6.homedir)();
88919
89578
  const appRoots = [
88920
- (0, import_node_path18.join)(home, ".onchainos", "task"),
88921
- (0, import_node_path18.join)(home, ".onchainos", "deliverables"),
88922
- (0, import_node_path18.join)(home, ".okx-agent-task")
89579
+ (0, import_node_path21.join)(home, ".onchainos", "task"),
89580
+ (0, import_node_path21.join)(home, ".onchainos", "deliverables"),
89581
+ (0, import_node_path21.join)(home, ".okx-agent-task")
88923
89582
  ];
88924
89583
  for (const root of appRoots) {
88925
89584
  if (expanded === root || expanded.startsWith(`${root}/`)) {
@@ -88934,7 +89593,7 @@ function inferAppOwnedCodexWritableRoot(failure) {
88934
89593
  return void 0;
88935
89594
  }
88936
89595
  if (containsOnchainosCommand(command) && /\b0x[0-9a-fA-F]{16,}\b/.test(command)) {
88937
- return (0, import_node_path18.join)((0, import_node_os6.homedir)(), ".onchainos", "task");
89596
+ return (0, import_node_path21.join)((0, import_node_os6.homedir)(), ".onchainos", "task");
88938
89597
  }
88939
89598
  return void 0;
88940
89599
  }
@@ -88943,7 +89602,7 @@ function expandHomePath2(value) {
88943
89602
  return (0, import_node_os6.homedir)();
88944
89603
  }
88945
89604
  if (value.startsWith("~/")) {
88946
- return (0, import_node_path18.join)((0, import_node_os6.homedir)(), value.slice(2));
89605
+ return (0, import_node_path21.join)((0, import_node_os6.homedir)(), value.slice(2));
88947
89606
  }
88948
89607
  return value;
88949
89608
  }
@@ -89910,23 +90569,23 @@ function shortenJobId2(jobId) {
89910
90569
  }
89911
90570
  return `${jobId.slice(0, 6)}\u2026${jobId.slice(-4)}`;
89912
90571
  }
89913
- var import_node_crypto9, import_node_fs14, import_promises6, import_node_child_process6, import_node_os6, import_node_path18, AiRunner, CODEX_TOOL_FAILURE_MARKER;
90572
+ var import_node_crypto9, import_node_fs15, import_promises8, import_node_os6, import_node_path21, AiRunner, CODEX_TOOL_FAILURE_MARKER;
89914
90573
  var init_ai_runner = __esm({
89915
90574
  "src/ai-runner.ts"() {
89916
90575
  "use strict";
89917
90576
  init_log();
89918
90577
  import_node_crypto9 = require("node:crypto");
89919
- import_node_fs14 = require("node:fs");
89920
- import_promises6 = require("node:fs/promises");
89921
- import_node_child_process6 = require("node:child_process");
90578
+ import_node_fs15 = require("node:fs");
90579
+ import_promises8 = require("node:fs/promises");
89922
90580
  import_node_os6 = require("node:os");
89923
- import_node_path18 = require("node:path");
90581
+ import_node_path21 = require("node:path");
89924
90582
  init_ai_command();
89925
90583
  init_paths();
89926
90584
  init_file_store();
89927
90585
  init_ai_provider();
89928
90586
  init_ai_adapter();
89929
90587
  init_task_config();
90588
+ init_win_spawn();
89930
90589
  init_session_store();
89931
90590
  init_user_attention_ipc();
89932
90591
  init_sentry_logger();
@@ -90047,7 +90706,7 @@ var init_ai_runner = __esm({
90047
90706
  ensureTaskDir(this.logsDir);
90048
90707
  const lifecycleLogsEnabled = isAiLifecycleLoggingEnabled();
90049
90708
  const logPath = lifecycleLogsEnabled ? this.buildRunLogPath(request) : "";
90050
- const log = lifecycleLogsEnabled ? (0, import_node_fs14.createWriteStream)(logPath, { flags: "a" }) : null;
90709
+ const log = lifecycleLogsEnabled ? (0, import_node_fs15.createWriteStream)(logPath, { flags: "a" }) : null;
90051
90710
  let existing = null;
90052
90711
  let storeReadStartedAt;
90053
90712
  let storeReadEndedAt;
@@ -90137,7 +90796,7 @@ var init_ai_runner = __esm({
90137
90796
  let timedOut = false;
90138
90797
  const timeoutMs = readAiProviderTimeoutMs();
90139
90798
  const spawnStartedAt = Date.now();
90140
- const child = (0, import_node_child_process6.spawn)(command, args, {
90799
+ const child = spawnCompat(command, args, {
90141
90800
  cwd: aiCwd,
90142
90801
  stdio: ["ignore", "pipe", "pipe"],
90143
90802
  env: buildAiProviderEnv(command, {
@@ -90191,17 +90850,17 @@ var init_ai_runner = __esm({
90191
90850
  stderrText += message;
90192
90851
  log?.write(message);
90193
90852
  console.error(message.trim());
90194
- child.kill("SIGTERM");
90853
+ killProcessTree(child, "SIGTERM");
90195
90854
  setTimeout(() => {
90196
90855
  if (!child.killed || child.exitCode === null) {
90197
- child.kill("SIGKILL");
90856
+ killProcessTree(child, "SIGKILL");
90198
90857
  }
90199
90858
  }, 5e3).unref();
90200
90859
  }, timeoutMs);
90201
90860
  timeout?.unref();
90202
- const closeResult = await new Promise((resolve8, reject) => {
90861
+ const closeResult = await new Promise((resolve9, reject) => {
90203
90862
  child.once("error", reject);
90204
- child.once("close", (code2, signal) => resolve8({ code: code2, signal }));
90863
+ child.once("close", (code2, signal) => resolve9({ code: code2, signal }));
90205
90864
  });
90206
90865
  if (timeout) {
90207
90866
  clearTimeout(timeout);
@@ -90223,8 +90882,8 @@ var init_ai_runner = __esm({
90223
90882
  const sessionWriteMs = sessionWriteEndedAt - sessionWriteStartedAt;
90224
90883
  const logFileCloseStartedAt = Date.now();
90225
90884
  if (log) {
90226
- await new Promise((resolve8) => {
90227
- log.end(resolve8);
90885
+ await new Promise((resolve9) => {
90886
+ log.end(resolve9);
90228
90887
  });
90229
90888
  }
90230
90889
  const logFileCloseEndedAt = Date.now();
@@ -90430,10 +91089,10 @@ var init_ai_runner = __esm({
90430
91089
  const safeMessageId = encodeURIComponent(request.messageId);
90431
91090
  if (request.source === "job-dispatch") {
90432
91091
  const safeJobId = encodeURIComponent(request.jobId ?? "unknown");
90433
- return (0, import_node_path18.join)(this.logsDir, `ai-${safeJobId}-${safeMessageId}.log`);
91092
+ return (0, import_node_path21.join)(this.logsDir, `ai-${safeJobId}-${safeMessageId}.log`);
90434
91093
  }
90435
91094
  const safeSessionKey = encodeURIComponent(request.sessionKey);
90436
- return (0, import_node_path18.join)(this.logsDir, `ai-session-${safeSessionKey}-${safeMessageId}.log`);
91095
+ return (0, import_node_path21.join)(this.logsDir, `ai-session-${safeSessionKey}-${safeMessageId}.log`);
90437
91096
  }
90438
91097
  readRunAiSessionId(provider, request, file, sessionMeta) {
90439
91098
  if (request.source === "job-dispatch" && request.jobId) {
@@ -90745,7 +91404,7 @@ var init_ai_runner = __esm({
90745
91404
  async appendLlmLog(entry) {
90746
91405
  try {
90747
91406
  ensureTaskDir(this.logsDir);
90748
- await (0, import_promises6.appendFile)((0, import_node_path18.join)(this.logsDir, "llm.log"), formatLlmLogEntry(entry), "utf8");
91407
+ await (0, import_promises8.appendFile)((0, import_node_path21.join)(this.logsDir, "llm.log"), formatLlmLogEntry(entry), "utf8");
90749
91408
  } catch (err2) {
90750
91409
  errorWithTimestamp("[okx-agent-task] failed to append llm.log:", err2);
90751
91410
  }
@@ -93006,12 +93665,12 @@ async function isHermesGatewayPluginEnabled(options = {}) {
93006
93665
  if (options.requireGatewayRuntime && detectGatewayInvocation(env) !== "hermes") {
93007
93666
  return false;
93008
93667
  }
93009
- const hermesHome = env.HERMES_HOME?.trim() || (0, import_node_path19.join)((0, import_node_os7.homedir)(), ".hermes");
93010
- if (!(0, import_node_fs15.existsSync)((0, import_node_path19.join)(hermesHome, "plugins", "platforms", "okx-a2a", "plugin.yaml"))) {
93668
+ const hermesHome = env.HERMES_HOME?.trim() || (0, import_node_path22.join)((0, import_node_os7.homedir)(), ".hermes");
93669
+ if (!(0, import_node_fs16.existsSync)((0, import_node_path22.join)(hermesHome, "plugins", "platforms", "okx-a2a", "plugin.yaml"))) {
93011
93670
  return false;
93012
93671
  }
93013
93672
  try {
93014
- return hermesConfigEnablesOkxA2a(await (0, import_promises7.readFile)((0, import_node_path19.join)(hermesHome, "config.yaml"), "utf8"));
93673
+ return hermesConfigEnablesOkxA2a(await (0, import_promises9.readFile)((0, import_node_path22.join)(hermesHome, "config.yaml"), "utf8"));
93015
93674
  } catch {
93016
93675
  return false;
93017
93676
  }
@@ -93187,12 +93846,12 @@ async function runListenerWithLock(options, paths) {
93187
93846
  }));
93188
93847
  }
93189
93848
  });
93190
- service.setPluginVersion("0.1.3");
93849
+ service.setPluginVersion("0.1.4-beta-520175e226-260702152522");
93191
93850
  await service.init();
93192
93851
  const pluginVersionStatus = service.pluginVersionStatus;
93193
93852
  if (pluginVersionStatus.unavailable) {
93194
93853
  throw new Error(
93195
- `@okxweb3/a2a-node v${"0.1.3"} is below the required minimum v${pluginVersionStatus.minVersion}`
93854
+ `@okxweb3/a2a-node v${"0.1.4-beta-520175e226-260702152522"} is below the required minimum v${pluginVersionStatus.minVersion}`
93196
93855
  );
93197
93856
  }
93198
93857
  const systemConfig = service.getSystemConfig();
@@ -93210,7 +93869,7 @@ async function runListenerWithLock(options, paths) {
93210
93869
  onchainosAgentId: "*",
93211
93870
  reason: "system-config missing sentryDsn",
93212
93871
  pluginId: "@okxweb3/a2a-node",
93213
- pluginVersion: "0.1.3"
93872
+ pluginVersion: "0.1.4-beta-520175e226-260702152522"
93214
93873
  });
93215
93874
  }
93216
93875
  logWithTimestamp(
@@ -93509,7 +94168,7 @@ async function runListenerWithLock(options, paths) {
93509
94168
  });
93510
94169
  await markDaemonReady(paths.daemonLockPath);
93511
94170
  logWithTimestamp(`[okx-agent-task] daemon ready lock=${paths.daemonLockPath}`);
93512
- await new Promise((resolve8) => {
94171
+ await new Promise((resolve9) => {
93513
94172
  const shutdown2 = (signal) => {
93514
94173
  if (stopping) {
93515
94174
  return;
@@ -93518,7 +94177,7 @@ async function runListenerWithLock(options, paths) {
93518
94177
  logWithTimestamp(`[okx-agent-task] received ${signal}, stopping listener`);
93519
94178
  const forceResolve = setTimeout(() => {
93520
94179
  logWithTimestamp("[okx-agent-task] listener shutdown timed out; forcing process exit");
93521
- resolve8();
94180
+ resolve9();
93522
94181
  }, SHUTDOWN_FORCE_RESOLVE_MS);
93523
94182
  void (async () => {
93524
94183
  if (timer) {
@@ -93546,7 +94205,7 @@ async function runListenerWithLock(options, paths) {
93546
94205
  stopClients(service);
93547
94206
  sessionStore.close();
93548
94207
  clearTimeout(forceResolve);
93549
- resolve8();
94208
+ resolve9();
93550
94209
  })();
93551
94210
  };
93552
94211
  process.once("SIGTERM", shutdown2);
@@ -93562,15 +94221,15 @@ async function timeSettled(fn) {
93562
94221
  return { durationMs: Date.now() - startedAt, error };
93563
94222
  }
93564
94223
  }
93565
- var import_node_fs15, import_promises7, import_node_os7, import_node_path19, DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC, DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC, XMTP_CLIENT_RECYCLE_INTERVAL_ENV, HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS, SHUTDOWN_FORCE_RESOLVE_MS;
94224
+ var import_node_fs16, import_promises9, import_node_os7, import_node_path22, DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC, DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC, XMTP_CLIENT_RECYCLE_INTERVAL_ENV, HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS, SHUTDOWN_FORCE_RESOLVE_MS;
93566
94225
  var init_listener = __esm({
93567
94226
  "src/listener.ts"() {
93568
94227
  "use strict";
93569
94228
  init_log();
93570
- import_node_fs15 = require("node:fs");
93571
- import_promises7 = require("node:fs/promises");
94229
+ import_node_fs16 = require("node:fs");
94230
+ import_promises9 = require("node:fs/promises");
93572
94231
  import_node_os7 = require("node:os");
93573
- import_node_path19 = require("node:path");
94232
+ import_node_path22 = require("node:path");
93574
94233
  init_onchainos();
93575
94234
  init_system_config();
93576
94235
  init_signer();
@@ -93599,9 +94258,9 @@ var init_listener = __esm({
93599
94258
 
93600
94259
  // ../core/src/file-upload-safety.ts
93601
94260
  function getUnsafeFileUploadReason(filePath, sensitiveUploadReg = []) {
93602
- const expanded = (0, import_node_path20.resolve)(expandHome(filePath));
93603
- const target = (0, import_node_fs16.realpathSync)(expanded);
93604
- const targetName = (0, import_node_path20.basename)(target);
94261
+ const expanded = (0, import_node_path23.resolve)(expandHome(filePath));
94262
+ const target = (0, import_node_fs17.realpathSync)(expanded);
94263
+ const targetName = (0, import_node_path23.basename)(target);
93605
94264
  if (targetName === ".env" || targetName.startsWith(".env.")) {
93606
94265
  return ".env";
93607
94266
  }
@@ -93614,13 +94273,13 @@ function getUnsafeFileUploadReason(filePath, sensitiveUploadReg = []) {
93614
94273
  return null;
93615
94274
  }
93616
94275
  for (const dir of SENSITIVE_HOME_DIRS) {
93617
- const sensitiveDir = safeRealpath((0, import_node_path20.join)(home, dir));
94276
+ const sensitiveDir = safeRealpath((0, import_node_path23.join)(home, dir));
93618
94277
  if (sensitiveDir && isPathInside(target, sensitiveDir)) {
93619
94278
  return `~/${dir}`;
93620
94279
  }
93621
94280
  }
93622
94281
  for (const file of SENSITIVE_HOME_FILES) {
93623
- const sensitiveFile = safeRealpath((0, import_node_path20.join)(home, file));
94282
+ const sensitiveFile = safeRealpath((0, import_node_path23.join)(home, file));
93624
94283
  if (sensitiveFile && target === sensitiveFile) {
93625
94284
  return `~/${file}`;
93626
94285
  }
@@ -93648,27 +94307,27 @@ function expandHome(filePath) {
93648
94307
  if (filePath === "~") {
93649
94308
  return (0, import_node_os8.homedir)();
93650
94309
  }
93651
- if (filePath.startsWith(`~${import_node_path20.sep}`)) {
93652
- return (0, import_node_path20.join)((0, import_node_os8.homedir)(), filePath.slice(2));
94310
+ if (filePath.startsWith(`~${import_node_path23.sep}`)) {
94311
+ return (0, import_node_path23.join)((0, import_node_os8.homedir)(), filePath.slice(2));
93653
94312
  }
93654
94313
  return filePath;
93655
94314
  }
93656
94315
  function safeRealpath(path) {
93657
- if (!(0, import_node_fs16.existsSync)(path)) {
94316
+ if (!(0, import_node_fs17.existsSync)(path)) {
93658
94317
  return null;
93659
94318
  }
93660
- return (0, import_node_fs16.realpathSync)(path);
94319
+ return (0, import_node_fs17.realpathSync)(path);
93661
94320
  }
93662
94321
  function isPathInside(target, dir) {
93663
- return target === dir || target.startsWith(`${dir}${import_node_path20.sep}`);
94322
+ return target === dir || target.startsWith(`${dir}${import_node_path23.sep}`);
93664
94323
  }
93665
- var import_node_fs16, import_node_os8, import_node_path20, SENSITIVE_HOME_DIRS, SENSITIVE_HOME_FILES, UNSAFE_FILE_UPLOAD_MESSAGE;
94324
+ var import_node_fs17, import_node_os8, import_node_path23, SENSITIVE_HOME_DIRS, SENSITIVE_HOME_FILES, UNSAFE_FILE_UPLOAD_MESSAGE;
93666
94325
  var init_file_upload_safety = __esm({
93667
94326
  "../core/src/file-upload-safety.ts"() {
93668
94327
  "use strict";
93669
- import_node_fs16 = require("node:fs");
94328
+ import_node_fs17 = require("node:fs");
93670
94329
  import_node_os8 = require("node:os");
93671
- import_node_path20 = require("node:path");
94330
+ import_node_path23 = require("node:path");
93672
94331
  SENSITIVE_HOME_DIRS = [
93673
94332
  ".ssh",
93674
94333
  ".gnupg",
@@ -93676,7 +94335,7 @@ var init_file_upload_safety = __esm({
93676
94335
  ".azure",
93677
94336
  ".kube",
93678
94337
  ".docker",
93679
- (0, import_node_path20.join)(".config", "gcloud")
94338
+ (0, import_node_path23.join)(".config", "gcloud")
93680
94339
  ];
93681
94340
  SENSITIVE_HOME_FILES = [
93682
94341
  ".npmrc",
@@ -93738,7 +94397,7 @@ function hasHelpFlag(args) {
93738
94397
  return args.some((arg) => arg === "-h" || arg === "--help" || arg === "help");
93739
94398
  }
93740
94399
  async function uploadFile(params) {
93741
- const filename = params.filename || (0, import_node_path21.basename)(params.filePath);
94400
+ const filename = params.filename || (0, import_node_path24.basename)(params.filePath);
93742
94401
  const mimeType = params.mimeType || "application/octet-stream";
93743
94402
  const uploadConfig = readUploadSystemConfig();
93744
94403
  const unsafeReason = getUnsafeFileUploadReason(params.filePath, uploadConfig.sensitiveUploadReg);
@@ -93754,16 +94413,16 @@ async function uploadFile(params) {
93754
94413
  return;
93755
94414
  }
93756
94415
  const maxFileSizeBytes = uploadConfig.maxFileSizeBytes;
93757
- const fileSize = (0, import_node_fs17.statSync)(params.filePath).size;
94416
+ const fileSize = (0, import_node_fs18.statSync)(params.filePath).size;
93758
94417
  if (fileSize > maxFileSizeBytes) {
93759
94418
  throw new Error(formatFileTooLargeMessage(maxFileSizeBytes));
93760
94419
  }
93761
- const data = (0, import_node_fs17.readFileSync)(params.filePath);
94420
+ const data = (0, import_node_fs18.readFileSync)(params.filePath);
93762
94421
  const attachment = { filename, mimeType, data: new Uint8Array(data) };
93763
94422
  const encrypted = await RemoteAttachmentCodec.encodeEncrypted(attachment, new AttachmentCodec());
93764
94423
  ensureFileDirs();
93765
- const encryptedPath = (0, import_node_path21.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto12.randomUUID)()}.enc`);
93766
- (0, import_node_fs17.writeFileSync)(encryptedPath, encrypted.payload);
94424
+ const encryptedPath = (0, import_node_path24.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto12.randomUUID)()}.enc`);
94425
+ (0, import_node_fs18.writeFileSync)(encryptedPath, encrypted.payload);
93767
94426
  try {
93768
94427
  const stdout = runOnchainos([
93769
94428
  "agent",
@@ -93799,14 +94458,14 @@ async function uploadFile(params) {
93799
94458
  }, null, 2));
93800
94459
  } finally {
93801
94460
  try {
93802
- (0, import_node_fs17.unlinkSync)(encryptedPath);
94461
+ (0, import_node_fs18.unlinkSync)(encryptedPath);
93803
94462
  } catch {
93804
94463
  }
93805
94464
  }
93806
94465
  }
93807
94466
  async function downloadFile(params) {
93808
94467
  ensureFileDirs();
93809
- const encryptedPath = (0, import_node_path21.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto12.randomUUID)()}.enc`);
94468
+ const encryptedPath = (0, import_node_path24.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto12.randomUUID)()}.enc`);
93810
94469
  try {
93811
94470
  const stdout = runOnchainos([
93812
94471
  "agent",
@@ -93830,7 +94489,7 @@ async function downloadFile(params) {
93830
94489
  }));
93831
94490
  throw new Error(`file download failed: ${stdout}`);
93832
94491
  }
93833
- const payload = new Uint8Array((0, import_node_fs17.readFileSync)(encryptedPath));
94492
+ const payload = new Uint8Array((0, import_node_fs18.readFileSync)(encryptedPath));
93834
94493
  const digestBytes = new Uint8Array(await import_node_crypto12.webcrypto.subtle.digest("SHA-256", payload));
93835
94494
  const actualDigest = Array.from(digestBytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
93836
94495
  if (actualDigest !== params.digest) {
@@ -93842,12 +94501,12 @@ async function downloadFile(params) {
93842
94501
  const outputFilename = params.filename || attachment.filename || `${(0, import_node_crypto12.randomUUID)()}.bin`;
93843
94502
  const outputDir = DOWNLOADS_DIR;
93844
94503
  ensureA2aTaskDir(outputDir);
93845
- const outputPath = (0, import_node_path21.resolve)(outputDir, (0, import_node_path21.basename)(outputFilename));
93846
- (0, import_node_fs17.writeFileSync)(outputPath, attachment.data);
94504
+ const outputPath = (0, import_node_path24.resolve)(outputDir, (0, import_node_path24.basename)(outputFilename));
94505
+ (0, import_node_fs18.writeFileSync)(outputPath, attachment.data);
93847
94506
  console.log(outputPath);
93848
94507
  } finally {
93849
94508
  try {
93850
- (0, import_node_fs17.unlinkSync)(encryptedPath);
94509
+ (0, import_node_fs18.unlinkSync)(encryptedPath);
93851
94510
  } catch {
93852
94511
  }
93853
94512
  }
@@ -93874,7 +94533,8 @@ function runOnchainos(args, operation, extra = {}) {
93874
94533
  const [bin, ...prefix] = command;
93875
94534
  const result = (0, import_node_child_process7.spawnSync)(bin, [...prefix, ...args], {
93876
94535
  encoding: "utf8",
93877
- env: process.env
94536
+ env: process.env,
94537
+ windowsHide: true
93878
94538
  });
93879
94539
  if (result.error) {
93880
94540
  logger.error(LogEvent.ONCHAINOS_CLI_ERROR, result.error, fileCliSentryExtra(operation, "exec_error", {
@@ -93943,7 +94603,7 @@ function readUploadSystemConfig() {
93943
94603
  const res = parseCliJson2(stdout, "system-config");
93944
94604
  if (res.data && typeof res.data === "object") {
93945
94605
  ensureA2aTaskDir(OKX_A2A_PATHS.xmtpDir);
93946
- (0, import_node_fs17.writeFileSync)(SYSTEM_CONFIG_PATH, JSON.stringify(res.data));
94606
+ (0, import_node_fs18.writeFileSync)(SYSTEM_CONFIG_PATH, JSON.stringify(res.data));
93947
94607
  }
93948
94608
  return parseUploadSystemConfig(res.data ?? {});
93949
94609
  } catch {
@@ -93966,10 +94626,10 @@ function fileCliSentryExtra(operation, reason, extra = {}) {
93966
94626
  }
93967
94627
  function readSystemConfigFromCache() {
93968
94628
  try {
93969
- if (!(0, import_node_fs17.existsSync)(SYSTEM_CONFIG_PATH)) {
94629
+ if (!(0, import_node_fs18.existsSync)(SYSTEM_CONFIG_PATH)) {
93970
94630
  return null;
93971
94631
  }
93972
- return JSON.parse((0, import_node_fs17.readFileSync)(SYSTEM_CONFIG_PATH, "utf8"));
94632
+ return JSON.parse((0, import_node_fs18.readFileSync)(SYSTEM_CONFIG_PATH, "utf8"));
93973
94633
  } catch {
93974
94634
  return null;
93975
94635
  }
@@ -94003,14 +94663,14 @@ function readRequiredOption(args, name2) {
94003
94663
  }
94004
94664
  return value;
94005
94665
  }
94006
- var import_node_child_process7, import_node_crypto12, import_node_fs17, import_node_path21, import_proto4, OKX_A2A_PATHS, OKX_A2A_HOME_DIR, FILE_WORK_DIR, DOWNLOADS_DIR, SYSTEM_CONFIG_PATH;
94666
+ var import_node_child_process7, import_node_crypto12, import_node_fs18, import_node_path24, import_proto4, OKX_A2A_PATHS, OKX_A2A_HOME_DIR, FILE_WORK_DIR, DOWNLOADS_DIR, SYSTEM_CONFIG_PATH;
94007
94667
  var init_file_cli = __esm({
94008
94668
  "src/file-cli.ts"() {
94009
94669
  "use strict";
94010
94670
  import_node_child_process7 = require("node:child_process");
94011
94671
  import_node_crypto12 = require("node:crypto");
94012
- import_node_fs17 = require("node:fs");
94013
- import_node_path21 = require("node:path");
94672
+ import_node_fs18 = require("node:fs");
94673
+ import_node_path24 = require("node:path");
94014
94674
  init_dist6();
94015
94675
  import_proto4 = __toESM(require_node3());
94016
94676
  init_a2a_paths();
@@ -94021,7 +94681,7 @@ var init_file_cli = __esm({
94021
94681
  OKX_A2A_HOME_DIR = OKX_A2A_PATHS.homeDir;
94022
94682
  FILE_WORK_DIR = process.env.OKX_A2A_FILE_WORK_DIR || OKX_A2A_PATHS.filesDir;
94023
94683
  DOWNLOADS_DIR = process.env.OKX_A2A_DOWNLOADS_DIR || OKX_A2A_PATHS.downloadsDir;
94024
- SYSTEM_CONFIG_PATH = (0, import_node_path21.resolve)(OKX_A2A_PATHS.xmtpDir, "system-config.json");
94684
+ SYSTEM_CONFIG_PATH = (0, import_node_path24.resolve)(OKX_A2A_PATHS.xmtpDir, "system-config.json");
94025
94685
  }
94026
94686
  });
94027
94687
 
@@ -94506,16 +95166,16 @@ function createWakeSignal() {
94506
95166
  wake = null;
94507
95167
  },
94508
95168
  wait(ms) {
94509
- return new Promise((resolve8) => {
95169
+ return new Promise((resolve9) => {
94510
95170
  const timer = setTimeout(() => {
94511
95171
  if (wake === finish) {
94512
95172
  wake = null;
94513
95173
  }
94514
- resolve8();
95174
+ resolve9();
94515
95175
  }, ms);
94516
95176
  const finish = () => {
94517
95177
  clearTimeout(timer);
94518
- resolve8();
95178
+ resolve9();
94519
95179
  };
94520
95180
  wake = finish;
94521
95181
  });
@@ -94523,7 +95183,7 @@ function createWakeSignal() {
94523
95183
  };
94524
95184
  }
94525
95185
  function sleep3(ms) {
94526
- return new Promise((resolve8) => setTimeout(resolve8, ms));
95186
+ return new Promise((resolve9) => setTimeout(resolve9, ms));
94527
95187
  }
94528
95188
  function output(json, payload, human) {
94529
95189
  if (json) {
@@ -96130,6 +96790,8 @@ var init_ai_cli = __esm({
96130
96790
  // src/update-cli.ts
96131
96791
  var update_cli_exports = {};
96132
96792
  __export(update_cli_exports, {
96793
+ assertHermesSetupSupportedOnPlatform: () => assertHermesSetupSupportedOnPlatform,
96794
+ buildExternalCommandInvocation: () => buildExternalCommandInvocation,
96133
96795
  buildNpmPackageSpec: () => buildNpmPackageSpec,
96134
96796
  buildProviderMismatchWarning: () => buildProviderMismatchWarning,
96135
96797
  ensureHermesOkxA2aPluginConfig: () => ensureHermesOkxA2aPluginConfig,
@@ -96347,9 +97009,7 @@ async function runSetup(options) {
96347
97009
  if (provider) {
96348
97010
  switchDefaultProviderForSetup(provider);
96349
97011
  providerReadiness = await ensureAiCliAuthReadyForSetup(provider, resolvedTarget, releasePlan.resultRelease);
96350
- if (provider === "codex") {
96351
- providerReadiness = persistCodexProviderCommandForSetup(providerReadiness);
96352
- }
97012
+ providerReadiness = persistProviderCommandForSetup(providerReadiness);
96353
97013
  }
96354
97014
  if (nodeChange.nodeChanged && provider) {
96355
97015
  await restartNodeDaemonAfterNodeSetup();
@@ -96475,11 +97135,14 @@ function switchDefaultProviderForSetup(provider) {
96475
97135
  store.close();
96476
97136
  }
96477
97137
  }
96478
- function persistCodexProviderCommandForSetup(metadata) {
96479
- if (metadata.provider !== "codex") {
97138
+ function persistProviderCommandForSetup(metadata, platform = process.platform) {
97139
+ if (metadata.authStatus !== "ready") {
96480
97140
  return metadata;
96481
97141
  }
96482
- if (metadata.authStatus !== "ready") {
97142
+ if (!metadata.providerCommand) {
97143
+ return metadata;
97144
+ }
97145
+ if (metadata.provider !== "codex" && platform !== "win32") {
96483
97146
  return metadata;
96484
97147
  }
96485
97148
  const store = new SessionStore();
@@ -96802,7 +97465,7 @@ async function getCurrentNodeCliVersion() {
96802
97465
  return await getGlobalNpmPackageVersion(UPDATE_PACKAGES.node) ?? getBundledNodeCliVersion();
96803
97466
  }
96804
97467
  function getBundledNodeCliVersion() {
96805
- return true ? "0.1.3" : null;
97468
+ return true ? "0.1.4-beta-520175e226-260702152522" : null;
96806
97469
  }
96807
97470
  function readConfiguredAiProvider() {
96808
97471
  const explicit = process.env.OKX_A2A_AI_PROVIDER || process.env.OKX_AGENT_TASK_AI_CLI;
@@ -96947,23 +97610,35 @@ function normalizeOpenClawPluginAllowValue(allow) {
96947
97610
  }
96948
97611
  return { value: nextAllow, changed: allowChanged };
96949
97612
  }
97613
+ function assertHermesSetupSupportedOnPlatform(platform = process.platform) {
97614
+ if (platform !== "win32") {
97615
+ return;
97616
+ }
97617
+ errorWithTimestamp(
97618
+ `${WIN_COMPAT_LOG_PREFIX} hermes setup/update blocked: platform=${platform}; installer chain (tar -xzf + bash install-or-upgrade.sh) requires bash, unavailable on Windows`
97619
+ );
97620
+ throw new Error(
97621
+ "Hermes setup/update is not supported on Windows yet. The Hermes gateway installer requires bash. Use WSL, or run setup on macOS/Linux, or choose the codex/claude provider on Windows."
97622
+ );
97623
+ }
96950
97624
  async function updateHermes(release, options) {
97625
+ assertHermesSetupSupportedOnPlatform();
96951
97626
  const label = options.label ?? "update";
96952
97627
  if (!options.allowGatewayRuntime) {
96953
97628
  assertNotRunningInsideGateway("hermes");
96954
97629
  }
96955
97630
  const spec = buildNpmPackageSpec("hermes", release);
96956
- const workDir = await (0, import_promises8.mkdtemp)((0, import_node_path22.join)((0, import_node_os9.tmpdir)(), `okx-a2a-${label}-hermes-`));
97631
+ const workDir = await (0, import_promises10.mkdtemp)((0, import_node_path25.join)((0, import_node_os9.tmpdir)(), `okx-a2a-${label}-hermes-`));
96957
97632
  try {
96958
97633
  console.log(`[${label}] downloading ${spec}`);
96959
97634
  const npmTarball = await npmPack(spec, workDir);
96960
- const npmPackageDir = (0, import_node_path22.join)(workDir, "npm-package");
97635
+ const npmPackageDir = (0, import_node_path25.join)(workDir, "npm-package");
96961
97636
  await runCommand("tar", ["-xzf", npmTarball, "-C", npmPackageDir], { ensureDir: npmPackageDir });
96962
- const pluginTarball = await findHermesPluginTarball((0, import_node_path22.join)(npmPackageDir, "package", "dist"));
96963
- const pluginDir = (0, import_node_path22.join)(workDir, "plugin");
97637
+ const pluginTarball = await findHermesPluginTarball((0, import_node_path25.join)(npmPackageDir, "package", "dist"));
97638
+ const pluginDir = (0, import_node_path25.join)(workDir, "plugin");
96964
97639
  await runCommand("tar", ["-xzf", pluginTarball, "-C", pluginDir], { ensureDir: pluginDir });
96965
97640
  const unpackedPluginDir = await findFirstDirectory(pluginDir);
96966
- const installer = (0, import_node_path22.join)(unpackedPluginDir, "scripts", "install-or-upgrade.sh");
97641
+ const installer = (0, import_node_path25.join)(unpackedPluginDir, "scripts", "install-or-upgrade.sh");
96967
97642
  console.log(`[${label}] running ${installer}`);
96968
97643
  await runCommand("bash", [installer, ...options.restart ? ["--restart"] : []], { cwd: unpackedPluginDir });
96969
97644
  await normalizeHermesOkxA2aPluginConfig();
@@ -96974,7 +97649,7 @@ async function updateHermes(release, options) {
96974
97649
  }
96975
97650
  console.log(`[${label}] hermes ${label} done`);
96976
97651
  } finally {
96977
- await (0, import_promises8.rm)(workDir, { recursive: true, force: true });
97652
+ await (0, import_promises10.rm)(workDir, { recursive: true, force: true });
96978
97653
  }
96979
97654
  }
96980
97655
  function setupReadyMessage(target) {
@@ -96989,7 +97664,7 @@ function setupReadyMessage(target) {
96989
97664
  async function normalizeHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPath()) {
96990
97665
  let content3;
96991
97666
  try {
96992
- content3 = await (0, import_promises8.readFile)(configFile, "utf8");
97667
+ content3 = await (0, import_promises10.readFile)(configFile, "utf8");
96993
97668
  } catch (error) {
96994
97669
  if (isNodeError(error) && error.code === "ENOENT") {
96995
97670
  return false;
@@ -97000,18 +97675,18 @@ async function normalizeHermesOkxA2aPluginConfig(configFile = resolveHermesConfi
97000
97675
  if (!normalized.changed) {
97001
97676
  return false;
97002
97677
  }
97003
- await (0, import_promises8.writeFile)(configFile, normalized.content);
97678
+ await (0, import_promises10.writeFile)(configFile, normalized.content);
97004
97679
  console.log(`[update] normalized Hermes plugins.enabled okx-a2a entry in ${configFile}`);
97005
97680
  return true;
97006
97681
  }
97007
97682
  async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPath()) {
97008
97683
  let content3;
97009
97684
  try {
97010
- content3 = await (0, import_promises8.readFile)(configFile, "utf8");
97685
+ content3 = await (0, import_promises10.readFile)(configFile, "utf8");
97011
97686
  } catch (error) {
97012
97687
  if (isNodeError(error) && error.code === "ENOENT") {
97013
- await (0, import_promises8.mkdir)((0, import_node_path22.resolve)(configFile, ".."), { recursive: true });
97014
- await (0, import_promises8.writeFile)(configFile, "plugins:\n enabled:\n - okx-a2a\n");
97688
+ await (0, import_promises10.mkdir)((0, import_node_path25.resolve)(configFile, ".."), { recursive: true });
97689
+ await (0, import_promises10.writeFile)(configFile, "plugins:\n enabled:\n - okx-a2a\n");
97015
97690
  console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
97016
97691
  return true;
97017
97692
  }
@@ -97019,7 +97694,7 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
97019
97694
  }
97020
97695
  const normalized = normalizeHermesPluginConfigContent(content3);
97021
97696
  if (normalized.changed) {
97022
- await (0, import_promises8.writeFile)(configFile, normalized.content);
97697
+ await (0, import_promises10.writeFile)(configFile, normalized.content);
97023
97698
  console.log(`[update] normalized Hermes plugins.enabled okx-a2a entry in ${configFile}`);
97024
97699
  return true;
97025
97700
  }
@@ -97027,16 +97702,15 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
97027
97702
  return false;
97028
97703
  }
97029
97704
  const updated = addHermesOkxA2aEnabled(content3);
97030
- await (0, import_promises8.writeFile)(configFile, updated);
97705
+ await (0, import_promises10.writeFile)(configFile, updated);
97031
97706
  console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
97032
97707
  return true;
97033
97708
  }
97034
97709
  function normalizeHermesPluginConfigContent(content3) {
97035
97710
  const trailingNewline = content3.endsWith("\n");
97036
- const indentRepair = normalizeEnabledListItemIndents(content3.replace(/\n$/, "").split(/\n/));
97037
- const duplicateRepair = removeDuplicateInlineEnabledHeaders(indentRepair.lines);
97711
+ const duplicateRepair = removeDuplicateInlineEnabledHeaders(content3.replace(/\n$/, "").split(/\n/));
97038
97712
  const lines = duplicateRepair.lines;
97039
- let changed = indentRepair.changed || duplicateRepair.changed;
97713
+ let changed = duplicateRepair.changed;
97040
97714
  let hasOkxA2a = false;
97041
97715
  let inPlugins = false;
97042
97716
  let pluginsIndent = -1;
@@ -97095,7 +97769,9 @@ function normalizeHermesPluginConfigContent(content3) {
97095
97769
  }
97096
97770
  output4.push(line);
97097
97771
  }
97098
- return { content: `${output4.join("\n")}${trailingNewline ? "\n" : ""}`, changed, hasOkxA2a };
97772
+ const indentRepair = normalizeEnabledListItemIndents(output4);
97773
+ changed ||= indentRepair.changed;
97774
+ return { content: `${indentRepair.lines.join("\n")}${trailingNewline ? "\n" : ""}`, changed, hasOkxA2a };
97099
97775
  }
97100
97776
  function normalizeEnabledListItemIndents(lines) {
97101
97777
  const output4 = [...lines];
@@ -97243,7 +97919,7 @@ function findFirstEnabledListItem(lines, startIndex, enabledIndent) {
97243
97919
  return null;
97244
97920
  }
97245
97921
  function resolveHermesConfigPath() {
97246
- return (0, import_node_path22.join)(process.env.HERMES_HOME ?? (0, import_node_path22.join)((0, import_node_os9.homedir)(), ".hermes"), "config.yaml");
97922
+ return (0, import_node_path25.join)(process.env.HERMES_HOME ?? (0, import_node_path25.join)((0, import_node_os9.homedir)(), ".hermes"), "config.yaml");
97247
97923
  }
97248
97924
  function lineIndent(line) {
97249
97925
  const match = line.match(/^\s*/);
@@ -97324,7 +98000,7 @@ async function isGatewayPluginInstalled(target) {
97324
98000
  if (target === "openclaw") {
97325
98001
  return (await getInstalledOpenClawPluginInfo()).installed;
97326
98002
  }
97327
- if ((0, import_node_fs18.existsSync)((0, import_node_path22.join)(process.env.HERMES_HOME ?? (0, import_node_path22.join)((0, import_node_os9.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml"))) {
98003
+ if ((0, import_node_fs19.existsSync)((0, import_node_path25.join)(process.env.HERMES_HOME ?? (0, import_node_path25.join)((0, import_node_os9.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml"))) {
97328
98004
  return true;
97329
98005
  }
97330
98006
  return await isGlobalNpmPackageInstalled(UPDATE_PACKAGES.hermes);
@@ -97418,9 +98094,9 @@ function parsePackageVersionFromText(output4) {
97418
98094
  return output4.match(/@okxweb3\/a2a-openclaw@([0-9A-Za-z.+-]+)/)?.[1] ?? null;
97419
98095
  }
97420
98096
  async function getInstalledHermesPluginVersion() {
97421
- const pluginYaml = (0, import_node_path22.join)(process.env.HERMES_HOME ?? (0, import_node_path22.join)((0, import_node_os9.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml");
98097
+ const pluginYaml = (0, import_node_path25.join)(process.env.HERMES_HOME ?? (0, import_node_path25.join)((0, import_node_os9.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml");
97422
98098
  try {
97423
- const content3 = await (0, import_promises8.readFile)(pluginYaml, "utf8");
98099
+ const content3 = await (0, import_promises10.readFile)(pluginYaml, "utf8");
97424
98100
  return parsePluginYamlVersion(content3);
97425
98101
  } catch (error) {
97426
98102
  if (isNodeError(error) && error.code === "ENOENT") {
@@ -97451,17 +98127,22 @@ async function getGlobalNpmPackageVersion(packageName) {
97451
98127
  }
97452
98128
  }
97453
98129
  async function resolveNpmPackageVersion(target, release) {
97454
- try {
97455
- const output4 = await runCommandCapture("npm", ["view", buildNpmPackageSpec(target, release), "version"]);
97456
- return output4.trim().split(/\r?\n/).at(-1)?.trim() || null;
97457
- } catch {
97458
- return null;
97459
- }
98130
+ const output4 = await runCommandCapture("npm", ["view", buildNpmPackageSpec(target, release), "version"]);
98131
+ return output4.trim().split(/\r?\n/).at(-1)?.trim() || null;
97460
98132
  }
97461
98133
  async function resolveRequiredNpmPackageVersion(target, release) {
97462
- const version2 = await resolveNpmPackageVersion(target, release);
98134
+ const spec = buildNpmPackageSpec(target, release);
98135
+ let version2;
98136
+ try {
98137
+ version2 = await resolveNpmPackageVersion(target, release);
98138
+ } catch (error) {
98139
+ const detail = error instanceof Error ? error.message : String(error);
98140
+ throw new Error(`Unable to resolve npm package ${spec}. Check the release value and npm registry access.
98141
+ ${detail}`);
98142
+ }
97463
98143
  if (!version2) {
97464
- throw new Error(`Unable to resolve npm package ${buildNpmPackageSpec(target, release)}. Check the release value and npm registry access.`);
98144
+ throw new Error(`Unable to resolve npm package ${spec}. Check the release value and npm registry access.
98145
+ npm view returned empty version output.`);
97465
98146
  }
97466
98147
  return version2;
97467
98148
  }
@@ -97471,23 +98152,23 @@ async function npmPack(spec, destination) {
97471
98152
  if (!tarballName) {
97472
98153
  throw new Error(`Unable to detect npm pack tarball from output: ${output4.trim()}`);
97473
98154
  }
97474
- return (0, import_node_path22.resolve)(destination, (0, import_node_path22.basename)(tarballName));
98155
+ return (0, import_node_path25.resolve)(destination, (0, import_node_path25.basename)(tarballName));
97475
98156
  }
97476
98157
  async function findHermesPluginTarball(distDir) {
97477
- const entries = await (0, import_promises8.readdir)(distDir);
98158
+ const entries = await (0, import_promises10.readdir)(distDir);
97478
98159
  const tarball = entries.find((entry) => /^okx-a2a-hermes-plugin-.+\.tar\.gz$/.test(entry));
97479
98160
  if (!tarball) {
97480
98161
  throw new Error(`Hermes npm package did not contain dist/okx-a2a-hermes-plugin-*.tar.gz`);
97481
98162
  }
97482
- return (0, import_node_path22.join)(distDir, tarball);
98163
+ return (0, import_node_path25.join)(distDir, tarball);
97483
98164
  }
97484
98165
  async function findFirstDirectory(parent) {
97485
- const entries = await (0, import_promises8.readdir)(parent, { withFileTypes: true });
98166
+ const entries = await (0, import_promises10.readdir)(parent, { withFileTypes: true });
97486
98167
  const dir = entries.find((entry) => entry.isDirectory());
97487
98168
  if (!dir) {
97488
98169
  throw new Error(`No unpacked plugin directory found under ${parent}`);
97489
98170
  }
97490
- return (0, import_node_path22.join)(parent, dir.name);
98171
+ return (0, import_node_path25.join)(parent, dir.name);
97491
98172
  }
97492
98173
  function readOption2(args, name2) {
97493
98174
  const index2 = args.indexOf(name2);
@@ -97532,11 +98213,12 @@ function assertOnlyKnownUpdateOptions(args, command = "update") {
97532
98213
  }
97533
98214
  async function runCommand(command, args, options = {}) {
97534
98215
  if (options.ensureDir) {
97535
- const { mkdir: mkdir5 } = await import("node:fs/promises");
97536
- await mkdir5(options.ensureDir, { recursive: true });
98216
+ const { mkdir: mkdir6 } = await import("node:fs/promises");
98217
+ await mkdir6(options.ensureDir, { recursive: true });
97537
98218
  }
97538
98219
  await new Promise((resolvePromise, reject) => {
97539
- const child = (0, import_node_child_process8.spawn)(command, args, {
98220
+ const invocation = buildExternalCommandInvocation(command, args);
98221
+ const child = (0, import_node_child_process8.spawn)(invocation.command, invocation.args, {
97540
98222
  cwd: options.cwd,
97541
98223
  stdio: redirectCommandStdoutToStderr ? [options.inheritStdin ? "inherit" : "ignore", "pipe", "pipe"] : "inherit"
97542
98224
  });
@@ -97565,20 +98247,21 @@ async function runCommand(command, args, options = {}) {
97565
98247
  child.stderr.pipe(process.stderr);
97566
98248
  }
97567
98249
  child.on("error", (error) => {
97568
- finish(() => reject(error));
98250
+ finish(() => reject(new Error(`${formatExternalCommand(command, args)} failed to start: ${error.message}`)));
97569
98251
  });
97570
98252
  child.on("close", (code2, signal) => {
97571
98253
  if (code2 === 0) {
97572
98254
  finish(() => resolvePromise());
97573
98255
  return;
97574
98256
  }
97575
- finish(() => reject(new Error(`${command} ${args.join(" ")} failed with ${signal ? `signal=${signal}` : `code=${code2}`}`)));
98257
+ finish(() => reject(new Error(`${formatExternalCommand(command, args)} failed with ${signal ? `signal=${signal}` : `code=${code2}`}`)));
97576
98258
  });
97577
98259
  });
97578
98260
  }
97579
98261
  async function runCommandCapture(command, args) {
97580
98262
  return await new Promise((resolvePromise, reject) => {
97581
- const child = (0, import_node_child_process8.spawn)(command, args, { stdio: ["ignore", "pipe", "pipe"] });
98263
+ const invocation = buildExternalCommandInvocation(command, args);
98264
+ const child = (0, import_node_child_process8.spawn)(invocation.command, invocation.args, { stdio: ["ignore", "pipe", "pipe"] });
97582
98265
  let stdout = "";
97583
98266
  let stderr = "";
97584
98267
  child.stdout.setEncoding("utf8");
@@ -97589,7 +98272,9 @@ async function runCommandCapture(command, args) {
97589
98272
  child.stderr.on("data", (chunk) => {
97590
98273
  stderr += chunk;
97591
98274
  });
97592
- child.on("error", reject);
98275
+ child.on("error", (error) => {
98276
+ reject(new Error(`${formatExternalCommand(command, args)} failed to start: ${error.message}`));
98277
+ });
97593
98278
  child.on("close", (code2, signal) => {
97594
98279
  if (code2 === 0) {
97595
98280
  if (stderr.trim()) {
@@ -97598,14 +98283,15 @@ async function runCommandCapture(command, args) {
97598
98283
  resolvePromise(stdout);
97599
98284
  return;
97600
98285
  }
97601
- reject(new Error(`${command} ${args.join(" ")} failed with ${signal ? `signal=${signal}` : `code=${code2}`}
98286
+ reject(new Error(`${formatExternalCommand(command, args)} failed with ${signal ? `signal=${signal}` : `code=${code2}`}
97602
98287
  ${stderr}`));
97603
98288
  });
97604
98289
  });
97605
98290
  }
97606
98291
  async function runCommandCaptureOptional(command, args) {
97607
98292
  return await new Promise((resolvePromise) => {
97608
- const child = (0, import_node_child_process8.spawn)(command, args, { stdio: ["ignore", "pipe", "ignore"] });
98293
+ const invocation = buildExternalCommandInvocation(command, args);
98294
+ const child = (0, import_node_child_process8.spawn)(invocation.command, invocation.args, { stdio: ["ignore", "pipe", "ignore"] });
97609
98295
  let stdout = "";
97610
98296
  child.stdout.setEncoding("utf8");
97611
98297
  child.stdout.on("data", (chunk) => {
@@ -97621,7 +98307,8 @@ async function runCommandCaptureOptional(command, args) {
97621
98307
  }
97622
98308
  async function runCommandCaptureStatus(command, args) {
97623
98309
  return await new Promise((resolvePromise) => {
97624
- const child = (0, import_node_child_process8.spawn)(command, args, { stdio: ["ignore", "pipe", "pipe"] });
98310
+ const invocation = buildExternalCommandInvocation(command, args);
98311
+ const child = (0, import_node_child_process8.spawn)(invocation.command, invocation.args, { stdio: ["ignore", "pipe", "pipe"] });
97625
98312
  let stdout = "";
97626
98313
  let stderr = "";
97627
98314
  child.stdout.setEncoding("utf8");
@@ -97654,16 +98341,24 @@ async function runCommandCaptureStatus(command, args) {
97654
98341
  });
97655
98342
  });
97656
98343
  }
97657
- var import_node_child_process8, import_node_fs18, import_promises8, import_node_os9, import_node_path22, UPDATE_PACKAGES, CODEX_NPM_PACKAGE, OPENCLAW_FORCE_INSTALL_FLAG, OPENCLAW_UNSAFE_INSTALL_FLAG, OKX_A2A_PLUGIN_ID, OPENCLAW_SESSION_DM_SCOPE_CONFIG_PATH, OPENCLAW_SESSION_DM_SCOPE_CONFIG_VALUE, OPENCLAW_PLUGIN_ALLOW_CONFIG_PATH, OPENCLAW_OKX_A2A_CONVERSATION_HOOK_ACCESS_CONFIG_PATH, DEFAULT_AI_PROVIDER_LOGIN_TIMEOUT_MS, SetupBlockedError, redirectCommandStdoutToStderr;
98344
+ function buildExternalCommandInvocation(command, args, platform = process.platform, comSpec = process.env.ComSpec ?? process.env.COMSPEC) {
98345
+ return toWindowsInvocation(command, args, platform, comSpec);
98346
+ }
98347
+ function formatExternalCommand(command, args) {
98348
+ return [command, ...args].join(" ");
98349
+ }
98350
+ var import_node_child_process8, import_node_fs19, import_promises10, import_node_os9, import_node_path25, UPDATE_PACKAGES, CODEX_NPM_PACKAGE, OPENCLAW_FORCE_INSTALL_FLAG, OPENCLAW_UNSAFE_INSTALL_FLAG, OKX_A2A_PLUGIN_ID, OPENCLAW_SESSION_DM_SCOPE_CONFIG_PATH, OPENCLAW_SESSION_DM_SCOPE_CONFIG_VALUE, OPENCLAW_PLUGIN_ALLOW_CONFIG_PATH, OPENCLAW_OKX_A2A_CONVERSATION_HOOK_ACCESS_CONFIG_PATH, DEFAULT_AI_PROVIDER_LOGIN_TIMEOUT_MS, SetupBlockedError, redirectCommandStdoutToStderr;
97658
98351
  var init_update_cli = __esm({
97659
98352
  "src/update-cli.ts"() {
97660
98353
  "use strict";
97661
98354
  import_node_child_process8 = require("node:child_process");
97662
- import_node_fs18 = require("node:fs");
97663
- import_promises8 = require("node:fs/promises");
98355
+ import_node_fs19 = require("node:fs");
98356
+ import_promises10 = require("node:fs/promises");
97664
98357
  import_node_os9 = require("node:os");
97665
- import_node_path22 = require("node:path");
98358
+ import_node_path25 = require("node:path");
97666
98359
  init_ai_command();
98360
+ init_win_spawn();
98361
+ init_log();
97667
98362
  init_ai_provider();
97668
98363
  init_session_store();
97669
98364
  UPDATE_PACKAGES = {
@@ -97694,9 +98389,9 @@ var init_update_cli = __esm({
97694
98389
 
97695
98390
  // src/cli.ts
97696
98391
  var import_node_child_process9 = require("node:child_process");
97697
- var import_node_fs19 = require("node:fs");
98392
+ var import_node_fs20 = require("node:fs");
97698
98393
  var import_node_os10 = require("node:os");
97699
- var import_node_path23 = require("node:path");
98394
+ var import_node_path26 = require("node:path");
97700
98395
  init_daemon();
97701
98396
  init_command_store();
97702
98397
  init_file_store();
@@ -97706,11 +98401,202 @@ init_outbound_behavior();
97706
98401
  init_openclaw_route();
97707
98402
  init_paths();
97708
98403
  init_task_config();
98404
+
98405
+ // src/log-tail.ts
98406
+ var import_node_fs10 = require("node:fs");
98407
+ var import_promises5 = require("node:fs/promises");
98408
+ var import_node_string_decoder = require("node:string_decoder");
98409
+ init_log();
98410
+ init_win_spawn();
98411
+ var READ_CHUNK_SIZE = 64 * 1024;
98412
+ var NEWLINE_BYTE = 10;
98413
+ async function readLastLines(filePath, maxLines) {
98414
+ if (!Number.isFinite(maxLines) || maxLines <= 0) {
98415
+ return "";
98416
+ }
98417
+ let handle;
98418
+ try {
98419
+ handle = await (0, import_promises5.open)(filePath, "r");
98420
+ } catch (error) {
98421
+ if (error.code === "ENOENT") {
98422
+ return "";
98423
+ }
98424
+ errorWithTimestamp(
98425
+ `${WIN_COMPAT_LOG_PREFIX} readLastLines open failed path=${filePath} errorCode=${error.code ?? "unknown"}: ${error.message}`
98426
+ );
98427
+ throw error;
98428
+ }
98429
+ try {
98430
+ const stats = await handle.stat();
98431
+ const size3 = stats.size;
98432
+ if (size3 === 0) {
98433
+ return "";
98434
+ }
98435
+ const chunks = [];
98436
+ let position = size3;
98437
+ let newlineCount = 0;
98438
+ let startOffset = 0;
98439
+ outer: while (position > 0) {
98440
+ const readLength = Math.min(READ_CHUNK_SIZE, position);
98441
+ position -= readLength;
98442
+ const buffer2 = Buffer.alloc(readLength);
98443
+ await readFully(handle, buffer2, position);
98444
+ chunks.unshift(buffer2);
98445
+ for (let i = readLength - 1; i >= 0; i--) {
98446
+ if (buffer2[i] !== NEWLINE_BYTE) {
98447
+ continue;
98448
+ }
98449
+ const absolute = position + i;
98450
+ if (absolute === size3 - 1) {
98451
+ continue;
98452
+ }
98453
+ newlineCount++;
98454
+ if (newlineCount === maxLines) {
98455
+ startOffset = absolute + 1;
98456
+ break outer;
98457
+ }
98458
+ }
98459
+ }
98460
+ const joined = Buffer.concat(chunks);
98461
+ return joined.subarray(startOffset - position).toString("utf8");
98462
+ } finally {
98463
+ await handle.close();
98464
+ }
98465
+ }
98466
+ async function followFile(filePath, onData, options = {}) {
98467
+ const pollIntervalMs = options.pollIntervalMs ?? 1e3;
98468
+ const signal = options.signal;
98469
+ if (signal?.aborted) {
98470
+ return;
98471
+ }
98472
+ let offset = await currentSizeOrZero(filePath);
98473
+ let decoder = new import_node_string_decoder.StringDecoder("utf8");
98474
+ let checking = false;
98475
+ let done = false;
98476
+ await new Promise((resolvePromise) => {
98477
+ let watcher;
98478
+ let timer;
98479
+ const finish = () => {
98480
+ if (done) {
98481
+ return;
98482
+ }
98483
+ done = true;
98484
+ if (timer !== void 0) {
98485
+ clearInterval(timer);
98486
+ }
98487
+ if (watcher !== void 0) {
98488
+ watcher.close();
98489
+ }
98490
+ signal?.removeEventListener("abort", finish);
98491
+ resolvePromise();
98492
+ };
98493
+ const check = async () => {
98494
+ if (checking || done) {
98495
+ return;
98496
+ }
98497
+ checking = true;
98498
+ try {
98499
+ const size3 = await currentSizeOrZero(filePath);
98500
+ if (size3 < offset) {
98501
+ logWithTimestamp(
98502
+ `${WIN_COMPAT_LOG_PREFIX} followFile detected truncation path=${filePath} previousOffset=${offset} newSize=${size3}; re-reading from 0`
98503
+ );
98504
+ offset = 0;
98505
+ decoder = new import_node_string_decoder.StringDecoder("utf8");
98506
+ }
98507
+ if (size3 > offset) {
98508
+ const buffer2 = await readRange(filePath, offset, size3);
98509
+ offset += buffer2.length;
98510
+ if (buffer2.length > 0 && !done) {
98511
+ const text = decoder.write(buffer2);
98512
+ if (text.length > 0) {
98513
+ onData(text);
98514
+ }
98515
+ }
98516
+ }
98517
+ } catch (error) {
98518
+ if (error.code !== "ENOENT") {
98519
+ errorWithTimestamp(
98520
+ `${WIN_COMPAT_LOG_PREFIX} followFile poll failed path=${filePath} errorCode=${error.code ?? "unknown"}: ${error.message}`
98521
+ );
98522
+ }
98523
+ } finally {
98524
+ checking = false;
98525
+ }
98526
+ };
98527
+ timer = setInterval(() => {
98528
+ void check();
98529
+ }, pollIntervalMs);
98530
+ try {
98531
+ watcher = (0, import_node_fs10.watch)(filePath, () => {
98532
+ void check();
98533
+ });
98534
+ watcher.on("error", (error) => {
98535
+ errorWithTimestamp(
98536
+ `${WIN_COMPAT_LOG_PREFIX} followFile fs.watch error path=${filePath}: ${error.message}; polling continues`
98537
+ );
98538
+ });
98539
+ } catch (error) {
98540
+ errorWithTimestamp(
98541
+ `${WIN_COMPAT_LOG_PREFIX} followFile fs.watch unavailable path=${filePath} errorCode=${error.code ?? "unknown"}: ${error.message}; falling back to polling only`
98542
+ );
98543
+ }
98544
+ signal?.addEventListener("abort", finish);
98545
+ if (signal?.aborted) {
98546
+ finish();
98547
+ return;
98548
+ }
98549
+ void check();
98550
+ });
98551
+ }
98552
+ async function currentSizeOrZero(filePath) {
98553
+ try {
98554
+ const stats = await (0, import_promises5.stat)(filePath);
98555
+ return stats.size;
98556
+ } catch (error) {
98557
+ if (error.code === "ENOENT") {
98558
+ return 0;
98559
+ }
98560
+ throw error;
98561
+ }
98562
+ }
98563
+ async function readRange(filePath, start, end) {
98564
+ const handle = await (0, import_promises5.open)(filePath, "r");
98565
+ try {
98566
+ const length2 = end - start;
98567
+ const buffer2 = Buffer.alloc(length2);
98568
+ let totalRead = 0;
98569
+ while (totalRead < length2) {
98570
+ const { bytesRead } = await handle.read(buffer2, totalRead, length2 - totalRead, start + totalRead);
98571
+ if (bytesRead === 0) {
98572
+ break;
98573
+ }
98574
+ totalRead += bytesRead;
98575
+ }
98576
+ return buffer2.subarray(0, totalRead);
98577
+ } finally {
98578
+ await handle.close();
98579
+ }
98580
+ }
98581
+ async function readFully(handle, buffer2, position) {
98582
+ let totalRead = 0;
98583
+ while (totalRead < buffer2.length) {
98584
+ const { bytesRead } = await handle.read(buffer2, totalRead, buffer2.length - totalRead, position + totalRead);
98585
+ if (bytesRead === 0) {
98586
+ return;
98587
+ }
98588
+ totalRead += bytesRead;
98589
+ }
98590
+ }
98591
+
98592
+ // src/cli.ts
98593
+ init_win_spawn();
98594
+ init_log();
97709
98595
  init_sentry_logger();
97710
98596
  init_sentry_config();
97711
98597
  var CURRENT_GATEWAY_SESSION_KEYS_ENV3 = "OKX_A2A_CURRENT_GATEWAY_SESSION_KEYS";
97712
98598
  function printUsage2() {
97713
- console.log(`okx-a2a ${"0.1.3"}
98599
+ console.log(`okx-a2a ${"0.1.4-beta-520175e226-260702152522"}
97714
98600
 
97715
98601
  Usage:
97716
98602
  okx-a2a <command> [options]
@@ -97747,7 +98633,7 @@ Run \`okx-a2a <command> -h\` for command-specific help.
97747
98633
  `);
97748
98634
  }
97749
98635
  function printVersion() {
97750
- console.log("0.1.3");
98636
+ console.log("0.1.4-beta-520175e226-260702152522");
97751
98637
  }
97752
98638
  function printDaemonUsage() {
97753
98639
  console.log(`Usage: okx-a2a daemon <start|restart|stop|status|autostart> [options]
@@ -98033,12 +98919,27 @@ async function printDaemonStatus() {
98033
98919
  }
98034
98920
  }
98035
98921
  async function tailLogFile(logPath) {
98036
- await new Promise((resolve8, reject) => {
98922
+ if (process.platform === "win32") {
98923
+ logWithTimestamp(`${WIN_COMPAT_LOG_PREFIX} tail binary unavailable on win32; using pure-Node tail path=${logPath}`);
98924
+ try {
98925
+ process.stdout.write(await readLastLines(logPath, 600));
98926
+ await followFile(logPath, (chunk) => {
98927
+ process.stdout.write(chunk);
98928
+ });
98929
+ } catch (error) {
98930
+ errorWithTimestamp(
98931
+ `${WIN_COMPAT_LOG_PREFIX} pure-Node tail failed path=${logPath} errorCode=${error.code ?? "unknown"}: ${error.message}`
98932
+ );
98933
+ throw error;
98934
+ }
98935
+ return;
98936
+ }
98937
+ await new Promise((resolve9, reject) => {
98037
98938
  const child = (0, import_node_child_process9.spawn)("tail", ["-600", "-f", logPath], { stdio: "inherit" });
98038
98939
  child.on("error", reject);
98039
98940
  child.on("close", (code2, signal) => {
98040
98941
  if (signal || code2 === 0) {
98041
- resolve8();
98942
+ resolve9();
98042
98943
  return;
98043
98944
  }
98044
98945
  reject(new Error(`tail exited with code=${code2}`));
@@ -98057,7 +98958,7 @@ async function handleLogs(args) {
98057
98958
  return;
98058
98959
  }
98059
98960
  if (subcommand === "llm") {
98060
- await tailLogFile((0, import_node_path23.join)(paths.logsDir, "llm.log"));
98961
+ await tailLogFile((0, import_node_path26.join)(paths.logsDir, "llm.log"));
98061
98962
  return;
98062
98963
  }
98063
98964
  throw new Error("logs requires <server|llm>");
@@ -98969,11 +99870,11 @@ function initDirectCliSentry() {
98969
99870
  }
98970
99871
  cliSentryInitAttempted = true;
98971
99872
  try {
98972
- const configPath = (0, import_node_path23.join)(resolveTaskHomeForSentryConfig(), "xmtp", "system-config.json");
98973
- if (!(0, import_node_fs19.existsSync)(configPath)) {
99873
+ const configPath = (0, import_node_path26.join)(resolveTaskHomeForSentryConfig(), "xmtp", "system-config.json");
99874
+ if (!(0, import_node_fs20.existsSync)(configPath)) {
98974
99875
  return;
98975
99876
  }
98976
- const config = JSON.parse((0, import_node_fs19.readFileSync)(configPath, "utf8"));
99877
+ const config = JSON.parse((0, import_node_fs20.readFileSync)(configPath, "utf8"));
98977
99878
  if (typeof config.sentryDsn !== "string" || !config.sentryDsn) {
98978
99879
  return;
98979
99880
  }
@@ -98993,11 +99894,11 @@ function resolveTaskHomeForSentryConfig() {
98993
99894
  try {
98994
99895
  const home = (0, import_node_os10.homedir)();
98995
99896
  if (home) {
98996
- return (0, import_node_path23.join)(home, ".okx-agent-task");
99897
+ return (0, import_node_path26.join)(home, ".okx-agent-task");
98997
99898
  }
98998
99899
  } catch {
98999
99900
  }
99000
- return (0, import_node_path23.resolve)(process.cwd(), ".okx-agent-task");
99901
+ return (0, import_node_path26.resolve)(process.cwd(), ".okx-agent-task");
99001
99902
  }
99002
99903
  function directCliSentryExtra(operation, extra = {}) {
99003
99904
  return {
@@ -99013,8 +99914,8 @@ async function flushDirectCliSentry() {
99013
99914
  return;
99014
99915
  }
99015
99916
  try {
99016
- const timeout = new Promise((resolve8) => {
99017
- const timer = setTimeout(() => resolve8("timeout"), 750);
99917
+ const timeout = new Promise((resolve9) => {
99918
+ const timer = setTimeout(() => resolve9("timeout"), 750);
99018
99919
  timer.unref?.();
99019
99920
  });
99020
99921
  const result = await Promise.race([shutdown().then(() => "flushed"), timeout]);