briyah 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +12 -1
  2. package/data/common/config/markup +1 -1
  3. package/data/common/config/story_models.json +3 -3
  4. package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
  5. package/data/common/prompts/moderate.json +34 -0
  6. package/data/common/prompts/moderate.prompt +136 -0
  7. package/data/common/prompts/perceive.prompt +1 -1
  8. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
  9. package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
  10. package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
  11. package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
  12. package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
  13. package/data/packs/dnd5e/rooms/campaign.json +18 -15
  14. package/data/packs/dnd5e/rooms/table.json +17 -16
  15. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +1 -1
  16. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +38 -0
  17. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +83 -16
  18. package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
  19. package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
  20. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +1 -1
  21. package/dist-sdk/server/src/ai/LLM/fal.service.js +1 -1
  22. package/dist-sdk/server/src/ai/LLM/googleai.service.js +1 -1
  23. package/dist-sdk/server/src/ai/LLM/grok.service.js +1 -1
  24. package/dist-sdk/server/src/ai/LLM/openai.service.js +1 -1
  25. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +1 -1
  26. package/dist-sdk/server/src/ai/LLM/together.service.js +1 -1
  27. package/dist-sdk/server/src/ai/agent-config.d.ts +0 -1
  28. package/dist-sdk/server/src/ai/agent-store.service.js +2 -4
  29. package/dist-sdk/server/src/ai/agent.d.ts +7 -2
  30. package/dist-sdk/server/src/ai/agent.js +11 -3
  31. package/dist-sdk/server/src/app/user-service-factory.js +8 -2
  32. package/dist-sdk/server/src/app.controller.d.ts +33 -0
  33. package/dist-sdk/server/src/app.controller.js +93 -2
  34. package/dist-sdk/server/src/app.service.d.ts +49 -4
  35. package/dist-sdk/server/src/app.service.js +101 -16
  36. package/dist-sdk/server/src/auth/jwt-auth.guard.js +26 -0
  37. package/dist-sdk/server/src/data/data-guide.builder.d.ts +2 -0
  38. package/dist-sdk/server/src/data/data-guide.builder.js +90 -0
  39. package/dist-sdk/server/src/data/data-registry.d.ts +32 -0
  40. package/dist-sdk/server/src/data/data-registry.js +61 -0
  41. package/dist-sdk/server/src/data/data.types.d.ts +158 -0
  42. package/dist-sdk/server/src/data/data.types.js +24 -0
  43. package/dist-sdk/server/src/data/query-validation.d.ts +45 -0
  44. package/dist-sdk/server/src/data/query-validation.js +245 -0
  45. package/dist-sdk/server/src/packs/pack-instantiation.service.js +5 -0
  46. package/dist-sdk/server/src/packs/pack-manifest.d.ts +14 -0
  47. package/dist-sdk/server/src/packs/pack-manifest.js +11 -0
  48. package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
  49. package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
  50. package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
  51. package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
  52. package/dist-sdk/server/src/room/room-config.d.ts +58 -1
  53. package/dist-sdk/server/src/room/room-config.js +19 -0
  54. package/dist-sdk/server/src/room/room-factory.d.ts +8 -0
  55. package/dist-sdk/server/src/room/room-factory.js +11 -0
  56. package/dist-sdk/server/src/room/room-store.service.d.ts +8 -0
  57. package/dist-sdk/server/src/room/room-store.service.js +43 -2
  58. package/dist-sdk/server/src/room/room.d.ts +110 -6
  59. package/dist-sdk/server/src/room/room.js +277 -10
  60. package/dist-sdk/server/src/rpg/rpg.service.js +5 -1
  61. package/dist-sdk/server/src/sdk/index.d.ts +4 -0
  62. package/dist-sdk/server/src/sdk/index.js +11 -1
  63. package/dist-sdk/server/src/story/story.service.d.ts +24 -65
  64. package/dist-sdk/server/src/story/story.service.js +105 -458
  65. package/dist-sdk/server/src/tools/core/data.tools.d.ts +17 -0
  66. package/dist-sdk/server/src/tools/core/data.tools.js +165 -0
  67. package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
  68. package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
  69. package/dist-sdk/server/src/tools/core/index.js +3 -1
  70. package/dist-sdk/server/src/tools/native-tool.types.d.ts +90 -0
  71. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +9 -0
  72. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +5 -0
  73. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +30 -0
  74. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +75 -0
  75. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +11 -2
  76. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +36 -5
  77. package/dist-sdk/server/src/tools/tool-execution.service.js +91 -21
  78. package/dist-sdk/shared/types/app.types.d.ts +43 -0
  79. package/dist-sdk/shared/types/app.types.js +15 -1
  80. package/package.json +1 -1
