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,16 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom error classes for semantic error handling in the application.
|
|
4
|
+
* These errors are thrown by service layer and mapped to HTTP exceptions in controllers.
|
|
5
|
+
*/
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.InsufficientBalanceError = exports.OperationFailedError = exports.ValidationError = exports.NotFoundError = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when a requested resource (agent, room, story, etc.) is not found.
|
|
10
|
+
* Maps to HTTP 404 Not Found in controllers.
|
|
11
|
+
*/
|
|
4
12
|
class NotFoundError extends Error {
|
|
5
13
|
constructor(message) {
|
|
6
14
|
super(message);
|
|
7
15
|
this.name = 'NotFoundError';
|
|
16
|
+
// Maintains proper stack trace for where our error was thrown (V8 only)
|
|
8
17
|
if (Error.captureStackTrace) {
|
|
9
18
|
Error.captureStackTrace(this, NotFoundError);
|
|
10
19
|
}
|
|
11
20
|
}
|
|
12
21
|
}
|
|
13
22
|
exports.NotFoundError = NotFoundError;
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when input validation fails or invalid data is provided.
|
|
25
|
+
* Maps to HTTP 400 Bad Request in controllers.
|
|
26
|
+
*/
|
|
14
27
|
class ValidationError extends Error {
|
|
15
28
|
constructor(message) {
|
|
16
29
|
super(message);
|
|
@@ -21,6 +34,10 @@ class ValidationError extends Error {
|
|
|
21
34
|
}
|
|
22
35
|
}
|
|
23
36
|
exports.ValidationError = ValidationError;
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when an operation fails due to system/IO errors.
|
|
39
|
+
* Maps to HTTP 500 Internal Server Error in controllers.
|
|
40
|
+
*/
|
|
24
41
|
class OperationFailedError extends Error {
|
|
25
42
|
constructor(message) {
|
|
26
43
|
super(message);
|
|
@@ -31,6 +48,10 @@ class OperationFailedError extends Error {
|
|
|
31
48
|
}
|
|
32
49
|
}
|
|
33
50
|
exports.OperationFailedError = OperationFailedError;
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when user has insufficient balance to perform an AI operation.
|
|
53
|
+
* This error should propagate to the client to trigger a credit purchase flow.
|
|
54
|
+
*/
|
|
34
55
|
class InsufficientBalanceError extends Error {
|
|
35
56
|
constructor(message) {
|
|
36
57
|
super(message);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal interface for environment-variable configuration access.
|
|
3
|
+
*
|
|
4
|
+
* Implemented by both NestJS `ConfigService` (from `@nestjs/config`) and
|
|
5
|
+
* `BriyahConfigService` so consumers can read env-derived settings without
|
|
6
|
+
* coupling to either implementation.
|
|
7
|
+
*/
|
|
1
8
|
export interface IConfigService {
|
|
2
9
|
get<T = string>(key: string, defaultValue?: T): T;
|
|
3
10
|
}
|
|
@@ -1,41 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a prompt file comes from.
|
|
3
|
+
*
|
|
4
|
+
* One lookup order, used by both the runtime (`BaseAiService.findPromptFile`) and
|
|
5
|
+
* the management API (`AppService.getPromptFile`). Those were two independent
|
|
6
|
+
* implementations of the same four levels, which is why a fifth and sixth level
|
|
7
|
+
* for packs lives here instead of being written twice.
|
|
8
|
+
*
|
|
9
|
+
* ## The two shapes of a folder reference
|
|
10
|
+
*
|
|
11
|
+
* `agent.promptFolder` is either a bare folder name (`dungeon_master`) or a
|
|
12
|
+
* pack-qualified one (`dnd5e:dungeon_master`). A bare name may not contain a
|
|
13
|
+
* colon — {@link assertPathSafe} enforces it — so the colon is a total
|
|
14
|
+
* discriminator between the two.
|
|
15
|
+
*
|
|
16
|
+
* ## Mirror-shadows-path, not tier-major
|
|
17
|
+
*
|
|
18
|
+
* The historical order is tier-major: a file at the *user root* beats a
|
|
19
|
+
* folder-specific file in *common*. That is deliberate, and it is documented in
|
|
20
|
+
* `briyah.ts` as how a host overrides a package-canonical prompt.
|
|
21
|
+
*
|
|
22
|
+
* The pack overlay does **not** follow that rule, and the difference is not an
|
|
23
|
+
* oversight. `user/<id>/packs/<pack>/prompts/` is not a tier — it is a
|
|
24
|
+
* copy-on-write mirror, whose files exist only because the user edited that exact
|
|
25
|
+
* path. So each mirrored path is checked immediately before the path it mirrors.
|
|
26
|
+
*
|
|
27
|
+
* Making the overlay tier-major instead would mean a user who edits a pack's
|
|
28
|
+
* *root* `compact_agent.prompt` silently shadows a folder-specific one. That is
|
|
29
|
+
* not hypothetical: `dungeon_master` is the only folder in the tree that ships its
|
|
30
|
+
* own `compact_agent.prompt`, and it would be the one to break.
|
|
31
|
+
*
|
|
32
|
+
* ## Why pack-qualified lookups ignore enablement
|
|
33
|
+
*
|
|
34
|
+
* A disabled pack is hidden, not switched off. Only the *bare-name* scan consults
|
|
35
|
+
* the enabled set — that is what stops a pack claiming a name like `narrator` for
|
|
36
|
+
* a user who never turned it on. A pack-qualified reference always resolves.
|
|
37
|
+
*
|
|
38
|
+
* Gating it would not hide anything, it would break things: `perceive.prompt`
|
|
39
|
+
* resolves on every turn and `getPreparedPrompt` throws when it misses, and
|
|
40
|
+
* `getPreparedSchema` returns `null` on a miss — which would drop the response
|
|
41
|
+
* schema and start feeding free text into a JSON parser. This mirrors the same
|
|
42
|
+
* split in `pack-artifacts.ts`, where listing is gated and resolution is not.
|
|
43
|
+
*/
|
|
1
44
|
import { PromptScope } from '../../../shared/types/app.types';
|
|
2
45
|
import { UserPathsService } from './user-paths.service';
|
|
46
|
+
/** Separates a pack from a folder in a prompt folder reference. */
|
|
3
47
|
export declare const PACK_FOLDER_SEPARATOR = ":";
|
|
48
|
+
/** The name meaning "the prompts root rather than a folder". */
|
|
4
49
|
export declare const SHARED_FOLDER = "shared";
|
|
50
|
+
/** Which of the four directory tiers a prompt file was found in. */
|
|
5
51
|
export type PromptTier = 'user' | 'common' | 'pack' | 'pack-overlay';
|
|
52
|
+
/** A prompt folder reference, split into its parts. */
|
|
6
53
|
export interface PromptRef {
|
|
54
|
+
/** The pack, or null for a bare folder name. */
|
|
7
55
|
pack: string | null;
|
|
56
|
+
/** The folder within that tier. Empty means the prompts root. */
|
|
8
57
|
folder: string;
|
|
9
58
|
}
|
|
59
|
+
/** One directory the lookup will consult, with where it sits. */
|
|
10
60
|
export interface PromptDir {
|
|
11
61
|
dir: string;
|
|
12
62
|
tier: PromptTier;
|
|
13
63
|
pack: string | null;
|
|
14
64
|
scope: PromptScope;
|
|
65
|
+
/**
|
|
66
|
+
* The directory *is* the named folder, rather than a root the lookup falls
|
|
67
|
+
* back to. Only these say anything about whether the folder exists: every
|
|
68
|
+
* lookup ends at the prompts roots, which always do.
|
|
69
|
+
*/
|
|
15
70
|
folderScoped: boolean;
|
|
16
71
|
}
|
|
72
|
+
/** A candidate file path, with where it would have come from. */
|
|
17
73
|
export interface PromptCandidate extends PromptDir {
|
|
18
74
|
absolutePath: string;
|
|
19
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Rejects anything that must never reach `path.join`.
|
|
78
|
+
*
|
|
79
|
+
* The colon matters more than it looks. On Windows a colon in a path component is
|
|
80
|
+
* the NTFS alternate-data-stream separator, so `path.join(dir, 'dnd5e:foo')` does
|
|
81
|
+
* not fail cleanly — it addresses a stream on a file named `dnd5e`. A qualified
|
|
82
|
+
* reference has to be split into segments before any path is built, and this is
|
|
83
|
+
* the backstop that proves it was.
|
|
84
|
+
*
|
|
85
|
+
* @param segment A single path component
|
|
86
|
+
* @throws {Error} If the segment could escape or corrupt the intended path
|
|
87
|
+
*/
|
|
20
88
|
export declare function assertPathSafe(segment: string): void;
|
|
89
|
+
/** Whether a name is usable as a pack directory. */
|
|
21
90
|
export declare function isValidPackName(packName: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Splits a prompt folder reference into its pack and folder.
|
|
93
|
+
*
|
|
94
|
+
* Accepts `folder`, `pack:folder`, `shared`, `pack:shared`, and the empty string
|
|
95
|
+
* (which some agents carry and which means the prompts root, the same as
|
|
96
|
+
* `shared`).
|
|
97
|
+
*
|
|
98
|
+
* @param value The value stored on `agent.promptFolder` or arriving as a route param
|
|
99
|
+
* @returns The parsed reference
|
|
100
|
+
* @throws {Error} If the pack name is malformed or either part is unsafe
|
|
101
|
+
*/
|
|
22
102
|
export declare function parsePromptFolder(value: string): PromptRef;
|
|
103
|
+
/** The inverse of {@link parsePromptFolder}. */
|
|
23
104
|
export declare function formatPromptFolder(ref: PromptRef): string;
|
|
105
|
+
/** True when the reference names a pack. */
|
|
24
106
|
export declare function isPackFolder(value: string): boolean;
|
|
25
107
|
export interface PromptResolveOptions {
|
|
108
|
+
/**
|
|
109
|
+
* The packs enabled for this user, consulted only for a bare folder name.
|
|
110
|
+
*
|
|
111
|
+
* A thunk rather than an array on purpose: a live `Agent` holds this for its
|
|
112
|
+
* whole lifetime, and a snapshot would go stale the moment the user toggled a
|
|
113
|
+
* pack, with no way to invalidate it short of a fan-out across every cached
|
|
114
|
+
* agent, room and service.
|
|
115
|
+
*
|
|
116
|
+
* Absent means "scan no packs", which is exactly the pre-pack behaviour — so a
|
|
117
|
+
* caller that has not been wired up yet is unaffected.
|
|
118
|
+
*/
|
|
26
119
|
enabledPacks?: () => readonly string[];
|
|
27
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* The directories a lookup consults, highest precedence first.
|
|
123
|
+
*
|
|
124
|
+
* Exposed separately from {@link promptSearchPaths} because listing a folder's
|
|
125
|
+
* files needs the directories without a file name. Note the order is the reverse
|
|
126
|
+
* of what a "scan every directory and let later writes win" loop wants — see
|
|
127
|
+
* {@link promptFolderDirsLowestFirst}.
|
|
128
|
+
*
|
|
129
|
+
* @param userPaths The per-user path service
|
|
130
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
131
|
+
* @param options Enablement, for the bare-name pack scan
|
|
132
|
+
* @returns The directories, most specific first
|
|
133
|
+
*/
|
|
28
134
|
export declare function promptFolderDirs(userPaths: UserPathsService, folder: string, options?: PromptResolveOptions): PromptDir[];
|
|
135
|
+
/**
|
|
136
|
+
* The same directories, lowest precedence first.
|
|
137
|
+
*
|
|
138
|
+
* `listPromptFiles` and `listPromptFilesWithScope` scan directories into a Map so
|
|
139
|
+
* that a later entry overwrites an earlier one, which means they need the
|
|
140
|
+
* opposite order from a first-hit-wins lookup.
|
|
141
|
+
*/
|
|
29
142
|
export declare function promptFolderDirsLowestFirst(userPaths: UserPathsService, folder: string, options?: PromptResolveOptions): PromptDir[];
|
|
143
|
+
/**
|
|
144
|
+
* Every path a lookup would try, highest precedence first.
|
|
145
|
+
*
|
|
146
|
+
* @param userPaths The per-user path service
|
|
147
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
148
|
+
* @param fileName The file name without an extension
|
|
149
|
+
* @param extension The extension, including the dot (`.prompt`, `.json`, `.mock`)
|
|
150
|
+
* @param options Enablement, for the bare-name pack scan
|
|
151
|
+
* @returns The candidate paths, which may not exist
|
|
152
|
+
*/
|
|
30
153
|
export declare function promptSearchPaths(userPaths: UserPathsService, folder: string, fileName: string, extension: string, options?: PromptResolveOptions): PromptCandidate[];
|
|
154
|
+
/**
|
|
155
|
+
* Finds a prompt file.
|
|
156
|
+
*
|
|
157
|
+
* @param userPaths The per-user path service
|
|
158
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
159
|
+
* @param fileName The file name without an extension
|
|
160
|
+
* @param extension The extension, including the dot
|
|
161
|
+
* @param options Enablement, for the bare-name pack scan
|
|
162
|
+
* @returns The first candidate that exists, or null
|
|
163
|
+
*/
|
|
31
164
|
export declare function resolvePromptFile(userPaths: UserPathsService, folder: string, fileName: string, extension: string, options?: PromptResolveOptions): PromptCandidate | null;
|
|
165
|
+
/**
|
|
166
|
+
* Whether a folder reference reaches a directory that exists.
|
|
167
|
+
*
|
|
168
|
+
* A reference that reaches nothing still *resolves*: every lookup ends at the
|
|
169
|
+
* shared prompts roots, so a misspelled folder — or a pack folder named bare by a
|
|
170
|
+
* user who has not enabled the pack — quietly produces a generic agent instead of
|
|
171
|
+
* the role that was asked for. Only a folder-scoped directory answers the
|
|
172
|
+
* question, which is why {@link PromptDir.folderScoped} exists.
|
|
173
|
+
*
|
|
174
|
+
* Unlike {@link resolvePromptFile} this consults enablement for a bare name, and
|
|
175
|
+
* that is the point: it answers "would this reference behave as the caller
|
|
176
|
+
* expects", and a bare pack folder with the pack switched off would not.
|
|
177
|
+
*
|
|
178
|
+
* @param userPaths The per-user path service
|
|
179
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
180
|
+
* @param options Enablement, for the bare-name pack scan
|
|
181
|
+
* @returns True when the folder exists in some tier, or names the prompts root
|
|
182
|
+
*/
|
|
32
183
|
export declare function promptFolderExists(userPaths: UserPathsService, folder: string, options?: PromptResolveOptions): boolean;
|
|
184
|
+
/** A prompt folder that exists somewhere, and the value that names it. */
|
|
33
185
|
export interface PromptFolderRef {
|
|
186
|
+
/** What a caller stores and sends back: `dungeon_master` or `dnd5e:dungeon_master`. */
|
|
34
187
|
value: string;
|
|
188
|
+
/** The folder alone. */
|
|
35
189
|
folder: string;
|
|
190
|
+
/** The pack, or null. */
|
|
36
191
|
pack: string | null;
|
|
37
192
|
tier: PromptTier;
|
|
38
193
|
scope: PromptScope;
|
|
39
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Every prompt folder reachable by this user, one entry per name.
|
|
197
|
+
*
|
|
198
|
+
* Unlike resolution, listing **is** gated: a disabled pack's folders do not
|
|
199
|
+
* appear. Where the same name exists in more than one tier the highest
|
|
200
|
+
* precedence wins, except that a pack folder never merges with a bare one — they
|
|
201
|
+
* are different values and both are listed.
|
|
202
|
+
*
|
|
203
|
+
* @param userPaths The per-user path service
|
|
204
|
+
* @param options Enablement, which here gates the pack folders themselves
|
|
205
|
+
* @returns The folders, sorted by the value that names them
|
|
206
|
+
*/
|
|
40
207
|
export declare function listPromptFolderRefs(userPaths: UserPathsService, options?: PromptResolveOptions): PromptFolderRef[];
|
|
208
|
+
/**
|
|
209
|
+
* Where a write to this folder belongs.
|
|
210
|
+
*
|
|
211
|
+
* Derived from the *reference*, never from where the file happened to resolve.
|
|
212
|
+
* Editing a pack folder's `perceive.prompt` that fell through to
|
|
213
|
+
* `common/prompts/perceive.prompt` must not write the user's prompts root — that
|
|
214
|
+
* would turn an edit made inside one pack into a global override for every folder
|
|
215
|
+
* the user has.
|
|
216
|
+
*
|
|
217
|
+
* @param userPaths The per-user path service
|
|
218
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
219
|
+
* @returns The directory to write into, which may not exist yet
|
|
220
|
+
*/
|
|
41
221
|
export declare function promptWriteDir(userPaths: UserPathsService, folder: string): string;
|
|
@@ -1,4 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Where a prompt file comes from.
|
|
4
|
+
*
|
|
5
|
+
* One lookup order, used by both the runtime (`BaseAiService.findPromptFile`) and
|
|
6
|
+
* the management API (`AppService.getPromptFile`). Those were two independent
|
|
7
|
+
* implementations of the same four levels, which is why a fifth and sixth level
|
|
8
|
+
* for packs lives here instead of being written twice.
|
|
9
|
+
*
|
|
10
|
+
* ## The two shapes of a folder reference
|
|
11
|
+
*
|
|
12
|
+
* `agent.promptFolder` is either a bare folder name (`dungeon_master`) or a
|
|
13
|
+
* pack-qualified one (`dnd5e:dungeon_master`). A bare name may not contain a
|
|
14
|
+
* colon — {@link assertPathSafe} enforces it — so the colon is a total
|
|
15
|
+
* discriminator between the two.
|
|
16
|
+
*
|
|
17
|
+
* ## Mirror-shadows-path, not tier-major
|
|
18
|
+
*
|
|
19
|
+
* The historical order is tier-major: a file at the *user root* beats a
|
|
20
|
+
* folder-specific file in *common*. That is deliberate, and it is documented in
|
|
21
|
+
* `briyah.ts` as how a host overrides a package-canonical prompt.
|
|
22
|
+
*
|
|
23
|
+
* The pack overlay does **not** follow that rule, and the difference is not an
|
|
24
|
+
* oversight. `user/<id>/packs/<pack>/prompts/` is not a tier — it is a
|
|
25
|
+
* copy-on-write mirror, whose files exist only because the user edited that exact
|
|
26
|
+
* path. So each mirrored path is checked immediately before the path it mirrors.
|
|
27
|
+
*
|
|
28
|
+
* Making the overlay tier-major instead would mean a user who edits a pack's
|
|
29
|
+
* *root* `compact_agent.prompt` silently shadows a folder-specific one. That is
|
|
30
|
+
* not hypothetical: `dungeon_master` is the only folder in the tree that ships its
|
|
31
|
+
* own `compact_agent.prompt`, and it would be the one to break.
|
|
32
|
+
*
|
|
33
|
+
* ## Why pack-qualified lookups ignore enablement
|
|
34
|
+
*
|
|
35
|
+
* A disabled pack is hidden, not switched off. Only the *bare-name* scan consults
|
|
36
|
+
* the enabled set — that is what stops a pack claiming a name like `narrator` for
|
|
37
|
+
* a user who never turned it on. A pack-qualified reference always resolves.
|
|
38
|
+
*
|
|
39
|
+
* Gating it would not hide anything, it would break things: `perceive.prompt`
|
|
40
|
+
* resolves on every turn and `getPreparedPrompt` throws when it misses, and
|
|
41
|
+
* `getPreparedSchema` returns `null` on a miss — which would drop the response
|
|
42
|
+
* schema and start feeding free text into a JSON parser. This mirrors the same
|
|
43
|
+
* split in `pack-artifacts.ts`, where listing is gated and resolution is not.
|
|
44
|
+
*/
|
|
2
45
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
46
|
if (k2 === undefined) k2 = k;
|
|
4
47
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -49,9 +92,30 @@ exports.promptWriteDir = promptWriteDir;
|
|
|
49
92
|
const fs = __importStar(require("fs"));
|
|
50
93
|
const path = __importStar(require("path"));
|
|
51
94
|
const errors_1 = require("../common/errors");
|
|
95
|
+
/** Separates a pack from a folder in a prompt folder reference. */
|
|
52
96
|
exports.PACK_FOLDER_SEPARATOR = ':';
|
|
97
|
+
/** The name meaning "the prompts root rather than a folder". */
|
|
53
98
|
exports.SHARED_FOLDER = 'shared';
|
|
99
|
+
/**
|
|
100
|
+
* A pack name: lowercase, no dot, no colon, no separator.
|
|
101
|
+
*
|
|
102
|
+
* The dot is excluded because `pack-artifacts.ts` uses it to separate the pack
|
|
103
|
+
* from the document in an artifact id, so a pack named `mock.trial` would produce
|
|
104
|
+
* ids that split at the wrong place.
|
|
105
|
+
*/
|
|
54
106
|
const PACK_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
107
|
+
/**
|
|
108
|
+
* Rejects anything that must never reach `path.join`.
|
|
109
|
+
*
|
|
110
|
+
* The colon matters more than it looks. On Windows a colon in a path component is
|
|
111
|
+
* the NTFS alternate-data-stream separator, so `path.join(dir, 'dnd5e:foo')` does
|
|
112
|
+
* not fail cleanly — it addresses a stream on a file named `dnd5e`. A qualified
|
|
113
|
+
* reference has to be split into segments before any path is built, and this is
|
|
114
|
+
* the backstop that proves it was.
|
|
115
|
+
*
|
|
116
|
+
* @param segment A single path component
|
|
117
|
+
* @throws {Error} If the segment could escape or corrupt the intended path
|
|
118
|
+
*/
|
|
55
119
|
function assertPathSafe(segment) {
|
|
56
120
|
if (!segment || segment === '.' || segment === '..') {
|
|
57
121
|
throw new errors_1.ValidationError(`Invalid name: "${segment}"`);
|
|
@@ -60,9 +124,21 @@ function assertPathSafe(segment) {
|
|
|
60
124
|
throw new errors_1.ValidationError(`Invalid name "${segment}": a folder name may not contain a path separator or a colon`);
|
|
61
125
|
}
|
|
62
126
|
}
|
|
127
|
+
/** Whether a name is usable as a pack directory. */
|
|
63
128
|
function isValidPackName(packName) {
|
|
64
129
|
return PACK_NAME.test(packName);
|
|
65
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Splits a prompt folder reference into its pack and folder.
|
|
133
|
+
*
|
|
134
|
+
* Accepts `folder`, `pack:folder`, `shared`, `pack:shared`, and the empty string
|
|
135
|
+
* (which some agents carry and which means the prompts root, the same as
|
|
136
|
+
* `shared`).
|
|
137
|
+
*
|
|
138
|
+
* @param value The value stored on `agent.promptFolder` or arriving as a route param
|
|
139
|
+
* @returns The parsed reference
|
|
140
|
+
* @throws {Error} If the pack name is malformed or either part is unsafe
|
|
141
|
+
*/
|
|
66
142
|
function parsePromptFolder(value) {
|
|
67
143
|
const trimmed = (value ?? '').trim();
|
|
68
144
|
const separator = trimmed.indexOf(exports.PACK_FOLDER_SEPARATOR);
|
|
@@ -77,6 +153,7 @@ function parsePromptFolder(value) {
|
|
|
77
153
|
if (!isValidPackName(pack)) {
|
|
78
154
|
throw new errors_1.ValidationError(`Invalid pack name "${pack}" in prompt folder "${trimmed}": expected lowercase letters, digits, "_" or "-"`);
|
|
79
155
|
}
|
|
156
|
+
// A bare `pack:` names no folder and no root; it is a typo, not the pack root.
|
|
80
157
|
if (!rest) {
|
|
81
158
|
throw new errors_1.ValidationError(`Prompt folder "${trimmed}" names a pack but no folder`);
|
|
82
159
|
}
|
|
@@ -85,20 +162,37 @@ function parsePromptFolder(value) {
|
|
|
85
162
|
assertPathSafe(folder);
|
|
86
163
|
return { pack, folder };
|
|
87
164
|
}
|
|
165
|
+
/** The inverse of {@link parsePromptFolder}. */
|
|
88
166
|
function formatPromptFolder(ref) {
|
|
89
167
|
const folder = ref.folder || exports.SHARED_FOLDER;
|
|
90
168
|
return ref.pack ? `${ref.pack}${exports.PACK_FOLDER_SEPARATOR}${folder}` : folder;
|
|
91
169
|
}
|
|
170
|
+
/** True when the reference names a pack. */
|
|
92
171
|
function isPackFolder(value) {
|
|
93
172
|
return (value ?? '').includes(exports.PACK_FOLDER_SEPARATOR);
|
|
94
173
|
}
|
|
174
|
+
/** How a tier reports itself over the wire, which only knows user vs common. */
|
|
95
175
|
function scopeOf(tier) {
|
|
96
176
|
return tier === 'user' || tier === 'pack-overlay' ? 'user' : 'common';
|
|
97
177
|
}
|
|
178
|
+
/** The enabled packs, sorted, or none when the caller supplied no thunk. */
|
|
98
179
|
function enabledPacksOf(options) {
|
|
99
180
|
const enabled = options?.enabledPacks?.() ?? [];
|
|
100
181
|
return [...enabled].filter(isValidPackName).sort();
|
|
101
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* The directories a lookup consults, highest precedence first.
|
|
185
|
+
*
|
|
186
|
+
* Exposed separately from {@link promptSearchPaths} because listing a folder's
|
|
187
|
+
* files needs the directories without a file name. Note the order is the reverse
|
|
188
|
+
* of what a "scan every directory and let later writes win" loop wants — see
|
|
189
|
+
* {@link promptFolderDirsLowestFirst}.
|
|
190
|
+
*
|
|
191
|
+
* @param userPaths The per-user path service
|
|
192
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
193
|
+
* @param options Enablement, for the bare-name pack scan
|
|
194
|
+
* @returns The directories, most specific first
|
|
195
|
+
*/
|
|
102
196
|
function promptFolderDirs(userPaths, folder, options) {
|
|
103
197
|
const ref = parsePromptFolder(folder);
|
|
104
198
|
const dirs = [];
|
|
@@ -107,12 +201,17 @@ function promptFolderDirs(userPaths, folder, options) {
|
|
|
107
201
|
if (ref.pack) {
|
|
108
202
|
const overlay = path.join(userPaths.getUserPackDir(ref.pack), 'prompts');
|
|
109
203
|
const installed = path.join(userPaths.getPackDir(ref.pack), 'prompts');
|
|
204
|
+
// The mirror sits immediately before the path it mirrors, at both depths.
|
|
110
205
|
if (ref.folder) {
|
|
111
206
|
pushFolder(path.join(overlay, ref.folder), 'pack-overlay', ref.pack);
|
|
112
207
|
pushFolder(path.join(installed, ref.folder), 'pack', ref.pack);
|
|
113
208
|
}
|
|
114
209
|
push(overlay, 'pack-overlay', ref.pack);
|
|
115
210
|
push(installed, 'pack', ref.pack);
|
|
211
|
+
// A pack folder still falls back to the shared roots, and this is
|
|
212
|
+
// load-bearing rather than tidy: `greeting.prompt` is root-only, and only
|
|
213
|
+
// `dungeon_master` ships its own `compact_agent.prompt`. Without these two
|
|
214
|
+
// levels every other pack folder silently loses both.
|
|
116
215
|
push(userPaths.getUserPromptsDir(), 'user');
|
|
117
216
|
push(userPaths.getCommonPromptsDir(), 'common');
|
|
118
217
|
return dedupe(dirs);
|
|
@@ -122,7 +221,13 @@ function promptFolderDirs(userPaths, folder, options) {
|
|
|
122
221
|
}
|
|
123
222
|
push(userPaths.getUserPromptsDir(), 'user');
|
|
124
223
|
if (ref.folder) {
|
|
224
|
+
// Above the packs, not below. A user may create their own pack, and a pack
|
|
225
|
+
// folder named `narrator`, `character`, `story_moderator` or `default`
|
|
226
|
+
// would otherwise hijack a name the server hardcodes.
|
|
125
227
|
pushFolder(path.join(userPaths.getCommonPromptsDir(), ref.folder), 'common');
|
|
228
|
+
// Per pack, overlay then installed — not all overlays then all installs,
|
|
229
|
+
// which would let one pack's shipped file beat another pack's overlay.
|
|
230
|
+
// Alphabetical because the enabled set's own order carries no meaning.
|
|
126
231
|
for (const pack of enabledPacksOf(options)) {
|
|
127
232
|
pushFolder(path.join(userPaths.getUserPackDir(pack), 'prompts', ref.folder), 'pack-overlay', pack);
|
|
128
233
|
pushFolder(path.join(userPaths.getPackDir(pack), 'prompts', ref.folder), 'pack', pack);
|
|
@@ -131,9 +236,26 @@ function promptFolderDirs(userPaths, folder, options) {
|
|
|
131
236
|
push(userPaths.getCommonPromptsDir(), 'common');
|
|
132
237
|
return dedupe(dirs);
|
|
133
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* The same directories, lowest precedence first.
|
|
241
|
+
*
|
|
242
|
+
* `listPromptFiles` and `listPromptFilesWithScope` scan directories into a Map so
|
|
243
|
+
* that a later entry overwrites an earlier one, which means they need the
|
|
244
|
+
* opposite order from a first-hit-wins lookup.
|
|
245
|
+
*/
|
|
134
246
|
function promptFolderDirsLowestFirst(userPaths, folder, options) {
|
|
135
247
|
return [...promptFolderDirs(userPaths, folder, options)].reverse();
|
|
136
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Every path a lookup would try, highest precedence first.
|
|
251
|
+
*
|
|
252
|
+
* @param userPaths The per-user path service
|
|
253
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
254
|
+
* @param fileName The file name without an extension
|
|
255
|
+
* @param extension The extension, including the dot (`.prompt`, `.json`, `.mock`)
|
|
256
|
+
* @param options Enablement, for the bare-name pack scan
|
|
257
|
+
* @returns The candidate paths, which may not exist
|
|
258
|
+
*/
|
|
137
259
|
function promptSearchPaths(userPaths, folder, fileName, extension, options) {
|
|
138
260
|
const file = `${fileName}${extension}`;
|
|
139
261
|
return promptFolderDirs(userPaths, folder, options).map((entry) => ({
|
|
@@ -141,6 +263,16 @@ function promptSearchPaths(userPaths, folder, fileName, extension, options) {
|
|
|
141
263
|
absolutePath: path.join(entry.dir, file),
|
|
142
264
|
}));
|
|
143
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Finds a prompt file.
|
|
268
|
+
*
|
|
269
|
+
* @param userPaths The per-user path service
|
|
270
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
271
|
+
* @param fileName The file name without an extension
|
|
272
|
+
* @param extension The extension, including the dot
|
|
273
|
+
* @param options Enablement, for the bare-name pack scan
|
|
274
|
+
* @returns The first candidate that exists, or null
|
|
275
|
+
*/
|
|
144
276
|
function resolvePromptFile(userPaths, folder, fileName, extension, options) {
|
|
145
277
|
for (const candidate of promptSearchPaths(userPaths, folder, fileName, extension, options)) {
|
|
146
278
|
if (fs.existsSync(candidate.absolutePath)) {
|
|
@@ -149,13 +281,45 @@ function resolvePromptFile(userPaths, folder, fileName, extension, options) {
|
|
|
149
281
|
}
|
|
150
282
|
return null;
|
|
151
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Whether a folder reference reaches a directory that exists.
|
|
286
|
+
*
|
|
287
|
+
* A reference that reaches nothing still *resolves*: every lookup ends at the
|
|
288
|
+
* shared prompts roots, so a misspelled folder — or a pack folder named bare by a
|
|
289
|
+
* user who has not enabled the pack — quietly produces a generic agent instead of
|
|
290
|
+
* the role that was asked for. Only a folder-scoped directory answers the
|
|
291
|
+
* question, which is why {@link PromptDir.folderScoped} exists.
|
|
292
|
+
*
|
|
293
|
+
* Unlike {@link resolvePromptFile} this consults enablement for a bare name, and
|
|
294
|
+
* that is the point: it answers "would this reference behave as the caller
|
|
295
|
+
* expects", and a bare pack folder with the pack switched off would not.
|
|
296
|
+
*
|
|
297
|
+
* @param userPaths The per-user path service
|
|
298
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
299
|
+
* @param options Enablement, for the bare-name pack scan
|
|
300
|
+
* @returns True when the folder exists in some tier, or names the prompts root
|
|
301
|
+
*/
|
|
152
302
|
function promptFolderExists(userPaths, folder, options) {
|
|
303
|
+
// The root is not a folder and is always there; `shared` and '' both mean it.
|
|
153
304
|
if (!parsePromptFolder(folder).folder)
|
|
154
305
|
return true;
|
|
155
306
|
return promptFolderDirs(userPaths, folder, options).some((entry) => entry.folderScoped && fs.existsSync(entry.dir));
|
|
156
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Every prompt folder reachable by this user, one entry per name.
|
|
310
|
+
*
|
|
311
|
+
* Unlike resolution, listing **is** gated: a disabled pack's folders do not
|
|
312
|
+
* appear. Where the same name exists in more than one tier the highest
|
|
313
|
+
* precedence wins, except that a pack folder never merges with a bare one — they
|
|
314
|
+
* are different values and both are listed.
|
|
315
|
+
*
|
|
316
|
+
* @param userPaths The per-user path service
|
|
317
|
+
* @param options Enablement, which here gates the pack folders themselves
|
|
318
|
+
* @returns The folders, sorted by the value that names them
|
|
319
|
+
*/
|
|
157
320
|
function listPromptFolderRefs(userPaths, options) {
|
|
158
321
|
const byValue = new Map();
|
|
322
|
+
// Lowest precedence first, so a later write wins the bare name.
|
|
159
323
|
const add = (dir, tier, pack) => {
|
|
160
324
|
for (const name of subdirectoriesOf(dir)) {
|
|
161
325
|
const value = pack ? `${pack}${exports.PACK_FOLDER_SEPARATOR}${name}` : name;
|
|
@@ -170,6 +334,19 @@ function listPromptFolderRefs(userPaths, options) {
|
|
|
170
334
|
add(userPaths.getUserPromptsDir(), 'user', null);
|
|
171
335
|
return [...byValue.values()].sort((a, b) => a.value.localeCompare(b.value));
|
|
172
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Where a write to this folder belongs.
|
|
339
|
+
*
|
|
340
|
+
* Derived from the *reference*, never from where the file happened to resolve.
|
|
341
|
+
* Editing a pack folder's `perceive.prompt` that fell through to
|
|
342
|
+
* `common/prompts/perceive.prompt` must not write the user's prompts root — that
|
|
343
|
+
* would turn an edit made inside one pack into a global override for every folder
|
|
344
|
+
* the user has.
|
|
345
|
+
*
|
|
346
|
+
* @param userPaths The per-user path service
|
|
347
|
+
* @param folder A prompt folder reference, bare or pack-qualified
|
|
348
|
+
* @returns The directory to write into, which may not exist yet
|
|
349
|
+
*/
|
|
173
350
|
function promptWriteDir(userPaths, folder) {
|
|
174
351
|
const ref = parsePromptFolder(folder);
|
|
175
352
|
const root = ref.pack
|
|
@@ -177,15 +354,20 @@ function promptWriteDir(userPaths, folder) {
|
|
|
177
354
|
: userPaths.getUserPromptsDir();
|
|
178
355
|
return ref.folder ? path.join(root, ref.folder) : root;
|
|
179
356
|
}
|
|
357
|
+
/** Drops repeated directories, keeping the highest-precedence occurrence. */
|
|
180
358
|
function dedupe(dirs) {
|
|
181
359
|
const seen = new Set();
|
|
182
360
|
return dirs.filter((entry) => {
|
|
361
|
+
// An agent with an empty promptFolder collapses its folder-specific paths
|
|
362
|
+
// onto its root ones. That used to be an accident of path.join; here it is
|
|
363
|
+
// explicit, so the two forms cannot drift.
|
|
183
364
|
if (seen.has(entry.dir))
|
|
184
365
|
return false;
|
|
185
366
|
seen.add(entry.dir);
|
|
186
367
|
return true;
|
|
187
368
|
});
|
|
188
369
|
}
|
|
370
|
+
/** Subdirectory names of a directory that may not exist. */
|
|
189
371
|
function subdirectoriesOf(dir) {
|
|
190
372
|
if (!fs.existsSync(dir))
|
|
191
373
|
return [];
|
|
@@ -1,17 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-user Briyah settings.
|
|
3
|
+
*
|
|
4
|
+
* Today that is only which packs the user has enabled, but it exists as its own
|
|
5
|
+
* file rather than a field somewhere for two reasons.
|
|
6
|
+
*
|
|
7
|
+
* **It is not `user-preferences.json`.** That file is the host's: its contract
|
|
8
|
+
* says preferences are application-defined and returned as-is, and
|
|
9
|
+
* `saveUserPreferences` writes the whole object. A host storing a theme there
|
|
10
|
+
* would wipe pack enablement on the next save.
|
|
11
|
+
*
|
|
12
|
+
* **It is not on `UserPathsService`.** That resolves paths, and it is faked with
|
|
13
|
+
* bare object literals across the specs — every method added to it has to be
|
|
14
|
+
* added to those fakes too.
|
|
15
|
+
*/
|
|
1
16
|
import { UserPathsService } from './user-paths.service';
|
|
17
|
+
/** The settings a user carries. Every field optional, so an absent file is valid. */
|
|
2
18
|
export interface UserConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Packs this user has switched on. Absent and empty both mean none — a pack is
|
|
21
|
+
* off until the user turns it on, matching how tool packs have always behaved.
|
|
22
|
+
*/
|
|
3
23
|
enabledPacks?: string[];
|
|
4
24
|
}
|
|
5
25
|
export declare class UserConfigService {
|
|
6
26
|
private readonly userPaths;
|
|
7
27
|
private cached;
|
|
8
28
|
private cachedAtMs;
|
|
29
|
+
/**
|
|
30
|
+
* How long a read is trusted before the file is consulted again.
|
|
31
|
+
*
|
|
32
|
+
* `UserServiceManager` keeps an `AppService` for 30 minutes, so caching for the
|
|
33
|
+
* life of the instance would mean a second tab, another process or the SDK
|
|
34
|
+
* toggling a pack and this one never noticing. A second is long enough to
|
|
35
|
+
* collapse the burst of reads a single page load produces and short enough that
|
|
36
|
+
* nobody sees a stale list.
|
|
37
|
+
*/
|
|
9
38
|
private static readonly CACHE_MS;
|
|
10
39
|
constructor(userPaths: UserPathsService);
|
|
40
|
+
/**
|
|
41
|
+
* Reads this user's settings.
|
|
42
|
+
* @returns The settings, or an empty object when there is no file or it is unreadable
|
|
43
|
+
*/
|
|
11
44
|
get(): UserConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Merges a patch into this user's settings.
|
|
47
|
+
* @param patch The fields to change
|
|
48
|
+
* @returns The settings as they now stand
|
|
49
|
+
*/
|
|
12
50
|
update(patch: Partial<UserConfig>): UserConfig;
|
|
51
|
+
/**
|
|
52
|
+
* The packs this user has enabled.
|
|
53
|
+
*
|
|
54
|
+
* Names only — whether a pack of that name is actually installed is the pack
|
|
55
|
+
* registry's business, so a pack that was enabled and then removed from disk
|
|
56
|
+
* stays in the list and comes back if it is reinstalled.
|
|
57
|
+
*
|
|
58
|
+
* @returns The enabled pack names
|
|
59
|
+
*/
|
|
13
60
|
enabledPacks(): readonly string[];
|
|
61
|
+
/**
|
|
62
|
+
* Turns one pack on or off, leaving the rest alone.
|
|
63
|
+
* @param packName The pack to change
|
|
64
|
+
* @param enabled Whether it should be on
|
|
65
|
+
*/
|
|
14
66
|
setPackEnabled(packName: string, enabled: boolean): void;
|
|
15
67
|
private configPath;
|
|
68
|
+
/**
|
|
69
|
+
* Reads the file, treating anything unreadable as absent.
|
|
70
|
+
*
|
|
71
|
+
* Throwing here would take down every page that lists a prompt or an artifact,
|
|
72
|
+
* because enablement is consulted on all of them. A corrupt file costs the user
|
|
73
|
+
* their pack selection, which they can set again.
|
|
74
|
+
*/
|
|
16
75
|
private read;
|
|
17
76
|
}
|