| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import type { |
| AgentMeta as V2AgentMeta, |
| SessionMeta as V2SessionMeta, |
| SessionSummary as V2SessionSummary, |
| } from '@moonshot-ai/agent-core-v2'; |
|
|
| import { resolve, win32 } from 'node:path'; |
|
|
| import type { AgentMeta, SessionMeta } from '#/replay'; |
| import type { JsonObject, SessionSummary } from '#/types'; |
|
|
| |
| |
| |
| |
| |
| export function normalizeWorkDir(workDir: string): string { |
| if (/^[A-Za-z]:[\\/]/.test(workDir) || /^[\\/]{2}[^\\/]+[\\/][^\\/]+/.test(workDir)) { |
| return win32.resolve(workDir).replaceAll('\\', '/'); |
| } |
| return resolve(workDir); |
| } |
|
|
| |
| export interface SessionSummaryFacts { |
| readonly workDir: string; |
| readonly sessionDir: string; |
| readonly additionalDirs?: readonly string[]; |
| } |
|
|
| export function v2SummaryToSessionSummary( |
| summary: V2SessionSummary, |
| facts: SessionSummaryFacts, |
| ): SessionSummary { |
| return { |
| id: summary.id, |
| title: summary.title, |
| lastPrompt: summary.lastPrompt, |
| workDir: facts.workDir, |
| sessionDir: facts.sessionDir, |
| createdAt: summary.createdAt, |
| updatedAt: summary.updatedAt, |
| archived: summary.archived, |
| metadata: summary.custom as JsonObject | undefined, |
| additionalDirs: facts.additionalDirs, |
| lastTurnReason: summary.lastTurnReason, |
| }; |
| } |
|
|
| |
| |
| |
| |
| |
| export function v2MetaToSessionMeta(meta: V2SessionMeta): SessionMeta { |
| return { |
| createdAt: new Date(meta.createdAt).toISOString(), |
| updatedAt: new Date(meta.updatedAt).toISOString(), |
| title: meta.title ?? '', |
| isCustomTitle: meta.titleKind === 'custom', |
| lastPrompt: meta.lastPrompt, |
| forkedFrom: meta.forkedFrom, |
| workDir: meta.cwd, |
| agents: v2AgentsToV1(meta.agents ?? {}), |
| custom: (meta.custom ?? {}) as Record<string, unknown>, |
| }; |
| } |
|
|
| function v2AgentsToV1(agents: Readonly<Record<string, V2AgentMeta>>): Record<string, AgentMeta> { |
| const mapped: Record<string, AgentMeta> = {}; |
| for (const [agentId, agent] of Object.entries(agents)) { |
| mapped[agentId] = { |
| homedir: agent.homedir, |
| |
| |
| type: agent.type ?? (agentId === 'main' ? 'main' : 'sub'), |
| |
| |
| parentAgentId: agent.parentAgentId ?? null, |
| swarmItem: agent.swarmItem, |
| }; |
| } |
| return mapped; |
| } |
|
|