briyah 1.0.0
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/.prettierrc +7 -0
- package/dist/ai/LLM/anthropic.module.d.ts +2 -0
- package/dist/ai/LLM/anthropic.module.js +21 -0
- package/dist/ai/LLM/anthropic.service.d.ts +27 -0
- package/dist/ai/LLM/anthropic.service.js +329 -0
- package/dist/ai/LLM/base-ai.service.d.ts +45 -0
- package/dist/ai/LLM/base-ai.service.js +409 -0
- package/dist/ai/LLM/deepseek.module.d.ts +2 -0
- package/dist/ai/LLM/deepseek.module.js +21 -0
- package/dist/ai/LLM/deepseek.service.d.ts +15 -0
- package/dist/ai/LLM/deepseek.service.js +279 -0
- package/dist/ai/LLM/fal.module.d.ts +2 -0
- package/dist/ai/LLM/fal.module.js +21 -0
- package/dist/ai/LLM/fal.service.d.ts +17 -0
- package/dist/ai/LLM/fal.service.js +314 -0
- package/dist/ai/LLM/googleai.module.d.ts +2 -0
- package/dist/ai/LLM/googleai.module.js +21 -0
- package/dist/ai/LLM/googleai.service.d.ts +20 -0
- package/dist/ai/LLM/googleai.service.js +271 -0
- package/dist/ai/LLM/grok.module.d.ts +2 -0
- package/dist/ai/LLM/grok.module.js +21 -0
- package/dist/ai/LLM/grok.service.d.ts +14 -0
- package/dist/ai/LLM/grok.service.js +263 -0
- package/dist/ai/LLM/mock.module.d.ts +2 -0
- package/dist/ai/LLM/mock.module.js +21 -0
- package/dist/ai/LLM/mock.service.d.ts +13 -0
- package/dist/ai/LLM/mock.service.js +194 -0
- package/dist/ai/LLM/openai.module.d.ts +2 -0
- package/dist/ai/LLM/openai.module.js +21 -0
- package/dist/ai/LLM/openai.service.d.ts +21 -0
- package/dist/ai/LLM/openai.service.js +421 -0
- package/dist/ai/LLM/together.module.d.ts +2 -0
- package/dist/ai/LLM/together.module.js +21 -0
- package/dist/ai/LLM/together.service.d.ts +18 -0
- package/dist/ai/LLM/together.service.js +285 -0
- package/dist/ai/LLM/vertexai.module.d.ts +2 -0
- package/dist/ai/LLM/vertexai.module.js +21 -0
- package/dist/ai/LLM/vertexai.service.d.ts +17 -0
- package/dist/ai/LLM/vertexai.service.js +323 -0
- package/dist/ai/agent-config.d.ts +32 -0
- package/dist/ai/agent-config.js +2 -0
- package/dist/ai/agent-factory.d.ts +15 -0
- package/dist/ai/agent-factory.js +24 -0
- package/dist/ai/agent-message.service.d.ts +9 -0
- package/dist/ai/agent-message.service.js +56 -0
- package/dist/ai/agent-store.module.d.ts +2 -0
- package/dist/ai/agent-store.module.js +21 -0
- package/dist/ai/agent-store.service.d.ts +31 -0
- package/dist/ai/agent-store.service.js +352 -0
- package/dist/ai/agent.d.ts +75 -0
- package/dist/ai/agent.js +174 -0
- package/dist/ai/ai-factory.module.d.ts +2 -0
- package/dist/ai/ai-factory.module.js +40 -0
- package/dist/ai/ai-factory.service.d.ts +24 -0
- package/dist/ai/ai-factory.service.js +94 -0
- package/dist/ai/artifact.module.d.ts +2 -0
- package/dist/ai/artifact.module.js +22 -0
- package/dist/ai/artifact.service.d.ts +21 -0
- package/dist/ai/artifact.service.js +239 -0
- package/dist/ai/attached-file.module.d.ts +2 -0
- package/dist/ai/attached-file.module.js +22 -0
- package/dist/ai/attached-file.service.d.ts +35 -0
- package/dist/ai/attached-file.service.js +253 -0
- package/dist/ai/model_prices.d.ts +2 -0
- package/dist/ai/model_prices.js +54 -0
- package/dist/ai/published-agents.service.d.ts +13 -0
- package/dist/ai/published-agents.service.js +118 -0
- package/dist/app/balance-message.service.d.ts +8 -0
- package/dist/app/balance-message.service.js +45 -0
- package/dist/app/balance.module.d.ts +2 -0
- package/dist/app/balance.module.js +20 -0
- package/dist/app/balance.service.d.ts +18 -0
- package/dist/app/balance.service.js +158 -0
- package/dist/app/stripe.controller.d.ts +31 -0
- package/dist/app/stripe.controller.js +150 -0
- package/dist/app/stripe.module.d.ts +2 -0
- package/dist/app/stripe.module.js +22 -0
- package/dist/app/stripe.service.d.ts +28 -0
- package/dist/app/stripe.service.js +198 -0
- package/dist/app/transaction.service.d.ts +15 -0
- package/dist/app/transaction.service.js +139 -0
- package/dist/app/user-service-factory.d.ts +21 -0
- package/dist/app/user-service-factory.js +81 -0
- package/dist/app/user-service-manager.d.ts +28 -0
- package/dist/app/user-service-manager.js +102 -0
- package/dist/app.controller.d.ts +232 -0
- package/dist/app.controller.js +2536 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +45 -0
- package/dist/app.service.d.ts +186 -0
- package/dist/app.service.js +1334 -0
- package/dist/auth/agent-access.decorator.d.ts +2 -0
- package/dist/auth/agent-access.decorator.js +10 -0
- package/dist/auth/auth.controller.d.ts +38 -0
- package/dist/auth/auth.controller.js +356 -0
- package/dist/auth/auth.module.d.ts +2 -0
- package/dist/auth/auth.module.js +55 -0
- package/dist/auth/auth.service.d.ts +14 -0
- package/dist/auth/auth.service.js +84 -0
- package/dist/auth/dto/bot-login.dto.d.ts +4 -0
- package/dist/auth/dto/bot-login.dto.js +2 -0
- package/dist/auth/dto/password-reset.dto.d.ts +11 -0
- package/dist/auth/dto/password-reset.dto.js +2 -0
- package/dist/auth/dto/phone-login.dto.d.ts +8 -0
- package/dist/auth/dto/phone-login.dto.js +2 -0
- package/dist/auth/dto/phone-verification.dto.d.ts +9 -0
- package/dist/auth/dto/phone-verification.dto.js +2 -0
- package/dist/auth/jwt-auth.guard.d.ts +13 -0
- package/dist/auth/jwt-auth.guard.js +143 -0
- package/dist/auth/jwt.strategy.d.ts +17 -0
- package/dist/auth/jwt.strategy.js +45 -0
- package/dist/auth/phone-validation.service.d.ts +7 -0
- package/dist/auth/phone-validation.service.js +50 -0
- package/dist/auth/public.decorator.d.ts +2 -0
- package/dist/auth/public.decorator.js +7 -0
- package/dist/auth/rate-limit.service.d.ts +16 -0
- package/dist/auth/rate-limit.service.js +84 -0
- package/dist/auth/room-access.decorator.d.ts +2 -0
- package/dist/auth/room-access.decorator.js +10 -0
- package/dist/auth/scopes.decorator.d.ts +2 -0
- package/dist/auth/scopes.decorator.js +7 -0
- package/dist/auth/scopes.guard.d.ts +9 -0
- package/dist/auth/scopes.guard.js +82 -0
- package/dist/auth/session.guard.d.ts +7 -0
- package/dist/auth/session.guard.js +55 -0
- package/dist/auth/twilio.service.d.ts +15 -0
- package/dist/auth/twilio.service.js +139 -0
- package/dist/auth/users.service.d.ts +24 -0
- package/dist/auth/users.service.js +149 -0
- package/dist/common/errors.d.ts +12 -0
- package/dist/common/errors.js +43 -0
- package/dist/config/configuration.module.d.ts +2 -0
- package/dist/config/configuration.module.js +20 -0
- package/dist/config/configuration.service.d.ts +26 -0
- package/dist/config/configuration.service.js +131 -0
- package/dist/main.js +15749 -0
- package/dist/room/artifact-store.service.d.ts +15 -0
- package/dist/room/artifact-store.service.js +226 -0
- package/dist/room/artifact.d.ts +6 -0
- package/dist/room/artifact.js +2 -0
- package/dist/room/message.d.ts +19 -0
- package/dist/room/message.js +70 -0
- package/dist/room/published-rooms.service.d.ts +12 -0
- package/dist/room/published-rooms.service.js +108 -0
- package/dist/room/room-config.d.ts +12 -0
- package/dist/room/room-config.js +2 -0
- package/dist/room/room-factory.d.ts +7 -0
- package/dist/room/room-factory.js +16 -0
- package/dist/room/room-message.module.d.ts +2 -0
- package/dist/room/room-message.module.js +21 -0
- package/dist/room/room-message.service.d.ts +8 -0
- package/dist/room/room-message.service.js +44 -0
- package/dist/room/room-store.module.d.ts +2 -0
- package/dist/room/room-store.module.js +25 -0
- package/dist/room/room-store.service.d.ts +38 -0
- package/dist/room/room-store.service.js +353 -0
- package/dist/room/room.d.ts +107 -0
- package/dist/room/room.js +833 -0
- package/dist/sdk/briyah-config.d.ts +13 -0
- package/dist/sdk/briyah-config.js +32 -0
- package/dist/sdk/briyah.d.ts +36 -0
- package/dist/sdk/briyah.js +122 -0
- package/dist/sdk/index.d.ts +6 -0
- package/dist/sdk/index.js +11 -0
- package/dist/server/src/ai/LLM/anthropic.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/anthropic.module.js +21 -0
- package/dist/server/src/ai/LLM/anthropic.service.d.ts +27 -0
- package/dist/server/src/ai/LLM/anthropic.service.js +329 -0
- package/dist/server/src/ai/LLM/base-ai.service.d.ts +45 -0
- package/dist/server/src/ai/LLM/base-ai.service.js +409 -0
- package/dist/server/src/ai/LLM/deepseek.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/deepseek.module.js +21 -0
- package/dist/server/src/ai/LLM/deepseek.service.d.ts +15 -0
- package/dist/server/src/ai/LLM/deepseek.service.js +279 -0
- package/dist/server/src/ai/LLM/fal.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/fal.module.js +21 -0
- package/dist/server/src/ai/LLM/fal.service.d.ts +17 -0
- package/dist/server/src/ai/LLM/fal.service.js +314 -0
- package/dist/server/src/ai/LLM/googleai.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/googleai.module.js +21 -0
- package/dist/server/src/ai/LLM/googleai.service.d.ts +20 -0
- package/dist/server/src/ai/LLM/googleai.service.js +271 -0
- package/dist/server/src/ai/LLM/grok.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/grok.module.js +21 -0
- package/dist/server/src/ai/LLM/grok.service.d.ts +14 -0
- package/dist/server/src/ai/LLM/grok.service.js +263 -0
- package/dist/server/src/ai/LLM/mock.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/mock.module.js +21 -0
- package/dist/server/src/ai/LLM/mock.service.d.ts +13 -0
- package/dist/server/src/ai/LLM/mock.service.js +194 -0
- package/dist/server/src/ai/LLM/openai.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/openai.module.js +21 -0
- package/dist/server/src/ai/LLM/openai.service.d.ts +21 -0
- package/dist/server/src/ai/LLM/openai.service.js +421 -0
- package/dist/server/src/ai/LLM/together.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/together.module.js +21 -0
- package/dist/server/src/ai/LLM/together.service.d.ts +18 -0
- package/dist/server/src/ai/LLM/together.service.js +285 -0
- package/dist/server/src/ai/LLM/vertexai.module.d.ts +2 -0
- package/dist/server/src/ai/LLM/vertexai.module.js +21 -0
- package/dist/server/src/ai/LLM/vertexai.service.d.ts +17 -0
- package/dist/server/src/ai/LLM/vertexai.service.js +323 -0
- package/dist/server/src/ai/agent-config.d.ts +32 -0
- package/dist/server/src/ai/agent-config.js +2 -0
- package/dist/server/src/ai/agent-factory.d.ts +15 -0
- package/dist/server/src/ai/agent-factory.js +24 -0
- package/dist/server/src/ai/agent-message.service.d.ts +9 -0
- package/dist/server/src/ai/agent-message.service.js +56 -0
- package/dist/server/src/ai/agent-store.module.d.ts +2 -0
- package/dist/server/src/ai/agent-store.module.js +21 -0
- package/dist/server/src/ai/agent-store.service.d.ts +31 -0
- package/dist/server/src/ai/agent-store.service.js +352 -0
- package/dist/server/src/ai/agent.d.ts +75 -0
- package/dist/server/src/ai/agent.js +174 -0
- package/dist/server/src/ai/ai-factory.module.d.ts +2 -0
- package/dist/server/src/ai/ai-factory.module.js +40 -0
- package/dist/server/src/ai/ai-factory.service.d.ts +24 -0
- package/dist/server/src/ai/ai-factory.service.js +94 -0
- package/dist/server/src/ai/artifact.module.d.ts +2 -0
- package/dist/server/src/ai/artifact.module.js +22 -0
- package/dist/server/src/ai/artifact.service.d.ts +21 -0
- package/dist/server/src/ai/artifact.service.js +239 -0
- package/dist/server/src/ai/attached-file.module.d.ts +2 -0
- package/dist/server/src/ai/attached-file.module.js +22 -0
- package/dist/server/src/ai/attached-file.service.d.ts +35 -0
- package/dist/server/src/ai/attached-file.service.js +253 -0
- package/dist/server/src/ai/model_prices.d.ts +2 -0
- package/dist/server/src/ai/model_prices.js +54 -0
- package/dist/server/src/ai/published-agents.service.d.ts +13 -0
- package/dist/server/src/ai/published-agents.service.js +118 -0
- package/dist/server/src/app/balance-message.service.d.ts +8 -0
- package/dist/server/src/app/balance-message.service.js +45 -0
- package/dist/server/src/app/balance.module.d.ts +2 -0
- package/dist/server/src/app/balance.module.js +20 -0
- package/dist/server/src/app/balance.service.d.ts +18 -0
- package/dist/server/src/app/balance.service.js +158 -0
- package/dist/server/src/app/stripe.controller.d.ts +31 -0
- package/dist/server/src/app/stripe.controller.js +148 -0
- package/dist/server/src/app/stripe.module.d.ts +2 -0
- package/dist/server/src/app/stripe.module.js +22 -0
- package/dist/server/src/app/stripe.service.d.ts +28 -0
- package/dist/server/src/app/stripe.service.js +198 -0
- package/dist/server/src/app/transaction.service.d.ts +15 -0
- package/dist/server/src/app/transaction.service.js +139 -0
- package/dist/server/src/app/user-service-factory.d.ts +21 -0
- package/dist/server/src/app/user-service-factory.js +81 -0
- package/dist/server/src/app/user-service-manager.d.ts +28 -0
- package/dist/server/src/app/user-service-manager.js +102 -0
- package/dist/server/src/app.controller.d.ts +232 -0
- package/dist/server/src/app.controller.js +2534 -0
- package/dist/server/src/app.module.d.ts +2 -0
- package/dist/server/src/app.module.js +45 -0
- package/dist/server/src/app.service.d.ts +186 -0
- package/dist/server/src/app.service.js +1334 -0
- package/dist/server/src/auth/agent-access.decorator.d.ts +2 -0
- package/dist/server/src/auth/agent-access.decorator.js +10 -0
- package/dist/server/src/auth/auth.controller.d.ts +38 -0
- package/dist/server/src/auth/auth.controller.js +356 -0
- package/dist/server/src/auth/auth.module.d.ts +2 -0
- package/dist/server/src/auth/auth.module.js +55 -0
- package/dist/server/src/auth/auth.service.d.ts +14 -0
- package/dist/server/src/auth/auth.service.js +84 -0
- package/dist/server/src/auth/dto/bot-login.dto.d.ts +4 -0
- package/dist/server/src/auth/dto/bot-login.dto.js +2 -0
- package/dist/server/src/auth/dto/password-reset.dto.d.ts +11 -0
- package/dist/server/src/auth/dto/password-reset.dto.js +2 -0
- package/dist/server/src/auth/dto/phone-login.dto.d.ts +8 -0
- package/dist/server/src/auth/dto/phone-login.dto.js +2 -0
- package/dist/server/src/auth/dto/phone-verification.dto.d.ts +9 -0
- package/dist/server/src/auth/dto/phone-verification.dto.js +2 -0
- package/dist/server/src/auth/jwt-auth.guard.d.ts +13 -0
- package/dist/server/src/auth/jwt-auth.guard.js +143 -0
- package/dist/server/src/auth/jwt.strategy.d.ts +17 -0
- package/dist/server/src/auth/jwt.strategy.js +45 -0
- package/dist/server/src/auth/phone-validation.service.d.ts +7 -0
- package/dist/server/src/auth/phone-validation.service.js +50 -0
- package/dist/server/src/auth/public.decorator.d.ts +2 -0
- package/dist/server/src/auth/public.decorator.js +7 -0
- package/dist/server/src/auth/rate-limit.service.d.ts +16 -0
- package/dist/server/src/auth/rate-limit.service.js +84 -0
- package/dist/server/src/auth/room-access.decorator.d.ts +2 -0
- package/dist/server/src/auth/room-access.decorator.js +10 -0
- package/dist/server/src/auth/scopes.decorator.d.ts +2 -0
- package/dist/server/src/auth/scopes.decorator.js +7 -0
- package/dist/server/src/auth/scopes.guard.d.ts +9 -0
- package/dist/server/src/auth/scopes.guard.js +82 -0
- package/dist/server/src/auth/session.guard.d.ts +7 -0
- package/dist/server/src/auth/session.guard.js +55 -0
- package/dist/server/src/auth/twilio.service.d.ts +15 -0
- package/dist/server/src/auth/twilio.service.js +139 -0
- package/dist/server/src/auth/users.service.d.ts +24 -0
- package/dist/server/src/auth/users.service.js +149 -0
- package/dist/server/src/common/errors.d.ts +12 -0
- package/dist/server/src/common/errors.js +43 -0
- package/dist/server/src/config/configuration.module.d.ts +2 -0
- package/dist/server/src/config/configuration.module.js +20 -0
- package/dist/server/src/config/configuration.service.d.ts +26 -0
- package/dist/server/src/config/configuration.service.js +131 -0
- package/dist/server/src/room/artifact-store.service.d.ts +15 -0
- package/dist/server/src/room/artifact-store.service.js +226 -0
- package/dist/server/src/room/artifact.d.ts +6 -0
- package/dist/server/src/room/artifact.js +2 -0
- package/dist/server/src/room/message.d.ts +19 -0
- package/dist/server/src/room/message.js +70 -0
- package/dist/server/src/room/published-rooms.service.d.ts +12 -0
- package/dist/server/src/room/published-rooms.service.js +108 -0
- package/dist/server/src/room/room-config.d.ts +12 -0
- package/dist/server/src/room/room-config.js +2 -0
- package/dist/server/src/room/room-factory.d.ts +7 -0
- package/dist/server/src/room/room-factory.js +16 -0
- package/dist/server/src/room/room-message.module.d.ts +2 -0
- package/dist/server/src/room/room-message.module.js +21 -0
- package/dist/server/src/room/room-message.service.d.ts +8 -0
- package/dist/server/src/room/room-message.service.js +44 -0
- package/dist/server/src/room/room-store.module.d.ts +2 -0
- package/dist/server/src/room/room-store.module.js +25 -0
- package/dist/server/src/room/room-store.service.d.ts +38 -0
- package/dist/server/src/room/room-store.service.js +353 -0
- package/dist/server/src/room/room.d.ts +107 -0
- package/dist/server/src/room/room.js +833 -0
- package/dist/server/src/sdk/briyah-config.d.ts +13 -0
- package/dist/server/src/sdk/briyah-config.js +32 -0
- package/dist/server/src/sdk/briyah.d.ts +36 -0
- package/dist/server/src/sdk/briyah.js +122 -0
- package/dist/server/src/sdk/index.d.ts +6 -0
- package/dist/server/src/sdk/index.js +11 -0
- package/dist/server/src/shared/shared.module.d.ts +2 -0
- package/dist/server/src/shared/shared.module.js +46 -0
- package/dist/server/src/story/story-message.service.d.ts +10 -0
- package/dist/server/src/story/story-message.service.js +57 -0
- package/dist/server/src/story/story-progress.service.d.ts +8 -0
- package/dist/server/src/story/story-progress.service.js +44 -0
- package/dist/server/src/story/story-store.module.d.ts +2 -0
- package/dist/server/src/story/story-store.module.js +22 -0
- package/dist/server/src/story/story-store.service.d.ts +23 -0
- package/dist/server/src/story/story-store.service.js +392 -0
- package/dist/server/src/story/story.service.d.ts +94 -0
- package/dist/server/src/story/story.service.js +1797 -0
- package/dist/shared/shared.module.d.ts +2 -0
- package/dist/shared/shared.module.js +46 -0
- package/dist/shared/types/app.types.d.ts +296 -0
- package/dist/shared/types/app.types.js +17 -0
- package/dist/story/story-message.service.d.ts +10 -0
- package/dist/story/story-message.service.js +57 -0
- package/dist/story/story-progress.service.d.ts +8 -0
- package/dist/story/story-progress.service.js +44 -0
- package/dist/story/story-store.module.d.ts +2 -0
- package/dist/story/story-store.module.js +22 -0
- package/dist/story/story-store.service.d.ts +23 -0
- package/dist/story/story-store.service.js +392 -0
- package/dist/story/story.service.d.ts +94 -0
- package/dist/story/story.service.js +1797 -0
- package/eslint.config.js +29 -0
- package/package.json +125 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.AgentStoreService = void 0;
|
|
46
|
+
const common_1 = require("@nestjs/common");
|
|
47
|
+
const agent_1 = require("./agent");
|
|
48
|
+
const crypto_1 = require("crypto");
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const ai_factory_service_1 = require("./ai-factory.service");
|
|
52
|
+
const artifact_service_1 = require("./artifact.service");
|
|
53
|
+
const configuration_service_1 = require("../config/configuration.service");
|
|
54
|
+
const attached_file_service_1 = require("./attached-file.service");
|
|
55
|
+
const balance_service_1 = require("../app/balance.service");
|
|
56
|
+
let AgentStoreService = class AgentStoreService {
|
|
57
|
+
aiFactoryService;
|
|
58
|
+
configService;
|
|
59
|
+
attachedFileService;
|
|
60
|
+
balanceService;
|
|
61
|
+
artifactService;
|
|
62
|
+
agents = new Map();
|
|
63
|
+
defaultStorageDir;
|
|
64
|
+
loaded = false;
|
|
65
|
+
loadPromise = null;
|
|
66
|
+
constructor(aiFactoryService, configService, attachedFileService, balanceService, artifactService) {
|
|
67
|
+
this.aiFactoryService = aiFactoryService;
|
|
68
|
+
this.configService = configService;
|
|
69
|
+
this.attachedFileService = attachedFileService;
|
|
70
|
+
this.balanceService = balanceService;
|
|
71
|
+
this.artifactService = artifactService;
|
|
72
|
+
this.defaultStorageDir = path.join(this.configService.getUserDataDir(), 'agents');
|
|
73
|
+
}
|
|
74
|
+
getDefaultStorageDir() {
|
|
75
|
+
return this.defaultStorageDir;
|
|
76
|
+
}
|
|
77
|
+
storeAgent(agent, storageDir) {
|
|
78
|
+
if (!agent.id) {
|
|
79
|
+
agent.id = (0, crypto_1.randomUUID)();
|
|
80
|
+
}
|
|
81
|
+
this.agents.set(agent.id, agent);
|
|
82
|
+
const finalStorageDir = storageDir || agent.storageDir;
|
|
83
|
+
this.saveAgentToFile(agent, finalStorageDir);
|
|
84
|
+
return agent.id;
|
|
85
|
+
}
|
|
86
|
+
async getAgent(id) {
|
|
87
|
+
await this.ensureLoaded();
|
|
88
|
+
return this.agents.get(id);
|
|
89
|
+
}
|
|
90
|
+
removeAgent(id) {
|
|
91
|
+
const agent = this.agents.get(id);
|
|
92
|
+
if (!agent) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (agent.aiService) {
|
|
96
|
+
try {
|
|
97
|
+
agent.aiService.finishAgent(agent);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
console.error(`Error finishing agent ${id}:`, error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.attachedFileService.deleteAllFiles(agent.id);
|
|
104
|
+
const result = this.agents.delete(id);
|
|
105
|
+
if (result) {
|
|
106
|
+
this.deleteAgentFile(id, agent.storageDir);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
async getAllAgentIds() {
|
|
111
|
+
await this.ensureLoaded();
|
|
112
|
+
return Array.from(this.agents.keys());
|
|
113
|
+
}
|
|
114
|
+
async getAgentCount() {
|
|
115
|
+
await this.ensureLoaded();
|
|
116
|
+
return this.agents.size;
|
|
117
|
+
}
|
|
118
|
+
async cloneAgentAsPublished(templateId, publishedName, _userId) {
|
|
119
|
+
await this.ensureLoaded();
|
|
120
|
+
const template = this.agents.get(templateId);
|
|
121
|
+
if (!template) {
|
|
122
|
+
throw new Error(`Template agent not found: ${templateId}`);
|
|
123
|
+
}
|
|
124
|
+
const instanceId = (0, crypto_1.randomUUID)();
|
|
125
|
+
const aiService = this.aiFactoryService.createAiService(template.serviceName);
|
|
126
|
+
const instance = new agent_1.Agent(instanceId, this.configService, this, this.balanceService, this.artifactService, publishedName, template.agentNickname || template.agentName, template.description, template.promptFolder, template.systemInstruction, [], template.modelName, template.serviceName, aiService, template.reasoningEffort, template.allowSearch, template.maxOutputTokens, template.beginInstruction, this.defaultStorageDir);
|
|
127
|
+
instance.templateAgentId = templateId;
|
|
128
|
+
instance.isPublished = true;
|
|
129
|
+
instance.createdAt = new Date();
|
|
130
|
+
instance.totalInputTokens = 0;
|
|
131
|
+
instance.totalOutputTokens = 0;
|
|
132
|
+
instance.totalCost = 0;
|
|
133
|
+
instance.totalMarkup = 0;
|
|
134
|
+
instance.attachedFiles = [...template.attachedFiles];
|
|
135
|
+
instance.attachedArtifacts = [...template.attachedArtifacts];
|
|
136
|
+
instance.maxHistoryMessages = template.maxHistoryMessages;
|
|
137
|
+
instance.promptCacheTTL = template.promptCacheTTL;
|
|
138
|
+
instance.markupRate = template.markupRate;
|
|
139
|
+
this.storeAgent(instance);
|
|
140
|
+
return instanceId;
|
|
141
|
+
}
|
|
142
|
+
async getPublishedInstances(templateId) {
|
|
143
|
+
await this.ensureLoaded();
|
|
144
|
+
const instances = [];
|
|
145
|
+
for (const agent of this.agents.values()) {
|
|
146
|
+
if (agent.templateAgentId === templateId) {
|
|
147
|
+
instances.push(agent);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return instances;
|
|
151
|
+
}
|
|
152
|
+
async resetPublishedInstance(instanceId, templateId) {
|
|
153
|
+
await this.ensureLoaded();
|
|
154
|
+
const instance = this.agents.get(instanceId);
|
|
155
|
+
if (!instance) {
|
|
156
|
+
throw new Error(`Instance agent not found: ${instanceId}`);
|
|
157
|
+
}
|
|
158
|
+
const template = this.agents.get(templateId);
|
|
159
|
+
if (!template) {
|
|
160
|
+
throw new Error(`Template agent not found: ${templateId}`);
|
|
161
|
+
}
|
|
162
|
+
if (instance.templateAgentId !== templateId) {
|
|
163
|
+
throw new Error(`Instance ${instanceId} does not belong to template ${templateId}`);
|
|
164
|
+
}
|
|
165
|
+
instance.description = template.description;
|
|
166
|
+
instance.agentNickname = template.agentNickname;
|
|
167
|
+
instance.promptFolder = template.promptFolder;
|
|
168
|
+
instance.systemInstruction = template.systemInstruction;
|
|
169
|
+
instance.modelName = template.modelName;
|
|
170
|
+
instance.serviceName = template.serviceName;
|
|
171
|
+
instance.reasoningEffort = template.reasoningEffort;
|
|
172
|
+
instance.allowSearch = template.allowSearch;
|
|
173
|
+
instance.maxOutputTokens = template.maxOutputTokens;
|
|
174
|
+
instance.attachedFiles = [...template.attachedFiles];
|
|
175
|
+
instance.attachedArtifacts = [...template.attachedArtifacts];
|
|
176
|
+
instance.beginInstruction = template.beginInstruction;
|
|
177
|
+
instance.maxHistoryMessages = template.maxHistoryMessages;
|
|
178
|
+
instance.promptCacheTTL = template.promptCacheTTL;
|
|
179
|
+
instance.markupRate = template.markupRate;
|
|
180
|
+
instance.history = [];
|
|
181
|
+
instance.totalInputTokens = 0;
|
|
182
|
+
instance.totalOutputTokens = 0;
|
|
183
|
+
instance.totalCost = 0;
|
|
184
|
+
instance.totalMarkup = 0;
|
|
185
|
+
instance.aiService = this.aiFactoryService.createAiService(instance.serviceName);
|
|
186
|
+
this.storeAgent(instance);
|
|
187
|
+
}
|
|
188
|
+
async ensureLoaded() {
|
|
189
|
+
if (this.loaded)
|
|
190
|
+
return;
|
|
191
|
+
if (!this.loadPromise) {
|
|
192
|
+
this.loadPromise = this.loadAgentsFromDirectory(this.defaultStorageDir)
|
|
193
|
+
.then(() => {
|
|
194
|
+
this.loaded = true;
|
|
195
|
+
})
|
|
196
|
+
.catch((error) => {
|
|
197
|
+
this.loadPromise = null;
|
|
198
|
+
throw error;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
await this.loadPromise;
|
|
202
|
+
}
|
|
203
|
+
async loadAgentsFromDirectory(storageDir, artifactService) {
|
|
204
|
+
try {
|
|
205
|
+
try {
|
|
206
|
+
await fs.promises.access(storageDir);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
console.log(`Agent storage directory not found: ${storageDir}`);
|
|
210
|
+
await fs.promises.mkdir(storageDir, { recursive: true });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const allFiles = await fs.promises.readdir(storageDir);
|
|
214
|
+
const files = allFiles.filter((file) => file.endsWith('.json'));
|
|
215
|
+
console.log(`Loading ${files.length} agents from ${storageDir}`);
|
|
216
|
+
for (const file of files) {
|
|
217
|
+
try {
|
|
218
|
+
const filePath = path.join(storageDir, file);
|
|
219
|
+
const fileContent = await fs.promises.readFile(filePath, 'utf-8');
|
|
220
|
+
const config = JSON.parse(fileContent);
|
|
221
|
+
if (this.agents.has(config.id)) {
|
|
222
|
+
console.log(`Agent ${config.agentName} (${config.id}) already loaded, skipping`);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const aiService = this.aiFactoryService.createAiService(config.serviceName);
|
|
226
|
+
const finalArtifactService = artifactService || this.artifactService;
|
|
227
|
+
const agent = new agent_1.Agent(config.id, this.configService, this, this.balanceService, finalArtifactService, config.agentName, config.agentNickname || config.agentName, config.description, config.promptFolder, config.systemInstruction, config.history || [], config.modelName, config.serviceName, aiService, config.reasoningEffort, config.allowSearch, config.maxOutputTokens, config.beginInstruction || '', storageDir);
|
|
228
|
+
agent.createdAt = new Date(config.createdAt);
|
|
229
|
+
agent.configService = this.configService;
|
|
230
|
+
agent.totalInputTokens = config.totalInputTokens || 0;
|
|
231
|
+
agent.totalOutputTokens = config.totalOutputTokens || 0;
|
|
232
|
+
agent.totalCost = config.totalCost || 0;
|
|
233
|
+
agent.totalMarkup = config.totalMarkup || 0;
|
|
234
|
+
agent.markupRate =
|
|
235
|
+
config.markupRate ??
|
|
236
|
+
(process.env.DEFAULT_MARKUP_RATE
|
|
237
|
+
? parseFloat(process.env.DEFAULT_MARKUP_RATE)
|
|
238
|
+
: 2);
|
|
239
|
+
agent.isControlledByHuman = config.isControlledByHuman || false;
|
|
240
|
+
agent.disableMarkup = config.disableMarkup || false;
|
|
241
|
+
agent.disableBalanceCheck = config.disableBalanceCheck || false;
|
|
242
|
+
agent.isPublished = config.isPublished || false;
|
|
243
|
+
agent.templateAgentId = config.templateAgentId;
|
|
244
|
+
agent.ownerRoomId = config.ownerRoomId;
|
|
245
|
+
agent.beginInstruction = config.beginInstruction || '';
|
|
246
|
+
agent.maxHistoryMessages = config.maxHistoryMessages || undefined;
|
|
247
|
+
agent.promptCacheTTL = Number(config.promptCacheTTL) ?? 0;
|
|
248
|
+
agent.id = config.id;
|
|
249
|
+
this.agents.set(config.id, agent);
|
|
250
|
+
if (config.attachedFiles && config.attachedFiles.length > 0) {
|
|
251
|
+
agent.attachedFiles = config.attachedFiles;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const fileMetadataList = this.attachedFileService.listFileMetadata(agent.id);
|
|
255
|
+
agent.attachedFiles = fileMetadataList;
|
|
256
|
+
}
|
|
257
|
+
for (const metadata of agent.attachedFiles) {
|
|
258
|
+
const fileData = this.attachedFileService.getFile(agent.id, metadata.fileId);
|
|
259
|
+
if (fileData && metadata.serviceMetadata && agent.fullContextFiles) {
|
|
260
|
+
metadata.serviceMetadata.fileData = Array.from(fileData);
|
|
261
|
+
console.log(`Restored fileData for ${metadata.fileName} (fullContextFiles=true)`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (config.attachedArtifacts && config.attachedArtifacts.length > 0) {
|
|
265
|
+
agent.attachedArtifacts = config.attachedArtifacts;
|
|
266
|
+
}
|
|
267
|
+
console.log(`Loaded agent: ${config.agentName} (${config.id}) with ${agent.history.length} history items`);
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
console.error(`Error loading agent from file ${file}:`, error);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
console.error(`Error loading agents from directory ${storageDir}:`, error);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
saveAgentToFile(agent, storageDir) {
|
|
279
|
+
try {
|
|
280
|
+
if (!fs.existsSync(storageDir)) {
|
|
281
|
+
fs.mkdirSync(storageDir, { recursive: true });
|
|
282
|
+
}
|
|
283
|
+
let attachedFilesWithoutFileData = agent.attachedFiles.map((file) => {
|
|
284
|
+
if (file.serviceMetadata?.fileData) {
|
|
285
|
+
const { fileData: _fileData, ...serviceMetadataWithoutFileData } = file.serviceMetadata;
|
|
286
|
+
return {
|
|
287
|
+
...file,
|
|
288
|
+
serviceMetadata: serviceMetadataWithoutFileData,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return file;
|
|
292
|
+
});
|
|
293
|
+
const config = {
|
|
294
|
+
id: agent.id,
|
|
295
|
+
agentName: agent.agentName,
|
|
296
|
+
agentNickname: agent.agentNickname,
|
|
297
|
+
description: agent.description,
|
|
298
|
+
promptFolder: agent.promptFolder,
|
|
299
|
+
systemInstruction: agent.systemInstruction,
|
|
300
|
+
modelName: agent.modelName,
|
|
301
|
+
serviceName: agent.serviceName,
|
|
302
|
+
reasoningEffort: agent.reasoningEffort,
|
|
303
|
+
allowSearch: agent.allowSearch,
|
|
304
|
+
maxOutputTokens: agent.maxOutputTokens,
|
|
305
|
+
createdAt: agent.createdAt.toISOString(),
|
|
306
|
+
attachedFiles: attachedFilesWithoutFileData,
|
|
307
|
+
attachedArtifacts: agent.attachedArtifacts,
|
|
308
|
+
history: agent.history,
|
|
309
|
+
maxHistoryMessages: agent.maxHistoryMessages,
|
|
310
|
+
totalInputTokens: agent.totalInputTokens,
|
|
311
|
+
totalOutputTokens: agent.totalOutputTokens,
|
|
312
|
+
totalCost: agent.totalCost,
|
|
313
|
+
totalMarkup: agent.totalMarkup,
|
|
314
|
+
markupRate: agent.markupRate,
|
|
315
|
+
disableMarkup: agent.disableMarkup,
|
|
316
|
+
disableBalanceCheck: agent.disableBalanceCheck,
|
|
317
|
+
isControlledByHuman: agent.isControlledByHuman,
|
|
318
|
+
isPublished: agent.isPublished,
|
|
319
|
+
templateAgentId: agent.templateAgentId,
|
|
320
|
+
beginInstruction: agent.beginInstruction,
|
|
321
|
+
promptCacheTTL: agent.promptCacheTTL,
|
|
322
|
+
ownerRoomId: agent.ownerRoomId,
|
|
323
|
+
};
|
|
324
|
+
const filePath = path.join(storageDir, `${agent.id}.json`);
|
|
325
|
+
fs.writeFileSync(filePath, JSON.stringify(config, null, 2), 'utf-8');
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.error(`Error saving agent ${agent.id} to file:`, error);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
deleteAgentFile(agentId, storageDir) {
|
|
332
|
+
try {
|
|
333
|
+
const filePath = path.join(storageDir, `${agentId}.json`);
|
|
334
|
+
if (fs.existsSync(filePath)) {
|
|
335
|
+
fs.unlinkSync(filePath);
|
|
336
|
+
console.log(`Deleted agent file: ${filePath}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
console.error(`Error deleting agent file ${agentId}:`, error);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
exports.AgentStoreService = AgentStoreService;
|
|
345
|
+
exports.AgentStoreService = AgentStoreService = __decorate([
|
|
346
|
+
(0, common_1.Injectable)(),
|
|
347
|
+
__metadata("design:paramtypes", [ai_factory_service_1.AiFactoryService,
|
|
348
|
+
configuration_service_1.ConfigurationService,
|
|
349
|
+
attached_file_service_1.AttachedFileService,
|
|
350
|
+
balance_service_1.BalanceService,
|
|
351
|
+
artifact_service_1.ArtifactService])
|
|
352
|
+
], AgentStoreService);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { OpenAI } from 'openai';
|
|
2
|
+
import { Assistant } from 'openai/resources/beta/assistants';
|
|
3
|
+
import { VectorStore } from 'openai/resources/vector-stores';
|
|
4
|
+
import { Message } from '@shared/types/app.types';
|
|
5
|
+
import { BaseAiService } from './LLM/base-ai.service';
|
|
6
|
+
import { FileMetadata } from './attached-file.service';
|
|
7
|
+
import { ArtifactService } from './artifact.service';
|
|
8
|
+
import { ConfigurationService } from '../config/configuration.service';
|
|
9
|
+
import { BalanceService } from '../app/balance.service';
|
|
10
|
+
import { AgentStoreService } from './agent-store.service';
|
|
11
|
+
export declare class Agent {
|
|
12
|
+
id?: string;
|
|
13
|
+
agentName: string;
|
|
14
|
+
agentNickname: string;
|
|
15
|
+
history: any[];
|
|
16
|
+
fullContextFiles: boolean;
|
|
17
|
+
static generateNickname(agentName: string): string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
totalInputTokens: number;
|
|
20
|
+
totalOutputTokens: number;
|
|
21
|
+
totalCost: number;
|
|
22
|
+
totalMarkup: number;
|
|
23
|
+
markupRate: number;
|
|
24
|
+
disableMarkup: boolean;
|
|
25
|
+
disableBalanceCheck: boolean;
|
|
26
|
+
isPublished: boolean;
|
|
27
|
+
templateAgentId?: string;
|
|
28
|
+
ownerRoomId?: string;
|
|
29
|
+
openai?: OpenAI;
|
|
30
|
+
assistant?: Assistant;
|
|
31
|
+
vectorStore?: VectorStore;
|
|
32
|
+
aiService: BaseAiService;
|
|
33
|
+
artifactService: ArtifactService;
|
|
34
|
+
configService: ConfigurationService;
|
|
35
|
+
balanceService?: BalanceService;
|
|
36
|
+
description: string;
|
|
37
|
+
promptFolder: string;
|
|
38
|
+
systemInstruction: string;
|
|
39
|
+
maxHistoryMessages?: number;
|
|
40
|
+
modelName: string;
|
|
41
|
+
serviceName: string;
|
|
42
|
+
reasoningEffort: 'low' | 'medium' | 'high' | null;
|
|
43
|
+
allowSearch: boolean;
|
|
44
|
+
maxOutputTokens: number;
|
|
45
|
+
attachedFiles: FileMetadata[];
|
|
46
|
+
attachedArtifacts: string[];
|
|
47
|
+
isControlledByHuman: boolean;
|
|
48
|
+
beginInstruction: string;
|
|
49
|
+
promptCacheTTL: number;
|
|
50
|
+
private onStateChange;
|
|
51
|
+
storageDir: string;
|
|
52
|
+
private agentStoreService;
|
|
53
|
+
constructor(id: string | null, configService: ConfigurationService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, systemInstruction: string, history: any[], modelName: string, serviceName: string, aiService: BaseAiService, reasoningEffort: 'low' | 'medium' | 'high' | null, allowSearch: boolean, maxOutputTokens: number, beginInstruction: string, storageDir: string);
|
|
54
|
+
attachDocument(fileName: string, fileData: Uint8Array): Promise<string>;
|
|
55
|
+
attachArtifact(artifactId: string): void;
|
|
56
|
+
detachArtifact(artifactId: string): void;
|
|
57
|
+
getAttachedArtifacts(): string[];
|
|
58
|
+
save(): void;
|
|
59
|
+
finishAgent(): Promise<void>;
|
|
60
|
+
deleteAgent(): Promise<void>;
|
|
61
|
+
setOnStateChange(callback: () => void): void;
|
|
62
|
+
notifyStateChange(): void;
|
|
63
|
+
canRespond(message: Message): boolean;
|
|
64
|
+
getFormattedMessages(fromIndex?: number): string[];
|
|
65
|
+
getRawMessages(): string[];
|
|
66
|
+
addToConversationHistory(message: any, fromSelf?: boolean): void;
|
|
67
|
+
trimHistoryIfNeeded(threshold?: number): void;
|
|
68
|
+
instructedPrompt(prompt: string, instructionFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
|
|
69
|
+
preparedPrompt(promptFileName: string, variables: any, saveResponse?: boolean, cacheMessage?: boolean): Promise<any>;
|
|
70
|
+
textPrompt(prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheMessage?: boolean, maxOutputChars?: number): Promise<any>;
|
|
71
|
+
generateImage(prompt: string, width: number, height: number, quality: string, referenceImageArtifactIds?: string[]): Promise<{
|
|
72
|
+
artifactId?: string;
|
|
73
|
+
error?: any;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
package/dist/ai/agent.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Agent = void 0;
|
|
4
|
+
const app_types_1 = require("@shared/types/app.types");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
class Agent {
|
|
7
|
+
id;
|
|
8
|
+
agentName;
|
|
9
|
+
agentNickname;
|
|
10
|
+
history;
|
|
11
|
+
fullContextFiles = true;
|
|
12
|
+
static generateNickname(agentName) {
|
|
13
|
+
const firstName = agentName.trim().split(/\s+/)[0];
|
|
14
|
+
return firstName || agentName;
|
|
15
|
+
}
|
|
16
|
+
createdAt;
|
|
17
|
+
totalInputTokens = 0;
|
|
18
|
+
totalOutputTokens = 0;
|
|
19
|
+
totalCost = 0;
|
|
20
|
+
totalMarkup = 0;
|
|
21
|
+
markupRate = 2;
|
|
22
|
+
disableMarkup = false;
|
|
23
|
+
disableBalanceCheck = false;
|
|
24
|
+
isPublished = false;
|
|
25
|
+
templateAgentId;
|
|
26
|
+
ownerRoomId;
|
|
27
|
+
openai;
|
|
28
|
+
assistant;
|
|
29
|
+
vectorStore;
|
|
30
|
+
aiService;
|
|
31
|
+
artifactService;
|
|
32
|
+
configService;
|
|
33
|
+
balanceService;
|
|
34
|
+
description;
|
|
35
|
+
promptFolder;
|
|
36
|
+
systemInstruction;
|
|
37
|
+
maxHistoryMessages;
|
|
38
|
+
modelName;
|
|
39
|
+
serviceName;
|
|
40
|
+
reasoningEffort;
|
|
41
|
+
allowSearch;
|
|
42
|
+
maxOutputTokens = 0;
|
|
43
|
+
attachedFiles = [];
|
|
44
|
+
attachedArtifacts = [];
|
|
45
|
+
isControlledByHuman = false;
|
|
46
|
+
beginInstruction = '';
|
|
47
|
+
promptCacheTTL = 0;
|
|
48
|
+
onStateChange = null;
|
|
49
|
+
storageDir;
|
|
50
|
+
agentStoreService;
|
|
51
|
+
constructor(id, configService, agentStoreService, balanceService, artifactService, agentName = '', agentNickname = '', description = '', promptFolder = '', systemInstruction = '', history = [], modelName = '', serviceName = '', aiService, reasoningEffort = null, allowSearch = false, maxOutputTokens = 0, beginInstruction = '', storageDir) {
|
|
52
|
+
this.agentName = agentName;
|
|
53
|
+
this.agentNickname = agentNickname || Agent.generateNickname(agentName);
|
|
54
|
+
this.description = description;
|
|
55
|
+
this.promptFolder = promptFolder;
|
|
56
|
+
this.systemInstruction = systemInstruction;
|
|
57
|
+
this.history = history;
|
|
58
|
+
this.openai = null;
|
|
59
|
+
this.assistant = null;
|
|
60
|
+
this.vectorStore = null;
|
|
61
|
+
this.fullContextFiles = true;
|
|
62
|
+
this.createdAt = new Date();
|
|
63
|
+
this.modelName = modelName;
|
|
64
|
+
this.serviceName = serviceName;
|
|
65
|
+
this.aiService = aiService;
|
|
66
|
+
this.reasoningEffort = reasoningEffort;
|
|
67
|
+
this.allowSearch = allowSearch;
|
|
68
|
+
this.maxOutputTokens = maxOutputTokens;
|
|
69
|
+
this.beginInstruction = beginInstruction;
|
|
70
|
+
this.storageDir = storageDir;
|
|
71
|
+
this.configService = configService;
|
|
72
|
+
this.agentStoreService = agentStoreService;
|
|
73
|
+
this.balanceService = balanceService;
|
|
74
|
+
this.artifactService = artifactService;
|
|
75
|
+
this.id = id ? id : (0, crypto_1.randomUUID)();
|
|
76
|
+
}
|
|
77
|
+
async attachDocument(fileName, fileData) {
|
|
78
|
+
return await this.aiService.attachDocument(this, fileName, fileData);
|
|
79
|
+
}
|
|
80
|
+
attachArtifact(artifactId) {
|
|
81
|
+
if (!this.attachedArtifacts.includes(artifactId)) {
|
|
82
|
+
this.attachedArtifacts.push(artifactId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
detachArtifact(artifactId) {
|
|
86
|
+
this.attachedArtifacts = this.attachedArtifacts.filter((id) => id !== artifactId);
|
|
87
|
+
}
|
|
88
|
+
getAttachedArtifacts() {
|
|
89
|
+
return [...this.attachedArtifacts];
|
|
90
|
+
}
|
|
91
|
+
save() {
|
|
92
|
+
this.agentStoreService.storeAgent(this);
|
|
93
|
+
this.notifyStateChange();
|
|
94
|
+
}
|
|
95
|
+
async finishAgent() {
|
|
96
|
+
this.agentStoreService.removeAgent(this);
|
|
97
|
+
}
|
|
98
|
+
async deleteAgent() {
|
|
99
|
+
this.agentStoreService.removeAgent(this.id);
|
|
100
|
+
}
|
|
101
|
+
setOnStateChange(callback) {
|
|
102
|
+
this.onStateChange = callback;
|
|
103
|
+
}
|
|
104
|
+
notifyStateChange() {
|
|
105
|
+
if (this.onStateChange) {
|
|
106
|
+
this.onStateChange();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
canRespond(message) {
|
|
110
|
+
if (!this.isControlledByHuman)
|
|
111
|
+
return true;
|
|
112
|
+
return message.targets.includes(this.agentNickname);
|
|
113
|
+
}
|
|
114
|
+
getFormattedMessages(fromIndex = 0) {
|
|
115
|
+
if (!this.history) {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
return this.history
|
|
119
|
+
.slice(fromIndex)
|
|
120
|
+
.map((message) => this.aiService.formatMessage(message));
|
|
121
|
+
}
|
|
122
|
+
getRawMessages() {
|
|
123
|
+
if (!this.history) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
return this.history.map((message) => message.content);
|
|
127
|
+
}
|
|
128
|
+
addToConversationHistory(message, fromSelf = false) {
|
|
129
|
+
let formattedMessage = message;
|
|
130
|
+
if (typeof message === 'object') {
|
|
131
|
+
if (message.action && message.action == app_types_1.MessageAction.MODERATE) {
|
|
132
|
+
formattedMessage = `From: ${message.sender}\n${message.content}`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
formattedMessage = JSON.stringify(message, null, 2);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.aiService.addToConversationHistory(this, formattedMessage, fromSelf);
|
|
139
|
+
}
|
|
140
|
+
trimHistoryIfNeeded(threshold = 0) {
|
|
141
|
+
if (!this.maxHistoryMessages)
|
|
142
|
+
return;
|
|
143
|
+
let systemMessageCount = 0;
|
|
144
|
+
for (let i = 0; i < this.history.length; i++) {
|
|
145
|
+
if (this.history[i].role === 'developer') {
|
|
146
|
+
systemMessageCount++;
|
|
147
|
+
}
|
|
148
|
+
else if (this.history[i].content.includes('[CONVERSATION HISTORY SUMMARY]')) {
|
|
149
|
+
systemMessageCount++;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const conversationMessages = this.history.slice(systemMessageCount);
|
|
156
|
+
if (conversationMessages.length > this.maxHistoryMessages + threshold) {
|
|
157
|
+
const keepMessages = conversationMessages.slice(-this.maxHistoryMessages);
|
|
158
|
+
this.history = [...this.history.slice(0, systemMessageCount), ...keepMessages];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async instructedPrompt(prompt, instructionFileName, variables, saveResponse = true, cacheMessage = false, maxOutputChars = 0) {
|
|
162
|
+
return await this.aiService.instructedPrompt(this, prompt, instructionFileName, variables, saveResponse, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
|
|
163
|
+
}
|
|
164
|
+
async preparedPrompt(promptFileName, variables, saveResponse = true, cacheMessage = false) {
|
|
165
|
+
return await this.aiService.preparedPrompt(this, promptFileName, variables, saveResponse, this.aiService.getCacheConfig(this, cacheMessage));
|
|
166
|
+
}
|
|
167
|
+
async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
|
|
168
|
+
return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
|
|
169
|
+
}
|
|
170
|
+
async generateImage(prompt, width, height, quality, referenceImageArtifactIds) {
|
|
171
|
+
return await this.aiService.generateImage(this, prompt, width, height, quality, referenceImageArtifactIds);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.Agent = Agent;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AiFactoryModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const ai_factory_service_1 = require("./ai-factory.service");
|
|
12
|
+
const openai_module_1 = require("./LLM/openai.module");
|
|
13
|
+
const grok_module_1 = require("./LLM/grok.module");
|
|
14
|
+
const vertexai_module_1 = require("./LLM/vertexai.module");
|
|
15
|
+
const anthropic_module_1 = require("./LLM/anthropic.module");
|
|
16
|
+
const deepseek_module_1 = require("./LLM/deepseek.module");
|
|
17
|
+
const together_module_1 = require("./LLM/together.module");
|
|
18
|
+
const mock_module_1 = require("./LLM/mock.module");
|
|
19
|
+
const googleai_module_1 = require("./LLM/googleai.module");
|
|
20
|
+
const fal_module_1 = require("./LLM/fal.module");
|
|
21
|
+
let AiFactoryModule = class AiFactoryModule {
|
|
22
|
+
};
|
|
23
|
+
exports.AiFactoryModule = AiFactoryModule;
|
|
24
|
+
exports.AiFactoryModule = AiFactoryModule = __decorate([
|
|
25
|
+
(0, common_1.Module)({
|
|
26
|
+
imports: [
|
|
27
|
+
openai_module_1.OpenAiModule,
|
|
28
|
+
grok_module_1.GrokAiModule,
|
|
29
|
+
vertexai_module_1.VertexAiModule,
|
|
30
|
+
anthropic_module_1.AnthropicAiModule,
|
|
31
|
+
deepseek_module_1.DeepSeekAiModule,
|
|
32
|
+
together_module_1.TogetherAiModule,
|
|
33
|
+
mock_module_1.MockAiModule,
|
|
34
|
+
googleai_module_1.GoogleAiModule,
|
|
35
|
+
fal_module_1.FalAiModule,
|
|
36
|
+
],
|
|
37
|
+
providers: [ai_factory_service_1.AiFactoryService],
|
|
38
|
+
exports: [ai_factory_service_1.AiFactoryService],
|
|
39
|
+
})
|
|
40
|
+
], AiFactoryModule);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseAiService } from './LLM/base-ai.service';
|
|
2
|
+
import { OpenAiService } from './LLM/openai.service';
|
|
3
|
+
import { GrokAiService } from './LLM/grok.service';
|
|
4
|
+
import { VertexAiService } from './LLM/vertexai.service';
|
|
5
|
+
import { AnthropicAiService } from './LLM/anthropic.service';
|
|
6
|
+
import { DeepSeekAiService } from './LLM/deepseek.service';
|
|
7
|
+
import { TogetherAiService } from './LLM/together.service';
|
|
8
|
+
import { MockAiService } from './LLM/mock.service';
|
|
9
|
+
import { GoogleAiService } from './LLM/googleai.service';
|
|
10
|
+
import { FalAiService } from './LLM/fal.service';
|
|
11
|
+
export declare class AiFactoryService {
|
|
12
|
+
private readonly openAiService;
|
|
13
|
+
private readonly grokAiService;
|
|
14
|
+
private readonly vertexAiService;
|
|
15
|
+
private readonly anthropicAiService;
|
|
16
|
+
private readonly deepSeekAiService;
|
|
17
|
+
private readonly togetherAiService;
|
|
18
|
+
private readonly mockAiService;
|
|
19
|
+
private readonly googleAiService;
|
|
20
|
+
private readonly falAiService;
|
|
21
|
+
constructor(openAiService: OpenAiService, grokAiService: GrokAiService, vertexAiService: VertexAiService, anthropicAiService: AnthropicAiService, deepSeekAiService: DeepSeekAiService, togetherAiService: TogetherAiService, mockAiService: MockAiService, googleAiService: GoogleAiService, falAiService: FalAiService);
|
|
22
|
+
createAiService(serviceName: string): BaseAiService;
|
|
23
|
+
getAllAiServices(): BaseAiService[];
|
|
24
|
+
}
|