34/**
5* Client utility functions to interact with svgHost service
6*/
78// Function to validate SVG content
9export const validateSvg = (content: string): boolean => {
10return (
15};
1617// Function to upload SVG content to svgHost
18export const uploadSvgToHost = async (svgContent: string, name: string): Promise<{success: boolean, id?: string, url?: string, error?: string}> => {
19try {
hono_html_AppsApp.tsx5 matches
3536\`\`\`javascript
37function greet(name) {
38console.log(\`Hello, \${name}!\`);
39}
173const SectionTitle = ({ title }: { title: string }) => <h2 className="text-2xl font-semibold mb-4">{title}</h2>;
174
175// Helper function to create toast notifications
176const showToast = (message: string, type: 'info' | 'success' | 'error' = 'success') => {
177const toastContainer = document.getElementById('toast-container');
831* Initializes the app in the browser
832*******************************************/
833function client() {
834createRoot(document.getElementById("root")).render(<ThemeDemo />);
835}
840* Handles initial page load and HTML setup
841*******************************************/
842export default async function server(request: Request): Promise<Response> {
843return new Response(
844`
854<script>
855// Set theme from localStorage on page load
856(function() {
857const savedTheme = localStorage.getItem('theme');
858if (savedTheme) {
hono_html_AppsApp.tsx3 matches
139};
140141function App() {
142const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
143const [, setUpdateTrigger] = useState({});
237}
238239function client() {
240createRoot(document.getElementById("root")).render(<App />);
241}
242if (typeof document !== "undefined") { client(); }
243244export default async function server(request: Request): Promise<Response> {
245const html = `
246<!DOCTYPE html>
hono_html_Appsserver3 matches
7const app = new Hono();
89// Helper function to read files relative to the current module
10const readAsset = (path: string) => readFile(path, import.meta.url);
1157// Import the App.tsx module to execute it
58const module = await import("./hm_links/App.tsx");
59// Call the default export function (server) with the request
60return await module.default(c.req.raw);
61} catch (error) {
70// Import the theme-demo App.tsx module to execute it
71const module = await import("./theme-demo/App.tsx");
72// Call the default export function (server) with the request
73return await module.default(c.req.raw);
74} catch (error) {
4import { formatAddress, formatJSON, MonoButtonWithStatus, Section } from "./ui.tsx";
56export function FarcasterMiniApp() {
7const [context, setContext] = useState<any>();
8const [walletAddresses, setWalletAddresses] = useState<any>();
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 {