@h-ai/ai 1.0.0-beta.1 → 1.0.0-beta.10

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.
@@ -3,13 +3,245 @@ import { HaiResult, HaiError } from '@h-ai/core';
3
3
  import { AgentCard } from '@a2a-js/sdk';
4
4
  import { AgentExecutor } from '@a2a-js/sdk/server';
5
5
  import * as zod from 'zod';
6
- import { ZodType, z } from 'zod';
7
- import { e as AudioOperations, a as AudioContent, P as PlayableAudio, b as AudioFormat } from './ai-audio-types-4R5yUAVl.js';
8
- import OpenAI from 'openai';
6
+ import { z, ZodType } from 'zod';
9
7
  import { Buffer } from 'node:buffer';
10
8
  import { CleanOptionsInput, ChunkOptionsInput } from '@h-ai/datapipe';
11
- import { PromptMessage } from '@modelcontextprotocol/sdk/types.js';
9
+ import { e as AudioOperations, a as AudioContent, P as PlayableAudio, b as AudioFormat } from './ai-audio-types-4R5yUAVl.js';
12
10
  import * as zod_v4_core from 'zod/v4/core';
11
+ import * as _agentclientprotocol_sdk from '@agentclientprotocol/sdk';
12
+ import { McpServer, ContentBlock, SessionNotification, ClientRequestHandlersByMethod, ClientCapabilities } from '@agentclientprotocol/sdk';
13
+ import OpenAI from 'openai';
14
+ import { PromptMessage } from '@modelcontextprotocol/sdk/types.js';
15
+
16
+ /**
17
+ * 工程主分支必须显式填写。
18
+ * @example
19
+ * ```ts
20
+ * import { ACPRepositorySchema } from '@h-ai/ai'
21
+ * const repository = ACPRepositorySchema.parse({ id: 'api', url: 'https://example.com/api.git', mainBranch: 'trunk' })
22
+ * ```
23
+ */
24
+ declare const ACPRepositorySchema: z.ZodObject<{
25
+ id: z.ZodString;
26
+ url: z.ZodString;
27
+ mainBranch: z.ZodString;
28
+ remote: z.ZodDefault<z.ZodString>;
29
+ }, z.core.$strict>;
30
+ /**
31
+ * 工作区持久目录或容器卷。
32
+ * @example
33
+ * ```ts
34
+ * import { ACPWorkspaceSchema } from '@h-ai/ai'
35
+ * const workspace = ACPWorkspaceSchema.parse({ id: 'project', storage: { type: 'directory', path: '/srv/project' }, repositories: [] })
36
+ * ```
37
+ */
38
+ declare const ACPWorkspaceSchema: z.ZodObject<{
39
+ id: z.ZodString;
40
+ storage: z.ZodDiscriminatedUnion<[z.ZodObject<{
41
+ type: z.ZodLiteral<"directory">;
42
+ path: z.ZodString;
43
+ }, z.core.$strict>, z.ZodObject<{
44
+ type: z.ZodLiteral<"volume">;
45
+ name: z.ZodString;
46
+ engine: z.ZodDefault<z.ZodEnum<{
47
+ auto: "auto";
48
+ podman: "podman";
49
+ docker: "docker";
50
+ }>>;
51
+ image: z.ZodString;
52
+ }, z.core.$strict>], "type">;
53
+ repositories: z.ZodDefault<z.ZodArray<z.ZodObject<{
54
+ id: z.ZodString;
55
+ url: z.ZodString;
56
+ mainBranch: z.ZodString;
57
+ remote: z.ZodDefault<z.ZodString>;
58
+ }, z.core.$strict>>>;
59
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
60
+ }, z.core.$strict>;
61
+ /**
62
+ * Agent 定义,仅保存凭据引用。
63
+ * @example
64
+ * ```ts
65
+ * import { ACPAgentSchema } from '@h-ai/ai'
66
+ * const agent = ACPAgentSchema.parse({ id: 'coder', name: 'Coder', mode: 'embedded', adapter: 'codex', modelIds: ['coding'], defaultModelId: 'coding' })
67
+ * ```
68
+ */
69
+ declare const ACPAgentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
70
+ mode: z.ZodLiteral<"custom-service">;
71
+ transport: z.ZodEnum<{
72
+ http: "http";
73
+ ws: "ws";
74
+ }>;
75
+ url: z.ZodURL;
76
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
77
+ supportedTransports: z.ZodArray<z.ZodEnum<{
78
+ http: "http";
79
+ ws: "ws";
80
+ }>>;
81
+ id: z.ZodString;
82
+ name: z.ZodString;
83
+ enabled: z.ZodDefault<z.ZodBoolean>;
84
+ adapter: z.ZodDefault<z.ZodString>;
85
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
86
+ defaultModelId: z.ZodOptional<z.ZodString>;
87
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ mode: z.ZodLiteral<"embedded">;
90
+ transport: z.ZodDefault<z.ZodLiteral<"stdio">>;
91
+ command: z.ZodOptional<z.ZodString>;
92
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
93
+ id: z.ZodString;
94
+ name: z.ZodString;
95
+ enabled: z.ZodDefault<z.ZodBoolean>;
96
+ adapter: z.ZodDefault<z.ZodString>;
97
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
98
+ defaultModelId: z.ZodOptional<z.ZodString>;
99
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
100
+ }, z.core.$strict>, z.ZodObject<{
101
+ mode: z.ZodLiteral<"builtin-service">;
102
+ transport: z.ZodDefault<z.ZodLiteral<"stdio">>;
103
+ image: z.ZodString;
104
+ engine: z.ZodDefault<z.ZodEnum<{
105
+ auto: "auto";
106
+ podman: "podman";
107
+ docker: "docker";
108
+ }>>;
109
+ command: z.ZodOptional<z.ZodString>;
110
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
111
+ id: z.ZodString;
112
+ name: z.ZodString;
113
+ enabled: z.ZodDefault<z.ZodBoolean>;
114
+ adapter: z.ZodDefault<z.ZodString>;
115
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
116
+ defaultModelId: z.ZodOptional<z.ZodString>;
117
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
118
+ }, z.core.$strict>], "mode">;
119
+ /**
120
+ * 会话 Git 发布请求。
121
+ * @example
122
+ * ```ts
123
+ * import { ACPPublishSchema } from '@h-ai/ai'
124
+ * const request = ACPPublishSchema.parse({ mode: 'push-branch', message: 'Implement task', author: { name: 'Developer', email: 'developer@example.com' } })
125
+ * ```
126
+ */
127
+ declare const ACPPublishSchema: z.ZodObject<{
128
+ mode: z.ZodEnum<{
129
+ "merge-main": "merge-main";
130
+ "push-branch": "push-branch";
131
+ }>;
132
+ message: z.ZodString;
133
+ author: z.ZodObject<{
134
+ name: z.ZodString;
135
+ email: z.ZodEmail;
136
+ }, z.core.$strict>;
137
+ }, z.core.$strict>;
138
+ /**
139
+ * ACP 执行限制。
140
+ * @example
141
+ * ```ts
142
+ * import { ACPConfigSchema } from '@h-ai/ai'
143
+ * const config = ACPConfigSchema.parse({ promptTimeout: 300000 })
144
+ * ```
145
+ */
146
+ declare const ACPConfigSchema: z.ZodObject<{
147
+ agents: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
148
+ mode: z.ZodLiteral<"custom-service">;
149
+ transport: z.ZodEnum<{
150
+ http: "http";
151
+ ws: "ws";
152
+ }>;
153
+ url: z.ZodURL;
154
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
155
+ supportedTransports: z.ZodArray<z.ZodEnum<{
156
+ http: "http";
157
+ ws: "ws";
158
+ }>>;
159
+ id: z.ZodString;
160
+ name: z.ZodString;
161
+ enabled: z.ZodDefault<z.ZodBoolean>;
162
+ adapter: z.ZodDefault<z.ZodString>;
163
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
164
+ defaultModelId: z.ZodOptional<z.ZodString>;
165
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
166
+ }, z.core.$strict>, z.ZodObject<{
167
+ mode: z.ZodLiteral<"embedded">;
168
+ transport: z.ZodDefault<z.ZodLiteral<"stdio">>;
169
+ command: z.ZodOptional<z.ZodString>;
170
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
171
+ id: z.ZodString;
172
+ name: z.ZodString;
173
+ enabled: z.ZodDefault<z.ZodBoolean>;
174
+ adapter: z.ZodDefault<z.ZodString>;
175
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
176
+ defaultModelId: z.ZodOptional<z.ZodString>;
177
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
178
+ }, z.core.$strict>, z.ZodObject<{
179
+ mode: z.ZodLiteral<"builtin-service">;
180
+ transport: z.ZodDefault<z.ZodLiteral<"stdio">>;
181
+ image: z.ZodString;
182
+ engine: z.ZodDefault<z.ZodEnum<{
183
+ auto: "auto";
184
+ podman: "podman";
185
+ docker: "docker";
186
+ }>>;
187
+ command: z.ZodOptional<z.ZodString>;
188
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
189
+ id: z.ZodString;
190
+ name: z.ZodString;
191
+ enabled: z.ZodDefault<z.ZodBoolean>;
192
+ adapter: z.ZodDefault<z.ZodString>;
193
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
194
+ defaultModelId: z.ZodOptional<z.ZodString>;
195
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
196
+ }, z.core.$strict>], "mode">>>;
197
+ workspaces: z.ZodDefault<z.ZodArray<z.ZodObject<{
198
+ id: z.ZodString;
199
+ storage: z.ZodDiscriminatedUnion<[z.ZodObject<{
200
+ type: z.ZodLiteral<"directory">;
201
+ path: z.ZodString;
202
+ }, z.core.$strict>, z.ZodObject<{
203
+ type: z.ZodLiteral<"volume">;
204
+ name: z.ZodString;
205
+ engine: z.ZodDefault<z.ZodEnum<{
206
+ auto: "auto";
207
+ podman: "podman";
208
+ docker: "docker";
209
+ }>>;
210
+ image: z.ZodString;
211
+ }, z.core.$strict>], "type">;
212
+ repositories: z.ZodDefault<z.ZodArray<z.ZodObject<{
213
+ id: z.ZodString;
214
+ url: z.ZodString;
215
+ mainBranch: z.ZodString;
216
+ remote: z.ZodDefault<z.ZodString>;
217
+ }, z.core.$strict>>>;
218
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
219
+ }, z.core.$strict>>>;
220
+ requestTimeout: z.ZodDefault<z.ZodNumber>;
221
+ promptTimeout: z.ZodDefault<z.ZodNumber>;
222
+ cancelTimeout: z.ZodDefault<z.ZodNumber>;
223
+ maxContentBytes: z.ZodDefault<z.ZodNumber>;
224
+ maxPendingEvents: z.ZodDefault<z.ZodNumber>;
225
+ }, z.core.$strict>;
226
+ /**
227
+ * ACP 初始化配置,已填充超时和只读清单默认值。
228
+ * @example
229
+ * ```ts
230
+ * import { ACPConfigSchema } from '@h-ai/ai'
231
+ * import type { ACPConfig } from '@h-ai/ai'
232
+ * const config: ACPConfig = ACPConfigSchema.parse({ promptTimeout: 300000 })
233
+ * ```
234
+ */
235
+ type ACPConfig = z.output<typeof ACPConfigSchema>;
236
+ /**
237
+ * ACP 初始化输入,省略字段采用 Schema 默认值。
238
+ * @example
239
+ * ```ts
240
+ * import type { ACPConfigInput } from '@h-ai/ai'
241
+ * const config: ACPConfigInput = { promptTimeout: 300000 }
242
+ * ```
243
+ */
244
+ type ACPConfigInput = z.input<typeof ACPConfigSchema>;
13
245
 
14
246
  /**
15
247
  * @h-ai/ai — Store 存储抽象类型
@@ -837,14 +1069,14 @@ type ToolDefinition = OpenAI.Chat.Completions.ChatCompletionTool;
837
1069
  * ```ts
838
1070
  * import type { TempModelConfig } from '@h-ai/ai'
839
1071
  *
840
- * const value: TempModelConfig = { model: 'gpt-4o-mini', api: 'chat', timeout: 15_000 }
1072
+ * const value: TempModelConfig = { model: 'gpt-4o-mini', protocol: 'chat', timeout: 15_000 }
841
1073
  * ```
842
1074
  */
