@deepseek-ai/dsh-ptc-runtime-node 0.2.1-rc.3 → 0.2.2-alpha.2

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.
@@ -1,5 +1,5 @@
1
1
  import type { PtcBindingFunction, PtcBindingNamespace, PtcJsonValue, PtcRunRequest } from '@deepseek-ai/dsh-ptc-runtime';
2
- import type { ReplyMessage } from './protocol.ts';
2
+ import { type PtcJsonWire } from './json-wire.ts';
3
3
  /**
4
4
  * Reject unusable namespaces before starting a process.
5
5
  * @param request - Host-owned binding declarations.
@@ -7,11 +7,10 @@ import type { ReplyMessage } from './protocol.ts';
7
7
  */
8
8
  export declare function validateBindings(request: PtcRunRequest): Map<string, PtcBindingNamespace>;
9
9
  /**
10
- * Invoke a host binding and encode its lossless result or bounded-channel rejection.
11
- * @param id - Program-issued correlation identifier.
12
- * @param binding - Current evaluation's declared function, absent if it was removed.
10
+ * Invoke a host binding and encode its lossless result.
11
+ * @param binding - Current evaluation's function, absent if it was removed.
13
12
  * @param args - Validated JSON arguments detached from the program.
14
- * @returns A reply suitable for the runtime's bounded control channel.
13
+ * @returns Flat lossless JSON; unavailable bindings and invalid results reject.
15
14
  */
16
- export declare function replyToBinding(id: number, binding: PtcBindingFunction | undefined, args: PtcJsonValue): Promise<ReplyMessage>;
15
+ export declare function invokeBinding(binding: PtcBindingFunction | undefined, args: PtcJsonValue): Promise<PtcJsonWire>;
17
16
  //# sourceMappingURL=bindings.d.ts.map
@@ -1,13 +1,8 @@
1
1
  /**
2
- * Program evaluation, output capture, and host binding proxies over the process channel.
2
+ * Output capture, result encoding, and host binding proxies over the process channel.
3
3
  * @module @deepseek-ai/dsh-ptc-runtime-node/src/bootstrap
4
4
  */
5
- import type { DoneMessage, ReplyMessage, ProgramBootData, ProgramToHost } from './protocol.ts';
6
- /** Program messages and host replies transported by the private process channel. */
7
- export interface BootstrapPort {
8
- postMessage(message: ProgramToHost): void;
9
- on(event: 'message', listener: (message: ReplyMessage) => void): void;
10
- }
5
+ import type { HostMethods, ProgramResult, ProgramBootData } from './protocol.ts';
11
6
  /**
12
7
  * A writable stream's `write` slot, as the bootstrap patches it (see
13
8
  * {@link captureStreamWrites}). Method-typed so the real
@@ -19,7 +14,7 @@ export interface PatchableStream {
19
14
  }
20
15
  /**
21
16
  * Ordered text capture under the shared outer JSON-byte budget, delivered to
22
- * a sink as each item lands (the real sink streams text over the port eagerly,
17
+ * a sink as each item lands (the real sink sends text to the host eagerly,
23
18
  * so captured output survives a mid-run termination). It includes the log
24
19
  * array syntax and string escaping in its accounting. Once exhausted it emits
25
20
  * the fitting prefix and reports the limit once; the host turns that condition
@@ -67,7 +62,7 @@ export declare function makeConsoleShim(logs: Pick<LogBuffer, 'push'>): Record<(
67
62
  */
68
63
  export declare function captureStreamWrites(logs: Pick<LogBuffer, 'push'>, stream: PatchableStream): () => void;
69
64
  /**
70
- * Prepare the program's completion value for the done message. Only lossless
65
+ * Prepare the program's completion value for the run result. Only lossless
71
66
  * JSON crosses, and a value that does not fit the remaining combined outer
72
67
  * budget reports `output-limit`; the host revalidates hostile traffic and
73
68
  * remains authoritative for native pipe writes the program shim cannot observe.
@@ -75,23 +70,18 @@ export declare function captureStreamWrites(logs: Pick<LogBuffer, 'push'>, strea
75
70
  * @param value - the program's completion value.
76
71
  * @param remainingOutputBytes - exact bytes left after captured logs.
77
72
  * @param maxOutputBytes - the configured cap named in an overflow diagnostic.
78
- * @returns the done-message fragment: `{}` for `undefined`, else a flat wire `{ value }`.
73
+ * @returns the result fragment: `{}` for `undefined`, else a flat wire `{ value }`.
79
74
  */
