@pi-oxide/extension-js 0.2.4 → 0.4.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/extension_js.d.ts CHANGED
@@ -4,93 +4,57 @@
4
4
  * A single global variable observed by `inspect_globals`.
5
5
  */
6
6
  export interface WasmGlobalVariable {
7
- name: string;
8
- type: string;
9
- value: string | null;
10
- keys: string[] | null;
7
+ name: string;
8
+ type: string;
9
+ value: string | null;
10
+ keys: string[] | null;
11
11
  }
12
12
 
13
13
  /**
14
14
  * An async command yielded from JS, waiting for external resolution.
15
15
  */
16
16
  export interface WasmAsyncCommand {
17
- call_id: number;
18
- action: string;
19
- params: unknown;
17
+ call_id: number;
18
+ action: string;
19
+ params: CommandParams;
20
+ run_id: string | null;
20
21
  }
21
22
 
22
23
  /**
23
24
  * Consumer-facing result of running a single cell.
24
25
  * Either success with an optional result string, or an error.
25
26
  */
26
- export type CellResult =
27
- | {
28
- status: "ok";
29
- stdout: string[];
30
- stderr: string[];
31
- result: string | null;
32
- execution_count: number;
33
- }
34
- | {
35
- status: "err";
36
- stdout: string[];
37
- stderr: string[];
38
- error: WasmCellError;
39
- execution_count: number;
40
- };
27
+ export type CellResult = { status: "ok"; stdout: string[]; stderr: string[]; result: string | null; execution_count: number } | { status: "err"; stdout: string[]; stderr: string[]; error: WasmCellError; execution_count: number };
41
28
 
42
29
  /**
43
30
  * Error details inside an async response.
44
31
  */
45
32
  export interface WasmAsyncError {
46
- message: string;
47
- code: string;
33
+ message: string;
34
+ code: string;
48
35
  }
49
36
 
50
37
  /**
51
38
  * Response passed to `resume_cell` to resolve an async yield.
52
39
  */
53
40
  export interface WasmAsyncResponse {
54
- ok: boolean;
55
- value: unknown;
56
- error: WasmAsyncError | null;
41
+ ok: boolean;
42
+ value: Value | null;
43
+ error: WasmAsyncError | null;
57
44
  }
58
45
 
59
46
  /**
60
47
  * Result of running a single cell, including async-loop state.
61
48
  * Either still pending (waiting for async resolution) or done.
62
49
  */
63
- export type WasmRunResult =
64
- | {
65
- status: "pending";
66
- stdout: string[];
67
- stderr: string[];
68
- commands: unknown[];
69
- fuel_exhausted: boolean;
70
- execution_count: number;
71
- pending_commands: WasmAsyncCommand[];
72
- }
73
- | {
74
- status: "ok";
75
- stdout: string[];
76
- stderr: string[];
77
- result: string | null;
78
- execution_count: number;
79
- }
80
- | {
81
- status: "err";
82
- stdout: string[];
83
- stderr: string[];
84
- error: WasmCellError;
85
- execution_count: number;
86
- };
50
+ export type WasmRunResult = { status: "pending"; stdout: string[]; stderr: string[]; commands: CommandParams[]; fuel_exhausted: boolean; execution_count: number; pending_commands: WasmAsyncCommand[] } | { status: "ok"; stdout: string[]; stderr: string[]; result: string | null; execution_count: number } | { status: "err"; stdout: string[]; stderr: string[]; error: WasmCellError; execution_count: number };
87
51
 
88
52
  /**
89
53
  * Snapshot of all JS globals.
90
54
  */
91
55
  export interface WasmGlobalsSnapshot {
92
- variables: WasmGlobalVariable[];
93
- execution_count: number;
56
+ variables: WasmGlobalVariable[];
57
+ execution_count: number;
94
58
  }
95
59
 
96
60
  /**
@@ -101,211 +65,340 @@ export type WasmCellStatus = "done" | "async_pending";
101
65
  /**
102
66
  * Structured error from running a cell.
103
67
  */
