@howaboua/pi-durable-worker-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
@@ -9,7 +9,7 @@ This is a separate execution product, not native Code or Notebook parity. There
9
9
  Install the release package with its pinned Durable peers. It is not published to the npm registry.
10
10
 
11
11
  ```sh
12
- npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.10.0/howaboua-pi-durable-worker-code-0.10.0.tgz
12
+ npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.11.0/howaboua-pi-durable-worker-code-0.11.0.tgz
13
13
  ```
14
14
 
15
15
  Import the package's compiled WASM through your host bundler. For Wrangler, add a `CompiledWasm` rule for `**/*.wasm` with `fallthrough: false`. No runtime fetching or compilation is needed.
@@ -992,8 +992,14 @@ async function observeCellProgress(id, api, context, budget) {
992
992
  return work;
993
993
  };
994
994
  const live = await api.watchDoc(LiveDoc3, api.conversationId, context);
995
- cell.start((value) => own(() => publish(value)));
996
- live?.start(() => own(async () => {
995
+ cell.start((call) => own(async () => {
996
+ if (call.kind === "failed")
997
+ throw call.error;
998
+ await publish(call.value);
999
+ }));
1000
+ live?.start((call) => own(async () => {
1001
+ if (call.kind === "failed")
1002
+ throw call.error;
997
1003
  await api.commit(async (tx) => {
998
1004
  const record = await tx.task(id);
999
1005
  if (record === undefined || record.state.status === "terminal")
@@ -1013,7 +1019,7 @@ async function observeCellProgress(id, api, context, budget) {
1013
1019
  const endings = await Promise.all([cell.stop(), live?.stop()]);
1014
1020
  await Promise.all([...pending]);
1015
1021
  for (const ending of endings)
1016
- if (ending?.reason === "listener_error")
1022
+ if (ending?.kind === "listener_error" || ending?.kind === "failed")
1017
1023
  throw ending.error;
1018
1024
  };
1019
1025
  }
@@ -1043,6 +1049,7 @@ function combineControls(controls, allowTermination = true) {
1043
1049
 
1044
1050
  // packages/execution/src/tool-contract.ts
1045
1051
  import { copyJson as copyJson7 } from "@earendil-works/chord";
1052
+ 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 {}";
1046
1053
  function readToolContract(tool) {
1047
1054
  const candidate = "executionHints" in tool ? tool.executionHints : undefined;
1048
1055
  if (candidate !== undefined && (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))) {
@@ -1408,14 +1415,14 @@ function forwardingHook() {
1408
1415
  import {
1409
1416
  defineTask as defineTask2
1410
1417
  } from "@earendil-works/pi-durable";
1411
- import { Compile as Compile2 } from "typebox/compile";
1418
+ import { compile as compile2 } from "@earendil-works/pi-schema";
1412
1419
 
1413
1420
  // packages/execution/src/nested-call.ts
1414
1421
  import { validateToolArguments } from "@earendil-works/pi-ai/utils/validation";
1415
1422
  import {
1416
1423
  ToolTask as ToolTask4
1417
1424
  } from "@earendil-works/pi-durable";
1418
- import { Compile } from "typebox/compile";
1425
+ import { compile } from "@earendil-works/pi-schema";
1419
1426
  function nestedCall(runtime, input) {
1420
1427
  const args = input.arguments;
1421
1428
  return {
@@ -1436,7 +1443,7 @@ function prepareNestedInput(tool, input) {
1436
1443
  if (typeof input !== "string")
1437
1444
  return input;
1438
1445
  const contract = readToolContract(tool);
1439
- if (Boolean(Compile(tool.parameters).Check(input)) || Boolean(Compile(contract.inputSchema).Check(input)))
1446
+ 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)))
1440
1447
  return input;
1441
1448
  const text = input.trim();
1442
1449
  if (contract.discovery === "help" && text === "help")
@@ -1599,9 +1606,9 @@ function createNestedToolTask(name) {
1599
1606
  return reject(runtime, call, executionError("tool_unavailable", `Tool ${call.name} is not available`), agent, tool, context);
1600
1607
  let args;
1601
1608
  try {
1602
- const supplied = task.input.arguments === null && !Compile2(tool.parameters).Check(null) && Compile2(tool.parameters).Check({}) ? undefined : task.input.arguments;
1609
+ const supplied = task.input.arguments === null && !compile2(tool.parameters).check(null) && compile2(tool.parameters).check({}) ? undefined : task.input.arguments;
1603
1610
  const prepared = tool.prepareArguments === undefined ? prepareNestedInput(tool, supplied) : tool.prepareArguments(prepareNestedInput(tool, supplied));
1604
- args = checked(tool, call, prepared === undefined && Compile2(tool.parameters).Check({}) ? {} : prepared);
1611
+ args = checked(tool, call, prepared === undefined && compile2(tool.parameters).check({}) ? {} : prepared);
1605
1612
  if (task.input.arguments === null || typeof task.input.arguments !== "object" || Array.isArray(task.input.arguments))
1606
1613
  call.arguments = args;
1607
1614
  } catch (error) {
@@ -1741,7 +1748,7 @@ function finishResult(tool, name, result) {
1741
1748
  } else if (final.structuredOutput === undefined) {
1742
1749
  if (!final.isError)
1743
1750
  throw new Error(`Tool ${name} returned no structuredOutput`);
1744
- } else if (!Compile2(tool.structuredOutputSchema).Check(final.structuredOutput)) {
1751
+ } else if (!compile2(tool.structuredOutputSchema).check(final.structuredOutput)) {
1745
1752
  throw new Error(`Tool ${name} returned structuredOutput that does not match its schema`);
1746
1753
  }
1747
1754
  } catch (error) {
@@ -2725,6 +2732,7 @@ function createWorkerCode(options) {
2725
2732
  tools: [exec, wait],
2726
2733
  sections: [
2727
2734
  section("worker-code", (input) => [
2735
+ nestedToolDiscoveryGuidance,
2728
2736
  "exec runs fresh bounded JavaScript. Await tools[name](args) and emit with text(value) or image({data,mimeType}). ALL_TOOLS lists callable contracts with original names. await yield_control() wakes the observer. Use wait for running cells. Guest globals and imports do not persist. No shell, ambient network or native globals.",
2729
2737
  ...input.agent.callable.filter((tool) => tool.name !== "exec" && tool.name !== "wait").map(readToolContract).filter((contract) => !contract.nativeOnly && !contract.deferLoading).map((contract) => contract.usage)
2730
2738
  ].join(`
@@ -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 TSchema = TSchema, D extends JsonValue = JsonValue> = ToolRegistration<T, D> & {
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
@@ -983,8 +983,14 @@ async function observeCellProgress(id, api, context, budget) {
983
983
  return work;
984
984
  };
985
985
  const live = await api.watchDoc(LiveDoc3, api.conversationId, context);
986
- cell.start((value) => own(() => publish(value)));
987
- live?.start(() => own(async () => {
986
+ cell.start((call) => own(async () => {
987
+ if (call.kind === "failed")
988
+ throw call.error;
989
+ await publish(call.value);
990
+ }));
991
+ live?.start((call) => own(async () => {
992
+ if (call.kind === "failed")
993
+ throw call.error;
988
994
  await api.commit(async (tx) => {
989
995
  const record = await tx.task(id);
990
996
  if (record === undefined || record.state.status === "terminal")
@@ -1004,7 +1010,7 @@ async function observeCellProgress(id, api, context, budget) {
1004
1010
  const endings = await Promise.all([cell.stop(), live?.stop()]);
1005
1011
  await Promise.all([...pending]);
1006
1012
  for (const ending of endings)
1007
- if (ending?.reason === "listener_error")
1013
+ if (ending?.kind === "listener_error" || ending?.kind === "failed")
1008
1014
  throw ending.error;
1009
1015
  };
1010
1016
  }
@@ -1034,6 +1040,7 @@ function combineControls(controls, allowTermination = true) {
1034
1040
 
1035
1041
  // packages/execution/src/tool-contract.ts
1036
1042
  import { copyJson as copyJson7 } from "@earendil-works/chord";
1043
+ 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 {}";
1037
1044
  function readToolContract(tool) {
1038
1045
  const candidate = "executionHints" in tool ? tool.executionHints : undefined;
1039
1046
  if (candidate !== undefined && (candidate === null || typeof candidate !== "object" || Array.isArray(candidate))) {
@@ -1399,14 +1406,14 @@ function forwardingHook() {
1399
1406
  import {
1400
1407
  defineTask as defineTask2
1401
1408
  } from "@earendil-works/pi-durable";
1402
- import { Compile as Compile2 } from "typebox/compile";
1409
+ import { compile as compile2 } from "@earendil-works/pi-schema";
1403
1410
 
1404
1411
  // packages/execution/src/nested-call.ts
1405
1412
  import { validateToolArguments } from "@earendil-works/pi-ai/utils/validation";
1406
1413
  import {
1407
1414
  ToolTask as ToolTask4
1408
1415
  } from "@earendil-works/pi-durable";
1409
- import { Compile } from "typebox/compile";
1416
+ import { compile } from "@earendil-works/pi-schema";
1410
1417
  function nestedCall(runtime, input) {
1411
1418
  const args = input.arguments;
1412
1419
  return {
@@ -1427,7 +1434,7 @@ function prepareNestedInput(tool, input) {
1427
1434
  if (typeof input !== "string")
1428
1435
  return input;
1429
1436
  const contract = readToolContract(tool);
1430
- if (Boolean(Compile(tool.parameters).Check(input)) || Boolean(Compile(contract.inputSchema).Check(input)))
1437
+ 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)))
1431
1438
  return input;
1432
1439
  const text = input.trim();
1433
1440
  if (contract.discovery === "help" && text === "help")
@@ -1590,9 +1597,9 @@ function createNestedToolTask(name) {
1590
1597
  return reject(runtime, call, executionError("tool_unavailable", `Tool ${call.name} is not available`), agent, tool, context);
1591
1598
  let args;
1592
1599
  try {
1593
- const supplied = task.input.arguments === null && !Compile2(tool.parameters).Check(null) && Compile2(tool.parameters).Check({}) ? undefined : task.input.arguments;
1600
+ const supplied = task.input.arguments === null && !compile2(tool.parameters).check(null) && compile2(tool.parameters).check({}) ? undefined : task.input.arguments;
1594
1601
  const prepared = tool.prepareArguments === undefined ? prepareNestedInput(tool, supplied) : tool.prepareArguments(prepareNestedInput(tool, supplied));
1595
- args = checked(tool, call, prepared === undefined && Compile2(tool.parameters).Check({}) ? {} : prepared);
1602
+ args = checked(tool, call, prepared === undefined && compile2(tool.parameters).check({}) ? {} : prepared);
1596
1603
  if (task.input.arguments === null || typeof task.input.arguments !== "object" || Array.isArray(task.input.arguments))
1597
1604
  call.arguments = args;
1598
1605
  } catch (error) {
@@ -1732,7 +1739,7 @@ function finishResult(tool, name, result) {
1732
1739
  } else if (final.structuredOutput === undefined) {
1733
1740
  if (!final.isError)
1734
1741
  throw new Error(`Tool ${name} returned no structuredOutput`);
1735
- } else if (!Compile2(tool.structuredOutputSchema).Check(final.structuredOutput)) {
1742
+ } else if (!compile2(tool.structuredOutputSchema).check(final.structuredOutput)) {
1736
1743
  throw new Error(`Tool ${name} returned structuredOutput that does not match its schema`);
1737
1744
  }
1738
1745
  } catch (error) {
@@ -2715,6 +2722,7 @@ function createWorkerCode(options) {
2715
2722
  tools: [exec, wait],
2716
2723
  sections: [
2717
2724
  section("worker-code", (input) => [
2725
+ nestedToolDiscoveryGuidance,
2718
2726
  "exec runs fresh bounded JavaScript. Await tools[name](args) and emit with text(value) or image({data,mimeType}). ALL_TOOLS lists callable contracts with original names. await yield_control() wakes the observer. Use wait for running cells. Guest globals and imports do not persist. No shell, ambient network or native globals.",
2719
2727
  ...input.agent.callable.filter((tool) => tool.name !== "exec" && tool.name !== "wait").map(readToolContract).filter((contract) => !contract.nativeOnly && !contract.deferLoading).map((contract) => contract.usage)
2720
2728
  ].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>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-durable-worker-code",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Bounded Worker-native JavaScript execution for Pi Durable",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,12 +42,13 @@
42
42
  "@jitl/quickjs-wasmfile-release-sync": "0.32.0",
43
43
  "quickjs-emscripten": "0.32.0",
44
44
  "typebox": "1.3.27",
45
- "@howaboua/pi-durable-components": "0.10.0"
45
+ "@howaboua/pi-durable-components": "0.11.0",
46
+ "@earendil-works/pi-schema": "1.5.0"
46
47
  },
47
48
  "peerDependencies": {
48
- "@earendil-works/chord": "1.4.0",
49
- "@earendil-works/pi-ai": "1.4.0",
50
- "@earendil-works/pi-durable": "1.4.0",
49
+ "@earendil-works/chord": "1.5.0",
50
+ "@earendil-works/pi-ai": "1.5.0",
51
+ "@earendil-works/pi-durable": "1.5.0",
51
52
  "@modelcontextprotocol/sdk": ">=1.25.2 <2"
52
53
  },
53
54
  "publishConfig": {