style: 完成所有文件的lint

This commit is contained in:
claude-code-best
2026-05-01 21:39:30 +08:00
parent d136872cc9
commit 6182015005
1333 changed files with 68255 additions and 77882 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +1,2 @@
export * from "./types";
export * from "./client";
export * from './types'
export * from './client'

View File

@@ -1,14 +1,14 @@
import { ACPClient } from "./client";
import type { ACPSettings } from "./types";
import { getActiveApiToken } from "../api/client";
import { ACPClient } from './client'
import type { ACPSettings } from './types'
import { getActiveApiToken } from '../api/client'
/**
* Build the RCS relay WebSocket URL for a given agent.
* Uses UUID auth (same as /code/ pages).
*/
export function buildRelayUrl(agentId: string): string {
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
return `${protocol}//${window.location.host}/acp/relay/${agentId}`;
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
return `${protocol}//${window.location.host}/acp/relay/${agentId}`
}
/**
@@ -17,10 +17,10 @@ export function buildRelayUrl(agentId: string): string {
* the frontend and the target acp-link instance.
*/
export function createRelayClient(agentId: string): ACPClient {
const relayUrl = buildRelayUrl(agentId);
const token = getActiveApiToken();
const relayUrl = buildRelayUrl(agentId)
const token = getActiveApiToken()
const settings: ACPSettings = token
? { proxyUrl: relayUrl, token }
: { proxyUrl: relayUrl };
return new ACPClient(settings);
: { proxyUrl: relayUrl }
return new ACPClient(settings)
}

View File

