SDK API Reference
API
| API | 用途 |
|---|---|
createCompanionSDK(options) | 创建 SDK instance。游戏中使用 transport: "auto"。 |
context(name, definition) | 注册 companion 可读取的 game state。 |
command(name, definition) | 注册 companion 可以请求的 game-owned action。 |
observe(type, data, options) | 上报普通 gameplay fact。 |
signal(type, definition) | 定义希望 companion 关注的 rare moment。 |
status() | 返回 SDK version、protocol、transport 和 host connection state。 |
isHostConnected() | host initialization 后返回 true。 |
Context
ts
companion.context("scene.current", {
description: "Current scene and objective",
read: () => ({ scene: "market", objective: "Ask for water" })
});read 返回的值是 prompt-visible。不要包含 token、hidden answer 或 private note。
Command
ts
companion.command("dialogue.repeat", {
title: "Repeat line",
inputSchema: { type: "object", properties: {}, additionalProperties: false },
handler: () => ({ ok: true })
});Command 应该保持小而明确,并且对 player 有可见效果。
