From 8368ffcc02269fb7625b94bab068697dfb7aee86 Mon Sep 17 00:00:00 2001 From: JJ-zhang-92 Date: Sat, 11 Jul 2026 21:43:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(runtime):=20thinking=20state=20uses=2030s?= =?UTF-8?q?=20idleAfter=20instead=20of=201.5s=20=E2=80=94=20keeps=20pet=20?= =?UTF-8?q?in=20thinking=20during=20LLM=20processing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pnpm-workspace.yaml | 4 ++++ src-tauri/src/runtime_state.rs | 12 ++++++++++-- src/hooks/useAgentState.ts | 2 ++ src/hooks/usePetSounds.ts | 1 + src/lib/appTypes.ts | 3 ++- src/lib/petAnimation.ts | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 pnpm-workspace.yaml diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..d508289 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,4 @@ +allowBuilds: + esbuild: set this to true or false +onlyBuiltDependencies: + - esbuild diff --git a/src-tauri/src/runtime_state.rs b/src-tauri/src/runtime_state.rs index 253cdc2..e6b9c4b 100644 --- a/src-tauri/src/runtime_state.rs +++ b/src-tauri/src/runtime_state.rs @@ -15,6 +15,7 @@ pub enum PetStateId { Waiting, Running, Review, + Thinking, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -52,6 +53,7 @@ impl DerivedPetState { const MIN_DWELL_MS: u64 = 200; const TEMP_STATE_IDLE_AFTER_MS: u64 = 1_500; +const THINKING_IDLE_AFTER_MS: u64 = 30_000; pub struct EventStateEngine { current: DerivedPetState, @@ -80,7 +82,12 @@ impl EventStateEngine { return self.request_idle(now_ms); } - self.set_state(next, now_ms, Some(now_ms + TEMP_STATE_IDLE_AFTER_MS)) + let idle_after = if next == PetStateId::Thinking { + Some(now_ms + THINKING_IDLE_AFTER_MS) + } else { + Some(now_ms + TEMP_STATE_IDLE_AFTER_MS) + }; + self.set_state(next, now_ms, idle_after) } pub fn advance_time(&mut self, now_ms: u64) -> DerivedPetState { @@ -100,7 +107,7 @@ impl EventStateEngine { return self.current(); } - if !matches!(self.current.state, PetStateId::Running | PetStateId::Review) { + if !matches!(self.current.state, PetStateId::Running | PetStateId::Review | PetStateId::Thinking) { return self.set_state(PetStateId::Idle, now_ms, None); } @@ -236,6 +243,7 @@ fn map_event_to_state(event: &RuntimeEvent) -> Option { "permission.waiting" | "session.waiting" => Some(PetStateId::Waiting), "session.stop" | "session.end" => Some(PetStateId::Waving), "session.error" => Some(PetStateId::Failed), + "thinking" => Some(PetStateId::Thinking), _ => None, } } diff --git a/src/hooks/useAgentState.ts b/src/hooks/useAgentState.ts index ce23a2f..56a20e7 100644 --- a/src/hooks/useAgentState.ts +++ b/src/hooks/useAgentState.ts @@ -28,6 +28,8 @@ function translate(petState: PetStateId, agentMessages: AgentMessage[]): AgentSt return { kind: "awaitingApproval", agent }; case "waving": return { kind: "celebrating", agent }; + case "thinking": + return { kind: "thinking", agent }; case "failed": return { kind: "hurt", agent }; case "idle": diff --git a/src/hooks/usePetSounds.ts b/src/hooks/usePetSounds.ts index d0e2e9b..3b6f648 100644 --- a/src/hooks/usePetSounds.ts +++ b/src/hooks/usePetSounds.ts @@ -15,6 +15,7 @@ export type AgentSoundKey = keyof PetAgentSounds; export function agentSoundKeyForPetState(state: PetStateId): AgentSoundKey | null { switch (state) { case "jumping": + case "thinking": return "thinking"; case "running": return "editing"; diff --git a/src/lib/appTypes.ts b/src/lib/appTypes.ts index 3fba798..bca4b7e 100644 --- a/src/lib/appTypes.ts +++ b/src/lib/appTypes.ts @@ -7,7 +7,8 @@ export type PetStateId = | "failed" | "waiting" | "running" - | "review"; + | "review" + | "thinking"; export type PetState = { id: PetStateId; diff --git a/src/lib/petAnimation.ts b/src/lib/petAnimation.ts index 1149e87..a12e031 100644 --- a/src/lib/petAnimation.ts +++ b/src/lib/petAnimation.ts @@ -65,7 +65,7 @@ function baseSpriteRow(_state: BaseState): PetStateId { function agentSpriteRow(state: AgentState): PetStateId { switch (state.kind) { case "thinking": - return "waiting"; + return "review"; case "editing": return "running"; case "inspecting":