@@ -1,33 +1,33 @@
// Permission option kinds (from ACP protocol)
export type PermissionOptionKind =
| "allow_once"
| "allow_always"
| "reject_once"
| "reject_always";
| 'allow_once'
| 'allow_always'
| 'reject_once'
| 'reject_always'
// Permission option (from ACP protocol)
export interface PermissionOption {
optionId: string;
name: string;
kind: PermissionOptionKind;
optionId: string
name: string
kind: PermissionOptionKind
}
// Permission request payload (sent from server to client)
export interface PermissionRequestPayload {
requestId: string; // Unique ID for this request (generated by server)
sessionId: string;
options: PermissionOption[];
requestId: string // Unique ID for this request (generated by server)
sessionId: string
options: PermissionOption[]
toolCall: {
toolCallId: string; // Tool call ID to match with existing tool calls
title?: string;
content?: ToolCallContent[];
};
toolCallId: string // Tool call ID to match with existing tool calls
title?: string
content?: ToolCallContent[]
}
}
// Permission response (sent from client to server)
export interface PermissionResponsePayload {
requestId: string;
outcome: { outcome: "cancelled" } | { outcome: "selected"; optionId: string };
requestId: string
outcome: { outcome: 'cancelled' } | { outcome: 'selected'; optionId: string }
}
// ============================================================================
@@ -38,129 +38,133 @@ export interface PermissionResponsePayload {
// ============================================================================
export interface BrowserToolParams {
action: "tabs" | "read" | "execute";
tabId?: number; // Required for read/execute
script?: string; // Required for execute
action: 'tabs' | 'read' | 'execute'
tabId?: number // Required for read/execute
script?: string // Required for execute
}
export interface BrowserTabInfo {
id: number;
url: string;
title: string;
active: boolean;
id: number
url: string
title: string
active: boolean
}
export interface BrowserTabsResult {
action: "tabs";
tabs: BrowserTabInfo[];
action: 'tabs'
tabs: BrowserTabInfo[]
}
export interface BrowserReadResult {
action: "read";
tabId: number;
url: string;
title: string;
dom: string;
action: 'read'
tabId: number
url: string
title: string
dom: string
viewport: {
width: number;
height: number;
scrollX: number;
scrollY: number;
};
selection: string | null;
width: number
height: number
scrollX: number
scrollY: number
}
selection: string | null
}
export interface BrowserExecuteResult {
action: "execute";
tabId: number;
url: string;
result?: unknown;
error?: string;
action: 'execute'
tabId: number
url: string
result?: unknown
error?: string
}
export type BrowserToolResult =
| BrowserTabsResult
| BrowserReadResult
| BrowserExecuteResult;
| BrowserExecuteResult
// Messages sent TO the proxy server
// Reference: Zed's MessageEditor.contents() builds Vec<acp::ContentBlock>
export type ProxyMessage =
| { type: "connect" }
| { type: "disconnect" }
| { type: "new_session"; payload?: { cwd?: string; permissionMode?: string } }
| { type: "prompt"; payload: { content: ContentBlock[] } } // Changed from { text: string } to match Zed
| { type: "cancel" }
| { type: "permission_response"; payload: PermissionResponsePayload }
| { type: "browser_tool_result"; callId: string; result: BrowserToolResult | { error: string } }
| { type: "set_session_model"; payload: { modelId: string } }
| { type: 'connect' }
| { type: 'disconnect' }
| { type: 'new_session'; payload?: { cwd?: string; permissionMode?: string } }
| { type: 'prompt'; payload: { content: ContentBlock[] } } // Changed from { text: string } to match Zed
| { type: 'cancel' }
| { type: 'permission_response'; payload: PermissionResponsePayload }
| {
type: 'browser_tool_result'
callId: string
result: BrowserToolResult | { error: string }
}
| { type: 'set_session_model'; payload: { modelId: string } }
// Session history operations - Reference: Zed's AgentSessionList trait
| { type: "list_sessions"; payload?: ListSessionsRequest }
| { type: "load_session"; payload: LoadSessionRequest }
| { type: "resume_session"; payload: ResumeSessionRequest }
| { type: 'list_sessions'; payload?: ListSessionsRequest }
| { type: 'load_session'; payload: LoadSessionRequest }
| { type: 'resume_session'; payload: ResumeSessionRequest }
// Heartbeat
| { type: "ping" };
| { type: 'ping' }
// Messages received FROM the proxy server
// Reference: Zed's AgentConnection stores agentCapabilities from initialize response
export interface ProxyStatusMessage {
type: "status";
type: 'status'
payload: {
connected: boolean;
agentInfo?: { name?: string; version?: string };
connected: boolean
agentInfo?: { name?: string; version?: string }
/** Full agent capabilities from initialize response */
capabilities?: AgentCapabilities;
};
capabilities?: AgentCapabilities
}
}
export interface ProxyErrorMessage {
type: "error";
payload: { message: string };
type: 'error'
payload: { message: string }
}
// Reference: Zed's session/initialize response includes promptCapabilities and models
export interface ProxySessionCreatedMessage {
type: "session_created";
type: 'session_created'
payload: {
sessionId: string;
promptCapabilities?: PromptCapabilities; // From agent's initialize response
models?: SessionModelState | null; // Model state if agent supports model selection
};
sessionId: string
promptCapabilities?: PromptCapabilities // From agent's initialize response
models?: SessionModelState | null // Model state if agent supports model selection
}
}
export interface ProxySessionUpdateMessage {
type: "session_update";
type: 'session_update'
payload: {
sessionId: string;
update: SessionUpdate;
};
sessionId: string
update: SessionUpdate
}
}
export interface ProxyPromptCompleteMessage {
type: "prompt_complete";
payload: { stopReason: string };
type: 'prompt_complete'
payload: { stopReason: string }
}
export interface ProxyPermissionRequestMessage {
type: "permission_request";
payload: PermissionRequestPayload;
type: 'permission_request'
payload: PermissionRequestPayload
}
export interface ProxyBrowserToolCallMessage {
type: "browser_tool_call";
callId: string;
params: BrowserToolParams;
type: 'browser_tool_call'
callId: string
params: BrowserToolParams
}
export interface ProxyPongMessage {
type: "pong";
type: 'pong'
}
export interface ProxyModelChangedMessage {
type: "model_changed";
type: 'model_changed'
payload: {
modelId: string;
};
modelId: string
}
}
// ============================================================================
@@ -173,8 +177,8 @@ export interface ProxyModelChangedMessage {
* Reference: Zed's AgentSessionListResponse
*/
export interface ProxySessionListMessage {
type: "session_list";
payload: ListSessionsResponse;
type: 'session_list'
payload: ListSessionsResponse
}
/**
@@ -182,12 +186,12 @@ export interface ProxySessionListMessage {
* Reference: Zed's load_session returns Entity<AcpThread>
*/
export interface ProxySessionLoadedMessage {
type: "session_loaded";
type: 'session_loaded'
payload: {
sessionId: string;
promptCapabilities?: PromptCapabilities;
models?: SessionModelState | null;
};
sessionId: string
promptCapabilities?: PromptCapabilities
models?: SessionModelState | null
}
}
/**
@@ -195,12 +199,12 @@ export interface ProxySessionLoadedMessage {
* Reference: Zed's resume_session returns Entity<AcpThread>
*/
export interface ProxySessionResumedMessage {
type: "session_resumed";
type: 'session_resumed'
payload: {
sessionId: string;
promptCapabilities?: PromptCapabilities;
models?: SessionModelState | null;
};
sessionId: string
promptCapabilities?: PromptCapabilities
models?: SessionModelState | null
}
}
export type ProxyResponse =
@@ -216,116 +220,123 @@ export type ProxyResponse =
// Session history responses
| ProxySessionListMessage
| ProxySessionLoadedMessage
| ProxySessionResumedMessage;
| ProxySessionResumedMessage
// Content block types (matches @agentclientprotocol/sdk ContentBlock)
// Reference: Zed's acp::ContentBlock in agent-client-protocol crate
export interface TextContent {
type: "text";
text: string;
type: 'text'
text: string
}
export interface ImageContent {
type: "image";
mimeType: string;
data: string; // base64 encoded image data
uri?: string; // optional URI for the image source
type: 'image'
mimeType: string
data: string // base64 encoded image data
uri?: string // optional URI for the image source
}
export interface ResourceLinkContent {
type: "resource_link";
uri: string;
name: string;
title?: string;
description?: string;
mimeType?: string;
size?: number;
type: 'resource_link'
uri: string
name: string
title?: string
description?: string
mimeType?: string
size?: number
}
export type ContentBlock = TextContent | ImageContent | ResourceLinkContent | { type: string; text?: string };
export type ContentBlock =
| TextContent
| ImageContent
| ResourceLinkContent
| { type: string; text?: string }
// Session update types from ACP
export interface AgentMessageChunkUpdate {
sessionUpdate: "agent_message_chunk";
content: ContentBlock;
sessionUpdate: 'agent_message_chunk'
content: ContentBlock
}
// Tool call content types from ACP
export interface ToolCallContentBlock {
type: "content";
content: ContentBlock;
type: 'content'
content: ContentBlock
}
export interface ToolCallDiffContent {
type: "diff";
path: string;
oldText?: string | null;
newText: string;
type: 'diff'
path: string
oldText?: string | null
newText: string
}
export interface ToolCallTerminalContent {
type: "terminal";
terminalId: string;
type: 'terminal'
terminalId: string
}
export type ToolCallContent = ToolCallContentBlock | ToolCallDiffContent | ToolCallTerminalContent;
export type ToolCallContent =
| ToolCallContentBlock
| ToolCallDiffContent
| ToolCallTerminalContent
export interface ToolCallUpdate {
sessionUpdate: "tool_call";
toolCallId: string;
title: string;
status: string;
content?: ToolCallContent[];
rawInput?: Record<string, unknown>;
rawOutput?: Record<string, unknown>;
sessionUpdate: 'tool_call'
toolCallId: string
title: string
status: string
content?: ToolCallContent[]
rawInput?: Record<string, unknown>
rawOutput?: Record<string, unknown>
}
export interface ToolCallStatusUpdate {
sessionUpdate: "tool_call_update";
toolCallId: string;
status?: string;
title?: string;
content?: ToolCallContent[];
rawInput?: Record<string, unknown>;
rawOutput?: Record<string, unknown>;
sessionUpdate: 'tool_call_update'
toolCallId: string
status?: string
title?: string
content?: ToolCallContent[]
rawInput?: Record<string, unknown>
rawOutput?: Record<string, unknown>
}
export interface AgentThoughtChunkUpdate {
sessionUpdate: "agent_thought_chunk";
content: ContentBlock;
sessionUpdate: 'agent_thought_chunk'
content: ContentBlock
}
export type PlanEntryPriority = "high" | "medium" | "low";
export type PlanEntryStatus = "pending" | "in_progress" | "completed";
export type PlanEntryPriority = 'high' | 'medium' | 'low'
export type PlanEntryStatus = 'pending' | 'in_progress' | 'completed'
export interface PlanEntry {
_meta?: Record<string, unknown> | null;
content: string;
priority: PlanEntryPriority;
status: PlanEntryStatus;
_meta?: Record<string, unknown> | null
content: string
priority: PlanEntryPriority
status: PlanEntryStatus
}
export interface PlanUpdate {
sessionUpdate: "plan";
_meta?: Record<string, unknown> | null;
entries: PlanEntry[];
sessionUpdate: 'plan'
_meta?: Record<string, unknown> | null
entries: PlanEntry[]
}
export interface UserMessageChunkUpdate {
sessionUpdate: "user_message_chunk";
content: ContentBlock;
sessionUpdate: 'user_message_chunk'
content: ContentBlock
}
// Available command from agent (matches ACP SDK AvailableCommand)
export interface AvailableCommand {
name: string;
description: string;
input?: { hint: string };
name: string
description: string
input?: { hint: string }
}
export interface AvailableCommandsUpdate {
sessionUpdate: "available_commands_update";
availableCommands: AvailableCommand[];
sessionUpdate: 'available_commands_update'
availableCommands: AvailableCommand[]
}
export type SessionUpdate =
@@ -335,22 +346,22 @@ export type SessionUpdate =
| AgentThoughtChunkUpdate
| PlanUpdate
| UserMessageChunkUpdate
| AvailableCommandsUpdate;
| AvailableCommandsUpdate
// Connection state
export type ConnectionState =
| "disconnected"
| "connecting"
| "connected"
| "error";
| 'disconnected'
| 'connecting'
| 'connected'
| 'error'
// PromptCapabilities from ACP protocol
// Reference: Zed's acp::PromptCapabilities in agent-client-protocol crate
// Used to check what content types the agent supports
export interface PromptCapabilities {
audio?: boolean; // Agent supports audio content
embeddedContext?: boolean; // Agent supports embedded context in prompts
image?: boolean; // Agent supports image content
audio?: boolean // Agent supports audio content
embeddedContext?: boolean // Agent supports embedded context in prompts
image?: boolean // Agent supports image content
}
// ============================================================================
@@ -365,9 +376,9 @@ export interface PromptCapabilities {
*/
export interface McpCapabilities {
/** Agent supports client-provided MCP servers */
clientServers?: boolean;
clientServers?: boolean
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
}
/**
@@ -377,7 +388,7 @@ export interface McpCapabilities {
*/
export interface SessionListCapabilities {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
}
/**
@@ -387,7 +398,7 @@ export interface SessionListCapabilities {
*/
export interface SessionResumeCapabilities {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
}
/**
@@ -397,7 +408,7 @@ export interface SessionResumeCapabilities {
*/
export interface SessionForkCapabilities {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
}
/**
@@ -411,13 +422,13 @@ export interface SessionForkCapabilities {
*/
export interface SessionCapabilities {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** @experimental Agent supports forking sessions via session/fork */
fork?: SessionForkCapabilities | null;
fork?: SessionForkCapabilities | null
/** @experimental Agent supports listing sessions via session/list */
list?: SessionListCapabilities | null;
list?: SessionListCapabilities | null
/** @experimental Agent supports resuming sessions via session/resume */
resume?: SessionResumeCapabilities | null;
resume?: SessionResumeCapabilities | null
}
/**
@@ -428,15 +439,15 @@ export interface SessionCapabilities {
*/
export interface AgentCapabilities {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** Whether the agent supports session/load */
loadSession?: boolean;
loadSession?: boolean
/** MCP capabilities supported by the agent */
mcpCapabilities?: McpCapabilities;
mcpCapabilities?: McpCapabilities
/** Prompt capabilities supported by the agent */
promptCapabilities?: PromptCapabilities;
promptCapabilities?: PromptCapabilities
/** Session capabilities supported by the agent */
sessionCapabilities?: SessionCapabilities;
sessionCapabilities?: SessionCapabilities
}
// ============================================================================
@@ -454,15 +465,15 @@ export interface AgentCapabilities {
*/
export interface AgentSessionInfo {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** Working directory for the session (required per SDK) */
cwd: string;
cwd: string
/** Unique identifier for the session */
sessionId: string;
sessionId: string
/** Human-readable title for the session */
title?: string | null;
title?: string | null
/** ISO 8601 timestamp when the session was last updated */
updatedAt?: string | null;
updatedAt?: string | null
}
/**
@@ -471,11 +482,11 @@ export interface AgentSessionInfo {
*/
export interface ListSessionsRequest {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** Filter sessions by working directory */
cwd?: string;
cwd?: string
/** Pagination cursor for fetching more results */
cursor?: string;
cursor?: string
}
/**
@@ -484,11 +495,11 @@ export interface ListSessionsRequest {
*/
export interface ListSessionsResponse {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** Cursor for fetching the next page of results */
nextCursor?: string | null;
nextCursor?: string | null
/** Array of session info objects */
sessions: AgentSessionInfo[];
sessions: AgentSessionInfo[]
}
/**
@@ -497,11 +508,11 @@ export interface ListSessionsResponse {
*/
export interface LoadSessionRequest {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** Session ID to load */
sessionId: string;
sessionId: string
/** Working directory for the session */
cwd?: string;
cwd?: string
}
/**
@@ -510,11 +521,11 @@ export interface LoadSessionRequest {
*/
export interface ResumeSessionRequest {
/** Reserved for extensibility */
_meta?: Record<string, unknown> | null;
_meta?: Record<string, unknown> | null
/** Session ID to resume */
sessionId: string;
sessionId: string
/** Working directory for the session */
cwd?: string;
cwd?: string
}
// ============================================================================
@@ -528,11 +539,11 @@ export interface ResumeSessionRequest {
*/
export interface ModelInfo {
/** Unique identifier for the model */
modelId: string;
modelId: string
/** Human-readable name of the model */
name: string;
name: string
/** Optional description of the model */
description?: string | null;
description?: string | null
}
/**
@@ -541,20 +552,20 @@ export interface ModelInfo {
*/
export interface SessionModelState {
/** The set of models that the Agent can use */
availableModels: ModelInfo[];
availableModels: ModelInfo[]
/** The current model the Agent is using */
currentModelId: string;
currentModelId: string
}
// Settings
export interface ACPSettings {
proxyUrl: string;
proxyUrl: string
/** Auth token for remote access (sent via WebSocket subprotocol) */
token?: string;
token?: string
/** Working directory for the agent session */
cwd?: string;
cwd?: string
}
export const DEFAULT_SETTINGS: ACPSettings = {
proxyUrl: "ws://localhost:9315/ws",
};
proxyUrl: 'ws://localhost:9315/ws',
}