@pi-oxide/extension-js 0.2.4 → 0.3.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,336 @@ 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"; message: string; line: number | null } | { kind: "runtime"; message: string; line: number | 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
+ }
166
+
167
+ export interface JsParamDoc {
168
+ name: string;
169
+ type: string;
170
+ required: boolean;
171
+ description: string;
172
+ }
173
+
174
+ export interface JsReturnDoc {
175
+ type: string;
176
+ description: string;
119
177
  }
120
178
 
121
179
  export interface OutlineNode {
122
- role: string;
123
- name: string;
124
- ref_id: string;
180
+ role: string;
181
+ name: string;
182
+ ref_id: string;
125
183
  }
126
184
 
127
185
  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;
186
+ x: number;
187
+ y: number;
188
+ width: number;
189
+ height: number;
190
+ top: number;
191
+ right: number;
192
+ bottom: number;
193
+ left: number;
136
194
  }
137
195
 
138
196
  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;
197
+ refId: string;
198
+ role: string;
199
+ name?: string;
200
+ description?: string;
201
+ tag: string;
202
+ id?: string;
203
+ classes?: string[];
204
+ value?: string;
205
+ placeholder?: string;
206
+ href?: string;
207
+ states: States;
208
+ inputType?: string;
209
+ rect?: Rect;
210
+ inViewport: boolean;
211
+ visible: boolean;
212
+ path?: string;
155
213
  }
156
214
 
157
215
  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;
216
+ disabled?: boolean;
217
+ checked?: boolean;
218
+ selected?: boolean;
219
+ expanded?: boolean;
220
+ pressed?: boolean;
221
+ required?: boolean;
222
+ readonly?: boolean;
223
+ invalid?: boolean;
224
+ hidden?: boolean;
225
+ focusable?: boolean;
226
+ interactive?: boolean;
227
+ current?: boolean;
170
228
  }
171
229
 
172
230
  export interface TreeSnapshot {
173
- version: string;
174
- url: string | null;
175
- title: string | null;
176
- viewport: Viewport | null;
177
- nodes: SemanticNode[];
178
- outline?: OutlineNode[];
231
+ version: string;
232
+ url: string | null;
233
+ title: string | null;
234
+ viewport: Viewport | null;
235
+ nodes: SemanticNode[];
236
+ outline?: OutlineNode[];
179
237
  }
180
238
 
181
239
  export interface Viewport {
182
- width: number;
183
- height: number;
184
- scrollX: number;
185
- scrollY: number;
240
+ width: number;
241
+ height: number;
242
+ scrollX: number;
243
+ scrollY: number;
186
244
  }
187
245
 
188
246
  export type SnapshotFormat = "compact-text" | "json" | "json-pretty";
189
247
 
248
+
190
249
  /**
191
250
  * 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.
251
+ * WASM runs inside a Web Worker; all browser side-effects are dispatched
252
+ * through the unified executable handler registry (Rust-local handlers or JS-registered callbacks).
194
253
  */
195
254
  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;
