briyah 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -7
- package/data/common/config/LICENSE-model-prices.md +65 -0
- package/data/common/config/model_prices.json +47443 -46295
- package/data/common/prompts/narrator/create_story.prompt +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +103 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +173 -2
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +172 -3
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +241 -5
- package/dist-sdk/server/src/ai/LLM/comfyui-client.d.ts +26 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-client.js +25 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.d.ts +54 -0
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.js +59 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.d.ts +21 -1
- package/dist-sdk/server/src/ai/LLM/comfyui.service.js +25 -1
- package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +52 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +102 -3
- package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/LLM/fal.service.js +55 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +19 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +42 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +22 -0
- package/dist-sdk/server/src/ai/LLM/grok.service.js +54 -2
- package/dist-sdk/server/src/ai/LLM/mock.service.js +31 -4
- package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/openai.service.js +80 -2
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.d.ts +21 -0
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +44 -2
- package/dist-sdk/server/src/ai/LLM/together.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/LLM/together.service.js +60 -2
- package/dist-sdk/server/src/ai/agent-config.d.ts +15 -0
- package/dist-sdk/server/src/ai/agent-factory.d.ts +16 -0
- package/dist-sdk/server/src/ai/agent-factory.js +20 -0
- package/dist-sdk/server/src/ai/agent-message.service.d.ts +30 -0
- package/dist-sdk/server/src/ai/agent-message.service.js +30 -0
- package/dist-sdk/server/src/ai/agent-store.service.d.ts +80 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +166 -5
- package/dist-sdk/server/src/ai/agent.d.ts +196 -0
- package/dist-sdk/server/src/ai/agent.js +224 -11
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +18 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +19 -0
- package/dist-sdk/server/src/ai/ai-factory.service.d.ts +9 -0
- package/dist-sdk/server/src/ai/ai-factory.service.js +9 -0
- package/dist-sdk/server/src/ai/artifact.service.d.ts +131 -0
- package/dist-sdk/server/src/ai/artifact.service.js +148 -3
- package/dist-sdk/server/src/ai/attached-file.service.d.ts +87 -0
- package/dist-sdk/server/src/ai/attached-file.service.js +105 -0
- package/dist-sdk/server/src/ai/model_prices.d.ts +30 -0
- package/dist-sdk/server/src/ai/model_prices.js +91 -5
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +84 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +168 -0
- package/dist-sdk/server/src/ai/published-agents.service.d.ts +25 -0
- package/dist-sdk/server/src/ai/published-agents.service.js +30 -3
- package/dist-sdk/server/src/app/balance-message.service.d.ts +24 -0
- package/dist-sdk/server/src/app/balance-message.service.js +24 -0
- package/dist-sdk/server/src/app/balance.module.d.ts +4 -0
- package/dist-sdk/server/src/app/balance.module.js +4 -0
- package/dist-sdk/server/src/app/balance.service.d.ts +37 -0
- package/dist-sdk/server/src/app/balance.service.js +54 -0
- package/dist-sdk/server/src/app/stripe.controller.d.ts +21 -0
- package/dist-sdk/server/src/app/stripe.controller.js +35 -0
- package/dist-sdk/server/src/app/stripe.service.d.ts +43 -0
- package/dist-sdk/server/src/app/stripe.service.js +62 -0
- package/dist-sdk/server/src/app/transaction.service.d.ts +27 -0
- package/dist-sdk/server/src/app/transaction.service.js +36 -0
- package/dist-sdk/server/src/app/user-service-factory.d.ts +8 -0
- package/dist-sdk/server/src/app/user-service-factory.js +38 -1
- package/dist-sdk/server/src/app/user-service-manager.d.ts +27 -0
- package/dist-sdk/server/src/app/user-service-manager.js +43 -0
- package/dist-sdk/server/src/app.controller.d.ts +87 -0
- package/dist-sdk/server/src/app.controller.js +272 -12
- package/dist-sdk/server/src/app.module.js +28 -6
- package/dist-sdk/server/src/app.service.d.ts +1661 -0
- package/dist-sdk/server/src/app.service.js +1837 -4
- package/dist-sdk/server/src/auth/agent-access.decorator.d.ts +17 -0
- package/dist-sdk/server/src/auth/agent-access.decorator.js +17 -0
- package/dist-sdk/server/src/auth/auth.controller.js +46 -0
- package/dist-sdk/server/src/auth/auth.module.js +3 -2
- package/dist-sdk/server/src/auth/auth.service.d.ts +33 -0
- package/dist-sdk/server/src/auth/auth.service.js +39 -3
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +18 -0
- package/dist-sdk/server/src/auth/jwt.strategy.js +2 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +9 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +9 -0
- package/dist-sdk/server/src/auth/phone-validation.service.d.ts +25 -0
- package/dist-sdk/server/src/auth/phone-validation.service.js +30 -0
- package/dist-sdk/server/src/auth/rate-limit.service.d.ts +19 -0
- package/dist-sdk/server/src/auth/rate-limit.service.js +24 -0
- package/dist-sdk/server/src/auth/room-access.decorator.d.ts +8 -0
- package/dist-sdk/server/src/auth/room-access.decorator.js +8 -0
- package/dist-sdk/server/src/auth/scopes.decorator.d.ts +7 -0
- package/dist-sdk/server/src/auth/scopes.decorator.js +7 -0
- package/dist-sdk/server/src/auth/scopes.guard.d.ts +16 -0
- package/dist-sdk/server/src/auth/scopes.guard.js +30 -0
- package/dist-sdk/server/src/auth/session.guard.d.ts +4 -0
- package/dist-sdk/server/src/auth/session.guard.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +27 -0
- package/dist-sdk/server/src/auth/twilio.service.js +30 -4
- package/dist-sdk/server/src/auth/users.service.d.ts +30 -0
- package/dist-sdk/server/src/auth/users.service.js +42 -0
- package/dist-sdk/server/src/common/errors.d.ts +20 -0
- package/dist-sdk/server/src/common/errors.js +21 -0
- package/dist-sdk/server/src/config/env-config.d.ts +7 -0
- package/dist-sdk/server/src/config/prompt-resolver.d.ts +180 -0
- package/dist-sdk/server/src/config/prompt-resolver.js +182 -0
- package/dist-sdk/server/src/config/user-config.service.d.ts +59 -0
- package/dist-sdk/server/src/config/user-config.service.js +57 -0
- package/dist-sdk/server/src/config/user-paths.service.d.ts +61 -0
- package/dist-sdk/server/src/config/user-paths.service.js +67 -0
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +121 -1
- package/dist-sdk/server/src/documents/pdf-conversion.js +94 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +98 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +99 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +100 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +58 -0
- package/dist-sdk/server/src/packs/pack.service.d.ts +99 -1
- package/dist-sdk/server/src/packs/pack.service.js +98 -1
- package/dist-sdk/server/src/room/artifact-store.service.d.ts +27 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +49 -3
- package/dist-sdk/server/src/room/artifact.d.ts +18 -0
- package/dist-sdk/server/src/room/message.d.ts +64 -0
- package/dist-sdk/server/src/room/message.js +77 -2
- package/dist-sdk/server/src/room/nickname.d.ts +26 -0
- package/dist-sdk/server/src/room/nickname.js +26 -0
- package/dist-sdk/server/src/room/published-rooms.service.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +26 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +12 -0
- package/dist-sdk/server/src/room/room-factory.js +14 -0
- package/dist-sdk/server/src/room/room-message.service.d.ts +28 -0
- package/dist-sdk/server/src/room/room-message.service.js +28 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +176 -0
- package/dist-sdk/server/src/room/room-store.service.js +238 -5
- package/dist-sdk/server/src/room/room.d.ts +878 -0
- package/dist-sdk/server/src/room/room.js +1291 -23
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +50 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +53 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +37 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +37 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +87 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +103 -0
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +57 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +17 -0
- package/dist-sdk/server/src/sdk/briyah.d.ts +228 -0
- package/dist-sdk/server/src/sdk/briyah.js +285 -7
- package/dist-sdk/server/src/sdk/index.js +23 -0
- package/dist-sdk/server/src/shared/shared.module.d.ts +8 -0
- package/dist-sdk/server/src/shared/shared.module.js +13 -5
- package/dist-sdk/server/src/story/story-message.service.d.ts +43 -0
- package/dist-sdk/server/src/story/story-message.service.js +43 -0
- package/dist-sdk/server/src/story/story-progress.service.d.ts +23 -0
- package/dist-sdk/server/src/story/story-progress.service.js +23 -0
- package/dist-sdk/server/src/story/story-store.service.d.ts +92 -0
- package/dist-sdk/server/src/story/story-store.service.js +136 -1
- package/dist-sdk/server/src/story/story.service.d.ts +398 -0
- package/dist-sdk/server/src/story/story.service.js +829 -25
- package/dist-sdk/server/src/tools/core/index.d.ts +22 -0
- package/dist-sdk/server/src/tools/core/index.js +22 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +11 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.d.ts +22 -0
- package/dist-sdk/server/src/tools/native-tool-registry.service.js +22 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +176 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +46 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +40 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +19 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +37 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +36 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +95 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +66 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +50 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +152 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +28 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +29 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +36 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +261 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +401 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +66 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +49 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +42 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +72 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +57 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +81 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +85 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +60 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +64 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +169 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +192 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +144 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +56 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +54 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +65 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +116 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +35 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +25 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +8 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +55 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +164 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +188 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +116 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +18 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +35 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +49 -0
- package/dist-sdk/server/src/tools/packs/index.js +66 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +95 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +98 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +73 -0
- package/dist-sdk/server/src/tools/tool-execution.service.js +74 -0
- package/dist-sdk/server/src/tools/tool-store.service.d.ts +11 -0
- package/dist-sdk/server/src/tools/tool-store.service.js +13 -1
- package/dist-sdk/shared/types/app.types.d.ts +285 -13
- package/dist-sdk/shared/types/app.types.js +3 -0
- package/package.json +167 -168
- package/data/common/config/random_words.txt +0 -2241
- package/data/common/story_ideas/biblical.json +0 -122
- package/data/common/story_ideas/fantasy.json +0 -82
- package/data/common/story_ideas/historical_fiction.json +0 -82
- package/data/common/story_ideas/science_fiction.json +0 -82
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -113
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1648
- package/docs/classes/Agent.html +0 -801
- package/docs/classes/Briyah.html +0 -296
- package/docs/classes/BriyahConfigService.html +0 -119
- package/docs/classes/NativeToolRegistry.html +0 -166
- package/docs/classes/PackInstantiationService.html +0 -157
- package/docs/classes/PackService.html +0 -247
- package/docs/classes/Room.html +0 -1434
- package/docs/classes/RoomMessage.html +0 -290
- package/docs/enums/MessageAction.html +0 -136
- package/docs/functions/availableToolPacks.html +0 -41
- package/docs/functions/buildMarkdown.html +0 -54
- package/docs/functions/dnd5eTools.html +0 -44
- package/docs/functions/installToolPacks.html +0 -51
- package/docs/functions/pageMarker.html +0 -45
- package/docs/functions/registerToolPacks.html +0 -54
- package/docs/functions/splitMarkdownIntoPages.html +0 -51
- package/docs/functions/stripWrappingFence.html +0 -52
- package/docs/hierarchy.html +0 -46
- package/docs/index.html +0 -595
- package/docs/interfaces/AgentCreationOptions.html +0 -125
- package/docs/interfaces/AgentInfo.html +0 -218
- package/docs/interfaces/AgentMessagesResponse.html +0 -74
- package/docs/interfaces/AppService.html +0 -3340
- package/docs/interfaces/Artifact.html +0 -95
- package/docs/interfaces/ArtifactMetadata.html +0 -112
- package/docs/interfaces/ArtifactWriteOptions.html +0 -90
- package/docs/interfaces/AttachDocumentResponse.html +0 -62
- package/docs/interfaces/BriyahConfigOptions.html +0 -124
- package/docs/interfaces/ChapterInfo.html +0 -62
- package/docs/interfaces/Character.html +0 -86
- package/docs/interfaces/ConversionAgent.html +0 -78
- package/docs/interfaces/CreateAgentResponse.html +0 -56
- package/docs/interfaces/CreateRoomResponse.html +0 -62
- package/docs/interfaces/CreateStoryResponse.html +0 -56
- package/docs/interfaces/FileList.html +0 -56
- package/docs/interfaces/FileMetadata.html +0 -89
- package/docs/interfaces/IConfigService.html +0 -79
- package/docs/interfaces/InstantiateModels.html +0 -64
- package/docs/interfaces/InstantiateRoomResult.html +0 -70
- package/docs/interfaces/LoadedPack.html +0 -131
- package/docs/interfaces/LoggingOptions.html +0 -92
- package/docs/interfaces/Message.html +0 -84
- package/docs/interfaces/ModelChoice.html +0 -73
- package/docs/interfaces/ModelInfo.html +0 -74
- package/docs/interfaces/NativeToolDefinition.html +0 -107
- package/docs/interfaces/PackAgentTemplate.html +0 -101
- package/docs/interfaces/PackRoomTemplate.html +0 -108
- package/docs/interfaces/PackView.html +0 -172
- package/docs/interfaces/PdfConversionOptions.html +0 -102
- package/docs/interfaces/PdfConversionResult.html +0 -97
- package/docs/interfaces/PdfMarkdownOptions.html +0 -198
- package/docs/interfaces/PdfMarkdownResult.html +0 -106
- package/docs/interfaces/PdfPageMarkdown.html +0 -94
- package/docs/interfaces/PreparedPromptResponse.html +0 -62
- package/docs/interfaces/ProcessTextResponse.html +0 -86
- package/docs/interfaces/PromptFile.html +0 -70
- package/docs/interfaces/PromptFileContent.html +0 -76
- package/docs/interfaces/PromptFilesResponse.html +0 -56
- package/docs/interfaces/PromptFolder.html +0 -80
- package/docs/interfaces/PromptFolderDefaults.html +0 -155
- package/docs/interfaces/PromptFolderDefaultsResponse.html +0 -79
- package/docs/interfaces/PromptFoldersResponse.html +0 -56
- package/docs/interfaces/RoomDetails.html +0 -151
- package/docs/interfaces/RoomErrorUpdate.html +0 -82
- package/docs/interfaces/RoomInfo.html +0 -88
- package/docs/interfaces/RoomMessageUpdate.html +0 -113
- package/docs/interfaces/RoomMessagesResponse.html +0 -62
- package/docs/interfaces/SendMessageResult.html +0 -62
- package/docs/interfaces/StoryErrorEvent.html +0 -84
- package/docs/interfaces/StoryIdea.html +0 -74
- package/docs/interfaces/StoryInfo.html +0 -198
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +0 -79
- package/docs/interfaces/StoryProgressChapterEvent.html +0 -72
- package/docs/interfaces/StoryState.html +0 -108
- package/docs/interfaces/StoryStateEvent.html +0 -76
- package/docs/interfaces/ToolArtifact.html +0 -85
- package/docs/interfaces/ToolCaller.html +0 -77
- package/docs/interfaces/ToolDefinition.html +0 -80
- package/docs/interfaces/ToolHelpers.html +0 -105
- package/docs/interfaces/ToolPackDocuments.html +0 -100
- package/docs/interfaces/ToolParameter.html +0 -74
- package/docs/interfaces/ToolRoomAccess.html +0 -260
- package/docs/interfaces/ToolSummary.html +0 -74
- package/docs/interfaces/ToolsResponse.html +0 -68
- package/docs/interfaces/Transaction.html +0 -104
- package/docs/interfaces/TransactionHistoryResponse.html +0 -62
- package/docs/modules.html +0 -53
- package/docs/types/PackOrigin.html +0 -34
- package/docs/types/PromptScope.html +0 -34
- package/docs/types/RoomTurnMode.html +0 -42
- package/docs/types/RoomUpdate.html +0 -36
- package/docs/types/RosterOverrides.html +0 -42
- package/docs/types/ToolContext.html +0 -40
- package/docs/types/ToolRunResult.html +0 -34
- package/src/tools/packs/dnd5e/README.md +0 -867
|
@@ -50,14 +50,37 @@ const crypto_1 = require("crypto");
|
|
|
50
50
|
const user_paths_service_1 = require("../config/user-paths.service");
|
|
51
51
|
const pack_artifacts_1 = require("./pack-artifacts");
|
|
52
52
|
const logger_1 = require("../common/logger");
|
|
53
|
+
/**
|
|
54
|
+
* Service for managing user artifacts (reusable markdown documents)
|
|
55
|
+
* Separate from AttachedFileService which handles agent-specific file uploads
|
|
56
|
+
* and separate from Room artifacts which are agent-generated conversation outputs
|
|
57
|
+
*
|
|
58
|
+
* Reads span two tiers: the user's own artifacts, and the read-only documents
|
|
59
|
+
* shipped by enabled tool packs (see `pack-artifacts.ts`). Writes only ever touch
|
|
60
|
+
* the user's, and a `pack:` id is refused rather than silently ignored.
|
|
61
|
+
*/
|
|
53
62
|
let ArtifactService = class ArtifactService {
|
|
54
63
|
userPaths;
|
|
55
64
|
artifactsDir;
|
|
65
|
+
/**
|
|
66
|
+
* Where packs live, highest precedence first: the user's own packs, then the
|
|
67
|
+
* host's. A pack name exists in only one of them, so the order settles a
|
|
68
|
+
* collision rather than layering.
|
|
69
|
+
*/
|
|
56
70
|
packRoots;
|
|
71
|
+
/**
|
|
72
|
+
* The packs whose documents this user should be offered.
|
|
73
|
+
*
|
|
74
|
+
* A thunk, and defaulting to none, so the many places that build an
|
|
75
|
+
* `ArtifactService` without a pack service keep working — they simply see no
|
|
76
|
+
* pack documents in a listing, which is what an unconfigured user sees anyway.
|
|
77
|
+
* Resolution never consults it.
|
|
78
|
+
*/
|
|
57
79
|
enabledPacks = () => [];
|
|
58
80
|
constructor(userPaths, storageDir) {
|
|
59
81
|
this.userPaths = userPaths;
|
|
60
82
|
this.packRoots = [this.userPaths.getUserPacksDir(), this.userPaths.getPacksDir()];
|
|
83
|
+
// Use provided storageDir or default to user-specific artifacts directory
|
|
61
84
|
if (storageDir) {
|
|
62
85
|
this.artifactsDir = storageDir;
|
|
63
86
|
}
|
|
@@ -65,13 +88,32 @@ let ArtifactService = class ArtifactService {
|
|
|
65
88
|
const userDataDir = this.userPaths.getUserDataDir();
|
|
66
89
|
this.artifactsDir = path.join(userDataDir, 'artifacts');
|
|
67
90
|
}
|
|
91
|
+
// Create artifacts directory if it doesn't exist
|
|
68
92
|
if (!fs.existsSync(this.artifactsDir)) {
|
|
69
93
|
fs.mkdirSync(this.artifactsDir, { recursive: true });
|
|
70
94
|
}
|
|
71
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Tells this service which packs the user has enabled.
|
|
98
|
+
*
|
|
99
|
+
* Set after construction because `PackService` and `ArtifactService` are both
|
|
100
|
+
* built per user and neither can be the other's constructor argument.
|
|
101
|
+
*
|
|
102
|
+
* @param enabledPacks A thunk over the user's enabled packs
|
|
103
|
+
*/
|
|
72
104
|
setEnabledPacks(enabledPacks) {
|
|
73
105
|
this.enabledPacks = enabledPacks;
|
|
74
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Guards every write path against a pack document.
|
|
109
|
+
*
|
|
110
|
+
* There is one copy of a shipped document and it is the same for every user,
|
|
111
|
+
* so editing, renaming or deleting one is not a thing a single user may do.
|
|
112
|
+
* Returning rather than throwing keeps the existing "false means it did not
|
|
113
|
+
* happen" contract of the write methods.
|
|
114
|
+
*
|
|
115
|
+
* @returns True when the caller should stop
|
|
116
|
+
*/
|
|
75
117
|
refuseWriteToPackDocument(artifactId, operation) {
|
|
76
118
|
if (!(0, pack_artifacts_1.isPackArtifactId)(artifactId)) {
|
|
77
119
|
return false;
|
|
@@ -79,9 +121,15 @@ let ArtifactService = class ArtifactService {
|
|
|
79
121
|
logger_1.logger.warn(`Refusing to ${operation} pack document ${artifactId}: shipped documents are read-only`);
|
|
80
122
|
return true;
|
|
81
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Gets the path to the metadata file
|
|
126
|
+
*/
|
|
82
127
|
getMetadataPath() {
|
|
83
128
|
return path.join(this.artifactsDir, 'metadata.json');
|
|
84
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Loads metadata from disk
|
|
132
|
+
*/
|
|
85
133
|
loadMetadata() {
|
|
86
134
|
const metadataPath = this.getMetadataPath();
|
|
87
135
|
if (!fs.existsSync(metadataPath)) {
|
|
@@ -96,13 +144,23 @@ let ArtifactService = class ArtifactService {
|
|
|
96
144
|
return {};
|
|
97
145
|
}
|
|
98
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Saves metadata to disk
|
|
149
|
+
*/
|
|
99
150
|
saveMetadata(metadata) {
|
|
100
151
|
const metadataPath = this.getMetadataPath();
|
|
101
152
|
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2), 'utf8');
|
|
102
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Gets the file path for an artifact
|
|
156
|
+
* @deprecated Use getArtifactFilePath instead for MIME-aware path resolution
|
|
157
|
+
*/
|
|
103
158
|
getArtifactPath(artifactId) {
|
|
104
159
|
return path.join(this.artifactsDir, `${artifactId}.md`);
|
|
105
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Gets the file path for an artifact based on its MIME type
|
|
163
|
+
*/
|
|
106
164
|
getArtifactFilePath(artifactId, metadata) {
|
|
107
165
|
if (metadata.mimeType?.startsWith('image/')) {
|
|
108
166
|
const extension = metadata.mimeType.split('/').pop();
|
|
@@ -110,10 +168,19 @@ let ArtifactService = class ArtifactService {
|
|
|
110
168
|
}
|
|
111
169
|
return path.join(this.artifactsDir, `${artifactId}.md`);
|
|
112
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Stores a new artifact
|
|
173
|
+
* @param name User-friendly name for the artifact
|
|
174
|
+
* @param content Markdown content
|
|
175
|
+
* @param description Optional description for the artifact
|
|
176
|
+
* @returns The artifactId
|
|
177
|
+
*/
|
|
113
178
|
storeArtifact(name, content, description) {
|
|
114
179
|
const artifactId = (0, crypto_1.randomUUID)();
|
|
115
180
|
const filePath = this.getArtifactPath(artifactId);
|
|
181
|
+
// Write content to file
|
|
116
182
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
183
|
+
// Update metadata
|
|
117
184
|
const metadata = this.loadMetadata();
|
|
118
185
|
metadata[artifactId] = {
|
|
119
186
|
artifactId,
|
|
@@ -127,7 +194,15 @@ let ArtifactService = class ArtifactService {
|
|
|
127
194
|
this.saveMetadata(metadata);
|
|
128
195
|
return artifactId;
|
|
129
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Gets artifact content
|
|
199
|
+
* @param artifactId The artifact ID
|
|
200
|
+
* @returns The content (string for text, Buffer for images), or null if not found
|
|
201
|
+
*/
|
|
130
202
|
getArtifact(artifactId) {
|
|
203
|
+
// Deliberately not gated on the pack being enabled: an agent resolves its
|
|
204
|
+
// attached ids on every request, and turning a pack off should not quietly
|
|
205
|
+
// strip a document out of an agent that already carries it.
|
|
131
206
|
if ((0, pack_artifacts_1.isPackArtifactId)(artifactId)) {
|
|
132
207
|
return (0, pack_artifacts_1.getPackArtifact)(this.packRoots, artifactId);
|
|
133
208
|
}
|
|
@@ -140,11 +215,12 @@ let ArtifactService = class ArtifactService {
|
|
|
140
215
|
return null;
|
|
141
216
|
}
|
|
142
217
|
try {
|
|
218
|
+
// Check if binary based on MIME type
|
|
143
219
|
if (metadata.mimeType?.startsWith('image/')) {
|
|
144
|
-
return fs.readFileSync(filePath);
|
|
220
|
+
return fs.readFileSync(filePath); // Return Buffer for images
|
|
145
221
|
}
|
|
146
222
|
else {
|
|
147
|
-
return fs.readFileSync(filePath, 'utf8');
|
|
223
|
+
return fs.readFileSync(filePath, 'utf8'); // Return string for text
|
|
148
224
|
}
|
|
149
225
|
}
|
|
150
226
|
catch (error) {
|
|
@@ -152,12 +228,39 @@ let ArtifactService = class ArtifactService {
|
|
|
152
228
|
return null;
|
|
153
229
|
}
|
|
154
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Lists a pack's document files by name, for a tool that enumerates its own
|
|
233
|
+
* documents rather than being handed them.
|
|
234
|
+
*
|
|
235
|
+
* Reads the pack's `artifacts/` directory rather than its manifest, so an
|
|
236
|
+
* operator can add a document by dropping a file in — see
|
|
237
|
+
* {@link listPackDocumentFiles}. Nothing in the client uses this; it exists for
|
|
238
|
+
* `helpers.packDocuments`.
|
|
239
|
+
* @param pack The pack name
|
|
240
|
+
* @param prefix Keep only file names starting with this
|
|
241
|
+
* @returns Bare `.md` file names, sorted
|
|
242
|
+
*/
|
|
155
243
|
listPackDocumentFiles(pack, prefix) {
|
|
156
244
|
return (0, pack_artifacts_1.listPackDocumentFiles)(this.packRoots, pack, prefix);
|
|
157
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Reads one of a pack's document files by name.
|
|
248
|
+
* @param pack The pack name
|
|
249
|
+
* @param fileName A bare file name from {@link listPackDocumentFiles}
|
|
250
|
+
* @returns The document's text, or null if there is no such file
|
|
251
|
+
*/
|
|
158
252
|
readPackDocumentFile(pack, fileName) {
|
|
159
253
|
return (0, pack_artifacts_1.readPackDocumentFile)(this.packRoots, pack, fileName);
|
|
160
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Lists all artifacts: the documents shipped by enabled tool packs first, then
|
|
257
|
+
* the user's own.
|
|
258
|
+
*
|
|
259
|
+
* Pack documents lead because they are the same for everyone and the user did
|
|
260
|
+
* not put them there — burying them among their own uploads is how they get
|
|
261
|
+
* missed.
|
|
262
|
+
* @returns Array of artifact metadata
|
|
263
|
+
*/
|
|
161
264
|
listArtifacts() {
|
|
162
265
|
const metadata = this.loadMetadata();
|
|
163
266
|
return [
|
|
@@ -165,6 +268,11 @@ let ArtifactService = class ArtifactService {
|
|
|
165
268
|
...Object.values(metadata),
|
|
166
269
|
];
|
|
167
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Gets metadata for a specific artifact
|
|
273
|
+
* @param artifactId The artifact ID
|
|
274
|
+
* @returns The metadata, or null if not found
|
|
275
|
+
*/
|
|
168
276
|
getArtifactMetadata(artifactId) {
|
|
169
277
|
if ((0, pack_artifacts_1.isPackArtifactId)(artifactId)) {
|
|
170
278
|
return (0, pack_artifacts_1.getPackArtifactMetadata)(this.packRoots, artifactId);
|
|
@@ -172,6 +280,12 @@ let ArtifactService = class ArtifactService {
|
|
|
172
280
|
const metadata = this.loadMetadata();
|
|
173
281
|
return metadata[artifactId] || null;
|
|
174
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Updates artifact content
|
|
285
|
+
* @param artifactId The artifact ID
|
|
286
|
+
* @param content New content
|
|
287
|
+
* @returns True if successful, false otherwise
|
|
288
|
+
*/
|
|
175
289
|
updateArtifact(artifactId, content) {
|
|
176
290
|
if (this.refuseWriteToPackDocument(artifactId, 'update')) {
|
|
177
291
|
return false;
|
|
@@ -181,7 +295,9 @@ let ArtifactService = class ArtifactService {
|
|
|
181
295
|
return false;
|
|
182
296
|
}
|
|
183
297
|
try {
|
|
298
|
+
// Write new content
|
|
184
299
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
300
|
+
// Update size in metadata
|
|
185
301
|
const metadata = this.loadMetadata();
|
|
186
302
|
if (metadata[artifactId]) {
|
|
187
303
|
metadata[artifactId].size = Buffer.byteLength(content, 'utf8');
|
|
@@ -194,6 +310,12 @@ let ArtifactService = class ArtifactService {
|
|
|
194
310
|
return false;
|
|
195
311
|
}
|
|
196
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Renames an artifact
|
|
315
|
+
* @param artifactId The artifact ID
|
|
316
|
+
* @param newName New name
|
|
317
|
+
* @returns True if successful, false otherwise
|
|
318
|
+
*/
|
|
197
319
|
renameArtifact(artifactId, newName) {
|
|
198
320
|
if (this.refuseWriteToPackDocument(artifactId, 'rename')) {
|
|
199
321
|
return false;
|
|
@@ -212,6 +334,12 @@ let ArtifactService = class ArtifactService {
|
|
|
212
334
|
return false;
|
|
213
335
|
}
|
|
214
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Updates an artifact's description in metadata
|
|
339
|
+
* @param artifactId The artifact ID
|
|
340
|
+
* @param description New description
|
|
341
|
+
* @returns True if successful, false otherwise
|
|
342
|
+
*/
|
|
215
343
|
updateArtifactDescription(artifactId, description) {
|
|
216
344
|
if (this.refuseWriteToPackDocument(artifactId, 'describe')) {
|
|
217
345
|
return false;
|
|
@@ -230,6 +358,11 @@ let ArtifactService = class ArtifactService {
|
|
|
230
358
|
return false;
|
|
231
359
|
}
|
|
232
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Deletes an artifact
|
|
363
|
+
* @param artifactId The artifact ID
|
|
364
|
+
* @returns True if successful, false otherwise
|
|
365
|
+
*/
|
|
233
366
|
deleteArtifact(artifactId) {
|
|
234
367
|
if (this.refuseWriteToPackDocument(artifactId, 'delete')) {
|
|
235
368
|
return false;
|
|
@@ -243,7 +376,9 @@ let ArtifactService = class ArtifactService {
|
|
|
243
376
|
return false;
|
|
244
377
|
}
|
|
245
378
|
try {
|
|
379
|
+
// Delete file
|
|
246
380
|
fs.unlinkSync(filePath);
|
|
381
|
+
// Update metadata
|
|
247
382
|
const allMetadata = this.loadMetadata();
|
|
248
383
|
delete allMetadata[artifactId];
|
|
249
384
|
this.saveMetadata(allMetadata);
|
|
@@ -254,12 +389,22 @@ let ArtifactService = class ArtifactService {
|
|
|
254
389
|
return false;
|
|
255
390
|
}
|
|
256
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Stores a new image artifact
|
|
394
|
+
* @param name User-friendly name for the artifact
|
|
395
|
+
* @param imageData Binary image data
|
|
396
|
+
* @param mimeType MIME type of the image (e.g., 'image/png')
|
|
397
|
+
* @param description Optional description for the artifact
|
|
398
|
+
* @returns The artifactId
|
|
399
|
+
*/
|
|
257
400
|
storeImageArtifact(name, imageData, mimeType, description) {
|
|
258
401
|
const artifactId = (0, crypto_1.randomUUID)();
|
|
259
|
-
const extension = mimeType.split('/')[1];
|
|
402
|
+
const extension = mimeType.split('/')[1]; // e.g., 'png' from 'image/png'
|
|
260
403
|
const fileName = `${artifactId}.${extension}`;
|
|
261
404
|
const filePath = path.join(this.artifactsDir, fileName);
|
|
405
|
+
// Write binary data
|
|
262
406
|
fs.writeFileSync(filePath, imageData);
|
|
407
|
+
// Update metadata
|
|
263
408
|
const metadata = this.loadMetadata();
|
|
264
409
|
metadata[artifactId] = {
|
|
265
410
|
artifactId,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { UserPathsService } from '../config/user-paths.service';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for file metadata
|
|
4
|
+
*/
|
|
2
5
|
export interface FileMetadata {
|
|
3
6
|
fileName: string;
|
|
4
7
|
fileId: string;
|
|
@@ -13,23 +16,107 @@ export interface FileMetadata {
|
|
|
13
16
|
[key: string]: any;
|
|
14
17
|
};
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Service for managing files attached to agents
|
|
21
|
+
*/
|
|
16
22
|
export declare class AttachedFileService {
|
|
17
23
|
private readonly userPaths;
|
|
18
24
|
private readonly attachedFilesDir;
|
|
19
25
|
constructor(userPaths: UserPathsService);
|
|
20
26
|
private getMetadataPath;
|
|
27
|
+
/**
|
|
28
|
+
* Stores a file for an owner (agent or room)
|
|
29
|
+
* @param ownerId The ID of the owner
|
|
30
|
+
* @param fileName The name of the file
|
|
31
|
+
* @param fileData The file data as a Uint8Array
|
|
32
|
+
* @param additionalMetadata Additional metadata to store with the file
|
|
33
|
+
* @returns The ID of the stored file
|
|
34
|
+
*/
|
|
21
35
|
storeFile(ownerId: string, fileName: string, fileData: Uint8Array, additionalMetadata?: Partial<FileMetadata>): string;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves a file for an owner
|
|
38
|
+
* @param ownerId The ID of the owner
|
|
39
|
+
* @param fileId The ID of the file
|
|
40
|
+
* @returns The file data as a Uint8Array, or null if not found
|
|
41
|
+
*/
|
|
22
42
|
getFile(ownerId: string, fileId: string): Uint8Array | null;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves a file by name for an owner
|
|
45
|
+
* @param ownerId The ID of the owner
|
|
46
|
+
* @param fileName The name of the file
|
|
47
|
+
* @returns The file data as a Uint8Array, or null if not found
|
|
48
|
+
*/
|
|
23
49
|
getFileByName(ownerId: string, fileName: string): Uint8Array | null;
|
|
50
|
+
/**
|
|
51
|
+
* Updates metadata for an existing file
|
|
52
|
+
* @param ownerId The ID of the owner
|
|
53
|
+
* @param fileId The ID of the file
|
|
54
|
+
* @param metadataUpdates The metadata updates to apply
|
|
55
|
+
* @returns True if the update was successful, false otherwise
|
|
56
|
+
*/
|
|
24
57
|
updateFileMetadata(ownerId: string, fileId: string, metadataUpdates: Partial<FileMetadata>): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Gets metadata for a file
|
|
60
|
+
* @param ownerId The ID of the owner
|
|
61
|
+
* @param fileId The ID of the file
|
|
62
|
+
* @returns The file metadata, or null if not found
|
|
63
|
+
*/
|
|
25
64
|
getFileMetadata(ownerId: string, fileId: string): FileMetadata | null;
|
|
65
|
+
/**
|
|
66
|
+
* Gets metadata for a file by its name
|
|
67
|
+
* @param ownerId The ID of the owner
|
|
68
|
+
* @param fileName The name of the file
|
|
69
|
+
* @returns The file metadata, or null if not found
|
|
70
|
+
*/
|
|
26
71
|
getFileMetadataByName(ownerId: string, fileName: string): FileMetadata | null;
|
|
72
|
+
/**
|
|
73
|
+
* Gets the ID of a file by its name
|
|
74
|
+
* @param ownerId The ID of the owner
|
|
75
|
+
* @param fileName The name of the file
|
|
76
|
+
* @returns The file ID, or null if not found
|
|
77
|
+
*/
|
|
27
78
|
getFileIdByName(ownerId: string, fileName: string): string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Lists all file metadata for an owner
|
|
81
|
+
* @param ownerId The ID of the owner
|
|
82
|
+
* @returns Array of file metadata objects
|
|
83
|
+
*/
|
|
28
84
|
listFileMetadata(ownerId: string): FileMetadata[];
|
|
85
|
+
/**
|
|
86
|
+
* Lists all files for an owner
|
|
87
|
+
* @param ownerId The ID of the owner
|
|
88
|
+
* @returns Array of file names
|
|
89
|
+
*/
|
|
29
90
|
listFiles(ownerId: string): string[];
|
|
91
|
+
/**
|
|
92
|
+
* Deletes a file for an owner
|
|
93
|
+
* @param ownerId The ID of the owner
|
|
94
|
+
* @param fileId The ID of the file
|
|
95
|
+
* @returns True if the file was deleted, false otherwise
|
|
96
|
+
*/
|
|
30
97
|
deleteFile(ownerId: string, fileId: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Deletes a file by name for an owner
|
|
100
|
+
* @param ownerId The ID of the owner
|
|
101
|
+
* @param fileName The name of the file
|
|
102
|
+
* @returns True if the file was deleted, false otherwise
|
|
103
|
+
*/
|
|
31
104
|
deleteFileByName(ownerId: string, fileName: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Deletes all files for an owner
|
|
107
|
+
* @param ownerId The ID of the owner
|
|
108
|
+
* @returns True if the owner's directory was deleted, false otherwise
|
|
109
|
+
*/
|
|
32
110
|
deleteAllFiles(ownerId: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the path to an owner's directory
|
|
113
|
+
* @param ownerId The ID of the owner
|
|
114
|
+
* @returns The path to the owner's directory
|
|
115
|
+
*/
|
|
33
116
|
private getOwnerDirectory;
|
|
117
|
+
/**
|
|
118
|
+
* Recursively deletes a directory
|
|
119
|
+
* @param dirPath The path to the directory
|
|
120
|
+
*/
|
|
34
121
|
private deleteDirectory;
|
|
35
122
|
}
|
|
@@ -49,6 +49,9 @@ const path = __importStar(require("path"));
|
|
|
49
49
|
const crypto_1 = require("crypto");
|
|
50
50
|
const user_paths_service_1 = require("../config/user-paths.service");
|
|
51
51
|
const logger_1 = require("../common/logger");
|
|
52
|
+
/**
|
|
53
|
+
* Service for managing files attached to agents
|
|
54
|
+
*/
|
|
52
55
|
let AttachedFileService = class AttachedFileService {
|
|
53
56
|
userPaths;
|
|
54
57
|
attachedFilesDir;
|
|
@@ -62,24 +65,39 @@ let AttachedFileService = class AttachedFileService {
|
|
|
62
65
|
getMetadataPath(ownerId) {
|
|
63
66
|
return path.join(this.getOwnerDirectory(ownerId), 'metadata.json');
|
|
64
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Stores a file for an owner (agent or room)
|
|
70
|
+
* @param ownerId The ID of the owner
|
|
71
|
+
* @param fileName The name of the file
|
|
72
|
+
* @param fileData The file data as a Uint8Array
|
|
73
|
+
* @param additionalMetadata Additional metadata to store with the file
|
|
74
|
+
* @returns The ID of the stored file
|
|
75
|
+
*/
|
|
65
76
|
storeFile(ownerId, fileName, fileData, additionalMetadata = {}) {
|
|
77
|
+
// Check if a file with this name already exists for this owner
|
|
66
78
|
const existingMetadata = this.getFileMetadataByName(ownerId, fileName);
|
|
67
79
|
if (existingMetadata) {
|
|
68
80
|
logger_1.logger.log(`File "${fileName}" already exists for owner ${ownerId}, returning existing fileId: ${existingMetadata.fileId}`);
|
|
81
|
+
// Update existing metadata if provided
|
|
69
82
|
if (Object.keys(additionalMetadata).length > 0) {
|
|
70
83
|
this.updateFileMetadata(ownerId, existingMetadata.fileId, additionalMetadata);
|
|
71
84
|
}
|
|
72
85
|
return existingMetadata.fileId;
|
|
73
86
|
}
|
|
87
|
+
// Create the owner's directory if it doesn't exist
|
|
74
88
|
const ownerDir = this.getOwnerDirectory(ownerId);
|
|
75
89
|
if (!fs.existsSync(ownerDir)) {
|
|
76
90
|
fs.mkdirSync(ownerDir, { recursive: true });
|
|
77
91
|
}
|
|
92
|
+
// Create a unique file ID
|
|
78
93
|
const fileId = (0, crypto_1.randomUUID)();
|
|
94
|
+
// Store the file on disk
|
|
79
95
|
const filePath = path.join(ownerDir, fileId);
|
|
80
96
|
fs.writeFileSync(filePath, Buffer.from(fileData));
|
|
97
|
+
// Prepare metadata
|
|
81
98
|
const metadataPath = this.getMetadataPath(ownerId);
|
|
82
99
|
let metadataMap = {};
|
|
100
|
+
// Load existing metadata if it exists
|
|
83
101
|
if (fs.existsSync(metadataPath)) {
|
|
84
102
|
try {
|
|
85
103
|
metadataMap = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
|
|
@@ -88,6 +106,7 @@ let AttachedFileService = class AttachedFileService {
|
|
|
88
106
|
logger_1.logger.error('Error loading file metadata:', error);
|
|
89
107
|
}
|
|
90
108
|
}
|
|
109
|
+
// Create new metadata entry
|
|
91
110
|
const metadata = {
|
|
92
111
|
fileName,
|
|
93
112
|
fileId,
|
|
@@ -95,21 +114,36 @@ let AttachedFileService = class AttachedFileService {
|
|
|
95
114
|
size: fileData.length,
|
|
96
115
|
...additionalMetadata,
|
|
97
116
|
};
|
|
117
|
+
// Add the new file to the metadata
|
|
98
118
|
metadataMap[fileId] = metadata;
|
|
119
|
+
// Save the updated metadata
|
|
99
120
|
fs.writeFileSync(metadataPath, JSON.stringify(metadataMap, null, 2));
|
|
100
121
|
return fileId;
|
|
101
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves a file for an owner
|
|
125
|
+
* @param ownerId The ID of the owner
|
|
126
|
+
* @param fileId The ID of the file
|
|
127
|
+
* @returns The file data as a Uint8Array, or null if not found
|
|
128
|
+
*/
|
|
102
129
|
getFile(ownerId, fileId) {
|
|
103
130
|
const filePath = path.join(this.getOwnerDirectory(ownerId), fileId);
|
|
104
131
|
if (!fs.existsSync(filePath)) {
|
|
105
132
|
return null;
|
|
106
133
|
}
|
|
134
|
+
// Check if it's a file, not a directory
|
|
107
135
|
const stats = fs.statSync(filePath);
|
|
108
136
|
if (!stats.isFile()) {
|
|
109
137
|
return null;
|
|
110
138
|
}
|
|
111
139
|
return new Uint8Array(fs.readFileSync(filePath));
|
|
112
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves a file by name for an owner
|
|
143
|
+
* @param ownerId The ID of the owner
|
|
144
|
+
* @param fileName The name of the file
|
|
145
|
+
* @returns The file data as a Uint8Array, or null if not found
|
|
146
|
+
*/
|
|
113
147
|
getFileByName(ownerId, fileName) {
|
|
114
148
|
const fileId = this.getFileIdByName(ownerId, fileName);
|
|
115
149
|
if (!fileId) {
|
|
@@ -117,6 +151,13 @@ let AttachedFileService = class AttachedFileService {
|
|
|
117
151
|
}
|
|
118
152
|
return this.getFile(ownerId, fileId);
|
|
119
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Updates metadata for an existing file
|
|
156
|
+
* @param ownerId The ID of the owner
|
|
157
|
+
* @param fileId The ID of the file
|
|
158
|
+
* @param metadataUpdates The metadata updates to apply
|
|
159
|
+
* @returns True if the update was successful, false otherwise
|
|
160
|
+
*/
|
|
120
161
|
updateFileMetadata(ownerId, fileId, metadataUpdates) {
|
|
121
162
|
const metadataPath = this.getMetadataPath(ownerId);
|
|
122
163
|
if (!fs.existsSync(metadataPath)) {
|
|
@@ -127,10 +168,12 @@ let AttachedFileService = class AttachedFileService {
|
|
|
127
168
|
if (!metadataMap[fileId]) {
|
|
128
169
|
return false;
|
|
129
170
|
}
|
|
171
|
+
// Update metadata with new values
|
|
130
172
|
metadataMap[fileId] = {
|
|
131
173
|
...metadataMap[fileId],
|
|
132
174
|
...metadataUpdates,
|
|
133
175
|
};
|
|
176
|
+
// Save updated metadata
|
|
134
177
|
fs.writeFileSync(metadataPath, JSON.stringify(metadataMap, null, 2));
|
|
135
178
|
return true;
|
|
136
179
|
}
|
|
@@ -139,6 +182,12 @@ let AttachedFileService = class AttachedFileService {
|
|
|
139
182
|
return false;
|
|
140
183
|
}
|
|
141
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Gets metadata for a file
|
|
187
|
+
* @param ownerId The ID of the owner
|
|
188
|
+
* @param fileId The ID of the file
|
|
189
|
+
* @returns The file metadata, or null if not found
|
|
190
|
+
*/
|
|
142
191
|
getFileMetadata(ownerId, fileId) {
|
|
143
192
|
const metadataPath = this.getMetadataPath(ownerId);
|
|
144
193
|
if (!fs.existsSync(metadataPath)) {
|
|
@@ -153,6 +202,12 @@ let AttachedFileService = class AttachedFileService {
|
|
|
153
202
|
return null;
|
|
154
203
|
}
|
|
155
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Gets metadata for a file by its name
|
|
207
|
+
* @param ownerId The ID of the owner
|
|
208
|
+
* @param fileName The name of the file
|
|
209
|
+
* @returns The file metadata, or null if not found
|
|
210
|
+
*/
|
|
156
211
|
getFileMetadataByName(ownerId, fileName) {
|
|
157
212
|
const metadataPath = this.getMetadataPath(ownerId);
|
|
158
213
|
if (!fs.existsSync(metadataPath)) {
|
|
@@ -160,6 +215,7 @@ let AttachedFileService = class AttachedFileService {
|
|
|
160
215
|
}
|
|
161
216
|
try {
|
|
162
217
|
const metadataMap = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
|
|
218
|
+
// Find the file metadata by name
|
|
163
219
|
for (const fileId in metadataMap) {
|
|
164
220
|
if (metadataMap[fileId].fileName === fileName) {
|
|
165
221
|
return metadataMap[fileId];
|
|
@@ -171,10 +227,21 @@ let AttachedFileService = class AttachedFileService {
|
|
|
171
227
|
}
|
|
172
228
|
return null;
|
|
173
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Gets the ID of a file by its name
|
|
232
|
+
* @param ownerId The ID of the owner
|
|
233
|
+
* @param fileName The name of the file
|
|
234
|
+
* @returns The file ID, or null if not found
|
|
235
|
+
*/
|
|
174
236
|
getFileIdByName(ownerId, fileName) {
|
|
175
237
|
const metadata = this.getFileMetadataByName(ownerId, fileName);
|
|
176
238
|
return metadata ? metadata.fileId : null;
|
|
177
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Lists all file metadata for an owner
|
|
242
|
+
* @param ownerId The ID of the owner
|
|
243
|
+
* @returns Array of file metadata objects
|
|
244
|
+
*/
|
|
178
245
|
listFileMetadata(ownerId) {
|
|
179
246
|
const metadataPath = this.getMetadataPath(ownerId);
|
|
180
247
|
if (!fs.existsSync(metadataPath)) {
|
|
@@ -189,9 +256,20 @@ let AttachedFileService = class AttachedFileService {
|
|
|
189
256
|
return [];
|
|
190
257
|
}
|
|
191
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Lists all files for an owner
|
|
261
|
+
* @param ownerId The ID of the owner
|
|
262
|
+
* @returns Array of file names
|
|
263
|
+
*/
|
|
192
264
|
listFiles(ownerId) {
|
|
193
265
|
return this.listFileMetadata(ownerId).map((metadata) => metadata.fileName);
|
|
194
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Deletes a file for an owner
|
|
269
|
+
* @param ownerId The ID of the owner
|
|
270
|
+
* @param fileId The ID of the file
|
|
271
|
+
* @returns True if the file was deleted, false otherwise
|
|
272
|
+
*/
|
|
195
273
|
deleteFile(ownerId, fileId) {
|
|
196
274
|
const ownerDir = this.getOwnerDirectory(ownerId);
|
|
197
275
|
const filePath = path.join(ownerDir, fileId);
|
|
@@ -199,10 +277,13 @@ let AttachedFileService = class AttachedFileService {
|
|
|
199
277
|
if (!fs.existsSync(filePath)) {
|
|
200
278
|
return false;
|
|
201
279
|
}
|
|
280
|
+
// Delete the file
|
|
202
281
|
fs.unlinkSync(filePath);
|
|
282
|
+
// Update the metadata
|
|
203
283
|
if (fs.existsSync(metadataPath)) {
|
|
204
284
|
try {
|
|
205
285
|
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
|
|
286
|
+
// Remove the file from the metadata
|
|
206
287
|
if (metadata[fileId]) {
|
|
207
288
|
delete metadata[fileId];
|
|
208
289
|
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
|
|
@@ -214,6 +295,12 @@ let AttachedFileService = class AttachedFileService {
|
|
|
214
295
|
}
|
|
215
296
|
return true;
|
|
216
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Deletes a file by name for an owner
|
|
300
|
+
* @param ownerId The ID of the owner
|
|
301
|
+
* @param fileName The name of the file
|
|
302
|
+
* @returns True if the file was deleted, false otherwise
|
|
303
|
+
*/
|
|
217
304
|
deleteFileByName(ownerId, fileName) {
|
|
218
305
|
const fileId = this.getFileIdByName(ownerId, fileName);
|
|
219
306
|
if (!fileId) {
|
|
@@ -221,28 +308,46 @@ let AttachedFileService = class AttachedFileService {
|
|
|
221
308
|
}
|
|
222
309
|
return this.deleteFile(ownerId, fileId);
|
|
223
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Deletes all files for an owner
|
|
313
|
+
* @param ownerId The ID of the owner
|
|
314
|
+
* @returns True if the owner's directory was deleted, false otherwise
|
|
315
|
+
*/
|
|
224
316
|
deleteAllFiles(ownerId) {
|
|
225
317
|
const ownerDir = this.getOwnerDirectory(ownerId);
|
|
226
318
|
if (!fs.existsSync(ownerDir)) {
|
|
227
319
|
return false;
|
|
228
320
|
}
|
|
321
|
+
// Delete the owner's directory recursively
|
|
229
322
|
this.deleteDirectory(ownerDir);
|
|
230
323
|
return true;
|
|
231
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Gets the path to an owner's directory
|
|
327
|
+
* @param ownerId The ID of the owner
|
|
328
|
+
* @returns The path to the owner's directory
|
|
329
|
+
*/
|
|
232
330
|
getOwnerDirectory(ownerId) {
|
|
233
331
|
return path.join(this.attachedFilesDir, ownerId);
|
|
234
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Recursively deletes a directory
|
|
335
|
+
* @param dirPath The path to the directory
|
|
336
|
+
*/
|
|
235
337
|
deleteDirectory(dirPath) {
|
|
236
338
|
if (fs.existsSync(dirPath)) {
|
|
237
339
|
fs.readdirSync(dirPath).forEach((file) => {
|
|
238
340
|
const curPath = path.join(dirPath, file);
|
|
239
341
|
if (fs.lstatSync(curPath).isDirectory()) {
|
|
342
|
+
// Recursive call for directories
|
|
240
343
|
this.deleteDirectory(curPath);
|
|
241
344
|
}
|
|
242
345
|
else {
|
|
346
|
+
// Delete file
|
|
243
347
|
fs.unlinkSync(curPath);
|
|
244
348
|
}
|
|
245
349
|
});
|
|
350
|
+
// Delete the empty directory
|
|
246
351
|
fs.rmdirSync(dirPath);
|
|
247
352
|
}
|
|
248
353
|
}
|