160 static async processFile(url: string, name: string): Promise<ProcessedFile> {
161 try {
162 const response = await fetch(url);
163 if (!response.ok) {
164 throw new Error(`Failed to fetch file: ${response.status}`);
165 }
166
391 if (SUPPORTED_IMAGE_EXTENSIONS.has(`.${extension}`)) {
392 try {
393 const response = await fetch(attachment.url);
394 const buffer = await response.arrayBuffer();
395 const base64 = btoa(String.fromCharCode(...new Uint8Array(buffer)));
438 }
439
440 return fetch(config.endpoint, {
441 method: "POST",
442 headers: config.headers,
49 }&count=3`;
50
51 const bingResponse = await fetch(bingUrl, {
52 headers: { "Ocp-Apim-Subscription-Key": BING_API_KEY },
53 });
1import { betterFetch } from "npm:@better-fetch/fetch";
2import { Temporal } from "npm:temporal-polyfill";
3type CostsObject = {
26
27/**
28 * Fetch organization costs for a given time period
29 */
30export async function fetchOrganizationCosts(
31 startTime: number,
32 days: number,
40 : `https://api.openai.com/v1/organization/costs?start_time=${startTime}&limit=${days}`;
41
42 const { data, error } = await betterFetch<Page<CostsObject>>(url, {
43 headers: { Authorization: `Bearer ${Bun.env.OPENAI_ADMIN_KEY}` },
44 });
45
46 if (error) {
47 console.error("Error fetching organization costs:", error);
48 if (error.status === 401 || error.status === 403) {
49 throw new Error(
51 );
52 }
53 throw new Error(`Failed to fetch organization costs: ${error.message}`);
54 }
55
232 async function runAgent(agentName, state, agentType) {
233 const card = createAgentCard(agentName, agentType);
234 const response = await fetch(\`/api/run-agent/\${agentName}\`, {
235 method: 'POST',
236 headers: { 'Content-Type': 'application/json' },
272 for (const agentName of primaryWorkflow) {
273 await runAgent(agentName, currentState, 'analysis');
274 // Fetch the full report from the card to update state correctly
275 currentState[\`\${agentName}_report\`] = JSON.parse(document.getElementById(\`report-card-\${agentName}\`).dataset.report);
276 }
361});
362
363export default app.fetch;
251 }
252
253 const response = await fetch(\`/api/run-agent/\${agentName}\`, {
254 method: 'POST',
255 headers: { 'Content-Type': 'application/json' },
382app.get("/", (c) => {
383 const sourceUrl = new URL(c.req.url);
384 // Ensure the URL is clean for the script's fetch calls (no path, no query)
385 const baseUrl = `https://${sourceUrl.hostname}`;
386 return c.html(generateHtml(baseUrl));
387});
388
389export default app.fetch;
17 const start = performance.now();
18 try {
19 res = await fetch(url);
20 end = performance.now();
21 status = res.status;
27 } catch (e) {
28 end = performance.now();
29 reason = `couldn't fetch: ${e}`;
30 ok = false;
31 }
5 const url = new URL(req.url);
6 url.hostname = "bgtfs.transitapp.com";
7 return fetch(url);
8}
15app.get("/src/**/*", (c) => serveFile(c.req.path, import.meta.url));
16
17export default app.fetch;
67 // Debug mode
68 if (mode === "debug") {
69 const response = await fetch(
70 `${baseUrl}?view=mTeam&view=mSettings&scoringPeriodId=2`,
71 {
112 `${baseUrl}?view=mMatchup&view=mMatchupScore&view=mTeam&view=mSettings&view=mBoxscore&view=mScoreboard&view=mRoster&view=mLiveScoring&scoringPeriodId=${targetWeek}`;
113
114 const response = await fetch(apiUrl, {
115 method: "GET",
116 headers: {
287 const apiUrl = `${baseUrl}?view=mTeam&view=mStandings&view=mSettings`;
288
289 const response = await fetch(apiUrl, {
290 method: "GET",
291 headers: {
353 `${baseUrl}?view=mRoster&view=mTeam&view=mLiveScoring&view=mMatchupScore&scoringPeriodId=${currentWeek}&teamId=${actualTeamId}`;
354
355 const response = await fetch(apiUrl, {
356 method: "GET",
357 headers: {
423 } catch (error) {
424 return Response.json({
425 error: "Failed to fetch fantasy data",
426 details: error.message,
427 });
13 console.log("📥 Incoming payload:", bodyText);
14
15 const resp = await fetch(APP_SCRIPT_URL, {
16 method: "POST",
17 headers: {