@spekn/cli 1.0.0 → 1.0.1

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 (154) hide show
  1. package/README.md +58 -0
  2. package/dist/main.js +3707 -611
  3. package/dist/tui/index.mjs +2 -2
  4. package/package.json +29 -12
  5. package/dist/__tests__/export-cli.test.d.ts +0 -1
  6. package/dist/__tests__/export-cli.test.js +0 -70
  7. package/dist/__tests__/tui-args-policy.test.d.ts +0 -1
  8. package/dist/__tests__/tui-args-policy.test.js +0 -50
  9. package/dist/acp-S2MHZOAD.mjs +0 -23
  10. package/dist/acp-UCCI44JY.mjs +0 -25
  11. package/dist/auth/credentials-store.d.ts +0 -2
  12. package/dist/auth/credentials-store.js +0 -5
  13. package/dist/auth/device-flow.d.ts +0 -36
  14. package/dist/auth/device-flow.js +0 -189
  15. package/dist/auth/jwt.d.ts +0 -1
  16. package/dist/auth/jwt.js +0 -6
  17. package/dist/auth/session.d.ts +0 -67
  18. package/dist/auth/session.js +0 -86
  19. package/dist/auth-login.d.ts +0 -34
  20. package/dist/auth-login.js +0 -202
  21. package/dist/auth-logout.d.ts +0 -25
  22. package/dist/auth-logout.js +0 -115
  23. package/dist/auth-status.d.ts +0 -24
  24. package/dist/auth-status.js +0 -109
  25. package/dist/backlog-generate.d.ts +0 -11
  26. package/dist/backlog-generate.js +0 -308
  27. package/dist/backlog-health.d.ts +0 -11
  28. package/dist/backlog-health.js +0 -287
  29. package/dist/bridge-login.d.ts +0 -40
  30. package/dist/bridge-login.js +0 -277
  31. package/dist/chunk-3PAYRI4G.mjs +0 -2428
  32. package/dist/chunk-M4CS3A25.mjs +0 -2426
  33. package/dist/commands/auth/login.d.ts +0 -30
  34. package/dist/commands/auth/login.js +0 -164
  35. package/dist/commands/auth/logout.d.ts +0 -25
  36. package/dist/commands/auth/logout.js +0 -115
  37. package/dist/commands/auth/status.d.ts +0 -24
  38. package/dist/commands/auth/status.js +0 -109
  39. package/dist/commands/backlog/generate.d.ts +0 -11
  40. package/dist/commands/backlog/generate.js +0 -308
  41. package/dist/commands/backlog/health.d.ts +0 -11
  42. package/dist/commands/backlog/health.js +0 -287
  43. package/dist/commands/bridge/login.d.ts +0 -36
  44. package/dist/commands/bridge/login.js +0 -258
  45. package/dist/commands/export.d.ts +0 -35
  46. package/dist/commands/export.js +0 -485
  47. package/dist/commands/marketplace-export.d.ts +0 -21
  48. package/dist/commands/marketplace-export.js +0 -214
  49. package/dist/commands/project-clean.d.ts +0 -1
  50. package/dist/commands/project-clean.js +0 -126
  51. package/dist/commands/repo/common.d.ts +0 -105
  52. package/dist/commands/repo/common.js +0 -775
  53. package/dist/commands/repo/detach.d.ts +0 -2
  54. package/dist/commands/repo/detach.js +0 -120
  55. package/dist/commands/repo/register.d.ts +0 -21
  56. package/dist/commands/repo/register.js +0 -175
  57. package/dist/commands/repo/sync.d.ts +0 -22
  58. package/dist/commands/repo/sync.js +0 -873
  59. package/dist/commands/skills-import-local.d.ts +0 -16
  60. package/dist/commands/skills-import-local.js +0 -352
  61. package/dist/commands/spec/drift-check.d.ts +0 -3
  62. package/dist/commands/spec/drift-check.js +0 -186
  63. package/dist/commands/spec/frontmatter.d.ts +0 -11
  64. package/dist/commands/spec/frontmatter.js +0 -219
  65. package/dist/commands/spec/lint.d.ts +0 -11
  66. package/dist/commands/spec/lint.js +0 -499
  67. package/dist/commands/spec/parse.d.ts +0 -11
  68. package/dist/commands/spec/parse.js +0 -162
  69. package/dist/export.d.ts +0 -35
  70. package/dist/export.js +0 -485
  71. package/dist/main.d.ts +0 -1
  72. package/dist/marketplace-export.d.ts +0 -21
  73. package/dist/marketplace-export.js +0 -214
  74. package/dist/project-clean.d.ts +0 -1
  75. package/dist/project-clean.js +0 -126
  76. package/dist/project-context.d.ts +0 -99
  77. package/dist/project-context.js +0 -376
  78. package/dist/repo-common.d.ts +0 -101
  79. package/dist/repo-common.js +0 -671
  80. package/dist/repo-detach.d.ts +0 -2
  81. package/dist/repo-detach.js +0 -102
  82. package/dist/repo-ingest.d.ts +0 -29
  83. package/dist/repo-ingest.js +0 -305
  84. package/dist/repo-register.d.ts +0 -21
  85. package/dist/repo-register.js +0 -175
  86. package/dist/repo-sync.d.ts +0 -16
  87. package/dist/repo-sync.js +0 -152
  88. package/dist/resources/prompt-loader.d.ts +0 -1
  89. package/dist/resources/prompt-loader.js +0 -62
  90. package/dist/skills-import-local.d.ts +0 -16
  91. package/dist/skills-import-local.js +0 -352
  92. package/dist/spec-drift-check.d.ts +0 -3
  93. package/dist/spec-drift-check.js +0 -186
  94. package/dist/spec-frontmatter.d.ts +0 -11
  95. package/dist/spec-frontmatter.js +0 -219
  96. package/dist/spec-lint.d.ts +0 -11
  97. package/dist/spec-lint.js +0 -499
  98. package/dist/spec-parse.d.ts +0 -11
  99. package/dist/spec-parse.js +0 -162
  100. package/dist/stubs/dotenv.d.ts +0 -5
  101. package/dist/stubs/dotenv.js +0 -6
  102. package/dist/stubs/typeorm.d.ts +0 -22
  103. package/dist/stubs/typeorm.js +0 -28
  104. package/dist/tui/app.d.ts +0 -7
  105. package/dist/tui/app.js +0 -122
  106. package/dist/tui/args.d.ts +0 -8
  107. package/dist/tui/args.js +0 -57
  108. package/dist/tui/capabilities/policy.d.ts +0 -7
  109. package/dist/tui/capabilities/policy.js +0 -64
  110. package/dist/tui/components/frame.d.ts +0 -8
  111. package/dist/tui/components/frame.js +0 -8
  112. package/dist/tui/components/status-bar.d.ts +0 -8
  113. package/dist/tui/components/status-bar.js +0 -8
  114. package/dist/tui/index.d.ts +0 -2
  115. package/dist/tui/index.js +0 -23
  116. package/dist/tui/keymap/use-global-keymap.d.ts +0 -19
  117. package/dist/tui/keymap/use-global-keymap.js +0 -82
  118. package/dist/tui/navigation/nav-items.d.ts +0 -3
  119. package/dist/tui/navigation/nav-items.js +0 -18
  120. package/dist/tui/screens/bridge.d.ts +0 -8
  121. package/dist/tui/screens/bridge.js +0 -19
  122. package/dist/tui/screens/decisions.d.ts +0 -5
  123. package/dist/tui/screens/decisions.js +0 -28
  124. package/dist/tui/screens/export.d.ts +0 -5
  125. package/dist/tui/screens/export.js +0 -16
  126. package/dist/tui/screens/home.d.ts +0 -5
  127. package/dist/tui/screens/home.js +0 -33
  128. package/dist/tui/screens/locked.d.ts +0 -5
  129. package/dist/tui/screens/locked.js +0 -9
  130. package/dist/tui/screens/specs.d.ts +0 -5
  131. package/dist/tui/screens/specs.js +0 -31
  132. package/dist/tui/services/client.d.ts +0 -1
  133. package/dist/tui/services/client.js +0 -18
  134. package/dist/tui/services/context-service.d.ts +0 -19
  135. package/dist/tui/services/context-service.js +0 -246
  136. package/dist/tui/shared-enums.d.ts +0 -16
  137. package/dist/tui/shared-enums.js +0 -19
  138. package/dist/tui/state/use-app-state.d.ts +0 -35
  139. package/dist/tui/state/use-app-state.js +0 -177
  140. package/dist/tui/types.d.ts +0 -77
  141. package/dist/tui/types.js +0 -2
  142. package/dist/tui-bundle.d.ts +0 -1
  143. package/dist/tui-bundle.js +0 -5
  144. package/dist/tui-entry.mjs +0 -1407
  145. package/dist/utils/cli-runtime.d.ts +0 -5
  146. package/dist/utils/cli-runtime.js +0 -22
  147. package/dist/utils/help-error.d.ts +0 -7
  148. package/dist/utils/help-error.js +0 -14
  149. package/dist/utils/interaction.d.ts +0 -19
  150. package/dist/utils/interaction.js +0 -93
  151. package/dist/utils/structured-log.d.ts +0 -7
  152. package/dist/utils/structured-log.js +0 -112
  153. package/dist/utils/trpc-url.d.ts +0 -4
  154. package/dist/utils/trpc-url.js +0 -15
