@linxiraos/pi-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/CHANGELOG.md +449 -0
  2. package/README.md +36 -0
  3. package/dist/types/abortable.d.ts +32 -0
  4. package/dist/types/acp/connection.d.ts +118 -0
  5. package/dist/types/acp/protocol.d.ts +526 -0
  6. package/dist/types/acp/schema.d.ts +41 -0
  7. package/dist/types/acp/stream.d.ts +8 -0
  8. package/dist/types/acp/transport.d.ts +81 -0
  9. package/dist/types/acp.d.ts +6 -0
  10. package/dist/types/async.d.ts +20 -0
  11. package/dist/types/binary.d.ts +17 -0
  12. package/dist/types/browsers.d.ts +68 -0
  13. package/dist/types/chalk.d.ts +125 -0
  14. package/dist/types/cli.d.ts +134 -0
  15. package/dist/types/color.d.ts +102 -0
  16. package/dist/types/dates.d.ts +7 -0
  17. package/dist/types/dirs.d.ts +282 -0
  18. package/dist/types/docx/converter.d.ts +46 -0
  19. package/dist/types/docx/xml.d.ts +26 -0
  20. package/dist/types/docx/zip.d.ts +6 -0
  21. package/dist/types/docx.d.ts +11 -0
  22. package/dist/types/dom/core.d.ts +431 -0
  23. package/dist/types/dom/parser.d.ts +7 -0
  24. package/dist/types/dom/selector.d.ts +5 -0
  25. package/dist/types/dom.d.ts +5 -0
  26. package/dist/types/env.d.ts +124 -0
  27. package/dist/types/fetch-retry.d.ts +96 -0
  28. package/dist/types/file-lock.d.ts +23 -0
  29. package/dist/types/format.d.ts +37 -0
  30. package/dist/types/frontmatter.d.ts +46 -0
  31. package/dist/types/fs-error.d.ts +31 -0
  32. package/dist/types/glob.d.ts +28 -0
  33. package/dist/types/headers.d.ts +34 -0
  34. package/dist/types/index.d.ts +39 -0
  35. package/dist/types/json-parse.d.ts +74 -0
  36. package/dist/types/json.d.ts +14 -0
  37. package/dist/types/logger/rotating-file.d.ts +18 -0
  38. package/dist/types/logger.d.ts +96 -0
  39. package/dist/types/loop-phase.d.ts +10 -0
  40. package/dist/types/lru.d.ts +46 -0
  41. package/dist/types/marked/core.d.ts +445 -0
  42. package/dist/types/marked.d.ts +2 -0
  43. package/dist/types/mermaid-ascii.d.ts +11 -0
  44. package/dist/types/mime.d.ts +29 -0
  45. package/dist/types/module-timer.d.ts +1 -0
  46. package/dist/types/path-tree.d.ts +76 -0
  47. package/dist/types/path.d.ts +2 -0
  48. package/dist/types/peek-file.d.ts +29 -0
  49. package/dist/types/postmortem.d.ts +104 -0
  50. package/dist/types/process-name.d.ts +7 -0
  51. package/dist/types/procmgr.d.ts +74 -0
  52. package/dist/types/prompt.d.ts +18 -0
  53. package/dist/types/ptree.d.ts +110 -0
  54. package/dist/types/readability/readability.d.ts +9 -0
  55. package/dist/types/readability/readerable.d.ts +10 -0
  56. package/dist/types/readability/types.d.ts +70 -0
  57. package/dist/types/readability.d.ts +4 -0
  58. package/dist/types/ring.d.ts +93 -0
  59. package/dist/types/runtime-install.d.ts +78 -0
  60. package/dist/types/sanitize-text.d.ts +29 -0
  61. package/dist/types/snowflake.d.ts +25 -0
  62. package/dist/types/stderr-guard.d.ts +22 -0
  63. package/dist/types/stream.d.ts +67 -0
  64. package/dist/types/tab-spacing.d.ts +24 -0
  65. package/dist/types/temp.d.ts +17 -0
  66. package/dist/types/template.d.ts +62 -0
  67. package/dist/types/timing-buffer.d.ts +22 -0
  68. package/dist/types/tls-fetch.d.ts +37 -0
  69. package/dist/types/turndown/gfm.d.ts +11 -0
  70. package/dist/types/turndown/html.d.ts +5 -0
  71. package/dist/types/turndown/service.d.ts +21 -0
  72. package/dist/types/turndown/types.d.ts +70 -0
  73. package/dist/types/turndown.d.ts +4 -0
  74. package/dist/types/type-guards.d.ts +5 -0
  75. package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
  76. package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
  77. package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
  78. package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
  79. package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
  80. package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
  81. package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
  82. package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
  83. package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
  84. package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
  85. package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
  86. package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
  87. package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
  88. package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
  89. package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
  90. package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
  91. package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
  92. package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
  93. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
  94. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
  95. package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
  96. package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
  97. package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
  98. package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
  99. package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
  100. package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
  101. package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
  102. package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
  103. package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
  104. package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
  105. package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
  106. package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
  107. package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
  108. package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
  109. package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
  110. package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
  111. package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
  112. package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
  113. package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
  114. package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
  115. package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
  116. package/dist/types/version.d.ts +18 -0
  117. package/dist/types/vterm/buffer.d.ts +99 -0
  118. package/dist/types/vterm/terminal.d.ts +44 -0
  119. package/dist/types/vterm.d.ts +8 -0
  120. package/dist/types/which.d.ts +37 -0
  121. package/dist/types/worker-host.d.ts +51 -0
  122. package/dist/types/xml.d.ts +31 -0
  123. package/package.json +59 -0
  124. package/src/abortable.ts +109 -0
  125. package/src/acp/connection.ts +344 -0
  126. package/src/acp/protocol.ts +466 -0
  127. package/src/acp/schema.ts +160 -0
  128. package/src/acp/stream.ts +82 -0
  129. package/src/acp/transport.ts +213 -0
  130. package/src/acp.ts +6 -0
  131. package/src/async.ts +91 -0
  132. package/src/binary.ts +50 -0
  133. package/src/browsers.ts +501 -0
  134. package/src/chalk.ts +312 -0
  135. package/src/cli.ts +529 -0
  136. package/src/color.ts +302 -0
  137. package/src/dates.ts +194 -0
  138. package/src/dirs.ts +1026 -0
  139. package/src/docx/converter.ts +681 -0
  140. package/src/docx/xml.ts +166 -0
  141. package/src/docx/zip.ts +87 -0
  142. package/src/docx.ts +20 -0
  143. package/src/dom/core.ts +1254 -0
  144. package/src/dom/parser.ts +370 -0
  145. package/src/dom/selector.ts +290 -0
  146. package/src/dom.ts +33 -0
  147. package/src/env.ts +400 -0
  148. package/src/fetch-retry.ts +379 -0
  149. package/src/file-lock.ts +69 -0
  150. package/src/format.ts +113 -0
  151. package/src/frontmatter.ts +205 -0
  152. package/src/fs-error.ts +56 -0
  153. package/src/glob.ts +189 -0
  154. package/src/headers.ts +167 -0
  155. package/src/index.ts +59 -0
  156. package/src/json-parse.ts +821 -0
  157. package/src/json.ts +23 -0
  158. package/src/logger/rotating-file.ts +149 -0
  159. package/src/logger.ts +798 -0
  160. package/src/loop-phase.ts +49 -0
  161. package/src/lru.ts +185 -0
  162. package/src/marked/core.ts +1576 -0
  163. package/src/marked.ts +2 -0
  164. package/src/mermaid-ascii.ts +31 -0
  165. package/src/mime.ts +159 -0
  166. package/src/module-timer.ts +148 -0
  167. package/src/path-tree.ts +147 -0
  168. package/src/path.ts +28 -0
  169. package/src/peek-file.ts +188 -0
  170. package/src/postmortem.ts +433 -0
  171. package/src/process-name.ts +57 -0
  172. package/src/procmgr.ts +247 -0
  173. package/src/prompt.ts +545 -0
  174. package/src/ptree.ts +412 -0
  175. package/src/readability/readability.ts +533 -0
  176. package/src/readability/readerable.ts +51 -0
  177. package/src/readability/types.ts +72 -0
  178. package/src/readability.ts +11 -0
  179. package/src/ring.ts +169 -0
  180. package/src/runtime-install.ts +393 -0
  181. package/src/sanitize-text.ts +96 -0
  182. package/src/snowflake.ts +121 -0
  183. package/src/stderr-guard.ts +155 -0
  184. package/src/stream.ts +454 -0
  185. package/src/tab-spacing.ts +336 -0
  186. package/src/temp.ts +134 -0
  187. package/src/template.ts +586 -0
  188. package/src/timing-buffer.ts +47 -0
  189. package/src/tls-fetch.ts +178 -0
  190. package/src/turndown/gfm.ts +106 -0
  191. package/src/turndown/html.ts +257 -0
  192. package/src/turndown/service.ts +334 -0
  193. package/src/turndown/types.ts +81 -0
  194. package/src/turndown.ts +5 -0
  195. package/src/type-guards.ts +17 -0
  196. package/src/vendor/mermaid-ascii/NOTICE +33 -0
  197. package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
  198. package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
  199. package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
  200. package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
  201. package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
  202. package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
  203. package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
  204. package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
  205. package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
  206. package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
  207. package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
  208. package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +277 -0
  209. package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
  210. package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
  211. package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
  212. package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
  213. package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
  214. package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
  215. package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
  216. package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
  217. package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
  218. package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
  219. package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
  220. package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
  221. package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
  222. package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
  223. package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
  224. package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
  225. package/src/vendor/mermaid-ascii/class/types.ts +121 -0
  226. package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
  227. package/src/vendor/mermaid-ascii/er/types.ts +91 -0
  228. package/src/vendor/mermaid-ascii/index.ts +14 -0
  229. package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
  230. package/src/vendor/mermaid-ascii/parser.ts +645 -0
  231. package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
  232. package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
  233. package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
  234. package/src/vendor/mermaid-ascii/types.ts +164 -0
  235. package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
  236. package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
  237. package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
  238. package/src/version.ts +99 -0
  239. package/src/vterm/buffer.ts +218 -0
  240. package/src/vterm/terminal.ts +773 -0
  241. package/src/vterm.ts +8 -0
  242. package/src/which.ts +234 -0
  243. package/src/worker-host.ts +100 -0
  244. package/src/xml.ts +313 -0
