@laplace.live/persona-sdk
v1.49.0
Published
TypeScript SDK and wire schema for the LAPLACE Persona plugin API
Readme
@laplace.live/persona-sdk
TypeScript SDK and wire schema for the LAPLACE Persona plugin API — a token-authenticated WebSocket API for driving the avatar, scenes, expressions, motions, hotkeys, and tracking parameters from outside the app.
Isomorphic: runs in Node ≥24, Bun, browsers, and OBS browser sources on the global WebSocket.
One runtime dependency (zod, backing the wire schemas).
Setup
Enable the API in Persona under Advanced → Plugin API, create a key, and copy the token.
import { PersonaClient } from '@laplace.live/persona-sdk'
const persona = new PersonaClient({ token: 'sk-lp-v1-…' })
await persona.connect()
// Typed request/response
const { scenes, activeSceneId } = await persona.call('scene.list')
await persona.call('expression.toggle', { name: 'Smile' })
await persona.call('scene.patch', {
background: { mode: 'color', color: '#112233', imageAssetId: null },
})
// Events (subscriptions survive reconnects)
persona.on('motion.started', m => console.log('playing', m.group))
// Parameter leases: the value keeps applying until released; the SDK owns the
// heartbeat, and if your process dies the parameter reverts within ~1 s.
const mouth = persona.driveParameter('MouthOpen', 0.8)
mouth.set(0.3)
mouth.release()By default the token travels as ?token= (works in browsers). From Node, createNodeClient
sends it as an Authorization: Bearer header instead, over Node's global WebSocket, and
logs the close that ends a session for good (the key revoked, or the session disconnected in
Persona):
import { createNodeClient } from '@laplace.live/persona-sdk'
const persona = createNodeClient({ token, log: console.warn })
await persona.connect()Any other socket that can set headers, such as the ws
package, plugs into new PersonaClient({ token, auth: "header", createWebSocket }).
Identifying your app
Pass clientInfo so your app shows up by name under Connected Clients in Persona's
settings (optional — unidentified clients work the same). The SDK re-declares it on every
reconnect; it is self-declared and display-only, never authorization:
const persona = new PersonaClient({
token,
clientInfo: { name: 'My Overlay', version: '1.2.0', developer: 'You' },
})Two server close codes are terminal and stop the reconnect loop: CLOSE_KEY_REVOKED (4001,
the key was revoked) and CLOSE_FORCE_DISCONNECTED (4002, the user disconnected the session
in Persona). The client reports them via onWarning and goes closed.
Treat the token like a password: it grants control of the app, including loading registered
models and web overlays. The server listens on loopback unless LAN access is enabled in
Persona's settings. To reach it on another computer, personaWsUrl({ host, port }) builds the
url; parseHost and parsePort check what a user typed into a form first.
Errors
When the connection fails, connect() and call() reject with a PersonaClientError whose
reason is one of CLIENT_ERROR_REASONS. Either can see connection-closed or
client-closed. Only connect() sees connect-timeout, after connectTimeoutMs, and the
attempt keeps dialing past it, so call close() to give up. Only call() sees
not-connected and request-timeout. A url the socket can't take at all rejects
connect() with the platform's own error instead, such as a TypeError for a malformed one.
When Persona answers a call with an error, call()
rejects with a PersonaApiError instead, whose code is one of API_ERROR_CODES. Switch on
reason and code, never on the English message.
Shortcuts
Hotkey.accelerator and AutomationInfo.accelerator hold up to three +-joined inputs fired
as a set — modifiers (MODIFIER_TOKENS), keys, mouse buttons, or one controller's buttons — so
compare them with comboKey. acceleratorLabel draws one as Persona does, one key cap per
input. Pass the desktop's platform rather than your own, and your language's mouse-button
names if you localize:
const platform = persona.serverInfo?.app.platform ?? ''
acceleratorLabel('Shift+LeftMouseButton', platform) // ['⇧', 'Left Click'] when Persona runs on macOS
acceleratorLabel('Shift+LeftMouseButton', platform, {
LeftMouseButton: '左键',
RightMouseButton: '右键',
MiddleMouseButton: '中键',
})Registry and catalog metadata
model.list / asset.list return refs with provenance and attribution: every ref carries
origin ('bundled' for first-party content, shipped with the app or downloaded from the
Persona catalog; 'user' for anything the user added) and may carry optional author /
url credits.
CatalogItem is the transport-agnostic content-metadata shape behind pickers: a stable
id (scene refs key off it), an InventoryKind, display name, and optional
description, thumbnailUrl, previewUrl (a short looping video shown in the thumbnail's
place), version, author, url, and download (a CatalogDownload: an https zip with
its byte size and sha256). The Persona marketplace serves its catalog as { version, items }
at https://marketplace.laplace.live +
MARKETPLACE_ITEMS_PATH. healCatalog turns a parsed document into usable rows, dropping
malformed ones, and pickLocalized(item.description, locale) reads a description in the
reader's language, falling back to English.
healCatalogItem heals one row, and healCatalogRows(raw, healRow) a document through a
row healer of your own, keeping the first of two ids equal ignoring case. A row needs an
id that passes isCatalogId (one path-safe segment, since an id names an install folder),
a non-blank name, and a kind from CATALOG_KINDS; CATALOG_FORMAT is the document's
version. healSha256 reads a digest as 64 lowercase hex characters, and
payloadEntryPath checks a payload zip's entry name, answering the relative POSIX path an
extractor may write, or null; no two of a payload's entries may share a payloadEntryKey.
healLocalizedText heals a LocalizedText (en required, the other shipped locales
optional) and never promotes another locale to en.
