Menu
Sign inDownload

Add-on objects

Every object, field and limit both halves of an add-on get, and the names we use for them.

Everything an add-on is handed and can hand back, field by field, with the names we use for it inside Comms Array

Make an add-on is the way in and the Add-on API is the contract (the manifest, permissions, versions). This page is the detail: every object in both halves of an add-on, what each field holds, what you get back from each call, what goes wrong, and the limits. Each game's tags, values and panels by id are in Games; every part of a button pack is in Button packs; each game's events are in Game events.

Fields marked 1.N arrived in that version of the add-on API (set api_version to the newest one you use). Everything else is 1.0. New fields can appear in any object: ignore the ones you don't know.

The names we use

The same words are used everywhere in Comms Array, in its code and on these pages. Use them when you ask for help.

NameWhat it is
PCComms Array running on the player's computer. It reads the game, runs add-ons and serves the pad
gamea game Comms Array supports, by id (starcitizen, elite). One is active at a time
enginethe program that reads one game for Comms Array (its logs, its telemetry). Add-ons never talk to it directly
add-onyour program: a Python package Comms Array starts in its own process, plus an optional pad script
padthe web app on the player's phone or tablet, paired with the PC
deviceanything paired with the PC: a pad, or a companion program with a device login
layouta pad's whole set of pages for one game (the built-in Phone and Tablet, or the player's own). A layout has a button pack or none
pageone screen of a layout: a grid of widgets. Pages can switch by themselves by situation (when tags, priority)
cellthe grid's unit, always square. The usual widget is 2x2 cells; a single light can be one cell
grid, cols, rowsa page is a grid of square cells, cols wide (2-32) and rows tall (1-64). A layout is made for a phone or tablet (its screen): there the grid fills the screen, and any other screen shows the whole grid too, as big as fits, with a margin; it never scrolls. The built-in Tablet is 24 x 12 and the Phone 12 x 18, made for the smallest of each. A layout with no rows has as many as fit each screen. A widget is w by h cells (h 1-40) at x, y; one below the last row isn't drawn
widgetone thing on a page: a button (a game action or a key), a gauge, a readout, parts, a light, a panel, a label, a spacer, the party, or one of an add-on's widget kinds
widget kinda type of widget your pad script registers with CA.widget(type, ...) and lists in the manifest's widgets
tilea widget as drawn on the grid. Yours is drawn in a frame
framethe sandboxed iframe your pad script runs in. Every tile and every panel of yours is its own frame
panel (add-on)a full-screen page of your widget (an editor, a list), opened from a tile tap or a settings button. It shows in the sheet
panel (game)one of the game's ready-made status widgets (shields, cargo, ...), a widget of type panel. Unrelated to your panels
sheetthe pad's pop-up page (settings, editors). Your panels open in it, under a strip with your title and Close
edit modethe pad while the player moves, adds and sets up widgets. Your tile is drawn with editing: true
settingsthe fields the pad draws for your widget in edit mode. Their values are saved on the widget
tag (situation)an on/off fact about now: landed, combat, on_foot. The game sends the ones that are on
value (metric)one thing the game measures (hull, speed, cargo). In code it's often called a metric
described valuea value's description: label, group, type, range, unit, levels (what it is)
presented valuea value as the PC formatted and coloured it: {v, t, level, pos, ...} (what it is now)
levelhow good a value is: ok, warn, bad, off, or "" (nothing to say)
lampthe light on a button that shows the game says something is on
button packa cockpit-hardware look for a whole layout. Its parts (plate, face, rim, lamp...) are in Button packs
platethe pack's hardware under a widget. Your tile sits on it unless its kind says plate: false
partythe group of players this PC is in, shared through the hub (commsarray.com)
hubcommsarray.com: accounts, parties, the add-on and engine store
statuswhat your add-on says about itself (api.set_status), handed to your frames

The Python side

Your package's create(api) is called once when your process starts. It returns your add-on object (any object; the hooks below are looked up on it by name, and any you leave out are skipped).

api: the add-on API object

