Something went wrong. Try again.
a tiny pet with a GPT-2 brain, living in your browser
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import type { Action } from "../types.ts";import { brainHas } from "./brain.ts";import { ACT_NEEDS } from "./config.ts";import { petCommand } from "./commands.ts";import { brain, store, toast, ui, view } from "./store.ts";import { isRemote } from "./hosting.ts";
// ---------- egg & hatching ----------// The egg incubates while the brain downloads: no brain, no pet.export function eggView() { if (store.badEgg) return { progress: 0, ready: false, bad: true }; if (!store.state.egg) return { progress: 0, ready: false }; const ready = brain.state === "ready"; const p = ready ? 1 : brain.progress ? (0.9 * brain.progress.loaded) / brain.progress.total : 0; return { progress: p, ready };}
// ---------- care ----------// Feeding, baths, medicine and catch are offers the brain answers. Pats,// cleaning and the lights just happen, and the brain reacts to them. The// shared engine applies all of them, locally or on the host.export function act(kind: Action, arg?: string) { if (!store.tabOwned || !store.state.pet || view.game || ui.hostingBusy) return; const p = store.state.pet.name; if (brain.state !== "ready") { if (!isRemote()) toast(`${p} is dozing until its brain is ready.`); return; } if (!brainHas(ACT_NEEDS[kind])) { toast(`${p} needs its new brain for that.`); return; } void petCommand({ type: "care", kind, item: arg || null });}