Skip to content

Commit 9982181

Browse files
committed
修复claude-for-chrome-mcp中的type和interface类型缺失
1 parent 12596e4 commit 9982181

14 files changed

Lines changed: 165 additions & 54 deletions

File tree

packages/@ant/claude-for-chrome-mcp/src/bridgeClient.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SocketConnectionError } from './mcpSocketClient.js'
99
import {
1010
localPlatformLabel,
1111
type BridgePermissionRequest,
12+
toLoggerDetail,
1213
type ChromeExtensionInfo,
1314
type ClaudeForChromeContext,
1415
type PermissionMode,
@@ -578,7 +579,7 @@ export class BridgeClient implements SocketClient {
578579
const durationMs = Date.now() - this.connectionStartTime
579580
logger.error(
580581
`[${serverName}] Failed to create WebSocket after ${durationMs}ms:`,
581-
error,
582+
toLoggerDetail(error),
582583
)
583584
trackEvent?.('chrome_bridge_connection_failed', {
584585
duration_ms: durationMs,
@@ -618,7 +619,10 @@ export class BridgeClient implements SocketClient {
618619
)
619620
this.handleMessage(message)
620621
} catch (error) {
621-
logger.error(`[${serverName}] Failed to parse bridge message:`, error)
622+
logger.error(
623+
`[${serverName}] Failed to parse bridge message:`,
624+
toLoggerDetail(error),
625+
)
622626
}
623627
})
624628

@@ -862,7 +866,10 @@ export class BridgeClient implements SocketClient {
862866
const allowed = await pending.onPermissionRequest(request)
863867
this.sendPermissionResponse(requestId, allowed)
864868
} catch (error) {
865-
logger.error(`[${serverName}] Error handling permission request:`, error)
869+
logger.error(
870+
`[${serverName}] Error handling permission request:`,
871+
toLoggerDetail(error),
872+
)
866873
this.sendPermissionResponse(requestId, false)
867874
}
868875
}

packages/@ant/claude-for-chrome-mcp/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export { localPlatformLabel } from './types.js'
88
export type {
99
BridgeConfig,
1010
ChromeExtensionInfo,
11+
ChromeBridgeTrackEventMetadata,
1112
ClaudeForChromeContext,
1213
Logger,
14+
LoggerDetail,
1315
PermissionMode,
1416
SocketClient,
1517
} from './types.js'
18+
export { toLoggerDetail } from './types.js'

packages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
PermissionMode,
1010
PermissionOverrides,
1111
} from './types.js'
12+
import { toLoggerDetail } from './types.js'
1213

1314
export class SocketConnectionError extends Error {
1415
constructor(message: string) {
@@ -87,7 +88,10 @@ class McpSocketClient {
8788
await this.validateSocketSecurity(socketPath)
8889
} catch (error) {
8990
this.connecting = false
90-
logger.info(`[${serverName}] Security validation failed:`, error)
91+
logger.info(
92+
`[${serverName}] Security validation failed:`,
93+
toLoggerDetail(error),
94+
)
9195
// Don't retry on security failures (wrong perms/owner) - those won't
9296
// self-resolve. Only the error handler retries on transient errors.
9397
return
@@ -145,14 +149,20 @@ class McpSocketClient {
145149
logger.info(`[${serverName}] Received unknown message: ${message}`)
146150
}
147151
} catch (error) {
148-
logger.info(`[${serverName}] Failed to parse message:`, error)
152+
logger.info(
153+
`[${serverName}] Failed to parse message:`,
154+
toLoggerDetail(error),
155+
)
149156
}
150157
}
151158
})
152159

