5import { renderToString } from "npm:react-dom/server";
67function StatusRow({ rows }) {
8return (
9<div className="w-full flex flex-col space-y-2">
28}
2930function StatusSection({ url, rows }) {
31const sectionRows = rows.filter(row => row[0] === url);
32const percentUp = Math.round((sectionRows.filter(row => row[1]).length / sectionRows.length) * 100);
44}
4546export default async function(req: Request): Promise<Response> {
47const { rows } = await sqlite.execute(
48"https://esm.town/v/pablobarcos/isMyWebsiteDown",
InvocationTracker_Testmain.tsx2 matches
2import { InvocationTracker } from 'https://esm.town/v/rozek/InvocationTracker'
34export default async function () {
5const TestCases = [
6/**** test constructor with valid inputs ****/
154/**** removeTable ****/
155156async function removeTable (TableName:string):Promise<void> {
157console.log('(cleaning up)')
158await sqlite.execute(
mightyAmberTakinmain.tsx10 matches
24);
2526function Hero({
27prompt,
28setPrompt,
4546<p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
47Turn your ideas into fully functional apps in{" "}
48<span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
49less than a second
116}
117118function App() {
119const previewRef = React.useRef<HTMLDivElement>(null);
120const [prompt, setPrompt] = useState("");
170});
171172function handleStarterPromptClick(promptItem: typeof prompts[number]) {
173setLoading(true);
174setTimeout(() => handleSubmit(promptItem.prompt), 0);
175}
176177async function handleSubmit(e: React.FormEvent | string) {
178if (typeof e !== "string") {
179e.preventDefault();
226}
227228function handleVersionChange(direction: "back" | "forward") {
229const { currentVersionIndex, versions } = versionHistory;
230if (direction === "back" && currentVersionIndex > 0) {
974);
975976function client() {
977const path = window.location.pathname;
978const root = createRoot(document.getElementById("root")!);
1010}
10111012function extractCodeFromFence(text: string): string {
1013const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1014return htmlMatch ? htmlMatch[1].trim() : text;
1015}
10161017async function generateCode(prompt: string, currentCode: string) {
1018const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1019if (starterPrompt) {
1059}
10601061export default async function server(req: Request): Promise<Response> {
1062// Dynamic import for SQLite to avoid client-side import
1063const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
moralCoffeeSkinkmain.tsx10 matches
24);
2526function Hero({
27prompt,
28setPrompt,
4546<p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
47Turn your ideas into fully functional apps in{" "}
48<span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
49less than a second
116}
117118function App() {
119const previewRef = React.useRef<HTMLDivElement>(null);
120const [prompt, setPrompt] = useState("");
170});
171172function handleStarterPromptClick(promptItem: typeof prompts[number]) {
173setLoading(true);
174setTimeout(() => handleSubmit(promptItem.prompt), 0);
175}
176177async function handleSubmit(e: React.FormEvent | string) {
178if (typeof e !== "string") {
179e.preventDefault();
226}
227228function handleVersionChange(direction: "back" | "forward") {
229const { currentVersionIndex, versions } = versionHistory;
230if (direction === "back" && currentVersionIndex > 0) {
974);
975976function client() {
977const path = window.location.pathname;
978const root = createRoot(document.getElementById("root")!);
1010}
10111012function extractCodeFromFence(text: string): string {
1013const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1014return htmlMatch ? htmlMatch[1].trim() : text;
1015}
10161017async function generateCode(prompt: string, currentCode: string) {
1018const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1019if (starterPrompt) {
1059}
10601061export default async function server(req: Request): Promise<Response> {
1062// Dynamic import for SQLite to avoid client-side import
1063const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
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}
linkInBioTemplatemain.tsx1 match
2import { renderToString } from "npm:react-dom/server";
34export default async function(req: Request) {
5return new Response(
6renderToString(
12});
1314async function main() {
15let session;
16let browser;
trackESMContentmain.tsx5 matches
10const TABLE_NAME = `${KEY}_versions_v1`;
1112async function fetchContent(url: string) {
13const response = await fetch(url);
14return await response.text();
15}
1617async function initializeDatabase() {
18await sqlite.execute(`
19CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
26}
2728export default async function(interval: Interval) {
29await initializeDatabase();
3056}
5758async function sha256(message: string): Promise<string> {
59const msgUint8 = new TextEncoder().encode(message);
60const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8);
64}
6566export async function getAllVersions() {
67await initializeDatabase();
68const versions = await sqlite.execute(`SELECT * FROM ${TABLE_NAME} ORDER BY timestamp DESC`);
12});
1314async function main() {
15let session;
16let browser;