@lengmoxxl/sdk 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
  The client SDK for [WangCai](https://github.com/lengmoXXL/WangCai), the terminal app. It reaches a machine, the one
3
3
  the app runs on or one over SSH, and drives its terminals, files and subprocesses through a single connection.
4
4
 
5
- A WangCai plugin compiles against this package, but at load time the app injects its own copy of this module, so a
6
- plugin never carries its own connection pool.
5
+ A WangCai plugin compiles against this package for the types it uses; the machines belong to the app, which keeps
6
+ one connection per machine and hands it to every plugin that asks for one.
7
7
 
8
8
  ## Install
9
9
 
@@ -16,9 +16,9 @@ npm install @lengmoxxl/sdk
16
16
  ## Use
17
17
 
18
18
  ```ts
19
- import { connect } from '@lengmoxxl/sdk';
19
+ import { openMachine } from '@lengmoxxl/sdk';
20
20
 
21
- const connection = await connect({ type: 'local', binary: '/path/to/wangcai' });
21
+ const connection = await openMachine({ type: 'local', binary: '/path/to/wangcai' });
22
22
 
23
23
  const sessions = await connection.pty.list();
24
24
  const session = await connection.pty.create({ rows: 24, cols: 80 }, '/repo');
@@ -30,9 +30,10 @@ const { stdout } = await connection.subprocess.exec('git', ['status'], { cwd: '/
30
30
  connection.disconnect();
31
31
  ```
32
32
 
33
- `connect` returns a `MachineConnection`. Connections are shared per target and reference counted, so two callers
34
- asking for the same SSH host drive one tunnel; the last `disconnect()` tears it down. `connect({ type: 'ssh', host,
35
- agent })` installs the carrier agent on the host first when `agent` is given.
33
+ `openMachine` returns a `MachineConnection`; every call opens its own. Sharing one belongs to the caller: a
34
+ connection is reference counted, so callers that hand the same one around keep it alive until the last
35
+ `disconnect()`. `openMachine({ type: 'ssh', host, agent })` installs the carrier agent on the host first when
36
+ `agent` is given.
36
37
 
37
38
  - `connection.pty` - `list`, `cwd`, `create`, `attach`, `close`
38
39
  - `connection.fs` - `stat`, `readDirectory`, `readFile`
@@ -50,4 +51,4 @@ npm run build
50
51
 
51
52
  From the repository root (the TypeScript and esbuild devDependencies live in the workspace root): esbuild bundles
52
53
  `index.ts` into `dist/index.cjs` with `ws` left external, then `tsc` emits the declarations. `npm publish` and
53
- `npm pack` run it for you.
54
+ `npm pack` run it for you.
package/dist/channel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AgentInfo } from './types';
1
+ import type { MachineConnection } from './connection';
2
2
  export type Dispose = () => void | Promise<void>;
3
3
  /** A sidebar tab the window opens for a plugin: what it is called, and what it draws. */
4
4
  export interface TabOptions {
@@ -31,10 +31,11 @@ export interface MainContext {
31
31
  handle<T = unknown>(method: string, handler: (params: T) => unknown): Dispose;
32
32
  publish(topic: string, data: unknown): void;
33
33
  };
34
+ connect(machine: {
35
+ host?: string;
36
+ }, signal?: AbortSignal): Promise<MachineConnection>;
34
37
  host: {
35
38
  dataDirectory: string;
36
- resourcesDirectory: string;
37
- agent: AgentInfo;
38
39
  config: any;
39
40
  };
40
41
  }
package/dist/index.cjs CHANGED
@@ -30,8 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- connect: () => connect,
34
- ensureAgent: () => ensureAgent
33
+ openMachine: () => openMachine
35
34
  });
36
35
  module.exports = __toCommonJS(index_exports);
37
36
 
@@ -489,19 +488,9 @@ var MachineConnection = class {
489
488
  };
490
489
 
491
490
  // index.ts
492
- var connections = /* @__PURE__ */ new Map();
493
- async function connect(options) {
491
+ async function openMachine(options) {
494
492
  options.signal?.throwIfAborted();
495
- const target = options.type === "ssh" ? `ssh:${options.host}` : `local:${options.binary ?? "wangcai"}`;
496
- const shared = connections.get(target);
497
- const machine = shared ?? new MachineConnection(options);
498
- if (shared) machine.retain();
499
- else {
500
- connections.set(target, machine);
501
- machine.onState((state) => {
502
- if (state.status === "disconnected" && connections.get(target) === machine) connections.delete(target);
503
- });
504
- }
493
+ const machine = new MachineConnection(options);
505
494
  const aborted = new Promise((_, reject) => {
506
495
  options.signal?.addEventListener("abort", () => reject(new Error("Connection cancelled")), { once: true });
507
496
  });
@@ -515,6 +504,5 @@ async function connect(options) {
515
504
  }
516
505
  // Annotate the CommonJS export names for ESM import in node:
517
506
  0 && (module.exports = {
518
- connect,
519
- ensureAgent
507
+ openMachine
520
508
  });
package/dist/index.d.ts CHANGED
@@ -3,5 +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
- export declare function connect(options: ConnectionOptions): Promise<MachineConnection>;
6
+ /** Opens one connection to a machine and waits for it to be ready. */
7
+ export declare function openMachine(options: ConnectionOptions): Promise<MachineConnection>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lengmoxxl/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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
+ }