562}
563564const apiRequestBody: any = { model, messages: messagesPayload };
565if (typeof params.temperature === "number") apiRequestBody.temperature = params.temperature;
566if (typeof params.max_tokens === "number" && params.max_tokens > 0)
567apiRequestBody.max_tokens = Math.floor(params.max_tokens);
568569log("INFO", "OpenAiCallTool", "Making OpenAI chat completion call.", {
576577try {
578const completion = await openaiClient.chat.completions.create(apiRequestBody);
579if (!completion?.choices?.length) {
580log("WARN", "OpenAiCallTool", "OpenAI response empty/unexpected.", { response: completion });
583return { mandateId, correlationId: taskId, payload: { result: completion } };
584} catch (e: any) {
585log("ERROR", "OpenAiCallTool", "OpenAI API call failed.", e);
586const errMsg = e.response?.data?.error?.message || e.error?.message || e.message || "Unknown OpenAI API error";
587return { mandateId, correlationId: taskId, payload: { result: null }, error: errMsg };
588}
701const { mandateId, taskId, payload } = input;
702const { log } = context;
703log("INFO", "ScrapeEmails", `Scraping emails for ${payload.businesses?.length ?? 0} sites.`);
704705if (!payload?.businesses || !Array.isArray(payload.businesses)) {
753await delay(WEBSITE_VISIT_DELAY_MS);
754}
755log("SUCCESS", "ScrapeEmails", `Scraping done. Found emails for ${foundLeads.length} leads.`);
756return { mandateId, correlationId: taskId, payload: { leads: foundLeads } };
757}
810} catch (error: any) {
811log("ERROR", "DraftEmails", `Failed for ${lead.name}: ${error.message}`, error);
812finalLeads.push({ ...lead, draftedEmail: "[OpenAI API call failed]" });
813}
814await delay(300); // Small delay between OpenAI calls
1117<body><h1>Superpowered Agent Platform - Lead Gen Demo</h1>
1118<p>Runs <code>leadGenWorkflowV1</code>. See <a href="/">Original V3 Demo</a>.</p>
1119<p><strong>Note:</strong> Google Search is simulated. Scraping is basic.</p>
1120<form id="leadGenForm">
1121<label for="searchQuery">Search Query (Required):</label><input type="text" id="searchQuery" name="searchQuery" required value="dentists in Los Angeles">
61const fetchStories = async () => {
62try {
63const response = await fetch("/api/stories");
64if (!response.ok) throw new Error("Failed to fetch dates");
65const data = await response.json();
75try {
76dispatch({ type: "loading", value: true });
77const response = await fetch(`/api/comments?query=${encodeURIComponent(query)}&story=${story}&page=${page}`);
78if (!response.ok) throw new Error("Failed to fetch comments");
79const data = await response.json();
364export default async function(req: Request): Promise<Response> {
365const url = new URL(req.url);
366if (url.pathname === "/api/stories") {
367const storySearch = await hnSearch({
368search_by_date: true,
385}
386387if (url.pathname === "/api/comments") {
388const params = url.searchParams;
389const query = params.get("query") || "";
440441function ProductCarousel({ children }: { children: React.ReactNode }) {
442const [emblaRef, emblaApi] = useEmblaCarousel({
443axis: "x",
444loop: false,
465466useEffect(() => {
467if (emblaApi) {
468scrollByRef.current = (delta: number) => {
469isScrollingRef.current = true;
470const scrollResult = emblaApi.scrollTo(emblaApi.selectedScrollSnap() + Math.sign(delta));
471472if (scrollResult && typeof scrollResult.then === "function") {
479};
480481const rootNode = emblaApi.rootNode();
482rootNode.addEventListener("wheel", onWheel, { passive: false });
483rootNode.style.overflowY = "auto";
488};
489}
490}, [emblaApi, onWheel]);
491492return (
690691const script = document.createElement("script");
692script.src = `https://maps.googleapis.com/maps/api/js?key=AIzaSyAOtUMb5jLTjTVM7iKzIx2SJ3HgMKNcM7U&libraries=places`;
693script.async = true;
694script.defer = true;
814// Reverse geocode the coordinates to get an address
815const response = await fetch(
816`https://maps.googleapis.com/maps/api/geocode/json?latlng=${position.coords.latitude},${position.coords.longitude}&key=AIzaSyAOtUMb5jLTjTVM7iKzIx2SJ3HgMKNcM7U`,
817);
818const data = await response.json();
1184});
11851186app.post("/api", async (c) => {
1187console.log(c.req.body);
1188return c.json({ ok: true });
stevensDemoREADME.md1 match
53You'll need to set up some environment variables to make it run.
5455- `ANTHROPIC_API_KEY` for LLM calls
56- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.
57- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.
reactHonoStarterindex.ts2 matches
12app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
1314// Add your API routes here
15// app.get("/api/data", c => c.json({ hello: "world" }));
1617// Unwrap and rethrow Hono errors as the original error
linearStandupmain.tsx9 matches
5758export async function exec(interval: Interval) {
59const apiKey = Deno.env.get("LINEAR_API_KEY");
60if (!apiKey) {
61console.error("LINEAR_API_KEY not found in environment variables");
62Deno.exit(1);
63}
65const { startDate, endDate } = getYesterdayDateRange();
6667const response = await fetch("https://api.linear.app/graphql", {
68method: "POST",
69headers: {
70"Content-Type": "application/json",
71Authorization: apiKey,
72},
73body: JSON.stringify({
8081if (data.errors) {
82console.error("Error fetching data from Linear API:", data.errors);
83Deno.exit(1);
84}
94}
9596const historyResponse = await fetch("https://api.linear.app/graphql", {
97method: "POST",
98headers: {
99"Content-Type": "application/json",
100Authorization: apiKey,
101},
102body: JSON.stringify({
190}
191192const slackResponse = await fetch("https://slack.com/api/chat.postMessage", {
193method: "POST",
194headers: {
little-placemain.tsx9 matches
81async function fetchAndUpdateCanvas() {
82try {
83const response = await fetch("/api/canvas-state");
84if (!response.ok) {
85const errorText = await response.text().catch(() => "Unknown server error (canvas-state)");
92drawCanvas(data.state);
93} else {
94console.error("Invalid data received from /api/canvas-state:", data);
95drawCanvas([]); // Draw empty if data is not as expected
96}
120121try {
122const toggleResponse = await fetch("/api/toggle-square", {
123method: "POST",
124headers: {
146const data = await toggleResponse.json();
147if (data && data.state) {
148// API returns the new state, use it directly.
149drawCanvas(data.state);
150} else {
151console.error("Invalid data received from /api/toggle-square:", data);
152// Fallback to full refresh if data from toggle is not as expected.
153await fetchAndUpdateCanvas();
181const url = new URL(req.url);
182183// API endpoint to get the current state of all filled squares
184if (url.pathname === "/api/canvas-state" && req.method === "GET") {
185try {
186const filledSquares = await getCanvasState();
197}
198199// API endpoint to toggle the state of a square
200if (url.pathname === "/api/toggle-square" && req.method === "POST") {
201try {
202const { x, y } = await req.json();
7<title>Val Town Hall Countdown</title>
8<script src="https://cdn.twind.style" crossorigin></script>
9<link rel="preconnect" href="https://fonts.googleapis.com">
10<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
12<script src="https://esm.town/v/std/catch"></script>
13<style>
36}));
3738// token middleware for API requests
39app.all("/api/*", async (c, next) => {
40const sessionCookie = getCookie(c, "_session");
41if (!sessionCookie) {
47});
4849app.route("/api", backend);
5051app.get("/frontend/*", c => {
Townie-02useUser.tsx1 match
1import { useState, useEffect } from "https://esm.sh/react@18.2.0?dev";
23const USER_ENDPOINT = "/api/user";
45export function useUser () {