import { sendMessage } from "./chat.run.js";
import { commandFailure } from "wimble/server";
const HELP = 'lilguy — a small guide to the files around it.\n\nUsage: run.js\n\nTo ask from the CLI: wimble run /lilguy ask "What is Wimble?"\nMount it on a profile to start exploring that profile instead.\n';
/** @param {import("./chat.run.js").ChatContext} context */
export default async function lilguy(context) {
const { args, accept, owner } = context;
if (args.includes("--help")) return HELP;
if (args[0] === "ask" && args.length > 1) {
try { return `${(await sendMessage(context, { question: args.slice(1).join(" "), messages: [] })).answer}\n`; }
catch { return commandFailure("I couldn't finish that reply. Please try again.\n"); }
}
if (args.length) return HELP;
if (!accept.includes("text/html")) return HELP;
const home = owner.id === "system";
return new Response(`<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>lilguy</title><link rel="stylesheet" href="./style.css"></head>
<body><main>
<div id="conversation-scroll">
<header><div class="face" aria-label="A little face whose eyes follow your pointer"><span class="eye"><span class="pupil"></span></span><span class="eye"><span class="pupil"></span></span></div>
<h1>${home ? "Ask me about Wimble" : "Ask me about anything"}</h1></header>
<section id="messages" role="log" aria-label="Conversation" aria-live="polite"></section>
</div>
<div id="status" role="status" aria-live="polite"></div>
<form><div class="composer"><textarea rows="1" aria-label="Your message" placeholder="Ask a question…" maxlength="12000"></textarea><button id="send" type="submit" aria-label="Send message" disabled><svg viewBox="0 0 20 20" width="18" height="18" fill="none" aria-hidden="true"><path d="M10 15V5m-4 4 4-4 4 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button></div></form>
</main><script type="module" src="./client.js"></script></body></html>`, { headers: { "content-type": "text/html; charset=utf-8" } });
}