gameplay_agentmain.tsx5 matches
7* If you define your agent with {@link Connect4Agent} or {@link PokerAgent},
8* then you can use {@link agentHandler} to create an http service that
9* serves it. The service it creates is a standard fetch handler that can be
10* used with a variety of different http server libraries.
11*
48* ]});
49*
50* Bun.serve({fetch: handler});
51* ```
52*
114115/**
116* Create standard fetch handler for an agent.
117*
118* Takes a list of agents and returns a handler that can be used to create an
119* agent http endpoint.
120* The handler implements the standard fetch interface and can be used with
121* a variety of different http server libraries.
122*
132*
133* @returns {(req: Request) => Promise<Response>} An async handler that can be
134* used with an http server that supports the fetch interface.
135*/
136export function agentHandler<
whoIsHiringmain.tsx12 matches
61}, [state.loading, state.hasMore]);
6263const fetchStories = async () => {
64try {
65const response = await fetch("/api/stories");
66if (!response.ok) throw new Error("Failed to fetch dates");
67const data = await response.json();
68setStories(data);
70}
71catch (err) {
72console.error("Error fetching stories:", err);
73}
74};
7576const fetchComments = async (query: string, story: string, page: number) => {
77try {
78dispatch({ type: "loading", value: true });
79const response = await fetch(`/api/comments?query=${encodeURIComponent(query)}&story=${story}&page=${page}`);
80if (!response.ok) throw new Error("Failed to fetch comments");
81const data = await response.json();
82setComments(prevComments => page === 1 ? data.hits : [...prevComments, ...data.hits]);
84dispatch({ type: "loading", value: false });
85} catch (err) {
86console.error("Error fetching comments:", err);
87dispatch({ type: "loading", value: false });
88}
99dispatch({ type: "hasMore", value: true });
100dispatch({ type: "query", value: newQuery });
101fetchComments(fullQuery, state.story, 1);
102};
103104useEffect(() => {
105fetchStories();
106107const handleScroll = () => {
122: "";
123const fullQuery = `${filtersQuery} ${state.query}`;
124fetchComments(fullQuery, state.story, state.page);
125}
126}
391tags: `comment, story_${story}`,
392page: 0,
393hitsPerPage: 100, // Fetch a moderate number of comments
394});
395
20setError("");
21try {
22const response = await fetch("/recipes", {
23method: "POST",
24headers: { "Content-Type": "application/json" },
32}
33} catch (err) {
34setError("An error occurred while fetching recipes. Please try again.");
35} finally {
36setLoading(false);
339340async function generateImage(recipeName: string): Promise<string> {
341const response = await fetch(`https://maxm-imggenurl.web.val.run/${encodeURIComponent(recipeName)}`);
342if (!response.ok) {
343throw new Error(`Failed to generate image for ${recipeName}`);
savvyTealCardinalmain.tsx5 matches
51setTrainingPlan("");
52setYoutubeLinks([]);
53const response = await fetch("/generate-training", {
54method: "POST",
55headers: { "Content-Type": "application/json", "Regenerate-Key": regenerateKey.toString() },
76setSharing(true);
77try {
78const response = await fetch("/share-training", {
79method: "POST",
80headers: { "Content-Type": "application/json" },
801const videoPlaceholders = trainingPlan.match(/\[VIDEO: .+?\]/g) || [];
802803// Fetch and embed YouTube videos
804const youtubeLinks = [];
805for (const placeholder of videoPlaceholders) {
897encodeURIComponent(sport + " " + query)
898}&key=${apiKey}&type=video&maxResults=1`;
899const response = await fetch(searchUrl);
900const data = await response.json();
901if (data.error) {
907}
908} catch (error) {
909console.error("Error fetching from YouTube API:", error);
910}
911}
getWeathermain.tsx3 matches
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
23export async function getWeather(location: string): Promise<WeatherResponse> {
4return fetchJSON(`https://wttr.in/${location}?format=j1`);
5}
6315<html>
316<body>
317<h1>Error Fetching Weather</h1>
318<p>${error.message}</p>
319</body>
getSiteMetadatamain.tsx2 matches
9return metadata;
10} catch (err) {
11console.error("Error fetching metadata:", err);
12return null;
13}
75);
7677export default app.fetch;
versatileBrownClownfishmain.tsx5 matches
1import { email } from "https://esm.town/v/std/email?v=9";
23// Fetches a random joke.
4// Fetches a random joke.
5async function fetchRandomJoke() {
6const response = await fetch(
7"https://official-joke-api.appspot.com/random_joke",
8);
10}
1112const randomJoke = await fetchRandomJoke();
13const setup = randomJoke.setup;
14const punchline = randomJoke.punchline;
tiny_jest_examplemain.tsx1 match
11const runTests = async () => {
12try {
13const response = await fetch("/run-tests", {
14method: "POST",
15headers: { "Content-Type": "application/json" },
fizzBuzzTestmain.tsx2 matches
113const runTests = async () => {
114try {
115const response = await fetch("/run-tests", {
116method: "POST",
117headers: { "Content-Type": "application/json" },
234} catch (error) {
235console.error("Error in runTests:", error);
236if (error instanceof TypeError && error.message.includes("Failed to fetch dynamically imported module")) {
237return {
238success: false,
cors_examplemain.tsx1 match
9async function request(url, options) {
10try {
11const response = await fetch(url, options);
12const status = response.status;
13const data = await response.text();