diff --git a/src/AI/chat.md b/src/AI/chat.md
index f1bbe07..a677119 100755
--- a/src/AI/chat.md
+++ b/src/AI/chat.md
@@ -159,7 +159,7 @@ We use different vendors for different models and try to use the best vendor ava
diff --git a/src/AI/txt2img.md b/src/AI/txt2img.md
index 7f5e618..7003545 100755
--- a/src/AI/txt2img.md
+++ b/src/AI/txt2img.md
@@ -124,7 +124,7 @@ A `Promise` that resolves to an `HTMLImageElement`. The elementβs `src` points
diff --git a/src/playground/examples/ai-chat-claude.html b/src/playground/examples/ai-chat-claude.html
index db57335..2ec8486 100644
--- a/src/playground/examples/ai-chat-claude.html
+++ b/src/playground/examples/ai-chat-claude.html
@@ -3,8 +3,8 @@
diff --git a/src/playground/examples/ai-chat-gemini.html b/src/playground/examples/ai-chat-gemini.html
index 2e311c1..f99dfa4 100644
--- a/src/playground/examples/ai-chat-gemini.html
+++ b/src/playground/examples/ai-chat-gemini.html
@@ -3,15 +3,17 @@
-
π Workers Exec - Authenticated Requests
+
Workers Exec - Authenticated Requests
Test authenticated requests to worker endpoints using puter.workers.exec().
-
π Setup
+
Setup
First, create a test worker with the following code:
Worker Name:
-
+
-
π Create Test Worker
+
Create Test Worker
-
π§ Request Builder
+
Request Builder
GET
@@ -265,7 +272,7 @@
π§ Request Builder
Endpoint:
-
+
@@ -278,29 +285,29 @@
π§ Request Builder
-
π Execute Request
-
π§ͺ Test All Endpoints
+
Execute Request
+
Test All Endpoints
-
β‘ Quick Tests
-
π Test Hello
-
π€ Test User Profile
-
π Test POST Data
-
βοΈ Test PUT Settings
-
ποΈ Test DELETE Resource
-
π₯ Test Health
+
Quick Tests
+
Test Hello
+
Test User Profile
+
Test POST Data
+
Test PUT Settings
+
Test DELETE Resource
+
Test Health
-
π¦ Batch Operations
-
π Run Batch Tests
-
β±οΈ Test with Timeout
+
Batch Operations
+
Run Batch Tests
+
Test with Timeout
@@ -338,12 +345,13 @@
π¦ Batch Operations
showOutput('setupOutput', 'Creating test worker...');
- const result = await puter.workers.create(workerName, workerCode);
- workerUrl = await puter.workers.get(workerName);
+ const workerFile = await puter.fs.write(`${workerName}.js`, workerCode);
+ const result = await puter.workers.create(workerName, workerFile.path);
+ workerUrl = result.url;
- showOutput('setupOutput', `β
Worker created successfully!\n\nWorker Name: ${workerName}\nWorker URL: ${workerUrl}\n\nYou can now test authenticated requests using puter.workers.exec()`);
+ showOutput('setupOutput', `Worker created successfully!\n\nWorker Name: ${workerName}\nWorker URL: ${result.url}\n\nYou can now test authenticated requests using puter.workers.exec()`);
} catch (error) {
- showOutput('setupOutput', `β Error creating worker: ${error.message}`, true);
+ showOutput('setupOutput', `Error creating worker: ${error.message}`, true);
}
}
@@ -380,7 +388,7 @@
π¦ Batch Operations
}
const startTime = Date.now();
- const response = await puter.workers.exec(endpoint, options);
+ const response = await puter.workers.exec(workerUrl + endpoint, options);
const endTime = Date.now();
let responseData;
@@ -391,96 +399,96 @@
π¦ Batch Operations
responseData = await response.text();
}
- const output = `β
Request executed successfully!
+ const output = `Request executed successfully!
-π Response Info:
+Response Info:
Status: ${response.status} ${response.statusText}
Time: ${endTime - startTime}ms
Content-Type: ${contentType || 'text/plain'}
-π€ Request Details:
+Request Details:
Method: ${currentMethod}
Endpoint: ${endpoint}
Headers: ${JSON.stringify(options.headers || {}, null, 2)}
-π₯ Response Data:
+Response Data:
${JSON.stringify(responseData, null, 2)}`;
showOutput('requestOutput', output);
} catch (error) {
- showOutput('requestOutput', `β Error executing request: ${error.message}`, true);
+ showOutput('requestOutput', `Error executing request: ${error.message}`, true);
}
}
async function testHello() {
try {
- const response = await puter.workers.exec('/api/hello');
+ const response = await puter.workers.exec(workerUrl + '/api/hello');
const data = await response.json();
- showOutput('quickTestsOutput', `β
Hello Test:\n${JSON.stringify(data, null, 2)}`);
+ showOutput('quickTestsOutput', `Hello Test:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
- showOutput('quickTestsOutput', `β Hello Test Failed: ${error.message}`, true);
+ showOutput('quickTestsOutput', `Hello Test Failed: ${error.message}`, true);
}
}
async function testUserProfile() {
try {
- const response = await puter.workers.exec('/api/user-profile');
+ const response = await puter.workers.exec(workerUrl + '/api/user-profile');
const data = await response.json();
- showOutput('quickTestsOutput', `β
User Profile Test:\n${JSON.stringify(data, null, 2)}`);
+ showOutput('quickTestsOutput', `User Profile Test:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
- showOutput('quickTestsOutput', `β User Profile Test Failed: ${error.message}`, true);
+ showOutput('quickTestsOutput', `User Profile Test Failed: ${error.message}`, true);
}
}
async function testPostData() {
try {
const testData = { message: 'Hello from exec!', timestamp: Date.now() };
- const response = await puter.workers.exec('/api/data', {
+ const response = await puter.workers.exec(workerUrl + '/api/data', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(testData)
});
const data = await response.json();
- showOutput('quickTestsOutput', `β
POST Data Test:\n${JSON.stringify(data, null, 2)}`);
+ showOutput('quickTestsOutput', `POST Data Test:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
- showOutput('quickTestsOutput', `β POST Data Test Failed: ${error.message}`, true);
+ showOutput('quickTestsOutput', `POST Data Test Failed: ${error.message}`, true);
}
}
async function testPutSettings() {
try {
const settings = { theme: 'dark', notifications: true, language: 'en' };
- const response = await puter.workers.exec('/api/settings', {
+ const response = await puter.workers.exec(workerUrl + '/api/settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(settings)
});
const data = await response.json();
- showOutput('quickTestsOutput', `β
PUT Settings Test:\n${JSON.stringify(data, null, 2)}`);
+ showOutput('quickTestsOutput', `PUT Settings Test:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
- showOutput('quickTestsOutput', `β PUT Settings Test Failed: ${error.message}`, true);
+ showOutput('quickTestsOutput', `PUT Settings Test Failed: ${error.message}`, true);
}
}
async function testDeleteResource() {
try {
- const response = await puter.workers.exec('/api/resource/123', {
+ const response = await puter.workers.exec(workerUrl + '/api/resource/123', {
method: 'DELETE'
});
const data = await response.json();
- showOutput('quickTestsOutput', `β
DELETE Resource Test:\n${JSON.stringify(data, null, 2)}`);
+ showOutput('quickTestsOutput', `DELETE Resource Test:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
- showOutput('quickTestsOutput', `β DELETE Resource Test Failed: ${error.message}`, true);
+ showOutput('quickTestsOutput', `DELETE Resource Test Failed: ${error.message}`, true);
}
}
async function testHealth() {
try {
- const response = await puter.workers.exec('/api/health');
+ const response = await puter.workers.exec(workerUrl + '/api/health');
const data = await response.json();
- showOutput('quickTestsOutput', `β
Health Test:\n${JSON.stringify(data, null, 2)}`);
+ showOutput('quickTestsOutput', `Health Test:\n${JSON.stringify(data, null, 2)}`);
} catch (error) {
- showOutput('quickTestsOutput', `β Health Test Failed: ${error.message}`, true);
+ showOutput('quickTestsOutput', `Health Test Failed: ${error.message}`, true);
}
}
@@ -498,13 +506,13 @@
π¦ Batch Operations
for (const test of tests) {
try {
await test.func();
- results.push(`β
${test.name}: Passed`);
+ results.push(`${test.name}: Passed`);
} catch (error) {
- results.push(`β ${test.name}: Failed - ${error.message}`);
+ results.push(`${test.name}: Failed - ${error.message}`);
}
}
- showOutput('quickTestsOutput', `π§ͺ All Endpoints Test Results:\n\n${results.join('\n')}`);
+ showOutput('quickTestsOutput', `All Endpoints Test Results:\n\n${results.join('\n')}`);
}
async function runBatchTests() {
@@ -516,13 +524,13 @@
π¦ Batch Operations
];
const results = await Promise.allSettled(
- operations.map(op => puter.workers.exec(op.endpoint, { method: op.method }))
+ operations.map(op => puter.workers.exec(workerUrl + op.endpoint, { method: op.method }))
);
const successful = results.filter(r => r.status === 'fulfilled');
const failed = results.filter(r => r.status === 'rejected');
- let output = `π¦ Batch Operations Results:\n\n`;
+ let output = `Batch Operations Results:\n\n`;
output += `Completed: ${successful.length}/${operations.length} operations\n`;
output += `Failed: ${failed.length} operations\n\n`;
@@ -535,7 +543,7 @@
π¦ Batch Operations
showOutput('batchOutput', output);
} catch (error) {
- showOutput('batchOutput', `β Batch test failed: ${error.message}`, true);
+ showOutput('batchOutput', `Batch test failed: ${error.message}`, true);
}
}
@@ -545,27 +553,27 @@
π¦ Batch Operations
const timeoutId = setTimeout(() => controller.abort(), 3000);
const startTime = Date.now();
- const response = await puter.workers.exec('/api/health', {
+ const response = await puter.workers.exec(workerUrl + '/api/health', {
signal: controller.signal
});
const endTime = Date.now();
-
+
clearTimeout(timeoutId);
const data = await response.json();
- showOutput('batchOutput', `β±οΈ Timeout Test (3s):\n\nResponse time: ${endTime - startTime}ms\nData: ${JSON.stringify(data, null, 2)}`);
+ showOutput('batchOutput', `Timeout Test (3s):\n\nResponse time: ${endTime - startTime}ms\nData: ${JSON.stringify(data, null, 2)}`);
} catch (error) {
if (error.name === 'AbortError') {
- showOutput('batchOutput', `β±οΈ Timeout Test: Request timed out after 3 seconds`, true);
+ showOutput('batchOutput', `Timeout Test: Request timed out after 3 seconds`, true);
} else {
- showOutput('batchOutput', `β Timeout Test Failed: ${error.message}`, true);
+ showOutput('batchOutput', `Timeout Test Failed: ${error.message}`, true);
}
}
}
// Initialize
document.addEventListener('DOMContentLoaded', function() {
- console.log('Workers Exec Playground loaded');
+ document.getElementById('workerName').value = puter.randName();
});