### Install Puter.js SDK Source: https://github.com/heyputer/puter.js/blob/main/README.md This snippet provides the necessary shell commands to clone the Puter.js repository from GitHub, navigate into its directory, and install all required project dependencies using npm. ```Shell git clone https://github.com/HeyPuter/puter.js.git cd puter.js npm install ``` -------------------------------- ### Run Puter.js Development Server Source: https://github.com/heyputer/puter.js/blob/main/README.md Execute this npm command to start the local development server for Puter.js. This server is essential for testing your applications and examples during development. ```Shell npm start ``` -------------------------------- ### Migrating Puter.js UI Function Calls Source: https://github.com/heyputer/puter.js/blob/main/app-migration-guide.txt Updates the `puter.showOpenFilePicker` pattern to `puter.ui.showOpenFilePicker`, standardizing UI function calls under the `puter.ui` namespace. ```APIDOC Old: puter.showOpenFilePicker New: puter.ui.showOpenFilePicker ``` -------------------------------- ### Migrating Puter.js Router Module to Hosting Source: https://github.com/heyputer/puter.js/blob/main/app-migration-guide.txt Renames the `puter.router` module to `puter.hosting` to better reflect its purpose related to application hosting functionalities. ```APIDOC Old: puter.router.* New: puter.hosting.* ``` -------------------------------- ### Migrating Puter.js CloudItem Instantiation Source: https://github.com/heyputer/puter.js/blob/main/app-migration-guide.txt Changes the `puter.createCloudItem(...)` factory function to direct instantiation using `new puter.CloudItem(...)` for creating cloud item objects. ```APIDOC Old: puter.createCloudItem(...) New: new puter.CloudItem(...) ``` -------------------------------- ### Integrate Puter.js and Use AI Chat in HTML Source: https://github.com/heyputer/puter.js/blob/main/README.md This example demonstrates how to include the Puter.js SDK in a basic HTML page. It then shows how to use the SDK's AI capabilities to perform a chat interaction, specifically with GPT-3.5 Turbo, and print the response to the console. ```HTML
``` -------------------------------- ### Migrating Puter.js Module Namespaces (FileSystem, Router, Apps) Source: https://github.com/heyputer/puter.js/blob/main/app-migration-guide.txt Renames top-level module accessors like `puter.FileSystem` to `puter.fs`, `puter.Router` to `puter.router`, and `puter.Apps` to `puter.apps` for consistency and brevity. ```APIDOC Old: puter.FileSystem.${msg}
`); } window.fail = function(msg) { throw new Error(msg); } window.assert = function(condition, message) { if (!condition) { throw new Error(message || "Assertion failed"); } } ``` -------------------------------- ### Execute Selected File System and Key Value Tests Source: https://github.com/heyputer/puter.js/blob/main/test/run.html Asynchronously iterates through selected file system and key-value tests. It executes each checked test, updates the test container's background color based on success or failure, and displays error messages for failed tests. ```javascript async function runTests() { // go through fsTests and run each test for (let i = 0; i < fsTests.length; i++) { if (document.getElementById(`fsTests${i}`).checked) { try{ await fsTests[i](); // make this test's container green $(`#fsTests-container-${i}`).css('background-color', '#85e085'); } catch (e) { console.log(e); // make this test's container red $(`#fsTests-container-${i}`).css('background-color', '#ffbfbf'); // message $(`#fsTests-container-${i}`).append(`${e}
`); } } } for (let i = 0; i < kvTests.length; i++) { if (document.getElementById(`kvTests${i}`).checked) { try{ await kvTests[i](); // make this test's container green $(`#kvTests-container-${i}`).css('background-color', '#85e085'); } catch (e) { // make this test's container red $(`#kvTests-container-${i}`).css('background-color', '#ff8484'); // message $(`#kvTests-container-${i}`).append(`${e}
`); } } } } ``` -------------------------------- ### Render File System and Key Value Test Checkboxes Source: https://github.com/heyputer/puter.js/blob/main/test/run.html Dynamically appends HTML elements to the '#tests' container, creating checkboxes and labels for each test found in the `fsTests` and `kvTests` arrays, allowing individual test selection. ```javascript // print the test name with checkbox for each test $('#tests').append('