104
- export type WasmCellError =
105
- | { kind: "compile"; message: string; line: number | null }
106
- | { kind: "runtime"; message: string; line: number | null }
107
- | { kind: "fuel_exhausted" }
108
- | { kind: "internal"; message: string };
68
+ export type WasmCellError = { kind: "compile"; name: string | null; message: string; line: number | null } | { kind: "runtime"; name: string | null; message: string; line: number | null; action: string | null; code: string | null } | { kind: "fuel_exhausted" } | { kind: "internal"; message: string };
109
69
 
110
70
  export interface CollectOptions {
111
- includeHidden?: boolean;
112
- includeNonInteractive?: boolean;
113
- includeGeometry?: boolean;
114
- includePath?: boolean;
115
- maxTextLength?: number;
116
- maxNodes?: number;
117
- interactiveOnly?: boolean;
118
- format?: SnapshotFormat;
71
+ includeHidden?: boolean;
72
+ includeNonInteractive?: boolean;
73
+ includeGeometry?: boolean;
74
+ includePath?: boolean;
75
+ maxTextLength?: number;
76
+ maxNodes?: number;
77
+ interactiveOnly?: boolean;
78
+ format?: SnapshotFormat;
79
+ }
80
+
81
+ export interface FsBoolResult {
82
+ ok: boolean;
83
+ }
84
+
85
+ export interface FsCopyParams {
86
+ from: string;
87
+ to: string;
88
+ }
89
+
90
+ export interface FsExistsResult {
91
+ exists: boolean;
92
+ }
93
+
94
+ export interface FsHashParams {
95
+ path: string;
96
+ algo: string;
97
+ }
98
+
99
+ export interface FsHashResult {
100
+ hash: string;
101
+ }
102
+
103
+ export interface FsListEntry {
104
+ name: string;
105
+ kind: string;
106
+ }
107
+
108
+ export interface FsListResult {
109
+ entries: FsListEntry[];
110
+ }
111
+
112
+ export interface FsPathParams {
113
+ path: string;
114
+ }
115
+
116
+ export interface FsReadRangeDataParams {
117
+ path: string;
118
+ offset: number;
119
+ data: string;
120
+ }
121
+
122
+ export interface FsReadRangeParams {
123
+ path: string;
124
+ offset: number;
125
+ len: number;
126
+ }
127
+
128
+ export interface FsStatResult {
129
+ path: string;
130
+ name: string;
131
+ kind: string;
132
+ size: number;
133
+ mime: string | null;
134
+ created_at: number | null;
135
+ modified_at: number | null;
136
+ }
137
+
138
+ export interface FsStringResult {
139
+ data: string;
140
+ }
141
+
142
+ export interface FsWriteParams {
143
+ path: string;
144
+ data: string;
145
+ }
146
+
147
+ export interface JsApiAlias {
148
+ namespace: string;
149
+ name: string;
150
+ fields: string[] | null;
151
+ }
152
+
153
+ export interface JsManifestEntry {
154
+ action: string;
155
+ namespace: string;
156
+ name: string;
157
+ publicName: string;
158
+ description: string;
159
+ fields: string[] | null;
160
+ aliases: JsApiAlias[];
161
+ paramsDoc: JsParamDoc[];
162
+ returnsDoc: JsReturnDoc;
163
+ errorCode: string;
164
+ errorCategory: string | null;
165
+ permission: string | null;
166
+ example: string | null;
167
+ }
168
+
169
+ export interface JsParamDoc {
170
+ name: string;
171
+ type: string;
172
+ required: boolean;
173
+ description: string;
174
+ }
175
+
176
+ export interface JsReturnDoc {
177
+ type: string;
178
+ description: string;
119
179
  }
120
180
 
121
181
  export interface OutlineNode {
122
- role: string;
123
- name: string;
124
- ref_id: string;
182
+ role: string;
183
+ name: string;
184
+ ref_id: string;
125
185
  }
126
186
 
