@pi-oxide/pi-host-web 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +132 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @pi-oxide/pi-host-web
2
+
3
+ WASM host for [pi-core](https://github.com/pi-oxide/pi-oxide) — a deterministic agent state machine, compiled to WebAssembly for browser and Node.js.
4
+
5
+ ## What it is
6
+
7
+ This package exposes the `pi-core` agent loop through typed JavaScript APIs. Every function returns a strongly-typed result envelope — never throws. The TypeScript definitions are generated directly from Rust structs via [tsify](https://github.com/madonoharu/tsify).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @pi-oxide/pi-host-web
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Browser
18
+
19
+ ```typescript
20
+ import init, * as wasm from "@pi-oxide/pi-host-web";
21
+
22
+ // Initialize the WASM module (async, required once)
23
+ await init();
24
+
25
+ // Create an agent
26
+ const result = wasm.createAgent({
27
+ system_prompt: "You are a helpful assistant.",
28
+ model: {
29
+ id: "claude-sonnet-4-20250514",
30
+ name: "Claude Sonnet",
31
+ api: "anthropic",
32
+ provider: "anthropic",
33
+ reasoning: false,
34
+ context_window: 200000,
35
+ max_tokens: 4096,
36
+ },
37
+ });
38
+
39
+ const handle = result.data.handle;
40
+
41
+ // Send a prompt
42
+ const step = wasm.prompt(handle, { text: "Hello!" });
43
+ console.log(step.data.actions);
44
+ ```
45
+
46
+ ### Node.js
47
+
48
+ ```typescript
49
+ import { readFileSync } from "node:fs";
50
+ import { createRequire } from "node:module";
51
+ import { dirname, join } from "node:path";
52
+
53
+ const require = createRequire(import.meta.url);
54
+ const pkgDir = dirname(require.resolve("@pi-oxide/pi-host-web/package.json"));
55
+ const wasmPath = join(pkgDir, "pi_host_web_bg.wasm");
56
+ const wasmBytes = readFileSync(wasmPath);
57
+
58
+ const pkg = await import("@pi-oxide/pi-host-web");
59
+ pkg.initSync({ module: wasmBytes });
60
+
61
+ // Now use pkg.createAgent(), pkg.prompt(), etc.
62
+ const result = pkg.createAgent({ ... });
63
+ ```
64
+
65
+ ## API
66
+
67
+ ### Agent lifecycle
68
+
69
+ | Function | Input | Returns | Description |
70
+ |----------|-------|---------|-------------|
71
+ | `createAgent(options)` | `AgentOptions` | `CreateAgentResult` | Creates a new agent instance |
72
+ | `destroyAgent(handle)` | `number` | `EmptyResult` | Destroys an agent and frees its slot |
73
+ | `reset(handle)` | `number` | `EmptyResult` | Resets agent state (keeps config) |
74
+ | `state(handle)` | `number` | `StateResult` | Returns current agent state |
75
+
76
+ ### Turn loop
77
+
78
+ | Function | Input | Returns | Description |
79
+ |----------|-------|---------|-------------|
80
+ | `prompt(handle, request)` | `number`, `PromptRequest` | `StepResult` | Starts a new turn |
81
+ | `feedLlmChunk(handle, chunk)` | `number`, `LlmChunk` | `EventsResult` | Feeds a streaming LLM chunk |
82
+ | `onLlmDone(handle, result)` | `number`, `LlmResult` | `StepResult` | Signals LLM stream completion |
83
+ | `onToolDone(handle, id, payload)` | `number`, `string`, `ToolDonePayload` | `StepResult` | Reports tool execution result |
84
+ | `onToolStarted(handle, id)` | `number`, `string` | `EventsResult` | Signals tool execution started |
85
+ | `onToolUpdate(handle, update)` | `number`, `ToolExecutionUpdate` | `EventsResult` | Streams tool stdout/stderr |
86
+ | `onToolCancelled(handle, id, reason)` | `number`, `string`, `CancelReason` | `StepResult` | Cancels a running tool |
87
+
88
+ ### Context projection
89
+
90
+ | Function | Input | Returns | Description |
91
+ |----------|-------|---------|-------------|
92
+ | `projectContext(input)` | `ProjectionInput` | `ProjectionResult` | Projects context to fit budget |
93
+
94
+ ### Steering
95
+
96
+ | Function | Input | Returns | Description |
97
+ |----------|-------|---------|-------------|
98
+ | `steer(handle, message)` | `number`, `AgentMessage` | `EventsResult` | Injects a steering message |
99
+ | `followUp(handle, message)` | `number`, `AgentMessage` | `EmptyResult` | Appends a follow-up message |
100
+
101
+ ### Observability
102
+
103
+ | Function | Returns | Description |
104
+ |----------|---------|-------------|
105
+ | `drainTraceLog()` | `string[]` | Drains and clears the Rust trace buffer |
106
+
107
+ ## Result envelopes
108
+
109
+ Every function returns a typed result with this shape:
110
+
111
+ ```typescript
112
+ interface Result<T> {
113
+ ok: boolean;
114
+ data?: T;
115
+ error?: {
116
+ code: string;
117
+ message: string;
118
+ };
119
+ }
120
+ ```
121
+
122
+ Concrete types: `CreateAgentResult`, `StepResult`, `EventsResult`, `StateResult`, `EmptyResult`, `ProjectionResult`.
123
+
124
+ ## Files
125
+
126
+ - `pi_host_web.js` — Main ESM entry point
127
+ - `pi_host_web_bg.wasm` — Compiled WebAssembly binary
128
+ - `pi_host_web.d.ts` — TypeScript declarations (generated from Rust)
129
+
130
+ ## License
131
+
132
+ MIT
package/package.json CHANGED
@@ -5,16 +5,17 @@
5
5
  "Irving Ou <irving@pi-oxide.dev>"
6
6
  ],
7
7
  "description": "WASM host for pi-core. Browser FileSystem Access API, fetch(), JS event loop.",
8
- "version": "0.1.0",
8
+ "version": "0.1.1",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/pi-oxide/pi-oxide"
12
+ "url": "git+https://github.com/pi-oxide/pi-oxide.git"
13
13
  },
14
14
  "files": [
15
15
  "pi_host_web_bg.wasm",
16
16
  "pi_host_web.js",
17
- "pi_host_web.d.ts"
17
+ "pi_host_web.d.ts",
18
+ "README.md"
18
19
  ],
19
20
  "main": "pi_host_web.js",
20
21
  "types": "pi_host_web.d.ts",