255
+ free(): void;
256
+ [Symbol.dispose](): void;
257
+ fsAppend(params: FsWriteParams): Promise<FsBoolResult>;
258
+ fsAppendBase64(params: FsWriteParams): Promise<FsBoolResult>;
259
+ fsAppendText(params: FsWriteParams): Promise<FsBoolResult>;
260
+ fsCopy(params: FsCopyParams): Promise<FsBoolResult>;
261
+ fsDelete(params: FsPathParams): Promise<FsBoolResult>;
262
+ fsExists(params: FsPathParams): Promise<FsExistsResult>;
263
+ fsHash(params: FsHashParams): Promise<FsHashResult>;
264
+ fsList(params: FsPathParams): Promise<FsListResult>;
265
+ fsMkdir(params: FsPathParams): Promise<FsBoolResult>;
266
+ fsMove(params: FsCopyParams): Promise<FsBoolResult>;
267
+ fsRead(params: FsPathParams): Promise<FsStringResult>;
268
+ fsReadBase64(params: FsPathParams): Promise<FsStringResult>;
269
+ fsReadRange(params: FsReadRangeParams): Promise<FsStringResult>;
270
+ fsReadText(params: FsPathParams): Promise<FsStringResult>;
271
+ fsStat(params: FsPathParams): Promise<FsStatResult>;
272
+ fsUpdate(params: FsReadRangeDataParams): Promise<FsBoolResult>;
273
+ fsWrite(params: FsWriteParams): Promise<FsBoolResult>;
274
+ fsWriteBase64(params: FsWriteParams): Promise<FsBoolResult>;
275
+ fsWriteText(params: FsWriteParams): Promise<FsBoolResult>;
276
+ /**
277
+ * Inject async and sync API bindings from the doc registry into the JS environment.
278
+ * Must be called after all manifest entries are registered.
279
+ */
280
+ injectRegistryBindings(): void;
281
+ /**
282
+ * Inspect all global variables in the current JS state.
283
+ */
284
+ inspect_globals(): WasmGlobalsSnapshot;
285
+ /**
286
+ * Load a JS library by executing its source code.
287
+ */
288
+ load_library(source: string): CellResult;
289
+ /**
290
+ * Create a new extension session.
291
+ */
292
+ constructor();
293
+ /**
294
+ * Reset the session, clearing all JS state.
295
+ */
296
+ reset(): void;
297
+ /**
298
+ * Run a cell, automatically resolving all async calls through the
299
+ * unified handler registry.
300
+ */
301
+ runCellAsync(code: string, stdin: string, run_id: string): Promise<CellResult>;
302
+ /**
303
+ * Signal the async execution loop to abort between command batches.
304
+ */
305
+ setAborted(value: boolean): void;
306
+ /**
307
+ * Set the fuel limit for execution.
308
+ */
309
+ set_fuel_limit(limit: number): void;
310
+ /**
311
+ * Clean up the session and release resources.
312
+ */
313
+ stopWith(): void;
227
314
  }
228
315
 
229
316
  export function collect_document(options: CollectOptions): TreeSnapshot;
230
317
 
231
- export function collect_element(
232
- root: Element,
233
- options: CollectOptions,
234
- ): TreeSnapshot;
318
+ export function collect_element(root: Element, options: CollectOptions): TreeSnapshot;
319
+
320
+ export function format_snapshot_js(snapshot: TreeSnapshot, format?: SnapshotFormat | null): string;
235
321
 
236
- export function format_snapshot_js(
237
- snapshot: TreeSnapshot,
238
- format?: SnapshotFormat | null,
239
- ): string;
322
+ export function freezeManifest(): void;
240
323
 
241
324
  export function generateApiDocs(format: string): string;
242
325
 
326
+ export function importManifestEntries(entries: Array<any>): void;
327
+
328
+ export function main(): void;
329
+
330
+ export function registerJsCall(entry: JsManifestEntry, callback: Function): void;
331
+
332
+ export function registerJsCallBatch(items: Array<any>): void;
333
+
334
+ export function registerSharedDispatch(callback: Function): void;
335
+
243
336
  /**
244
337
  * 0=debug, 1=info, 2=warn, 3=error, 4=none
245
338
  */
246
339
  export function setLogLevel(level: number): void;
247
340
 
248
- export type InitInput =
249
- | RequestInfo
250
- | URL
251
- | Response
252
- | BufferSource
253
- | WebAssembly.Module;
341
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
254
342
 
255
343
  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;
