@howaboua/pi-durable-worker-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.
@@ -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(`
@@ -0,0 +1,6 @@
1
+ import { type ComponentInstance, type ComponentRequest } from "@howaboua/pi-durable-components";
2
+ import { createWorkerCode, type WorkerCodeOptions } from "./index.ts";
3
+ export declare const WORKER_CODE_WASM_ABI = "quickjs-emscripten/0.32.0/release-sync";
4
+ /** Optional complete constructor override; replaces baseline JSON configuration. */
5
+ export declare const workerCodeOptions: import("@howaboua/pi-durable-components").ComponentCapability<WorkerCodeOptions>;
6
+ export declare function createComponent(request: ComponentRequest): ComponentInstance<ReturnType<typeof createWorkerCode>>;
@@ -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.9.1",
3
+ "version": "0.11.0",
4
4
  "description": "Bounded Worker-native JavaScript execution for Pi Durable",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,7 +25,11 @@
25
25
  "types": "./dist/worker-code/src/index.d.ts",
26
26
  "import": "./dist/index.js"
27
27
  },
28
- "./quickjs.wasm": "./dist/quickjs.wasm"
28
+ "./quickjs.wasm": "./dist/quickjs.wasm",
29
+ "./component": {
30
+ "types": "./dist/worker-code/src/activation.d.ts",
31
+ "import": "./dist/activation.js"
32
+ }
29
33
  },
30
34
  "files": [
31
35
  "dist",
@@ -37,15 +41,31 @@
37
41
  "dependencies": {
38
42
  "@jitl/quickjs-wasmfile-release-sync": "0.32.0",
39
43
  "quickjs-emscripten": "0.32.0",
40
- "typebox": "1.3.27"
44
+ "typebox": "1.3.27",
45
+ "@howaboua/pi-durable-components": "0.11.0",
46
+ "@earendil-works/pi-schema": "1.5.0"
41
47
  },
42
48
  "peerDependencies": {
43
- "@earendil-works/chord": "1.4.0",
44
- "@earendil-works/pi-ai": "1.4.0",
45
- "@earendil-works/pi-durable": "1.4.0",
46
- "@modelcontextprotocol/sdk": "1.25.2"
49
+ "@earendil-works/chord": "1.5.0",
50
+ "@earendil-works/pi-ai": "1.5.0",
51
+ "@earendil-works/pi-durable": "1.5.0",
52
+ "@modelcontextprotocol/sdk": ">=1.25.2 <2"
47
53
  },
48
54
  "publishConfig": {
49
55
  "access": "public"
56
+ },
57
+ "durable": {
58
+ "schemaVersion": 1,
59
+ "kind": "extension",
60
+ "entry": "./component",
61
+ "runtimes": [
62
+ "node",
63
+ "workerd"
64
+ ],
65
+ "requires": [
66
+ "durable.compiled-wasm.v1"
67
+ ],
68
+ "permissions": [],
69
+ "selectionGroup": "execution"
50
70
  }
51
71
  }