@lengmoxxl/sdk 0.1.1 → 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
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- ensureAgent: () => ensureAgent,
34
33
  openMachine: () => openMachine
35
34
  });
36
35
  module.exports = __toCommonJS(index_exports);
@@ -115,12 +114,13 @@ var Pty = class {
115
114
  var import_node_child_process = require("node:child_process");
116
115
  var import_node_util = require("node:util");
117
116
  var exec = (0, import_node_util.promisify)(import_node_child_process.execFile);
117
+ var DOWNLOAD_TIMEOUT = 3e4;
118
118
  function agentCommand(command) {
119
119
  const home = process.env.WANGCAI_HOME;
120
120
  const exportHome = home ? `export WANGCAI_HOME='${home.replace(/'/g, String.raw`'\''`)}'; ` : "";
121
121
  return `${exportHome}export PATH="$HOME/.local/bin:$PATH"; ${command}`;
122
122
  }
123
- async function ensureAgent(host, { version, prefix, signal }) {
123
+ async function ensureAgent(host, { version, prefixes, signal }) {
124
124
  const targets = {
125
125
  "Darwin x86_64": "x86_64-apple-darwin",
126
126
  "Darwin arm64": "aarch64-apple-darwin",
@@ -133,19 +133,35 @@ async function ensureAgent(host, { version, prefix, signal }) {
133
133
  const target = targets[platform];
134
134
  if (!target) throw new Error(`${platform} \u4E0A\u6682\u4E0D\u652F\u6301\u81EA\u52A8\u5B89\u88C5 agent`);
135
135
  if (installed === `wangcai ${version}`) return;
136
- const response = await fetch(`${prefix}/v${version}/wangcai-${target}`, { signal });
137
- if (!response.ok) throw new Error(`\u4E0B\u8F7D agent \u5931\u8D25\uFF1A${response.status} ${response.statusText}`);
138
- const binary = Buffer.from(await response.arrayBuffer());
139
- await new Promise((resolve, reject) => {
140
- 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"] });
141
- let stderr = "";
142
- child.stderr.on("data", (chunk) => {
143
- 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);
144
160
  });
145
- child.on("error", reject);
146
- child.on("close", (code) => code === 0 ? resolve() : reject(new Error(stderr.trim() || `\u5199\u5165 agent \u5931\u8D25\uFF08ssh \u9000\u51FA\u7801 ${code}\uFF09`)));
147
- child.stdin.end(binary);
148
- });
161
+ return;
162
+ }
163
+ throw new Error(`\u4E0B\u8F7D agent \u5931\u8D25\uFF1A
164
+ ${failures.join("\n\n")}`);
149
165
  }
150
166
 
151
167
  // connection.ts
@@ -505,6 +521,5 @@ async function openMachine(options) {
505
521
  }
506
522
  // Annotate the CommonJS export names for ESM import in node:
507
523
  0 && (module.exports = {
508
- ensureAgent,
509
524
  openMachine
510
525
  });
package/dist/index.d.ts CHANGED
@@ -3,6 +3,5 @@ import type { ConnectionOptions } from './types';
3
3
  export type { AgentInfo, ConnectionOptions, FileClick, Machine, MachineState, Session, Size, Output, Snapshot, TerminalEvent, DirectoryEntry, ExecOptions, ExecResult, Profile, Theme, WorkspaceActive, WorkspaceRow, WorkspaceMenuItem } from './types';
4
4
  export type { MachineConnection } from './connection';
5
5
  export type { Pty } from './pty';
6
- export { ensureAgent } from './agent';
7
6
  /** Opens one connection to a machine and waits for it to be ready. */
8
7
  export declare function openMachine(options: ConnectionOptions): Promise<MachineConnection>;
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.1",
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": {
@@ -52,4 +52,4 @@
52
52
  "typescript": "^5.9.0",
53
53
  "esbuild": "^0.25.0"
54
54
  }
55
- }
55
+ }