OpenTowniesystem_prompt.txt10 matches
13- Generate code in TypeScript or TSX
14- Add appropriate TypeScript types and interfaces for all data structures
15- Prefer official SDKs or libraries than writing API calls directly
16- Ask the user to supply API or library documentation if you are at all unsure about it
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
23### 1. HTTP Trigger
2425- Create web APIs and endpoints
26- Handle HTTP requests and responses
27- Example structure:
167However, it's *extremely importing* to note that `parseProject` and other Standard Library utilities ONLY RUN ON THE SERVER.
168If you need access to this data on the client, run it in the server and pass it to the client by splicing it into the HTML page
169or by making an API request for it.
170171## Val Town Platform Specifics
175- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
176- **Storage:** DO NOT use the Deno KV module for storage
177- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
178- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
179- **View Source:** Add a view source link by importing & using `import.meta.url.replace("ems.sh", "val.town)"` (or passing this data to the client) and include `target="_top"` attribute
180- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
181- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
182- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
183- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
184- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
218### Backend (Hono) Best Practices
219220- Hono is the recommended API framework
221- Main entry point should be `backend/index.ts`
222- **Static asset serving:** Use the utility functions to read and serve project files:
242});
243```
244- Create RESTful API routes for CRUD operations
245- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
246```ts
279- For files in the project, use `readFile` helpers
2802815. **API Design:**
282- `fetch` handler is the entry point for HTTP vals
283- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
OpenTowniesoundEffects.ts4 matches
45/**
6* Plays a bell sound notification using the Web Audio API
7* @returns A Promise that resolves when the sound has started playing
8*/
13const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
14if (!AudioContext) {
15console.warn("Web Audio API not supported in this browser");
16resolve();
17return;
6566/**
67* Plays a simple notification sound using the Web Audio API
68* This is a simpler, shorter bell sound
69* @returns A Promise that resolves when the sound has started playing
75const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
76if (!AudioContext) {
77console.warn("Web Audio API not supported in this browser");
78resolve();
79return;
OpenTowniesend-message.ts11 matches
19}
2021const { messages, project, branchId, anthropicApiKey, selectedFiles, images } = await c.req.json();
22console.log("Original messages:", JSON.stringify(messages, null, 2));
23console.log("Images received:", JSON.stringify(images, null, 2));
2425// Check if API key is available
26if (!anthropicApiKey) {
27return Response.json({
28error: "Anthropic API key is required. Please log out and add your Anthropic API key to use this app.",
29}, { status: 400 });
30}
3132let apiKey;
33if (!anthropicApiKey) {
34return Response.json({
35error: "Anthropic API key is required. Please log out and add your Anthropic API key to use this app.",
36}, { status: 400 });
37} else if (anthropicApiKey === Deno.env.get("PASSWORD")) {
38apiKey = Deno.env.get("PROVIDED_ANTHROPIC_API_KEY");
39} else {
40apiKey = anthropicApiKey;
41}
4243const anthropic = createAnthropic({
44apiKey,
45});
46
OpenTownieProjects.tsx1 match
1011async function loader({ bearerToken }: { bearerToken: string }) {
12const data = await (await fetch("/api/projects-loader", {
13headers: {
14"Authorization": "Bearer " + bearerToken,
OpenTownieLogin.tsx8 matches
4export function Login() {
5const [bearerToken, setBearerToken] = useLocalStorage("bearer", "");
6const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage("anthropic_api_key", "");
78return (
11<div className="text-center mb-8">
12<h2 className="text-xl sm:text-2xl font-bold text-gray-800 mb-2 tracking-tight">Login to OpenTownie</h2>
13<p className="text-sm sm:text-base text-gray-600 mb-4">Enter your API keys to get started</p>
14</div>
1520<a
21target="_blank"
22href="https://www.val.town/settings/api"
23className="text-indigo-600 hover:text-indigo-800 font-medium flex items-center transition-colors duration-200"
24>
25Val Town API Token
26<svg
27xmlns="http://www.w3.org/2000/svg"
78<label className="block text-sm font-medium text-gray-700">
79<div className="flex items-center mb-1">
80<span>Anthropic API Key</span>
81<a
82href="https://console.anthropic.com/settings/keys"
91<input
92type="password"
93value={anthropicApiKey}
94onChange={(e: any) => setAnthropicApiKey(e.target.value)}
95placeholder="sk-ant-xxxxx"
96autoComplete="off"
124125<div className="text-center text-xs text-gray-500 mt-6 bg-gray-50 p-3 rounded-lg">
126Your API keys are stored locally in your browser and never stored on our servers.
127</div>
128</div>
OpenTownieDirectoryTree.tsx1 match
236];
237238// Capitalize first letter
239if (num >= 0 && num <= 10) {
240const word = words[num];
OpenTownieCreateProject.tsx1 match
3233try {
34const response = await fetch("/api/create-project", {
35method: "POST",
36headers: {
OpenTownieCreateBranch.tsx1 match
43
44try {
45const response = await fetch("/api/create-branch", {
46method: "POST",
47headers: {
OpenTownieChat.tsx5 matches
8import { ChatMessages } from "./ChatMessages.tsx";
9import { ChatInput } from "./ChatInput.tsx";
10import { ApiKeyWarning } from "./ApiKeyWarning.tsx";
11import { processFiles } from "./ImageUpload.tsx";
12import { Preview } from "./Preview.tsx";
15project,
16bearerToken,
17anthropicApiKey,
18setProject,
19}: {
20project: any;
21bearerToken: string;
22anthropicApiKey: string;
23setProject: (project: any) => void;
24}) {
57project,
58branchId,
59anthropicApiKey,
60bearerToken,
61selectedFiles,
170171<div className="p-6 flex flex-col h-full w-full">
172<ApiKeyWarning show={!anthropicApiKey} />
173
174<div className="flex flex-col lg:flex-row gap-4">
OpenTownieBranchControl.tsx2 matches
37setIsLoadingBranches(true);
38try {
39const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
40headers: {
41"Authorization": `Bearer ${bearerToken}`,
107const fetchBranches = async () => {
108try {
109const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
110headers: {
111"Authorization": `Bearer ${bearerToken}`,