@jackwener/opencli 0.7.8 → 0.7.9

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 @@
1
+ export {};
package/dist/_debug.js ADDED
@@ -0,0 +1,7 @@
1
+ import { render, evalExpr } from '../pipeline/template.js';
2
+ const ctx = { item: { first: 'X', second: 'Y' } };
3
+ console.log('evalExpr item.first:', JSON.stringify(evalExpr('item.first', ctx)));
4
+ console.log('evalExpr item.second:', JSON.stringify(evalExpr('item.second', ctx)));
5
+ const template = '$' + '{{ item.first }}-$' + '{{ item.second }}';
6
+ console.log('template:', JSON.stringify(template));
7
+ console.log('render result:', JSON.stringify(render(template, ctx)));
@@ -0,0 +1,2 @@
1
+ import type { IPage } from './types.js';
2
+ export declare function withTemporaryTab<T>(page: IPage, fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,30 @@
1
+ function tabCount(tabs) {
2
+ if (Array.isArray(tabs))
3
+ return tabs.length;
4
+ if (typeof tabs === 'string') {
5
+ const matches = tabs.match(/Tab \d+/g);
6
+ return matches ? matches.length : 0;
7
+ }
8
+ return 0;
9
+ }
10
+ export async function withTemporaryTab(page, fn) {
11
+ let closeIndex = null;
12
+ try {
13
+ const before = tabCount(await page.tabs());
14
+ await page.newTab();
15
+ const after = tabCount(await page.tabs());
16
+ closeIndex = Math.max(after - 1, before);
17
+ if (closeIndex >= 0) {
18
+ await page.selectTab(closeIndex);
19
+ }
20
+ return await fn();
21
+ }
22
+ finally {
23
+ if (closeIndex != null && closeIndex >= 0) {
24
+ try {
25
+ await page.closeTab(closeIndex);
26
+ }
27
+ catch { }
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Browser interaction via Playwright MCP Bridge extension.
3
+ * Connects to an existing Chrome browser through the extension.
4
+ */
5
+ import { withTimeoutMs } from './runtime.js';
6
+ type ConnectFailureKind = 'missing-token' | 'extension-timeout' | 'extension-not-installed' | 'mcp-init' | 'process-exit' | 'unknown';
7
+ type PlaywrightMCPState = 'idle' | 'connecting' | 'connected' | 'closing' | 'closed';
8
+ type ConnectFailureInput = {
9
+ kind: ConnectFailureKind;
10
+ timeout: number;
11
+ hasExtensionToken: boolean;
12
+ tokenFingerprint?: string | null;
13
+ stderr?: string;
14
+ exitCode?: number | null;
15
+ rawMessage?: string;
16
+ };
17
+ export declare function getTokenFingerprint(token: string | undefined): string | null;
18
+ export declare function formatBrowserConnectError(input: ConnectFailureInput): Error;
19
+ declare function createJsonRpcRequest(method: string, params?: Record<string, any>): {
20
+ id: number;
21
+ message: string;
22
+ };
23
+ import type { IPage } from './types.js';
24
+ /**
25
+ * Page abstraction wrapping JSON-RPC calls to Playwright MCP.
26
+ */
27
+ export declare class Page implements IPage {
28
+ private _request;
29
+ constructor(_request: (method: string, params?: Record<string, any>) => Promise<any>);
30
+ call(method: string, params?: Record<string, any>): Promise<any>;
31
+ goto(url: string): Promise<void>;
32
+ evaluate(js: string): Promise<any>;
33
+ snapshot(opts?: {
34
+ interactive?: boolean;
35
+ compact?: boolean;
36
+ maxDepth?: number;
37
+ raw?: boolean;
38
+ }): Promise<any>;
39
+ click(ref: string): Promise<void>;
40
+ typeText(ref: string, text: string): Promise<void>;
41
+ pressKey(key: string): Promise<void>;
42
+ wait(options: number | {
43
+ text?: string;
44
+ time?: number;
45
+ timeout?: number;
46
+ }): Promise<void>;
47
+ tabs(): Promise<any>;
48
+ closeTab(index?: number): Promise<void>;
49
+ newTab(): Promise<void>;
50
+ selectTab(index: number): Promise<void>;
51
+ networkRequests(includeStatic?: boolean): Promise<any>;
52
+ consoleMessages(level?: string): Promise<any>;
53
+ scroll(direction?: string, _amount?: number): Promise<void>;
54
+ autoScroll(options?: {
55
+ times?: number;
56
+ delayMs?: number;
57
+ }): Promise<void>;
58
+ installInterceptor(pattern: string): Promise<void>;
59
+ getInterceptedRequests(): Promise<any[]>;
60
+ }
61
+ /**
62
+ * Playwright MCP process manager.
63
+ */
64
+ export declare class PlaywrightMCP {
65
+ private static _activeInsts;
66
+ private static _cleanupRegistered;
67
+ private static _registerGlobalCleanup;
68
+ private _proc;
69
+ private _buffer;
70
+ private _pending;
71
+ private _initialTabIdentities;
72
+ private _closingPromise;
73
+ private _state;
74
+ private _page;
75
+ get state(): PlaywrightMCPState;
76
+ private _sendRequest;
77
+ private _rejectPendingRequests;
78
+ private _resetAfterFailedConnect;
79
+ connect(opts?: {
80
+ timeout?: number;
81
+ }): Promise<Page>;
82
+ close(): Promise<void>;
83
+ }
84
+ declare function extractTabEntries(raw: any): Array<{
85
+ index: number;
86
+ identity: string;
87
+ }>;
88
+ declare function diffTabIndexes(initialIdentities: string[], currentTabs: Array<{
89
+ index: number;
90
+ identity: string;
91
+ }>): number[];
92
+ declare function appendLimited(current: string, chunk: string, limit: number): string;
93
+ declare function buildMcpArgs(input: {
94
+ mcpPath: string;
95
+ executablePath?: string | null;
96
+ }): string[];
97
+ export declare const __test__: {
98
+ createJsonRpcRequest: typeof createJsonRpcRequest;
99
+ extractTabEntries: typeof extractTabEntries;
100
+ diffTabIndexes: typeof diffTabIndexes;
101
+ appendLimited: typeof appendLimited;
102
+ buildMcpArgs: typeof buildMcpArgs;
103
+ withTimeoutMs: typeof withTimeoutMs;
104
+ };
105
+ export {};