mioku 1.3.0 → 1.3.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/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_exec = require('./exec-CQ79KQZ-.cjs');
1
+ const require_exec = require('./exec-BoUCPBk_.cjs');
2
2
  const node_fs = require_exec.__toESM(require("node:fs"));
3
3
  const node_path = require_exec.__toESM(require("node:path"));
4
4
  const node_url = require_exec.__toESM(require("node:url"));
@@ -172,8 +172,8 @@ const RAW_TEXT_DECODER = new TextDecoder();
172
172
  const decodeBody = async (response) => {
173
173
  const arrayBuffer = await response.arrayBuffer();
174
174
  const headers = {};
175
- response.headers.forEach((value, key) => {
176
- headers[key.toLowerCase()] = value;
175
+ response.headers.forEach((value, key$1) => {
176
+ headers[key$1.toLowerCase()] = value;
177
177
  });
178
178
  return {
179
179
  body: new Uint8Array(arrayBuffer),
@@ -844,8 +844,8 @@ const definePlugin = (plugin) => plugin;
844
844
  //#endregion
845
845
  //#region src/runtime/context.ts
846
846
  var AdapterRegistrationConflictError = class extends Error {
847
- constructor(key) {
848
- super(`Bot already registered for ${key}`);
847
+ constructor(key$1) {
848
+ super(`Bot already registered for ${key$1}`);
849
849
  this.name = "AdapterRegistrationConflictError";
850
850
  }
851
851
  };
@@ -920,8 +920,8 @@ var AdapterContextImpl = class {
920
920
  if (!gateway) throw new Error(`Resource references unknown gateway "${resource.gateway}"`);
921
921
  }
922
922
  if (resource.scope === "bot") {
923
- const key = `${this.#state.definition.name}:${resource.bot_id}`;
924
- if (!this.#bots.has(key)) throw new Error(`Resource references unknown bot "${resource.bot_id}"`);
923
+ const key$1 = `${this.#state.definition.name}:${resource.bot_id}`;
924
+ if (!this.#bots.has(key$1)) throw new Error(`Resource references unknown bot "${resource.bot_id}"`);
925
925
  }
926
926
  this.#state.resources.push(resource);
927
927
  return () => {
@@ -974,10 +974,10 @@ function store$2() {
974
974
  if (!g[STORE_SYMBOL]) g[STORE_SYMBOL] = {};
975
975
  return g[STORE_SYMBOL];
976
976
  }
977
- function getOrCreate(key, factory) {
977
+ function getOrCreate(key$1, factory) {
978
978
  const s = store$2();
979
- if (s[key] === void 0) s[key] = factory();
980
- return s[key];
979
+ if (s[key$1] === void 0) s[key$1] = factory();
980
+ return s[key$1];
981
981
  }
982
982
 
983
983
  //#endregion
@@ -995,37 +995,37 @@ var BotRegistry = class {
995
995
  #disposers = new Map();
996
996
  /** 登记一个 bot,返回可注销的上下文 */
997
997
  register(bot) {
998
- const key = connectedBotKey(bot.adapter, bot.bot_id);
999
- if (this.#bots.has(key)) throw new AdapterRegistrationConflictError(key);
1000
- this.#bots.set(key, {
998
+ const key$1 = connectedBotKey(bot.adapter, bot.bot_id);
999
+ if (this.#bots.has(key$1)) throw new AdapterRegistrationConflictError(key$1);
1000
+ this.#bots.set(key$1, {
1001
1001
  adapter: bot.adapter,
1002
1002
  bot_id: bot.bot_id,
1003
1003
  bot
1004
1004
  });
1005
- connectedBots.set(key, bot);
1005
+ connectedBots.set(key$1, bot);
1006
1006
  const dispose = () => {
1007
1007
  this.unregister(bot.bot_id, bot.adapter);
1008
1008
  };
1009
- this.#disposers.set(key, dispose);
1009
+ this.#disposers.set(key$1, dispose);
1010
1010
  return {
1011
1011
  bot,
1012
1012
  unregister: dispose
1013
1013
  };
1014
1014
  }
1015
- has(key) {
1016
- return this.#bots.has(key);
1015
+ has(key$1) {
1016
+ return this.#bots.has(key$1);
1017
1017
  }
1018
1018
  unregister(bot_id, adapter) {
1019
- const key = connectedBotKey(adapter, bot_id);
1020
- const removed = this.#bots.delete(key);
1021
- this.#disposers.delete(key);
1022
- connectedBots.delete(key);
1019
+ const key$1 = connectedBotKey(adapter, bot_id);
1020
+ const removed = this.#bots.delete(key$1);
1021
+ this.#disposers.delete(key$1);
1022
+ connectedBots.delete(key$1);
1023
1023
  return removed;
1024
1024
  }
1025
1025
  /** 按 bot_id 取 bot(只按 id 匹配,不限适配器) */
1026
1026
  pick(bot_id) {
1027
- const key = String(bot_id);
1028
- for (const entry of this.#bots.values()) if (entry.bot_id === key) return entry.bot;
1027
+ const key$1 = String(bot_id);
1028
+ for (const entry of this.#bots.values()) if (entry.bot_id === key$1) return entry.bot;
1029
1029
  return void 0;
1030
1030
  }
1031
1031
  find(adapter, bot_id) {
@@ -1405,23 +1405,23 @@ const getGTk = (pskey) => {
1405
1405
  */
1406
1406
  const match = async (event, pattern, quote = true) => {
1407
1407
  const inputText = event.message.text();
1408
- for (const [key, value] of Object.entries(pattern)) {
1408
+ for (const [key$1, value] of Object.entries(pattern)) {
1409
1409
  let isMatched = false;
1410
1410
  let matches = null;
1411
- const isRegExp = key.startsWith("/") && key.endsWith("/");
1412
- const hasWildcard = key.includes("*");
1411
+ const isRegExp = key$1.startsWith("/") && key$1.endsWith("/");
1412
+ const hasWildcard = key$1.includes("*");
1413
1413
  if (isRegExp) try {
1414
- const regex = new RegExp(key.slice(1, -1));
1414
+ const regex = new RegExp(key$1.slice(1, -1));
1415
1415
  matches = inputText.match(regex);
1416
1416
  if (matches) isMatched = true;
1417
1417
  } catch (err) {
1418
- throw new Error(`无效的正则表达式: ${key}`, { cause: err });
1418
+ throw new Error(`无效的正则表达式: ${key$1}`, { cause: err });
1419
1419
  }
1420
1420
  else if (hasWildcard) {
1421
- const regex = new RegExp(`^${key.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`);
1421
+ const regex = new RegExp(`^${key$1.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`);
1422
1422
  matches = inputText.match(regex);
1423
1423
  if (matches) isMatched = true;
1424
- } else if (key === inputText) isMatched = true;
1424
+ } else if (key$1 === inputText) isMatched = true;
1425
1425
  if (!isMatched) continue;
1426
1426
  const result = typeof value === "function" ? await value(matches, event) : value;
1427
1427
  if (result) {
@@ -1894,6 +1894,47 @@ var ServiceManager = class ServiceManager {
1894
1894
  };
1895
1895
  var manager_default = ServiceManager.getInstance();
1896
1896
 
1897
+ //#endregion
1898
+ //#region src/services/config-defaults.ts
1899
+ const defaults = new Map();
1900
+ function key(scope, owner, name) {
1901
+ return `${scope}\u0000${owner}\u0000${name}`;
1902
+ }
1903
+ /** 登记一份配置的默认值;同名重复登记以最后一次为准 */
1904
+ function registerConfigDefaults(scope, owner, name, value) {
1905
+ if (!value || typeof value !== "object") return;
1906
+ defaults.set(key(scope, owner, name), clone(value));
1907
+ }
1908
+ /** 取默认值(深拷贝,调用方随便改);没有登记时返回 undefined */
1909
+ function getConfigDefaults(scope, owner, name) {
1910
+ const stored = defaults.get(key(scope, owner, name));
1911
+ return stored ? clone(stored) : void 0;
1912
+ }
1913
+ function isPlainObject$1(value) {
1914
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1915
+ }
1916
+ function clone(value) {
1917
+ return JSON.parse(JSON.stringify(value));
1918
+ }
1919
+ /**
1920
+ * 用默认值补齐一份配置
1921
+ */
1922
+ function withConfigDefaults(stored, fallback) {
1923
+ const base = fallback ? clone(fallback) : {};
1924
+ return mergeInto(base, stored);
1925
+ }
1926
+ function mergeInto(base, overrides) {
1927
+ if (!isPlainObject$1(overrides)) return base;
1928
+ for (const [name, value] of Object.entries(overrides)) {
1929
+ if (value === void 0 || value === null) continue;
1930
+ if (isPlainObject$1(value)) {
1931
+ const current = base[name];
1932
+ base[name] = mergeInto(isPlainObject$1(current) ? current : {}, value);
1933
+ } else base[name] = Array.isArray(value) ? [...value] : value;
1934
+ }
1935
+ return base;
1936
+ }
1937
+
1897
1938
  //#endregion
1898
1939
  //#region src/services/config.ts
1899
1940
  const SERVICE_CONFIG_ROOT = "service";
@@ -1908,21 +1949,35 @@ function ensureDir(serviceName) {
1908
1949
  const dir = resolveConfigDir(serviceName);
1909
1950
  if (!(0, fs.existsSync)(dir)) (0, fs.mkdirSync)(dir, { recursive: true });
1910
1951
  }
1911
- /** 注册服务配置:文件不存在时把 defaults 写入磁盘 */
1912
- async function registerServiceConfig(serviceName, configName, defaults) {
1952
+ /**
1953
+ * 注册服务配
1954
+ */
1955
+ async function registerServiceConfig(serviceName, configName, defaults$1) {
1913
1956
  ensureDir(serviceName);
1957
+ registerConfigDefaults("service", serviceName, configName, defaults$1);
1914
1958
  const configPath = resolveConfigPath(serviceName, configName);
1915
- if (!(0, fs.existsSync)(configPath)) await fs_promises.writeFile(configPath, JSON.stringify(defaults, null, 2), "utf-8");
1959
+ if (!(0, fs.existsSync)(configPath)) {
1960
+ await fs_promises.writeFile(configPath, JSON.stringify(defaults$1, null, 2), "utf-8");
1961
+ return;
1962
+ }
1963
+ try {
1964
+ const existing = JSON.parse(await fs_promises.readFile(configPath, "utf-8"));
1965
+ const merged = withConfigDefaults(existing, defaults$1);
1966
+ if (JSON.stringify(merged) !== JSON.stringify(existing)) await fs_promises.writeFile(configPath, JSON.stringify(merged, null, 2), "utf-8");
1967
+ } catch (error) {
1968
+ rootLogger.warn(`[service-config] 补全 ${serviceName}/${configName} 失败: ${error}`);
1969
+ }
1916
1970
  }
1917
1971
  /** 读取服务配置,文件不存在或解析失败时返回空对象 */
1918
1972
  async function getServiceConfig(serviceName, configName) {
1919
1973
  const configPath = resolveConfigPath(serviceName, configName);
1974
+ const fallback = getConfigDefaults("service", serviceName, configName);
1920
1975
  try {
1921
- return JSON.parse(await fs_promises.readFile(configPath, "utf-8"));
1976
+ return withConfigDefaults(JSON.parse(await fs_promises.readFile(configPath, "utf-8")), fallback);
1922
1977
  } catch (error) {
1923
- if (!(0, fs.existsSync)(configPath)) return {};
1978
+ if (!(0, fs.existsSync)(configPath)) return fallback ?? {};
1924
1979
  rootLogger.warn(`[service-config] 读取 ${serviceName}/${configName} 失败: ${error}`);
1925
- return {};
1980
+ return fallback ?? {};
1926
1981
  }
1927
1982
  }
1928
1983
  /** 覆盖写入服务配置 */
@@ -1936,10 +1991,13 @@ async function getServiceConfigs(serviceName) {
1936
1991
  if (!(0, fs.existsSync)(dir)) return {};
1937
1992
  const result = {};
1938
1993
  const files = (await fs_promises.readdir(dir)).filter((name) => name.endsWith(".json"));
1939
- for (const file of files) try {
1940
- result[path.basename(file, ".json")] = JSON.parse(await fs_promises.readFile(path.join(dir, file), "utf-8"));
1941
- } catch (error) {
1942
- rootLogger.warn(`[service-config] 读取 ${serviceName}/${file} 失败: ${error}`);
1994
+ for (const file of files) {
1995
+ const configName = path.basename(file, ".json");
1996
+ try {
1997
+ result[configName] = withConfigDefaults(JSON.parse(await fs_promises.readFile(path.join(dir, file), "utf-8")), getConfigDefaults("service", serviceName, configName));
1998
+ } catch (error) {
1999
+ rootLogger.warn(`[service-config] 读取 ${serviceName}/${file} 失败: ${error}`);
2000
+ }
1943
2001
  }
1944
2002
  return result;
1945
2003
  }
@@ -2345,7 +2403,7 @@ const canonicalJson = (value) => {
2345
2403
  if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
2346
2404
  if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
2347
2405
  const obj = value;
2348
- return `{${Object.keys(obj).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(obj[key])}`).join(",")}}`;
2406
+ return `{${Object.keys(obj).sort().map((key$1) => `${JSON.stringify(key$1)}:${canonicalJson(obj[key$1])}`).join(",")}}`;
2349
2407
  };
2350
2408
  /** 结构化载荷(json/xml/ark)的稳定摘要 */
2351
2409
  const structuredDigest = (raw) => {
@@ -2366,9 +2424,9 @@ const normalizeMediaUrl = (raw) => {
2366
2424
  try {
2367
2425
  const url = new URL(raw);
2368
2426
  const kept = new URLSearchParams();
2369
- for (const key of MEDIA_URL_QUERY_KEYS) {
2370
- const value = url.searchParams.get(key);
2371
- if (value) kept.set(key, value);
2427
+ for (const key$1 of MEDIA_URL_QUERY_KEYS) {
2428
+ const value = url.searchParams.get(key$1);
2429
+ if (value) kept.set(key$1, value);
2372
2430
  }
2373
2431
  const query = kept.toString();
2374
2432
  return `${url.host}${url.pathname}${query ? `?${query}` : ""}`;
@@ -2390,7 +2448,7 @@ const mediaDigest = (data) => {
2390
2448
  if (md5$1) return `h:${md5$1}`;
2391
2449
  const sha1 = firstHex(data.sha1, HEX40);
2392
2450
  if (sha1) return `h:${sha1}`;
2393
- for (const key of [
2451
+ for (const key$1 of [
2394
2452
  "file_unique",
2395
2453
  "file_id",
2396
2454
  "fid",
@@ -2398,19 +2456,19 @@ const mediaDigest = (data) => {
2398
2456
  "file",
2399
2457
  "name"
2400
2458
  ]) {
2401
- const hex = firstHex(data[key], HEX32);
2459
+ const hex = firstHex(data[key$1], HEX32);
2402
2460
  if (hex) return `h:${hex}`;
2403
2461
  }
2404
2462
  const url = data.url;
2405
2463
  if (typeof url === "string" && url) return `u:${normalizeMediaUrl(url)}`;
2406
- for (const key of [
2464
+ for (const key$1 of [
2407
2465
  "file",
2408
2466
  "file_id",
2409
2467
  "fid",
2410
2468
  "id",
2411
2469
  "name"
2412
2470
  ]) {
2413
- const value = data[key];
2471
+ const value = data[key$1];
2414
2472
  if (typeof value === "string" && value) return `r:${value.toLowerCase()}`;
2415
2473
  }
2416
2474
  return "";
@@ -2517,27 +2575,27 @@ var EventCorrelator = class {
2517
2575
  if (cached) return cached;
2518
2576
  const located = this.#locate(event);
2519
2577
  if (!located) return null;
2520
- const { key, ttl } = located;
2578
+ const { key: key$1, ttl } = located;
2521
2579
  const now = Date.now();
2522
2580
  this.#observed++;
2523
- let group = this.#groups.get(key);
2581
+ let group = this.#groups.get(key$1);
2524
2582
  let duplicate = false;
2525
2583
  if (group && group.expiresAt >= now) {
2526
2584
  duplicate = true;
2527
2585
  this.#duplicates++;
2528
2586
  const participant = participantOf(event);
2529
2587
  if (!group.participants.some((item) => sameParticipant(item, participant))) group.participants.push(participant);
2530
- this.#logger?.debug(`去重命中: key=${key} adapter=${participant.adapter} bot=${participant.botId ?? ""} primary=${group.primary.adapter}:${group.primary.botId ?? ""}`);
2588
+ this.#logger?.debug(`去重命中: key=${key$1} adapter=${participant.adapter} bot=${participant.botId ?? ""} primary=${group.primary.adapter}:${group.primary.botId ?? ""}`);
2531
2589
  } else {
2532
2590
  const participant = participantOf(event);
2533
2591
  group = {
2534
- key,
2592
+ key: key$1,
2535
2593
  expiresAt: now + ttl,
2536
2594
  firstSeenAt: now,
2537
2595
  primary: participant,
2538
2596
  participants: [participant]
2539
2597
  };
2540
- this.#groups.set(key, group);
2598
+ this.#groups.set(key$1, group);
2541
2599
  this.#inserts++;
2542
2600
  if (this.#inserts >= PRUNE_INTERVAL || this.#groups.size > this.#maxSize) {
2543
2601
  this.#inserts = 0;
@@ -2590,12 +2648,12 @@ var EventCorrelator = class {
2590
2648
  return null;
2591
2649
  }
2592
2650
  #prune(now) {
2593
- for (const [key, group] of this.#groups) if (group.expiresAt < now) this.#groups.delete(key);
2651
+ for (const [key$1, group] of this.#groups) if (group.expiresAt < now) this.#groups.delete(key$1);
2594
2652
  if (this.#groups.size <= this.#maxSize) return;
2595
2653
  const drop = this.#groups.size - this.#maxSize;
2596
2654
  let dropped = 0;
2597
- for (const key of this.#groups.keys()) {
2598
- this.#groups.delete(key);
2655
+ for (const key$1 of this.#groups.keys()) {
2656
+ this.#groups.delete(key$1);
2599
2657
  this.#evicted++;
2600
2658
  if (++dropped >= drop) break;
2601
2659
  }
@@ -2714,8 +2772,8 @@ var CommandManager = class {
2714
2772
  canUseCommand(plugin, command, event) {
2715
2773
  const registered = this.#resolveRegistered(plugin, command);
2716
2774
  if (registered) return this.#canUse(registered, event);
2717
- const key = commandKey$1(command);
2718
- const action = this.#resolveAction(plugin, key, event) ?? this.#resolveAction(plugin, command, event);
2775
+ const key$1 = commandKey$1(command);
2776
+ const action = this.#resolveAction(plugin, key$1, event) ?? this.#resolveAction(plugin, command, event);
2719
2777
  return action !== "block";
2720
2778
  }
2721
2779
  syncMetadata(metadata) {
@@ -2744,11 +2802,11 @@ var CommandManager = class {
2744
2802
  const seen = new Set();
2745
2803
  const runtimeByKey = new Map(runtime.map((command) => [commandKey$1(command.name), command]));
2746
2804
  for (const command of metadata?.config.help?.commands ?? []) {
2747
- const key = commandKey$1(command.cmd);
2748
- const runtimeCommand = runtimeByKey.get(key);
2805
+ const key$1 = commandKey$1(command.cmd);
2806
+ const runtimeCommand = runtimeByKey.get(key$1);
2749
2807
  if (runtimeCommand) {
2750
2808
  const cmd = displayCommand(runtimeCommand, this.#getDefaultPrefix());
2751
- seen.add(key);
2809
+ seen.add(key$1);
2752
2810
  commands.push({
2753
2811
  cmd,
2754
2812
  id: runtimeCommand.id,
@@ -2756,8 +2814,8 @@ var CommandManager = class {
2756
2814
  usage: runtimeCommand.usage ?? command.usage,
2757
2815
  role: runtimeCommand.permission
2758
2816
  });
2759
- } else if (!seen.has(key)) {
2760
- seen.add(key);
2817
+ } else if (!seen.has(key$1)) {
2818
+ seen.add(key$1);
2761
2819
  commands.push(command);
2762
2820
  }
2763
2821
  }
@@ -2920,9 +2978,9 @@ var CommandManager = class {
2920
2978
  #resolveRegistered(plugin, ref) {
2921
2979
  const raw = String(ref ?? "").trim();
2922
2980
  if (!raw) return void 0;
2923
- const key = commandKey$1(raw);
2981
+ const key$1 = commandKey$1(raw);
2924
2982
  const candidates = this.#commands.filter((item) => item.plugin === plugin);
2925
- return candidates.find((item) => item.id === raw) ?? candidates.find((item) => item.name === raw) ?? candidates.find((item) => item.aliases.includes(raw)) ?? candidates.find((item) => commandKey$1(item.id) === key) ?? candidates.find((item) => commandKey$1(item.name) === key) ?? candidates.find((item) => item.aliases.some((alias) => commandKey$1(alias) === key));
2983
+ return candidates.find((item) => item.id === raw) ?? candidates.find((item) => item.name === raw) ?? candidates.find((item) => item.aliases.includes(raw)) ?? candidates.find((item) => commandKey$1(item.id) === key$1) ?? candidates.find((item) => commandKey$1(item.name) === key$1) ?? candidates.find((item) => item.aliases.some((alias) => commandKey$1(alias) === key$1));
2926
2984
  }
2927
2985
  #canUse(command, event) {
2928
2986
  const userId = userIdOf(event);
@@ -2987,8 +3045,8 @@ var CommandManager = class {
2987
3045
  #admins() {
2988
3046
  return this.#configIds("admins");
2989
3047
  }
2990
- #configIds(key) {
2991
- return [...key === "owners" ? this.#getOwners() : this.#getAdmins()].map(String);
3048
+ #configIds(key$1) {
3049
+ return [...key$1 === "owners" ? this.#getOwners() : this.#getAdmins()].map(String);
2992
3050
  }
2993
3051
  };
2994
3052
  let activeCommandManager;
@@ -3037,8 +3095,8 @@ async function registerPluginArtifacts(ctx) {
3037
3095
  title: existing?.title || generated.title,
3038
3096
  description: existing?.description || generated.description,
3039
3097
  commands: [...existing?.commands ?? [], ...generated.commands.filter((command) => {
3040
- const key = commandKey(command.cmd);
3041
- return !(existing?.commands ?? []).some((item) => commandKey(item.cmd) === key);
3098
+ const key$1 = commandKey(command.cmd);
3099
+ return !(existing?.commands ?? []).some((item) => commandKey(item.cmd) === key$1);
3042
3100
  })]
3043
3101
  } : existing;
3044
3102
  if (help) if (helpService) {
@@ -3276,10 +3334,10 @@ const registerStatusProvider = (target, provider) => {
3276
3334
  adapter: target,
3277
3335
  bot_id: void 0
3278
3336
  } : target;
3279
- const key = providerKey(adapter, bot_id);
3280
- statusProviders.set(key, provider);
3337
+ const key$1 = providerKey(adapter, bot_id);
3338
+ statusProviders.set(key$1, provider);
3281
3339
  return () => {
3282
- if (statusProviders.get(key) === provider) statusProviders.delete(key);
3340
+ if (statusProviders.get(key$1) === provider) statusProviders.delete(key$1);
3283
3341
  };
3284
3342
  };
3285
3343
  const resolveProvider = (bot) => statusProviders.get(providerKey(bot.adapter, bot.bot_id)) ?? statusProviders.get(providerKey(bot.adapter));
@@ -3357,7 +3415,7 @@ const STAT_GROUPS = [["📋", [["friends", "好友"], ["groups", "群"]]], ["
3357
3415
  const formatStats = (stats) => {
3358
3416
  const segments = [];
3359
3417
  for (const [icon, fields] of STAT_GROUPS) {
3360
- const parts = fields.filter(([key]) => stats[key] != null).map(([key, label]) => `${label} ${localNum(stats[key])}`);
3418
+ const parts = fields.filter(([key$1]) => stats[key$1] != null).map(([key$1, label]) => `${label} ${localNum(stats[key$1])}`);
3361
3419
  if (parts.length) segments.push(`${icon} ${parts.join(" / ")}`);
3362
3420
  }
3363
3421
  return segments.join(" · ");
@@ -4396,12 +4454,12 @@ function registerUpdateCommands(ctx) {
4396
4454
  }
4397
4455
  if (arg === "check" || arg === "检查") {
4398
4456
  const pending = getPendingMap();
4399
- const key = conversationKey(event);
4400
- const existing = pending.get(key);
4457
+ const key$1 = conversationKey(event);
4458
+ const existing = pending.get(key$1);
4401
4459
  if (existing) {
4402
4460
  existing.disposer();
4403
4461
  clearTimeout(existing.timer);
4404
- pending.delete(key);
4462
+ pending.delete(key$1);
4405
4463
  }
4406
4464
  let items;
4407
4465
  try {
@@ -4419,15 +4477,15 @@ function registerUpdateCommands(ctx) {
4419
4477
  const timeoutMs = SELECT_TIMEOUT_MS;
4420
4478
  const listenerDispose = ctx.handle("message", async (ev) => {
4421
4479
  if (String(ev?.self_id || "") !== selfId) return;
4422
- if (conversationKey(ev) !== key) return;
4480
+ if (conversationKey(ev) !== key$1) return;
4423
4481
  if (!isEventMaster(ev)) return;
4424
4482
  const evText = ctx.text(ev)?.trim() || "";
4425
4483
  if (evText.startsWith(`${prefix}update`)) return;
4426
- const sel = pending.get(key);
4484
+ const sel = pending.get(key$1);
4427
4485
  if (!sel) return;
4428
4486
  clearTimeout(sel.timer);
4429
4487
  sel.disposer();
4430
- pending.delete(key);
4488
+ pending.delete(key$1);
4431
4489
  const parsed = parseSelection(evText, sel.items.length);
4432
4490
  const chosen = parsed.all ? sel.items : parsed.indices.map((i) => sel.items[i]).filter(Boolean);
4433
4491
  if (chosen.length === 0) {
@@ -4437,13 +4495,13 @@ function registerUpdateCommands(ctx) {
4437
4495
  await performUpdateAndReport(ctx, event, chosen.map((i) => i.name));
4438
4496
  });
4439
4497
  const timer = setTimeout(async () => {
4440
- const sel = pending.get(key);
4498
+ const sel = pending.get(key$1);
4441
4499
  if (!sel) return;
4442
4500
  sel.disposer();
4443
- pending.delete(key);
4501
+ pending.delete(key$1);
4444
4502
  await replyText(event, "操作超时,已取消更新");
4445
4503
  }, timeoutMs);
4446
- pending.set(key, {
4504
+ pending.set(key$1, {
4447
4505
  disposer: listenerDispose,
4448
4506
  timer,
4449
4507
  items
@@ -5379,7 +5437,7 @@ const HELP_COMMAND_KEYS = new Set([
5379
5437
  "role"
5380
5438
  ]);
5381
5439
  function warnUnknownFields(prefix, obj, allowed) {
5382
- for (const key of Object.keys(obj)) if (!allowed.has(key)) rootLogger.warn(`[plugin-manifest] ${prefix} 含未知字段 "${key}"(将被忽略)`);
5440
+ for (const key$1 of Object.keys(obj)) if (!allowed.has(key$1)) rootLogger.warn(`[plugin-manifest] ${prefix} 含未知字段 "${key$1}"(将被忽略)`);
5383
5441
  }
5384
5442
  function isPlainObject(value) {
5385
5443
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -5524,7 +5582,7 @@ const collectDirectDependencyNames = (pkg) => {
5524
5582
  pkg.optionalDependencies
5525
5583
  ]) {
5526
5584
  if (!map) continue;
5527
- for (const key of Object.keys(map)) set.add(key);
5585
+ for (const key$1 of Object.keys(map)) set.add(key$1);
5528
5586
  }
5529
5587
  return Array.from(set);
5530
5588
  };
@@ -5808,10 +5866,10 @@ var MiokuRuntime = class {
5808
5866
  return this.#bots.pick(bot_id);
5809
5867
  }
5810
5868
  listPlugins() {
5811
- return Array.from(this.#enabledPlugins.entries()).map(([key]) => {
5812
- const colon = key.indexOf(":");
5813
- const type = key.slice(0, colon);
5814
- const name = key.slice(colon + 1);
5869
+ return Array.from(this.#enabledPlugins.entries()).map(([key$1]) => {
5870
+ const colon = key$1.indexOf(":");
5871
+ const type = key$1.slice(0, colon);
5872
+ const name = key$1.slice(colon + 1);
5815
5873
  const isExternal = type !== "builtin";
5816
5874
  const version$2 = isExternal ? getPluginMetadata(name)?.version : void 0;
5817
5875
  return {
@@ -5847,8 +5905,8 @@ var MiokuRuntime = class {
5847
5905
  throw new Error(`插件 ${name} 不存在`);
5848
5906
  }
5849
5907
  async disablePlugin(name) {
5850
- const key = `external:${name}`;
5851
- const entry = this.#enabledPlugins.get(key);
5908
+ const key$1 = `external:${name}`;
5909
+ const entry = this.#enabledPlugins.get(key$1);
5852
5910
  if (!entry) {
5853
5911
  if (this.#enabledPlugins.has(`builtin:${name}`)) throw new Error(`内置插件 ${name} 无法禁用`);
5854
5912
  throw new Error(`插件 ${name} 不存在或未启用`);
@@ -5856,7 +5914,7 @@ var MiokuRuntime = class {
5856
5914
  try {
5857
5915
  await entry.cleanup?.();
5858
5916
  } finally {
5859
- this.#enabledPlugins.delete(key);
5917
+ this.#enabledPlugins.delete(key$1);
5860
5918
  removePluginMetadata(name);
5861
5919
  }
5862
5920
  await this.#refreshPluginArtifacts();
@@ -6342,8 +6400,8 @@ function splitFrontmatter(text$1) {
6342
6400
  }
6343
6401
  return void 0;
6344
6402
  }
6345
- function stringField(source, key) {
6346
- const value = source[key];
6403
+ function stringField(source, key$1) {
6404
+ const value = source[key$1];
6347
6405
  return typeof value === "string" ? value.trim() : "";
6348
6406
  }
6349
6407
  function booleanField(value) {
@@ -6365,9 +6423,9 @@ function readAllowedTools(value) {
6365
6423
  function readMetadata(value) {
6366
6424
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
6367
6425
  const result = {};
6368
- for (const [key, item] of Object.entries(value)) {
6426
+ for (const [key$1, item] of Object.entries(value)) {
6369
6427
  if (item === null || item === void 0) continue;
6370
- result[key] = typeof item === "string" ? item : JSON.stringify(item) ?? String(item);
6428
+ result[key$1] = typeof item === "string" ? item : JSON.stringify(item) ?? String(item);
6371
6429
  }
6372
6430
  return Object.keys(result).length > 0 ? result : void 0;
6373
6431
  }
@@ -6400,9 +6458,9 @@ function parseSkillFile(path$8, raw) {
6400
6458
  diagnostics.push(diagnostic("INVALID_YAML", `frontmatter YAML 解析失败:${err}`, path$8, "error"));
6401
6459
  return { diagnostics };
6402
6460
  }
6403
- for (const key of Object.keys(data)) {
6404
- if (SKILL_KNOWN_KEYS.includes(key)) continue;
6405
- diagnostics.push(diagnostic("UNKNOWN_KEY", `未知 frontmatter 字段 "${key}",已忽略`, path$8));
6461
+ for (const key$1 of Object.keys(data)) {
6462
+ if (SKILL_KNOWN_KEYS.includes(key$1)) continue;
6463
+ diagnostics.push(diagnostic("UNKNOWN_KEY", `未知 frontmatter 字段 "${key$1}",已忽略`, path$8));
6406
6464
  }
6407
6465
  const name = stringField(data, "name");
6408
6466
  if (!name) {
@@ -6763,15 +6821,15 @@ function createSkillCatalog(options = {}) {
6763
6821
  async function scanRoot(root, found) {
6764
6822
  const group = [];
6765
6823
  for (const entry of found) {
6766
- const key = await entryStamp(entry);
6824
+ const key$1 = await entryStamp(entry);
6767
6825
  const cached = entries.get(entry.skillPath);
6768
- if (cached && cached.key === key) {
6826
+ if (cached && cached.key === key$1) {
6769
6827
  group.push(...cached.skills);
6770
6828
  continue;
6771
6829
  }
6772
6830
  const result = await readSkillEntry(root, entry, discoverOptions);
6773
6831
  entries.set(entry.skillPath, {
6774
- key,
6832
+ key: key$1,
6775
6833
  skills: result.skills,
6776
6834
  diagnostics: result.diagnostics
6777
6835
  });
@@ -7257,6 +7315,7 @@ Object.defineProperty(exports, 'fs', {
7257
7315
  exports.getActiveCommandManager = getActiveCommandManager;
7258
7316
  exports.getAllPluginRuntimeStates = getAllPluginRuntimeStates;
7259
7317
  exports.getBuiltinPlugins = getBuiltinPlugins;
7318
+ exports.getConfigDefaults = getConfigDefaults;
7260
7319
  exports.getConfigDir = getConfigDir;
7261
7320
  exports.getDataDir = getDataDir;
7262
7321
  exports.getGTk = getGTk;
@@ -7364,6 +7423,7 @@ exports.readMiokuConfig = readMiokuConfig;
7364
7423
  exports.readPackageJson = readPackageJson;
7365
7424
  exports.readPackageJsonSafe = readPackageJsonSafe;
7366
7425
  exports.readSkillEntry = readSkillEntry;
7426
+ exports.registerConfigDefaults = registerConfigDefaults;
7367
7427
  exports.registerPluginArtifacts = registerPluginArtifacts;
7368
7428
  exports.registerServiceConfig = registerServiceConfig;
7369
7429
  exports.registerStatusProvider = registerStatusProvider;
@@ -7419,5 +7479,6 @@ exports.updateServiceConfig = updateServiceConfig;
7419
7479
  exports.uuid = uuid;
7420
7480
  exports.version = version$1;
7421
7481
  exports.wait = wait;
7482
+ exports.withConfigDefaults = withConfigDefaults;
7422
7483
  exports.writePackageJson = writePackageJson;
7423
7484
  //# sourceMappingURL=index.cjs.map