cardamonval-town.mdc12 matches
910- Ask clarifying questions when requirements are ambiguous
11- Provide complete, functional solutions rather than skeleton implementations
12- Test your logic against edge cases before presenting the final solution
13- Ensure all code follows Val Town's specific platform requirements
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
24- Follow modern ES6+ conventions and functional programming practices if possible
2526## Types of triggers
3334```ts
35export default async function (req: Request) {
36return new Response("Hello World");
37}
4546```ts
47export default async function () {
48// Scheduled task code
49}
5758```ts
59export default async function (email: Email) {
60// Process email
61}
65## Val Town Standard Libraries
6667Val Town provides several hosted services and utility functions.
6869### Blob Storage
119```
120121## Val Town Utility Functions
122123Val Town provides several utility functions to help with common project tasks.
124125### Importing Utilities
181โ โโโ database/
182โ โ โโโ migrations.ts # Schema definitions
183โ โ โโโ queries.ts # DB query functions
184โ โ โโโ README.md
185โ โโโ routes/ # Route modules
200โโโ shared/
201โโโ README.md
202โโโ utils.ts # Shared types and functions
203```
204208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
210- **Static asset serving:** Use the utility functions to read and serve project files:
211```ts
212import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
244- Export clear query functions with proper TypeScript typing
245246## Common Gotchas and Solutions
4import { OpenAI } from "npm:openai";
56function pm(...lines: string[]): string {
7return lines.join("\n");
8}
910export async function emailValHandler(inboundEmail: Email) {
11const userPrompt = pm(
12`From: ${inboundEmail.from}`,
23}
2425export default async function(interval: Interval) {
26const today = new Intl.DateTimeFormat("en-US", {
27month: "short",
20const wss = new WebSocketServer({ noServer: true });
2122// Helper function to broadcast messages to all connected clients
23function broadcastToAll(data: any, excludeClient?: WebSocket) {
24const message = JSON.stringify(data);
25clients.forEach((client) => {
GlancerdemoCache.ts1 match
9});
1011export default async function (interval: Interval) {
12// this cron runs every minute
13// it saves a blob for every page in the "Glancer demos" database
7});
89export async function getRelatedPagesFromDatabase(pageId: string) {
10try {
11const response = await notion.databases.query({
1import ValTown from "npm:@valtown/sdk";
23export default async function(req: Request) {
4try {
5const vt = new ValTown();
val-town-http-mcp-servervtCli.ts9 matches
8* @returns Promise resolving to boolean indicating CLI availability
9*/
10export async function isVtCliAvailable(): Promise<boolean> {
11try {
12const command = new Deno.Command("which", {
30* @returns Promise resolving to boolean indicating CLI availability
31*/
32export async function getCliAvailability(): Promise<boolean> {
33if (_isCliAvailable === null) {
34_isCliAvailable = await isVtCliAvailable();
42* @returns Promise resolving to an object containing command execution result
43*/
44export async function runVtCommand(args: string[]): Promise<{
45success: boolean;
46output: string;
7172/**
73* Parse CLI JSON output (placeholder for missing function)
74* @param output CLI output string to parse
75* @returns Parsed JSON object or error
76*/
77export function parseCliJsonOutput(output: string): any {
78try {
79return JSON.parse(output);
8485/**
86* Prepare Val workspace (placeholder for missing function)
87* @param valId Val ID to prepare workspace for
88* @returns Workspace preparation result
89*/
90export async function prepareValWorkspace(valId: string): Promise<{
91success: boolean;
92workspacePath?: string;
102103/**
104* Cleanup temporary directory (placeholder for missing function)
105* @param dirPath Directory path to cleanup
106* @returns Cleanup result
107*/
108export async function cleanupTempDirectory(dirPath: string): Promise<{
109success: boolean;
110error?: string;
6import {z} from "npm:zod"
78export function registerValTools(server: McpServer, config: Config) {
9// Get val by username and val name
10server.tool(
val-town-http-mcp-servervalley.txt11 matches
10- **Never bake in secrets into the code** - always use environment variables
11- Include comments explaining complex logic (avoid commenting obvious operations)
12- Follow modern ES6+ conventions and functional programming practices if possible
1314## Types of triggers
2122```ts
23export default async function (req: Request) {
24return new Response("Hello World");
25}
3536```ts
37export default async function () {
38// Scheduled task code
39}
4950```ts
51export default async function (email: Email) {
52// Process email
53}
58## Val Town Standard Libraries
5960Val Town provides several hosted services and utility functions.
6162### Blob Storage
112```
113114## Val Town Utility Functions
115116Val Town provides several utility functions to help with common project tasks.
117118### Importing Utilities
191โ โโโ database/
192โ โ โโโ migrations.ts # Schema definitions
193โ โ โโโ queries.ts # DB query functions
194โ โ โโโ README.md
195โ โโโ routes/ # Route modules
210โโโ shared/
211โโโ README.md
212โโโ utils.ts # Shared types and functions
213```
214217- Hono is the recommended API framework
218- Main entry point should be `backend/index.ts`
219- **Static asset serving:** Use the utility functions to read and serve project files:
220```ts
221import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
251- Run migrations on startup or comment out for performance
252- Change table names when modifying schemas rather than altering
253- Export clear query functions with proper TypeScript typing
254255## Common Gotchas and Solutions
6## Understanding Val Town
78Val Town is a platform for writing, running, and deploying JavaScript/TypeScript code in the cloud. It functions as a social coding environment where users can create and share code that runs on Val Town's serverless infrastructure.
910### Val Town Projects
21## Core Guidelines
2223- Provide complete, functional solutions
24- Test logic against edge cases
25- Follow Val Town's platform requirements
26- Write clean, maintainable TypeScript/TSX code
27- Add appropriate TypeScript types for all data structures
28- Prefer functional programming practices where appropriate
2930## Coding Requirements