Unify protocol types and modes

This commit is contained in:
weishu
2026-01-03 14:43:59 +08:00
parent bfca058967
commit e2028b6914
20 changed files with 360 additions and 393 deletions
+10 -67
View File
@@ -1,13 +1,12 @@
export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'read-only' | 'safe-yolo' | 'yolo'
export type ModelMode = 'default' | 'sonnet' | 'opus'
import type {
DecryptedMessage as ProtocolDecryptedMessage,
ModelMode,
Session,
SyncEvent as ProtocolSyncEvent,
WorktreeMetadata
} from '@hapi/protocol/types'
export type WorktreeMetadata = {
basePath: string
branch: string
name: string
worktreePath?: string
createdAt?: number
}
export type { AgentState, ModelMode, PermissionMode, Session, TodoItem, WorktreeMetadata } from '@hapi/protocol/types'
export type SessionMetadataSummary = {
path: string
@@ -22,51 +21,6 @@ export type SessionMetadataSummary = {
worktree?: WorktreeMetadata
}
export type AgentStateRequest = {
tool: string
arguments: unknown
createdAt?: number | null
}
export type AgentStateCompletedRequest = {
tool: string
arguments: unknown
createdAt?: number | null
completedAt?: number | null
status: 'canceled' | 'denied' | 'approved'
reason?: string
mode?: string
decision?: 'approved' | 'approved_for_session' | 'denied' | 'abort'
allowTools?: string[]
answers?: Record<string, string[]>
}
export type AgentState = {
controlledByUser?: boolean | null
requests?: Record<string, AgentStateRequest> | null
completedRequests?: Record<string, AgentStateCompletedRequest> | null
}
export type TodoItem = {
content: string
status: 'pending' | 'in_progress' | 'completed'
priority: 'high' | 'medium' | 'low'
id: string
}
export type Session = {
id: string
createdAt: number
updatedAt: number
active: boolean
thinking: boolean
metadata: SessionMetadataSummary | null
agentState: AgentState | null
todos?: TodoItem[]
permissionMode?: PermissionMode
modelMode?: ModelMode
}
export type SessionSummaryMetadata = {
name?: string
path: string
@@ -89,12 +43,7 @@ export type SessionSummary = {
export type MessageStatus = 'sending' | 'sent' | 'failed'
export type DecryptedMessage = {
id: string
seq: number | null
localId: string | null
content: unknown
createdAt: number
export type DecryptedMessage = ProtocolDecryptedMessage & {
status?: MessageStatus
originalText?: string
}
@@ -216,10 +165,4 @@ export type PushVapidPublicKeyResponse = {
publicKey: string
}
export type SyncEvent =
| { type: 'session-added'; sessionId: string; data?: unknown; namespace?: string }
| { type: 'session-updated'; sessionId: string; data?: unknown; namespace?: string }
| { type: 'session-removed'; sessionId: string; namespace?: string }
| { type: 'message-received'; sessionId: string; message: DecryptedMessage; namespace?: string }
| { type: 'machine-updated'; machineId: string; data?: unknown; namespace?: string }
| { type: 'connection-changed'; data?: { status: string }; namespace?: string }
export type SyncEvent = ProtocolSyncEvent