koishi-plugin-media-luna 0.0.11 → 0.0.12
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/lib/core/api/preset-api.d.ts.map +1 -1
- package/lib/core/api/preset-api.js +20 -0
- package/lib/core/api/preset-api.js.map +1 -1
- package/lib/core/medialuna.service.d.ts.map +1 -1
- package/lib/core/medialuna.service.js +6 -1
- package/lib/core/medialuna.service.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/README.md +6 -0
- package/lib/plugins/connector-comfyui/index.d.ts +7 -0
- package/lib/plugins/connector-comfyui/index.d.ts.map +1 -0
- package/lib/plugins/connector-comfyui/index.js +221 -0
- package/lib/plugins/connector-comfyui/index.js.map +1 -0
- package/lib/plugins/connector-midjourney/index.d.ts +7 -0
- package/lib/plugins/connector-midjourney/index.d.ts.map +1 -0
- package/lib/plugins/connector-midjourney/index.js +186 -0
- package/lib/plugins/connector-midjourney/index.js.map +1 -0
- package/lib/plugins/connector-modelscope/index.d.ts +7 -0
- package/lib/plugins/connector-modelscope/index.d.ts.map +1 -0
- package/lib/plugins/connector-modelscope/index.js +207 -0
- package/lib/plugins/connector-modelscope/index.js.map +1 -0
- package/lib/plugins/connector-runway/index.d.ts +7 -0
- package/lib/plugins/connector-runway/index.d.ts.map +1 -0
- package/lib/plugins/connector-runway/index.js +178 -0
- package/lib/plugins/connector-runway/index.js.map +1 -0
- package/lib/plugins/connector-stability/index.d.ts +7 -0
- package/lib/plugins/connector-stability/index.d.ts.map +1 -0
- package/lib/plugins/connector-stability/index.js +191 -0
- package/lib/plugins/connector-stability/index.js.map +1 -0
- package/lib/plugins/connector-suno/index.d.ts +7 -0
- package/lib/plugins/connector-suno/index.d.ts.map +1 -0
- package/lib/plugins/connector-suno/index.js +225 -0
- package/lib/plugins/connector-suno/index.js.map +1 -0
- package/lib/plugins/index.d.ts +5 -0
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +11 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/preset/index.d.ts.map +1 -1
- package/lib/plugins/preset/index.js +7 -0
- package/lib/plugins/preset/index.js.map +1 -1
- package/lib/plugins/preset/service.d.ts +2 -0
- package/lib/plugins/preset/service.d.ts.map +1 -1
- package/lib/plugins/preset/service.js +8 -0
- package/lib/plugins/preset/service.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Midjourney 连接器插件
|
|
3
|
+
// 适配通用 Midjourney API Proxy (如 GoAPI, TTApi, userapi.ai 等)
|
|
4
|
+
// 通常遵循: POST /imagine -> { task_id } -> GET /fetch -> { status, imageUrl }
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MidjourneyConnector = void 0;
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
/** Midjourney 配置字段 */
|
|
9
|
+
const mjFields = [
|
|
10
|
+
{
|
|
11
|
+
key: 'apiUrl',
|
|
12
|
+
label: 'API URL',
|
|
13
|
+
type: 'text',
|
|
14
|
+
required: true,
|
|
15
|
+
default: 'https://api.midjourneyapi.xyz/mj/v2',
|
|
16
|
+
placeholder: 'https://api.midjourneyapi.xyz/mj/v2',
|
|
17
|
+
description: 'MJ Proxy 服务的基础地址'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: 'apiKey',
|
|
21
|
+
label: 'API Key',
|
|
22
|
+
type: 'password',
|
|
23
|
+
required: true,
|
|
24
|
+
description: 'Proxy 服务商提供的 API Key'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
key: 'webhookUrl',
|
|
28
|
+
label: 'Webhook 回调地址',
|
|
29
|
+
type: 'text',
|
|
30
|
+
placeholder: 'https://your-domain.com/mj-webhook',
|
|
31
|
+
description: '可选:用于接收任务完成通知(若服务商支持且您配置了公网回调)'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: 'aspectRatio',
|
|
35
|
+
label: '默认宽高比 (--ar)',
|
|
36
|
+
type: 'text',
|
|
37
|
+
default: '1:1',
|
|
38
|
+
placeholder: '16:9',
|
|
39
|
+
description: '默认宽高比,如 16:9, 9:16, 2:3'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: 'mode',
|
|
43
|
+
label: '模式',
|
|
44
|
+
type: 'select',
|
|
45
|
+
default: 'fast',
|
|
46
|
+
options: [
|
|
47
|
+
{ label: 'Fast (快速)', value: 'fast' },
|
|
48
|
+
{ label: 'Relax (慢速)', value: 'relax' },
|
|
49
|
+
{ label: 'Turbo (极速)', value: 'turbo' }
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: 'timeout',
|
|
54
|
+
label: '超时时间(秒)',
|
|
55
|
+
type: 'number',
|
|
56
|
+
default: 600
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
/** 卡片展示字段 */
|
|
60
|
+
const mjCardFields = [
|
|
61
|
+
{ source: 'connectorConfig', key: 'mode', label: '模式' },
|
|
62
|
+
{ source: 'connectorConfig', key: 'aspectRatio', label: '比例' }
|
|
63
|
+
];
|
|
64
|
+
/** 轮询任务状态 */
|
|
65
|
+
async function pollTask(ctx, fetchUrl, apiKey, timeoutMs) {
|
|
66
|
+
const startTime = Date.now();
|
|
67
|
+
const interval = 3000; // 3秒轮询一次
|
|
68
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
69
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
70
|
+
try {
|
|
71
|
+
const res = await ctx.http.post(fetchUrl, {}, {
|
|
72
|
+
headers: { 'X-API-KEY': apiKey }
|
|
73
|
+
});
|
|
74
|
+
// 适配常见 Proxy 格式
|
|
75
|
+
// GoAPI: { status: 'finished', task_id: '...', task_result: { image_url: '...' } }
|
|
76
|
+
// TTApi: { status: 'SUCCESS', imageUrl: '...' }
|
|
77
|
+
const status = res.status?.toLowerCase();
|
|
78
|
+
if (status === 'finished' || status === 'success' || status === 'completed') {
|
|
79
|
+
const url = res.task_result?.image_url || res.imageUrl || res.url;
|
|
80
|
+
if (url) {
|
|
81
|
+
return [url];
|
|
82
|
+
}
|
|
83
|
+
// 有些返回的是 grid 图片,可能需要进一步分割,这里简化为返回主图
|
|
84
|
+
}
|
|
85
|
+
else if (status === 'failed' || status === 'error') {
|
|
86
|
+
throw new Error(`MJ Task Failed: ${JSON.stringify(res)}`);
|
|
87
|
+
}
|
|
88
|
+
// continue polling if 'processing', 'pending', 'started'
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
// ignore network glitch, continue polling
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
throw new Error('Midjourney task timeout');
|
|
95
|
+
}
|
|
96
|
+
/** Midjourney 生成函数 */
|
|
97
|
+
async function generate(ctx, config, files, prompt) {
|
|
98
|
+
const { apiUrl, apiKey, webhookUrl, aspectRatio = '1:1', mode = 'fast', timeout = 600 } = config;
|
|
99
|
+
const baseUrl = apiUrl.replace(/\/$/, '');
|
|
100
|
+
// 1. 发起 Imagine 任务
|
|
101
|
+
// 注意:不同 Proxy 的 API 路径和参数可能略有不同,这里适配一种通用格式
|
|
102
|
+
// 通常是 POST /imagine
|
|
103
|
+
const imagineUrl = `${baseUrl}/imagine`;
|
|
104
|
+
// 拼接参数到 prompt
|
|
105
|
+
let fullPrompt = prompt;
|
|
106
|
+
if (aspectRatio && !fullPrompt.includes('--ar')) {
|
|
107
|
+
fullPrompt += ` --ar ${aspectRatio}`;
|
|
108
|
+
}
|
|
109
|
+
// 处理垫图 (Image Prompt)
|
|
110
|
+
// 如果有输入图片,需要先上传或者直接把 URL 拼在 prompt 前面
|
|
111
|
+
// 由于 Proxy 通常只接受 URL,这里假设 files 已经被中间件上传并替换为了 url (需要 storage-input 中间件配合)
|
|
112
|
+
// 这里暂时只处理文本 Prompt
|
|
113
|
+
const body = {
|
|
114
|
+
prompt: fullPrompt,
|
|
115
|
+
process_mode: mode
|
|
116
|
+
};
|
|
117
|
+
if (webhookUrl)
|
|
118
|
+
body.webhook_url = webhookUrl;
|
|
119
|
+
let taskId;
|
|
120
|
+
try {
|
|
121
|
+
const res = await ctx.http.post(imagineUrl, body, {
|
|
122
|
+
headers: {
|
|
123
|
+
'Content-Type': 'application/json',
|
|
124
|
+
'X-API-KEY': apiKey
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
taskId = res.task_id || res.taskId || res.id;
|
|
128
|
+
if (!taskId) {
|
|
129
|
+
throw new Error(`Failed to start MJ task: ${JSON.stringify(res)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (e instanceof Error)
|
|
134
|
+
throw new Error(`MJ API Error: ${e.message}`);
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
// 2. 轮询结果 (如果没有 Webhook 或需要同步等待)
|
|
138
|
+
// POST /fetch 或 GET /task/{id}
|
|
139
|
+
const fetchUrl = `${baseUrl}/result`; // 或者是 /fetch
|
|
140
|
+
// 这里的轮询逻辑需要根据具体 Proxy 的协议调整
|
|
141
|
+
// 这是一个基于 GoAPI 风格的示例
|
|
142
|
+
const imageUrls = await pollTask(ctx, fetchUrl, apiKey, timeout * 1000);
|
|
143
|
+
return imageUrls.map(url => ({
|
|
144
|
+
kind: 'image',
|
|
145
|
+
url,
|
|
146
|
+
mime: 'image/png', // MJ 通常返回 PNG 或 WebP
|
|
147
|
+
meta: {
|
|
148
|
+
taskId,
|
|
149
|
+
prompt: fullPrompt
|
|
150
|
+
}
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
/** Midjourney 连接器定义 */
|
|
154
|
+
const MidjourneyConnector = {
|
|
155
|
+
id: 'midjourney',
|
|
156
|
+
name: 'Midjourney (Proxy)',
|
|
157
|
+
supportedTypes: ['image'],
|
|
158
|
+
fields: mjFields,
|
|
159
|
+
cardFields: mjCardFields,
|
|
160
|
+
generate,
|
|
161
|
+
getRequestLog(config, files, prompt) {
|
|
162
|
+
const { apiUrl, aspectRatio, mode } = config;
|
|
163
|
+
return {
|
|
164
|
+
endpoint: apiUrl,
|
|
165
|
+
model: 'midjourney-v6', // MJ 版本通常包含在 prompt 里,这里写死 v6 示意
|
|
166
|
+
prompt,
|
|
167
|
+
fileCount: files.length,
|
|
168
|
+
parameters: {
|
|
169
|
+
aspectRatio,
|
|
170
|
+
mode
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
exports.MidjourneyConnector = MidjourneyConnector;
|
|
176
|
+
exports.default = (0, core_1.definePlugin)({
|
|
177
|
+
id: 'connector-midjourney',
|
|
178
|
+
name: 'Midjourney 连接器',
|
|
179
|
+
description: '适配通用 Midjourney API Proxy 服务',
|
|
180
|
+
version: '1.0.0',
|
|
181
|
+
connector: MidjourneyConnector,
|
|
182
|
+
async onLoad(ctx) {
|
|
183
|
+
ctx.logger.info('Midjourney connector loaded');
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/connector-midjourney/index.ts"],"names":[],"mappings":";AAAA,mBAAmB;AACnB,2DAA2D;AAC3D,2EAA2E;;;AAG3E,qCAAyC;AAGzC,sBAAsB;AACtB,MAAM,QAAQ,GAAqB;IACjC;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,qCAAqC;QAC9C,WAAW,EAAE,qCAAqC;QAClD,WAAW,EAAE,kBAAkB;KAChC;IACD;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;QAC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AAC,CAAA;IAChD,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConnectorDefinition } from '../../core';
|
|
2
|
+
/** ModelScope 连接器定义 */
|
|
3
|
+
declare const ModelScopeConnector: ConnectorDefinition;
|
|
4
|
+
declare const _default: import("../../core").PluginDefinition;
|
|
5
|
+
export default _default;
|
|
6
|
+
export { ModelScopeConnector };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/connector-modelscope/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAgF,MAAM,YAAY,CAAA;AA0MnI,uBAAuB;AACvB,QAAA,MAAM,mBAAmB,EAAE,mBAkB1B,CAAA;;AAED,wBASE;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ModelScope (魔搭) 连接器插件
|
|
3
|
+
// 适配 ModelScope Inference API
|
|
4
|
+
// 文档: https://modelscope.cn/docs/inference-api
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ModelScopeConnector = void 0;
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
/** ModelScope 配置字段 */
|
|
9
|
+
const modelscopeFields = [
|
|
10
|
+
{
|
|
11
|
+
key: 'apiUrl',
|
|
12
|
+
label: 'API URL',
|
|
13
|
+
type: 'text',
|
|
14
|
+
required: true,
|
|
15
|
+
default: 'https://api-inference.modelscope.cn',
|
|
16
|
+
placeholder: 'https://api-inference.modelscope.cn'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
key: 'apiKey',
|
|
20
|
+
label: 'API Key',
|
|
21
|
+
type: 'password',
|
|
22
|
+
required: true,
|
|
23
|
+
description: 'ModelScope Token'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: 'model',
|
|
27
|
+
label: '模型',
|
|
28
|
+
type: 'text',
|
|
29
|
+
required: true,
|
|
30
|
+
default: 'Tongyi-MAI/Z-Image-Turbo',
|
|
31
|
+
placeholder: 'Tongyi-MAI/Z-Image-Turbo',
|
|
32
|
+
description: 'ModelScope Model-Id'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: 'loras',
|
|
36
|
+
label: 'LoRA 模型',
|
|
37
|
+
type: 'text',
|
|
38
|
+
placeholder: '可选:LoRA Repo ID',
|
|
39
|
+
description: '可选:LoRA 模型 ID (支持 JSON 格式的多 LoRA 配置)'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: 'negativePrompt',
|
|
43
|
+
label: '负面提示词',
|
|
44
|
+
type: 'textarea',
|
|
45
|
+
description: '可选:负面提示词'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: 'width',
|
|
49
|
+
label: '宽度',
|
|
50
|
+
type: 'number',
|
|
51
|
+
default: 1024
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: 'height',
|
|
55
|
+
label: '高度',
|
|
56
|
+
type: 'number',
|
|
57
|
+
default: 1024
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: 'numImages',
|
|
61
|
+
label: '生成数量',
|
|
62
|
+
type: 'number',
|
|
63
|
+
default: 1
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: 'seed',
|
|
67
|
+
label: '种子',
|
|
68
|
+
type: 'number',
|
|
69
|
+
placeholder: '留空随机'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
key: 'timeout',
|
|
73
|
+
label: '超时时间(秒)',
|
|
74
|
+
type: 'number',
|
|
75
|
+
default: 300
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
/** 卡片展示字段 */
|
|
79
|
+
const modelscopeCardFields = [
|
|
80
|
+
{ source: 'connectorConfig', key: 'model', label: '模型' }
|
|
81
|
+
];
|
|
82
|
+
/** ModelScope 生成函数 */
|
|
83
|
+
async function generate(ctx, config, files, prompt) {
|
|
84
|
+
const { apiUrl, apiKey, model = 'Tongyi-MAI/Z-Image-Turbo', loras, negativePrompt, width = 1024, height = 1024, numImages = 1, seed, timeout = 300 } = config;
|
|
85
|
+
const baseUrl = apiUrl.replace(/\/$/, '');
|
|
86
|
+
// 1. 发起任务
|
|
87
|
+
// POST /v1/images/generations
|
|
88
|
+
const endpoint = `${baseUrl}/v1/images/generations`;
|
|
89
|
+
const body = {
|
|
90
|
+
model: model,
|
|
91
|
+
prompt: prompt,
|
|
92
|
+
n: Number(numImages),
|
|
93
|
+
size: `${width}x${height}` // 适配标准格式
|
|
94
|
+
};
|
|
95
|
+
// ModelScope 特有参数通常直接放在 body 顶层或 parameters 中,
|
|
96
|
+
// 提供的示例是直接放在顶层。
|
|
97
|
+
// 但 API 文档指出,除了 model/prompt 外,其他参数可能需要根据模型不同调整
|
|
98
|
+
if (negativePrompt)
|
|
99
|
+
body.negative_prompt = negativePrompt;
|
|
100
|
+
if (seed)
|
|
101
|
+
body.seed = Number(seed);
|
|
102
|
+
// 处理 LoRAs
|
|
103
|
+
if (loras) {
|
|
104
|
+
try {
|
|
105
|
+
// 尝试解析为 JSON (多 LoRA 配置)
|
|
106
|
+
body.loras = JSON.parse(loras);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// 否则作为单字符串 (单 LoRA)
|
|
110
|
+
body.loras = loras;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 处理输入图片 (图生图)
|
|
114
|
+
const imageFile = files.find(f => f.mime.startsWith('image/'));
|
|
115
|
+
if (imageFile) {
|
|
116
|
+
const base64 = Buffer.from(imageFile.data).toString('base64');
|
|
117
|
+
body.image = `data:${imageFile.mime};base64,${base64}`;
|
|
118
|
+
// 如果是 img2img,通常需要 task_type 或者是不同的 endpoint?
|
|
119
|
+
// ModelScope Inference API 对 img2img 的支持视模型而定
|
|
120
|
+
}
|
|
121
|
+
let taskId;
|
|
122
|
+
try {
|
|
123
|
+
const res = await ctx.http.post(endpoint, body, {
|
|
124
|
+
headers: {
|
|
125
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
126
|
+
'Content-Type': 'application/json',
|
|
127
|
+
'X-ModelScope-Async-Mode': 'true' // 强制异步模式
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
taskId = res.task_id;
|
|
131
|
+
if (!taskId)
|
|
132
|
+
throw new Error(`Invalid ModelScope response: ${JSON.stringify(res)}`);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
if (e.response?.data) {
|
|
136
|
+
throw new Error(`ModelScope API Error: ${JSON.stringify(e.response.data)}`);
|
|
137
|
+
}
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
// 2. 轮询结果
|
|
141
|
+
const startTime = Date.now();
|
|
142
|
+
const interval = 3000;
|
|
143
|
+
while (Date.now() - startTime < timeout * 1000) {
|
|
144
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
145
|
+
try {
|
|
146
|
+
const res = await ctx.http.get(`${baseUrl}/v1/tasks/${taskId}`, {
|
|
147
|
+
headers: {
|
|
148
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
149
|
+
'X-ModelScope-Task-Type': 'image_generation'
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const status = res.task_status; // SUCCEED, FAILED, RUNNING, PENDING
|
|
153
|
+
if (status === 'SUCCEED') {
|
|
154
|
+
const urls = res.output_images;
|
|
155
|
+
if (!urls || urls.length === 0)
|
|
156
|
+
throw new Error('Task succeeded but no images found');
|
|
157
|
+
return urls.map((url) => ({
|
|
158
|
+
kind: 'image',
|
|
159
|
+
url: url,
|
|
160
|
+
mime: 'image/jpeg', // 通常是 jpg/png
|
|
161
|
+
meta: {
|
|
162
|
+
model,
|
|
163
|
+
taskId
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
else if (status === 'FAILED') {
|
|
168
|
+
throw new Error(`ModelScope Task Failed: ${res.message || 'Unknown error'}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
// ignore
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
throw new Error('ModelScope task timeout');
|
|
176
|
+
}
|
|
177
|
+
/** ModelScope 连接器定义 */
|
|
178
|
+
const ModelScopeConnector = {
|
|
179
|
+
id: 'modelscope',
|
|
180
|
+
name: 'ModelScope (魔搭)',
|
|
181
|
+
supportedTypes: ['image'],
|
|
182
|
+
fields: modelscopeFields,
|
|
183
|
+
cardFields: modelscopeCardFields,
|
|
184
|
+
generate,
|
|
185
|
+
getRequestLog(config, files, prompt) {
|
|
186
|
+
const { apiUrl, model } = config;
|
|
187
|
+
return {
|
|
188
|
+
endpoint: apiUrl,
|
|
189
|
+
model,
|
|
190
|
+
prompt,
|
|
191
|
+
fileCount: files.length,
|
|
192
|
+
parameters: {}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
exports.ModelScopeConnector = ModelScopeConnector;
|
|
197
|
+
exports.default = (0, core_1.definePlugin)({
|
|
198
|
+
id: 'connector-modelscope',
|
|
199
|
+
name: 'ModelScope 连接器',
|
|
200
|
+
description: '适配 ModelScope Inference API',
|
|
201
|
+
version: '1.0.0',
|
|
202
|
+
connector: ModelScopeConnector,
|
|
203
|
+
async onLoad(ctx) {
|
|
204
|
+
ctx.logger.info('ModelScope connector loaded');
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/connector-modelscope/index.ts"],"names":[],"mappings":";AAAA,wBAAwB;AACxB,8BAA8B;AAC9B,+CAA+C;;;AAG/C,qCAAyC;AAGzC,sBAAsB;AACtB,MAAM,gBAAgB,GAAqB;I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AAwB;IAC/C,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE,iBAAiB;IACvB,cAAc,EAAE,CAAC,OAAO,CAAC;IACzB,MAAM,EAAE,gBAAgB;IACxB,UAAU,EAAE,oBAAoB;IAChC,QAAQ;IAER,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM;QACjC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QAChC,OAAO;YACL,QAAQ,EAAE,MAAM;YAChB,KAAK;YACL,MAAM;YACN,SAAS,EAAE,KAAK,CAAC,MAAM;YACvB,UAAU,EAAE,EAAE;SACf,CAAA;IACH,CAAC;CACF,CAAA;AAaQ,kDAAmB;AAX5B,kBAAe,IAAA,mBAAY,EAAC;IAC1B,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,6BAA6B;IAC1C,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,mBAAmB;IAC9B,KAAK,CAAC,MAAM,CAAC,GAAG;QACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IAChD,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConnectorDefinition } from '../../core';
|
|
2
|
+
/** Runway 连接器定义 */
|
|
3
|
+
declare const RunwayConnector: ConnectorDefinition;
|
|
4
|
+
declare const _default: import("../../core").PluginDefinition;
|
|
5
|
+
export default _default;
|
|
6
|
+
export { RunwayConnector };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/connector-runway/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAgF,MAAM,YAAY,CAAA;AAyKnI,mBAAmB;AACnB,QAAA,MAAM,eAAe,EAAE,mBAkBtB,CAAA;;AAED,wBASE;AAEF,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Runway 连接器插件
|
|
3
|
+
// 适配 Runway Gen-3 Alpha (第三方/模拟 API)
|
|
4
|
+
// 视频生成通常耗时较长,必须异步轮询
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RunwayConnector = void 0;
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
/** Runway 配置字段 */
|
|
9
|
+
const runwayFields = [
|
|
10
|
+
{
|
|
11
|
+
key: 'apiUrl',
|
|
12
|
+
label: 'API URL',
|
|
13
|
+
type: 'text',
|
|
14
|
+
required: true,
|
|
15
|
+
default: 'https://api.runwayml.com/v1', // 示意地址
|
|
16
|
+
placeholder: 'https://api.your-provider.com/runway',
|
|
17
|
+
description: 'Runway API 基础地址'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: 'apiKey',
|
|
21
|
+
label: 'API Key',
|
|
22
|
+
type: 'password',
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: 'model',
|
|
27
|
+
label: '模型',
|
|
28
|
+
type: 'text',
|
|
29
|
+
default: 'gen-3-alpha',
|
|
30
|
+
placeholder: 'gen-3-alpha, gen-2',
|
|
31
|
+
description: '模型名称'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: 'duration',
|
|
35
|
+
label: '时长 (秒)',
|
|
36
|
+
type: 'select',
|
|
37
|
+
default: '5',
|
|
38
|
+
options: [
|
|
39
|
+
{ label: '5 秒', value: '5' },
|
|
40
|
+
{ label: '10 秒', value: '10' }
|
|
41
|
+
],
|
|
42
|
+
description: '生成视频的时长'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: 'aspectRatio',
|
|
46
|
+
label: '宽高比',
|
|
47
|
+
type: 'select',
|
|
48
|
+
default: '16:9',
|
|
49
|
+
options: [
|
|
50
|
+
{ label: '16:9', value: '16:9' },
|
|
51
|
+
{ label: '9:16', value: '9:16' }
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: 'seed',
|
|
56
|
+
label: '种子',
|
|
57
|
+
type: 'number',
|
|
58
|
+
placeholder: '留空随机'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: 'timeout',
|
|
62
|
+
label: '超时时间(秒)',
|
|
63
|
+
type: 'number',
|
|
64
|
+
default: 600 // 视频生成很慢
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
/** 卡片展示字段 */
|
|
68
|
+
const runwayCardFields = [
|
|
69
|
+
{ source: 'connectorConfig', key: 'model', label: '模型' },
|
|
70
|
+
{ source: 'connectorConfig', key: 'duration', label: '时长' }
|
|
71
|
+
];
|
|
72
|
+
/** Runway 生成函数 */
|
|
73
|
+
async function generate(ctx, config, files, prompt) {
|
|
74
|
+
const { apiUrl, apiKey, model = 'gen-3-alpha', duration = '5', aspectRatio = '16:9', seed, timeout = 600 } = config;
|
|
75
|
+
const baseUrl = apiUrl.replace(/\/$/, '');
|
|
76
|
+
// 1. 发起任务 (POST /image_to_video 或 /text_to_video)
|
|
77
|
+
let endpoint = `${baseUrl}/tasks`; // 假设通用任务接口
|
|
78
|
+
const body = {
|
|
79
|
+
promptText: prompt,
|
|
80
|
+
model: model,
|
|
81
|
+
parameters: {
|
|
82
|
+
durationSeconds: Number(duration),
|
|
83
|
+
aspectRatio: aspectRatio
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
if (seed)
|
|
87
|
+
body.parameters.seed = Number(seed);
|
|
88
|
+
// 处理输入图片 (Gen-3 支持 Image-to-Video)
|
|
89
|
+
const imageFile = files.find(f => f.mime.startsWith('image/'));
|
|
90
|
+
if (imageFile) {
|
|
91
|
+
const base64 = Buffer.from(imageFile.data).toString('base64');
|
|
92
|
+
body.promptImage = `data:${imageFile.mime};base64,${base64}`;
|
|
93
|
+
// 或者需要先上传图片获得 URL,视具体 API 实现而定
|
|
94
|
+
}
|
|
95
|
+
let taskId;
|
|
96
|
+
try {
|
|
97
|
+
const res = await ctx.http.post(endpoint, body, {
|
|
98
|
+
headers: {
|
|
99
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
100
|
+
'Content-Type': 'application/json'
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
taskId = res.id || res.taskId;
|
|
104
|
+
if (!taskId)
|
|
105
|
+
throw new Error(`Invalid Runway response: ${JSON.stringify(res)}`);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (e.response?.data) {
|
|
109
|
+
throw new Error(`Runway API Error: ${JSON.stringify(e.response.data)}`);
|
|
110
|
+
}
|
|
111
|
+
throw e;
|
|
112
|
+
}
|
|
113
|
+
// 2. 轮询结果
|
|
114
|
+
const startTime = Date.now();
|
|
115
|
+
const interval = 5000;
|
|
116
|
+
while (Date.now() - startTime < timeout * 1000) {
|
|
117
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
118
|
+
try {
|
|
119
|
+
const res = await ctx.http.get(`${baseUrl}/tasks/${taskId}`, {
|
|
120
|
+
headers: { 'Authorization': `Bearer ${apiKey}` }
|
|
121
|
+
});
|
|
122
|
+
const status = res.status; // PENDING, RUNNING, SUCCEEDED, FAILED
|
|
123
|
+
if (status === 'SUCCEEDED') {
|
|
124
|
+
const url = res.output?.[0] || res.url;
|
|
125
|
+
if (!url)
|
|
126
|
+
throw new Error('Task succeeded but no URL found');
|
|
127
|
+
return [{
|
|
128
|
+
kind: 'video',
|
|
129
|
+
url: url,
|
|
130
|
+
mime: 'video/mp4',
|
|
131
|
+
meta: {
|
|
132
|
+
model,
|
|
133
|
+
duration,
|
|
134
|
+
taskId
|
|
135
|
+
}
|
|
136
|
+
}];
|
|
137
|
+
}
|
|
138
|
+
else if (status === 'FAILED') {
|
|
139
|
+
throw new Error(`Runway Task Failed: ${res.failureReason || 'Unknown error'}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
// ignore
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
throw new Error('Runway task timeout');
|
|
147
|
+
}
|
|
148
|
+
/** Runway 连接器定义 */
|
|
149
|
+
const RunwayConnector = {
|
|
150
|
+
id: 'runway',
|
|
151
|
+
name: 'Runway',
|
|
152
|
+
supportedTypes: ['video'],
|
|
153
|
+
fields: runwayFields,
|
|
154
|
+
cardFields: runwayCardFields,
|
|
155
|
+
generate,
|
|
156
|
+
getRequestLog(config, files, prompt) {
|
|
157
|
+
const { apiUrl, model } = config;
|
|
158
|
+
return {
|
|
159
|
+
endpoint: apiUrl,
|
|
160
|
+
model,
|
|
161
|
+
prompt,
|
|
162
|
+
fileCount: files.length,
|
|
163
|
+
parameters: {}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
exports.RunwayConnector = RunwayConnector;
|
|
168
|
+
exports.default = (0, core_1.definePlugin)({
|
|
169
|
+
id: 'connector-runway',
|
|
170
|
+
name: 'Runway 连接器',
|
|
171
|
+
description: '适配 Runway Gen-2/Gen-3 视频生成',
|
|
172
|
+
version: '1.0.0',
|
|
173
|
+
connector: RunwayConnector,
|
|
174
|
+
async onLoad(ctx) {
|
|
175
|
+
ctx.logger.info('Runway connector loaded');
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/connector-runway/index.ts"],"names":[],"mappings":";AAAA,eAAe;AACf,qCAAqC;AACrC,oBAAoB;;;AAGpB,qCAAyC;AAGzC,kBAAkB;AAClB,MAAM,YAAY,GAAqB;IACrC;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,6BAA6B,EAAE,OAAO;QA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K,CAAC,MAAM,CAAC,GAAG;QACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConnectorDefinition } from '../../core';
|
|
2
|
+
/** Stability AI 连接器定义 */
|
|
3
|
+
declare const StabilityConnector: ConnectorDefinition;
|
|
4
|
+
declare const _default: import("../../core").PluginDefinition;
|
|
5
|
+
export default _default;
|
|
6
|
+
export { StabilityConnector };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/connector-stability/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAgF,MAAM,YAAY,CAAA;AA6KnI,yBAAyB;AACzB,QAAA,MAAM,kBAAkB,EAAE,mBAoBzB,CAAA;;AAED,wBASE;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|