ab132ffc043_.cursorrules15 matches
8### 1. Script Vals
910- Basic JavaScript/TypeScript functions
11- Can be imported by other vals
12- Example structure:
1314```typescript
15export function myFunction() {
16// Your code here
17}
2526```typescript
27export default async function (req: Request) {
28return new Response("Hello World");
29}
3738```typescript
39export default async function () {
40// Scheduled task code
41}
4950```typescript
51export default async function (email: Email) {
52// Process email
53}
5758- Ask clarifying questions when requirements are ambiguous
59- Provide complete, functional solutions rather than skeleton implementations
60- Test your logic against edge cases before presenting the final solution
61- Ensure all code follows Val Town's specific platform requirements
70- **Never bake in secrets into the code** - always use environment variables
71- Include comments explaining complex logic (avoid commenting obvious operations)
72- Follow modern ES6+ conventions and functional programming practices if possible
7374## Val Town Standard Libraries
7576Val Town provides several hosted services and utility functions.
7778### Blob Storage
124```
125126## Val Town Utility Functions
127128Val Town provides several utility functions to help with common project tasks.
129130### Importing Utilities
176{
177name: "should add numbers correctly",
178function: () => {
179expect(1 + 1).toBe(2);
180},
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
213โ โ โโโ README.md
214โ โโโ index.ts # Main entry point
226โโโ shared/
227โโโ README.md
228โโโ utils.ts # Shared types and functions
229```
230232- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
233- Main entry point should be `backend/index.ts`
234- **Static asset serving:** Use the utility functions to read and serve project files:
235```ts
236// Use the serveFile utility to handle content types automatically
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
275- Export clear query functions with proper TypeScript typing
276- Follow the queries and migrations pattern from the example
277
ab132ffc043_populateDemo.ts5 matches
56// Create the memories_demo table
7async function createMemoriesDemoTable() {
8try {
9await sqlite.execute(`
2526// Create a fake memory with proper ID and timestamps
27function createMemory(date, text, createdBy, tags, createdDateOffset = 0) {
28const id = nanoid(10);
29// Base date is April 5, 2025
375376// Insert memories into the database
377async function insertDemoMemories() {
378try {
379// Clear existing data if any
406}
407408// Main function to populate demo data
409export default async function populateDemo() {
410try {
411// Create the table
1import { sendDailyBriefing } from "./sendDailyBrief.ts";
23export async function cronDailyBrief() {
4try {
5const chatId = Deno.env.get("TELEGRAM_CHAT_ID");
ab132ffc043_sendDailyBrief.ts6 matches
13} from "../memoryUtils.ts";
1415async function generateBriefingContent(anthropic, memories, today, isSunday) {
16try {
17const weekdaysHelp = generateWeekDays(today);
96}
9798export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99// Get API keys from environment
100const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139216}
217218function generateWeekDays(today) {
219let output = [];
220239// console.log(weekDays);
240241// Export a function that calls sendDailyBriefing with no parameters
242// This maintains backward compatibility with existing cron jobs
243export default async function (overrideToday?: DateTime) {
244return await sendDailyBriefing(undefined, overrideToday);
245}
4import { DateTime } from "https://esm.sh/luxon@3.4.4";
56export async function testDailyBrief() {
7try {
8const testChatId = Deno.env.get("TEST_TELEGRAM_CHAT_ID");
2// Run this script manually to add new columns to the memories table
34export default async function migrateMemoriesDb() {
5try {
6// Import SQLite module
2// Run this script manually to set createdBy based on memory content
34export default async function populateCreatedBy() {
5try {
6// Import SQLite module
2// Run this script manually to create the database table
34export default async function setupTelegramChatDb() {
5try {
6// Import SQLite module
4import { nanoid } from "https://esm.sh/nanoid@5.0.5";
56export default async function populateMemoryIds() {
7try {
8// Import SQLite module
ab132ffc043_README.md2 matches
16In a normal server environment, you would likely use a middleware [like this one](https://hono.dev/docs/getting-started/nodejs#serve-static-files) to serve static files. Some frameworks or deployment platforms automatically make any content inside a `public/` folder public.
1718However in Val Town you need to handle this yourself, and it can be suprisingly difficult to read and serve files in a Val Town Project. This template uses helper functions from [stevekrouse/utils/serve-public](https://www.val.town/x/stevekrouse/utils/branch/main/code/serve-public/README.md), which handle reading project files in a way that will work across branches and forks, automatically transpiles typescript to javascript, and assigns content-types based on the file's extension.
1920### `index.html`
26## CRUD API Routes
2728This 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.
2930## Errors