@cplieger/web-terminal-engine 2.5.0 → 2.8.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/jsr.json +1 -1
- package/package.json +2 -2
- package/src/connection.ts +2 -1
- package/src/index.ts +2 -0
- package/src/routes.ts +19 -0
- package/src/status-stream.ts +13 -5
- package/src/wsurl.ts +4 -2
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cplieger/web-terminal-engine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"typecheck": "tsc -p tsconfig.json",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"pngjs": "7.0.0",
|
|
25
25
|
"prettier": "3.9.5",
|
|
26
26
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
27
|
-
"typescript-eslint": "8.
|
|
27
|
+
"typescript-eslint": "8.64.0",
|
|
28
28
|
"vitest": "4.1.10"
|
|
29
29
|
},
|
|
30
30
|
"description": "Browser terminal engine: VT500 screen buffer, DOM renderer, and binary wire protocol",
|
package/src/connection.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// without bound.
|
|
23
23
|
|
|
24
24
|
import { wsURL } from "./wsurl.js";
|
|
25
|
+
import { WS_PATH } from "./routes.js";
|
|
25
26
|
import { controlFrame } from "./wire.js";
|
|
26
27
|
import { decodeWireBinary, WIRE_PROTOCOL_VERSION } from "./wire-binary.js";
|
|
27
28
|
import * as modes from "./modes.js";
|
|
@@ -45,7 +46,7 @@ let connState: ConnState = { status: "disconnected" };
|
|
|
45
46
|
let reconnectDelay = INITIAL_DELAY_MS;
|
|
46
47
|
let lastSentCols = 0;
|
|
47
48
|
let lastSentRows = 0;
|
|
48
|
-
let wsPath =
|
|
49
|
+
let wsPath: string = WS_PATH;
|
|
49
50
|
|
|
50
51
|
// --- Per-session resume state (the switching cache's connection half) ---
|
|
51
52
|
//
|
package/src/index.ts
CHANGED
|
@@ -10,8 +10,10 @@ export * as connection from "./connection.js";
|
|
|
10
10
|
export { decodeWireBinary } from "./wire-binary.js";
|
|
11
11
|
export { controlFrame, CONTROL_FRAME_PREFIX } from "./wire.js";
|
|
12
12
|
export { wsURL } from "./wsurl.js";
|
|
13
|
+
export { WS_PATH, SESSIONS_PATH, SESSION_EVENTS_PATH } from "./routes.js";
|
|
13
14
|
export { connectStatusStream } from "./status-stream.js";
|
|
14
15
|
export type {
|
|
16
|
+
SessionInfo,
|
|
15
17
|
SessionStatus,
|
|
16
18
|
StatusStream,
|
|
17
19
|
StatusStreamCallbacks,
|
package/src/routes.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Session-route path contract, TS half. These mirror the Go terminal
|
|
2
|
+
// package's exported constants (WSPath, SessionsPath, SessionEventsPath),
|
|
3
|
+
// whose MountSessionRoutes wires exactly this topology on the server — one
|
|
4
|
+
// name per path on each side of the wire, so a consumer composing its own
|
|
5
|
+
// URLs (or overriding a default) references the contract instead of
|
|
6
|
+
// restating a literal that could drift. Any addition here is an addition to
|
|
7
|
+
// the server mount contract and is release-noted on both halves.
|
|
8
|
+
|
|
9
|
+
/** WS_PATH is the terminal WebSocket route; the client connects per session
|
|
10
|
+
* with `?session=<id>`. Mirrors Go `terminal.WSPath`. */
|
|
11
|
+
export const WS_PATH = "/ws";
|
|
12
|
+
|
|
13
|
+
/** SESSIONS_PATH is the session REST route (POST create, GET list; DELETE and
|
|
14
|
+
* PUT title live under its subtree). Mirrors Go `terminal.SessionsPath`. */
|
|
15
|
+
export const SESSIONS_PATH = "/api/sessions";
|
|
16
|
+
|
|
17
|
+
/** SESSION_EVENTS_PATH is the session status stream (SSE). Mirrors Go
|
|
18
|
+
* `terminal.SessionEventsPath`. */
|
|
19
|
+
export const SESSION_EVENTS_PATH = "/api/sessions/events";
|
package/src/status-stream.ts
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import { nextBackoffDelay } from "./reconnect.js";
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
10
|
+
/** SessionInfo is one session's wire shape: the JSON object the session REST
|
|
11
|
+
* API (GET/POST /api/sessions) returns per session. Mirrors the Go
|
|
12
|
+
* terminal.SessionInfo — the two are kept in lockstep by hand (single 6-field
|
|
13
|
+
* type; flip to wiregen if this surface grows). */
|
|
14
|
+
export interface SessionInfo {
|
|
13
15
|
readonly id: string;
|
|
14
16
|
readonly status: "working" | "idle" | "input" | "done" | "exited";
|
|
15
17
|
readonly title: string;
|
|
@@ -18,8 +20,6 @@ export interface SessionStatus {
|
|
|
18
20
|
* this instead of `title`. */
|
|
19
21
|
readonly clientTitle?: string;
|
|
20
22
|
readonly createdAt: string;
|
|
21
|
-
/** true when the session is gone (closed or reaped); the consumer drops it. */
|
|
22
|
-
readonly removed?: boolean;
|
|
23
23
|
/** true once the session has emitted a genuine activity signal — OSC 9;4
|
|
24
24
|
* progress (kiro-cli, Claude Code, …) or a classified OSC 9 notification.
|
|
25
25
|
* Sticky for the session's life. Consumers reveal the per-tab activity dot
|
|
@@ -28,6 +28,14 @@ export interface SessionStatus {
|
|
|
28
28
|
readonly reportsActivity?: boolean;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** SessionStatus is one session's current status as carried on the status
|
|
32
|
+
* stream (SSE): the REST wire shape plus the stream-only removal marker. It
|
|
33
|
+
* mirrors the server's status event. */
|
|
34
|
+
export interface SessionStatus extends SessionInfo {
|
|
35
|
+
/** true when the session is gone (closed or reaped); the consumer drops it. */
|
|
36
|
+
readonly removed?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
/** StatusStreamCallbacks are the consumer's hooks. Declared as function-typed
|
|
32
40
|
* properties (not method shorthand) so destructuring them is safe. */
|
|
33
41
|
export interface StatusStreamCallbacks {
|
package/src/wsurl.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WS_PATH } from "./routes.js";
|
|
2
|
+
|
|
1
3
|
// Pure URL helper, no DOM / terminal / WebSocket dependencies.
|
|
2
4
|
// Kept in a dedicated module so it can be property-tested without
|
|
3
5
|
// touching `location`. The caller threads the live `location.*` through.
|
|
@@ -9,10 +11,10 @@
|
|
|
9
11
|
*
|
|
10
12
|
* @param pageProtocol `location.protocol` (e.g. `"https:"`).
|
|
11
13
|
* @param pageHost `location.host` (host[:port]).
|
|
12
|
-
* @param path WebSocket endpoint path; defaults to `"/ws"
|
|
14
|
+
* @param path WebSocket endpoint path; defaults to `WS_PATH` (`"/ws"`).
|
|
13
15
|
* @returns A parseable `ws://`/`wss://` URL.
|
|
14
16
|
*/
|
|
15
|
-
export function wsURL(pageProtocol: string, pageHost: string, path =
|
|
17
|
+
export function wsURL(pageProtocol: string, pageHost: string, path = WS_PATH): string {
|
|
16
18
|
const wsProto = pageProtocol === "https:" ? "wss:" : "ws:";
|
|
17
19
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
18
20
|
return `${wsProto}//${pageHost}${normalizedPath}`;
|