@@ -0,0 +1,101 @@
1
+ import { Agent } from '../../ai/agent';
2
+ import { ArtifactService } from '../../ai/artifact.service';
3
+ /**
4
+ * The three agents that make a picture. None of them is ever a member of the
5
+ * room they work for: in broadcast turn mode `selectResponders` returns every
6
+ * agent in the room, so a member illustrator would be prompted on every message.
7
+ * They are held by id and driven directly.
8
+ */
9
+ export interface IllustrationAgentIds {
10
+ illustratorAgentId?: string;
11
+ artistAgentId?: string;
12
+ artistEditAgentId?: string;
13
+ }
14
+ /** The resolved trio, with `artistEdit` absent when the model has no editing variant. */
15
+ export interface IllustrationAgents {
16
+ illustrator: Agent;
17
+ artist: Agent;
18
+ artistEdit: Agent | null;
19
+ }
20
+ /**
21
+ * Everything the pipeline needs that differs between a story and a plain room.
22
+ *
23
+ * Deliberately a descriptor of plain accessors rather than a `Room` or a
24
+ * `StoryInfo`: the service must not learn what a story is. Same reasoning as
25
+ * `Room.buildToolRoomAccess`, which is a closure so that the tool-facing contract
26
+ * never drags the room graph into it.
27
+ *
28
+ * This indirection is also what makes the extraction safe for existing stories.
29
+ * A story's target reports the directory its images are already in and the
30
+ * `/api/stories/...` URL already baked into its saved message bodies, so nothing
31
+ * moves and no stored transcript goes stale.
32
+ */
33
+ export interface IllustrationTarget {
34
+ /** storyId or roomId. Used for logging and as the in-flight lock key. */
35
+ readonly key: string;
36
+ /** Agent-name prefix, so the agents read as "<label> - Illustrator". */
37
+ readonly label: string;
38
+ /** Where the three agents persist. */
39
+ readonly agentsDir: string;
40
+ /** Where image bytes live. Story: stories/<id>/artifacts. Room: rooms/<id>/images. */
41
+ readonly artifacts: ArtifactService;
42
+ /** Builds the markdown link for a stored image. */
43
+ imageUrl(artifactId: string): string;
44
+ /** Names the finished image artifact, e.g. `Story image - 7`. */
45
+ imageName(sequence: number): string;
46
+ /** Feeds `describe_character`: a story's scenario, or a room's goal. */
47
+ scenario(): string;
48
+ /**
49
+ * Whether a narrator writes the prose being illustrated.
50
+ *
51
+ * Renders the `{{#if narrator}}` branches of `describe_scene.prompt`. A story
52
+ * has one and its wording is what that prompt was written around; an ordinary
53
+ * room has recent messages and no narration, and being told to read "the most
54
+ * recent narration from the narrator" would send the illustrator looking for
55
+ * something that is not there.
56
+ */
57
+ readonly narrated: boolean;
58
+ /** The chosen entry in image_models.json. Absent, or "No images", disables. */
59
+ imageModelName(): string | undefined;
60
+ /**
61
+ * A text service/model for the illustrator, which writes the image prompt and
62
+ * so must never be the image model — a ComfyUI-backed agent throws on a text
63
+ * prompt. Absent means the caller creates its agents itself, as a story does at
64
+ * creation time; the pipeline then only ever loads them.
65
+ */
66
+ textModel?(): {
67
+ service: string;
68
+ model: string;
69
+ } | null;
70
+ agentIds(): IllustrationAgentIds;
71
+ /**
72
+ * Persists lazily-created agent ids. A story writes them to `StoryInfo`; a room
73
+ * writes a sidecar beside its images and **never** to `RoomConfig`, because
74
+ * `cloneRoomAsPublished` copies every setting verbatim into each published
75
+ * instance and a template must not share one illustrator's history with them.
76
+ */
77
+ saveAgentIds(ids: IllustrationAgentIds): void;
78
+ }
79
+ /** One request for a picture. */
80
+ export interface IllustrationRequest {
81
+ /** The scene to draw. Supplied by the caller, never read off the room — the room's
82
+ * `currentSituation` holds the raw preamble, a story's holds the parsed text. */
83
+ situation: string;
84
+ situationTime?: string;
85
+ /** Recent prose to push into the illustrator's rolling history. */
86
+ narration?: string;
87
+ /** An explicit brief from the `illustrate` tool. Absent on the automatic path. */
88
+ brief?: string;
89
+ /** Who or what the caller asked to be shown, by the names the room uses. */
90
+ subjects?: string[];
91
+ /** Nickname of the agent that asked, for logging and the per-turn cap. */
92
+ requestedBy?: string;
93
+ /** Sequence number for `imageName`. A story passes its turn number. */
94
+ sequence?: number;
95
+ /**
96
+ * False on the second pass of the reference recursion. A brand-new setting is
97
+ * drawn as a character-free reference first, then this method runs again to
98
+ * draw the actual scene on top of it; without the flag that would recurse.
99
+ */
100
+ allowReference?: boolean;
101
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,18 @@
1
- import { RoomTurnMode } from '../../../shared/types/app.types';
1
+ import { RoomIllustrationMode, RoomTurnMode } from '../../../shared/types/app.types';
2
+ /**
3
+ * The image model that will actually draw for a room, or undefined when none will.
4
+ *
5
+ * Collapses the two ways a room ends up drawing nothing — no model configured
6
+ * anywhere, and the {@link NO_IMAGES} sentinel — into the one answer every caller
7
+ * wants. It exists because `"No images"` is a *truthy string*, so the obvious
8
+ * `if (!room.getImageModel())` reads it as a real model: a room explicitly set to
9
+ * draw nothing would accept illustration requests all day and quietly produce
10
+ * nothing, since the sentinel only resolves to null much later, where the artist
11
+ * agent is built.
12
+ *
13
+ * @param chosen The room's `imageModel`, which may be absent
14
+ */
15
+ export declare function resolveRoomImageModel(chosen?: string): string | undefined;
2
16
  /**
3
17
  * Interface for serializable room configuration
4
18
  * Note: Artifacts are now stored as individual .artifact files in the room directory
@@ -29,6 +43,45 @@ export interface RoomConfig {
29
43
  pack?: string;
30
44
  /** The pack template's key, when this room came from one. */
31
45
  packRoomKey?: string;
46
+ /**
47
+ * What a client's Begin button sends into the room.
48
+ *
49
+ * Delivered as a `System` `speak` addressed to the room leader, which takes the
50
+ * first turn. A room is pull-driven — an agent is prompted only when a message
51
+ * arrives — so without this a freshly built room waits for a person to type
52
+ * something before anything happens at all.
53
+ *
54
+ * Absent or blank means the room offers no Begin.
55
+ */
56
+ beginInstruction?: string;
57
+ /**
58
+ * Which entry in `image_models.json` draws this room's pictures.
59
+ *
60
+ * Absent falls back to `DEFAULT_IMAGE_MODEL`; the {@link NO_IMAGES} sentinel
61
+ * disables illustration for this room alone. Read it through
62
+ * {@link resolveRoomImageModel} rather than testing it for truthiness — the
63
+ * sentinel is a non-empty string.
64
+ *
65
+ * A room created through the dialog is explicitly set to the sentinel, so the
66
+ * fallback now only covers rooms made before that and pack templates that name
67
+ * no model of their own.
68
+ *
69
+ * A setting rather than identity, so it is right that a published instance
70
+ * inherits it. The illustrator and artist *agent ids* deliberately live
71
+ * outside `RoomConfig` for the opposite reason — see the sidecar written by
72
+ * `IllustrationService`.
73
+ */
74
+ imageModel?: string;
75
+ /**
76
+ * When the room asks for a picture of its own accord.
77
+ *
78
+ * `on-request` (the default) draws only when an agent calls the `illustrate`
79
+ * tool. `auto` also draws whenever the scene changes, which is how stories
80
+ * have always behaved — but it is opt-in for rooms because a game master that
81
+ * restates the situation on every tool call would otherwise buy an image each
82
+ * time. `off` refuses both.
83
+ */
84
+ illustrationMode?: RoomIllustrationMode;
32
85
  }
