feat: 工作台聊天室功能

This commit is contained in:
2026-05-31 02:37:23 +08:00
parent 83cf9eab94
commit f83f434863
33 changed files with 2520 additions and 265 deletions

View File

@@ -0,0 +1,45 @@
import type {
Conversation,
ConversationListResponse,
ConversationResponse,
MessageListResponse,
} from "../../shared/api";
import { handleResponse, handleVoidResponse } from "../utils/api";
export async function createConversation(projectId: string, modelId?: string): Promise<Conversation> {
const response = await fetch(`/api/projects/${projectId}/conversations`, {
body: JSON.stringify({ modelId }),
headers: { "Content-Type": "application/json" },
method: "POST",
});
return handleResponse(response, (data) => (data as ConversationResponse).conversation);
}
export async function deleteConversation(projectId: string, conversationId: string): Promise<void> {
const response = await fetch(`/api/projects/${projectId}/conversations/${conversationId}`, { method: "DELETE" });
return handleVoidResponse(response);
}
export async function fetchConversation(projectId: string, conversationId: string): Promise<Conversation> {
const response = await fetch(`/api/projects/${projectId}/conversations/${conversationId}`);
return handleResponse(response, (data) => (data as ConversationResponse).conversation);
}
export async function fetchConversations(projectId: string): Promise<ConversationListResponse> {
const response = await fetch(`/api/projects/${projectId}/conversations?pageSize=100`);
if (!response.ok) {
const body = (await response.json().catch(() => null)) as null | { error?: string };
throw new Error(body?.error ?? `HTTP ${response.status}`);
}
return response.json() as Promise<ConversationListResponse>;
}
export async function fetchMessages(projectId: string, conversationId: string): Promise<MessageListResponse> {
const response = await fetch(`/api/projects/${projectId}/conversations/${conversationId}/messages?pageSize=200`);
if (!response.ok) {
const body = (await response.json().catch(() => null)) as null | { error?: string };
throw new Error(body?.error ?? `HTTP ${response.status}`);
}
return response.json() as Promise<MessageListResponse>;
}