@mayflowergmbh/wasmsh-pyodide 0.6.3 → 0.7.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 +69 -0
- package/assets/pyodide.asm.js +1 -1
- package/assets/pyodide.asm.wasm +0 -0
- package/assets/pyodide.js +1 -1
- package/assets/pyodide.mjs +1 -1
- package/assets/python_stdlib.zip +0 -0
- package/browser-worker.js +95 -3
- package/index.d.ts +47 -0
- package/lib/allowlist.mjs +16 -2
- package/lib/fetch-helper.mjs +96 -16
- package/lib/fetch-membrane.mjs +263 -0
- package/lib/fs-membrane.mjs +280 -0
- package/lib/node-host-session.mjs +99 -1
- package/lib/node-module.mjs +67 -5
- package/lib/ptc-helper.mjs +194 -0
- package/node-host.mjs +207 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -231,6 +231,75 @@ Returned by both `createNodeSession` and `createBrowserWorkerSession`.
|
|
|
231
231
|
|--------|-------|-------------|
|
|
232
232
|
| `DEFAULT_WORKSPACE_DIR` | `"/workspace"` | The fixed sandbox root |
|
|
233
233
|
|
|
234
|
+
### `runPtc` — host-mediated tool calls from inside Python
|
|
235
|
+
|
|
236
|
+
The Node host advertises a `host_call: "v1"` capability on boot and
|
|
237
|
+
accepts a `runPtc` JSON-RPC method that lets user Python `await`
|
|
238
|
+
host-registered tools mid-execution. Since v0.6.4 this is exposed
|
|
239
|
+
directly on the Node session — there is no need to speak the wire
|
|
240
|
+
protocol by hand:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
import { createNodeSession } from "@mayflowergmbh/wasmsh-pyodide";
|
|
244
|
+
|
|
245
|
+
const session = await createNodeSession();
|
|
246
|
+
try {
|
|
247
|
+
const envelope = await session.runPtc({
|
|
248
|
+
code: "x = await tools.search(q='foo'); x",
|
|
249
|
+
tools: ["search"],
|
|
250
|
+
onHostCall: async ({ tool, args }) => {
|
|
251
|
+
// Resolve the host-side tool. Return a `host_call_result` envelope.
|
|
252
|
+
if (tool === "search") {
|
|
253
|
+
return { ok: true, value: `hit:${args.q}` };
|
|
254
|
+
}
|
|
255
|
+
return { ok: false, error: "UnknownTool", message: tool };
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
// envelope.value === "hit:foo"
|
|
259
|
+
} finally {
|
|
260
|
+
await session.close();
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`onHostCall` is invoked once per `await tools.<name>(...)` in the user
|
|
265
|
+
code; multiple host calls can be in flight concurrently (e.g. when the
|
|
266
|
+
user calls `asyncio.gather(...)`). The browser session does **not**
|
|
267
|
+
support `runPtc` and throws if called — PTC is Node-only today.
|
|
268
|
+
|
|
269
|
+
Wire protocol (newline-delimited JSON over stdin/stdout) for
|
|
270
|
+
implementations that want to drive the host directly:
|
|
271
|
+
|
|
272
|
+
```jsonc
|
|
273
|
+
// Boot
|
|
274
|
+
{"type": "ack", "capabilities": {"host_call": "v1"}}
|
|
275
|
+
|
|
276
|
+
// Client → host
|
|
277
|
+
{"id": 1, "method": "init", "params": {...}}
|
|
278
|
+
{"id": 2, "method": "runPtc", "params": {
|
|
279
|
+
"code": "await tools.search(q='foo')",
|
|
280
|
+
"tools": ["search"]
|
|
281
|
+
}}
|
|
282
|
+
|
|
283
|
+
// Host → client, mid-runPtc (interleaved with the eventual response)
|
|
284
|
+
{"type": "host_call", "id": "hc_<seq>", "tool": "search", "args": {"q": "foo"}}
|
|
285
|
+
|
|
286
|
+
// Client → host
|
|
287
|
+
{"type": "host_call_result", "id": "hc_<seq>", "ok": true, "value": "hit:foo"}
|
|
288
|
+
|
|
289
|
+
// Host → client, terminal
|
|
290
|
+
{"id": 2, "ok": true, "result": {"envelope": {
|
|
291
|
+
"ok": true, "stdout": "", "stderr": "", "value": "hit:foo"
|
|
292
|
+
}}}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
The host emits `host_call` messages as the user's `await tools.<name>(...)`
|
|
296
|
+
calls resolve into the JS bridge; each must be replied to with a
|
|
297
|
+
matching `host_call_result` exactly once. Multiple host calls may be
|
|
298
|
+
in flight concurrently (e.g. `await asyncio.gather(...)`).
|
|
299
|
+
|
|
300
|
+
Design notes: [ADR-0031](https://github.com/mayflower/wasmsh/blob/main/docs/adr/adr-0031-ptc-suspend-resume.md)
|
|
301
|
+
and the [full spec](https://github.com/mayflower/wasmsh/blob/main/docs/explanation/ptc-suspend-resume.md).
|
|
302
|
+
|
|
234
303
|
### Helper functions
|
|
235
304
|
|
|
236
305
|
| Function | Returns | Description |
|