@howaboua/pi-durable-code 0.9.1 → 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 +2 -2
- package/dist/activation.js +4766 -0
- package/dist/code/src/activation.d.ts +5 -0
- package/dist/code/src/history.d.ts +1 -1
- package/dist/execution/src/custom-commands.d.ts +1 -1
- package/dist/execution/src/tool-contract.d.ts +2 -2
- package/dist/index.js +17 -10
- package/package.json +30 -6
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ComponentInstance, type ComponentRequest } from "@howaboua/pi-durable-components";
|
|
2
|
+
import { type CodeModeOptions, createCodeMode } from "./index.ts";
|
|
3
|
+
/** Optional complete constructor override; replaces baseline JSON configuration. */
|
|
4
|
+
export declare const codeOptions: import("@howaboua/pi-durable-components").ComponentCapability<CodeModeOptions>;
|
|
5
|
+
export declare function createComponent(request: ComponentRequest): ComponentInstance<ReturnType<typeof createCodeMode>>;
|
|
@@ -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",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/code/src/index.d.ts",
|
|
29
29
|
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./component": {
|
|
32
|
+
"types": "./dist/code/src/activation.d.ts",
|
|
33
|
+
"import": "./dist/activation.js"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"files": [
|
|
@@ -41,15 +45,35 @@
|
|
|
41
45
|
"smol-toml": "1.9.0",
|
|
42
46
|
"proxy-from-env": "2.1.0",
|
|
43
47
|
"undici": "8.10.2",
|
|
44
|
-
"typebox": "1.3.27"
|
|
48
|
+
"typebox": "1.3.27",
|
|
49
|
+
"@howaboua/pi-durable-components": "0.11.0",
|
|
50
|
+
"@earendil-works/pi-schema": "1.5.0"
|
|
45
51
|
},
|
|
46
52
|
"peerDependencies": {
|
|
47
|
-
"@earendil-works/chord": "1.
|
|
48
|
-
"@earendil-works/pi-ai": "1.
|
|
49
|
-
"@earendil-works/pi-durable": "1.
|
|
50
|
-
"@modelcontextprotocol/sdk": "1.25.2"
|
|
53
|
+
"@earendil-works/chord": "1.5.0",
|
|
54
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
55
|
+
"@earendil-works/pi-durable": "1.5.0",
|
|
56
|
+
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
51
57
|
},
|
|
52
58
|
"publishConfig": {
|
|
53
59
|
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"durable": {
|
|
62
|
+
"schemaVersion": 1,
|
|
63
|
+
"kind": "extension",
|
|
64
|
+
"entry": "./component",
|
|
65
|
+
"runtimes": [
|
|
66
|
+
"node"
|
|
67
|
+
],
|
|
68
|
+
"requires": [
|
|
69
|
+
"durable.node-execution.v1",
|
|
70
|
+
"durable.state.v1"
|
|
71
|
+
],
|
|
72
|
+
"permissions": [
|
|
73
|
+
"filesystem",
|
|
74
|
+
"process",
|
|
75
|
+
"network"
|
|
76
|
+
],
|
|
77
|
+
"selectionGroup": "execution"
|
|
54
78
|
}
|
|
55
79
|
}
|