briyah 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -7
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
- package/dist-sdk/server/src/ai/agent.d.ts +196 -0
- package/dist-sdk/server/src/ai/agent.js +224 -11
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +38 -1
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +87 -0
- package/dist-sdk/server/src/app.controller.js +272 -12
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1661 -0
- package/dist-sdk/server/src/app.service.js +1837 -4
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +26 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
- package/dist-sdk/server/src/room/room-factory.js +14 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +176 -0
- package/dist-sdk/server/src/room/room-store.service.js +238 -5
- package/dist-sdk/server/src/room/room.d.ts +878 -0
- package/dist-sdk/server/src/room/room.js +1291 -23
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +103 -0
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +398 -0
- package/dist-sdk/server/src/story/story.service.js +829 -25
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +22 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +176 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +116 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
- package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +285 -13
- package/dist-sdk/shared/types/app.types.js +3 -0
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -54,6 +54,12 @@ const user_paths_service_1 = require("../config/user-paths.service");
|
|
|
54
54
|
const attached_file_service_1 = require("./attached-file.service");
|
|
55
55
|
const balance_service_1 = require("../app/balance.service");
|
|
56
56
|
const logger_1 = require("../common/logger");
|
|
57
|
+
/**
|
|
58
|
+
* A service that stores and retrieves Agent objects by ID
|
|
59
|
+
* Each agent is stored in its own JSON file named by its GUID
|
|
60
|
+
* Supports configurable storage directories (e.g., for story-specific agents)
|
|
61
|
+
* Uses lazy loading - agents are loaded from disk on first access
|
|
62
|
+
*/
|
|
57
63
|
let AgentStoreService = class AgentStoreService {
|
|
58
64
|
aiFactoryService;
|
|
59
65
|
userPaths;
|
|
@@ -72,67 +78,124 @@ let AgentStoreService = class AgentStoreService {
|
|
|
72
78
|
this.balanceService = balanceService;
|
|
73
79
|
this.artifactService = artifactService;
|
|
74
80
|
this.configService = configService;
|
|
81
|
+
// Default storage directory for non-story agents
|
|
75
82
|
this.defaultStorageDir = path.join(this.userPaths.getUserDataDir(), 'agents');
|
|
83
|
+
// Agents will be loaded lazily on first access via ensureLoaded()
|
|
76
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets the default storage directory for agents
|
|
87
|
+
* @returns The default storage directory path
|
|
88
|
+
*/
|
|
77
89
|
getDefaultStorageDir() {
|
|
78
90
|
return this.defaultStorageDir;
|
|
79
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Registers an agent in the in-memory store without writing to disk.
|
|
94
|
+
* Use this when creating a new agent that the user hasn't explicitly saved yet.
|
|
95
|
+
* Call agent.save() later to persist it.
|
|
96
|
+
* @param agent The agent to register
|
|
97
|
+
*/
|
|
80
98
|
registerAgent(agent) {
|
|
81
99
|
if (!agent.id) {
|
|
82
100
|
agent.id = (0, crypto_1.randomUUID)();
|
|
83
101
|
}
|
|
84
102
|
this.agents.set(agent.id, agent);
|
|
85
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Stores an agent and returns its unique ID
|
|
106
|
+
* @param agent The agent to store
|
|
107
|
+
* @param storageDir Optional custom storage directory (defaults to server/data/agents)
|
|
108
|
+
* @returns The unique ID for the agent
|
|
109
|
+
*/
|
|
86
110
|
storeAgent(agent, storageDir) {
|
|
111
|
+
// If agent doesn't have an ID, generate one
|
|
87
112
|
if (!agent.id) {
|
|
88
113
|
agent.id = (0, crypto_1.randomUUID)();
|
|
89
114
|
}
|
|
90
115
|
this.agents.set(agent.id, agent);
|
|
116
|
+
// Save the agent to its individual file
|
|
91
117
|
const finalStorageDir = storageDir || agent.storageDir;
|
|
92
118
|
this.saveAgentToFile(agent, finalStorageDir);
|
|
93
119
|
return agent.id;
|
|
94
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves an agent by its ID
|
|
123
|
+
* @param id The agent ID
|
|
124
|
+
* @returns The agent, or undefined if not found
|
|
125
|
+
*/
|
|
95
126
|
async getAgent(id) {
|
|
96
127
|
await this.ensureLoaded();
|
|
97
128
|
return this.agents.get(id);
|
|
98
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Removes an agent from the store and deletes its file
|
|
132
|
+
* @param id The agent ID
|
|
133
|
+
* @returns True if the agent was found and removed, false otherwise
|
|
134
|
+
*/
|
|
99
135
|
removeAgent(id) {
|
|
100
136
|
const agent = this.agents.get(id);
|
|
101
137
|
if (!agent) {
|
|
102
138
|
return false;
|
|
103
139
|
}
|
|
140
|
+
// Call finishAgent on the AI service if available
|
|
104
141
|
if (agent.aiService) {
|
|
105
142
|
try {
|
|
106
143
|
agent.aiService.finishAgent(agent);
|
|
107
144
|
}
|
|
108
145
|
catch (error) {
|
|
109
146
|
logger_1.logger.error(`Error finishing agent ${id}:`, error);
|
|
147
|
+
// Continue with deletion even if finishAgent fails
|
|
110
148
|
}
|
|
111
149
|
}
|
|
112
150
|
this.attachedFileService.deleteAllFiles(agent.id);
|
|
151
|
+
// Remove the agent from the store
|
|
113
152
|
const result = this.agents.delete(id);
|
|
153
|
+
// Delete the agent's file
|
|
114
154
|
if (result) {
|
|
115
155
|
this.deleteAgentFile(id, agent.storageDir);
|
|
116
156
|
}
|
|
117
157
|
return result;
|
|
118
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Gets all agent IDs from the in-memory store
|
|
161
|
+
* @returns Array of agent IDs
|
|
162
|
+
*/
|
|
119
163
|
async getAllAgentIds() {
|
|
120
164
|
await this.ensureLoaded();
|
|
121
165
|
return Array.from(this.agents.keys());
|
|
122
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets the number of agents in the store
|
|
169
|
+
* @returns The number of agents
|
|
170
|
+
*/
|
|
123
171
|
async getAgentCount() {
|
|
124
172
|
await this.ensureLoaded();
|
|
125
173
|
return this.agents.size;
|
|
126
174
|
}
|
|
127
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Clones an agent as a published instance with a new name
|
|
177
|
+
* @param templateId The ID of the template agent to clone
|
|
178
|
+
* @param publishedName The name for the published instance
|
|
179
|
+
* @param userId The user ID (for tracking purposes)
|
|
180
|
+
* @returns The ID of the newly created published instance
|
|
181
|
+
*/
|
|
182
|
+
async cloneAgentAsPublished(templateId, publishedName,
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
184
|
+
_userId) {
|
|
128
185
|
await this.ensureLoaded();
|
|
129
186
|
const template = this.agents.get(templateId);
|
|
130
187
|
if (!template) {
|
|
131
188
|
throw new Error(`Template agent not found: ${templateId}`);
|
|
132
189
|
}
|
|
190
|
+
// Generate new ID for the instance
|
|
133
191
|
const instanceId = (0, crypto_1.randomUUID)();
|
|
192
|
+
// Get the AI service for the new instance
|
|
134
193
|
const aiService = this.aiFactoryService.createAiService(template.serviceName);
|
|
135
|
-
|
|
194
|
+
// Create new agent with copied properties
|
|
195
|
+
const instance = new agent_1.Agent(instanceId, this.userPaths, this.configService, this, this.balanceService, this.artifactService, publishedName, // New name for the instance
|
|
196
|
+
template.agentNickname || template.agentName, template.description, template.promptFolder, template.systemInstruction, [], // Empty history for new instance
|
|
197
|
+
template.modelName, template.serviceName, aiService, template.reasoningEffort, template.allowSearch, template.maxOutputTokens, template.beginInstruction, this.defaultStorageDir);
|
|
198
|
+
// Set instance-specific properties
|
|
136
199
|
instance.templateAgentId = templateId;
|
|
137
200
|
instance.isPublished = true;
|
|
138
201
|
instance.createdAt = new Date();
|
|
@@ -140,6 +203,7 @@ let AgentStoreService = class AgentStoreService {
|
|
|
140
203
|
instance.totalOutputTokens = 0;
|
|
141
204
|
instance.totalCost = 0;
|
|
142
205
|
instance.totalMarkup = 0;
|
|
206
|
+
// Copy attached files and artifacts metadata
|
|
143
207
|
instance.privateContext = template.privateContext;
|
|
144
208
|
instance.attachedFiles = [...template.attachedFiles];
|
|
145
209
|
instance.attachedArtifacts = [...template.attachedArtifacts];
|
|
@@ -149,12 +213,24 @@ let AgentStoreService = class AgentStoreService {
|
|
|
149
213
|
instance.smallModelName = template.smallModelName;
|
|
150
214
|
instance.toolNames = [...template.toolNames];
|
|
151
215
|
instance.useModerator = template.useModerator;
|
|
216
|
+
// The human player must survive publishing: a published room's whole point
|
|
217
|
+
// is that its visitor plays this agent. Without the flag the room has no
|
|
218
|
+
// human, so it never yields the floor and the visitor's messages arrive as
|
|
219
|
+
// 'system' rather than under their character's name.
|
|
152
220
|
instance.isControlledByHuman = template.isControlledByHuman;
|
|
221
|
+
// A published copy of a pack's agent stays filed under that pack, so it is
|
|
222
|
+
// listed and hidden alongside the template it came from.
|
|
153
223
|
instance.pack = template.pack;
|
|
154
224
|
instance.packAgentKey = template.packAgentKey;
|
|
225
|
+
// Store the new instance
|
|
155
226
|
this.storeAgent(instance);
|
|
156
227
|
return instanceId;
|
|
157
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Gets all published instances of a template agent
|
|
231
|
+
* @param templateId The ID of the template agent
|
|
232
|
+
* @returns Array of published instances
|
|
233
|
+
*/
|
|
158
234
|
async getPublishedInstances(templateId) {
|
|
159
235
|
await this.ensureLoaded();
|
|
160
236
|
const instances = [];
|
|
@@ -165,6 +241,13 @@ let AgentStoreService = class AgentStoreService {
|
|
|
165
241
|
}
|
|
166
242
|
return instances;
|
|
167
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Resets a published instance to match its template's current properties
|
|
246
|
+
* Preserves the instance ID, name, creation date and usage totals
|
|
247
|
+
* Clears conversation history
|
|
248
|
+
* @param instanceId The ID of the instance to reset
|
|
249
|
+
* @param templateId The ID of the template agent
|
|
250
|
+
*/
|
|
168
251
|
async resetPublishedInstance(instanceId, templateId) {
|
|
169
252
|
await this.ensureLoaded();
|
|
170
253
|
const instance = this.agents.get(instanceId);
|
|
@@ -175,9 +258,11 @@ let AgentStoreService = class AgentStoreService {
|
|
|
175
258
|
if (!template) {
|
|
176
259
|
throw new Error(`Template agent not found: ${templateId}`);
|
|
177
260
|
}
|
|
261
|
+
// Validate that this instance belongs to this template
|
|
178
262
|
if (instance.templateAgentId !== templateId) {
|
|
179
263
|
throw new Error(`Instance ${instanceId} does not belong to template ${templateId}`);
|
|
180
264
|
}
|
|
265
|
+
// Update properties from template
|
|
181
266
|
instance.description = template.description;
|
|
182
267
|
instance.privateContext = template.privateContext;
|
|
183
268
|
instance.agentNickname = template.agentNickname;
|
|
@@ -197,13 +282,28 @@ let AgentStoreService = class AgentStoreService {
|
|
|
197
282
|
instance.markupRate = template.markupRate;
|
|
198
283
|
instance.toolNames = [...template.toolNames];
|
|
199
284
|
instance.useModerator = template.useModerator;
|
|
285
|
+
// Kept in step with the template for the same reason the clone copies it.
|
|
200
286
|
instance.isControlledByHuman = template.isControlledByHuman;
|
|
201
287
|
instance.pack = template.pack;
|
|
202
288
|
instance.packAgentKey = template.packAgentKey;
|
|
289
|
+
// Clear the conversation, but not what it cost.
|
|
290
|
+
//
|
|
291
|
+
// A reset is about the instance's state, not its accounting: the money was
|
|
292
|
+
// spent and the user was billed for it, so zeroing the totals here made a
|
|
293
|
+
// published agent look free and lost the only record of what it had run up.
|
|
294
|
+
// The counters start at zero on the clone, which is where they belong —
|
|
295
|
+
// that instance really has spent nothing yet.
|
|
203
296
|
instance.history = [];
|
|
297
|
+
// Update AI service reference (in case serviceName changed)
|
|
204
298
|
instance.aiService = this.aiFactoryService.createAiService(instance.serviceName);
|
|
299
|
+
// Save the updated instance
|
|
205
300
|
this.storeAgent(instance);
|
|
206
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Ensures default agents are loaded from disk (lazy loading)
|
|
304
|
+
* Only loads once - subsequent calls are no-op
|
|
305
|
+
* Uses promise memoization to prevent concurrent loads
|
|
306
|
+
*/
|
|
207
307
|
async ensureLoaded() {
|
|
208
308
|
if (this.loaded)
|
|
209
309
|
return;
|
|
@@ -213,14 +313,21 @@ let AgentStoreService = class AgentStoreService {
|
|
|
213
313
|
this.loaded = true;
|
|
214
314
|
})
|
|
215
315
|
.catch((error) => {
|
|
216
|
-
this.loadPromise = null;
|
|
316
|
+
this.loadPromise = null; // Allow retry on error
|
|
217
317
|
throw error;
|
|
218
318
|
});
|
|
219
319
|
}
|
|
220
320
|
await this.loadPromise;
|
|
221
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Loads agents from a specific directory
|
|
324
|
+
* Used for loading story-specific agents
|
|
325
|
+
* @param storageDir The directory to load agents from
|
|
326
|
+
* @param artifactService Optional artifact service (for story-specific artifacts)
|
|
327
|
+
*/
|
|
222
328
|
async loadAgentsFromDirectory(storageDir, artifactService) {
|
|
223
329
|
try {
|
|
330
|
+
// Check if directory exists
|
|
224
331
|
try {
|
|
225
332
|
await fs.promises.access(storageDir);
|
|
226
333
|
}
|
|
@@ -229,64 +336,103 @@ let AgentStoreService = class AgentStoreService {
|
|
|
229
336
|
await fs.promises.mkdir(storageDir, { recursive: true });
|
|
230
337
|
return;
|
|
231
338
|
}
|
|
339
|
+
// Read all .json files from the directory
|
|
232
340
|
const allFiles = await fs.promises.readdir(storageDir);
|
|
233
341
|
const files = allFiles.filter((file) => file.endsWith('.json'));
|
|
234
342
|
logger_1.logger.log(`Loading ${files.length} agents from ${storageDir}`);
|
|
343
|
+
// Load each agent file
|
|
235
344
|
for (const file of files) {
|
|
236
345
|
try {
|
|
237
346
|
const filePath = path.join(storageDir, file);
|
|
238
347
|
const fileContent = await fs.promises.readFile(filePath, 'utf-8');
|
|
239
348
|
const config = JSON.parse(fileContent);
|
|
349
|
+
// Check if agent already exists in store (prevents duplicate loading)
|
|
240
350
|
if (this.agents.has(config.id)) {
|
|
241
351
|
logger_1.logger.log(`Agent ${config.agentName} (${config.id}) already loaded, skipping`);
|
|
242
352
|
continue;
|
|
243
353
|
}
|
|
354
|
+
// Get the AI service for this agent
|
|
244
355
|
const aiService = this.aiFactoryService.createAiService(config.serviceName);
|
|
356
|
+
// Use provided artifact service or fall back to default
|
|
245
357
|
const finalArtifactService = artifactService || this.artifactService;
|
|
246
|
-
|
|
358
|
+
// Create a new agent with the saved configuration, including history
|
|
359
|
+
const agent = new agent_1.Agent(config.id, this.userPaths, this.configService, this, this.balanceService, finalArtifactService, config.agentName, config.agentNickname || config.agentName, config.description, config.promptFolder, config.systemInstruction, config.history || [], // Restore history or use empty array
|
|
360
|
+
config.modelName, config.serviceName, aiService, config.reasoningEffort, config.allowSearch, config.maxOutputTokens, config.beginInstruction || '', storageDir);
|
|
361
|
+
// Restore agent-private context (e.g. story inventory)
|
|
247
362
|
agent.privateContext = config.privateContext || '';
|
|
363
|
+
// Set the creation date
|
|
248
364
|
agent.createdAt = new Date(config.createdAt);
|
|
365
|
+
// Set the user paths service reference
|
|
249
366
|
agent.userPaths = this.userPaths;
|
|
367
|
+
// Restore the optional same-service small model used for mechanical prompts
|
|
250
368
|
agent.smallModelName = config.smallModelName;
|
|
369
|
+
// Restore token counts and cost
|
|
251
370
|
agent.totalInputTokens = config.totalInputTokens || 0;
|
|
252
371
|
agent.totalOutputTokens = config.totalOutputTokens || 0;
|
|
253
372
|
agent.totalCost = config.totalCost || 0;
|
|
254
373
|
agent.totalMarkup = config.totalMarkup || 0;
|
|
374
|
+
// Load markupRate from saved config; if absent, the Agent
|
|
375
|
+
// constructor already applied the DEFAULT_MARKUP_RATE default.
|
|
255
376
|
if (config.markupRate !== undefined) {
|
|
256
377
|
agent.markupRate = config.markupRate;
|
|
257
378
|
}
|
|
379
|
+
// Restore human control flag
|
|
258
380
|
agent.isControlledByHuman = config.isControlledByHuman || false;
|
|
381
|
+
// Restore markup and balance check flags
|
|
259
382
|
agent.disableMarkup = config.disableMarkup || false;
|
|
260
383
|
agent.disableBalanceCheck = config.disableBalanceCheck || false;
|
|
384
|
+
// Restore publication status
|
|
261
385
|
agent.isPublished = config.isPublished || false;
|
|
386
|
+
// Restore template agent ID (for published instances)
|
|
262
387
|
agent.templateAgentId = config.templateAgentId;
|
|
388
|
+
// Restore room ownership (for agents cloned as part of published rooms)
|
|
263
389
|
agent.ownerRoomId = config.ownerRoomId;
|
|
390
|
+
// Restore which pack the agent is filed under
|
|
264
391
|
agent.pack = config.pack;
|
|
265
392
|
agent.packAgentKey = config.packAgentKey;
|
|
393
|
+
// Restore begin instruction
|
|
266
394
|
agent.beginInstruction = config.beginInstruction || '';
|
|
267
395
|
agent.maxHistoryMessages = config.maxHistoryMessages || undefined;
|
|
396
|
+
// Restore cache keep-alive settings
|
|
268
397
|
agent.promptCacheTTL = Number(config.promptCacheTTL) ?? 0;
|
|
398
|
+
// Restore tool grants
|
|
269
399
|
agent.toolNames = config.toolNames || [];
|
|
400
|
+
// Restore the moderated-messaging declaration
|
|
270
401
|
agent.useModerator = config.useModerator || false;
|
|
402
|
+
// Store the agent with its original ID
|
|
271
403
|
agent.id = config.id;
|
|
272
404
|
this.agents.set(config.id, agent);
|
|
405
|
+
// Note: Identity is now handled in textPrompt, not during agent creation
|
|
406
|
+
// Use file metadata from config if available (preserves serviceMetadata)
|
|
407
|
+
// Otherwise fall back to AttachedFileService
|
|
273
408
|
if (config.attachedFiles && config.attachedFiles.length > 0) {
|
|
274
409
|
agent.attachedFiles = config.attachedFiles;
|
|
275
410
|
}
|
|
276
411
|
else {
|
|
412
|
+
// Fallback: Load file metadata from AttachedFileService
|
|
277
413
|
const fileMetadataList = this.attachedFileService.listFileMetadata(agent.id);
|
|
278
414
|
agent.attachedFiles = fileMetadataList;
|
|
279
415
|
}
|
|
416
|
+
// Restore file data to serviceMetadata for agents using fullContextFiles
|
|
417
|
+
// When fullContextFiles is true, files are included directly in prompts
|
|
418
|
+
// When false, files are stored in vector stores (OpenAI) or similar
|
|
280
419
|
for (const metadata of agent.attachedFiles) {
|
|
281
420
|
const fileData = this.attachedFileService.getFile(agent.id, metadata.fileId);
|
|
282
421
|
if (fileData && metadata.serviceMetadata && agent.fullContextFiles) {
|
|
422
|
+
// Restore fileData for agents that include files directly in prompts
|
|
283
423
|
metadata.serviceMetadata.fileData = Array.from(fileData);
|
|
284
424
|
logger_1.logger.log(`Restored fileData for ${metadata.fileName} (fullContextFiles=true)`);
|
|
285
425
|
}
|
|
426
|
+
// If fullContextFiles is false, the service uses remote storage (vector stores, etc.)
|
|
427
|
+
// The resourceId or similar should already be in serviceMetadata from saved config
|
|
286
428
|
}
|
|
429
|
+
// Restore attached artifacts
|
|
287
430
|
if (config.attachedArtifacts && config.attachedArtifacts.length > 0) {
|
|
288
431
|
agent.attachedArtifacts = config.attachedArtifacts;
|
|
289
432
|
}
|
|
433
|
+
// Debug, not log: this fires once per agent in the user's whole
|
|
434
|
+
// library, so a table of nine agents produced fifty-one lines and
|
|
435
|
+
// buried the boot sequence. The count is logged once below.
|
|
290
436
|
logger_1.logger.debug(`Loaded agent: ${config.agentName} (${config.id}) with ${agent.history.length} history items`);
|
|
291
437
|
}
|
|
292
438
|
catch (error) {
|
|
@@ -298,13 +444,23 @@ let AgentStoreService = class AgentStoreService {
|
|
|
298
444
|
logger_1.logger.error(`Error loading agents from directory ${storageDir}:`, error);
|
|
299
445
|
}
|
|
300
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Saves a single agent to its own JSON file
|
|
449
|
+
* @param agent The agent to save
|
|
450
|
+
* @param storageDir The directory to save the agent in
|
|
451
|
+
*/
|
|
301
452
|
saveAgentToFile(agent, storageDir) {
|
|
302
453
|
try {
|
|
454
|
+
// Ensure the directory exists
|
|
303
455
|
if (!fs.existsSync(storageDir)) {
|
|
304
456
|
fs.mkdirSync(storageDir, { recursive: true });
|
|
305
457
|
}
|
|
458
|
+
// Create a copy of attachedFiles without the fileData property
|
|
459
|
+
// (fileData is already stored in the upload folder)
|
|
306
460
|
let attachedFilesWithoutFileData = agent.attachedFiles.map((file) => {
|
|
307
461
|
if (file.serviceMetadata?.fileData) {
|
|
462
|
+
// Create a copy without fileData
|
|
463
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
308
464
|
const { fileData: _fileData, ...serviceMetadataWithoutFileData } = file.serviceMetadata;
|
|
309
465
|
return {
|
|
310
466
|
...file,
|
|
@@ -344,7 +500,7 @@ let AgentStoreService = class AgentStoreService {
|
|
|
344
500
|
templateAgentId: agent.templateAgentId,
|
|
345
501
|
beginInstruction: agent.beginInstruction,
|
|
346
502
|
promptCacheTTL: agent.promptCacheTTL,
|
|
347
|
-
ownerRoomId: agent.ownerRoomId,
|
|
503
|
+
ownerRoomId: agent.ownerRoomId, // NEW: Persist room ownership
|
|
348
504
|
toolNames: agent.toolNames,
|
|
349
505
|
useModerator: agent.useModerator,
|
|
350
506
|
pack: agent.pack,
|
|
@@ -357,6 +513,11 @@ let AgentStoreService = class AgentStoreService {
|
|
|
357
513
|
logger_1.logger.error(`Error saving agent ${agent.id} to file:`, error);
|
|
358
514
|
}
|
|
359
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* Deletes an agent's JSON file
|
|
518
|
+
* @param agentId The agent ID
|
|
519
|
+
* @param storageDir The directory containing the agent file
|
|
520
|
+
*/
|
|
360
521
|
deleteAgentFile(agentId, storageDir) {
|
|
361
522
|
try {
|
|
362
523
|
const filePath = path.join(storageDir, `${agentId}.json`);
|
|
@@ -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,65 @@ 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
77
|
systemInstruction: string;
|
|
45
78
|
maxHistoryMessages?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Index into {@link history} below which the rolling window may trim, and at or
|
|
81
|
+
* above which it may not. Protects a task that must survive intact from an agent
|
|
82
|
+
* whose window is deliberately short.
|
|
83
|
+
*
|
|
84
|
+
* **Deliberately not in `AgentConfig` and never saved.** `maxHistoryMessages` is
|
|
85
|
+
* operator configuration; this is transient state about the task in flight, and
|
|
86
|
+
* persisting it would leave an agent looking as though its window had been
|
|
87
|
+
* changed by hand. A restart clears it, costing at most the protection on one
|
|
88
|
+
* task in progress.
|
|
89
|
+
*
|
|
90
|
+
* It also needs no clearing. Re-pinning ends the previous pin, so an abandoned
|
|
91
|
+
* task is reclaimed the next time one starts, and the worst a stale pin can do is
|
|
92
|
+
* keep more history than intended — never drop any.
|
|
93
|
+
*/
|
|
46
94
|
historyPin?: number;
|
|
47
95
|
modelName: string;
|
|
48
96
|
smallModelName?: string;
|
|
@@ -55,37 +103,178 @@ export declare class Agent {
|
|
|
55
103
|
isControlledByHuman: boolean;
|
|
56
104
|
beginInstruction: string;
|
|
57
105
|
toolNames: string[];
|
|
106
|
+
/**
|
|
107
|
+
* This agent intends to send MODERATE messages, so its room needs a moderator
|
|
108
|
+
* to route them.
|
|
109
|
+
*
|
|
110
|
+
* For a human-controlled agent it is also what removes the action and target
|
|
111
|
+
* pickers from the room's composer: the player types, the room forces the
|
|
112
|
+
* message to MODERATE, and the moderator decides who hears it and who answers.
|
|
113
|
+
*
|
|
114
|
+
* For an AI agent it is a declaration, not a coercion. An agent emits MODERATE
|
|
115
|
+
* by its own choice — either its perceive schema offers `moderate` as a way to
|
|
116
|
+
* defer the routing decision, or it has no schema at all and answers in prose,
|
|
117
|
+
* which Room.parseAgentResponse converts. An agent that names its own targets
|
|
118
|
+
* keeps doing so.
|
|
119
|
+
*/
|
|
58
120
|
useModerator: boolean;
|
|
59
121
|
promptCacheTTL: number;
|
|
60
122
|
private onStateChange;
|
|
61
123
|
storageDir: string;
|
|
62
124
|
private agentStoreService;
|
|
125
|
+
/**
|
|
126
|
+
* @internal Agents are constructed by the framework (AgentStoreService /
|
|
127
|
+
* BaseAiService.createAgent); SDK consumers should obtain them via
|
|
128
|
+
* {@link Briyah} rather than calling this directly.
|
|
129
|
+
*/
|
|
63
130
|
constructor(id: string | null, userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, systemInstruction: string, history: any[], modelName: string, serviceName: string, aiService: BaseAiService, reasoningEffort: 'low' | 'medium' | 'high' | null, allowSearch: boolean, maxOutputTokens: number, beginInstruction: string, storageDir: string);
|
|
64
131
|
attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
|
|
132
|
+
/**
|
|
133
|
+
* Attaches an artifact to the agent
|
|
134
|
+
* @param artifactId The artifact ID
|
|
135
|
+
*/
|
|
65
136
|
attachArtifact(artifactId: string): void;
|
|
137
|
+
/**
|
|
138
|
+
* Detaches an artifact from the agent
|
|
139
|
+
* @param artifactId The artifact ID
|
|
140
|
+
*/
|
|
66
141
|
detachArtifact(artifactId: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Gets all attached artifact IDs
|
|
144
|
+
* @returns Array of artifact IDs
|
|
145
|
+
*/
|
|
67
146
|
getAttachedArtifacts(): string[];
|
|
147
|
+
/**
|
|
148
|
+
* Saves the agent to disk via AgentStoreService
|
|
149
|
+
* Called automatically after conversation history changes
|
|
150
|
+
*/
|
|
68
151
|
save(): void;
|
|
69
152
|
finishAgent(): Promise<void>;
|
|
70
153
|
deleteAgent(): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Sets the callback to be called when agent state changes
|
|
156
|
+
* Used for SSE updates to push changes to connected clients
|
|
157
|
+
* @param callback Function to call when state changes
|
|
158
|
+
*/
|
|
71
159
|
setOnStateChange(callback: () => void): void;
|
|
160
|
+
/**
|
|
161
|
+
* Notifies listeners that the agent state has changed
|
|
162
|
+
* Triggers SSE updates if callback is registered
|
|
163
|
+
*/
|
|
72
164
|
notifyStateChange(): void;
|
|
73
165
|
canRespond(message: Message): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Gets formatted messages from the agent's history starting from a specific index
|
|
168
|
+
* @param fromIndex The index to start from (0-based)
|
|
169
|
+
* @returns Array of formatted messages
|
|
170
|
+
*/
|
|
74
171
|
getFormattedMessages(fromIndex?: number): string[];
|
|
172
|
+
/**
|
|
173
|
+
* Gets the raw (unformatted) content of every message in the agent's history.
|
|
174
|
+
* @returns Array of message content strings
|
|
175
|
+
*/
|
|
75
176
|
getRawMessages(): string[];
|
|
177
|
+
/**
|
|
178
|
+
* Message fields that are dropped when a message is written into history.
|
|
179
|
+
*
|
|
180
|
+
* History sits in the cached prompt prefix of every agent that holds it, so each
|
|
181
|
+
* of these is paid for on every turn until the message falls out of the window:
|
|
182
|
+
*
|
|
183
|
+
* - `timestamp` — a wall-clock instant. No prompt in the repository reads one, and
|
|
184
|
+
* ordering is already carried by the position in the array.
|
|
185
|
+
* - `index` — the message's position in the room log, which is a storage detail.
|
|
186
|
+
* - `situation` — *current* state, not history. Every agent is handed the live
|
|
187
|
+
* situation in its transient prompt on every turn (`Room.buildTransientPrompt`),
|
|
188
|
+
* so the copies stored here are superseded by definition and, being the longest
|
|
189
|
+
* field on a room leader's messages, the most expensive thing in the window.
|
|
190
|
+
*/
|
|
76
191
|
private static readonly HISTORY_OMITTED_FIELDS;
|
|
192
|
+
/**
|
|
193
|
+
* Renders a room message as the compact JSON that goes into conversation history.
|
|
194
|
+
*
|
|
195
|
+
* Compact rather than indented, and without the fields above or any field that is
|
|
196
|
+
* empty: an absent `name` and an empty `name` say the same thing to a model, and
|
|
197
|
+
* only one of them costs tokens in every cached prefix that carries the message.
|
|
198
|
+
*
|
|
199
|
+
* @param message The room message to render
|
|
200
|
+
* @returns The message as a single-line JSON string
|
|
201
|
+
*/
|
|
77
202
|
private static formatMessageForHistory;
|
|
78
203
|
addToConversationHistory(message: any, fromSelf?: boolean): void;
|
|
204
|
+
/**
|
|
205
|
+
* Marks the current end of history as the start of a task the rolling window
|
|
206
|
+
* must not trim into.
|
|
207
|
+
*
|
|
208
|
+
* A no-op for an agent with no window: there is nothing to protect it from, and
|
|
209
|
+
* a pin on an agent that keeps everything would only be a field to explain. That
|
|
210
|
+
* is what makes it safe to call from a shared path — the Dungeon Master running
|
|
211
|
+
* its own fight keeps its whole campaign either way.
|
|
212
|
+
*
|
|
213
|
+
* Call it *before* the message that starts the task is added to history, so the
|
|
214
|
+
* task's own opening instruction is inside the pin rather than the first thing
|
|
215
|
+
* dropped.
|
|
216
|
+
*/
|
|
79
217
|
pinHistory(): void;
|
|
218
|
+
/** How many trailing messages the pin protects from trimming. */
|
|
80
219
|
private pinnedMessageCount;
|
|
220
|
+
/**
|
|
221
|
+
* Trims conversation history to keep only the last N messages if maxHistoryMessages is set
|
|
222
|
+
* Preserves system messages (role: 'developer') at the start of history
|
|
223
|
+
* Used for rolling window history management (e.g., moderator agents)
|
|
224
|
+
*
|
|
225
|
+
* A {@link historyPin} raises the floor: everything since the pin is kept even
|
|
226
|
+
* when that is more than the window allows. The window still applies to whatever
|
|
227
|
+
* came before it, so a specialist handed a second task drops the first.
|
|
228
|
+
* @param threshold Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once
|
|
229
|
+
*/
|
|
81
230
|
trimHistoryIfNeeded(threshold?: number): void;
|
|
231
|
+
/**
|
|
232
|
+
* Whether `<name>.prompt` resolves for this agent, so a caller can tell an agent
|
|
233
|
+
* that can run a kind of turn from one whose prompt folder has no prompt for it.
|
|
234
|
+
*
|
|
235
|
+
* False when the agent has no AI service or no paths yet — the answer to "could
|
|
236
|
+
* this agent run that turn" is then no, which is what a caller wants to hear.
|
|
237
|
+
*/
|
|
82
238
|
hasPrompt(name: string): boolean;
|
|
83
239
|
instructedPrompt(prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
|
|
84
240
|
preparedPrompt(promptFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean): Promise<any>;
|
|
85
241
|
withSmallModel<T>(fn: () => Promise<T>): Promise<T>;
|
|
242
|
+
/**
|
|
243
|
+
* How large a history may grow, in characters, before it is worth compacting.
|
|
244
|
+
*
|
|
245
|
+
* Read per call rather than cached so an operator can retune a long-running
|
|
246
|
+
* server without restarting it. Characters rather than tokens because it is the
|
|
247
|
+
* one measure available without asking a tokenizer, and the threshold only has
|
|
248
|
+
* to be roughly right — four characters to a token is close enough to make
|
|
249
|
+
* 100,000 mean "about 25k tokens".
|
|
250
|
+
*
|
|
251
|
+
* @returns The threshold in characters
|
|
252
|
+
*/
|
|
86
253
|
static compactionThresholdChars(): number;
|
|
254
|
+
/**
|
|
255
|
+
* The size of this agent's conversation history in characters.
|
|
256
|
+
* @returns Total characters across every message in history
|
|
257
|
+
*/
|
|
87
258
|
historyChars(): number;
|
|
259
|
+
/**
|
|
260
|
+
* Whether this agent's history has grown past the compaction threshold.
|
|
261
|
+
*
|
|
262
|
+
* An agent with `maxHistoryMessages` is excluded: a rolling window already
|
|
263
|
+
* bounds it, and the two mechanisms answer different needs. A window is for an
|
|
264
|
+
* agent whose old turns stop mattering — a moderator routing the next message
|
|
265
|
+
* does not need last hour's. Compaction is for one whose past must survive in
|
|
266
|
+
* some form, which is why it costs a model call to write a summary rather than
|
|
267
|
+
* dropping messages off the front.
|
|
268
|
+
*
|
|
269
|
+
* @returns True when compaction is worth a call
|
|
270
|
+
*/
|
|
88
271
|
needsCompaction(): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Replace this agent's conversation history with a single summary message.
|
|
274
|
+
* Uses the `compact_agent` prompt, resolved via the standard lookup order:
|
|
275
|
+
* user/<promptFolder> → user/root → common/<promptFolder> → common/root.
|
|
276
|
+
* On failure, the original history is restored.
|
|
277
|
+
*/
|
|
89
278
|
compact(): Promise<{
|
|
90
279
|
success: boolean;
|
|
91
280
|
originalLength: number;
|
|
@@ -96,6 +285,13 @@ export declare class Agent {
|
|
|
96
285
|
summary?: string;
|
|
97
286
|
}>;
|
|
98
287
|
textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
|
|
288
|
+
/**
|
|
289
|
+
* Generates an image from a text prompt.
|
|
290
|
+
* @param prompt Text description of the image
|
|
291
|
+
* @param imageProperties Optional provider-specific image options
|
|
292
|
+
* (e.g. `width`, `height`, `quality`) passed through to the underlying AI service
|
|
293
|
+
* @returns Promise resolving to `{ artifactId }` on success or `{ error }` on failure
|
|
294
|
+
*/
|
|
99
295
|
generateImage(prompt: string, imageProperties?: Record<string, any>): Promise<{
|
|
100
296
|
artifactId?: string;
|
|
101
297
|
error?: any;
|