val-to-textvaltown.mdc12 matches
910- Ask clarifying questions when requirements are ambiguous
11- Provide complete, functional solutions rather than skeleton implementations
12- Test your logic against edge cases before presenting the final solution
13- Ensure all code follows Val Town's specific platform requirements
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
24- Follow modern ES6+ conventions and functional programming practices if possible
2526## Types of triggers
3334```ts
35export default async function (req: Request) {
36return new Response("Hello World");
37}
4546```ts
47export default async function () {
48// Scheduled task code
49}
5758```ts
59export default async function (email: Email) {
60// Process email
61}
65## Val Town Standard Libraries
6667Val Town provides several hosted services and utility functions.
6869### Blob Storage
119```
120121## Val Town Utility Functions
122123Val Town provides several utility functions to help with common project tasks.
124125### Importing Utilities
181โ โโโ database/
182โ โ โโโ migrations.ts # Schema definitions
183โ โ โโโ queries.ts # DB query functions
184โ โ โโโ README.md
185โ โโโ routes/ # Route modules
200โโโ shared/
201โโโ README.md
202โโโ utils.ts # Shared types and functions
203```
204208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
210- **Static asset serving:** Use the utility functions to read and serve project files:
211```ts
212import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
244- Export clear query functions with proper TypeScript typing
245246## Common Gotchas and Solutions
val-to-textValOutput.tsx1 match
3import type { ValOutputProps } from "../types.ts";
45export function ValOutput({
6text,
7files,
val-to-textValForm.tsx1 match
3import type { ValFormProps } from "../types.ts";
45export function ValForm({
6username,
7valName,
val-to-textutils.ts3 matches
10type File = ValTown.Vals.Files.FileRetrieveResponse;
1112export function formatOutput({
13username,
14valname,
42}
4344export async function getTreeAndContent(id: string): Promise<{
45filesWithContent: { name: string; content: string }[];
46tree: FileTree;
71}
7273export async function getFilesWithContent(
74files: File[],
75valId: string,
val-to-textuseValExport.ts1 match
1import { useState } from "https://esm.sh/react@18.2.0";
23export function useValExport() {
4const [text, setText] = useState<undefined | string>();
5const [files, setFiles] = useState<number>(0);
val-to-textApp.tsx1 match
5import { useValExport } from "../hooks/useValExport.ts";
67export function App() {
8const [name, setName] = React.useState("val-to-text");
9const [username, setUsername] = React.useState("nbbaier");
autonomous-valdemo.tsx7 matches
1import agent from "./agent.tsx";
23export default async function(req: Request) {
4// Default objective as fallback
5let objective = `Buy 100 shares of MSFT and 100 shares of NVDA.`;
89}
9091// Function to generate HTML for tool calls
92function generateToolCallsHtml(results: any): string {
93if (!results || !results.steps) {
94return "";
146}
147148// Function to generate the HTML page with the form and optional results
149function generateHtmlPage(objective?: string, results?: any, errorMessage?: string): string {
150const defaultObjective = objective || `What is the current temperature in Tokyo?`;
151233</style>
234<script>
235// Function to populate the textarea with the selected prompt
236function setPrompt(value) {
237if (value) {
238document.getElementById('objective').value = value;
autonomous-valagent.tsx1 match
16import { formatResult, parseStatusToolResult } from "./utils.tsx";
1718export default async function POST(req: Request) {
19if (req.headers.get("Authorization") !== `Bearer ${Deno.env.get("AGENT_API_KEY")}`) {
20return new Response("Unauthorized", { status: 401 });
RequirementsWriterApp.tsx1 match
2import { useState } from "https://esm.sh/react@18.2.0";
34export function App() {
5const [clicked, setClicked] = useState(0);
6return (
untitled-6069main.tsx19 matches
296297<script>
298// Data loading functions
299async function fetchData(endpoint) {
300try {
301const response = await fetch(`/Repository/docrepo/backend/api/${endpoint}.php`);
371372// Toggle loading spinner
373function toggleLoading(elementId, show) {
374const element = document.getElementById(elementId);
375if (element) {
378}
379380// Render functions for each section
381function renderWebinars(webinars) {
382const container = document.getElementById('webinarsContainer');
383if (!container) return;
399}
400401function renderResearch(featured, recent) {
402const featuredContainer = document.getElementById('featuredResearch');
403const recentContainer = document.getElementById('recentResearch');
431}
432433// Additional render functions would follow the same pattern...
434// (renderInnovations, renderConferences, renderDepartments, etc.)
435436// Helper function to display time since
437function timeSince(date) {
438const seconds = Math.floor((new Date() - date) / 1000);
439let interval = Math.floor(seconds / 31536000);
451}
452453// Authentication functions
454function checkAuthStatus() {
455fetch('/Repository/docrepo/backend/api/auth/session.php')
456.then(res => res.json())
463}
464465function updateUIForLoggedInUser(user) {
466const loginBtn = document.getElementById('loginToggle');
467const registerBtn = document.getElementById('registerToggle');
478}
479480async function handleLogout() {
481try {
482const response = await fetch('/Repository/docrepo/backend/api/auth/logout.php', {
498const registerModal = document.getElementById('registerModal');
499500function toggleModal(show, hide) {
501show.classList.remove('hidden');
502hide.classList.add('hidden');
504}
505506function clearMessages() {
507document.getElementById('loginError').textContent = '';
508document.getElementById('loginError').classList.add('hidden');
542// Smooth scrolling for navigation links
543document.querySelectorAll('a[href^="#"]').forEach(anchor => {
544anchor.addEventListener('click', function (e) {
545e.preventDefault();
546const target = document.querySelector(this.getAttribute('href'));
614});
615616function renderDepartments(departments) {
617const container = document.getElementById('departmentsContainer');
618if (!container || !departments) return;
639640641function renderDepartmentsDropdown(departments) {
642const dropdown = document.getElementById('departmentsDropdown');
643if (!dropdown || !departments) return;
650}
651652async function fetchData(endpoint) {
653const loadingElement = document.getElementById(`${endpoint}Loading`);
654if (loadingElement) loadingElement.style.display = 'block';