agx-wasm 0.0.0-stage → 0.5.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 CHANGED
@@ -1,3 +1,64 @@
1
- # Temporary Holding Version
1
+ # agx-wasm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ WebAssembly / TypeScript bindings for [agx-core](../agx-core/README.md).
4
+ Drive agx's agent-trace parsers from browsers, Node, Deno, or any
5
+ wasm-bindgen host — no native install, no Python, no terminal.
6
+
7
+ ## Build
8
+
9
+ ```sh
10
+ cargo install wasm-pack
11
+ cd crates/agx-wasm
12
+
13
+ wasm-pack build --target web # for <script type="module">
14
+ wasm-pack build --target nodejs # for `require("./pkg")` / `import` in Node
15
+ wasm-pack build --target bundler # for webpack / vite / rollup / esbuild
16
+ ```
17
+
18
+ Each target produces a `pkg/` with TypeScript declarations.
19
+
20
+ ## JS surface
21
+
22
+ ```js
23
+ import init, { load, scan_pii, version } from "agx-wasm";
24
+
25
+ await init(); // one-time panic-hook install
26
+
27
+ // Read a session file however the host allows.
28
+ const bytes = await fetch("session.jsonl").then(r => r.arrayBuffer());
29
+ const steps = load("session.jsonl", new Uint8Array(bytes));
30
+ for (const step of steps) {
31
+ console.log(step.kind, step.label);
32
+ }
33
+
34
+ // Arbitrary-text PII scan.
35
+ for (const m of scan_pii("my api key is sk-abc...")) {
36
+ console.log(m.category, m.snippet);
37
+ }
38
+
39
+ console.log(version());
40
+ ```
41
+
42
+ ## Schema
43
+
44
+ Every Step object mirrors the stable JSON schema documented in
45
+ [docs/eval-integration.md](https://github.com/brevity1swos/agx/blob/main/docs/eval-integration.md)
46
+ — same field names the CLI's `--export json` emits, same shape the
47
+ Python `agx.load` returns. Contract is versioned across the three
48
+ surfaces.
49
+
50
+ ## Why bytes, not paths?
51
+
52
+ WASM doesn't get a filesystem by default. The JS side owns I/O
53
+ (File / Blob / fetch / fs.readFileSync / Deno.readFile) and passes
54
+ raw bytes in. Format detection + parsing happen in the Rust wasm.
55
+
56
+ ## Distribution
57
+
58
+ Published to npm as `agx-wasm` by `.github/workflows/wasm-packages.yml`
59
+ when release-plz tags an agx-core release (`agx-core-v*`). The package
60
+ version follows agx-core's.
61
+
62
+ ## License
63
+
64
+ Dual-licensed under MIT OR Apache-2.0.
package/agx_wasm.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Call once from JS before using the other exports. Installs a
6
+ * panic hook that routes Rust panics to the browser console. Cheap
7
+ * and safe to call multiple times (no-op after first).
8
+ */
9
+ export function init(): void;
10
+
11
+ /**
12
+ * Load a session. `filename` is a hint used for format detection
13
+ * (agx-core uses content not extension, but this keeps error
14
+ * messages useful). `bytes` is the raw file content.
15
+ *
16
+ * Returns an array of Step-shaped JS objects — same keys as the
17
+ * Rust `--export json` output.
18
+ */
19
+ export function load(filename: string, bytes: Uint8Array): any;
20
+
21
+ /**
22
+ * Run agx-core's PII scanner over a string. Mirrors the CLI's
23
+ * `--scan-pii` output: one object per match with `category`,
24
+ * `step_index` (always 0 for free-text), and `snippet`.
25
+ */
26
+ export function scan_pii(text: string): any;
27
+
28
+ /**
29
+ * Version string exposed to JS as a module constant. Matches
30
+ * `Cargo.toml` package version.
31
+ */
32
+ export function version(): string;
package/agx_wasm.js ADDED
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./agx_wasm.d.ts" */
2
+ import * as wasm from "./agx_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./agx_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ init, load, scan_pii, version
9
+ } from "./agx_wasm_bg.js";
package/agx_wasm_bg.js ADDED
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Call once from JS before using the other exports. Installs a
3
+ * panic hook that routes Rust panics to the browser console. Cheap
4
+ * and safe to call multiple times (no-op after first).
5
+ */
6
+ export function init() {
7
+ wasm.init();
8
+ }
9
+
10
+ /**
11
+ * Load a session. `filename` is a hint used for format detection
12
+ * (agx-core uses content not extension, but this keeps error
13
+ * messages useful). `bytes` is the raw file content.
14
+ *
15
+ * Returns an array of Step-shaped JS objects — same keys as the
16
+ * Rust `--export json` output.
17
+ * @param {string} filename
18
+ * @param {Uint8Array} bytes
19
+ * @returns {any}
20
+ */
21
+ export function load(filename, bytes) {
22
+ const ptr0 = passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
23
+ const len0 = WASM_VECTOR_LEN;
24
+ const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
25
+ const len1 = WASM_VECTOR_LEN;
26
+ const ret = wasm.load(ptr0, len0, ptr1, len1);
27
+ if (ret[2]) {
28
+ throw takeFromExternrefTable0(ret[1]);
29
+ }
30
+ return takeFromExternrefTable0(ret[0]);
31
+ }
32
+
33
+ /**
34
+ * Run agx-core's PII scanner over a string. Mirrors the CLI's
35
+ * `--scan-pii` output: one object per match with `category`,
36
+ * `step_index` (always 0 for free-text), and `snippet`.
37
+ * @param {string} text
38
+ * @returns {any}
39
+ */
40
+ export function scan_pii(text) {
41
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
42
+ const len0 = WASM_VECTOR_LEN;
43
+ const ret = wasm.scan_pii(ptr0, len0);
44
+ if (ret[2]) {
45
+ throw takeFromExternrefTable0(ret[1]);
46
+ }
47
+ return takeFromExternrefTable0(ret[0]);
48
+ }
49
+
50
+ /**
51
+ * Version string exposed to JS as a module constant. Matches
52
+ * `Cargo.toml` package version.
53
+ * @returns {string}
54
+ */
55
+ export function version() {
56
+ let deferred1_0;
57
+ let deferred1_1;
58
+ try {
59
+ const ret = wasm.version();
60
+ deferred1_0 = ret[0];
61
+ deferred1_1 = ret[1];
62
+ return getStringFromWasm0(ret[0], ret[1]);
63
+ } finally {
64
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
65
+ }
66
+ }
67
+ export function __wbg_Error_960c155d3d49e4c2(arg0, arg1) {
68
+ const ret = Error(getStringFromWasm0(arg0, arg1));
69
+ return ret;
70
+ }
71
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
72
+ const ret = String(arg1);
73
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
74
+ const len1 = WASM_VECTOR_LEN;
75
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
76
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
77
+ }
78
+ export function __wbg___wbindgen_is_string_6df3bf7ef1164ed3(arg0) {
79
+ const ret = typeof(arg0) === 'string';
80
+ return ret;
81
+ }
82
+ export function __wbg___wbindgen_throw_6b64449b9b9ed33c(arg0, arg1) {
83
+ throw new Error(getStringFromWasm0(arg0, arg1));
84
+ }
85
+ export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
86
+ let deferred0_0;
87
+ let deferred0_1;
88
+ try {
89
+ deferred0_0 = arg0;
90
+ deferred0_1 = arg1;
91
+ console.error(getStringFromWasm0(arg0, arg1));
92
+ } finally {
93
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
94
+ }
95
+ }
96
+ export function __wbg_new_227d7c05414eb861() {
97
+ const ret = new Error();
98
+ return ret;
99
+ }
100
+ export function __wbg_new_34d45cc8e36aaead() {
101
+ const ret = new Map();
102
+ return ret;
103
+ }
104
+ export function __wbg_new_682678e2f47e32bc() {
105
+ const ret = new Array();
106
+ return ret;
107
+ }
108
+ export function __wbg_new_aa8d0fa9762c29bd() {
109
+ const ret = new Object();
110
+ return ret;
111
+ }
112
+ export function __wbg_set_3bf1de9fab0cd644(arg0, arg1, arg2) {
113
+ arg0[arg1 >>> 0] = arg2;
114
+ }
115
+ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
116
+ arg0[arg1] = arg2;
117
+ }
118
+ export function __wbg_set_fde2cec06c23692b(arg0, arg1, arg2) {
119
+ const ret = arg0.set(arg1, arg2);
120
+ return ret;
121
+ }
122
+ export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
123
+ const ret = arg1.stack;
124
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
125
+ const len1 = WASM_VECTOR_LEN;
126
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
127
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
128
+ }
129
+ export function __wbindgen_cast_0000000000000001(arg0) {
130
+ // Cast intrinsic for `F64 -> Externref`.
131
+ const ret = arg0;
132
+ return ret;
133
+ }
134
+ export function __wbindgen_cast_0000000000000002(arg0) {
135
+ // Cast intrinsic for `I64 -> Externref`.
136
+ const ret = arg0;
137
+ return ret;
138
+ }
139
+ export function __wbindgen_cast_0000000000000003(arg0, arg1) {
140
+ // Cast intrinsic for `Ref(String) -> Externref`.
141
+ const ret = getStringFromWasm0(arg0, arg1);
142
+ return ret;
143
+ }
144
+ export function __wbindgen_cast_0000000000000004(arg0) {
145
+ // Cast intrinsic for `U64 -> Externref`.
146
+ const ret = BigInt.asUintN(64, arg0);
147
+ return ret;
148
+ }
149
+ export function __wbindgen_init_externref_table() {
150
+ const table = wasm.__wbindgen_externrefs;
151
+ const offset = table.grow(4);
152
+ table.set(0, undefined);
153
+ table.set(offset + 0, undefined);
154
+ table.set(offset + 1, null);
155
+ table.set(offset + 2, true);
156
+ table.set(offset + 3, false);
157
+ }
158
+ let cachedDataViewMemory0 = null;
159
+ function getDataViewMemory0() {
160
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
161
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
162
+ }
163
+ return cachedDataViewMemory0;
164
+ }
165
+
166
+ function getStringFromWasm0(ptr, len) {
167
+ ptr = ptr >>> 0;
168
+ return decodeText(ptr, len);
169
+ }
170
+
171
+ let cachedUint8ArrayMemory0 = null;
172
+ function getUint8ArrayMemory0() {
173
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
174
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
175
+ }
176
+ return cachedUint8ArrayMemory0;
177
+ }
178
+
179
+ function passArray8ToWasm0(arg, malloc) {
180
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
181
+ getUint8ArrayMemory0().set(arg, ptr / 1);
182
+ WASM_VECTOR_LEN = arg.length;
183
+ return ptr;
184
+ }
185
+
186
+ function passStringToWasm0(arg, malloc, realloc) {
187
+ if (realloc === undefined) {
188
+ const buf = cachedTextEncoder.encode(arg);
189
+ const ptr = malloc(buf.length, 1) >>> 0;
190
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
191
+ WASM_VECTOR_LEN = buf.length;
192
+ return ptr;
193
+ }
194
+
195
+ let len = arg.length;
196
+ let ptr = malloc(len, 1) >>> 0;
197
+
198
+ const mem = getUint8ArrayMemory0();
199
+
200
+ let offset = 0;
201
+
202
+ for (; offset < len; offset++) {
203
+ const code = arg.charCodeAt(offset);
204
+ if (code > 0x7F) break;
205
+ mem[ptr + offset] = code;
206
+ }
207
+ if (offset !== len) {
208
+ if (offset !== 0) {
209
+ arg = arg.slice(offset);
210
+ }
211
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
212
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
213
+ const ret = cachedTextEncoder.encodeInto(arg, view);
214
+
215
+ offset += ret.written;
216
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
217
+ }
218
+
219
+ WASM_VECTOR_LEN = offset;
220
+ return ptr;
221
+ }
222
+
223
+ function takeFromExternrefTable0(idx) {
224
+ const value = wasm.__wbindgen_externrefs.get(idx);
225
+ wasm.__externref_table_dealloc(idx);
226
+ return value;
227
+ }
228
+
229
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
230
+ cachedTextDecoder.decode();
231
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
232
+ let numBytesDecoded = 0;
233
+ function decodeText(ptr, len) {
234
+ numBytesDecoded += len;
235
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
236
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
237
+ cachedTextDecoder.decode();
238
+ numBytesDecoded = len;
239
+ }
240
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
241
+ }
242
+
243
+ const cachedTextEncoder = new TextEncoder();
244
+
245
+ if (!('encodeInto' in cachedTextEncoder)) {
246
+ cachedTextEncoder.encodeInto = function (arg, view) {
247
+ const buf = cachedTextEncoder.encode(arg);
248
+ view.set(buf);
249
+ return {
250
+ read: arg.length,
251
+ written: buf.length
252
+ };
253
+ };
254
+ }
255
+
256
+ let WASM_VECTOR_LEN = 0;
257
+
258
+
259
+ let wasm;
260
+ export function __wbg_set_wasm(val) {
261
+ wasm = val;
262
+ }
Binary file
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "agx-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "type": "module",
4
+ "description": "WebAssembly / TypeScript bindings for agx-core — load and inspect AI agent traces from browsers and Node.",
5
+ "version": "0.5.0",
6
+ "license": "MIT OR Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/brevity1swos/agx"
10
+ },
11
+ "files": [
12
+ "agx_wasm_bg.wasm",
13
+ "agx_wasm.js",
14
+ "agx_wasm_bg.js",
15
+ "agx_wasm.d.ts"
16
+ ],
17
+ "main": "agx_wasm.js",
18
+ "types": "agx_wasm.d.ts",
19
+ "sideEffects": [
20
+ "./agx_wasm.js",
21
+ "./snippets/*"
22
+ ]
23
+ }