12app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
13
14// Add your API routes here
15// app.get("/api/data", c => c.json({ hello: "world" }));
16
17// Chat API endpoint
18app.post("/api/chat", async (c) => {
19 const { messages } = await c.req.json();
20
21 try {
22 // Call your agent API
23 const requestBody = {
24 messages: messages,
30 };
31
32 // Add authorization header if API key is available
33 const apiKey = Deno.env.get("AGENT_API_KEY")?.trim();
34
35 if (apiKey) {
36 headers["Authorization"] = `Bearer ${apiKey}`;
37 }
38
50 if (!response.ok) {
51 const errorText = await response.text();
52 console.error(`Agent API error: ${response.status} - ${errorText}`);
53 throw new Error(`Agent API error: ${response.status} - ${errorText}`);
54 }
55
219 });
220 } catch (error) {
221 console.error("Chat API error:", error);
222
223 // Return error as streaming response