@@ -1,2428 +0,0 @@
1
- // Bundled TUI entry (ESM) — loaded via dynamic import() from CJS main.js
2
- import { createRequire as __createRequire } from 'module';
3
- const require = __createRequire(import.meta.url);
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
- }) : x)(function(x) {
14
- if (typeof require !== "undefined") return require.apply(this, arguments);
15
- throw Error('Dynamic require of "' + x + '" is not supported');
16
- });
17
- var __esm = (fn, res) => function __init() {
18
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
19
- };
20
- var __commonJS = (cb, mod) => function __require2() {
21
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
22
- };
23
- var __export = (target, all) => {
24
- for (var name in all)
25
- __defProp(target, name, { get: all[name], enumerable: true });
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") {
29
- for (let key of __getOwnPropNames(from))
30
- if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
- }
33
- return to;
34
- };
35
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
36
- // If the importer is in node compatibility mode or this is not an ESM
37
- // file that has been converted to a CommonJS file using a Babel-
38
- // compatible transform (i.e. "__esModule" has not been set), then set
39
- // "default" to the CommonJS "module.exports" for node compatibility.
40
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
41
- mod
42
- ));
43
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
44
-
45
- // ../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js
46
- var AGENT_METHODS, CLIENT_METHODS, PROTOCOL_VERSION;
47
- var init_schema = __esm({
48
- "../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js"() {
49
- "use strict";
50
- AGENT_METHODS = {
51
- authenticate: "authenticate",
52
- initialize: "initialize",
53
- session_cancel: "session/cancel",
54
- session_fork: "session/fork",
55
- session_list: "session/list",
56
- session_load: "session/load",
57
- session_new: "session/new",
58
- session_prompt: "session/prompt",
59
- session_resume: "session/resume",
60
- session_set_config_option: "session/set_config_option",
61
- session_set_mode: "session/set_mode",
62
- session_set_model: "session/set_model"
63
- };
64
- CLIENT_METHODS = {
65
- fs_read_text_file: "fs/read_text_file",
66
- fs_write_text_file: "fs/write_text_file",
67
- session_request_permission: "session/request_permission",
68
- session_update: "session/update",
69
- terminal_create: "terminal/create",
70
- terminal_kill: "terminal/kill",
71
- terminal_output: "terminal/output",
72
- terminal_release: "terminal/release",
73
- terminal_wait_for_exit: "terminal/wait_for_exit"
74
- };
75
- PROTOCOL_VERSION = 1;
76
- }
77
- });
78
-
79
- // ../../node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js
80
- import { z } from "zod/v4";
81
- var zAuthMethod, zAuthenticateRequest, zAuthenticateResponse, zBlobResourceContents, zCost, zCreateTerminalResponse, zDiff, zEnvVariable, zErrorCode, zError, zExtNotification, zExtRequest, zExtResponse, zFileSystemCapability, zClientCapabilities, zHttpHeader, zImplementation, zKillTerminalCommandResponse, zListSessionsRequest, zMcpCapabilities, zMcpServerHttp, zMcpServerSse, zMcpServerStdio, zMcpServer, zModelId, zModelInfo, zNewSessionRequest, zPermissionOptionId, zPermissionOptionKind, zPermissionOption, zPlanEntryPriority, zPlanEntryStatus, zPlanEntry, zPlan, zPromptCapabilities, zProtocolVersion, zInitializeRequest, zReadTextFileResponse, zReleaseTerminalResponse, zRequestId, zCancelRequestNotification, zRole, zAnnotations, zAudioContent, zImageContent, zResourceLink, zSelectedPermissionOutcome, zRequestPermissionOutcome, zRequestPermissionResponse, zSessionConfigGroupId, zSessionConfigId, zSessionConfigOptionCategory, zSessionConfigValueId, zSessionConfigSelectOption, zSessionConfigSelectGroup, zSessionConfigSelectOptions, zSessionConfigSelect, zSessionConfigOption, zConfigOptionUpdate, zSessionForkCapabilities, zSessionId, zCancelNotification, zClientNotification, zCreateTerminalRequest, zForkSessionRequest, zKillTerminalCommandRequest, zLoadSessionRequest, zReadTextFileRequest, zReleaseTerminalRequest, zResumeSessionRequest, zSessionInfo, zListSessionsResponse, zSessionInfoUpdate, zSessionListCapabilities, zSessionModeId, zCurrentModeUpdate, zSessionMode, zSessionModeState, zSessionModelState, zForkSessionResponse, zLoadSessionResponse, zNewSessionResponse, zResumeSessionResponse, zSessionResumeCapabilities, zSessionCapabilities, zAgentCapabilities, zInitializeResponse, zSetSessionConfigOptionRequest, zSetSessionConfigOptionResponse, zSetSessionModeRequest, zSetSessionModeResponse, zSetSessionModelRequest, zSetSessionModelResponse, zStopReason, zTerminal, zTerminalExitStatus, zTerminalOutputRequest, zTerminalOutputResponse, zTextContent, zTextResourceContents, zEmbeddedResourceResource, zEmbeddedResource, zContentBlock, zContent, zContentChunk, zPromptRequest, zClientRequest, zToolCallContent, zToolCallId, zToolCallLocation, zToolCallStatus, zToolKind, zToolCall, zToolCallUpdate, zRequestPermissionRequest, zUnstructuredCommandInput, zAvailableCommandInput, zAvailableCommand, zAvailableCommandsUpdate, zUsage, zPromptResponse, zAgentResponse, zUsageUpdate, zSessionUpdate, zSessionNotification, zAgentNotification, zWaitForTerminalExitRequest, zWaitForTerminalExitResponse, zWriteTextFileRequest, zAgentRequest, zWriteTextFileResponse, zClientResponse;
82
- var init_zod_gen = __esm({
83
- "../../node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js"() {
84
- "use strict";
85
- zAuthMethod = z.object({
86
- _meta: z.union([
87
- z.record(z.string(), z.unknown()),
88
- z.null()
89
- ]).optional(),
90
- description: z.union([
91
- z.string(),
92
- z.null()
93
- ]).optional(),
94
- id: z.string(),
95
- name: z.string()
96
- });
97
- zAuthenticateRequest = z.object({
98
- _meta: z.union([
99
- z.record(z.string(), z.unknown()),
100
- z.null()
101
- ]).optional(),
102
- methodId: z.string()
103
- });
104
- zAuthenticateResponse = z.object({
105
- _meta: z.union([
106
- z.record(z.string(), z.unknown()),
107
- z.null()
108
- ]).optional()
109
- });
110
- zBlobResourceContents = z.object({
111
- _meta: z.union([
112
- z.record(z.string(), z.unknown()),
113
- z.null()
114
- ]).optional(),
115
- blob: z.string(),
116
- mimeType: z.union([
117
- z.string(),
118
- z.null()
119
- ]).optional(),
120
- uri: z.string()
121
- });
122
- zCost = z.object({
123
- amount: z.number(),
124
- currency: z.string()
125
- });
126
- zCreateTerminalResponse = z.object({
127
- _meta: z.union([
128
- z.record(z.string(), z.unknown()),
129
- z.null()
130
- ]).optional(),
131
- terminalId: z.string()
132
- });
133
- zDiff = z.object({
134
- _meta: z.union([
135
- z.record(z.string(), z.unknown()),
136
- z.null()
137
- ]).optional(),
138
- newText: z.string(),
139
- oldText: z.union([
140
- z.string(),
141
- z.null()
142
- ]).optional(),
143
- path: z.string()
144
- });
145
- zEnvVariable = z.object({
146
- _meta: z.union([
147
- z.record(z.string(), z.unknown()),
148
- z.null()
149
- ]).optional(),
150
- name: z.string(),
151
- value: z.string()
152
- });
153
- zErrorCode = z.union([
154
- z.literal(-32700),
155
- z.literal(-32600),
156
- z.literal(-32601),
157
- z.literal(-32602),
158
- z.literal(-32603),
159
- z.literal(-32800),
160
- z.literal(-32e3),
161
- z.literal(-32002),
162
- z.number().int().min(-2147483648, {
163
- message: "Invalid value: Expected int32 to be >= -2147483648"
164
- }).max(2147483647, {
165
- message: "Invalid value: Expected int32 to be <= 2147483647"
166
- })
167
- ]);
168
- zError = z.object({
169
- code: zErrorCode,
170
- data: z.unknown().optional(),
171
- message: z.string()
172
- });
173
- zExtNotification = z.unknown();
174
- zExtRequest = z.unknown();
175
- zExtResponse = z.unknown();
176
- zFileSystemCapability = z.object({
177
- _meta: z.union([
178
- z.record(z.string(), z.unknown()),
179
- z.null()
180
- ]).optional(),
181
- readTextFile: z.boolean().optional().default(false),
182
- writeTextFile: z.boolean().optional().default(false)
183
- });
184
- zClientCapabilities = z.object({
185
- _meta: z.union([
186
- z.record(z.string(), z.unknown()),
187
- z.null()
188
- ]).optional(),
189
- fs: zFileSystemCapability.optional().default({
190
- readTextFile: false,
191
- writeTextFile: false
192
- }),
193
- terminal: z.boolean().optional().default(false)
194
- });
195
- zHttpHeader = z.object({
196
- _meta: z.union([
197
- z.record(z.string(), z.unknown()),
198
- z.null()
199
- ]).optional(),
200
- name: z.string(),
201
- value: z.string()
202
- });
203
- zImplementation = z.object({
204
- _meta: z.union([
205
- z.record(z.string(), z.unknown()),
206
- z.null()
207
- ]).optional(),
208
- name: z.string(),
209
- title: z.union([
210
- z.string(),
211
- z.null()
212
- ]).optional(),
213
- version: z.string()
214
- });
215
- zKillTerminalCommandResponse = z.object({
216
- _meta: z.union([
217
- z.record(z.string(), z.unknown()),
218
- z.null()
219
- ]).optional()
220
- });
221
- zListSessionsRequest = z.object({
222
- _meta: z.union([
223
- z.record(z.string(), z.unknown()),
224
- z.null()
225
- ]).optional(),
226
- cursor: z.union([
227
- z.string(),
228
- z.null()
229
- ]).optional(),
230
- cwd: z.union([
231
- z.string(),
232
- z.null()
233
- ]).optional()
234
- });
235
- zMcpCapabilities = z.object({
236
- _meta: z.union([
237
- z.record(z.string(), z.unknown()),
238
- z.null()
239
- ]).optional(),
240
- http: z.boolean().optional().default(false),
241
- sse: z.boolean().optional().default(false)
242
- });
243
- zMcpServerHttp = z.object({
244
- _meta: z.union([
245
- z.record(z.string(), z.unknown()),
246
- z.null()
247
- ]).optional(),
248
- headers: z.array(zHttpHeader),
249
- name: z.string(),
250
- url: z.string()
251
- });
252
- zMcpServerSse = z.object({
253
- _meta: z.union([
254
- z.record(z.string(), z.unknown()),
255
- z.null()
256
- ]).optional(),
257
- headers: z.array(zHttpHeader),
258
- name: z.string(),
259
- url: z.string()
260
- });
261
- zMcpServerStdio = z.object({
262
- _meta: z.union([
263
- z.record(z.string(), z.unknown()),
264
- z.null()
265
- ]).optional(),
266
- args: z.array(z.string()),
267
- command: z.string(),
268
- env: z.array(zEnvVariable),
269
- name: z.string()
270
- });
271
- zMcpServer = z.union([
272
- zMcpServerHttp.and(z.object({
273
- type: z.literal("http")
274
- })),
275
- zMcpServerSse.and(z.object({
276
- type: z.literal("sse")
277
- })),
278
- zMcpServerStdio
279
- ]);
280
- zModelId = z.string();
281
- zModelInfo = z.object({
282
- _meta: z.union([
283
- z.record(z.string(), z.unknown()),
284
- z.null()
285
- ]).optional(),
286
- description: z.union([
287
- z.string(),
288
- z.null()
289
- ]).optional(),
290
- modelId: zModelId,
291
- name: z.string()
292
- });
293
- zNewSessionRequest = z.object({
294
- _meta: z.union([
295
- z.record(z.string(), z.unknown()),
296
- z.null()
297
- ]).optional(),
298
- cwd: z.string(),
299
- mcpServers: z.array(zMcpServer)
300
- });
301
- zPermissionOptionId = z.string();
302
- zPermissionOptionKind = z.union([
303
- z.literal("allow_once"),
304
- z.literal("allow_always"),
305
- z.literal("reject_once"),
306
- z.literal("reject_always")
307
- ]);
308
- zPermissionOption = z.object({
309
- _meta: z.union([
310
- z.record(z.string(), z.unknown()),
311
- z.null()
312
- ]).optional(),
313
- kind: zPermissionOptionKind,
314
- name: z.string(),
315
- optionId: zPermissionOptionId
316
- });
317
- zPlanEntryPriority = z.union([
318
- z.literal("high"),
319
- z.literal("medium"),
320
- z.literal("low")
321
- ]);
322
- zPlanEntryStatus = z.union([
323
- z.literal("pending"),
324
- z.literal("in_progress"),
325
- z.literal("completed")
326
- ]);
327
- zPlanEntry = z.object({
328
- _meta: z.union([
329
- z.record(z.string(), z.unknown()),
330
- z.null()
331
- ]).optional(),
332
- content: z.string(),
333
- priority: zPlanEntryPriority,
334
- status: zPlanEntryStatus
335
- });
336
- zPlan = z.object({
337
- _meta: z.union([
338
- z.record(z.string(), z.unknown()),
339
- z.null()
340
- ]).optional(),
341
- entries: z.array(zPlanEntry)
342
- });
343
- zPromptCapabilities = z.object({
344
- _meta: z.union([
345
- z.record(z.string(), z.unknown()),
346
- z.null()
347
- ]).optional(),
348
- audio: z.boolean().optional().default(false),
349
- embeddedContext: z.boolean().optional().default(false),
350
- image: z.boolean().optional().default(false)
351
- });
352
- zProtocolVersion = z.number().int().gte(0).lte(65535);
353
- zInitializeRequest = z.object({
354
- _meta: z.union([
355
- z.record(z.string(), z.unknown()),
356
- z.null()
357
- ]).optional(),
358
- clientCapabilities: zClientCapabilities.optional().default({
359
- fs: {
360
- readTextFile: false,
361
- writeTextFile: false
362
- },
363
- terminal: false
364
- }),
365
- clientInfo: z.union([
366
- zImplementation,
367
- z.null()
368
- ]).optional(),
369
- protocolVersion: zProtocolVersion
370
- });
371
- zReadTextFileResponse = z.object({
372
- _meta: z.union([
373
- z.record(z.string(), z.unknown()),
374
- z.null()
375
- ]).optional(),
376
- content: z.string()
377
- });
378
- zReleaseTerminalResponse = z.object({
379
- _meta: z.union([
380
- z.record(z.string(), z.unknown()),
381
- z.null()
382
- ]).optional()
383
- });
384
- zRequestId = z.union([
385
- z.null(),
386
- z.number(),
387
- z.string()
388
- ]);
389
- zCancelRequestNotification = z.object({
390
- _meta: z.union([
391
- z.record(z.string(), z.unknown()),
392
- z.null()
393
- ]).optional(),
394
- requestId: zRequestId
395
- });
396
- zRole = z.enum([
397
- "assistant",
398
- "user"
399
- ]);
400
- zAnnotations = z.object({
401
- _meta: z.union([
402
- z.record(z.string(), z.unknown()),
403
- z.null()
404
- ]).optional(),
405
- audience: z.union([
406
- z.array(zRole),
407
- z.null()
408
- ]).optional(),
409
- lastModified: z.union([
410
- z.string(),
411
- z.null()
412
- ]).optional(),
413
- priority: z.union([
414
- z.number(),
415
- z.null()
416
- ]).optional()
417
- });
418
- zAudioContent = z.object({
419
- _meta: z.union([
420
- z.record(z.string(), z.unknown()),
421
- z.null()
422
- ]).optional(),
423
- annotations: z.union([
424
- zAnnotations,
425
- z.null()
426
- ]).optional(),
427
- data: z.string(),
428
- mimeType: z.string()
429
- });
430
- zImageContent = z.object({
431
- _meta: z.union([
432
- z.record(z.string(), z.unknown()),
433
- z.null()
434
- ]).optional(),
435
- annotations: z.union([
436
- zAnnotations,
437
- z.null()
438
- ]).optional(),
439
- data: z.string(),
440
- mimeType: z.string(),
441
- uri: z.union([
442
- z.string(),
443
- z.null()
444
- ]).optional()
445
- });
446
- zResourceLink = z.object({
447
- _meta: z.union([
448
- z.record(z.string(), z.unknown()),
449
- z.null()
450
- ]).optional(),
451
- annotations: z.union([
452
- zAnnotations,
453
- z.null()
454
- ]).optional(),
455
- description: z.union([
456
- z.string(),
457
- z.null()
458
- ]).optional(),
459
- mimeType: z.union([
460
- z.string(),
461
- z.null()
462
- ]).optional(),
463
- name: z.string(),
464
- size: z.union([
465
- z.number(),
466
- z.null()
467
- ]).optional(),
468
- title: z.union([
469
- z.string(),
470
- z.null()
471
- ]).optional(),
472
- uri: z.string()
473
- });
474
- zSelectedPermissionOutcome = z.object({
475
- _meta: z.union([
476
- z.record(z.string(), z.unknown()),
477
- z.null()
478
- ]).optional(),
479
- optionId: zPermissionOptionId
480
- });
481
- zRequestPermissionOutcome = z.union([
482
- z.object({
483
- outcome: z.literal("cancelled")
484
- }),
485
- zSelectedPermissionOutcome.and(z.object({
486
- outcome: z.literal("selected")
487
- }))
488
- ]);
489
- zRequestPermissionResponse = z.object({
490
- _meta: z.union([
491
- z.record(z.string(), z.unknown()),
492
- z.null()
493
- ]).optional(),
494
- outcome: zRequestPermissionOutcome
495
- });
496
- zSessionConfigGroupId = z.string();
497
- zSessionConfigId = z.string();
498
- zSessionConfigOptionCategory = z.union([
499
- z.literal("mode"),
500
- z.literal("model"),
501
- z.literal("thought_level"),
502
- z.string()
503
- ]);
504
- zSessionConfigValueId = z.string();
505
- zSessionConfigSelectOption = z.object({
506
- _meta: z.union([
507
- z.record(z.string(), z.unknown()),
508
- z.null()
509
- ]).optional(),
510
- description: z.union([
511
- z.string(),
512
- z.null()
513
- ]).optional(),
514
- name: z.string(),
515
- value: zSessionConfigValueId
516
- });
517
- zSessionConfigSelectGroup = z.object({
518
- _meta: z.union([
519
- z.record(z.string(), z.unknown()),
520
- z.null()
521
- ]).optional(),
522
- group: zSessionConfigGroupId,
523
- name: z.string(),
524
- options: z.array(zSessionConfigSelectOption)
525
- });
526
- zSessionConfigSelectOptions = z.union([
527
- z.array(zSessionConfigSelectOption),
528
- z.array(zSessionConfigSelectGroup)
529
- ]);
530
- zSessionConfigSelect = z.object({
531
- currentValue: zSessionConfigValueId,
532
- options: zSessionConfigSelectOptions
533
- });
534
- zSessionConfigOption = zSessionConfigSelect.and(z.object({
535
- type: z.literal("select")
536
- })).and(z.object({
537
- _meta: z.union([
538
- z.record(z.string(), z.unknown()),
539
- z.null()
540
- ]).optional(),
541
- category: z.union([
542
- zSessionConfigOptionCategory,
543
- z.null()
544
- ]).optional(),
545
- description: z.union([
546
- z.string(),
547
- z.null()
548
- ]).optional(),
549
- id: zSessionConfigId,
550
- name: z.string()
551
- }));
552
- zConfigOptionUpdate = z.object({
553
- _meta: z.union([
554
- z.record(z.string(), z.unknown()),
555
- z.null()
556
- ]).optional(),
557
- configOptions: z.array(zSessionConfigOption)
558
- });
559
- zSessionForkCapabilities = z.object({
560
- _meta: z.union([
561
- z.record(z.string(), z.unknown()),
562
- z.null()
563
- ]).optional()
564
- });
565
- zSessionId = z.string();
566
- zCancelNotification = z.object({
567
- _meta: z.union([
568
- z.record(z.string(), z.unknown()),
569
- z.null()
570
- ]).optional(),
571
- sessionId: zSessionId
572
- });
573
- zClientNotification = z.object({
574
- method: z.string(),
575
- params: z.union([
576
- z.union([
577
- zCancelNotification,
578
- zExtNotification
579
- ]),
580
- z.null()
581
- ]).optional()
582
- });
583
- zCreateTerminalRequest = z.object({
584
- _meta: z.union([
585
- z.record(z.string(), z.unknown()),
586
- z.null()
587
- ]).optional(),
588
- args: z.array(z.string()).optional(),
589
- command: z.string(),
590
- cwd: z.union([
591
- z.string(),
592
- z.null()
593
- ]).optional(),
594
- env: z.array(zEnvVariable).optional(),
595
- outputByteLimit: z.union([
596
- z.number(),
597
- z.null()
598
- ]).optional(),
599
- sessionId: zSessionId
600
- });
601
- zForkSessionRequest = z.object({
602
- _meta: z.union([
603
- z.record(z.string(), z.unknown()),
604
- z.null()
605
- ]).optional(),
606
- cwd: z.string(),
607
- mcpServers: z.array(zMcpServer).optional(),
608
- sessionId: zSessionId
609
- });
610
- zKillTerminalCommandRequest = z.object({
611
- _meta: z.union([
612
- z.record(z.string(), z.unknown()),
613
- z.null()
614
- ]).optional(),
615
- sessionId: zSessionId,
616
- terminalId: z.string()
617
- });
618
- zLoadSessionRequest = z.object({
619
- _meta: z.union([
620
- z.record(z.string(), z.unknown()),
621
- z.null()
622
- ]).optional(),
623
- cwd: z.string(),
624
- mcpServers: z.array(zMcpServer),
625
- sessionId: zSessionId
626
- });
627
- zReadTextFileRequest = z.object({
628
- _meta: z.union([
629
- z.record(z.string(), z.unknown()),
630
- z.null()
631
- ]).optional(),
632
- limit: z.union([
633
- z.number().int().gte(0).max(4294967295, {
634
- message: "Invalid value: Expected uint32 to be <= 4294967295"
635
- }),
636
- z.null()
637
- ]).optional(),
638
- line: z.union([
639
- z.number().int().gte(0).max(4294967295, {
640
- message: "Invalid value: Expected uint32 to be <= 4294967295"
641
- }),
642
- z.null()
643
- ]).optional(),
644
- path: z.string(),
645
- sessionId: zSessionId
646
- });
647
- zReleaseTerminalRequest = z.object({
648
- _meta: z.union([
649
- z.record(z.string(), z.unknown()),
650
- z.null()
651
- ]).optional(),
652
- sessionId: zSessionId,
653
- terminalId: z.string()
654
- });
655
- zResumeSessionRequest = z.object({
656
- _meta: z.union([
657
- z.record(z.string(), z.unknown()),
658
- z.null()
659
- ]).optional(),
660
- cwd: z.string(),
661
- mcpServers: z.array(zMcpServer).optional(),
662
- sessionId: zSessionId
663
- });
664
- zSessionInfo = z.object({
665
- _meta: z.union([
666
- z.record(z.string(), z.unknown()),
667
- z.null()
668
- ]).optional(),
669
- cwd: z.string(),
670
- sessionId: zSessionId,
671
- title: z.union([
672
- z.string(),
673
- z.null()
674
- ]).optional(),
675
- updatedAt: z.union([
676
- z.string(),
677
- z.null()
678
- ]).optional()
679
- });
680
- zListSessionsResponse = z.object({
681
- _meta: z.union([
682
- z.record(z.string(), z.unknown()),
683
- z.null()
684
- ]).optional(),
685
- nextCursor: z.union([
686
- z.string(),
687
- z.null()
688
- ]).optional(),
689
- sessions: z.array(zSessionInfo)
690
- });
691
- zSessionInfoUpdate = z.object({
692
- _meta: z.union([
693
- z.record(z.string(), z.unknown()),
694
- z.null()
695
- ]).optional(),
696
- title: z.union([
697
- z.string(),
698
- z.null()
699
- ]).optional(),
700
- updatedAt: z.union([
701
- z.string(),
702
- z.null()
703
- ]).optional()
704
- });
705
- zSessionListCapabilities = z.object({
706
- _meta: z.union([
707
- z.record(z.string(), z.unknown()),
708
- z.null()
709
- ]).optional()
710
- });
711
- zSessionModeId = z.string();
712
- zCurrentModeUpdate = z.object({
713
- _meta: z.union([
714
- z.record(z.string(), z.unknown()),
715
- z.null()
716
- ]).optional(),
717
- currentModeId: zSessionModeId
718
- });
719
- zSessionMode = z.object({
720
- _meta: z.union([
721
- z.record(z.string(), z.unknown()),
722
- z.null()
723
- ]).optional(),
724
- description: z.union([
725
- z.string(),
726
- z.null()
727
- ]).optional(),
728
- id: zSessionModeId,
729
- name: z.string()
730
- });
731
- zSessionModeState = z.object({
732
- _meta: z.union([
733
- z.record(z.string(), z.unknown()),
734
- z.null()
735
- ]).optional(),
736
- availableModes: z.array(zSessionMode),
737
- currentModeId: zSessionModeId
738
- });
739
- zSessionModelState = z.object({
740
- _meta: z.union([
741
- z.record(z.string(), z.unknown()),
742
- z.null()
743
- ]).optional(),
744
- availableModels: z.array(zModelInfo),
745
- currentModelId: zModelId
746
- });
747
- zForkSessionResponse = z.object({
748
- _meta: z.union([
749
- z.record(z.string(), z.unknown()),
750
- z.null()
751
- ]).optional(),
752
- configOptions: z.union([
753
- z.array(zSessionConfigOption),
754
- z.null()
755
- ]).optional(),
756
- models: z.union([
757
- zSessionModelState,
758
- z.null()
759
- ]).optional(),
760
- modes: z.union([
761
- zSessionModeState,
762
- z.null()
763
- ]).optional(),
764
- sessionId: zSessionId
765
- });
766
- zLoadSessionResponse = z.object({
767
- _meta: z.union([
768
- z.record(z.string(), z.unknown()),
769
- z.null()
770
- ]).optional(),
771
- configOptions: z.union([
772
- z.array(zSessionConfigOption),
773
- z.null()
774
- ]).optional(),
775
- models: z.union([
776
- zSessionModelState,
777
- z.null()
778
- ]).optional(),
779
- modes: z.union([
780
- zSessionModeState,
781
- z.null()
782
- ]).optional()
783
- });
784
- zNewSessionResponse = z.object({
785
- _meta: z.union([
786
- z.record(z.string(), z.unknown()),
787
- z.null()
788
- ]).optional(),
789
- configOptions: z.union([
790
- z.array(zSessionConfigOption),
791
- z.null()
792
- ]).optional(),
793
- models: z.union([
794
- zSessionModelState,
795
- z.null()
796
- ]).optional(),
797
- modes: z.union([
798
- zSessionModeState,
799
- z.null()
800
- ]).optional(),
801
- sessionId: zSessionId
802
- });
803
- zResumeSessionResponse = z.object({
804
- _meta: z.union([
805
- z.record(z.string(), z.unknown()),
806
- z.null()
807
- ]).optional(),
808
- configOptions: z.union([
809
- z.array(zSessionConfigOption),
810
- z.null()
811
- ]).optional(),
812
- models: z.union([
813
- zSessionModelState,
814
- z.null()
815
- ]).optional(),
816
- modes: z.union([
817
- zSessionModeState,
818
- z.null()
819
- ]).optional()
820
- });
821
- zSessionResumeCapabilities = z.object({
822
- _meta: z.union([
823
- z.record(z.string(), z.unknown()),
824
- z.null()
825
- ]).optional()
826
- });
827
- zSessionCapabilities = z.object({
828
- _meta: z.union([
829
- z.record(z.string(), z.unknown()),
830
- z.null()
831
- ]).optional(),
832
- fork: z.union([
833
- zSessionForkCapabilities,
834
- z.null()
835
- ]).optional(),
836
- list: z.union([
837
- zSessionListCapabilities,
838
- z.null()
839
- ]).optional(),
840
- resume: z.union([
841
- zSessionResumeCapabilities,
842
- z.null()
843
- ]).optional()
844
- });
845
- zAgentCapabilities = z.object({
846
- _meta: z.union([
847
- z.record(z.string(), z.unknown()),
848
- z.null()
849
- ]).optional(),
850
- loadSession: z.boolean().optional().default(false),
851
- mcpCapabilities: zMcpCapabilities.optional().default({
852
- http: false,
853
- sse: false
854
- }),
855
- promptCapabilities: zPromptCapabilities.optional().default({
856
- audio: false,
857
- embeddedContext: false,
858
- image: false
859
- }),
860
- sessionCapabilities: zSessionCapabilities.optional().default({})
861
- });
862
- zInitializeResponse = z.object({
863
- _meta: z.union([
864
- z.record(z.string(), z.unknown()),
865
- z.null()
866
- ]).optional(),
867
- agentCapabilities: zAgentCapabilities.optional().default({
868
- loadSession: false,
869
- mcpCapabilities: {
870
- http: false,
871
- sse: false
872
- },
873
- promptCapabilities: {
874
- audio: false,
875
- embeddedContext: false,
876
- image: false
877
- },
878
- sessionCapabilities: {}
879
- }),
880
- agentInfo: z.union([
881
- zImplementation,
882
- z.null()
883
- ]).optional(),
884
- authMethods: z.array(zAuthMethod).optional().default([]),
885
- protocolVersion: zProtocolVersion
886
- });
887
- zSetSessionConfigOptionRequest = z.object({
888
- _meta: z.union([
889
- z.record(z.string(), z.unknown()),
890
- z.null()
891
- ]).optional(),
892
- configId: zSessionConfigId,
893
- sessionId: zSessionId,
894
- value: zSessionConfigValueId
895
- });
896
- zSetSessionConfigOptionResponse = z.object({
897
- _meta: z.union([
898
- z.record(z.string(), z.unknown()),
899
- z.null()
900
- ]).optional(),
901
- configOptions: z.array(zSessionConfigOption)
902
- });
903
- zSetSessionModeRequest = z.object({
904
- _meta: z.union([
905
- z.record(z.string(), z.unknown()),
906
- z.null()
907
- ]).optional(),
908
- modeId: zSessionModeId,
909
- sessionId: zSessionId
910
- });
911
- zSetSessionModeResponse = z.object({
912
- _meta: z.union([
913
- z.record(z.string(), z.unknown()),
914
- z.null()
915
- ]).optional()
916
- });
917
- zSetSessionModelRequest = z.object({
918
- _meta: z.union([
919
- z.record(z.string(), z.unknown()),
920
- z.null()
921
- ]).optional(),
922
- modelId: zModelId,
923
- sessionId: zSessionId
924
- });
925
- zSetSessionModelResponse = z.object({
926
- _meta: z.union([
927
- z.record(z.string(), z.unknown()),
928
- z.null()
929
- ]).optional()
930
- });
931
- zStopReason = z.union([
932
- z.literal("end_turn"),
933
- z.literal("max_tokens"),
934
- z.literal("max_turn_requests"),
935
- z.literal("refusal"),
936
- z.literal("cancelled")
937
- ]);
938
- zTerminal = z.object({
939
- _meta: z.union([
940
- z.record(z.string(), z.unknown()),
941
- z.null()
942
- ]).optional(),
943
- terminalId: z.string()
944
- });
945
- zTerminalExitStatus = z.object({
946
- _meta: z.union([
947
- z.record(z.string(), z.unknown()),
948
- z.null()
949
- ]).optional(),
950
- exitCode: z.union([
951
- z.number().int().gte(0).max(4294967295, {
952
- message: "Invalid value: Expected uint32 to be <= 4294967295"
953
- }),
954
- z.null()
955
- ]).optional(),
956
- signal: z.union([
957
- z.string(),
958
- z.null()
959
- ]).optional()
960
- });
961
- zTerminalOutputRequest = z.object({
962
- _meta: z.union([
963
- z.record(z.string(), z.unknown()),
964
- z.null()
965
- ]).optional(),
966
- sessionId: zSessionId,
967
- terminalId: z.string()
968
- });
969
- zTerminalOutputResponse = z.object({
970
- _meta: z.union([
971
- z.record(z.string(), z.unknown()),
972
- z.null()
973
- ]).optional(),
974
- exitStatus: z.union([
975
- zTerminalExitStatus,
976
- z.null()
977
- ]).optional(),
978
- output: z.string(),
979
- truncated: z.boolean()
980
- });
981
- zTextContent = z.object({
982
- _meta: z.union([
983
- z.record(z.string(), z.unknown()),
984
- z.null()
985
- ]).optional(),
986
- annotations: z.union([
987
- zAnnotations,
988
- z.null()
989
- ]).optional(),
990
- text: z.string()
991
- });
992
- zTextResourceContents = z.object({
993
- _meta: z.union([
994
- z.record(z.string(), z.unknown()),
995
- z.null()
996
- ]).optional(),
997
- mimeType: z.union([
998
- z.string(),
999
- z.null()
1000
- ]).optional(),
1001
- text: z.string(),
1002
- uri: z.string()
1003
- });
1004
- zEmbeddedResourceResource = z.union([
1005
- zTextResourceContents,
1006
- zBlobResourceContents
1007
- ]);
1008
- zEmbeddedResource = z.object({
1009
- _meta: z.union([
1010
- z.record(z.string(), z.unknown()),
1011
- z.null()
1012
- ]).optional(),
1013
- annotations: z.union([
1014
- zAnnotations,
1015
- z.null()
1016
- ]).optional(),
1017
- resource: zEmbeddedResourceResource
1018
- });
1019
- zContentBlock = z.union([
1020
- zTextContent.and(z.object({
1021
- type: z.literal("text")
1022
- })),
1023
- zImageContent.and(z.object({
1024
- type: z.literal("image")
1025
- })),
1026
- zAudioContent.and(z.object({
1027
- type: z.literal("audio")
1028
- })),
1029
- zResourceLink.and(z.object({
1030
- type: z.literal("resource_link")
1031
- })),
1032
- zEmbeddedResource.and(z.object({
1033
- type: z.literal("resource")
1034
- }))
1035
- ]);
1036
- zContent = z.object({
1037
- _meta: z.union([
1038
- z.record(z.string(), z.unknown()),
1039
- z.null()
1040
- ]).optional(),
1041
- content: zContentBlock
1042
- });
1043
- zContentChunk = z.object({
1044
- _meta: z.union([
1045
- z.record(z.string(), z.unknown()),
1046
- z.null()
1047
- ]).optional(),
1048
- content: zContentBlock
1049
- });
1050
- zPromptRequest = z.object({
1051
- _meta: z.union([
1052
- z.record(z.string(), z.unknown()),
1053
- z.null()
1054
- ]).optional(),
1055
- prompt: z.array(zContentBlock),
1056
- sessionId: zSessionId
1057
- });
1058
- zClientRequest = z.object({
1059
- id: zRequestId,
1060
- method: z.string(),
1061
- params: z.union([
1062
- z.union([
1063
- zInitializeRequest,
1064
- zAuthenticateRequest,
1065
- zNewSessionRequest,
1066
- zLoadSessionRequest,
1067
- zListSessionsRequest,
1068
- zForkSessionRequest,
1069
- zResumeSessionRequest,
1070
- zSetSessionModeRequest,
1071
- zSetSessionConfigOptionRequest,
1072
- zPromptRequest,
1073
- zSetSessionModelRequest,
1074
- zExtRequest
1075
- ]),
1076
- z.null()
1077
- ]).optional()
1078
- });
1079
- zToolCallContent = z.union([
1080
- zContent.and(z.object({
1081
- type: z.literal("content")
1082
- })),
1083
- zDiff.and(z.object({
1084
- type: z.literal("diff")
1085
- })),
1086
- zTerminal.and(z.object({
1087
- type: z.literal("terminal")
1088
- }))
1089
- ]);
1090
- zToolCallId = z.string();
1091
- zToolCallLocation = z.object({
1092
- _meta: z.union([
1093
- z.record(z.string(), z.unknown()),
1094
- z.null()
1095
- ]).optional(),
1096
- line: z.union([
1097
- z.number().int().gte(0).max(4294967295, {
1098
- message: "Invalid value: Expected uint32 to be <= 4294967295"
1099
- }),
1100
- z.null()
1101
- ]).optional(),
1102
- path: z.string()
1103
- });
1104
- zToolCallStatus = z.union([
1105
- z.literal("pending"),
1106
- z.literal("in_progress"),
1107
- z.literal("completed"),
1108
- z.literal("failed")
1109
- ]);
1110
- zToolKind = z.union([
1111
- z.literal("read"),
1112
- z.literal("edit"),
1113
- z.literal("delete"),
1114
- z.literal("move"),
1115
- z.literal("search"),
1116
- z.literal("execute"),
1117
- z.literal("think"),
1118
- z.literal("fetch"),
1119
- z.literal("switch_mode"),
1120
- z.literal("other")
1121
- ]);
1122
- zToolCall = z.object({
1123
- _meta: z.union([
1124
- z.record(z.string(), z.unknown()),
1125
- z.null()
1126
- ]).optional(),
1127
- content: z.array(zToolCallContent).optional(),
1128
- kind: zToolKind.optional(),
1129
- locations: z.array(zToolCallLocation).optional(),
1130
- rawInput: z.unknown().optional(),
1131
- rawOutput: z.unknown().optional(),
1132
- status: zToolCallStatus.optional(),
1133
- title: z.string(),
1134
- toolCallId: zToolCallId
1135
- });
1136
- zToolCallUpdate = z.object({
1137
- _meta: z.union([
1138
- z.record(z.string(), z.unknown()),
1139
- z.null()
1140
- ]).optional(),
1141
- content: z.union([
1142
- z.array(zToolCallContent),
1143
- z.null()
1144
- ]).optional(),
1145
- kind: z.union([
1146
- zToolKind,
1147
- z.null()
1148
- ]).optional(),
1149
- locations: z.union([
1150
- z.array(zToolCallLocation),
1151
- z.null()
1152
- ]).optional(),
1153
- rawInput: z.unknown().optional(),
1154
- rawOutput: z.unknown().optional(),
1155
- status: z.union([
1156
- zToolCallStatus,
1157
- z.null()
1158
- ]).optional(),
1159
- title: z.union([
1160
- z.string(),
1161
- z.null()
1162
- ]).optional(),
1163
- toolCallId: zToolCallId
1164
- });
1165
- zRequestPermissionRequest = z.object({
1166
- _meta: z.union([
1167
- z.record(z.string(), z.unknown()),
1168
- z.null()
1169
- ]).optional(),
1170
- options: z.array(zPermissionOption),
1171
- sessionId: zSessionId,
1172
- toolCall: zToolCallUpdate
1173
- });
1174
- zUnstructuredCommandInput = z.object({
1175
- _meta: z.union([
1176
- z.record(z.string(), z.unknown()),
1177
- z.null()
1178
- ]).optional(),
1179
- hint: z.string()
1180
- });
1181
- zAvailableCommandInput = zUnstructuredCommandInput;
1182
- zAvailableCommand = z.object({
1183
- _meta: z.union([
1184
- z.record(z.string(), z.unknown()),
1185
- z.null()
1186
- ]).optional(),
1187
- description: z.string(),
1188
- input: z.union([
1189
- zAvailableCommandInput,
1190
- z.null()
1191
- ]).optional(),
1192
- name: z.string()
1193
- });
1194
- zAvailableCommandsUpdate = z.object({
1195
- _meta: z.union([
1196
- z.record(z.string(), z.unknown()),
1197
- z.null()
1198
- ]).optional(),
1199
- availableCommands: z.array(zAvailableCommand)
1200
- });
1201
- zUsage = z.object({
1202
- cachedReadTokens: z.union([
1203
- z.number(),
1204
- z.null()
1205
- ]).optional(),
1206
- cachedWriteTokens: z.union([
1207
- z.number(),
1208
- z.null()
1209
- ]).optional(),
1210
- inputTokens: z.number(),
1211
- outputTokens: z.number(),
1212
- thoughtTokens: z.union([
1213
- z.number(),
1214
- z.null()
1215
- ]).optional(),
1216
- totalTokens: z.number()
1217
- });
1218
- zPromptResponse = z.object({
1219
- _meta: z.union([
1220
- z.record(z.string(), z.unknown()),
1221
- z.null()
1222
- ]).optional(),
1223
- stopReason: zStopReason,
1224
- usage: z.union([
1225
- zUsage,
1226
- z.null()
1227
- ]).optional()
1228
- });
1229
- zAgentResponse = z.union([
1230
- z.object({
1231
- id: zRequestId,
1232
- result: z.union([
1233
- zInitializeResponse,
1234
- zAuthenticateResponse,
1235
- zNewSessionResponse,
1236
- zLoadSessionResponse,
1237
- zListSessionsResponse,
1238
- zForkSessionResponse,
1239
- zResumeSessionResponse,
1240
- zSetSessionModeResponse,
1241
- zSetSessionConfigOptionResponse,
1242
- zPromptResponse,
1243
- zSetSessionModelResponse,
1244
- zExtResponse
1245
- ])
1246
- }),
1247
- z.object({
1248
- error: zError,
1249
- id: zRequestId
1250
- })
1251
- ]);
1252
- zUsageUpdate = z.object({
1253
- _meta: z.union([
1254
- z.record(z.string(), z.unknown()),
1255
- z.null()
1256
- ]).optional(),
1257
- cost: z.union([
1258
- zCost,
1259
- z.null()
1260
- ]).optional(),
1261
- size: z.number(),
1262
- used: z.number()
1263
- });
1264
- zSessionUpdate = z.union([
1265
- zContentChunk.and(z.object({
1266
- sessionUpdate: z.literal("user_message_chunk")
1267
- })),
1268
- zContentChunk.and(z.object({
1269
- sessionUpdate: z.literal("agent_message_chunk")
1270
- })),
1271
- zContentChunk.and(z.object({
1272
- sessionUpdate: z.literal("agent_thought_chunk")
1273
- })),
1274
- zToolCall.and(z.object({
1275
- sessionUpdate: z.literal("tool_call")
1276
- })),
1277
- zToolCallUpdate.and(z.object({
1278
- sessionUpdate: z.literal("tool_call_update")
1279
- })),
1280
- zPlan.and(z.object({
1281
- sessionUpdate: z.literal("plan")
1282
- })),
1283
- zAvailableCommandsUpdate.and(z.object({
1284
- sessionUpdate: z.literal("available_commands_update")
1285
- })),
1286
- zCurrentModeUpdate.and(z.object({
1287
- sessionUpdate: z.literal("current_mode_update")
1288
- })),
1289
- zConfigOptionUpdate.and(z.object({
1290
- sessionUpdate: z.literal("config_option_update")
1291
- })),
1292
- zSessionInfoUpdate.and(z.object({
1293
- sessionUpdate: z.literal("session_info_update")
1294
- })),
1295
- zUsageUpdate.and(z.object({
1296
- sessionUpdate: z.literal("usage_update")
1297
- }))
1298
- ]);
1299
- zSessionNotification = z.object({
1300
- _meta: z.union([
1301
- z.record(z.string(), z.unknown()),
1302
- z.null()
1303
- ]).optional(),
1304
- sessionId: zSessionId,
1305
- update: zSessionUpdate
1306
- });
1307
- zAgentNotification = z.object({
1308
- method: z.string(),
1309
- params: z.union([
1310
- z.union([
1311
- zSessionNotification,
1312
- zExtNotification
1313
- ]),
1314
- z.null()
1315
- ]).optional()
1316
- });
1317
- zWaitForTerminalExitRequest = z.object({
1318
- _meta: z.union([
1319
- z.record(z.string(), z.unknown()),
1320
- z.null()
1321
- ]).optional(),
1322
- sessionId: zSessionId,
1323
- terminalId: z.string()
1324
- });
1325
- zWaitForTerminalExitResponse = z.object({
1326
- _meta: z.union([
1327
- z.record(z.string(), z.unknown()),
1328
- z.null()
1329
- ]).optional(),
1330
- exitCode: z.union([
1331
- z.number().int().gte(0).max(4294967295, {
1332
- message: "Invalid value: Expected uint32 to be <= 4294967295"
1333
- }),
1334
- z.null()
1335
- ]).optional(),
1336
- signal: z.union([
1337
- z.string(),
1338
- z.null()
1339
- ]).optional()
1340
- });
1341
- zWriteTextFileRequest = z.object({
1342
- _meta: z.union([
1343
- z.record(z.string(), z.unknown()),
1344
- z.null()
1345
- ]).optional(),
1346
- content: z.string(),
1347
- path: z.string(),
1348
- sessionId: zSessionId
1349
- });
1350
- zAgentRequest = z.object({
1351
- id: zRequestId,
1352
- method: z.string(),
1353
- params: z.union([
1354
- z.union([
1355
- zWriteTextFileRequest,
1356
- zReadTextFileRequest,
1357
- zRequestPermissionRequest,
1358
- zCreateTerminalRequest,
1359
- zTerminalOutputRequest,
1360
- zReleaseTerminalRequest,
1361
- zWaitForTerminalExitRequest,
1362
- zKillTerminalCommandRequest,
1363
- zExtRequest
1364
- ]),
1365
- z.null()
1366
- ]).optional()
1367
- });
1368
- zWriteTextFileResponse = z.object({
1369
- _meta: z.union([
1370
- z.record(z.string(), z.unknown()),
1371
- z.null()
1372
- ]).optional()
1373
- });
1374
- zClientResponse = z.union([
1375
- z.object({
1376
- id: zRequestId,
1377
- result: z.union([
1378
- zWriteTextFileResponse,
1379
- zReadTextFileResponse,
1380
- zRequestPermissionResponse,
1381
- zCreateTerminalResponse,
1382
- zTerminalOutputResponse,
1383
- zReleaseTerminalResponse,
1384
- zWaitForTerminalExitResponse,
1385
- zKillTerminalCommandResponse,
1386
- zExtResponse
1387
- ])
1388
- }),
1389
- z.object({
1390
- error: zError,
1391
- id: zRequestId
1392
- })
1393
- ]);
1394
- }
1395
- });
1396
-
1397
- // ../../node_modules/@agentclientprotocol/sdk/dist/stream.js
1398
- function ndJsonStream(output, input) {
1399
- const textEncoder = new TextEncoder();
1400
- const textDecoder = new TextDecoder();
1401
- const readable = new ReadableStream({
1402
- async start(controller) {
1403
- let content = "";
1404
- const reader = input.getReader();
1405
- try {
1406
- while (true) {
1407
- const { value, done } = await reader.read();
1408
- if (done) {
1409
- break;
1410
- }
1411
- if (!value) {
1412
- continue;
1413
- }
1414
- content += textDecoder.decode(value, {
1415
- stream: true
1416
- });
1417
- const lines = content.split("\n");
1418
- content = lines.pop() || "";
1419
- for (const line of lines) {
1420
- const trimmedLine = line.trim();
1421
- if (trimmedLine) {
1422
- try {
1423
- const message = JSON.parse(trimmedLine);
1424
- controller.enqueue(message);
1425
- } catch (err) {
1426
- console.error("Failed to parse JSON message:", trimmedLine, err);
1427
- }
1428
- }
1429
- }
1430
- }
1431
- } finally {
1432
- reader.releaseLock();
1433
- controller.close();
1434
- }
1435
- }
1436
- });
1437
- const writable = new WritableStream({
1438
- async write(message) {
1439
- const content = JSON.stringify(message) + "\n";
1440
- const writer = output.getWriter();
1441
- try {
1442
- await writer.write(textEncoder.encode(content));
1443
- } finally {
1444
- writer.releaseLock();
1445
- }
1446
- }
1447
- });
1448
- return {
1449
- readable,
1450
- writable
1451
- };
1452
- }
1453
- var init_stream = __esm({
1454
- "../../node_modules/@agentclientprotocol/sdk/dist/stream.js"() {
1455
- "use strict";
1456
- __name(ndJsonStream, "ndJsonStream");
1457
- }
1458
- });
1459
-
1460
- // ../../node_modules/@agentclientprotocol/sdk/dist/acp.js
1461
- var acp_exports = {};
1462
- __export(acp_exports, {
1463
- AGENT_METHODS: () => AGENT_METHODS,
1464
- AgentSideConnection: () => AgentSideConnection,
1465
- CLIENT_METHODS: () => CLIENT_METHODS,
1466
- ClientSideConnection: () => ClientSideConnection,
1467
- PROTOCOL_VERSION: () => PROTOCOL_VERSION,
1468
- RequestError: () => RequestError,
1469
- TerminalHandle: () => TerminalHandle,
1470
- ndJsonStream: () => ndJsonStream
1471
- });
1472
- import { z as z2 } from "zod";
1473
- var AgentSideConnection, TerminalHandle, ClientSideConnection, Connection, RequestError;
1474
- var init_acp = __esm({
1475
- "../../node_modules/@agentclientprotocol/sdk/dist/acp.js"() {
1476
- init_schema();
1477
- init_zod_gen();
1478
- init_schema();
1479
- init_stream();
1480
- AgentSideConnection = class {
1481
- static {
1482
- __name(this, "AgentSideConnection");
1483
- }
1484
- #connection;
1485
- /**
1486
- * Creates a new agent-side connection to a client.
1487
- *
1488
- * This establishes the communication channel from the agent's perspective
1489
- * following the ACP specification.
1490
- *
1491
- * @param toAgent - A function that creates an Agent handler to process incoming client requests
1492
- * @param stream - The bidirectional message stream for communication. Typically created using
1493
- * {@link ndJsonStream} for stdio-based connections.
1494
- *
1495
- * See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
1496
- */
1497
- constructor(toAgent, stream) {
1498
- const agent = toAgent(this);
1499
- const requestHandler = /* @__PURE__ */ __name(async (method, params) => {
1500
- switch (method) {
1501
- case AGENT_METHODS.initialize: {
1502
- const validatedParams = zInitializeRequest.parse(params);
1503
- return agent.initialize(validatedParams);
1504
- }
1505
- case AGENT_METHODS.session_new: {
1506
- const validatedParams = zNewSessionRequest.parse(params);
1507
- return agent.newSession(validatedParams);
1508
- }
1509
- case AGENT_METHODS.session_load: {
1510
- if (!agent.loadSession) {
1511
- throw RequestError.methodNotFound(method);
1512
- }
1513
- const validatedParams = zLoadSessionRequest.parse(params);
1514
- return agent.loadSession(validatedParams);
1515
- }
1516
- case AGENT_METHODS.session_list: {
1517
- if (!agent.unstable_listSessions) {
1518
- throw RequestError.methodNotFound(method);
1519
- }
1520
- const validatedParams = zListSessionsRequest.parse(params);
1521
- return agent.unstable_listSessions(validatedParams);
1522
- }
1523
- case AGENT_METHODS.session_fork: {
1524
- if (!agent.unstable_forkSession) {
1525
- throw RequestError.methodNotFound(method);
1526
- }
1527
- const validatedParams = zForkSessionRequest.parse(params);
1528
- return agent.unstable_forkSession(validatedParams);
1529
- }
1530
- case AGENT_METHODS.session_resume: {
1531
- if (!agent.unstable_resumeSession) {
1532
- throw RequestError.methodNotFound(method);
1533
- }
1534
- const validatedParams = zResumeSessionRequest.parse(params);
1535
- return agent.unstable_resumeSession(validatedParams);
1536
- }
1537
- case AGENT_METHODS.session_set_mode: {
1538
- if (!agent.setSessionMode) {
1539
- throw RequestError.methodNotFound(method);
1540
- }
1541
- const validatedParams = zSetSessionModeRequest.parse(params);
1542
- const result = await agent.setSessionMode(validatedParams);
1543
- return result ?? {};
1544
- }
1545
- case AGENT_METHODS.authenticate: {
1546
- const validatedParams = zAuthenticateRequest.parse(params);
1547
- const result = await agent.authenticate(validatedParams);
1548
- return result ?? {};
1549
- }
1550
- case AGENT_METHODS.session_prompt: {
1551
- const validatedParams = zPromptRequest.parse(params);
1552
- return agent.prompt(validatedParams);
1553
- }
1554
- case AGENT_METHODS.session_set_model: {
1555
- if (!agent.unstable_setSessionModel) {
1556
- throw RequestError.methodNotFound(method);
1557
- }
1558
- const validatedParams = zSetSessionModelRequest.parse(params);
1559
- const result = await agent.unstable_setSessionModel(validatedParams);
1560
- return result ?? {};
1561
- }
1562
- case AGENT_METHODS.session_set_config_option: {
1563
- if (!agent.setSessionConfigOption) {
1564
- throw RequestError.methodNotFound(method);
1565
- }
1566
- const validatedParams = zSetSessionConfigOptionRequest.parse(params);
1567
- return agent.setSessionConfigOption(validatedParams);
1568
- }
1569
- default:
1570
- if (agent.extMethod) {
1571
- return agent.extMethod(method, params);
1572
- }
1573
- throw RequestError.methodNotFound(method);
1574
- }
1575
- }, "requestHandler");
1576
- const notificationHandler = /* @__PURE__ */ __name(async (method, params) => {
1577
- switch (method) {
1578
- case AGENT_METHODS.session_cancel: {
1579
- const validatedParams = zCancelNotification.parse(params);
1580
- return agent.cancel(validatedParams);
1581
- }
1582
- default:
1583
- if (agent.extNotification) {
1584
- return agent.extNotification(method, params);
1585
- }
1586
- throw RequestError.methodNotFound(method);
1587
- }
1588
- }, "notificationHandler");
1589
- this.#connection = new Connection(requestHandler, notificationHandler, stream);
1590
- }
1591
- /**
1592
- * Handles session update notifications from the agent.
1593
- *
1594
- * This is a notification endpoint (no response expected) that sends
1595
- * real-time updates about session progress, including message chunks,
1596
- * tool calls, and execution plans.
1597
- *
1598
- * Note: Clients SHOULD continue accepting tool call updates even after
1599
- * sending a `session/cancel` notification, as the agent may send final
1600
- * updates before responding with the cancelled stop reason.
1601
- *
1602
- * See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output)
1603
- */
1604
- async sessionUpdate(params) {
1605
- return await this.#connection.sendNotification(CLIENT_METHODS.session_update, params);
1606
- }
1607
- /**
1608
- * Requests permission from the user for a tool call operation.
1609
- *
1610
- * Called by the agent when it needs user authorization before executing
1611
- * a potentially sensitive operation. The client should present the options
1612
- * to the user and return their decision.
1613
- *
1614
- * If the client cancels the prompt turn via `session/cancel`, it MUST
1615
- * respond to this request with `RequestPermissionOutcome::Cancelled`.
1616
- *
1617
- * See protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission)
1618
- */
1619
- async requestPermission(params) {
1620
- return await this.#connection.sendRequest(CLIENT_METHODS.session_request_permission, params);
1621
- }
1622
- /**
1623
- * Reads content from a text file in the client's file system.
1624
- *
1625
- * Only available if the client advertises the `fs.readTextFile` capability.
1626
- * Allows the agent to access file contents within the client's environment.
1627
- *
1628
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
1629
- */
1630
- async readTextFile(params) {
1631
- return await this.#connection.sendRequest(CLIENT_METHODS.fs_read_text_file, params);
1632
- }
1633
- /**
1634
- * Writes content to a text file in the client's file system.
1635
- *
1636
- * Only available if the client advertises the `fs.writeTextFile` capability.
1637
- * Allows the agent to create or modify files within the client's environment.
1638
- *
1639
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
1640
- */
1641
- async writeTextFile(params) {
1642
- return await this.#connection.sendRequest(CLIENT_METHODS.fs_write_text_file, params) ?? {};
1643
- }
1644
- /**
1645
- * Executes a command in a new terminal.
1646
- *
1647
- * Returns a `TerminalHandle` that can be used to get output, wait for exit,
1648
- * kill the command, or release the terminal.
1649
- *
1650
- * The terminal can also be embedded in tool calls by using its ID in
1651
- * `ToolCallContent` with type "terminal".
1652
- *
1653
- * @param params - The terminal creation parameters
1654
- * @returns A handle to control and monitor the terminal
1655
- */
1656
- async createTerminal(params) {
1657
- const response = await this.#connection.sendRequest(CLIENT_METHODS.terminal_create, params);
1658
- return new TerminalHandle(response.terminalId, params.sessionId, this.#connection);
1659
- }
1660
- /**
1661
- * Extension method
1662
- *
1663
- * Allows the Agent to send an arbitrary request that is not part of the ACP spec.
1664
- */
1665
- async extMethod(method, params) {
1666
- return await this.#connection.sendRequest(method, params);
1667
- }
1668
- /**
1669
- * Extension notification
1670
- *
1671
- * Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
1672
- */
1673
- async extNotification(method, params) {
1674
- return await this.#connection.sendNotification(method, params);
1675
- }
1676
- /**
1677
- * AbortSignal that aborts when the connection closes.
1678
- *
1679
- * This signal can be used to:
1680
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
1681
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
1682
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
1683
- *
1684
- * The connection closes when the underlying stream ends, either normally or due to an error.
1685
- *
1686
- * @example
1687
- * ```typescript
1688
- * const connection = new AgentSideConnection(agent, stream);
1689
- *
1690
- * // Listen for closure
1691
- * connection.signal.addEventListener('abort', () => {
1692
- * console.log('Connection closed - performing cleanup');
1693
- * });
1694
- *
1695
- * // Check status
1696
- * if (connection.signal.aborted) {
1697
- * console.log('Connection is already closed');
1698
- * }
1699
- *
1700
- * // Pass to other APIs
1701
- * fetch(url, { signal: connection.signal });
1702
- * ```
1703
- */
1704
- get signal() {
1705
- return this.#connection.signal;
1706
- }
1707
- /**
1708
- * Promise that resolves when the connection closes.
1709
- *
1710
- * The connection closes when the underlying stream ends, either normally or due to an error.
1711
- * Once closed, the connection cannot send or receive any more messages.
1712
- *
1713
- * This is useful for async/await style cleanup:
1714
- *
1715
- * @example
1716
- * ```typescript
1717
- * const connection = new AgentSideConnection(agent, stream);
1718
- * await connection.closed;
1719
- * console.log('Connection closed - performing cleanup');
1720
- * ```
1721
- */
1722
- get closed() {
1723
- return this.#connection.closed;
1724
- }
1725
- };
1726
- TerminalHandle = class {
1727
- static {
1728
- __name(this, "TerminalHandle");
1729
- }
1730
- id;
1731
- #sessionId;
1732
- #connection;
1733
- constructor(id, sessionId, conn) {
1734
- this.id = id;
1735
- this.#sessionId = sessionId;
1736
- this.#connection = conn;
1737
- }
1738
- /**
1739
- * Gets the current terminal output without waiting for the command to exit.
1740
- */
1741
- async currentOutput() {
1742
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_output, {
1743
- sessionId: this.#sessionId,
1744
- terminalId: this.id
1745
- });
1746
- }
1747
- /**
1748
- * Waits for the terminal command to complete and returns its exit status.
1749
- */
1750
- async waitForExit() {
1751
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_wait_for_exit, {
1752
- sessionId: this.#sessionId,
1753
- terminalId: this.id
1754
- });
1755
- }
1756
- /**
1757
- * Kills the terminal command without releasing the terminal.
1758
- *
1759
- * The terminal remains valid after killing, allowing you to:
1760
- * - Get the final output with `currentOutput()`
1761
- * - Check the exit status
1762
- * - Release the terminal when done
1763
- *
1764
- * Useful for implementing timeouts or cancellation.
1765
- */
1766
- async kill() {
1767
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_kill, {
1768
- sessionId: this.#sessionId,
1769
- terminalId: this.id
1770
- }) ?? {};
1771
- }
1772
- /**
1773
- * Releases the terminal and frees all associated resources.
1774
- *
1775
- * If the command is still running, it will be killed.
1776
- * After release, the terminal ID becomes invalid and cannot be used
1777
- * with other terminal methods.
1778
- *
1779
- * Tool calls that already reference this terminal will continue to
1780
- * display its output.
1781
- *
1782
- * **Important:** Always call this method when done with the terminal.
1783
- */
1784
- async release() {
1785
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_release, {
1786
- sessionId: this.#sessionId,
1787
- terminalId: this.id
1788
- }) ?? {};
1789
- }
1790
- async [Symbol.asyncDispose]() {
1791
- await this.release();
1792
- }
1793
- };
1794
- ClientSideConnection = class {
1795
- static {
1796
- __name(this, "ClientSideConnection");
1797
- }
1798
- #connection;
1799
- /**
1800
- * Creates a new client-side connection to an agent.
1801
- *
1802
- * This establishes the communication channel between a client and agent
1803
- * following the ACP specification.
1804
- *
1805
- * @param toClient - A function that creates a Client handler to process incoming agent requests
1806
- * @param stream - The bidirectional message stream for communication. Typically created using
1807
- * {@link ndJsonStream} for stdio-based connections.
1808
- *
1809
- * See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
1810
- */
1811
- constructor(toClient, stream) {
1812
- const client = toClient(this);
1813
- const requestHandler = /* @__PURE__ */ __name(async (method, params) => {
1814
- switch (method) {
1815
- case CLIENT_METHODS.fs_write_text_file: {
1816
- const validatedParams = zWriteTextFileRequest.parse(params);
1817
- return client.writeTextFile?.(validatedParams);
1818
- }
1819
- case CLIENT_METHODS.fs_read_text_file: {
1820
- const validatedParams = zReadTextFileRequest.parse(params);
1821
- return client.readTextFile?.(validatedParams);
1822
- }
1823
- case CLIENT_METHODS.session_request_permission: {
1824
- const validatedParams = zRequestPermissionRequest.parse(params);
1825
- return client.requestPermission(validatedParams);
1826
- }
1827
- case CLIENT_METHODS.terminal_create: {
1828
- const validatedParams = zCreateTerminalRequest.parse(params);
1829
- return client.createTerminal?.(validatedParams);
1830
- }
1831
- case CLIENT_METHODS.terminal_output: {
1832
- const validatedParams = zTerminalOutputRequest.parse(params);
1833
- return client.terminalOutput?.(validatedParams);
1834
- }
1835
- case CLIENT_METHODS.terminal_release: {
1836
- const validatedParams = zReleaseTerminalRequest.parse(params);
1837
- const result = await client.releaseTerminal?.(validatedParams);
1838
- return result ?? {};
1839
- }
1840
- case CLIENT_METHODS.terminal_wait_for_exit: {
1841
- const validatedParams = zWaitForTerminalExitRequest.parse(params);
1842
- return client.waitForTerminalExit?.(validatedParams);
1843
- }
1844
- case CLIENT_METHODS.terminal_kill: {
1845
- const validatedParams = zKillTerminalCommandRequest.parse(params);
1846
- const result = await client.killTerminal?.(validatedParams);
1847
- return result ?? {};
1848
- }
1849
- default:
1850
- if (client.extMethod) {
1851
- return client.extMethod(method, params);
1852
- }
1853
- throw RequestError.methodNotFound(method);
1854
- }
1855
- }, "requestHandler");
1856
- const notificationHandler = /* @__PURE__ */ __name(async (method, params) => {
1857
- switch (method) {
1858
- case CLIENT_METHODS.session_update: {
1859
- const validatedParams = zSessionNotification.parse(params);
1860
- return client.sessionUpdate(validatedParams);
1861
- }
1862
- default:
1863
- if (client.extNotification) {
1864
- return client.extNotification(method, params);
1865
- }
1866
- throw RequestError.methodNotFound(method);
1867
- }
1868
- }, "notificationHandler");
1869
- this.#connection = new Connection(requestHandler, notificationHandler, stream);
1870
- }
1871
- /**
1872
- * Establishes the connection with a client and negotiates protocol capabilities.
1873
- *
1874
- * This method is called once at the beginning of the connection to:
1875
- * - Negotiate the protocol version to use
1876
- * - Exchange capability information between client and agent
1877
- * - Determine available authentication methods
1878
- *
1879
- * The agent should respond with its supported protocol version and capabilities.
1880
- *
1881
- * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
1882
- */
1883
- async initialize(params) {
1884
- return await this.#connection.sendRequest(AGENT_METHODS.initialize, params);
1885
- }
1886
- /**
1887
- * Creates a new conversation session with the agent.
1888
- *
1889
- * Sessions represent independent conversation contexts with their own history and state.
1890
- *
1891
- * The agent should:
1892
- * - Create a new session context
1893
- * - Connect to any specified MCP servers
1894
- * - Return a unique session ID for future requests
1895
- *
1896
- * May return an `auth_required` error if the agent requires authentication.
1897
- *
1898
- * See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
1899
- */
1900
- async newSession(params) {
1901
- return await this.#connection.sendRequest(AGENT_METHODS.session_new, params);
1902
- }
1903
- /**
1904
- * Loads an existing session to resume a previous conversation.
1905
- *
1906
- * This method is only available if the agent advertises the `loadSession` capability.
1907
- *
1908
- * The agent should:
1909
- * - Restore the session context and conversation history
1910
- * - Connect to the specified MCP servers
1911
- * - Stream the entire conversation history back to the client via notifications
1912
- *
1913
- * See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
1914
- */
1915
- async loadSession(params) {
1916
- return await this.#connection.sendRequest(AGENT_METHODS.session_load, params) ?? {};
1917
- }
1918
- /**
1919
- * **UNSTABLE**
1920
- *
1921
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1922
- *
1923
- * Forks an existing session to create a new independent session.
1924
- *
1925
- * Creates a new session based on the context of an existing one, allowing
1926
- * operations like generating summaries without affecting the original session's history.
1927
- *
1928
- * This method is only available if the agent advertises the `session.fork` capability.
1929
- *
1930
- * @experimental
1931
- */
1932
- async unstable_forkSession(params) {
1933
- return await this.#connection.sendRequest(AGENT_METHODS.session_fork, params);
1934
- }
1935
- /**
1936
- * **UNSTABLE**
1937
- *
1938
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1939
- *
1940
- * Lists existing sessions from the agent.
1941
- *
1942
- * This method is only available if the agent advertises the `listSessions` capability.
1943
- *
1944
- * Returns a list of sessions with metadata like session ID, working directory,
1945
- * title, and last update time. Supports filtering by working directory and
1946
- * cursor-based pagination.
1947
- *
1948
- * @experimental
1949
- */
1950
- async unstable_listSessions(params) {
1951
- return await this.#connection.sendRequest(AGENT_METHODS.session_list, params);
1952
- }
1953
- /**
1954
- * **UNSTABLE**
1955
- *
1956
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1957
- *
1958
- * Resumes an existing session without returning previous messages.
1959
- *
1960
- * This method is only available if the agent advertises the `session.resume` capability.
1961
- *
1962
- * The agent should resume the session context, allowing the conversation to continue
1963
- * without replaying the message history (unlike `session/load`).
1964
- *
1965
- * @experimental
1966
- */
1967
- async unstable_resumeSession(params) {
1968
- return await this.#connection.sendRequest(AGENT_METHODS.session_resume, params);
1969
- }
1970
- /**
1971
- * Sets the operational mode for a session.
1972
- *
1973
- * Allows switching between different agent modes (e.g., "ask", "architect", "code")
1974
- * that affect system prompts, tool availability, and permission behaviors.
1975
- *
1976
- * The mode must be one of the modes advertised in `availableModes` during session
1977
- * creation or loading. Agents may also change modes autonomously and notify the
1978
- * client via `current_mode_update` notifications.
1979
- *
1980
- * This method can be called at any time during a session, whether the Agent is
1981
- * idle or actively generating a turn.
1982
- *
1983
- * See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
1984
- */
1985
- async setSessionMode(params) {
1986
- return await this.#connection.sendRequest(AGENT_METHODS.session_set_mode, params) ?? {};
1987
- }
1988
- /**
1989
- * **UNSTABLE**
1990
- *
1991
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1992
- *
1993
- * Select a model for a given session.
1994
- *
1995
- * @experimental
1996
- */
1997
- async unstable_setSessionModel(params) {
1998
- return await this.#connection.sendRequest(AGENT_METHODS.session_set_model, params) ?? {};
1999
- }
2000
- /**
2001
- * Set a configuration option for a given session.
2002
- *
2003
- * The response contains the full set of configuration options and their current values,
2004
- * as changing one option may affect the available values or state of other options.
2005
- */
2006
- async setSessionConfigOption(params) {
2007
- return await this.#connection.sendRequest(AGENT_METHODS.session_set_config_option, params);
2008
- }
2009
- /**
2010
- * Authenticates the client using the specified authentication method.
2011
- *
2012
- * Called when the agent requires authentication before allowing session creation.
2013
- * The client provides the authentication method ID that was advertised during initialization.
2014
- *
2015
- * After successful authentication, the client can proceed to create sessions with
2016
- * `newSession` without receiving an `auth_required` error.
2017
- *
2018
- * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
2019
- */
2020
- async authenticate(params) {
2021
- return await this.#connection.sendRequest(AGENT_METHODS.authenticate, params) ?? {};
2022
- }
2023
- /**
2024
- * Processes a user prompt within a session.
2025
- *
2026
- * This method handles the whole lifecycle of a prompt:
2027
- * - Receives user messages with optional context (files, images, etc.)
2028
- * - Processes the prompt using language models
2029
- * - Reports language model content and tool calls to the Clients
2030
- * - Requests permission to run tools
2031
- * - Executes any requested tool calls
2032
- * - Returns when the turn is complete with a stop reason
2033
- *
2034
- * See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
2035
- */
2036
- async prompt(params) {
2037
- return await this.#connection.sendRequest(AGENT_METHODS.session_prompt, params);
2038
- }
2039
- /**
2040
- * Cancels ongoing operations for a session.
2041
- *
2042
- * This is a notification sent by the client to cancel an ongoing prompt turn.
2043
- *
2044
- * Upon receiving this notification, the Agent SHOULD:
2045
- * - Stop all language model requests as soon as possible
2046
- * - Abort all tool call invocations in progress
2047
- * - Send any pending `session/update` notifications
2048
- * - Respond to the original `session/prompt` request with `StopReason::Cancelled`
2049
- *
2050
- * See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
2051
- */
2052
- async cancel(params) {
2053
- return await this.#connection.sendNotification(AGENT_METHODS.session_cancel, params);
2054
- }
2055
- /**
2056
- * Extension method
2057
- *
2058
- * Allows the Client to send an arbitrary request that is not part of the ACP spec.
2059
- */
2060
- async extMethod(method, params) {
2061
- return await this.#connection.sendRequest(method, params);
2062
- }
2063
- /**
2064
- * Extension notification
2065
- *
2066
- * Allows the Client to send an arbitrary notification that is not part of the ACP spec.
2067
- */
2068
- async extNotification(method, params) {
2069
- return await this.#connection.sendNotification(method, params);
2070
- }
2071
- /**
2072
- * AbortSignal that aborts when the connection closes.
2073
- *
2074
- * This signal can be used to:
2075
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
2076
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
2077
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
2078
- *
2079
- * The connection closes when the underlying stream ends, either normally or due to an error.
2080
- *
2081
- * @example
2082
- * ```typescript
2083
- * const connection = new ClientSideConnection(client, stream);
2084
- *
2085
- * // Listen for closure
2086
- * connection.signal.addEventListener('abort', () => {
2087
- * console.log('Connection closed - performing cleanup');
2088
- * });
2089
- *
2090
- * // Check status
2091
- * if (connection.signal.aborted) {
2092
- * console.log('Connection is already closed');
2093
- * }
2094
- *
2095
- * // Pass to other APIs
2096
- * fetch(url, { signal: connection.signal });
2097
- * ```
2098
- */
2099
- get signal() {
2100
- return this.#connection.signal;
2101
- }
2102
- /**
2103
- * Promise that resolves when the connection closes.
2104
- *
2105
- * The connection closes when the underlying stream ends, either normally or due to an error.
2106
- * Once closed, the connection cannot send or receive any more messages.
2107
- *
2108
- * This is useful for async/await style cleanup:
2109
- *
2110
- * @example
2111
- * ```typescript
2112
- * const connection = new ClientSideConnection(client, stream);
2113
- * await connection.closed;
2114
- * console.log('Connection closed - performing cleanup');
2115
- * ```
2116
- */
2117
- get closed() {
2118
- return this.#connection.closed;
2119
- }
2120
- };
2121
- Connection = class Connection2 {
2122
- static {
2123
- __name(this, "Connection");
2124
- }
2125
- #pendingResponses = /* @__PURE__ */ new Map();
2126
- #nextRequestId = 0;
2127
- #requestHandler;
2128
- #notificationHandler;
2129
- #stream;
2130
- #writeQueue = Promise.resolve();
2131
- #abortController = new AbortController();
2132
- #closedPromise;
2133
- constructor(requestHandler, notificationHandler, stream) {
2134
- this.#requestHandler = requestHandler;
2135
- this.#notificationHandler = notificationHandler;
2136
- this.#stream = stream;
2137
- this.#closedPromise = new Promise((resolve) => {
2138
- this.#abortController.signal.addEventListener("abort", () => resolve());
2139
- });
2140
- this.#receive();
2141
- }
2142
- /**
2143
- * AbortSignal that aborts when the connection closes.
2144
- *
2145
- * This signal can be used to:
2146
- * - Listen for connection closure via event listeners
2147
- * - Check connection status synchronously with `signal.aborted`
2148
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
2149
- */
2150
- get signal() {
2151
- return this.#abortController.signal;
2152
- }
2153
- /**
2154
- * Promise that resolves when the connection closes.
2155
- *
2156
- * The connection closes when the underlying stream ends, either normally
2157
- * or due to an error. Once closed, the connection cannot send or receive
2158
- * any more messages.
2159
- *
2160
- * @example
2161
- * ```typescript
2162
- * const connection = new ClientSideConnection(client, stream);
2163
- * await connection.closed;
2164
- * console.log('Connection closed - performing cleanup');
2165
- * ```
2166
- */
2167
- get closed() {
2168
- return this.#closedPromise;
2169
- }
2170
- async #receive() {
2171
- const reader = this.#stream.readable.getReader();
2172
- try {
2173
- while (true) {
2174
- const { value: message, done } = await reader.read();
2175
- if (done) {
2176
- break;
2177
- }
2178
- if (!message) {
2179
- continue;
2180
- }
2181
- try {
2182
- this.#processMessage(message);
2183
- } catch (err) {
2184
- console.error("Unexpected error during message processing:", message, err);
2185
- if ("id" in message && message.id !== void 0) {
2186
- this.#sendMessage({
2187
- jsonrpc: "2.0",
2188
- id: message.id,
2189
- error: {
2190
- code: -32700,
2191
- message: "Parse error"
2192
- }
2193
- });
2194
- }
2195
- }
2196
- }
2197
- } finally {
2198
- reader.releaseLock();
2199
- this.#abortController.abort();
2200
- }
2201
- }
2202
- async #processMessage(message) {
2203
- if ("method" in message && "id" in message) {
2204
- const response = await this.#tryCallRequestHandler(message.method, message.params);
2205
- if ("error" in response) {
2206
- console.error("Error handling request", message, response.error);
2207
- }
2208
- await this.#sendMessage({
2209
- jsonrpc: "2.0",
2210
- id: message.id,
2211
- ...response
2212
- });
2213
- } else if ("method" in message) {
2214
- const response = await this.#tryCallNotificationHandler(message.method, message.params);
2215
- if ("error" in response) {
2216
- console.error("Error handling notification", message, response.error);
2217
- }
2218
- } else if ("id" in message) {
2219
- this.#handleResponse(message);
2220
- } else {
2221
- console.error("Invalid message", {
2222
- message
2223
- });
2224
- }
2225
- }
2226
- async #tryCallRequestHandler(method, params) {
2227
- try {
2228
- const result = await this.#requestHandler(method, params);
2229
- return {
2230
- result: result ?? null
2231
- };
2232
- } catch (error) {
2233
- if (error instanceof RequestError) {
2234
- return error.toResult();
2235
- }
2236
- if (error instanceof z2.ZodError) {
2237
- return RequestError.invalidParams(error.format()).toResult();
2238
- }
2239
- let details;
2240
- if (error instanceof Error) {
2241
- details = error.message;
2242
- } else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
2243
- details = error.message;
2244
- }
2245
- try {
2246
- return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
2247
- } catch {
2248
- return RequestError.internalError({
2249
- details
2250
- }).toResult();
2251
- }
2252
- }
2253
- }
2254
- async #tryCallNotificationHandler(method, params) {
2255
- try {
2256
- await this.#notificationHandler(method, params);
2257
- return {
2258
- result: null
2259
- };
2260
- } catch (error) {
2261
- if (error instanceof RequestError) {
2262
- return error.toResult();
2263
- }
2264
- if (error instanceof z2.ZodError) {
2265
- return RequestError.invalidParams(error.format()).toResult();
2266
- }
2267
- let details;
2268
- if (error instanceof Error) {
2269
- details = error.message;
2270
- } else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
2271
- details = error.message;
2272
- }
2273
- try {
2274
- return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
2275
- } catch {
2276
- return RequestError.internalError({
2277
- details
2278
- }).toResult();
2279
- }
2280
- }
2281
- }
2282
- #handleResponse(response) {
2283
- const pendingResponse = this.#pendingResponses.get(response.id);
2284
- if (pendingResponse) {
2285
- if ("result" in response) {
2286
- pendingResponse.resolve(response.result);
2287
- } else if ("error" in response) {
2288
- pendingResponse.reject(response.error);
2289
- }
2290
- this.#pendingResponses.delete(response.id);
2291
- } else {
2292
- console.error("Got response to unknown request", response.id);
2293
- }
2294
- }
2295
- async sendRequest(method, params) {
2296
- const id = this.#nextRequestId++;
2297
- const responsePromise = new Promise((resolve, reject) => {
2298
- this.#pendingResponses.set(id, {
2299
- resolve,
2300
- reject
2301
- });
2302
- });
2303
- await this.#sendMessage({
2304
- jsonrpc: "2.0",
2305
- id,
2306
- method,
2307
- params
2308
- });
2309
- return responsePromise;
2310
- }
2311
- async sendNotification(method, params) {
2312
- await this.#sendMessage({
2313
- jsonrpc: "2.0",
2314
- method,
2315
- params
2316
- });
2317
- }
2318
- async #sendMessage(message) {
2319
- this.#writeQueue = this.#writeQueue.then(async () => {
2320
- const writer = this.#stream.writable.getWriter();
2321
- try {
2322
- await writer.write(message);
2323
- } finally {
2324
- writer.releaseLock();
2325
- }
2326
- }).catch((error) => {
2327
- console.error("ACP write error:", error);
2328
- });
2329
- return this.#writeQueue;
2330
- }
2331
- };
2332
- RequestError = class _RequestError extends Error {
2333
- static {
2334
- __name(this, "RequestError");
2335
- }
2336
- code;
2337
- data;
2338
- constructor(code, message, data) {
2339
- super(message);
2340
- this.code = code;
2341
- this.name = "RequestError";
2342
- this.data = data;
2343
- }
2344
- /**
2345
- * Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
2346
- */
2347
- static parseError(data, additionalMessage) {
2348
- return new _RequestError(-32700, `Parse error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2349
- }
2350
- /**
2351
- * The JSON sent is not a valid Request object.
2352
- */
2353
- static invalidRequest(data, additionalMessage) {
2354
- return new _RequestError(-32600, `Invalid request${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2355
- }
2356
- /**
2357
- * The method does not exist / is not available.
2358
- */
2359
- static methodNotFound(method) {
2360
- return new _RequestError(-32601, `"Method not found": ${method}`, {
2361
- method
2362
- });
2363
- }
2364
- /**
2365
- * Invalid method parameter(s).
2366
- */
2367
- static invalidParams(data, additionalMessage) {
2368
- return new _RequestError(-32602, `Invalid params${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2369
- }
2370
- /**
2371
- * Internal JSON-RPC error.
2372
- */
2373
- static internalError(data, additionalMessage) {
2374
- return new _RequestError(-32603, `Internal error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2375
- }
2376
- /**
2377
- * Authentication required.
2378
- */
2379
- static authRequired(data, additionalMessage) {
2380
- return new _RequestError(-32e3, `Authentication required${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2381
- }
2382
- /**
2383
- * Resource, such as a file, was not found
2384
- */
2385
- static resourceNotFound(uri) {
2386
- return new _RequestError(-32002, `Resource not found${uri ? `: ${uri}` : ""}`, uri && {
2387
- uri
2388
- });
2389
- }
2390
- toResult() {
2391
- return {
2392
- error: {
2393
- code: this.code,
2394
- message: this.message,
2395
- data: this.data
2396
- }
2397
- };
2398
- }
2399
- toErrorResponse() {
2400
- return {
2401
- code: this.code,
2402
- message: this.message,
2403
- data: this.data
2404
- };
2405
- }
2406
- };
2407
- }
2408
- });
2409
-
2410
- export {
2411
- __name,
2412
- __require,
2413
- __esm,
2414
- __commonJS,
2415
- __export,
2416
- __toESM,
2417
- __toCommonJS,
2418
- AGENT_METHODS,
2419
- CLIENT_METHODS,
2420
- PROTOCOL_VERSION,
2421
- ndJsonStream,
2422
- AgentSideConnection,
2423
- TerminalHandle,
2424
- ClientSideConnection,
2425
- RequestError,
2426
- acp_exports,
2427
- init_acp
2428
- };