SDK API Reference
createCompanionSDK
ts
const companion = createCompanionSDK({ transport: "auto" });| Option | Type | Description |
|---|---|---|
transport | "auto" | "iframe" | "wkwebview" | CompanionTransport | Host transport. Use auto for games. |
documentTitle | string | Runtime name reported during initialization. |
postMessage | (message) => void | Compatibility shortcut for custom hosts. |
context
ts
companion.context("scene.current", {
description: "Current scene and objective",
read: () => ({ scene: "market", objective: "Ask for water" })
});Contexts must return compact JSON-compatible state. Treat the returned object as prompt-visible.
command
ts
companion.command("dialogue.repeat", {
title: "Repeat line",
inputSchema: { type: "object", properties: {}, additionalProperties: false },
handler: () => ({ ok: true })
});Commands are game-owned actions. Validate inputs and keep effects visible to the player.
observe
ts
companion.observe("answer.wrong", { questionId: "q-1" }, {
context: "scene.current",
priority: "low"
});Use observations for normal game facts. They do not require the game to interrupt the player.
signal
ts
const repeatedWrong = companion.signal("learning.repeated_wrong", {
context: "scene.current",
commands: ["dialogue.repeat"],
priority: "high",
cooldownKey: "q-1-wrong"
});
repeatedWrong.emit({ attempts: 3 });Signals are for rare moments where the game explicitly asks the companion to pay attention.
status
ts
companion.status();| Field | Description |
|---|---|
sdkVersion | SDK package version. |
protocolVersion | Companion protocol capability. |
capability | Manifest capability required by the host. |
transport | Active transport kind. |
hostConnected | true after host initialization. |