FieldTypeWhat
api.namestryour add-on's name from the manifest
api.permissionsset of strthe permissions the player had granted you when your process started (a subset of what you asked for). The player can untick one at any time, and from then on its calls raise 403: handle that rather than trusting this set
api.data_dirstryour own folder on the PC (Comms Array's addon-data/<name>), made for you. Keep settings and saved data here. It stays when you're updated
api.loglogging.Loggergoes into Comms Array's log under your name
api.active_gamedictthe active game (game object, below). Set before create and kept current
api.latest_statedictstate.live: the newest live state, in the game's own shape. {} until the first one
api.latest_paddictstate.live: the newest game-neutral values, {"tags", "metrics", "lamps"} (pad values, below)
api.latest_partydict or None1.1, party.read: the newest party (party object, in the API page)

Calls (all async except set_status). Each needs its permission; without it, it raises AddonError 403.

CallPermissionReturns
await api.state()state.live{"state": game's own shape, "game": engine status, "pad": pad values}
await api.press(action, hold_ms=None, confirm=False)actions.press (+ actions.dangerous)a press result (below)
await api.keys(op, **fields)input.keys; 1.7: keys.read for lookup, actions, check, statusa keys result (below). 1.5: a hold from down is kept alive for you until up or release_all
await api.catalog(q=None, subject=None, ids=None, limit=200)1.5, actions.press or input.keys (1.7: or keys.read){"subjects", "synonyms", "actions": [catalogue rows], "total", "more"}: the rows the pad's widget picker lists (docs/engine-api.md, "catalog"). q searches names, the game's words and variants; ids finds the rows holding those action ids (a row's own or a variant's); limit 1-500
await api.button(action, op="tap", hold_id=None, confirm=False)1.5: actions.press for a tap the game presses itself, input.keys for any other action and every holda press result or a keys result: what the pad's Button would do. op: tap, down (a hold, by key; kept alive until up), up (with the hold_id)
await api.set(action, state, confirm=False)1.5, actions.press or input.keys (as the press it makes){"status": "ok", "pressed": action} or {"status": "ok", "already": true}. action: any form of a lit thing; state: "on" or "off". 409 unknown_state (where: where to bind its set form) when the game doesn't report it and has no form that sets it. Sets on one thing take turns: 429 busy when this one can't get its turn within 4 s, 409 cancelled when your add-on let go of everything (release_all) while it waited
api.lamp(action)1.5, state.live"on", "off", "busy" or None: the lamp a pad button on that action shows, from api.latest_pad. A lamp-aware form ("<Action>.on") reads its base action's
await api.account()account.status{"signed_in": bool, "account": bool}: signed in at all; holds a valid account licence
await api.game()game.info{"engine": id, "game": engine status, ...} plus what the engine says about where the game is (Star Citizen: channel_dir, game_log)
await api.party()party.read (1.1)the party object
await api.call(addon, fn, body=None, timeout=15)uses.<addon>.<fn>whatever that add-on's handle_call answered
await api.device_login(name)devices.login{"token", "device": {"id", "name"}}: give the token to your companion program. At most 3 per add-on. It presses only what you may (actions.press, input.keys), and is revoked when you're removed or the permission is unticked
await api.device_revoke(id)devices.login{"ok": bool}. Only your own device logins
await api.pad_info()1.6, devices.login{"url": "http://127.0.0.1:<port>/pad?local", "on": bool}: where your companion program opens the pad on this PC; on is false while phone & tablet control is off
api.set_status(dict)nonenothing. Any JSON-able dict; your frames read it as CA.pad.status (with running added)

Every call waits up to 15 seconds for Comms Array (then asyncio.TimeoutError). If your process isn't connected, calls raise AddonError 503 not_connected.

AddonError

from commsarray.pluginhost import AddonError. Raised for every refused or failed call: .code (an HTTP-style number) and .body (a dict with status and usually message). Raise it yourself in handle_pad / handle_call to answer with that code and body.

.code.body["status"]When
403not_permitted (with permission)you weren't granted that permission
403blockeda dangerous action without actions.dangerous
400unknown_actionthe game doesn't offer that action
400bad_request, bad_keysa malformed request; a key name that isn't a key
404no_such_function, not_foundapi.call to a function that add-on doesn't provide; revoking a device that isn't yours
409needs_confirma dangerous action without confirm=True
409keys_off, not_focusedkey presses are off for this game, or the game window doesn't have focus
409busyanother key press is going on
429limit, busythe 3 device logins are used; key presses are busy
503error, addon_not_running, not_connectedthe game can't be reached; the add-on you called isn't running; you aren't connected
504timeoutthe add-on you called didn't answer in 10 seconds

Hooks: what Comms Array calls on your object

All optional. handle_pad and handle_call must be async def (Comms Array awaits them); the rest can be plain or async. An exception in one is logged and Comms Array carries on (it never stops your process).

HookPermissionWhen, and with what
start()noneonce, right after create. It runs beside the message loop, so it can await calls
stop()nonewhen Comms Array closes, the player switches you off, or you're updated. Be quick
on_state(state)state.livethe live state changed, at most 10 a second. state is the game's own shape; api.latest_pad is the game-neutral one. If you're slow, the states in between are skipped (you always get the newest)
on_event(event)events.gamea game event: {"type", "data", "ts"} (event, below)
on_journal(event)events.journalone of the game's raw log events (journal event, below)
on_party(party)party.read (1.1)the party changed (at most once a second); None when the player unticked party.read
on_game(game)nonethe active game changed, or its engine started or said hello again: the game object
async handle_pad(device, body)pad.widgetsone of your frames called CA.call(body). Return (dict, code)
async handle_call(fn, caller, body)none (they need uses.<you>.<fn>)another add-on called one of your provides. caller is its name. Return (dict, code)
device_gone(device_id)nonea pad disconnected: let go of anything you held for it

handle_pad and handle_call must answer within 10 seconds (the caller then gets 504 timeout). Return a JSON-able dict and an int code: 200 for success, 4xx for "no", the same way Comms Array answers you.

The game object

api.active_game, on_game(game). No permission needed.

FieldWhat
idthe game's id: starcitizen, elite, ... (null with no game)
engine_versionthe version of the engine reading it
namethe game's name, for people
statusthe engine's status: off, waiting (the game isn't running), connected, live (data is flowing)
tagsevery situation tag the game has: {tag id: label}
metricsevery value the game describes: {value id: description} (value description, below)

Pad values

api.latest_pad and (await api.state())["pad"], state.live. The game-neutral live view, the same one the pad draws from.

FieldWhat
tagsthe tag ids that are on right now: ["live", "in_ship", "landed"]
metrics{value id: presented value} for every described value (unknown ones as fresh: "unknown")
lamps1.5: {action id: "on" | "off" | "busy"}, what lights the pad's buttons ({} when the game isn't live). Only actions whose state the game reports have one