80
- export declare function prepareCompletion(value: unknown, remainingOutputBytes: number, maxOutputBytes?: number): Omit<DoneMessage, 'type'>;
75
+ export declare function prepareCompletion(value: unknown, remainingOutputBytes: number, maxOutputBytes?: number): ProgramResult;
81
76
  /**
82
- * Prepare a thrown program value without sending an unbounded stack or
83
- * string across the process channel.
77
+ * Prepare a thrown program value, including cross-realm errors, without sending
78
+ * an unbounded stack or string across the process channel.
84
79
  * @param error - the value thrown by the program.
85
80
  * @param remainingOutputBytes - exact bytes left after captured logs.
86
81
  * @param maxOutputBytes - the configured cap named in an overflow diagnostic.
87
82
  * @returns a bounded exception or fixed output-limit fragment.
88
83
  */
89
- export declare function prepareException(error: unknown, remainingOutputBytes: number, maxOutputBytes?: number): Omit<DoneMessage, 'type'>;
90
- /** One awaited binding call's settlement handles, keyed by call id in the pending map. */
91
- export interface PendingCall {
92
- resolve(value: unknown): void;
93
- reject(error: Error): void;
94
- }
84
+ export declare function prepareException(error: unknown, remainingOutputBytes: number, maxOutputBytes?: number): ProgramResult;
95
85
  /** Constructor type for one program-visible binding rejection class. */
96
86
  export type BindingErrorConstructor = new (memberName: string, message: string) => Error;
97
87
  /**
@@ -104,49 +94,12 @@ export declare function makeBindingErrorClass(descriptor: {
104
94
  memberNameProperty: string;
105
95
  }): BindingErrorConstructor;
106
96
  /**
107
- * Build each declared error class once so calls and `instanceof` share constructor identity.
108
- * @param data - binding namespace declarations from the boot payload.
109
- * @returns constructors keyed by their owning namespace global.
110
- */
111
- export declare function makeBindingErrorClasses(data: Pick<ProgramBootData, 'namespaces'>): Map<string, BindingErrorConstructor>;
112
- /**
113
- * Route host replies into the pending-call map: each reply settles its call
114
- * at most once, and a reply for an unknown id (stray, or a duplicate answer
115
- * to an id already settled) is ignored. Shared wiring between
116
- * {@link runProgram} and the tests that exercise {@link makeNamespaces}
117
- * standalone.
118
- * @param port - the port whose `message` events carry the replies.
119
- * @param pending - the id-keyed map of unsettled binding calls.
120
- */
121
- export declare function wireReplies(port: BootstrapPort, pending: Map<number, PendingCall>): void;
122
- /**
123
- * Build the binding namespace objects the program sees: one null-prototype global per
124
- * namespace, each declared name an own enumerable async function that bridges over the port
125
- * (`__proto__`/`constructor`/`toString` are ordinary keys, never prototype collisions).
126
- * Lossy arguments reject before posting; clone failures and host failure
127
- * replies reject only the corresponding call.
128
- *
129
- * @param data - the boot payload's namespace declarations (globals + names).
130
- * @param port - the port binding calls are posted to.
131
- * @param pending - the id-keyed map each posted call parks its handles in.
132
- * @param nextId - the shared mutable id counter (program-issued correlation ids).
133
- * @param errorClasses - Namespace constructors shared with program globals, resolved for each invocation.
134
- * @returns one namespace object per declaration, in declaration order.
135
- */
136
- export declare function makeNamespaces(data: Pick<ProgramBootData, 'namespaces'>, port: BootstrapPort, pending: Map<number, PendingCall>, nextId: {
137
- value: number;
138
- }, errorClasses?: Pick<ReadonlyMap<string, BindingErrorConstructor>, 'get'>): Record<string, unknown>[];
139
- /**
140
- * Run one strict async-function body, allowing top-level `await` and `return`, and post exactly
141
- * one terminal {@link DoneMessage}; a thrown program error becomes its `error` field.
142
- * @param port - host message port or test double.
143
- * @param data - the boot payload the host sent.
144
- * @param streams - stdout/stderr objects captured as program logs.
145
- * @returns after posting the done message.
97
+ * Build null-prototype binding globals with namespace-specific rejection classes.
98
+ * @param data - Namespace declarations injected into the program.
99
+ * @param host - Evaluation-scoped remote binding calls.
100
+ * @param errorClasses - Constructors shared with program globals, resolved per invocation.
101
+ * @returns One namespace object per declaration; arguments and results must be lossless JSON.
146
102
  */
