# Panel Push Tool

`panel_push` pushes a build directory into a new version of a panel through a Verdalia Relay: a directory on the user's computer, inside a Relay filesystem mount, as a bundler such as Vite emits it.

## When to Use

The agent uses it when the user builds a panel locally with a framework and wants the build live. The user's Relay reads the directory; Verdalia does the rest.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `panel` | string | Yes | The panel's id |
| `connection` | string | No | The Relay connection's id, as `list_connections` gives it. Left out, the workspace's only Relay |
| `mount` | string | Yes | The Relay filesystem mount holding the directory |
| `path` | string | Yes | The build directory, relative to the mount, such as `lights/dist` |
| `main` | string | No | The main HTML asset's name. Left out, the base version's main, by name: the build must hold a file of that name |
| `from` | string | No | The id of the version the push is based on. Left out, the version people see |
| `vendors` | array of strings | No | The vendor identifiers the version may use, replacing the list, such as `verdalia-ui.js`. Stored exactly as given: a vendor listed without one it imports is refused. Left out, the base version's list carries over |
| `switch` | boolean | No | Whether the new version becomes what people see; default `true`. `false` stages it for `panel_switch` |

## What happens

1. The Relay lists every file under `path`, each named by its file name (`dist/assets/app.js` is `app.js`), with its size and SHA-256.
2. Only the files the workspace does not hold yet are read from the Relay, and each is checked against the hash the Relay reported.
3. The main HTML's relative `src` and `href` values that name one of the files are rewritten to `asset:` names, so a bundler's own `index.html` works as it is emitted.
4. The files become the version's assets, in place of the base version's own. Its workflows and tables carry over, and so do its vendor libraries unless `vendors` states a list. A main the build lacks, a main that is not `.html`, and a second `.html` file are refused. The version is written in one step: on any refusal nothing is stored.

A built panel compiles JSX with the automatic runtime and `jsxImportSource: 'preact'`, and marks `preact`, `preact/hooks`, `preact/jsx-runtime`, `@verdalia/ui`, `uplot` and `iconify-icon` as external; those are listed in `vendors`, together with every library each one imports: `verdalia-preact-hooks.js` and `verdalia-preact-jsx-runtime.js` need `verdalia-preact.js`; `verdalia-ui.js` needs `verdalia-preact.js`, `verdalia-preact-hooks.js` and `verdalia-htm.js`. `get_docs("panels")` has the reference Vite configuration.

## Returns

| Field | Type | Description |
|-------|------|-------------|
| `version` | string | The new version's id |
| `current_version` | string | The id of the version people see now |
| `previous_version` | string or null | The version the push was based on, to switch back to with `panel_switch` |
| `stored` | integer | How many assets were stored new |
| `reused` | integer | How many the workspace held already |
| `page_urls` | array of strings | The full URL of every navigation page that shows the panel; empty when none does |
| `editor_url` | string | The full URL of the panel's editor in Settings |

## Example Scenario

```json
{
  "panel": "01JC4Z8Q2V6M3K9T1R5X7B0N4D",
  "mount": "projects",
  "path": "lights/dist",
  "vendors": ["verdalia-ui.js", "verdalia-ui.css", "verdalia-preact.js", "verdalia-preact-hooks.js", "verdalia-preact-jsx-runtime.js", "verdalia-htm.js"]
}
```

## Notes

- A directory with more than 64 files, two files with one name, a file over 1,048,576 bytes, a file name over 67 characters with its extension, or a file that is not `.html`, `.js`, `.mjs`, `.css` or `.svg` is refused before anything is read. Raster images and fonts are inlined by the bundler as `data:` URIs
- A directory holding an `.html` file besides the main is refused: a version holds exactly one `.html` asset
- A file named as a vendor library, such as `verdalia-ui.js`, is refused; vendor libraries are named in `vendors`
- A vendor identifier that is not one Verdalia ships is refused
- A vendor list that leaves out a library one of its vendors imports is refused, naming both
- A push whose files are all held already stores none and reuses each one
- A Relay that predates panel pushes is refused
- With no Relay connected, with several and no `connection`, or with the Relay offline or unpaired, the push is refused, saying which
- The version limits and the 50 MB workspace limit are those of `panel_update`; a refusal states sizes in bytes
- Risk: write