843
1075
  interface TempModelConfig {
844
1076
  /** 模型名称(传给 API 的实际模型名) */
845
1077
  model: string;
846
- /** API 协议(未指定时回退全局 `api`,再回退 `chat`;决定走 Chat Completions / Responses / Anthropic) */
847
- api?: ApiType;
1078
+ /** API 协议(未指定时回退全局 `protocol`,再回退 `chat`;决定走 Chat Completions / Responses / Anthropic) */
1079
+ protocol?: ApiType;
848
1080
  /** API Key(未指定时回退全局配置 / 环境变量) */
849
1081
  apiKey?: string;
850
1082
  /** API 基础 URL(未指定时回退全局配置 / 环境变量 / 默认 OpenAI) */
@@ -3081,13 +3313,6 @@ interface MemoryOperations extends MemoryCoreOperations {
3081
3313
  admin: MemoryAdminOperations;
3082
3314
  }
3083
3315
 
3084
- /**
3085
- * @h-ai/ai — 错误码 + 配置 Schema
3086
- *
3087
- * 定义 AI 模块的错误码常量、Zod Schema 和配置类型。
3088
- * @module ai-config
3089
- */
3090
-
3091
3316
  /**
3092
3317
  * 可选密钥 Schema。
3093
3318
  *
@@ -3139,12 +3364,12 @@ declare const OptionalSecretSchema: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodS
3139
3364
  * ```
3140
3365
  */
3141
3366
  declare const ModelScenarioSchema: z.ZodEnum<{
3367
+ default: "default";
3142
3368
  chat: "chat";
3143
3369
  summary: "summary";
3144
3370
  plan: "plan";
3145
3371
  reasoning: "reasoning";
3146
3372
  ocr: "ocr";
3147
- default: "default";
3148
3373
  execute: "execute";
3149
3374
  extraction: "extraction";
3150
3375
  embedding: "embedding";
@@ -3202,6 +3427,35 @@ declare const ApiTypeSchema: z.ZodEnum<{
3202
3427
  * ```
3203
3428
  */
3204
3429
  type ApiType = z.infer<typeof ApiTypeSchema>;
3430
+ /**
3431
+ * 模型能力元数据;缺省字段表示未知,不从调用预算推断容量。
3432
+ * @example
3433
+ * ```ts
3434
+ * import { ModelCapabilitiesSchema } from '@h-ai/ai'
3435
+ * const capabilities = ModelCapabilitiesSchema.parse({ contextWindow: 128000, toolCalling: true })
3436
+ * ```
3437
+ */
3438
+ declare const ModelCapabilitiesSchema: z.ZodObject<{
3439
+ contextWindow: z.ZodOptional<z.ZodNumber>;
3440
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
3441
+ inputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3442
+ image: "image";
3443
+ audio: "audio";
3444
+ text: "text";
3445
+ video: "video";
3446
+ }>>>;
3447
+ outputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3448
+ image: "image";
3449
+ audio: "audio";
3450
+ text: "text";
3451
+ video: "video";
3452
+ }>>>;
3453
+ toolCalling: z.ZodOptional<z.ZodBoolean>;
3454
+ reasoning: z.ZodOptional<z.ZodObject<{
3455
+ supported: z.ZodBoolean;
3456
+ efforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
3457
+ }, z.core.$strict>>;
3458
+ }, z.core.$strict>;
3205
3459
  /**
3206
3460
  * 模型条目 Schema
3207
3461
  *
@@ -3222,8 +3476,29 @@ type ApiType = z.infer<typeof ApiTypeSchema>;
3222
3476
  */
3223
3477
  declare const ModelEntrySchema: z.ZodObject<{
3224
3478
  id: z.ZodString;
3479
+ capabilities: z.ZodOptional<z.ZodObject<{
3480
+ contextWindow: z.ZodOptional<z.ZodNumber>;
3481
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
3482
+ inputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3483
+ image: "image";
3484
+ audio: "audio";
3485
+ text: "text";
3486
+ video: "video";
3487
+ }>>>;
3488
+ outputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3489
+ image: "image";
3490
+ audio: "audio";
3491
+ text: "text";
3492
+ video: "video";
3493
+ }>>>;
3494
+ toolCalling: z.ZodOptional<z.ZodBoolean>;
3495
+ reasoning: z.ZodOptional<z.ZodObject<{
3496
+ supported: z.ZodBoolean;
3497
+ efforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
3498
+ }, z.core.$strict>>;
3499
+ }, z.core.$strict>>;
3225
3500
  model: z.ZodString;
3226
- api: z.ZodOptional<z.ZodEnum<{
3501
+ protocol: z.ZodOptional<z.ZodEnum<{
3227
3502
  chat: "chat";
3228
3503
  responses: "responses";
3229
3504
  anthropic: "anthropic";
@@ -3233,7 +3508,7 @@ declare const ModelEntrySchema: z.ZodObject<{
3233
3508
  maxTokens: z.ZodOptional<z.ZodNumber>;
3234
3509
  temperature: z.ZodOptional<z.ZodNumber>;
3235
3510
  timeout: z.ZodOptional<z.ZodNumber>;
3236
- }, z.core.$strip>;
3511
+ }, z.core.$strict>;
3237
3512
  /**
3238
3513
  * 模型条目类型
3239
3514
  *
@@ -3273,7 +3548,7 @@ declare const LLMConfigSchema: z.ZodObject<{
3273
3548
  apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
3274
3549
  baseUrl: z.ZodOptional<z.ZodURL>;
3275
3550
  model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
3276
- api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
3551
+ protocol: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
3277
3552
  chat: "chat";
3278
3553
  responses: "responses";
3279
3554
  anthropic: "anthropic";
@@ -3284,8 +3559,29 @@ declare const LLMConfigSchema: z.ZodObject<{
3284
3559
  tempModelCacheTtl: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
3285
3560
  models: z.ZodOptional<z.ZodArray<z.ZodObject<{
3286
3561
  id: z.ZodString;
3562
+ capabilities: z.ZodOptional<z.ZodObject<{
3563
+ contextWindow: z.ZodOptional<z.ZodNumber>;
3564
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
3565
+ inputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3566
+ image: "image";
3567
+ audio: "audio";
3568
+ text: "text";
3569
+ video: "video";
3570
+ }>>>;
3571
+ outputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
3572
+ image: "image";
3573
+ audio: "audio";
3574
+ text: "text";
3575
+ video: "video";
3576
+ }>>>;
3577
+ toolCalling: z.ZodOptional<z.ZodBoolean>;
3578
+ reasoning: z.ZodOptional<z.ZodObject<{
3579
+ supported: z.ZodBoolean;
3580
+ efforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
3581
+ }, z.core.$strict>>;
3582
+ }, z.core.$strict>>;
3287
3583
  model: z.ZodString;
3288
- api: z.ZodOptional<z.ZodEnum<{
3584
+ protocol: z.ZodOptional<z.ZodEnum<{
3289
3585
  chat: "chat";
3290
3586
  responses: "responses";
3291
3587
  anthropic: "anthropic";
@@ -3295,21 +3591,21 @@ declare const LLMConfigSchema: z.ZodObject<{
3295
3591
  maxTokens: z.ZodOptional<z.ZodNumber>;
3296
3592
  temperature: z.ZodOptional<z.ZodNumber>;
3297
3593
  timeout: z.ZodOptional<z.ZodNumber>;
3298
- }, z.core.$strip>>>;
3594
+ }, z.core.$strict>>>;
3299
3595
  scenarios: z.ZodOptional<z.ZodObject<{
3596
+ default: z.ZodOptional<z.ZodString>;
3300
3597
  chat: z.ZodOptional<z.ZodString>;
3301
3598
  summary: z.ZodOptional<z.ZodString>;
3302
3599
  plan: z.ZodOptional<z.ZodString>;
3303
3600
  reasoning: z.ZodOptional<z.ZodString>;
3304
3601
  ocr: z.ZodOptional<z.ZodString>;
3305
- default: z.ZodOptional<z.ZodString>;
3306
3602
  execute: z.ZodOptional<z.ZodString>;
3307
3603
  extraction: z.ZodOptional<z.ZodString>;
3308
3604
  embedding: z.ZodOptional<z.ZodString>;
3309
3605
  rerank: z.ZodOptional<z.ZodString>;
3310
3606
  fast: z.ZodOptional<z.ZodString>;
3311
3607
  }, z.core.$strip>>;
3312
- }, z.core.$strip>;
3608
+ }, z.core.$strict>;
3313
3609
  /**
3314
3610
  * LLM 配置类型
3315
3611
  *
@@ -3333,15 +3629,17 @@ type LLMConfig = z.infer<typeof LLMConfigSchema>;
3333
3629
  *
3334
3630
  * // 展示模型选择,不输出配置中的 apiKey。
3335
3631
  * function label(config: ResolvedModelConfig): string {
3336
- * return `${config.api}/${config.model}, timeout=${config.timeout}ms`
3632
+ * return `${config.protocol}/${config.model}, timeout=${config.timeout}ms`
3337
3633
  * }
3338
3634
  * ```
3339
3635
  */
3340
3636
  interface ResolvedModelConfig {
3637
+ /** 已确认的模型能力 */
3638
+ capabilities?: z.infer<typeof ModelCapabilitiesSchema>;
3341
3639
  /** 模型名称(传给 API 的实际模型名) */
3342
3640
  model: string;
3343
3641
  /** API 协议(模型条目 > 全局配置 > `chat`) */
3344
- api: ApiType;
3642
+ protocol: ApiType;
3345
3643
  /** API Key(模型条目 > 全局配置 > 环境变量) */
3346
3644
  apiKey: string | undefined;
3347
3645
  /** API 基础 URL(模型条目 > 全局配置 > 环境变量 > 默认 OpenAI) */
@@ -3394,8 +3692,8 @@ declare function resolveModelEntry(llmConfig: LLMConfig, scenario: ModelScenario
3394
3692
  /**
3395
3693
  * 解析某次 chat 请求应使用的 API 协议(不校验 API Key)
3396
3694
  *
3397
- * 供 LLM Provider 路由层选择底层实现使用:优先取显式模型条目的 `api`,
3398
- * 其次全局 `api`,最后回退 `chat`。临时模型的 `api` 由调用方单独传入优先。
3695
+ * 供 LLM Provider 路由层选择底层实现使用:优先取显式模型条目的 `protocol`,
3696
+ * 其次全局 `protocol`,最后回退 `chat`。临时模型的 `protocol` 由调用方单独传入优先。
3399
3697
  *
3400
3698
  * @param llmConfig - LLM 配置
3401
3699
  * @param explicitModel - 显式指定的模型名/ID(可选)
@@ -3406,7 +3704,7 @@ declare function resolveModelEntry(llmConfig: LLMConfig, scenario: ModelScenario
3406
3704
  * ```ts
3407
3705
  * import { LLMConfigSchema, resolveModelApi } from '@h-ai/ai'
3408
3706
  *
3409
- * const config = LLMConfigSchema.parse({ models: [{ id: 'claude', model: 'claude-sonnet-4', api: 'anthropic' }] })
3707
+ * const config = LLMConfigSchema.parse({ models: [{ id: 'claude', model: 'claude-sonnet-4', protocol: 'anthropic' }] })
3410
3708
  * const protocol = resolveModelApi(config, 'claude')
3411
3709
  * ```
3412
3710
  */
@@ -3481,6 +3779,37 @@ declare const MCPServerConfigSchema: z.ZodObject<{
3481
3779
  * ```
3482
3780
  */
3483
3781
  type MCPServerConfig = z.infer<typeof MCPServerConfigSchema>;
3782
+ /**
3783
+ * 外部 MCP 服务清单项;凭据仅保存环境变量引用,可供 ACP 会话选择。
3784
+ * @example
3785
+ * ```ts
3786
+ * import { MCPExternalServerSchema } from '@h-ai/ai'
3787
+ * const server = MCPExternalServerSchema.parse({ id: 'docs', name: 'Docs', transport: 'http', url: 'https://mcp.example.com' })
3788
+ * ```
3789
+ */
3790
+ declare const MCPExternalServerSchema: z.ZodObject<{
3791
+ id: z.ZodString;
3792
+ name: z.ZodString;
3793
+ transport: z.ZodEnum<{
3794
+ http: "http";
3795
+ stdio: "stdio";
3796
+ sse: "sse";
3797
+ }>;
3798
+ command: z.ZodOptional<z.ZodString>;
3799
+ args: z.ZodDefault<z.ZodArray<z.ZodString>>;
3800
+ url: z.ZodOptional<z.ZodURL>;
3801
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
3802
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
3803
+ }, z.core.$strict>;
3804
+ /**
3805
+ * 外部 MCP 服务配置。
3806
+ * @example
3807
+ * ```ts
3808
+ * import type { MCPExternalServer } from '@h-ai/ai'
3809
+ * function serverId(server: MCPExternalServer) { return server.id }
3810
+ * ```
3811
+ */
3812
+ type MCPExternalServer = z.infer<typeof MCPExternalServerSchema>;
3484
3813
  /**
3485
3814
  * MCP 配置 Schema
3486
3815
  *
@@ -3500,6 +3829,20 @@ type MCPServerConfig = z.infer<typeof MCPServerConfigSchema>;
3500
3829
  * ```
3501
3830
  */
3502
3831
  declare const MCPConfigSchema: z.ZodObject<{
3832
+ servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
3833
+ id: z.ZodString;
3834
+ name: z.ZodString;
3835
+ transport: z.ZodEnum<{
3836
+ http: "http";
3837
+ stdio: "stdio";
3838
+ sse: "sse";
3839
+ }>;
3840
+ command: z.ZodOptional<z.ZodString>;
3841
+ args: z.ZodDefault<z.ZodArray<z.ZodString>>;
3842
+ url: z.ZodOptional<z.ZodURL>;
3843
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
3844
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
3845
+ }, z.core.$strict>>>;
3503
3846
  server: z.ZodOptional<z.ZodObject<{
3504
3847
  name: z.ZodString;
3505
3848
  version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
@@ -4468,11 +4811,91 @@ declare function resolveImageModel(imageConfig: ImageConfig, explicit?: string):
4468
4811
  * ```
4469
4812
  */
4470
4813
  declare const AIConfigSchema: z.ZodObject<{
4814
+ acp: z.ZodOptional<z.ZodObject<{
4815
+ agents: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
4816
+ mode: z.ZodLiteral<"custom-service">;
4817
+ transport: z.ZodEnum<{
4818
+ http: "http";
4819
+ ws: "ws";
4820
+ }>;
4821
+ url: z.ZodURL;
4822
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4823
+ supportedTransports: z.ZodArray<z.ZodEnum<{
4824
+ http: "http";
4825
+ ws: "ws";
4826
+ }>>;
4827
+ id: z.ZodString;
4828
+ name: z.ZodString;
4829
+ enabled: z.ZodDefault<z.ZodBoolean>;
4830
+ adapter: z.ZodDefault<z.ZodString>;
4831
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
4832
+ defaultModelId: z.ZodOptional<z.ZodString>;
4833
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4834
+ }, z.core.$strict>, z.ZodObject<{
4835
+ mode: z.ZodLiteral<"embedded">;
4836
+ transport: z.ZodDefault<z.ZodLiteral<"stdio">>;
4837
+ command: z.ZodOptional<z.ZodString>;
4838
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
4839
+ id: z.ZodString;
4840
+ name: z.ZodString;
4841
+ enabled: z.ZodDefault<z.ZodBoolean>;
4842
+ adapter: z.ZodDefault<z.ZodString>;
4843
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
4844
+ defaultModelId: z.ZodOptional<z.ZodString>;
4845
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4846
+ }, z.core.$strict>, z.ZodObject<{
4847
+ mode: z.ZodLiteral<"builtin-service">;
4848
+ transport: z.ZodDefault<z.ZodLiteral<"stdio">>;
4849
+ image: z.ZodString;
4850
+ engine: z.ZodDefault<z.ZodEnum<{
4851
+ auto: "auto";
4852
+ podman: "podman";
4853
+ docker: "docker";
4854
+ }>>;
4855
+ command: z.ZodOptional<z.ZodString>;
4856
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
4857
+ id: z.ZodString;
4858
+ name: z.ZodString;
4859
+ enabled: z.ZodDefault<z.ZodBoolean>;
4860
+ adapter: z.ZodDefault<z.ZodString>;
4861
+ modelIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
4862
+ defaultModelId: z.ZodOptional<z.ZodString>;
4863
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4864
+ }, z.core.$strict>], "mode">>>;
4865
+ workspaces: z.ZodDefault<z.ZodArray<z.ZodObject<{
4866
+ id: z.ZodString;
4867
+ storage: z.ZodDiscriminatedUnion<[z.ZodObject<{
4868
+ type: z.ZodLiteral<"directory">;
4869
+ path: z.ZodString;
4870
+ }, z.core.$strict>, z.ZodObject<{
4871
+ type: z.ZodLiteral<"volume">;
4872
+ name: z.ZodString;
4873
+ engine: z.ZodDefault<z.ZodEnum<{
4874
+ auto: "auto";
4875
+ podman: "podman";
4876
+ docker: "docker";
4877
+ }>>;
4878
+ image: z.ZodString;
4879
+ }, z.core.$strict>], "type">;
4880
+ repositories: z.ZodDefault<z.ZodArray<z.ZodObject<{
4881
+ id: z.ZodString;
4882
+ url: z.ZodString;
4883
+ mainBranch: z.ZodString;
4884
+ remote: z.ZodDefault<z.ZodString>;
4885
+ }, z.core.$strict>>>;
4886
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4887
+ }, z.core.$strict>>>;
4888
+ requestTimeout: z.ZodDefault<z.ZodNumber>;
4889
+ promptTimeout: z.ZodDefault<z.ZodNumber>;
4890
+ cancelTimeout: z.ZodDefault<z.ZodNumber>;
4891
+ maxContentBytes: z.ZodDefault<z.ZodNumber>;
4892
+ maxPendingEvents: z.ZodDefault<z.ZodNumber>;
4893
+ }, z.core.$strict>>;
4471
4894
  llm: z.ZodDefault<z.ZodObject<{
4472
4895
  apiKey: z.ZodOptional<z.ZodPipe<z.ZodNullable<z.ZodString>, z.ZodTransform<string | undefined, string | null>>>;
4473
4896
  baseUrl: z.ZodOptional<z.ZodURL>;
4474
4897
  model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
4475
- api: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
4898
+ protocol: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
4476
4899
  chat: "chat";
4477
4900
  responses: "responses";
4478
4901
  anthropic: "anthropic";
@@ -4483,8 +4906,29 @@ declare const AIConfigSchema: z.ZodObject<{
4483
4906
  tempModelCacheTtl: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
4484
4907
  models: z.ZodOptional<z.ZodArray<z.ZodObject<{
4485
4908
  id: z.ZodString;
4909
+ capabilities: z.ZodOptional<z.ZodObject<{
4910
+ contextWindow: z.ZodOptional<z.ZodNumber>;
4911
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
4912
+ inputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
4913
+ image: "image";
4914
+ audio: "audio";
4915
+ text: "text";
4916
+ video: "video";
4917
+ }>>>;
4918
+ outputModalities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
4919
+ image: "image";
4920
+ audio: "audio";
4921
+ text: "text";
4922
+ video: "video";
4923
+ }>>>;
4924
+ toolCalling: z.ZodOptional<z.ZodBoolean>;
4925
+ reasoning: z.ZodOptional<z.ZodObject<{
4926
+ supported: z.ZodBoolean;
4927
+ efforts: z.ZodOptional<z.ZodArray<z.ZodString>>;
4928
+ }, z.core.$strict>>;
4929
+ }, z.core.$strict>>;
4486
4930
  model: z.ZodString;
4487
- api: z.ZodOptional<z.ZodEnum<{
4931
+ protocol: z.ZodOptional<z.ZodEnum<{
4488
4932
  chat: "chat";
4489
4933
  responses: "responses";
4490
4934
  anthropic: "anthropic";
@@ -4494,22 +4938,36 @@ declare const AIConfigSchema: z.ZodObject<{
4494
4938
  maxTokens: z.ZodOptional<z.ZodNumber>;
4495
4939
  temperature: z.ZodOptional<z.ZodNumber>;
4496
4940
  timeout: z.ZodOptional<z.ZodNumber>;
4497
- }, z.core.$strip>>>;
4941
+ }, z.core.$strict>>>;
4498
4942
  scenarios: z.ZodOptional<z.ZodObject<{
4943
+ default: z.ZodOptional<z.ZodString>;
4499
4944
  chat: z.ZodOptional<z.ZodString>;
4500
4945
  summary: z.ZodOptional<z.ZodString>;
4501
4946
  plan: z.ZodOptional<z.ZodString>;
4502
4947
  reasoning: z.ZodOptional<z.ZodString>;
4503
4948
  ocr: z.ZodOptional<z.ZodString>;
4504
- default: z.ZodOptional<z.ZodString>;
4505
4949
  execute: z.ZodOptional<z.ZodString>;
4506
4950
  extraction: z.ZodOptional<z.ZodString>;
4507
4951
  embedding: z.ZodOptional<z.ZodString>;
4508
4952
  rerank: z.ZodOptional<z.ZodString>;
4509
4953
  fast: z.ZodOptional<z.ZodString>;
4510
4954
  }, z.core.$strip>>;
4511
- }, z.core.$strip>>;
4955
+ }, z.core.$strict>>;
4512
4956
  mcp: z.ZodOptional<z.ZodObject<{
4957
+ servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
4958
+ id: z.ZodString;
4959
+ name: z.ZodString;
4960
+ transport: z.ZodEnum<{
4961
+ http: "http";
4962
+ stdio: "stdio";
4963
+ sse: "sse";
4964
+ }>;
4965
+ command: z.ZodOptional<z.ZodString>;
4966
+ args: z.ZodDefault<z.ZodArray<z.ZodString>>;
4967
+ url: z.ZodOptional<z.ZodURL>;
4968
+ environmentRefs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4969
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
4970
+ }, z.core.$strict>>>;
4513
4971
  server: z.ZodOptional<z.ZodObject<{
4514
4972
  name: z.ZodString;
4515
4973
  version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
@@ -6359,90 +6817,267 @@ interface FileOperations {
6359
6817
  }
6360
6818
 
6361
6819
  /**
6362
- * @h-ai/ai — 文生图公共类型
6820
+ * @h-ai/ai — Persona 子功能类型
6363
6821
  *
6364
- * 公共契约只暴露业务需要的提示词、尺寸和标准化图片字节。
6365
- * 厂商请求字段、临时 URL 与响应中间态由 Provider 内部处理。
6366
- * @module image/ai-image-types
6822
+ * 定义「AI 角色人格」的持久化与组合接口。Persona 解决的是「AI 是谁」的问题:
6823
+ * 多智能体场景(如多位专家同台访谈)中,每个 AI 有稳定的系统提示词、性格特征与
6824
+ * 长期人格。它与 Memory 正交——Memory 用 `objectId` / `scope` 回答「谁的记忆」,
6825
+ * Persona 回答「这个 AI 的身份与人设」,二者通过 `scope: { personaId }` 关联。
6826
+ * @module ai-persona-types
6367
6827
  */
6368
6828
 
6369
6829
  /**
6370
- * 图片像素尺寸
6830
+ * Persona 档案输入(创建 / 覆盖保存时使用)
6371
6831
  *
6372
6832
  * @example
6373
6833
  * ```ts
6374
- * import type { ImageSize } from '@h-ai/ai'
6834
+ * import type { PersonaProfileInput } from '@h-ai/ai'
6375
6835
  *
6376
- * const value: ImageSize = { width: 1024, height: 1024 }
6836
+ * const value: PersonaProfileInput = { id: 'support', objectId: 'tenant-1', name: '客服助手', systemPrompt: '根据已验证的订单信息回答。', traits: ['简洁', '先核对证据'] }
6377
6837
  * ```
6378
6838
  */
6379
- interface ImageSize {
6380
- /** 宽度(像素) */
6381
- width: number;
6382
- /** 高度(像素) */
6383
- height: number;
6839
+ interface PersonaProfileInput {
6840
+ /** 角色唯一标识(业务侧稳定 ID,如 `xiaop`) */
6841
+ id: string;
6842
+ /**
6843
+ * 所属主体 ID(多租户隔离)
6844
+ *
6845
+ * 不同主体可创建同名角色而互不覆盖;不传时归为平台内置角色 `system`。
6846
+ */
6847
+ objectId?: string;
6848
+ /** 角色显示名(如「小P」) */
6849
+ name?: string;
6850
+ /** 角色系统提示词(定义身份、职责、语气) */
6851
+ systemPrompt: string;
6852
+ /** 性格 / 风格特征(组合进系统提示词,如「谨慎」「喜欢引用案例」) */
6853
+ traits?: string[];
6854
+ /** 附加元数据 */
6855
+ metadata?: Record<string, unknown>;
6384
6856
  }
6385
6857
  /**
6386
- * 可选参考图;Provider 会转换为对应厂商的传输格式
6858
+ * 完整的 Persona 档案
6387
6859
  *
6388
6860
  * @example
6389
6861
  * ```ts
6390
- * import type { ReferenceImage } from '@h-ai/ai'
6391
- * import { readFile } from 'node:fs/promises'
6862
+ * import type { PersonaProfile } from '@h-ai/ai'
6392
6863
  *
6393
- * const reference: ReferenceImage = { data: await readFile('reference.png'), mimeType: 'image/png' }
6864
+ * function label(profile: PersonaProfile): string {
6865
+ * return `${profile.objectId}/${profile.id}: ${profile.name ?? profile.id}`
6866
+ * }
6394
6867
  * ```
6395
6868
  */
6396
- interface ReferenceImage {
6397
- /** 图片二进制内容 */
6398
- data: Uint8Array;
6399
- /** 图片 MIME 类型,例如 `image/png`、`image/jpeg` */
6400
- mimeType: string;
6869
+ interface PersonaProfile {
6870
+ /** 角色唯一标识 */
6871
+ id: string;
6872
+ /** 所属主体 ID(多租户隔离;平台内置角色为 `system`) */
6873
+ objectId: string;
6874
+ /** 角色显示名 */
6875
+ name?: string;
6876
+ /** 角色系统提示词 */
6877
+ systemPrompt: string;
6878
+ /** 性格 / 风格特征 */
6879
+ traits: string[];
6880
+ /** 附加元数据 */
6881
+ metadata?: Record<string, unknown>;
6882
+ /** 创建时间(Unix 毫秒) */
6883
+ createdAt: number;
6884
+ /** 更新时间(Unix 毫秒) */
6885
+ updatedAt: number;
6401
6886
  }
6402
6887
  /**
6403
- * 文生图请求
6888
+ * Persona 档案更新输入
6889
+ *
6890
+ * 所有字段可选,仅更新传入的字段。
6404
6891
  *
6405
6892
  * @example
6406
6893
  * ```ts
6407
- * import type { GenerateImageRequest } from '@h-ai/ai'
6894
+ * import type { PersonaProfileUpdate } from '@h-ai/ai'
6408
6895
  *
6409
- * const value: GenerateImageRequest = { prompt: '水墨山水,留白构图', size: { width: 1024, height: 1024 }, signal: new AbortController().signal }
6896
+ * const value: PersonaProfileUpdate = { traits: ['简洁', '引用来源'] }
6410
6897
  * ```
6411
6898
  */
6412
- interface GenerateImageRequest {
6413
- /** 图片内容与风格提示词 */
6414
- prompt: string;
6415
- /** 模型 ID;不传时使用配置中的默认文生图模型 */
6416
- model?: string;
6417
- /** 输出像素尺寸;不传时由模型决定 */
6418
- size?: ImageSize;
6419
- /** 用于图生图、编辑或风格参考的一张或多张图片 */
6420
- referenceImages?: ReferenceImage[];
6421
- /** 取消整个厂商请求和图片下载;模型 timeout 同时限制总耗时。 */
6422
- signal?: AbortSignal;
6899
+ interface PersonaProfileUpdate {
6900
+ /** 更新显示名 */
6901
+ name?: string;
6902
+ /** 更新系统提示词 */
6903
+ systemPrompt?: string;
6904
+ /** 更新特征列表(整体替换) */
6905
+ traits?: string[];
6906
+ /** 更新元数据 */
6907
+ metadata?: Record<string, unknown>;
6423
6908
  }
6424
6909
  /**
6425
- * 标准化后的单张图片
6910
+ * Persona 操作接口(通过 `ai.persona` 访问)
6911
+ *
6912
+ * 管理 AI 角色人格的持久化与系统提示词组合。需要先调用 `ai.init()` 初始化后使用。
6426
6913
  *
6427
6914
  * @example
6428
6915
  * ```ts
6429
- * import type { GeneratedImage } from '@h-ai/ai'
6916
+ * import { ai } from '@h-ai/ai'
6430
6917
  *
6431
- * function imageBlob(image: GeneratedImage): Blob {
6432
- * return new Blob([Uint8Array.from(image.data)], { type: image.mimeType })
6918
+ * // 应用启动已成功初始化 ai;这里是业务服务函数。
6919
+ * async function run() {
6920
+ * const result = await ai.persona.save({ id: 'support', objectId: 'tenant-1', systemPrompt: '先核对订单状态再回答。' })
6921
+ * if (!result.success)
6922
+ * return result
6923
+ * const composed = await ai.persona.compose(result.data.id, { objectId: result.data.objectId })
6924
+ * if (!composed.success)
6925
+ * return composed
6926
+ * return composed.data
6433
6927
  * }
6434
6928
  * ```
6435
6929
  */
6436
- interface GeneratedImage {
6437
- /** 图片二进制内容 */
6438
- data: Uint8Array;
6439
- /** 经魔数核验的栅格图片 MIME:PNG、JPEG、GIF、WebP。 */
6440
- mimeType: string;
6441
- /** 宽度提示,来自请求或厂商;未通过完整图片解码核验。 */
6442
- width?: number;
6443
- /** 高度提示,来自请求或厂商;未通过完整图片解码核验。 */
6444
- height?: number;
6445
- }
6930
+ interface PersonaOperations {
6931
+ /**
6932
+ * 创建或覆盖保存一个角色档案(upsert 语义)
6933
+ *
6934
+ * @param profile - 角色档案输入
6935
+ * @returns 保存后的完整档案
6936
+ */
6937
+ save: (profile: PersonaProfileInput) => Promise<HaiResult<PersonaProfile>>;
6938
+ /**
6939
+ * 按 ID 获取角色档案
6940
+ *
6941
+ * @param id - 角色 ID
6942
+ * @returns 角色档案,不存在时返回 PERSONA_NOT_FOUND
6943
+ */
6944
+ get: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile>>;
6945
+ /**
6946
+ * 更新角色档案(仅更新传入字段)
6947
+ *
6948
+ * @param id - 角色 ID
6949
+ * @param updates - 需要更新的字段
6950
+ * @param options - 主体作用域(默认 `system`)
6951
+ * @returns 更新后的完整档案
6952
+ */
6953
+ update: (id: string, updates: PersonaProfileUpdate, options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile>>;
6954
+ /**
6955
+ * 删除角色档案
6956
+ *
6957
+ * @param id - 角色 ID
6958
+ * @param options - 主体作用域(默认 `system`)
6959
+ * @returns 成功返回 ok(undefined)
6960
+ */
6961
+ remove: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<void>>;
6962
+ /**
6963
+ * 列出指定主体的角色档案
6964
+ *
6965
+ * @param options - 主体作用域(默认 `system`)
6966
+ * @returns 角色档案列表
6967
+ */
6968
+ list: (options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile[]>>;
6969
+ /**
6970
+ * 组合角色的完整系统提示词
6971
+ *
6972
+ * 将 `systemPrompt` 与 `traits` 拼装为一段可直接作为 system 消息的文本,
6973
+ * 供 `ai.context.createManager({ scope, systemPrompt })` 使用。
6974
+ *
6975
+ * @param id - 角色 ID
6976
+ * @param options - 主体作用域(默认 `system`)
6977
+ * @returns 组合后的系统提示词,角色不存在时返回 PERSONA_NOT_FOUND
6978
+ */
6979
+ compose: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<string>>;
6980
+ }
6981
+ /**
6982
+ * Persona 操作的主体作用域选项
6983
+ *
6984
+ * @example
6985
+ * ```ts
6986
+ * import type { PersonaScopeOptions } from '@h-ai/ai'
6987
+ *
6988
+ * const value: PersonaScopeOptions = { objectId: 'tenant-1' }
6989
+ * ```
6990
+ */
6991
+ interface PersonaScopeOptions {
6992
+ /** 所属主体 ID(不传时归为平台内置角色 `system`) */
6993
+ objectId?: string;
6994
+ }
6995
+
6996
+ /**
6997
+ * @h-ai/ai — 文生图公共类型
6998
+ *
6999
+ * 公共契约只暴露业务需要的提示词、尺寸和标准化图片字节。
7000
+ * 厂商请求字段、临时 URL 与响应中间态由 Provider 内部处理。
7001
+ * @module image/ai-image-types
7002
+ */
7003
+
7004
+ /**
7005
+ * 图片像素尺寸
7006
+ *
7007
+ * @example
7008
+ * ```ts
7009
+ * import type { ImageSize } from '@h-ai/ai'
7010
+ *
7011
+ * const value: ImageSize = { width: 1024, height: 1024 }
7012
+ * ```
7013
+ */
7014
+ interface ImageSize {
7015
+ /** 宽度(像素) */
7016
+ width: number;
7017
+ /** 高度(像素) */
7018
+ height: number;
7019
+ }
7020
+ /**
7021
+ * 可选参考图;Provider 会转换为对应厂商的传输格式
7022
+ *
7023
+ * @example
7024
+ * ```ts
7025
+ * import type { ReferenceImage } from '@h-ai/ai'
7026
+ * import { readFile } from 'node:fs/promises'
7027
+ *
7028
+ * const reference: ReferenceImage = { data: await readFile('reference.png'), mimeType: 'image/png' }
7029
+ * ```
7030
+ */
7031
+ interface ReferenceImage {
7032
+ /** 图片二进制内容 */
7033
+ data: Uint8Array;
7034
+ /** 图片 MIME 类型,例如 `image/png`、`image/jpeg` */
7035
+ mimeType: string;
7036
+ }
7037
+ /**
7038
+ * 文生图请求
7039
+ *
7040
+ * @example
7041
+ * ```ts
7042
+ * import type { GenerateImageRequest } from '@h-ai/ai'
7043
+ *
7044
+ * const value: GenerateImageRequest = { prompt: '水墨山水,留白构图', size: { width: 1024, height: 1024 }, signal: new AbortController().signal }
7045
+ * ```
7046
+ */
7047
+ interface GenerateImageRequest {
7048
+ /** 图片内容与风格提示词 */
7049
+ prompt: string;
7050
+ /** 模型 ID;不传时使用配置中的默认文生图模型 */
7051
+ model?: string;
7052
+ /** 输出像素尺寸;不传时由模型决定 */
7053
+ size?: ImageSize;
7054
+ /** 用于图生图、编辑或风格参考的一张或多张图片 */
7055
+ referenceImages?: ReferenceImage[];
7056
+ /** 取消整个厂商请求和图片下载;模型 timeout 同时限制总耗时。 */
7057
+ signal?: AbortSignal;
7058
+ }
7059
+ /**
7060
+ * 标准化后的单张图片
7061
+ *
7062
+ * @example
7063
+ * ```ts
7064
+ * import type { GeneratedImage } from '@h-ai/ai'
7065
+ *
7066
+ * function imageBlob(image: GeneratedImage): Blob {
7067
+ * return new Blob([Uint8Array.from(image.data)], { type: image.mimeType })
7068
+ * }
7069
+ * ```
7070
+ */
7071
+ interface GeneratedImage {
7072
+ /** 图片二进制内容 */
7073
+ data: Uint8Array;
7074
+ /** 经魔数核验的栅格图片 MIME:PNG、JPEG、GIF、WebP。 */
7075
+ mimeType: string;
7076
+ /** 宽度提示,来自请求或厂商;未通过完整图片解码核验。 */
7077
+ width?: number;
7078
+ /** 高度提示,来自请求或厂商;未通过完整图片解码核验。 */
7079
+ height?: number;
7080
+ }
6446
7081
  /**
6447
7082
  * 文生图结果
6448
7083
  *
@@ -6690,180 +7325,159 @@ interface MCPOperations {
6690
7325
  }
6691
7326
 
6692
7327
  /**
6693
- * @h-ai/ai — Persona 子功能类型
6694
- *
6695
- * 定义「AI 角色人格」的持久化与组合接口。Persona 解决的是「AI 是谁」的问题:
6696
- * 多智能体场景(如多位专家同台访谈)中,每个 AI 有稳定的系统提示词、性格特征与
6697
- * 长期人格。它与 Memory 正交——Memory 用 `objectId` / `scope` 回答「谁的记忆」,
6698
- * Persona 回答「这个 AI 的身份与人设」,二者通过 `scope: { personaId }` 关联。
6699
- * @module ai-persona-types
7328
+ * 清单项与来源;配置来源不可修改,version 仅用于数据库乐观并发更新。
7329
+ * @example
7330
+ * ```ts
7331
+ * import type { AIResourceEntry, ModelEntry } from '@h-ai/ai'
7332
+ * function editable(entry: AIResourceEntry<ModelEntry>) { return entry.source === 'database' }
7333
+ * ```
6700
7334
  */
6701
-
7335
+ interface AIResourceEntry<T> {
7336
+ /** 原始配置;返回独立副本,修改副本不会修改清单。 */
7337
+ value: T;
7338
+ /** config 来自初始化配置,database 来自 AIStoreProvider。 */
7339
+ source: 'config' | 'database';
7340
+ /** get 返回的数据库版本;更新/删除时可传回以拒绝过期写入。 */
7341
+ version?: string;
7342
+ }
6702
7343
  /**
6703
- * Persona 档案输入(创建 / 覆盖保存时使用)
6704
- *
7344
+ * 配置与数据库合并的资源清单。相同 ID 配置优先,配置记录永不写回数据库。
6705
7345
  * @example
6706
7346
  * ```ts
6707
- * import type { PersonaProfileInput } from '@h-ai/ai'
6708
- *
6709
- * const value: PersonaProfileInput = { id: 'support', objectId: 'tenant-1', name: '客服助手', systemPrompt: '根据已验证的订单信息回答。', traits: ['简洁', '先核对证据'] }
7347
+ * import { ai } from '@h-ai/ai'
7348
+ * async function listModels() { const result = await ai.llm.models.list(); if (!result.success) return result; return result.data.map(item => ({ id: item.value.id, source: item.source })) }
6710
7349
  * ```
6711
7350
  */
6712
- interface PersonaProfileInput {
6713
- /** 角色唯一标识(业务侧稳定 ID,如 `xiaop`) */
6714
- id: string;
7351
+ interface AIResourceRegistry<T, Input = T> {
6715
7352
  /**
6716
- * 所属主体 ID(多租户隔离)
6717
- *
6718
- * 不同主体可创建同名角色而互不覆盖;不传时归为平台内置角色 `system`。
7353
+ * 读取合并清单;保留配置顺序,追加未被遮蔽的数据库项。
7354
+ * @returns 包含 value/source 的去重列表;列表项无数据库版本。
7355
+ * @example
7356
+ * ```ts
7357
+ * import { ai } from '@h-ai/ai'
7358
+ * const result = await ai.llm.models.list()
7359
+ * if (result.success) { const entries = result.data }
7360
+ * ```
6719
7361
  */
6720
- objectId?: string;
6721
- /** 角色显示名(如「小P」) */
6722
- name?: string;
6723
- /** 角色系统提示词(定义身份、职责、语气) */
6724
- systemPrompt: string;
6725
- /** 性格 / 风格特征(组合进系统提示词,如「谨慎」「喜欢引用案例」) */
6726
- traits?: string[];
6727
- /** 附加元数据 */
6728
- metadata?: Record<string, unknown>;
7362
+ list: () => Promise<HaiResult<AIResourceEntry<T>[]>>;
7363
+ /**
7364
+ * 按 ID 读取来源、配置和数据库版本。
7365
+ * @param id - 资源 ID。
7366
+ * @returns 包含 value/source/version 的资源条目,未找到时返回失败。
7367
+ * @example
7368
+ * ```ts
7369
+ * import { ai } from '@h-ai/ai'
7370
+ * const result = await ai.llm.models.get('coding')
7371
+ * if (result.success) { const source = result.data.source }
7372
+ * ```
7373
+ */
7374
+ get: (id: string) => Promise<HaiResult<AIResourceEntry<T>>>;
7375
+ /**
7376
+ * 新建数据库记录;ID 已存在或属于配置时拒绝。
7377
+ * @param input - 完整资源配置。
7378
+ * @returns 新建条目及版本的 HaiResult,配置同 ID 返回只读错误。
7379
+ * @example
7380
+ * ```ts
7381
+ * import { ai } from '@h-ai/ai'
7382
+ * const result = await ai.llm.models.register({ id: 'coding', model: 'example-model', protocol: 'responses' })
7383
+ * if (!result.success) { const code = result.error.code }
7384
+ * ```
7385
+ */
7386
+ register: (input: Input) => Promise<HaiResult<AIResourceEntry<T>>>;
7387
+ /**
7388
+ * 完整替换数据库记录;配置来源只读。版本不匹配时不写入。
7389
+ * @param input - 同 ID 的完整新配置。
7390
+ * @param expectedVersion - 可选的 get 版本。
7391
+ * @returns 替换后的条目及版本;过期版本返回资源冲突。
7392
+ * @example
7393
+ * ```ts
7394
+ * import { ai } from '@h-ai/ai'
7395
+ * const current = await ai.llm.models.get('coding')
7396
+ * if (current.success && current.data.source === 'database') {
7397
+ * const result = await ai.llm.models.update({ ...current.data.value, temperature: 0.2 }, current.data.version)
7398
+ * if (!result.success) { const code = result.error.code }
7399
+ * }
7400
+ * ```
7401
+ */
7402
+ update: (input: Input, expectedVersion?: string) => Promise<HaiResult<AIResourceEntry<T>>>;
7403
+ /**
7404
+ * 删除数据库记录,采用 CAS 墓碑避免与并发更新相互覆盖;不删除外部文件。
7405
+ * @param id - 资源 ID。
7406
+ * @param expectedVersion - 可选的 get 版本。
7407
+ * @returns 删除完成的 HaiResult;配置只读、版本冲突或记录不存在时失败。
7408
+ * @example
7409
+ * ```ts
7410
+ * import { ai } from '@h-ai/ai'
7411
+ * const result = await ai.llm.models.remove('temporary')
7412
+ * if (!result.success) { const code = result.error.code }
7413
+ * ```
7414
+ */
7415
+ remove: (id: string, expectedVersion?: string) => Promise<HaiResult<void>>;
6729
7416
  }
6730
7417
  /**
6731
- * 完整的 Persona 档案
6732
- *
7418
+ * 包含配置/数据库资源维护的 llm 操作接口。
6733
7419
  * @example
6734
7420
  * ```ts
6735
- * import type { PersonaProfile } from '@h-ai/ai'
6736
- *
6737
- * function label(profile: PersonaProfile): string {
6738
- * return `${profile.objectId}/${profile.id}: ${profile.name ?? profile.id}`
6739
- * }
7421
+ * import { ai } from '@h-ai/ai'
7422
+ * const result = await ai.llm.models.list()
7423
+ * if (result.success) { const resources = result.data }
6740
7424
  * ```
6741
7425
  */
6742
- interface PersonaProfile {
6743
- /** 角色唯一标识 */
6744
- id: string;
6745
- /** 所属主体 ID(多租户隔离;平台内置角色为 `system`) */
6746
- objectId: string;
6747
- /** 角色显示名 */
6748
- name?: string;
6749
- /** 角色系统提示词 */
6750
- systemPrompt: string;
6751
- /** 性格 / 风格特征 */
6752
- traits: string[];
6753
- /** 附加元数据 */
6754
- metadata?: Record<string, unknown>;
6755
- /** 创建时间(Unix 毫秒) */
6756
- createdAt: number;
6757
- /** 更新时间(Unix 毫秒) */
6758
- updatedAt: number;
7426
+ interface ManagedLLMOperations extends LLMOperations {
7427
+ /** 配置只读、数据库可维护的合并清单。 */
7428
+ models: AIResourceRegistry<z.output<typeof ModelEntrySchema>, z.input<typeof ModelEntrySchema>>;
6759
7429
  }
6760
7430
  /**
6761
- * Persona 档案更新输入
6762
- *
6763
- * 所有字段可选,仅更新传入的字段。
6764
- *
7431
+ * 包含配置/数据库资源维护的 audio 操作接口。
6765
7432
  * @example
6766
7433
  * ```ts
6767
- * import type { PersonaProfileUpdate } from '@h-ai/ai'
6768
- *
6769
- * const value: PersonaProfileUpdate = { traits: ['简洁', '引用来源'] }
7434
+ * import { ai } from '@h-ai/ai'
7435
+ * const result = await ai.audio.models.list()
7436
+ * if (result.success) { const resources = result.data }
6770
7437
  * ```
6771
7438
  */
6772
- interface PersonaProfileUpdate {
6773
- /** 更新显示名 */
6774
- name?: string;
6775
- /** 更新系统提示词 */
6776
- systemPrompt?: string;
6777
- /** 更新特征列表(整体替换) */
6778
- traits?: string[];
6779
- /** 更新元数据 */
6780
- metadata?: Record<string, unknown>;
7439
+ interface ManagedAudioOperations extends AudioOperations {
7440
+ /** 配置只读、数据库可维护的合并清单。 */
7441
+ models: AIResourceRegistry<z.output<typeof AudioModelEntrySchema>, z.input<typeof AudioModelEntrySchema>>;
6781
7442
  }
6782
7443
  /**
6783
- * Persona 操作接口(通过 `ai.persona` 访问)
6784
- *
6785
- * 管理 AI 角色人格的持久化与系统提示词组合。需要先调用 `ai.init()` 初始化后使用。
6786
- *
7444
+ * 包含配置/数据库资源维护的 image 操作接口。
6787
7445
  * @example
6788
7446
  * ```ts
6789
7447
  * import { ai } from '@h-ai/ai'
6790
- *
6791
- * // 应用启动已成功初始化 ai;这里是业务服务函数。
6792
- * async function run() {
6793
- * const result = await ai.persona.save({ id: 'support', objectId: 'tenant-1', systemPrompt: '先核对订单状态再回答。' })
6794
- * if (!result.success)
6795
- * return result
6796
- * const composed = await ai.persona.compose(result.data.id, { objectId: result.data.objectId })
6797
- * if (!composed.success)
6798
- * return composed
6799
- * return composed.data
6800
- * }
7448
+ * const result = await ai.image.models.list()
7449
+ * if (result.success) { const resources = result.data }
6801
7450
  * ```
6802
7451
  */
6803
- interface PersonaOperations {
6804
- /**
6805
- * 创建或覆盖保存一个角色档案(upsert 语义)
6806
- *
6807
- * @param profile - 角色档案输入
6808
- * @returns 保存后的完整档案
6809
- */
6810
- save: (profile: PersonaProfileInput) => Promise<HaiResult<PersonaProfile>>;
6811
- /**
6812
- * 按 ID 获取角色档案
6813
- *
6814
- * @param id - 角色 ID
6815
- * @returns 角色档案,不存在时返回 PERSONA_NOT_FOUND
6816
- */
6817
- get: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile>>;
6818
- /**
6819
- * 更新角色档案(仅更新传入字段)
6820
- *
6821
- * @param id - 角色 ID
6822
- * @param updates - 需要更新的字段
6823
- * @param options - 主体作用域(默认 `system`)
6824
- * @returns 更新后的完整档案
6825
- */
6826
- update: (id: string, updates: PersonaProfileUpdate, options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile>>;
6827
- /**
6828
- * 删除角色档案
6829
- *
6830
- * @param id - 角色 ID
6831
- * @param options - 主体作用域(默认 `system`)
6832
- * @returns 成功返回 ok(undefined)
6833
- */
6834
- remove: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<void>>;
6835
- /**
6836
- * 列出指定主体的角色档案
6837
- *
6838
- * @param options - 主体作用域(默认 `system`)
6839
- * @returns 角色档案列表
6840
- */
6841
- list: (options?: PersonaScopeOptions) => Promise<HaiResult<PersonaProfile[]>>;
6842
- /**
6843
- * 组合角色的完整系统提示词
6844
- *
6845
- * 将 `systemPrompt` 与 `traits` 拼装为一段可直接作为 system 消息的文本,
6846
- * 供 `ai.context.createManager({ scope, systemPrompt })` 使用。
6847
- *
6848
- * @param id - 角色 ID
6849
- * @param options - 主体作用域(默认 `system`)
6850
- * @returns 组合后的系统提示词,角色不存在时返回 PERSONA_NOT_FOUND
6851
- */
6852
- compose: (id: string, options?: PersonaScopeOptions) => Promise<HaiResult<string>>;
7452
+ interface ManagedImageOperations extends ImageOperations {
7453
+ /** 配置只读、数据库可维护的合并清单。 */
7454
+ models: AIResourceRegistry<z.output<typeof ImageModelEntrySchema>, z.input<typeof ImageModelEntrySchema>>;
6853
7455
  }
6854
7456
  /**
6855
- * Persona 操作的主体作用域选项
6856
- *
7457
+ * 包含配置/数据库资源维护的 mcp 操作接口。
6857
7458
  * @example
6858
7459
  * ```ts
6859
- * import type { PersonaScopeOptions } from '@h-ai/ai'
6860
- *
6861
- * const value: PersonaScopeOptions = { objectId: 'tenant-1' }
7460
+ * import { ai } from '@h-ai/ai'
7461
+ * const result = await ai.mcp.servers.list()
7462
+ * if (result.success) { const resources = result.data }
6862
7463
  * ```
6863
7464
  */
6864
- interface PersonaScopeOptions {
6865
- /** 所属主体 ID(不传时归为平台内置角色 `system`) */
6866
- objectId?: string;
7465
+ interface ManagedMCPOperations extends MCPOperations {
7466
+ /** 配置只读、数据库可维护的合并清单。 */
7467
+ servers: AIResourceRegistry<z.output<typeof MCPExternalServerSchema>, z.input<typeof MCPExternalServerSchema>>;
7468
+ }
7469
+ /**
7470
+ * 包含配置/数据库资源维护的 retrieval 操作接口。
7471
+ * @example
7472
+ * ```ts
7473
+ * import { ai } from '@h-ai/ai'
7474
+ * const result = await ai.retrieval.sources.list()
7475
+ * if (result.success) { const resources = result.data }
7476
+ * ```
7477
+ */
7478
+ interface ManagedRetrievalOperations extends RetrievalOperations {
7479
+ /** 配置只读、数据库可维护的合并清单。 */
7480
+ sources: AIResourceRegistry<z.output<typeof RetrievalSourceSchema>, z.input<typeof RetrievalSourceSchema>>;
6867
7481
  }
6868
7482
 
6869
7483
  /**
@@ -7046,6 +7660,21 @@ interface TokenOperations {
7046
7660
  */
7047
7661
  declare const HaiAIError: {
7048
7662
  readonly INTERNAL_ERROR: _h_ai_core.HaiErrorDef;
7663
+ readonly ACP_GIT_NOT_FOUND: _h_ai_core.HaiErrorDef;
7664
+ readonly ACP_OPERATION_FAILED: _h_ai_core.HaiErrorDef;
7665
+ readonly ACP_INVALID_REQUEST: _h_ai_core.HaiErrorDef;
7666
+ readonly ACP_NOT_FOUND: _h_ai_core.HaiErrorDef;
7667
+ readonly ACP_BUSY: _h_ai_core.HaiErrorDef;
7668
+ readonly ACP_UNSUPPORTED: _h_ai_core.HaiErrorDef;
7669
+ readonly ACP_CANCELLED: _h_ai_core.HaiErrorDef;
7670
+ readonly ACP_TIMEOUT: _h_ai_core.HaiErrorDef;
7671
+ readonly ACP_OUTPUT_INVALID: _h_ai_core.HaiErrorDef;
7672
+ readonly ACP_CONFLICT: _h_ai_core.HaiErrorDef;
7673
+ readonly ACP_PARTIAL_FAILURE: _h_ai_core.HaiErrorDef;
7674
+ readonly ACP_CLOSED: _h_ai_core.HaiErrorDef;
7675
+ readonly ACP_RUNTIME_UNAVAILABLE: _h_ai_core.HaiErrorDef;
7676
+ readonly ACP_MODEL_INCOMPATIBLE: _h_ai_core.HaiErrorDef;
7677
+ readonly ACP_CLEANUP_FAILED: _h_ai_core.HaiErrorDef;
7049
7678
  readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
7050
7679
  readonly CONFIGURATION_ERROR: _h_ai_core.HaiErrorDef;
7051
7680
  readonly INIT_IN_PROGRESS: _h_ai_core.HaiErrorDef;
@@ -7118,6 +7747,11 @@ declare const HaiAIError: {
7118
7747
  readonly IMAGE_DOWNLOAD_BLOCKED: _h_ai_core.HaiErrorDef;
7119
7748
  readonly IMAGE_TOO_LARGE: _h_ai_core.HaiErrorDef;
7120
7749
  readonly IMAGE_TIMEOUT: _h_ai_core.HaiErrorDef;
7750
+ readonly RESOURCE_READ_ONLY: _h_ai_core.HaiErrorDef;
7751
+ readonly RESOURCE_NOT_FOUND: _h_ai_core.HaiErrorDef;
7752
+ readonly RESOURCE_CONFLICT: _h_ai_core.HaiErrorDef;
7753
+ readonly RESOURCE_INVALID: _h_ai_core.HaiErrorDef;
7754
+ readonly RESOURCE_OPERATION_FAILED: _h_ai_core.HaiErrorDef;
7121
7755
  readonly CONTEXT_COMPRESS_FAILED: _h_ai_core.HaiErrorDef;
7122
7756
  readonly CONTEXT_SUMMARIZE_FAILED: _h_ai_core.HaiErrorDef;
7123
7757
  readonly CONTEXT_TOKEN_ESTIMATE_FAILED: _h_ai_core.HaiErrorDef;
@@ -7152,6 +7786,8 @@ declare const HaiAIError: {
7152
7786
  * ```
7153
7787
  */
7154
7788
  interface AIInitOptions {
7789
+ /** 可信服务端扩展:为其他 ACP 智能体生成原生配置。 */
7790
+ acpAdapters?: Record<string, ACPAgentAdapter>;
7155
7791
  /**
7156
7792
  * 自定义存储 Provider
7157
7793
  *
@@ -7208,9 +7844,11 @@ interface AIFunctions {
7208
7844
  /** 是否已初始化(`init()` 成功后为 `true`,`close()` 后为 `false`) */
7209
7845
  readonly isInitialized: boolean;
7210
7846
  /** LLM 操作(聊天、流式、模型列表),需要先调用 `init()` */
7211
- readonly llm: LLMOperations;
7212
- /** MCP 操作(工具/资源/提示词注册与调用),需要先调用 `init()` */
7213
- readonly mcp: MCPOperations;
7847
+ readonly llm: ManagedLLMOperations;
7848
+ /** ACP 智能体、工作区与原生会话,需要先调用 `init()`。 */
7849
+ readonly acp: ACPOperations;
7850
+ /** MCP 本地函数注册及配置/数据库外部服务清单,需要先调用 `init()`。 */
7851
+ readonly mcp: ManagedMCPOperations;
7214
7852
  /** 工具操作(定义工具与注册表),纯函数,无需初始化 */
7215
7853
  readonly tools: ToolsOperations;
7216
7854
  /** 流处理操作(流处理器、SSE 编解码),纯函数,无需初始化 */
@@ -7220,7 +7858,7 @@ interface AIFunctions {
7220
7858
  /** 推理操作(ReAct / CoT / Plan-Execute),需要先调用 `init()` */
7221
7859
  readonly reasoning: ReasoningOperations;
7222
7860
  /** 检索操作(向量检索),需要先调用 `init()` */
7223
- readonly retrieval: RetrievalOperations;
7861
+ readonly retrieval: ManagedRetrievalOperations;
7224
7862
  /** RAG 操作(检索增强生成),需要先调用 `init()` */
7225
7863
  readonly rag: RagOperations;
7226
7864
  /** Knowledge 操作(知识库管理与检索),需要先调用 `init()` 和 `knowledge.setup()` */
@@ -7244,9 +7882,9 @@ interface AIFunctions {
7244
7882
  /** A2A 操作(Agent-to-Agent 协议),需要先调用 `init()` 并配置 `a2a` */
7245
7883
  readonly a2a: A2AOperations;
7246
7884
  /** Audio 操作(语音识别 / 语音合成),需要先调用 `init()` 并配置 `audio` */
7247
- readonly audio: AudioOperations;
7885
+ readonly audio: ManagedAudioOperations;
7248
7886
  /** Image 操作(文生图),需要先调用 `init()` 并配置 `image` */
7249
- readonly image: ImageOperations;
7887
+ readonly image: ManagedImageOperations;
7250
7888
  }
7251
7889
 
7252
7890
  /** @h-ai/ai — 音频播放负载序列化 */
@@ -7602,4 +8240,1524 @@ interface AudioWsEndMessage {
7602
8240
  */
7603
8241
  type AudioWsServerMessage = AudioWsSpeechMessage | AudioWsTranscriptMessage | AudioWsSegmentStartedMessage | AudioWsSegmentDoneMessage | AudioWsErrorMessage | AudioWsEndMessage;
7604
8242
 
7605
- export { AudioWsStartMessageSchema as $, type A2AAgentCardConfig as A, AUDIO_WS_PATH as B, type ApiType as C, ApiTypeSchema as D, type AskOptions as E, type AssistantMessage as F, type AudioConfig as G, AudioConfigSchema as H, AudioFormatSchema as I, type AudioModelEntry as J, AudioModelEntrySchema as K, type AudioOperation as L, AudioOperationSchema as M, AudioOperationsSchema as N, type AudioProviderName as O, AudioProviderSchema as P, type AudioWsClientMessage as Q, AudioWsClientMessageSchema as R, type AudioWsDoneMessage as S, AudioWsDoneMessageSchema as T, type AudioWsEndMessage as U, type AudioWsErrorMessage as V, type AudioWsSegmentDoneMessage as W, type AudioWsSegmentStartedMessage as X, type AudioWsServerMessage as Y, type AudioWsSpeechMessage as Z, type AudioWsStartMessage as _, type A2AApiKeySecurity as a, type ImageProviderName as a$, type AudioWsTextMessage as a0, AudioWsTextMessageSchema as a1, type AudioWsTranscriptMessage as a2, type ChatCompletionChoice as a3, type ChatCompletionChunk as a4, type ChatCompletionDelta as a5, type ChatCompletionRequest as a6, type ChatCompletionResponse as a7, type ChatHistoryOptions as a8, type ChatMessage as a9, type EmbeddingOperations as aA, type EmbeddingRequest as aB, type EmbeddingResponse as aC, type EntityDocumentRelation as aD, type EntityDocumentResult as aE, type EntityListOptions as aF, type EntityQueryOptions as aG, type EntityType as aH, EntityTypeSchema as aI, type FileConfig as aJ, FileConfigSchema as aK, type FileOperations as aL, type FileParseMethod as aM, type FileParseOptions as aN, type FileParseRequest as aO, type FileParseResult as aP, type GenerateImageRequest as aQ, type GenerateImageResult as aR, type GenerateObjectRequest as aS, type GeneratedImage as aT, HaiAIError as aU, type ImageConfig as aV, ImageConfigSchema as aW, type ImageContent as aX, type ImageModelEntry as aY, ImageModelEntrySchema as aZ, type ImageOperations as a_, type ChatRecord as aa, type Citation as ab, type CommitTurnInput as ac, type CompressConfig as ad, CompressConfigSchema as ae, type CompressOperations as af, type CompressOptions as ag, type CompressResult as ah, type CompressionStrategy as ai, CompressionStrategySchema as aj, type ConsolidateOptions as ak, type ConsolidateResult as al, type ContextChatOptions as am, type ContextChatResult as an, type ContextManager as ao, type ContextManagerOptions as ap, type ContextOperations as aq, type ContextResetOptions as ar, type ContextStreamEvent as as, type ConversationTurn as at, type ConversationTurnStatus as au, type DefineToolOptions as av, type DeveloperMessage as aw, type EmbeddingConfig as ax, EmbeddingConfigSchema as ay, type EmbeddingItem as az, type A2AAuthenticator as b, MemoryTypeSchema as b$, ImageProviderSchema as b0, type ImageSize as b1, type InteractionScope as b2, type KnowledgeAskOptions as b3, type KnowledgeAskResult as b4, type KnowledgeConfig as b5, KnowledgeConfigSchema as b6, type KnowledgeDocumentInfo as b7, type KnowledgeDocumentListOptions as b8, type KnowledgeDocumentMetadata as b9, type MCPPromptContent as bA, type MCPPromptMessage as bB, type MCPResource as bC, type MCPResourceContent as bD, type MCPServerCapabilities as bE, MCPServerCapabilitiesSchema as bF, type MCPServerConfig as bG, MCPServerConfigSchema as bH, type MCPToolDefinition as bI, type MCPToolHandler as bJ, type McpServerOptions as bK, type MemoryAccessScope as bL, type MemoryAdminOperations as bM, type MemoryClearAllOptions as bN, type MemoryClearOptions as bO, type MemoryConfig as bP, MemoryConfigSchema as bQ, type MemoryCoreOperations as bR, type MemoryEntry as bS, type MemoryEntryInput as bT, type MemoryExtractOptions as bU, type MemoryInjectionOptions as bV, type MemoryListOptions as bW, type MemoryListPageOptions as bX, type MemoryOperations as bY, type MemoryRecallOptions as bZ, type MemoryType as b_, type KnowledgeDocumentRemoveOptions as ba, type KnowledgeDocumentRevision as bb, type KnowledgeEntity as bc, type KnowledgeIngestBatchProgress as bd, type KnowledgeIngestBatchResult as be, type KnowledgeIngestFileInput as bf, type KnowledgeIngestInput as bg, type KnowledgeIngestResult as bh, type KnowledgeOperations as bi, type KnowledgeRepairOptions as bj, type KnowledgeRepairProgress as bk, type KnowledgeRepairResult as bl, type KnowledgeRetrieveItem as bm, type KnowledgeRetrieveOptions as bn, type KnowledgeRetrieveResult as bo, type KnowledgeSetupOptions as bp, type KnowledgeStore as bq, type LLMConfig as br, LLMConfigSchema as bs, type LLMOperations as bt, type MCPConfig as bu, MCPConfigSchema as bv, type MCPContext as bw, type MCPOperations as bx, type MCPPrompt as by, type MCPPromptArgument as bz, type A2ACallOptions as c, type TempModelConfig as c$, type MemoryUpdateInput as c0, type MessageContent as c1, type MessageRole as c2, type ModelEntry as c3, ModelEntrySchema as c4, type ModelScenario as c5, ModelScenarioSchema as c6, type ObjectRef as c7, OptionalSecretSchema as c8, type OutputFormat as c9, type ResolvedModelConfig as cA, type RetrievalConfig as cB, RetrievalConfigSchema as cC, type RetrievalOperations as cD, type RetrievalRequest as cE, type RetrievalResult as cF, type RetrievalResultItem as cG, type RetrievalSource as cH, type RetrievalSourceConfig as cI, RetrievalSourceSchema as cJ, type SSEDecoder as cK, type SSEEvent as cL, type ScopedMemoryBinding as cM, type ScopedMemoryOperations as cN, type SessionInfo as cO, type StoreFilter as cP, type StorePage as cQ, type StoreScope as cR, type StreamOperations as cS, type StreamProcessor as cT, type StreamResult as cU, type SummaryConfig as cV, SummaryConfigSchema as cW, type SummaryOperations as cX, type SummaryOptions as cY, type SummaryResult as cZ, type SystemMessage as c_, type PersonaOperations as ca, type PersonaProfile as cb, type PersonaProfileInput as cc, type PersonaProfileUpdate as cd, type PersonaScopeOptions as ce, type RagContextItem as cf, type RagOperations as cg, type RagOptions as ch, type RagResult as ci, type RagStreamEvent as cj, type ReasoningOperations as ck, type ReasoningOptions as cl, type ReasoningResult as cm, type ReasoningStep as cn, type ReasoningStepType as co, type ReasoningStrategy as cp, type ReasoningStreamEvent as cq, type ReferenceImage as cr, type RerankDocument as cs, type RerankItem as ct, type RerankOperations as cu, type RerankRequest as cv, type RerankResponse as cw, type ResolveRequiredModelEntryOptions as cx, type ResolvedAudioModel as cy, type ResolvedImageModel as cz, type A2ACallResult as d, type TextContent as d0, type TokenConfig as d1, TokenConfigSchema as d2, type TokenOperations as d3, type TokenUsage as d4, type Tool as d5, type ToolAuthorizationRequest as d6, type ToolAuthorizer as d7, type ToolCall as d8, type ToolDefinition as d9, type ToolErrorType as da, type ToolExecutionContext as db, type ToolExecutionOptions as dc, type ToolMessage as dd, type ToolRegistryOperations as de, type ToolRegistryOptions as df, type ToolsOperations as dg, type UserMessage as dh, type WhereClause as di, type WhereOperator as dj, type WhereValue as dk, ensureAudioCredential as dl, resolveAudioModel as dm, resolveImageModel as dn, resolveModelApi as dp, resolveModelEntry as dq, serializePlayableAudio as dr, type A2ACallerIdentity as e, type A2AConfig as f, A2AConfigSchema as g, type A2AContextInfo as h, type A2AHandleResult as i, type A2AMessageRecord as j, type A2AOperations as k, type A2ASecurityConfig as l, A2ASkillConfigSchema as m, type A2ATaskFilter as n, type AIConfig as o, type AIConfigInput as p, AIConfigSchema as q, type AIFunctions as r, type AIInitOptions as s, type AIRelStore as t, type AIRelStoreCompareAndSwap as u, type AIRelStoreOptions as v, type AIStoreProvider as w, type AIVectorBackend as x, type AIVectorStore as y, type AIVersionedRecord as z };
8243
+ /**
8244
+ * ACP 子系统;资源占用通过 CAS 持久化,不以超时推断失联进程已停止。
8245
+ * @param provider - 与 AI 模块共享的持久存储;工厂创建表后由调用方统一初始化。
8246
+ * @param config - 经 AIConfigSchema 校验的模块配置,包括只读智能体和工作区。
8247
+ * @param extensions - 可信原生配置适配器,可覆盖同名内置适配器。
8248
+ * @param modelConfig - 获取包含数据库模型的实时配置;默认使用初始化配置。
8249
+ * @param mcpLookup - 将合并清单 ID 解析为原生 MCP 定义,启动时解析环境变量。
8250
+ * @returns 智能体、工作区、会话管理器和低层连接入口;业务失败返回 HaiResult。
8251
+ * @example
8252
+ * ```ts
8253
+ * // 模块内部上下文;存储在工厂创建所有表后统一初始化。
8254
+ * async function assemble(provider: AIStoreProvider, config: AIConfig) { const acp = createACPOperations(provider, config); await provider.initialize(); return acp }
8255
+ * ```
8256
+ */
8257
+ declare function createACPOperations(provider: AIStoreProvider, config: AIConfig, extensions?: Record<string, ACPAgentAdapter>, modelConfig?: () => Promise<AIConfig>, mcpLookup?: (ids: string[]) => Promise<McpServer[]>): {
8258
+ agents: {
8259
+ /**
8260
+ * 校验模型与适配器后新增数据库智能体;配置同名条目只读。
8261
+ * @param input - 完整智能体定义,必须引用已有 Hai 模型 ID。
8262
+ * @returns 带 source/version 的新增条目;配置同 ID 返回只读错误。
8263
+ * @example
8264
+ * ```ts
8265
+ * import { ai } from '@h-ai/ai'
8266
+ * // 前提:ai 已成功初始化。
8267
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8268
+ * const result = await ai.acp.agents.register({ id: 'coder', name: 'Coder', mode: 'embedded', adapter: 'codex', modelIds: ['coding'] })
8269
+ * ```
8270
+ */
8271
+ register: (input: z.input<typeof ACPAgentSchema>) => Promise<HaiResult<AIResourceEntry<{
8272
+ mode: "custom-service";
8273
+ transport: "http" | "ws";
8274
+ url: string;
8275
+ headerEnv: Record<string, string>;
8276
+ supportedTransports: ("http" | "ws")[];
8277
+ id: string;
8278
+ name: string;
8279
+ enabled: boolean;
8280
+ adapter: string;
8281
+ modelIds: string[];
8282
+ environmentRefs: Record<string, string>;
8283
+ defaultModelId?: string | undefined;
8284
+ } | {
8285
+ mode: "embedded";
8286
+ transport: "stdio";
8287
+ id: string;
8288
+ name: string;
8289
+ enabled: boolean;
8290
+ adapter: string;
8291
+ modelIds: string[];
8292
+ environmentRefs: Record<string, string>;
8293
+ command?: string | undefined;
8294
+ args?: string[] | undefined;
8295
+ defaultModelId?: string | undefined;
8296
+ } | {
8297
+ mode: "builtin-service";
8298
+ transport: "stdio";
8299
+ image: string;
8300
+ engine: "auto" | "podman" | "docker";
8301
+ id: string;
8302
+ name: string;
8303
+ enabled: boolean;
8304
+ adapter: string;
8305
+ modelIds: string[];
8306
+ environmentRefs: Record<string, string>;
8307
+ command?: string | undefined;
8308
+ args?: string[] | undefined;
8309
+ defaultModelId?: string | undefined;
8310
+ }>>>;
8311
+ /**
8312
+ * 按 ID 读取合并清单条目;source 区分配置与数据库,数据库 get 返回 version。
8313
+ * @param id - 智能体 ID。
8314
+ * @returns 合并后的资源条目;未找到时返回资源不存在错误。
8315
+ * @example
8316
+ * ```ts
8317
+ * import { ai } from '@h-ai/ai'
8318
+ * // 前提:ai 已成功初始化。
8319
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8320
+ * const result = await ai.acp.agents.get('coder')
8321
+ * ```
8322
+ */
8323
+ get: (id: string) => Promise<HaiResult<AIResourceEntry<{
8324
+ mode: "custom-service";
8325
+ transport: "http" | "ws";
8326
+ url: string;
8327
+ headerEnv: Record<string, string>;
8328
+ supportedTransports: ("http" | "ws")[];
8329
+ id: string;
8330
+ name: string;
8331
+ enabled: boolean;
8332
+ adapter: string;
8333
+ modelIds: string[];
8334
+ environmentRefs: Record<string, string>;
8335
+ defaultModelId?: string | undefined;
8336
+ } | {
8337
+ mode: "embedded";
8338
+ transport: "stdio";
8339
+ id: string;
8340
+ name: string;
8341
+ enabled: boolean;
8342
+ adapter: string;
8343
+ modelIds: string[];
8344
+ environmentRefs: Record<string, string>;
8345
+ command?: string | undefined;
8346
+ args?: string[] | undefined;
8347
+ defaultModelId?: string | undefined;
8348
+ } | {
8349
+ mode: "builtin-service";
8350
+ transport: "stdio";
8351
+ image: string;
8352
+ engine: "auto" | "podman" | "docker";
8353
+ id: string;
8354
+ name: string;
8355
+ enabled: boolean;
8356
+ adapter: string;
8357
+ modelIds: string[];
8358
+ environmentRefs: Record<string, string>;
8359
+ command?: string | undefined;
8360
+ args?: string[] | undefined;
8361
+ defaultModelId?: string | undefined;
8362
+ }>>>;
8363
+ /**
8364
+ * 列出配置与数据库合并后的智能体;同 ID 配置优先。
8365
+ * @returns 去重后的智能体条目列表;列表项不带数据库 version。
8366
+ * @example
8367
+ * ```ts
8368
+ * import { ai } from '@h-ai/ai'
8369
+ * // 前提:ai 已成功初始化。
8370
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8371
+ * const result = await ai.acp.agents.list()
8372
+ * ```
8373
+ */
8374
+ list: () => Promise<HaiResult<AIResourceEntry<{
8375
+ mode: "custom-service";
8376
+ transport: "http" | "ws";
8377
+ url: string;
8378
+ headerEnv: Record<string, string>;
8379
+ supportedTransports: ("http" | "ws")[];
8380
+ id: string;
8381
+ name: string;
8382
+ enabled: boolean;
8383
+ adapter: string;
8384
+ modelIds: string[];
8385
+ environmentRefs: Record<string, string>;
8386
+ defaultModelId?: string | undefined;
8387
+ } | {
8388
+ mode: "embedded";
8389
+ transport: "stdio";
8390
+ id: string;
8391
+ name: string;
8392
+ enabled: boolean;
8393
+ adapter: string;
8394
+ modelIds: string[];
8395
+ environmentRefs: Record<string, string>;
8396
+ command?: string | undefined;
8397
+ args?: string[] | undefined;
8398
+ defaultModelId?: string | undefined;
8399
+ } | {
8400
+ mode: "builtin-service";
8401
+ transport: "stdio";
8402
+ image: string;
8403
+ engine: "auto" | "podman" | "docker";
8404
+ id: string;
8405
+ name: string;
8406
+ enabled: boolean;
8407
+ adapter: string;
8408
+ modelIds: string[];
8409
+ environmentRefs: Record<string, string>;
8410
+ command?: string | undefined;
8411
+ args?: string[] | undefined;
8412
+ defaultModelId?: string | undefined;
8413
+ }>[]>>;
8414
+ /**
8415
+ * 整体替换数据库智能体;可传入 get 返回的版本防止覆盖并发修改,配置条目不可改。
8416
+ * @param input - 包含原 ID 的完整替换定义。
8417
+ * @param version - get 返回的数据库版本;传入时校验并发修改。
8418
+ * @returns 更新后的资源条目;配置只读、版本冲突均返回失败。
8419
+ * @example
8420
+ * ```ts
8421
+ * import { ai } from '@h-ai/ai'
8422
+ * // 前提:ai 已成功初始化。
8423
+ * // definition 为完整替换定义;entry 为 get 成功返回的条目。
8424
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8425
+ * const result = await ai.acp.agents.update(definition, entry.version)
8426
+ * ```
8427
+ */
8428
+ update: (input: z.input<typeof ACPAgentSchema>, version?: string) => Promise<HaiResult<AIResourceEntry<{
8429
+ mode: "custom-service";
8430
+ transport: "http" | "ws";
8431
+ url: string;
8432
+ headerEnv: Record<string, string>;
8433
+ supportedTransports: ("http" | "ws")[];
8434
+ id: string;
8435
+ name: string;
8436
+ enabled: boolean;
8437
+ adapter: string;
8438
+ modelIds: string[];
8439
+ environmentRefs: Record<string, string>;
8440
+ defaultModelId?: string | undefined;
8441
+ } | {
8442
+ mode: "embedded";
8443
+ transport: "stdio";
8444
+ id: string;
8445
+ name: string;
8446
+ enabled: boolean;
8447
+ adapter: string;
8448
+ modelIds: string[];
8449
+ environmentRefs: Record<string, string>;
8450
+ command?: string | undefined;
8451
+ args?: string[] | undefined;
8452
+ defaultModelId?: string | undefined;
8453
+ } | {
8454
+ mode: "builtin-service";
8455
+ transport: "stdio";
8456
+ image: string;
8457
+ engine: "auto" | "podman" | "docker";
8458
+ id: string;
8459
+ name: string;
8460
+ enabled: boolean;
8461
+ adapter: string;
8462
+ modelIds: string[];
8463
+ environmentRefs: Record<string, string>;
8464
+ command?: string | undefined;
8465
+ args?: string[] | undefined;
8466
+ defaultModelId?: string | undefined;
8467
+ }>>>;
8468
+ /**
8469
+ * 删除无会话引用的数据库智能体定义;不删除镜像或外部服务。
8470
+ * @param id - 数据库智能体 ID。
8471
+ * @param version - 可选的期望版本。
8472
+ * @returns 删除完成的 HaiResult;存在会话引用时返回 ACP_BUSY。
8473
+ * @example
8474
+ * ```ts
8475
+ * import { ai } from '@h-ai/ai'
8476
+ * // 前提:ai 已成功初始化。
8477
+ * // entry 为 get 成功返回的数据库条目。
8478
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8479
+ * const result = await ai.acp.agents.remove('coder', entry.version)
8480
+ * ```
8481
+ */
8482
+ remove: (id: string, version?: string) => Promise<HaiResult<void>>;
8483
+ /**
8484
+ * 解析模型和原生配置,验证适配器是否兼容;不持久保存模型凭据。
8485
+ * @param id - 已登记智能体 ID。
8486
+ * @param modelId - 可选模型 ID,须在智能体 modelIds 中。
8487
+ * @returns 智能体模式与绑定模型摘要;不返回凭据或原生配置内容。
8488
+ * @example
8489
+ * ```ts
8490
+ * import { ai } from '@h-ai/ai'
8491
+ * // 前提:ai 已成功初始化。
8492
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8493
+ * const result = await ai.acp.agents.initialize('coder')
8494
+ * ```
8495
+ */
8496
+ initialize: (id: string, modelId?: string) => Promise<{
8497
+ success: false;
8498
+ error: _h_ai_core.HaiError;
8499
+ } | {
8500
+ success: true;
8501
+ data: {
8502
+ agentId: string;
8503
+ mode: "custom-service";
8504
+ modelIds: never[];
8505
+ } | {
8506
+ agentId: string;
8507
+ mode: "embedded" | "builtin-service";
8508
+ modelIds: string[];
8509
+ };
8510
+ }>;
8511
+ /**
8512
+ * 实际启动并握手后关闭连接,返回智能体能力;托管模式需指定工作区。
8513
+ * @param id - 已登记智能体 ID。
8514
+ * @param options - 回调、能力及工作区;托管模式必须传 workspaceId。
8515
+ * @returns 原生初始化结果(智能体能力、认证方法等)的 HaiResult。
8516
+ * @example
8517
+ * ```ts
8518
+ * import { ai } from '@h-ai/ai'
8519
+ * // 前提:ai 已成功初始化。
8520
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8521
+ * const result = await ai.acp.agents.check('coder', { workspaceId: 'project' })
8522
+ * ```
8523
+ */
8524
+ check: (id: string, options?: ACPClientOptions & {
8525
+ workspaceId?: string;
8526
+ }) => Promise<{
8527
+ success: false;
8528
+ error: _h_ai_core.HaiError;
8529
+ } | {
8530
+ success: true;
8531
+ data: _agentclientprotocol_sdk.InitializeResponse;
8532
+ }>;
8533
+ };
8534
+ workspaces: {
8535
+ /**
8536
+ * 新增数据库工作区并归一化存储位置;拒绝目录重叠或同一 volume 重复登记。
8537
+ * @param input - 工作区存储位置、显式 Git 主分支和环境变量引用。
8538
+ * @returns 带来源和版本的工作区条目;重叠位置返回冲突错误。
8539
+ * @example
8540
+ * ```ts
8541
+ * import { ai } from '@h-ai/ai'
8542
+ * // 前提:ai 已成功初始化。
8543
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8544
+ * const result = await ai.acp.workspaces.register({ id: 'project', storage: { type: 'directory', path: '/srv/project' } })
8545
+ * ```
8546
+ */
8547
+ register: (input: z.input<typeof ACPWorkspaceSchema>) => Promise<HaiResult<AIResourceEntry<{
8548
+ id: string;
8549
+ storage: {
8550
+ type: "directory";
8551
+ path: string;
8552
+ } | {
8553
+ type: "volume";
8554
+ name: string;
8555
+ engine: "auto" | "podman" | "docker";
8556
+ image: string;
8557
+ };
8558
+ repositories: {
8559
+ id: string;
8560
+ url: string;
8561
+ mainBranch: string;
8562
+ remote: string;
8563
+ }[];
8564
+ environmentRefs: Record<string, string>;
8565
+ }>>>;
8566
+ /**
8567
+ * 读取工作区定义及来源;配置条目无数据库版本。
8568
+ * @param id - 工作区 ID。
8569
+ * @returns 工作区资源条目;未找到时返回资源不存在错误。
8570
+ * @example
8571
+ * ```ts
8572
+ * import { ai } from '@h-ai/ai'
8573
+ * // 前提:ai 已成功初始化。
8574
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8575
+ * const result = await ai.acp.workspaces.get('project')
8576
+ * ```
8577
+ */
8578
+ get: (id: string) => Promise<HaiResult<AIResourceEntry<{
8579
+ id: string;
8580
+ storage: {
8581
+ type: "directory";
8582
+ path: string;
8583
+ } | {
8584
+ type: "volume";
8585
+ name: string;
8586
+ engine: "auto" | "podman" | "docker";
8587
+ image: string;
8588
+ };
8589
+ repositories: {
8590
+ id: string;
8591
+ url: string;
8592
+ mainBranch: string;
8593
+ remote: string;
8594
+ }[];
8595
+ environmentRefs: Record<string, string>;
8596
+ }>>>;
8597
+ /**
8598
+ * 列出配置与数据库合并后的工作区;不创建路径或克隆工程。
8599
+ * @returns 去重后的工作区列表;列表项不含数据库 version。
8600
+ * @example
8601
+ * ```ts
8602
+ * import { ai } from '@h-ai/ai'
8603
+ * // 前提:ai 已成功初始化。
8604
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8605
+ * const result = await ai.acp.workspaces.list()
8606
+ * ```
8607
+ */
8608
+ list: () => Promise<HaiResult<AIResourceEntry<{
8609
+ id: string;
8610
+ storage: {
8611
+ type: "directory";
8612
+ path: string;
8613
+ } | {
8614
+ type: "volume";
8615
+ name: string;
8616
+ engine: "auto" | "podman" | "docker";
8617
+ image: string;
8618
+ };
8619
+ repositories: {
8620
+ id: string;
8621
+ url: string;
8622
+ mainBranch: string;
8623
+ remote: string;
8624
+ }[];
8625
+ environmentRefs: Record<string, string>;
8626
+ }>[]>>;
8627
+ /**
8628
+ * 整体替换无会话引用的数据库工作区,重新检查存储位置重叠;配置条目不可修改。
8629
+ * @param input - 包含原 ID 的完整替换定义。
8630
+ * @param version - 可选的数据库期望版本。
8631
+ * @returns 更新后的工作区;有会话引用、位置冲突或版本冲突时失败。
8632
+ * @example
8633
+ * ```ts
8634
+ * import { ai } from '@h-ai/ai'
8635
+ * // 前提:ai 已成功初始化。
8636
+ * // definition 为完整替换定义;entry 为 get 成功返回的条目。
8637
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8638
+ * const result = await ai.acp.workspaces.update(definition, entry.version)
8639
+ * ```
8640
+ */
8641
+ update: (input: z.input<typeof ACPWorkspaceSchema>, version?: string) => Promise<HaiResult<AIResourceEntry<{
8642
+ id: string;
8643
+ storage: {
8644
+ type: "directory";
8645
+ path: string;
8646
+ } | {
8647
+ type: "volume";
8648
+ name: string;
8649
+ engine: "auto" | "podman" | "docker";
8650
+ image: string;
8651
+ };
8652
+ repositories: {
8653
+ id: string;
8654
+ url: string;
8655
+ mainBranch: string;
8656
+ remote: string;
8657
+ }[];
8658
+ environmentRefs: Record<string, string>;
8659
+ }>>>;
8660
+ /**
8661
+ * 创建目录并克隆缺失工程;已有内容不自动 pull 或覆盖,Git 不存在时返回明确错误。
8662
+ * @param id - 已登记工作区 ID。
8663
+ * @returns 准备后的 main 绝对目录;克隆失败保留现场供检查。
8664
+ * @example
8665
+ * ```ts
8666
+ * import { ai } from '@h-ai/ai'
8667
+ * // 前提:ai 已成功初始化。
8668
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8669
+ * const result = await ai.acp.workspaces.prepare('project')
8670
+ * ```
8671
+ */
8672
+ prepare: (id: string) => Promise<{
8673
+ success: false;
8674
+ error: _h_ai_core.HaiError;
8675
+ } | {
8676
+ success: true;
8677
+ data: string;
8678
+ }>;
8679
+ /**
8680
+ * 将有限大小的文件写入 main/files,拒绝覆盖、路径逃逸和符号链接;失败前已写入文件会保留。
8681
+ * @param id - 已登记工作区 ID。
8682
+ * @param files - 相对路径和 UTF-8 文本或二进制;不允许覆盖或路径逃逸。
8683
+ * @returns 已导入相对路径列表;写入中途失败不回滚已有文件。
8684
+ * @example
8685
+ * ```ts
8686
+ * import { ai } from '@h-ai/ai'
8687
+ * // 前提:ai 已成功初始化。
8688
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8689
+ * const result = await ai.acp.workspaces.importFiles('project', [{ path: 'notes.txt', content: '需求' }])
8690
+ * ```
8691
+ */
8692
+ importFiles: (id: string, files: Array<{
8693
+ path: string;
8694
+ content: string | Uint8Array;
8695
+ }>) => Promise<{
8696
+ success: false;
8697
+ error: _h_ai_core.HaiError;
8698
+ } | {
8699
+ success: true;
8700
+ data: {
8701
+ imported: string[];
8702
+ };
8703
+ }>;
8704
+ /**
8705
+ * 移除无会话引用的数据库定义,保留磁盘目录、Git 检出和 volume。
8706
+ * @param id - 数据库工作区 ID。
8707
+ * @param version - 可选的数据库期望版本。
8708
+ * @returns 删除定义的 HaiResult;引用存在时失败,文件始终保留。
8709
+ * @example
8710
+ * ```ts
8711
+ * import { ai } from '@h-ai/ai'
8712
+ * // 前提:ai 已成功初始化。
8713
+ * // entry 为 get 成功返回的数据库条目。
8714
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8715
+ * const result = await ai.acp.workspaces.remove('project', entry.version)
8716
+ * ```
8717
+ */
8718
+ remove: (id: string, version?: string) => Promise<HaiResult<void>>;
8719
+ };
8720
+ sessions: {
8721
+ /**
8722
+ * 绑定模型、工作区和 MCP,准备目录后建立原生会话;newWorktree 可选择独立工程分支。
8723
+ * @param options - 智能体、工作区、模型、MCP 及可信回调;newWorktree 默认 false。
8724
+ * @returns 可用于 prompt/stream/publish 的会话句柄;启动失败保留失败记录。
8725
+ * @example
8726
+ * ```ts
8727
+ * import { ai } from '@h-ai/ai'
8728
+ * // 前提:ai 已成功初始化。
8729
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8730
+ * const result = await ai.acp.sessions.create({ agentId: 'coder', workspaceId: 'project', newWorktree: true })
8731
+ * ```
8732
+ */
8733
+ create: (options: ACPCreateSessionOptions) => Promise<{
8734
+ success: false;
8735
+ error: _h_ai_core.HaiError;
8736
+ } | {
8737
+ success: true;
8738
+ data: {
8739
+ id: string;
8740
+ /**
8741
+ * 读取持久会话信息,包括状态、原生 ID 和当前容器。
8742
+ * @returns 包含 ACPSessionInfo 的 HaiResult;记录不存在时返回失败。
8743
+ * @example
8744
+ * ```ts
8745
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8746
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8747
+ * const result = await session.info()
8748
+ * ```
8749
+ */
8750
+ info: () => Promise<{
8751
+ success: false;
8752
+ error: _h_ai_core.HaiError;
8753
+ } | {
8754
+ success: true;
8755
+ data: ACPSessionInfo;
8756
+ }>;
8757
+ /**
8758
+ * 发送一轮内容,等待最终停止原因、最终消息文本和完整事件;同一会话不允许并发轮次。
8759
+ * @param content - 原生 ACP 内容块,不允许同一会话并发执行。
8760
+ * @param signal - 本轮取消信号;取消超时会关闭连接。
8761
+ * @returns 最终文本、停止原因和事件的 HaiResult。
8762
+ * @example
8763
+ * ```ts
8764
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8765
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8766
+ * const result = await session.prompt([{ type: 'text', text: '检查工程' }])
8767
+ * ```
8768
+ */
8769
+ prompt: (content: ContentBlock[], signal?: AbortSignal) => Promise<{
8770
+ success: false;
8771
+ error: _h_ai_core.HaiError;
8772
+ } | {
8773
+ success: true;
8774
+ data: {
8775
+ text: string;
8776
+ events: SessionNotification[];
8777
+ stopReason: _agentclientprotocol_sdk.StopReason;
8778
+ _meta?: {
8779
+ [key: string]: unknown;
8780
+ } | null;
8781
+ };
8782
+ }>;
8783
+ /**
8784
+ * 仅接受正常结束的一份 JSON(允许完整 JSON 代码围栏),再按 schema 校验;前后夹杂文本视为失败。
8785
+ * @param content - 要求返回结构化 JSON 的原生内容块。
8786
+ * @param schema - 最终 JSON 的 Zod 校验器。
8787
+ * @param signal - 可选的本轮取消信号。
8788
+ * @returns 经过 schema 校验的数据;输出不合法时返回 ACP_OUTPUT_INVALID。
8789
+ * @example
8790
+ * ```ts
8791
+ * import { z } from 'zod'
8792
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8793
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8794
+ * const result = await session.promptStructured([{ type: 'text', text: '返回 JSON' }], z.object({ ok: z.boolean() }))
8795
+ * ```
8796
+ */
8797
+ promptStructured: <T>(content: ContentBlock[], schema: z.ZodType<T>, signal?: AbortSignal) => Promise<{
8798
+ success: false;
8799
+ error: _h_ai_core.HaiError;
8800
+ } | {
8801
+ success: true;
8802
+ data: Awaited<T>;
8803
+ }>;
8804
+ /**
8805
+ * 迭代本轮 ACP 事件;中途退出迭代会取消本轮,失败会抛错,调用方需 try/finally 清理。
8806
+ * @param content - 本轮原生内容块。
8807
+ * @param signal - 可选取消信号;结束迭代同样会取消本轮。
8808
+ * @returns 异步事件迭代器;流式失败抛出异常,需在调用方捕获。
8809
+ * @throws 连接关闭、取消超时、输出超限或原生请求失败。
8810
+ * @example
8811
+ * ```ts
8812
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8813
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8814
+ * for await (const event of session.stream([{ type: 'text', text: '检查工程' }])) { const update = event.update }
8815
+ * ```
8816
+ */
8817
+ stream(content: ContentBlock[], signal?: AbortSignal): AsyncGenerator<SessionNotification>;
8818
+ /**
8819
+ * 请求取消正在执行的一轮;超时未停止时关闭所拥有的传输。
8820
+ * @returns 取消完成的 HaiResult;超时或清理失败返回错误。
8821
+ * @example
8822
+ * ```ts
8823
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8824
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8825
+ * const result = await session.cancel()
8826
+ * ```
8827
+ */
8828
+ cancel: () => Promise<{
8829
+ success: false;
8830
+ error: _h_ai_core.HaiError;
8831
+ } | {
8832
+ success: true;
8833
+ data: void;
8834
+ }>;
8835
+ /**
8836
+ * 选择智能体公布的原生模式 ID;不兼容时返回协议失败。
8837
+ * @param mode - 握手或事件中公布的原生模式 ID。
8838
+ * @returns 原生模式设置结果的 HaiResult。
8839
+ * @example
8840
+ * ```ts
8841
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8842
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8843
+ * const result = await session.setMode('code')
8844
+ * ```
8845
+ */
8846
+ setMode: (mode: string) => Promise<{
8847
+ success: false;
8848
+ error: _h_ai_core.HaiError;
8849
+ } | {
8850
+ success: true;
8851
+ data: _agentclientprotocol_sdk.SetSessionModeResponse;
8852
+ }>;
8853
+ /**
8854
+ * 设置智能体公布的原生配置选项;值必须符合该智能体的选项定义。
8855
+ * @param key - 原生配置选项 ID。
8856
+ * @param value - 该选项允许的值。
8857
+ * @returns 原生配置更新结果的 HaiResult。
8858
+ * @example
8859
+ * ```ts
8860
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8861
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8862
+ * const result = await session.setConfigOption('model', 'coding')
8863
+ * ```
8864
+ */
8865
+ setConfigOption: (key: string, value: string) => Promise<{
8866
+ success: false;
8867
+ error: _h_ai_core.HaiError;
8868
+ } | {
8869
+ success: true;
8870
+ data: _agentclientprotocol_sdk.SetSessionConfigOptionResponse;
8871
+ }>;
8872
+ /**
8873
+ * 先关闭会话执行环境,再 fetch 并仅快进各工程明确配置的主分支;不修改会话分支。
8874
+ * @returns 各仓更新报告;部分失败时报告位于 error.cause.reports。
8875
+ * @example
8876
+ * ```ts
8877
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8878
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8879
+ * const result = await session.updateMain()
8880
+ * ```
8881
+ */
8882
+ updateMain: () => Promise<{
8883
+ success: false;
8884
+ error: _h_ai_core.HaiError;
8885
+ } | {
8886
+ success: true;
8887
+ data: ACPGitReport[];
8888
+ }>;
8889
+ /**
8890
+ * 关闭执行环境后逐仓提交并推送;仅支持受管理的独立会话,部分失败保留各仓报告,禁止强推。
8891
+ * @param request - 发布模式、提交说明和作者;仅支持受管理的独立会话。
8892
+ * @returns 各仓提交/推送报告;部分失败时报告位于 error.cause.reports。
8893
+ * @example
8894
+ * ```ts
8895
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8896
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8897
+ * const result = await session.publish({ mode: 'merge-main', message: '完成任务', author: { name: 'Developer', email: 'dev@example.com' } })
8898
+ * ```
8899
+ */
8900
+ publish: (request: z.input<typeof ACPPublishSchema>) => Promise<{
8901
+ success: false;
8902
+ error: _h_ai_core.HaiError;
8903
+ } | {
8904
+ success: true;
8905
+ data: ACPGitReport[];
8906
+ }>;
8907
+ /**
8908
+ * 停止拥有的进程或容器,释放占用;保留工作目录和原生状态,供后续显式恢复。
8909
+ * @returns 关闭完成的 HaiResult;清理失败时不释放仍在占用的资源。
8910
+ * @example
8911
+ * ```ts
8912
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8913
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8914
+ * const result = await session.close()
8915
+ * ```
8916
+ */
8917
+ close: () => Promise<{
8918
+ success: false;
8919
+ error: _h_ai_core.HaiError;
8920
+ } | {
8921
+ success: true;
8922
+ data: void;
8923
+ }>;
8924
+ };
8925
+ }>;
8926
+ /**
8927
+ * 获取持久会话的管理句柄;已关闭会话需要 resume 后才能执行 prompt。
8928
+ * @param id - 框架会话 ID,不是智能体原生 ID。
8929
+ * @returns 管理句柄的 HaiResult;不会自动重新启动智能体。
8930
+ * @example
8931
+ * ```ts
8932
+ * import { ai } from '@h-ai/ai'
8933
+ * // 前提:ai 已成功初始化。
8934
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8935
+ * const result = await ai.acp.sessions.get('task-1')
8936
+ * ```
8937
+ */
8938
+ get: (id: string) => Promise<{
8939
+ success: false;
8940
+ error: _h_ai_core.HaiError;
8941
+ } | {
8942
+ success: true;
8943
+ data: {
8944
+ id: string;
8945
+ /**
8946
+ * 读取持久会话信息,包括状态、原生 ID 和当前容器。
8947
+ * @returns 包含 ACPSessionInfo 的 HaiResult;记录不存在时返回失败。
8948
+ * @example
8949
+ * ```ts
8950
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8951
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8952
+ * const result = await session.info()
8953
+ * ```
8954
+ */
8955
+ info: () => Promise<{
8956
+ success: false;
8957
+ error: _h_ai_core.HaiError;
8958
+ } | {
8959
+ success: true;
8960
+ data: ACPSessionInfo;
8961
+ }>;
8962
+ /**
8963
+ * 发送一轮内容,等待最终停止原因、最终消息文本和完整事件;同一会话不允许并发轮次。
8964
+ * @param content - 原生 ACP 内容块,不允许同一会话并发执行。
8965
+ * @param signal - 本轮取消信号;取消超时会关闭连接。
8966
+ * @returns 最终文本、停止原因和事件的 HaiResult。
8967
+ * @example
8968
+ * ```ts
8969
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8970
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8971
+ * const result = await session.prompt([{ type: 'text', text: '检查工程' }])
8972
+ * ```
8973
+ */
8974
+ prompt: (content: ContentBlock[], signal?: AbortSignal) => Promise<{
8975
+ success: false;
8976
+ error: _h_ai_core.HaiError;
8977
+ } | {
8978
+ success: true;
8979
+ data: {
8980
+ text: string;
8981
+ events: SessionNotification[];
8982
+ stopReason: _agentclientprotocol_sdk.StopReason;
8983
+ _meta?: {
8984
+ [key: string]: unknown;
8985
+ } | null;
8986
+ };
8987
+ }>;
8988
+ /**
8989
+ * 仅接受正常结束的一份 JSON(允许完整 JSON 代码围栏),再按 schema 校验;前后夹杂文本视为失败。
8990
+ * @param content - 要求返回结构化 JSON 的原生内容块。
8991
+ * @param schema - 最终 JSON 的 Zod 校验器。
8992
+ * @param signal - 可选的本轮取消信号。
8993
+ * @returns 经过 schema 校验的数据;输出不合法时返回 ACP_OUTPUT_INVALID。
8994
+ * @example
8995
+ * ```ts
8996
+ * import { z } from 'zod'
8997
+ * // session 为 sessions.create/get/resume 成功返回的 data。
8998
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
8999
+ * const result = await session.promptStructured([{ type: 'text', text: '返回 JSON' }], z.object({ ok: z.boolean() }))
9000
+ * ```
9001
+ */
9002
+ promptStructured: <T>(content: ContentBlock[], schema: z.ZodType<T>, signal?: AbortSignal) => Promise<{
9003
+ success: false;
9004
+ error: _h_ai_core.HaiError;
9005
+ } | {
9006
+ success: true;
9007
+ data: Awaited<T>;
9008
+ }>;
9009
+ /**
9010
+ * 迭代本轮 ACP 事件;中途退出迭代会取消本轮,失败会抛错,调用方需 try/finally 清理。
9011
+ * @param content - 本轮原生内容块。
9012
+ * @param signal - 可选取消信号;结束迭代同样会取消本轮。
9013
+ * @returns 异步事件迭代器;流式失败抛出异常,需在调用方捕获。
9014
+ * @throws 连接关闭、取消超时、输出超限或原生请求失败。
9015
+ * @example
9016
+ * ```ts
9017
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9018
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9019
+ * for await (const event of session.stream([{ type: 'text', text: '检查工程' }])) { const update = event.update }
9020
+ * ```
9021
+ */
9022
+ stream(content: ContentBlock[], signal?: AbortSignal): AsyncGenerator<SessionNotification>;
9023
+ /**
9024
+ * 请求取消正在执行的一轮;超时未停止时关闭所拥有的传输。
9025
+ * @returns 取消完成的 HaiResult;超时或清理失败返回错误。
9026
+ * @example
9027
+ * ```ts
9028
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9029
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9030
+ * const result = await session.cancel()
9031
+ * ```
9032
+ */
9033
+ cancel: () => Promise<{
9034
+ success: false;
9035
+ error: _h_ai_core.HaiError;
9036
+ } | {
9037
+ success: true;
9038
+ data: void;
9039
+ }>;
9040
+ /**
9041
+ * 选择智能体公布的原生模式 ID;不兼容时返回协议失败。
9042
+ * @param mode - 握手或事件中公布的原生模式 ID。
9043
+ * @returns 原生模式设置结果的 HaiResult。
9044
+ * @example
9045
+ * ```ts
9046
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9047
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9048
+ * const result = await session.setMode('code')
9049
+ * ```
9050
+ */
9051
+ setMode: (mode: string) => Promise<{
9052
+ success: false;
9053
+ error: _h_ai_core.HaiError;
9054
+ } | {
9055
+ success: true;
9056
+ data: _agentclientprotocol_sdk.SetSessionModeResponse;
9057
+ }>;
9058
+ /**
9059
+ * 设置智能体公布的原生配置选项;值必须符合该智能体的选项定义。
9060
+ * @param key - 原生配置选项 ID。
9061
+ * @param value - 该选项允许的值。
9062
+ * @returns 原生配置更新结果的 HaiResult。
9063
+ * @example
9064
+ * ```ts
9065
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9066
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9067
+ * const result = await session.setConfigOption('model', 'coding')
9068
+ * ```
9069
+ */
9070
+ setConfigOption: (key: string, value: string) => Promise<{
9071
+ success: false;
9072
+ error: _h_ai_core.HaiError;
9073
+ } | {
9074
+ success: true;
9075
+ data: _agentclientprotocol_sdk.SetSessionConfigOptionResponse;
9076
+ }>;
9077
+ /**
9078
+ * 先关闭会话执行环境,再 fetch 并仅快进各工程明确配置的主分支;不修改会话分支。
9079
+ * @returns 各仓更新报告;部分失败时报告位于 error.cause.reports。
9080
+ * @example
9081
+ * ```ts
9082
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9083
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9084
+ * const result = await session.updateMain()
9085
+ * ```
9086
+ */
9087
+ updateMain: () => Promise<{
9088
+ success: false;
9089
+ error: _h_ai_core.HaiError;
9090
+ } | {
9091
+ success: true;
9092
+ data: ACPGitReport[];
9093
+ }>;
9094
+ /**
9095
+ * 关闭执行环境后逐仓提交并推送;仅支持受管理的独立会话,部分失败保留各仓报告,禁止强推。
9096
+ * @param request - 发布模式、提交说明和作者;仅支持受管理的独立会话。
9097
+ * @returns 各仓提交/推送报告;部分失败时报告位于 error.cause.reports。
9098
+ * @example
9099
+ * ```ts
9100
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9101
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9102
+ * const result = await session.publish({ mode: 'merge-main', message: '完成任务', author: { name: 'Developer', email: 'dev@example.com' } })
9103
+ * ```
9104
+ */
9105
+ publish: (request: z.input<typeof ACPPublishSchema>) => Promise<{
9106
+ success: false;
9107
+ error: _h_ai_core.HaiError;
9108
+ } | {
9109
+ success: true;
9110
+ data: ACPGitReport[];
9111
+ }>;
9112
+ /**
9113
+ * 停止拥有的进程或容器,释放占用;保留工作目录和原生状态,供后续显式恢复。
9114
+ * @returns 关闭完成的 HaiResult;清理失败时不释放仍在占用的资源。
9115
+ * @example
9116
+ * ```ts
9117
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9118
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9119
+ * const result = await session.close()
9120
+ * ```
9121
+ */
9122
+ close: () => Promise<{
9123
+ success: false;
9124
+ error: _h_ai_core.HaiError;
9125
+ } | {
9126
+ success: true;
9127
+ data: void;
9128
+ }>;
9129
+ };
9130
+ }>;
9131
+ /**
9132
+ * 列出持久会话,可按工作区 ID 过滤。
9133
+ * @param workspaceId - 可选工作区筛选条件;省略返回全部会话。
9134
+ * @returns 持久 ACPSessionInfo 列表的 HaiResult。
9135
+ * @example
9136
+ * ```ts
9137
+ * import { ai } from '@h-ai/ai'
9138
+ * // 前提:ai 已成功初始化。
9139
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9140
+ * const result = await ai.acp.sessions.list('project')
9141
+ * ```
9142
+ */
9143
+ list: (workspaceId?: string) => Promise<{
9144
+ success: false;
9145
+ error: _h_ai_core.HaiError;
9146
+ } | {
9147
+ success: true;
9148
+ data: ACPSessionInfo[];
9149
+ }>;
9150
+ /**
9151
+ * 使用原生会话 ID 和保留状态恢复;智能体定义或模型能力已改变时拒绝恢复。
9152
+ * @param id - 已关闭或失败的框架会话 ID。
9153
+ * @param options - 本次连接的回调、能力和取消信号,不从数据库恢复回调。
9154
+ * @returns 恢复后的会话句柄;原生服务不支持恢复或配置变化时失败。
9155
+ * @example
9156
+ * ```ts
9157
+ * import { ai } from '@h-ai/ai'
9158
+ * // 前提:ai 已成功初始化。
9159
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9160
+ * const result = await ai.acp.sessions.resume('task-1')
9161
+ * ```
9162
+ */
9163
+ resume: (id: string, options?: ACPClientOptions) => Promise<{
9164
+ success: false;
9165
+ error: _h_ai_core.HaiError;
9166
+ } | {
9167
+ success: true;
9168
+ data: {
9169
+ id: string;
9170
+ /**
9171
+ * 读取持久会话信息,包括状态、原生 ID 和当前容器。
9172
+ * @returns 包含 ACPSessionInfo 的 HaiResult;记录不存在时返回失败。
9173
+ * @example
9174
+ * ```ts
9175
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9176
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9177
+ * const result = await session.info()
9178
+ * ```
9179
+ */
9180
+ info: () => Promise<{
9181
+ success: false;
9182
+ error: _h_ai_core.HaiError;
9183
+ } | {
9184
+ success: true;
9185
+ data: ACPSessionInfo;
9186
+ }>;
9187
+ /**
9188
+ * 发送一轮内容,等待最终停止原因、最终消息文本和完整事件;同一会话不允许并发轮次。
9189
+ * @param content - 原生 ACP 内容块,不允许同一会话并发执行。
9190
+ * @param signal - 本轮取消信号;取消超时会关闭连接。
9191
+ * @returns 最终文本、停止原因和事件的 HaiResult。
9192
+ * @example
9193
+ * ```ts
9194
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9195
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9196
+ * const result = await session.prompt([{ type: 'text', text: '检查工程' }])
9197
+ * ```
9198
+ */
9199
+ prompt: (content: ContentBlock[], signal?: AbortSignal) => Promise<{
9200
+ success: false;
9201
+ error: _h_ai_core.HaiError;
9202
+ } | {
9203
+ success: true;
9204
+ data: {
9205
+ text: string;
9206
+ events: SessionNotification[];
9207
+ stopReason: _agentclientprotocol_sdk.StopReason;
9208
+ _meta?: {
9209
+ [key: string]: unknown;
9210
+ } | null;
9211
+ };
9212
+ }>;
9213
+ /**
9214
+ * 仅接受正常结束的一份 JSON(允许完整 JSON 代码围栏),再按 schema 校验;前后夹杂文本视为失败。
9215
+ * @param content - 要求返回结构化 JSON 的原生内容块。
9216
+ * @param schema - 最终 JSON 的 Zod 校验器。
9217
+ * @param signal - 可选的本轮取消信号。
9218
+ * @returns 经过 schema 校验的数据;输出不合法时返回 ACP_OUTPUT_INVALID。
9219
+ * @example
9220
+ * ```ts
9221
+ * import { z } from 'zod'
9222
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9223
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9224
+ * const result = await session.promptStructured([{ type: 'text', text: '返回 JSON' }], z.object({ ok: z.boolean() }))
9225
+ * ```
9226
+ */
9227
+ promptStructured: <T>(content: ContentBlock[], schema: z.ZodType<T>, signal?: AbortSignal) => Promise<{
9228
+ success: false;
9229
+ error: _h_ai_core.HaiError;
9230
+ } | {
9231
+ success: true;
9232
+ data: Awaited<T>;
9233
+ }>;
9234
+ /**
9235
+ * 迭代本轮 ACP 事件;中途退出迭代会取消本轮,失败会抛错,调用方需 try/finally 清理。
9236
+ * @param content - 本轮原生内容块。
9237
+ * @param signal - 可选取消信号;结束迭代同样会取消本轮。
9238
+ * @returns 异步事件迭代器;流式失败抛出异常,需在调用方捕获。
9239
+ * @throws 连接关闭、取消超时、输出超限或原生请求失败。
9240
+ * @example
9241
+ * ```ts
9242
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9243
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9244
+ * for await (const event of session.stream([{ type: 'text', text: '检查工程' }])) { const update = event.update }
9245
+ * ```
9246
+ */
9247
+ stream(content: ContentBlock[], signal?: AbortSignal): AsyncGenerator<SessionNotification>;
9248
+ /**
9249
+ * 请求取消正在执行的一轮;超时未停止时关闭所拥有的传输。
9250
+ * @returns 取消完成的 HaiResult;超时或清理失败返回错误。
9251
+ * @example
9252
+ * ```ts
9253
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9254
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9255
+ * const result = await session.cancel()
9256
+ * ```
9257
+ */
9258
+ cancel: () => Promise<{
9259
+ success: false;
9260
+ error: _h_ai_core.HaiError;
9261
+ } | {
9262
+ success: true;
9263
+ data: void;
9264
+ }>;
9265
+ /**
9266
+ * 选择智能体公布的原生模式 ID;不兼容时返回协议失败。
9267
+ * @param mode - 握手或事件中公布的原生模式 ID。
9268
+ * @returns 原生模式设置结果的 HaiResult。
9269
+ * @example
9270
+ * ```ts
9271
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9272
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9273
+ * const result = await session.setMode('code')
9274
+ * ```
9275
+ */
9276
+ setMode: (mode: string) => Promise<{
9277
+ success: false;
9278
+ error: _h_ai_core.HaiError;
9279
+ } | {
9280
+ success: true;
9281
+ data: _agentclientprotocol_sdk.SetSessionModeResponse;
9282
+ }>;
9283
+ /**
9284
+ * 设置智能体公布的原生配置选项;值必须符合该智能体的选项定义。
9285
+ * @param key - 原生配置选项 ID。
9286
+ * @param value - 该选项允许的值。
9287
+ * @returns 原生配置更新结果的 HaiResult。
9288
+ * @example
9289
+ * ```ts
9290
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9291
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9292
+ * const result = await session.setConfigOption('model', 'coding')
9293
+ * ```
9294
+ */
9295
+ setConfigOption: (key: string, value: string) => Promise<{
9296
+ success: false;
9297
+ error: _h_ai_core.HaiError;
9298
+ } | {
9299
+ success: true;
9300
+ data: _agentclientprotocol_sdk.SetSessionConfigOptionResponse;
9301
+ }>;
9302
+ /**
9303
+ * 先关闭会话执行环境,再 fetch 并仅快进各工程明确配置的主分支;不修改会话分支。
9304
+ * @returns 各仓更新报告;部分失败时报告位于 error.cause.reports。
9305
+ * @example
9306
+ * ```ts
9307
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9308
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9309
+ * const result = await session.updateMain()
9310
+ * ```
9311
+ */
9312
+ updateMain: () => Promise<{
9313
+ success: false;
9314
+ error: _h_ai_core.HaiError;
9315
+ } | {
9316
+ success: true;
9317
+ data: ACPGitReport[];
9318
+ }>;
9319
+ /**
9320
+ * 关闭执行环境后逐仓提交并推送;仅支持受管理的独立会话,部分失败保留各仓报告,禁止强推。
9321
+ * @param request - 发布模式、提交说明和作者;仅支持受管理的独立会话。
9322
+ * @returns 各仓提交/推送报告;部分失败时报告位于 error.cause.reports。
9323
+ * @example
9324
+ * ```ts
9325
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9326
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9327
+ * const result = await session.publish({ mode: 'merge-main', message: '完成任务', author: { name: 'Developer', email: 'dev@example.com' } })
9328
+ * ```
9329
+ */
9330
+ publish: (request: z.input<typeof ACPPublishSchema>) => Promise<{
9331
+ success: false;
9332
+ error: _h_ai_core.HaiError;
9333
+ } | {
9334
+ success: true;
9335
+ data: ACPGitReport[];
9336
+ }>;
9337
+ /**
9338
+ * 停止拥有的进程或容器,释放占用;保留工作目录和原生状态,供后续显式恢复。
9339
+ * @returns 关闭完成的 HaiResult;清理失败时不释放仍在占用的资源。
9340
+ * @example
9341
+ * ```ts
9342
+ * // session 为 sessions.create/get/resume 成功返回的 data。
9343
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9344
+ * const result = await session.close()
9345
+ * ```
9346
+ */
9347
+ close: () => Promise<{
9348
+ success: false;
9349
+ error: _h_ai_core.HaiError;
9350
+ } | {
9351
+ success: true;
9352
+ data: void;
9353
+ }>;
9354
+ };
9355
+ }>;
9356
+ /**
9357
+ * 关闭本进程拥有的会话并释放锁,不删除历史和工程内容。
9358
+ * @param id - 框架会话 ID。
9359
+ * @returns 关闭完成的 HaiResult;不允许关闭其他进程拥有的执行环境。
9360
+ * @example
9361
+ * ```ts
9362
+ * import { ai } from '@h-ai/ai'
9363
+ * // 前提:ai 已成功初始化。
9364
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9365
+ * const result = await ai.acp.sessions.close('task-1')
9366
+ * ```
9367
+ */
9368
+ close: (id: string) => Promise<{
9369
+ success: false;
9370
+ error: _h_ai_core.HaiError;
9371
+ } | {
9372
+ success: true;
9373
+ data: void;
9374
+ }>;
9375
+ /**
9376
+ * 仅删除已关闭或失败的会话记录;不删除工作树及原生文件,不替代 Git worktree 清理。
9377
+ * @param id - 框架会话 ID。
9378
+ * @returns 删除完成的 HaiResult;活动会话返回忙碌错误。
9379
+ * @example
9380
+ * ```ts
9381
+ * import { ai } from '@h-ai/ai'
9382
+ * // 前提:ai 已成功初始化。
9383
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9384
+ * const result = await ai.acp.sessions.remove('task-1')
9385
+ * ```
9386
+ */
9387
+ remove: (id: string) => Promise<{
9388
+ success: false;
9389
+ error: _h_ai_core.HaiError;
9390
+ } | {
9391
+ success: true;
9392
+ data: void;
9393
+ }>;
9394
+ };
9395
+ /**
9396
+ * 连接原生 stdio/HTTP/WS 服务;不创建工作区或提供传输兼容桥。
9397
+ * @param transport - 智能体实际支持的原生传输与命令或地址。
9398
+ * @param options - 可信回调、声明能力和初始化取消信号。
9399
+ * @returns 低层连接句柄的 HaiResult;连接失败不自动转换传输。
9400
+ * @example
9401
+ * ```ts
9402
+ * import { ai } from '@h-ai/ai'
9403
+ * // 前提:ai 已成功初始化。
9404
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9405
+ * const result = await ai.acp.connect({ type: 'http', url: 'https://agent.example.com/acp' })
9406
+ * ```
9407
+ */
9408
+ connect: (transport: ACPTransport, options?: ACPClientOptions) => Promise<{
9409
+ success: false;
9410
+ error: _h_ai_core.HaiError;
9411
+ } | {
9412
+ success: true;
9413
+ data: {
9414
+ info: _agentclientprotocol_sdk.InitializeResponse;
9415
+ /**
9416
+ * 选择对端握手公布的认证方法,返回 HaiResult。
9417
+ * @param method - initialize 返回的认证方法 ID。
9418
+ * @returns 认证响应的 HaiResult。
9419
+ * @example
9420
+ * ```ts
9421
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9422
+ * const result = await connection.authenticate('api-key')
9423
+ * ```
9424
+ */
9425
+ authenticate: (method: string) => Promise<{
9426
+ success: false;
9427
+ error: _h_ai_core.HaiError;
9428
+ } | {
9429
+ success: true;
9430
+ data: _agentclientprotocol_sdk.AuthenticateResponse;
9431
+ }>;
9432
+ /**
9433
+ * 在对端可见的绝对 cwd 创建原生会话,返回 prompt/cancel 句柄。
9434
+ * @param cwd - 对端文件系统可见的绝对工作目录。
9435
+ * @param mcpServers - 可选原生 MCP 定义;调用方负责凭据与授权。
9436
+ * @returns 原生会话句柄;不创建框架持久会话记录。
9437
+ * @example
9438
+ * ```ts
9439
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9440
+ * const result = await connection.createSession('/srv/project', [])
9441
+ * ```
9442
+ */
9443
+ createSession: (cwd: string, mcpServers?: McpServer[]) => Promise<{
9444
+ success: false;
9445
+ error: _h_ai_core.HaiError;
9446
+ } | {
9447
+ success: true;
9448
+ data: {
9449
+ id: string;
9450
+ /**
9451
+ * 发送一轮原生内容,返回最终文本、停止原因和事件。
9452
+ * @param content - 原生 ACP 内容块。
9453
+ * @param signal - 可选本轮取消信号。
9454
+ * @returns 最终文本、停止原因和事件的 HaiResult。
9455
+ * @example
9456
+ * ```ts
9457
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9458
+ * const result = await session.prompt([{ type: 'text', text: '检查工程' }])
9459
+ * ```
9460
+ */
9461
+ prompt: (content: ContentBlock[], signal?: AbortSignal) => Promise<{
9462
+ success: false;
9463
+ error: _h_ai_core.HaiError;
9464
+ } | {
9465
+ success: true;
9466
+ data: {
9467
+ text: string;
9468
+ events: SessionNotification[];
9469
+ stopReason: _agentclientprotocol_sdk.StopReason;
9470
+ _meta?: {
9471
+ [key: string]: unknown;
9472
+ } | null;
9473
+ };
9474
+ }>;
9475
+ /**
9476
+ * 取消当前轮次,超时则关闭连接。
9477
+ * @returns 取消完成的 HaiResult。
9478
+ * @example
9479
+ * ```ts
9480
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9481
+ * const result = await session.cancel()
9482
+ * ```
9483
+ */
9484
+ cancel: () => Promise<{
9485
+ success: false;
9486
+ error: _h_ai_core.HaiError;
9487
+ } | {
9488
+ success: true;
9489
+ data: void;
9490
+ }>;
9491
+ };
9492
+ }>;
9493
+ /**
9494
+ * 读取对端原生会话列表;未声明相应能力时返回错误。
9495
+ * @param cursor - 上一次原生列表响应中的分页游标。
9496
+ * @returns 原生分页响应的 HaiResult。
9497
+ * @example
9498
+ * ```ts
9499
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9500
+ * const result = await connection.listSessions()
9501
+ * ```
9502
+ */
9503
+ listSessions: (cursor?: string) => Promise<{
9504
+ success: false;
9505
+ error: _h_ai_core.HaiError;
9506
+ } | {
9507
+ success: true;
9508
+ data: _agentclientprotocol_sdk.ListSessionsResponse;
9509
+ }>;
9510
+ /**
9511
+ * 按原生 ID 删除远端会话;不会删除框架数据库会话记录。
9512
+ * @param id - 对端返回的原生会话 ID。
9513
+ * @returns 原生删除响应的 HaiResult;不支持时返回协议错误。
9514
+ * @example
9515
+ * ```ts
9516
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9517
+ * const result = await connection.deleteSession('native-id')
9518
+ * ```
9519
+ */
9520
+ deleteSession: (id: string) => Promise<{
9521
+ success: false;
9522
+ error: _h_ai_core.HaiError;
9523
+ } | {
9524
+ success: true;
9525
+ data: _agentclientprotocol_sdk.DeleteSessionResponse;
9526
+ }>;
9527
+ /**
9528
+ * 关闭连接和拥有的子进程;不删除远端文件或持久状态。
9529
+ * @returns 关闭完成的 HaiResult;可重复关闭。
9530
+ * @example
9531
+ * ```ts
9532
+ * // connection/session 为已成功连接或创建的句柄,先检查 result.success。
9533
+ * const result = await connection.close()
9534
+ * ```
9535
+ */
9536
+ close: () => Promise<{
9537
+ success: false;
9538
+ error: _h_ai_core.HaiError;
9539
+ } | {
9540
+ success: true;
9541
+ data: void;
9542
+ }>;
9543
+ };
9544
+ }>;
9545
+ /**
9546
+ * 关闭子系统及拥有的资源;由 ai.close 生命周期调用。
9547
+ * @returns 所有已接受操作结束和拥有资源完成清理后的 Promise。
9548
+ * @throws 清理进程或容器失败时抛出 ACPFailure,由 ai.close 统一处理。
9549
+ * @example
9550
+ * ```ts
9551
+ * import { ai } from '@h-ai/ai'
9552
+ * // 前提:ai 已成功初始化。
9553
+ * // 普通 API 先检查 result.success,再读取 data 或 error。
9554
+ * await ai.close()
9555
+ * ```
9556
+ */
9557
+ close(): Promise<void>;
9558
+ };
9559
+
9560
+ /**
9561
+ * 原生传输参数;HTTP/WS 使用锁定版本的官方实验传输,不进行隐式转换。
9562
+ * @example
9563
+ * ```ts
9564
+ * import type { ACPTransport } from '@h-ai/ai'
9565
+ * const transport: ACPTransport = { type: 'stdio', command: 'codex-acp' }
9566
+ * ```
9567
+ */
9568
+ type ACPTransport = {
9569
+ /** 通过独占子进程 stdin/stdout 传输 ACP。 */
9570
+ type: 'stdio';
9571
+ /** 直接执行的程序路径,不通过 shell。 */
9572
+ command: string;
9573
+ /** 原生参数数组。 */
9574
+ args?: string[];
9575
+ /** 子进程工作目录。 */
9576
+ cwd?: string;
9577
+ /** 传给子进程的环境变量,与最小宿主环境合并。 */
9578
+ env?: Record<string, string>;
9579
+ } | {
9580
+ /** 原生远程传输;对端必须支持相同 SDK 协议版本。 */
9581
+ type: 'http' | 'ws';
9582
+ /** ACP 服务地址,协议应与 type 一致。 */
9583
+ url: string;
9584
+ /** 当前连接的认证请求头,仅保存在内存。 */
9585
+ headers?: Record<string, string>;
9586
+ };
9587
+ /**
9588
+ * 可信宿主回调。声明能力必须提供对应实现;默认拒绝权限请求。
9589
+ * @example
9590
+ * ```ts
9591
+ * import type { ACPClientOptions } from '@h-ai/ai'
9592
+ * const options: ACPClientOptions = { handlers: { 'session/request_permission': () => ({ outcome: { outcome: 'cancelled' } }) } }
9593
+ * ```
9594
+ */
9595
+ interface ACPClientOptions {
9596
+ /** 接收原生会话事件,包括 session/new 完成前的事件;抛错将关闭连接。 */
9597
+ onEvent?: (event: SessionNotification) => void;
9598
+ /** 可信客户端回调实现;未提供权限回调时默认拒绝。 */
9599
+ handlers?: Partial<ClientRequestHandlersByMethod>;
9600
+ /** 向智能体声明的能力;声明的文件、终端和 elicitation 能力必须配齐回调。 */
9601
+ capabilities?: ClientCapabilities;
9602
+ /** 初始化连接的取消信号;每轮 prompt 的取消信号独立传入。 */
9603
+ signal?: AbortSignal;
9604
+ }
9605
+ /**
9606
+ * 可信原生配置扩展;返回值只传给进程,不写入 Agent 定义存储。
9607
+ * @example
9608
+ * ```ts
9609
+ * import type { ACPAgentAdapter } from '@h-ai/ai'
9610
+ * const adapter: ACPAgentAdapter = { configure: () => ({ command: 'my-agent', args: ['--acp'], env: {} }) }
9611
+ * ```
9612
+ */
9613
+ interface ACPAgentAdapter {
9614
+ /**
9615
+ * 生成当前会话的原生启动参数;实现可以异步,不应在此启动进程或持久保存密钥。
9616
+ * @param input - 智能体、已解析模型与独立状态目录。
9617
+ * @returns 原生可执行文件、参数、临时环境和可选配置文件。
9618
+ * @example
9619
+ * ```ts
9620
+ * const adapter: ACPAgentAdapter = { configure: ({ statePath }) => ({ command: 'my-agent', args: ['--acp'], env: { AGENT_HOME: statePath } }) }
9621
+ * ```
9622
+ */
9623
+ configure: (input: ACPAgentAdapterInput) => ACPAgentLaunch | Promise<ACPAgentLaunch>;
9624
+ }
9625
+ /**
9626
+ * 原生适配器输入;模型来源由框架统一解析,适配器不维护独立模型清单。
9627
+ * @example
9628
+ * ```ts
9629
+ * import type { ACPAgentAdapterInput } from '@h-ai/ai'
9630
+ * function selected(input: ACPAgentAdapterInput) { return input.models.find(model => model.id === input.modelId) }
9631
+ * ```
9632
+ */
9633
+ interface ACPAgentAdapterInput {
9634
+ /** 合并清单中的智能体定义。 */
9635
+ agent: z.infer<typeof ACPAgentSchema>;
9636
+ /** 智能体绑定的全部模型及已解析协议、凭据、容量和模态信息。 */
9637
+ models: Array<{
9638
+ id: string;
9639
+ config: ResolvedModelConfig;
9640
+ }>;
9641
+ /** 本次会话选择的模型 ID。 */
9642
+ modelId?: string;
9643
+ /** 已创建的专属状态目录;托管容器内使用 /state/<会话 ID>。 */
9644
+ statePath: string;
9645
+ }
9646
+ /**
9647
+ * 单次启动的原生配置;env 可能含凭据,不可向浏览器或日志直接公开。
9648
+ * @example
9649
+ * ```ts
9650
+ * import type { ACPAgentLaunch } from '@h-ai/ai'
9651
+ * const launch: ACPAgentLaunch = { command: 'my-agent', args: ['--acp'], env: {} }
9652
+ * ```
9653
+ */
9654
+ interface ACPAgentLaunch {
9655
+ /** 直接执行的程序,禁止拼接 shell 命令。 */
9656
+ command: string;
9657
+ /** 原生参数数组。 */
9658
+ args: string[];
9659
+ /** 仅向当前执行环境注入的变量。 */
9660
+ env: Record<string, string>;
9661
+ /** 状态目录下的普通配置文件,文件名不允许路径分隔符。 */
9662
+ files?: Record<string, string>;
9663
+ }
9664
+ /**
9665
+ * 持久会话绑定;原生 ID 不等于框架 ID,工作目录只能由登记信息生成。
9666
+ * @example
9667
+ * ```ts
9668
+ * import type { ACPSessionInfo } from '@h-ai/ai'
9669
+ * function sessionStatus(session: ACPSessionInfo) { return session.status }
9670
+ * ```
9671
+ */
9672
+ interface ACPSessionInfo {
9673
+ /** 框架会话 ID,与智能体返回的 nativeId 分开维护。 */
9674
+ id: string;
9675
+ /** 合并清单中的智能体 ID。 */
9676
+ agentId: string;
9677
+ /** 受管理工作区 ID;远程自定义服务可省略。 */
9678
+ workspaceId?: string;
9679
+ /** 智能体实际可见的绝对工作目录。 */
9680
+ cwd: string;
9681
+ /** 是否使用独立检出目录;false 表示共享工作区主目录。 */
9682
+ newWorktree: boolean;
9683
+ /** 独立会话中所有工程共用的分支名。 */
9684
+ branch?: string;
9685
+ /** 启动时选定的 Hai 模型 ID。 */
9686
+ modelId?: string;
9687
+ /** 模型非密钥配置的摘要;用于阻止不兼容的会话恢复。 */
9688
+ modelSignature?: string;
9689
+ /** 智能体原生会话 ID,恢复时原样传回。 */
9690
+ nativeId?: string;
9691
+ /** 打开中、运行中、已关闭或打开失败。 */
9692
+ status: 'opening' | 'active' | 'closed' | 'failed';
9693
+ /** 创建会话时的智能体定义快照。 */
9694
+ agent: z.infer<typeof ACPAgentSchema>;
9695
+ /** 直接绑定的原生 MCP 参数;可能含凭据,仅供可信服务端管理。 */
9696
+ mcpServers: McpServer[];
9697
+ /** 从 MCP 合并清单选择的服务 ID;凭据在启动时解析。 */
9698
+ mcpServerIds?: string[];
9699
+ /** 当前拥有的容器;关闭后清空,volume 内容仍保留。 */
9700
+ resource?: {
9701
+ engine?: 'podman' | 'docker';
9702
+ container: string;
9703
+ };
9704
+ }
9705
+ /**
9706
+ * 创建会话参数;远程服务使用它自身可见的绝对路径。
9707
+ * @example
9708
+ * ```ts
9709
+ * import type { ACPCreateSessionOptions } from '@h-ai/ai'
9710
+ * const options: ACPCreateSessionOptions = { agentId: 'coder', workspaceId: 'project', newWorktree: true }
9711
+ * ```
9712
+ */
9713
+ interface ACPCreateSessionOptions extends ACPClientOptions {
9714
+ /** 可选业务会话 ID;省略时生成 UUID。 */
9715
+ id?: string;
9716
+ /** 合并清单中的智能体 ID。 */
9717
+ agentId: string;
9718
+ /** 托管模式必填的工作区 ID。 */
9719
+ workspaceId?: string;
9720
+ /** 自定义远程服务可见的绝对路径;托管模式由工作区计算。 */
9721
+ cwd?: string;
9722
+ /** 默认 false;true 时从每个工程当前本地主分支创建 worktree。 */
9723
+ newWorktree?: boolean;
9724
+ /** 独立会话分支名;默认 acp/<会话 ID>。 */
9725
+ branch?: string;
9726
+ /** 本次会话的模型 ID,必须在智能体 modelIds 内。 */
9727
+ modelId?: string;
9728
+ /** 直接传给智能体的 MCP 定义;与 mcpServerIds 合并。 */
9729
+ mcpServers?: McpServer[];
9730
+ /** 从 ai.mcp.servers 选择的登记服务。 */
9731
+ mcpServerIds?: string[];
9732
+ }
9733
+ /**
9734
+ * 每个工程分别报告,保留失败前已发生的提交和推送结果。
9735
+ * @example
9736
+ * ```ts
9737
+ * import type { ACPGitReport } from '@h-ai/ai'
9738
+ * function failedRepositories(reports: ACPGitReport[]) { return reports.filter(report => !report.success).map(report => report.repositoryId) }
9739
+ * ```
9740
+ */
9741
+ interface ACPGitReport {
9742
+ /** 工作区中声明的工程 ID。 */
9743
+ repositoryId: string;
9744
+ /** 该工程是否完成全部请求操作。 */
9745
+ success: boolean;
9746
+ /** 成功时为 done;失败时标明停止阶段。 */
9747
+ phase: 'check' | 'commit' | 'fetch' | 'merge' | 'push' | 'done';
9748
+ /** 已创建或发布的提交 SHA;失败前可能已经产生提交。 */
9749
+ commit?: string;
9750
+ /** 脱敏的失败原因,不包含 Git stderr 或认证资料。 */
9751
+ error?: string;
9752
+ }
9753
+ /**
9754
+ * ACP 操作入口。
9755
+ * @example
9756
+ * ```ts
9757
+ * import { ai } from '@h-ai/ai'
9758
+ * async function listAgents() { const result = await ai.acp.agents.list(); if (!result.success) return result; return result.data }
9759
+ * ```
9760
+ */
9761
+ type ACPOperations = ReturnType<typeof createACPOperations>;
9762
+
9763
+ export { type AudioModelEntry as $, type A2AAgentCardConfig as A, ACPRepositorySchema as B, type ACPSessionInfo as C, type ACPTransport as D, ACPWorkspaceSchema as E, type AIConfig as F, type AIConfigInput as G, AIConfigSchema as H, type AIFunctions as I, type AIInitOptions as J, type AIRelStore as K, type AIRelStoreCompareAndSwap as L, type AIRelStoreOptions as M, type AIResourceEntry as N, type AIResourceRegistry as O, type AIStoreProvider as P, type AIVectorBackend as Q, type AIVectorStore as R, type AIVersionedRecord as S, AUDIO_WS_PATH as T, type ApiType as U, ApiTypeSchema as V, type AskOptions as W, type AssistantMessage as X, type AudioConfig as Y, AudioConfigSchema as Z, AudioFormatSchema as _, type A2AApiKeySecurity as a, type FileConfig as a$, AudioModelEntrySchema as a0, type AudioOperation as a1, AudioOperationSchema as a2, AudioOperationsSchema as a3, type AudioProviderName as a4, AudioProviderSchema as a5, type AudioWsClientMessage as a6, AudioWsClientMessageSchema as a7, type AudioWsDoneMessage as a8, AudioWsDoneMessageSchema as a9, type CompressionStrategy as aA, CompressionStrategySchema as aB, type ConsolidateOptions as aC, type ConsolidateResult as aD, type ContextChatOptions as aE, type ContextChatResult as aF, type ContextManager as aG, type ContextManagerOptions as aH, type ContextOperations as aI, type ContextResetOptions as aJ, type ContextStreamEvent as aK, type ConversationTurn as aL, type ConversationTurnStatus as aM, type DefineToolOptions as aN, type DeveloperMessage as aO, type EmbeddingConfig as aP, EmbeddingConfigSchema as aQ, type EmbeddingItem as aR, type EmbeddingOperations as aS, type EmbeddingRequest as aT, type EmbeddingResponse as aU, type EntityDocumentRelation as aV, type EntityDocumentResult as aW, type EntityListOptions as aX, type EntityQueryOptions as aY, type EntityType as aZ, EntityTypeSchema as a_, type AudioWsEndMessage as aa, type AudioWsErrorMessage as ab, type AudioWsSegmentDoneMessage as ac, type AudioWsSegmentStartedMessage as ad, type AudioWsServerMessage as ae, type AudioWsSpeechMessage as af, type AudioWsStartMessage as ag, AudioWsStartMessageSchema as ah, type AudioWsTextMessage as ai, AudioWsTextMessageSchema as aj, type AudioWsTranscriptMessage as ak, type ChatCompletionChoice as al, type ChatCompletionChunk as am, type ChatCompletionDelta as an, type ChatCompletionRequest as ao, type ChatCompletionResponse as ap, type ChatHistoryOptions as aq, type ChatMessage as ar, type ChatRecord as as, type Citation as at, type CommitTurnInput as au, type CompressConfig as av, CompressConfigSchema as aw, type CompressOperations as ax, type CompressOptions as ay, type CompressResult as az, type A2AAuthenticator as b, MCPServerConfigSchema as b$, FileConfigSchema as b0, type FileOperations as b1, type FileParseMethod as b2, type FileParseOptions as b3, type FileParseRequest as b4, type FileParseResult as b5, type GenerateImageRequest as b6, type GenerateImageResult as b7, type GenerateObjectRequest as b8, type GeneratedImage as b9, type KnowledgeOperations as bA, type KnowledgeRepairOptions as bB, type KnowledgeRepairProgress as bC, type KnowledgeRepairResult as bD, type KnowledgeRetrieveItem as bE, type KnowledgeRetrieveOptions as bF, type KnowledgeRetrieveResult as bG, type KnowledgeSetupOptions as bH, type KnowledgeStore as bI, type LLMConfig as bJ, LLMConfigSchema as bK, type LLMOperations as bL, type MCPConfig as bM, MCPConfigSchema as bN, type MCPContext as bO, type MCPExternalServer as bP, MCPExternalServerSchema as bQ, type MCPOperations as bR, type MCPPrompt as bS, type MCPPromptArgument as bT, type MCPPromptContent as bU, type MCPPromptMessage as bV, type MCPResource as bW, type MCPResourceContent as bX, type MCPServerCapabilities as bY, MCPServerCapabilitiesSchema as bZ, type MCPServerConfig as b_, HaiAIError as ba, type ImageConfig as bb, ImageConfigSchema as bc, type ImageContent as bd, type ImageModelEntry as be, ImageModelEntrySchema as bf, type ImageOperations as bg, type ImageProviderName as bh, ImageProviderSchema as bi, type ImageSize as bj, type InteractionScope as bk, type KnowledgeAskOptions as bl, type KnowledgeAskResult as bm, type KnowledgeConfig as bn, KnowledgeConfigSchema as bo, type KnowledgeDocumentInfo as bp, type KnowledgeDocumentListOptions as bq, type KnowledgeDocumentMetadata as br, type KnowledgeDocumentRemoveOptions as bs, type KnowledgeDocumentRevision as bt, type KnowledgeEntity as bu, type KnowledgeIngestBatchProgress as bv, type KnowledgeIngestBatchResult as bw, type KnowledgeIngestFileInput as bx, type KnowledgeIngestInput as by, type KnowledgeIngestResult as bz, type A2ACallOptions as c, type RetrievalConfig as c$, type MCPToolDefinition as c0, type MCPToolHandler as c1, type ManagedAudioOperations as c2, type ManagedImageOperations as c3, type ManagedLLMOperations as c4, type ManagedMCPOperations as c5, type ManagedRetrievalOperations as c6, type McpServerOptions as c7, type MemoryAccessScope as c8, type MemoryAdminOperations as c9, type PersonaOperations as cA, type PersonaProfile as cB, type PersonaProfileInput as cC, type PersonaProfileUpdate as cD, type PersonaScopeOptions as cE, type RagContextItem as cF, type RagOperations as cG, type RagOptions as cH, type RagResult as cI, type RagStreamEvent as cJ, type ReasoningOperations as cK, type ReasoningOptions as cL, type ReasoningResult as cM, type ReasoningStep as cN, type ReasoningStepType as cO, type ReasoningStrategy as cP, type ReasoningStreamEvent as cQ, type ReferenceImage as cR, type RerankDocument as cS, type RerankItem as cT, type RerankOperations as cU, type RerankRequest as cV, type RerankResponse as cW, type ResolveRequiredModelEntryOptions as cX, type ResolvedAudioModel as cY, type ResolvedImageModel as cZ, type ResolvedModelConfig as c_, type MemoryClearAllOptions as ca, type MemoryClearOptions as cb, type MemoryConfig as cc, MemoryConfigSchema as cd, type MemoryCoreOperations as ce, type MemoryEntry as cf, type MemoryEntryInput as cg, type MemoryExtractOptions as ch, type MemoryInjectionOptions as ci, type MemoryListOptions as cj, type MemoryListPageOptions as ck, type MemoryOperations as cl, type MemoryRecallOptions as cm, type MemoryType as cn, MemoryTypeSchema as co, type MemoryUpdateInput as cp, type MessageContent as cq, type MessageRole as cr, ModelCapabilitiesSchema as cs, type ModelEntry as ct, ModelEntrySchema as cu, type ModelScenario as cv, ModelScenarioSchema as cw, type ObjectRef as cx, OptionalSecretSchema as cy, type OutputFormat as cz, type A2ACallResult as d, RetrievalConfigSchema as d0, type RetrievalOperations as d1, type RetrievalRequest as d2, type RetrievalResult as d3, type RetrievalResultItem as d4, type RetrievalSource as d5, type RetrievalSourceConfig as d6, RetrievalSourceSchema as d7, type SSEDecoder as d8, type SSEEvent as d9, type ToolDefinition as dA, type ToolErrorType as dB, type ToolExecutionContext as dC, type ToolExecutionOptions as dD, type ToolMessage as dE, type ToolRegistryOperations as dF, type ToolRegistryOptions as dG, type ToolsOperations as dH, type UserMessage as dI, type WhereClause as dJ, type WhereOperator as dK, type WhereValue as dL, ensureAudioCredential as dM, resolveAudioModel as dN, resolveImageModel as dO, resolveModelApi as dP, resolveModelEntry as dQ, serializePlayableAudio as dR, type ScopedMemoryBinding as da, type ScopedMemoryOperations as db, type SessionInfo as dc, type StoreFilter as dd, type StorePage as de, type StoreScope as df, type StreamOperations as dg, type StreamProcessor as dh, type StreamResult as di, type SummaryConfig as dj, SummaryConfigSchema as dk, type SummaryOperations as dl, type SummaryOptions as dm, type SummaryResult as dn, type SystemMessage as dp, type TempModelConfig as dq, type TextContent as dr, type TokenConfig as ds, TokenConfigSchema as dt, type TokenOperations as du, type TokenUsage as dv, type Tool as dw, type ToolAuthorizationRequest as dx, type ToolAuthorizer as dy, type ToolCall as dz, type A2ACallerIdentity as e, type A2AConfig as f, A2AConfigSchema as g, type A2AContextInfo as h, type A2AHandleResult as i, type A2AMessageRecord as j, type A2AOperations as k, type A2ASecurityConfig as l, A2ASkillConfigSchema as m, type A2ATaskFilter as n, type ACPAgentAdapter as o, type ACPAgentAdapterInput as p, type ACPAgentLaunch as q, ACPAgentSchema as r, type ACPClientOptions as s, type ACPConfig as t, type ACPConfigInput as u, ACPConfigSchema as v, type ACPCreateSessionOptions as w, type ACPGitReport as x, type ACPOperations as y, ACPPublishSchema as z };