376
377 // Send request to the AI
378 const response = await fetch('/orthodoxy-ai', {
379 method: 'POST',
380 headers: {
88async function initQuiz() {
89 try {
90 // Fetch quiz data
91 const response = await fetch('quiz-data.json');
92 const data = await response.json();
93 quizData = data.questions;
73
74// Export the Hono app for HTTP vals
75export default app.fetch;
16 return c.json(response);
17 } catch (error) {
18 console.error("Error fetching chat messages:", error);
19 const response: ApiResponse<null> = {
20 success: false,
21 error: "Failed to fetch chat messages",
22 };
23 return c.json(response, 500);
15 return c.json(response);
16 } catch (error) {
17 console.error("Error fetching job postings:", error);
18 const response: ApiResponse<null> = {
19 success: false,
20 error: "Failed to fetch job postings",
21 };
22 return c.json(response, 500);
9// Function to create a file in a project
10export async function createProjectFile(projectId: string, path: string, content: string, apiKey: string) {
11 const response = await fetch(`https://api.val.town/v1/projects/${projectId}/files`, {
12 method: "POST",
13 headers: {
31// Function to update a file in a project
32export async function updateProjectFile(projectId: string, path: string, content: string, apiKey: string) {
33 const response = await fetch(`https://api.val.town/v1/projects/${projectId}/files/${path}`, {
34 method: "PUT",
35 headers: {
52// Function to set a file as HTTP handler
53export async function setFileAsHttpHandler(projectId: string, path: string, apiKey: string) {
54 const response = await fetch(`https://api.val.town/v1/projects/${projectId}/http-handler`, {
55 method: "PUT",
56 headers: {
104});
105
106export default app.fetch;
216
217 // Convert data URL to blob
218 const response = await fetch(previewImg.src);
219 const blob = await response.blob();
220
226
227 // Send to API
228 const result = await fetch('/api/analyze-food', {
229 method: 'POST',
230 body: formData
135 const lastSunday = today.startOf("week").minus({ days: 1 });
136
137 // Fetch relevant memories using the utility function
138 const memories = await getRelevantMemories();
139
67 const [currentPage, setCurrentPage] = useState(1);
68
69 const fetchMemories = useCallback(async () => {
70 setLoading(true);
71 setError(null);
72 try {
73 const response = await fetch(API_BASE);
74 if (!response.ok) {
75 throw new Error(`HTTP error! status: ${response.status}`);
78 setMemories(data);
79 } catch (e) {
80 console.error("Failed to fetch memories:", e);
81 setError(e.message || "Failed to fetch memories.");
82 } finally {
83 setLoading(false);
86
87 useEffect(() => {
88 fetchMemories();
89 }, [fetchMemories]);
90
91 const handleAddMemory = async (e: React.FormEvent) => {
100
101 try {
102 const response = await fetch(API_BASE, {
103 method: "POST",
104 headers: { "Content-Type": "application/json" },
112 setNewMemoryTags("");
113 setShowAddForm(false);
114 await fetchMemories();
115 } catch (e) {
116 console.error("Failed to add memory:", e);
123
124 try {
125 const response = await fetch(`${API_BASE}/${id}`, {
126 method: "DELETE",
127 });
129 throw new Error(`HTTP error! status: ${response.status}`);
130 }
131 await fetchMemories();
132 } catch (e) {
133 console.error("Failed to delete memory:", e);
155
156 try {
157 const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158 method: "PUT",
159 headers: { "Content-Type": "application/json" },
164 }
165 setEditingMemory(null);
166 await fetchMemories();
167 } catch (e) {
168 console.error("Failed to update memory:", e);