@pi-oxide/extension-js 0.12.3 → 0.13.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.
Files changed (145) hide show
  1. package/content-script/action-result.d.ts +4 -0
  2. package/content-script/dom-tree.d.ts +28 -0
  3. package/content-script/dom-utils.d.ts +37 -0
  4. package/content-script/file-resolution.d.ts +22 -0
  5. package/content-script/form-validation.d.ts +12 -0
  6. package/content-script/handlers.d.ts +3 -0
  7. package/content-script/index.d.ts +6 -0
  8. package/content-script/listbox.d.ts +7 -0
  9. package/content-script/logger.d.ts +12 -0
  10. package/content-script/message-router.d.ts +1 -0
  11. package/content-script/observation-lease.d.ts +55 -0
  12. package/content-script/registry.d.ts +24 -0
  13. package/content-script/schemas.d.ts +5 -0
  14. package/content-script/snapshot.d.ts +3 -0
  15. package/content-script.js +3 -3
  16. package/extension_js.d.ts +11 -3
  17. package/extension_js.js +25949 -16750
  18. package/index.js +2242 -1773
  19. package/main/index.d.ts +8 -0
  20. package/main/runner/chrome/internals.d.ts +9 -0
  21. package/main/runner/chrome/native.d.ts +6 -0
  22. package/main/runner/command.d.ts +3 -0
  23. package/main/runner/dom/snapshot.d.ts +8 -0
  24. package/main/runner/fetch.d.ts +4 -0
  25. package/main/runner/host.d.ts +3 -0
  26. package/main/runner/index.d.ts +2 -0
  27. package/main/runner/lib/constants.d.ts +14 -0
  28. package/main/runner/lib/host-registry.d.ts +6 -0
  29. package/main/runner/lib/network-tracker.d.ts +16 -0
  30. package/main/runner/lib/params-helpers.d.ts +2 -0
  31. package/main/runner/lib/params.d.ts +5 -0
  32. package/main/runner/lib/types.d.ts +116 -0
  33. package/main/runner/runtime.d.ts +15 -0
  34. package/main/runner/sidepanel/dom.d.ts +6 -0
  35. package/main/runner/snapshot-merge.d.ts +8 -0
  36. package/main/runner/tab/execute.d.ts +24 -0
  37. package/main/runner/tools/aliases.d.ts +1 -0
  38. package/main/runner/tools/chrome/action.d.ts +1 -0
  39. package/main/runner/tools/chrome/alarms.d.ts +1 -0
  40. package/main/runner/tools/chrome/bookmarks.d.ts +1 -0
  41. package/main/runner/tools/chrome/browsing-data.d.ts +1 -0
  42. package/main/runner/tools/chrome/capability.d.ts +30 -0
  43. package/main/runner/tools/chrome/context-menus.d.ts +1 -0
  44. package/main/runner/tools/chrome/cookies.d.ts +1 -0
  45. package/main/runner/tools/chrome/declarative-net-request.d.ts +1 -0
  46. package/main/runner/tools/chrome/desktop-capture.d.ts +1 -0
  47. package/main/runner/tools/chrome/downloads.d.ts +1 -0
  48. package/main/runner/tools/chrome/history.d.ts +1 -0
  49. package/main/runner/tools/chrome/identity.d.ts +1 -0
  50. package/main/runner/tools/chrome/idle.d.ts +1 -0
  51. package/main/runner/tools/chrome/index.d.ts +1 -0
  52. package/main/runner/tools/chrome/management.d.ts +1 -0
  53. package/main/runner/tools/chrome/notifications.d.ts +1 -0
  54. package/main/runner/tools/chrome/offscreen.d.ts +1 -0
  55. package/main/runner/tools/chrome/page-capture.d.ts +1 -0
  56. package/main/runner/tools/chrome/permissions.d.ts +1 -0
  57. package/main/runner/tools/chrome/register-helpers.d.ts +9 -0
  58. package/main/runner/tools/chrome/runtime.d.ts +1 -0
  59. package/main/runner/tools/chrome/scripting.d.ts +1 -0
  60. package/main/runner/tools/chrome/sessions.d.ts +1 -0
  61. package/main/runner/tools/chrome/side-panel.d.ts +1 -0
  62. package/main/runner/tools/chrome/system.d.ts +1 -0
  63. package/main/runner/tools/chrome/tab-groups.d.ts +1 -0
  64. package/main/runner/tools/chrome/tabs.d.ts +1 -0
  65. package/main/runner/tools/chrome/top-sites.d.ts +1 -0
  66. package/main/runner/tools/chrome/windows.d.ts +1 -0
  67. package/main/runner/tools/chrome-storage.d.ts +1 -0
  68. package/main/runner/tools/clipboard.d.ts +1 -0
  69. package/main/runner/tools/dom.d.ts +1 -0
  70. package/main/runner/tools/host-call.d.ts +1 -0
  71. package/main/runner/tools/network.d.ts +1 -0
  72. package/main/runner/tools/page.d.ts +1 -0
  73. package/main/runner/tools/sidepanel.d.ts +1 -0
  74. package/main/runner/tools/storage.d.ts +1 -0
  75. package/main/runner/tools/tab.d.ts +1 -0
  76. package/main/session/extension-session.d.ts +106 -0
  77. package/main/tab-context.d.ts +12 -0
  78. package/package.json +5 -2
  79. package/shared/array-buffer.d.ts +4 -0
  80. package/shared/collect-inline-snapshot.d.ts +50 -0
  81. package/shared/cross/agent-errors.d.ts +28 -0
  82. package/shared/cross/array-buffer.d.ts +4 -0
  83. package/shared/cross/collect-inline-snapshot.d.ts +58 -0
  84. package/shared/cross/content-script-actions.d.ts +7 -0
  85. package/shared/cross/content-script-tools.d.ts +3 -0
  86. package/shared/cross/dispatch.d.ts +5 -0
  87. package/shared/cross/fetch-response.d.ts +12 -0
  88. package/shared/cross/format-types.d.ts +43 -0
  89. package/shared/cross/fs-types.d.ts +81 -0
  90. package/shared/cross/generated.d.ts +328 -0
  91. package/shared/cross/manifest.d.ts +130 -0
  92. package/shared/cross/normalize-agent-error.d.ts +17 -0
  93. package/shared/cross/page-specs.d.ts +7 -0
  94. package/shared/cross/schemas/chrome.d.ts +56 -0
  95. package/shared/cross/schemas/clipboard.d.ts +19 -0
  96. package/shared/cross/schemas/fs.d.ts +65 -0
  97. package/shared/cross/schemas/helpers.d.ts +71 -0
  98. package/shared/cross/schemas/host.d.ts +15 -0
  99. package/shared/cross/schemas/network.d.ts +34 -0
  100. package/shared/cross/schemas/page.d.ts +494 -0
  101. package/shared/cross/schemas/returns.d.ts +8791 -0
  102. package/shared/cross/schemas/sidepanel.d.ts +284 -0
  103. package/shared/cross/schemas/snapshot.d.ts +272 -0
  104. package/shared/cross/schemas/storage.d.ts +60 -0
  105. package/shared/cross/schemas/tab.d.ts +597 -0
  106. package/shared/cross/schemas.d.ts +12 -0
  107. package/shared/cross/snapshot-filter.d.ts +15 -0
  108. package/shared/cross/tab-specs.d.ts +3 -0
  109. package/shared/cross/types.d.ts +12 -0
  110. package/shared/cross/zod-to-docs.d.ts +28 -0
  111. package/shared/cs/ref-id.d.ts +5 -0
  112. package/shared/cs/snapshot-dom.d.ts +47 -0
  113. package/shared/fetch-response.d.ts +12 -0
  114. package/shared/fs-types.d.ts +81 -0
  115. package/shared/generated.d.ts +241 -0
  116. package/shared/log-levels.d.ts +5 -0
  117. package/shared/logger.d.ts +18 -0
  118. package/shared/main/content-script-response.d.ts +5 -0
  119. package/shared/main/define-content-script-tool.d.ts +7 -0
  120. package/shared/main/log-levels.d.ts +5 -0
  121. package/shared/main/logger.d.ts +18 -0
  122. package/shared/main/routes.d.ts +14 -0
  123. package/shared/main/tool-registry.d.ts +19 -0
  124. package/shared/ref-id.d.ts +5 -0
  125. package/shared/registry/agent-errors.d.ts +27 -0
  126. package/shared/registry/content-script-actions.d.ts +7 -0
  127. package/shared/registry/content-script-response.d.ts +5 -0
  128. package/shared/registry/content-script-tools.d.ts +13 -0
  129. package/shared/registry/define-content-script-tool.d.ts +7 -0
  130. package/shared/registry/dispatch.d.ts +5 -0
  131. package/shared/registry/manifest.d.ts +130 -0
  132. package/shared/registry/normalize-agent-error.d.ts +17 -0
  133. package/shared/registry/routes.d.ts +14 -0
  134. package/shared/registry/types.d.ts +12 -0
  135. package/shared/registry/zod-to-docs.d.ts +28 -0
  136. package/shared/schemas.d.ts +10663 -0
  137. package/shared/snapshot-dom.d.ts +47 -0
  138. package/shared/snapshot-filter.d.ts +15 -0
  139. package/shared/tool-registry.d.ts +19 -0
  140. package/worker/binary-blob-store.d.ts +12 -0
  141. package/worker/fetch-store.d.ts +1 -0
  142. package/worker/resolve-set-files.d.ts +22 -0
  143. package/worker/vfs-write-cache.d.ts +3 -0
  144. package/worker/worker.d.ts +84 -0
  145. package/worker.js +1852 -1695
