refactor(chat): split machine and repository flows

This commit is contained in:
2026-06-30 19:16:33 +08:00
parent d33c34d751
commit ed109f25a0
12 changed files with 908 additions and 730 deletions
@@ -0,0 +1,49 @@
"use client";
import {
ChatHistoryResponse,
ChatSendResponse,
SendMessageRequest,
UnlockHistoryResponse,
UnlockPrivateRequest,
UnlockPrivateResponse,
} from "@/data/dto/chat";
import type { ChatApi } from "@/data/services/api";
import { Result } from "@/utils";
export class ChatRemoteDataSource {
constructor(private readonly api: ChatApi) {}
async sendMessage(
message: string,
options?: { image?: string; useWebSocket?: boolean },
): Promise<Result<ChatSendResponse>> {
return Result.wrap(async () => {
const request = SendMessageRequest.from({
message,
image: options?.image ?? "",
useWebSocket: options?.useWebSocket ?? false,
});
return await this.api.sendMessage(request);
});
}
async getHistory(
limit = 50,
offset = 0,
): Promise<Result<ChatHistoryResponse>> {
return Result.wrap(() => this.api.getHistory(limit, offset));
}
async unlockPrivateMessage(
messageId: string,
): Promise<Result<UnlockPrivateResponse>> {
return Result.wrap(() =>
this.api.unlockPrivateMessage(UnlockPrivateRequest.from({ messageId })),
);
}
async unlockHistory(): Promise<Result<UnlockHistoryResponse>> {
return Result.wrap(() => this.api.unlockHistory());
}
}