@howaboua/pi-durable-notebook 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/NOTICE +54 -0
- package/README.md +105 -2
- package/dist/activation.js +11433 -0
- 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/history.d.ts +14 -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/history.js +315 -0
- package/dist/index.js +11718 -0
- package/dist/notebook/src/activation.d.ts +5 -0
- package/dist/notebook/src/binding-metadata-source.d.ts +2 -0
- package/dist/notebook/src/bridge-protocol.d.ts +29 -0
- package/dist/notebook/src/bridge-server.d.ts +20 -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-manager.d.ts +41 -0
- package/dist/notebook/src/checkpoint-runtime.d.ts +18 -0
- package/dist/notebook/src/checkpoint-store.d.ts +8 -0
- package/dist/notebook/src/checkpoint.d.ts +15 -0
- package/dist/notebook/src/client.d.ts +18 -0
- package/dist/notebook/src/command-output.d.ts +1 -0
- package/dist/notebook/src/control-contract.d.ts +5 -0
- package/dist/notebook/src/deno-archive.d.ts +2 -0
- package/dist/notebook/src/deno-assets.d.ts +11 -0
- package/dist/notebook/src/deno-binary.d.ts +6 -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/engine.d.ts +21 -0
- package/dist/notebook/src/execution-runtime.d.ts +33 -0
- package/dist/notebook/src/execution-settlement.d.ts +15 -0
- package/dist/notebook/src/glob.d.ts +1 -0
- package/dist/notebook/src/history.d.ts +6 -0
- package/dist/notebook/src/index.d.ts +57 -0
- package/dist/notebook/src/isolated-runtime.d.ts +19 -0
- package/dist/notebook/src/isolated-storage.d.ts +2 -0
- package/dist/notebook/src/journal-document.d.ts +36 -0
- package/dist/notebook/src/journal.d.ts +37 -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/lifecycle-contract.d.ts +32 -0
- package/dist/notebook/src/lifecycle-inspection.d.ts +7 -0
- package/dist/notebook/src/lifecycle-pins.d.ts +10 -0
- package/dist/notebook/src/lifecycle-release.d.ts +12 -0
- package/dist/notebook/src/lifecycle-result.d.ts +43 -0
- package/dist/notebook/src/lifecycle-runtime.d.ts +35 -0
- package/dist/notebook/src/lifecycle.d.ts +13 -0
- package/dist/notebook/src/lsp-process.d.ts +23 -0
- package/dist/notebook/src/notebook-bootstrap.d.ts +1 -0
- package/dist/notebook/src/notebook-control.d.ts +26 -0
- package/dist/notebook/src/notebook-diagnostic-report.d.ts +25 -0
- package/dist/notebook/src/notebook-diagnostics.d.ts +10 -0
- package/dist/notebook/src/npm-imports.d.ts +10 -0
- package/dist/notebook/src/presentation.d.ts +3 -0
- package/dist/notebook/src/profile-lifecycle.d.ts +22 -0
- package/dist/notebook/src/profile-state-format.d.ts +36 -0
- package/dist/notebook/src/profile-state.d.ts +29 -0
- package/dist/notebook/src/project-identity.d.ts +1 -0
- package/dist/notebook/src/project-state-commit.d.ts +23 -0
- package/dist/notebook/src/project-state-conflicts.d.ts +7 -0
- package/dist/notebook/src/project-state-files.d.ts +9 -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/project-state-merge.d.ts +31 -0
- package/dist/notebook/src/project-state-metadata.d.ts +20 -0
- package/dist/notebook/src/project-state-runtime.d.ts +13 -0
- package/dist/notebook/src/project-state.d.ts +18 -0
- package/dist/notebook/src/recovery.d.ts +28 -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/session-identity.d.ts +2 -0
- package/dist/notebook/src/session-observations.d.ts +35 -0
- package/dist/notebook/src/session-runtime.d.ts +48 -0
- package/dist/notebook/src/session-startup.d.ts +23 -0
- package/dist/notebook/src/storage-retention.d.ts +21 -0
- package/dist/notebook/src/tool-callbacks.d.ts +20 -0
- package/dist/notebook/src/tool-observation.d.ts +21 -0
- package/dist/presentation.js +144 -0
- package/package.json +78 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { KernelExecutionResult } from "./jupyter-kernel.ts";
|
|
2
|
+
import { type ProjectStateManifest } from "./project-state-format.ts";
|
|
3
|
+
export declare function projectBindingNamesSource(marker: string): string;
|
|
4
|
+
export declare function parseProjectBindingNames(result: KernelExecutionResult, marker: string): string[];
|
|
5
|
+
export declare function promoteProjectBindingsSource(names: string[]): string;
|
|
6
|
+
export declare function syncProjectBindingsSource(names: string[]): string;
|
|
7
|
+
export declare function projectStateCaptureSource(options: {
|
|
8
|
+
candidates: string[];
|
|
9
|
+
payloadPath: string;
|
|
10
|
+
manifestPath: string;
|
|
11
|
+
maxBytes: number;
|
|
12
|
+
}): string;
|
|
13
|
+
export declare function projectStateRestoreSource(manifest: Pick<ProjectStateManifest, "entries">, payloadPath: string, clearNames?: string[]): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DenoJupyterKernel } from "./jupyter-kernel.ts";
|
|
2
|
+
import { type ProjectStateBaseline, type ProjectStateSummary } from "./project-state-format.ts";
|
|
3
|
+
import type { ProjectStatePinUpdate } from "./project-state-merge.ts";
|
|
4
|
+
export type { ProjectStateBaseline, ProjectStateSummary, } from "./project-state-format.ts";
|
|
5
|
+
export declare function restoreProjectState(kernel: DenoJupyterKernel, identity: {
|
|
6
|
+
project: string;
|
|
7
|
+
agentDir: string;
|
|
8
|
+
maxBytes: number;
|
|
9
|
+
signal?: AbortSignal | undefined;
|
|
10
|
+
}): Promise<ProjectStateSummary>;
|
|
11
|
+
export declare function writeProjectState(kernel: DenoJupyterKernel, identity: {
|
|
12
|
+
project: string;
|
|
13
|
+
session: string;
|
|
14
|
+
agentDir: string;
|
|
15
|
+
}, baseline: ProjectStateBaseline, baselineNames: ReadonlySet<string>, maxBytes: number, excludeNames?: ReadonlySet<string>, pins?: ProjectStatePinUpdate | undefined): Promise<ProjectStateSummary>;
|
|
16
|
+
export declare function promoteProjectStateBindings(kernel: DenoJupyterKernel, names: string[]): Promise<void>;
|
|
17
|
+
export declare function projectStateBindingSelection(kernel: DenoJupyterKernel, signal?: AbortSignal): Promise<string[]>;
|
|
18
|
+
export declare function syncProjectStateBindings(kernel: DenoJupyterKernel, names: string[], signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { NotebookControlResult, NotebookSessionContext, ToolExecutionContext } from "./runtime-contract.ts";
|
|
2
|
+
import type { NotebookRuntimeHealth } from "./runtime-health.ts";
|
|
3
|
+
import type { NotebookStorageRetention } from "./storage-retention.ts";
|
|
4
|
+
interface NotebookRecoveryHost {
|
|
5
|
+
stopWithoutCheckpoint(): Promise<string | undefined>;
|
|
6
|
+
startClean(context: NotebookSessionContext, signal?: AbortSignal): Promise<void>;
|
|
7
|
+
checkpointEmpty(): Promise<void>;
|
|
8
|
+
configuredProfileActive(): boolean;
|
|
9
|
+
runtimeHealth(context: NotebookSessionContext): NotebookRuntimeHealth;
|
|
10
|
+
}
|
|
11
|
+
export declare class NotebookRecoveryController {
|
|
12
|
+
private readonly agentDir;
|
|
13
|
+
private readonly maxBytes;
|
|
14
|
+
private readonly profile;
|
|
15
|
+
private readonly host;
|
|
16
|
+
private readonly storage;
|
|
17
|
+
constructor(options: {
|
|
18
|
+
agentDir: string;
|
|
19
|
+
maxBytes: number;
|
|
20
|
+
profile?: string | undefined;
|
|
21
|
+
storage: NotebookStorageRetention;
|
|
22
|
+
}, host: NotebookRecoveryHost);
|
|
23
|
+
diagnostics(context: ToolExecutionContext, signal?: AbortSignal): Promise<NotebookControlResult>;
|
|
24
|
+
unpin(names: string[], context: ToolExecutionContext, signal?: AbortSignal): Promise<NotebookControlResult>;
|
|
25
|
+
reset(context: ToolExecutionContext, signal?: AbortSignal): Promise<NotebookControlResult>;
|
|
26
|
+
private identity;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { NotebookStorageRetention } from "./storage-retention.ts";
|
|
2
|
+
export interface NotebookSessionContext {
|
|
3
|
+
cwd: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NotebookRuntimeOptions {
|
|
7
|
+
maxHeapMiB: number;
|
|
8
|
+
agentDir: string;
|
|
9
|
+
profile?: string | undefined;
|
|
10
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
11
|
+
storage?: NotebookStorageRetention | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface ToolExecutionContext {
|
|
14
|
+
cwd: string;
|
|
15
|
+
sessionContext: NotebookSessionContext;
|
|
16
|
+
onUpdate?: ((result: {
|
|
17
|
+
content: Array<{
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "image";
|
|
22
|
+
data: string;
|
|
23
|
+
mimeType: string;
|
|
24
|
+
}>;
|
|
25
|
+
details?: unknown;
|
|
26
|
+
}) => void) | undefined;
|
|
27
|
+
setBlocked?: ((id: string, active: boolean) => void) | undefined;
|
|
28
|
+
onYield?: (() => Promise<void>) | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface NotebookToolIdentity {
|
|
31
|
+
name: string;
|
|
32
|
+
namespace?: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface NotebookToolDefinition {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
usage: string;
|
|
38
|
+
help?: string | undefined;
|
|
39
|
+
textOutput?: "command" | "plain-command" | undefined;
|
|
40
|
+
invoke(input: unknown, context: ToolExecutionContext, signal: AbortSignal): Promise<unknown>;
|
|
41
|
+
}
|
|
42
|
+
export interface NotebookExecutionClient {
|
|
43
|
+
execute(source: string, context: ToolExecutionContext, signal?: AbortSignal, tools?: NotebookToolDefinition[]): Promise<RuntimeResponse>;
|
|
44
|
+
wait(cellId: string, yieldTimeMs: number, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
45
|
+
terminate(cellId: string, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
46
|
+
shutdown(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export interface RuntimeContentItem {
|
|
49
|
+
type: "input_text" | "input_image";
|
|
50
|
+
text?: string;
|
|
51
|
+
image_url?: string;
|
|
52
|
+
detail?: "auto" | "low" | "high" | "original" | null;
|
|
53
|
+
}
|
|
54
|
+
export interface NotebookMemoryUsage {
|
|
55
|
+
heapUsedBytes: number;
|
|
56
|
+
heapTotalBytes: number;
|
|
57
|
+
rssBytes: number;
|
|
58
|
+
externalBytes: number;
|
|
59
|
+
heapLimitBytes: number;
|
|
60
|
+
}
|
|
61
|
+
export type NotebookHook = "startup" | "tool_result";
|
|
62
|
+
export type NotebookControlRequest = {
|
|
63
|
+
action: "status";
|
|
64
|
+
query?: string | undefined;
|
|
65
|
+
} | {
|
|
66
|
+
action: "list";
|
|
67
|
+
query?: string | undefined;
|
|
68
|
+
} | {
|
|
69
|
+
action: "checkpoint";
|
|
70
|
+
} | {
|
|
71
|
+
action: "save";
|
|
72
|
+
name: string;
|
|
73
|
+
} | {
|
|
74
|
+
action: "load";
|
|
75
|
+
name: string;
|
|
76
|
+
} | {
|
|
77
|
+
action: "pin";
|
|
78
|
+
names: string[];
|
|
79
|
+
hook?: NotebookHook | false | undefined;
|
|
80
|
+
} | {
|
|
81
|
+
action: "unpin";
|
|
82
|
+
names: string[];
|
|
83
|
+
} | {
|
|
84
|
+
action: "release";
|
|
85
|
+
names: string[];
|
|
86
|
+
} | {
|
|
87
|
+
action: "prune";
|
|
88
|
+
query: string;
|
|
89
|
+
} | {
|
|
90
|
+
action: "restart";
|
|
91
|
+
} | {
|
|
92
|
+
action: "diagnostics";
|
|
93
|
+
} | {
|
|
94
|
+
action: "reset";
|
|
95
|
+
};
|
|
96
|
+
export interface NotebookControlResult {
|
|
97
|
+
message: string;
|
|
98
|
+
details: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
export type RuntimeResponse = ({
|
|
101
|
+
kind: "yielded";
|
|
102
|
+
cellId: string;
|
|
103
|
+
contentItems: RuntimeContentItem[];
|
|
104
|
+
} | {
|
|
105
|
+
kind: "terminated";
|
|
106
|
+
cellId: string;
|
|
107
|
+
contentItems: RuntimeContentItem[];
|
|
108
|
+
} | {
|
|
109
|
+
kind: "result";
|
|
110
|
+
cellId: string;
|
|
111
|
+
contentItems: RuntimeContentItem[];
|
|
112
|
+
errorText?: string | undefined;
|
|
113
|
+
}) & {
|
|
114
|
+
maxOutputTokens?: number | undefined;
|
|
115
|
+
missingCell?: true | undefined;
|
|
116
|
+
notebookMemory?: NotebookMemoryUsage | undefined;
|
|
117
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NotebookRuntimeHealthState = "not_started" | "ready" | "invalidated";
|
|
2
|
+
export interface NotebookRuntimeHealth {
|
|
3
|
+
state: NotebookRuntimeHealthState;
|
|
4
|
+
}
|
|
5
|
+
export declare const NOTEBOOK_INTERRUPTED_NOTICE = "Notebook runtime was invalidated by an interrupted cell. The next operation will recreate it from the last completed checkpoint; durable project bindings were preserved. External side effects were not rolled back";
|
|
6
|
+
export declare const NOTEBOOK_BOOTSTRAP_NOTICE = "Notebook runtime bootstrap was unavailable. The kernel was discarded; the next operation will recreate it from the last completed checkpoint. Durable project bindings were preserved";
|
|
7
|
+
export declare const NOTEBOOK_KERNEL_FAILURE_NOTICE = "Notebook runtime became unavailable during a host operation. The next operation will recreate it from the last completed checkpoint; durable project bindings were preserved. External side effects were not rolled back";
|
|
8
|
+
export declare function withNotebookRecoveryGuidance(message: string): string;
|
|
9
|
+
export declare function isNotebookBootstrapFailure(value: unknown): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { NotebookCheckpointIdentity } from "./checkpoint-format.ts";
|
|
2
|
+
import { type NotebookJournal } from "./journal.ts";
|
|
3
|
+
import type { NotebookMemoryUsage } from "./runtime-contract.ts";
|
|
4
|
+
import type { NotebookStorageRetention } from "./storage-retention.ts";
|
|
5
|
+
/** Runtime observations are cleared independently of durable checkpoint identity. */
|
|
6
|
+
export declare class NotebookSessionObservations {
|
|
7
|
+
private notice;
|
|
8
|
+
private memoryValue;
|
|
9
|
+
private journalValue;
|
|
10
|
+
private startedAtValue;
|
|
11
|
+
private completedCells;
|
|
12
|
+
private readonly identity;
|
|
13
|
+
private readonly checkpointStatus;
|
|
14
|
+
private readonly storage;
|
|
15
|
+
private readonly maxBytes;
|
|
16
|
+
constructor(identity: () => NotebookCheckpointIdentity | undefined, checkpointStatus: () => Record<string, unknown>, storage: NotebookStorageRetention, maxBytes: number);
|
|
17
|
+
started(journal: NotebookJournal | undefined): void;
|
|
18
|
+
resetMemory(): void;
|
|
19
|
+
clearNotice(): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
journal(): NotebookJournal | undefined;
|
|
22
|
+
recordCompletedCell(): void;
|
|
23
|
+
materializeJournal(): void;
|
|
24
|
+
recordMemory(memory: NotebookMemoryUsage | undefined): void;
|
|
25
|
+
recordNpmImports(source: string): Promise<void>;
|
|
26
|
+
memory(): NotebookMemoryUsage | undefined;
|
|
27
|
+
addNotice(notice: string): void;
|
|
28
|
+
takeNotice(): string | undefined;
|
|
29
|
+
metadata(): {
|
|
30
|
+
startedAt?: number | undefined;
|
|
31
|
+
userCells: number;
|
|
32
|
+
memory?: NotebookMemoryUsage | undefined;
|
|
33
|
+
checkpoint: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { NotebookBridgeServer } from "./bridge-server.ts";
|
|
2
|
+
import { NotebookCheckpointManager } from "./checkpoint-manager.ts";
|
|
3
|
+
import type { DenoJupyterKernel } from "./jupyter-kernel.ts";
|
|
4
|
+
import { type RetainedProjectBinding } from "./project-state-metadata.ts";
|
|
5
|
+
import type { NotebookRuntimeOptions, NotebookSessionContext, ToolExecutionContext } from "./runtime-contract.ts";
|
|
6
|
+
import { type NotebookRuntimeHealth } from "./runtime-health.ts";
|
|
7
|
+
import { NotebookSessionObservations } from "./session-observations.ts";
|
|
8
|
+
import { NotebookStorageRetention } from "./storage-retention.ts";
|
|
9
|
+
export declare class NotebookSessionRuntime {
|
|
10
|
+
readonly options: NotebookRuntimeOptions;
|
|
11
|
+
readonly checkpointMaxBytes: number;
|
|
12
|
+
readonly checkpoints: NotebookCheckpointManager;
|
|
13
|
+
readonly observations: NotebookSessionObservations;
|
|
14
|
+
readonly storage: NotebookStorageRetention;
|
|
15
|
+
private readonly bridge;
|
|
16
|
+
private readonly runningCellId;
|
|
17
|
+
private kernelValue;
|
|
18
|
+
private runtimeHealthValue;
|
|
19
|
+
private identityValue;
|
|
20
|
+
private checkpointIdentityValue;
|
|
21
|
+
private startup;
|
|
22
|
+
private startupAbort;
|
|
23
|
+
private baseline;
|
|
24
|
+
private profileLoaded;
|
|
25
|
+
private checkpointActivity;
|
|
26
|
+
constructor(options: {
|
|
27
|
+
runtime: NotebookRuntimeOptions;
|
|
28
|
+
bridge: NotebookBridgeServer;
|
|
29
|
+
runningCellId(): string | undefined;
|
|
30
|
+
});
|
|
31
|
+
identityMatches(context: NotebookSessionContext): boolean;
|
|
32
|
+
ensure(context: ToolExecutionContext, signal?: AbortSignal): Promise<void>;
|
|
33
|
+
restart(context: NotebookSessionContext, signal?: AbortSignal, skipProfile?: boolean): Promise<string | undefined>;
|
|
34
|
+
invalidateKernel(notice?: string): Promise<void>;
|
|
35
|
+
recoverFromBootstrapFailure(value: unknown): Promise<boolean>;
|
|
36
|
+
stopWithoutCheckpoint(): Promise<void>;
|
|
37
|
+
abortStartup(reason: Error): Promise<void>;
|
|
38
|
+
shutdown(): Promise<void>;
|
|
39
|
+
kernel(): DenoJupyterKernel | undefined;
|
|
40
|
+
runtimeHealth(): NotebookRuntimeHealth;
|
|
41
|
+
runtimeHealthFor(context: NotebookSessionContext): NotebookRuntimeHealth;
|
|
42
|
+
baselineNames(): ReadonlySet<string>;
|
|
43
|
+
configuredProfileLoaded(): boolean;
|
|
44
|
+
retainedBindings(): RetainedProjectBinding[];
|
|
45
|
+
private start;
|
|
46
|
+
private handleKernelFailure;
|
|
47
|
+
private beginStartup;
|
|
48
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { NotebookBridgeServer } from "./bridge-server.ts";
|
|
2
|
+
import { type NotebookCheckpointIdentity } from "./checkpoint.ts";
|
|
3
|
+
import { type NotebookJournal } from "./journal.ts";
|
|
4
|
+
import { DenoJupyterKernel } from "./jupyter-kernel.ts";
|
|
5
|
+
import { type ProjectStateBaseline } from "./project-state.ts";
|
|
6
|
+
import type { NotebookRuntimeOptions, NotebookSessionContext } from "./runtime-contract.ts";
|
|
7
|
+
export interface StartedNotebookSession {
|
|
8
|
+
kernel: DenoJupyterKernel;
|
|
9
|
+
journal: NotebookJournal | undefined;
|
|
10
|
+
checkpointIdentity: NotebookCheckpointIdentity;
|
|
11
|
+
baselineNames: Set<string>;
|
|
12
|
+
projectBaseline: ProjectStateBaseline;
|
|
13
|
+
configuredProfileLoaded: boolean;
|
|
14
|
+
restoreNotice?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function startNotebookSession(options: {
|
|
17
|
+
context: NotebookSessionContext;
|
|
18
|
+
runtime: NotebookRuntimeOptions;
|
|
19
|
+
bridge: NotebookBridgeServer;
|
|
20
|
+
checkpointMaxBytes: number;
|
|
21
|
+
onKernelFailure?: ((kernel: DenoJupyterKernel, error: Error) => void) | undefined;
|
|
22
|
+
signal?: AbortSignal | undefined;
|
|
23
|
+
}): Promise<StartedNotebookSession>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type NotebookJournalRetention = "off" | "week" | "on";
|
|
2
|
+
export type NotebookCheckpointRetention = "never" | "month" | "week";
|
|
3
|
+
export interface NotebookStoragePolicy {
|
|
4
|
+
journals?: NotebookJournalRetention;
|
|
5
|
+
checkpointCleanup?: NotebookCheckpointRetention;
|
|
6
|
+
}
|
|
7
|
+
/** Owns coalesced maintenance. The host supplies policy, never Pi-global paths. */
|
|
8
|
+
export declare class NotebookStorageRetention {
|
|
9
|
+
private pending;
|
|
10
|
+
private forceAgain;
|
|
11
|
+
readonly agentDir: string;
|
|
12
|
+
private readonly getPolicy;
|
|
13
|
+
constructor(agentDir: string, getPolicy?: () => NotebookStoragePolicy);
|
|
14
|
+
policy(): Required<NotebookStoragePolicy>;
|
|
15
|
+
schedule(): void;
|
|
16
|
+
maintain(force?: boolean): Promise<void>;
|
|
17
|
+
drain(): Promise<void>;
|
|
18
|
+
private pass;
|
|
19
|
+
}
|
|
20
|
+
export declare function notebookJournalsDirectory(agentDir: string): string;
|
|
21
|
+
export declare function removeExpiredNotebookJournalFiles(files: string[], now?: number): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NotebookBridgeServer } from "./bridge-server.ts";
|
|
2
|
+
import type { NotebookCell } from "./cell.ts";
|
|
3
|
+
import type { NotebookMemoryUsage, NotebookToolDefinition, RuntimeResponse, ToolExecutionContext } from "./runtime-contract.ts";
|
|
4
|
+
/** The kernel owns hook dispatch. This host boundary owns cancellation of its HTTP callbacks. */
|
|
5
|
+
export declare class NotebookToolCallbacks {
|
|
6
|
+
readonly bridge: NotebookBridgeServer;
|
|
7
|
+
private readonly cells;
|
|
8
|
+
constructor(options: {
|
|
9
|
+
activeCell(): NotebookCell | undefined;
|
|
10
|
+
recordMemory(usage: NotebookMemoryUsage): void;
|
|
11
|
+
});
|
|
12
|
+
bindCell(id: string, context: ToolExecutionContext, tools: Map<string, NotebookToolDefinition>): void;
|
|
13
|
+
updateCellContext(id: string, context: ToolExecutionContext): void;
|
|
14
|
+
invokeDirect(id: string, _requestId: number, name: string, input: unknown): Promise<unknown>;
|
|
15
|
+
cancelCell(id: string): void;
|
|
16
|
+
notifyDirect(id: string, text: string): void;
|
|
17
|
+
attach(response: RuntimeResponse): RuntimeResponse;
|
|
18
|
+
closeCell(id: string): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type TaskId, type ToolExecutionApi } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellObservation } from "../../execution/src/cell-contract.ts";
|
|
4
|
+
export declare function notebookCellTaskId(value: string): TaskId<import("@earendil-works/pi-durable").ToolExecutionResult>;
|
|
5
|
+
export declare function observeNotebookCell(observation: CellObservation, maxTokens: number, api: ToolExecutionApi, context: Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult | {
|
|
6
|
+
structuredOutput?: import("@earendil-works/chord").JsonValue;
|
|
7
|
+
isError?: boolean;
|
|
8
|
+
diagnostics?: readonly import("@earendil-works/pi-durable").ToolDiagnostic[];
|
|
9
|
+
usage?: import("@earendil-works/pi-ai").Usage;
|
|
10
|
+
control?: import("@earendil-works/pi-durable").ToolControl;
|
|
11
|
+
output: (import("@earendil-works/pi-ai").ImageContent | {
|
|
12
|
+
type: "text";
|
|
13
|
+
text: string;
|
|
14
|
+
})[];
|
|
15
|
+
details: {
|
|
16
|
+
cell_id: string;
|
|
17
|
+
status: "aborted" | "completed" | "failed" | "interrupted" | "running";
|
|
18
|
+
forwardedToolCalls?: import("@earendil-works/chord").JsonValue;
|
|
19
|
+
runtime?: import("@earendil-works/chord").JsonValue;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// packages/execution/src/presentation.ts
|
|
2
|
+
function object(value) {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
4
|
+
throw new TypeError("Expected execution presentation object");
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
function string(value) {
|
|
8
|
+
if (typeof value !== "string")
|
|
9
|
+
throw new TypeError("Expected string");
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function json(value, ancestors = new Set) {
|
|
13
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
14
|
+
return value;
|
|
15
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
16
|
+
return value;
|
|
17
|
+
if (typeof value !== "object" || ancestors.has(value))
|
|
18
|
+
throw new TypeError("Expected finite, acyclic JSON details");
|
|
19
|
+
ancestors.add(value);
|
|
20
|
+
try {
|
|
21
|
+
if (!Array.isArray(value))
|
|
22
|
+
object(value);
|
|
23
|
+
return Array.isArray(value) ? value.map((item) => json(item, ancestors)) : Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
24
|
+
key,
|
|
25
|
+
json(item, ancestors)
|
|
26
|
+
]));
|
|
27
|
+
} finally {
|
|
28
|
+
ancestors.delete(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function parseExecutionResultReceipt(value) {
|
|
32
|
+
if (value === null)
|
|
33
|
+
return null;
|
|
34
|
+
const fields = object(value);
|
|
35
|
+
const content = fields["content"] === undefined ? [] : fields["content"];
|
|
36
|
+
const diagnostics = fields["diagnostics"] === undefined ? [] : fields["diagnostics"];
|
|
37
|
+
const isError = fields["isError"] === undefined ? false : fields["isError"];
|
|
38
|
+
if (!Array.isArray(content) || !Array.isArray(diagnostics) || typeof isError !== "boolean")
|
|
39
|
+
throw new TypeError("Invalid execution result receipt");
|
|
40
|
+
return {
|
|
41
|
+
content: content.map((value) => {
|
|
42
|
+
const item = object(value);
|
|
43
|
+
if (item["type"] === "text")
|
|
44
|
+
return { type: "text", text: string(item["text"]) };
|
|
45
|
+
if (item["type"] === "image") {
|
|
46
|
+
const mimeType = string(item["mimeType"]);
|
|
47
|
+
const data = string(item["data"]);
|
|
48
|
+
if (!/^image\/[A-Za-z0-9][A-Za-z0-9.+-]*$/.test(mimeType) || data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data))
|
|
49
|
+
throw new TypeError("Invalid execution image");
|
|
50
|
+
return { type: "image", data, mimeType };
|
|
51
|
+
}
|
|
52
|
+
throw new TypeError("Invalid execution content type");
|
|
53
|
+
}),
|
|
54
|
+
isError,
|
|
55
|
+
details: json(fields["details"] ?? null),
|
|
56
|
+
diagnostics: diagnostics.map((value) => {
|
|
57
|
+
const item = object(value);
|
|
58
|
+
const severity = item["severity"];
|
|
59
|
+
if (severity !== "info" && severity !== "warn" && severity !== "error")
|
|
60
|
+
throw new TypeError("Invalid execution diagnostic severity");
|
|
61
|
+
return {
|
|
62
|
+
severity,
|
|
63
|
+
message: string(item["message"]),
|
|
64
|
+
...item["code"] === undefined ? {} : { code: string(item["code"]) }
|
|
65
|
+
};
|
|
66
|
+
})
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// packages/execution/src/forwarded-tools.ts
|
|
71
|
+
function object2(value) {
|
|
72
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
73
|
+
throw new TypeError("Invalid forwarded tool calls object");
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
function string2(value) {
|
|
77
|
+
if (typeof value !== "string" || !value)
|
|
78
|
+
throw new TypeError("Invalid forwarded tool identity");
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function json2(value, ancestors = new Set) {
|
|
82
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
83
|
+
return value;
|
|
84
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
85
|
+
return value;
|
|
86
|
+
if (!value || typeof value !== "object" || ancestors.has(value))
|
|
87
|
+
throw new TypeError("Invalid forwarded tool JSON");
|
|
88
|
+
ancestors.add(value);
|
|
89
|
+
try {
|
|
90
|
+
return Array.isArray(value) ? value.map((item) => json2(item, ancestors)) : Object.fromEntries(Object.entries(object2(value)).map(([key, item]) => [
|
|
91
|
+
key,
|
|
92
|
+
json2(item, ancestors)
|
|
93
|
+
]));
|
|
94
|
+
} finally {
|
|
95
|
+
ancestors.delete(value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function parseForwardedToolCalls(details) {
|
|
99
|
+
if (!details || typeof details !== "object" || !("forwardedToolCalls" in details))
|
|
100
|
+
return null;
|
|
101
|
+
const fields = object2(details.forwardedToolCalls);
|
|
102
|
+
if (fields["version"] !== 1)
|
|
103
|
+
throw new TypeError("Unsupported forwarded tool calls version");
|
|
104
|
+
const cellId = string2(fields["cellId"]);
|
|
105
|
+
if (!/^[1-9][0-9]*$/.test(cellId) || !Number.isSafeInteger(Number(cellId)))
|
|
106
|
+
throw new TypeError("Invalid forwarded cell ID");
|
|
107
|
+
const omittedCalls = fields["omittedCalls"];
|
|
108
|
+
if (typeof omittedCalls !== "number" || !Number.isSafeInteger(omittedCalls) || omittedCalls < 0 || !Array.isArray(fields["calls"]))
|
|
109
|
+
throw new TypeError("Invalid forwarded tool call list");
|
|
110
|
+
const ids = new Set;
|
|
111
|
+
const calls = fields["calls"].map((value) => {
|
|
112
|
+
const call = object2(value);
|
|
113
|
+
const callId = string2(call["callId"]);
|
|
114
|
+
if (ids.has(callId))
|
|
115
|
+
throw new TypeError("Duplicate forwarded tool call ID");
|
|
116
|
+
ids.add(callId);
|
|
117
|
+
const status = call["status"];
|
|
118
|
+
if (status !== "pending" && status !== "running" && status !== "completed" && status !== "failed" && status !== "aborted" && status !== "interrupted")
|
|
119
|
+
throw new TypeError("Invalid forwarded tool status");
|
|
120
|
+
const omitted = call["omittedFields"];
|
|
121
|
+
if (!Array.isArray(omitted) || omitted.some((field) => field !== "arguments" && field !== "result") || new Set(omitted).size !== omitted.length)
|
|
122
|
+
throw new TypeError("Invalid forwarded omitted fields");
|
|
123
|
+
const omittedFields = omitted.map((field) => {
|
|
124
|
+
if (field === "arguments" || field === "result")
|
|
125
|
+
return field;
|
|
126
|
+
throw new TypeError("Invalid forwarded omitted field");
|
|
127
|
+
});
|
|
128
|
+
if (!("arguments" in call) !== omittedFields.includes("arguments") || omittedFields.includes("result") && call["result"] !== null)
|
|
129
|
+
throw new TypeError("Inconsistent forwarded omitted fields");
|
|
130
|
+
return {
|
|
131
|
+
callId,
|
|
132
|
+
parentCallId: string2(call["parentCallId"]),
|
|
133
|
+
name: string2(call["name"]),
|
|
134
|
+
...omittedFields.includes("arguments") ? {} : { arguments: json2(call["arguments"]) },
|
|
135
|
+
status,
|
|
136
|
+
result: parseExecutionResultReceipt(json2(call["result"])),
|
|
137
|
+
omittedFields
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
return { version: 1, cellId, calls, omittedCalls };
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
parseForwardedToolCalls
|
|
144
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@howaboua/pi-durable-notebook",
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Persistent notebook execution and shell tools for Pi Durable",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IgorWarzocha/pi-durable-components.git",
|
|
10
|
+
"directory": "packages/notebook"
|
|
11
|
+
},
|
|
12
|
+
"author": "Igor Warzocha",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.19.0"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/notebook/src/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./history": {
|
|
20
|
+
"types": "./dist/notebook/src/history.d.ts",
|
|
21
|
+
"import": "./dist/history.js"
|
|
22
|
+
},
|
|
23
|
+
"./presentation": {
|
|
24
|
+
"types": "./dist/notebook/src/presentation.d.ts",
|
|
25
|
+
"import": "./dist/presentation.js"
|
|
26
|
+
},
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/notebook/src/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./component": {
|
|
32
|
+
"types": "./dist/notebook/src/activation.d.ts",
|
|
33
|
+
"import": "./dist/activation.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"NOTICE",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"node-pty": "1.1.0",
|
|
45
|
+
"smol-toml": "1.9.0",
|
|
46
|
+
"proxy-from-env": "2.1.0",
|
|
47
|
+
"undici": "8.10.2",
|
|
48
|
+
"typebox": "1.3.27",
|
|
49
|
+
"@howaboua/pi-durable-components": "0.10.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@earendil-works/chord": "1.4.0",
|
|
53
|
+
"@earendil-works/pi-ai": "1.4.0",
|
|
54
|
+
"@earendil-works/pi-durable": "1.4.0",
|
|
55
|
+
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"durable": {
|
|
61
|
+
"schemaVersion": 1,
|
|
62
|
+
"kind": "extension",
|
|
63
|
+
"entry": "./component",
|
|
64
|
+
"runtimes": [
|
|
65
|
+
"node"
|
|
66
|
+
],
|
|
67
|
+
"requires": [
|
|
68
|
+
"durable.node-execution.v1",
|
|
69
|
+
"durable.state.v1"
|
|
70
|
+
],
|
|
71
|
+
"permissions": [
|
|
72
|
+
"filesystem",
|
|
73
|
+
"process",
|
|
74
|
+
"network",
|
|
75
|
+
"storage"
|
|
76
|
+
],
|
|
77
|
+
"selectionGroup": "execution"
|
|
78
|
+
}
|
|
79
|
+
}
|