@agentclientprotocol/claude-agent-acp 0.102.1-preview.1 → 0.102.1-preview.3

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 (229) hide show
  1. package/README.md +5 -1
  2. package/dist/acp-agent.d.ts +93 -622
  3. package/dist/acp-agent.d.ts.map +1 -1
  4. package/dist/acp-agent.js +369 -3474
  5. package/dist/acp-client.d.ts +28 -0
  6. package/dist/acp-client.d.ts.map +1 -0
  7. package/dist/acp-client.js +1 -0
  8. package/dist/acp-subagents.d.ts +1 -2
  9. package/dist/acp-subagents.d.ts.map +1 -1
  10. package/dist/auth-methods.d.ts +21 -0
  11. package/dist/auth-methods.d.ts.map +1 -0
  12. package/dist/auth-methods.js +68 -0
  13. package/dist/auth-status-reporter.d.ts +112 -0
  14. package/dist/auth-status-reporter.d.ts.map +1 -0
  15. package/dist/auth-status-reporter.js +253 -0
  16. package/dist/background-work.d.ts +12 -265
  17. package/dist/background-work.d.ts.map +1 -1
  18. package/dist/background-work.js +8 -558
  19. package/dist/client-system-prompt.d.ts +7 -0
  20. package/dist/client-system-prompt.d.ts.map +1 -1
  21. package/dist/client-system-prompt.js +24 -0
  22. package/dist/context-compaction.d.ts +20 -0
  23. package/dist/context-compaction.d.ts.map +1 -1
  24. package/dist/context-compaction.js +26 -0
  25. package/dist/context-window.d.ts +70 -0
  26. package/dist/context-window.d.ts.map +1 -0
  27. package/dist/context-window.js +132 -0
  28. package/dist/diff.d.ts +1 -1
  29. package/dist/diff.js +1 -1
  30. package/dist/elicitation.d.ts +66 -1
  31. package/dist/elicitation.d.ts.map +1 -1
  32. package/dist/elicitation.js +109 -0
  33. package/dist/file-change-audit.d.ts +4 -3
  34. package/dist/file-change-audit.d.ts.map +1 -1
  35. package/dist/file-change-audit.js +3 -2
  36. package/dist/lib.d.ts +5 -1
  37. package/dist/lib.d.ts.map +1 -1
  38. package/dist/lib.js +3 -1
  39. package/dist/logger.d.ts +10 -0
  40. package/dist/logger.d.ts.map +1 -0
  41. package/dist/logger.js +1 -0
  42. package/dist/mcp-oauth.d.ts +44 -0
  43. package/dist/mcp-oauth.d.ts.map +1 -0
  44. package/dist/mcp-oauth.js +142 -0
  45. package/dist/mcp-servers.d.ts +10 -0
  46. package/dist/mcp-servers.d.ts.map +1 -0
  47. package/dist/mcp-servers.js +29 -0
  48. package/dist/message-filters.d.ts +43 -0
  49. package/dist/message-filters.d.ts.map +1 -0
  50. package/dist/message-filters.js +197 -0
  51. package/dist/native-subagents.d.ts +18 -8
  52. package/dist/native-subagents.d.ts.map +1 -1
  53. package/dist/native-subagents.js +7 -35
  54. package/dist/new-session-meta.d.ts +40 -0
  55. package/dist/new-session-meta.d.ts.map +1 -0
  56. package/dist/new-session-meta.js +1 -0
  57. package/dist/permissions/presentation.d.ts +29 -0
  58. package/dist/permissions/presentation.d.ts.map +1 -1
  59. package/dist/permissions/presentation.js +38 -11
  60. package/dist/prompt-suggestions.d.ts +29 -0
  61. package/dist/prompt-suggestions.d.ts.map +1 -1
  62. package/dist/prompt-suggestions.js +45 -0
  63. package/dist/prompt-to-claude.d.ts +10 -0
  64. package/dist/prompt-to-claude.d.ts.map +1 -0
  65. package/dist/prompt-to-claude.js +120 -0
  66. package/dist/providers.d.ts +139 -0
  67. package/dist/providers.d.ts.map +1 -0
  68. package/dist/providers.js +286 -0
  69. package/dist/remote-control.d.ts +62 -0
  70. package/dist/remote-control.d.ts.map +1 -0
  71. package/dist/remote-control.js +78 -0
  72. package/dist/result-end.d.ts +68 -0
  73. package/dist/result-end.d.ts.map +1 -0
  74. package/dist/result-end.js +84 -0
  75. package/dist/sdk-to-acp.d.ts +93 -0
  76. package/dist/sdk-to-acp.d.ts.map +1 -0
  77. package/dist/sdk-to-acp.js +635 -0
  78. package/dist/serve.d.ts +9 -3
  79. package/dist/serve.d.ts.map +1 -1
  80. package/dist/serve.js +10 -5
  81. package/dist/session-config-ids.d.ts +1 -0
  82. package/dist/session-config-ids.d.ts.map +1 -1
  83. package/dist/session-config-ids.js +1 -0
  84. package/dist/session-config-options.d.ts +64 -0
  85. package/dist/session-config-options.d.ts.map +1 -0
  86. package/dist/session-config-options.js +162 -0
  87. package/dist/session-effort.d.ts +67 -0
  88. package/dist/session-effort.d.ts.map +1 -1
  89. package/dist/session-effort.js +98 -0
  90. package/dist/session-env.d.ts +22 -0
  91. package/dist/session-env.d.ts.map +1 -0
  92. package/dist/session-env.js +66 -0
  93. package/dist/session-fast-mode.d.ts +83 -0
  94. package/dist/session-fast-mode.d.ts.map +1 -0
  95. package/dist/session-fast-mode.js +142 -0
  96. package/dist/session-index/connection.d.ts +5 -6
  97. package/dist/session-index/connection.d.ts.map +1 -1
  98. package/dist/session-index/connection.js +3 -5
  99. package/dist/session-mode.d.ts +1 -0
  100. package/dist/session-mode.d.ts.map +1 -1
  101. package/dist/session-mode.js +1 -1
  102. package/dist/session-model.d.ts +41 -0
  103. package/dist/session-model.d.ts.map +1 -1
  104. package/dist/session-model.js +110 -45
  105. package/dist/session-notices.d.ts +44 -0
  106. package/dist/session-notices.d.ts.map +1 -1
  107. package/dist/session-notices.js +68 -0
  108. package/dist/session-titles.d.ts +34 -12
  109. package/dist/session-titles.d.ts.map +1 -1
  110. package/dist/session-titles.js +7 -6
  111. package/dist/session-usage.d.ts +125 -0
  112. package/dist/session-usage.d.ts.map +1 -0
  113. package/dist/session-usage.js +196 -0
  114. package/dist/slash-commands.d.ts +10 -0
  115. package/dist/slash-commands.d.ts.map +1 -0
  116. package/dist/slash-commands.js +99 -0
  117. package/dist/streamed-text.d.ts +33 -0
  118. package/dist/streamed-text.d.ts.map +1 -0
  119. package/dist/streamed-text.js +71 -0
  120. package/dist/subagent-configuration.d.ts +32 -0
  121. package/dist/subagent-configuration.d.ts.map +1 -0
  122. package/dist/subagent-configuration.js +70 -0
  123. package/dist/subagent-replay.d.ts +18 -0
  124. package/dist/subagent-replay.d.ts.map +1 -1
  125. package/dist/subagent-replay.js +25 -15
  126. package/dist/tool-calls/client-capabilities.d.ts +8 -8
  127. package/dist/tool-calls/client-capabilities.js +4 -4
  128. package/dist/tool-calls/renderer.d.ts +4 -5
  129. package/dist/tool-calls/renderer.d.ts.map +1 -1
  130. package/dist/tool-calls/renderer.js +4 -5
  131. package/dist/turn-events.d.ts +6 -46
  132. package/dist/turn-events.d.ts.map +1 -1
  133. package/dist/utils.d.ts +1 -1
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/v2/agent.d.ts +7 -11
  136. package/dist/v2/agent.d.ts.map +1 -1
  137. package/dist/v2/agent.js +751 -331
  138. package/dist/v2/air.d.ts +33 -0
  139. package/dist/v2/air.d.ts.map +1 -0
  140. package/dist/v2/air.js +29 -0
  141. package/dist/v2/auth.d.ts +97 -0
  142. package/dist/v2/auth.d.ts.map +1 -0
  143. package/dist/v2/auth.js +216 -0
  144. package/dist/v2/background.d.ts +27 -16
  145. package/dist/v2/background.d.ts.map +1 -1
  146. package/dist/v2/background.js +4 -32
  147. package/dist/v2/child-config.d.ts +55 -0
  148. package/dist/v2/child-config.d.ts.map +1 -0
  149. package/dist/v2/child-config.js +92 -0
  150. package/dist/v2/clear-context.d.ts +94 -0
  151. package/dist/v2/clear-context.d.ts.map +1 -0
  152. package/dist/v2/clear-context.js +176 -0
  153. package/dist/v2/commands.d.ts +46 -0
  154. package/dist/v2/commands.d.ts.map +1 -0
  155. package/dist/v2/commands.js +54 -0
  156. package/dist/v2/config.d.ts +187 -0
  157. package/dist/v2/config.d.ts.map +1 -0
  158. package/dist/v2/config.js +494 -0
  159. package/dist/v2/elicitation.d.ts +93 -0
  160. package/dist/v2/elicitation.d.ts.map +1 -0
  161. package/dist/v2/elicitation.js +160 -0
  162. package/dist/v2/file-changes.d.ts +61 -0
  163. package/dist/v2/file-changes.d.ts.map +1 -0
  164. package/dist/v2/file-changes.js +108 -0
  165. package/dist/v2/file-preview.d.ts +18 -0
  166. package/dist/v2/file-preview.d.ts.map +1 -0
  167. package/dist/v2/file-preview.js +29 -0
  168. package/dist/v2/initialize.d.ts +10 -24
  169. package/dist/v2/initialize.d.ts.map +1 -1
  170. package/dist/v2/initialize.js +4 -111
  171. package/dist/v2/outcome.d.ts +81 -0
  172. package/dist/v2/outcome.d.ts.map +1 -0
  173. package/dist/v2/outcome.js +166 -0
  174. package/dist/v2/permissions.d.ts +92 -0
  175. package/dist/v2/permissions.d.ts.map +1 -0
  176. package/dist/v2/permissions.js +162 -0
  177. package/dist/v2/prompt.d.ts +2 -42
  178. package/dist/v2/prompt.d.ts.map +1 -1
  179. package/dist/v2/prompt.js +2 -119
  180. package/dist/v2/remote-control.d.ts +41 -0
  181. package/dist/v2/remote-control.d.ts.map +1 -0
  182. package/dist/v2/remote-control.js +63 -0
  183. package/dist/v2/reports.d.ts +198 -0
  184. package/dist/v2/reports.d.ts.map +1 -0
  185. package/dist/v2/reports.js +487 -0
  186. package/dist/v2/restarts.d.ts +128 -0
  187. package/dist/v2/restarts.d.ts.map +1 -0
  188. package/dist/v2/restarts.js +348 -0
  189. package/dist/v2/session-requests.d.ts +20 -0
  190. package/dist/v2/session-requests.d.ts.map +1 -0
  191. package/dist/v2/session-requests.js +108 -0
  192. package/dist/v2/session-update.d.ts +2 -13
  193. package/dist/v2/session-update.d.ts.map +1 -1
  194. package/dist/v2/session-update.js +2 -22
  195. package/dist/v2/session.d.ts +340 -41
  196. package/dist/v2/session.d.ts.map +1 -1
  197. package/dist/v2/session.js +1224 -141
  198. package/dist/v2/setup.d.ts +49 -0
  199. package/dist/v2/setup.d.ts.map +1 -0
  200. package/dist/v2/setup.js +62 -0
  201. package/dist/v2/stopped-work.d.ts +123 -0
  202. package/dist/v2/stopped-work.d.ts.map +1 -0
  203. package/dist/v2/stopped-work.js +210 -0
  204. package/dist/v2/stream.d.ts +229 -0
  205. package/dist/v2/stream.d.ts.map +1 -0
  206. package/dist/v2/stream.js +507 -0
  207. package/dist/v2/subagent-replay.d.ts +115 -0
  208. package/dist/v2/subagent-replay.d.ts.map +1 -0
  209. package/dist/v2/subagent-replay.js +479 -0
  210. package/dist/v2/subscription-guard.d.ts +60 -0
  211. package/dist/v2/subscription-guard.d.ts.map +1 -0
  212. package/dist/v2/subscription-guard.js +84 -0
  213. package/dist/v2/tasks.d.ts +492 -0
  214. package/dist/v2/tasks.d.ts.map +1 -0
  215. package/dist/v2/tasks.js +1728 -0
  216. package/dist/v2/terminal.d.ts.map +1 -1
  217. package/dist/v2/terminal.js +6 -1
  218. package/dist/v2/tool-call.d.ts +3 -2
  219. package/dist/v2/tool-call.d.ts.map +1 -1
  220. package/dist/v2/update-translator.d.ts +36 -0
  221. package/dist/v2/update-translator.d.ts.map +1 -0
  222. package/dist/v2/update-translator.js +80 -0
  223. package/dist/workflow-progress.d.ts +23 -0
  224. package/dist/workflow-progress.d.ts.map +1 -1
  225. package/dist/workflow-progress.js +31 -8
  226. package/package.json +1 -1
  227. package/dist/v2/permission.d.ts +0 -28
  228. package/dist/v2/permission.d.ts.map +0 -1
  229. package/dist/v2/permission.js +0 -41
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Client-managed LLM routing, shared by the v1 core and the v2 core:
3
+ * the `main` provider of `providers/list`, `providers/set` and
4
+ * `providers/disable`, and the legacy gateway logins (`authenticate` or
5
+ * `auth/login` with `gateway` or `gateway-bedrock`). Each core holds its own
6
+ * {@link ProviderConfig} and gateway login, and builds the query env of its
7
+ * sessions with {@link createEnvForProvider}.
8
+ */
9
+ import { RequestError, } from "@agentclientprotocol/sdk/unstable";
10
+ import { GatewayListingError, listBedrockModels, listGatewayModels, PROVIDER_AUTH_TOKEN_PLACEHOLDER, selectBedrockRegion, } from "./gateway-models.js";
11
+ export const SUPPORTED_PROTOCOLS = ["anthropic", "bedrock", "vertex"];
12
+ export const PROVIDER_ID = "main";
13
+ export const DEFAULT_ANTHROPIC_BASE_URL = "https://api.anthropic.com";
14
+ export const DEFAULT_VERTEX_BASE_URL = "https://aiplatform.googleapis.com";
15
+ /**
16
+ * Adapt a legacy gateway `authenticate` request into the shared
17
+ * {@link ProviderConfig} shape. Returns `null` when no gateway request is
18
+ * present. `methodId` selects the protocol: `gateway-bedrock` → bedrock,
19
+ * otherwise anthropic.
20
+ */
21
+ export function gatewayRequestToProviderConfig(request) {
22
+ // `authenticate` validates the payload before it stores one, so a stored
23
+ // request always carries a usable gateway. Re-check the shape here anyway:
24
+ // this function decides whether a provider override is active, and the
25
+ // `--hide-claude-auth` guard is off while one is.
26
+ const gateway = request?._meta?.gateway;
27
+ if (!gateway || !isValidBaseUrl(gateway.baseUrl)) {
28
+ return null;
29
+ }
30
+ return {
31
+ apiType: request?.methodId === "gateway-bedrock" ? "bedrock" : "anthropic",
32
+ baseUrl: gateway.baseUrl,
33
+ headers: gateway.headers ?? {},
34
+ };
35
+ }
36
+ /**
37
+ * Map a resolved provider config into the Claude Code env vars that redirect API
38
+ * traffic and inject headers. Returns an empty object when routing is
39
+ * unconfigured. The token/bypass placeholders (`" "`) are required so the CLI
40
+ * skips its normal login/credential checks when a gateway is in use.
41
+ */
42
+ export function createEnvForProvider(config) {
43
+ if (!config) {
44
+ return {};
45
+ }
46
+ const resetRouting = {
47
+ ANTHROPIC_BASE_URL: "",
48
+ ANTHROPIC_BEDROCK_BASE_URL: "",
49
+ ANTHROPIC_VERTEX_BASE_URL: "",
50
+ CLAUDE_CODE_USE_BEDROCK: "0",
51
+ CLAUDE_CODE_USE_VERTEX: "0",
52
+ ANTHROPIC_VERTEX_PROJECT_ID: "",
53
+ CLOUD_ML_REGION: "",
54
+ AWS_REGION: "",
55
+ ANTHROPIC_API_KEY: "",
56
+ ANTHROPIC_AUTH_TOKEN: "",
57
+ CLAUDE_CODE_OAUTH_TOKEN: "",
58
+ };
59
+ const customHeaders = Object.entries(config.headers)
60
+ .map(([key, value]) => `${key}: ${value}`)
61
+ .join("\n");
62
+ if (config.apiType === "bedrock") {
63
+ return {
64
+ ...resetRouting,
65
+ CLAUDE_CODE_USE_BEDROCK: "1",
66
+ AWS_BEARER_TOKEN_BEDROCK: PROVIDER_AUTH_TOKEN_PLACEHOLDER, // Bypass local AWS credential checks
67
+ ANTHROPIC_BEDROCK_BASE_URL: config.baseUrl,
68
+ ANTHROPIC_CUSTOM_HEADERS: customHeaders,
69
+ ...(config.bedrockRegionPrefix
70
+ ? { ANTHROPIC_BEDROCK_REGION_PREFIX: config.bedrockRegionPrefix }
71
+ : {}),
72
+ };
73
+ }
74
+ if (config.apiType === "vertex") {
75
+ // `config.vertex` is guaranteed present for vertex by `unstable_setProvider`
76
+ // validation; fall back to empty strings defensively.
77
+ // Leaving ANTHROPIC_VERTEX_BASE_URL empty for the default endpoint lets
78
+ // Claude Code use its native Vertex endpoint/model resolution. Supplying
79
+ // even the default host marks the session as a custom Vertex deployment and
80
+ // can hide otherwise-valid models.
81
+ return {
82
+ ...resetRouting,
83
+ CLAUDE_CODE_USE_VERTEX: "1",
84
+ ...(config.baseUrl !== DEFAULT_VERTEX_BASE_URL
85
+ ? { ANTHROPIC_VERTEX_BASE_URL: config.baseUrl }
86
+ : {}),
87
+ ANTHROPIC_VERTEX_PROJECT_ID: config.vertex?.projectId ?? "",
88
+ CLOUD_ML_REGION: config.vertex?.region ?? "",
89
+ ANTHROPIC_CUSTOM_HEADERS: customHeaders,
90
+ };
91
+ }
92
+ return {
93
+ ...resetRouting,
94
+ ANTHROPIC_BASE_URL: config.baseUrl,
95
+ ANTHROPIC_CUSTOM_HEADERS: customHeaders,
96
+ ANTHROPIC_AUTH_TOKEN: PROVIDER_AUTH_TOKEN_PLACEHOLDER, // Bypass local Claude login checks
97
+ };
98
+ }
99
+ function sameHeaders(a, b) {
100
+ const aKeys = Object.keys(a);
101
+ return aKeys.length === Object.keys(b).length && aKeys.every((key) => b[key] === a[key]);
102
+ }
103
+ /**
104
+ * A provider base URL as logs may show it: its origin only. The URL can come
105
+ * from the env or the client and can carry credentials (`https://user:key@host`)
106
+ * or a key in its path or query, so a log line must not print it whole.
107
+ */
108
+ export function loggableBaseUrl(baseUrl) {
109
+ if (baseUrl === undefined)
110
+ return "native";
111
+ try {
112
+ return new URL(baseUrl).origin;
113
+ }
114
+ catch {
115
+ return "invalid";
116
+ }
117
+ }
118
+ /**
119
+ * Validate a provider base URL: must be a non-empty absolute http(s) URL.
120
+ */
121
+ export function isValidBaseUrl(baseUrl) {
122
+ if (typeof baseUrl !== "string" || baseUrl.trim() === "") {
123
+ return false;
124
+ }
125
+ let parsed;
126
+ try {
127
+ parsed = new URL(baseUrl);
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ return parsed.protocol === "http:" || parsed.protocol === "https:";
133
+ }
134
+ /** The gateway login methods, advertised to a client with `auth._meta.gateway`. */
135
+ export function gatewayAuthMethods() {
136
+ return ["anthropic", "bedrock"].map((protocol) => ({
137
+ id: protocol === "anthropic" ? "gateway" : "gateway-bedrock",
138
+ name: "Custom model gateway",
139
+ description: "Use a custom gateway to authenticate and access models",
140
+ _meta: { gateway: { protocol } },
141
+ }));
142
+ }
143
+ export function isGatewayAuthMethod(methodId) {
144
+ return methodId === "gateway" || methodId === "gateway-bedrock";
145
+ }
146
+ /**
147
+ * The gateway login `params` asks for, once its payload is usable: the same
148
+ * base URL rule as `providers/set`. An unchecked payload either throws a
149
+ * `TypeError` deep in session creation, or installs an empty base URL that
150
+ * silently turns the `--hide-claude-auth` subscription guard off.
151
+ *
152
+ * A request that carries no gateway payload at all keeps its historical
153
+ * meaning: it installs no override and succeeds. A client that probes the
154
+ * method this way must keep working. Only a payload that IS present has to be
155
+ * usable.
156
+ */
157
+ export function validatedGatewayAuthRequest(params) {
158
+ const gateway = params._meta?.gateway;
159
+ if (gateway !== undefined && gateway !== null) {
160
+ if (typeof gateway !== "object" || !isValidBaseUrl(gateway.baseUrl)) {
161
+ throw RequestError.invalidParams({ baseUrl: gateway.baseUrl }, "`_meta.gateway.baseUrl` must be a non-empty absolute http(s) URL.");
162
+ }
163
+ if (gateway.headers !== undefined && typeof gateway.headers !== "object") {
164
+ throw RequestError.invalidParams(undefined, "`_meta.gateway.headers` must be an object of header names to values.");
165
+ }
166
+ }
167
+ return params;
168
+ }
169
+ /** The native routing of the agent: a gateway login, else the process env. */
170
+ export function defaultProviderConfig(gatewayAuthRequest) {
171
+ const gatewayConfig = gatewayRequestToProviderConfig(gatewayAuthRequest);
172
+ if (gatewayConfig) {
173
+ return gatewayConfig;
174
+ }
175
+ if (process.env.CLAUDE_CODE_USE_BEDROCK) {
176
+ return {
177
+ apiType: "bedrock",
178
+ baseUrl: process.env.ANTHROPIC_BEDROCK_BASE_URL ?? "https://bedrock-runtime.amazonaws.com",
179
+ headers: {},
180
+ };
181
+ }
182
+ if (process.env.CLAUDE_CODE_USE_VERTEX) {
183
+ return {
184
+ apiType: "vertex",
185
+ baseUrl: process.env.ANTHROPIC_VERTEX_BASE_URL ?? DEFAULT_VERTEX_BASE_URL,
186
+ headers: {},
187
+ };
188
+ }
189
+ return {
190
+ apiType: "anthropic",
191
+ baseUrl: process.env.ANTHROPIC_BASE_URL ?? DEFAULT_ANTHROPIC_BASE_URL,
192
+ headers: {},
193
+ };
194
+ }
195
+ /** The `providers/list` response for the `main` provider routed by `config`. */
196
+ export function listProvidersResponse(config) {
197
+ const provider = {
198
+ providerId: PROVIDER_ID,
199
+ supported: SUPPORTED_PROTOCOLS,
200
+ required: false,
201
+ current: { apiType: config.apiType, baseUrl: config.baseUrl },
202
+ };
203
+ return { providers: [provider] };
204
+ }
205
+ /**
206
+ * The configuration a `providers/set` request asks for. Rejects unknown IDs,
207
+ * unsupported protocols, empty or invalid base URLs, and a `vertex` request
208
+ * without its project and region, with `invalid_params`.
209
+ */
210
+ export function providerConfigFromSetRequest(params) {
211
+ if (params.providerId !== PROVIDER_ID) {
212
+ throw RequestError.invalidParams({ providerId: params.providerId }, `Unknown provider ID "${params.providerId}"; expected "${PROVIDER_ID}".`);
213
+ }
214
+ if (!SUPPORTED_PROTOCOLS.includes(params.apiType)) {
215
+ throw RequestError.invalidParams({ apiType: params.apiType, supported: SUPPORTED_PROTOCOLS }, `Unsupported apiType "${params.apiType}" for provider "${PROVIDER_ID}".`);
216
+ }
217
+ if (!isValidBaseUrl(params.baseUrl)) {
218
+ throw RequestError.invalidParams({ baseUrl: params.baseUrl }, "baseUrl must be a non-empty absolute http(s) URL.");
219
+ }
220
+ const config = {
221
+ apiType: params.apiType,
222
+ baseUrl: params.baseUrl,
223
+ headers: params.headers ?? {},
224
+ };
225
+ // Vertex requires project + region, which the standard payload cannot
226
+ // carry, so they arrive via `_meta.claudeCode.vertex`.
227
+ if (params.apiType === "vertex") {
228
+ const vertex = params._meta?.claudeCode?.vertex;
229
+ if (!vertex ||
230
+ typeof vertex.projectId !== "string" ||
231
+ vertex.projectId.trim() === "" ||
232
+ typeof vertex.region !== "string" ||
233
+ vertex.region.trim() === "") {
234
+ throw RequestError.invalidParams(undefined, "vertex apiType requires non-empty `_meta.claudeCode.vertex.projectId` and `_meta.claudeCode.vertex.region`.");
235
+ }
236
+ config.vertex = { projectId: vertex.projectId, region: vertex.region };
237
+ }
238
+ return config;
239
+ }
240
+ /**
241
+ * Adds to `config` the model ids its gateway lists, and for `bedrock` the
242
+ * region prefix picked from them, so the sessions it routes offer only those.
243
+ * Setting the same gateway as `current` again reuses its listing. `vertex`
244
+ * gateways are not listed. A failed listing throws an `internal_error`.
245
+ */
246
+ export async function withListedModels(config, current, logger) {
247
+ try {
248
+ Object.assign(config, await listProviderModels(config, current, logger));
249
+ }
250
+ catch (error) {
251
+ if (error instanceof GatewayListingError) {
252
+ throw RequestError.internalError({ providerId: PROVIDER_ID, apiType: config.apiType, baseUrl: config.baseUrl }, `Model discovery for provider "${PROVIDER_ID}" failed: ${error.message}`);
253
+ }
254
+ throw error;
255
+ }
256
+ logger.log(`[providers/set] listedModels=${config.listedModels?.length ?? "none"} bedrockRegionPrefix=${config.bedrockRegionPrefix ?? "none"}`);
257
+ return config;
258
+ }
259
+ async function listProviderModels(config, current, logger) {
260
+ // Reuse needs the very same headers, so a rotated token lists again, and a
261
+ // failed listing then fails that `providers/set`. Deliberate: AIR keeps its
262
+ // proxy key for the IDE's lifetime and does not rotate it.
263
+ if (current?.listedModels &&
264
+ current.apiType === config.apiType &&
265
+ current.baseUrl === config.baseUrl &&
266
+ sameHeaders(current.headers, config.headers)) {
267
+ return {
268
+ listedModels: current.listedModels,
269
+ bedrockRegionPrefix: current.bedrockRegionPrefix,
270
+ };
271
+ }
272
+ if (config.apiType === "anthropic") {
273
+ return { listedModels: await listGatewayModels(config.baseUrl, config.headers, logger) };
274
+ }
275
+ if (config.apiType === "bedrock") {
276
+ const modelIds = await listBedrockModels(config.baseUrl, config.headers, logger);
277
+ if (!modelIds)
278
+ return {};
279
+ const region = selectBedrockRegion(modelIds);
280
+ if (region.modelIds.length < modelIds.length) {
281
+ logger.log(`[providers/set] Bedrock models span several region prefixes; using ${region.regionPrefix} and dropping ${modelIds.length - region.modelIds.length} id(s) of other prefixes`);
282
+ }
283
+ return { listedModels: region.modelIds, bedrockRegionPrefix: region.regionPrefix };
284
+ }
285
+ return {};
286
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `/remote-control`, which the adapter serves itself, and the messages that a
3
+ * person types in another client of the session (claude.ai or the Claude
4
+ * mobile app, over Remote Control). Shared by the v1 core and the v2
5
+ * core, which run the command each in their own turn model.
6
+ */
7
+ /** The content blocks of a prompt, in v1 or v2 form: the command is one text block. */
8
+ type PromptContent = ReadonlyArray<{
9
+ type: string;
10
+ text?: unknown;
11
+ }>;
12
+ import type { Query, SDKUserMessage, SDKUserMessageReplay, SlashCommand } from "@anthropic-ai/claude-agent-sdk";
13
+ /** Runtime Remote Control control exposed by the pinned Agent SDK. Like
14
+ * `mcpAuthenticate`, it is not in the public `Query` declaration yet. The CLI's
15
+ * own `/remote-control` is terminal-bound and not offered to SDK hosts, so the
16
+ * adapter handles the command itself and answers with the session URL. */
17
+ export type RemoteControlQuery = Query & {
18
+ enableRemoteControl(enabled: boolean, name?: string): Promise<{
19
+ session_url?: string;
20
+ connect_url?: string;
21
+ }>;
22
+ };
23
+ export declare function supportsRemoteControl(query: Query): query is RemoteControlQuery;
24
+ export declare const REMOTE_CONTROL_COMMAND_NAME = "remote-control";
25
+ export type RemoteControlCommand = {
26
+ action: "connect";
27
+ name?: string;
28
+ } | {
29
+ action: "disconnect";
30
+ };
31
+ /** Parses `/remote-control [name]` and `/remote-control off` from a single-text
32
+ * prompt. Connecting is idempotent, so the command never needs to know whether
33
+ * Remote Control is already on. */
34
+ export declare function parseRemoteControlCommand(prompt: PromptContent): RemoteControlCommand | null;
35
+ /** Whether Claude Code offers a slash command of this name to an ACP client.
36
+ * This is the rule `getAvailableSlashCommands` applies when it lists the
37
+ * commands, so the adapter stands in for the command exactly when the client
38
+ * sees the adapter's entry: Claude Code's terminal-bound commands are not
39
+ * offered, and a user's own command or skill of the name is never shadowed. */
40
+ export declare function claudeCodeOffersCommand(commands: readonly SlashCommand[], terminalCommands: readonly string[] | undefined, name: string): boolean;
41
+ /**
42
+ * The `/remote-control` command of `prompt` that the adapter runs: the query
43
+ * serves Remote Control and Claude Code does not offer a command of that name.
44
+ * `null` for any other prompt, which goes to Claude Code.
45
+ */
46
+ export declare function adapterRemoteControlCommand(prompt: PromptContent, query: Query, terminalCommands: readonly string[] | undefined): Promise<{
47
+ query: RemoteControlQuery;
48
+ command: RemoteControlCommand;
49
+ } | null>;
50
+ /**
51
+ * Connects Remote Control (again, if it is already on) or disconnects it, and
52
+ * returns the text that tells the user how it went. A failure is in the text:
53
+ * this never throws.
54
+ */
55
+ export declare function runRemoteControlCommand(query: RemoteControlQuery, command: RemoteControlCommand, logError: (message: string) => void): Promise<string>;
56
+ /** A top-level message a person typed in another client of the session, such
57
+ * as claude.ai or the Claude mobile app over Remote Control. Tool results and
58
+ * the CLI's own synthetic messages are user-role too, but carry no human
59
+ * origin. */
60
+ export declare function isRemoteHumanMessage(message: SDKUserMessage | SDKUserMessageReplay): boolean;
61
+ export {};
62
+ //# sourceMappingURL=remote-control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-control.d.ts","sourceRoot":"","sources":["../src/remote-control.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,uFAAuF;AACvF,KAAK,aAAa,GAAG,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAErE,OAAO,KAAK,EACV,KAAK,EACL,cAAc,EACd,oBAAoB,EACpB,YAAY,EACb,MAAM,gCAAgC,CAAC;AAExC;;;2EAG2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG;IACvC,mBAAmB,CACjB,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5D,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,kBAAkB,CAE/E;AAED,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D,MAAM,MAAM,oBAAoB,GAAG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,CAAC;AAEnG;;oCAEoC;AACpC,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,aAAa,GAAG,oBAAoB,GAAG,IAAI,CAQ5F;AAED;;;;gFAIgF;AAChF,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC/C,IAAI,EAAE,MAAM,GACX,OAAO,CAIT;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAC9C,OAAO,CAAC;IAAE,KAAK,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GAAG,IAAI,CAAC,CAa9E;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED;;;cAGc;AACd,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,oBAAoB,GAAG,OAAO,CAO5F"}
@@ -0,0 +1,78 @@
1
+ export function supportsRemoteControl(query) {
2
+ return typeof query.enableRemoteControl === "function";
3
+ }
4
+ export const REMOTE_CONTROL_COMMAND_NAME = "remote-control";
5
+ /** Parses `/remote-control [name]` and `/remote-control off` from a single-text
6
+ * prompt. Connecting is idempotent, so the command never needs to know whether
7
+ * Remote Control is already on. */
8
+ export function parseRemoteControlCommand(prompt) {
9
+ const [first] = prompt;
10
+ if (prompt.length !== 1 || first?.type !== "text" || typeof first.text !== "string")
11
+ return null;
12
+ const match = /^\/remote-control(?:\s+([\s\S]*))?$/.exec(first.text.trim());
13
+ if (!match)
14
+ return null;
15
+ const argument = match[1]?.trim();
16
+ if (argument?.toLowerCase() === "off")
17
+ return { action: "disconnect" };
18
+ return argument ? { action: "connect", name: argument } : { action: "connect" };
19
+ }
20
+ /** Whether Claude Code offers a slash command of this name to an ACP client.
21
+ * This is the rule `getAvailableSlashCommands` applies when it lists the
22
+ * commands, so the adapter stands in for the command exactly when the client
23
+ * sees the adapter's entry: Claude Code's terminal-bound commands are not
24
+ * offered, and a user's own command or skill of the name is never shadowed. */
25
+ export function claudeCodeOffersCommand(commands, terminalCommands, name) {
26
+ return commands.some((command) => command.name === name && !terminalCommands?.includes(command.name));
27
+ }
28
+ /**
29
+ * The `/remote-control` command of `prompt` that the adapter runs: the query
30
+ * serves Remote Control and Claude Code does not offer a command of that name.
31
+ * `null` for any other prompt, which goes to Claude Code.
32
+ */
33
+ export async function adapterRemoteControlCommand(prompt, query, terminalCommands) {
34
+ const command = parseRemoteControlCommand(prompt);
35
+ if (!command || !supportsRemoteControl(query))
36
+ return null;
37
+ if (claudeCodeOffersCommand(await query.supportedCommands(), terminalCommands, REMOTE_CONTROL_COMMAND_NAME)) {
38
+ return null;
39
+ }
40
+ return { query, command };
41
+ }
42
+ /**
43
+ * Connects Remote Control (again, if it is already on) or disconnects it, and
44
+ * returns the text that tells the user how it went. A failure is in the text:
45
+ * this never throws.
46
+ */
47
+ export async function runRemoteControlCommand(query, command, logError) {
48
+ if (command.action === "disconnect") {
49
+ try {
50
+ await query.enableRemoteControl(false);
51
+ return "Remote Control is off. Run /remote-control to reconnect.";
52
+ }
53
+ catch (error) {
54
+ logError(`Failed to disable Remote Control: ${error}`);
55
+ return `Could not stop Remote Control: ${error instanceof Error ? error.message : error}`;
56
+ }
57
+ }
58
+ try {
59
+ const result = await query.enableRemoteControl(true, command.name);
60
+ return result.session_url
61
+ ? `Remote Control is active. Continue this session from claude.ai/code or the Claude mobile app:\n\n${result.session_url}\n\nRun /remote-control off to disconnect.`
62
+ : "Remote Control is active, but Claude Code did not return a session URL.";
63
+ }
64
+ catch (error) {
65
+ logError(`Failed to enable Remote Control: ${error}`);
66
+ return `Could not start Remote Control: ${error instanceof Error ? error.message : error}`;
67
+ }
68
+ }
69
+ /** A top-level message a person typed in another client of the session, such
70
+ * as claude.ai or the Claude mobile app over Remote Control. Tool results and
71
+ * the CLI's own synthetic messages are user-role too, but carry no human
72
+ * origin. */
73
+ export function isRemoteHumanMessage(message) {
74
+ return (message.type === "user" &&
75
+ message.origin?.kind === "human" &&
76
+ message.parent_tool_use_id === null &&
77
+ !message.isSynthetic);
78
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * How Claude Code's `result` ends the work that it reports, and whether that
3
+ * work was the user's turn or a cycle Claude Code started on its own: the
4
+ * rules that both cores read a turn's result with (the v1 prompt loop in
5
+ * `acp-agent.ts` and `v2/`). Each core adds its own side effects, such as v1's
6
+ * session failure category.
7
+ */
8
+ import type { SDKMessage, SDKMessageOrigin, SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
9
+ export type ResultEnd = {
10
+ stopReason: "refusal" | "max_tokens" | "end_turn" | "max_turn_requests";
11
+ }
12
+ /**
13
+ * The result failed the work, with Claude Code's error text. `loginRequired`:
14
+ * the text of a `success` result tells the user to run `/login`.
15
+ */
16
+ | {
17
+ error: string;
18
+ loginRequired: boolean;
19
+ };
20
+ /**
21
+ * True when CLI error text tells the user to sign in with `/login`. The CLI
22
+ * words this several ways — "Not logged in · Please run /login", "Not logged
23
+ * in · Run /login", "Login expired · Run /login to sign in again, or
24
+ * re-authenticate your Anthropic profile" — so match the "run /login"
25
+ * instruction rather than one sentence.
26
+ */
27
+ export declare function isLoginRequiredText(text: string): boolean;
28
+ /**
29
+ * - Any subtype with `stop_reason: "refusal"`: `refusal`, also on an error.
30
+ * - `success`: an error with the `/login` text fails the work, then
31
+ * `stop_reason: "max_tokens"` is `max_tokens`, then any other error fails
32
+ * the work. Otherwise `end_turn`.
33
+ * - `error_during_execution`: `max_tokens` as for `success`, then an error
34
+ * fails the work. Otherwise `end_turn`.
35
+ * - `error_max_turns`, `error_max_budget_usd` and
36
+ * `error_max_structured_output_retries`: an error fails the work, whatever
37
+ * the stop reason. Otherwise `max_turn_requests`.
38
+ */
39
+ export declare function resultEnd(result: SDKResultMessage): ResultEnd;
40
+ /** Result-message origin kinds that mark an AUTONOMOUS cycle — work the
41
+ * model did on its own (a task-notification followup, a peer/coordinator/
42
+ * observer message it handled) rather than the user's prompt. Absent,
43
+ * `human`, and `channel` origins are the user's own turn (this adapter's
44
+ * prompts arrive as the ACP channel on some CLI configurations — ALL
45
+ * channel servers are treated as user, so a foreign channel integration's
46
+ * autonomously-handled result is misclassified as the user's; accepted,
47
+ * see below), and `auto-continuation` continues the user's turn, so its
48
+ * result is the turn's real terminal.
49
+ *
50
+ * Deliberately fail-OPEN: an unknown future kind defaults to the user
51
+ * lane — including `unclassified` (SDK 0.3.232+), the CLI's own "couldn't
52
+ * attribute this" marker, which gets the same safe default. Misrouting a
53
+ * USER result into the autonomous lane hangs the prompt un-detectably
54
+ * (the result is skipped, its trailing idle absorbed as owed, so the
55
+ * #825 detector can't fire); misrouting an autonomous result into the
56
+ * user lane is the bounded misattribution class this set exists to
57
+ * reduce.
58
+ *
59
+ * Exception: a result from one of these origins that names a pending prompt
60
+ * in `user_message_uuids` consumed that folded prompt and takes the user
61
+ * lane (see the result handler of each core). */
62
+ export declare const AUTONOMOUS_RESULT_ORIGINS: ReadonlySet<SDKMessageOrigin["kind"]>;
63
+ /** Whether Claude Code ended the work of `result` because an interrupt
64
+ * stopped it, while the model streamed or while a tool ran. */
65
+ export declare function isAbortedResult(result: Extract<SDKMessage, {
66
+ type: "result";
67
+ }>): boolean;
68
+ //# sourceMappingURL=result-end.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-end.d.ts","sourceRoot":"","sources":["../src/result-end.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,SAAS,GACjB;IAAE,UAAU,EAAE,SAAS,GAAG,YAAY,GAAG,UAAU,GAAG,mBAAmB,CAAA;CAAE;AAC7E;;;GAGG;GACD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAmB7D;AAMD;;;;;;;;;;;;;;;;;;;;;kDAqBkD;AAClD,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAM1E,CAAC;AAEH;gEACgE;AAChE,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAIxF"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * True when CLI error text tells the user to sign in with `/login`. The CLI
3
+ * words this several ways — "Not logged in · Please run /login", "Not logged
4
+ * in · Run /login", "Login expired · Run /login to sign in again, or
5
+ * re-authenticate your Anthropic profile" — so match the "run /login"
6
+ * instruction rather than one sentence.
7
+ */
8
+ export function isLoginRequiredText(text) {
9
+ return /\brun \/login\b/i.test(text);
10
+ }
11
+ /**
12
+ * - Any subtype with `stop_reason: "refusal"`: `refusal`, also on an error.
13
+ * - `success`: an error with the `/login` text fails the work, then
14
+ * `stop_reason: "max_tokens"` is `max_tokens`, then any other error fails
15
+ * the work. Otherwise `end_turn`.
16
+ * - `error_during_execution`: `max_tokens` as for `success`, then an error
17
+ * fails the work. Otherwise `end_turn`.
18
+ * - `error_max_turns`, `error_max_budget_usd` and
19
+ * `error_max_structured_output_retries`: an error fails the work, whatever
20
+ * the stop reason. Otherwise `max_turn_requests`.
21
+ */
22
+ export function resultEnd(result) {
23
+ if (result.stop_reason === "refusal")
24
+ return { stopReason: "refusal" };
25
+ switch (result.subtype) {
26
+ case "success":
27
+ if (result.is_error && isLoginRequiredText(result.result)) {
28
+ return { error: result.result, loginRequired: true };
29
+ }
30
+ if (result.stop_reason === "max_tokens")
31
+ return { stopReason: "max_tokens" };
32
+ if (result.is_error)
33
+ return { error: result.result, loginRequired: false };
34
+ return { stopReason: "end_turn" };
35
+ case "error_during_execution":
36
+ if (result.stop_reason === "max_tokens")
37
+ return { stopReason: "max_tokens" };
38
+ if (result.is_error)
39
+ return failed(result);
40
+ return { stopReason: "end_turn" };
41
+ default:
42
+ // `error_max_turns`, `error_max_budget_usd`, `error_max_structured_output_retries`.
43
+ if (result.is_error)
44
+ return failed(result);
45
+ return { stopReason: "max_turn_requests" };
46
+ }
47
+ }
48
+ function failed(result) {
49
+ return { error: result.errors.join(", ") || result.subtype, loginRequired: false };
50
+ }
51
+ /** Result-message origin kinds that mark an AUTONOMOUS cycle — work the
52
+ * model did on its own (a task-notification followup, a peer/coordinator/
53
+ * observer message it handled) rather than the user's prompt. Absent,
54
+ * `human`, and `channel` origins are the user's own turn (this adapter's
55
+ * prompts arrive as the ACP channel on some CLI configurations — ALL
56
+ * channel servers are treated as user, so a foreign channel integration's
57
+ * autonomously-handled result is misclassified as the user's; accepted,
58
+ * see below), and `auto-continuation` continues the user's turn, so its
59
+ * result is the turn's real terminal.
60
+ *
61
+ * Deliberately fail-OPEN: an unknown future kind defaults to the user
62
+ * lane — including `unclassified` (SDK 0.3.232+), the CLI's own "couldn't
63
+ * attribute this" marker, which gets the same safe default. Misrouting a
64
+ * USER result into the autonomous lane hangs the prompt un-detectably
65
+ * (the result is skipped, its trailing idle absorbed as owed, so the
66
+ * #825 detector can't fire); misrouting an autonomous result into the
67
+ * user lane is the bounded misattribution class this set exists to
68
+ * reduce.
69
+ *
70
+ * Exception: a result from one of these origins that names a pending prompt
71
+ * in `user_message_uuids` consumed that folded prompt and takes the user
72
+ * lane (see the result handler of each core). */
73
+ export const AUTONOMOUS_RESULT_ORIGINS = new Set([
74
+ "task-notification",
75
+ "peer",
76
+ "coordinator",
77
+ "observer",
78
+ "observer-activity",
79
+ ]);
80
+ /** Whether Claude Code ended the work of `result` because an interrupt
81
+ * stopped it, while the model streamed or while a tool ran. */
82
+ export function isAbortedResult(result) {
83
+ return (result.terminal_reason === "aborted_streaming" || result.terminal_reason === "aborted_tools");
84
+ }