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
|
@@ -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;
|
|
@@ -17,12 +17,22 @@ const openai_2 = require("openai");
|
|
|
17
17
|
const model_prices_1 = require("../model_prices");
|
|
18
18
|
const errors_1 = require("../../common/errors");
|
|
19
19
|
const logger_1 = require("../../common/logger");
|
|
20
|
+
// Effort levels in ascending intensity. Used to pick the nearest supported
|
|
21
|
+
// effort when an agent's configured value isn't allowed by a given model.
|
|
20
22
|
const EFFORT_ORDER = ['low', 'medium', 'high'];
|
|
23
|
+
// Models with restricted `reasoning.effort` support. Keys are matched as
|
|
24
|
+
// prefixes against `agent.modelName` so dated variants (e.g.
|
|
25
|
+
// `gpt-5-pro-2025-10-06`) inherit the same restrictions. Models not listed
|
|
26
|
+
// here are assumed to accept the full ['low', 'medium', 'high'] set.
|
|
21
27
|
const MODEL_EFFORT_ALLOWLIST = {
|
|
22
28
|
'gpt-5-pro': ['high'],
|
|
23
29
|
};
|
|
24
30
|
let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService {
|
|
25
31
|
openai;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the effort levels the given model accepts, or `null` if the
|
|
34
|
+
* model has no restrictions (all of `EFFORT_ORDER` is allowed).
|
|
35
|
+
*/
|
|
26
36
|
getAllowedReasoningEfforts(modelName) {
|
|
27
37
|
for (const prefix of Object.keys(MODEL_EFFORT_ALLOWLIST)) {
|
|
28
38
|
if (modelName === prefix || modelName.startsWith(`${prefix}-`)) {
|
|
@@ -31,6 +41,12 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
31
41
|
}
|
|
32
42
|
return null;
|
|
33
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Coerces the agent's configured reasoning effort to one the model
|
|
46
|
+
* actually supports. Picks the nearest allowed level (preferring a
|
|
47
|
+
* higher level on ties) and logs a warning whenever a coercion happens.
|
|
48
|
+
* Returns `null` unchanged so callers can preserve "no effort" intent.
|
|
49
|
+
*/
|
|
34
50
|
resolveReasoningEffort(modelName, requested) {
|
|
35
51
|
if (!requested)
|
|
36
52
|
return requested;
|
|
@@ -42,6 +58,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
42
58
|
let bestDist = Math.abs(EFFORT_ORDER.indexOf(best) - requestedIdx);
|
|
43
59
|
for (const candidate of allowed) {
|
|
44
60
|
const dist = Math.abs(EFFORT_ORDER.indexOf(candidate) - requestedIdx);
|
|
61
|
+
// On ties, prefer the higher candidate (later in EFFORT_ORDER).
|
|
45
62
|
if (dist < bestDist ||
|
|
46
63
|
(dist === bestDist &&
|
|
47
64
|
EFFORT_ORDER.indexOf(candidate) > EFFORT_ORDER.indexOf(best))) {
|
|
@@ -62,9 +79,10 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
62
79
|
}
|
|
63
80
|
const options = {
|
|
64
81
|
apiKey: apiKey,
|
|
65
|
-
timeout: 600000,
|
|
82
|
+
timeout: 600000, // 10 minutes for very long requests (e.g., story imports)
|
|
66
83
|
maxRetries: 3,
|
|
67
84
|
};
|
|
85
|
+
// Add organization ID if provided
|
|
68
86
|
if (process.env.OPENAI_ORGANIZATION_ID) {
|
|
69
87
|
options.organization = process.env.OPENAI_ORGANIZATION_ID;
|
|
70
88
|
}
|
|
@@ -86,6 +104,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
86
104
|
return false;
|
|
87
105
|
}
|
|
88
106
|
async fetchModelsFromApi() {
|
|
107
|
+
// Get all models
|
|
89
108
|
const models = await this.openai.models.list();
|
|
90
109
|
return models.data.map((model) => {
|
|
91
110
|
return {
|
|
@@ -99,6 +118,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
99
118
|
async finishAgent(agent) {
|
|
100
119
|
if (!agent)
|
|
101
120
|
return;
|
|
121
|
+
// Delete vector store if it exists
|
|
102
122
|
if (agent.vectorStore) {
|
|
103
123
|
try {
|
|
104
124
|
await this.openai.vectorStores.delete(agent.vectorStore.id);
|
|
@@ -108,6 +128,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
108
128
|
logger_1.logger.error(`Error deleting vector store for agent ${agent.id}:`, error);
|
|
109
129
|
}
|
|
110
130
|
}
|
|
131
|
+
// Delete all OpenAI files using metadata
|
|
111
132
|
for (const metadata of agent.attachedFiles) {
|
|
112
133
|
if (metadata.serviceMetadata?.serviceName === this.getServiceName() &&
|
|
113
134
|
metadata.serviceMetadata?.resourceId) {
|
|
@@ -121,23 +142,32 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
121
142
|
}
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
|
-
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
145
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
147
|
+
_cacheConfig = null, maxOutputChars = 0) {
|
|
148
|
+
// CHECK BALANCE BEFORE AI CALL (unless disabled)
|
|
125
149
|
if (agent.balanceService && !agent.disableBalanceCheck) {
|
|
126
150
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
127
151
|
if (!hasSufficientBalance) {
|
|
128
152
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
129
153
|
}
|
|
130
154
|
}
|
|
155
|
+
// Build messages array locally without modifying agent.history yet
|
|
156
|
+
// Prepend identity message
|
|
131
157
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
132
158
|
const messages = [{ role: 'user', content: identity }];
|
|
159
|
+
// Track if we have any files that need vector store
|
|
133
160
|
let hasVectorStoreFiles = false;
|
|
161
|
+
// Add attached files - either from vector store or directly in message
|
|
134
162
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
135
163
|
for (const file of agent.attachedFiles) {
|
|
136
164
|
if (file.serviceMetadata?.serviceName === this.getServiceName() &&
|
|
137
165
|
file.serviceMetadata?.resourceId) {
|
|
166
|
+
// File is in vector store - just track that we need file_search tool
|
|
138
167
|
hasVectorStoreFiles = true;
|
|
139
168
|
}
|
|
140
169
|
else if (file.serviceMetadata?.fileData) {
|
|
170
|
+
// File has direct data - include it in the message
|
|
141
171
|
const fileData = new Uint8Array(file.serviceMetadata.fileData);
|
|
142
172
|
const textContent = Buffer.from(fileData).toString('utf-8');
|
|
143
173
|
messages.push({
|
|
@@ -146,6 +176,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
146
176
|
});
|
|
147
177
|
}
|
|
148
178
|
}
|
|
179
|
+
// Add message about vector store files if any exist
|
|
149
180
|
if (hasVectorStoreFiles) {
|
|
150
181
|
const vectorStoreFileNames = agent.attachedFiles
|
|
151
182
|
.filter((f) => f.serviceMetadata?.serviceName === this.getServiceName() &&
|
|
@@ -158,12 +189,15 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
158
189
|
});
|
|
159
190
|
}
|
|
160
191
|
}
|
|
192
|
+
// Handle attached artifacts
|
|
161
193
|
if (agent.attachedArtifacts && agent.attachedArtifacts.length > 0) {
|
|
162
194
|
for (const artifactId of agent.attachedArtifacts) {
|
|
163
195
|
const content = agent.artifactService.getArtifact(artifactId);
|
|
196
|
+
// Only include text artifacts (skip binary/image artifacts)
|
|
164
197
|
if (content && typeof content === 'string') {
|
|
165
198
|
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
166
199
|
const fileName = metadata ? `${metadata.name}.md` : 'artifact.md';
|
|
200
|
+
// Add as text message
|
|
167
201
|
messages.push({
|
|
168
202
|
role: 'user',
|
|
169
203
|
content: `Attached document: ${fileName}\n\n${content}`,
|
|
@@ -171,6 +205,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
171
205
|
}
|
|
172
206
|
}
|
|
173
207
|
}
|
|
208
|
+
// Add conversation history
|
|
174
209
|
messages.push(...agent.history);
|
|
175
210
|
if (prompt) {
|
|
176
211
|
messages.push({ role: 'user', content: prompt });
|
|
@@ -216,6 +251,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
216
251
|
responseText = response.output_text;
|
|
217
252
|
}
|
|
218
253
|
this.debugLogResponse(agent.agentName, responseText);
|
|
254
|
+
// Track token usage if available, including cache-specific metrics
|
|
219
255
|
if (response.usage) {
|
|
220
256
|
this.computeMessageCost(agent, response.usage);
|
|
221
257
|
}
|
|
@@ -224,10 +260,12 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
224
260
|
logger_1.logger.error(error);
|
|
225
261
|
throw error;
|
|
226
262
|
}
|
|
263
|
+
// Only modify agent.history if saveResponse=true
|
|
227
264
|
if (saveResponse) {
|
|
228
265
|
this.addToConversationHistory(agent, prompt, false);
|
|
229
266
|
this.addToConversationHistory(agent, responseText, true);
|
|
230
267
|
}
|
|
268
|
+
// If saveResponse=false, don't modify history at all
|
|
231
269
|
if (jsonSchema)
|
|
232
270
|
return this.parseStructuredResponse(responseText);
|
|
233
271
|
return responseText;
|
|
@@ -254,6 +292,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
254
292
|
agent.vectorStore = foundVs;
|
|
255
293
|
resultText += `Found existing vector store (${agent.agentName}). `;
|
|
256
294
|
}
|
|
295
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
257
296
|
}
|
|
258
297
|
catch (error) {
|
|
259
298
|
agent.vectorStore = null;
|
|
@@ -262,33 +301,42 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
262
301
|
}
|
|
263
302
|
if (!vectorStore)
|
|
264
303
|
throw new Error('No vector store could be created for this agent.');
|
|
304
|
+
// Check if we already have this file in OpenAI
|
|
265
305
|
const existingMetadata = agent.attachedFiles.find((f) => f.fileName === fileName && f.serviceMetadata?.serviceName === this.getServiceName());
|
|
266
306
|
if (existingMetadata?.serviceMetadata?.resourceId) {
|
|
307
|
+
// We already have this file in OpenAI
|
|
267
308
|
const fileId = existingMetadata.serviceMetadata.resourceId;
|
|
309
|
+
// Check if it's already in the vector store
|
|
268
310
|
const vectorStoresFilePage = await this.openai.vectorStores.files.list(vectorStore.id);
|
|
269
311
|
let vectorStoresFiles = vectorStoresFilePage.data;
|
|
270
312
|
let vectorStoresFileFound = vectorStoresFiles.find((f) => f.id === fileId);
|
|
271
313
|
if (vectorStoresFileFound) {
|
|
314
|
+
// Note: File info will be prepended to each request in textPrompt
|
|
272
315
|
return (resultText +
|
|
273
316
|
` -- File found in vector store ${vectorStore.name} with file id: ${fileId}`);
|
|
274
317
|
}
|
|
275
318
|
else {
|
|
319
|
+
// Add existing file to vector store
|
|
276
320
|
await this.openai.vectorStores.files.createAndPoll(vectorStore.id, {
|
|
277
321
|
file_id: fileId,
|
|
278
322
|
});
|
|
323
|
+
// Note: File info will be prepended to each request in textPrompt
|
|
279
324
|
return (resultText +
|
|
280
325
|
` -- Adding existing file to vector store ${vectorStore.name} with file id: ${fileId}`);
|
|
281
326
|
}
|
|
282
327
|
}
|
|
328
|
+
// Upload new file to OpenAI
|
|
283
329
|
let fileInput = fileData;
|
|
284
330
|
let fileToUpload = await (0, openai_1.toFile)(fileInput, fileName);
|
|
285
331
|
const fileObject = await this.openai.files.create({
|
|
286
332
|
file: fileToUpload,
|
|
287
333
|
purpose: 'assistants',
|
|
288
334
|
});
|
|
335
|
+
// Add file to vector store
|
|
289
336
|
await this.openai.vectorStores.files.createAndPoll(vectorStore.id, {
|
|
290
337
|
file_id: fileObject.id,
|
|
291
338
|
});
|
|
339
|
+
// Update file metadata with OpenAI-specific information
|
|
292
340
|
const additionalMetadata = {
|
|
293
341
|
serviceMetadata: {
|
|
294
342
|
serviceName: this.getServiceName(),
|
|
@@ -296,17 +344,29 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
296
344
|
vectorStoreId: vectorStore.id,
|
|
297
345
|
},
|
|
298
346
|
};
|
|
347
|
+
// Find the existing file metadata in the agent's attachedFiles
|
|
299
348
|
const fileMetadataIndex = agent.attachedFiles.findIndex((f) => f.fileName === fileName);
|
|
300
349
|
if (fileMetadataIndex >= 0) {
|
|
350
|
+
// Update existing metadata
|
|
301
351
|
agent.attachedFiles[fileMetadataIndex] = {
|
|
302
352
|
...agent.attachedFiles[fileMetadataIndex],
|
|
303
353
|
...additionalMetadata,
|
|
304
354
|
};
|
|
305
355
|
}
|
|
356
|
+
// Note: File info will be prepended to each request in textPrompt
|
|
306
357
|
return (resultText +
|
|
307
358
|
` -- Uploaded new file to vector store ${vectorStore.name} with file id: ${fileObject.id}`);
|
|
308
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
362
|
+
* @param agent The agent to add the message to
|
|
363
|
+
* @param message The formatted message to add
|
|
364
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
365
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
366
|
+
*/
|
|
309
367
|
addToConversationHistory(agent, message, fromSelf = false, developer = false) {
|
|
368
|
+
// Default implementation for most services
|
|
369
|
+
// Subclasses should override this if they have a different history format
|
|
310
370
|
if (!agent.history) {
|
|
311
371
|
agent.history = [];
|
|
312
372
|
}
|
|
@@ -321,6 +381,12 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
321
381
|
});
|
|
322
382
|
agent.trimHistoryIfNeeded();
|
|
323
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Compute the cost of a message with markup and cache-aware pricing for OpenAI
|
|
386
|
+
* OpenAI provides a 50% discount on cached tokens (no cache creation charge)
|
|
387
|
+
* @param agent The agent making the request
|
|
388
|
+
* @param usage Usage object from the API response
|
|
389
|
+
*/
|
|
324
390
|
computeMessageCost(agent, usage) {
|
|
325
391
|
const totalInputTokens = usage.input_tokens || 0;
|
|
326
392
|
const cachedTokens = usage.input_tokens_details?.cached_tokens || 0;
|
|
@@ -331,20 +397,25 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
331
397
|
logger_1.logger.error(`No price info found for model ${agent.modelName}`);
|
|
332
398
|
return;
|
|
333
399
|
}
|
|
400
|
+
// Calculate cache-aware costs (OpenAI: 50% discount on cached)
|
|
334
401
|
const uncachedCost = uncachedInputTokens * modelInfo.input_cost_per_token;
|
|
335
402
|
const cachedCost = cachedTokens *
|
|
336
403
|
(modelInfo.cache_read_input_token_cost || modelInfo.input_cost_per_token * 0.5);
|
|
337
404
|
const outputCost = outputTokens * modelInfo.output_cost_per_token;
|
|
405
|
+
// Calculate markup: 2x output cost only (unless disabled)
|
|
338
406
|
const markup = agent.disableMarkup ? 0 : outputCost * agent.markupRate;
|
|
339
407
|
const cost = uncachedCost + cachedCost + outputCost + markup;
|
|
408
|
+
// Update agent totals
|
|
340
409
|
agent.totalInputTokens += totalInputTokens;
|
|
341
410
|
agent.totalOutputTokens += outputTokens;
|
|
342
411
|
agent.totalCost += cost;
|
|
343
412
|
agent.totalMarkup += markup;
|
|
344
413
|
logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
|
|
414
|
+
// Log cache metrics for monitoring
|
|
345
415
|
if (cachedTokens > 0) {
|
|
346
416
|
logger_1.logger.log(`Cache metrics for ${agent.agentName}: cached=${cachedTokens}, uncached=${uncachedInputTokens}`);
|
|
347
417
|
}
|
|
418
|
+
// Decrement balance with markup
|
|
348
419
|
if (agent.balanceService && cost > 0) {
|
|
349
420
|
agent.balanceService.decrementBalance(cost, markup);
|
|
350
421
|
}
|
|
@@ -368,6 +439,13 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
|
|
|
368
439
|
agent.balanceService.decrementBalance(cost, 0);
|
|
369
440
|
}
|
|
370
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Generates an image from a text prompt
|
|
444
|
+
* @param agent The agent making the request
|
|
445
|
+
* @param prompt Text description of the image to generate
|
|
446
|
+
* @param imageProperties API parameters spread into the request; may include `centsPerImage` for fallback pricing
|
|
447
|
+
* @returns Promise resolving to { artifactId } or { error }
|
|
448
|
+
*/
|
|
371
449
|
async generateImage(agent, prompt, imageProperties) {
|
|
372
450
|
const { centsPerImage, ...apiProperties } = imageProperties ?? {};
|
|
373
451
|
const modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { BaseAiService } from './base-ai.service';
|
|
2
2
|
import { Agent } from '../agent';
|
|
3
3
|
import { ModelInfo } from '../../../../shared/types/app.types';
|
|
4
|
+
/**
|
|
5
|
+
* Text provider for self-hosted OpenAI-compatible inference servers
|
|
6
|
+
* (vLLM, Ollama, llama.cpp server, LM Studio, ...). The server is reached via
|
|
7
|
+
* SELF_HOSTED_BASE_URL (which must include the /v1 path segment). Models are
|
|
8
|
+
* whatever the server reports from /v1/models, so no pricing entries exist;
|
|
9
|
+
* token usage is always tracked, cost is only charged when a matching
|
|
10
|
+
* model_prices.json entry is present.
|
|
11
|
+
*/
|
|
4
12
|
export declare class SelfHostedAiService extends BaseAiService {
|
|
5
13
|
private openai;
|
|
6
14
|
constructor();
|
|
@@ -8,6 +16,19 @@ export declare class SelfHostedAiService extends BaseAiService {
|
|
|
8
16
|
requiresKnownModel(): boolean;
|
|
9
17
|
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
10
18
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
21
|
+
* @param agent The agent to add the message to
|
|
22
|
+
* @param message The formatted message to add
|
|
23
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
24
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
25
|
+
*/
|
|
11
26
|
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
|
|
27
|
+
/**
|
|
28
|
+
* Tracks token usage for every request; charges cost only when the model
|
|
29
|
+
* has a model_prices.json entry. Unpriced models are the norm for
|
|
30
|
+
* self-hosted servers, so their absence is logged at debug level, not as
|
|
31
|
+
* an error.
|
|
32
|
+
*/
|
|
12
33
|
private computeMessageCost;
|
|
13
34
|
}
|
|
@@ -16,6 +16,14 @@ const base_ai_service_1 = require("./base-ai.service");
|
|
|
16
16
|
const model_prices_1 = require("../model_prices");
|
|
17
17
|
const errors_1 = require("../../common/errors");
|
|
18
18
|
const logger_1 = require("../../common/logger");
|
|
19
|
+
/**
|
|
20
|
+
* Text provider for self-hosted OpenAI-compatible inference servers
|
|
21
|
+
* (vLLM, Ollama, llama.cpp server, LM Studio, ...). The server is reached via
|
|
22
|
+
* SELF_HOSTED_BASE_URL (which must include the /v1 path segment). Models are
|
|
23
|
+
* whatever the server reports from /v1/models, so no pricing entries exist;
|
|
24
|
+
* token usage is always tracked, cost is only charged when a matching
|
|
25
|
+
* model_prices.json entry is present.
|
|
26
|
+
*/
|
|
19
27
|
let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.BaseAiService {
|
|
20
28
|
openai;
|
|
21
29
|
constructor() {
|
|
@@ -27,9 +35,11 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
27
35
|
return;
|
|
28
36
|
}
|
|
29
37
|
this.openai = new openai_1.OpenAI({
|
|
38
|
+
// The SDK refuses an empty apiKey; self-hosted servers without
|
|
39
|
+
// auth ignore the placeholder value.
|
|
30
40
|
apiKey: process.env['SELF_HOSTED_API_KEY'] || 'sk-no-key-required',
|
|
31
41
|
baseURL,
|
|
32
|
-
timeout: 600000,
|
|
42
|
+
timeout: 600000, // 10 minutes — large local models can be slow
|
|
33
43
|
maxRetries: 3,
|
|
34
44
|
});
|
|
35
45
|
logger_1.logger.debug('SelfHosted service initialized successfully');
|
|
@@ -47,6 +57,7 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
47
57
|
}
|
|
48
58
|
async fetchModelsFromApi() {
|
|
49
59
|
const models = await this.openai.models.list();
|
|
60
|
+
// Some servers (older Ollama builds) return sparse model objects
|
|
50
61
|
return models.data
|
|
51
62
|
.filter((model) => model && model.id)
|
|
52
63
|
.map((model) => ({
|
|
@@ -56,7 +67,13 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
56
67
|
service: 'SelfHosted',
|
|
57
68
|
}));
|
|
58
69
|
}
|
|
59
|
-
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
70
|
+
async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
+
_cacheConfig = null,
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
74
|
+
_maxOutputChars = 0) {
|
|
75
|
+
// CHECK BALANCE BEFORE AI CALL — only when the model actually has a
|
|
76
|
+
// pricing entry; free self-hosted models stay usable at zero balance.
|
|
60
77
|
const modelInfo = (0, model_prices_1.resolveModelInfo)(agent.modelName, this.getModelPricePrefix());
|
|
61
78
|
if (modelInfo && agent.balanceService && !agent.disableBalanceCheck) {
|
|
62
79
|
const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
|
|
@@ -64,6 +81,7 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
64
81
|
throw new errors_1.InsufficientBalanceError('Insufficient balance. Please add funds to continue using AI services.');
|
|
65
82
|
}
|
|
66
83
|
}
|
|
84
|
+
// Build messages array locally without modifying agent.history yet
|
|
67
85
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
68
86
|
const instructions = promptInstructions || agent.systemInstruction;
|
|
69
87
|
const messages = [];
|
|
@@ -76,6 +94,8 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
76
94
|
role: 'system',
|
|
77
95
|
content: [{ type: 'text', text: identity }],
|
|
78
96
|
});
|
|
97
|
+
// Attached files are always inlined as text — self-hosted servers have
|
|
98
|
+
// no files API.
|
|
79
99
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
80
100
|
for (const file of agent.attachedFiles) {
|
|
81
101
|
if (!file.serviceMetadata?.fileData)
|
|
@@ -93,9 +113,11 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
93
113
|
});
|
|
94
114
|
}
|
|
95
115
|
}
|
|
116
|
+
// Handle attached artifacts
|
|
96
117
|
if (agent.attachedArtifacts && agent.attachedArtifacts.length > 0) {
|
|
97
118
|
for (const artifactId of agent.attachedArtifacts) {
|
|
98
119
|
const content = agent.artifactService.getArtifact(artifactId);
|
|
120
|
+
// Only include text artifacts (skip binary/image artifacts)
|
|
99
121
|
if (content && typeof content === 'string') {
|
|
100
122
|
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
101
123
|
const fileName = metadata ? `${metadata.name}.md` : 'artifact.md';
|
|
@@ -111,6 +133,7 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
111
133
|
}
|
|
112
134
|
}
|
|
113
135
|
}
|
|
136
|
+
// Small local models need an explicit schema nudge to produce JSON
|
|
114
137
|
if (jsonSchema) {
|
|
115
138
|
messages.push({
|
|
116
139
|
role: 'system',
|
|
@@ -122,7 +145,9 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
122
145
|
],
|
|
123
146
|
});
|
|
124
147
|
}
|
|
148
|
+
// Add conversation history
|
|
125
149
|
messages.push(...agent.history);
|
|
150
|
+
// Add user prompt to local array
|
|
126
151
|
if (prompt) {
|
|
127
152
|
messages.push({
|
|
128
153
|
role: 'user',
|
|
@@ -141,6 +166,8 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
141
166
|
if (choice.message.content)
|
|
142
167
|
responseText = choice.message.content;
|
|
143
168
|
}
|
|
169
|
+
// Strip <think> blocks local reasoning models emit before any
|
|
170
|
+
// further processing
|
|
144
171
|
responseText = this.trimResponseText(responseText);
|
|
145
172
|
if (jsonSchema) {
|
|
146
173
|
responseText = this.trimToJson(responseText);
|
|
@@ -154,6 +181,8 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
154
181
|
logger_1.logger.error(error);
|
|
155
182
|
throw error;
|
|
156
183
|
}
|
|
184
|
+
// Only modify agent.history if saveResponse=true
|
|
185
|
+
// Note: We don't save the temporary system instructions to history
|
|
157
186
|
if (saveResponse) {
|
|
158
187
|
this.addToConversationHistory(agent, prompt, false);
|
|
159
188
|
this.addToConversationHistory(agent, responseText, true);
|
|
@@ -162,6 +191,13 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
162
191
|
return this.parseStructuredResponse(responseText);
|
|
163
192
|
return responseText;
|
|
164
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
196
|
+
* @param agent The agent to add the message to
|
|
197
|
+
* @param message The formatted message to add
|
|
198
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
199
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
200
|
+
*/
|
|
165
201
|
addToConversationHistory(agent, message, fromSelf = false, developer = false) {
|
|
166
202
|
if (!agent.history) {
|
|
167
203
|
agent.history = [];
|
|
@@ -177,6 +213,12 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
|
|
|
177
213
|
});
|
|
178
214
|
agent.trimHistoryIfNeeded();
|
|
179
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Tracks token usage for every request; charges cost only when the model
|
|
218
|
+
* has a model_prices.json entry. Unpriced models are the norm for
|
|
219
|
+
* self-hosted servers, so their absence is logged at debug level, not as
|
|
220
|
+
* an error.
|
|
221
|
+
*/
|
|
180
222
|
computeMessageCost(agent, usage, modelInfo) {
|
|
181
223
|
const promptTokens = usage.prompt_tokens || 0;
|
|
182
224
|
const completionTokens = usage.completion_tokens || 0;
|