1export default async function (interval: Interval) {
2
3}
URLReceivermainFunctionTest2 matches
1import { expect } from "jsr:@std/expect";
2import { checkWebsite } from "./mainFunctionURLReciver2";
34console.log("Starting Website Checker Tests");
12];
1314async function runTests() {
15console.log("\nTesting valid website URL");
16let result = await checkWebsite(TEST_URLS[0]);
URLReceiversummaryURLReceiverTest7 matches
47interface TestCase {
48description: string;
49function: Function;
50expectedBehavior: string;
51}
5253function logTestInfo(message: string) {
54console.log(` ${message}`);
55}
59description: "Initialize generator",
60expectedBehavior: "Should start with empty state",
61function: () => {
62console.log("\nTEST: Initialize generator");
63console.log("Expected: Should start with no URLs processed\n");
83description: "Process test URLs",
84expectedBehavior: "Should identify working and broken URLs",
85function: () => {
86console.log("\nTEST: Processing multiple URLs");
87console.log("Expected: Should correctly identify good and bad URLs\n");
124description: "Test error handling",
125expectedBehavior: "Should handle different types of errors",
126function: () => {
127console.log("\nTEST: Error handling");
128console.log("Expected: Should identify and explain different errors\n");
182];
183184async function runTests() {
185console.log("Starting test run...\n");
186let passed = 0;
189for (const test of tests) {
190try {
191await test.function();
192console.log("\nā TEST PASSED");
193passed++;
URLReceiverurlCrawlerTests8 matches
17inputs: Record<string, unknown>;
18expectedBehavior: string;
19function: Function;
20}
2127inputs: {},
28expectedBehavior: "should return initial progress state",
29function: () => {
30crawler.reset();
31const progress = crawler.getProgress();
41inputs: { url: TEST_URLS[0] },
42expectedBehavior: "should not crawl beyond specified depth",
43function: async (inputs) => {
44// Create mock URLs with known depths
45const baseUrl = inputs.url;
105inputs: { url: TEST_URLS[0] },
106expectedBehavior: "should only crawl URLs from the same domain",
107function: async (inputs) => {
108const result = await crawler.crawl(inputs.url);
109133},
134expectedBehavior: "should normalize URLs consistently",
135function: async (inputs) => {
136const results = await Promise.all(
137inputs.testUrls.map(url => crawler.crawl(url)),
157},
158expectedBehavior: "should properly categorize different errors",
159function: async (inputs) => {
160const results = await Promise.all(
161inputs.testUrls.map(url => crawler.crawl(url)),
177];
178179async function runTests() {
180console.log("\nStarting enhanced test suite...");
181let passed = 0;
187188try {
189await test.function(test.inputs);
190console.log("ā Test passed\n");
191passed++;
OpenTowniegenerateCode.ts2 matches
1import OpenAI from "https://esm.sh/openai";
23function parseValResponse(response: string) {
4const codeBlockRegex = /```val type=(\w+)\n([\s\S]*?)```/;
5const match = response.match(codeBlockRegex);
25}
2627export async function generateCodeAnthropic(messages: Message[]): Promise<ValResponse | null> {
28const system = await (await fetch(`${import.meta.url.split("/").slice(0, -1).join("/")}/system_prompt.txt`)).text();
29
userEnrichmentserver.ts1 match
11let { query, dataRoutes } = createStaticHandler(routes);
1213export async function handler(request: Request) {
14// 1. run actions/loaders to get the routing context with `query`
15let context = await query(request);
userEnrichmenthome.tsx1 match
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
23export default function Home() {
4return <h1>This is just a test!</h1>;
5}
OpenTownieindex.tsx4 matches
5import { generateCodeAnthropic, makeFullPrompt } from "./backend/generateCode";
67function App() {
8const [messages, setMessages] = useState<{ content: string; role: string }[]>([]);
9const [inputMessage, setInputMessage] = useState("make a todo app");
11const [bearerToken, _setBearerToken] = useState(localStorage.getItem("val-town-bearer"));
1213function setBearerToken(token: string) {
14_setBearerToken(token);
15localStorage.setItem("val-town-bearer", token);
79}
8081function client() {
82createRoot(document.getElementById("root")).render(<App />);
83}
84if (typeof document !== "undefined") { client(); }
8586export default async function server(req: Request): Promise<Response> {
87// console.log(req);
88if (req.method === "POST") {
OpenTowniesystem_prompt.txt17 matches
101. `http`: http vals export a default server request handler.
112. `script`: script vals can be imported into other vals, similar to an npm package.
123. `cron`: cron vals export a function that can automatically run at user-set intervals, similar to a cron command.
134. `email`: email vals export a function that runs when its associated email address receives an email.
1415Follow these requirements for Val Town when generating code.
49</requirements>
5051If the user asks for specific functionality, the Val Town standard library includes the following:
5253<libraries>
63```
6465Blob storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
66`const { blob } = await import("https://esm.town/v/std/blob");`
67</library>
78If you are changing a SQLite table's schema, you should also change the table's name so it creates a fresh table, ie by adding _2 or _3 after it everywhere. Ensure that tables are created before they are used.
7980SQLite storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
81`const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");`
82</library>
99```
100101OpenAI only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
102`const { OpenAI } = await import "https://esm.town/v/std/openai");`
103</library>
113```
114115Email only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
116`const { email } = await import "https://esm.town/v/std/email");`
117</library>
131Write the code in ```val code fences.
132Include the val type as metadata on the code fence, e.g.: ```val type=script
133If this is a new val, decide what val type is appropriate based on the user's prompt. Default to choosing http type vals unless the user has requested specific functionality that requires a different type.
134135* If the user requests diff format in their prompt, follow these steps:
157* Use fetch to communicate with the backend server portion.
158*/
159function App() {
160return (
161<div>
167/**
168* Client-only code
169* Any code that makes use of document or window should be scoped to the `client()` function.
170* This val should not cause errors when imported as a module in a browser.
171*/
172function client() {
173createRoot(document.getElementById("root")).render(<App />);
174}
177/**
178* Server-only code
179* Any code that is meant to run on the server should be included in the server function.
180* This can include endpoints that the client side component can send fetch requests to.
181*/
182export default async function server(request: Request): Promise<Response> {
183/** If needed, blob storage or sqlite can be imported as a dynamic import in this function.
184* Blob storage should never be used in the browser directly.
185* Other server-side specific modules can be imported in a similar way.
232```val type=script
233/** Use this template for creating script vals only */
234export default function () {
235return "Hello, world";
236}
243```val type=cron
244/** Use this template for creating cron vals only */
245export default async function (interval: Interval) {
246// code will run at an interval set by the user
247console.log(`Hello, world: ${Date.now()}`);
270// The email address for this val will be `<username>.<valname>@valtown.email` which can be derived from:
271// const emailAddress = new URL(import.meta.url).pathname.split("/").slice(-2).join(".") + "@valtown.email";
272export default async function (e: Email) {
273console.log("Email received!", email.from, email.subject, email.text);
274}
vbloghono-adapter6 matches
7const app = new Hono();
89function Style() {
10return <style>{`body{margin:0;padding:32px;font-family:Menlo, monospace}`}</style>;
11}
1213function Home(data: Data, c: Context) {
14return (
15<div>
29}
3031function Post(data: Data, c: Context) {
32const name = c.req.param("post");
33const post = data.posts.find(p => p.name === name);
46}
4748function NotFound(data: Data, c: Context) {
49const name = c.req.param("post");
50return (
59type RouteComponent = (data: Data, context: Context<any, any, {}>) => JSX.Element;
6061function route(Component: RouteComponent, data: Data) {
62return async (c) => c.html(Component(data, c));
63}
6465export default function honoAdapter(data: Data) {
66app.get("/", route(Home, data));
67app.get("/posts/:post", route(Post, data));