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

52
src/lib/coding-teacher.ts Normal file
View File

@@ -0,0 +1,52 @@
import { hostApiFetch, createHostEventSource, ensureHostApiToken } from './host-api';
import type {
TeacherAvailability,
TeacherDefinition,
TeacherSend,
TeacherTopic,
TeacherTopicList,
} from '../../shared/coding-teacher';
export function teacherTopicsPath(projectId: string, sourceId: string) {
return projectId === 'preview'
? '/api/coding/teacher-preview/topics'
: `/api/coding/projects/${encodeURIComponent(projectId)}/conversations/${encodeURIComponent(sourceId)}/teacher-topics`;
}
export const teacherApi = {
config: () =>
hostApiFetch<TeacherAvailability & { definition: TeacherDefinition | null }>(
'/api/coding/teacher/config'
),
preview: (draftRevision: number) =>
hostApiFetch<{ payload: TeacherDefinition; draft_revision: number }>(
'/api/coding/teacher-preview?draftRevision=' + draftRevision
),
list: (base: string) => hostApiFetch<TeacherTopicList>(base),
create: (base: string, draftRevision?: number, sampleContext?: string) =>
hostApiFetch<TeacherTopic>(base, {
method: 'POST',
body: JSON.stringify({ draftRevision, sampleContext }),
}),
read: (base: string, id: string) =>
hostApiFetch<TeacherTopic>(base + '/' + encodeURIComponent(id)),
send: (base: string, id: string, input: TeacherSend) =>
hostApiFetch<TeacherTopic>(base + '/' + encodeURIComponent(id) + '/messages', {
method: 'POST',
body: JSON.stringify(input),
}),
cancel: (base: string, id: string, requestId: string) =>
hostApiFetch<TeacherTopic>(
base +
'/' +
encodeURIComponent(id) +
'/requests/' +
encodeURIComponent(requestId) +
'/cancel',
{ method: 'POST' }
),
save: (base: string, id: string) =>
hostApiFetch<TeacherTopic>(base + '/' + encodeURIComponent(id) + '/save', { method: 'POST' }),
async events(base: string, id: string) {
await ensureHostApiToken();
return createHostEventSource(base + '/' + encodeURIComponent(id) + '/events');
},
};