@huyooo/ai-chat-bridge-electron 0.2.44 → 0.3.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,112 @@
1
+ /**
2
+ * 火山引擎大模型流式语音识别 - WebSocket 客户端
3
+ *
4
+ * 在 Electron 主进程中运行,处理与火山引擎 ASR 服务的通信
5
+ */
6
+ import { type AsrResult } from './protocol';
7
+ /** ASR 客户端配置 */
8
+ export interface AsrClientConfig {
9
+ /** 火山引擎 App ID */
10
+ appId: string;
11
+ /** 火山引擎 Access Key */
12
+ accessKey: string;
13
+ /** 资源 ID */
14
+ resourceId?: string;
15
+ /** 使用双向流式优化版 */
16
+ useAsyncMode?: boolean;
17
+ }
18
+ /** ASR 事件回调 */
19
+ export interface AsrCallbacks {
20
+ /** 连接成功 */
21
+ onConnected?: () => void;
22
+ /** 收到识别结果 */
23
+ onResult?: (result: AsrResult, isLast: boolean) => void;
24
+ /** 发生错误 */
25
+ onError?: (error: Error) => void;
26
+ /** 连接关闭 */
27
+ onClose?: () => void;
28
+ }
29
+ /** ASR 会话配置 */
30
+ export interface AsrSessionConfig {
31
+ /** 音频格式 */
32
+ format?: 'pcm' | 'wav';
33
+ /** 采样率 */
34
+ sampleRate?: number;
35
+ /** 启用标点 */
36
+ enablePunc?: boolean;
37
+ /** 启用 ITN(数字规整) */
38
+ enableItn?: boolean;
39
+ /** 启用语义顺滑 */
40
+ enableDdc?: boolean;
41
+ /** 输出分句信息 */
42
+ showUtterances?: boolean;
43
+ }
44
+ /**
45
+ * ASR WebSocket 客户端
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const client = new AsrClient({
50
+ * appId: 'your-app-id',
51
+ * accessKey: 'your-access-key',
52
+ * });
53
+ *
54
+ * await client.connect({
55
+ * onResult: (result, isLast) => {
56
+ * console.log('识别结果:', result.result?.text);
57
+ * },
58
+ * onError: (error) => {
59
+ * console.error('错误:', error);
60
+ * },
61
+ * });
62
+ *
63
+ * client.sendAudio(audioBuffer);
64
+ * client.finish(); // 发送最后一包
65
+ * ```
66
+ */
67
+ export declare class AsrClient {
68
+ private config;
69
+ private ws;
70
+ private callbacks;
71
+ private connectId;
72
+ private isConnected;
73
+ private sessionConfig;
74
+ constructor(config: AsrClientConfig);
75
+ /**
76
+ * 获取 WebSocket 连接地址
77
+ */
78
+ private getWsUrl;
79
+ /**
80
+ * 获取资源 ID
81
+ */
82
+ private getResourceId;
83
+ /**
84
+ * 连接到 ASR 服务
85
+ */
86
+ connect(callbacks: AsrCallbacks, sessionConfig?: AsrSessionConfig): Promise<void>;
87
+ /**
88
+ * 发送首包(Full Client Request)
89
+ */
90
+ private sendFullClientRequest;
91
+ /**
92
+ * 发送音频数据
93
+ * @param audioData PCM 音频数据(16bit, 16kHz, 单声道)
94
+ */
95
+ sendAudio(audioData: Buffer): void;
96
+ /**
97
+ * 发送最后一包并结束识别
98
+ */
99
+ finish(): void;
100
+ /**
101
+ * 断开连接
102
+ */
103
+ disconnect(): void;
104
+ /**
105
+ * 检查是否已连接
106
+ */
107
+ get connected(): boolean;
108
+ }
109
+ /**
110
+ * 创建 ASR 客户端实例
111
+ */
112
+ export declare function createAsrClient(config: AsrClientConfig): AsrClient;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * ASR 模块导出
3
+ */
4
+ export * from './protocol';
5
+ export * from './client';
6
+ /** ASR 桥接配置 */
7
+ export interface AsrBridgeConfig {
8
+ /** IPC channel 前缀 */
9
+ channelPrefix?: string;
10
+ /** 火山引擎 App ID */
11
+ appId: string;
12
+ /** 火山引擎 Access Key */
13
+ accessKey: string;
14
+ /** 资源 ID */
15
+ resourceId?: string;
16
+ }
17
+ /**
18
+ * 创建 ASR Electron 桥接
19
+ *
20
+ * 在主进程中调用,注册 ASR 相关的 IPC handlers
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { createAsrBridge } from '@huyooo/ai-chat-bridge-electron/main';
25
+ *
26
+ * createAsrBridge({
27
+ * appId: process.env.VOLC_APP_ID!,
28
+ * accessKey: process.env.VOLC_ACCESS_KEY!,
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function createAsrBridge(config: AsrBridgeConfig): {
33
+ /** 清理所有会话 */
34
+ cleanup: () => void;
35
+ };
@@ -0,0 +1,135 @@
1
+ /**
2
+ * 火山引擎大模型流式语音识别 - 二进制协议编解码
3
+ *
4
+ * 协议结构:
5
+ * - Header (4 bytes)
6
+ * - [Sequence (4 bytes, optional)]
7
+ * - Payload size (4 bytes)
8
+ * - Payload (variable)
9
+ */
10
+ /** 消息类型 */
11
+ export declare const MessageType: {
12
+ /** 客户端发送:包含请求参数的完整请求 */
13
+ readonly FULL_CLIENT_REQUEST: 1;
14
+ /** 客户端发送:仅包含音频数据 */
15
+ readonly AUDIO_ONLY_REQUEST: 2;
16
+ /** 服务端响应:包含识别结果 */
17
+ readonly FULL_SERVER_RESPONSE: 9;
18
+ /** 服务端响应:错误消息 */
19
+ readonly ERROR_RESPONSE: 15;
20
+ };
21
+ /** 消息类型特定标志 */
22
+ export declare const MessageFlags: {
23
+ /** 无特殊标志 */
24
+ readonly NONE: 0;
25
+ /** header 后 4 字节为正 sequence number */
26
+ readonly HAS_SEQUENCE: 1;
27
+ /** 最后一包(负包) */
28
+ readonly LAST_PACKET: 2;
29
+ /** 最后一包且有 sequence number */
30
+ readonly LAST_PACKET_WITH_SEQUENCE: 3;
31
+ };
32
+ /** 序列化方法 */
33
+ export declare const SerializationMethod: {
34
+ readonly NONE: 0;
35
+ readonly JSON: 1;
36
+ };
37
+ /** 压缩方法 */
38
+ export declare const CompressionMethod: {
39
+ readonly NONE: 0;
40
+ readonly GZIP: 1;
41
+ };
42
+ /** ASR 请求配置 */
43
+ export interface AsrRequestConfig {
44
+ /** 用户相关配置 */
45
+ user?: {
46
+ uid?: string;
47
+ did?: string;
48
+ platform?: string;
49
+ sdk_version?: string;
50
+ app_version?: string;
51
+ };
52
+ /** 音频配置 */
53
+ audio: {
54
+ format: 'pcm' | 'wav' | 'ogg' | 'mp3';
55
+ codec?: 'raw' | 'opus';
56
+ rate?: number;
57
+ bits?: number;
58
+ channel?: number;
59
+ /** 语种(仅流式输入模式支持) */
60
+ language?: string;
61
+ };
62
+ /** 请求配置 */
63
+ request: {
64
+ model_name: 'bigmodel';
65
+ /** 启用 ITN(数字规整) */
66
+ enable_itn?: boolean;
67
+ /** 启用标点 */
68
+ enable_punc?: boolean;
69
+ /** 启用语义顺滑 */
70
+ enable_ddc?: boolean;
71
+ /** 输出语音停顿、分句、分词信息 */
72
+ show_utterances?: boolean;
73
+ /** 结果返回方式:full(全量)/single(增量) */
74
+ result_type?: 'full' | 'single';
75
+ /** 启用首字返回加速 */
76
+ enable_accelerate_text?: boolean;
77
+ /** 首字返回加速率 (0-20) */
78
+ accelerate_score?: number;
79
+ /** 语义切句最大静音阈值 (ms) */
80
+ vad_segment_duration?: number;
81
+ /** 强制判停时间 (ms) */
82
+ end_window_size?: number;
83
+ /** 热词等语料配置 */
84
+ corpus?: {
85
+ boosting_table_name?: string;
86
+ boosting_table_id?: string;
87
+ correct_table_name?: string;
88
+ correct_table_id?: string;
89
+ context?: string;
90
+ };
91
+ };
92
+ }
93
+ /** ASR 识别结果 */
94
+ export interface AsrResult {
95
+ result?: {
96
+ text: string;
97
+ utterances?: Array<{
98
+ text: string;
99
+ start_time: number;
100
+ end_time: number;
101
+ definite: boolean;
102
+ words?: Array<{
103
+ text: string;
104
+ start_time: number;
105
+ end_time: number;
106
+ blank_duration: number;
107
+ }>;
108
+ }>;
109
+ };
110
+ audio_info?: {
111
+ duration: number;
112
+ };
113
+ }
114
+ /** 服务端响应 */
115
+ export interface ServerResponse {
116
+ type: 'result' | 'error';
117
+ sequence?: number;
118
+ isLast: boolean;
119
+ data: AsrResult | {
120
+ code: number;
121
+ message: string;
122
+ };
123
+ }
124
+ /**
125
+ * 编码 Full Client Request(首包)
126
+ */
127
+ export declare function encodeFullClientRequest(config: AsrRequestConfig, useGzip?: boolean): Buffer;
128
+ /**
129
+ * 编码 Audio Only Request(音频包)
130
+ */
131
+ export declare function encodeAudioOnlyRequest(audioData: Buffer, isLast?: boolean, useGzip?: boolean): Buffer;
132
+ /**
133
+ * 解码服务端响应
134
+ */
135
+ export declare function decodeServerResponse(data: Buffer): ServerResponse;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * createElectronChat - Electron 平台声明式 AI Chat 入口
3
+ *
4
+ * 将 AssetManager + ElectronBridge + ASR 合并为一次配置调用。
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { createElectronChat } from '@huyooo/ai-chat-bridge-electron/main';
9
+ * import Database from 'better-sqlite3';
10
+ *
11
+ * const chat = await createElectronChat({
12
+ * dataDir: app.getPath('userData'),
13
+ * sqliteFactory: (sqlitePath) => new Database(sqlitePath),
14
+ * llm: { models: { ... } },
15
+ * tools: [
16
+ * tavilySearchTool(API_KEY),
17
+ * getWeatherTool(),
18
+ * ],
19
+ * asr: { appId: '...', accessKey: '...' },
20
+ * });
21
+ * ```
22
+ */
23
+ import type { LLMConfig, Tool, ToolPlugin, ChatOptions, DataEngineContext } from '@huyooo/ai-chat-core';
24
+ import type { StorageContext, StorageAdapter, SqliteDatabaseFactory } from '@huyooo/ai-chat-storage';
25
+ import { type AssetManager, type AssetMetadataStore } from '@huyooo/ai-chat-host-node';
26
+ /** ASR 语音识别配置 */
27
+ export interface AsrConfig {
28
+ appId: string;
29
+ accessKey: string;
30
+ resourceId?: string;
31
+ }
32
+ /**
33
+ * Electron AI Chat 配置
34
+ *
35
+ * 平台无关字段:llm, tools(由 ai-chat-core 定义类型)
36
+ * Electron 特有字段:dataDir, assetsDir, metadataStore, asr, channelPrefix
37
+ */
38
+ export interface ElectronChatConfig {
39
+ /**
40
+ * 应用数据根目录
41
+ *
42
+ * 内部结构(可被 assetsDir 覆盖):
43
+ * dataDir/data/ → SQLite + 搜索索引
44
+ * dataDir/assets/skills/ → 技能文件夹
45
+ * dataDir/assets/skills-state.json → 技能启用状态(默认)
46
+ */
47
+ dataDir: string;
48
+ /** 资产文件目录,默认 dataDir/assets */
49
+ assetsDir?: string;
50
+ /** 元数据存储(技能启用状态等),不传则用 skills-state.json */
51
+ metadataStore?: AssetMetadataStore;
52
+ /** LLM 模型配置 */
53
+ llm: LLMConfig;
54
+ /** 最大模型轮次(可选,默认不限制) */
55
+ maxIterations?: number;
56
+ /** 最大总执行时长,单位毫秒(可选,默认不限制) */
57
+ maxDurationMs?: number;
58
+ /** 最大工具调用次数(可选,默认不限制) */
59
+ maxToolCalls?: number;
60
+ /** 最大累计 token 数(可选,默认不限制) */
61
+ maxTotalTokens?: number;
62
+ /** 代码级工具(Agent 启动即可用) */
63
+ tools?: (Tool | ToolPlugin)[];
64
+ /** 预加载的工具引用(支持 id / alias / 原始名称) */
65
+ preloadTools?: string[] | true;
66
+ /** ASR 语音识别(可选) */
67
+ asr?: AsrConfig;
68
+ /** IPC channel 前缀,默认 'ai-chat' */
69
+ channelPrefix?: string;
70
+ /** 当前工作目录 */
71
+ cwd?: string;
72
+ /** 默认租户上下文 */
73
+ defaultContext?: StorageContext;
74
+ /** 宿主提供的 better-sqlite3 工厂 */
75
+ sqliteFactory: SqliteDatabaseFactory;
76
+ /** 发送消息前钩子 */
77
+ beforeChat?: (options: ChatOptions) => ChatOptions | Promise<ChatOptions>;
78
+ /** 宿主应用注入的数据引擎接口(可选,传递给 ToolContext.dataEngine) */
79
+ dataEngine?: DataEngineContext;
80
+ }
81
+ /** createElectronChat 返回值 */
82
+ export interface ElectronChat {
83
+ /** ChatRuntime 实例 */
84
+ agent: unknown;
85
+ /** 持久化存储 */
86
+ storage: StorageAdapter;
87
+ /** 统一资产管理器 */
88
+ assetManager: AssetManager;
89
+ }
90
+ /**
91
+ * 创建 Electron AI Chat 实例(声明式一步到位)
92
+ *
93
+ * 内部自动完成:
94
+ * 1. assetManager(工具注册 + 技能扫描 + 预加载)
95
+ * 2. createElectronBridge(Agent + IPC + Storage)
96
+ * 3. manager.bind(agent)(运行时工具注入)
97
+ * 4. createAsrBridge(语音识别,可选)
98
+ * 5. 技能内容自动注入 system prompt(通过 beforeChat 组合)
99
+ */
100
+ export declare function createElectronChat(config: ElectronChatConfig): Promise<ElectronChat>;
@@ -1,169 +1,13 @@
1
- import { AgentConfig, ToolConfigItem, ChatOptions, HybridAgent } from '@huyooo/ai-chat-core';
2
- export { AgentConfig, ChatEvent, ChatMode, ChatOptions, MODELS, ProviderType } 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
- /** ASR 请求配置 */
7
- interface AsrRequestConfig {
8
- /** 用户相关配置 */
9
- user?: {
10
- uid?: string;
11
- did?: string;
12
- platform?: string;
13
- sdk_version?: string;
14
- app_version?: string;
15
- };
16
- /** 音频配置 */
17
- audio: {
18
- format: 'pcm' | 'wav' | 'ogg' | 'mp3';
19
- codec?: 'raw' | 'opus';
20
- rate?: number;
21
- bits?: number;
22
- channel?: number;
23
- /** 语种(仅流式输入模式支持) */
24
- language?: string;
25
- };
26
- /** 请求配置 */
27
- request: {
28
- model_name: 'bigmodel';
29
- /** 启用 ITN(数字规整) */
30
- enable_itn?: boolean;
31
- /** 启用标点 */
32
- enable_punc?: boolean;
33
- /** 启用语义顺滑 */
34
- enable_ddc?: boolean;
35
- /** 输出语音停顿、分句、分词信息 */
36
- show_utterances?: boolean;
37
- /** 结果返回方式:full(全量)/single(增量) */
38
- result_type?: 'full' | 'single';
39
- /** 启用首字返回加速 */
40
- enable_accelerate_text?: boolean;
41
- /** 首字返回加速率 (0-20) */
42
- accelerate_score?: number;
43
- /** 语义切句最大静音阈值 (ms) */
44
- vad_segment_duration?: number;
45
- /** 强制判停时间 (ms) */
46
- end_window_size?: number;
47
- /** 热词等语料配置 */
48
- corpus?: {
49
- boosting_table_name?: string;
50
- boosting_table_id?: string;
51
- correct_table_name?: string;
52
- correct_table_id?: string;
53
- context?: string;
54
- };
55
- };
56
- }
57
- /** ASR 识别结果 */
58
- interface AsrResult {
59
- result?: {
60
- text: string;
61
- utterances?: Array<{
62
- text: string;
63
- start_time: number;
64
- end_time: number;
65
- definite: boolean;
66
- words?: Array<{
67
- text: string;
68
- start_time: number;
69
- end_time: number;
70
- blank_duration: number;
71
- }>;
72
- }>;
73
- };
74
- audio_info?: {
75
- duration: number;
76
- };
77
- }
78
-
79
- /**
80
- * 火山引擎大模型流式语音识别 - WebSocket 客户端
81
- *
82
- * 在 Electron 主进程中运行,处理与火山引擎 ASR 服务的通信
83
- */
84
-
85
- /** ASR 客户端配置 */
86
- interface AsrClientConfig {
87
- /** 火山引擎 App ID */
88
- appId: string;
89
- /** 火山引擎 Access Key */
90
- accessKey: string;
91
- /** 资源 ID */
92
- resourceId?: string;
93
- /** 使用双向流式优化版 */
94
- useAsyncMode?: boolean;
95
- }
96
- /** ASR 事件回调 */
97
- interface AsrCallbacks {
98
- /** 连接成功 */
99
- onConnected?: () => void;
100
- /** 收到识别结果 */
101
- onResult?: (result: AsrResult, isLast: boolean) => void;
102
- /** 发生错误 */
103
- onError?: (error: Error) => void;
104
- /** 连接关闭 */
105
- onClose?: () => void;
106
- }
107
- /** ASR 会话配置 */
108
- interface AsrSessionConfig {
109
- /** 音频格式 */
110
- format?: 'pcm' | 'wav';
111
- /** 采样率 */
112
- sampleRate?: number;
113
- /** 启用标点 */
114
- enablePunc?: boolean;
115
- /** 启用 ITN(数字规整) */
116
- enableItn?: boolean;
117
- /** 启用语义顺滑 */
118
- enableDdc?: boolean;
119
- /** 输出分句信息 */
120
- showUtterances?: boolean;
121
- }
122
-
123
- /**
124
- * ASR 模块导出
125
- */
126
-
127
- /** ASR 桥接配置 */
128
- interface AsrBridgeConfig {
129
- /** IPC channel 前缀 */
130
- channelPrefix?: string;
131
- /** 火山引擎 App ID */
132
- appId: string;
133
- /** 火山引擎 Access Key */
134
- accessKey: string;
135
- /** 资源 ID */
136
- resourceId?: string;
137
- }
138
- /**
139
- * 创建 ASR Electron 桥接
140
- *
141
- * 在主进程中调用,注册 ASR 相关的 IPC handlers
142
- *
143
- * @example
144
- * ```ts
145
- * import { createAsrBridge } from '@huyooo/ai-chat-bridge-electron/main';
146
- *
147
- * createAsrBridge({
148
- * appId: process.env.VOLC_APP_ID!,
149
- * accessKey: process.env.VOLC_ACCESS_KEY!,
150
- * });
151
- * ```
152
- */
153
- declare function createAsrBridge(config: AsrBridgeConfig): {
154
- /** 清理所有会话 */
155
- cleanup: () => void;
156
- };
157
-
158
1
  /**
159
2
  * Electron 主进程桥接
160
3
  *
161
4
  * 在主进程中调用,注册 IPC handlers
162
5
  * 集成 SQLite 存储
163
6
  */
164
-
7
+ import { ChatRuntime, buildModelOptions, type LLMConfig, type ChatEvent, type ChatOptions, type ChatMode, type ProtocolId, type ToolConfigItem, type ModelOption, type McpServerConfig, type DataEngineContext, type ToolExecutionAuditHooks } from '@huyooo/ai-chat-core';
8
+ import type { AtResolvedFileContext } from '@huyooo/ai-chat-types';
165
9
  /** 文件信息 */
166
- interface FileInfo {
10
+ export interface FileInfo {
167
11
  name: string;
168
12
  path: string;
169
13
  isDirectory: boolean;
@@ -171,12 +15,22 @@ interface FileInfo {
171
15
  modifiedAt: Date;
172
16
  extension: string;
173
17
  }
174
-
175
- interface ElectronBridgeOptions extends Omit<AgentConfig, 'tools'> {
18
+ import { type StorageAdapter, type StorageContext, type SqliteDatabaseFactory, type SessionRecord, type MessageRecord } from '@huyooo/ai-chat-storage';
19
+ export interface ElectronBridgeOptions {
20
+ /** 统一 LLM 配置(endpoints + models 降级链) */
21
+ llmConfig: LLMConfig;
22
+ /** 当前工作目录 */
23
+ cwd?: string;
24
+ /** 最大模型轮次(可选,默认不限制) */
25
+ maxIterations?: number;
26
+ /** 最大总执行时长,单位毫秒(可选,默认不限制) */
27
+ maxDurationMs?: number;
28
+ /** 最大工具调用次数(可选,默认不限制) */
29
+ maxToolCalls?: number;
30
+ /** 最大累计 token 数(可选,默认不限制) */
31
+ maxTotalTokens?: number;
176
32
  /** IPC channel 前缀 */
177
33
  channelPrefix?: string;
178
- /** Tavily API Key(用于统一 Web Search;可选) */
179
- tavilyApiKey?: string;
180
34
  /**
181
35
  * 统一数据目录(必填)
182
36
  * 所有数据都存储在此目录下:
@@ -186,16 +40,75 @@ interface ElectronBridgeOptions extends Omit<AgentConfig, 'tools'> {
186
40
  dataDir: string;
187
41
  /** 默认租户上下文 */
188
42
  defaultContext?: StorageContext;
43
+ /** 宿主提供的 better-sqlite3 工厂 */
44
+ sqliteFactory: SqliteDatabaseFactory;
189
45
  /**
190
46
  * 工具列表(Vite 插件风格)
191
47
  * 支持:ToolPlugin、Promise<ToolPlugin>
192
48
  */
193
49
  tools?: ToolConfigItem[];
50
+ /**
51
+ * 外部 MCP Server(stdio / HTTP 等),由 ChatRuntime 连接并注册工具到会话
52
+ */
53
+ mcpServers?: McpServerConfig[];
194
54
  /**
195
55
  * 发送消息前的钩子(可注入额外 options,如本地 Skills 内容)
196
56
  * 返回修改后的 options,或 undefined 保持不变
197
57
  */
198
58
  beforeChat?: (options: ChatOptions) => ChatOptions | Promise<ChatOptions>;
59
+ /** 宿主应用注入的数据引擎接口(可选,传递给 ToolContext.dataEngine) */
60
+ dataEngine?: DataEngineContext;
61
+ /** 宿主应用注入的审计钩子(可选,桥接层只负责传递会话/请求边界) */
62
+ audit?: {
63
+ startTurn(input: {
64
+ conversationId?: string | null;
65
+ model?: string | null;
66
+ mode?: string | null;
67
+ userMessage?: string | null;
68
+ metadata?: Record<string, unknown>;
69
+ }): string;
70
+ finishTurn(input: {
71
+ turnId: string;
72
+ eventCount?: number;
73
+ completedAt?: string;
74
+ }): void;
75
+ failTurn(input: {
76
+ turnId: string;
77
+ eventCount?: number;
78
+ completedAt?: string;
79
+ error: unknown;
80
+ }): void;
81
+ runWithContext<T>(context: {
82
+ conversationId?: string | null;
83
+ turnId?: string | null;
84
+ }, fn: () => T): T;
85
+ recordToolApprovalRequest?(input: {
86
+ id: string;
87
+ name: string;
88
+ toolName?: string | null;
89
+ extensionId?: string | null;
90
+ displayName?: string | null;
91
+ args: Record<string, unknown>;
92
+ context?: {
93
+ conversationId?: string | null;
94
+ turnId?: string | null;
95
+ };
96
+ }): void;
97
+ recordToolApprovalResponse?(input: {
98
+ id: string;
99
+ name?: string | null;
100
+ toolName?: string | null;
101
+ extensionId?: string | null;
102
+ displayName?: string | null;
103
+ approved: boolean;
104
+ context?: {
105
+ conversationId?: string | null;
106
+ turnId?: string | null;
107
+ };
108
+ }): void;
109
+ } & ToolExecutionAuditHooks;
110
+ /** 宿主提供的 @ 文件上下文解析器(可选,用于 PDF/Docx/Notebook 等高级解析) */
111
+ resolveAtFileContext?: (filePath: string) => Promise<AtResolvedFileContext | null>;
199
112
  }
200
113
  /**
201
114
  * 创建 Electron IPC 桥接
@@ -206,15 +119,21 @@ interface ElectronBridgeOptions extends Omit<AgentConfig, 'tools'> {
206
119
  *
207
120
  * app.whenReady().then(async () => {
208
121
  * const { agent, storage } = await createElectronBridge({
209
- * arkApiKey: 'xxx',
210
- * geminiApiKey: 'xxx',
122
+ * llmConfig: { endpoints: {...}, models: {...} },
123
+ * dataDir: '/path/to/data',
124
+ * sqliteFactory: (sqlitePath) => new Database(sqlitePath),
211
125
  * });
212
126
  * });
213
127
  * ```
214
128
  */
215
- declare function createElectronBridge(options: ElectronBridgeOptions): Promise<{
216
- agent: HybridAgent;
129
+ export declare function createElectronBridge(options: ElectronBridgeOptions): Promise<{
130
+ agent: ChatRuntime;
217
131
  storage: StorageAdapter;
218
132
  }>;
219
-
220
- export { type AsrBridgeConfig, type AsrCallbacks, type AsrClientConfig, type AsrRequestConfig, type AsrResult, type AsrSessionConfig, type ElectronBridgeOptions, type FileInfo, createAsrBridge, createElectronBridge };
133
+ export type { LLMConfig, ChatEvent, ChatOptions, ChatMode, ProtocolId, ModelOption, StorageAdapter, StorageContext, SessionRecord, MessageRecord, };
134
+ export { buildModelOptions };
135
+ export { createAsrBridge, type AsrBridgeConfig } from './asr';
136
+ export type { AsrClientConfig, AsrSessionConfig, AsrCallbacks } from './asr/client';
137
+ export type { AsrResult, AsrRequestConfig } from './asr/protocol';
138
+ export { createElectronChat } from './create-electron-chat';
139
+ export type { ElectronChatConfig, ElectronChat, AsrConfig } from './create-electron-chat';