# Packages

Source: https://docs.lightair.app/developers/extend/packages

> What a Lightair package is, every field of lightair-package.json, the kinds of content and their tiers, and the ways a package is installed.

In short:
- A package is a folder, or a `.airpkg` zip of it, with `lightair-package.json` at its root.
- The manifest names the package, its version, the package API range it needs and what it contains.
- Each kind of content has a tier (data, shader, script, native) that decides what it may ask for.
- Install one with **File › Install Package…**, by dropping it on the window, or from a `lightair://` link.

A package carries widgets, scenes, media, sounds, automations, scripts or helper programs into
Lightair. It's installed once per user, side by side with its other versions, and a show that
uses it records which version.

## Make a package

1. Make a folder and put your content in it, one folder (or file) per item.
2. Add `lightair-package.json` at the folder's top.
3. Install the folder to try it (see [Install a package](#install-a-package)).
4. Zip it as a `.airpkg` to share it, or build and check it with
   [`lightair-pack`](/developers/extend/publish).

A package of two widgets:

```text
neon-pack/
├── lightair-package.json
├── LICENSE
└── widgets/
    ├── alerts/
    │   ├── manifest.json
    │   ├── fields.json
    │   ├── index.html
    │   ├── style.css
    │   └── main.js
    └── goal/
        └── …
```

```json
{
  "id": "com.example.neon-pack",
  "name": "Neon Pack",
  "version": "1.0.0",
  "lightair": ">=1.1 <2",
  "author": "Example Studio",
  "licence": "MIT",
  "description": "Alerts and a goal bar in neon tubes.",
  "contents": [
    { "kind": "widget", "path": "widgets/alerts" },
    { "kind": "widget", "path": "widgets/goal" }
  ]
}
```

## The manifest

`lightair-package.json` is a JSON object. Lightair reports every problem in it at once, in plain
sentences, when it reads the package.

| Field | Required | What it is |
|---|---|---|
| `id` | Yes | A reverse-domain name, unique to this package and never reused: `com.example.neon-pack`. At least two parts separated by dots; each part is lower-case ASCII letters, digits, `-` and `_`, starts with a letter or digit and doesn't end with `-`. At most 128 characters. |
| `name` | Yes | The name people see. At most 100 characters. |
| `version` | Yes | A [semantic version](https://semver.org): `1.0.0`, `2.1.0-beta.1`. |
| `lightair` | Yes | The range of the package API it was made for (see [Version ranges](#version-ranges)). |
| `author` | No | Who made it. |
| `licence` | No | Its licence, as an SPDX expression (`MIT`, `MIT AND OFL-1.1`). `license` is read too. |
| `description` | No | A sentence or two on what it adds. |
| `platforms` | No | Where it works: any of `macos`, `windows`, `linux`, `ios`, `android`. Left out or empty: everywhere. |
| `dependencies` | No | Other packages it needs: an object of package id → version range. A package can't depend on itself. |
| `contents` | Yes | What it adds: a list of at least one [content entry](#contents). |
| `permissions` | No | What its code or web pages may reach. See [Permissions](/developers/extend/permissions). |
| `optional_permissions` | No | Permissions it may ask for later, while it runs. Scripts and helpers only. |

### Version ranges

The `lightair` field and each dependency take a version range:

- `^1.2` or `1.2`: anything compatible, up to 2.0.
- `~1.2`: up to 1.3.
- `=1.2.0`: only that version.
- `*`: any version.
- `>=1.1 <2` or `>=1.1, <2`: both bounds.

Alternatives (`||`) and hyphen ranges (`1.0 - 2.0`) aren't accepted.

This version of Lightair implements package API **1.1.0**. Write `>=1.1 <2` when a widget is a
skin of a built-in or loads its own files (fonts, pictures, sounds); `>=1.0 <2` otherwise. A
package whose range leaves out 1.1.0 doesn't install: Lightair says whether it needs a newer or
an older Lightair.

## Contents

Each entry in `contents` has a `kind` and a `path`. The path is relative to the package's root,
normally a folder, and must stay inside the package. The manifest itself can't be listed, and no
path can be listed twice.

```json
{ "kind": "widget", "path": "widgets/alerts" }
```

A helper adds `entry`, its program for each platform, and optionally `modes`, the first argument
it can be started with:

```json
{
  "kind": "helper",
  "path": "helper",
  "entry": {
    "macos-arm64": "bin/darwin-arm64/my-helper",
    "macos-x64": "bin/darwin-x64/my-helper",
    "windows-x64": "bin/windows-x64/my-helper.exe"
  },
  "modes": ["serve"]
}
```

The targets are `macos-arm64`, `macos-x64`, `windows-x64`, `windows-arm64` and `linux-x64`. Only a
helper may have an `entry`. See [Native helpers](/developers/extend/helpers).

### Kinds

| Kind | Tier | What Lightair does with it |
|---|---|---|
| `widget` | Data | A widget's folder. Listed in **Add Object › Widgets** and in the Packages panel. See [Widgets](/developers/extend/widgets). |
| `template` | Data | A scene's `scene.json` (or the folder holding it). Added as a new scene after the selected one. |
| `media` | Data | Pictures, video and sound files, and avatars. Placed in the scene as objects. |
| `avatar` | Data | `.vrm`, `.glb`, `.inp`, `.inx`, `.lairava` files and Live2D models (a folder with a `.model3.json`). Placed in the scene. |
| `sound` | Data | Sound files. Added as soundboard pads. |
| `lut` | Data | A `.cube` or `.png` look-up table. Added as a LUT effect on the selected object. |
| `recipe` | Data | An automation's `automation.json`. Added to Automations, switched off. |
| `extension` | Script | A script plugin's folder with its `main.js`. See [Script plugins](/developers/extend/script-plugins). |
| `helper` | Native | A helper program, run in a sandbox. See [Native helpers](/developers/extend/helpers). |

Pictures are `png`, `jpg`, `jpeg`, `gif`, `webp`, `bmp`, `tga` and `heic`; video is `mp4`,
`mov`, `m4v`, `mkv`, `webm` and `avi`; sound is `mp3`, `wav`, `m4a`, `aac`, `flac`, `ogg` and
`aiff`.

The manifest also accepts `look`, `transition`, `effect-preset`, `theme`, `font`,
`shader-effect`, `shader-transition`, `shader-source`, `wasm-effect` and `wasm-source`. Lightair
installs and lists packages that hold them, but doesn't load that content. A kind Lightair
doesn't know at all stops the package installing.

### Tiers

Each kind belongs to a tier. The higher the tier, the more the content can do, and the more
Lightair asks of it. A package's tier is the highest of its contents'.

| Tier | Content | Where it runs | Permissions it may declare |
|---|---|---|---|
| 1. Data | Files Lightair reads | Nothing runs. A widget's or template's web pages run in Lightair's web view. | Only `network:` hosts, and only when it holds a widget or a template |
| 2. Shader | WGSL shaders | Installed, not loaded | None |
| 3. Script | JavaScript | In its own isolate, inside Lightair | Any except `full-access` and the helper-only ones |
| 4. Native | Helper programs, WebAssembly | A helper runs as its own process, in a sandbox; WebAssembly is installed, not run | Any, including `full-access` |

## Size and safety limits

Lightair refuses a package that:

- has more than 20,000 files, a file over 4 GiB, or more than 16 GiB in all (also the largest a
  `.airpkg` may be);
- has a path longer than 400 bytes or more than 24 folders deep;
- has a manifest over 1 MiB;
- holds a link, or a path that leaves the package;
- has two files whose names differ only by case;
- lists content that isn't there.

Hidden files (names starting with `.`), `__MACOSX`, `Thumbs.db` and `desktop.ini` are skipped.

## The .airpkg file

A `.airpkg` is a zip of the package folder. The package is either the zip's top or the one folder
at its top, so zipping the folder itself works. Lightair hashes every file (SHA-256) as it reads
the archive, and the content's checksum is the same whether a package comes as a folder or a
`.airpkg`.

## Install a package

Any of these opens Lightair's install screen, which says what the package adds, its size, its
licence, what it may do and where it comes from. Nothing installs until the person confirms.

- **File › Install Package…**, or **+ › Install from a file…** in the Packages panel. Pick a
  `.airpkg`, a package folder or a `.lwidget`.
- Drop a `.airpkg`, a package folder or a `.lwidget` on Lightair's window.
- Open a link:
  - `lightair://install?id=<id>&version=<version>` installs from Lightair's catalog. `version`
    is optional (the latest). Add `&catalog=<base URL>` for a community catalog; Lightair offers
    to add the catalog first.
  - `lightair://install?git=<https URL>&rev=<tag, branch or commit>` installs straight from a
    git repository. `rev` defaults to `main`, only `https://` addresses are accepted, and `git`
    must be installed. The exact commit is recorded.
  - `lightair://catalog?url=<base URL>` adds a community catalog. See
    [Run a catalog](/developers/extend/run-a-catalog).
- Call [packages.install](/developers/remote-api/packages.install) through the Remote API.

A `.lwidget` (one widget's files zipped with a small `manifest.json`) installs as a package of
one widget, with the id `local.widget.<name>`.

:::caution
A package's version can't change its contents. Installing the same id and version with different
files fails: "a changed package needs a new version number". Raise `version` each time you
change a package, or remove the installed version first.
:::

## Where packages live

Each version is installed in its own folder:

- macOS: `~/Library/Application Support/Lightair/Packages/<id>/<version>/`
- Windows: `%APPDATA%\Lightair\Packages\<id>\<version>\`

**Show packages in Finder** (or **Explorer**) in the Packages panel's **+** menu opens the folder.

A show that uses a package records it in two files in the show's folder: `packages.json` (each id
with the range it needs) and `packages-lock.json` (the exact version, checksum, source and size).
Opening the show on a computer without the package says what's missing. **File › Export
Workspace with Packages…** copies the show with each package it uses as
`Packages/<id>-<version>.airpkg`, so the copy can install them on another computer.

**File › Export as Package…** writes the selected objects, or the selected scene, out as a
`.airpkg`: a scene becomes a template with the media it uses beside its `scene.json`, and a
widget with its own code becomes a widget folder. Lightair asks for the name, version, author
and licence and writes the manifest.

## Related

- [Permissions](/developers/extend/permissions)
- [Widgets](/developers/extend/widgets)
- [Publish a package](/developers/extend/publish)
