@howaboua/pi-durable-js-notebook 0.0.0-stage → 0.9.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.
- package/LICENSE +21 -0
- package/NOTICE +39 -0
- package/README.md +38 -2
- package/dist/execution/src/cell-contract.d.ts +49 -0
- package/dist/execution/src/cell-observation.d.ts +7 -0
- package/dist/execution/src/cell-progress.d.ts +4 -0
- package/dist/execution/src/cell-task.d.ts +17 -0
- package/dist/execution/src/cell-tools.d.ts +8 -0
- package/dist/execution/src/cells.d.ts +14 -0
- package/dist/execution/src/command-backend.d.ts +22 -0
- package/dist/execution/src/controls.d.ts +3 -0
- package/dist/execution/src/custom-command-config.d.ts +21 -0
- package/dist/execution/src/custom-commands.d.ts +62 -0
- package/dist/execution/src/exec-source.d.ts +21 -0
- package/dist/execution/src/forwarded-tools.d.ts +21 -0
- package/dist/execution/src/forwarding-hook.d.ts +6 -0
- package/dist/execution/src/forwarding.d.ts +15 -0
- package/dist/execution/src/index.d.ts +6 -0
- package/dist/execution/src/invocation-state.d.ts +26 -0
- package/dist/execution/src/invocation.d.ts +35 -0
- package/dist/execution/src/native-tools.d.ts +11 -0
- package/dist/execution/src/nested-call.d.ts +26 -0
- package/dist/execution/src/nested-result.d.ts +8 -0
- package/dist/execution/src/nested.d.ts +3 -0
- package/dist/execution/src/output.d.ts +48 -0
- package/dist/execution/src/presentation.d.ts +59 -0
- package/dist/execution/src/progress.d.ts +23 -0
- package/dist/execution/src/projection.d.ts +5 -0
- package/dist/execution/src/shell/backend.d.ts +28 -0
- package/dist/execution/src/shell/format.d.ts +2 -0
- package/dist/execution/src/shell/node-backend.d.ts +9 -0
- package/dist/execution/src/shell/output.d.ts +19 -0
- package/dist/execution/src/shell/process-session.d.ts +50 -0
- package/dist/execution/src/shell/results.d.ts +14 -0
- package/dist/execution/src/shell/session-manager.d.ts +46 -0
- package/dist/execution/src/shell/session-store.d.ts +53 -0
- package/dist/execution/src/shell/shell-args.d.ts +4 -0
- package/dist/execution/src/shell/shell.d.ts +14 -0
- package/dist/execution/src/shell/wait.d.ts +7 -0
- package/dist/execution/src/shell.d.ts +14 -0
- package/dist/execution/src/tool-contract.d.ts +34 -0
- package/dist/execution/src/tool-origin.d.ts +11 -0
- package/dist/execution/src/tool-source.d.ts +6 -0
- package/dist/execution/src/tool-value.d.ts +3 -0
- package/dist/execution/src/wait-session.d.ts +6 -0
- package/dist/index.js +6338 -0
- package/dist/js-notebook/src/bindings.d.ts +6 -0
- package/dist/js-notebook/src/client.d.ts +34 -0
- package/dist/js-notebook/src/data-state.d.ts +20 -0
- package/dist/js-notebook/src/data-storage.d.ts +17 -0
- package/dist/js-notebook/src/engine.d.ts +16 -0
- package/dist/js-notebook/src/index.d.ts +53 -0
- package/dist/js-notebook/src/kernel.d.ts +25 -0
- package/dist/js-notebook/src/managed-bindings.d.ts +20 -0
- package/dist/js-notebook/src/managed-source.d.ts +9 -0
- package/dist/js-notebook/src/notebook-control.d.ts +7 -0
- package/dist/js-notebook/src/portable-state.d.ts +79 -0
- package/dist/js-notebook/src/prelude.d.ts +1 -0
- package/dist/js-notebook/src/project.d.ts +67 -0
- package/dist/js-notebook/src/protocol.d.ts +115 -0
- package/dist/js-notebook/src/runtime-cache.d.ts +2 -0
- package/dist/js-notebook/src/runtime-contract.d.ts +117 -0
- package/dist/js-notebook/src/runtime.d.ts +8 -0
- package/dist/js-notebook/src/state-validation.d.ts +2 -0
- package/dist/js-notebook/src/storage.d.ts +18 -0
- package/dist/js-notebook/src/support.d.ts +12 -0
- package/dist/js-notebook/src/tool-calls.d.ts +11 -0
- package/dist/js-notebook/src/worker.d.ts +1 -0
- package/dist/notebook/src/cell.d.ts +34 -0
- package/dist/notebook/src/checkpoint-activity.d.ts +7 -0
- package/dist/notebook/src/checkpoint-format.d.ts +32 -0
- package/dist/notebook/src/checkpoint-store.d.ts +8 -0
- package/dist/notebook/src/command-output.d.ts +1 -0
- package/dist/notebook/src/deno-syntax-diagnostics.d.ts +1 -0
- package/dist/notebook/src/directory-lock.d.ts +10 -0
- package/dist/notebook/src/glob.d.ts +1 -0
- package/dist/notebook/src/jupyter-connection.d.ts +17 -0
- package/dist/notebook/src/jupyter-execution.d.ts +29 -0
- package/dist/notebook/src/jupyter-kernel.d.ts +43 -0
- package/dist/notebook/src/jupyter-output.d.ts +32 -0
- package/dist/notebook/src/jupyter-shell.d.ts +18 -0
- package/dist/notebook/src/jupyter-socket.d.ts +17 -0
- package/dist/notebook/src/jupyter-wire.d.ts +16 -0
- package/dist/notebook/src/profile-state-format.d.ts +36 -0
- package/dist/notebook/src/project-identity.d.ts +1 -0
- package/dist/notebook/src/project-state-format.d.ts +80 -0
- package/dist/notebook/src/project-state-lock.d.ts +1 -0
- package/dist/notebook/src/runtime-contract.d.ts +117 -0
- package/dist/notebook/src/runtime-health.d.ts +9 -0
- package/dist/notebook/src/storage-retention.d.ts +21 -0
- package/dist/notebook/src/tool-observation.d.ts +21 -0
- package/dist/worker.js +1545 -0
- package/package.json +51 -5
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { QuickJS } from "quickjs-wasi";
|
|
2
|
+
import type { JsBindings } from "./managed-bindings.ts";
|
|
3
|
+
import type { JsBindingStatus, JsInventory } from "./protocol.ts";
|
|
4
|
+
export declare function inspectJsBindings(vm: QuickJS, inventory: JsInventory, query?: string, managed?: JsBindings): JsBindingStatus[];
|
|
5
|
+
export declare function isJsInventory(value: unknown): value is JsInventory;
|
|
6
|
+
export declare function validJsBindingName(name: string): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { NotebookControlRequest, NotebookControlResult, NotebookExecutionClient, NotebookRuntimeOptions, NotebookToolDefinition, RuntimeResponse, ToolExecutionContext } from "./runtime-contract.ts";
|
|
2
|
+
export declare class JsNotebookClient implements NotebookExecutionClient {
|
|
3
|
+
private readonly project;
|
|
4
|
+
private readonly delegate;
|
|
5
|
+
private readonly cells;
|
|
6
|
+
private identity;
|
|
7
|
+
private inspectionOnly;
|
|
8
|
+
private inspection;
|
|
9
|
+
private managing;
|
|
10
|
+
private preparing;
|
|
11
|
+
private controls;
|
|
12
|
+
private liveQueue;
|
|
13
|
+
private closing;
|
|
14
|
+
private running;
|
|
15
|
+
private isolatedRunning;
|
|
16
|
+
constructor(options: NotebookRuntimeOptions);
|
|
17
|
+
execute(source: string, context: ToolExecutionContext, signal?: AbortSignal, tools?: NotebookToolDefinition[]): Promise<RuntimeResponse>;
|
|
18
|
+
wait(id: string, yieldTimeMs: number, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
19
|
+
terminate(id: string, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
20
|
+
checkpoint(): Promise<void>;
|
|
21
|
+
shutdown(): Promise<void>;
|
|
22
|
+
controlNotebook(request: NotebookControlRequest, context: ToolExecutionContext, signal?: AbortSignal): Promise<NotebookControlResult>;
|
|
23
|
+
private prepare;
|
|
24
|
+
private stopSession;
|
|
25
|
+
private contextKey;
|
|
26
|
+
private assertReady;
|
|
27
|
+
private transaction;
|
|
28
|
+
private run;
|
|
29
|
+
private complete;
|
|
30
|
+
private runCell;
|
|
31
|
+
private stop;
|
|
32
|
+
private observe;
|
|
33
|
+
private response;
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { QuickJS } from "quickjs-wasi";
|
|
2
|
+
import type { JsBindings } from "./managed-bindings.ts";
|
|
3
|
+
import { type PortableState } from "./portable-state.ts";
|
|
4
|
+
import type { JsInventory } from "./protocol.ts";
|
|
5
|
+
import type { JsSupport } from "./support.ts";
|
|
6
|
+
/** The data graph format/merge is shared, never the TS runtime or its state files. */
|
|
7
|
+
export declare function assertJsData(value: unknown): asserts value is PortableState;
|
|
8
|
+
export declare function captureJsData(vm: QuickJS, support: JsSupport, inventory: JsInventory, names: readonly string[], bindings: JsBindings): PortableState;
|
|
9
|
+
/** Call in a disposable full-VM candidate. Failure must not publish partial declarations. */
|
|
10
|
+
export declare function restoreJsData(vm: QuickJS, support: JsSupport, inventory: JsInventory, state: PortableState, bindings: JsBindings): void;
|
|
11
|
+
export interface JsReleaseResult {
|
|
12
|
+
released: string[];
|
|
13
|
+
legacyRetained: string[];
|
|
14
|
+
skipped: {
|
|
15
|
+
name: string;
|
|
16
|
+
reason: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
/** Drop registry roots, never rebuild closures from recipes. */
|
|
20
|
+
export declare function releaseJsData(vm: QuickJS, inventory: JsInventory, names: readonly string[], protectedNames: ReadonlyMap<string, string>, bindings: JsBindings): JsReleaseResult;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PortableState } from "./portable-state.ts";
|
|
2
|
+
/** JS-only selected data and reset-survival pins. */
|
|
3
|
+
export declare class JsDataStorage {
|
|
4
|
+
readonly projectKey: string;
|
|
5
|
+
private readonly project;
|
|
6
|
+
private readonly profiles;
|
|
7
|
+
private readonly maxBytes;
|
|
8
|
+
constructor(agentDir: string, cwd: string, maxBytes: number);
|
|
9
|
+
readProfile(name: string): Promise<PortableState | undefined>;
|
|
10
|
+
writeProfile(name: string, state: PortableState): Promise<void>;
|
|
11
|
+
readProject(): Promise<PortableState>;
|
|
12
|
+
/** Caller holds the whole-notebook lease; pin data is reset-survival state, not a second fork. */
|
|
13
|
+
writeProject(candidate: PortableState): Promise<void>;
|
|
14
|
+
private profile;
|
|
15
|
+
private read;
|
|
16
|
+
private write;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ToolExecutionApi } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellEngine } from "../../execution/src/cell-contract.ts";
|
|
4
|
+
import type { NotebookControlRequest, NotebookControlResult } from "./runtime-contract.ts";
|
|
5
|
+
export interface JsNotebookEngineOptions {
|
|
6
|
+
stateDirectory: string;
|
|
7
|
+
/** Explicit permission to run native workers and access project checkpoint files. */
|
|
8
|
+
native: {
|
|
9
|
+
environmentId: string;
|
|
10
|
+
};
|
|
11
|
+
maxHeapMiB?: number | undefined;
|
|
12
|
+
profile?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare function createJsNotebookEngine(options: JsNotebookEngineOptions): CellEngine & {
|
|
15
|
+
control(request: NotebookControlRequest, api: ToolExecutionApi, context: Context): Promise<NotebookControlResult>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Harness, type TaskId } from "@earendil-works/pi-durable";
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { type ShellRuntimeOptions } from "../../execution/src/shell.ts";
|
|
5
|
+
import { type JsNotebookEngineOptions } from "./engine.ts";
|
|
6
|
+
export type { CustomCommandBackend, CustomCommandRequest, NodeCommandBackendOptions, } from "../../execution/src/command-backend.ts";
|
|
7
|
+
export { createNodeCommandBackend } from "../../execution/src/command-backend.ts";
|
|
8
|
+
export type { CustomCommandDefinition, CustomCommandParseOptions, } from "../../execution/src/custom-command-config.ts";
|
|
9
|
+
export { parseCustomCommand } from "../../execution/src/custom-command-config.ts";
|
|
10
|
+
export type { CustomCommandDiscovery, CustomCommandDiscoveryError, CustomCommandOptions, CustomCommandRoot, LiveCustomCommandOptions, } from "../../execution/src/custom-commands.ts";
|
|
11
|
+
export { createCustomCommands, discoverCustomCommands, loadCustomCommandTools, } from "../../execution/src/custom-commands.ts";
|
|
12
|
+
export { CODE_MODE_EXEC_CONSTRAINED_SAMPLING as NOTEBOOK_EXEC_CONSTRAINED_SAMPLING, CODE_MODE_EXEC_GRAMMAR as NOTEBOOK_EXEC_GRAMMAR, } from "../../execution/src/exec-source.ts";
|
|
13
|
+
export type { NodeShellBackendOptions, ShellOutputStream, ShellProcess, ShellProcessBackend, ShellProcessEvents, ShellRuntimeOptions, ShellSpawnRequest, } from "../../execution/src/shell.ts";
|
|
14
|
+
export { createNodeShellBackend } from "../../execution/src/shell.ts";
|
|
15
|
+
export type { ExecutionToolHints, ExecutionToolRegistration, } from "../../execution/src/tool-contract.ts";
|
|
16
|
+
export type { JsNotebookEngineOptions } from "./engine.ts";
|
|
17
|
+
export interface JsNotebookModeOptions extends JsNotebookEngineOptions {
|
|
18
|
+
shell: ShellRuntimeOptions;
|
|
19
|
+
cancelTask: (id: TaskId, context: Context) => ReturnType<Harness["abortTask"]>;
|
|
20
|
+
}
|
|
21
|
+
/** One application-owned JS Notebook component, with project-shared checkpoints. */
|
|
22
|
+
export declare function createJsNotebookMode(options: JsNotebookModeOptions): {
|
|
23
|
+
extension: import("@earendil-works/pi-durable").Extension<{
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
parameters: Type.TObject<{
|
|
27
|
+
input: Type.TOptional<Type.TString>;
|
|
28
|
+
}>;
|
|
29
|
+
constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
|
|
30
|
+
replay?: "safe" | "unsafe";
|
|
31
|
+
executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
|
|
32
|
+
prepareArguments?(args: unknown): {
|
|
33
|
+
input?: string;
|
|
34
|
+
};
|
|
35
|
+
structuredOutputSchema?: Type.TSchema;
|
|
36
|
+
callers?: readonly ("model" | "tools")[];
|
|
37
|
+
deferred?: true;
|
|
38
|
+
outputLimits?: {
|
|
39
|
+
readonly maxBytes?: number;
|
|
40
|
+
readonly maxLines?: number;
|
|
41
|
+
readonly retain?: "head" | "tail";
|
|
42
|
+
};
|
|
43
|
+
execute(args: {
|
|
44
|
+
input?: string;
|
|
45
|
+
}, api: import("@earendil-works/pi-durable").ToolExecutionApi<import("@earendil-works/chord").JsonValue>, context: Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<import("@earendil-works/chord").JsonValue>>;
|
|
46
|
+
executionHints: {
|
|
47
|
+
discovery: "help";
|
|
48
|
+
};
|
|
49
|
+
} | import("@earendil-works/pi-durable").ToolRegistration>;
|
|
50
|
+
/** Bind the owning Harness before execution to retain native nested display receipts and native-only tools. */
|
|
51
|
+
bind: (harness: Pick<Harness, "conversation">) => void;
|
|
52
|
+
close(): Promise<void>;
|
|
53
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JsInput, JsOutcome, JsSnapshot } from "./protocol.ts";
|
|
2
|
+
import type { JsRuntime } from "./runtime.ts";
|
|
3
|
+
import type { RuntimeContentItem } from "./runtime-contract.ts";
|
|
4
|
+
interface Callbacks {
|
|
5
|
+
output(items: RuntimeContentItem[]): void;
|
|
6
|
+
notify(text: string): void;
|
|
7
|
+
yield(): void;
|
|
8
|
+
request(id: number, name: string, value: unknown): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
/** A compiled WASM module is shared; each kernel owns a separate VM and thread. */
|
|
11
|
+
export declare class JsKernel {
|
|
12
|
+
private readonly worker;
|
|
13
|
+
private readonly interrupt;
|
|
14
|
+
private next;
|
|
15
|
+
private active;
|
|
16
|
+
private failure;
|
|
17
|
+
private stopping;
|
|
18
|
+
static create(runtime: JsRuntime, heapBytes: number, snapshot?: JsSnapshot, managementClone?: boolean): Promise<JsKernel>;
|
|
19
|
+
private constructor();
|
|
20
|
+
execute(input: JsInput, callbacks: Callbacks): Promise<JsOutcome>;
|
|
21
|
+
stop(): Promise<void>;
|
|
22
|
+
private fail;
|
|
23
|
+
private request;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JSValueHandle, QuickJS } from "quickjs-wasi";
|
|
2
|
+
import type { JsBindingStatus, JsInventory } from "./protocol.ts";
|
|
3
|
+
export declare const JS_BINDINGS_SOURCE: string;
|
|
4
|
+
export declare class JsBindings {
|
|
5
|
+
readonly token: number;
|
|
6
|
+
private readonly vm;
|
|
7
|
+
constructor(vm: QuickJS, inventory: JsInventory, token?: number);
|
|
8
|
+
call(name: string, ...args: JSValueHandle[]): JSValueHandle;
|
|
9
|
+
private named;
|
|
10
|
+
has(name: string): boolean;
|
|
11
|
+
isMasked(name: string): boolean;
|
|
12
|
+
read(name: string): JSValueHandle;
|
|
13
|
+
remove(name: string): boolean;
|
|
14
|
+
inspect(): {
|
|
15
|
+
bindings: JsBindingStatus[];
|
|
16
|
+
masked: string[];
|
|
17
|
+
};
|
|
18
|
+
add(name: string, kind: "var" | "let" | "const", value: JSValueHandle): void;
|
|
19
|
+
execute(source: string): JSValueHandle;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsDeclaration } from "./protocol.ts";
|
|
2
|
+
export interface ManagedCell {
|
|
3
|
+
source: string;
|
|
4
|
+
declarations: JsDeclaration[];
|
|
5
|
+
references: string[];
|
|
6
|
+
}
|
|
7
|
+
/** Native cell-local lexicals retain const/TDZ/closure semantics. Free references
|
|
8
|
+
* capture stable binding records rather than looking up later replacement names. */
|
|
9
|
+
export declare function managedCell(source: string, existing: ReadonlyMap<string, JsDeclaration["kind"]>): ManagedCell;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { NotebookControlRequest } from "./runtime-contract.ts";
|
|
3
|
+
export declare const NOTEBOOK_PARAMETERS: Type.TObject<{
|
|
4
|
+
input: Type.TOptional<Type.TString>;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const NOTEBOOK_HELP = "Call notebook with {} or {\"input\":\"help\"}, or put a JSON action object in input.\n{\"action\":\"status\",\"query\"?:string} Inspect binding inventory by glob\n{\"action\":\"diagnostics\"} Runtime and saved-state summary\n{\"action\":\"list\",\"query\"?:string} List profiles and isolated candidates\n{\"action\":\"checkpoint\"} Save the complete VM without replay\n{\"action\":\"save\",\"name\":string,\"names\"?:string[]} Save the whole VM, or selected plain data\n{\"action\":\"load\",\"name\":string} Whole-VM profiles replace live state. Selected-data profiles add noncolliding bindings\n{\"action\":\"pin\",\"names\":string[]} Persist plain data across project reset and protect its names\n{\"action\":\"unpin\",\"names\":string[]} Remove protection, keeping live values\n{\"action\":\"hook\",\"name\":string,\"event\":\"startup\"|\"tool_result\"|false} Register a retained function or remove its hook\n{\"action\":\"release\",\"names\":string[]} Release unpinned bindings. Other aliases and closures remain\n{\"action\":\"prune\",\"query\":string} Release matching unpinned bindings\n{\"action\":\"restart\"} Stop active cells and restore the last checkpoint\n{\"action\":\"reset\"} Discard the project VM. Pins and profiles survive\n\nRun management after exec returns. Inside exec, tools.notebook({action,...}) supports status without query, list and diagnostics only. Other valid controls return notRun with a retry request. Profile names: 1-64 letters, numbers, dots, underscores or hyphens, starting with a letter or number. Queries accept case-insensitive * and ? globs.\nNormal cells share one serial project VM. isolated:true forks the last committed checkpoint and saves a candidate without changing live state. Loading a stale candidate is rejected and saves a recovery profile for deliberate replacement. Whole-VM snapshots preserve closures, classes and cycles. Selected data and reset-survival pins do not preserve functions or class instances.\nHooks are retained functions awaited in name order. startup receives {type:\"startup\"} once after restore and cannot call tools. tool_result receives {type:\"tool_result\",toolName,input,status,result?,error?}. Calls inside hooks do not retrigger hooks. Failed startup blocks normal execution. Cancellation stops the owned VM and restores only the last checkpoint on restart. Tool and file effects are never rolled back or replayed.";
|
|
7
|
+
export declare function parseNotebookRequest(input: unknown): NotebookControlRequest;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type PortableValue = null | undefined | string | number | boolean | bigint | {
|
|
2
|
+
ref: string;
|
|
3
|
+
};
|
|
4
|
+
type PortableNode = {
|
|
5
|
+
kind: "object";
|
|
6
|
+
nullPrototype: boolean;
|
|
7
|
+
properties: Record<string, PortableValue>;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "array";
|
|
10
|
+
length: number;
|
|
11
|
+
properties: Record<string, PortableValue>;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "map";
|
|
14
|
+
entries: [PortableValue, PortableValue][];
|
|
15
|
+
} | {
|
|
16
|
+
kind: "set";
|
|
17
|
+
entries: PortableValue[];
|
|
18
|
+
} | {
|
|
19
|
+
kind: "binary";
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "date";
|
|
23
|
+
time: number;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "regexp";
|
|
26
|
+
source: string;
|
|
27
|
+
flags: string;
|
|
28
|
+
lastIndex: number;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "view";
|
|
31
|
+
constructor: string;
|
|
32
|
+
buffer: PortableValue;
|
|
33
|
+
byteOffset: number;
|
|
34
|
+
length: number;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "recipe";
|
|
37
|
+
name: string;
|
|
38
|
+
properties: Record<string, PortableValue>;
|
|
39
|
+
} | {
|
|
40
|
+
kind: "checkpoint";
|
|
41
|
+
snapshot: string;
|
|
42
|
+
restore: string;
|
|
43
|
+
data: PortableValue;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "module";
|
|
46
|
+
specifier: string;
|
|
47
|
+
imported: string;
|
|
48
|
+
attributes?: Record<string, string> | undefined;
|
|
49
|
+
};
|
|
50
|
+
interface BindingRecipe {
|
|
51
|
+
name: string;
|
|
52
|
+
kind: string;
|
|
53
|
+
declaration: string;
|
|
54
|
+
source?: string | undefined;
|
|
55
|
+
references?: string[] | undefined;
|
|
56
|
+
module?: {
|
|
57
|
+
specifier: string;
|
|
58
|
+
imported: string;
|
|
59
|
+
attributes?: Record<string, string> | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
hook?: "startup" | "tool_result" | undefined;
|
|
62
|
+
checkpoint?: {
|
|
63
|
+
snapshot: string;
|
|
64
|
+
restore: string;
|
|
65
|
+
} | undefined;
|
|
66
|
+
}
|
|
67
|
+
export interface PortableState {
|
|
68
|
+
version: 1;
|
|
69
|
+
roots: Record<string, PortableValue>;
|
|
70
|
+
nodes: Record<string, PortableNode>;
|
|
71
|
+
bindings: Record<string, BindingRecipe>;
|
|
72
|
+
pins: string[];
|
|
73
|
+
imports: string[];
|
|
74
|
+
}
|
|
75
|
+
export declare function emptyState(): PortableState;
|
|
76
|
+
/** Profiles are loaded by value: their graph IDs must not alias an existing session graph. */
|
|
77
|
+
export declare function forkPortableState(original: PortableState): PortableState;
|
|
78
|
+
export declare function compactState(state: PortableState): PortableState;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const JS_PRELUDE: string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { JsKernel } from "./kernel.ts";
|
|
2
|
+
import type { JsOutcome, JsSnapshot, JsTool } from "./protocol.ts";
|
|
3
|
+
import type { NotebookControlRequest, NotebookControlResult, NotebookRuntimeOptions } from "./runtime-contract.ts";
|
|
4
|
+
/** Owns the live heap and its durable project image; the client owns scheduling. */
|
|
5
|
+
export declare class JsNotebookProject {
|
|
6
|
+
private storage;
|
|
7
|
+
private dataStorage;
|
|
8
|
+
private observedProject;
|
|
9
|
+
private pins;
|
|
10
|
+
private projectWarning;
|
|
11
|
+
private durable;
|
|
12
|
+
private dirty;
|
|
13
|
+
private migrationNotice;
|
|
14
|
+
private kernel;
|
|
15
|
+
private runtime;
|
|
16
|
+
private runtimeAbort;
|
|
17
|
+
private unavailable;
|
|
18
|
+
private startupError;
|
|
19
|
+
private heapBytes;
|
|
20
|
+
private latestTools;
|
|
21
|
+
private bindings;
|
|
22
|
+
private inventoryComplete;
|
|
23
|
+
private hooks;
|
|
24
|
+
private readonly options;
|
|
25
|
+
constructor(options: NotebookRuntimeOptions);
|
|
26
|
+
get stopped(): boolean;
|
|
27
|
+
get error(): string | undefined;
|
|
28
|
+
recordStartupError(error: unknown): void;
|
|
29
|
+
get warning(): string | undefined;
|
|
30
|
+
get snapshot(): JsSnapshot | undefined;
|
|
31
|
+
isolationBaseline(): Promise<JsSnapshot>;
|
|
32
|
+
get startupAborted(): boolean;
|
|
33
|
+
startupSignal(signal?: AbortSignal): AbortSignal;
|
|
34
|
+
abortStartup(): void;
|
|
35
|
+
renewStartup(): void;
|
|
36
|
+
setTools(tools: JsTool[]): void;
|
|
37
|
+
invalidate(): void;
|
|
38
|
+
takeMigrationNotice(): string | undefined;
|
|
39
|
+
withLock<T>(operation: () => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
40
|
+
get available(): boolean;
|
|
41
|
+
hasDataProfile(name: string): Promise<boolean>;
|
|
42
|
+
list(query?: string): Promise<NotebookControlResult>;
|
|
43
|
+
private createKernel;
|
|
44
|
+
bindStorage(cwd: string, identity: string): void;
|
|
45
|
+
initialize(inspectionOnly: boolean, signal?: AbortSignal): Promise<void>;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
inspect(signal?: AbortSignal): Promise<void>;
|
|
48
|
+
restart(reset: boolean, signal: AbortSignal | undefined, retryStartup: () => void): Promise<NotebookControlResult>;
|
|
49
|
+
control(request: NotebookControlRequest, signal?: AbortSignal): Promise<NotebookControlResult>;
|
|
50
|
+
refreshProject(signal?: AbortSignal): Promise<void>;
|
|
51
|
+
private requireStorage;
|
|
52
|
+
private requireDataStorage;
|
|
53
|
+
private liveBudget;
|
|
54
|
+
status(activeCells: string[], query?: string): NotebookControlResult;
|
|
55
|
+
private recordInventory;
|
|
56
|
+
capture(): Promise<JsSnapshot>;
|
|
57
|
+
private liveSnapshot;
|
|
58
|
+
private mutate;
|
|
59
|
+
private restoreInitial;
|
|
60
|
+
commit(result: JsOutcome, sync?: boolean): Promise<void>;
|
|
61
|
+
private syncProject;
|
|
62
|
+
private managedResult;
|
|
63
|
+
cellKernel(isolated: boolean, maxCells: number, signal: AbortSignal, baseline?: JsSnapshot): Promise<JsKernel>;
|
|
64
|
+
adoptLiveKernel(kernel: JsKernel): void;
|
|
65
|
+
recordCell(result: JsOutcome): void;
|
|
66
|
+
saveCandidate(snapshot: JsSnapshot, name: string, baseline?: JsSnapshot): Promise<void>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { CodemodeWasmModule } from "@earendil-works/pi-codemode";
|
|
2
|
+
import type { JsReleaseResult } from "./data-state.ts";
|
|
3
|
+
import type { PortableState } from "./portable-state.ts";
|
|
4
|
+
import type { NotebookHook, RuntimeContentItem } from "./runtime-contract.ts";
|
|
5
|
+
export interface JsDeclaration {
|
|
6
|
+
name: string;
|
|
7
|
+
kind: "let" | "const" | "var" | "using" | "await using" | "function" | "class";
|
|
8
|
+
}
|
|
9
|
+
export interface JsInventory {
|
|
10
|
+
declarations: JsDeclaration[];
|
|
11
|
+
baseline: string[];
|
|
12
|
+
complete: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface JsBindingStatus {
|
|
15
|
+
name: string;
|
|
16
|
+
kind: JsDeclaration["kind"] | "global";
|
|
17
|
+
type: string;
|
|
18
|
+
}
|
|
19
|
+
export interface JsSnapshot {
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
controller: number;
|
|
22
|
+
inventory?: JsInventory;
|
|
23
|
+
support?: number;
|
|
24
|
+
bindings?: number;
|
|
25
|
+
projectRevision?: string;
|
|
26
|
+
pins?: string[];
|
|
27
|
+
observedProject?: {
|
|
28
|
+
key: string;
|
|
29
|
+
state: PortableState;
|
|
30
|
+
};
|
|
31
|
+
startup?: {
|
|
32
|
+
status: "pending" | "done" | "failed";
|
|
33
|
+
error?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface JsTool {
|
|
37
|
+
name: string;
|
|
38
|
+
exposed: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
output?: "plain-command" | "command";
|
|
41
|
+
}
|
|
42
|
+
type JsDataOperation = {
|
|
43
|
+
action: "export" | "pin" | "unpin" | "release";
|
|
44
|
+
names: string[];
|
|
45
|
+
} | {
|
|
46
|
+
action: "import";
|
|
47
|
+
state: PortableState;
|
|
48
|
+
pins?: string[];
|
|
49
|
+
};
|
|
50
|
+
export interface JsInput {
|
|
51
|
+
source?: string;
|
|
52
|
+
tools: JsTool[];
|
|
53
|
+
inspect?: string;
|
|
54
|
+
hook?: {
|
|
55
|
+
name: string;
|
|
56
|
+
event: NotebookHook | false;
|
|
57
|
+
};
|
|
58
|
+
data?: JsDataOperation;
|
|
59
|
+
management?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export type JsCommand = {
|
|
62
|
+
kind: "run";
|
|
63
|
+
run: number;
|
|
64
|
+
input: JsInput;
|
|
65
|
+
} | {
|
|
66
|
+
kind: "reply";
|
|
67
|
+
run: number;
|
|
68
|
+
id: number;
|
|
69
|
+
json?: string;
|
|
70
|
+
error?: string;
|
|
71
|
+
};
|
|
72
|
+
export interface JsOutcome {
|
|
73
|
+
snapshot?: JsSnapshot;
|
|
74
|
+
error?: string;
|
|
75
|
+
fatal?: boolean;
|
|
76
|
+
heapBytes: number;
|
|
77
|
+
bindings?: JsBindingStatus[];
|
|
78
|
+
inventoryComplete?: boolean;
|
|
79
|
+
hooks?: {
|
|
80
|
+
name: string;
|
|
81
|
+
event: NotebookHook;
|
|
82
|
+
}[];
|
|
83
|
+
pins?: string[];
|
|
84
|
+
pinState?: PortableState;
|
|
85
|
+
pinError?: string;
|
|
86
|
+
data?: PortableState;
|
|
87
|
+
release?: JsReleaseResult;
|
|
88
|
+
}
|
|
89
|
+
export type JsMessage = {
|
|
90
|
+
run: number;
|
|
91
|
+
} & ({
|
|
92
|
+
kind: "output";
|
|
93
|
+
items: RuntimeContentItem[];
|
|
94
|
+
} | {
|
|
95
|
+
kind: "notify";
|
|
96
|
+
text: string;
|
|
97
|
+
} | {
|
|
98
|
+
kind: "yield";
|
|
99
|
+
} | {
|
|
100
|
+
kind: "call";
|
|
101
|
+
id: number;
|
|
102
|
+
name: string;
|
|
103
|
+
json: string;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "done";
|
|
106
|
+
outcome: JsOutcome;
|
|
107
|
+
});
|
|
108
|
+
export interface JsWorkerData {
|
|
109
|
+
wasm: CodemodeWasmModule;
|
|
110
|
+
moduleUrl: string;
|
|
111
|
+
interrupt: SharedArrayBuffer;
|
|
112
|
+
heapBytes: number;
|
|
113
|
+
snapshot?: JsSnapshot;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
interface NotebookSessionContext {
|
|
2
|
+
cwd: string;
|
|
3
|
+
sessionId: string;
|
|
4
|
+
}
|
|
5
|
+
export interface NotebookRuntimeOptions {
|
|
6
|
+
maxHeapMiB: number;
|
|
7
|
+
agentDir: string;
|
|
8
|
+
profile?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface ToolExecutionContext {
|
|
11
|
+
cwd: string;
|
|
12
|
+
sessionContext: NotebookSessionContext;
|
|
13
|
+
onUpdate?: ((result: {
|
|
14
|
+
content: Array<{
|
|
15
|
+
type: "text";
|
|
16
|
+
text: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: "image";
|
|
19
|
+
data: string;
|
|
20
|
+
mimeType: string;
|
|
21
|
+
}>;
|
|
22
|
+
details?: unknown;
|
|
23
|
+
}) => void) | undefined;
|
|
24
|
+
setBlocked?: ((id: string, active: boolean) => void) | undefined;
|
|
25
|
+
onYield?: (() => Promise<void>) | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface NotebookToolDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
usage: string;
|
|
31
|
+
help?: string | undefined;
|
|
32
|
+
textOutput?: "command" | "plain-command" | undefined;
|
|
33
|
+
invoke(input: unknown, context: ToolExecutionContext, signal: AbortSignal): Promise<unknown>;
|
|
34
|
+
}
|
|
35
|
+
export interface NotebookExecutionClient {
|
|
36
|
+
execute(source: string, context: ToolExecutionContext, signal?: AbortSignal, tools?: NotebookToolDefinition[]): Promise<RuntimeResponse>;
|
|
37
|
+
wait(cellId: string, yieldTimeMs: number, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
38
|
+
terminate(cellId: string, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
39
|
+
shutdown(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface RuntimeContentItem {
|
|
42
|
+
type: "input_text" | "input_image";
|
|
43
|
+
text?: string;
|
|
44
|
+
image_url?: string;
|
|
45
|
+
detail?: "auto" | "low" | "high" | "original" | null;
|
|
46
|
+
}
|
|
47
|
+
interface NotebookMemoryUsage {
|
|
48
|
+
heapUsedBytes: number;
|
|
49
|
+
heapTotalBytes: number;
|
|
50
|
+
rssBytes: number;
|
|
51
|
+
externalBytes: number;
|
|
52
|
+
heapLimitBytes: number;
|
|
53
|
+
}
|
|
54
|
+
export type NotebookHook = "startup" | "tool_result";
|
|
55
|
+
export type NotebookControlRequest = {
|
|
56
|
+
action: "status";
|
|
57
|
+
query?: string | undefined;
|
|
58
|
+
} | {
|
|
59
|
+
action: "list";
|
|
60
|
+
query?: string | undefined;
|
|
61
|
+
} | {
|
|
62
|
+
action: "hook";
|
|
63
|
+
name: string;
|
|
64
|
+
event: NotebookHook | false;
|
|
65
|
+
} | {
|
|
66
|
+
action: "checkpoint";
|
|
67
|
+
} | {
|
|
68
|
+
action: "save";
|
|
69
|
+
name: string;
|
|
70
|
+
names?: string[];
|
|
71
|
+
} | {
|
|
72
|
+
action: "load";
|
|
73
|
+
name: string;
|
|
74
|
+
} | {
|
|
75
|
+
action: "pin";
|
|
76
|
+
names: string[];
|
|
77
|
+
hook?: NotebookHook | false | undefined;
|
|
78
|
+
checkpoint?: unknown;
|
|
79
|
+
} | {
|
|
80
|
+
action: "unpin";
|
|
81
|
+
names: string[];
|
|
82
|
+
} | {
|
|
83
|
+
action: "release";
|
|
84
|
+
names: string[];
|
|
85
|
+
} | {
|
|
86
|
+
action: "prune";
|
|
87
|
+
query: string;
|
|
88
|
+
} | {
|
|
89
|
+
action: "restart";
|
|
90
|
+
} | {
|
|
91
|
+
action: "diagnostics";
|
|
92
|
+
} | {
|
|
93
|
+
action: "reset";
|
|
94
|
+
};
|
|
95
|
+
export interface NotebookControlResult {
|
|
96
|
+
message: string;
|
|
97
|
+
details: Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
export type RuntimeResponse = ({
|
|
100
|
+
kind: "yielded";
|
|
101
|
+
cellId: string;
|
|
102
|
+
contentItems: RuntimeContentItem[];
|
|
103
|
+
} | {
|
|
104
|
+
kind: "terminated";
|
|
105
|
+
cellId: string;
|
|
106
|
+
contentItems: RuntimeContentItem[];
|
|
107
|
+
} | {
|
|
108
|
+
kind: "result";
|
|
109
|
+
cellId: string;
|
|
110
|
+
contentItems: RuntimeContentItem[];
|
|
111
|
+
errorText?: string | undefined;
|
|
112
|
+
}) & {
|
|
113
|
+
maxOutputTokens?: number | undefined;
|
|
114
|
+
missingCell?: true | undefined;
|
|
115
|
+
notebookMemory?: NotebookMemoryUsage | undefined;
|
|
116
|
+
};
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CodemodeWasmModule } from "@earendil-works/pi-codemode";
|
|
2
|
+
export interface JsRuntime {
|
|
3
|
+
wasm: CodemodeWasmModule;
|
|
4
|
+
moduleUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class RuntimeInstallError extends Error {
|
|
7
|
+
}
|
|
8
|
+
export declare function loadJsRuntime(stateDirectory: string, signal?: AbortSignal): Promise<JsRuntime>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsSnapshot } from "./protocol.ts";
|
|
2
|
+
export declare class JsStateStorage {
|
|
3
|
+
private readonly root;
|
|
4
|
+
private readonly session;
|
|
5
|
+
private readonly legacySession;
|
|
6
|
+
private readonly maxBytes;
|
|
7
|
+
private observed;
|
|
8
|
+
constructor(agentDir: string, cwd: string, identity: string, maxBytes: number);
|
|
9
|
+
withLock<T>(operation: () => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
10
|
+
migrateLegacy(): Promise<boolean>;
|
|
11
|
+
read(name?: string, previous?: JsSnapshot): Promise<JsSnapshot | undefined>;
|
|
12
|
+
private readPath;
|
|
13
|
+
private decode;
|
|
14
|
+
write(snapshot: JsSnapshot, name?: string): Promise<void>;
|
|
15
|
+
reset(): Promise<void>;
|
|
16
|
+
list(query?: string): Promise<string[]>;
|
|
17
|
+
private path;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JSValueHandle, QuickJS } from "quickjs-wasi";
|
|
2
|
+
import type { NotebookHook } from "./runtime-contract.ts";
|
|
3
|
+
export declare const JS_SUPPORT_SOURCE: string;
|
|
4
|
+
export declare class JsSupport {
|
|
5
|
+
readonly token: number;
|
|
6
|
+
private readonly vm;
|
|
7
|
+
constructor(vm: QuickJS, token?: number);
|
|
8
|
+
call(name: string, ...args: JSValueHandle[]): JSValueHandle;
|
|
9
|
+
identity(value: JSValueHandle, suppliedId?: string): string;
|
|
10
|
+
isExtensible(value: JSValueHandle): boolean;
|
|
11
|
+
register(name: string, event: NotebookHook | false, fn: JSValueHandle): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NotebookToolDefinition, ToolExecutionContext } from "./runtime-contract.ts";
|
|
2
|
+
/** Per-cell ownership for ordinary Durable registrations, not a Pi delegate adapter. */
|
|
3
|
+
export declare class NativeToolCalls {
|
|
4
|
+
private readonly cells;
|
|
5
|
+
bindCell(id: string, context: ToolExecutionContext, tools: Map<string, NotebookToolDefinition>, signal: AbortSignal): void;
|
|
6
|
+
updateCellContext(id: string, context: ToolExecutionContext): void;
|
|
7
|
+
invokeDirect(cellId: string, id: number, name: string, input: unknown): Promise<unknown>;
|
|
8
|
+
cancelCell(id: string): void;
|
|
9
|
+
closeCell(id: string): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|