Skip to content

SDK API Reference

Package@consenger/[email protected]
Protocolcompanion.plugin.v1
RuntimeBrowser
StatusPublic alpha

createCompanionSDK

ts
const companion = createCompanionSDK({ transport: "auto" });
OptionTypeDescription
transport"auto" | "iframe" | "wkwebview" | CompanionTransportHost transport. Use auto for games.
documentTitlestringRuntime name reported during initialization.
postMessage(message) => voidCompatibility 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();
FieldDescription
sdkVersionSDK package version.
protocolVersionCompanion protocol capability.
capabilityManifest capability required by the host.
transportActive transport kind.
hostConnectedtrue after host initialization.