mioku-service-webui 4.10.1 → 4.11.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/package.json +1 -1
- package/routes/config.ts +0 -1
- package/system.ts +54 -93
- package/utils.ts +0 -1
package/package.json
CHANGED
package/routes/config.ts
CHANGED
|
@@ -23,7 +23,6 @@ export function createConfigRoutes() {
|
|
|
23
23
|
logger.info(`[webui-action] config.mioku.update`, {
|
|
24
24
|
owners: body?.owners?.length,
|
|
25
25
|
admins: body?.admins?.length,
|
|
26
|
-
napcat: body?.napcat?.length,
|
|
27
26
|
plugins: body?.plugins?.length,
|
|
28
27
|
coreConfigured: Boolean(body?.core),
|
|
29
28
|
});
|
package/system.ts
CHANGED
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
isNpmPackageName,
|
|
26
26
|
isPackageDir,
|
|
27
27
|
isValidRepoUrl,
|
|
28
|
-
LOCAL_CONFIG_PATH,
|
|
29
28
|
NODE_MODULES_DIR,
|
|
30
29
|
normalizeManagedPackageName,
|
|
31
30
|
PLUGINS_DIR,
|
|
@@ -76,22 +75,6 @@ function normalizeRepositoryUrl(repository: any): string {
|
|
|
76
75
|
return url.replace(/\.git$/, "");
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
interface NapcatNodeConfig {
|
|
80
|
-
name?: string;
|
|
81
|
-
host?: string;
|
|
82
|
-
port?: number;
|
|
83
|
-
token?: string;
|
|
84
|
-
protocol?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface MiokiRuntimeConfig {
|
|
88
|
-
mioki?: {
|
|
89
|
-
napcat?: NapcatNodeConfig[];
|
|
90
|
-
[key: string]: any;
|
|
91
|
-
};
|
|
92
|
-
[key: string]: any;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
78
|
const SYSTEM_PLUGIN_NAMES = new Set(["chat", "help"]);
|
|
96
79
|
const SYSTEM_SERVICE_NAMES = new Set(["ai", "config", "help", "screenshot"]);
|
|
97
80
|
const CORE_CONFIG_PATH = path.join(
|
|
@@ -299,7 +282,7 @@ function readPackageJson(dir: string): any {
|
|
|
299
282
|
|
|
300
283
|
const WEBUI_PLUGIN_PREFIX = "mioku-plugin-";
|
|
301
284
|
|
|
302
|
-
function
|
|
285
|
+
function appendToMiokuPlugins(cwd: string, pkgName: string): boolean {
|
|
303
286
|
if (!pkgName.startsWith(WEBUI_PLUGIN_PREFIX)) return false;
|
|
304
287
|
const shortName = pkgName.slice(WEBUI_PLUGIN_PREFIX.length);
|
|
305
288
|
|
|
@@ -307,12 +290,12 @@ function appendToMiokiPlugins(cwd: string, pkgName: string): boolean {
|
|
|
307
290
|
if (!fs.existsSync(packageJsonPath)) return false;
|
|
308
291
|
|
|
309
292
|
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
310
|
-
const
|
|
311
|
-
const plugins = Array.isArray(
|
|
293
|
+
const mioku = pkg.mioku ?? {};
|
|
294
|
+
const plugins = Array.isArray(mioku.plugins) ? [...mioku.plugins] : [];
|
|
312
295
|
if (plugins.includes(shortName)) return false;
|
|
313
296
|
|
|
314
297
|
plugins.push(shortName);
|
|
315
|
-
pkg.
|
|
298
|
+
pkg.mioku = { ...mioku, plugins };
|
|
316
299
|
fs.writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
317
300
|
return true;
|
|
318
301
|
}
|
|
@@ -321,21 +304,12 @@ function readRootPackageJson(): any {
|
|
|
321
304
|
return JSON.parse(fs.readFileSync(ROOT_PACKAGE_PATH, "utf-8"));
|
|
322
305
|
}
|
|
323
306
|
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
for (const candidate of candidates) {
|
|
330
|
-
if (fs.existsSync(candidate)) {
|
|
331
|
-
try {
|
|
332
|
-
return JSON.parse(fs.readFileSync(candidate, "utf-8"));
|
|
333
|
-
} catch {
|
|
334
|
-
// ignore
|
|
335
|
-
}
|
|
336
|
-
}
|
|
307
|
+
function readRootPackageJsonSafe(): any {
|
|
308
|
+
try {
|
|
309
|
+
return readRootPackageJson();
|
|
310
|
+
} catch {
|
|
311
|
+
return null;
|
|
337
312
|
}
|
|
338
|
-
return null;
|
|
339
313
|
}
|
|
340
314
|
|
|
341
315
|
function readMiokuPackageJson(): any | null {
|
|
@@ -1073,7 +1047,7 @@ export async function installManagedPackage(
|
|
|
1073
1047
|
|
|
1074
1048
|
let enabled = false;
|
|
1075
1049
|
if (input.target === "plugin") {
|
|
1076
|
-
enabled =
|
|
1050
|
+
enabled = appendToMiokuPlugins(installDir, installedName);
|
|
1077
1051
|
}
|
|
1078
1052
|
|
|
1079
1053
|
return {
|
|
@@ -1230,20 +1204,20 @@ export async function removeManagedPackage(
|
|
|
1230
1204
|
throw new Error(`bun remove 失败: ${result.stderr || result.stdout}`);
|
|
1231
1205
|
}
|
|
1232
1206
|
|
|
1233
|
-
// clean up
|
|
1207
|
+
// clean up mioku.plugins list for plugins
|
|
1234
1208
|
if (input.target === "plugin") {
|
|
1235
1209
|
const pkgPath = ROOT_PACKAGE_PATH;
|
|
1236
1210
|
if (fs.existsSync(pkgPath)) {
|
|
1237
1211
|
try {
|
|
1238
1212
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1239
|
-
const
|
|
1240
|
-
const plugins: string[] = Array.isArray(
|
|
1241
|
-
?
|
|
1213
|
+
const mioku = pkg.mioku ?? {};
|
|
1214
|
+
const plugins: string[] = Array.isArray(mioku.plugins)
|
|
1215
|
+
? mioku.plugins
|
|
1242
1216
|
: [];
|
|
1243
1217
|
const shortName = fullName.replace(/^mioku-plugin-/, "");
|
|
1244
1218
|
if (plugins.includes(shortName)) {
|
|
1245
|
-
pkg.
|
|
1246
|
-
...
|
|
1219
|
+
pkg.mioku = {
|
|
1220
|
+
...mioku,
|
|
1247
1221
|
plugins: plugins.filter((p: string) => p !== shortName),
|
|
1248
1222
|
};
|
|
1249
1223
|
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
@@ -2376,15 +2350,6 @@ export async function getSystemOverview(): Promise<Record<string, any>> {
|
|
|
2376
2350
|
nodeVersion: process.version,
|
|
2377
2351
|
},
|
|
2378
2352
|
versions: {
|
|
2379
|
-
mioki: (() => {
|
|
2380
|
-
const miokiPkg = readMiokiPackageJson();
|
|
2381
|
-
if (miokiPkg?.version) return normalizeVersionSpec(miokiPkg.version);
|
|
2382
|
-
return normalizeVersionSpec(
|
|
2383
|
-
rootPkg?.dependencies?.mioki ||
|
|
2384
|
-
rootPkg?.devDependencies?.mioki ||
|
|
2385
|
-
"unknown",
|
|
2386
|
-
);
|
|
2387
|
-
})(),
|
|
2388
2353
|
mioku: (() => {
|
|
2389
2354
|
const miokuPkg = readMiokuPackageJson();
|
|
2390
2355
|
if (miokuPkg?.version) return normalizeVersionSpec(miokuPkg.version);
|
|
@@ -2454,31 +2419,27 @@ export function updateAdapterConfig(adapterName: string, data: any): any {
|
|
|
2454
2419
|
}
|
|
2455
2420
|
|
|
2456
2421
|
export interface MiokuConfig {
|
|
2457
|
-
owners:
|
|
2458
|
-
admins:
|
|
2459
|
-
napcat: Array<{
|
|
2460
|
-
name: string;
|
|
2461
|
-
protocol: string;
|
|
2462
|
-
port: number;
|
|
2463
|
-
host: string;
|
|
2464
|
-
token: string;
|
|
2465
|
-
}>;
|
|
2422
|
+
owners: string[];
|
|
2423
|
+
admins: string[];
|
|
2466
2424
|
plugins: string[];
|
|
2467
2425
|
core: CoreSystemConfig;
|
|
2468
2426
|
}
|
|
2469
2427
|
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2428
|
+
function toStringArray(input: unknown): string[] {
|
|
2429
|
+
return Array.isArray(input) ? input.map((v) => String(v)) : [];
|
|
2430
|
+
}
|
|
2473
2431
|
|
|
2474
|
-
|
|
2475
|
-
|
|
2432
|
+
export function getMiokuConfig(): MiokuConfig {
|
|
2433
|
+
const rootPkg = readRootPackageJsonSafe();
|
|
2434
|
+
const miokuConfig =
|
|
2435
|
+
rootPkg && typeof rootPkg.mioku === "object" && rootPkg.mioku !== null
|
|
2436
|
+
? rootPkg.mioku
|
|
2437
|
+
: {};
|
|
2476
2438
|
|
|
2477
2439
|
return {
|
|
2478
|
-
owners:
|
|
2479
|
-
admins:
|
|
2480
|
-
|
|
2481
|
-
plugins: Array.isArray(miokiConfig.plugins) ? miokiConfig.plugins : [],
|
|
2440
|
+
owners: toStringArray(miokuConfig.owners),
|
|
2441
|
+
admins: toStringArray(miokuConfig.admins),
|
|
2442
|
+
plugins: toStringArray(miokuConfig.plugins),
|
|
2482
2443
|
core: getCoreSystemConfig(),
|
|
2483
2444
|
};
|
|
2484
2445
|
}
|
|
@@ -2486,31 +2447,31 @@ export function getMiokuConfig(): MiokuConfig {
|
|
|
2486
2447
|
export function updateMiokuConfig(config: Partial<MiokuConfig>): MiokuConfig {
|
|
2487
2448
|
const current = getMiokuConfig();
|
|
2488
2449
|
const updated: MiokuConfig = {
|
|
2489
|
-
owners: Array.isArray(config.owners)
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2450
|
+
owners: Array.isArray(config.owners)
|
|
2451
|
+
? config.owners.map((v) => String(v))
|
|
2452
|
+
: current.owners,
|
|
2453
|
+
admins: Array.isArray(config.admins)
|
|
2454
|
+
? config.admins.map((v) => String(v))
|
|
2455
|
+
: current.admins,
|
|
2456
|
+
plugins: Array.isArray(config.plugins)
|
|
2457
|
+
? config.plugins.map((v) => String(v))
|
|
2458
|
+
: current.plugins,
|
|
2493
2459
|
core: config.core ? updateCoreSystemConfig(config.core) : current.core,
|
|
2494
2460
|
};
|
|
2495
2461
|
|
|
2496
|
-
|
|
2497
|
-
localConfig.mioki = {
|
|
2498
|
-
...localConfig.mioki,
|
|
2499
|
-
owners: updated.owners,
|
|
2500
|
-
admins: updated.admins,
|
|
2501
|
-
napcat: updated.napcat,
|
|
2502
|
-
plugins: updated.plugins,
|
|
2503
|
-
};
|
|
2504
|
-
writeJsonFile(LOCAL_CONFIG_PATH, localConfig);
|
|
2505
|
-
|
|
2462
|
+
// 适配器配置(mioku.adapters)由适配器配置页维护,这里不再改写
|
|
2506
2463
|
const rootPkg = readRootPackageJson();
|
|
2507
|
-
|
|
2508
|
-
rootPkg.
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2464
|
+
const miokuConfig =
|
|
2465
|
+
typeof rootPkg.mioku === "object" && rootPkg.mioku !== null
|
|
2466
|
+
? rootPkg.mioku
|
|
2467
|
+
: {};
|
|
2468
|
+
|
|
2469
|
+
miokuConfig.owners = updated.owners;
|
|
2470
|
+
miokuConfig.admins = updated.admins;
|
|
2471
|
+
miokuConfig.plugins = updated.plugins;
|
|
2472
|
+
|
|
2473
|
+
rootPkg.mioku = miokuConfig;
|
|
2474
|
+
writeRootPackageJson(rootPkg);
|
|
2514
2475
|
|
|
2515
2476
|
return updated;
|
|
2516
2477
|
}
|
|
@@ -2519,9 +2480,9 @@ export function getAvailablePlugins(): string[] {
|
|
|
2519
2480
|
const modulesPath = NODE_MODULES_DIR;
|
|
2520
2481
|
if (!fs.existsSync(modulesPath)) {
|
|
2521
2482
|
// Fallback to config-based reading
|
|
2522
|
-
const rootPkg =
|
|
2523
|
-
const
|
|
2524
|
-
return Array.isArray(
|
|
2483
|
+
const rootPkg = readRootPackageJsonSafe();
|
|
2484
|
+
const miokuConfig = rootPkg?.mioku || {};
|
|
2485
|
+
return Array.isArray(miokuConfig.plugins) ? miokuConfig.plugins : [];
|
|
2525
2486
|
}
|
|
2526
2487
|
|
|
2527
2488
|
const plugins: string[] = [];
|
package/utils.ts
CHANGED
|
@@ -20,7 +20,6 @@ export const SETTINGS_PATH = path.join(
|
|
|
20
20
|
);
|
|
21
21
|
export const AUTH_PATH = path.join(getServiceConfigDir("webui"), "auth.json");
|
|
22
22
|
export const ROOT_PACKAGE_PATH = path.join(process.cwd(), "package.json");
|
|
23
|
-
export const LOCAL_CONFIG_PATH = path.join(getConfigDir(), "mioku.json");
|
|
24
23
|
|
|
25
24
|
export const WEBUI_DIST = path.join(__dirname, "dist");
|
|
26
25
|
export const CONFIG_DIR = getConfigDir();
|