14 "redirect": req.redirect,
15 "searchParams": Object.fromEntries(searchParams.entries()),
16 "docs": "https://developer.mozilla.org/en-US/docs/Web/API/Request",
17 });
18};
2import { getCurrentWeather } from "https://esm.town/v/cosmo/get_current_weather";
3
4export async function getWeatherMessage(apiKey, latitude, longitude) {
5 const currentWeather = await getCurrentWeather(latitude, longitude),
6 { icon } = currentWeather,
27 { role: "user", content: JSON.stringify(weather) },
28 ],
29 chatResponse = await chat(apiKey, messages),
30 message = chatResponse.choices[0].message.content;
31
1export async function getCurrentWeather(latitude = 0, longitude = 0) {
2 const pointsResponse = await fetch(`https://api.weather.gov/points/${latitude},${longitude}`),
3 { properties: { forecastHourly } } = await pointsResponse.json(),
4 forecastResponse = await fetch(forecastHourly),
15 <link
16 rel="preload"
17 href="https://fonts.googleapis.com/css?family=Inter:300,400,500"
18 as="style"
19 type="text/css"
20 />
21 <link
22 href="https://fonts.googleapis.com/css?family=Material+Icons&display=swap"
23 rel="stylesheet"
24 />
1# Echo incoming request as JSON
2See https://developer.mozilla.org/en-US/docs/Web/API/Request
3
4
1import { saveToTana } from "https://esm.town/v/nbbaier/saveToTana";
2import { APIPlainNode } from "https://esm.town/v/nbbaier/tanaTypes";
3import { Hono } from "npm:hono";
4
5const token = Deno.env.get("tanaInputAPI");
6
7export const honoTanaEndpoint = async (req: Request) => {
10 let { text, url } = c.req.query();
11
12 const payload: APIPlainNode = {
13 name: text,
14 children: [
7 privacy?: "public" | "unlisted" | "private";
8}) => {
9 return fetchJSON("https://api.val.town/v1/vals", {
10 method: "post",
11 bearer: token,
1import { paginateAPI } from "https://esm.town/v/andreterron/paginateAPI";
2import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
3import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
4
11};
12const me = await fetchJSON(
13 `${API_URL}/v1/me`,
14 opts,
15);
16// TODO: Paginate
17const vals = await paginateAPI(
18 `${API_URL}/v1/users/${me.id}/vals?limit=100`,
19 opts,
20);
2 // try/catch prevents crashes if the script doesn't have env access
3 try {
4 return Deno.env.get("VALTOWN_API_URL");
5 } catch {}
6}
7
8export const API_URL = envOrUndefined("VALTOWN_API_URL") ?? "https://api.val.town";
1const { default: OpenAI } = await import("npm:openai");
2
3export async function chat(apiKey, messages) {
4 const openai = new OpenAI({ apiKey });
5
6 return openai.chat.completions.create({