6});
7
8const STEEL_API_KEY = process.env.STEEL_API_KEY;
9// Initialize Steel client with the API key from environment variables
10const client = new Steel({
11 steelAPIKey: STEEL_API_KEY,
12});
13
36 // Connect Puppeteer to the Steel session
37 browser = await puppeteer.connect({
38 browserWSEndpoint: `wss://connect.steel.dev?apiKey=${STEEL_API_KEY}&sessionId=${session.id}`,
39 });
40
15 */
16export async function redirectOriginalVals(
17 apiKey: string,
18 originalVals: any[],
19 projectName: string,
32 let endpointUrl: string | undefined; // Initialize as undefined, explicitly type
33 try {
34 const projectResponse = await fetch(`https://api.val.town/v1/alias/projects/${username}/${projectName}`, {
35 headers: {
36 "Authorization": `Bearer ${apiKey}`,
37 },
38 });
50
51 // Fetch the project files to get the endpoint URL
52 const filesResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=`, {
53 headers: {
54 "Authorization": `Bearer ${apiKey}`,
55 },
56 });
97 try {
98 // First, get the val ID
99 const valResponse = await fetch(`https://api.val.town/v1/alias/${valOwner}/${valName}`, {
100 headers: {
101 "Authorization": `Bearer ${apiKey}`,
102 },
103 });
138
139 // --- Step 2: Update Code ---
140 const versionUpdateUrl = `https://api.val.town/v1/vals/${valId}/versions`;
141 console.log(`Creating new version (code/privacy) for ${valOwner}/${valName} at: ${versionUpdateUrl}`);
142
151 method: "POST",
152 headers: {
153 "Authorization": `Bearer ${apiKey}`,
154 "Content-Type": "application/json",
155 },
167
168 // --- Step 3: Update README (Patch the Val) ---
169 const readmeUpdateUrl = `https://api.val.town/v1/vals/${valId}`;
170 console.log(`Updating README for ${valOwner}/${valName} at: ${readmeUpdateUrl}`);
171
177 method: "PUT", // Use PUT as documented for updating val properties
178 headers: {
179 "Authorization": `Bearer ${apiKey}`,
180 "Content-Type": "application/json",
181 },
12 */
13export async function createProjectFromVals(
14 apiKey: string,
15 vals: ValInfo[],
16 customProjectName?: string,
19 try {
20 // Validate inputs
21 if (!apiKey) {
22 throw new Error("API key is required");
23 }
24
35 projectId = existingProjectId;
36 // Fetch existing project details to get name and author
37 const projectDetailsResponse = await fetch(`https://api.val.town/v1/projects/${projectId}`, {
38 headers: { "Authorization": `Bearer ${apiKey}` },
39 });
40 if (!projectDetailsResponse.ok) {
67
68 // Create the new project
69 const projectResponse = await fetch("https://api.val.town/v1/projects", {
70 method: "POST",
71 headers: {
72 "Authorization": `Bearer ${apiKey}`,
73 "Content-Type": "application/json",
74 },
104 try {
105 // Fetch the val details
106 const valResponse = await fetch(`https://api.val.town/v1/alias/${valInfo.username}/${valInfo.valName}`, {
107 headers: { "Authorization": `Bearer ${apiKey}` },
108 });
109
155
156 // Add the file to the project (use the determined projectId)
157 const fileResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=${filePath}`, {
158 method: "POST",
159 headers: {
160 "Authorization": `Bearer ${apiKey}`,
161 "Content-Type": "application/json",
162 },
188 // Generate and add README.md
189 const readmeContent = generateReadme(finalProjectName, vals, convertedVals);
190 await fetch(`https://api.val.town/v1/projects/${projectId}/files/README.md`, {
191 method: "POST",
192 headers: {
193 "Authorization": `Bearer ${apiKey}`,
194 "Content-Type": "application/json",
195 },
104 // Analytics retrieval endpoint
105 if (url.pathname === "/analytics") {
106 const providedKey = request.headers.get("X-API-Key");
107
108 // Basic authentication
12 },
13 {
14 "prompt": "weather dashboard for nyc using open-meteo API for NYC with icons",
15 "title": "Weather App",
16 "code":
8
91. Sign up for [Cerebras](https://cloud.cerebras.ai/)
102. Get a Cerebras API Key
113. Save it in your project env variable called `CEREBRAS_API_KEY`
211 } catch (error) {
212 Toastify({
213 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
214 position: "center",
215 duration: 3000,
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>CerebrasCoder</title>
7 <link rel="preconnect" href="https://fonts.googleapis.com" />
8 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9 <link
10 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
11 rel="stylesheet"
12 />
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">
24
25
16 };
17 } else {
18 const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
19 const completion = await client.chat.completions.create({
20 messages: [
12 },
13 {
14 "prompt": "weather dashboard for nyc using open-meteo API for NYC with icons",
15 "title": "Weather App",
16 "code":