33
86
  /**
34
87
  * Every setting a room carries, without its identity or its content.
@@ -43,4 +96,8 @@ export interface RoomConfig {
43
96
  export type RoomSettingsSnapshot = Omit<RoomConfig, 'id' | 'agentIds' | 'messages' | 'createdAt'> & Required<Pick<RoomConfig, 'roomLeader' | 'turnMode'>> & {
44
97
  /** Never undefined here: `Room.getModerator()` normalizes absent to ''. */
45
98
  moderator: string;
99
+ /** Never undefined here either — `Room.setBeginInstruction` normalizes. */
100
+ beginInstruction: string;
101
+ /** Never undefined here: `Room.getIllustrationMode()` normalizes absent to 'on-request'. */
102
+ illustrationMode: RoomIllustrationMode;
46
103
  };
@@ -1,2 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveRoomImageModel = resolveRoomImageModel;
4
+ const app_types_1 = require("../../../shared/types/app.types");
5
+ /**
6
+ * The image model that will actually draw for a room, or undefined when none will.
7
+ *
8
+ * Collapses the two ways a room ends up drawing nothing — no model configured
9
+ * anywhere, and the {@link NO_IMAGES} sentinel — into the one answer every caller
10
+ * wants. It exists because `"No images"` is a *truthy string*, so the obvious
11
+ * `if (!room.getImageModel())` reads it as a real model: a room explicitly set to
12
+ * draw nothing would accept illustration requests all day and quietly produce
13
+ * nothing, since the sentinel only resolves to null much later, where the artist
14
+ * agent is built.
15
+ *
16
+ * @param chosen The room's `imageModel`, which may be absent
17
+ */
18
+ function resolveRoomImageModel(chosen) {
19
+ const model = chosen || process.env.DEFAULT_IMAGE_MODEL;
20
+ return !model || model === app_types_1.NO_IMAGES ? undefined : model;
21
+ }
@@ -2,6 +2,7 @@ import { Room } from './room';
2
2
  import { RoomStoreService } from './room-store.service';
