briyah 2.0.2 → 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/LICENSE +216 -0
- package/README.md +43 -7
- 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/prompts/narrator/create_story.prompt +2 -0
- package/data/packs/dnd5e/agents/player.json +11 -11
- package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
- package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
- 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 +1662 -0
- package/dist-sdk/server/src/app.service.js +1862 -6
- 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 +27 -0
- package/dist-sdk/server/src/room/nickname.js +41 -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 +177 -0
- package/dist-sdk/server/src/room/room-store.service.js +242 -5
- package/dist-sdk/server/src/room/room.d.ts +906 -1
- package/dist-sdk/server/src/room/room.js +1525 -34
- 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 +38 -3
- package/dist-sdk/server/src/rpg/rpg-roster.js +49 -49
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -5
- 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.d.ts +0 -1
- package/dist-sdk/server/src/sdk/index.js +24 -3
- 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 +25 -0
- package/dist-sdk/server/src/tools/core/index.js +31 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +10 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +72 -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 +186 -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 +125 -1
- 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 +52 -2
- package/dist-sdk/server/src/tools/packs/index.js +83 -9
- 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 -14
- package/dist-sdk/shared/types/app.types.js +3 -0
- package/package.json +167 -139
- 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/data/packs/acts/agents/character-guide.json +0 -6
- package/data/packs/acts/agents/discipleship-mentor.json +0 -6
- package/data/packs/acts/agents/mentor-coach.json +0 -6
- package/data/packs/acts/agents/student.json +0 -13
- package/data/packs/acts/agents/table-moderator.json +0 -6
- package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
- package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
- package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
- package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
- package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
- package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
- package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
- package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
- package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
- package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
- package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
- package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
- package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
- package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
- package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
- package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
- package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
- package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
- package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
- package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
- package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
- package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
- package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
- package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
- package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
- package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
- package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
- package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
- package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
- package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
- package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
- package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
- package/data/packs/acts/artifacts/manifest.json +0 -197
- package/data/packs/acts/artifacts/stage-guide.md +0 -94
- package/data/packs/acts/pack.json +0 -6
- package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
- package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
- package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
- package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
- package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
- package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
- package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
- package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
- package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
- package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
- package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
- package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
- package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
- package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
- package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
- package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
- package/data/packs/acts/rooms/session.json +0 -14
- package/data/packs/acts/rooms/training.json +0 -58
- package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
- package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
- package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
- 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 -1338
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/actsTools.html +0 -44
- 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 -48
- 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 -3337
- 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 -227
- 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
|
@@ -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
|
}
|
|
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).
|
|
163
231
|
let instructionText = promptInstructions || agent.systemInstruction;
|
|
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
|
}
|
|
@@ -9,43 +9,212 @@ export declare class BaseAiService {
|
|
|
9
9
|
protected modelsCache: ModelInfo[];
|
|
10
10
|
protected _isAvailable: boolean;
|
|
11
11
|
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Returns whether this service is available for use
|
|
14
|
+
* This is typically false if the service failed to initialize (e.g., missing API key)
|
|
15
|
+
*/
|
|
12
16
|
get isAvailable(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the name of this service type
|
|
19
|
+
* @returns The service type name
|
|
20
|
+
*/
|
|
13
21
|
getServiceName(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Provider prefix used when looking up model pricing in model_prices.json.
|
|
24
|
+
* Override in services that use prefixed keys (e.g. `deepseek/`, `xai/`,
|
|
25
|
+
* `together_ai/`, `fal_ai/`). Default is no prefix — the raw model name is
|
|
26
|
+
* expected to match a key directly.
|
|
27
|
+
*/
|
|
14
28
|
getModelPricePrefix(): string | null;
|
|
15
29
|
supportsImageGeneration(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether createAgent() must find the model in model_prices.json /
|
|
32
|
+
* image_models.json before an agent can be created. Services whose model
|
|
33
|
+
* names are deployment-specific and have no marginal cost (Mock,
|
|
34
|
+
* self-hosted providers) override this to return false.
|
|
35
|
+
*/
|
|
16
36
|
requiresKnownModel(): boolean;
|
|
17
37
|
supportsPromptCaching(): boolean;
|
|
18
38
|
getCacheConfig(_agent: Agent, _cacheMessage: boolean): any;
|
|
19
39
|
stripQuotes(quotedText: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Finds a prompt file using the shared lookup order.
|
|
42
|
+
*
|
|
43
|
+
* For a bare folder that is the historical four levels — user/folder,
|
|
44
|
+
* user/root, common/folder, common/root — plus the folders of any pack the
|
|
45
|
+
* agent's owner has enabled. For a pack-qualified folder (`dnd5e:battle_master`)
|
|
46
|
+
* it is the pack's own tiers, then the shared roots. See `prompt-resolver.ts`.
|
|
47
|
+
*
|
|
48
|
+
* @param agent The agent context
|
|
49
|
+
* @param fileName The prompt file name without extension
|
|
50
|
+
* @param extension The file extension (e.g., '.prompt' or '.json')
|
|
51
|
+
* @returns The full path to the file, or null if not found
|
|
52
|
+
*/
|
|
20
53
|
protected findPromptFile(agent: Agent, fileName: string, extension: string): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Whether a prompt file resolves for this agent, without reading or compiling it.
|
|
56
|
+
*
|
|
57
|
+
* Lets a caller find out that {@link getPreparedPrompt} would throw before
|
|
58
|
+
* committing to a call — used to tell an agent that can run a given kind of turn
|
|
59
|
+
* from one whose prompt folder simply does not have that prompt.
|
|
60
|
+
*
|
|
61
|
+
* @param agent The agent whose prompt folder is searched
|
|
62
|
+
* @param fileName The prompt file name without extension
|
|
63
|
+
* @param extension The file extension, defaulting to `.prompt`
|
|
64
|
+
*/
|
|
21
65
|
hasPromptFile(agent: Agent, fileName: string, extension?: string): boolean;
|
|
22
66
|
getPreparedPrompt(agent: Agent, promptFileName: string, variables: any): string;
|
|
23
67
|
protected getPreparedSchema(agent: Agent, promptFileName: string): any;
|
|
68
|
+
/**
|
|
69
|
+
* Lists available models from the AI service
|
|
70
|
+
* Uses cached results if available, otherwise queries the API
|
|
71
|
+
* @returns Promise with model information
|
|
72
|
+
*/
|
|
24
73
|
listModels(): Promise<ModelInfo[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Actual implementation to fetch models from the API
|
|
76
|
+
* This should be overridden by subclasses
|
|
77
|
+
* @returns Promise with model information
|
|
78
|
+
*/
|
|
25
79
|
protected fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates an agent with the AI service
|
|
82
|
+
* @param userPaths User paths service for prompt and data directories
|
|
83
|
+
* @param configService Environment-variable configuration service
|
|
84
|
+
* @param agentStoreService
|
|
85
|
+
* @param balanceService
|
|
86
|
+
* @param artifactService
|
|
87
|
+
* @param agentName Name of the agent
|
|
88
|
+
* @param description
|
|
89
|
+
* @param promptFolder Directory name containing prompts
|
|
90
|
+
* @param modelName Name of the model to use
|
|
91
|
+
* @param storageDir
|
|
92
|
+
* @returns A new Agent instance
|
|
93
|
+
*/
|
|
26
94
|
createAgent(userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string): Agent;
|
|
27
|
-
|
|
28
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Sends a text prompt to the AI service
|
|
97
|
+
* @param agent The agent context
|
|
98
|
+
* @param prompt The text prompt
|
|
99
|
+
* @param _jsonSchema
|
|
100
|
+
* @param _saveResponse
|
|
101
|
+
* @param _promptInstructions
|
|
102
|
+
* @param _cacheConfig
|
|
103
|
+
* @param _maxOutputChars
|
|
104
|
+
* @returns The AI response
|
|
105
|
+
*/
|
|
106
|
+
textPrompt(agent: Agent, prompt: string, _jsonSchema?: any, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
107
|
+
_saveResponse?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
108
|
+
_promptInstructions?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
109
|
+
_cacheConfig?: any, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
110
|
+
_maxOutputChars?: number): Promise<any>;
|
|
111
|
+
/**
|
|
112
|
+
* Generates an image from a text prompt with optional reference images
|
|
113
|
+
* @param agent The agent making the request
|
|
114
|
+
* @param prompt Text description of the image to generate
|
|
115
|
+
* @param width
|
|
116
|
+
* @param height
|
|
117
|
+
* @param quality
|
|
118
|
+
* @param referenceImageArtifactIds Optional array of artifact IDs containing reference images
|
|
119
|
+
* @param options Optional generation parameters (size, quality, format)
|
|
120
|
+
* @returns Promise resolving to JSON string with { url, artifactId }
|
|
121
|
+
*/
|
|
122
|
+
generateImage(_agent: Agent, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
123
|
+
_prompt: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
124
|
+
_imageProperties?: Record<string, any>): Promise<{
|
|
29
125
|
artifactId?: string;
|
|
30
126
|
error?: any;
|
|
31
127
|
}>;
|
|
32
|
-
editImage(_agent: Agent,
|
|
128
|
+
editImage(_agent: Agent, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
129
|
+
_prompt: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
130
|
+
_imageProperties?: Record<string, any>, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
131
|
+
_referenceImageArtifactIds?: string[]): Promise<{
|
|
33
132
|
artifactId?: string;
|
|
34
133
|
error?: any;
|
|
35
134
|
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Helper: Load reference images from artifacts
|
|
137
|
+
*/
|
|
36
138
|
protected loadReferenceImages(agent: Agent, artifactIds: string[]): Promise<File[]>;
|
|
139
|
+
/**
|
|
140
|
+
* Helper: Save image from base64 data as artifact
|
|
141
|
+
*/
|
|
37
142
|
protected saveImageAsArtifact(agent: Agent, base64Data: string, prompt: string): Promise<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Processes a prepared prompt with the AI service
|
|
145
|
+
* @param agent The agent context
|
|
146
|
+
* @param promptFileName Name of the prompt file
|
|
147
|
+
* @param variables Variables to use in the prompt template
|
|
148
|
+
* @param saveResponse Whether to save the response in the agent history
|
|
149
|
+
* @param cacheConfig
|
|
150
|
+
* @returns The AI response as a parsed JSON object
|
|
151
|
+
*/
|
|
38
152
|
preparedPrompt(agent: Agent, promptFileName: string, variables: any, saveResponse?: boolean, cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
39
153
|
instructedPrompt(agent: Agent, prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
154
|
+
/**
|
|
155
|
+
* Attaches a document to the agent or as a shared document
|
|
156
|
+
* @param agent The agent context (null for shared documents)
|
|
157
|
+
* @param fileName The name of the file
|
|
158
|
+
* @param fileData The file data as a Uint8Array
|
|
159
|
+
* @returns Promise with a human-readable success message
|
|
160
|
+
*/
|
|
40
161
|
attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
|
|
162
|
+
/**
|
|
163
|
+
* Finishes an agent and cleans up resources
|
|
164
|
+
* @param agent The agent to finish
|
|
165
|
+
*/
|
|
41
166
|
finishAgent(_agent: Agent): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
169
|
+
* @param agent The agent to add the message to
|
|
170
|
+
* @param message The formatted message to add
|
|
171
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
172
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
173
|
+
*/
|
|
42
174
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
|
|
175
|
+
/**
|
|
176
|
+
* Trims a string to extract JSON content
|
|
177
|
+
* @param str The string to trim
|
|
178
|
+
* @returns The trimmed string containing only JSON
|
|
179
|
+
*/
|
|
180
|
+
/**
|
|
181
|
+
* Formats a message from the agent's history in a human-readable way
|
|
182
|
+
* @param message The message object from the agent's history
|
|
183
|
+
* @returns A formatted string representation of the message
|
|
184
|
+
*/
|
|
43
185
|
formatMessage(message: any): string;
|
|
44
186
|
protected debugLogRequest(agentName: string, content: unknown): void;
|
|
187
|
+
/** Only writes a file when content is non-empty (no-op for non-reasoning models). */
|
|
45
188
|
protected debugLogThinking(agentName: string, thinking: string): void;
|
|
46
189
|
protected debugLogResponse(agentName: string, response: string): void;
|
|
190
|
+
/**
|
|
191
|
+
* The provider's own account of a refused call, as a single log line.
|
|
192
|
+
*
|
|
193
|
+
* `logger` renders its extra arguments with `JSON.stringify`, and an Error
|
|
194
|
+
* stringifies to `{}` — so passing a caught error as an argument logs nothing
|
|
195
|
+
* at all. The status code and response body that say *why* a call was refused
|
|
196
|
+
* live on the AI SDK's `APICallError`, so they have to be read off explicitly
|
|
197
|
+
* and interpolated into the message itself.
|
|
198
|
+
* @param error The error a generate call threw
|
|
199
|
+
* @returns A one-line description, with the response body truncated
|
|
200
|
+
*/
|
|
47
201
|
protected static describeProviderError(error: unknown): string;
|
|
48
202
|
trimResponseText(str: string): string;
|
|
49
203
|
trimToJson(str: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* Parses a model's JSON response into an object, tolerating the encoding
|
|
206
|
+
* mistakes models routinely make. Tries a strict JSON.parse first; on
|
|
207
|
+
* failure it runs the text through jsonrepair, which fixes unescaped quotes
|
|
208
|
+
* (e.g. an inch mark like 5'6" inside a string), literal control
|
|
209
|
+
* characters, trailing commas, and similar issues — then parses again.
|
|
210
|
+
*
|
|
211
|
+
* This is the single place every provider should turn raw model text into
|
|
212
|
+
* a structured object, so a single stray character never discards an
|
|
213
|
+
* otherwise-valid response.
|
|
214
|
+
*
|
|
215
|
+
* @param text Raw (already trimmed-to-JSON) model output.
|
|
216
|
+
* @returns The parsed object.
|
|
217
|
+
* @throws The original parse error if the text cannot be recovered.
|
|
218
|
+
*/
|
|
50
219
|
parseStructuredResponse(text: string): any;
|
|
51
220
|
}
|