@mearl/browser-core 3.0.5 → 3.0.7
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/dist/browserActionProtocol.d.ts +23 -4
- package/dist/browserActionProtocol.js +7 -1
- package/dist/extensionAgentAccess.d.ts +9 -0
- package/dist/extensionAgentAccess.js +24 -0
- package/dist/externalBrowserControl.d.ts +3 -0
- package/dist/externalBrowserControl.js +27 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/pageWebMcp.d.ts +57 -0
- package/dist/pageWebMcp.js +125 -0
- package/dist/proxyPermissions.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BrowserCapabilityCatalog } from './browserCapabilities.js';
|
|
2
|
+
import type { PageCallToolParams } from './pageWebMcp.js';
|
|
2
3
|
export interface GetCapabilitiesParams {
|
|
3
4
|
/** Include method and setting details for this installed App ID. */
|
|
4
5
|
app?: string;
|
|
@@ -134,7 +135,7 @@ export type BrowserJsonPrimitive = string | number | boolean | null;
|
|
|
134
135
|
export type BrowserJsonValue = BrowserJsonPrimitive | BrowserJsonValue[] | {
|
|
135
136
|
[key: string]: BrowserJsonValue;
|
|
136
137
|
};
|
|
137
|
-
export type BrowserProviderOperation = 'start' | 'close' | 'detach' | 'deleteData' | 'access' | 'syncCookies';
|
|
138
|
+
export type BrowserProviderOperation = 'start' | 'close' | 'detach' | 'deleteData' | 'access' | 'syncCookies' | 'handoff' | 'resume' | 'finish';
|
|
138
139
|
export interface BrowserProviderIdentity {
|
|
139
140
|
id: string;
|
|
140
141
|
name: string;
|
|
@@ -268,9 +269,16 @@ export interface BrowserReleaseParams {
|
|
|
268
269
|
keepArtifactIds?: string[];
|
|
269
270
|
}
|
|
270
271
|
export interface BrowserControlParams {
|
|
271
|
-
operation: 'handoff' | 'resume';
|
|
272
|
+
operation: 'handoff' | 'resume' | 'finish';
|
|
272
273
|
tabId?: number;
|
|
273
274
|
reason?: string;
|
|
275
|
+
/** External Provider finish only; retain these result pages. */
|
|
276
|
+
keepTabIds?: number[];
|
|
277
|
+
}
|
|
278
|
+
export interface ExternalBrowserControlResult {
|
|
279
|
+
controlSessionMode: 'external';
|
|
280
|
+
operation: BrowserControlParams['operation'];
|
|
281
|
+
control: 'agent' | 'user' | 'finished';
|
|
274
282
|
}
|
|
275
283
|
export interface BrowserArtifact {
|
|
276
284
|
artifactId: string;
|
|
@@ -652,6 +660,7 @@ export interface PageSnapshotQuery {
|
|
|
652
660
|
}
|
|
653
661
|
export interface PageSnapshotParams {
|
|
654
662
|
tabId: number;
|
|
663
|
+
includeWebMcp?: 'full';
|
|
655
664
|
depth?: number;
|
|
656
665
|
maxChars?: number;
|
|
657
666
|
maxNodes?: number;
|
|
@@ -846,7 +855,7 @@ export interface BrowserActionMap {
|
|
|
846
855
|
request: BrowserControlParams;
|
|
847
856
|
response: {
|
|
848
857
|
session: ControlSessionInfo;
|
|
849
|
-
};
|
|
858
|
+
} | ExternalBrowserControlResult;
|
|
850
859
|
};
|
|
851
860
|
page_download: {
|
|
852
861
|
request: PageDownloadParams;
|
|
@@ -904,6 +913,12 @@ export interface BrowserActionMap {
|
|
|
904
913
|
request: PageEvalParams;
|
|
905
914
|
response: unknown;
|
|
906
915
|
};
|
|
916
|
+
page_call_tool: {
|
|
917
|
+
request: PageCallToolParams;
|
|
918
|
+
response: {
|
|
919
|
+
result: unknown;
|
|
920
|
+
};
|
|
921
|
+
};
|
|
907
922
|
page_runtime: {
|
|
908
923
|
request: Record<string, unknown>;
|
|
909
924
|
response: unknown;
|
|
@@ -973,7 +988,7 @@ export type BrowserActionResponse<A extends BrowserAction> = BrowserActionMap[A]
|
|
|
973
988
|
};
|
|
974
989
|
export type BrowserCommandAction = Exclude<BrowserAction, 'browser_select_browser'>;
|
|
975
990
|
export type ExtensionBrowserAction = Exclude<BrowserCommandAction, 'browser_list' | 'browser_launch' | 'browser_close' | 'browser_control' | 'page_download'>;
|
|
976
|
-
export declare const TAB_ID_REQUIRED_ACTIONS: readonly ["tab_checkpoint", "capture_checkpoint", "get_requests", "get_logs", "get_events", "set_mock", "get_mocks", "page_screenshot", "tab_close", "page_click", "page_drag", "page_type", "page_scroll", "page_hover", "page_eval", "page_inspect", "page_snapshot", "page_press", "page_wait", "page_navigate", "page_upload", "page_download", "page_frames", "set_device_emulation", "set_app_profile", "set_timezone", "run_actions"];
|
|
991
|
+
export declare const TAB_ID_REQUIRED_ACTIONS: readonly ["tab_checkpoint", "capture_checkpoint", "get_requests", "get_logs", "get_events", "set_mock", "get_mocks", "page_screenshot", "tab_close", "page_click", "page_drag", "page_type", "page_scroll", "page_hover", "page_eval", "page_call_tool", "page_inspect", "page_snapshot", "page_press", "page_wait", "page_navigate", "page_upload", "page_download", "page_frames", "set_device_emulation", "set_app_profile", "set_timezone", "run_actions"];
|
|
977
992
|
export type TabIdRequiredAction = (typeof TAB_ID_REQUIRED_ACTIONS)[number];
|
|
978
993
|
export declare function actionRequiresTabId(action: unknown): action is TabIdRequiredAction;
|
|
979
994
|
export declare function validateRequiredActionTabId(action: string, data: unknown): void;
|
|
@@ -1009,6 +1024,7 @@ export declare const BROWSER_ACTIONS: {
|
|
|
1009
1024
|
readonly page_scroll: true;
|
|
1010
1025
|
readonly page_hover: true;
|
|
1011
1026
|
readonly page_eval: true;
|
|
1027
|
+
readonly page_call_tool: true;
|
|
1012
1028
|
readonly page_runtime: true;
|
|
1013
1029
|
readonly page_inspect: true;
|
|
1014
1030
|
readonly page_snapshot: true;
|
|
@@ -1054,6 +1070,7 @@ export declare const BROWSER_COMMAND_ACTIONS: {
|
|
|
1054
1070
|
readonly page_scroll: true;
|
|
1055
1071
|
readonly page_hover: true;
|
|
1056
1072
|
readonly page_eval: true;
|
|
1073
|
+
readonly page_call_tool: true;
|
|
1057
1074
|
readonly page_runtime: true;
|
|
1058
1075
|
readonly page_inspect: true;
|
|
1059
1076
|
readonly page_snapshot: true;
|
|
@@ -1094,6 +1111,7 @@ export declare const EXTENSION_BROWSER_ACTIONS: {
|
|
|
1094
1111
|
readonly page_scroll: true;
|
|
1095
1112
|
readonly page_hover: true;
|
|
1096
1113
|
readonly page_eval: true;
|
|
1114
|
+
readonly page_call_tool: true;
|
|
1097
1115
|
readonly page_runtime: true;
|
|
1098
1116
|
readonly page_inspect: true;
|
|
1099
1117
|
readonly page_snapshot: true;
|
|
@@ -1135,6 +1153,7 @@ export declare const BROWSER_CAPABILITY_ACTIONS: {
|
|
|
1135
1153
|
readonly page_scroll: true;
|
|
1136
1154
|
readonly page_hover: true;
|
|
1137
1155
|
readonly page_eval: true;
|
|
1156
|
+
readonly page_call_tool: true;
|
|
1138
1157
|
readonly page_runtime: true;
|
|
1139
1158
|
readonly page_inspect: true;
|
|
1140
1159
|
readonly page_snapshot: true;
|
|
@@ -58,6 +58,7 @@ export const TAB_ID_REQUIRED_ACTIONS = [
|
|
|
58
58
|
'page_scroll',
|
|
59
59
|
'page_hover',
|
|
60
60
|
'page_eval',
|
|
61
|
+
'page_call_tool',
|
|
61
62
|
'page_inspect',
|
|
62
63
|
'page_snapshot',
|
|
63
64
|
'page_press',
|
|
@@ -76,7 +77,9 @@ export function actionRequiresTabId(action) {
|
|
|
76
77
|
return typeof action === 'string' && TAB_ID_REQUIRED_ACTION_SET.has(action);
|
|
77
78
|
}
|
|
78
79
|
export function validateRequiredActionTabId(action, data) {
|
|
79
|
-
if (action === 'get_capabilities' &&
|
|
80
|
+
if (action === 'get_capabilities' &&
|
|
81
|
+
data &&
|
|
82
|
+
typeof data === 'object' &&
|
|
80
83
|
['tabId', 'tabIds', 'openerTabId'].some(key => Object.hasOwn(data, key))) {
|
|
81
84
|
throw new Error('get_capabilities does not accept page targets');
|
|
82
85
|
}
|
|
@@ -140,6 +143,7 @@ export const BROWSER_ACTIONS = {
|
|
|
140
143
|
page_scroll: true,
|
|
141
144
|
page_hover: true,
|
|
142
145
|
page_eval: true,
|
|
146
|
+
page_call_tool: true,
|
|
143
147
|
page_runtime: true,
|
|
144
148
|
page_inspect: true,
|
|
145
149
|
page_snapshot: true,
|
|
@@ -185,6 +189,7 @@ export const BROWSER_COMMAND_ACTIONS = {
|
|
|
185
189
|
page_scroll: true,
|
|
186
190
|
page_hover: true,
|
|
187
191
|
page_eval: true,
|
|
192
|
+
page_call_tool: true,
|
|
188
193
|
page_runtime: true,
|
|
189
194
|
page_inspect: true,
|
|
190
195
|
page_snapshot: true,
|
|
@@ -225,6 +230,7 @@ export const EXTENSION_BROWSER_ACTIONS = {
|
|
|
225
230
|
page_scroll: true,
|
|
226
231
|
page_hover: true,
|
|
227
232
|
page_eval: true,
|
|
233
|
+
page_call_tool: true,
|
|
228
234
|
page_runtime: true,
|
|
229
235
|
page_inspect: true,
|
|
230
236
|
page_snapshot: true,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Native Messaging management handshake; independent of Agent page access. */
|
|
2
|
+
export interface ExtensionAgentPolicy {
|
|
3
|
+
revision: number;
|
|
4
|
+
providerIds: string[];
|
|
5
|
+
available?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Internal file references grant payload trust, not permission to operate pages. */
|
|
8
|
+
export declare function requiresExtensionAgentAccess(action: string, data: any, trustedInternal?: boolean): boolean;
|
|
9
|
+
export declare function isExtensionAgentPolicy(value: unknown): value is ExtensionAgentPolicy;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Internal file references grant payload trust, not permission to operate pages. */
|
|
2
|
+
export function requiresExtensionAgentAccess(action, data, trustedInternal = false) {
|
|
3
|
+
if (!trustedInternal)
|
|
4
|
+
return true;
|
|
5
|
+
if (!action.startsWith('__') && action !== 'get_browser_info')
|
|
6
|
+
return true;
|
|
7
|
+
if (action === '__capture_download' || action === '__export_cookies')
|
|
8
|
+
return true;
|
|
9
|
+
if (action === '__send_request_files')
|
|
10
|
+
return data?.operation !== 'abort';
|
|
11
|
+
if (action === '__browser_enhancement')
|
|
12
|
+
return data?.operation !== 'release';
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
export function isExtensionAgentPolicy(value) {
|
|
16
|
+
const policy = value;
|
|
17
|
+
return (!!policy &&
|
|
18
|
+
Number.isSafeInteger(policy.revision) &&
|
|
19
|
+
policy.revision >= 0 &&
|
|
20
|
+
(policy.available === undefined || typeof policy.available === 'boolean') &&
|
|
21
|
+
Array.isArray(policy.providerIds) &&
|
|
22
|
+
policy.providerIds.length <= 100 &&
|
|
23
|
+
policy.providerIds.every(id => typeof id === 'string' && id.length > 0 && id.length <= 256 && !/[\x00-\x1f]/.test(id)));
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** External task lifecycle calls must not silently discard page retention options. */
|
|
2
|
+
export function parseExternalBrowserControl(value) {
|
|
3
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
4
|
+
throw new Error('Invalid browser control request');
|
|
5
|
+
const data = value;
|
|
6
|
+
if (Object.keys(data).some(key => !['operation', 'tabId', 'reason', 'keepTabIds'].includes(key)))
|
|
7
|
+
throw new Error('Unsupported browser control parameter');
|
|
8
|
+
if (typeof data.operation !== 'string' ||
|
|
9
|
+
!['handoff', 'resume', 'finish'].includes(data.operation))
|
|
10
|
+
throw new Error('Invalid browser control operation');
|
|
11
|
+
if (data.tabId !== undefined && (!Number.isSafeInteger(data.tabId) || Number(data.tabId) < 0))
|
|
12
|
+
throw new Error('Invalid control tabId');
|
|
13
|
+
if (data.reason !== undefined && typeof data.reason !== 'string')
|
|
14
|
+
throw new Error('Invalid control reason');
|
|
15
|
+
if (data.keepTabIds !== undefined &&
|
|
16
|
+
(data.operation !== 'finish' ||
|
|
17
|
+
!Array.isArray(data.keepTabIds) ||
|
|
18
|
+
data.keepTabIds.some(id => !Number.isSafeInteger(id) || id < 0) ||
|
|
19
|
+
new Set(data.keepTabIds).size !== data.keepTabIds.length))
|
|
20
|
+
throw new Error('keepTabIds requires finish and unique nonnegative integer tab IDs');
|
|
21
|
+
return {
|
|
22
|
+
operation: data.operation,
|
|
23
|
+
...(data.tabId !== undefined ? { tabId: data.tabId } : {}),
|
|
24
|
+
...(data.reason !== undefined ? { reason: data.reason } : {}),
|
|
25
|
+
...(data.keepTabIds !== undefined ? { keepTabIds: [...data.keepTabIds] } : {}),
|
|
26
|
+
};
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './appProfileDefinition.js';
|
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './browserEnhancement.js';
|
|
4
4
|
export * from './browserDiscovery.js';
|
|
5
|
+
export * from './externalBrowserControl.js';
|
|
5
6
|
export * from './providerAppResources.js';
|
|
6
7
|
export * from './eventFilters.js';
|
|
7
8
|
export * from './requestSerializer.js';
|
|
@@ -30,6 +31,7 @@ export * from './backendNodeRefs.js';
|
|
|
30
31
|
export * from './pageEffectRefs.js';
|
|
31
32
|
export * from './pageWait.js';
|
|
32
33
|
export * from './pageNavigation.js';
|
|
34
|
+
export * from './pageWebMcp.js';
|
|
33
35
|
export * from './tabMatching.js';
|
|
34
36
|
export * from './agentChat.js';
|
|
35
37
|
export * from './agentSkills.js';
|
|
@@ -65,3 +67,4 @@ export * from './extensionVersion.js';
|
|
|
65
67
|
export { MEARL_NATIVE_HOST_NAMES, type NativeHostIntegrationMode } from './nativeHostNames.js';
|
|
66
68
|
export * from './dataStructure.js';
|
|
67
69
|
export * from './requestMetadata.js';
|
|
70
|
+
export * from './extensionAgentAccess.js';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './appProfileDefinition.js';
|
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './browserEnhancement.js';
|
|
4
4
|
export * from './browserDiscovery.js';
|
|
5
|
+
export * from './externalBrowserControl.js';
|
|
5
6
|
export * from './providerAppResources.js';
|
|
6
7
|
export * from './eventFilters.js';
|
|
7
8
|
export * from './requestSerializer.js';
|
|
@@ -29,6 +30,7 @@ export * from './backendNodeRefs.js';
|
|
|
29
30
|
export * from './pageEffectRefs.js';
|
|
30
31
|
export * from './pageWait.js';
|
|
31
32
|
export * from './pageNavigation.js';
|
|
33
|
+
export * from './pageWebMcp.js';
|
|
32
34
|
export * from './tabMatching.js';
|
|
33
35
|
export * from './agentChat.js';
|
|
34
36
|
export * from './agentSkills.js';
|
|
@@ -64,3 +66,4 @@ export * from './extensionVersion.js';
|
|
|
64
66
|
export { MEARL_NATIVE_HOST_NAMES } from './nativeHostNames.js';
|
|
65
67
|
export * from './dataStructure.js';
|
|
66
68
|
export * from './requestMetadata.js';
|
|
69
|
+
export * from './extensionAgentAccess.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface PageCallToolParams {
|
|
2
|
+
tabId: number;
|
|
3
|
+
toolRef: string;
|
|
4
|
+
arguments?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface PageWebMcpTool {
|
|
7
|
+
ref?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
inputSchema?: Record<string, unknown>;
|
|
11
|
+
annotations?: Record<string, unknown>;
|
|
12
|
+
origin: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PageWebMcpCatalog {
|
|
15
|
+
url: string;
|
|
16
|
+
status: 'ready' | 'unsupported' | 'discovery-only';
|
|
17
|
+
tools: PageWebMcpTool[];
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type PageWebMcpRequest = {
|
|
21
|
+
operation: 'discover';
|
|
22
|
+
} | {
|
|
23
|
+
operation: 'call';
|
|
24
|
+
toolRef: string;
|
|
25
|
+
input: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
export type PageWebMcpResult = {
|
|
28
|
+
catalog: PageWebMcpCatalog;
|
|
29
|
+
} | {
|
|
30
|
+
result: unknown;
|
|
31
|
+
} | {
|
|
32
|
+
error: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function pageWebMcpCallRequest(params: PageCallToolParams): PageWebMcpRequest;
|
|
35
|
+
/** Runs in an isolated world. Native tool objects stay in their original document. */
|
|
36
|
+
export declare function executePageWebMcp(request: PageWebMcpRequest): Promise<PageWebMcpResult>;
|
|
37
|
+
/** Passive discovery never delays the browser action that triggered it. */
|
|
38
|
+
export declare class PageWebMcpObservation {
|
|
39
|
+
private catalog?;
|
|
40
|
+
private pending?;
|
|
41
|
+
private refs;
|
|
42
|
+
protected get hasCatalog(): boolean;
|
|
43
|
+
reset(): void;
|
|
44
|
+
assertRef(toolRef: string): void;
|
|
45
|
+
refresh(probe: () => Promise<PageWebMcpResult>): Promise<void>;
|
|
46
|
+
fields(url: string | undefined, full?: boolean): {
|
|
47
|
+
webmcp: never[];
|
|
48
|
+
webmcpStatus: string;
|
|
49
|
+
} | {
|
|
50
|
+
webmcp?: undefined;
|
|
51
|
+
webmcpStatus?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
webmcpTruncated?: boolean | undefined;
|
|
54
|
+
webmcpStatus?: "unsupported" | "ready" | "discovery-only" | undefined;
|
|
55
|
+
webmcp: PageWebMcpTool[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export function pageWebMcpCallRequest(params) {
|
|
2
|
+
const { toolRef, arguments: input = {} } = params;
|
|
3
|
+
if (typeof toolRef !== 'string' || !/^webmcp:[0-9a-f-]{36}$/.test(toolRef))
|
|
4
|
+
throw new Error('page_call_tool requires a toolRef from the page WebMCP catalog');
|
|
5
|
+
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
6
|
+
throw new Error('page_call_tool arguments must be a JSON object');
|
|
7
|
+
return { operation: 'call', toolRef, input };
|
|
8
|
+
}
|
|
9
|
+
/** Runs in an isolated world. Native tool objects stay in their original document. */
|
|
10
|
+
export async function executePageWebMcp(request) {
|
|
11
|
+
const world = globalThis;
|
|
12
|
+
const context = document.modelContext;
|
|
13
|
+
if (request.operation === 'call') {
|
|
14
|
+
const tool = world.__mearlWebMcpRefs?.get(request.toolRef);
|
|
15
|
+
if (!context || !tool || tool.window !== window)
|
|
16
|
+
return {
|
|
17
|
+
error: 'WEBMCP_STALE_TOOL: Refresh the page WebMCP catalog before calling this tool',
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const result = await context.executeTool(tool, request.input, {
|
|
21
|
+
signal: AbortSignal.timeout(10_000),
|
|
22
|
+
});
|
|
23
|
+
return { result: result ?? null };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return { error: `WEBMCP_CALL_FAILED: ${String(error)}. Check page state before retrying.` };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const catalog = {
|
|
30
|
+
url: location.href,
|
|
31
|
+
status: 'unsupported',
|
|
32
|
+
tools: [],
|
|
33
|
+
truncated: false,
|
|
34
|
+
};
|
|
35
|
+
if (typeof context?.getTools !== 'function' || typeof context.executeTool !== 'function')
|
|
36
|
+
return { catalog };
|
|
37
|
+
// Older Chrome returns dictionaries and dispatches by name, even with an old tool object.
|
|
38
|
+
const toolPrototype = world.Tool?.prototype;
|
|
39
|
+
catalog.status = toolPrototype ? 'ready' : 'discovery-only';
|
|
40
|
+
const refs = (world.__mearlWebMcpRefs ??= new Map());
|
|
41
|
+
let remaining = 64_000;
|
|
42
|
+
for (const tool of await context.getTools()) {
|
|
43
|
+
if (tool.window !== window)
|
|
44
|
+
continue;
|
|
45
|
+
const { name, description, inputSchema, annotations, origin } = tool;
|
|
46
|
+
const metadata = { name, description, inputSchema, annotations, origin };
|
|
47
|
+
const length = JSON.stringify(metadata).length;
|
|
48
|
+
if (catalog.tools.length >= 64 || length > remaining) {
|
|
49
|
+
catalog.truncated = true;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (toolPrototype && Object.getPrototypeOf(tool) === toolPrototype) {
|
|
53
|
+
metadata.ref = `webmcp:${crypto.randomUUID()}`;
|
|
54
|
+
refs.set(metadata.ref, tool);
|
|
55
|
+
}
|
|
56
|
+
catalog.tools.push(metadata);
|
|
57
|
+
remaining -= length;
|
|
58
|
+
}
|
|
59
|
+
while (refs.size > 256)
|
|
60
|
+
refs.delete(refs.keys().next().value);
|
|
61
|
+
return { catalog };
|
|
62
|
+
}
|
|
63
|
+
/** Passive discovery never delays the browser action that triggered it. */
|
|
64
|
+
export class PageWebMcpObservation {
|
|
65
|
+
catalog;
|
|
66
|
+
pending;
|
|
67
|
+
refs = new Set();
|
|
68
|
+
get hasCatalog() {
|
|
69
|
+
return this.catalog !== undefined;
|
|
70
|
+
}
|
|
71
|
+
reset() {
|
|
72
|
+
this.catalog = undefined;
|
|
73
|
+
this.pending = undefined;
|
|
74
|
+
this.refs.clear();
|
|
75
|
+
}
|
|
76
|
+
assertRef(toolRef) {
|
|
77
|
+
if (!this.refs.has(toolRef))
|
|
78
|
+
throw new Error('WEBMCP_STALE_TOOL: Refresh the page WebMCP catalog before calling this tool');
|
|
79
|
+
}
|
|
80
|
+
refresh(probe) {
|
|
81
|
+
if (this.pending)
|
|
82
|
+
return this.pending;
|
|
83
|
+
let cancelTimeout = () => { };
|
|
84
|
+
const timeout = new Promise(resolve => {
|
|
85
|
+
const timer = setTimeout(resolve, 500);
|
|
86
|
+
cancelTimeout = () => clearTimeout(timer);
|
|
87
|
+
});
|
|
88
|
+
const pending = Promise.race([Promise.resolve().then(probe), timeout])
|
|
89
|
+
.catch(() => undefined)
|
|
90
|
+
.then(result => {
|
|
91
|
+
if (this.pending !== pending)
|
|
92
|
+
return;
|
|
93
|
+
this.catalog =
|
|
94
|
+
result && typeof result === 'object' && 'catalog' in result ? result.catalog : undefined;
|
|
95
|
+
for (const tool of this.catalog?.tools ?? []) {
|
|
96
|
+
if (tool.ref)
|
|
97
|
+
this.refs.add(tool.ref);
|
|
98
|
+
}
|
|
99
|
+
while (this.refs.size > 256)
|
|
100
|
+
this.refs.delete(this.refs.values().next().value);
|
|
101
|
+
})
|
|
102
|
+
.finally(() => {
|
|
103
|
+
cancelTimeout();
|
|
104
|
+
if (this.pending === pending)
|
|
105
|
+
this.pending = undefined;
|
|
106
|
+
});
|
|
107
|
+
this.pending = pending;
|
|
108
|
+
return pending;
|
|
109
|
+
}
|
|
110
|
+
fields(url, full = false) {
|
|
111
|
+
const catalog = this.catalog;
|
|
112
|
+
if (!catalog || (url && catalog.url !== url))
|
|
113
|
+
return full ? { webmcp: [], webmcpStatus: 'unavailable' } : {};
|
|
114
|
+
if (!full && !catalog.tools.length && !catalog.truncated)
|
|
115
|
+
return {};
|
|
116
|
+
const tools = full ? catalog.tools : catalog.tools.slice(0, 8);
|
|
117
|
+
return {
|
|
118
|
+
webmcp: tools,
|
|
119
|
+
...(full || catalog.status !== 'ready' ? { webmcpStatus: catalog.status } : {}),
|
|
120
|
+
...(catalog.truncated || tools.length < catalog.tools.length
|
|
121
|
+
? { webmcpTruncated: true }
|
|
122
|
+
: {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
package/dist/proxyPermissions.js
CHANGED
|
@@ -6,7 +6,7 @@ export class DomainPermissionError extends Error {
|
|
|
6
6
|
domain;
|
|
7
7
|
code = 'DOMAIN_PERMISSION_REQUIRED';
|
|
8
8
|
requestDispatched = false;
|
|
9
|
-
constructor(action, domain, message = `${action}: Access to "${domain}" is not authorized.
|
|
9
|
+
constructor(action, domain, message = `${action}: Access to "${domain}" is not authorized. Request user authorization, then retry:\nmearl request_permission --payload '${JSON.stringify({ domain }).replace(/'/g, "'\\''")}'`) {
|
|
10
10
|
super(message);
|
|
11
11
|
this.action = action;
|
|
12
12
|
this.domain = domain;
|
package/package.json
CHANGED