Files
Genarrative/apps/ai-game-creator-shell/src/features/app-shell/useDeveloperAgentState.ts
T
kdletters 578f8019fc
Project CI / Repository checks (push) Successful in 1m14s
Project CI / Frontend tests (push) Successful in 3m9s
Project CI / Backend tests (push) Successful in 3m58s
Project CI / Native shell tests (push) Successful in 14m6s
优化AGC项目入口并识别Godot工作区
项目页只保留打开项目和新建项目并统一原生目录选择
按根目录及一层子目录识别project.godot并记录相对Godot根
保持.agent位于用户选择的工作区根并补齐Windows构建门禁
补充响应式布局、测试、技术方案和共享项目记忆
2026-08-14 21:53:43 +08:00

166 lines
6.2 KiB
TypeScript

import { useRef, useState } from 'react';
import { seedManifest } from '../../app/constants';
import type {
AgentBackgroundSubmitMode,
AgentChatInteractionMode,
AgentChatPendingRuntimeRun,
AgentChatReplyPhase,
AgentConversationSessionRecord,
AgentGoalDialogState,
AgentGoalRecord,
AgentRuntimeState,
GameCreatorLlmConfigStatus,
LocalConversationMessageRecord,
TauriInvoke,
} from '../../app/types';
import { deriveAgentStatusCards } from '../project-summary/agentPresentation';
export function useDeveloperAgentState() {
const launcherAgentChatAgents = deriveAgentStatusCards(seedManifest, null);
const [agentChatProjectPath, setAgentChatProjectPath] = useState('');
const [agentChatSelectedAgentId, setAgentChatSelectedAgentId] = useState(
launcherAgentChatAgents[0]?.id ?? '',
);
const [agentChatMessages, setAgentChatMessages] = useState<
LocalConversationMessageRecord[]
>([]);
const [agentChatSessions, setAgentChatSessions] = useState<
AgentConversationSessionRecord[]
>([]);
const [agentChatSelectedSessionId, setAgentChatSelectedSessionId] = useState<
string | null
>(null);
const [agentChatActiveSessionId, setAgentChatActiveSessionId] = useState<
string | null
>(null);
const [agentChatLegacySessionMode, setAgentChatLegacySessionMode] =
useState(false);
const [agentChatConversationPath, setAgentChatConversationPath] =
useState('');
const [agentChatSessionStatus, setAgentChatSessionStatus] = useState('');
const [agentChatInput, setAgentChatInput] = useState('');
const [agentChatInteractionMode, setAgentChatInteractionMode] =
useState<AgentChatInteractionMode>('run');
const [agentChatRunSubmitMode, setAgentChatRunSubmitMode] =
useState<AgentBackgroundSubmitMode>('steer');
const [agentChatReplyPhase, setAgentChatReplyPhase] =
useState<AgentChatReplyPhase>('idle');
const [agentChatStatus, setAgentChatStatus] = useState('请选择项目和 Agent');
const [agentChatBusy, setAgentChatBusy] = useState(false);
const agentChatMessagesRef = useRef<HTMLDivElement | null>(null);
const agentChatShouldFollowLatestRef = useRef(true);
const [agentChatBackgroundBusy, setAgentChatBackgroundBusy] = useState(false);
const [agentChatPendingRuntimeRun, setAgentChatPendingRuntimeRunState] =
useState<AgentChatPendingRuntimeRun | null>(null);
const [agentChatLlmConfigStatus, setAgentChatLlmConfigStatus] =
useState<GameCreatorLlmConfigStatus | null>(null);
const [agentChatLlmStatus, setAgentChatLlmStatus] =
useState('尚未检查 LLM 配置');
const [agentChatRuntime, setAgentChatRuntime] =
useState<AgentRuntimeState | null>(null);
const [agentChatActiveRuntime, setAgentChatActiveRuntime] =
useState<AgentRuntimeState | null>(null);
const [agentChatRuntimeError, setAgentChatRuntimeError] = useState('');
const [agentChatGoal, setAgentChatGoal] = useState<AgentGoalRecord | null>(
null,
);
const [agentChatGoalError, setAgentChatGoalError] = useState('');
const [agentChatGoalDialog, setAgentChatGoalDialog] =
useState<AgentGoalDialogState | null>(null);
const [agentChatGoalDialogError, setAgentChatGoalDialogError] = useState('');
const [agentChatResumeConfirmation, setAgentChatResumeConfirmation] =
useState<{ projectPath: string; detail: string } | null>(null);
const agentChatLoadVersionRef = useRef(0);
const agentChatRuntimeResumeProjectPathRef = useRef<string | null>(null);
const agentChatProjectPathRef = useRef(agentChatProjectPath);
agentChatProjectPathRef.current = agentChatProjectPath;
const agentChatSelectedAgentIdRef = useRef(agentChatSelectedAgentId);
agentChatSelectedAgentIdRef.current = agentChatSelectedAgentId;
const agentChatSelectedSessionIdRef = useRef(agentChatSelectedSessionId);
agentChatSelectedSessionIdRef.current = agentChatSelectedSessionId;
const agentChatActiveSessionIdRef = useRef(agentChatActiveSessionId);
agentChatActiveSessionIdRef.current = agentChatActiveSessionId;
const agentChatPendingRuntimeRunRef =
useRef<AgentChatPendingRuntimeRun | null>(null);
const agentChatRuntimeSyncingRunIdsRef = useRef(new Set<string>());
const agentChatRuntimeSyncConversationRef = useRef<
| ((
invoke: TauriInvoke,
pendingRun: AgentChatPendingRuntimeRun,
) => Promise<void>)
| null
>(null);
return {
launcherAgentChatAgents,
agentChatProjectPath,
setAgentChatProjectPath,
agentChatSelectedAgentId,
setAgentChatSelectedAgentId,
agentChatMessages,
setAgentChatMessages,
agentChatSessions,
setAgentChatSessions,
agentChatSelectedSessionId,
setAgentChatSelectedSessionId,
agentChatActiveSessionId,
setAgentChatActiveSessionId,
agentChatLegacySessionMode,
setAgentChatLegacySessionMode,
agentChatConversationPath,
setAgentChatConversationPath,
agentChatSessionStatus,
setAgentChatSessionStatus,
agentChatInput,
setAgentChatInput,
agentChatInteractionMode,
setAgentChatInteractionMode,
agentChatRunSubmitMode,
setAgentChatRunSubmitMode,
agentChatReplyPhase,
setAgentChatReplyPhase,
agentChatStatus,
setAgentChatStatus,
agentChatBusy,
setAgentChatBusy,
agentChatMessagesRef,
agentChatShouldFollowLatestRef,
agentChatBackgroundBusy,
setAgentChatBackgroundBusy,
agentChatPendingRuntimeRun,
setAgentChatPendingRuntimeRunState,
agentChatLlmConfigStatus,
setAgentChatLlmConfigStatus,
agentChatLlmStatus,
setAgentChatLlmStatus,
agentChatRuntime,
setAgentChatRuntime,
agentChatActiveRuntime,
setAgentChatActiveRuntime,
agentChatRuntimeError,
setAgentChatRuntimeError,
agentChatGoal,
setAgentChatGoal,
agentChatGoalError,
setAgentChatGoalError,
agentChatGoalDialog,
setAgentChatGoalDialog,
agentChatGoalDialogError,
setAgentChatGoalDialogError,
agentChatResumeConfirmation,
setAgentChatResumeConfirmation,
agentChatLoadVersionRef,
agentChatRuntimeResumeProjectPathRef,
agentChatProjectPathRef,
agentChatSelectedAgentIdRef,
agentChatSelectedSessionIdRef,
agentChatActiveSessionIdRef,
agentChatPendingRuntimeRunRef,
agentChatRuntimeSyncingRunIdsRef,
agentChatRuntimeSyncConversationRef,
};
}
export type DeveloperAgentState = ReturnType<typeof useDeveloperAgentState>;