ai-world-sdk 1.5.8 → 1.5.10
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/dist/__tests__/llm.real.test.js +13 -11
- package/dist/cli/commands/image.js +146 -43
- package/dist/cli/commands/plugin-token.d.ts +2 -0
- package/dist/cli/commands/plugin-token.js +181 -0
- package/dist/cli/index.js +2 -0
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/dist/image.d.ts +93 -0
- package/dist/image.js +227 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -1
- package/dist/plugin-token.d.ts +71 -0
- package/dist/plugin-token.js +133 -0
- package/package.json +1 -1
- package/skills/ai-world-sdk/SKILL.md +1 -0
- package/skills/ai-world-sdk/docs/admin-api.md +55 -0
- package/skills/ai-world-sdk/docs/cli-commands.md +14 -0
- package/skills/ai-world-sdk/docs/image-generation.md +324 -9
|
@@ -45,6 +45,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
const dotenv = __importStar(require("dotenv"));
|
|
47
47
|
const llm_1 = require("../llm");
|
|
48
|
+
const image_1 = require("../image");
|
|
48
49
|
const config_1 = require("../config");
|
|
49
50
|
const ai_1 = require("ai");
|
|
50
51
|
// 加载环境变量
|
|
@@ -214,17 +215,17 @@ describe("llm.ts — 真实集成测试(文本 + 图像)", () => {
|
|
|
214
215
|
// ============================================================
|
|
215
216
|
// createProvider + generateImage(kunpo 图像生成)
|
|
216
217
|
// ============================================================
|
|
217
|
-
describe("
|
|
218
|
+
describe("generateKunpoImage(kunpo 图像)", () => {
|
|
218
219
|
const promptArg = "A simple red circle on a white background";
|
|
219
|
-
test("kunpo —
|
|
220
|
-
const modelId = process.env.KUNPO_IMAGE_MODEL || "
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
model: imageModel,
|
|
220
|
+
test("kunpo — Image-GI2(异步)", async () => {
|
|
221
|
+
const modelId = process.env.KUNPO_IMAGE_MODEL || "Image-GI2";
|
|
222
|
+
const result = await (0, image_1.generateKunpoImage)({
|
|
223
|
+
pluginId: PLUGIN_ID,
|
|
224
|
+
model: modelId,
|
|
225
225
|
prompt: promptArg,
|
|
226
|
-
n: 1,
|
|
227
226
|
size: "1024x1024",
|
|
227
|
+
quality: "high",
|
|
228
|
+
async: true,
|
|
228
229
|
});
|
|
229
230
|
expect(result.images).toBeDefined();
|
|
230
231
|
expect(result.images.length).toBeGreaterThan(0);
|
|
@@ -294,9 +295,10 @@ describe("llm.ts — 真实集成测试(文本 + 图像)", () => {
|
|
|
294
295
|
const provider = (0, llm_1.createProvider)("api2img", "openai", "test");
|
|
295
296
|
expect(typeof provider.languageModel).toBe("function");
|
|
296
297
|
});
|
|
297
|
-
test("
|
|
298
|
-
const
|
|
299
|
-
|
|
298
|
+
test("getImageProxyConfig 返回 /api/llm/image 代理地址", () => {
|
|
299
|
+
const { getImageProxyConfig } = require("../image");
|
|
300
|
+
const cfg = getImageProxyConfig("test");
|
|
301
|
+
expect(cfg.baseUrl).toContain("/api/llm/image");
|
|
300
302
|
});
|
|
301
303
|
});
|
|
302
304
|
});
|
|
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.registerImageCommands = registerImageCommands;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
-
const ai_1 = require("ai");
|
|
40
39
|
const index_1 = require("../../index");
|
|
41
|
-
const config_1 = require("
|
|
40
|
+
const config_1 = require("../../config");
|
|
41
|
+
const config_2 = require("../config");
|
|
42
42
|
const output_1 = require("../output");
|
|
43
43
|
const utils_1 = require("../utils");
|
|
44
44
|
function collectOpts(cmd) {
|
|
@@ -63,22 +63,86 @@ function stripB64ForLog(obj) {
|
|
|
63
63
|
}
|
|
64
64
|
return copy;
|
|
65
65
|
}
|
|
66
|
+
async function downloadUrlToFile(url, outputPath) {
|
|
67
|
+
const res = await fetch(url);
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
throw new Error(`下载图像失败: ${res.status}`);
|
|
70
|
+
}
|
|
71
|
+
const abs = path.resolve(outputPath);
|
|
72
|
+
const dir = path.dirname(abs);
|
|
73
|
+
if (!fs.existsSync(dir))
|
|
74
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
75
|
+
fs.writeFileSync(abs, Buffer.from(await res.arrayBuffer()));
|
|
76
|
+
}
|
|
77
|
+
/** OpenAI 图像:经 /api/llm/openai 代理(HTTP,非 AI SDK) */
|
|
78
|
+
async function generateOpenAIImageViaProxy(pluginId, model, prompt, size) {
|
|
79
|
+
const serverUrl = config_1.sdkConfig.getServerUrl() || '';
|
|
80
|
+
const token = config_1.sdkConfig.getToken() || '';
|
|
81
|
+
const body = {
|
|
82
|
+
model,
|
|
83
|
+
prompt,
|
|
84
|
+
n: 1,
|
|
85
|
+
response_format: 'b64_json',
|
|
86
|
+
};
|
|
87
|
+
if (size)
|
|
88
|
+
body.size = size;
|
|
89
|
+
const res = await fetch(`${serverUrl}/api/llm/openai/images/generations`, {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
'X-Plugin-Id': pluginId,
|
|
94
|
+
'X-Provider': 'api2img',
|
|
95
|
+
Authorization: `Bearer ${token}`,
|
|
96
|
+
},
|
|
97
|
+
body: JSON.stringify(body),
|
|
98
|
+
});
|
|
99
|
+
if (!res.ok) {
|
|
100
|
+
const text = await res.text().catch(() => '');
|
|
101
|
+
throw new Error(`OpenAI 图像生成失败: ${res.status} ${text}`);
|
|
102
|
+
}
|
|
103
|
+
const json = (await res.json());
|
|
104
|
+
const first = json.data?.[0];
|
|
105
|
+
if (!first) {
|
|
106
|
+
throw new Error('OpenAI 图像生成响应无数据');
|
|
107
|
+
}
|
|
108
|
+
if (first.b64_json) {
|
|
109
|
+
const buf = Buffer.from(first.b64_json, 'base64');
|
|
110
|
+
return { uint8Array: new Uint8Array(buf), mediaType: 'image/png' };
|
|
111
|
+
}
|
|
112
|
+
if (first.url) {
|
|
113
|
+
const imgRes = await fetch(first.url);
|
|
114
|
+
if (!imgRes.ok) {
|
|
115
|
+
throw new Error(`下载图像失败: ${imgRes.status}`);
|
|
116
|
+
}
|
|
117
|
+
const buf = Buffer.from(await imgRes.arrayBuffer());
|
|
118
|
+
return {
|
|
119
|
+
uint8Array: new Uint8Array(buf),
|
|
120
|
+
mediaType: imgRes.headers.get('content-type') || 'image/png',
|
|
121
|
+
url: first.url,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
throw new Error('OpenAI 图像生成响应无 url 或 b64_json');
|
|
125
|
+
}
|
|
66
126
|
function registerImageCommands(program) {
|
|
67
|
-
const image = program
|
|
127
|
+
const image = program
|
|
128
|
+
.command('image')
|
|
129
|
+
.description('图像生成(doubao / gemini / openai / kunpo)');
|
|
68
130
|
image
|
|
69
131
|
.command('generate')
|
|
70
|
-
.requiredOption('--provider <name>', 'doubao, gemini, or
|
|
132
|
+
.requiredOption('--provider <name>', 'doubao, gemini, openai, or kunpo')
|
|
71
133
|
.requiredOption('--prompt <text>', 'Prompt text')
|
|
72
134
|
.option('--model <id>', 'Model id')
|
|
73
|
-
.option('--size <value>', 'Size
|
|
135
|
+
.option('--size <value>', 'Size e.g. 1024x1024, 1536x1024')
|
|
136
|
+
.option('--quality <value>', 'KUNPO quality: low, standard, medium, high, hd')
|
|
137
|
+
.option('--sync', 'KUNPO: use sync /images/generations (not recommended)')
|
|
74
138
|
.option('--output <file>', 'Write first image to file')
|
|
75
|
-
.option('--plugin-id <id>', 'Plugin id (required for openai)')
|
|
139
|
+
.option('--plugin-id <id>', 'Plugin id (required for openai / kunpo)')
|
|
76
140
|
.action(async (options, cmd) => {
|
|
77
141
|
const commandName = 'image generate';
|
|
78
142
|
try {
|
|
79
143
|
void (0, utils_1.getFormat)(program);
|
|
80
144
|
const o = collectOpts(cmd);
|
|
81
|
-
const auth = (0,
|
|
145
|
+
const auth = (0, config_2.resolveAuth)({
|
|
82
146
|
baseUrl: o.baseUrl,
|
|
83
147
|
token: o.token,
|
|
84
148
|
pluginId: options.pluginId ??
|
|
@@ -88,8 +152,8 @@ function registerImageCommands(program) {
|
|
|
88
152
|
(0, utils_1.requireOption)(options.prompt, 'prompt');
|
|
89
153
|
(0, utils_1.requireOption)(options.provider, 'provider');
|
|
90
154
|
const providerName = options.provider.toLowerCase();
|
|
91
|
-
if (!['doubao', 'gemini', 'openai'].includes(providerName)) {
|
|
92
|
-
const err = new Error('缺少必需参数: --provider 必须是 doubao、gemini 或
|
|
155
|
+
if (!['doubao', 'gemini', 'openai', 'kunpo'].includes(providerName)) {
|
|
156
|
+
const err = new Error('缺少必需参数: --provider 必须是 doubao、gemini、openai 或 kunpo');
|
|
93
157
|
err.code = 'VALIDATION_ERROR';
|
|
94
158
|
throw err;
|
|
95
159
|
}
|
|
@@ -106,15 +170,7 @@ function registerImageCommands(program) {
|
|
|
106
170
|
(0, utils_1.writeOutputFile)(options.output, Buffer.from(first.b64_json, 'base64'));
|
|
107
171
|
}
|
|
108
172
|
else if (first?.url) {
|
|
109
|
-
|
|
110
|
-
const dir = path.dirname(abs);
|
|
111
|
-
if (!fs.existsSync(dir))
|
|
112
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
113
|
-
const res = await fetch(first.url);
|
|
114
|
-
if (!res.ok) {
|
|
115
|
-
throw new Error(`下载图像失败: ${res.status}`);
|
|
116
|
-
}
|
|
117
|
-
fs.writeFileSync(abs, Buffer.from(await res.arrayBuffer()));
|
|
173
|
+
await downloadUrlToFile(first.url, options.output);
|
|
118
174
|
}
|
|
119
175
|
}
|
|
120
176
|
(0, output_1.outputJSON)(options.output ? stripB64ForLog({ ...result, savedTo: options.output }) : result);
|
|
@@ -136,15 +192,7 @@ function registerImageCommands(program) {
|
|
|
136
192
|
(0, utils_1.writeOutputFile)(options.output, Buffer.from(first.b64_json, 'base64'));
|
|
137
193
|
}
|
|
138
194
|
else if (first?.url) {
|
|
139
|
-
|
|
140
|
-
const dir = path.dirname(abs);
|
|
141
|
-
if (!fs.existsSync(dir))
|
|
142
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
143
|
-
const res = await fetch(first.url);
|
|
144
|
-
if (!res.ok) {
|
|
145
|
-
throw new Error(`下载图像失败: ${res.status}`);
|
|
146
|
-
}
|
|
147
|
-
fs.writeFileSync(abs, Buffer.from(await res.arrayBuffer()));
|
|
195
|
+
await downloadUrlToFile(first.url, options.output);
|
|
148
196
|
}
|
|
149
197
|
}
|
|
150
198
|
(0, output_1.outputJSON)(options.output ? stripB64ForLog({ ...result, savedTo: options.output }) : result);
|
|
@@ -155,28 +203,83 @@ function registerImageCommands(program) {
|
|
|
155
203
|
auth.pluginId;
|
|
156
204
|
(0, utils_1.requireOption)(pluginId, 'plugin-id');
|
|
157
205
|
(0, utils_1.initSDK)({ ...auth, pluginId });
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
206
|
+
if (providerName === 'kunpo') {
|
|
207
|
+
const modelId = options.model || 'Image-GI2';
|
|
208
|
+
const useSync = Boolean(options.sync);
|
|
209
|
+
if (useSync) {
|
|
210
|
+
const body = {
|
|
211
|
+
model: modelId,
|
|
212
|
+
prompt: options.prompt,
|
|
213
|
+
response_format: 'b64_json',
|
|
214
|
+
n: 1,
|
|
215
|
+
};
|
|
216
|
+
if (options.size && /^\d+x\d+$|auto/.test(options.size)) {
|
|
217
|
+
body.size = options.size;
|
|
218
|
+
}
|
|
219
|
+
if (options.quality) {
|
|
220
|
+
body.quality = options.quality;
|
|
221
|
+
}
|
|
222
|
+
const resp = await (0, index_1.generateImageSync)(pluginId, body);
|
|
223
|
+
const first = resp.data?.[0];
|
|
224
|
+
if (options.output && first?.b64_json) {
|
|
225
|
+
(0, utils_1.writeOutputFile)(options.output, Buffer.from(first.b64_json, 'base64'));
|
|
226
|
+
}
|
|
227
|
+
else if (options.output && first?.url) {
|
|
228
|
+
await downloadUrlToFile(first.url, options.output);
|
|
229
|
+
}
|
|
230
|
+
(0, output_1.outputJSON)({
|
|
231
|
+
provider: 'kunpo',
|
|
232
|
+
model: modelId,
|
|
233
|
+
mode: 'sync',
|
|
234
|
+
proxy: (0, index_1.getImageProxyConfig)(pluginId).baseUrl,
|
|
235
|
+
savedTo: options.output || undefined,
|
|
236
|
+
data: resp.data?.map((d) => ({
|
|
237
|
+
...d,
|
|
238
|
+
b64_json: d.b64_json ? '[omitted]' : undefined,
|
|
239
|
+
})),
|
|
240
|
+
});
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const kunpoOpts = {
|
|
244
|
+
pluginId: pluginId,
|
|
245
|
+
model: modelId,
|
|
246
|
+
prompt: options.prompt,
|
|
247
|
+
async: true,
|
|
248
|
+
};
|
|
249
|
+
if (options.size && /^\d+x\d+$|auto/.test(options.size)) {
|
|
250
|
+
kunpoOpts.size = options.size;
|
|
251
|
+
}
|
|
252
|
+
if (options.quality) {
|
|
253
|
+
kunpoOpts.quality = options.quality;
|
|
254
|
+
}
|
|
255
|
+
const imgResult = await (0, index_1.generateKunpoImage)(kunpoOpts);
|
|
256
|
+
const first = imgResult.images[0];
|
|
257
|
+
if (options.output && first) {
|
|
258
|
+
(0, utils_1.writeOutputFile)(options.output, Buffer.from(first.uint8Array));
|
|
259
|
+
}
|
|
260
|
+
(0, output_1.outputJSON)({
|
|
261
|
+
provider: 'kunpo',
|
|
262
|
+
model: modelId,
|
|
263
|
+
mode: 'async',
|
|
264
|
+
taskId: imgResult.taskId,
|
|
265
|
+
resultUrl: imgResult.resultUrl,
|
|
266
|
+
mediaType: first?.mediaType,
|
|
267
|
+
savedTo: options.output || undefined,
|
|
268
|
+
});
|
|
269
|
+
return;
|
|
167
270
|
}
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
271
|
+
// openai:/api/llm/openai 代理 HTTP
|
|
272
|
+
const modelId = options.model || 'dall-e-3';
|
|
273
|
+
const img = await generateOpenAIImageViaProxy(pluginId, modelId, options.prompt, options.size);
|
|
274
|
+
if (options.output) {
|
|
275
|
+
(0, utils_1.writeOutputFile)(options.output, Buffer.from(img.uint8Array));
|
|
172
276
|
}
|
|
173
277
|
(0, output_1.outputJSON)({
|
|
174
278
|
provider: 'openai',
|
|
175
279
|
model: modelId,
|
|
176
|
-
mediaType:
|
|
280
|
+
mediaType: img.mediaType,
|
|
281
|
+
url: img.url,
|
|
177
282
|
savedTo: options.output || undefined,
|
|
178
|
-
usage: imgResult.usage,
|
|
179
|
-
warnings: imgResult.warnings,
|
|
180
283
|
});
|
|
181
284
|
}
|
|
182
285
|
catch (err) {
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerPluginTokenCommands = registerPluginTokenCommands;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const output_1 = require("../output");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
function collectOpts(cmd) {
|
|
8
|
+
const chain = [];
|
|
9
|
+
for (let c = cmd; c; c = c.parent)
|
|
10
|
+
chain.unshift(c);
|
|
11
|
+
const o = {};
|
|
12
|
+
for (const c of chain)
|
|
13
|
+
Object.assign(o, c.opts());
|
|
14
|
+
return o;
|
|
15
|
+
}
|
|
16
|
+
function resolveAndInit(cmd) {
|
|
17
|
+
const o = collectOpts(cmd);
|
|
18
|
+
const auth = (0, config_1.resolveAuth)({
|
|
19
|
+
baseUrl: o.baseUrl,
|
|
20
|
+
token: o.token,
|
|
21
|
+
pluginId: o.pluginId,
|
|
22
|
+
});
|
|
23
|
+
(0, utils_1.initSDK)(auth);
|
|
24
|
+
return o;
|
|
25
|
+
}
|
|
26
|
+
function parsePositiveInt(raw, flag) {
|
|
27
|
+
if (raw == null || raw === '')
|
|
28
|
+
return undefined;
|
|
29
|
+
const n = parseInt(raw, 10);
|
|
30
|
+
if (!Number.isFinite(n)) {
|
|
31
|
+
const err = new Error(`无效的 ${flag}: ${raw}`);
|
|
32
|
+
err.code = 'VALIDATION_ERROR';
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
return n;
|
|
36
|
+
}
|
|
37
|
+
function registerPluginTokenCommands(program) {
|
|
38
|
+
const pt = program.command('plugin-token').description('插件 Token 管理(需管理员权限)');
|
|
39
|
+
pt.command('list')
|
|
40
|
+
.description('列出插件 Token')
|
|
41
|
+
.option('--plugin-id <id>', '按插件 ID 过滤')
|
|
42
|
+
.option('--active', '仅显示启用')
|
|
43
|
+
.option('--inactive', '仅显示停用')
|
|
44
|
+
.option('--page <n>', '页码')
|
|
45
|
+
.option('--page-size <n>', '每页条数')
|
|
46
|
+
.action(async (opts, cmd) => {
|
|
47
|
+
try {
|
|
48
|
+
const o = resolveAndInit(cmd);
|
|
49
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
50
|
+
const client = new PluginTokenClient();
|
|
51
|
+
const isActive = opts.active ? true : opts.inactive ? false : undefined;
|
|
52
|
+
const result = await client.list({
|
|
53
|
+
pluginId: opts.pluginId,
|
|
54
|
+
isActive,
|
|
55
|
+
page: parsePositiveInt(opts.page, '--page') || 1,
|
|
56
|
+
pageSize: parsePositiveInt(opts.pageSize, '--page-size') || 20,
|
|
57
|
+
});
|
|
58
|
+
(0, output_1.output)(result, (0, utils_1.getFormat)(program));
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
(0, utils_1.handleError)(err, 'plugin-token list');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
pt.command('create')
|
|
65
|
+
.description('创建插件 Token')
|
|
66
|
+
.requiredOption('--plugin-id <id>', '插件 ID')
|
|
67
|
+
.requiredOption('--name <name>', 'Token 名称')
|
|
68
|
+
.requiredOption('--role-id <id>', '角色 ID')
|
|
69
|
+
.option('--description <desc>', '描述')
|
|
70
|
+
.option('--expires <date>', '过期时间 (ISO 8601)')
|
|
71
|
+
.action(async (opts, cmd) => {
|
|
72
|
+
try {
|
|
73
|
+
resolveAndInit(cmd);
|
|
74
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
75
|
+
const client = new PluginTokenClient();
|
|
76
|
+
const result = await client.create({
|
|
77
|
+
plugin_id: opts.pluginId,
|
|
78
|
+
name: opts.name,
|
|
79
|
+
role_id: Number(opts.roleId),
|
|
80
|
+
description: opts.description,
|
|
81
|
+
expires_at: opts.expires,
|
|
82
|
+
});
|
|
83
|
+
(0, output_1.output)(result, (0, utils_1.getFormat)(program));
|
|
84
|
+
console.error(`\n⚠️ Token 仅显示一次,请妥善保存: ${result.token}`);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
(0, utils_1.handleError)(err, 'plugin-token create');
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
pt.command('get')
|
|
91
|
+
.argument('<id>', 'Token ID')
|
|
92
|
+
.description('获取插件 Token 详情')
|
|
93
|
+
.action(async (idArg, _opts, cmd) => {
|
|
94
|
+
try {
|
|
95
|
+
resolveAndInit(cmd);
|
|
96
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
97
|
+
const client = new PluginTokenClient();
|
|
98
|
+
const result = await client.get(Number(idArg));
|
|
99
|
+
(0, output_1.output)(result, (0, utils_1.getFormat)(program));
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
(0, utils_1.handleError)(err, 'plugin-token get');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
pt.command('update')
|
|
106
|
+
.argument('<id>', 'Token ID')
|
|
107
|
+
.description('更新插件 Token')
|
|
108
|
+
.option('--name <name>', '名称')
|
|
109
|
+
.option('--description <desc>', '描述')
|
|
110
|
+
.option('--role-id <id>', '角色 ID')
|
|
111
|
+
.option('--expires <date>', '过期时间 (ISO 8601)')
|
|
112
|
+
.action(async (idArg, opts, cmd) => {
|
|
113
|
+
try {
|
|
114
|
+
resolveAndInit(cmd);
|
|
115
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
116
|
+
const client = new PluginTokenClient();
|
|
117
|
+
const data = {};
|
|
118
|
+
if (opts.name != null)
|
|
119
|
+
data.name = opts.name;
|
|
120
|
+
if (opts.description != null)
|
|
121
|
+
data.description = opts.description;
|
|
122
|
+
if (opts.roleId != null)
|
|
123
|
+
data.role_id = Number(opts.roleId);
|
|
124
|
+
if (opts.expires != null)
|
|
125
|
+
data.expires_at = opts.expires;
|
|
126
|
+
const result = await client.update(Number(idArg), data);
|
|
127
|
+
(0, output_1.output)(result, (0, utils_1.getFormat)(program));
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
(0, utils_1.handleError)(err, 'plugin-token update');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
pt.command('delete')
|
|
134
|
+
.argument('<id>', 'Token ID')
|
|
135
|
+
.description('删除插件 Token')
|
|
136
|
+
.action(async (idArg, _opts, cmd) => {
|
|
137
|
+
try {
|
|
138
|
+
resolveAndInit(cmd);
|
|
139
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
140
|
+
const client = new PluginTokenClient();
|
|
141
|
+
await client.delete(Number(idArg));
|
|
142
|
+
(0, output_1.output)({ deleted: true, id: Number(idArg) }, (0, utils_1.getFormat)(program));
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
(0, utils_1.handleError)(err, 'plugin-token delete');
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
pt.command('regenerate')
|
|
149
|
+
.argument('<id>', 'Token ID')
|
|
150
|
+
.description('重新生成 Token(旧 Token 立即失效)')
|
|
151
|
+
.action(async (idArg, _opts, cmd) => {
|
|
152
|
+
try {
|
|
153
|
+
resolveAndInit(cmd);
|
|
154
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
155
|
+
const client = new PluginTokenClient();
|
|
156
|
+
const result = await client.regenerate(Number(idArg));
|
|
157
|
+
(0, output_1.output)(result, (0, utils_1.getFormat)(program));
|
|
158
|
+
console.error(`\n⚠️ 新 Token 仅显示一次: ${result.token}`);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
(0, utils_1.handleError)(err, 'plugin-token regenerate');
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
pt.command('toggle')
|
|
165
|
+
.argument('<id>', 'Token ID')
|
|
166
|
+
.description('切换启用/停用状态')
|
|
167
|
+
.action(async (idArg, _opts, cmd) => {
|
|
168
|
+
try {
|
|
169
|
+
resolveAndInit(cmd);
|
|
170
|
+
const { PluginTokenClient } = require('../../plugin-token');
|
|
171
|
+
const client = new PluginTokenClient();
|
|
172
|
+
const result = await client.toggle(Number(idArg));
|
|
173
|
+
const status = result.is_active ? '已启用' : '已停用';
|
|
174
|
+
console.error(`Token #${idArg} ${status}`);
|
|
175
|
+
(0, output_1.output)(result, (0, utils_1.getFormat)(program));
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
(0, utils_1.handleError)(err, 'plugin-token toggle');
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -104,6 +104,7 @@ const stats_1 = require("./commands/stats");
|
|
|
104
104
|
const ai_config_1 = require("./commands/ai-config");
|
|
105
105
|
const shared_1 = require("./commands/shared");
|
|
106
106
|
const chrome_1 = require("./commands/chrome");
|
|
107
|
+
const plugin_token_1 = require("./commands/plugin-token");
|
|
107
108
|
(0, help_1.registerHelpCommand)(program);
|
|
108
109
|
(0, version_1.registerVersionCommand)(program);
|
|
109
110
|
(0, auth_1.registerAuthCommands)(program);
|
|
@@ -121,6 +122,7 @@ const chrome_1 = require("./commands/chrome");
|
|
|
121
122
|
(0, ai_config_1.registerAiConfigCommands)(program);
|
|
122
123
|
(0, shared_1.registerSharedCommands)(program);
|
|
123
124
|
(0, chrome_1.registerChromeCommands)(program);
|
|
125
|
+
(0, plugin_token_1.registerPluginTokenCommands)(program);
|
|
124
126
|
program.parseAsync(process.argv).catch((err) => {
|
|
125
127
|
(0, utils_1.handleError)(err, process.argv.slice(2).join(' '));
|
|
126
128
|
});
|
package/dist/config.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
11
11
|
*/
|
|
12
|
-
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.
|
|
12
|
+
export declare const SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.10";
|
|
13
13
|
/**
|
|
14
14
|
* 版本兼容性错误
|
|
15
15
|
*/
|
|
@@ -35,8 +35,8 @@ declare class SDKConfig {
|
|
|
35
35
|
private _authCheckPromise;
|
|
36
36
|
private _currentUser;
|
|
37
37
|
private _cliMode;
|
|
38
|
-
readonly sdkSignature = "AI_WORLD_SDK_V:1.5.
|
|
39
|
-
readonly sdkVersion = "1.5.
|
|
38
|
+
readonly sdkSignature = "AI_WORLD_SDK_V:1.5.10";
|
|
39
|
+
readonly sdkVersion = "1.5.10";
|
|
40
40
|
constructor();
|
|
41
41
|
/**
|
|
42
42
|
* Set global base URL
|
package/dist/config.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.sdkConfig = exports.VersionCompatibilityError = exports.SDK_SIGNATURE = void 0;
|
|
8
8
|
// SDK 版本号(构建时自动从 package.json 更新)
|
|
9
9
|
// 此版本号会在运行 npm run build 时自动从 package.json 读取并更新
|
|
10
|
-
const SDK_VERSION = "1.5.
|
|
10
|
+
const SDK_VERSION = "1.5.10";
|
|
11
11
|
/**
|
|
12
12
|
* SDK 特征码 - 用于在构建后的 JS 文件中识别 SDK 版本
|
|
13
13
|
* 格式: AI_WORLD_SDK_V:版本号
|
|
@@ -15,7 +15,7 @@ const SDK_VERSION = "1.5.8";
|
|
|
15
15
|
*
|
|
16
16
|
* 注意: {VERSION} 占位符会在构建时被替换为实际版本号
|
|
17
17
|
*/
|
|
18
|
-
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.
|
|
18
|
+
exports.SDK_SIGNATURE = "AI_WORLD_SDK_V:1.5.10";
|
|
19
19
|
/**
|
|
20
20
|
* 版本兼容性错误
|
|
21
21
|
*/
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** 腾讯 AIART 支持的模型 */
|
|
2
|
+
export type KunpoTencentImageModel = "Image-GI" | "Image-GI2" | "Image-GPT2";
|
|
3
|
+
/** OpenAI Images 兼容的 quality(GI 映射分辨率,GPT 映射质量档位) */
|
|
4
|
+
export type KunpoImageQuality = "low" | "standard" | "medium" | "high" | "hd";
|
|
5
|
+
export type KunpoInputFidelity = "high" | "low";
|
|
6
|
+
export type KunpoResponseFormat = "url" | "b64_json";
|
|
7
|
+
export interface KunpoImageGenerationOptions {
|
|
8
|
+
pluginId: string;
|
|
9
|
+
model: KunpoTencentImageModel | string;
|
|
10
|
+
prompt: string;
|
|
11
|
+
/** 默认 true:POST /images/tasks + 轮询 */
|
|
12
|
+
async?: boolean;
|
|
13
|
+
/** 图片数量,默认 1 */
|
|
14
|
+
n?: number;
|
|
15
|
+
/** 图片宽高,默认 auto:自动根据模型和质量生成 */
|
|
16
|
+
size?: `${number}x${number}` | "auto";
|
|
17
|
+
quality?: KunpoImageQuality;
|
|
18
|
+
responseFormat?: KunpoResponseFormat;
|
|
19
|
+
/** 图生图参考图 URL 数组 */
|
|
20
|
+
images?: string[];
|
|
21
|
+
/** 图生图 */
|
|
22
|
+
image?: string;
|
|
23
|
+
background?: string;
|
|
24
|
+
outputFormat?: "png";
|
|
25
|
+
inputFidelity?: KunpoInputFidelity;
|
|
26
|
+
seed?: number;
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
abortSignal?: AbortSignal;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
/** 轮询间隔时间,默认 30000ms */
|
|
31
|
+
pollIntervalMs?: number;
|
|
32
|
+
/** 轮询超时时间,默认 15 * 60 * 1000ms */
|
|
33
|
+
pollTimeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface GeneratedImageFile {
|
|
36
|
+
base64: string;
|
|
37
|
+
uint8Array: Uint8Array;
|
|
38
|
+
mediaType: string;
|
|
39
|
+
url?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface KunpoImageGenerationResult {
|
|
42
|
+
image: GeneratedImageFile;
|
|
43
|
+
images: GeneratedImageFile[];
|
|
44
|
+
taskId?: string;
|
|
45
|
+
resultUrl?: string;
|
|
46
|
+
}
|
|
47
|
+
interface KunpoTaskSubmitResponse {
|
|
48
|
+
id?: string;
|
|
49
|
+
task_id?: string;
|
|
50
|
+
model?: string;
|
|
51
|
+
status?: string;
|
|
52
|
+
created_at?: number;
|
|
53
|
+
}
|
|
54
|
+
interface KunpoTaskQueryResponse {
|
|
55
|
+
code?: string;
|
|
56
|
+
data?: {
|
|
57
|
+
task_id?: string;
|
|
58
|
+
status?: string;
|
|
59
|
+
result_url?: string;
|
|
60
|
+
fail_reason?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface OpenAIImageGenerationResponse {
|
|
64
|
+
created?: number;
|
|
65
|
+
data?: Array<{
|
|
66
|
+
url?: string;
|
|
67
|
+
b64_json?: string;
|
|
68
|
+
revised_prompt?: string;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
/** 后端图像专用代理 /api/llm/image */
|
|
72
|
+
export declare function getImageProxyConfig(pluginId: string, headers?: Record<string, string>): {
|
|
73
|
+
baseUrl: string;
|
|
74
|
+
headers: Record<string, string>;
|
|
75
|
+
};
|
|
76
|
+
export declare function bytesFromUrl(url: string, signal?: AbortSignal): Promise<GeneratedImageFile>;
|
|
77
|
+
/** POST /api/llm/image/images/tasks */
|
|
78
|
+
export declare function submitImageTask(pluginId: string, body: Record<string, unknown>, signal?: AbortSignal, headers?: Record<string, string>): Promise<KunpoTaskSubmitResponse>;
|
|
79
|
+
/** GET /api/llm/image/images/tasks/:taskId */
|
|
80
|
+
export declare function getImageTask(pluginId: string, taskId: string, signal?: AbortSignal, headers?: Record<string, string>): Promise<KunpoTaskQueryResponse>;
|
|
81
|
+
/** POST /api/llm/image/images/generations(同步,不推荐生产使用) */
|
|
82
|
+
export declare function generateImageSync(pluginId: string, body: Record<string, unknown>, signal?: AbortSignal, headers?: Record<string, string>): Promise<OpenAIImageGenerationResponse>;
|
|
83
|
+
export declare function pollImageTask(pluginId: string, taskId: string, options?: {
|
|
84
|
+
pollIntervalMs?: number;
|
|
85
|
+
pollTimeoutMs?: number;
|
|
86
|
+
abortSignal?: AbortSignal;
|
|
87
|
+
headers?: Record<string, string>;
|
|
88
|
+
}): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* 通过后端 /api/llm/image 代理生成图像(默认异步)
|
|
91
|
+
*/
|
|
92
|
+
export declare function generateKunpoImage(options: KunpoImageGenerationOptions): Promise<KunpoImageGenerationResult>;
|
|
93
|
+
export {};
|