127
187
  export interface Rect {
128
- x: number;
129
- y: number;
130
- width: number;
131
- height: number;
132
- top: number;
133
- right: number;
134
- bottom: number;
135
- left: number;
188
+ x: number;
189
+ y: number;
190
+ width: number;
191
+ height: number;
192
+ top: number;
193
+ right: number;
194
+ bottom: number;
195
+ left: number;
136
196
  }
137
197
 
138
198
  export interface SemanticNode {
139
- refId: string;
140
- role: string;
141
- name?: string;
142
- description?: string;
143
- tag: string;
144
- id?: string;
145
- classes?: string[];
146
- value?: string;
147
- placeholder?: string;
148
- href?: string;
149
- states: States;
150
- inputType?: string;
151
- rect?: Rect;
152
- inViewport: boolean;
153
- visible: boolean;
154
- path?: string;
199
+ refId: string;
200
+ role: string;
201
+ name?: string;
202
+ description?: string;
203
+ tag: string;
204
+ id?: string;
205
+ classes?: string[];
206
+ value?: string;
207
+ placeholder?: string;
208
+ href?: string;
209
+ states: States;
210
+ inputType?: string;
211
+ rect?: Rect;
212
+ inViewport: boolean;
213
+ visible: boolean;
214
+ path?: string;
155
215
  }
156
216
 
157
217
  export interface States {
158
- disabled?: boolean;
159
- checked?: boolean;
160
- selected?: boolean;
161
- expanded?: boolean;
162
- pressed?: boolean;
163
- required?: boolean;
164
- readonly?: boolean;
165
- invalid?: boolean;
166
- hidden?: boolean;
167
- focusable?: boolean;
168
- interactive?: boolean;
169
- current?: boolean;
218
+ disabled?: boolean;
219
+ checked?: boolean;
220
+ selected?: boolean;
221
+ expanded?: boolean;
222
+ pressed?: boolean;
223
+ required?: boolean;
224
+ readonly?: boolean;
225
+ invalid?: boolean;
226
+ hidden?: boolean;
227
+ focusable?: boolean;
228
+ interactive?: boolean;
229
+ current?: boolean;
170
230
  }
171
231
 
172
232
  export interface TreeSnapshot {
173
- version: string;
174
- url: string | null;
175
- title: string | null;
176
- viewport: Viewport | null;
177
- nodes: SemanticNode[];
178
- outline?: OutlineNode[];
233
+ version: string;
234
+ url: string | null;
235
+ title: string | null;
236
+ viewport: Viewport | null;
237
+ nodes: SemanticNode[];
238
+ outline?: OutlineNode[];
179
239
  }
180
240
 
181
241
  export interface Viewport {
182
- width: number;
183
- height: number;
184
- scrollX: number;
185
- scrollY: number;
242
+ width: number;
243
+ height: number;
244
+ scrollX: number;
245
+ scrollY: number;
186
246
  }
187
247
 
188
248
  export type SnapshotFormat = "compact-text" | "json" | "json-pretty";
189
249
 
250
+
190
251
  /**
191
252
  * ExtensionSession wraps BaseSession for the Chrome Extension environment.
192
- * WASM runs inside a Web Worker; all browser side-effects are relayed
193
- * to the main-thread runner via the `__extension_js_relay` global function.
253
+ * WASM runs inside a Web Worker; all browser side-effects are dispatched
254
+ * through the unified executable handler registry (Rust-local handlers or JS-registered callbacks).
194
255
  */
