@faceclaw/evenhub-extensions
Types and a small helper for the Faceclaw extension API.
Faceclaw is an alternative host for
EvenHub apps: it runs them on the Even Realities G2 glasses without the stock
Even app. An app built against the standard @evenrealities/even_hub_sdk
runs unchanged. This package lets such an app detect that it is running
inside Faceclaw and use a few extra, Faceclaw-only capabilities.
The only entry point is the injected global window.getFaceclawExtensions,
which is a function inside Faceclaw and undefined in the stock Even app and
every other host. Nothing on the standard SDK, on window, or on any built-in
prototype is modified, so an app that uses these extensions still runs
everywhere else; it just skips the extras.
Example
import { getFaceclawExtensions } from "@faceclaw/evenhub-extensions";
const fc = getFaceclawExtensions();
if (fc) {
console.log("Running in", fc.getVersion()); // "Faceclaw/0.8.2"
fc.addWindowLifecycleListener((e) => {
if (e.type === "hidden") pauseExpensiveWork();
});
}
Entry point
FaceclawExtensions
The Faceclaw-only capability surface, obtained with getFaceclawExtensions. Everything here is in addition to the standard EvenHub SDK.
Calls that return a promise reject with an Error if the host fails to
carry them out.
Properties
Methods
getVersion()
getVersion(): string;
The host's name and version, for example "Faceclaw/0.8.2". For display
and logging; use FaceclawExtensions.apiVersion for feature checks.
Returns
string
returnToAppSwitcher()
returnToAppSwitcher(): void;
Hand input focus back to Faceclaw's app switcher without closing the app, which keeps running in the background.
Returns
void
quit()
quit(): void;
Close this app and tear down its window.
Faceclaw treats the stock shutDownPageContainer(1) as "return to the app
switcher", so apps that quit on double-tap stay alive. This method always
quits.
Returns
void
addWindowLifecycleListener()
addWindowLifecycleListener(listener): () => void;
Subscribe to window lifecycle changes (see WindowLifecycleEventType).
Parameters
| Parameter | Type | Description |
|---|---|---|
listener |
(event) => void |
Called on each transition. |
Returns
A function that unsubscribes listener.
() => void
getConfiguredApiKeys()
getConfiguredApiKeys(): Promise<ApiKeyService[]>;
List the services whose API keys the user has configured in Faceclaw. This returns only the service names, never the keys, and doesn't prompt the user. Use FaceclawExtensions.requestApiKeyAccess to obtain the keys.
Returns
Promise<ApiKeyService[]>
requestApiKeyAccess()
requestApiKeyAccess(services): Promise<Partial<Record<ApiKeyService, string>>>;
Ask the user to share one or more configured API keys with this app. This opens a consent prompt on the glasses, unless the user already granted these services to this app earlier in the session.
Parameters
| Parameter | Type | Description |
|---|---|---|
services |
ApiKeyService[] |
The services whose keys the app wants. |
Returns
Promise<Partial<Record<ApiKeyService, string>>>
A map from service to key, containing only the services that were both requested and configured. It is empty if the user declines.
playBuzzer()
playBuzzer(steps): Promise<void>;
Play a tone sequence on the glasses' piezo buzzer. Sequences longer than the firmware's per-message limit of 48 steps are split and paced automatically.
Parameters
| Parameter | Type |
|---|---|
steps |
BuzzerStep[] |
Returns
Promise<void>
A promise that resolves once every part of the sequence has been queued on the glasses, which can be before it finishes playing.
addCompassListener()
addCompassListener(listener): () => void;
Turn on the glasses' magnetometer and receive heading samples. The sensor stays on while at least one listener is registered, and readings are only delivered while the app is the foreground window.
The magnetometer sits inside the right arm, which rests against the wearer's head at an angle that differs between wearers (and between wears), so the raw heading is only relative. See CompassReading for the corrected headings and when to trust them.
Parameters
| Parameter | Type | Description |
|---|---|---|
listener |
(reading) => void |
Called with each sample. |
Returns
A function that unsubscribes listener.
() => void
createLayout()
createLayout(layout): Promise<boolean>;
Build the app's page from an extended layout. This is a superset of the
stock createStartUpPageContainer; see FaceclawLayout for the
differences.
Unlike the stock call it may be called more than once. Once an app uses an
extended layout, its window stays at the full 576×452 size for the rest of
the session, including for later stock rebuildPageContainer calls.
Parameters
| Parameter | Type |
|---|---|
layout |
FaceclawLayout |
Returns
Promise<boolean>
A promise that resolves to true on success.
replaceLayout()
replaceLayout(layout): Promise<boolean>;
Replace the current page with a new extended layout. This is a superset of
the stock rebuildPageContainer. Containers marked preserve inherit
their content from the same-named container in the outgoing layout.
Parameters
| Parameter | Type |
|---|---|
layout |
FaceclawLayout |
Returns
Promise<boolean>
A promise that resolves to true on success.
setAssistantTools()
setAssistantTools(tools): void;
Declare the app's voice-assistant tools, replacing any set earlier. Each
tool's handler runs in the app when the assistant calls it.
Parameters
| Parameter | Type | Description |
|---|---|---|
tools |
AssistantTool<any>[] |
The tools to offer. Pass [] to remove them all. |
Returns
void
getFaceclawExtensions()
function getFaceclawExtensions(): FaceclawExtensions | null;
Return the Faceclaw extension API if the app is running inside Faceclaw, or
null otherwise (in the stock Even app, a browser, a simulator, or Node).
Safe to call anywhere, at any time; Faceclaw installs the API before any page
script runs.
Returns
FaceclawExtensions | null
Window lifecycle
WindowLifecycleEventType
type WindowLifecycleEventType = "visible" | "hidden" | "focused" | "blurred";
A window lifecycle transition, delivered to FaceclawExtensions.addWindowLifecycleListener.
visible/hidden: the app's glasses window became the shown surface, or stopped being it. This happens when the user switches the foreground window or the phone screen turns on or off. A hidden app keeps running (Faceclaw keeps its webview alive), but nothing it renders reaches the glasses.focused/blurred: input focus moved onto or off the app's window (for example, the user opened the app switcher). A blurred app can still be visible, but it doesn't receive taps or scrolls.
An app can assume it starts visible and focused at launch. Events report
changes from there.
WindowLifecycleEvent
Payload of a FaceclawExtensions.addWindowLifecycleListener callback.
Properties
| Property | Type | Description |
|---|---|---|
type |
WindowLifecycleEventType |
Which transition happened. |
API keys
ApiKeyService
type ApiKeyService = "openai" | "anthropic" | "soniox" | "elevenlabs" | "mapbox";
Third-party services whose API keys the user may have configured in Faceclaw.
Buzzer
BuzzerStep
One step of a piezo-buzzer tone sequence. The G2 has a single monophonic PWM buzzer, and the firmware plays a sequence's steps back to back on its own timer.
Properties
Compass
CompassReading
A magnetometer heading sample from FaceclawExtensions.addCompassListener. All headings are in degrees clockwise, in the range [0, 360).
Prefer trueHeadingDegrees when it is present, then magneticHeadingDegrees.
If wearerCalibrated is false, treat both as relative headings, or let the
user zero them.
Properties
Extended layout
FaceclawContainerCommon
Fields shared by every container in a FaceclawLayout. They match the
stock SDK's container-property classes, plus preserve.
As in the stock SDK every field is optional, so the stock
TextContainerProperty, ImageContainerProperty and ListContainerProperty
classes can be passed directly. In practice you should set containerID,
containerName and the geometry on every container.
Extended by
Properties
FaceclawTextContainer
A text container. The fields match the stock SDK's TextContainerProperty, plus preserve.
Extends
Properties
FaceclawImageContainer
type FaceclawImageContainer = FaceclawContainerCommon;
An image container. The fields match the stock SDK's ImageContainerProperty,
plus preserve.
In the extended layout an image container may be as large as the whole
576×452 canvas; the stock limit is 288×144. Push pixels with the stock
updateImageRawData, which in Faceclaw accepts PNG, uncompressed BMP, or raw
grayscale sized to the container (8 bits per pixel, or 4 bits per pixel packed
two to a byte, high nibble first).
FaceclawListItems
The items of a FaceclawListContainer. Matches the stock ListItemContainerProperty.
Properties
FaceclawListContainer
A list container. The fields match the stock SDK's ListContainerProperty, plus preserve.
Extends
Properties
| Property | Type | Description |
|---|---|---|
containerID? |
number |
Container identity. Stock content updates (textContainerUpgrade, updateImageRawData) address containers by this ID. |
containerName? |
string |
Container name. preserve matches containers across layouts by name. |
xPosition? |
number |
Left edge in pixels on the 576×452 canvas. |
yPosition? |
number |
Top edge in pixels on the 576×452 canvas. |
width? |
number |
Width in pixels. |
height? |
number |
Height in pixels. |
zOrderIndex? |
number |
Stacking order: higher values draw on top. |
isEventCapture? |
number | boolean |
When set to 1/true, this container receives the app's tap and scroll events. Exactly one text or list container per layout should capture events. |
preserve? |
boolean |
When true, inherit content (text, image pixels, or list items and selection) from the container of the same kind and containerName in the previous layout. Otherwise the container starts blank. |
itemContainer? |
FaceclawListItems |
The list's items and selection style. |
borderWidth? |
number |
Border width in pixels, 0–5. Wider values are clamped. |
borderColor? |
number |
Accepted for compatibility with stock payloads. Faceclaw currently ignores it. |
borderRadius? |
number |
Border corner radius in pixels. |
paddingLength? |
number |
Padding between the border and the items, in pixels. |
FaceclawMenu
The page's contextual menu. Matches the stock SDK's MenuContainerProperty,
with the same limits: at most 10 items, each itemID a unique non-zero
uint32, and each itemName at most 32 UTF-8 bytes. Selections arrive as the
stock menuItemClickEvent.
Properties
| Property | Type | Description |
|---|---|---|
menuItems? |
object[] |
Menu entries, in display order. |
FaceclawLayout
A page layout for FaceclawExtensions.createLayout and FaceclawExtensions.replaceLayout.
It has the same shape as the stock CreateStartUpPageContainer /
RebuildPageContainer, so you can build it with the stock SDK's container
classes, with three differences:
- The canvas is the full 576×452 app area instead of 576×288, so image containers may be up to 576×452.
- There is no limit on the number of containers.
- Each container may set
preserve: trueto inherit its content from the same-named container in the previous layout.
Properties
| Property | Type | Description |
|---|---|---|
textObject? |
FaceclawTextContainer[] |
Text containers. |
imageObject? |
FaceclawContainerCommon[] |
Image containers. |
listObject? |
FaceclawListContainer[] |
List containers. |
menuObject? |
FaceclawMenu |
The page's contextual menu. Omit it to clear any previous menu. |
containerTotalNum? |
number |
Accepted for compatibility with stock payloads and ignored: there is no container limit. |
Assistant tools
JsonSchema
type JsonSchema = Record<string, unknown>;
A JSON Schema object describing a tool's arguments.
AssistantTool
A tool the app contributes to Faceclaw's voice assistant, for use with FaceclawExtensions.setAssistantTools.
The assistant sees the tool namespaced by the app's package name, as
app.<packageName>.<name>. name here is the bare name without that prefix.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
Args |
any |
The arguments object the assistant passes to handler, as described by parameters. |
Properties
| Property | Type | Default value | Description |
|---|---|---|---|
name |
string |
undefined |
Bare tool name (no package prefix), for example "set_color". |
description |
string |
undefined |
What the tool does. The assistant reads this to decide when to call it. |
parameters? |
JsonSchema |
{ type: "object", properties: {} } |
JSON Schema for the arguments object the assistant will pass to handler. |
availability? |
"open" | "foreground" |
"foreground" |
When the tool can be called: "foreground" only while the app owns the visible window, or "open" any time the app is running, including in the background. |
handler |
(args) => unknown |
undefined |
Called when the assistant invokes the tool. Return a string, or any JSON-serializable value, to report back to the assistant. Throw (or reject) to report an error. May be async. |