147
- export declare function runProgram(port: BootstrapPort, data: ProgramBootData, streams: {
148
- stdout: PatchableStream;
149
- stderr: PatchableStream;
150
- }): Promise<void>;
103
+ export declare function makeNamespaces(data: Pick<ProgramBootData, 'namespaces'>, host: Pick<HostMethods, 'invoke'>, errorClasses: Pick<ReadonlyMap<string, BindingErrorConstructor>, 'get'>): Record<string, unknown>[];
151
104
  export {};
152
105
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -5,8 +5,10 @@ import type { LaunchConfig } from './launch.ts';
5
5
  export interface Config {
6
6
  /** Worker invocation in the subprocess world; omitted selects the local carrier. */
7
7
  launch?: LaunchConfig;
8
- /** per-call starts fresh processes; persistent-in-memory retains a REPL per owner under the same file policy. */
9
- executionMode?: 'per-call' | 'persistent-in-memory';
8
+ /** per-call uses fresh async function bodies; vm-script uses VM contexts; persistent-in-memory retains a REPL per owner. */
9
+ executionMode?: 'per-call' | 'persistent-in-memory' | 'vm-script';
10
+ /** Retain a Script process and context per stateOwner; only supported with executionMode: vm-script. */
11
+ scriptPersistence?: boolean;
10
12
  /** Default elapsed deadline, including nested tool and approval waits. */
11
13
  timeoutMs?: number;
12
14
  /** Maximum numeric elapsed budget accepted by resolve. */
@@ -15,7 +17,7 @@ export interface Config {
15
17
  maxOutputBytes?: number;
16
18
  /** V8 old-generation heap limit in MiB; native allocations are excluded. */
17
19
  maxOldGenerationSizeMb?: number;
18
- /** Maximum control frame, outstanding argument and queued control-output bytes. */
20
+ /** Maximum control message, outstanding binding-argument and queued control-output bytes. */
19
21
  maxMessageBytes?: number;
20
22
  /** Maximum simultaneous host binding calls accepted from a program. */
21
23
  maxPendingCalls?: number;
@@ -0,0 +1,10 @@
1
+ /** Pure configuration changes for Node PTC profile editors. */
2
+ import type { PtcProgramFormat } from '@deepseek-ai/dsh-ptc-runtime';
3
+ import type { Config } from './config.ts';
4
+ /**
5
+ * Select retained Node execution while preserving Script syntax.
6
+ * @param programFormat - Effective syntax; omission uses the Node provider's default function-body syntax.
7
+ * @returns Both execution settings to merge into the profile atomically; function bodies switch to the retained REPL.
8
+ */
9
+ export declare function resolvePersistentExecution(programFormat?: PtcProgramFormat): Pick<Required<Config>, 'executionMode' | 'scriptPersistence'>;
10
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,8 @@
1
+ /** Strict async-function-body evaluation with host bindings as parameters. */
2
+ import type { ProgramEvaluator } from './types.ts';
3
+ /**
4
+ * Create an evaluator whose function-local declarations end with each call.
5
+ * @returns Binding globals, asynchronous evaluation and resource cleanup.
6
+ */
7
+ export declare function createAsyncFunctionEvaluator(): ProgramEvaluator;
8
+ //# sourceMappingURL=async-function.d.ts.map
@@ -0,0 +1,11 @@
1
+ /** Select one child evaluator without process-lifetime policy. */
2
+ import type { PtcProgramFormat } from '@deepseek-ai/dsh-ptc-runtime';
3
+ import type { ProgramEvaluator } from './types.ts';
4
+ /**
5
+ * Create the selected evaluator for either a fresh or retained process.
6
+ * @param format - Evaluation syntax selected by the host.
7
+ * @param reportError - Asynchronous diagnostics attributed to the active evaluation.
8
+ * @returns Globals, evaluation entry point, and resource cleanup.
9
+ */
10
+ export declare function createProgramEvaluator(format: PtcProgramFormat, reportError: (message: string) => void): ProgramEvaluator;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { ProgramEvaluator } from './types.ts';
2
+ /**
3
+ * Create a REPL whose globals survive sequential evaluations until close.
4
+ * @param reportError - REPL diagnostics attributed to the active evaluation.
5
+ * @returns Retained globals, asynchronous evaluation and REPL cleanup.
6
+ */
7
+ export declare function createReplEvaluator(reportError: (message: string) => void): ProgramEvaluator;
8
+ //# sourceMappingURL=repl.d.ts.map
@@ -0,0 +1,24 @@
1
+ /** Evaluation results and operations shared by the three child evaluators. */
2
+ /** One evaluation's completion or thrown value. */
3
+ type EvaluationResult = {
4
+ ok: true;
5
+ value: unknown;
6
+ } | {
7
+ ok: false;
8
+ error: unknown;
9
+ };
10
+ /** Program globals and resources owned by one evaluator. */
11
+ export interface ProgramEvaluator {
12
+ /** Mutable globals populated with the current evaluation's bindings. */
13
+ globals: Record<string, unknown>;
14
+ /**
15
+ * Evaluate source and deliver its result after any supported asynchronous work.
16
+ * @param code - Type-stripped program in the selected syntax.
17
+ * @param finish - Callback receiving the completion or exception.
18
+ */
19
+ evaluate(code: string, finish: (result: EvaluationResult) => void): void;
20
+ /** Release evaluator-owned resources after evaluation or process shutdown. */
21
+ close(): void;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Transform top-level await using Node's retained-declaration and boxed-result convention.
3
+ * @param src - Type-stripped JavaScript ending in a newline, with any hashbang removed.
4
+ * @returns Transformed source yielding undefined or { value }, or null when native errors apply.
5
+ * @throws SyntaxError for invalid syntax or unsupported top-level disposable bindings.
6
+ */
7
+ export declare function processTopLevelAwait(src: string): string | null;
8
+ //# sourceMappingURL=vm-script-await.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { ProgramEvaluator } from './types.ts';
2
+ /**
3
+ * Create a VM context supporting Script completion values and top-level await.
4
+ * @returns Retained globals, asynchronous evaluation and resource cleanup.
5
+ */
6
+ export declare function createVmScriptEvaluator(): ProgramEvaluator;
7
+ //# sourceMappingURL=vm-script.d.ts.map
@@ -0,0 +1,66 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { PtcProgramFormat, PtcRunRequest, PtcRunResult, PtcRunSpec } from '@deepseek-ai/dsh-ptc-runtime';
3
+ import type { ResolvedConfig } from './config.ts';
4
+ import type { PolicyProcesses } from './policy-processes.ts';
5
+ /** Syntax, state retention and model guidance selected during provider construction. */
6
+ export interface ExecutionMode {
7
+ /** Child evaluator selected independently of process lifetime. */
8
+ readonly format: PtcProgramFormat;
9
+ /** Whether caller-owned objects retain processes between runs. */
10
+ readonly retainsState: boolean;
11
+ /** Model-facing syntax, output and recovery rules. */
12
+ readonly executionInstructions: string;
13
+ /**
14
+ * Erase TypeScript in the selected syntax without executing the program.
15
+ * @param program - Model-written TypeScript source.
16
+ * @returns JavaScript accepted by the selected evaluator.
17
+ */
18
+ stripTypes(program: string): string;
19
+ }
20
+ /**
21
+ * Select program semantics and create their shared process owner.
22
+ * @param ctx - Provider lifecycle and execution services.
23
+ * @param config - Validated configuration with loader defaults.
24
+ * @param processes - Policy invalidation and process cleanup coordination.
25
+ * @returns Mode selection and temporary or retained execution through one process implementation.
26
+ */
27
+ export declare function createExecution(ctx: Context, config: ResolvedConfig, processes: PolicyProcesses): NodeExecution;
28
+ /** Temporary processes and optional object-owned reuse share one process implementation. */
29
+ declare class NodeExecution {
30
+ private readonly ctx;
31
+ private readonly config;
32
+ private readonly processes;
33
+ readonly mode: ExecutionMode;
34
+ private readonly owners;
35
+ private readonly workers;
36
+ /**
37
+ * Own process instances and optional owner lookup for one provider.
38
+ * @param ctx - Provider lifecycle and execution services.
39
+ * @param config - Validated limits and selected executable.
40
+ * @param processes - Provider-owned policy invalidation and cleanup.
41
+ * @param mode - Program syntax and TypeScript erasure.
42
+ */
43
+ constructor(ctx: Context, config: ResolvedConfig, processes: PolicyProcesses, mode: ExecutionMode);
44
+ /** Stop every owned process, retaining failed cleanup for a later retry. */
45
+ dispose(): Promise<void>;
46
+ /**
47
+ * Resolve the common file policy, directory and deadline defaults.
48
+ * @param request - Program, bindings, owner, directory and elapsed budget.
49
+ * @returns Resolved inputs with the selected file policy.
50
+ */
51
+ resolve(request: PtcRunRequest): PtcRunSpec;
52
+ /**
53
+ * Evaluate in a temporary process or reuse an enabled state owner's process.
54
+ * @param spec - Resolved request; concurrent calls for one owner are rejected.
55
+ * @returns Captured logs, JSON completion, or a structured execution failure.
56
+ */
57
+ run(spec: PtcRunSpec): Promise<PtcRunResult>;
58
+ /**
59
+ * Release retained state and await its process cleanup.
60
+ * @param owner - Exact object supplied to run.
61
+ * @returns Completion after the owned process and output streams stop.
62
+ */
63
+ release(owner: object): Promise<void>;
64
+ }
65
+ export {};
66
+ //# sourceMappingURL=execution.d.ts.map
@@ -1,6 +1,7 @@
1
+ /** Node PTC provider with uniform admission and configurable evaluation and process ownership. */
1
2
  import { Context } from '@deepseek-ai/cordis';
2
3
  import { PtcRuntime } from '@deepseek-ai/dsh-ptc-runtime';
3
- import type { PtcRunRequest, PtcRunResult, PtcRunSpec } from '@deepseek-ai/dsh-ptc-runtime';
4
+ import type { PtcProgramFormat, PtcRunRequest, PtcRunResult, PtcRunSpec } from '@deepseek-ai/dsh-ptc-runtime';
4
5
  import type { SandboxMode } from '@deepseek-ai/dsh-sandbox';
5
6
  import type { Config } from './config.ts';
6
7
  export type { Config } from './config.ts';
@@ -11,9 +12,10 @@ export declare class NodePtcRuntime extends PtcRuntime {
11
12
  static Config: import("@deepseek-ai/schemastery").default<Config>;
12
13
  readonly language = "typescript";
13
14
  readonly isolation = "process";
14
- private readonly inMemory?;
15
+ private readonly execution;
15
16
  private readonly processes;
16
- get programFormat(): 'function-body' | 'repl';
17
+ get programFormat(): PtcProgramFormat;
18
+ get retainsState(): boolean;
17
19
  get executionInstructions(): string;
18
20
  private readonly config;
19
21
  private readonly live;
@@ -38,7 +40,6 @@ export declare class NodePtcRuntime extends PtcRuntime {
38
40
  * @returns Logs, JSON completion or failure; retained processes remain until release or invalidation.
39
41
  */
40
42
  run(spec: PtcRunSpec): Promise<PtcRunResult>;
41
- private execute;
42
43
  }
43
44
  export default NodePtcRuntime;
44
45
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Lossless-JSON snapshots for the dependency-free source bootstrap closure.
2
+ * Lossless-JSON snapshots shared by the host and the source bootstrap closure.
3
3
  * @module @deepseek-ai/dsh-ptc-runtime-node/json-wire
4
4
  */
5
5
  import type { PtcJsonValue } from '@deepseek-ai/dsh-ptc-runtime';
@@ -24,7 +24,7 @@ export declare function resolveLaunch(config?: LaunchConfig): LaunchConfig;
24
24
  * @param fs - Filesystem mapping host bootstrap assets into the process world.
25
25
  * @param config - resolved worker invocation.
26
26
  * @param maxMessageBytes - Validated frame and queued-write limit.
27
- * @param persistent - Select the in-memory REPL bootstrap instead of the one-shot evaluator.
27
+ * @param persistent - Whether the selected mode requires retained-process launch support.
28
28
  * @returns Arguments following the resolved Node executable.
29
29
  */
30
30
  export declare function bootstrapArgs(fs: Pick<FileSystem, 'processPathFromHostPath'>, config: LaunchConfig, maxMessageBytes: number, persistent?: boolean): string[];
@@ -1,18 +1,12 @@
1
- import { type Duplex } from 'node:stream';
2
- import type { PatchableStream } from './bootstrap.ts';
3
- /** Process state owned by the REPL child; tests supply instance-local streams and environment. */
4
- export interface PersistentProcess {
5
- env: NodeJS.ProcessEnv;
6
- stdout: PatchableStream;
7
- stderr: PatchableStream;
8
- chdir(directory: string): void;
9
- }
1
+ /** Existing retained bootstrap entry delegates to the shared Node evaluation loop. */
2
+ import type { Duplex } from 'node:stream';
3
+ import type { ProgramProcess } from './process.ts';
10
4
  /**
11
- * Serve sequential evaluations until the owning host closes the control channel.
5
+ * Serve evaluations through the installed retained-bootstrap entry.
12
6
  * @param stream - Inherited private control endpoint.
13
7
  * @param maxMessageBytes - Maximum control frame and queued output bytes.
14
- * @param processState - Child environment, output and directory control, bound only in the REPL context.
15
- * @returns After the channel closes and the REPL releases its streams.
8
+ * @param processState - Child environment, output and directory control.
9
+ * @returns After control closure and evaluator cleanup.
16
10
  */
17
- export declare function runPersistentMain(stream: Duplex, maxMessageBytes: number, processState: PersistentProcess): Promise<void>;
11
+ export declare function runPersistentMain(stream: Duplex, maxMessageBytes: number, processState: ProgramProcess): Promise<void>;
18
12
  //# sourceMappingURL=persistent-process.d.ts.map
@@ -1,19 +1,21 @@
1
- /** Node child execution over an inherited control channel; no Harness services run here. */
2
1
  import type { Duplex } from 'node:stream';
2
+ import type { PtcProgramFormat } from '@deepseek-ai/dsh-ptc-runtime';
3
3
  import type { PatchableStream } from './bootstrap.ts';
4
- /** Process-owned environment and output streams consumed by the child bootstrap. */
4
+ /** Process-owned environment, output and directory control consumed by the child. */
5
5
  export interface ProgramProcess {
6
6
  env: NodeJS.ProcessEnv;
7
7
  stdout: PatchableStream;
8
8
  stderr: PatchableStream;
9
- exitCode: string | number | null | undefined;
9
+ exitCode?: string | number | null | undefined;
10
+ chdir(directory: string): void;
10
11
  }
11
12
  /**
12
- * Run one host-supplied program after the control handshake.
13
+ * Serve sequential evaluations until the host closes the control channel.
13
14
  * @param stream - Inherited, already-adopted control endpoint.
14
- * @param maxMessageBytes - Host-validated maximum frame and queued-write bytes.
15
- * @param processState - Environment, output streams and exit status of this Node child.
16
- * @returns After control output flushes and host shutdown is observed, or transport failure closes the channel.
15
+ * @param maxMessageBytes - Maximum control message and queued output bytes.
16
+ * @param processState - Child environment, output, directory control and exit status.
17
+ * @param defaultFormat - Syntax used by installed bootstraps when the host omits it.
18
+ * @returns After control closure and evaluator cleanup.
17
19
  */
18
- export declare function runNodeMain(stream: Duplex, maxMessageBytes: number, processState: ProgramProcess): Promise<void>;
20
+ export declare function runNodeMain(stream: Duplex, maxMessageBytes: number, processState: ProgramProcess, defaultFormat?: PtcProgramFormat): Promise<void>;
19
21
  //# sourceMappingURL=process.d.ts.map
@@ -1,14 +1,15 @@
1
- /**
2
- * JSON message vocabulary carried by the bounded process channel. The host validates every
3
- * message because model code can write directly to the inherited descriptor.
4
- * @module @deepseek-ai/dsh-ptc-runtime-node/src/protocol
5
- */
6
- import type { PtcJsonWire } from './json-wire.ts';
7
- /** What the host hands the program at spawn, after the readiness handshake. */
1
+ /** Typed methods shared by the host and its co-shipped Node execution process, and validation of untrusted program results. */
2
+ import type { PtcProgramFormat, PtcJsonValue, PtcRunFailure } from '@deepseek-ai/dsh-ptc-runtime';
3
+ import { type PtcJsonWire } from './json-wire.ts';
4
+ /** Inputs for one program; host functions remain in the parent process. */
8
5
  export interface ProgramBootData {
9
- /** The type-stripped (plain JS) program body. */
6
+ /** Type-stripped JavaScript source. */
10
7
  code: string;
11
- /** Binding namespaces to materialize; functions themselves stay host-side. */
8
+ /** Evaluation syntax; omitted uses the installed bootstrap's default. */
9
+ programFormat?: PtcProgramFormat;
10
+ /** Whether the host will reuse this process after the evaluation. */
11
+ retainsState: boolean;
12
+ /** Globals and callable names injected into the program. */
12
13
  namespaces: {
13
14
  global: string;
14
15
  names: string[];
@@ -17,59 +18,54 @@ export interface ProgramBootData {
17
18
  memberNameProperty: string;
18
19
  };
19
20
  }[];
20
- /** Hard cap for the combined serialized outer logs plus completion value or failure diagnostic. */
21
+ /** Combined serialized log and completion budget. */
21
22
  maxOutputBytes: number;
22
23
  }
23
- /** Program → host: one bridged binding call. */
24
- interface CallMessage {
25
- type: 'call';
26
- /** Program-issued correlation id; the host answers each id at most once and ignores duplicates. */
27
- id: number;
28
- /** The namespace global the call targets. */
29
- global: string;
30
- /** The function name within the namespace. */
31
- name: string;
32
- /** The single argument as a flat lossless-JSON wire value. */
33
- args: PtcJsonWire;
34
- }
35
- /** Program → host: captured text, streamed eagerly so output survives a mid-run termination (timeout, abort, OOM). */
36
- interface LogMessage {
37
- type: 'log';
38
- text: string;
39
- }
40
- /** Program → host: program-side capture or completion measurement exceeded the outer cap. */
41
- interface OutputLimitMessage {
42
- type: 'output-limit';
43
- }
44
- /**
45
- * Program → host: the program settled. `error` carries a program exception,
46
- * invalid completion, or output overflow (budgets, aborts, and substrate death
47
- * are observed host-side). `value` is present only on a clean completion that
48
- * produced one, as a flat wire value already lossless and admitted against
49
- * the remaining combined output cap. Logs are NOT carried here — they streamed
50
- * eagerly as {@link LogMessage}s.
51
- */
52
- export interface DoneMessage {
53
- type: 'done';
24
+ /** Program completion; logs are delivered separately before this result. */
25
+ export interface ProgramResult {
54
26
  value?: PtcJsonWire;
55
27
  error?: {
56
28
  kind: 'exception' | 'invalid-output' | 'output-limit';
57
29
  message: string;
58
30
  };
59
31
  }
60
- /** Every message the program sends. */
61
- export type ProgramToHost = CallMessage | LogMessage | OutputLimitMessage | DoneMessage;
62
- /** Host → program: the answer to one {@link CallMessage}. */
63
- export type ReplyMessage = {
64
- type: 'reply';
65
- id: number;
66
- ok: true;
67
- value: PtcJsonWire;
68
- } | {
69
- type: 'reply';
70
- id: number;
71
- ok: false;
72
- message: string;
32
+ /** Host operations for the current evaluation; one pipe delivers its messages before its result. */
33
+ export interface HostMethods {
34
+ /** Announce that the process can accept its first evaluation. */
35
+ ready(): void;
36
+ /**
37
+ * Invoke a binding under its originating host execution context.
38
+ * @param global - Namespace global.
39
+ * @param name - Function name within the namespace.
40
+ * @param args - Flat lossless JSON arguments.
41
+ * @returns Flat lossless JSON result; binding failures reject the call.
42
+ */
43
+ invoke(global: string, name: string, args: PtcJsonWire): Promise<PtcJsonWire>;
44
+ /**
45
+ * Admit captured output before completion or interruption.
46
+ * @param text - Captured text.
47
+ */
48
+ log(text: string): void;
49
+ /** Report exhausted program-side output accounting. */
50
+ outputLimit(): void;
51
+ }
52
+ /** Operations implemented by either the per-call child or retained REPL. */
53
+ export interface ProgramMethods {
54
+ /**
55
+ * Evaluate code with the supplied binding declarations and output budget.
56
+ * @param cwd - Execution-world working directory.
57
+ * @param data - Program and injected declarations.
58
+ * @returns Completion or a bounded program failure, after captured output is sent.
59
+ */
60
+ run(cwd: string, data: ProgramBootData): Promise<ProgramResult>;
61
+ }
62
+ /**
63
+ * Decode a remote run result without trusting model-written control traffic.
64
+ * @param result - Untrusted result returned by the program process.
65
+ * @returns Decoded completion or failure; malformed envelopes throw a protocol error.
66
+ */
67
+ export declare function readProgramResult(result: unknown): {
68
+ value?: PtcJsonValue;
69
+ error?: PtcRunFailure;
73
70
  };
74
- export {};
75
71
  //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { Duplex } from 'node:stream';
2
+ import { type BirpcReturn } from 'birpc';
3
+ /**
4
+ * Connect typed methods over one control endpoint; execution owns all deadlines.
5
+ * @param stream - Owned control endpoint; `$close()` destroys it and rejects outstanding remote calls.
6
+ * @param maxMessageBytes - Maximum incoming JSON line and queued outgoing bytes.
7
+ * @param functions - Only these own methods may be called by the peer.
8
+ * @param eventNames - Remote methods sent as notifications without a response.
9
+ * @param failure - Receives the first I/O error, peer closure or malformed-message failure after the endpoint closes.
10
+ * @returns Typed remote calls and birpc lifetime controls.
11
+ */
12
+ export declare function createProcessRpc<Remote extends object, Local extends object>(stream: Duplex, maxMessageBytes: number, functions: Local, eventNames: (keyof Remote)[], failure: (error: Error, kind: 'io' | 'closed' | 'protocol') => void): BirpcReturn<Remote, Local>;
13
+ //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { Context } from '@deepseek-ai/cordis';
2
+ import type { PtcRunSpec, PtcRunResult, PtcBindingNamespace } from '@deepseek-ai/dsh-ptc-runtime';
3
+ import type { SandboxExecutionPolicy } from '@deepseek-ai/dsh-sandbox';
4
+ import type { PolicyProcesses } from './policy-processes.ts';
5
+ import type { ResolvedConfig } from './config.ts';
6
+ import type { ExecutionMode } from './execution.ts';
7
+ /** One managed process; all mutable program state belongs to this process alone. */
8
+ export declare class ProgramWorker {
9
+ private readonly ctx;
10
+ private readonly config;
11
+ readonly policy: SandboxExecutionPolicy;
12
+ private readonly mode;
13
+ private readonly retainsState;
14
+ private readonly unregister;
15
+ private confined;
16
+ private handle?;
17
+ private channel?;
18
+ private active;
19
+ /** Admission remains reserved until the result includes completed process cleanup. */
20
+ private running;
21
+ private cleanupPending;
22
+ private ready;
23
+ private stderr;
24
+ private controlFailure;
25
+ private stopped;
26
+ private starting?;
27
+ private exitOutcome?;
28
+ private readonly controller;
29
+ closed: boolean;
30
+ /** Whether termination succeeded and this process no longer needs cleanup retries. */
31
+ get cleanupComplete(): boolean;
32
+ /**
33
+ * Own one process under a fixed file policy.
34
+ * @param ctx - Provider execution services.
35
+ * @param config - Validated resource limits and launch selection.
36
+ * @param policy - Authority retained for the lifetime of this process.
37
+ * @param processes - Session policy invalidation and cleanup coordination.
38
+ * @param mode - Evaluator syntax and TypeScript erasure.
39
+ * @param retainsState - Whether this process belongs to an owner and survives completed evaluations.
40
+ */
41
+ constructor(ctx: Context, config: ResolvedConfig, policy: SandboxExecutionPolicy, processes: PolicyProcesses, mode: ExecutionMode, retainsState: boolean);
42
+ /** Reject reuse until the previous evaluation and required cleanup settle. */
43
+ assertIdle(): void;
44
+ /**
45
+ * Evaluate a program, retaining this process only for an enabled state owner.
46
+ * @param spec - Resolved program inputs and cancellation.
47
+ * @param bindings - Current host binding implementations.
48
+ * @returns Output after any required process cleanup.
49
+ */
50
+ run(spec: PtcRunSpec, bindings: Map<string, PtcBindingNamespace>): Promise<PtcRunResult>;
51
+ private output;
52
+ private message;
53
+ private abortMessage;
54
+ private evaluate;
55
+ /** Cancel active work and await managed process termination and output drainage. */
56
+ dispose(): Promise<void>;
57
+ private stop;
58
+ private fail;
59
+ private dispatch;
60
+ private withControlFailure;
61
+ private exitMessage;
62
+ private start;
63
+ }
64
+ //# sourceMappingURL=worker.d.ts.map