@theokit/sdk 4.3.0 → 4.4.1
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.
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/interactive/types.ts
|
|
4
|
+
var InteractiveUnavailableError = class extends Error {
|
|
5
|
+
code = "interactive_unavailable";
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "InteractiveUnavailableError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var NoSuchSessionError = class extends Error {
|
|
12
|
+
code = "no_such_session";
|
|
13
|
+
constructor(sessionId) {
|
|
14
|
+
super(`no such live session "${sessionId}" (it may have exited or been killed)`);
|
|
15
|
+
this.name = "NoSuchSessionError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var InteractiveBackend = class {
|
|
19
|
+
};
|
|
20
|
+
async function resolveInteractive(provider, ctx) {
|
|
21
|
+
return provider instanceof InteractiveBackend ? provider : provider(ctx);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.InteractiveBackend = InteractiveBackend;
|
|
25
|
+
exports.InteractiveUnavailableError = InteractiveUnavailableError;
|
|
26
|
+
exports.NoSuchSessionError = NoSuchSessionError;
|
|
27
|
+
exports.resolveInteractive = resolveInteractive;
|
|
28
|
+
//# sourceMappingURL=index.cjs.map
|
|
29
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/interactive/types.ts"],"names":[],"mappings":";;;AAkBO,IAAM,2BAAA,GAAN,cAA0C,KAAA,CAAM;AAAA,EAC5C,IAAA,GAAO,yBAAA;AAAA,EAChB,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,6BAAA;AAAA,EACd;AACF;AAIO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EACnC,IAAA,GAAO,iBAAA;AAAA,EAChB,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA,CAAM,CAAA,sBAAA,EAAyB,SAAS,CAAA,qCAAA,CAAuC,CAAA;AAC/E,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AACF;AA2CO,IAAe,qBAAf,MAAkC;AAmBzC;AAcA,eAAsB,kBAAA,CACpB,UACA,GAAA,EAC6B;AAC7B,EAAA,OAAO,QAAA,YAAoB,kBAAA,GAAqB,QAAA,GAAW,QAAA,CAAS,GAAG,CAAA;AACzE","file":"index.cjs","sourcesContent":["/**\n * Interactive-session backend protocol — the streaming twin of `SandboxBackend`\n * (which is one-shot `execute`). A surface-agnostic contract for driving a\n * long-lived interactive process (a REPL, `git rebase -i`, any command that\n * PROMPTS for stdin): start → `session_id`, write to stdin, read incremental\n * output, kill.\n *\n * Injected exactly like {@link FilesystemProvider} (SE31) — the tool depends on\n * the interface, the HOST supplies the implementation, so the SAME tool runs on\n * a local PTY (`@theokit/sdk-pty`), a container/E2B backend (cluster/web), or a\n * desktop backend (Tauri) with NO tool change and NO native dependency in core.\n *\n * @public\n */\n\n/** Thrown when the interactive path is requested but no backend can provide it\n * (no provider injected, or a local backend whose native module / spawn failed).\n * The caller falls back to non-interactive exec. */\nexport class InteractiveUnavailableError extends Error {\n readonly code = \"interactive_unavailable\" as const;\n constructor(message: string) {\n super(message);\n this.name = \"InteractiveUnavailableError\";\n }\n}\n\n/** Thrown (typed) when a write/kill targets an unknown or already-exited session,\n * so callers branch on the type instead of string-matching a message. */\nexport class NoSuchSessionError extends Error {\n readonly code = \"no_such_session\" as const;\n constructor(sessionId: string) {\n super(`no such live session \"${sessionId}\" (it may have exited or been killed)`);\n this.name = \"NoSuchSessionError\";\n }\n}\n\n/** Result of starting a session: its id + whatever the program printed on startup. */\nexport interface StartInteractiveResult {\n sessionId: string;\n output: string;\n}\n\n/** Result of writing to a session: the output produced during the yield window + liveness. */\nexport interface WriteStdinResult {\n output: string;\n alive: boolean;\n}\n\n/** Bounds a start call. All optional; a backend clamps/defaults each. */\nexport interface StartInteractiveOptions {\n /** Working directory for the session. Defaults to the backend's root. */\n cwd?: string;\n /** How long to wait, in ms, before returning the startup output (clamped by the backend). */\n yieldMs?: number;\n /** Idle time, in ms, after which the backend reaps a forgotten session. */\n ttlMs?: number;\n /** Cap on the returned output bytes (tail kept). */\n maxBytes?: number;\n /** Terminal geometry, when the backend allocates a real TTY. */\n cols?: number;\n rows?: number;\n}\n\n/** Bounds a write call. */\nexport interface WriteStdinOptions {\n yieldMs?: number;\n ttlMs?: number;\n maxBytes?: number;\n}\n\n/**\n * Pluggable interactive-session backend. Implement the three abstract methods.\n * A backend that cannot provide interactive sessions should not be constructed —\n * callers detect absence by catching {@link InteractiveUnavailableError}.\n *\n * @public\n */\nexport abstract class InteractiveBackend {\n /** Spawn `command` as an interactive session; resolve after the yield window with the\n * `session_id` + startup output. Throws {@link InteractiveUnavailableError} when the\n * session cannot be allocated. */\n abstract startInteractive(\n command: string,\n opts?: StartInteractiveOptions,\n ): Promise<StartInteractiveResult>;\n\n /** Write `chars` to a live session's stdin; resolve after the yield window with the output it\n * produced + whether it is still alive. Throws {@link NoSuchSessionError} on an unknown session. */\n abstract writeStdin(\n sessionId: string,\n chars: string,\n opts?: WriteStdinOptions,\n ): Promise<WriteStdinResult>;\n\n /** Kill a session (idempotent) and free its slot. */\n abstract kill(sessionId: string): void;\n}\n\n/**\n * A backend OR a per-request resolver of one — mirrors {@link FilesystemProvider}. A resolver runs\n * at tool-execution time (request scope), so multi-tenant / multi-role agents get a distinct backend\n * per request without a shared mutable one.\n *\n * @public\n */\nexport type InteractiveProvider<Ctx = unknown> =\n | InteractiveBackend\n | ((ctx: Ctx) => InteractiveBackend | Promise<InteractiveBackend>);\n\n/** Resolve an {@link InteractiveProvider} to a concrete backend for `ctx`. */\nexport async function resolveInteractive<Ctx>(\n provider: InteractiveProvider<Ctx>,\n ctx: Ctx,\n): Promise<InteractiveBackend> {\n return provider instanceof InteractiveBackend ? provider : provider(ctx);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@theokit/sdk/interactive` — pluggable interactive-session backend seam.
|
|
3
|
+
*
|
|
4
|
+
* The streaming twin of `@theokit/sdk/sandbox` (one-shot `execute`) and sibling
|
|
5
|
+
* of `@theokit/sdk/filesystem`. Ship an `InteractiveBackend` (e.g. the local
|
|
6
|
+
* `@theokit/sdk-pty`, a container/E2B backend for the cluster, or a Tauri
|
|
7
|
+
* backend) to give agent shell tools a surface-agnostic REPL/stdin capability —
|
|
8
|
+
* with NO native dependency in core.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export { InteractiveBackend, type InteractiveProvider, InteractiveUnavailableError, NoSuchSessionError, resolveInteractive, type StartInteractiveOptions, type StartInteractiveResult, type WriteStdinOptions, type WriteStdinResult, } from "./types.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/interactive/types.ts
|
|
2
|
+
var InteractiveUnavailableError = class extends Error {
|
|
3
|
+
code = "interactive_unavailable";
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "InteractiveUnavailableError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var NoSuchSessionError = class extends Error {
|
|
10
|
+
code = "no_such_session";
|
|
11
|
+
constructor(sessionId) {
|
|
12
|
+
super(`no such live session "${sessionId}" (it may have exited or been killed)`);
|
|
13
|
+
this.name = "NoSuchSessionError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var InteractiveBackend = class {
|
|
17
|
+
};
|
|
18
|
+
async function resolveInteractive(provider, ctx) {
|
|
19
|
+
return provider instanceof InteractiveBackend ? provider : provider(ctx);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { InteractiveBackend, InteractiveUnavailableError, NoSuchSessionError, resolveInteractive };
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/interactive/types.ts"],"names":[],"mappings":";AAkBO,IAAM,2BAAA,GAAN,cAA0C,KAAA,CAAM;AAAA,EAC5C,IAAA,GAAO,yBAAA;AAAA,EAChB,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,6BAAA;AAAA,EACd;AACF;AAIO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EACnC,IAAA,GAAO,iBAAA;AAAA,EAChB,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA,CAAM,CAAA,sBAAA,EAAyB,SAAS,CAAA,qCAAA,CAAuC,CAAA;AAC/E,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACd;AACF;AA2CO,IAAe,qBAAf,MAAkC;AAmBzC;AAcA,eAAsB,kBAAA,CACpB,UACA,GAAA,EAC6B;AAC7B,EAAA,OAAO,QAAA,YAAoB,kBAAA,GAAqB,QAAA,GAAW,QAAA,CAAS,GAAG,CAAA;AACzE","file":"index.js","sourcesContent":["/**\n * Interactive-session backend protocol — the streaming twin of `SandboxBackend`\n * (which is one-shot `execute`). A surface-agnostic contract for driving a\n * long-lived interactive process (a REPL, `git rebase -i`, any command that\n * PROMPTS for stdin): start → `session_id`, write to stdin, read incremental\n * output, kill.\n *\n * Injected exactly like {@link FilesystemProvider} (SE31) — the tool depends on\n * the interface, the HOST supplies the implementation, so the SAME tool runs on\n * a local PTY (`@theokit/sdk-pty`), a container/E2B backend (cluster/web), or a\n * desktop backend (Tauri) with NO tool change and NO native dependency in core.\n *\n * @public\n */\n\n/** Thrown when the interactive path is requested but no backend can provide it\n * (no provider injected, or a local backend whose native module / spawn failed).\n * The caller falls back to non-interactive exec. */\nexport class InteractiveUnavailableError extends Error {\n readonly code = \"interactive_unavailable\" as const;\n constructor(message: string) {\n super(message);\n this.name = \"InteractiveUnavailableError\";\n }\n}\n\n/** Thrown (typed) when a write/kill targets an unknown or already-exited session,\n * so callers branch on the type instead of string-matching a message. */\nexport class NoSuchSessionError extends Error {\n readonly code = \"no_such_session\" as const;\n constructor(sessionId: string) {\n super(`no such live session \"${sessionId}\" (it may have exited or been killed)`);\n this.name = \"NoSuchSessionError\";\n }\n}\n\n/** Result of starting a session: its id + whatever the program printed on startup. */\nexport interface StartInteractiveResult {\n sessionId: string;\n output: string;\n}\n\n/** Result of writing to a session: the output produced during the yield window + liveness. */\nexport interface WriteStdinResult {\n output: string;\n alive: boolean;\n}\n\n/** Bounds a start call. All optional; a backend clamps/defaults each. */\nexport interface StartInteractiveOptions {\n /** Working directory for the session. Defaults to the backend's root. */\n cwd?: string;\n /** How long to wait, in ms, before returning the startup output (clamped by the backend). */\n yieldMs?: number;\n /** Idle time, in ms, after which the backend reaps a forgotten session. */\n ttlMs?: number;\n /** Cap on the returned output bytes (tail kept). */\n maxBytes?: number;\n /** Terminal geometry, when the backend allocates a real TTY. */\n cols?: number;\n rows?: number;\n}\n\n/** Bounds a write call. */\nexport interface WriteStdinOptions {\n yieldMs?: number;\n ttlMs?: number;\n maxBytes?: number;\n}\n\n/**\n * Pluggable interactive-session backend. Implement the three abstract methods.\n * A backend that cannot provide interactive sessions should not be constructed —\n * callers detect absence by catching {@link InteractiveUnavailableError}.\n *\n * @public\n */\nexport abstract class InteractiveBackend {\n /** Spawn `command` as an interactive session; resolve after the yield window with the\n * `session_id` + startup output. Throws {@link InteractiveUnavailableError} when the\n * session cannot be allocated. */\n abstract startInteractive(\n command: string,\n opts?: StartInteractiveOptions,\n ): Promise<StartInteractiveResult>;\n\n /** Write `chars` to a live session's stdin; resolve after the yield window with the output it\n * produced + whether it is still alive. Throws {@link NoSuchSessionError} on an unknown session. */\n abstract writeStdin(\n sessionId: string,\n chars: string,\n opts?: WriteStdinOptions,\n ): Promise<WriteStdinResult>;\n\n /** Kill a session (idempotent) and free its slot. */\n abstract kill(sessionId: string): void;\n}\n\n/**\n * A backend OR a per-request resolver of one — mirrors {@link FilesystemProvider}. A resolver runs\n * at tool-execution time (request scope), so multi-tenant / multi-role agents get a distinct backend\n * per request without a shared mutable one.\n *\n * @public\n */\nexport type InteractiveProvider<Ctx = unknown> =\n | InteractiveBackend\n | ((ctx: Ctx) => InteractiveBackend | Promise<InteractiveBackend>);\n\n/** Resolve an {@link InteractiveProvider} to a concrete backend for `ctx`. */\nexport async function resolveInteractive<Ctx>(\n provider: InteractiveProvider<Ctx>,\n ctx: Ctx,\n): Promise<InteractiveBackend> {\n return provider instanceof InteractiveBackend ? provider : provider(ctx);\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive-session backend protocol — the streaming twin of `SandboxBackend`
|
|
3
|
+
* (which is one-shot `execute`). A surface-agnostic contract for driving a
|
|
4
|
+
* long-lived interactive process (a REPL, `git rebase -i`, any command that
|
|
5
|
+
* PROMPTS for stdin): start → `session_id`, write to stdin, read incremental
|
|
6
|
+
* output, kill.
|
|
7
|
+
*
|
|
8
|
+
* Injected exactly like {@link FilesystemProvider} (SE31) — the tool depends on
|
|
9
|
+
* the interface, the HOST supplies the implementation, so the SAME tool runs on
|
|
10
|
+
* a local PTY (`@theokit/sdk-pty`), a container/E2B backend (cluster/web), or a
|
|
11
|
+
* desktop backend (Tauri) with NO tool change and NO native dependency in core.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
/** Thrown when the interactive path is requested but no backend can provide it
|
|
16
|
+
* (no provider injected, or a local backend whose native module / spawn failed).
|
|
17
|
+
* The caller falls back to non-interactive exec. */
|
|
18
|
+
export declare class InteractiveUnavailableError extends Error {
|
|
19
|
+
readonly code: "interactive_unavailable";
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/** Thrown (typed) when a write/kill targets an unknown or already-exited session,
|
|
23
|
+
* so callers branch on the type instead of string-matching a message. */
|
|
24
|
+
export declare class NoSuchSessionError extends Error {
|
|
25
|
+
readonly code: "no_such_session";
|
|
26
|
+
constructor(sessionId: string);
|
|
27
|
+
}
|
|
28
|
+
/** Result of starting a session: its id + whatever the program printed on startup. */
|
|
29
|
+
export interface StartInteractiveResult {
|
|
30
|
+
sessionId: string;
|
|
31
|
+
output: string;
|
|
32
|
+
}
|
|
33
|
+
/** Result of writing to a session: the output produced during the yield window + liveness. */
|
|
34
|
+
export interface WriteStdinResult {
|
|
35
|
+
output: string;
|
|
36
|
+
alive: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Bounds a start call. All optional; a backend clamps/defaults each. */
|
|
39
|
+
export interface StartInteractiveOptions {
|
|
40
|
+
/** Working directory for the session. Defaults to the backend's root. */
|
|
41
|
+
cwd?: string;
|
|
42
|
+
/** How long to wait, in ms, before returning the startup output (clamped by the backend). */
|
|
43
|
+
yieldMs?: number;
|
|
44
|
+
/** Idle time, in ms, after which the backend reaps a forgotten session. */
|
|
45
|
+
ttlMs?: number;
|
|
46
|
+
/** Cap on the returned output bytes (tail kept). */
|
|
47
|
+
maxBytes?: number;
|
|
48
|
+
/** Terminal geometry, when the backend allocates a real TTY. */
|
|
49
|
+
cols?: number;
|
|
50
|
+
rows?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Bounds a write call. */
|
|
53
|
+
export interface WriteStdinOptions {
|
|
54
|
+
yieldMs?: number;
|
|
55
|
+
ttlMs?: number;
|
|
56
|
+
maxBytes?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Pluggable interactive-session backend. Implement the three abstract methods.
|
|
60
|
+
* A backend that cannot provide interactive sessions should not be constructed —
|
|
61
|
+
* callers detect absence by catching {@link InteractiveUnavailableError}.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export declare abstract class InteractiveBackend {
|
|
66
|
+
/** Spawn `command` as an interactive session; resolve after the yield window with the
|
|
67
|
+
* `session_id` + startup output. Throws {@link InteractiveUnavailableError} when the
|
|
68
|
+
* session cannot be allocated. */
|
|
69
|
+
abstract startInteractive(command: string, opts?: StartInteractiveOptions): Promise<StartInteractiveResult>;
|
|
70
|
+
/** Write `chars` to a live session's stdin; resolve after the yield window with the output it
|
|
71
|
+
* produced + whether it is still alive. Throws {@link NoSuchSessionError} on an unknown session. */
|
|
72
|
+
abstract writeStdin(sessionId: string, chars: string, opts?: WriteStdinOptions): Promise<WriteStdinResult>;
|
|
73
|
+
/** Kill a session (idempotent) and free its slot. */
|
|
74
|
+
abstract kill(sessionId: string): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A backend OR a per-request resolver of one — mirrors {@link FilesystemProvider}. A resolver runs
|
|
78
|
+
* at tool-execution time (request scope), so multi-tenant / multi-role agents get a distinct backend
|
|
79
|
+
* per request without a shared mutable one.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export type InteractiveProvider<Ctx = unknown> = InteractiveBackend | ((ctx: Ctx) => InteractiveBackend | Promise<InteractiveBackend>);
|
|
84
|
+
/** Resolve an {@link InteractiveProvider} to a concrete backend for `ctx`. */
|
|
85
|
+
export declare function resolveInteractive<Ctx>(provider: InteractiveProvider<Ctx>, ctx: Ctx): Promise<InteractiveBackend>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theokit/sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "TypeScript SDK for the Theo agent harness — same surface, local or cloud.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/usetheodev/theokit-sdk#readme",
|
|
@@ -278,6 +278,16 @@
|
|
|
278
278
|
"default": "./dist/filesystem/index.cjs"
|
|
279
279
|
}
|
|
280
280
|
},
|
|
281
|
+
"./interactive": {
|
|
282
|
+
"import": {
|
|
283
|
+
"types": "./dist/interactive/index.d.ts",
|
|
284
|
+
"default": "./dist/interactive/index.js"
|
|
285
|
+
},
|
|
286
|
+
"require": {
|
|
287
|
+
"types": "./dist/interactive/index.d.cts",
|
|
288
|
+
"default": "./dist/interactive/index.cjs"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
281
291
|
"./package.json": "./package.json"
|
|
282
292
|
},
|
|
283
293
|
"files": [
|