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
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in tool packs: sets of native tools that ship with Briyah.
|
|
4
|
+
*
|
|
5
|
+
* Registration is process-global, matching how native tools work generally. What
|
|
6
|
+
* used to gate it — `BRIYAH_TOOL_PACKS` — no longer does: a pack's tools are
|
|
7
|
+
* registered at boot and *enablement is per user*, held in their config and
|
|
8
|
+
* applied where tools are listed rather than where they are registered. See
|
|
9
|
+
* `packs/pack.service.ts`.
|
|
10
|
+
*
|
|
11
|
+
* Registering everything is safe because registration alone grants nothing. A
|
|
12
|
+
* tool reaches an agent only through `agent.toolNames`, and
|
|
13
|
+
* `AppService.listNativeToolSummaries` will not offer a tool whose pack the user
|
|
14
|
+
* has not switched on.
|
|
15
|
+
*/
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.dnd5eTools = void 0;
|
|
4
18
|
exports.installToolPacks = installToolPacks;
|
|
@@ -9,9 +23,33 @@ const dnd5e_1 = require("./dnd5e");
|
|
|
9
23
|
Object.defineProperty(exports, "dnd5eTools", { enumerable: true, get: function () { return dnd5e_1.dnd5eTools; } });
|
|
10
24
|
const core_1 = require("../core");
|
|
11
25
|
const logger_1 = require("../../common/logger");
|
|
26
|
+
/**
|
|
27
|
+
* The packs that ship with the npm package, by name.
|
|
28
|
+
*
|
|
29
|
+
* Only the bundled ones. A pack this repository runs but does not publish is
|
|
30
|
+
* registered by `main.ts` through {@link registerPack} — `acts` implements a
|
|
31
|
+
* curriculum whose rules, cards and chapter scripts belong to their author, so it
|
|
32
|
+
* is kept out of the package by leaving it out of here.
|
|
33
|
+
*
|
|
34
|
+
* That boundary has to be a static import rather than a directory scan: the server
|
|
35
|
+
* is bundled by webpack into a single `main.js`, so at runtime there is no pack
|
|
36
|
+
* directory to look in, and a computed `require` makes webpack try to bundle every
|
|
37
|
+
* file beside this one. The pack *content* is discovered from `data/packs/`,
|
|
38
|
+
* because content is read at runtime and never bundled.
|
|
39
|
+
*/
|
|
12
40
|
const PACKS = {
|
|
13
41
|
dnd5e: dnd5e_1.dnd5eTools,
|
|
14
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Registers the core tools and every built-in pack's tools.
|
|
45
|
+
*
|
|
46
|
+
* Core first, so a pack that shipped a colliding name would overwrite it loudly
|
|
47
|
+
* through `registerTool`'s warning rather than the other way round. `packs.spec.ts`
|
|
48
|
+
* is what actually stops that happening.
|
|
49
|
+
*
|
|
50
|
+
* @param registry The process-wide native tool registry
|
|
51
|
+
* @returns The names of the tools that were registered
|
|
52
|
+
*/
|
|
15
53
|
function installToolPacks(registry) {
|
|
16
54
|
const core = (0, core_1.coreTools)().map((tool) => ({ ...tool, group: core_1.CORE_TOOL_GROUP }));
|
|
17
55
|
registry.registerTools(core);
|
|
@@ -21,6 +59,17 @@ function installToolPacks(registry) {
|
|
|
21
59
|
...registerToolPacks(registry, Object.keys(PACKS).join(',')),
|
|
22
60
|
];
|
|
23
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Registers the named tool packs into the native registry.
|
|
64
|
+
*
|
|
65
|
+
* Kept alongside {@link installToolPacks} for an SDK host that wants only some of
|
|
66
|
+
* the built-in packs' tools in its process.
|
|
67
|
+
*
|
|
68
|
+
* @param registry The process-wide native tool registry
|
|
69
|
+
* @param packList A comma-separated list of pack names. Empty or undefined
|
|
70
|
+
* registers nothing.
|
|
71
|
+
* @returns The names of the tools that were registered
|
|
72
|
+
*/
|
|
24
73
|
function registerToolPacks(registry, packList) {
|
|
25
74
|
const names = (packList || '')
|
|
26
75
|
.split(',')
|
|
@@ -39,12 +88,29 @@ function registerToolPacks(registry, packList) {
|
|
|
39
88
|
}
|
|
40
89
|
return registered;
|
|
41
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Registers one pack's tools under a name.
|
|
93
|
+
*
|
|
94
|
+
* For a pack that is not in {@link PACKS}: one this repository runs but does not
|
|
95
|
+
* publish, or one an SDK host wrote itself. `main.ts` registers `acts` this way,
|
|
96
|
+
* and `main.ts` is excluded from the SDK build, so the published package has no
|
|
97
|
+
* path to it at all.
|
|
98
|
+
*
|
|
99
|
+
* @param registry The process-wide native tool registry
|
|
100
|
+
* @param name The pack name, stamped on every tool as its group
|
|
101
|
+
* @param tools The pack's tool definitions
|
|
102
|
+
* @returns The names of the tools that were registered
|
|
103
|
+
*/
|
|
42
104
|
function registerPack(registry, name, tools) {
|
|
105
|
+
// Stamp the pack name on every tool so the UI can collapse the pack into
|
|
106
|
+
// one node, and so listing can filter by what the user has enabled. A
|
|
107
|
+
// pack's definitions do not name their own pack.
|
|
43
108
|
const grouped = tools.map((tool) => ({ ...tool, group: name }));
|
|
44
109
|
registry.registerTools(grouped);
|
|
45
110
|
logger_1.logger.log(`Registered tool pack "${name}" with ${grouped.length} tools`);
|
|
46
111
|
return grouped.map((tool) => tool.name);
|
|
47
112
|
}
|
|
113
|
+
/** The names of the packs that ship with the package. */
|
|
48
114
|
function availableToolPacks() {
|
|
49
115
|
return Object.keys(PACKS);
|
|
50
116
|
}
|
|
@@ -1,13 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argument coercion for tool handlers.
|
|
3
|
+
*
|
|
4
|
+
* Tool arguments arrive from `JSON.parse` of text an LLM wrote, and the only
|
|
5
|
+
* validation Briyah performs is that required parameters are present — there is
|
|
6
|
+
* no type checking and no rejection of extra keys. So a parameter declared
|
|
7
|
+
* `number` routinely arrives as `"3"`, `"+3"` or `" 3 "`, and a parameter
|
|
8
|
+
* declared `string` that is documented as holding JSON arrives about as often as
|
|
9
|
+
* a real object as it does as a string. Every handler runs its arguments through
|
|
10
|
+
* this module before touching them.
|
|
11
|
+
*/
|
|
12
|
+
/** Raised when an argument cannot be coerced. Carries a repair hint for the model. */
|
|
1
13
|
export declare class ArgumentError extends Error {
|
|
2
14
|
constructor(param: string, received: unknown, expected: string, example?: string);
|
|
3
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Coerces a value to a number, tolerating the string forms an LLM emits.
|
|
18
|
+
* @param value The raw argument value
|
|
19
|
+
* @param param The parameter name, for the error message
|
|
20
|
+
* @param fallback Returned when the value is absent
|
|
21
|
+
* @returns The number
|
|
22
|
+
* @throws {ArgumentError} If the value is present but not numeric
|
|
23
|
+
*/
|
|
4
24
|
export declare function num(value: unknown, param: string, fallback?: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Coerces a value to an integer, rounding toward zero.
|
|
27
|
+
* @param value The raw argument value
|
|
28
|
+
* @param param The parameter name, for the error message
|
|
29
|
+
* @param fallback Returned when the value is absent
|
|
30
|
+
* @returns The integer
|
|
31
|
+
*/
|
|
5
32
|
export declare function int(value: unknown, param: string, fallback?: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Coerces a value to a boolean, accepting true/false, "true"/"false",
|
|
35
|
+
* "yes"/"no" and 1/0.
|
|
36
|
+
* @param value The raw argument value
|
|
37
|
+
* @param fallback Returned when the value is absent or unrecognized
|
|
38
|
+
* @returns The boolean
|
|
39
|
+
*/
|
|
6
40
|
export declare function bool(value: unknown, fallback?: boolean): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Coerces a value to a trimmed string.
|
|
43
|
+
* @param value The raw argument value
|
|
44
|
+
* @param param The parameter name, for the error message
|
|
45
|
+
* @param fallback Returned when the value is absent
|
|
46
|
+
* @returns The trimmed string
|
|
47
|
+
* @throws {ArgumentError} If the value is required and absent
|
|
48
|
+
*/
|
|
7
49
|
export declare function str(value: unknown, param: string, fallback?: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Splits a delimited list parameter into entries. Semicolons are the documented
|
|
52
|
+
* separator, but commas, newlines and a genuine JSON array are all accepted
|
|
53
|
+
* because models mix them freely.
|
|
54
|
+
* @param value The raw argument value
|
|
55
|
+
* @returns The non-empty trimmed entries, or [] when absent
|
|
56
|
+
*/
|
|
8
57
|
export declare function list(value: unknown): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Reads a parameter documented as holding a JSON object. Accepts either a real
|
|
60
|
+
* object or a JSON string, and tolerates a fenced ```json block around it.
|
|
61
|
+
* @param value The raw argument value
|
|
62
|
+
* @param param The parameter name, for the error message
|
|
63
|
+
* @param example A correct example, quoted back to the model on failure
|
|
64
|
+
* @returns The object, or {} when absent
|
|
65
|
+
* @throws {ArgumentError} If the value is present but is not an object
|
|
66
|
+
*/
|
|
9
67
|
export declare function jsonObject(value: unknown, param: string, example?: string): Record<string, any>;
|
|
68
|
+
/**
|
|
69
|
+
* Reads a parameter documented as holding a JSON array of objects.
|
|
70
|
+
* @param value The raw argument value
|
|
71
|
+
* @param param The parameter name, for the error message
|
|
72
|
+
* @param example A correct example, quoted back to the model on failure
|
|
73
|
+
* @returns The array, or [] when absent
|
|
74
|
+
* @throws {ArgumentError} If the value is present but is not an array
|
|
75
|
+
*/
|
|
10
76
|
export declare function jsonArray(value: unknown, param: string, example?: string): any[];
|
|
77
|
+
/**
|
|
78
|
+
* Normalizes a name for comparison: lowercase, punctuation and extra
|
|
79
|
+
* whitespace removed. Lets "Thalia Emberwood" match "thalia emberwood" and
|
|
80
|
+
* "Healer's Kit" match "healers kit".
|
|
81
|
+
* @param name The name to normalize
|
|
82
|
+
* @returns The comparison key
|
|
83
|
+
*/
|
|
11
84
|
export declare function nameKey(name: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Finds an entry in a list of known names, matching loosely.
|
|
87
|
+
*
|
|
88
|
+
* Returns the first candidate when several match, which is safe for a short list
|
|
89
|
+
* whose entries are known to be distinct — a party of characters. For a long list
|
|
90
|
+
* where partial names genuinely collide, use {@link matchNames} and report the
|
|
91
|
+
* ambiguity instead of picking silently.
|
|
92
|
+
* @param wanted The name the model supplied
|
|
93
|
+
* @param known The names that exist
|
|
94
|
+
* @returns The matching known name, or undefined
|
|
95
|
+
*/
|
|
12
96
|
export declare function matchName(wanted: string, known: string[]): string | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Finds every entry that could be what the caller meant, from the most precise
|
|
99
|
+
* tier that produced anything: an exact match, else a shared first word, else a
|
|
100
|
+
* shared prefix in either direction.
|
|
101
|
+
*
|
|
102
|
+
* Tiers do not merge. An exact match never comes back alongside loose ones, so a
|
|
103
|
+
* query for "bandit" resolves cleanly even when "bandit captain" also exists.
|
|
104
|
+
* @param wanted The name the model supplied
|
|
105
|
+
* @param known The names that exist
|
|
106
|
+
* @returns Every candidate in the best matching tier; empty when nothing matches
|
|
107
|
+
*/
|
|
13
108
|
export declare function matchNames(wanted: string, known: string[]): string[];
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Argument coercion for tool handlers.
|
|
4
|
+
*
|
|
5
|
+
* Tool arguments arrive from `JSON.parse` of text an LLM wrote, and the only
|
|
6
|
+
* validation Briyah performs is that required parameters are present — there is
|
|
7
|
+
* no type checking and no rejection of extra keys. So a parameter declared
|
|
8
|
+
* `number` routinely arrives as `"3"`, `"+3"` or `" 3 "`, and a parameter
|
|
9
|
+
* declared `string` that is documented as holding JSON arrives about as often as
|
|
10
|
+
* a real object as it does as a string. Every handler runs its arguments through
|
|
11
|
+
* this module before touching them.
|
|
12
|
+
*/
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.ArgumentError = void 0;
|
|
4
15
|
exports.num = num;
|
|
@@ -11,6 +22,7 @@ exports.jsonArray = jsonArray;
|
|
|
11
22
|
exports.nameKey = nameKey;
|
|
12
23
|
exports.matchName = matchName;
|
|
13
24
|
exports.matchNames = matchNames;
|
|
25
|
+
/** Raised when an argument cannot be coerced. Carries a repair hint for the model. */
|
|
14
26
|
class ArgumentError extends Error {
|
|
15
27
|
constructor(param, received, expected, example) {
|
|
16
28
|
const got = received === undefined ? 'nothing' : JSON.stringify(received);
|
|
@@ -20,6 +32,14 @@ class ArgumentError extends Error {
|
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
34
|
exports.ArgumentError = ArgumentError;
|
|
35
|
+
/**
|
|
36
|
+
* Coerces a value to a number, tolerating the string forms an LLM emits.
|
|
37
|
+
* @param value The raw argument value
|
|
38
|
+
* @param param The parameter name, for the error message
|
|
39
|
+
* @param fallback Returned when the value is absent
|
|
40
|
+
* @returns The number
|
|
41
|
+
* @throws {ArgumentError} If the value is present but not numeric
|
|
42
|
+
*/
|
|
23
43
|
function num(value, param, fallback) {
|
|
24
44
|
if (value === undefined || value === null || value === '') {
|
|
25
45
|
if (fallback !== undefined)
|
|
@@ -35,9 +55,23 @@ function num(value, param, fallback) {
|
|
|
35
55
|
}
|
|
36
56
|
throw new ArgumentError(param, value, 'a number', '3');
|
|
37
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Coerces a value to an integer, rounding toward zero.
|
|
60
|
+
* @param value The raw argument value
|
|
61
|
+
* @param param The parameter name, for the error message
|
|
62
|
+
* @param fallback Returned when the value is absent
|
|
63
|
+
* @returns The integer
|
|
64
|
+
*/
|
|
38
65
|
function int(value, param, fallback) {
|
|
39
66
|
return Math.trunc(num(value, param, fallback));
|
|
40
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Coerces a value to a boolean, accepting true/false, "true"/"false",
|
|
70
|
+
* "yes"/"no" and 1/0.
|
|
71
|
+
* @param value The raw argument value
|
|
72
|
+
* @param fallback Returned when the value is absent or unrecognized
|
|
73
|
+
* @returns The boolean
|
|
74
|
+
*/
|
|
41
75
|
function bool(value, fallback = false) {
|
|
42
76
|
if (value === undefined || value === null || value === '')
|
|
43
77
|
return fallback;
|
|
@@ -54,6 +88,14 @@ function bool(value, fallback = false) {
|
|
|
54
88
|
}
|
|
55
89
|
return fallback;
|
|
56
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Coerces a value to a trimmed string.
|
|
93
|
+
* @param value The raw argument value
|
|
94
|
+
* @param param The parameter name, for the error message
|
|
95
|
+
* @param fallback Returned when the value is absent
|
|
96
|
+
* @returns The trimmed string
|
|
97
|
+
* @throws {ArgumentError} If the value is required and absent
|
|
98
|
+
*/
|
|
57
99
|
function str(value, param, fallback) {
|
|
58
100
|
if (value === undefined || value === null) {
|
|
59
101
|
if (fallback !== undefined)
|
|
@@ -66,6 +108,13 @@ function str(value, param, fallback) {
|
|
|
66
108
|
return String(value);
|
|
67
109
|
throw new ArgumentError(param, value, 'a string');
|
|
68
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Splits a delimited list parameter into entries. Semicolons are the documented
|
|
113
|
+
* separator, but commas, newlines and a genuine JSON array are all accepted
|
|
114
|
+
* because models mix them freely.
|
|
115
|
+
* @param value The raw argument value
|
|
116
|
+
* @returns The non-empty trimmed entries, or [] when absent
|
|
117
|
+
*/
|
|
69
118
|
function list(value) {
|
|
70
119
|
if (value === undefined || value === null || value === '')
|
|
71
120
|
return [];
|
|
@@ -77,6 +126,15 @@ function list(value) {
|
|
|
77
126
|
.map((v) => v.trim())
|
|
78
127
|
.filter((v) => v.length > 0);
|
|
79
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Reads a parameter documented as holding a JSON object. Accepts either a real
|
|
131
|
+
* object or a JSON string, and tolerates a fenced ```json block around it.
|
|
132
|
+
* @param value The raw argument value
|
|
133
|
+
* @param param The parameter name, for the error message
|
|
134
|
+
* @param example A correct example, quoted back to the model on failure
|
|
135
|
+
* @returns The object, or {} when absent
|
|
136
|
+
* @throws {ArgumentError} If the value is present but is not an object
|
|
137
|
+
*/
|
|
80
138
|
function jsonObject(value, param, example) {
|
|
81
139
|
if (value === undefined || value === null || value === '')
|
|
82
140
|
return {};
|
|
@@ -97,6 +155,14 @@ function jsonObject(value, param, example) {
|
|
|
97
155
|
}
|
|
98
156
|
throw new ArgumentError(param, value, 'a JSON object', example);
|
|
99
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Reads a parameter documented as holding a JSON array of objects.
|
|
160
|
+
* @param value The raw argument value
|
|
161
|
+
* @param param The parameter name, for the error message
|
|
162
|
+
* @param example A correct example, quoted back to the model on failure
|
|
163
|
+
* @returns The array, or [] when absent
|
|
164
|
+
* @throws {ArgumentError} If the value is present but is not an array
|
|
165
|
+
*/
|
|
100
166
|
function jsonArray(value, param, example) {
|
|
101
167
|
if (value === undefined || value === null || value === '')
|
|
102
168
|
return [];
|
|
@@ -108,6 +174,7 @@ function jsonArray(value, param, example) {
|
|
|
108
174
|
const parsed = JSON.parse(cleaned);
|
|
109
175
|
if (Array.isArray(parsed))
|
|
110
176
|
return parsed;
|
|
177
|
+
// A single object where a list was asked for is a common near-miss.
|
|
111
178
|
if (parsed && typeof parsed === 'object')
|
|
112
179
|
return [parsed];
|
|
113
180
|
}
|
|
@@ -117,11 +184,19 @@ function jsonArray(value, param, example) {
|
|
|
117
184
|
}
|
|
118
185
|
throw new ArgumentError(param, value, 'a JSON array', example);
|
|
119
186
|
}
|
|
187
|
+
/** Removes a surrounding markdown code fence, which models add unprompted. */
|
|
120
188
|
function stripCodeFence(text) {
|
|
121
189
|
const trimmed = text.trim();
|
|
122
190
|
const fenced = /^```(?:json)?\s*\n?([\s\S]*?)\n?```$/.exec(trimmed);
|
|
123
191
|
return fenced ? fenced[1].trim() : trimmed;
|
|
124
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Normalizes a name for comparison: lowercase, punctuation and extra
|
|
195
|
+
* whitespace removed. Lets "Thalia Emberwood" match "thalia emberwood" and
|
|
196
|
+
* "Healer's Kit" match "healers kit".
|
|
197
|
+
* @param name The name to normalize
|
|
198
|
+
* @returns The comparison key
|
|
199
|
+
*/
|
|
125
200
|
function nameKey(name) {
|
|
126
201
|
return name
|
|
127
202
|
.toLowerCase()
|
|
@@ -129,10 +204,32 @@ function nameKey(name) {
|
|
|
129
204
|
.replace(/\s+/g, ' ')
|
|
130
205
|
.trim();
|
|
131
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Finds an entry in a list of known names, matching loosely.
|
|
209
|
+
*
|
|
210
|
+
* Returns the first candidate when several match, which is safe for a short list
|
|
211
|
+
* whose entries are known to be distinct — a party of characters. For a long list
|
|
212
|
+
* where partial names genuinely collide, use {@link matchNames} and report the
|
|
213
|
+
* ambiguity instead of picking silently.
|
|
214
|
+
* @param wanted The name the model supplied
|
|
215
|
+
* @param known The names that exist
|
|
216
|
+
* @returns The matching known name, or undefined
|
|
217
|
+
*/
|
|
132
218
|
function matchName(wanted, known) {
|
|
133
219
|
const candidates = matchNames(wanted, known);
|
|
134
220
|
return candidates.length > 0 ? candidates[0] : undefined;
|
|
135
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Finds every entry that could be what the caller meant, from the most precise
|
|
224
|
+
* tier that produced anything: an exact match, else a shared first word, else a
|
|
225
|
+
* shared prefix in either direction.
|
|
226
|
+
*
|
|
227
|
+
* Tiers do not merge. An exact match never comes back alongside loose ones, so a
|
|
228
|
+
* query for "bandit" resolves cleanly even when "bandit captain" also exists.
|
|
229
|
+
* @param wanted The name the model supplied
|
|
230
|
+
* @param known The names that exist
|
|
231
|
+
* @returns Every candidate in the best matching tier; empty when nothing matches
|
|
232
|
+
*/
|
|
136
233
|
function matchNames(wanted, known) {
|
|
137
234
|
const key = nameKey(wanted);
|
|
138
235
|
if (!key)
|
|
@@ -140,6 +237,7 @@ function matchNames(wanted, known) {
|
|
|
140
237
|
const exact = known.filter((k) => nameKey(k) === key);
|
|
141
238
|
if (exact.length > 0)
|
|
142
239
|
return exact;
|
|
240
|
+
// First word, so "Thalia" finds "Thalia Emberwood"
|
|
143
241
|
const firstWord = known.filter((k) => nameKey(k).split(' ')[0] === key.split(' ')[0]);
|
|
144
242
|
if (firstWord.length > 0)
|
|
145
243
|
return firstWord;
|
|
@@ -1,24 +1,128 @@
|
|
|
1
1
|
import { ToolDefinition, ToolRunResult } from '../../../shared/types/app.types';
|
|
2
2
|
import { ToolStoreService } from './tool-store.service';
|
|
3
3
|
import { NativeToolRegistry } from './native-tool-registry.service';
|
|
4
|
-
import { NativeToolDefinition, ToolHelpers, ToolContext, ToolPackDocuments, ToolRoomAccess } from './native-tool.types';
|
|
4
|
+
import { NativeToolDefinition, ToolHelpers, ToolContext, ToolIllustration, ToolPackDocuments, ToolRoomAccess } from './native-tool.types';
|
|
5
5
|
type CompiledTool = (args: Record<string, any>, helpers: ToolHelpers, context: ToolContext) => Promise<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Executes tools an agent calls with the EXECUTE action. Tools come from two
|
|
8
|
+
* sources, resolved native-first:
|
|
9
|
+
* - Native tools (host-implemented functions in {@link NativeToolRegistry}) —
|
|
10
|
+
* trusted, always available.
|
|
11
|
+
* - User-authored tools (JS-string code in {@link ToolStoreService}) — gated by
|
|
12
|
+
* `allowUserAuthoredTools`; the code is the body of an async function
|
|
13
|
+
* receiving (args, helpers, context).
|
|
14
|
+
*
|
|
15
|
+
* `context` is the host's opaque per-invocation value (see AppService.sendRoomMessage);
|
|
16
|
+
* it is threaded through unchanged and never inspected here.
|
|
17
|
+
*/
|
|
6
18
|
export declare class ToolExecutionService {
|
|
7
19
|
private readonly toolStore;
|
|
8
20
|
private readonly nativeRegistry;
|
|
9
21
|
private readonly allowUserAuthoredTools;
|
|
10
22
|
private readonly packDocuments?;
|
|
11
23
|
private compiledCache;
|
|
24
|
+
/**
|
|
25
|
+
* @param toolStore The user's store of user-authored tools
|
|
26
|
+
* @param nativeRegistry The process-wide registry of host-implemented tools
|
|
27
|
+
* @param allowUserAuthoredTools Whether stored JS-string tools may run at all
|
|
28
|
+
* @param packDocuments Read access to installed packs' shipped documents,
|
|
29
|
+
* exposed to every tool as `helpers.packDocuments`. Optional so a unit test
|
|
30
|
+
* can build the service with nothing behind it; a tool that needs it fails
|
|
31
|
+
* with its own message.
|
|
32
|
+
*/
|
|
12
33
|
constructor(toolStore: ToolStoreService, nativeRegistry: NativeToolRegistry, allowUserAuthoredTools?: boolean, packDocuments?: ToolPackDocuments);
|
|
34
|
+
/**
|
|
35
|
+
* Compiles a user-authored tool's code into an async function.
|
|
36
|
+
* Throws SyntaxError on bad code.
|
|
37
|
+
* @param tool The tool definition to compile
|
|
38
|
+
* @returns The compiled async function
|
|
39
|
+
*/
|
|
13
40
|
static compile(tool: ToolDefinition): CompiledTool;
|
|
14
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The room-facing entry point: validates the grant, the tool, and the
|
|
43
|
+
* arguments before running. All failures are returned in-band as
|
|
44
|
+
* { ok: false, error } so the calling agent can recover.
|
|
45
|
+
* @param name The tool name from the agent's EXECUTE message
|
|
46
|
+
* @param contentJson The message content: a JSON object of named arguments
|
|
47
|
+
* @param grantedNames The tool names granted to the calling agent
|
|
48
|
+
* @param context The host's opaque per-invocation context
|
|
49
|
+
* @param room Access to the calling agent's room, exposed as helpers.room
|
|
50
|
+
* @returns The tool run result
|
|
51
|
+
*/
|
|
52
|
+
runForAgent(name: string, contentJson: string, grantedNames: string[], context?: ToolContext, room?: ToolRoomAccess, illustration?: ToolIllustration): Promise<ToolRunResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Runs a tool for the API test endpoint. Same validation as the agent path,
|
|
55
|
+
* minus the grant check, so the Test panel shows the errors agents would get.
|
|
56
|
+
* There is no room here, so helpers.room is absent and tools that require it
|
|
57
|
+
* fail with their own explanatory message.
|
|
58
|
+
* @param name The tool name
|
|
59
|
+
* @param args Named arguments for the tool
|
|
60
|
+
* @param context Optional opaque context (usually absent for UI tests)
|
|
61
|
+
* @returns The tool run result
|
|
62
|
+
*/
|
|
15
63
|
test(name: string, args: Record<string, any>, context?: ToolContext): Promise<ToolRunResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves a tool (native first, then user-authored), checks required
|
|
66
|
+
* parameters, and runs it.
|
|
67
|
+
* @param name The tool name
|
|
68
|
+
* @param args Named arguments for the tool
|
|
69
|
+
* @param context The host's opaque per-invocation context
|
|
70
|
+
* @param room Access to the calling agent's room, if any
|
|
71
|
+
* @returns The tool run result
|
|
72
|
+
*/
|
|
16
73
|
private runValidated;
|
|
17
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Checks the LLM-supplied arguments against the declared parameters:
|
|
76
|
+
* required presence first, then any declared `enum`. Returns a ready-to-send
|
|
77
|
+
* error message, or null when the arguments are acceptable.
|
|
78
|
+
*
|
|
79
|
+
* An enum failure names the allowed values, so the agent can correct itself
|
|
80
|
+
* on its next turn rather than guessing again — the same self-correcting
|
|
81
|
+
* contract the rest of runForAgent uses. An omitted optional parameter is
|
|
82
|
+
* not enum-checked; `null` is treated as omitted, since models routinely
|
|
83
|
+
* send it for "not applicable".
|
|
84
|
+
* @param parameters The tool's declared parameters
|
|
85
|
+
* @param args The named arguments the agent supplied
|
|
86
|
+
* @returns An error message, or null when the arguments are acceptable
|
|
87
|
+
*/
|
|
88
|
+
private static validateParams;
|
|
89
|
+
/**
|
|
90
|
+
* Runs an invocation with a timeout and an abort-wired fetch helper. Fetches
|
|
91
|
+
* made through helpers.fetch are aborted when the timeout fires.
|
|
92
|
+
* @param name The tool name (for logging)
|
|
93
|
+
* @param toolTimeoutMs The tool's configured timeout, if any
|
|
94
|
+
* @param toolMaxResultChars The tool's configured result budget, if any
|
|
95
|
+
* @param invoke Runs the tool with the provided helpers
|
|
96
|
+
* @param room Access to the calling agent's room, omitted when there is none
|
|
97
|
+
* @returns The tool run result
|
|
98
|
+
*/
|
|
18
99
|
private execute;
|
|
19
100
|
private getCompiled;
|
|
101
|
+
/**
|
|
102
|
+
* Caps an oversized result while keeping it valid JSON of the same shape.
|
|
103
|
+
*
|
|
104
|
+
* This used to serialize, slice at the budget, and return the resulting
|
|
105
|
+
* string. That handed the agent unparseable half-JSON with the explanation
|
|
106
|
+
* stranded at the end, past the cut — and because the object had become a
|
|
107
|
+
* string it also defeated Room.describeToolResult's `detail`/`summary`
|
|
108
|
+
* lookup, so the room log lost its readable line for exactly the results a
|
|
109
|
+
* person most wanted to read. Instead:
|
|
110
|
+
*
|
|
111
|
+
* - An object keeps its keys. Its longest string properties are clipped, in
|
|
112
|
+
* order, until the whole thing fits, and `_truncated`/`_originalChars`
|
|
113
|
+
* record what happened so the agent can say so or ask for less.
|
|
114
|
+
* - A bare string is clipped in place with the same marker appended.
|
|
115
|
+
* - Anything that cannot be clipped that way — a long array, say — is
|
|
116
|
+
* replaced by a small object saying so, which is at least parseable.
|
|
117
|
+
*
|
|
118
|
+
* @param result The raw tool result
|
|
119
|
+
* @param maxChars The serialized-JSON budget for this tool
|
|
120
|
+
* @returns A result that serializes within budget
|
|
121
|
+
*/
|
|
20
122
|
private static truncateResult;
|
|
123
|
+
/** @returns The native tool definitions registered in this process. */
|
|
21
124
|
listNativeTools(): NativeToolDefinition[];
|
|
125
|
+
/** @returns Whether user-authored (string) tools may run in this deployment. */
|
|
22
126
|
get userAuthoredToolsEnabled(): boolean;
|
|
23
127
|
}
|
|
24
128
|
export {};
|