@pi-oxide/extension-js 0.12.4 → 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 +25785 -16587
  18. package/index.js +2227 -1774
  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 +1756 -1615
@@ -0,0 +1,130 @@
1
+ import { z } from 'zod';
2
+
3
+ export interface Command {
4
+ action: string;
5
+ params: unknown;
6
+ call_id?: number;
7
+ runId?: string;
8
+ }
9
+ export type AsyncError = {
10
+ message: string;
11
+ code: string;
12
+ category?: string;
13
+ hint?: string;
14
+ recovery?: string[];
15
+ details?: Record<string, unknown>;
16
+ };
17
+ export type AsyncResponse<T = unknown> = {
18
+ ok: true;
19
+ value: T;
20
+ } | {
21
+ ok: false;
22
+ error: AsyncError;
23
+ };
24
+ export interface ToolDocParam {
25
+ name: string;
26
+ type: string;
27
+ required: boolean;
28
+ description: string;
29
+ }
30
+ export interface ToolDoc {
31
+ action: string;
32
+ namespace: string;
33
+ description: string;
34
+ params: ToolDocParam[];
35
+ returns: {
36
+ type: string;
37
+ description: string;
38
+ };
39
+ errorCode: string;
40
+ errorCategory?: string;
41
+ example?: string;
42
+ }
43
+ export type ToolAgentMeta = {
44
+ prerequisites?: string[];
45
+ notes?: string[];
46
+ tags?: Array<"read" | "write" | "mutation" | "snapshot" | "navigation" | "chrome">;
47
+ relatedApis?: string[];
48
+ };
49
+ export interface ToolDefinition<P, R> {
50
+ action: string;
51
+ namespace: string;
52
+ description: string;
53
+ params: z.ZodSchema<P>;
54
+ returns: z.ZodSchema<R>;
55
+ handler: (params: P, callId?: number, runId?: string, signal?: AbortSignal) => Promise<R>;
56
+ paramTypes: ToolDocParam[];
57
+ returnType?: string;
58
+ returnDoc: string;
59
+ errorCode: string;
60
+ errorCategory?: string;
61
+ example?: string;
62
+ }
63
+ export type ExecutionContextId = string;
64
+ export type CallContext = {
65
+ action: string;
66
+ callId?: number;
67
+ runId?: string;
68
+ signal?: AbortSignal;
69
+ };
70
+ export type JsCallSpec<P, R> = {
71
+ action: string;
72
+ namespace: string;
73
+ name: string;
74
+ description: string;
75
+ params: z.ZodSchema<P>;
76
+ returns: z.ZodSchema<R>;
77
+ fields?: string[];
78
+ aliases?: Array<{
79
+ namespace: string;
80
+ name: string;
81
+ fields?: string[];
82
+ }>;
83
+ owner: ExecutionContextId;
84
+ handler: (params: P, ctx: CallContext) => Promise<R>;
85
+ errorCode: string;
86
+ errorCategory?: string;
87
+ paramTypes?: ToolDocParam[];
88
+ returnType?: string;
89
+ returnDoc?: string;
90
+ /** Chrome permission required to use this API (e.g. "notifications", "cookies"). */
91
+ permission?: string;
92
+ /** Runnable example string for this API. */
93
+ example?: string;
94
+ /** Agent-facing metadata for this API. */
95
+ agentMeta?: ToolAgentMeta;
96
+ };
97
+ export type SerializableJsCallManifestEntry = {
98
+ action: string;
99
+ namespace: string;
100
+ name: string;
101
+ publicName: string;
102
+ description: string;
103
+ fields: string[] | null;
104
+ aliases: Array<{
105
+ namespace: string;
106
+ name: string;
107
+ fields: string[] | null;
108
+ }> | null;
109
+ owner: ExecutionContextId;
110
+ paramsDoc: ToolDocParam[];
111
+ returnsDoc: {
112
+ type: string;
113
+ description: string;
114
+ };
115
+ errorCode: string;
116
+ errorCategory?: string;
117
+ /** Chrome permission required to use this API (e.g. "notifications", "cookies"). */
118
+ permission?: string;
119
+ /** Runnable example string for this API. */
120
+ example?: string;
121
+ prerequisites?: string[];
122
+ notes?: string[];
123
+ tags?: string[];
124
+ relatedApis?: string[];
125
+ };
126
+ /** Rust/WASM often passes BTreeMap params as a JS Map; Zod object schemas need plain objects.
127
+ * Native-parity chrome actions also JSON-round-trip in dispatch_handler; this covers relay paths. */
128
+ export declare function coerceWasmParams(params: unknown): unknown;
129
+ /** Convert a serializable manifest entry to the shape expected by WASM registerJsCall/registerJsCallBatch. */
130
+ export declare function manifestEntryToWasm(entry: SerializableJsCallManifestEntry): Record<string, unknown>;
@@ -0,0 +1,17 @@
1
+ import { contentScriptMissingError, isContentScriptConnectionError, labelNotFoundError, noTabError, notInteractableError, observationRequiredError, StaleRefCandidate, staleRefError, throwStructuredAgentError } from './agent-errors.js';
2
+ import { AsyncError } from './manifest.js';
3
+
4
+ export { contentScriptMissingError, isContentScriptConnectionError, labelNotFoundError, noTabError, notInteractableError, observationRequiredError, type StaleRefCandidate, staleRefError, throwStructuredAgentError, };
5
+ export declare function normalizeAgentError(err: unknown, context?: {
6
+ tabId?: number;
7
+ url?: string;
8
+ action?: string;
9
+ }): AsyncError;
10
+ export declare function agentErrorResponse(err: unknown, context?: {
11
+ tabId?: number;
12
+ url?: string;
13
+ action?: string;
14
+ }): {
15
+ ok: false;
16
+ error: AsyncError;
17
+ };
@@ -0,0 +1,14 @@
1
+ import { ExecutionContextId } from './manifest.js';
2
+ import { Route, TabPolicy } from './types.js';
3
+
4
+ export declare function setRoute(action: string, route: Route): void;
5
+ export declare function getRoute(action: string): Route | undefined;
6
+ export declare function clearRoutes(): void;
7
+ export declare function inferTabPolicy(action: string): TabPolicy;
8
+ export declare function inferEndpoint(owner: ExecutionContextId): Route["endpoint"];
9
+ export declare function inferOwner(action: string, owner: ExecutionContextId): ExecutionContextId;
10
+ export declare function routeFromOwner(action: string, owner: ExecutionContextId): Route;
11
+ export declare function populateRoutesFromManifest(entries: Array<{
12
+ action: string;
13
+ owner: ExecutionContextId;
14
+ }>): void;
@@ -0,0 +1,12 @@
1
+ export type TabPolicy = "active" | "required" | "optional";
2
+ export type RouteEndpoint = "main-thread" | "content-script" | `worker:${string}`;
3
+ export type Route = {
4
+ endpoint: RouteEndpoint;
5
+ tabPolicy: TabPolicy;
6
+ };
7
+ export type DispatchContext = {
8
+ action: string;
9
+ callId?: number;
10
+ runId?: string;
11
+ signal?: AbortSignal;
12
+ };
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { ToolDocParam } from './manifest.js';
3
+
4
+ /**
5
+ * Produce a human-readable type description for a Zod schema.
6
+ *
7
+ * @param schema – the Zod schema to describe
8
+ * @param depth – current recursion depth (used internally)
9
+ * @param maxDepth – maximum depth before truncating nested objects with "...";
10
+ * default 2 is used for validation-error messages, 3 for docs
11
+ */
12
+ export declare function describeSchema(schema: z.ZodTypeAny, depth?: number, maxDepth?: number): string;
13
+ /**
14
+ * Derive parameter documentation from a ZodObject schema.
15
+ *
16
+ * Transparent wrappers (ZodEffects, ZodDefault, ZodPipeline) are unwrapped
17
+ * before inspecting the shape. Keys starting with `__` are filtered out as
18
+ * internal convention. ZodDefault fields are treated as optional because the
19
+ * default value means agents don't need to provide them.
20
+ */
21
+ export declare function zodToParamDocs(schema: z.ZodTypeAny): ToolDocParam[];
22
+ /**
23
+ * Derive a rich return-type string from a Zod schema.
24
+ *
25
+ * Uses describeSchema with maxDepth=3 so nested objects are expanded one level
26
+ * deeper than validation-error messages.
27
+ */
28
+ export declare function zodToReturnType(schema: z.ZodTypeAny): string;