@iwsdk/vite-plugin-dev 0.3.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { ProcessedDevOptions, InjectionBundleResult } from './types.js';
8
+ /**
9
+ * Load and customize the pre-built injection bundle
10
+ */
11
+ export declare function buildInjectionBundle(options: ProcessedDevOptions): Promise<InjectionBundleResult>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export { MCPWebSocketClient, initMCPClient } from './ws-client.js';
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { XRDevice } from 'iwer';
8
+ /**
9
+ * Interface that any framework can implement to provide MCP tools.
10
+ * The vite plugin will route requests to this runtime when available.
11
+ */
12
+ interface FrameworkMCPRuntime {
13
+ /**
14
+ * Returns true if this runtime handles the given method.
15
+ */
16
+ handles(method: string): boolean;
17
+ /**
18
+ * Dispatch a method call. Returns result or throws an error.
19
+ */
20
+ dispatch(method: string, params: Record<string, unknown>): Promise<unknown>;
21
+ }
22
+ declare global {
23
+ interface Window {
24
+ FRAMEWORK_MCP_RUNTIME?: FrameworkMCPRuntime;
25
+ }
26
+ }
27
+ /**
28
+ * WebSocket client that connects the browser to the Vite dev server's MCP endpoint.
29
+ * Routes commands to device.remote.dispatch() for IWER tools,
30
+ * framework runtime for IWSDK tools, and handles page reload locally.
31
+ */
32
+ export declare class MCPWebSocketClient {
33
+ private ws;
34
+ private device;
35
+ private reconnectAttempts;
36
+ private maxReconnectAttempts;
37
+ private reconnectDelay;
38
+ private reconnectTimer;
39
+ private intentionalDisconnect;
40
+ private verbose;
41
+ readonly tabId: string;
42
+ readonly tabGeneration: number;
43
+ constructor(device: XRDevice, options?: {
44
+ verbose?: boolean;
45
+ });
46
+ /**
47
+ * Connect to the Vite dev server's WebSocket endpoint
48
+ */
49
+ connect(port?: number): void;
50
+ /**
51
+ * Disconnect from the WebSocket
52
+ */
53
+ disconnect(): void;
54
+ private getVitePort;
55
+ private setupEventHandlers;
56
+ private handleMessage;
57
+ /**
58
+ * Dispatch a method call to the appropriate handler.
59
+ * Priority:
60
+ * 1. Plugin-specific tools (page reload - always local)
61
+ * 2. Framework runtime (IWSDK or any framework providing FRAMEWORK_MCP_RUNTIME)
62
+ * 3. IWER device control (device.remote.dispatch)
63
+ */
64
+ private dispatch;
65
+ private send;
66
+ private scheduleReconnect;
67
+ }
68
+ /**
69
+ * Initialize MCP WebSocket client and connect to the server
70
+ */
71
+ export declare function initMCPClient(device: XRDevice, options?: {
72
+ port?: number;
73
+ verbose?: boolean;
74
+ }): MCPWebSocketClient;
75
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ /**
8
+ * Minimal WebSocket interface used by the relay.
9
+ * Compatible with both the `ws` library and the browser WebSocket API.
10
+ */
11
+ export interface RelayWebSocket {
12
+ readyState: number;
13
+ send(data: string): void;
14
+ }
15
+ export interface RelayOptions {
16
+ verbose?: boolean;
17
+ }
18
+ export interface RelayHandler {
19
+ /**
20
+ * Handle an incoming message from a connected client.
21
+ * Routes requests to all other clients and deduplicates responses
22
+ * using first-response-wins semantics.
23
+ */
24
+ onMessage(senderWs: RelayWebSocket, data: string, clients: Set<RelayWebSocket>): void;
25
+ /** Number of pending (unresolved) relay requests. */
26
+ pendingCount(): number;
27
+ /** Clean up stale pending entries older than `maxAgeMs`. */
28
+ cleanStale(maxAgeMs: number): void;
29
+ }
30
+ /**
31
+ * Create a relay handler that implements first-response-wins message routing.
32
+ *
33
+ * When multiple browser tabs are connected, a request from the MCP server is
34
+ * broadcast to all tabs. Each tab processes it and responds. The relay
35
+ * forwards only the FIRST response for each request ID and silently drops
36
+ * duplicates.
37
+ */
38
+ export declare function createRelayHandler(options?: RelayOptions): RelayHandler;