25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),
21 try {
22 // First API call - Get search results
23 const searchResult = await fetch("/api/search", {
24 method: "POST",
25 headers: { "Content-Type": "application/json" },
32 // Second API call - Get summary
33 setSummaryLoading(true);
34 const summaryResult = await fetch("/api/summarize", {
35 method: "POST",
36 headers: { "Content-Type": "application/json" },
125
126 // Search using SerpApi
127 const searchResponse = await fetch(
128 `https://serpapi.com/search.json?q=${encodeURIComponent(query)}&api_key=${Deno.env.get("SERP_API_KEY")}`,
129 );
54 setLoading(true);
55 try {
56 const response = await fetch("/", {
57 method: "POST",
58 body: JSON.stringify({ level, password, requirements }),
44
45 useEffect(() => {
46 fetchLeaderboard();
47 }, []);
48
49 const fetchLeaderboard = async () => {
50 const response = await fetch("?action=leaderboard");
51 const data = await response.json();
52 setLeaderboard(data);
66 }
67
68 await fetch("?action=update", {
69 method: "POST",
70 body: JSON.stringify({ name: playerName, xp: newXp, level: newLevel }),
71 });
72
73 fetchLeaderboard();
74 };
75
30 setLoading(prev => ({ ...prev, [operation]: true }));
31 try {
32 const response = await fetch(`/run?operation=${operation}`, {
33 method: "POST",
34 headers: {
138}
139
140async function fetchContent(): Promise<string> {
141 const response = await fetch("https://www.gutenberg.org/cache/epub/1342/pg1342.txt");
142 const text = await response.text();
143
151 const MODEL_NAME = "claude-3-5-sonnet-20240620";
152
153 const bookContent = await fetchContent();
154 const startTime = Date.now();
155
187 const MODEL_NAME = "claude-3-5-sonnet-20240620";
188
189 const bookContent = await fetchContent();
190 const startTime = Date.now();
191
226 const MODEL_NAME = "claude-3-5-sonnet-20240620";
227
228 const bookContent = await fetchContent();
229 const questions = [
230 "What is the title of this novel?",
9
10 useEffect(() => {
11 fetchScores();
12 }, []);
13
14 const fetchScores = async () => {
15 try {
16 const response = await fetch('/api/scores');
17 if (!response.ok) {
18 throw new Error('Failed to fetch scores');
19 }
20 const data = await response.json();
68 if (url.pathname === '/api/scores') {
69 try {
70 const mlbResponse = await fetch('https://statsapi.mlb.com/api/v1/schedule/games/?sportId=1');
71 const mlbData = await mlbResponse.json();
72
83 });
84 } catch (error) {
85 return new Response(JSON.stringify({ error: 'Failed to fetch MLB scores' }), {
86 status: 500,
87 headers: { 'Content-Type': 'application/json' }
10
11 useEffect(() => {
12 fetchCoworkers();
13 fetchPeopleBrought();
14 }, []);
15
16 const fetchCoworkers = async () => {
17 const response = await fetch("?action=list");
18 const data = await response.json();
19 setCoworkers(data);
20 };
21
22 const fetchPeopleBrought = async () => {
23 const response = await fetch("?action=getPeopleBrought");
24 const data = await response.json();
25 setPeopleBrought(data.peopleBrought);
30 if (!newCoworker.trim()) return;
31
32 await fetch("?action=add", {
33 method: "POST",
34 body: JSON.stringify({ name: newCoworker }),
35 });
36 setNewCoworker("");
37 fetchCoworkers();
38 };
39
41 const value = parseInt(e.target.value) || 1;
42 setPeopleBrought(value);
43 await fetch("?action=updatePeopleBrought", {
44 method: "POST",
45 body: JSON.stringify({ peopleBrought: value }),
48
49 const deleteCoworker = async (id) => {
50 await fetch("?action=delete", {
51 method: "POST",
52 body: JSON.stringify({ id }),
53 });
54 fetchCoworkers();
55 };
56
1// This val fetches recent tweets about @SnapAR or Lens Studio
2// Updated to use Social Data instead of Twitter API
3
12 return retResponse(data.tweets);
13 } catch (error) {
14 console.error("Error fetching posts:", error);
15 return new Response(JSON.stringify({ error: "Failed to fetch posts", details: error.message }), {
16 status: 500,
17 headers: { "Content-Type": "application/json" },
1// This val fetches recent tweets about @SnapAR or Lens Studio, removes duplicates,
2// and displays them as embedded tweets with preview images on a dark background.
3// Updated to use Social Data instead of Twitter API
5import { socialDataSearch } from "https://esm.town/v/stevekrouse/socialDataSearch?v=5";
6
7// This val fetches recent social media posts about @SnapAR or Lens Studio using socialDataSearch,
8// and displays them as embedded posts with preview images on a dark background.
9
15 return retResponse(data.tweets);
16 } catch (error) {
17 console.error("Error fetching posts:", error);
18 return new Response(JSON.stringify({ error: "Failed to fetch posts", details: error.message }), {
19 status: 500,
20 headers: { "Content-Type": "application/json" },
30 // handler may only run once now, where in the old runtime it
31 // ran on every request. To migrate your code, you may have to
32 // move some code that was outside your fetch handler to run inside it.
33 // </p>
34