@howaboua/pi-durable-js-notebook 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.
@@ -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<Type.TSchema, import("@earendil-works/chord").JsonValue>>>;
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 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
@@ -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((value) => own(() => publish(value)));
600
- live?.start(() => own(async () => {
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?.reason === "listener_error")
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 { Compile as Compile2 } from "typebox/compile";
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 { Compile } from "typebox/compile";
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(Compile(tool.parameters).Check(input)) || Boolean(Compile(contract.inputSchema).Check(input)))
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 && !Compile2(tool.parameters).Check(null) && Compile2(tool.parameters).Check({}) ? undefined : task.input.arguments;
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 && Compile2(tool.parameters).Check({}) ? {} : prepared);
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 (!Compile2(tool.structuredOutputSchema).Check(final.structuredOutput)) {
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.4.0", stateDirectory, signal);
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
  ]
@@ -0,0 +1,5 @@
1
+ import { type ComponentInstance, type ComponentRequest } from "@howaboua/pi-durable-components";
2
+ import { createJsNotebookMode, type JsNotebookModeOptions } from "./index.ts";
3
+ /** Optional complete constructor override; replaces baseline JSON configuration. */
4
+ export declare const jsNotebookOptions: import("@howaboua/pi-durable-components").ComponentCapability<JsNotebookModeOptions>;
5
+ export declare function createComponent(request: ComponentRequest): ComponentInstance<ReturnType<typeof createJsNotebookMode>>;
@@ -32,7 +32,7 @@ export declare function createJsNotebookMode(options: JsNotebookModeOptions): {
32
32
  prepareArguments?(args: unknown): {
33
33
  input?: string;
34
34
  };
35
- structuredOutputSchema?: Type.TSchema;
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.9.1",
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",
@@ -23,6 +23,10 @@
23
23
  "./worker": {
24
24
  "types": "./dist/js-notebook/src/worker.d.ts",
25
25
  "import": "./dist/worker.js"
26
+ },
27
+ "./component": {
28
+ "types": "./dist/js-notebook/src/activation.d.ts",
29
+ "import": "./dist/activation.js"
26
30
  }
27
31
  },
28
32
  "files": [
@@ -38,15 +42,35 @@
38
42
  "typebox": "1.3.27",
39
43
  "acorn": "8.19.0",
40
44
  "quickjs-wasi": "3.6.3",
41
- "@earendil-works/pi-codemode": "1.4.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"
42
48
  },
43
49
  "peerDependencies": {
44
- "@earendil-works/chord": "1.4.0",
45
- "@earendil-works/pi-ai": "1.4.0",
46
- "@earendil-works/pi-durable": "1.4.0",
47
- "@modelcontextprotocol/sdk": "1.25.2"
50
+ "@earendil-works/chord": "1.5.0",
51
+ "@earendil-works/pi-ai": "1.5.0",
52
+ "@earendil-works/pi-durable": "1.5.0",
53
+ "@modelcontextprotocol/sdk": ">=1.25.2 <2"
48
54
  },
49
55
  "publishConfig": {
50
56
  "access": "public"
57
+ },
58
+ "durable": {
59
+ "schemaVersion": 1,
60
+ "kind": "extension",
61
+ "entry": "./component",
62
+ "runtimes": [
63
+ "node"
64
+ ],
65
+ "requires": [
66
+ "durable.node-execution.v1",
67
+ "durable.state.v1"
68
+ ],
69
+ "permissions": [
70
+ "filesystem",
71
+ "process",
72
+ "storage"
73
+ ],
74
+ "selectionGroup": "execution"
51
75
  }
52
76
  }