@howaboua/pi-durable-worker-code 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/NOTICE +49 -0
- package/README.md +71 -2
- package/dist/QUICKJS-LICENSE +47 -0
- package/dist/activation.js +2829 -0
- package/dist/execution/src/cell-contract.d.ts +49 -0
- package/dist/execution/src/cell-observation.d.ts +7 -0
- package/dist/execution/src/cell-progress.d.ts +4 -0
- package/dist/execution/src/cell-task.d.ts +17 -0
- package/dist/execution/src/cell-tools.d.ts +8 -0
- package/dist/execution/src/cells.d.ts +14 -0
- package/dist/execution/src/controls.d.ts +3 -0
- package/dist/execution/src/exec-source.d.ts +21 -0
- package/dist/execution/src/forwarded-tools.d.ts +21 -0
- package/dist/execution/src/forwarding-hook.d.ts +6 -0
- package/dist/execution/src/forwarding.d.ts +15 -0
- package/dist/execution/src/history.d.ts +14 -0
- package/dist/execution/src/invocation-state.d.ts +26 -0
- package/dist/execution/src/invocation.d.ts +35 -0
- package/dist/execution/src/native-tools.d.ts +11 -0
- package/dist/execution/src/nested-call.d.ts +26 -0
- package/dist/execution/src/nested-result.d.ts +8 -0
- package/dist/execution/src/nested.d.ts +3 -0
- package/dist/execution/src/output.d.ts +48 -0
- package/dist/execution/src/presentation.d.ts +59 -0
- package/dist/execution/src/progress.d.ts +23 -0
- package/dist/execution/src/projection.d.ts +5 -0
- package/dist/execution/src/tool-contract.d.ts +34 -0
- package/dist/execution/src/tool-origin.d.ts +11 -0
- package/dist/execution/src/tool-value.d.ts +3 -0
- package/dist/execution/src/wait-session.d.ts +6 -0
- package/dist/history.js +315 -0
- package/dist/index.js +2771 -0
- package/dist/presentation.js +201 -0
- package/dist/quickjs.wasm +0 -0
- package/dist/worker-code/src/activation.d.ts +6 -0
- package/dist/worker-code/src/guest.d.ts +16 -0
- package/dist/worker-code/src/history.d.ts +6 -0
- package/dist/worker-code/src/index.d.ts +47 -0
- package/dist/worker-code/src/interpreter.d.ts +20 -0
- package/dist/worker-code/src/limits.d.ts +20 -0
- package/dist/worker-code/src/modules.d.ts +13 -0
- package/dist/worker-code/src/output.d.ts +6 -0
- package/dist/worker-code/src/presentation.d.ts +22 -0
- package/dist/worker-code/src/runtime.d.ts +17 -0
- package/dist/worker-code/src/tool-result.d.ts +3 -0
- package/package.json +69 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Igor Warzocha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Generic truncation recovery guidance follows Pi Stuff merged PR #552
|
|
2
|
+
revision 84bd5bce60a77c4298484d4b7c810d4fe5220a1b, retaining the MIT notices below.
|
|
3
|
+
|
|
4
|
+
Worker Code is an original bounded runtime adapter for Pi Durable. Its
|
|
5
|
+
runtime-neutral execution coordinator and nested dispatcher are compiled
|
|
6
|
+
from the internal packages/execution source tree. See that directory's NOTICE
|
|
7
|
+
for notices for its shared output and execution contracts.
|
|
8
|
+
|
|
9
|
+
Shared execution contracts are adapted from @howaboua/pi-codex-conversion,
|
|
10
|
+
revision b2006db9def12c373ae48e70044d30f7d6b7e34f.
|
|
11
|
+
Source: https://github.com/IgorWarzocha/howaboua-pi-stuff
|
|
12
|
+
Shared output retention derives from Pi Durable revision
|
|
13
|
+
f5d20047b3ad43d068a8eb61bd4e1f193bedbce6.
|
|
14
|
+
Modifications: Durable-native execution ownership, bounded Worker runtime,
|
|
15
|
+
ordinary-tool dispatch and cancellation cleanup.
|
|
16
|
+
|
|
17
|
+
MIT License
|
|
18
|
+
Copyright (c) 2025 Mario Zechner
|
|
19
|
+
Copyright (c) 2026 Igor Warzocha
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|
|
38
|
+
|
|
39
|
+
The compiled quickjs.wasm asset is copied without modification from
|
|
40
|
+
@jitl/quickjs-wasmfile-release-sync 0.32.0. The adapter uses the exact pinned
|
|
41
|
+
quickjs-emscripten 0.32.0 release-sync public API.
|
|
42
|
+
Source: https://github.com/justjake/quickjs-emscripten
|
|
43
|
+
|
|
44
|
+
quickjs-emscripten copyright (c) 2019-2024 Jake Teton-Landis
|
|
45
|
+
QuickJS Javascript Engine copyright (c) 2017-2021 Fabrice Bellard
|
|
46
|
+
QuickJS Javascript Engine copyright (c) 2017-2021 Charlie Gordon
|
|
47
|
+
|
|
48
|
+
The complete upstream MIT license notices accompany the binary in
|
|
49
|
+
dist/QUICKJS-LICENSE. No QuickJS or Pi Durable source was modified or vendored.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Worker Code
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run bounded JavaScript inside a Worker and call ordinary Pi Durable tools. This package adds `exec` and `wait` to an existing Harness. It also executes app-owned workspace modules for editable tools, tests, prompts and hooks.
|
|
4
|
+
|
|
5
|
+
This is a separate execution product, not native Code or Notebook parity. There is no shell, filesystem, ambient network, Node, Deno, timer or arbitrary npm access in the guest. Each invocation gets a fresh QuickJS context. Workspace persistence and activation belong to the app.
|
|
6
|
+
|
|
7
|
+
## Install in a Worker
|
|
8
|
+
|
|
9
|
+
Install the release package with its pinned Durable peers. It is not published to the npm registry.
|
|
10
|
+
|
|
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
|
|
13
|
+
```
|
|
14
|
+
|
|
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.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import wasmModule from "@howaboua/pi-durable-worker-code/quickjs.wasm";
|
|
19
|
+
import { createWorkerCode } from "@howaboua/pi-durable-worker-code";
|
|
20
|
+
|
|
21
|
+
const workerCode = createWorkerCode({
|
|
22
|
+
wasmModule,
|
|
23
|
+
cancelTask: (id, context) => harness.abortTask(id, context),
|
|
24
|
+
});
|
|
25
|
+
registry.install(workerCode.extension);
|
|
26
|
+
// Open your existing Harness with this registry, then bind it.
|
|
27
|
+
workerCode.bind(harness);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Declare static `.wasm` imports as `WebAssembly.Module` in the consuming app's TypeScript configuration. Install extensions before resuming persisted tasks. Select `workerCode.extension` alongside your ordinary tool extensions through the conversation's agent configuration. Do not select native Code or Notebook at the same time. On shutdown, await `workerCode.close()` before closing the Harness.
|
|
31
|
+
|
|
32
|
+
The model calls `exec` with JavaScript source. Guest code awaits `tools[name](args)` and emits with `text(value)` or `image({data,mimeType})`. Original registration names remain intact. `ALL_TOOLS` lists callable contracts. Bare values and returned values are discarded by `exec`.
|
|
33
|
+
|
|
34
|
+
`await yield_control()` publishes progress and wakes the observer without stopping the cell. A running observation returns its `cellId`. `wait` observes that cell or terminates it with `terminate: true`. The optional leading `// @exec: {"yield_time_ms":0,"max_output_tokens":1000}` controls observation, not runtime quotas. Each observation has an independent output budget. An unchanged running snapshot is not repeated.
|
|
35
|
+
|
|
36
|
+
## Execute workspace modules
|
|
37
|
+
|
|
38
|
+
Snapshots are immutable maps of canonical absolute virtual paths to source strings. Imports resolve only inside that snapshot. Relative imports are allowed, root escapes and unknown modules are rejected.
|
|
39
|
+
|
|
40
|
+
For `exec`, factory `modules` accepts a snapshot or a synchronous snapshot provider. Use `modules: () => activeFiles` when the app reloads its workspace. Each cell copies the provider's current source map before awaiting interpreter admission. Already-running cells retain their old imports after activation.
|
|
41
|
+
|
|
42
|
+
`evaluateModule({modules,entry,exportName}, {signal})` reads a JSON data export. Supply `args` to call the export as a function instead. This route is pure. Use it for manifests, fixed tests, prompt rendering and bounded hooks. Guest code receives no ordinary tools or output capabilities.
|
|
43
|
+
|
|
44
|
+
An ordinary app-owned tool can call `executeToolModule(request, api, context, {allowedTools})`. The export is invoked with `request.args` and must return a JSON `ToolExecutionResult`. Grants default to empty. `exec`, `wait` and native-only registrations are always excluded. Granted calls use the same nested Durable task path owned by the current tool, not another cell or direct registration execution. Validation, preparation, wrapping, hooks, results, usage and invocation-ordered controls survive.
|
|
45
|
+
|
|
46
|
+
Host wrappers for impure guest modules must declare `replay: "unsafe"`. Never expose credentials, bindings, registry mutation or arbitrary host callbacks to the guest. Keep capability grants and fixed validation outside editable source. The app owns source versions, passing test receipts and atomic activation of its ordinary extension registrations.
|
|
47
|
+
|
|
48
|
+
## Bounds and recovery
|
|
49
|
+
|
|
50
|
+
`limits` is trusted host configuration and can only reduce `DEFAULT_WORKER_CODE_LIMITS`. Defaults are 8 MiB guest heap, 256 KiB stack, 64 interrupt polls, 4096 promise jobs, 128 tool calls, 32 pending bridge calls, 64 KiB source per file, 256 KiB total module snapshot, 128 modules, 32 KiB arguments, 128 KiB JSON results, 256 KiB total emitted output and 30 seconds waiting for host work. Heap cannot be configured below 256 KiB or stack below 16 KiB because context startup needs memory.
|
|
51
|
+
|
|
52
|
+
All component instances in an isolate share one compiled interpreter with 16 MiB initial and 32 MiB maximum imported WASM memory. Admission allows at most four runtimes and 24 MiB reserved guest heaps across all Harness owners. Three default-size guests can run together. Admission fails immediately when exhausted, avoiding nested-call deadlocks. Reuse the same imported module identity. `budget()` reports admission and linear-memory usage.
|
|
53
|
+
|
|
54
|
+
Fuel and job counts bound interpreted loops. A wall timer only bounds host I/O waits. Expensive interpreter builtins still rely on the hosting Worker's CPU quota as the outer limit. Tool JSON is never silently truncated. Transport and output overflow fail visibly. Images count against the same output budget.
|
|
55
|
+
|
|
56
|
+
Cells and their owned calls are cancelled and joined. Interrupted cells do not replay source. Unsafe nested effects remain reported as potentially partially executed. Guest globals do not survive a process restart. Reinstall the app's active immutable source snapshot before resuming its existing journal.
|
|
57
|
+
|
|
58
|
+
## Validation
|
|
59
|
+
|
|
60
|
+
From the repository, run `node --experimental-strip-types --test packages/worker-code/test/workflows.test.mjs`. This executes the actual compiled WASM on workerd with genuine Durable registrations. It covers concurrent impure handlers, hooks and wrapped results, isolation, module imports, fuel, jobs, heap and transport limits, incremental output, yield, wait, cancellation and isolate-wide admission across separate Harness owners.
|
|
61
|
+
|
|
62
|
+
The consuming app must separately prove its persistence, lease fencing, activation and abrupt process-loss recovery. This package does not supply another scheduler or journal.
|
|
63
|
+
|
|
64
|
+
## Headless presentations
|
|
65
|
+
|
|
66
|
+
`@howaboua/pi-durable-worker-code/presentation` exports `workerCodeCapability`, `workerCodeSummary` and `workerCodeDetail`. These browser-safe descriptors are structurally compatible with the UI SDK without importing it. They perform no I/O and have no renderer.
|
|
67
|
+
|
|
68
|
+
The host supplies `{cell, result}`. Each field is explicitly nullable. A cell is `{id, status}`, with a canonical positive decimal task ID and the actual coordinator status: `running`, `completed`, `failed`, `aborted` or `interrupted`. Read these from exec/wait receipt details `cellId` and `status`. Do not substitute host request activity for cell lifecycle.
|
|
69
|
+
|
|
70
|
+
`result: null` means output has not been acquired. Otherwise pass the ordinary execution receipt. Parsing retains text, base64 images, `isError`, JSON details and structured diagnostics. Omitted fields normalize to empty content, false, null and empty diagnostics. Usage and controls remain Durable-owned, not presentation actions. Summary selects title, cell identity and status, output availability and nullable `isError`. Detail selects the full validated state. Summary can request detail without acquiring it.
|
|
71
|
+
|
|
72
|
+
The host authorizes `exec` and `wait` through ordinary registrations and publishes acquired receipts on the declared `results` stream. This is host publication, not a new runtime stream or tool bridge. Each receipt is one bounded observation, not cumulative output. Presentation disposal does not terminate cells, roll back effects or authorize replay. Acquisition, binding and cancellation policy belong to the host.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
quickjs-emscripten:
|
|
2
|
+
The MIT License
|
|
3
|
+
|
|
4
|
+
quickjs-emscripten copyright (c) 2019-2024 Jake Teton-Landis
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
quickjs:
|
|
26
|
+
QuickJS Javascript Engine
|
|
27
|
+
|
|
28
|
+
Copyright (c) 2017-2021 Fabrice Bellard
|
|
29
|
+
Copyright (c) 2017-2021 Charlie Gordon
|
|
30
|
+
|
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
32
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
33
|
+
in the Software without restriction, including without limitation the rights
|
|
34
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
35
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
36
|
+
furnished to do so, subject to the following conditions:
|
|
37
|
+
|
|
38
|
+
The above copyright notice and this permission notice shall be included in
|
|
39
|
+
all copies or substantial portions of the Software.
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
42
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
44
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
45
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
46
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
47
|
+
THE SOFTWARE.
|