mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 22:35:51 +00:00
feat(remote-control): 优化 Web 展示、状态同步与桥接控制流程 (#288)
Co-authored-by: chengzifeng <chengzifeng@meituan.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { PermissionUpdate } from '../utils/permissions/PermissionUpdateSchema.js'
|
||||
import type { SDKControlResponse } from '../entrypoints/sdk/controlTypes.js'
|
||||
|
||||
type BridgePermissionResponse = {
|
||||
behavior: 'allow' | 'deny'
|
||||
@@ -39,5 +40,65 @@ function isBridgePermissionResponse(
|
||||
)
|
||||
}
|
||||
|
||||
export { isBridgePermissionResponse }
|
||||
function toBridgePermissionMessage(
|
||||
controlResponse: Record<string, unknown>,
|
||||
parsed: BridgePermissionResponse | undefined,
|
||||
): string | undefined {
|
||||
if (typeof controlResponse.message === 'string' && controlResponse.message) {
|
||||
return controlResponse.message
|
||||
}
|
||||
if (typeof parsed?.message === 'string' && parsed.message) {
|
||||
return parsed.message
|
||||
}
|
||||
if (typeof controlResponse.error === 'string' && controlResponse.error) {
|
||||
return controlResponse.error
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a control_response from the bridge transport into the simplified
|
||||
* allow/deny shape used by interactive permission handlers.
|
||||
*/
|
||||
function parseBridgePermissionResponse(
|
||||
message: SDKControlResponse,
|
||||
): BridgePermissionResponse | null {
|
||||
const controlResponse = message.response
|
||||
if (!controlResponse || typeof controlResponse !== 'object') return null
|
||||
|
||||
if (
|
||||
controlResponse.subtype === 'success' &&
|
||||
'response' in controlResponse &&
|
||||
isBridgePermissionResponse(controlResponse.response)
|
||||
) {
|
||||
return controlResponse.response
|
||||
}
|
||||
|
||||
if (controlResponse.subtype !== 'error') {
|
||||
return null
|
||||
}
|
||||
|
||||
const nested =
|
||||
'response' in controlResponse &&
|
||||
isBridgePermissionResponse(controlResponse.response)
|
||||
? controlResponse.response
|
||||
: undefined
|
||||
|
||||
const messageText = toBridgePermissionMessage(controlResponse, nested)
|
||||
|
||||
if (nested) {
|
||||
return messageText ? { ...nested, message: messageText } : nested
|
||||
}
|
||||
|
||||
if (messageText) {
|
||||
return {
|
||||
behavior: 'deny',
|
||||
message: messageText,
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export { isBridgePermissionResponse, parseBridgePermissionResponse }
|
||||
export type { BridgePermissionCallbacks, BridgePermissionResponse }
|
||||
|
||||
Reference in New Issue
Block a user