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// Unwrap and rethrow Hono errors as the original error
8## Hono
9
10This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
11
12## Serving assets to the frontend
20### `index.html`
21
22The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
23
24We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
25
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
31
32Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.
112
113/**
114 * Format chat history for Anthropic API
115 */
116function formatChatHistoryForAI(history) {
450bot.on("message", async (ctx) => {
451 try {
452 // Get Anthropic API key from environment
453 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
454 if (!apiKey) {
455 console.error("Anthropic API key is not configured.");
456 ctx.reply(
457 "I apologize, but I'm not properly configured at the moment. Please inform the household administrator.",
461
462 // Initialize Anthropic client
463 const anthropic = new Anthropic({ apiKey });
464
465 // Get message text and user info
671 // Set webhook if it is not set yet
672 if (!isEndpointSet) {
673 await bot.api.setWebhook(req.url, {
674 secret_token: SECRET_TOKEN,
675 });
12 },
13 {
14 "prompt": "weather dashboard for nyc using open-meteo API for NYC with icons",
15 "title": "Weather App",
16 "code":
8
91. Sign up for [Cerebras](https://cloud.cerebras.ai/)
102. Get a Cerebras API Key
113. Save it in your project env variable called `CEREBRAS_API_KEY`
211 } catch (error) {
212 Toastify({
213 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
214 position: "center",
215 duration: 3000,
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>CerebrasCoder</title>
7 <link rel="preconnect" href="https://fonts.googleapis.com" />
8 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9 <link
10 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
11 rel="stylesheet"
12 />
21 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
22 <meta property="og:type" content="website">
23 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
24
25
16 };
17 } else {
18 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
19 const completion = await client.chat.completions.create({
20 messages: [
1async function getLibrariesIoDependents(packageName: string) {
2 // Retrieve API key from environment variable
3 const apiKey = Deno.env.get("LIBRARY_IO");
4
5 if (!apiKey) {
6 throw new Error("Libraries.io API key is not configured");
7 }
8
9 try {
10 const url = `https://libraries.io/api/NPM/${packageName}/dependent_repositories?api_key=${apiKey}`;
11 const response = await fetch(url);
12
13 if (!response.ok) {
14 const errorText = await response.text();
15 throw new Error(`Libraries.io API error: ${errorText}`);
16 }
17
16- Create a fresh, empty database
17- Set up all necessary database tables and indexes
18- Import calendar events (if Google Calendar API credentials are set)
19
20### 2. Environment Variables
23
24#### For LLM functionality:
25- `ANTHROPIC_API_KEY` - For AI responses and daily briefings
26
27#### For Telegram integration:
31
32#### For Google Calendar integration:
33- `GOOGLE_CLIENT_ID` - Google API client ID
34- `GOOGLE_CLIENT_SECRET` - Google API client secret
35- `GOOGLE_REFRESH_TOKEN` - Google OAuth refresh token
36- `GOOGLE_CALENDAR_ID` - Your Google Calendar ID (or "primary")
93
94- Check your environment variables are correctly set
95- Ensure you have the necessary permissions for API calls
96- Look at the console logs for detailed error messages