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
|
@@ -8,10 +8,40 @@ export declare class TogetherAiService extends BaseAiService {
|
|
|
8
8
|
getModelPricePrefix(): string;
|
|
9
9
|
supportsImageGeneration(): boolean;
|
|
10
10
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
13
|
+
* @param agent The agent to add the message to
|
|
14
|
+
* @param message The formatted message to add
|
|
15
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
16
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
17
|
+
*/
|
|
11
18
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
|
|
12
19
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Compute the cost of a text message with markup for Together AI
|
|
22
|
+
* Together AI doesn't support prompt caching, so this is a simple calculation
|
|
23
|
+
* Handles model name lookup with together_ai/ prefix if needed
|
|
24
|
+
* @param agent The agent making the request
|
|
25
|
+
* @param usage Usage object from the API response
|
|
26
|
+
*/
|
|
13
27
|
private computeMessageCost;
|
|
28
|
+
/**
|
|
29
|
+
* Compute the cost of image generation with markup (hardcoded to 0 for images)
|
|
30
|
+
* Together AI image models separate tokens into image_tokens and text_tokens with different pricing
|
|
31
|
+
* @param agent The agent making the request
|
|
32
|
+
* @param usage The usage object from the image generation response
|
|
33
|
+
*/
|
|
14
34
|
private computeImageCost;
|
|
35
|
+
/**
|
|
36
|
+
* Generates an image from a text prompt with optional reference images
|
|
37
|
+
* @param agent The agent making the request
|
|
38
|
+
* @param prompt Text description of the image to generate
|
|
39
|
+
* @param width
|
|
40
|
+
* @param height
|
|
41
|
+
* @param quality
|
|
42
|
+
* @param referenceImageArtifactIds Optional array of artifact IDs containing reference images
|
|
43
|
+
* @returns Promise resolving to JSON string with { url, artifactId }
|
|
44
|
+
*/
|
|
15
45
|
generateImage(agent: Agent, prompt: string, imageProperties?: Record<string, any>): Promise<{
|
|
16
46
|
artifactId?: string;
|
|
17
47
|
error?: any;
|
|
@@ -31,7 +31,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
31
31
|
}
|
|
32
32
|
this.togetherClient = new together_ai_1.default({
|
|
33
33
|
apiKey: apiKey,
|
|
34
|
-
timeout: 600000,
|
|
34
|
+
timeout: 600000, // 10 minutes for very long requests
|
|
35
35
|
maxRetries: 3,
|
|
36
36
|
});
|
|
37
37
|
logger_1.logger.debug('TogetherAI service initialized successfully');
|
|
@@ -63,6 +63,13 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
63
63
|
};
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
68
|
+
* @param agent The agent to add the message to
|
|
69
|
+
* @param message The formatted message to add
|
|
70
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
71
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
72
|
+
*/
|
|
66
73
|
addToConversationHistory(agent, message, fromSelf = false, developer = false) {
|
|
67
74
|
if (!agent.history) {
|
|
68
75
|
agent.history = [];
|
|
@@ -78,19 +85,25 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
78
85
|
});
|
|
79
86
|
agent.trimHistoryIfNeeded();
|
|
80
87
|
}
|
|
81
|
-
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
88
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
|
+
_cacheConfig = null, maxOutputChars = 0) {
|
|
91
|
+
// CHECK BALANCE BEFORE AI CALL (unless disabled)
|
|
82
92
|
if (agent.balanceService && !agent.disableBalanceCheck) {
|
|
83
93
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
84
94
|
if (!hasSufficientBalance) {
|
|
85
95
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
86
96
|
}
|
|
87
97
|
}
|
|
98
|
+
// Build messages array locally without modifying agent.history yet
|
|
99
|
+
// Prepend identity and system instruction at the beginning
|
|
88
100
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
89
101
|
const instructions = promptInstructions || agent.systemInstruction;
|
|
90
102
|
const messages = [];
|
|
91
103
|
if (instructions)
|
|
92
104
|
messages.push({ role: 'system', content: instructions });
|
|
93
105
|
messages.push({ role: 'system', content: identity });
|
|
106
|
+
// Add attached files as text (Together AI doesn't support native file uploads)
|
|
94
107
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
95
108
|
for (const file of agent.attachedFiles) {
|
|
96
109
|
if (file.serviceMetadata?.fileData) {
|
|
@@ -103,13 +116,16 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
118
|
}
|
|
119
|
+
// Add conversation history
|
|
106
120
|
messages.push(...agent.history);
|
|
121
|
+
// Add user prompt to local array
|
|
107
122
|
if (prompt) {
|
|
108
123
|
messages.push({
|
|
109
124
|
role: 'user',
|
|
110
125
|
content: prompt,
|
|
111
126
|
});
|
|
112
127
|
}
|
|
128
|
+
// Configure response format if JSON schema provided
|
|
113
129
|
const responseFormat = jsonSchema
|
|
114
130
|
? {
|
|
115
131
|
type: 'json_schema',
|
|
@@ -130,6 +146,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
130
146
|
let responseText;
|
|
131
147
|
try {
|
|
132
148
|
const response = await this.togetherClient.chat.completions.create(requestParams);
|
|
149
|
+
// Extract response
|
|
133
150
|
if (response.choices && response.choices[0]?.message?.content) {
|
|
134
151
|
responseText = response.choices[0].message.content;
|
|
135
152
|
}
|
|
@@ -143,6 +160,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
143
160
|
responseText = this.trimResponseText(responseText);
|
|
144
161
|
}
|
|
145
162
|
this.debugLogResponse(agent.agentName, responseText);
|
|
163
|
+
// Track token usage
|
|
146
164
|
if (response.usage) {
|
|
147
165
|
this.computeMessageCost(agent, response.usage);
|
|
148
166
|
}
|
|
@@ -151,6 +169,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
151
169
|
logger_1.logger.error('Error calling Together AI:', error);
|
|
152
170
|
throw error;
|
|
153
171
|
}
|
|
172
|
+
// Only modify agent.history if saveResponse=true
|
|
154
173
|
if (saveResponse) {
|
|
155
174
|
this.addToConversationHistory(agent, prompt, false);
|
|
156
175
|
this.addToConversationHistory(agent, responseText, true);
|
|
@@ -160,9 +179,17 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
160
179
|
}
|
|
161
180
|
return responseText;
|
|
162
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Compute the cost of a text message with markup for Together AI
|
|
184
|
+
* Together AI doesn't support prompt caching, so this is a simple calculation
|
|
185
|
+
* Handles model name lookup with together_ai/ prefix if needed
|
|
186
|
+
* @param agent The agent making the request
|
|
187
|
+
* @param usage Usage object from the API response
|
|
188
|
+
*/
|
|
163
189
|
computeMessageCost(agent, usage) {
|
|
164
190
|
const promptTokens = usage.prompt_tokens || 0;
|
|
165
191
|
const completionTokens = usage.completion_tokens || 0;
|
|
192
|
+
// Try to find model with current name, then try with together_ai/ prefix
|
|
166
193
|
let modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
167
194
|
if (!modelInfo && !agent.modelName.startsWith('together_ai/')) {
|
|
168
195
|
modelInfo = (0, model_prices_1.getModelPrices)()[`together_ai/${agent.modelName}`];
|
|
@@ -171,19 +198,29 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
171
198
|
logger_1.logger.error(`No price info found for model ${agent.modelName} or together_ai/${agent.modelName}`);
|
|
172
199
|
return;
|
|
173
200
|
}
|
|
201
|
+
// Simple calculation (no cache support)
|
|
174
202
|
const inputCost = promptTokens * modelInfo.input_cost_per_token;
|
|
175
203
|
const outputCost = completionTokens * modelInfo.output_cost_per_token;
|
|
204
|
+
// Calculate markup: 2x output cost (unless disabled)
|
|
176
205
|
const markup = agent.disableMarkup ? 0 : outputCost * agent.markupRate;
|
|
177
206
|
const cost = inputCost + outputCost + markup;
|
|
207
|
+
// Update agent totals
|
|
178
208
|
agent.totalInputTokens += promptTokens;
|
|
179
209
|
agent.totalOutputTokens += completionTokens;
|
|
180
210
|
agent.totalCost += cost;
|
|
181
211
|
agent.totalMarkup += markup;
|
|
182
212
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
213
|
+
// Decrement balance with markup
|
|
183
214
|
if (agent.balanceService && cost > 0) {
|
|
184
215
|
agent.balanceService.decrementBalance(cost, markup);
|
|
185
216
|
}
|
|
186
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Compute the cost of image generation with markup (hardcoded to 0 for images)
|
|
220
|
+
* Together AI image models separate tokens into image_tokens and text_tokens with different pricing
|
|
221
|
+
* @param agent The agent making the request
|
|
222
|
+
* @param usage The usage object from the image generation response
|
|
223
|
+
*/
|
|
187
224
|
computeImageCost(agent, usage, centsPerImage) {
|
|
188
225
|
const modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
189
226
|
if (!modelInfo) {
|
|
@@ -198,15 +235,19 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
198
235
|
logger_1.logger.warn(`No price info found for model ${agent.modelName}. Skipping cost tracking.`);
|
|
199
236
|
return;
|
|
200
237
|
}
|
|
238
|
+
// Extract token counts from usage object
|
|
201
239
|
const inputImageTokens = usage.input_tokens_details?.image_tokens || 0;
|
|
202
240
|
const inputTextTokens = usage.input_tokens_details?.text_tokens || 0;
|
|
203
241
|
const outputImageTokens = usage.output_tokens_details?.image_tokens || 0;
|
|
204
242
|
const outputTextTokens = usage.output_tokens_details?.text_tokens || 0;
|
|
243
|
+
// Track all token usage
|
|
205
244
|
const totalInputTokens = usage.input_tokens || 0;
|
|
206
245
|
const totalOutputTokens = usage.output_tokens || 0;
|
|
207
246
|
agent.totalInputTokens += totalInputTokens;
|
|
208
247
|
agent.totalOutputTokens += totalOutputTokens;
|
|
248
|
+
// Calculate input costs (with cache support)
|
|
209
249
|
let inputCost = 0;
|
|
250
|
+
// Input image tokens (with cache support)
|
|
210
251
|
if (inputImageTokens > 0) {
|
|
211
252
|
const cachedImageTokens = usage.input_tokens_details?.cached_image_tokens || 0;
|
|
212
253
|
const uncachedImageTokens = inputImageTokens - cachedImageTokens;
|
|
@@ -218,6 +259,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
218
259
|
modelInfo.input_cost_per_image_token * 0.5);
|
|
219
260
|
}
|
|
220
261
|
}
|
|
262
|
+
// Input text tokens (with cache support)
|
|
221
263
|
if (inputTextTokens > 0) {
|
|
222
264
|
const cachedTextTokens = usage.input_tokens_details?.cached_text_tokens || 0;
|
|
223
265
|
const uncachedTextTokens = inputTextTokens - cachedTextTokens;
|
|
@@ -229,22 +271,38 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
|
|
|
229
271
|
modelInfo.input_cost_per_token * 0.5);
|
|
230
272
|
}
|
|
231
273
|
}
|
|
274
|
+
// Calculate output costs
|
|
232
275
|
let outputCost = 0;
|
|
276
|
+
// Output image tokens
|
|
233
277
|
if (outputImageTokens > 0) {
|
|
234
278
|
outputCost += outputImageTokens * (modelInfo.output_cost_per_image_token || 0);
|
|
235
279
|
}
|
|
280
|
+
// Output text tokens
|
|
236
281
|
if (outputTextTokens > 0) {
|
|
237
282
|
outputCost += outputTextTokens * (modelInfo.output_cost_per_token || 0);
|
|
238
283
|
}
|
|
284
|
+
// Calculate markup: hardcoded to 0 for image generation
|
|
239
285
|
const markup = outputCost * 0;
|
|
240
286
|
const cost = inputCost + outputCost + markup;
|
|
287
|
+
// Update agent totals
|
|
241
288
|
agent.totalCost += cost;
|
|
242
289
|
agent.totalMarkup += markup;
|
|
243
290
|
logger_1.logger.log(`Cost for image generation: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
291
|
+
// Decrement balance with markup
|
|
244
292
|
if (agent.balanceService && cost > 0) {
|
|
245
293
|
agent.balanceService.decrementBalance(cost, markup);
|
|
246
294
|
}
|
|
247
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Generates an image from a text prompt with optional reference images
|
|
298
|
+
* @param agent The agent making the request
|
|
299
|
+
* @param prompt Text description of the image to generate
|
|
300
|
+
* @param width
|
|
301
|
+
* @param height
|
|
302
|
+
* @param quality
|
|
303
|
+
* @param referenceImageArtifactIds Optional array of artifact IDs containing reference images
|
|
304
|
+
* @returns Promise resolving to JSON string with { url, artifactId }
|
|
305
|
+
*/
|
|
248
306
|
async generateImage(agent, prompt, imageProperties) {
|
|
249
307
|
const { centsPerImage, ...apiProperties } = imageProperties ?? {};
|
|
250
308
|
const modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { FileMetadata } from './attached-file.service';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for serializable agent configuration
|
|
4
|
+
*/
|
|
2
5
|
export interface AgentConfig {
|
|
3
6
|
id: string;
|
|
4
7
|
agentName: string;
|
|
@@ -33,6 +36,18 @@ export interface AgentConfig {
|
|
|
33
36
|
ownerRoomId?: string;
|
|
34
37
|
toolNames?: string[];
|
|
35
38
|
useModerator?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The pack this agent is filed under, which decides whether it is listed.
|
|
41
|
+
*
|
|
42
|
+
* Set when the agent is created from a pack template, and editable afterwards
|
|
43
|
+
* so a user can file their own work under a pack of their own. Absent means
|
|
44
|
+
* "not filed", and an agent naming a pack that is not installed is still
|
|
45
|
+
* listed — deleting a pack must not hide the agents it produced.
|
|
46
|
+
*
|
|
47
|
+
* Deliberately not `templateAgentId`, which means "published instance of a
|
|
48
|
+
* local template" and changes which list the agent appears in.
|
|
49
|
+
*/
|
|
36
50
|
pack?: string;
|
|
51
|
+
/** The pack template's key, when this agent came from one. */
|
|
37
52
|
packAgentKey?: string;
|
|
38
53
|
}
|
|
@@ -5,6 +5,10 @@ import { UserPathsService } from '../config/user-paths.service';
|
|
|
5
5
|
import { IConfigService } from '../config/env-config';
|
|
6
6
|
import { BalanceService } from '../app/balance.service';
|
|
7
7
|
import { Agent } from './agent';
|
|
8
|
+
/**
|
|
9
|
+
* Factory for creating AI agents
|
|
10
|
+
* Not a singleton - instantiated per-user by UserServiceFactory
|
|
11
|
+
*/
|
|
8
12
|
export declare class AgentFactory {
|
|
9
13
|
private readonly aiFactoryService;
|
|
10
14
|
private readonly agentStoreService;
|
|
@@ -13,5 +17,17 @@ export declare class AgentFactory {
|
|
|
13
17
|
private readonly artifactService;
|
|
14
18
|
private readonly configService;
|
|
15
19
|
constructor(aiFactoryService: AiFactoryService, agentStoreService: AgentStoreService, userPaths: UserPathsService, balanceService: BalanceService, artifactService: ArtifactService, configService: IConfigService);
|
|
20
|
+
/**
|
|
21
|
+
* Creates an agent using the specified AI service
|
|
22
|
+
* @param aiServiceName The AI service to use (e.g., 'Anthropic', 'OpenAI', 'Grok')
|
|
23
|
+
* @param agentName Name of the agent
|
|
24
|
+
* @param agentNickname Nickname for the agent (optional, defaults to empty string)
|
|
25
|
+
* @param description Agent description
|
|
26
|
+
* @param promptFolder Prompt folder name (e.g., 'default', 'attorney', 'character')
|
|
27
|
+
* @param modelName Model to use (e.g., 'claude-opus-4-5', 'gpt-4')
|
|
28
|
+
* @param storageDir Optional storage directory (defaults to agentStore default)
|
|
29
|
+
* @param artifactService Optional artifact service (defaults to factory's artifact service)
|
|
30
|
+
* @returns Created Agent instance
|
|
31
|
+
*/
|
|
16
32
|
createAgent(aiServiceName: string, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string, artifactService?: ArtifactService): Agent;
|
|
17
33
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating AI agents
|
|
6
|
+
* Not a singleton - instantiated per-user by UserServiceFactory
|
|
7
|
+
*/
|
|
4
8
|
class AgentFactory {
|
|
5
9
|
aiFactoryService;
|
|
6
10
|
agentStoreService;
|
|
@@ -16,10 +20,26 @@ class AgentFactory {
|
|
|
16
20
|
this.artifactService = artifactService;
|
|
17
21
|
this.configService = configService;
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates an agent using the specified AI service
|
|
25
|
+
* @param aiServiceName The AI service to use (e.g., 'Anthropic', 'OpenAI', 'Grok')
|
|
26
|
+
* @param agentName Name of the agent
|
|
27
|
+
* @param agentNickname Nickname for the agent (optional, defaults to empty string)
|
|
28
|
+
* @param description Agent description
|
|
29
|
+
* @param promptFolder Prompt folder name (e.g., 'default', 'attorney', 'character')
|
|
30
|
+
* @param modelName Model to use (e.g., 'claude-opus-4-5', 'gpt-4')
|
|
31
|
+
* @param storageDir Optional storage directory (defaults to agentStore default)
|
|
32
|
+
* @param artifactService Optional artifact service (defaults to factory's artifact service)
|
|
33
|
+
* @returns Created Agent instance
|
|
34
|
+
*/
|
|
19
35
|
createAgent(aiServiceName, agentName, agentNickname, description, promptFolder, modelName, storageDir = '', artifactService) {
|
|
36
|
+
// Get AI service by name
|
|
20
37
|
const aiService = this.aiFactoryService.createAiService(aiServiceName);
|
|
38
|
+
// Use default storage dir if not provided
|
|
21
39
|
const finalStorageDir = storageDir || this.agentStoreService.getDefaultStorageDir();
|
|
40
|
+
// Use provided artifact service or fall back to factory's default
|
|
22
41
|
const finalArtifactService = artifactService || this.artifactService;
|
|
42
|
+
// Create agent with all dependencies
|
|
23
43
|
return aiService.createAgent(this.userPaths, this.configService, this.agentStoreService, this.balanceService, finalArtifactService, agentName, agentNickname, description, promptFolder, modelName, finalStorageDir);
|
|
24
44
|
}
|
|
25
45
|
}
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
/**
|
|
3
|
+
* Service for managing SSE connections for agent message updates
|
|
4
|
+
* Uses event-driven updates triggered by agent state changes (no polling)
|
|
5
|
+
*/
|
|
2
6
|
export declare class AgentMessageService {
|
|
3
7
|
private messageEmitters;
|
|
8
|
+
/**
|
|
9
|
+
* Gets or creates a message emitter for an agent
|
|
10
|
+
* @param agentId The agent ID
|
|
11
|
+
* @returns The event emitter for this agent
|
|
12
|
+
*/
|
|
4
13
|
getOrCreateEmitter(agentId: string): EventEmitter;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the message emitter for an agent
|
|
16
|
+
* @param agentId The agent ID
|
|
17
|
+
* @returns The event emitter or undefined if not found
|
|
18
|
+
*/
|
|
5
19
|
getEmitter(agentId: string): EventEmitter | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Emits a message update event for an agent
|
|
22
|
+
* Called when agent's message history changes
|
|
23
|
+
* @param agentId The agent ID
|
|
24
|
+
* @param agentState The updated agent state
|
|
25
|
+
*/
|
|
6
26
|
emitUpdate(agentId: string, agentState: any): void;
|
|
27
|
+
/**
|
|
28
|
+
* Emits an error event for an agent
|
|
29
|
+
* Called when errors occur during agent operations
|
|
30
|
+
* @param agentId The agent ID
|
|
31
|
+
* @param error The error that occurred
|
|
32
|
+
*/
|
|
7
33
|
emitError(agentId: string, error: Error): void;
|
|
34
|
+
/**
|
|
35
|
+
* Cleans up the message emitter for an agent
|
|
36
|
+
* @param agentId The agent ID
|
|
37
|
+
*/
|
|
8
38
|
cleanup(agentId: string): void;
|
|
9
39
|
}
|
|
@@ -9,8 +9,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.AgentMessageService = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const events_1 = require("events");
|
|
12
|
+
/**
|
|
13
|
+
* Service for managing SSE connections for agent message updates
|
|
14
|
+
* Uses event-driven updates triggered by agent state changes (no polling)
|
|
15
|
+
*/
|
|
12
16
|
let AgentMessageService = class AgentMessageService {
|
|
13
17
|
messageEmitters = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Gets or creates a message emitter for an agent
|
|
20
|
+
* @param agentId The agent ID
|
|
21
|
+
* @returns The event emitter for this agent
|
|
22
|
+
*/
|
|
14
23
|
getOrCreateEmitter(agentId) {
|
|
15
24
|
let emitter = this.messageEmitters.get(agentId);
|
|
16
25
|
if (!emitter) {
|
|
@@ -19,9 +28,20 @@ let AgentMessageService = class AgentMessageService {
|
|
|
19
28
|
}
|
|
20
29
|
return emitter;
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the message emitter for an agent
|
|
33
|
+
* @param agentId The agent ID
|
|
34
|
+
* @returns The event emitter or undefined if not found
|
|
35
|
+
*/
|
|
22
36
|
getEmitter(agentId) {
|
|
23
37
|
return this.messageEmitters.get(agentId);
|
|
24
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Emits a message update event for an agent
|
|
41
|
+
* Called when agent's message history changes
|
|
42
|
+
* @param agentId The agent ID
|
|
43
|
+
* @param agentState The updated agent state
|
|
44
|
+
*/
|
|
25
45
|
emitUpdate(agentId, agentState) {
|
|
26
46
|
const emitter = this.messageEmitters.get(agentId);
|
|
27
47
|
if (emitter) {
|
|
@@ -31,6 +51,12 @@ let AgentMessageService = class AgentMessageService {
|
|
|
31
51
|
});
|
|
32
52
|
}
|
|
33
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Emits an error event for an agent
|
|
56
|
+
* Called when errors occur during agent operations
|
|
57
|
+
* @param agentId The agent ID
|
|
58
|
+
* @param error The error that occurred
|
|
59
|
+
*/
|
|
34
60
|
emitError(agentId, error) {
|
|
35
61
|
const emitter = this.messageEmitters.get(agentId);
|
|
36
62
|
if (emitter) {
|
|
@@ -42,6 +68,10 @@ let AgentMessageService = class AgentMessageService {
|
|
|
42
68
|
});
|
|
43
69
|
}
|
|
44
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Cleans up the message emitter for an agent
|
|
73
|
+
* @param agentId The agent ID
|
|
74
|
+
*/
|
|
45
75
|
cleanup(agentId) {
|
|
46
76
|
const emitter = this.messageEmitters.get(agentId);
|
|
47
77
|
if (emitter) {
|
|
@@ -5,6 +5,12 @@ import { UserPathsService } from '../config/user-paths.service';
|
|
|
5
5
|
import { IConfigService } from '../config/env-config';
|
|
6
6
|
import { AttachedFileService } from './attached-file.service';
|
|
7
7
|
import { BalanceService } from '../app/balance.service';
|
|
8
|
+
/**
|
|
9
|
+
* A service that stores and retrieves Agent objects by ID
|
|
10
|
+
* Each agent is stored in its own JSON file named by its GUID
|
|
11
|
+
* Supports configurable storage directories (e.g., for story-specific agents)
|
|
12
|
+
* Uses lazy loading - agents are loaded from disk on first access
|
|
13
|
+
*/
|
|
8
14
|
export declare class AgentStoreService {
|
|
9
15
|
private readonly aiFactoryService;
|
|
10
16
|
private readonly userPaths;
|
|
@@ -17,18 +23,92 @@ export declare class AgentStoreService {
|
|
|
17
23
|
private loaded;
|
|
18
24
|
private loadPromise;
|
|
19
25
|
constructor(aiFactoryService: AiFactoryService, userPaths: UserPathsService, attachedFileService: AttachedFileService, balanceService: BalanceService, artifactService: ArtifactService, configService: IConfigService);
|
|
26
|
+
/**
|
|
27
|
+
* Gets the default storage directory for agents
|
|
28
|
+
* @returns The default storage directory path
|
|
29
|
+
*/
|
|
20
30
|
getDefaultStorageDir(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Registers an agent in the in-memory store without writing to disk.
|
|
33
|
+
* Use this when creating a new agent that the user hasn't explicitly saved yet.
|
|
34
|
+
* Call agent.save() later to persist it.
|
|
35
|
+
* @param agent The agent to register
|
|
36
|
+
*/
|
|
21
37
|
registerAgent(agent: Agent): void;
|
|
38
|
+
/**
|
|
39
|
+
* Stores an agent and returns its unique ID
|
|
40
|
+
* @param agent The agent to store
|
|
41
|
+
* @param storageDir Optional custom storage directory (defaults to server/data/agents)
|
|
42
|
+
* @returns The unique ID for the agent
|
|
43
|
+
*/
|
|
22
44
|
storeAgent(agent: Agent, storageDir?: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves an agent by its ID
|
|
47
|
+
* @param id The agent ID
|
|
48
|
+
* @returns The agent, or undefined if not found
|
|
49
|
+
*/
|
|
23
50
|
getAgent(id: string): Promise<Agent | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Removes an agent from the store and deletes its file
|
|
53
|
+
* @param id The agent ID
|
|
54
|
+
* @returns True if the agent was found and removed, false otherwise
|
|
55
|
+
*/
|
|
24
56
|
removeAgent(id: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Gets all agent IDs from the in-memory store
|
|
59
|
+
* @returns Array of agent IDs
|
|
60
|
+
*/
|
|
25
61
|
getAllAgentIds(): Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the number of agents in the store
|
|
64
|
+
* @returns The number of agents
|
|
65
|
+
*/
|
|
26
66
|
getAgentCount(): Promise<number>;
|
|
67
|
+
/**
|
|
68
|
+
* Clones an agent as a published instance with a new name
|
|
69
|
+
* @param templateId The ID of the template agent to clone
|
|
70
|
+
* @param publishedName The name for the published instance
|
|
71
|
+
* @param userId The user ID (for tracking purposes)
|
|
72
|
+
* @returns The ID of the newly created published instance
|
|
73
|
+
*/
|
|
27
74
|
cloneAgentAsPublished(templateId: string, publishedName: string, _userId: string): Promise<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Gets all published instances of a template agent
|
|
77
|
+
* @param templateId The ID of the template agent
|
|
78
|
+
* @returns Array of published instances
|
|
79
|
+
*/
|
|
28
80
|
getPublishedInstances(templateId: string): Promise<Agent[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Resets a published instance to match its template's current properties
|
|
83
|
+
* Preserves the instance ID, name, creation date and usage totals
|
|
84
|
+
* Clears conversation history
|
|
85
|
+
* @param instanceId The ID of the instance to reset
|
|
86
|
+
* @param templateId The ID of the template agent
|
|
87
|
+
*/
|
|
29
88
|
resetPublishedInstance(instanceId: string, templateId: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Ensures default agents are loaded from disk (lazy loading)
|
|
91
|
+
* Only loads once - subsequent calls are no-op
|
|
92
|
+
* Uses promise memoization to prevent concurrent loads
|
|
93
|
+
*/
|
|
30
94
|
private ensureLoaded;
|
|
95
|
+
/**
|
|
96
|
+
* Loads agents from a specific directory
|
|
97
|
+
* Used for loading story-specific agents
|
|
98
|
+
* @param storageDir The directory to load agents from
|
|
99
|
+
* @param artifactService Optional artifact service (for story-specific artifacts)
|
|
100
|
+
*/
|
|
31
101
|
loadAgentsFromDirectory(storageDir: string, artifactService?: ArtifactService): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Saves a single agent to its own JSON file
|
|
104
|
+
* @param agent The agent to save
|
|
105
|
+
* @param storageDir The directory to save the agent in
|
|
106
|
+
*/
|
|
32
107
|
private saveAgentToFile;
|
|
108
|
+
/**
|
|
109
|
+
* Deletes an agent's JSON file
|
|
110
|
+
* @param agentId The agent ID
|
|
111
|
+
* @param storageDir The directory containing the agent file
|
|
112
|
+
*/
|
|
33
113
|
private deleteAgentFile;
|
|
34
114
|
}
|