@lengmoxxl/sdk 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AgentInfo } from './types';
2
2
  export declare function agentCommand(command: string): string;
3
- export declare function ensureAgent(host: string, { version, prefix, signal }: AgentInfo & {
3
+ export declare function ensureAgent(host: string, { version, prefixes, signal }: AgentInfo & {
4
4
  signal?: AbortSignal;
5
5
  }): Promise<void>;
package/dist/channel.d.ts CHANGED
@@ -53,5 +53,6 @@ export interface UiContext {
53
53
  message: string;
54
54
  };
55
55
  tabs(options: TabOptions): void;
56
+ open(url: string): Promise<void>;
56
57
  };
57
58
  }
package/dist/index.cjs CHANGED
@@ -114,12 +114,13 @@ var Pty = class {
114
114
  var import_node_child_process = require("node:child_process");
115
115
  var import_node_util = require("node:util");
116
116
  var exec = (0, import_node_util.promisify)(import_node_child_process.execFile);
117
+ var DOWNLOAD_TIMEOUT = 3e4;
117
118
  function agentCommand(command) {
118
119
  const home = process.env.WANGCAI_HOME;
119
120
  const exportHome = home ? `export WANGCAI_HOME='${home.replace(/'/g, String.raw`'\''`)}'; ` : "";
120
121
  return `${exportHome}export PATH="$HOME/.local/bin:$PATH"; ${command}`;
121
122
  }
122
- async function ensureAgent(host, { version, prefix, signal }) {
123
+ async function ensureAgent(host, { version, prefixes, signal }) {
123
124
  const targets = {
124
125
  "Darwin x86_64": "x86_64-apple-darwin",
125
126
  "Darwin arm64": "aarch64-apple-darwin",
@@ -132,19 +133,35 @@ async function ensureAgent(host, { version, prefix, signal }) {
132
133
  const target = targets[platform];
133
134
  if (!target) throw new Error(`${platform} \u4E0A\u6682\u4E0D\u652F\u6301\u81EA\u52A8\u5B89\u88C5 agent`);
134
135
  if (installed === `wangcai ${version}`) return;
135
- const response = await fetch(`${prefix}/v${version}/wangcai-${target}`, { signal });
136
- if (!response.ok) throw new Error(`\u4E0B\u8F7D agent \u5931\u8D25\uFF1A${response.status} ${response.statusText}`);
137
- const binary = Buffer.from(await response.arrayBuffer());
138
- await new Promise((resolve, reject) => {
139
- const child = (0, import_node_child_process.spawn)("ssh", remote("mkdir -p ~/.local/bin && cat > ~/.local/bin/.wangcai.tmp && chmod 755 ~/.local/bin/.wangcai.tmp && mv ~/.local/bin/.wangcai.tmp ~/.local/bin/wangcai"), { stdio: ["pipe", "ignore", "pipe"] });
140
- let stderr = "";
141
- child.stderr.on("data", (chunk) => {
142
- stderr += chunk;
136
+ const failures = [];
137
+ for (const prefix of prefixes) {
138
+ signal?.throwIfAborted();
139
+ const url = `${prefix}/v${version}/wangcai-${target}`;
140
+ const deadline = AbortSignal.timeout(DOWNLOAD_TIMEOUT);
141
+ let binary;
142
+ try {
143
+ const response = await fetch(url, { signal: signal ? AbortSignal.any([signal, deadline]) : deadline });
144
+ if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);
145
+ binary = Buffer.from(await response.arrayBuffer());
146
+ } catch (error) {
147
+ failures.push(`${url}
148
+ ${error instanceof Error ? error.message : String(error)}`);
149
+ continue;
150
+ }
151
+ await new Promise((resolve, reject) => {
152
+ const child = (0, import_node_child_process.spawn)("ssh", remote("mkdir -p ~/.local/bin && cat > ~/.local/bin/.wangcai.tmp && chmod 755 ~/.local/bin/.wangcai.tmp && mv ~/.local/bin/.wangcai.tmp ~/.local/bin/wangcai"), { stdio: ["pipe", "ignore", "pipe"] });
153
+ let stderr = "";
154
+ child.stderr.on("data", (chunk) => {
155
+ stderr += chunk;
156
+ });
157
+ child.on("error", reject);
158
+ child.on("close", (code) => code === 0 ? resolve() : reject(new Error(stderr.trim() || `\u5199\u5165 agent \u5931\u8D25\uFF08ssh \u9000\u51FA\u7801 ${code}\uFF09`)));
159
+ child.stdin.end(binary);
143
160
  });
144
- child.on("error", reject);
145
- child.on("close", (code) => code === 0 ? resolve() : reject(new Error(stderr.trim() || `\u5199\u5165 agent \u5931\u8D25\uFF08ssh \u9000\u51FA\u7801 ${code}\uFF09`)));
146
- child.stdin.end(binary);
147
- });
161
+ return;
162
+ }
163
+ throw new Error(`\u4E0B\u8F7D agent \u5931\u8D25\uFF1A
164
+ ${failures.join("\n\n")}`);
148
165
  }
149
166
 
150
167
  // connection.ts
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export interface AgentInfo {
2
2
  version: string;
3
- prefix: string;
3
+ prefixes: string[];
4
4
  }
5
5
  /**
6
6
  * The workspace protocol. A plugin that init.ts lists under `workspaces` is a workspace provider, and
@@ -132,7 +132,4 @@ export interface Theme {
132
132
  }
133
133
  export interface Profile {
134
134
  theme: Theme;
135
- agent: {
136
- downloadPrefix: string;
137
- };
138
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lengmoxxl/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Client SDK for WangCai: connect to a local or remote machine and drive its pty, files and git",
5
5
  "license": "MIT",
6
6
  "repository": {