fix tsc
This commit is contained in:
@@ -1,26 +1,10 @@
|
||||
import { RelayConnection, logger } from './relayConnection'
|
||||
import { createStore } from 'zustand/vanilla'
|
||||
import type { ExtensionState, ConnectionState, TabState, TabInfo } from './types'
|
||||
|
||||
// Relay URL - fixed port for MCP bridge
|
||||
const RELAY_URL = 'ws://localhost:19988/extension'
|
||||
|
||||
type ConnectionState = 'disconnected' | 'reconnecting' | 'connected' | 'error'
|
||||
type TabState = 'connecting' | 'connected' | 'error'
|
||||
|
||||
interface TabInfo {
|
||||
targetId: string
|
||||
state: TabState
|
||||
errorText?: string
|
||||
}
|
||||
|
||||
interface ExtensionState {
|
||||
connection: RelayConnection | undefined
|
||||
connectedTabs: Map<number, TabInfo>
|
||||
connectionState: ConnectionState
|
||||
currentTabId: number | undefined
|
||||
errorText: string | undefined
|
||||
}
|
||||
|
||||
const useExtensionStore = createStore<ExtensionState>((set) => ({
|
||||
connection: undefined,
|
||||
connectedTabs: new Map(),
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { RelayConnection } from './relayConnection'
|
||||
|
||||
export type ConnectionState = 'disconnected' | 'reconnecting' | 'connected' | 'error'
|
||||
export type TabState = 'connecting' | 'connected' | 'error'
|
||||
|
||||
export interface TabInfo {
|
||||
targetId: string
|
||||
state: TabState
|
||||
errorText?: string
|
||||
}
|
||||
|
||||
export interface ExtensionState {
|
||||
connection: RelayConnection | undefined
|
||||
connectedTabs: Map<number, TabInfo>
|
||||
connectionState: ConnectionState
|
||||
currentTabId: number | undefined
|
||||
errorText: string | undefined
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"@mizchi/selector-generator": "1.50.0-next",
|
||||
"@types/chrome": "^0.0.315",
|
||||
"@types/node": "^24.10.1",
|
||||
"@vitest/ui": "^4.0.8",
|
||||
"mcp-extension": "workspace:*",
|
||||
|
||||
@@ -55,7 +55,6 @@ declare global {
|
||||
var toggleExtensionForActiveTab: () => Promise<{ isConnected: boolean; state: ExtensionState }>;
|
||||
var getExtensionState: () => ExtensionState;
|
||||
var disconnectEverything: () => Promise<void>;
|
||||
var chrome: any;
|
||||
}
|
||||
|
||||
describe('MCP Server Tests', () => {
|
||||
@@ -224,13 +223,12 @@ describe('MCP Server Tests', () => {
|
||||
// Get extension state to verify the page is marked as connected
|
||||
const extensionState = await serviceWorker.evaluate(async () => {
|
||||
const state = globalThis.getExtensionState()
|
||||
const chrome = globalThis.chrome
|
||||
const tabs = await chrome.tabs.query({})
|
||||
const testTab = tabs.find((t: any) => t.url?.includes('mcp-test'))
|
||||
return {
|
||||
connected: !!testTab && state.connectedTabs.has(testTab.id),
|
||||
connected: !!testTab && !!testTab.id && state.connectedTabs.has(testTab.id),
|
||||
tabId: testTab?.id,
|
||||
tabInfo: testTab ? state.connectedTabs.get(testTab.id) : null,
|
||||
tabInfo: testTab?.id ? state.connectedTabs.get(testTab.id) : null,
|
||||
connectionState: state.connectionState
|
||||
}
|
||||
})
|
||||
@@ -583,8 +581,8 @@ describe('MCP Server Tests', () => {
|
||||
const tabA = tabs.find((t: any) => t.url?.includes('tab-a'))
|
||||
const tabB = tabs.find((t: any) => t.url?.includes('tab-b'))
|
||||
return {
|
||||
idA: state.connectedTabs.get(tabA?.id)?.targetId,
|
||||
idB: state.connectedTabs.get(tabB?.id)?.targetId
|
||||
idA: state.connectedTabs.get(tabA?.id ?? -1)?.targetId,
|
||||
idB: state.connectedTabs.get(tabB?.id ?? -1)?.targetId
|
||||
}
|
||||
})
|
||||
|
||||
@@ -669,8 +667,8 @@ describe('MCP Server Tests', () => {
|
||||
const tabA = tabs.find((t: any) => t.url?.includes('tab-a'))
|
||||
const tabB = tabs.find((t: any) => t.url?.includes('tab-b'))
|
||||
return {
|
||||
idA: state.connectedTabs.get(tabA?.id)?.targetId,
|
||||
idB: state.connectedTabs.get(tabB?.id)?.targetId
|
||||
idA: state.connectedTabs.get(tabA?.id ?? -1)?.targetId,
|
||||
idB: state.connectedTabs.get(tabB?.id ?? -1)?.targetId
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
"outDir": "dist",
|
||||
"types": ["node", "chrome"]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
Generated
+3
@@ -94,6 +94,9 @@ importers:
|
||||
'@mizchi/selector-generator':
|
||||
specifier: 1.50.0-next
|
||||
version: 1.50.0-next
|
||||
'@types/chrome':
|
||||
specifier: ^0.0.315
|
||||
version: 0.0.315
|
||||
'@types/node':
|
||||
specifier: ^24.10.1
|
||||
version: 24.10.1
|
||||
|
||||
Reference in New Issue
Block a user