@howaboua/pi-durable-code 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
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Run JavaScript that composes ordinary Durable tools. `exec` and `wait` are the model-facing surface. Shell execution and PTY sessions are included.
|
|
4
4
|
|
|
5
|
-
Requires Node 22.19 or newer and Durable 1.
|
|
5
|
+
Requires Node 22.19 or newer and Durable 1.5.0.
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.
|
|
8
|
+
npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.11.0/howaboua-pi-durable-code-0.11.0.tgz
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
The shell's native PTY addon requires Python, Make and a C++ compiler on Linux. If install scripts are disabled, run `npm rebuild node-pty` before using interactive shells. Pipe-based commands do not require the addon.
|
package/dist/activation.js
CHANGED
|
@@ -603,8 +603,14 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
603
603
|
return work;
|
|
604
604
|
};
|
|
605
605
|
const live = await api.watchDoc(LiveDoc2, api.conversationId, context);
|
|
606
|
-
cell.start((
|
|
607
|
-
|
|
606
|
+
cell.start((call) => own(async () => {
|
|
607
|
+
if (call.kind === "failed")
|
|
608
|
+
throw call.error;
|
|
609
|
+
await publish(call.value);
|
|
610
|
+
}));
|
|
611
|
+
live?.start((call) => own(async () => {
|
|
612
|
+
if (call.kind === "failed")
|
|
613
|
+
throw call.error;
|
|
608
614
|
await api.commit(async (tx) => {
|
|
609
615
|
const record = await tx.task(id);
|
|
610
616
|
if (record === undefined || record.state.status === "terminal")
|
|
@@ -624,7 +630,7 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
624
630
|
const endings = await Promise.all([cell.stop(), live?.stop()]);
|
|
625
631
|
await Promise.all([...pending]);
|
|
626
632
|
for (const ending of endings)
|
|
627
|
-
if (ending?.
|
|
633
|
+
if (ending?.kind === "listener_error" || ending?.kind === "failed")
|
|
628
634
|
throw ending.error;
|
|
629
635
|
};
|
|
630
636
|
}
|
|
@@ -1107,6 +1113,7 @@ function combineControls(controls, allowTermination = true) {
|
|
|
1107
1113
|
|
|
1108
1114
|
// packages/execution/src/tool-contract.ts
|
|
1109
1115
|
import { copyJson as copyJson7 } from "@earendil-works/chord";
|
|
1116
|
+
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 {}";
|
|
1110
1117
|
function readToolContract(tool) {
|
|
1111
1118
|
const candidate = "executionHints" in tool ? tool.executionHints : undefined;
|
|
1112
1119
|
if (candidate !== undefined && (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))) {
|
|
@@ -1472,14 +1479,14 @@ function forwardingHook() {
|
|
|
1472
1479
|
import {
|
|
1473
1480
|
defineTask as defineTask2
|
|
1474
1481
|
} from "@earendil-works/pi-durable";
|
|
1475
|
-
import {
|
|
1482
|
+
import { compile as compile2 } from "@earendil-works/pi-schema";
|
|
1476
1483
|
|
|
1477
1484
|
// packages/execution/src/nested-call.ts
|
|
1478
1485
|
import { validateToolArguments } from "@earendil-works/pi-ai/utils/validation";
|
|
1479
1486
|
import {
|
|
1480
1487
|
ToolTask as ToolTask4
|
|
1481
1488
|
} from "@earendil-works/pi-durable";
|
|
1482
|
-
import {
|
|
1489
|
+
import { compile } from "@earendil-works/pi-schema";
|
|
1483
1490
|
function nestedCall(runtime, input) {
|
|
1484
1491
|
const args = input.arguments;
|
|
1485
1492
|
return {
|
|
@@ -1500,7 +1507,7 @@ function prepareNestedInput(tool, input) {
|
|
|
1500
1507
|
if (typeof input !== "string")
|
|
1501
1508
|
return input;
|
|
1502
1509
|
const contract = readToolContract(tool);
|
|
1503
|
-
if (Boolean(
|
|
1510
|
+
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)))
|
|
1504
1511
|
return input;
|
|
1505
1512
|
const text = input.trim();
|
|
1506
1513
|
if (contract.discovery === "help" && text === "help")
|
|
@@ -1663,9 +1670,9 @@ function createNestedToolTask(name) {
|
|
|
1663
1670
|
return reject(runtime, call, executionError("tool_unavailable", `Tool ${call.name} is not available`), agent, tool, context);
|
|
1664
1671
|
let args;
|
|
1665
1672
|
try {
|
|
1666
|
-
const supplied = task.input.arguments === null && !
|
|
1673
|
+
const supplied = task.input.arguments === null && !compile2(tool.parameters).check(null) && compile2(tool.parameters).check({}) ? undefined : task.input.arguments;
|
|
1667
1674
|
const prepared = tool.prepareArguments === undefined ? prepareNestedInput(tool, supplied) : tool.prepareArguments(prepareNestedInput(tool, supplied));
|
|
1668
|
-
args = checked(tool, call, prepared === undefined &&
|
|
1675
|
+
args = checked(tool, call, prepared === undefined && compile2(tool.parameters).check({}) ? {} : prepared);
|
|
1669
1676
|
if (task.input.arguments === null || typeof task.input.arguments !== "object" || Array.isArray(task.input.arguments))
|
|
1670
1677
|
call.arguments = args;
|
|
1671
1678
|
} catch (error) {
|
|
@@ -1805,7 +1812,7 @@ function finishResult(tool, name, result) {
|
|
|
1805
1812
|
} else if (final.structuredOutput === undefined) {
|
|
1806
1813
|
if (!final.isError)
|
|
1807
1814
|
throw new Error(`Tool ${name} returned no structuredOutput`);
|
|
1808
|
-
} else if (!
|
|
1815
|
+
} else if (!compile2(tool.structuredOutputSchema).check(final.structuredOutput)) {
|
|
1809
1816
|
throw new Error(`Tool ${name} returned structuredOutput that does not match its schema`);
|
|
1810
1817
|
}
|
|
1811
1818
|
} catch (error) {
|
|
@@ -4677,7 +4684,7 @@ function createCodeMode(options) {
|
|
|
4677
4684
|
const usage = input.agent.callable.filter((tool) => tool.name !== "exec" && tool.name !== "wait").map(readToolContract).filter((contract) => !contract.nativeOnly && !contract.deferLoading).map((contract) => contract.prompt).join(`
|
|
4678
4685
|
`);
|
|
4679
4686
|
return [
|
|
4680
|
-
|
|
4687
|
+
nestedToolDiscoveryGuidance,
|
|
4681
4688
|
'exec accepts JavaScript source with optional // @exec: {"yield_time_ms":30000,"max_output_tokens":10000}. Await work and emit with text(value), image(value), generatedImage(value), notify(value). tools contains ordinary registered tools. ALL_TOOLS lists callable contracts. store(key,value)/load(key) retain serializable values between cells. Cells have no filesystem, network or Node globals. Shell tools follow the conversation environment. Use wait for exec cells and tools.write_stdin for shell sessions.',
|
|
4682
4689
|
usage
|
|
4683
4690
|
].filter(Boolean).join(`
|
|
@@ -2,5 +2,5 @@ export type { ExecutionHistoryRequest } from "../../execution/src/history.ts";
|
|
|
2
2
|
export declare const readForwardedToolCalls: (harness: {
|
|
3
3
|
conversation: (id: import("@earendil-works/pi-durable").ConversationId, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").Conversation | undefined>;
|
|
4
4
|
getTask: <R>(id: import("@earendil-works/pi-durable").TaskId<R>, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").TaskRecord<import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue, R> | undefined>;
|
|
5
|
-
commit: <T>(change: (tx: import("@earendil-works/pi-durable").Tx) => T | Promise<T>, context: import("@earendil-works/chord").Context) => Promise<T>;
|
|
5
|
+
commit: <T>(change: (tx: import("@earendil-works/pi-durable").Tx) => T | Promise<T>, context: import("@earendil-works/chord").Context, options?: import("@earendil-works/pi-durable").CommitOptions) => Promise<T>;
|
|
6
6
|
}, request: import("../../execution/src/history.ts").ExecutionHistoryRequest, context: import("@earendil-works/chord").Context) => Promise<ReadonlyMap<string, import("./presentation.ts").ForwardedToolCalls>>;
|
|
@@ -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
|
@@ -593,8 +593,14 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
593
593
|
return work;
|
|
594
594
|
};
|
|
595
595
|
const live = await api.watchDoc(LiveDoc2, api.conversationId, context);
|
|
596
|
-
cell.start((
|
|
597
|
-
|
|
596
|
+
cell.start((call) => own(async () => {
|
|
597
|
+
if (call.kind === "failed")
|
|
598
|
+
throw call.error;
|
|
599
|
+
await publish(call.value);
|
|
600
|
+
}));
|
|
601
|
+
live?.start((call) => own(async () => {
|
|
602
|
+
if (call.kind === "failed")
|
|
603
|
+
throw call.error;
|
|
598
604
|
await api.commit(async (tx) => {
|
|
599
605
|
const record = await tx.task(id);
|
|
600
606
|
if (record === undefined || record.state.status === "terminal")
|
|
@@ -614,7 +620,7 @@ async function observeCellProgress(id, api, context, budget) {
|
|
|
614
620
|
const endings = await Promise.all([cell.stop(), live?.stop()]);
|
|
615
621
|
await Promise.all([...pending]);
|
|
616
622
|
for (const ending of endings)
|
|
617
|
-
if (ending?.
|
|
623
|
+
if (ending?.kind === "listener_error" || ending?.kind === "failed")
|
|
618
624
|
throw ending.error;
|
|
619
625
|
};
|
|
620
626
|
}
|
|
@@ -1097,6 +1103,7 @@ function combineControls(controls, allowTermination = true) {
|
|
|
1097
1103
|
|
|
1098
1104
|
// packages/execution/src/tool-contract.ts
|
|
1099
1105
|
import { copyJson as copyJson7 } from "@earendil-works/chord";
|
|
1106
|
+
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 {}";
|
|
1100
1107
|
function readToolContract(tool) {
|
|
1101
1108
|
const candidate = "executionHints" in tool ? tool.executionHints : undefined;
|
|
1102
1109
|
if (candidate !== undefined && (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))) {
|
|
@@ -1462,14 +1469,14 @@ function forwardingHook() {
|
|
|
1462
1469
|
import {
|
|
1463
1470
|
defineTask as defineTask2
|
|
1464
1471
|
} from "@earendil-works/pi-durable";
|
|
1465
|
-
import {
|
|
1472
|
+
import { compile as compile2 } from "@earendil-works/pi-schema";
|
|
1466
1473
|
|
|
1467
1474
|
// packages/execution/src/nested-call.ts
|
|
1468
1475
|
import { validateToolArguments } from "@earendil-works/pi-ai/utils/validation";
|
|
1469
1476
|
import {
|
|
1470
1477
|
ToolTask as ToolTask4
|
|
1471
1478
|
} from "@earendil-works/pi-durable";
|
|
1472
|
-
import {
|
|
1479
|
+
import { compile } from "@earendil-works/pi-schema";
|
|
1473
1480
|
function nestedCall(runtime, input) {
|
|
1474
1481
|
const args = input.arguments;
|
|
1475
1482
|
return {
|
|
@@ -1490,7 +1497,7 @@ function prepareNestedInput(tool, input) {
|
|
|
1490
1497
|
if (typeof input !== "string")
|
|
1491
1498
|
return input;
|
|
1492
1499
|
const contract = readToolContract(tool);
|
|
1493
|
-
if (Boolean(
|
|
1500
|
+
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)))
|
|
1494
1501
|
return input;
|
|
1495
1502
|
const text = input.trim();
|
|
1496
1503
|
if (contract.discovery === "help" && text === "help")
|
|
@@ -1653,9 +1660,9 @@ function createNestedToolTask(name) {
|
|
|
1653
1660
|
return reject(runtime, call, executionError("tool_unavailable", `Tool ${call.name} is not available`), agent, tool, context);
|
|
1654
1661
|
let args;
|
|
1655
1662
|
try {
|
|
1656
|
-
const supplied = task.input.arguments === null && !
|
|
1663
|
+
const supplied = task.input.arguments === null && !compile2(tool.parameters).check(null) && compile2(tool.parameters).check({}) ? undefined : task.input.arguments;
|
|
1657
1664
|
const prepared = tool.prepareArguments === undefined ? prepareNestedInput(tool, supplied) : tool.prepareArguments(prepareNestedInput(tool, supplied));
|
|
1658
|
-
args = checked(tool, call, prepared === undefined &&
|
|
1665
|
+
args = checked(tool, call, prepared === undefined && compile2(tool.parameters).check({}) ? {} : prepared);
|
|
1659
1666
|
if (task.input.arguments === null || typeof task.input.arguments !== "object" || Array.isArray(task.input.arguments))
|
|
1660
1667
|
call.arguments = args;
|
|
1661
1668
|
} catch (error) {
|
|
@@ -1795,7 +1802,7 @@ function finishResult(tool, name, result) {
|
|
|
1795
1802
|
} else if (final.structuredOutput === undefined) {
|
|
1796
1803
|
if (!final.isError)
|
|
1797
1804
|
throw new Error(`Tool ${name} returned no structuredOutput`);
|
|
1798
|
-
} else if (!
|
|
1805
|
+
} else if (!compile2(tool.structuredOutputSchema).check(final.structuredOutput)) {
|
|
1799
1806
|
throw new Error(`Tool ${name} returned structuredOutput that does not match its schema`);
|
|
1800
1807
|
}
|
|
1801
1808
|
} catch (error) {
|
|
@@ -5031,7 +5038,7 @@ function createCodeMode(options) {
|
|
|
5031
5038
|
const usage = input.agent.callable.filter((tool) => tool.name !== "exec" && tool.name !== "wait").map(readToolContract).filter((contract) => !contract.nativeOnly && !contract.deferLoading).map((contract) => contract.prompt).join(`
|
|
5032
5039
|
`);
|
|
5033
5040
|
return [
|
|
5034
|
-
|
|
5041
|
+
nestedToolDiscoveryGuidance,
|
|
5035
5042
|
'exec accepts JavaScript source with optional // @exec: {"yield_time_ms":30000,"max_output_tokens":10000}. Await work and emit with text(value), image(value), generatedImage(value), notify(value). tools contains ordinary registered tools. ALL_TOOLS lists callable contracts. store(key,value)/load(key) retain serializable values between cells. Cells have no filesystem, network or Node globals. Shell tools follow the conversation environment. Use wait for exec cells and tools.write_stdin for shell sessions.',
|
|
5036
5043
|
usage
|
|
5037
5044
|
].filter(Boolean).join(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-durable-code",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Code execution and shell tools for Pi Durable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,12 +46,13 @@
|
|
|
46
46
|
"proxy-from-env": "2.1.0",
|
|
47
47
|
"undici": "8.10.2",
|
|
48
48
|
"typebox": "1.3.27",
|
|
49
|
-
"@howaboua/pi-durable-components": "0.
|
|
49
|
+
"@howaboua/pi-durable-components": "0.11.0",
|
|
50
|
+
"@earendil-works/pi-schema": "1.5.0"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"@earendil-works/chord": "1.
|
|
53
|
-
"@earendil-works/pi-ai": "1.
|
|
54
|
-
"@earendil-works/pi-durable": "1.
|
|
53
|
+
"@earendil-works/chord": "1.5.0",
|
|
54
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
55
|
+
"@earendil-works/pi-durable": "1.5.0",
|
|
55
56
|
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|