@reglow/reglow 0.4.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/README.md +267 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/reglow/common/errors.d.ts +92 -0
- package/dist/reglow/common/errors.js +127 -0
- package/dist/reglow/common/errors.js.map +1 -0
- package/dist/reglow/common/exception_handler.d.ts +14 -0
- package/dist/reglow/common/exception_handler.js +135 -0
- package/dist/reglow/common/exception_handler.js.map +1 -0
- package/dist/reglow/common/i18n.d.ts +15 -0
- package/dist/reglow/common/i18n.js +61 -0
- package/dist/reglow/common/i18n.js.map +1 -0
- package/dist/reglow/common/middleware.d.ts +5 -0
- package/dist/reglow/common/middleware.js +131 -0
- package/dist/reglow/common/middleware.js.map +1 -0
- package/dist/reglow/common/response.d.ts +28 -0
- package/dist/reglow/common/response.js +42 -0
- package/dist/reglow/common/response.js.map +1 -0
- package/dist/reglow/common/serialize.d.ts +6 -0
- package/dist/reglow/common/serialize.js +39 -0
- package/dist/reglow/common/serialize.js.map +1 -0
- package/dist/reglow/common/utils/date_utils.d.ts +10 -0
- package/dist/reglow/common/utils/date_utils.js +30 -0
- package/dist/reglow/common/utils/date_utils.js.map +1 -0
- package/dist/reglow/common/utils/parse-user-agent.d.ts +11 -0
- package/dist/reglow/common/utils/parse-user-agent.js +80 -0
- package/dist/reglow/common/utils/parse-user-agent.js.map +1 -0
- package/dist/reglow/common/utils/string_utils.d.ts +14 -0
- package/dist/reglow/common/utils/string_utils.js +31 -0
- package/dist/reglow/common/utils/string_utils.js.map +1 -0
- package/dist/reglow/core/auth.d.ts +15 -0
- package/dist/reglow/core/auth.js +184 -0
- package/dist/reglow/core/auth.js.map +1 -0
- package/dist/reglow/core/cache.d.ts +6 -0
- package/dist/reglow/core/cache.js +15 -0
- package/dist/reglow/core/cache.js.map +1 -0
- package/dist/reglow/core/config.d.ts +45 -0
- package/dist/reglow/core/config.js +83 -0
- package/dist/reglow/core/config.js.map +1 -0
- package/dist/reglow/core/data_scope.d.ts +21 -0
- package/dist/reglow/core/data_scope.js +20 -0
- package/dist/reglow/core/data_scope.js.map +1 -0
- package/dist/reglow/core/database.d.ts +4 -0
- package/dist/reglow/core/database.js +43 -0
- package/dist/reglow/core/database.js.map +1 -0
- package/dist/reglow/core/email.d.ts +12 -0
- package/dist/reglow/core/email.js +277 -0
- package/dist/reglow/core/email.js.map +1 -0
- package/dist/reglow/core/entities.d.ts +462 -0
- package/dist/reglow/core/entities.js +6 -0
- package/dist/reglow/core/entities.js.map +1 -0
- package/dist/reglow/core/fastify.d.ts +21 -0
- package/dist/reglow/core/fastify.js +2 -0
- package/dist/reglow/core/fastify.js.map +1 -0
- package/dist/reglow/core/logging.d.ts +8 -0
- package/dist/reglow/core/logging.js +32 -0
- package/dist/reglow/core/logging.js.map +1 -0
- package/dist/reglow/core/models.d.ts +98 -0
- package/dist/reglow/core/models.js +57 -0
- package/dist/reglow/core/models.js.map +1 -0
- package/dist/reglow/core/observability.d.ts +17 -0
- package/dist/reglow/core/observability.js +92 -0
- package/dist/reglow/core/observability.js.map +1 -0
- package/dist/reglow/core/payment.d.ts +107 -0
- package/dist/reglow/core/payment.js +1177 -0
- package/dist/reglow/core/payment.js.map +1 -0
- package/dist/reglow/core/plugin.d.ts +19 -0
- package/dist/reglow/core/plugin.js +85 -0
- package/dist/reglow/core/plugin.js.map +1 -0
- package/dist/reglow/core/rate_limit.d.ts +2 -0
- package/dist/reglow/core/rate_limit.js +28 -0
- package/dist/reglow/core/rate_limit.js.map +1 -0
- package/dist/reglow/core/redis.d.ts +30 -0
- package/dist/reglow/core/redis.js +278 -0
- package/dist/reglow/core/redis.js.map +1 -0
- package/dist/reglow/core/redis_keys.d.ts +22 -0
- package/dist/reglow/core/redis_keys.js +59 -0
- package/dist/reglow/core/redis_keys.js.map +1 -0
- package/dist/reglow/core/security.d.ts +25 -0
- package/dist/reglow/core/security.js +64 -0
- package/dist/reglow/core/security.js.map +1 -0
- package/dist/reglow/core/session.d.ts +17 -0
- package/dist/reglow/core/session.js +194 -0
- package/dist/reglow/core/session.js.map +1 -0
- package/dist/reglow/core/sms.d.ts +19 -0
- package/dist/reglow/core/sms.js +33 -0
- package/dist/reglow/core/sms.js.map +1 -0
- package/dist/reglow/core/storage.d.ts +45 -0
- package/dist/reglow/core/storage.js +249 -0
- package/dist/reglow/core/storage.js.map +1 -0
- package/dist/reglow/modules/agreement/controller.d.ts +7 -0
- package/dist/reglow/modules/agreement/controller.js +242 -0
- package/dist/reglow/modules/agreement/controller.js.map +1 -0
- package/dist/reglow/modules/agreement/repository.d.ts +30 -0
- package/dist/reglow/modules/agreement/repository.js +160 -0
- package/dist/reglow/modules/agreement/repository.js.map +1 -0
- package/dist/reglow/modules/agreement/router.d.ts +13 -0
- package/dist/reglow/modules/agreement/router.js +10 -0
- package/dist/reglow/modules/agreement/router.js.map +1 -0
- package/dist/reglow/modules/agreement/schema.d.ts +30 -0
- package/dist/reglow/modules/agreement/schema.js +27 -0
- package/dist/reglow/modules/agreement/schema.js.map +1 -0
- package/dist/reglow/modules/agreement/service.d.ts +42 -0
- package/dist/reglow/modules/agreement/service.js +349 -0
- package/dist/reglow/modules/agreement/service.js.map +1 -0
- package/dist/reglow/modules/ai/controller.d.ts +25 -0
- package/dist/reglow/modules/ai/controller.js +1143 -0
- package/dist/reglow/modules/ai/controller.js.map +1 -0
- package/dist/reglow/modules/ai/router.d.ts +9 -0
- package/dist/reglow/modules/ai/router.js +7 -0
- package/dist/reglow/modules/ai/router.js.map +1 -0
- package/dist/reglow/modules/ai/schema.d.ts +48 -0
- package/dist/reglow/modules/ai/schema.js +40 -0
- package/dist/reglow/modules/ai/schema.js.map +1 -0
- package/dist/reglow/modules/ai/service.d.ts +8 -0
- package/dist/reglow/modules/ai/service.js +137 -0
- package/dist/reglow/modules/ai/service.js.map +1 -0
- package/dist/reglow/modules/article/controller.d.ts +6 -0
- package/dist/reglow/modules/article/controller.js +204 -0
- package/dist/reglow/modules/article/controller.js.map +1 -0
- package/dist/reglow/modules/article/repository.d.ts +37 -0
- package/dist/reglow/modules/article/repository.js +184 -0
- package/dist/reglow/modules/article/repository.js.map +1 -0
- package/dist/reglow/modules/article/router.d.ts +10 -0
- package/dist/reglow/modules/article/router.js +8 -0
- package/dist/reglow/modules/article/router.js.map +1 -0
- package/dist/reglow/modules/article/schema.d.ts +66 -0
- package/dist/reglow/modules/article/schema.js +66 -0
- package/dist/reglow/modules/article/schema.js.map +1 -0
- package/dist/reglow/modules/article/service.d.ts +81 -0
- package/dist/reglow/modules/article/service.js +254 -0
- package/dist/reglow/modules/article/service.js.map +1 -0
- package/dist/reglow/modules/auth/controller.d.ts +6 -0
- package/dist/reglow/modules/auth/controller.js +127 -0
- package/dist/reglow/modules/auth/controller.js.map +1 -0
- package/dist/reglow/modules/auth/router.d.ts +9 -0
- package/dist/reglow/modules/auth/router.js +7 -0
- package/dist/reglow/modules/auth/router.js.map +1 -0
- package/dist/reglow/modules/auth/schema.d.ts +59 -0
- package/dist/reglow/modules/auth/schema.js +56 -0
- package/dist/reglow/modules/auth/schema.js.map +1 -0
- package/dist/reglow/modules/auth/service.d.ts +69 -0
- package/dist/reglow/modules/auth/service.js +492 -0
- package/dist/reglow/modules/auth/service.js.map +1 -0
- package/dist/reglow/modules/config/controller.d.ts +7 -0
- package/dist/reglow/modules/config/controller.js +297 -0
- package/dist/reglow/modules/config/controller.js.map +1 -0
- package/dist/reglow/modules/config/repository.d.ts +17 -0
- package/dist/reglow/modules/config/repository.js +88 -0
- package/dist/reglow/modules/config/repository.js.map +1 -0
- package/dist/reglow/modules/config/router.d.ts +13 -0
- package/dist/reglow/modules/config/router.js +8 -0
- package/dist/reglow/modules/config/router.js.map +1 -0
- package/dist/reglow/modules/config/schema.d.ts +37 -0
- package/dist/reglow/modules/config/schema.js +25 -0
- package/dist/reglow/modules/config/schema.js.map +1 -0
- package/dist/reglow/modules/customer_service/controller.d.ts +3 -0
- package/dist/reglow/modules/customer_service/controller.js +443 -0
- package/dist/reglow/modules/customer_service/controller.js.map +1 -0
- package/dist/reglow/modules/customer_service/document_parser.d.ts +5 -0
- package/dist/reglow/modules/customer_service/document_parser.js +84 -0
- package/dist/reglow/modules/customer_service/document_parser.js.map +1 -0
- package/dist/reglow/modules/customer_service/repository.d.ts +72 -0
- package/dist/reglow/modules/customer_service/repository.js +376 -0
- package/dist/reglow/modules/customer_service/repository.js.map +1 -0
- package/dist/reglow/modules/customer_service/router.d.ts +14 -0
- package/dist/reglow/modules/customer_service/router.js +9 -0
- package/dist/reglow/modules/customer_service/router.js.map +1 -0
- package/dist/reglow/modules/customer_service/schema.d.ts +97 -0
- package/dist/reglow/modules/customer_service/schema.js +91 -0
- package/dist/reglow/modules/customer_service/schema.js.map +1 -0
- package/dist/reglow/modules/customer_service/sdk_template.html +666 -0
- package/dist/reglow/modules/customer_service/service.d.ts +92 -0
- package/dist/reglow/modules/customer_service/service.js +1642 -0
- package/dist/reglow/modules/customer_service/service.js.map +1 -0
- package/dist/reglow/modules/customer_service/ws.d.ts +29 -0
- package/dist/reglow/modules/customer_service/ws.js +182 -0
- package/dist/reglow/modules/customer_service/ws.js.map +1 -0
- package/dist/reglow/modules/dept/controller.d.ts +6 -0
- package/dist/reglow/modules/dept/controller.js +122 -0
- package/dist/reglow/modules/dept/controller.js.map +1 -0
- package/dist/reglow/modules/dept/repository.d.ts +24 -0
- package/dist/reglow/modules/dept/repository.js +140 -0
- package/dist/reglow/modules/dept/repository.js.map +1 -0
- package/dist/reglow/modules/dept/router.d.ts +9 -0
- package/dist/reglow/modules/dept/router.js +7 -0
- package/dist/reglow/modules/dept/router.js.map +1 -0
- package/dist/reglow/modules/dept/schema.d.ts +37 -0
- package/dist/reglow/modules/dept/schema.js +33 -0
- package/dist/reglow/modules/dept/schema.js.map +1 -0
- package/dist/reglow/modules/dept/service.d.ts +33 -0
- package/dist/reglow/modules/dept/service.js +88 -0
- package/dist/reglow/modules/dept/service.js.map +1 -0
- package/dist/reglow/modules/dict/controller.d.ts +5 -0
- package/dist/reglow/modules/dict/controller.js +87 -0
- package/dist/reglow/modules/dict/controller.js.map +1 -0
- package/dist/reglow/modules/dict/model.d.ts +7 -0
- package/dist/reglow/modules/dict/model.js +8 -0
- package/dist/reglow/modules/dict/model.js.map +1 -0
- package/dist/reglow/modules/dict/repository.d.ts +16 -0
- package/dist/reglow/modules/dict/repository.js +103 -0
- package/dist/reglow/modules/dict/repository.js.map +1 -0
- package/dist/reglow/modules/dict/router.d.ts +9 -0
- package/dist/reglow/modules/dict/router.js +7 -0
- package/dist/reglow/modules/dict/router.js.map +1 -0
- package/dist/reglow/modules/dict/schema.d.ts +38 -0
- package/dist/reglow/modules/dict/schema.js +37 -0
- package/dist/reglow/modules/dict/schema.js.map +1 -0
- package/dist/reglow/modules/dict/service.d.ts +15 -0
- package/dist/reglow/modules/dict/service.js +88 -0
- package/dist/reglow/modules/dict/service.js.map +1 -0
- package/dist/reglow/modules/employee/controller.d.ts +6 -0
- package/dist/reglow/modules/employee/controller.js +167 -0
- package/dist/reglow/modules/employee/controller.js.map +1 -0
- package/dist/reglow/modules/employee/repository.d.ts +22 -0
- package/dist/reglow/modules/employee/repository.js +129 -0
- package/dist/reglow/modules/employee/repository.js.map +1 -0
- package/dist/reglow/modules/employee/router.d.ts +9 -0
- package/dist/reglow/modules/employee/router.js +7 -0
- package/dist/reglow/modules/employee/router.js.map +1 -0
- package/dist/reglow/modules/employee/schema.d.ts +57 -0
- package/dist/reglow/modules/employee/schema.js +58 -0
- package/dist/reglow/modules/employee/schema.js.map +1 -0
- package/dist/reglow/modules/employee/service.d.ts +30 -0
- package/dist/reglow/modules/employee/service.js +193 -0
- package/dist/reglow/modules/employee/service.js.map +1 -0
- package/dist/reglow/modules/log/controller.d.ts +6 -0
- package/dist/reglow/modules/log/controller.js +137 -0
- package/dist/reglow/modules/log/controller.js.map +1 -0
- package/dist/reglow/modules/log/data-scope.d.ts +9 -0
- package/dist/reglow/modules/log/data-scope.js +108 -0
- package/dist/reglow/modules/log/data-scope.js.map +1 -0
- package/dist/reglow/modules/log/router.d.ts +9 -0
- package/dist/reglow/modules/log/router.js +7 -0
- package/dist/reglow/modules/log/router.js.map +1 -0
- package/dist/reglow/modules/material/controller.d.ts +3 -0
- package/dist/reglow/modules/material/controller.js +400 -0
- package/dist/reglow/modules/material/controller.js.map +1 -0
- package/dist/reglow/modules/material/repository.d.ts +37 -0
- package/dist/reglow/modules/material/repository.js +183 -0
- package/dist/reglow/modules/material/repository.js.map +1 -0
- package/dist/reglow/modules/material/router.d.ts +14 -0
- package/dist/reglow/modules/material/router.js +11 -0
- package/dist/reglow/modules/material/router.js.map +1 -0
- package/dist/reglow/modules/material/schema.d.ts +40 -0
- package/dist/reglow/modules/material/schema.js +34 -0
- package/dist/reglow/modules/material/schema.js.map +1 -0
- package/dist/reglow/modules/material/service.d.ts +85 -0
- package/dist/reglow/modules/material/service.js +292 -0
- package/dist/reglow/modules/material/service.js.map +1 -0
- package/dist/reglow/modules/menu/controller.d.ts +6 -0
- package/dist/reglow/modules/menu/controller.js +69 -0
- package/dist/reglow/modules/menu/controller.js.map +1 -0
- package/dist/reglow/modules/menu/repository.d.ts +14 -0
- package/dist/reglow/modules/menu/repository.js +37 -0
- package/dist/reglow/modules/menu/repository.js.map +1 -0
- package/dist/reglow/modules/menu/router.d.ts +9 -0
- package/dist/reglow/modules/menu/router.js +7 -0
- package/dist/reglow/modules/menu/router.js.map +1 -0
- package/dist/reglow/modules/menu/schema.d.ts +39 -0
- package/dist/reglow/modules/menu/schema.js +37 -0
- package/dist/reglow/modules/menu/schema.js.map +1 -0
- package/dist/reglow/modules/menu/service.d.ts +31 -0
- package/dist/reglow/modules/menu/service.js +89 -0
- package/dist/reglow/modules/menu/service.js.map +1 -0
- package/dist/reglow/modules/message/controller.d.ts +7 -0
- package/dist/reglow/modules/message/controller.js +260 -0
- package/dist/reglow/modules/message/controller.js.map +1 -0
- package/dist/reglow/modules/message/repository.d.ts +27 -0
- package/dist/reglow/modules/message/repository.js +145 -0
- package/dist/reglow/modules/message/repository.js.map +1 -0
- package/dist/reglow/modules/message/router.d.ts +13 -0
- package/dist/reglow/modules/message/router.js +8 -0
- package/dist/reglow/modules/message/router.js.map +1 -0
- package/dist/reglow/modules/message/schema.d.ts +39 -0
- package/dist/reglow/modules/message/schema.js +37 -0
- package/dist/reglow/modules/message/schema.js.map +1 -0
- package/dist/reglow/modules/message/service.d.ts +70 -0
- package/dist/reglow/modules/message/service.js +199 -0
- package/dist/reglow/modules/message/service.js.map +1 -0
- package/dist/reglow/modules/notice/controller.d.ts +6 -0
- package/dist/reglow/modules/notice/controller.js +123 -0
- package/dist/reglow/modules/notice/controller.js.map +1 -0
- package/dist/reglow/modules/notice/repository.d.ts +25 -0
- package/dist/reglow/modules/notice/repository.js +145 -0
- package/dist/reglow/modules/notice/repository.js.map +1 -0
- package/dist/reglow/modules/notice/router.d.ts +9 -0
- package/dist/reglow/modules/notice/router.js +7 -0
- package/dist/reglow/modules/notice/router.js.map +1 -0
- package/dist/reglow/modules/notice/schema.d.ts +23 -0
- package/dist/reglow/modules/notice/schema.js +22 -0
- package/dist/reglow/modules/notice/schema.js.map +1 -0
- package/dist/reglow/modules/notice/service.d.ts +45 -0
- package/dist/reglow/modules/notice/service.js +149 -0
- package/dist/reglow/modules/notice/service.js.map +1 -0
- package/dist/reglow/modules/payment/controller.d.ts +6 -0
- package/dist/reglow/modules/payment/controller.js +186 -0
- package/dist/reglow/modules/payment/controller.js.map +1 -0
- package/dist/reglow/modules/payment/router.d.ts +10 -0
- package/dist/reglow/modules/payment/router.js +8 -0
- package/dist/reglow/modules/payment/router.js.map +1 -0
- package/dist/reglow/modules/payment/schema.d.ts +52 -0
- package/dist/reglow/modules/payment/schema.js +43 -0
- package/dist/reglow/modules/payment/schema.js.map +1 -0
- package/dist/reglow/modules/payment/service.d.ts +28 -0
- package/dist/reglow/modules/payment/service.js +219 -0
- package/dist/reglow/modules/payment/service.js.map +1 -0
- package/dist/reglow/modules/photo/controller.d.ts +2 -0
- package/dist/reglow/modules/photo/controller.js +323 -0
- package/dist/reglow/modules/photo/controller.js.map +1 -0
- package/dist/reglow/modules/photo/controller_client.d.ts +2 -0
- package/dist/reglow/modules/photo/controller_client.js +293 -0
- package/dist/reglow/modules/photo/controller_client.js.map +1 -0
- package/dist/reglow/modules/photo/repository.d.ts +50 -0
- package/dist/reglow/modules/photo/repository.js +240 -0
- package/dist/reglow/modules/photo/repository.js.map +1 -0
- package/dist/reglow/modules/photo/router.d.ts +15 -0
- package/dist/reglow/modules/photo/router.js +10 -0
- package/dist/reglow/modules/photo/router.js.map +1 -0
- package/dist/reglow/modules/photo/schema.d.ts +69 -0
- package/dist/reglow/modules/photo/schema.js +66 -0
- package/dist/reglow/modules/photo/schema.js.map +1 -0
- package/dist/reglow/modules/photo/service.d.ts +98 -0
- package/dist/reglow/modules/photo/service.js +295 -0
- package/dist/reglow/modules/photo/service.js.map +1 -0
- package/dist/reglow/modules/post/controller.d.ts +6 -0
- package/dist/reglow/modules/post/controller.js +61 -0
- package/dist/reglow/modules/post/controller.js.map +1 -0
- package/dist/reglow/modules/post/repository.d.ts +12 -0
- package/dist/reglow/modules/post/repository.js +46 -0
- package/dist/reglow/modules/post/repository.js.map +1 -0
- package/dist/reglow/modules/post/router.d.ts +9 -0
- package/dist/reglow/modules/post/router.js +7 -0
- package/dist/reglow/modules/post/router.js.map +1 -0
- package/dist/reglow/modules/post/schema.d.ts +19 -0
- package/dist/reglow/modules/post/schema.js +18 -0
- package/dist/reglow/modules/post/schema.js.map +1 -0
- package/dist/reglow/modules/post/service.d.ts +18 -0
- package/dist/reglow/modules/post/service.js +44 -0
- package/dist/reglow/modules/post/service.js.map +1 -0
- package/dist/reglow/modules/role/controller.d.ts +6 -0
- package/dist/reglow/modules/role/controller.js +103 -0
- package/dist/reglow/modules/role/controller.js.map +1 -0
- package/dist/reglow/modules/role/repository.d.ts +22 -0
- package/dist/reglow/modules/role/repository.js +84 -0
- package/dist/reglow/modules/role/repository.js.map +1 -0
- package/dist/reglow/modules/role/router.d.ts +9 -0
- package/dist/reglow/modules/role/router.js +7 -0
- package/dist/reglow/modules/role/router.js.map +1 -0
- package/dist/reglow/modules/role/schema.d.ts +32 -0
- package/dist/reglow/modules/role/schema.js +29 -0
- package/dist/reglow/modules/role/schema.js.map +1 -0
- package/dist/reglow/modules/role/service.d.ts +22 -0
- package/dist/reglow/modules/role/service.js +72 -0
- package/dist/reglow/modules/role/service.js.map +1 -0
- package/dist/reglow/modules/user/controller.d.ts +6 -0
- package/dist/reglow/modules/user/controller.js +126 -0
- package/dist/reglow/modules/user/controller.js.map +1 -0
- package/dist/reglow/modules/user/controller_client.d.ts +2 -0
- package/dist/reglow/modules/user/controller_client.js +291 -0
- package/dist/reglow/modules/user/controller_client.js.map +1 -0
- package/dist/reglow/modules/user/repository.d.ts +12 -0
- package/dist/reglow/modules/user/repository.js +71 -0
- package/dist/reglow/modules/user/repository.js.map +1 -0
- package/dist/reglow/modules/user/router.d.ts +16 -0
- package/dist/reglow/modules/user/router.js +11 -0
- package/dist/reglow/modules/user/router.js.map +1 -0
- package/dist/reglow/modules/user/schema.d.ts +92 -0
- package/dist/reglow/modules/user/schema.js +82 -0
- package/dist/reglow/modules/user/schema.js.map +1 -0
- package/dist/reglow/modules/user/service.d.ts +43 -0
- package/dist/reglow/modules/user/service.js +311 -0
- package/dist/reglow/modules/user/service.js.map +1 -0
- package/dist/reglow/modules/video/controller.d.ts +2 -0
- package/dist/reglow/modules/video/controller.js +254 -0
- package/dist/reglow/modules/video/controller.js.map +1 -0
- package/dist/reglow/modules/video/repository.d.ts +38 -0
- package/dist/reglow/modules/video/repository.js +186 -0
- package/dist/reglow/modules/video/repository.js.map +1 -0
- package/dist/reglow/modules/video/router.d.ts +10 -0
- package/dist/reglow/modules/video/router.js +8 -0
- package/dist/reglow/modules/video/router.js.map +1 -0
- package/dist/reglow/modules/video/schema.d.ts +62 -0
- package/dist/reglow/modules/video/schema.js +61 -0
- package/dist/reglow/modules/video/schema.js.map +1 -0
- package/dist/reglow/modules/video/service.d.ts +80 -0
- package/dist/reglow/modules/video/service.js +251 -0
- package/dist/reglow/modules/video/service.js.map +1 -0
- package/dist/reglow/scripts/init-data.d.ts +44 -0
- package/dist/reglow/scripts/init-data.js +472 -0
- package/dist/reglow/scripts/init-data.js.map +1 -0
- package/dist/reglow/scripts/remove-business-menu.d.ts +1 -0
- package/dist/reglow/scripts/remove-business-menu.js +124 -0
- package/dist/reglow/scripts/remove-business-menu.js.map +1 -0
- package/dist/reglow/scripts/schema.d.ts +9 -0
- package/dist/reglow/scripts/schema.js +746 -0
- package/dist/reglow/scripts/schema.js.map +1 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.d.ts +1 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js +304 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +162 -0
- package/dist/server.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,1143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI 模块 Controller - 路由处理器 + 多厂商适配器 + 默认配置
|
|
3
|
+
* 对应 backend-python 的 reglow/modules/ai/controller.py
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { knex } from "../../core/database.js";
|
|
8
|
+
import { ModelRegistry } from "../../core/models.js";
|
|
9
|
+
import { AppException, ErrorCode } from "../../common/errors.js";
|
|
10
|
+
import { ApiResponse } from "../../common/response.js";
|
|
11
|
+
import { logger } from "../../core/logging.js";
|
|
12
|
+
import settings from "../../core/config.js";
|
|
13
|
+
import { ChatRequestSchema, SaveProviderSchema, DeleteProviderSchema, VideoGenerateSchema, ImageGenerateSchema, } from "./schema.js";
|
|
14
|
+
import { queryImageTask } from "./service.js";
|
|
15
|
+
const SS = ModelRegistry.get("SysSetting");
|
|
16
|
+
// ===================== 默认配置 =====================
|
|
17
|
+
const DEEPSEEK_DEFAULT_MODELS = [
|
|
18
|
+
"deepseek-v4-flash",
|
|
19
|
+
"deepseek-v4-pro",
|
|
20
|
+
"deepseek-chat",
|
|
21
|
+
"deepseek-reasoner",
|
|
22
|
+
];
|
|
23
|
+
const DEFAULT_PROVIDERS = {
|
|
24
|
+
deepseek: {
|
|
25
|
+
api_key: "",
|
|
26
|
+
base_url: "https://api.deepseek.com/v1",
|
|
27
|
+
model: "deepseek-v4-flash",
|
|
28
|
+
models: [
|
|
29
|
+
{
|
|
30
|
+
name: "DeepSeek V4 Flash",
|
|
31
|
+
model_id: "deepseek-v4-flash",
|
|
32
|
+
type: "t2t",
|
|
33
|
+
desc: "新一代快速模型,响应速度极快,适合日常对话和内容生成",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "DeepSeek V4 Pro",
|
|
37
|
+
model_id: "deepseek-v4-pro",
|
|
38
|
+
type: "t2t",
|
|
39
|
+
desc: "旗舰级深度推理模型,支持长上下文与复杂逻辑推理",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
aliyun: {
|
|
44
|
+
api_key: "",
|
|
45
|
+
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
46
|
+
model: "qwen-plus",
|
|
47
|
+
models: [
|
|
48
|
+
{
|
|
49
|
+
name: "通义千问 Max",
|
|
50
|
+
model_id: "qwen-max",
|
|
51
|
+
type: "t2t",
|
|
52
|
+
desc: "通义千问旗舰模型,适合复杂任务",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "通义千问 Plus",
|
|
56
|
+
model_id: "qwen-plus",
|
|
57
|
+
type: "t2t",
|
|
58
|
+
desc: "通义千问增强模型,均衡性能与速度",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "通义千问 Turbo",
|
|
62
|
+
model_id: "qwen-turbo",
|
|
63
|
+
type: "t2t",
|
|
64
|
+
desc: "通义千问极速模型,响应最快",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "万相 2.7 文生图",
|
|
68
|
+
model_id: "wan2.7-image",
|
|
69
|
+
type: "t2i",
|
|
70
|
+
desc: "万相2.7文生图,生成速度快,支持2K分辨率",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "万相 2.7 文生图 Pro",
|
|
74
|
+
model_id: "wan2.7-image-pro",
|
|
75
|
+
type: "t2i",
|
|
76
|
+
desc: "万相2.7专业版,支持4K高清文生图",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "万相 2.7 图生图",
|
|
80
|
+
model_id: "wan2.7-image",
|
|
81
|
+
type: "i2i",
|
|
82
|
+
desc: "万相2.7图生图,支持0-9张参考图",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "万相 2.7 图生图 Pro",
|
|
86
|
+
model_id: "wan2.7-image-pro",
|
|
87
|
+
type: "i2i",
|
|
88
|
+
desc: "万相2.7专业版图生图,支持多图参考与图像编辑",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "万相 2.6 图像编辑",
|
|
92
|
+
model_id: "wan2.6-image",
|
|
93
|
+
type: "i2i",
|
|
94
|
+
desc: "万相2.6图像编辑,支持1-4张参考图",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "万相 2.7 文生视频",
|
|
98
|
+
model_id: "wan2.7-t2v",
|
|
99
|
+
type: "t2v",
|
|
100
|
+
desc: "万相2.7文生视频,支持720P/1080P",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "万相 2.7 图生视频",
|
|
104
|
+
model_id: "wan2.7-i2v",
|
|
105
|
+
type: "i2v",
|
|
106
|
+
desc: "万相2.7图生视频,基于首帧图片生成视频",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "万相 2.7 参考生视频",
|
|
110
|
+
model_id: "wan2.7-r2v",
|
|
111
|
+
type: "v2v",
|
|
112
|
+
desc: "万相2.7参考生视频,基于参考素材生成视频",
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
volcano: {
|
|
117
|
+
api_key: "",
|
|
118
|
+
base_url: "https://ark.cn-beijing.volces.com/api/v3",
|
|
119
|
+
model: "doubao-seedream-4.5",
|
|
120
|
+
models: [
|
|
121
|
+
{
|
|
122
|
+
name: "豆包 Pro 32K",
|
|
123
|
+
model_id: "doubao-pro-32k",
|
|
124
|
+
type: "t2t",
|
|
125
|
+
desc: "豆包Pro 32K,支持长文本对话与推理",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "豆包 Pro 128K",
|
|
129
|
+
model_id: "doubao-pro-128k",
|
|
130
|
+
type: "t2t",
|
|
131
|
+
desc: "豆包Pro 128K,超长上下文对话",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "Seedream 4.5 文生图",
|
|
135
|
+
model_id: "doubao-seedream-4.5",
|
|
136
|
+
type: "t2i",
|
|
137
|
+
desc: "Seedream 4.5文生图,支持组图、高分辨率输出",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "Seedream 4.5 图生图",
|
|
141
|
+
model_id: "doubao-seedream-4.5",
|
|
142
|
+
type: "i2i",
|
|
143
|
+
desc: "Seedream 4.5图生图,支持多图参考与图像编辑",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "Seedance 2.0 文生视频",
|
|
147
|
+
model_id: "doubao-seedance-2-0-260128",
|
|
148
|
+
type: "t2v",
|
|
149
|
+
desc: "Seedance 2.0文生视频,支持480P/720P/1080P",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "Seedance 2.0 图生视频",
|
|
153
|
+
model_id: "doubao-seedance-2-0-260128",
|
|
154
|
+
type: "i2v",
|
|
155
|
+
desc: "Seedance 2.0图生视频,基于首帧图片生成视频",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "Seedance 2.0 参考生视频",
|
|
159
|
+
model_id: "doubao-seedance-2-0-260128",
|
|
160
|
+
type: "v2v",
|
|
161
|
+
desc: "Seedance 2.0多模态参考生视频,支持图/视频/音频参考",
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
tencent: {
|
|
166
|
+
api_key: "",
|
|
167
|
+
base_url: "https://tokenhub.tencentmaas.com/v1",
|
|
168
|
+
model: "hy3-preview",
|
|
169
|
+
models: [
|
|
170
|
+
{
|
|
171
|
+
name: "混元 3.0 Preview",
|
|
172
|
+
model_id: "hy3-preview",
|
|
173
|
+
type: "t2t",
|
|
174
|
+
desc: "混元3.0预览版,新一代旗舰对话模型",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "混元 Image 3.0",
|
|
178
|
+
model_id: "hy-image-v3.0",
|
|
179
|
+
type: "t2i",
|
|
180
|
+
desc: "混元生图3.0,高质量文生图",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "混元 Image Lite",
|
|
184
|
+
model_id: "hy-image-lite",
|
|
185
|
+
type: "t2i",
|
|
186
|
+
desc: "混元生图轻量版,快速出图",
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
zhipu: {
|
|
191
|
+
api_key: "",
|
|
192
|
+
base_url: "https://open.bigmodel.cn/api/paas/v4",
|
|
193
|
+
model: "glm-4.6",
|
|
194
|
+
models: [
|
|
195
|
+
{
|
|
196
|
+
name: "GLM-4.6",
|
|
197
|
+
model_id: "glm-4.6",
|
|
198
|
+
type: "t2t",
|
|
199
|
+
desc: "GLM-4.6旗舰模型,支持200K上下文与深度推理",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "GLM-4.6 Flash",
|
|
203
|
+
model_id: "glm-4.6-flash",
|
|
204
|
+
type: "t2t",
|
|
205
|
+
desc: "GLM-4.6 Flash,极速响应免费模型",
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "GLM-Image",
|
|
209
|
+
model_id: "glm-image",
|
|
210
|
+
type: "t2i",
|
|
211
|
+
desc: "GLM-Image文生图,支持中英双语提示词",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "CogView-4",
|
|
215
|
+
model_id: "cogview-4-250304",
|
|
216
|
+
type: "t2i",
|
|
217
|
+
desc: "CogView-4文生图,支持生成汉字与任意分辨率",
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "CogVideoX-2 文生视频",
|
|
221
|
+
model_id: "cogvideox-2",
|
|
222
|
+
type: "t2v",
|
|
223
|
+
desc: "CogVideoX-2文生视频,支持大幅度运动与多种艺术风格",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "CogVideoX-2 图生视频",
|
|
227
|
+
model_id: "cogvideox-2",
|
|
228
|
+
type: "i2v",
|
|
229
|
+
desc: "CogVideoX-2图生视频,图生视频能力提升38%",
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
moonshot: {
|
|
234
|
+
api_key: "",
|
|
235
|
+
base_url: "https://api.moonshot.cn/v1",
|
|
236
|
+
model: "kimi-k2.6",
|
|
237
|
+
models: [
|
|
238
|
+
{
|
|
239
|
+
name: "Kimi K2.6",
|
|
240
|
+
model_id: "kimi-k2.6",
|
|
241
|
+
type: "t2t",
|
|
242
|
+
desc: "Kimi K2.6,支持文本/图像/视频多模态输入与思考模式",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "Kimi K2.7 Code",
|
|
246
|
+
model_id: "kimi-k2.7-code",
|
|
247
|
+
type: "t2t",
|
|
248
|
+
desc: "Kimi K2.7 Code,编程专用模型,工具调用能力强",
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
// 各服务商对 deep_think / web_search 的参数映射(值为 null 表示不适用)
|
|
254
|
+
const PROVIDER_FEATURE_PARAMS = {
|
|
255
|
+
deepseek: {
|
|
256
|
+
deep_think: { reasoning_effort: "high" },
|
|
257
|
+
web_search: { web_search: true },
|
|
258
|
+
},
|
|
259
|
+
zhipu: {
|
|
260
|
+
deep_think: { enable_thinking: true },
|
|
261
|
+
web_search: { enable_search: true },
|
|
262
|
+
},
|
|
263
|
+
moonshot: {
|
|
264
|
+
deep_think: null,
|
|
265
|
+
web_search: { web_search: true },
|
|
266
|
+
},
|
|
267
|
+
volcano: {
|
|
268
|
+
deep_think: { reasoning_effort: "high" },
|
|
269
|
+
web_search: { web_search: true },
|
|
270
|
+
},
|
|
271
|
+
tencent: {
|
|
272
|
+
deep_think: { reasoning_effort: "high" },
|
|
273
|
+
web_search: { web_search: true },
|
|
274
|
+
},
|
|
275
|
+
aliyun: {
|
|
276
|
+
deep_think: { enable_thinking: true },
|
|
277
|
+
web_search: { enable_search: true },
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
// 图片生成 API(同步)
|
|
281
|
+
export const IMAGE_API_URLS = {
|
|
282
|
+
aliyun: "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
|
|
283
|
+
volcano: "https://ark.cn-beijing.volces.com/api/v3/images/generations",
|
|
284
|
+
tencent: "https://tokenhub.tencentmaas.com/v1/images/generations",
|
|
285
|
+
zhipu: "https://open.bigmodel.cn/api/paas/v4/images/generations",
|
|
286
|
+
};
|
|
287
|
+
// 视频生成 - 创建任务 API
|
|
288
|
+
const VIDEO_CREATE_URLS = {
|
|
289
|
+
aliyun: "https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis",
|
|
290
|
+
volcano: "https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks",
|
|
291
|
+
zhipu: "https://open.bigmodel.cn/api/paas/v4/videos/generations",
|
|
292
|
+
};
|
|
293
|
+
// 视频生成 - 查询任务 API({base}/{task_id})
|
|
294
|
+
const VIDEO_QUERY_URLS = {
|
|
295
|
+
aliyun: "https://dashscope.aliyuncs.com/api/v1/tasks",
|
|
296
|
+
volcano: "https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks",
|
|
297
|
+
zhipu: "https://open.bigmodel.cn/api/paas/v4/async-result",
|
|
298
|
+
};
|
|
299
|
+
const MIME_MAP = {
|
|
300
|
+
".jpg": "image/jpeg",
|
|
301
|
+
".jpeg": "image/jpeg",
|
|
302
|
+
".png": "image/png",
|
|
303
|
+
".gif": "image/gif",
|
|
304
|
+
".webp": "image/webp",
|
|
305
|
+
".bmp": "image/bmp",
|
|
306
|
+
".mp4": "video/mp4",
|
|
307
|
+
".mov": "video/quicktime",
|
|
308
|
+
".mp3": "audio/mpeg",
|
|
309
|
+
".wav": "audio/wav",
|
|
310
|
+
};
|
|
311
|
+
// ===================== 通用辅助 =====================
|
|
312
|
+
function isTimeoutError(e) {
|
|
313
|
+
return (e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError"));
|
|
314
|
+
}
|
|
315
|
+
async function getSetting(groupKey, key, def = "") {
|
|
316
|
+
const row = (await knex(SS)
|
|
317
|
+
.where("group_key", groupKey)
|
|
318
|
+
.where("key", key)
|
|
319
|
+
.first());
|
|
320
|
+
return row?.value ?? def;
|
|
321
|
+
}
|
|
322
|
+
async function setSetting(groupKey, key, value) {
|
|
323
|
+
const existing = await knex(SS)
|
|
324
|
+
.where("group_key", groupKey)
|
|
325
|
+
.where("key", key)
|
|
326
|
+
.first();
|
|
327
|
+
if (existing) {
|
|
328
|
+
await knex(SS)
|
|
329
|
+
.where("group_key", groupKey)
|
|
330
|
+
.where("key", key)
|
|
331
|
+
.update({ value });
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
await knex(SS).insert({ group_key: groupKey, key, value });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function parseJsonOr(raw, fallback) {
|
|
338
|
+
if (!raw)
|
|
339
|
+
return fallback;
|
|
340
|
+
try {
|
|
341
|
+
return JSON.parse(raw);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
return fallback;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function convertSize(size, provider) {
|
|
348
|
+
if (!size)
|
|
349
|
+
return "";
|
|
350
|
+
const normalized = size
|
|
351
|
+
.replace(/\*/g, "x")
|
|
352
|
+
.replace(/:/g, "x")
|
|
353
|
+
.replace(/×/g, "x");
|
|
354
|
+
if (provider === "tencent")
|
|
355
|
+
return normalized.replace(/x/g, ":");
|
|
356
|
+
return normalized;
|
|
357
|
+
}
|
|
358
|
+
function extractImagePrompt(inputData) {
|
|
359
|
+
let prompt = "";
|
|
360
|
+
let refImage = null;
|
|
361
|
+
const messages = inputData.messages;
|
|
362
|
+
if (Array.isArray(messages) && messages.length) {
|
|
363
|
+
const first = messages[0];
|
|
364
|
+
const content = first?.content;
|
|
365
|
+
if (Array.isArray(content)) {
|
|
366
|
+
for (const item of content) {
|
|
367
|
+
if (!item || typeof item !== "object")
|
|
368
|
+
continue;
|
|
369
|
+
const rec = item;
|
|
370
|
+
if ("text" in rec)
|
|
371
|
+
prompt = String(rec.text);
|
|
372
|
+
else if ("image" in rec)
|
|
373
|
+
refImage = typeof rec.image === "string" ? rec.image : null;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if (typeof content === "string") {
|
|
377
|
+
prompt = content;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return { prompt, refImage };
|
|
381
|
+
}
|
|
382
|
+
function extractVideoPrompt(inputData) {
|
|
383
|
+
const prompt = typeof inputData.prompt === "string" ? inputData.prompt : "";
|
|
384
|
+
let firstFrame = null;
|
|
385
|
+
const refMedia = [];
|
|
386
|
+
const media = inputData.media;
|
|
387
|
+
if (Array.isArray(media)) {
|
|
388
|
+
for (const item of media) {
|
|
389
|
+
if (!item || typeof item !== "object")
|
|
390
|
+
continue;
|
|
391
|
+
const rec = item;
|
|
392
|
+
if (rec.type === "first_frame") {
|
|
393
|
+
firstFrame = typeof rec.url === "string" ? rec.url : null;
|
|
394
|
+
}
|
|
395
|
+
else if (rec.type === "reference_image" ||
|
|
396
|
+
rec.type === "reference_video") {
|
|
397
|
+
refMedia.push(rec);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (!firstFrame) {
|
|
402
|
+
firstFrame =
|
|
403
|
+
typeof inputData.img_url === "string" ? inputData.img_url : null;
|
|
404
|
+
}
|
|
405
|
+
if (!refMedia.length) {
|
|
406
|
+
const refUrls = inputData.reference_urls;
|
|
407
|
+
if (Array.isArray(refUrls)) {
|
|
408
|
+
for (const u of refUrls) {
|
|
409
|
+
refMedia.push({ type: "reference_image", url: u });
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return { prompt, firstFrame, refMedia };
|
|
414
|
+
}
|
|
415
|
+
function normalizeTaskStatus(status) {
|
|
416
|
+
const s = (status || "").toUpperCase();
|
|
417
|
+
if (s === "PENDING" || s === "QUEUED")
|
|
418
|
+
return "PENDING";
|
|
419
|
+
if (s === "RUNNING" || s === "PROCESSING")
|
|
420
|
+
return "RUNNING";
|
|
421
|
+
if (s === "SUCCEEDED" || s === "SUCCESS")
|
|
422
|
+
return "SUCCEEDED";
|
|
423
|
+
if (s === "FAILED" || s === "FAIL" || s === "ERROR")
|
|
424
|
+
return "FAILED";
|
|
425
|
+
return s || "UNKNOWN";
|
|
426
|
+
}
|
|
427
|
+
async function extractError(resp, action) {
|
|
428
|
+
let errorMsg = `${action}服务返回错误`;
|
|
429
|
+
let text = "";
|
|
430
|
+
try {
|
|
431
|
+
text = await resp.text();
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
text = "";
|
|
435
|
+
}
|
|
436
|
+
if (text) {
|
|
437
|
+
try {
|
|
438
|
+
const errData = JSON.parse(text);
|
|
439
|
+
const inner = errData.message ??
|
|
440
|
+
errData.error?.message;
|
|
441
|
+
if (typeof inner === "string" && inner)
|
|
442
|
+
errorMsg = inner;
|
|
443
|
+
}
|
|
444
|
+
catch {
|
|
445
|
+
errorMsg = text.slice(0, 300) || errorMsg;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
logger.error(`${action} API 请求失败: ${resp.status} ${text.slice(0, 500)}`);
|
|
449
|
+
return new AppException(ErrorCode.PARAM_ERROR, `${action}失败: ${errorMsg}`);
|
|
450
|
+
}
|
|
451
|
+
// ===================== 图片生成适配器 =====================
|
|
452
|
+
export async function imageGenerateAliyun(apiKey, model, inputData, parameters) {
|
|
453
|
+
const payload = { model, input: inputData };
|
|
454
|
+
if (Object.keys(parameters).length)
|
|
455
|
+
payload.parameters = parameters;
|
|
456
|
+
const resp = await fetch(IMAGE_API_URLS.aliyun, {
|
|
457
|
+
method: "POST",
|
|
458
|
+
headers: {
|
|
459
|
+
Authorization: `Bearer ${apiKey}`,
|
|
460
|
+
"Content-Type": "application/json",
|
|
461
|
+
},
|
|
462
|
+
body: JSON.stringify(payload),
|
|
463
|
+
signal: AbortSignal.timeout(120_000),
|
|
464
|
+
});
|
|
465
|
+
if (resp.status !== 200)
|
|
466
|
+
throw await extractError(resp, "图片生成");
|
|
467
|
+
const result = (await resp.json());
|
|
468
|
+
return result.output ?? {};
|
|
469
|
+
}
|
|
470
|
+
export async function imageGenerateOpenAICompat(apiKey, model, inputData, parameters, url, provider) {
|
|
471
|
+
const { prompt, refImage } = extractImagePrompt(inputData);
|
|
472
|
+
const size = convertSize(typeof parameters.size === "string" ? parameters.size : "", provider);
|
|
473
|
+
const payload = { model, prompt };
|
|
474
|
+
if (refImage)
|
|
475
|
+
payload.image = refImage;
|
|
476
|
+
if (size)
|
|
477
|
+
payload.size = size;
|
|
478
|
+
const resp = await fetch(url, {
|
|
479
|
+
method: "POST",
|
|
480
|
+
headers: {
|
|
481
|
+
Authorization: `Bearer ${apiKey}`,
|
|
482
|
+
"Content-Type": "application/json",
|
|
483
|
+
},
|
|
484
|
+
body: JSON.stringify(payload),
|
|
485
|
+
signal: AbortSignal.timeout(120_000),
|
|
486
|
+
});
|
|
487
|
+
if (resp.status !== 200)
|
|
488
|
+
throw await extractError(resp, "图片生成");
|
|
489
|
+
const result = (await resp.json());
|
|
490
|
+
const dataList = Array.isArray(result.data)
|
|
491
|
+
? result.data
|
|
492
|
+
: [];
|
|
493
|
+
const images = dataList
|
|
494
|
+
.filter((item) => typeof item.url === "string" && item.url)
|
|
495
|
+
.map((item) => ({ image: item.url }));
|
|
496
|
+
return { choices: [{ message: { content: images } }] };
|
|
497
|
+
}
|
|
498
|
+
// ===================== 视频生成适配器 =====================
|
|
499
|
+
async function videoGenerateAliyun(apiKey, model, inputData, parameters) {
|
|
500
|
+
const payload = { model, input: inputData };
|
|
501
|
+
if (Object.keys(parameters).length)
|
|
502
|
+
payload.parameters = parameters;
|
|
503
|
+
const resp = await fetch(VIDEO_CREATE_URLS.aliyun, {
|
|
504
|
+
method: "POST",
|
|
505
|
+
headers: {
|
|
506
|
+
Authorization: `Bearer ${apiKey}`,
|
|
507
|
+
"Content-Type": "application/json",
|
|
508
|
+
"X-DashScope-Async": "enable",
|
|
509
|
+
},
|
|
510
|
+
body: JSON.stringify(payload),
|
|
511
|
+
signal: AbortSignal.timeout(60_000),
|
|
512
|
+
});
|
|
513
|
+
if (resp.status !== 200)
|
|
514
|
+
throw await extractError(resp, "视频生成");
|
|
515
|
+
const result = (await resp.json());
|
|
516
|
+
return result.output ?? {};
|
|
517
|
+
}
|
|
518
|
+
async function videoGenerateVolcano(apiKey, model, inputData, parameters) {
|
|
519
|
+
const { prompt, firstFrame, refMedia } = extractVideoPrompt(inputData);
|
|
520
|
+
const content = [];
|
|
521
|
+
const textParts = [prompt];
|
|
522
|
+
const ratio = parameters.ratio;
|
|
523
|
+
if (ratio)
|
|
524
|
+
textParts.push(`--ratio ${ratio}`);
|
|
525
|
+
const duration = parameters.duration;
|
|
526
|
+
if (duration)
|
|
527
|
+
textParts.push(`--dur ${duration}`);
|
|
528
|
+
const resolution = parameters.resolution;
|
|
529
|
+
if (resolution)
|
|
530
|
+
textParts.push(`--resolution ${resolution}`);
|
|
531
|
+
content.push({ type: "text", text: textParts.join(" ") });
|
|
532
|
+
if (firstFrame) {
|
|
533
|
+
content.push({
|
|
534
|
+
type: "image_url",
|
|
535
|
+
image_url: { url: firstFrame, role: "first_frame" },
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
for (const item of refMedia) {
|
|
539
|
+
if (item.type === "reference_video") {
|
|
540
|
+
content.push({
|
|
541
|
+
type: "video_url",
|
|
542
|
+
video_url: { url: item.url ?? "", role: "reference_video" },
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
content.push({
|
|
547
|
+
type: "image_url",
|
|
548
|
+
image_url: { url: item.url ?? "", role: "reference_image" },
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const payload = { model, content };
|
|
553
|
+
const resp = await fetch(VIDEO_CREATE_URLS.volcano, {
|
|
554
|
+
method: "POST",
|
|
555
|
+
headers: {
|
|
556
|
+
Authorization: `Bearer ${apiKey}`,
|
|
557
|
+
"Content-Type": "application/json",
|
|
558
|
+
},
|
|
559
|
+
body: JSON.stringify(payload),
|
|
560
|
+
signal: AbortSignal.timeout(60_000),
|
|
561
|
+
});
|
|
562
|
+
if (resp.status !== 200)
|
|
563
|
+
throw await extractError(resp, "视频生成");
|
|
564
|
+
const result = (await resp.json());
|
|
565
|
+
const taskId = typeof result.id === "string" ? result.id : "";
|
|
566
|
+
return { task_id: taskId, task_status: "PENDING" };
|
|
567
|
+
}
|
|
568
|
+
async function videoGenerateZhipu(apiKey, model, inputData, _parameters) {
|
|
569
|
+
const { prompt, firstFrame } = extractVideoPrompt(inputData);
|
|
570
|
+
const payload = { model, prompt };
|
|
571
|
+
if (firstFrame)
|
|
572
|
+
payload.image_url = firstFrame;
|
|
573
|
+
const resp = await fetch(VIDEO_CREATE_URLS.zhipu, {
|
|
574
|
+
method: "POST",
|
|
575
|
+
headers: {
|
|
576
|
+
Authorization: `Bearer ${apiKey}`,
|
|
577
|
+
"Content-Type": "application/json",
|
|
578
|
+
},
|
|
579
|
+
body: JSON.stringify(payload),
|
|
580
|
+
signal: AbortSignal.timeout(60_000),
|
|
581
|
+
});
|
|
582
|
+
if (resp.status !== 200)
|
|
583
|
+
throw await extractError(resp, "视频生成");
|
|
584
|
+
const result = (await resp.json());
|
|
585
|
+
const taskId = typeof result.id === "string" ? result.id : "";
|
|
586
|
+
const taskStatus = normalizeTaskStatus(typeof result.task_status === "string" ? result.task_status : "PROCESSING");
|
|
587
|
+
return { task_id: taskId, task_status: taskStatus };
|
|
588
|
+
}
|
|
589
|
+
// ===================== 视频任务查询适配器 =====================
|
|
590
|
+
async function videoTaskAliyun(apiKey, taskId) {
|
|
591
|
+
const resp = await fetch(`${VIDEO_QUERY_URLS.aliyun}/${taskId}`, {
|
|
592
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
593
|
+
signal: AbortSignal.timeout(30_000),
|
|
594
|
+
});
|
|
595
|
+
if (resp.status !== 200) {
|
|
596
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `查询任务状态失败: ${(await resp.text()).slice(0, 300)}`);
|
|
597
|
+
}
|
|
598
|
+
const result = (await resp.json());
|
|
599
|
+
return result.output ?? {};
|
|
600
|
+
}
|
|
601
|
+
async function videoTaskVolcano(apiKey, taskId) {
|
|
602
|
+
const resp = await fetch(`${VIDEO_QUERY_URLS.volcano}/${taskId}`, {
|
|
603
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
604
|
+
signal: AbortSignal.timeout(30_000),
|
|
605
|
+
});
|
|
606
|
+
if (resp.status !== 200) {
|
|
607
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `查询任务状态失败: ${(await resp.text()).slice(0, 300)}`);
|
|
608
|
+
}
|
|
609
|
+
const result = (await resp.json());
|
|
610
|
+
const taskStatus = normalizeTaskStatus(typeof result.status === "string" ? result.status : "running");
|
|
611
|
+
let videoUrl = "";
|
|
612
|
+
const content = result.content;
|
|
613
|
+
if (content && typeof content === "object") {
|
|
614
|
+
videoUrl =
|
|
615
|
+
typeof content.video_url === "string"
|
|
616
|
+
? content.video_url
|
|
617
|
+
: "";
|
|
618
|
+
}
|
|
619
|
+
return { task_id: taskId, task_status: taskStatus, video_url: videoUrl };
|
|
620
|
+
}
|
|
621
|
+
async function videoTaskZhipu(apiKey, taskId) {
|
|
622
|
+
const resp = await fetch(`${VIDEO_QUERY_URLS.zhipu}/${taskId}`, {
|
|
623
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
624
|
+
signal: AbortSignal.timeout(30_000),
|
|
625
|
+
});
|
|
626
|
+
if (resp.status !== 200) {
|
|
627
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `查询任务状态失败: ${(await resp.text()).slice(0, 300)}`);
|
|
628
|
+
}
|
|
629
|
+
const result = (await resp.json());
|
|
630
|
+
const taskStatus = normalizeTaskStatus(typeof result.task_status === "string" ? result.task_status : "PROCESSING");
|
|
631
|
+
let videoUrl = "";
|
|
632
|
+
const videoResult = result.video_result;
|
|
633
|
+
if (Array.isArray(videoResult) && videoResult.length) {
|
|
634
|
+
const first = videoResult[0];
|
|
635
|
+
if (first && typeof first === "object") {
|
|
636
|
+
videoUrl =
|
|
637
|
+
typeof first.url === "string"
|
|
638
|
+
? first.url
|
|
639
|
+
: "";
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return { task_id: taskId, task_status: taskStatus, video_url: videoUrl };
|
|
643
|
+
}
|
|
644
|
+
// ===================== 配置读取 =====================
|
|
645
|
+
export async function getProviderApiKey(provider) {
|
|
646
|
+
const config = await getProviderConfig(provider);
|
|
647
|
+
if (config && config.api_key)
|
|
648
|
+
return config.api_key;
|
|
649
|
+
const envMap = {
|
|
650
|
+
aliyun: "DASHSCOPE_API_KEY",
|
|
651
|
+
volcano: "ARK_API_KEY",
|
|
652
|
+
tencent: "TENCENT_API_KEY",
|
|
653
|
+
zhipu: "ZHIPU_API_KEY",
|
|
654
|
+
};
|
|
655
|
+
const envKey = process.env[envMap[provider] ?? ""];
|
|
656
|
+
if (envKey)
|
|
657
|
+
return envKey;
|
|
658
|
+
const providerNames = {
|
|
659
|
+
aliyun: "阿里云百炼",
|
|
660
|
+
volcano: "火山方舟",
|
|
661
|
+
tencent: "腾讯云",
|
|
662
|
+
zhipu: "智谱AI",
|
|
663
|
+
};
|
|
664
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `未配置${providerNames[provider] ?? provider} API Key,请在系统设置中配置 ${provider} 供应商的 API Key`);
|
|
665
|
+
}
|
|
666
|
+
function inferModelType(name) {
|
|
667
|
+
const n = name.toLowerCase();
|
|
668
|
+
if (n.includes("-t2v") || n.includes("t2v"))
|
|
669
|
+
return "t2v";
|
|
670
|
+
if (n.includes("-i2v") || n.includes("i2v"))
|
|
671
|
+
return "i2v";
|
|
672
|
+
if (n.includes("-r2v") || n.includes("r2v"))
|
|
673
|
+
return "v2v";
|
|
674
|
+
if (n.includes("-t2i") || n.includes("t2i"))
|
|
675
|
+
return "t2i";
|
|
676
|
+
return "t2t";
|
|
677
|
+
}
|
|
678
|
+
function migrateModels(modelsRaw, modelDescs, modelTypes) {
|
|
679
|
+
if (!modelsRaw)
|
|
680
|
+
return [];
|
|
681
|
+
// 已经是新格式(对象数组)
|
|
682
|
+
if (Array.isArray(modelsRaw) &&
|
|
683
|
+
modelsRaw.length &&
|
|
684
|
+
typeof modelsRaw[0] === "object" &&
|
|
685
|
+
modelsRaw[0] !== null) {
|
|
686
|
+
return modelsRaw.map((m) => {
|
|
687
|
+
const item = { ...m };
|
|
688
|
+
if (!("model_id" in item))
|
|
689
|
+
item.model_id = item.name ?? "";
|
|
690
|
+
return item;
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
// 旧格式:字符串数组
|
|
694
|
+
if (Array.isArray(modelsRaw) &&
|
|
695
|
+
modelsRaw.every((m) => typeof m === "string")) {
|
|
696
|
+
return modelsRaw.map((name) => ({
|
|
697
|
+
name,
|
|
698
|
+
model_id: name,
|
|
699
|
+
type: modelTypes[name] || inferModelType(name),
|
|
700
|
+
desc: modelDescs[name] || "",
|
|
701
|
+
}));
|
|
702
|
+
}
|
|
703
|
+
return [];
|
|
704
|
+
}
|
|
705
|
+
export async function getProviderConfig(provider) {
|
|
706
|
+
const defaults = DEFAULT_PROVIDERS[provider] ?? {};
|
|
707
|
+
const apiKey = await getSetting("ai", `${provider}_api_key`, defaults.api_key ?? "");
|
|
708
|
+
if (!apiKey)
|
|
709
|
+
return null;
|
|
710
|
+
const baseUrl = await getSetting("ai", `${provider}_base_url`, defaults.base_url ?? "");
|
|
711
|
+
const model = await getSetting("ai", `${provider}_model`, defaults.model ?? "");
|
|
712
|
+
const modelsJson = await getSetting("ai", `${provider}_models`, "");
|
|
713
|
+
const modelsRaw = parseJsonOr(modelsJson, defaults.models ?? []);
|
|
714
|
+
const modelDescsJson = await getSetting("ai", `${provider}_model_descs`, "");
|
|
715
|
+
const modelDescs = parseJsonOr(modelDescsJson, {});
|
|
716
|
+
const modelTypesJson = await getSetting("ai", `${provider}_model_types`, "");
|
|
717
|
+
const modelTypes = parseJsonOr(modelTypesJson, {});
|
|
718
|
+
const models = migrateModels(modelsRaw, modelDescs, modelTypes);
|
|
719
|
+
return { api_key: apiKey, base_url: baseUrl, model, models };
|
|
720
|
+
}
|
|
721
|
+
export async function getAllProviderConfigs() {
|
|
722
|
+
const rows = (await knex(SS).where("group_key", "ai"));
|
|
723
|
+
const settingsMap = {};
|
|
724
|
+
for (const row of rows) {
|
|
725
|
+
const parts = row.key.split("_", 2);
|
|
726
|
+
if (parts.length === 2) {
|
|
727
|
+
const provider = parts[0];
|
|
728
|
+
const field = parts[1];
|
|
729
|
+
if (!settingsMap[provider])
|
|
730
|
+
settingsMap[provider] = {};
|
|
731
|
+
settingsMap[provider][field] = row.value ?? "";
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
const providers = [];
|
|
735
|
+
for (const provider of Object.keys(settingsMap)) {
|
|
736
|
+
const defaults = DEFAULT_PROVIDERS[provider] ?? {};
|
|
737
|
+
const cfg = settingsMap[provider] ?? {};
|
|
738
|
+
const apiKey = cfg.api_key ?? "";
|
|
739
|
+
const modelsJson = cfg.models ?? "";
|
|
740
|
+
if (!apiKey && !modelsJson)
|
|
741
|
+
continue;
|
|
742
|
+
const modelsRaw = parseJsonOr(modelsJson, defaults.models ?? []);
|
|
743
|
+
const modelDescs = parseJsonOr(cfg.model_descs ?? "", {});
|
|
744
|
+
const modelTypes = parseJsonOr(cfg.model_types ?? "", {});
|
|
745
|
+
const models = migrateModels(modelsRaw, modelDescs, modelTypes);
|
|
746
|
+
providers.push({
|
|
747
|
+
provider,
|
|
748
|
+
api_key: apiKey,
|
|
749
|
+
base_url: cfg.base_url ?? defaults.base_url ?? "",
|
|
750
|
+
model: cfg.model ?? defaults.model ?? "",
|
|
751
|
+
models,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
return providers;
|
|
755
|
+
}
|
|
756
|
+
// ===================== 本地 URL 转 base64 =====================
|
|
757
|
+
function extractPathname(url) {
|
|
758
|
+
try {
|
|
759
|
+
return new URL(url, "http://localhost").pathname;
|
|
760
|
+
}
|
|
761
|
+
catch {
|
|
762
|
+
return "";
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function resolveLocalUrl(url) {
|
|
766
|
+
if (!url || url.startsWith("data:"))
|
|
767
|
+
return url;
|
|
768
|
+
const pathname = extractPathname(url);
|
|
769
|
+
if (!pathname.startsWith("/uploads/"))
|
|
770
|
+
return url;
|
|
771
|
+
const rel = pathname.slice("/uploads/".length);
|
|
772
|
+
if (rel.includes("..") || rel.startsWith("/"))
|
|
773
|
+
return url;
|
|
774
|
+
const filePath = path.join(settings.UPLOAD_DIR, rel);
|
|
775
|
+
if (!existsSync(filePath)) {
|
|
776
|
+
logger.warning(`文件不存在,跳过转换: ${filePath}`);
|
|
777
|
+
return url;
|
|
778
|
+
}
|
|
779
|
+
try {
|
|
780
|
+
const data = readFileSync(filePath).toString("base64");
|
|
781
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
782
|
+
const mime = MIME_MAP[ext] ?? "application/octet-stream";
|
|
783
|
+
return `data:${mime};base64,${data}`;
|
|
784
|
+
}
|
|
785
|
+
catch (e) {
|
|
786
|
+
logger.warning(`文件 base64 转换失败 ${filePath}: ${e.message}`);
|
|
787
|
+
return url;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function resolveLocalImageUrls(messages) {
|
|
791
|
+
for (const msg of messages) {
|
|
792
|
+
if (!Array.isArray(msg.content))
|
|
793
|
+
continue;
|
|
794
|
+
for (const part of msg.content) {
|
|
795
|
+
if (!part || typeof part !== "object")
|
|
796
|
+
continue;
|
|
797
|
+
const rec = part;
|
|
798
|
+
if (rec.type !== "image_url")
|
|
799
|
+
continue;
|
|
800
|
+
const imageUrl = rec.image_url;
|
|
801
|
+
if (!imageUrl || typeof imageUrl !== "object")
|
|
802
|
+
continue;
|
|
803
|
+
const url = imageUrl.url;
|
|
804
|
+
if (typeof url !== "string" || !url)
|
|
805
|
+
continue;
|
|
806
|
+
if (url.startsWith("data:"))
|
|
807
|
+
continue;
|
|
808
|
+
const pathname = extractPathname(url);
|
|
809
|
+
if (!pathname.startsWith("/uploads/"))
|
|
810
|
+
continue;
|
|
811
|
+
const rel = pathname.slice("/uploads/".length);
|
|
812
|
+
if (rel.includes("..") || rel.startsWith("/"))
|
|
813
|
+
continue;
|
|
814
|
+
const filePath = path.join(settings.UPLOAD_DIR, rel);
|
|
815
|
+
if (!existsSync(filePath)) {
|
|
816
|
+
logger.warning(`图片文件不存在,跳过转换: ${filePath}`);
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
const imgData = readFileSync(filePath).toString("base64");
|
|
821
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
822
|
+
const mime = MIME_MAP[ext] ?? "image/jpeg";
|
|
823
|
+
imageUrl.url = `data:${mime};base64,${imgData}`;
|
|
824
|
+
}
|
|
825
|
+
catch (e) {
|
|
826
|
+
logger.warning(`图片 base64 转换失败 ${filePath}: ${e.message}`);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function resolveVideoMediaUrls(inputData) {
|
|
832
|
+
const media = inputData.media;
|
|
833
|
+
if (Array.isArray(media)) {
|
|
834
|
+
for (const item of media) {
|
|
835
|
+
if (!item || typeof item !== "object")
|
|
836
|
+
continue;
|
|
837
|
+
const rec = item;
|
|
838
|
+
if (rec.url)
|
|
839
|
+
rec.url = resolveLocalUrl(String(rec.url));
|
|
840
|
+
if (rec.reference_voice) {
|
|
841
|
+
rec.reference_voice = resolveLocalUrl(String(rec.reference_voice));
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (inputData.img_url) {
|
|
846
|
+
inputData.img_url = resolveLocalUrl(String(inputData.img_url));
|
|
847
|
+
}
|
|
848
|
+
const refUrls = inputData.reference_urls;
|
|
849
|
+
if (Array.isArray(refUrls)) {
|
|
850
|
+
inputData.reference_urls = refUrls.map((u) => resolveLocalUrl(String(u)));
|
|
851
|
+
}
|
|
852
|
+
if (inputData.audio_url) {
|
|
853
|
+
inputData.audio_url = resolveLocalUrl(String(inputData.audio_url));
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
// ===================== 路由处理器 =====================
|
|
857
|
+
export async function aiRoutes(fastify, _opts) {
|
|
858
|
+
// 获取供应商配置列表
|
|
859
|
+
fastify.get("/providers", { schema: { summary: "获取供应商配置列表" }, preHandler: [fastify.requirePermission("operation:setting:read")] }, async () => {
|
|
860
|
+
const providers = await getAllProviderConfigs();
|
|
861
|
+
return ApiResponse.success({ providers });
|
|
862
|
+
});
|
|
863
|
+
// 保存供应商配置
|
|
864
|
+
fastify.put("/providers", {
|
|
865
|
+
preHandler: [fastify.requirePermission("operation:setting:update")],
|
|
866
|
+
schema: { summary: "保存供应商配置", body: SaveProviderSchema },
|
|
867
|
+
}, async (request) => {
|
|
868
|
+
const data = request.body;
|
|
869
|
+
const defaults = DEFAULT_PROVIDERS[data.provider] ?? {};
|
|
870
|
+
const fields = {
|
|
871
|
+
[`${data.provider}_api_key`]: data.api_key,
|
|
872
|
+
[`${data.provider}_base_url`]: data.base_url || defaults.base_url || "",
|
|
873
|
+
[`${data.provider}_model`]: data.model || defaults.model || "",
|
|
874
|
+
[`${data.provider}_models`]: JSON.stringify(data.models ?? defaults.models ?? []),
|
|
875
|
+
};
|
|
876
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
877
|
+
await setSetting("ai", key, value);
|
|
878
|
+
}
|
|
879
|
+
return ApiResponse.success(null, "AI 配置已保存");
|
|
880
|
+
});
|
|
881
|
+
// 删除供应商配置
|
|
882
|
+
fastify.delete("/providers", {
|
|
883
|
+
preHandler: [fastify.requirePermission("operation:setting:update")],
|
|
884
|
+
schema: { summary: "删除供应商配置", body: DeleteProviderSchema },
|
|
885
|
+
}, async (request) => {
|
|
886
|
+
const data = request.body;
|
|
887
|
+
await knex(SS)
|
|
888
|
+
.where("group_key", "ai")
|
|
889
|
+
.where("key", "like", `${data.provider}\\_%`)
|
|
890
|
+
.delete();
|
|
891
|
+
return ApiResponse.success(null, `已删除 ${data.provider} 配置`);
|
|
892
|
+
});
|
|
893
|
+
// 可用模型列表
|
|
894
|
+
fastify.get("/models", { schema: { summary: "可用模型列表" }, preHandler: [fastify.requirePermission("content:article:create")] }, async () => {
|
|
895
|
+
const config = await getProviderConfig("deepseek");
|
|
896
|
+
if (!config)
|
|
897
|
+
return ApiResponse.success(DEEPSEEK_DEFAULT_MODELS);
|
|
898
|
+
const modelNames = config.models.map((m) => m.name);
|
|
899
|
+
return ApiResponse.success(modelNames.length ? modelNames : DEEPSEEK_DEFAULT_MODELS);
|
|
900
|
+
});
|
|
901
|
+
// AI 对话代理(支持流式/非流式)
|
|
902
|
+
fastify.post("/chat", {
|
|
903
|
+
preHandler: [fastify.requirePermission("content:article:create")],
|
|
904
|
+
schema: { summary: "AI 对话代理(支持流式/非流式)", body: ChatRequestSchema },
|
|
905
|
+
}, async (request, reply) => {
|
|
906
|
+
const data = request.body;
|
|
907
|
+
const provider = data.provider || "deepseek";
|
|
908
|
+
const config = await getProviderConfig(provider);
|
|
909
|
+
if (!config || !config.api_key) {
|
|
910
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `AI 服务未配置,请在系统设置中配置 ${provider} 的 API Key`);
|
|
911
|
+
}
|
|
912
|
+
const model = data.model || config.model || "deepseek-v4-flash";
|
|
913
|
+
resolveLocalImageUrls(data.messages);
|
|
914
|
+
const url = `${config.base_url}/chat/completions`;
|
|
915
|
+
const headers = {
|
|
916
|
+
Authorization: `Bearer ${config.api_key}`,
|
|
917
|
+
"Content-Type": "application/json",
|
|
918
|
+
};
|
|
919
|
+
const payload = {
|
|
920
|
+
model,
|
|
921
|
+
messages: data.messages.map((m) => ({
|
|
922
|
+
role: m.role,
|
|
923
|
+
content: m.content,
|
|
924
|
+
})),
|
|
925
|
+
temperature: 0.7,
|
|
926
|
+
max_tokens: 4096,
|
|
927
|
+
};
|
|
928
|
+
const featureParams = PROVIDER_FEATURE_PARAMS[provider] ?? {};
|
|
929
|
+
if (data.deep_think) {
|
|
930
|
+
const dp = featureParams.deep_think;
|
|
931
|
+
if (dp)
|
|
932
|
+
Object.assign(payload, dp);
|
|
933
|
+
}
|
|
934
|
+
if (data.web_search) {
|
|
935
|
+
const sp = featureParams.web_search;
|
|
936
|
+
if (sp)
|
|
937
|
+
Object.assign(payload, sp);
|
|
938
|
+
}
|
|
939
|
+
// 流式模式:实时推送 SSE
|
|
940
|
+
if (data.stream) {
|
|
941
|
+
payload.stream = true;
|
|
942
|
+
reply.hijack();
|
|
943
|
+
reply.raw.writeHead(200, {
|
|
944
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
945
|
+
"Cache-Control": "no-cache",
|
|
946
|
+
Connection: "keep-alive",
|
|
947
|
+
"X-Accel-Buffering": "no",
|
|
948
|
+
});
|
|
949
|
+
try {
|
|
950
|
+
const resp = await fetch(url, {
|
|
951
|
+
method: "POST",
|
|
952
|
+
headers,
|
|
953
|
+
body: JSON.stringify(payload),
|
|
954
|
+
signal: AbortSignal.timeout(120_000),
|
|
955
|
+
});
|
|
956
|
+
if (resp.status !== 200) {
|
|
957
|
+
const body = await resp.text();
|
|
958
|
+
logger.error(`AI API 请求失败: ${resp.status} ${body.slice(0, 500)}`);
|
|
959
|
+
let msg = `AI 服务返回错误 (${resp.status})`;
|
|
960
|
+
try {
|
|
961
|
+
const errDetail = JSON.parse(body).error;
|
|
962
|
+
const detail = errDetail?.message;
|
|
963
|
+
if (typeof detail === "string" && detail) {
|
|
964
|
+
msg = `AI 服务错误: ${detail}`;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
catch {
|
|
968
|
+
// ignore
|
|
969
|
+
}
|
|
970
|
+
reply.raw.write(`data: ${JSON.stringify({ type: "error", content: msg })}\n\n`);
|
|
971
|
+
reply.raw.end();
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (resp.body) {
|
|
975
|
+
const reader = resp.body.getReader();
|
|
976
|
+
while (true) {
|
|
977
|
+
const { done, value } = await reader.read();
|
|
978
|
+
if (done)
|
|
979
|
+
break;
|
|
980
|
+
if (value && value.length)
|
|
981
|
+
reply.raw.write(value);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
reply.raw.write("data: [DONE]\n\n");
|
|
985
|
+
reply.raw.end();
|
|
986
|
+
}
|
|
987
|
+
catch (e) {
|
|
988
|
+
logger.error("AI 流式调用异常", e);
|
|
989
|
+
reply.raw.write(`data: ${JSON.stringify({
|
|
990
|
+
type: "error",
|
|
991
|
+
content: `AI 调用失败: ${e.message}`,
|
|
992
|
+
})}\n\n`);
|
|
993
|
+
reply.raw.end();
|
|
994
|
+
}
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
// 非流式模式:一次性返回
|
|
998
|
+
try {
|
|
999
|
+
const resp = await fetch(url, {
|
|
1000
|
+
method: "POST",
|
|
1001
|
+
headers,
|
|
1002
|
+
body: JSON.stringify(payload),
|
|
1003
|
+
signal: AbortSignal.timeout(120_000),
|
|
1004
|
+
});
|
|
1005
|
+
if (resp.status !== 200) {
|
|
1006
|
+
const body = await resp.text();
|
|
1007
|
+
logger.error(`AI API 请求失败: ${resp.status} ${body.slice(0, 500)}`);
|
|
1008
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `AI 服务返回错误 (${resp.status}): ${body.slice(0, 300)}`);
|
|
1009
|
+
}
|
|
1010
|
+
const result = (await resp.json());
|
|
1011
|
+
const message = (result.choices?.[0]
|
|
1012
|
+
?.message ?? {});
|
|
1013
|
+
const replyContent = typeof message.content === "string" ? message.content : "";
|
|
1014
|
+
const thinking = typeof message.reasoning_content === "string"
|
|
1015
|
+
? message.reasoning_content
|
|
1016
|
+
: "";
|
|
1017
|
+
return ApiResponse.success({ reply: replyContent, thinking });
|
|
1018
|
+
}
|
|
1019
|
+
catch (e) {
|
|
1020
|
+
if (e instanceof AppException)
|
|
1021
|
+
throw e;
|
|
1022
|
+
if (isTimeoutError(e)) {
|
|
1023
|
+
throw new AppException(ErrorCode.PARAM_ERROR, "AI 服务响应超时,请稍后重试");
|
|
1024
|
+
}
|
|
1025
|
+
logger.error("AI 调用异常", e);
|
|
1026
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `AI 调用失败: ${e.message}`);
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
// AI 视频生成
|
|
1030
|
+
fastify.post("/video/generate", {
|
|
1031
|
+
preHandler: [fastify.requirePermission("content:article:create")],
|
|
1032
|
+
schema: { summary: "AI 视频生成", body: VideoGenerateSchema },
|
|
1033
|
+
}, async (request) => {
|
|
1034
|
+
const data = request.body;
|
|
1035
|
+
const provider = data.provider || "aliyun";
|
|
1036
|
+
const apiKey = await getProviderApiKey(provider);
|
|
1037
|
+
resolveVideoMediaUrls(data.input);
|
|
1038
|
+
try {
|
|
1039
|
+
let output;
|
|
1040
|
+
if (provider === "aliyun") {
|
|
1041
|
+
output = await videoGenerateAliyun(apiKey, data.model, data.input, data.parameters ?? {});
|
|
1042
|
+
}
|
|
1043
|
+
else if (provider === "volcano") {
|
|
1044
|
+
output = await videoGenerateVolcano(apiKey, data.model, data.input, data.parameters ?? {});
|
|
1045
|
+
}
|
|
1046
|
+
else if (provider === "zhipu") {
|
|
1047
|
+
output = await videoGenerateZhipu(apiKey, data.model, data.input, data.parameters ?? {});
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `服务商 ${provider} 暂不支持视频生成`);
|
|
1051
|
+
}
|
|
1052
|
+
return ApiResponse.success(output);
|
|
1053
|
+
}
|
|
1054
|
+
catch (e) {
|
|
1055
|
+
if (e instanceof AppException)
|
|
1056
|
+
throw e;
|
|
1057
|
+
if (isTimeoutError(e)) {
|
|
1058
|
+
throw new AppException(ErrorCode.PARAM_ERROR, "视频生成服务响应超时,请稍后重试");
|
|
1059
|
+
}
|
|
1060
|
+
logger.error("视频生成调用异常", e);
|
|
1061
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `视频生成失败: ${e.message}`);
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
// 查询视频生成任务状态
|
|
1065
|
+
fastify.get("/video/task/:task_id", { schema: { summary: "查询视频生成任务状态" }, preHandler: [fastify.requirePermission("content:article:create")] }, async (request) => {
|
|
1066
|
+
const taskId = request.params.task_id;
|
|
1067
|
+
const provider = String(request.query.provider ?? "aliyun");
|
|
1068
|
+
const apiKey = await getProviderApiKey(provider);
|
|
1069
|
+
try {
|
|
1070
|
+
let output;
|
|
1071
|
+
if (provider === "aliyun") {
|
|
1072
|
+
output = await videoTaskAliyun(apiKey, taskId);
|
|
1073
|
+
}
|
|
1074
|
+
else if (provider === "volcano") {
|
|
1075
|
+
output = await videoTaskVolcano(apiKey, taskId);
|
|
1076
|
+
}
|
|
1077
|
+
else if (provider === "zhipu") {
|
|
1078
|
+
output = await videoTaskZhipu(apiKey, taskId);
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `服务商 ${provider} 暂不支持视频任务查询`);
|
|
1082
|
+
}
|
|
1083
|
+
return ApiResponse.success(output);
|
|
1084
|
+
}
|
|
1085
|
+
catch (e) {
|
|
1086
|
+
if (e instanceof AppException)
|
|
1087
|
+
throw e;
|
|
1088
|
+
if (isTimeoutError(e)) {
|
|
1089
|
+
throw new AppException(ErrorCode.PARAM_ERROR, "查询任务状态超时");
|
|
1090
|
+
}
|
|
1091
|
+
logger.error("查询视频任务状态异常", e);
|
|
1092
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `查询失败: ${e.message}`);
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
// AI 图片生成
|
|
1096
|
+
fastify.post("/image/generate", {
|
|
1097
|
+
preHandler: [fastify.requirePermission("content:article:create")],
|
|
1098
|
+
schema: { summary: "AI 图片生成", body: ImageGenerateSchema },
|
|
1099
|
+
}, async (request) => {
|
|
1100
|
+
const data = request.body;
|
|
1101
|
+
const provider = data.provider || "aliyun";
|
|
1102
|
+
const apiKey = await getProviderApiKey(provider);
|
|
1103
|
+
const model = data.model || "wan2.7-image";
|
|
1104
|
+
try {
|
|
1105
|
+
let output;
|
|
1106
|
+
if (provider === "aliyun") {
|
|
1107
|
+
output = await imageGenerateAliyun(apiKey, model, data.input, data.parameters ?? {});
|
|
1108
|
+
}
|
|
1109
|
+
else if (provider === "volcano" ||
|
|
1110
|
+
provider === "tencent" ||
|
|
1111
|
+
provider === "zhipu") {
|
|
1112
|
+
output = await imageGenerateOpenAICompat(apiKey, model, data.input, data.parameters ?? {}, IMAGE_API_URLS[provider], provider);
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `服务商 ${provider} 暂不支持图片生成`);
|
|
1116
|
+
}
|
|
1117
|
+
return ApiResponse.success(output);
|
|
1118
|
+
}
|
|
1119
|
+
catch (e) {
|
|
1120
|
+
if (e instanceof AppException)
|
|
1121
|
+
throw e;
|
|
1122
|
+
if (isTimeoutError(e)) {
|
|
1123
|
+
throw new AppException(ErrorCode.PARAM_ERROR, "图片生成服务响应超时,请稍后重试");
|
|
1124
|
+
}
|
|
1125
|
+
logger.error("图片生成调用异常", e);
|
|
1126
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `图片生成失败: ${e.message}`);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
// 查询图片生成异步任务状态
|
|
1130
|
+
fastify.get("/image/task/:task_id", { schema: { summary: "查询图片生成异步任务状态" }, preHandler: [fastify.requirePermission("content:article:create")] }, async (request) => {
|
|
1131
|
+
const taskId = request.params.task_id;
|
|
1132
|
+
const provider = String(request.query.provider ?? "aliyun");
|
|
1133
|
+
try {
|
|
1134
|
+
const result = await queryImageTask(provider, taskId);
|
|
1135
|
+
return ApiResponse.success(result);
|
|
1136
|
+
}
|
|
1137
|
+
catch (e) {
|
|
1138
|
+
logger.error("图片任务查询异常", e);
|
|
1139
|
+
throw new AppException(ErrorCode.PARAM_ERROR, `任务查询失败: ${e.message}`);
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
//# sourceMappingURL=controller.js.map
|