koishi-plugin-media-luna 0.0.1
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/client/README.md +558 -0
- package/client/api.ts +256 -0
- package/client/components/ChannelConfigDialog.vue +1113 -0
- package/client/components/ChannelsView.vue +698 -0
- package/client/components/ConfigRenderer.vue +164 -0
- package/client/components/EmptyState.vue +87 -0
- package/client/components/GenerateView.vue +778 -0
- package/client/components/HistoryGallery.vue +590 -0
- package/client/components/ImageLightbox.vue +510 -0
- package/client/components/ImageUpload.vue +298 -0
- package/client/components/JsonEditor.vue +68 -0
- package/client/components/LoadingState.vue +73 -0
- package/client/components/PresetsView.vue +800 -0
- package/client/components/ScrollContainer.vue +45 -0
- package/client/components/SettingsView.vue +231 -0
- package/client/components/StatusBadge.vue +55 -0
- package/client/components/TagFilter.vue +139 -0
- package/client/components/TagInput.vue +63 -0
- package/client/components/TasksView.vue +1074 -0
- package/client/components/ViewModeSwitch.vue +78 -0
- package/client/components/settings/CachePanel.vue +142 -0
- package/client/components/settings/MiddlewaresPanel.vue +480 -0
- package/client/components/settings/PluginsPanel.vue +493 -0
- package/client/index.ts +13 -0
- package/client/pages/index.vue +177 -0
- package/client/styles/shared.css +258 -0
- package/client/types.ts +158 -0
- package/client/utils/format.ts +72 -0
- package/dist/index.js +1 -0
- package/dist/style.css +1 -0
- package/lib/api/README.md +643 -0
- package/lib/api/cache-api.d.ts +6 -0
- package/lib/api/cache-api.d.ts.map +1 -0
- package/lib/api/cache-api.js +147 -0
- package/lib/api/cache-api.js.map +1 -0
- package/lib/api/channel-api.d.ts +6 -0
- package/lib/api/channel-api.d.ts.map +1 -0
- package/lib/api/channel-api.js +148 -0
- package/lib/api/channel-api.js.map +1 -0
- package/lib/api/connector-api.d.ts +6 -0
- package/lib/api/connector-api.d.ts.map +1 -0
- package/lib/api/connector-api.js +63 -0
- package/lib/api/connector-api.js.map +1 -0
- package/lib/api/generate-api.d.ts +6 -0
- package/lib/api/generate-api.d.ts.map +1 -0
- package/lib/api/generate-api.js +123 -0
- package/lib/api/generate-api.js.map +1 -0
- package/lib/api/index.d.ts +15 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +34 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/middleware-api.d.ts +6 -0
- package/lib/api/middleware-api.d.ts.map +1 -0
- package/lib/api/middleware-api.js +212 -0
- package/lib/api/middleware-api.js.map +1 -0
- package/lib/api/plugin-api.d.ts +6 -0
- package/lib/api/plugin-api.d.ts.map +1 -0
- package/lib/api/plugin-api.js +78 -0
- package/lib/api/plugin-api.js.map +1 -0
- package/lib/api/preset-api.d.ts +6 -0
- package/lib/api/preset-api.d.ts.map +1 -0
- package/lib/api/preset-api.js +256 -0
- package/lib/api/preset-api.js.map +1 -0
- package/lib/api/settings-api.d.ts +6 -0
- package/lib/api/settings-api.d.ts.map +1 -0
- package/lib/api/settings-api.js +118 -0
- package/lib/api/settings-api.js.map +1 -0
- package/lib/api/task-api.d.ts +6 -0
- package/lib/api/task-api.d.ts.map +1 -0
- package/lib/api/task-api.js +148 -0
- package/lib/api/task-api.js.map +1 -0
- package/lib/config.d.ts +6 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +8 -0
- package/lib/config.js.map +1 -0
- package/lib/connectors/builtin/chat-api.d.ts +9 -0
- package/lib/connectors/builtin/chat-api.d.ts.map +1 -0
- package/lib/connectors/builtin/chat-api.js +351 -0
- package/lib/connectors/builtin/chat-api.js.map +1 -0
- package/lib/connectors/builtin/dalle.d.ts +6 -0
- package/lib/connectors/builtin/dalle.d.ts.map +1 -0
- package/lib/connectors/builtin/dalle.js +109 -0
- package/lib/connectors/builtin/dalle.js.map +1 -0
- package/lib/connectors/builtin/flux.d.ts +7 -0
- package/lib/connectors/builtin/flux.d.ts.map +1 -0
- package/lib/connectors/builtin/flux.js +199 -0
- package/lib/connectors/builtin/flux.js.map +1 -0
- package/lib/connectors/builtin/index.d.ts +5 -0
- package/lib/connectors/builtin/index.d.ts.map +1 -0
- package/lib/connectors/builtin/index.js +6 -0
- package/lib/connectors/builtin/index.js.map +1 -0
- package/lib/connectors/builtin/sd-webui.d.ts +7 -0
- package/lib/connectors/builtin/sd-webui.d.ts.map +1 -0
- package/lib/connectors/builtin/sd-webui.js +157 -0
- package/lib/connectors/builtin/sd-webui.js.map +1 -0
- package/lib/connectors/connector-registry.d.ts +36 -0
- package/lib/connectors/connector-registry.d.ts.map +1 -0
- package/lib/connectors/connector-registry.js +66 -0
- package/lib/connectors/connector-registry.js.map +1 -0
- package/lib/connectors/index.d.ts +3 -0
- package/lib/connectors/index.d.ts.map +1 -0
- package/lib/connectors/index.js +4 -0
- package/lib/connectors/index.js.map +1 -0
- package/lib/core/api/api-utils.d.ts +46 -0
- package/lib/core/api/api-utils.d.ts.map +1 -0
- package/lib/core/api/api-utils.js +78 -0
- package/lib/core/api/api-utils.js.map +1 -0
- package/lib/core/api/cache-api.d.ts +6 -0
- package/lib/core/api/cache-api.d.ts.map +1 -0
- package/lib/core/api/cache-api.js +147 -0
- package/lib/core/api/cache-api.js.map +1 -0
- package/lib/core/api/channel-api.d.ts +6 -0
- package/lib/core/api/channel-api.d.ts.map +1 -0
- package/lib/core/api/channel-api.js +146 -0
- package/lib/core/api/channel-api.js.map +1 -0
- package/lib/core/api/connector-api.d.ts +6 -0
- package/lib/core/api/connector-api.d.ts.map +1 -0
- package/lib/core/api/connector-api.js +63 -0
- package/lib/core/api/connector-api.js.map +1 -0
- package/lib/core/api/generate-api.d.ts +6 -0
- package/lib/core/api/generate-api.d.ts.map +1 -0
- package/lib/core/api/generate-api.js +124 -0
- package/lib/core/api/generate-api.js.map +1 -0
- package/lib/core/api/index.d.ts +16 -0
- package/lib/core/api/index.d.ts.map +1 -0
- package/lib/core/api/index.js +38 -0
- package/lib/core/api/index.js.map +1 -0
- package/lib/core/api/middleware-api.d.ts +6 -0
- package/lib/core/api/middleware-api.d.ts.map +1 -0
- package/lib/core/api/middleware-api.js +196 -0
- package/lib/core/api/middleware-api.js.map +1 -0
- package/lib/core/api/plugin-api.d.ts +6 -0
- package/lib/core/api/plugin-api.d.ts.map +1 -0
- package/lib/core/api/plugin-api.js +78 -0
- package/lib/core/api/plugin-api.js.map +1 -0
- package/lib/core/api/preset-api.d.ts +6 -0
- package/lib/core/api/preset-api.d.ts.map +1 -0
- package/lib/core/api/preset-api.js +272 -0
- package/lib/core/api/preset-api.js.map +1 -0
- package/lib/core/api/settings-api.d.ts +6 -0
- package/lib/core/api/settings-api.d.ts.map +1 -0
- package/lib/core/api/settings-api.js +118 -0
- package/lib/core/api/settings-api.js.map +1 -0
- package/lib/core/api/task-api.d.ts +6 -0
- package/lib/core/api/task-api.d.ts.map +1 -0
- package/lib/core/api/task-api.js +281 -0
- package/lib/core/api/task-api.js.map +1 -0
- package/lib/core/channel.service.d.ts +44 -0
- package/lib/core/channel.service.d.ts.map +1 -0
- package/lib/core/channel.service.js +146 -0
- package/lib/core/channel.service.js.map +1 -0
- package/lib/core/config/config.service.d.ts +89 -0
- package/lib/core/config/config.service.d.ts.map +1 -0
- package/lib/core/config/config.service.js +216 -0
- package/lib/core/config/config.service.js.map +1 -0
- package/lib/core/config/index.d.ts +3 -0
- package/lib/core/config/index.d.ts.map +1 -0
- package/lib/core/config/index.js +3 -0
- package/lib/core/config/index.js.map +1 -0
- package/lib/core/error.d.ts +73 -0
- package/lib/core/error.d.ts.map +1 -0
- package/lib/core/error.js +137 -0
- package/lib/core/error.js.map +1 -0
- package/lib/core/index.d.ts +12 -0
- package/lib/core/index.d.ts.map +1 -0
- package/lib/core/index.js +23 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/logger.d.ts +18 -0
- package/lib/core/logger.d.ts.map +1 -0
- package/lib/core/logger.js +39 -0
- package/lib/core/logger.js.map +1 -0
- package/lib/core/medialuna.service.d.ts +168 -0
- package/lib/core/medialuna.service.d.ts.map +1 -0
- package/lib/core/medialuna.service.js +423 -0
- package/lib/core/medialuna.service.js.map +1 -0
- package/lib/core/pipeline/dependency-graph.d.ts +43 -0
- package/lib/core/pipeline/dependency-graph.d.ts.map +1 -0
- package/lib/core/pipeline/dependency-graph.js +223 -0
- package/lib/core/pipeline/dependency-graph.js.map +1 -0
- package/lib/core/pipeline/generation-pipeline.d.ts +40 -0
- package/lib/core/pipeline/generation-pipeline.d.ts.map +1 -0
- package/lib/core/pipeline/generation-pipeline.js +216 -0
- package/lib/core/pipeline/generation-pipeline.js.map +1 -0
- package/lib/core/pipeline/index.d.ts +4 -0
- package/lib/core/pipeline/index.d.ts.map +1 -0
- package/lib/core/pipeline/index.js +5 -0
- package/lib/core/pipeline/index.js.map +1 -0
- package/lib/core/pipeline/middleware-registry.d.ts +33 -0
- package/lib/core/pipeline/middleware-registry.d.ts.map +1 -0
- package/lib/core/pipeline/middleware-registry.js +78 -0
- package/lib/core/pipeline/middleware-registry.js.map +1 -0
- package/lib/core/plugin-loader.d.ts +77 -0
- package/lib/core/plugin-loader.d.ts.map +1 -0
- package/lib/core/plugin-loader.js +300 -0
- package/lib/core/plugin-loader.js.map +1 -0
- package/lib/core/registry/connector.registry.d.ts +36 -0
- package/lib/core/registry/connector.registry.d.ts.map +1 -0
- package/lib/core/registry/connector.registry.js +65 -0
- package/lib/core/registry/connector.registry.js.map +1 -0
- package/lib/core/registry/index.d.ts +3 -0
- package/lib/core/registry/index.d.ts.map +1 -0
- package/lib/core/registry/index.js +4 -0
- package/lib/core/registry/index.js.map +1 -0
- package/lib/core/registry/service.registry.d.ts +27 -0
- package/lib/core/registry/service.registry.d.ts.map +1 -0
- package/lib/core/registry/service.registry.js +54 -0
- package/lib/core/registry/service.registry.js.map +1 -0
- package/lib/core/request.service.d.ts +83 -0
- package/lib/core/request.service.d.ts.map +1 -0
- package/lib/core/request.service.js +237 -0
- package/lib/core/request.service.js.map +1 -0
- package/lib/core/types.d.ts +270 -0
- package/lib/core/types.d.ts.map +1 -0
- package/lib/core/types.js +17 -0
- package/lib/core/types.js.map +1 -0
- package/lib/database.d.ts +6 -0
- package/lib/database.d.ts.map +1 -0
- package/lib/database.js +89 -0
- package/lib/database.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +54 -0
- package/lib/index.js.map +1 -0
- package/lib/middlewares/builtin/billing.d.ts +45 -0
- package/lib/middlewares/builtin/billing.d.ts.map +1 -0
- package/lib/middlewares/builtin/billing.js +362 -0
- package/lib/middlewares/builtin/billing.js.map +1 -0
- package/lib/middlewares/builtin/index.d.ts +6 -0
- package/lib/middlewares/builtin/index.d.ts.map +1 -0
- package/lib/middlewares/builtin/index.js +7 -0
- package/lib/middlewares/builtin/index.js.map +1 -0
- package/lib/middlewares/builtin/preset.d.ts +14 -0
- package/lib/middlewares/builtin/preset.d.ts.map +1 -0
- package/lib/middlewares/builtin/preset.js +156 -0
- package/lib/middlewares/builtin/preset.js.map +1 -0
- package/lib/middlewares/builtin/remote-preset-sync.d.ts +8 -0
- package/lib/middlewares/builtin/remote-preset-sync.d.ts.map +1 -0
- package/lib/middlewares/builtin/remote-preset-sync.js +32 -0
- package/lib/middlewares/builtin/remote-preset-sync.js.map +1 -0
- package/lib/middlewares/builtin/request.d.ts +10 -0
- package/lib/middlewares/builtin/request.d.ts.map +1 -0
- package/lib/middlewares/builtin/request.js +50 -0
- package/lib/middlewares/builtin/request.js.map +1 -0
- package/lib/middlewares/builtin/storage.d.ts +64 -0
- package/lib/middlewares/builtin/storage.d.ts.map +1 -0
- package/lib/middlewares/builtin/storage.js +715 -0
- package/lib/middlewares/builtin/storage.js.map +1 -0
- package/lib/middlewares/builtin/task-recorder.d.ts +20 -0
- package/lib/middlewares/builtin/task-recorder.d.ts.map +1 -0
- package/lib/middlewares/builtin/task-recorder.js +138 -0
- package/lib/middlewares/builtin/task-recorder.js.map +1 -0
- package/lib/middlewares/index.d.ts +2 -0
- package/lib/middlewares/index.d.ts.map +1 -0
- package/lib/middlewares/index.js +3 -0
- package/lib/middlewares/index.js.map +1 -0
- package/lib/pipeline/dependency-graph.d.ts +43 -0
- package/lib/pipeline/dependency-graph.d.ts.map +1 -0
- package/lib/pipeline/dependency-graph.js +240 -0
- package/lib/pipeline/dependency-graph.js.map +1 -0
- package/lib/pipeline/generation-pipeline.d.ts +38 -0
- package/lib/pipeline/generation-pipeline.d.ts.map +1 -0
- package/lib/pipeline/generation-pipeline.js +211 -0
- package/lib/pipeline/generation-pipeline.js.map +1 -0
- package/lib/pipeline/index.d.ts +4 -0
- package/lib/pipeline/index.d.ts.map +1 -0
- package/lib/pipeline/index.js +5 -0
- package/lib/pipeline/index.js.map +1 -0
- package/lib/pipeline/middleware-registry.d.ts +36 -0
- package/lib/pipeline/middleware-registry.d.ts.map +1 -0
- package/lib/pipeline/middleware-registry.js +83 -0
- package/lib/pipeline/middleware-registry.js.map +1 -0
- package/lib/plugins/billing/config.d.ts +19 -0
- package/lib/plugins/billing/config.d.ts.map +1 -0
- package/lib/plugins/billing/config.js +98 -0
- package/lib/plugins/billing/config.js.map +1 -0
- package/lib/plugins/billing/index.d.ts +4 -0
- package/lib/plugins/billing/index.d.ts.map +1 -0
- package/lib/plugins/billing/index.js +20 -0
- package/lib/plugins/billing/index.js.map +1 -0
- package/lib/plugins/billing/middleware.d.ts +12 -0
- package/lib/plugins/billing/middleware.d.ts.map +1 -0
- package/lib/plugins/billing/middleware.js +233 -0
- package/lib/plugins/billing/middleware.js.map +1 -0
- package/lib/plugins/cache/config.d.ts +44 -0
- package/lib/plugins/cache/config.d.ts.map +1 -0
- package/lib/plugins/cache/config.js +187 -0
- package/lib/plugins/cache/config.js.map +1 -0
- package/lib/plugins/cache/index.d.ts +6 -0
- package/lib/plugins/cache/index.d.ts.map +1 -0
- package/lib/plugins/cache/index.js +87 -0
- package/lib/plugins/cache/index.js.map +1 -0
- package/lib/plugins/cache/middleware.d.ts +12 -0
- package/lib/plugins/cache/middleware.d.ts.map +1 -0
- package/lib/plugins/cache/middleware.js +194 -0
- package/lib/plugins/cache/middleware.js.map +1 -0
- package/lib/plugins/cache/service.d.ts +106 -0
- package/lib/plugins/cache/service.d.ts.map +1 -0
- package/lib/plugins/cache/service.js +467 -0
- package/lib/plugins/cache/service.js.map +1 -0
- package/lib/plugins/cache/utils/index.d.ts +4 -0
- package/lib/plugins/cache/utils/index.d.ts.map +1 -0
- package/lib/plugins/cache/utils/index.js +5 -0
- package/lib/plugins/cache/utils/index.js.map +1 -0
- package/lib/plugins/cache/utils/mime.d.ts +9 -0
- package/lib/plugins/cache/utils/mime.d.ts.map +1 -0
- package/lib/plugins/cache/utils/mime.js +65 -0
- package/lib/plugins/cache/utils/mime.js.map +1 -0
- package/lib/plugins/cache/utils/s3.d.ts +19 -0
- package/lib/plugins/cache/utils/s3.d.ts.map +1 -0
- package/lib/plugins/cache/utils/s3.js +147 -0
- package/lib/plugins/cache/utils/s3.js.map +1 -0
- package/lib/plugins/cache/utils/webdav.d.ts +16 -0
- package/lib/plugins/cache/utils/webdav.d.ts.map +1 -0
- package/lib/plugins/cache/utils/webdav.js +69 -0
- package/lib/plugins/cache/utils/webdav.js.map +1 -0
- package/lib/plugins/connector-chat-api/index.d.ts +7 -0
- package/lib/plugins/connector-chat-api/index.d.ts.map +1 -0
- package/lib/plugins/connector-chat-api/index.js +400 -0
- package/lib/plugins/connector-chat-api/index.js.map +1 -0
- package/lib/plugins/connector-dalle/index.d.ts +7 -0
- package/lib/plugins/connector-dalle/index.d.ts.map +1 -0
- package/lib/plugins/connector-dalle/index.js +140 -0
- package/lib/plugins/connector-dalle/index.js.map +1 -0
- package/lib/plugins/connector-flux/index.d.ts +7 -0
- package/lib/plugins/connector-flux/index.d.ts.map +1 -0
- package/lib/plugins/connector-flux/index.js +232 -0
- package/lib/plugins/connector-flux/index.js.map +1 -0
- package/lib/plugins/connector-sd-webui/index.d.ts +7 -0
- package/lib/plugins/connector-sd-webui/index.d.ts.map +1 -0
- package/lib/plugins/connector-sd-webui/index.js +171 -0
- package/lib/plugins/connector-sd-webui/index.js.map +1 -0
- package/lib/plugins/index.d.ts +22 -0
- package/lib/plugins/index.d.ts.map +1 -0
- package/lib/plugins/index.js +21 -0
- package/lib/plugins/index.js.map +1 -0
- package/lib/plugins/preset/config.d.ts +37 -0
- package/lib/plugins/preset/config.d.ts.map +1 -0
- package/lib/plugins/preset/config.js +74 -0
- package/lib/plugins/preset/config.js.map +1 -0
- package/lib/plugins/preset/index.d.ts +6 -0
- package/lib/plugins/preset/index.d.ts.map +1 -0
- package/lib/plugins/preset/index.js +58 -0
- package/lib/plugins/preset/index.js.map +1 -0
- package/lib/plugins/preset/middleware.d.ts +6 -0
- package/lib/plugins/preset/middleware.d.ts.map +1 -0
- package/lib/plugins/preset/middleware.js +126 -0
- package/lib/plugins/preset/middleware.js.map +1 -0
- package/lib/plugins/preset/remote-sync.service.d.ts +84 -0
- package/lib/plugins/preset/remote-sync.service.d.ts.map +1 -0
- package/lib/plugins/preset/remote-sync.service.js +342 -0
- package/lib/plugins/preset/remote-sync.service.js.map +1 -0
- package/lib/plugins/preset/service.d.ts +64 -0
- package/lib/plugins/preset/service.d.ts.map +1 -0
- package/lib/plugins/preset/service.js +196 -0
- package/lib/plugins/preset/service.js.map +1 -0
- package/lib/plugins/prompt-encoding/config.d.ts +25 -0
- package/lib/plugins/prompt-encoding/config.d.ts.map +1 -0
- package/lib/plugins/prompt-encoding/config.js +62 -0
- package/lib/plugins/prompt-encoding/config.js.map +1 -0
- package/lib/plugins/prompt-encoding/index.d.ts +5 -0
- package/lib/plugins/prompt-encoding/index.d.ts.map +1 -0
- package/lib/plugins/prompt-encoding/index.js +21 -0
- package/lib/plugins/prompt-encoding/index.js.map +1 -0
- package/lib/plugins/prompt-encoding/middleware.d.ts +6 -0
- package/lib/plugins/prompt-encoding/middleware.d.ts.map +1 -0
- package/lib/plugins/prompt-encoding/middleware.js +151 -0
- package/lib/plugins/prompt-encoding/middleware.js.map +1 -0
- package/lib/plugins/task/config.d.ts +15 -0
- package/lib/plugins/task/config.d.ts.map +1 -0
- package/lib/plugins/task/config.js +33 -0
- package/lib/plugins/task/config.js.map +1 -0
- package/lib/plugins/task/index.d.ts +5 -0
- package/lib/plugins/task/index.d.ts.map +1 -0
- package/lib/plugins/task/index.js +58 -0
- package/lib/plugins/task/index.js.map +1 -0
- package/lib/plugins/task/middleware.d.ts +14 -0
- package/lib/plugins/task/middleware.d.ts.map +1 -0
- package/lib/plugins/task/middleware.js +123 -0
- package/lib/plugins/task/middleware.js.map +1 -0
- package/lib/plugins/task/service.d.ts +94 -0
- package/lib/plugins/task/service.d.ts.map +1 -0
- package/lib/plugins/task/service.js +226 -0
- package/lib/plugins/task/service.js.map +1 -0
- package/lib/plugins/webui-auth/config.d.ts +12 -0
- package/lib/plugins/webui-auth/config.d.ts.map +1 -0
- package/lib/plugins/webui-auth/config.js +30 -0
- package/lib/plugins/webui-auth/config.js.map +1 -0
- package/lib/plugins/webui-auth/index.d.ts +5 -0
- package/lib/plugins/webui-auth/index.d.ts.map +1 -0
- package/lib/plugins/webui-auth/index.js +99 -0
- package/lib/plugins/webui-auth/index.js.map +1 -0
- package/lib/plugins/webui-auth/service.d.ts +42 -0
- package/lib/plugins/webui-auth/service.d.ts.map +1 -0
- package/lib/plugins/webui-auth/service.js +106 -0
- package/lib/plugins/webui-auth/service.js.map +1 -0
- package/lib/services/asset-cache.service.d.ts +133 -0
- package/lib/services/asset-cache.service.d.ts.map +1 -0
- package/lib/services/asset-cache.service.js +882 -0
- package/lib/services/asset-cache.service.js.map +1 -0
- package/lib/services/cache.service.d.ts +110 -0
- package/lib/services/cache.service.d.ts.map +1 -0
- package/lib/services/cache.service.js +333 -0
- package/lib/services/cache.service.js.map +1 -0
- package/lib/services/channel.service.d.ts +44 -0
- package/lib/services/channel.service.d.ts.map +1 -0
- package/lib/services/channel.service.js +154 -0
- package/lib/services/channel.service.js.map +1 -0
- package/lib/services/config.service.d.ts +73 -0
- package/lib/services/config.service.d.ts.map +1 -0
- package/lib/services/config.service.js +171 -0
- package/lib/services/config.service.js.map +1 -0
- package/lib/services/index.d.ts +8 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +9 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/medialuna.service.d.ts +173 -0
- package/lib/services/medialuna.service.d.ts.map +1 -0
- package/lib/services/medialuna.service.js +455 -0
- package/lib/services/medialuna.service.js.map +1 -0
- package/lib/services/preset.service.d.ts +69 -0
- package/lib/services/preset.service.d.ts.map +1 -0
- package/lib/services/preset.service.js +202 -0
- package/lib/services/preset.service.js.map +1 -0
- package/lib/services/remote-preset.service.d.ts +97 -0
- package/lib/services/remote-preset.service.d.ts.map +1 -0
- package/lib/services/remote-preset.service.js +212 -0
- package/lib/services/remote-preset.service.js.map +1 -0
- package/lib/services/task.service.d.ts +57 -0
- package/lib/services/task.service.d.ts.map +1 -0
- package/lib/services/task.service.js +138 -0
- package/lib/services/task.service.js.map +1 -0
- package/lib/types/index.d.ts +357 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +21 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +66 -0
- package/readme.md +326 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// S3 工具模块
|
|
2
|
+
// S3 兼容存储的上传工具函数
|
|
3
|
+
import { createHash, createHmac } from 'crypto';
|
|
4
|
+
/** 格式化日期为 AWS 格式 */
|
|
5
|
+
function toAmzDate(d) {
|
|
6
|
+
const pad = (n, w = 2) => n.toString().padStart(w, '0');
|
|
7
|
+
return (d.getUTCFullYear().toString() +
|
|
8
|
+
pad(d.getUTCMonth() + 1) +
|
|
9
|
+
pad(d.getUTCDate()) +
|
|
10
|
+
'T' +
|
|
11
|
+
pad(d.getUTCHours()) +
|
|
12
|
+
pad(d.getUTCMinutes()) +
|
|
13
|
+
pad(d.getUTCSeconds()) +
|
|
14
|
+
'Z');
|
|
15
|
+
}
|
|
16
|
+
/** 计算 SHA256 哈希(十六进制) */
|
|
17
|
+
function sha256Hex(data) {
|
|
18
|
+
return createHash('sha256').update(data).digest('hex');
|
|
19
|
+
}
|
|
20
|
+
/** 计算 HMAC(返回 Buffer) */
|
|
21
|
+
function hmac(key, data) {
|
|
22
|
+
return createHmac('sha256', key).update(data, 'utf8').digest();
|
|
23
|
+
}
|
|
24
|
+
/** 计算 HMAC(返回十六进制) */
|
|
25
|
+
function hmacHex(key, data) {
|
|
26
|
+
return createHmac('sha256', key).update(data, 'utf8').digest('hex');
|
|
27
|
+
}
|
|
28
|
+
/** 获取 AWS 签名密钥 */
|
|
29
|
+
function getSignatureKey(secretKey, dateStamp, regionName, serviceName) {
|
|
30
|
+
const kDate = hmac('AWS4' + secretKey, dateStamp);
|
|
31
|
+
const kRegion = hmac(kDate, regionName);
|
|
32
|
+
const kService = hmac(kRegion, serviceName);
|
|
33
|
+
return hmac(kService, 'aws4_request');
|
|
34
|
+
}
|
|
35
|
+
/** 去除多余空格 */
|
|
36
|
+
function trimSpaces(str) {
|
|
37
|
+
return str.replace(/\s+/g, ' ').trim();
|
|
38
|
+
}
|
|
39
|
+
/** URL 编码路径中的每个部分 */
|
|
40
|
+
function encodeKey(key) {
|
|
41
|
+
return key.split('/').map(encodeURIComponent).join('/');
|
|
42
|
+
}
|
|
43
|
+
/** 拼接 URL 和路径 */
|
|
44
|
+
function joinUrl(base, key) {
|
|
45
|
+
const b = base.replace(/\/$/, '');
|
|
46
|
+
return `${b}/${encodeKey(key)}`;
|
|
47
|
+
}
|
|
48
|
+
/** 构建 S3 主机和路径信息 */
|
|
49
|
+
function buildS3HostAndPath(config, key) {
|
|
50
|
+
let base;
|
|
51
|
+
if (config.endpoint) {
|
|
52
|
+
base = new URL(config.endpoint);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
base = new URL(`https://s3.${config.region || 'us-east-1'}.amazonaws.com`);
|
|
56
|
+
}
|
|
57
|
+
const bucket = config.bucket;
|
|
58
|
+
const isIp = /^\d{1,3}(?:\.\d{1,3}){3}$/.test(base.hostname);
|
|
59
|
+
const hasPort = !!base.port;
|
|
60
|
+
const isLocal = base.hostname === 'localhost';
|
|
61
|
+
const preferPath = isIp || hasPort || isLocal;
|
|
62
|
+
const usePath = !!config.forcePathStyle || preferPath;
|
|
63
|
+
const hostname = base.hostname;
|
|
64
|
+
const port = base.port ? `:${base.port}` : '';
|
|
65
|
+
let host = hostname + port;
|
|
66
|
+
let path = '';
|
|
67
|
+
if (usePath) {
|
|
68
|
+
path = `/${bucket}/${encodeKey(key)}`;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
host = `${bucket}.${hostname}${port}`;
|
|
72
|
+
path = `/${encodeKey(key)}`;
|
|
73
|
+
}
|
|
74
|
+
const url = `${base.protocol}//${host}${path}`;
|
|
75
|
+
const canonicalUri = path;
|
|
76
|
+
return { host, url, canonicalUri };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 上传文件到 S3 兼容存储
|
|
80
|
+
*/
|
|
81
|
+
export async function uploadToS3(buffer, filename, mime, config) {
|
|
82
|
+
const bucket = config.bucket;
|
|
83
|
+
const region = config.region || 'us-east-1';
|
|
84
|
+
const accessKeyId = config.accessKeyId;
|
|
85
|
+
const secretAccessKey = config.secretAccessKey;
|
|
86
|
+
if (!bucket)
|
|
87
|
+
throw new Error('S3 缺少 bucket 配置');
|
|
88
|
+
if (!accessKeyId || !secretAccessKey)
|
|
89
|
+
throw new Error('S3 需提供访问凭证');
|
|
90
|
+
const now = new Date();
|
|
91
|
+
const amzDate = toAmzDate(now);
|
|
92
|
+
const dateStamp = amzDate.slice(0, 8);
|
|
93
|
+
const key = filename;
|
|
94
|
+
const hostInfo = buildS3HostAndPath(config, key);
|
|
95
|
+
const { host, url, canonicalUri } = hostInfo;
|
|
96
|
+
const payloadHash = sha256Hex(buffer);
|
|
97
|
+
const headers = {
|
|
98
|
+
'host': host,
|
|
99
|
+
'x-amz-content-sha256': payloadHash,
|
|
100
|
+
'x-amz-date': amzDate,
|
|
101
|
+
};
|
|
102
|
+
if (mime)
|
|
103
|
+
headers['content-type'] = mime;
|
|
104
|
+
if (config.acl)
|
|
105
|
+
headers['x-amz-acl'] = config.acl;
|
|
106
|
+
const signedHeaders = Object.keys(headers)
|
|
107
|
+
.map(k => k.toLowerCase())
|
|
108
|
+
.sort()
|
|
109
|
+
.join(';');
|
|
110
|
+
const canonicalHeaders = Object.keys(headers)
|
|
111
|
+
.map(k => k.toLowerCase())
|
|
112
|
+
.sort()
|
|
113
|
+
.map(k => `${k}:${trimSpaces(String(headers[k]))}\n`)
|
|
114
|
+
.join('');
|
|
115
|
+
const canonicalRequest = [
|
|
116
|
+
'PUT',
|
|
117
|
+
canonicalUri,
|
|
118
|
+
'',
|
|
119
|
+
canonicalHeaders,
|
|
120
|
+
signedHeaders,
|
|
121
|
+
payloadHash,
|
|
122
|
+
].join('\n');
|
|
123
|
+
const algorithm = 'AWS4-HMAC-SHA256';
|
|
124
|
+
const credentialScope = `${dateStamp}/${region}/s3/aws4_request`;
|
|
125
|
+
const stringToSign = [
|
|
126
|
+
algorithm,
|
|
127
|
+
amzDate,
|
|
128
|
+
credentialScope,
|
|
129
|
+
sha256Hex(Buffer.from(canonicalRequest, 'utf8')),
|
|
130
|
+
].join('\n');
|
|
131
|
+
const signingKey = getSignatureKey(secretAccessKey, dateStamp, region, 's3');
|
|
132
|
+
const signature = hmacHex(signingKey, stringToSign);
|
|
133
|
+
const authorization = `${algorithm} Credential=${accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
|
|
134
|
+
const reqHeaders = { ...headers, Authorization: authorization };
|
|
135
|
+
const resp = await fetch(url, {
|
|
136
|
+
method: 'PUT',
|
|
137
|
+
headers: reqHeaders,
|
|
138
|
+
body: new Uint8Array(buffer)
|
|
139
|
+
});
|
|
140
|
+
if (!resp.ok)
|
|
141
|
+
throw new Error(`S3 上传失败: ${resp.status}`);
|
|
142
|
+
const publicUrl = config.publicBaseUrl
|
|
143
|
+
? joinUrl(config.publicBaseUrl, key)
|
|
144
|
+
: url;
|
|
145
|
+
return { url: publicUrl, key };
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.js","sourceRoot":"","sources":["../../../../src/plugins/cache/utils/s3.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,iBAAiB;AAEjB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAc/C,oBAAoB;AACpB,SAAS,SAAS,CAAC,CAAO;IACxB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC/D,OAAO,CACL,CAAC,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE;QAC7B,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QACxB,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QACnB,GAAG;QACH,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpB,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CACJ,CAAA;AACH,CAAC;AAED,yBAAyB;AACzB,SAAS,SAAS,CAAC,IAAqB;IACtC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACxD,CAAC;AAED,yBAAyB;AACzB,SAAS,IAAI,CAAC,GAAoB,EAAE,IAAY;IAC9C,OAAO,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAA;AAChE,CAAC;AAED,sBAAsB;AACtB,SAAS,OAAO,CAAC,GAAoB,EAAE,IAAY;IACj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AC5B,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,UAAiB;QAC1B,IAAI,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC;KAC7B,CAAC,CAAA;IACF,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IAExD,MAAM,SAAS,GAAG,MAAM,CAAC,aAAa;QACpC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC;QACpC,CAAC,CAAC,GAAG,CAAA;IACP,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** WebDAV 配置接口 */
|
|
2
|
+
export interface WebDavConfig {
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
username?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
basePath?: string;
|
|
7
|
+
publicBaseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 上传文件到 WebDAV
|
|
11
|
+
*/
|
|
12
|
+
export declare function uploadToWebDav(buffer: Buffer, filename: string, mime: string, config: WebDavConfig): Promise<{
|
|
13
|
+
url: string;
|
|
14
|
+
key: string;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=webdav.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webdav.d.ts","sourceRoot":"","sources":["../../../../src/plugins/cache/utils/webdav.ts"],"names":[],"mappings":"AAGA,kBAAkB;AAClB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AA2CD;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CA4BvC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// WebDAV 工具模块
|
|
2
|
+
// WebDAV 存储的上传工具函数
|
|
3
|
+
/** Base64 编码 */
|
|
4
|
+
function b64(str) {
|
|
5
|
+
return Buffer.from(str, 'utf8').toString('base64');
|
|
6
|
+
}
|
|
7
|
+
/** 去除尾部斜杠 */
|
|
8
|
+
function trimSlash(s) {
|
|
9
|
+
return s.replace(/\/+$/, '');
|
|
10
|
+
}
|
|
11
|
+
/** URL 编码路径 */
|
|
12
|
+
function encodePath(path) {
|
|
13
|
+
return path.split('/').map(encodeURIComponent).join('/');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 确保 WebDAV 基础路径存在(创建必要的目录)
|
|
17
|
+
*/
|
|
18
|
+
async function ensureWebDavBasePath(config) {
|
|
19
|
+
const base = (config.basePath || '').replace(/^\/+|\/+$/g, '');
|
|
20
|
+
if (!base)
|
|
21
|
+
return;
|
|
22
|
+
const segments = base.split('/').filter(Boolean);
|
|
23
|
+
let current = '';
|
|
24
|
+
for (const seg of segments) {
|
|
25
|
+
current = current ? `${current}/${seg}` : seg;
|
|
26
|
+
const url = `${trimSlash(config.endpoint)}/${encodePath(current)}`;
|
|
27
|
+
try {
|
|
28
|
+
await fetch(url, {
|
|
29
|
+
method: 'MKCOL',
|
|
30
|
+
headers: {
|
|
31
|
+
'Authorization': `Basic ${b64(`${config.username}:${config.password}`)}`
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// 忽略错误(目录可能已存在)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 上传文件到 WebDAV
|
|
42
|
+
*/
|
|
43
|
+
export async function uploadToWebDav(buffer, filename, mime, config) {
|
|
44
|
+
if (!config.endpoint || !config.username || !config.password) {
|
|
45
|
+
throw new Error('WebDAV 缺少必要配置');
|
|
46
|
+
}
|
|
47
|
+
await ensureWebDavBasePath(config);
|
|
48
|
+
const remotePath = config.basePath
|
|
49
|
+
? `${config.basePath.replace(/\/+$/, '')}/${filename}`
|
|
50
|
+
: filename;
|
|
51
|
+
const url = `${trimSlash(config.endpoint)}/${encodePath(remotePath)}`;
|
|
52
|
+
const headers = {
|
|
53
|
+
'Authorization': `Basic ${b64(`${config.username}:${config.password}`)}`,
|
|
54
|
+
};
|
|
55
|
+
if (mime)
|
|
56
|
+
headers['Content-Type'] = mime;
|
|
57
|
+
const res = await fetch(url, {
|
|
58
|
+
method: 'PUT',
|
|
59
|
+
headers: headers,
|
|
60
|
+
body: new Uint8Array(buffer)
|
|
61
|
+
});
|
|
62
|
+
if (!res.ok)
|
|
63
|
+
throw new Error(`WebDAV 上传失败: ${res.status}`);
|
|
64
|
+
const publicUrl = config.publicBaseUrl
|
|
65
|
+
? `${trimSlash(config.publicBaseUrl)}/${encodePath(remotePath)}`
|
|
66
|
+
: url;
|
|
67
|
+
return { url: publicUrl, key: remotePath };
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=webdav.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webdav.js","sourceRoot":"","sources":["../../../../src/plugins/cache/utils/webdav.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,mBAAmB;AAWnB,gBAAgB;AAChB,SAAS,GAAG,CAAC,GAAW;IACtB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AACpD,CAAC;AAED,aAAa;AACb,SAAS,SAAS,CAAC,CAAS;IAC1B,OAAO,CAAC,CA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C5C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConnectorDefinition } from '../../core';
|
|
2
|
+
/** Chat API 连接器定义 */
|
|
3
|
+
declare const ChatApiConnector: ConnectorDefinition;
|
|
4
|
+
declare const _default: import("../../core").PluginDefinition;
|
|
5
|
+
export default _default;
|
|
6
|
+
export { ChatApiConnector };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/connector-chat-api/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAgF,MAAM,YAAY,CAAA;AAsZnI,qBAAqB;AACrB,QAAA,MAAM,gBAAgB,EAAE,mBAiCvB,CAAA;;AAED,wBAWE;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
// Chat API 连接器插件
|
|
2
|
+
// 支持 OpenAI Chat Completions 兼容格式,从回复中提取多媒体内容
|
|
3
|
+
import { definePlugin } from '../../core';
|
|
4
|
+
/** Chat API 配置字段 */
|
|
5
|
+
const chatApiFields = [
|
|
6
|
+
{
|
|
7
|
+
key: 'apiUrl',
|
|
8
|
+
label: 'API URL',
|
|
9
|
+
type: 'text',
|
|
10
|
+
required: true,
|
|
11
|
+
default: 'https://api.openai.com/v1/chat/completions',
|
|
12
|
+
placeholder: 'https://api.openai.com/v1/chat/completions',
|
|
13
|
+
description: 'Chat Completions 兼容的 API 端点'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
key: 'apiKey',
|
|
17
|
+
label: 'API Key',
|
|
18
|
+
type: 'password',
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: 'model',
|
|
23
|
+
label: '模型',
|
|
24
|
+
type: 'text',
|
|
25
|
+
required: true,
|
|
26
|
+
default: 'gpt-4o',
|
|
27
|
+
placeholder: 'gpt-4o',
|
|
28
|
+
description: '模型名称'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: 'systemPrompt',
|
|
32
|
+
label: '系统提示词',
|
|
33
|
+
type: 'textarea',
|
|
34
|
+
default: 'You are a helpful assistant that generates images. Please respond with image URLs.',
|
|
35
|
+
description: '系统提示词,用于引导模型生成多媒体内容'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: 'extractMode',
|
|
39
|
+
label: '提取模式',
|
|
40
|
+
type: 'select',
|
|
41
|
+
default: 'auto',
|
|
42
|
+
options: [
|
|
43
|
+
{ label: '自动检测', value: 'auto' },
|
|
44
|
+
{ label: 'URL 提取', value: 'url' },
|
|
45
|
+
{ label: 'Markdown 图片', value: 'markdown' },
|
|
46
|
+
{ label: 'Base64 图片', value: 'base64' },
|
|
47
|
+
{ label: '纯文本返回', value: 'text' }
|
|
48
|
+
],
|
|
49
|
+
description: '从回复中提取多媒体内容的方式'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: 'temperature',
|
|
53
|
+
label: '温度',
|
|
54
|
+
type: 'number',
|
|
55
|
+
default: 0.7,
|
|
56
|
+
description: '生成随机性,0-2 之间'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: 'topP',
|
|
60
|
+
label: 'Top P',
|
|
61
|
+
type: 'number',
|
|
62
|
+
default: 1,
|
|
63
|
+
description: '核采样阈值,0-1 之间'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: 'presencePenalty',
|
|
67
|
+
label: '存在惩罚',
|
|
68
|
+
type: 'number',
|
|
69
|
+
default: 0,
|
|
70
|
+
description: '存在惩罚,-2.0 到 2.0 之间'
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: 'frequencyPenalty',
|
|
74
|
+
label: '频率惩罚',
|
|
75
|
+
type: 'number',
|
|
76
|
+
default: 0,
|
|
77
|
+
description: '频率惩罚,-2.0 到 2.0 之间'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: 'stream',
|
|
81
|
+
label: '流式响应',
|
|
82
|
+
type: 'boolean',
|
|
83
|
+
default: false,
|
|
84
|
+
description: '是否启用流式传输'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: 'maxTokens',
|
|
88
|
+
label: '最大 Token 数',
|
|
89
|
+
type: 'number',
|
|
90
|
+
default: 40960,
|
|
91
|
+
description: '回复的最大 token 数量'
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: 'timeout',
|
|
95
|
+
label: '超时时间(秒)',
|
|
96
|
+
type: 'number',
|
|
97
|
+
default: 360
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
/** 卡片展示字段 */
|
|
101
|
+
const chatApiCardFields = [
|
|
102
|
+
{ source: 'connectorConfig', key: 'model', label: '模型' }
|
|
103
|
+
];
|
|
104
|
+
/**
|
|
105
|
+
* 检查是否为有效 URL
|
|
106
|
+
*/
|
|
107
|
+
function isValidUrl(url) {
|
|
108
|
+
try {
|
|
109
|
+
new URL(url);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 检查 URL 是否可能是多媒体资源
|
|
118
|
+
*/
|
|
119
|
+
function isMediaUrl(url) {
|
|
120
|
+
const mediaExtensions = [
|
|
121
|
+
// 图片
|
|
122
|
+
'.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg', '.bmp', '.ico',
|
|
123
|
+
// 视频
|
|
124
|
+
'.mp4', '.webm', '.avi', '.mov', '.mkv',
|
|
125
|
+
// 音频
|
|
126
|
+
'.mp3', '.wav', '.ogg', '.flac', '.m4a'
|
|
127
|
+
];
|
|
128
|
+
const lowerUrl = url.toLowerCase();
|
|
129
|
+
// 检查扩展名
|
|
130
|
+
if (mediaExtensions.some(ext => lowerUrl.includes(ext))) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
// 检查常见的图片托管服务
|
|
134
|
+
const imageHosts = [
|
|
135
|
+
'videos.openai.com',
|
|
136
|
+
'imgur.com', 'i.imgur.com',
|
|
137
|
+
'cdn.discordapp.com',
|
|
138
|
+
'media.discordapp.net',
|
|
139
|
+
'pbs.twimg.com',
|
|
140
|
+
'oaidalleapiprodscus.blob.core.windows.net', // OpenAI DALL-E
|
|
141
|
+
'replicate.delivery', // Replicate
|
|
142
|
+
'storage.googleapis.com'
|
|
143
|
+
];
|
|
144
|
+
if (imageHosts.some(host => lowerUrl.includes(host))) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 根据 URL 判断媒体类型
|
|
151
|
+
*/
|
|
152
|
+
function getMediaKind(url) {
|
|
153
|
+
const lowerUrl = url.toLowerCase();
|
|
154
|
+
if (lowerUrl.includes('videos.openai.com')) {
|
|
155
|
+
return 'video';
|
|
156
|
+
}
|
|
157
|
+
const videoExtensions = ['.mp4', '.webm', '.avi', '.mov', '.mkv'];
|
|
158
|
+
if (videoExtensions.some(ext => lowerUrl.includes(ext))) {
|
|
159
|
+
return 'video';
|
|
160
|
+
}
|
|
161
|
+
const audioExtensions = ['.mp3', '.wav', '.ogg', '.flac', '.m4a'];
|
|
162
|
+
if (audioExtensions.some(ext => lowerUrl.includes(ext))) {
|
|
163
|
+
return 'audio';
|
|
164
|
+
}
|
|
165
|
+
return 'image';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 从回复内容中提取多媒体资源
|
|
169
|
+
* 使用 Set 确保 URL 不重复
|
|
170
|
+
*/
|
|
171
|
+
function extractMediaFromContent(content, mode) {
|
|
172
|
+
const assets = [];
|
|
173
|
+
const seenUrls = new Set();
|
|
174
|
+
/** 添加资源(自动去重) */
|
|
175
|
+
const addAsset = (asset) => {
|
|
176
|
+
const key = asset.url || asset.content || '';
|
|
177
|
+
if (seenUrls.has(key))
|
|
178
|
+
return false;
|
|
179
|
+
seenUrls.add(key);
|
|
180
|
+
assets.push(asset);
|
|
181
|
+
return true;
|
|
182
|
+
};
|
|
183
|
+
if (mode === 'text') {
|
|
184
|
+
// 纯文本模式,直接返回文本
|
|
185
|
+
return [{
|
|
186
|
+
kind: 'text',
|
|
187
|
+
content: content
|
|
188
|
+
}];
|
|
189
|
+
}
|
|
190
|
+
if (mode === 'auto' || mode === 'markdown') {
|
|
191
|
+
// 提取 Markdown 图片: 
|
|
192
|
+
const markdownImageRegex = /!\[([^\]]*)\]\(([^)]+)\)/g;
|
|
193
|
+
let match;
|
|
194
|
+
while ((match = markdownImageRegex.exec(content)) !== null) {
|
|
195
|
+
const url = match[2];
|
|
196
|
+
if (isValidUrl(url)) {
|
|
197
|
+
addAsset({
|
|
198
|
+
kind: 'image',
|
|
199
|
+
url: url,
|
|
200
|
+
meta: { alt: match[1] }
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// 提取 HTML 视频/图片标签 (包括在代码块中的)
|
|
205
|
+
const htmlVideoRegex = /<video[^>]+src=(['"])(.*?)\1/gi;
|
|
206
|
+
while ((match = htmlVideoRegex.exec(content)) !== null) {
|
|
207
|
+
const url = match[2];
|
|
208
|
+
if (isValidUrl(url)) {
|
|
209
|
+
addAsset({
|
|
210
|
+
kind: 'video',
|
|
211
|
+
url: url
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const htmlImageRegex = /<img[^>]+src=(['"])(.*?)\1/gi;
|
|
216
|
+
while ((match = htmlImageRegex.exec(content)) !== null) {
|
|
217
|
+
const url = match[2];
|
|
218
|
+
if (isValidUrl(url)) {
|
|
219
|
+
addAsset({
|
|
220
|
+
kind: 'image',
|
|
221
|
+
url: url
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (mode === 'auto' || mode === 'url') {
|
|
227
|
+
// 提取独立的 URL(排除已提取的)
|
|
228
|
+
const urlRegex = /https?:\/\/[^\s<>"{}|\\^`[\]']+/g;
|
|
229
|
+
let match;
|
|
230
|
+
while ((match = urlRegex.exec(content)) !== null) {
|
|
231
|
+
const url = match[0];
|
|
232
|
+
if (!seenUrls.has(url) && isMediaUrl(url)) {
|
|
233
|
+
const kind = getMediaKind(url);
|
|
234
|
+
addAsset({
|
|
235
|
+
kind,
|
|
236
|
+
url: url
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (mode === 'auto' || mode === 'base64') {
|
|
242
|
+
// 提取 base64 图片: data:image/xxx;base64,xxx
|
|
243
|
+
const base64Regex = /data:(image\/[^;]+);base64,([A-Za-z0-9+/=]+)/g;
|
|
244
|
+
let match;
|
|
245
|
+
while ((match = base64Regex.exec(content)) !== null) {
|
|
246
|
+
addAsset({
|
|
247
|
+
kind: 'image',
|
|
248
|
+
url: match[0],
|
|
249
|
+
mime: match[1]
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// 如果没有提取到任何多媒体,返回文本内容
|
|
254
|
+
if (assets.length === 0) {
|
|
255
|
+
return [{
|
|
256
|
+
kind: 'text',
|
|
257
|
+
content: content
|
|
258
|
+
}];
|
|
259
|
+
}
|
|
260
|
+
return assets;
|
|
261
|
+
}
|
|
262
|
+
/** Chat API 生成函数 */
|
|
263
|
+
async function generate(ctx, config, files, prompt) {
|
|
264
|
+
const { apiUrl, apiKey, model, systemPrompt = '', extractMode = 'auto', temperature = 0.7, topP = 1, presencePenalty = 0, frequencyPenalty = 0, stream = false, maxTokens = 40960, timeout = 360 } = config;
|
|
265
|
+
// 验证必需配置
|
|
266
|
+
if (!apiUrl) {
|
|
267
|
+
throw new Error('API URL 未配置,请在渠道设置中配置 API URL');
|
|
268
|
+
}
|
|
269
|
+
if (!apiKey) {
|
|
270
|
+
throw new Error('API Key 未配置,请在渠道设置中配置 API Key');
|
|
271
|
+
}
|
|
272
|
+
if (!model) {
|
|
273
|
+
throw new Error('模型未配置,请在渠道设置中配置模型名称');
|
|
274
|
+
}
|
|
275
|
+
// 构建消息
|
|
276
|
+
const messages = [];
|
|
277
|
+
if (systemPrompt) {
|
|
278
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
279
|
+
}
|
|
280
|
+
// 构建用户消息(支持多模态输入)
|
|
281
|
+
if (files.length > 0) {
|
|
282
|
+
const content = [{ type: 'text', text: prompt }];
|
|
283
|
+
for (const file of files) {
|
|
284
|
+
if (file.mime.startsWith('image/')) {
|
|
285
|
+
// 将图片转为 base64
|
|
286
|
+
const base64 = Buffer.from(file.data).toString('base64');
|
|
287
|
+
content.push({
|
|
288
|
+
type: 'image_url',
|
|
289
|
+
image_url: {
|
|
290
|
+
url: `data:${file.mime};base64,${base64}`
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
messages.push({ role: 'user', content });
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
messages.push({ role: 'user', content: prompt });
|
|
299
|
+
}
|
|
300
|
+
// 发送请求
|
|
301
|
+
const response = await ctx.http.post(apiUrl, {
|
|
302
|
+
model,
|
|
303
|
+
messages,
|
|
304
|
+
temperature: Number(temperature),
|
|
305
|
+
top_p: Number(topP),
|
|
306
|
+
presence_penalty: Number(presencePenalty),
|
|
307
|
+
frequency_penalty: Number(frequencyPenalty),
|
|
308
|
+
stream: Boolean(stream),
|
|
309
|
+
max_tokens: Number(maxTokens)
|
|
310
|
+
}, {
|
|
311
|
+
headers: {
|
|
312
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
313
|
+
'Content-Type': 'application/json',
|
|
314
|
+
'Accept': '*/*'
|
|
315
|
+
},
|
|
316
|
+
timeout: timeout * 1000,
|
|
317
|
+
responseType: stream ? 'text' : 'json'
|
|
318
|
+
});
|
|
319
|
+
let content = '';
|
|
320
|
+
if (stream) {
|
|
321
|
+
// 处理流式响应
|
|
322
|
+
const lines = response.split('\n');
|
|
323
|
+
let isSSE = false;
|
|
324
|
+
for (const line of lines) {
|
|
325
|
+
if (line.trim().startsWith('data: ')) {
|
|
326
|
+
isSSE = true;
|
|
327
|
+
const data = line.trim().slice(6);
|
|
328
|
+
if (data === '[DONE]')
|
|
329
|
+
break;
|
|
330
|
+
try {
|
|
331
|
+
const json = JSON.parse(data);
|
|
332
|
+
const delta = json.choices?.[0]?.delta?.content;
|
|
333
|
+
if (delta)
|
|
334
|
+
content += delta;
|
|
335
|
+
}
|
|
336
|
+
catch (e) {
|
|
337
|
+
// ignore parse error
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// 如果没有解析出 SSE 内容(可能是服务端不支持流式或返回了错误 JSON),尝试直接解析
|
|
342
|
+
if (!isSSE && !content) {
|
|
343
|
+
try {
|
|
344
|
+
const json = JSON.parse(response);
|
|
345
|
+
content = json.choices?.[0]?.message?.content || '';
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
// ignore
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
// 提取回复内容
|
|
354
|
+
const choice = response.choices?.[0];
|
|
355
|
+
if (!choice) {
|
|
356
|
+
throw new Error('No response from Chat API');
|
|
357
|
+
}
|
|
358
|
+
content = choice.message?.content || '';
|
|
359
|
+
}
|
|
360
|
+
// 根据提取模式处理回复
|
|
361
|
+
return extractMediaFromContent(content, extractMode);
|
|
362
|
+
}
|
|
363
|
+
/** Chat API 连接器定义 */
|
|
364
|
+
const ChatApiConnector = {
|
|
365
|
+
id: 'chat-api',
|
|
366
|
+
name: 'Chat API',
|
|
367
|
+
supportedTypes: ['image', 'audio', 'video'],
|
|
368
|
+
fields: chatApiFields,
|
|
369
|
+
cardFields: chatApiCardFields,
|
|
370
|
+
generate,
|
|
371
|
+
/** 获取请求日志 */
|
|
372
|
+
getRequestLog(config, files, prompt) {
|
|
373
|
+
const { apiUrl, model, systemPrompt = '', extractMode = 'auto', temperature = 0.7, maxTokens = 40960 } = config;
|
|
374
|
+
return {
|
|
375
|
+
endpoint: apiUrl?.split('?')[0],
|
|
376
|
+
model,
|
|
377
|
+
prompt,
|
|
378
|
+
fileCount: files.length,
|
|
379
|
+
parameters: {
|
|
380
|
+
systemPrompt: systemPrompt ? `${systemPrompt.slice(0, 100)}${systemPrompt.length > 100 ? '...' : ''}` : undefined,
|
|
381
|
+
extractMode,
|
|
382
|
+
temperature,
|
|
383
|
+
maxTokens,
|
|
384
|
+
hasImages: files.some(f => f.mime.startsWith('image/'))
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
export default definePlugin({
|
|
390
|
+
id: 'connector-chat-api',
|
|
391
|
+
name: 'Chat API 连接器',
|
|
392
|
+
description: 'OpenAI Chat Completions 兼容的多媒体提取连接器',
|
|
393
|
+
version: '1.0.0',
|
|
394
|
+
connector: ChatApiConnector,
|
|
395
|
+
async onLoad(ctx) {
|
|
396
|
+
ctx.logger.info('Chat API connector loaded');
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
export { ChatApiConnector };
|
|
400
|
+
//# sourceMappingURL=index.js.map
|