briyah 2.0.4 → 2.0.5
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.
- package/README.md +12 -1
- package/data/common/config/markup +1 -1
- package/data/common/config/story_models.json +3 -3
- package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
- package/data/common/prompts/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/rooms/campaign.json +18 -15
- package/data/packs/dnd5e/rooms/table.json +17 -16
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +60 -16
- package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
- package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/fal.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/openai.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/together.service.js +1 -1
- package/dist-sdk/server/src/ai/agent-config.d.ts +0 -1
- package/dist-sdk/server/src/ai/agent-store.service.js +2 -4
- package/dist-sdk/server/src/ai/agent.d.ts +1 -2
- package/dist-sdk/server/src/ai/agent.js +1 -3
- package/dist-sdk/server/src/app/user-service-factory.js +8 -2
- package/dist-sdk/server/src/app.controller.d.ts +33 -0
- package/dist-sdk/server/src/app.controller.js +93 -2
- package/dist-sdk/server/src/app.service.d.ts +49 -4
- package/dist-sdk/server/src/app.service.js +101 -16
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +26 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +5 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +14 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +11 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +58 -1
- package/dist-sdk/server/src/room/room-config.js +19 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +8 -0
- package/dist-sdk/server/src/room/room-factory.js +11 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +8 -0
- package/dist-sdk/server/src/room/room-store.service.js +43 -2
- package/dist-sdk/server/src/room/room.d.ts +103 -1
- package/dist-sdk/server/src/room/room.js +240 -4
- package/dist-sdk/server/src/rpg/rpg.service.js +5 -1
- package/dist-sdk/server/src/story/story.service.d.ts +24 -65
- package/dist-sdk/server/src/story/story.service.js +105 -458
- package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
- package/dist-sdk/server/src/tools/core/index.js +2 -1
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +90 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +9 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +30 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +75 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +11 -2
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +36 -5
- package/dist-sdk/server/src/tools/tool-execution.service.js +91 -21
- package/dist-sdk/shared/types/app.types.d.ts +43 -0
- package/dist-sdk/shared/types/app.types.js +15 -1
- package/package.json +1 -1
|
@@ -179,6 +179,22 @@ class Room {
|
|
|
179
179
|
pack;
|
|
180
180
|
/** The pack template's key, when this room came from one. */
|
|
181
181
|
packRoomKey;
|
|
182
|
+
/** What Begin sends to the leader. See {@link RoomConfig.beginInstruction}. */
|
|
183
|
+
beginInstruction = '';
|
|
184
|
+
/** Which image_models.json entry draws this room. See {@link RoomConfig.imageModel}. */
|
|
185
|
+
imageModel;
|
|
186
|
+
/** When the room illustrates itself. See {@link RoomConfig.illustrationMode}. */
|
|
187
|
+
illustrationMode = 'on-request';
|
|
188
|
+
/**
|
|
189
|
+
* Agents that work for this room but never take a turn in it: the illustrator
|
|
190
|
+
* and the two artists.
|
|
191
|
+
*
|
|
192
|
+
* Kept out of `agents` deliberately. In broadcast turn mode `selectResponders`
|
|
193
|
+
* returns every agent in the room, so a member illustrator would be prompted
|
|
194
|
+
* on every message. They are here only so their spend is counted — see
|
|
195
|
+
* {@link totalCost}.
|
|
196
|
+
*/
|
|
197
|
+
attachedAgents = [];
|
|
182
198
|
// Persistence
|
|
183
199
|
storageDir;
|
|
184
200
|
roomStoreService; // Reference to RoomStoreService for self-persistence
|
|
@@ -188,6 +204,17 @@ class Room {
|
|
|
188
204
|
// Opaque, host-supplied context for the current interaction, threaded to any
|
|
189
205
|
// tool an agent invokes. In-memory only — never serialized to disk.
|
|
190
206
|
currentToolContext = undefined;
|
|
207
|
+
// Draws this room's pictures. Absent in tests that construct Room directly, and
|
|
208
|
+
// in an SDK host that wired none.
|
|
209
|
+
illustrationService;
|
|
210
|
+
/**
|
|
211
|
+
* Images each agent has asked for during its current turn, keyed by nickname.
|
|
212
|
+
* An image costs real money and takes minutes, so an agent gets one per turn;
|
|
213
|
+
* `runAgentTurn` clears its entry as the turn begins.
|
|
214
|
+
*/
|
|
215
|
+
imagesThisTurn = new Map();
|
|
216
|
+
/** One picture per agent per turn. */
|
|
217
|
+
static IMAGES_PER_TURN = 1;
|
|
191
218
|
constructor(id, name, goal, baseRoomDir = '', storageDir = '', roomStoreService = null) {
|
|
192
219
|
this.name = name;
|
|
193
220
|
this.goal = goal;
|
|
@@ -257,6 +284,66 @@ class Room {
|
|
|
257
284
|
setPackRoomKey(key) {
|
|
258
285
|
this.packRoomKey = key || undefined;
|
|
259
286
|
}
|
|
287
|
+
/** @returns What Begin sends, or '' when this room offers no Begin */
|
|
288
|
+
getBeginInstruction() {
|
|
289
|
+
return this.beginInstruction;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Sets what Begin sends to the room leader.
|
|
293
|
+
*
|
|
294
|
+
* Normalized to '' rather than left undefined, the same way `getModerator()`
|
|
295
|
+
* normalizes: a settings snapshot read from a room that was never given one
|
|
296
|
+
* must equal a snapshot of a room that was given a blank one, or the
|
|
297
|
+
* round-trip through {@link RoomStoreService.applyRoomSettings} is not one.
|
|
298
|
+
* @param instruction The instruction; empty or undefined clears it
|
|
299
|
+
*/
|
|
300
|
+
setBeginInstruction(instruction) {
|
|
301
|
+
this.beginInstruction = instruction?.trim() || '';
|
|
302
|
+
}
|
|
303
|
+
/** @returns The image_models.json entry name, or undefined to use the env default */
|
|
304
|
+
getImageModel() {
|
|
305
|
+
return this.imageModel;
|
|
306
|
+
}
|
|
307
|
+
setImageModel(model) {
|
|
308
|
+
this.imageModel = model?.trim() || undefined;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @returns When this room illustrates itself. Normalized the way
|
|
312
|
+
* `getModerator()` and `getBeginInstruction()` are, so that a snapshot of a
|
|
313
|
+
* room never given one equals a snapshot of a room given the default.
|
|
314
|
+
*/
|
|
315
|
+
getIllustrationMode() {
|
|
316
|
+
return this.illustrationMode;
|
|
317
|
+
}
|
|
318
|
+
setIllustrationMode(mode) {
|
|
319
|
+
this.illustrationMode = mode || 'on-request';
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Registers an agent that works for this room without ever taking a turn.
|
|
323
|
+
* Idempotent, since the illustration service resolves its agents on every call.
|
|
324
|
+
* @param agent The off-roster agent whose spend belongs to this room
|
|
325
|
+
*/
|
|
326
|
+
attachAgent(agent) {
|
|
327
|
+
if (!agent)
|
|
328
|
+
return;
|
|
329
|
+
if (this.attachedAgents.some((a) => a.id === agent.id))
|
|
330
|
+
return;
|
|
331
|
+
this.attachedAgents.push(agent);
|
|
332
|
+
}
|
|
333
|
+
/** @returns The off-roster agents, e.g. for cleanup when the room is deleted */
|
|
334
|
+
getAttachedAgents() {
|
|
335
|
+
return [...this.attachedAgents];
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* What this room has cost so far.
|
|
339
|
+
*
|
|
340
|
+
* The one place that knows the illustrator and artists are not in `agents`.
|
|
341
|
+
* Callers that used to reduce over `getAgents()` must use this instead, or
|
|
342
|
+
* image spend is invisible.
|
|
343
|
+
*/
|
|
344
|
+
totalCost() {
|
|
345
|
+
return [...this.agents, ...this.attachedAgents].reduce((sum, agent) => sum + (agent.totalCost || 0), 0);
|
|
346
|
+
}
|
|
260
347
|
clearRoomMessages() {
|
|
261
348
|
this.roomMessages = [];
|
|
262
349
|
this.roomStoreService.clearRoomMessages(this.id, this.storageDir);
|
|
@@ -1092,7 +1179,7 @@ class Room {
|
|
|
1092
1179
|
tools.push({
|
|
1093
1180
|
name: native.name,
|
|
1094
1181
|
description: native.description,
|
|
1095
|
-
parameters: native.parameters
|
|
1182
|
+
parameters: Room.describeToolParameters(native.parameters),
|
|
1096
1183
|
});
|
|
1097
1184
|
continue;
|
|
1098
1185
|
}
|
|
@@ -1105,12 +1192,23 @@ class Room {
|
|
|
1105
1192
|
tools.push({
|
|
1106
1193
|
name: tool.name,
|
|
1107
1194
|
description: tool.description,
|
|
1108
|
-
parameters: tool.parameters
|
|
1195
|
+
parameters: Room.describeToolParameters(tool.parameters),
|
|
1109
1196
|
});
|
|
1110
1197
|
}
|
|
1111
1198
|
}
|
|
1112
1199
|
return tools;
|
|
1113
1200
|
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Prepares declared parameters for the perceive prompt, pre-joining any
|
|
1203
|
+
* `enum` so the template can render it. See {@link PromptToolParameter}.
|
|
1204
|
+
* @param parameters The tool's declared parameters
|
|
1205
|
+
* @returns The parameters, each with `enumText` when it declares an enum
|
|
1206
|
+
*/
|
|
1207
|
+
static describeToolParameters(parameters) {
|
|
1208
|
+
return (parameters || []).map((param) => param.enum && param.enum.length > 0
|
|
1209
|
+
? { ...param, enumText: param.enum.join(', ') }
|
|
1210
|
+
: param);
|
|
1211
|
+
}
|
|
1114
1212
|
/**
|
|
1115
1213
|
* Renders an artifact for a prompt, dropping any ```briyah-state fenced
|
|
1116
1214
|
* block.
|
|
@@ -1307,6 +1405,9 @@ class Room {
|
|
|
1307
1405
|
* paused/adjourned mid-turn
|
|
1308
1406
|
*/
|
|
1309
1407
|
async runAgentTurn(agent, heardMessage, opts = {}) {
|
|
1408
|
+
// A turn is the unit the image cap is measured in, and it spans the whole
|
|
1409
|
+
// EXECUTE/PUBLISH chain below — so it resets here rather than per prompt.
|
|
1410
|
+
this.imagesThisTurn.delete(agent.agentNickname);
|
|
1310
1411
|
const variables = await this.buildPerceiveVariables(agent);
|
|
1311
1412
|
let response = await this.promptAgentOnce(agent, this.buildTransientPrompt(agent, heardMessage), variables);
|
|
1312
1413
|
const maxIterations = Room.maxToolIterations();
|
|
@@ -1363,7 +1464,15 @@ class Room {
|
|
|
1363
1464
|
}
|
|
1364
1465
|
if (response.action === app_types_1.MessageAction.EXECUTE ||
|
|
1365
1466
|
response.action === app_types_1.MessageAction.PUBLISH) {
|
|
1366
|
-
|
|
1467
|
+
// A THINK is logged and goes no further — queueAgentResponse drops it, and
|
|
1468
|
+
// getLatestRoomMessages filters it out — so coercing to one ended the turn
|
|
1469
|
+
// with nothing for the person waiting: the host sees a stalled "working"
|
|
1470
|
+
// and no message ever arrives. Say what happened in the room, and let the
|
|
1471
|
+
// agent's own words through as speech so the turn is not silent.
|
|
1472
|
+
this.addRoomMessage(new message_1.RoomMessage('System', app_types_1.MessageAction.SYSTEM, response.action === app_types_1.MessageAction.EXECUTE
|
|
1473
|
+
? `${agent.agentNickname} reached the tool-call limit for this turn; "${response.name}" was not run.`
|
|
1474
|
+
: `${agent.agentNickname} reached the tool-call limit for this turn.`, [], null, null));
|
|
1475
|
+
response = new message_1.RoomMessage(agent.agentNickname, app_types_1.MessageAction.SPEAK, response.content, []);
|
|
1367
1476
|
}
|
|
1368
1477
|
return response;
|
|
1369
1478
|
}
|
|
@@ -1378,7 +1487,7 @@ class Room {
|
|
|
1378
1487
|
async executeToolForAgent(agent, message) {
|
|
1379
1488
|
const toolName = message.name;
|
|
1380
1489
|
const result = this.toolExecutionService
|
|
1381
|
-
? await this.toolExecutionService.runForAgent(toolName, message.content, agent.toolNames || [], this.currentToolContext, this.buildToolRoomAccess(agent))
|
|
1490
|
+
? await this.toolExecutionService.runForAgent(toolName, message.content, agent.toolNames || [], this.currentToolContext, this.buildToolRoomAccess(agent), this.buildToolIllustration(agent))
|
|
1382
1491
|
: { ok: false, error: 'Tool execution is not available in this room' };
|
|
1383
1492
|
const argsPreview = Room.previewForToolLog(message.content || '', Room.TOOL_LOG_ARGS_PREVIEW);
|
|
1384
1493
|
const statusText = 'error' in result ? `error: ${result.error}` : Room.describeToolResult(result.result);
|
|
@@ -1888,6 +1997,90 @@ Recent Message: ${message.getContent()}
|
|
|
1888
1997
|
this.toolStoreService = toolStore;
|
|
1889
1998
|
this.toolExecutionService = toolExecution;
|
|
1890
1999
|
}
|
|
2000
|
+
/**
|
|
2001
|
+
* @internal Injects the shared illustration pipeline. Called wherever
|
|
2002
|
+
* {@link setToolServices} is; SDK consumers never call this directly.
|
|
2003
|
+
*/
|
|
2004
|
+
setIllustrationService(illustration) {
|
|
2005
|
+
this.illustrationService = illustration;
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Builds the illustration capability a tool sees, for one calling agent.
|
|
2009
|
+
*
|
|
2010
|
+
* A closure rather than a class holding a Room, for the reason
|
|
2011
|
+
* {@link buildToolRoomAccess} is: `ToolIllustration` is part of the tool-facing
|
|
2012
|
+
* contract, and importing Room into it would drag the room graph into the SDK's
|
|
2013
|
+
* public types.
|
|
2014
|
+
*
|
|
2015
|
+
* `request` returns the moment the work is queued. Drawing takes minutes and a
|
|
2016
|
+
* tool call has at most 120 seconds, so waiting would guarantee a timeout; the
|
|
2017
|
+
* finished picture arrives as its own message instead.
|
|
2018
|
+
*/
|
|
2019
|
+
buildToolIllustration(agent) {
|
|
2020
|
+
const illustration = this.illustrationService;
|
|
2021
|
+
if (!illustration)
|
|
2022
|
+
return undefined;
|
|
2023
|
+
const nickname = agent.agentNickname;
|
|
2024
|
+
const target = illustration.targetFor(this);
|
|
2025
|
+
const mode = this.getIllustrationMode();
|
|
2026
|
+
const available = mode !== 'off' && !!target.imageModelName();
|
|
2027
|
+
const counter = this.imagesThisTurn;
|
|
2028
|
+
return {
|
|
2029
|
+
available,
|
|
2030
|
+
get usedThisTurn() {
|
|
2031
|
+
return counter.get(nickname) ?? 0;
|
|
2032
|
+
},
|
|
2033
|
+
perTurnLimit: Room.IMAGES_PER_TURN,
|
|
2034
|
+
request: (brief, subjects) => {
|
|
2035
|
+
if (!available)
|
|
2036
|
+
return { accepted: false, reason: 'images_disabled' };
|
|
2037
|
+
const used = this.imagesThisTurn.get(nickname) ?? 0;
|
|
2038
|
+
if (used >= Room.IMAGES_PER_TURN) {
|
|
2039
|
+
return { accepted: false, reason: 'turn_limit' };
|
|
2040
|
+
}
|
|
2041
|
+
if (illustration.isBusy(target.key)) {
|
|
2042
|
+
return { accepted: false, reason: 'in_flight' };
|
|
2043
|
+
}
|
|
2044
|
+
// Counted on acceptance, not on completion: the point is to stop an
|
|
2045
|
+
// agent asking repeatedly within one turn, and the answer will not
|
|
2046
|
+
// arrive before the turn ends.
|
|
2047
|
+
this.imagesThisTurn.set(nickname, used + 1);
|
|
2048
|
+
void illustration
|
|
2049
|
+
.illustrate(this, target, {
|
|
2050
|
+
situation: this.getSituation() || this.getGoal(),
|
|
2051
|
+
situationTime: this.getSituationTime(),
|
|
2052
|
+
brief,
|
|
2053
|
+
subjects,
|
|
2054
|
+
requestedBy: nickname,
|
|
2055
|
+
sequence: this.roomMessages.length,
|
|
2056
|
+
allowReference: true,
|
|
2057
|
+
})
|
|
2058
|
+
.catch((error) => logger_1.logger.error('Illustration request failed:', error));
|
|
2059
|
+
return { accepted: true };
|
|
2060
|
+
},
|
|
2061
|
+
portrait: (characterName, profile) => {
|
|
2062
|
+
if (!available)
|
|
2063
|
+
return { accepted: false, reason: 'images_disabled' };
|
|
2064
|
+
const used = this.imagesThisTurn.get(nickname) ?? 0;
|
|
2065
|
+
if (used >= Room.IMAGES_PER_TURN) {
|
|
2066
|
+
return { accepted: false, reason: 'turn_limit' };
|
|
2067
|
+
}
|
|
2068
|
+
// Deliberately not gated on `isBusy`: that lock keeps overlapping
|
|
2069
|
+
// scenes from drawing a situation that has already moved on, and a
|
|
2070
|
+
// portrait has no situation. Seating a party would otherwise give a
|
|
2071
|
+
// face to whoever was created first and nobody else.
|
|
2072
|
+
this.imagesThisTurn.set(nickname, used + 1);
|
|
2073
|
+
const ready = illustration
|
|
2074
|
+
.portrait(target, characterName, profile, this)
|
|
2075
|
+
.then((artifactId) => (artifactId ? target.imageUrl(artifactId) : null))
|
|
2076
|
+
.catch((error) => {
|
|
2077
|
+
logger_1.logger.error(`Portrait request for ${characterName} failed:`, error);
|
|
2078
|
+
return null;
|
|
2079
|
+
});
|
|
2080
|
+
return { accepted: true, ready };
|
|
2081
|
+
},
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
1891
2084
|
/**
|
|
1892
2085
|
* Saves messages incrementally to disk
|
|
1893
2086
|
* @param messages The new messages to append
|
|
@@ -2139,12 +2332,55 @@ Recent Message: ${message.getContent()}
|
|
|
2139
2332
|
*/
|
|
2140
2333
|
async handleSituationUpdate(situation, messageBody) {
|
|
2141
2334
|
logger_1.logger.log(`Situation updated: ${situation}`);
|
|
2335
|
+
const previous = this.currentSituation;
|
|
2142
2336
|
this.currentSituation = situation;
|
|
2143
2337
|
// Notify callback if registered. Awaited so callers that need the
|
|
2144
2338
|
// situation fully processed before continuing can rely on it being done.
|
|
2145
2339
|
if (this.onSituationUpdate) {
|
|
2146
2340
|
await this.onSituationUpdate(situation, messageBody);
|
|
2147
2341
|
}
|
|
2342
|
+
// After the callback, deliberately. A story rewrites `currentSituation` in
|
|
2343
|
+
// there — the room is handed the narrator's raw four-tag preamble and the
|
|
2344
|
+
// story replaces it with the parsed text — so reading it any earlier would
|
|
2345
|
+
// send the whole preamble to the illustrator.
|
|
2346
|
+
if (situation !== previous) {
|
|
2347
|
+
this.requestAutomaticIllustration(messageBody);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
/**
|
|
2351
|
+
* Draws the new scene, when the room is set to illustrate itself.
|
|
2352
|
+
*
|
|
2353
|
+
* Only in `auto`. The default is `on-request` for a reason: an agent may be
|
|
2354
|
+
* told to restate the situation on *every* response — the dnd5e Dungeon Master
|
|
2355
|
+
* is — so a room wired the way stories are would buy a picture several times a
|
|
2356
|
+
* turn. Stories are unaffected either way, because StoryService still issues
|
|
2357
|
+
* their illustrations itself, with the chapter and character branches this
|
|
2358
|
+
* cannot see.
|
|
2359
|
+
*
|
|
2360
|
+
* Fire-and-forget: drawing takes minutes and nothing is waiting on it.
|
|
2361
|
+
*/
|
|
2362
|
+
requestAutomaticIllustration(narration) {
|
|
2363
|
+
if (this.illustrationMode !== 'auto')
|
|
2364
|
+
return;
|
|
2365
|
+
const illustration = this.illustrationService;
|
|
2366
|
+
if (!illustration)
|
|
2367
|
+
return;
|
|
2368
|
+
const target = illustration.targetFor(this);
|
|
2369
|
+
if (!target.imageModelName())
|
|
2370
|
+
return;
|
|
2371
|
+
// The service holds the authoritative lock; this only avoids the work of
|
|
2372
|
+
// building a request that would be dropped.
|
|
2373
|
+
if (illustration.isBusy(target.key))
|
|
2374
|
+
return;
|
|
2375
|
+
void illustration
|
|
2376
|
+
.illustrate(this, target, {
|
|
2377
|
+
situation: this.getSituation(),
|
|
2378
|
+
situationTime: this.getSituationTime(),
|
|
2379
|
+
narration,
|
|
2380
|
+
sequence: this.roomMessages.length,
|
|
2381
|
+
allowReference: true,
|
|
2382
|
+
})
|
|
2383
|
+
.catch((error) => logger_1.logger.error('Automatic illustration failed:', error));
|
|
2148
2384
|
}
|
|
2149
2385
|
handlePublishMessages(messages) {
|
|
2150
2386
|
for (const message of messages) {
|
|
@@ -99,7 +99,11 @@ class RpgService {
|
|
|
99
99
|
agentNickname: seat.seatName.replace(/\s+/g, ''),
|
|
100
100
|
description: `${seat.seatName}, a player at the table. Renamed to their character once their sheet is built.`,
|
|
101
101
|
controlledByHuman: seat.isHuman,
|
|
102
|
-
|
|
102
|
+
// AI players only. A person at the table keeps the action and
|
|
103
|
+
// target pickers, so they can whisper to another player or
|
|
104
|
+
// address the DM directly rather than having the moderator
|
|
105
|
+
// decide both from their text.
|
|
106
|
+
useModerator: !seat.isHuman,
|
|
103
107
|
...(seat.isHuman ? {} : { privateContext: seat.personality }),
|
|
104
108
|
},
|
|
105
109
|
pack: rpg_roster_1.RPG_PACK,
|
|
@@ -10,6 +10,7 @@ import { StoryInfo, StoryState, Character } from '../../../shared/types/app.type
|
|
|
10
10
|
import { UserPathsService } from '../config/user-paths.service';
|
|
11
11
|
import { ArtifactService } from '../ai/artifact.service';
|
|
12
12
|
import { Readable } from 'stream';
|
|
13
|
+
import { IllustrationService } from '../room/illustration/illustration.service';
|
|
13
14
|
/**
|
|
14
15
|
* Service handling business logic for stories
|
|
15
16
|
* Works alongside StoryStoreService which handles persistence
|
|
@@ -23,9 +24,19 @@ export declare class StoryService {
|
|
|
23
24
|
private readonly userPaths;
|
|
24
25
|
private readonly agentFactory;
|
|
25
26
|
private readonly roomFactory;
|
|
27
|
+
private readonly illustration;
|
|
26
28
|
private readonly storyArtifactServices;
|
|
27
29
|
private readonly chaptersInProgress;
|
|
28
|
-
constructor(storyStore: StoryStoreService, agentStore: AgentStoreService, roomStore: RoomStoreService, progressService: StoryProgressService, messageService: StoryMessageService, userPaths: UserPathsService, agentFactory: AgentFactory, roomFactory: RoomFactory);
|
|
30
|
+
constructor(storyStore: StoryStoreService, agentStore: AgentStoreService, roomStore: RoomStoreService, progressService: StoryProgressService, messageService: StoryMessageService, userPaths: UserPathsService, agentFactory: AgentFactory, roomFactory: RoomFactory, illustration: IllustrationService);
|
|
31
|
+
/**
|
|
32
|
+
* Describes a story to the illustration pipeline.
|
|
33
|
+
*
|
|
34
|
+
* The indirection is what keeps existing stories untouched by the extraction:
|
|
35
|
+
* this reports the artifacts directory a story's images are already in and the
|
|
36
|
+
* `/api/stories/...` URL already baked into its saved message bodies, so
|
|
37
|
+
* nothing moves and no stored transcript goes stale.
|
|
38
|
+
*/
|
|
39
|
+
private illustrationTarget;
|
|
29
40
|
/**
|
|
30
41
|
* Gets the progress emitter for a story
|
|
31
42
|
* @param storyId The story ID
|
|
@@ -377,38 +388,6 @@ export declare class StoryService {
|
|
|
377
388
|
* @returns Update result with details for each character
|
|
378
389
|
*/
|
|
379
390
|
private updateCharacterProfiles;
|
|
380
|
-
/**
|
|
381
|
-
* Looks up image model configuration by name for one variant. Each consolidated
|
|
382
|
-
* entry in image_models.json carries a `generation` block (text-to-image) and an
|
|
383
|
-
* `editing` block (image-to-image); this returns the service/model for the
|
|
384
|
-
* requested variant.
|
|
385
|
-
* @param modelName The name from image_models.json
|
|
386
|
-
* @param variant Which model to resolve: 'generation' or 'editing'
|
|
387
|
-
* @returns {service, model} or null if disabled/not found
|
|
388
|
-
*/
|
|
389
|
-
private getImageModelConfig;
|
|
390
|
-
/**
|
|
391
|
-
* Looks up the image generation properties (API params plus centsPerImage)
|
|
392
|
-
* for an agent's model from image_models.json. This is read fresh at call
|
|
393
|
-
* time rather than stored on the Agent — only the modelName is persisted.
|
|
394
|
-
*
|
|
395
|
-
* @param agent The artist or artistEdit agent
|
|
396
|
-
* @returns The merged imageProperties to pass to generateImage/editImage,
|
|
397
|
-
* or an empty object if the model isn't in image_models.json
|
|
398
|
-
*/
|
|
399
|
-
private getImagePropertiesForAgent;
|
|
400
|
-
/**
|
|
401
|
-
* Creates the artist agent for a story
|
|
402
|
-
* The artist agent is persistent and saved to disk for cost tracking
|
|
403
|
-
* @param storyId The story ID
|
|
404
|
-
* @param storyAgentsDir The story agents directory
|
|
405
|
-
* @param storyArtifactService The story artifact service
|
|
406
|
-
* @param imageModelName The consolidated image model name from image_models.json
|
|
407
|
-
* @param nickname The agent nickname ('Artist' or 'Artist (Edit)')
|
|
408
|
-
* @param variant Which model of the entry to use: 'generation' or 'editing'
|
|
409
|
-
* @returns Artist agent
|
|
410
|
-
*/
|
|
411
|
-
private createArtistAgent;
|
|
412
391
|
/**
|
|
413
392
|
* Generates portrait image for a character
|
|
414
393
|
* @param room The story room
|
|
@@ -417,39 +396,7 @@ export declare class StoryService {
|
|
|
417
396
|
* @returns Promise resolving to the artifact ID of the generated image, or null on failure
|
|
418
397
|
*/
|
|
419
398
|
private generateCharacterPortrait;
|
|
420
|
-
/**
|
|
421
|
-
* Generates a portrait for a character by name + profile, without requiring a character agent.
|
|
422
|
-
* Used for both real characters (delegated from generateCharacterPortrait) and for minor
|
|
423
|
-
* characters named by the illustrator that have no agent backing them.
|
|
424
|
-
*
|
|
425
|
-
* @param storyId The story ID
|
|
426
|
-
* @param characterName The character's display name (used for the Portrait - <name> artifact)
|
|
427
|
-
* @param characterProfile A profile or brief description used to author the visual prompt
|
|
428
|
-
* @param promptAgent Agent used to run describe_character. Defaults to the artist when omitted.
|
|
429
|
-
* @returns Artifact ID of the generated portrait, or null on failure
|
|
430
|
-
*/
|
|
431
|
-
private generatePortraitForName;
|
|
432
399
|
private updateCharacterPortrait;
|
|
433
|
-
/**
|
|
434
|
-
* Generates scene illustrations based on narrator messages
|
|
435
|
-
*/
|
|
436
|
-
private generateSceneIllustration;
|
|
437
|
-
/**
|
|
438
|
-
* Ensures every character named by the illustrator has a Portrait artifact before the
|
|
439
|
-
* story image is generated. Names already present in existingPortraitNames are skipped.
|
|
440
|
-
* Unknown names must have a matching entry in newCharacters (providing briefDescription)
|
|
441
|
-
* — otherwise we cannot generate a portrait and the character is dropped from logging
|
|
442
|
-
* (generateStoryImage's existing fallback will then warn and skip them).
|
|
443
|
-
*/
|
|
444
|
-
private ensureMinorCharacterPortraits;
|
|
445
|
-
/**
|
|
446
|
-
* Generates scene reference image (environment only)
|
|
447
|
-
*/
|
|
448
|
-
private generateSceneReference;
|
|
449
|
-
/**
|
|
450
|
-
* Generates story image (scene + characters)
|
|
451
|
-
*/
|
|
452
|
-
private generateStoryImage;
|
|
453
400
|
/**
|
|
454
401
|
* Parses the narrator's preamble into structured fields. Extracts each
|
|
455
402
|
* tag's inner text (first occurrence, case-insensitive); missing tags
|
|
@@ -466,6 +413,13 @@ export declare class StoryService {
|
|
|
466
413
|
* @param preamble The raw preamble text captured by the Room
|
|
467
414
|
*/
|
|
468
415
|
private updateStorySituation;
|
|
416
|
+
/**
|
|
417
|
+
* Asks the shared illustration pipeline for a picture of the story's current
|
|
418
|
+
* scene. The situation is passed in rather than read off the room: the room's
|
|
419
|
+
* copy holds the narrator's raw four-tag preamble, while the story's is the
|
|
420
|
+
* parsed inner text, and the illustrator wants the latter.
|
|
421
|
+
*/
|
|
422
|
+
private illustrateStorySituation;
|
|
469
423
|
/**
|
|
470
424
|
* Generates a complete markdown document of the story
|
|
471
425
|
* Includes metadata, all completed chapters, and current chapter in progress
|
|
@@ -484,6 +438,11 @@ export declare class StoryService {
|
|
|
484
438
|
}>;
|
|
485
439
|
/**
|
|
486
440
|
* Formats room messages as markdown text
|
|
441
|
+
*
|
|
442
|
+
* A message's situation is not printed. It restates where the scene stands,
|
|
443
|
+
* which is useful live and merely repetitive on the page — the narrator sets one
|
|
444
|
+
* often enough that the document filled up with headings.
|
|
445
|
+
*
|
|
487
446
|
* @param messages Array of room messages
|
|
488
447
|
* @returns Formatted markdown string
|
|
489
448
|
*/
|