briyah 2.0.3 → 2.0.4
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 +43 -7
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
- 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 +102 -3
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
- 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 +80 -2
- 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 +44 -2
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
- 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 -5
- package/dist-sdk/server/src/ai/agent.d.ts +196 -0
- package/dist-sdk/server/src/ai/agent.js +224 -11
- 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 +38 -1
- 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 +87 -0
- package/dist-sdk/server/src/app.controller.js +272 -12
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1661 -0
- package/dist-sdk/server/src/app.service.js +1837 -4
- 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 +18 -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 +99 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +58 -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/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 +26 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
- package/dist-sdk/server/src/room/room-factory.js +14 -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 +176 -0
- package/dist-sdk/server/src/room/room-store.service.js +238 -5
- package/dist-sdk/server/src/room/room.d.ts +878 -0
- package/dist-sdk/server/src/room/room.js +1291 -23
- 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 +103 -0
- 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 +398 -0
- package/dist-sdk/server/src/story/story.service.js +829 -25
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +22 -0
- 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 +176 -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 +192 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -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 +164 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -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 +116 -0
- 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 +73 -0
- package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
- 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 +285 -13
- package/dist-sdk/shared/types/app.types.js +3 -0
- 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,13 +1,40 @@
|
|
|
1
1
|
import { UserPathsService } from '../config/user-paths.service';
|
|
2
2
|
import { Transaction } from '../../../shared/types/app.types';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing payment transactions
|
|
5
|
+
* Stores transaction records in user-specific directories
|
|
6
|
+
*/
|
|
3
7
|
export declare class TransactionService {
|
|
4
8
|
private userId;
|
|
5
9
|
private userPaths;
|
|
6
10
|
private transactionsDir;
|
|
7
11
|
constructor(userId: string, userPaths: UserPathsService);
|
|
12
|
+
/**
|
|
13
|
+
* Record a new transaction
|
|
14
|
+
* @param amount Amount in dollars
|
|
15
|
+
* @param paymentId Payment provider ID (e.g. a Stripe Payment Intent ID)
|
|
16
|
+
* @param status Initial transaction status
|
|
17
|
+
* @returns Created transaction
|
|
18
|
+
*/
|
|
8
19
|
recordTransaction(amount: number, paymentId: string, status?: 'pending' | 'succeeded' | 'failed' | 'cancelled'): Promise<Transaction>;
|
|
20
|
+
/**
|
|
21
|
+
* Update transaction status
|
|
22
|
+
* @param paymentId Payment provider ID
|
|
23
|
+
* @param status New status
|
|
24
|
+
*/
|
|
9
25
|
updateTransactionStatus(paymentId: string, status: 'pending' | 'succeeded' | 'failed' | 'cancelled'): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get transaction by payment provider ID
|
|
28
|
+
* @param paymentId Payment provider ID
|
|
29
|
+
* @returns Transaction or null if not found
|
|
30
|
+
*/
|
|
10
31
|
getTransactionByPaymentId(paymentId: string): Promise<Transaction | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Get transaction history for user
|
|
34
|
+
* @param limit Maximum number of transactions to return
|
|
35
|
+
* @param offset Number of transactions to skip
|
|
36
|
+
* @returns List of transactions sorted by creation date (newest first)
|
|
37
|
+
*/
|
|
11
38
|
getTransactions(limit?: number, offset?: number): Promise<{
|
|
12
39
|
transactions: Transaction[];
|
|
13
40
|
total: number;
|
|
@@ -38,6 +38,10 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const zod_1 = require("zod");
|
|
40
40
|
const logger_1 = require("../common/logger");
|
|
41
|
+
/**
|
|
42
|
+
* Service for managing payment transactions
|
|
43
|
+
* Stores transaction records in user-specific directories
|
|
44
|
+
*/
|
|
41
45
|
class TransactionService {
|
|
42
46
|
userId;
|
|
43
47
|
userPaths;
|
|
@@ -45,12 +49,21 @@ class TransactionService {
|
|
|
45
49
|
constructor(userId, userPaths) {
|
|
46
50
|
this.userId = userId;
|
|
47
51
|
this.userPaths = userPaths;
|
|
52
|
+
// Set transactions directory path
|
|
48
53
|
const userDataPath = this.userPaths.getUserDataDir();
|
|
49
54
|
this.transactionsDir = path.join(userDataPath, 'transactions');
|
|
55
|
+
// Ensure transactions directory exists
|
|
50
56
|
if (!fs.existsSync(this.transactionsDir)) {
|
|
51
57
|
fs.mkdirSync(this.transactionsDir, { recursive: true });
|
|
52
58
|
}
|
|
53
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Record a new transaction
|
|
62
|
+
* @param amount Amount in dollars
|
|
63
|
+
* @param paymentId Payment provider ID (e.g. a Stripe Payment Intent ID)
|
|
64
|
+
* @param status Initial transaction status
|
|
65
|
+
* @returns Created transaction
|
|
66
|
+
*/
|
|
54
67
|
async recordTransaction(amount, paymentId, status = 'pending') {
|
|
55
68
|
const timestamp = Date.now();
|
|
56
69
|
const transaction = {
|
|
@@ -63,6 +76,7 @@ class TransactionService {
|
|
|
63
76
|
createdAt: timestamp,
|
|
64
77
|
updatedAt: timestamp,
|
|
65
78
|
};
|
|
79
|
+
// Create filename: {timestamp}-{paymentId}.json
|
|
66
80
|
const filename = `${timestamp}-${paymentId}.json`;
|
|
67
81
|
const filePath = path.join(this.transactionsDir, filename);
|
|
68
82
|
try {
|
|
@@ -74,15 +88,23 @@ class TransactionService {
|
|
|
74
88
|
throw error;
|
|
75
89
|
}
|
|
76
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Update transaction status
|
|
93
|
+
* @param paymentId Payment provider ID
|
|
94
|
+
* @param status New status
|
|
95
|
+
*/
|
|
77
96
|
async updateTransactionStatus(paymentId, status) {
|
|
78
97
|
try {
|
|
98
|
+
// Find transaction file by payment ID
|
|
79
99
|
const transaction = await this.getTransactionByPaymentId(paymentId);
|
|
80
100
|
if (!transaction) {
|
|
81
101
|
logger_1.logger.error(`Transaction not found for payment ID ${paymentId}`);
|
|
82
102
|
return;
|
|
83
103
|
}
|
|
104
|
+
// Update status and timestamp
|
|
84
105
|
transaction.status = status;
|
|
85
106
|
transaction.updatedAt = Date.now();
|
|
107
|
+
// Find the file and update it
|
|
86
108
|
const files = fs.readdirSync(this.transactionsDir);
|
|
87
109
|
const matchingFile = files.find((file) => file.includes(paymentId));
|
|
88
110
|
if (matchingFile) {
|
|
@@ -95,6 +117,11 @@ class TransactionService {
|
|
|
95
117
|
throw error;
|
|
96
118
|
}
|
|
97
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Get transaction by payment provider ID
|
|
122
|
+
* @param paymentId Payment provider ID
|
|
123
|
+
* @returns Transaction or null if not found
|
|
124
|
+
*/
|
|
98
125
|
async getTransactionByPaymentId(paymentId) {
|
|
99
126
|
try {
|
|
100
127
|
const files = fs.readdirSync(this.transactionsDir);
|
|
@@ -111,8 +138,15 @@ class TransactionService {
|
|
|
111
138
|
return null;
|
|
112
139
|
}
|
|
113
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Get transaction history for user
|
|
143
|
+
* @param limit Maximum number of transactions to return
|
|
144
|
+
* @param offset Number of transactions to skip
|
|
145
|
+
* @returns List of transactions sorted by creation date (newest first)
|
|
146
|
+
*/
|
|
114
147
|
async getTransactions(limit = 50, offset = 0) {
|
|
115
148
|
try {
|
|
149
|
+
// Read all transaction files
|
|
116
150
|
const files = fs.readdirSync(this.transactionsDir);
|
|
117
151
|
const transactions = [];
|
|
118
152
|
for (const file of files) {
|
|
@@ -123,7 +157,9 @@ class TransactionService {
|
|
|
123
157
|
const transaction = JSON.parse(content);
|
|
124
158
|
transactions.push(transaction);
|
|
125
159
|
}
|
|
160
|
+
// Sort by creation date (newest first)
|
|
126
161
|
transactions.sort((a, b) => b.createdAt - a.createdAt);
|
|
162
|
+
// Apply pagination
|
|
127
163
|
const total = transactions.length;
|
|
128
164
|
const paginatedTransactions = transactions.slice(offset, offset + limit);
|
|
129
165
|
return {
|
|
@@ -9,6 +9,9 @@ import { PublishedAgentsService } from '../ai/published-agents.service';
|
|
|
9
9
|
import { PublishedRoomsService } from '../room/published-rooms.service';
|
|
10
10
|
import { BalanceMessageService } from './balance-message.service';
|
|
11
11
|
import { NativeToolRegistry } from '../tools/native-tool-registry.service';
|
|
12
|
+
/**
|
|
13
|
+
* Factory for creating user-specific AppService instances with their dependencies
|
|
14
|
+
*/
|
|
12
15
|
export declare class UserServiceFactory {
|
|
13
16
|
private readonly aiFactoryService;
|
|
14
17
|
private readonly agentMessageService;
|
|
@@ -21,5 +24,10 @@ export declare class UserServiceFactory {
|
|
|
21
24
|
private readonly configService;
|
|
22
25
|
private readonly nativeToolRegistry;
|
|
23
26
|
constructor(aiFactoryService: AiFactoryService, agentMessageService: AgentMessageService, roomMessageService: RoomMessageService, storyProgressService: StoryProgressService, storyMessageService: StoryMessageService, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService, balanceMessageService: BalanceMessageService, configService: ConfigService, nativeToolRegistry: NativeToolRegistry);
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new AppService instance with user-specific dependencies
|
|
29
|
+
* @param userId The user ID for which to create the service
|
|
30
|
+
* @returns A new AppService instance configured for the specified user
|
|
31
|
+
*/
|
|
24
32
|
createAppService(userId: string): AppService;
|
|
25
33
|
}
|
|
@@ -40,6 +40,9 @@ const user_config_service_1 = require("../config/user-config.service");
|
|
|
40
40
|
const pack_service_1 = require("../packs/pack.service");
|
|
41
41
|
const pack_instantiation_service_1 = require("../packs/pack-instantiation.service");
|
|
42
42
|
const rpg_service_1 = require("../rpg/rpg.service");
|
|
43
|
+
/**
|
|
44
|
+
* Factory for creating user-specific AppService instances with their dependencies
|
|
45
|
+
*/
|
|
43
46
|
let UserServiceFactory = class UserServiceFactory {
|
|
44
47
|
aiFactoryService;
|
|
45
48
|
agentMessageService;
|
|
@@ -63,30 +66,64 @@ let UserServiceFactory = class UserServiceFactory {
|
|
|
63
66
|
this.configService = configService;
|
|
64
67
|
this.nativeToolRegistry = nativeToolRegistry;
|
|
65
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new AppService instance with user-specific dependencies
|
|
71
|
+
* @param userId The user ID for which to create the service
|
|
72
|
+
* @returns A new AppService instance configured for the specified user
|
|
73
|
+
*/
|
|
66
74
|
createAppService(userId) {
|
|
75
|
+
// 1. Create UserPathsService with userId (reads BRIYAH_DATA_PATH from env)
|
|
67
76
|
const userPaths = new user_paths_service_1.UserPathsService(userId);
|
|
77
|
+
// 1.5. Per-user settings, and the packs they turn on. Everything that
|
|
78
|
+
// filters a listing by pack reads enablement through PackService, and does
|
|
79
|
+
// so through a thunk rather than a snapshot: this AppService is cached for
|
|
80
|
+
// half an hour, so a copy taken here would go stale the moment the user
|
|
81
|
+
// toggled a pack in another tab.
|
|
68
82
|
const userConfig = new user_config_service_1.UserConfigService(userPaths);
|
|
69
83
|
const packService = new pack_service_1.PackService(userPaths, userConfig, () => this.nativeToolRegistry.listTools().map((tool) => tool.name));
|
|
84
|
+
// 2. Create BalanceService (depends on UserPathsService and BalanceMessageService)
|
|
70
85
|
const balanceService = new balance_service_1.BalanceService(userId, userPaths, this.balanceMessageService);
|
|
71
86
|
const transactionService = new transaction_service_1.TransactionService(userId, userPaths);
|
|
87
|
+
// 3. Create AttachedFileService (depends on UserPathsService)
|
|
72
88
|
const attachedFileService = new attached_file_service_1.AttachedFileService(userPaths);
|
|
89
|
+
// 3.5. Create ArtifactService (depends on UserPathsService)
|
|
73
90
|
const artifactService = new artifact_service_1.ArtifactService(userPaths);
|
|
74
91
|
artifactService.setEnabledPacks(() => packService.enabledPacks());
|
|
92
|
+
// 4. Create AgentStoreService (depends on UserPathsService, AttachedFileService, BalanceService, and ArtifactService)
|
|
75
93
|
const agentStore = new agent_store_service_1.AgentStoreService(this.aiFactoryService, userPaths, attachedFileService, balanceService, artifactService, this.configService);
|
|
94
|
+
// 5. Create AgentFactory (depends on AiFactoryService, AgentStoreService, UserPathsService, BalanceService, and ArtifactService)
|
|
76
95
|
const agentFactory = new agent_factory_1.AgentFactory(this.aiFactoryService, agentStore, userPaths, balanceService, artifactService, this.configService);
|
|
96
|
+
// 5.5. Create ArtifactStoreService (no dependencies)
|
|
77
97
|
const artifactStore = new artifact_store_service_1.ArtifactStoreService();
|
|
98
|
+
// 5.6. Create tool services (native + user-defined tools agents can EXECUTE).
|
|
99
|
+
// User-authored (string) tools are gated off by default; native tools are
|
|
100
|
+
// always available. The native registry is shared across all users.
|
|
78
101
|
const toolStore = new tool_store_service_1.ToolStoreService(userPaths);
|
|
79
102
|
const allowUserAuthoredTools = String(this.configService.get('ALLOW_USER_AUTHORED_TOOLS')).toLowerCase() === 'true';
|
|
80
|
-
const toolExecution = new tool_execution_service_1.ToolExecutionService(toolStore, this.nativeToolRegistry, allowUserAuthoredTools,
|
|
103
|
+
const toolExecution = new tool_execution_service_1.ToolExecutionService(toolStore, this.nativeToolRegistry, allowUserAuthoredTools,
|
|
104
|
+
// Read access to installed packs' shipped documents, reaching tools as
|
|
105
|
+
// `helpers.packDocuments`. Deliberately the file listing rather than the
|
|
106
|
+
// manifest, so a pack's tools see a document the moment it is dropped in.
|
|
107
|
+
{
|
|
81
108
|
list: (pack, prefix) => artifactService.listPackDocumentFiles(pack, prefix),
|
|
82
109
|
read: (pack, fileName) => artifactService.readPackDocumentFile(pack, fileName),
|
|
83
110
|
});
|
|
111
|
+
// 6. Create RoomStoreService (depends on UserPathsService, AgentStoreService, AttachedFileService, ArtifactStoreService, and tool services)
|
|
84
112
|
const roomStore = new room_store_service_1.RoomStoreService(userPaths, agentStore, attachedFileService, artifactStore, toolStore, toolExecution);
|
|
113
|
+
// 7. Create RoomFactory (depends on RoomStoreService and tool services)
|
|
85
114
|
const roomFactory = new room_factory_1.RoomFactory(roomStore, toolStore, toolExecution);
|
|
115
|
+
// 8. Create StoryStoreService (depends on UserPathsService)
|
|
86
116
|
const storyStore = new story_store_service_1.StoryStoreService(userPaths, roomStore);
|
|
117
|
+
// 9. Create StoryService (depends on all user-specific services)
|
|
87
118
|
const storyService = new story_service_1.StoryService(storyStore, agentStore, roomStore, this.storyProgressService, this.storyMessageService, userPaths, agentFactory, roomFactory);
|
|
119
|
+
// 10. Create AppService with all dependencies
|
|
88
120
|
const appService = new app_service_1.AppService(this.aiFactoryService, agentStore, this.agentMessageService, roomStore, this.roomMessageService, userPaths, attachedFileService, artifactService, storyStore, storyService, this.publishedAgentsService, this.publishedRoomsService, balanceService, this.balanceMessageService, transactionService, agentFactory, roomFactory, toolStore, toolExecution, packService);
|
|
121
|
+
// Built after the AppService it drives, and handed back through it, because
|
|
122
|
+
// instantiating a pack's room goes through the same createRoom and
|
|
123
|
+
// createRoomAgent paths the API uses rather than around them.
|
|
89
124
|
appService.setPackInstantiation(new pack_instantiation_service_1.PackInstantiationService(appService, packService, roomStore));
|
|
125
|
+
// Built after pack instantiation because it drives that too: a campaign is a
|
|
126
|
+
// pack room with a party seated on it and a public link.
|
|
90
127
|
appService.setRpg(new rpg_service_1.RpgService(appService, packService, userConfig, userPaths, userId));
|
|
91
128
|
return appService;
|
|
92
129
|
}
|
|
@@ -3,6 +3,10 @@ import { ConfigService } from '@nestjs/config';
|
|
|
3
3
|
import { AppService } from '../app.service';
|
|
4
4
|
import { UserServiceFactory } from './user-service-factory';
|
|
5
5
|
export { IConfigService } from '../config/env-config';
|
|
6
|
+
/**
|
|
7
|
+
* Manages cached AppService instances per user
|
|
8
|
+
* Implements idle timeout and cleanup for inactive users
|
|
9
|
+
*/
|
|
6
10
|
export declare class UserServiceManager implements OnModuleInit, OnModuleDestroy {
|
|
7
11
|
private readonly userServiceFactory;
|
|
8
12
|
private readonly configService;
|
|
@@ -11,10 +15,29 @@ export declare class UserServiceManager implements OnModuleInit, OnModuleDestroy
|
|
|
11
15
|
private readonly cacheTimeoutMinutes;
|
|
12
16
|
private readonly cleanupIntervalMinutes;
|
|
13
17
|
constructor(userServiceFactory: UserServiceFactory, configService: ConfigService);
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the cleanup interval when the module starts
|
|
20
|
+
*/
|
|
14
21
|
onModuleInit(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Clean up when the module is destroyed
|
|
24
|
+
*/
|
|
15
25
|
onModuleDestroy(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the AppService for a specific user, creating it if necessary
|
|
28
|
+
* @param userId The user ID
|
|
29
|
+
* @returns The AppService instance for the user
|
|
30
|
+
*/
|
|
16
31
|
getAppService(userId: string): AppService;
|
|
32
|
+
/**
|
|
33
|
+
* Manually removes a user's service from the cache
|
|
34
|
+
* @param userId The user ID to remove
|
|
35
|
+
*/
|
|
17
36
|
removeUserService(userId: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Gets cache statistics
|
|
39
|
+
* @returns Object with cache statistics
|
|
40
|
+
*/
|
|
18
41
|
getCacheStats(): {
|
|
19
42
|
cachedUsers: number;
|
|
20
43
|
users: {
|
|
@@ -22,5 +45,9 @@ export declare class UserServiceManager implements OnModuleInit, OnModuleDestroy
|
|
|
22
45
|
ageMinutes: number;
|
|
23
46
|
}[];
|
|
24
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Periodically removes inactive user services from the cache
|
|
50
|
+
* Runs every 5 minutes
|
|
51
|
+
*/
|
|
25
52
|
private cleanupInactiveUsers;
|
|
26
53
|
}
|
|
@@ -14,6 +14,10 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const config_1 = require("@nestjs/config");
|
|
15
15
|
const user_service_factory_1 = require("./user-service-factory");
|
|
16
16
|
const logger_1 = require("../common/logger");
|
|
17
|
+
/**
|
|
18
|
+
* Manages cached AppService instances per user
|
|
19
|
+
* Implements idle timeout and cleanup for inactive users
|
|
20
|
+
*/
|
|
17
21
|
let UserServiceManager = class UserServiceManager {
|
|
18
22
|
userServiceFactory;
|
|
19
23
|
configService;
|
|
@@ -24,36 +28,63 @@ let UserServiceManager = class UserServiceManager {
|
|
|
24
28
|
constructor(userServiceFactory, configService) {
|
|
25
29
|
this.userServiceFactory = userServiceFactory;
|
|
26
30
|
this.configService = configService;
|
|
31
|
+
// Three hours, because the unit this cache serves is a *session*, not a
|
|
32
|
+
// request. Thirty minutes is shorter than the gaps a person leaves while
|
|
33
|
+
// reading and deciding, so a played campaign evicted and rebuilt the whole
|
|
34
|
+
// user — every room and all fifty-one agents, six times in one sitting.
|
|
35
|
+
//
|
|
36
|
+
// Rebuilding is mostly disk and log noise rather than money; the agents come
|
|
37
|
+
// back identical, so a prompt cache still inside its TTL should survive it.
|
|
38
|
+
// Should: one reload in that session was followed by a total cache miss on an
|
|
39
|
+
// agent 40 minutes into a 60-minute TTL, which is unexplained and worth
|
|
40
|
+
// chasing before this default is treated as a cost fix.
|
|
27
41
|
this.cacheTimeoutMinutes = parseInt(this.configService.get('USER_SERVICE_CACHE_TIMEOUT_MINUTES', '180'));
|
|
28
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the cleanup interval when the module starts
|
|
45
|
+
*/
|
|
29
46
|
onModuleInit() {
|
|
30
47
|
if (this.cleanupIntervalId) {
|
|
31
48
|
return;
|
|
32
49
|
}
|
|
50
|
+
// Start cleanup interval (runs every 5 minutes)
|
|
33
51
|
this.cleanupIntervalId = setInterval(() => this.cleanupInactiveUsers(), this.cleanupIntervalMinutes * 60 * 1000);
|
|
34
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Clean up when the module is destroyed
|
|
55
|
+
*/
|
|
35
56
|
onModuleDestroy() {
|
|
36
57
|
if (this.cleanupIntervalId) {
|
|
37
58
|
clearInterval(this.cleanupIntervalId);
|
|
38
59
|
this.cleanupIntervalId = null;
|
|
60
|
+
// Clear all user services
|
|
39
61
|
this.userServices.clear();
|
|
40
62
|
logger_1.logger.log('[UserServiceManager] Shutdown complete');
|
|
41
63
|
}
|
|
42
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the AppService for a specific user, creating it if necessary
|
|
67
|
+
* @param userId The user ID
|
|
68
|
+
* @returns The AppService instance for the user
|
|
69
|
+
*/
|
|
43
70
|
getAppService(userId) {
|
|
44
71
|
const now = Date.now();
|
|
72
|
+
// Check if user service exists and is not expired
|
|
45
73
|
const context = this.userServices.get(userId);
|
|
46
74
|
if (context) {
|
|
47
75
|
const ageMinutes = (now - context.lastAccessed) / (60 * 1000);
|
|
48
76
|
if (ageMinutes < this.cacheTimeoutMinutes) {
|
|
77
|
+
// Cache hit - update last accessed time
|
|
49
78
|
context.lastAccessed = now;
|
|
50
79
|
return context.appService;
|
|
51
80
|
}
|
|
52
81
|
else {
|
|
82
|
+
// Cache expired - remove it
|
|
53
83
|
logger_1.logger.log(`[UserServiceManager] Cache expired for user ${userId} (${ageMinutes.toFixed(1)}min old)`);
|
|
54
84
|
this.userServices.delete(userId);
|
|
55
85
|
}
|
|
56
86
|
}
|
|
87
|
+
// Cache miss or expired - create new AppService
|
|
57
88
|
const appService = this.userServiceFactory.createAppService(userId);
|
|
58
89
|
this.userServices.set(userId, {
|
|
59
90
|
appService,
|
|
@@ -61,11 +92,19 @@ let UserServiceManager = class UserServiceManager {
|
|
|
61
92
|
});
|
|
62
93
|
return appService;
|
|
63
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Manually removes a user's service from the cache
|
|
97
|
+
* @param userId The user ID to remove
|
|
98
|
+
*/
|
|
64
99
|
removeUserService(userId) {
|
|
65
100
|
if (this.userServices.delete(userId)) {
|
|
66
101
|
logger_1.logger.log(`[UserServiceManager] Manually removed service for user ${userId}`);
|
|
67
102
|
}
|
|
68
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Gets cache statistics
|
|
106
|
+
* @returns Object with cache statistics
|
|
107
|
+
*/
|
|
69
108
|
getCacheStats() {
|
|
70
109
|
const now = Date.now();
|
|
71
110
|
const users = Array.from(this.userServices.entries()).map(([userId, context]) => ({
|
|
@@ -77,6 +116,10 @@ let UserServiceManager = class UserServiceManager {
|
|
|
77
116
|
users,
|
|
78
117
|
};
|
|
79
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Periodically removes inactive user services from the cache
|
|
121
|
+
* Runs every 5 minutes
|
|
122
|
+
*/
|
|
80
123
|
cleanupInactiveUsers() {
|
|
81
124
|
const now = Date.now();
|
|
82
125
|
const timeoutMs = this.cacheTimeoutMinutes * 60 * 1000;
|
|
@@ -11,6 +11,13 @@ export declare class AppController {
|
|
|
11
11
|
private readonly publishedAgentsService;
|
|
12
12
|
private readonly publishedRoomsService;
|
|
13
13
|
constructor(userServiceManager: UserServiceManager, publishedAgentsService: PublishedAgentsService, publishedRoomsService: PublishedRoomsService);
|
|
14
|
+
/**
|
|
15
|
+
* Helper method to get the user-specific AppService from the request
|
|
16
|
+
* @param req The Express request object (with authenticated user)
|
|
17
|
+
* @param agentId Optional agent ID for fallback lookup
|
|
18
|
+
* @param roomId Optional room ID for fallback lookup
|
|
19
|
+
* @returns The AppService instance for the authenticated user, agent owner, or room owner
|
|
20
|
+
*/
|
|
14
21
|
private getAppService;
|
|
15
22
|
listServices(req: ExpressRequest): string[];
|
|
16
23
|
listModels(req: ExpressRequest, aiServiceName: string): Promise<ModelInfo[]>;
|
|
@@ -50,6 +57,10 @@ export declare class AppController {
|
|
|
50
57
|
listRpgCampaigns(req: ExpressRequest): Promise<RpgCampaignInfo[]>;
|
|
51
58
|
getRpgCampaign(req: ExpressRequest, campaignId: string): Promise<RpgCampaignDetails>;
|
|
52
59
|
createRpgCampaign(req: ExpressRequest, body: CreateRpgCampaignRequest): Promise<CreateRpgCampaignResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* Gives a campaign a public link again, for one whose instance was deleted by hand.
|
|
62
|
+
* Creation publishes, so this is the repair path rather than the normal one.
|
|
63
|
+
*/
|
|
53
64
|
republishRpgCampaign(req: ExpressRequest, campaignId: string): Promise<{
|
|
54
65
|
instanceId: string;
|
|
55
66
|
publicPath: string;
|
|
@@ -60,6 +71,20 @@ export declare class AppController {
|
|
|
60
71
|
variables?: any;
|
|
61
72
|
}): Promise<PreparedPromptResponse>;
|
|
62
73
|
listAgents(req: ExpressRequest, published?: string, includeRoomAgents?: string): Promise<AgentInfo[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Validates a request's turnMode so an unrecognized value is a 400 rather
|
|
76
|
+
* than silently becoming 'broadcast'.
|
|
77
|
+
* @param value The raw turnMode from the request body
|
|
78
|
+
* @returns The turn mode, or undefined when the field was omitted
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* Reads the models an instantiate request supplies.
|
|
82
|
+
*
|
|
83
|
+
* A pack's template names a *role* (`primary` or `economy`), never a model, so
|
|
84
|
+
* the caller has to say what each role means on this deployment. `economy`
|
|
85
|
+
* falls back to `primary` rather than erroring: a caller that offers only one
|
|
86
|
+
* model gets a working room, just not a cheap one.
|
|
87
|
+
*/
|
|
63
88
|
private static parseInstantiateModels;
|
|
64
89
|
private static parseTurnMode;
|
|
65
90
|
createRoom(req: ExpressRequest, body: {
|
|
@@ -78,9 +103,20 @@ export declare class AppController {
|
|
|
78
103
|
roomLeader?: string;
|
|
79
104
|
turnMode?: string;
|
|
80
105
|
moderator?: string;
|
|
106
|
+
/** Files the room under a pack. Empty string clears it. */
|
|
81
107
|
pack?: string;
|
|
82
108
|
}): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Creates an agent that belongs to this room and adds it to it.
|
|
111
|
+
*
|
|
112
|
+
* The only way an agent joins a room. `agentName` is the bare name — the room's
|
|
113
|
+
* name is prefixed onto it server-side, so the client never has to assemble it
|
|
114
|
+
* (and cannot end up prefixing it twice).
|
|
115
|
+
*/
|
|
83
116
|
createRoomAgent(req: ExpressRequest, roomId: string, body: CreateRoomAgentRequest): Promise<CreateAgentResponse>;
|
|
117
|
+
/**
|
|
118
|
+
* Removes an agent from a room, deleting it when the room owns it.
|
|
119
|
+
*/
|
|
84
120
|
removeRoomAgent(req: ExpressRequest, roomId: string, agentId: string): Promise<void>;
|
|
85
121
|
listRooms(req: ExpressRequest, published?: string): Promise<RoomInfo[]>;
|
|
86
122
|
getRoomDetails(req: ExpressRequest, roomId: string): Promise<RoomDetails>;
|
|
@@ -155,8 +191,20 @@ export declare class AppController {
|
|
|
155
191
|
folderName: string;
|
|
156
192
|
}): Promise<void>;
|
|
157
193
|
listStories(req: ExpressRequest): StoryInfo[];
|
|
194
|
+
/**
|
|
195
|
+
* List all available story genres
|
|
196
|
+
* GET /api/stories/genres
|
|
197
|
+
*/
|
|
158
198
|
listStoryGenres(req: ExpressRequest): string[];
|
|
199
|
+
/**
|
|
200
|
+
* Get a random story idea from any random genre
|
|
201
|
+
* GET /api/stories/genres/random
|
|
202
|
+
*/
|
|
159
203
|
getRandomStoryIdea(req: ExpressRequest): Promise<StoryIdea | null>;
|
|
204
|
+
/**
|
|
205
|
+
* Get a random story idea from a specific genre
|
|
206
|
+
* GET /api/stories/genres/:genreName
|
|
207
|
+
*/
|
|
160
208
|
getStoryIdeasByGenre(req: ExpressRequest, genreName: string): Promise<StoryIdea | null>;
|
|
161
209
|
createStory(req: ExpressRequest, body: {
|
|
162
210
|
name: string;
|
|
@@ -224,42 +272,81 @@ export declare class AppController {
|
|
|
224
272
|
savePlotPlan(req: ExpressRequest, storyId: string, body: {
|
|
225
273
|
content: string;
|
|
226
274
|
}): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* List artifacts for a story
|
|
277
|
+
*/
|
|
227
278
|
listStoryArtifacts(req: ExpressRequest, storyId: string): Promise<{
|
|
228
279
|
artifacts: any[];
|
|
229
280
|
}>;
|
|
281
|
+
/**
|
|
282
|
+
* Get specific story artifact content
|
|
283
|
+
*/
|
|
230
284
|
getStoryArtifact(req: ExpressRequest, storyId: string, artifactId: string, res: Response): Promise<void>;
|
|
231
285
|
storyProgress(req: ExpressRequest, storyId: string): Observable<MessageEvent>;
|
|
232
286
|
storyMessages(req: ExpressRequest, storyId: string): Observable<MessageEvent>;
|
|
233
287
|
agentMessages(req: ExpressRequest, agentId: string): Promise<Observable<MessageEvent>>;
|
|
234
288
|
roomMessages(req: ExpressRequest, roomId: string): Promise<Observable<MessageEvent>>;
|
|
235
289
|
balanceUpdates(req: ExpressRequest): Observable<MessageEvent>;
|
|
290
|
+
/**
|
|
291
|
+
* Get current user balance
|
|
292
|
+
*/
|
|
236
293
|
getBalance(req: ExpressRequest): Promise<{
|
|
237
294
|
balance: number;
|
|
238
295
|
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Add funds to user balance
|
|
298
|
+
*/
|
|
299
|
+
/**
|
|
300
|
+
* List all artifacts for the user
|
|
301
|
+
*/
|
|
239
302
|
listArtifacts(req: ExpressRequest): Promise<{
|
|
240
303
|
artifacts: any[];
|
|
241
304
|
}>;
|
|
305
|
+
/**
|
|
306
|
+
* Get specific artifact content
|
|
307
|
+
*/
|
|
242
308
|
getArtifact(req: ExpressRequest, artifactId: string): Promise<{
|
|
243
309
|
content: string;
|
|
244
310
|
}>;
|
|
311
|
+
/**
|
|
312
|
+
* Create new artifact (upload)
|
|
313
|
+
*/
|
|
245
314
|
createArtifact(req: ExpressRequest, body: {
|
|
246
315
|
name: string;
|
|
247
316
|
content?: string;
|
|
248
317
|
}, file: Express.Multer.File): Promise<{
|
|
249
318
|
artifactId: string;
|
|
250
319
|
}>;
|
|
320
|
+
/**
|
|
321
|
+
* Update artifact content
|
|
322
|
+
*/
|
|
251
323
|
updateArtifact(req: ExpressRequest, artifactId: string, body: {
|
|
252
324
|
content: string;
|
|
253
325
|
}): Promise<void>;
|
|
326
|
+
/**
|
|
327
|
+
* Rename artifact
|
|
328
|
+
*/
|
|
254
329
|
renameArtifact(req: ExpressRequest, artifactId: string, body: {
|
|
255
330
|
name: string;
|
|
256
331
|
}): Promise<void>;
|
|
332
|
+
/**
|
|
333
|
+
* Delete artifact
|
|
334
|
+
*/
|
|
257
335
|
deleteArtifact(req: ExpressRequest, artifactId: string): Promise<void>;
|
|
336
|
+
/**
|
|
337
|
+
* List artifacts attached to agent
|
|
338
|
+
*/
|
|
258
339
|
listAgentArtifacts(req: ExpressRequest, agentId: string): Promise<{
|
|
259
340
|
artifacts: any[];
|
|
260
341
|
}>;
|
|
342
|
+
/**
|
|
343
|
+
* Attach artifact to agent
|
|
344
|
+
*/
|
|
261
345
|
attachArtifactToAgent(req: ExpressRequest, agentId: string, body: {
|
|
262
346
|
artifactId: string;
|
|
263
347
|
}): Promise<void>;
|
|
348
|
+
/**
|
|
349
|
+
* Detach artifact from agent
|
|
350
|
+
*/
|
|
264
351
|
detachArtifactFromAgent(req: ExpressRequest, agentId: string, artifactId: string): Promise<void>;
|
|
265
352
|
}
|