Files
hermes-ui/packages/client/src/stores/hermes/pets.ts
T
toor 1e9ea89d86
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
chore: bootstrap hermes-ui skeleton from 0.6.29 snapshot
Import the client, server, skills, tests, and build scripts as the starting
point for the rebuild, then trim the surfaces this project does not ship:
Electron desktop packaging, the marketing website, and the ESP32 firmware
tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows.

Rename the package and CLI entry points to hermes-ui, drop the prepare hook so
npm ci no longer triggers a build, and drop the removed tsconfig and nodemon
references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs
so the documented package map and hard rules match this repository.

reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
2026-10-16 10:34:35 +08:00

83 lines
2.2 KiB
TypeScript

import { computed, ref } from 'vue'
import { defineStore } from 'pinia'
import * as petsApi from '@/api/hermes/pets'
import type { ActivePet, WebPetPosition } from '@/api/hermes/pets'
export const usePetsStore = defineStore('pets', () => {
const activePet = ref<ActivePet | null>(null)
const loading = ref(false)
const saving = ref(false)
const error = ref('')
const hasActivePet = computed(() => !!activePet.value?.enabled)
async function loadActivePet(): Promise<ActivePet | null> {
loading.value = true
error.value = ''
try {
activePet.value = await petsApi.fetchActivePet()
return activePet.value
} catch (err: any) {
error.value = err?.message || 'Failed to load active pet'
activePet.value = null
return null
} finally {
loading.value = false
}
}
async function adopt(slug: string): Promise<ActivePet> {
saving.value = true
error.value = ''
try {
activePet.value = await petsApi.adoptPet(slug)
return activePet.value
} catch (err: any) {
error.value = err?.message || 'Failed to adopt pet'
throw err
} finally {
saving.value = false
}
}
async function savePreferences(input: { scale?: number; position?: WebPetPosition; enabled?: boolean }): Promise<void> {
if (!activePet.value) return
activePet.value = {
...activePet.value,
...(typeof input.scale === 'number' ? { scale: input.scale } : {}),
...(input.position ? { position: input.position } : {}),
...(typeof input.enabled === 'boolean' ? { enabled: input.enabled } : {}),
}
saving.value = true
try {
const saved = await petsApi.updateActivePetPreferences(input)
if (saved) activePet.value = saved
else if (input.enabled === false) activePet.value = null
} finally {
saving.value = false
}
}
async function hideActivePet(): Promise<void> {
await savePreferences({ enabled: false })
}
function clear(): void {
activePet.value = null
error.value = ''
}
return {
activePet,
loading,
saving,
error,
hasActivePet,
loadActivePet,
adopt,
savePreferences,
hideActivePet,
clear,
}
})