@huyooo/ai-chat-bridge-electron 0.1.0

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,145 @@
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/main/index.ts
21
+ var main_exports = {};
22
+ __export(main_exports, {
23
+ AVAILABLE_MODELS: () => import_ai_chat_core.AVAILABLE_MODELS,
24
+ createElectronBridge: () => createElectronBridge
25
+ });
26
+ module.exports = __toCommonJS(main_exports);
27
+ var import_electron = require("electron");
28
+ var import_ai_chat_core = require("@huyooo/ai-chat-core");
29
+ var import_ai_chat_storage = require("@huyooo/ai-chat-storage");
30
+ async function createElectronBridge(options) {
31
+ const {
32
+ channelPrefix = "ai-chat",
33
+ storagePath,
34
+ defaultContext = {},
35
+ ...agentConfig
36
+ } = options;
37
+ const agent = new import_ai_chat_core.HybridAgent(agentConfig);
38
+ const storage = await (0, import_ai_chat_storage.createStorage)({
39
+ type: "sqlite",
40
+ sqlitePath: storagePath || (0, import_ai_chat_storage.getDefaultStoragePath)()
41
+ });
42
+ const getContext = () => defaultContext;
43
+ import_electron.ipcMain.handle(`${channelPrefix}:models`, () => {
44
+ return import_ai_chat_core.AVAILABLE_MODELS;
45
+ });
46
+ import_electron.ipcMain.handle(`${channelPrefix}:send`, async (event, params) => {
47
+ const webContents = event.sender;
48
+ const { message, images, options: options2 = {}, sessionId } = params;
49
+ console.log("[AI-Chat] \u6536\u5230\u6D88\u606F:", { message, options: options2, images: images?.length || 0, sessionId });
50
+ try {
51
+ for await (const progress of agent.chat(message, options2, images)) {
52
+ console.log(
53
+ "[AI-Chat] \u8FDB\u5EA6:",
54
+ progress.type,
55
+ progress.type === "text_delta" ? progress.data.slice(0, 20) : progress.type === "thinking" ? JSON.stringify(progress.data) : progress.type === "search_result" ? `\u641C\u7D22\u5B8C\u6210 ${progress.data.results?.length || 0} \u6761` : JSON.stringify(progress.data).slice(0, 100)
56
+ );
57
+ if (!webContents.isDestroyed()) {
58
+ webContents.send(`${channelPrefix}:progress`, progress);
59
+ }
60
+ }
61
+ console.log("[AI-Chat] \u5B8C\u6210");
62
+ } catch (error) {
63
+ console.error("[AI-Chat] \u9519\u8BEF:", error);
64
+ if (!webContents.isDestroyed()) {
65
+ webContents.send(`${channelPrefix}:progress`, {
66
+ type: "error",
67
+ data: String(error)
68
+ });
69
+ }
70
+ }
71
+ });
72
+ import_electron.ipcMain.handle(`${channelPrefix}:cancel`, () => {
73
+ agent.abort();
74
+ });
75
+ import_electron.ipcMain.handle(`${channelPrefix}:clearAgentHistory`, () => {
76
+ agent.clearHistory();
77
+ });
78
+ import_electron.ipcMain.handle(`${channelPrefix}:agentHistory`, () => {
79
+ return agent.getHistory();
80
+ });
81
+ import_electron.ipcMain.handle(`${channelPrefix}:setWorkingDir`, (_event, dir) => {
82
+ agent.setWorkingDir(dir);
83
+ });
84
+ import_electron.ipcMain.handle(`${channelPrefix}:config`, () => {
85
+ return agent.getConfig();
86
+ });
87
+ import_electron.ipcMain.handle(`${channelPrefix}:sessions:list`, async () => {
88
+ return storage.getSessions(getContext());
89
+ });
90
+ import_electron.ipcMain.handle(`${channelPrefix}:sessions:get`, async (_event, id) => {
91
+ return storage.getSession(id, getContext());
92
+ });
93
+ import_electron.ipcMain.handle(`${channelPrefix}:sessions:create`, async (_event, params) => {
94
+ const input = {
95
+ id: params.id || crypto.randomUUID(),
96
+ title: params.title || "\u65B0\u5BF9\u8BDD",
97
+ model: params.model || "doubao-seed-1-6-251015",
98
+ mode: params.mode || "agent"
99
+ };
100
+ return storage.createSession(input, getContext());
101
+ });
102
+ import_electron.ipcMain.handle(`${channelPrefix}:sessions:update`, async (_event, id, data) => {
103
+ await storage.updateSession(id, data, getContext());
104
+ return storage.getSession(id, getContext());
105
+ });
106
+ import_electron.ipcMain.handle(`${channelPrefix}:sessions:delete`, async (_event, id) => {
107
+ await storage.deleteSession(id, getContext());
108
+ return { success: true };
109
+ });
110
+ import_electron.ipcMain.handle(`${channelPrefix}:messages:list`, async (_event, sessionId) => {
111
+ return storage.getMessages(sessionId, getContext());
112
+ });
113
+ import_electron.ipcMain.handle(`${channelPrefix}:messages:save`, async (_event, params) => {
114
+ const input = {
115
+ id: crypto.randomUUID(),
116
+ sessionId: params.sessionId,
117
+ role: params.role,
118
+ content: params.content,
119
+ thinking: params.thinking || null,
120
+ toolCalls: params.toolCalls || null,
121
+ searchResults: params.searchResults || null,
122
+ operationIds: params.operationIds || null
123
+ };
124
+ return storage.saveMessage(input, getContext());
125
+ });
126
+ import_electron.ipcMain.handle(`${channelPrefix}:messages:deleteAfter`, async (_event, sessionId, timestamp) => {
127
+ await storage.deleteMessagesAfter(sessionId, new Date(timestamp), getContext());
128
+ return { success: true };
129
+ });
130
+ import_electron.ipcMain.handle(`${channelPrefix}:operations:list`, async (_event, sessionId) => {
131
+ return storage.getOperations(sessionId, getContext());
132
+ });
133
+ import_electron.ipcMain.handle(`${channelPrefix}:trash:list`, async () => {
134
+ return storage.getTrashItems?.(getContext()) || [];
135
+ });
136
+ import_electron.ipcMain.handle(`${channelPrefix}:trash:restore`, async (_event, id) => {
137
+ return storage.restoreFromTrash?.(id, getContext());
138
+ });
139
+ return { agent, storage };
140
+ }
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ AVAILABLE_MODELS,
144
+ createElectronBridge
145
+ });
@@ -0,0 +1,41 @@
1
+ import { AgentConfig, HybridAgent } from '@huyooo/ai-chat-core';
2
+ export { AVAILABLE_MODELS, AgentConfig, ChatMode, ChatOptions, ChatProgress, ModelProvider } from '@huyooo/ai-chat-core';
3
+ import { StorageContext, StorageAdapter } from '@huyooo/ai-chat-storage';
4
+ export { MessageRecord, SessionRecord, StorageAdapter, StorageContext } from '@huyooo/ai-chat-storage';
5
+
6
+ /**
7
+ * Electron 主进程桥接
8
+ *
9
+ * 在主进程中调用,注册 IPC handlers
10
+ * 集成 SQLite 存储
11
+ */
12
+
13
+ interface ElectronBridgeOptions extends AgentConfig {
14
+ /** IPC channel 前缀 */
15
+ channelPrefix?: string;
16
+ /** SQLite 数据库路径 */
17
+ storagePath?: string;
18
+ /** 默认租户上下文 */
19
+ defaultContext?: StorageContext;
20
+ }
21
+ /**
22
+ * 创建 Electron IPC 桥接
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { createElectronBridge } from '@huyooo/ai-chat-bridge-electron/main';
27
+ *
28
+ * app.whenReady().then(async () => {
29
+ * const { agent, storage } = await createElectronBridge({
30
+ * arkApiKey: 'xxx',
31
+ * geminiApiKey: 'xxx',
32
+ * });
33
+ * });
34
+ * ```
35
+ */
36
+ declare function createElectronBridge(options: ElectronBridgeOptions): Promise<{
37
+ agent: HybridAgent;
38
+ storage: StorageAdapter;
39
+ }>;
40
+
41
+ export { type ElectronBridgeOptions, createElectronBridge };
@@ -0,0 +1,41 @@
1
+ import { AgentConfig, HybridAgent } from '@huyooo/ai-chat-core';
2
+ export { AVAILABLE_MODELS, AgentConfig, ChatMode, ChatOptions, ChatProgress, ModelProvider } from '@huyooo/ai-chat-core';
3
+ import { StorageContext, StorageAdapter } from '@huyooo/ai-chat-storage';
4
+ export { MessageRecord, SessionRecord, StorageAdapter, StorageContext } from '@huyooo/ai-chat-storage';
5
+
6
+ /**
7
+ * Electron 主进程桥接
8
+ *
9
+ * 在主进程中调用,注册 IPC handlers
10
+ * 集成 SQLite 存储
11
+ */
12
+
13
+ interface ElectronBridgeOptions extends AgentConfig {
14
+ /** IPC channel 前缀 */
15
+ channelPrefix?: string;
16
+ /** SQLite 数据库路径 */
17
+ storagePath?: string;
18
+ /** 默认租户上下文 */
19
+ defaultContext?: StorageContext;
20
+ }
21
+ /**
22
+ * 创建 Electron IPC 桥接
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { createElectronBridge } from '@huyooo/ai-chat-bridge-electron/main';
27
+ *
28
+ * app.whenReady().then(async () => {
29
+ * const { agent, storage } = await createElectronBridge({
30
+ * arkApiKey: 'xxx',
31
+ * geminiApiKey: 'xxx',
32
+ * });
33
+ * });
34
+ * ```
35
+ */
36
+ declare function createElectronBridge(options: ElectronBridgeOptions): Promise<{
37
+ agent: HybridAgent;
38
+ storage: StorageAdapter;
39
+ }>;
40
+
41
+ export { type ElectronBridgeOptions, createElectronBridge };
@@ -0,0 +1,125 @@
1
+ // src/main/index.ts
2
+ import { ipcMain } from "electron";
3
+ import {
4
+ HybridAgent,
5
+ AVAILABLE_MODELS
6
+ } from "@huyooo/ai-chat-core";
7
+ import {
8
+ createStorage,
9
+ getDefaultStoragePath
10
+ } from "@huyooo/ai-chat-storage";
11
+ async function createElectronBridge(options) {
12
+ const {
13
+ channelPrefix = "ai-chat",
14
+ storagePath,
15
+ defaultContext = {},
16
+ ...agentConfig
17
+ } = options;
18
+ const agent = new HybridAgent(agentConfig);
19
+ const storage = await createStorage({
20
+ type: "sqlite",
21
+ sqlitePath: storagePath || getDefaultStoragePath()
22
+ });
23
+ const getContext = () => defaultContext;
24
+ ipcMain.handle(`${channelPrefix}:models`, () => {
25
+ return AVAILABLE_MODELS;
26
+ });
27
+ ipcMain.handle(`${channelPrefix}:send`, async (event, params) => {
28
+ const webContents = event.sender;
29
+ const { message, images, options: options2 = {}, sessionId } = params;
30
+ console.log("[AI-Chat] \u6536\u5230\u6D88\u606F:", { message, options: options2, images: images?.length || 0, sessionId });
31
+ try {
32
+ for await (const progress of agent.chat(message, options2, images)) {
33
+ console.log(
34
+ "[AI-Chat] \u8FDB\u5EA6:",
35
+ progress.type,
36
+ progress.type === "text_delta" ? progress.data.slice(0, 20) : progress.type === "thinking" ? JSON.stringify(progress.data) : progress.type === "search_result" ? `\u641C\u7D22\u5B8C\u6210 ${progress.data.results?.length || 0} \u6761` : JSON.stringify(progress.data).slice(0, 100)
37
+ );
38
+ if (!webContents.isDestroyed()) {
39
+ webContents.send(`${channelPrefix}:progress`, progress);
40
+ }
41
+ }
42
+ console.log("[AI-Chat] \u5B8C\u6210");
43
+ } catch (error) {
44
+ console.error("[AI-Chat] \u9519\u8BEF:", error);
45
+ if (!webContents.isDestroyed()) {
46
+ webContents.send(`${channelPrefix}:progress`, {
47
+ type: "error",
48
+ data: String(error)
49
+ });
50
+ }
51
+ }
52
+ });
53
+ ipcMain.handle(`${channelPrefix}:cancel`, () => {
54
+ agent.abort();
55
+ });
56
+ ipcMain.handle(`${channelPrefix}:clearAgentHistory`, () => {
57
+ agent.clearHistory();
58
+ });
59
+ ipcMain.handle(`${channelPrefix}:agentHistory`, () => {
60
+ return agent.getHistory();
61
+ });
62
+ ipcMain.handle(`${channelPrefix}:setWorkingDir`, (_event, dir) => {
63
+ agent.setWorkingDir(dir);
64
+ });
65
+ ipcMain.handle(`${channelPrefix}:config`, () => {
66
+ return agent.getConfig();
67
+ });
68
+ ipcMain.handle(`${channelPrefix}:sessions:list`, async () => {
69
+ return storage.getSessions(getContext());
70
+ });
71
+ ipcMain.handle(`${channelPrefix}:sessions:get`, async (_event, id) => {
72
+ return storage.getSession(id, getContext());
73
+ });
74
+ ipcMain.handle(`${channelPrefix}:sessions:create`, async (_event, params) => {
75
+ const input = {
76
+ id: params.id || crypto.randomUUID(),
77
+ title: params.title || "\u65B0\u5BF9\u8BDD",
78
+ model: params.model || "doubao-seed-1-6-251015",
79
+ mode: params.mode || "agent"
80
+ };
81
+ return storage.createSession(input, getContext());
82
+ });
83
+ ipcMain.handle(`${channelPrefix}:sessions:update`, async (_event, id, data) => {
84
+ await storage.updateSession(id, data, getContext());
85
+ return storage.getSession(id, getContext());
86
+ });
87
+ ipcMain.handle(`${channelPrefix}:sessions:delete`, async (_event, id) => {
88
+ await storage.deleteSession(id, getContext());
89
+ return { success: true };
90
+ });
91
+ ipcMain.handle(`${channelPrefix}:messages:list`, async (_event, sessionId) => {
92
+ return storage.getMessages(sessionId, getContext());
93
+ });
94
+ ipcMain.handle(`${channelPrefix}:messages:save`, async (_event, params) => {
95
+ const input = {
96
+ id: crypto.randomUUID(),
97
+ sessionId: params.sessionId,
98
+ role: params.role,
99
+ content: params.content,
100
+ thinking: params.thinking || null,
101
+ toolCalls: params.toolCalls || null,
102
+ searchResults: params.searchResults || null,
103
+ operationIds: params.operationIds || null
104
+ };
105
+ return storage.saveMessage(input, getContext());
106
+ });
107
+ ipcMain.handle(`${channelPrefix}:messages:deleteAfter`, async (_event, sessionId, timestamp) => {
108
+ await storage.deleteMessagesAfter(sessionId, new Date(timestamp), getContext());
109
+ return { success: true };
110
+ });
111
+ ipcMain.handle(`${channelPrefix}:operations:list`, async (_event, sessionId) => {
112
+ return storage.getOperations(sessionId, getContext());
113
+ });
114
+ ipcMain.handle(`${channelPrefix}:trash:list`, async () => {
115
+ return storage.getTrashItems?.(getContext()) || [];
116
+ });
117
+ ipcMain.handle(`${channelPrefix}:trash:restore`, async (_event, id) => {
118
+ return storage.restoreFromTrash?.(id, getContext());
119
+ });
120
+ return { agent, storage };
121
+ }
122
+ export {
123
+ AVAILABLE_MODELS,
124
+ createElectronBridge
125
+ };
@@ -0,0 +1,68 @@
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/preload/index.ts
21
+ var preload_exports = {};
22
+ __export(preload_exports, {
23
+ exposeElectronBridge: () => exposeElectronBridge
24
+ });
25
+ module.exports = __toCommonJS(preload_exports);
26
+ var import_electron = require("electron");
27
+ function exposeElectronBridge(options = {}) {
28
+ const { channelPrefix = "ai-chat", exposeName = "aiChatBridge" } = options;
29
+ const bridge = {
30
+ // ============ Chat API ============
31
+ getModels: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:models`),
32
+ send: (params) => import_electron.ipcRenderer.invoke(`${channelPrefix}:send`, params),
33
+ cancel: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:cancel`),
34
+ clearAgentHistory: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:clearAgentHistory`),
35
+ getAgentHistory: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:agentHistory`),
36
+ setWorkingDir: (dir) => import_electron.ipcRenderer.invoke(`${channelPrefix}:setWorkingDir`, dir),
37
+ getConfig: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:config`),
38
+ onProgress: (callback) => {
39
+ const handler = (_event, progress) => {
40
+ callback(progress);
41
+ };
42
+ import_electron.ipcRenderer.on(`${channelPrefix}:progress`, handler);
43
+ return () => {
44
+ import_electron.ipcRenderer.removeListener(`${channelPrefix}:progress`, handler);
45
+ };
46
+ },
47
+ // ============ Sessions API ============
48
+ getSessions: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:sessions:list`),
49
+ getSession: (id) => import_electron.ipcRenderer.invoke(`${channelPrefix}:sessions:get`, id),
50
+ createSession: (params) => import_electron.ipcRenderer.invoke(`${channelPrefix}:sessions:create`, params || {}),
51
+ updateSession: (id, data) => import_electron.ipcRenderer.invoke(`${channelPrefix}:sessions:update`, id, data),
52
+ deleteSession: (id) => import_electron.ipcRenderer.invoke(`${channelPrefix}:sessions:delete`, id),
53
+ // ============ Messages API ============
54
+ getMessages: (sessionId) => import_electron.ipcRenderer.invoke(`${channelPrefix}:messages:list`, sessionId),
55
+ saveMessage: (params) => import_electron.ipcRenderer.invoke(`${channelPrefix}:messages:save`, params),
56
+ deleteMessagesAfter: (sessionId, timestamp) => import_electron.ipcRenderer.invoke(`${channelPrefix}:messages:deleteAfter`, sessionId, timestamp),
57
+ // ============ Operations API ============
58
+ getOperations: (sessionId) => import_electron.ipcRenderer.invoke(`${channelPrefix}:operations:list`, sessionId),
59
+ // ============ Trash API ============
60
+ getTrashItems: () => import_electron.ipcRenderer.invoke(`${channelPrefix}:trash:list`),
61
+ restoreFromTrash: (id) => import_electron.ipcRenderer.invoke(`${channelPrefix}:trash:restore`, id)
62
+ };
63
+ import_electron.contextBridge.exposeInMainWorld(exposeName, bridge);
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ exposeElectronBridge
68
+ });
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Electron Preload 桥接
3
+ *
4
+ * 在 preload 脚本中调用,暴露 API 给渲染进程
5
+ */
6
+ /** 发送消息参数 */
7
+ interface SendMessageParams {
8
+ message: string;
9
+ images?: string[];
10
+ sessionId?: string;
11
+ options?: {
12
+ mode?: string;
13
+ model?: string;
14
+ provider?: string;
15
+ enableWebSearch?: boolean;
16
+ thinkingMode?: string;
17
+ thinkingBudget?: number;
18
+ };
19
+ }
20
+ /** 模型配置 */
21
+ interface ModelConfig {
22
+ provider: string;
23
+ model: string;
24
+ displayName: string;
25
+ supportsTools: boolean;
26
+ supportsWebSearch: boolean;
27
+ supportedThinkingModes: string[];
28
+ }
29
+ /** 会话记录 */
30
+ interface SessionRecord {
31
+ id: string;
32
+ appId: string | null;
33
+ userId: string | null;
34
+ title: string;
35
+ model: string;
36
+ mode: 'agent' | 'plan' | 'ask';
37
+ createdAt: Date;
38
+ updatedAt: Date;
39
+ }
40
+ /** 消息记录 */
41
+ interface MessageRecord {
42
+ id: string;
43
+ sessionId: string;
44
+ role: 'user' | 'assistant';
45
+ content: string;
46
+ thinking?: string | null;
47
+ toolCalls?: string | null;
48
+ searchResults?: string | null;
49
+ operationIds?: string | null;
50
+ timestamp: Date;
51
+ }
52
+ /** 操作记录 */
53
+ interface OperationRecord {
54
+ id: string;
55
+ sessionId: string;
56
+ messageId?: string | null;
57
+ command: string;
58
+ operationType: string;
59
+ affectedFiles: string;
60
+ status: string;
61
+ timestamp: Date;
62
+ }
63
+ /** 回收站记录 */
64
+ interface TrashRecord {
65
+ id: string;
66
+ sessionId: string;
67
+ originalPath: string;
68
+ trashPath: string;
69
+ deletedAt: Date;
70
+ autoDeleteAt: Date;
71
+ }
72
+ interface AiChatBridge {
73
+ /** 获取可用模型 */
74
+ getModels(): Promise<ModelConfig[]>;
75
+ /** 发送消息 */
76
+ send(params: SendMessageParams): Promise<void>;
77
+ /** 取消当前请求 */
78
+ cancel(): Promise<void>;
79
+ /** 清空 Agent 内存历史 */
80
+ clearAgentHistory(): Promise<void>;
81
+ /** 获取 Agent 内存历史 */
82
+ getAgentHistory(): Promise<unknown[]>;
83
+ /** 设置工作目录 */
84
+ setWorkingDir(dir: string): Promise<void>;
85
+ /** 获取配置 */
86
+ getConfig(): Promise<unknown>;
87
+ /** 监听进度事件 */
88
+ onProgress(callback: (progress: unknown) => void): () => void;
89
+ /** 获取会话列表 */
90
+ getSessions(): Promise<SessionRecord[]>;
91
+ /** 获取单个会话 */
92
+ getSession(id: string): Promise<SessionRecord | null>;
93
+ /** 创建会话 */
94
+ createSession(params?: {
95
+ title?: string;
96
+ model?: string;
97
+ mode?: string;
98
+ }): Promise<SessionRecord>;
99
+ /** 更新会话 */
100
+ updateSession(id: string, data: {
101
+ title?: string;
102
+ model?: string;
103
+ mode?: string;
104
+ }): Promise<SessionRecord | null>;
105
+ /** 删除会话 */
106
+ deleteSession(id: string): Promise<{
107
+ success: boolean;
108
+ }>;
109
+ /** 获取会话消息 */
110
+ getMessages(sessionId: string): Promise<MessageRecord[]>;
111
+ /** 保存消息 */
112
+ saveMessage(params: {
113
+ sessionId: string;
114
+ role: 'user' | 'assistant';
115
+ content: string;
116
+ thinking?: string;
117
+ toolCalls?: string;
118
+ searchResults?: string;
119
+ operationIds?: string;
120
+ }): Promise<MessageRecord>;
121
+ /** 删除指定时间之后的消息(用于分叉) */
122
+ deleteMessagesAfter(sessionId: string, timestamp: number): Promise<{
123
+ success: boolean;
124
+ }>;
125
+ /** 获取操作日志 */
126
+ getOperations(sessionId: string): Promise<OperationRecord[]>;
127
+ /** 获取回收站 */
128
+ getTrashItems(): Promise<TrashRecord[]>;
129
+ /** 恢复回收站项目 */
130
+ restoreFromTrash(id: string): Promise<TrashRecord | undefined>;
131
+ }
132
+ interface ExposeOptions {
133
+ /** IPC channel 前缀 */
134
+ channelPrefix?: string;
135
+ /** 暴露的全局变量名 */
136
+ exposeName?: string;
137
+ }
138
+ /**
139
+ * 暴露 AI Chat API 给渲染进程
140
+ */
141
+ declare function exposeElectronBridge(options?: ExposeOptions): void;
142
+
143
+ export { type AiChatBridge, type ExposeOptions, exposeElectronBridge };