@@ -0,0 +1,526 @@
1
+ /** Behavior-compatible reimplementation of @agentclientprotocol/sdk's used protocol surface. */
2
+ /** Metadata reserved for protocol extensions. */
3
+ export interface Meta {
4
+ _meta?: Record<string, unknown> | null;
5
+ }
6
+ /** A value which may be produced asynchronously. */
7
+ export type MaybePromise<T> = T | Promise<T>;
8
+ /** ACP protocol version identifier. */
9
+ export type ProtocolVersion = number;
10
+ /** Current ACP protocol version. */
11
+ export declare const PROTOCOL_VERSION = 1;
12
+ /** Conversation session identifier. */
13
+ export type SessionId = string;
14
+ /** Tool call identifier. */
15
+ export type ToolCallId = string;
16
+ /** ACP tool category. */
17
+ export type ToolKind = "read" | "edit" | "delete" | "move" | "search" | "execute" | "think" | "fetch" | "switch_mode" | "other";
18
+ /** ACP tool execution state. */
19
+ export type ToolCallStatus = "pending" | "in_progress" | "completed" | "failed";
20
+ /** ACP prompt stop reason. */
21
+ export type StopReason = "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled";
22
+ /** ACP permission choice kind. */
23
+ export type PermissionOptionKind = "allow_once" | "allow_always" | "reject_once" | "reject_always";
24
+ /** Text content block. */
25
+ export interface TextContent extends Meta {
26
+ type: "text";
27
+ text: string;
28
+ }
29
+ /** Image content block. */
30
+ export interface ImageContent extends Meta {
31
+ type: "image";
32
+ data: string;
33
+ mimeType: string;
34
+ }
35
+ /** Audio content block. */
36
+ export interface AudioContent extends Meta {
37
+ type: "audio";
38
+ data: string;
39
+ mimeType: string;
40
+ }
41
+ /** Resource link content block. */
42
+ export interface ResourceLink extends Meta {
43
+ type: "resource_link";
44
+ uri: string;
45
+ name?: string;
46
+ title?: string;
47
+ mimeType?: string | null;
48
+ description?: string | null;
49
+ size?: number | null;
50
+ }
51
+ /** Text or blob resource embedded in a prompt. */
52
+ export type EmbeddedResourceValue = ({
53
+ uri: string;
54
+ text: string;
55
+ mimeType?: string;
56
+ } | {
57
+ uri: string;
58
+ blob: string;
59
+ mimeType?: string;
60
+ }) & Meta;
61
+ /** Embedded resource content block. */
62
+ export interface EmbeddedResource extends Meta {
63
+ type: "resource";
64
+ resource: EmbeddedResourceValue;
65
+ }
66
+ /** Displayable ACP content. */
67
+ export type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource;
68
+ /** Content wrapper used by tool calls. */
69
+ export interface ToolContent extends Meta {
70
+ type: "content";
71
+ content: ContentBlock;
72
+ }
73
+ /** File diff emitted by a tool call. */
74
+ export interface ToolDiff extends Meta {
75
+ type: "diff";
76
+ path: string;
77
+ oldText?: string | null;
78
+ newText: string;
79
+ }
80
+ /** Terminal reference emitted by a tool call. */
81
+ export interface ToolTerminal extends Meta {
82
+ type: "terminal";
83
+ terminalId: string;
84
+ }
85
+ /** Tool call output item. */
86
+ export type ToolCallContent = ToolContent | ToolDiff | ToolTerminal;
87
+ /** File location associated with a tool call. */
88
+ export interface ToolCallLocation extends Meta {
89
+ path: string;
90
+ line?: number | null;
91
+ }
92
+ /** Initial tool call notification. */
93
+ export interface ToolCall extends Meta {
94
+ toolCallId: ToolCallId;
95
+ title: string;
96
+ kind?: ToolKind | null;
97
+ status?: ToolCallStatus | null;
98
+ content?: ToolCallContent[] | null;
99
+ locations?: ToolCallLocation[] | null;
100
+ rawInput?: unknown;
101
+ rawOutput?: unknown;
102
+ }
103
+ /** Partial update to a tool call. */
104
+ export interface ToolCallUpdate extends Meta {
105
+ toolCallId: ToolCallId;
106
+ title?: string | null;
107
+ kind?: ToolKind | null;
108
+ status?: ToolCallStatus | null;
109
+ content?: ToolCallContent[] | null;
110
+ locations?: ToolCallLocation[] | null;
111
+ rawInput?: unknown;
112
+ rawOutput?: unknown;
113
+ }
114
+ /** Permission option presented by the client. */
115
+ export interface PermissionOption extends Meta {
116
+ optionId: string;
117
+ name: string;
118
+ kind: PermissionOptionKind;
119
+ }
120
+ /** Request for permission to execute a tool call. */
121
+ export interface RequestPermissionRequest extends Meta {
122
+ sessionId: SessionId;
123
+ toolCall: ToolCallUpdate;
124
+ options: PermissionOption[];
125
+ }
126
+ /** Permission request response. */
127
+ export interface RequestPermissionResponse extends Meta {
128
+ outcome: {
129
+ outcome: "cancelled";
130
+ } | {
131
+ outcome: "selected";
132
+ optionId: string;
133
+ };
134
+ }
135
+ /** Client filesystem capabilities. */
136
+ export interface FileSystemCapabilities {
137
+ readTextFile?: boolean;
138
+ writeTextFile?: boolean;
139
+ }
140
+ /** Capabilities advertised by an ACP client. */
141
+ export interface ClientCapabilities {
142
+ fs?: FileSystemCapabilities;
143
+ terminal?: boolean;
144
+ auth?: {
145
+ terminal?: boolean;
146
+ };
147
+ elicitation?: {
148
+ form?: Record<string, unknown>;
149
+ url?: Record<string, unknown>;
150
+ };
151
+ _meta?: Record<string, unknown>;
152
+ }
153
+ /** Implementation identity sent during initialization. */
154
+ export interface Implementation {
155
+ name: string;
156
+ version: string;
157
+ title?: string;
158
+ }
159
+ /** Initialization request. */
160
+ export interface InitializeRequest extends Meta {
161
+ protocolVersion: ProtocolVersion;
162
+ clientCapabilities?: ClientCapabilities;
163
+ clientInfo?: Implementation | null;
164
+ }
165
+ /** Authentication method using an environment variable. */
166
+ export interface AuthMethodEnvVar extends Meta {
167
+ type: "env_var";
168
+ id: string;
169
+ name: string;
170
+ description?: string | null;
171
+ variable: string;
172
+ }
173
+ /** Authentication method using a terminal command. */
174
+ export interface AuthMethodTerminal extends Meta {
175
+ type: "terminal";
176
+ id: string;
177
+ name: string;
178
+ description?: string | null;
179
+ command?: string;
180
+ args?: string[];
181
+ }
182
+ /** Authentication method handled by the agent. */
183
+ export interface AuthMethodAgent extends Meta {
184
+ type?: "agent";
185
+ id: string;
186
+ name: string;
187
+ description?: string | null;
188
+ }
189
+ /** Authentication method advertised by an agent. */
190
+ export type AuthMethod = AuthMethodEnvVar | AuthMethodTerminal | AuthMethodAgent;
191
+ /** Initialization response. */
192
+ export interface InitializeResponse extends Meta {
193
+ protocolVersion: ProtocolVersion;
194
+ agentCapabilities?: Record<string, unknown>;
195
+ authMethods?: AuthMethod[];
196
+ agentInfo?: Implementation | null;
197
+ }
198
+ /** Authentication request. */
199
+ export interface AuthenticateRequest extends Meta {
200
+ methodId: string;
201
+ }
202
+ /** Authentication response. */
203
+ export interface AuthenticateResponse extends Meta {
204
+ }
205
+ /** ACP MCP server configuration. */
206
+ export type McpServer = ({
207
+ type?: "stdio";
208
+ name: string;
209
+ command: string;
210
+ args?: string[];
211
+ env: Array<{
212
+ name: string;
213
+ value: string;
214
+ }>;
215
+ } | {
216
+ type: "http" | "sse" | "acp";
217
+ name: string;
218
+ url: string;
219
+ headers: Array<{
220
+ name: string;
221
+ value: string;
222
+ }>;
223
+ }) & Meta;
224
+ /** Session mode descriptor. */
225
+ export interface SessionMode extends Meta {
226
+ id: string;
227
+ name: string;
228
+ description?: string | null;
229
+ }
230
+ /** Current session mode and available choices. */
231
+ export interface SessionModeState extends Meta {
232
+ currentModeId: string;
233
+ availableModes: SessionMode[];
234
+ }
235
+ /** Select configuration value. */
236
+ export interface SessionConfigSelectOption extends Meta {
237
+ value: string;
238
+ name: string;
239
+ description?: string | null;
240
+ }
241
+ /** Session configuration option. */
242
+ export type SessionConfigOption = ({
243
+ type: "select";
244
+ currentValue: string;
245
+ options: SessionConfigSelectOption[];
246
+ } | {
247
+ type: "boolean";
248
+ currentValue: boolean;
249
+ }) & {
250
+ id: string;
251
+ name: string;
252
+ description?: string | null;
253
+ category?: string | null;
254
+ } & Meta;
255
+ /** Shared fields for creating or restoring a session. */
256
+ export interface SessionSetupRequest extends Meta {
257
+ cwd: string;
258
+ mcpServers: McpServer[];
259
+ additionalDirectories?: string[];
260
+ }
261
+ /** New-session request. */
262
+ export interface NewSessionRequest extends SessionSetupRequest {
263
+ }
264
+ /** New-session response. */
265
+ export interface NewSessionResponse extends Meta {
266
+ sessionId: SessionId;
267
+ modes?: SessionModeState | null;
268
+ configOptions?: SessionConfigOption[] | null;
269
+ }
270
+ /** Load-session request. */
271
+ export interface LoadSessionRequest extends SessionSetupRequest {
272
+ sessionId: SessionId;
273
+ }
274
+ /** Load-session response. */
275
+ export interface LoadSessionResponse extends Meta {
276
+ modes?: SessionModeState | null;
277
+ configOptions?: SessionConfigOption[] | null;
278
+ }
279
+ /** Resume-session request. */
280
+ export interface ResumeSessionRequest extends LoadSessionRequest {
281
+ }
282
+ /** Resume-session response. */
283
+ export interface ResumeSessionResponse extends LoadSessionResponse {
284
+ }
285
+ /** Fork-session request. */
286
+ export interface ForkSessionRequest extends LoadSessionRequest {
287
+ }
288
+ /** Fork-session response. */
289
+ export interface ForkSessionResponse extends NewSessionResponse {
290
+ }
291
+ /** Close-session request. */
292
+ export interface CloseSessionRequest extends Meta {
293
+ sessionId: SessionId;
294
+ }
295
+ /** Close-session response. */
296
+ export interface CloseSessionResponse extends Meta {
297
+ }
298
+ /** Session-list request. */
299
+ export interface ListSessionsRequest extends Meta {
300
+ cwd?: string | null;
301
+ cursor?: string | null;
302
+ additionalDirectories?: string[];
303
+ }
304
+ /** Session metadata. */
305
+ export interface SessionInfo extends Meta {
306
+ sessionId: SessionId;
307
+ cwd: string;
308
+ additionalDirectories?: string[];
309
+ title?: string | null;
310
+ updatedAt?: string | null;
311
+ }
312
+ /** Session-list response. */
313
+ export interface ListSessionsResponse extends Meta {
314
+ sessions: SessionInfo[];
315
+ nextCursor?: string | null;
316
+ }
317
+ /** Set-mode request. */
318
+ export interface SetSessionModeRequest extends Meta {
319
+ sessionId: SessionId;
320
+ modeId: string;
321
+ }
322
+ /** Set-mode response. */
323
+ export interface SetSessionModeResponse extends Meta {
324
+ }
325
+ /** Set-config request. */
326
+ export interface SetSessionConfigOptionRequest extends Meta {
327
+ sessionId: SessionId;
328
+ configId: string;
329
+ value: string | boolean;
330
+ }
331
+ /** Set-config response. */
332
+ export interface SetSessionConfigOptionResponse extends Meta {
333
+ configOptions: SessionConfigOption[];
334
+ }
335
+ /** Slash command advertised by an agent. */
336
+ export interface AvailableCommand extends Meta {
337
+ name: string;
338
+ description: string;
339
+ input?: {
340
+ hint: string;
341
+ } | null;
342
+ }
343
+ /** Session plan entry. */
344
+ export interface PlanEntry extends Meta {
345
+ content: string;
346
+ priority: "high" | "medium" | "low";
347
+ status: "pending" | "in_progress" | "completed";
348
+ }
349
+ /** Session update payload. */
350
+ export type SessionUpdate = ({
351
+ sessionUpdate: "agent_message_chunk" | "agent_thought_chunk" | "user_message_chunk";
352
+ content: ContentBlock;
353
+ messageId?: string;
354
+ } & Meta) | ({
355
+ sessionUpdate: "tool_call";
356
+ } & ToolCall) | ({
357
+ sessionUpdate: "tool_call_update";
358
+ } & ToolCallUpdate) | ({
359
+ sessionUpdate: "plan";
360
+ entries: PlanEntry[];
361
+ } & Meta) | ({
362
+ sessionUpdate: "current_mode_update";
363
+ currentModeId: string;
364
+ } & Meta) | ({
365
+ sessionUpdate: "config_option_update";
366
+ configOptions: SessionConfigOption[];
367
+ } & Meta) | ({
368
+ sessionUpdate: "available_commands_update";
369
+ availableCommands: AvailableCommand[];
370
+ } & Meta) | ({
371
+ sessionUpdate: "session_info_update";
372
+ title?: string | null;
373
+ updatedAt?: string | null;
374
+ } & Meta) | ({
375
+ sessionUpdate: "usage_update";
376
+ size: number;
377
+ used: number;
378
+ cost?: {
379
+ amount: number;
380
+ currency: string;
381
+ } | null;
382
+ } & Meta);
383
+ /** Notification containing a session update. */
384
+ export interface SessionNotification extends Meta {
385
+ sessionId: SessionId;
386
+ update: SessionUpdate;
387
+ }
388
+ /** Prompt request. */
389
+ export interface PromptRequest extends Meta {
390
+ sessionId: SessionId;
391
+ prompt: ContentBlock[];
392
+ }
393
+ /** Prompt token usage. */
394
+ export interface Usage extends Meta {
395
+ totalTokens: number;
396
+ inputTokens: number;
397
+ outputTokens: number;
398
+ cachedReadTokens?: number | null;
399
+ cachedWriteTokens?: number | null;
400
+ thoughtTokens?: number | null;
401
+ }
402
+ /** Prompt response. */
403
+ export interface PromptResponse extends Meta {
404
+ stopReason: StopReason;
405
+ usage?: Usage | null;
406
+ }
407
+ /** Read-file request. */
408
+ export interface ReadTextFileRequest extends Meta {
409
+ sessionId: string;
410
+ path: string;
411
+ line?: number | null;
412
+ limit?: number | null;
413
+ }
414
+ /** Read-file response. */
415
+ export interface ReadTextFileResponse extends Meta {
416
+ content: string;
417
+ }
418
+ /** Write-file request. */
419
+ export interface WriteTextFileRequest extends Meta {
420
+ sessionId: string;
421
+ path: string;
422
+ content: string;
423
+ }
424
+ /** Write-file response. */
425
+ export interface WriteTextFileResponse extends Meta {
426
+ }
427
+ /** Create-terminal request. */
428
+ export interface CreateTerminalRequest extends Meta {
429
+ sessionId: string;
430
+ command: string;
431
+ args?: string[];
432
+ env?: Array<{
433
+ name: string;
434
+ value: string;
435
+ }>;
436
+ cwd?: string;
437
+ outputByteLimit?: number;
438
+ }
439
+ /** Terminal output response. */
440
+ export interface TerminalOutputResponse extends Meta {
441
+ output: string;
442
+ truncated: boolean;
443
+ exitStatus?: {
444
+ exitCode?: number | null;
445
+ signal?: string | null;
446
+ } | null;
447
+ }
448
+ /** Terminal exit response. */
449
+ export interface WaitForTerminalExitResponse extends Meta {
450
+ exitCode?: number | null;
451
+ signal?: string | null;
452
+ }
453
+ /** Empty terminal response. */
454
+ export interface TerminalActionResponse extends Meta {
455
+ }
456
+ /** Elicitation scalar value. */
457
+ export type ElicitationContentValue = string | number | boolean | string[];
458
+ /** Elicitation property schema. */
459
+ export type ElicitationPropertySchema = Record<string, unknown> & {
460
+ type: string;
461
+ title?: string;
462
+ description?: string;
463
+ };
464
+ /** Elicitation creation request. */
465
+ export type CreateElicitationRequest = ({
466
+ mode: "form";
467
+ sessionId: string;
468
+ message: string;
469
+ requestedSchema: {
470
+ type: "object";
471
+ properties: Record<string, ElicitationPropertySchema>;
472
+ required?: string[];
473
+ };
474
+ } & Meta) | ({
475
+ mode: "url";
476
+ sessionId: string;
477
+ message: string;
478
+ url: string;
479
+ elicitationId: string;
480
+ } & Meta) | ({
481
+ mode: string;
482
+ sessionId: string;
483
+ message: string;
484
+ requestedSchema?: {
485
+ type: "object";
486
+ properties: Record<string, ElicitationPropertySchema>;
487
+ required?: string[];
488
+ };
489
+ url?: string;
490
+ elicitationId?: string;
491
+ } & Meta);
492
+ /** Elicitation creation response. */
493
+ export type CreateElicitationResponse = ({
494
+ action: "accept";
495
+ content: Record<string, ElicitationContentValue>;
496
+ } & Meta) | ({
497
+ action: "decline" | "cancel";
498
+ content?: never;
499
+ } & Meta) | ({
500
+ action: string;
501
+ content?: Record<string, ElicitationContentValue>;
502
+ } & Meta);
503
+ /** Completion notification for URL elicitation. */
504
+ export interface CompleteElicitationNotification extends Meta {
505
+ sessionId: string;
506
+ elicitationId: string;
507
+ }
508
+ /** Agent-side request handler contract. */
509
+ export interface Agent {
510
+ initialize(params: InitializeRequest): MaybePromise<InitializeResponse>;
511
+ newSession(params: NewSessionRequest): MaybePromise<NewSessionResponse>;
512
+ prompt(params: PromptRequest): MaybePromise<PromptResponse>;
513
+ cancel(params: {
514
+ sessionId: string;
515
+ }): MaybePromise<void>;
516
+ authenticate?(params: AuthenticateRequest): MaybePromise<AuthenticateResponse | void>;
517
+ loadSession?(params: LoadSessionRequest): MaybePromise<LoadSessionResponse | void>;
518
+ listSessions?(params: ListSessionsRequest): MaybePromise<ListSessionsResponse>;
519
+ resumeSession?(params: ResumeSessionRequest): MaybePromise<ResumeSessionResponse>;
520
+ unstable_forkSession?(params: ForkSessionRequest): MaybePromise<ForkSessionResponse>;
521
+ closeSession?(params: CloseSessionRequest): MaybePromise<CloseSessionResponse | void>;
522
+ setSessionMode?(params: SetSessionModeRequest): MaybePromise<SetSessionModeResponse | void>;
523
+ setSessionConfigOption?(params: SetSessionConfigOptionRequest): MaybePromise<SetSessionConfigOptionResponse>;
524
+ extMethod?(method: string, params: Record<string, unknown>): MaybePromise<Record<string, unknown>>;
525
+ extNotification?(method: string, params: Record<string, unknown>): MaybePromise<void>;
526
+ }
@@ -0,0 +1,41 @@
1
+ import type { ForkSessionResponse, LoadSessionResponse, NewSessionResponse, PromptResponse, SessionNotification } from "./protocol.js";
2
+ /** Validation failure compatible with the used Zod error surface. */
3
+ export interface ValidationError {
4
+ issues: Array<{
5
+ path: Array<string | number>;
6
+ message: string;
7
+ }>;
8
+ }
9
+ /** Successful validation result. */
10
+ export interface ValidationSuccess<T> {
11
+ success: true;
12
+ data: T;
13
+ }
14
+ /** Failed validation result. */
15
+ export interface ValidationFailure {
16
+ success: false;
17
+ error: ValidationError;
18
+ }
19
+ /** Runtime validator compatible with the used schema call shape. */
20
+ export interface Validator<T> {
21
+ safeParse(value: unknown): ValidationSuccess<T> | ValidationFailure;
22
+ parse(value: unknown): T;
23
+ }
24
+ /** Validator for new-session responses. */
25
+ export declare const zNewSessionResponse: Validator<NewSessionResponse>;
26
+ /** Validator for load-session responses. */
27
+ export declare const zLoadSessionResponse: Validator<LoadSessionResponse>;
28
+ /** Validator for fork-session responses. */
29
+ export declare const zForkSessionResponse: Validator<ForkSessionResponse>;
30
+ /** Validator for prompt responses. */
31
+ export declare const zPromptResponse: Validator<PromptResponse>;
32
+ /** Validator for session notifications. */
33
+ export declare const zSessionNotification: Validator<SessionNotification>;
34
+ /** ACP runtime validators. */
35
+ export declare const schema: {
36
+ readonly zNewSessionResponse: Validator<NewSessionResponse>;
37
+ readonly zLoadSessionResponse: Validator<LoadSessionResponse>;
38
+ readonly zForkSessionResponse: Validator<ForkSessionResponse>;
39
+ readonly zPromptResponse: Validator<PromptResponse>;
40
+ readonly zSessionNotification: Validator<SessionNotification>;
41
+ };
@@ -0,0 +1,8 @@
1
+ import type { AnyMessage } from "./transport.js";
2
+ /** Bidirectional JSON-RPC message transport. */
3
+ export interface Stream {
4
+ writable: WritableStream<AnyMessage>;
5
+ readable: ReadableStream<AnyMessage>;
6
+ }
7
+ /** Converts byte-oriented newline-delimited JSON streams to an ACP message transport. */
8
+ export declare function ndJsonStream(output: WritableStream<Uint8Array>, input: ReadableStream<Uint8Array>): Stream;
@@ -0,0 +1,81 @@
1
+ import type { MaybePromise } from "./protocol.js";
2
+ import type { Stream } from "./stream.js";
3
+ /** JSON-RPC request identifier. */
4
+ export type JsonRpcId = string | number | null;
5
+ /** JSON-RPC request. */
6
+ export interface AnyRequest {
7
+ jsonrpc: "2.0";
8
+ id: JsonRpcId;
9
+ method: string;
10
+ params?: unknown;
11
+ }
12
+ /** JSON-RPC notification. */
13
+ export interface AnyNotification {
14
+ jsonrpc: "2.0";
15
+ method: string;
16
+ params?: unknown;
17
+ }
18
+ /** JSON-RPC error payload. */
19
+ export interface ErrorResponse {
20
+ code: number;
21
+ message: string;
22
+ data?: unknown;
23
+ }
24
+ /** JSON-RPC response. */
25
+ export type AnyResponse = {
26
+ jsonrpc: "2.0";
27
+ id: JsonRpcId;
28
+ } & ({
29
+ result: unknown;
30
+ } | {
31
+ error: ErrorResponse;
32
+ });
33
+ /** Any JSON-RPC wire message. */
34
+ export type AnyMessage = AnyRequest | AnyNotification | AnyResponse;
35
+ /** Error returned by a JSON-RPC peer or handler. */
36
+ export declare class RequestError extends Error {
37
+ /** JSON-RPC error code. */
38
+ readonly code: number;
39
+ /** Optional protocol error data. */
40
+ readonly data?: unknown;
41
+ constructor(code: number, message: string, data?: unknown);
42
+ /** Creates a JSON parse error. */
43
+ static parseError(data?: unknown, additionalMessage?: string): RequestError;
44
+ /** Creates an invalid-request error. */
45
+ static invalidRequest(data?: unknown, additionalMessage?: string): RequestError;
46
+ /** Creates a method-not-found error. */
47
+ static methodNotFound(method: string): RequestError;
48
+ /** Creates an invalid-parameters error. */
49
+ static invalidParams(data?: unknown, additionalMessage?: string): RequestError;
50
+ /** Creates an internal error. */
51
+ static internalError(data?: unknown, additionalMessage?: string): RequestError;
52
+ /** Creates a cancellation error. */
53
+ static requestCancelled(data?: unknown, additionalMessage?: string): RequestError;
54
+ /** Creates an authentication-required error. */
55
+ static authRequired(data?: unknown, additionalMessage?: string): RequestError;
56
+ /** Creates a resource-not-found error. */
57
+ static resourceNotFound(uri?: string): RequestError;
58
+ /** Converts this error into a JSON-RPC result. */
59
+ toResult(): {
60
+ error: ErrorResponse;
61
+ };
62
+ /** Converts this error into a JSON-RPC error payload. */
63
+ toErrorResponse(): ErrorResponse;
64
+ }
65
+ type Dispatcher = (method: string, params: unknown, notification: boolean) => MaybePromise<unknown>;
66
+ /** Correlated bidirectional JSON-RPC connection. */
67
+ export declare class RpcConnection {
68
+ #private;
69
+ constructor(stream: Stream, dispatcher: Dispatcher);
70
+ /** Signal aborted when the stream closes. */
71
+ get signal(): AbortSignal;
72
+ /** Promise resolved when the stream closes. */
73
+ get closed(): Promise<void>;
74
+ /** Sends a correlated JSON-RPC request. */
75
+ request<Response>(method: string, params?: unknown): Promise<Response>;
76
+ /** Sends a JSON-RPC notification. */
77
+ notify(method: string, params?: unknown): Promise<void>;
78
+ /** Closes the connection and rejects outstanding requests. */
79
+ close(error?: unknown): void;
80
+ }
81
+ export {};
@@ -0,0 +1,6 @@
1
+ /** Behavior-compatible reimplementation of @agentclientprotocol/sdk's used surface. */
2
+ export * from "./acp/connection.js";
3
+ export * from "./acp/protocol.js";
4
+ export * from "./acp/schema.js";
5
+ export * from "./acp/stream.js";
6
+ export * from "./acp/transport.js";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Wrap a promise with a timeout and optional abort signal.
3
+ * Rejects with the given message if the timeout fires first.
4
+ * Cleans up all listeners on settlement.
5
+ */
6
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, message: string, signal?: AbortSignal): Promise<T>;
7
+ /**
8
+ * Coalesces rapid-fire writes into one deferred batch. `push` queues a value
9
+ * and returns a promise for the batch flush; the first push of a batch arms a
10
+ * timer (`delayMs`, or a microtask at 0), and every push before it fires joins
11
+ * the same batch and shares the same promise. Used to keep hot paths off
12
+ * synchronous storage (prompt history, model perf).
13
+ */
14
+ export declare class AsyncDrain<T> {
15
+ #private;
16
+ readonly delayMs: number;
17
+ constructor(delayMs?: number);
18
+ /** Queue `value`; `hnd` receives the whole batch when the window closes. */
19
+ push(value: T, hnd: (values: T[]) => Promise<void> | void): Promise<void>;
20
+ }