195
256
  export class ExtensionSession {
196
- free(): void;
197
- [Symbol.dispose](): void;
198
- /**
199
- * Inspect all global variables in the current JS state.
200
- */
201
- inspect_globals(): WasmGlobalsSnapshot;
202
- /**
203
- * Load a JS library by executing its source code.
204
- */
205
- load_library(source: string): CellResult;
206
- /**
207
- * Create a new extension session.
208
- */
209
- constructor();
210
- /**
211
- * Reset the session, clearing all JS state.
212
- */
213
- reset(): void;
214
- /**
215
- * Run a cell, automatically resolving all async calls by relaying
216
- * them to the main-thread runner via `__extension_js_relay`.
217
- */
218
- runCellAsync(code: string, stdin: string): Promise<CellResult>;
219
- /**
220
- * Set the fuel limit for execution.
221
- */
222
- set_fuel_limit(limit: number): void;
223
- /**
224
- * Clean up the session and release resources.
225
- */
226
- stopWith(): void;
257
+ free(): void;
258
+ [Symbol.dispose](): void;
259
+ /**
260
+ * Generate API documentation for every registered public API.
261
+ */
262
+ apiDocs(format: string): string;
263
+ fsAppend(params: FsWriteParams): Promise<FsBoolResult>;
264
+ fsAppendBase64(params: FsWriteParams): Promise<FsBoolResult>;
265
+ fsAppendText(params: FsWriteParams): Promise<FsBoolResult>;
266
+ fsCopy(params: FsCopyParams): Promise<FsBoolResult>;
267
+ fsDelete(params: FsPathParams): Promise<FsBoolResult>;
268
+ fsExists(params: FsPathParams): Promise<FsExistsResult>;
269
+ fsHash(params: FsHashParams): Promise<FsHashResult>;
270
+ fsList(params: FsPathParams): Promise<FsListResult>;
271
+ fsMkdir(params: FsPathParams): Promise<FsBoolResult>;
272
+ fsMove(params: FsCopyParams): Promise<FsBoolResult>;
273
+ fsRead(params: FsPathParams): Promise<FsStringResult>;
274
+ fsReadBase64(params: FsPathParams): Promise<FsStringResult>;
275
+ fsReadRange(params: FsReadRangeParams): Promise<FsStringResult>;
276
+ fsReadText(params: FsPathParams): Promise<FsStringResult>;
277
+ fsStat(params: FsPathParams): Promise<FsStatResult>;
278
+ fsUpdate(params: FsReadRangeDataParams): Promise<FsBoolResult>;
279
+ fsWrite(params: FsWriteParams): Promise<FsBoolResult>;
280
+ fsWriteBase64(params: FsWriteParams): Promise<FsBoolResult>;
281
+ fsWriteText(params: FsWriteParams): Promise<FsBoolResult>;
282
+ /**
283
+ * Inject async and sync API bindings from the doc registry into the JS environment.
284
+ * Must be called after all manifest entries are registered.
285
+ */
286
+ injectRegistryBindings(): void;
287
+ /**
288
+ * Inspect all global variables in the current JS state.
289
+ */
290
+ inspect_globals(): WasmGlobalsSnapshot;
291
+ /**
292
+ * Load a JS library by executing its source code.
293
+ */
294
+ load_library(source: string): CellResult;
295
+ /**
296
+ * Create a new extension session.
297
+ */
298
+ constructor();
299
+ /**
300
+ * Reset the session, clearing all JS state.
301
+ */
302
+ reset(): void;
303
+ /**
304
+ * Run a cell, automatically resolving all async calls through the
305
+ * unified handler registry.
306
+ */
307
+ runCellAsync(code: string, stdin: string, run_id: string): Promise<CellResult>;
308
+ /**
309
+ * Signal the async execution loop to abort between command batches.
310
+ */
311
+ setAborted(value: boolean): void;
312
+ /**
313
+ * Set the fuel limit for execution.
314
+ */
315
+ set_fuel_limit(limit: number): void;
316
+ /**
317
+ * Clean up the session and release resources.
318
+ */
319
+ stopWith(): void;
227
320
  }
228
321
 
229
322
  export function collect_document(options: CollectOptions): TreeSnapshot;
230
323
 
231
- export function collect_element(
232
- root: Element,
233
- options: CollectOptions,
234
- ): TreeSnapshot;
324
+ export function collect_element(root: Element, options: CollectOptions): TreeSnapshot;
325
+
326
+ export function format_snapshot_js(snapshot: TreeSnapshot, format?: SnapshotFormat | null): string;
327
+
328
+ export function freezeManifest(): void;
329
+
330
+ export function importManifestEntries(entries: Array<any>): void;
331
+
332
+ export function main(): void;
333
+
334
+ export function registerJsCall(entry: JsManifestEntry, callback: Function): void;
235
335
 
