TownieuseChatLogic.ts1 match
11}
1213export function useChatLogic({
14project,
15branchId,
TownieuseBranches.tsx1 match
3const ENDPOINT = "/api/project-branches";
45export function useBranches (projectId: string) {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(true);
Townietext-editor.ts1 match
4import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
56function printFileType(file: any) {
7if (file.type === "interval")
8return " (cron)";
Towniesystem_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
176โ โโโ database/
177โ โ โโโ migrations.ts # Schema definitions
178โ โ โโโ queries.ts # DB query functions
179โ โ โโโ README.md
180โ โโโ routes/ # Route modules
195โโโ shared/
196โโโ README.md
197โโโ utils.ts # Shared types and functions
198```
199203- Main entry point should be `backend/index.ts`
204- Do NOT use Hono serveStatic middleware
205- **Static asset serving:** Use the utility functions to read and serve project files:
206```ts
207import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
237- Run migrations on startup or comment out for performance
238- Change table names when modifying schemas rather than altering
239- Export clear query functions with proper TypeScript typing
240241## Common Gotchas and Solutions
Towniestyles.css2 matches
241transition-property: background-color;
242transition-duration: 400ms;
243transition-timing-function: linear;
244}
245875transition-property: color, background-color, border-color, opacity;
876transition-duration: 200ms;
877transition-timing-function: ease-in-out;
878}
879
TowniesoundEffects.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 {
Townieschema.tsx2 matches
22}
2324async function createTables() {
25// archive a table
26// await sqlite.execute(
68}
6970async function deleteTables() {
71await sqlite.execute(`DROP TABLE IF EXISTS ${USAGE_TABLE}`);
72await sqlite.execute(`DROP TABLE IF EXISTS ${INFERENCE_CALLS_TABLE}`);
Townierequests.ts5 matches
29}
3031export function renderRequests(data: RequestRow[], pagination: PaginationData, baseUrl: string): string {
32// Calculate totals
33const totalRequests = pagination.totalItems;
39// Client-side script for collapsible rows
40const script = `
41// Function to toggle inference details
42function toggleInferenceDetails(usageId) {
43const detailsElement = document.getElementById('inference-' + usageId);
44
153
154// Add click event listeners to all collapsible rows
155document.addEventListener('DOMContentLoaded', function() {
156document.querySelectorAll('.collapsible').forEach(row => {
157row.addEventListener('click', function() {
158const usageId = this.getAttribute('data-id');
159toggleInferenceDetails(usageId);
Townierequests.ts4 matches
6* Get paginated usage requests
7*/
8export async function getRequests(url: URL) {
9const { page, pageSize } = getPaginationParams(url);
10
35* Get a single request by ID
36*/
37export async function getRequestById(id: string) {
38const result = await sqlite.execute(`
39SELECT * FROM ${USAGE_TABLE}
51* Get inference calls for a specific usage request
52*/
53export async function getInferenceCallsForRequest(usageId: string) {
54const result = await sqlite.execute(`
55SELECT
75* Calculate totals from inference calls for a request
76*/
77export async function getInferenceTotalsForRequest(usageId: string) {
78const calls = await getInferenceCallsForRequest(usageId);
79
Towniequeries.tsx6 matches
7// but in the meantime, we can cache user info in memory
8const userIdCache: { [key: string]: any } = {};
9export async function getUser(bearerToken: string) {
10if (userIdCache[bearerToken]) return userIdCache[bearerToken];
1116}
1718async function last24Hours(userId: string) {
19const usage = await sqlite.execute(
20`SELECT
45"lightweight": 10, // brad noble, added temporarily for prep for town hall on 5/21/25
46};
47export async function overLimit(bearerToken: string) {
48const user = await getUser(bearerToken);
49const last24HourUsage = await last24Hours(user.id);
54}
5556export async function insertInferenceCall({
57usage_id,
58input_tokens,
108}
109110export async function startTrackingUsage({
111bearerToken,
112val_id,
150}
151152export async function finishTrackingUsage({
153rowid,
154input_tokens,