refactor: strengthen sdk control and settings types

This commit is contained in:
2026-04-03 13:38:47 +08:00
parent f25dc3b6be
commit 097bc753f0
3 changed files with 113 additions and 13 deletions

View File

@@ -1,4 +1,3 @@
export {
SDKControlRequest,
SDKControlResponse,
} from './controlTypes.ts'
export class SDKControlRequest {}
export class SDKControlResponse {}

View File

@@ -1,14 +1,103 @@
export type SDKControlRequest = Record<string, unknown> & {
subtype?: string
import type { SDKMessage } from './coreTypes.ts'
export type SDKPermissionResponse =
| {
behavior: 'allow'
updatedInput?: Record<string, unknown>
message?: string
}
| {
behavior: 'deny' | 'ask'
message?: string
updatedInput?: Record<string, unknown>
}
export type SDKControlInterruptRequest = {
subtype: 'interrupt'
}
export type SDKControlResponse = Record<string, unknown> & {
type?: string
subtype?: string
export type SDKControlPermissionRequest = {
subtype: 'can_use_tool'
tool_name: string
input: Record<string, unknown>
permission_suggestions?: Array<Record<string, unknown>>
blocked_path?: string
decision_reason?: string
title?: string
display_name?: string
tool_use_id: string
agent_id?: string
description?: string
}
export type StdoutMessage = SDKControlResponse
export type SDKControlRequestInner =
| SDKControlInterruptRequest
| SDKControlPermissionRequest
| ({
subtype: string
} & Record<string, unknown>)
export class SDKControlRequest {}
export type SDKControlRequest = {
type: 'control_request'
request_id: string
request: SDKControlRequestInner
}
export class SDKControlResponse {}
export type SDKControlSuccessResponse = {
subtype: 'success'
request_id: string
response?: SDKPermissionResponse | Record<string, unknown>
}
export type SDKControlErrorResponse = {
subtype: 'error'
request_id: string
error: string
}
export type SDKControlResponseInner =
| SDKControlSuccessResponse
| SDKControlErrorResponse
| ({
subtype: string
request_id: string
} & Record<string, unknown>)
export type SDKControlResponse = {
type: 'control_response'
response: SDKControlResponseInner
}
export type SDKControlCancelRequest = {
type: 'control_cancel_request'
request_id: string
tool_use_id?: string
}
export type KeepAliveMessage = {
type: 'keep_alive'
[key: string]: unknown
}
export type SDKStreamlinedTextMessage = {
type: 'streamlined_text'
text: string
session_id?: string
uuid?: string
}
export type SDKStreamlinedToolUseSummaryMessage = {
type: 'streamlined_tool_use_summary'
tool_summary: string
session_id?: string
uuid?: string
}
export type StdoutMessage =
| SDKMessage
| SDKControlRequest
| SDKControlResponse
| SDKControlCancelRequest
| KeepAliveMessage
| SDKStreamlinedTextMessage
| SDKStreamlinedToolUseSummaryMessage

View File

@@ -1 +1,13 @@
export type Settings = Record<string, unknown>
export type SettingsValue =
| string
| number
| boolean
| null
| SettingsObject
| SettingsValue[]
export type SettingsObject = {
[key: string]: SettingsValue
}
export type Settings = SettingsObject