Towniedashboard.ts1 match
15}
1617export function renderDashboard(data: UserSummaryRow[]): string {
18// Calculate totals
19const totalUsers = data.length;
Townie.cursorrules12 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}
4243```ts
44export default async function () {
45// Scheduled task code
46}
5657```ts
58export default async function (email: Email) {
59// Process email
60}
66## Val Town Standard Libraries
6768Val Town provides several hosted services and utility functions.
6970### Blob Storage
120```
121122## Val Town Utility Functions
123124Val Town provides several utility functions to help with common project tasks.
125126### Importing Utilities
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
203โ โ โโโ README.md
204โ โโโ routes/ # Route modules
219โโโ shared/
220โโโ README.md
221โโโ utils.ts # Shared types and functions
222```
223226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229```ts
230import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263264## Common Gotchas and Solutions
TownieChatRoute.tsx3 matches
14import { Loading } from "./Loading.tsx";
1516export function ChatRoute() {
17const { projectId, branchId } = useParams() as {
18projectId: string;
50}
5152function Conversation({
53project,
54files,
163}
164165function shouldRefetch(message) {
166for (let i = 0; i < message?.parts?.length; i++) {
167let part = message.parts[i];
TownieChatRouteSingleColumn.tsx3 matches
1920// alt single-column version of /chat route
21export function ChatRouteSingleColumn () {
22const { projectId, branchId } = useParams() as {
23projectId: string;
56}
5758function Conversation ({
59project,
60files,
177}
178179function shouldRefetch (message) {
180for (let i = 0; i < message?.parts?.length; i++) {
181let part = message.parts[i];
TowniecalculateCost.tsx1 match
5const CACHE_WRITE_RATE = 3.75; // $3.75 per M cache-write tokens
67export function calculateCost({
8input_tokens,
9output_tokens,
TownieBranchSelect.tsx1 match
7const NEW_BRANCH_VAL = "__NEW_BRANCH__";
89export function BranchSelect() {
10const { projectId, branchId } = useParams() as {
11projectId: string;
5* Returns null if authentication is successful, or a Response if it fails
6*/
7export async function basicAuthMiddleware(req: Request): Promise<Response | null> {
8const realm = "Usage Dashboard";
9const unauthorizedResponse = new Response("Unauthorized", {
18});
1920export function App() {
21const [audio, setAudio] = useLocalStorage("AUDIO", false);
22const user = useUser();
vtProjectSearchutils.tsx2 matches
1// Format date to relative time
2export function formatRelativeTime(dateString: string): string {
3const date = new Date(dateString);
4const now = new Date();
3738// Format date for tooltip (full date)
39export function formatFullDate(dateString: string): string {
40const date = new Date(dateString);
41return date.toLocaleDateString("en-US", {
vtProjectSearchdocsearch.ts2 matches
62* @param query Search query
63*/
64export async function searchDocsCount(
65query: string
66): Promise<number> {
85* @param fetchData Whether to fetch the full data for each result
86*/
87export async function searchDocs(
88query: string,
89page: number = 1,