briyah 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -7
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
- package/dist-sdk/server/src/ai/agent.d.ts +196 -0
- package/dist-sdk/server/src/ai/agent.js +224 -11
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +38 -1
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +87 -0
- package/dist-sdk/server/src/app.controller.js +272 -12
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1661 -0
- package/dist-sdk/server/src/app.service.js +1837 -4
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +26 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
- package/dist-sdk/server/src/room/room-factory.js +14 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +176 -0
- package/dist-sdk/server/src/room/room-store.service.js +238 -5
- package/dist-sdk/server/src/room/room.d.ts +878 -0
- package/dist-sdk/server/src/room/room.js +1291 -23
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +103 -0
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +398 -0
- package/dist-sdk/server/src/story/story.service.js +829 -25
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +22 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +176 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +116 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
- package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +285 -13
- package/dist-sdk/shared/types/app.types.js +3 -0
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -11,9 +11,63 @@ export interface WorkflowValues {
|
|
|
11
11
|
height: number;
|
|
12
12
|
refImage?: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Directory holding the shipped workflow templates. Lives under
|
|
16
|
+
* common/config so it is covered by the SDK's seedCommonData() copy of the
|
|
17
|
+
* config subdir. Reads BRIYAH_DATA_PATH directly (same convention as
|
|
18
|
+
* model_prices.ts) because listing happens with no user context.
|
|
19
|
+
*/
|
|
14
20
|
export declare function getCommonWorkflowsDir(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves a workflow template file for a pair name and variant, checking the
|
|
23
|
+
* user's override directory first, then the common directory.
|
|
24
|
+
* @returns Full path to the template file, or null when neither exists
|
|
25
|
+
*/
|
|
15
26
|
export declare function resolveWorkflowFile(pairName: string, variant: WorkflowVariant, userPaths?: UserPathsService): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Scans the common workflows directory for template pairs. A pair is any base
|
|
29
|
+
* name with at least one of `<name>.t2i.json` / `<name>.edit.json`.
|
|
30
|
+
* User-directory-only pairs are not listed (there is no user context at
|
|
31
|
+
* model-list time) but still resolve at generation time.
|
|
32
|
+
*/
|
|
16
33
|
export declare function listWorkflowPairs(): WorkflowPair[];
|
|
34
|
+
/**
|
|
35
|
+
* Loads and parses a workflow template file.
|
|
36
|
+
* @throws When the file cannot be read or parsed
|
|
37
|
+
*/
|
|
17
38
|
export declare function loadWorkflowTemplate(filePath: string): any;
|
|
39
|
+
/**
|
|
40
|
+
* Substitutes placeholder tokens in a parsed workflow template.
|
|
41
|
+
*
|
|
42
|
+
* Token semantics:
|
|
43
|
+
* - A string value that is exactly "{{seed}}", "{{width}}" or "{{height}}" is
|
|
44
|
+
* replaced with the corresponding number (ComfyUI validates input types).
|
|
45
|
+
* - A string value that is exactly "{{ref_image}}" is replaced with the
|
|
46
|
+
* uploaded reference filename.
|
|
47
|
+
* - Any other string has "{{prompt}}" (and "{{ref_image}}") occurrences
|
|
48
|
+
* substring-replaced, so templates may wrap the prompt, e.g.
|
|
49
|
+
* "masterpiece, {{prompt}}, cinematic".
|
|
50
|
+
*
|
|
51
|
+
* Unrecognized {{...}} tokens are warned about but left in place — ComfyUI's
|
|
52
|
+
* own validation will surface them if they matter.
|
|
53
|
+
*
|
|
54
|
+
* @returns A patched deep copy; the input object is not modified
|
|
55
|
+
*/
|
|
18
56
|
export declare function patchWorkflow(templateJson: any, values: WorkflowValues): any;
|
|
57
|
+
/**
|
|
58
|
+
* Extends an edit workflow with additional reference images by chaining
|
|
59
|
+
* ReferenceLatent nodes — the ComfyUI analog of the hosted Kontext multi
|
|
60
|
+
* endpoints, where the model conditions on each reference separately.
|
|
61
|
+
*
|
|
62
|
+
* Convention required of the template: exactly one ReferenceLatent node,
|
|
63
|
+
* whose latent comes from a VAEEncode fed (possibly via single-image
|
|
64
|
+
* processing nodes like FluxKontextImageScale) by a LoadImage. For each
|
|
65
|
+
* extra reference the LoadImage→...→VAEEncode chain is cloned and a new
|
|
66
|
+
* ReferenceLatent is appended to the conditioning chain; consumers of the
|
|
67
|
+
* original ReferenceLatent output are rewired to the last one.
|
|
68
|
+
*
|
|
69
|
+
* @param workflow A patched workflow (first reference already in place)
|
|
70
|
+
* @param extraRefImages Uploaded filenames for references 2..N, in order
|
|
71
|
+
* @returns A modified deep copy; the input workflow is not changed
|
|
72
|
+
*/
|
|
19
73
|
export declare function chainReferenceImages(workflow: any, extraRefImages: string[]): any;
|
|
@@ -43,6 +43,12 @@ const fs = __importStar(require("fs"));
|
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
44
|
const logger_1 = require("../../common/logger");
|
|
45
45
|
const WORKFLOWS_SUBDIR = 'comfyui-workflows';
|
|
46
|
+
/**
|
|
47
|
+
* Directory holding the shipped workflow templates. Lives under
|
|
48
|
+
* common/config so it is covered by the SDK's seedCommonData() copy of the
|
|
49
|
+
* config subdir. Reads BRIYAH_DATA_PATH directly (same convention as
|
|
50
|
+
* model_prices.ts) because listing happens with no user context.
|
|
51
|
+
*/
|
|
46
52
|
function getCommonWorkflowsDir() {
|
|
47
53
|
const dataDir = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'briyah-data');
|
|
48
54
|
return path.join(dataDir, 'common', 'config', WORKFLOWS_SUBDIR);
|
|
@@ -50,6 +56,11 @@ function getCommonWorkflowsDir() {
|
|
|
50
56
|
function getUserWorkflowsDir(userPaths) {
|
|
51
57
|
return path.join(userPaths.getUserDataDir(), WORKFLOWS_SUBDIR);
|
|
52
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolves a workflow template file for a pair name and variant, checking the
|
|
61
|
+
* user's override directory first, then the common directory.
|
|
62
|
+
* @returns Full path to the template file, or null when neither exists
|
|
63
|
+
*/
|
|
53
64
|
function resolveWorkflowFile(pairName, variant, userPaths) {
|
|
54
65
|
const fileName = `${pairName}.${variant}.json`;
|
|
55
66
|
const searchPaths = [];
|
|
@@ -64,6 +75,12 @@ function resolveWorkflowFile(pairName, variant, userPaths) {
|
|
|
64
75
|
}
|
|
65
76
|
return null;
|
|
66
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Scans the common workflows directory for template pairs. A pair is any base
|
|
80
|
+
* name with at least one of `<name>.t2i.json` / `<name>.edit.json`.
|
|
81
|
+
* User-directory-only pairs are not listed (there is no user context at
|
|
82
|
+
* model-list time) but still resolve at generation time.
|
|
83
|
+
*/
|
|
67
84
|
function listWorkflowPairs() {
|
|
68
85
|
const dir = getCommonWorkflowsDir();
|
|
69
86
|
if (!fs.existsSync(dir)) {
|
|
@@ -83,10 +100,31 @@ function listWorkflowPairs() {
|
|
|
83
100
|
.map(([name, variants]) => ({ name, variants: [...variants] }))
|
|
84
101
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
85
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Loads and parses a workflow template file.
|
|
105
|
+
* @throws When the file cannot be read or parsed
|
|
106
|
+
*/
|
|
86
107
|
function loadWorkflowTemplate(filePath) {
|
|
87
108
|
const raw = fs.readFileSync(filePath, 'utf8');
|
|
88
109
|
return JSON.parse(raw);
|
|
89
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Substitutes placeholder tokens in a parsed workflow template.
|
|
113
|
+
*
|
|
114
|
+
* Token semantics:
|
|
115
|
+
* - A string value that is exactly "{{seed}}", "{{width}}" or "{{height}}" is
|
|
116
|
+
* replaced with the corresponding number (ComfyUI validates input types).
|
|
117
|
+
* - A string value that is exactly "{{ref_image}}" is replaced with the
|
|
118
|
+
* uploaded reference filename.
|
|
119
|
+
* - Any other string has "{{prompt}}" (and "{{ref_image}}") occurrences
|
|
120
|
+
* substring-replaced, so templates may wrap the prompt, e.g.
|
|
121
|
+
* "masterpiece, {{prompt}}, cinematic".
|
|
122
|
+
*
|
|
123
|
+
* Unrecognized {{...}} tokens are warned about but left in place — ComfyUI's
|
|
124
|
+
* own validation will surface them if they matter.
|
|
125
|
+
*
|
|
126
|
+
* @returns A patched deep copy; the input object is not modified
|
|
127
|
+
*/
|
|
90
128
|
function patchWorkflow(templateJson, values) {
|
|
91
129
|
const numericTokens = {
|
|
92
130
|
'{{seed}}': values.seed,
|
|
@@ -126,6 +164,22 @@ function patchWorkflow(templateJson, values) {
|
|
|
126
164
|
}
|
|
127
165
|
return patched;
|
|
128
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Extends an edit workflow with additional reference images by chaining
|
|
169
|
+
* ReferenceLatent nodes — the ComfyUI analog of the hosted Kontext multi
|
|
170
|
+
* endpoints, where the model conditions on each reference separately.
|
|
171
|
+
*
|
|
172
|
+
* Convention required of the template: exactly one ReferenceLatent node,
|
|
173
|
+
* whose latent comes from a VAEEncode fed (possibly via single-image
|
|
174
|
+
* processing nodes like FluxKontextImageScale) by a LoadImage. For each
|
|
175
|
+
* extra reference the LoadImage→...→VAEEncode chain is cloned and a new
|
|
176
|
+
* ReferenceLatent is appended to the conditioning chain; consumers of the
|
|
177
|
+
* original ReferenceLatent output are rewired to the last one.
|
|
178
|
+
*
|
|
179
|
+
* @param workflow A patched workflow (first reference already in place)
|
|
180
|
+
* @param extraRefImages Uploaded filenames for references 2..N, in order
|
|
181
|
+
* @returns A modified deep copy; the input workflow is not changed
|
|
182
|
+
*/
|
|
129
183
|
function chainReferenceImages(workflow, extraRefImages) {
|
|
130
184
|
if (extraRefImages.length === 0)
|
|
131
185
|
return workflow;
|
|
@@ -146,6 +200,8 @@ function chainReferenceImages(workflow, extraRefImages) {
|
|
|
146
200
|
throw new Error(`Expected the ReferenceLatent latent input to come from a VAEEncode node, ` +
|
|
147
201
|
`found '${vaeEncode?.class_type}'.`);
|
|
148
202
|
}
|
|
203
|
+
// Walk from VAEEncode.pixels back to the LoadImage, collecting any
|
|
204
|
+
// single-image processing nodes in between (e.g. FluxKontextImageScale).
|
|
149
205
|
const middleChain = [];
|
|
150
206
|
let cursor = String(vaeEncode.inputs.pixels?.[0]);
|
|
151
207
|
while (result[cursor] && result[cursor].class_type !== 'LoadImage') {
|
|
@@ -160,7 +216,8 @@ function chainReferenceImages(workflow, extraRefImages) {
|
|
|
160
216
|
if (!result[cursor]) {
|
|
161
217
|
throw new Error('Could not find the LoadImage node feeding the ReferenceLatent chain.');
|
|
162
218
|
}
|
|
163
|
-
middleChain.reverse();
|
|
219
|
+
middleChain.reverse(); // now ordered LoadImage side → VAEEncode side
|
|
220
|
+
// Snapshot consumers of the original ReferenceLatent output before adding clones
|
|
164
221
|
const consumers = [];
|
|
165
222
|
for (const nodeId of Object.keys(result)) {
|
|
166
223
|
const inputs = result[nodeId].inputs ?? {};
|
|
@@ -196,6 +253,7 @@ function chainReferenceImages(workflow, extraRefImages) {
|
|
|
196
253
|
};
|
|
197
254
|
lastRefLatentId = newRefLatentId;
|
|
198
255
|
}
|
|
256
|
+
// Rewire the original consumers to the end of the chain
|
|
199
257
|
for (const { nodeId, inputKey } of consumers) {
|
|
200
258
|
result[nodeId].inputs[inputKey] = [lastRefLatentId, 0];
|
|
201
259
|
}
|
|
@@ -7,8 +7,17 @@ export declare class ComfyUiAiService extends BaseAiService {
|
|
|
7
7
|
getServiceName(): string;
|
|
8
8
|
supportsImageGeneration(): boolean;
|
|
9
9
|
requiresKnownModel(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Model names are workflow-template pair names discovered on disk (one
|
|
12
|
+
* ModelInfo per `<name>.t2i.json`/`<name>.edit.json` pair in the common
|
|
13
|
+
* workflows directory). The ComfyUI server itself is not queried.
|
|
14
|
+
*/
|
|
10
15
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
11
|
-
textPrompt(_agent: Agent, _prompt: string, _jsonSchema?: any,
|
|
16
|
+
textPrompt(_agent: Agent, _prompt: string, _jsonSchema?: any, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
17
|
+
_saveResponse?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
18
|
+
_promptInstructions?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
19
|
+
_cacheConfig?: any, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
|
+
_maxOutputChars?: number): Promise<any>;
|
|
12
21
|
generateImage(agent: Agent, prompt: string, imageProperties?: Record<string, any>): Promise<{
|
|
13
22
|
artifactId?: string;
|
|
14
23
|
error?: any;
|
|
@@ -17,10 +26,21 @@ export declare class ComfyUiAiService extends BaseAiService {
|
|
|
17
26
|
artifactId?: string;
|
|
18
27
|
error?: any;
|
|
19
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Balance gate, applied only when the image actually costs something.
|
|
31
|
+
* Self-hosted generation ships with centsPerImage 0 and stays usable at
|
|
32
|
+
* zero balance.
|
|
33
|
+
*/
|
|
20
34
|
private checkBalance;
|
|
21
35
|
private prepareWorkflow;
|
|
22
36
|
private runWorkflow;
|
|
23
37
|
private computeImageCost;
|
|
38
|
+
/**
|
|
39
|
+
* Loads reference artifacts as buffers, failing loudly on any missing or
|
|
40
|
+
* non-image artifact. The base loadReferenceImages() silently drops
|
|
41
|
+
* missing entries, which would break the positional Image-N contract the
|
|
42
|
+
* story prompts rely on.
|
|
43
|
+
*/
|
|
24
44
|
private loadReferenceBuffers;
|
|
25
45
|
private buildMultiRefPreamble;
|
|
26
46
|
}
|
|
@@ -59,6 +59,11 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
|
|
|
59
59
|
requiresKnownModel() {
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Model names are workflow-template pair names discovered on disk (one
|
|
64
|
+
* ModelInfo per `<name>.t2i.json`/`<name>.edit.json` pair in the common
|
|
65
|
+
* workflows directory). The ComfyUI server itself is not queried.
|
|
66
|
+
*/
|
|
62
67
|
async fetchModelsFromApi() {
|
|
63
68
|
return (0, comfyui_workflow_1.listWorkflowPairs)().map((pair) => ({
|
|
64
69
|
name: pair.name,
|
|
@@ -67,7 +72,11 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
|
|
|
67
72
|
service: 'ComfyUI',
|
|
68
73
|
}));
|
|
69
74
|
}
|
|
70
|
-
async textPrompt(_agent, _prompt, _jsonSchema = null,
|
|
75
|
+
async textPrompt(_agent, _prompt, _jsonSchema = null, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
76
|
+
_saveResponse = true, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
77
|
+
_promptInstructions = null, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
78
|
+
_cacheConfig = null, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
79
|
+
_maxOutputChars = 0) {
|
|
71
80
|
throw new Error('ComfyUI agents are image-generation only. Use generateImage/editImage, ' +
|
|
72
81
|
'or choose a text provider for chat agents.');
|
|
73
82
|
}
|
|
@@ -103,6 +112,10 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
|
|
|
103
112
|
if (balanceError)
|
|
104
113
|
throw balanceError;
|
|
105
114
|
const references = this.loadReferenceBuffers(agent, referenceImageArtifactIds);
|
|
115
|
+
// Each reference is uploaded and conditioned on separately via a
|
|
116
|
+
// chained ReferenceLatent node — the ComfyUI analog of the hosted
|
|
117
|
+
// Kontext multi-image endpoints. Order is preserved so the
|
|
118
|
+
// prompt's "Image k" references map to the k-th upload.
|
|
106
119
|
const refImages = [];
|
|
107
120
|
for (const reference of references) {
|
|
108
121
|
const uploaded = await this.client.uploadImage(reference.buffer, `briyah-ref-${(0, crypto_1.randomUUID)()}.png`);
|
|
@@ -129,6 +142,11 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
|
|
|
129
142
|
return { error };
|
|
130
143
|
}
|
|
131
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Balance gate, applied only when the image actually costs something.
|
|
147
|
+
* Self-hosted generation ships with centsPerImage 0 and stays usable at
|
|
148
|
+
* zero balance.
|
|
149
|
+
*/
|
|
132
150
|
checkBalance(agent, centsPerImage) {
|
|
133
151
|
if (!centsPerImage || centsPerImage <= 0)
|
|
134
152
|
return null;
|
|
@@ -166,6 +184,12 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
|
|
|
166
184
|
agent.balanceService.decrementBalance(cost, 0);
|
|
167
185
|
}
|
|
168
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Loads reference artifacts as buffers, failing loudly on any missing or
|
|
189
|
+
* non-image artifact. The base loadReferenceImages() silently drops
|
|
190
|
+
* missing entries, which would break the positional Image-N contract the
|
|
191
|
+
* story prompts rely on.
|
|
192
|
+
*/
|
|
169
193
|
loadReferenceBuffers(agent, artifactIds) {
|
|
170
194
|
const references = [];
|
|
171
195
|
for (const artifactId of artifactIds) {
|
|
@@ -8,10 +8,62 @@ export declare class DeepSeekAiService extends BaseAiService {
|
|
|
8
8
|
getServiceName(): string;
|
|
9
9
|
getModelPricePrefix(): string;
|
|
10
10
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Adds a message to the agent history in the DeepSeek format
|
|
13
|
+
* @param agent The agent to add the message to
|
|
14
|
+
* @param message The formatted message to add
|
|
15
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
16
|
+
*/
|
|
11
17
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
|
|
18
|
+
/**
|
|
19
|
+
* Salvages a response the schema rejected but Briyah can still use.
|
|
20
|
+
*
|
|
21
|
+
* This service is the only one that *validates* against the prompt's JSON
|
|
22
|
+
* schema: `generateObject` converts it to Zod and throws
|
|
23
|
+
* `AI_NoObjectGeneratedError` on any mismatch. Every other provider does a
|
|
24
|
+
* lenient `JSON.parse`, so a response that merely omits a field reaches
|
|
25
|
+
* `Room.parseAgentResponse` — which is itself defensive, requiring `name` only
|
|
26
|
+
* for an EXECUTE and moderating anything it cannot read.
|
|
27
|
+
*
|
|
28
|
+
* The schemas therefore claim fields are required that Briyah does not require —
|
|
29
|
+
* `name` has to stay in `required` because OpenAI rejects a schema whose
|
|
30
|
+
* `required` omits any property. A response that merely leaves one out is
|
|
31
|
+
* perfectly usable, and discarding it loses the agent's whole turn.
|
|
32
|
+
*
|
|
33
|
+
* So a validation failure is downgraded to a warning and the unvalidated object
|
|
34
|
+
* is used. A response that is not JSON at all still throws — `value` is absent
|
|
35
|
+
* and the text will not parse, which is a genuinely unusable answer rather than
|
|
36
|
+
* a strict-schema quibble.
|
|
37
|
+
* @param agent The agent whose turn this was, for the log line
|
|
38
|
+
* @param error The error `generateObject` threw
|
|
39
|
+
* @returns The salvaged object and the usage to bill, or null to rethrow
|
|
40
|
+
*/
|
|
12
41
|
private recoverUnvalidatedObject;
|
|
42
|
+
/**
|
|
43
|
+
* The most specific message inside a validation failure's cause chain.
|
|
44
|
+
*
|
|
45
|
+
* `AI_NoObjectGeneratedError` wraps `AI_TypeValidationError` wraps `ZodError`,
|
|
46
|
+
* and only the innermost one says which field was wrong — which is the whole
|
|
47
|
+
* value of the log line.
|
|
48
|
+
* @param error The thrown error
|
|
49
|
+
* @returns A one-line description, truncated
|
|
50
|
+
*/
|
|
13
51
|
private static describeValidationFailure;
|
|
14
52
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* Attaches a document to the agent or as a shared document
|
|
55
|
+
* @param agent The agent context (null for shared documents)
|
|
56
|
+
* @param fileName The name of the file
|
|
57
|
+
* @param fileData The file data as a Uint8Array
|
|
58
|
+
* @returns Promise with the result
|
|
59
|
+
*/
|
|
15
60
|
attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Compute the cost of a message with markup and cache-aware pricing for DeepSeek
|
|
63
|
+
* DeepSeek provides a 74-75% discount on cached tokens (no cache creation charge)
|
|
64
|
+
* Handles model name lookup with deepseek/ prefix if needed
|
|
65
|
+
* @param agent The agent making the request
|
|
66
|
+
* @param usage Usage object from the API response
|
|
67
|
+
*/
|
|
16
68
|
private computeMessageCost;
|
|
17
69
|
}
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.DeepSeekAiService = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const deepseek_1 = require("@ai-sdk/deepseek");
|
|
16
|
+
// Aliased: `textPrompt`'s own parameter is called `jsonSchema` and would shadow it.
|
|
16
17
|
const ai_1 = require("ai");
|
|
17
18
|
const jsonrepair_1 = require("jsonrepair");
|
|
18
19
|
const base_ai_service_1 = require("./base-ai.service");
|
|
@@ -76,6 +77,12 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
76
77
|
throw error;
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Adds a message to the agent history in the DeepSeek format
|
|
82
|
+
* @param agent The agent to add the message to
|
|
83
|
+
* @param message The formatted message to add
|
|
84
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
85
|
+
*/
|
|
79
86
|
addToConversationHistory(agent, message, fromSelf = false) {
|
|
80
87
|
if (!agent.history) {
|
|
81
88
|
agent.history = [];
|
|
@@ -88,9 +95,34 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
88
95
|
});
|
|
89
96
|
agent.trimHistoryIfNeeded();
|
|
90
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Salvages a response the schema rejected but Briyah can still use.
|
|
100
|
+
*
|
|
101
|
+
* This service is the only one that *validates* against the prompt's JSON
|
|
102
|
+
* schema: `generateObject` converts it to Zod and throws
|
|
103
|
+
* `AI_NoObjectGeneratedError` on any mismatch. Every other provider does a
|
|
104
|
+
* lenient `JSON.parse`, so a response that merely omits a field reaches
|
|
105
|
+
* `Room.parseAgentResponse` — which is itself defensive, requiring `name` only
|
|
106
|
+
* for an EXECUTE and moderating anything it cannot read.
|
|
107
|
+
*
|
|
108
|
+
* The schemas therefore claim fields are required that Briyah does not require —
|
|
109
|
+
* `name` has to stay in `required` because OpenAI rejects a schema whose
|
|
110
|
+
* `required` omits any property. A response that merely leaves one out is
|
|
111
|
+
* perfectly usable, and discarding it loses the agent's whole turn.
|
|
112
|
+
*
|
|
113
|
+
* So a validation failure is downgraded to a warning and the unvalidated object
|
|
114
|
+
* is used. A response that is not JSON at all still throws — `value` is absent
|
|
115
|
+
* and the text will not parse, which is a genuinely unusable answer rather than
|
|
116
|
+
* a strict-schema quibble.
|
|
117
|
+
* @param agent The agent whose turn this was, for the log line
|
|
118
|
+
* @param error The error `generateObject` threw
|
|
119
|
+
* @returns The salvaged object and the usage to bill, or null to rethrow
|
|
120
|
+
*/
|
|
91
121
|
recoverUnvalidatedObject(agent, error) {
|
|
92
122
|
if (!ai_1.NoObjectGeneratedError.isInstance(error))
|
|
93
123
|
return null;
|
|
124
|
+
// `value` — the object the SDK parsed before Zod refused it — is on the
|
|
125
|
+
// error at runtime but absent from its published type.
|
|
94
126
|
let object = error.value;
|
|
95
127
|
if (object === undefined && error.text) {
|
|
96
128
|
try {
|
|
@@ -106,6 +138,15 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
106
138
|
`Keys returned: ${Object.keys(object).join(', ')}. ${DeepSeekAiService_1.describeValidationFailure(error)}`);
|
|
107
139
|
return { object, usage: error.usage };
|
|
108
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* The most specific message inside a validation failure's cause chain.
|
|
143
|
+
*
|
|
144
|
+
* `AI_NoObjectGeneratedError` wraps `AI_TypeValidationError` wraps `ZodError`,
|
|
145
|
+
* and only the innermost one says which field was wrong — which is the whole
|
|
146
|
+
* value of the log line.
|
|
147
|
+
* @param error The thrown error
|
|
148
|
+
* @returns A one-line description, truncated
|
|
149
|
+
*/
|
|
109
150
|
static describeValidationFailure(error) {
|
|
110
151
|
let current = error;
|
|
111
152
|
let message = '';
|
|
@@ -117,17 +158,26 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
117
158
|
const flattened = message.replace(/\s+/g, ' ').trim();
|
|
118
159
|
return flattened.length > 300 ? `${flattened.slice(0, 300)}…` : flattened;
|
|
119
160
|
}
|
|
120
|
-
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
161
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
|
+
_cacheConfig = null, maxOutputChars = 0) {
|
|
164
|
+
// CHECK BALANCE BEFORE AI CALL (unless disabled)
|
|
121
165
|
if (agent.balanceService && !agent.disableBalanceCheck) {
|
|
122
166
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
123
167
|
if (!hasSufficientBalance) {
|
|
124
168
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
125
169
|
}
|
|
126
170
|
}
|
|
171
|
+
// Build messages array locally without modifying agent.history yet
|
|
127
172
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
128
173
|
const instructions = promptInstructions || agent.systemInstruction;
|
|
174
|
+
// The instructions go in the `system` option rather than as a leading
|
|
175
|
+
// system message. The SDK warns about the latter because a system turn
|
|
176
|
+
// sitting in `messages` is indistinguishable from one a model was talked
|
|
177
|
+
// into emitting, and this agent's `messages` are largely player text.
|
|
129
178
|
const messages = [];
|
|
130
179
|
messages.push({ role: 'user', content: identity });
|
|
180
|
+
// Add attached files as text (DeepSeek doesn't support document types)
|
|
131
181
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
132
182
|
for (const file of agent.attachedFiles) {
|
|
133
183
|
if (file.serviceMetadata?.fileData) {
|
|
@@ -140,12 +190,15 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
140
190
|
}
|
|
141
191
|
}
|
|
142
192
|
}
|
|
193
|
+
// Handle attached artifacts
|
|
143
194
|
if (agent.attachedArtifacts && agent.attachedArtifacts.length > 0) {
|
|
144
195
|
for (const artifactId of agent.attachedArtifacts) {
|
|
145
196
|
const content = agent.artifactService.getArtifact(artifactId);
|
|
197
|
+
// Only include text artifacts (skip binary/image artifacts)
|
|
146
198
|
if (content && typeof content === 'string') {
|
|
147
199
|
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
148
200
|
const fileName = metadata ? `${metadata.name}.md` : 'artifact.md';
|
|
201
|
+
// Add as user message
|
|
149
202
|
messages.push({
|
|
150
203
|
role: 'user',
|
|
151
204
|
content: `Attached document: ${fileName}\n\n${content}`,
|
|
@@ -153,7 +206,9 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
153
206
|
}
|
|
154
207
|
}
|
|
155
208
|
}
|
|
209
|
+
// Add conversation history
|
|
156
210
|
messages.push(...agent.history);
|
|
211
|
+
// Add the new text prompt as a simple text message
|
|
157
212
|
if (prompt) {
|
|
158
213
|
messages.push({
|
|
159
214
|
role: 'user',
|
|
@@ -170,16 +225,30 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
170
225
|
};
|
|
171
226
|
this.debugLogRequest(agent.agentName, requestParams);
|
|
172
227
|
try {
|
|
228
|
+
// Use AI SDK to generate response
|
|
173
229
|
if (jsonSchema) {
|
|
174
230
|
let object;
|
|
175
231
|
let usage;
|
|
176
232
|
try {
|
|
233
|
+
// Generate structured output with schema
|
|
177
234
|
const result = await (0, ai_1.generateObject)({
|
|
178
235
|
model: this.deepseekClient(agent.modelName),
|
|
179
236
|
system: instructions || undefined,
|
|
180
|
-
messages: messages,
|
|
237
|
+
messages: messages, // Use local messages array
|
|
181
238
|
temperature: 0,
|
|
239
|
+
// The prompt's JSON Schema, passed through as-is rather than
|
|
240
|
+
// converted to Zod. DeepSeek has no server-side schema
|
|
241
|
+
// enforcement, so the SDK injects the schema into the system
|
|
242
|
+
// message — which makes the field `description`s the actual
|
|
243
|
+
// instruction the model reads, and a Zod conversion drops
|
|
244
|
+
// them along with `additionalProperties` and nested
|
|
245
|
+
// `required`.
|
|
182
246
|
schema: (0, ai_1.jsonSchema)(jsonSchema),
|
|
247
|
+
// Repair malformed JSON before the SDK parses it. Models
|
|
248
|
+
// routinely emit unescaped quotes (e.g. an inch mark like
|
|
249
|
+
// 5'6") or stray control characters that break a strict
|
|
250
|
+
// parse; jsonrepair fixes these so a single bad character
|
|
251
|
+
// doesn't discard the whole response.
|
|
183
252
|
experimental_repairText: async ({ text }) => {
|
|
184
253
|
try {
|
|
185
254
|
return (0, jsonrepair_1.jsonrepair)(text);
|
|
@@ -204,21 +273,27 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
204
273
|
object = recovered.object;
|
|
205
274
|
usage = recovered.usage;
|
|
206
275
|
}
|
|
276
|
+
// Track token usage including cache-specific metrics. Also runs on
|
|
277
|
+
// the recovered path — the tokens were spent either way, and
|
|
278
|
+
// skipping it billed the caller nothing for a call they paid for.
|
|
207
279
|
if (usage) {
|
|
208
280
|
this.computeMessageCost(agent, usage);
|
|
209
281
|
}
|
|
210
282
|
this.debugLogResponse(agent.agentName, JSON.stringify(object, null, 2));
|
|
283
|
+
// Only modify agent.history if saveResponse=true
|
|
211
284
|
if (saveResponse) {
|
|
212
285
|
this.addToConversationHistory(agent, prompt, false);
|
|
213
286
|
this.addToConversationHistory(agent, JSON.stringify(object), true);
|
|
214
287
|
}
|
|
288
|
+
// If saveResponse=false, don't modify history at all
|
|
215
289
|
return object;
|
|
216
290
|
}
|
|
217
291
|
else {
|
|
292
|
+
// Generate text response
|
|
218
293
|
const result = await (0, ai_1.generateText)({
|
|
219
294
|
model: this.deepseekClient(agent.modelName),
|
|
220
295
|
system: instructions || undefined,
|
|
221
|
-
messages: messages,
|
|
296
|
+
messages: messages, // Use local messages array
|
|
222
297
|
temperature: 0,
|
|
223
298
|
providerOptions: {
|
|
224
299
|
deepseek: {
|
|
@@ -226,15 +301,19 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
226
301
|
},
|
|
227
302
|
},
|
|
228
303
|
});
|
|
304
|
+
// Track token usage including cache-specific metrics
|
|
229
305
|
if (result.usage) {
|
|
230
306
|
this.computeMessageCost(agent, result.usage);
|
|
231
307
|
}
|
|
308
|
+
// result.reasoning is populated for deepseek-reasoner models
|
|
232
309
|
this.debugLogThinking(agent.agentName, result.reasoning ?? '');
|
|
233
310
|
this.debugLogResponse(agent.agentName, result.text);
|
|
311
|
+
// Only modify agent.history if saveResponse=true
|
|
234
312
|
if (saveResponse) {
|
|
235
313
|
this.addToConversationHistory(agent, prompt, false);
|
|
236
314
|
this.addToConversationHistory(agent, result.text, true);
|
|
237
315
|
}
|
|
316
|
+
// If saveResponse=false, don't modify history at all
|
|
238
317
|
return result.text;
|
|
239
318
|
}
|
|
240
319
|
}
|
|
@@ -244,17 +323,32 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
244
323
|
throw error;
|
|
245
324
|
}
|
|
246
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Attaches a document to the agent or as a shared document
|
|
328
|
+
* @param agent The agent context (null for shared documents)
|
|
329
|
+
* @param fileName The name of the file
|
|
330
|
+
* @param fileData The file data as a Uint8Array
|
|
331
|
+
* @returns Promise with the result
|
|
332
|
+
*/
|
|
247
333
|
async attachDocument(agent, fileName, fileData) {
|
|
248
334
|
if (agent === null) {
|
|
249
335
|
throw new Error('Shared document attachment not supported by the DeepSeek service');
|
|
250
336
|
}
|
|
251
337
|
return super.attachDocument(agent, fileName, fileData);
|
|
252
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Compute the cost of a message with markup and cache-aware pricing for DeepSeek
|
|
341
|
+
* DeepSeek provides a 74-75% discount on cached tokens (no cache creation charge)
|
|
342
|
+
* Handles model name lookup with deepseek/ prefix if needed
|
|
343
|
+
* @param agent The agent making the request
|
|
344
|
+
* @param usage Usage object from the API response
|
|
345
|
+
*/
|
|
253
346
|
computeMessageCost(agent, usage) {
|
|
254
347
|
const totalInputTokens = usage.inputTokens || 0;
|
|
255
348
|
const cachedTokens = usage.cachedInputTokens || 0;
|
|
256
349
|
const uncachedInputTokens = totalInputTokens - cachedTokens;
|
|
257
350
|
const outputTokens = usage.outputTokens || 0;
|
|
351
|
+
// Try to find model with current name, then try with deepseek/ prefix
|
|
258
352
|
let modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
259
353
|
if (!modelInfo && !agent.modelName.startsWith('deepseek/')) {
|
|
260
354
|
modelInfo = (0, model_prices_1.getModelPrices)()[`deepseek/${agent.modelName}`];
|
|
@@ -263,20 +357,25 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
263
357
|
logger_1.logger.error(`No price info found for model ${agent.modelName} or deepseek/${agent.modelName}`);
|
|
264
358
|
return;
|
|
265
359
|
}
|
|
360
|
+
// Calculate cache-aware costs (DeepSeek: 75% discount on cached)
|
|
266
361
|
const uncachedCost = uncachedInputTokens * modelInfo.input_cost_per_token;
|
|
267
362
|
const cachedCost = cachedTokens *
|
|
268
363
|
(modelInfo.cache_read_input_token_cost || modelInfo.input_cost_per_token * 0.25);
|
|
269
364
|
const outputCost = outputTokens * modelInfo.output_cost_per_token;
|
|
365
|
+
// Calculate markup: 2x output cost only (unless disabled)
|
|
270
366
|
const markup = agent.disableMarkup ? 0 : outputCost * agent.markupRate;
|
|
271
367
|
const cost = uncachedCost + cachedCost + outputCost + markup;
|
|
368
|
+
// Update agent totals
|
|
272
369
|
agent.totalInputTokens += totalInputTokens;
|
|
273
370
|
agent.totalOutputTokens += outputTokens;
|
|
274
371
|
agent.totalCost += cost;
|
|
275
372
|
agent.totalMarkup += markup;
|
|
276
373
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
374
|
+
// Log cache metrics for monitoring
|
|
277
375
|
if (cachedTokens > 0) {
|
|
278
376
|
logger_1.logger.log(`Cache metrics for ${agent.agentName}: cached=${cachedTokens}, uncached=${uncachedInputTokens}`);
|
|
279
377
|
}
|
|
378
|
+
// Decrement balance with markup
|
|
280
379
|
if (agent.balanceService && cost > 0) {
|
|
281
380
|
agent.balanceService.decrementBalance(cost, markup);
|
|
282
381
|
}
|
|
@@ -7,9 +7,34 @@ export declare class FalAiService extends BaseAiService {
|
|
|
7
7
|
getModelPricePrefix(): string;
|
|
8
8
|
supportsImageGeneration(): boolean;
|
|
9
9
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
12
|
+
* @param agent The agent to add the message to
|
|
13
|
+
* @param message The formatted message to add
|
|
14
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
15
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
16
|
+
*/
|
|
10
17
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
|
|
11
18
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Compute the cost of a text message with markup for Fal AI
|
|
21
|
+
* Handles model name lookup with fal_ai/ prefix if needed
|
|
22
|
+
* @param agent The agent making the request
|
|
23
|
+
* @param usage Usage object from the API response (or estimated)
|
|
24
|
+
* @param estimatedInputTokens Fallback estimate if usage not provided
|
|
25
|
+
* @param estimatedOutputTokens Fallback estimate if usage not provided
|
|
26
|
+
*/
|
|
12
27
|
private computeMessageCost;
|
|
28
|
+
/**
|
|
29
|
+
* Generates an image from a text prompt with optional reference images
|
|
30
|
+
* @param agent The agent making the request
|
|
31
|
+
* @param prompt Text description of the image to generate
|
|
32
|
+
* @param width
|
|
33
|
+
* @param height
|
|
34
|
+
* @param quality
|
|
35
|
+
* @param referenceImageArtifactIds Optional array of artifact IDs containing reference images
|
|
36
|
+
* @returns Promise resolving to JSON string with { artifactId }
|
|
37
|
+
*/
|
|
13
38
|
private computeImageCost;
|
|
14
39
|
generateImage(agent: Agent, prompt: string, imageProperties?: Record<string, any>): Promise<{
|
|
15
40
|
artifactId?: string;
|