feat(composer): replicate WorkBuddy branch label and context usage (TODO 21)

This commit is contained in:
xiaohan.yuan committed 2026-10-17 08:15:19 +08:00
1 parent cb8a7e6466
commit bde041c12d
21 files changed
+1350 -12

No files matched your search

+6 -1
View File
@@ -10,7 +10,8 @@ import type {
GatewayConfigView,
WorkspaceInfo,
WindowState,
AppInfo
AppInfo,
GitBranchInfo
} from './types'
import type { DownloadPayload, DownloadResult, ResourceEntry, ResourceRange, WorkspaceResource } from './resources'
import type { ChatAttachment, InteractionResponse, MessageQuote, PermissionMode } from './conversation'
@@ -91,6 +92,10 @@ export interface YCodeApi {
onSettingsChanged(listener: () => void): () => void
onSettingsNavigate(listener: (section: string, action?: 'new') => void): () => void
}
git: {
/** 读取某个会话工作目录的真实分支信息;目录不在仓库内或 git 不可用时返回 repo:false/unavailable。 */
branch(sessionId: string): Ipc<GitBranchInfo>
}
config: {
get(): Ipc<GatewayConfigView>
update(patch: ConfigPatchLike): Ipc<GatewayConfigView>
+28
View File
@@ -125,11 +125,39 @@ export type ChatEvent = { sessionId?: string; turnDurationMs?: number } & (
| { runId: string; type: 'interaction'; interaction: ChatInteraction }
| { runId: string; type: 'tool_call'; call: ToolCallRecord }
| { runId: string; type: 'tool_result'; call: ToolCallRecord }
| { runId: string; type: 'usage'; usage: TokenUsage }
| { runId: string; type: 'done'; content: string; tools: ToolCallRecord[] }
| { runId: string; type: 'cancelled' }
| { runId: string; type: 'error'; message: string }
)
/**
* 上游返回的真实 token 用量(Responses `response.completed.usage`)。
* 只做透传,不做估算:拿不到就不产生该事件。
*/
export interface TokenUsage {
inputTokens: number
outputTokens: number
totalTokens: number
cachedTokens?: number
}
/**
* 会话工作目录的 Git 信息(用于对话框的分支标签)。
* `repo: false` 表示该目录不在 Git 仓库内;`detached: true` 时 `branch` 为空、`head` 为短 SHA。
*/
export interface GitBranchInfo {
/** 目录是否位于 Git 工作树内 */
repo: boolean
/** 分支名;detached HEAD 或尚无提交时为 null */
branch: string | null
detached: boolean
/** detached HEAD 的短 SHA;无提交时为 null */
head: string | null
/** git 可执行文件缺失或命令超时时为 true,UI 不显示分支标签 */
unavailable?: boolean
}
/** 一次会话的元信息 */
export interface SessionMeta {
id: string