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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { buildSpawnPlan, commandExists, compareVersions, pickHighestVersion, resolveCommand, runCommand, runCommandInherit, version } from "./exec-B_5FzqAA.js";
1
+ import { buildSpawnPlan, commandExists, compareVersions, pickHighestVersion, resolveCommand, runCommand, runCommandInherit, version } from "./exec-C_iMY_-7.js";
2
2
  import { createRequire } from "node:module";
3
3
  import * as fs$5 from "node:fs";
4
4
  import * as fs$4 from "node:fs";
@@ -192,8 +192,8 @@ const RAW_TEXT_DECODER = new TextDecoder();
192
192
  const decodeBody = async (response) => {
193
193
  const arrayBuffer = await response.arrayBuffer();
194
194
  const headers = {};
195
- response.headers.forEach((value, key) => {
196
- headers[key.toLowerCase()] = value;
195
+ response.headers.forEach((value, key$1) => {
196
+ headers[key$1.toLowerCase()] = value;
197
197
  });
198
198
  return {
199
199
  body: new Uint8Array(arrayBuffer),
@@ -864,8 +864,8 @@ const definePlugin = (plugin) => plugin;
864
864
  //#endregion
865
865
  //#region src/runtime/context.ts
866
866
  var AdapterRegistrationConflictError = class extends Error {
867
- constructor(key) {
868
- super(`Bot already registered for ${key}`);
867
+ constructor(key$1) {
868
+ super(`Bot already registered for ${key$1}`);
869
869
  this.name = "AdapterRegistrationConflictError";
870
870
  }
871
871
  };
@@ -940,8 +940,8 @@ var AdapterContextImpl = class {
940
940
  if (!gateway) throw new Error(`Resource references unknown gateway "${resource.gateway}"`);
941
941
  }
942
942
  if (resource.scope === "bot") {
943
- const key = `${this.#state.definition.name}:${resource.bot_id}`;
944
- if (!this.#bots.has(key)) throw new Error(`Resource references unknown bot "${resource.bot_id}"`);
943
+ const key$1 = `${this.#state.definition.name}:${resource.bot_id}`;
944
+ if (!this.#bots.has(key$1)) throw new Error(`Resource references unknown bot "${resource.bot_id}"`);
945
945
  }
946
946
  this.#state.resources.push(resource);
947
947
  return () => {
@@ -994,10 +994,10 @@ function store$2() {
994
994
  if (!g[STORE_SYMBOL]) g[STORE_SYMBOL] = {};
995
995
  return g[STORE_SYMBOL];
996
996
  }
997
- function getOrCreate(key, factory) {
997
+ function getOrCreate(key$1, factory) {
998
998
  const s = store$2();
999
- if (s[key] === void 0) s[key] = factory();
1000
- return s[key];
999
+ if (s[key$1] === void 0) s[key$1] = factory();
1000
+ return s[key$1];
1001
1001
  }
1002
1002
 
1003
1003
  //#endregion
@@ -1015,37 +1015,37 @@ var BotRegistry = class {
1015
1015
  #disposers = new Map();
1016
1016
  /** 登记一个 bot,返回可注销的上下文 */
1017
1017
  register(bot) {
1018
- const key = connectedBotKey(bot.adapter, bot.bot_id);
1019
- if (this.#bots.has(key)) throw new AdapterRegistrationConflictError(key);
1020
- this.#bots.set(key, {
1018
+ const key$1 = connectedBotKey(bot.adapter, bot.bot_id);
1019
+ if (this.#bots.has(key$1)) throw new AdapterRegistrationConflictError(key$1);
1020
+ this.#bots.set(key$1, {
1021
1021
  adapter: bot.adapter,
1022
1022
  bot_id: bot.bot_id,
1023
1023
  bot
1024
1024
  });
1025
- connectedBots.set(key, bot);
1025
+ connectedBots.set(key$1, bot);
1026
1026
  const dispose = () => {
1027
1027
  this.unregister(bot.bot_id, bot.adapter);
1028
1028
  };
1029
- this.#disposers.set(key, dispose);
1029
+ this.#disposers.set(key$1, dispose);
1030
1030
  return {
1031
1031
  bot,
1032
1032
  unregister: dispose
1033
1033
  };
1034
1034
  }
1035
- has(key) {
1036
- return this.#bots.has(key);
1035
+ has(key$1) {
1036
+ return this.#bots.has(key$1);
1037
1037
  }
1038
1038
  unregister(bot_id, adapter) {
1039
- const key = connectedBotKey(adapter, bot_id);
1040
- const removed = this.#bots.delete(key);
1041
- this.#disposers.delete(key);
1042
- connectedBots.delete(key);
1039
+ const key$1 = connectedBotKey(adapter, bot_id);
1040
+ const removed = this.#bots.delete(key$1);
1041
+ this.#disposers.delete(key$1);
1042
+ connectedBots.delete(key$1);
1043
1043
  return removed;
1044
1044
  }
1045
1045
  /** 按 bot_id 取 bot(只按 id 匹配,不限适配器) */
1046
1046
  pick(bot_id) {
1047
- const key = String(bot_id);
1048
- for (const entry of this.#bots.values()) if (entry.bot_id === key) return entry.bot;
1047
+ const key$1 = String(bot_id);
1048
+ for (const entry of this.#bots.values()) if (entry.bot_id === key$1) return entry.bot;
1049
1049
  return void 0;
1050
1050
  }
1051
1051
  find(adapter, bot_id) {
@@ -1425,23 +1425,23 @@ const getGTk = (pskey) => {
1425
1425
  */
1426
1426
  const match = async (event, pattern, quote = true) => {
1427
1427
  const inputText = event.message.text();
1428
- for (const [key, value] of Object.entries(pattern)) {
1428
+ for (const [key$1, value] of Object.entries(pattern)) {
1429
1429
  let isMatched = false;
1430
1430
  let matches = null;
1431
- const isRegExp = key.startsWith("/") && key.endsWith("/");
1432
- const hasWildcard = key.includes("*");
1431
+ const isRegExp = key$1.startsWith("/") && key$1.endsWith("/");
1432
+ const hasWildcard = key$1.includes("*");
1433
1433
  if (isRegExp) try {
1434
- const regex = new RegExp(key.slice(1, -1));
1434
+ const regex = new RegExp(key$1.slice(1, -1));
1435
1435
  matches = inputText.match(regex);
1436
1436
  if (matches) isMatched = true;
1437
1437
  } catch (err) {
1438
- throw new Error(`无效的正则表达式: ${key}`, { cause: err });
1438
+ throw new Error(`无效的正则表达式: ${key$1}`, { cause: err });
1439
1439
  }
1440
1440
  else if (hasWildcard) {
1441
- const regex = new RegExp(`^${key.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`);
1441
+ const regex = new RegExp(`^${key$1.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`);
1442
1442
  matches = inputText.match(regex);
1443
1443
  if (matches) isMatched = true;
1444
- } else if (key === inputText) isMatched = true;
1444
+ } else if (key$1 === inputText) isMatched = true;
1445
1445
  if (!isMatched) continue;
1446
1446
  const result = typeof value === "function" ? await value(matches, event) : value;
1447
1447
  if (result) {
@@ -1914,6 +1914,47 @@ var ServiceManager = class ServiceManager {
1914
1914
  };
1915
1915
  var manager_default = ServiceManager.getInstance();
1916
1916
 
1917
+ //#endregion
1918
+ //#region src/services/config-defaults.ts
1919
+ const defaults = new Map();
1920
+ function key(scope, owner, name) {
1921
+ return `${scope}\u0000${owner}\u0000${name}`;
1922
+ }
1923
+ /** 登记一份配置的默认值;同名重复登记以最后一次为准 */
1924
+ function registerConfigDefaults(scope, owner, name, value) {
1925
+ if (!value || typeof value !== "object") return;
1926
+ defaults.set(key(scope, owner, name), clone(value));
1927
+ }
1928
+ /** 取默认值(深拷贝,调用方随便改);没有登记时返回 undefined */
1929
+ function getConfigDefaults(scope, owner, name) {
1930
+ const stored = defaults.get(key(scope, owner, name));
1931
+ return stored ? clone(stored) : void 0;
1932
+ }
1933
+ function isPlainObject$1(value) {
1934
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1935
+ }
1936
+ function clone(value) {
1937
+ return JSON.parse(JSON.stringify(value));
1938
+ }
1939
+ /**
1940
+ * 用默认值补齐一份配置
1941
+ */
1942
+ function withConfigDefaults(stored, fallback) {
1943
+ const base = fallback ? clone(fallback) : {};
1944
+ return mergeInto(base, stored);
1945
+ }
1946
+ function mergeInto(base, overrides) {
1947
+ if (!isPlainObject$1(overrides)) return base;
1948
+ for (const [name, value] of Object.entries(overrides)) {
1949
+ if (value === void 0 || value === null) continue;
1950
+ if (isPlainObject$1(value)) {
1951
+ const current = base[name];
1952
+ base[name] = mergeInto(isPlainObject$1(current) ? current : {}, value);
1953
+ } else base[name] = Array.isArray(value) ? [...value] : value;
1954
+ }
1955
+ return base;
1956
+ }
1957
+
1917
1958
  //#endregion
1918
1959
  //#region src/services/config.ts
1919
1960
  const SERVICE_CONFIG_ROOT = "service";
@@ -1928,21 +1969,35 @@ function ensureDir(serviceName) {
1928
1969
  const dir = resolveConfigDir(serviceName);
1929
1970
  if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
1930
1971
  }
1931
- /** 注册服务配置:文件不存在时把 defaults 写入磁盘 */
1932
- async function registerServiceConfig(serviceName, configName, defaults) {
1972
+ /**
1973
+ * 注册服务配
1974
+ */
1975
+ async function registerServiceConfig(serviceName, configName, defaults$1) {
1933
1976
  ensureDir(serviceName);
1977
+ registerConfigDefaults("service", serviceName, configName, defaults$1);
1934
1978
  const configPath = resolveConfigPath(serviceName, configName);
1935
- if (!existsSync(configPath)) await fs$7.writeFile(configPath, JSON.stringify(defaults, null, 2), "utf-8");
1979
+ if (!existsSync(configPath)) {
1980
+ await fs$7.writeFile(configPath, JSON.stringify(defaults$1, null, 2), "utf-8");
1981
+ return;
1982
+ }
1983
+ try {
1984
+ const existing = JSON.parse(await fs$7.readFile(configPath, "utf-8"));
1985
+ const merged = withConfigDefaults(existing, defaults$1);
1986
+ if (JSON.stringify(merged) !== JSON.stringify(existing)) await fs$7.writeFile(configPath, JSON.stringify(merged, null, 2), "utf-8");
1987
+ } catch (error) {
1988
+ rootLogger.warn(`[service-config] 补全 ${serviceName}/${configName} 失败: ${error}`);
1989
+ }
1936
1990
  }
1937
1991
  /** 读取服务配置,文件不存在或解析失败时返回空对象 */
1938
1992
  async function getServiceConfig(serviceName, configName) {
1939
1993
  const configPath = resolveConfigPath(serviceName, configName);
1994
+ const fallback = getConfigDefaults("service", serviceName, configName);
1940
1995
  try {
1941
- return JSON.parse(await fs$7.readFile(configPath, "utf-8"));
1996
+ return withConfigDefaults(JSON.parse(await fs$7.readFile(configPath, "utf-8")), fallback);
1942
1997
  } catch (error) {
1943
- if (!existsSync(configPath)) return {};
1998
+ if (!existsSync(configPath)) return fallback ?? {};
1944
1999
  rootLogger.warn(`[service-config] 读取 ${serviceName}/${configName} 失败: ${error}`);
1945
- return {};
2000
+ return fallback ?? {};
1946
2001
  }
1947
2002
  }
1948
2003
  /** 覆盖写入服务配置 */
@@ -1956,10 +2011,13 @@ async function getServiceConfigs(serviceName) {
1956
2011
  if (!existsSync(dir)) return {};
1957
2012
  const result = {};
1958
2013
  const files = (await fs$7.readdir(dir)).filter((name) => name.endsWith(".json"));
1959
- for (const file of files) try {
1960
- result[path$11.basename(file, ".json")] = JSON.parse(await fs$7.readFile(path$11.join(dir, file), "utf-8"));
1961
- } catch (error) {
1962
- rootLogger.warn(`[service-config] 读取 ${serviceName}/${file} 失败: ${error}`);
2014
+ for (const file of files) {
2015
+ const configName = path$11.basename(file, ".json");
2016
+ try {
2017
+ result[configName] = withConfigDefaults(JSON.parse(await fs$7.readFile(path$11.join(dir, file), "utf-8")), getConfigDefaults("service", serviceName, configName));
2018
+ } catch (error) {
2019
+ rootLogger.warn(`[service-config] 读取 ${serviceName}/${file} 失败: ${error}`);
2020
+ }
1963
2021
  }
1964
2022
  return result;
1965
2023
  }
@@ -2365,7 +2423,7 @@ const canonicalJson = (value) => {
2365
2423
  if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
2366
2424
  if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
2367
2425
  const obj = value;
2368
- return `{${Object.keys(obj).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(obj[key])}`).join(",")}}`;
2426
+ return `{${Object.keys(obj).sort().map((key$1) => `${JSON.stringify(key$1)}:${canonicalJson(obj[key$1])}`).join(",")}}`;
2369
2427
  };
2370
2428
  /** 结构化载荷(json/xml/ark)的稳定摘要 */
2371
2429
  const structuredDigest = (raw) => {
@@ -2386,9 +2444,9 @@ const normalizeMediaUrl = (raw) => {
2386
2444
  try {
2387
2445
  const url = new URL(raw);
2388
2446
  const kept = new URLSearchParams();
2389
- for (const key of MEDIA_URL_QUERY_KEYS) {
2390
- const value = url.searchParams.get(key);
2391
- if (value) kept.set(key, value);
2447
+ for (const key$1 of MEDIA_URL_QUERY_KEYS) {
2448
+ const value = url.searchParams.get(key$1);
2449
+ if (value) kept.set(key$1, value);
2392
2450
  }
2393
2451
  const query = kept.toString();
2394
2452
  return `${url.host}${url.pathname}${query ? `?${query}` : ""}`;
@@ -2410,7 +2468,7 @@ const mediaDigest = (data) => {
2410
2468
  if (md5$1) return `h:${md5$1}`;
2411
2469
  const sha1 = firstHex(data.sha1, HEX40);
2412
2470
  if (sha1) return `h:${sha1}`;
2413
- for (const key of [
2471
+ for (const key$1 of [
2414
2472
  "file_unique",
2415
2473
  "file_id",
2416
2474
  "fid",
@@ -2418,19 +2476,19 @@ const mediaDigest = (data) => {
2418
2476
  "file",
2419
2477
  "name"
2420
2478
  ]) {
2421
- const hex = firstHex(data[key], HEX32);
2479
+ const hex = firstHex(data[key$1], HEX32);
2422
2480
  if (hex) return `h:${hex}`;
2423
2481
  }
2424
2482
  const url = data.url;
2425
2483
  if (typeof url === "string" && url) return `u:${normalizeMediaUrl(url)}`;
2426
- for (const key of [
2484
+ for (const key$1 of [
2427
2485
  "file",
2428
2486
  "file_id",
2429
2487
  "fid",
2430
2488
  "id",
2431
2489
  "name"
2432
2490
  ]) {
2433
- const value = data[key];
2491
+ const value = data[key$1];
2434
2492
  if (typeof value === "string" && value) return `r:${value.toLowerCase()}`;
2435
2493
  }
2436
2494
  return "";
@@ -2537,27 +2595,27 @@ var EventCorrelator = class {
2537
2595
  if (cached) return cached;
2538
2596
  const located = this.#locate(event);
2539
2597
  if (!located) return null;
2540
- const { key, ttl } = located;
2598
+ const { key: key$1, ttl } = located;
2541
2599
  const now = Date.now();
2542
2600
  this.#observed++;
2543
- let group = this.#groups.get(key);
2601
+ let group = this.#groups.get(key$1);
2544
2602
  let duplicate = false;
2545
2603
  if (group && group.expiresAt >= now) {
2546
2604
  duplicate = true;
2547
2605
  this.#duplicates++;
2548
2606
  const participant = participantOf(event);
2549
2607
  if (!group.participants.some((item) => sameParticipant(item, participant))) group.participants.push(participant);
2550
- this.#logger?.debug(`去重命中: key=${key} adapter=${participant.adapter} bot=${participant.botId ?? ""} primary=${group.primary.adapter}:${group.primary.botId ?? ""}`);
2608
+ this.#logger?.debug(`去重命中: key=${key$1} adapter=${participant.adapter} bot=${participant.botId ?? ""} primary=${group.primary.adapter}:${group.primary.botId ?? ""}`);
2551
2609
  } else {
2552
2610
  const participant = participantOf(event);
2553
2611
  group = {
2554
- key,
2612
+ key: key$1,
2555
2613
  expiresAt: now + ttl,
2556
2614
  firstSeenAt: now,
2557
2615
  primary: participant,
2558
2616
  participants: [participant]
2559
2617
  };
2560
- this.#groups.set(key, group);
2618
+ this.#groups.set(key$1, group);
2561
2619
  this.#inserts++;
2562
2620
  if (this.#inserts >= PRUNE_INTERVAL || this.#groups.size > this.#maxSize) {
2563
2621
  this.#inserts = 0;
@@ -2610,12 +2668,12 @@ var EventCorrelator = class {
2610
2668
  return null;
2611
2669
  }
2612
2670
  #prune(now) {
2613
- for (const [key, group] of this.#groups) if (group.expiresAt < now) this.#groups.delete(key);
2671
+ for (const [key$1, group] of this.#groups) if (group.expiresAt < now) this.#groups.delete(key$1);
2614
2672
  if (this.#groups.size <= this.#maxSize) return;
2615
2673
  const drop = this.#groups.size - this.#maxSize;
2616
2674
  let dropped = 0;
2617
- for (const key of this.#groups.keys()) {
2618
- this.#groups.delete(key);
2675
+ for (const key$1 of this.#groups.keys()) {
2676
+ this.#groups.delete(key$1);
2619
2677
  this.#evicted++;
2620
2678
  if (++dropped >= drop) break;
2621
2679
  }
@@ -2734,8 +2792,8 @@ var CommandManager = class {
2734
2792
  canUseCommand(plugin, command, event) {
2735
2793
  const registered = this.#resolveRegistered(plugin, command);
2736
2794
  if (registered) return this.#canUse(registered, event);
2737
- const key = commandKey$1(command);
2738
- const action = this.#resolveAction(plugin, key, event) ?? this.#resolveAction(plugin, command, event);
2795
+ const key$1 = commandKey$1(command);
2796
+ const action = this.#resolveAction(plugin, key$1, event) ?? this.#resolveAction(plugin, command, event);
2739
2797
  return action !== "block";
2740
2798
  }
2741
2799
  syncMetadata(metadata) {
@@ -2764,11 +2822,11 @@ var CommandManager = class {
2764
2822
  const seen = new Set();
2765
2823
  const runtimeByKey = new Map(runtime.map((command) => [commandKey$1(command.name), command]));
2766
2824
  for (const command of metadata?.config.help?.commands ?? []) {
2767
- const key = commandKey$1(command.cmd);
2768
- const runtimeCommand = runtimeByKey.get(key);
2825
+ const key$1 = commandKey$1(command.cmd);
2826
+ const runtimeCommand = runtimeByKey.get(key$1);
2769
2827
  if (runtimeCommand) {
2770
2828
  const cmd = displayCommand(runtimeCommand, this.#getDefaultPrefix());
2771
- seen.add(key);
2829
+ seen.add(key$1);
2772
2830
  commands.push({
2773
2831
  cmd,
2774
2832
  id: runtimeCommand.id,
@@ -2776,8 +2834,8 @@ var CommandManager = class {
2776
2834
  usage: runtimeCommand.usage ?? command.usage,
2777
2835
  role: runtimeCommand.permission
2778
2836
  });
2779
- } else if (!seen.has(key)) {
2780
- seen.add(key);
2837
+ } else if (!seen.has(key$1)) {
2838
+ seen.add(key$1);
2781
2839
  commands.push(command);
2782
2840
  }
2783
2841
  }
@@ -2940,9 +2998,9 @@ var CommandManager = class {
2940
2998
  #resolveRegistered(plugin, ref) {
2941
2999
  const raw = String(ref ?? "").trim();
2942
3000
  if (!raw) return void 0;
2943
- const key = commandKey$1(raw);
3001
+ const key$1 = commandKey$1(raw);
2944
3002
  const candidates = this.#commands.filter((item) => item.plugin === plugin);
2945
- 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));
3003
+ 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));
2946
3004
  }
2947
3005
  #canUse(command, event) {
2948
3006
  const userId = userIdOf(event);
@@ -3007,8 +3065,8 @@ var CommandManager = class {
3007
3065
  #admins() {
3008
3066
  return this.#configIds("admins");
3009
3067
  }
3010
- #configIds(key) {
3011
- return [...key === "owners" ? this.#getOwners() : this.#getAdmins()].map(String);
3068
+ #configIds(key$1) {
3069
+ return [...key$1 === "owners" ? this.#getOwners() : this.#getAdmins()].map(String);
3012
3070
  }
3013
3071
  };
3014
3072
  let activeCommandManager;
@@ -3057,8 +3115,8 @@ async function registerPluginArtifacts(ctx) {
3057
3115
  title: existing?.title || generated.title,
3058
3116
  description: existing?.description || generated.description,
3059
3117
  commands: [...existing?.commands ?? [], ...generated.commands.filter((command) => {
3060
- const key = commandKey(command.cmd);
3061
- return !(existing?.commands ?? []).some((item) => commandKey(item.cmd) === key);
3118
+ const key$1 = commandKey(command.cmd);
3119
+ return !(existing?.commands ?? []).some((item) => commandKey(item.cmd) === key$1);
3062
3120
  })]
3063
3121
  } : existing;
3064
3122
  if (help) if (helpService) {
@@ -3296,10 +3354,10 @@ const registerStatusProvider = (target, provider) => {
3296
3354
  adapter: target,
3297
3355
  bot_id: void 0
3298
3356
  } : target;
3299
- const key = providerKey(adapter, bot_id);
3300
- statusProviders.set(key, provider);
3357
+ const key$1 = providerKey(adapter, bot_id);
3358
+ statusProviders.set(key$1, provider);
3301
3359
  return () => {
3302
- if (statusProviders.get(key) === provider) statusProviders.delete(key);
3360
+ if (statusProviders.get(key$1) === provider) statusProviders.delete(key$1);
3303
3361
  };
3304
3362
  };
3305
3363
  const resolveProvider = (bot) => statusProviders.get(providerKey(bot.adapter, bot.bot_id)) ?? statusProviders.get(providerKey(bot.adapter));
@@ -3377,7 +3435,7 @@ const STAT_GROUPS = [["📋", [["friends", "好友"], ["groups", "群"]]], ["
3377
3435
  const formatStats = (stats) => {
3378
3436
  const segments = [];
3379
3437
  for (const [icon, fields] of STAT_GROUPS) {
3380
- const parts = fields.filter(([key]) => stats[key] != null).map(([key, label]) => `${label} ${localNum(stats[key])}`);
3438
+ const parts = fields.filter(([key$1]) => stats[key$1] != null).map(([key$1, label]) => `${label} ${localNum(stats[key$1])}`);
3381
3439
  if (parts.length) segments.push(`${icon} ${parts.join(" / ")}`);
3382
3440
  }
3383
3441
  return segments.join(" · ");
@@ -4416,12 +4474,12 @@ function registerUpdateCommands(ctx) {
4416
4474
  }
4417
4475
  if (arg === "check" || arg === "检查") {
4418
4476
  const pending = getPendingMap();
4419
- const key = conversationKey(event);
4420
- const existing = pending.get(key);
4477
+ const key$1 = conversationKey(event);
4478
+ const existing = pending.get(key$1);
4421
4479
  if (existing) {
4422
4480
  existing.disposer();
4423
4481
  clearTimeout(existing.timer);
4424
- pending.delete(key);
4482
+ pending.delete(key$1);
4425
4483
  }
4426
4484
  let items;
4427
4485
  try {
@@ -4439,15 +4497,15 @@ function registerUpdateCommands(ctx) {
4439
4497
  const timeoutMs = SELECT_TIMEOUT_MS;
4440
4498
  const listenerDispose = ctx.handle("message", async (ev) => {
4441
4499
  if (String(ev?.self_id || "") !== selfId) return;
4442
- if (conversationKey(ev) !== key) return;
4500
+ if (conversationKey(ev) !== key$1) return;
4443
4501
  if (!isEventMaster(ev)) return;
4444
4502
  const evText = ctx.text(ev)?.trim() || "";
4445
4503
  if (evText.startsWith(`${prefix}update`)) return;
4446
- const sel = pending.get(key);
4504
+ const sel = pending.get(key$1);
4447
4505
  if (!sel) return;
4448
4506
  clearTimeout(sel.timer);
4449
4507
  sel.disposer();
4450
- pending.delete(key);
4508
+ pending.delete(key$1);
4451
4509
  const parsed = parseSelection(evText, sel.items.length);
4452
4510
  const chosen = parsed.all ? sel.items : parsed.indices.map((i) => sel.items[i]).filter(Boolean);
4453
4511
  if (chosen.length === 0) {
@@ -4457,13 +4515,13 @@ function registerUpdateCommands(ctx) {
4457
4515
  await performUpdateAndReport(ctx, event, chosen.map((i) => i.name));
4458
4516
  });
4459
4517
  const timer = setTimeout(async () => {
4460
- const sel = pending.get(key);
4518
+ const sel = pending.get(key$1);
4461
4519
  if (!sel) return;
4462
4520
  sel.disposer();
4463
- pending.delete(key);
4521
+ pending.delete(key$1);
4464
4522
  await replyText(event, "操作超时,已取消更新");
4465
4523
  }, timeoutMs);
4466
- pending.set(key, {
4524
+ pending.set(key$1, {
4467
4525
  disposer: listenerDispose,
4468
4526
  timer,
4469
4527
  items
@@ -5399,7 +5457,7 @@ const HELP_COMMAND_KEYS = new Set([
5399
5457
  "role"
5400
5458
  ]);
5401
5459
  function warnUnknownFields(prefix, obj, allowed) {
5402
- for (const key of Object.keys(obj)) if (!allowed.has(key)) rootLogger.warn(`[plugin-manifest] ${prefix} 含未知字段 "${key}"(将被忽略)`);
5460
+ for (const key$1 of Object.keys(obj)) if (!allowed.has(key$1)) rootLogger.warn(`[plugin-manifest] ${prefix} 含未知字段 "${key$1}"(将被忽略)`);
5403
5461
  }
5404
5462
  function isPlainObject(value) {
5405
5463
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -5544,7 +5602,7 @@ const collectDirectDependencyNames = (pkg) => {
5544
5602
  pkg.optionalDependencies
5545
5603
  ]) {
5546
5604
  if (!map) continue;
5547
- for (const key of Object.keys(map)) set.add(key);
5605
+ for (const key$1 of Object.keys(map)) set.add(key$1);
5548
5606
  }
5549
5607
  return Array.from(set);
5550
5608
  };
@@ -5828,10 +5886,10 @@ var MiokuRuntime = class {
5828
5886
  return this.#bots.pick(bot_id);
5829
5887
  }
5830
5888
  listPlugins() {
5831
- return Array.from(this.#enabledPlugins.entries()).map(([key]) => {
5832
- const colon = key.indexOf(":");
5833
- const type = key.slice(0, colon);
5834
- const name = key.slice(colon + 1);
5889
+ return Array.from(this.#enabledPlugins.entries()).map(([key$1]) => {
5890
+ const colon = key$1.indexOf(":");
5891
+ const type = key$1.slice(0, colon);
5892
+ const name = key$1.slice(colon + 1);
5835
5893
  const isExternal = type !== "builtin";
5836
5894
  const version$2 = isExternal ? getPluginMetadata(name)?.version : void 0;
5837
5895
  return {
@@ -5867,8 +5925,8 @@ var MiokuRuntime = class {
5867
5925
  throw new Error(`插件 ${name} 不存在`);
5868
5926
  }
5869
5927
  async disablePlugin(name) {
5870
- const key = `external:${name}`;
5871
- const entry = this.#enabledPlugins.get(key);
5928
+ const key$1 = `external:${name}`;
5929
+ const entry = this.#enabledPlugins.get(key$1);
5872
5930
  if (!entry) {
5873
5931
  if (this.#enabledPlugins.has(`builtin:${name}`)) throw new Error(`内置插件 ${name} 无法禁用`);
5874
5932
  throw new Error(`插件 ${name} 不存在或未启用`);
@@ -5876,7 +5934,7 @@ var MiokuRuntime = class {
5876
5934
  try {
5877
5935
  await entry.cleanup?.();
5878
5936
  } finally {
5879
- this.#enabledPlugins.delete(key);
5937
+ this.#enabledPlugins.delete(key$1);
5880
5938
  removePluginMetadata(name);
5881
5939
  }
5882
5940
  await this.#refreshPluginArtifacts();
@@ -6362,8 +6420,8 @@ function splitFrontmatter(text$1) {
6362
6420
  }
6363
6421
  return void 0;
6364
6422
  }
6365
- function stringField(source, key) {
6366
- const value = source[key];
6423
+ function stringField(source, key$1) {
6424
+ const value = source[key$1];
6367
6425
  return typeof value === "string" ? value.trim() : "";
6368
6426
  }
6369
6427
  function booleanField(value) {
@@ -6385,9 +6443,9 @@ function readAllowedTools(value) {
6385
6443
  function readMetadata(value) {
6386
6444
  if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
6387
6445
  const result = {};
6388
- for (const [key, item] of Object.entries(value)) {
6446
+ for (const [key$1, item] of Object.entries(value)) {
6389
6447
  if (item === null || item === void 0) continue;
6390
- result[key] = typeof item === "string" ? item : JSON.stringify(item) ?? String(item);
6448
+ result[key$1] = typeof item === "string" ? item : JSON.stringify(item) ?? String(item);
6391
6449
  }
6392
6450
  return Object.keys(result).length > 0 ? result : void 0;
6393
6451
  }
@@ -6420,9 +6478,9 @@ function parseSkillFile(path$14, raw) {
6420
6478
  diagnostics.push(diagnostic("INVALID_YAML", `frontmatter YAML 解析失败:${err}`, path$14, "error"));
6421
6479
  return { diagnostics };
6422
6480
  }
6423
- for (const key of Object.keys(data)) {
6424
- if (SKILL_KNOWN_KEYS.includes(key)) continue;
6425
- diagnostics.push(diagnostic("UNKNOWN_KEY", `未知 frontmatter 字段 "${key}",已忽略`, path$14));
6481
+ for (const key$1 of Object.keys(data)) {
6482
+ if (SKILL_KNOWN_KEYS.includes(key$1)) continue;
6483
+ diagnostics.push(diagnostic("UNKNOWN_KEY", `未知 frontmatter 字段 "${key$1}",已忽略`, path$14));
6426
6484
  }
6427
6485
  const name = stringField(data, "name");
6428
6486
  if (!name) {
@@ -6783,15 +6841,15 @@ function createSkillCatalog(options = {}) {
6783
6841
  async function scanRoot(root, found) {
6784
6842
  const group = [];
6785
6843
  for (const entry of found) {
6786
- const key = await entryStamp(entry);
6844
+ const key$1 = await entryStamp(entry);
6787
6845
  const cached = entries.get(entry.skillPath);
6788
- if (cached && cached.key === key) {
6846
+ if (cached && cached.key === key$1) {
6789
6847
  group.push(...cached.skills);
6790
6848
  continue;
6791
6849
  }
6792
6850
  const result = await readSkillEntry(root, entry, discoverOptions);
6793
6851
  entries.set(entry.skillPath, {
6794
- key,
6852
+ key: key$1,
6795
6853
  skills: result.skills,
6796
6854
  diagnostics: result.diagnostics
6797
6855
  });
@@ -7138,5 +7196,5 @@ function installProcessErrorGuards() {
7138
7196
  }
7139
7197
 
7140
7198
  //#endregion
7141
- export { AI_GEMINI_THINKING_LEVELS, AI_THINKING_LEVELS, AdapterContextImpl, AdapterRegistrationConflictError, ArchMap, BOT_CWD, BUILTIN_PLUGINS, BotRegistry, CORE_PLUGINS, CapabilityRegistry, ChromeUA, CommandManager, DEFAULT_SKILL_ROOT_SPECS, DriverShutdownError, EventBus, EventCorrelator, HttpRequestError, MessageSegmentImpl, MiokuContext, MiokuRuntime, SKILL_COMPATIBILITY_MAX, SKILL_DESCRIPTION_MAX, SKILL_FILE_NAME, SKILL_KNOWN_KEYS, SKILL_NAME_MAX, SKILL_NAME_PATTERN, ServiceManager, Services, SystemMap, TOOL_RESULT_FOLLOWUP_KEY, UnsupportedCapabilityError, WebSocketConnectTimeoutError, addService, applyLogLevel, asMessage, atOf, avatarGet, avatarSet, base64Decode, base64Encode, bindCapabilities, botConfig, botStatus, box, buildAdapterReport, buildMiokuStatus, buildRoutes, buildSpawnPlan, clamp, collectBotStats, colorize, colors, commandExists, connectedBotKey, connectedBots, conversationGetHistory, createCmd, createDB, createDefaultDriver, createFriendRef, createGroupRef, createImportContext, createMessage, createMiokuLogger, createRuntime, createSkillCatalog, createStore, dayjs, dedent, defineAdapter, defineCapability, definePlugin, defineService, defineState, deleteServiceConfig, discoverAdapterCandidates, discoverPluginCandidates, discoverRoot, discoverSkills, displayAdapterId, ensureDataDir, expandHomePath, filesize, filter, find, findLocalPlugins, findSkillRoot, formatAdapterReport, formatDuration, formatMiokuStatus, formatMiokuStatusFn, forwardSend, friendDelete, friendGetInfo, friendGetList, fs, getActiveCommandManager, getAllPluginRuntimeStates, getBuiltinPlugins, getConfigDir, getDataDir, getGTk, getPluginConfigDir, getPluginDataDir, getPluginMetadata, getPluginMetadataList, getPluginRuntimeState, getService, getServiceConfig, getServiceConfigDir, getServiceConfigs, getServiceDataDir, getTerminalInput, groupGetInfo, groupGetList, groupGetMembers, groupLeave, groupSetName, groupSetPortrait, groupSetWholeBan, hasEventRight, hasPluginState, hasRight, hasService, isAdapterEvent, isAdmin, isBoolean, isBotEvent, isDefined, isEventAdmin, isEventAdminConfigOnly, isEventGroupAdmin, isEventGroupOwner, isEventMaster, isEventOwner, isEventOwnerOrAdmin, isFunction, isMessage, isMessageEvent, isMetaEvent, isMiokuPlugin, isNoticeEvent, isNumber, isObject, isOwner, isOwnerOrAdmin, isRequestEvent, isSegment, isString, listSkillEntries, loadAdapterDefinition, loadLocalPlugin, loadNpmPlugin, localNum, localeDate, localeTime, locateSkillRoots, rootLogger as logger, match, md5, memberBan, memberGetInfo, memberKick, memberPoke, memberSetAdmin, memberSetCard, memberSetTitle, mergeSkillGroups, messageGet, messageGetForward, messageRecall, messageSend, mriLib as mri, noNullish, normalizeAIThinkingLevel, normalizeAdmins, normalizeOwners, normalizePlugins, normalizeSkillPermissionRole, noticeAdmins, noticeFriends, noticeGroups, noticeOwners, parseSkillFile, path, prettyMs, profileSet, qs, randomId, randomInt, randomItem, randomItems, readMiokuConfig, readPackageJson, readPackageJsonSafe, readSkillEntry, registerPluginArtifacts, registerServiceConfig, registerStatusProvider, reloadMiokuConfig, removePluginMetadata, renderSkillCatalog, renderSkillContent, requireService, resetPluginMetadata, resetPluginRuntimeState, resolveCommand, resolveEntry, resolveLocalPluginEntry, resolveLocalPluginPath, resolveSkillRoots, rootLogger, rootOfPath, runCommand, runCommandInherit, segment, sendMessage, manager_default as serviceManager, servicesRegistry, setActiveCommandManager, setBotCwd, setBuiltinPlugins, setPluginMetadata, setPluginRuntimeState, setService, setWritableConfig, start, startRuntime, string2argv, stringifyError, stripAnsi, text, toArray, toId, toUserId, unique, updateMiokuConfig, updateServiceConfig, uuid, version$1 as version, wait, writePackageJson };
7199
+ export { AI_GEMINI_THINKING_LEVELS, AI_THINKING_LEVELS, AdapterContextImpl, AdapterRegistrationConflictError, ArchMap, BOT_CWD, BUILTIN_PLUGINS, BotRegistry, CORE_PLUGINS, CapabilityRegistry, ChromeUA, CommandManager, DEFAULT_SKILL_ROOT_SPECS, DriverShutdownError, EventBus, EventCorrelator, HttpRequestError, MessageSegmentImpl, MiokuContext, MiokuRuntime, SKILL_COMPATIBILITY_MAX, SKILL_DESCRIPTION_MAX, SKILL_FILE_NAME, SKILL_KNOWN_KEYS, SKILL_NAME_MAX, SKILL_NAME_PATTERN, ServiceManager, Services, SystemMap, TOOL_RESULT_FOLLOWUP_KEY, UnsupportedCapabilityError, WebSocketConnectTimeoutError, addService, applyLogLevel, asMessage, atOf, avatarGet, avatarSet, base64Decode, base64Encode, bindCapabilities, botConfig, botStatus, box, buildAdapterReport, buildMiokuStatus, buildRoutes, buildSpawnPlan, clamp, collectBotStats, colorize, colors, commandExists, connectedBotKey, connectedBots, conversationGetHistory, createCmd, createDB, createDefaultDriver, createFriendRef, createGroupRef, createImportContext, createMessage, createMiokuLogger, createRuntime, createSkillCatalog, createStore, dayjs, dedent, defineAdapter, defineCapability, definePlugin, defineService, defineState, deleteServiceConfig, discoverAdapterCandidates, discoverPluginCandidates, discoverRoot, discoverSkills, displayAdapterId, ensureDataDir, expandHomePath, filesize, filter, find, findLocalPlugins, findSkillRoot, formatAdapterReport, formatDuration, formatMiokuStatus, formatMiokuStatusFn, forwardSend, friendDelete, friendGetInfo, friendGetList, fs, getActiveCommandManager, getAllPluginRuntimeStates, getBuiltinPlugins, getConfigDefaults, getConfigDir, getDataDir, getGTk, getPluginConfigDir, getPluginDataDir, getPluginMetadata, getPluginMetadataList, getPluginRuntimeState, getService, getServiceConfig, getServiceConfigDir, getServiceConfigs, getServiceDataDir, getTerminalInput, groupGetInfo, groupGetList, groupGetMembers, groupLeave, groupSetName, groupSetPortrait, groupSetWholeBan, hasEventRight, hasPluginState, hasRight, hasService, isAdapterEvent, isAdmin, isBoolean, isBotEvent, isDefined, isEventAdmin, isEventAdminConfigOnly, isEventGroupAdmin, isEventGroupOwner, isEventMaster, isEventOwner, isEventOwnerOrAdmin, isFunction, isMessage, isMessageEvent, isMetaEvent, isMiokuPlugin, isNoticeEvent, isNumber, isObject, isOwner, isOwnerOrAdmin, isRequestEvent, isSegment, isString, listSkillEntries, loadAdapterDefinition, loadLocalPlugin, loadNpmPlugin, localNum, localeDate, localeTime, locateSkillRoots, rootLogger as logger, match, md5, memberBan, memberGetInfo, memberKick, memberPoke, memberSetAdmin, memberSetCard, memberSetTitle, mergeSkillGroups, messageGet, messageGetForward, messageRecall, messageSend, mriLib as mri, noNullish, normalizeAIThinkingLevel, normalizeAdmins, normalizeOwners, normalizePlugins, normalizeSkillPermissionRole, noticeAdmins, noticeFriends, noticeGroups, noticeOwners, parseSkillFile, path, prettyMs, profileSet, qs, randomId, randomInt, randomItem, randomItems, readMiokuConfig, readPackageJson, readPackageJsonSafe, readSkillEntry, registerConfigDefaults, registerPluginArtifacts, registerServiceConfig, registerStatusProvider, reloadMiokuConfig, removePluginMetadata, renderSkillCatalog, renderSkillContent, requireService, resetPluginMetadata, resetPluginRuntimeState, resolveCommand, resolveEntry, resolveLocalPluginEntry, resolveLocalPluginPath, resolveSkillRoots, rootLogger, rootOfPath, runCommand, runCommandInherit, segment, sendMessage, manager_default as serviceManager, servicesRegistry, setActiveCommandManager, setBotCwd, setBuiltinPlugins, setPluginMetadata, setPluginRuntimeState, setService, setWritableConfig, start, startRuntime, string2argv, stringifyError, stripAnsi, text, toArray, toId, toUserId, unique, updateMiokuConfig, updateServiceConfig, uuid, version$1 as version, wait, withConfigDefaults, writePackageJson };
7142
7200
  //# sourceMappingURL=index.js.map