briyah 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -8
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/config/story_models.json +3 -3
- package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/data/common/prompts/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/rooms/campaign.json +18 -15
- package/data/packs/dnd5e/rooms/table.json +17 -16
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
- package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
- package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
- package/dist-sdk/server/src/ai/agent.d.ts +197 -2
- package/dist-sdk/server/src/ai/agent.js +225 -14
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +46 -3
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +120 -0
- package/dist-sdk/server/src/app.controller.js +365 -14
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1710 -4
- package/dist-sdk/server/src/app.service.js +1938 -20
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +84 -1
- package/dist-sdk/server/src/room/room-config.js +19 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
- package/dist-sdk/server/src/room/room-factory.js +25 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
- package/dist-sdk/server/src/room/room-store.service.js +280 -6
- package/dist-sdk/server/src/room/room.d.ts +981 -1
- package/dist-sdk/server/src/room/room.js +1531 -27
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +366 -9
- package/dist-sdk/server/src/story/story.service.js +825 -374
- package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +24 -1
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
- package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +328 -13
- package/dist-sdk/shared/types/app.types.js +18 -1
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Documents shipped by a pack, exposed as read-only artifacts.
|
|
4
|
+
*
|
|
5
|
+
* A pack like `dnd5e` ships reference material its tools deliberately do not
|
|
6
|
+
* cover — combat procedure, class features — which an agent needs as an attached
|
|
7
|
+
* document rather than a tool result. Those files live in
|
|
8
|
+
* `data/packs/<pack>/artifacts/` beside a `manifest.json`, and are surfaced
|
|
9
|
+
* through {@link ArtifactService} so the Artifacts page and the per-agent attach
|
|
10
|
+
* flow treat them like any other artifact.
|
|
11
|
+
*
|
|
12
|
+
* Two properties matter and are the reason this is not a per-user copy:
|
|
13
|
+
*
|
|
14
|
+
* - **The ids are stable.** `pack:dnd5e.class-wizard` is the same string for every
|
|
15
|
+
* user, across restarts and reinstalls. `agent.attachedArtifacts` holds ids and
|
|
16
|
+
* resolves them on every request, so an id that changed would silently drop a
|
|
17
|
+
* document out of an agent's context. Moving these files from
|
|
18
|
+
* `common/artifacts/<pack>/` to `packs/<pack>/artifacts/` deliberately did not
|
|
19
|
+
* change one.
|
|
20
|
+
* - **They are read-only.** There is one copy, so a correction reaches everyone,
|
|
21
|
+
* and nothing has to remember that a user deleted one.
|
|
22
|
+
*/
|
|
2
23
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
24
|
if (k2 === undefined) k2 = k;
|
|
4
25
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -44,13 +65,61 @@ exports.resetPackArtifactCache = resetPackArtifactCache;
|
|
|
44
65
|
const fs = __importStar(require("fs"));
|
|
45
66
|
const path = __importStar(require("path"));
|
|
46
67
|
const logger_1 = require("../common/logger");
|
|
68
|
+
/** Marks an artifact id as belonging to a pack rather than to a user. */
|
|
47
69
|
exports.PACK_ARTIFACT_PREFIX = 'pack:';
|
|
70
|
+
/**
|
|
71
|
+
* Separates the pack from the document in an id: `pack:dnd5e.class-wizard`.
|
|
72
|
+
*
|
|
73
|
+
* Deliberately not a slash. An artifact id travels as a path segment on the
|
|
74
|
+
* detach route (`DELETE /api/agents/:agentId/artifacts/:artifactId`), and a slash
|
|
75
|
+
* there splits into an extra segment that matches nothing. Pack names must not
|
|
76
|
+
* contain this character.
|
|
77
|
+
*/
|
|
48
78
|
const PACK_SEPARATOR = '.';
|
|
79
|
+
/**
|
|
80
|
+
* The extension a pack document has. Every shipped document is Markdown — the
|
|
81
|
+
* manifest loader hardcodes `text/markdown` as the mime type — and restricting
|
|
82
|
+
* {@link listPackDocumentFiles} to it keeps an editor's backup copy of a document
|
|
83
|
+
* from listing as a second document.
|
|
84
|
+
*/
|
|
49
85
|
const DOCUMENT_EXTENSION = '.md';
|
|
86
|
+
/**
|
|
87
|
+
* Parsed manifests, keyed by the pack roots they were read from.
|
|
88
|
+
*
|
|
89
|
+
* The files ship with the build and never change while the process runs, so they
|
|
90
|
+
* are read once. Keyed by the roots because tests point at fixtures, and because
|
|
91
|
+
* a host may hand different users different roots.
|
|
92
|
+
*/
|
|
50
93
|
const cache = new Map();
|
|
94
|
+
/** True when the id names a pack document rather than a user artifact. */
|
|
51
95
|
function isPackArtifactId(artifactId) {
|
|
52
96
|
return artifactId.startsWith(exports.PACK_ARTIFACT_PREFIX);
|
|
53
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads every pack's artifact manifest under the given pack roots.
|
|
100
|
+
*
|
|
101
|
+
* A pack root holds one subdirectory per pack, and each pack keeps its documents
|
|
102
|
+
* in an `artifacts/` subdirectory of its own. **The pack name comes from the pack
|
|
103
|
+
* directory, not from the directory the manifest sits in** — `loadPack` refuses a
|
|
104
|
+
* manifest whose `pack` disagrees with the name it is given, so passing
|
|
105
|
+
* `'artifacts'` would reject every manifest and drop every document with nothing
|
|
106
|
+
* but a warning to show for it.
|
|
107
|
+
*
|
|
108
|
+
* A manifest that is missing, unparseable, or names a file that is not there is
|
|
109
|
+
* skipped with a warning rather than thrown: a bad shipped document must not stop
|
|
110
|
+
* the Artifacts page from listing the user's own.
|
|
111
|
+
*
|
|
112
|
+
* **Layering is per document, not per pack, and that is load-bearing.** A user's
|
|
113
|
+
* pack directory is a copy-on-write mirror holding only what they changed, so it
|
|
114
|
+
* routinely exists holding a single *prompt* and no `artifacts/` directory at all.
|
|
115
|
+
* A root that merely has a directory of the right name must therefore not take the
|
|
116
|
+
* pack over: doing so hides every document the other roots supply, both from the
|
|
117
|
+
* listing and from the agents that resolve one on every request — and nothing
|
|
118
|
+
* reports it, since a document that fails to resolve is simply absent from a
|
|
119
|
+
* prompt. So each root contributes the documents it actually defines, earlier roots
|
|
120
|
+
* winning per id. `prompt-resolver.ts` describes the same mirror-shadows-path model
|
|
121
|
+
* for prompts.
|
|
122
|
+
*/
|
|
54
123
|
function loadAll(packRoots) {
|
|
55
124
|
const key = packRoots.join(path.delimiter);
|
|
56
125
|
const cached = cache.get(key);
|
|
@@ -66,6 +135,8 @@ function loadAll(packRoots) {
|
|
|
66
135
|
continue;
|
|
67
136
|
const artifactsDir = path.join(root, entry.name, 'artifacts');
|
|
68
137
|
for (const resolved of loadPack(packRoots, artifactsDir, entry.name)) {
|
|
138
|
+
// First root to define an id wins; later roots fill in the rest,
|
|
139
|
+
// so an overlay may replace one document without hiding the others.
|
|
69
140
|
if (!documents.has(resolved.metadata.artifactId)) {
|
|
70
141
|
documents.set(resolved.metadata.artifactId, resolved);
|
|
71
142
|
}
|
|
@@ -75,6 +146,15 @@ function loadAll(packRoots) {
|
|
|
75
146
|
cache.set(key, documents);
|
|
76
147
|
return documents;
|
|
77
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Resolves one manifest's entries against the files they name.
|
|
151
|
+
* @param packRoots Every root, so a document's *file* layers the same way its
|
|
152
|
+
* entry does — an overlaid copy of `class-wizard.md` is the one that is read,
|
|
153
|
+
* whether or not the overlay declares a manifest of its own
|
|
154
|
+
* @param packDir The `artifacts/` directory this manifest sits in
|
|
155
|
+
* @param dirName The pack directory's name, which the manifest must agree with
|
|
156
|
+
* @returns One entry per document that resolved
|
|
157
|
+
*/
|
|
78
158
|
function loadPack(packRoots, packDir, dirName) {
|
|
79
159
|
const manifestPath = path.join(packDir, 'manifest.json');
|
|
80
160
|
if (!fs.existsSync(manifestPath)) {
|
|
@@ -106,6 +186,8 @@ function loadPack(packRoots, packDir, dirName) {
|
|
|
106
186
|
logger_1.logger.warn(`Skipping "${document.id}" in ${manifestPath}: an id may not contain "${PACK_SEPARATOR}"`);
|
|
107
187
|
continue;
|
|
108
188
|
}
|
|
189
|
+
// The manifest ships with the build, but a file name is still a path and
|
|
190
|
+
// is treated as one.
|
|
109
191
|
if (document.file !== path.basename(document.file)) {
|
|
110
192
|
logger_1.logger.warn(`Skipping "${document.id}" in ${manifestPath}: file must be a bare name`);
|
|
111
193
|
continue;
|
|
@@ -131,8 +213,23 @@ function loadPack(packRoots, packDir, dirName) {
|
|
|
131
213
|
},
|
|
132
214
|
});
|
|
133
215
|
}
|
|
216
|
+
// The pack name prefixes every id, so this also proves ids are unique overall.
|
|
134
217
|
return resolved;
|
|
135
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Lists the documents of the packs a given user has **enabled**.
|
|
221
|
+
*
|
|
222
|
+
* Gating applies to listing only. {@link getPackArtifact} resolves a document
|
|
223
|
+
* whatever the pack list says, so turning a pack off does not silently strip a
|
|
224
|
+
* document out of an agent that already has it attached.
|
|
225
|
+
*
|
|
226
|
+
* The enabled set is a parameter rather than a module-level lookup because
|
|
227
|
+
* enablement is per user, and this module is shared by every user in the process.
|
|
228
|
+
*
|
|
229
|
+
* @param packRoots Directories holding packs, one subdirectory per pack
|
|
230
|
+
* @param enabledPacks The packs this user has switched on
|
|
231
|
+
* @returns Metadata for every listable pack document, sorted by name
|
|
232
|
+
*/
|
|
136
233
|
function listPackArtifacts(packRoots, enabledPacks) {
|
|
137
234
|
const packs = new Set(enabledPacks);
|
|
138
235
|
return [...loadAll(packRoots).values()]
|
|
@@ -140,12 +237,25 @@ function listPackArtifacts(packRoots, enabledPacks) {
|
|
|
140
237
|
.map((doc) => doc.metadata)
|
|
141
238
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
142
239
|
}
|
|
240
|
+
/** The pack name out of a `pack:<pack>.<name>` id. */
|
|
143
241
|
function packOf(artifactId) {
|
|
144
242
|
return artifactId.slice(exports.PACK_ARTIFACT_PREFIX.length).split(PACK_SEPARATOR)[0];
|
|
145
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Reads a pack document's metadata.
|
|
246
|
+
* @param packRoots Directories holding packs, one subdirectory per pack
|
|
247
|
+
* @param artifactId A `pack:`-prefixed id
|
|
248
|
+
* @returns The metadata, or null if no such document ships
|
|
249
|
+
*/
|
|
146
250
|
function getPackArtifactMetadata(packRoots, artifactId) {
|
|
147
251
|
return loadAll(packRoots).get(artifactId)?.metadata ?? null;
|
|
148
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Reads a pack document's content.
|
|
255
|
+
* @param packRoots Directories holding packs, one subdirectory per pack
|
|
256
|
+
* @param artifactId A `pack:`-prefixed id
|
|
257
|
+
* @returns The Markdown, or null if no such document ships
|
|
258
|
+
*/
|
|
149
259
|
function getPackArtifact(packRoots, artifactId) {
|
|
150
260
|
const document = loadAll(packRoots).get(artifactId);
|
|
151
261
|
if (!document) {
|
|
@@ -159,6 +269,28 @@ function getPackArtifact(packRoots, artifactId) {
|
|
|
159
269
|
return null;
|
|
160
270
|
}
|
|
161
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Lists a pack's document files by name, rather than by manifest entry.
|
|
274
|
+
*
|
|
275
|
+
* The manifest is the listing for *people* — it carries the display name the
|
|
276
|
+
* Artifacts page and the attach dialog show, so a file with no entry is invisible
|
|
277
|
+
* there. This is the listing for *code*, and it deliberately reads the directory
|
|
278
|
+
* instead: a pack whose tools enumerate their own documents lets an operator add
|
|
279
|
+
* one by dropping a file in, with nothing else to edit. The 5e pack's
|
|
280
|
+
* `class-*.md` documents are the case this exists for.
|
|
281
|
+
*
|
|
282
|
+
* Resolved per file rather than per pack, so a user's overlay may replace one
|
|
283
|
+
* document without hiding the rest — the same layering `prompt-resolver.ts` uses,
|
|
284
|
+
* and deliberately not {@link loadAll}'s whole-pack claim.
|
|
285
|
+
*
|
|
286
|
+
* Not gated on pack enablement, for the same reason {@link getPackArtifact} is
|
|
287
|
+
* not: a tool that has been granted must keep working.
|
|
288
|
+
*
|
|
289
|
+
* @param packRoots Directories holding packs, one subdirectory per pack
|
|
290
|
+
* @param pack The pack name
|
|
291
|
+
* @param prefix Keep only file names starting with this, case-insensitively
|
|
292
|
+
* @returns Bare file names, each ending in `.md`, sorted and without duplicates
|
|
293
|
+
*/
|
|
162
294
|
function listPackDocumentFiles(packRoots, pack, prefix = '') {
|
|
163
295
|
if (!isBareName(pack)) {
|
|
164
296
|
return [];
|
|
@@ -176,12 +308,25 @@ function listPackDocumentFiles(packRoots, pack, prefix = '') {
|
|
|
176
308
|
const key = name.toLowerCase();
|
|
177
309
|
if (!key.endsWith(DOCUMENT_EXTENSION) || !key.startsWith(wanted))
|
|
178
310
|
continue;
|
|
311
|
+
// First root wins, so an overlay's copy of a document does not list twice.
|
|
179
312
|
if (!found.has(key))
|
|
180
313
|
found.set(key, name);
|
|
181
314
|
}
|
|
182
315
|
}
|
|
183
316
|
return [...found.values()].sort((a, b) => a.localeCompare(b));
|
|
184
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Reads one of a pack's document files by name.
|
|
320
|
+
*
|
|
321
|
+
* The counterpart to {@link listPackDocumentFiles}: what that lists, this reads.
|
|
322
|
+
* Roots are searched in order, so a user's overlay of a document wins over the
|
|
323
|
+
* installed one.
|
|
324
|
+
*
|
|
325
|
+
* @param packRoots Directories holding packs, one subdirectory per pack
|
|
326
|
+
* @param pack The pack name
|
|
327
|
+
* @param fileName A bare file name, as returned by {@link listPackDocumentFiles}
|
|
328
|
+
* @returns The file's text, or null if there is no such document
|
|
329
|
+
*/
|
|
185
330
|
function readPackDocumentFile(packRoots, pack, fileName) {
|
|
186
331
|
const filePath = findDocumentFile(packRoots, pack, fileName);
|
|
187
332
|
if (!filePath) {
|
|
@@ -195,6 +340,19 @@ function readPackDocumentFile(packRoots, pack, fileName) {
|
|
|
195
340
|
return null;
|
|
196
341
|
}
|
|
197
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Locates one of a pack's document files, highest-precedence root first.
|
|
345
|
+
*
|
|
346
|
+
* The single place a document's file is resolved, so the manifest tier and the file
|
|
347
|
+
* tier cannot disagree about which copy of `class-wizard.md` is the real one — an
|
|
348
|
+
* agent's attached document and `class_guide`'s reading of the same file would
|
|
349
|
+
* otherwise diverge the moment a user overlaid it.
|
|
350
|
+
*
|
|
351
|
+
* @param packRoots Directories holding packs, one subdirectory per pack
|
|
352
|
+
* @param pack The pack name
|
|
353
|
+
* @param fileName A bare file name
|
|
354
|
+
* @returns The path to read, or null when no root has the file
|
|
355
|
+
*/
|
|
198
356
|
function findDocumentFile(packRoots, pack, fileName) {
|
|
199
357
|
if (!isBareName(pack) || !isBareName(fileName)) {
|
|
200
358
|
return null;
|
|
@@ -206,6 +364,15 @@ function findDocumentFile(packRoots, pack, fileName) {
|
|
|
206
364
|
}
|
|
207
365
|
return null;
|
|
208
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* Whether a name may be joined onto a path as a single component.
|
|
369
|
+
*
|
|
370
|
+
* These two functions take names that reach them from a tool, and therefore
|
|
371
|
+
* ultimately from a model, so a name is checked rather than trusted. `path.basename`
|
|
372
|
+
* settles both traversal and separators in one comparison; the leading-dot rule
|
|
373
|
+
* keeps `.` and `..` out, and on NTFS a colon would be read as the alternate-data-stream
|
|
374
|
+
* separator rather than failing cleanly.
|
|
375
|
+
*/
|
|
209
376
|
function isBareName(name) {
|
|
210
377
|
return (typeof name === 'string' &&
|
|
211
378
|
name.length > 0 &&
|
|
@@ -213,6 +380,7 @@ function isBareName(name) {
|
|
|
213
380
|
!name.includes(':') &&
|
|
214
381
|
name === path.basename(name));
|
|
215
382
|
}
|
|
383
|
+
/** Test seam: drops the parsed manifests so a spec can rewrite its fixtures. */
|
|
216
384
|
function resetPackArtifactCache() {
|
|
217
385
|
cache.clear();
|
|
218
386
|
}
|
|
@@ -4,10 +4,35 @@ export declare class PublishedAgentsService implements OnModuleInit {
|
|
|
4
4
|
private readonly mappingFile;
|
|
5
5
|
constructor();
|
|
6
6
|
onModuleInit(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Get the userId for a published agent
|
|
9
|
+
* @param agentId The agent ID to lookup
|
|
10
|
+
* @returns The userId who owns the agent, or undefined if not found
|
|
11
|
+
*/
|
|
7
12
|
getUserId(agentId: string): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Add a published agent to the mapping
|
|
15
|
+
* @param agentId The agent ID
|
|
16
|
+
* @param userId The user who owns the agent
|
|
17
|
+
*/
|
|
8
18
|
addPublishedAgent(agentId: string, userId: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Remove a published agent from the mapping
|
|
21
|
+
* @param agentId The agent ID to remove
|
|
22
|
+
*/
|
|
9
23
|
removePublishedAgent(agentId: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Check if an agent is in the published mapping
|
|
26
|
+
* @param agentId The agent ID to check
|
|
27
|
+
* @returns True if the agent is in the mapping
|
|
28
|
+
*/
|
|
10
29
|
isAgentPublished(agentId: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Load the mapping from disk
|
|
32
|
+
*/
|
|
11
33
|
private load;
|
|
34
|
+
/**
|
|
35
|
+
* Save the mapping to disk
|
|
36
|
+
*/
|
|
12
37
|
private save;
|
|
13
38
|
}
|
|
@@ -48,11 +48,13 @@ const fs = __importStar(require("fs"));
|
|
|
48
48
|
const path = __importStar(require("path"));
|
|
49
49
|
const logger_1 = require("../common/logger");
|
|
50
50
|
let PublishedAgentsService = class PublishedAgentsService {
|
|
51
|
-
mapping = new Map();
|
|
51
|
+
mapping = new Map(); // agentId → userId
|
|
52
52
|
mappingFile;
|
|
53
53
|
constructor() {
|
|
54
|
+
// Priority: env var > default
|
|
54
55
|
const dataPath = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
|
|
55
56
|
const dataDir = path.resolve(dataPath, 'common');
|
|
57
|
+
// Ensure the data/common directory exists
|
|
56
58
|
if (!fs.existsSync(dataDir)) {
|
|
57
59
|
fs.mkdirSync(dataDir, { recursive: true });
|
|
58
60
|
}
|
|
@@ -61,26 +63,48 @@ let PublishedAgentsService = class PublishedAgentsService {
|
|
|
61
63
|
onModuleInit() {
|
|
62
64
|
this.load();
|
|
63
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the userId for a published agent
|
|
68
|
+
* @param agentId The agent ID to lookup
|
|
69
|
+
* @returns The userId who owns the agent, or undefined if not found
|
|
70
|
+
*/
|
|
64
71
|
getUserId(agentId) {
|
|
65
72
|
return this.mapping.get(agentId);
|
|
66
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Add a published agent to the mapping
|
|
76
|
+
* @param agentId The agent ID
|
|
77
|
+
* @param userId The user who owns the agent
|
|
78
|
+
*/
|
|
67
79
|
addPublishedAgent(agentId, userId) {
|
|
68
80
|
this.mapping.set(agentId, userId);
|
|
69
81
|
this.save();
|
|
70
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Remove a published agent from the mapping
|
|
85
|
+
* @param agentId The agent ID to remove
|
|
86
|
+
*/
|
|
71
87
|
removePublishedAgent(agentId) {
|
|
72
88
|
this.mapping.delete(agentId);
|
|
73
89
|
this.save();
|
|
74
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Check if an agent is in the published mapping
|
|
93
|
+
* @param agentId The agent ID to check
|
|
94
|
+
* @returns True if the agent is in the mapping
|
|
95
|
+
*/
|
|
75
96
|
isAgentPublished(agentId) {
|
|
76
97
|
return this.mapping.has(agentId);
|
|
77
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Load the mapping from disk
|
|
101
|
+
*/
|
|
78
102
|
load() {
|
|
79
103
|
try {
|
|
80
104
|
if (!fs.existsSync(this.mappingFile)) {
|
|
81
105
|
logger_1.logger.log('[PublishedAgentsService] No published agents file found, starting fresh');
|
|
82
106
|
this.mapping = new Map();
|
|
83
|
-
this.save();
|
|
107
|
+
this.save(); // Create initial file
|
|
84
108
|
return;
|
|
85
109
|
}
|
|
86
110
|
const data = fs.readFileSync(this.mappingFile, 'utf-8');
|
|
@@ -96,9 +120,12 @@ let PublishedAgentsService = class PublishedAgentsService {
|
|
|
96
120
|
logger_1.logger.error('[PublishedAgentsService] Error loading published agents:', error);
|
|
97
121
|
logger_1.logger.log('[PublishedAgentsService] Starting with empty mapping');
|
|
98
122
|
this.mapping = new Map();
|
|
99
|
-
this.save();
|
|
123
|
+
this.save(); // Create fresh file
|
|
100
124
|
}
|
|
101
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Save the mapping to disk
|
|
128
|
+
*/
|
|
102
129
|
save() {
|
|
103
130
|
try {
|
|
104
131
|
const data = {
|
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
/**
|
|
3
|
+
* Service for managing SSE connections for user balance updates
|
|
4
|
+
* Uses event-driven updates triggered by balance changes (no polling)
|
|
5
|
+
*/
|
|
2
6
|
export declare class BalanceMessageService {
|
|
3
7
|
private messageEmitters;
|
|
8
|
+
/**
|
|
9
|
+
* Gets or creates a message emitter for a user
|
|
10
|
+
* @param userId The user ID
|
|
11
|
+
* @returns The event emitter for this user
|
|
12
|
+
*/
|
|
4
13
|
getOrCreateEmitter(userId: string): EventEmitter;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the message emitter for a user
|
|
16
|
+
* @param userId The user ID
|
|
17
|
+
* @returns The event emitter or undefined if not found
|
|
18
|
+
*/
|
|
5
19
|
getEmitter(userId: string): EventEmitter | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Emits a balance update event for a user
|
|
22
|
+
* Called when user's balance changes
|
|
23
|
+
* @param userId The user ID
|
|
24
|
+
* @param balance The updated balance
|
|
25
|
+
*/
|
|
6
26
|
emitUpdate(userId: string, balance: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* Cleans up the message emitter for a user
|
|
29
|
+
* @param userId The user ID
|
|
30
|
+
*/
|
|
7
31
|
cleanup(userId: string): void;
|
|
8
32
|
}
|
|
@@ -9,8 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.BalanceMessageService = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const events_1 = require("events");
|
|
12
|
+
/**
|
|
13
|
+
* Service for managing SSE connections for user balance updates
|
|
14
|
+
* Uses event-driven updates triggered by balance changes (no polling)
|
|
15
|
+
*/
|
|
12
16
|
let BalanceMessageService = class BalanceMessageService {
|
|
13
17
|
messageEmitters = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Gets or creates a message emitter for a user
|
|
20
|
+
* @param userId The user ID
|
|
21
|
+
* @returns The event emitter for this user
|
|
22
|
+
*/
|
|
14
23
|
getOrCreateEmitter(userId) {
|
|
15
24
|
let emitter = this.messageEmitters.get(userId);
|
|
16
25
|
if (!emitter) {
|
|
@@ -19,9 +28,20 @@ let BalanceMessageService = class BalanceMessageService {
|
|
|
19
28
|
}
|
|
20
29
|
return emitter;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the message emitter for a user
|
|
33
|
+
* @param userId The user ID
|
|
34
|
+
* @returns The event emitter or undefined if not found
|
|
35
|
+
*/
|
|
22
36
|
getEmitter(userId) {
|
|
23
37
|
return this.messageEmitters.get(userId);
|
|
24
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Emits a balance update event for a user
|
|
41
|
+
* Called when user's balance changes
|
|
42
|
+
* @param userId The user ID
|
|
43
|
+
* @param balance The updated balance
|
|
44
|
+
*/
|
|
25
45
|
emitUpdate(userId, balance) {
|
|
26
46
|
const emitter = this.messageEmitters.get(userId);
|
|
27
47
|
if (emitter) {
|
|
@@ -31,6 +51,10 @@ let BalanceMessageService = class BalanceMessageService {
|
|
|
31
51
|
});
|
|
32
52
|
}
|
|
33
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Cleans up the message emitter for a user
|
|
56
|
+
* @param userId The user ID
|
|
57
|
+
*/
|
|
34
58
|
cleanup(userId) {
|
|
35
59
|
const emitter = this.messageEmitters.get(userId);
|
|
36
60
|
if (emitter) {
|
|
@@ -9,6 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.BalanceModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const balance_message_service_1 = require("./balance-message.service");
|
|
12
|
+
/**
|
|
13
|
+
* Module providing balance-related services
|
|
14
|
+
* Provides BalanceMessageService for SSE balance updates
|
|
15
|
+
*/
|
|
12
16
|
let BalanceModule = class BalanceModule {
|
|
13
17
|
};
|
|
14
18
|
exports.BalanceModule = BalanceModule;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { UserPathsService } from '../config/user-paths.service';
|
|
2
2
|
import { BalanceMessageService } from './balance-message.service';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing user balance
|
|
5
|
+
* Tracks AI usage costs and enforces spending limits
|
|
6
|
+
*/
|
|
3
7
|
export declare class BalanceService {
|
|
4
8
|
private userId;
|
|
5
9
|
private userPaths;
|
|
@@ -8,11 +12,44 @@ export declare class BalanceService {
|
|
|
8
12
|
private startingBalance;
|
|
9
13
|
private balanceMessageService?;
|
|
10
14
|
constructor(userId: string, userPaths: UserPathsService, balanceMessageService?: BalanceMessageService);
|
|
15
|
+
/**
|
|
16
|
+
* Get current balance (loads from file)
|
|
17
|
+
* @returns Current balance as number
|
|
18
|
+
* @throws If balance file is corrupted
|
|
19
|
+
*/
|
|
11
20
|
getBalance(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Get current markup (loads from file)
|
|
23
|
+
* @returns Current markup total
|
|
24
|
+
* @throws If markup file is corrupted
|
|
25
|
+
*/
|
|
12
26
|
getMarkup(): number;
|
|
27
|
+
/**
|
|
28
|
+
* Check if user has sufficient balance to make AI calls
|
|
29
|
+
* @returns true if balance >= 0, false otherwise
|
|
30
|
+
*/
|
|
13
31
|
hasSufficientBalance(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Decrement balance by specified amount
|
|
34
|
+
* @param amount Amount to subtract from balance
|
|
35
|
+
* @param markup Amount to add to markup total
|
|
36
|
+
* @throws If amount is negative
|
|
37
|
+
*/
|
|
14
38
|
decrementBalance(amount: number, markup?: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* Add funds to balance
|
|
41
|
+
* @param amount Amount to add to balance
|
|
42
|
+
* @throws If amount is negative or zero
|
|
43
|
+
*/
|
|
15
44
|
addBalance(amount: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Save balance to file
|
|
47
|
+
* @param balance New balance value
|
|
48
|
+
*/
|
|
16
49
|
private saveBalance;
|
|
50
|
+
/**
|
|
51
|
+
* Save markup to file
|
|
52
|
+
* @param markup
|
|
53
|
+
*/
|
|
17
54
|
private saveMarkup;
|
|
18
55
|
}
|
|
@@ -37,6 +37,10 @@ exports.BalanceService = void 0;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const logger_1 = require("../common/logger");
|
|
40
|
+
/**
|
|
41
|
+
* Service for managing user balance
|
|
42
|
+
* Tracks AI usage costs and enforces spending limits
|
|
43
|
+
*/
|
|
40
44
|
class BalanceService {
|
|
41
45
|
userId;
|
|
42
46
|
userPaths;
|
|
@@ -48,6 +52,7 @@ class BalanceService {
|
|
|
48
52
|
this.userId = userId;
|
|
49
53
|
this.userPaths = userPaths;
|
|
50
54
|
this.balanceMessageService = balanceMessageService;
|
|
55
|
+
// Validate and load STARTING_BALANCE from environment
|
|
51
56
|
if (!process.env.STARTING_BALANCE) {
|
|
52
57
|
throw new Error('STARTING_BALANCE environment variable is required');
|
|
53
58
|
}
|
|
@@ -58,18 +63,28 @@ class BalanceService {
|
|
|
58
63
|
if (this.startingBalance < 0) {
|
|
59
64
|
throw new Error('STARTING_BALANCE must be non-negative');
|
|
60
65
|
}
|
|
66
|
+
// Set balance file path in user's userconfig directory
|
|
61
67
|
const userconfigPath = this.userPaths.getUserConfigDir();
|
|
62
68
|
this.balanceFilePath = path.join(userconfigPath, 'balance');
|
|
63
69
|
const commonConfigPath = this.userPaths.getCommonConfigDir();
|
|
64
70
|
this.markupFilePath = path.join(commonConfigPath, 'markup');
|
|
65
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Get current balance (loads from file)
|
|
74
|
+
* @returns Current balance as number
|
|
75
|
+
* @throws If balance file is corrupted
|
|
76
|
+
*/
|
|
66
77
|
getBalance() {
|
|
67
78
|
try {
|
|
79
|
+
// Check if balance file exists
|
|
68
80
|
if (!fs.existsSync(this.balanceFilePath)) {
|
|
81
|
+
// Create with starting balance for new users
|
|
69
82
|
this.saveBalance(this.startingBalance);
|
|
70
83
|
return this.startingBalance;
|
|
71
84
|
}
|
|
85
|
+
// Read balance file
|
|
72
86
|
const balanceStr = fs.readFileSync(this.balanceFilePath, 'utf-8').trim();
|
|
87
|
+
// Parse number
|
|
73
88
|
const balance = parseFloat(balanceStr);
|
|
74
89
|
if (isNaN(balance)) {
|
|
75
90
|
logger_1.logger.error(`Balance file corrupted for user ${this.userId}, resetting to starting balance`);
|
|
@@ -80,16 +95,26 @@ class BalanceService {
|
|
|
80
95
|
}
|
|
81
96
|
catch (error) {
|
|
82
97
|
logger_1.logger.error(`Error reading balance for user ${this.userId}:`, error);
|
|
98
|
+
// Return starting balance as fallback
|
|
83
99
|
return this.startingBalance;
|
|
84
100
|
}
|
|
85
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Get current markup (loads from file)
|
|
104
|
+
* @returns Current markup total
|
|
105
|
+
* @throws If markup file is corrupted
|
|
106
|
+
*/
|
|
86
107
|
getMarkup() {
|
|
87
108
|
try {
|
|
109
|
+
// Check if balance file exists
|
|
88
110
|
if (!fs.existsSync(this.markupFilePath)) {
|
|
111
|
+
// Create with starting markup
|
|
89
112
|
this.saveMarkup(0);
|
|
90
113
|
return 0;
|
|
91
114
|
}
|
|
115
|
+
// Read balance file
|
|
92
116
|
const markupStr = fs.readFileSync(this.markupFilePath, 'utf-8').trim();
|
|
117
|
+
// Parse number
|
|
93
118
|
const markup = parseFloat(markupStr);
|
|
94
119
|
if (isNaN(markup)) {
|
|
95
120
|
logger_1.logger.error(`Markup file corrupted, resetting to 0`);
|
|
@@ -100,13 +125,24 @@ class BalanceService {
|
|
|
100
125
|
}
|
|
101
126
|
catch (error) {
|
|
102
127
|
logger_1.logger.error(`Error reading markup:`, error);
|
|
128
|
+
// Return starting balance as fallback
|
|
103
129
|
return 0;
|
|
104
130
|
}
|
|
105
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if user has sufficient balance to make AI calls
|
|
134
|
+
* @returns true if balance >= 0, false otherwise
|
|
135
|
+
*/
|
|
106
136
|
hasSufficientBalance() {
|
|
107
137
|
const balance = this.getBalance();
|
|
108
138
|
return balance >= 0;
|
|
109
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Decrement balance by specified amount
|
|
142
|
+
* @param amount Amount to subtract from balance
|
|
143
|
+
* @param markup Amount to add to markup total
|
|
144
|
+
* @throws If amount is negative
|
|
145
|
+
*/
|
|
110
146
|
decrementBalance(amount, markup = 0) {
|
|
111
147
|
if (amount < 0) {
|
|
112
148
|
throw new Error('Amount must be positive');
|
|
@@ -118,6 +154,11 @@ class BalanceService {
|
|
|
118
154
|
const newMarkup = currentMarkup + markup;
|
|
119
155
|
this.saveMarkup(newMarkup);
|
|
120
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Add funds to balance
|
|
159
|
+
* @param amount Amount to add to balance
|
|
160
|
+
* @throws If amount is negative or zero
|
|
161
|
+
*/
|
|
121
162
|
addBalance(amount) {
|
|
122
163
|
if (amount <= 0) {
|
|
123
164
|
throw new Error('Amount must be positive');
|
|
@@ -126,13 +167,20 @@ class BalanceService {
|
|
|
126
167
|
const newBalance = currentBalance + amount;
|
|
127
168
|
this.saveBalance(newBalance);
|
|
128
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Save balance to file
|
|
172
|
+
* @param balance New balance value
|
|
173
|
+
*/
|
|
129
174
|
saveBalance(balance) {
|
|
130
175
|
try {
|
|
176
|
+
// Ensure userconfig directory exists
|
|
131
177
|
const userconfigPath = this.userPaths.getUserConfigDir();
|
|
132
178
|
if (!fs.existsSync(userconfigPath)) {
|
|
133
179
|
fs.mkdirSync(userconfigPath, { recursive: true });
|
|
134
180
|
}
|
|
181
|
+
// Write balance to file as plain text
|
|
135
182
|
fs.writeFileSync(this.balanceFilePath, balance.toString(), 'utf-8');
|
|
183
|
+
// Emit SSE update if service is available
|
|
136
184
|
if (this.balanceMessageService) {
|
|
137
185
|
this.balanceMessageService.emitUpdate(this.userId, balance);
|
|
138
186
|
}
|
|
@@ -142,12 +190,18 @@ class BalanceService {
|
|
|
142
190
|
throw error;
|
|
143
191
|
}
|
|
144
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Save markup to file
|
|
195
|
+
* @param markup
|
|
196
|
+
*/
|
|
145
197
|
saveMarkup(markup) {
|
|
146
198
|
try {
|
|
199
|
+
// Ensure userconfig directory exists
|
|
147
200
|
const commonConfigPath = this.userPaths.getCommonConfigDir();
|
|
148
201
|
if (!fs.existsSync(commonConfigPath)) {
|
|
149
202
|
fs.mkdirSync(commonConfigPath, { recursive: true });
|
|
150
203
|
}
|
|
204
|
+
// Write balance to file as plain text
|
|
151
205
|
fs.writeFileSync(this.markupFilePath, markup.toString(), 'utf-8');
|
|
152
206
|
}
|
|
153
207
|
catch (error) {
|