mioku-service-webui 4.10.1 → 4.11.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-service-webui",
3
- "version": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "description": "Mioku WebUI 服务",
5
5
  "main": "index.ts",
6
6
  "type": "module",
package/routes/config.ts CHANGED
@@ -23,7 +23,7 @@ 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,
26
+ onebotInstances: body?.onebotInstances?.length,
27
27
  plugins: body?.plugins?.length,
28
28
  coreConfigured: Boolean(body?.core),
29
29
  });
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,20 +75,13 @@ function normalizeRepositoryUrl(repository: any): string {
76
75
  return url.replace(/\.git$/, "");
77
76
  }
78
77
 
79
- interface NapcatNodeConfig {
80
- name?: string;
78
+ export interface OneBotInstanceConfig {
79
+ protocol?: string;
81
80
  host?: string;
82
81
  port?: number;
83
82
  token?: string;
84
- protocol?: string;
85
- }
86
-
87
- interface MiokiRuntimeConfig {
88
- mioki?: {
89
- napcat?: NapcatNodeConfig[];
90
- [key: string]: any;
91
- };
92
- [key: string]: any;
83
+ reconnect?: boolean;
84
+ [key: string]: unknown;
93
85
  }
94
86
 
95
87
  const SYSTEM_PLUGIN_NAMES = new Set(["chat", "help"]);
@@ -299,7 +291,7 @@ function readPackageJson(dir: string): any {
299
291
 
300
292
  const WEBUI_PLUGIN_PREFIX = "mioku-plugin-";
301
293
 
302
- function appendToMiokiPlugins(cwd: string, pkgName: string): boolean {
294
+ function appendToMiokuPlugins(cwd: string, pkgName: string): boolean {
303
295
  if (!pkgName.startsWith(WEBUI_PLUGIN_PREFIX)) return false;
304
296
  const shortName = pkgName.slice(WEBUI_PLUGIN_PREFIX.length);
305
297
 
@@ -307,12 +299,12 @@ function appendToMiokiPlugins(cwd: string, pkgName: string): boolean {
307
299
  if (!fs.existsSync(packageJsonPath)) return false;
308
300
 
309
301
  const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
310
- const mioki = pkg.mioki ?? {};
311
- const plugins = Array.isArray(mioki.plugins) ? [...mioki.plugins] : [];
302
+ const mioku = pkg.mioku ?? {};
303
+ const plugins = Array.isArray(mioku.plugins) ? [...mioku.plugins] : [];
312
304
  if (plugins.includes(shortName)) return false;
313
305
 
314
306
  plugins.push(shortName);
315
- pkg.mioki = { ...mioki, plugins };
307
+ pkg.mioku = { ...mioku, plugins };
316
308
  fs.writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
317
309
  return true;
318
310
  }
@@ -321,21 +313,12 @@ function readRootPackageJson(): any {
321
313
  return JSON.parse(fs.readFileSync(ROOT_PACKAGE_PATH, "utf-8"));
322
314
  }
323
315
 
324
- function readMiokiPackageJson(): any | null {
325
- const candidates = [
326
- path.join(process.cwd(), "node_modules", "mioku", "package.json"),
327
- path.join(process.cwd(), "..", "node_modules", "mioku", "package.json"),
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
- }
316
+ function readRootPackageJsonSafe(): any {
317
+ try {
318
+ return readRootPackageJson();
319
+ } catch {
320
+ return null;
337
321
  }
338
- return null;
339
322
  }
340
323
 
341
324
  function readMiokuPackageJson(): any | null {
@@ -1073,7 +1056,7 @@ export async function installManagedPackage(
1073
1056
 
1074
1057
  let enabled = false;
1075
1058
  if (input.target === "plugin") {
1076
- enabled = appendToMiokiPlugins(installDir, installedName);
1059
+ enabled = appendToMiokuPlugins(installDir, installedName);
1077
1060
  }
1078
1061
 
1079
1062
  return {
@@ -1230,20 +1213,20 @@ export async function removeManagedPackage(
1230
1213
  throw new Error(`bun remove 失败: ${result.stderr || result.stdout}`);
1231
1214
  }
1232
1215
 
1233
- // clean up mioki.plugins list for plugins
1216
+ // clean up mioku.plugins list for plugins
1234
1217
  if (input.target === "plugin") {
1235
1218
  const pkgPath = ROOT_PACKAGE_PATH;
1236
1219
  if (fs.existsSync(pkgPath)) {
1237
1220
  try {
1238
1221
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1239
- const mioki = pkg.mioki ?? {};
1240
- const plugins: string[] = Array.isArray(mioki.plugins)
1241
- ? mioki.plugins
1222
+ const mioku = pkg.mioku ?? {};
1223
+ const plugins: string[] = Array.isArray(mioku.plugins)
1224
+ ? mioku.plugins
1242
1225
  : [];
1243
1226
  const shortName = fullName.replace(/^mioku-plugin-/, "");
1244
1227
  if (plugins.includes(shortName)) {
1245
- pkg.mioki = {
1246
- ...mioki,
1228
+ pkg.mioku = {
1229
+ ...mioku,
1247
1230
  plugins: plugins.filter((p: string) => p !== shortName),
1248
1231
  };
1249
1232
  fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
@@ -2376,15 +2359,6 @@ export async function getSystemOverview(): Promise<Record<string, any>> {
2376
2359
  nodeVersion: process.version,
2377
2360
  },
2378
2361
  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
2362
  mioku: (() => {
2389
2363
  const miokuPkg = readMiokuPackageJson();
2390
2364
  if (miokuPkg?.version) return normalizeVersionSpec(miokuPkg.version);
@@ -2454,31 +2428,56 @@ export function updateAdapterConfig(adapterName: string, data: any): any {
2454
2428
  }
2455
2429
 
2456
2430
  export interface MiokuConfig {
2457
- owners: number[];
2458
- admins: number[];
2459
- napcat: Array<{
2460
- name: string;
2461
- protocol: string;
2462
- port: number;
2463
- host: string;
2464
- token: string;
2465
- }>;
2431
+ owners: string[];
2432
+ admins: string[];
2466
2433
  plugins: string[];
2434
+ onebotInstances: OneBotInstanceConfig[];
2467
2435
  core: CoreSystemConfig;
2468
2436
  }
2469
2437
 
2470
- export function getMiokuConfig(): MiokuConfig {
2471
- const localConfig = readJsonFile<any>(LOCAL_CONFIG_PATH, null);
2472
- const rootPkg = readRootPackageJson();
2438
+ function toStringArray(input: unknown): string[] {
2439
+ return Array.isArray(input) ? input.map((v) => String(v)) : [];
2440
+ }
2473
2441
 
2474
- const miokiConfig =
2475
- localConfig && localConfig.mioki ? localConfig.mioki : rootPkg?.mioki || {};
2442
+ function normalizeOneBotInstances(input: unknown): OneBotInstanceConfig[] {
2443
+ if (!Array.isArray(input)) return [];
2444
+ return input
2445
+ .filter((item) => item && typeof item === "object")
2446
+ .map((item: any) => ({
2447
+ ...item,
2448
+ protocol: item.protocol === "wss" ? "wss" : "ws",
2449
+ host: typeof item.host === "string" && item.host ? item.host : "localhost",
2450
+ port:
2451
+ typeof item.port === "number" && Number.isFinite(item.port)
2452
+ ? item.port
2453
+ : 3001,
2454
+ token: typeof item.token === "string" ? item.token : "",
2455
+ reconnect: item.reconnect !== false,
2456
+ }));
2457
+ }
2458
+
2459
+ function getOneBotInstancesFromPkg(miokuConfig: any): OneBotInstanceConfig[] {
2460
+ const adapters =
2461
+ miokuConfig && typeof miokuConfig === "object" ? miokuConfig.adapters : null;
2462
+ const onebotv11 =
2463
+ adapters && typeof adapters === "object" ? adapters.onebotv11 : null;
2464
+ const instances =
2465
+ onebotv11 && typeof onebotv11 === "object" ? onebotv11.instances : null;
2466
+ return normalizeOneBotInstances(instances);
2467
+ }
2468
+
2469
+ export function getMiokuConfig(): MiokuConfig {
2470
+ const rootPkg = readRootPackageJsonSafe();
2471
+ const miokuConfig =
2472
+ rootPkg && typeof rootPkg.mioku === "object" && rootPkg.mioku !== null
2473
+ ? rootPkg.mioku
2474
+ : {};
2476
2475
 
2477
2476
  return {
2478
- owners: Array.isArray(miokiConfig.owners) ? miokiConfig.owners : [],
2479
- admins: Array.isArray(miokiConfig.admins) ? miokiConfig.admins : [],
2480
- napcat: Array.isArray(miokiConfig.napcat) ? miokiConfig.napcat : [],
2481
- plugins: Array.isArray(miokiConfig.plugins) ? miokiConfig.plugins : [],
2477
+ owners: toStringArray(miokuConfig.owners),
2478
+ admins: toStringArray(miokuConfig.admins),
2479
+ plugins: toStringArray(miokuConfig.plugins),
2480
+ onebotInstances: getOneBotInstancesFromPkg(miokuConfig),
2482
2481
  core: getCoreSystemConfig(),
2483
2482
  };
2484
2483
  }
@@ -2486,31 +2485,44 @@ export function getMiokuConfig(): MiokuConfig {
2486
2485
  export function updateMiokuConfig(config: Partial<MiokuConfig>): MiokuConfig {
2487
2486
  const current = getMiokuConfig();
2488
2487
  const updated: MiokuConfig = {
2489
- owners: Array.isArray(config.owners) ? config.owners : current.owners,
2490
- admins: Array.isArray(config.admins) ? config.admins : current.admins,
2491
- napcat: Array.isArray(config.napcat) ? config.napcat : current.napcat,
2492
- plugins: Array.isArray(config.plugins) ? config.plugins : current.plugins,
2488
+ owners: Array.isArray(config.owners)
2489
+ ? config.owners.map((v) => String(v))
2490
+ : current.owners,
2491
+ admins: Array.isArray(config.admins)
2492
+ ? config.admins.map((v) => String(v))
2493
+ : current.admins,
2494
+ plugins: Array.isArray(config.plugins)
2495
+ ? config.plugins.map((v) => String(v))
2496
+ : current.plugins,
2497
+ onebotInstances: Array.isArray(config.onebotInstances)
2498
+ ? normalizeOneBotInstances(config.onebotInstances)
2499
+ : current.onebotInstances,
2493
2500
  core: config.core ? updateCoreSystemConfig(config.core) : current.core,
2494
2501
  };
2495
2502
 
2496
- const localConfig = readJsonFile<any>(LOCAL_CONFIG_PATH, { mioki: {} });
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
-
2506
2503
  const rootPkg = readRootPackageJson();
2507
- if (rootPkg.mioki) {
2508
- rootPkg.mioki.owners = updated.owners;
2509
- rootPkg.mioki.admins = updated.admins;
2510
- rootPkg.mioki.napcat = updated.napcat;
2511
- rootPkg.mioki.plugins = updated.plugins;
2512
- writeRootPackageJson(rootPkg);
2513
- }
2504
+ const miokuConfig =
2505
+ typeof rootPkg.mioku === "object" && rootPkg.mioku !== null
2506
+ ? rootPkg.mioku
2507
+ : {};
2508
+
2509
+ miokuConfig.owners = updated.owners;
2510
+ miokuConfig.admins = updated.admins;
2511
+ miokuConfig.plugins = updated.plugins;
2512
+
2513
+ const adapters =
2514
+ typeof miokuConfig.adapters === "object" && miokuConfig.adapters !== null
2515
+ ? miokuConfig.adapters
2516
+ : {};
2517
+ const onebotv11 =
2518
+ typeof adapters.onebotv11 === "object" && adapters.onebotv11 !== null
2519
+ ? adapters.onebotv11
2520
+ : {};
2521
+ adapters.onebotv11 = { ...onebotv11, instances: updated.onebotInstances };
2522
+ miokuConfig.adapters = adapters;
2523
+
2524
+ rootPkg.mioku = miokuConfig;
2525
+ writeRootPackageJson(rootPkg);
2514
2526
 
2515
2527
  return updated;
2516
2528
  }
@@ -2519,9 +2531,9 @@ export function getAvailablePlugins(): string[] {
2519
2531
  const modulesPath = NODE_MODULES_DIR;
2520
2532
  if (!fs.existsSync(modulesPath)) {
2521
2533
  // Fallback to config-based reading
2522
- const rootPkg = readRootPackageJson();
2523
- const miokiConfig = rootPkg?.mioki || {};
2524
- return Array.isArray(miokiConfig.plugins) ? miokiConfig.plugins : [];
2534
+ const rootPkg = readRootPackageJsonSafe();
2535
+ const miokuConfig = rootPkg?.mioku || {};
2536
+ return Array.isArray(miokuConfig.plugins) ? miokuConfig.plugins : [];
2525
2537
  }
2526
2538
 
2527
2539
  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();