@datnguyennnx/localterm-server 0.0.15
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 +21 -0
- package/dist/agent-rpc.d.ts +27 -0
- package/dist/agent-rpc.d.ts.map +1 -0
- package/dist/agent-rpc.js +213 -0
- package/dist/agent-rpc.js.map +1 -0
- package/dist/agent-token.d.ts +21 -0
- package/dist/agent-token.d.ts.map +1 -0
- package/dist/agent-token.js +53 -0
- package/dist/agent-token.js.map +1 -0
- package/dist/constants.d.ts +54 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +106 -0
- package/dist/constants.js.map +1 -0
- package/dist/default-shell.d.ts +2 -0
- package/dist/default-shell.d.ts.map +1 -0
- package/dist/default-shell.js +44 -0
- package/dist/default-shell.js.map +1 -0
- package/dist/ensure-spawn-helper-executable.d.ts +2 -0
- package/dist/ensure-spawn-helper-executable.d.ts.map +1 -0
- package/dist/ensure-spawn-helper-executable.js +34 -0
- package/dist/ensure-spawn-helper-executable.js.map +1 -0
- package/dist/errors.d.ts +64 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +84 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +424 -0
- package/dist/index.js.map +1 -0
- package/dist/osc133-chunk-parser.d.ts +8 -0
- package/dist/osc133-chunk-parser.d.ts.map +1 -0
- package/dist/osc133-chunk-parser.js +29 -0
- package/dist/osc133-chunk-parser.js.map +1 -0
- package/dist/osc7-chunk-parser.d.ts +7 -0
- package/dist/osc7-chunk-parser.d.ts.map +1 -0
- package/dist/osc7-chunk-parser.js +29 -0
- package/dist/osc7-chunk-parser.js.map +1 -0
- package/dist/output-batcher.d.ts +11 -0
- package/dist/output-batcher.d.ts.map +1 -0
- package/dist/output-batcher.js +47 -0
- package/dist/output-batcher.js.map +1 -0
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +1 -0
- package/dist/schemas.d.ts +66 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +118 -0
- package/dist/schemas.js.map +1 -0
- package/dist/security.d.ts +5 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +63 -0
- package/dist/security.js.map +1 -0
- package/dist/session-registry.d.ts +9 -0
- package/dist/session-registry.d.ts.map +1 -0
- package/dist/session-registry.js +19 -0
- package/dist/session-registry.js.map +1 -0
- package/dist/session.d.ts +62 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +238 -0
- package/dist/session.js.map +1 -0
- package/dist/shell-integration/index.d.ts +7 -0
- package/dist/shell-integration/index.d.ts.map +1 -0
- package/dist/shell-integration/index.js +29 -0
- package/dist/shell-integration/index.js.map +1 -0
- package/dist/static-resolver.d.ts +7 -0
- package/dist/static-resolver.d.ts.map +1 -0
- package/dist/static-resolver.js +65 -0
- package/dist/static-resolver.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/format-working-directory-title.d.ts +2 -0
- package/dist/utils/format-working-directory-title.d.ts.map +1 -0
- package/dist/utils/format-working-directory-title.js +28 -0
- package/dist/utils/format-working-directory-title.js.map +1 -0
- package/dist/utils/get-heartbeat-action.d.ts +4 -0
- package/dist/utils/get-heartbeat-action.d.ts.map +1 -0
- package/dist/utils/get-heartbeat-action.js +11 -0
- package/dist/utils/get-heartbeat-action.js.map +1 -0
- package/dist/utils/parse-osc133-from-chunk.d.ts +10 -0
- package/dist/utils/parse-osc133-from-chunk.d.ts.map +1 -0
- package/dist/utils/parse-osc133-from-chunk.js +44 -0
- package/dist/utils/parse-osc133-from-chunk.js.map +1 -0
- package/dist/utils/parse-osc7-from-chunk.d.ts +2 -0
- package/dist/utils/parse-osc7-from-chunk.d.ts.map +1 -0
- package/dist/utils/parse-osc7-from-chunk.js +32 -0
- package/dist/utils/parse-osc7-from-chunk.js.map +1 -0
- package/dist/utils/resolve-cwd-for-pid.d.ts +2 -0
- package/dist/utils/resolve-cwd-for-pid.d.ts.map +1 -0
- package/dist/utils/resolve-cwd-for-pid.js +29 -0
- package/dist/utils/resolve-cwd-for-pid.js.map +1 -0
- package/dist/utils/strip-ansi.d.ts +13 -0
- package/dist/utils/strip-ansi.d.ts.map +1 -0
- package/dist/utils/strip-ansi.js +28 -0
- package/dist/utils/strip-ansi.js.map +1 -0
- package/package.json +69 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { WS_BACKPRESSURE_THRESHOLD_BYTES, WS_CLOSE_BACKPRESSURE, WS_CLOSE_CAPACITY_REACHED, WS_CLOSE_POLICY_VIOLATION } from "./constants.js";
|
|
2
|
+
interface NonLoopbackHostError {
|
|
3
|
+
kind: "non-loopback-host";
|
|
4
|
+
code: "E_LT_SERVER_NON_LOOPBACK_HOST";
|
|
5
|
+
host: string;
|
|
6
|
+
}
|
|
7
|
+
interface ListenFailedError {
|
|
8
|
+
kind: "listen-failed";
|
|
9
|
+
code: "E_LT_SERVER_LISTEN_FAILED";
|
|
10
|
+
host: string;
|
|
11
|
+
port: number;
|
|
12
|
+
cause: Error;
|
|
13
|
+
}
|
|
14
|
+
interface LoopbackDeniedError {
|
|
15
|
+
kind: "loopback-denied";
|
|
16
|
+
code: "E_LT_SERVER_LOOPBACK_DENIED";
|
|
17
|
+
reason: "host" | "origin";
|
|
18
|
+
observed: string | null;
|
|
19
|
+
wsCloseCode: typeof WS_CLOSE_POLICY_VIOLATION;
|
|
20
|
+
}
|
|
21
|
+
interface BackpressureError {
|
|
22
|
+
kind: "backpressure";
|
|
23
|
+
code: "E_LT_SERVER_BACKPRESSURE";
|
|
24
|
+
bufferedBytes: number;
|
|
25
|
+
thresholdBytes: typeof WS_BACKPRESSURE_THRESHOLD_BYTES;
|
|
26
|
+
wsCloseCode: typeof WS_CLOSE_BACKPRESSURE;
|
|
27
|
+
}
|
|
28
|
+
interface SessionCapacityError {
|
|
29
|
+
kind: "session-capacity";
|
|
30
|
+
code: "E_LT_SERVER_SESSION_CAPACITY";
|
|
31
|
+
limit: number;
|
|
32
|
+
wsCloseCode: typeof WS_CLOSE_CAPACITY_REACHED;
|
|
33
|
+
}
|
|
34
|
+
interface FrameRejectedError {
|
|
35
|
+
kind: "frame-rejected";
|
|
36
|
+
code: "E_LT_SERVER_FRAME_REJECTED";
|
|
37
|
+
direction: "inbound" | "outbound";
|
|
38
|
+
reason: string;
|
|
39
|
+
}
|
|
40
|
+
interface PathTraversalError {
|
|
41
|
+
kind: "path-traversal";
|
|
42
|
+
code: "E_LT_SERVER_PATH_TRAVERSAL";
|
|
43
|
+
requested: string;
|
|
44
|
+
}
|
|
45
|
+
export type ServerError = NonLoopbackHostError | ListenFailedError | LoopbackDeniedError | BackpressureError | SessionCapacityError | FrameRejectedError | PathTraversalError;
|
|
46
|
+
export type ServerErrorCode = ServerError["code"];
|
|
47
|
+
export type ServerErrorKind = ServerError["kind"];
|
|
48
|
+
export declare const serverError: {
|
|
49
|
+
nonLoopbackHost: (host: string) => NonLoopbackHostError;
|
|
50
|
+
listenFailed: (host: string, port: number, cause: Error) => ListenFailedError;
|
|
51
|
+
loopbackDenied: (reason: "host" | "origin", observed: string | null) => LoopbackDeniedError;
|
|
52
|
+
backpressure: (bufferedBytes: number) => BackpressureError;
|
|
53
|
+
sessionCapacity: (limit: number) => SessionCapacityError;
|
|
54
|
+
frameRejected: (direction: "inbound" | "outbound", reason: string) => FrameRejectedError;
|
|
55
|
+
pathTraversal: (requested: string) => PathTraversalError;
|
|
56
|
+
};
|
|
57
|
+
export declare const formatServerError: (error: ServerError) => string;
|
|
58
|
+
export declare class ServerErrorException extends Error {
|
|
59
|
+
readonly error: ServerError;
|
|
60
|
+
constructor(error: ServerError);
|
|
61
|
+
}
|
|
62
|
+
export declare const isServerErrorException: (value: unknown) => value is ServerErrorException;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,gBAAgB,CAAC;AAExB,UAAU,oBAAoB;IAC5B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,+BAA+B,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,2BAA2B,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd;AAED,UAAU,mBAAmB;IAC3B,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,EAAE,6BAA6B,CAAC;IACpC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,OAAO,yBAAyB,CAAC;CAC/C;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,0BAA0B,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,+BAA+B,CAAC;IACvD,WAAW,EAAE,OAAO,qBAAqB,CAAC;CAC3C;AAED,UAAU,oBAAoB;IAC5B,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,EAAE,8BAA8B,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,yBAAyB,CAAC;CAC/C;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,4BAA4B,CAAC;IACnC,SAAS,EAAE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ost: (host) => ({
|
|
4
|
+
kind: "non-loopback-host",
|
|
5
|
+
code: "E_LT_SERVER_NON_LOOPBACK_HOST",
|
|
6
|
+
host,
|
|
7
|
+
}),
|
|
8
|
+
listenFailed: (host, port, cause) => ({
|
|
9
|
+
kind: "listen-failed",
|
|
10
|
+
code: "E_LT_SERVER_LISTEN_FAILED",
|
|
11
|
+
host,
|
|
12
|
+
port,
|
|
13
|
+
cause,
|
|
14
|
+
}),
|
|
15
|
+
loopbackDenied: (reason, observed) => ({
|
|
16
|
+
kind: "loopback-denied",
|
|
17
|
+
code: "E_LT_SERVER_LOOPBACK_DENIED",
|
|
18
|
+
reason,
|
|
19
|
+
observed,
|
|
20
|
+
wsCloseCode: WS_CLOSE_POLICY_VIOLATION,
|
|
21
|
+
}),
|
|
22
|
+
backpressure: (bufferedBytes) => ({
|
|
23
|
+
kind: "backpressure",
|
|
24
|
+
code: "E_LT_SERVER_BACKPRESSURE",
|
|
25
|
+
bufferedBytes,
|
|
26
|
+
thresholdBytes: WS_BACKPRESSURE_THRESHOLD_BYTES,
|
|
27
|
+
wsCloseCode: WS_CLOSE_BACKPRESSURE,
|
|
28
|
+
}),
|
|
29
|
+
sessionCapacity: (limit) => ({
|
|
30
|
+
kind: "session-capacity",
|
|
31
|
+
code: "E_LT_SERVER_SESSION_CAPACITY",
|
|
32
|
+
limit,
|
|
33
|
+
wsCloseCode: WS_CLOSE_CAPACITY_REACHED,
|
|
34
|
+
}),
|
|
35
|
+
frameRejected: (direction, reason) => ({
|
|
36
|
+
kind: "frame-rejected",
|
|
37
|
+
code: "E_LT_SERVER_FRAME_REJECTED",
|
|
38
|
+
direction,
|
|
39
|
+
reason,
|
|
40
|
+
}),
|
|
41
|
+
pathTraversal: (requested) => ({
|
|
42
|
+
kind: "path-traversal",
|
|
43
|
+
code: "E_LT_SERVER_PATH_TRAVERSAL",
|
|
44
|
+
requested,
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
const exhaustivenessGuard = (impossible) => {
|
|
48
|
+
throw new Error(`unhandled ServerError variant: ${JSON.stringify(impossible)}`);
|
|
49
|
+
};
|
|
50
|
+
export const formatServerError = (error) => {
|
|
51
|
+
switch (error.kind) {
|
|
52
|
+
case "non-loopback-host":
|
|
53
|
+
return `refusing to bind non-loopback host '${error.host}': pass 127.0.0.1 or localhost`;
|
|
54
|
+
case "listen-failed":
|
|
55
|
+
return `failed to listen on ${error.host}:${error.port}: ${error.cause.message}`;
|
|
56
|
+
case "loopback-denied": {
|
|
57
|
+
const where = error.reason === "host" ? "Host header" : "Origin header";
|
|
58
|
+
const seen = error.observed ? ` (saw '${error.observed}')` : "";
|
|
59
|
+
return `forbidden: non-loopback ${where}${seen}`;
|
|
60
|
+
}
|
|
61
|
+
case "backpressure":
|
|
62
|
+
return `closing socket: outbound buffered ${error.bufferedBytes}B exceeds ${error.thresholdBytes}B threshold`;
|
|
63
|
+
case "session-capacity":
|
|
64
|
+
return `refusing new session: at capacity (${error.limit} concurrent sessions)`;
|
|
65
|
+
case "frame-rejected":
|
|
66
|
+
return `dropping malformed ${error.direction} frame: ${error.reason}`;
|
|
67
|
+
case "path-traversal":
|
|
68
|
+
return `refusing path-traversal request: '${error.requested}'`;
|
|
69
|
+
default:
|
|
70
|
+
return exhaustivenessGuard(error);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export class ServerErrorException extends Error {
|
|
74
|
+
error;
|
|
75
|
+
constructor(error) {
|
|
76
|
+
super(formatServerError(error), {
|
|
77
|
+
cause: "cause" in error ? error.cause : undefined,
|
|
78
|
+
});
|
|
79
|
+
this.name = "ServerErrorException";
|
|
80
|
+
this.error = error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const isServerErrorException = (value) => value instanceof ServerErrorException;
|
|
84
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAA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AAC;AAEF,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,KAAK,CAAc;IAC5B,YAAY,KAAkB;QAC5B,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE;YAC9B,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAClD,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAc,EAAiC,EAAE,CACtF,KAAK,YAAY,oBAAoB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SessionRegistry } from "./session-registry.js";
|
|
2
|
+
export interface ServerOptions {
|
|
3
|
+
port?: number;
|
|
4
|
+
host?: string;
|
|
5
|
+
staticRoot?: string | null;
|
|
6
|
+
agentToken?: string;
|
|
7
|
+
allowDestructiveCommands?: boolean;
|
|
8
|
+
maxConcurrentSessions?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RunningServer {
|
|
11
|
+
port: number;
|
|
12
|
+
host: string;
|
|
13
|
+
registry: SessionRegistry;
|
|
14
|
+
stop: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare const createServer: (options?: ServerOptions) => Promise<RunningServer>;
|
|
17
|
+
export type { Session } from "./session.js";
|
|
18
|
+
export type { SessionRegistry } from "./session-registry.js";
|
|
19
|
+
export type * from "./types.js";
|
|
20
|
+
export { DEFAULT_HOST, DEFAULT_PORT, WS_CLOSE_BACKPRESSURE } from "./constants.js";
|
|
21
|
+
export { isLoopbackHost } from "./security.js";
|
|
22
|
+
export { healthSchema } from "./schemas.js";
|
|
23
|
+
export { ServerErrorException, formatServerError, isServerErrorException, serverError, } from "./errors.js";
|
|
24
|
+
export type { ServerError, ServerErrorCode, ServerErrorKind } from "./errors.js";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AASxD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AA6DD,eAAO,MAAM,YAAY,GAAU,UAAS,aAAkB,KAAG,OAAO,CAAC,aAAa,CA4WrF,CAAC;AAEF,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,mBAAmB,YAAY,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { serve } from "@hono/node-server";
|
|
4
|
+
import { createNodeWebSocket } from "@hono/node-ws";
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { DEFAULT_HOST, DEFAULT_PORT, HTTP_STATUS_NOT_FOUND, MAX_CONCURRENT_SESSIONS, SERVER_STOP_GRACE_MS, WS_BACKPRESSURE_THRESHOLD_BYTES, WS_CLOSE_BACKPRESSURE, WS_CLOSE_CAPACITY_REACHED, WS_CLOSE_POLICY_VIOLATION, WS_HEARTBEAT_INTERVAL_MS, WS_OUTBOUND_DRAIN_POLL_MS, WS_OUTBOUND_PAUSE_HIGH_WATER_BYTES, WS_OUTBOUND_RESUME_LOW_WATER_BYTES, WS_READY_STATE_OPEN, } from "./constants.js";
|
|
7
|
+
import { ServerErrorException, serverError } from "./errors.js";
|
|
8
|
+
import { clientToServerMessageSchema } from "./schemas.js";
|
|
9
|
+
import { enforceLoopback, isLoopbackHost, loopbackMiddleware } from "./security.js";
|
|
10
|
+
import { OutputBatcher } from "./output-batcher.js";
|
|
11
|
+
import { Session } from "./session.js";
|
|
12
|
+
import { SessionRegistry } from "./session-registry.js";
|
|
13
|
+
import { resolveStaticAsset } from "./static-resolver.js";
|
|
14
|
+
import { getHeartbeatAction } from "./utils/get-heartbeat-action.js";
|
|
15
|
+
import { SHELL_INTEGRATION_ENV_VAR } from "./shell-integration/index.js";
|
|
16
|
+
import { validateAgentToken, loadOrCreateAgentToken } from "./agent-token.js";
|
|
17
|
+
import { handleRpcRequest } from "./agent-rpc.js";
|
|
18
|
+
import { stripAnsi } from "./utils/strip-ansi.js";
|
|
19
|
+
const REVALIDATED_STATIC_PATHS = new Set(["/sw.js", "/manifest.webmanifest"]);
|
|
20
|
+
const getRawBufferedAmount = (raw) => {
|
|
21
|
+
if (!raw || typeof raw !== "object")
|
|
22
|
+
return 0;
|
|
23
|
+
const candidate = Reflect.get(raw, "bufferedAmount");
|
|
24
|
+
return typeof candidate === "number" ? candidate : 0;
|
|
25
|
+
};
|
|
26
|
+
const callRawMethod = (raw, method) => {
|
|
27
|
+
if (!raw || typeof raw !== "object")
|
|
28
|
+
return false;
|
|
29
|
+
const candidate = Reflect.get(raw, method);
|
|
30
|
+
if (typeof candidate !== "function")
|
|
31
|
+
return false;
|
|
32
|
+
try {
|
|
33
|
+
candidate.call(raw);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const onRawEvent = (raw, event, listener) => {
|
|
41
|
+
if (!raw || typeof raw !== "object")
|
|
42
|
+
return null;
|
|
43
|
+
const on = Reflect.get(raw, "on");
|
|
44
|
+
const off = Reflect.get(raw, "off");
|
|
45
|
+
if (typeof on !== "function" || typeof off !== "function")
|
|
46
|
+
return null;
|
|
47
|
+
on.call(raw, event, listener);
|
|
48
|
+
return () => {
|
|
49
|
+
try {
|
|
50
|
+
off.call(raw, event, listener);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
/* socket already torn down */
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const safeSendRaw = (ws, payload) => {
|
|
58
|
+
if (ws.readyState !== WS_READY_STATE_OPEN)
|
|
59
|
+
return;
|
|
60
|
+
if (getRawBufferedAmount(ws.raw) > WS_BACKPRESSURE_THRESHOLD_BYTES) {
|
|
61
|
+
ws.close(WS_CLOSE_BACKPRESSURE, "backpressure");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
ws.send(payload);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
/* socket closed between readyState check and send */
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const safeSend = (ws, payload) => {
|
|
72
|
+
safeSendRaw(ws, JSON.stringify(payload));
|
|
73
|
+
};
|
|
74
|
+
export const createServer = async (options = {}) => {
|
|
75
|
+
const port = options.port ?? DEFAULT_PORT;
|
|
76
|
+
const host = options.host ?? DEFAULT_HOST;
|
|
77
|
+
if (!isLoopbackHost(host)) {
|
|
78
|
+
throw new ServerErrorException(serverError.nonLoopbackHost(host));
|
|
79
|
+
}
|
|
80
|
+
const staticRoot = typeof options.staticRoot === "string" ? path.resolve(options.staticRoot) : null;
|
|
81
|
+
loadOrCreateAgentToken();
|
|
82
|
+
const registry = new SessionRegistry();
|
|
83
|
+
const app = new Hono();
|
|
84
|
+
const { injectWebSocket, upgradeWebSocket, wss } = createNodeWebSocket({ app });
|
|
85
|
+
const api = new Hono();
|
|
86
|
+
api.use("*", loopbackMiddleware);
|
|
87
|
+
api.get("/health", (context) => context.json({ ok: true, sessions: registry.size() }));
|
|
88
|
+
api.notFound((context) => context.json({ error: "not_found" }, HTTP_STATUS_NOT_FOUND));
|
|
89
|
+
app.route("/api", api);
|
|
90
|
+
app.get("/ws", upgradeWebSocket((context) => {
|
|
91
|
+
const blocked = enforceLoopback(context);
|
|
92
|
+
if (blocked) {
|
|
93
|
+
return { onOpen: (_event, ws) => ws.close(WS_CLOSE_POLICY_VIOLATION, "forbidden") };
|
|
94
|
+
}
|
|
95
|
+
let session = null;
|
|
96
|
+
let drainPollTimer = null;
|
|
97
|
+
let heartbeatTimer = null;
|
|
98
|
+
let stopHeartbeat = null;
|
|
99
|
+
let outputBatcher = null;
|
|
100
|
+
const stopDrainPoll = () => {
|
|
101
|
+
if (drainPollTimer === null)
|
|
102
|
+
return;
|
|
103
|
+
clearInterval(drainPollTimer);
|
|
104
|
+
drainPollTimer = null;
|
|
105
|
+
};
|
|
106
|
+
const stopHeartbeatChecks = () => {
|
|
107
|
+
if (heartbeatTimer !== null) {
|
|
108
|
+
clearInterval(heartbeatTimer);
|
|
109
|
+
heartbeatTimer = null;
|
|
110
|
+
}
|
|
111
|
+
if (stopHeartbeat) {
|
|
112
|
+
stopHeartbeat();
|
|
113
|
+
stopHeartbeat = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const rawCwd = context.req.query("cwd");
|
|
117
|
+
let requestedCwd;
|
|
118
|
+
if (rawCwd) {
|
|
119
|
+
try {
|
|
120
|
+
const stat = fs.statSync(rawCwd);
|
|
121
|
+
if (stat.isDirectory())
|
|
122
|
+
requestedCwd = rawCwd;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
/* invalid or inaccessible path; fall back to default cwd */
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const rawMode = context.req.query("mode");
|
|
129
|
+
const sessionMode = rawMode === "agent" ? "agent" : "human";
|
|
130
|
+
return {
|
|
131
|
+
onOpen(_event, ws) {
|
|
132
|
+
if (sessionMode === "agent") {
|
|
133
|
+
const rawToken = context.req.query("token");
|
|
134
|
+
if (!rawToken || !validateAgentToken(rawToken)) {
|
|
135
|
+
ws.close(1008, "invalid agent token");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const maxSessions = options.maxConcurrentSessions ?? MAX_CONCURRENT_SESSIONS;
|
|
140
|
+
if (registry.size() >= maxSessions) {
|
|
141
|
+
ws.close(WS_CLOSE_CAPACITY_REACHED, "session capacity reached");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const integrationEnv = sessionMode === "agent"
|
|
145
|
+
? { [SHELL_INTEGRATION_ENV_VAR]: "1" }
|
|
146
|
+
: undefined;
|
|
147
|
+
const newSession = new Session({ cwd: requestedCwd, mode: sessionMode, env: integrationEnv });
|
|
148
|
+
session = newSession;
|
|
149
|
+
registry.register(newSession);
|
|
150
|
+
// Heartbeat. Without this, half-open sockets (laptop sleep, network
|
|
151
|
+
// dropout) never surface as a `close` event and the daemon keeps
|
|
152
|
+
// streaming PTY output into the void. We only enable it if the raw
|
|
153
|
+
// socket exposes `on("pong")` — otherwise the timer would tick with
|
|
154
|
+
// no pongs ever observed and kill healthy connections after the
|
|
155
|
+
// first idle window.
|
|
156
|
+
let lastPongAt = Date.now();
|
|
157
|
+
let pendingPingAt = 0;
|
|
158
|
+
stopHeartbeat = onRawEvent(ws.raw, "pong", () => {
|
|
159
|
+
lastPongAt = Date.now();
|
|
160
|
+
pendingPingAt = 0;
|
|
161
|
+
});
|
|
162
|
+
if (stopHeartbeat) {
|
|
163
|
+
heartbeatTimer = setInterval(() => {
|
|
164
|
+
if (ws.readyState !== WS_READY_STATE_OPEN)
|
|
165
|
+
return;
|
|
166
|
+
const now = Date.now();
|
|
167
|
+
const idleMs = now - lastPongAt;
|
|
168
|
+
const heartbeatAction = getHeartbeatAction(now, lastPongAt, pendingPingAt);
|
|
169
|
+
if (heartbeatAction === "wait")
|
|
170
|
+
return;
|
|
171
|
+
if (heartbeatAction === "grace-ping") {
|
|
172
|
+
pendingPingAt = now;
|
|
173
|
+
callRawMethod(ws.raw, "ping");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (heartbeatAction === "terminate") {
|
|
177
|
+
console.warn(`ws heartbeat timeout: no pong for ${idleMs}ms (grace ${now - pendingPingAt}ms, pid ${newSession.pid}); terminating`);
|
|
178
|
+
stopHeartbeatChecks();
|
|
179
|
+
if (!callRawMethod(ws.raw, "terminate"))
|
|
180
|
+
ws.close();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
callRawMethod(ws.raw, "ping");
|
|
184
|
+
}, WS_HEARTBEAT_INTERVAL_MS);
|
|
185
|
+
heartbeatTimer.unref?.();
|
|
186
|
+
}
|
|
187
|
+
// Outbound flow control. When the WS buffer climbs past the high
|
|
188
|
+
// water mark we pause the PTY (OS pipe back-pressure stops the
|
|
189
|
+
// child process producing more output) and start polling for the
|
|
190
|
+
// buffer to drain back below the low water mark. This way bursty
|
|
191
|
+
// output (`cat`, build logs, npm install) doesn't kill the
|
|
192
|
+
// connection — only a genuinely wedged receiver eventually trips
|
|
193
|
+
// the WS_BACKPRESSURE_THRESHOLD_BYTES emergency in safeSend.
|
|
194
|
+
const ensureDrainPoll = () => {
|
|
195
|
+
if (drainPollTimer !== null)
|
|
196
|
+
return;
|
|
197
|
+
drainPollTimer = setInterval(() => {
|
|
198
|
+
if (!newSession.isPaused) {
|
|
199
|
+
stopDrainPoll();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (getRawBufferedAmount(ws.raw) <= WS_OUTBOUND_RESUME_LOW_WATER_BYTES) {
|
|
203
|
+
newSession.resume();
|
|
204
|
+
stopDrainPoll();
|
|
205
|
+
}
|
|
206
|
+
}, WS_OUTBOUND_DRAIN_POLL_MS);
|
|
207
|
+
drainPollTimer.unref?.();
|
|
208
|
+
};
|
|
209
|
+
// Wire listeners BEFORE the first safeSend so any synchronous emit
|
|
210
|
+
// from Session (current or future) reaches the client. Today
|
|
211
|
+
// node-pty's data/exit are async, but this guards against drift.
|
|
212
|
+
outputBatcher = new OutputBatcher((output) => {
|
|
213
|
+
safeSendRaw(ws, output.buffer);
|
|
214
|
+
if (!newSession.isPaused &&
|
|
215
|
+
getRawBufferedAmount(ws.raw) >= WS_OUTBOUND_PAUSE_HIGH_WATER_BYTES) {
|
|
216
|
+
newSession.pause();
|
|
217
|
+
ensureDrainPoll();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const onOutput = (data) => outputBatcher?.push(data);
|
|
221
|
+
const onTitle = (title) => safeSend(ws, { type: "title", title });
|
|
222
|
+
const onCwd = (cwd) => safeSend(ws, { type: "cwd", cwd });
|
|
223
|
+
const onExit = (code) => {
|
|
224
|
+
outputBatcher?.flush();
|
|
225
|
+
outputBatcher?.dispose();
|
|
226
|
+
outputBatcher = null;
|
|
227
|
+
stopDrainPoll();
|
|
228
|
+
stopHeartbeatChecks();
|
|
229
|
+
safeSend(ws, { type: "exit", code });
|
|
230
|
+
ws.close();
|
|
231
|
+
};
|
|
232
|
+
newSession.on("output", onOutput);
|
|
233
|
+
// Agent-mode gets ANSI-stripped text alongside raw binary output.
|
|
234
|
+
if (sessionMode === "agent") {
|
|
235
|
+
const onAgentOutput = (data) => {
|
|
236
|
+
const text = stripAnsi(data);
|
|
237
|
+
if (text)
|
|
238
|
+
safeSend(ws, { type: "agent-output", text });
|
|
239
|
+
};
|
|
240
|
+
newSession.on("output", onAgentOutput);
|
|
241
|
+
}
|
|
242
|
+
const onCommandBoundary = (boundary) => {
|
|
243
|
+
safeSend(ws, {
|
|
244
|
+
type: "command-boundary",
|
|
245
|
+
phase: boundary.phase,
|
|
246
|
+
...(boundary.exitCode !== undefined ? { exitCode: boundary.exitCode } : {}),
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
newSession.on("commandBoundary", onCommandBoundary);
|
|
250
|
+
newSession.on("title", onTitle);
|
|
251
|
+
newSession.on("cwd", onCwd);
|
|
252
|
+
newSession.on("exit", onExit);
|
|
253
|
+
safeSend(ws, {
|
|
254
|
+
type: "session",
|
|
255
|
+
shell: newSession.shell,
|
|
256
|
+
shellName: newSession.shellBaseName,
|
|
257
|
+
pid: newSession.pid,
|
|
258
|
+
cwd: newSession.cwd,
|
|
259
|
+
});
|
|
260
|
+
},
|
|
261
|
+
onMessage(event, ws) {
|
|
262
|
+
if (!session)
|
|
263
|
+
return;
|
|
264
|
+
let rawPayload;
|
|
265
|
+
try {
|
|
266
|
+
const raw = typeof event.data === "string" ? event.data : event.data.toString();
|
|
267
|
+
rawPayload = JSON.parse(raw);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const parsed = clientToServerMessageSchema.safeParse(rawPayload);
|
|
273
|
+
if (!parsed.success)
|
|
274
|
+
return;
|
|
275
|
+
if (parsed.data.type === "input") {
|
|
276
|
+
session.write(parsed.data.data);
|
|
277
|
+
}
|
|
278
|
+
else if (parsed.data.type === "resize") {
|
|
279
|
+
session.resize(parsed.data.cols, parsed.data.rows);
|
|
280
|
+
}
|
|
281
|
+
else if (parsed.data.type === "flow-pause") {
|
|
282
|
+
session.pause();
|
|
283
|
+
}
|
|
284
|
+
else if (parsed.data.type === "flow-resume") {
|
|
285
|
+
session.resume();
|
|
286
|
+
}
|
|
287
|
+
else if (parsed.data.type === "rpc") {
|
|
288
|
+
handleRpcRequest({
|
|
289
|
+
registry,
|
|
290
|
+
allowDestructiveCommands: options.allowDestructiveCommands ?? false,
|
|
291
|
+
sendResponse: (rpcId, result, error) => {
|
|
292
|
+
safeSend(ws, { type: "rpc-response", id: rpcId, result, error });
|
|
293
|
+
},
|
|
294
|
+
}, { id: parsed.data.id, method: parsed.data.method, params: parsed.data.params });
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
onClose(event) {
|
|
298
|
+
outputBatcher?.dispose();
|
|
299
|
+
outputBatcher = null;
|
|
300
|
+
stopDrainPoll();
|
|
301
|
+
stopHeartbeatChecks();
|
|
302
|
+
// Most "the terminal randomly died" reports are actually the WS
|
|
303
|
+
// closing for a reason we never surfaced; logging code+reason+
|
|
304
|
+
// wasClean here makes the next incident a 1-line lookup in
|
|
305
|
+
// ~/.localterm/server.log.
|
|
306
|
+
const pidLabel = session ? ` pid ${session.pid}` : "";
|
|
307
|
+
console.info(`ws closed${pidLabel}: code=${event.code} reason=${JSON.stringify(event.reason)} wasClean=${event.wasClean}`);
|
|
308
|
+
if (!session)
|
|
309
|
+
return;
|
|
310
|
+
registry.unregister(session);
|
|
311
|
+
session.dispose();
|
|
312
|
+
session = null;
|
|
313
|
+
},
|
|
314
|
+
onError(event) {
|
|
315
|
+
outputBatcher?.dispose();
|
|
316
|
+
outputBatcher = null;
|
|
317
|
+
stopDrainPoll();
|
|
318
|
+
stopHeartbeatChecks();
|
|
319
|
+
const errorValue = event && typeof event === "object" ? (Reflect.get(event, "error") ?? event) : event;
|
|
320
|
+
const message = errorValue instanceof Error ? errorValue.message : String(errorValue);
|
|
321
|
+
const pidLabel = session ? ` pid ${session.pid}` : "";
|
|
322
|
+
console.error(`ws error${pidLabel}: ${message}`);
|
|
323
|
+
if (!session)
|
|
324
|
+
return;
|
|
325
|
+
registry.unregister(session);
|
|
326
|
+
session.dispose();
|
|
327
|
+
session = null;
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}));
|
|
331
|
+
if (staticRoot) {
|
|
332
|
+
app.use("*", loopbackMiddleware);
|
|
333
|
+
app.get("*", (context) => {
|
|
334
|
+
const requestPath = context.req.path;
|
|
335
|
+
if (requestPath.startsWith("/api/") || requestPath.startsWith("/ws")) {
|
|
336
|
+
return context.json({ error: "not_found" }, HTTP_STATUS_NOT_FOUND);
|
|
337
|
+
}
|
|
338
|
+
const asset = resolveStaticAsset(staticRoot, requestPath);
|
|
339
|
+
if (!asset)
|
|
340
|
+
return context.text("not found", HTTP_STATUS_NOT_FOUND);
|
|
341
|
+
const shouldRevalidate = REVALIDATED_STATIC_PATHS.has(requestPath);
|
|
342
|
+
return new Response(new Uint8Array(asset.body), {
|
|
343
|
+
status: asset.status,
|
|
344
|
+
headers: {
|
|
345
|
+
"content-type": asset.contentType,
|
|
346
|
+
...(shouldRevalidate ? { "cache-control": "no-cache" } : {}),
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
let httpServer = null;
|
|
352
|
+
let actualPort = port;
|
|
353
|
+
await new Promise((resolve, reject) => {
|
|
354
|
+
const handleError = (error) => {
|
|
355
|
+
reject(new ServerErrorException(serverError.listenFailed(host, port, error)));
|
|
356
|
+
};
|
|
357
|
+
const node = serve({
|
|
358
|
+
fetch: app.fetch,
|
|
359
|
+
hostname: host,
|
|
360
|
+
port,
|
|
361
|
+
}, () => {
|
|
362
|
+
const address = node.address();
|
|
363
|
+
if (address && typeof address === "object")
|
|
364
|
+
actualPort = address.port;
|
|
365
|
+
node.removeListener("error", handleError);
|
|
366
|
+
resolve();
|
|
367
|
+
});
|
|
368
|
+
node.once("error", handleError);
|
|
369
|
+
httpServer = node;
|
|
370
|
+
});
|
|
371
|
+
if (!httpServer) {
|
|
372
|
+
throw new ServerErrorException(serverError.listenFailed(host, port, new Error("hono serve() resolved without binding an http server")));
|
|
373
|
+
}
|
|
374
|
+
injectWebSocket(httpServer);
|
|
375
|
+
const stop = async () => {
|
|
376
|
+
registry.disposeAll();
|
|
377
|
+
// Forcibly tear down every WS first. node-pty + ws upgraded sockets
|
|
378
|
+
// aren't tracked in http.Server's keep-alive set, so target.close() would
|
|
379
|
+
// otherwise wait forever for them and the CLI's force-exit fallback would
|
|
380
|
+
// fire on every shutdown.
|
|
381
|
+
for (const client of wss.clients) {
|
|
382
|
+
try {
|
|
383
|
+
client.terminate();
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
/* socket already torn down */
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
wss.close();
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
/* idempotent close — wss may already be closed */
|
|
394
|
+
}
|
|
395
|
+
if (!httpServer)
|
|
396
|
+
return;
|
|
397
|
+
const target = httpServer;
|
|
398
|
+
const closeAllConnections = Reflect.get(target, "closeAllConnections");
|
|
399
|
+
if (typeof closeAllConnections === "function") {
|
|
400
|
+
closeAllConnections.call(target);
|
|
401
|
+
}
|
|
402
|
+
await new Promise((resolve) => {
|
|
403
|
+
let settled = false;
|
|
404
|
+
const settle = () => {
|
|
405
|
+
if (settled)
|
|
406
|
+
return;
|
|
407
|
+
settled = true;
|
|
408
|
+
resolve();
|
|
409
|
+
};
|
|
410
|
+
const grace = setTimeout(settle, SERVER_STOP_GRACE_MS);
|
|
411
|
+
grace.unref?.();
|
|
412
|
+
target.close(() => {
|
|
413
|
+
clearTimeout(grace);
|
|
414
|
+
settle();
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
return { port: actualPort, host, registry, stop };
|
|
419
|
+
};
|
|
420
|
+
export { DEFAULT_HOST, DEFAULT_PORT, WS_CLOSE_BACKPRESSURE } from "./constants.js";
|
|
421
|
+
export { isLoopbackHost } from "./security.js";
|
|
422
|
+
export { healthSchema } from "./schemas.js";
|
|
423
|
+
export { ServerErrorException, formatServerError, isServerErrorException, serverError, } from "./errors.js";
|
|
424
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAmB,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,+BAA+B,EAC/B,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,kCAAkC,EAClC,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,gB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AAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,MAAM,MAAM,GAAG,GAAG,EAAE;gBAClB,IAAI,OAAO;oBAAE,OAAO;gBACpB,OAAO,GAAG,IAAI,CAAC;gBACf,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC;YACF,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;YACvD,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;gBAChB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,MAAM,EAAE,CAAC;YACX,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACpD,CAAC,CAAC;AAKF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CommandBoundary } from "./utils/parse-osc133-from-chunk.js";
|
|
2
|
+
export declare class Osc133ChunkParser {
|
|
3
|
+
private pending;
|
|
4
|
+
push(data: string): CommandBoundary | null;
|
|
5
|
+
reset(): void;
|
|
6
|
+
private isIncompleteOsc;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=osc133-chunk-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osc133-chunk-parser.d.ts","sourceRoot":"","sources":["../src/osc133-chunk-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAEhG,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAM;IAErB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAc1C,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,eAAe;CAKxB"}
|