import { $ } from "bun" import { Hono } from "hono" import { openai, createFile } from "./src/openai" import { serveStatic } from "hono/bun" import fs from "fs" const CAMERA = process.env.IAGO_CAMERA || "Set IAGO_CAMERA environment variable" const PROMPT = "What text do you see in this image?" const IMAGE_PATH = "./photo.jpg" const app = new Hono() // Serve static files from public directory app.use("/*", serveStatic({ root: "./public" })) app.get("/", (c) => { return c.json({ message: "Hello World" }) }) // you know app.get("/status", async (c) => { if (!(await checkImagesnap())) return c.json({ status: "imagesnap not found", devices: [], camera: CAMERA }) const devices = await getDevices() return c.json({ devices, camera: CAMERA, status: devices.includes(CAMERA) ? "camera found" : "camera not found" }) }) // take a picture with the camera app.get("/capture", async (c) => { try { await runImagesnap() const image = await Bun.file(IMAGE_PATH).arrayBuffer() return new Response(image, { headers: { "Content-Type": "image/jpeg" }, }) } catch (err: any) { return c.json({ error: err.message }, 500) } }) // capture and analyze image app.get("/analyze", async (c) => { try { await runImagesnap() const fileId = await createFile(IMAGE_PATH) const result = await openai.responses.create({ model: "gpt-4o", input: [ { role: "user", content: [ { type: "input_text", text: PROMPT }, { type: "input_image", file_id: fileId, detail: "high" } ] } ] }) return c.json({ result: result.output_text }) } catch (err: any) { return c.json({ error: err.message }, 500) } }) // capture and analyze image, return HTML app.get("/analyze.html", async (c) => { try { await runImagesnap() const fileId = await createFile(IMAGE_PATH) const result = await openai.responses.create({ model: "gpt-4o", input: [ { role: "user", content: [ { type: "input_text", text: "This image contains a corkboard with index cards on it. Please return the text content of each index card followed by a line break, and nothing else." }, { type: "input_image", file_id: fileId, detail: "high" } ] } ] }) return c.html(`