Townieuser-summary.ts1 match
6* This includes a fallback to inference calls data when usage data is missing
7*/
8export async function getUserSummary() {
9// First, get the standard grouped data from the usage table
10const groupedUsageData = await sqlite.execute(`
TownieuseProject.tsx1 match
4const FILES_ENDPOINT = "/api/project-files";
56export function useProject(projectId: string, branchId?: string) {
7const [data, setData] = useState<any>(null);
8const [loading, setLoading] = useState(true);
TownieuseProjects.tsx1 match
3const ENDPOINT = "/api/projects-loader";
45export function useProjects() {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(true);
TownieuseLoadingFavicon.ts3 matches
1import { useEffect } from "react";
23function setLoadingFavicon() {
4document.querySelector('link[rel="icon"]').href = "/favicon-loading.svg";
5}
6function resetFavicon() {
7document.querySelector('link[rel="icon"]').href = "/favicon.svg";
8}
910export function useLoadingFavicon(loading: boolean) {
11useEffect(() => {
12if (loading) setLoadingFavicon();
TownieuseCreateProject.tsx1 match
3const ENDPOINT = "/api/create-project";
45export function useCreateProject() {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(false);
TownieuseCreateBranch.tsx1 match
3const ENDPOINT = "/api/create-branch";
45export function useCreateBranch(projectId: string) {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(false);
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.ts7 matches
3import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
45function printFileType(file: any){
6if (file.type === "interval")
7return " (cron)"
14* View a file or directory in a Val Town project
15*/
16async function view(
17vt: ValTown,
18project: any,
71* Replace a string in a file in a Val Town project
72*/
73async function str_replace(
74vt: ValTown,
75project: any,
133* Create a new file in a Val Town project
134*/
135async function create(vt: ValTown, project: any, branch_id: string | undefined, path: string, file_text?: string) {
136let type_: "file" | "http" | "script";
137if (path.includes("backend/index.ts")) type_ = "http";
167* Insert a string at a specific line in a file in a Val Town project
168*/
169async function insert(
170vt: ValTown,
171project: any,
210* Undo the last edit to a file in a Val Town project (not implemented)
211*/
212async function undo_edit(vt: ValTown, project: any, branch_id: string | undefined) {
213return {
214type: "error",
220* Creates a text editor tool for editing files in a Val Town project
221*/
222export function getTextEditorTool(bearerToken: string, project: any, branch_id: string | undefined) {
223const vt = new ValTown({ bearerToken });
224return anthropic.tools.textEditor_20250124({
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
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```
217221- Main entry point should be `backend/index.ts`
222- Do NOT use Hono serveStatic middleware
223- **Static asset serving:** Use the utility functions to read and serve project files:
224```ts
225import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
255- Run migrations on startup or comment out for performance
256- Change table names when modifying schemas rather than altering
257- Export clear query functions with proper TypeScript typing
258259## Common Gotchas and Solutions