feat: organize project conversations and add coding teacher side chat

This commit is contained in:
2026-09-22 12:30:26 +08:00
parent 2f82b9f79c
commit 9242a40d87
45 changed files with 2987 additions and 1137 deletions

View File

@@ -0,0 +1,33 @@
import type { CodingProjectService } from '../coding-projects/project-service';
import type { CodingConversationRuntime } from '../coding-runtime/contracts';
import { readCodingConversationHistory } from '../coding-projects/conversation-history';
import { sourceContext } from './context';
import { TeacherError } from './config-client';
import type { TeacherSourceContext } from '../../shared/coding-teacher';
export async function readTeacherSource(
projects: CodingProjectService,
runtime: CodingConversationRuntime,
userDataDir: string,
projectId: string,
sourceId: string
): Promise<TeacherSourceContext> {
const project = await projects.getProject(projectId);
const conversation = await projects.conversationStore(project.path).get(sourceId);
if (!conversation) throw new TeacherError(404, 'teacher_source_not_found', '来源会话不存在。');
try {
const snapshot = await runtime.getSnapshot(sourceId);
if (snapshot.conversation.projectId === projectId) return sourceContext(snapshot);
} catch {
/* Cold history does not require a running worker. */
}
try {
return sourceContext(await readCodingConversationHistory(userDataDir, projectId, conversation));
} catch {
throw new TeacherError(
409,
'teacher_source_unreadable',
'暂时无法读取来源会话,请先打开该会话。'
);
}
}