@chatbi-v/core 3.0.0 → 3.1.4

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.
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/manifest/index.ts
21
+ var manifest_exports = {};
22
+ __export(manifest_exports, {
23
+ EXTENSION_TYPES: () => EXTENSION_TYPES,
24
+ PLUGIN_TYPES: () => PLUGIN_TYPES,
25
+ PluginManifestSchema: () => PluginManifestSchema,
26
+ RENDER_MODES: () => RENDER_MODES,
27
+ assertManifest: () => assertManifest,
28
+ extractManifestFromPlugin: () => extractManifestFromPlugin,
29
+ normalizePluginManifest: () => normalizePluginManifest,
30
+ validateManifest: () => validateManifest
31
+ });
32
+ module.exports = __toCommonJS(manifest_exports);
33
+
34
+ // src/manifest/PluginManifest.ts
35
+ var import_zod = require("zod");
36
+ var EXTENSION_TYPES = ["slot", "hook", "command", "service"];
37
+ var RENDER_MODES = ["replace", "append", "prepend"];
38
+ var ExtensionSchema = import_zod.z.object({
39
+ /** 扩展点名称/标识符 */
40
+ name: import_zod.z.string().min(1, "\u6269\u5C55\u70B9\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"),
41
+ /** 扩展点类型 */
42
+ type: import_zod.z.enum(EXTENSION_TYPES),
43
+ /** 扩展点描述 */
44
+ description: import_zod.z.string().optional(),
45
+ /** 对于 slot 类型,指定插槽位置 */
46
+ slot: import_zod.z.string().optional(),
47
+ /** 扩展点的配置选项 */
48
+ config: import_zod.z.record(import_zod.z.any()).optional(),
49
+ /**
50
+ * 渲染模式
51
+ * @description 定义插槽内容的渲染方式:replace(替换)、append(追加)、prepend(前置)
52
+ */
53
+ renderMode: import_zod.z.enum(RENDER_MODES).optional(),
54
+ /**
55
+ * 条件渲染配置
56
+ * @description 用于条件渲染,如 requiresAuth: true 表示需要认证
57
+ */
58
+ condition: import_zod.z.record(import_zod.z.any()).optional()
59
+ });
60
+ var DependencySchema = import_zod.z.object({
61
+ /** 依赖插件 ID */
62
+ id: import_zod.z.string().min(1, "\u4F9D\u8D56\u63D2\u4EF6 ID \u4E0D\u80FD\u4E3A\u7A7A"),
63
+ /** 依赖版本范围 (SemVer) */
64
+ version: import_zod.z.string().min(1, "\u4F9D\u8D56\u7248\u672C\u4E0D\u80FD\u4E3A\u7A7A"),
65
+ /** 是否为可选依赖 */
66
+ optional: import_zod.z.boolean().optional().default(false)
67
+ });
68
+ var PLUGIN_TYPES = [
69
+ "business",
70
+ "functional",
71
+ "view",
72
+ "theme",
73
+ "renderer",
74
+ "system"
75
+ ];
76
+ var EntrySchema = import_zod.z.union([
77
+ import_zod.z.string().min(1, "\u5165\u53E3\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A"),
78
+ import_zod.z.object({
79
+ /** 入口文件 URL */
80
+ url: import_zod.z.string().min(1, "\u5165\u53E3 URL \u4E0D\u80FD\u4E3A\u7A7A"),
81
+ /** 共享作用域 (用于模块联邦) */
82
+ shareScope: import_zod.z.string().optional()
83
+ })
84
+ ]);
85
+ var CompatibilitySchema = import_zod.z.object({
86
+ /** 最低宿主版本 */
87
+ minVersion: import_zod.z.string().optional(),
88
+ /** 最高宿主版本 */
89
+ maxVersion: import_zod.z.string().optional(),
90
+ /** 兼容的宿主版本列表 */
91
+ supportedVersions: import_zod.z.array(import_zod.z.string()).optional()
92
+ });
93
+ var CapabilitiesSchema = import_zod.z.record(import_zod.z.boolean());
94
+ var ConfigurationSchema = import_zod.z.array(
95
+ import_zod.z.object({
96
+ key: import_zod.z.string().min(1),
97
+ type: import_zod.z.enum(["string", "number", "boolean", "select"]),
98
+ label: import_zod.z.string().min(1),
99
+ description: import_zod.z.string().optional(),
100
+ default: import_zod.z.any().optional(),
101
+ options: import_zod.z.array(import_zod.z.object({ label: import_zod.z.string(), value: import_zod.z.any() })).optional()
102
+ })
103
+ );
104
+ var PERMISSION_ACTIONS = [
105
+ "read",
106
+ "write",
107
+ "execute",
108
+ "admin"
109
+ ];
110
+ var PERMISSION_SCOPES = ["plugin", "global", "user"];
111
+ var PluginManifestSchema = import_zod.z.object({
112
+ /** 插件唯一 ID (推荐反向域名格式) */
113
+ id: import_zod.z.string().min(1, "\u63D2\u4EF6 ID \u4E0D\u80FD\u4E3A\u7A7A"),
114
+ /** 插件版本号 (SemVer) */
115
+ version: import_zod.z.string().min(1, "\u7248\u672C\u53F7\u4E0D\u80FD\u4E3A\u7A7A").refine((v) => /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$/.test(v), {
116
+ message: "\u7248\u672C\u53F7\u5FC5\u987B\u7B26\u5408 SemVer \u683C\u5F0F"
117
+ }),
118
+ /** 插件显示名称 */
119
+ name: import_zod.z.string().min(1, "\u63D2\u4EF6\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"),
120
+ /** 插件入口 */
121
+ entry: EntrySchema,
122
+ /** 插件类型 */
123
+ type: import_zod.z.enum(PLUGIN_TYPES).optional().default("business"),
124
+ /** 插件功能描述 */
125
+ description: import_zod.z.string().optional(),
126
+ /** 插件作者 */
127
+ author: import_zod.z.string().optional(),
128
+ /** 插件图标 */
129
+ icon: import_zod.z.string().optional(),
130
+ /** 兼容性要求 */
131
+ compatibility: CompatibilitySchema.optional(),
132
+ /** 插件依赖 */
133
+ dependencies: import_zod.z.array(DependencySchema).optional().default([]),
134
+ /** 扩展点声明 */
135
+ extensions: import_zod.z.array(ExtensionSchema).optional().default([]),
136
+ /** 能力声明 */
137
+ capabilities: CapabilitiesSchema.optional(),
138
+ /** 配置项定义 */
139
+ configuration: ConfigurationSchema.optional(),
140
+ /** 存储定义 */
141
+ storage: import_zod.z.array(import_zod.z.any()).optional(),
142
+ /** 路由定义 (仅供展示,实际路由在运行时注册) */
143
+ routes: import_zod.z.array(import_zod.z.object({ path: import_zod.z.string() })).optional(),
144
+ /** 权限声明 */
145
+ permissions: import_zod.z.array(
146
+ import_zod.z.object({
147
+ action: import_zod.z.enum(PERMISSION_ACTIONS),
148
+ scope: import_zod.z.enum(PERMISSION_SCOPES),
149
+ resource: import_zod.z.string()
150
+ })
151
+ ).optional(),
152
+ /** 插件优先级 */
153
+ priority: import_zod.z.number().optional().default(100)
154
+ });
155
+
156
+ // src/manifest/ManifestValidator.ts
157
+ function formatZodErrors(error) {
158
+ return error.errors.map((err) => ({
159
+ message: err.message,
160
+ path: err.path.map(String),
161
+ type: err.code
162
+ }));
163
+ }
164
+ function validateManifest(raw) {
165
+ const result = PluginManifestSchema.safeParse(raw);
166
+ if (result.success) {
167
+ return {
168
+ valid: true,
169
+ data: result.data
170
+ };
171
+ }
172
+ return {
173
+ valid: false,
174
+ errors: formatZodErrors(result.error)
175
+ };
176
+ }
177
+ function assertManifest(raw) {
178
+ return PluginManifestSchema.parse(raw);
179
+ }
180
+
181
+ // src/manifest/ManifestWrapper.ts
182
+ function extractManifestFromPlugin(plugin) {
183
+ const input = plugin;
184
+ const metadata = input.metadata;
185
+ const manifest = {
186
+ id: input.id || metadata?.id,
187
+ version: metadata?.version || "1.0.0",
188
+ name: metadata?.name || input.name,
189
+ type: metadata?.type || input.type,
190
+ description: metadata?.description || input.description,
191
+ author: metadata?.author || input.author,
192
+ icon: metadata?.icon || input.icon,
193
+ entry: input.entry || "index.js"
194
+ };
195
+ const deps = metadata?.dependencies || input.dependencies;
196
+ if (Array.isArray(deps)) {
197
+ manifest.dependencies = deps.map((dep) => {
198
+ if (typeof dep === "string") {
199
+ return { id: dep, version: "*", optional: false };
200
+ }
201
+ return dep;
202
+ });
203
+ }
204
+ const extensions = metadata?.extensions || input.extensions;
205
+ if (Array.isArray(extensions)) {
206
+ manifest.extensions = extensions.map(
207
+ (ext) => ({
208
+ name: ext.slot || ext.name,
209
+ type: "slot",
210
+ description: ext.meta?.description,
211
+ slot: ext.slot
212
+ })
213
+ );
214
+ }
215
+ const caps = metadata?.capabilities || input.capabilities;
216
+ if (caps && typeof caps === "object") {
217
+ manifest.capabilities = caps;
218
+ }
219
+ const config = metadata?.configuration || input.configuration;
220
+ if (Array.isArray(config)) {
221
+ manifest.configuration = config;
222
+ }
223
+ return manifest;
224
+ }
225
+ function normalizePluginManifest(input) {
226
+ let manifest;
227
+ if (!input || typeof input !== "object") {
228
+ return {
229
+ valid: false,
230
+ errors: [{ message: "\u8F93\u5165\u5FC5\u987B\u662F\u5BF9\u8C61", path: [], type: "invalid_type" }]
231
+ };
232
+ }
233
+ const record = input;
234
+ if (record.id && record.version && record.name && record.entry) {
235
+ manifest = record;
236
+ } else if (record.metadata) {
237
+ manifest = extractManifestFromPlugin(record);
238
+ } else {
239
+ manifest = extractManifestFromPlugin(record);
240
+ }
241
+ return validateManifest(manifest);
242
+ }
243
+ // Annotate the CommonJS export names for ESM import in node:
244
+ 0 && (module.exports = {
245
+ EXTENSION_TYPES,
246
+ PLUGIN_TYPES,
247
+ PluginManifestSchema,
248
+ RENDER_MODES,
249
+ assertManifest,
250
+ extractManifestFromPlugin,
251
+ normalizePluginManifest,
252
+ validateManifest
253
+ });
@@ -0,0 +1,56 @@
1
+ import { c as PluginManifest, P as Plugin } from '../plugin-port-CHRPxDOi.cjs';
2
+ export { Q as Command, U as CommandHandler, V as CommandType, W as Compatibility, D as Dependency, a4 as EXTENSION_TYPES, X as Entry, Y as Extension, Z as ExtensionType, _ as HookType, $ as OnActivateHandler, a0 as OnDeactivateHandler, a1 as OnErrorHandler, B as PLUGIN_TYPES, a3 as PluginManifestSchema, C as PluginType, a5 as RENDER_MODES, a2 as RenderMode } from '../plugin-port-CHRPxDOi.cjs';
3
+ import 'zod';
4
+
5
+ /**
6
+ * 验证结果类型
7
+ */
8
+ interface ValidationResult {
9
+ /** 是否有效 */
10
+ valid: boolean;
11
+ /** 验证通过时的数据 */
12
+ data?: PluginManifest;
13
+ /** 验证失败时的错误 */
14
+ errors?: {
15
+ /** 错误消息 */
16
+ message: string;
17
+ /** 错误路径 */
18
+ path: string[];
19
+ /** 具体错误类型 */
20
+ type: string;
21
+ }[];
22
+ }
23
+ /**
24
+ * 验证 Manifest
25
+ * @param raw - 待验证的原始数据
26
+ * @returns 验证结果
27
+ */
28
+ declare function validateManifest(raw: unknown): ValidationResult;
29
+ /**
30
+ * 验证 Manifest 并抛出错误
31
+ * @param raw - 待验证的原始数据
32
+ * @returns 验证通过的 Manifest 数据
33
+ * @throws ZodError 当验证失败时
34
+ */
35
+ declare function assertManifest(raw: unknown): PluginManifest;
36
+
37
+ /**
38
+ * Manifest 向后兼容包装器
39
+ * @description 支持旧版 definePlugin 格式自动转换为 Manifest 格式
40
+ */
41
+
42
+ /**
43
+ * 从 Plugin 对象提取 Manifest
44
+ * @param plugin - 插件对象
45
+ * @returns 提取的 Manifest 对象
46
+ */
47
+ declare function extractManifestFromPlugin(plugin: Plugin | Record<string, unknown>): Partial<PluginManifest>;
48
+ /**
49
+ * 规范化插件 Manifest
50
+ * @param input - Plugin 对象、definePlugin 结果或纯对象
51
+ * @returns 规范化后的 Manifest
52
+ * @throws 当输入无效且无法转换时
53
+ */
54
+ declare function normalizePluginManifest(input: Plugin | Record<string, unknown> | unknown): ValidationResult;
55
+
56
+ export { PluginManifest, type ValidationResult, assertManifest, extractManifestFromPlugin, normalizePluginManifest, validateManifest };
@@ -0,0 +1,56 @@
1
+ import { c as PluginManifest, P as Plugin } from '../plugin-port-CHRPxDOi.js';
2
+ export { Q as Command, U as CommandHandler, V as CommandType, W as Compatibility, D as Dependency, a4 as EXTENSION_TYPES, X as Entry, Y as Extension, Z as ExtensionType, _ as HookType, $ as OnActivateHandler, a0 as OnDeactivateHandler, a1 as OnErrorHandler, B as PLUGIN_TYPES, a3 as PluginManifestSchema, C as PluginType, a5 as RENDER_MODES, a2 as RenderMode } from '../plugin-port-CHRPxDOi.js';
3
+ import 'zod';
4
+
5
+ /**
6
+ * 验证结果类型
7
+ */
8
+ interface ValidationResult {
9
+ /** 是否有效 */
10
+ valid: boolean;
11
+ /** 验证通过时的数据 */
12
+ data?: PluginManifest;
13
+ /** 验证失败时的错误 */
14
+ errors?: {
15
+ /** 错误消息 */
16
+ message: string;
17
+ /** 错误路径 */
18
+ path: string[];
19
+ /** 具体错误类型 */
20
+ type: string;
21
+ }[];
22
+ }
23
+ /**
24
+ * 验证 Manifest
25
+ * @param raw - 待验证的原始数据
26
+ * @returns 验证结果
27
+ */
28
+ declare function validateManifest(raw: unknown): ValidationResult;
29
+ /**
30
+ * 验证 Manifest 并抛出错误
31
+ * @param raw - 待验证的原始数据
32
+ * @returns 验证通过的 Manifest 数据
33
+ * @throws ZodError 当验证失败时
34
+ */
35
+ declare function assertManifest(raw: unknown): PluginManifest;
36
+
37
+ /**
38
+ * Manifest 向后兼容包装器
39
+ * @description 支持旧版 definePlugin 格式自动转换为 Manifest 格式
40
+ */
41
+
42
+ /**
43
+ * 从 Plugin 对象提取 Manifest
44
+ * @param plugin - 插件对象
45
+ * @returns 提取的 Manifest 对象
46
+ */
47
+ declare function extractManifestFromPlugin(plugin: Plugin | Record<string, unknown>): Partial<PluginManifest>;
48
+ /**
49
+ * 规范化插件 Manifest
50
+ * @param input - Plugin 对象、definePlugin 结果或纯对象
51
+ * @returns 规范化后的 Manifest
52
+ * @throws 当输入无效且无法转换时
53
+ */
54
+ declare function normalizePluginManifest(input: Plugin | Record<string, unknown> | unknown): ValidationResult;
55
+
56
+ export { PluginManifest, type ValidationResult, assertManifest, extractManifestFromPlugin, normalizePluginManifest, validateManifest };
@@ -0,0 +1,20 @@
1
+ import {
2
+ EXTENSION_TYPES,
3
+ PLUGIN_TYPES,
4
+ PluginManifestSchema,
5
+ RENDER_MODES,
6
+ assertManifest,
7
+ extractManifestFromPlugin,
8
+ normalizePluginManifest,
9
+ validateManifest
10
+ } from "../chunk-AAKBSVX6.mjs";
11
+ export {
12
+ EXTENSION_TYPES,
13
+ PLUGIN_TYPES,
14
+ PluginManifestSchema,
15
+ RENDER_MODES,
16
+ assertManifest,
17
+ extractManifestFromPlugin,
18
+ normalizePluginManifest,
19
+ validateManifest
20
+ };