"use client" import { useEffect, useRef, useState, useTransition } from "react" import { VideoPlayer } from "@/components/business/video-player" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { render } from "./render" import { Agent, AgentType, Scene } from "./agents/types" import { agents, defaultAgent, getAgent } from "./agents" export default function Main() { const [url, setUrl] = useState() const [isPending, startTransition] = useTransition() const [scene, setScene] = useState() const ref = useRef(defaultAgent) useEffect(() => { const updateView = async () => { // console.log(`update view..`) await startTransition(async () => { // console.log(`getting agent..`) const type = ref?.current const agent = getAgent(type) // console.log(`asking agent to determine things..`) const scene = agent.simulate() // console.log(`rendering scene..`) const newUrl = await render(scene.prompt) if (type !== ref?.current) { console.log("agent type changed! reloading scene") setTimeout(() => { updateView() }, 0) return } if (newUrl) { // console.log(`got a new url: ${newUrl}`) setUrl(newUrl) setScene(scene) setTimeout(() => { updateView()}, 1000) } else { // console.log(`going to wait a bit more: ${newUrl}`) setTimeout(() => { updateView()}, 3000) } }) } updateView() }, []) return (
{(scene) ?

Action: {scene.action}

Position: {scene.position}

: null}
) }