Examples
These examples show the expected browser-game shape for @consenger/companion-sdk.
Vanilla browser game
html
<script src="./companion-sdk.js"></script>
<script>
const companion = window.Consenger.companion;
companion.context("round.current", {
description: "Current round state visible to the player",
read: () => ({
round: 3,
goal: "Pick the matching Japanese word",
choices: ["みず", "そら", "ねこ"]
})
});
companion.command("round.hint", {
title: "Show a hint",
inputSchema: { type: "object", properties: {}, additionalProperties: false },
handler: () => {
showHint();
return { ok: true };
}
});
</script>Phaser scene
ts
import { createCompanionSDK } from "@consenger/companion-sdk";
const companion = createCompanionSDK({ transport: "auto" });
export class QuizScene extends Phaser.Scene {
create() {
companion.context("scene.current", {
description: "Current quiz scene",
read: () => ({
scene: this.scene.key,
score: this.score,
prompt: this.currentPrompt
})
});
companion.command("scene.pause", {
title: "Pause the game",
inputSchema: { type: "object", properties: {}, additionalProperties: false },
handler: () => {
this.scene.pause();
return { ok: true };
}
});
}
}Godot Web export
For Godot Web exports, include the SDK browser bundle beside Project.html and call it from JavaScript glue code. Keep Godot gameplay state as the source of truth, then expose only small player-facing snapshots through companion.context().
