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 @@ diff --git a/src/playground/examples/ai-chat-stream.html b/src/playground/examples/ai-chat-stream.html index 9518ab7..4f2401f 100644 --- a/src/playground/examples/ai-chat-stream.html +++ b/src/playground/examples/ai-chat-stream.html @@ -3,7 +3,7 @@ diff --git a/src/playground/examples/ai-txt2img-options.html b/src/playground/examples/ai-txt2img-options.html index f975612..9603965 100644 --- a/src/playground/examples/ai-txt2img-options.html +++ b/src/playground/examples/ai-txt2img-options.html @@ -4,7 +4,7 @@ diff --git a/src/playground/examples/workers-exec.html b/src/playground/examples/workers-exec.html index 4baa7d8..063ee17 100644 --- a/src/playground/examples/workers-exec.html +++ b/src/playground/examples/workers-exec.html @@ -157,12 +157,12 @@
-

πŸ” 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:

- +
- +
-

πŸ”§ Request Builder

+

Request Builder

@@ -265,7 +272,7 @@

πŸ”§ Request Builder

- +
- - + +
-

⚑ Quick Tests

- - - - - - +

Quick Tests

+ + + + + +
-

πŸ“¦ Batch Operations

- - +

Batch Operations

+ +
@@ -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(); }); diff --git a/src/playground/examples/workers-list.html b/src/playground/examples/workers-list.html index 99a0778..b9c08f6 100644 --- a/src/playground/examples/workers-list.html +++ b/src/playground/examples/workers-list.html @@ -12,12 +12,10 @@ puter.print(`Found ${Object.keys(workers).length} worker(s):
`); Object.entries(workers).forEach(([name, details], index) => { - const deployDate = new Date(details.deployTime * 1000); - puter.print(`${index + 1}. ${name}
`); puter.print(`URL: ${details.url}
`); - puter.print(`Source: ${details.filePath}
`); - puter.print(`Deployed: ${deployDate.toLocaleString()}
`); + puter.print(`Source: ${details.file_path}
`); + puter.print(`Deployed: ${new Date(details.created_at)}
`); puter.print('
'); }); } diff --git a/src/playground/examples/workers-management.html b/src/playground/examples/workers-management.html index c32c281..a6efa34 100644 --- a/src/playground/examples/workers-management.html +++ b/src/playground/examples/workers-management.html @@ -129,7 +129,7 @@
-

πŸ”„ Workers Management

+

Workers Management

Manage your serverless workers with the Puter.js Workers API.

@@ -159,14 +159,14 @@

Create New Worker

return { number: Math.floor(Math.random() * 1000) }; });
- +

List All Workers

- +
@@ -177,7 +177,7 @@

Get Worker URL

- + @@ -186,9 +186,9 @@

Get Worker URL

Delete Worker

- +
- + @@ -199,11 +199,12 @@

Test Worker

- + +