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
|
@@ -15,6 +15,11 @@ export declare class Agent {
|
|
|
15
15
|
agentNickname: string;
|
|
16
16
|
history: any[];
|
|
17
17
|
fullContextFiles: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Generates a nickname from an agent name by taking the first word
|
|
20
|
+
* @param agentName The full agent name
|
|
21
|
+
* @returns The first word as nickname, or the full name if empty
|
|
22
|
+
*/
|
|
18
23
|
static generateNickname(agentName: string): string;
|
|
19
24
|
createdAt: Date;
|
|
20
25
|
totalInputTokens: number;
|
|
@@ -27,22 +32,64 @@ export declare class Agent {
|
|
|
27
32
|
isPublished: boolean;
|
|
28
33
|
templateAgentId?: string;
|
|
29
34
|
ownerRoomId?: string;
|
|
35
|
+
/** The pack this agent is filed under. See {@link AgentConfig.pack}. */
|
|
30
36
|
pack?: string;
|
|
37
|
+
/** The pack template's key, when this agent came from one. */
|
|
31
38
|
packAgentKey?: string;
|
|
32
39
|
openai?: OpenAI;
|
|
33
40
|
assistant?: Assistant;
|
|
34
41
|
vectorStore?: VectorStore;
|
|
42
|
+
/** @internal Direct reference to the AI service */
|
|
35
43
|
aiService: BaseAiService;
|
|
44
|
+
/** @internal Reference to ArtifactService for retrieving artifact content */
|
|
36
45
|
artifactService: ArtifactService;
|
|
46
|
+
/** @internal Reference to user-specific filesystem paths */
|
|
37
47
|
userPaths: UserPathsService;
|
|
48
|
+
/** @internal Reference to environment-variable configuration */
|
|
38
49
|
configService: IConfigService;
|
|
50
|
+
/** @internal Reference to balance service for cost tracking and limits */
|
|
39
51
|
balanceService?: BalanceService;
|
|
40
52
|
description: string;
|
|
53
|
+
/**
|
|
54
|
+
* Private, agent-specific context that is visible only to this agent — never to
|
|
55
|
+
* other agents. Injected into the agent's transient (uncached) prompt message
|
|
56
|
+
* rather than the cached system instructions, so it can change frequently without
|
|
57
|
+
* invalidating the prompt cache. In stories this holds the character's inventory
|
|
58
|
+
* and conditions; contrast with {@link description}, which is the public
|
|
59
|
+
* appearance every other agent can see.
|
|
60
|
+
*/
|
|
41
61
|
privateContext: string;
|
|
42
62
|
promptFolder: string;
|
|
63
|
+
/**
|
|
64
|
+
* The packs the owning user has enabled, consulted only when
|
|
65
|
+
* {@link promptFolder} is a bare name — a pack-qualified one always resolves.
|
|
66
|
+
*
|
|
67
|
+
* A thunk rather than an array because an agent outlives a toggle: the user
|
|
68
|
+
* can enable a pack while this instance is cached, and a snapshot taken at
|
|
69
|
+
* construction would need invalidating across every cached agent, room and
|
|
70
|
+
* service. Reading through the thunk means there is nothing to invalidate.
|
|
71
|
+
*
|
|
72
|
+
* Absent means "scan no packs", which is exactly the behaviour from before
|
|
73
|
+
* packs existed. Deliberately not in `AgentConfig` — it belongs to the user,
|
|
74
|
+
* not the agent, and persisting it would freeze a copy of the enabled set.
|
|
75
|
+
*/
|
|
43
76
|
enabledPacks?: () => readonly string[];
|
|
44
|
-
systemInstruction: string;
|
|
45
77
|
maxHistoryMessages?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Index into {@link history} below which the rolling window may trim, and at or
|
|
80
|
+
* above which it may not. Protects a task that must survive intact from an agent
|
|
81
|
+
* whose window is deliberately short.
|
|
82
|
+
*
|
|
83
|
+
* **Deliberately not in `AgentConfig` and never saved.** `maxHistoryMessages` is
|
|
84
|
+
* operator configuration; this is transient state about the task in flight, and
|
|
85
|
+
* persisting it would leave an agent looking as though its window had been
|
|
86
|
+
* changed by hand. A restart clears it, costing at most the protection on one
|
|
87
|
+
* task in progress.
|
|
88
|
+
*
|
|
89
|
+
* It also needs no clearing. Re-pinning ends the previous pin, so an abandoned
|
|
90
|
+
* task is reclaimed the next time one starts, and the worst a stale pin can do is
|
|
91
|
+
* keep more history than intended — never drop any.
|
|
92
|
+
*/
|
|
46
93
|
historyPin?: number;
|
|
47
94
|
modelName: string;
|
|
48
95
|
smallModelName?: string;
|
|
@@ -55,37 +102,178 @@ export declare class Agent {
|
|
|
55
102
|
isControlledByHuman: boolean;
|
|
56
103
|
beginInstruction: string;
|
|
57
104
|
toolNames: string[];
|
|
105
|
+
/**
|
|
106
|
+
* This agent intends to send MODERATE messages, so its room needs a moderator
|
|
107
|
+
* to route them.
|
|
108
|
+
*
|
|
109
|
+
* For a human-controlled agent it is also what removes the action and target
|
|
110
|
+
* pickers from the room's composer: the player types, the room forces the
|
|
111
|
+
* message to MODERATE, and the moderator decides who hears it and who answers.
|
|
112
|
+
*
|
|
113
|
+
* For an AI agent it is a declaration, not a coercion. An agent emits MODERATE
|
|
114
|
+
* by its own choice — either its perceive schema offers `moderate` as a way to
|
|
115
|
+
* defer the routing decision, or it has no schema at all and answers in prose,
|
|
116
|
+
* which Room.parseAgentResponse converts. An agent that names its own targets
|
|
117
|
+
* keeps doing so.
|
|
118
|
+
*/
|
|
58
119
|
useModerator: boolean;
|
|
59
120
|
promptCacheTTL: number;
|
|
60
121
|
private onStateChange;
|
|
61
122
|
storageDir: string;
|
|
62
123
|
private agentStoreService;
|
|
63
|
-
|
|
124
|
+
/**
|
|
125
|
+
* @internal Agents are constructed by the framework (AgentStoreService /
|
|
126
|
+
* BaseAiService.createAgent); SDK consumers should obtain them via
|
|
127
|
+
* {@link Briyah} rather than calling this directly.
|
|
128
|
+
*/
|
|
129
|
+
constructor(id: string | null, userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, history: any[], modelName: string, serviceName: string, aiService: BaseAiService, reasoningEffort: 'low' | 'medium' | 'high' | null, allowSearch: boolean, maxOutputTokens: number, beginInstruction: string, storageDir: string);
|
|
64
130
|
attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
|
|
131
|
+
/**
|
|
132
|
+
* Attaches an artifact to the agent
|
|
133
|
+
* @param artifactId The artifact ID
|
|
134
|
+
*/
|
|
65
135
|
attachArtifact(artifactId: string): void;
|
|
136
|
+
/**
|
|
137
|
+
* Detaches an artifact from the agent
|
|
138
|
+
* @param artifactId The artifact ID
|
|
139
|
+
*/
|
|
66
140
|
detachArtifact(artifactId: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Gets all attached artifact IDs
|
|
143
|
+
* @returns Array of artifact IDs
|
|
144
|
+
*/
|
|
67
145
|
getAttachedArtifacts(): string[];
|
|
146
|
+
/**
|
|
147
|
+
* Saves the agent to disk via AgentStoreService
|
|
148
|
+
* Called automatically after conversation history changes
|
|
149
|
+
*/
|
|
68
150
|
save(): void;
|
|
69
151
|
finishAgent(): Promise<void>;
|
|
70
152
|
deleteAgent(): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Sets the callback to be called when agent state changes
|
|
155
|
+
* Used for SSE updates to push changes to connected clients
|
|
156
|
+
* @param callback Function to call when state changes
|
|
157
|
+
*/
|
|
71
158
|
setOnStateChange(callback: () => void): void;
|
|
159
|
+
/**
|
|
160
|
+
* Notifies listeners that the agent state has changed
|
|
161
|
+
* Triggers SSE updates if callback is registered
|
|
162
|
+
*/
|
|
72
163
|
notifyStateChange(): void;
|
|
73
164
|
canRespond(message: Message): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Gets formatted messages from the agent's history starting from a specific index
|
|
167
|
+
* @param fromIndex The index to start from (0-based)
|
|
168
|
+
* @returns Array of formatted messages
|
|
169
|
+
*/
|
|
74
170
|
getFormattedMessages(fromIndex?: number): string[];
|
|
171
|
+
/**
|
|
172
|
+
* Gets the raw (unformatted) content of every message in the agent's history.
|
|
173
|
+
* @returns Array of message content strings
|
|
174
|
+
*/
|
|
75
175
|
getRawMessages(): string[];
|
|
176
|
+
/**
|
|
177
|
+
* Message fields that are dropped when a message is written into history.
|
|
178
|
+
*
|
|
179
|
+
* History sits in the cached prompt prefix of every agent that holds it, so each
|
|
180
|
+
* of these is paid for on every turn until the message falls out of the window:
|
|
181
|
+
*
|
|
182
|
+
* - `timestamp` — a wall-clock instant. No prompt in the repository reads one, and
|
|
183
|
+
* ordering is already carried by the position in the array.
|
|
184
|
+
* - `index` — the message's position in the room log, which is a storage detail.
|
|
185
|
+
* - `situation` — *current* state, not history. Every agent is handed the live
|
|
186
|
+
* situation in its transient prompt on every turn (`Room.buildTransientPrompt`),
|
|
187
|
+
* so the copies stored here are superseded by definition and, being the longest
|
|
188
|
+
* field on a room leader's messages, the most expensive thing in the window.
|
|
189
|
+
*/
|
|
76
190
|
private static readonly HISTORY_OMITTED_FIELDS;
|
|
191
|
+
/**
|
|
192
|
+
* Renders a room message as the compact JSON that goes into conversation history.
|
|
193
|
+
*
|
|
194
|
+
* Compact rather than indented, and without the fields above or any field that is
|
|
195
|
+
* empty: an absent `name` and an empty `name` say the same thing to a model, and
|
|
196
|
+
* only one of them costs tokens in every cached prefix that carries the message.
|
|
197
|
+
*
|
|
198
|
+
* @param message The room message to render
|
|
199
|
+
* @returns The message as a single-line JSON string
|
|
200
|
+
*/
|
|
77
201
|
private static formatMessageForHistory;
|
|
78
202
|
addToConversationHistory(message: any, fromSelf?: boolean): void;
|
|
203
|
+
/**
|
|
204
|
+
* Marks the current end of history as the start of a task the rolling window
|
|
205
|
+
* must not trim into.
|
|
206
|
+
*
|
|
207
|
+
* A no-op for an agent with no window: there is nothing to protect it from, and
|
|
208
|
+
* a pin on an agent that keeps everything would only be a field to explain. That
|
|
209
|
+
* is what makes it safe to call from a shared path — the Dungeon Master running
|
|
210
|
+
* its own fight keeps its whole campaign either way.
|
|
211
|
+
*
|
|
212
|
+
* Call it *before* the message that starts the task is added to history, so the
|
|
213
|
+
* task's own opening instruction is inside the pin rather than the first thing
|
|
214
|
+
* dropped.
|
|
215
|
+
*/
|
|
79
216
|
pinHistory(): void;
|
|
217
|
+
/** How many trailing messages the pin protects from trimming. */
|
|
80
218
|
private pinnedMessageCount;
|
|
219
|
+
/**
|
|
220
|
+
* Trims conversation history to keep only the last N messages if maxHistoryMessages is set
|
|
221
|
+
* Preserves system messages (role: 'developer') at the start of history
|
|
222
|
+
* Used for rolling window history management (e.g., moderator agents)
|
|
223
|
+
*
|
|
224
|
+
* A {@link historyPin} raises the floor: everything since the pin is kept even
|
|
225
|
+
* when that is more than the window allows. The window still applies to whatever
|
|
226
|
+
* came before it, so a specialist handed a second task drops the first.
|
|
227
|
+
* @param threshold Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once
|
|
228
|
+
*/
|
|
81
229
|
trimHistoryIfNeeded(threshold?: number): void;
|
|
230
|
+
/**
|
|
231
|
+
* Whether `<name>.prompt` resolves for this agent, so a caller can tell an agent
|
|
232
|
+
* that can run a kind of turn from one whose prompt folder has no prompt for it.
|
|
233
|
+
*
|
|
234
|
+
* False when the agent has no AI service or no paths yet — the answer to "could
|
|
235
|
+
* this agent run that turn" is then no, which is what a caller wants to hear.
|
|
236
|
+
*/
|
|
82
237
|
hasPrompt(name: string): boolean;
|
|
83
238
|
instructedPrompt(prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
|
|
84
239
|
preparedPrompt(promptFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean): Promise<any>;
|
|
85
240
|
withSmallModel<T>(fn: () => Promise<T>): Promise<T>;
|
|
241
|
+
/**
|
|
242
|
+
* How large a history may grow, in characters, before it is worth compacting.
|
|
243
|
+
*
|
|
244
|
+
* Read per call rather than cached so an operator can retune a long-running
|
|
245
|
+
* server without restarting it. Characters rather than tokens because it is the
|
|
246
|
+
* one measure available without asking a tokenizer, and the threshold only has
|
|
247
|
+
* to be roughly right — four characters to a token is close enough to make
|
|
248
|
+
* 100,000 mean "about 25k tokens".
|
|
249
|
+
*
|
|
250
|
+
* @returns The threshold in characters
|
|
251
|
+
*/
|
|
86
252
|
static compactionThresholdChars(): number;
|
|
253
|
+
/**
|
|
254
|
+
* The size of this agent's conversation history in characters.
|
|
255
|
+
* @returns Total characters across every message in history
|
|
256
|
+
*/
|
|
87
257
|
historyChars(): number;
|
|
258
|
+
/**
|
|
259
|
+
* Whether this agent's history has grown past the compaction threshold.
|
|
260
|
+
*
|
|
261
|
+
* An agent with `maxHistoryMessages` is excluded: a rolling window already
|
|
262
|
+
* bounds it, and the two mechanisms answer different needs. A window is for an
|
|
263
|
+
* agent whose old turns stop mattering — a moderator routing the next message
|
|
264
|
+
* does not need last hour's. Compaction is for one whose past must survive in
|
|
265
|
+
* some form, which is why it costs a model call to write a summary rather than
|
|
266
|
+
* dropping messages off the front.
|
|
267
|
+
*
|
|
268
|
+
* @returns True when compaction is worth a call
|
|
269
|
+
*/
|
|
88
270
|
needsCompaction(): boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Replace this agent's conversation history with a single summary message.
|
|
273
|
+
* Uses the `compact_agent` prompt, resolved via the standard lookup order:
|
|
274
|
+
* user/<promptFolder> → user/root → common/<promptFolder> → common/root.
|
|
275
|
+
* On failure, the original history is restored.
|
|
276
|
+
*/
|
|
89
277
|
compact(): Promise<{
|
|
90
278
|
success: boolean;
|
|
91
279
|
originalLength: number;
|
|
@@ -96,6 +284,13 @@ export declare class Agent {
|
|
|
96
284
|
summary?: string;
|
|
97
285
|
}>;
|
|
98
286
|
textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
|
|
287
|
+
/**
|
|
288
|
+
* Generates an image from a text prompt.
|
|
289
|
+
* @param prompt Text description of the image
|
|
290
|
+
* @param imageProperties Optional provider-specific image options
|
|
291
|
+
* (e.g. `width`, `height`, `quality`) passed through to the underlying AI service
|
|
292
|
+
* @returns Promise resolving to `{ artifactId }` on success or `{ error }` on failure
|
|
293
|
+
*/
|
|
99
294
|
generateImage(prompt: string, imageProperties?: Record<string, any>): Promise<{
|
|
100
295
|
artifactId?: string;
|
|
101
296
|
error?: any;
|
|
@@ -9,8 +9,14 @@ class Agent {
|
|
|
9
9
|
agentName;
|
|
10
10
|
agentNickname;
|
|
11
11
|
history;
|
|
12
|
-
fullContextFiles = true;
|
|
12
|
+
fullContextFiles = true; // If true, include the complete contents of files in the prompt context, otherwise files will be searched in a vector store
|
|
13
|
+
/**
|
|
14
|
+
* Generates a nickname from an agent name by taking the first word
|
|
15
|
+
* @param agentName The full agent name
|
|
16
|
+
* @returns The first word as nickname, or the full name if empty
|
|
17
|
+
*/
|
|
13
18
|
static generateNickname(agentName) {
|
|
19
|
+
// Take first word of agent name as nickname
|
|
14
20
|
const firstName = agentName.trim().split(/\s+/)[0];
|
|
15
21
|
return firstName || agentName;
|
|
16
22
|
}
|
|
@@ -19,51 +25,118 @@ class Agent {
|
|
|
19
25
|
totalOutputTokens = 0;
|
|
20
26
|
totalCost = 0;
|
|
21
27
|
totalMarkup = 0;
|
|
22
|
-
markupRate = 2;
|
|
23
|
-
disableMarkup = false;
|
|
24
|
-
disableBalanceCheck = false;
|
|
28
|
+
markupRate = 2; // Default markup rate multiplier
|
|
29
|
+
disableMarkup = false; // When true, markup is always 0 regardless of markupRate
|
|
30
|
+
disableBalanceCheck = false; // When true, skip balance check but still decrement
|
|
25
31
|
isPublished = false;
|
|
26
32
|
templateAgentId;
|
|
27
|
-
ownerRoomId;
|
|
33
|
+
ownerRoomId; // The room this agent belongs to; it is hidden from the agent list and deleted with the room
|
|
34
|
+
/** The pack this agent is filed under. See {@link AgentConfig.pack}. */
|
|
28
35
|
pack;
|
|
36
|
+
/** The pack template's key, when this agent came from one. */
|
|
29
37
|
packAgentKey;
|
|
38
|
+
// AI Service-specific data
|
|
30
39
|
openai;
|
|
31
40
|
assistant;
|
|
32
41
|
vectorStore;
|
|
42
|
+
// Service references (framework plumbing — hidden from SDK docs)
|
|
43
|
+
/** @internal Direct reference to the AI service */
|
|
33
44
|
aiService;
|
|
45
|
+
/** @internal Reference to ArtifactService for retrieving artifact content */
|
|
34
46
|
artifactService;
|
|
47
|
+
/** @internal Reference to user-specific filesystem paths */
|
|
35
48
|
userPaths;
|
|
49
|
+
/** @internal Reference to environment-variable configuration */
|
|
36
50
|
configService;
|
|
51
|
+
/** @internal Reference to balance service for cost tracking and limits */
|
|
37
52
|
balanceService;
|
|
53
|
+
// Clonable configuration properties
|
|
38
54
|
description;
|
|
55
|
+
/**
|
|
56
|
+
* Private, agent-specific context that is visible only to this agent — never to
|
|
57
|
+
* other agents. Injected into the agent's transient (uncached) prompt message
|
|
58
|
+
* rather than the cached system instructions, so it can change frequently without
|
|
59
|
+
* invalidating the prompt cache. In stories this holds the character's inventory
|
|
60
|
+
* and conditions; contrast with {@link description}, which is the public
|
|
61
|
+
* appearance every other agent can see.
|
|
62
|
+
*/
|
|
39
63
|
privateContext = '';
|
|
40
64
|
promptFolder;
|
|
65
|
+
/**
|
|
66
|
+
* The packs the owning user has enabled, consulted only when
|
|
67
|
+
* {@link promptFolder} is a bare name — a pack-qualified one always resolves.
|
|
68
|
+
*
|
|
69
|
+
* A thunk rather than an array because an agent outlives a toggle: the user
|
|
70
|
+
* can enable a pack while this instance is cached, and a snapshot taken at
|
|
71
|
+
* construction would need invalidating across every cached agent, room and
|
|
72
|
+
* service. Reading through the thunk means there is nothing to invalidate.
|
|
73
|
+
*
|
|
74
|
+
* Absent means "scan no packs", which is exactly the behaviour from before
|
|
75
|
+
* packs existed. Deliberately not in `AgentConfig` — it belongs to the user,
|
|
76
|
+
* not the agent, and persisting it would freeze a copy of the enabled set.
|
|
77
|
+
*/
|
|
41
78
|
enabledPacks;
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
maxHistoryMessages; // If set, keep only last N messages (rolling window)
|
|
80
|
+
/**
|
|
81
|
+
* Index into {@link history} below which the rolling window may trim, and at or
|
|
82
|
+
* above which it may not. Protects a task that must survive intact from an agent
|
|
83
|
+
* whose window is deliberately short.
|
|
84
|
+
*
|
|
85
|
+
* **Deliberately not in `AgentConfig` and never saved.** `maxHistoryMessages` is
|
|
86
|
+
* operator configuration; this is transient state about the task in flight, and
|
|
87
|
+
* persisting it would leave an agent looking as though its window had been
|
|
88
|
+
* changed by hand. A restart clears it, costing at most the protection on one
|
|
89
|
+
* task in progress.
|
|
90
|
+
*
|
|
91
|
+
* It also needs no clearing. Re-pinning ends the previous pin, so an abandoned
|
|
92
|
+
* task is reclaimed the next time one starts, and the worst a stale pin can do is
|
|
93
|
+
* keep more history than intended — never drop any.
|
|
94
|
+
*/
|
|
44
95
|
historyPin;
|
|
45
96
|
modelName;
|
|
46
|
-
smallModelName;
|
|
97
|
+
smallModelName; // Same-service smaller model used by withSmallModel for mechanical prompts
|
|
47
98
|
serviceName;
|
|
48
99
|
reasoningEffort;
|
|
49
100
|
allowSearch;
|
|
50
101
|
maxOutputTokens = 0;
|
|
51
102
|
attachedFiles = [];
|
|
52
|
-
attachedArtifacts = [];
|
|
103
|
+
attachedArtifacts = []; // Array of artifact IDs
|
|
53
104
|
isControlledByHuman = false;
|
|
54
105
|
beginInstruction = '';
|
|
55
|
-
toolNames = [];
|
|
106
|
+
toolNames = []; // Names of user-defined tools this agent may EXECUTE
|
|
107
|
+
/**
|
|
108
|
+
* This agent intends to send MODERATE messages, so its room needs a moderator
|
|
109
|
+
* to route them.
|
|
110
|
+
*
|
|
111
|
+
* For a human-controlled agent it is also what removes the action and target
|
|
112
|
+
* pickers from the room's composer: the player types, the room forces the
|
|
113
|
+
* message to MODERATE, and the moderator decides who hears it and who answers.
|
|
114
|
+
*
|
|
115
|
+
* For an AI agent it is a declaration, not a coercion. An agent emits MODERATE
|
|
116
|
+
* by its own choice — either its perceive schema offers `moderate` as a way to
|
|
117
|
+
* defer the routing decision, or it has no schema at all and answers in prose,
|
|
118
|
+
* which Room.parseAgentResponse converts. An agent that names its own targets
|
|
119
|
+
* keeps doing so.
|
|
120
|
+
*/
|
|
56
121
|
useModerator = false;
|
|
57
|
-
|
|
122
|
+
// Cache keep-alive settings (Anthropic only)
|
|
123
|
+
promptCacheTTL = 0; // The number of minutes to keep the prompt cache
|
|
124
|
+
// State change callback for SSE updates
|
|
58
125
|
onStateChange = null;
|
|
126
|
+
// Persistence
|
|
59
127
|
storageDir;
|
|
60
|
-
agentStoreService;
|
|
61
|
-
|
|
128
|
+
agentStoreService; // Reference to AgentStoreService for self-persistence
|
|
129
|
+
/**
|
|
130
|
+
* @internal Agents are constructed by the framework (AgentStoreService /
|
|
131
|
+
* BaseAiService.createAgent); SDK consumers should obtain them via
|
|
132
|
+
* {@link Briyah} rather than calling this directly.
|
|
133
|
+
*/
|
|
134
|
+
constructor(id, userPaths, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
|
|
62
135
|
this.agentName = agentName;
|
|
136
|
+
// Auto-generate nickname if not provided
|
|
63
137
|
this.agentNickname = agentNickname || Agent.generateNickname(agentName);
|
|
64
138
|
this.description = description;
|
|
65
139
|
this.promptFolder = promptFolder;
|
|
66
|
-
this.systemInstruction = systemInstruction;
|
|
67
140
|
this.history = history;
|
|
68
141
|
this.openai = null;
|
|
69
142
|
this.assistant = null;
|
|
@@ -95,17 +168,33 @@ class Agent {
|
|
|
95
168
|
async attachDocument(fileName, fileData) {
|
|
96
169
|
return await this.aiService.attachDocument(this, fileName, fileData);
|
|
97
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Attaches an artifact to the agent
|
|
173
|
+
* @param artifactId The artifact ID
|
|
174
|
+
*/
|
|
98
175
|
attachArtifact(artifactId) {
|
|
99
176
|
if (!this.attachedArtifacts.includes(artifactId)) {
|
|
100
177
|
this.attachedArtifacts.push(artifactId);
|
|
101
178
|
}
|
|
102
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Detaches an artifact from the agent
|
|
182
|
+
* @param artifactId The artifact ID
|
|
183
|
+
*/
|
|
103
184
|
detachArtifact(artifactId) {
|
|
104
185
|
this.attachedArtifacts = this.attachedArtifacts.filter((id) => id !== artifactId);
|
|
105
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Gets all attached artifact IDs
|
|
189
|
+
* @returns Array of artifact IDs
|
|
190
|
+
*/
|
|
106
191
|
getAttachedArtifacts() {
|
|
107
192
|
return [...this.attachedArtifacts];
|
|
108
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Saves the agent to disk via AgentStoreService
|
|
196
|
+
* Called automatically after conversation history changes
|
|
197
|
+
*/
|
|
109
198
|
save() {
|
|
110
199
|
this.agentStoreService.storeAgent(this);
|
|
111
200
|
this.notifyStateChange();
|
|
@@ -116,9 +205,18 @@ class Agent {
|
|
|
116
205
|
async deleteAgent() {
|
|
117
206
|
this.agentStoreService.removeAgent(this.id);
|
|
118
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Sets the callback to be called when agent state changes
|
|
210
|
+
* Used for SSE updates to push changes to connected clients
|
|
211
|
+
* @param callback Function to call when state changes
|
|
212
|
+
*/
|
|
119
213
|
setOnStateChange(callback) {
|
|
120
214
|
this.onStateChange = callback;
|
|
121
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Notifies listeners that the agent state has changed
|
|
218
|
+
* Triggers SSE updates if callback is registered
|
|
219
|
+
*/
|
|
122
220
|
notifyStateChange() {
|
|
123
221
|
if (this.onStateChange) {
|
|
124
222
|
this.onStateChange();
|
|
@@ -129,6 +227,11 @@ class Agent {
|
|
|
129
227
|
return true;
|
|
130
228
|
return message.targets.includes(this.agentNickname);
|
|
131
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Gets formatted messages from the agent's history starting from a specific index
|
|
232
|
+
* @param fromIndex The index to start from (0-based)
|
|
233
|
+
* @returns Array of formatted messages
|
|
234
|
+
*/
|
|
132
235
|
getFormattedMessages(fromIndex = 0) {
|
|
133
236
|
if (!this.history) {
|
|
134
237
|
return [];
|
|
@@ -137,13 +240,41 @@ class Agent {
|
|
|
137
240
|
.slice(fromIndex)
|
|
138
241
|
.map((message) => this.aiService.formatMessage(message));
|
|
139
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Gets the raw (unformatted) content of every message in the agent's history.
|
|
245
|
+
* @returns Array of message content strings
|
|
246
|
+
*/
|
|
140
247
|
getRawMessages() {
|
|
141
248
|
if (!this.history) {
|
|
142
249
|
return [];
|
|
143
250
|
}
|
|
144
251
|
return this.history.map((message) => message.content);
|
|
145
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Message fields that are dropped when a message is written into history.
|
|
255
|
+
*
|
|
256
|
+
* History sits in the cached prompt prefix of every agent that holds it, so each
|
|
257
|
+
* of these is paid for on every turn until the message falls out of the window:
|
|
258
|
+
*
|
|
259
|
+
* - `timestamp` — a wall-clock instant. No prompt in the repository reads one, and
|
|
260
|
+
* ordering is already carried by the position in the array.
|
|
261
|
+
* - `index` — the message's position in the room log, which is a storage detail.
|
|
262
|
+
* - `situation` — *current* state, not history. Every agent is handed the live
|
|
263
|
+
* situation in its transient prompt on every turn (`Room.buildTransientPrompt`),
|
|
264
|
+
* so the copies stored here are superseded by definition and, being the longest
|
|
265
|
+
* field on a room leader's messages, the most expensive thing in the window.
|
|
266
|
+
*/
|
|
146
267
|
static HISTORY_OMITTED_FIELDS = ['timestamp', 'index', 'situation'];
|
|
268
|
+
/**
|
|
269
|
+
* Renders a room message as the compact JSON that goes into conversation history.
|
|
270
|
+
*
|
|
271
|
+
* Compact rather than indented, and without the fields above or any field that is
|
|
272
|
+
* empty: an absent `name` and an empty `name` say the same thing to a model, and
|
|
273
|
+
* only one of them costs tokens in every cached prefix that carries the message.
|
|
274
|
+
*
|
|
275
|
+
* @param message The room message to render
|
|
276
|
+
* @returns The message as a single-line JSON string
|
|
277
|
+
*/
|
|
147
278
|
static formatMessageForHistory(message) {
|
|
148
279
|
const compact = {};
|
|
149
280
|
for (const [field, value] of Object.entries(message)) {
|
|
@@ -169,23 +300,53 @@ class Agent {
|
|
|
169
300
|
}
|
|
170
301
|
this.aiService.addToConversationHistory(this, formattedMessage, fromSelf);
|
|
171
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Marks the current end of history as the start of a task the rolling window
|
|
305
|
+
* must not trim into.
|
|
306
|
+
*
|
|
307
|
+
* A no-op for an agent with no window: there is nothing to protect it from, and
|
|
308
|
+
* a pin on an agent that keeps everything would only be a field to explain. That
|
|
309
|
+
* is what makes it safe to call from a shared path — the Dungeon Master running
|
|
310
|
+
* its own fight keeps its whole campaign either way.
|
|
311
|
+
*
|
|
312
|
+
* Call it *before* the message that starts the task is added to history, so the
|
|
313
|
+
* task's own opening instruction is inside the pin rather than the first thing
|
|
314
|
+
* dropped.
|
|
315
|
+
*/
|
|
172
316
|
pinHistory() {
|
|
173
317
|
if (!this.maxHistoryMessages)
|
|
174
318
|
return;
|
|
175
319
|
this.historyPin = this.history.length;
|
|
176
320
|
}
|
|
321
|
+
/** How many trailing messages the pin protects from trimming. */
|
|
177
322
|
pinnedMessageCount() {
|
|
178
323
|
if (this.historyPin === undefined)
|
|
179
324
|
return 0;
|
|
180
325
|
if (this.historyPin > this.history.length) {
|
|
326
|
+
// The history was replaced wholesale under the pin — compaction, or a
|
|
327
|
+
// restore — so it points at a message that no longer exists. Drop it.
|
|
328
|
+
// Clamping to zero instead would look right until history grew back
|
|
329
|
+
// past the old index, at which point a dead pin would silently start
|
|
330
|
+
// widening the window again.
|
|
181
331
|
this.historyPin = undefined;
|
|
182
332
|
return 0;
|
|
183
333
|
}
|
|
184
334
|
return this.history.length - this.historyPin;
|
|
185
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Trims conversation history to keep only the last N messages if maxHistoryMessages is set
|
|
338
|
+
* Preserves system messages (role: 'developer') at the start of history
|
|
339
|
+
* Used for rolling window history management (e.g., moderator agents)
|
|
340
|
+
*
|
|
341
|
+
* A {@link historyPin} raises the floor: everything since the pin is kept even
|
|
342
|
+
* when that is more than the window allows. The window still applies to whatever
|
|
343
|
+
* came before it, so a specialist handed a second task drops the first.
|
|
344
|
+
* @param threshold Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once
|
|
345
|
+
*/
|
|
186
346
|
trimHistoryIfNeeded(threshold = 0) {
|
|
187
347
|
if (!this.maxHistoryMessages)
|
|
188
348
|
return;
|
|
349
|
+
// Count system messages at start (role: 'developer')
|
|
189
350
|
let systemMessageCount = 0;
|
|
190
351
|
for (let i = 0; i < this.history.length; i++) {
|
|
191
352
|
if (this.history[i].role === 'developer') {
|
|
@@ -198,17 +359,27 @@ class Agent {
|
|
|
198
359
|
break;
|
|
199
360
|
}
|
|
200
361
|
}
|
|
362
|
+
// Keep system messages + last N conversation messages, or everything since
|
|
363
|
+
// the pin when the task in flight is longer than the window.
|
|
201
364
|
const keep = Math.max(this.maxHistoryMessages, this.pinnedMessageCount());
|
|
202
365
|
const conversationMessages = this.history.slice(systemMessageCount);
|
|
203
366
|
if (conversationMessages.length > keep + threshold) {
|
|
204
367
|
const keepMessages = conversationMessages.slice(-keep);
|
|
205
368
|
const removed = conversationMessages.length - keepMessages.length;
|
|
206
369
|
this.history = [...this.history.slice(0, systemMessageCount), ...keepMessages];
|
|
370
|
+
// The pin is an index, and the messages under it just moved.
|
|
207
371
|
if (this.historyPin !== undefined) {
|
|
208
372
|
this.historyPin = Math.max(systemMessageCount, this.historyPin - removed);
|
|
209
373
|
}
|
|
210
374
|
}
|
|
211
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Whether `<name>.prompt` resolves for this agent, so a caller can tell an agent
|
|
378
|
+
* that can run a kind of turn from one whose prompt folder has no prompt for it.
|
|
379
|
+
*
|
|
380
|
+
* False when the agent has no AI service or no paths yet — the answer to "could
|
|
381
|
+
* this agent run that turn" is then no, which is what a caller wants to hear.
|
|
382
|
+
*/
|
|
212
383
|
hasPrompt(name) {
|
|
213
384
|
if (!this.aiService || !this.userPaths)
|
|
214
385
|
return false;
|
|
@@ -233,17 +404,50 @@ class Agent {
|
|
|
233
404
|
this.modelName = original;
|
|
234
405
|
}
|
|
235
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* How large a history may grow, in characters, before it is worth compacting.
|
|
409
|
+
*
|
|
410
|
+
* Read per call rather than cached so an operator can retune a long-running
|
|
411
|
+
* server without restarting it. Characters rather than tokens because it is the
|
|
412
|
+
* one measure available without asking a tokenizer, and the threshold only has
|
|
413
|
+
* to be roughly right — four characters to a token is close enough to make
|
|
414
|
+
* 100,000 mean "about 25k tokens".
|
|
415
|
+
*
|
|
416
|
+
* @returns The threshold in characters
|
|
417
|
+
*/
|
|
236
418
|
static compactionThresholdChars() {
|
|
237
419
|
return Number(process.env.AGENT_COMPACTION_THRESHOLD) || 100000;
|
|
238
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* The size of this agent's conversation history in characters.
|
|
423
|
+
* @returns Total characters across every message in history
|
|
424
|
+
*/
|
|
239
425
|
historyChars() {
|
|
240
426
|
return (this.history ?? []).reduce((sum, m) => sum + (m?.content?.length || 0), 0);
|
|
241
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Whether this agent's history has grown past the compaction threshold.
|
|
430
|
+
*
|
|
431
|
+
* An agent with `maxHistoryMessages` is excluded: a rolling window already
|
|
432
|
+
* bounds it, and the two mechanisms answer different needs. A window is for an
|
|
433
|
+
* agent whose old turns stop mattering — a moderator routing the next message
|
|
434
|
+
* does not need last hour's. Compaction is for one whose past must survive in
|
|
435
|
+
* some form, which is why it costs a model call to write a summary rather than
|
|
436
|
+
* dropping messages off the front.
|
|
437
|
+
*
|
|
438
|
+
* @returns True when compaction is worth a call
|
|
439
|
+
*/
|
|
242
440
|
needsCompaction() {
|
|
243
441
|
if (this.maxHistoryMessages)
|
|
244
442
|
return false;
|
|
245
443
|
return this.historyChars() > Agent.compactionThresholdChars();
|
|
246
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Replace this agent's conversation history with a single summary message.
|
|
447
|
+
* Uses the `compact_agent` prompt, resolved via the standard lookup order:
|
|
448
|
+
* user/<promptFolder> → user/root → common/<promptFolder> → common/root.
|
|
449
|
+
* On failure, the original history is restored.
|
|
450
|
+
*/
|
|
247
451
|
async compact() {
|
|
248
452
|
const originalHistory = [...(this.history || [])];
|
|
249
453
|
const originalLength = originalHistory.length;
|
|
@@ -286,6 +490,13 @@ class Agent {
|
|
|
286
490
|
async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
|
|
287
491
|
return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
|
|
288
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Generates an image from a text prompt.
|
|
495
|
+
* @param prompt Text description of the image
|
|
496
|
+
* @param imageProperties Optional provider-specific image options
|
|
497
|
+
* (e.g. `width`, `height`, `quality`) passed through to the underlying AI service
|
|
498
|
+
* @returns Promise resolving to `{ artifactId }` on success or `{ error }` on failure
|
|
499
|
+
*/
|
|
289
500
|
async generateImage(prompt, imageProperties) {
|
|
290
501
|
return await this.aiService.generateImage(this, prompt, imageProperties);
|
|
291
502
|
}
|