Pinokio
repository·main·Indexed 42 days ago
https://github.com/pinokiocomputer/program.pinokio.computerA browser-based platform for locally installing, running, and automating AI applications and workflows. It features a custom JSON-based scripting language, a dedicated isolated file system (pinokio home), and tools like Gepeto for generating app launchers including install, start, reset, and update scripts.
What's inside Pinokio
- A Pinokio script is a declarative markup used to automate tasks like installing and running software. It is written in JSON, but can also be written in JavaScript (which returns the resulting JSON) to allow for dynamic script generation.
Pass parameters to Pinokio scripts
mainWhen a menu item in
pinokio.jsdefines aparamsobject, those values are passed to the script specified byhref. Inside the target script (e.g., a.jsonfile), these parameters are accessible via theinputvariable.For example, if
pinokio.jspasses{ url: "https://example.com" }, a script using the template string{{input.url}}will resolve tohttps://example.com.{ "run": [{ "method": "shell.run", "params": { "message": "git clone {{input.url}}" } }] }Use Relative File Paths in URIs
mainPinokio allows you to reference local files using relative paths. The path is automatically resolved relative to the directory containing the currently running script.
For example, if
start.jsis located in/PINOKIO_HOME/api/myapp, calling a script with the URIsubroutine.jsonwill cause the interpreter to look for and execute/PINOKIO_HOME/api/myapp/subroutine.json.// start.js module.exports = { "run": [{ "method": "script.start", "params": { "uri": "subroutine.json" } }] }Manipulate data with the _ (lodash) utility
mainThe
_variable provides access to lodash methods directly within template expressions. This allows for complex data manipulation (like finding differences between arrays or sampling items) inside JSON scripts.{ "run": [{ "method": "log", "params": { "raw": "{{_.sample(self.friends)}}" } }] }Manage state with `local` variables
mainVariables prefixed with
local.(e.g.,local.items,local.prompt) are used to store state within a script execution.Key characteristics:
- They are reset whenever the script finishes running.
- They persist across steps within a single execution run.
- You can set or update them using the
local.setAPI.
Configure UI components (shortcut, app, and info)
mainPinokio allows you to build user interfaces using JSON or JavaScript. A project's UI is composed of three primary components:
- shortcut: Defines how the application is displayed on the Pinokio home page after it is downloaded. This is configured using
pinokio.js. - app: Defines the actual layout and interface of the installed application page. This is configured using
pinokio.js. - info: Defines how the application is presented on the Pinokio discover page and the official website (https://pinokio.computer). This is configured using
pinokio_meta.json.
- shortcut: Defines how the application is displayed on the Pinokio home page after it is downloaded. This is configured using
How Pinokio Virtual Drives and fs.link work
mainPinokio Virtual Drives allow you to store data outside of individual applications to enable persistence, sharing across apps (e.g., AI models), and deduplication. The
fs.linkAPI manages these drives using symbolic links.1. Folder Linking
Links a folder within the repository to a path in a virtual drive. This is useful for sharing large model files across multiple apps.
2. Peer Linking
Allows multiple applications to share the same virtual drive by declaring them as
peersusing their git repository URIs. When an app runsfs.linkwith apeersarray, it first checks if a virtual drive already exists for any of those peers. If found, it uses the existing drive; otherwise, it creates a new one.3. Venv Linking
An automated way to deduplicate Python packages across multiple
venvenvironments. By callingfs.linkwith avenvpath, Pinokio scans the installed pip packages and moves them into a centralized/drive/drives/pip/directory, replacing the original files in thevenvwith symbolic links to the shared versions.// Example of Folder Linking with Peers { "method": "fs.link", "params": { "drive": { "checkpoints": "app/models/checkpoints" }, "peers": [ "https://github.com/cocktailpeanutlabs/comfyui.git" ] } }How script memory and the `input` variable work
mainPinokio scripts execute step-by-step, and you can use the
inputvariable to pass data between steps.There are two types of
input:- Return values between steps: For any step
run[i]wherei > 0, theinputvalue is the return value from the previous steprun[i-1]. - Initial script launch parameter: For the first step
run[0],inputis the parameter passed when the script is launched. This can be set via:- The
paramsobject in ascript.startAPI call. - The
paramsobject in apinokio.jsmenu itemhref.
- The
Use the
{{input}}template syntax to access these values in your RPCparams.{ "run": [{ "id": "run", "method": "gradio.predict", "params": { "uri": "http://127.0.0.1:7860", "path": "/answer_question_1", "params": [ { "path": "https://media.timeout.com/images/105795964/750/422/image.jpg" }, "Explain what is going on here" ] } }, { "method": "log", "params": { "json2": "{{input.data[0]}}" } }] }- Return values between steps: For any step
Access script metadata with `self`
mainThe
selfkeyword allows you to access custom key/value pairs defined within the script object itself. A Pinokio script is a JSON object that can contain arunarray and any other custom keys.Example: Using
selfto handle platform-specific commands.{ "cmds": { "win32": "dir", "darwin": "ls", "linux": "ls" }, "run": [{ "method": "shell.run", "params": { "message": "{{self.cmds[platform]}}" } }] }Understand the Pinokio File System and Directory Structure
mainPinokio operates within an isolated folder called the pinokio home. This ensures that all installations (like Python, Node.js, or FFmpeg) do not interfere with your global system configuration. You can set or change this location in the settings tab.
Inside the
pinokio homefolder, the following directories are used:api: Stores all downloaded apps and scripts. Each subfolder here appears as an app in the Pinokio UI.bin: Stores globally installed modules shared across multiple apps (e.g.,ffmpeg,nodejs,python) to prevent redundant installations.cache: Stores files automatically cached by apps. If an app fails, deleting this folder and restarting can often resolve issues.drive: Stores virtual drives created via thefs.linkAPI.logs: Contains log files for each individual app.
Use Template Expressions and Memory Variables
mainPinokio uses a template interpreter to allow dynamic command generation.
Template Syntax: Wrap expressions in
{{ }}. These are evaluated at the beginning of every step in therunarray.Capabilities:
- JavaScript Evaluation: Run any Node.js expression (e.g.,
{{Buffer.from(input.images[0], "base64")}}). - Memory Variables: Access system and state variables (e.g.,
{{current}}returns the index of the currently executing step). - Input Passing: The return value of a previous step is passed to the next step as the
{{input}}variable.
Example:
{ "method": "local.set", "params": { "name": "{{input}}" } }- JavaScript Evaluation: Run any Node.js expression (e.g.,
Understand Virtual Drives
mainVirtual drives allow you to store data outside of individual application repositories while making them appear as if they are inside, using symbolic links (Linux/Mac) or junctions (Windows). This is achieved via the
fs.linkAPI.Key Benefits
- Persistence: Data stays in
/PINOKIO_HOME/driveeven if the application repository is deleted or updated. - Sharing (Peers): Multiple apps can share a single drive (e.g., sharing AI models like
.safetensorfiles between ComfyUI and Stable Diffusion) by specifying apeerarray. If a peer drive exists,fs.linkwill link to the existing one instead of creating a new one. - Disk Space Savings: Prevents redundant downloads of large libraries (like
pytorch) or models across multiple applications.
How it works
When you create a link, Pinokio creates a symbolic link from the app's internal path to an external folder in
/PINOKIO_HOME/drive. Applications do not need any special code to support this; they simply interact with their local file paths as usual, and the OS redirects the request to the virtual drive.- Persistence: Data stays in