mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 05:45:51 +00:00
feat(remote-control): 优化 Web 展示、状态同步与桥接控制流程 (#288)
Co-authored-by: chengzifeng <chengzifeng@meituan.com>
This commit is contained in:
76
src/utils/taskStateMessage.ts
Normal file
76
src/utils/taskStateMessage.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { randomUUID } from 'crypto'
|
||||
import type { SDKMessage } from 'src/entrypoints/agentSdkTypes.js'
|
||||
import type { Task } from './tasks.js'
|
||||
|
||||
export type TaskStateItem = Pick<
|
||||
Task,
|
||||
| 'id'
|
||||
| 'subject'
|
||||
| 'description'
|
||||
| 'activeForm'
|
||||
| 'status'
|
||||
| 'owner'
|
||||
| 'blocks'
|
||||
| 'blockedBy'
|
||||
>
|
||||
|
||||
export type TaskStateMessage = SDKMessage & {
|
||||
type: 'task_state'
|
||||
uuid: string
|
||||
task_list_id: string
|
||||
tasks: TaskStateItem[]
|
||||
}
|
||||
|
||||
export type TaskStateSnapshot = Pick<
|
||||
TaskStateMessage,
|
||||
'task_list_id' | 'tasks'
|
||||
>
|
||||
|
||||
function toTaskStateItem(task: Task): TaskStateItem {
|
||||
return {
|
||||
id: task.id,
|
||||
subject: task.subject,
|
||||
description: task.description,
|
||||
activeForm: task.activeForm,
|
||||
status: task.status,
|
||||
owner: task.owner,
|
||||
blocks: [...task.blocks],
|
||||
blockedBy: [...task.blockedBy],
|
||||
}
|
||||
}
|
||||
|
||||
function compareTaskStateItems(a: TaskStateItem, b: TaskStateItem): number {
|
||||
return a.id.localeCompare(b.id)
|
||||
}
|
||||
|
||||
export function buildTaskStateSnapshot(
|
||||
taskListId: string,
|
||||
tasks: Task[],
|
||||
): TaskStateSnapshot {
|
||||
return {
|
||||
task_list_id: taskListId,
|
||||
tasks: tasks
|
||||
.filter(task => !task.metadata?._internal)
|
||||
.map(toTaskStateItem)
|
||||
.sort(compareTaskStateItems),
|
||||
}
|
||||
}
|
||||
|
||||
export function getTaskStateSnapshotKey(
|
||||
taskListId: string,
|
||||
tasks: Task[],
|
||||
): string {
|
||||
return JSON.stringify(buildTaskStateSnapshot(taskListId, tasks))
|
||||
}
|
||||
|
||||
export function buildTaskStateMessage(
|
||||
taskListId: string,
|
||||
tasks: Task[],
|
||||
): TaskStateMessage {
|
||||
const snapshot = buildTaskStateSnapshot(taskListId, tasks)
|
||||
return {
|
||||
type: 'task_state',
|
||||
uuid: randomUUID(),
|
||||
...snapshot,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user