@longzai-intelligence-electron/core 0.0.2

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,1095 @@
1
+ import "./rolldown-runtime-BqT_7tdF.js";
2
+ import { A as isSuccess, C as IPCSerializable, D as IPCResult, E as IPCError, M as unwrap, N as IPCErrorCode, O as failure$1, P as IPCErrorCodeSchema, S as IPCReturn, T as TypedAPI, _ as IPCAPIToShortAPI, a as InferIPCAPI, b as IPCParams, c as ZodIPCMethodsDefinition, d as createIPCFunctionSchema, f as createIPCMethodDefinitionSchema, g as IPCAPIToFunctions, h as ExtractMethodName, i as IPCResultSchema, j as success$1, k as isFailure, l as ZodIPCSchema, m as defineZodIPCSchema, n as IPCErrorSchema, o as InferIPCAPIFromSchema, p as createIPCResultSchema, r as IPCMethodDefinition, s as ZodIPCMethodDecl, t as IPCResult$1, u as createIPCAPISchema, v as IPCAPIWithMapping, w as StrictIPCAPI, x as IPCParamsArray, y as IPCMethodDefinition$1 } from "./types-DKXNvkb9.js";
3
+ import { BrowserWindow, BrowserWindowConstructorOptions, IpcMainInvokeEvent } from "electron";
4
+ import * as z from "zod";
5
+ import { DataSource } from "typeorm";
6
+ //#region src/ipc/typed/main.utils.d.ts
7
+ /**
8
+ * 方法定义结构接口
9
+ *
10
+ * 用于类型推断的辅助接口
11
+ */
12
+ type MethodDefinitionLike = {
13
+ /**
14
+ * 方法参数
15
+ */
16
+ params: unknown;
17
+ /**
18
+ * 方法返回值
19
+ */
20
+ return: unknown;
21
+ };
22
+ /**
23
+ * 提取方法定义的参数类型
24
+ *
25
+ * @typeParam T - 方法定义类型
26
+ */
27
+ type MethodParams<T> = T extends MethodDefinitionLike ? T['params'] : never;
28
+ /**
29
+ * 提取方法定义的返回类型
30
+ *
31
+ * @typeParam T - 方法定义类型
32
+ */
33
+ type MethodReturn<T> = T extends MethodDefinitionLike ? T['return'] : never;
34
+ /**
35
+ * 提取 IPC 方法的参数类型
36
+ *
37
+ * @typeParam T - IPC API 定义类型
38
+ * @typeParam K - 方法键名
39
+ */
40
+ type ExtractIPCParams<T extends StrictIPCAPI, K extends keyof T> = T[K] extends IPCMethodDefinition$1 ? [...MethodParams<T[K]>] : unknown[];
41
+ /**
42
+ * 提取 IPC 方法的返回类型
43
+ *
44
+ * @typeParam T - IPC API 定义类型
45
+ * @typeParam K - 方法键名
46
+ */
47
+ type ExtractIPCReturn<T extends StrictIPCAPI, K extends keyof T> = T[K] extends IPCMethodDefinition$1 ? Promise<MethodReturn<T[K]>> | MethodReturn<T[K]> : Promise<unknown>;
48
+ /**
49
+ * IPC Handler 函数类型
50
+ *
51
+ * T 为 IPC API 定义类型,K 为方法键名
52
+ *
53
+ * @typeParam T - IPC API 定义类型
54
+ * @typeParam K - 方法键名
55
+ */
56
+ type IPCHandler<T extends StrictIPCAPI, K extends keyof T> = (event: IpcMainInvokeEvent, ...args: ExtractIPCParams<T, K>) => ExtractIPCReturn<T, K>;
57
+ /**
58
+ * 创建带类型的 IPC handler 工厂函数
59
+ *
60
+ * 避免在每次调用时重复指定泛型参数,只需在创建时指定一次 API 类型
61
+ * T 为 IPC API 定义类型,必须继承 StrictIPCAPI
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const handle = createHandle<FavoriteIPCAPI>();
66
+ *
67
+ * handle('favorite:getAll', async () => {
68
+ * return favoriteRepository.getAll();
69
+ * });
70
+ *
71
+ * handle('favorite:getByTargetId', async (_, targetId, targetType) => {
72
+ * // 参数类型自动推断
73
+ * return favoriteRepository.getByTargetId(targetId, targetType);
74
+ * });
75
+ * ```;
76
+ *
77
+ * @typeParam T - IPC API 定义类型
78
+ * @returns 带类型的 handle 函数
79
+ */
80
+ declare function createHandle<T extends StrictIPCAPI>(): <K extends keyof T>(channel: K, handler: IPCHandler<T, K>) => void;
81
+ /**
82
+ * 创建带类型的 IPC handler 移除工厂函数
83
+ *
84
+ * 避免在每次调用时重复指定泛型参数,只需在创建时指定一次 API 类型
85
+ * T 为 IPC API 定义类型,必须继承 StrictIPCAPI
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const remove = createRemove<FavoriteIPCAPI>();
90
+ *
91
+ * remove('favorite:getAll');
92
+ * remove('favorite:getByTargetId');
93
+ * ```;
94
+ *
95
+ * @typeParam T - IPC API 定义类型
96
+ * @returns 带类型的 remove 函数
97
+ */
98
+ declare function createRemove<T extends StrictIPCAPI>(): <K extends keyof T>(channel: K) => void;
99
+ /**
100
+ * 批量注册 handlers
101
+ *
102
+ * T 为 IPC API 定义类型
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * interface MyIPCAPI extends StrictIPCAPI {
107
+ * 'agent:getAll': {
108
+ * params: readonly [];
109
+ * return: Agent[];
110
+ * };
111
+ * 'agent:delete': {
112
+ * params: readonly [id: string];
113
+ * return: boolean;
114
+ * };
115
+ * }
116
+ *
117
+ * registerHandlers<MyIPCAPI>({
118
+ * 'agent:getAll': async () => AgentRepository.getAll(),
119
+ * 'agent:delete': async (_, id) => AgentRepository.delete(id),
120
+ * });
121
+ * ```;
122
+ *
123
+ * @typeParam T - IPC API 定义类型
124
+ * @param handlers - Handler 映射对象
125
+ */
126
+ declare function registerHandlers<T extends StrictIPCAPI>(handlers: { [K in keyof T]?: IPCHandler<T, K>; }): void;
127
+ //#endregion
128
+ //#region src/ipc/zod/main/helpers.d.ts
129
+ /**
130
+ * 验证结果类型
131
+ *
132
+ * @typeParam T - 验证结果的数据类型
133
+ */
134
+ type ValidationResult<T> = {
135
+ /**
136
+ * 验证成功标识
137
+ */
138
+ success: true;
139
+ /**
140
+ * 验证后的数据
141
+ */
142
+ data: T;
143
+ } | {
144
+ /**
145
+ * 验证失败标识
146
+ */
147
+ success: false;
148
+ /**
149
+ * 错误信息
150
+ */
151
+ error: string;
152
+ };
153
+ /**
154
+ * 参数验证器函数类型
155
+ *
156
+ * @typeParam T - 参数类型
157
+ */
158
+ type ParamsValidator<T> = (args: unknown[]) => ValidationResult<T>;
159
+ /**
160
+ * 创建参数验证器
161
+ *
162
+ * @typeParam P - 参数 Schema 类型
163
+ * @param paramsSchema - 参数 Zod Schema
164
+ * @returns 验证中间件函数
165
+ */
166
+ declare function createParamsValidator<P extends z.ZodType>(paramsSchema: P): ParamsValidator<z.infer<P>>;
167
+ //#endregion
168
+ //#region src/ipc/zod/main/types.d.ts
169
+ /**
170
+ * Zod Handler 函数类型
171
+ *
172
+ * @typeParam P - 参数 Schema 类型
173
+ * @typeParam R - 返回值 Schema 类型
174
+ */
175
+ type ZodHandler<P extends z.ZodType, R extends z.ZodType> = (event: IpcMainInvokeEvent, ...args: z.infer<P> extends unknown[] ? z.infer<P> : [z.infer<P>]) => Promise<z.infer<R>> | z.infer<R>;
176
+ /**
177
+ * Handler 函数类型(内部使用)
178
+ *
179
+ * @param event - IPC 事件对象
180
+ * @param args - Handler 参数
181
+ */
182
+ type InternalHandlerFn = (event: IpcMainInvokeEvent, ...args: unknown[]) => Promise<IPCResult$1<unknown>>;
183
+ /**
184
+ * 从 ZodFunction Schema 提取参数元组类型
185
+ *
186
+ * @typeParam F - ZodFunction 类型
187
+ */
188
+ type ExtractHandlerArgs<F> = F extends z.ZodFunction<infer I, infer _> ? I extends z.ZodTuple<infer Items> ? { [K in keyof Items]: z.infer<Items[K]>; } : [] : unknown[];
189
+ /**
190
+ * 类型安全的 Handler 函数类型
191
+ *
192
+ * @typeParam F - ZodFunction Schema 类型
193
+ */
194
+ type TypedHandlerFn<F extends z.ZodFunction> = (event: IpcMainInvokeEvent, ...args: ExtractHandlerArgs<F>) => Promise<IPCResult$1<unknown>>;
195
+ /**
196
+ * 从 ZodIPCSchema 中提取 ZodFunction 类型
197
+ *
198
+ * 条件类型:匹配包含 input(输入参数 Schema 数组)和 output(输出结果 Schema)属性的结构
199
+ *
200
+ * @typeParam T - ZodIPCMethodsDefinition 类型
201
+ * @typeParam K - 方法键名
202
+ */
203
+ type ExtractZodFunctionFromIPCSchema<T extends ZodIPCMethodsDefinition, K extends keyof T> = T[K] extends {
204
+ /**
205
+ * 输入参数 Schema 数组
206
+ */
207
+ input?: infer I;
208
+ /**
209
+ * 输出结果 Schema
210
+ */
211
+ output: unknown;
212
+ } ? I extends z.ZodTypeAny[] ? z.ZodFunction<z.ZodTuple<{ [Index in keyof I]: I[Index]; }>, z.ZodPromise<z.ZodUnknown>> : z.ZodFunction<z.ZodTuple<[]>, z.ZodPromise<z.ZodUnknown>> : never;
213
+ /**
214
+ * ZodIPCSchema Handler 注册函数类型
215
+ *
216
+ * @typeParam T - ZodIPCMethodsDefinition 类型
217
+ */
218
+ type ZodIPCSchemaHandleRegisterFn<T extends ZodIPCMethodsDefinition> = <K extends keyof T & string>(key: K, handler: TypedHandlerFn<ExtractZodFunctionFromIPCSchema<T, K>>) => void;
219
+ /**
220
+ * ZodIPCSchema Remove 函数类型
221
+ *
222
+ * @typeParam T - ZodIPCMethodsDefinition 类型
223
+ */
224
+ type ZodIPCSchemaRemoveFn<T extends ZodIPCMethodsDefinition> = <K extends keyof T & string>(key: K) => void;
225
+ //#endregion
226
+ //#region src/ipc/zod/main/handlers.d.ts
227
+ /**
228
+ * 创建带 Zod 验证的 IPC Handler
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const ParamsSchema = z.tuple([z.string(), z.string().optional()]);
233
+ * const ReturnSchema = createIPCResultSchema(z.object({ id: z.string() }));
234
+ *
235
+ * registerZodHandler(
236
+ * 'company:addItem',
237
+ * ParamsSchema,
238
+ * ReturnSchema,
239
+ * async (_, name, industry) => {
240
+ * return { success: true, data: { id: '123' } };
241
+ * },
242
+ * );
243
+ * ```;
244
+ *
245
+ * @typeParam P - 参数 Schema 类型
246
+ * @typeParam R - 返回值 Schema 类型
247
+ * @param channel - IPC 通道名称
248
+ * @param paramsSchema - 参数 Zod Schema
249
+ * @param _returnSchema - 返回值 Zod Schema(用于文档目的)
250
+ * @param handler - Handler 函数
251
+ */
252
+ declare function registerZodHandler<P extends z.ZodType, R extends z.ZodType>(channel: string, paramsSchema: P, _returnSchema: R, handler: ZodHandler<P, R>): void;
253
+ /**
254
+ * 创建带 Zod 验证的 Handler 工厂函数
255
+ *
256
+ * 返回一个函数,用于注册带类型验证的 Handler
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const AgentIPCAPISchema = defineZodIPCSchema('agent', {
261
+ * getAll: { output: z.array(AgentSchema) },
262
+ * getById: { input: [z.string()], output: AgentSchema.nullable() },
263
+ * create: { input: [AgentCreateParamsSchema], output: AgentSchema },
264
+ * delete: { input: [z.string()], output: z.void() },
265
+ * });
266
+ *
267
+ * // 通道名自动推导
268
+ * AgentIPCAPISchema.channels.getAll; // 'agent:getAll'
269
+ *
270
+ * // Main 进程使用(无需传递 channels)
271
+ * const handle = createZodHandle(AgentIPCAPISchema);
272
+ * handle('getAll', async () => success(await repo.getAll()));
273
+ * handle('getById', async (_, id) => success(await repo.getById(id)));
274
+ * ```;
275
+ *
276
+ * @typeParam T - 方法定义类型
277
+ * @param ipcSchema - ZodIPCSchema 对象(由 defineZodIPCSchema 创建)
278
+ * @returns 注册函数
279
+ */
280
+ declare function createZodHandle<T extends ZodIPCMethodsDefinition>(ipcSchema: ZodIPCSchema<T>): ZodIPCSchemaHandleRegisterFn<T>;
281
+ /**
282
+ * 批量注册带 Zod 验证的 Handlers
283
+ *
284
+ * @example
285
+ * ```typescript
286
+ * const AgentIPCAPISchema = defineZodIPCSchema('agent', {
287
+ * getAll: { output: z.array(AgentSchema) },
288
+ * getById: { input: [z.string()], output: AgentSchema.nullable() },
289
+ * });
290
+ *
291
+ * registerZodHandlers(AgentIPCAPISchema, {
292
+ * getAll: async () => success(await repo.getAll()),
293
+ * getById: async (_, id) => success(await repo.getById(id)),
294
+ * });
295
+ * ```;
296
+ *
297
+ * @typeParam T - 方法定义类型
298
+ * @param ipcSchema - ZodIPCSchema 对象
299
+ * @param handlers - Handler 映射对象
300
+ */
301
+ declare function registerZodHandlers<T extends ZodIPCMethodsDefinition>(ipcSchema: ZodIPCSchema<T>, handlers: Record<string, InternalHandlerFn>): void;
302
+ /**
303
+ * 移除 IPC Handler
304
+ *
305
+ * @param channel - IPC 通道名称
306
+ */
307
+ declare function removeZodHandler(channel: string): void;
308
+ /**
309
+ * 创建带 Zod 验证的 Handler 移除工厂函数
310
+ *
311
+ * @typeParam T - 方法定义类型
312
+ * @param ipcSchema - ZodIPCSchema 对象
313
+ * @returns 移除函数
314
+ */
315
+ declare function createZodRemove<T extends ZodIPCMethodsDefinition>(ipcSchema: ZodIPCSchema<T>): ZodIPCSchemaRemoveFn<T>;
316
+ //#endregion
317
+ //#region src/window/types.d.ts
318
+ /**
319
+ * 窗口配置选项
320
+ */
321
+ type WindowOptions = {
322
+ /**
323
+ * 窗口宽度
324
+ */
325
+ width?: number;
326
+ /**
327
+ * 窗口高度
328
+ */
329
+ height?: number;
330
+ /**
331
+ * 最小宽度
332
+ */
333
+ minWidth?: number;
334
+ /**
335
+ * 最小高度
336
+ */
337
+ minHeight?: number;
338
+ /**
339
+ * 是否无边框
340
+ */
341
+ frame?: boolean;
342
+ /**
343
+ * 标题栏样式
344
+ */
345
+ titleBarStyle?: 'hidden' | 'hiddenInset' | 'default';
346
+ /**
347
+ * 是否自动隐藏菜单栏
348
+ */
349
+ autoHideMenuBar?: boolean;
350
+ /**
351
+ * 是否启用 DevTools(开发环境)
352
+ */
353
+ devTools?: boolean;
354
+ /**
355
+ * 额外的 BrowserWindow 选项
356
+ */
357
+ browserWindowOptions?: Partial<BrowserWindowConstructorOptions>;
358
+ };
359
+ /**
360
+ * 默认窗口配置
361
+ *
362
+ * 提供窗口的默认配置值,包括宽度、高度、边框样式等
363
+ */
364
+ declare const DEFAULT_WINDOW_OPTIONS: Required<Pick<WindowOptions, 'width' | 'height' | 'frame' | 'titleBarStyle' | 'autoHideMenuBar'>>;
365
+ //#endregion
366
+ //#region src/window/channels.d.ts
367
+ /**
368
+ * 窗口控制 IPC 通道常量
369
+ *
370
+ * 定义了窗口控制相关的 IPC 通道名称
371
+ */
372
+ /**
373
+ * 窗口控制 IPC 通道常量
374
+ */
375
+ declare const WINDOW_CONTROL_CHANNELS: {
376
+ /**
377
+ * 最小化窗口通道
378
+ */
379
+ readonly MINIMIZE: 'window:minimize';
380
+ /**
381
+ * 最大化/还原窗口通道
382
+ */
383
+ readonly MAXIMIZE: 'window:maximize';
384
+ /**
385
+ * 关闭窗口通道
386
+ */
387
+ readonly CLOSE: 'window:close';
388
+ /**
389
+ * 查询窗口是否最大化通道
390
+ */
391
+ readonly IS_MAXIMIZED: 'window:is-maximized';
392
+ };
393
+ //#endregion
394
+ //#region src/window/window-manager.manager.d.ts
395
+ /**
396
+ * 获取主窗口实例
397
+ *
398
+ * 返回当前主窗口的 BrowserWindow 实例
399
+ *
400
+ * @returns 主窗口实例或 null
401
+ */
402
+ declare function getMainWindow(): BrowserWindow | null;
403
+ /**
404
+ * 注册窗口控制 IPC 处理器
405
+ *
406
+ * 注册以下窗口控制处理器:
407
+ * - window-minimize: 最小化窗口
408
+ * - window-maximize: 最大化/还原窗口
409
+ * - window-close: 关闭窗口
410
+ * - window-is-maximized: 查询窗口是否最大化
411
+ */
412
+ declare function registerWindowControlHandlers(): void;
413
+ /**
414
+ * 创建主窗口
415
+ *
416
+ * 创建应用的主浏览器窗口,配置窗口属性和事件处理器
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * // 使用默认配置
421
+ * createWindow();
422
+ *
423
+ * // 自定义配置
424
+ * createWindow({ width: 1000, height: 700 });
425
+ * ```;
426
+ *
427
+ * @param options - 窗口配置选项
428
+ */
429
+ declare function createWindow(options?: WindowOptions): void;
430
+ /**
431
+ * 销毁主窗口引用
432
+ *
433
+ * 清空主窗口引用,用于应用关闭时清理资源
434
+ */
435
+ declare function destroyMainWindow(): void;
436
+ //#endregion
437
+ //#region src/di/container.service.d.ts
438
+ /**
439
+ * 依赖注入容器
440
+ *
441
+ * 使用单例模式管理所有依赖实例
442
+ */
443
+ /**
444
+ * 类型守卫函数类型
445
+ *
446
+ * @typeParam T - 期望的类型
447
+ */
448
+ type TypeGuard<T> = (value: unknown) => value is T;
449
+ /**
450
+ * 依赖注入容器
451
+ *
452
+ * 使用单例模式管理所有依赖实例,提供注册和解析功能
453
+ */
454
+ declare class DIContainerService {
455
+ /**
456
+ * 容器单例实例
457
+ */
458
+ private static instance;
459
+ /**
460
+ * 依赖实例映射表
461
+ */
462
+ private instances;
463
+ /**
464
+ * 私有构造函数,防止外部实例化
465
+ */
466
+ private constructor();
467
+ /**
468
+ * 获取容器单例实例
469
+ *
470
+ * @returns DI 容器实例
471
+ */
472
+ static getInstance(): DIContainerService;
473
+ /**
474
+ * 注册依赖实例
475
+ *
476
+ * T 为实例类型
477
+ *
478
+ * @typeParam T - 依赖实例的类型
479
+ * @param token - 依赖标识
480
+ * @param instance - 依赖实例
481
+ */
482
+ register<T>(token: string, instance: T): void;
483
+ /**
484
+ * 解析依赖实例(返回 unknown 类型,需要调用者使用类型守卫)
485
+ *
486
+ * @param token - 依赖标识
487
+ * @returns 依赖实例(unknown 类型)
488
+ * @throws {@link Error} 依赖未注册时抛出错误
489
+ */
490
+ resolve(token: string): unknown;
491
+ /**
492
+ * 使用类型守卫解析依赖实例
493
+ *
494
+ * T 为实例类型
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * // 定义类型守卫
499
+ * function isDatabaseService(value: unknown): value is DatabaseService {
500
+ * return (
501
+ * value !== null &&
502
+ * typeof value === 'object' &&
503
+ * 'query' in value &&
504
+ * typeof value.query === 'function'
505
+ * );
506
+ * }
507
+ *
508
+ * // 使用类型守卫解析
509
+ * const db = container.resolveWithGuard('database', isDatabaseService);
510
+ * ```;
511
+ *
512
+ * @typeParam T - 依赖实例的目标类型
513
+ * @param token - 依赖标识
514
+ * @param guard - 类型守卫函数
515
+ * @returns 依赖实例
516
+ * @throws {@link Error} 依赖未注册时抛出错误
517
+ * @throws {@link Error} 类型守卫检查失败时抛出错误
518
+ */
519
+ resolveWithGuard<T>(token: string, guard: TypeGuard<T>): T;
520
+ /**
521
+ * 检查依赖是否已注册
522
+ *
523
+ * @param token - 依赖标识
524
+ * @returns 是否已注册
525
+ */
526
+ has(token: string): boolean;
527
+ /**
528
+ * 清除所有依赖实例
529
+ *
530
+ * 用于测试或重置容器
531
+ */
532
+ clear(): void;
533
+ }
534
+ /**
535
+ * 获取全局 DI 容器实例
536
+ *
537
+ * @returns DI 容器实例
538
+ */
539
+ declare function getContainer(): DIContainerService;
540
+ //#endregion
541
+ //#region src/di/tokens.d.ts
542
+ /**
543
+ * DI Token 常量定义
544
+ */
545
+ /**
546
+ * 核心 Token 常量
547
+ *
548
+ * 用于依赖注入的核心标识符
549
+ */
550
+ declare const CORE_TOKENS: {
551
+ /**
552
+ * 日志服务 Token
553
+ */
554
+ readonly LOGGER: 'logger';
555
+ /**
556
+ * 数据库服务 Token
557
+ */
558
+ readonly DATABASE: 'database';
559
+ /**
560
+ * 窗口服务 Token
561
+ */
562
+ readonly WINDOW_SERVICE: 'window-service';
563
+ /**
564
+ * 生命周期管理器 Token
565
+ */
566
+ readonly LIFECYCLE_MANAGER: 'lifecycle-manager';
567
+ };
568
+ /**
569
+ * 仓库 Token 常量
570
+ *
571
+ * 继承核心 Token,用于仓库层依赖注入
572
+ */
573
+ declare const REPOSITORY_TOKENS: {
574
+ /**
575
+ * 日志服务 Token
576
+ */
577
+ readonly LOGGER: 'logger';
578
+ /**
579
+ * 数据库服务 Token
580
+ */
581
+ readonly DATABASE: 'database';
582
+ /**
583
+ * 窗口服务 Token
584
+ */
585
+ readonly WINDOW_SERVICE: 'window-service';
586
+ /**
587
+ * 生命周期管理器 Token
588
+ */
589
+ readonly LIFECYCLE_MANAGER: 'lifecycle-manager';
590
+ };
591
+ //#endregion
592
+ //#region src/errors/errors.d.ts
593
+ /**
594
+ * 错误码枚举
595
+ *
596
+ * 定义所有可能的错误码
597
+ */
598
+ declare const ErrorCode: z.ZodEnum<{
599
+ AUTH_FAILED: "AUTH_FAILED";
600
+ AUTH_INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS";
601
+ AUTH_TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED";
602
+ AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED";
603
+ DB_CONNECTION_ERROR: "DB_CONNECTION_ERROR";
604
+ DB_CONSTRAINT_VIOLATION: "DB_CONSTRAINT_VIOLATION";
605
+ DB_NOT_FOUND: "DB_NOT_FOUND";
606
+ DB_QUERY_ERROR: "DB_QUERY_ERROR";
607
+ FILE_NOT_FOUND: "FILE_NOT_FOUND";
608
+ FILE_PERMISSION_DENIED: "FILE_PERMISSION_DENIED";
609
+ FILE_READ_ERROR: "FILE_READ_ERROR";
610
+ FILE_WRITE_ERROR: "FILE_WRITE_ERROR";
611
+ GIT_COMMAND_FAILED: "GIT_COMMAND_FAILED";
612
+ GIT_MERGE_CONFLICT: "GIT_MERGE_CONFLICT";
613
+ GIT_NOT_A_REPO: "GIT_NOT_A_REPO";
614
+ INVALID_ARGUMENT: "INVALID_ARGUMENT";
615
+ NETWORK_ERROR: "NETWORK_ERROR";
616
+ NETWORK_TIMEOUT: "NETWORK_TIMEOUT";
617
+ OPERATION_FAILED: "OPERATION_FAILED";
618
+ PLUGIN_EXECUTION_ERROR: "PLUGIN_EXECUTION_ERROR";
619
+ PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED";
620
+ PLUGIN_NOT_FOUND: "PLUGIN_NOT_FOUND";
621
+ UNKNOWN: "UNKNOWN";
622
+ }>;
623
+ /**
624
+ * 错误码类型
625
+ *
626
+ * 从 ErrorCode Schema 推断的类型
627
+ */
628
+ type ErrorCode = z.infer<typeof ErrorCode>;
629
+ /**
630
+ * 应用错误类
631
+ *
632
+ * 统一的错误类型,包含错误码、消息和详情
633
+ */
634
+ declare class AppError extends Error {
635
+ /**
636
+ * 错误码
637
+ */
638
+ readonly code: ErrorCode;
639
+ /**
640
+ * 错误详情
641
+ */
642
+ readonly details?: unknown;
643
+ /**
644
+ * 错误时间戳
645
+ */
646
+ readonly timestamp: number;
647
+ /**
648
+ * 创建应用错误实例
649
+ *
650
+ * @param code - 错误码
651
+ * @param message - 错误消息
652
+ * @param details - 错误详情
653
+ */
654
+ constructor(code: ErrorCode, message: string, details?: unknown);
655
+ /**
656
+ * 转换为 JSON 格式
657
+ *
658
+ * @returns JSON 对象
659
+ */
660
+ toJSON(): Record<string, unknown>;
661
+ /**
662
+ * 从错误对象创建 AppError
663
+ *
664
+ * 如果传入的已经是 AppError 实例则直接返回,否则创建新的 AppError
665
+ *
666
+ * @param error - 原始错误对象
667
+ * @param code - 错误码,默认为 UNKNOWN
668
+ * @returns AppError 实例
669
+ */
670
+ static fromError(error: Error, code?: ErrorCode): AppError;
671
+ /**
672
+ * 创建未知错误
673
+ *
674
+ * @param message - 错误消息
675
+ * @returns AppError 实例
676
+ */
677
+ static unknown(message: string): AppError;
678
+ /**
679
+ * 创建无效参数错误
680
+ *
681
+ * @param message - 错误消息
682
+ * @returns AppError 实例
683
+ */
684
+ static invalidArgument(message: string): AppError;
685
+ /**
686
+ * 创建操作失败错误
687
+ *
688
+ * @param message - 错误消息
689
+ * @returns AppError 实例
690
+ */
691
+ static operationFailed(message: string): AppError;
692
+ }
693
+ /**
694
+ * 错误处理结果类型
695
+ *
696
+ * T 为数据类型
697
+ */
698
+ type ErrorResult = {
699
+ /**
700
+ * 是否成功
701
+ */
702
+ success: false;
703
+ /**
704
+ * 错误对象
705
+ */
706
+ error?: AppError;
707
+ };
708
+ /**
709
+ * 成功结果类型
710
+ *
711
+ * T 为数据类型
712
+ *
713
+ * @typeParam T - 成功时返回的数据类型
714
+ */
715
+ type SuccessResult<T> = {
716
+ /**
717
+ * 是否成功
718
+ */
719
+ success: true;
720
+ /**
721
+ * 返回数据
722
+ */
723
+ data: T;
724
+ };
725
+ /**
726
+ * 结果类型(成功或失败)
727
+ *
728
+ * T 为数据类型
729
+ *
730
+ * @typeParam T - 成功时返回的数据类型
731
+ */
732
+ type Result<T> = SuccessResult<T> | ErrorResult;
733
+ /**
734
+ * 异步操作函数类型
735
+ *
736
+ * T 为返回数据类型
737
+ *
738
+ * @typeParam T - 成功时返回的数据类型
739
+ */
740
+ type AsyncOperation<T> = () => Promise<T>;
741
+ /**
742
+ * 创建成功结果
743
+ *
744
+ * T 为数据类型
745
+ *
746
+ * @typeParam T - 成功时返回的数据类型
747
+ * @param data - 成功数据
748
+ * @returns 成功结果
749
+ */
750
+ declare function success<T>(data: T): SuccessResult<T>;
751
+ /**
752
+ * 创建错误结果
753
+ *
754
+ * @param code - 错误码
755
+ * @param message - 错误消息
756
+ * @param details - 错误详情
757
+ * @returns 错误结果
758
+ */
759
+ declare function failure(code: ErrorCode, message: string, details?: unknown): ErrorResult;
760
+ /**
761
+ * 包装异步操作,自动捕获错误
762
+ *
763
+ * T 为返回数据类型
764
+ *
765
+ * @typeParam T - 成功时返回的数据类型
766
+ * @param operation - 异步操作
767
+ * @param errorCode - 错误码
768
+ * @returns 结果类型
769
+ */
770
+ declare function wrapAsync<T>(operation: AsyncOperation<T>, errorCode?: ErrorCode): Promise<Result<T>>;
771
+ //#endregion
772
+ //#region src/lifecycle/lifecycle-manager.manager.d.ts
773
+ /**
774
+ * 关闭钩子类型
775
+ */
776
+ type ShutdownHook = () => Promise<void> | void;
777
+ /**
778
+ * 启动钩子类型
779
+ */
780
+ type StartupHook = () => Promise<void> | void;
781
+ /**
782
+ * 就绪钩子类型
783
+ */
784
+ type ReadyHook = () => Promise<void> | void;
785
+ /**
786
+ * 生命周期阶段
787
+ */
788
+ declare const LifecyclePhase: z.ZodEnum<{
789
+ IDLE: "IDLE";
790
+ INITIALIZING: "INITIALIZING";
791
+ READY: "READY";
792
+ SHUTTING_DOWN: "SHUTTING_DOWN";
793
+ }>;
794
+ /**
795
+ * 生命周期阶段类型
796
+ */
797
+ type LifecyclePhase = z.infer<typeof LifecyclePhase>;
798
+ /**
799
+ * 生命周期管理器
800
+ *
801
+ * 管理应用的启动和关闭流程,支持注册关闭钩子
802
+ */
803
+ declare class LifecycleManager {
804
+ /**
805
+ * 当前生命周期阶段
806
+ */
807
+ private phase;
808
+ /**
809
+ * 数据库实例
810
+ */
811
+ private database;
812
+ /**
813
+ * 启动钩子列表
814
+ */
815
+ private startupHooks;
816
+ /**
817
+ * 就绪钩子列表
818
+ */
819
+ private readyHooks;
820
+ /**
821
+ * 关闭钩子列表
822
+ */
823
+ private shutdownHooks;
824
+ /**
825
+ * 就绪解析器列表
826
+ */
827
+ private readyResolvers;
828
+ /**
829
+ * 设置数据库实例
830
+ *
831
+ * @param dataSource - TypeORM 数据源
832
+ */
833
+ setDatabase(dataSource: DataSource): void;
834
+ /**
835
+ * 获取当前生命周期阶段
836
+ *
837
+ * @returns 当前生命周期阶段
838
+ */
839
+ getPhase(): LifecyclePhase;
840
+ /**
841
+ * 检查是否已就绪
842
+ *
843
+ * @returns 是否已就绪
844
+ */
845
+ isReady(): boolean;
846
+ /**
847
+ * 获取数据库实例
848
+ *
849
+ * @returns 数据源实例或 null
850
+ */
851
+ getDatabase(): DataSource | null;
852
+ /**
853
+ * 注册关闭钩子
854
+ *
855
+ * @param hook - 关闭钩子函数
856
+ */
857
+ onShutdown(hook: ShutdownHook): void;
858
+ /**
859
+ * 注册启动前钩子
860
+ *
861
+ * @param hook - 启动前钩子函数
862
+ */
863
+ onBeforeStartup(hook: StartupHook): void;
864
+ /**
865
+ * 注册就绪钩子
866
+ *
867
+ * @param hook - 就绪钩子函数
868
+ */
869
+ onReady(hook: ReadyHook): void;
870
+ /**
871
+ * 初始化生命周期
872
+ *
873
+ * 执行启动和就绪钩子
874
+ *
875
+ * @returns 异步完成,无返回值
876
+ */
877
+ initialize(): Promise<void>;
878
+ /**
879
+ * 等待就绪
880
+ *
881
+ * @returns 就绪状态的 Promise
882
+ */
883
+ whenReady(): Promise<void>;
884
+ /**
885
+ * 执行关闭流程
886
+ *
887
+ * 按顺序执行所有注册的关闭钩子
888
+ */
889
+ shutdown(): Promise<void>;
890
+ }
891
+ /**
892
+ * 全局生命周期管理器实例
893
+ */
894
+ declare const lifecycleManager: LifecycleManager;
895
+ //#endregion
896
+ //#region src/security/csp.config.d.ts
897
+ /**
898
+ * CSP 安全策略模块
899
+ */
900
+ /**
901
+ * CSP 策略配置选项
902
+ */
903
+ type CSPPolicyOptions = {
904
+ /**
905
+ * 开发环境连接源
906
+ */
907
+ devConnectSrc?: string[];
908
+ /**
909
+ * 生产环境连接源
910
+ */
911
+ prodConnectSrc?: string[];
912
+ };
913
+ /**
914
+ * 创建 CSP 策略
915
+ *
916
+ * 根据环境创建内容安全策略字符串
917
+ *
918
+ * @param isDev - 是否为开发环境
919
+ * @param options - CSP 策略配置选项
920
+ * @returns CSP 策略字符串
921
+ */
922
+ declare function createCSPPolicy(isDev: boolean, options?: CSPPolicyOptions): string;
923
+ /**
924
+ * 配置 CSP
925
+ *
926
+ * 为默认会话配置内容安全策略
927
+ *
928
+ * @param options - CSP 策略配置选项
929
+ */
930
+ declare function configureCSP(options?: CSPPolicyOptions): void;
931
+ //#endregion
932
+ //#region src/config/vite.config.d.ts
933
+ /**
934
+ * Vite 配置工厂
935
+ */
936
+ /**
937
+ * Desktop Vite 配置选项
938
+ */
939
+ type DesktopViteConfigOptions = {
940
+ /**
941
+ * 应用名称
942
+ */
943
+ appName: string;
944
+ /**
945
+ * 需要外部化的包
946
+ */
947
+ externalPackages?: string[];
948
+ };
949
+ /**
950
+ * Main 进程配置
951
+ */
952
+ type MainConfig = {
953
+ /**
954
+ * 路径解析配置
955
+ */
956
+ resolve: {
957
+ /**
958
+ * 路径别名配置
959
+ */
960
+ alias: Record<string, string>;
961
+ };
962
+ /**
963
+ * 构建配置
964
+ */
965
+ build: {
966
+ /**
967
+ * 外部依赖配置
968
+ */
969
+ externalizeDeps: {
970
+ /**
971
+ * 需要外部化的包列表
972
+ */
973
+ exclude: string[];
974
+ };
975
+ };
976
+ };
977
+ /**
978
+ * Preload 进程配置
979
+ */
980
+ type PreloadConfig = {
981
+ /**
982
+ * 路径解析配置
983
+ */
984
+ resolve: {
985
+ /**
986
+ * 路径别名配置
987
+ */
988
+ alias: Record<string, string>;
989
+ };
990
+ /**
991
+ * 构建配置
992
+ */
993
+ build: {
994
+ /**
995
+ * 外部依赖配置
996
+ */
997
+ externalizeDeps: {
998
+ /**
999
+ * 需要外部化的包列表
1000
+ */
1001
+ exclude: string[];
1002
+ };
1003
+ /**
1004
+ * Rollup 构建选项
1005
+ */
1006
+ rollupOptions: {
1007
+ /**
1008
+ * 外部模块
1009
+ */
1010
+ external: string[];
1011
+ /**
1012
+ * 输出配置
1013
+ */
1014
+ output: {
1015
+ /**
1016
+ * 入口文件命名
1017
+ */
1018
+ entryFileNames: string;
1019
+ };
1020
+ };
1021
+ };
1022
+ /**
1023
+ * 库输出配置
1024
+ */
1025
+ lib: {
1026
+ /**
1027
+ * 入口文件路径
1028
+ */
1029
+ entry: string;
1030
+ /**
1031
+ * 输出格式
1032
+ */
1033
+ formats: 'cjs'[];
1034
+ };
1035
+ };
1036
+ /**
1037
+ * Renderer 进程配置
1038
+ */
1039
+ type RendererConfig = {
1040
+ /**
1041
+ * 路径解析配置
1042
+ */
1043
+ resolve: {
1044
+ /**
1045
+ * 路径别名配置
1046
+ */
1047
+ alias: Record<string, string>;
1048
+ };
1049
+ };
1050
+ /**
1051
+ * Desktop Vite 配置结果
1052
+ */
1053
+ type DesktopViteConfigResult = {
1054
+ /**
1055
+ * Main 进程配置
1056
+ */
1057
+ main: MainConfig;
1058
+ /**
1059
+ * Preload 进程配置
1060
+ */
1061
+ preload: PreloadConfig;
1062
+ /**
1063
+ * Renderer 进程配置
1064
+ */
1065
+ renderer: RendererConfig;
1066
+ };
1067
+ /**
1068
+ * 创建 Electron Vite 配置
1069
+ *
1070
+ * 由于此模块需要 \@tailwindcss/vite、\@vitejs/plugin-react 和 electron-vite,
1071
+ * 这些依赖应该在使用此模块的应用中安装
1072
+ *
1073
+ * @example
1074
+ * ```typescript
1075
+ * import { createDesktopViteConfig } from '@longzai-intelligence/electron/config';
1076
+ * import tailwindcss from '@tailwindcss/vite';
1077
+ * import react from '@vitejs/plugin-react';
1078
+ *
1079
+ * export default defineConfig({
1080
+ * ...createDesktopViteConfig({
1081
+ * appName: 'desktop',
1082
+ * externalPackages: ['@longzai-intelligence/shared-kernel', '@longzai-intelligence/utils'],
1083
+ * }),
1084
+ * renderer: {
1085
+ * plugins: [react(), tailwindcss()],
1086
+ * },
1087
+ * });
1088
+ * ```;
1089
+ *
1090
+ * @param options - 配置选项
1091
+ * @returns Electron Vite 配置对象
1092
+ */
1093
+ declare function createDesktopViteConfig(options: DesktopViteConfigOptions): DesktopViteConfigResult;
1094
+ //#endregion
1095
+ export { AppError, CORE_TOKENS, type CSPPolicyOptions, DEFAULT_WINDOW_OPTIONS, DIContainerService as DIContainer, DIContainerService, type DesktopViteConfigOptions, ErrorCode, type ErrorResult, type ExtractMethodName, type IPCAPIToFunctions, type IPCAPIToShortAPI, type IPCAPIWithMapping, type IPCError, type IPCErrorCode, IPCErrorCodeSchema, IPCErrorSchema, type IPCMethodDefinition, type IPCParams, type IPCParamsArray, type IPCResult, IPCResultSchema, type IPCReturn, type IPCSerializable, type InferIPCAPI, type InferIPCAPIFromSchema, LifecycleManager, LifecyclePhase, REPOSITORY_TOKENS, type Result, type StrictIPCAPI, type SuccessResult, type TypedAPI, WINDOW_CONTROL_CHANNELS, type WindowOptions, type ZodHandler, type ZodIPCMethodDecl, type ZodIPCMethodsDefinition, type ZodIPCSchema, configureCSP, createCSPPolicy, createDesktopViteConfig, createHandle, createIPCAPISchema, createIPCFunctionSchema, createIPCMethodDefinitionSchema, createIPCResultSchema, createParamsValidator, createRemove, createWindow, createZodHandle, createZodRemove, defineZodIPCSchema, destroyMainWindow, failure as errorFailure, success as errorSuccess, failure$1 as failure, getContainer, getMainWindow, isFailure, isSuccess, lifecycleManager, registerHandlers, registerWindowControlHandlers, registerZodHandler, registerZodHandlers, removeZodHandler, success$1 as success, unwrap, wrapAsync };