2import { ITERATIONS_TABLE, KEY, PROJECTS_TABLE, SCHEMA_VERSION } from "./migrations.ts";
3
4export async function createProject(prompt: string) {
5 const projectResult = await sqlite.execute(
6 `INSERT INTO ${PROJECTS_TABLE} (initial_prompt) VALUES (?)`,
11}
12
13export async function getNextVersionNumber(projectId: number) {
14 const data = await sqlite.execute(
15 `SELECT version_number FROM ${ITERATIONS_TABLE}
21}
22
23export async function insertVersion(projectId: number, versionNumber: number, prompt: string, code: string) {
24 await sqlite.execute(
25 `INSERT INTO ${ITERATIONS_TABLE}
29}
30
31export async function getCodeInner(table: string, project: string, version?: string) {
32 let data;
33 if (version === undefined) {
50}
51
52export async function getCode(project: string, version?: string) {
53 // try to get code in the new table partition first
54 const code = await getCodeInner(ITERATIONS_TABLE, project, version);
7export const ITERATIONS_TABLE = "cerebras_coder_iterations";
8
9export async function createTables() {
10 await sqlite.execute(`
11 CREATE TABLE IF NOT EXISTS ${PROJECTS_TABLE} (
6await createTables();
7
8export default async function cerebras_coder(req: Request): Promise<Response> {
9 if (req.method === "POST") {
10 let { prompt, currentCode, versionHistory, projectId } = await req.json();
23);
24
25function Hero({
26 prompt,
27 setPrompt,
44
45 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
46 Turn your ideas into fully functional apps in{" "}
47 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
48 less than a second
115}
116
117function App() {
118 const previewRef = React.useRef<HTMLDivElement>(null);
119 const [prompt, setPrompt] = useState("");
169 });
170
171 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
172 setLoading(true);
173 setTimeout(() => handleSubmit(promptItem.prompt), 0);
174 }
175
176 async function handleSubmit(e: React.FormEvent | string) {
177 if (typeof e !== "string") {
178 e.preventDefault();
225 }
226
227 function handleVersionChange(direction: "back" | "forward") {
228 const { currentVersionIndex, versions } = versionHistory;
229 if (direction === "back" && currentVersionIndex > 0) {
973);
974
975function client() {
976 const path = window.location.pathname;
977 const root = createRoot(document.getElementById("root")!);
19 <meta property="og:site_name" content="Cerebras Coder">
20 <meta property="og:url" content="https://cerebrascoder.com"/>
21 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
22 <meta property="og:type" content="website">
23 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
2import STARTER_PROMPTS from "../public/starter-prompts.js";
3
4function extractCodeFromFence(text: string): string {
5 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
6 return htmlMatch ? htmlMatch[1].trim() : text;
7}
8
9export async function generateCode(prompt: string, currentCode: string) {
10 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
11 if (starterPrompt) {
1import { blob } from "https://esm.town/v/std/blob";
2
3export default async function(req: Request): Promise<Response> {
4 const url = new URL(req.url);
5
1// Val.town function to fetch and archive Bluesky posts (TypeScript)
2// This can be run as a cron job every 30 minutes
3
73const FETCH_FULL_HISTORY = false; // Change to false after initial import
74
75export default async function(): Promise<{
76 success: boolean;
77 error?: string;
202
203// Authenticate with Bluesky AT Protocol
204async function authenticateBluesky(handle: string, password: string): Promise<BlueskySession> {
205 const response = await fetch("https://bsky.social/xrpc/com.atproto.server.createSession", {
206 method: "POST",
223
224// Fetch posts from author's feed with pagination
225async function fetchAuthorFeed(
226 session: BlueskySession,
227 fetchFullHistory: boolean = false,
293
294// Extract media URLs from Bluesky post
295function extractBlueskyMedia(post: BlueskyPost): string[] {
296 const mediaUrls: string[] = [];
297
1// Val.town function to fetch and archive Mastodon posts
2// This can be run as a cron job every 30 minutes
3
8const MASTODON_USERNAME = "gabby"; // Just the username, no @ symbol
9
10export default async function(interval: Interval) {
11 // Initialize Supabase client
12 const supabaseUrl = Deno.env.get("SUPABASE_URL");
140}
141
142// Helper function to extract media URLs from Mastodon status
143function extractMastodonMedia(status) {
144 const mediaUrls = [];
145
161}
162
163// Helper function to convert HTML to plain text
164function stripHtml(html) {
165 // Basic HTML stripping - removes tags and decodes entities
166 return html
1// Val.town function to fetch and archive Micro.blog posts
2// This can be run as a cron job every 30 minutes
3
7const MICROBLOG_USERNAME = "welson";
8
9export default async function(interval: Interval) {
10 // Initialize Supabase client
11 const supabaseUrl = Deno.env.get("SUPABASE_URL");
112}
113
114// Helper function to extract media URLs from a post
115function extractMediaUrls(post) {
116 const mediaUrls = [];
117