1/* Custom 3D and animation styles */
2@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
3
4* {
665 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
666 throw new Error(
667 `OpenAI API Call Failed: ${err.message}`
668 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
669 );
1086function generateGuidedAIProcessUI(processDefsForUIJson: string): string {
1087 return `<!DOCTYPE html><html lang="en">
1088<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Real Estate Influencer AI Toolkit</title><script src="https://cdn.tailwindcss.com"></script><link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Montserrat:wght@400;600&display=swap" rel="stylesheet">
1089<style>
1090body{font-family:'Roboto',sans-serif;background-color:#eef2f9;color:#2d3748;display:flex;flex-direction:column;align-items:center;padding:2rem 1rem;min-height:100vh}
105 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
106 throw new Error(
107 `OpenAI API Call Failed: ${err.message}`
108 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
109 );
6): string {
7 return `<!DOCTYPE html><html lang="en">
8<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Mechanical Engineering R&D AI Assistant</title><script src="[https://cdn.tailwindcss.com](https://cdn.tailwindcss.com)"></script><link href="[https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Montserrat:wght@400;600&display=swap](https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Montserrat:wght@400;600&display=swap)" rel="stylesheet">
9<style>
10body{font-family:'Roboto',sans-serif;background-color:#eef2f9;color:#2d3748;display:flex;flex-direction:column;align-items:center;padding:2rem 1rem;min-height:100vh}
547 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
548 throw new Error(
549 `OpenAI API Call Failed: ${err.message}`
550 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
551 );
996 // Added classes for property description and checklist rendering
997 return `<!DOCTYPE html><html lang="en">
998<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Real Estate Showing AI Assistant</title><script src="https://cdn.tailwindcss.com"></script><link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Montserrat:wght@400;600&display=swap" rel="stylesheet">
999<style>
1000body{font-family:'Roboto',sans-serif;background-color:#eef2f9;color:#2d3748;display:flex;flex-direction:column;align-items:center;padding:2rem 1rem;min-height:100vh}
1The api was returning vals tbat dont exist any mkre. I had Townie help me debug but theres still soke kind of issue.
2
3---
4
5
6Perfect! Now I can see the full structure of val objects from the API. Based on the response, I can see that there is no "deactivated" property or similar field that indicates whether a val is inactive or deleted.
7Here are all the properties available on val objects from the API:
8Core Properties:
9name - The val's name
18Metadata:
19url - Val Town web URL
20links - Object with API endpoints and module URLs
21author - Object with author ID and username
22likeCount - Number of likes
29status
30archived
31The Issue: If you're seeing vals in the list API that don't exist anymore, this suggests:
32Caching issue - The API might be returning cached results that include deleted vals
33Race condition - Vals might be getting deleted between when the list is generated and when you try to access them
34Permission changes - Vals might have changed privacy settings making them inaccessible
35API inconsistency - There might be a lag between deletion and removal from the list endpoint
36Potential Solutions:
37Check the actual endpoint - Try accessing the links.endpoint URL to see if it returns 404
38Use the individual val API - Call the links.self URL to verify the val still exists
39Filter by updatedAt - You could filter out very old vals if that correlates with the issue
40Report to Val Town - This seems like an API consistency issue that should be reported
41Would you like me to modify the API to test which vals are actually accessible vs. which ones return 404s?
1export default async function(req: Request) {
2 // You'll need to set your Val Town API token as an environment variable
3 const apiToken = Deno.env.get("VALTOWN_API_TOKEN");
4
5 if (!apiToken) {
6 return new Response("VALTOWN_API_TOKEN environment variable not set", { status: 500 });
7 }
8
9 try {
10 // Get your username first (you can also hardcode this if you know it)
11 const meResponse = await fetch("https://api.val.town/v1/me", {
12 headers: {
13 "Authorization": `Bearer ${apiToken}`,
14 },
15 });
23
24 // List all vals for your user
25 const valsResponse = await fetch(`https://api.val.town/v1/users/${username}/vals`, {
26 headers: {
27 "Authorization": `Bearer ${apiToken}`,
28 },
29 });
463 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
464 throw new Error(
465 `OpenAI API Call Failed: ${err.message}`
466 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
467 );
859function generateGuidedAIProcessUI(processDefsForUIJson: string): string {
860 return `<!DOCTYPE html><html lang="en">
861<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Mechanical Engineering R&D AI Assistant</title><script src="https://cdn.tailwindcss.com"></script><link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Montserrat:wght@400;600&display=swap" rel="stylesheet">
862<style>
863body{font-family:'Roboto',sans-serif;background-color:#eef2f9;color:#2d3748;display:flex;flex-direction:column;align-items:center;padding:2rem 1rem;min-height:100vh}
5// main controller function
6export async function emailValHandler(receivedEmail) {
7 const llmApiUrl = "https://api.anthropic.com/v1/messages";
8 const apiKey = Deno.env.get("ANTHROPIC_API_KEY"); // replace this entire line with your OpenAI API key as a string, e.g., "sk-123..." or use environment variable: https://docs.val.town/reference/environment-variables/
9 const model = "claude-opus-4-20250514";
10
11 if (!apiKey) {
12 throw new Error(
13 "ANTHROPIC_API_KEY is not set. Please set it or replace this line with your API key.",
14 );
15 }
36
37 // step 4: send prompt to openai
38 const aiResponse = await sendRequestToAI(prompt, llmApiUrl, apiKey, model);
39
40 // log the openai response
122
123// helper function to send a request to openai
124async function sendRequestToAI(prompt, llmApiUrl, apiKey, model) {
125 try {
126 // prepare the openai messages payload
149
150 // send the request to openai
151 const response = await fetch(llmApiUrl, {
152 method: "POST",
153 body: JSON.stringify(body),
154 headers: {
155 "Content-Type": "application/json",
156 Authorization: `Bearer ${apiKey}`,
157 },
158 });
20});
21
22// API endpoint for numerology analysis
23app.post("/api/numerology", async c => {
24 try {
25 const input: NumerologyInput = await c.req.json();
43 return `# Numerology Report for ${input.fullNameAtBirth}
44
45**⚠️ DEMO MODE**: This is a sample report structure. Configure TOGETHER_API_KEY for personalized AI-generated analysis.
46
47## Your Core Numbers at a Glance
121
122async function generateNumerologyReport(input: NumerologyInput): Promise<NumerologyResponse> {
123 const apiKey = Deno.env.get("TOGETHER_API_KEY");
124 if (!apiKey) {
125 // Return a demo report when API key is not configured
126 return {
127 report: generateDemoReport(input),
128 error: "Demo mode: TOGETHER_API_KEY not configured. This is a sample report."
129 };
130 }
243
244 try {
245 const response = await fetch("https://api.together.xyz/v1/chat/completions", {
246 method: "POST",
247 headers: {
248 "Authorization": `Bearer ${apiKey}`,
249 "Content-Type": "application/json",
250 },
264 if (!response.ok) {
265 const errorText = await response.text();
266 console.error("Together.ai API error:", response.status, errorText);
267 return { error: `API error: ${response.status} - ${errorText}` };
268 }
269