Something went wrong. Try again.
a tiny pet with a GPT-2 brain, living in your browser
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import type { Disturbance, Generated, Generation, PetState } from "../types.ts";import { act } from "./care.ts";import { DEBUG } from "./config.ts";import { petTurn, wantTurn } from "./conversation.ts";import { writeDiary } from "./diary.ts";import { changed, editState, petEngine } from "./engine.ts";import { brain, emit, store, toast, ui, upgrade, view } from "./store.ts";import { canRunLocally } from "./hosting.ts";export function debugTurn(opts: Generation, result: Generated) { if (!DEBUG) return; ui.debugLog.push({ ...result, at: new Date(), mode: opts.mode }); if (ui.debugLog.length > 20) ui.debugLog.shift(); emit();}export function setAge(ms: number) { if (!canRunLocally() || !store.state.pet) return; petEngine().setAge(ms, Date.now()); changed();}export const copyText = (text: string) => navigator.clipboard.writeText(text).then( () => toast("Copied."), () => toast("Couldn't copy."), );// Debug controls run the same engine paths as the pet; tags applied here// behave as if the brain had written them.const debug = { setWakeRoll: (roll: (() => number) | null) => petEngine().setWakeRoll(roll), disturb: (kind: Disturbance) => { const woke = petEngine().disturb(kind, Date.now()); changed(); return woke; }, get disturbances() { return petEngine().disturbances; }, resetDisturbances: () => petEngine().resetDisturbances(), applyTags: (text: string) => { if (!canRunLocally()) return; petEngine().applyLine(text, Date.now()); changed(); }, simulate: (from: number, to: number, quiet: boolean) => { const events = petEngine().simulate(from, to, quiet); changed(); return events; }, /** Edits the save in place, e.g. `edit((s) => { s.stats.tummy = 15 })`. */ edit: (fn: (state: PetState) => void) => editState(fn),};export function testControls() { return { state: () => store.state, brain, view, act, petTurn, writeDiary, wantTurn, renderAll: emit, upgrade, ...(DEBUG ? { debug } : {}), };}export type TestControls = ReturnType<typeof testControls>;