@thurstonsand/ghosttykit 0.0.0
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 +174 -0
- package/dist/src/client.d.ts +59 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +271 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/codes.d.ts +14 -0
- package/dist/src/codes.d.ts.map +1 -0
- package/dist/src/codes.js +13 -0
- package/dist/src/codes.js.map +1 -0
- package/dist/src/errors.d.ts +41 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +89 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/paste-internal.d.ts +5 -0
- package/dist/src/paste-internal.d.ts.map +1 -0
- package/dist/src/paste-internal.js +259 -0
- package/dist/src/paste-internal.js.map +1 -0
- package/dist/src/paste.d.ts +42 -0
- package/dist/src/paste.d.ts.map +1 -0
- package/dist/src/paste.js +17 -0
- package/dist/src/paste.js.map +1 -0
- package/dist/src/protocol.d.ts +106 -0
- package/dist/src/protocol.d.ts.map +1 -0
- package/dist/src/protocol.js +132 -0
- package/dist/src/protocol.js.map +1 -0
- package/dist/src/socket.d.ts +7 -0
- package/dist/src/socket.d.ts.map +1 -0
- package/dist/src/socket.js +39 -0
- package/dist/src/socket.js.map +1 -0
- package/dist/test/client.test.d.ts +2 -0
- package/dist/test/client.test.d.ts.map +1 -0
- package/dist/test/client.test.js +174 -0
- package/dist/test/client.test.js.map +1 -0
- package/dist/test/protocol.test.d.ts +2 -0
- package/dist/test/protocol.test.d.ts.map +1 -0
- package/dist/test/protocol.test.js +25 -0
- package/dist/test/protocol.test.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @thurstonsand/ghosttykit
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for GhosttyKit daemon and bridge clients.
|
|
4
|
+
|
|
5
|
+
Use this package from Node.js tools that need to talk to `ghosttykitd` or a GhosttyKit bridge socket.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Install GhosttyKit on your Mac. See the root [GhosttyKit README](../../README.md#install) for the full install flow.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
brew install thurstonsand/ghosttykit/ghosttykit
|
|
13
|
+
open -a Ghostty
|
|
14
|
+
brew services start thurstonsand/ghosttykit/ghosttykit
|
|
15
|
+
gty doctor
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Install the SDK:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install @thurstonsand/ghosttykit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use matching nightlies if you want to track the latest changes:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
brew install thurstonsand/ghosttykit/ghosttykit-nightly
|
|
28
|
+
brew services start thurstonsand/ghosttykit/ghosttykit-nightly
|
|
29
|
+
npm install @thurstonsand/ghosttykit@nightly
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
Create a client and call GhosttyKit commands:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { client } from "@thurstonsand/ghosttykit";
|
|
38
|
+
|
|
39
|
+
const gty = client();
|
|
40
|
+
const status = await gty.doctor();
|
|
41
|
+
|
|
42
|
+
console.log(status.healthy);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
By default, the client connects to `GTY_SOCK` when set, otherwise the standard local daemon socket. Pass `socketPath` to target another daemon or bridge socket:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const gty = client({ socketPath: "/path/to/ghosttykit.sock" });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
await gty.doctor(); // DoctorStatus
|
|
55
|
+
await gty.terminalId({ focused: true }); // string
|
|
56
|
+
await gty.tabTerminalCount({ focused: true }); // number
|
|
57
|
+
const tty = process.env.GTY_TTY ?? "/dev/ttys001";
|
|
58
|
+
|
|
59
|
+
await gty.keyTableActivate("nvim", { tty, focused: true, ack: true });
|
|
60
|
+
await gty.keyTableDeactivate({ tty, focused: true, ack: true });
|
|
61
|
+
await gty.focus("left", { tty, focused: true, ack: true });
|
|
62
|
+
await gty.split("right", {
|
|
63
|
+
tty,
|
|
64
|
+
cwd: process.cwd(),
|
|
65
|
+
focus: "new",
|
|
66
|
+
ack: true,
|
|
67
|
+
});
|
|
68
|
+
await gty.resize("right", { pixels: 40 }, { tty, ack: true });
|
|
69
|
+
await gty.zoom({ tty, ack: true });
|
|
70
|
+
await gty.clearCache({ ack: true });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Create a bridge lease:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const bridge = await gty.bridge({ tty, focused: true });
|
|
77
|
+
try {
|
|
78
|
+
console.log(bridge.socketPath);
|
|
79
|
+
} finally {
|
|
80
|
+
bridge.close();
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Paste
|
|
85
|
+
|
|
86
|
+
`paste()` returns a consumable discriminated union. Use `Paste.match` for exhaustive handling, or switch on `paste.kind` directly.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { Paste, client } from "@thurstonsand/ghosttykit";
|
|
90
|
+
|
|
91
|
+
const paste = await client().paste();
|
|
92
|
+
|
|
93
|
+
const editorText = await Paste.match(paste, {
|
|
94
|
+
text: (paste) => paste.text(),
|
|
95
|
+
files: async (paste) => {
|
|
96
|
+
const files = await paste.save("/tmp/pi-paste-file");
|
|
97
|
+
return files.map((file) => `@${file.path}`).join(" ");
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Paste payloads are streams. Calling `text()`, `raw()`, `contents()`, or `save()` consumes the paste. `paste.state` reports `"pending"`, `"consuming"`, or `"consumed"`; a second consume attempt throws `PasteConsumedError`.
|
|
103
|
+
|
|
104
|
+
Text paste methods:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
if (paste.kind === "text") {
|
|
108
|
+
await paste.text(); // string
|
|
109
|
+
await paste.raw(); // Uint8Array
|
|
110
|
+
await paste.save("/tmp/paste-output"); // pasted-text-<uuid>.txt
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
File paste methods:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
if (paste.kind === "files") {
|
|
118
|
+
paste.files; // metadata
|
|
119
|
+
await paste.contents(); // metadata plus actual files as Uint8Array
|
|
120
|
+
await paste.save("/tmp/paste-output"); // metadata plus saved path
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Protocol escape hatch
|
|
125
|
+
|
|
126
|
+
Low-level protocol requests are available through the `protocol` namespace when you need direct control:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { client, protocol } from "@thurstonsand/ghosttykit";
|
|
130
|
+
|
|
131
|
+
const gty = client();
|
|
132
|
+
const stream = await gty.stream<protocol.PasteStreamFrameHeader>(
|
|
133
|
+
protocol.pasteRequest(),
|
|
134
|
+
);
|
|
135
|
+
try {
|
|
136
|
+
if (stream.header.kind === "files") {
|
|
137
|
+
for (const file of stream.header.files ?? []) {
|
|
138
|
+
// Read exactly file.bytes from stream.body.
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} finally {
|
|
142
|
+
stream.close();
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Raw methods are `call`, `notify`, `stream`, and `hold`. They work with request builders from `protocol` and return protocol frames.
|
|
147
|
+
|
|
148
|
+
## Errors
|
|
149
|
+
|
|
150
|
+
Failed daemon replies throw typed errors based on the protocol code:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { PasteEmptyError, client } from "@thurstonsand/ghosttykit";
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await client().paste();
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error instanceof PasteEmptyError) {
|
|
159
|
+
// Clipboard has no supported content.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Transport and client-shape failures throw non-protocol errors such as `TransportError`, `InvalidReplyModeError`, `InvalidReplyError`, and `PasteConsumedError`.
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
From this repository:
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
cd sdk/ts
|
|
172
|
+
npm install
|
|
173
|
+
npm run check
|
|
174
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Readable } from "node:stream";
|
|
2
|
+
import type { Paste } from "./paste.js";
|
|
3
|
+
import { type AckOptions, type Direction, type DoctorCheck, type FocusTarget, type FrameReply, type PasteOptions, type Request, type ResizeAmount, type TerminalIdOptions, type TerminalTargetOptions } from "./protocol.js";
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
socketPath?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DoctorStatus {
|
|
8
|
+
healthy: boolean;
|
|
9
|
+
checks: readonly DoctorCheck[];
|
|
10
|
+
}
|
|
11
|
+
export interface RawStream<T extends FrameReply = FrameReply> {
|
|
12
|
+
header: T;
|
|
13
|
+
body: Readable;
|
|
14
|
+
close(): void;
|
|
15
|
+
}
|
|
16
|
+
export interface HoldResult<T extends FrameReply = FrameReply> {
|
|
17
|
+
reply: T;
|
|
18
|
+
close(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface Bridge {
|
|
21
|
+
readonly socketPath: string;
|
|
22
|
+
close(): void;
|
|
23
|
+
}
|
|
24
|
+
export interface CommandOptions extends AckOptions {
|
|
25
|
+
}
|
|
26
|
+
export interface TerminalOptions extends TerminalTargetOptions {
|
|
27
|
+
tty: string;
|
|
28
|
+
}
|
|
29
|
+
export interface TerminalCommandOptions extends TerminalOptions {
|
|
30
|
+
ack?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface SplitCommandOptions extends TerminalCommandOptions {
|
|
33
|
+
cwd?: string;
|
|
34
|
+
commandText?: string;
|
|
35
|
+
focus?: FocusTarget;
|
|
36
|
+
}
|
|
37
|
+
export declare class GhosttyKitClient {
|
|
38
|
+
readonly socketPath: string;
|
|
39
|
+
constructor(options?: ClientOptions);
|
|
40
|
+
call<T extends FrameReply = FrameReply>(request: Request): Promise<T>;
|
|
41
|
+
notify(request: Request): Promise<void>;
|
|
42
|
+
stream<T extends FrameReply = FrameReply>(request: Request): Promise<RawStream<T>>;
|
|
43
|
+
hold<T extends FrameReply = FrameReply>(request: Request): Promise<HoldResult<T>>;
|
|
44
|
+
doctor(): Promise<DoctorStatus>;
|
|
45
|
+
terminalId(options?: TerminalIdOptions): Promise<string>;
|
|
46
|
+
tabTerminalCount(options?: TerminalTargetOptions): Promise<number>;
|
|
47
|
+
clearCache(options?: CommandOptions): Promise<void>;
|
|
48
|
+
keyTableActivate(table: string, options: TerminalCommandOptions): Promise<void>;
|
|
49
|
+
keyTableDeactivate(options: TerminalCommandOptions): Promise<void>;
|
|
50
|
+
focus(direction: Direction, options: TerminalCommandOptions): Promise<void>;
|
|
51
|
+
split(direction: Direction, options: SplitCommandOptions): Promise<void>;
|
|
52
|
+
resize(direction: Direction, amount: ResizeAmount, options: TerminalCommandOptions): Promise<void>;
|
|
53
|
+
zoom(options?: CommandOptions): Promise<void>;
|
|
54
|
+
paste(options?: PasteOptions): Promise<Paste>;
|
|
55
|
+
bridge(options: TerminalOptions): Promise<Bridge>;
|
|
56
|
+
private send;
|
|
57
|
+
}
|
|
58
|
+
export declare function client(options?: ClientOptions): GhosttyKitClient;
|
|
59
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@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AS,EACpB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC;IAIV,IAAI,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,KAAK,CAAC;IAKjD,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;YAWzC,IAAI;CAOnB;AAED,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,gBAAgB,CAEpE"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
import { InvalidReplyError, InvalidReplyModeError, TransportError, throwIfReplyError, } from "./errors.js";
|
|
3
|
+
import { pasteFromStream } from "./paste-internal.js";
|
|
4
|
+
import { bridgeCreateRequest, bridgeLeaseRequest, clearCacheRequest, doctorRequest, encodeRequest, focusRequest, keyTableActivateRequest, keyTableDeactivateRequest, pasteRequest, replyModeOf, resizeRequest, splitRequest, tabTerminalCountRequest, terminalIdRequest, zoomRequest, } from "./protocol.js";
|
|
5
|
+
import { dial, socketPath as resolveSocketPath } from "./socket.js";
|
|
6
|
+
export class GhosttyKitClient {
|
|
7
|
+
socketPath;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.socketPath = resolveSocketPath(options);
|
|
10
|
+
}
|
|
11
|
+
async call(request) {
|
|
12
|
+
requireReplyMode(request, "frame");
|
|
13
|
+
validateRequest(request);
|
|
14
|
+
const socket = await dial(this.socketPath);
|
|
15
|
+
try {
|
|
16
|
+
await writeRequest(socket, request);
|
|
17
|
+
const reply = await readJsonLine(socket);
|
|
18
|
+
throwIfReplyError(reply);
|
|
19
|
+
return reply;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
socket.destroy();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async notify(request) {
|
|
26
|
+
requireReplyMode(request, "none");
|
|
27
|
+
validateRequest(request);
|
|
28
|
+
const socket = await dial(this.socketPath);
|
|
29
|
+
try {
|
|
30
|
+
await writeRequest(socket, request);
|
|
31
|
+
await waitForEOF(socket);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
socket.destroy();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async stream(request) {
|
|
38
|
+
requireReplyMode(request, "stream");
|
|
39
|
+
validateRequest(request);
|
|
40
|
+
const socket = await dial(this.socketPath);
|
|
41
|
+
try {
|
|
42
|
+
await writeRequest(socket, request);
|
|
43
|
+
const { value: header, rest } = await readJsonLineWithRest(socket);
|
|
44
|
+
throwIfReplyError(header);
|
|
45
|
+
const body = new PassThrough();
|
|
46
|
+
if (rest.length > 0) {
|
|
47
|
+
body.write(rest);
|
|
48
|
+
}
|
|
49
|
+
socket.pipe(body);
|
|
50
|
+
return { header, body, close: () => socket.destroy() };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
socket.destroy();
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async hold(request) {
|
|
58
|
+
requireReplyMode(request, "hold");
|
|
59
|
+
validateRequest(request);
|
|
60
|
+
const socket = await dial(this.socketPath);
|
|
61
|
+
try {
|
|
62
|
+
await writeRequest(socket, request);
|
|
63
|
+
const reply = await readJsonLine(socket);
|
|
64
|
+
throwIfReplyError(reply);
|
|
65
|
+
return { reply, close: () => socket.destroy() };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
socket.destroy();
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async doctor() {
|
|
73
|
+
const reply = await this.call(doctorRequest());
|
|
74
|
+
return { healthy: reply.healthy, checks: reply.checks ?? [] };
|
|
75
|
+
}
|
|
76
|
+
async terminalId(options = {}) {
|
|
77
|
+
const reply = await this.call(terminalIdRequest(options));
|
|
78
|
+
return requiredReplyValue(reply, "terminal-id reply missing terminal ID");
|
|
79
|
+
}
|
|
80
|
+
async tabTerminalCount(options = {}) {
|
|
81
|
+
const reply = await this.call(tabTerminalCountRequest(options));
|
|
82
|
+
const value = Number.parseInt(requiredReplyValue(reply, "tab-terminal-count reply missing count"), 10);
|
|
83
|
+
if (!Number.isSafeInteger(value)) {
|
|
84
|
+
throw new InvalidReplyError("tab-terminal-count reply has invalid count");
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
async clearCache(options = {}) {
|
|
89
|
+
await this.send(clearCacheRequest(options), options.ack);
|
|
90
|
+
}
|
|
91
|
+
async keyTableActivate(table, options) {
|
|
92
|
+
const requestOptions = { ...options, table };
|
|
93
|
+
await this.send(keyTableActivateRequest(requestOptions), options.ack);
|
|
94
|
+
}
|
|
95
|
+
async keyTableDeactivate(options) {
|
|
96
|
+
await this.send(keyTableDeactivateRequest(options), options.ack);
|
|
97
|
+
}
|
|
98
|
+
async focus(direction, options) {
|
|
99
|
+
await this.send(focusRequest({ ...options, direction }), options.ack);
|
|
100
|
+
}
|
|
101
|
+
async split(direction, options) {
|
|
102
|
+
const requestOptions = { ...options, direction };
|
|
103
|
+
await this.send(splitRequest(requestOptions), options.ack);
|
|
104
|
+
}
|
|
105
|
+
async resize(direction, amount, options) {
|
|
106
|
+
await this.send(resizeRequest({ ...options, direction, amount }), options.ack);
|
|
107
|
+
}
|
|
108
|
+
async zoom(options = {}) {
|
|
109
|
+
await this.send(zoomRequest(options), options.ack);
|
|
110
|
+
}
|
|
111
|
+
async paste(options = {}) {
|
|
112
|
+
const result = await this.stream(pasteRequest(options));
|
|
113
|
+
return pasteFromStream(normalizePasteHeader(result.header), result.body, result.close);
|
|
114
|
+
}
|
|
115
|
+
async bridge(options) {
|
|
116
|
+
const reply = await this.call(bridgeCreateRequest(options));
|
|
117
|
+
if (!reply.socketPath || !reply.leaseToken) {
|
|
118
|
+
throw new InvalidReplyError("bridge-create reply missing socket path or lease token");
|
|
119
|
+
}
|
|
120
|
+
const lease = await new GhosttyKitClient({ socketPath: reply.socketPath }).hold(bridgeLeaseRequest(reply.leaseToken));
|
|
121
|
+
return { socketPath: reply.socketPath, close: lease.close };
|
|
122
|
+
}
|
|
123
|
+
async send(request, ack) {
|
|
124
|
+
if (ack) {
|
|
125
|
+
await this.call(request);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
await this.notify(request);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function client(options = {}) {
|
|
132
|
+
return new GhosttyKitClient(options);
|
|
133
|
+
}
|
|
134
|
+
function requireReplyMode(request, want) {
|
|
135
|
+
const got = replyModeOf(request);
|
|
136
|
+
if (got !== want) {
|
|
137
|
+
throw new InvalidReplyModeError(`request reply mode is ${got}, not ${want}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function validateRequest(request) {
|
|
141
|
+
if (request.command === "terminal-id" &&
|
|
142
|
+
request.refresh === true &&
|
|
143
|
+
request.tty &&
|
|
144
|
+
request.focused !== true) {
|
|
145
|
+
throw new InvalidReplyError("cannot refresh terminal-id if it is not the focused window");
|
|
146
|
+
}
|
|
147
|
+
if (request.command === "resize") {
|
|
148
|
+
validateResizeAmount(request.amount);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function validateResizeAmount(amount) {
|
|
152
|
+
if (!amount || typeof amount !== "object") {
|
|
153
|
+
throw new InvalidReplyError("resize amount is required");
|
|
154
|
+
}
|
|
155
|
+
const value = amount;
|
|
156
|
+
const hasPixels = value.pixels !== undefined;
|
|
157
|
+
const hasPercent = value.percent !== undefined;
|
|
158
|
+
if (hasPixels === hasPercent) {
|
|
159
|
+
throw new InvalidReplyError("resize amount must specify exactly one of pixels or percent");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function normalizePasteHeader(header) {
|
|
163
|
+
if (header.kind === "text" && typeof header.bytes === "number") {
|
|
164
|
+
return header;
|
|
165
|
+
}
|
|
166
|
+
if (header.kind === "files" && Array.isArray(header.files) && typeof header.bytes === "number") {
|
|
167
|
+
return header;
|
|
168
|
+
}
|
|
169
|
+
throw new InvalidReplyError("invalid paste stream header");
|
|
170
|
+
}
|
|
171
|
+
function requiredReplyValue(reply, message) {
|
|
172
|
+
if (typeof reply.value !== "string" || reply.value === "") {
|
|
173
|
+
throw new InvalidReplyError(message);
|
|
174
|
+
}
|
|
175
|
+
return reply.value;
|
|
176
|
+
}
|
|
177
|
+
function writeRequest(socket, request) {
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
socket.write(encodeRequest(request), (error) => {
|
|
180
|
+
if (error) {
|
|
181
|
+
reject(new TransportError(`send request: ${error.message}`, {
|
|
182
|
+
cause: error,
|
|
183
|
+
}));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
resolve();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async function readJsonLine(socket) {
|
|
191
|
+
const { value, rest } = await readJsonLineWithRest(socket);
|
|
192
|
+
if (rest.length > 0) {
|
|
193
|
+
socket.unshift(rest);
|
|
194
|
+
}
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
async function readJsonLineWithRest(socket) {
|
|
198
|
+
const { line, rest } = await readLine(socket);
|
|
199
|
+
try {
|
|
200
|
+
return { value: JSON.parse(line), rest };
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
throw new InvalidReplyError("decode reply", { cause: error });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function readLine(socket) {
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
const chunks = [];
|
|
209
|
+
let totalBytes = 0;
|
|
210
|
+
function cleanup() {
|
|
211
|
+
socket.off("data", onData);
|
|
212
|
+
socket.off("error", onError);
|
|
213
|
+
socket.off("end", onEnd);
|
|
214
|
+
}
|
|
215
|
+
function onData(chunk) {
|
|
216
|
+
const newlineIndex = chunk.indexOf(0x0a);
|
|
217
|
+
if (newlineIndex === -1) {
|
|
218
|
+
chunks.push(chunk);
|
|
219
|
+
totalBytes += chunk.length;
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const lineChunk = chunk.subarray(0, newlineIndex);
|
|
223
|
+
const rest = chunk.subarray(newlineIndex + 1);
|
|
224
|
+
chunks.push(lineChunk);
|
|
225
|
+
totalBytes += lineChunk.length;
|
|
226
|
+
cleanup();
|
|
227
|
+
resolve({
|
|
228
|
+
line: Buffer.concat(chunks, totalBytes).toString("utf8"),
|
|
229
|
+
rest,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function onError(error) {
|
|
233
|
+
cleanup();
|
|
234
|
+
reject(new TransportError(`read reply: ${error.message}`, { cause: error }));
|
|
235
|
+
}
|
|
236
|
+
function onEnd() {
|
|
237
|
+
cleanup();
|
|
238
|
+
reject(new TransportError("read reply: unexpected EOF"));
|
|
239
|
+
}
|
|
240
|
+
socket.on("data", onData);
|
|
241
|
+
socket.once("error", onError);
|
|
242
|
+
socket.once("end", onEnd);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function waitForEOF(socket) {
|
|
246
|
+
return new Promise((resolve, reject) => {
|
|
247
|
+
function cleanup() {
|
|
248
|
+
socket.off("data", onData);
|
|
249
|
+
socket.off("error", onError);
|
|
250
|
+
socket.off("end", onEnd);
|
|
251
|
+
}
|
|
252
|
+
function onData() {
|
|
253
|
+
cleanup();
|
|
254
|
+
reject(new InvalidReplyError("daemon sent unexpected data for no-reply request"));
|
|
255
|
+
}
|
|
256
|
+
function onError(error) {
|
|
257
|
+
cleanup();
|
|
258
|
+
reject(new TransportError(`wait for daemon completion: ${error.message}`, {
|
|
259
|
+
cause: error,
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
function onEnd() {
|
|
263
|
+
cleanup();
|
|
264
|
+
resolve();
|
|
265
|
+
}
|
|
266
|
+
socket.once("data", onData);
|
|
267
|
+
socket.once("error", onError);
|
|
268
|
+
socket.once("end", onEnd);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAGL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EAIjB,aAAa,EACb,aAAa,EAGb,YAAY,EAEZ,uBAAuB,EACvB,yBAAyB,EAIzB,YAAY,EAGZ,WAAW,EACX,aAAa,EAEb,YAAY,EAGZ,uBAAuB,EACvB,iBAAiB,EACjB,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA2CpE,MAAM,OAAO,gBAAgB;IAClB,UAAU,CAAS;IAE5B,YAAY,UAAyB,EAAE;QACrC,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,IAAI,CAAoC,OAAgB;QAC5D,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnC,eAAe,CAAC,OAAO,CAAC,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC;YACH,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAI,MAAM,CAAC,CAAC;YAC5C,iBAAiB,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAA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,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC;QAED,SAAS,MAAM;YACb,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,iBAAiB,CAAC,kDAAkD,CAAC,CAAC,CAAC;QACpF,CAAC;QAED,SAAS,OAAO,CAAC,KAAY;YAC3B,OAAO,EAAE,CAAC;YACV,MAAM,CACJ,IAAI,cAAc,CAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,EAAE;gBACjE,KAAK,EAAE,KAAK;aACb,CAAC,CACH,CAAC;QACJ,CAAC;QAED,SAAS,KAAK;YACZ,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const protocolCodes: {
|
|
2
|
+
readonly ok: "ok";
|
|
3
|
+
readonly protocolVersionMismatch: "protocol_version_mismatch";
|
|
4
|
+
readonly unknownCommand: "unknown_command";
|
|
5
|
+
readonly invalidRequest: "invalid_request";
|
|
6
|
+
readonly terminalNotFound: "terminal_not_found";
|
|
7
|
+
readonly ghosttyUnavailable: "ghostty_unavailable";
|
|
8
|
+
readonly pasteEmpty: "paste_empty";
|
|
9
|
+
readonly pasteUnsupported: "paste_unsupported";
|
|
10
|
+
readonly streamFailed: "stream_failed";
|
|
11
|
+
readonly internalError: "internal_error";
|
|
12
|
+
};
|
|
13
|
+
export type ProtocolCode = (typeof protocolCodes)[keyof typeof protocolCodes];
|
|
14
|
+
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/codes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;;;;;;;CAWhB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const protocolCodes = {
|
|
2
|
+
ok: "ok",
|
|
3
|
+
protocolVersionMismatch: "protocol_version_mismatch",
|
|
4
|
+
unknownCommand: "unknown_command",
|
|
5
|
+
invalidRequest: "invalid_request",
|
|
6
|
+
terminalNotFound: "terminal_not_found",
|
|
7
|
+
ghosttyUnavailable: "ghostty_unavailable",
|
|
8
|
+
pasteEmpty: "paste_empty",
|
|
9
|
+
pasteUnsupported: "paste_unsupported",
|
|
10
|
+
streamFailed: "stream_failed",
|
|
11
|
+
internalError: "internal_error",
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/codes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,EAAE,EAAE,IAAI;IACR,uBAAuB,EAAE,2BAA2B;IACpD,cAAc,EAAE,iBAAiB;IACjC,cAAc,EAAE,iBAAiB;IACjC,gBAAgB,EAAE,oBAAoB;IACtC,kBAAkB,EAAE,qBAAqB;IACzC,UAAU,EAAE,aAAa;IACzB,gBAAgB,EAAE,mBAAmB;IACrC,YAAY,EAAE,eAAe;IAC7B,aAAa,EAAE,gBAAgB;CACvB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ProtocolCode } from "./codes.js";
|
|
2
|
+
import type { FrameReply } from "./protocol.js";
|
|
3
|
+
export declare class GhosttyKitError extends Error {
|
|
4
|
+
readonly code: ProtocolCode | string;
|
|
5
|
+
constructor(code: ProtocolCode | string, message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class ReplyError extends GhosttyKitError {
|
|
8
|
+
}
|
|
9
|
+
export declare class ProtocolVersionMismatchError extends GhosttyKitError {
|
|
10
|
+
}
|
|
11
|
+
export declare class UnknownCommandError extends GhosttyKitError {
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidRequestError extends GhosttyKitError {
|
|
14
|
+
}
|
|
15
|
+
export declare class TerminalNotFoundError extends GhosttyKitError {
|
|
16
|
+
}
|
|
17
|
+
export declare class GhosttyUnavailableError extends GhosttyKitError {
|
|
18
|
+
}
|
|
19
|
+
export declare class PasteEmptyError extends GhosttyKitError {
|
|
20
|
+
}
|
|
21
|
+
export declare class PasteUnsupportedError extends GhosttyKitError {
|
|
22
|
+
}
|
|
23
|
+
export declare class StreamFailedError extends GhosttyKitError {
|
|
24
|
+
}
|
|
25
|
+
export declare class InternalError extends GhosttyKitError {
|
|
26
|
+
}
|
|
27
|
+
export declare class TransportError extends Error {
|
|
28
|
+
constructor(message: string, options?: ErrorOptions);
|
|
29
|
+
}
|
|
30
|
+
export declare class InvalidReplyModeError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
export declare class InvalidReplyError extends Error {
|
|
34
|
+
constructor(message: string, options?: ErrorOptions);
|
|
35
|
+
}
|
|
36
|
+
export declare class PasteConsumedError extends Error {
|
|
37
|
+
constructor(message: string);
|
|
38
|
+
}
|
|
39
|
+
export declare function errorFromReply(reply: FrameReply): GhosttyKitError | undefined;
|
|
40
|
+
export declare function throwIfReplyError(reply: FrameReply): void;
|
|
41
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU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