1export default async function getValsContextWindow(model: any) {
2 const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
3
4 const API_URL = "https://api.val.town";
58 );
59 });
60 export default app.fetch;`,
61 },
62 {
118 {
119 prompt: "Write a val that accesses environment variables",
120 code: `const res = await fetch("${API_URL}/v1/me", {
121 headers: {
122 Authorization: \`Bearer \${Deno.env.get("valtown")}\`,
130 code: `import process from "node:process";
131
132 const res = await fetch("${API_URL}/v1/me", {
133 headers: {
134 Authorization: \`Bearer \${process.env.valtown}\`,
154 code: `import cheerio from "npm:cheerio";
155
156 const response = await fetch("https://example.com");
157 const body = await response.text();
158 const $ = cheerio.load(body);
528 {
529 role: "user",
530 content: "Write a val that fetches the weather in Brooklyn, NY",
531 },
532 {
533 role: "assistant",
534 content:
535 "```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m¤t_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
536 },
537 {
542 role: "assistant",
543 content:
544 "```ts\n/** @jsxImportSource npm:hono@3/jsx */\nimport { Hono } from \"npm:hono\";\n\nconst app = new Hono();\napp.get(\"/\", async (c) => {\n return c.html(\n <div>\n <form>\n Your name: <input type=\"text\" name=\"name\" /> <input type=\"submit\" />\n </form>\n Hello {c.req.query(\"name\")}\n </div>,\n );\n});\nexport default app.fetch;\n```",
545 },
546 ...templatePrompts,
18
19export async function checkIp() {
20 const result = await fetch(`https://ipqualityscore.com/api/json/ip/${ipqsApiKey}/${ipAddress}`);
21 const newData = await result.json();
22
34 // YOU MAY NOW RUN THE FILE.
35
36 const data = await fetch(
37 `https://api.stage.teamsurfboard.com/api/v1/schedule?start=${start.toISOString()}&end=${end.toISOString()}`,
38 {
54
55function Demo({ data }) {
56 if (!data) return <p>Failed to fetch</p>;
57
58 function processData(data) {
10
11 useEffect(() => {
12 async function fetchSchedule() {
13 await fetch("/schedule")
14 .then(response => {
15 return response.json();
21 }
22
23 fetchSchedule();
24 }, []);
25
62 const tomorrow = new Date(today);
63 tomorrow.setDate(tomorrow.getDate() + 1);
64 const data = await fetch(
65 `https://api.stage.teamsurfboard.com/api/v1/schedule?start=${today.toISOString()}&end=${tomorrow.toISOString()}`,
66 {
76});
77
78export default app.fetch;
37
38/**
39 * @param handler Fetch handler
40 * @param val Define which val should open
41 */
42export function modifyFetchHandler(
43 handler: (req: Request) => Response | Promise<Response>,
44 { val, style }: { val?: ValRef; style?: string } = {},
52}
53
54export default modifyFetchHandler;
8 const tomorrow = new Date(today);
9 tomorrow.setDate(tomorrow.getDate() + 1);
10 const data = await fetch(
11 `https://api.stage.teamsurfboard.com/api/v1/schedule?start=${today.toISOString()}&end=${tomorrow.toISOString()}`,
12 {
36};
37function Schedule({ data }) {
38 if (!data) return <p>Failed to fetch</p>;
39
40 const [hours, setHours] = useState(10);
28});
29
30export default app.fetch;
27 const authHeader = req.headers.get("Proxy-Authorization") || req.headers.get("Authorization");
28 const token = authHeader ? parseBearerString(authHeader) : undefined;
29 const meRes = await fetch(`${API_URL}/v1/me`, { headers: { Authorization: `Bearer ${token}` } });
30 if (!meRes.ok) {
31 return new Response("Unauthorized", { status: 401 });
62 });
63
64 const openAIRes = await fetch(url, {
65 method: req.method,
66 headers,
16}
17
18// Function to fetch package info from NPM registry
19async function fetchPackageInfo(packageName: string) {
20 const url = `https://registry.npmjs.org/${packageName}`;
21 const response = await fetch(url);
22 if (!response.ok) {
23 throw new Error(`Failed to fetch package info for ${packageName}`);
24 }
25 return response.json();
70async function checkPackageLicenses(packageJsonUrl: string): Promise<{ licenses: PackageLicense[]; repoName: string }> {
71 try {
72 const response = await fetch(packageJsonUrl);
73 if (!response.ok) {
74 throw new Error(`Failed to fetch package.json from ${packageJsonUrl}`);
75 }
76 const packageJson: PackageJson = await response.json();
83 for (const [name, version] of Object.entries(dependencies)) {
84 try {
85 const packageInfo = await fetchPackageInfo(name);
86 const license = extractLicenseInfo(packageInfo);
87 const repoUrl = extractGitHubRepoUrl(packageInfo);
165});
166
167export default app.fetch;
16}
17
18// Function to fetch package info from NPM registry
19async function fetchPackageInfo(packageName: string) {
20 const url = `https://registry.npmjs.org/${packageName}`;
21 const response = await fetch(url);
22 if (!response.ok) {
23 throw new Error(`Failed to fetch package info for ${packageName}`);
24 }
25 return response.json();
45
46async function getGithubReleases(repo: string): Promise<GithubRelease[]> {
47 const response = await fetch(`https://api.github.com/repos/${repo}/releases`);
48 if (!response.ok) {
49 throw new Error(`Failed to fetch releases from ${repo}`);
50 }
51 return response.json();
76async function checkNpmUpdates(packageJsonUrl: string): Promise<string> {
77 try {
78 const response = await fetch(packageJsonUrl);
79 if (!response.ok) {
80 throw new Error(`Failed to fetch package.json from ${packageJsonUrl}`);
81 }
82 const packageJson: PackageJson = await response.json();
89 for (const [name, version] of Object.entries(dependencies)) {
90 try {
91 const packageInfo = await fetchPackageInfo(name);
92 const repoUrl = extractGitHubRepoUrl(packageInfo);
93 if (!repoUrl) {
114 for (const [name, version] of Object.entries(devDependencies)) {
115 try {
116 const packageInfo = await fetchPackageInfo(name);
117 const repoUrl = extractGitHubRepoUrl(packageInfo);
118 if (!repoUrl) {
178});
179
180export default app.fetch;