Something went wrong. Try again.
My version of https://github.com/vercel-labs/fx
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Node.js agent · fx examples</title><main> <h1>Node.js agent</h1> <p>A native libfx agent. Each request starts a new conversation.</p> <form> <label for="prompt">Prompt</label><br> <textarea id="prompt" name="prompt" rows="3" cols="30" required maxlength="2000">Explain closures in two sentences.</textarea><br> <button disabled>Send</button> </form> <p role="status" id="status"></p> <label for="reply">Reply</label><br> <textarea id="reply" rows="12" cols="30" readonly></textarea> <p><a href="https://github.com/vercel-labs/fx/blob/b9f8b733803f170d1a09cadf1bf5033e04bf44ed/examples/README.md#run-an-example">Code and setup</a></p></main><script type="module"> import { readReply } from '/read-reply.mjs'
const form = document.querySelector('form') const button = document.querySelector('button') const reply = document.querySelector('#reply') const status = document.querySelector('#status') form.addEventListener('submit', async (event) => { event.preventDefault() button.disabled = true reply.value = '' status.textContent = 'Replying…' try { const response = await fetch('/api/chat', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ prompt: new FormData(form).get('prompt') }), }) if (!response.ok) throw new Error(response.status === 429 ? 'Request limit reached. Try again later.' : await response.text()) for await (const text of readReply(response)) reply.value += text status.textContent = 'Reply complete.' } catch (error) { status.textContent = error.message } finally { button.disabled = false } }) button.disabled = false</script></html>