@vibecook/ghosttea 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 James Yong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @vibecook/ghosttea
2
+
3
+ Typed browser client for connecting an Electron renderer to the Ghosttea
4
+ terminal service through a transferred control `MessagePort`.
5
+
6
+ ```ts
7
+ import { ControlClient } from "@vibecook/ghosttea";
8
+
9
+ const client = new ControlClient(controlPort);
10
+ const response = await client.request({ type: "list-sessions" });
11
+ ```
12
+
13
+ Ghosttea is developed at <https://github.com/jamesyong-42/ghosttea>.
@@ -0,0 +1,13 @@
1
+ import type { ClientCommand, ServerEvent } from "@vibecook/ghosttea-protocol";
2
+ type CommandPayload = ClientCommand extends infer Command ? Command extends {
3
+ requestId: number;
4
+ } ? Omit<Command, "requestId"> : never : never;
5
+ export declare class ControlClient extends EventTarget {
6
+ #private;
7
+ constructor(port: MessagePort);
8
+ request(command: CommandPayload, timeoutMs?: number): Promise<ServerEvent>;
9
+ notify(command: CommandPayload): void;
10
+ dispose(): void;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG9E,KAAK,cAAc,GAAG,aAAa,SAAS,MAAM,OAAO,GACrD,OAAO,SAAS;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACnC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAC1B,KAAK,GACP,KAAK,CAAC;AAQV,qBAAa,aAAc,SAAQ,WAAW;;IAK5C,YAAY,IAAI,EAAE,WAAW,EAK5B;IAED,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,SAAS,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAWzE;IAED,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAEpC;IAED,OAAO,IAAI,IAAI,CAQd;CAuBF"}
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { isServerEvent } from "@vibecook/ghosttea-protocol";
2
+ export class ControlClient extends EventTarget {
3
+ #port;
4
+ #pending = new Map();
5
+ #nextRequestId = 1;
6
+ constructor(port) {
7
+ super();
8
+ this.#port = port;
9
+ this.#port.addEventListener("message", this.#onMessage);
10
+ this.#port.start();
11
+ }
12
+ request(command, timeoutMs = 10_000) {
13
+ const requestId = this.#nextRequestId++;
14
+ const envelope = { ...command, requestId };
15
+ return new Promise((resolve, reject) => {
16
+ const timeout = setTimeout(() => {
17
+ this.#pending.delete(requestId);
18
+ reject(new Error(`Terminal request timed out: ${command.type}`));
19
+ }, timeoutMs);
20
+ this.#pending.set(requestId, { resolve, reject, timeout });
21
+ this.#port.postMessage(envelope);
22
+ });
23
+ }
24
+ notify(command) {
25
+ this.#port.postMessage({ ...command, requestId: 0 });
26
+ }
27
+ dispose() {
28
+ this.#port.removeEventListener("message", this.#onMessage);
29
+ this.#port.close();
30
+ for (const pending of this.#pending.values()) {
31
+ clearTimeout(pending.timeout);
32
+ pending.reject(new Error("Terminal control channel closed"));
33
+ }
34
+ this.#pending.clear();
35
+ }
36
+ #onMessage = (message) => {
37
+ if (!isServerEvent(message.data))
38
+ return;
39
+ const event = message.data;
40
+ if (event.requestId === 0) {
41
+ this.dispatchEvent(new CustomEvent(event.type, { detail: event }));
42
+ if (event.type === "bridge-error") {
43
+ for (const pending of this.#pending.values()) {
44
+ clearTimeout(pending.timeout);
45
+ pending.reject(new Error(event.message));
46
+ }
47
+ this.#pending.clear();
48
+ }
49
+ return;
50
+ }
51
+ const pending = this.#pending.get(event.requestId);
52
+ if (!pending)
53
+ return;
54
+ this.#pending.delete(event.requestId);
55
+ clearTimeout(pending.timeout);
56
+ if (event.type === "error")
57
+ pending.reject(new Error(event.message));
58
+ else
59
+ pending.resolve(event);
60
+ };
61
+ }
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAc5D,MAAM,OAAO,aAAc,SAAQ,WAAW;IACnC,KAAK,CAAc;IACnB,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IACtD,cAAc,GAAG,CAAC,CAAC;IAEnB,YAAY,IAAiB;QAC3B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACxD,IAAI,CAAC,KAAK,C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@@
1
+ {
2
+ "name": "@vibecook/ghosttea",
3
+ "version": "0.1.0",
4
+ "description": "Typed browser client for the Ghosttea terminal service.",
5
+ "license": "MIT",
6
+ "author": "James Yong",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/jamesyong-42/ghosttea.git",
25
+ "directory": "packages/terminal-client"
26
+ },
27
+ "homepage": "https://github.com/jamesyong-42/ghosttea#readme",
28
+ "bugs": {
29
+ "url": "https://github.com/jamesyong-42/ghosttea/issues"
30
+ },
31
+ "keywords": [
32
+ "electron",
33
+ "ghostty",
34
+ "terminal"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true
39
+ },
40
+ "dependencies": {
41
+ "@vibecook/ghosttea-protocol": "0.1.0"
42
+ },
43
+ "scripts": {
44
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
45
+ "build": "npm run clean && tsc -p tsconfig.build.json",
46
+ "check": "tsc --noEmit",
47
+ "test": "vitest run",
48
+ "prepublishOnly": "npm run build"
49
+ },
50
+ "devDependencies": {
51
+ "typescript": "7.0.2",
52
+ "vitest": "4.1.10"
53
+ }
54
+ }