@@ -0,0 +1,8 @@
1
+ import { ExtensionSession } from './session/extension-session.js';
2
+ export type { CellResult as JsRunResult, WasmGlobalsSnapshot as JsGlobalsSnapshot, } from '../../pkg/extension_js.js';
3
+ export type { LogLevel } from '../shared/main/logger.js';
4
+ export { LOG_LEVEL_NUMERIC, setLogLevel } from '../shared/main/logger.js';
5
+ export { registerHostHandler, registerHostHandlers, } from './runner/index.js';
6
+ export { ExtensionSession } from './session/extension-session.js';
7
+ /** Register a MessagePort for routing registry calls to an auxiliary worker context. */
8
+ export declare function registerWorkerRelayPort(session: ExtensionSession, owner: string, port: MessagePort): void;
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ import { AsyncError, ToolDocParam } from '../../../shared/main/tool-registry.js';
3
+
4
+ export { invokeNative, isNativeParityAction, type NativeArgs, normalizeParityArgs, requireArgumentArray, resolveChromeMethod, } from './native.js';
5
+ export declare function normalizeChromeError(err: unknown): {
6
+ ok: false;
7
+ error: AsyncError;
8
+ };
9
+ export declare function registerChromePassthrough(action: string, _namespace: string, description: string, apiPath: string[], returnsSchema: z.ZodSchema<unknown>, errorCode: string, errorCategory: string | undefined, paramTypes?: ToolDocParam[], example?: string, returnType?: string): void;
@@ -0,0 +1,6 @@
1
+ export type NativeArgs = readonly unknown[];
2
+ export declare function isNativeParityAction(action: string): boolean;
3
+ export declare function invokeNative(method: (...args: unknown[]) => unknown, args: NativeArgs): unknown;
4
+ export declare function normalizeParityArgs(action: string, args: NativeArgs): NativeArgs;
5
+ export declare function requireArgumentArray(value: unknown, action: string): NativeArgs;
6
+ export declare function resolveChromeMethod(chromeRoot: unknown, apiPath: string[], methodName: string): (...args: unknown[]) => unknown;
@@ -0,0 +1,3 @@
1
+ import { AsyncResponse, Command } from '../../shared/main/tool-registry.js';
2
+
3
+ export declare function executeMainThreadCommand(command: Command, relaySignal?: AbortSignal): Promise<AsyncResponse>;
@@ -0,0 +1,8 @@
1
+ import { AsyncResponse } from '../../../shared/main/tool-registry.js';
2
+ import { DomFormatParams, DomSnapshotParams, DomSnapshotValue } from '../lib/types.js';
3
+
4
+ export declare function ensureDomSnapshot(): Promise<void>;
5
+ export declare function handleDomSnapshot(params: DomSnapshotParams): Promise<AsyncResponse<DomSnapshotValue>>;
6
+ export declare function handleDomFormat(params: DomFormatParams): Promise<AsyncResponse<string>>;
7
+ /** Local/test entry — production snapshots use the content-script path. */
8
+ export declare function buildSnapshotInTab(maxNodesArg: unknown): import('../../../shared/cross/collect-inline-snapshot.js').InlineSnapshotResult;
@@ -0,0 +1,4 @@
1
+ import { AsyncResponse } from '../../shared/main/tool-registry.js';
2
+ import { FetchParams, FetchValue } from './lib/types.js';
3
+
4
+ export declare function handleFetch(params: FetchParams): Promise<AsyncResponse<FetchValue>>;
@@ -0,0 +1,3 @@
1
+ import { AsyncResponse } from '../../shared/main/tool-registry.js';
2
+
3
+ export declare function handleHostCallAction(action: string, params: unknown): Promise<AsyncResponse>;
@@ -0,0 +1,2 @@
1
+ export { type Command, setRunnerAbortController, } from '../../shared/main/tool-registry.js';
2
+ export { executeMainThreadCommand, getActiveTabId, initExtensionListeners, isValidMainThreadAction, normalizeParams, registerHostHandler, registerHostHandlers, removeExtensionListeners, } from './runtime.js';
@@ -0,0 +1,14 @@
1
+ export declare const DEFAULT_MAX_NODES = 500;
2
+ export declare const DEFAULT_TIMEOUT_MS = 30000;
3
+ export declare const DEFAULT_SCROLL_AMOUNT = 300;
4
+ export declare const DEFAULT_POLL_INTERVAL_MS = 100;
5
+ export declare const RETRY_DELAY_MS = 500;
6
+ export declare const INJECTION_DELAY_MS = 300;
7
+ /** Brief pause after tabs.update so status can transition to loading. */
8
+ export declare const NAVIGATION_SETTLE_MS = 100;
9
+ /** Grace period after content-script ping before returning from page.goto. */
10
+ export declare const CONTENT_SCRIPT_GRACE_MS = 500;
11
+ /** Fast fail-fast ping before content-script mutations (health, relay). */
12
+ export declare const CS_FAST_PING_MS = 500;
13
+ /** Quiet period with no in-flight requests before declaring network idle. */
14
+ export declare const NETWORK_IDLE_QUIET_MS = 500;
@@ -0,0 +1,6 @@
1
+ import { HostHandler } from './types.js';
2
+
3
+ export declare const hostHandlers: Record<string, HostHandler>;
4
+ export declare function registerHostHandler<T, R>(action: string, handler: (params: T) => Promise<R>): void;
5
+ export declare function registerHostHandlers(handlers: Record<string, HostHandler>): void;
6
+ export declare function isValidMainThreadAction(action: string): boolean;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Tracks in-flight network requests for a specific tab using chrome.webRequest.
3
+ * Observe-only (MV3 compatible) — no request blocking or modification.
4
+ */
5
+ export declare class NetworkTracker {
6
+ private readonly tabId;
7
+ private inFlight;
8
+ private onBeforeRequest;
9
+ private onCompleted;
10
+ private onErrorOccurred;
11
+ constructor(tabId: number);
12
+ start(): void;
13
+ get pendingCount(): number;
14
+ waitForIdle(timeoutMs: number, traceId?: string): Promise<void>;
15
+ dispose(): void;
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare function asRecord(params: unknown): Record<string, unknown>;
2
+ export declare function extractTabId(params: unknown): number | null;
@@ -0,0 +1,5 @@
1
+ import { AsyncResponse } from '../../../shared/main/tool-registry.js';
2
+
3
+ export { asRecord, extractTabId } from './params-helpers.js';
4
+ export declare function normalizeParams(action: string, params: unknown): unknown;
5
+ export declare function unwrapResult<T>(result: AsyncResponse<T>): T;
@@ -0,0 +1,116 @@
1
+ import { DomFormatParams, DomSnapshotParams, FetchParams, TreeSnapshot } from '../../../shared/cross/generated.js';
2
+
3
+ export type { DomFormatParams, DomSnapshotParams, FetchParams };
4
+ declare global {
5
+ interface Window {
6
+ __hostHandlers?: Record<string, HostHandler>;
7
+ }
8
+ }
9
+ export type HostHandler<T = unknown, R = unknown> = (params: T) => Promise<R>;
10
+ export type FetchValue = {
11
+ status: number;
12
+ ok: boolean;
13
+ headers: Record<string, string>;
14
+ body: string;
15
+ bodyEncoding: "text" | "base64";
16
+ byteLength: number;
17
+ contentType: string;
18
+ finalUrl: string;
19
+ };
20
+ export type DomSnapshotValue = {
21
+ data: TreeSnapshot;
22
+ text: string;
23
+ };
24
+ export type TabMessage = {
25
+ action: "click";
26
+ params: {
27
+ refId?: string;
28
+ label?: string;
29
+ };
30
+ } | {
31
+ action: "fill";
32
+ params: {
33
+ refId?: string;
34
+ value: string;
35
+ label?: string;
36
+ };
37
+ } | {
38
+ action: "type";
39
+ params: {
40
+ refId?: string;
41
+ text: string;
42
+ label?: string;
43
+ };
44
+ } | {
45
+ action: "append";
46
+ params: {
47
+ refId?: string;
48
+ text: string;
49
+ label?: string;
50
+ };
51
+ } | {
52
+ action: "press";
53
+ params: {
54
+ key: string;
55
+ };
56
+ } | {
57
+ action: "select";
58
+ params: {
59
+ refId: string;
60
+ value: string;
61
+ };
62
+ } | {
63
+ action: "check";
64
+ params: {
65
+ refId: string;
66
+ checked: boolean;
67
+ };
68
+ } | {
69
+ action: "hover";
70
+ params: {
71
+ refId: string;
72
+ };
73
+ } | {
74
+ action: "unhover";
75
+ params: Record<string, never>;
76
+ } | {
77
+ action: "scroll";
78
+ params: {
79
+ direction: string;
80
+ amount: number;
81
+ };
82
+ } | {
83
+ action: "scrollTo";
84
+ params: {
85
+ x: number;
86
+ y: number;
87
+ refId?: string;
88
+ };
89
+ } | {
90
+ action: "dblclick";
91
+ params: {
92
+ refId: string;
93
+ };
94
+ } | {
95
+ action: "back";
96
+ params: Record<string, never>;
97
+ } | {
98
+ action: "ping";
99
+ params?: Record<string, never>;
100
+ };
101
+ type CodedError = Error & {
102
+ code: string;
103
+ category?: string;
104
+ hint?: string;
105
+ recovery?: string[];
106
+ details?: Record<string, unknown>;
107
+ };
108
+ export declare function makeError(message: string, code: string, category?: string, extra?: Pick<CodedError, "hint" | "recovery" | "details">): CodedError;
109
+ export declare function throwAgentError(error: {
110
+ message: string;
111
+ code: string;
112
+ category?: string;
113
+ hint?: string;
114
+ recovery?: string[];
115
+ details?: Record<string, unknown>;
116
+ }): never;
@@ -0,0 +1,15 @@
1
+ export { type Command, setRunnerAbortController, throwIfAborted, } from '../../shared/main/tool-registry.js';
2
+ export { getActiveTabId, initExtensionListeners, removeExtensionListeners, resolveActiveTabId, } from '../tab-context.js';
3
+ export { registerChromePassthrough } from './chrome/internals.js';
4
+ export { invokeNative, isNativeParityAction, type NativeArgs, requireArgumentArray, resolveChromeMethod, } from './chrome/native.js';
5
+ export { executeMainThreadCommand } from './command.js';
6
+ export { buildSnapshotInTab, ensureDomSnapshot, handleDomFormat, handleDomSnapshot, } from './dom/snapshot.js';
7
+ export { handleFetch } from './fetch.js';
8
+ export { handleHostCallAction } from './host.js';
9
+ export { CONTENT_SCRIPT_GRACE_MS, CS_FAST_PING_MS, DEFAULT_MAX_NODES, DEFAULT_POLL_INTERVAL_MS, DEFAULT_SCROLL_AMOUNT, DEFAULT_TIMEOUT_MS, NAVIGATION_SETTLE_MS, NETWORK_IDLE_QUIET_MS, } from './lib/constants.js';
10
+ export { isValidMainThreadAction, registerHostHandler, registerHostHandlers, } from './lib/host-registry.js';
11
+ export { asRecord, extractTabId, normalizeParams, unwrapResult, } from './lib/params.js';
12
+ export type { DomFormatParams, DomSnapshotParams, FetchParams, } from './lib/types.js';
13
+ export { makeError, throwAgentError } from './lib/types.js';
14
+ export { extractRefId, getElementByRefId } from './sidepanel/dom.js';
15
+ export { pingTabContentScript, preflightDomTab, waitForTabLoad, } from './tab/execute.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Find an element by its opaque reference ID.
3
+ * @param refId — opaque element ref in 'e{N}' format (e.g. 'e2'). Must match schema regex ^e\d+$.
4
+ */
5
+ export declare function getElementByRefId(refId: string): Element | null;
6
+ export declare function extractRefId(params: unknown): string | undefined;
@@ -0,0 +1,8 @@
1
+ import { Command } from '../../shared/cross/manifest.js';
2
+
3
+ export declare function isSnapshotAction(action: string): boolean;
4
+ /**
5
+ * Collect snapshots from every http(s) frame in the tab, merge them,
6
+ * and return the unified result. Pipeline: enumerate → collect → merge.
7
+ */
8
+ export declare function executeMultiFrameSnapshot(cmd: Command, tabId: number, relayId?: string): Promise<unknown>;
@@ -0,0 +1,24 @@
1
+ import { AsyncResponse } from '../../../shared/main/tool-registry.js';
2
+
3
+ /** Fail fast when a tab URL cannot host content-script DOM APIs (non-http(s)). */
4
+ export declare function preflightDomTab(tabId: number): Promise<AsyncResponse | null>;
5
+ export declare function pingTabContentScript(tabId: number, timeoutMs?: number): Promise<AsyncResponse<{
6
+ ok: true;
7
+ }>>;
8
+ export type WaitForTabLoadOptions = {
9
+ /** Tab URL before navigation; used to detect blocked navigations, not for redirect matching. */
10
+ preNavigationUrl?: string;
11
+ /** When set, returns whether a loading event was observed before waitForTabLoad (e.g. listener registered pre-update). */
12
+ getNavSawLoading?: () => boolean;
13
+ /** trace-id for logging correlation with the originating run_js cell. */
14
+ runId?: string;
15
+ /**
16
+ * Grace window (ms) for heavy SPAs whose `load` event never fires. Once the
17
+ * tab has provably navigated (URL moved away from preNavigationUrl) but
18
+ * `complete` hasn't arrived, settle as loaded after this delay instead of
19
+ * waiting out the full timeout. Default 5000. Ignored when preNavigationUrl
20
+ * is unknown (can't prove navigation).
21
+ */
22
+ loadGraceMs?: number;
23
+ };
24
+ export declare function waitForTabLoad(tabId: number | null, timeoutMs?: number, options?: WaitForTabLoadOptions): Promise<AsyncResponse<boolean>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Initialize capability cache by reading chrome.permissions.getAll().
3
+ * Call once at extension startup.
4
+ */
5
+ export declare function initCapabilities(): Promise<void>;
6
+ /** Re-read chrome.permissions.getAll() and update the cache. */
7
+ export declare function refreshCapabilities(): Promise<void>;
8
+ /** Reset the capability cache to null (test helper). */
9
+ export declare function resetCapabilities(): void;
10
+ /**
11
+ * Manifest permission for a chrome API path, or null when no manifest permission is required.
12
+ */
13
+ export declare function manifestPermissionForApiPath(apiPath: string[]): string | null;
14
+ /**
15
+ * @deprecated Use manifestPermissionForApiPath
16
+ */
17
+ export declare function permissionFromApiPath(apiPath: string[]): string | null;
18
+ /**
19
+ * Manifest permission for a chrome_* action target.
20
+ * e.g. "chrome_notifications_create" → "notifications"
21
+ */
22
+ export declare function permissionFromChromeAction(action: string): string | null;
23
+ /**
24
+ * Whether a manifest permission is currently granted.
25
+ * - null permission → always true (namespace-only APIs)
26
+ * - non-null → cache-only; false when cache missing or permission absent
27
+ */
28
+ export declare function hasPermission(permission: string | null): boolean;
29
+ /** Throw E_PERMISSION if the manifest permission is required but not granted. */
30
+ export declare function checkPermission(apiName: string, permission: string | null): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+
3
+ export declare const zChromeAny: z.ZodUnknown;
4
+ /** Chrome void APIs often resolve to undefined, null, or boolean (not strictly null). */
5
+ export declare const zChromeVoid: z.ZodUnion<[z.ZodNull, z.ZodUndefined, z.ZodBoolean]>;
6
+ /** @deprecated Use zChromeVoid */
7
+ export declare const zChromeNull: z.ZodUnion<[z.ZodNull, z.ZodUndefined, z.ZodBoolean]>;
8
+ /** Register a chrome.* passthrough from action name and API path segments. */
9
+ export declare function regChrome(action: string, apiPath: string[], description: string, returnsSchema?: z.ZodSchema<unknown>, example?: string, returnType?: string): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,106 @@
1
+ import { CellResult, FsCopyParams, FsHashParams, FsPathParams, FsReadRangeDataParams, FsReadRangeParams, FsWriteParams, WasmGlobalsSnapshot } from '../../../pkg/extension_js.js';
2
+ import { InlineSnapshotResult } from '../../shared/cross/collect-inline-snapshot.js';
3
+ import { SnapshotFilter } from '../../shared/cross/snapshot-filter.js';
4
+ import { LogLevel } from '../../shared/main/logger.js';
5
+
6
+ export declare class ExtensionSession {
7
+ private worker;
8
+ private pendingCalls;
9
+ private inFlightRelays;
10
+ private disposed;
11
+ private onCleanupComplete;
12
+ private abortController;
13
+ private runQueue;
14
+ private constructor();
15
+ /**
16
+ * Initialize the extension-js runtime.
17
+ * Automatically detects extension context, spawns the Worker,
18
+ * starts the main-thread runner loop, and returns [session, runner].
19
+ *
20
+ * The spawned Worker uses `new Worker(..., { type: "module" })`. Your bundler
21
+ * must support emitting module Workers as separate chunks.
22
+ *
23
+ * AbortController is module-global: only one active session per extension
24
+ * page is fully safe. Concurrent sessions race on the same abort signal.
25
+ */
26
+ static init(): Promise<[ExtensionSession, Promise<void>]>;
27
+ private startWorker;
28
+ private handleWorkerMessage;
29
+ private executeContextCommand;
30
+ /**
31
+ * Race a main-thread command against a hard timeout. If the handler hangs
32
+ * (e.g. waitForTabLoad on a page that never reaches `complete`, or a content
33
+ * script that never reconnects), this converts the hang into a structured
34
+ * E_TIMEOUT error that the relay posts back to the worker — instead of
35
+ * leaving the cell's join_all awaiting forever.
36
+ */
37
+ private withMainThreadTimeout;
38
+ registerWorkerRelayPort(owner: string, port: MessagePort): void;
39
+ private executeContentScriptCommand;
40
+ /** Send a registryCall to a specific frame and unwrap the response. */
41
+ private sendToFrame;
42
+ private postAndWait;
43
+ runCellAsync(code: string, stdin?: string, traceId?: string): Promise<CellResult>;
44
+ setLogLevel(level: LogLevel): void;
45
+ reset(): Promise<void>;
46
+ inspectGlobals(): Promise<WasmGlobalsSnapshot>;
47
+ apiDocs(format?: "json" | "markdown"): Promise<unknown[] | string>;
48
+ setFuelLimit(limit: number): void;
49
+ loadLibrary(source: string): Promise<CellResult>;
50
+ private safePost;
51
+ private safePostCsv;
52
+ private safePostZip;
53
+ private safePostXlsx;
54
+ private safePostPdf;
55
+ get fs(): {
56
+ exists: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsExistsResult>;
57
+ stat: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStatResult>;
58
+ read: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
59
+ readText: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
60
+ readBase64: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
61
+ list: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsListResult>;
62
+ mkdir: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsBoolResult>;
63
+ delete: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsBoolResult>;
64
+ copy: (params: FsCopyParams) => Promise<import('../../worker/extension_js.js').FsBoolResult>;
65
+ move: (params: FsCopyParams) => Promise<import('../../worker/extension_js.js').FsBoolResult>;
66
+ write: (params: FsWriteParams) => Promise<import('../../worker/extension_js.js').FsWriteResult>;
67
+ writeText: (params: FsWriteParams) => Promise<import('../../worker/extension_js.js').FsWriteResult>;
68
+ writeBase64: (params: FsWriteParams) => Promise<import('../../worker/extension_js.js').FsWriteResult>;
69
+ append: (params: FsWriteParams) => Promise<import('../../worker/extension_js.js').FsWriteResult>;
70
+ appendText: (params: FsWriteParams) => Promise<import('../../worker/extension_js.js').FsWriteResult>;
71
+ appendBase64: (params: FsWriteParams) => Promise<import('../../worker/extension_js.js').FsWriteResult>;
72
+ readRange: (params: FsReadRangeParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
73
+ update: (params: FsReadRangeDataParams) => Promise<import('../../worker/extension_js.js').FsBoolResult>;
74
+ hash: (params: FsHashParams) => Promise<import('../../worker/extension_js.js').FsHashResult>;
75
+ };
76
+ get csv(): {
77
+ parse: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
78
+ };
79
+ get zip(): {
80
+ list: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
81
+ };
82
+ get xlsx(): {
83
+ read: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
84
+ };
85
+ get pdf(): {
86
+ text: (params: FsPathParams) => Promise<import('../../worker/extension_js.js').FsStringResult>;
87
+ };
88
+ get snapshot(): {
89
+ query: (filter?: SnapshotFilter, options?: {
90
+ maxNodes?: number;
91
+ tabId?: number;
92
+ }) => Promise<InlineSnapshotResult>;
93
+ };
94
+ /**
95
+ * Clean up the session, terminate the Worker, and release resources.
96
+ * Accepts the runner Promise returned by init() so it can be awaited
97
+ * for graceful shutdown.
98
+ *
99
+ * Sends a reset message to the Worker, then waits only 50 ms before
100
+ * forcefully calling worker.terminate(). If WASM cleanup takes longer,
101
+ * the Worker is killed mid-operation. Pending async calls are rejected
102
+ * with "ExtensionSession stopped".
103
+ */
104
+ stopWith(runner: Promise<void>): Promise<void>;
105
+ private generateId;
106
+ }
@@ -0,0 +1,12 @@
1
+ import { TabPolicy } from '../shared/cross/types.js';
2
+
3
+ export declare function getActiveTabId(): number | null;
4
+ export declare function setActiveTabId(tabId: number | null): void;
5
+ export declare function initTabContext(chromeApi: typeof chrome): void;
6
+ export declare function removeTabContextListeners(): void;
7
+ /** @deprecated Use initTabContext — kept for runner API compatibility */
8
+ export declare function initExtensionListeners(): void;
9
+ /** @deprecated Use removeTabContextListeners — kept for runner API compatibility */
10
+ export declare function removeExtensionListeners(): void;
11
+ export declare function resolveActiveTabId(): Promise<number | null>;
12
+ export declare function resolveTabId(tabPolicy: TabPolicy, params: Record<string, unknown>): number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pi-oxide/extension-js",
3
3
  "type": "module",
4
- "version": "0.12.3",
4
+ "version": "0.13.0",
5
5
  "license": "LicenseRef-PiccoloNotebook-Fair-BYOK-1.0",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
@@ -12,7 +12,10 @@
12
12
  "extension_js.js",
13
13
  "extension_js.d.ts",
14
14
  "content-script.js",
15
- "*.d.ts"
15
+ "content-script/",
16
+ "main/",
17
+ "shared/",
18
+ "worker/"
16
19
  ],
17
20
  "dependencies": {
18
21
  "zod": "^3.23.8",
@@ -0,0 +1,4 @@
1
+ /** Decode a base64 string into bytes. Throws on invalid input. */
2
+ export declare function base64ToUint8Array(base64: string): Uint8Array;
3
+ /** Convert Uint8Array to base64 without spread-arg limits on large buffers. */
4
+ export declare function arrayBufferToBase64(bytes: Uint8Array): string;