236
- export function format_snapshot_js(
237
- snapshot: TreeSnapshot,
238
- format?: SnapshotFormat | null,
239
- ): string;
336
+ export function registerJsCallBatch(items: Array<any>): void;
240
337
 
241
- export function generateApiDocs(format: string): string;
338
+ export function registerSharedDispatch(callback: Function): void;
242
339
 
243
340
  /**
244
- * 0=debug, 1=info, 2=warn, 3=error, 4=none
341
+ * 0=trace, 1=debug, 2=info, 3=warn, 4=error, 5=none
245
342
  */
246
343
  export function setLogLevel(level: number): void;
247
344
 
248
- export type InitInput =
249
- | RequestInfo
250
- | URL
251
- | Response
252
- | BufferSource
253
- | WebAssembly.Module;
345
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
254
346
 
255
347
  export interface InitOutput {
256
- readonly memory: WebAssembly.Memory;
257
- readonly __wbg_extensionsession_free: (a: number, b: number) => void;
258
- readonly extensionsession_inspect_globals: (a: number) => any;
259
- readonly extensionsession_load_library: (
260
- a: number,
261
- b: number,
262
- c: number,
263
- ) => any;
264
- readonly extensionsession_new: () => number;
265
- readonly extensionsession_reset: (a: number) => void;
266
- readonly extensionsession_runCellAsync: (
267
- a: number,
268
- b: number,
269
- c: number,
270
- d: number,
271
- e: number,
272
- ) => any;
273
- readonly extensionsession_set_fuel_limit: (a: number, b: number) => void;
274
- readonly extensionsession_stopWith: (a: number) => void;
275
- readonly setLogLevel: (a: number) => void;
276
- readonly generateApiDocs: (a: number, b: number) => [number, number];
277
- readonly collect_document: (a: any) => any;
278
- readonly collect_element: (a: any, b: any) => any;
279
- readonly format_snapshot_js: (a: any, b: number) => [number, number];
280
- readonly wasm_bindgen__convert__closures_____invoke__hbaf3bd60d2f803db: (
281
- a: number,
282
- b: number,
283
- c: any,
284
- ) => [number, number];
285
- readonly wasm_bindgen__convert__closures_____invoke__hf458ead16698aa30: (
286
- a: number,
287
- b: number,
288
- c: any,
289
- d: any,
290
- ) => void;
291
- readonly wasm_bindgen__convert__closures_____invoke__hd488ef5680429ef6: (
292
- a: number,
293
- b: number,
294
- ) => number;
295
- readonly __wbindgen_malloc: (a: number, b: number) => number;
296
- readonly __wbindgen_realloc: (
297
- a: number,
298
- b: number,
299
- c: number,
300
- d: number,
301
- ) => number;
302
- readonly __wbindgen_exn_store: (a: number) => void;
303
- readonly __externref_table_alloc: () => number;
304
- readonly __wbindgen_externrefs: WebAssembly.Table;
305
- readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
306
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
307
- readonly __externref_table_dealloc: (a: number) => void;
308
- readonly __wbindgen_start: () => void;
348
+ readonly memory: WebAssembly.Memory;
349
+ readonly __wbg_extensionsession_free: (a: number, b: number) => void;
350
+ readonly extensionsession_apiDocs: (a: number, b: number, c: number) => [number, number, number, number];
351
+ readonly extensionsession_fsAppend: (a: number, b: any) => any;
352
+ readonly extensionsession_fsAppendBase64: (a: number, b: any) => any;
353
+ readonly extensionsession_fsAppendText: (a: number, b: any) => any;
354
+ readonly extensionsession_fsCopy: (a: number, b: any) => any;
355
+ readonly extensionsession_fsDelete: (a: number, b: any) => any;
356
+ readonly extensionsession_fsExists: (a: number, b: any) => any;
357
+ readonly extensionsession_fsHash: (a: number, b: any) => any;
358
+ readonly extensionsession_fsList: (a: number, b: any) => any;
359
+ readonly extensionsession_fsMkdir: (a: number, b: any) => any;
360
+ readonly extensionsession_fsMove: (a: number, b: any) => any;
361
+ readonly extensionsession_fsRead: (a: number, b: any) => any;
362
+ readonly extensionsession_fsReadBase64: (a: number, b: any) => any;
363
+ readonly extensionsession_fsReadRange: (a: number, b: any) => any;
364
+ readonly extensionsession_fsReadText: (a: number, b: any) => any;
365
+ readonly extensionsession_fsStat: (a: number, b: any) => any;
366
+ readonly extensionsession_fsUpdate: (a: number, b: any) => any;
367
+ readonly extensionsession_fsWrite: (a: number, b: any) => any;
368
+ readonly extensionsession_fsWriteBase64: (a: number, b: any) => any;
369
+ readonly extensionsession_fsWriteText: (a: number, b: any) => any;
370
+ readonly extensionsession_injectRegistryBindings: (a: number) => void;
371
+ readonly extensionsession_inspect_globals: (a: number) => any;
372
+ readonly extensionsession_load_library: (a: number, b: number, c: number) => any;
373
+ readonly extensionsession_new: () => number;
374
+ readonly extensionsession_reset: (a: number) => void;
375
+ readonly extensionsession_runCellAsync: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
376
+ readonly extensionsession_setAborted: (a: number, b: number) => void;
377
+ readonly extensionsession_set_fuel_limit: (a: number, b: number) => void;
378
+ readonly extensionsession_stopWith: (a: number) => void;
379
+ readonly freezeManifest: () => [number, number];
380
+ readonly importManifestEntries: (a: any) => [number, number];
381
+ readonly main: () => void;
382
+ readonly registerJsCall: (a: any, b: any) => [number, number];
383
+ readonly registerJsCallBatch: (a: any) => [number, number];
384
+ readonly registerSharedDispatch: (a: any) => [number, number];
385
+ readonly setLogLevel: (a: number) => void;
386
+ readonly collect_document: (a: any) => any;
387
+ readonly collect_element: (a: any, b: any) => any;
388
+ readonly format_snapshot_js: (a: any, b: number) => [number, number];
389
+ readonly wasm_bindgen__convert__closures_____invoke__hafd7db4a84e7076d: (a: number, b: number, c: any) => [number, number];
390
+ readonly wasm_bindgen__convert__closures_____invoke__h72adce5fbcd58c92: (a: number, b: number, c: any, d: any) => void;
391
+ readonly wasm_bindgen__convert__closures_____invoke__h027ec0463d981e5e: (a: number, b: number) => number;
392
+ readonly wasm_bindgen__convert__closures_____invoke__h2f71c847222394ea: (a: number, b: number) => void;
393
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
394
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
395
+ readonly __wbindgen_exn_store: (a: number) => void;
396
+ readonly __externref_table_alloc: () => number;
397
+ readonly __wbindgen_externrefs: WebAssembly.Table;
398
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
399
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
400
+ readonly __externref_table_dealloc: (a: number) => void;
401
+ readonly __wbindgen_start: () => void;
309
402
  }
310
403
 
311
404
  export type SyncInitInput = BufferSource | WebAssembly.Module;
@@ -318,9 +411,7 @@ export type SyncInitInput = BufferSource | WebAssembly.Module;
318
411
  *
319
412
  * @returns {InitOutput}
320
413
  */
321
- export function initSync(
322
- module: { module: SyncInitInput } | SyncInitInput,
323
- ): InitOutput;
414
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
324
415
 
325
416
  /**
326
417
  * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
@@ -330,9 +421,4 @@ export function initSync(
330
421
  *
331
422
  * @returns {Promise<InitOutput>}
332
423
  */
333
- export default function __wbg_init(
334
- module_or_path?:
335
- | { module_or_path: InitInput | Promise<InitInput> }
336
- | InitInput
337
- | Promise<InitInput>,
338
- ): Promise<InitOutput>;
424
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;