3
3
  import { ToolStoreService } from '../tools/tool-store.service';
4
4
  import { ToolExecutionService } from '../tools/tool-execution.service';
5
+ import { IllustrationService } from './illustration/illustration.service';
5
6
  /**
6
7
  * Factory for creating Room instances
7
8
  * Not a singleton - instantiated per-user by UserServiceFactory
@@ -11,6 +12,13 @@ export declare class RoomFactory {
11
12
  private readonly toolStoreService;
12
13
  private readonly toolExecutionService;
13
14
  constructor(roomStoreService: RoomStoreService, toolStoreService: ToolStoreService, toolExecutionService: ToolExecutionService);
15
+ /**
16
+ * Draws rooms' pictures. Set after construction rather than injected, because
17
+ * IllustrationService is built alongside this factory's own dependencies.
18
+ */
19
+ private illustrationService?;
20
+ /** @internal Wires the illustration pipeline onto every room this factory builds. */
21
+ setIllustrationService(illustration: IllustrationService): void;
14
22
  /**
15
23
  * Creates a room with the specified parameters
16
24
  * @param name The room name
@@ -15,6 +15,15 @@ class RoomFactory {
15
15
  this.toolStoreService = toolStoreService;
16
16
  this.toolExecutionService = toolExecutionService;
17
17
  }
18
+ /**
19
+ * Draws rooms' pictures. Set after construction rather than injected, because
20
+ * IllustrationService is built alongside this factory's own dependencies.
21
+ */
22
+ illustrationService;
23
+ /** @internal Wires the illustration pipeline onto every room this factory builds. */
24
+ setIllustrationService(illustration) {
25
+ this.illustrationService = illustration;
26
+ }
18
27
  /**
19
28
  * Creates a room with the specified parameters
20
29
  * @param name The room name
@@ -29,6 +38,8 @@ class RoomFactory {
29
38
  // Create room with all dependencies
30
39
  const room = new room_1.Room(null, name, goal, baseRoomDir, finalStorageDir, this.roomStoreService);
31
40
  room.setToolServices(this.toolStoreService, this.toolExecutionService);
41
+ if (this.illustrationService)
42
+ room.setIllustrationService(this.illustrationService);
32
43
  return room;
33
44
  }
34
45
  }
@@ -9,6 +9,7 @@ import { ArtifactStoreService } from './artifact-store.service';
9
9
  import { Artifact } from './artifact';
10
10
  import { ToolStoreService } from '../tools/tool-store.service';
11
11
  import { ToolExecutionService } from '../tools/tool-execution.service';
12
+ import { IllustrationService } from './illustration/illustration.service';
12
13
  /**
13
14
  * A service that stores and retrieves Room objects by ID
14
15
  * Each room is stored in its own folder (named by GUID) containing:
@@ -29,12 +30,19 @@ export declare class RoomStoreService {
29
30
  private readonly defaultStorageDir;
30
31
  private loaded;
31
32
  private loadPromise;
33
+ /**
34
+ * Draws rooms' pictures. Set after construction rather than injected, because
35
+ * IllustrationService needs an AgentStore that is built alongside this one.
36
+ */
37
+ private illustrationService?;
32
38
  constructor(userPaths: UserPathsService, agentStore: AgentStoreService, attachedFileService: AttachedFileService, artifactStoreService: ArtifactStoreService, toolStoreService: ToolStoreService, toolExecutionService: ToolExecutionService);