api.latest_state (and state in on_state) is the game's own shape, unlike this one: it can change with the game, so prefer latest_pad where it has what you need.

Value description

What a value is: active_game["metrics"][id], CA.describe(id). The full format is the engine contract's "Described values"; in short:

FieldForWhat
labelallthe value's name, for people
groupallwhere it's listed (Ship, Flight, ...)
typeallnumber, bool, enum, text or list
rangenumber[min, max]: a gauge's empty and full
unitnumbershown after the number (m/s, %, t)
formatnumberdecimals (the default), percent, duration (seconds), heading (degrees)
decimalsnumber0-6
levelsnumber{"warn": x, "bad": y, "low_is_bad": true}
levelsenum, bool{value: level} (bools: "true", "false")
valuesenum, bool{value: word to show}
oflistthe description of each part
itemslistthe parts' labels in order (each a string or {"label", "levels"}); without it, the parts change and each brings its own label

Which widget kinds can show a value (CA.values(kind), a value setting's kind):

KindShows
gaugea number with a range, or with format: "percent"
readouta number, bool, enum or text
partsa list
lightanything with a level: a number, bool, enum, or a list (one of its parts, picked by label, or the whole list)

Presented value

What a value is now: pad["metrics"][id], CA.value(id). Already formatted and coloured by the PC, exactly as the pad's own widgets show it.

FieldWhat
vthe raw value in its own unit (a number, true/false, an enum value, a text, a list), or null
tthe text to show: "80%", "deep space" (the game's own text). "—" when unknown
levelok, warn, bad, off or ""
pos0..1, where a number is in its range (a gauge's fill), or null
freshlive, last_known (from a log, not live; see age) or unknown
ageseconds since a last_known value was true, or null
partslist values only: [{"label", "v", "t", "level", "pos"}]

Event

on_event(event), events.game.

FieldWhat
typewhat happened: player.downed, vehicle.missile_warning, ... (each game's list: Game events)
datathe event's details, a dict (each type's in the events page)
tswhen, in seconds since 1970 (UTC)

Journal event

on_journal(event), events.journal. One of the game's own log lines, read into a dict: type (each game's list: Game events, "Log events") plus that type's fields as the game wrote them. Never chat and never other players' names: the engine drops chat and social lines and strips name fields before you get it.

Device

handle_pad(device, body): the pad (or companion program) that called.

FieldWhat
idthe device's id (d_...). Stable until the player unpairs it; device_gone gets the same id
namethe name the player gave it ("Kitchen tablet")
can_editwhether the player lets devices edit layouts (the PC's setting): use it to decide whether a pad may change your shared settings

Status

Whatever dict you pass to api.set_status. Comms Array doesn't read inside it: it hands it to your frames as CA.pad.status, with running (bool) added. Frames get it when they're drawn (a page change, a layout save, a reload), so it suits slow-changing things ("4 rules", "signed in as ..."). For anything live, answer CA.call or send CA.share between your frames.

The pad side

Your pad_js runs in a frame: /pad/sandbox.html in a sandboxed iframe with an opaque origin. Each tile of yours is one frame, each open panel another, and one hidden frame runs once to read your widget kinds (the define frame). In every frame the global CA is the pad's SDK.

CA.widget(type, def): a widget kind

type: lowercase letters, digits and _, starting with a letter, up to 40 (and listed in the manifest's widgets).

def fieldWhat
addhow the kind appears in the pad's Add widget list (below)
settingsthe fields the pad draws for it in edit mode (below)
tile(root, w, ctx)draws the tile into root. May return {update(state)}, called with every live state
panels{name: (root, w, ctx) => ...}: full-screen panels, opened with CA.openPanel(name) or a panel setting. Names: a-z 0-9 _ -, up to 40
add fieldWhat
labelthe name in the list (40)
descone line under it (200)
size[w, h] in cells when added: w 1-32, h 1-40 (default [1, 1]). Cells are square and small (about 50 px on a landscape tablet); the pad's own widgets are 2x2 to 4x2, so [4, 4] is a good start for a widget with some text
propsa function returning the new widget's starting fields: () => ({label: "Taps"}) (24 fields; text, numbers or booleans of up to 200 characters; not id, type, x, y, w, h, when)
plate1.3. false: the kind draws edge to edge and never sits on a button pack's plate (a map, a camera)
look1.4. "own": the kind starts in your own look rather than the pack's (the default, "pack"). The player can switch each widget (Button packs, "Your widget in the pack's parts")

Settings fields

Up to 20 per kind. Each one's value is saved on the widget under its key (lowercase, digits and _, starting with a letter, up to 31; not id, type, x, y, w, h, when). A field that doesn't fit these rules isn't drawn.

typeDrawsIts own fieldsSaves
texta text boxmax (1-200, default 80)a string
numbera number boxmin, max, stepa number (0 when empty)
selecta drop-downoptions: up to 50, each a value or [value, label]the value, as a string
checkboxa tick boxtrue / false
valuethe pad's value picker (only values that fit)kind: gauge, readout, parts or lighta value id
panela button that opens one of your panelspanel: the panel's name (no key)nothing

Every field also takes label (40) and help (300, a line under it).

w: the widget

The widget as saved in the layout, a copy (changing it changes nothing).

FieldWhat
idthe widget's id, stable while it's on the page
typeyour kind
x, y, w, hwhere it is on the grid and its size in columns and rows (w.w is the width: name your own fields something else). when is reserved too
your fieldseverything your props and settings saved: 24 fields at most, text, numbers or booleans, up to 200 characters each
ca_look1.4, the pad's own: the player's look for this widget ("pack" or "own"), when they picked one. Reserved: a setting can't use the name

ctx

FieldWhat
editingthe pad is in edit mode: taps move the widget, so don't act on them
panelin a panel, its name; "" in a tile

CA: everything in a frame

MemberWhat
CA.widget(type, def)register a widget kind (above)
CA.statethe newest live state (below). Replaced with every update
CA.onState(fn)fn(state) on every update (a tile's update gets it too)
CA.value(id)the presented value; {v: null, t: "—", level: "", pos: null, fresh: "unknown", age: null, parts: []} when the game doesn't have it
CA.describe(id)the value description, or null
CA.values(kind)the value ids a gauge, readout, parts or light can show
CA.padfacts about the pad (below), fixed for the frame's life
CA.editingthe same as ctx.editing
await CA.call(body)sends body (a plain object, 16 KB) to your handle_pad and resolves with its dict. Never rejects: {status: "offline"} when the PC can't be reached or doesn't answer in 25 s, {status: "rate_limited"} past 4 at once, {status: "bad_request"} when too big
CA.toast(text)a short message at the bottom of the pad (300 characters)
CA.buzz(ms)vibrate: milliseconds (0-1000) or a pattern of up to 10
CA.openPanel(name)open one of your panels. Only right after the player tapped this tile (within 1.5 s) and never in edit mode
await CA.pickAction()1.5, with actions.press or input.keys: the pad's own action picker (subjects, search, the game's words) over this frame, right after the player tapped it (as CA.openPanel), never in edit mode. Resolves with the chosen catalogue row ({action, name, variants, key, api, lit, ...}, as api.catalog) or null (cancelled, not allowed, not after a tap). One at a time
CA.close()in a panel: close it
CA.sheet(html, wire)in a panel: draw html as a pad sheet page (pad.css sheet styles), then wire(root) to hook it up
CA.share(data)send data (JSON, 8 KB) to every other open frame of your add-on
CA.onShare(fn)fn(data) for each CA.share from another of your frames
CA.party1.1, party.read: the party object; null without the permission
CA.pack1.3: the colours of the button pack in use (below), or null. With Match my ship it's the ship's pack, and your frames are drawn again when it changes
CA.plated1.3: this tile sits on the pack's plate
CA.clear1.6: the layout is Clear (an overlay over a game): draw no background behind your tile. pad.css boxes ("w b") in your frame go clear by themselves, with outlined text
CA.look1.4: "pack" (the pack's stylesheets and parts are in this frame) or "own" (yours; also with no pack)
CA.lamp(level)1.4: the pack's own lamp for a level (ok, warn, bad, off, ""), as HTML; a plain pk-led in your own look
CA.table(cols, rows, empty)1.4: the table part's HTML (cols: [{kind, label, w}], kinds text, num, lamp, bar; rows: [{cells, level, on}])
CA.fitTable(el)1.4: folds the table's rows that don't fit el into "+N more" (call it once the table is in the page)
CA.esc(s)HTML-escape a string: use it for anything you put in innerHTML
CA.clamp(v, lo, hi)a number kept between two others
CA.flash(el, ok)flash an element green (ok) or red (a "w b" box's border)

CA.toast and CA.buzz together are limited to a few at a time (about one a second after that).

Live state

CA.state, update(state), CA.onState(fn). What the pad gets from the PC, as each frame sees it.

FieldWhat
gamethe engine's status: off, waiting, connected, live
enginethe active game's id
tagsthe tag ids on now
metrics{value id: presented value}
lamps{action id: "on" | "off" | "busy"}: what the game says each action's thing is
panelsthe game's ready-made panels' data (the pad draws them; their shape is the game's)
stripthe pad's top line: {title, values, badges}
profilethe current profile key (in Star Citizen, the ship): pages can be set per profile
playerthe player's in-game name, if the game says it
devicethis pad: {id, layout}
layouts_revchanges whenever a layout is saved
talways "state"
party1.1, party.read only: the party object (also CA.party). Without the permission it isn't there at all

CA.pad: facts about the pad

FieldWhat
titleyour add-on's title
statusyour api.set_status dict, plus running
profilesthe profile keys the player has (ships, for Star Citizen)
profile_groups{profile: [profile keys]}: profiles the player's pages treat as one
glossarythe game's own words: {"player": "handle", "vehicle": "ship", ...} (Games)
metricsevery value description (what CA.describe reads)
values{gauge: [...ids], readout: [...], parts: [...]} (what CA.values reads)
accentthe layout's accent colour (also --accent)
packthe same as CA.pack

CA.pack: the button pack's colours

1.3. In every frame, null when the layout has no pack. Every part by name: Button packs.

FieldWhat
namethe pack's name, for people ("Spearhead")
facethe plate's face colour
accentthe pack's accent
lampthe lamp colour (lit)
okfine: the lamp colour
warn, badamber and red, the same in every pack
offsomething that's off (a soft grey)
wellthe plate's rim colour: what a gauge's bar sits in
edgethe plate's outer edge
text, dimtext that reads on the face, and a quieter one
roundthe pack draws gauges as ring dials
segmentedthe pack's bars are ten lit blocks, not a smooth fill

On the plate (CA.plated), the pad's CSS variables in your frame are the pack's:

VariableIs
--text, --dimtext, dim
--ok, --warn, --bad, --offthe level colours
--accentaccent
--pk-face, --pk-lamp, --pk-accent, --pk-well, --pk-edgeface, lamp, accent, well, edge

Off the plate (no pack, panels, plate: false tiles) the variables are the pad's own dark theme: --bg, --panel, --btn, --edge, --text, --dim, --ok, --warn, --bad, --accent, --off, --purple.

pad.css: the classes you can use

Your frame loads the pad's stylesheet, so your tiles can look like the pad's own widgets. These classes are the ones we keep working for add-ons; anything else in pad.css is the pad's own and can change.

ClassWhat
wa tile's box (rounded, bordered). Your root element in a tile: <div class="w b">
ba button-like tile: centred column, bold label. Clear on a pack's plate, so the plate shows
suba second, smaller, dim line in a b
lampa small lamp in a b; lit when the b also has on, blinking with busy
on, busyon a b: lit (green), waiting
naon a b: not available (faded)
c-blue, c-green, c-amber, c-red, c-purple, c-greyon a b: the pad's button colours
staleon a w: the value is the last known one, not live (faded, with a small ring)
dim, badtext colours
chip, chipssmall rounded tags, and a row of them
pilla small capsule label
sheet, row, primaryin a panel (CA.sheet): the page, a row of controls, the main button (<button class="primary">)

CA.flash(el, ok) adds flash-ok / flash-bad for you.

1.4, the pack's parts by class name (plain in your own look, the pack's in its look): pk-tabs / pk-tab, pk-toggle, pk-btn, pk-led, pk-screen and pk-table, each with on for the chosen or lit one. Every one, with its markup: Button packs, "Your widget in the pack's parts".

What a frame can't do

  • No network. No fetch, WebSocket or images from addresses: everything goes through CA.call to your Python side. Images only as data: or blob: URLs.
  • No storage. No cookies, localStorage or IndexedDB: keep what you need in your Python side's data_dir, or in the widget's settings.
  • No way out. No popups, no navigating (a frame that navigates is removed), no reaching the pad page or the player's login.
  • Messages are checked. A frame that sends more than about 120 messages a second is removed and its tile shows "stopped". So is a frame that loads twice.
  • Your widget kinds are read from the define frame within 4 seconds of the pad loading, and that list is 32 KB at most.

Limits, all in one place

LimitValue
live states to on_stateat most 10 a second (the newest wins; one that came inside the window arrives when it ends)
presses (api.press, api.keys tap and down)1.5: 10 a second, 20 at once, per add-on (429 rate_limited)
taps of one key waiting their turn1.5: 10 (429 busy)
api.catalog answerup to 500 rows, and under 200 KB
party updates to on_partyat most 1 a second
a call from Pythonwaits 15 s
your handle_pad / handle_call answerwithin 10 s
one message between your process and Comms Array256 KB
CA.call from a pad16 KB body, 4 at once, 10 a second per device (20 in a burst), 25 s to answer
CA.share8 KB
CA.toast text300 characters
widget kinds' description32 KB
widget fields24 per widget, 200 characters each
settings fields20 per kind
device logins3 per add-on
pages in the manifest8, each 1-80 widgets
crashes5 in 5 minutes, then Comms Array stops restarting you until the player does
From the Comms Array source, commsarray-agent d615c4d.