344
+ readonly memory: WebAssembly.Memory;
345
+ readonly __wbg_extensionsession_free: (a: number, b: number) => void;
346
+ readonly extensionsession_fsAppend: (a: number, b: any) => any;
347
+ readonly extensionsession_fsAppendBase64: (a: number, b: any) => any;
348
+ readonly extensionsession_fsAppendText: (a: number, b: any) => any;
349
+ readonly extensionsession_fsCopy: (a: number, b: any) => any;
350
+ readonly extensionsession_fsDelete: (a: number, b: any) => any;
351
+ readonly extensionsession_fsExists: (a: number, b: any) => any;
352
+ readonly extensionsession_fsHash: (a: number, b: any) => any;
353
+ readonly extensionsession_fsList: (a: number, b: any) => any;
354
+ readonly extensionsession_fsMkdir: (a: number, b: any) => any;
355
+ readonly extensionsession_fsMove: (a: number, b: any) => any;
356
+ readonly extensionsession_fsRead: (a: number, b: any) => any;
357
+ readonly extensionsession_fsReadBase64: (a: number, b: any) => any;
358
+ readonly extensionsession_fsReadRange: (a: number, b: any) => any;
359
+ readonly extensionsession_fsReadText: (a: number, b: any) => any;
360
+ readonly extensionsession_fsStat: (a: number, b: any) => any;
361
+ readonly extensionsession_fsUpdate: (a: number, b: any) => any;
362
+ readonly extensionsession_fsWrite: (a: number, b: any) => any;
363
+ readonly extensionsession_fsWriteBase64: (a: number, b: any) => any;
364
+ readonly extensionsession_fsWriteText: (a: number, b: any) => any;
365
+ readonly extensionsession_injectRegistryBindings: (a: number) => void;
366
+ readonly extensionsession_inspect_globals: (a: number) => any;
367
+ readonly extensionsession_load_library: (a: number, b: number, c: number) => any;
368
+ readonly extensionsession_new: () => number;
369
+ readonly extensionsession_reset: (a: number) => void;
370
+ readonly extensionsession_runCellAsync: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
371
+ readonly extensionsession_setAborted: (a: number, b: number) => void;
372
+ readonly extensionsession_set_fuel_limit: (a: number, b: number) => void;
373
+ readonly extensionsession_stopWith: (a: number) => void;
374
+ readonly freezeManifest: () => void;
375
+ readonly generateApiDocs: (a: number, b: number) => [number, number, number, number];
376
+ readonly importManifestEntries: (a: any) => [number, number];
377
+ readonly main: () => void;
378
+ readonly registerJsCall: (a: any, b: any) => [number, number];
379
+ readonly registerJsCallBatch: (a: any) => [number, number];
380
+ readonly registerSharedDispatch: (a: any) => [number, number];
381
+ readonly setLogLevel: (a: number) => void;
382
+ readonly collect_document: (a: any) => any;
383
+ readonly collect_element: (a: any, b: any) => any;
384
+ readonly format_snapshot_js: (a: any, b: number) => [number, number];
385
+ readonly wasm_bindgen__convert__closures_____invoke__hafd7db4a84e7076d: (a: number, b: number, c: any) => [number, number];
386
+ readonly wasm_bindgen__convert__closures_____invoke__h72adce5fbcd58c92: (a: number, b: number, c: any, d: any) => void;
387
+ readonly wasm_bindgen__convert__closures_____invoke__h027ec0463d981e5e: (a: number, b: number) => number;
388
+ readonly wasm_bindgen__convert__closures_____invoke__h2f71c847222394ea: (a: number, b: number) => void;
389
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
390
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
391
+ readonly __wbindgen_exn_store: (a: number) => void;
392
+ readonly __externref_table_alloc: () => number;
393
+ readonly __wbindgen_externrefs: WebAssembly.Table;
394
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
395
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
396
+ readonly __externref_table_dealloc: (a: number) => void;
397
+ readonly __wbindgen_start: () => void;
309
398
  }
310
399
 
311
400
  export type SyncInitInput = BufferSource | WebAssembly.Module;
@@ -318,9 +407,7 @@ export type SyncInitInput = BufferSource | WebAssembly.Module;
318
407
  *
319
408
  * @returns {InitOutput}
320
409
  */
321
- export function initSync(
322
- module: { module: SyncInitInput } | SyncInitInput,
323
- ): InitOutput;
410
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
324
411
 
325
412
  /**
326
413
  * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
@@ -330,9 +417,4 @@ export function initSync(
330
417
  *
331
418
  * @returns {Promise<InitOutput>}
332
419
  */
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>;
420
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;