briyah 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +216 -0
- package/README.md +43 -7
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/data/packs/dnd5e/agents/player.json +11 -11
- package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -20
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +19 -12
- package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +10 -6
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
- package/dist-sdk/server/src/ai/agent.d.ts +196 -0
- package/dist-sdk/server/src/ai/agent.js +224 -11
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +38 -1
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +87 -0
- package/dist-sdk/server/src/app.controller.js +272 -12
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1662 -0
- package/dist-sdk/server/src/app.service.js +1862 -6
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +27 -0
- package/dist-sdk/server/src/room/nickname.js +41 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +26 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
- package/dist-sdk/server/src/room/room-factory.js +14 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +177 -0
- package/dist-sdk/server/src/room/room-store.service.js +242 -5
- package/dist-sdk/server/src/room/room.d.ts +906 -1
- package/dist-sdk/server/src/room/room.js +1525 -34
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +38 -3
- package/dist-sdk/server/src/rpg/rpg-roster.js +49 -49
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +108 -5
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.d.ts +0 -1
- package/dist-sdk/server/src/sdk/index.js +24 -3
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +398 -0
- package/dist-sdk/server/src/story/story.service.js +829 -25
- package/dist-sdk/server/src/tools/core/index.d.ts +25 -0
- package/dist-sdk/server/src/tools/core/index.js +31 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +10 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +72 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +186 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +125 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +52 -2
- package/dist-sdk/server/src/tools/packs/index.js +83 -9
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
- package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +285 -14
- package/dist-sdk/shared/types/app.types.js +3 -0
- package/package.json +167 -139
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/data/packs/acts/agents/character-guide.json +0 -6
- package/data/packs/acts/agents/discipleship-mentor.json +0 -6
- package/data/packs/acts/agents/mentor-coach.json +0 -6
- package/data/packs/acts/agents/student.json +0 -13
- package/data/packs/acts/agents/table-moderator.json +0 -6
- package/data/packs/acts/artifacts/chapter-01-acts-1.md +0 -405
- package/data/packs/acts/artifacts/chapter-02-acts-2.md +0 -443
- package/data/packs/acts/artifacts/chapter-03-acts-3.md +0 -409
- package/data/packs/acts/artifacts/chapter-04-acts-4.md +0 -438
- package/data/packs/acts/artifacts/chapter-05-acts-5.md +0 -434
- package/data/packs/acts/artifacts/chapter-06-acts-6.md +0 -441
- package/data/packs/acts/artifacts/chapter-07-acts-7.md +0 -472
- package/data/packs/acts/artifacts/chapter-08-acts-8.md +0 -512
- package/data/packs/acts/artifacts/chapter-09-acts-9.md +0 -346
- package/data/packs/acts/artifacts/chapter-10-acts-10.md +0 -367
- package/data/packs/acts/artifacts/chapter-11-acts-11.md +0 -391
- package/data/packs/acts/artifacts/chapter-12-acts-12.md +0 -390
- package/data/packs/acts/artifacts/chapter-13-acts-13.md +0 -388
- package/data/packs/acts/artifacts/chapter-14-acts-14.md +0 -466
- package/data/packs/acts/artifacts/chapter-15-acts-15.md +0 -413
- package/data/packs/acts/artifacts/chapter-16-acts-16.md +0 -585
- package/data/packs/acts/artifacts/chapter-17-acts-17.md +0 -428
- package/data/packs/acts/artifacts/chapter-18-acts-18.md +0 -486
- package/data/packs/acts/artifacts/chapter-19-acts-19.md +0 -461
- package/data/packs/acts/artifacts/chapter-20-acts-20.md +0 -389
- package/data/packs/acts/artifacts/chapter-21-acts-21.md +0 -452
- package/data/packs/acts/artifacts/chapter-22-acts-22.md +0 -424
- package/data/packs/acts/artifacts/chapter-23-acts-23.md +0 -395
- package/data/packs/acts/artifacts/chapter-24-acts-24.md +0 -446
- package/data/packs/acts/artifacts/chapter-25-acts-25.md +0 -391
- package/data/packs/acts/artifacts/chapter-26-acts-26.md +0 -431
- package/data/packs/acts/artifacts/chapter-27-acts-27.md +0 -530
- package/data/packs/acts/artifacts/chapter-28-acts-28.md +0 -1871
- package/data/packs/acts/artifacts/chapters.manifest.json +0 -170
- package/data/packs/acts/artifacts/character_guide-creation.md +0 -112
- package/data/packs/acts/artifacts/discipleship_mentor-procedure.md +0 -154
- package/data/packs/acts/artifacts/discipleship_mentor-systems.md +0 -72
- package/data/packs/acts/artifacts/manifest.json +0 -197
- package/data/packs/acts/artifacts/stage-guide.md +0 -94
- package/data/packs/acts/pack.json +0 -6
- package/data/packs/acts/prompts/acts_player/defaults_config.json +0 -5
- package/data/packs/acts/prompts/acts_player/perceive.json +0 -29
- package/data/packs/acts/prompts/acts_player/perceive.prompt +0 -87
- package/data/packs/acts/prompts/acts_player/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/acts_room_moderator/defaults_config.json +0 -9
- package/data/packs/acts/prompts/acts_room_moderator/moderate.json +0 -34
- package/data/packs/acts/prompts/acts_room_moderator/moderate.prompt +0 -70
- package/data/packs/acts/prompts/acts_room_moderator/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/character_guide/defaults_config.json +0 -18
- package/data/packs/acts/prompts/character_guide/perceive.json +0 -29
- package/data/packs/acts/prompts/character_guide/perceive.prompt +0 -140
- package/data/packs/acts/prompts/character_guide/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/discipleship_mentor/defaults_config.json +0 -23
- package/data/packs/acts/prompts/discipleship_mentor/perceive.json +0 -33
- package/data/packs/acts/prompts/discipleship_mentor/perceive.prompt +0 -245
- package/data/packs/acts/prompts/discipleship_mentor/system_instruction.prompt +0 -0
- package/data/packs/acts/prompts/mentor_coach/defaults_config.json +0 -13
- package/data/packs/acts/prompts/mentor_coach/perceive.json +0 -29
- package/data/packs/acts/prompts/mentor_coach/perceive.prompt +0 -87
- package/data/packs/acts/prompts/mentor_coach/system_instruction.prompt +0 -0
- package/data/packs/acts/rooms/session.json +0 -14
- package/data/packs/acts/rooms/training.json +0 -58
- package/dist-sdk/server/src/tools/packs/acts/data/cards.d.ts +0 -53
- package/dist-sdk/server/src/tools/packs/acts/data/cards.js +0 -54
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/character-cards.generated.js +0 -185
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.d.ts +0 -12
- package/dist-sdk/server/src/tools/packs/acts/data/encounters.js +0 -102
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/event-cards.generated.js +0 -196
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/data/item-cards.generated.js +0 -1311
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.d.ts +0 -5
- package/dist-sdk/server/src/tools/packs/acts/engine/cards.js +0 -27
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.d.ts +0 -37
- package/dist-sdk/server/src/tools/packs/acts/engine/challenge.js +0 -120
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/engine/dice.js +0 -41
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.d.ts +0 -54
- package/dist-sdk/server/src/tools/packs/acts/engine/sheet.js +0 -200
- package/dist-sdk/server/src/tools/packs/acts/index.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/index.js +0 -24
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/award.tool.js +0 -184
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/challenge.tool.js +0 -107
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/chapter.tool.js +0 -146
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/check.tool.js +0 -241
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.d.ts +0 -3
- package/dist-sdk/server/src/tools/packs/acts/tools/encounter.tool.js +0 -72
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.d.ts +0 -2
- package/dist-sdk/server/src/tools/packs/acts/tools/faith.tool.js +0 -75
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/acts/tools/shared.js +0 -70
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.d.ts +0 -4
- package/dist-sdk/server/src/tools/packs/acts/tools/sheet.tools.js +0 -215
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1338
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/actsTools.html +0 -44
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -48
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3337
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -227
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -56,33 +56,69 @@ const jsonrepair_1 = require("jsonrepair");
|
|
|
56
56
|
const model_prices_1 = require("../model_prices");
|
|
57
57
|
const ai_debug_logger_1 = require("../ai-debug-logger");
|
|
58
58
|
let BaseAiService = class BaseAiService {
|
|
59
|
+
// Cache for models to avoid repeated API calls
|
|
59
60
|
modelsCache = null;
|
|
61
|
+
// Indicates whether this service is properly initialized and available for use
|
|
60
62
|
_isAvailable = true;
|
|
61
63
|
constructor() { }
|
|
64
|
+
/**
|
|
65
|
+
* Returns whether this service is available for use
|
|
66
|
+
* This is typically false if the service failed to initialize (e.g., missing API key)
|
|
67
|
+
*/
|
|
62
68
|
get isAvailable() {
|
|
63
69
|
return this._isAvailable;
|
|
64
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets the name of this service type
|
|
73
|
+
* @returns The service type name
|
|
74
|
+
*/
|
|
65
75
|
getServiceName() {
|
|
66
76
|
return '';
|
|
67
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Provider prefix used when looking up model pricing in model_prices.json.
|
|
80
|
+
* Override in services that use prefixed keys (e.g. `deepseek/`, `xai/`,
|
|
81
|
+
* `together_ai/`, `fal_ai/`). Default is no prefix — the raw model name is
|
|
82
|
+
* expected to match a key directly.
|
|
83
|
+
*/
|
|
68
84
|
getModelPricePrefix() {
|
|
69
85
|
return null;
|
|
70
86
|
}
|
|
71
87
|
supportsImageGeneration() {
|
|
72
88
|
return false;
|
|
73
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether createAgent() must find the model in model_prices.json /
|
|
92
|
+
* image_models.json before an agent can be created. Services whose model
|
|
93
|
+
* names are deployment-specific and have no marginal cost (Mock,
|
|
94
|
+
* self-hosted providers) override this to return false.
|
|
95
|
+
*/
|
|
74
96
|
requiresKnownModel() {
|
|
75
97
|
return true;
|
|
76
98
|
}
|
|
77
99
|
supportsPromptCaching() {
|
|
78
100
|
return false;
|
|
79
101
|
}
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
103
|
getCacheConfig(_agent, _cacheMessage) {
|
|
81
104
|
return null;
|
|
82
105
|
}
|
|
83
106
|
stripQuotes(quotedText) {
|
|
84
107
|
return quotedText.replace(/^['"]+|['"]+$/g, '');
|
|
85
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Finds a prompt file using the shared lookup order.
|
|
111
|
+
*
|
|
112
|
+
* For a bare folder that is the historical four levels — user/folder,
|
|
113
|
+
* user/root, common/folder, common/root — plus the folders of any pack the
|
|
114
|
+
* agent's owner has enabled. For a pack-qualified folder (`dnd5e:battle_master`)
|
|
115
|
+
* it is the pack's own tiers, then the shared roots. See `prompt-resolver.ts`.
|
|
116
|
+
*
|
|
117
|
+
* @param agent The agent context
|
|
118
|
+
* @param fileName The prompt file name without extension
|
|
119
|
+
* @param extension The file extension (e.g., '.prompt' or '.json')
|
|
120
|
+
* @returns The full path to the file, or null if not found
|
|
121
|
+
*/
|
|
86
122
|
findPromptFile(agent, fileName, extension) {
|
|
87
123
|
const userPaths = agent.userPaths;
|
|
88
124
|
if (!userPaths) {
|
|
@@ -92,27 +128,51 @@ let BaseAiService = class BaseAiService {
|
|
|
92
128
|
enabledPacks: agent.enabledPacks,
|
|
93
129
|
})?.absolutePath ?? null);
|
|
94
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Whether a prompt file resolves for this agent, without reading or compiling it.
|
|
133
|
+
*
|
|
134
|
+
* Lets a caller find out that {@link getPreparedPrompt} would throw before
|
|
135
|
+
* committing to a call — used to tell an agent that can run a given kind of turn
|
|
136
|
+
* from one whose prompt folder simply does not have that prompt.
|
|
137
|
+
*
|
|
138
|
+
* @param agent The agent whose prompt folder is searched
|
|
139
|
+
* @param fileName The prompt file name without extension
|
|
140
|
+
* @param extension The file extension, defaulting to `.prompt`
|
|
141
|
+
*/
|
|
95
142
|
hasPromptFile(agent, fileName, extension = '.prompt') {
|
|
96
143
|
return this.findPromptFile(agent, fileName, extension) !== null;
|
|
97
144
|
}
|
|
98
145
|
getPreparedPrompt(agent, promptFileName, variables) {
|
|
146
|
+
// Use 4-level fallback to find the prompt file
|
|
99
147
|
const preparedFile = this.findPromptFile(agent, promptFileName, '.prompt');
|
|
100
148
|
if (!preparedFile) {
|
|
101
149
|
throw new errors_1.NotFoundError(`Prompt file '${promptFileName}.prompt' not found for agent '${agent.agentName}' (folder: ${agent.promptFolder})`);
|
|
102
150
|
}
|
|
151
|
+
// Read and compile the prompt template.
|
|
152
|
+
//
|
|
153
|
+
// noEscape because a prompt is not HTML. Handlebars escapes `{{var}}` by
|
|
154
|
+
// default, which turned every apostrophe in a description into `'`
|
|
155
|
+
// and every fenced code block inside an artifact into `````
|
|
156
|
+
// — so a character sheet arrived at the model as entity soup, and the
|
|
157
|
+
// JSON inside it doubly so. There is no injection risk to trade against:
|
|
158
|
+
// nothing downstream renders this as markup.
|
|
103
159
|
const preparedPrompt = fs.readFileSync(preparedFile).toString('utf8');
|
|
104
160
|
const template = (0, handlebars_1.compile)(preparedPrompt, { noEscape: true });
|
|
105
161
|
return template(variables);
|
|
106
162
|
}
|
|
107
163
|
getPreparedSchema(agent, promptFileName) {
|
|
164
|
+
// Use 4-level fallback to find the schema file
|
|
108
165
|
const jsonSchemaFile = this.findPromptFile(agent, promptFileName, '.json');
|
|
166
|
+
// Schemas are optional, return null if not found
|
|
109
167
|
if (!jsonSchemaFile) {
|
|
110
168
|
return null;
|
|
111
169
|
}
|
|
170
|
+
// Allows creating an empty .json file to return a plain text response
|
|
112
171
|
let jsonSchemaString = (0, fs_1.readFileSync)(jsonSchemaFile).toString('utf8');
|
|
113
172
|
if (!jsonSchemaString) {
|
|
114
173
|
return null;
|
|
115
174
|
}
|
|
175
|
+
// Try to parse the JSON schema if found
|
|
116
176
|
try {
|
|
117
177
|
return JSON.parse(jsonSchemaString);
|
|
118
178
|
}
|
|
@@ -121,15 +181,24 @@ let BaseAiService = class BaseAiService {
|
|
|
121
181
|
return null;
|
|
122
182
|
}
|
|
123
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Lists available models from the AI service
|
|
186
|
+
* Uses cached results if available, otherwise queries the API
|
|
187
|
+
* @returns Promise with model information
|
|
188
|
+
*/
|
|
124
189
|
async listModels() {
|
|
190
|
+
// Check if service is available
|
|
125
191
|
if (!this.isAvailable) {
|
|
126
192
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
127
193
|
}
|
|
194
|
+
// Return cached models if available
|
|
128
195
|
if (this.modelsCache) {
|
|
129
196
|
return this.modelsCache;
|
|
130
197
|
}
|
|
198
|
+
// If no cache, call the actual implementation
|
|
131
199
|
try {
|
|
132
200
|
const models = await this.fetchModelsFromApi();
|
|
201
|
+
// Cache the result for future calls
|
|
133
202
|
this.modelsCache = models;
|
|
134
203
|
return models;
|
|
135
204
|
}
|
|
@@ -138,10 +207,30 @@ let BaseAiService = class BaseAiService {
|
|
|
138
207
|
throw error;
|
|
139
208
|
}
|
|
140
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Actual implementation to fetch models from the API
|
|
212
|
+
* This should be overridden by subclasses
|
|
213
|
+
* @returns Promise with model information
|
|
214
|
+
*/
|
|
141
215
|
async fetchModelsFromApi() {
|
|
142
216
|
throw new Error('fetchModelsFromApi method not implemented in base class');
|
|
143
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Creates an agent with the AI service
|
|
220
|
+
* @param userPaths User paths service for prompt and data directories
|
|
221
|
+
* @param configService Environment-variable configuration service
|
|
222
|
+
* @param agentStoreService
|
|
223
|
+
* @param balanceService
|
|
224
|
+
* @param artifactService
|
|
225
|
+
* @param agentName Name of the agent
|
|
226
|
+
* @param description
|
|
227
|
+
* @param promptFolder Directory name containing prompts
|
|
228
|
+
* @param modelName Name of the model to use
|
|
229
|
+
* @param storageDir
|
|
230
|
+
* @returns A new Agent instance
|
|
231
|
+
*/
|
|
144
232
|
createAgent(userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, modelName, storageDir = '') {
|
|
233
|
+
// Check if service is available
|
|
145
234
|
if (!this.isAvailable) {
|
|
146
235
|
throw new Error(`${this.getServiceName()} service is not available. Check API key configuration.`);
|
|
147
236
|
}
|
|
@@ -151,10 +240,15 @@ let BaseAiService = class BaseAiService {
|
|
|
151
240
|
if (!agentName) {
|
|
152
241
|
throw new Error('Agent name is required');
|
|
153
242
|
}
|
|
243
|
+
// Refuse to create an agent for a model that has no pricing entry —
|
|
244
|
+
// otherwise cost tracking silently falls back to zero and balance gating
|
|
245
|
+
// is bypassed. Services with requiresKnownModel() === false are exempt:
|
|
246
|
+
// their models have no real cost and are never listed in model_prices.json.
|
|
154
247
|
if (this.requiresKnownModel() && !(0, model_prices_1.isKnownModel)(modelName, this.getModelPricePrefix())) {
|
|
155
248
|
throw new Error(`Model '${modelName}' is not listed in model_prices.json for ${this.getServiceName()}. ` +
|
|
156
249
|
`Add a pricing entry before using this model.`);
|
|
157
250
|
}
|
|
251
|
+
// Create a temporary agent object to use the findPromptFile helper
|
|
158
252
|
const tempAgent = { promptFolder, userPaths };
|
|
159
253
|
const systemInstructionFile = this.findPromptFile(tempAgent, 'system_instruction', '.prompt');
|
|
160
254
|
let systemInstructionPrompt = null;
|
|
@@ -167,33 +261,74 @@ let BaseAiService = class BaseAiService {
|
|
|
167
261
|
systemInstructionPrompt = null;
|
|
168
262
|
}
|
|
169
263
|
}
|
|
170
|
-
const agent = new agent_1.Agent(null, userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, systemInstructionPrompt, [], modelName, this.getServiceName(), this,
|
|
264
|
+
const agent = new agent_1.Agent(null, userPaths, configService, agentStoreService, balanceService, artifactService, agentName, agentNickname, description, promptFolder, systemInstructionPrompt, [], modelName, this.getServiceName(), this, // Pass the service instance itself
|
|
265
|
+
null, // no reasoning
|
|
266
|
+
false, // do not allow search
|
|
267
|
+
0, // Default to maximum output tokens
|
|
268
|
+
'', // begin instruction
|
|
269
|
+
storageDir);
|
|
171
270
|
return agent;
|
|
172
271
|
}
|
|
173
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Sends a text prompt to the AI service
|
|
274
|
+
* @param agent The agent context
|
|
275
|
+
* @param prompt The text prompt
|
|
276
|
+
* @param _jsonSchema
|
|
277
|
+
* @param _saveResponse
|
|
278
|
+
* @param _promptInstructions
|
|
279
|
+
* @param _cacheConfig
|
|
280
|
+
* @param _maxOutputChars
|
|
281
|
+
* @returns The AI response
|
|
282
|
+
*/
|
|
283
|
+
async textPrompt(agent, prompt, _jsonSchema = null, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
284
|
+
_saveResponse = true, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
285
|
+
_promptInstructions = null, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
286
|
+
_cacheConfig = null, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
287
|
+
_maxOutputChars = 0) {
|
|
288
|
+
// Check if service is available
|
|
174
289
|
if (!this.isAvailable) {
|
|
175
290
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
176
291
|
}
|
|
177
292
|
throw new Error('Method not implemented in base class');
|
|
178
293
|
}
|
|
179
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Generates an image from a text prompt with optional reference images
|
|
296
|
+
* @param agent The agent making the request
|
|
297
|
+
* @param prompt Text description of the image to generate
|
|
298
|
+
* @param width
|
|
299
|
+
* @param height
|
|
300
|
+
* @param quality
|
|
301
|
+
* @param referenceImageArtifactIds Optional array of artifact IDs containing reference images
|
|
302
|
+
* @param options Optional generation parameters (size, quality, format)
|
|
303
|
+
* @returns Promise resolving to JSON string with { url, artifactId }
|
|
304
|
+
*/
|
|
305
|
+
async generateImage(_agent, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
306
|
+
_prompt, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
307
|
+
_imageProperties) {
|
|
180
308
|
if (!this.isAvailable) {
|
|
181
309
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
182
310
|
}
|
|
183
311
|
throw new Error(`generateImage method not implemented for ${this.getServiceName()}`);
|
|
184
312
|
}
|
|
185
|
-
async editImage(_agent,
|
|
313
|
+
async editImage(_agent, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
314
|
+
_prompt, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
315
|
+
_imageProperties, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
316
|
+
_referenceImageArtifactIds) {
|
|
186
317
|
if (!this.isAvailable) {
|
|
187
318
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
188
319
|
}
|
|
189
320
|
throw new Error(`editImage method not implemented for ${this.getServiceName()}`);
|
|
190
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Helper: Load reference images from artifacts
|
|
324
|
+
*/
|
|
191
325
|
async loadReferenceImages(agent, artifactIds) {
|
|
192
326
|
const images = [];
|
|
193
327
|
for (const artifactId of artifactIds) {
|
|
194
328
|
const imageData = agent.artifactService.getArtifact(artifactId);
|
|
195
329
|
const metadata = agent.artifactService.getArtifactMetadata(artifactId);
|
|
196
330
|
if (imageData && Buffer.isBuffer(imageData) && metadata) {
|
|
331
|
+
// Convert Buffer to File for OpenAI API
|
|
197
332
|
const uint8Array = new Uint8Array(imageData);
|
|
198
333
|
const blob = new Blob([uint8Array], {
|
|
199
334
|
type: metadata.mimeType || 'image/png',
|
|
@@ -206,13 +341,30 @@ let BaseAiService = class BaseAiService {
|
|
|
206
341
|
}
|
|
207
342
|
return images;
|
|
208
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Helper: Save image from base64 data as artifact
|
|
346
|
+
*/
|
|
209
347
|
async saveImageAsArtifact(agent, base64Data, prompt) {
|
|
348
|
+
// Decode base64 to buffer
|
|
210
349
|
const buffer = Buffer.from(base64Data, 'base64');
|
|
350
|
+
// Default to PNG for generated images
|
|
211
351
|
const mimeType = 'image/png';
|
|
352
|
+
// Generate name from prompt (truncate if too long)
|
|
212
353
|
const name = prompt.substring(0, 50).trim() + ' (generated)';
|
|
354
|
+
// Save as artifact
|
|
213
355
|
return agent.artifactService.storeImageArtifact(name, buffer, mimeType);
|
|
214
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Processes a prepared prompt with the AI service
|
|
359
|
+
* @param agent The agent context
|
|
360
|
+
* @param promptFileName Name of the prompt file
|
|
361
|
+
* @param variables Variables to use in the prompt template
|
|
362
|
+
* @param saveResponse Whether to save the response in the agent history
|
|
363
|
+
* @param cacheConfig
|
|
364
|
+
* @returns The AI response as a parsed JSON object
|
|
365
|
+
*/
|
|
215
366
|
async preparedPrompt(agent, promptFileName, variables, saveResponse = true, cacheConfig = false, maxOutputChars = 0) {
|
|
367
|
+
// Check if service is available
|
|
216
368
|
if (!this.isAvailable) {
|
|
217
369
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
218
370
|
}
|
|
@@ -221,6 +373,7 @@ let BaseAiService = class BaseAiService {
|
|
|
221
373
|
return this.textPrompt(agent, preparedPrompt, jsonSchema, saveResponse, null, cacheConfig, maxOutputChars);
|
|
222
374
|
}
|
|
223
375
|
async instructedPrompt(agent, prompt, instructionFileName, variables, saveResponse = true, cacheConfig = null, maxOutputChars = 0) {
|
|
376
|
+
// Check if service is available
|
|
224
377
|
if (!this.isAvailable) {
|
|
225
378
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
226
379
|
}
|
|
@@ -228,7 +381,15 @@ let BaseAiService = class BaseAiService {
|
|
|
228
381
|
let jsonSchema = this.getPreparedSchema(agent, instructionFileName);
|
|
229
382
|
return this.textPrompt(agent, prompt, jsonSchema, saveResponse, promptInstructions, cacheConfig, maxOutputChars);
|
|
230
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Attaches a document to the agent or as a shared document
|
|
386
|
+
* @param agent The agent context (null for shared documents)
|
|
387
|
+
* @param fileName The name of the file
|
|
388
|
+
* @param fileData The file data as a Uint8Array
|
|
389
|
+
* @returns Promise with a human-readable success message
|
|
390
|
+
*/
|
|
231
391
|
async attachDocument(agent, fileName, fileData) {
|
|
392
|
+
// Check if service is available
|
|
232
393
|
if (!this.isAvailable) {
|
|
233
394
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
234
395
|
}
|
|
@@ -238,6 +399,7 @@ let BaseAiService = class BaseAiService {
|
|
|
238
399
|
try {
|
|
239
400
|
let ext = fileName.split('.').pop();
|
|
240
401
|
let mimeType = 'application/octet-stream';
|
|
402
|
+
// Determine MIME type based on extension
|
|
241
403
|
if (ext.toLowerCase() === 'pdf') {
|
|
242
404
|
mimeType = 'application/pdf';
|
|
243
405
|
}
|
|
@@ -253,26 +415,34 @@ let BaseAiService = class BaseAiService {
|
|
|
253
415
|
else if (['xls', 'xlsx'].includes(ext.toLowerCase())) {
|
|
254
416
|
mimeType = 'application/vnd.ms-excel';
|
|
255
417
|
}
|
|
418
|
+
// Create metadata for this file and store the file data with it
|
|
256
419
|
const fileMetadata = {
|
|
257
420
|
fileName,
|
|
421
|
+
// fileId should already be set by AttachedFileService before this method is called
|
|
258
422
|
mimeType,
|
|
259
423
|
size: fileData.length,
|
|
260
424
|
uploadDate: new Date().toISOString(),
|
|
261
425
|
serviceMetadata: {
|
|
262
426
|
serviceName: this.getServiceName(),
|
|
263
|
-
|
|
427
|
+
// Store the actual file data temporarily in metadata for immediate use
|
|
428
|
+
fileData: Array.from(fileData), // Convert Uint8Array to regular array for JSON serialization
|
|
264
429
|
},
|
|
265
430
|
};
|
|
431
|
+
// Check if file already exists in agent's attachedFiles
|
|
266
432
|
const existingFileIndex = agent.attachedFiles.findIndex((f) => f.fileName === fileName);
|
|
267
433
|
if (existingFileIndex >= 0) {
|
|
434
|
+
// Update existing metadata (preserve existing fileId)
|
|
268
435
|
agent.attachedFiles[existingFileIndex] = {
|
|
269
436
|
...agent.attachedFiles[existingFileIndex],
|
|
270
437
|
...fileMetadata,
|
|
271
438
|
};
|
|
272
439
|
}
|
|
273
440
|
else {
|
|
441
|
+
// Add new file metadata to agent
|
|
442
|
+
// Cast to FileMetadata since fileId should already be set by AttachedFileService
|
|
274
443
|
agent.attachedFiles.push(fileMetadata);
|
|
275
444
|
}
|
|
445
|
+
// Note: File is stored in attachedFiles and will be prepended to each request by textPrompt
|
|
276
446
|
return `Document attached: ${fileName}`;
|
|
277
447
|
}
|
|
278
448
|
catch (error) {
|
|
@@ -280,12 +450,28 @@ let BaseAiService = class BaseAiService {
|
|
|
280
450
|
throw new Error(`Error attaching document: ${error.message}`);
|
|
281
451
|
}
|
|
282
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Finishes an agent and cleans up resources
|
|
455
|
+
* @param agent The agent to finish
|
|
456
|
+
*/
|
|
457
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
283
458
|
async finishAgent(_agent) {
|
|
459
|
+
// Check if service is available
|
|
284
460
|
if (!this.isAvailable) {
|
|
285
461
|
return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
|
|
286
462
|
}
|
|
463
|
+
// Default implementation does nothing
|
|
287
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Adds a message to the agent history in the appropriate format for this service
|
|
467
|
+
* @param agent The agent to add the message to
|
|
468
|
+
* @param message The formatted message to add
|
|
469
|
+
* @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
|
|
470
|
+
* @param developer Whether the message is a system instruction from the developer
|
|
471
|
+
*/
|
|
288
472
|
addToConversationHistory(agent, message, fromSelf = false, developer = false) {
|
|
473
|
+
// Default implementation for most services
|
|
474
|
+
// Subclasses should override this if they have a different history format
|
|
289
475
|
if (!agent.history) {
|
|
290
476
|
agent.history = [];
|
|
291
477
|
}
|
|
@@ -300,10 +486,21 @@ let BaseAiService = class BaseAiService {
|
|
|
300
486
|
});
|
|
301
487
|
agent.trimHistoryIfNeeded();
|
|
302
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Trims a string to extract JSON content
|
|
491
|
+
* @param str The string to trim
|
|
492
|
+
* @returns The trimmed string containing only JSON
|
|
493
|
+
*/
|
|
494
|
+
/**
|
|
495
|
+
* Formats a message from the agent's history in a human-readable way
|
|
496
|
+
* @param message The message object from the agent's history
|
|
497
|
+
* @returns A formatted string representation of the message
|
|
498
|
+
*/
|
|
303
499
|
formatMessage(message) {
|
|
304
500
|
if (!message) {
|
|
305
501
|
return 'No message';
|
|
306
502
|
}
|
|
503
|
+
// Default implementation for most services
|
|
307
504
|
if (message.role && message.content) {
|
|
308
505
|
let content = message.content;
|
|
309
506
|
if (typeof content === 'object') {
|
|
@@ -311,17 +508,33 @@ let BaseAiService = class BaseAiService {
|
|
|
311
508
|
}
|
|
312
509
|
return `${message.role}: ${content}`;
|
|
313
510
|
}
|
|
511
|
+
// Generic fallback
|
|
314
512
|
return JSON.stringify(message);
|
|
315
513
|
}
|
|
514
|
+
// -------------------------------------------------------------------------
|
|
515
|
+
// AI debug-logging helpers — call these in textPrompt() overrides
|
|
516
|
+
// -------------------------------------------------------------------------
|
|
316
517
|
debugLogRequest(agentName, content) {
|
|
317
518
|
ai_debug_logger_1.AiDebugLogger.writeRequest(agentName, content);
|
|
318
519
|
}
|
|
520
|
+
/** Only writes a file when content is non-empty (no-op for non-reasoning models). */
|
|
319
521
|
debugLogThinking(agentName, thinking) {
|
|
320
522
|
ai_debug_logger_1.AiDebugLogger.writeThinking(agentName, thinking);
|
|
321
523
|
}
|
|
322
524
|
debugLogResponse(agentName, response) {
|
|
323
525
|
ai_debug_logger_1.AiDebugLogger.writeResponse(agentName, response);
|
|
324
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* The provider's own account of a refused call, as a single log line.
|
|
529
|
+
*
|
|
530
|
+
* `logger` renders its extra arguments with `JSON.stringify`, and an Error
|
|
531
|
+
* stringifies to `{}` — so passing a caught error as an argument logs nothing
|
|
532
|
+
* at all. The status code and response body that say *why* a call was refused
|
|
533
|
+
* live on the AI SDK's `APICallError`, so they have to be read off explicitly
|
|
534
|
+
* and interpolated into the message itself.
|
|
535
|
+
* @param error The error a generate call threw
|
|
536
|
+
* @returns A one-line description, with the response body truncated
|
|
537
|
+
*/
|
|
325
538
|
static describeProviderError(error) {
|
|
326
539
|
if (!ai_1.APICallError.isInstance(error)) {
|
|
327
540
|
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
@@ -341,8 +554,11 @@ let BaseAiService = class BaseAiService {
|
|
|
341
554
|
if (!str) {
|
|
342
555
|
return str;
|
|
343
556
|
}
|
|
557
|
+
// Remove <think>...</think> tags and their content
|
|
558
|
+
// Use a regex that matches the opening tag, any content (including newlines), and the closing tag
|
|
344
559
|
str = str.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
|
|
345
560
|
if (str.startsWith('```')) {
|
|
561
|
+
// Strip first line and return the rest
|
|
346
562
|
const lines = str.split('\n');
|
|
347
563
|
if (lines.length > 1) {
|
|
348
564
|
str = lines.slice(1).join('\n');
|
|
@@ -352,6 +568,7 @@ let BaseAiService = class BaseAiService {
|
|
|
352
568
|
}
|
|
353
569
|
}
|
|
354
570
|
if (str.endsWith('```')) {
|
|
571
|
+
// Strip last line
|
|
355
572
|
const lines = str.split('\n');
|
|
356
573
|
if (lines.length > 1) {
|
|
357
574
|
str = lines.slice(0, -1).join('\n');
|
|
@@ -363,10 +580,12 @@ let BaseAiService = class BaseAiService {
|
|
|
363
580
|
return str;
|
|
364
581
|
}
|
|
365
582
|
trimToJson(str) {
|
|
583
|
+
// Look for either object or array start
|
|
366
584
|
let objectStart = str.indexOf('{');
|
|
367
585
|
let arrayStart = str.indexOf('[');
|
|
368
586
|
let startIndex = -1;
|
|
369
587
|
let endChar = '';
|
|
588
|
+
// Determine which comes first (or if only one exists)
|
|
370
589
|
if (objectStart !== -1 && arrayStart !== -1) {
|
|
371
590
|
if (objectStart < arrayStart) {
|
|
372
591
|
startIndex = objectStart;
|
|
@@ -394,6 +613,21 @@ let BaseAiService = class BaseAiService {
|
|
|
394
613
|
}
|
|
395
614
|
return str;
|
|
396
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* Parses a model's JSON response into an object, tolerating the encoding
|
|
618
|
+
* mistakes models routinely make. Tries a strict JSON.parse first; on
|
|
619
|
+
* failure it runs the text through jsonrepair, which fixes unescaped quotes
|
|
620
|
+
* (e.g. an inch mark like 5'6" inside a string), literal control
|
|
621
|
+
* characters, trailing commas, and similar issues — then parses again.
|
|
622
|
+
*
|
|
623
|
+
* This is the single place every provider should turn raw model text into
|
|
624
|
+
* a structured object, so a single stray character never discards an
|
|
625
|
+
* otherwise-valid response.
|
|
626
|
+
*
|
|
627
|
+
* @param text Raw (already trimmed-to-JSON) model output.
|
|
628
|
+
* @returns The parsed object.
|
|
629
|
+
* @throws The original parse error if the text cannot be recovered.
|
|
630
|
+
*/
|
|
397
631
|
parseStructuredResponse(text) {
|
|
398
632
|
try {
|
|
399
633
|
return JSON.parse(text);
|
|
@@ -405,6 +639,8 @@ let BaseAiService = class BaseAiService {
|
|
|
405
639
|
return JSON.parse(repaired);
|
|
406
640
|
}
|
|
407
641
|
catch {
|
|
642
|
+
// Surface the original error — it points at the real problem
|
|
643
|
+
// better than the post-repair failure.
|
|
408
644
|
logger_1.logger.error('Failed to parse structured response even after repair');
|
|
409
645
|
throw firstError;
|
|
410
646
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export interface ComfyUiClientOptions {
|
|
2
|
+
/** Base URL of the ComfyUI server, without a trailing slash (e.g. http://gpu-box:8188) */
|
|
2
3
|
baseUrl: string;
|
|
4
|
+
/** Extra headers merged into every request (e.g. reverse-proxy basic auth) */
|
|
3
5
|
extraHeaders?: Record<string, string>;
|
|
6
|
+
/** Total time to wait for a queued prompt to complete, in ms (queue wait + generation) */
|
|
4
7
|
timeoutMs?: number;
|
|
8
|
+
/** Interval between /history polls, in ms */
|
|
5
9
|
pollIntervalMs?: number;
|
|
6
10
|
}
|
|
7
11
|
export interface ComfyUiImageRef {
|
|
@@ -9,6 +13,11 @@ export interface ComfyUiImageRef {
|
|
|
9
13
|
subfolder: string;
|
|
10
14
|
type: string;
|
|
11
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Minimal HTTP client for the ComfyUI server API. Plain class (not a Nest
|
|
18
|
+
* service) so it can be constructed and unit-tested without DI. Uses the
|
|
19
|
+
* global fetch/FormData available in Node 18+.
|
|
20
|
+
*/
|
|
12
21
|
export declare class ComfyUiClient {
|
|
13
22
|
private readonly baseUrl;
|
|
14
23
|
private readonly extraHeaders;
|
|
@@ -16,13 +25,30 @@ export declare class ComfyUiClient {
|
|
|
16
25
|
private readonly pollIntervalMs;
|
|
17
26
|
private readonly clientId;
|
|
18
27
|
constructor(options: ComfyUiClientOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether the ComfyUI server responds. Intended for diagnostics and
|
|
30
|
+
* tests; generation paths surface their own errors.
|
|
31
|
+
*/
|
|
19
32
|
checkReachable(): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Uploads an image to the ComfyUI input folder.
|
|
35
|
+
* @returns The server-side name (and subfolder) to reference in a LoadImage node
|
|
36
|
+
*/
|
|
20
37
|
uploadImage(data: Buffer, filename: string): Promise<{
|
|
21
38
|
name: string;
|
|
22
39
|
subfolder: string;
|
|
23
40
|
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Queues a workflow (API-format graph) for execution.
|
|
43
|
+
* @returns The prompt id to poll for completion
|
|
44
|
+
*/
|
|
24
45
|
queuePrompt(workflow: Record<string, any>): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Polls /history until the prompt completes, fails, or the timeout elapses.
|
|
48
|
+
* @returns The first output image reference from the completed workflow
|
|
49
|
+
*/
|
|
25
50
|
waitForCompletion(promptId: string): Promise<ComfyUiImageRef>;
|
|
51
|
+
/** Downloads a generated image. */
|
|
26
52
|
fetchOutput(ref: ComfyUiImageRef): Promise<Buffer>;
|
|
27
53
|
private findFirstOutputImage;
|
|
28
54
|
private extractErrorMessages;
|
|
@@ -5,6 +5,11 @@ const crypto_1 = require("crypto");
|
|
|
5
5
|
const logger_1 = require("../../common/logger");
|
|
6
6
|
const DEFAULT_TIMEOUT_MS = 600_000;
|
|
7
7
|
const DEFAULT_POLL_INTERVAL_MS = 2_000;
|
|
8
|
+
/**
|
|
9
|
+
* Minimal HTTP client for the ComfyUI server API. Plain class (not a Nest
|
|
10
|
+
* service) so it can be constructed and unit-tested without DI. Uses the
|
|
11
|
+
* global fetch/FormData available in Node 18+.
|
|
12
|
+
*/
|
|
8
13
|
class ComfyUiClient {
|
|
9
14
|
baseUrl;
|
|
10
15
|
extraHeaders;
|
|
@@ -18,6 +23,10 @@ class ComfyUiClient {
|
|
|
18
23
|
this.pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
19
24
|
this.clientId = (0, crypto_1.randomUUID)();
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether the ComfyUI server responds. Intended for diagnostics and
|
|
28
|
+
* tests; generation paths surface their own errors.
|
|
29
|
+
*/
|
|
21
30
|
async checkReachable() {
|
|
22
31
|
try {
|
|
23
32
|
const response = await fetch(`${this.baseUrl}/system_stats`, {
|
|
@@ -30,6 +39,10 @@ class ComfyUiClient {
|
|
|
30
39
|
return false;
|
|
31
40
|
}
|
|
32
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Uploads an image to the ComfyUI input folder.
|
|
44
|
+
* @returns The server-side name (and subfolder) to reference in a LoadImage node
|
|
45
|
+
*/
|
|
33
46
|
async uploadImage(data, filename) {
|
|
34
47
|
const form = new FormData();
|
|
35
48
|
form.append('image', new Blob([new Uint8Array(data)], { type: 'image/png' }), filename);
|
|
@@ -45,6 +58,10 @@ class ComfyUiClient {
|
|
|
45
58
|
const result = await response.json();
|
|
46
59
|
return { name: result.name ?? filename, subfolder: result.subfolder ?? '' };
|
|
47
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Queues a workflow (API-format graph) for execution.
|
|
63
|
+
* @returns The prompt id to poll for completion
|
|
64
|
+
*/
|
|
48
65
|
async queuePrompt(workflow) {
|
|
49
66
|
const response = await fetch(`${this.baseUrl}/prompt`, {
|
|
50
67
|
method: 'POST',
|
|
@@ -52,11 +69,13 @@ class ComfyUiClient {
|
|
|
52
69
|
body: JSON.stringify({ prompt: workflow, client_id: this.clientId }),
|
|
53
70
|
});
|
|
54
71
|
if (!response.ok) {
|
|
72
|
+
// ComfyUI returns validation errors as JSON with node-level details
|
|
55
73
|
let detail = '';
|
|
56
74
|
try {
|
|
57
75
|
detail = JSON.stringify(await response.json());
|
|
58
76
|
}
|
|
59
77
|
catch {
|
|
78
|
+
/* body was not JSON */
|
|
60
79
|
}
|
|
61
80
|
throw new Error(`ComfyUI rejected the workflow: ${response.status} ${response.statusText}${detail ? ` — ${detail}` : ''}`);
|
|
62
81
|
}
|
|
@@ -66,6 +85,10 @@ class ComfyUiClient {
|
|
|
66
85
|
}
|
|
67
86
|
return result.prompt_id;
|
|
68
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Polls /history until the prompt completes, fails, or the timeout elapses.
|
|
90
|
+
* @returns The first output image reference from the completed workflow
|
|
91
|
+
*/
|
|
69
92
|
async waitForCompletion(promptId) {
|
|
70
93
|
const deadline = Date.now() + this.timeoutMs;
|
|
71
94
|
while (Date.now() < deadline) {
|
|
@@ -85,6 +108,7 @@ class ComfyUiClient {
|
|
|
85
108
|
const image = this.findFirstOutputImage(entry);
|
|
86
109
|
if (image)
|
|
87
110
|
return image;
|
|
111
|
+
// Entry exists with success status but no image output — malformed workflow
|
|
88
112
|
if (statusStr === 'success' || entry.status?.completed) {
|
|
89
113
|
throw new Error('ComfyUI workflow completed but produced no image output. ' +
|
|
90
114
|
'Check that the workflow template ends in a SaveImage node.');
|
|
@@ -95,6 +119,7 @@ class ComfyUiClient {
|
|
|
95
119
|
throw new Error(`ComfyUI generation timed out after ${Math.round(this.timeoutMs / 1000)}s. ` +
|
|
96
120
|
'This includes queue wait and model cold-start; raise COMFYUI_TIMEOUT_MS if the server is just slow.');
|
|
97
121
|
}
|
|
122
|
+
/** Downloads a generated image. */
|
|
98
123
|
async fetchOutput(ref) {
|
|
99
124
|
const params = new URLSearchParams({
|
|
100
125
|
filename: ref.filename,
|