';
// "Run"
- if (exampleID)
- html += ``;
+ if (exampleID == "intro-chatgpt")
+ html += ``;
+ else
+ html += ``;
// "Copy"
html += '
';
@@ -689,6 +692,7 @@ generateDocumentation('./src');
generateRedirects();
generateSitemap();
generateLLMs();
+generatePlayground();
if (anyErrors) {
process.exit(1);
diff --git a/src/examples.js b/src/examples.js
new file mode 100644
index 0000000..b0afcf3
--- /dev/null
+++ b/src/examples.js
@@ -0,0 +1,529 @@
+const examples = [
+ {
+ title: 'Introduction',
+ children: [
+ {
+ title: 'Hello World',
+ description: 'Try Puter.js instantly with interactive examples in your browser. Run, edit, and experiment with code - no installation or setup required.',
+ slug: '',
+ source: '/playground/examples/intro-chatgpt.html'
+ },
+ {
+ title: 'Image Analysis',
+ description: 'Analyze images with AI using Puter.js. Run and experiment with this GPT Vision example directly in the playground.',
+ slug: 'intro-gpt-vision',
+ source: '/playground/examples/intro-gpt-vision.html'
+ },
+ {
+ title: 'Cloud Storage',
+ description: 'Write files to cloud storage with Puter.js filesystem API. Run and modify this code example instantly in your browser.',
+ slug: 'intro-fs-write',
+ source: '/playground/examples/intro-fs-write.html'
+ },
+ {
+ title: 'Key-Value Store',
+ description: 'Store and retrieve data with Puter.js key-value API. Run and experiment with this working code in the playground.',
+ slug: 'intro-kv-set',
+ source: '/playground/examples/intro-kv-set.html'
+ },
+ {
+ title: 'Publish a Website',
+ description: 'Deploy websites instantly with Puter.js hosting API. Run and modify this example to publish your own site directly in the playground.',
+ slug: 'intro-hosting',
+ source: '/playground/examples/intro-hosting.html'
+ },
+ {
+ title: 'Authentication',
+ description: 'Implement user authentication with Puter.js auth API. Run and experiment with this sign-in example in the playground.',
+ slug: 'intro-auth',
+ source: '/playground/examples/intro-auth.html'
+ }
+ ]
+ },
+ {
+ title: 'AI',
+ children: [
+ {
+ title: 'Chat with GPT-5 nano',
+ description: 'Chat with GPT-5 nano using Puter.js AI API. Run and experiment with this chatbot example directly in the playground.',
+ slug: 'ai-chatgpt',
+ source: '/playground/examples/ai-chatgpt.html'
+ },
+ {
+ title: 'Image Analysis',
+ description: 'Analyze images with AI using Puter.js GPT Vision API. Run and modify this code example instantly in your browser.',
+ slug: 'ai-gpt-vision',
+ source: '/playground/examples/ai-gpt-vision.html'
+ },
+ {
+ title: 'Stream the response',
+ description: 'Stream AI chat responses in real-time with Puter.js. Run and experiment with this streaming example in the playground.',
+ slug: 'ai-chat-stream',
+ source: '/playground/examples/ai-chat-stream.html'
+ },
+ {
+ title: 'Function Calling',
+ description: 'Try AI function calling with Puter.js. Run and experiment with this advanced example directly in the playground.',
+ slug: 'ai-function-calling',
+ source: '/playground/examples/ai-function-calling.html'
+ },
+ {
+ title: 'AI Resume Analyzer (File handling)',
+ description: 'Try an AI resume analyzer with file handling and GPT integration. Run and experiment with this Puter.js example directly in your browser.',
+ slug: 'ai-resume-analyzer',
+ source: '/playground/examples/ai-resume-analyzer.html'
+ },
+ {
+ title: 'Chat with OpenAI o3-mini',
+ description: 'Chat with OpenAI o3-mini using Puter.js AI API. Run and experiment with this example directly in the playground.',
+ slug: 'ai-chat-openai-o3-mini',
+ source: '/playground/examples/ai-chat-openai-o3-mini.html'
+ },
+ {
+ title: 'Chat with Claude Sonnet',
+ description: 'Chat with Claude Sonnet using Puter.js AI API. Run and experiment with this example directly in the playground.',
+ slug: 'ai-chat-claude',
+ source: '/playground/examples/ai-chat-claude.html'
+ },
+ {
+ title: 'Chat with DeepSeek',
+ description: 'Chat with DeepSeek using Puter.js AI API. Run and experiment with this example directly in the playground.',
+ slug: 'ai-chat-deepseek',
+ source: '/playground/examples/ai-chat-deepseek.html'
+ },
+ {
+ title: 'Chat with Gemini',
+ description: 'Chat with Google Gemini using Puter.js AI API. Run and experiment with this example directly in the playground.',
+ slug: 'ai-chat-gemini',
+ source: '/playground/examples/ai-chat-gemini.html'
+ },
+ {
+ title: 'Chat with xAI (Grok)',
+ description: 'Chat with xAI Grok using Puter.js AI API. Run and experiment with this example directly in the playground.',
+ slug: 'ai-xai',
+ source: '/playground/examples/ai-xai.html'
+ },
+ {
+ title: 'Extract Text from Image',
+ description: 'Extract text from images using Puter.js AI API. Run and modify this OCR example instantly in your browser.',
+ slug: 'ai-img2txt',
+ source: '/playground/examples/ai-img2txt.html'
+ },
+ {
+ title: 'Text to Image',
+ description: 'Generate images from text with Puter.js AI API. Run and experiment with this text-to-image example in the playground.',
+ slug: 'ai-txt2img',
+ source: '/playground/examples/ai-txt2img.html'
+ },
+ {
+ title: 'Text to Image with options',
+ description: 'Generate images with custom options using Puter.js AI API. Run and experiment with advanced text-to-image parameters in the playground.',
+ slug: 'ai-txt2img-options',
+ source: '/playground/examples/ai-txt2img-options.html'
+ },
+ {
+ title: 'Text to Image with image-to-image generation',
+ description: 'Transform images with AI using Puter.js image-to-image generation. Run and experiment with this example directly in the playground.',
+ slug: 'ai-txt2img-image-to-image',
+ source: '/playground/examples/ai-txt2img-image-to-image.html'
+ },
+ {
+ title: 'Text to Speech',
+ description: 'Convert text to speech with Puter.js AI API. Run and experiment with this TTS example directly in the playground.',
+ slug: 'ai-txt2speech',
+ source: '/playground/examples/ai-txt2speech.html'
+ },
+ {
+ title: 'Text to Speech with options',
+ description: 'Generate speech with custom voice options using Puter.js AI API. Run and experiment with advanced TTS parameters in the playground.',
+ slug: 'ai-txt2speech-options',
+ source: '/playground/examples/ai-txt2speech-options.html'
+ },
+ {
+ title: 'Text to Speech with engines',
+ description: 'Try different TTS engines with Puter.js AI API. Run and compare speech synthesis options directly in the playground.',
+ slug: 'ai-txt2speech-engines',
+ source: '/playground/examples/ai-txt2speech-engines.html'
+ },
+ {
+ title: 'Text to Speech with OpenAI',
+ description: 'Generate speech with OpenAI voices using Puter.js AI API. Run and experiment with this TTS example in the playground.',
+ slug: 'ai-txt2speech-openai',
+ source: '/playground/examples/ai-txt2speech-openai.html'
+ },
+ {
+ title: 'Text to Video',
+ description: 'Generate videos from text with Puter.js AI API. Run and experiment with this text-to-video example in the playground.',
+ slug: 'ai-txt2vid',
+ source: '/playground/examples/ai-txt2vid.html'
+ },
+ {
+ title: 'Text to Video with options',
+ description: 'Generate videos with custom options using Puter.js AI API. Run and experiment with advanced text-to-video parameters in the playground.',
+ slug: 'ai-txt2vid-options',
+ source: '/playground/examples/ai-txt2vid-options.html'
+ }
+ ]
+ },
+ {
+ title: 'FileSystem',
+ children: [
+ {
+ title: 'Write File',
+ description: 'Write files to cloud storage with Puter.js filesystem API. Run and modify this code example instantly in your browser.',
+ slug: 'fs-write',
+ source: '/playground/examples/fs-write.html'
+ },
+ {
+ title: 'Read File',
+ description: 'Read files from cloud storage with Puter.js filesystem API. Run and experiment with this code example in the playground.',
+ slug: 'fs-read',
+ source: '/playground/examples/fs-read.html'
+ },
+ {
+ title: 'Make a Directory',
+ description: 'Create directories with Puter.js filesystem API. Run and modify this code example instantly in your browser.',
+ slug: 'fs-mkdir',
+ source: '/playground/examples/fs-mkdir.html'
+ },
+ {
+ title: 'Delete',
+ description: 'Delete files with Puter.js filesystem API. Run and experiment with this code example directly in the playground.',
+ slug: 'fs-delete',
+ source: '/playground/examples/fs-delete.html'
+ },
+ {
+ title: 'Read Directory',
+ description: 'List directory contents with Puter.js filesystem API. Run and modify this code example instantly in your browser.',
+ slug: 'fs-readdir',
+ source: '/playground/examples/fs-readdir.html'
+ },
+ {
+ title: 'Rename',
+ description: 'Rename files and directories with Puter.js filesystem API. Run and experiment with this code example in the playground.',
+ slug: 'fs-rename',
+ source: '/playground/examples/fs-rename.html'
+ },
+ {
+ title: 'Get File/Directory Info',
+ description: 'Get file metadata with Puter.js filesystem API. Run and modify this stat example instantly in your browser.',
+ slug: 'fs-stat',
+ source: '/playground/examples/fs-stat.html'
+ },
+ {
+ title: 'Copy File/Directory',
+ description: 'Copy files and directories with Puter.js filesystem API. Run and experiment with this code example in the playground.',
+ slug: 'fs-copy',
+ source: '/playground/examples/fs-copy.html'
+ },
+ {
+ title: 'Move File/Directory',
+ description: 'Move files and directories with Puter.js filesystem API. Run and modify this code example instantly in your browser.',
+ slug: 'fs-move',
+ source: '/playground/examples/fs-move.html'
+ },
+ {
+ title: 'Upload',
+ description: 'Upload files with Puter.js filesystem API. Run and experiment with this file upload example directly in the playground.',
+ slug: 'fs-upload',
+ source: '/playground/examples/fs-upload.html'
+ },
+ {
+ title: 'Write a file with deduplication',
+ description: 'Write files with automatic deduplication using Puter.js. Run and experiment with this example directly in the playground.',
+ slug: 'fs-write-dedupe',
+ source: '/playground/examples/fs-write-dedupe.html'
+ },
+ {
+ title: 'Create a new file with input coming from a file input',
+ description: 'Create files from file input elements with Puter.js. Run and experiment with this example directly in the playground.',
+ slug: 'fs-write-from-input',
+ source: '/playground/examples/fs-write-from-input.html'
+ },
+ {
+ title: 'Create a file in a directory that does not exist',
+ description: 'Write files with automatic parent directory creation using Puter.js. Run and experiment with this example in the playground.',
+ slug: 'fs-write-create-missing-parents',
+ source: '/playground/examples/fs-write-create-missing-parents.html'
+ },
+ {
+ title: 'Create a directory with deduplication',
+ description: 'Create directories with automatic deduplication using Puter.js. Run and modify this code example instantly in your browser.',
+ slug: 'fs-mkdir-dedupe',
+ source: '/playground/examples/fs-mkdir-dedupe.html'
+ },
+ {
+ title: 'Create a directory with missing parent directories',
+ description: 'Create nested directories automatically with Puter.js. Run and experiment with this example directly in the playground.',
+ slug: 'fs-mkdir-create-missing-parents',
+ source: '/playground/examples/fs-mkdir-create-missing-parents.html'
+ },
+ {
+ title: 'Move a file with missing parent directories',
+ description: 'Move files with automatic parent directory creation using Puter.js. Run and experiment with this example in the playground.',
+ slug: 'fs-move-create-missing-parents',
+ source: '/playground/examples/fs-move-create-missing-parents.html'
+ },
+ {
+ title: 'Delete a directory',
+ description: 'Delete directories with Puter.js filesystem API. Run and modify this code example instantly in your browser.',
+ slug: 'fs-delete-directory',
+ source: '/playground/examples/fs-delete-directory.html'
+ }
+ ]
+ },
+ {
+ title: 'Key-Value Store',
+ children: [
+ {
+ title: 'Set',
+ description: 'Store data with Puter.js key-value API. Run and experiment with this set example directly in the playground.',
+ slug: 'kv-set',
+ source: '/playground/examples/kv-set.html'
+ },
+ {
+ title: 'Get',
+ description: 'Retrieve data with Puter.js key-value API. Run and modify this get example instantly in your browser.',
+ slug: 'kv-get',
+ source: '/playground/examples/kv-get.html'
+ },
+ {
+ title: 'Increment',
+ description: 'Increment numeric values with Puter.js key-value API. Run and experiment with this example in the playground.',
+ slug: 'kv-incr',
+ source: '/playground/examples/kv-incr.html'
+ },
+ {
+ title: 'Increment (Object value)',
+ description: 'Increment nested values in objects with Puter.js key-value API. Run and experiment with this example in the playground.',
+ slug: 'kv-incr-nested',
+ source: '/playground/examples/kv-incr-nested.html'
+ },
+ {
+ title: 'Decrement',
+ description: 'Decrement numeric values with Puter.js key-value API. Run and modify this code example instantly in your browser.',
+ slug: 'kv-decr',
+ source: '/playground/examples/kv-decr.html'
+ },
+ {
+ title: 'Decrement (Object value)',
+ description: 'Decrement nested values in objects with Puter.js key-value API. Run and experiment with this example in the playground.',
+ slug: 'kv-decr-nested',
+ source: '/playground/examples/kv-decr-nested.html'
+ },
+ {
+ title: 'Delete',
+ description: 'Delete key-value pairs with Puter.js API. Run and experiment with this delete example directly in the playground.',
+ slug: 'kv-del',
+ source: '/playground/examples/kv-del.html'
+ },
+ {
+ title: 'List',
+ description: 'List all keys with Puter.js key-value API. Run and modify this code example instantly in your browser.',
+ slug: 'kv-list',
+ source: '/playground/examples/kv-list.html'
+ },
+ {
+ title: 'Flush',
+ description: 'Clear all data with Puter.js key-value API. Run and experiment with this flush example in the playground.',
+ slug: 'kv-flush',
+ source: '/playground/examples/kv-flush.html'
+ },
+ {
+ title: "What's your name?",
+ description: 'Try a simple name storage app with Puter.js key-value API. Run and experiment with this interactive example in the playground.',
+ slug: 'kv-name',
+ source: '/playground/examples/kv-name.html'
+ }
+ ]
+ },
+ {
+ title: 'Networking',
+ children: [
+ {
+ title: 'Basic TCP Socket',
+ description: 'Create TCP socket connections with Puter.js networking API. Run and experiment with this example directly in the playground.',
+ slug: 'net-basic',
+ source: '/playground/examples/net-basic.html'
+ },
+ {
+ title: 'TLS Socket',
+ description: 'Create secure TLS connections with Puter.js networking API. Run and modify this code example instantly in your browser.',
+ slug: 'net-tls',
+ source: '/playground/examples/net-tls.html'
+ },
+ {
+ title: 'Fetch',
+ description: 'Make HTTP requests with Puter.js fetch API. Run and experiment with this example directly in the playground.',
+ slug: 'net-fetch',
+ source: '/playground/examples/net-fetch.html'
+ }
+ ]
+ },
+ {
+ title: 'Hosting',
+ children: [
+ {
+ title: 'Create a simple website displaying "Hello world!"',
+ description: 'Deploy a simple website instantly with Puter.js hosting API. Run and experiment with this example directly in the playground.',
+ slug: 'hosting-create',
+ source: '/playground/examples/hosting-create.html'
+ },
+ {
+ title: 'Create 3 random websites and then list them',
+ description: 'Create and list multiple websites with Puter.js hosting API. Run and modify this code example instantly in your browser.',
+ slug: 'hosting-list',
+ source: '/playground/examples/hosting-list.html'
+ },
+ {
+ title: 'Create a random website then delete it',
+ description: 'Deploy and delete websites with Puter.js hosting API. Run and experiment with this example in the playground.',
+ slug: 'hosting-delete',
+ source: '/playground/examples/hosting-delete.html'
+ },
+ {
+ title: 'Update a subdomain to point to a new directory',
+ description: 'Update website subdomains with Puter.js hosting API. Run and modify this code example instantly in your browser.',
+ slug: 'hosting-update',
+ source: '/playground/examples/hosting-update.html'
+ },
+ {
+ title: 'Retrieve information about a subdomain',
+ description: 'Get website information with Puter.js hosting API. Run and experiment with this example directly in the playground.',
+ slug: 'hosting-get',
+ source: '/playground/examples/hosting-get.html'
+ }
+ ]
+ },
+ {
+ title: 'Authentication',
+ children: [
+ {
+ title: 'Sign in',
+ description: 'Implement user sign-in with Puter.js auth API. Run and experiment with this authentication example in the playground.',
+ slug: 'auth-sign-in',
+ source: '/playground/examples/auth-sign-in.html'
+ },
+ {
+ title: 'Sign out',
+ description: 'Sign out users with Puter.js auth API. Run and modify this code example instantly in your browser.',
+ slug: 'auth-sign-out',
+ source: '/playground/examples/auth-sign-out.html'
+ },
+ {
+ title: 'Check sign in',
+ description: 'Check authentication status with Puter.js auth API. Run and experiment with this example directly in the playground.',
+ slug: 'auth-is-signed-in',
+ source: '/playground/examples/auth-is-signed-in.html'
+ },
+ {
+ title: 'Get user',
+ description: 'Retrieve user information with Puter.js auth API. Run and modify this code example instantly in your browser.',
+ slug: 'auth-get-user',
+ source: '/playground/examples/auth-get-user.html'
+ },
+ {
+ title: "Get user's monthly usage",
+ description: 'Get user usage statistics with Puter.js auth API. Run and experiment with this example directly in the playground.',
+ slug: 'auth-get-monthly-usage',
+ source: '/playground/examples/auth-get-monthly-usage.html'
+ }
+ ]
+ },
+ {
+ title: 'Apps',
+ children: [
+ {
+ title: 'To-Do List',
+ description: 'Try a complete to-do list app built with Puter.js. Run, edit, and experiment with this working example in the playground.',
+ slug: 'app-todo',
+ source: '/playground/examples/app-todo.html'
+ },
+ {
+ title: 'AI Chat',
+ description: 'Try a complete AI chat app built with Puter.js. Run, edit, and experiment with this working example in the playground.',
+ slug: 'app-ai-chat',
+ source: '/playground/examples/app-ai-chat.html'
+ },
+ {
+ title: 'Camera Photo Describer',
+ description: 'Try a camera app with AI image analysis built with Puter.js. Run and experiment with this working example in the playground.',
+ slug: 'app-camera',
+ source: '/playground/examples/app-camera.html'
+ },
+ {
+ title: 'Text Summarizer',
+ description: 'Try an AI text summarizer app built with Puter.js. Run, edit, and experiment with this working example in the playground.',
+ slug: 'app-summarizer',
+ source: '/playground/examples/app-summarizer.html'
+ },
+ {
+ title: 'Create an app pointing to example.com',
+ description: 'Create app registrations with Puter.js apps API. Run and experiment with this example directly in the playground.',
+ slug: 'app-create',
+ source: '/playground/examples/app-create.html'
+ },
+ {
+ title: 'Create 3 random apps and then list them',
+ description: 'Create and list app registrations with Puter.js apps API. Run and modify this code example instantly in your browser.',
+ slug: 'app-list',
+ source: '/playground/examples/app-list.html'
+ },
+ {
+ title: 'Create a random app then delete it',
+ description: 'Create and delete app registrations with Puter.js apps API. Run and experiment with this example in the playground.',
+ slug: 'app-delete',
+ source: '/playground/examples/app-delete.html'
+ },
+ {
+ title: 'Create a random app then change its title',
+ description: 'Update app registrations with Puter.js apps API. Run and modify this code example instantly in your browser.',
+ slug: 'app-update',
+ source: '/playground/examples/app-update.html'
+ },
+ {
+ title: 'Create a random app then get it',
+ description: 'Get app information with Puter.js apps API. Run and experiment with this example directly in the playground.',
+ slug: 'app-get',
+ source: '/playground/examples/app-get.html'
+ }
+ ]
+ },
+ {
+ title: 'Workers',
+ children: [
+ {
+ title: 'Create a worker',
+ description: 'Deploy serverless workers with Puter.js workers API. Run and experiment with this example directly in the playground.',
+ slug: 'workers-create',
+ source: '/playground/examples/workers-create.html'
+ },
+ {
+ title: 'List workers',
+ description: 'List all workers with Puter.js workers API. Run and modify this code example instantly in your browser.',
+ slug: 'workers-list',
+ source: '/playground/examples/workers-list.html'
+ },
+ {
+ title: 'Get a worker',
+ description: 'Get worker information with Puter.js workers API. Run and experiment with this example in the playground.',
+ slug: 'workers-get',
+ source: '/playground/examples/workers-get.html'
+ },
+ {
+ title: 'Workers Management',
+ description: 'Manage workers with Puter.js workers API. Run and modify this complete management example instantly in your browser.',
+ slug: 'workers-management',
+ source: '/playground/examples/workers-management.html'
+ },
+ {
+ title: 'Authenticated Worker Requests',
+ description: 'Execute authenticated worker requests with Puter.js workers API. Run and experiment with this example in the playground.',
+ slug: 'workers-exec',
+ source: '/playground/examples/workers-exec.html'
+ }
+ ]
+ }
+];
+
+module.exports = examples;
\ No newline at end of file
diff --git a/src/playground.js b/src/playground.js
new file mode 100644
index 0000000..f88233a
--- /dev/null
+++ b/src/playground.js
@@ -0,0 +1,173 @@
+const fs = require('fs');
+const path = require('path');
+const examples = require('./examples')
+
+// Function to generate sidebar HTML
+const generateSidebarHtml = (sections) => {
+ let sidebarHtml = '