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
|
@@ -9,8 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.StoryMessageService = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const events_1 = require("events");
|
|
12
|
+
/**
|
|
13
|
+
* Service for managing SSE connections for story message updates
|
|
14
|
+
* Uses event-driven updates triggered by room state changes (no polling)
|
|
15
|
+
*/
|
|
12
16
|
let StoryMessageService = class StoryMessageService {
|
|
13
17
|
messageEmitters = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Gets or creates a message emitter for a story
|
|
20
|
+
* @param storyId The story ID
|
|
21
|
+
* @returns The event emitter for this story
|
|
22
|
+
*/
|
|
14
23
|
getOrCreateEmitter(storyId) {
|
|
15
24
|
let emitter = this.messageEmitters.get(storyId);
|
|
16
25
|
if (!emitter) {
|
|
@@ -19,14 +28,31 @@ let StoryMessageService = class StoryMessageService {
|
|
|
19
28
|
}
|
|
20
29
|
return emitter;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the message emitter for a story
|
|
33
|
+
* @param storyId The story ID
|
|
34
|
+
* @returns The event emitter or undefined if not found
|
|
35
|
+
*/
|
|
22
36
|
getEmitter(storyId) {
|
|
23
37
|
return this.messageEmitters.get(storyId);
|
|
24
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Emits a `'story-state'` event for a story.
|
|
41
|
+
* Called by the room's `onStateChange` callback after every turn.
|
|
42
|
+
* @param storyId The story ID
|
|
43
|
+
* @param state The updated story state
|
|
44
|
+
*/
|
|
25
45
|
emitStoryState(storyId, state) {
|
|
26
46
|
const emitter = this.getOrCreateEmitter(storyId);
|
|
27
47
|
const payload = { type: 'story-state', state, timestamp: Date.now() };
|
|
28
48
|
emitter.emit('story-state', payload);
|
|
29
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Emits a `'suggest-introduce-character'` event for a story.
|
|
52
|
+
* Called when the narrator decides a new character should enter the story.
|
|
53
|
+
* @param storyId The story ID
|
|
54
|
+
* @param characterName The name of the character to introduce
|
|
55
|
+
*/
|
|
30
56
|
emitIntroduceCharacter(storyId, characterName) {
|
|
31
57
|
const emitter = this.getOrCreateEmitter(storyId);
|
|
32
58
|
const payload = {
|
|
@@ -36,6 +62,11 @@ let StoryMessageService = class StoryMessageService {
|
|
|
36
62
|
};
|
|
37
63
|
emitter.emit('suggest-introduce-character', payload);
|
|
38
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Emits a `'suggest-progress-chapter'` event for a story.
|
|
67
|
+
* Called when the narrator decides the story is ready to advance to the next chapter.
|
|
68
|
+
* @param storyId The story ID
|
|
69
|
+
*/
|
|
39
70
|
emitProgressChapter(storyId) {
|
|
40
71
|
const emitter = this.getOrCreateEmitter(storyId);
|
|
41
72
|
const payload = {
|
|
@@ -44,6 +75,14 @@ let StoryMessageService = class StoryMessageService {
|
|
|
44
75
|
};
|
|
45
76
|
emitter.emit('suggest-progress-chapter', payload);
|
|
46
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Emits a `'story-error'` event for a story.
|
|
80
|
+
* Called by the room's `onError` callback when room processing fails.
|
|
81
|
+
* Named `'story-error'` rather than `'error'` to avoid Node.js throwing when
|
|
82
|
+
* no listener is attached.
|
|
83
|
+
* @param storyId The story ID
|
|
84
|
+
* @param error The error that occurred
|
|
85
|
+
*/
|
|
47
86
|
emitError(storyId, error) {
|
|
48
87
|
const emitter = this.getOrCreateEmitter(storyId);
|
|
49
88
|
const payload = {
|
|
@@ -54,6 +93,10 @@ let StoryMessageService = class StoryMessageService {
|
|
|
54
93
|
};
|
|
55
94
|
emitter.emit('story-error', payload);
|
|
56
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Cleans up the message emitter for a story
|
|
98
|
+
* @param storyId The story ID
|
|
99
|
+
*/
|
|
57
100
|
cleanup(storyId) {
|
|
58
101
|
const emitter = this.messageEmitters.get(storyId);
|
|
59
102
|
if (emitter) {
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
/**
|
|
3
|
+
* Service for tracking and emitting progress updates during story creation
|
|
4
|
+
*/
|
|
2
5
|
export declare class StoryProgressService {
|
|
3
6
|
private progressMap;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new progress emitter for a story
|
|
9
|
+
* @param storyId The story ID
|
|
10
|
+
* @returns The event emitter for this story
|
|
11
|
+
*/
|
|
4
12
|
createProgressEmitter(storyId: string): EventEmitter;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the progress emitter for a story
|
|
15
|
+
* @param storyId The story ID
|
|
16
|
+
* @returns The event emitter or undefined if not found
|
|
17
|
+
*/
|
|
5
18
|
getProgressEmitter(storyId: string): EventEmitter | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Emits a progress update for a story
|
|
21
|
+
* @param storyId The story ID
|
|
22
|
+
* @param step The current step identifier
|
|
23
|
+
* @param message The progress message to display
|
|
24
|
+
*/
|
|
6
25
|
emitProgress(storyId: string, step: string, message: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Cleans up the progress emitter for a story
|
|
28
|
+
* @param storyId The story ID
|
|
29
|
+
*/
|
|
7
30
|
cleanup(storyId: string): void;
|
|
8
31
|
}
|
|
@@ -10,16 +10,35 @@ exports.StoryProgressService = void 0;
|
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const events_1 = require("events");
|
|
12
12
|
const logger_1 = require("../common/logger");
|
|
13
|
+
/**
|
|
14
|
+
* Service for tracking and emitting progress updates during story creation
|
|
15
|
+
*/
|
|
13
16
|
let StoryProgressService = class StoryProgressService {
|
|
14
17
|
progressMap = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new progress emitter for a story
|
|
20
|
+
* @param storyId The story ID
|
|
21
|
+
* @returns The event emitter for this story
|
|
22
|
+
*/
|
|
15
23
|
createProgressEmitter(storyId) {
|
|
16
24
|
const emitter = new events_1.EventEmitter();
|
|
17
25
|
this.progressMap.set(storyId, emitter);
|
|
18
26
|
return emitter;
|
|
19
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Gets the progress emitter for a story
|
|
30
|
+
* @param storyId The story ID
|
|
31
|
+
* @returns The event emitter or undefined if not found
|
|
32
|
+
*/
|
|
20
33
|
getProgressEmitter(storyId) {
|
|
21
34
|
return this.progressMap.get(storyId);
|
|
22
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Emits a progress update for a story
|
|
38
|
+
* @param storyId The story ID
|
|
39
|
+
* @param step The current step identifier
|
|
40
|
+
* @param message The progress message to display
|
|
41
|
+
*/
|
|
23
42
|
emitProgress(storyId, step, message) {
|
|
24
43
|
const emitter = this.progressMap.get(storyId);
|
|
25
44
|
if (emitter) {
|
|
@@ -31,6 +50,10 @@ let StoryProgressService = class StoryProgressService {
|
|
|
31
50
|
logger_1.logger.log(`[Story ${storyId}] ${step}: ${message}`);
|
|
32
51
|
}
|
|
33
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Cleans up the progress emitter for a story
|
|
55
|
+
* @param storyId The story ID
|
|
56
|
+
*/
|
|
34
57
|
cleanup(storyId) {
|
|
35
58
|
const emitter = this.progressMap.get(storyId);
|
|
36
59
|
if (emitter) {
|
|
@@ -2,23 +2,115 @@ import { UserPathsService } from '../config/user-paths.service';
|
|
|
2
2
|
import { StoryInfo, ChapterInfo } from '../../../shared/types/app.types';
|
|
3
3
|
import { RoomMessage } from '../room/message';
|
|
4
4
|
import { RoomStoreService } from '../room/room-store.service';
|
|
5
|
+
/**
|
|
6
|
+
* A service that stores and retrieves Story objects from the filesystem
|
|
7
|
+
* Each story is stored in its own folder in server/data/stories/[story-id]/
|
|
8
|
+
* with a metadata.json file containing the story data
|
|
9
|
+
*/
|
|
5
10
|
export declare class StoryStoreService {
|
|
6
11
|
private readonly userPaths;
|
|
7
12
|
private readonly roomStore;
|
|
8
13
|
private readonly storiesDir;
|
|
9
14
|
constructor(userPaths: UserPathsService, roomStore: RoomStoreService);
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new story with a GUID as its ID and directory structure
|
|
17
|
+
* Initial metadata contains only id and name - other properties should be set via updateStoryMetadata
|
|
18
|
+
* @param name The story name
|
|
19
|
+
* @returns The story information including the generated ID
|
|
20
|
+
*/
|
|
10
21
|
createStory(name: string): StoryInfo;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a story by its ID
|
|
24
|
+
* @param id The story ID
|
|
25
|
+
* @returns The story information, or null if not found
|
|
26
|
+
*/
|
|
11
27
|
getStory(id: string): StoryInfo | null;
|
|
28
|
+
/**
|
|
29
|
+
* Updates the story metadata
|
|
30
|
+
* @param id The story ID
|
|
31
|
+
* @param storyInfo The updated story information
|
|
32
|
+
* @returns True if successful, false otherwise
|
|
33
|
+
*/
|
|
12
34
|
updateStoryMetadata(id: string, storyInfo: StoryInfo): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Saves the initial story creation parameters to a separate file for historical purposes
|
|
37
|
+
* @param id The story ID
|
|
38
|
+
* @param idea The original story idea or imported story text
|
|
39
|
+
* @param userCharacterDesc The original user character description
|
|
40
|
+
* @param otherCharactersDesc The original other characters description
|
|
41
|
+
* @returns True if successful, false otherwise
|
|
42
|
+
*/
|
|
13
43
|
saveStoryCreationParameters(id: string, idea: string, userCharacterDesc: string, otherCharactersDesc: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Lists all stories
|
|
46
|
+
* @returns Array of story information
|
|
47
|
+
*/
|
|
14
48
|
getAllStories(): StoryInfo[];
|
|
49
|
+
/**
|
|
50
|
+
* Removes a story from the filesystem
|
|
51
|
+
* @param id The story ID
|
|
52
|
+
* @returns True if the story was found and removed, false otherwise
|
|
53
|
+
*/
|
|
15
54
|
removeStory(id: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Lists all chapters for a story
|
|
57
|
+
* @param storyId The story ID
|
|
58
|
+
* @returns Array of ChapterInfo objects sorted by chapter number
|
|
59
|
+
*/
|
|
16
60
|
listChapters(storyId: string): ChapterInfo[];
|
|
61
|
+
/**
|
|
62
|
+
* Gets the content of a specific chapter
|
|
63
|
+
* @param storyId The story ID
|
|
64
|
+
* @param chapterIndex The chapter number (e.g., 1, 2, 3)
|
|
65
|
+
* @returns The chapter content from the messages file, or null if not found
|
|
66
|
+
*/
|
|
17
67
|
getChapterContent(storyId: string, chapterIndex: number): Promise<RoomMessage[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the next chapter index by examining existing chapters
|
|
70
|
+
* @param storyId The story ID
|
|
71
|
+
* @returns The next chapter index (e.g., 1, 2, 3...)
|
|
72
|
+
*/
|
|
18
73
|
getNextChapterIndex(storyId: string): number;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new chapter folder and copies the current room messages to it
|
|
76
|
+
* @param storyId The story ID
|
|
77
|
+
* @param chapterIndex The chapter index
|
|
78
|
+
* @param chapterTitle The title for this chapter
|
|
79
|
+
* @returns True if successful, false otherwise
|
|
80
|
+
*/
|
|
19
81
|
createChapterBackup(storyId: string, chapterIndex: number, chapterTitle: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Saves custom content to a chapter folder
|
|
84
|
+
* @param storyId The story ID
|
|
85
|
+
* @param chapterIndex The chapter index
|
|
86
|
+
* @param content The content to save
|
|
87
|
+
* @returns True if successful, false otherwise
|
|
88
|
+
*/
|
|
20
89
|
saveChapterContent(storyId: string, chapterIndex: number, content: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Deletes a chapter folder and all its contents
|
|
92
|
+
* @param storyId The story ID
|
|
93
|
+
* @param chapterIndex The chapter index
|
|
94
|
+
* @returns True if successful, false otherwise
|
|
95
|
+
*/
|
|
21
96
|
deleteChapter(storyId: string, chapterIndex: number): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Restores room files (messages + artifacts) from a chapter backup back into
|
|
99
|
+
* the live room folder, overwriting any current files. The chapter folder's
|
|
100
|
+
* agents/ subdirectory and its metadata.json are left in place — agents are
|
|
101
|
+
* restored separately via {@link restoreAgentsFromChapter}, and the chapter
|
|
102
|
+
* metadata describes the backup itself.
|
|
103
|
+
* @param storyId The story ID
|
|
104
|
+
* @param chapterIndex The chapter to restore from
|
|
105
|
+
* @returns Number of files restored, or -1 on error
|
|
106
|
+
*/
|
|
22
107
|
restoreRoomFilesFromChapter(storyId: string, chapterIndex: number): number;
|
|
108
|
+
/**
|
|
109
|
+
* Restores agent message histories from a chapter backup
|
|
110
|
+
* @param storyId The story ID
|
|
111
|
+
* @param chapterIndex The chapter to restore from
|
|
112
|
+
* @param agentStore The agent store service for loading agents
|
|
113
|
+
* @returns Array of agent IDs that were restored
|
|
114
|
+
*/
|
|
23
115
|
restoreAgentsFromChapter(storyId: string, chapterIndex: number, agentStore: any): Promise<string[]>;
|
|
24
116
|
}
|
|
@@ -50,6 +50,11 @@ const fs = __importStar(require("fs"));
|
|
|
50
50
|
const path = __importStar(require("path"));
|
|
51
51
|
const room_store_service_1 = require("../room/room-store.service");
|
|
52
52
|
const logger_1 = require("../common/logger");
|
|
53
|
+
/**
|
|
54
|
+
* A service that stores and retrieves Story objects from the filesystem
|
|
55
|
+
* Each story is stored in its own folder in server/data/stories/[story-id]/
|
|
56
|
+
* with a metadata.json file containing the story data
|
|
57
|
+
*/
|
|
53
58
|
let StoryStoreService = class StoryStoreService {
|
|
54
59
|
userPaths;
|
|
55
60
|
roomStore;
|
|
@@ -57,16 +62,27 @@ let StoryStoreService = class StoryStoreService {
|
|
|
57
62
|
constructor(userPaths, roomStore) {
|
|
58
63
|
this.userPaths = userPaths;
|
|
59
64
|
this.roomStore = roomStore;
|
|
65
|
+
// Stories are stored in server/data/user/{userId}/stories/
|
|
60
66
|
this.storiesDir = path.join(this.userPaths.getUserDataDir(), 'stories');
|
|
67
|
+
// Create the stories directory if it doesn't exist
|
|
61
68
|
if (!fs.existsSync(this.storiesDir)) {
|
|
62
69
|
fs.mkdirSync(this.storiesDir, { recursive: true });
|
|
63
70
|
}
|
|
64
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new story with a GUID as its ID and directory structure
|
|
74
|
+
* Initial metadata contains only id and name - other properties should be set via updateStoryMetadata
|
|
75
|
+
* @param name The story name
|
|
76
|
+
* @returns The story information including the generated ID
|
|
77
|
+
*/
|
|
65
78
|
createStory(name) {
|
|
79
|
+
// Generate a GUID for the story
|
|
66
80
|
const storyId = (0, crypto_1.randomUUID)();
|
|
81
|
+
// Create the story folder and subfolders
|
|
67
82
|
const storyFolder = path.join(this.storiesDir, storyId);
|
|
68
83
|
const chaptersFolder = path.join(storyFolder, 'chapters');
|
|
69
84
|
fs.mkdirSync(chaptersFolder, { recursive: true });
|
|
85
|
+
// Create minimal initial story metadata
|
|
70
86
|
const storyInfo = {
|
|
71
87
|
aiModel: '',
|
|
72
88
|
aiService: '',
|
|
@@ -84,18 +100,26 @@ let StoryStoreService = class StoryStoreService {
|
|
|
84
100
|
scenario: '',
|
|
85
101
|
characters: [],
|
|
86
102
|
};
|
|
103
|
+
// Write the metadata.json file
|
|
87
104
|
const metadataPath = path.join(storyFolder, 'metadata.json');
|
|
88
105
|
fs.writeFileSync(metadataPath, JSON.stringify(storyInfo, null, 2));
|
|
89
106
|
logger_1.logger.log(`Created story: ${name} (${storyId})`);
|
|
90
107
|
return storyInfo;
|
|
91
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves a story by its ID
|
|
111
|
+
* @param id The story ID
|
|
112
|
+
* @returns The story information, or null if not found
|
|
113
|
+
*/
|
|
92
114
|
getStory(id) {
|
|
93
115
|
const storyFolder = path.join(this.storiesDir, id);
|
|
94
116
|
const metadataPath = path.join(storyFolder, 'metadata.json');
|
|
117
|
+
// Check if the story folder and metadata file exist
|
|
95
118
|
if (!fs.existsSync(metadataPath)) {
|
|
96
119
|
return null;
|
|
97
120
|
}
|
|
98
121
|
try {
|
|
122
|
+
// Read and parse the metadata file
|
|
99
123
|
const metadataContent = fs.readFileSync(metadataPath, 'utf8');
|
|
100
124
|
const storyInfo = JSON.parse(metadataContent);
|
|
101
125
|
return storyInfo;
|
|
@@ -105,14 +129,22 @@ let StoryStoreService = class StoryStoreService {
|
|
|
105
129
|
return null;
|
|
106
130
|
}
|
|
107
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Updates the story metadata
|
|
134
|
+
* @param id The story ID
|
|
135
|
+
* @param storyInfo The updated story information
|
|
136
|
+
* @returns True if successful, false otherwise
|
|
137
|
+
*/
|
|
108
138
|
updateStoryMetadata(id, storyInfo) {
|
|
109
139
|
const storyFolder = path.join(this.storiesDir, id);
|
|
110
140
|
const metadataPath = path.join(storyFolder, 'metadata.json');
|
|
141
|
+
// Check if the story directory exists (may have been deleted during cleanup)
|
|
111
142
|
if (!fs.existsSync(storyFolder)) {
|
|
112
143
|
logger_1.logger.warn(`Cannot update metadata for story ${id}: directory does not exist (likely cleaned up after error)`);
|
|
113
144
|
return false;
|
|
114
145
|
}
|
|
115
146
|
try {
|
|
147
|
+
// Write the updated metadata
|
|
116
148
|
fs.writeFileSync(metadataPath, JSON.stringify(storyInfo, null, 2));
|
|
117
149
|
return true;
|
|
118
150
|
}
|
|
@@ -121,9 +153,18 @@ let StoryStoreService = class StoryStoreService {
|
|
|
121
153
|
return false;
|
|
122
154
|
}
|
|
123
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Saves the initial story creation parameters to a separate file for historical purposes
|
|
158
|
+
* @param id The story ID
|
|
159
|
+
* @param idea The original story idea or imported story text
|
|
160
|
+
* @param userCharacterDesc The original user character description
|
|
161
|
+
* @param otherCharactersDesc The original other characters description
|
|
162
|
+
* @returns True if successful, false otherwise
|
|
163
|
+
*/
|
|
124
164
|
saveStoryCreationParameters(id, idea, userCharacterDesc, otherCharactersDesc) {
|
|
125
165
|
const storyFolder = path.join(this.storiesDir, id);
|
|
126
166
|
const creationParamsPath = path.join(storyFolder, 'story_creation.json');
|
|
167
|
+
// Check if the story directory exists
|
|
127
168
|
if (!fs.existsSync(storyFolder)) {
|
|
128
169
|
logger_1.logger.warn(`Cannot save creation parameters for story ${id}: directory does not exist`);
|
|
129
170
|
return false;
|
|
@@ -143,16 +184,23 @@ let StoryStoreService = class StoryStoreService {
|
|
|
143
184
|
return false;
|
|
144
185
|
}
|
|
145
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Lists all stories
|
|
189
|
+
* @returns Array of story information
|
|
190
|
+
*/
|
|
146
191
|
getAllStories() {
|
|
147
192
|
const stories = [];
|
|
148
193
|
try {
|
|
194
|
+
// Check if the stories directory exists
|
|
149
195
|
if (!fs.existsSync(this.storiesDir)) {
|
|
150
196
|
return stories;
|
|
151
197
|
}
|
|
198
|
+
// Read all directories in the stories folder
|
|
152
199
|
const storyFolders = fs
|
|
153
200
|
.readdirSync(this.storiesDir, { withFileTypes: true })
|
|
154
201
|
.filter((dirent) => dirent.isDirectory())
|
|
155
202
|
.map((dirent) => dirent.name);
|
|
203
|
+
// Load each story's metadata
|
|
156
204
|
for (const storyId of storyFolders) {
|
|
157
205
|
const story = this.getStory(storyId);
|
|
158
206
|
if (story) {
|
|
@@ -166,12 +214,19 @@ let StoryStoreService = class StoryStoreService {
|
|
|
166
214
|
return stories;
|
|
167
215
|
}
|
|
168
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Removes a story from the filesystem
|
|
219
|
+
* @param id The story ID
|
|
220
|
+
* @returns True if the story was found and removed, false otherwise
|
|
221
|
+
*/
|
|
169
222
|
removeStory(id) {
|
|
170
223
|
const storyFolder = path.join(this.storiesDir, id);
|
|
224
|
+
// Check if the story folder exists
|
|
171
225
|
if (!fs.existsSync(storyFolder)) {
|
|
172
226
|
return false;
|
|
173
227
|
}
|
|
174
228
|
try {
|
|
229
|
+
// Remove the entire story folder
|
|
175
230
|
fs.rmSync(storyFolder, { recursive: true, force: true });
|
|
176
231
|
logger_1.logger.log(`Deleted story: ${id}`);
|
|
177
232
|
return true;
|
|
@@ -181,6 +236,11 @@ let StoryStoreService = class StoryStoreService {
|
|
|
181
236
|
return false;
|
|
182
237
|
}
|
|
183
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Lists all chapters for a story
|
|
241
|
+
* @param storyId The story ID
|
|
242
|
+
* @returns Array of ChapterInfo objects sorted by chapter number
|
|
243
|
+
*/
|
|
184
244
|
listChapters(storyId) {
|
|
185
245
|
const chaptersFolder = path.join(this.storiesDir, storyId, 'chapters');
|
|
186
246
|
if (!fs.existsSync(chaptersFolder)) {
|
|
@@ -191,16 +251,19 @@ let StoryStoreService = class StoryStoreService {
|
|
|
191
251
|
const chapterInfos = [];
|
|
192
252
|
for (const item of items) {
|
|
193
253
|
const chapterPath = path.join(chaptersFolder, item);
|
|
254
|
+
// Skip if not a directory
|
|
194
255
|
if (!fs.statSync(chapterPath).isDirectory()) {
|
|
195
256
|
continue;
|
|
196
257
|
}
|
|
258
|
+
// Extract chapter number from directory name (e.g., "chapter_1" -> 1)
|
|
197
259
|
const match = item.match(/^chapter_(\d+)$/);
|
|
198
260
|
if (!match) {
|
|
199
261
|
continue;
|
|
200
262
|
}
|
|
201
263
|
const chapterNum = parseInt(match[1], 10);
|
|
264
|
+
// Read metadata.json to get the chapter title
|
|
202
265
|
const metadataPath = path.join(chapterPath, 'metadata.json');
|
|
203
|
-
let chapterTitle = `Chapter ${chapterNum}`;
|
|
266
|
+
let chapterTitle = `Chapter ${chapterNum}`; // Default title
|
|
204
267
|
if (fs.existsSync(metadataPath)) {
|
|
205
268
|
try {
|
|
206
269
|
const metadataContent = fs.readFileSync(metadataPath, 'utf8');
|
|
@@ -211,6 +274,7 @@ let StoryStoreService = class StoryStoreService {
|
|
|
211
274
|
}
|
|
212
275
|
catch (error) {
|
|
213
276
|
logger_1.logger.error(`Error reading chapter metadata for ${item}:`, error);
|
|
277
|
+
// Continue with default title
|
|
214
278
|
}
|
|
215
279
|
}
|
|
216
280
|
chapterInfos.push({
|
|
@@ -218,6 +282,7 @@ let StoryStoreService = class StoryStoreService {
|
|
|
218
282
|
chapterTitle,
|
|
219
283
|
});
|
|
220
284
|
}
|
|
285
|
+
// Sort by chapter number
|
|
221
286
|
return chapterInfos.sort((a, b) => a.chapterNum - b.chapterNum);
|
|
222
287
|
}
|
|
223
288
|
catch (error) {
|
|
@@ -225,12 +290,20 @@ let StoryStoreService = class StoryStoreService {
|
|
|
225
290
|
return [];
|
|
226
291
|
}
|
|
227
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Gets the content of a specific chapter
|
|
295
|
+
* @param storyId The story ID
|
|
296
|
+
* @param chapterIndex The chapter number (e.g., 1, 2, 3)
|
|
297
|
+
* @returns The chapter content from the messages file, or null if not found
|
|
298
|
+
*/
|
|
228
299
|
async getChapterContent(storyId, chapterIndex) {
|
|
229
300
|
const chapterMessagesPath = path.join(this.storiesDir, storyId, 'chapters', `chapter_${chapterIndex}`, 'messages');
|
|
230
301
|
try {
|
|
302
|
+
// Check if the messages file exists
|
|
231
303
|
if (!fs.existsSync(chapterMessagesPath)) {
|
|
232
304
|
return null;
|
|
233
305
|
}
|
|
306
|
+
// Read and return the messages content
|
|
234
307
|
return await this.roomStore.readRoomMessagesFromFileAsync(chapterMessagesPath);
|
|
235
308
|
}
|
|
236
309
|
catch (error) {
|
|
@@ -238,10 +311,23 @@ let StoryStoreService = class StoryStoreService {
|
|
|
238
311
|
return null;
|
|
239
312
|
}
|
|
240
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Gets the next chapter index by examining existing chapters
|
|
316
|
+
* @param storyId The story ID
|
|
317
|
+
* @returns The next chapter index (e.g., 1, 2, 3...)
|
|
318
|
+
*/
|
|
241
319
|
getNextChapterIndex(storyId) {
|
|
242
320
|
const chapters = this.listChapters(storyId);
|
|
321
|
+
// Return the next index (max + 1, or 1 if no chapters exist)
|
|
243
322
|
return chapters.length > 0 ? Math.max(...chapters.map((c) => c.chapterNum)) + 1 : 1;
|
|
244
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Creates a new chapter folder and copies the current room messages to it
|
|
326
|
+
* @param storyId The story ID
|
|
327
|
+
* @param chapterIndex The chapter index
|
|
328
|
+
* @param chapterTitle The title for this chapter
|
|
329
|
+
* @returns True if successful, false otherwise
|
|
330
|
+
*/
|
|
245
331
|
createChapterBackup(storyId, chapterIndex, chapterTitle) {
|
|
246
332
|
const storyFolder = path.join(this.storiesDir, storyId);
|
|
247
333
|
const chapterFolder = path.join(storyFolder, 'chapters', `chapter_${chapterIndex}`);
|
|
@@ -251,17 +337,21 @@ let StoryStoreService = class StoryStoreService {
|
|
|
251
337
|
logger_1.logger.error(`Cannot create chapter backup: story ${storyId} has no room ID`);
|
|
252
338
|
return false;
|
|
253
339
|
}
|
|
340
|
+
// Create the chapter folder if it doesn't exist
|
|
254
341
|
if (!fs.existsSync(chapterFolder)) {
|
|
255
342
|
fs.mkdirSync(chapterFolder, { recursive: true });
|
|
256
343
|
}
|
|
344
|
+
// Get the room folder path
|
|
257
345
|
const roomFolder = path.join(storyFolder, 'rooms', story.roomId);
|
|
258
346
|
if (!fs.existsSync(roomFolder)) {
|
|
259
347
|
logger_1.logger.warn(`Room folder not found for story ${storyId}`);
|
|
260
348
|
return true;
|
|
261
349
|
}
|
|
350
|
+
// Copy all files from the room folder EXCEPT metadata.json
|
|
262
351
|
const files = fs.readdirSync(roomFolder);
|
|
263
352
|
let copiedCount = 0;
|
|
264
353
|
for (const file of files) {
|
|
354
|
+
// Skip metadata.json - we'll create our own
|
|
265
355
|
if (file === 'metadata.json') {
|
|
266
356
|
continue;
|
|
267
357
|
}
|
|
@@ -272,13 +362,16 @@ let StoryStoreService = class StoryStoreService {
|
|
|
272
362
|
copiedCount++;
|
|
273
363
|
}
|
|
274
364
|
}
|
|
365
|
+
// Copy agent files with their message histories
|
|
275
366
|
const agentsFolder = path.join(storyFolder, 'agents');
|
|
276
367
|
const chapterAgentsFolder = path.join(chapterFolder, 'agents');
|
|
277
368
|
let agentsCopied = 0;
|
|
278
369
|
if (fs.existsSync(agentsFolder)) {
|
|
370
|
+
// Create agents subfolder in chapter backup
|
|
279
371
|
if (!fs.existsSync(chapterAgentsFolder)) {
|
|
280
372
|
fs.mkdirSync(chapterAgentsFolder, { recursive: true });
|
|
281
373
|
}
|
|
374
|
+
// Get room metadata to find which agents are in this room
|
|
282
375
|
const roomMetadataPath = path.join(roomFolder, 'metadata.json');
|
|
283
376
|
let agentIds = [];
|
|
284
377
|
if (fs.existsSync(roomMetadataPath)) {
|
|
@@ -290,6 +383,7 @@ let StoryStoreService = class StoryStoreService {
|
|
|
290
383
|
logger_1.logger.error(`Error reading room metadata for story ${storyId}:`, error);
|
|
291
384
|
}
|
|
292
385
|
}
|
|
386
|
+
// Copy each agent's JSON file
|
|
293
387
|
for (const agentId of agentIds) {
|
|
294
388
|
const sourceAgentFile = path.join(agentsFolder, `${agentId}.json`);
|
|
295
389
|
const targetAgentFile = path.join(chapterAgentsFolder, `${agentId}.json`);
|
|
@@ -299,6 +393,7 @@ let StoryStoreService = class StoryStoreService {
|
|
|
299
393
|
}
|
|
300
394
|
}
|
|
301
395
|
}
|
|
396
|
+
// Create chapter-specific metadata.json
|
|
302
397
|
const chapterMetadata = {
|
|
303
398
|
chapterNum: chapterIndex,
|
|
304
399
|
chapterTitle: chapterTitle,
|
|
@@ -313,13 +408,22 @@ let StoryStoreService = class StoryStoreService {
|
|
|
313
408
|
return false;
|
|
314
409
|
}
|
|
315
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Saves custom content to a chapter folder
|
|
413
|
+
* @param storyId The story ID
|
|
414
|
+
* @param chapterIndex The chapter index
|
|
415
|
+
* @param content The content to save
|
|
416
|
+
* @returns True if successful, false otherwise
|
|
417
|
+
*/
|
|
316
418
|
saveChapterContent(storyId, chapterIndex, content) {
|
|
317
419
|
const storyFolder = path.join(this.storiesDir, storyId);
|
|
318
420
|
const chapterFolder = path.join(storyFolder, 'chapters', `chapter_${chapterIndex}`);
|
|
319
421
|
try {
|
|
422
|
+
// Create the chapter folder if it doesn't exist
|
|
320
423
|
if (!fs.existsSync(chapterFolder)) {
|
|
321
424
|
fs.mkdirSync(chapterFolder, { recursive: true });
|
|
322
425
|
}
|
|
426
|
+
// Write the content to the messages file
|
|
323
427
|
const chapterMessagesPath = path.join(chapterFolder, 'messages');
|
|
324
428
|
fs.writeFileSync(chapterMessagesPath, content, 'utf8');
|
|
325
429
|
logger_1.logger.log(`Saved chapter ${chapterIndex} content for story ${storyId} (${content.length} characters)`);
|
|
@@ -330,12 +434,20 @@ let StoryStoreService = class StoryStoreService {
|
|
|
330
434
|
return false;
|
|
331
435
|
}
|
|
332
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* Deletes a chapter folder and all its contents
|
|
439
|
+
* @param storyId The story ID
|
|
440
|
+
* @param chapterIndex The chapter index
|
|
441
|
+
* @returns True if successful, false otherwise
|
|
442
|
+
*/
|
|
333
443
|
deleteChapter(storyId, chapterIndex) {
|
|
334
444
|
const chapterFolder = path.join(this.storiesDir, storyId, 'chapters', `chapter_${chapterIndex}`);
|
|
335
445
|
try {
|
|
446
|
+
// Check if the chapter folder exists
|
|
336
447
|
if (!fs.existsSync(chapterFolder)) {
|
|
337
448
|
return false;
|
|
338
449
|
}
|
|
450
|
+
// Remove the entire chapter folder
|
|
339
451
|
fs.rmSync(chapterFolder, { recursive: true, force: true });
|
|
340
452
|
logger_1.logger.log(`Deleted chapter ${chapterIndex} for story ${storyId}`);
|
|
341
453
|
return true;
|
|
@@ -345,6 +457,16 @@ let StoryStoreService = class StoryStoreService {
|
|
|
345
457
|
return false;
|
|
346
458
|
}
|
|
347
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Restores room files (messages + artifacts) from a chapter backup back into
|
|
462
|
+
* the live room folder, overwriting any current files. The chapter folder's
|
|
463
|
+
* agents/ subdirectory and its metadata.json are left in place — agents are
|
|
464
|
+
* restored separately via {@link restoreAgentsFromChapter}, and the chapter
|
|
465
|
+
* metadata describes the backup itself.
|
|
466
|
+
* @param storyId The story ID
|
|
467
|
+
* @param chapterIndex The chapter to restore from
|
|
468
|
+
* @returns Number of files restored, or -1 on error
|
|
469
|
+
*/
|
|
348
470
|
restoreRoomFilesFromChapter(storyId, chapterIndex) {
|
|
349
471
|
const storyFolder = path.join(this.storiesDir, storyId);
|
|
350
472
|
const chapterFolder = path.join(storyFolder, 'chapters', `chapter_${chapterIndex}`);
|
|
@@ -383,6 +505,13 @@ let StoryStoreService = class StoryStoreService {
|
|
|
383
505
|
return -1;
|
|
384
506
|
}
|
|
385
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Restores agent message histories from a chapter backup
|
|
510
|
+
* @param storyId The story ID
|
|
511
|
+
* @param chapterIndex The chapter to restore from
|
|
512
|
+
* @param agentStore The agent store service for loading agents
|
|
513
|
+
* @returns Array of agent IDs that were restored
|
|
514
|
+
*/
|
|
386
515
|
async restoreAgentsFromChapter(storyId, chapterIndex, agentStore) {
|
|
387
516
|
const storyFolder = path.join(this.storiesDir, storyId);
|
|
388
517
|
const chapterAgentsFolder = path.join(storyFolder, 'chapters', `chapter_${chapterIndex}`, 'agents');
|
|
@@ -392,6 +521,7 @@ let StoryStoreService = class StoryStoreService {
|
|
|
392
521
|
logger_1.logger.warn(`No agents folder found in chapter ${chapterIndex} backup for story ${storyId}`);
|
|
393
522
|
return restoredAgentIds;
|
|
394
523
|
}
|
|
524
|
+
// Read all agent JSON files from the chapter backup
|
|
395
525
|
const agentFiles = fs
|
|
396
526
|
.readdirSync(chapterAgentsFolder)
|
|
397
527
|
.filter((file) => file.endsWith('.json'));
|
|
@@ -399,10 +529,15 @@ let StoryStoreService = class StoryStoreService {
|
|
|
399
529
|
const agentId = agentFile.replace('.json', '');
|
|
400
530
|
const chapterAgentPath = path.join(chapterAgentsFolder, agentFile);
|
|
401
531
|
try {
|
|
532
|
+
// Read the backed-up agent config
|
|
402
533
|
const backupConfig = JSON.parse(fs.readFileSync(chapterAgentPath, 'utf8'));
|
|
534
|
+
// Get the current agent from memory
|
|
403
535
|
const agent = await agentStore.getAgent(agentId);
|
|
404
536
|
if (agent) {
|
|
537
|
+
// Restore ONLY the history from backup
|
|
538
|
+
// DO NOT restore token counts or costs - user pays for all work done
|
|
405
539
|
agent.history = backupConfig.history || [];
|
|
540
|
+
// Save the restored state to disk
|
|
406
541
|
agent.save();
|
|
407
542
|
restoredAgentIds.push(agentId);
|
|
408
543
|
logger_1.logger.log(`Restored agent ${agentId} history from chapter ${chapterIndex} (${agent.history.length} messages)`);
|