feat(characters): support character-scoped conversations

This commit is contained in:
2026-07-17 11:42:31 +08:00
parent 93efcb6604
commit 2796010971
85 changed files with 1645 additions and 251 deletions
@@ -9,11 +9,14 @@ import type { LoadMoreHistoryActorEvent } from "@/stores/chat/machine/actors/his
import {
createLoadHistoryCallback,
createTestChatMachine,
TEST_CHAT_MACHINE_INPUT,
} from "./chat-machine.test-utils";
describe("chat history flow", () => {
it("enters user ready after history is loaded", async () => {
const actor = createActor(createTestChatMachine()).start();
const actor = createActor(createTestChatMachine(), {
input: TEST_CHAT_MACHINE_INPUT,
}).start();
actor.send({ type: "ChatUserLogin", token: "token" });
await waitFor(actor, (snapshot) =>
@@ -45,7 +48,10 @@ describe("chat history flow", () => {
};
const machine = chatMachine.provide({
actors: {
loadHistory: fromCallback<ChatEvent>(({ sendBack }) => {
loadHistory: fromCallback<
ChatEvent,
{ characterId: string }
>(({ sendBack }) => {
sendBack({
type: "ChatLocalHistoryLoaded",
output: {
@@ -70,7 +76,9 @@ describe("chat history flow", () => {
}),
},
});
const actor = createActor(machine).start();
const actor = createActor(machine, {
input: TEST_CHAT_MACHINE_INPUT,
}).start();
actor.send({ type: "ChatUserLogin", token: "token" });
await waitFor(actor, (snapshot) =>
@@ -109,7 +117,10 @@ describe("chat history flow", () => {
[latestMessage],
{ total: 120, limit: 50 },
),
loadMoreHistory: fromCallback<LoadMoreHistoryActorEvent>(
loadMoreHistory: fromCallback<
LoadMoreHistoryActorEvent,
{ characterId: string }
>(
({ receive, sendBack }) => {
receive((event) => {
requests.push(event);
@@ -143,7 +154,9 @@ describe("chat history flow", () => {
),
},
});
const actor = createActor(machine).start();
const actor = createActor(machine, {
input: TEST_CHAT_MACHINE_INPUT,
}).start();
actor.send({ type: "ChatUserLogin", token: "token" });
await waitFor(actor, (snapshot) =>
@@ -183,7 +196,10 @@ describe("chat history flow", () => {
total: 75,
limit: 50,
}),
loadMoreHistory: fromCallback<LoadMoreHistoryActorEvent>(
loadMoreHistory: fromCallback<
LoadMoreHistoryActorEvent,
{ characterId: string }
>(
({ receive, sendBack }) => {
receive((event) => {
requestCount += 1;
@@ -209,7 +225,9 @@ describe("chat history flow", () => {
),
},
});
const actor = createActor(machine).start();
const actor = createActor(machine, {
input: TEST_CHAT_MACHINE_INPUT,
}).start();
actor.send({ type: "ChatGuestLogin" });
await waitFor(actor, (snapshot) =>
@@ -240,7 +258,10 @@ describe("chat history flow", () => {
total: 50,
limit: 50,
}),
loadMoreHistory: fromCallback<LoadMoreHistoryActorEvent>(
loadMoreHistory: fromCallback<
LoadMoreHistoryActorEvent,
{ characterId: string }
>(
({ receive }) => {
receive(() => {
requested = true;
@@ -250,7 +271,9 @@ describe("chat history flow", () => {
),
},
});
const actor = createActor(machine).start();
const actor = createActor(machine, {
input: TEST_CHAT_MACHINE_INPUT,
}).start();
actor.send({ type: "ChatUserLogin", token: "token" });
await waitFor(actor, (snapshot) =>