Packs, as this user sees them.
Campaigns: the streamlined D&D surface, built on packs and published rooms.
Whether this deployment permits users to author and run their own tools. Native (host-registered) tools are always available regardless.
Adds funds to the user's balance.
Use this to credit a user after a payment is processed by your application.
Dollar amount to add (must be positive)
Attaches a user artifact to an agent so the agent can read its content in prompts.
The attachment is persisted immediately via agent.save(). The artifact content
is injected into the agent's context on each subsequent call.
The agent's ID
The artifact's ID (from listUserArtifacts)
Attaches a document to an agent so it can reference the file's contents in prompts.
The file is stored on disk and uploaded to the AI provider if required (e.g. OpenAI file uploads, Grok file uploads). The agent state is persisted after attachment.
The agent's ID
File name including extension (e.g. 'report.pdf')
Raw file bytes as a Buffer
Object containing a documentId that can be used with deleteAttachedFileById
Opens a room by sending its begin instruction to the room leader.
A room is pull-driven: an agent is prompted only when a message arrives. So a room nobody has spoken in never moves, however complete its configuration — which for a turn-based table means the leader is waiting to be asked to lead. This is the ask.
Sent as System rather than as a person, and addressed by targets rather
than left for the room to place: in broadcast mode an untargeted message
prompts every agent, which for an opening move is one call per member to
decide one reply.
The already-begun check is here rather than left to the client because a
published room is one link the whole party holds. Two people looking at the
same empty transcript both press Begin, and only a check the room makes
itself stops the leader being opened twice. isProcessingInProgress() is the
half of it that covers the window before the first message lands.
The room's ID
Optionalcontext: unknown
Opaque host value threaded to any tool the turn invokes
Whether the message was accepted, as sendRoomMessage reports it
Summarizes and compresses agent conversation histories to reduce token usage.
Uses story-specific prompts: the narrator summarizes plot events, characters summarize their relationships and experiences. The original messages are replaced with a compact summary block.
The story's ID
Object with success flag, optional message, and compaction details
Converts a PDF to Markdown a page at a time and returns the pages.
The building block under convertUserArtifact, public because a host embedding Briyah usually wants the pages and the cost rather than an artifact — to extract records from each page, to cache the result under its own key, or to show progress. Every page is converted by its own throwaway agent, so nothing accumulates history and pages stay independent.
Bounded, retried and non-fatal: at most PdfMarkdownOptions.concurrency
pages are in flight, each page is retried on an empty response, a thrown
error or a timeout, and a page that exhausts its attempts is reported in
failedPages rather than failing the document.
The raw PDF
Models, prompt, hints and limits; every field has a default
The pages, the assembled Markdown, what failed, and the cost
Creates an artifact from a PDF by converting it to Markdown, running the conversion in the background.
Returns the artifact ID immediately with placeholder content. The artifact content is replaced with the converted Markdown when the background job finishes. If conversion fails, the artifact content is replaced with an error message.
Requires the DOC_CONVERSION_AI_SERVICE and DOC_CONVERSION_AI_MODEL
environment variables to be set to an AI service that supports PDF documents.
A PDF over ten pages is converted page by page, at most
PDF_CONVERT_CONCURRENCY at a time, with each page retried before it is
given up on. A page that is given up on does not fail the document: the
artifact still lands, naming the pages that are missing from it so they can
be re-run. Only a conversion that produces nothing at all replaces the
artifact with an error.
Display name for the artifact
Buffer containing the raw PDF data
The new artifact's ID (content is a placeholder until conversion completes)
Creates a new AI agent and registers it in memory.
The agent is immediately findable by ID but not persisted to disk.
Call agent.save() when you want to write it to storage.
Provider name (e.g. 'Anthropic', 'OpenAI'). Use getAiServiceNames for valid values.
Full name of the agent (used in conversation logs and file storage)
Short display name shown in the UI
Brief description of the agent's role or personality
Model identifier (e.g. 'claude-haiku-4-5', 'gpt-4o')
Prompt folder under data/prompts/ that provides the agent's system instruction. Defaults to 'default'.
OptionalcontrolledByHuman: boolean
If true, the agent's responses are driven by a human rather than the AI. Defaults to false.
OptionalreasoningEffort: "low" | "medium" | "high"
Extended-thinking effort level for models that support it (e.g. Claude 3.7 Sonnet, o1/o3). Pass null to disable. Defaults to undefined (model default).
OptionalmaxOutputTokens: number
Override the model's default maximum output token limit
OptionalbeginInstruction: string
Optional prompt stored with the agent and sent when the host app triggers a "Begin" action (e.g. 'Begin by reading the attached documents and asking the user the first question.')
Optionaloptions: AgentCreationOptions
Everything else an agent can be created with: tool grants, private context, prompt cache TTL, search, the history window and the small-model override. Add new settings here rather than as further positional parameters.
The newly created Agent instance
Creates an agent from a prompt folder, applying everything that folder declares.
A folder's defaults_config.json names the role: what it is called, which tools
it needs, which documents it carries. createAgent takes none of that —
it takes eleven positional arguments and an options object, and leaves the
mapping to the caller. Every caller then writes the same mapping: the web
client's create-agent dialog, and every SDK host after it. Hard-coding the
result instead is worse, because a pack's tool and document lists change and a
transcribed copy does not.
Differences from createAgent, each deliberate:
attachDocuments is false.
PromptFolderDefaults.documentIds describes them as a pre-tick that
stays the user's choice, which is right for a dialog where somebody can untick
a box; headless there is nobody to untick, and a character creator without its
class documents builds sheets with no spells and no class features.Model id for this agent
Provider name, e.g. 'Anthropic'
OptionalattachDocuments?: booleanAttach the folder's documentIds (default true)
Prompt folder name, e.g. 'dungeon_master'
Optionaloverrides?: Partial<PromptFolderDefaults>Fields to override the folder's declared defaults;
the same shape, so {agentNickname: 'Homer', controlledByHuman: true} is all
a human-controlled player needs
The created, saved agent
If the folder does not exist. Unlike createAgent, which warns and carries on, this refuses: the whole point of the call is the folder's recipe, and a folder that is not there has none — the agent would come out with no tools, no documents and the shared root prompts
const dm = await appService.createAgentFromFolder({
folder: 'dungeon_master',
aiServiceName: 'Anthropic',
aiModel: 'claude-sonnet-5',
});
const you = await appService.createAgentFromFolder({
folder: 'dnd_player',
aiServiceName: 'Anthropic',
aiModel: 'claude-haiku-4-5',
overrides: { agentNickname: 'Homer', controlledByHuman: true },
});
Creates a new prompt folder in the user prompts directory.
An empty system_instruction.prompt file is created inside the folder so that
it is immediately usable as a prompt source for agents.
Name of the folder to create
OptionalroomLeader: stringOptionalturnMode: RoomTurnModeOptionalmoderator: stringOptionalbeginInstruction: stringOptionalimageModel: stringOptionalillustrationMode: RoomIllustrationModeCreates an agent that belongs to a room and adds it to that room.
This is the only way an agent joins a room. The agent is owned by it: it is left out of listAgents and deleted with the room, so a room is a self-contained cast rather than a set of references to a shared pool.
request.agentName is the bare name. It is stored prefixed with the room's
name, while the nickname is derived from the bare name — otherwise every
agent in the room would be addressed by the room's first word.
The room the agent will belong to
The same fields createAgent takes
Object containing the new agentId
Adds an agent to a room, built from a prompt folder's declared defaults.
The room-scoped counterpart to createAgentFromFolder, and the piece a
pack's room template is instantiated through. Everything a folder already
declares — name, nickname, description, tool grants, documents, cache TTL —
comes from its defaults_config.json, so a template only has to say what
differs.
Routed through createRoomAgent rather than createAgentFromFolder,
which does none of what a room member needs: the stored name is prefixed with
the room's, the nickname is derived from the bare name, ownerRoomId is set,
the moderator requirement is checked, and an agent whose nickname collides is
removed again instead of being left behind belonging to a room it never joined.
The room to add to
The folder to build from, the model to use, and any overrides
Optionaloverrides?: Partial<PromptFolderDefaults>Optionalpack?: stringFiles the new agent under a pack, so it is listed and hidden with it.
OptionalpackAgentKey?: stringThe pack template's key, when this agent came from one.
OptionalsmallModelName?: stringThe new agent's id, its resolved nickname, and any document ids that resolved to nothing — returned rather than swallowed, because a document that silently fails to attach is a capability the agent appears to have and does not
If the room does not exist, or the folder does not. See createAgentFromFolder for why a missing folder is fatal here
Creates a new interactive story with AI-driven characters.
When this method returns, the story is immediately playable: brief character
backgrounds and the opening scene have already been generated. A background job
then generates the detailed plot plan and full character profiles; subscribe to
getStoryProgressEmitter to be notified when that finishes (step === 'complete'),
but there is no need to wait for it before letting the player interact.
Display name for the story
Brief premise or concept for the story
Description of the character the human player will portray
Description of other prominent characters to generate
OptionalstoryModel: string
Model identifier from story_models.json (e.g. 'claude-haiku-4-5'). Defaults to the configured default.
OptionalisImport: boolean
Set true when reconstructing a story from exported data. Default false.
OptionalimageModelName: string
Optional image model name from image_models.json (supplies both the generation and editing models)
OptionalskipDetailedPlot: boolean
Set true to generate a simple plot scenario instead of a detailed plot plan with secrets, twists, and events. Default false.
Story metadata including the new id - story is ready to play immediately
// Story is playable as soon as createStory returns
const story = await appService.createStory(
'The Lost Kingdom',
'A medieval fantasy adventure',
'A young knight seeking redemption',
'A wise wizard and a cunning rogue',
);
// Optionally listen for background completion (plot plan + detailed profiles)
const emitter = appService.getStoryProgressEmitter(story.id);
emitter?.on('progress', ({ step, message }) => {
if (step === 'complete') console.log('Background setup finished');
});
Creates a new user-authored tool.
The tool definition to create
The created tool definition
Creates a new named artifact and returns its ID.
The artifact is persisted immediately. Use the returned ID to attach it to agents (attachArtifactToAgent) or reference it in room messages.
Human-readable display name for the artifact
Initial text content (typically Markdown)
The new artifact's ID
Records that the player declined a narrator-suggested character introduction.
Prevents the narrator from suggesting the same character again in this story.
The story's ID
The character name that was declined
Removes a file from an agent by its file name.
Deletes the file from storage and updates the agent's metadata. Use deleteAttachedFileById if you have the document ID instead.
The agent's ID
Name of the file to remove (e.g. 'report.pdf')
Removes an attached file by its document ID (as returned by attachDocument).
Searches all agents to locate the owner, removes the file from storage, and updates the agent's metadata.
The documentId returned by attachDocument
Removes a character's agent from the story while preserving their profile file.
The character can be reintroduced later via introduceCharacterToStory and their profile will be available.
The story's ID
The character's name
Removes the newest message from an agent's conversation.
Returns the conversation as it now stands rather than nothing, because the caller is a button somebody clicks repeatedly: a second round trip for the new transcript would show the list lagging a click behind on a slow connection.
The agent whose history to shorten
The remaining messages and the agent's running totals
Deletes a prompt file from the user prompts directory.
Removes both the .prompt and .json variants if they exist.
This is a no-op if neither file is present.
Prompt folder name, or 'shared' for the root prompts directory
Base name of the file to delete (without extension)
Deletes a prompt folder and all its contents from the user prompts directory.
Only user-owned folders can be deleted; common folders are not affected.
Name of the folder to delete
Permanently deletes a room and all its data.
If the room is a template, all of its published instances are deleted first. The agents the room owns, its attached files and its published room mapping are also cleaned up.
The room's ID
Permanently deletes a story, its room, all characters, chapters, and artifacts.
The story's ID
Permanently deletes a user artifact.
Any agents that have the artifact attached will lose access to it after deletion.
The artifact's ID (from listUserArtifacts)
true on success, false if no artifact with that ID exists
Removes an artifact attachment from an agent.
The artifact itself is not deleted - only the link between the agent and the artifact
is removed. Changes are persisted immediately via agent.save().
The agent's ID
The artifact's ID to detach
Generates the full story as a single markdown document.
Combines all chapters and room messages in narrative order.
The story's ID
The complete story formatted as markdown text
Updates the name, goal, and/or agent membership of an existing room.
Published room instances cannot be edited - edit the template instead.
The room's ID
New display name
New goal description
OptionalbaseRoomDir: string
Optional override for the room's base storage directory
OptionalagentIds: string[]
Replacement list of agent IDs (replaces current membership entirely). Omit to leave membership unchanged, which is what the client does: membership is managed through createRoomAgent and removeRoomAgent, not by re-sending the roster with every rename.
OptionalroomLeader: string
Nickname (or name) of the member agent to lead the room. Omit to leave the current leader unchanged.
OptionalturnMode: RoomTurnMode
How the room chooses who responds. Omit to leave unchanged. See RoomTurnMode.
Optionalmoderator: string
Nickname of the moderator agent. Omit to leave unchanged.
Optionalpack: string
The pack to file the room under. Empty string clears it.
OptionalbeginInstruction: string
What beginRoom sends to the leader. Empty string clears it, which withdraws the room's Begin. Omit to leave unchanged.
OptionalimageModel: stringOptionalillustrationMode: RoomIllustrationModeReadonlyenabledThe packs this user has enabled, as a thunk.
Handed to the prompt resolver and to every agent this service creates. A thunk rather than an array because both outlive a toggle — see Agent.enabledPacks.
Ensures the real-time state callback is registered for an agent.
Normally called automatically by processText and getAgentMessages. Call this explicitly when connecting a new SSE client to an agent that was loaded from disk (not yet touched in this session).
The agent's ID
Ensures the real-time state callback is registered for a room.
Normally called automatically. Call this explicitly when connecting a new SSE client to a room that was loaded from disk (not yet touched in this session).
The room's ID
Exports the complete story data as a downloadable zip archive.
The archive can be re-imported via importStoryFromZip.
The story's ID
Object with a stream (readable zip stream) and filename for the download
Returns detailed metadata for a specific agent.
The agent's ID
Agent metadata object, or null if no agent with the given ID exists
Returns the formatted conversation history for a specific character in a story.
The story's ID
The character agent's ID
Object with content containing the formatted history text
Returns a Node.js EventEmitter that fires whenever this agent's state changes
(new message, token count update, etc.).
Useful for building real-time UIs. Subscribe to the 'update' event to receive
agent state payloads without polling.
The agent's ID
EventEmitter that emits 'update' events with agent state payloads
Returns an agent's conversation history starting from a given index.
Pass the messageIndex from a previous response as fromIndex to
retrieve only new messages since the last poll.
The agent's ID
Zero-based index to start from (default 0 returns all messages)
Object with the messages array and cumulative token/cost totals. Returns empty messages with zero counts if the agent is not found.
Returns the names of all available AI service providers.
Only providers that have a configured API key are included.
Array of provider names (e.g. 'Anthropic', 'OpenAI', 'GoogleAI')
Returns the user's current credit balance in dollars.
The balance is decremented automatically after each AI call based on token usage
and any configured markup. Calls that would exceed the balance throw
InsufficientBalanceError before the request is sent.
Current balance in dollars
Returns a Node.js EventEmitter that fires whenever the user's balance changes.
Subscribe to the 'update' event to push real-time balance updates to a connected
client (e.g. via SSE) without polling.
The user's ID (typically the same ID used with getAppService)
EventEmitter that emits 'update' events with the new balance value
Returns the messages from a specific chapter checkpoint.
The story's ID
The chapter number (1-based, as returned by listChapters)
Array of room messages from that chapter
Returns the profile for a specific character.
The story's ID
The character's name
Object with content containing the character profile markdown
Returns the inventory for a specific character.
The story's ID
The character's name
Object with content containing the inventory markdown
Returns the story's plot plan.
The plot plan is a room artifact generated by the narrator at story creation and updated as the story progresses.
The story's ID
Object with content containing the plot plan markdown
Reads a prompt file, applying the shared lookup order (prompt-resolver.ts).
For a bare folder that is the historical four levels — user/{folder},
user/root, common/{folder}, common/root — plus the folders of any pack
this user has enabled. For a pack-qualified folder (dnd5e:battle_master) it
is the pack's own tiers, then the shared roots.
The returned scope collapses the four tiers onto the two the client knows:
a pack overlay reports 'user', a pack's own file reports 'common'. pack
and tier carry the detail, and are populated even when the reference was
bare. Returns { content: '' } if the file does not exist in any location.
Prompt folder name, 'shared' for the root prompts directory,
or a pack-qualified name like dnd5e:dungeon_master
Base name of the prompt file (with or without .prompt/.json extension)
{ content, scope, pack, tier } where all but content are omitted when not found
Reads a prompt folder's defaults_config.json — the agent settings the create-agent
form pre-fills when that folder is chosen.
Resolved through the same 4-level fallback as any other prompt file, so a user copy overrides the shipped one and a file at the prompts root supplies defaults for every folder that has none of its own.
A missing file and an unparseable one both return { defaults: {} }: defaults are a
convenience, and a folder must stay usable when its config is broken. Unparseable is
logged; missing is not, since most folders have no config at all.
Every field is coerced to its declared type and unknown keys are dropped, so a typo in a hand-edited file cannot ride through to the create-agent request.
Prompt folder name, or 'shared' for the root prompts directory
The declared defaults, and the scope the file was read from
Returns all published instances created from a template agent.
ID of the template agent
Array of agent metadata objects for each published instance
Returns all published instances created from a template room.
ID of the template room
Array of room summary objects for each published instance
Returns a random story idea from a randomly selected genre.
A random StoryIdea object, or null if no genres/ideas are available
Returns a random story idea from the specified genre.
Genre name as returned by listStoryGenres (e.g. 'fantasy')
A random StoryIdea object, or null if the genre file is empty
Returns all artifacts published in a room.
Artifacts are collaborative documents created by agents via the 'publish' action.
The room's ID
Object with an artifacts array. Returns { artifacts: [] } if the room is not found.
Returns the raw Room object for a given ID.
Use getRoomDetails for a plain metadata object. This method exposes
the full Room instance, which is useful for advanced operations.
The room's ID
The Room instance, or null if not found
Returns full details for a room, including the metadata of each member agent.
The room's ID
Room details object, or null if no room with the given ID exists
Returns one of a room's generated images, with the metadata needed to serve
it. Rooms keep their images in their own directory, separate from the
.artifact text files, so this does not go through the artifact store.
The room's ID
The image's ID, as it appears in the message markdown
The bytes and MIME type, or null when there is no such image
Returns a Node.js EventEmitter that fires whenever a new message arrives in the room.
Subscribe to the 'update' event to receive room message payloads in real time
without polling.
The room's ID
EventEmitter that emits 'update' events with room message payloads
Returns messages from a room's conversation log starting from a given index.
Pass the index of the last message you received as fromIndex to poll for
new messages only.
The room's ID
Zero-based index to start from (default 0 returns all messages)
If true, includes 'think' action messages which are
normally hidden (agents' internal reasoning). Default false.
Object with the messages array and total cost across all agents. Returns empty messages with zero cost if the room is not found.
Returns the content of a specific story artifact.
The story's ID
The artifact's ID (from listStoryArtifacts)
The artifact content as a string or Buffer, or null if not found
Returns metadata for a specific story.
The story's ID
Story metadata, or undefined if not found
Returns the EventEmitter for real-time story updates.
The emitter fires four named events. Each payload includes a timestamp field.
'story-state' - StoryStateEvent
Fires after every room turn with the complete updated game state.
emitter.on('story-state', (event: StoryStateEvent) => {
const myTurn = event.state.currentSpeaker === event.state.userAgentName;
});
Use state.currentSpeaker === state.userAgentName to detect the player's turn.
Do not use state.humanPrompt for turn detection - it is a UI display string
(e.g. "What does Elena do next?") present even when it is not the player's turn.
'suggest-introduce-character' - StoryIntroduceCharacterEvent
Fires when the narrator wants to add a new character. The host app should surface
this to the player before acting.
fromNarratorSuggestion: trueemitter.on('suggest-introduce-character', (event: StoryIntroduceCharacterEvent) => {
// event.characterName is the narrator-chosen name
});
'suggest-progress-chapter' - StoryProgressChapterEvent
Fires when the narrator wants to advance to the next chapter. The host app should
surface this to the player before acting.
'story-error' - StoryErrorEvent
Fires when the story engine encounters a fatal error during room processing.
Named 'story-error' rather than 'error' to avoid Node.js throwing an uncaught
exception when no listener is attached to 'error'.
Check event.errorType === 'InsufficientBalanceError' for balance failures.
The story's ID
EventEmitter emitting 'story-state', 'suggest-introduce-character',
'suggest-progress-chapter', and 'story-error' events
Gets messages from a story's room starting from a specific index
The story ID
The index to start from (0-based)
Array of indexed messages and total story cost
Returns the EventEmitter for tracking background story work.
Subscribe to the 'progress' event. Each event payload is
{ step: string, message: string, timestamp: number }.
step values emitted after createStory returns:
The story is already playable when createStory returns. There is no 'ready'
step for story creation - the storyId does not exist until createStory returns,
so the client cannot subscribe to the progress emitter until after that point.
These steps describe the optional background job (plot plan + detailed profiles)
that continues after the method returns:
'start' - background job has begun'profiles' - generating detailed character profiles'portraits' - generating character portrait images (only if an image model is configured)'complete' - background job finished; detailed profiles and plot plan are now available'error' - background job failed; message contains the error textstep values emitted during progressStory:
'ready' fires just before progressStory returns, so the story is playable
as soon as the Promise resolves - no need to separately listen for 'ready'.
The event is emitted for the benefit of SSE clients that want to update their UI
in real time. After 'ready', a background job continues:
'opening-scene' - writing the new chapter's opening scene'chapter-backup' - saving chapter checkpoint data'ready' - chapter ready; fired just before progressStory resolves'profiles' - (background) recreating plot plan and character profiles'complete' - (background) all chapter work done'error' - progression failedThe emitter is removed after the terminal step ('complete', 'ready', or 'error'),
so this method returns undefined once a terminal step has fired.
The story's ID
EventEmitter emitting 'progress' events, or undefined if already complete
Returns the current runtime state of a story.
Includes messages, pending message count, processing status, and story metadata. Useful for restoring UI state after reconnecting.
The story's ID
Full story state object
Retrieves a single transaction by its payment provider ID.
The payment provider ID used when the transaction was recorded
The matching Transaction, or null if not found
Returns paginated transaction history for this user, sorted newest-first.
Maximum number of records to return (default: 50)
Number of records to skip for pagination (default: 0)
Object with a transactions array and a total count
Returns the content of a user artifact.
Text artifacts are returned as string; binary artifacts (e.g. converted PDFs
in intermediate state) may be returned as Buffer.
The artifact's ID (from listUserArtifacts)
The artifact content, or null if no artifact with that ID exists
Returns the user's stored preferences object.
Preferences are application-defined - Briyah stores and returns them as-is.
Returns {} if no preferences have been saved yet.
The preferences object previously written by saveUserPreferences, or an empty object if none exist
Reconstructs a story from a previously exported zip archive.
Raw bytes of the zip file produced by exportStoryData
Story metadata for the newly imported story
Cancels any pending AI turns and forces the human's turn.
Drops the room's pending message queue and pauses processing so the human-controlled agent becomes the current speaker. Any in-flight LLM calls (perceive or moderator) will discard their responses on return.
The story's ID
Adds a new AI character to an existing story.
Creates a character agent and integrates it into the story's room. The character profile is generated by the AI based on the provided description.
When getStoryMessageEmitter fires a 'suggestion' update with
suggestion.type === 'introduce_character', pass suggestion.characterName as
name and set fromNarratorSuggestion: true to accept the suggestion.
To reject it instead, call declineCharacter.
The story's ID
The character's name
Brief description of the character's personality and role
OptionalstoryModel: string
Optional model override from story_models.json
OptionalfromNarratorSuggestion: boolean
Set true when accepting a narrator 'suggestion' update. Default false.
Returns metadata for all artifacts currently attached to an agent.
Attached artifacts are included in the agent's context on every prompt, allowing the agent to reference their content. Use attachArtifactToAgent and detachArtifactFromAgent to manage attachments.
The agent's ID
Array of artifact metadata objects for the agent's attached artifacts
Lists all top-level agents belonging to this user.
Agents that are owned by a room or story are excluded - use getRoomDetails or story methods to access those agents.
Also return the agents owned by a room or story. Only for offering an existing agent as something to copy; the agent list a user manages is the default, unowned one.
Array of agent metadata objects
Fetches available models from the specified AI service provider.
Provider name as returned by getAiServiceNames
Array of model descriptors including name, description, and service
Lists the files currently attached to an agent.
The agent's ID
Object with a files array of file names. Returns { files: [] } if the agent is not found.
Returns all chapter checkpoints for a story.
Chapters are created by progressStory and can be read with getChapter.
The story's ID
Object with a chapters array of chapter info objects
Returns all current characters in a story.
The story's ID
Array of character objects (derived from the story's room agents)
Returns models available for image generation, as configured in
common/config/image_models.json.
Array of model descriptors. Returns an empty array if the config file is missing.
Native tools this user may grant.
Filtered to the packs they have enabled. Two kinds are always listed: a tool
with no group, registered by the host directly rather than by a pack, and a
core tool, which belongs to the engine rather than to a domain and so has
no pack to enable. Filtering core out would hide rename_agent from every
user permanently, since core never appears in anyone's enabled list.
Listing only. ToolExecutionService and Room.buildAvailableTools
deliberately do not filter, so disabling a pack hides its tools from the
pickers without stopping an agent that already holds one from calling it.
Code-free summaries of the grantable native tools
Returns the names of all prompt files in a folder, merged from both the common and user prompt directories.
Pass 'shared' as folderName to list files in the root prompts directory.
Files that exist in both directories appear once in the result.
Folder to list, or 'shared' for the root prompts directory
Object with a files array of base names (no extension), sorted alphabetically
Returns prompt file names in a folder annotated with their origin scope.
When the same file name exists in both the common and user directories,
the user copy wins and the entry is reported as scope: 'user'.
Pass 'shared' as folderName to list files in the root prompts directory.
Folder to list, or 'shared' for the root prompts directory
Object with a files array of { name, scope } entries, sorted alphabetically
Returns every prompt folder name this user can reach.
Covers the common and user prompt directories plus the folders of any pack
the user has enabled, which appear pack-qualified (dnd5e:dungeon_master).
A folder in more than one directory appears once.
Sorted array of folder names
Returns prompt folder names annotated with where they came from.
When the same folder name exists in both the user and common directories the
user copy wins and the entry reports scope: 'user'. A pack's folder is a
separate entry under its qualified name, so a pack shipping a witness
folder does not collide with a witness folder the user wrote.
Pack folders are listed only for enabled packs. That is the difference between listing and resolving: a disabled pack's folder still resolves when an agent names it, it just stops being offered.
Optionalscope: PromptScope
Optional filter: 'common' returns only system-provided folders
(including packs', which are read-only in the same way), 'user' returns only
the user's own folders and their pack overlays, omit to return all
Object with a folders array, sorted by name
Returns all prepared prompt template names available to a specific agent.
Merges prompts from the agent's own prompt folder and the root prompts directory, deduplicating across both. These names can be passed to runPreparedPrompt.
The agent's ID
Array of prompt template names (without file extension)
Lists all published agent instances belonging to this user.
Published agents are clones of template agents that are accessible via the public API (e.g. for end-users to chat with). Agents owned by rooms are excluded from this list.
Array of agent metadata objects for all published instances
Lists every published room instance this user owns.
The room counterpart to listPublishedAgents, and the only view of them that is not filtered by which template they came from — a published room is a live public link, and the point of the list is seeing all of them and what they have cost.
Array of room summary objects, one per published instance
Lists the rooms this user builds and owns.
Published instances are excluded — use getPublishedRoomInstances for those, which is also how the client reaches them.
Array of room summary objects (id, name, goal, agent count)
Returns all artifacts associated with a story.
Story artifacts include the plot plan and any documents published by agents during the narrative.
The story's ID
Array of artifact metadata objects
Returns the available story genre names.
Genres are read from common/story_ideas/ - each .json file corresponds to a genre.
Pass a genre name to getRandomStoryIdeaByGenre to get a story idea.
Array of genre names (e.g. ['fantasy', 'sci-fi', 'mystery'])
Returns models available for story generation, as configured in
common/config/story_models.json.
Array of model descriptors. Returns an empty array if the config file is missing.
Lists user-authored tools (with code). Empty when authoring is disabled.
Array of user-authored tool definitions
Returns metadata for all artifacts owned by this user.
Artifacts are persistent named documents that can be attached to agents
(see attachArtifactToAgent) or shared with rooms via the 'publish' action.
Use getUserArtifact to retrieve the actual content.
Array of artifact metadata objects (ID, name, creation date, etc.)
Pauses message processing in a room.
Pending messages remain in the queue. Call resumeRoom to continue processing.
The room's ID
Sends a text prompt to an agent and returns its response.
The exchange is added to the agent's conversation history and persisted to disk.
The agent's ID (from createAgent or listAgents)
The prompt text to send
Object containing the agent's reply text (result), the latest formatted
message, its index in the history, and cumulative token counts and cost
Advances the story to the next chapter.
Creates a checkpoint of the current chapter state and rebuilds the opening scene.
The story is immediately playable when this Promise resolves - the 'ready'
progress event fires just before the function returns, so awaiting this call is
sufficient; there is no need to separately wait for the event.
After the function returns, a background job recreates the plot plan and character
profiles for the new chapter ('profiles' --> 'complete'). Agent
conversation histories are not compacted here - each agent compacts
independently on demand when it individually reaches the compaction threshold
(see compactStory for manual compaction).
The story's ID
Object with the new chapterIndex
Whether a prompt folder reference reaches a folder that exists.
The check every "build an agent from a folder" path makes before it builds one: a reference that reaches nothing does not fail, it falls back to the shared root prompts and produces a generic conversational agent. A bare name for a pack this user has not enabled counts as not existing, because that is how it will behave.
Prompt folder name, bare or pack:folder
True when the folder exists, or names the prompts root
Creates a publicly accessible clone of a template agent.
The new instance is independent of the template's conversation history. Multiple instances can be created from a single template. Use resetPublishedInstance to restore an instance to the template's current state.
ID of the template agent to clone
Display name for the new instance
Object with the new instanceId and the publicUrl path
Programmatically publishes an artifact to a room.
This is the imperative equivalent of an agent sending a 'publish' action message.
Agents in the room can read and reference the artifact in subsequent prompts.
The room's ID
Artifact name (unique within the room)
Display name of the creator
The artifact's text content
Agent names that can view this artifact (empty array = all agents)
Creates a publicly accessible clone of a template room.
The instance is a full copy of the template including all agents. Use resetPublishedRoomInstance to restore it to the template's state.
ID of the template room to clone
Display name for the instance (defaults to the template's name)
The owning user's ID (used for public access mapping)
The new instance's room ID
Records a new payment transaction.
Call this when your payment provider confirms a payment has been initiated.
The paymentId should be the unique identifier issued by your payment provider
(e.g. a Stripe Payment Intent ID). Use updateTransactionStatus to update
the status once the provider confirms success or failure.
Dollar amount of the transaction
Unique payment identifier from your payment provider
Initial status; defaults to 'pending'
The created Transaction record
Clears an agent's conversation history while preserving its configuration and re-attaching any previously uploaded files.
Useful for starting a fresh conversation without recreating the agent. If the history begins with a summary block (from a prior compaction), only messages after the summary are cleared.
The agent's ID
Removes an agent from a room, and deletes it if the room owns it.
The room's ID
The agent's ID
Changes the display name of an artifact.
The artifact's ID (from listUserArtifacts)
New display name for the artifact
true on success, false if no artifact with that ID exists
Resets a published agent instance to its template's current state.
Clears the instance's conversation history and regenerates it from the template agent. Does not affect the template itself.
ID of the published instance to reset
Resets a published room instance to a clean state.
Clears the instance's messages and artifacts, and resets all of its cloned agents to their template state. Does not affect the template room.
ID of the published room instance to reset
Resets a story to the beginning while preserving artifacts and the opening scene.
If a chapter 1 backup exists, agents are restored from it; otherwise their conversation histories are cleared. The list of declined characters is also cleared.
The story's ID
Submits the human player's response to the story.
Adds the content as a player message and triggers the AI characters to continue the narrative.
Pass the literal string 'PASS' (case-insensitive) to skip the player's
turn and let the AI characters continue without player input.
The story's ID
The player's message or action, or 'PASS' to skip the turn
Resumes any stories that were paused due to insufficient balance.
Call this after adding balance via addBalance to allow stories that stalled mid-processing to continue from where they left off.
The number of stories that were resumed
Reverts the most recent chapter progression for a story. Restores room messages, artifacts, and agent histories from the previous chapter backup, then deletes that backup. Only valid when the current chapter has not been played past the opening scene.
The story's ID
Executes a named Handlebars prompt template against an agent.
The template is loaded from the agent's prompt folder (with the standard 4-level
fallback). variables are substituted into the template before sending.
The agent's ID
Template name returned by listPrompts (without extension)
Key-value pairs substituted into the template's {{variable}} placeholders
Object with a result string containing the agent's response
Saves a character's profile markdown.
The story's ID
The character's name
Markdown content for the character profile
Saves a character's inventory markdown.
The story's ID
The character's name
Markdown content for the character inventory
Saves the story's plot plan.
Persists the content as a room artifact via the publish mechanism.
The story's ID
The plot plan markdown to save
Writes content to a prompt file in the user prompt directory.
Always saves to the user directory - common prompt files are never overwritten.
If the target folder does not exist it is created automatically.
Passing 'shared' as folderName writes to the root user prompts directory.
Special case: passing an empty content for a 'json' file deletes the file
rather than writing an empty document.
Prompt folder name, or 'shared' for the root user prompts directory
Base name of the file (without extension)
File content to write
'prompt' (writes a .prompt file) or 'json' (writes a .json file)
Persists the user's preferences object to disk.
The shape of preferences is application-defined. Pass any serializable object;
it will be stored as JSON and returned verbatim by getUserPreferences.
Serializable preferences object to store
Adds a message to a room's pending queue to be processed by the agents.
Action values:
'moderate' (default) - routes the message through the room's moderator (story rooms only)'speak' - all agents hear the message; targets (if provided) restricts which agents may respond'whisper' - only agents listed in targets hear the message'think' - inaudible; stays only in the sender's history, not shown to other agents'shout' - overrides all other conversations; all agents hear and respond'adjourn' - signals intent to halt the conversation; the room adjourns once every agent agreesAnything else is sent as 'speak'. To create an artifact use publishArtifact
rather than this method.
The room's ID
The message text (or artifact body when action is 'publish')
Display name of the sender (e.g. 'User', 'System')
Message action type (default 'moderate')
Agent names to receive or respond to the message (behavior varies by action)
If true, clears any pending messages before adding this one. Default false.
Optionalcontext: unknownWhether the message was accepted. A human agent's message is rejected
(accepted: false with a reason) when it is not the human's turn to speak.
// Broadcast a message that all agents can respond to
await appService.sendRoomMessage(roomId, 'Hello everyone!', 'User', 'speak');
// Whisper to a specific agent
const result = await appService.sendRoomMessage(roomId, 'Just between us...', 'User', 'whisper', ['James']);
if (!result.accepted) {
console.log(result.reason); // e.g. "It is James's turn to speak"
}
Supplies the service that builds agents and rooms from pack templates.
Set after construction rather than injected: it drives this service, so it cannot also be one of its constructor arguments.
Sets which agent leads the room's conversation and persists the change.
The room leader is given conversational authority in the default room prompts (other agents defer to it) and is consulted on adjournment.
The room's ID
Nickname of the member agent to make leader
Supplies the service that builds and reads campaigns.
Set after construction for the same reason pack instantiation is: it drives this service, so it cannot also be one of its constructor arguments.
Runs a tool with the given arguments for testing from the Tools page.
Failures are returned in-band as { ok: false, error }.
The tool's name
Named arguments for the tool
The tool run result
Updates one or more properties of an existing agent and persists the changes.
Only fields that are present in the updates object are changed;
omitted fields are left as-is.
The agent's ID
Fields to update:
agentNickname - short display namedescription - role or personality descriptionmodelName - model identifier (e.g. 'claude-haiku-4-5')reasoningEffort - 'low' | 'medium' | 'high' | nullisControlledByHuman - whether a human drives this agent's responsesmaxOutputTokens - override the model's default output token limitallowSearch - enable web search capability (provider must support it)beginInstruction - prompt sent when the host app triggers a "Begin" actionUpdates an existing user-authored tool.
The tool's name
The updated tool definition
The saved tool definition
Updates the status of an existing transaction.
Call this when your payment provider webhook confirms the final outcome of a payment.
The payment provider ID used when the transaction was recorded
New status ('succeeded', 'failed', or 'cancelled')
Replaces the content of an existing artifact.
The artifact's ID (from listUserArtifacts)
New content to write
true on success, false if no artifact with that ID exists
Builds agents and rooms from pack templates.