| 1 | import * as Schema from "effect/Schema"; |
| 2 | import type * as V2 from "./_generated/schema.gen.ts"; |
| 3 | |
| 4 | type Meta = AcpMeta | null; |
| 5 | type AcpMeta = NonNullable<V2.InitializeRequest["_meta"]>; |
| 6 | type KnownContentBlock<T extends V2.ContentBlock["type"]> = Extract< |
| 7 | V2.ContentBlock, |
| 8 | { readonly type: T } |
| 9 | >; |
| 10 | |
| 11 | /** Provider-neutral content accepted by T3 after ACP v1 or v2 negotiation. */ |
| 12 | export type ContentBlock = |
| 13 | | KnownContentBlock<"text"> |
| 14 | | KnownContentBlock<"image"> |
| 15 | | KnownContentBlock<"audio"> |
| 16 | | KnownContentBlock<"resource_link"> |
| 17 | | KnownContentBlock<"resource"> |
| 18 | | { |
| 19 | readonly type: "_t3_unknown"; |
| 20 | readonly originalType: string; |
| 21 | readonly raw: unknown; |
| 22 | }; |
| 23 | |
| 24 | export type AbsolutePath = V2.AbsolutePath; |
| 25 | export type AvailableCommand = Omit<V2.AvailableCommand, "input"> & { |
| 26 | readonly input?: Extract<V2.AvailableCommandInput, { readonly type: "text" }> | null; |
| 27 | }; |
| 28 | export type CloseSessionRequest = V2.CloseSessionRequest; |
| 29 | export type CloseSessionResponse = V2.CloseSessionResponse; |
| 30 | export type DeleteSessionRequest = V2.DeleteSessionRequest; |
| 31 | export type DeleteSessionResponse = V2.DeleteSessionResponse; |
| 32 | export type ListProvidersRequest = V2.ListProvidersRequest; |
| 33 | export type ListProvidersResponse = V2.ListProvidersResponse; |
| 34 | export type SetProviderRequest = V2.SetProviderRequest; |
| 35 | export type SetProviderResponse = V2.SetProviderResponse; |
| 36 | export type DisableProviderRequest = V2.DisableProviderRequest; |
| 37 | export type DisableProviderResponse = V2.DisableProviderResponse; |
| 38 | export type ConnectMcpRequest = V2.ConnectMcpRequest; |
| 39 | export type ConnectMcpResponse = V2.ConnectMcpResponse; |
| 40 | export type MessageMcpRequest = V2.MessageMcpRequest; |
| 41 | export type MessageMcpNotification = V2.MessageMcpNotification; |
| 42 | export type MessageMcpResponse = V2.MessageMcpResponse; |
| 43 | export type DisconnectMcpRequest = V2.DisconnectMcpRequest; |
| 44 | export type DisconnectMcpResponse = V2.DisconnectMcpResponse; |
| 45 | export type CompleteElicitationNotification = V2.CompleteElicitationNotification; |
| 46 | export type CreateElicitationRequest = V2.CreateElicitationRequest; |
| 47 | export type CreateElicitationResponse = V2.CreateElicitationResponse; |
| 48 | export type ElicitationContentValue = V2.ElicitationContentValue; |
| 49 | export type ForkSessionRequest = Omit<V2.ForkSessionRequest, "mcpServers"> & { |
| 50 | readonly mcpServers?: ReadonlyArray<McpServer>; |
| 51 | }; |
| 52 | export type ListSessionsRequest = V2.ListSessionsRequest; |
| 53 | export type ListSessionsResponse = V2.ListSessionsResponse; |
| 54 | export type LogoutResponse = V2.LogoutAuthResponse; |
| 55 | export type LogoutRequest = V2.LogoutAuthRequest; |
| 56 | export type StopReason = V2.StopReason; |
| 57 | export type Usage = V2.Usage; |
| 58 | export type TerminalExitStatus = V2.TerminalExitStatus; |
| 59 | export type ToolCallLocation = V2.ToolCallLocation; |
| 60 | export type ToolCallStatus = V2.ToolCallStatus; |
| 61 | export type ToolKind = V2.ToolKind; |
| 62 | |
| 63 | export type ClientCapabilities = { |
| 64 | readonly fs?: { readonly readTextFile?: boolean; readonly writeTextFile?: boolean }; |
| 65 | readonly terminal?: boolean; |
| 66 | readonly session?: { readonly list?: Meta } | null; |
| 67 | readonly plan?: Meta; |
| 68 | readonly auth?: { readonly terminal?: boolean }; |
| 69 | readonly elicitation?: V2.ElicitationCapabilities | null; |
| 70 | readonly _meta?: Meta; |
| 71 | }; |
| 72 | |
| 73 | export type InitializeRequest = { |
| 74 | readonly protocolVersion: number; |
| 75 | readonly clientCapabilities?: ClientCapabilities; |
| 76 | readonly clientInfo?: V2.Implementation | null; |
| 77 | readonly _meta?: Meta; |
| 78 | }; |
| 79 | |
| 80 | export type AgentCapabilities = { |
| 81 | readonly loadSession?: boolean; |
| 82 | readonly promptCapabilities?: { |
| 83 | readonly image?: boolean; |
| 84 | readonly audio?: boolean; |
| 85 | readonly embeddedContext?: boolean; |
| 86 | }; |
| 87 | readonly mcpCapabilities?: { |
| 88 | readonly stdio?: boolean; |
| 89 | readonly http?: boolean; |
| 90 | readonly sse?: boolean; |
| 91 | readonly acp?: boolean; |
| 92 | }; |
| 93 | readonly sessionCapabilities?: { |
| 94 | readonly list?: Meta; |
| 95 | readonly fork?: Meta; |
| 96 | readonly resume?: Meta; |
| 97 | readonly close?: Meta; |
| 98 | readonly delete?: Meta; |
| 99 | readonly additionalDirectories?: Meta; |
| 100 | }; |
| 101 | readonly auth?: { readonly logout?: Meta }; |
| 102 | readonly providers?: Meta; |
| 103 | readonly _meta?: Meta; |
| 104 | }; |
| 105 | |
| 106 | interface AuthMethodBase { |
| 107 | readonly id: string; |
| 108 | readonly name: string; |
| 109 | readonly description?: string | null; |
| 110 | readonly _meta?: Meta; |
| 111 | } |
| 112 | |
| 113 | export type AuthMethod = |
| 114 | | (AuthMethodBase & { |
| 115 | readonly type: "terminal"; |
| 116 | readonly args?: ReadonlyArray<string>; |
| 117 | readonly env?: Readonly<Record<string, string>>; |
| 118 | }) |
| 119 | | (AuthMethodBase & { |
| 120 | readonly type: "env_var"; |
| 121 | readonly vars: ReadonlyArray<{ readonly name: string; readonly label?: string }>; |
| 122 | readonly link?: string | null; |
| 123 | }) |
| 124 | | (AuthMethodBase & { readonly type?: "agent" }); |
| 125 | |
| 126 | export type InitializeResponse = { |
| 127 | readonly protocolVersion: number; |
| 128 | readonly agentCapabilities?: AgentCapabilities; |
| 129 | readonly authMethods?: ReadonlyArray<AuthMethod>; |
| 130 | readonly agentInfo?: V2.Implementation | null; |
| 131 | readonly _meta?: Meta; |
| 132 | }; |
| 133 | |
| 134 | export type AuthenticateRequest = V2.LoginAuthRequest; |
| 135 | export type AuthenticateResponse = V2.LoginAuthResponse; |
| 136 | export type CancelNotification = V2.CancelSessionNotification; |
| 137 | |
| 138 | export type McpServer = |
| 139 | | { |
| 140 | readonly name: string; |
| 141 | readonly command: string; |
| 142 | readonly args?: ReadonlyArray<string>; |
| 143 | readonly env?: ReadonlyArray<V2.EnvVariable>; |
| 144 | readonly _meta?: Meta; |
| 145 | } |
| 146 | | V2.McpServer; |
| 147 | |
| 148 | export type NewSessionRequest = Omit<V2.NewSessionRequest, "mcpServers"> & { |
| 149 | readonly mcpServers: ReadonlyArray<McpServer>; |
| 150 | }; |
| 151 | export type ResumeSessionRequest = Omit<V2.ResumeSessionRequest, "mcpServers"> & { |
| 152 | readonly mcpServers?: ReadonlyArray<McpServer>; |
| 153 | }; |
| 154 | export type LoadSessionRequest = Omit<ResumeSessionRequest, "replayFrom">; |
| 155 | |
| 156 | export interface SessionMode { |
| 157 | readonly id: string; |
| 158 | readonly name: string; |
| 159 | readonly description?: string | null; |
| 160 | readonly _meta?: Meta; |
| 161 | } |
| 162 | |
| 163 | export interface SessionModeState { |
| 164 | readonly currentModeId: string; |
| 165 | readonly availableModes: ReadonlyArray<SessionMode>; |
| 166 | readonly _meta?: Meta; |
| 167 | } |
| 168 | |
| 169 | export interface NewSessionResponse { |
| 170 | readonly models?: SessionModelState | null; |
| 171 | readonly sessionId: string; |
| 172 | readonly modes?: SessionModeState | null; |
| 173 | readonly configOptions?: ReadonlyArray<SessionConfigOption> | null; |
| 174 | readonly _meta?: Meta; |
| 175 | } |
| 176 | |
| 177 | export interface LoadSessionResponse { |
| 178 | readonly models?: SessionModelState | null; |
| 179 | readonly modes?: SessionModeState | null; |
| 180 | readonly configOptions?: ReadonlyArray<SessionConfigOption> | null; |
| 181 | readonly _meta?: Meta; |
| 182 | } |
| 183 | |
| 184 | export type ResumeSessionResponse = LoadSessionResponse; |
| 185 | export interface ForkSessionResponse extends NewSessionResponse {} |
| 186 | |
| 187 | export type SessionConfigSelectOption = V2.SessionConfigSelectOption; |
| 188 | export type SessionConfigSelectOptions = |
| 189 | | ReadonlyArray<SessionConfigSelectOption> |
| 190 | | ReadonlyArray<{ |
| 191 | readonly groupId: string; |
| 192 | readonly name: string; |
| 193 | readonly options: ReadonlyArray<SessionConfigSelectOption>; |
| 194 | readonly _meta?: Meta; |
| 195 | }>; |
| 196 | |
| 197 | interface SessionConfigOptionBase { |
| 198 | readonly id: string; |
| 199 | readonly name: string; |
| 200 | readonly description?: string | null; |
| 201 | readonly category?: string | null; |
| 202 | readonly _meta?: Meta; |
| 203 | } |
| 204 | |
| 205 | export type SessionConfigOption = |
| 206 | | (SessionConfigOptionBase & { |
| 207 | readonly type: "select"; |
| 208 | readonly currentValue: string; |
| 209 | readonly options: SessionConfigSelectOptions; |
| 210 | }) |
| 211 | | (SessionConfigOptionBase & { |
| 212 | readonly type: "boolean"; |
| 213 | readonly currentValue: boolean; |
| 214 | }); |
| 215 | |
| 216 | export type SetSessionConfigOptionRequest = |
| 217 | | { |
| 218 | readonly sessionId: string; |
| 219 | readonly configId: string; |
| 220 | readonly value: string; |
| 221 | readonly _meta?: Meta; |
| 222 | } |
| 223 | | { |
| 224 | readonly type: "boolean"; |
| 225 | readonly sessionId: string; |
| 226 | readonly configId: string; |
| 227 | readonly value: boolean; |
| 228 | readonly _meta?: Meta; |
| 229 | }; |
| 230 | |
| 231 | export interface SetSessionConfigOptionResponse { |
| 232 | readonly configOptions: ReadonlyArray<SessionConfigOption>; |
| 233 | readonly _meta?: Meta; |
| 234 | } |
| 235 | |
| 236 | export interface SetSessionModeResponse { |
| 237 | readonly _meta?: Meta; |
| 238 | } |
| 239 | |
| 240 | export type PromptRequest = Omit<V2.PromptRequest, "prompt"> & { |
| 241 | readonly prompt: ReadonlyArray<ContentBlock>; |
| 242 | }; |
| 243 | export interface PromptResponse { |
| 244 | readonly stopReason: StopReason; |
| 245 | readonly usage?: V2.Usage | null; |
| 246 | readonly _meta?: Meta; |
| 247 | } |
| 248 | |
| 249 | export type ToolCallContent = |
| 250 | | { readonly type: "content"; readonly content: ContentBlock; readonly _meta?: Meta } |
| 251 | | { |
| 252 | readonly type: "diff"; |
| 253 | readonly path: string; |
| 254 | readonly oldText?: string | null; |
| 255 | readonly newText: string; |
| 256 | readonly _meta?: Meta; |
| 257 | } |
| 258 | | { |
| 259 | readonly type: "diff"; |
| 260 | readonly changes: ReadonlyArray<V2.DiffChange>; |
| 261 | readonly patch?: V2.DiffPatch | null; |
| 262 | readonly _meta?: Meta; |
| 263 | } |
| 264 | | { readonly type: "terminal"; readonly terminalId: string; readonly _meta?: Meta } |
| 265 | | { |
| 266 | readonly type: "_t3_unknown"; |
| 267 | readonly originalType: string; |
| 268 | readonly raw: unknown; |
| 269 | }; |
| 270 | |
| 271 | export interface ToolCallUpdate { |
| 272 | readonly toolCallId: string; |
| 273 | readonly name?: string | null; |
| 274 | readonly title?: string | null; |
| 275 | readonly kind?: ToolKind | null; |
| 276 | readonly status?: ToolCallStatus | null; |
| 277 | readonly content?: ReadonlyArray<ToolCallContent> | null; |
| 278 | readonly locations?: ReadonlyArray<ToolCallLocation> | null; |
| 279 | readonly rawInput?: unknown; |
| 280 | readonly rawOutput?: unknown; |
| 281 | readonly _meta?: Meta; |
| 282 | } |
| 283 | |
| 284 | type MessageChunkUpdate = { |
| 285 | readonly content: ContentBlock; |
| 286 | readonly messageId?: string | null; |
| 287 | readonly _meta?: Meta; |
| 288 | }; |
| 289 | |
| 290 | type MessageUpdate = { |
| 291 | readonly messageId: string; |
| 292 | readonly content?: ReadonlyArray<ContentBlock> | null; |
| 293 | readonly _meta?: Meta; |
| 294 | }; |
| 295 | |
| 296 | export type SessionUpdate = |
| 297 | | (MessageChunkUpdate & { readonly sessionUpdate: "user_message_chunk" }) |
| 298 | | (MessageChunkUpdate & { readonly sessionUpdate: "agent_message_chunk" }) |
| 299 | | (MessageChunkUpdate & { readonly sessionUpdate: "agent_thought_chunk" }) |
| 300 | | (MessageUpdate & { readonly sessionUpdate: "user_message" }) |
| 301 | | (MessageUpdate & { readonly sessionUpdate: "agent_message" }) |
| 302 | | (MessageUpdate & { readonly sessionUpdate: "agent_thought" }) |
| 303 | | (ToolCallUpdate & { readonly sessionUpdate: "tool_call"; readonly title: string }) |
| 304 | | (ToolCallUpdate & { readonly sessionUpdate: "tool_call_update" }) |
| 305 | | { |
| 306 | readonly sessionUpdate: "tool_call_content_chunk"; |
| 307 | readonly toolCallId: string; |
| 308 | readonly content: ToolCallContent; |
| 309 | readonly _meta?: Meta; |
| 310 | } |
| 311 | | { |
| 312 | readonly sessionUpdate: "state_update"; |
| 313 | readonly state: "running"; |
| 314 | readonly _meta?: Meta; |
| 315 | } |
| 316 | | { |
| 317 | readonly sessionUpdate: "state_update"; |
| 318 | readonly state: "idle"; |
| 319 | readonly stopReason?: StopReason | null; |
| 320 | readonly usage?: Usage | null; |
| 321 | readonly _meta?: Meta; |
| 322 | } |
| 323 | | { |
| 324 | readonly sessionUpdate: "state_update"; |
| 325 | readonly state: "requires_action"; |
| 326 | readonly _meta?: Meta; |
| 327 | } |
| 328 | | Extract<V2.SessionUpdate, { readonly sessionUpdate: "terminal_update" }> |
| 329 | | Extract<V2.SessionUpdate, { readonly sessionUpdate: "terminal_output_chunk" }> |
| 330 | | Extract<V2.SessionUpdate, { readonly sessionUpdate: "plan_update" }> |
| 331 | | Extract<V2.SessionUpdate, { readonly sessionUpdate: "plan_removed" }> |
| 332 | | { |
| 333 | readonly sessionUpdate: "available_commands_update"; |
| 334 | readonly availableCommands: ReadonlyArray<AvailableCommand>; |
| 335 | readonly _meta?: Meta; |
| 336 | } |
| 337 | | Extract<V2.SessionUpdate, { readonly sessionUpdate: "session_info_update" }> |
| 338 | | Extract<V2.SessionUpdate, { readonly sessionUpdate: "usage_update" }> |
| 339 | | { |
| 340 | readonly sessionUpdate: "compaction_update"; |
| 341 | readonly compactionId: string; |
| 342 | readonly status: string; |
| 343 | readonly summary?: ReadonlyArray<ContentBlock> | null; |
| 344 | readonly error?: string | null; |
| 345 | readonly _meta?: Meta; |
| 346 | } |
| 347 | | { |
| 348 | readonly sessionUpdate: "compaction_summary_chunk"; |
| 349 | readonly compactionId: string; |
| 350 | readonly content: ContentBlock; |
| 351 | readonly _meta?: Meta; |
| 352 | } |
| 353 | | { |
| 354 | readonly sessionUpdate: "config_option_update"; |
| 355 | readonly configOptions: ReadonlyArray<SessionConfigOption>; |
| 356 | readonly _meta?: Meta; |
| 357 | } |
| 358 | | { readonly sessionUpdate: "plan"; readonly entries: ReadonlyArray<V2.PlanEntry> } |
| 359 | | { readonly sessionUpdate: "current_mode_update"; readonly currentModeId: string } |
| 360 | | { |
| 361 | readonly sessionUpdate: "_t3_unknown"; |
| 362 | readonly originalSessionUpdate: string; |
| 363 | readonly raw: unknown; |
| 364 | }; |
| 365 | |
| 366 | export interface SessionNotification { |
| 367 | readonly sessionId: string; |
| 368 | readonly update: SessionUpdate; |
| 369 | readonly _meta?: Meta; |
| 370 | } |
| 371 | |
| 372 | export type RequestPermissionRequest = { |
| 373 | readonly sessionId: string; |
| 374 | readonly title?: string; |
| 375 | readonly description?: string | null; |
| 376 | readonly subject?: V2.RequestPermissionSubject | null; |
| 377 | readonly toolCall: ToolCallUpdate; |
| 378 | readonly options: ReadonlyArray<V2.PermissionOption>; |
| 379 | readonly _meta?: Meta; |
| 380 | }; |
| 381 | export type RequestPermissionResponse = V2.RequestPermissionResponse; |
| 382 | |
| 383 | // ACP v1 client-mediated filesystem and terminal shapes remain as internal |
| 384 | // types for the legacy policy helpers. ACP v2 never advertises or wires them. |
| 385 | export interface ReadTextFileRequest { |
| 386 | readonly sessionId: string; |
| 387 | readonly path: string; |
| 388 | readonly line?: number | null; |
| 389 | readonly limit?: number | null; |
| 390 | } |
| 391 | export interface ReadTextFileResponse { |
| 392 | readonly content: string; |
| 393 | } |
| 394 | export interface WriteTextFileRequest { |
| 395 | readonly sessionId: string; |
| 396 | readonly path: string; |
| 397 | readonly content: string; |
| 398 | } |
| 399 | export interface WriteTextFileResponse {} |
| 400 | export interface CreateTerminalRequest { |
| 401 | readonly sessionId: string; |
| 402 | readonly command: string; |
| 403 | readonly args?: ReadonlyArray<string>; |
| 404 | readonly env?: ReadonlyArray<V2.EnvVariable>; |
| 405 | readonly cwd?: string | null; |
| 406 | readonly outputByteLimit?: number | null; |
| 407 | } |
| 408 | export interface CreateTerminalResponse { |
| 409 | readonly terminalId: string; |
| 410 | } |
| 411 | interface TerminalRequest { |
| 412 | readonly sessionId: string; |
| 413 | readonly terminalId: string; |
| 414 | } |
| 415 | export type TerminalOutputRequest = TerminalRequest; |
| 416 | export interface TerminalOutputResponse { |
| 417 | readonly output: string; |
| 418 | readonly truncated: boolean; |
| 419 | readonly exitStatus?: TerminalExitStatus | null; |
| 420 | } |
| 421 | export type WaitForTerminalExitRequest = TerminalRequest; |
| 422 | export type WaitForTerminalExitResponse = TerminalExitStatus; |
| 423 | export type KillTerminalRequest = TerminalRequest; |
| 424 | export interface KillTerminalResponse {} |
| 425 | export type ReleaseTerminalRequest = TerminalRequest; |
| 426 | export interface ReleaseTerminalResponse {} |
| 427 | |
| 428 | // Older v1 agents still advertise and select models through this removed unstable API. |
| 429 | const LegacyMeta = Schema.optionalKey(Schema.NullOr(Schema.Record(Schema.String, Schema.Json))); |
| 430 | export const ModelInfo = Schema.Struct({ |
| 431 | modelId: Schema.String, |
| 432 | name: Schema.String, |
| 433 | description: Schema.optionalKey(Schema.NullOr(Schema.String)), |
| 434 | _meta: LegacyMeta, |
| 435 | }); |
| 436 | export type ModelInfo = typeof ModelInfo.Type; |
| 437 | export const SessionModelState = Schema.Struct({ |
| 438 | currentModelId: Schema.String, |
| 439 | availableModels: Schema.Array(ModelInfo), |
| 440 | _meta: LegacyMeta, |
| 441 | }); |
| 442 | export type SessionModelState = typeof SessionModelState.Type; |
| 443 | export const SetSessionModelRequest = Schema.Struct({ |
| 444 | sessionId: Schema.String, |
| 445 | modelId: Schema.String, |
| 446 | _meta: LegacyMeta, |
| 447 | }); |
| 448 | export type SetSessionModelRequest = typeof SetSessionModelRequest.Type; |
| 449 | export const SetSessionModelResponse = Schema.Struct({ _meta: LegacyMeta }); |
| 450 | export type SetSessionModelResponse = typeof SetSessionModelResponse.Type; |
| 451 | export type PermissionOption = V2.PermissionOption; |