briyah 2.0.2 → 2.0.3
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/LICENSE +216 -0
- package/data/common/config/markup +1 -1
- package/data/packs/dnd5e/agents/player.json +11 -11
- package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
- package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
- package/dist-sdk/server/src/app.service.d.ts +1 -0
- package/dist-sdk/server/src/app.service.js +26 -3
- package/dist-sdk/server/src/room/nickname.d.ts +1 -0
- package/dist-sdk/server/src/room/nickname.js +15 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +1 -0
- package/dist-sdk/server/src/room/room-store.service.js +4 -0
- package/dist-sdk/server/src/room/room.d.ts +28 -1
- package/dist-sdk/server/src/room/room.js +235 -12
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +1 -3
- package/dist-sdk/server/src/rpg/rpg-roster.js +12 -49
- package/dist-sdk/server/src/rpg/rpg.service.js +5 -5
- package/dist-sdk/server/src/sdk/index.d.ts +0 -1
- package/dist-sdk/server/src/sdk/index.js +1 -3
- package/dist-sdk/server/src/tools/core/index.d.ts +3 -0
- package/dist-sdk/server/src/tools/core/index.js +9 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +61 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +10 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +9 -1
- package/dist-sdk/server/src/tools/packs/index.d.ts +3 -2
- package/dist-sdk/server/src/tools/packs/index.js +17 -9
- package/dist-sdk/shared/types/app.types.d.ts +0 -1
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Agent.html +73 -73
- package/docs/classes/Briyah.html +16 -16
- package/docs/classes/BriyahConfigService.html +7 -7
- package/docs/classes/NativeToolRegistry.html +10 -10
- package/docs/classes/PackInstantiationService.html +7 -7
- package/docs/classes/PackService.html +13 -13
- package/docs/classes/Room.html +190 -94
- package/docs/classes/RoomMessage.html +22 -22
- package/docs/enums/MessageAction.html +18 -18
- package/docs/functions/availableToolPacks.html +5 -5
- package/docs/functions/buildMarkdown.html +4 -4
- package/docs/functions/dnd5eTools.html +4 -4
- package/docs/functions/installToolPacks.html +8 -5
- package/docs/functions/pageMarker.html +4 -4
- package/docs/functions/registerToolPacks.html +4 -4
- package/docs/functions/splitMarkdownIntoPages.html +4 -4
- package/docs/functions/stripWrappingFence.html +4 -4
- package/docs/hierarchy.html +11 -11
- package/docs/index.html +4 -4
- package/docs/interfaces/AgentCreationOptions.html +12 -12
- package/docs/interfaces/AgentInfo.html +30 -30
- package/docs/interfaces/AgentMessagesResponse.html +8 -8
- package/docs/interfaces/AppService.html +140 -137
- package/docs/interfaces/Artifact.html +9 -9
- package/docs/interfaces/ArtifactMetadata.html +13 -13
- package/docs/interfaces/ArtifactWriteOptions.html +7 -7
- package/docs/interfaces/AttachDocumentResponse.html +6 -6
- package/docs/interfaces/BriyahConfigOptions.html +12 -12
- package/docs/interfaces/ChapterInfo.html +6 -6
- package/docs/interfaces/Character.html +10 -10
- package/docs/interfaces/ConversionAgent.html +6 -6
- package/docs/interfaces/CreateAgentResponse.html +5 -5
- package/docs/interfaces/CreateRoomResponse.html +6 -6
- package/docs/interfaces/CreateStoryResponse.html +5 -5
- package/docs/interfaces/FileList.html +5 -5
- package/docs/interfaces/FileMetadata.html +10 -10
- package/docs/interfaces/IConfigService.html +5 -5
- package/docs/interfaces/InstantiateModels.html +6 -6
- package/docs/interfaces/InstantiateRoomResult.html +7 -7
- package/docs/interfaces/LoadedPack.html +16 -16
- package/docs/interfaces/LoggingOptions.html +9 -9
- package/docs/interfaces/Message.html +9 -9
- package/docs/interfaces/ModelChoice.html +7 -7
- package/docs/interfaces/ModelInfo.html +8 -8
- package/docs/interfaces/NativeToolDefinition.html +10 -10
- package/docs/interfaces/PackAgentTemplate.html +9 -9
- package/docs/interfaces/PackRoomTemplate.html +11 -11
- package/docs/interfaces/PackView.html +20 -20
- package/docs/interfaces/PdfConversionOptions.html +10 -10
- package/docs/interfaces/PdfConversionResult.html +10 -10
- package/docs/interfaces/PdfMarkdownOptions.html +21 -21
- package/docs/interfaces/PdfMarkdownResult.html +11 -11
- package/docs/interfaces/PdfPageMarkdown.html +9 -9
- package/docs/interfaces/PreparedPromptResponse.html +6 -6
- package/docs/interfaces/ProcessTextResponse.html +10 -10
- package/docs/interfaces/PromptFile.html +7 -7
- package/docs/interfaces/PromptFileContent.html +8 -8
- package/docs/interfaces/PromptFilesResponse.html +5 -5
- package/docs/interfaces/PromptFolder.html +8 -8
- package/docs/interfaces/PromptFolderDefaults.html +19 -19
- package/docs/interfaces/PromptFolderDefaultsResponse.html +7 -7
- package/docs/interfaces/PromptFoldersResponse.html +5 -5
- package/docs/interfaces/RoomDetails.html +19 -19
- package/docs/interfaces/RoomErrorUpdate.html +8 -8
- package/docs/interfaces/RoomInfo.html +10 -10
- package/docs/interfaces/RoomMessageUpdate.html +13 -13
- package/docs/interfaces/RoomMessagesResponse.html +6 -6
- package/docs/interfaces/SendMessageResult.html +6 -6
- package/docs/interfaces/StoryErrorEvent.html +8 -8
- package/docs/interfaces/StoryIdea.html +8 -8
- package/docs/interfaces/StoryInfo.html +28 -28
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +7 -7
- package/docs/interfaces/StoryProgressChapterEvent.html +6 -6
- package/docs/interfaces/StoryState.html +12 -12
- package/docs/interfaces/StoryStateEvent.html +7 -7
- package/docs/interfaces/ToolArtifact.html +9 -9
- package/docs/interfaces/ToolCaller.html +7 -7
- package/docs/interfaces/ToolDefinition.html +9 -9
- package/docs/interfaces/ToolHelpers.html +7 -7
- package/docs/interfaces/ToolPackDocuments.html +6 -6
- package/docs/interfaces/ToolParameter.html +8 -8
- package/docs/interfaces/ToolRoomAccess.html +49 -16
- package/docs/interfaces/ToolSummary.html +8 -8
- package/docs/interfaces/ToolsResponse.html +7 -7
- package/docs/interfaces/Transaction.html +13 -13
- package/docs/interfaces/TransactionHistoryResponse.html +6 -6
- package/docs/modules.html +6 -6
- package/docs/types/PackOrigin.html +4 -4
- package/docs/types/PromptScope.html +4 -4
- package/docs/types/RoomTurnMode.html +4 -4
- package/docs/types/RoomUpdate.html +4 -4
- package/docs/types/RosterOverrides.html +4 -4
- package/docs/types/ToolContext.html +4 -4
- package/docs/types/ToolRunResult.html +4 -4
- package/package.json +32 -3
- package/data/packs/acts/agents/character-guide.json +0 -6
- package/data/packs/acts/agents/discipleship-mentor.json +0 -6
- package/data/packs/acts/agents/mentor-coach.json +0 -6
- package/data/packs/acts/agents/student.json +0 -13
- package/data/packs/acts/agents/table-moderator.json +0 -6
- package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
- package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
- package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
- package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
- package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
- package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
- package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
- package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
- package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
- package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
- package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
- package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
- package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
- package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
- package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
- package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
- package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
- package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
- package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
- package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
- package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
- package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
- package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
- package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
- package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
- package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
- package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
- package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
- package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
- package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
- package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
- package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
- package/data/packs/acts/artifacts/manifest.json +0 -197
- package/data/packs/acts/artifacts/stage-guide.md +0 -94
- package/data/packs/acts/pack.json +0 -6
- package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
- package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
- package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
- package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
- package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
- package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
- package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
- package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
- package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
- package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
- package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
- package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
- package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
- package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
- package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
- package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
- package/data/packs/acts/rooms/session.json +0 -14
- package/data/packs/acts/rooms/training.json +0 -58
- package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
- package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
- package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
- package/docs/functions/actsTools.html +0 -44
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Room = void 0;
|
|
4
|
+
const agent_1 = require("../ai/agent");
|
|
4
5
|
const app_types_1 = require("../../../shared/types/app.types");
|
|
5
6
|
const message_1 = require("./message");
|
|
7
|
+
const nickname_1 = require("./nickname");
|
|
6
8
|
const crypto_1 = require("crypto");
|
|
7
9
|
const errors_1 = require("../common/errors");
|
|
8
10
|
const logger_1 = require("../common/logger");
|
|
9
11
|
const MAX_DESCRIPTION_CHARS = 500;
|
|
12
|
+
const MAX_NICKNAME_CHARS = 40;
|
|
10
13
|
class Room {
|
|
11
14
|
static maxToolIterations() {
|
|
12
15
|
const configured = Number(process.env.ROOM_MAX_TOOL_ITERATIONS);
|
|
@@ -17,6 +20,29 @@ class Room {
|
|
|
17
20
|
const configured = Number(process.env.ROOM_MAX_SELF_CONTINUES);
|
|
18
21
|
return Number.isFinite(configured) && configured >= 0 ? Math.floor(configured) : 3;
|
|
19
22
|
}
|
|
23
|
+
static maxStallRecoveries() {
|
|
24
|
+
const configured = Number(process.env.ROOM_MAX_STALL_RECOVERIES);
|
|
25
|
+
return Number.isFinite(configured) && configured >= 0 ? Math.floor(configured) : 3;
|
|
26
|
+
}
|
|
27
|
+
static rerouteNote(sender, declined) {
|
|
28
|
+
const names = Room.listNames(declined);
|
|
29
|
+
return [
|
|
30
|
+
`IMPORTANT: this message was given to ${names} to answer, and it was not answered.`,
|
|
31
|
+
`Nothing was said in the room and nobody is speaking, so the table is now waiting.`,
|
|
32
|
+
`Name in "name" the one agent who should answer it instead, and put that same`,
|
|
33
|
+
`agent in "targets" — an answer with no targets is discarded.`,
|
|
34
|
+
`Do not name ${sender}, and do not name ${names} again.`,
|
|
35
|
+
].join(' ');
|
|
36
|
+
}
|
|
37
|
+
static rerouteHandoffNote(sender, declined) {
|
|
38
|
+
return (`From system: ${sender}'s message above was given to ${Room.listNames(declined)}, ` +
|
|
39
|
+
`who did not answer it. It is meant for you. Answer it now.`);
|
|
40
|
+
}
|
|
41
|
+
static retryHandoffNote(declined) {
|
|
42
|
+
return (`From system: your message above was given to ${Room.listNames(declined)}, who did ` +
|
|
43
|
+
`not answer it, and nobody else here can take it. Carry on, and address whoever ` +
|
|
44
|
+
`should act next.`);
|
|
45
|
+
}
|
|
20
46
|
id;
|
|
21
47
|
name;
|
|
22
48
|
goal;
|
|
@@ -37,6 +63,8 @@ class Room {
|
|
|
37
63
|
currentSpeaker = null;
|
|
38
64
|
selfContinuingAgent = null;
|
|
39
65
|
consecutiveSelfContinues = 0;
|
|
66
|
+
lastDispatch = null;
|
|
67
|
+
stallRecoveries = 0;
|
|
40
68
|
isPublished = false;
|
|
41
69
|
isLoading = false;
|
|
42
70
|
onStateChangeCallbacks = new Map();
|
|
@@ -193,6 +221,121 @@ class Room {
|
|
|
193
221
|
if (opts.drain && this.pendingMessages && this.pendingMessages.length > 0) {
|
|
194
222
|
this.processPendingMessages();
|
|
195
223
|
}
|
|
224
|
+
this.recoverStalledFloor();
|
|
225
|
+
}
|
|
226
|
+
recoverStalledFloor() {
|
|
227
|
+
if (this.turnMode !== 'directed')
|
|
228
|
+
return;
|
|
229
|
+
if (this.isPaused || this.isAdjourned || this.isLoading)
|
|
230
|
+
return;
|
|
231
|
+
if (this.processingInProgress)
|
|
232
|
+
return;
|
|
233
|
+
if (this.currentSpeaker !== null)
|
|
234
|
+
return;
|
|
235
|
+
if (this.pendingMessages && this.pendingMessages.length > 0)
|
|
236
|
+
return;
|
|
237
|
+
const dispatch = this.lastDispatch;
|
|
238
|
+
if (!dispatch)
|
|
239
|
+
return;
|
|
240
|
+
const moderator = this.configuredModerator();
|
|
241
|
+
if (!moderator)
|
|
242
|
+
return;
|
|
243
|
+
if (this.stallRecoveries >= Room.maxStallRecoveries()) {
|
|
244
|
+
logger_1.logger.warn(`Room ${this.name}: ${this.stallRecoveries} stalled turn(s) re-routed in a row with nothing said; leaving the floor free`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this.stallRecoveries += 1;
|
|
248
|
+
logger_1.logger.warn(`Room ${this.name}: nobody answered ${dispatch.message.getSender()} and the room has gone quiet; asking ${moderator.agentNickname} to re-route (attempt ${this.stallRecoveries} of ${Room.maxStallRecoveries()})`);
|
|
249
|
+
this.processingInProgress = true;
|
|
250
|
+
this.notifyStateChange();
|
|
251
|
+
void this.rerouteStalledTurn(dispatch, moderator).catch((error) => {
|
|
252
|
+
logger_1.logger.error(`Room ${this.name}: re-routing a stalled turn failed:`, error);
|
|
253
|
+
this.endTurn('release', { drain: true });
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
configuredModerator() {
|
|
257
|
+
if (!this.moderator)
|
|
258
|
+
return undefined;
|
|
259
|
+
return this.agents.find((a) => !a.isControlledByHuman &&
|
|
260
|
+
this.checkAgentNicknameMatch(a.agentNickname, this.moderator));
|
|
261
|
+
}
|
|
262
|
+
async rerouteStalledTurn(dispatch, moderator) {
|
|
263
|
+
const stalled = dispatch.message;
|
|
264
|
+
let named;
|
|
265
|
+
await this.moderate(moderator, stalled, (answer) => {
|
|
266
|
+
named = answer?.name;
|
|
267
|
+
}, { note: Room.rerouteNote(stalled.getSender(), dispatch.responders) });
|
|
268
|
+
if (this.isPaused || this.isAdjourned) {
|
|
269
|
+
this.endTurn('keep');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const responder = this.resolveRerouteResponder(named, dispatch, moderator);
|
|
273
|
+
if (!responder) {
|
|
274
|
+
logger_1.logger.warn(`Room ${this.name}: nobody left to answer ${stalled.getSender()}'s message; leaving the floor free`);
|
|
275
|
+
this.endTurn('release', { drain: true });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!stalled.canHear(responder.agentNickname)) {
|
|
279
|
+
this.deliverModerated(responder, stalled, stalled.getContent());
|
|
280
|
+
}
|
|
281
|
+
this.lastDispatch = {
|
|
282
|
+
message: stalled,
|
|
283
|
+
responders: [...dispatch.responders, responder.agentNickname],
|
|
284
|
+
};
|
|
285
|
+
if (responder.isControlledByHuman) {
|
|
286
|
+
logger_1.logger.log(`Re-routed ${stalled.getSender()}'s message to ${responder.agentNickname}`);
|
|
287
|
+
this.endTurn({ to: responder.agentNickname });
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const isAuthor = this.checkAgentNicknameMatch(responder.agentNickname, stalled.getSender());
|
|
291
|
+
responder.addToConversationHistory(isAuthor
|
|
292
|
+
? Room.retryHandoffNote(dispatch.responders)
|
|
293
|
+
: Room.rerouteHandoffNote(stalled.getSender(), dispatch.responders), false);
|
|
294
|
+
responder.save();
|
|
295
|
+
this.setCurrentSpeaker(responder.agentNickname);
|
|
296
|
+
this.getAgentAiResponse(responder, stalled, (message) => {
|
|
297
|
+
if (this.isPaused) {
|
|
298
|
+
this.endTurn('keep');
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.queueAgentResponse(message);
|
|
302
|
+
this.endTurn('release', { drain: true });
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
resolveRerouteResponder(named, dispatch, moderator) {
|
|
306
|
+
const excluded = [moderator.agentNickname, ...dispatch.responders];
|
|
307
|
+
const eligible = (agent) => !excluded.some((name) => this.checkAgentNicknameMatch(agent.agentNickname, name));
|
|
308
|
+
const sender = dispatch.message.getSender();
|
|
309
|
+
const chosen = named
|
|
310
|
+
? this.agents.find((a) => this.checkAgentNicknameMatch(a.agentNickname, named))
|
|
311
|
+
: undefined;
|
|
312
|
+
if (chosen) {
|
|
313
|
+
if (eligible(chosen) && !this.checkAgentNicknameMatch(chosen.agentNickname, sender)) {
|
|
314
|
+
return chosen;
|
|
315
|
+
}
|
|
316
|
+
logger_1.logger.warn(`Room ${this.name}: moderator re-routed to ${chosen.agentNickname}, who sent the message or has already declined it; falling back`);
|
|
317
|
+
}
|
|
318
|
+
const leader = this.agents.find((a) => a.agentNickname === this.getRoomLeader());
|
|
319
|
+
if (leader && eligible(leader) && !this.checkAgentNicknameMatch(leader.agentNickname, sender)) {
|
|
320
|
+
return leader;
|
|
321
|
+
}
|
|
322
|
+
const author = this.agents.find((a) => this.checkAgentNicknameMatch(a.agentNickname, sender));
|
|
323
|
+
return author && eligible(author) && !author.isControlledByHuman ? author : undefined;
|
|
324
|
+
}
|
|
325
|
+
queueAgentResponse(message) {
|
|
326
|
+
if (message === null)
|
|
327
|
+
return;
|
|
328
|
+
if (message.action === app_types_1.MessageAction.THINK) {
|
|
329
|
+
this.addRoomMessage(message);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
this.stallRecoveries = 0;
|
|
333
|
+
if (message.action === app_types_1.MessageAction.SHOUT) {
|
|
334
|
+
this.pendingMessages = [message, ...(this.pendingMessages || [])];
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
this.pendingMessages = [...(this.pendingMessages || []), message];
|
|
338
|
+
}
|
|
196
339
|
}
|
|
197
340
|
getRoomMessageStats() {
|
|
198
341
|
let numMessages = this.roomMessages.length;
|
|
@@ -242,6 +385,83 @@ class Room {
|
|
|
242
385
|
getArtifacts() {
|
|
243
386
|
return [...this.artifacts];
|
|
244
387
|
}
|
|
388
|
+
renameAgent(from, to) {
|
|
389
|
+
const agent = this.agents.find((a) => this.checkAgentNicknameMatch(a.agentNickname, from));
|
|
390
|
+
if (!agent)
|
|
391
|
+
return { renamed: false, reason: 'not_found' };
|
|
392
|
+
const fullName = (to || '').trim().slice(0, MAX_NICKNAME_CHARS);
|
|
393
|
+
if (!fullName)
|
|
394
|
+
return { renamed: false, reason: 'invalid' };
|
|
395
|
+
const nickname = agent_1.Agent.generateNickname(fullName);
|
|
396
|
+
const previous = agent.agentNickname;
|
|
397
|
+
if (previous === nickname && agent.agentName === fullName) {
|
|
398
|
+
return { renamed: false, reason: 'unchanged', from: previous, to: nickname };
|
|
399
|
+
}
|
|
400
|
+
const clash = this.conflictingNickname(agent, nickname);
|
|
401
|
+
if (clash) {
|
|
402
|
+
return {
|
|
403
|
+
renamed: false,
|
|
404
|
+
reason: 'ambiguous',
|
|
405
|
+
from: previous,
|
|
406
|
+
to: nickname,
|
|
407
|
+
conflictsWith: clash,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
agent.agentNickname = nickname;
|
|
411
|
+
agent.agentName = fullName;
|
|
412
|
+
agent.save();
|
|
413
|
+
const artifactsUpdated = this.repointNickname(previous, nickname);
|
|
414
|
+
return {
|
|
415
|
+
renamed: true,
|
|
416
|
+
from: previous,
|
|
417
|
+
to: nickname,
|
|
418
|
+
fullName,
|
|
419
|
+
artifactsUpdated,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
conflictingNickname(agent, nickname) {
|
|
423
|
+
const clash = this.agents.find((a) => a !== agent && (0, nickname_1.nicknamesAreAmbiguous)(a.agentNickname, nickname));
|
|
424
|
+
return clash?.agentNickname;
|
|
425
|
+
}
|
|
426
|
+
repointNickname(previous, nickname) {
|
|
427
|
+
if (!previous || previous === nickname)
|
|
428
|
+
return 0;
|
|
429
|
+
const artifactsUpdated = this.renameInArtifacts(previous, nickname);
|
|
430
|
+
if (this.roomLeader === previous)
|
|
431
|
+
this.roomLeader = nickname;
|
|
432
|
+
if (this.moderator === previous)
|
|
433
|
+
this.moderator = nickname;
|
|
434
|
+
this.saveMetadata();
|
|
435
|
+
this.announceRename(previous, nickname);
|
|
436
|
+
return artifactsUpdated;
|
|
437
|
+
}
|
|
438
|
+
renameInArtifacts(previous, nickname) {
|
|
439
|
+
let changed = 0;
|
|
440
|
+
for (const artifact of this.artifacts) {
|
|
441
|
+
let touched = false;
|
|
442
|
+
if (artifact.creator === previous) {
|
|
443
|
+
artifact.creator = nickname;
|
|
444
|
+
touched = true;
|
|
445
|
+
}
|
|
446
|
+
if (artifact.viewers?.some((viewer) => viewer === previous)) {
|
|
447
|
+
artifact.viewers = artifact.viewers.map((viewer) => viewer === previous ? nickname : viewer);
|
|
448
|
+
touched = true;
|
|
449
|
+
}
|
|
450
|
+
if (!touched)
|
|
451
|
+
continue;
|
|
452
|
+
changed++;
|
|
453
|
+
if (this.roomStoreService && this.storageDir) {
|
|
454
|
+
this.roomStoreService.saveArtifactFile(this.id, this.storageDir, artifact);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return changed;
|
|
458
|
+
}
|
|
459
|
+
announceRename(previous, nickname) {
|
|
460
|
+
const note = `[Room] "${previous}" is now known as "${nickname}". Earlier messages use the old name.`;
|
|
461
|
+
for (const agent of this.agents) {
|
|
462
|
+
agent.addToConversationHistory(note, false);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
245
465
|
isRoomAdjourned() {
|
|
246
466
|
return this.isAdjourned;
|
|
247
467
|
}
|
|
@@ -665,6 +885,7 @@ class Room {
|
|
|
665
885
|
target.save();
|
|
666
886
|
return true;
|
|
667
887
|
},
|
|
888
|
+
renameAgent: (nickname, newName) => this.renameAgent(nickname, newName),
|
|
668
889
|
};
|
|
669
890
|
}
|
|
670
891
|
getAgentAiResponse(agent, message, onResponse) {
|
|
@@ -722,7 +943,7 @@ class Room {
|
|
|
722
943
|
}
|
|
723
944
|
this.getAgentAiResponse(agent, message, onResponse);
|
|
724
945
|
}
|
|
725
|
-
async moderate(moderatorAgent, message, onResponse) {
|
|
946
|
+
async moderate(moderatorAgent, message, onResponse, opts = {}) {
|
|
726
947
|
const humanAgents = this.getHumanAgents();
|
|
727
948
|
const humanAgent = humanAgents[0];
|
|
728
949
|
const humanAgentNames = humanAgents.map((a) => a.agentNickname);
|
|
@@ -750,6 +971,9 @@ ${this.buildSituationHeader()}
|
|
|
750
971
|
Sender: ${message.getSender()}
|
|
751
972
|
Recent Message: ${message.getContent()}
|
|
752
973
|
`;
|
|
974
|
+
if (opts.note) {
|
|
975
|
+
prompt += `\n${opts.note}\n`;
|
|
976
|
+
}
|
|
753
977
|
if (this.lastModeratedAudience.length > 0) {
|
|
754
978
|
prompt += `\nAudience of the previous message: ${this.lastModeratedAudience.join(', ')}\n`;
|
|
755
979
|
}
|
|
@@ -1035,6 +1259,8 @@ Recent Message: ${message.getContent()}
|
|
|
1035
1259
|
}
|
|
1036
1260
|
const humanAgent = this.getHumanAgentByName(message.sender);
|
|
1037
1261
|
const isHumanMessage = !!humanAgent;
|
|
1262
|
+
if (isHumanMessage)
|
|
1263
|
+
this.stallRecoveries = 0;
|
|
1038
1264
|
if (isHumanMessage && humanAgent.useModerator && message.action !== app_types_1.MessageAction.MODERATE) {
|
|
1039
1265
|
logger_1.logger.log(`${humanAgent.agentNickname} uses the moderator; sending as moderate rather than ${message.action}`);
|
|
1040
1266
|
message.action = app_types_1.MessageAction.MODERATE;
|
|
@@ -1198,6 +1424,7 @@ Recent Message: ${message.getContent()}
|
|
|
1198
1424
|
}
|
|
1199
1425
|
this.setCurrentSpeaker(responderNickname);
|
|
1200
1426
|
const continuing = this.checkAgentNicknameMatch(originalMessage.sender, responderAgent.agentNickname);
|
|
1427
|
+
this.lastDispatch = { message: relayed, responders: [responderAgent.agentNickname] };
|
|
1201
1428
|
this.perceive(responderAgent, relayed, (response) => {
|
|
1202
1429
|
if (this.isPaused) {
|
|
1203
1430
|
this.endTurn('keep');
|
|
@@ -1205,6 +1432,8 @@ Recent Message: ${message.getContent()}
|
|
|
1205
1432
|
}
|
|
1206
1433
|
if (response !== null) {
|
|
1207
1434
|
this.pendingMessages = [response, ...this.pendingMessages];
|
|
1435
|
+
if (response.action !== app_types_1.MessageAction.THINK)
|
|
1436
|
+
this.stallRecoveries = 0;
|
|
1208
1437
|
}
|
|
1209
1438
|
this.endTurn('release', { drain: true });
|
|
1210
1439
|
}, { continuing });
|
|
@@ -1451,22 +1680,16 @@ Recent Message: ${message.getContent()}
|
|
|
1451
1680
|
this.endTurn('release', { drain: true });
|
|
1452
1681
|
return;
|
|
1453
1682
|
}
|
|
1683
|
+
this.lastDispatch = {
|
|
1684
|
+
message: nextMessage,
|
|
1685
|
+
responders: responders.map((a) => a.agentNickname),
|
|
1686
|
+
};
|
|
1454
1687
|
for (const agent of responders) {
|
|
1455
1688
|
this.pinHistoryOnHandoff(agent, nextMessage);
|
|
1456
1689
|
const continuing = agent.agentNickname === nextMessage.getSender();
|
|
1457
1690
|
this.perceive(agent, nextMessage, (message) => {
|
|
1458
1691
|
agentsInProgress--;
|
|
1459
|
-
|
|
1460
|
-
if (message.action === app_types_1.MessageAction.THINK) {
|
|
1461
|
-
this.addRoomMessage(message);
|
|
1462
|
-
}
|
|
1463
|
-
else if (message.action === app_types_1.MessageAction.SHOUT) {
|
|
1464
|
-
this.pendingMessages = [message, ...this.pendingMessages];
|
|
1465
|
-
}
|
|
1466
|
-
else {
|
|
1467
|
-
this.pendingMessages = [...this.pendingMessages, message];
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1692
|
+
this.queueAgentResponse(message);
|
|
1470
1693
|
if (agentsInProgress === 0) {
|
|
1471
1694
|
this.endTurn(this.isPaused ? 'keep' : 'release', { drain: true });
|
|
1472
1695
|
}
|
|
@@ -4,7 +4,5 @@ export declare const RPG_ROOM_KEY = "campaign";
|
|
|
4
4
|
export declare const RPG_PLAYER_FOLDER = "dnd5e:dnd_player";
|
|
5
5
|
export declare const RPG_PLAYER_AGENT_KEY = "player";
|
|
6
6
|
export declare const RPG_MAX_PLAYERS = 6;
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const RPG_CREW_NICKNAMES: Readonly<Record<string, string>>;
|
|
9
|
-
export declare function nicknamesAreAmbiguous(a: string, b: string): boolean;
|
|
7
|
+
export declare const RPG_SEAT_NAMES: readonly ["Player One", "Player Two", "Player Three", "Player Four", "Player Five", "Player Six"];
|
|
10
8
|
export declare function assertSeatable(players: RpgPlayerRequest[] | undefined): void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.nicknamesAreAmbiguous = nicknamesAreAmbiguous;
|
|
3
|
+
exports.RPG_SEAT_NAMES = exports.RPG_MAX_PLAYERS = exports.RPG_PLAYER_AGENT_KEY = exports.RPG_PLAYER_FOLDER = exports.RPG_ROOM_KEY = exports.RPG_PACK = void 0;
|
|
5
4
|
exports.assertSeatable = assertSeatable;
|
|
6
5
|
const errors_1 = require("../common/errors");
|
|
7
6
|
exports.RPG_PACK = 'dnd5e';
|
|
@@ -9,26 +8,14 @@ exports.RPG_ROOM_KEY = 'campaign';
|
|
|
9
8
|
exports.RPG_PLAYER_FOLDER = `${exports.RPG_PACK}:dnd_player`;
|
|
10
9
|
exports.RPG_PLAYER_AGENT_KEY = 'player';
|
|
11
10
|
exports.RPG_MAX_PLAYERS = 6;
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function nicknamesAreAmbiguous(a, b) {
|
|
21
|
-
const keys = (name) => {
|
|
22
|
-
const trimmed = name.trim();
|
|
23
|
-
return new Set([trimmed.toLowerCase(), trimmed.split(/\s+/)[0].toLowerCase()]);
|
|
24
|
-
};
|
|
25
|
-
const left = keys(a);
|
|
26
|
-
for (const key of keys(b)) {
|
|
27
|
-
if (left.has(key))
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
11
|
+
exports.RPG_SEAT_NAMES = [
|
|
12
|
+
'Player One',
|
|
13
|
+
'Player Two',
|
|
14
|
+
'Player Three',
|
|
15
|
+
'Player Four',
|
|
16
|
+
'Player Five',
|
|
17
|
+
'Player Six',
|
|
18
|
+
];
|
|
32
19
|
function assertSeatable(players) {
|
|
33
20
|
if (!players || players.length === 0) {
|
|
34
21
|
throw new errors_1.ValidationError('A campaign needs at least one player.');
|
|
@@ -39,33 +26,9 @@ function assertSeatable(players) {
|
|
|
39
26
|
if (!players.some((player) => player.isHuman)) {
|
|
40
27
|
throw new errors_1.ValidationError('At least one player has to be a person.');
|
|
41
28
|
}
|
|
42
|
-
|
|
43
|
-
const name = player.characterName?.trim() ?? '';
|
|
44
|
-
if (!name) {
|
|
45
|
-
throw new errors_1.ValidationError('Every player needs a character name.');
|
|
46
|
-
}
|
|
47
|
-
if (name.length > exports.RPG_MAX_CHARACTER_NAME) {
|
|
48
|
-
throw new errors_1.ValidationError(`"${name}" is too long for a character name (${exports.RPG_MAX_CHARACTER_NAME} characters).`);
|
|
49
|
-
}
|
|
50
|
-
if (!/[a-z0-9]/i.test(name)) {
|
|
51
|
-
throw new errors_1.ValidationError(`"${name}" needs at least one letter or number.`);
|
|
52
|
-
}
|
|
53
|
-
for (const [nickname, role] of Object.entries(exports.RPG_CREW_NICKNAMES)) {
|
|
54
|
-
if (nicknamesAreAmbiguous(name, nickname)) {
|
|
55
|
-
throw new errors_1.ValidationError(`"${name}" is too close to "${nickname}", which is ${role}'s name at this table. Pick another.`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
29
|
+
players.forEach((player, index) => {
|
|
58
30
|
if (!player.isHuman && !player.modelName?.trim()) {
|
|
59
|
-
throw new errors_1.ValidationError(
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
for (let i = 0; i < players.length; i++) {
|
|
63
|
-
for (let j = i + 1; j < players.length; j++) {
|
|
64
|
-
const first = players[i].characterName.trim();
|
|
65
|
-
const second = players[j].characterName.trim();
|
|
66
|
-
if (nicknamesAreAmbiguous(first, second)) {
|
|
67
|
-
throw new errors_1.ValidationError(`The table cannot tell "${first}" and "${second}" apart. Give them distinct names.`);
|
|
68
|
-
}
|
|
31
|
+
throw new errors_1.ValidationError(`${exports.RPG_SEAT_NAMES[index]} is an AI player and needs a model.`);
|
|
69
32
|
}
|
|
70
|
-
}
|
|
33
|
+
});
|
|
71
34
|
}
|
|
@@ -45,9 +45,9 @@ class RpgService {
|
|
|
45
45
|
aiModel: seat.model?.model ?? this.economyModel(crewModels),
|
|
46
46
|
smallModelName: seat.model?.small_model ?? crewModels.primary.smallModelName,
|
|
47
47
|
overrides: {
|
|
48
|
-
agentName: seat.
|
|
49
|
-
agentNickname: seat.
|
|
50
|
-
description: `${seat.
|
|
48
|
+
agentName: seat.seatName,
|
|
49
|
+
agentNickname: seat.seatName.replace(/\s+/g, ''),
|
|
50
|
+
description: `${seat.seatName}, a player at the table. Renamed to their character once their sheet is built.`,
|
|
51
51
|
controlledByHuman: seat.isHuman,
|
|
52
52
|
useModerator: true,
|
|
53
53
|
...(seat.isHuman ? {} : { privateContext: seat.personality }),
|
|
@@ -117,8 +117,8 @@ class RpgService {
|
|
|
117
117
|
}
|
|
118
118
|
resolveSeats(players) {
|
|
119
119
|
const configDir = this.userPaths.getCommonConfigDir();
|
|
120
|
-
return players.map((player) => ({
|
|
121
|
-
|
|
120
|
+
return players.map((player, index) => ({
|
|
121
|
+
seatName: rpg_roster_1.RPG_SEAT_NAMES[index],
|
|
122
122
|
isHuman: player.isHuman,
|
|
123
123
|
personality: player.personality?.trim() ?? '',
|
|
124
124
|
model: player.isHuman
|
|
@@ -7,7 +7,6 @@ export type { AgentInfo, CreateAgentResponse, RoomInfo, RoomDetails, CreateRoomR
|
|
|
7
7
|
export type { LoggingOptions } from './briyah-config';
|
|
8
8
|
export type { NativeToolDefinition, ToolHelpers, ToolContext, ToolCaller, ToolArtifact, ToolRoomAccess, ToolPackDocuments, ArtifactWriteOptions, } from '../tools/native-tool.types';
|
|
9
9
|
export { dnd5eTools } from '../tools/packs/dnd5e';
|
|
10
|
-
export { actsTools } from '../tools/packs/acts';
|
|
11
10
|
export { installToolPacks, registerToolPacks, availableToolPacks } from '../tools/packs';
|
|
12
11
|
export { NativeToolRegistry } from '../tools/native-tool-registry.service';
|
|
13
12
|
export { PackService } from '../packs/pack.service';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoomMessage = exports.Room = exports.Agent = exports.PackInstantiationService = exports.PackService = exports.NativeToolRegistry = exports.availableToolPacks = exports.registerToolPacks = exports.installToolPacks = exports.
|
|
3
|
+
exports.RoomMessage = exports.Room = exports.Agent = exports.PackInstantiationService = exports.PackService = exports.NativeToolRegistry = exports.availableToolPacks = exports.registerToolPacks = exports.installToolPacks = exports.dnd5eTools = exports.buildMarkdown = exports.pageMarker = exports.stripWrappingFence = exports.splitMarkdownIntoPages = exports.BriyahConfigService = exports.Briyah = void 0;
|
|
4
4
|
var briyah_1 = require("./briyah");
|
|
5
5
|
Object.defineProperty(exports, "Briyah", { enumerable: true, get: function () { return briyah_1.Briyah; } });
|
|
6
6
|
var briyah_config_1 = require("./briyah-config");
|
|
@@ -12,8 +12,6 @@ Object.defineProperty(exports, "pageMarker", { enumerable: true, get: function (
|
|
|
12
12
|
Object.defineProperty(exports, "buildMarkdown", { enumerable: true, get: function () { return pdf_conversion_1.buildMarkdown; } });
|
|
13
13
|
var dnd5e_1 = require("../tools/packs/dnd5e");
|
|
14
14
|
Object.defineProperty(exports, "dnd5eTools", { enumerable: true, get: function () { return dnd5e_1.dnd5eTools; } });
|
|
15
|
-
var acts_1 = require("../tools/packs/acts");
|
|
16
|
-
Object.defineProperty(exports, "actsTools", { enumerable: true, get: function () { return acts_1.actsTools; } });
|
|
17
15
|
var packs_1 = require("../tools/packs");
|
|
18
16
|
Object.defineProperty(exports, "installToolPacks", { enumerable: true, get: function () { return packs_1.installToolPacks; } });
|
|
19
17
|
Object.defineProperty(exports, "registerToolPacks", { enumerable: true, get: function () { return packs_1.registerToolPacks; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CORE_TOOL_GROUP = void 0;
|
|
4
|
+
exports.coreTools = coreTools;
|
|
5
|
+
const rename_tool_1 = require("./rename.tool");
|
|
6
|
+
exports.CORE_TOOL_GROUP = 'core';
|
|
7
|
+
function coreTools() {
|
|
8
|
+
return [rename_tool_1.renameAgentTool];
|
|
9
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renameAgentTool = void 0;
|
|
4
|
+
const coerce_1 = require("../shared/coerce");
|
|
5
|
+
exports.renameAgentTool = {
|
|
6
|
+
name: 'rename_agent',
|
|
7
|
+
description: 'Rename an agent so the room knows it by its character\'s name. Use this once a character has a name — after that, addressing the character by name routes to them directly, instead of the room not recognising the name and the message going nowhere useful. ' +
|
|
8
|
+
'The routing name is the first word, so "Thorin Oakenshield" is addressed as "Thorin". ' +
|
|
9
|
+
'Their character sheet and anything else they can view follow the rename automatically. ' +
|
|
10
|
+
'A name that would be confused with another agent at the table is refused — ask for a different one rather than seating two people the room cannot tell apart. ' +
|
|
11
|
+
'Example: {"agent": "PlayerOne", "name": "Thorin Oakenshield"}',
|
|
12
|
+
parameters: [
|
|
13
|
+
{
|
|
14
|
+
name: 'agent',
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'The agent to rename, by the name the room currently knows it by',
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'name',
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: "The character's name, e.g. \"Thorin Oakenshield\"",
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
async handler(args, helpers) {
|
|
27
|
+
if (!helpers?.room) {
|
|
28
|
+
throw new Error('Renaming works on the agents of a room and there is no room here. Run it from a room rather than the tool tester.');
|
|
29
|
+
}
|
|
30
|
+
const agent = (0, coerce_1.str)(args.agent, 'agent');
|
|
31
|
+
const name = (0, coerce_1.str)(args.name, 'name');
|
|
32
|
+
const outcome = helpers.room.renameAgent(agent, name);
|
|
33
|
+
if (outcome.renamed) {
|
|
34
|
+
return {
|
|
35
|
+
applied: true,
|
|
36
|
+
...outcome,
|
|
37
|
+
note: `The room now knows them as "${outcome.to}". Address them by that name from here on; ` +
|
|
38
|
+
'earlier messages still use the old one.',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (outcome.reason === 'ambiguous') {
|
|
42
|
+
return {
|
|
43
|
+
applied: false,
|
|
44
|
+
violation: 'ambiguous_name',
|
|
45
|
+
message: `"${outcome.to}" would be confused with "${outcome.conflictsWith}", who is already at this table.`,
|
|
46
|
+
rule: 'Two agents in a room must not share a name, or a first word — the room routes by name and could not tell them apart.',
|
|
47
|
+
options: [
|
|
48
|
+
'Ask for a different character name.',
|
|
49
|
+
`Anything that does not start with "${outcome.conflictsWith}" works.`,
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (outcome.reason === 'unchanged') {
|
|
54
|
+
return { applied: false, violation: 'unchanged', message: `They are already called "${outcome.to}".` };
|
|
55
|
+
}
|
|
56
|
+
if (outcome.reason === 'invalid') {
|
|
57
|
+
throw new Error('A name is required, and cannot be blank — it is how the room addresses them.');
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`No agent called "${agent}" is in this room. Use the name the room currently knows them by.`);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -11,6 +11,15 @@ export interface ToolArtifact {
|
|
|
11
11
|
viewers: string[];
|
|
12
12
|
transient: boolean;
|
|
13
13
|
}
|
|
14
|
+
export interface RenameOutcome {
|
|
15
|
+
renamed: boolean;
|
|
16
|
+
from?: string;
|
|
17
|
+
to?: string;
|
|
18
|
+
fullName?: string;
|
|
19
|
+
reason?: 'not_found' | 'ambiguous' | 'invalid' | 'unchanged';
|
|
20
|
+
conflictsWith?: string;
|
|
21
|
+
artifactsUpdated?: number;
|
|
22
|
+
}
|
|
14
23
|
export interface ArtifactWriteOptions {
|
|
15
24
|
viewers?: string[];
|
|
16
25
|
creator?: string;
|
|
@@ -27,6 +36,7 @@ export interface ToolRoomAccess {
|
|
|
27
36
|
update(name: string, mutate: (current: ToolArtifact | undefined) => string | null, options?: ArtifactWriteOptions): ToolArtifact | undefined;
|
|
28
37
|
remove(name: string): boolean;
|
|
29
38
|
setDescription(nickname: string, description: string): boolean;
|
|
39
|
+
renameAgent(nickname: string, newName: string): RenameOutcome;
|
|
30
40
|
}
|
|
31
41
|
export interface ToolPackDocuments {
|
|
32
42
|
list(pack: string, prefix?: string): string[];
|
|
@@ -93,12 +93,20 @@ exports.createSheetTool = {
|
|
|
93
93
|
(0, shared_1.refreshPartyStatus)(room);
|
|
94
94
|
const identity = publicIdentity(state);
|
|
95
95
|
const described = state.owner ? room.setDescription(state.owner, identity) : false;
|
|
96
|
+
const renamed = state.owner ? room.renameAgent(state.owner, state.name) : undefined;
|
|
96
97
|
const guides = shareGuidesForCharacter(room, helpers.packDocuments, state);
|
|
97
98
|
return {
|
|
98
99
|
created: artifactName,
|
|
99
100
|
headline: (0, shared_1.sheetHeadline)(state),
|
|
100
|
-
owner: state.owner,
|
|
101
|
+
owner: renamed?.renamed ? renamed.to : state.owner,
|
|
101
102
|
publicIdentity: described ? identity : undefined,
|
|
103
|
+
renamedTo: renamed?.renamed ? renamed.to : undefined,
|
|
104
|
+
renameNote: renamed?.renamed
|
|
105
|
+
? `The table now knows this player as "${renamed.to}". Address them by that name from here on.`
|
|
106
|
+
: renamed?.reason === 'ambiguous'
|
|
107
|
+
? `Their agent could NOT be renamed: "${renamed.to}" would be confused with "${renamed.conflictsWith}". ` +
|
|
108
|
+
`Keep addressing them as "${state.owner}", or ask the player for a character name that does not clash.`
|
|
109
|
+
: undefined,
|
|
102
110
|
classGuides: guides.classes.length > 0 ? guides.classes : undefined,
|
|
103
111
|
classesWithoutRules: guides.missingClasses.length > 0 ? guides.missingClasses : undefined,
|
|
104
112
|
spellsOffList: (() => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NativeToolRegistry } from '../native-tool-registry.service';
|
|
2
|
+
import { NativeToolDefinition } from '../native-tool.types';
|
|
2
3
|
import { dnd5eTools } from './dnd5e';
|
|
3
|
-
import { actsTools } from './acts';
|
|
4
4
|
export declare function installToolPacks(registry: NativeToolRegistry): string[];
|
|
5
5
|
export declare function registerToolPacks(registry: NativeToolRegistry, packList: string | undefined): string[];
|
|
6
|
+
export declare function registerPack(registry: NativeToolRegistry, name: string, tools: NativeToolDefinition[]): string[];
|
|
6
7
|
export declare function availableToolPacks(): string[];
|
|
7
|
-
export { dnd5eTools
|
|
8
|
+
export { dnd5eTools };
|