* 完善所有用到的type对象,并添加中文注释

* 补充遗失的type
This commit is contained in:
xiaoFjun-eng
2026-05-19 09:05:04 +08:00
committed by GitHub
parent c499bfb4ed
commit ea399f1862
68 changed files with 986 additions and 208 deletions

View File

@@ -60,6 +60,8 @@ import type {
SessionMessage,
SessionMutationOptions,
} from './sdk/runtimeTypes.js'
// 与 settings / hooks schema 共用的钩子事件与 SessionEnd 退出原因字面量表
import { EXIT_REASONS, HOOK_EVENTS } from './sdk/coreSchemas.js'
export type {
ListSessionsOptions,
@@ -441,5 +443,9 @@ export async function connectRemoteControl(
): Promise<RemoteControlHandle | null> {
throw new Error('not implemented')
}
export type HookEvent = any
export type ExitReason = any
/** 会话钩子事件名(与 `HOOK_EVENTS` / settings schema 一致)。 */
export type HookEvent = (typeof HOOK_EVENTS)[number] // 与 `coreSchemas.HOOK_EVENTS` 逐项对应
/** `SessionEnd` 钩子等使用的进程退出原因枚举。 */
export type ExitReason = (typeof EXIT_REASONS)[number] // 与 `coreSchemas.EXIT_REASONS` 逐项对应

View File

@@ -1,8 +1,8 @@
/**
* Stub: Generated SDK core types.
* Stub:自动生成的 SDK Core 类型。
*
* In the full build, this is auto-generated from coreSchemas.ts Zod schemas.
* Here we provide typed stubs for all the types referenced throughout the codebase.
* 在完整构建中,这些类型会基于 coreSchemas.ts 中的 Zod schema 自动生成。
* 这里提供的是类型化的 stub用于覆盖代码库中引用到的所有相关类型。
*/
import type { UUID } from 'crypto'
@@ -65,11 +65,259 @@ export type RewindFilesResult = {
// Account
export type AccountInfo = Record<string, unknown>
// Hook input types
export type HookInput = { hook_event_name: string; [key: string]: unknown }
export type HookJSONOutput = Record<string, unknown>
export type AsyncHookJSONOutput = Record<string, unknown>
export type SyncHookJSONOutput = Record<string, unknown>
// 钩子输入类型
export type HookInputBase = {
session_id: string // 会话 ID
transcript_path: string // 转录文件路径
cwd: string // 当前工作目录
permission_mode?: string // 权限模式(可选)
/** 仅在从子代理触发的钩子中存在 */
agent_id?: string
/** 在子代理钩子中存在,或在使用 --agent 启动的主线程会话中存在 */
agent_type?: string
}
export type HookInput =
| (HookInputBase & {
hook_event_name: 'PreToolUse'
tool_name: string
tool_input: unknown
tool_use_id: string
})
| (HookInputBase & {
hook_event_name: 'PermissionRequest'
tool_name: string
tool_input: unknown
permission_suggestions?: PermissionUpdate[]
})
| (HookInputBase & {
hook_event_name: 'PostToolUse'
tool_name: string
tool_input: unknown
tool_response: unknown
tool_use_id: string
})
| (HookInputBase & {
hook_event_name: 'PostToolUseFailure'
tool_name: string
tool_input: unknown
tool_use_id: string
error: string
is_interrupt?: boolean
})
| (HookInputBase & {
hook_event_name: 'PermissionDenied'
tool_name: string
tool_input: unknown
tool_use_id: string
reason: string
})
| (HookInputBase & {
hook_event_name: 'Notification'
message: string
title?: string
notification_type: string
})
| (HookInputBase & { hook_event_name: 'UserPromptSubmit'; prompt: string })
| (HookInputBase & {
hook_event_name: 'SessionStart'
source: 'startup' | 'resume' | 'clear' | 'compact'
agent_type?: string
model?: string
})
| (HookInputBase & {
hook_event_name: 'SessionEnd'
reason:
| 'clear'
| 'resume'
| 'logout'
| 'prompt_input_exit'
| 'other'
| 'bypass_permissions_disabled'
})
| (HookInputBase & {
hook_event_name: 'Setup'
trigger: 'init' | 'maintenance'
})
| (HookInputBase & {
hook_event_name: 'Stop'
stop_hook_active: boolean
last_assistant_message?: string
})
| (HookInputBase & {
hook_event_name: 'StopFailure'
error: string
error_details?: unknown
last_assistant_message?: string
})
| (HookInputBase & {
hook_event_name: 'SubagentStart'
agent_id: string
agent_type: string
})
| (HookInputBase & {
hook_event_name: 'SubagentStop'
stop_hook_active: boolean
agent_id: string
agent_transcript_path: string
agent_type: string
last_assistant_message?: string
})
| (HookInputBase & {
hook_event_name: 'PreCompact'
trigger: 'manual' | 'auto'
custom_instructions: string | null
})
| (HookInputBase & {
hook_event_name: 'PostCompact'
trigger: 'manual' | 'auto'
compact_summary: string
})
| (HookInputBase & {
hook_event_name: 'TeammateIdle'
teammate_name: string
team_name: string
})
| (HookInputBase & {
hook_event_name: 'TaskCreated'
task_id: string
task_subject: string
task_description?: string
teammate_name?: string
team_name?: string
})
| (HookInputBase & {
hook_event_name: 'TaskCompleted'
task_id: string
task_subject: string
task_description?: string
teammate_name?: string
team_name?: string
})
| (HookInputBase & {
hook_event_name: 'Elicitation'
mcp_server_name: string
message: string
mode?: 'form' | 'url'
url?: string
elicitation_id?: string
requested_schema?: Record<string, unknown>
})
| (HookInputBase & {
hook_event_name: 'ElicitationResult'
mcp_server_name: string
elicitation_id?: string
mode?: 'form' | 'url'
action: 'accept' | 'decline' | 'cancel'
content?: Record<string, unknown>
})
| (HookInputBase & {
hook_event_name: 'ConfigChange'
source:
| 'user_settings'
| 'project_settings'
| 'local_settings'
| 'policy_settings'
| 'skills'
file_path?: string
})
| (HookInputBase & {
hook_event_name: 'InstructionsLoaded'
file_path: string
memory_type: 'User' | 'Project' | 'Local' | 'Managed'
load_reason:
| 'session_start'
| 'nested_traversal'
| 'path_glob_match'
| 'include'
| 'compact'
globs?: string[]
trigger_file_path?: string
parent_file_path?: string
})
| (HookInputBase & { hook_event_name: 'WorktreeCreate'; name: string })
| (HookInputBase & {
hook_event_name: 'WorktreeRemove'
worktree_path: string
})
| (HookInputBase & {
hook_event_name: 'CwdChanged'
old_cwd: string
new_cwd: string
})
| (HookInputBase & {
hook_event_name: 'FileChanged'
file_path: string
event: 'change' | 'add' | 'unlink'
})
export type AsyncHookJSONOutput = {
async: true
asyncTimeout?: number
}
export type SyncHookJSONOutput = {
continue?: boolean
suppressOutput?: boolean
stopReason?: string
decision?: 'approve' | 'block'
systemMessage?: string
reason?: string
hookSpecificOutput?:
| {
hookEventName: 'PreToolUse'
permissionDecision?: string
permissionDecisionReason?: string
updatedInput?: Record<string, unknown>
additionalContext?: string
}
| { hookEventName: 'UserPromptSubmit'; additionalContext?: string }
| {
hookEventName: 'SessionStart'
additionalContext?: string
initialUserMessage?: string
watchPaths?: string[]
}
| { hookEventName: 'Setup'; additionalContext?: string }
| { hookEventName: 'SubagentStart'; additionalContext?: string }
| {
hookEventName: 'PostToolUse'
additionalContext?: string
updatedMCPToolOutput?: unknown
}
| { hookEventName: 'PostToolUseFailure'; additionalContext?: string }
| { hookEventName: 'PermissionDenied'; retry?: boolean }
| { hookEventName: 'Notification'; additionalContext?: string }
| {
hookEventName: 'PermissionRequest'
decision:
| {
behavior: 'allow'
updatedInput?: Record<string, unknown>
/**
* 注意:钩子使用的 JSON schema 为 PermissionUpdateSchema()
* 它是一个比传统 `{path, permission}` 结构更丰富的联合类型。
*/
updatedPermissions?: unknown[]
}
| { behavior: 'deny'; message?: string; interrupt?: boolean }
}
| {
hookEventName: 'Elicitation'
action?: 'accept' | 'decline' | 'cancel'
content?: Record<string, unknown>
}
| {
hookEventName: 'ElicitationResult'
action?: 'accept' | 'decline' | 'cancel'
content?: Record<string, unknown>
}
| { hookEventName: 'CwdChanged'; watchPaths?: string[] }
| { hookEventName: 'FileChanged'; watchPaths?: string[] }
| { hookEventName: 'WorktreeCreate'; worktreePath: string }
}
export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput
export type PreToolUseHookInput = HookInput & { tool_name: string }
export type PostToolUseHookInput = HookInput & { tool_name: string }