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
|
@@ -7,25 +7,46 @@ export declare class StripeController {
|
|
|
7
7
|
private readonly stripeService;
|
|
8
8
|
private readonly userServiceManager;
|
|
9
9
|
constructor(stripeService: StripeService, userServiceManager: UserServiceManager);
|
|
10
|
+
/**
|
|
11
|
+
* Create a Payment Intent for adding credit
|
|
12
|
+
*/
|
|
10
13
|
createPaymentIntent(req: ExpressRequest & {
|
|
11
14
|
user: {
|
|
12
15
|
userId: string;
|
|
13
16
|
};
|
|
14
17
|
}, body: CreatePaymentIntentRequest): Promise<CreatePaymentIntentResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a Checkout Session for adding credit via Discord
|
|
20
|
+
*/
|
|
15
21
|
createCheckoutSession(req: ExpressRequest & {
|
|
16
22
|
user: {
|
|
17
23
|
userId: string;
|
|
18
24
|
};
|
|
19
25
|
}, body: CreateCheckoutSessionRequest): Promise<CreateCheckoutSessionResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Get user balance for a completed Stripe checkout session
|
|
28
|
+
* Public endpoint — no JWT required, used by the payment-success page
|
|
29
|
+
*/
|
|
20
30
|
getCheckoutSessionBalance(sessionId: string): Promise<{
|
|
21
31
|
balance: number;
|
|
22
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Get Stripe configuration (publishable key)
|
|
35
|
+
* This endpoint is authenticated and returns the publishable key needed for Stripe.js initialization
|
|
36
|
+
*/
|
|
23
37
|
getStripeConfig(): Promise<{
|
|
24
38
|
publishableKey: string;
|
|
25
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Stripe webhook endpoint
|
|
42
|
+
* Handles payment_intent.succeeded and payment_intent.payment_failed events
|
|
43
|
+
*/
|
|
26
44
|
handleWebhook(req: RawBodyRequest<ExpressRequest>, signature: string): Promise<{
|
|
27
45
|
received: boolean;
|
|
28
46
|
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get transaction history
|
|
49
|
+
*/
|
|
29
50
|
getTransactionHistory(req: ExpressRequest & {
|
|
30
51
|
user: {
|
|
31
52
|
userId: string;
|
|
@@ -27,42 +27,67 @@ let StripeController = class StripeController {
|
|
|
27
27
|
this.stripeService = stripeService;
|
|
28
28
|
this.userServiceManager = userServiceManager;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a Payment Intent for adding credit
|
|
32
|
+
*/
|
|
30
33
|
async createPaymentIntent(req, body) {
|
|
31
34
|
const userId = req.user.userId;
|
|
32
35
|
const { amount } = body;
|
|
36
|
+
// Get user's AppService
|
|
33
37
|
const appService = this.userServiceManager.getAppService(userId);
|
|
38
|
+
// Create Payment Intent
|
|
34
39
|
const result = await this.stripeService.createPaymentIntent(userId, amount, appService);
|
|
35
40
|
return result;
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a Checkout Session for adding credit via Discord
|
|
44
|
+
*/
|
|
37
45
|
async createCheckoutSession(req, body) {
|
|
38
46
|
const userId = req.user.userId;
|
|
39
47
|
const { amount } = body;
|
|
48
|
+
// Get user's AppService
|
|
40
49
|
const appService = this.userServiceManager.getAppService(userId);
|
|
50
|
+
// Create Checkout Session
|
|
41
51
|
const result = await this.stripeService.createCheckoutSession(userId, amount, appService);
|
|
42
52
|
return result;
|
|
43
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Get user balance for a completed Stripe checkout session
|
|
56
|
+
* Public endpoint — no JWT required, used by the payment-success page
|
|
57
|
+
*/
|
|
44
58
|
async getCheckoutSessionBalance(sessionId) {
|
|
45
59
|
const { userId } = await this.stripeService.getCheckoutSessionUser(sessionId);
|
|
46
60
|
const appService = this.userServiceManager.getAppService(userId);
|
|
47
61
|
return { balance: appService.getBalance() };
|
|
48
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Get Stripe configuration (publishable key)
|
|
65
|
+
* This endpoint is authenticated and returns the publishable key needed for Stripe.js initialization
|
|
66
|
+
*/
|
|
49
67
|
async getStripeConfig() {
|
|
50
68
|
return this.stripeService.getStripeConfig();
|
|
51
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Stripe webhook endpoint
|
|
72
|
+
* Handles payment_intent.succeeded and payment_intent.payment_failed events
|
|
73
|
+
*/
|
|
52
74
|
async handleWebhook(req, signature) {
|
|
53
75
|
logger_1.logger.log('[Stripe Webhook] Received webhook request');
|
|
54
76
|
if (!signature) {
|
|
55
77
|
logger_1.logger.error('[Stripe Webhook] Missing stripe-signature header');
|
|
56
78
|
throw new common_1.BadRequestException('Missing stripe-signature header');
|
|
57
79
|
}
|
|
80
|
+
// Get raw body for signature verification
|
|
58
81
|
const rawBody = req.rawBody;
|
|
59
82
|
if (!rawBody) {
|
|
60
83
|
logger_1.logger.error('[Stripe Webhook] Missing request body');
|
|
61
84
|
throw new common_1.BadRequestException('Missing request body');
|
|
62
85
|
}
|
|
63
86
|
logger_1.logger.log('[Stripe Webhook] Verifying webhook signature...');
|
|
87
|
+
// Verify webhook signature
|
|
64
88
|
const event = this.stripeService.verifyWebhookSignature(rawBody, signature);
|
|
65
89
|
logger_1.logger.log(`[Stripe Webhook] Event type: ${event.type}, Event ID: ${event.id}`);
|
|
90
|
+
// Handle event
|
|
66
91
|
switch (event.type) {
|
|
67
92
|
case 'payment_intent.succeeded': {
|
|
68
93
|
logger_1.logger.log('[Stripe Webhook] Matched payment_intent.succeeded case');
|
|
@@ -72,7 +97,9 @@ let StripeController = class StripeController {
|
|
|
72
97
|
logger_1.logger.error('Payment Intent missing userId in metadata');
|
|
73
98
|
return { received: true };
|
|
74
99
|
}
|
|
100
|
+
// Get user's AppService
|
|
75
101
|
const appService = this.userServiceManager.getAppService(userId);
|
|
102
|
+
// Handle successful payment
|
|
76
103
|
await this.stripeService.handlePaymentIntentSucceeded(paymentIntent, appService);
|
|
77
104
|
break;
|
|
78
105
|
}
|
|
@@ -84,7 +111,9 @@ let StripeController = class StripeController {
|
|
|
84
111
|
logger_1.logger.error('[Stripe Webhook] Payment Intent missing userId in metadata');
|
|
85
112
|
return { received: true };
|
|
86
113
|
}
|
|
114
|
+
// Get user's AppService
|
|
87
115
|
const appService = this.userServiceManager.getAppService(userId);
|
|
116
|
+
// Handle failed payment
|
|
88
117
|
await this.stripeService.handlePaymentIntentFailed(paymentIntent, appService);
|
|
89
118
|
break;
|
|
90
119
|
}
|
|
@@ -94,11 +123,17 @@ let StripeController = class StripeController {
|
|
|
94
123
|
logger_1.logger.log('[Stripe Webhook] Webhook processed successfully');
|
|
95
124
|
return { received: true };
|
|
96
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Get transaction history
|
|
128
|
+
*/
|
|
97
129
|
async getTransactionHistory(req, limit, offset) {
|
|
98
130
|
const userId = req.user.userId;
|
|
131
|
+
// Parse query parameters
|
|
99
132
|
const parsedLimit = limit ? parseInt(limit, 10) : 50;
|
|
100
133
|
const parsedOffset = offset ? parseInt(offset, 10) : 0;
|
|
134
|
+
// Get user's AppService
|
|
101
135
|
const appService = this.userServiceManager.getAppService(userId);
|
|
136
|
+
// Get transactions
|
|
102
137
|
const result = await appService.getTransactions(parsedLimit, parsedOffset);
|
|
103
138
|
return result;
|
|
104
139
|
}
|
|
@@ -3,6 +3,9 @@ import { AppService } from '../app.service';
|
|
|
3
3
|
type StripeInstance = ReturnType<typeof Stripe>;
|
|
4
4
|
type StripeEvent = ReturnType<StripeInstance['webhooks']['constructEvent']>;
|
|
5
5
|
type StripePaymentIntent = Awaited<ReturnType<StripeInstance['paymentIntents']['retrieve']>>;
|
|
6
|
+
/**
|
|
7
|
+
* Service for managing Stripe payment operations
|
|
8
|
+
*/
|
|
6
9
|
export declare class StripeService {
|
|
7
10
|
private stripe;
|
|
8
11
|
private minPaymentAmount;
|
|
@@ -10,22 +13,62 @@ export declare class StripeService {
|
|
|
10
13
|
private publishableKey;
|
|
11
14
|
private webhookSecret;
|
|
12
15
|
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Create a Payment Intent for adding credit
|
|
18
|
+
* @param userId User ID
|
|
19
|
+
* @param amount Amount in dollars
|
|
20
|
+
* @param appService App service for the user
|
|
21
|
+
* @returns Client secret and publishable key
|
|
22
|
+
*/
|
|
13
23
|
createPaymentIntent(userId: string, amount: number, appService: AppService): Promise<{
|
|
14
24
|
clientSecret: string;
|
|
15
25
|
publishableKey: string;
|
|
16
26
|
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a Checkout Session for adding credit via Discord
|
|
29
|
+
* @param userId User ID
|
|
30
|
+
* @param amount Amount in dollars
|
|
31
|
+
* @param appService App service for the user
|
|
32
|
+
* @returns Checkout session URL
|
|
33
|
+
*/
|
|
17
34
|
createCheckoutSession(userId: string, amount: number, appService: AppService): Promise<{
|
|
18
35
|
url: string;
|
|
19
36
|
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve a checkout session and return the userId from its metadata
|
|
39
|
+
* Used by the payment-success page to look up the user's balance without a JWT
|
|
40
|
+
* @param sessionId Stripe checkout session ID
|
|
41
|
+
* @returns userId and payment status
|
|
42
|
+
*/
|
|
20
43
|
getCheckoutSessionUser(sessionId: string): Promise<{
|
|
21
44
|
userId: string;
|
|
22
45
|
paymentStatus: string;
|
|
23
46
|
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get Stripe configuration
|
|
49
|
+
* @returns Stripe publishable key for frontend initialization
|
|
50
|
+
*/
|
|
24
51
|
getStripeConfig(): {
|
|
25
52
|
publishableKey: string;
|
|
26
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Verify webhook signature from Stripe
|
|
56
|
+
* @param rawBody Raw request body
|
|
57
|
+
* @param signature Stripe signature from header
|
|
58
|
+
* @returns Stripe event
|
|
59
|
+
*/
|
|
27
60
|
verifyWebhookSignature(rawBody: Buffer | string, signature: string): StripeEvent;
|
|
61
|
+
/**
|
|
62
|
+
* Handle successful payment
|
|
63
|
+
* @param paymentIntent Payment Intent
|
|
64
|
+
* @param appService App service for the user
|
|
65
|
+
*/
|
|
28
66
|
handlePaymentIntentSucceeded(paymentIntent: StripePaymentIntent, appService: AppService): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Handle failed payment
|
|
69
|
+
* @param paymentIntent Payment Intent
|
|
70
|
+
* @param appService App service for the user
|
|
71
|
+
*/
|
|
29
72
|
handlePaymentIntentFailed(paymentIntent: StripePaymentIntent, appService: AppService): Promise<void>;
|
|
30
73
|
}
|
|
31
74
|
export {};
|
|
@@ -16,6 +16,9 @@ exports.StripeService = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const stripe_1 = __importDefault(require("stripe"));
|
|
18
18
|
const logger_1 = require("../common/logger");
|
|
19
|
+
/**
|
|
20
|
+
* Service for managing Stripe payment operations
|
|
21
|
+
*/
|
|
19
22
|
let StripeService = class StripeService {
|
|
20
23
|
stripe;
|
|
21
24
|
minPaymentAmount;
|
|
@@ -23,6 +26,7 @@ let StripeService = class StripeService {
|
|
|
23
26
|
publishableKey;
|
|
24
27
|
webhookSecret;
|
|
25
28
|
constructor() {
|
|
29
|
+
// Validate environment variables
|
|
26
30
|
if (!process.env.STRIPE_SECRET_KEY) {
|
|
27
31
|
throw new Error('STRIPE_SECRET_KEY environment variable is required');
|
|
28
32
|
}
|
|
@@ -32,15 +36,25 @@ let StripeService = class StripeService {
|
|
|
32
36
|
if (!process.env.STRIPE_WEBHOOK_SECRET) {
|
|
33
37
|
throw new Error('STRIPE_WEBHOOK_SECRET environment variable is required');
|
|
34
38
|
}
|
|
39
|
+
// Initialize Stripe
|
|
35
40
|
this.stripe = (0, stripe_1.default)(process.env.STRIPE_SECRET_KEY, {
|
|
36
41
|
apiVersion: '2026-03-25.dahlia',
|
|
37
42
|
});
|
|
38
43
|
this.publishableKey = process.env.STRIPE_PUBLISHABLE_KEY;
|
|
39
44
|
this.webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
45
|
+
// Load payment limits
|
|
40
46
|
this.minPaymentAmount = parseFloat(process.env.MIN_PAYMENT_AMOUNT || '5.00');
|
|
41
47
|
this.maxPaymentAmount = parseFloat(process.env.MAX_PAYMENT_AMOUNT || '500.00');
|
|
42
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a Payment Intent for adding credit
|
|
51
|
+
* @param userId User ID
|
|
52
|
+
* @param amount Amount in dollars
|
|
53
|
+
* @param appService App service for the user
|
|
54
|
+
* @returns Client secret and publishable key
|
|
55
|
+
*/
|
|
43
56
|
async createPaymentIntent(userId, amount, appService) {
|
|
57
|
+
// Validate amount
|
|
44
58
|
if (!amount || amount <= 0) {
|
|
45
59
|
throw new common_1.BadRequestException('Amount must be greater than 0');
|
|
46
60
|
}
|
|
@@ -51,7 +65,9 @@ let StripeService = class StripeService {
|
|
|
51
65
|
throw new common_1.BadRequestException(`Amount must not exceed $${this.maxPaymentAmount.toFixed(2)}`);
|
|
52
66
|
}
|
|
53
67
|
try {
|
|
68
|
+
// Convert dollars to cents
|
|
54
69
|
const amountInCents = Math.round(amount * 100);
|
|
70
|
+
// Create Payment Intent with userId in metadata
|
|
55
71
|
const paymentIntent = await this.stripe.paymentIntents.create({
|
|
56
72
|
amount: amountInCents,
|
|
57
73
|
currency: 'usd',
|
|
@@ -62,6 +78,7 @@ let StripeService = class StripeService {
|
|
|
62
78
|
enabled: true,
|
|
63
79
|
},
|
|
64
80
|
});
|
|
81
|
+
// Record pending transaction
|
|
65
82
|
await appService.recordTransaction(amount, paymentIntent.id, 'pending');
|
|
66
83
|
return {
|
|
67
84
|
clientSecret: paymentIntent.client_secret,
|
|
@@ -73,7 +90,15 @@ let StripeService = class StripeService {
|
|
|
73
90
|
throw new common_1.InternalServerErrorException('Failed to create payment intent');
|
|
74
91
|
}
|
|
75
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a Checkout Session for adding credit via Discord
|
|
95
|
+
* @param userId User ID
|
|
96
|
+
* @param amount Amount in dollars
|
|
97
|
+
* @param appService App service for the user
|
|
98
|
+
* @returns Checkout session URL
|
|
99
|
+
*/
|
|
76
100
|
async createCheckoutSession(userId, amount, appService) {
|
|
101
|
+
// Validate amount (same validation as payment intent)
|
|
77
102
|
if (!amount || amount <= 0) {
|
|
78
103
|
throw new common_1.BadRequestException('Amount must be greater than 0');
|
|
79
104
|
}
|
|
@@ -84,7 +109,9 @@ let StripeService = class StripeService {
|
|
|
84
109
|
throw new common_1.BadRequestException(`Amount must not exceed $${this.maxPaymentAmount.toFixed(2)}`);
|
|
85
110
|
}
|
|
86
111
|
try {
|
|
112
|
+
// Convert dollars to cents
|
|
87
113
|
const amountInCents = Math.round(amount * 100);
|
|
114
|
+
// Create Checkout Session
|
|
88
115
|
const session = await this.stripe.checkout.sessions.create({
|
|
89
116
|
payment_method_types: ['card'],
|
|
90
117
|
line_items: [
|
|
@@ -112,6 +139,7 @@ let StripeService = class StripeService {
|
|
|
112
139
|
},
|
|
113
140
|
},
|
|
114
141
|
});
|
|
142
|
+
// Record pending transaction
|
|
115
143
|
if (session.payment_intent) {
|
|
116
144
|
await appService.recordTransaction(amount, session.payment_intent, 'pending');
|
|
117
145
|
}
|
|
@@ -124,6 +152,12 @@ let StripeService = class StripeService {
|
|
|
124
152
|
throw new common_1.InternalServerErrorException('Failed to create checkout session');
|
|
125
153
|
}
|
|
126
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Retrieve a checkout session and return the userId from its metadata
|
|
157
|
+
* Used by the payment-success page to look up the user's balance without a JWT
|
|
158
|
+
* @param sessionId Stripe checkout session ID
|
|
159
|
+
* @returns userId and payment status
|
|
160
|
+
*/
|
|
127
161
|
async getCheckoutSessionUser(sessionId) {
|
|
128
162
|
try {
|
|
129
163
|
const session = await this.stripe.checkout.sessions.retrieve(sessionId);
|
|
@@ -140,11 +174,21 @@ let StripeService = class StripeService {
|
|
|
140
174
|
throw new common_1.BadRequestException('Invalid or expired session ID');
|
|
141
175
|
}
|
|
142
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Get Stripe configuration
|
|
179
|
+
* @returns Stripe publishable key for frontend initialization
|
|
180
|
+
*/
|
|
143
181
|
getStripeConfig() {
|
|
144
182
|
return {
|
|
145
183
|
publishableKey: this.publishableKey,
|
|
146
184
|
};
|
|
147
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Verify webhook signature from Stripe
|
|
188
|
+
* @param rawBody Raw request body
|
|
189
|
+
* @param signature Stripe signature from header
|
|
190
|
+
* @returns Stripe event
|
|
191
|
+
*/
|
|
148
192
|
verifyWebhookSignature(rawBody, signature) {
|
|
149
193
|
try {
|
|
150
194
|
return this.stripe.webhooks.constructEvent(rawBody, signature, this.webhookSecret);
|
|
@@ -154,6 +198,11 @@ let StripeService = class StripeService {
|
|
|
154
198
|
throw new common_1.BadRequestException('Invalid webhook signature');
|
|
155
199
|
}
|
|
156
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Handle successful payment
|
|
203
|
+
* @param paymentIntent Payment Intent
|
|
204
|
+
* @param appService App service for the user
|
|
205
|
+
*/
|
|
157
206
|
async handlePaymentIntentSucceeded(paymentIntent, appService) {
|
|
158
207
|
try {
|
|
159
208
|
const userId = paymentIntent.metadata.userId;
|
|
@@ -162,22 +211,29 @@ let StripeService = class StripeService {
|
|
|
162
211
|
logger_1.logger.error('Payment Intent missing userId in metadata:', paymentIntent.id);
|
|
163
212
|
return;
|
|
164
213
|
}
|
|
214
|
+
// Convert cents to dollars
|
|
165
215
|
const amount = paymentIntent.amount / 100;
|
|
166
216
|
logger_1.logger.log(`[Stripe Webhook] Amount: $${amount.toFixed(2)}`);
|
|
217
|
+
// Check if transaction already processed
|
|
167
218
|
const existingTransaction = await appService.getTransactionByPaymentId(paymentIntent.id);
|
|
168
219
|
logger_1.logger.log(`[Stripe Webhook] Existing transaction:`, existingTransaction);
|
|
169
220
|
if (existingTransaction?.status === 'succeeded') {
|
|
170
221
|
logger_1.logger.log(`Transaction ${paymentIntent.id} already processed, skipping`);
|
|
171
222
|
return;
|
|
172
223
|
}
|
|
224
|
+
// Get balance before
|
|
173
225
|
const balanceBefore = await appService.getBalance();
|
|
174
226
|
logger_1.logger.log(`[Stripe Webhook] Balance before: $${balanceBefore.toFixed(2)}`);
|
|
227
|
+
// Add balance
|
|
175
228
|
logger_1.logger.log(`[Stripe Webhook] Adding $${amount.toFixed(2)} to balance`);
|
|
176
229
|
await appService.addBalance(amount);
|
|
230
|
+
// Get balance after
|
|
177
231
|
const balanceAfter = await appService.getBalance();
|
|
178
232
|
logger_1.logger.log(`[Stripe Webhook] Balance after: $${balanceAfter.toFixed(2)}`);
|
|
233
|
+
// Update transaction status
|
|
179
234
|
logger_1.logger.log(`[Stripe Webhook] Updating transaction status to 'succeeded'`);
|
|
180
235
|
await appService.updateTransactionStatus(paymentIntent.id, 'succeeded');
|
|
236
|
+
// Resume any paused stories now that balance is positive
|
|
181
237
|
logger_1.logger.log(`[Stripe Webhook] Checking for paused stories to resume...`);
|
|
182
238
|
const resumedCount = await appService.resumePausedStories();
|
|
183
239
|
if (resumedCount > 0) {
|
|
@@ -190,6 +246,11 @@ let StripeService = class StripeService {
|
|
|
190
246
|
throw error;
|
|
191
247
|
}
|
|
192
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Handle failed payment
|
|
251
|
+
* @param paymentIntent Payment Intent
|
|
252
|
+
* @param appService App service for the user
|
|
253
|
+
*/
|
|
193
254
|
async handlePaymentIntentFailed(paymentIntent, appService) {
|
|
194
255
|
try {
|
|
195
256
|
const userId = paymentIntent.metadata.userId;
|
|
@@ -197,6 +258,7 @@ let StripeService = class StripeService {
|
|
|
197
258
|
logger_1.logger.error('Payment Intent missing userId in metadata:', paymentIntent.id);
|
|
198
259
|
return;
|
|
199
260
|
}
|
|
261
|
+
// Update transaction status
|
|
200
262
|
await appService.updateTransactionStatus(paymentIntent.id, 'failed');
|
|
201
263
|
logger_1.logger.log(`Payment failed for user ${userId}: ${paymentIntent.id}`);
|
|
202
264
|
}
|
|
@@ -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,10 @@ 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
|
+
const illustration_service_1 = require("../room/illustration/illustration.service");
|
|
44
|
+
/**
|
|
45
|
+
* Factory for creating user-specific AppService instances with their dependencies
|
|
46
|
+
*/
|
|
43
47
|
let UserServiceFactory = class UserServiceFactory {
|
|
44
48
|
aiFactoryService;
|
|
45
49
|
agentMessageService;
|
|
@@ -63,30 +67,69 @@ let UserServiceFactory = class UserServiceFactory {
|
|
|
63
67
|
this.configService = configService;
|
|
64
68
|
this.nativeToolRegistry = nativeToolRegistry;
|
|
65
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new AppService instance with user-specific dependencies
|
|
72
|
+
* @param userId The user ID for which to create the service
|
|
73
|
+
* @returns A new AppService instance configured for the specified user
|
|
74
|
+
*/
|
|
66
75
|
createAppService(userId) {
|
|
76
|
+
// 1. Create UserPathsService with userId (reads BRIYAH_DATA_PATH from env)
|
|
67
77
|
const userPaths = new user_paths_service_1.UserPathsService(userId);
|
|
78
|
+
// 1.5. Per-user settings, and the packs they turn on. Everything that
|
|
79
|
+
// filters a listing by pack reads enablement through PackService, and does
|
|
80
|
+
// so through a thunk rather than a snapshot: this AppService is cached for
|
|
81
|
+
// half an hour, so a copy taken here would go stale the moment the user
|
|
82
|
+
// toggled a pack in another tab.
|
|
68
83
|
const userConfig = new user_config_service_1.UserConfigService(userPaths);
|
|
69
84
|
const packService = new pack_service_1.PackService(userPaths, userConfig, () => this.nativeToolRegistry.listTools().map((tool) => tool.name));
|
|
85
|
+
// 2. Create BalanceService (depends on UserPathsService and BalanceMessageService)
|
|
70
86
|
const balanceService = new balance_service_1.BalanceService(userId, userPaths, this.balanceMessageService);
|
|
71
87
|
const transactionService = new transaction_service_1.TransactionService(userId, userPaths);
|
|
88
|
+
// 3. Create AttachedFileService (depends on UserPathsService)
|
|
72
89
|
const attachedFileService = new attached_file_service_1.AttachedFileService(userPaths);
|
|
90
|
+
// 3.5. Create ArtifactService (depends on UserPathsService)
|
|
73
91
|
const artifactService = new artifact_service_1.ArtifactService(userPaths);
|
|
74
92
|
artifactService.setEnabledPacks(() => packService.enabledPacks());
|
|
93
|
+
// 4. Create AgentStoreService (depends on UserPathsService, AttachedFileService, BalanceService, and ArtifactService)
|
|
75
94
|
const agentStore = new agent_store_service_1.AgentStoreService(this.aiFactoryService, userPaths, attachedFileService, balanceService, artifactService, this.configService);
|
|
95
|
+
// 5. Create AgentFactory (depends on AiFactoryService, AgentStoreService, UserPathsService, BalanceService, and ArtifactService)
|
|
76
96
|
const agentFactory = new agent_factory_1.AgentFactory(this.aiFactoryService, agentStore, userPaths, balanceService, artifactService, this.configService);
|
|
97
|
+
// 5.5. Create ArtifactStoreService (no dependencies)
|
|
77
98
|
const artifactStore = new artifact_store_service_1.ArtifactStoreService();
|
|
99
|
+
// 5.6. Create tool services (native + user-defined tools agents can EXECUTE).
|
|
100
|
+
// User-authored (string) tools are gated off by default; native tools are
|
|
101
|
+
// always available. The native registry is shared across all users.
|
|
78
102
|
const toolStore = new tool_store_service_1.ToolStoreService(userPaths);
|
|
79
103
|
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,
|
|
104
|
+
const toolExecution = new tool_execution_service_1.ToolExecutionService(toolStore, this.nativeToolRegistry, allowUserAuthoredTools,
|
|
105
|
+
// Read access to installed packs' shipped documents, reaching tools as
|
|
106
|
+
// `helpers.packDocuments`. Deliberately the file listing rather than the
|
|
107
|
+
// manifest, so a pack's tools see a document the moment it is dropped in.
|
|
108
|
+
{
|
|
81
109
|
list: (pack, prefix) => artifactService.listPackDocumentFiles(pack, prefix),
|
|
82
110
|
read: (pack, fileName) => artifactService.readPackDocumentFile(pack, fileName),
|
|
83
111
|
});
|
|
112
|
+
// 6. Create RoomStoreService (depends on UserPathsService, AgentStoreService, AttachedFileService, ArtifactStoreService, and tool services)
|
|
84
113
|
const roomStore = new room_store_service_1.RoomStoreService(userPaths, agentStore, attachedFileService, artifactStore, toolStore, toolExecution);
|
|
114
|
+
// 7. Create RoomFactory (depends on RoomStoreService and tool services)
|
|
85
115
|
const roomFactory = new room_factory_1.RoomFactory(roomStore, toolStore, toolExecution);
|
|
116
|
+
// 8. Create StoryStoreService (depends on UserPathsService)
|
|
86
117
|
const storyStore = new story_store_service_1.StoryStoreService(userPaths, roomStore);
|
|
87
|
-
|
|
88
|
-
|
|
118
|
+
// 8b. The illustration pipeline. Shared by stories and rooms, so it is built
|
|
119
|
+
// here rather than inside either of them.
|
|
120
|
+
const illustration = new illustration_service_1.IllustrationService(userPaths, agentStore, agentFactory);
|
|
121
|
+
roomStore.setIllustrationService(illustration);
|
|
122
|
+
roomFactory.setIllustrationService(illustration);
|
|
123
|
+
// 9. Create StoryService (depends on all user-specific services)
|
|
124
|
+
const storyService = new story_service_1.StoryService(storyStore, agentStore, roomStore, this.storyProgressService, this.storyMessageService, userPaths, agentFactory, roomFactory, illustration);
|
|
125
|
+
// 10. Create AppService with all dependencies
|
|
126
|
+
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, illustration);
|
|
127
|
+
// Built after the AppService it drives, and handed back through it, because
|
|
128
|
+
// instantiating a pack's room goes through the same createRoom and
|
|
129
|
+
// createRoomAgent paths the API uses rather than around them.
|
|
89
130
|
appService.setPackInstantiation(new pack_instantiation_service_1.PackInstantiationService(appService, packService, roomStore));
|
|
131
|
+
// Built after pack instantiation because it drives that too: a campaign is a
|
|
132
|
+
// pack room with a party seated on it and a public link.
|
|
90
133
|
appService.setRpg(new rpg_service_1.RpgService(appService, packService, userConfig, userPaths, userId));
|
|
91
134
|
return appService;
|
|
92
135
|
}
|