chore: establish YCode replication baseline and TODO

This commit is contained in:
xiaohan.yuan committed 2026-10-17 02:43:49 +08:00
commit 6dc59f89ba
1118 files changed
+196002

No files matched your search

+149
View File
@@ -0,0 +1,149 @@
/**
* IPC 契约(主进程与 preload 共享)。
* 放在 shared 下,避免主进程反向依赖 electron 类型。
*/
import type {
ChatMessage,
ChatEvent,
SessionMeta,
GatewayConfigView,
WorkspaceInfo,
WindowState,
AppInfo
} from './types'
import type { DownloadPayload, DownloadResult, ResourceEntry, ResourceRange, WorkspaceResource } from './resources'
import type { ChatAttachment, InteractionResponse, PermissionMode } from './conversation'
import type { CustomModelInput, ModelRegistryView, ModelTestResult } from './models'
import type { SessionContext, WorkspaceRegistryView } from './workspaces'
import type { BrowserHostApi } from './browser-host'
import type { TerminalHostApi } from './terminal-host'
import type { ExpertsApi, McpApi, SkillsApi } from './capabilities'
export interface ConfigPatchLike {
speechBaseUrl?: string
speechModel?: string
baseUrl?: string
model?: string
temperature?: number
maxToolRounds?: number
apiKey?: string
}
export type EditAction = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'selectAll'
export interface SendPayload {
skillIds?: string[]
planId?: string
resources?: string[]
sessionId: string
text: string
attachments?: ChatAttachment[]
permissionMode?: PermissionMode
/** Retry/edit from this message; descendants are preserved in an archived branch. */
fromMessageId?: string
action?: 'edit' | 'resend' | 'regenerate'
}
export interface SendResult {
runId: string
assistantMessageId: string
/** Frozen identity of the model selected when this assistant turn started. */
modelId?: string
modelName?: string
assistantDisplay?: import('./capabilities').ExpertBinding
userMessage: ChatMessage
messages?: ChatMessage[]
}
/** 统一的返回包装,便于渲染进程处理错误而不炸掉 UI */
export type Ipc<T> = Promise<T>
/** A cancelled folder picker has no attached ID, even when the registry has a selection. */
export interface WorkspaceAttachResult extends WorkspaceRegistryView {
attachedWorkspaceId?: string
}
/** preload 暴露给渲染进程的 API 形状 */
export interface YCodeApi {
experts: ExpertsApi
skills: SkillsApi
mcp: McpApi
browser: BrowserHostApi
terminal: TerminalHostApi
window: {
minimize(): Ipc<void>
toggleMaximize(): Ipc<{ maximized: boolean }>
close(): Ipc<void>
getState(): Ipc<WindowState>
onState(listener: (state: WindowState) => void): () => void
onFocus(listener: (focused: boolean) => void): () => void
}
edit: {
action(action: EditAction): Ipc<void>
}
app: {
info(): Ipc<AppInfo>
openConfigDir(): Ipc<void>
openSettings(section?: string, action?: 'new'): Ipc<void>
onSettingsChanged(listener: () => void): () => void
onSettingsNavigate(listener: (section: string, action?: 'new') => void): () => void
}
config: {
get(): Ipc<GatewayConfigView>
update(patch: ConfigPatchLike): Ipc<GatewayConfigView>
}
workspace: {
get(): Ipc<WorkspaceInfo>
choose(): Ipc<WorkspaceInfo & { changed: boolean }>
list(): Ipc<WorkspaceRegistryView>
generate(name: string): Ipc<WorkspaceRegistryView>
attach(path?: string): Ipc<WorkspaceAttachResult>
select(id: string | null): Ipc<WorkspaceRegistryView>
rename(id: string, name: string): Ipc<WorkspaceRegistryView>
remove(id: string): Ipc<WorkspaceRegistryView>
open(id: string): Ipc<void>
}
models: {
list(): Ipc<ModelRegistryView>
save(input: CustomModelInput, overwrite?: boolean): Ipc<ModelRegistryView>
remove(id: string): Ipc<ModelRegistryView>
select(id: string | null): Ipc<ModelRegistryView>
test(input: CustomModelInput): Ipc<ModelTestResult>
}
resources: {
list(sessionId?: string, workspaceId?: string): Ipc<ResourceEntry[]>
openExternal(url: string): Ipc<void>
read(path: string, range?: ResourceRange, sessionId?: string): Ipc<WorkspaceResource>
readText(path: string, sessionId?: string): Ipc<string>
classify(path: string, sessionId?: string): Ipc<'file' | 'directory' | 'unknown'>
resolveImage(source: string, sessionId?: string): Ipc<string | undefined>
download(payload: DownloadPayload): Ipc<DownloadResult>
downloadImage(source: string, filename?: string, sessionId?: string): Ipc<DownloadResult>
}
attachments: {
pick(): Ipc<ChatAttachment[]>
stage(payload: { name: string; mimeType: string; dataBase64: string }): Ipc<ChatAttachment>
remove(id: string): Ipc<void>
}
speech: {
transcribe(payload: { audioBase64: string; mimeType: string }): Ipc<{ text: string }>
}
session: {
list(): Ipc<SessionMeta[]>
create(title?: string, context?: SessionContext): Ipc<SessionMeta>
updateContext(id: string, context: SessionContext): Ipc<SessionMeta>
messages(sessionId: string): Ipc<ChatMessage[]>
rename(sessionId: string, title: string): Ipc<void>
remove(sessionId: string): Ipc<void>
}
chat: {
revert(sessionId: string, userMessageId: string): Ipc<{ messages: ChatMessage[] }>
feedback(sessionId: string, messageId: string, value: 'like' | 'dislike'): Ipc<void>
send(payload: SendPayload): Ipc<SendResult>
cancel(runId: string): Ipc<{ cancelled: boolean }>
respond(runId: string, interactionId: string, response: InteractionResponse): Ipc<{ accepted: boolean }>
/** 返回取消订阅函数 */
onEvent(listener: (event: ChatEvent) => void): () => void
}
}