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
|
@@ -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,47 +25,116 @@ 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
79
|
systemInstruction;
|
|
43
|
-
maxHistoryMessages;
|
|
80
|
+
maxHistoryMessages; // If set, keep only last N messages (rolling window)
|
|
81
|
+
/**
|
|
82
|
+
* Index into {@link history} below which the rolling window may trim, and at or
|
|
83
|
+
* above which it may not. Protects a task that must survive intact from an agent
|
|
84
|
+
* whose window is deliberately short.
|
|
85
|
+
*
|
|
86
|
+
* **Deliberately not in `AgentConfig` and never saved.** `maxHistoryMessages` is
|
|
87
|
+
* operator configuration; this is transient state about the task in flight, and
|
|
88
|
+
* persisting it would leave an agent looking as though its window had been
|
|
89
|
+
* changed by hand. A restart clears it, costing at most the protection on one
|
|
90
|
+
* task in progress.
|
|
91
|
+
*
|
|
92
|
+
* It also needs no clearing. Re-pinning ends the previous pin, so an abandoned
|
|
93
|
+
* task is reclaimed the next time one starts, and the worst a stale pin can do is
|
|
94
|
+
* keep more history than intended — never drop any.
|
|
95
|
+
*/
|
|
44
96
|
historyPin;
|
|
45
97
|
modelName;
|
|
46
|
-
smallModelName;
|
|
98
|
+
smallModelName; // Same-service smaller model used by withSmallModel for mechanical prompts
|
|
47
99
|
serviceName;
|
|
48
100
|
reasoningEffort;
|
|
49
101
|
allowSearch;
|
|
50
102
|
maxOutputTokens = 0;
|
|
51
103
|
attachedFiles = [];
|
|
52
|
-
attachedArtifacts = [];
|
|
104
|
+
attachedArtifacts = []; // Array of artifact IDs
|
|
53
105
|
isControlledByHuman = false;
|
|
54
106
|
beginInstruction = '';
|
|
55
|
-
toolNames = [];
|
|
107
|
+
toolNames = []; // Names of user-defined tools this agent may EXECUTE
|
|
108
|
+
/**
|
|
109
|
+
* This agent intends to send MODERATE messages, so its room needs a moderator
|
|
110
|
+
* to route them.
|
|
111
|
+
*
|
|
112
|
+
* For a human-controlled agent it is also what removes the action and target
|
|
113
|
+
* pickers from the room's composer: the player types, the room forces the
|
|
114
|
+
* message to MODERATE, and the moderator decides who hears it and who answers.
|
|
115
|
+
*
|
|
116
|
+
* For an AI agent it is a declaration, not a coercion. An agent emits MODERATE
|
|
117
|
+
* by its own choice — either its perceive schema offers `moderate` as a way to
|
|
118
|
+
* defer the routing decision, or it has no schema at all and answers in prose,
|
|
119
|
+
* which Room.parseAgentResponse converts. An agent that names its own targets
|
|
120
|
+
* keeps doing so.
|
|
121
|
+
*/
|
|
56
122
|
useModerator = false;
|
|
57
|
-
|
|
123
|
+
// Cache keep-alive settings (Anthropic only)
|
|
124
|
+
promptCacheTTL = 0; // The number of minutes to keep the prompt cache
|
|
125
|
+
// State change callback for SSE updates
|
|
58
126
|
onStateChange = null;
|
|
127
|
+
// Persistence
|
|
59
128
|
storageDir;
|
|
60
|
-
agentStoreService;
|
|
129
|
+
agentStoreService; // Reference to AgentStoreService for self-persistence
|
|
130
|
+
/**
|
|
131
|
+
* @internal Agents are constructed by the framework (AgentStoreService /
|
|
132
|
+
* BaseAiService.createAgent); SDK consumers should obtain them via
|
|
133
|
+
* {@link Briyah} rather than calling this directly.
|
|
134
|
+
*/
|
|
61
135
|
constructor(id, userPaths, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', systemInstruction = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
|
|
62
136
|
this.agentName = agentName;
|
|
137
|
+
// Auto-generate nickname if not provided
|
|
63
138
|
this.agentNickname = agentNickname || Agent.generateNickname(agentName);
|
|
64
139
|
this.description = description;
|
|
65
140
|
this.promptFolder = promptFolder;
|
|
@@ -95,17 +170,33 @@ class Agent {
|
|
|
95
170
|
async attachDocument(fileName, fileData) {
|
|
96
171
|
return await this.aiService.attachDocument(this, fileName, fileData);
|
|
97
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Attaches an artifact to the agent
|
|
175
|
+
* @param artifactId The artifact ID
|
|
176
|
+
*/
|
|
98
177
|
attachArtifact(artifactId) {
|
|
99
178
|
if (!this.attachedArtifacts.includes(artifactId)) {
|
|
100
179
|
this.attachedArtifacts.push(artifactId);
|
|
101
180
|
}
|
|
102
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Detaches an artifact from the agent
|
|
184
|
+
* @param artifactId The artifact ID
|
|
185
|
+
*/
|
|
103
186
|
detachArtifact(artifactId) {
|
|
104
187
|
this.attachedArtifacts = this.attachedArtifacts.filter((id) => id !== artifactId);
|
|
105
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Gets all attached artifact IDs
|
|
191
|
+
* @returns Array of artifact IDs
|
|
192
|
+
*/
|
|
106
193
|
getAttachedArtifacts() {
|
|
107
194
|
return [...this.attachedArtifacts];
|
|
108
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Saves the agent to disk via AgentStoreService
|
|
198
|
+
* Called automatically after conversation history changes
|
|
199
|
+
*/
|
|
109
200
|
save() {
|
|
110
201
|
this.agentStoreService.storeAgent(this);
|
|
111
202
|
this.notifyStateChange();
|
|
@@ -116,9 +207,18 @@ class Agent {
|
|
|
116
207
|
async deleteAgent() {
|
|
117
208
|
this.agentStoreService.removeAgent(this.id);
|
|
118
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Sets the callback to be called when agent state changes
|
|
212
|
+
* Used for SSE updates to push changes to connected clients
|
|
213
|
+
* @param callback Function to call when state changes
|
|
214
|
+
*/
|
|
119
215
|
setOnStateChange(callback) {
|
|
120
216
|
this.onStateChange = callback;
|
|
121
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Notifies listeners that the agent state has changed
|
|
220
|
+
* Triggers SSE updates if callback is registered
|
|
221
|
+
*/
|
|
122
222
|
notifyStateChange() {
|
|
123
223
|
if (this.onStateChange) {
|
|
124
224
|
this.onStateChange();
|
|
@@ -129,6 +229,11 @@ class Agent {
|
|
|
129
229
|
return true;
|
|
130
230
|
return message.targets.includes(this.agentNickname);
|
|
131
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Gets formatted messages from the agent's history starting from a specific index
|
|
234
|
+
* @param fromIndex The index to start from (0-based)
|
|
235
|
+
* @returns Array of formatted messages
|
|
236
|
+
*/
|
|
132
237
|
getFormattedMessages(fromIndex = 0) {
|
|
133
238
|
if (!this.history) {
|
|
134
239
|
return [];
|
|
@@ -137,13 +242,41 @@ class Agent {
|
|
|
137
242
|
.slice(fromIndex)
|
|
138
243
|
.map((message) => this.aiService.formatMessage(message));
|
|
139
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Gets the raw (unformatted) content of every message in the agent's history.
|
|
247
|
+
* @returns Array of message content strings
|
|
248
|
+
*/
|
|
140
249
|
getRawMessages() {
|
|
141
250
|
if (!this.history) {
|
|
142
251
|
return [];
|
|
143
252
|
}
|
|
144
253
|
return this.history.map((message) => message.content);
|
|
145
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Message fields that are dropped when a message is written into history.
|
|
257
|
+
*
|
|
258
|
+
* History sits in the cached prompt prefix of every agent that holds it, so each
|
|
259
|
+
* of these is paid for on every turn until the message falls out of the window:
|
|
260
|
+
*
|
|
261
|
+
* - `timestamp` — a wall-clock instant. No prompt in the repository reads one, and
|
|
262
|
+
* ordering is already carried by the position in the array.
|
|
263
|
+
* - `index` — the message's position in the room log, which is a storage detail.
|
|
264
|
+
* - `situation` — *current* state, not history. Every agent is handed the live
|
|
265
|
+
* situation in its transient prompt on every turn (`Room.buildTransientPrompt`),
|
|
266
|
+
* so the copies stored here are superseded by definition and, being the longest
|
|
267
|
+
* field on a room leader's messages, the most expensive thing in the window.
|
|
268
|
+
*/
|
|
146
269
|
static HISTORY_OMITTED_FIELDS = ['timestamp', 'index', 'situation'];
|
|
270
|
+
/**
|
|
271
|
+
* Renders a room message as the compact JSON that goes into conversation history.
|
|
272
|
+
*
|
|
273
|
+
* Compact rather than indented, and without the fields above or any field that is
|
|
274
|
+
* empty: an absent `name` and an empty `name` say the same thing to a model, and
|
|
275
|
+
* only one of them costs tokens in every cached prefix that carries the message.
|
|
276
|
+
*
|
|
277
|
+
* @param message The room message to render
|
|
278
|
+
* @returns The message as a single-line JSON string
|
|
279
|
+
*/
|
|
147
280
|
static formatMessageForHistory(message) {
|
|
148
281
|
const compact = {};
|
|
149
282
|
for (const [field, value] of Object.entries(message)) {
|
|
@@ -169,23 +302,53 @@ class Agent {
|
|
|
169
302
|
}
|
|
170
303
|
this.aiService.addToConversationHistory(this, formattedMessage, fromSelf);
|
|
171
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Marks the current end of history as the start of a task the rolling window
|
|
307
|
+
* must not trim into.
|
|
308
|
+
*
|
|
309
|
+
* A no-op for an agent with no window: there is nothing to protect it from, and
|
|
310
|
+
* a pin on an agent that keeps everything would only be a field to explain. That
|
|
311
|
+
* is what makes it safe to call from a shared path — the Dungeon Master running
|
|
312
|
+
* its own fight keeps its whole campaign either way.
|
|
313
|
+
*
|
|
314
|
+
* Call it *before* the message that starts the task is added to history, so the
|
|
315
|
+
* task's own opening instruction is inside the pin rather than the first thing
|
|
316
|
+
* dropped.
|
|
317
|
+
*/
|
|
172
318
|
pinHistory() {
|
|
173
319
|
if (!this.maxHistoryMessages)
|
|
174
320
|
return;
|
|
175
321
|
this.historyPin = this.history.length;
|
|
176
322
|
}
|
|
323
|
+
/** How many trailing messages the pin protects from trimming. */
|
|
177
324
|
pinnedMessageCount() {
|
|
178
325
|
if (this.historyPin === undefined)
|
|
179
326
|
return 0;
|
|
180
327
|
if (this.historyPin > this.history.length) {
|
|
328
|
+
// The history was replaced wholesale under the pin — compaction, or a
|
|
329
|
+
// restore — so it points at a message that no longer exists. Drop it.
|
|
330
|
+
// Clamping to zero instead would look right until history grew back
|
|
331
|
+
// past the old index, at which point a dead pin would silently start
|
|
332
|
+
// widening the window again.
|
|
181
333
|
this.historyPin = undefined;
|
|
182
334
|
return 0;
|
|
183
335
|
}
|
|
184
336
|
return this.history.length - this.historyPin;
|
|
185
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Trims conversation history to keep only the last N messages if maxHistoryMessages is set
|
|
340
|
+
* Preserves system messages (role: 'developer') at the start of history
|
|
341
|
+
* Used for rolling window history management (e.g., moderator agents)
|
|
342
|
+
*
|
|
343
|
+
* A {@link historyPin} raises the floor: everything since the pin is kept even
|
|
344
|
+
* when that is more than the window allows. The window still applies to whatever
|
|
345
|
+
* came before it, so a specialist handed a second task drops the first.
|
|
346
|
+
* @param threshold Allow history to grow 'threshold' messages past the limit before trimming a 'threshold'-sized chunk of messages at once
|
|
347
|
+
*/
|
|
186
348
|
trimHistoryIfNeeded(threshold = 0) {
|
|
187
349
|
if (!this.maxHistoryMessages)
|
|
188
350
|
return;
|
|
351
|
+
// Count system messages at start (role: 'developer')
|
|
189
352
|
let systemMessageCount = 0;
|
|
190
353
|
for (let i = 0; i < this.history.length; i++) {
|
|
191
354
|
if (this.history[i].role === 'developer') {
|
|
@@ -198,17 +361,27 @@ class Agent {
|
|
|
198
361
|
break;
|
|
199
362
|
}
|
|
200
363
|
}
|
|
364
|
+
// Keep system messages + last N conversation messages, or everything since
|
|
365
|
+
// the pin when the task in flight is longer than the window.
|
|
201
366
|
const keep = Math.max(this.maxHistoryMessages, this.pinnedMessageCount());
|
|
202
367
|
const conversationMessages = this.history.slice(systemMessageCount);
|
|
203
368
|
if (conversationMessages.length > keep + threshold) {
|
|
204
369
|
const keepMessages = conversationMessages.slice(-keep);
|
|
205
370
|
const removed = conversationMessages.length - keepMessages.length;
|
|
206
371
|
this.history = [...this.history.slice(0, systemMessageCount), ...keepMessages];
|
|
372
|
+
// The pin is an index, and the messages under it just moved.
|
|
207
373
|
if (this.historyPin !== undefined) {
|
|
208
374
|
this.historyPin = Math.max(systemMessageCount, this.historyPin - removed);
|
|
209
375
|
}
|
|
210
376
|
}
|
|
211
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* Whether `<name>.prompt` resolves for this agent, so a caller can tell an agent
|
|
380
|
+
* that can run a kind of turn from one whose prompt folder has no prompt for it.
|
|
381
|
+
*
|
|
382
|
+
* False when the agent has no AI service or no paths yet — the answer to "could
|
|
383
|
+
* this agent run that turn" is then no, which is what a caller wants to hear.
|
|
384
|
+
*/
|
|
212
385
|
hasPrompt(name) {
|
|
213
386
|
if (!this.aiService || !this.userPaths)
|
|
214
387
|
return false;
|
|
@@ -233,17 +406,50 @@ class Agent {
|
|
|
233
406
|
this.modelName = original;
|
|
234
407
|
}
|
|
235
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* How large a history may grow, in characters, before it is worth compacting.
|
|
411
|
+
*
|
|
412
|
+
* Read per call rather than cached so an operator can retune a long-running
|
|
413
|
+
* server without restarting it. Characters rather than tokens because it is the
|
|
414
|
+
* one measure available without asking a tokenizer, and the threshold only has
|
|
415
|
+
* to be roughly right — four characters to a token is close enough to make
|
|
416
|
+
* 100,000 mean "about 25k tokens".
|
|
417
|
+
*
|
|
418
|
+
* @returns The threshold in characters
|
|
419
|
+
*/
|
|
236
420
|
static compactionThresholdChars() {
|
|
237
421
|
return Number(process.env.AGENT_COMPACTION_THRESHOLD) || 100000;
|
|
238
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* The size of this agent's conversation history in characters.
|
|
425
|
+
* @returns Total characters across every message in history
|
|
426
|
+
*/
|
|
239
427
|
historyChars() {
|
|
240
428
|
return (this.history ?? []).reduce((sum, m) => sum + (m?.content?.length || 0), 0);
|
|
241
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Whether this agent's history has grown past the compaction threshold.
|
|
432
|
+
*
|
|
433
|
+
* An agent with `maxHistoryMessages` is excluded: a rolling window already
|
|
434
|
+
* bounds it, and the two mechanisms answer different needs. A window is for an
|
|
435
|
+
* agent whose old turns stop mattering — a moderator routing the next message
|
|
436
|
+
* does not need last hour's. Compaction is for one whose past must survive in
|
|
437
|
+
* some form, which is why it costs a model call to write a summary rather than
|
|
438
|
+
* dropping messages off the front.
|
|
439
|
+
*
|
|
440
|
+
* @returns True when compaction is worth a call
|
|
441
|
+
*/
|
|
242
442
|
needsCompaction() {
|
|
243
443
|
if (this.maxHistoryMessages)
|
|
244
444
|
return false;
|
|
245
445
|
return this.historyChars() > Agent.compactionThresholdChars();
|
|
246
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Replace this agent's conversation history with a single summary message.
|
|
449
|
+
* Uses the `compact_agent` prompt, resolved via the standard lookup order:
|
|
450
|
+
* user/<promptFolder> → user/root → common/<promptFolder> → common/root.
|
|
451
|
+
* On failure, the original history is restored.
|
|
452
|
+
*/
|
|
247
453
|
async compact() {
|
|
248
454
|
const originalHistory = [...(this.history || [])];
|
|
249
455
|
const originalLength = originalHistory.length;
|
|
@@ -286,6 +492,13 @@ class Agent {
|
|
|
286
492
|
async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
|
|
287
493
|
return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
|
|
288
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Generates an image from a text prompt.
|
|
497
|
+
* @param prompt Text description of the image
|
|
498
|
+
* @param imageProperties Optional provider-specific image options
|
|
499
|
+
* (e.g. `width`, `height`, `quality`) passed through to the underlying AI service
|
|
500
|
+
* @returns Promise resolving to `{ artifactId }` on success or `{ error }` on failure
|
|
501
|
+
*/
|
|
289
502
|
async generateImage(prompt, imageProperties) {
|
|
290
503
|
return await this.aiService.generateImage(this, prompt, imageProperties);
|
|
291
504
|
}
|
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes per-call debug files for AI requests, thinking output, and responses.
|
|
3
|
+
*
|
|
4
|
+
* Enabled when process.env.AI_DEBUG === 'true' (or when aiDebug is set in
|
|
5
|
+
* LoggingOptions, which maps to the same env var via BriyahConfigService).
|
|
6
|
+
*
|
|
7
|
+
* Files are written to:
|
|
8
|
+
* {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_REQUEST.txt
|
|
9
|
+
* {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_THINKING.txt
|
|
10
|
+
* {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_RESPONSE.txt
|
|
11
|
+
*
|
|
12
|
+
* The millisecond-resolution timestamp prefix keeps files sortable chronologically and
|
|
13
|
+
* distinguishes concurrent calls from different agents.
|
|
14
|
+
*
|
|
15
|
+
* Logging errors are swallowed so they never interrupt the main request flow.
|
|
16
|
+
*/
|
|
1
17
|
export declare class AiDebugLogger {
|
|
2
18
|
static isEnabled(): boolean;
|
|
3
19
|
private static getLogDir;
|
|
4
20
|
private static timestamp;
|
|
21
|
+
/** Replace filesystem-unsafe characters and cap length so filenames stay readable. */
|
|
5
22
|
private static sanitize;
|
|
6
23
|
private static write;
|
|
7
24
|
static writeRequest(agentName: string, content: unknown): void;
|
|
25
|
+
/** No-op when content is empty — avoids creating zero-byte THINKING files on non-reasoning models. */
|
|
8
26
|
static writeThinking(agentName: string, content: string): void;
|
|
9
27
|
static writeResponse(agentName: string, content: string): void;
|
|
10
28
|
}
|
|
@@ -36,6 +36,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.AiDebugLogger = void 0;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
+
/**
|
|
40
|
+
* Writes per-call debug files for AI requests, thinking output, and responses.
|
|
41
|
+
*
|
|
42
|
+
* Enabled when process.env.AI_DEBUG === 'true' (or when aiDebug is set in
|
|
43
|
+
* LoggingOptions, which maps to the same env var via BriyahConfigService).
|
|
44
|
+
*
|
|
45
|
+
* Files are written to:
|
|
46
|
+
* {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_REQUEST.txt
|
|
47
|
+
* {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_THINKING.txt
|
|
48
|
+
* {BRIYAH_DATA_PATH}/logs/ai-debug/YYYY-MM-DD_HH-mm-ss-SSS_<agentName>_RESPONSE.txt
|
|
49
|
+
*
|
|
50
|
+
* The millisecond-resolution timestamp prefix keeps files sortable chronologically and
|
|
51
|
+
* distinguishes concurrent calls from different agents.
|
|
52
|
+
*
|
|
53
|
+
* Logging errors are swallowed so they never interrupt the main request flow.
|
|
54
|
+
*/
|
|
39
55
|
class AiDebugLogger {
|
|
40
56
|
static isEnabled() {
|
|
41
57
|
return process.env.AI_DEBUG === 'true';
|
|
@@ -53,6 +69,7 @@ class AiDebugLogger {
|
|
|
53
69
|
`_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}` +
|
|
54
70
|
`-${pad(now.getMilliseconds(), 3)}`);
|
|
55
71
|
}
|
|
72
|
+
/** Replace filesystem-unsafe characters and cap length so filenames stay readable. */
|
|
56
73
|
static sanitize(name) {
|
|
57
74
|
return name.replace(/[<>:"/\\|?*\s]+/g, '_').substring(0, 80);
|
|
58
75
|
}
|
|
@@ -64,12 +81,14 @@ class AiDebugLogger {
|
|
|
64
81
|
fs.writeFileSync(path.join(this.getLogDir(), filename), content, 'utf8');
|
|
65
82
|
}
|
|
66
83
|
catch {
|
|
84
|
+
// Never let debug logging break the main flow.
|
|
67
85
|
}
|
|
68
86
|
}
|
|
69
87
|
static writeRequest(agentName, content) {
|
|
70
88
|
const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
|
71
89
|
this.write(agentName, 'REQUEST', text);
|
|
72
90
|
}
|
|
91
|
+
/** No-op when content is empty — avoids creating zero-byte THINKING files on non-reasoning models. */
|
|
73
92
|
static writeThinking(agentName, content) {
|
|
74
93
|
if (!content)
|
|
75
94
|
return;
|
|
@@ -21,6 +21,15 @@ export declare class AiFactoryService {
|
|
|
21
21
|
private readonly comfyUiAiService;
|
|
22
22
|
private readonly selfHostedAiService;
|
|
23
23
|
constructor(openAiService: OpenAiService, grokAiService: GrokAiService, anthropicAiService: AnthropicAiService, deepSeekAiService: DeepSeekAiService, togetherAiService: TogetherAiService, mockAiService: MockAiService, googleAiService: GoogleAiService, falAiService: FalAiService, comfyUiAiService: ComfyUiAiService, selfHostedAiService: SelfHostedAiService);
|
|
24
|
+
/**
|
|
25
|
+
* Creates an AI service instance based on the service name
|
|
26
|
+
* @param serviceName The name of the service to create (must match getServiceName())
|
|
27
|
+
* @returns The appropriate AI service instance
|
|
28
|
+
*/
|
|
24
29
|
createAiService(serviceName: string): BaseAiService;
|
|
30
|
+
/**
|
|
31
|
+
* Gets all available AI services
|
|
32
|
+
* @returns Array of all AI service instances
|
|
33
|
+
*/
|
|
25
34
|
getAllAiServices(): BaseAiService[];
|
|
26
35
|
}
|
|
@@ -44,6 +44,11 @@ let AiFactoryService = class AiFactoryService {
|
|
|
44
44
|
this.comfyUiAiService = comfyUiAiService;
|
|
45
45
|
this.selfHostedAiService = selfHostedAiService;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates an AI service instance based on the service name
|
|
49
|
+
* @param serviceName The name of the service to create (must match getServiceName())
|
|
50
|
+
* @returns The appropriate AI service instance
|
|
51
|
+
*/
|
|
47
52
|
createAiService(serviceName) {
|
|
48
53
|
switch (serviceName) {
|
|
49
54
|
case this.openAiService.getServiceName():
|
|
@@ -70,6 +75,10 @@ let AiFactoryService = class AiFactoryService {
|
|
|
70
75
|
throw new Error(`Unknown AI service: ${serviceName}`);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets all available AI services
|
|
80
|
+
* @returns Array of all AI service instances
|
|
81
|
+
*/
|
|
73
82
|
getAllAiServices() {
|
|
74
83
|
return [
|
|
75
84
|
this.openAiService,
|
|
@@ -1,27 +1,158 @@
|
|
|
1
1
|
import { UserPathsService } from '../config/user-paths.service';
|
|
2
2
|
import { ArtifactMetadata } from '../../../shared/types/app.types';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing user artifacts (reusable markdown documents)
|
|
5
|
+
* Separate from AttachedFileService which handles agent-specific file uploads
|
|
6
|
+
* and separate from Room artifacts which are agent-generated conversation outputs
|
|
7
|
+
*
|
|
8
|
+
* Reads span two tiers: the user's own artifacts, and the read-only documents
|
|
9
|
+
* shipped by enabled tool packs (see `pack-artifacts.ts`). Writes only ever touch
|
|
10
|
+
* the user's, and a `pack:` id is refused rather than silently ignored.
|
|
11
|
+
*/
|
|
3
12
|
export declare class ArtifactService {
|
|
4
13
|
private readonly userPaths;
|
|
5
14
|
private readonly artifactsDir;
|
|
15
|
+
/**
|
|
16
|
+
* Where packs live, highest precedence first: the user's own packs, then the
|
|
17
|
+
* host's. A pack name exists in only one of them, so the order settles a
|
|
18
|
+
* collision rather than layering.
|
|
19
|
+
*/
|
|
6
20
|
private readonly packRoots;
|
|
21
|
+
/**
|
|
22
|
+
* The packs whose documents this user should be offered.
|
|
23
|
+
*
|
|
24
|
+
* A thunk, and defaulting to none, so the many places that build an
|
|
25
|
+
* `ArtifactService` without a pack service keep working — they simply see no
|
|
26
|
+
* pack documents in a listing, which is what an unconfigured user sees anyway.
|
|
27
|
+
* Resolution never consults it.
|
|
28
|
+
*/
|
|
7
29
|
private enabledPacks;
|
|
8
30
|
constructor(userPaths: UserPathsService, storageDir?: string);
|
|
31
|
+
/**
|
|
32
|
+
* Tells this service which packs the user has enabled.
|
|
33
|
+
*
|
|
34
|
+
* Set after construction because `PackService` and `ArtifactService` are both
|
|
35
|
+
* built per user and neither can be the other's constructor argument.
|
|
36
|
+
*
|
|
37
|
+
* @param enabledPacks A thunk over the user's enabled packs
|
|
38
|
+
*/
|
|
9
39
|
setEnabledPacks(enabledPacks: () => readonly string[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Guards every write path against a pack document.
|
|
42
|
+
*
|
|
43
|
+
* There is one copy of a shipped document and it is the same for every user,
|
|
44
|
+
* so editing, renaming or deleting one is not a thing a single user may do.
|
|
45
|
+
* Returning rather than throwing keeps the existing "false means it did not
|
|
46
|
+
* happen" contract of the write methods.
|
|
47
|
+
*
|
|
48
|
+
* @returns True when the caller should stop
|
|
49
|
+
*/
|
|
10
50
|
private refuseWriteToPackDocument;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the path to the metadata file
|
|
53
|
+
*/
|
|
11
54
|
private getMetadataPath;
|
|
55
|
+
/**
|
|
56
|
+
* Loads metadata from disk
|
|
57
|
+
*/
|
|
12
58
|
private loadMetadata;
|
|
59
|
+
/**
|
|
60
|
+
* Saves metadata to disk
|
|
61
|
+
*/
|
|
13
62
|
private saveMetadata;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the file path for an artifact
|
|
65
|
+
* @deprecated Use getArtifactFilePath instead for MIME-aware path resolution
|
|
66
|
+
*/
|
|
14
67
|
private getArtifactPath;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the file path for an artifact based on its MIME type
|
|
70
|
+
*/
|
|
15
71
|
private getArtifactFilePath;
|
|
72
|
+
/**
|
|
73
|
+
* Stores a new artifact
|
|
74
|
+
* @param name User-friendly name for the artifact
|
|
75
|
+
* @param content Markdown content
|
|
76
|
+
* @param description Optional description for the artifact
|
|
77
|
+
* @returns The artifactId
|
|
78
|
+
*/
|
|
16
79
|
storeArtifact(name: string, content: string, description?: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Gets artifact content
|
|
82
|
+
* @param artifactId The artifact ID
|
|
83
|
+
* @returns The content (string for text, Buffer for images), or null if not found
|
|
84
|
+
*/
|
|
17
85
|
getArtifact(artifactId: string): string | Buffer | null;
|
|
86
|
+
/**
|
|
87
|
+
* Lists a pack's document files by name, for a tool that enumerates its own
|
|
88
|
+
* documents rather than being handed them.
|
|
89
|
+
*
|
|
90
|
+
* Reads the pack's `artifacts/` directory rather than its manifest, so an
|
|
91
|
+
* operator can add a document by dropping a file in — see
|
|
92
|
+
* {@link listPackDocumentFiles}. Nothing in the client uses this; it exists for
|
|
93
|
+
* `helpers.packDocuments`.
|
|
94
|
+
* @param pack The pack name
|
|
95
|
+
* @param prefix Keep only file names starting with this
|
|
96
|
+
* @returns Bare `.md` file names, sorted
|
|
97
|
+
*/
|
|
18
98
|
listPackDocumentFiles(pack: string, prefix?: string): string[];
|
|
99
|
+
/**
|
|
100
|
+
* Reads one of a pack's document files by name.
|
|
101
|
+
* @param pack The pack name
|
|
102
|
+
* @param fileName A bare file name from {@link listPackDocumentFiles}
|
|
103
|
+
* @returns The document's text, or null if there is no such file
|
|
104
|
+
*/
|
|
19
105
|
readPackDocumentFile(pack: string, fileName: string): string | null;
|
|
106
|
+
/**
|
|
107
|
+
* Lists all artifacts: the documents shipped by enabled tool packs first, then
|
|
108
|
+
* the user's own.
|
|
109
|
+
*
|
|
110
|
+
* Pack documents lead because they are the same for everyone and the user did
|
|
111
|
+
* not put them there — burying them among their own uploads is how they get
|
|
112
|
+
* missed.
|
|
113
|
+
* @returns Array of artifact metadata
|
|
114
|
+
*/
|
|
20
115
|
listArtifacts(): ArtifactMetadata[];
|
|
116
|
+
/**
|
|
117
|
+
* Gets metadata for a specific artifact
|
|
118
|
+
* @param artifactId The artifact ID
|
|
119
|
+
* @returns The metadata, or null if not found
|
|
120
|
+
*/
|
|
21
121
|
getArtifactMetadata(artifactId: string): ArtifactMetadata | null;
|
|
122
|
+
/**
|
|
123
|
+
* Updates artifact content
|
|
124
|
+
* @param artifactId The artifact ID
|
|
125
|
+
* @param content New content
|
|
126
|
+
* @returns True if successful, false otherwise
|
|
127
|
+
*/
|
|
22
128
|
updateArtifact(artifactId: string, content: string): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Renames an artifact
|
|
131
|
+
* @param artifactId The artifact ID
|
|
132
|
+
* @param newName New name
|
|
133
|
+
* @returns True if successful, false otherwise
|
|
134
|
+
*/
|
|
23
135
|
renameArtifact(artifactId: string, newName: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Updates an artifact's description in metadata
|
|
138
|
+
* @param artifactId The artifact ID
|
|
139
|
+
* @param description New description
|
|
140
|
+
* @returns True if successful, false otherwise
|
|
141
|
+
*/
|
|
24
142
|
updateArtifactDescription(artifactId: string, description: string): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Deletes an artifact
|
|
145
|
+
* @param artifactId The artifact ID
|
|
146
|
+
* @returns True if successful, false otherwise
|
|
147
|
+
*/
|
|
25
148
|
deleteArtifact(artifactId: string): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Stores a new image artifact
|
|
151
|
+
* @param name User-friendly name for the artifact
|
|
152
|
+
* @param imageData Binary image data
|
|
153
|
+
* @param mimeType MIME type of the image (e.g., 'image/png')
|
|
154
|
+
* @param description Optional description for the artifact
|
|
155
|
+
* @returns The artifactId
|
|
156
|
+
*/
|
|
26
157
|
storeImageArtifact(name: string, imageData: Buffer, mimeType: string, description?: string): string;
|
|
27
158
|
}
|