OpenTowniesystem_prompt.txt12 matches
45- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
2021## Types of triggers
2829```ts
30export default async function (req: Request) {
31return new Response("Hello World");
32}
4041```ts
42export default async function () {
43// Scheduled task code
44}
5253```ts
54export default async function (email: Email) {
55// Process email
56}
60## Val Town Standard Libraries
6162Val Town provides several hosted services and utility functions.
6364### Blob Storage
114```
115116## Val Town Utility Functions
117118Val Town provides several utility functions to help with common project tasks.
119120### Importing Utilities
194โ โโโ database/
195โ โ โโโ migrations.ts # Schema definitions
196โ โ โโโ queries.ts # DB query functions
197โ โ โโโ README.md
198โ โโโ routes/ # Route modules
213โโโ shared/
214โโโ README.md
215โโโ utils.ts # Shared types and functions
216```
217220- 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:
223```ts
224import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
254- Run migrations on startup or comment out for performance
255- Change table names when modifying schemas rather than altering
256- Export clear query functions with proper TypeScript typing
257258## Common Gotchas and Solutions
OpenTowniesoundEffects.ts3 matches
1/**
2* Sound effects utility functions for the application
3*/
47* @returns A Promise that resolves when the sound has started playing
8*/
9export function playBellSound(): Promise<void> {
10return new Promise((resolve) => {
11try {
69* @returns A Promise that resolves when the sound has started playing
70*/
71export function playSimpleNotification(): Promise<void> {
72return new Promise((resolve) => {
73try {
OpenTownieProjects.tsx2 matches
9);
1011async function loader({ bearerToken }: { bearerToken: string }) {
12const data = await (await fetch("/api/projects-loader", {
13headers: {
18}
1920export function Projects({ bearerToken, setProject }: { bearerToken: string; setProject: any }) {
21const [loaderData, setLoaderData] = useState<any>();
22const [isLoading, setIsLoading] = useState<boolean>(true);
OpenTownieProjectFiles.tsx1 match
11}
1213export function ProjectFiles({
14projectFiles,
15isLoadingFiles,
OpenTownieMessagePart.tsx2 matches
4import { ImagePreview } from "./ImageUpload.tsx";
56// Helper function to detect language from file path
7const detectLanguage = (path: string): string => {
8if (!path) return "text";
86};
8788export function MessagePart({ part }: { part: NonNullable<Message["parts"]>[number] }) {
89if (part.type === "text") return <ReactMarkdown>{part.text}</ReactMarkdown>;
90if (part.type === "reasoning")
OpenTownieMessageItem.tsx1 match
24}
2526export function MessageItem({ message, usages, messageEndTimes, running }: MessageItemProps) {
27return (
28<div
OpenTownieLogin.tsx1 match
2import { useLocalStorage } from "https://esm.sh/react-use?dev&deps=react@18.2.0&react-dom@18.2.0";
34export function Login() {
5const [bearerToken, setBearerToken] = useLocalStorage("bearer", "");
6const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage("anthropic_api_key", "");
OpenTownieImageUpload.tsx3 matches
11}
1213export function ImageUpload({ images, setImages, processFiles }: ImageUploadProps) {
14const fileInputRef = useRef<HTMLInputElement>(null);
1579}
8081// Process files utility function - moved from the component to be reusable
82export const processFiles = async (files: File[], images: (string | null)[], setImages: (images: (string | null)[]) => void) => {
83// Filter for image files only
124125// Component to display images in messages
126export function ImagePreview({ images }: { images: string[] }) {
127const [expandedImage, setExpandedImage] = useState<string | null>(null);
128
1export default function fileWithLineNumbers(text: string, view_range = []) {
2return [
3undefined, // Line numbers are 1-indexed
OpenTownieErrorDisplay.tsx1 match
6}
78export function ErrorDisplay({ error }: ErrorDisplayProps) {
9if (!error) return null;
10