koishi-plugin-media-luna 0.0.11 → 0.0.13
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/components/settings/PluginsPanel.vue +1 -3
- package/dist/index.js +1 -1
- package/dist/style.css +1 -1
- 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,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;IACzC;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,qCAAqC;QAC9C,WAAW,EAAE,qCAAqC;KACnD;IACD;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SA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ACjC,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;QAC/C,WAAW,EAAE,sCAAsC;QACnD,WAAW,EAAE,iBAAiB;KAC/B;IACD;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;KACf;IACD;QACE,GAAG,EAAE,OAAO;QACZ,KAAK,EAA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定义 */
|
|
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"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Stability AI 连接器插件
|
|
3
|
+
// 基于 Stable Image API (v2beta)
|
|
4
|
+
// 文档: https://platform.stability.ai/docs/api-reference
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StabilityConnector = void 0;
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
/** Stability AI 配置字段 */
|
|
9
|
+
const stabilityFields = [
|
|
10
|
+
{
|
|
11
|
+
key: 'apiKey',
|
|
12
|
+
label: 'API Key',
|
|
13
|
+
type: 'password',
|
|
14
|
+
required: true,
|
|
15
|
+
description: 'Stability AI API Key (sk-...)'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
key: 'model',
|
|
19
|
+
label: '模型',
|
|
20
|
+
type: 'text',
|
|
21
|
+
default: 'sd3-large',
|
|
22
|
+
required: true,
|
|
23
|
+
placeholder: 'sd3-large',
|
|
24
|
+
description: 'sd3-large, sd3-large-turbo, sd3-medium, core'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
key: 'aspectRatio',
|
|
28
|
+
label: '宽高比',
|
|
29
|
+
type: 'select',
|
|
30
|
+
default: '1:1',
|
|
31
|
+
options: [
|
|
32
|
+
{ label: '1:1', value: '1:1' },
|
|
33
|
+
{ label: '16:9', value: '16:9' },
|
|
34
|
+
{ label: '21:9', value: '21:9' },
|
|
35
|
+
{ label: '2:3', value: '2:3' },
|
|
36
|
+
{ label: '3:2', value: '3:2' },
|
|
37
|
+
{ label: '4:5', value: '4:5' },
|
|
38
|
+
{ label: '5:4', value: '5:4' },
|
|
39
|
+
{ label: '9:16', value: '9:16' },
|
|
40
|
+
{ label: '9:21', value: '9:21' }
|
|
41
|
+
],
|
|
42
|
+
description: '生成图像的宽高比'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: 'negativePrompt',
|
|
46
|
+
label: '负面提示词',
|
|
47
|
+
type: 'textarea',
|
|
48
|
+
description: '仅部分模型支持 (如 sd3-large, core)'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: 'seed',
|
|
52
|
+
label: '种子',
|
|
53
|
+
type: 'number',
|
|
54
|
+
default: 0,
|
|
55
|
+
description: '0 为随机'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: 'outputFormat',
|
|
59
|
+
label: '输出格式',
|
|
60
|
+
type: 'select',
|
|
61
|
+
default: 'png',
|
|
62
|
+
options: [
|
|
63
|
+
{ label: 'PNG', value: 'png' },
|
|
64
|
+
{ label: 'JPEG', value: 'jpeg' }
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: 'timeout',
|
|
69
|
+
label: '超时时间(秒)',
|
|
70
|
+
type: 'number',
|
|
71
|
+
default: 60
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
/** 卡片展示字段 */
|
|
75
|
+
const stabilityCardFields = [
|
|
76
|
+
{ source: 'connectorConfig', key: 'model', label: '模型' },
|
|
77
|
+
{ source: 'connectorConfig', key: 'aspectRatio', label: '比例' }
|
|
78
|
+
];
|
|
79
|
+
/** Stability AI 生成函数 */
|
|
80
|
+
async function generate(ctx, config, files, prompt) {
|
|
81
|
+
const { apiKey, model = 'sd3-large', aspectRatio = '1:1', negativePrompt, seed = 0, outputFormat = 'png', timeout = 60 } = config;
|
|
82
|
+
// 根据模型选择 Endpoint
|
|
83
|
+
// Stable Image Core 使用不同端点
|
|
84
|
+
let apiUrl = 'https://api.stability.ai/v2beta/stable-image/generate/sd3';
|
|
85
|
+
if (model === 'core') {
|
|
86
|
+
apiUrl = 'https://api.stability.ai/v2beta/stable-image/generate/core';
|
|
87
|
+
}
|
|
88
|
+
else if (model.includes('ultra')) {
|
|
89
|
+
apiUrl = 'https://api.stability.ai/v2beta/stable-image/generate/ultra';
|
|
90
|
+
}
|
|
91
|
+
// 构建 FormData
|
|
92
|
+
const formData = new FormData();
|
|
93
|
+
formData.append('prompt', prompt);
|
|
94
|
+
formData.append('aspect_ratio', aspectRatio);
|
|
95
|
+
formData.append('output_format', outputFormat);
|
|
96
|
+
// 可选参数
|
|
97
|
+
if (negativePrompt)
|
|
98
|
+
formData.append('negative_prompt', negativePrompt);
|
|
99
|
+
if (seed && seed !== 0)
|
|
100
|
+
formData.append('seed', seed.toString());
|
|
101
|
+
// 处理垫图 (Image-to-Image)
|
|
102
|
+
// SD3 API 支持 mode: 'image-to-image' 和 image 参数
|
|
103
|
+
const imageFile = files.find(f => f.mime.startsWith('image/'));
|
|
104
|
+
if (imageFile) {
|
|
105
|
+
formData.append('image', new Blob([imageFile.data], { type: imageFile.mime }));
|
|
106
|
+
formData.append('mode', 'image-to-image');
|
|
107
|
+
formData.append('strength', '0.7'); // 默认去噪强度
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
formData.append('mode', 'text-to-image');
|
|
111
|
+
}
|
|
112
|
+
// 必须指定 model 参数
|
|
113
|
+
if (model !== 'core' && !model.includes('ultra')) {
|
|
114
|
+
formData.append('model', model);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const response = await ctx.http.post(apiUrl, formData, {
|
|
118
|
+
headers: {
|
|
119
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
120
|
+
'Accept': 'image/*' // 请求直接返回图片二进制数据
|
|
121
|
+
},
|
|
122
|
+
responseType: 'arraybuffer',
|
|
123
|
+
timeout: timeout * 1000
|
|
124
|
+
});
|
|
125
|
+
// 检查响应类型
|
|
126
|
+
// 如果 Accept 是 image/*,成功时直接返回二进制图片
|
|
127
|
+
// 失败时通常返回 JSON
|
|
128
|
+
// Stability AI v2beta 直接返回图片数据
|
|
129
|
+
const mime = outputFormat === 'png' ? 'image/png' : 'image/jpeg';
|
|
130
|
+
const base64 = Buffer.from(response).toString('base64');
|
|
131
|
+
return [{
|
|
132
|
+
kind: 'image',
|
|
133
|
+
url: `data:${mime};base64,${base64}`,
|
|
134
|
+
mime,
|
|
135
|
+
meta: {
|
|
136
|
+
model,
|
|
137
|
+
aspectRatio,
|
|
138
|
+
seed
|
|
139
|
+
}
|
|
140
|
+
}];
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
// 尝试解析错误 JSON
|
|
144
|
+
if (e.response?.data) {
|
|
145
|
+
try {
|
|
146
|
+
const errorText = Buffer.from(e.response.data).toString();
|
|
147
|
+
const errorJson = JSON.parse(errorText);
|
|
148
|
+
if (errorJson.errors) {
|
|
149
|
+
throw new Error(`Stability AI Error: ${errorJson.errors.map((err) => err.message).join(', ')}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// ignore
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Stability AI 连接器定义 */
|
|
160
|
+
const StabilityConnector = {
|
|
161
|
+
id: 'stability',
|
|
162
|
+
name: 'Stability AI',
|
|
163
|
+
supportedTypes: ['image'],
|
|
164
|
+
fields: stabilityFields,
|
|
165
|
+
cardFields: stabilityCardFields,
|
|
166
|
+
generate,
|
|
167
|
+
getRequestLog(config, files, prompt) {
|
|
168
|
+
const { model, aspectRatio } = config;
|
|
169
|
+
return {
|
|
170
|
+
endpoint: 'api.stability.ai',
|
|
171
|
+
model,
|
|
172
|
+
prompt,
|
|
173
|
+
fileCount: files.length,
|
|
174
|
+
parameters: {
|
|
175
|
+
aspectRatio
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
exports.StabilityConnector = StabilityConnector;
|
|
181
|
+
exports.default = (0, core_1.definePlugin)({
|
|
182
|
+
id: 'connector-stability',
|
|
183
|
+
name: 'Stability AI 连接器',
|
|
184
|
+
description: 'Stability AI 官方连接器 (SD3/Core)',
|
|
185
|
+
version: '1.0.0',
|
|
186
|
+
connector: StabilityConnector,
|
|
187
|
+
async onLoad(ctx) {
|
|
188
|
+
ctx.logger.info('Stability AI connector loaded');
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/connector-stability/index.ts"],"names":[],"mappings":";AAAA,qBAAqB;AACrB,+BAA+B;AAC/B,uDAAuD;;;AAGvD,qCAAyC;AAGzC,wBAAwB;AACxB,MAAM,eAAe,GAAqB;IACxC;QACE,GAAG,EAAE,QAAQ;QACb,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,+BAA+B;KAC7C;IACD;QACE,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,WAAW;QACxB,WAAW,EAAE,8CAA8C;KAC5D;IACD;QACE,GAAG,EAAE,aAAa;QAClB,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,KAAK;QACd,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK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,CAAC;CACF,CAAA;AAaQ,gDAAkB;AAX3B,kBAAe,IAAA,mBAAY,EAAC;IAC1B,EAAE,EAAE,qBAAqB;IACzB,IAAI,EAAE,kBAAkB;IACxB,WAAW,EAAE,+BAA+B;IAC5C,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,kBAAkB;IAC7B,KAAK,CAAC,MAAM,CAAC,GAAG;QACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;IAClD,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConnectorDefinition } from '../../core';
|
|
2
|
+
/** Suno 连接器定义 */
|
|
3
|
+
declare const SunoConnector: ConnectorDefinition;
|
|
4
|
+
declare const _default: import("../../core").PluginDefinition;
|
|
5
|
+
export default _default;
|
|
6
|
+
export { SunoConnector };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/connector-suno/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAgF,MAAM,YAAY,CAAA;AA8NnI,iBAAiB;AACjB,QAAA,MAAM,aAAa,EAAE,mBAqBpB,CAAA;;AAED,wBASE;AAEF,OAAO,EAAE,aAAa,EAAE,CAAA"}
|