Merge project conversations and cloud coding teacher into main

This commit is contained in:
2026-09-22 13:54:50 +08:00
45 changed files with 2987 additions and 1137 deletions

View File

@@ -66,6 +66,7 @@ const moduleAccessKeyById: Record<AiModuleId, ModuleAccessKey> = {
};
const PROGRAMMING_ROUTE_PREFIXES = [
'/coding-teacher-preview',
'/plugins',
'/plugin-marketplace',
'/my-plugins',

View File

@@ -106,7 +106,7 @@ export async function listCodingProjectConversations(
export async function createCodingProjectConversation(input: {
projectId: string;
agentId: string;
agentId?: string;
title: string;
}): Promise<CodingConversationMetadata> {
const response = await hostApiFetch<{ conversation: CodingConversationMetadata }>(

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');
},
};