briyah 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -8
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/config/story_models.json +3 -3
- package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/data/common/prompts/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/rooms/campaign.json +18 -15
- package/data/packs/dnd5e/rooms/table.json +17 -16
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
- package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
- package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
- package/dist-sdk/server/src/ai/agent.d.ts +197 -2
- package/dist-sdk/server/src/ai/agent.js +225 -14
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +46 -3
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +120 -0
- package/dist-sdk/server/src/app.controller.js +365 -14
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1710 -4
- package/dist-sdk/server/src/app.service.js +1938 -20
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +84 -1
- package/dist-sdk/server/src/room/room-config.js +19 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
- package/dist-sdk/server/src/room/room-factory.js +25 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
- package/dist-sdk/server/src/room/room-store.service.js +280 -6
- package/dist-sdk/server/src/room/room.d.ts +981 -1
- package/dist-sdk/server/src/room/room.js +1531 -27
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +366 -9
- package/dist-sdk/server/src/story/story.service.js +825 -374
- package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +24 -1
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
- package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +328 -13
- package/dist-sdk/shared/types/app.types.js +18 -1
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -138,7 +138,7 @@ Everyone hears what you say, but only the character you name responds.
|
|
|
138
138
|
{{#each availableTools}}
|
|
139
139
|
- **{{this.name}}**: {{this.description}}
|
|
140
140
|
{{#each this.parameters}}
|
|
141
|
-
- {{this.name}} ({{this.type}}{{#if this.required}}, required{{/if}}): {{this.description}}
|
|
141
|
+
- {{this.name}} ({{this.type}}{{#if this.required}}, required{{/if}}): {{this.description}}{{#if this.enumText}} Must be exactly one of: {{this.enumText}}.{{/if}}
|
|
142
142
|
{{/each}}
|
|
143
143
|
{{/each}}
|
|
144
144
|
{{else}}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
"key": "campaign",
|
|
3
|
-
"name": "Campaign",
|
|
4
|
-
"goal": "Play a fifth-edition campaign: the Dungeon Master runs the world, the Battle Master runs fights, and the players play their characters.",
|
|
5
|
-
"turnMode": "directed",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
{
|
|
2
|
+
"key": "campaign",
|
|
3
|
+
"name": "Campaign",
|
|
4
|
+
"goal": "Play a fifth-edition campaign: the Dungeon Master runs the world, the Battle Master runs fights, and the players play their characters.",
|
|
5
|
+
"turnMode": "directed",
|
|
6
|
+
"imageModel": "FLUX.1 Kontext",
|
|
7
|
+
"illustrationMode": "on-request",
|
|
8
|
+
"agents": [
|
|
9
|
+
"table_moderator",
|
|
10
|
+
"dungeon_master",
|
|
11
|
+
"battle_master",
|
|
12
|
+
"character_creator",
|
|
13
|
+
"campaign_designer"
|
|
14
|
+
],
|
|
15
|
+
"roomLeader": "dungeon_master",
|
|
16
|
+
"moderator": "table_moderator",
|
|
17
|
+
"beginInstruction": "Session zero begins. The whole table is seated and waiting on you, and the roster is final. Follow your Before the first session procedure now."
|
|
18
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"key": "table",
|
|
3
|
-
"name": "D&D Table",
|
|
4
|
-
"goal": "Play a fifth-edition campaign: the Dungeon Master runs the world, the Battle Master runs fights, and the players play their characters.",
|
|
5
|
-
"turnMode": "directed",
|
|
6
|
-
"agents": [
|
|
7
|
-
"table_moderator",
|
|
8
|
-
"dungeon_master",
|
|
9
|
-
"battle_master",
|
|
10
|
-
"character_creator",
|
|
11
|
-
"campaign_designer",
|
|
12
|
-
"player"
|
|
13
|
-
],
|
|
14
|
-
"roomLeader": "dungeon_master",
|
|
15
|
-
"moderator": "table_moderator"
|
|
16
|
-
|
|
1
|
+
{
|
|
2
|
+
"key": "table",
|
|
3
|
+
"name": "D&D Table",
|
|
4
|
+
"goal": "Play a fifth-edition campaign: the Dungeon Master runs the world, the Battle Master runs fights, and the players play their characters.",
|
|
5
|
+
"turnMode": "directed",
|
|
6
|
+
"agents": [
|
|
7
|
+
"table_moderator",
|
|
8
|
+
"dungeon_master",
|
|
9
|
+
"battle_master",
|
|
10
|
+
"character_creator",
|
|
11
|
+
"campaign_designer",
|
|
12
|
+
"player"
|
|
13
|
+
],
|
|
14
|
+
"roomLeader": "dungeon_master",
|
|
15
|
+
"moderator": "table_moderator",
|
|
16
|
+
"beginInstruction": "Session zero begins. The whole table is seated and waiting on you, and the roster is final. Follow your Before the first session procedure now."
|
|
17
|
+
}
|
|
@@ -22,12 +22,115 @@ export declare class AnthropicAiService extends BaseAiService {
|
|
|
22
22
|
ttl?: undefined;
|
|
23
23
|
};
|
|
24
24
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Adds a message to the agent history in the Anthropic format
|
|
27
|
+
* @param agent The agent to add the message to
|
|
28
|
+
* @param message The formatted message to add
|
|
29
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
30
|
+
*/
|
|
25
31
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* How far past `maxHistoryMessages` history is allowed to grow before it is cut
|
|
34
|
+
* back — the hysteresis that decides how long a cached prefix survives.
|
|
35
|
+
*
|
|
36
|
+
* A trim drops messages off the front, which changes the prefix and forces the
|
|
37
|
+
* whole thing to be written again. Writing costs 2x the base input rate at a
|
|
38
|
+
* one-hour cache TTL and 1.25x at five minutes, against 0.1x to read, so the
|
|
39
|
+
* number of trims matters far more than the size of the window: a turn adds two
|
|
40
|
+
* messages, so N messages of headroom buys N/2 turns per write. Reads are cheap
|
|
41
|
+
* enough that headroom is worth roughly twice the window — carrying more messages
|
|
42
|
+
* costs a tenth per call, while trimming half as often saves a full write.
|
|
43
|
+
*
|
|
44
|
+
* A flat headroom punished exactly the agents built to be cheap. A moderator
|
|
45
|
+
* keeping 16 messages got 5 turns per write; over the sampled session that was
|
|
46
|
+
* 14 writes against 27 reads, and the writes were 90% of its input cost. Scaling
|
|
47
|
+
* the headroom to the window gives the same number of *turns* per write to every
|
|
48
|
+
* agent whatever its window, and never grants less headroom than the flat value
|
|
49
|
+
* it replaces.
|
|
50
|
+
*
|
|
51
|
+
* A trim is also the only thing that can cost an agent its cache entirely, because
|
|
52
|
+
* **a prefix below the model's minimum cacheable length is not cached at all** —
|
|
53
|
+
* silently, with no error and no metrics. That minimum is not ordered by model
|
|
54
|
+
* generation: Haiku 4.5 wants 4096 tokens where Sonnet wants 1024. An agent whose
|
|
55
|
+
* system prompt alone sits under its model's minimum has no system-level entry to
|
|
56
|
+
* fall back on however its blocks are marked, so its *whole* cache lives or dies
|
|
57
|
+
* with the windowed history — which is why a bigger window can be the cheaper
|
|
58
|
+
* setting even though every call then carries more tokens.
|
|
59
|
+
*
|
|
60
|
+
* With caching **off** there is nothing to protect and the headroom is zero: the
|
|
61
|
+
* whole point of carrying messages past the window is to leave a cached prefix
|
|
62
|
+
* undisturbed, so without a cache those extra messages are paid for at full rate
|
|
63
|
+
* on every call and bought nothing. Trim exactly at the window instead. The test
|
|
64
|
+
* is `promptCacheTTL === 0`, matching `getCacheConfig` — an *unset* TTL means
|
|
65
|
+
* caching is on with the default lifetime, not off.
|
|
66
|
+
*
|
|
67
|
+
* @param agent The agent whose history is about to be trimmed
|
|
68
|
+
* @returns Messages of headroom to allow past the agent's window
|
|
69
|
+
*/
|
|
26
70
|
private static trimHeadroom;
|
|
27
71
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Appends "here is what you said, now correct it" to a local messages array
|
|
74
|
+
* for a retry.
|
|
75
|
+
*
|
|
76
|
+
* The assistant turn is omitted when the response was blank, because the API
|
|
77
|
+
* rejects an empty text content block outright — `messages: text content
|
|
78
|
+
* blocks must be non-empty`, HTTP 400. Echoing an empty response back turned
|
|
79
|
+
* one recoverable parse failure into three hard failures and lost the agent's
|
|
80
|
+
* whole turn, so the shape that cannot be sent is never built.
|
|
81
|
+
* @param messages The in-flight messages array for this call, mutated in place
|
|
82
|
+
* @param responseText What the model said, possibly empty
|
|
83
|
+
* @param retryMessage The correction to send as the user turn
|
|
84
|
+
*/
|
|
28
85
|
private appendRetryExchange;
|
|
86
|
+
/**
|
|
87
|
+
* Computes the cost of a message with cache-aware pricing
|
|
88
|
+
* @returns The total cost in dollars
|
|
89
|
+
* @param agent
|
|
90
|
+
* @param usage
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* The web search tool definition for a given model.
|
|
94
|
+
*
|
|
95
|
+
* Two versions exist and the newer one is not universally accepted. It filters
|
|
96
|
+
* results **before** they reach the context window, which is the whole cost
|
|
97
|
+
* argument for preferring it — but only the models carrying
|
|
98
|
+
* `supports_web_search_filtering` in `model_prices.json` take it, and one that
|
|
99
|
+
* does not rejects the request outright. So the basic variant is the default:
|
|
100
|
+
* every model accepts it, and guessing wrong in that direction costs unfiltered
|
|
101
|
+
* results rather than a failed turn.
|
|
102
|
+
* @param modelInfo The model's price/capability entry, possibly absent
|
|
103
|
+
* @returns The tool definition to send
|
|
104
|
+
*/
|
|
29
105
|
private static webSearchTool;
|
|
106
|
+
/**
|
|
107
|
+
* How many times a single turn may be resumed after `pause_turn`.
|
|
108
|
+
*
|
|
109
|
+
* A backstop, not a budget: each resume re-sends a prompt the cache already
|
|
110
|
+
* holds, and the model is mid-task, so stopping early throws the work away. Five
|
|
111
|
+
* covers a long research turn; a model still searching after that is looping.
|
|
112
|
+
*/
|
|
30
113
|
private static readonly MAX_PAUSE_RESUMES;
|
|
114
|
+
/**
|
|
115
|
+
* Carries on a turn the server paused, and returns the response that finished it.
|
|
116
|
+
*
|
|
117
|
+
* A server-side tool — web search here — runs inside Anthropic's own sampling
|
|
118
|
+
* loop, and when that loop hits its iteration limit the turn comes back with
|
|
119
|
+
* `stop_reason: 'pause_turn'` and content ending in a `server_tool_use` block:
|
|
120
|
+
* no text, because the model has not got to its answer yet. The documented way
|
|
121
|
+
* to continue is to send the same request again with the assistant turn appended
|
|
122
|
+
* and **no** "carry on" message of our own — the server picks up where it left
|
|
123
|
+
* off. Treating that as a malformed response instead is how a campaign
|
|
124
|
+
* designer's turn died three times over while it was looking something up.
|
|
125
|
+
*
|
|
126
|
+
* The assistant content is appended **verbatim**, thinking blocks included: the
|
|
127
|
+
* API rejects a turn whose blocks have been edited, and this is the same model
|
|
128
|
+
* either way.
|
|
129
|
+
* @param agent The agent whose turn this is
|
|
130
|
+
* @param createParams The request being made, whose `messages` array is extended
|
|
131
|
+
* @param first The response that came back paused, or not
|
|
132
|
+
* @returns The response that finished the turn, or the last one if it kept pausing
|
|
133
|
+
*/
|
|
31
134
|
private resumePausedTurn;
|
|
32
135
|
private computeMessageCost;
|
|
33
136
|
}
|
|
@@ -31,7 +31,7 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
31
31
|
}
|
|
32
32
|
this.anthropic = new sdk_1.Anthropic({
|
|
33
33
|
apiKey: apiKey,
|
|
34
|
-
timeout: 1200000,
|
|
34
|
+
timeout: 1200000, // 20 minutes for very long requests (e.g., story imports, plot planning)
|
|
35
35
|
maxRetries: 3,
|
|
36
36
|
});
|
|
37
37
|
logger_1.logger.debug('Anthropic service initialized successfully');
|
|
@@ -43,6 +43,7 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
43
43
|
}
|
|
44
44
|
createAgent(userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
45
45
|
let agent = super.createAgent(userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir);
|
|
46
|
+
// Enable prompt caching by default for Anthropic agents
|
|
46
47
|
agent.promptCacheTTL = 5;
|
|
47
48
|
return agent;
|
|
48
49
|
}
|
|
@@ -66,7 +67,10 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
66
67
|
}
|
|
67
68
|
async fetchModelsFromApi() {
|
|
68
69
|
try {
|
|
70
|
+
// Use the Anthropic SDK's models.list() method to get available models
|
|
71
|
+
// This is documented in the API as anthropic.models.list({ ...params }) -> ModelInfosPage
|
|
69
72
|
const modelsResponse = await this.anthropic.models.list();
|
|
73
|
+
// Transform the response to match the expected format for our application
|
|
70
74
|
return modelsResponse.data.map((model) => ({
|
|
71
75
|
name: model.id,
|
|
72
76
|
description: model.id,
|
|
@@ -78,6 +82,12 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
78
82
|
logger_1.logger.error('Error fetching Anthropic models:', error);
|
|
79
83
|
}
|
|
80
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Adds a message to the agent history in the Anthropic format
|
|
87
|
+
* @param agent The agent to add the message to
|
|
88
|
+
* @param message The formatted message to add
|
|
89
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
90
|
+
*/
|
|
81
91
|
addToConversationHistory(agent, message, fromSelf = false) {
|
|
82
92
|
if (!agent.history) {
|
|
83
93
|
agent.history = [];
|
|
@@ -90,24 +100,67 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
90
100
|
});
|
|
91
101
|
agent.trimHistoryIfNeeded(AnthropicAiService_1.trimHeadroom(agent));
|
|
92
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* How far past `maxHistoryMessages` history is allowed to grow before it is cut
|
|
105
|
+
* back — the hysteresis that decides how long a cached prefix survives.
|
|
106
|
+
*
|
|
107
|
+
* A trim drops messages off the front, which changes the prefix and forces the
|
|
108
|
+
* whole thing to be written again. Writing costs 2x the base input rate at a
|
|
109
|
+
* one-hour cache TTL and 1.25x at five minutes, against 0.1x to read, so the
|
|
110
|
+
* number of trims matters far more than the size of the window: a turn adds two
|
|
111
|
+
* messages, so N messages of headroom buys N/2 turns per write. Reads are cheap
|
|
112
|
+
* enough that headroom is worth roughly twice the window — carrying more messages
|
|
113
|
+
* costs a tenth per call, while trimming half as often saves a full write.
|
|
114
|
+
*
|
|
115
|
+
* A flat headroom punished exactly the agents built to be cheap. A moderator
|
|
116
|
+
* keeping 16 messages got 5 turns per write; over the sampled session that was
|
|
117
|
+
* 14 writes against 27 reads, and the writes were 90% of its input cost. Scaling
|
|
118
|
+
* the headroom to the window gives the same number of *turns* per write to every
|
|
119
|
+
* agent whatever its window, and never grants less headroom than the flat value
|
|
120
|
+
* it replaces.
|
|
121
|
+
*
|
|
122
|
+
* A trim is also the only thing that can cost an agent its cache entirely, because
|
|
123
|
+
* **a prefix below the model's minimum cacheable length is not cached at all** —
|
|
124
|
+
* silently, with no error and no metrics. That minimum is not ordered by model
|
|
125
|
+
* generation: Haiku 4.5 wants 4096 tokens where Sonnet wants 1024. An agent whose
|
|
126
|
+
* system prompt alone sits under its model's minimum has no system-level entry to
|
|
127
|
+
* fall back on however its blocks are marked, so its *whole* cache lives or dies
|
|
128
|
+
* with the windowed history — which is why a bigger window can be the cheaper
|
|
129
|
+
* setting even though every call then carries more tokens.
|
|
130
|
+
*
|
|
131
|
+
* With caching **off** there is nothing to protect and the headroom is zero: the
|
|
132
|
+
* whole point of carrying messages past the window is to leave a cached prefix
|
|
133
|
+
* undisturbed, so without a cache those extra messages are paid for at full rate
|
|
134
|
+
* on every call and bought nothing. Trim exactly at the window instead. The test
|
|
135
|
+
* is `promptCacheTTL === 0`, matching `getCacheConfig` — an *unset* TTL means
|
|
136
|
+
* caching is on with the default lifetime, not off.
|
|
137
|
+
*
|
|
138
|
+
* @param agent The agent whose history is about to be trimmed
|
|
139
|
+
* @returns Messages of headroom to allow past the agent's window
|
|
140
|
+
*/
|
|
93
141
|
static trimHeadroom(agent) {
|
|
94
142
|
if (agent.promptCacheTTL === 0)
|
|
95
143
|
return 0;
|
|
96
144
|
return 2 * Math.max(10, agent.maxHistoryMessages ?? 0);
|
|
97
145
|
}
|
|
98
146
|
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheConfig = false, maxOutputChars = 0) {
|
|
147
|
+
// CHECK BALANCE BEFORE AI CALL (unless disabled)
|
|
99
148
|
if (agent.balanceService && !agent.disableBalanceCheck) {
|
|
100
149
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
101
150
|
if (!hasSufficientBalance) {
|
|
102
151
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
103
152
|
}
|
|
104
153
|
}
|
|
154
|
+
// Check if there are any attached files to include with this prompt
|
|
105
155
|
const attachedFiles = agent.attachedFiles.filter((file) => file.serviceMetadata?.fileData);
|
|
156
|
+
// Create individual messages for each attached document
|
|
106
157
|
let documentMessages = [];
|
|
158
|
+
// Build a separate message for each attached file
|
|
107
159
|
for (const file of attachedFiles) {
|
|
108
160
|
if (file.serviceMetadata?.fileData) {
|
|
109
161
|
const fileData = new Uint8Array(file.serviceMetadata.fileData);
|
|
110
162
|
let fileContent;
|
|
163
|
+
// Anthropic only supports PDFs as documents, text files need to be converted to text
|
|
111
164
|
if (file.mimeType === 'application/pdf') {
|
|
112
165
|
const base64Data = Buffer.from(fileData).toString('base64');
|
|
113
166
|
fileContent = {
|
|
@@ -120,21 +173,26 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
120
173
|
};
|
|
121
174
|
}
|
|
122
175
|
else {
|
|
176
|
+
// For text-based files (md, txt, etc.), convert to text
|
|
123
177
|
const textContent = Buffer.from(fileData).toString('utf-8');
|
|
124
178
|
fileContent = {
|
|
125
179
|
type: 'text',
|
|
126
180
|
text: `Attached file "${file.fileName}":\n\n${textContent}`,
|
|
127
181
|
};
|
|
128
182
|
}
|
|
183
|
+
// Each document becomes its own message
|
|
129
184
|
documentMessages.push({ role: 'user', content: [fileContent] });
|
|
130
185
|
}
|
|
131
186
|
}
|
|
187
|
+
// Handle attached artifacts
|
|
132
188
|
if (agent.attachedArtifacts && agent.attachedArtifacts.length > 0) {
|
|
133
189
|
for (const artifactId of agent.attachedArtifacts) {
|
|
134
190
|
const content = agent.artifactService.getArtifact(artifactId);
|
|
191
|
+
// Only include text artifacts (skip binary/image artifacts)
|
|
135
192
|
if (content && typeof content === 'string') {
|
|
136
193
|
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
137
194
|
const fileName = metadata ? `${metadata.name}.md` : 'artifact.md';
|
|
195
|
+
// Format as text content
|
|
138
196
|
const artifactMessage = {
|
|
139
197
|
role: 'user',
|
|
140
198
|
content: [
|
|
@@ -154,16 +212,27 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
154
212
|
documentMessages[documentMessages.length - 1].content.length > 0) {
|
|
155
213
|
documentMessages[documentMessages.length - 1].content[0]['cache_control'] = cacheConfig;
|
|
156
214
|
}
|
|
215
|
+
// Structured-output contract (the JSON schema instruction), if any.
|
|
157
216
|
let schemaInstruction = '';
|
|
158
217
|
if (jsonSchema) {
|
|
159
218
|
schemaInstruction =
|
|
160
219
|
'\n\nIMPORTANT: You MUST respond with ONLY valid JSON that conforms to the provided schema. Do not include any explanatory text, markdown formatting, or other content before or after the JSON. Your entire response should be parseable as JSON.\n\nJSON Schema:\n' +
|
|
161
220
|
JSON.stringify(jsonSchema, null, 2);
|
|
162
221
|
}
|
|
163
|
-
|
|
222
|
+
// Build system instruction with caching support.
|
|
223
|
+
//
|
|
224
|
+
// When prompt caching is enabled, keep the JSON schema OUT of the system block. The
|
|
225
|
+
// cacheable prefix is ordered system -> messages, so anything in the system block sits
|
|
226
|
+
// before the attached document; a schema that varies per call (e.g. multi-pass extraction
|
|
227
|
+
// over one cached page) would change that prefix every call and defeat the document cache.
|
|
228
|
+
// Instead, append the schema to the trailing prompt message (after the cached document) so
|
|
229
|
+
// the system + document prefix stays byte-identical across calls. Without caching, keep the
|
|
230
|
+
// schema in the system block (unchanged behavior).
|
|
231
|
+
let instructionText = promptInstructions || this.getSystemInstruction(agent);
|
|
164
232
|
if (jsonSchema && !cacheConfig) {
|
|
165
233
|
instructionText += schemaInstruction;
|
|
166
234
|
}
|
|
235
|
+
// Convert system instruction to a content block array with cache_control
|
|
167
236
|
const systemBlocks = [];
|
|
168
237
|
if (instructionText)
|
|
169
238
|
systemBlocks.push({ type: 'text', text: instructionText });
|
|
@@ -171,6 +240,8 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
171
240
|
type: 'text',
|
|
172
241
|
text: `Your agent identity is ${agent.agentName}: ${agent.description}`,
|
|
173
242
|
};
|
|
243
|
+
// Only attach cache_control when caching is actually enabled — Anthropic's API
|
|
244
|
+
// rejects cache_control: false (it expects an ephemeral object or omission).
|
|
174
245
|
if (cacheConfig) {
|
|
175
246
|
identityBlock.cache_control = cacheConfig;
|
|
176
247
|
}
|
|
@@ -183,6 +254,9 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
183
254
|
messageHistory[messageHistory.length - 1].content[0]['cache_control'] = cacheConfig;
|
|
184
255
|
}
|
|
185
256
|
const messages = [...documentMessages, ...messageHistory];
|
|
257
|
+
// Add the new text prompt as a simple, uncached text message. When caching is on, the
|
|
258
|
+
// JSON-schema contract rides on this trailing message (after the cached document) rather
|
|
259
|
+
// than in the system block — see the instruction-building note above.
|
|
186
260
|
if (prompt || (jsonSchema && cacheConfig)) {
|
|
187
261
|
const promptText = jsonSchema && cacheConfig ? (prompt || '') + schemaInstruction : prompt;
|
|
188
262
|
messages.push({
|
|
@@ -216,12 +290,22 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
216
290
|
let createParams = {
|
|
217
291
|
model: agent.modelName,
|
|
218
292
|
messages: messages,
|
|
219
|
-
system: systemBlocks,
|
|
293
|
+
system: systemBlocks, // Use content blocks array for caching
|
|
220
294
|
max_tokens: maxOutputTokens,
|
|
221
295
|
tools: tools.length > 0 ? tools : undefined,
|
|
222
296
|
};
|
|
223
297
|
if (modelInfo?.supports_adaptive_thinking) {
|
|
298
|
+
// Adaptive-thinking models (flagged by `supports_adaptive_thinking`
|
|
299
|
+
// in model_prices.json) reject `temperature`/`top_p`/`top_k` (any
|
|
300
|
+
// non-default value 400s) and the legacy `thinking.type` values
|
|
301
|
+
// "enabled"/"disabled". Use adaptive thinking with
|
|
302
|
+
// `output_config.effort` to control depth; omit `thinking`
|
|
303
|
+
// entirely when no effort was requested (the model then runs
|
|
304
|
+
// without thinking, which is also its default on these models).
|
|
224
305
|
if (agent.reasoningEffort) {
|
|
306
|
+
// These models omit thinking text by default (display defaults
|
|
307
|
+
// to "omitted") — request summarized thinking when AI debug
|
|
308
|
+
// logging is on, otherwise the THINKING log files would be empty.
|
|
225
309
|
createParams.thinking = ai_debug_logger_1.AiDebugLogger.isEnabled()
|
|
226
310
|
? { type: 'adaptive', display: 'summarized' }
|
|
227
311
|
: { type: 'adaptive' };
|
|
@@ -259,6 +343,13 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
259
343
|
this.debugLogThinking(agent.agentName, thinkingText);
|
|
260
344
|
this.debugLogResponse(agent.agentName, responseText);
|
|
261
345
|
if (!responseText.trim()) {
|
|
346
|
+
// A response can legitimately carry no text: a server-side tool
|
|
347
|
+
// call is a `server_tool_use` block, and every block that is
|
|
348
|
+
// neither thinking nor text is dropped by the loop above. Say what
|
|
349
|
+
// actually came back, because the retry path below can only report
|
|
350
|
+
// "empty" — which reads as a model failure and sent one agent into
|
|
351
|
+
// three rounds of being told it had said nothing while it was in
|
|
352
|
+
// the middle of a web search.
|
|
262
353
|
logger_1.logger.warn(`Empty text from ${agent.agentName}: stop_reason=${response.stop_reason}, blocks=[${(response.content || [])
|
|
263
354
|
.map((block) => block.type)
|
|
264
355
|
.join(', ')}]`);
|
|
@@ -267,26 +358,35 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
267
358
|
responseText = this.trimToJson(responseText);
|
|
268
359
|
}
|
|
269
360
|
let parsedResponse;
|
|
361
|
+
// If JSON response is expected, try to parse it
|
|
270
362
|
if (jsonSchema) {
|
|
271
363
|
try {
|
|
272
364
|
parsedResponse = this.parseStructuredResponse(responseText);
|
|
365
|
+
// Success! Add to history if saveResponse=true
|
|
273
366
|
if (saveResponse) {
|
|
367
|
+
// Add both the user message and assistant response to history
|
|
274
368
|
agent.addToConversationHistory(prompt, false);
|
|
275
369
|
agent.addToConversationHistory(responseText, true);
|
|
276
370
|
}
|
|
371
|
+
// If saveResponse=false, don't modify history at all
|
|
277
372
|
return parsedResponse;
|
|
278
373
|
}
|
|
279
374
|
catch (parseError) {
|
|
280
375
|
lastError = parseError;
|
|
281
376
|
const wasEmpty = !responseText.trim();
|
|
282
377
|
if (wasEmpty) {
|
|
378
|
+
// Distinguished from malformed JSON because the causes
|
|
379
|
+
// and the fixes differ: there is nothing to repair here,
|
|
380
|
+
// the model simply returned no text.
|
|
283
381
|
logger_1.logger.warn(`Empty response on attempt ${attempt}/${maxRetries}; the model returned no text content`);
|
|
284
382
|
}
|
|
285
383
|
else {
|
|
286
384
|
logger_1.logger.warn(`JSON parse attempt ${attempt}/${maxRetries} failed:`, parseError);
|
|
287
385
|
logger_1.logger.warn('Raw response:', responseText);
|
|
288
386
|
}
|
|
387
|
+
// For retries, we add the retry message to the local messages array
|
|
289
388
|
if (attempt < maxRetries) {
|
|
389
|
+
// Add a correction message for the retry
|
|
290
390
|
const retryMessage = wasEmpty
|
|
291
391
|
? 'Your previous response was empty. Respond with ONLY valid JSON conforming to the schema.'
|
|
292
392
|
: `Your previous response was not valid JSON. Please respond with ONLY valid JSON that can be parsed. No explanatory text, no markdown, no formatting - just pure JSON that conforms to the schema. Here was the parsing error: ${parseError.message}`;
|
|
@@ -295,21 +395,26 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
295
395
|
}
|
|
296
396
|
}
|
|
297
397
|
else {
|
|
398
|
+
// Text response - add to history if saveResponse=true
|
|
298
399
|
if (responseText.length > maxOutputChars && maxOutputChars > 0) {
|
|
400
|
+
// Add a correction message for the retry
|
|
299
401
|
const retryMessage = `Your previous response exceeded the character limit of ${maxOutputChars}. Please try again with a shorter response.`;
|
|
300
402
|
this.appendRetryExchange(messages, responseText, retryMessage);
|
|
301
403
|
}
|
|
302
404
|
else {
|
|
303
405
|
if (saveResponse) {
|
|
406
|
+
// Add both the user message and assistant response to history
|
|
304
407
|
agent.addToConversationHistory(prompt, false);
|
|
305
408
|
agent.addToConversationHistory(responseText, true);
|
|
306
409
|
}
|
|
410
|
+
// If saveResponse=false, don't modify history at all
|
|
307
411
|
return responseText;
|
|
308
412
|
}
|
|
309
413
|
}
|
|
310
414
|
}
|
|
311
415
|
catch (apiError) {
|
|
312
416
|
lastError = apiError;
|
|
417
|
+
// Don't retry on 404 — the model or resource doesn't exist
|
|
313
418
|
if (apiError.status === 404) {
|
|
314
419
|
const innerError = apiError.error?.error;
|
|
315
420
|
const errorType = innerError?.type ?? 'not_found_error';
|
|
@@ -318,12 +423,27 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
318
423
|
}
|
|
319
424
|
logger_1.logger.error(`API call attempt ${attempt}/${maxRetries} failed:`, apiError);
|
|
320
425
|
if (attempt < maxRetries) {
|
|
426
|
+
// Wait a bit before retrying API calls
|
|
321
427
|
await new Promise((resolve) => setTimeout(resolve, 1000 * attempt));
|
|
322
428
|
}
|
|
323
429
|
}
|
|
324
430
|
}
|
|
431
|
+
// If we get here, all retries failed
|
|
325
432
|
throw new Error(`Failed to get valid response after ${maxRetries} attempts. Last error: ${lastError?.message || 'Unknown error'}`);
|
|
326
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Appends "here is what you said, now correct it" to a local messages array
|
|
436
|
+
* for a retry.
|
|
437
|
+
*
|
|
438
|
+
* The assistant turn is omitted when the response was blank, because the API
|
|
439
|
+
* rejects an empty text content block outright — `messages: text content
|
|
440
|
+
* blocks must be non-empty`, HTTP 400. Echoing an empty response back turned
|
|
441
|
+
* one recoverable parse failure into three hard failures and lost the agent's
|
|
442
|
+
* whole turn, so the shape that cannot be sent is never built.
|
|
443
|
+
* @param messages The in-flight messages array for this call, mutated in place
|
|
444
|
+
* @param responseText What the model said, possibly empty
|
|
445
|
+
* @param retryMessage The correction to send as the user turn
|
|
446
|
+
*/
|
|
327
447
|
appendRetryExchange(messages, responseText, retryMessage) {
|
|
328
448
|
if (responseText.trim()) {
|
|
329
449
|
messages.push({
|
|
@@ -336,6 +456,25 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
336
456
|
content: [{ type: 'text', text: retryMessage }],
|
|
337
457
|
});
|
|
338
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Computes the cost of a message with cache-aware pricing
|
|
461
|
+
* @returns The total cost in dollars
|
|
462
|
+
* @param agent
|
|
463
|
+
* @param usage
|
|
464
|
+
*/
|
|
465
|
+
/**
|
|
466
|
+
* The web search tool definition for a given model.
|
|
467
|
+
*
|
|
468
|
+
* Two versions exist and the newer one is not universally accepted. It filters
|
|
469
|
+
* results **before** they reach the context window, which is the whole cost
|
|
470
|
+
* argument for preferring it — but only the models carrying
|
|
471
|
+
* `supports_web_search_filtering` in `model_prices.json` take it, and one that
|
|
472
|
+
* does not rejects the request outright. So the basic variant is the default:
|
|
473
|
+
* every model accepts it, and guessing wrong in that direction costs unfiltered
|
|
474
|
+
* results rather than a failed turn.
|
|
475
|
+
* @param modelInfo The model's price/capability entry, possibly absent
|
|
476
|
+
* @returns The tool definition to send
|
|
477
|
+
*/
|
|
339
478
|
static webSearchTool(modelInfo) {
|
|
340
479
|
return {
|
|
341
480
|
type: modelInfo?.supports_web_search_filtering
|
|
@@ -345,7 +484,34 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
345
484
|
max_uses: 5,
|
|
346
485
|
};
|
|
347
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* How many times a single turn may be resumed after `pause_turn`.
|
|
489
|
+
*
|
|
490
|
+
* A backstop, not a budget: each resume re-sends a prompt the cache already
|
|
491
|
+
* holds, and the model is mid-task, so stopping early throws the work away. Five
|
|
492
|
+
* covers a long research turn; a model still searching after that is looping.
|
|
493
|
+
*/
|
|
348
494
|
static MAX_PAUSE_RESUMES = 5;
|
|
495
|
+
/**
|
|
496
|
+
* Carries on a turn the server paused, and returns the response that finished it.
|
|
497
|
+
*
|
|
498
|
+
* A server-side tool — web search here — runs inside Anthropic's own sampling
|
|
499
|
+
* loop, and when that loop hits its iteration limit the turn comes back with
|
|
500
|
+
* `stop_reason: 'pause_turn'` and content ending in a `server_tool_use` block:
|
|
501
|
+
* no text, because the model has not got to its answer yet. The documented way
|
|
502
|
+
* to continue is to send the same request again with the assistant turn appended
|
|
503
|
+
* and **no** "carry on" message of our own — the server picks up where it left
|
|
504
|
+
* off. Treating that as a malformed response instead is how a campaign
|
|
505
|
+
* designer's turn died three times over while it was looking something up.
|
|
506
|
+
*
|
|
507
|
+
* The assistant content is appended **verbatim**, thinking blocks included: the
|
|
508
|
+
* API rejects a turn whose blocks have been edited, and this is the same model
|
|
509
|
+
* either way.
|
|
510
|
+
* @param agent The agent whose turn this is
|
|
511
|
+
* @param createParams The request being made, whose `messages` array is extended
|
|
512
|
+
* @param first The response that came back paused, or not
|
|
513
|
+
* @returns The response that finished the turn, or the last one if it kept pausing
|
|
514
|
+
*/
|
|
349
515
|
async resumePausedTurn(agent, createParams, first) {
|
|
350
516
|
let response = first;
|
|
351
517
|
for (let resume = 1; response?.stop_reason === 'pause_turn'; resume++) {
|
|
@@ -372,22 +538,27 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
|
|
|
372
538
|
const cacheReadTokens = usage.cache_read_input_tokens || 0;
|
|
373
539
|
const standardInputTokens = usage.input_tokens || 0;
|
|
374
540
|
const outputTokens = usage.output_tokens || 0;
|
|
541
|
+
// Calculate cache-aware costs
|
|
375
542
|
const standardCost = standardInputTokens * modelInfo.input_cost_per_token;
|
|
376
543
|
const cacheCreationCost = cacheCreationTokens *
|
|
377
544
|
(modelInfo.cache_creation_input_token_cost || modelInfo.input_cost_per_token * 1.25);
|
|
378
545
|
const cacheReadCost = cacheReadTokens *
|
|
379
546
|
(modelInfo.cache_read_input_token_cost || modelInfo.input_cost_per_token * 0.1);
|
|
380
547
|
const outputCost = outputTokens * modelInfo.output_cost_per_token;
|
|
548
|
+
// Markup only Anthropic output costs (unless disabled)
|
|
381
549
|
const markup = agent.disableMarkup ? 0 : outputCost * agent.markupRate;
|
|
382
550
|
const cost = standardCost + cacheCreationCost + cacheReadCost + outputCost + markup;
|
|
551
|
+
// Add all input tokens to total count
|
|
383
552
|
agent.totalInputTokens += standardInputTokens + cacheCreationTokens + cacheReadTokens;
|
|
384
553
|
agent.totalOutputTokens += outputTokens;
|
|
385
554
|
agent.totalCost += cost;
|
|
386
555
|
agent.totalMarkup += markup;
|
|
387
556
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost.toFixed(4)}, markup: ${markup.toFixed(4)}`);
|
|
557
|
+
// DECREMENT BALANCE AFTER CALL
|
|
388
558
|
if (agent.balanceService && cost > 0) {
|
|
389
559
|
agent.balanceService.decrementBalance(cost, markup);
|
|
390
560
|
}
|
|
561
|
+
// Log cache metrics for monitoring
|
|
391
562
|
if (cacheCreationTokens > 0 || cacheReadTokens > 0) {
|
|
392
563
|
logger_1.logger.log(`Cache metrics for ${agent.agentName}: creation=${cacheCreationTokens}, read=${cacheReadTokens}, standard=${standardInputTokens}`);
|
|
393
564
|
}
|