Briyah SDK - v2.0.6
    Preparing search index...

    Class Room

    Index
    • Parameters

      • id: string
      • name: string
      • goal: string
      • baseRoomDir: string = ''
      • storageDir: string = ''
      • roomStoreService: any = null

      Returns Room

    IMAGES_PER_TURN: 1

    One picture per agent per turn.

    • Parameters

      • message: RoomMessage
      • Optionaloptions: { suppressSituationUpdate?: boolean }

      Returns void

    • Parameters

      Returns void

    • Adds an agent to the room

      Parameters

      • agent: Agent

        The agent to add

      Returns boolean

      True if the agent was added, false if it was already in the room

    • Registers an agent that works for this room without ever taking a turn. Idempotent, since the illustration service resolves its agents on every call.

      Parameters

      • agent: Agent

        The off-roster agent whose spend belongs to this room

      Returns void

    • Parameters

      • existingNickname: string
      • targetNickname: string

      Returns boolean

    • Stops delivering errors to a subscriber.

      Parameters

      • key: string

        The key it registered with

      Returns void

    • Returns void

    • The agent this room would refuse to rename to nickname, if any.

      Separate from renameAgent so a caller renaming an agent that sits in more than one room can check them all before changing anything — a rename applied to two rooms and refused by a third would leave the agent named one thing and half the rooms pointing at another.

      Parameters

      • agent: Agent

        The agent being renamed, excluded from its own check

      • nickname: string

        The nickname it would take

      Returns string

      The conflicting agent's nickname, or undefined

    • Deletes an artifact from the room

      Parameters

      • name: string

        The name of the artifact to delete

      Returns boolean

      True if the artifact was found and deleted, false otherwise

    • Returns void

    • Returns string

    • Gets an artifact by name

      Parameters

      • name: string

        The name of the artifact

      Returns Artifact

      The artifact or undefined if not found

    • Returns number

    • Returns Agent[]

    • Gets all artifacts in the room

      Returns Artifact[]

      Array of artifacts

    • Returns Agent[]

      The off-roster agents, e.g. for cleanup when the room is deleted

    • Returns string

    • Returns string

      What Begin sends, or '' when this room offers no Begin

    • Returns Date

    • Returns string

    • The human the room falls back to when it has to pick one, which is whoever arrived first. Used to open the conversation and to attribute a message that arrives with no sender. Which one it is carries no meaning.

      Returns Agent

    • Returns string

    • The human-controlled agent a sender name refers to, matched the same way message targets are, or undefined when no human answers to that name.

      Parameters

      • sender: string

      Returns Agent

    • Gets the name of the default human-controlled agent

      Returns string

      The human agent's name or empty string if not found

    • Every human-controlled agent in the room, in arrival order.

      A room may have more than one: several people can share a browser, and one person can play several characters. Code that genuinely needs a single human uses getDefaultHumanAgent — but anything reacting to a message must resolve the human from its sender, because the sender is rarely the default.

      Returns Agent[]

    • Returns string

    • Returns RoomIllustrationMode

      When this room illustrates itself. Normalized the way getModerator() and getBeginInstruction() are, so that a snapshot of a room never given one equals a snapshot of a room given the default.

    • Returns string

      The image_models.json entry name, or undefined to use the env default

    • Returns boolean

    • Parameters

      • fromIndex: number = 0
      • includeThoughts: boolean = false

      Returns RoomMessage[]

    • Returns string

      The configured moderator nickname, or '' when none is set

    • Gets the agent that places messages the room cannot route mechanically.

      Prefers the configured setModerator nickname. The fallback to the first agent is how story rooms have always chosen theirs — the narrator is added first — and is kept so they keep working, but it is a guess: in any other room the first agent is whoever happened to be added first and has no moderate.prompt at all. Name one explicitly.

      The fallback prefers an agent whose own folder carries a moderate.prompt, because a folder that ships one was written to route for its domain and its examples are drawn from it. It has to ask for the folder's own file: common/prompts/moderate.prompt is the shared fallback, so every agent can moderate and asking whether one merely resolves the prompt would pick out nobody. Arrival order is consulted only when no folder is purpose-built, which is the ordinary case in a room assembled from generic agents.

      Returns Agent

      The moderator agent or undefined if the room is empty

    • Returns string

    • Returns string

      The pack this room is filed under, or undefined when it is not filed

    • Returns string

      The pack template's key, when this room came from one

    • Returns boolean

    • Returns string

    • Returns { numChars: number; numMessages: number }

    • Returns any

    • Gets the current story situation

      Returns string

      The current situation string

    • Gets the current in-story time (24-hour "HH:MM"), stored separately from the situation text.

      Returns string

      The current time string, or '' if none is set

    • Returns string

    • Returns string

    • Gets the artifacts delivered to an agent in the uncached per-turn prompt.

      Parameters

      • agentNickname: string

        The name of the agent

      Returns Artifact[]

      Array of transient artifacts readable by the agent

    • Gets the artifacts rendered into an agent's cached prompt block.

      Transient artifacts are deliberately excluded: they go in the per-turn prompt instead (see buildTransientPrompt), which is the whole point of marking one transient. They are still readable — getTransientArtifacts returns them, and a tool reads any artifact regardless.

      Parameters

      • agentNickname: string

        The name of the agent

      Returns Artifact[]

      Array of artifacts visible to the agent

    • Parameters

      Returns void

    • Parameters

      Returns void

    • Returns void

    • Parameters

      • agentNickname: string

      Returns boolean

    • True when nickname names a human-controlled agent in this room.

      Parameters

      • nickname: string

      Returns boolean

    • True when a message is the players talking among themselves: a whisper whose every target is a human-controlled agent.

      Such a message cannot reach the game. canHear restricts a whisper to its targets, so no AI agent hears it; every target is human, so no agent is prompted and nothing is spent. That is what lets the room take one out of turn and leave the floor untouched — the players get to chat across the table while an agent is mid-turn, and it still shows up in the transcript for everyone at the table to read.

      Parameters

      Returns boolean

    • Returns boolean

    • Checks if the room is currently adjourned

      Returns boolean

      True if the room is adjourned, false otherwise

    • True when the room is idle pending input from the human-controlled agent.

      This is distinct from isProcessingInProgress(): after an agent addresses the human, the room intentionally leaves processing "in progress" while it waits for the human's reply (the human's perceive never fires a response callback). Hosts should use this flag — not processingInProgress — to decide whether to show a typing indicator.

      Returns boolean

    • Moderator agent evaluates and routes a message (moved from Agent)

      Parameters

      • moderatorAgent: Agent

        The moderator agent

      • message: RoomMessage

        RoomMessage to moderate

      • onResponse: (message: RoomMessage) => void

        Callback with routing decision

      • opts: { note?: string } = {}
        • Optionalnote?: string

          Extra instruction for this one routing decision, put in the transient prompt so it never enters the moderator's cached prefix

      Returns Promise<void>

    • Returns void

    • Returns void

    • Allows an agent to perceive messages and generate a response (moved from Agent)

      Parameters

      • agent: Agent

        The agent that is perceiving

      • message: RoomMessage
      • onResponse: (message: RoomMessage) => void

        Callback with agent's response or null

      • opts: { continuing?: boolean } = {}

      Returns void

    • Creates or updates an artifact with PUBLISH action If body is empty, deletes the artifact instead

      Parameters

      • name: string

        The name of the artifact

      • creator: string

        The name of the agent who created it

      • body: string

        The content of the artifact (empty body will delete the artifact)

      • viewers: string[] = []

        Array of agent names who can view the artifact

      • Optionaltransient: boolean

      Returns Artifact

      The created or updated artifact, or null if deleted

    • Returns void

    • Removes a previously-registered state-change listener.

      Parameters

      Returns void

    • Renames an agent, and everything in this room that named it.

      A room routes by nickname and nothing else, so an agent whose character is called something different gives every other agent two names for one person. The Dungeon Master addresses the character, the room has never heard of them, and the message falls through to the moderator — see namesNobodyInADirectedRoom, which exists to catch exactly that and once absorbed about a quarter of a campaign's calls. This is the fix that makes the workaround unnecessary: give the agent the character's name.

      Expensive in the same way ToolRoomAccess.setDescription is, and for the same reason: the roster sits in every agent's cached prompt prefix, so a rename throws away the whole room's cache. Character creation is the moment for it, because play has not started; mid-scene it is a real cost.

      History is deliberately not rewritten. Past messages are a record of what was said, and rewriting them would mean parsing and re-serializing every entry, with compaction summaries reachable only by regex. Instead every agent is told, once, that the name changed — which is what lets them reconcile a roster that says Leah with a history that says StudentOne.

      Parameters

      • from: string

        The agent to rename, matched the way messages are routed

      • to: string

        The new name — a character name, which may be longer than a nickname

      Returns RenameResult

      What happened, including the reason when nothing did

    • Repoints everything in this room that named an agent, and tells the room.

      The room-side half of a rename, split out because an agent may sit in more than one room while its own record is only mutated once. renameAgent is this plus the agent itself.

      Parameters

      • previous: string

        The nickname being replaced

      • nickname: string

        The nickname replacing it

      Returns number

      How many artifacts changed

    • Returns void

    • Saves messages incrementally to disk

      Parameters

      Returns void

    • Saves the room metadata to disk

      Returns string

    • Replaces all agents in the room with new agents

      Parameters

      • newAgents: Agent[]

        Array of agents to set

      Returns void

    • Sets the room's artifacts (used when loading from storage)

      Parameters

      • artifacts: Artifact[]

        Array of artifacts to set

      Returns void

    • Parameters

      • dir: string

      Returns void

    • Sets what Begin sends to the room leader.

      Normalized to '' rather than left undefined, the same way getModerator() normalizes: a settings snapshot read from a room that was never given one must equal a snapshot of a room that was given a blank one, or the round-trip through RoomStoreService.applyRoomSettings is not one.

      Parameters

      • instruction: string

        The instruction; empty or undefined clears it

      Returns void

    • Parameters

      • date: Date

      Returns void

    • Parameters

      • agentNickname: string

      Returns void

    • Parameters

      • goal: string

      Returns void

    • Parameters

      • id: string

      Returns void

    • Parameters

      • mode: RoomIllustrationMode

      Returns void

    • Parameters

      • model: string

      Returns void

    • Parameters

      • isLoading: boolean

      Returns void

    • Names the agent that places messages the room cannot route mechanically.

      Parameters

      • agentNickname: string

        The moderator's nickname; empty clears it

      Returns void

    • Parameters

      • name: string

      Returns void

    • Subscribes to errors raised while running a turn.

      Keyed like setOnStateChange, and for the same reason: more than one thing wants to hear about a failed turn. A single-callback setter meant the last caller silently replaced the first — the SDK's bridge onto the room's update stream and a story's own handler could not both exist, and whichever registered second won without any sign that it had taken the other's place.

      Parameters

      • key: string

        Identifies the subscriber; registering the same key twice replaces it

      • callback: (error: Error) => void

        Function to call on errors

      Returns void

    • Parameters

      Returns void

    • Sets a callback to be invoked whenever situation changes

      Parameters

      • callback: (situation: string, messageBody?: string) => void | Promise<void>

        Function to call with new situation

      Returns void

    • Registers a state-change listener under a stable key. Each key holds at most one listener — re-registering with the same key replaces its callback. Different keys can coexist so multiple subsystems (e.g. the rooms SSE endpoint and the story service) both receive notifications without clobbering each other.

      Parameters

      • key: string

        Stable identifier for the subsystem (e.g. 'app-service', 'story')

      • callback: () => void

        Function to call on state changes

      Returns void

    • Files this room under a pack, or clears it.

      Parameters

      • pack: string

        The pack name; empty or undefined clears it

      Returns void

    • Parameters

      • key: string

      Returns void

    • Parameters

      • published: boolean

      Returns void

    • Parameters

      • agentNickname: string

      Returns void

    • Parameters

      Returns void

    • Parameters

      • service: any

      Returns void

    • Sets the current story situation

      Parameters

      • situation: string

        The situation string to set

      Returns void

    • Sets the current in-story time (24-hour "HH:MM").

      Parameters

      • time: string

        The time string to set

      Returns void

    • Parameters

      • dir: string

      Returns void

    • Parameters

      • templateId: string

      Returns void

    • Sets how the room chooses who responds to a message. See RoomTurnMode.

      Parameters

      • mode: RoomTurnMode

        The turn mode; anything unrecognized falls back to 'broadcast'

      Returns void

    • What this room has cost so far.

      The one place that knows the illustrator and artists are not in agents. Callers that used to reduce over getAgents() must use this instead, or image spend is invisible.

      Returns number

    • Extracts an opaque "preamble" block from the top of an agent response.

      A preamble is one or more consecutive <tag>value</tag> lines at the very start of the response, terminated by a blank line or non-tag content. The captured preamble is the verbatim text of those tag lines, suitable for downstream parsing by whoever owns the semantic interpretation (e.g. the story service for narrator responses).

      The Room itself never parses the preamble's contents. It just hands the text to the situation callback so callers (story, debate, etc.) can interpret it however they want.

      Parameters

      • response: string

      Returns { content: string; preamble: string }