Skip to content

Session & host state ​

Read conversation history, read pipeline state, list installed plugins, locate plugin directories / runtimes by id, write logs.


Session and history ​

python
host.get_recent_conversation(max_turns: int = 5) -> list[dict]
host.get_history_as_text(query: str = "") -> str

Each get_recent_conversation item:

python
{
  "id": int,
  "speaker": "peer" | "self",
  "speaker_label": str,     # display name, already localised with the UI language
  "transcript": str,        # raw ASR transcript
  "translation": str,
  "time": str,
}
  • Only valid sentences are included (transcript or translation non-empty).
  • max_turns is clamped to [1, 50].
  • Compatible alias: getRecentConversation.

When feeding an LLM (e.g. an assistant plugin), use transcript only: machine translation adds a second layer of distortion.

get_history_as_text(query) returns the history rendered as text (query, when non-empty, filters by keyword first); it is ready to be spliced straight into a prompt.


Pipeline and host state ​

python
host.get_pipeline_state() -> dict
host.get_active_provider(plugin_type: str) -> str
host.list_installed_plugins(type_filter: str = "") -> list[dict]
host.get_app_version() -> str
host.get_locale() -> str
host.log(level: str, message: str, **fields: Any) -> None

get_pipeline_state():

python
{
  "running": bool,
  "loading": bool,
  "scene": str,
  "source_lang": str,
  "target_lang": str,
  "outbound_source_lang": str,
  "outbound_target_lang": str,
  "show_source": bool,
  "show_translation": bool,
  "enable_translation": bool,
  "mic_muted": bool,
  "interpretation_mode": bool,
  "interpretation_streaming": bool,
  "providers": {
    "asr": str, "mt": str, "tts": str,
    "interpretation": str, "theme": str,
  },
}
  • get_active_provider("asr" | "mt" | "tts" | "theme" | "interpretation") → plugin id or "none".
  • Each list_installed_plugins(type_filter) item contains id / name / type / enabled / version / source_path (same source as the Workshop list). Passing "" or "all" to type_filter means everything; "other" means uncategorised.
  • get_locale() returns the current UI language (e.g. zh-CN / en-US).
  • log(level, message, **fields): level ∈ debug|info|warning|error, written to the host's plugin log channel, and may carry arbitrary JSON fields (host.log("info", "加载完成", ms=1200)). This is your only troubleshooting outlet — it is the first thing we see when a user sends logs.

Locating plugins and runtimes by id ​

python
host.plugin_dir(plugin_id: str) -> str        # install directory; "" when not installed
host.has_plugin(plugin_id: str) -> bool       # installed (enabled not required)
host.list_installed_plugins() -> list[dict]   # each item carries source_path
host.runtime_dir(runtime_id: str) -> str      # runtime directory; "" when not downloaded
host.has_runtime(runtime_id: str) -> bool     # whether the runtime is ready

Never hard-code a sibling plugin's directory name — a Workshop install names the folder after the plugin id (<data dir>/workshop/workshop.amd_llama), while one you drop into extensions/ yourself may use underscores. Looking it up by id is correct for both:

python
from pathlib import Path

dep = self.host.plugin_dir("workshop.common_llama")
exe = Path(dep) / "llama" / "llama-server.exe" if dep else None

The matching dependency declaration and host gate are in Prerequisite plugins and Host runtimes.


Recommendations ​

  • When you need to know "is it running right now" rather than "read the state once", subscribe to the pipeline.state event instead of polling get_pipeline_state() (see Event bus).
  • When deciding availability in check_ready(), use plugin_dir() / runtime_dir() / inspect_model_artifact() to make a file-level decision instead of starting a service (see Capabilities & read-only contract).

TransBox — empowering borderless cross-language communication for everyone