@threahq/remote-session 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/lifecycle.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { ShutdownOptions } from "./session.js";
2
+ /** The slice of `process` the lifecycle wiring touches, narrowed so it can be unit-tested with a fake. */
3
+ export interface LifecycleProcess {
4
+ /** The host's pid, read once at wiring: after the host dies, `process.ppid` names whoever adopted us. */
5
+ ppid: number;
6
+ on(event: string, listener: (arg?: unknown) => void): unknown;
7
+ stdin: {
8
+ on(event: string, listener: (arg?: unknown) => void): unknown;
9
+ };
10
+ stderr: {
11
+ write(chunk: string): unknown;
12
+ };
13
+ exit(code: number): never;
14
+ }
15
+ export interface LifecycleOptions {
16
+ /** Prefix for shutdown log lines, e.g. "[threa-channel]". */
17
+ logPrefix?: string;
18
+ /** Bound on teardown so a hung Threa request can't hold the process past its host's kill grace window. */
19
+ exitGuardMs?: number;
20
+ /** Is the process with this pid still running? Decides whether a closed stdin is the host's death or its choice. */
21
+ parentAlive?: (pid: number) => boolean;
22
+ /** Wait before probing the parent: a host that was just killed may not be reaped yet. */
23
+ parentProbeDelayMs?: number;
24
+ }
25
+ /**
26
+ * Route every way the process can die through one graceful teardown, so the
27
+ * session marks presence offline + fails its in-flight claim instead of just
28
+ * vanishing. A host runtime typically never respawns a dead stdio child
29
+ * mid-session, so a silent drop strands the scratchpad as "busy" with nobody to
30
+ * answer until a human restarts. The paths covered:
31
+ * - SIGINT/SIGTERM — the host's normal stop, and a 2nd Ctrl-C.
32
+ * - SIGHUP — terminal/SSH/tmux disconnect (previously an unhandled hard kill).
33
+ * - stdin end/close — the parent's write end closed: the host exited, was
34
+ * killed, or was swapped out by an auto-update. The session we serve is gone,
35
+ * so exit rather than linger as an orphan that keeps renewing the claim.
36
+ * - uncaughtException/unhandledRejection — a steady-state throw would otherwise
37
+ * vanish the process with no log and no cleanup; log it and exit non-zero.
38
+ */
39
+ export declare function wireLifecycle(server: {
40
+ shutdown(options?: ShutdownOptions): Promise<void>;
41
+ }, host: LifecycleProcess, options?: LifecycleOptions): void;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@threahq/remote-session",
3
+ "version": "0.1.0",
4
+ "description": "SDK for connecting an interactive agent runtime to a Threa scratchpad: session linking, claiming work, presence and claim renewal, /steer and /stop, attachments, and interim or final replies. A connector implements deliverTurn; the SDK runs the loop.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/threahq/threa.git",
9
+ "directory": "extensions/remote-session"
10
+ },
11
+ "homepage": "https://threa.io/developers",
12
+ "bugs": {
13
+ "url": "https://github.com/threahq/threa/issues"
14
+ },
15
+ "keywords": [
16
+ "threa",
17
+ "bot",
18
+ "agent",
19
+ "runtime",
20
+ "connector",
21
+ "sdk"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "main": "./index.js",
26
+ "types": "./index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./index.d.ts",
30
+ "import": "./index.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "dependencies": {
38
+ "@threahq/bot-runtime-client": "^0.1.0",
39
+ "socket.io-client": "^4.8.1"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }