"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" import { ImageSegment } from "./types" export default function Main() { const [url, setUrl] = useState("") const [isPending, startTransition] = useTransition() const [scene, setScene] = useState() const [segments, setSegments] = 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 rendered = await render( scene.prompt, [] // note: using actionnables will add +30sec to the query // scene.actionnables ) if (type !== ref?.current) { console.log("agent type changed! reloading scene") setTimeout(() => { updateView() }, 0) return } if (rendered.videoUrl) { // console.log(`got a new url: ${newUrl}`) setUrl(rendered.videoUrl) setScene(scene) setSegments(rendered.segments) setTimeout(() => { updateView()}, 1000) } else { // console.log(`going to wait a bit more: ${newUrl}`) setTimeout(() => { updateView()}, rendered.error ? 6000 : 3000) } }) } updateView() }, []) return (

Note: changing the model might take up to 1 minute

{(scene) ?

Action: {scene.action}

Position: {scene.position}

Light: {scene.light}

: null}
{segments.map((segment, i) =>
{segment.label} ({segment.score})
)}
) }