briyah 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -8
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/config/story_models.json +3 -3
- package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/data/common/prompts/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/rooms/campaign.json +18 -15
- package/data/packs/dnd5e/rooms/table.json +17 -16
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +174 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +194 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +299 -19
- package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
- package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +103 -4
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +56 -2
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +43 -2
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +55 -3
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +81 -3
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +45 -3
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +61 -3
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -1
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -7
- package/dist-sdk/server/src/ai/agent.d.ts +197 -2
- package/dist-sdk/server/src/ai/agent.js +225 -14
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +46 -3
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +120 -0
- package/dist-sdk/server/src/app.controller.js +365 -14
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1710 -4
- package/dist-sdk/server/src/app.service.js +1938 -20
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +44 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +104 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +114 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +69 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +84 -1
- package/dist-sdk/server/src/room/room-config.js +19 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +20 -0
- package/dist-sdk/server/src/room/room-factory.js +25 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +184 -0
- package/dist-sdk/server/src/room/room-store.service.js +280 -6
- package/dist-sdk/server/src/room/room.d.ts +981 -1
- package/dist-sdk/server/src/room/room.js +1531 -27
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -1
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +366 -9
- package/dist-sdk/server/src/story/story.service.js +825 -374
- package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +24 -1
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +266 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +201 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +149 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +194 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +263 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +127 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +107 -3
- package/dist-sdk/server/src/tools/tool-execution.service.js +163 -19
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +328 -13
- package/dist-sdk/shared/types/app.types.js +18 -1
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -44,6 +44,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
async fetchModelsFromApi() {
|
|
47
|
+
// Try to fetch models from API, fall back to curated list
|
|
47
48
|
try {
|
|
48
49
|
const response = await this.googleAI.models.list();
|
|
49
50
|
return response.page.map((model) => {
|
|
@@ -60,6 +61,12 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
60
61
|
logger_1.logger.warn('Could not fetch models from Google AI API, using fallback list:', error.message);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Adds a message to the agent history in Google AI format
|
|
66
|
+
* @param agent The agent to add the message to
|
|
67
|
+
* @param message The formatted message to add
|
|
68
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
69
|
+
*/
|
|
63
70
|
addToConversationHistory(agent, message, fromSelf = false) {
|
|
64
71
|
if (!agent.history) {
|
|
65
72
|
agent.history = [];
|
|
@@ -72,15 +79,20 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
72
79
|
});
|
|
73
80
|
agent.trimHistoryIfNeeded();
|
|
74
81
|
}
|
|
75
|
-
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
82
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
84
|
+
_cacheConfig = null, maxOutputChars = 0) {
|
|
85
|
+
// CHECK BALANCE BEFORE AI CALL (unless disabled)
|
|
76
86
|
if (agent.balanceService && !agent.disableBalanceCheck) {
|
|
77
87
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
78
88
|
if (!hasSufficientBalance) {
|
|
79
89
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
80
90
|
}
|
|
81
91
|
}
|
|
92
|
+
// Build messages array
|
|
82
93
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
83
94
|
const messages = [{ role: 'user', parts: [{ text: identity }] }];
|
|
95
|
+
// Add attached files as text (Google AI supports native file uploads, but we'll use text for simplicity)
|
|
84
96
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
85
97
|
for (const file of agent.attachedFiles) {
|
|
86
98
|
if (file.serviceMetadata?.fileData) {
|
|
@@ -93,23 +105,29 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
93
105
|
}
|
|
94
106
|
}
|
|
95
107
|
}
|
|
108
|
+
// Add conversation history
|
|
96
109
|
messages.push(...agent.history);
|
|
110
|
+
// Add user prompt
|
|
97
111
|
if (prompt) {
|
|
98
112
|
messages.push({
|
|
99
113
|
role: 'user',
|
|
100
114
|
parts: [{ text: prompt }],
|
|
101
115
|
});
|
|
102
116
|
}
|
|
117
|
+
// Configure generation
|
|
103
118
|
const generationConfig = {
|
|
104
119
|
maxOutputTokens: 8192,
|
|
105
120
|
temperature: 0,
|
|
106
121
|
};
|
|
122
|
+
// Add JSON schema if provided
|
|
107
123
|
if (jsonSchema) {
|
|
108
124
|
generationConfig.responseMimeType = 'application/json';
|
|
125
|
+
// Remove properties that aren't part of the schema spec
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
109
127
|
const { name: _name, description: _description, ...schemaOnly } = jsonSchema;
|
|
110
128
|
generationConfig.responseSchema = schemaOnly;
|
|
111
129
|
}
|
|
112
|
-
const instructions = promptInstructions || agent
|
|
130
|
+
const instructions = promptInstructions || this.getSystemInstruction(agent);
|
|
113
131
|
const requestParams = {
|
|
114
132
|
model: agent.modelName,
|
|
115
133
|
contents: messages,
|
|
@@ -122,6 +140,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
122
140
|
let responseText;
|
|
123
141
|
try {
|
|
124
142
|
const response = await this.googleAI.models.generateContent(requestParams);
|
|
143
|
+
// Extract response text
|
|
125
144
|
if (response.text) {
|
|
126
145
|
responseText = response.text;
|
|
127
146
|
}
|
|
@@ -131,6 +150,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
131
150
|
else {
|
|
132
151
|
responseText = '';
|
|
133
152
|
}
|
|
153
|
+
// Trim response
|
|
134
154
|
if (jsonSchema) {
|
|
135
155
|
responseText = this.trimToJson(responseText);
|
|
136
156
|
}
|
|
@@ -138,6 +158,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
138
158
|
responseText = this.trimResponseText(responseText);
|
|
139
159
|
}
|
|
140
160
|
this.debugLogResponse(agent.agentName, responseText);
|
|
161
|
+
// Track token usage
|
|
141
162
|
if (response.usageMetadata) {
|
|
142
163
|
this.computeMessageCost(agent, response.usageMetadata);
|
|
143
164
|
}
|
|
@@ -146,6 +167,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
146
167
|
logger_1.logger.error('Error calling Google AI:', error);
|
|
147
168
|
throw error;
|
|
148
169
|
}
|
|
170
|
+
// Only modify agent.history if saveResponse=true
|
|
149
171
|
if (saveResponse) {
|
|
150
172
|
this.addToConversationHistory(agent, prompt, false);
|
|
151
173
|
this.addToConversationHistory(agent, responseText, true);
|
|
@@ -192,6 +214,11 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
192
214
|
return { error };
|
|
193
215
|
}
|
|
194
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Compute the cost of a message with markup
|
|
219
|
+
* @param agent The agent making the request
|
|
220
|
+
* @param usage Usage metadata object
|
|
221
|
+
*/
|
|
195
222
|
computeMessageCost(agent, usage) {
|
|
196
223
|
const inputTokens = usage.promptTokenCount || 0;
|
|
197
224
|
const outputTokens = usage.candidatesTokenCount || 0;
|
|
@@ -202,17 +229,25 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
202
229
|
}
|
|
203
230
|
const inputCost = inputTokens * modelInfo.input_cost_per_token;
|
|
204
231
|
const outputCost = outputTokens * modelInfo.output_cost_per_token;
|
|
232
|
+
// Calculate markup: 2x output cost (unless disabled)
|
|
205
233
|
const markup = agent.disableMarkup ? 0 : outputCost * agent.markupRate;
|
|
206
234
|
const cost = inputCost + outputCost + markup;
|
|
235
|
+
// Update agent totals
|
|
207
236
|
agent.totalInputTokens += inputTokens;
|
|
208
237
|
agent.totalOutputTokens += outputTokens;
|
|
209
238
|
agent.totalCost += cost;
|
|
210
239
|
agent.totalMarkup += markup;
|
|
211
240
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
241
|
+
// Decrement balance with markup
|
|
212
242
|
if (agent.balanceService && cost > 0) {
|
|
213
243
|
agent.balanceService.decrementBalance(cost, markup);
|
|
214
244
|
}
|
|
215
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Compute the cost of image generation with markup (hardcoded to 0 for images)
|
|
248
|
+
* @param agent The agent making the request
|
|
249
|
+
* @param modelName The model name used for image generation
|
|
250
|
+
*/
|
|
216
251
|
computeImageCost(agent, modelName, centsPerImage) {
|
|
217
252
|
const modelInfo = (0, model_prices_1.getModelPrices)()[modelName];
|
|
218
253
|
if (!modelInfo || !modelInfo.output_cost_per_image) {
|
|
@@ -228,15 +263,21 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
|
|
|
228
263
|
return;
|
|
229
264
|
}
|
|
230
265
|
const outputCost = modelInfo.output_cost_per_image;
|
|
266
|
+
// Calculate markup: hardcoded to 0 for image generation
|
|
231
267
|
const markup = outputCost * 0;
|
|
232
268
|
const cost = outputCost + markup;
|
|
269
|
+
// Update agent totals
|
|
233
270
|
agent.totalCost += cost;
|
|
234
271
|
agent.totalMarkup += markup;
|
|
235
272
|
logger_1.logger.log(`Cost for image generation: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
273
|
+
// Decrement balance with markup
|
|
236
274
|
if (agent.balanceService && cost > 0) {
|
|
237
275
|
agent.balanceService.decrementBalance(cost, markup);
|
|
238
276
|
}
|
|
239
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Override the formatMessage method to handle Google AI specific message format
|
|
280
|
+
*/
|
|
240
281
|
formatMessage(message) {
|
|
241
282
|
if (!message) {
|
|
242
283
|
return 'No message';
|
|
@@ -7,9 +7,31 @@ export declare class GrokAiService extends BaseAiService {
|
|
|
7
7
|
getServiceName(): string;
|
|
8
8
|
getModelPricePrefix(): string;
|
|
9
9
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Uploads a document to Grok's Files API
|
|
12
|
+
* @param agent The agent to attach the document to
|
|
13
|
+
* @param fileName The name of the file
|
|
14
|
+
* @param fileData The file data as a Uint8Array
|
|
15
|
+
* @param fullContext
|
|
16
|
+
* @returns A success message with the file ID
|
|
17
|
+
*/
|
|
10
18
|
attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
|
|
11
19
|
finishAgent(agent: Agent): Promise<void>;
|
|
12
20
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
23
|
+
* @param agent The agent to add the message to
|
|
24
|
+
* @param message The formatted message to add
|
|
25
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
26
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
27
|
+
*/
|
|
13
28
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
|
|
29
|
+
/**
|
|
30
|
+
* Compute the cost of a message with markup and cache-aware pricing for Grok
|
|
31
|
+
* Grok provides a 75% discount on cached tokens (no cache creation charge)
|
|
32
|
+
* Handles model name lookup with xai/ prefix if needed
|
|
33
|
+
* @param agent The agent making the request
|
|
34
|
+
* @param usage Usage object from the API response
|
|
35
|
+
*/
|
|
14
36
|
private computeMessageCost;
|
|
15
37
|
}
|
|
@@ -30,7 +30,7 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
30
30
|
const options = {
|
|
31
31
|
apiKey: apiKey,
|
|
32
32
|
baseURL: 'https://api.x.ai/v1',
|
|
33
|
-
timeout: 600000,
|
|
33
|
+
timeout: 600000, // 10 minutes for very long requests (e.g., story imports)
|
|
34
34
|
maxRetries: 3,
|
|
35
35
|
};
|
|
36
36
|
this.openai = new openai_1.OpenAI(options);
|
|
@@ -59,27 +59,40 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
59
59
|
};
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Uploads a document to Grok's Files API
|
|
64
|
+
* @param agent The agent to attach the document to
|
|
65
|
+
* @param fileName The name of the file
|
|
66
|
+
* @param fileData The file data as a Uint8Array
|
|
67
|
+
* @param fullContext
|
|
68
|
+
* @returns A success message with the file ID
|
|
69
|
+
*/
|
|
62
70
|
async attachDocument(agent, fileName, fileData) {
|
|
63
71
|
if (agent.fullContextFiles) {
|
|
64
72
|
return super.attachDocument(agent, fileName, fileData);
|
|
65
73
|
}
|
|
74
|
+
// Check if we already uploaded this file to Grok
|
|
66
75
|
const existingMetadata = agent.attachedFiles.find((f) => f.fileName === fileName && f.serviceMetadata?.serviceName === this.getServiceName());
|
|
67
76
|
if (existingMetadata?.serviceMetadata?.resourceId) {
|
|
77
|
+
// File already uploaded to Grok
|
|
68
78
|
const fileId = existingMetadata.serviceMetadata.resourceId;
|
|
69
79
|
return `File found with Grok file id: ${fileId}`;
|
|
70
80
|
}
|
|
81
|
+
// Upload file to Grok using OpenAI SDK
|
|
71
82
|
let fileInput = fileData;
|
|
72
83
|
let fileToUpload = await (0, openai_2.toFile)(fileInput, fileName);
|
|
73
84
|
const fileObject = await this.openai.files.create({
|
|
74
85
|
file: fileToUpload,
|
|
75
86
|
purpose: 'assistants',
|
|
76
87
|
});
|
|
88
|
+
// Update file metadata with Grok-specific information
|
|
77
89
|
const additionalMetadata = {
|
|
78
90
|
serviceMetadata: {
|
|
79
91
|
serviceName: this.getServiceName(),
|
|
80
92
|
resourceId: fileObject.id,
|
|
81
93
|
},
|
|
82
94
|
};
|
|
95
|
+
// Find and update existing metadata
|
|
83
96
|
const fileMetadataIndex = agent.attachedFiles.findIndex((f) => f.fileName === fileName);
|
|
84
97
|
if (fileMetadataIndex >= 0) {
|
|
85
98
|
agent.attachedFiles[fileMetadataIndex] = {
|
|
@@ -92,6 +105,7 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
92
105
|
async finishAgent(agent) {
|
|
93
106
|
if (!agent)
|
|
94
107
|
return;
|
|
108
|
+
// Delete all Grok files using metadata
|
|
95
109
|
for (const metadata of agent.attachedFiles) {
|
|
96
110
|
if (metadata.serviceMetadata?.serviceName === this.getServiceName() &&
|
|
97
111
|
metadata.serviceMetadata?.resourceId) {
|
|
@@ -105,15 +119,20 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
}
|
|
108
|
-
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
122
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
124
|
+
_cacheConfig = null, maxOutputChars = 0) {
|
|
125
|
+
// CHECK BALANCE BEFORE AI CALL (unless disabled)
|
|
109
126
|
if (agent.balanceService && !agent.disableBalanceCheck) {
|
|
110
127
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
111
128
|
if (!hasSufficientBalance) {
|
|
112
129
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
113
130
|
}
|
|
114
131
|
}
|
|
132
|
+
// Build messages array locally without modifying agent.history yet
|
|
133
|
+
// Prepend identity and system instruction at the beginning
|
|
115
134
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
116
|
-
const instructions = promptInstructions || agent
|
|
135
|
+
const instructions = promptInstructions || this.getSystemInstruction(agent);
|
|
117
136
|
const messages = [];
|
|
118
137
|
if (instructions)
|
|
119
138
|
messages.push({
|
|
@@ -124,6 +143,7 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
124
143
|
role: 'system',
|
|
125
144
|
content: [{ type: 'text', text: identity }],
|
|
126
145
|
});
|
|
146
|
+
// Add system messages for each attached file (tells Grok what files are available)
|
|
127
147
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
128
148
|
for (const file of agent.attachedFiles) {
|
|
129
149
|
if (file.serviceMetadata?.serviceName === this.getServiceName() &&
|
|
@@ -149,17 +169,21 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
149
169
|
role: 'user',
|
|
150
170
|
content: [
|
|
151
171
|
{ type: 'text', text: textContent },
|
|
172
|
+
// {type: 'file', file: {filename: file.fileName, file_data: base64Data }}
|
|
152
173
|
],
|
|
153
174
|
});
|
|
154
175
|
}
|
|
155
176
|
}
|
|
156
177
|
}
|
|
178
|
+
// Handle attached artifacts
|
|
157
179
|
if (agent.attachedArtifacts && agent.attachedArtifacts.length > 0) {
|
|
158
180
|
for (const artifactId of agent.attachedArtifacts) {
|
|
159
181
|
const content = agent.artifactService.getArtifact(artifactId);
|
|
182
|
+
// Only include text artifacts (skip binary/image artifacts)
|
|
160
183
|
if (content && typeof content === 'string') {
|
|
161
184
|
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
162
185
|
const fileName = metadata ? `${metadata.name}.md` : 'artifact.md';
|
|
186
|
+
// Add as text message
|
|
163
187
|
messages.push({
|
|
164
188
|
role: 'user',
|
|
165
189
|
content: [
|
|
@@ -172,7 +196,9 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
172
196
|
}
|
|
173
197
|
}
|
|
174
198
|
}
|
|
199
|
+
// Add conversation history
|
|
175
200
|
messages.push(...agent.history);
|
|
201
|
+
// Add user prompt to local array
|
|
176
202
|
if (prompt) {
|
|
177
203
|
messages.push({
|
|
178
204
|
role: 'user',
|
|
@@ -196,6 +222,7 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
196
222
|
responseText = this.trimToJson(responseText);
|
|
197
223
|
}
|
|
198
224
|
this.debugLogResponse(agent.agentName, responseText);
|
|
225
|
+
// Track token usage if available, including cache-specific metrics
|
|
199
226
|
if (response.usage) {
|
|
200
227
|
this.computeMessageCost(agent, response.usage);
|
|
201
228
|
}
|
|
@@ -204,15 +231,27 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
204
231
|
logger_1.logger.error(error);
|
|
205
232
|
throw error;
|
|
206
233
|
}
|
|
234
|
+
// Only modify agent.history if saveResponse=true
|
|
235
|
+
// Note: We don't save the temporary system instructions to history
|
|
207
236
|
if (saveResponse) {
|
|
208
237
|
this.addToConversationHistory(agent, prompt, false);
|
|
209
238
|
this.addToConversationHistory(agent, responseText, true);
|
|
210
239
|
}
|
|
240
|
+
// If saveResponse=false, don't modify history at all
|
|
211
241
|
if (jsonSchema)
|
|
212
242
|
return this.parseStructuredResponse(responseText);
|
|
213
243
|
return responseText;
|
|
214
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
247
|
+
* @param agent The agent to add the message to
|
|
248
|
+
* @param message The formatted message to add
|
|
249
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
250
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
251
|
+
*/
|
|
215
252
|
addToConversationHistory(agent, message, fromSelf = false, developer = false) {
|
|
253
|
+
// Default implementation for most services
|
|
254
|
+
// Subclasses should override this if they have a different history format
|
|
216
255
|
if (!agent.history) {
|
|
217
256
|
agent.history = [];
|
|
218
257
|
}
|
|
@@ -227,11 +266,19 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
227
266
|
});
|
|
228
267
|
agent.trimHistoryIfNeeded();
|
|
229
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Compute the cost of a message with markup and cache-aware pricing for Grok
|
|
271
|
+
* Grok provides a 75% discount on cached tokens (no cache creation charge)
|
|
272
|
+
* Handles model name lookup with xai/ prefix if needed
|
|
273
|
+
* @param agent The agent making the request
|
|
274
|
+
* @param usage Usage object from the API response
|
|
275
|
+
*/
|
|
230
276
|
computeMessageCost(agent, usage) {
|
|
231
277
|
const totalPromptTokens = usage.prompt_tokens || 0;
|
|
232
278
|
const cachedTokens = usage.prompt_tokens_details?.cached_tokens || 0;
|
|
233
279
|
const uncachedPromptTokens = totalPromptTokens - cachedTokens;
|
|
234
280
|
const completionTokens = usage.completion_tokens || 0;
|
|
281
|
+
// Try to find model with current name, then try with xai/ prefix
|
|
235
282
|
let modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
236
283
|
if (!modelInfo && !agent.modelName.startsWith('xai/')) {
|
|
237
284
|
modelInfo = (0, model_prices_1.getModelPrices)()[`xai/${agent.modelName}`];
|
|
@@ -240,20 +287,25 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
|
|
|
240
287
|
logger_1.logger.error(`No price info found for model ${agent.modelName} or xai/${agent.modelName}`);
|
|
241
288
|
return;
|
|
242
289
|
}
|
|
290
|
+
// Calculate cache-aware costs (Grok: 75% discount on cached)
|
|
243
291
|
const uncachedCost = uncachedPromptTokens * modelInfo.input_cost_per_token;
|
|
244
292
|
const cachedCost = cachedTokens *
|
|
245
293
|
(modelInfo.cache_read_input_token_cost || modelInfo.input_cost_per_token * 0.25);
|
|
246
294
|
const outputCost = completionTokens * modelInfo.output_cost_per_token;
|
|
295
|
+
// Calculate markup: 2x output cost only (unless disabled)
|
|
247
296
|
const markup = agent.disableMarkup ? 0 : outputCost * agent.markupRate;
|
|
248
297
|
const cost = uncachedCost + cachedCost + outputCost + markup;
|
|
298
|
+
// Update agent totals
|
|
249
299
|
agent.totalInputTokens += totalPromptTokens;
|
|
250
300
|
agent.totalOutputTokens += completionTokens;
|
|
251
301
|
agent.totalCost += cost;
|
|
252
302
|
agent.totalMarkup += markup;
|
|
253
303
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
304
|
+
// Log cache metrics for monitoring
|
|
254
305
|
if (cachedTokens > 0) {
|
|
255
306
|
logger_1.logger.log(`Cache metrics for ${agent.agentName}: cached=${cachedTokens}, uncached=${uncachedPromptTokens}`);
|
|
256
307
|
}
|
|
308
|
+
// Decrement balance with markup
|
|
257
309
|
if (agent.balanceService && cost > 0) {
|
|
258
310
|
agent.balanceService.decrementBalance(cost, markup);
|
|
259
311
|
}
|
|
@@ -51,7 +51,7 @@ const logger_1 = require("../../common/logger");
|
|
|
51
51
|
let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService {
|
|
52
52
|
constructor() {
|
|
53
53
|
super();
|
|
54
|
-
this._isAvailable = true;
|
|
54
|
+
this._isAvailable = true; // Always available for testing
|
|
55
55
|
}
|
|
56
56
|
getServiceName() {
|
|
57
57
|
return 'Mock';
|
|
@@ -70,18 +70,27 @@ let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService
|
|
|
70
70
|
},
|
|
71
71
|
];
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
// Override preparedPrompt to load .mock files
|
|
74
|
+
async preparedPrompt(agent, promptFileName, variables, saveResponse = true,
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
76
|
+
_cacheConfig = null) {
|
|
77
|
+
// Find the corresponding .mock file using same lookup as .prompt
|
|
74
78
|
const mockFile = this.findPromptFile(agent, promptFileName, '.mock');
|
|
75
79
|
if (!mockFile) {
|
|
76
80
|
logger_1.logger.warn(`Mock file '${promptFileName}.mock' not found for agent '${agent.agentName}'. Using generic response.`);
|
|
81
|
+
// Fall back to generic response
|
|
77
82
|
const preparedPrompt = this.getPreparedPrompt(agent, promptFileName, variables);
|
|
78
83
|
const jsonSchema = this.getPreparedSchema(agent, promptFileName);
|
|
79
84
|
return this.textPrompt(agent, preparedPrompt, jsonSchema, saveResponse);
|
|
80
85
|
}
|
|
81
86
|
const mockResponse = fs.readFileSync(mockFile).toString('utf8');
|
|
87
|
+
// Get JSON schema if exists
|
|
82
88
|
const jsonSchema = this.getPreparedSchema(agent, promptFileName);
|
|
89
|
+
// Get the prepared prompt for tracking (even though we won't use it)
|
|
83
90
|
const preparedPrompt = this.getPreparedPrompt(agent, promptFileName, variables);
|
|
91
|
+
// Track costs
|
|
84
92
|
await this.trackMockCosts(agent, preparedPrompt, mockResponse);
|
|
93
|
+
// Parse response based on schema
|
|
85
94
|
if (jsonSchema) {
|
|
86
95
|
try {
|
|
87
96
|
const parsedResponse = JSON.parse(mockResponse);
|
|
@@ -109,29 +118,38 @@ let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService
|
|
|
109
118
|
if (promptFileName === 'moderate') {
|
|
110
119
|
const senderMatch = prompt.match(/^Sender:\s*(.*)$/m);
|
|
111
120
|
const sender = senderMatch ? senderMatch[1].trim() : null;
|
|
121
|
+
// Prompt of the form, "How are you, Bob?" -> "Bob"
|
|
112
122
|
const targetMatch = prompt.match(/, \s(.*)\?/m);
|
|
113
123
|
const target = targetMatch ? targetMatch[1].trim() : null;
|
|
114
124
|
const agents = variables.agents;
|
|
115
125
|
const targetAgent = agents.find((agent) => agent.agentName === target);
|
|
116
126
|
if (targetAgent)
|
|
127
|
+
// If a target agent is mentioned in the dialog, send the response to that agent's mock file
|
|
117
128
|
mockFileName = `moderate_to_${targetAgent.agentName}`;
|
|
118
129
|
else if (sender === variables.humanAgentName || sender === 'system')
|
|
119
|
-
|
|
130
|
+
// Send system messages and all other human responses to the narrator
|
|
131
|
+
mockFileName = 'moderate'; // Send all other responses back to the human agent
|
|
120
132
|
else
|
|
121
133
|
mockFileName = 'moderate_to_alice';
|
|
122
134
|
}
|
|
123
135
|
return mockFileName;
|
|
124
136
|
}
|
|
137
|
+
// Override instructedPrompt to load .mock files
|
|
125
138
|
async instructedPrompt(agent, prompt = null, promptFileName, variables = {}, saveResponse = true, cacheConfig = null) {
|
|
139
|
+
// Find the corresponding .mock file using same lookup as .prompt
|
|
126
140
|
const mockFileBaseName = this.getMockFile(promptFileName, prompt, variables);
|
|
127
141
|
const mockFile = this.findPromptFile(agent, mockFileBaseName, '.mock');
|
|
128
142
|
if (!mockFile) {
|
|
129
143
|
logger_1.logger.warn(`Mock file '${mockFile}' not found for agent '${agent.agentName}'. Using generic response.`);
|
|
144
|
+
// Fall back to generic response
|
|
130
145
|
return this.textPrompt(agent, prompt || 'Mock prompt', null, saveResponse, cacheConfig);
|
|
131
146
|
}
|
|
132
147
|
const mockResponse = fs.readFileSync(mockFile).toString('utf8');
|
|
148
|
+
// Get JSON schema if exists
|
|
133
149
|
const jsonSchema = this.getPreparedSchema(agent, promptFileName);
|
|
150
|
+
// Track costs
|
|
134
151
|
await this.trackMockCosts(agent, prompt || mockResponse, mockResponse);
|
|
152
|
+
// Parse response based on schema
|
|
135
153
|
if (jsonSchema) {
|
|
136
154
|
try {
|
|
137
155
|
const parsedResponse = JSON.parse(mockResponse);
|
|
@@ -154,7 +172,13 @@ let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService
|
|
|
154
172
|
return mockResponse;
|
|
155
173
|
}
|
|
156
174
|
}
|
|
157
|
-
|
|
175
|
+
// Fallback for direct textPrompt calls (generic response)
|
|
176
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true,
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
178
|
+
_promptInstructions = null,
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
180
|
+
_cacheConfig = null, maxOutputChars = 0) {
|
|
181
|
+
// Generic mock response for direct calls
|
|
158
182
|
const mockResponse = jsonSchema
|
|
159
183
|
? { action: 'SPEAK', content: 'Generic mock response' }
|
|
160
184
|
: 'Generic mock response';
|
|
@@ -176,13 +200,16 @@ let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService
|
|
|
176
200
|
}
|
|
177
201
|
const inputCost = inputTokens * modelInfo.input_cost_per_token;
|
|
178
202
|
const outputCost = outputTokens * modelInfo.output_cost_per_token;
|
|
203
|
+
// Calculate markup: 2x output cost
|
|
179
204
|
const markup = outputCost * agent.markupRate;
|
|
180
205
|
const totalCost = inputCost + outputCost + markup;
|
|
206
|
+
// Update agent totals
|
|
181
207
|
agent.totalCost += totalCost;
|
|
182
208
|
agent.totalInputTokens += inputTokens;
|
|
183
209
|
agent.totalOutputTokens += outputTokens;
|
|
184
210
|
agent.totalMarkup += markup;
|
|
185
211
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${totalCost} (markup: ${markup.toFixed(4)})`);
|
|
212
|
+
// Decrement balance with markup
|
|
186
213
|
if (agent.balanceService) {
|
|
187
214
|
await agent.balanceService.decrementBalance(totalCost, markup);
|
|
188
215
|
}
|
|
@@ -3,7 +3,17 @@ import { BaseAiService } from './base-ai.service';
|
|
|
3
3
|
import { ModelInfo } from '../../../../shared/types/app.types';
|
|
4
4
|
export declare class OpenAiService extends BaseAiService {
|
|
5
5
|
private openai;
|
|
6
|
+
/**
|
|
7
|
+
* Returns the effort levels the given model accepts, or `null` if the
|
|
8
|
+
* model has no restrictions (all of `EFFORT_ORDER` is allowed).
|
|
9
|
+
*/
|
|
6
10
|
private getAllowedReasoningEfforts;
|
|
11
|
+
/**
|
|
12
|
+
* Coerces the agent's configured reasoning effort to one the model
|
|
13
|
+
* actually supports. Picks the nearest allowed level (preferring a
|
|
14
|
+
* higher level on ties) and logs a warning whenever a coercion happens.
|
|
15
|
+
* Returns `null` unchanged so callers can preserve "no effort" intent.
|
|
16
|
+
*/
|
|
7
17
|
private resolveReasoningEffort;
|
|
8
18
|
constructor();
|
|
9
19
|
getServiceName(): string;
|
|
@@ -13,9 +23,29 @@ export declare class OpenAiService extends BaseAiService {
|
|
|
13
23
|
finishAgent(agent: Agent): Promise<void>;
|
|
14
24
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
15
25
|
attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
28
|
+
* @param agent The agent to add the message to
|
|
29
|
+
* @param message The formatted message to add
|
|
30
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
31
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
32
|
+
*/
|
|
16
33
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
|
|
34
|
+
/**
|
|
35
|
+
* Compute the cost of a message with markup and cache-aware pricing for OpenAI
|
|
36
|
+
* OpenAI provides a 50% discount on cached tokens (no cache creation charge)
|
|
37
|
+
* @param agent The agent making the request
|
|
38
|
+
* @param usage Usage object from the API response
|
|
39
|
+
*/
|
|
17
40
|
private computeMessageCost;
|
|
18
41
|
private computeImageCost;
|
|
42
|
+
/**
|
|
43
|
+
* Generates an image from a text prompt
|
|
44
|
+
* @param agent The agent making the request
|
|
45
|
+
* @param prompt Text description of the image to generate
|
|
46
|
+
* @param imageProperties API parameters spread into the request; may include `centsPerImage` for fallback pricing
|
|
47
|
+
* @returns Promise resolving to { artifactId } or { error }
|
|
48
|
+
*/
|
|
19
49
|
generateImage(agent: Agent, prompt: string, imageProperties?: Record<string, any>): Promise<{
|
|
20
50
|
artifactId?: string;
|
|
21
51
|
error?: any;
|