153160
this.socket.on('error', (error: Error & { code?: string }) => {
154161
clearTimeout(connectTimeout)
155-
logger.info(`[${serverName}] Socket error (code: ${error.code}):`, error)
162+
logger.info(
163+
`[${serverName}] Socket error (code: ${error.code}):`,
164+
toLoggerDetail(error),
165+
)
156166
this.connected = false
157167
this.connecting = false
158168

packages/@ant/claude-for-chrome-mcp/src/toolCalls.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
PermissionOverrides,
88
SocketClient,
99
} from './types.js'
10+
import { toLoggerDetail } from './types.js'
1011

1112
export const handleToolCall = async (
1213
context: ClaudeForChromeContext,
@@ -44,7 +45,10 @@ export const handleToolCall = async (
4445

4546
return handleToolCallDisconnected(context)
4647
} catch (error) {
47-
context.logger.info(`[${context.serverName}] Error calling tool:`, error)
48+
context.logger.info(
49+
`[${context.serverName}] Error calling tool:`,
50+
toLoggerDetail(error),
51+
)
4852

4953
if (error instanceof SocketConnectionError) {
5054
return handleToolCallDisconnected(context)
@@ -165,8 +169,7 @@ async function handleToolCallConnected(
165169

166170
// Fallback for unexpected result format
167171
context.logger.warn(
168-
`[${context.serverName}] Unexpected result format from socket bridge`,
169-
response,
172+
`[${context.serverName}] Unexpected result format from socket bridge: ${JSON.stringify(response)}`,
170173
)
171174

172175
return {

packages/@ant/claude-for-chrome-mcp/src/types.ts

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,66 @@
1+
/** Optional util.format detail; call sites pass caught exceptions. */
2+
export type LoggerDetail = Error | NodeJS.ErrnoException
3+
4+
export function toLoggerDetail(detail: unknown): LoggerDetail | undefined {
5+
return detail instanceof Error ? detail : undefined
6+
}
7+
18
export interface Logger {
2-
info: (message: string, ...args: unknown[]) => void
3-
error: (message: string, ...args: unknown[]) => void
4-
warn: (message: string, ...args: unknown[]) => void
5-
debug: (message: string, ...args: unknown[]) => void
6-
silly: (message: string, ...args: unknown[]) => void
9+
info: (message: string, detail?: LoggerDetail) => void
10+
error: (message: string, detail?: LoggerDetail) => void
11+
warn: (message: string, detail?: LoggerDetail) => void
12+
debug: (message: string, detail?: LoggerDetail) => void
13+
silly: (message: string, detail?: LoggerDetail) => void
714
}
815

16+
export type ChromeBridgeConnectionErrorType =
17+
| 'no_user_id'
18+
| 'no_oauth_token'
19+
| 'websocket_error'
20+
21+
/** Metadata shapes emitted by bridgeClient trackEvent calls. */
22+
export type ChromeBridgeToolCallMetadata = {
23+
tool_name: string
24+
tool_use_id: string
25+
duration_ms?: number
26+
timeout_ms?: number
27+
error_message?: string
28+
}
29+
30+
export type ChromeBridgeConnectionFailedMetadata = {
31+
duration_ms: number
32+
error_type: ChromeBridgeConnectionErrorType
33+
reconnect_attempt: number
34+
}
35+
36+
export type ChromeBridgeConnectionStartedMetadata = {
37+
bridge_url: string
38+
}
39+
40+
export type ChromeBridgeDisconnectedMetadata = {
41+
close_code: number
42+
duration_since_connect_ms: number
43+
reconnect_attempt: number
44+
}
45+
46+
export type ChromeBridgeConnectionSucceededMetadata = {
47+
duration_ms: number
48+
status: 'paired' | 'waiting'
49+
}
50+
51+
export type ChromeBridgeReconnectExhaustedMetadata = {
52+
total_attempts: number
53+
}
54+
55+
export type ChromeBridgeTrackEventMetadata =
56+
| ChromeBridgeToolCallMetadata
57+
| ChromeBridgeConnectionFailedMetadata
58+
| ChromeBridgeConnectionStartedMetadata
59+
| ChromeBridgeDisconnectedMetadata
60+
| ChromeBridgeConnectionSucceededMetadata
61+
| ChromeBridgeReconnectExhaustedMetadata
62+
| null
63+
964
export type PermissionMode =
1065
| 'ask'
1166
| 'skip_all_permission_checks'
@@ -49,9 +104,9 @@ export interface ClaudeForChromeContext {
49104
/** If set, permission mode is sent to the extension immediately on bridge connection. */
50105
initialPermissionMode?: PermissionMode
51106
/** Optional callback to track telemetry events for bridge connections */
52-
trackEvent?: <K extends string>(
53-
eventName: K,
54-
metadata: Record<string, unknown> | null,
107+
trackEvent?: (
108+
eventName: string,
109+
metadata: ChromeBridgeTrackEventMetadata,
55110
) => void
56111
/** Called when user pairs with an extension via the browser pairing flow. */
57112
onExtensionPaired?: (deviceId: string, name: string) => void

packages/@ant/computer-use-mcp/src/pixelCompare.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
import type { ScreenshotResult } from './executor.js'
23-
import type { Logger } from './types.js'
23+
import { type Logger, toLoggerDetail } from './types.js'
2424

2525
/** Injected by the host. See `ComputerUseHostAdapter.cropRawPatch`. */
2626
export type CropRawPatchFn = (
@@ -165,7 +165,10 @@ export async function validateClickTarget(
165165
} catch (err) {
166166
// Skip validation on technical errors, execute action anyway.
167167
// Battle-tested: validation failure must never block the click.
168-
logger.debug('[pixelCompare] validation error, skipping', err)
168+
logger.debug(
169+
'[pixelCompare] validation error, skipping',
170+
toLoggerDetail(err),
171+
)
169172
return { valid: true, skipped: true }
170173
}
171174
}

packages/@ant/computer-use-mcp/src/toolCalls.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import type {
9191
ResolvedAppRequest,
9292
TeachStepRequest,
9393
} from './types.js'
94+
import { toLoggerDetail } from './types.js'
9495

9596
/**
9697
* Finder is never hidden by the hide loop (hiding Finder kills the Desktop),
@@ -4446,7 +4447,10 @@ export async function handleToolCall(
44464447
// For ungated tools, the executor may have been mid-call; that's fine —
44474448
// the result is still a tool error, never an implicit success.
44484449
const msg = err instanceof Error ? err.message : String(err)
4449-
logger.error(`[${serverName}] tool=${name} threw: ${msg}`, err)
4450+
logger.error(
4451+
`[${serverName}] tool=${name} threw: ${msg}`,
4452+
toLoggerDetail(err),
4453+
)
44504454
return errorResult(`Tool "${name}" failed: ${msg}`, 'executor_threw')
44514455
}
44524456
}

packages/@ant/computer-use-mcp/src/types.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ import type {
88
* cross-respawn `scaleCoord` survival. */
99
export type ScreenshotDims = Omit<ScreenshotResult, 'base64'>
1010

11-
/** Shape mirrors claude-for-chrome-mcp/src/types.ts:1-7 */
11+
/** Shape mirrors claude-for-chrome-mcp/src/types.ts Logger */
12+
export type LoggerDetail = Error | NodeJS.ErrnoException
13+
14+
export function toLoggerDetail(detail: unknown): LoggerDetail | undefined {
15+
return detail instanceof Error ? detail : undefined
16+
}
17+
1218
export interface Logger {
13-
info: (message: string, ...args: unknown[]) => void
14-
error: (message: string, ...args: unknown[]) => void
15-
warn: (message: string, ...args: unknown[]) => void
16-
debug: (message: string, ...args: unknown[]) => void
17-
silly: (message: string, ...args: unknown[]) => void
19+
info: (message: string, detail?: LoggerDetail) => void
20+
error: (message: string, detail?: LoggerDetail) => void
21+
warn: (message: string, detail?: LoggerDetail) => void
22+
debug: (message: string, detail?: LoggerDetail) => void
23+
silly: (message: string, detail?: LoggerDetail) => void
1824
}
1925

2026
/**

packages/@ant/ink/src/core/dom.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { EventHandlerProps } from './events/event-handlers.js'
12
import type { FocusManager } from './focus.js'
23
import { createLayoutNode } from './layout/engine.js'
34
import type { LayoutNode } from './layout/node.js'
@@ -48,7 +49,7 @@ export type DOMElement = {
4849
// Event handlers set by the reconciler for the capture/bubble dispatcher.
4950
// Stored separately from attributes so handler identity changes don't
5051
// mark dirty and defeat the blit optimization.
51-
_eventHandlers?: Record<string, unknown>
52+
_eventHandlers?: Partial<EventHandlerProps>
5253

5354
// Scroll state for overflow: 'scroll' boxes. scrollTop is the number of
5455
// rows the content is scrolled down by. scrollHeight/scrollViewportHeight

packages/@ant/ink/src/core/events/terminal-event.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export class TerminalEvent extends Event {
101101
_prepareForTarget(_target: EventTarget): void {}
102102
}
103103

104+
import type { EventHandlerProps } from './event-handlers.js'
105+
104106
export type EventTarget = {
105107
parentNode: EventTarget | undefined
106-
_eventHandlers?: Record<string, unknown>
108+
_eventHandlers?: Partial<EventHandlerProps>
107109
}

0 commit comments

Comments
 (0)