untitled-8264Main2.ts12 matches
1export default async function (req: Request): Promise<Response> {
2const fftSize = 2048;
3const TWO_PI = 2.0 * 3.141592653579;
56const errorBox = document.getElementById("errorBox");
5758function showError(e) {
59console.error(e);
60errorBox.style.display = "block";
6364// DPR-aware resize
65function resize() {
66const dpr = Math.min(window.devicePixelRatio || 1, 2);
67const w = Math.floor(window.innerWidth * dpr);
178\`;
179180function compileShader(type, src) {
181const s = gl.createShader(type);
182gl.shaderSource(s, src);
204gl.bindVertexArray(vao);
205206function createAttrib(data, attribName, usage) {
207const loc = gl.getAttribLocation(program, attribName);
208if (loc === -1) throw new Error("Attrib not found or optimized out: " + attribName);
230231// Matrices
232function mat4Perspective(fovDeg, aspect, near, far) {
233const f = 1.0 / Math.tan((fovDeg * Math.PI) / 360);
234const nf = 1 / (near - far);
241return out;
242}
243function subtract(a, b) { return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]; }
244function normalize(v) {
245const l = Math.hypot(v[0], v[1], v[2]) || 1;
246return [v[0]/l, v[1]/l, v[2]/l];
247}
248function cross(a, b) {
249return [a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]];
250}
251function dot(a, b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; }
252function mat4LookAt(eye, target, up) {
253const z = normalize(subtract(eye, target));
254const x = normalize(cross(up, z));
296297// Render loop
298function render(ts) {
299// Update audio only if ready
300if (analyser) {
vtEditorFilesAGENTS.md12 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}
4243```ts
44export default async function () {
45// Scheduled task code
46}
5657```ts
58export default async function (email: Email) {
59// Process email
60}
66## Val Town Standard Libraries
6768Val Town provides several hosted services and utility functions.
6970### Blob Storage
120```
121122## Val Town Utility Functions
123124Val Town provides several utility functions to help with common project tasks.
125126### Importing Utilities
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
203โ โ โโโ README.md
204โ โโโ routes/ # Route modules
219โโโ shared/
220โโโ README.md
221โโโ utils.ts # Shared types and functions
222```
223226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229```ts
230import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263264## Common Gotchas and Solutions
362363// Handle main niche selection
364nicheSelect.addEventListener('change', function() {
365const selectedValue = this.value;
366
387});
388389// Banner preview functionality
390function updateBannerPreview(bannerNumber) {
391const imageUrl = document.getElementById(`banner${bannerNumber}_image`).value;
392const clickUrl = document.getElementById(`banner${bannerNumber}_url`).value;
422423// Handle form submission
424form.addEventListener('submit', function(e) {
425e.preventDefault();
426
486487// Auto-resize iframe
488function resizeIframe() {
489const height = document.body.scrollHeight;
490parent.postMessage({
untitled-2952main.ts1 match
1// Learn more: https://docs.val.town/vals/http/
2export default async function (req: Request): Promise<Response> {
3const searchParams = new URL(req.url).searchParams;
4
11- **Schedule**: Every minute
12- **Threshold**: Sessions older than 60 seconds without heartbeat updates
13- **Function**: Marks stale sessions as not viewing and syncs to Notion
1415**How Viewing Sessions Work**:
39- **Purpose**: Cleans up orphaned agent blobs
40- **Schedule**: Every minute
41- **Function**: Deletes agent blobs where the agent ID doesn't match the demo's
42"Glimpse agents" relation in Notion
43- **Read-Only Notion**: Only reads Notion data, never modifies it
9* Hook for tracking user viewing status with automatic updates
10*/
11export function useViewingTracking(
12glimpseId: string,
13isAuthorized: boolean
636465// Cleanup function
66return () => {
67if (intervalRef.current) {
4};
56export default async function handler(req: Request) {
7if (req.method !== "GET") {
8return new Response("Method Not Allowed", { status: 405 });
1export default async function (interval: Interval) {
2const f = await fetch("https://sih-2025-demo.onrender.com/");
3const s = await f.text();
255```typescript
256// In route handler
257const result = await controllerFunction(params);
258259if (!result.success) {
10**Returns:** `UseAuthReturn`
11- `userEmail` - Current user's email from window data
12- `isAuthorized(pageProperties)` - Function to check if user can access a page
1314**Usage:**
29- `loading` - Loading state
30- `error` - Error state
31- `refetch` - Function to manually refetch data
3233**Usage:**