33
39
  /**
34
40
  * Gets the default storage directory for rooms
35
41
  * @returns The default storage directory path
36
42
  */
37
43
  getDefaultStorageDir(): string;
44
+ /** @internal Wires the illustration pipeline onto every room this store builds. */
45
+ setIllustrationService(illustration: IllustrationService): void;
38
46
  /**
39
47
  * Stores a room and returns its unique ID
40
48
  * If the room already has an ID in the store, it updates that entry instead
@@ -76,6 +76,11 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
76
76
  defaultStorageDir;
77
77
  loaded = false;
78
78
  loadPromise = null;
79
+ /**
80
+ * Draws rooms' pictures. Set after construction rather than injected, because
81
+ * IllustrationService needs an AgentStore that is built alongside this one.
82
+ */
83
+ illustrationService;
79
84
  constructor(userPaths, agentStore, attachedFileService, artifactStoreService, toolStoreService, toolExecutionService) {
80
85
  this.userPaths = userPaths;
81
86
  this.agentStore = agentStore;
@@ -94,6 +99,13 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
94
99
  getDefaultStorageDir() {
95
100
  return this.defaultStorageDir;
96
101
  }
102
+ /** @internal Wires the illustration pipeline onto every room this store builds. */
103
+ setIllustrationService(illustration) {
104
+ this.illustrationService = illustration;
105
+ for (const room of this.rooms.values()) {
106
+ room.setIllustrationService(illustration);
107
+ }
108
+ }
97
109
  /**
98
110
  * Stores a room and returns its unique ID
99
111
  * If the room already has an ID in the store, it updates that entry instead
@@ -107,6 +119,8 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
107
119
  room.setStorageDir(finalStorageDir);
108
120
  room.setRoomStoreService(this);
109
121
  room.setToolServices(this.toolStoreService, this.toolExecutionService);
122
+ if (this.illustrationService)
123
+ room.setIllustrationService(this.illustrationService);
110
124
  this.rooms.set(room.getId(), room);
111
125
  this.saveRoomToFile(room, finalStorageDir);
112
126
  return room.getId();
@@ -189,6 +203,8 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
189
203
  // 4. Create new room instance
190
204
  const instance = new room_1.Room(instanceId, publishedName, template.getGoal(), template.getBaseRoomDir(), this.defaultStorageDir, this);
191
205
  instance.setToolServices(this.toolStoreService, this.toolExecutionService);
206
+ if (this.illustrationService)
207
+ instance.setIllustrationService(this.illustrationService);
192
208
  // 5. Add cloned agents to instance
193
209
  for (const agentId of clonedAgentIds) {
194
210
  const agent = await this.agentStore.getAgent(agentId);
@@ -204,7 +220,14 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
204
220
  isPublished: true,
205
221
  templateRoomId: templateId,
206
222
  });
207
- // 7. Store instance
223
+ // 7. Open it for business, as every other path that produces a usable room
224
+ // does. A Room is "processing" until this is called — that is how it refuses
225
+ // work while it is still being assembled — so an instance that skipped it
226
+ // reported itself mid-turn with nothing running, which is a status line that
227
+ // lies to the party and a room that refuses to be begun. After the agents
228
+ // arrive, because it hands the floor to the human player.
229
+ instance.ready();
230
+ // 8. Store instance
208
231
  this.storeRoom(instance);
209
232
  return instanceId;
210
233
  }
@@ -231,6 +254,9 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
231
254
  templateRoomId: room.getTemplateRoomId(),
232
255
  pack: room.getPack(),
233
256
  packRoomKey: room.getPackRoomKey(),
257
+ beginInstruction: room.getBeginInstruction(),
258
+ imageModel: room.getImageModel(),
259
+ illustrationMode: room.getIllustrationMode(),
234
260
  };
235
261
  }
236
262
  /**
@@ -262,6 +288,9 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
262
288
  }
263
289
  room.setPack(settings.pack);
264
290
  room.setPackRoomKey(settings.packRoomKey);
291
+ room.setBeginInstruction(settings.beginInstruction);
292
+ room.setImageModel(settings.imageModel);
293
+ room.setIllustrationMode(settings.illustrationMode);
265
294
  room.setRoomLeader(settings.roomLeader);
266
295
  room.setTurnMode(settings.turnMode);
267
296
  room.setModerator(settings.moderator);
@@ -451,6 +480,8 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
451
480
  // Create a new room with the saved name
452
481
  const room = new room_1.Room(config.id, config.name, config.goal, '', storageDir, this);
453
482
  room.setToolServices(this.toolStoreService, this.toolExecutionService);
483
+ if (this.illustrationService)
484
+ room.setIllustrationService(this.illustrationService);
454
485
  room.setLoading(true);
455
486
  // Set the creation date
456
487
  room.setCreatedAt(new Date(config.createdAt));
@@ -470,6 +501,9 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
470
501
  // Load which pack the room is filed under
471
502
  room.setPack(config.pack);
472
503
  room.setPackRoomKey(config.packRoomKey);
504
+ room.setBeginInstruction(config.beginInstruction);
505
+ room.setImageModel(config.imageModel);
506
+ room.setIllustrationMode(config.illustrationMode);
473
507
  // Add agents to the room (loaded from adjacent agents directory)
474
508
  //
475
509
  // An id that resolves to nothing is a deleted agent the room still
@@ -546,6 +580,9 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
546
580
  templateRoomId: room.getTemplateRoomId(), // NEW: Persist template link
547
581
  pack: room.getPack(),
548
582
  packRoomKey: room.getPackRoomKey(),
583
+ beginInstruction: room.getBeginInstruction(),
584
+ imageModel: room.getImageModel(),
585
+ illustrationMode: room.getIllustrationMode(),
549
586
  };
550
587
  const metadataPath = path.join(roomDir, 'metadata.json');
551
588
  fs.writeFileSync(metadataPath, JSON.stringify(config, null, 2), 'utf-8');
@@ -640,8 +677,12 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
640
677
  try {
641
678
  // Only the agents this room owns. A member it does not own — a story's
642
679
  // shared cast, say — outlives it.
680
+ //
681
+ // Attached agents are included because the illustrator and artists work
682
+ // for the room without ever joining its roster, so iterating members
683
+ // alone would leave them behind with nothing left to reach them by.
643
684
  if (room) {
644
- for (const agent of room.getAgents()) {
685
+ for (const agent of [...room.getAgents(), ...room.getAttachedAgents()]) {
645
686
  if (agent.ownerRoomId !== roomId)
646
687
  continue;
647
688
  try {
@@ -1,9 +1,10 @@
1
1
  import { Agent } from '../ai/agent';
2
- import { RoomTurnMode, SendMessageResult } from '../../../shared/types/app.types';
2
+ import { RoomIllustrationMode, RoomTurnMode, SendMessageResult } from '../../../shared/types/app.types';
3
3
  import { RoomMessage } from './message';
4
4
  import { Artifact } from './artifact';
5
5
  import { ToolStoreService } from '../tools/tool-store.service';
6
6
  import { ToolExecutionService } from '../tools/tool-execution.service';
7
+ import { IllustrationService } from './illustration/illustration.service';
7
8
  /** What a rename did, or why it did nothing. */
8
9
  export interface RenameResult {
9
10
  renamed: boolean;
@@ -150,11 +151,36 @@ export declare class Room {
150
151
  private pack;
151
152
  /** The pack template's key, when this room came from one. */
152
153
  private packRoomKey;
154
+ /** What Begin sends to the leader. See {@link RoomConfig.beginInstruction}. */
155
+ private beginInstruction;
156
+ /** Which image_models.json entry draws this room. See {@link RoomConfig.imageModel}. */
157
+ private imageModel;
158
+ /** When the room illustrates itself. See {@link RoomConfig.illustrationMode}. */
159
+ private illustrationMode;
160
+ /**
161
+ * Agents that work for this room but never take a turn in it: the illustrator
162
+ * and the two artists.
163
+ *
164
+ * Kept out of `agents` deliberately. In broadcast turn mode `selectResponders`
165
+ * returns every agent in the room, so a member illustrator would be prompted
166
+ * on every message. They are here only so their spend is counted — see
167
+ * {@link totalCost}.
168
+ */
169
+ private attachedAgents;
153
170
  private storageDir;
154
171
  private roomStoreService;
155
172
  private toolStoreService?;
156
173
  private toolExecutionService?;
157
174
  private currentToolContext;
175
+ private illustrationService?;
176
+ /**
177
+ * Images each agent has asked for during its current turn, keyed by nickname.
178
+ * An image costs real money and takes minutes, so an agent gets one per turn;
179
+ * `runAgentTurn` clears its entry as the turn begins.
180
+ */
181
+ private imagesThisTurn;
182
+ /** One picture per agent per turn. */
183
+ static readonly IMAGES_PER_TURN = 1;
158
184
  constructor(id: string | null, name: string, goal: string, baseRoomDir?: string, storageDir?: string, roomStoreService?: any);
159
185
  deleteRoom(): void;
160
186
  setLoading(isLoading: boolean): void;
@@ -179,6 +205,44 @@ export declare class Room {
179
205
  /** @returns The pack template's key, when this room came from one */
180
206
  getPackRoomKey(): string | undefined;
181
207
  setPackRoomKey(key: string | undefined): void;
208
+ /** @returns What Begin sends, or '' when this room offers no Begin */
209
+ getBeginInstruction(): string;
210
+ /**
211
+ * Sets what Begin sends to the room leader.
212
+ *
213
+ * Normalized to '' rather than left undefined, the same way `getModerator()`
214
+ * normalizes: a settings snapshot read from a room that was never given one
215
+ * must equal a snapshot of a room that was given a blank one, or the
216
+ * round-trip through {@link RoomStoreService.applyRoomSettings} is not one.
217
+ * @param instruction The instruction; empty or undefined clears it
218
+ */
219
+ setBeginInstruction(instruction: string | undefined): void;
220
+ /** @returns The image_models.json entry name, or undefined to use the env default */
221
+ getImageModel(): string | undefined;
222
+ setImageModel(model: string | undefined): void;
223
+ /**
224
+ * @returns When this room illustrates itself. Normalized the way
225
+ * `getModerator()` and `getBeginInstruction()` are, so that a snapshot of a
226
+ * room never given one equals a snapshot of a room given the default.
227
+ */
228
+ getIllustrationMode(): RoomIllustrationMode;
229
+ setIllustrationMode(mode: RoomIllustrationMode | undefined): void;
230
+ /**
231
+ * Registers an agent that works for this room without ever taking a turn.
232
+ * Idempotent, since the illustration service resolves its agents on every call.
233
+ * @param agent The off-roster agent whose spend belongs to this room
234
+ */
235
+ attachAgent(agent: Agent): void;
236
+ /** @returns The off-roster agents, e.g. for cleanup when the room is deleted */
237
+ getAttachedAgents(): Agent[];
238
+ /**
239
+ * What this room has cost so far.
240
+ *
241
+ * The one place that knows the illustrator and artists are not in `agents`.
242
+ * Callers that used to reduce over `getAgents()` must use this instead, or
243
+ * image spend is invisible.
244
+ */
245
+ totalCost(): number;
182
246
  clearRoomMessages(): void;
183
247
  /**
184
248
  * Adds an agent to the room
@@ -502,6 +566,13 @@ export declare class Room {
502
566
  * @returns Array of tool descriptors (empty when the agent has no usable tools)
503
567
  */
504
568
  private buildAvailableTools;
569
+ /**
570
+ * Prepares declared parameters for the perceive prompt, pre-joining any
571
+ * `enum` so the template can render it. See {@link PromptToolParameter}.
572
+ * @param parameters The tool's declared parameters
573
+ * @returns The parameters, each with `enumText` when it declares an enum
574
+ */
575
+ private static describeToolParameters;
505
576
  /**
506
577
  * Renders an artifact for a prompt, dropping any ```briyah-state fenced
507
578
  * block.
@@ -788,6 +859,24 @@ export declare class Room {
788
859
  * @param toolExecution The user's tool execution service
789
860
  */
790
861
  setToolServices(toolStore: ToolStoreService, toolExecution: ToolExecutionService): void;
862
+ /**
863
+ * @internal Injects the shared illustration pipeline. Called wherever
864
+ * {@link setToolServices} is; SDK consumers never call this directly.
865
+ */
866
+ setIllustrationService(illustration: IllustrationService): void;
867
+ /**
868
+ * Builds the illustration capability a tool sees, for one calling agent.
869
+ *
870
+ * A closure rather than a class holding a Room, for the reason
871
+ * {@link buildToolRoomAccess} is: `ToolIllustration` is part of the tool-facing
872
+ * contract, and importing Room into it would drag the room graph into the SDK's
873
+ * public types.
874
+ *
875
+ * `request` returns the moment the work is queued. Drawing takes minutes and a
876
+ * tool call has at most 120 seconds, so waiting would guarantee a timeout; the
877
+ * finished picture arrives as its own message instead.
878
+ */
879
+ private buildToolIllustration;
791
880
  /**
792
881
  * Saves messages incrementally to disk
793
882
  * @param messages The new messages to append
@@ -891,11 +980,13 @@ export declare class Room {
891
980
  * other room the first agent is whoever happened to be added first and has no
892
981
  * `moderate.prompt` at all. Name one explicitly.
893
982
  *
894
- * The fallback prefers an agent that actually has a `moderate.prompt`, because
895
- * one that does not fails in the worst way available: the prompt lookup throws,
896
- * the throw is swallowed, and the message disappears. Arrival order is only
897
- * consulted when nobody in the room can moderate, which keeps a room that was
898
- * working before this preference existed working now.
983
+ * The fallback prefers an agent whose own folder carries a `moderate.prompt`,
984
+ * because a folder that ships one was written to route for its domain and its
985
+ * examples are drawn from it. It has to ask for the folder's *own* file:
986
+ * `common/prompts/moderate.prompt` is the shared fallback, so every agent can
987
+ * moderate and asking whether one merely resolves the prompt would pick out
988
+ * nobody. Arrival order is consulted only when no folder is purpose-built,
989
+ * which is the ordinary case in a room assembled from generic agents.
899
990
  * @returns The moderator agent or undefined if the room is empty
900
991
  */
901
992
  getModeratorAgent(): Agent | undefined;
@@ -944,6 +1035,19 @@ export declare class Room {
944
1035
  * room yet (it may not be logged at the time the callback fires).
945
1036
  */
946
1037
  private handleSituationUpdate;
1038
+ /**
1039
+ * Draws the new scene, when the room is set to illustrate itself.
1040
+ *
1041
+ * Only in `auto`. The default is `on-request` for a reason: an agent may be
1042
+ * told to restate the situation on *every* response — the dnd5e Dungeon Master
1043
+ * is — so a room wired the way stories are would buy a picture several times a
1044
+ * turn. Stories are unaffected either way, because StoryService still issues
1045
+ * their illustrations itself, with the chapter and character branches this
1046
+ * cannot see.
1047
+ *
1048
+ * Fire-and-forget: drawing takes minutes and nothing is waiting on it.
1049
+ */
1050
+ private requestAutomaticIllustration;
947
1051
  handlePublishMessages(messages: RoomMessage[]): void;
948
1052
  handleAdjournMessages(messages: RoomMessage[]): void;
949
1053
  addPendingMessage(message: RoomMessage, clearQueue?: boolean, context?: unknown): SendMessageResult;