feat: organize project conversations and add coding teacher side chat
This commit is contained in:
52
src/lib/coding-teacher.ts
Normal file
52
src/lib/coding-teacher.ts
Normal 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');
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user