briyah 2.0.3 → 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 +55 -8
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/config/story_models.json +3 -3
- package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- 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.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
- 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/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
- package/dist-sdk/server/src/ai/agent.d.ts +197 -2
- package/dist-sdk/server/src/ai/agent.js +225 -14
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +46 -3
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +120 -0
- package/dist-sdk/server/src/app.controller.js +365 -14
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1710 -4
- package/dist-sdk/server/src/app.service.js +1938 -20
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -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/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +84 -1
- package/dist-sdk/server/src/room/room-config.js +19 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
- package/dist-sdk/server/src/room/room-factory.js +25 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
- package/dist-sdk/server/src/room/room-store.service.js +280 -6
- package/dist-sdk/server/src/room/room.d.ts +981 -1
- package/dist-sdk/server/src/room/room.js +1531 -27
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +366 -9
- package/dist-sdk/server/src/story/story.service.js +825 -374
- 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.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +24 -1
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
- package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +328 -13
- package/dist-sdk/shared/types/app.types.js +18 -1
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argument coercion, re-exported from where it now lives.
|
|
3
|
+
*
|
|
4
|
+
* The implementation moved to `server/src/tools/shared/coerce.ts` when a second
|
|
5
|
+
* pack needed it: nothing in it is about D&D, and every pack has the same problem
|
|
6
|
+
* — tool arguments arrive from `JSON.parse` of text an LLM wrote, with no type
|
|
7
|
+
* checking anywhere in the path.
|
|
8
|
+
*
|
|
9
|
+
* Kept as a re-export rather than removed so this pack's ten importers, and any
|
|
10
|
+
* host reaching in, keep working against one implementation.
|
|
11
|
+
*/
|
|
1
12
|
export * from '../../../shared/coerce';
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Argument coercion, re-exported from where it now lives.
|
|
4
|
+
*
|
|
5
|
+
* The implementation moved to `server/src/tools/shared/coerce.ts` when a second
|
|
6
|
+
* pack needed it: nothing in it is about D&D, and every pack has the same problem
|
|
7
|
+
* — tool arguments arrive from `JSON.parse` of text an LLM wrote, with no type
|
|
8
|
+
* checking anywhere in the path.
|
|
9
|
+
*
|
|
10
|
+
* Kept as a re-export rather than removed so this pack's ten importers, and any
|
|
11
|
+
* host reaching in, keep working against one implementation.
|
|
12
|
+
*/
|
|
2
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
14
|
if (k2 === undefined) k2 = k;
|
|
4
15
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -1,34 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dice expression parsing and rolling. Pure apart from the RNG, which is
|
|
3
|
+
* injectable so tests can be deterministic.
|
|
4
|
+
*
|
|
5
|
+
* Grammar, in the order a term may appear:
|
|
6
|
+
* [label=] NdM [modifiers] [+K|-K ...] [xN]
|
|
7
|
+
* where modifiers are, in any order and any case:
|
|
8
|
+
* kh[N] / kl[N] keep the highest / lowest N dice (default 1)
|
|
9
|
+
* dh[N] / dl[N] drop the highest / lowest N dice (default 1)
|
|
10
|
+
* adv / dis shorthand for 2d20kh1 / 2d20kl1 on a single d20
|
|
11
|
+
* r1 reroll each 1 once, keeping the new value
|
|
12
|
+
* min2 treat any die below 2 as 2 (great weapon fighting)
|
|
13
|
+
* crit double the number of dice (a critical hit's damage)
|
|
14
|
+
*/
|
|
15
|
+
/** Rolls an integer in [1, sides]. */
|
|
1
16
|
export type Rng = (sides: number) => number;
|
|
2
17
|
export declare const defaultRng: Rng;
|
|
18
|
+
/** Hard caps so one call cannot produce an unreadable or oversized result. */
|
|
3
19
|
export declare const MAX_EXPRESSIONS = 20;
|
|
4
20
|
export declare const MAX_DICE_PER_CALL = 100;
|
|
5
21
|
export declare const MAX_REPEAT = 20;
|
|
6
22
|
export interface DieRoll {
|
|
23
|
+
/** The face rolled, after any reroll or minimum was applied. */
|
|
7
24
|
value: number;
|
|
25
|
+
/** The original face, present only when a modifier changed it. */
|
|
8
26
|
original?: number;
|
|
27
|
+
/** True when this die was dropped by a keep/drop modifier. */
|
|
9
28
|
dropped?: boolean;
|
|
10
29
|
}
|
|
11
30
|
export interface RollResult {
|
|
31
|
+
/** The label, or the expression text when unlabelled. */
|
|
12
32
|
label: string;
|
|
33
|
+
/** The expression as parsed, echoed so the caller can confirm intent. */
|
|
13
34
|
expression: string;
|
|
14
35
|
dice: DieRoll[];
|
|
36
|
+
/** The flat modifier applied after the dice. */
|
|
15
37
|
modifier: number;
|
|
16
38
|
total: number;
|
|
39
|
+
/** The faces of the dice that counted, for a d20 test's natural roll. */
|
|
17
40
|
kept: number[];
|
|
41
|
+
/** True when a single kept d20 came up 20, false when 1, absent otherwise. */
|
|
18
42
|
natural20?: boolean;
|
|
19
43
|
natural1?: boolean;
|
|
20
44
|
}
|
|
21
45
|
export declare class DiceError extends Error {
|
|
22
46
|
constructor(message: string);
|
|
23
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Splits a semicolon-separated expression list and rolls each one.
|
|
50
|
+
* @param expressions The raw `expressions` argument
|
|
51
|
+
* @param rng The random source
|
|
52
|
+
* @returns One result per rolled expression, expanded for any `xN` repeat
|
|
53
|
+
* @throws {DiceError} On an unparseable expression or an exceeded cap
|
|
54
|
+
*/
|
|
24
55
|
export declare function rollExpressions(expressions: string, rng?: Rng): RollResult[];
|
|
56
|
+
/**
|
|
57
|
+
* Rolls a single already-parsed expression string.
|
|
58
|
+
* @param expression One expression, e.g. `1d20+5 adv`
|
|
59
|
+
* @param rng The random source
|
|
60
|
+
* @returns The roll result
|
|
61
|
+
*/
|
|
25
62
|
export declare function rollOne(expression: string, rng?: Rng): RollResult;
|
|
63
|
+
/**
|
|
64
|
+
* Rolls a d20 test: one d20 plus a modifier, with advantage or disadvantage.
|
|
65
|
+
* @param modifier The total bonus to add
|
|
66
|
+
* @param mode 'normal', 'advantage' or 'disadvantage'
|
|
67
|
+
* @param rng The random source
|
|
68
|
+
* @returns The roll result
|
|
69
|
+
*/
|
|
26
70
|
export declare function rollD20(modifier: number, mode: 'normal' | 'advantage' | 'disadvantage', rng?: Rng): RollResult;
|
|
71
|
+
/**
|
|
72
|
+
* Renders a roll for a tool result: compact, but showing every die so the DM can
|
|
73
|
+
* narrate and a player can see the roll was real.
|
|
74
|
+
* @param result The roll to describe
|
|
75
|
+
* @returns A one-line summary, e.g. `attack: [17] +5 = 22` or `4d6kh3: [5 4 4 ~2] = 13`
|
|
76
|
+
*/
|
|
77
|
+
/** An attack's damage, rolled and described. */
|
|
27
78
|
export interface DamageRoll {
|
|
79
|
+
/** The expression as rolled, including `crit` when the dice were doubled. */
|
|
28
80
|
expression: string;
|
|
29
81
|
total: number;
|
|
30
82
|
type?: string;
|
|
31
83
|
detail: string;
|
|
32
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Rolls an attack's damage.
|
|
87
|
+
*
|
|
88
|
+
* Here rather than beside the check tool because two tools now need it: `check`
|
|
89
|
+
* rolls damage when an attack lands, and `spend` rolls it when a held die turns a
|
|
90
|
+
* miss into a hit. One implementation means the two cannot disagree about how a
|
|
91
|
+
* critical doubles.
|
|
92
|
+
* @param expression The damage dice, e.g. '1d8+3'
|
|
93
|
+
* @param type The damage type, for the report
|
|
94
|
+
* @param critical Whether to double the dice
|
|
95
|
+
* @param rng The random source
|
|
96
|
+
* @returns The roll, never below zero
|
|
97
|
+
*/
|
|
33
98
|
export declare function rollDamage(expression: string, type: string | undefined, critical: boolean, rng?: Rng): DamageRoll;
|
|
34
99
|
export declare function describeRoll(result: RollResult): string;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Dice expression parsing and rolling. Pure apart from the RNG, which is
|
|
4
|
+
* injectable so tests can be deterministic.
|
|
5
|
+
*
|
|
6
|
+
* Grammar, in the order a term may appear:
|
|
7
|
+
* [label=] NdM [modifiers] [+K|-K ...] [xN]
|
|
8
|
+
* where modifiers are, in any order and any case:
|
|
9
|
+
* kh[N] / kl[N] keep the highest / lowest N dice (default 1)
|
|
10
|
+
* dh[N] / dl[N] drop the highest / lowest N dice (default 1)
|
|
11
|
+
* adv / dis shorthand for 2d20kh1 / 2d20kl1 on a single d20
|
|
12
|
+
* r1 reroll each 1 once, keeping the new value
|
|
13
|
+
* min2 treat any die below 2 as 2 (great weapon fighting)
|
|
14
|
+
* crit double the number of dice (a critical hit's damage)
|
|
15
|
+
*/
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.DiceError = exports.MAX_REPEAT = exports.MAX_DICE_PER_CALL = exports.MAX_EXPRESSIONS = exports.defaultRng = void 0;
|
|
4
18
|
exports.rollExpressions = rollExpressions;
|
|
@@ -8,6 +22,7 @@ exports.rollDamage = rollDamage;
|
|
|
8
22
|
exports.describeRoll = describeRoll;
|
|
9
23
|
const defaultRng = (sides) => Math.floor(Math.random() * sides) + 1;
|
|
10
24
|
exports.defaultRng = defaultRng;
|
|
25
|
+
/** Hard caps so one call cannot produce an unreadable or oversized result. */
|
|
11
26
|
exports.MAX_EXPRESSIONS = 20;
|
|
12
27
|
exports.MAX_DICE_PER_CALL = 100;
|
|
13
28
|
exports.MAX_REPEAT = 20;
|
|
@@ -18,6 +33,13 @@ class DiceError extends Error {
|
|
|
18
33
|
}
|
|
19
34
|
}
|
|
20
35
|
exports.DiceError = DiceError;
|
|
36
|
+
/**
|
|
37
|
+
* Splits a semicolon-separated expression list and rolls each one.
|
|
38
|
+
* @param expressions The raw `expressions` argument
|
|
39
|
+
* @param rng The random source
|
|
40
|
+
* @returns One result per rolled expression, expanded for any `xN` repeat
|
|
41
|
+
* @throws {DiceError} On an unparseable expression or an exceeded cap
|
|
42
|
+
*/
|
|
21
43
|
function rollExpressions(expressions, rng = exports.defaultRng) {
|
|
22
44
|
const terms = String(expressions)
|
|
23
45
|
.split(';')
|
|
@@ -43,11 +65,24 @@ function rollExpressions(expressions, rng = exports.defaultRng) {
|
|
|
43
65
|
}
|
|
44
66
|
return results;
|
|
45
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Rolls a single already-parsed expression string.
|
|
70
|
+
* @param expression One expression, e.g. `1d20+5 adv`
|
|
71
|
+
* @param rng The random source
|
|
72
|
+
* @returns The roll result
|
|
73
|
+
*/
|
|
46
74
|
function rollOne(expression, rng = exports.defaultRng) {
|
|
47
75
|
const term = parseTerm(expression);
|
|
48
76
|
term.repeat = 1;
|
|
49
77
|
return rollTerm(term, termLabel(term), rng);
|
|
50
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Rolls a d20 test: one d20 plus a modifier, with advantage or disadvantage.
|
|
81
|
+
* @param modifier The total bonus to add
|
|
82
|
+
* @param mode 'normal', 'advantage' or 'disadvantage'
|
|
83
|
+
* @param rng The random source
|
|
84
|
+
* @returns The roll result
|
|
85
|
+
*/
|
|
51
86
|
function rollD20(modifier, mode, rng = exports.defaultRng) {
|
|
52
87
|
const term = {
|
|
53
88
|
count: mode === 'normal' ? 1 : 2,
|
|
@@ -69,9 +104,17 @@ function termLabel(term) {
|
|
|
69
104
|
const mod = term.modifier === 0 ? '' : term.modifier > 0 ? `+${term.modifier}` : `${term.modifier}`;
|
|
70
105
|
return `${term.count}d${term.sides}${mod}`;
|
|
71
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Parses one expression term.
|
|
109
|
+
* @param text The term, optionally prefixed with `label=`
|
|
110
|
+
* @returns The parsed term
|
|
111
|
+
* @throws {DiceError} If the term has no dice or an unsupported modifier
|
|
112
|
+
*/
|
|
72
113
|
function parseTerm(text) {
|
|
73
114
|
let body = text.trim();
|
|
74
115
|
let label;
|
|
116
|
+
// A label is `name=` before the dice. Guard against matching the '=' of a
|
|
117
|
+
// future comparison operator by requiring the label to be word-ish.
|
|
75
118
|
const labelMatch = /^([A-Za-z][A-Za-z0-9 _'-]*)=\s*(.+)$/.exec(body);
|
|
76
119
|
if (labelMatch) {
|
|
77
120
|
label = labelMatch[1].trim();
|
|
@@ -86,8 +129,14 @@ function parseTerm(text) {
|
|
|
86
129
|
minimumTwo: false,
|
|
87
130
|
repeat: 1,
|
|
88
131
|
};
|
|
132
|
+
// The dice term is extracted first. Modifiers are often written flush against
|
|
133
|
+
// it ("4d6kh3"), which leaves no word boundary for the modifier patterns to
|
|
134
|
+
// anchor on; removing the dice first gives every modifier clean edges.
|
|
89
135
|
const diceMatch = /(\d*)\s*d\s*(\d+)/i.exec(body);
|
|
90
136
|
if (!diceMatch) {
|
|
137
|
+
// A bare number is a constant, not an error. Several SRD creatures deal
|
|
138
|
+
// flat damage with no die at all — a cat's claws do 1 slashing — and the
|
|
139
|
+
// Dungeon Master rolls those through the same tool as everything else.
|
|
91
140
|
const constant = /^[+-]?\d+$/.exec(body);
|
|
92
141
|
if (constant) {
|
|
93
142
|
term.count = 0;
|
|
@@ -107,6 +156,7 @@ function parseTerm(text) {
|
|
|
107
156
|
throw new DiceError(`"${text}" rolls no dice.`);
|
|
108
157
|
if (term.sides < 2)
|
|
109
158
|
throw new DiceError(`A die must have at least 2 sides ("${text}").`);
|
|
159
|
+
// Word modifiers next, so what remains is arithmetic.
|
|
110
160
|
const takeWord = (pattern) => {
|
|
111
161
|
const match = pattern.exec(rest);
|
|
112
162
|
if (match) {
|
|
@@ -128,6 +178,7 @@ function parseTerm(text) {
|
|
|
128
178
|
const dropHigh = takeWord(/\bdh(\d*)\b/i);
|
|
129
179
|
const dropLow = takeWord(/\bdl(\d*)\b/i);
|
|
130
180
|
const repeat = takeWord(/\bx(\d+)\b/i);
|
|
181
|
+
// Whatever arithmetic remains is the flat modifier.
|
|
131
182
|
const remaining = rest.replace(/\s+/g, '');
|
|
132
183
|
if (remaining) {
|
|
133
184
|
const parts = remaining.match(/[+-]\d+/g);
|
|
@@ -190,12 +241,14 @@ function rollTerm(term, label, rng) {
|
|
|
190
241
|
total,
|
|
191
242
|
kept,
|
|
192
243
|
};
|
|
244
|
+
// Only a single kept d20 has a meaningful natural result.
|
|
193
245
|
if (term.sides === 20 && kept.length === 1) {
|
|
194
246
|
result.natural20 = kept[0] === 20;
|
|
195
247
|
result.natural1 = kept[0] === 1;
|
|
196
248
|
}
|
|
197
249
|
return result;
|
|
198
250
|
}
|
|
251
|
+
/** Marks dice as dropped per the term's keep/drop modifiers. */
|
|
199
252
|
function applyKeepDrop(dice, term) {
|
|
200
253
|
const keepCount = term.keepHighest !== undefined
|
|
201
254
|
? term.keepHighest
|
|
@@ -205,6 +258,7 @@ function applyKeepDrop(dice, term) {
|
|
|
205
258
|
if (keepCount === undefined && term.dropHighest === undefined && term.dropLowest === undefined) {
|
|
206
259
|
return;
|
|
207
260
|
}
|
|
261
|
+
// Sort indices by value so ties drop deterministically (lowest index first).
|
|
208
262
|
const order = dice.map((d, i) => ({ i, value: d.value })).sort((a, b) => a.value - b.value || a.i - b.i);
|
|
209
263
|
const markDropped = (entries) => {
|
|
210
264
|
for (const entry of entries)
|
|
@@ -248,6 +302,19 @@ function describeTerm(term) {
|
|
|
248
302
|
parts.push(term.modifier > 0 ? `+${term.modifier}` : `${term.modifier}`);
|
|
249
303
|
return parts.join(' ');
|
|
250
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Rolls an attack's damage.
|
|
307
|
+
*
|
|
308
|
+
* Here rather than beside the check tool because two tools now need it: `check`
|
|
309
|
+
* rolls damage when an attack lands, and `spend` rolls it when a held die turns a
|
|
310
|
+
* miss into a hit. One implementation means the two cannot disagree about how a
|
|
311
|
+
* critical doubles.
|
|
312
|
+
* @param expression The damage dice, e.g. '1d8+3'
|
|
313
|
+
* @param type The damage type, for the report
|
|
314
|
+
* @param critical Whether to double the dice
|
|
315
|
+
* @param rng The random source
|
|
316
|
+
* @returns The roll, never below zero
|
|
317
|
+
*/
|
|
251
318
|
function rollDamage(expression, type, critical, rng = exports.defaultRng) {
|
|
252
319
|
const toRoll = critical ? `${expression} crit` : expression;
|
|
253
320
|
const roll = rollOne(toRoll, rng);
|
|
@@ -1,32 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Encounter` artifact: whose turn it is, and which round.
|
|
3
|
+
*
|
|
4
|
+
* Turn order is state the tools maintain rather than something the agent running the
|
|
5
|
+
* fight re-states each message, because a re-stated order drifts. Same shape as every
|
|
6
|
+
* other artifact the pack owns: a readable summary for the person at the table above
|
|
7
|
+
* a fenced `briyah-state` block for the tools.
|
|
8
|
+
*
|
|
9
|
+
* Whose turn it is is an **index**, not a set of done-flags. There is one number to
|
|
10
|
+
* be wrong about, and "everyone before it has acted" cannot contradict itself the way
|
|
11
|
+
* a list of ticks can.
|
|
12
|
+
*
|
|
13
|
+
* Pure, with no room access, like the rest of `engine/`.
|
|
14
|
+
*/
|
|
15
|
+
/** The schema version, bumped when a migration becomes necessary. */
|
|
1
16
|
export declare const ENCOUNTER_STATE_VERSION = 1;
|
|
2
17
|
export interface Combatant {
|
|
3
18
|
name: string;
|
|
19
|
+
/** The initiative total this combatant rolled. */
|
|
4
20
|
init: number;
|
|
21
|
+
/** True for a monster, so a turn can be skipped once it is dead. */
|
|
5
22
|
foe?: boolean;
|
|
6
23
|
}
|
|
7
24
|
export interface EncounterState {
|
|
8
25
|
v: number;
|
|
26
|
+
/** What this fight is called, for the render. */
|
|
9
27
|
name: string;
|
|
10
28
|
round: number;
|
|
29
|
+
/**
|
|
30
|
+
* Index into {@link order} of whose turn it is. Everyone before it has acted
|
|
31
|
+
* this round; everyone from it onward has not.
|
|
32
|
+
*/
|
|
11
33
|
turn: number;
|
|
12
34
|
order: Combatant[];
|
|
35
|
+
/**
|
|
36
|
+
* Attack rolls made this round, keyed by {@link combatantKey}. Cleared when the
|
|
37
|
+
* round rolls over.
|
|
38
|
+
*
|
|
39
|
+
* Here rather than on the creature because it is about the round, not the
|
|
40
|
+
* creature, and this is the only object that knows when a round ends. It is what
|
|
41
|
+
* stops a creature attacking twice in a round — which is not a hypothetical: a
|
|
42
|
+
* wolf with a single Bite and no Multiattack bit once before its turn came up and
|
|
43
|
+
* again after it did, and the second one killed a player character.
|
|
44
|
+
*/
|
|
13
45
|
atk?: Record<string, number>;
|
|
14
46
|
}
|
|
47
|
+
/** How a combatant is keyed in {@link EncounterState.atk}. */
|
|
15
48
|
export declare function combatantKey(name: string): string;
|
|
16
49
|
export declare class EncounterError extends Error {
|
|
50
|
+
/** A machine-readable reason so callers can branch without parsing the message. */
|
|
17
51
|
readonly violation: string;
|
|
18
52
|
constructor(violation: string, message: string);
|
|
19
53
|
}
|
|
54
|
+
/** A fight that has just been rolled for, on round one with the first combatant up. */
|
|
20
55
|
export declare function newEncounter(name: string, order: Combatant[]): EncounterState;
|
|
56
|
+
/**
|
|
57
|
+
* Reads the encounter out of its artifact body.
|
|
58
|
+
* @param body The artifact body, or undefined when no fight is running
|
|
59
|
+
* @returns The state, or null when there is no fight
|
|
60
|
+
* @throws {EncounterError} When the block exists but cannot be read, so a caller
|
|
61
|
+
* refuses to overwrite rather than destroying what survives.
|
|
62
|
+
*/
|
|
21
63
|
export declare function parseEncounter(body: string | undefined): EncounterState | null;
|
|
64
|
+
/** How many attack rolls a combatant has already made this round. */
|
|
22
65
|
export declare function attacksThisRound(state: EncounterState, name: string): number;
|
|
66
|
+
/** Records an attack roll against the current round's budget. */
|
|
23
67
|
export declare function recordAttack(state: EncounterState, name: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Where a combatant sits in the order relative to the turn pointer.
|
|
70
|
+
* @param state The encounter
|
|
71
|
+
* @param name The combatant
|
|
72
|
+
* @returns 'past' when their turn this round is over, 'up' when it is theirs now,
|
|
73
|
+
* 'ahead' when it has not come round yet, and 'absent' when they are not in the
|
|
74
|
+
* fight at all — a creature outside the order is not governed by it.
|
|
75
|
+
*/
|
|
24
76
|
export declare function turnStanding(state: EncounterState, name: string): 'past' | 'up' | 'ahead' | 'absent';
|
|
77
|
+
/** Whose turn it currently is. */
|
|
25
78
|
export declare function currentCombatant(state: EncounterState): Combatant;
|
|
79
|
+
/**
|
|
80
|
+
* Moves to the next combatant, wrapping into the next round.
|
|
81
|
+
*
|
|
82
|
+
* `skip` is consulted for each candidate so a dead monster does not get a turn; the
|
|
83
|
+
* order alone carries nothing to tell a caller that. An order where everyone is
|
|
84
|
+
* skippable advances the round and stops rather than looping forever.
|
|
85
|
+
* @param state The encounter, mutated in place
|
|
86
|
+
* @param skip Answers whether a combatant should be passed over
|
|
87
|
+
* @returns Who is up now, and whether the round advanced
|
|
88
|
+
*/
|
|
26
89
|
export declare function advanceTurn(state: EncounterState, skip?: (combatant: Combatant) => boolean): {
|
|
27
90
|
combatant: Combatant;
|
|
28
91
|
newRound: boolean;
|
|
29
92
|
skipped: string[];
|
|
30
93
|
};
|
|
94
|
+
/** Removes a combatant from the order, keeping the turn pointing at the same one. */
|
|
31
95
|
export declare function removeCombatant(state: EncounterState, name: string): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Renders the artifact: a readable order above the state the tools read.
|
|
98
|
+
*
|
|
99
|
+
* The marks are the point — a person glancing at this wants to see how far round the
|
|
100
|
+
* table has got without counting. `←` is up now, `✓` has acted this round.
|
|
101
|
+
* @param state The encounter
|
|
102
|
+
* @param dead Names that are down, marked so nobody wonders why they are skipped
|
|
103
|
+
* @returns The artifact body
|
|
104
|
+
*/
|
|
32
105
|
export declare function renderEncounter(state: EncounterState, dead?: string[]): string;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The `Encounter` artifact: whose turn it is, and which round.
|
|
4
|
+
*
|
|
5
|
+
* Turn order is state the tools maintain rather than something the agent running the
|
|
6
|
+
* fight re-states each message, because a re-stated order drifts. Same shape as every
|
|
7
|
+
* other artifact the pack owns: a readable summary for the person at the table above
|
|
8
|
+
* a fenced `briyah-state` block for the tools.
|
|
9
|
+
*
|
|
10
|
+
* Whose turn it is is an **index**, not a set of done-flags. There is one number to
|
|
11
|
+
* be wrong about, and "everyone before it has acted" cannot contradict itself the way
|
|
12
|
+
* a list of ticks can.
|
|
13
|
+
*
|
|
14
|
+
* Pure, with no room access, like the rest of `engine/`.
|
|
15
|
+
*/
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.EncounterError = exports.ENCOUNTER_STATE_VERSION = void 0;
|
|
4
18
|
exports.combatantKey = combatantKey;
|
|
@@ -12,11 +26,14 @@ exports.advanceTurn = advanceTurn;
|
|
|
12
26
|
exports.removeCombatant = removeCombatant;
|
|
13
27
|
exports.renderEncounter = renderEncounter;
|
|
14
28
|
const STATE_FENCE_TAG = 'briyah-state';
|
|
29
|
+
/** The schema version, bumped when a migration becomes necessary. */
|
|
15
30
|
exports.ENCOUNTER_STATE_VERSION = 1;
|
|
31
|
+
/** How a combatant is keyed in {@link EncounterState.atk}. */
|
|
16
32
|
function combatantKey(name) {
|
|
17
33
|
return name.trim().toLowerCase();
|
|
18
34
|
}
|
|
19
35
|
class EncounterError extends Error {
|
|
36
|
+
/** A machine-readable reason so callers can branch without parsing the message. */
|
|
20
37
|
violation;
|
|
21
38
|
constructor(violation, message) {
|
|
22
39
|
super(message);
|
|
@@ -25,15 +42,25 @@ class EncounterError extends Error {
|
|
|
25
42
|
}
|
|
26
43
|
}
|
|
27
44
|
exports.EncounterError = EncounterError;
|
|
45
|
+
/** A fight that has just been rolled for, on round one with the first combatant up. */
|
|
28
46
|
function newEncounter(name, order) {
|
|
29
47
|
return { v: exports.ENCOUNTER_STATE_VERSION, name, round: 1, turn: 0, order, atk: {} };
|
|
30
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Reads the encounter out of its artifact body.
|
|
51
|
+
* @param body The artifact body, or undefined when no fight is running
|
|
52
|
+
* @returns The state, or null when there is no fight
|
|
53
|
+
* @throws {EncounterError} When the block exists but cannot be read, so a caller
|
|
54
|
+
* refuses to overwrite rather than destroying what survives.
|
|
55
|
+
*/
|
|
31
56
|
function parseEncounter(body) {
|
|
32
57
|
if (!body || !body.trim())
|
|
33
58
|
return null;
|
|
34
59
|
const lines = body.split('\n');
|
|
35
60
|
const open = lines.findIndex((line) => line.trim() === '```' + STATE_FENCE_TAG);
|
|
36
61
|
if (open === -1) {
|
|
62
|
+
// Overwritten by hand, or written before the state block existed. Reported
|
|
63
|
+
// rather than guessed at.
|
|
37
64
|
throw new EncounterError('encounter_corrupt', `The "Encounter" artifact has no "${STATE_FENCE_TAG}" block, so the turn order cannot be read. Roll initiative again to start a fresh one.`);
|
|
38
65
|
}
|
|
39
66
|
const closeOffset = lines.slice(open + 1).findIndex((line) => line.trim() === '```');
|
|
@@ -77,15 +104,25 @@ function parseEncounter(body) {
|
|
|
77
104
|
atk,
|
|
78
105
|
};
|
|
79
106
|
}
|
|
107
|
+
/** How many attack rolls a combatant has already made this round. */
|
|
80
108
|
function attacksThisRound(state, name) {
|
|
81
109
|
return state.atk?.[combatantKey(name)] || 0;
|
|
82
110
|
}
|
|
111
|
+
/** Records an attack roll against the current round's budget. */
|
|
83
112
|
function recordAttack(state, name) {
|
|
84
113
|
if (!state.atk)
|
|
85
114
|
state.atk = {};
|
|
86
115
|
const key = combatantKey(name);
|
|
87
116
|
state.atk[key] = (state.atk[key] || 0) + 1;
|
|
88
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Where a combatant sits in the order relative to the turn pointer.
|
|
120
|
+
* @param state The encounter
|
|
121
|
+
* @param name The combatant
|
|
122
|
+
* @returns 'past' when their turn this round is over, 'up' when it is theirs now,
|
|
123
|
+
* 'ahead' when it has not come round yet, and 'absent' when they are not in the
|
|
124
|
+
* fight at all — a creature outside the order is not governed by it.
|
|
125
|
+
*/
|
|
89
126
|
function turnStanding(state, name) {
|
|
90
127
|
const key = combatantKey(name);
|
|
91
128
|
const index = state.order.findIndex((entry) => combatantKey(entry.name) === key);
|
|
@@ -97,9 +134,20 @@ function turnStanding(state, name) {
|
|
|
97
134
|
return 'up';
|
|
98
135
|
return 'ahead';
|
|
99
136
|
}
|
|
137
|
+
/** Whose turn it currently is. */
|
|
100
138
|
function currentCombatant(state) {
|
|
101
139
|
return state.order[state.turn];
|
|
102
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Moves to the next combatant, wrapping into the next round.
|
|
143
|
+
*
|
|
144
|
+
* `skip` is consulted for each candidate so a dead monster does not get a turn; the
|
|
145
|
+
* order alone carries nothing to tell a caller that. An order where everyone is
|
|
146
|
+
* skippable advances the round and stops rather than looping forever.
|
|
147
|
+
* @param state The encounter, mutated in place
|
|
148
|
+
* @param skip Answers whether a combatant should be passed over
|
|
149
|
+
* @returns Who is up now, and whether the round advanced
|
|
150
|
+
*/
|
|
103
151
|
function advanceTurn(state, skip = () => false) {
|
|
104
152
|
const skipped = [];
|
|
105
153
|
let newRound = false;
|
|
@@ -109,6 +157,9 @@ function advanceTurn(state, skip = () => false) {
|
|
|
109
157
|
state.turn = 0;
|
|
110
158
|
state.round += 1;
|
|
111
159
|
newRound = true;
|
|
160
|
+
// Everyone's attack is available again. Cleared on the way into the new
|
|
161
|
+
// round rather than as each turn ends, because a creature may legitimately
|
|
162
|
+
// act before its own turn comes up and the budget has to outlive that.
|
|
112
163
|
state.atk = {};
|
|
113
164
|
}
|
|
114
165
|
const candidate = state.order[state.turn];
|
|
@@ -116,8 +167,10 @@ function advanceTurn(state, skip = () => false) {
|
|
|
116
167
|
return { combatant: candidate, newRound, skipped };
|
|
117
168
|
skipped.push(candidate.name);
|
|
118
169
|
}
|
|
170
|
+
// Everyone left is skippable: the fight is over in all but name.
|
|
119
171
|
return { combatant: state.order[state.turn], newRound, skipped };
|
|
120
172
|
}
|
|
173
|
+
/** Removes a combatant from the order, keeping the turn pointing at the same one. */
|
|
121
174
|
function removeCombatant(state, name) {
|
|
122
175
|
const index = state.order.findIndex((entry) => entry.name.toLowerCase() === name.trim().toLowerCase());
|
|
123
176
|
if (index === -1)
|
|
@@ -127,12 +180,22 @@ function removeCombatant(state, name) {
|
|
|
127
180
|
state.turn = 0;
|
|
128
181
|
return true;
|
|
129
182
|
}
|
|
183
|
+
// Removing someone earlier in the order shifts everyone after them down one.
|
|
130
184
|
if (index < state.turn)
|
|
131
185
|
state.turn -= 1;
|
|
132
186
|
if (state.turn >= state.order.length)
|
|
133
187
|
state.turn = 0;
|
|
134
188
|
return true;
|
|
135
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Renders the artifact: a readable order above the state the tools read.
|
|
192
|
+
*
|
|
193
|
+
* The marks are the point — a person glancing at this wants to see how far round the
|
|
194
|
+
* table has got without counting. `←` is up now, `✓` has acted this round.
|
|
195
|
+
* @param state The encounter
|
|
196
|
+
* @param dead Names that are down, marked so nobody wonders why they are skipped
|
|
197
|
+
* @returns The artifact body
|
|
198
|
+
*/
|
|
136
199
|
function renderEncounter(state, dead = []) {
|
|
137
200
|
const down = new Set(dead.map((name) => name.toLowerCase()));
|
|
138
201
|
const lines = [`# ${state.name}`, '', `**Round ${state.round}**`, ''];
|
|
@@ -1,26 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carrying capacity, and the optional encumbrance variant.
|
|
3
|
+
*
|
|
4
|
+
* Two regimes, and the difference matters. The **base rule** is always in force and
|
|
5
|
+
* is almost never binding — capacity is Strength × 15, "high enough that most
|
|
6
|
+
* characters don't usually have to worry about it" — so the only thing it changes is
|
|
7
|
+
* a speed of 5 feet while dragging something too heavy.
|
|
8
|
+
*
|
|
9
|
+
* The **variant** is opt-in, and turning it on has a consequence the rules state
|
|
10
|
+
* outright: "when you use this variant, ignore the Strength column of the Armor
|
|
11
|
+
* table." So a character playing with encumbrance stops taking the heavy-armour
|
|
12
|
+
* speed penalty and starts taking a weight penalty instead. Applying both would
|
|
13
|
+
* charge them twice for the same plate mail.
|
|
14
|
+
*
|
|
15
|
+
* Pure, with no room access, like the rest of `engine/`.
|
|
16
|
+
*/
|
|
1
17
|
import type { SheetState } from './sheet';
|
|
18
|
+
/**
|
|
19
|
+
* What one of an item weighs, in pounds.
|
|
20
|
+
*
|
|
21
|
+
* Three lookups, in order, and each earns its place. An exact name; then the same
|
|
22
|
+
* words with a comma swapped round, because the SRD files things for sorting rather
|
|
23
|
+
* than for reading — `Clothes, common` is what a person writes as "common clothes",
|
|
24
|
+
* exactly as `Crossbow, light` is a light crossbow. Then a bundle: the SRD prices
|
|
25
|
+
* ammunition twenty at a time, so `Arrows (20) — 1 lb.` means one arrow weighs a
|
|
26
|
+
* twentieth of a pound and a sheet saying `arrows x40` should come to two.
|
|
27
|
+
* @param name The item as written on the sheet
|
|
28
|
+
* @returns Pounds for one, or null when the SRD never prints a weight for it
|
|
29
|
+
*/
|
|
2
30
|
export declare function itemWeight(name: string): number | null;
|
|
3
31
|
export interface CarriedWeight {
|
|
32
|
+
/** Total pounds of everything whose weight is known. */
|
|
4
33
|
pounds: number;
|
|
34
|
+
/**
|
|
35
|
+
* Items carried whose weight the SRD never prints — vestments, a holy symbol, a
|
|
36
|
+
* campaign's own trinket. Named rather than assumed to weigh nothing, so a total
|
|
37
|
+
* is never mistaken for the whole truth.
|
|
38
|
+
*/
|
|
5
39
|
unweighed: string[];
|
|
6
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Adds up what the character is carrying.
|
|
43
|
+
* @param state The character
|
|
44
|
+
* @returns The total, and whatever could not be weighed
|
|
45
|
+
*/
|
|
7
46
|
export declare function carriedWeight(state: SheetState): CarriedWeight;
|
|
8
47
|
export interface CarryingCapacity {
|
|
48
|
+
/** Strength × 15, adjusted for size. */
|
|
9
49
|
capacity: number;
|
|
50
|
+
/** Twice that: what can be pushed, dragged or lifted. */
|
|
10
51
|
pushDragLift: number;
|
|
52
|
+
/** The variant's first threshold, Strength × 5. */
|
|
11
53
|
encumberedAt: number;
|
|
54
|
+
/** The variant's second, Strength × 10. */
|
|
12
55
|
heavilyEncumberedAt: number;
|
|
13
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* What this character can carry.
|
|
59
|
+
*
|
|
60
|
+
* Size adjusts every figure: "for each size category above Medium, double the
|
|
61
|
+
* creature's carrying capacity ... for a Tiny creature, halve these weights."
|
|
62
|
+
* @param state The character
|
|
63
|
+
* @returns The capacity and the variant's thresholds
|
|
64
|
+
*/
|
|
14
65
|
export declare function carryingCapacity(state: SheetState): CarryingCapacity;
|
|
66
|
+
/** Where a character sits against the thresholds. */
|
|
15
67
|
export type EncumbranceTier = 'unencumbered' | 'encumbered' | 'heavily encumbered' | 'over capacity';
|
|
68
|
+
/** True when this character plays with the optional encumbrance variant. */
|
|
16
69
|
export declare function usesVariant(state: SheetState): boolean;
|
|
17
70
|
export interface EncumbranceState {
|
|
18
71
|
tier: EncumbranceTier;
|
|
72
|
+
/** Feet to subtract from speed. */
|
|
19
73
|
speedPenalty: number;
|
|
74
|
+
/** True when Strength, Dexterity and Constitution rolls have disadvantage. */
|
|
20
75
|
disadvantage: boolean;
|
|
21
76
|
carried: CarriedWeight;
|
|
22
77
|
capacity: CarryingCapacity;
|
|
78
|
+
/** True when the variant is in force; the tiers are meaningless without it. */
|
|
23
79
|
variant: boolean;
|
|
24
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Works out the character's encumbrance.
|
|
83
|
+
*
|
|
84
|
+
* Without the variant only one thing bites: carrying more than capacity, which the
|
|
85
|
+
* base rules cover by dropping speed to 5 feet while you drag it. With the variant,
|
|
86
|
+
* the two thresholds apply instead.
|
|
87
|
+
* @param state The character
|
|
88
|
+
* @returns The tier and what it costs
|
|
89
|
+
*/
|
|
25
90
|
export declare function encumbrance(state: SheetState): EncumbranceState;
|
|
91
|
+
/** A readable line for the sheet and for `read_sheet`. */
|
|
26
92
|
export declare function describeEncumbrance(state: SheetState): string;
|