A plugin's window half
Source of truth: schema/taji.json (the Frame* types) and packages/plugin/; schema_defs_documented in engine/crates/taji/tests/docs.rs holds this page to the schema, packages/plugin/entries.test.ts and packages/plugin/frame/surface.test.ts to the package.
This page is the contract between an installed plugin's window half, a frame, and Taji's window: what the frame is, the messages on its port, the names @taji/plugin exports, what a plugin contributes, what the floor allows and the theme tokens. To build a pane, follow a pane.
The frame
| Fact | Value |
|---|---|
| Where it runs | A sandboxed iframe (sandbox="allow-scripts") at GET /plugin/<id>/frame: an opaque origin, no token, no network (connect-src 'none'). Security holds the rest |
| Who mounts it | Taji's window, and a paired phone. A local browser draws <name> runs only in Taji's window |
| On a phone | Path-loaded frame files carry the URL's key |
| Regions | FrameCall mount takes panes, pages or home. An installed plugin's host mounts panes, and home (one hidden frame, drawing nothing, where its items run) when it declares [[ui.items]] |
| Hello | The bundle sends hello with what definePlugin contributes. A disagreement with [ui], or no hello within 10 s, renders the reason in place of the frame |
| Missing plugin | A pane whose plugin is not installed reads <kind> is not installed |
| Chrome | The window's title reads "Taji is asking" only while Taji's own sheet holds the keyboard; a frame cannot change it. Ask for a key through a [[link]] form, never a field in a pane |
The channel
One MessagePort joins the frame and the window. The window posts it on load with the message taji-plugin/frame. Each side calls functions the other serves, structured-cloned: a function inside args or a value crosses as a FrameFn, an event as undefined, and a refusal as data the receiver rebuilds as Refused.
| Type | Is |
|---|---|
FrameMessage | The envelope: a call {call, fn, args} (fn a served name, or a FrameFn's number), an answer {answer, value}, {answer, refused: {path, status, body}} or {answer, thrown}, or {release} for a handed function the receiver dropped |
FrameFn | {$fn: n}: a function handed across, called by its number |
FrameOffer | {id, panes, items}: what a bundle contributes, each list sorted, items as <slot>/<id>. hello's offer must equal the manifest's [ui], else 409 manifest |
FrameHostCall | A call of a name the window serves (below) |
FrameCall | A call of a name the frame serves (below) |
FrameAsk | A message a frame sends on /ws/market: get, stream, unsubscribe |
FrameRefusal | The window's answer to a FrameAsk it does not send: the kernel's error frame under the ask's id, 403 with error grant or scope, no seq |
packages/plugin/frame/surface.test.ts pins each name, its fewest and most arguments, and every message against the schema. A change to any of them bumps API, the major of the schema's version, which hello names.
Calls the window serves
FrameHostCall. Every call but hello is refused 409 api until a hello of this API's major has passed.
| Name | Arguments | Does |
|---|---|---|
hello | {api, offer} | Opens the channel. api other than this kernel's is 409 api; an offer that differs from the manifest is 409 manifest; either replaces the frame with the reason |
read | path | GET /read/<path> where the floor admits it, else 403 scope. ui/settings is answered with the frame's own keys |
verb | path, body | POST /verb/<path> where the floor admits it, else 403 scope; answers {status, body} |
verbOnLeave | path, body? | The same post, sent as the pane closes |
openSocket | path, {frame, opened, down} | One socket per path, only /ws/market and /ws/live; its handlers are called with each frame. On /ws/market only a FrameAsk is sent; on /ws/live each header is held to the read floor |
run | id, args? | A command the frame may run (commands), else 403 scope |
key | init | A chord (⌘, Ctrl or ⌥) always reaches Taji's keymap, whatever the frame did with it; a bare key reaches it when the pane left it unhandled outside a field. 403 scope from a frame without focus |
overlay | depth | How many overlays the frame holds open; Taji's Esc then calls closeTopmost |
pickSymbol | none | Taji's symbol search; answers the picked item, or null when dismissed |
say | note | One line in the window's note under the plugin's name, at most 200 characters |
picked | fn | Calls fn with the book's pick ({id, alias, live} or null) now and on each change; answers a function that stops it |
pointer | none | A pointer pressed in the frame, pressed on its iframe so the grid focuses the pane and Taji's menus close |
read, verb, verbOnLeave, run, key, overlay and say share one bucket, 50 a second with a burst of 100; past it the call is refused 429 rate.
Calls the frame serves
FrameCall.
| Name | Arguments | Does |
|---|---|---|
mount | region, id, props | Draws the region's contribution, id the pane's kind |
props | props | Draws it again with new props |
closeTopmost | none | Closes the frame's topmost overlay, on Esc |
item | slot, id, payload | Runs the plugin's item. The payload is a MenuAt for chart.menu@1 and {arg, at} for composer.command@1; a chart.menu@1 rejection is said through say, any other rejects to the caller |
Asks on /ws/market
FrameAsk. A get or stream the window refuses is answered a FrameRefusal and never sent.
| Ask | Fields | Refused when |
|---|---|---|
get | id, product, query | The product is neither the plugin's own [[products]] nor in [grants] reads (grant); it is positions, or another chart's indicators, or the ask carries refresh (scope) |
stream | id, product, and the product's words | The same |
unsubscribe | id | Never |
@taji/plugin exports
Frames import packages/plugin/index.ts. packages/plugin/entries.test.ts lists its names and separates them from window.ts (the window's realm: the trade acts, queryClient, market) and host.ts (the shell), which a frame build does not resolve. While 0.x a name can change in any release.
| Export | Signature |
|---|---|
definePlugin | (p: Plugin) => Plugin; the default export of <dir>/ui/plugin.tsx. An installed plugin contributes FramePlugin, {id, panes?, items?}: write definePlugin({…} satisfies FramePlugin) to have the compiler hold it there |
useProduct, getProduct | <T>(product: Product, query: string | null) => {data, error, pending, at}, at the millisecond the answer or refusal landed; getProduct<T>(product, query, signal?) reads once. An own product is <plugin>.<name>, e.g. useProduct<RowsBody>("acme.levels", "symbols=index:%24PULSE&from=…") |
useTicks | (product: TickProduct, item: string | null, words?: {ticks?: number}) => {rows: ArrowRow[]; lapsed: string | null}, e.g. useTicks("acme.levels", "index:$PULSE"); TickProduct is depth, trades or an own product; ticks folds a depth book to rows of that many ticks. It holds each frame's newest row, depth excepted (the book whole); a pane that lists rows as they stream accumulates them itself |
useNode, useNodes | <T>(path: string | null, select?) => {data, error, pending}; the same over paths: string[] |
read, verb, verbOnLeave | read(path, signal?); verb(path, body, signal?) => Promise<{status, body}>; verbOnLeave(path, body?) posts as the pane closes. Refused is the error of a refusal: path, status, body |
setting, keep, onSettings | setting<T>(key, fallback): T; keep(key, value | null) writes through the kernel; onSettings(listener) returns its stop |
run | <K extends keyof Commands>(id: K, ...args) => Promise<…>, refused no_command where none provides it |
items | <K extends keyof Items>(slot: K) => Item[] of that slot |
pickSymbol, say, usePickedAccount | () => Promise<string | null>; (note: string) => void, one line of at most 200 characters; () => {id, alias, live} | null |
usePaneShown, useOverlay | () => boolean, false while a page hides the pane; (close: () => void, on = true) takes Esc for close |
useBars, useQuote, useRows, useChain, useBook, usePositions, useQuotes, … | Taji's own data hooks, with *Each forms. In a frame each reads through the floor, so one whose product or path the manifest does not grant is refused |
Two more entries are a frame's: @taji/plugin/chart (Chart, treemap, stepped, Units, PlotTokens: Draw with Chart; a chart with no backend) and @taji/plugin/layer (defineLayer, columnsOf and the layer contract's types: a chart layer). packages/plugin/entries.test.ts holds the chart entry's names and that it reaches no window module.
The rest (act, setSymbol, setView, the display-zone helpers) are Taji's own acts and types; the complete list is INDEX in packages/plugin/entries.test.ts.
Draw with Chart
What Chart gives you
Chart (packages/plugin/chart/index.tsx) draws the Shapes your function returns as DOM, so you write none of this:
- A tile for each rect, in the theme's colours.
- The
labelsyou ask for, boxed in each tile at the largest size that fits and dropped where none does. - A tooltip of the
tipcolumns of the row under the pointer or the focused tile, printed by each column's unit. - Arrow keys that move between tiles, and Enter, Space or a click that calls
onPick(row). - On a phone, the tooltip docked to the plot's foot, a tap focusing a tile and a tap on the focused one picking.
- A place in
GET /read/ui/capture, since the tiles are DOM.
A Chart states what it drew in data-chart-shapes as {"rects", "labels"}, which check reads.
shapes and when it reruns
shapes(size, tokens) returns the picture for a plot of size pixels ({w, h}) and the theme's tokens (up, down, ink, muted, surface1, surface2, each 0xRRGGBBAA). It runs when rows, the plot's size or the tokens change, and not on any other render. Build rows in useMemo, as the pane guide's scaffold does: a new object each render redraws each render.
treemap and stepped
treemap(rows, opts, size, tokens) (packages/plugin/chart/treemap.ts) tiles each row by its size column, squarified, with the rows grouped under header strips by the group column where you name one; labels are the columns written in each tile. A row whose size is not above 0 draws nothing, and the shapes' note says N of M sized. With colour, each tile takes stepped(value, step, tokens) (packages/plugin/chart/stepped.ts): seven steps, step apart and clamped at three either side of 0, so step: 1 runs from −3% to +3%, with 0 a neutral grey. A null colour cell is NaN, drawn surface2 as no quote, never as step 0. Without colour every tile is surface2. A tile's area is its datum, so small tiles stay small (WCAG 2.5.8's essential exception), and every tile is reached by the arrow keys; a pane that picks from tiles also offers the pick another way where it can (a search, a list).
units
units names each column's Unit: price, usd, shares, contracts, ratio, percent or count. {unit: "percent", signed: true} also prints a + on a positive cell, so the tooltip reads +3.77% and −3.01% for a change. A column with no unit prints on the K, M, B ladder.
Rows to columns
columnsOf(rows, numeric, lists, strings) (packages/plugin/layer/rows.ts) turns served rows into the columns treemap reads: each numeric column a Float64Array, a null NaN, and each strings column an array of text, a null cell "". A Decimal128 column arrives in the row as a string of its exact digits, "215600000.0000000000", so a figure keeps every digit through the page (cellOf in packages/plugin/state/data.ts); columnsOf converts the columns you name numeric to numbers, and it converts nothing else.
Panes and slots
Plugin is {id, panes?, pages?, fills?, items?, commands?, forms?} (packages/plugin/plugin.ts). An installed plugin contributes panes and items alone, each declared in [ui] and equal to its hello (a disagreement is 409 manifest); layers need no bundle. A taken id, pane kind, item or command leaves an installed plugin out of the window, with a console warning; a compiled-in one throws at registration.
panes
Pane is {kind, label, Icon, Body, Preview?, size?, Tools?, link?, bare?, keep?}.
| Field | Meaning |
|---|---|
kind, label | The kernel's pane kind, <plugin id>.<word>, and its name |
Icon | The dock's and the gallery's glyph. An installed pane's is its [[ui.panes]] icon, else its label's first letter |
Body | ComponentType<PaneProps>, a pane in the canvas, a tab or the dock's popup |
Preview?, Tools? | The gallery card's still sketch (compiled-in panes only); a component drawn in the host's head after the title |
size? | {w?, h?, min?: {w, h}} in px: the popup's first size, absent 480x420; min the least a popup's corner leaves it, absent 200x120 |
link? | true: the body follows chart, and the host's head leads with the link key |
bare? | true: the host draws no .pane-body, and on a phone no head |
keep? | true: the body stays mounted under a page, hidden and inert (usePaneShown false); any other renders nothing there |
An installed pane's entry in the window is kind, label, Icon and Body (ui/src/shell/installed.tsx); the other fields apply to a compiled-in pane's.
PaneProps:
| Prop | Type | Meaning |
|---|---|---|
deskId, chart | string | null | The open desk, and the node of the chart the pane follows: its link group's first chart, else the focused one |
place | string | <desk>/<pane>: key per-pane settings by it, so two panes of one kind keep each their own |
paneId | number | The pane's id in the layout |
active, maximized | boolean | Whether the pane is the focused one, and whether it fills the canvas |
onMaximize | (() => void) | null | Maximizes the pane (a phone's Expand, the head menu's Maximize); null where there is none |
linked | boolean | The pane is in a link group with a chart on this layout, so chart is that group's; a chart pane is a member and keeps the focused chart |
items
Item is {slot, id, order, label, hint?, run}: a row a Taji surface draws. id is <plugin id>.<word>, label 1 to 40 characters in [[ui.items]], order the position among rows, lowest first. An item joins an Items slot (@n its version); a slot Taji does not know stays dormant.
| Slot | run is called with | Drawn |
|---|---|---|
chart.menu@1 | (at: MenuAt): {chart, symbol, price, time}, price the menu's price word or null, time the bar's t in UTC seconds or null | A row in the chart's right-click menu, when a symbol is set. A rejection is said through say |
composer.command@1 | (arg: string, at: CommandAt): {deskId, chart} | /<word> in the composer, from id <plugin>.<word>; two plugins sharing <word> both show with their plugin's name. hint, up to 200 characters, is the row's second line; a rejection shows its words in the composer |
Compiled-in only
pages, fills, commands and forms are not contributed by an installed plugin.
| Contribution | Shape | Meaning |
|---|---|---|
pages | {id, label, order, Icon?} and Body: ComponentType<{deskId}> or pane | A left bar entry, id in [a-z0-9_] and never one of the shell's own views (desk, connections, accounts, first). Body opens ?view=<id>; pane opens that kind of the same plugin's panes on the active desk, and the entry is off while no desk is open |
fills | {slot, order, Body} | A body drawn in a Slots slot: toolbar.{left,center,right,trade}@1 (ToolbarProps), details.sections@1 ({item, keyStats, shown}), details.news@1 ({symbol}) |
commands | {[id]: fn} | What a plugin gives others to run |
forms | {word, Body} | What the link sheet draws for #form=<word>, Body given {target, close} |
Commands
Commands (packages/plugin/plugin.ts): each takes at most one argument.
| Command | Takes |
|---|---|
chart.showTable@1, chart.downloadData@1 | none |
chart.openSettings@1 | {chart, tab?} |
chart.wantAlert@1, chart.wantSelected@1 | id | null |
chart.autoTimeframe@1 | {chart}, answers a promise |
reference.showNews@1 | symbol | null |
reference.showFilings@1 | Shown | null |
reference.showFinancials@1 | {item, tab?} |
watchlist.openNotes@1 | item | null |
A frame's run takes reference.showNews@1, reference.showFilings@1, reference.showFinancials@1, watchlist.openNotes@1, chart.showTable@1, and chart.openSettings@1 on its own chart: the six of FrameCommands.
Pack, serve and open
| Item | Rule |
|---|---|
| Source | <dir>/ui/plugin.tsx default-exports definePlugin({id, panes, items}) from @taji/plugin, never @taji/plugin/window or @taji/plugin/host: a frame build resolves neither (ui/mock/frame/vite.config.ts) |
| Pack | bun run ui/pack.ts <dir> [--out <out dir>] [--watch] writes <dir>/ui/index.js, and <dir>/ui/index.css where it imports a sheet; --out writes them to another directory. --watch repacks, and the pane, closed and opened again, loads the new bundle. Exit 1 on a failed build, or with neither a plugin.tsx nor a layer builder to pack (ui/pack.ts) |
| Frame document | GET /plugin/<id>/frame while the row is enabled: /app/frame/kit.css, the package's <dir>/ui/index.css where there is one, <div id="root"> and <dir>/ui/index.js, under Content-Security-Policy: sandbox allow-scripts; default-src 'none', Cache-Control: no-store. 404 for an id no plugin holds |
| Frame files | GET /plugin/<id>/ui/<file>: <dir>/ui/index.js, <dir>/ui/index.css, a declared icon or a layer's ui/<name>.js; 404 for any other file. No token; on a phone the key (engine/crates/taji/src/wire/plugin_ui.rs) |
| Refused row | A package missing <dir>/ui/index.js (unless its [ui] holds layers alone) or a declared icon |
| Add a pane | POST /verb/desk/<id>/layout/add_pane {"anchor_pane_id": <paneId>, "position": "right", "kind": "<plugin>.<word>"} |
| Close a pane | POST /verb/desk/<id>/layout/close_pane {"pane_id": <paneId>} |
| Find a pane | GET /read/desk/<id>/layout: panes[] holds each paneId and kind |
| Open the window | TAJI_STATE_DIR=<state> TAJI_WIRE=<port> taji ui against a running kernel (TAJI_WIRE defaults to 7780; <state>/wire-port holds the port of a kernel booted with TAJI_WIRE=0). A debug kernel starts <repo>/window, keyed; TAJI_WINDOW=<window dir> runs that directory unkeyed. End both with POST /verb/ui/quit |
The floor
The window holds every frame to its manifest and denies by default (packages/plugin/frame/floor.ts, packages/plugin/frame/host.tsx).
| Call | Admitted | Else |
|---|---|---|
verb, verbOnLeave | Its pane's chart's set_symbol; its own plugin.<id>.* settings; a route of its own [[kernel.verbs]], none under trading/, link/, agent/, ui/ or plugins/, and the verb's scopes must hold page | 403 scope |
read | ui; ui/settings, answered with its own plugin.<id>.* keys and taji.accent alone; data/coverage/<class>; its chart and under it; its claimed nodes, directly or after desk/<word>/; never trading/ | 403 scope |
/ws/market | get and stream of its own [[products]] and [grants] reads, never with refresh | 403 scope, or grant for a product |
/ws/live | Headers naming only paths it may read; any other change arrives as the paths of its own reads it makes stale | none |
run | The six commands above | 403 scope |
| Rate | 50 calls a second, burst 100, of read, verb, verbOnLeave, run, key, overlay and say together | 429 rate |
A path the browser's URL parser would change (a .. or . segment, an empty one, \, #, a space) is refused scope, and a verb path carries no query. No order verb passes.
Kit tokens
The frame loads Taji's theme, /app/frame/kit.css (packages/kit/tokens.css), whose colours go vivid on a wide-gamut screen as the page's do; the package's own <dir>/ui/index.css is drawn as written, its own @media (color-gamut: p3) rules included. The promised tokens: --ground, --surface-1, --surface-2, --surface-3, --line, --line-strong, --ink, --ink-2, --ink-3, --accent, --on-accent, --up, --down, --well, --focus, --sans, --mono, --fs-micro, --fs-dense, --fs-body, --fs-ui, --fs-title, --fs-table, --fs-table-2, --fs-table-3, --sp-2, --sp-4, --sp-8, --sp-12, --sp-16, --sp-24, --r-control, --r-card, --dur-1, --dur-2, --ease-out. Others may be renamed.
See also
- A pane: build and pack one.
- A chart layer: draw on the chart with no frame.
- The manifest: the
[ui]table a frame's offer must equal. - The process protocol
- Security: what a frame cannot reach.