@chatbi-v/core 3.0.0 → 3.1.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
@@ -85,6 +85,7 @@ __export(index_exports, {
85
85
  StorageManager: () => StorageManager,
86
86
  ToolRegistry: () => ToolRegistry,
87
87
  adapterRegistry: () => adapterRegistry,
88
+ aiStore: () => aiStore,
88
89
  apiEngine: () => apiEngine,
89
90
  assertManifest: () => assertManifest,
90
91
  cleanUrlParams: () => cleanUrlParams,
@@ -108,6 +109,7 @@ __export(index_exports, {
108
109
  evaluateRule: () => evaluateRule,
109
110
  evaluateRules: () => evaluateRules,
110
111
  extractManifestFromPlugin: () => extractManifestFromPlugin,
112
+ featureFlagsStore: () => featureFlagsStore,
111
113
  getDefaultRegistry: () => getDefaultRegistry,
112
114
  handleError: () => handleError,
113
115
  hashString: () => simpleHash2,
@@ -125,9 +127,6 @@ __export(index_exports, {
125
127
  resolvePluginRegistry: () => resolvePluginRegistry,
126
128
  serviceRegistry: () => serviceRegistry,
127
129
  simpleHash: () => simpleHash,
128
- useAIStore: () => useAIStore,
129
- useFeature: () => useFeature,
130
- useFeatureFlags: () => useFeatureFlags,
131
130
  validateManifest: () => validateManifest,
132
131
  version: () => version
133
132
  });
@@ -135,7 +134,10 @@ module.exports = __toCommonJS(index_exports);
135
134
 
136
135
  // src/types/branded.ts
137
136
  var import_zod = require("zod");
138
- var PluginIdSchema = import_zod.z.string().min(1, "Plugin ID \u4E0D\u80FD\u4E3A\u7A7A").regex(/^[a-zA-Z0-9][-a-zA-Z0-9.]*[a-zA-Z0-9]$/, "Plugin ID \u5FC5\u987B\u7B26\u5408\u53CD\u5411\u57DF\u540D\u683C\u5F0F");
137
+ var PluginIdSchema = import_zod.z.string().min(1, "Plugin ID \u4E0D\u80FD\u4E3A\u7A7A").regex(
138
+ /^[a-zA-Z0-9][-a-zA-Z0-9.]*[a-zA-Z0-9]$/,
139
+ "Plugin ID \u5FC5\u987B\u7B26\u5408\u53CD\u5411\u57DF\u540D\u683C\u5F0F"
140
+ );
139
141
  var SlotKeySchema = import_zod.z.string().min(1, "SlotKey \u4E0D\u80FD\u4E3A\u7A7A");
140
142
  function createPluginId(id) {
141
143
  const validated = PluginIdSchema.parse(id);
@@ -229,7 +231,14 @@ var DependencySchema = import_zod3.z.object({
229
231
  /** 是否为可选依赖 */
230
232
  optional: import_zod3.z.boolean().optional().default(false)
231
233
  });
232
- var PLUGIN_TYPES = ["business", "functional", "view", "theme", "renderer", "system"];
234
+ var PLUGIN_TYPES = [
235
+ "business",
236
+ "functional",
237
+ "view",
238
+ "theme",
239
+ "renderer",
240
+ "system"
241
+ ];
233
242
  var EntrySchema = import_zod3.z.union([
234
243
  import_zod3.z.string().min(1, "\u5165\u53E3\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A"),
235
244
  import_zod3.z.object({
@@ -258,16 +267,20 @@ var ConfigurationSchema = import_zod3.z.array(
258
267
  options: import_zod3.z.array(import_zod3.z.object({ label: import_zod3.z.string(), value: import_zod3.z.any() })).optional()
259
268
  })
260
269
  );
261
- var PERMISSION_ACTIONS = ["read", "write", "execute", "admin"];
270
+ var PERMISSION_ACTIONS = [
271
+ "read",
272
+ "write",
273
+ "execute",
274
+ "admin"
275
+ ];
262
276
  var PERMISSION_SCOPES = ["plugin", "global", "user"];
263
277
  var PluginManifestSchema = import_zod3.z.object({
264
278
  /** 插件唯一 ID (推荐反向域名格式) */
265
279
  id: import_zod3.z.string().min(1, "\u63D2\u4EF6 ID \u4E0D\u80FD\u4E3A\u7A7A"),
266
280
  /** 插件版本号 (SemVer) */
267
- version: import_zod3.z.string().min(1, "\u7248\u672C\u53F7\u4E0D\u80FD\u4E3A\u7A7A").refine(
268
- (v) => /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$/.test(v),
269
- { message: "\u7248\u672C\u53F7\u5FC5\u987B\u7B26\u5408 SemVer \u683C\u5F0F" }
270
- ),
281
+ version: import_zod3.z.string().min(1, "\u7248\u672C\u53F7\u4E0D\u80FD\u4E3A\u7A7A").refine((v) => /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$/.test(v), {
282
+ message: "\u7248\u672C\u53F7\u5FC5\u987B\u7B26\u5408 SemVer \u683C\u5F0F"
283
+ }),
271
284
  /** 插件显示名称 */
272
285
  name: import_zod3.z.string().min(1, "\u63D2\u4EF6\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"),
273
286
  /** 插件入口 */
@@ -295,11 +308,13 @@ var PluginManifestSchema = import_zod3.z.object({
295
308
  /** 路由定义 (仅供展示,实际路由在运行时注册) */
296
309
  routes: import_zod3.z.array(import_zod3.z.object({ path: import_zod3.z.string() })).optional(),
297
310
  /** 权限声明 */
298
- permissions: import_zod3.z.array(import_zod3.z.object({
299
- action: import_zod3.z.enum(PERMISSION_ACTIONS),
300
- scope: import_zod3.z.enum(PERMISSION_SCOPES),
301
- resource: import_zod3.z.string()
302
- })).optional(),
311
+ permissions: import_zod3.z.array(
312
+ import_zod3.z.object({
313
+ action: import_zod3.z.enum(PERMISSION_ACTIONS),
314
+ scope: import_zod3.z.enum(PERMISSION_SCOPES),
315
+ resource: import_zod3.z.string()
316
+ })
317
+ ).optional(),
303
318
  /** 插件优先级 */
304
319
  priority: import_zod3.z.number().optional().default(100)
305
320
  });
@@ -324,7 +339,7 @@ var Slot = {
324
339
  Custom: "custom"
325
340
  };
326
341
  var BasePlugin = class {
327
- /**
342
+ /**
328
343
  * 插件 ID
329
344
  * @description 自动从 metadata.id 获取
330
345
  */
@@ -475,7 +490,9 @@ var Logger = class _Logger {
475
490
  return [`%c ${prefix} %c${locStr}`, style, locStyle];
476
491
  } else {
477
492
  const colorCode = getAnsiColorForString(prefix);
478
- return [`${colorCode}[${prefix}]${ANSI.reset}${ANSI.dim}${locStr}${ANSI.reset}`];
493
+ return [
494
+ `${colorCode}[${prefix}]${ANSI.reset}${ANSI.dim}${locStr}${ANSI.reset}`
495
+ ];
479
496
  }
480
497
  }
481
498
  /**
@@ -489,11 +506,18 @@ var Logger = class _Logger {
489
506
  const countStyle = "color: gray; font-size: 0.9em;";
490
507
  const locStyle = "color: gray; font-size: 0.8em; font-family: monospace; font-weight: normal;";
491
508
  const countStr = count > 0 ? `(${count > 1 ? count + " messages" : "1 message"}${countDetails ? ", " + countDetails : ""})` : "";
492
- return [`%c ${prefix} %c ${countStr}%c${locStr}`, badgeStyle, countStyle, locStyle];
509
+ return [
510
+ `%c ${prefix} %c ${countStr}%c${locStr}`,
511
+ badgeStyle,
512
+ countStyle,
513
+ locStyle
514
+ ];
493
515
  } else {
494
516
  const colorCode = getAnsiColorForString(prefix);
495
517
  const countStr = count > 0 ? `(${count > 1 ? count + " messages" : "1 message"}${countDetails ? ", " + countDetails : ""})` : "";
496
- return [`${colorCode}[${prefix}]${ANSI.reset} ${ANSI.dim}${countStr}${locStr}${ANSI.reset}`];
518
+ return [
519
+ `${colorCode}[${prefix}]${ANSI.reset} ${ANSI.dim}${countStr}${locStr}${ANSI.reset}`
520
+ ];
497
521
  }
498
522
  }
499
523
  /**
@@ -549,14 +573,22 @@ var Logger = class _Logger {
549
573
  });
550
574
  prefixOrder.forEach((prefix) => {
551
575
  const entries = groups.get(prefix);
552
- const counts = entries.reduce((acc, curr) => {
553
- const key = curr.level === 2 /* WARN */ ? "warn" : "info";
554
- acc[key] = (acc[key] || 0) + 1;
555
- return acc;
556
- }, {});
576
+ const counts = entries.reduce(
577
+ (acc, curr) => {
578
+ const key = curr.level === 2 /* WARN */ ? "warn" : "info";
579
+ acc[key] = (acc[key] || 0) + 1;
580
+ return acc;
581
+ },
582
+ {}
583
+ );
557
584
  const countDetails = Object.entries(counts).map(([k, v]) => `${v} ${k}`).join(", ");
558
585
  const lastLocation = entries[entries.length - 1].location;
559
- const groupTitleArgs = _Logger.getGroupTitleArgs(prefix, entries.length, entries.length > 1 ? countDetails : "", lastLocation);
586
+ const groupTitleArgs = _Logger.getGroupTitleArgs(
587
+ prefix,
588
+ entries.length,
589
+ entries.length > 1 ? countDetails : "",
590
+ lastLocation
591
+ );
560
592
  console.groupCollapsed(...groupTitleArgs);
561
593
  entries.forEach((entry) => {
562
594
  const method = entry.level === 2 /* WARN */ ? "warn" : entry.level === 0 /* DEBUG */ ? "debug" : "info";
@@ -601,7 +633,11 @@ var Logger = class _Logger {
601
633
  if (_Logger.level <= 1 /* INFO */) {
602
634
  _Logger.flush();
603
635
  const location2 = getCallerLocation();
604
- const prefixArgs = this.getFormattedPrefix(this.prefix, 1 /* INFO */, location2);
636
+ const prefixArgs = this.getFormattedPrefix(
637
+ this.prefix,
638
+ 1 /* INFO */,
639
+ location2
640
+ );
605
641
  if (_Logger.isBrowser) {
606
642
  if (collapsed) {
607
643
  console.groupCollapsed(...prefixArgs, label);
@@ -668,7 +704,7 @@ var ServiceRegistry = class {
668
704
  * 异步等待并获取服务
669
705
  * @description 如果服务尚未注册,将返回一个 Promise,直到该服务被注册时 resolve。
670
706
  * 支持设置超时时间,防止因插件加载失败导致的永久挂起。
671
- *
707
+ *
672
708
  * @template T - 服务类型的泛型
673
709
  * @param name - 待等待的服务名称
674
710
  * @param timeout - 超时时间 (毫秒),默认 10000ms (10秒)。若为 0 则永不超时。
@@ -697,7 +733,9 @@ var ServiceRegistry = class {
697
733
  if (set.size === 0) this.listeners.delete(name);
698
734
  }
699
735
  const availableServices = Array.from(this.services.keys());
700
- logger2.warn(`\u7B49\u5F85\u670D\u52A1 "${name}" \u8D85\u65F6\u3002\u5F53\u524D\u53EF\u7528\u670D\u52A1: ${availableServices.join(", ")}`);
736
+ logger2.warn(
737
+ `\u7B49\u5F85\u670D\u52A1 "${name}" \u8D85\u65F6\u3002\u5F53\u524D\u53EF\u7528\u670D\u52A1: ${availableServices.join(", ")}`
738
+ );
701
739
  reject(new Error(`\u7B49\u5F85\u670D\u52A1 "${name}" \u8D85\u65F6 (${timeout}ms)`));
702
740
  }, timeout);
703
741
  }
@@ -759,7 +797,9 @@ var ConfigManager = class {
759
797
  * 深度合并两个对象
760
798
  */
761
799
  deepMerge(target, source) {
762
- const result = { ...target };
800
+ const result = {
801
+ ...target
802
+ };
763
803
  if (source === null || source === void 0) {
764
804
  return result;
765
805
  }
@@ -810,7 +850,9 @@ var ToolRegistry = class {
810
850
  */
811
851
  register(tool) {
812
852
  if (this.tools.has(tool.name)) {
813
- console.warn(`[AI Tool] Tool ${tool.name} is already registered, overwriting.`);
853
+ console.warn(
854
+ `[AI Tool] Tool ${tool.name} is already registered, overwriting.`
855
+ );
814
856
  }
815
857
  this.tools.set(tool.name, tool);
816
858
  }
@@ -850,8 +892,14 @@ var MockAIProvider = class {
850
892
  ["greeting", "\u4F60\u597D\uFF01\u6211\u662F AI \u52A9\u624B\uFF0C\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u52A9\u4F60\u7684\u5417\uFF1F"],
851
893
  ["weather", "\u4ECA\u5929\u5929\u6C14\u6674\u6717\uFF0C\u9002\u5408\u51FA\u884C\uFF01"],
852
894
  ["time", `\u73B0\u5728\u65F6\u95F4\u662F ${(/* @__PURE__ */ new Date()).toLocaleString()}`],
853
- ["help", "\u6211\u53EF\u4EE5\u5E2E\u4F60\uFF1A\n1. \u67E5\u8BE2\u5929\u6C14\n2. \u6267\u884C\u8BA1\u7B97\n3. \u83B7\u53D6\u65F6\u95F4\n4. \u56DE\u7B54\u95EE\u9898"],
854
- ["default", '\u6211\u6536\u5230\u4F60\u7684\u6D88\u606F: "{input}"\u3002\u4F60\u53EF\u4EE5\u95EE\u6211\u5929\u6C14\u3001\u65F6\u95F4\uFF0C\u6216\u8005\u9700\u8981\u4EC0\u4E48\u5E2E\u52A9\uFF1F']
895
+ [
896
+ "help",
897
+ "\u6211\u53EF\u4EE5\u5E2E\u4F60\uFF1A\n1. \u67E5\u8BE2\u5929\u6C14\n2. \u6267\u884C\u8BA1\u7B97\n3. \u83B7\u53D6\u65F6\u95F4\n4. \u56DE\u7B54\u95EE\u9898"
898
+ ],
899
+ [
900
+ "default",
901
+ '\u6211\u6536\u5230\u4F60\u7684\u6D88\u606F: "{input}"\u3002\u4F60\u53EF\u4EE5\u95EE\u6211\u5929\u6C14\u3001\u65F6\u95F4\uFF0C\u6216\u8005\u9700\u8981\u4EC0\u4E48\u5E2E\u52A9\uFF1F'
902
+ ]
855
903
  ]);
856
904
  /**
857
905
  * 生成回复
@@ -862,7 +910,9 @@ var MockAIProvider = class {
862
910
  return this.responses.get("greeting");
863
911
  }
864
912
  if (/(天气|weather)/i.test(input)) {
865
- const cityMatch = input.match(/(?:在|到|北京|上海|广州|深圳|杭州)?(.+?(?:天气|weather))/i);
913
+ const cityMatch = input.match(
914
+ /(?:在|到|北京|上海|广州|深圳|杭州)?(.+?(?:天气|weather))/i
915
+ );
866
916
  const city = cityMatch?.[1]?.replace(/天气|weather/gi, "").trim() || "\u5317\u4EAC";
867
917
  return `${city} \u4ECA\u5929\u5929\u6C14\u6674\u6717\uFF0C25\xB0C\uFF0C\u9002\u5408\u51FA\u884C\uFF01`;
868
918
  }
@@ -884,7 +934,9 @@ var MockAIProvider = class {
884
934
  * 聊天(非流式)
885
935
  */
886
936
  async chat(messages, options) {
887
- await new Promise((resolve) => setTimeout(resolve, 500 + Math.random() * 500));
937
+ await new Promise(
938
+ (resolve) => setTimeout(resolve, 500 + Math.random() * 500)
939
+ );
888
940
  const lastMessage = messages[messages.length - 1];
889
941
  const content = lastMessage?.content || "";
890
942
  return {
@@ -906,7 +958,9 @@ var MockAIProvider = class {
906
958
  type: "content",
907
959
  content: char
908
960
  };
909
- await new Promise((resolve) => setTimeout(resolve, 30 + Math.random() * 50));
961
+ await new Promise(
962
+ (resolve) => setTimeout(resolve, 30 + Math.random() * 50)
963
+ );
910
964
  }
911
965
  yield { type: "done" };
912
966
  }
@@ -1104,7 +1158,9 @@ var SessionManager = class {
1104
1158
  return this.sessions.get(id) || null;
1105
1159
  }
1106
1160
  listSessions() {
1107
- return Array.from(this.sessions.values()).sort((a, b) => b.updatedAt - a.updatedAt);
1161
+ return Array.from(this.sessions.values()).sort(
1162
+ (a, b) => b.updatedAt - a.updatedAt
1163
+ );
1108
1164
  }
1109
1165
  deleteSession(id) {
1110
1166
  this.sessions.delete(id);
@@ -1165,8 +1221,8 @@ var SessionLocalStorageAdapter = class {
1165
1221
  };
1166
1222
 
1167
1223
  // src/ai/store.ts
1168
- var import_zustand = require("zustand");
1169
- var useAIStore = (0, import_zustand.create)((set, get) => ({
1224
+ var import_vanilla = require("zustand/vanilla");
1225
+ var aiStore = (0, import_vanilla.createStore)((set, get) => ({
1170
1226
  // Initial state
1171
1227
  provider: null,
1172
1228
  sessions: [],
@@ -1264,7 +1320,7 @@ var useAIStore = (0, import_zustand.create)((set, get) => ({
1264
1320
  }));
1265
1321
  function createAIStore(apiKey, defaultModel) {
1266
1322
  const provider = new OpenAIProvider(apiKey, { model: defaultModel });
1267
- useAIStore.getState().setProvider(provider);
1323
+ aiStore.getState().setProvider(provider);
1268
1324
  }
1269
1325
 
1270
1326
  // src/domain/auto-loader.ts
@@ -1273,13 +1329,17 @@ var DEFAULT_RULES = [
1273
1329
  { pathSegment: "@chatbi-plugins", idPrefix: "@chatbi-v/plugin" },
1274
1330
  { pathSegment: "@chatbi-apps", idPrefix: "@chatbi-v/app" },
1275
1331
  { pathSegment: "packages/plugins", idPrefix: "@chatbi-v/plugin" },
1276
- { pathSegment: "packages/apps", idPrefix: "@chatbi-v/app" }
1332
+ { pathSegment: "packages/apps", idPrefix: "@chatbi-v/app" },
1333
+ { pathSegment: "apps", idPrefix: "@chatbi-v/app" }
1277
1334
  ];
1278
1335
  var resolvePluginRegistry = (options) => {
1279
1336
  const { modules, rules = DEFAULT_RULES } = options;
1280
1337
  const registry = {};
1281
1338
  const compiledRules = rules.map((rule) => {
1282
- const escapedSegment = rule.pathSegment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1339
+ const escapedSegment = rule.pathSegment.replace(
1340
+ /[.*+?^${}()|[\]\\]/g,
1341
+ "\\$&"
1342
+ );
1283
1343
  return {
1284
1344
  ...rule,
1285
1345
  regex: new RegExp(`${escapedSegment}/([^/]+)/src/index`)
@@ -1359,7 +1419,7 @@ var CoreError = class extends Error {
1359
1419
  }
1360
1420
  };
1361
1421
  function handleError(error, options) {
1362
- const { code, strategy, defaultValue, logger: logger10, context } = options;
1422
+ const { code, strategy, defaultValue, logger: logger11, context } = options;
1363
1423
  const coreError = error instanceof CoreError ? error : new CoreError(
1364
1424
  code,
1365
1425
  error instanceof Error ? error.message : String(error),
@@ -1368,16 +1428,16 @@ function handleError(error, options) {
1368
1428
  );
1369
1429
  switch (strategy) {
1370
1430
  case "throw" /* THROW */:
1371
- logger10?.error(`[${code}] \u9519\u8BEF\u629B\u51FA:`, coreError);
1431
+ logger11?.error(`[${code}] \u9519\u8BEF\u629B\u51FA:`, coreError);
1372
1432
  throw coreError;
1373
1433
  case "resolve" /* RESOLVE */:
1374
- logger10?.warn(`[${code}] \u9519\u8BEF\u5DF2\u964D\u7EA7:`, coreError);
1434
+ logger11?.warn(`[${code}] \u9519\u8BEF\u5DF2\u964D\u7EA7:`, coreError);
1375
1435
  return defaultValue;
1376
1436
  case "reject" /* REJECT */:
1377
- logger10?.error(`[${code}] \u9519\u8BEF\u62D2\u7EDD:`, coreError);
1437
+ logger11?.error(`[${code}] \u9519\u8BEF\u62D2\u7EDD:`, coreError);
1378
1438
  return Promise.reject(coreError);
1379
1439
  case "silent" /* SILENT */:
1380
- logger10?.debug(`[${code}] \u9519\u8BEF\u5DF2\u9759\u9ED8:`, coreError);
1440
+ logger11?.debug(`[${code}] \u9519\u8BEF\u5DF2\u9759\u9ED8:`, coreError);
1381
1441
  return defaultValue;
1382
1442
  }
1383
1443
  }
@@ -1625,7 +1685,9 @@ var PerformanceStorage = class {
1625
1685
  */
1626
1686
  enforceLifecycleLimit() {
1627
1687
  if (this.lifecycleCache.length > this.settings.maxLifecycleRecords) {
1628
- this.lifecycleCache = this.lifecycleCache.slice(-this.settings.maxLifecycleRecords);
1688
+ this.lifecycleCache = this.lifecycleCache.slice(
1689
+ -this.settings.maxLifecycleRecords
1690
+ );
1629
1691
  }
1630
1692
  }
1631
1693
  /**
@@ -1633,7 +1695,9 @@ var PerformanceStorage = class {
1633
1695
  */
1634
1696
  enforceRuntimeLimit() {
1635
1697
  if (this.runtimeCache.length > this.settings.maxRuntimeSamples) {
1636
- this.runtimeCache = this.runtimeCache.slice(-this.settings.maxRuntimeSamples);
1698
+ this.runtimeCache = this.runtimeCache.slice(
1699
+ -this.settings.maxRuntimeSamples
1700
+ );
1637
1701
  }
1638
1702
  }
1639
1703
  /**
@@ -1641,7 +1705,10 @@ var PerformanceStorage = class {
1641
1705
  */
1642
1706
  persistLifecycle() {
1643
1707
  try {
1644
- this.systemStorage.setItem(this.LIFECYCLE_KEY, JSON.stringify(this.lifecycleCache));
1708
+ this.systemStorage.setItem(
1709
+ this.LIFECYCLE_KEY,
1710
+ JSON.stringify(this.lifecycleCache)
1711
+ );
1645
1712
  } catch (e) {
1646
1713
  console.warn("[PerformanceStorage] Failed to persist lifecycle:", e);
1647
1714
  }
@@ -1651,7 +1718,10 @@ var PerformanceStorage = class {
1651
1718
  */
1652
1719
  persistRuntime() {
1653
1720
  try {
1654
- this.systemStorage.setItem(this.RUNTIME_KEY, JSON.stringify(this.runtimeCache));
1721
+ this.systemStorage.setItem(
1722
+ this.RUNTIME_KEY,
1723
+ JSON.stringify(this.runtimeCache)
1724
+ );
1655
1725
  } catch (e) {
1656
1726
  console.warn("[PerformanceStorage] Failed to persist runtime:", e);
1657
1727
  }
@@ -1687,8 +1757,12 @@ var PerformanceStorage = class {
1687
1757
  this.systemStorage.removeItem(this.LIFECYCLE_KEY);
1688
1758
  this.systemStorage.removeItem(this.RUNTIME_KEY);
1689
1759
  } else {
1690
- this.lifecycleCache = this.lifecycleCache.filter((m) => m.pluginId !== pluginId);
1691
- this.runtimeCache = this.runtimeCache.filter((m) => m.pluginId !== pluginId);
1760
+ this.lifecycleCache = this.lifecycleCache.filter(
1761
+ (m) => m.pluginId !== pluginId
1762
+ );
1763
+ this.runtimeCache = this.runtimeCache.filter(
1764
+ (m) => m.pluginId !== pluginId
1765
+ );
1692
1766
  this.persistLifecycle();
1693
1767
  this.persistRuntime();
1694
1768
  }
@@ -1780,7 +1854,7 @@ var LocalStorageAdapter = class {
1780
1854
  }
1781
1855
  /**
1782
1856
  * 清空存储空间
1783
- * @description
1857
+ * @description
1784
1858
  * - 若定义了前缀:仅删除以该前缀开头的键名,不影响其他数据。
1785
1859
  * - 若未定义前缀:调用原生 `localStorage.clear()` 清空所有数据。
1786
1860
  */
@@ -1890,8 +1964,8 @@ var DefaultEventBus = class {
1890
1964
  };
1891
1965
 
1892
1966
  // src/store.ts
1893
- var import_vanilla = require("zustand/vanilla");
1894
- var coreStore = (0, import_vanilla.createStore)((set) => ({
1967
+ var import_vanilla2 = require("zustand/vanilla");
1968
+ var coreStore = (0, import_vanilla2.createStore)((set) => ({
1895
1969
  pluginVersion: 0,
1896
1970
  slotVersions: {},
1897
1971
  routeVersion: 0,
@@ -1962,7 +2036,12 @@ var ProxySandbox = class {
1962
2036
  allowNetwork: true,
1963
2037
  ...options
1964
2038
  };
1965
- const dangerousGlobals = ["eval", "Function", "importScripts", "execScript"];
2039
+ const dangerousGlobals = [
2040
+ "eval",
2041
+ "Function",
2042
+ "importScripts",
2043
+ "execScript"
2044
+ ];
1966
2045
  for (const dangerous of dangerousGlobals) {
1967
2046
  if (typeof globalContext[dangerous] !== "undefined") {
1968
2047
  logger6.warn(
@@ -2028,11 +2107,17 @@ var ProxySandbox = class {
2028
2107
  */
2029
2108
  inactive() {
2030
2109
  this.running = false;
2031
- this.effectPool.timeouts.forEach((id) => this.globalContext.clearTimeout(id));
2110
+ this.effectPool.timeouts.forEach(
2111
+ (id) => this.globalContext.clearTimeout(id)
2112
+ );
2032
2113
  this.effectPool.timeouts.clear();
2033
- this.effectPool.intervals.forEach((id) => this.globalContext.clearInterval(id));
2114
+ this.effectPool.intervals.forEach(
2115
+ (id) => this.globalContext.clearInterval(id)
2116
+ );
2034
2117
  this.effectPool.intervals.clear();
2035
- this.effectPool.rafs.forEach((id) => this.globalContext.cancelAnimationFrame(id));
2118
+ this.effectPool.rafs.forEach(
2119
+ (id) => this.globalContext.cancelAnimationFrame(id)
2120
+ );
2036
2121
  this.effectPool.rafs.clear();
2037
2122
  this.effectPool.listeners.forEach((listeners, type) => {
2038
2123
  listeners.forEach(({ listener, options }) => {
@@ -2179,7 +2264,9 @@ var ProxySandbox = class {
2179
2264
  fakeWindow.removeEventListener = (type, listener, options) => {
2180
2265
  const listeners = this.effectPool.listeners.get(type);
2181
2266
  if (listeners) {
2182
- const index = listeners.findIndex((item) => item.listener === listener && item.options === options);
2267
+ const index = listeners.findIndex(
2268
+ (item) => item.listener === listener && item.options === options
2269
+ );
2183
2270
  if (index !== -1) listeners.splice(index, 1);
2184
2271
  }
2185
2272
  return this.globalContext.removeEventListener(type, listener, options);
@@ -2278,36 +2365,43 @@ var PluginRuntime = class {
2278
2365
  logger7.debug(`\u5DF2\u4E3A\u63D2\u4EF6 ${this.plugin.id} \u81EA\u52A8\u6CE8\u518C API \u914D\u7F6E`);
2279
2366
  }
2280
2367
  if (this.plugin.metadata.configuration && this.plugin.metadata.configuration.length > 0) {
2281
- const configMap = new Map(this.plugin.metadata.configuration.map((c) => [c.key, c]));
2368
+ const configMap = new Map(
2369
+ this.plugin.metadata.configuration.map((c) => [c.key, c])
2370
+ );
2282
2371
  const getterCache = /* @__PURE__ */ new Map();
2283
- const configService = new Proxy({}, {
2284
- get: (target, prop) => {
2285
- if (typeof prop !== "string") {
2286
- return Reflect.get(target, prop);
2287
- }
2288
- if (prop.startsWith("get")) {
2289
- if (getterCache.has(prop)) {
2290
- return getterCache.get(prop);
2372
+ const configService = new Proxy(
2373
+ {},
2374
+ {
2375
+ get: (target, prop) => {
2376
+ if (typeof prop !== "string") {
2377
+ return Reflect.get(target, prop);
2291
2378
  }
2292
- const configKey = prop.slice(3).charAt(0).toLowerCase() + prop.slice(3).slice(1);
2293
- const configItem = configMap.get(configKey);
2294
- if (configItem) {
2295
- if (configItem.private || configItem.internal) {
2296
- logger7.warn(`\u5C1D\u8BD5\u8BBF\u95EE\u79C1\u6709\u914D\u7F6E: ${configKey}`);
2297
- const noop = () => void 0;
2298
- getterCache.set(prop, noop);
2299
- return noop;
2379
+ if (prop.startsWith("get")) {
2380
+ if (getterCache.has(prop)) {
2381
+ return getterCache.get(prop);
2382
+ }
2383
+ const configKey = prop.slice(3).charAt(0).toLowerCase() + prop.slice(3).slice(1);
2384
+ const configItem = configMap.get(configKey);
2385
+ if (configItem) {
2386
+ if (configItem.private || configItem.internal) {
2387
+ logger7.warn(`\u5C1D\u8BD5\u8BBF\u95EE\u79C1\u6709\u914D\u7F6E: ${configKey}`);
2388
+ const noop = () => void 0;
2389
+ getterCache.set(prop, noop);
2390
+ return noop;
2391
+ }
2392
+ const getter = () => this.context.storage.get(configKey);
2393
+ getterCache.set(prop, getter);
2394
+ return getter;
2300
2395
  }
2301
- const getter = () => this.context.storage.get(configKey);
2302
- getterCache.set(prop, getter);
2303
- return getter;
2304
2396
  }
2397
+ return Reflect.get(target, prop);
2305
2398
  }
2306
- return Reflect.get(target, prop);
2307
2399
  }
2308
- });
2400
+ );
2309
2401
  this.context.registerService("config", configService);
2310
- logger7.debug(`\u5DF2\u4E3A\u63D2\u4EF6 ${this.plugin.id} \u81EA\u52A8\u6CE8\u518C\u914D\u7F6E\u670D\u52A1 (Proxy Mode)`);
2402
+ logger7.debug(
2403
+ `\u5DF2\u4E3A\u63D2\u4EF6 ${this.plugin.id} \u81EA\u52A8\u6CE8\u518C\u914D\u7F6E\u670D\u52A1 (Proxy Mode)`
2404
+ );
2311
2405
  }
2312
2406
  if (this.plugin.onLoad) {
2313
2407
  await this.plugin.onLoad(this.context);
@@ -2502,6 +2596,7 @@ var ScopedStorageAdapter = class {
2502
2596
  };
2503
2597
 
2504
2598
  // src/domain/storage-manager.ts
2599
+ var logger8 = createLogger("StorageManager");
2505
2600
  var DEFAULT_MAX_CACHE_SIZE = 100;
2506
2601
  var LRUCache = class {
2507
2602
  constructor(maxSize = DEFAULT_MAX_CACHE_SIZE) {
@@ -2565,6 +2660,22 @@ var StorageManager = class {
2565
2660
  registerSchema(pluginId, schema) {
2566
2661
  this.schemas.set(pluginId, schema);
2567
2662
  }
2663
+ /**
2664
+ * 删除插件的所有存储数据
2665
+ * @description 包括插件私有存储、上下文存储、注册 Schema 及内存缓存
2666
+ * @param pluginId - 插件 ID
2667
+ */
2668
+ deletePluginStorage(pluginId) {
2669
+ const pluginPrefix = `plugin:${pluginId}:`;
2670
+ this.schemas.delete(pluginId);
2671
+ const cacheKeys = this.memoryCache.keys();
2672
+ cacheKeys.forEach((key) => {
2673
+ if (key.startsWith(pluginPrefix)) {
2674
+ this.memoryCache.delete(key);
2675
+ }
2676
+ });
2677
+ logger8.debug(`[StorageManager] Deleted storage for plugin: ${pluginId}`);
2678
+ }
2568
2679
  /**
2569
2680
  * 内部校验方法:检查键名是否在 Schema 中声明
2570
2681
  * @param pluginId - 插件 ID
@@ -2576,12 +2687,16 @@ var StorageManager = class {
2576
2687
  if (!schemaList) return;
2577
2688
  const item = schemaList.find((s) => s.key === key);
2578
2689
  if (!item) {
2579
- console.warn(`[Storage] Key "${key}" not defined in plugin "${pluginId}" schema.`);
2690
+ console.warn(
2691
+ `[Storage] Key "${key}" not defined in plugin "${pluginId}" schema.`
2692
+ );
2580
2693
  return;
2581
2694
  }
2582
2695
  const definedScope = item.scope || "plugin";
2583
2696
  if (definedScope !== scope) {
2584
- console.warn(`[Storage] Key "${key}" defined in scope "${definedScope}" but accessed via "${scope}".`);
2697
+ console.warn(
2698
+ `[Storage] Key "${key}" defined in scope "${definedScope}" but accessed via "${scope}".`
2699
+ );
2585
2700
  }
2586
2701
  }
2587
2702
  /**
@@ -2614,7 +2729,7 @@ var StorageManager = class {
2614
2729
  * - 自动序列化/反序列化 JSON。
2615
2730
  * - 自动校验 Schema。
2616
2731
  * - 取值回退逻辑:持久化存储 -> ConfigManager -> Schema 默认值。
2617
- *
2732
+ *
2618
2733
  * @param pluginId - 插件 ID
2619
2734
  * @returns 包含 get/set/remove 及 shared 子对象的复合接口
2620
2735
  */
@@ -2684,7 +2799,7 @@ var StorageManager = class {
2684
2799
  };
2685
2800
 
2686
2801
  // src/domain/plugin-manager.ts
2687
- var logger8 = createLogger("PluginManager");
2802
+ var logger9 = createLogger("PluginManager");
2688
2803
  var PluginErrorType = /* @__PURE__ */ ((PluginErrorType2) => {
2689
2804
  PluginErrorType2["RECOVERABLE"] = "recoverable";
2690
2805
  PluginErrorType2["FATAL"] = "fatal";
@@ -2818,10 +2933,10 @@ var PluginManager = class {
2818
2933
  const savedStates = systemStorage.getItem("plugin_states");
2819
2934
  if (savedStates) {
2820
2935
  this.pluginStates = JSON.parse(savedStates);
2821
- logger8.debug("\u4ECE\u7CFB\u7EDF\u5B58\u50A8\u4E2D\u52A0\u8F7D\u72B6\u6001:", this.pluginStates);
2936
+ logger9.debug("\u4ECE\u7CFB\u7EDF\u5B58\u50A8\u4E2D\u52A0\u8F7D\u72B6\u6001:", this.pluginStates);
2822
2937
  }
2823
2938
  } catch (e) {
2824
- logger8.error("\u52A0\u8F7D\u63D2\u4EF6\u72B6\u6001\u5931\u8D25:", e);
2939
+ logger9.error("\u52A0\u8F7D\u63D2\u4EF6\u72B6\u6001\u5931\u8D25:", e);
2825
2940
  }
2826
2941
  }
2827
2942
  /**
@@ -2830,9 +2945,9 @@ var PluginManager = class {
2830
2945
  saveStates() {
2831
2946
  try {
2832
2947
  this.storageManager.getSystemStorage().setItem("plugin_states", JSON.stringify(this.pluginStates));
2833
- logger8.debug("\u5DF2\u4FDD\u5B58\u63D2\u4EF6\u72B6\u6001\u5230\u5B58\u50A8");
2948
+ logger9.debug("\u5DF2\u4FDD\u5B58\u63D2\u4EF6\u72B6\u6001\u5230\u5B58\u50A8");
2834
2949
  } catch (e) {
2835
- logger8.error("\u4FDD\u5B58\u63D2\u4EF6\u72B6\u6001\u5931\u8D25:", e);
2950
+ logger9.error("\u4FDD\u5B58\u63D2\u4EF6\u72B6\u6001\u5931\u8D25:", e);
2836
2951
  }
2837
2952
  }
2838
2953
  /**
@@ -2937,7 +3052,9 @@ var PluginManager = class {
2937
3052
  if (this.sharedContext) {
2938
3053
  await this.mountPlugin(pluginId);
2939
3054
  } else {
2940
- logger8.warn(`PluginManager \u5C1A\u672A\u521D\u59CB\u5316\uFF0C\u63D2\u4EF6 ${pluginId} \u5DF2\u6807\u8BB0\u4E3A\u542F\u7528\u4F46\u672A\u6302\u8F7D\u3002\u8BF7\u786E\u4FDD\u8C03\u7528 initPlugins()\u3002`);
3055
+ logger9.warn(
3056
+ `PluginManager \u5C1A\u672A\u521D\u59CB\u5316\uFF0C\u63D2\u4EF6 ${pluginId} \u5DF2\u6807\u8BB0\u4E3A\u542F\u7528\u4F46\u672A\u6302\u8F7D\u3002\u8BF7\u786E\u4FDD\u8C03\u7528 initPlugins()\u3002`
3057
+ );
2941
3058
  }
2942
3059
  }
2943
3060
  /**
@@ -3024,17 +3141,116 @@ var PluginManager = class {
3024
3141
  const plugin = this.plugins.get(pluginId);
3025
3142
  if (plugin) {
3026
3143
  try {
3027
- const runtime = new PluginRuntime(plugin, this.sharedContext, this.storageManager);
3144
+ const runtime = new PluginRuntime(
3145
+ plugin,
3146
+ this.sharedContext,
3147
+ this.storageManager
3148
+ );
3028
3149
  this.runtimes.set(pluginId, runtime);
3029
3150
  runtime.mount();
3030
3151
  } catch (e) {
3031
- logger8.error(`\u542F\u7528\u63D2\u4EF6 ${pluginId} \u5931\u8D25:`, e);
3152
+ logger9.error(`\u542F\u7528\u63D2\u4EF6 ${pluginId} \u5931\u8D25:`, e);
3032
3153
  }
3033
3154
  }
3034
3155
  }
3035
3156
  }
3036
3157
  this.notify();
3037
3158
  }
3159
+ /**
3160
+ * 删除插件及其所有关联状态
3161
+ * @description 完整清理流程:禁用 -> 卸载运行时 -> 清理存储 -> 清理配置 -> 清理状态 -> 通知
3162
+ * @param pluginId - 插件 ID
3163
+ * @param cleanupStorage - 是否清理存储(默认 true)
3164
+ */
3165
+ async deletePlugin(pluginId, cleanupStorage = true) {
3166
+ logger9.info(`[PluginManager] Deleting plugin: ${pluginId}`);
3167
+ if (!this.plugins.has(pluginId)) {
3168
+ logger9.warn(
3169
+ `[PluginManager] Plugin ${pluginId} not found, skipping delete`
3170
+ );
3171
+ return;
3172
+ }
3173
+ this.togglePlugin(pluginId, false);
3174
+ if (cleanupStorage) {
3175
+ this.storageManager.deletePluginStorage(pluginId);
3176
+ }
3177
+ configManager.delete(pluginId);
3178
+ this.plugins.delete(pluginId);
3179
+ this.runtimes.delete(pluginId);
3180
+ delete this.pluginStates[pluginId];
3181
+ this.extensions.forEach((extList, slot) => {
3182
+ const filtered = extList.filter((ext) => ext._pluginId !== pluginId);
3183
+ if (filtered.length !== extList.length) {
3184
+ this.extensions.set(slot, filtered);
3185
+ }
3186
+ });
3187
+ this.memoizedExtensions.clear();
3188
+ this.memoizedRoutes = null;
3189
+ this.notify();
3190
+ logger9.info(`[PluginManager] Plugin ${pluginId} deleted successfully`);
3191
+ }
3192
+ /**
3193
+ * 更新插件元数据和包地址
3194
+ * @description 更新流程:禁用旧版本 -> 卸载 -> 更新元数据 -> 重新加载并激活
3195
+ * @param pluginId - 插件 ID
3196
+ * @param newManifest - 新的插件清单
3197
+ * @param newBundleUrl - 新的包地址(可选,如果不改变则传 undefined)
3198
+ */
3199
+ async updatePlugin(pluginId, newManifest, newBundleUrl) {
3200
+ logger9.info(`[PluginManager] Updating plugin: ${pluginId}`);
3201
+ const existingPlugin = this.plugins.get(pluginId);
3202
+ if (!existingPlugin) {
3203
+ logger9.warn(
3204
+ `[PluginManager] Plugin ${pluginId} not found, cannot update`
3205
+ );
3206
+ return;
3207
+ }
3208
+ this.togglePlugin(pluginId, false);
3209
+ this.runtimes.delete(pluginId);
3210
+ const updatedPlugin = {
3211
+ ...existingPlugin,
3212
+ // @ts-expect-error - existing type issue
3213
+ metadata: {
3214
+ ...existingPlugin.metadata,
3215
+ ...newManifest,
3216
+ // 确保 ID 不被覆盖
3217
+ id: pluginId
3218
+ }
3219
+ };
3220
+ if (newBundleUrl) {
3221
+ try {
3222
+ const reloadedPlugin = await this.loadRemotePlugin(
3223
+ pluginId,
3224
+ newBundleUrl,
3225
+ { version: newManifest.version }
3226
+ );
3227
+ if (reloadedPlugin) {
3228
+ reloadedPlugin.metadata = {
3229
+ ...reloadedPlugin.metadata,
3230
+ ...newManifest,
3231
+ id: pluginId
3232
+ };
3233
+ this.plugins.set(pluginId, reloadedPlugin);
3234
+ } else {
3235
+ this.plugins.set(pluginId, updatedPlugin);
3236
+ }
3237
+ } catch (e) {
3238
+ logger9.error(
3239
+ `[PluginManager] Failed to reload plugin ${pluginId} from ${newBundleUrl}:`,
3240
+ e
3241
+ );
3242
+ this.plugins.set(pluginId, updatedPlugin);
3243
+ }
3244
+ } else {
3245
+ this.plugins.set(pluginId, updatedPlugin);
3246
+ }
3247
+ const pluginToRegister = this.plugins.get(pluginId);
3248
+ if (pluginToRegister) {
3249
+ this.register(pluginToRegister, true);
3250
+ }
3251
+ this.notify();
3252
+ logger9.info(`[PluginManager] Plugin ${pluginId} updated successfully`);
3253
+ }
3038
3254
  /**
3039
3255
  * 设置插件的显示排序权重
3040
3256
  * @param pluginId - 插件 ID
@@ -3098,7 +3314,7 @@ var PluginManager = class {
3098
3314
  try {
3099
3315
  this.storageManager.getContextStorage(pluginId).set(key, value);
3100
3316
  } catch (e) {
3101
- logger8.warn("\u4FDD\u5B58\u914D\u7F6E\u5230\u5B58\u50A8\u5931\u8D25", e);
3317
+ logger9.warn("\u4FDD\u5B58\u914D\u7F6E\u5230\u5B58\u50A8\u5931\u8D25", e);
3102
3318
  }
3103
3319
  this.eventBus.emit("config:changed", { pluginId, key, value });
3104
3320
  }
@@ -3149,7 +3365,9 @@ var PluginManager = class {
3149
3365
  const runtime = this.runtimes.get(pluginId);
3150
3366
  return runtime ? runtime.isLoadedStatus() : false;
3151
3367
  });
3152
- const sortedExtensions = extensions.sort((a, b) => (a.order || 0) - (b.order || 0));
3368
+ const sortedExtensions = extensions.sort(
3369
+ (a, b) => (a.order || 0) - (b.order || 0)
3370
+ );
3153
3371
  this.memoizedExtensions.set(slotStr, sortedExtensions);
3154
3372
  return sortedExtensions;
3155
3373
  }
@@ -3188,7 +3406,7 @@ var PluginManager = class {
3188
3406
  */
3189
3407
  register(plugin, notify = true) {
3190
3408
  if (!this.validatePlugin(plugin)) {
3191
- logger8.error(`\u63D2\u4EF6\u6CE8\u518C\u5931\u8D25: ${plugin?.id || "\u672A\u77E5"}`);
3409
+ logger9.error(`\u63D2\u4EF6\u6CE8\u518C\u5931\u8D25: ${plugin?.id || "\u672A\u77E5"}`);
3192
3410
  return;
3193
3411
  }
3194
3412
  if (this.plugins.has(plugin.id)) {
@@ -3256,12 +3474,14 @@ var PluginManager = class {
3256
3474
  this.handleRendererPlugin(plugin);
3257
3475
  break;
3258
3476
  default:
3259
- logger8.warn(`\u63D2\u4EF6 ${plugin.id} \u7C7B\u578B\u672A\u77E5: ${plugin.metadata.type}, fallback to business logic`);
3477
+ logger9.warn(
3478
+ `\u63D2\u4EF6 ${plugin.id} \u7C7B\u578B\u672A\u77E5: ${plugin.metadata.type}, fallback to business logic`
3479
+ );
3260
3480
  this.handleBusinessPlugin(plugin);
3261
3481
  break;
3262
3482
  }
3263
3483
  if (plugin.metadata.routes && plugin.metadata.routes.length > 0) {
3264
- logger8.info(`\u5DF2\u4ECE\u63D2\u4EF6 ${plugin.id} \u6536\u96C6\u8DEF\u7531:`, plugin.metadata.routes);
3484
+ logger9.info(`\u5DF2\u4ECE\u63D2\u4EF6 ${plugin.id} \u6536\u96C6\u8DEF\u7531:`, plugin.metadata.routes);
3265
3485
  }
3266
3486
  if (plugin.metadata.extensions && plugin.metadata.extensions.length > 0) {
3267
3487
  plugin.metadata.extensions.forEach((ext) => {
@@ -3269,10 +3489,10 @@ var PluginManager = class {
3269
3489
  list.push({ ...ext, _pluginId: plugin.id });
3270
3490
  this.extensions.set(ext.slot, list);
3271
3491
  });
3272
- logger8.info(`\u5DF2\u4ECE\u63D2\u4EF6 ${plugin.id} \u6536\u96C6\u6269\u5C55\u70B9`);
3492
+ logger9.info(`\u5DF2\u4ECE\u63D2\u4EF6 ${plugin.id} \u6536\u96C6\u6269\u5C55\u70B9`);
3273
3493
  }
3274
3494
  this.plugins.set(plugin.id, plugin);
3275
- logger8.info(`\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\u4E3A ${plugin.metadata.type}\u3002`);
3495
+ logger9.info(`\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\u4E3A ${plugin.metadata.type}\u3002`);
3276
3496
  if (notify) {
3277
3497
  this.notify();
3278
3498
  }
@@ -3286,7 +3506,7 @@ var PluginManager = class {
3286
3506
  const runtime = this.runtimes.get(pluginId);
3287
3507
  if (!runtime) {
3288
3508
  const msg = `\u5C1D\u8BD5\u6302\u8F7D\u4E0D\u5B58\u5728\u6216\u672A\u521D\u59CB\u5316\u7684\u63D2\u4EF6: ${pluginId}`;
3289
- logger8.warn(msg);
3509
+ logger9.warn(msg);
3290
3510
  throw new Error(msg);
3291
3511
  }
3292
3512
  if (runtime.status === "mounted") return;
@@ -3294,7 +3514,7 @@ var PluginManager = class {
3294
3514
  if (plugin?.metadata.dependencies) {
3295
3515
  for (const depId of plugin.metadata.dependencies) {
3296
3516
  if (!this.runtimes.has(depId)) {
3297
- logger8.error(`\u63D2\u4EF6 ${pluginId} \u4F9D\u8D56\u7F3A\u5931: ${depId}`);
3517
+ logger9.error(`\u63D2\u4EF6 ${pluginId} \u4F9D\u8D56\u7F3A\u5931: ${depId}`);
3298
3518
  throw new Error(`Dependency ${depId} missing for ${pluginId}`);
3299
3519
  }
3300
3520
  await this.mountPlugin(depId);
@@ -3304,7 +3524,7 @@ var PluginManager = class {
3304
3524
  try {
3305
3525
  await runtime.load();
3306
3526
  } catch (e) {
3307
- logger8.error(`\u63D2\u4EF6 ${pluginId} load \u5931\u8D25:`, e);
3527
+ logger9.error(`\u63D2\u4EF6 ${pluginId} load \u5931\u8D25:`, e);
3308
3528
  throw e;
3309
3529
  }
3310
3530
  }
@@ -3313,7 +3533,7 @@ var PluginManager = class {
3313
3533
  await runtime.mount();
3314
3534
  this.notify();
3315
3535
  } catch (e) {
3316
- logger8.error(`\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25:`, e);
3536
+ logger9.error(`\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25:`, e);
3317
3537
  throw e;
3318
3538
  }
3319
3539
  }
@@ -3325,7 +3545,7 @@ var PluginManager = class {
3325
3545
  */
3326
3546
  async initPlugins(sharedContext = {}, autoMount = false) {
3327
3547
  if (this.isInitializing) {
3328
- logger8.warn("PluginManager is already initializing, skipping...");
3548
+ logger9.warn("PluginManager is already initializing, skipping...");
3329
3549
  return;
3330
3550
  }
3331
3551
  this.isInitializing = true;
@@ -3337,7 +3557,11 @@ var PluginManager = class {
3337
3557
  this.plugins.forEach((plugin) => {
3338
3558
  if (!this.isPluginEnabled(plugin.id)) return;
3339
3559
  if (!this.runtimes.has(plugin.id)) {
3340
- const runtime = new PluginRuntime(plugin, this.sharedContext, this.storageManager);
3560
+ const runtime = new PluginRuntime(
3561
+ plugin,
3562
+ this.sharedContext,
3563
+ this.storageManager
3564
+ );
3341
3565
  this.runtimes.set(plugin.id, runtime);
3342
3566
  }
3343
3567
  });
@@ -3347,7 +3571,9 @@ var PluginManager = class {
3347
3571
  for (const id of sortedPluginIds) {
3348
3572
  const plugin = this.plugins.get(id);
3349
3573
  if (plugin?.metadata.dependencies) {
3350
- const missing = plugin.metadata.dependencies.filter((depId) => !this.runtimes.has(depId));
3574
+ const missing = plugin.metadata.dependencies.filter(
3575
+ (depId) => !this.runtimes.has(depId)
3576
+ );
3351
3577
  if (missing.length > 0) {
3352
3578
  missingDeps.set(id, missing);
3353
3579
  idsToLoad.delete(id);
@@ -3357,7 +3583,7 @@ var PluginManager = class {
3357
3583
  }
3358
3584
  if (missingDeps.size > 0) {
3359
3585
  missingDeps.forEach((deps, id) => {
3360
- logger8.error(`\u63D2\u4EF6 ${id} \u65E0\u6CD5\u52A0\u8F7D\uFF0C\u7F3A\u5931\u4F9D\u8D56: ${deps.join(", ")}`);
3586
+ logger9.error(`\u63D2\u4EF6 ${id} \u65E0\u6CD5\u52A0\u8F7D\uFF0C\u7F3A\u5931\u4F9D\u8D56: ${deps.join(", ")}`);
3361
3587
  });
3362
3588
  }
3363
3589
  for (const id of sortedPluginIds) {
@@ -3389,9 +3615,11 @@ var PluginManager = class {
3389
3615
  let lastError;
3390
3616
  for (let attempt = 0; attempt <= defaultRetryConfig.maxRetries; attempt++) {
3391
3617
  try {
3392
- logger8.info(`[PluginManager] invoking onLoad for ${pluginId} (attempt ${attempt + 1})`);
3618
+ logger9.info(
3619
+ `[PluginManager] invoking onLoad for ${pluginId} (attempt ${attempt + 1})`
3620
+ );
3393
3621
  await runtime.load();
3394
- logger8.info(`[PluginManager] onLoad completed for ${pluginId}`);
3622
+ logger9.info(`[PluginManager] onLoad completed for ${pluginId}`);
3395
3623
  this.eventBus.emit("plugin:loaded", { pluginId, attempt });
3396
3624
  return;
3397
3625
  } catch (e) {
@@ -3400,7 +3628,7 @@ var PluginManager = class {
3400
3628
  handleError(e, {
3401
3629
  code: "2002" /* PLUGIN_LOAD_FAILED */,
3402
3630
  strategy: "silent" /* SILENT */,
3403
- logger: logger8,
3631
+ logger: logger9,
3404
3632
  context: {
3405
3633
  pluginId,
3406
3634
  attempt: attempt + 1,
@@ -3408,7 +3636,10 @@ var PluginManager = class {
3408
3636
  phase: "load"
3409
3637
  }
3410
3638
  });
3411
- logger8.warn(`\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u5931\u8D25 (attempt ${attempt + 1}, type: ${errorType}):`, e);
3639
+ logger9.warn(
3640
+ `\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u5931\u8D25 (attempt ${attempt + 1}, type: ${errorType}):`,
3641
+ e
3642
+ );
3412
3643
  this.eventBus.emit("plugin:error", {
3413
3644
  pluginId,
3414
3645
  error: e,
@@ -3420,11 +3651,11 @@ var PluginManager = class {
3420
3651
  break;
3421
3652
  }
3422
3653
  const delay = calculateRetryDelay(defaultRetryConfig, attempt);
3423
- logger8.info(`\u63D2\u4EF6 ${pluginId} \u5C06\u5728 ${delay}ms \u540E\u91CD\u8BD5...`);
3654
+ logger9.info(`\u63D2\u4EF6 ${pluginId} \u5C06\u5728 ${delay}ms \u540E\u91CD\u8BD5...`);
3424
3655
  await new Promise((resolve) => setTimeout(resolve, delay));
3425
3656
  }
3426
3657
  }
3427
- logger8.error(`\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u5931\u8D25\uFF0C\u5DF2\u8FBE\u6700\u5927\u91CD\u8BD5\u6B21\u6570:`, lastError);
3658
+ logger9.error(`\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u5931\u8D25\uFF0C\u5DF2\u8FBE\u6700\u5927\u91CD\u8BD5\u6B21\u6570:`, lastError);
3428
3659
  this.eventBus.emit("plugin:load-failed", { pluginId, error: lastError });
3429
3660
  }
3430
3661
  /**
@@ -3435,7 +3666,7 @@ var PluginManager = class {
3435
3666
  for (let attempt = 0; attempt <= defaultRetryConfig.maxRetries; attempt++) {
3436
3667
  try {
3437
3668
  await runtime.mount();
3438
- logger8.info(`[PluginManager] onMount completed for ${pluginId}`);
3669
+ logger9.info(`[PluginManager] onMount completed for ${pluginId}`);
3439
3670
  this.eventBus.emit("plugin:mounted", { pluginId, attempt });
3440
3671
  return;
3441
3672
  } catch (e) {
@@ -3444,7 +3675,7 @@ var PluginManager = class {
3444
3675
  handleError(e, {
3445
3676
  code: "2003" /* PLUGIN_MOUNT_FAILED */,
3446
3677
  strategy: "silent" /* SILENT */,
3447
- logger: logger8,
3678
+ logger: logger9,
3448
3679
  context: {
3449
3680
  pluginId,
3450
3681
  attempt: attempt + 1,
@@ -3452,7 +3683,10 @@ var PluginManager = class {
3452
3683
  phase: "mount"
3453
3684
  }
3454
3685
  });
3455
- logger8.warn(`\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25 (attempt ${attempt + 1}, type: ${errorType}):`, e);
3686
+ logger9.warn(
3687
+ `\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25 (attempt ${attempt + 1}, type: ${errorType}):`,
3688
+ e
3689
+ );
3456
3690
  this.eventBus.emit("plugin:error", {
3457
3691
  pluginId,
3458
3692
  error: e,
@@ -3464,11 +3698,11 @@ var PluginManager = class {
3464
3698
  break;
3465
3699
  }
3466
3700
  const delay = calculateRetryDelay(defaultRetryConfig, attempt);
3467
- logger8.info(`\u63D2\u4EF6 ${pluginId} \u5C06\u5728 ${delay}ms \u540E\u91CD\u8BD5...`);
3701
+ logger9.info(`\u63D2\u4EF6 ${pluginId} \u5C06\u5728 ${delay}ms \u540E\u91CD\u8BD5...`);
3468
3702
  await new Promise((resolve) => setTimeout(resolve, delay));
3469
3703
  }
3470
3704
  }
3471
- logger8.error(`\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25\uFF0C\u5DF2\u8FBE\u6700\u5927\u91CD\u8BD5\u6B21\u6570:`, lastError);
3705
+ logger9.error(`\u63D2\u4EF6 ${pluginId} \u6302\u8F7D\u5931\u8D25\uFF0C\u5DF2\u8FBE\u6700\u5927\u91CD\u8BD5\u6B21\u6570:`, lastError);
3472
3706
  this.eventBus.emit("plugin:mount-failed", { pluginId, error: lastError });
3473
3707
  }
3474
3708
  /**
@@ -3482,7 +3716,7 @@ var PluginManager = class {
3482
3716
  const visit = (id) => {
3483
3717
  if (visited.has(id)) return;
3484
3718
  if (visiting.has(id)) {
3485
- logger8.error(`\u5FAA\u73AF\u4F9D\u8D56\u68C0\u6D4B\u5230: ${id}`);
3719
+ logger9.error(`\u5FAA\u73AF\u4F9D\u8D56\u68C0\u6D4B\u5230: ${id}`);
3486
3720
  return;
3487
3721
  }
3488
3722
  visiting.add(id);
@@ -3499,9 +3733,9 @@ var PluginManager = class {
3499
3733
  sorted.push(id);
3500
3734
  };
3501
3735
  const priorityMap = {
3502
- "system": 100,
3503
- "functional": 50,
3504
- "business": 10
3736
+ system: 100,
3737
+ functional: 50,
3738
+ business: 10
3505
3739
  };
3506
3740
  const sortedIdsByType = [...ids].sort((a, b) => {
3507
3741
  const pA = priorityMap[this.plugins.get(a)?.metadata.type || ""] || 0;
@@ -3518,34 +3752,43 @@ var PluginManager = class {
3518
3752
  * @param notify 是否在加载完成后触发通知,默认为 true
3519
3753
  */
3520
3754
  async loadPlugins(configs, registry, notify = true) {
3521
- logger8.info("\u5F00\u59CB\u52A0\u8F7D\u63D2\u4EF6...");
3522
- const localLoadPromises = Object.entries(registry).map(async ([registryId, importFn]) => {
3523
- try {
3524
- const module2 = await importFn();
3525
- const config = configs[registryId];
3526
- const plugin = this.instantiatePlugin(registryId, module2, config);
3527
- if (plugin && config) {
3528
- configManager.set(plugin.id, config);
3755
+ logger9.info("\u5F00\u59CB\u52A0\u8F7D\u63D2\u4EF6...");
3756
+ const localLoadPromises = Object.entries(registry).map(
3757
+ async ([registryId, importFn]) => {
3758
+ try {
3759
+ const module2 = await importFn();
3760
+ const config = configs[registryId];
3761
+ const plugin = this.instantiatePlugin(registryId, module2, config);
3762
+ if (plugin && config) {
3763
+ configManager.set(plugin.id, config);
3764
+ }
3765
+ return plugin;
3766
+ } catch (e) {
3767
+ logger9.error(`\u52A0\u8F7D\u672C\u5730\u63D2\u4EF6\u6A21\u5757 ${registryId} \u5931\u8D25:`, e);
3768
+ return null;
3529
3769
  }
3530
- return plugin;
3531
- } catch (e) {
3532
- logger8.error(`\u52A0\u8F7D\u672C\u5730\u63D2\u4EF6\u6A21\u5757 ${registryId} \u5931\u8D25:`, e);
3533
- return null;
3534
3770
  }
3535
- });
3771
+ );
3536
3772
  const onlineLoadPromises = Object.entries(configs).filter(([id, config]) => config.url && !registry[id]).map(async ([pluginId, config]) => {
3537
3773
  try {
3538
- const plugin = await this.loadRemotePlugin(pluginId, config.url, config);
3774
+ const plugin = await this.loadRemotePlugin(
3775
+ pluginId,
3776
+ config.url,
3777
+ config
3778
+ );
3539
3779
  if (plugin && config) {
3540
3780
  configManager.set(plugin.id, config);
3541
3781
  }
3542
3782
  return plugin;
3543
3783
  } catch (e) {
3544
- logger8.error(`\u52A0\u8F7D\u5728\u7EBF\u63D2\u4EF6 ${pluginId} \u5931\u8D25:`, e);
3784
+ logger9.error(`\u52A0\u8F7D\u5728\u7EBF\u63D2\u4EF6 ${pluginId} \u5931\u8D25:`, e);
3545
3785
  return null;
3546
3786
  }
3547
3787
  });
3548
- const loadedPlugins = await Promise.all([...localLoadPromises, ...onlineLoadPromises]);
3788
+ const loadedPlugins = await Promise.all([
3789
+ ...localLoadPromises,
3790
+ ...onlineLoadPromises
3791
+ ]);
3549
3792
  loadedPlugins.forEach((plugin) => {
3550
3793
  if (plugin) {
3551
3794
  this.register(plugin, false);
@@ -3554,7 +3797,7 @@ var PluginManager = class {
3554
3797
  if (notify) {
3555
3798
  this.notify();
3556
3799
  }
3557
- logger8.info(`\u63D2\u4EF6\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171\u52A0\u8F7D ${this.plugins.size} \u4E2A\u63D2\u4EF6`);
3800
+ logger9.info(`\u63D2\u4EF6\u52A0\u8F7D\u5B8C\u6210\uFF0C\u5171\u52A0\u8F7D ${this.plugins.size} \u4E2A\u63D2\u4EF6`);
3558
3801
  }
3559
3802
  /**
3560
3803
  * 加载远程插件
@@ -3563,16 +3806,21 @@ var PluginManager = class {
3563
3806
  * @param config 插件配置
3564
3807
  */
3565
3808
  async loadRemotePlugin(pluginId, url, config) {
3566
- logger8.info(`\u6B63\u5728\u4ECE ${url} \u52A0\u8F7D\u8FDC\u7A0B\u63D2\u4EF6 ${pluginId}...`);
3809
+ logger9.info(`\u6B63\u5728\u4ECE ${url} \u52A0\u8F7D\u8FDC\u7A0B\u63D2\u4EF6 ${pluginId}...`);
3567
3810
  if (config?.format === "iife") {
3568
3811
  return this.loadIIFEPlugin(pluginId, url, config);
3569
3812
  }
3570
3813
  try {
3571
- const dynamicImport = new Function("specifier", "return import(specifier)");
3814
+ const dynamicImport = new Function(
3815
+ "specifier",
3816
+ "return import(specifier)"
3817
+ );
3572
3818
  const module2 = await dynamicImport(url);
3573
3819
  return this.instantiatePlugin(pluginId, module2, config);
3574
3820
  } catch (e) {
3575
- logger8.warn(`ESM \u52A0\u8F7D\u5931\u8D25 (${e instanceof Error ? e.message : String(e)})\uFF0C\u5C1D\u8BD5 IIFE \u52A0\u8F7D: ${pluginId}`);
3821
+ logger9.warn(
3822
+ `ESM \u52A0\u8F7D\u5931\u8D25 (${e instanceof Error ? e.message : String(e)})\uFF0C\u5C1D\u8BD5 IIFE \u52A0\u8F7D: ${pluginId}`
3823
+ );
3576
3824
  return this.loadIIFEPlugin(pluginId, url, config);
3577
3825
  }
3578
3826
  }
@@ -3589,7 +3837,9 @@ var PluginManager = class {
3589
3837
  if (pluginModule) {
3590
3838
  resolve(this.instantiatePlugin(pluginId, pluginModule, config));
3591
3839
  } else {
3592
- reject(new Error(`\u8FDC\u7A0B\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u540E\u672A\u627E\u5230\u5168\u5C40\u53D8\u91CF ${globalName}`));
3840
+ reject(
3841
+ new Error(`\u8FDC\u7A0B\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u540E\u672A\u627E\u5230\u5168\u5C40\u53D8\u91CF ${globalName}`)
3842
+ );
3593
3843
  }
3594
3844
  };
3595
3845
  script.onerror = () => reject(new Error(`\u8FDC\u7A0B\u63D2\u4EF6 ${pluginId} \u52A0\u8F7D\u5931\u8D25: ${url}`));
@@ -3613,7 +3863,9 @@ var PluginManager = class {
3613
3863
  if (PluginClass) {
3614
3864
  const isClass = typeof PluginClass === "function" && PluginClass.prototype;
3615
3865
  if (isClass) {
3616
- logger8.warn(`\u63D2\u4EF6 ${pluginId} \u4F7F\u7528\u4E86\u7C7B\u5B9A\u4E49\u6A21\u5F0F\u3002\u5EFA\u8BAE\u7EDF\u4E00\u4F7F\u7528 definePlugin() \u5DE5\u5382\u6A21\u5F0F\u4EE5\u6D88\u9664\u6B67\u4E49\u5E76\u7B80\u5316\u4EE3\u7801\u3002`);
3866
+ logger9.warn(
3867
+ `\u63D2\u4EF6 ${pluginId} \u4F7F\u7528\u4E86\u7C7B\u5B9A\u4E49\u6A21\u5F0F\u3002\u5EFA\u8BAE\u7EDF\u4E00\u4F7F\u7528 definePlugin() \u5DE5\u5382\u6A21\u5F0F\u4EE5\u6D88\u9664\u6B67\u4E49\u5E76\u7B80\u5316\u4EE3\u7801\u3002`
3868
+ );
3617
3869
  }
3618
3870
  const pluginInstance = typeof PluginClass === "function" ? new PluginClass() : PluginClass;
3619
3871
  const isFilePath = pluginId.includes("/") && (pluginId.includes(".ts") || pluginId.includes(".tsx"));
@@ -3631,11 +3883,14 @@ var PluginManager = class {
3631
3883
  }
3632
3884
  }
3633
3885
  if (config) {
3634
- pluginInstance.defaultConfig = { ...pluginInstance.defaultConfig, ...config };
3886
+ pluginInstance.defaultConfig = {
3887
+ ...pluginInstance.defaultConfig,
3888
+ ...config
3889
+ };
3635
3890
  }
3636
3891
  return pluginInstance;
3637
3892
  }
3638
- logger8.warn(`\u6A21\u5757 ${pluginId} \u672A\u5BFC\u51FA\u6709\u6548\u7684\u63D2\u4EF6\u5165\u53E3`);
3893
+ logger9.warn(`\u6A21\u5757 ${pluginId} \u672A\u5BFC\u51FA\u6709\u6548\u7684\u63D2\u4EF6\u5165\u53E3`);
3639
3894
  return null;
3640
3895
  }
3641
3896
  // --- Private Handlers ---
@@ -3650,35 +3905,35 @@ var PluginManager = class {
3650
3905
  if (plugin.defaultConfig) {
3651
3906
  this.registerDefaultConfig(plugin.id, plugin.defaultConfig);
3652
3907
  }
3653
- logger8.debug(`[Business] \u4E1A\u52A1\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u9ED8\u8BA4\u7981\u7528\uFF09`);
3908
+ logger9.debug(`[Business] \u4E1A\u52A1\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u9ED8\u8BA4\u7981\u7528\uFF09`);
3654
3909
  }
3655
3910
  handleFunctionalPlugin(plugin) {
3656
3911
  const config = PLUGIN_TYPE_CONFIGS.functional;
3657
3912
  this.pluginLazyInit.set(plugin.id, true);
3658
3913
  this.pluginDefaultEnabled.set(plugin.id, config.defaultEnabled);
3659
- logger8.debug(`[Functional] \u529F\u80FD\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u61D2\u52A0\u8F7D\uFF09`);
3914
+ logger9.debug(`[Functional] \u529F\u80FD\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u61D2\u52A0\u8F7D\uFF09`);
3660
3915
  }
3661
3916
  handleViewPlugin(plugin) {
3662
3917
  const config = PLUGIN_TYPE_CONFIGS.view;
3663
3918
  this.pluginLazyInit.set(plugin.id, true);
3664
3919
  this.pluginDefaultEnabled.set(plugin.id, config.defaultEnabled);
3665
- logger8.debug(`[View] \u89C6\u56FE\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u61D2\u52A0\u8F7D\uFF09`);
3920
+ logger9.debug(`[View] \u89C6\u56FE\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u61D2\u52A0\u8F7D\uFF09`);
3666
3921
  }
3667
3922
  handleThemePlugin(plugin) {
3668
3923
  const config = PLUGIN_TYPE_CONFIGS.theme;
3669
3924
  this.pluginDefaultEnabled.set(plugin.id, config.defaultEnabled);
3670
- logger8.debug(`[Theme] \u4E3B\u9898\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C`);
3925
+ logger9.debug(`[Theme] \u4E3B\u9898\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C`);
3671
3926
  }
3672
3927
  handleRendererPlugin(plugin) {
3673
3928
  const config = PLUGIN_TYPE_CONFIGS.renderer;
3674
3929
  this.pluginDefaultEnabled.set(plugin.id, config.defaultEnabled);
3675
- logger8.debug(`[Renderer] \u6E32\u67D3\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C`);
3930
+ logger9.debug(`[Renderer] \u6E32\u67D3\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C`);
3676
3931
  }
3677
3932
  handleSystemPlugin(plugin) {
3678
3933
  const config = PLUGIN_TYPE_CONFIGS.system;
3679
3934
  this.pluginForces.set(plugin.id, true);
3680
3935
  this.pluginDefaultEnabled.set(plugin.id, true);
3681
- logger8.debug(`[System] \u7CFB\u7EDF\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u5F3A\u5236\u542F\u7528\uFF09`);
3936
+ logger9.debug(`[System] \u7CFB\u7EDF\u63D2\u4EF6 ${plugin.id} \u5DF2\u6CE8\u518C\uFF08\u5F3A\u5236\u542F\u7528\uFF09`);
3682
3937
  }
3683
3938
  /**
3684
3939
  * 注册插件默认配置
@@ -3693,8 +3948,8 @@ var PluginManager = class {
3693
3948
  var pluginManager = new PluginManager(new LocalStorageAdapter());
3694
3949
 
3695
3950
  // src/feature-flag/FeatureRegistry.ts
3696
- var import_zustand2 = require("zustand");
3697
3951
  var import_middleware = require("zustand/middleware");
3952
+ var import_vanilla3 = require("zustand/vanilla");
3698
3953
  var FEATURE_NAMESPACE_PREFIX = "chatbi:feature:";
3699
3954
  var STORAGE_KEY2 = "chatbi:feature:store";
3700
3955
  function simpleHash(str) {
@@ -3733,7 +3988,7 @@ function evaluateRules(rules, context) {
3733
3988
  }
3734
3989
  return false;
3735
3990
  }
3736
- var useFeatureFlags = (0, import_zustand2.create)()(
3991
+ var featureFlagsStore = (0, import_vanilla3.createStore)()(
3737
3992
  (0, import_middleware.persist)(
3738
3993
  (set, get) => ({
3739
3994
  features: {},
@@ -3894,23 +4149,6 @@ function createUserRule(userId) {
3894
4149
  };
3895
4150
  }
3896
4151
 
3897
- // src/feature-flag/useFeature.ts
3898
- var import_shallow = require("zustand/react/shallow");
3899
- function useFeature(flagName, context) {
3900
- const { isEnabled, getFeature } = useFeatureFlags(
3901
- (0, import_shallow.useShallow)((state) => ({
3902
- isEnabled: state.isEnabled,
3903
- getFeature: state.getFeature
3904
- }))
3905
- );
3906
- const enabled = isEnabled(flagName, context);
3907
- const config = getFeature(flagName);
3908
- return {
3909
- isEnabled: enabled,
3910
- config
3911
- };
3912
- }
3913
-
3914
4152
  // src/manifest/ManifestValidator.ts
3915
4153
  function formatZodErrors(error) {
3916
4154
  return error.errors.map((err) => ({
@@ -3961,12 +4199,14 @@ function extractManifestFromPlugin(plugin) {
3961
4199
  }
3962
4200
  const extensions = metadata?.extensions || input.extensions;
3963
4201
  if (Array.isArray(extensions)) {
3964
- manifest.extensions = extensions.map((ext) => ({
3965
- name: ext.slot || ext.name,
3966
- type: "slot",
3967
- description: ext.meta?.description,
3968
- slot: ext.slot
3969
- }));
4202
+ manifest.extensions = extensions.map(
4203
+ (ext) => ({
4204
+ name: ext.slot || ext.name,
4205
+ type: "slot",
4206
+ description: ext.meta?.description,
4207
+ slot: ext.slot
4208
+ })
4209
+ );
3970
4210
  }
3971
4211
  const caps = metadata?.capabilities || input.capabilities;
3972
4212
  if (caps && typeof caps === "object") {
@@ -4022,7 +4262,7 @@ var AxiosAdapter = class {
4022
4262
  // 强制不缓存流式响应
4023
4263
  headers: {
4024
4264
  "Cache-Control": "no-cache",
4025
- "Pragma": "no-cache",
4265
+ Pragma: "no-cache",
4026
4266
  ...config.headers
4027
4267
  },
4028
4268
  // 自定义适配器:在拦截器链中执行 fetch
@@ -4052,7 +4292,9 @@ var AxiosAdapter = class {
4052
4292
  if (hijacked) return;
4053
4293
  }
4054
4294
  if (!(fetchResponse instanceof Response)) {
4055
- throw new Error("\u6D41\u5F0F\u8BF7\u6C42\u5931\u8D25\uFF1A\u672A\u80FD\u83B7\u53D6\u5230\u539F\u59CB\u54CD\u5E94\u6D41\uFF0C\u8BF7\u68C0\u67E5 Axios \u54CD\u5E94\u62E6\u622A\u5668\u662F\u5426\u6B63\u786E\u5904\u7406\u4E86 Response \u5BF9\u8C61\u3002");
4295
+ throw new Error(
4296
+ "\u6D41\u5F0F\u8BF7\u6C42\u5931\u8D25\uFF1A\u672A\u80FD\u83B7\u53D6\u5230\u539F\u59CB\u54CD\u5E94\u6D41\uFF0C\u8BF7\u68C0\u67E5 Axios \u54CD\u5E94\u62E6\u622A\u5668\u662F\u5426\u6B63\u786E\u5904\u7406\u4E86 Response \u5BF9\u8C61\u3002"
4297
+ );
4056
4298
  }
4057
4299
  if (!fetchResponse.ok) {
4058
4300
  throw new Error(`HTTP error! status: ${fetchResponse.status}`);
@@ -4086,7 +4328,7 @@ var AxiosAdapter = class {
4086
4328
  };
4087
4329
 
4088
4330
  // src/api/engine.ts
4089
- var logger9 = createLogger("ApiEngine");
4331
+ var logger10 = createLogger("ApiEngine");
4090
4332
  var ApiEngine = class {
4091
4333
  adapter;
4092
4334
  config = {};
@@ -4126,7 +4368,7 @@ var ApiEngine = class {
4126
4368
  * @param config 配置对象
4127
4369
  */
4128
4370
  register(config) {
4129
- logger9.info("\u6B63\u5728\u6CE8\u518C API \u914D\u7F6E:", Object.keys(config));
4371
+ logger10.info("\u6B63\u5728\u6CE8\u518C API \u914D\u7F6E:", Object.keys(config));
4130
4372
  this.config = { ...this.config, ...config };
4131
4373
  }
4132
4374
  /**
@@ -4145,10 +4387,16 @@ var ApiEngine = class {
4145
4387
  async call(module2, action, data, options = {}) {
4146
4388
  const endpoint = this.getEndpoint(module2, action);
4147
4389
  if (!endpoint) {
4148
- logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module2}.${action} (\u5F53\u524D\u5DF2\u6CE8\u518C\u6A21\u5757: ${Object.keys(this.config).join(", ")})`);
4390
+ logger10.warn(
4391
+ `\u672A\u627E\u5230 API \u5B9A\u4E49: ${module2}.${action} (\u5F53\u524D\u5DF2\u6CE8\u518C\u6A21\u5757: ${Object.keys(this.config).join(", ")})`
4392
+ );
4149
4393
  return Promise.resolve(void 0);
4150
4394
  }
4151
- const requestConfig = await this.prepareRequestConfig(endpoint, data, options);
4395
+ const requestConfig = await this.prepareRequestConfig(
4396
+ endpoint,
4397
+ data,
4398
+ options
4399
+ );
4152
4400
  let response;
4153
4401
  try {
4154
4402
  response = await this.adapter.request(requestConfig, endpoint);
@@ -4159,9 +4407,12 @@ var ApiEngine = class {
4159
4407
  throw error;
4160
4408
  }
4161
4409
  }
4162
- const hijacked = await this.applyResponseInterceptors(response, requestConfig);
4410
+ const hijacked = await this.applyResponseInterceptors(
4411
+ response,
4412
+ requestConfig
4413
+ );
4163
4414
  if (hijacked) {
4164
- logger9.info("\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module2, action);
4415
+ logger10.info("\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module2, action);
4165
4416
  return void 0;
4166
4417
  }
4167
4418
  this.checkHttpStatus(response);
@@ -4179,14 +4430,18 @@ var ApiEngine = class {
4179
4430
  async stream(module2, action, data, options = {}) {
4180
4431
  const endpoint = this.getEndpoint(module2, action);
4181
4432
  if (!endpoint) {
4182
- logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module2}.${action}\uFF0C\u8DF3\u8FC7\u6D41\u5F0F\u8BF7\u6C42\u3002`);
4433
+ logger10.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module2}.${action}\uFF0C\u8DF3\u8FC7\u6D41\u5F0F\u8BF7\u6C42\u3002`);
4183
4434
  return;
4184
4435
  }
4185
4436
  if (!this.adapter.stream) {
4186
- logger9.warn("\u5F53\u524D API \u9002\u914D\u5668\u4E0D\u652F\u6301\u6D41\u5F0F\u4F20\u8F93\u3002");
4437
+ logger10.warn("\u5F53\u524D API \u9002\u914D\u5668\u4E0D\u652F\u6301\u6D41\u5F0F\u4F20\u8F93\u3002");
4187
4438
  return;
4188
4439
  }
4189
- const requestConfig = await this.prepareRequestConfig(endpoint, data, options);
4440
+ const requestConfig = await this.prepareRequestConfig(
4441
+ endpoint,
4442
+ data,
4443
+ options
4444
+ );
4190
4445
  const callbacks = {
4191
4446
  onMessage: options.onMessage,
4192
4447
  onError: options.onError,
@@ -4198,9 +4453,12 @@ var ApiEngine = class {
4198
4453
  {
4199
4454
  ...callbacks,
4200
4455
  onResponse: async (response) => {
4201
- const hijacked = await this.applyResponseInterceptors(response, requestConfig);
4456
+ const hijacked = await this.applyResponseInterceptors(
4457
+ response,
4458
+ requestConfig
4459
+ );
4202
4460
  if (hijacked) {
4203
- logger9.info("\u6D41\u5F0F\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module2, action);
4461
+ logger10.info("\u6D41\u5F0F\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module2, action);
4204
4462
  if (requestConfig.signal instanceof AbortController) {
4205
4463
  requestConfig.signal.abort();
4206
4464
  }
@@ -4228,7 +4486,8 @@ var ApiEngine = class {
4228
4486
  const pathParams = options.params || {};
4229
4487
  url = url.replace(/:([a-zA-Z0-9_]+)/g, (_, key) => {
4230
4488
  if (pathParams[key] !== void 0) return String(pathParams[key]);
4231
- if (data && typeof data === "object" && data[key] !== void 0) return String(data[key]);
4489
+ if (data && typeof data === "object" && data[key] !== void 0)
4490
+ return String(data[key]);
4232
4491
  return `:${key}`;
4233
4492
  });
4234
4493
  const method = endpoint.method;
@@ -4300,7 +4559,7 @@ var ApiEngine = class {
4300
4559
  if (!isSuccess) {
4301
4560
  const strategy = endpoint.errorStrategy || "reject";
4302
4561
  if (strategy === "reject") {
4303
- logger9.error(`API \u8BF7\u6C42\u4E1A\u52A1\u9519\u8BEF (${module2}.${action}):`, res.message);
4562
+ logger10.error(`API \u8BF7\u6C42\u4E1A\u52A1\u9519\u8BEF (${module2}.${action}):`, res.message);
4304
4563
  throw new Error(res.message || `Request failed with code ${code}`);
4305
4564
  }
4306
4565
  }
@@ -4460,9 +4719,9 @@ function resolveApiModules(definitionsMap, mocksMap = {}) {
4460
4719
  }
4461
4720
 
4462
4721
  // src/utils/date.ts
4463
- var import_zh_cn = require("dayjs/locale/zh-cn");
4722
+ var import_zh_cn = require("dayjs/locale/zh-cn.js");
4464
4723
  var import_dayjs = __toESM(require("dayjs"), 1);
4465
- var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"), 1);
4724
+ var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime.js"), 1);
4466
4725
  import_dayjs.default.extend(import_relativeTime.default);
4467
4726
  import_dayjs.default.locale("zh-cn");
4468
4727
  var dateUtils = {
@@ -4673,7 +4932,10 @@ var RemoteLoader = class {
4673
4932
  */
4674
4933
  constructor(options = {}) {
4675
4934
  const cacheOptions = options.cache || { ttl: 5 * 60 * 1e3 };
4676
- const retryOptions = options.retry || { maxRetries: 3, retryDelay: 1e3 };
4935
+ const retryOptions = options.retry || {
4936
+ maxRetries: 3,
4937
+ retryDelay: 1e3
4938
+ };
4677
4939
  this.options = {
4678
4940
  timeout: options.timeout || 1e4,
4679
4941
  retry: retryOptions,
@@ -4734,10 +4996,18 @@ var RemoteLoader = class {
4734
4996
  async loadManifest(sourceId) {
4735
4997
  const source = this.sources.get(sourceId);
4736
4998
  if (!source) {
4737
- return this.createErrorResult("NOT_FOUND", `Source ${sourceId} not found`, false);
4999
+ return this.createErrorResult(
5000
+ "NOT_FOUND",
5001
+ `Source ${sourceId} not found`,
5002
+ false
5003
+ );
4738
5004
  }
4739
5005
  if (!source.enabled) {
4740
- return this.createErrorResult("NOT_FOUND", `Source ${sourceId} is disabled`, false);
5006
+ return this.createErrorResult(
5007
+ "NOT_FOUND",
5008
+ `Source ${sourceId} is disabled`,
5009
+ false
5010
+ );
4741
5011
  }
4742
5012
  const cacheKey = source.url;
4743
5013
  const cached = this.cache.get(cacheKey);
@@ -4753,7 +5023,11 @@ var RemoteLoader = class {
4753
5023
  const validationResult = validateManifest(data);
4754
5024
  if (!validationResult.valid) {
4755
5025
  const errors = validationResult.errors?.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
4756
- return this.createErrorResult("VALIDATION_ERROR", `Manifest validation failed: ${errors}`, false);
5026
+ return this.createErrorResult(
5027
+ "VALIDATION_ERROR",
5028
+ `Manifest validation failed: ${errors}`,
5029
+ false
5030
+ );
4757
5031
  }
4758
5032
  this.cache.set(cacheKey, validationResult.data);
4759
5033
  return {
@@ -4776,7 +5050,7 @@ var RemoteLoader = class {
4776
5050
  const response = await import_axios2.default.get(url, {
4777
5051
  timeout: this.options.timeout,
4778
5052
  headers: {
4779
- "Accept": "application/json"
5053
+ Accept: "application/json"
4780
5054
  }
4781
5055
  });
4782
5056
  return response.data;
@@ -4798,7 +5072,11 @@ var RemoteLoader = class {
4798
5072
  handleLoadError(error) {
4799
5073
  const axiosError = error;
4800
5074
  if (axiosError.code === "ECONNREFUSED" || axiosError.code === "ENOTFOUND") {
4801
- return this.createErrorResult("NETWORK", `Network error: ${axiosError.message}`, true);
5075
+ return this.createErrorResult(
5076
+ "NETWORK",
5077
+ `Network error: ${axiosError.message}`,
5078
+ true
5079
+ );
4802
5080
  }
4803
5081
  if (axiosError.code === "ETIMEDOUT" || axiosError.code === "ECONNABORTED") {
4804
5082
  return this.createErrorResult("TIMEOUT", "Request timeout", true);
@@ -4807,16 +5085,28 @@ var RemoteLoader = class {
4807
5085
  return this.createErrorResult("NOT_FOUND", "Manifest not found", false);
4808
5086
  }
4809
5087
  if (axiosError.response?.status && axiosError.response.status >= 500) {
4810
- return this.createErrorResult("NETWORK", `Server error: ${axiosError.response.status}`, true);
5088
+ return this.createErrorResult(
5089
+ "NETWORK",
5090
+ `Server error: ${axiosError.response.status}`,
5091
+ true
5092
+ );
4811
5093
  }
4812
5094
  if (axiosError.response?.data) {
4813
5095
  try {
4814
5096
  JSON.parse(JSON.stringify(axiosError.response.data));
4815
5097
  } catch (e) {
4816
- return this.createErrorResult("PARSE", `Failed to parse response: ${e instanceof Error ? e.message : String(e)}`, false);
5098
+ return this.createErrorResult(
5099
+ "PARSE",
5100
+ `Failed to parse response: ${e instanceof Error ? e.message : String(e)}`,
5101
+ false
5102
+ );
4817
5103
  }
4818
5104
  }
4819
- return this.createErrorResult("NETWORK", axiosError.message || "Unknown error", this.retryStrategy.isRetryable(axiosError));
5105
+ return this.createErrorResult(
5106
+ "NETWORK",
5107
+ axiosError.message || "Unknown error",
5108
+ this.retryStrategy.isRetryable(axiosError)
5109
+ );
4820
5110
  }
4821
5111
  /**
4822
5112
  * 创建错误结果
@@ -4957,7 +5247,10 @@ var CycleDetector = class {
4957
5247
  detect(plugins) {
4958
5248
  const graph = /* @__PURE__ */ new Map();
4959
5249
  for (const plugin of plugins) {
4960
- graph.set(plugin.id, plugin.dependencies.map((d) => d.id));
5250
+ graph.set(
5251
+ plugin.id,
5252
+ plugin.dependencies.map((d) => d.id)
5253
+ );
4961
5254
  }
4962
5255
  return this.detectFromGraph(graph);
4963
5256
  }
@@ -5142,7 +5435,7 @@ var NpmRegistry = class {
5142
5435
  baseURL: baseUrl,
5143
5436
  timeout: 1e4,
5144
5437
  headers: {
5145
- "Accept": "application/json"
5438
+ Accept: "application/json"
5146
5439
  }
5147
5440
  });
5148
5441
  this.cache = new import_lru_cache2.default({
@@ -5374,7 +5667,7 @@ var SharedDepsDetector = class {
5374
5667
  }
5375
5668
  };
5376
5669
 
5377
- // src/adapter/AdapterInterface.ts
5670
+ // src/adapters/AdapterInterface.ts
5378
5671
  var BaseAdapter = class {
5379
5672
  /**
5380
5673
  * 模板方法 - 三层变换默认实现
@@ -5396,7 +5689,7 @@ var BaseAdapter = class {
5396
5689
  }
5397
5690
  };
5398
5691
 
5399
- // src/adapter/AdapterRegistry.ts
5692
+ // src/adapters/AdapterRegistry.ts
5400
5693
  var AdapterRegistry = class {
5401
5694
  adapters = /* @__PURE__ */ new Map();
5402
5695
  states = /* @__PURE__ */ new Map();
@@ -5408,7 +5701,9 @@ var AdapterRegistry = class {
5408
5701
  */
5409
5702
  register(adapter) {
5410
5703
  if (this.adapters.has(adapter.id)) {
5411
- console.warn(`[AdapterRegistry] Adapter ${adapter.id} already registered, overwriting`);
5704
+ console.warn(
5705
+ `[AdapterRegistry] Adapter ${adapter.id} already registered, overwriting`
5706
+ );
5412
5707
  }
5413
5708
  this.adapters.set(adapter.id, adapter);
5414
5709
  this.states.set(adapter.id, {
@@ -5424,7 +5719,9 @@ var AdapterRegistry = class {
5424
5719
  */
5425
5720
  unregister(adapterId) {
5426
5721
  if (this.activeAdapterId === adapterId) {
5427
- console.warn(`[AdapterRegistry] Cannot unregister active adapter ${adapterId}`);
5722
+ console.warn(
5723
+ `[AdapterRegistry] Cannot unregister active adapter ${adapterId}`
5724
+ );
5428
5725
  return false;
5429
5726
  }
5430
5727
  const adapter = this.adapters.get(adapterId);
@@ -5605,6 +5902,7 @@ var adapterRegistry = new AdapterRegistry();
5605
5902
  StorageManager,
5606
5903
  ToolRegistry,
5607
5904
  adapterRegistry,
5905
+ aiStore,
5608
5906
  apiEngine,
5609
5907
  assertManifest,
5610
5908
  cleanUrlParams,
@@ -5628,6 +5926,7 @@ var adapterRegistry = new AdapterRegistry();
5628
5926
  evaluateRule,
5629
5927
  evaluateRules,
5630
5928
  extractManifestFromPlugin,
5929
+ featureFlagsStore,
5631
5930
  getDefaultRegistry,
5632
5931
  handleError,
5633
5932
  hashString,
@@ -5645,9 +5944,6 @@ var adapterRegistry = new AdapterRegistry();
5645
5944
  resolvePluginRegistry,
5646
5945
  serviceRegistry,
5647
5946
  simpleHash,
5648
- useAIStore,
5649
- useFeature,
5650
- useFeatureFlags,
5651
5947
  validateManifest,
5652
5948
  version
5653
5949
  });