182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
10
11 useEffect(() => {
12 fetchChatHistory();
13 }, []);
14
15 const fetchChatHistory = async () => {
16 try {
17 const response = await fetch("/history");
18 const history = await response.json();
19 setMessages(history);
46
47 try {
48 const response = await fetch("/chat", {
49 method: "POST",
50 headers: { "Content-Type": "application/json" },
103 const resetConversation = async () => {
104 try {
105 await fetch("/reset", { method: "POST" });
106 setMessages([]);
107 } catch (error) {
180 `);
181
182 // Fetch chat history
183 if (request.method === "GET" && new URL(request.url).pathname === "/history") {
184 const result = await sqlite.execute(`
12
13 useEffect(() => {
14 fetchChatHistory();
15 }, []);
16
17 const fetchChatHistory = async () => {
18 try {
19 const response = await fetch("/history");
20 const history = await response.json();
21 setMessages(history);
87
88 try {
89 const response = await fetch("/chat", {
90 method: "POST",
91 headers: { "Content-Type": "application/json" },
144 const resetConversation = async () => {
145 try {
146 await fetch("/reset", { method: "POST" });
147 setMessages([]);
148 // Stop any ongoing speech
236 `);
237
238 // Fetch chat history
239 if (request.method === "GET" && new URL(request.url).pathname === "/history") {
240 const result = await sqlite.execute(`
12
13 useEffect(() => {
14 fetchChatHistory();
15 }, []);
16
17 const fetchChatHistory = async () => {
18 try {
19 const response = await fetch("/history");
20 const history = await response.json();
21 setMessages(history);
87
88 try {
89 const response = await fetch("/chat", {
90 method: "POST",
91 headers: { "Content-Type": "application/json" },
144 const resetConversation = async () => {
145 try {
146 await fetch("/reset", { method: "POST" });
147 setMessages([]);
148 // Stop any ongoing speech
236 `);
237
238 // Fetch chat history
239 if (request.method === "GET" && new URL(request.url).pathname === "/history") {
240 const result = await sqlite.execute(`
251
252 try {
253 const response = await fetch("/api/love-template", {
254 method: "POST",
255 headers: { "Content-Type": "application/json" },
709 );
710 } catch (error) {
711 console.error("Error fetching love template:", error);
712 return new Response("Internal Server Error", { status: 500 });
713 }
729 const totalPages = Math.ceil(total / limit);
730
731 // Fetch paginated records
732 const result = await sqlite.execute(`
733 SELECT shareable_id, partner_name, start_date, love_letter, music_url, music_thumbnail, template_type, images, created_at
808 });
809 } catch (error) {
810 console.error("Error fetching love templates:", error);
811 return new Response("<h1>Internal Server Error</h1>", {
812 status: 500,
170 setTheme("dark");
171 }
172 fetchModels();
173 }, []);
174
181 };
182
183 const fetchModels = async () => {
184 setLoading(true);
185 setProgress(0);
191
192 try {
193 const response = await fetch("/api/models");
194 if (!response.ok) throw new Error("Failed to fetch models");
195 const data = await response.json();
196 setModels(data);
124 // Note: This is a placeholder as Val Town doesn't have a native Google AI client
125 // Would need to implement actual API call here
126 const response = await fetch(
127 "https://generativelanguage.googleapis.com/v1beta/models/" + model.id + ":generateContent",
128 {
112 // Note: This is a placeholder as Val Town doesn't have a native Anthropic client
113 // Would need to implement actual API call here
114 const response = await fetch("https://api.anthropic.com/v1/messages", {
115 method: "POST",
116 headers: {
20 stock_image: "3",
21 });
22 const response = await fetch(`/image?${params.toString()}`, {
23 method: "GET",
24 });
38 formData.append("type", imageType);
39
40 fetch("/upload", {
41 method: "POST",
42 body: formData,