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
@@ -4,6 +4,8 @@ import type { Dispatch, ReactNode } from "react";
import { createActorContext, shallowEqual } from "@xstate/react";
import type { SnapshotFrom } from "xstate";
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
import { privateRoomMachine } from "./private-room-machine";
import type {
PrivateRoomEvent,
@@ -11,6 +13,7 @@ import type {
} from "./private-room-machine";
export interface PrivateRoomContextState {
characterId: string;
status: string;
items: MachineContext["items"];
creditBalance: number;
@@ -31,11 +34,17 @@ const PrivateRoomActorContext = createActorContext(privateRoomMachine);
export interface PrivateRoomProviderProps {
children: ReactNode;
characterId?: string;
}
export function PrivateRoomProvider({ children }: PrivateRoomProviderProps) {
export function PrivateRoomProvider({
children,
characterId = DEFAULT_CHARACTER_ID,
}: PrivateRoomProviderProps) {
return (
<PrivateRoomActorContext.Provider>{children}</PrivateRoomActorContext.Provider>
<PrivateRoomActorContext.Provider options={{ input: { characterId } }}>
{children}
</PrivateRoomActorContext.Provider>
);
}
@@ -58,6 +67,7 @@ function selectPrivateRoomState(
state: PrivateRoomSnapshot,
): PrivateRoomContextState {
return {
characterId: state.context.characterId,
status: String(state.value),
items: state.context.items,
creditBalance: state.context.creditBalance,