@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MAX_PENDING_PARSE_BYTES } from "./constants.js";
|
|
2
|
+
import { parseOsc133FromChunk } from "./utils/parse-osc133-from-chunk.js";
|
|
3
|
+
export class Osc133ChunkParser {
|
|
4
|
+
pending = "";
|
|
5
|
+
push(data) {
|
|
6
|
+
const combined = this.pending + data;
|
|
7
|
+
this.pending = "";
|
|
8
|
+
const boundary = parseOsc133FromChunk(combined);
|
|
9
|
+
const lastOscIndex = combined.lastIndexOf("\x1b]");
|
|
10
|
+
const pendingStart = lastOscIndex !== -1 ? lastOscIndex : combined.endsWith("\x1b") ? combined.length - 1 : -1;
|
|
11
|
+
if (pendingStart !== -1 && combined.length - pendingStart <= MAX_PENDING_PARSE_BYTES) {
|
|
12
|
+
const tail = combined.slice(pendingStart);
|
|
13
|
+
if (this.isIncompleteOsc(tail))
|
|
14
|
+
this.pending = tail;
|
|
15
|
+
}
|
|
16
|
+
return boundary;
|
|
17
|
+
}
|
|
18
|
+
reset() {
|
|
19
|
+
this.pending = "";
|
|
20
|
+
}
|
|
21
|
+
isIncompleteOsc(tail) {
|
|
22
|
+
if (tail.length < 2)
|
|
23
|
+
return true;
|
|
24
|
+
if (tail[1] !== "]")
|
|
25
|
+
return false;
|
|
26
|
+
return !tail.includes("\x07", 2) && !tail.includes("\x1b\\", 2);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingUR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jC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osc7-chunk-parser.d.ts","sourceRoot":"","sources":["../src/osc7-chunk-parser.ts"],"names":[],"mappings":"AAGA,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAM;IAErB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAcjC,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,eAAe;CAKxB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MAX_PENDING_PARSE_BYTES } from "./constants.js";
|
|
2
|
+
import { parseOsc7FromChunk } from "./utils/parse-osc7-from-chunk.js";
|
|
3
|
+
export class Osc7ChunkParser {
|
|
4
|
+
pending = "";
|
|
5
|
+
push(data) {
|
|
6
|
+
const combined = this.pending + data;
|
|
7
|
+
this.pending = "";
|
|
8
|
+
const path = parseOsc7FromChunk(combined);
|
|
9
|
+
const lastOscIndex = combined.lastIndexOf("\x1b]");
|
|
10
|
+
const pendingStart = lastOscIndex !== -1 ? lastOscIndex : combined.endsWith("\x1b") ? combined.length - 1 : -1;
|
|
11
|
+
if (pendingStart !== -1 && combined.length - pendingStart <= MAX_PENDING_PARSE_BYTES) {
|
|
12
|
+
const tail = combined.slice(pendingStart);
|
|
13
|
+
if (this.isIncompleteOsc(tail))
|
|
14
|
+
this.pending = tail;
|
|
15
|
+
}
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
reset() {
|
|
19
|
+
this.pending = "";
|
|
20
|
+
}
|
|
21
|
+
isIncompleteOsc(tail) {
|
|
22
|
+
if (tail.length < 2)
|
|
23
|
+
return true;
|
|
24
|
+
if (tail[1] !== "]")
|
|
25
|
+
return false;
|
|
26
|
+
return !tail.includes("\x07", 2) && !tail.includes("\x1b\\", 2);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=osc7-chunk-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osc7-chunk-parser.js","sourceRoot":"","sources":["../src/osc7-chunk-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,MAAM,OAAO,eAAe;IAClB,OAAO,GAAG,EAAE,CAAC;IAErB,IAAI,CAAC,IAAY;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,YAAY,GAChB,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5F,IAAI,YAAY,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,YAAY,IAAI,uBAAuB,EAAE,CAAC;YACrF,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAC1C,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;gBAAE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAEO,eAAe,CAAC,IAAY;QAClC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACjC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class OutputBatcher {
|
|
2
|
+
private readonly onFlush;
|
|
3
|
+
private readonly chunks;
|
|
4
|
+
private bufferedBytes;
|
|
5
|
+
private timer;
|
|
6
|
+
constructor(onFlush: (output: Uint8Array<ArrayBuffer>) => void);
|
|
7
|
+
push(data: string): void;
|
|
8
|
+
flush(): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=output-batcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-batcher.d.ts","sourceRoot":"","sources":["../src/output-batcher.ts"],"names":[],"mappings":"AAIA,qBAAa,aAAa;IAKZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,KAAK,CAA+B;gBAEf,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI;IAE/E,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAgBxB,KAAK,IAAI,IAAI;IAYb,OAAO,IAAI,IAAI;CAQhB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OUTPUT_BATCH_MAX_BYTES, OUTPUT_BATCH_WINDOW_MS } from "./constants.js";
|
|
2
|
+
const TRAILING_HIGH_SURROGATE_PATTERN = /[\uD800-\uDBFF]$/;
|
|
3
|
+
export class OutputBatcher {
|
|
4
|
+
onFlush;
|
|
5
|
+
chunks = [];
|
|
6
|
+
bufferedBytes = 0;
|
|
7
|
+
timer = null;
|
|
8
|
+
constructor(onFlush) {
|
|
9
|
+
this.onFlush = onFlush;
|
|
10
|
+
}
|
|
11
|
+
push(data) {
|
|
12
|
+
if (!data)
|
|
13
|
+
return;
|
|
14
|
+
this.chunks.push(data);
|
|
15
|
+
this.bufferedBytes += Buffer.byteLength(data);
|
|
16
|
+
if (this.bufferedBytes >= OUTPUT_BATCH_MAX_BYTES &&
|
|
17
|
+
!TRAILING_HIGH_SURROGATE_PATTERN.test(data)) {
|
|
18
|
+
this.flush();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (this.timer !== null)
|
|
22
|
+
clearTimeout(this.timer);
|
|
23
|
+
this.timer = setTimeout(() => this.flush(), OUTPUT_BATCH_WINDOW_MS);
|
|
24
|
+
this.timer.unref();
|
|
25
|
+
}
|
|
26
|
+
flush() {
|
|
27
|
+
if (this.timer !== null) {
|
|
28
|
+
clearTimeout(this.timer);
|
|
29
|
+
this.timer = null;
|
|
30
|
+
}
|
|
31
|
+
if (this.chunks.length === 0)
|
|
32
|
+
return;
|
|
33
|
+
const output = new TextEncoder().encode(this.chunks.join(""));
|
|
34
|
+
this.chunks.length = 0;
|
|
35
|
+
this.bufferedBytes = 0;
|
|
36
|
+
this.onFlush(output);
|
|
37
|
+
}
|
|
38
|
+
dispose() {
|
|
39
|
+
if (this.timer !== null) {
|
|
40
|
+
clearTimeout(this.timer);
|
|
41
|
+
this.timer = null;
|
|
42
|
+
}
|
|
43
|
+
this.chunks.length = 0;
|
|
44
|
+
this.bufferedBytes = 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=output-batcher.js.map
|
|
@@ -0,0 +1 @@
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ACrC,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9D,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MAX_COLS, MAX_CONCURRENT_SESSIONS, MAX_INPUT_BYTES, MAX_OUTPUT_BYTES, MAX_ROWS, MAX_TITLE_LENGTH, WS_BACKPRESSURE_THRESHOLD_BYTES, WS_CLOSE_BACKPRESSURE, WS_CLOSE_CAPACITY_REACHED, WS_CLOSE_POLICY_VIOLATION, WS_READY_STATE_OPEN, } from "./constants.js";
|
|
2
|
+
export { clientToServerMessageSchema, healthSchema, serverToClientMessageSchema, } from "./schemas.js";
|
|
3
|
+
export type { ClientToServerMessage, ServerToClientMessage } from "./types.js";
|
|
4
|
+
export type { ServerError, ServerErrorCode, ServerErrorKind } from "./errors.js";
|
|
5
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,+BAA+B,EAC/B,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC/E,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { MAX_COLS, MAX_CONCURRENT_SESSIONS, MAX_INPUT_BYTES, MAX_OUTPUT_BYTES, MAX_ROWS, MAX_TITLE_LENGTH, WS_BACKPRESSURE_THRESHOLD_BYTES, WS_CLOSE_BACKPRESSURE, WS_CLOSE_CAPACITY_REACHED, WS_CLOSE_POLICY_VIOLATION, WS_READY_STATE_OPEN, } from "./constants.js";
|
|
2
|
+
export { clientToServerMessageSchema, healthSchema, serverToClientMessageSchema, } from "./schemas.js";
|
|
3
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,+BAA+B,EAC/B,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,2BAA2B,GAC5B,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const healthSchema: z.ZodObject<{
|
|
3
|
+
ok: z.ZodBoolean;
|
|
4
|
+
sessions: z.ZodNumber;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
export declare const clientToServerMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
7
|
+
type: z.ZodLiteral<"input">;
|
|
8
|
+
data: z.ZodString;
|
|
9
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"resize">;
|
|
11
|
+
cols: z.ZodNumber;
|
|
12
|
+
rows: z.ZodNumber;
|
|
13
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
14
|
+
type: z.ZodLiteral<"flow-pause">;
|
|
15
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"flow-resume">;
|
|
17
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
18
|
+
type: z.ZodLiteral<"rpc">;
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
method: z.ZodEnum<{
|
|
21
|
+
spawn_session: "spawn_session";
|
|
22
|
+
list_sessions: "list_sessions";
|
|
23
|
+
write_input: "write_input";
|
|
24
|
+
read_output: "read_output";
|
|
25
|
+
wait_for_boundary: "wait_for_boundary";
|
|
26
|
+
exec: "exec";
|
|
27
|
+
}>;
|
|
28
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
29
|
+
}, z.core.$strict>], "type">;
|
|
30
|
+
export declare const serverToClientMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
31
|
+
type: z.ZodLiteral<"output">;
|
|
32
|
+
data: z.ZodString;
|
|
33
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"exit">;
|
|
35
|
+
code: z.ZodNullable<z.ZodNumber>;
|
|
36
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
37
|
+
type: z.ZodLiteral<"title">;
|
|
38
|
+
title: z.ZodString;
|
|
39
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
40
|
+
type: z.ZodLiteral<"session">;
|
|
41
|
+
shell: z.ZodString;
|
|
42
|
+
shellName: z.ZodString;
|
|
43
|
+
pid: z.ZodNumber;
|
|
44
|
+
cwd: z.ZodString;
|
|
45
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
46
|
+
type: z.ZodLiteral<"cwd">;
|
|
47
|
+
cwd: z.ZodString;
|
|
48
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
49
|
+
type: z.ZodLiteral<"agent-output">;
|
|
50
|
+
text: z.ZodString;
|
|
51
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
52
|
+
type: z.ZodLiteral<"command-boundary">;
|
|
53
|
+
phase: z.ZodEnum<{
|
|
54
|
+
"prompt-start": "prompt-start";
|
|
55
|
+
"command-start": "command-start";
|
|
56
|
+
"output-start": "output-start";
|
|
57
|
+
"command-end": "command-end";
|
|
58
|
+
}>;
|
|
59
|
+
exitCode: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
type: z.ZodLiteral<"rpc-response">;
|
|
62
|
+
id: z.ZodString;
|
|
63
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
64
|
+
error: z.ZodOptional<z.ZodString>;
|
|
65
|
+
}, z.core.$strict>], "type">;
|
|
66
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,YAAY;;;kBAKd,CAAC;AA6CZ,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;4BAMtC,CAAC;AAgEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAStC,CAAC"}
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { MAX_COLS, MAX_INPUT_BYTES, MAX_OUTPUT_BYTES, MAX_ROWS, MAX_TITLE_LENGTH, } from "./constants.js";
|
|
3
|
+
export const healthSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
ok: z.boolean(),
|
|
6
|
+
sessions: z.number().int().nonnegative(),
|
|
7
|
+
})
|
|
8
|
+
.strict();
|
|
9
|
+
const inputMessageSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
type: z.literal("input"),
|
|
12
|
+
data: z.string().max(MAX_INPUT_BYTES),
|
|
13
|
+
})
|
|
14
|
+
.strict();
|
|
15
|
+
const resizeMessageSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
type: z.literal("resize"),
|
|
18
|
+
cols: z.number().int().positive().max(MAX_COLS),
|
|
19
|
+
rows: z.number().int().positive().max(MAX_ROWS),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const flowPauseMessageSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
type: z.literal("flow-pause"),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
const flowResumeMessageSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
type: z.literal("flow-resume"),
|
|
30
|
+
})
|
|
31
|
+
.strict();
|
|
32
|
+
const rpcRequestMessageSchema = z
|
|
33
|
+
.object({
|
|
34
|
+
type: z.literal("rpc"),
|
|
35
|
+
id: z.string().min(1).max(64),
|
|
36
|
+
method: z.enum([
|
|
37
|
+
"spawn_session",
|
|
38
|
+
"list_sessions",
|
|
39
|
+
"write_input",
|
|
40
|
+
"read_output",
|
|
41
|
+
"wait_for_boundary",
|
|
42
|
+
"exec",
|
|
43
|
+
]),
|
|
44
|
+
params: z.record(z.string(), z.unknown()).optional(),
|
|
45
|
+
})
|
|
46
|
+
.strict();
|
|
47
|
+
export const clientToServerMessageSchema = z.discriminatedUnion("type", [
|
|
48
|
+
inputMessageSchema,
|
|
49
|
+
resizeMessageSchema,
|
|
50
|
+
flowPauseMessageSchema,
|
|
51
|
+
flowResumeMessageSchema,
|
|
52
|
+
rpcRequestMessageSchema,
|
|
53
|
+
]);
|
|
54
|
+
const outputMessageSchema = z
|
|
55
|
+
.object({
|
|
56
|
+
type: z.literal("output"),
|
|
57
|
+
data: z.string().max(MAX_OUTPUT_BYTES),
|
|
58
|
+
})
|
|
59
|
+
.strict();
|
|
60
|
+
const exitMessageSchema = z
|
|
61
|
+
.object({
|
|
62
|
+
type: z.literal("exit"),
|
|
63
|
+
code: z.number().int().nullable(),
|
|
64
|
+
})
|
|
65
|
+
.strict();
|
|
66
|
+
const titleMessageSchema = z
|
|
67
|
+
.object({
|
|
68
|
+
type: z.literal("title"),
|
|
69
|
+
title: z.string().max(MAX_TITLE_LENGTH),
|
|
70
|
+
})
|
|
71
|
+
.strict();
|
|
72
|
+
const sessionMessageSchema = z
|
|
73
|
+
.object({
|
|
74
|
+
type: z.literal("session"),
|
|
75
|
+
shell: z.string().min(1),
|
|
76
|
+
shellName: z.string().min(1),
|
|
77
|
+
pid: z.number().int().nonnegative(),
|
|
78
|
+
cwd: z.string().min(1),
|
|
79
|
+
})
|
|
80
|
+
.strict();
|
|
81
|
+
const cwdMessageSchema = z
|
|
82
|
+
.object({
|
|
83
|
+
type: z.literal("cwd"),
|
|
84
|
+
cwd: z.string().min(1),
|
|
85
|
+
})
|
|
86
|
+
.strict();
|
|
87
|
+
const agentOutputMessageSchema = z
|
|
88
|
+
.object({
|
|
89
|
+
type: z.literal("agent-output"),
|
|
90
|
+
text: z.string(),
|
|
91
|
+
})
|
|
92
|
+
.strict();
|
|
93
|
+
const commandBoundaryMessageSchema = z
|
|
94
|
+
.object({
|
|
95
|
+
type: z.literal("command-boundary"),
|
|
96
|
+
phase: z.enum(["prompt-start", "command-start", "output-start", "command-end"]),
|
|
97
|
+
exitCode: z.number().int().optional(),
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
const rpcResponseMessageSchema = z
|
|
101
|
+
.object({
|
|
102
|
+
type: z.literal("rpc-response"),
|
|
103
|
+
id: z.string().min(1).max(64),
|
|
104
|
+
result: z.unknown().optional(),
|
|
105
|
+
error: z.string().optional(),
|
|
106
|
+
})
|
|
107
|
+
.strict();
|
|
108
|
+
export const serverToClientMessageSchema = z.discriminatedUnion("type", [
|
|
109
|
+
outputMessageSchema,
|
|
110
|
+
exitMessageSchema,
|
|
111
|
+
titleMessageSchema,
|
|
112
|
+
sessionMessageSchema,
|
|
113
|
+
cwdMessageSchema,
|
|
114
|
+
agentOutputMessageSchema,
|
|
115
|
+
commandBoundaryMessageSchema,
|
|
116
|
+
rpcResponseMessageSchema,
|
|
117
|
+
]);
|
|
118
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE;IACf,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;CACzC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,kBAAkB,GAAG,CAAC;KACzB,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,mBAAmB,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACzB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG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AAG,CAAC;KAC/B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,4BAA4B,GAAG,CAAC;KACnC,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC;IACnC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAC/E,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,wBAAwB,GAAG,CAAC;KAC/B,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IAC/B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IAC7B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC9B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACtE,mBAAmB;IACnB,iBAAiB;IACjB,kBAAkB;IAClB,oBAAoB;IACpB,gBAAgB;IAChB,wBAAwB;IACxB,4BAA4B;IAC5B,wBAAwB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context, MiddlewareHandler } from "hono";
|
|
2
|
+
export declare const isLoopbackHost: (host: string) => boolean;
|
|
3
|
+
export declare const enforceLoopback: (context: Context) => Response | null;
|
|
4
|
+
export declare const loopbackMiddleware: MiddlewareHandler;
|
|
5
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAqCvD,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAA8C,CAAC;AAE7F,eAAO,MAAM,eAAe,GAAI,SAAS,OAAO,KAAG,QAAQ,GAAG,IAc7D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,iBAIhC,CAAC"}
|
package/dist/security.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { LOOPBACK_HOSTS } from "./constants.js";
|
|
2
|
+
const stripPort = (hostHeader) => {
|
|
3
|
+
if (!hostHeader)
|
|
4
|
+
return null;
|
|
5
|
+
const trimmed = hostHeader.trim();
|
|
6
|
+
if (!trimmed)
|
|
7
|
+
return null;
|
|
8
|
+
if (trimmed.startsWith("[")) {
|
|
9
|
+
const end = trimmed.indexOf("]");
|
|
10
|
+
return end === -1 ? trimmed : trimmed.slice(0, end + 1);
|
|
11
|
+
}
|
|
12
|
+
if (trimmed.includes(":") && !trimmed.includes("."))
|
|
13
|
+
return `[${trimmed}]`;
|
|
14
|
+
const colon = trimmed.lastIndexOf(":");
|
|
15
|
+
if (colon === -1)
|
|
16
|
+
return trimmed;
|
|
17
|
+
return trimmed.slice(0, colon);
|
|
18
|
+
};
|
|
19
|
+
const originHostname = (originHeader) => {
|
|
20
|
+
if (!originHeader)
|
|
21
|
+
return null;
|
|
22
|
+
if (originHeader === "null")
|
|
23
|
+
return null;
|
|
24
|
+
try {
|
|
25
|
+
return new URL(originHeader).hostname;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const isLoopback = (hostname) => {
|
|
32
|
+
if (!hostname)
|
|
33
|
+
return false;
|
|
34
|
+
if (LOOPBACK_HOSTS.has(hostname))
|
|
35
|
+
return true;
|
|
36
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost"))
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
const normalizeBareIpv6 = (host) => host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
41
|
+
export const isLoopbackHost = (host) => isLoopback(normalizeBareIpv6(host));
|
|
42
|
+
export const enforceLoopback = (context) => {
|
|
43
|
+
const hostHeader = context.req.header("host");
|
|
44
|
+
const hostname = stripPort(hostHeader);
|
|
45
|
+
if (!isLoopback(hostname)) {
|
|
46
|
+
return new Response("forbidden: non-loopback host", { status: 403 });
|
|
47
|
+
}
|
|
48
|
+
const origin = context.req.header("origin");
|
|
49
|
+
if (origin !== undefined) {
|
|
50
|
+
const originHost = originHostname(origin);
|
|
51
|
+
if (!isLoopback(originHost)) {
|
|
52
|
+
return new Response("forbidden: cross-origin", { status: 403 });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
export const loopbackMiddleware = async (context, next) => {
|
|
58
|
+
const blocked = enforceLoopback(context);
|
|
59
|
+
if (blocked)
|
|
60
|
+
return blocked;
|
|
61
|
+
await next();
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,SAAS,GAAG,CAAC,UAA8B,EAAiB,EAAE;IAClE,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;I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C,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,MAAM,IAAI,EAAE,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Session } from "./session.js";
|
|
2
|
+
export declare class SessionRegistry {
|
|
3
|
+
private readonly sessions;
|
|
4
|
+
register(session: Session): void;
|
|
5
|
+
unregister(session: Session): void;
|
|
6
|
+
size(): number;
|
|
7
|
+
disposeAll(): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=session-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-registry.d.ts","sourceRoot":"","sources":["../src/session-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAE/C,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIhC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,IAAI,IAAI,MAAM;IAId,UAAU,IAAI,IAAI;CAMnB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class SessionRegistry {
|
|
2
|
+
sessions = new Set();
|
|
3
|
+
register(session) {
|
|
4
|
+
this.sessions.add(session);
|
|
5
|
+
}
|
|
6
|
+
unregister(session) {
|
|
7
|
+
this.sessions.delete(session);
|
|
8
|
+
}
|
|
9
|
+
size() {
|
|
10
|
+
return this.sessions.size;
|
|
11
|
+
}
|
|
12
|
+
disposeAll() {
|
|
13
|
+
for (const session of this.sessions) {
|
|
14
|
+
session.dispose();
|
|
15
|
+
}
|
|
16
|
+
this.sessions.clear();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=session-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-registry.js","sourceRoot":"","sources":["../src/session-registry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;IACT,QAAQ,GAAG,IAAI,GAAG,EAAW,CAAC;IAE/C,QAAQ,CAAC,OAAgB;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,OAAgB;QACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,UAAU;QACR,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import type { CommandBoundary } from "./utils/parse-osc133-from-chunk.js";
|
|
3
|
+
import type { SpawnPtyInput } from "./types.js";
|
|
4
|
+
interface SessionEvents {
|
|
5
|
+
output: [data: string];
|
|
6
|
+
exit: [code: number | null];
|
|
7
|
+
title: [title: string];
|
|
8
|
+
cwd: [cwd: string];
|
|
9
|
+
commandBoundary: [boundary: CommandBoundary];
|
|
10
|
+
}
|
|
11
|
+
export declare class Session extends EventEmitter<SessionEvents> {
|
|
12
|
+
readonly shell: string;
|
|
13
|
+
readonly cwd: string;
|
|
14
|
+
readonly createdAt: number;
|
|
15
|
+
readonly mode: "human" | "agent";
|
|
16
|
+
private readonly pty;
|
|
17
|
+
private readonly shellName;
|
|
18
|
+
private currentCols;
|
|
19
|
+
private currentRows;
|
|
20
|
+
private exited;
|
|
21
|
+
private paused;
|
|
22
|
+
private titlePollTimer;
|
|
23
|
+
private lastEmittedTitle;
|
|
24
|
+
private lastEmittedCwd;
|
|
25
|
+
private nextCwdResolveAt;
|
|
26
|
+
private osc7Detected;
|
|
27
|
+
private readonly osc7ChunkParser;
|
|
28
|
+
private readonly osc133ChunkParser;
|
|
29
|
+
constructor(input: SpawnPtyInput);
|
|
30
|
+
get pid(): number;
|
|
31
|
+
get shellBaseName(): string;
|
|
32
|
+
get cols(): number;
|
|
33
|
+
get rows(): number;
|
|
34
|
+
get isExited(): boolean;
|
|
35
|
+
get isPaused(): boolean;
|
|
36
|
+
write(data: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Stop reading data from the PTY. node-pty buffers further child output in
|
|
39
|
+
* the OS pipe; once that fills, write() in the child process blocks, which
|
|
40
|
+
* propagates flow control all the way back to the producing program (e.g.
|
|
41
|
+
* `cat large_file`). Used by the WS layer to pause heavy output streams
|
|
42
|
+
* when the outbound socket buffer is filling, so we don't have to kill the
|
|
43
|
+
* connection just to recover memory.
|
|
44
|
+
*/
|
|
45
|
+
pause(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Reverse of `pause()`. Buffered child output starts flowing again and the
|
|
48
|
+
* child process unblocks if it was stuck in write().
|
|
49
|
+
*/
|
|
50
|
+
resume(): void;
|
|
51
|
+
resize(cols: number, rows: number): void;
|
|
52
|
+
kill(signal?: NodeJS.Signals): void;
|
|
53
|
+
dispose(): void;
|
|
54
|
+
private onPtyOutput;
|
|
55
|
+
private scheduleTitlePoll;
|
|
56
|
+
private runTitlePoll;
|
|
57
|
+
private computeTitle;
|
|
58
|
+
private resolveLiveCwd;
|
|
59
|
+
private stopTitlePolling;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuB3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAA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