@lengmoxxl/sdk 0.1.0 → 0.1.1
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 +9 -8
- package/dist/channel.d.ts +4 -3
- package/dist/index.cjs +6 -16
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
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
|
|
6
|
-
|
|
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 {
|
|
19
|
+
import { openMachine } from '@lengmoxxl/sdk';
|
|
20
20
|
|
|
21
|
-
const connection = await
|
|
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
|
-
`
|
|
34
|
-
|
|
35
|
-
agent })` installs the carrier agent on the host first when
|
|
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 {
|
|
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,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
ensureAgent: () => ensureAgent,
|
|
34
|
+
openMachine: () => openMachine
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
@@ -489,19 +489,9 @@ var MachineConnection = class {
|
|
|
489
489
|
};
|
|
490
490
|
|
|
491
491
|
// index.ts
|
|
492
|
-
|
|
493
|
-
async function connect(options) {
|
|
492
|
+
async function openMachine(options) {
|
|
494
493
|
options.signal?.throwIfAborted();
|
|
495
|
-
const
|
|
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
|
-
}
|
|
494
|
+
const machine = new MachineConnection(options);
|
|
505
495
|
const aborted = new Promise((_, reject) => {
|
|
506
496
|
options.signal?.addEventListener("abort", () => reject(new Error("Connection cancelled")), { once: true });
|
|
507
497
|
});
|
|
@@ -515,6 +505,6 @@ async function connect(options) {
|
|
|
515
505
|
}
|
|
516
506
|
// Annotate the CommonJS export names for ESM import in node:
|
|
517
507
|
0 && (module.exports = {
|
|
518
|
-
|
|
519
|
-
|
|
508
|
+
ensureAgent,
|
|
509
|
+
openMachine
|
|
520
510
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export type { AgentInfo, ConnectionOptions, FileClick, Machine, MachineState, Se
|
|
|
4
4
|
export type { MachineConnection } from './connection';
|
|
5
5
|
export type { Pty } from './pty';
|
|
6
6
|
export { ensureAgent } from './agent';
|
|
7
|
-
|
|
7
|
+
/** Opens one connection to a machine and waits for it to be ready. */
|
|
8
|
+
export declare function openMachine(options: ConnectionOptions): Promise<MachineConnection>;
|