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
|
@@ -857,6 +857,14 @@ let AppController = AppController_1 = class AppController {
|
|
|
857
857
|
}
|
|
858
858
|
return value;
|
|
859
859
|
}
|
|
860
|
+
static parseIllustrationMode(value) {
|
|
861
|
+
if (value === undefined)
|
|
862
|
+
return undefined;
|
|
863
|
+
if (value !== 'off' && value !== 'on-request' && value !== 'auto') {
|
|
864
|
+
throw new common_1.BadRequestException(`illustrationMode must be 'off', 'on-request' or 'auto'`);
|
|
865
|
+
}
|
|
866
|
+
return value;
|
|
867
|
+
}
|
|
860
868
|
async createRoom(req, body) {
|
|
861
869
|
// Validate required fields. A room may start empty: the agents that belong
|
|
862
870
|
// to it are created through POST rooms/:roomId/agents once it exists.
|
|
@@ -872,9 +880,10 @@ let AppController = AppController_1 = class AppController {
|
|
|
872
880
|
throw new common_1.BadRequestException('Room name too long');
|
|
873
881
|
}
|
|
874
882
|
const turnMode = AppController_1.parseTurnMode(body.turnMode);
|
|
883
|
+
const illustrationMode = AppController_1.parseIllustrationMode(body.illustrationMode);
|
|
875
884
|
try {
|
|
876
885
|
const appService = this.getAppService(req);
|
|
877
|
-
return await appService.createRoom(body.roomName, body.roomGoal, body.agentIds ?? [], body.roomLeader, turnMode, body.moderator);
|
|
886
|
+
return await appService.createRoom(body.roomName, body.roomGoal, body.agentIds ?? [], body.roomLeader, turnMode, body.moderator, body.beginInstruction, body.imageModel, illustrationMode);
|
|
878
887
|
}
|
|
879
888
|
catch (error) {
|
|
880
889
|
logger_1.logger.error(`[${req.user?.sub}] Error creating room ${body.roomName}:`, error);
|
|
@@ -886,10 +895,13 @@ let AppController = AppController_1 = class AppController {
|
|
|
886
895
|
}
|
|
887
896
|
}
|
|
888
897
|
async editRoom(req, roomId, body) {
|
|
898
|
+
// Parsed before the try, like turnMode: a rejected value is a bad request,
|
|
899
|
+
// and inside the try the catch below would turn it into a 500.
|
|
889
900
|
const turnMode = AppController_1.parseTurnMode(body.turnMode);
|
|
901
|
+
const illustrationMode = AppController_1.parseIllustrationMode(body.illustrationMode);
|
|
890
902
|
try {
|
|
891
903
|
const appService = this.getAppService(req);
|
|
892
|
-
await appService.editRoom(roomId, body.roomName, body.roomGoal, body.baseRoomDir, body.agentIds, body.roomLeader, turnMode, body.moderator, body.pack);
|
|
904
|
+
await appService.editRoom(roomId, body.roomName, body.roomGoal, body.baseRoomDir, body.agentIds, body.roomLeader, turnMode, body.moderator, body.pack, body.beginInstruction, body.imageModel, illustrationMode);
|
|
893
905
|
}
|
|
894
906
|
catch (error) {
|
|
895
907
|
logger_1.logger.error(`[${req.user?.sub}] Error editing room ${roomId}:`, error);
|
|
@@ -1174,6 +1186,37 @@ let AppController = AppController_1 = class AppController {
|
|
|
1174
1186
|
throw new common_1.HttpException('Failed to send room message', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
1175
1187
|
}
|
|
1176
1188
|
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Opens a room with its configured begin instruction.
|
|
1191
|
+
*
|
|
1192
|
+
* `RoomAccess` rather than `OwnerOnly`, and deliberately: the people who most
|
|
1193
|
+
* need to start a published room are the party holding its link, who have a
|
|
1194
|
+
* room-scoped token and nothing more. It is also a strictly narrower power than
|
|
1195
|
+
* the message endpoint beside it — the caller chooses nothing, since the
|
|
1196
|
+
* content, sender, action and target all come from the room's own settings.
|
|
1197
|
+
*/
|
|
1198
|
+
async beginRoom(req, roomId) {
|
|
1199
|
+
try {
|
|
1200
|
+
const appService = this.getAppService(req, undefined, roomId);
|
|
1201
|
+
return await appService.beginRoom(roomId);
|
|
1202
|
+
}
|
|
1203
|
+
catch (error) {
|
|
1204
|
+
logger_1.logger.error(`[${req.user?.sub}] Error beginning room ${roomId}:`, error);
|
|
1205
|
+
if (error instanceof errors_1.NotFoundError) {
|
|
1206
|
+
throw new common_1.NotFoundException(error.message);
|
|
1207
|
+
}
|
|
1208
|
+
if (error instanceof errors_1.ValidationError) {
|
|
1209
|
+
throw new common_1.BadRequestException(error.message);
|
|
1210
|
+
}
|
|
1211
|
+
// A room that has already begun is a conflict rather than a bad request:
|
|
1212
|
+
// the same call would have worked a moment earlier, and the client's job
|
|
1213
|
+
// is to stop offering Begin, not to fix its payload.
|
|
1214
|
+
if (error instanceof errors_1.OperationFailedError) {
|
|
1215
|
+
throw new common_1.HttpException(error.message, common_1.HttpStatus.CONFLICT);
|
|
1216
|
+
}
|
|
1217
|
+
throw new common_1.HttpException('Failed to begin room', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1177
1220
|
async pauseRoom(req, roomId) {
|
|
1178
1221
|
try {
|
|
1179
1222
|
const appService = this.getAppService(req, undefined, roomId);
|
|
@@ -1500,6 +1543,33 @@ let AppController = AppController_1 = class AppController {
|
|
|
1500
1543
|
throw new common_1.HttpException('Failed to revert chapter', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
1501
1544
|
}
|
|
1502
1545
|
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Serves a picture the room's illustrator drew.
|
|
1548
|
+
*
|
|
1549
|
+
* Read access rather than owner-only, because the whole point is that a
|
|
1550
|
+
* published campaign shows its images to the people playing it. The browser
|
|
1551
|
+
* fetches this as a subresource of a message, carrying neither the room header
|
|
1552
|
+
* nor a cookie, so `JwtAuthGuard` has a branch that resolves a published room
|
|
1553
|
+
* id straight from this URL — the same accommodation the SSE routes need.
|
|
1554
|
+
*/
|
|
1555
|
+
async getRoomImage(req, roomId, artifactId, res) {
|
|
1556
|
+
try {
|
|
1557
|
+
const appService = this.getAppService(req, undefined, roomId);
|
|
1558
|
+
const image = await appService.getRoomImage(roomId, artifactId);
|
|
1559
|
+
if (!image) {
|
|
1560
|
+
throw new common_1.NotFoundException('Image not found');
|
|
1561
|
+
}
|
|
1562
|
+
res.setHeader('Content-Type', image.mimeType);
|
|
1563
|
+
res.send(image.content);
|
|
1564
|
+
}
|
|
1565
|
+
catch (error) {
|
|
1566
|
+
if (error instanceof common_1.NotFoundException) {
|
|
1567
|
+
throw error;
|
|
1568
|
+
}
|
|
1569
|
+
logger_1.logger.error(`Error getting image ${artifactId} for room ${roomId}:`, error);
|
|
1570
|
+
throw new common_1.HttpException('Failed to get image', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1503
1573
|
async getRoomArtifacts(req, roomId) {
|
|
1504
1574
|
try {
|
|
1505
1575
|
const appService = this.getAppService(req, undefined, roomId);
|
|
@@ -2978,6 +3048,16 @@ __decorate([
|
|
|
2978
3048
|
__metadata("design:paramtypes", [Object, String, Object]),
|
|
2979
3049
|
__metadata("design:returntype", Promise)
|
|
2980
3050
|
], AppController.prototype, "sendRoomMessage", null);
|
|
3051
|
+
__decorate([
|
|
3052
|
+
(0, room_access_decorator_1.RoomAccess)(),
|
|
3053
|
+
(0, common_1.Post)('rooms/:roomId/begin'),
|
|
3054
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
|
|
3055
|
+
__param(0, (0, common_1.Request)()),
|
|
3056
|
+
__param(1, (0, common_1.Param)('roomId')),
|
|
3057
|
+
__metadata("design:type", Function),
|
|
3058
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
3059
|
+
__metadata("design:returntype", Promise)
|
|
3060
|
+
], AppController.prototype, "beginRoom", null);
|
|
2981
3061
|
__decorate([
|
|
2982
3062
|
(0, room_access_decorator_1.RoomAccess)(),
|
|
2983
3063
|
(0, common_1.Post)('rooms/:roomId/pause'),
|
|
@@ -3167,6 +3247,17 @@ __decorate([
|
|
|
3167
3247
|
__metadata("design:paramtypes", [Object, String]),
|
|
3168
3248
|
__metadata("design:returntype", Promise)
|
|
3169
3249
|
], AppController.prototype, "revertStoryChapter", null);
|
|
3250
|
+
__decorate([
|
|
3251
|
+
(0, room_access_decorator_1.RoomReadAccess)(),
|
|
3252
|
+
(0, common_1.Get)('rooms/:roomId/images/:artifactId'),
|
|
3253
|
+
__param(0, (0, common_1.Request)()),
|
|
3254
|
+
__param(1, (0, common_1.Param)('roomId')),
|
|
3255
|
+
__param(2, (0, common_1.Param)('artifactId')),
|
|
3256
|
+
__param(3, (0, common_1.Res)()),
|
|
3257
|
+
__metadata("design:type", Function),
|
|
3258
|
+
__metadata("design:paramtypes", [Object, String, String, Object]),
|
|
3259
|
+
__metadata("design:returntype", Promise)
|
|
3260
|
+
], AppController.prototype, "getRoomImage", null);
|
|
3170
3261
|
__decorate([
|
|
3171
3262
|
(0, room_access_decorator_1.RoomReadAccess)(),
|
|
3172
3263
|
(0, common_1.Get)('rooms/:roomId/artifacts'),
|
|
@@ -11,6 +11,7 @@ import { StoryStoreService } from './story/story-store.service';
|
|
|
11
11
|
import { StoryService } from './story/story.service';
|
|
12
12
|
import { UserPathsService } from './config/user-paths.service';
|
|
13
13
|
import { PackService } from './packs/pack.service';
|
|
14
|
+
import { IllustrationService } from './room/illustration/illustration.service';
|
|
14
15
|
import { PackInstantiationService } from './packs/pack-instantiation.service';
|
|
15
16
|
import { RpgService } from './rpg/rpg.service';
|
|
16
17
|
import { AttachedFileService } from './ai/attached-file.service';
|
|
@@ -25,7 +26,7 @@ import { AgentFactory } from './ai/agent-factory';
|
|
|
25
26
|
import { RoomFactory } from './room/room-factory';
|
|
26
27
|
import { EventEmitter } from 'events';
|
|
27
28
|
import { PdfConversionOptions, PdfConversionResult } from './documents/pdf-conversion';
|
|
28
|
-
import { AgentInfo, RoomInfo, RoomDetails, RoomTurnMode, CreateRoomResponse, CreateAgentResponse, CreateRoomAgentRequest, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, PromptFolderDefaults, PromptFolderDefaultsResponse, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, SendMessageResult, StoryInfo, StoryState, Character, Transaction, TransactionHistoryResponse, ToolDefinition, ToolSummary, ToolRunResult } from '../../shared/types/app.types';
|
|
29
|
+
import { AgentInfo, RoomInfo, RoomDetails, RoomIllustrationMode, RoomTurnMode, CreateRoomResponse, CreateAgentResponse, CreateRoomAgentRequest, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, PromptFolderDefaults, PromptFolderDefaultsResponse, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, SendMessageResult, StoryInfo, StoryState, Character, Transaction, TransactionHistoryResponse, ToolDefinition, ToolSummary, ToolRunResult } from '../../shared/types/app.types';
|
|
29
30
|
import { RoomMessage } from './room/message';
|
|
30
31
|
import { ToolStoreService } from './tools/tool-store.service';
|
|
31
32
|
import { ToolExecutionService } from './tools/tool-execution.service';
|
|
@@ -125,9 +126,10 @@ export declare class AppService {
|
|
|
125
126
|
private readonly toolStore;
|
|
126
127
|
private readonly toolExecution;
|
|
127
128
|
private readonly packService;
|
|
129
|
+
private readonly illustration;
|
|
128
130
|
private aiServices;
|
|
129
131
|
private readonly userPreferencesFile;
|
|
130
|
-
constructor(aiFactoryService: AiFactoryService, agentStore: AgentStoreService, agentMessageService: AgentMessageService, roomStore: RoomStoreService, roomMessageService: RoomMessageService, userPaths: UserPathsService, attachedFileService: AttachedFileService, artifactService: ArtifactService, storyStore: StoryStoreService, storyService: StoryService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceService: BalanceService, balanceMessageService: BalanceMessageService, transactionService: TransactionService, agentFactory: AgentFactory, roomFactory: RoomFactory, toolStore: ToolStoreService, toolExecution: ToolExecutionService, packService: PackService);
|
|
132
|
+
constructor(aiFactoryService: AiFactoryService, agentStore: AgentStoreService, agentMessageService: AgentMessageService, roomStore: RoomStoreService, roomMessageService: RoomMessageService, userPaths: UserPathsService, attachedFileService: AttachedFileService, artifactService: ArtifactService, storyStore: StoryStoreService, storyService: StoryService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceService: BalanceService, balanceMessageService: BalanceMessageService, transactionService: TransactionService, agentFactory: AgentFactory, roomFactory: RoomFactory, toolStore: ToolStoreService, toolExecution: ToolExecutionService, packService: PackService, illustration: IllustrationService);
|
|
131
133
|
/** Packs, as this user sees them. */
|
|
132
134
|
get packs(): PackService;
|
|
133
135
|
private packInstantiationService?;
|
|
@@ -483,7 +485,7 @@ export declare class AppService {
|
|
|
483
485
|
* @param arriving An agent not yet in the room, checked as though it were.
|
|
484
486
|
*/
|
|
485
487
|
private assertModeratorAvailable;
|
|
486
|
-
createRoom(roomName: string, goal: string, agentIds: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string): Promise<CreateRoomResponse>;
|
|
488
|
+
createRoom(roomName: string, goal: string, agentIds: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode): Promise<CreateRoomResponse>;
|
|
487
489
|
/**
|
|
488
490
|
* Updates the name, goal, and/or agent membership of an existing room.
|
|
489
491
|
*
|
|
@@ -502,10 +504,13 @@ export declare class AppService {
|
|
|
502
504
|
* @param turnMode - How the room chooses who responds. Omit to leave unchanged.
|
|
503
505
|
* See {@link RoomTurnMode}.
|
|
504
506
|
* @param moderator - Nickname of the moderator agent. Omit to leave unchanged.
|
|
507
|
+
* @param pack - The pack to file the room under. Empty string clears it.
|
|
508
|
+
* @param beginInstruction - What {@link beginRoom} sends to the leader. Empty
|
|
509
|
+
* string clears it, which withdraws the room's Begin. Omit to leave unchanged.
|
|
505
510
|
* @throws {NotFoundError} If the room does not exist
|
|
506
511
|
* @throws {OperationFailedError} If attempting to edit a published room instance
|
|
507
512
|
*/
|
|
508
|
-
editRoom(roomId: string, roomName: string, goal: string, baseRoomDir?: string, agentIds?: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, pack?: string): Promise<void>;
|
|
513
|
+
editRoom(roomId: string, roomName: string, goal: string, baseRoomDir?: string, agentIds?: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, pack?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode): Promise<void>;
|
|
509
514
|
/**
|
|
510
515
|
* Separates a room's name from the bare name of an agent that belongs to it.
|
|
511
516
|
*/
|
|
@@ -706,6 +711,33 @@ export declare class AppService {
|
|
|
706
711
|
* ```
|
|
707
712
|
*/
|
|
708
713
|
sendRoomMessage(roomId: string, content: string, sender: string, action?: string, targets?: string[], clearQueue?: boolean, context?: unknown): Promise<SendMessageResult>;
|
|
714
|
+
/**
|
|
715
|
+
* Opens a room by sending its begin instruction to the room leader.
|
|
716
|
+
*
|
|
717
|
+
* A room is pull-driven: an agent is prompted only when a message arrives. So a
|
|
718
|
+
* room nobody has spoken in never moves, however complete its configuration —
|
|
719
|
+
* which for a turn-based table means the leader is waiting to be asked to lead.
|
|
720
|
+
* This is the ask.
|
|
721
|
+
*
|
|
722
|
+
* Sent as `System` rather than as a person, and addressed by `targets` rather
|
|
723
|
+
* than left for the room to place: in `broadcast` mode an untargeted message
|
|
724
|
+
* prompts every agent, which for an opening move is one call per member to
|
|
725
|
+
* decide one reply.
|
|
726
|
+
*
|
|
727
|
+
* The already-begun check is here rather than left to the client because a
|
|
728
|
+
* published room is one link the whole party holds. Two people looking at the
|
|
729
|
+
* same empty transcript both press Begin, and only a check the room makes
|
|
730
|
+
* itself stops the leader being opened twice. `isProcessingInProgress()` is the
|
|
731
|
+
* half of it that covers the window before the first message lands.
|
|
732
|
+
*
|
|
733
|
+
* @param roomId - The room's ID
|
|
734
|
+
* @param context - Opaque host value threaded to any tool the turn invokes
|
|
735
|
+
* @returns Whether the message was accepted, as {@link sendRoomMessage} reports it
|
|
736
|
+
* @throws {NotFoundError} If the room does not exist
|
|
737
|
+
* @throws {ValidationError} If the room has no begin instruction, or no agent to address
|
|
738
|
+
* @throws {OperationFailedError} If the room has already begun
|
|
739
|
+
*/
|
|
740
|
+
beginRoom(roomId: string, context?: unknown): Promise<SendMessageResult>;
|
|
709
741
|
/**
|
|
710
742
|
* Pauses message processing in a room.
|
|
711
743
|
*
|
|
@@ -1900,6 +1932,19 @@ export declare class AppService {
|
|
|
1900
1932
|
* @returns The artifact content as a string or Buffer, or `null` if not found
|
|
1901
1933
|
*/
|
|
1902
1934
|
getStoryArtifact(storyId: string, artifactId: string): string | Buffer | null;
|
|
1935
|
+
/**
|
|
1936
|
+
* Returns one of a room's generated images, with the metadata needed to serve
|
|
1937
|
+
* it. Rooms keep their images in their own directory, separate from the
|
|
1938
|
+
* `.artifact` text files, so this does not go through the artifact store.
|
|
1939
|
+
*
|
|
1940
|
+
* @param roomId - The room's ID
|
|
1941
|
+
* @param artifactId - The image's ID, as it appears in the message markdown
|
|
1942
|
+
* @returns The bytes and MIME type, or `null` when there is no such image
|
|
1943
|
+
*/
|
|
1944
|
+
getRoomImage(roomId: string, artifactId: string): Promise<{
|
|
1945
|
+
content: string | Buffer;
|
|
1946
|
+
mimeType: string;
|
|
1947
|
+
} | null>;
|
|
1903
1948
|
/**
|
|
1904
1949
|
* Returns metadata for all artifacts currently attached to an agent.
|
|
1905
1950
|
*
|
|
@@ -43,6 +43,7 @@ const core_1 = require("./tools/core");
|
|
|
43
43
|
const app_types_1 = require("../../shared/types/app.types");
|
|
44
44
|
const pdf_lib_1 = require("pdf-lib");
|
|
45
45
|
const pdf_conversion_1 = require("./documents/pdf-conversion");
|
|
46
|
+
const app_types_2 = require("../../shared/types/app.types");
|
|
46
47
|
const message_1 = require("./room/message");
|
|
47
48
|
const logger_1 = require("./common/logger");
|
|
48
49
|
/**
|
|
@@ -74,9 +75,10 @@ class AppService {
|
|
|
74
75
|
toolStore;
|
|
75
76
|
toolExecution;
|
|
76
77
|
packService;
|
|
78
|
+
illustration;
|
|
77
79
|
aiServices;
|
|
78
80
|
userPreferencesFile = 'user-preferences.json';
|
|
79
|
-
constructor(aiFactoryService, agentStore, agentMessageService, roomStore, roomMessageService, userPaths, attachedFileService, artifactService, storyStore, storyService, publishedAgentsService, publishedRoomsService, balanceService, balanceMessageService, transactionService, agentFactory, roomFactory, toolStore, toolExecution, packService) {
|
|
81
|
+
constructor(aiFactoryService, agentStore, agentMessageService, roomStore, roomMessageService, userPaths, attachedFileService, artifactService, storyStore, storyService, publishedAgentsService, publishedRoomsService, balanceService, balanceMessageService, transactionService, agentFactory, roomFactory, toolStore, toolExecution, packService, illustration) {
|
|
80
82
|
this.aiFactoryService = aiFactoryService;
|
|
81
83
|
this.agentStore = agentStore;
|
|
82
84
|
this.agentMessageService = agentMessageService;
|
|
@@ -97,6 +99,7 @@ class AppService {
|
|
|
97
99
|
this.toolStore = toolStore;
|
|
98
100
|
this.toolExecution = toolExecution;
|
|
99
101
|
this.packService = packService;
|
|
102
|
+
this.illustration = illustration;
|
|
100
103
|
this.aiServices = this.aiFactoryService.getAllAiServices();
|
|
101
104
|
}
|
|
102
105
|
/** Packs, as this user sees them. */
|
|
@@ -193,7 +196,7 @@ class AppService {
|
|
|
193
196
|
// only needs the name and description. "No images" is offered as a fixed
|
|
194
197
|
// option in the dialog itself, so it is excluded here.
|
|
195
198
|
return entries
|
|
196
|
-
.filter((entry) => entry.name && entry.name !==
|
|
199
|
+
.filter((entry) => entry.name && entry.name !== app_types_2.NO_IMAGES)
|
|
197
200
|
.map((entry) => ({ name: entry.name, description: entry.description ?? '' }));
|
|
198
201
|
}
|
|
199
202
|
catch (error) {
|
|
@@ -814,7 +817,7 @@ class AppService {
|
|
|
814
817
|
throw new errors_1.ValidationError(`${names} ${needsModerator.length === 1 ? 'uses' : 'use'} a moderator, ` +
|
|
815
818
|
`so room "${room.getName()}" needs one. ${reason}`);
|
|
816
819
|
}
|
|
817
|
-
async createRoom(roomName, goal, agentIds, roomLeader, turnMode, moderator) {
|
|
820
|
+
async createRoom(roomName, goal, agentIds, roomLeader, turnMode, moderator, beginInstruction, imageModel, illustrationMode) {
|
|
818
821
|
// Validate that all agents exist before creating the room
|
|
819
822
|
for (const agentId of agentIds) {
|
|
820
823
|
const agent = await this.agentStore.getAgent(agentId);
|
|
@@ -840,6 +843,15 @@ class AppService {
|
|
|
840
843
|
if (moderator !== undefined) {
|
|
841
844
|
room.setModerator(moderator);
|
|
842
845
|
}
|
|
846
|
+
if (beginInstruction !== undefined) {
|
|
847
|
+
room.setBeginInstruction(beginInstruction);
|
|
848
|
+
}
|
|
849
|
+
if (imageModel !== undefined) {
|
|
850
|
+
room.setImageModel(imageModel);
|
|
851
|
+
}
|
|
852
|
+
if (illustrationMode !== undefined) {
|
|
853
|
+
room.setIllustrationMode(illustrationMode);
|
|
854
|
+
}
|
|
843
855
|
// Before saveMetadata, so a room that cannot route its members' messages is
|
|
844
856
|
// never written to disk.
|
|
845
857
|
this.assertModeratorAvailable(room);
|
|
@@ -868,10 +880,13 @@ class AppService {
|
|
|
868
880
|
* @param turnMode - How the room chooses who responds. Omit to leave unchanged.
|
|
869
881
|
* See {@link RoomTurnMode}.
|
|
870
882
|
* @param moderator - Nickname of the moderator agent. Omit to leave unchanged.
|
|
883
|
+
* @param pack - The pack to file the room under. Empty string clears it.
|
|
884
|
+
* @param beginInstruction - What {@link beginRoom} sends to the leader. Empty
|
|
885
|
+
* string clears it, which withdraws the room's Begin. Omit to leave unchanged.
|
|
871
886
|
* @throws {NotFoundError} If the room does not exist
|
|
872
887
|
* @throws {OperationFailedError} If attempting to edit a published room instance
|
|
873
888
|
*/
|
|
874
|
-
async editRoom(roomId, roomName, goal, baseRoomDir, agentIds, roomLeader, turnMode, moderator, pack) {
|
|
889
|
+
async editRoom(roomId, roomName, goal, baseRoomDir, agentIds, roomLeader, turnMode, moderator, pack, beginInstruction, imageModel, illustrationMode) {
|
|
875
890
|
// Get the existing room
|
|
876
891
|
const room = await this.roomStore.getRoom(roomId);
|
|
877
892
|
if (!room) {
|
|
@@ -920,6 +935,15 @@ class AppService {
|
|
|
920
935
|
if (pack !== undefined) {
|
|
921
936
|
room.setPack(pack);
|
|
922
937
|
}
|
|
938
|
+
if (beginInstruction !== undefined) {
|
|
939
|
+
room.setBeginInstruction(beginInstruction);
|
|
940
|
+
}
|
|
941
|
+
if (imageModel !== undefined) {
|
|
942
|
+
room.setImageModel(imageModel);
|
|
943
|
+
}
|
|
944
|
+
if (illustrationMode !== undefined) {
|
|
945
|
+
room.setIllustrationMode(illustrationMode);
|
|
946
|
+
}
|
|
923
947
|
// Catches clearing the moderator, or pointing it at an agent this edit just
|
|
924
948
|
// removed, while a member still needs one.
|
|
925
949
|
this.assertModeratorAvailable(room);
|
|
@@ -1182,6 +1206,9 @@ class AppService {
|
|
|
1182
1206
|
roomLeader: room.getRoomLeader(),
|
|
1183
1207
|
turnMode: room.getTurnMode(),
|
|
1184
1208
|
moderator: room.getModerator(),
|
|
1209
|
+
beginInstruction: room.getBeginInstruction(),
|
|
1210
|
+
imageModel: room.getImageModel(),
|
|
1211
|
+
illustrationMode: room.getIllustrationMode(),
|
|
1185
1212
|
baseRoomDir: room.getBaseRoomDir(),
|
|
1186
1213
|
pack: room.getPack(),
|
|
1187
1214
|
isPublished: room.getIsPublished(),
|
|
@@ -1243,10 +1270,7 @@ class AppService {
|
|
|
1243
1270
|
}
|
|
1244
1271
|
// Get messages from the specified index
|
|
1245
1272
|
const indexedMessages = room.getLatestRoomMessages(fromIndex, includeThoughts);
|
|
1246
|
-
const totalCost = room
|
|
1247
|
-
.getAgents()
|
|
1248
|
-
.map((a) => a.totalCost)
|
|
1249
|
-
.reduce((acc, v) => acc + v, 0);
|
|
1273
|
+
const totalCost = room.totalCost();
|
|
1250
1274
|
return {
|
|
1251
1275
|
messages: indexedMessages,
|
|
1252
1276
|
totalCost: totalCost,
|
|
@@ -1374,6 +1398,53 @@ class AppService {
|
|
|
1374
1398
|
// value threaded to any tool the resulting turn invokes (never persisted).
|
|
1375
1399
|
return room.addPendingMessage(new message_1.RoomMessage(sender, messageAction, content, targets), clearQueue, context);
|
|
1376
1400
|
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Opens a room by sending its begin instruction to the room leader.
|
|
1403
|
+
*
|
|
1404
|
+
* A room is pull-driven: an agent is prompted only when a message arrives. So a
|
|
1405
|
+
* room nobody has spoken in never moves, however complete its configuration —
|
|
1406
|
+
* which for a turn-based table means the leader is waiting to be asked to lead.
|
|
1407
|
+
* This is the ask.
|
|
1408
|
+
*
|
|
1409
|
+
* Sent as `System` rather than as a person, and addressed by `targets` rather
|
|
1410
|
+
* than left for the room to place: in `broadcast` mode an untargeted message
|
|
1411
|
+
* prompts every agent, which for an opening move is one call per member to
|
|
1412
|
+
* decide one reply.
|
|
1413
|
+
*
|
|
1414
|
+
* The already-begun check is here rather than left to the client because a
|
|
1415
|
+
* published room is one link the whole party holds. Two people looking at the
|
|
1416
|
+
* same empty transcript both press Begin, and only a check the room makes
|
|
1417
|
+
* itself stops the leader being opened twice. `isProcessingInProgress()` is the
|
|
1418
|
+
* half of it that covers the window before the first message lands.
|
|
1419
|
+
*
|
|
1420
|
+
* @param roomId - The room's ID
|
|
1421
|
+
* @param context - Opaque host value threaded to any tool the turn invokes
|
|
1422
|
+
* @returns Whether the message was accepted, as {@link sendRoomMessage} reports it
|
|
1423
|
+
* @throws {NotFoundError} If the room does not exist
|
|
1424
|
+
* @throws {ValidationError} If the room has no begin instruction, or no agent to address
|
|
1425
|
+
* @throws {OperationFailedError} If the room has already begun
|
|
1426
|
+
*/
|
|
1427
|
+
async beginRoom(roomId, context) {
|
|
1428
|
+
const room = await this.roomStore.getRoom(roomId);
|
|
1429
|
+
if (!room) {
|
|
1430
|
+
throw new errors_1.NotFoundError('Room not found');
|
|
1431
|
+
}
|
|
1432
|
+
const instruction = room.getBeginInstruction();
|
|
1433
|
+
if (!instruction) {
|
|
1434
|
+
throw new errors_1.ValidationError('This room has no begin instruction.');
|
|
1435
|
+
}
|
|
1436
|
+
if (room.getRoomMessageStats().numMessages > 0 || room.isProcessingInProgress()) {
|
|
1437
|
+
throw new errors_1.OperationFailedError('This room has already begun.');
|
|
1438
|
+
}
|
|
1439
|
+
// Falls back to the first agent, which is the room's convention everywhere
|
|
1440
|
+
// else. Only an empty room has nobody at all.
|
|
1441
|
+
const leader = room.getRoomLeader();
|
|
1442
|
+
if (!leader) {
|
|
1443
|
+
throw new errors_1.ValidationError('This room has no agents to address.');
|
|
1444
|
+
}
|
|
1445
|
+
logger_1.logger.log(`Beginning room "${room.getName()}" by addressing ${leader}`);
|
|
1446
|
+
return this.sendRoomMessage(roomId, instruction, 'System', 'speak', [leader], false, context);
|
|
1447
|
+
}
|
|
1377
1448
|
/**
|
|
1378
1449
|
* Pauses message processing in a room.
|
|
1379
1450
|
*
|
|
@@ -1618,10 +1689,7 @@ class AppService {
|
|
|
1618
1689
|
goal: room.getGoal(),
|
|
1619
1690
|
agentCount: room.getAgentCount(),
|
|
1620
1691
|
pack: room.getPack(),
|
|
1621
|
-
totalCost: room
|
|
1622
|
-
.getAgents()
|
|
1623
|
-
.map((agent) => agent.totalCost || 0)
|
|
1624
|
-
.reduce((total, cost) => total + cost, 0),
|
|
1692
|
+
totalCost: room.totalCost(),
|
|
1625
1693
|
};
|
|
1626
1694
|
}
|
|
1627
1695
|
/**
|
|
@@ -2861,10 +2929,7 @@ class AppService {
|
|
|
2861
2929
|
// `action`, which costs nothing and cannot fall out of step.
|
|
2862
2930
|
const messages = room.getLatestRoomMessages(0, true);
|
|
2863
2931
|
const latestMessage = messages.length > 0 ? messages[messages.length - 1] : undefined;
|
|
2864
|
-
const totalCost = room
|
|
2865
|
-
.getAgents()
|
|
2866
|
-
.map((a) => a.totalCost)
|
|
2867
|
-
.reduce((acc, v) => acc + v, 0);
|
|
2932
|
+
const totalCost = room.totalCost();
|
|
2868
2933
|
const roomState = {
|
|
2869
2934
|
// Both variants travel on the room's 'update' event, so a host that
|
|
2870
2935
|
// narrows on `type` needs it present on the ordinary one too.
|
|
@@ -3574,6 +3639,26 @@ class AppService {
|
|
|
3574
3639
|
const storyArtifactService = this.getStoryArtifactService(storyId);
|
|
3575
3640
|
return storyArtifactService.getArtifact(artifactId);
|
|
3576
3641
|
}
|
|
3642
|
+
/**
|
|
3643
|
+
* Returns one of a room's generated images, with the metadata needed to serve
|
|
3644
|
+
* it. Rooms keep their images in their own directory, separate from the
|
|
3645
|
+
* `.artifact` text files, so this does not go through the artifact store.
|
|
3646
|
+
*
|
|
3647
|
+
* @param roomId - The room's ID
|
|
3648
|
+
* @param artifactId - The image's ID, as it appears in the message markdown
|
|
3649
|
+
* @returns The bytes and MIME type, or `null` when there is no such image
|
|
3650
|
+
*/
|
|
3651
|
+
async getRoomImage(roomId, artifactId) {
|
|
3652
|
+
const room = await this.roomStore.getRoom(roomId);
|
|
3653
|
+
if (!room)
|
|
3654
|
+
return null;
|
|
3655
|
+
const artifacts = this.illustration.targetFor(room).artifacts;
|
|
3656
|
+
const metadata = artifacts.getArtifactMetadata(artifactId);
|
|
3657
|
+
const content = artifacts.getArtifact(artifactId);
|
|
3658
|
+
if (!metadata || !content)
|
|
3659
|
+
return null;
|
|
3660
|
+
return { content, mimeType: metadata.mimeType || 'application/octet-stream' };
|
|
3661
|
+
}
|
|
3577
3662
|
/**
|
|
3578
3663
|
* Returns metadata for all artifacts currently attached to an agent.
|
|
3579
3664
|
*
|
|
@@ -118,6 +118,32 @@ let JwtAuthGuard = class JwtAuthGuard {
|
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
// Match a room image: /rooms/:roomId/images/:artifactId
|
|
122
|
+
//
|
|
123
|
+
// Here for the same reason the SSE branches above are: the browser fetches
|
|
124
|
+
// this itself, as a subresource of a message, so it carries neither the
|
|
125
|
+
// X-Briyah-Room-Id header the published-room client sets nor a cookie.
|
|
126
|
+
// Without this an <img> in a published room's transcript would 401.
|
|
127
|
+
//
|
|
128
|
+
// Read-only deliberately — this must never become a way to post. An
|
|
129
|
+
// unpublished room has no mapping, so it falls through to Priority 4 and is
|
|
130
|
+
// refused.
|
|
131
|
+
const roomImageMatch = url.match(/\/rooms\/([^\/\?]+)\/images\//);
|
|
132
|
+
if (roomImageMatch) {
|
|
133
|
+
const roomId = roomImageMatch[1];
|
|
134
|
+
const userId = this.publishedRoomsService.getUserId(roomId);
|
|
135
|
+
if (userId) {
|
|
136
|
+
request.user = {
|
|
137
|
+
sub: userId,
|
|
138
|
+
userId: userId,
|
|
139
|
+
type: 'room-access',
|
|
140
|
+
scope: ['room:read'],
|
|
141
|
+
roomId: roomId,
|
|
142
|
+
authSource: 'image-url',
|
|
143
|
+
};
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
121
147
|
// Priority 4: Standard JWT authentication (existing code)
|
|
122
148
|
// Try JWT from HTTP-only cookie first (for web clients)
|
|
123
149
|
let token = request.cookies?.briyah_jwt;
|
|
@@ -121,6 +121,11 @@ class PackInstantiationService {
|
|
|
121
121
|
moderator: moderatorKey ? (nicknames.get(moderatorKey) ?? '') : '',
|
|
122
122
|
pack: packName,
|
|
123
123
|
packRoomKey: template.key,
|
|
124
|
+
beginInstruction: template.beginInstruction ?? '',
|
|
125
|
+
// A template that names neither leaves the room on the server's
|
|
126
|
+
// default model, drawing only when an agent asks.
|
|
127
|
+
imageModel: template.imageModel,
|
|
128
|
+
illustrationMode: template.illustrationMode ?? 'on-request',
|
|
124
129
|
});
|
|
125
130
|
room.saveMetadata();
|
|
126
131
|
return { roomId, agentIds, warnings };
|
|
@@ -96,6 +96,13 @@ export interface PackRoomTemplate {
|
|
|
96
96
|
name: string;
|
|
97
97
|
goal: string;
|
|
98
98
|
turnMode?: 'broadcast' | 'directed';
|
|
99
|
+
/**
|
|
100
|
+
* Which entry in `image_models.json` draws this room, when the pack wants a
|
|
101
|
+
* particular one. Absent leaves the room on the server default.
|
|
102
|
+
*/
|
|
103
|
+
imageModel?: string;
|
|
104
|
+
/** When the room illustrates itself. Absent means `on-request`. */
|
|
105
|
+
illustrationMode?: 'off' | 'on-request' | 'auto';
|
|
99
106
|
/**
|
|
100
107
|
* The roster, as loaded.
|
|
101
108
|
*
|
|
@@ -115,6 +122,13 @@ export interface PackRoomTemplate {
|
|
|
115
122
|
roomLeader?: string;
|
|
116
123
|
/** The moderator, also named by agent key. */
|
|
117
124
|
moderator?: string;
|
|
125
|
+
/**
|
|
126
|
+
* What Begin sends to this room's leader, shipped with the template.
|
|
127
|
+
*
|
|
128
|
+
* Here rather than in whatever service builds the room, so a pack's opening
|
|
129
|
+
* move is written beside the prompts it has to agree with.
|
|
130
|
+
*/
|
|
131
|
+
beginInstruction?: string;
|
|
118
132
|
}
|
|
119
133
|
/** A pack directory, read. */
|
|
120
134
|
export interface LoadedPack {
|
|
@@ -267,9 +267,20 @@ function validateRoomTemplate(value, file) {
|
|
|
267
267
|
...(value.turnMode === 'directed' || value.turnMode === 'broadcast'
|
|
268
268
|
? { turnMode: value.turnMode }
|
|
269
269
|
: {}),
|
|
270
|
+
...(typeof value.imageModel === 'string' &&
|
|
271
|
+
value.imageModel.trim() && { imageModel: value.imageModel.trim() }),
|
|
272
|
+
...(value.illustrationMode === 'off' ||
|
|
273
|
+
value.illustrationMode === 'on-request' ||
|
|
274
|
+
value.illustrationMode === 'auto'
|
|
275
|
+
? { illustrationMode: value.illustrationMode }
|
|
276
|
+
: {}),
|
|
270
277
|
agents,
|
|
271
278
|
...(isValidKey(value.roomLeader) && { roomLeader: value.roomLeader }),
|
|
272
279
|
...(isValidKey(value.moderator) && { moderator: value.moderator }),
|
|
280
|
+
...(typeof value.beginInstruction === 'string' &&
|
|
281
|
+
value.beginInstruction.trim() && {
|
|
282
|
+
beginInstruction: value.beginInstruction.trim(),
|
|
283
|
+
}),
|
|
273
284
|
};
|
|
274
285
|
}
|
|
275
286
|
function normalizeRoomAgentEntry(entry, file) {
|