utilsexample.test.ts4 matches
8{
9name: "no-op",
10function: () => {
11return true;
12},
14{
15name: "passing test",
16function: () => {
17expect(1).toBe(1);
18},
20{
21name: "Failing test",
22function: () => {
23expect(1).toBe(2);
24},
31{
32name: "passing test 2",
33function: () => {
34expect(1).toBe(1);
35},
trAIderAgentagent.ts1 match
62});
6364export async function trAIderAgent(conversation: { role: string; content: string }[]): Promise<Response> {
65const metaDetails = `
66\n
magnificentCopperOrcamain.tsx3 matches
3import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
45function App() {
6const [statuses, setStatuses] = useState([]);
7const [copiedStatus, setCopiedStatus] = useState(null);
94}
9596function client() {
97const link = document.createElement("link");
98link.href = "https://fonts.googleapis.com/css2?family=Hind+Siliguri&display=swap";
105if (typeof document !== "undefined") { client(); }
106107export default async function server(request: Request): Promise<Response> {
108const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
109const KEY = "magnificentCopperOrca";
FixItWandSignIn.tsx1 match
4type SignInState = "idle" | "loading" | "sent";
56export function SignIn() {
7const [email, setEmail] = useState<null | string>(null);
8const [state, setState] = useState<SignInState>("idle");
imagegeneratormain.tsx4 matches
8const CANVAS_HEIGHT = 400;
910function SnakeGame() {
11const canvasRef = useRef(null);
12const [score, setScore] = useState(0);
2324// Generate random food position
25function generateFood() {
26return {
27x: Math.floor(Math.random() * (CANVAS_WIDTH / GRID_SIZE)) * GRID_SIZE,
205}
206207function client() {
208createRoot(document.getElementById("root")).render(<SnakeGame />);
209}
210if (typeof document !== "undefined") { client(); }
211212export default async function server(request: Request): Promise<Response> {
213return new Response(
214`
OpenTownieuseProjectFiles.ts1 match
17* Custom hook to fetch and manage project files
18*/
19export function useProjectFiles({
20projectId,
21branchId,
OpenTownieuseChatLogic.ts1 match
13}
1415export function useChatLogic({
16project,
17branchId,
OpenTownietext-editor.ts6 matches
5* View a file or directory in a Val Town project
6*/
7async function view(
8vt: ValTown,
9project: any,
70* Replace a string in a file in a Val Town project
71*/
72async function str_replace(
73vt: ValTown,
74project: any,
132* Create a new file in a Val Town project
133*/
134async function create(vt: ValTown, project: any, branch_id: string | undefined, path: string, file_text?: string) {
135let type_: "file" | "http" | "script";
136if (path.includes("backend/index.ts")) type_ = "http";
166* Insert a string at a specific line in a file in a Val Town project
167*/
168async function insert(
169vt: ValTown,
170project: any,
209* Undo the last edit to a file in a Val Town project (not implemented)
210*/
211async function undo_edit(vt: ValTown, project: any, branch_id: string | undefined) {
212return {
213type: "error",
219* Creates a text editor tool for editing files in a Val Town project
220*/
221export function getTextEditorTool(bearerToken: string, project: any, branch_id: string | undefined) {
222const vt = new ValTown({ bearerToken });
223return anthropic.tools.textEditor_20250124({
OpenTowniesystem_prompt.txt9 matches
7- Respond in a friendly and concise manner
8- Ask clarifying questions when requirements are ambiguous
9- Provide complete, functional solutions rather than skeleton implementations
10- Test your logic against edge cases before presenting the final solution
11- Ensure all code follows Val Town's specific platform requirements
30- **Never bake in secrets into the code** - always use environment variables
31- Include comments explaining complex logic (avoid commenting obvious operations)
32- Follow modern ES6+ conventions and functional programming practices where appropriate
3334### Val Town Utility Functions
3536Val Town provides several utility functions to help with common project tasks. These utilities handle file management, project information, and testing.
3738### Importing Utilities
84{
85name: "should add numbers correctly",
86function: () => {
87expect(1 + 1).toBe(2);
88},
168โ โโโ database/
169โ โ โโโ migrations.ts # Schema definitions
170โ โ โโโ queries.ts # DB query functions
171โ โ โโโ README.md
172โ โโโ index.ts # Main entry point
184โโโ shared/
185โโโ README.md
186โโโ utils.ts # Shared types and functions
187```
188190- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
191- Main entry point should be `backend/index.ts`
192- **Static asset serving:** Use the utility functions to read and serve project files:
193```ts
194// Use the serveFile utility to handle content types automatically
231- Run migrations on startup or comment out for performance
232- Change table names when modifying schemas rather than altering
233- Export clear query functions with proper TypeScript typing
234- Follow the queries and migrations pattern from the example
235
OpenTowniesoundEffects.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 {