@howaboua/pi-durable-js-notebook 0.10.0 → 0.11.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/README.md
CHANGED
|
@@ -7,7 +7,7 @@ The component registers `exec`, `wait`, `notebook`, `exec_command` and `write_st
|
|
|
7
7
|
## Host setup
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.
|
|
10
|
+
npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.11.0/howaboua-pi-durable-js-notebook-0.11.0.tgz
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Use Node.js 22.19 or later. Bun hosts are rejected because worker termination is part of the cancellation boundary. Install the package and its declared Durable peers through your application's package manager. QuickJS and its WASM loader use exact versions. If the installed runtime is unavailable, the component can provision its owned cache on first use and reuse it offline.
|
package/dist/activation.js
CHANGED
|
@@ -606,8 +606,14 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
606
606
|
return work;
|
|
607
607
|
};
|
|
608
608
|
const live = await api.watchDoc(LiveDoc2, api.conversationId, context);
|
|
609
|
-
cell.start((
|
|
610
|
-
|
|
609
|
+
cell.start((call) => own(async () => {
|
|
610
|
+
if (call.kind === "failed")
|
|
611
|
+
throw call.error;
|
|
612
|
+
await publish(call.value);
|
|
613
|
+
}));
|
|
614
|
+
live?.start((call) => own(async () => {
|
|
615
|
+
if (call.kind === "failed")
|
|
616
|
+
throw call.error;
|
|
611
617
|
await api.commit(async (tx) => {
|
|
612
618
|
const record = await tx.task(id);
|
|
613
619
|
if (record === undefined || record.state.status === "terminal")
|
|
@@ -627,7 +633,7 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
627
633
|
const endings = await Promise.all([cell.stop(), live?.stop()]);
|
|
628
634
|
await Promise.all([...pending]);
|
|
629
635
|
for (const ending of endings)
|
|
630
|
-
if (ending?.
|
|
636
|
+
if (ending?.kind === "listener_error" || ending?.kind === "failed")
|
|
631
637
|
throw ending.error;
|
|
632
638
|
};
|
|
633
639
|
}
|
|
@@ -1110,6 +1116,7 @@ function combineControls(controls, allowTermination = true) {
|
|
|
1110
1116
|
|
|
1111
1117
|
// packages/execution/src/tool-contract.ts
|
|
1112
1118
|
import { copyJson as copyJson7 } from "@earendil-works/chord";
|
|
1119
|
+
var nestedToolDiscoveryGuidance = "Tools without a shown call signature: help is required only while their current arguments are unknown. Call with no arguments and read the result before composing an operation. Reuse known arguments without repeating help. Structured discovery uses {}";
|
|
1113
1120
|
function readToolContract(tool) {
|
|
1114
1121
|
const candidate = "executionHints" in tool ? tool.executionHints : undefined;
|
|
1115
1122
|
if (candidate !== undefined && (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))) {
|
|
@@ -1475,14 +1482,14 @@ function forwardingHook() {
|
|
|
1475
1482
|
import {
|
|
1476
1483
|
defineTask as defineTask2
|
|
1477
1484
|
} from "@earendil-works/pi-durable";
|
|
1478
|
-
import {
|
|
1485
|
+
import { compile as compile2 } from "@earendil-works/pi-schema";
|
|
1479
1486
|
|
|
1480
1487
|
// packages/execution/src/nested-call.ts
|
|
1481
1488
|
import { validateToolArguments } from "@earendil-works/pi-ai/utils/validation";
|
|
1482
1489
|
import {
|
|
1483
1490
|
ToolTask as ToolTask4
|
|
1484
1491
|
} from "@earendil-works/pi-durable";
|
|
1485
|
-
import {
|
|
1492
|
+
import { compile } from "@earendil-works/pi-schema";
|
|
1486
1493
|
function nestedCall(runtime, input) {
|
|
1487
1494
|
const args = input.arguments;
|
|
1488
1495
|
return {
|
|
@@ -1503,7 +1510,7 @@ function prepareNestedInput(tool, input) {
|
|
|
1503
1510
|
if (typeof input !== "string")
|
|
1504
1511
|
return input;
|
|
1505
1512
|
const contract = readToolContract(tool);
|
|
1506
|
-
if (Boolean(
|
|
1513
|
+
if (Boolean(compile(tool.parameters).check(input)) || (typeof contract.inputSchema === "boolean" || typeof contract.inputSchema === "object" && contract.inputSchema !== null && !Array.isArray(contract.inputSchema)) && Boolean(compile(contract.inputSchema).check(input)))
|
|
1507
1514
|
return input;
|
|
1508
1515
|
const text = input.trim();
|
|
1509
1516
|
if (contract.discovery === "help" && text === "help")
|
|
@@ -1666,9 +1673,9 @@ function createNestedToolTask(name) {
|
|
|
1666
1673
|
return reject(runtime, call, executionError("tool_unavailable", `Tool ${call.name} is not available`), agent, tool, context);
|
|
1667
1674
|
let args;
|
|
1668
1675
|
try {
|
|
1669
|
-
const supplied = task.input.arguments === null && !
|
|
1676
|
+
const supplied = task.input.arguments === null && !compile2(tool.parameters).check(null) && compile2(tool.parameters).check({}) ? undefined : task.input.arguments;
|
|
1670
1677
|
const prepared = tool.prepareArguments === undefined ? prepareNestedInput(tool, supplied) : tool.prepareArguments(prepareNestedInput(tool, supplied));
|
|
1671
|
-
args = checked(tool, call, prepared === undefined &&
|
|
1678
|
+
args = checked(tool, call, prepared === undefined && compile2(tool.parameters).check({}) ? {} : prepared);
|
|
1672
1679
|
if (task.input.arguments === null || typeof task.input.arguments !== "object" || Array.isArray(task.input.arguments))
|
|
1673
1680
|
call.arguments = args;
|
|
1674
1681
|
} catch (error) {
|
|
@@ -1808,7 +1815,7 @@ function finishResult(tool, name, result) {
|
|
|
1808
1815
|
} else if (final.structuredOutput === undefined) {
|
|
1809
1816
|
if (!final.isError)
|
|
1810
1817
|
throw new Error(`Tool ${name} returned no structuredOutput`);
|
|
1811
|
-
} else if (!
|
|
1818
|
+
} else if (!compile2(tool.structuredOutputSchema).check(final.structuredOutput)) {
|
|
1812
1819
|
throw new Error(`Tool ${name} returned structuredOutput that does not match its schema`);
|
|
1813
1820
|
}
|
|
1814
1821
|
} catch (error) {
|
|
@@ -4193,7 +4200,7 @@ async function runtimePackage(name, version, stateDirectory, signal) {
|
|
|
4193
4200
|
}
|
|
4194
4201
|
async function loadJsRuntime(stateDirectory, signal) {
|
|
4195
4202
|
signal?.throwIfAborted();
|
|
4196
|
-
const installed = await runtimePackage("@earendil-works/pi-codemode", "1.
|
|
4203
|
+
const installed = await runtimePackage("@earendil-works/pi-codemode", "1.5.0", stateDirectory, signal);
|
|
4197
4204
|
const manifest = JSON.parse(await readFile3(installed.manifest, "utf8"));
|
|
4198
4205
|
if (!manifest || typeof manifest !== "object" || !("main" in manifest) || typeof manifest.main !== "string")
|
|
4199
4206
|
throw new Error("The JS Notebook runtime package is incomplete; reinstall it, then retry");
|
|
@@ -5947,11 +5954,7 @@ function createJsNotebookMode(options) {
|
|
|
5947
5954
|
section("notebook", (input) => {
|
|
5948
5955
|
const base = 'exec: JavaScript with top-level await in a persistent QuickJS VM. Closures, classes and cyclic data survive checkpoints without replay. Bare values are discarded. Use text(value), image(value), notify(value), store(key,value), load(key), exit() and yield_control(). ALL_TOOLS lists selected registrations. Normal cells share project state. A leading // @exec: {"isolated":true} forks the last committed state and saves a candidate without adopting it. Whole-notebook profile loads replace live state. External effects are never rolled back. Node APIs and imports are unavailable inside the VM.';
|
|
5949
5956
|
const promoted = input.agent.callable.filter((tool) => !["exec", "wait", "notebook"].includes(tool.name)).map(readToolContract).filter((contract) => !contract.nativeOnly && !contract.deferLoading).map((contract) => contract.prompt);
|
|
5950
|
-
return [
|
|
5951
|
-
base,
|
|
5952
|
-
"For tools listed without a call signature, call with no arguments to get usage without performing an operation. Structured calls use {}.",
|
|
5953
|
-
...promoted
|
|
5954
|
-
].join(`
|
|
5957
|
+
return [base, nestedToolDiscoveryGuidance, ...promoted].join(`
|
|
5955
5958
|
`);
|
|
5956
5959
|
})
|
|
5957
5960
|
]
|
|
@@ -56,7 +56,7 @@ export declare function createCustomCommands(options: LiveCustomCommandOptions,
|
|
|
56
56
|
tasks?: readonly import("@earendil-works/pi-durable").AnyTask[];
|
|
57
57
|
hooks: import("@earendil-works/pi-durable").HookRegistration[];
|
|
58
58
|
};
|
|
59
|
-
refresh: (refreshContext: Context) => Promise<import("@earendil-works/pi-durable").RegistrySnapshot<import("@earendil-works/pi-durable").ToolRegistration<
|
|
59
|
+
refresh: (refreshContext: Context) => Promise<import("@earendil-works/pi-durable").RegistrySnapshot<import("@earendil-works/pi-durable").ToolRegistration<object, import("@earendil-works/chord").JsonValue>>>;
|
|
60
60
|
readonly errors: readonly CustomCommandDiscoveryError[];
|
|
61
61
|
close(): Promise<void>;
|
|
62
62
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type JsonValue } from "@earendil-works/chord";
|
|
2
|
-
import type { TSchema } from "@earendil-works/pi-ai";
|
|
3
2
|
import type { ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
export declare const nestedToolDiscoveryGuidance = "Tools without a shown call signature: help is required only while their current arguments are unknown. Call with no arguments and read the result before composing an operation. Reuse known arguments without repeating help. Structured discovery uses {}";
|
|
4
4
|
/** Optional runtime presentation and observation policy on an ordinary registration. */
|
|
5
5
|
export interface ExecutionToolHints {
|
|
6
6
|
readonly usage?: string;
|
|
@@ -13,7 +13,7 @@ export interface ExecutionToolHints {
|
|
|
13
13
|
/** Keep the tool on the provider surface and prohibit calls from execution cells. */
|
|
14
14
|
readonly nativeOnly?: boolean;
|
|
15
15
|
}
|
|
16
|
-
export type ExecutionToolRegistration<T extends
|
|
16
|
+
export type ExecutionToolRegistration<T extends object = object, D extends JsonValue = JsonValue> = ToolRegistration<T, D> & {
|
|
17
17
|
readonly executionHints?: ExecutionToolHints;
|
|
18
18
|
};
|
|
19
19
|
interface ExecutionToolContract {
|
package/dist/index.js
CHANGED
|
@@ -596,8 +596,14 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
596
596
|
return work;
|
|
597
597
|
};
|
|
598
598
|
const live = await api.watchDoc(LiveDoc2, api.conversationId, context);
|
|
599
|
-
cell.start((
|
|
600
|
-
|
|
599
|
+
cell.start((call) => own(async () => {
|
|
600
|
+
if (call.kind === "failed")
|
|
601
|
+
throw call.error;
|
|
602
|
+
await publish(call.value);
|
|
603
|
+
}));
|
|
604
|
+
live?.start((call) => own(async () => {
|
|
605
|
+
if (call.kind === "failed")
|
|
606
|
+
throw call.error;
|
|
601
607
|
await api.commit(async (tx) => {
|
|
602
608
|
const record = await tx.task(id);
|
|
603
609
|
if (record === undefined || record.state.status === "terminal")
|
|
@@ -617,7 +623,7 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
617
623
|
const endings = await Promise.all([cell.stop(), live?.stop()]);
|
|
618
624
|
await Promise.all([...pending]);
|
|
619
625
|
for (const ending of endings)
|
|
620
|
-
if (ending?.
|
|
626
|
+
if (ending?.kind === "listener_error" || ending?.kind === "failed")
|
|
621
627
|
throw ending.error;
|
|
622
628
|
};
|
|
623
629
|
}
|
|
@@ -1100,6 +1106,7 @@ function combineControls(controls, allowTermination = true) {
|
|
|
1100
1106
|
|
|
1101
1107
|
// packages/execution/src/tool-contract.ts
|
|
1102
1108
|
import { copyJson as copyJson7 } from "@earendil-works/chord";
|
|
1109
|
+
var nestedToolDiscoveryGuidance = "Tools without a shown call signature: help is required only while their current arguments are unknown. Call with no arguments and read the result before composing an operation. Reuse known arguments without repeating help. Structured discovery uses {}";
|
|
1103
1110
|
function readToolContract(tool) {
|
|
1104
1111
|
const candidate = "executionHints" in tool ? tool.executionHints : undefined;
|
|
1105
1112
|
if (candidate !== undefined && (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))) {
|
|
@@ -1465,14 +1472,14 @@ function forwardingHook() {
|
|
|
1465
1472
|
import {
|
|
1466
1473
|
defineTask as defineTask2
|
|
1467
1474
|
} from "@earendil-works/pi-durable";
|
|
1468
|
-
import {
|
|
1475
|
+
import { compile as compile2 } from "@earendil-works/pi-schema";
|
|
1469
1476
|
|
|
1470
1477
|
// packages/execution/src/nested-call.ts
|
|
1471
1478
|
import { validateToolArguments } from "@earendil-works/pi-ai/utils/validation";
|
|
1472
1479
|
import {
|
|
1473
1480
|
ToolTask as ToolTask4
|
|
1474
1481
|
} from "@earendil-works/pi-durable";
|
|
1475
|
-
import {
|
|
1482
|
+
import { compile } from "@earendil-works/pi-schema";
|
|
1476
1483
|
function nestedCall(runtime, input) {
|
|
1477
1484
|
const args = input.arguments;
|
|
1478
1485
|
return {
|
|
@@ -1493,7 +1500,7 @@ function prepareNestedInput(tool, input) {
|
|
|
1493
1500
|
if (typeof input !== "string")
|
|
1494
1501
|
return input;
|
|
1495
1502
|
const contract = readToolContract(tool);
|
|
1496
|
-
if (Boolean(
|
|
1503
|
+
if (Boolean(compile(tool.parameters).check(input)) || (typeof contract.inputSchema === "boolean" || typeof contract.inputSchema === "object" && contract.inputSchema !== null && !Array.isArray(contract.inputSchema)) && Boolean(compile(contract.inputSchema).check(input)))
|
|
1497
1504
|
return input;
|
|
1498
1505
|
const text = input.trim();
|
|
1499
1506
|
if (contract.discovery === "help" && text === "help")
|
|
@@ -1656,9 +1663,9 @@ function createNestedToolTask(name) {
|
|
|
1656
1663
|
return reject(runtime, call, executionError("tool_unavailable", `Tool ${call.name} is not available`), agent, tool, context);
|
|
1657
1664
|
let args;
|
|
1658
1665
|
try {
|
|
1659
|
-
const supplied = task.input.arguments === null && !
|
|
1666
|
+
const supplied = task.input.arguments === null && !compile2(tool.parameters).check(null) && compile2(tool.parameters).check({}) ? undefined : task.input.arguments;
|
|
1660
1667
|
const prepared = tool.prepareArguments === undefined ? prepareNestedInput(tool, supplied) : tool.prepareArguments(prepareNestedInput(tool, supplied));
|
|
1661
|
-
args = checked(tool, call, prepared === undefined &&
|
|
1668
|
+
args = checked(tool, call, prepared === undefined && compile2(tool.parameters).check({}) ? {} : prepared);
|
|
1662
1669
|
if (task.input.arguments === null || typeof task.input.arguments !== "object" || Array.isArray(task.input.arguments))
|
|
1663
1670
|
call.arguments = args;
|
|
1664
1671
|
} catch (error) {
|
|
@@ -1798,7 +1805,7 @@ function finishResult(tool, name, result) {
|
|
|
1798
1805
|
} else if (final.structuredOutput === undefined) {
|
|
1799
1806
|
if (!final.isError)
|
|
1800
1807
|
throw new Error(`Tool ${name} returned no structuredOutput`);
|
|
1801
|
-
} else if (!
|
|
1808
|
+
} else if (!compile2(tool.structuredOutputSchema).check(final.structuredOutput)) {
|
|
1802
1809
|
throw new Error(`Tool ${name} returned structuredOutput that does not match its schema`);
|
|
1803
1810
|
}
|
|
1804
1811
|
} catch (error) {
|
|
@@ -4183,7 +4190,7 @@ async function runtimePackage(name, version, stateDirectory, signal) {
|
|
|
4183
4190
|
}
|
|
4184
4191
|
async function loadJsRuntime(stateDirectory, signal) {
|
|
4185
4192
|
signal?.throwIfAborted();
|
|
4186
|
-
const installed = await runtimePackage("@earendil-works/pi-codemode", "1.
|
|
4193
|
+
const installed = await runtimePackage("@earendil-works/pi-codemode", "1.5.0", stateDirectory, signal);
|
|
4187
4194
|
const manifest = JSON.parse(await readFile3(installed.manifest, "utf8"));
|
|
4188
4195
|
if (!manifest || typeof manifest !== "object" || !("main" in manifest) || typeof manifest.main !== "string")
|
|
4189
4196
|
throw new Error("The JS Notebook runtime package is incomplete; reinstall it, then retry");
|
|
@@ -6301,11 +6308,7 @@ function createJsNotebookMode(options) {
|
|
|
6301
6308
|
section("notebook", (input) => {
|
|
6302
6309
|
const base = 'exec: JavaScript with top-level await in a persistent QuickJS VM. Closures, classes and cyclic data survive checkpoints without replay. Bare values are discarded. Use text(value), image(value), notify(value), store(key,value), load(key), exit() and yield_control(). ALL_TOOLS lists selected registrations. Normal cells share project state. A leading // @exec: {"isolated":true} forks the last committed state and saves a candidate without adopting it. Whole-notebook profile loads replace live state. External effects are never rolled back. Node APIs and imports are unavailable inside the VM.';
|
|
6303
6310
|
const promoted = input.agent.callable.filter((tool) => !["exec", "wait", "notebook"].includes(tool.name)).map(readToolContract).filter((contract) => !contract.nativeOnly && !contract.deferLoading).map((contract) => contract.prompt);
|
|
6304
|
-
return [
|
|
6305
|
-
base,
|
|
6306
|
-
"For tools listed without a call signature, call with no arguments to get usage without performing an operation. Structured calls use {}.",
|
|
6307
|
-
...promoted
|
|
6308
|
-
].join(`
|
|
6311
|
+
return [base, nestedToolDiscoveryGuidance, ...promoted].join(`
|
|
6309
6312
|
`);
|
|
6310
6313
|
})
|
|
6311
6314
|
]
|
|
@@ -32,7 +32,7 @@ export declare function createJsNotebookMode(options: JsNotebookModeOptions): {
|
|
|
32
32
|
prepareArguments?(args: unknown): {
|
|
33
33
|
input?: string;
|
|
34
34
|
};
|
|
35
|
-
structuredOutputSchema?:
|
|
35
|
+
structuredOutputSchema?: object;
|
|
36
36
|
callers?: readonly ("model" | "tools")[];
|
|
37
37
|
deferred?: true;
|
|
38
38
|
outputLimits?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-durable-js-notebook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Persistent QuickJS notebook and shell tools for Pi Durable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"typebox": "1.3.27",
|
|
43
43
|
"acorn": "8.19.0",
|
|
44
44
|
"quickjs-wasi": "3.6.3",
|
|
45
|
-
"@earendil-works/pi-codemode": "1.
|
|
46
|
-
"@howaboua/pi-durable-components": "0.
|
|
45
|
+
"@earendil-works/pi-codemode": "1.5.0",
|
|
46
|
+
"@howaboua/pi-durable-components": "0.11.0",
|
|
47
|
+
"@earendil-works/pi-schema": "1.5.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@earendil-works/chord": "1.
|
|
50
|
-
"@earendil-works/pi-ai": "1.
|
|
51
|
-
"@earendil-works/pi-durable": "1.
|
|
50
|
+
"@earendil-works/chord": "1.5.0",
|
|
51
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
52
|
+
"@earendil-works/pi-durable": "1.5.0",
|
|
52
53
|
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
53
54
|
},
|
|
54
55
|
"publishConfig": {
|