@pi-oxide/extension-js 0.2.0 → 0.2.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.
@@ -0,0 +1,44 @@
1
+ declare const __LOG_LEVELS: {
2
+ readonly debug: 0;
3
+ readonly info: 1;
4
+ readonly warn: 2;
5
+ readonly error: 3;
6
+ readonly none: 4;
7
+ };
8
+ declare let __logLevel: number;
9
+ declare function __formatMeta(meta: Record<string, unknown> | undefined): string;
10
+ declare function __log(level: number, event: string, meta?: Record<string, unknown>): void;
11
+ declare const logger: {
12
+ debug: (event: string, meta?: Record<string, unknown>) => void;
13
+ info: (event: string, meta?: Record<string, unknown>) => void;
14
+ warn: (event: string, meta?: Record<string, unknown>) => void;
15
+ error: (event: string, meta?: Record<string, unknown>) => void;
16
+ };
17
+ declare function getElementByRefId(refId: string | number): Element | null;
18
+ declare function findElementByLabel(query: string): Element | null;
19
+ declare function findCandidateLabels(query: string): string[];
20
+ declare function asRecord(obj: unknown): Record<string, unknown>;
21
+ declare function getStringParam(params: unknown, key: string): string;
22
+ declare function getNumberParam(params: unknown, key: string, fallback: number): number;
23
+ declare function getAccessibleRole(el: Element): string;
24
+ declare function getAccessibleName(el: Element): string;
25
+ declare function shouldInclude(el: Element): boolean;
26
+ interface SnapshotNode {
27
+ refId: number;
28
+ role: string;
29
+ tag: string;
30
+ name?: string;
31
+ }
32
+ interface SnapshotResult {
33
+ text: string;
34
+ nodes: SnapshotNode[];
35
+ url: string;
36
+ title: string;
37
+ viewport: {
38
+ width: number;
39
+ height: number;
40
+ };
41
+ }
42
+ declare function inlineSnapshot(maxNodes: number): SnapshotResult;
43
+ type Handler<T = unknown, R = unknown> = (params: T) => R | Promise<R>;
44
+ declare const handlers: Record<string, Handler>;
@@ -0,0 +1,55 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_extensionsession_free: (a: number, b: number) => void;
5
+ export const extensionsession_inspect_globals: (a: number) => any;
6
+ export const extensionsession_load_library: (
7
+ a: number,
8
+ b: number,
9
+ c: number,
10
+ ) => any;
11
+ export const extensionsession_new: () => number;
12
+ export const extensionsession_reset: (a: number) => void;
13
+ export const extensionsession_runCellAsync: (
14
+ a: number,
15
+ b: number,
16
+ c: number,
17
+ d: number,
18
+ e: number,
19
+ ) => any;
20
+ export const extensionsession_set_fuel_limit: (a: number, b: number) => void;
21
+ export const extensionsession_stopWith: (a: number) => void;
22
+ export const setLogLevel: (a: number) => void;
23
+ export const generateApiDocs: (a: number, b: number) => [number, number];
24
+ export const collect_document: (a: any) => any;
25
+ export const collect_element: (a: any, b: any) => any;
26
+ export const format_snapshot_js: (a: any, b: number) => [number, number];
27
+ export const wasm_bindgen__convert__closures_____invoke__hbaf3bd60d2f803db: (
28
+ a: number,
29
+ b: number,
30
+ c: any,
31
+ ) => [number, number];
32
+ export const wasm_bindgen__convert__closures_____invoke__hf458ead16698aa30: (
33
+ a: number,
34
+ b: number,
35
+ c: any,
36
+ d: any,
37
+ ) => void;
38
+ export const wasm_bindgen__convert__closures_____invoke__hd488ef5680429ef6: (
39
+ a: number,
40
+ b: number,
41
+ ) => number;
42
+ export const __wbindgen_malloc: (a: number, b: number) => number;
43
+ export const __wbindgen_realloc: (
44
+ a: number,
45
+ b: number,
46
+ c: number,
47
+ d: number,
48
+ ) => number;
49
+ export const __wbindgen_exn_store: (a: number) => void;
50
+ export const __externref_table_alloc: () => number;
51
+ export const __wbindgen_externrefs: WebAssembly.Table;
52
+ export const __wbindgen_destroy_closure: (a: number, b: number) => void;
53
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
54
+ export const __externref_table_dealloc: (a: number) => void;
55
+ export const __wbindgen_start: () => void;
package/generated.d.ts ADDED
@@ -0,0 +1,208 @@
1
+ import { TreeSnapshot } from '@pi-oxide/dom-semantic-tree';
2
+
3
+ export type CommandParams = FetchParams | SleepParams | PageClickParams | PageDblClickParams | PageFillParams | PageTypeParams | PagePressParams | PageSelectParams | PageCheckParams | PageHoverParams | PageScrollParams | PageScrollToParams | PageGotoParams | PageFindParams | PageWaitForParams | PageExtractParams | PageAppendParams | PageWaitParams | StorageGetParams | StorageSetParams | StorageDeleteParams | DomSnapshotParams | DomFormatParams | TabClickParams | TabFillParams | TabEvaluateParams | TabBackParams | TabWaitForLoadParams | TabScrollToParams | TabTypeParams | TabPressParams | TabSelectParams | TabCheckParams | TabHoverParams | TabUnhoverParams | TabScrollParams | TabDblClickParams | FsWriteParams | FsPathParams | FsCopyParams | FsUpdateParams | FsHashParams | FsReadRangeParams;
4
+ export type AsyncCommand = {
5
+ call_id: number;
6
+ action: string;
7
+ params: CommandParams;
8
+ };
9
+ export type CellError = {
10
+ kind: "compile";
11
+ message: string;
12
+ line: number | null;
13
+ } | {
14
+ kind: "runtime";
15
+ message: string;
16
+ line: number | null;
17
+ } | {
18
+ kind: "fuel_exhausted";
19
+ } | {
20
+ kind: "internal";
21
+ message: string;
22
+ };
23
+ export type CellStatus = "done" | "async_pending";
24
+ export type DomSnapshotParams = {
25
+ interactive_only: boolean;
26
+ max_nodes: bigint;
27
+ };
28
+ export type DomFormatParams = {
29
+ snapshot: TreeSnapshot;
30
+ format?: string;
31
+ };
32
+ export type FetchParams = {
33
+ url: string;
34
+ method: string;
35
+ headers: Record<string, string>;
36
+ body: string | null;
37
+ timeout: bigint;
38
+ };
39
+ export type FsCopyParams = {
40
+ from: string;
41
+ to: string;
42
+ };
43
+ export type FsHashParams = {
44
+ path: string;
45
+ algo: string;
46
+ };
47
+ export type FsPathParams = {
48
+ path: string;
49
+ };
50
+ export type FsReadRangeParams = {
51
+ path: string;
52
+ offset: bigint;
53
+ len: number;
54
+ };
55
+ export type FsUpdateParams = {
56
+ path: string;
57
+ offset: bigint;
58
+ data: string;
59
+ };
60
+ export type FsWriteParams = {
61
+ path: string;
62
+ data: string;
63
+ };
64
+ export type PageAppendParams = {
65
+ refId: string;
66
+ label: string;
67
+ text: string;
68
+ };
69
+ export type PageCheckParams = {
70
+ refId: string;
71
+ checked: boolean;
72
+ };
73
+ export type PageClickParams = {
74
+ refId: string;
75
+ label: string;
76
+ };
77
+ export type PageDblClickParams = {
78
+ refId: string;
79
+ label: string;
80
+ };
81
+ export type PageExtractParams = {
82
+ fields: string[];
83
+ };
84
+ export type PageFillParams = {
85
+ refId: string;
86
+ label: string;
87
+ value: string;
88
+ };
89
+ export type PageFindParams = {
90
+ selector: string;
91
+ };
92
+ export type PageGotoParams = {
93
+ url: string;
94
+ };
95
+ export type PageHoverParams = {
96
+ refId: string;
97
+ };
98
+ export type PagePressParams = {
99
+ key: string;
100
+ };
101
+ export type PageScrollParams = {
102
+ direction: string;
103
+ amount: number;
104
+ };
105
+ export type PageScrollToParams = {
106
+ refId: string;
107
+ };
108
+ export type PageSelectParams = {
109
+ refId: string;
110
+ value: string;
111
+ };
112
+ export type PageTypeParams = {
113
+ refId: string;
114
+ label: string;
115
+ text: string;
116
+ };
117
+ export type PageWaitForParams = {
118
+ selector: string;
119
+ timeout: bigint;
120
+ };
121
+ export type PageWaitParams = {
122
+ duration: bigint;
123
+ };
124
+ export type RunResult = {
125
+ stdout: string[];
126
+ stderr: string[];
127
+ result: string | null;
128
+ error: CellError | null;
129
+ commands: CommandParams[];
130
+ fuel_exhausted: boolean;
131
+ execution_count: number;
132
+ status: CellStatus;
133
+ pending_commands: AsyncCommand[];
134
+ };
135
+ export type SleepParams = {
136
+ duration: bigint;
137
+ };
138
+ export type StorageDeleteParams = {
139
+ key: string;
140
+ };
141
+ export type StorageGetParams = {
142
+ key: string;
143
+ };
144
+ export type StorageSetParams = {
145
+ key: string;
146
+ value: string;
147
+ };
148
+ export type TabBackParams = {
149
+ tabId: bigint;
150
+ };
151
+ export type TabCheckParams = {
152
+ tabId: bigint;
153
+ refId: string;
154
+ checked: boolean;
155
+ };
156
+ export type TabClickParams = {
157
+ tabId: bigint;
158
+ refId: string;
159
+ };
160
+ export type TabDblClickParams = {
161
+ tabId: bigint;
162
+ refId: string;
163
+ };
164
+ export type TabEvaluateParams = {
165
+ tabId: bigint;
166
+ script: string;
167
+ };
168
+ export type TabFillParams = {
169
+ tabId: bigint;
170
+ refId: string;
171
+ value: string;
172
+ };
173
+ export type TabHoverParams = {
174
+ tabId: bigint;
175
+ refId: string;
176
+ };
177
+ export type TabPressParams = {
178
+ tabId: bigint;
179
+ key: string;
180
+ };
181
+ export type TabScrollParams = {
182
+ tabId: bigint;
183
+ direction: string;
184
+ amount: number;
185
+ };
186
+ export type TabScrollToParams = {
187
+ tabId: bigint;
188
+ x: number;
189
+ y: number;
190
+ refId: string | null;
191
+ };
192
+ export type TabSelectParams = {
193
+ tabId: bigint;
194
+ refId: string;
195
+ value: string;
196
+ };
197
+ export type TabTypeParams = {
198
+ tabId: bigint;
199
+ refId: string;
200
+ text: string;
201
+ };
202
+ export type TabUnhoverParams = {
203
+ tabId: bigint;
204
+ };
205
+ export type TabWaitForLoadParams = {
206
+ tabId: bigint;
207
+ timeout: bigint;
208
+ };
package/index.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ import { CellResult, FsCopyParams, FsHashParams, FsPathParams, FsReadRangeDataParams, FsReadRangeParams, FsWriteParams, WasmGlobalsSnapshot } from './extension_js.js';
2
+ import { registerHostHandler, registerHostHandlers } from './runner.js';
3
+
4
+ export { generateApiDocs } from './extension_js.js';
5
+ export type { LogLevel } from './logger.js';
6
+ export { setLogLevel } from './logger.js';
7
+ export type { CellResult as JsRunResult, WasmGlobalsSnapshot as JsGlobalsSnapshot, };
8
+ export { registerHostHandler, registerHostHandlers };
9
+ export interface JsApiDoc {
10
+ namespace: string;
11
+ name: string;
12
+ action: string | null;
13
+ description: string;
14
+ params: {
15
+ name: string;
16
+ js_type: string;
17
+ required: boolean;
18
+ description: string;
19
+ }[];
20
+ returns: {
21
+ js_type: string;
22
+ description: string;
23
+ };
24
+ source: string;
25
+ }
26
+ /**
27
+ * ExtensionSession proxy that lives on the main thread.
28
+ * The actual WASM ExtensionSession runs inside a Web Worker;
29
+ * this proxy forwards calls via postMessage and awaits responses.
30
+ */
31
+ export declare class ExtensionSession {
32
+ private worker;
33
+ private pendingCalls;
34
+ private disposed;
35
+ private onCleanupComplete;
36
+ private abortController;
37
+ private constructor();
38
+ /**
39
+ * Initialize the extension-js runtime.
40
+ * Automatically detects extension context, spawns the Worker,
41
+ * starts the main-thread runner loop, and returns [session, runner].
42
+ *
43
+ * The spawned Worker uses `new Worker(..., { type: "module" })`. Your bundler
44
+ * must support emitting module Workers as separate chunks.
45
+ *
46
+ * AbortController is module-global: only one active session per extension
47
+ * page is fully safe. Concurrent sessions race on the same abort signal.
48
+ */
49
+ static init(): Promise<[ExtensionSession, Promise<void>]>;
50
+ private startWorker;
51
+ private handleWorkerMessage;
52
+ private postAndWait;
53
+ runCellAsync(code: string, stdin?: string): Promise<CellResult>;
54
+ reset(): Promise<void>;
55
+ inspectGlobals(): Promise<WasmGlobalsSnapshot>;
56
+ setFuelLimit(limit: number): void;
57
+ loadLibrary(source: string): Promise<CellResult>;
58
+ private safePost;
59
+ get fs(): {
60
+ exists: (params: FsPathParams) => Promise<import('./extension_js.js').FsExistsResult>;
61
+ stat: (params: FsPathParams) => Promise<import('./extension_js.js').FsStatResult>;
62
+ read: (params: FsPathParams) => Promise<import('./extension_js.js').FsStringResult>;
63
+ readText: (params: FsPathParams) => Promise<import('./extension_js.js').FsStringResult>;
64
+ readBase64: (params: FsPathParams) => Promise<import('./extension_js.js').FsStringResult>;
65
+ list: (params: FsPathParams) => Promise<import('./extension_js.js').FsListResult>;
66
+ mkdir: (params: FsPathParams) => Promise<import('./extension_js.js').FsBoolResult>;
67
+ delete: (params: FsPathParams) => Promise<import('./extension_js.js').FsBoolResult>;
68
+ copy: (params: FsCopyParams) => Promise<import('./extension_js.js').FsBoolResult>;
69
+ move: (params: FsCopyParams) => Promise<import('./extension_js.js').FsBoolResult>;
70
+ write: (params: FsWriteParams) => Promise<import('./extension_js.js').FsBoolResult>;
71
+ writeText: (params: FsWriteParams) => Promise<import('./extension_js.js').FsBoolResult>;
72
+ writeBase64: (params: FsWriteParams) => Promise<import('./extension_js.js').FsBoolResult>;
73
+ append: (params: FsWriteParams) => Promise<import('./extension_js.js').FsBoolResult>;
74
+ appendText: (params: FsWriteParams) => Promise<import('./extension_js.js').FsBoolResult>;
75
+ appendBase64: (params: FsWriteParams) => Promise<import('./extension_js.js').FsBoolResult>;
76
+ readRange: (params: FsReadRangeParams) => Promise<import('./extension_js.js').FsStringResult>;
77
+ update: (params: FsReadRangeDataParams) => Promise<import('./extension_js.js').FsBoolResult>;
78
+ hash: (params: FsHashParams) => Promise<import('./extension_js.js').FsHashResult>;
79
+ };
80
+ /**
81
+ * Clean up the session, terminate the Worker, and release resources.
82
+ * Accepts the runner Promise returned by init() so it can be awaited
83
+ * for graceful shutdown.
84
+ *
85
+ * Sends a reset message to the Worker, then waits only 50 ms before
86
+ * forcefully calling worker.terminate(). If WASM cleanup takes longer,
87
+ * the Worker is killed mid-operation. Pending async calls are rejected
88
+ * with "ExtensionSession stopped".
89
+ */
90
+ stopWith(runner: Promise<void>): Promise<void>;
91
+ private generateId;
92
+ }