Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
allowBuilds:
esbuild: set this to true or false
onlyBuiltDependencies:
- esbuild
12 changes: 10 additions & 2 deletions src-tauri/src/runtime_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum PetStateId {
Waiting,
Running,
Review,
Thinking,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}

Expand Down Expand Up @@ -236,6 +243,7 @@ fn map_event_to_state(event: &RuntimeEvent) -> Option<PetStateId> {
"permission.waiting" | "session.waiting" => Some(PetStateId::Waiting),
"session.stop" | "session.end" => Some(PetStateId::Waving),
"session.error" => Some(PetStateId::Failed),
"thinking" => Some(PetStateId::Thinking),
_ => None,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useAgentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
1 change: 1 addition & 0 deletions src/hooks/usePetSounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/lib/appTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type PetStateId =
| "failed"
| "waiting"
| "running"
| "review";
| "review"
| "thinking";

export type PetState = {
id: PetStateId;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/petAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down