briyah 1.3.5 → 1.4.0
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 +689 -684
- package/data/common/artifacts/dnd5e/campaign_designer-setting.md +112 -0
- package/data/common/artifacts/dnd5e/character_creator-basics.md +40 -0
- package/data/common/artifacts/dnd5e/class-barbarian.md +64 -0
- package/data/common/artifacts/dnd5e/class-bard.md +63 -0
- package/data/common/artifacts/dnd5e/class-cleric.md +60 -0
- package/data/common/artifacts/dnd5e/class-druid.md +56 -0
- package/data/common/artifacts/dnd5e/class-fighter.md +53 -0
- package/data/common/artifacts/dnd5e/class-monk.md +77 -0
- package/data/common/artifacts/dnd5e/class-paladin.md +66 -0
- package/data/common/artifacts/dnd5e/class-ranger.md +73 -0
- package/data/common/artifacts/dnd5e/class-rogue.md +62 -0
- package/data/common/artifacts/dnd5e/class-sorcerer.md +67 -0
- package/data/common/artifacts/dnd5e/class-warlock.md +83 -0
- package/data/common/artifacts/dnd5e/class-wizard.md +51 -0
- package/data/common/artifacts/dnd5e/dungeon_master-procedure.md +348 -0
- package/data/common/artifacts/dnd5e/manifest.json +95 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +1250 -237
- package/data/common/prompts/campaign_designer/defaults_config.json +16 -0
- package/data/common/prompts/campaign_designer/perceive.json +29 -0
- package/data/common/prompts/campaign_designer/perceive.prompt +345 -0
- package/data/common/prompts/campaign_designer/system_instruction.prompt +0 -0
- package/data/common/prompts/character_creator/defaults_config.json +31 -0
- package/data/common/prompts/character_creator/perceive.json +29 -0
- package/data/common/prompts/character_creator/perceive.prompt +621 -0
- package/data/common/prompts/character_creator/system_instruction.prompt +0 -0
- package/data/common/prompts/dnd_player/defaults_config.json +5 -0
- package/data/common/prompts/dnd_player/perceive.json +29 -0
- package/data/common/prompts/dnd_player/perceive.prompt +312 -0
- package/data/common/prompts/dnd_player/system_instruction.prompt +0 -0
- package/data/common/prompts/dnd_room_moderator/defaults_config.json +9 -0
- package/data/common/prompts/dnd_room_moderator/moderate.json +34 -0
- package/data/common/prompts/dnd_room_moderator/moderate.prompt +291 -0
- package/data/common/prompts/dnd_room_moderator/system_instruction.prompt +0 -0
- package/data/common/prompts/dungeon_master/compact_agent.prompt +24 -0
- package/data/common/prompts/dungeon_master/defaults_config.json +29 -0
- package/data/common/prompts/dungeon_master/perceive.json +33 -0
- package/data/common/prompts/dungeon_master/perceive.prompt +757 -0
- package/data/common/prompts/dungeon_master/system_instruction.prompt +0 -0
- package/data/common/prompts/room_moderator/moderate.json +34 -29
- package/data/common/prompts/room_moderator/moderate.prompt +230 -210
- package/data/common/prompts/story_moderator/moderate.prompt +5 -2
- package/data/common/prompts/story_moderator/moderate_to_alice.mock +6 -6
- package/data/common/prompts/story_moderator/moderate_to_bob.mock +6 -6
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +34 -22
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +1 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +4 -1
- package/dist-sdk/server/src/ai/agent-config.d.ts +1 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +6 -4
- package/dist-sdk/server/src/ai/agent.d.ts +7 -0
- package/dist-sdk/server/src/ai/agent.js +33 -2
- package/dist-sdk/server/src/ai/artifact.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/artifact.service.js +29 -1
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +7 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +155 -0
- package/dist-sdk/server/src/app/stripe.controller.js +5 -0
- package/dist-sdk/server/src/app.controller.d.ts +18 -18
- package/dist-sdk/server/src/app.controller.js +249 -25
- package/dist-sdk/server/src/app.service.d.ts +30 -17
- package/dist-sdk/server/src/app.service.js +303 -35
- package/dist-sdk/server/src/auth/auth.controller.js +3 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +1 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +5 -1
- package/dist-sdk/server/src/auth/twilio.service.js +5 -3
- package/dist-sdk/server/src/config/user-paths.service.d.ts +2 -0
- package/dist-sdk/server/src/config/user-paths.service.js +8 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +10 -2
- package/dist-sdk/server/src/room/artifact.d.ts +1 -0
- package/dist-sdk/server/src/room/message.d.ts +2 -1
- package/dist-sdk/server/src/room/message.js +5 -4
- package/dist-sdk/server/src/room/room-config.d.ts +3 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +4 -2
- package/dist-sdk/server/src/room/room-store.service.js +46 -12
- package/dist-sdk/server/src/room/room.d.ts +29 -3
- package/dist-sdk/server/src/room/room.js +390 -122
- package/dist-sdk/server/src/sdk/briyah.js +12 -0
- package/dist-sdk/server/src/sdk/index.d.ts +4 -1
- package/dist-sdk/server/src/sdk/index.js +9 -1
- package/dist-sdk/server/src/story/story.service.js +10 -12
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +22 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +24 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +154 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +9 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +1824 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +44 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +17293 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +41 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +250 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +16 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +3760 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +12 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +449 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +88 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +109 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +30 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +329 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +9 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +100 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +117 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +1057 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +147 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +263 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +26 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +129 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +22 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +127 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +137 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +26 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +182 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +48 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +344 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +98 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +456 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +123 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +201 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +35 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +323 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +117 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +122 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +157 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +465 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +116 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +234 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +616 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/index.js +45 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +2 -2
- package/dist-sdk/server/src/tools/tool-execution.service.js +7 -6
- package/dist-sdk/shared/types/app.types.d.ts +63 -0
- 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 +51 -15
- package/docs/classes/Briyah.html +14 -14
- package/docs/classes/BriyahConfigService.html +5 -5
- package/docs/classes/NativeToolRegistry.html +21 -0
- package/docs/classes/Room.html +79 -29
- package/docs/classes/RoomMessage.html +32 -15
- package/docs/enums/MessageAction.html +3 -3
- package/docs/functions/availableToolPacks.html +2 -0
- package/docs/functions/dnd5eTools.html +5 -0
- package/docs/functions/enabledToolPacks.html +2 -0
- package/docs/functions/registerToolPacks.html +6 -0
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +3 -3
- package/docs/interfaces/AgentInfo.html +17 -2
- package/docs/interfaces/AgentMessagesResponse.html +2 -2
- package/docs/interfaces/AppService.html +230 -181
- package/docs/interfaces/Artifact.html +15 -3
- package/docs/interfaces/ArtifactMetadata.html +5 -2
- package/docs/interfaces/ArtifactWriteOptions.html +21 -0
- package/docs/interfaces/AttachDocumentResponse.html +2 -2
- package/docs/interfaces/BriyahConfigOptions.html +9 -9
- package/docs/interfaces/ChapterInfo.html +2 -2
- package/docs/interfaces/Character.html +2 -2
- package/docs/interfaces/CreateAgentResponse.html +2 -2
- package/docs/interfaces/CreateRoomResponse.html +2 -2
- package/docs/interfaces/CreateStoryResponse.html +2 -2
- package/docs/interfaces/FileList.html +2 -2
- package/docs/interfaces/FileMetadata.html +3 -3
- package/docs/interfaces/IConfigService.html +3 -3
- package/docs/interfaces/LoggingOptions.html +6 -6
- package/docs/interfaces/Message.html +2 -2
- package/docs/interfaces/ModelInfo.html +2 -2
- package/docs/interfaces/NativeToolDefinition.html +11 -7
- package/docs/interfaces/PreparedPromptResponse.html +2 -2
- package/docs/interfaces/ProcessTextResponse.html +2 -2
- package/docs/interfaces/PromptFile.html +2 -2
- package/docs/interfaces/PromptFileContent.html +2 -2
- package/docs/interfaces/PromptFilesResponse.html +2 -2
- package/docs/interfaces/PromptFolder.html +2 -2
- package/docs/interfaces/PromptFoldersResponse.html +2 -2
- package/docs/interfaces/RoomDetails.html +15 -2
- package/docs/interfaces/RoomInfo.html +3 -2
- package/docs/interfaces/RoomMessageUpdate.html +2 -2
- package/docs/interfaces/RoomMessagesResponse.html +2 -2
- package/docs/interfaces/SendMessageResult.html +2 -2
- package/docs/interfaces/StoryErrorEvent.html +3 -3
- package/docs/interfaces/StoryIdea.html +2 -2
- package/docs/interfaces/StoryInfo.html +3 -3
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +3 -3
- package/docs/interfaces/StoryProgressChapterEvent.html +3 -3
- package/docs/interfaces/StoryState.html +5 -5
- package/docs/interfaces/StoryStateEvent.html +3 -3
- package/docs/interfaces/ToolArtifact.html +8 -0
- package/docs/interfaces/ToolCaller.html +8 -0
- package/docs/interfaces/ToolDefinition.html +2 -2
- package/docs/interfaces/ToolHelpers.html +7 -3
- package/docs/interfaces/ToolParameter.html +2 -2
- package/docs/interfaces/ToolRoomAccess.html +51 -0
- package/docs/interfaces/ToolSummary.html +3 -2
- package/docs/interfaces/ToolsResponse.html +2 -2
- package/docs/interfaces/Transaction.html +2 -2
- package/docs/interfaces/TransactionHistoryResponse.html +2 -2
- package/docs/modules.html +1 -1
- package/docs/types/PromptScope.html +1 -1
- package/docs/types/ToolContext.html +2 -2
- package/docs/types/ToolRunResult.html +1 -1
- package/package.json +6 -4
- package/dist-sdk/server/src/ai/LLM/base-ai.service.spec.d.ts +0 -1
- package/dist-sdk/server/src/ai/LLM/base-ai.service.spec.js +0 -89
- package/dist-sdk/server/src/ai/LLM/comfyui-client.spec.d.ts +0 -1
- package/dist-sdk/server/src/ai/LLM/comfyui-client.spec.js +0 -143
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.spec.d.ts +0 -1
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.spec.js +0 -207
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.patchSheetTool = exports.readSheetTool = exports.createSheetTool = void 0;
|
|
37
|
+
const coerce_1 = require("../engine/coerce");
|
|
38
|
+
const character_1 = require("../engine/character");
|
|
39
|
+
const rules = __importStar(require("../engine/rules"));
|
|
40
|
+
const races_1 = require("../engine/races");
|
|
41
|
+
const backgrounds_1 = require("../engine/backgrounds");
|
|
42
|
+
const encumbrance_1 = require("../engine/encumbrance");
|
|
43
|
+
const feats_1 = require("../engine/feats");
|
|
44
|
+
const spells_1 = require("../engine/spells");
|
|
45
|
+
const srd_1 = require("../data/srd");
|
|
46
|
+
const sheet_1 = require("../engine/sheet");
|
|
47
|
+
const shared_1 = require("./shared");
|
|
48
|
+
const SPEC_EXAMPLE = '{"class":"Ranger","subclass":"Hunter","level":3,"race":"Wood Elf","background":"Outlander","alignment":"NG","abilities":{"str":10,"dex":16,"con":14,"int":11,"wis":15,"cha":9},"skills":["perception","stealth","survival"],"equipment":["studded leather","longbow","arrows x40"],"attacks":[{"n":"Longbow","atk":5,"dmg":"1d8+3","type":"piercing"}],"spells":["hunter\'s mark"],"backstory":"Raised by the Emberwood circle."}';
|
|
49
|
+
const SET_EXAMPLE = '{"ac":18,"hp.max":32,"speed":25,"resist":["fire"],"uses.channel_divinity.cur":0}';
|
|
50
|
+
exports.createSheetTool = {
|
|
51
|
+
name: 'create_sheet',
|
|
52
|
+
description: 'Create a character sheet. "character" is the character\'s name. "spec" is a JSON object describing them; only the class is genuinely required and everything else is derived or defaulted. Hit points, armour class, proficiency bonus, saving throws, skill modifiers, spell slots and hit dice are all computed from the 5e rules, so do not work them out yourself. Include a "backstory" string to seed the sheet\'s notes section, which later tool calls never overwrite. "owner" is the nickname of the agent who plays this character — set it, because the sheet is made readable to that agent alone, and because it is how the rest of the table is told who they are: the owning agent\'s public description becomes the character\'s name, race and class, replacing whatever placeholder they were created with. Set "replace" to true to overwrite an existing sheet. Example spec: ' +
|
|
53
|
+
SPEC_EXAMPLE,
|
|
54
|
+
parameters: [
|
|
55
|
+
{ name: 'character', type: 'string', description: "The character's name", required: true },
|
|
56
|
+
{
|
|
57
|
+
name: 'spec',
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: `A JSON object describing the character, e.g. ${SPEC_EXAMPLE}`,
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'owner',
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'Nickname of the agent who plays this character',
|
|
66
|
+
required: false,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'replace',
|
|
70
|
+
type: 'boolean',
|
|
71
|
+
description: 'Overwrite an existing sheet for this character',
|
|
72
|
+
required: false,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
async handler(args, helpers) {
|
|
76
|
+
const room = (0, shared_1.requireRoom)(helpers);
|
|
77
|
+
const name = (0, coerce_1.str)(args.character, 'character');
|
|
78
|
+
if (!name)
|
|
79
|
+
throw new Error('A character needs a name.');
|
|
80
|
+
const spec = (0, coerce_1.jsonObject)(args.spec, 'spec', SPEC_EXAMPLE);
|
|
81
|
+
const owner = args.owner ? (0, coerce_1.str)(args.owner, 'owner') : undefined;
|
|
82
|
+
const state = (0, character_1.buildCharacter)(name, spec, owner);
|
|
83
|
+
const raceResult = (0, character_1.lastRaceResult)();
|
|
84
|
+
const backgroundResult = (0, character_1.lastBackgroundResult)();
|
|
85
|
+
for (const item of state.inv) {
|
|
86
|
+
if (isWorn(item.n))
|
|
87
|
+
item.eq = true;
|
|
88
|
+
}
|
|
89
|
+
(0, character_1.recomputeDerived)(state);
|
|
90
|
+
state.hp.cur = state.hp.max;
|
|
91
|
+
const notes = spec.backstory ? `## Backstory\n${spec.backstory}` : '';
|
|
92
|
+
const artifactName = (0, shared_1.writeNewSheet)(room, state, notes, (0, coerce_1.bool)(args.replace));
|
|
93
|
+
(0, shared_1.refreshPartyStatus)(room);
|
|
94
|
+
const identity = publicIdentity(state);
|
|
95
|
+
const described = state.owner ? room.setDescription(state.owner, identity) : false;
|
|
96
|
+
return {
|
|
97
|
+
created: artifactName,
|
|
98
|
+
headline: (0, shared_1.sheetHeadline)(state),
|
|
99
|
+
owner: state.owner,
|
|
100
|
+
publicIdentity: described ? identity : undefined,
|
|
101
|
+
spellsOffList: (() => {
|
|
102
|
+
const off = (0, spells_1.offListSpells)(state, state.spells || []);
|
|
103
|
+
return off.length > 0
|
|
104
|
+
? off.map((entry) => entry.onLists
|
|
105
|
+
? `${entry.spell} is on the ${entry.onLists.join('/')} list, not this character's`
|
|
106
|
+
: `${entry.spell} is not an SRD spell`)
|
|
107
|
+
: undefined;
|
|
108
|
+
})(),
|
|
109
|
+
background: state.bg
|
|
110
|
+
? {
|
|
111
|
+
applied: backgroundResult.background || state.bg,
|
|
112
|
+
inTheSrd: backgroundResult.known,
|
|
113
|
+
granted: backgroundResult.changes.length > 0 ? backgroundResult.changes : undefined,
|
|
114
|
+
stillToChoose: backgroundResult.outstanding.length > 0
|
|
115
|
+
? backgroundResult.outstanding
|
|
116
|
+
: undefined,
|
|
117
|
+
}
|
|
118
|
+
: undefined,
|
|
119
|
+
race: raceResult.race
|
|
120
|
+
? {
|
|
121
|
+
applied: raceResult.subrace
|
|
122
|
+
? `${raceResult.subrace} ${raceResult.race}`
|
|
123
|
+
: raceResult.race,
|
|
124
|
+
abilityIncreases: Object.entries(raceResult.increases)
|
|
125
|
+
.map(([ability, amount]) => `${ability.toUpperCase()} +${amount}`)
|
|
126
|
+
.join(', ') || undefined,
|
|
127
|
+
stillToChoose: raceResult.outstanding.length > 0 ? raceResult.outstanding : undefined,
|
|
128
|
+
}
|
|
129
|
+
: undefined,
|
|
130
|
+
raceProblems: raceResult.problems.length > 0 ? raceResult.problems : undefined,
|
|
131
|
+
derived: {
|
|
132
|
+
hitPoints: `${state.hp.cur}/${state.hp.max}`,
|
|
133
|
+
armorClass: `${state.ac} (${rules.computeArmorClass(state).explanation})`,
|
|
134
|
+
proficiencyBonus: (0, sheet_1.signed)(rules.proficiencyBonus(state)),
|
|
135
|
+
initiative: (0, sheet_1.signed)(state.initBonus),
|
|
136
|
+
passivePerception: rules.passivePerception(state),
|
|
137
|
+
spellSaveDc: rules.spellSaveDc(state) || undefined,
|
|
138
|
+
hitDice: Object.entries(state.hd)
|
|
139
|
+
.map(([die, pool]) => `${pool.max}${die}`)
|
|
140
|
+
.join(', '),
|
|
141
|
+
spellSlots: Object.entries(state.slots)
|
|
142
|
+
.map(([level, pool]) => `L${level} x${pool.max}`)
|
|
143
|
+
.join(', ') || 'none',
|
|
144
|
+
},
|
|
145
|
+
note: `The sheet is readable by ${state.owner || 'its creator'} only. Read it back with read_sheet rather than making it visible to everyone.`,
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
function publicIdentity(state) {
|
|
150
|
+
const classes = state.class
|
|
151
|
+
.map((entry) => {
|
|
152
|
+
const className = srd_1.CLASSES[entry.c]?.name || entry.c;
|
|
153
|
+
return entry.sub ? `${className} (${entry.sub})` : className;
|
|
154
|
+
})
|
|
155
|
+
.join('/');
|
|
156
|
+
const descriptors = [state.race, classes].filter(Boolean).join(' ');
|
|
157
|
+
return descriptors ? `${state.name} — ${descriptors}` : state.name;
|
|
158
|
+
}
|
|
159
|
+
function isWorn(itemName) {
|
|
160
|
+
const key = itemName.toLowerCase();
|
|
161
|
+
return /\bshield\b/.test(key) || srd_1.ARMOR[key] !== undefined;
|
|
162
|
+
}
|
|
163
|
+
exports.readSheetTool = {
|
|
164
|
+
name: 'read_sheet',
|
|
165
|
+
description: 'Read a character sheet. "character" is a name, or "party" for a one-line summary of everyone. "section" narrows the answer to combat, abilities, skills, spells, inventory, conditions, race, feats, background, or carrying; the default returns the whole sheet. Narrow it when you only need one thing — short answers keep the conversation fast and cheap.',
|
|
166
|
+
parameters: [
|
|
167
|
+
{
|
|
168
|
+
name: 'character',
|
|
169
|
+
type: 'string',
|
|
170
|
+
description: 'A character name, or "party" for everyone',
|
|
171
|
+
required: true,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'section',
|
|
175
|
+
type: 'string',
|
|
176
|
+
description: 'combat, abilities, skills, spells, inventory, conditions, or all',
|
|
177
|
+
required: false,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
async handler(args, helpers) {
|
|
181
|
+
const room = (0, shared_1.requireRoom)(helpers);
|
|
182
|
+
const who = (0, coerce_1.str)(args.character, 'character');
|
|
183
|
+
const section = (0, coerce_1.str)(args.section, 'section', 'all').toLowerCase();
|
|
184
|
+
if (who.toLowerCase() === 'party' || who.toLowerCase() === 'all') {
|
|
185
|
+
const names = (0, shared_1.listCharacterNames)(room);
|
|
186
|
+
const lines = [];
|
|
187
|
+
for (const name of names) {
|
|
188
|
+
const artifact = room.get((0, sheet_1.sheetArtifactName)(name));
|
|
189
|
+
if (!artifact)
|
|
190
|
+
continue;
|
|
191
|
+
try {
|
|
192
|
+
lines.push((0, shared_1.partyLine)((0, sheet_1.parseSheet)(artifact.body)));
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
lines.push(`- ${name}: sheet unreadable (${e.message})`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { party: lines, count: lines.length };
|
|
199
|
+
}
|
|
200
|
+
const sheet = (0, shared_1.loadSheet)(room, who);
|
|
201
|
+
const state = sheet.state;
|
|
202
|
+
const result = {
|
|
203
|
+
character: state.name,
|
|
204
|
+
headline: (0, shared_1.sheetHeadline)(state),
|
|
205
|
+
};
|
|
206
|
+
if (sheet.warnings.length > 0)
|
|
207
|
+
result.warnings = sheet.warnings;
|
|
208
|
+
const wants = (name) => section === 'all' || section === name;
|
|
209
|
+
if (wants('feats') && (0, feats_1.takenFeats)(state).length > 0) {
|
|
210
|
+
result.feats = (0, feats_1.takenFeats)(state).map((name) => {
|
|
211
|
+
const { feat } = (0, feats_1.resolveFeat)(name);
|
|
212
|
+
return feat ? (0, feats_1.describeFeat)(feat) : `${name} (not an SRD feat)`;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (wants('carrying')) {
|
|
216
|
+
const load = (0, encumbrance_1.encumbrance)(state);
|
|
217
|
+
result.carrying = {
|
|
218
|
+
pounds: load.carried.pounds,
|
|
219
|
+
capacity: load.capacity.capacity,
|
|
220
|
+
pushDragLift: load.capacity.pushDragLift,
|
|
221
|
+
tier: load.tier,
|
|
222
|
+
variantInUse: load.variant,
|
|
223
|
+
unweighed: load.carried.unweighed.length > 0 ? load.carried.unweighed : undefined,
|
|
224
|
+
thresholds: load.variant
|
|
225
|
+
? {
|
|
226
|
+
encumberedAbove: load.capacity.encumberedAt,
|
|
227
|
+
heavilyEncumberedAbove: load.capacity.heavilyEncumberedAt,
|
|
228
|
+
}
|
|
229
|
+
: undefined,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (wants('background') && state.bg) {
|
|
233
|
+
const feature = (0, backgrounds_1.backgroundFeature)(state);
|
|
234
|
+
result.background = {
|
|
235
|
+
name: state.bg,
|
|
236
|
+
feature: feature ? `${feature.n}. ${feature.text}` : undefined,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (wants('race') && state.race) {
|
|
240
|
+
const traits = (0, races_1.racialTraits)(state);
|
|
241
|
+
result.race = {
|
|
242
|
+
name: state.race,
|
|
243
|
+
size: state.size,
|
|
244
|
+
speed: `${rules.effectiveSpeed(state).speed} ft`,
|
|
245
|
+
darkvision: state.darkvision ? `${state.darkvision} ft` : undefined,
|
|
246
|
+
languages: state.languages,
|
|
247
|
+
traits: traits.map((trait) => `${trait.n}. ${trait.text}`),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (wants('combat')) {
|
|
251
|
+
result.combat = {
|
|
252
|
+
hitPoints: `${state.hp.cur}/${state.hp.max}`,
|
|
253
|
+
temporaryHitPoints: state.hp.temp || undefined,
|
|
254
|
+
armorClass: state.ac,
|
|
255
|
+
initiative: (0, sheet_1.signed)(state.initBonus),
|
|
256
|
+
speed: `${state.speed} ft`,
|
|
257
|
+
attacks: state.attacks.map((a) => `${a.n} ${(0, sheet_1.signed)(a.atk)} (${a.dmg}${a.type ? ` ${a.type}` : ''})`),
|
|
258
|
+
hitDice: Object.entries(state.hd).map(([die, pool]) => `${pool.cur}/${pool.max} ${die}`),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (wants('abilities')) {
|
|
262
|
+
result.abilities = Object.fromEntries(srd_1.ABILITIES.map((a) => [
|
|
263
|
+
a,
|
|
264
|
+
`${state.abil[a]} (${(0, sheet_1.signed)(rules.abilityModifier(state, a))}), save ${(0, sheet_1.signed)(rules.saveModifier(state, a))}`,
|
|
265
|
+
]));
|
|
266
|
+
}
|
|
267
|
+
if (wants('skills')) {
|
|
268
|
+
result.skills = Object.fromEntries(rules
|
|
269
|
+
.skillNames()
|
|
270
|
+
.map((skill) => [(0, sheet_1.titleCase)(skill), (0, sheet_1.signed)(rules.skillModifier(state, skill))]));
|
|
271
|
+
result.passivePerception = rules.passivePerception(state);
|
|
272
|
+
}
|
|
273
|
+
if (wants('spells')) {
|
|
274
|
+
result.spells = {
|
|
275
|
+
known: (state.spells || []).map(spells_1.summariseSpell),
|
|
276
|
+
saveDc: rules.spellSaveDc(state) || undefined,
|
|
277
|
+
attackBonus: rules.spellSaveDc(state) ? (0, sheet_1.signed)(rules.spellAttackBonus(state)) : undefined,
|
|
278
|
+
slots: Object.fromEntries(Object.entries(state.slots).map(([level, pool]) => [level, `${pool.cur}/${pool.max}`])),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (wants('inventory')) {
|
|
282
|
+
result.inventory = state.inv.map((item) => {
|
|
283
|
+
const parts = [item.n];
|
|
284
|
+
if (item.q > 1)
|
|
285
|
+
parts.push(`x${item.q}`);
|
|
286
|
+
if (item.chg !== undefined)
|
|
287
|
+
parts.push(`(${item.chg} uses)`);
|
|
288
|
+
if (item.eq)
|
|
289
|
+
parts.push('(equipped)');
|
|
290
|
+
return parts.join(' ');
|
|
291
|
+
});
|
|
292
|
+
result.coin = state.coin;
|
|
293
|
+
}
|
|
294
|
+
if (wants('conditions')) {
|
|
295
|
+
result.conditions = state.cond.map((c) => ({
|
|
296
|
+
name: c.n,
|
|
297
|
+
duration: c.dur,
|
|
298
|
+
effect: srd_1.CONDITIONS[c.n] || 'Not a standard condition; adjudicate as described.',
|
|
299
|
+
}));
|
|
300
|
+
result.exhaustion = {
|
|
301
|
+
level: state.exh,
|
|
302
|
+
effect: srd_1.EXHAUSTION_EFFECTS[state.exh] || srd_1.EXHAUSTION_EFFECTS[0],
|
|
303
|
+
};
|
|
304
|
+
if (state.hp.cur === 0) {
|
|
305
|
+
result.dying = {
|
|
306
|
+
stable: state.stable,
|
|
307
|
+
deathSaves: `${state.deathSaves.s} success / ${state.deathSaves.f} failure`,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (section !== 'all' && !Object.keys(result).some((k) => k === section)) {
|
|
312
|
+
result.note = `"${section}" is not a section. Use combat, abilities, skills, spells, inventory, conditions, race, feats, background, carrying, or all.`;
|
|
313
|
+
}
|
|
314
|
+
return result;
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
exports.patchSheetTool = {
|
|
318
|
+
name: 'patch_sheet',
|
|
319
|
+
description: 'Set fields on a character sheet directly, for anything the other tools do not cover. "set" is a JSON object of dotted paths to values applied to the sheet\'s underlying state, for example ' +
|
|
320
|
+
SET_EXAMPLE +
|
|
321
|
+
'. "append" adds entries to a list field, e.g. {"attacks":[{"n":"Dagger","atk":5,"dmg":"1d4+3","type":"piercing"}]}. "note" appends a line to the character\'s notes, which no other tool overwrites. Set "recompute" to true to recalculate hit points, armour class, initiative and spell slots after the change — do that after altering abilities, level, or equipment. A change that would leave the sheet inconsistent is refused with an explanation. Prefer a specific tool when one exists: this one does no rules reasoning for you.',
|
|
322
|
+
parameters: [
|
|
323
|
+
{ name: 'character', type: 'string', description: 'Whose sheet to change', required: true },
|
|
324
|
+
{
|
|
325
|
+
name: 'set',
|
|
326
|
+
type: 'string',
|
|
327
|
+
description: `A JSON object of dotted paths to values, e.g. ${SET_EXAMPLE}`,
|
|
328
|
+
required: false,
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
name: 'append',
|
|
332
|
+
type: 'string',
|
|
333
|
+
description: 'A JSON object of list fields to append to, e.g. {"resist":["cold"]}',
|
|
334
|
+
required: false,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: 'note',
|
|
338
|
+
type: 'string',
|
|
339
|
+
description: "A line to append to the character's notes",
|
|
340
|
+
required: false,
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: 'recompute',
|
|
344
|
+
type: 'boolean',
|
|
345
|
+
description: 'Recalculate hit points, armour class, initiative and spell slots after the change',
|
|
346
|
+
required: false,
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
async handler(args, helpers) {
|
|
350
|
+
const room = (0, shared_1.requireRoom)(helpers);
|
|
351
|
+
const character = (0, coerce_1.str)(args.character, 'character');
|
|
352
|
+
const set = (0, coerce_1.jsonObject)(args.set, 'set', SET_EXAMPLE);
|
|
353
|
+
const append = (0, coerce_1.jsonObject)(args.append, 'append', '{"resist":["cold"]}');
|
|
354
|
+
const note = args.note ? (0, coerce_1.str)(args.note, 'note') : '';
|
|
355
|
+
const recompute = (0, coerce_1.bool)(args.recompute);
|
|
356
|
+
if (Object.keys(set).length === 0 && Object.keys(append).length === 0 && !note) {
|
|
357
|
+
throw new Error(`Nothing to change. Give "set", "append", or "note". Example set: ${SET_EXAMPLE}`);
|
|
358
|
+
}
|
|
359
|
+
const sheet = (0, shared_1.loadSheet)(room, character);
|
|
360
|
+
const candidate = (0, character_1.cloneState)(sheet.state);
|
|
361
|
+
const applied = [];
|
|
362
|
+
for (const [path, value] of Object.entries(set)) {
|
|
363
|
+
setPath(candidate, path, value);
|
|
364
|
+
applied.push(`${path} = ${JSON.stringify(value)}`);
|
|
365
|
+
}
|
|
366
|
+
for (const [path, value] of Object.entries(append)) {
|
|
367
|
+
const target = getPath(candidate, path);
|
|
368
|
+
if (!Array.isArray(target)) {
|
|
369
|
+
throw new Error(`"${path}" is not a list on this sheet, so nothing can be appended to it.`);
|
|
370
|
+
}
|
|
371
|
+
const additions = Array.isArray(value) ? value : [value];
|
|
372
|
+
target.push(...additions);
|
|
373
|
+
applied.push(`appended ${additions.length} to ${path}`);
|
|
374
|
+
}
|
|
375
|
+
if (recompute) {
|
|
376
|
+
(0, character_1.recomputeDerived)(candidate);
|
|
377
|
+
applied.push('recomputed hit points, armour class, initiative and spell slots');
|
|
378
|
+
}
|
|
379
|
+
const problem = validate(candidate);
|
|
380
|
+
if (problem) {
|
|
381
|
+
return {
|
|
382
|
+
applied: false,
|
|
383
|
+
violation: 'inconsistent_sheet',
|
|
384
|
+
message: problem,
|
|
385
|
+
options: [
|
|
386
|
+
'Correct the value and try again',
|
|
387
|
+
'Set the dependent field in the same call',
|
|
388
|
+
'Pass recompute=true to let the rules recalculate derived values',
|
|
389
|
+
],
|
|
390
|
+
state: (0, shared_1.liveState)(sheet.state),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
candidate.rev = (sheet.state.rev || 0) + 1;
|
|
394
|
+
const notes = note ? [sheet.notes, `- ${note}`].filter(Boolean).join('\n') : sheet.notes;
|
|
395
|
+
room.update(sheet.artifactName, () => (0, sheet_1.renderSheet)(candidate, notes), {
|
|
396
|
+
viewers: [candidate.owner || room.caller.nickname],
|
|
397
|
+
});
|
|
398
|
+
(0, shared_1.refreshPartyStatus)(room);
|
|
399
|
+
return {
|
|
400
|
+
applied: true,
|
|
401
|
+
character: candidate.name,
|
|
402
|
+
changes: applied,
|
|
403
|
+
headline: (0, shared_1.sheetHeadline)(candidate),
|
|
404
|
+
state: (0, shared_1.liveState)(candidate),
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
function getPath(state, path) {
|
|
409
|
+
return path.split('.').reduce((node, key) => (node === undefined ? undefined : node[key]), state);
|
|
410
|
+
}
|
|
411
|
+
function setPath(state, path, value) {
|
|
412
|
+
const keys = path.split('.');
|
|
413
|
+
let node = state;
|
|
414
|
+
for (const key of keys.slice(0, -1)) {
|
|
415
|
+
if (node[key] === undefined || node[key] === null || typeof node[key] !== 'object') {
|
|
416
|
+
node[key] = {};
|
|
417
|
+
}
|
|
418
|
+
node = node[key];
|
|
419
|
+
}
|
|
420
|
+
node[keys[keys.length - 1]] = value;
|
|
421
|
+
}
|
|
422
|
+
function validate(state) {
|
|
423
|
+
if (!Number.isFinite(state.hp.max) || state.hp.max < 1) {
|
|
424
|
+
return `Hit point maximum must be at least 1, but would be ${state.hp.max}.`;
|
|
425
|
+
}
|
|
426
|
+
if (!Number.isFinite(state.hp.cur) || state.hp.cur < 0) {
|
|
427
|
+
return `Current hit points cannot be negative, but would be ${state.hp.cur}.`;
|
|
428
|
+
}
|
|
429
|
+
if (state.hp.cur > state.hp.max) {
|
|
430
|
+
return `Current hit points (${state.hp.cur}) cannot exceed the maximum (${state.hp.max}). Set hp.max in the same call if the maximum is meant to rise.`;
|
|
431
|
+
}
|
|
432
|
+
if (state.hp.temp < 0) {
|
|
433
|
+
return `Temporary hit points cannot be negative, but would be ${state.hp.temp}.`;
|
|
434
|
+
}
|
|
435
|
+
if (state.exh < 0 || state.exh > srd_1.EXHAUSTION_EFFECTS.length - 1) {
|
|
436
|
+
return `Exhaustion must be between 0 and ${srd_1.EXHAUSTION_EFFECTS.length - 1}, but would be ${state.exh}.`;
|
|
437
|
+
}
|
|
438
|
+
for (const ability of srd_1.ABILITIES) {
|
|
439
|
+
const score = state.abil[ability];
|
|
440
|
+
if (!Number.isFinite(score) || score < 1 || score > 30) {
|
|
441
|
+
return `${ability.toUpperCase()} must be between 1 and 30, but would be ${score}.`;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
for (const [level, pool] of Object.entries(state.slots)) {
|
|
445
|
+
if (pool.cur < 0)
|
|
446
|
+
return `Level ${level} spell slots cannot be negative.`;
|
|
447
|
+
if (pool.cur > pool.max) {
|
|
448
|
+
return `Level ${level} spell slots remaining (${pool.cur}) cannot exceed the maximum (${pool.max}).`;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
for (const [die, pool] of Object.entries(state.hd)) {
|
|
452
|
+
if (pool.cur < 0 || pool.cur > pool.max) {
|
|
453
|
+
return `${die} hit dice remaining (${pool.cur}) must be between 0 and ${pool.max}.`;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
for (const entry of state.class) {
|
|
457
|
+
if (!srd_1.CLASSES[entry.c]) {
|
|
458
|
+
return `"${entry.c}" is not a class in the SRD. Known classes: ${Object.keys(srd_1.CLASSES).join(', ')}.`;
|
|
459
|
+
}
|
|
460
|
+
if (!Number.isFinite(entry.lvl) || entry.lvl < 1 || entry.lvl > 20) {
|
|
461
|
+
return `Class level must be between 1 and 20, but ${entry.c} would be ${entry.lvl}.`;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spellTool = void 0;
|
|
4
|
+
const coerce_1 = require("../engine/coerce");
|
|
5
|
+
const srd_1 = require("../data/srd");
|
|
6
|
+
const spells_1 = require("../engine/spells");
|
|
7
|
+
exports.spellTool = {
|
|
8
|
+
name: 'spell',
|
|
9
|
+
description: 'Get what a spell does, or list what a class can cast. Reading: give "spell" a name and you get its level, school, casting time, range, components, duration, whether it needs concentration or can be cast as a ritual, which classes have it, its full text, and its "At Higher Levels" clause if it has one. Use the full name: a partial name that matches several spells comes back asking which one you meant. Listing: set "spell" to "list" and narrow with "for_class" (bard, cleric, druid, paladin, ranger, sorcerer, warlock, wizard) and "level" (0 for cantrips, 1 to 9) — "what second-level spells can a cleric take" is for_class = cleric, level = 2. "search" narrows a listing by name. There are 319 spells, so a listing without a class or a level will be capped.',
|
|
10
|
+
parameters: [
|
|
11
|
+
{
|
|
12
|
+
name: 'spell',
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: 'The spell to look up, or "list" to see what is available',
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'for_class',
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'With spell = "list", show only spells on this class\'s list',
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'level',
|
|
25
|
+
type: 'number',
|
|
26
|
+
description: 'With spell = "list", show only spells of this level; 0 for cantrips',
|
|
27
|
+
required: false,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'search',
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'With spell = "list", show only names containing this text',
|
|
33
|
+
required: false,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
async handler(args) {
|
|
37
|
+
const wanted = (0, coerce_1.str)(args.spell, 'spell');
|
|
38
|
+
if (!wanted)
|
|
39
|
+
throw new Error('Name a spell, or "list" to see what is available.');
|
|
40
|
+
if (['list', 'all', 'names'].includes(wanted.toLowerCase())) {
|
|
41
|
+
return list(args);
|
|
42
|
+
}
|
|
43
|
+
const resolved = (0, spells_1.resolveSpell)(wanted);
|
|
44
|
+
if (resolved.ambiguous) {
|
|
45
|
+
return {
|
|
46
|
+
found: false,
|
|
47
|
+
spell: wanted,
|
|
48
|
+
ambiguous: resolved.ambiguous,
|
|
49
|
+
message: `"${wanted}" matches ${resolved.ambiguous.length} spells. Ask again with the full name.`,
|
|
50
|
+
note: 'Do not pick one at random and do not invent what it does.',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (!resolved.spell) {
|
|
54
|
+
const suggestions = (0, spells_1.nearSpells)(wanted);
|
|
55
|
+
return {
|
|
56
|
+
found: false,
|
|
57
|
+
spell: wanted,
|
|
58
|
+
message: `No spell called "${wanted}" in the System Reference Document.`,
|
|
59
|
+
didYouMean: suggestions.length > 0 ? suggestions : undefined,
|
|
60
|
+
options: [
|
|
61
|
+
'List what a class can cast with spell: "list" and for_class',
|
|
62
|
+
'If this is a spell particular to the campaign, its description belongs in the Campaign document',
|
|
63
|
+
],
|
|
64
|
+
note: 'Do not invent what a spell does. A player who has been told the wrong effect has been told it for good.',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
found: true,
|
|
69
|
+
spell: resolved.spell.name,
|
|
70
|
+
details: compact(resolved.spell),
|
|
71
|
+
entry: (0, spells_1.describeSpell)(resolved.spell),
|
|
72
|
+
attribution: srd_1.SRD_ATTRIBUTION,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
function list(args) {
|
|
77
|
+
const forClass = args.for_class ? (0, coerce_1.str)(args.for_class, 'for_class').toLowerCase() : undefined;
|
|
78
|
+
if (forClass && !srd_1.CLASSES[forClass]) {
|
|
79
|
+
throw new Error(`"${forClass}" is not a class. Use one of: ${Object.keys(srd_1.CLASSES).join(', ')}.`);
|
|
80
|
+
}
|
|
81
|
+
const level = args.level !== undefined && args.level !== '' && args.level !== null
|
|
82
|
+
? (0, coerce_1.int)(args.level, 'level')
|
|
83
|
+
: undefined;
|
|
84
|
+
if (level !== undefined && (level < 0 || level > 9)) {
|
|
85
|
+
throw new Error('A spell level is 0 for a cantrip, or 1 to 9.');
|
|
86
|
+
}
|
|
87
|
+
const search = args.search ? (0, coerce_1.str)(args.search, 'search') : undefined;
|
|
88
|
+
const available = (0, spells_1.availableSpells)(forClass, level, search);
|
|
89
|
+
return {
|
|
90
|
+
spells: available.spells,
|
|
91
|
+
total: available.total,
|
|
92
|
+
forClass: available.forClass,
|
|
93
|
+
level: available.level !== undefined ? (0, spells_1.spellLevelName)(available.level) : undefined,
|
|
94
|
+
search,
|
|
95
|
+
truncated: available.truncated,
|
|
96
|
+
note: available.truncated
|
|
97
|
+
? 'Only the first names are shown. Narrow with "for_class" and "level" — those two together almost always fit.'
|
|
98
|
+
: forClass
|
|
99
|
+
? undefined
|
|
100
|
+
: 'Pass "for_class" to see only what one class can cast.',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function compact(spell) {
|
|
104
|
+
return {
|
|
105
|
+
level: spell.level === 0 ? 'cantrip' : spell.level,
|
|
106
|
+
school: spell.school,
|
|
107
|
+
castingTime: spell.castingTime,
|
|
108
|
+
range: spell.range,
|
|
109
|
+
components: spell.components,
|
|
110
|
+
duration: spell.duration,
|
|
111
|
+
concentration: spell.concentration,
|
|
112
|
+
ritual: spell.ritual,
|
|
113
|
+
classes: spell.classes,
|
|
114
|
+
higherLevels: spell.higherLevels,
|
|
115
|
+
};
|
|
116
|
+
}
|